@coco-vexel/coco-office-editor 1.0.12 → 1.0.13
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 +50 -35
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +50 -35
- package/dist/{model-CgISL5eB.d.cts → model-ttSpXtd3.d.cts} +2 -0
- package/dist/{model-CgISL5eB.d.ts → model-ttSpXtd3.d.ts} +2 -0
- package/dist/{native-DVRWKaOC.d.cts → native-B7rEV_h6.d.cts} +1 -1
- package/dist/{native-D9lhNG94.d.ts → native-DQL69NnL.d.ts} +1 -1
- package/dist/word-native.cjs +34 -19
- package/dist/word-native.d.cts +2 -2
- package/dist/word-native.d.ts +2 -2
- package/dist/word-native.js +34 -19
- package/dist/word.cjs +43 -28
- package/dist/word.d.cts +4 -4
- package/dist/word.d.ts +4 -4
- package/dist/word.js +43 -28
- package/package.json +3 -3
- package/src/styles/editor.css +17 -2
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {fromZip,fromFlatOpc,markDirty,createXmlPart,setPart,createBinaryPart,getPart}from'@coco-vexel/coco-office/pack';import {buildIndices,listTables,listDrawings,listStories,W_NS,listSections,W14_NS,buildParagraphInfo,getImageBytesSync}from'@coco-vexel/coco-office/word-view';import {writeWordTableBorders}from'@coco-vexel/coco-office/word';import {PluginKey,Plugin}from'prosemirror-state';import {Schema}from'prosemirror-model';import'prosemirror-commands';import'prosemirror-keymap';import'prosemirror-view';import {parseCellAddress,parseRangeAddress,formatCellAddress,captureExcelCellStyle,shiftFormulaReferences,formatRangeAddress,ExcelWorkbook,SpreadsheetFormulaEngine,diffExcelWorkbookModels,rewriteFormulaForRowSort,equalExcelCellStyles,columnIndexToName,rewriteFormulaReferences,splitSheetQualifiedAddress,readExcelEmbeddedObjectPreviews,columnNameToIndex}from'@coco-vexel/coco-office/excel';import {resolvePptEffectivePlaceholderProperties,Presentation}from'@coco-vexel/coco-office/ppt';var bg=Object.defineProperty,wg=Object.defineProperties;var xg=Object.getOwnPropertyDescriptors;var Jo=Object.getOwnPropertySymbols;var Kd=Object.prototype.hasOwnProperty,_d=Object.prototype.propertyIsEnumerable;var Za=(t,e,n)=>e in t?bg(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n,v=(t,e)=>{for(var n in e||(e={}))Kd.call(e,n)&&Za(t,n,e[n]);if(Jo)for(var n of Jo(e))_d.call(e,n)&&Za(t,n,e[n]);return t},F=(t,e)=>wg(t,xg(e));var Ln=(t,e)=>{var n={};for(var r in t)Kd.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&Jo)for(var r of Jo(t))e.indexOf(r)<0&&_d.call(t,r)&&(n[r]=t[r]);return n};var W=(t,e,n)=>Za(t,typeof e!="symbol"?e+"":e,n);var hn=class extends Error{constructor(n){super(`${n} editor is read-only`);W(this,"code","EDITOR_READ_ONLY");this.name="EditorReadOnlyError";}};var qd=[{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"}],yg=qd[3];function qt(t,e=yg){var a;let n=t.split(",").map(s=>s.trim()).filter(Boolean),r=n.join(" "),o=(a=qd.find(s=>s.matches.test(r)))!=null?a:e;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 Dr(t,e="\u6C49\u5B57Aa0"){var n;typeof document=="undefined"||!((n=document.fonts)!=null&&n.load)||await Promise.all([...new Set(t)].map(r=>document.fonts.load(r,e).catch(()=>[])));}var sc="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Pg="http://schemas.openxmlformats.org/package/2006/relationships",xt="http://schemas.openxmlformats.org/drawingml/2006/main",Ja="http://schemas.openxmlformats.org/markup-compatibility/2006",Rg="urn:schemas-microsoft-com:office:office",ts="urn:schemas-microsoft-com:vml",Mg={firstRow:true,lastRow:false,firstColumn:true,lastColumn:false,noHorizontalBand:false,noVerticalBand:true};async function ZC(t){let e=await fromZip(t);return rs(e,buildIndices(e))}function JC(t){let e=fromFlatOpc(t);return rs(e,buildIndices(e))}async function QC(t){return rs(t._getPackage(),t._getIndices())}function rs(t,e){var g;let n=[],r=[],o=[],i=new Set,a=new Map(listTables(t,e,{scope:"all",includeNested:true,includeCellTexts:true}).map(h=>[h.tableId,h])),s=new Map;for(let[h,x]of e.tblIdx)s.set(x,h);let l=new Map,d=new Map(listDrawings(t,e,{scope:"all"}).map(h=>[h.drawingId,h])),u=new Map;for(let h of d.values()){if(!h.anchorParaId)continue;let x=(g=u.get(h.anchorParaId))!=null?g:[];x.push(h),u.set(h.anchorParaId,x);}let p=new Map;for(let[h,x]of e.drawingIdx){l.set(x,h);let S=ub(t,e,h,d.get(h));S&&p.set(h,S);}let f=Wg(t),b={indices:e,drawingIdByElement:l,drawingInfoById:d,drawingsByAnchorParaId:u,imagesByDrawingId:p,theme:f,documentDefaults:hb(t,f),numbering:mb(t),numberingCounters:new Map,defaultParagraphStyleId:nc(t,"paragraph"),defaultTableStyleId:nc(t,"table"),paragraphStyleFormats:vb(t,e,f),tableStyleFormats:Sb(t,f),hyperlinkByElement:$g(t)};for(let h of listStories(t,{kinds:["body"]})){let x=uc(h.id,h.root,{context:b,attachedCommentIds:i,tableIdByElement:s,tableInfoById:a,flattenSdt:true});n.push(...x.blocks),r.push(...x.paragraphs),o.push(...x.tables);}let w=Vg(t,{context:b,attachedCommentIds:i,tableIdByElement:s,tableInfoById:a});return {kind:"word",defaults:b.documentDefaults,pageLayout:Ag(t),sections:Fg(t),headers:w.headers,footers:w.footers,blocks:n,paragraphs:r,tables:o,detachedComments:Hb(e,i),detachedRevisions:[]}}function Ag(t){let e=t.parts.get("word/document.xml"),n=e==null?void 0:e.xmlDom;if(!n)return;let r=n.getElementsByTagNameNS(W_NS,"body")[0];if(!r)return;let o=Dg(r);if(o)return lc(o)}function lc(t){var p,f,b,w;let e=q(t,W_NS,"pgSz"),n=q(t,W_NS,"pgMar"),r=Bb(t,W_NS,"docGrid"),o=e?Ae(e,"w"):void 0,i=e?Ae(e,"h"):void 0;if(o===void 0||i===void 0)return;let a=e?e.getAttributeNS(W_NS,"orient"):null,s={width:o,height:i,margin:{top:n&&(p=Ae(n,"top"))!=null?p:1440,right:n&&(f=Ae(n,"right"))!=null?f: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(t){let e=t.getAttributeNS(W_NS,"type"),n=e==="default"||e==="lines"||e==="linesAndChars"||e==="snapToChars"?e:void 0,r=Ae(t,"linePitch"),o=Ae(t,"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(t){for(let e=t.childNodes.length-1;e>=0;e--){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===W_NS){if(r.localName==="sectPr")return r;if(r.localName==="p"){let o=q(r,W_NS,"pPr"),i=o?q(o,W_NS,"sectPr"):null;if(i)return i}}}return null}function Wg(t){var i;let e={colors:new Map,fonts:new Map},n=(i=t.parts.get("word/theme/theme1.xml"))==null?void 0:i.xmlDom;if(!n)return e;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=Bg(r,a);s&&e.colors.set(a,s);}let o=n.getElementsByTagNameNS(xt,"fontScheme")[0];return o&&(Xd(e.fonts,q(o,xt,"majorFont"),"major"),Xd(e.fonts,q(o,xt,"minorFont"),"minor")),e}function Bg(t,e){var r;let n=q(t,xt,e);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=Wr(s);if(l)return l}}function Xd(t,e,n){if(!e)return;let r=Qa(q(e,xt,"latin")),o=Qa(q(e,xt,"ea"))||r,i=Qa(q(e,xt,"cs"))||r;r&&(t.set(`${n}Ascii`,r),t.set(`${n}HAnsi`,r)),o&&t.set(`${n}EastAsia`,o),i&&t.set(`${n}Bidi`,i);}function Qa(t){var n;let e=(n=t==null?void 0:t.getAttribute("typeface"))!=null?n:void 0;return e&&e.length>0?e:void 0}function Fg(t){let e=Hg(t);if(e.length>0)return e;let n=listSections(t);return n.length>0?n.map(r=>{var o,i;return F(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 Hg(t){let e=listStories(t,{kinds:["body"]})[0];if(!e)return [];let n=cc(e.partPath),r=[],o,i,a=0;for(let l of is(e.root)){if(l.localName==="p"){let d=os("body",l,a++);o||(o=d),i=d;let u=ei(l,W_NS,["pPr","sectPr"]);u&&o&&i&&(r.push(Yd(r.length,o,i,u,t,n)),o=void 0);continue}if(l.localName==="tbl"){a++;continue}}let s=q(e.root,W_NS,"sectPr");return s&&o&&i&&r.push(Yd(r.length,o,i,s,t,n)),r}function Yd(t,e,n,r,o,i){var p;let a={sectionIndex:t,firstParaId:e,lastParaId:n,headerRefs:Zd(o,r,i,"headerReference"),footerRefs:Zd(o,r,i,"footerReference"),titlePage:q(r,W_NS,"titlePg")!==null},s=lc(r);s&&(a.pageLayout=s);let l=q(r,W_NS,"pgNumType"),d=l?Ae(l,"start"):void 0;d!==void 0&&(a.pageNumberStart=d);let u=(p=q(r,W_NS,"type"))==null?void 0:p.getAttributeNS(W_NS,"val");return (u==="nextPage"||u==="continuous"||u==="evenPage"||u==="oddPage"||u==="nextColumn")&&(a.type=u),a}function Zd(t,e,n,r){if(!n)return [];let o=dc(t,n);if(!o)return [];let i=[];for(let a of yt(e,W_NS,r)){let s=a.getAttributeNS(sc,"id");if(!s)continue;let l=o.get(s);if(!l)continue;let d=a.getAttributeNS(W_NS,"type");i.push({type:d==="first"||d==="even"?d:"default",partName:Og(n,l)});}return i}function dc(t,e){let n=t.parts.get(e),r=n==null?void 0:n.xmlDom;if(!r)return null;let o=new Map,i=r.getElementsByTagNameNS(Pg,"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 Og(t,e){if(e.startsWith("/"))return e.slice(1);let r=t.lastIndexOf("/_rels/");return r<0?e:`${t.slice(0,r)}/${e}`.replace(/\\/g,"/")}function cc(t){let e=t.lastIndexOf("/"),n=e>=0?t.slice(0,e):"",r=t.slice(e+1);return n.length>0?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function $g(t){var n,r;let e=new Map;for(let o of listStories(t,{kinds:["body","header","footer"]})){let i=cc(o.partPath),a=i?dc(t,i):null,s=o.root.getElementsByTagNameNS(W_NS,"hyperlink");for(let l=0;l<s.length;l+=1){let d=s[l];if(!d)continue;let u=d.getAttributeNS(sc,"id"),p=u?a==null?void 0:a.get(u):void 0,f=(n=d.getAttributeNS(W_NS,"anchor"))!=null?n:void 0,b=(r=d.getAttributeNS(W_NS,"tooltip"))!=null?r:void 0;!p&&!f||e.set(d,v(v(v({},p?{target:p}:{}),f?{anchor:f}:{}),b?{tooltip:b}:{}));}}return e}function os(t,e,n){var r;return ((r=e.getAttributeNS(W14_NS,"paraId"))==null?void 0:r.toUpperCase())||`${t}:p:${n}`}function uc(t,e,n){let r=[],o=[],i=[],a=n.flattenSdt?is(e,n.suppressPlaceholderSdtContent===true):zg(e);for(let s=0;s<a.length;s++){let l=a[s];if(l.localName==="p"){let d=ni(t,l,n.context,n.attachedCommentIds,os(t,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=fc(u,l,t,n.context,n.attachedCommentIds,n.tableIdByElement,n.tableInfoById,n.suppressPlaceholderSdtContent===true);r.push(p),i.push(p),o.push(...pc(p)),i.push(...hc(p));}}return {blocks:r,paragraphs:o,tables:i}}function zg(t){let e=[];for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];if(!r||r.nodeType!==1||r.namespaceURI!==W_NS)continue;let o=r;(o.localName==="p"||o.localName==="tbl")&&e.push(o);}return e}function is(t,e=false){let n=[],r=o=>{if(o.namespaceURI===W_NS&&!(e&&Wc(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<t.childNodes.length;o++){let i=t.childNodes[o];(i==null?void 0:i.nodeType)===1&&r(i);}return n}function Vg(t,e){let n=[],r=[];for(let o of listStories(t,{kinds:["header","footer"]})){if(o.kind!=="header"&&o.kind!=="footer")continue;let i=uc(o.id,o.root,F(v({},e),{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 ni(t,e,n,r,o,i=false){let a=buildParagraphInfo(t,e,"full",true,{structuralWhitespace:true}),s=a.paraId||o||"",l=sb(e,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=Gg(e,n.theme),f=Br(ei(e,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=wb(w.numbering,n),gb(w,n)),w!==void 0&&(d.format=w),a.table!==void 0&&(d.table=a.table),d}function Gg(t,e){for(let n of yt(t,W_NS,"r")){let r=nn(n,e);if(r)return r}for(let n of yt(t,W_NS,"hyperlink")){let r=yt(n,W_NS,"r")[0],o=r?nn(r,e):void 0;if(o)return o}for(let n of ["ins","del","fldSimple"])for(let r of yt(t,W_NS,n)){let o=yt(r,W_NS,"r")[0],i=o?nn(o,e):void 0;if(i)return i}}function fc(t,e,n,r,o,i,a,s=false){var S,k,I,D,H,A;let l=ob((S=t.cellGrid)!=null?S:[]),d=Yg(e),u=Xg(e),p=t.tableStyleId?r.tableStyleFormats.get(t.tableStyleId):void 0,f=(k=Zg(e))!=null?k:p==null?void 0:p.cellMargin,b=(I=eb(e))!=null?I:p==null?void 0:p.borders,w=p!=null?p:r.tableStyleFormats.get((D=r.defaultTableStyleId)!=null?D:""),g=Kg(e,w==null?void 0:w.layoutMode),h=bc(p==null?void 0:p.tableLook,_g(e)),x=0;return F(v(v(v(F(v({type:"table",tableId:t.tableId},t.tableStyleId?{tableStyleId:t.tableStyleId}:{}),{columnWidths:t.columnWidths}),g?{layout:g}:{}),h?{tableLook:h}:{}),b?{borders:b}:{}),{rows:(A=(H=t.cellGrid)==null?void 0:H.map((O,ee)=>{let le=Ug(d[ee]);return F(v(v(v({},t.rowHeights[ee]?{height:t.rowHeights[ee]}:{}),le.isHeader?{isHeader:true}:{}),le.cantSplit?{cantSplit:true}:{}),{cells:O.map((ae,te)=>{var et,kt,fn,ut,Rt,ht,Ze,Kt,ft,Qt,Kn,mt,In,Nn;let oe=p?ib(p,ee,te,(et=t.cellGrid)!=null?et:[],h):void 0,U=u[x++],X=U?jg(U,{storyId:n,tableId:t.tableId,context:r,attachedCommentIds:o,tableIdByElement:i,tableInfoById:a,suppressPlaceholderSdtContent:s}):void 0,B=X!=null&&X.paragraphs.length?X.paragraphs:ae.paragraphIds.map(gt=>r.indices.paraIdx.get(gt.toUpperCase())).filter(gt=>gt!==void 0).map(gt=>ni(n,gt,r,o,void 0,s)),G=B.length>0?B:rb(t.tableId,ee,te,ae.text),K={text:ae.text||((kt=X==null?void 0:X.directParagraphs.map(gt=>gt.text).join(`
|
|
2
|
-
`))!=null?kt:""),gridSpan:
|
|
3
|
-
`).map((o,i)=>({type:"paragraph",paraId:`${t}:r${e}: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 ob(t){var r,o;let e=yc(t),n=new Map;for(let i=0;i<e.length;i++){let a=(r=e[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<e.length&&((o=e[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 yc(t){return t.map(e=>{let n=0;return e.map(r=>{let o=n,i=Math.max(1,r.gridSpan);return n+=i,{startColumn:o,endColumn:n-1,columnSpan:i,cell:r}})})}function ib(t,e,n,r,o){var w;let i=t.conditions;if(!i)return;let a=yc(r),s=(w=a[e])==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=ab(o),p=u.rowBandSize,f=u.columnBandSize,b;return !u.noHorizontalBand&&Math.floor(e/p)%2===0?b=Et(b,i.band1Horz):u.noHorizontalBand||(b=Et(b,i.band2Horz)),!u.noVerticalBand&&Math.floor(s.startColumn/f)%2===0?b=Et(b,i.band1Vert):u.noVerticalBand||(b=Et(b,i.band2Vert)),u.firstRow&&e===0&&(b=Et(b,i.firstRow)),u.lastRow&&e===l-1&&(b=Et(b,i.lastRow)),u.firstColumn&&s.startColumn===0&&(b=Et(b,i.firstCol)),u.lastColumn&&s.endColumn===d&&(b=Et(b,i.lastCol)),u.firstRow&&u.firstColumn&&e===0&&s.startColumn===0&&(b=Et(b,i.nwCell)),u.firstRow&&u.lastColumn&&e===0&&s.endColumn===d&&(b=Et(b,i.neCell)),u.lastRow&&u.firstColumn&&e===l-1&&s.startColumn===0&&(b=Et(b,i.swCell)),u.lastRow&&u.lastColumn&&e===l-1&&s.endColumn===d&&(b=Et(b,i.seCell)),b}function ab(t){var e,n;return F(v(v({},Mg),t!=null?t:{}),{rowBandSize:(e=t==null?void 0:t.rowBandSize)!=null?e:1,columnBandSize:(n=t==null?void 0:t.columnBandSize)!=null?n:1})}function sb(t,e,n,r=false){var te,oe,U,X;let o=[],i=[],a=new Map,s=new Set,l=new Set,d=0,u=null,p="",f=B=>Bc(B,r),b=B=>{let G=p.length;return p+=B,{from:G,to:p.length}},w=t.childNodes;for(let B=0;B<w.length;B++){let G=w[B];if(!G||G.nodeType!==1)continue;let z=G;if(z.namespaceURI!==W_NS){g("unknown",z);continue}if(z.localName==="pPr")continue;if(z.localName==="hyperlink"){h(z);continue}let K=oc(z,"commentRangeStart");if(K!==null){a.set(K,p.length);continue}let Y=oc(z,"commentRangeEnd");if(Y!==null){let xe=a.get(Y);if(xe!==void 0){let Le=Fb(n.indices,Y,e,xe,p.length,p);Le&&i.push(Le),a.delete(Y);}continue}if(z.localName==="ins"||z.localName==="del"){let xe=z.localName==="ins"?"insert":"delete",Le=ds(z,xe==="delete"?"delText":"t"),{from:Ge,to:et}=b(Le),kt=(te=z.getAttributeNS(W_NS,"id"))!=null?te:"",fn=yt(z,W_NS,"r")[0],ut=fn?nn(fn,n.theme):void 0,Rt=F(v({kind:"revision",from:Ge,to:et,text:Le},ut?{format:ut}:{}),{revisionId:kt,revisionKind:xe,author:(oe=z.getAttributeNS(W_NS,"author"))!=null?oe:"",date:(U=z.getAttributeNS(W_NS,"date"))!=null?U:""});o.push(Rt),kt.length>0&&i.push({kind:"revision",id:`revision:${kt}`,revisionId:kt,revisionKind:xe,paraId:e,from:Ge,to:et,text:Le,author:Rt.author,date:Rt.date});continue}if(z.localName==="r"&&Ob(z)){x(z);continue}if(u&&z.localName==="r"){k(z);continue}if(z.localName==="fldSimple"&&S(z)||z.localName==="r"&&Yb(z))continue;if(z.localName==="r"&&Vb(z)){O(z);continue}let Se=z.localName==="r"?Gb(z):[];if(Se.length>0){for(let xe of Se)ee(xe);continue}if(zb(z)){ee(z);continue}let Ee=f(z);if(Ee.length>0){let{from:xe,to:Le}=b(Ee),Ge={kind:"text",from:xe,to:Le,text:Ee};if(z.localName==="r"){let et=nn(z,n.theme);et&&(Ge.format=et);}o.push(Ge);}}H(),le(t);for(let B of (X=n.drawingsByAnchorParaId.get(e))!=null?X:[])s.has(B.drawingId)||ae(B);return {text:p,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:z,to:K}=b("\uFFFC");o.push({kind:"placeholder",from:z,to:K,placeholderKind:B,sourceTag:G.localName});}function h(B){let G=n.hyperlinkByElement.get(B);for(let z=0;z<B.childNodes.length;z+=1){let K=B.childNodes[z];if(!K||K.nodeType!==1)continue;let Y=K;if(Y.namespaceURI!==W_NS||Y.localName!=="r")continue;let Se=f(Y);if(Se.length===0)continue;let{from:Ee,to:xe}=b(Se),Le={kind:"text",from:Ee,to:xe,text:Se},Ge=nn(Y,n.theme);Ge&&(Le.format=Ge),G&&(Le.hyperlink=v({},G)),o.push(Le);}}function x(B){var z;let G=nn(B,n.theme);for(let K=0;K<B.childNodes.length;K++){let Y=B.childNodes[K];if(!Y||Y.nodeType!==1)continue;let Se=Y;if(Se.namespaceURI!==W_NS)continue;if(Se.localName==="fldChar"){let et=Se.getAttributeNS(W_NS,"fldCharType");et==="begin"?(H(),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+=(z=Se.textContent)!=null?z:"";continue}let Ee=$b(Se);if(Ee.length===0)continue;if(u){u.inResult&&(u.cachedText+=Ee);continue}let{from:xe,to:Le}=b(Ee),Ge={kind:"text",from:xe,to:Le,text:Ee};G&&(Ge.format=G),o.push(Ge);}}function S(B){var Y;let G=(Y=B.getAttributeNS(W_NS,"instr"))!=null?Y:"",z=ic(G);if(!z)return false;let K=f(B);return D(z,G,K,nn(B,n.theme)),true}function k(B){let G=f(B);G.length>0&&(u!=null&&u.inResult)&&(u.cachedText+=G);}function I(B){let G=ic(B.instruction);if(G){D(G,B.instruction,B.cachedText,B.format);return}A(B);}function D(B,G,z,K){let{from:Y,to:Se}=b("\uFFFC"),Ee={kind:"field",from:Y,to:Se,fieldKind:B,instruction:G,cachedText:z};K&&(Ee.format=K),o.push(Ee);}function H(){u&&(A(u),u=null);}function A(B){if(B.cachedText.length===0)return;let{from:G,to:z}=b(B.cachedText),K={kind:"text",from:G,to:z,text:B.cachedText};B.format&&(K.format=B.format),o.push(K);}function O(B){let G=nn(B,n.theme);for(let z=0;z<B.childNodes.length;z++){let K=B.childNodes[z];if(!K||K.nodeType!==1)continue;let Y=K;if(Y.namespaceURI!==W_NS)continue;if(Y.localName==="br"&&Y.getAttributeNS(W_NS,"type")==="page"){g("pageBreak",Y);continue}let Se=f(Y);if(Se.length===0)continue;let{from:Ee,to:xe}=b(Se),Le={kind:"text",from:Ee,to:xe,text:Se};G&&(Le.format=G),o.push(Le);}}function ee(B){if(B.namespaceURI===W_NS&&B.localName==="pict"){if(jb(B)||Ub(B,t,e,n))return;let xe=_b(B,e,d);if(!xe||l.has(B))return;l.add(B),d+=1;let{from:Le,to:Ge}=b("\uFFFC");o.push(F(v({},xe),{from:Le,to:Ge}));return}let G=n.drawingIdByElement.get(B),z=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||!z){g("drawing",B);return}let{from:Y,to:Se}=b("\uFFFC");s.add(G);let Ee={kind:"image",from:Y,to:Se,drawingId:G,src:z.src,contentType:z.contentType};z.width!==void 0&&(Ee.width=z.width),z.height!==void 0&&(Ee.height=z.height),z.anchoringMode!==void 0&&(Ee.anchoringMode=z.anchoringMode),z.wrap!==void 0&&(Ee.wrap=z.wrap),z.position!==void 0&&(Ee.position=z.position),o.push(Ee);}function le(B){for(let G of ["drawing","pict"]){let z=B.getElementsByTagNameNS(W_NS,G);for(let K=0;K<z.length;K++){let Y=z[K];if(!Y)continue;if(G==="pict"){if(l.has(Y))continue;ee(Y);continue}let Se=n.drawingIdByElement.get(Y);!Se||s.has(Se)||ee(Y);}}}function ae(B){var xe;if(B.kind==="picture"||(s.add(B.drawingId),lb(B,n)))return;let G=B.kind==="textBox"&&(xe=B.innerText)!=null?xe:"",{from:z,to:K}=b(G.length>0?G:"\uFFFC"),Y={kind:"drawing",from:z,to:K,drawingId:B.drawingId,drawingKind:B.kind};G.length>0&&(Y.text=G);let Se=vc(B.extentEMU);if(Se.width!==void 0&&(Y.width=Se.width),Se.height!==void 0&&(Y.height=Se.height),B.anchoringMode!==void 0&&(Y.anchoringMode=B.anchoringMode),B.wrap!==void 0&&(Y.wrap=B.wrap),B.position!==void 0&&(Y.position=B.position),B.hasBorder!==void 0&&(Y.hasBorder=B.hasBorder),B.hasFill!==void 0&&(Y.hasFill=B.hasFill),B.isLineOrConnector!==void 0&&(Y.isLineOrConnector=B.isLineOrConnector),B.isLineOrConnector){let Le=Kb(n.indices.drawingIdx.get(B.drawingId),n.theme);Le.color&&(Y.strokeColor=Le.color),Le.width!==void 0&&(Y.strokeWidth=Le.width);}B.innerTextAlign!==void 0&&(Y.innerTextAlign=B.innerTextAlign);let Ee=cb(B,n);Ee.length>0&&(Y.paragraphs=Ee),o.push(Y);}}var ec=127e3;function lb(t,e){var a,s,l,d;if(t.kind!=="textBox"||t.anchoringMode!=="anchor"||t.extentEMU.cx<=0||t.extentEMU.cy<=0||t.extentEMU.cx>ec||t.extentEMU.cy>ec)return false;let n=(s=(a=t.position)==null?void 0:a.horizontal)==null?void 0:s.posOffset,r=(d=(l=t.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=e.indices.drawingIdx.get(t.drawingId);if(!o)return false;let i=o.getElementsByTagNameNS(W_NS,"txbxContent")[0];return i?db(i):false}function db(t){var o,i;let e=[],n=0,r=t.getElementsByTagName("*");for(let a=0;a<r.length;a+=1){let s=r[a];if(!(!s||s.namespaceURI!==W_NS)){if(s.localName==="fldChar"){let l=s.getAttributeNS(W_NS,"fldCharType");if(l==="begin")e.push({instruction:""});else if(l==="end"){let d=e.pop();if(!d||!/^SET\b/i.test(d.instruction.trim()))return false;n+=1;}continue}if(s.localName==="instrText"){let l=e[e.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&&e.length===0)return false}}return e.length===0&&n>0}function cb(t,e){if(t.kind!=="textBox"||!t.innerParagraphIds||t.innerParagraphIds.length===0)return [];let n=new Set;return t.innerParagraphIds.flatMap(r=>{let o=e.indices.paraIdx.get(r);return o?[ni("body",o,e,n,r)]:[]})}function ub(t,e,n,r){let o=getImageBytesSync(t,e,n);if(!o)return null;let i={src:`data:${o.contentType};base64,${pb(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=fb(o);return a.width!==void 0&&(i.width=a.width),a.height!==void 0&&(i.height=a.height),i}function fb(t){return vc(t.extentEMU)}function vc(t){let{cx:e,cy:n}=t;return {width:e>0?Math.round(e/914400*96):void 0,height:n>0?Math.round(n/914400*96):void 0}}function pb(t){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",r=0;for(;r+2<t.length;r+=3){let o=t[r]<<16|t[r+1]<<8|t[r+2];n+=Dn(e,o>>18&63),n+=Dn(e,o>>12&63),n+=Dn(e,o>>6&63),n+=Dn(e,o&63);}if(r<t.length){let o=t[r],i=r+1<t.length?t[r+1]:0,a=o<<16|i<<8;n+=Dn(e,a>>18&63),n+=Dn(e,a>>12&63),n+=r+1<t.length?Dn(e,a>>6&63):"=",n+="=";}return n}function Dn(t,e){return t.charAt(e)}function hb(t,e){let n={},r=as(t);if(!r)return n;let o=r.getElementsByTagNameNS(W_NS,"docDefaults")[0];if(!o)return n;let i=ei(o,W_NS,["rPrDefault","rPr"]),a=i?Nc(i,e):void 0;a&&(n.run=a);let s=ei(o,W_NS,["pPrDefault","pPr"]);if(s){let l=Br(s,e);l&&(n.paragraph=l);}return n}function as(t){for(let e of t.parts.values())if(e.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"&&e.xmlDom)return e.xmlDom;return null}function mb(t){var a,s,l,d,u,p,f;let e=bb(t);if(!e)return {nums:new Map};let n=new Map,r=e.getElementsByTagNameNS(W_NS,"abstractNum");for(let b=0;b<r.length;b++){let w=r[b];if(!w)continue;let g=w.getAttributeNS(W_NS,"abstractNumId");if(!g)continue;let h=new Map;for(let x of yt(w,W_NS,"lvl")){let S=(a=Ae(x,"ilvl"))!=null?a:0,k=(l=(s=q(x,W_NS,"numFmt"))==null?void 0:s.getAttributeNS(W_NS,"val"))!=null?l:void 0,I=(u=(d=q(x,W_NS,"lvlText"))==null?void 0:d.getAttributeNS(W_NS,"val"))!=null?u:void 0,D=q(x,W_NS,"start"),H=D&&(p=Ae(D,"val"))!=null?p:1,A=Br(q(x,W_NS,"pPr"));h.set(S,v(v(v({ilvl:S,start:H},k?{numFmt:k}:{}),I?{lvlText:I}:{}),A?{paragraphFormat:A}:{}));}n.set(g,h);}let o=new Map,i=e.getElementsByTagNameNS(W_NS,"num");for(let b=0;b<i.length;b++){let w=i[b];if(!w)continue;let g=w.getAttributeNS(W_NS,"numId"),h=(f=q(w,W_NS,"abstractNumId"))==null?void 0:f.getAttributeNS(W_NS,"val");if(!g||!h)continue;let x=n.get(h);x&&o.set(g,x);}return {nums:o}}function gb(t,e){var o,i;if(!t.numbering)return;let n=(o=e.numbering.nums.get(t.numbering.numId))==null?void 0:o.get(t.numbering.ilvl),r=n==null?void 0:n.paragraphFormat;if(r){if(r.indent!==void 0){let a=(i=t.indent)!=null?i:{};t.indent=v({},a),r.indent.left!==void 0&&(a.left===void 0||a.left===0)&&(t.indent.left=r.indent.left),r.indent.right!==void 0&&a.right===void 0&&(t.indent.right=r.indent.right),r.indent.firstLine!==void 0&&a.firstLine===void 0&&(t.indent.firstLine=r.indent.firstLine);}t.spacing===void 0&&r.spacing!==void 0&&(t.spacing=v({},r.spacing)),t.alignment===void 0&&r.alignment!==void 0&&(t.alignment=r.alignment);}}function bb(t){for(let e of t.parts.values())if(e.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"&&e.xmlDom)return e.xmlDom;return null}function wb(t,e){var l,d,u,p,f;let n=(l=e.numbering.nums.get(t.numId))==null?void 0:l.get(t.ilvl),r=(d=t.numFmt)!=null?d:n==null?void 0:n.numFmt,o=(u=t.lvlText)!=null?u:n==null?void 0:n.lvlText,i=v(v(v(v({},t),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=xb(o),i;let s=((f=e.numberingCounters.get(a))!=null?f:((p=n==null?void 0:n.start)!=null?p:1)-1)+1;return e.numberingCounters.set(a,s),i.label=yb(s,r,o),i}function xb(t){let e=t==null?void 0:t.replace(/%\d+/g,"").trim();return e&&e.length>0?e:"\u2022"}function yb(t,e,n){let r=e==="lowerLetter"?tc(t,false):e==="upperLetter"?tc(t,true):String(t);return n?n.replace(/%\d+/g,r):`${r}.`}function tc(t,e){let n=Math.max(1,t),r="";for(;n>0;)n-=1,r=String.fromCharCode((e?65:97)+n%26)+r,n=Math.floor(n/26);return r}function vb(t,e,n){var i,a;let r=new Map;for(let s of t.parts.values()){if(s.contentType!=="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"||!s.xmlDom)continue;let l=s.xmlDom.getElementsByTagNameNS(W_NS,"style");for(let d=0;d<l.length;d++){let u=l[d];if(!u)continue;let p=u.getAttributeNS(W_NS,"styleId");if(!p||((i=u.getAttributeNS(W_NS,"type"))!=null?i:"paragraph")!=="paragraph")continue;let b={},w=(a=q(u,W_NS,"basedOn"))==null?void 0:a.getAttributeNS(W_NS,"val");w&&(b.basedOn=w);let g=Nb(u,n);g&&(b.format=g),r.set(p,b);}}let o=new Map;for(let s of r.keys()){let l=Ec(s,r,new Set);l&&o.set(s,l);}for(let s of e.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 nc(t,e){var o;let n=as(t);if(!n)return;let r=n.getElementsByTagNameNS(W_NS,"style");for(let i=0;i<r.length;i++){let a=r[i];if(!a||((o=a.getAttributeNS(W_NS,"type"))!=null?o:"paragraph")!==e||a.getAttributeNS(W_NS,"default")!=="1")continue;let l=a.getAttributeNS(W_NS,"styleId");if(l)return l}}function Sb(t,e){var a,s;let n=new Map,r=as(t);if(!r)return new Map;let o=r.getElementsByTagNameNS(W_NS,"style");for(let l=0;l<o.length;l++){let d=o[l];if(!d)continue;let u=d.getAttributeNS(W_NS,"styleId");if(!u||((a=d.getAttributeNS(W_NS,"type"))!=null?a:"paragraph")!=="table")continue;let f={},b=(s=q(d,W_NS,"basedOn"))==null?void 0:s.getAttributeNS(W_NS,"val");b&&(f.basedOn=b);let w=kb(d,e);w&&(f.format=w),n.set(u,f);}let i=new Map;for(let l of n.keys()){let d=Sc(l,n,new Set);d&&i.set(l,d);}return i}function Sc(t,e,n){if(n.has(t))return;n.add(t);let r=e.get(t);if(!r)return;let o=r.basedOn?Sc(r.basedOn,e,n):void 0;return ns(o,r.format)}function kb(t,e){let n=ns(kc(q(t,W_NS,"tblPr"),q(t,W_NS,"tcPr"),e),Eb(t,e)),r=Cb(t,e);return r?ns(n,{conditions:r}):n}function Eb(t,e){for(let n of yt(t,W_NS,"tblStylePr"))if(n.getAttributeNS(W_NS,"type")==="wholeTable")return kc(q(n,W_NS,"tblPr"),q(n,W_NS,"tcPr"),e)}function Cb(t,e){let n={};for(let r of yt(t,W_NS,"tblStylePr")){let o=r.getAttributeNS(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=Ib(r,e);i&&(n[o]=i);}return Object.keys(n).length>0?n:void 0}function Ib(t,e){let n={},r=ss(q(t,W_NS,"tcPr"),e);r&&(n.cell=r);let o=Ht(Br(q(t,W_NS,"pPr"),e),Cc(q(t,W_NS,"rPr"),e));return o&&(n.paragraphFormat=o),Object.keys(n).length>0?n:void 0}function kc(t,e,n){let r={};if(t){let o=mc(t);o&&(r.layoutMode=o);let i=wc(t);i&&(r.borders=i);let a=ri(q(t,W_NS,"tblCellMar"));a&&(r.cellMargin=a);let s=gc(t);s&&(r.tableLook=s);}if(e){let o=ss(e,n);o&&(r.cell=o);}return Object.keys(r).length>0?r:void 0}function ss(t,e){if(!t)return;let n={},r=ri(q(t,W_NS,"tcMar"));r&&(n.margin=r);let o=tb(t);o&&(n.borders=o);let i=oi(q(t,W_NS,"shd"),e);i&&(n.shading=i);let a=nb(q(t,W_NS,"vAlign"));a&&(n.verticalAlignment=a);let s=st(q(t,W_NS,"noWrap"));return (s!==void 0?s:q(t,W_NS,"noWrap")!==null)&&(n.noWrap=true),Object.keys(n).length>0?n:void 0}function ns(t,e){var r,o,i,a,s,l,d,u,p,f,b,w,g,h,x,S,k,I,D,H;if(!t&&!e)return;let n=v(v({},t!=null?t:{}),e!=null?e:{});if((t!=null&&t.borders||e!=null&&e.borders)&&(n.borders=v(v({},(r=t==null?void 0:t.borders)!=null?r:{}),(o=e==null?void 0:e.borders)!=null?o:{})),(t!=null&&t.cellMargin||e!=null&&e.cellMargin)&&(n.cellMargin=v(v({},(i=t==null?void 0:t.cellMargin)!=null?i:{}),(a=e==null?void 0:e.cellMargin)!=null?a:{})),(t!=null&&t.tableLook||e!=null&&e.tableLook)&&(n.tableLook=bc(t==null?void 0:t.tableLook,e==null?void 0:e.tableLook)),(t!=null&&t.cell||e!=null&&e.cell)&&(n.cell=v(v({},(s=t==null?void 0:t.cell)!=null?s:{}),(l=e==null?void 0:e.cell)!=null?l:{}),((d=t==null?void 0:t.cell)!=null&&d.margin||(u=e==null?void 0:e.cell)!=null&&u.margin)&&(n.cell.margin=v(v({},(f=(p=t==null?void 0:t.cell)==null?void 0:p.margin)!=null?f:{}),(w=(b=e==null?void 0:e.cell)==null?void 0:b.margin)!=null?w:{})),((g=t==null?void 0:t.cell)!=null&&g.borders||(h=e==null?void 0:e.cell)!=null&&h.borders)&&(n.cell.borders=v(v({},(S=(x=t==null?void 0:t.cell)==null?void 0:x.borders)!=null?S:{}),(I=(k=e==null?void 0:e.cell)==null?void 0:k.borders)!=null?I:{}))),(t!=null&&t.paragraphFormat||e!=null&&e.paragraphFormat)&&(n.paragraphFormat=Ht(t==null?void 0:t.paragraphFormat,e==null?void 0:e.paragraphFormat)),t!=null&&t.conditions||e!=null&&e.conditions){n.conditions=v({},(D=t==null?void 0:t.conditions)!=null?D:{});for(let[A,O]of Object.entries((H=e==null?void 0:e.conditions)!=null?H:{}))n.conditions[A]=Et(n.conditions[A],O);}return n}function Et(t,e){var r,o,i,a,s,l,d,u,p,f,b,w,g,h;if(!t&&!e)return;let n=v(v({},t!=null?t:{}),e!=null?e:{});return (t!=null&&t.cell||e!=null&&e.cell)&&(n.cell=v(v({},(r=t==null?void 0:t.cell)!=null?r:{}),(o=e==null?void 0:e.cell)!=null?o:{}),((i=t==null?void 0:t.cell)!=null&&i.margin||(a=e==null?void 0:e.cell)!=null&&a.margin)&&(n.cell.margin=v(v({},(l=(s=t==null?void 0:t.cell)==null?void 0:s.margin)!=null?l:{}),(u=(d=e==null?void 0:e.cell)==null?void 0:d.margin)!=null?u:{})),((p=t==null?void 0:t.cell)!=null&&p.borders||(f=e==null?void 0:e.cell)!=null&&f.borders)&&(n.cell.borders=v(v({},(w=(b=t==null?void 0:t.cell)==null?void 0:b.borders)!=null?w:{}),(h=(g=e==null?void 0:e.cell)==null?void 0:g.borders)!=null?h:{}))),(t!=null&&t.paragraphFormat||e!=null&&e.paragraphFormat)&&(n.paragraphFormat=Ht(t==null?void 0:t.paragraphFormat,e==null?void 0:e.paragraphFormat)),n}function Ec(t,e,n){if(n.has(t))return;n.add(t);let r=e.get(t);if(!r)return;let o=r.basedOn?Ec(r.basedOn,e,n):void 0;return Ht(o,r.format)}function Nb(t,e){let n=Br(q(t,W_NS,"pPr"),e),r=Cc(q(t,W_NS,"rPr"),e);return Ht(n,r)}function Br(t,e){var o,i;let n={},r=false;if(t){let a=q(t,W_NS,"jc"),s=a==null?void 0:a.getAttributeNS(W_NS,"val");(s==="left"||s==="center"||s==="right"||s==="both"||s==="distribute")&&(n.alignment=s,r=true);let l=q(t,W_NS,"ind");if(l){let I=Ae(l,"left"),D=Ae(l,"right"),H=Ae(l,"firstLine"),A=Ae(l,"hanging"),O=H!==void 0?H:A!==void 0?-A:void 0;(I!==void 0||D!==void 0||O!==void 0)&&(n.indent={},I!==void 0&&(n.indent.left=I),D!==void 0&&(n.indent.right=D),O!==void 0&&(n.indent.firstLine=O),r=true);}let d=q(t,W_NS,"spacing");if(d){let I=Ae(d,"before"),D=Ae(d,"after"),H=Ae(d,"line"),A=d.getAttributeNS(W_NS,"lineRule"),O=A==="auto"||A==="exact"||A==="atLeast"?A:void 0;(I!==void 0||D!==void 0||H!==void 0||O!==void 0)&&(n.spacing={},I!==void 0&&(n.spacing.before=I),D!==void 0&&(n.spacing.after=D),H!==void 0&&(n.spacing.line=H),O!==void 0&&(n.spacing.lineRule=O),r=true);}let u=Tb(q(t,W_NS,"tabs"));u!==void 0&&(n.tabStops=u,r=true);let p=q(t,W_NS,"outlineLvl"),f=p?Ae(p,"val"):void 0;f!==void 0&&f>=0&&f<=9&&(n.outlineLevel=f,r=true);let b=q(t,W_NS,"numPr");if(b){let I=(o=q(b,W_NS,"numId"))==null?void 0:o.getAttributeNS(W_NS,"val");I&&I!=="0"&&(n.hasNumbering=true,n.numbering={numId:I,ilvl:q(b,W_NS,"ilvl")&&(i=Ae(q(b,W_NS,"ilvl"),"val"))!=null?i:0},r=true);}Ic(q(t,W_NS,"rPr"),n,e,false)&&(r=true),Pb(t,n)&&(r=true);let w=oi(q(t,W_NS,"shd"),e);w&&(n.shading=w,r=true);let g=st(q(t,W_NS,"keepNext"));g!==void 0&&(n.keepNext=g,r=true);let h=st(q(t,W_NS,"keepLines"));h!==void 0&&(n.keepLines=h,r=true);let x=st(q(t,W_NS,"widowControl"));x!==void 0&&(n.widowControl=x,r=true);let S=st(q(t,W_NS,"snapToGrid"));S!==void 0&&(n.snapToGrid=S,r=true);let k=st(q(t,W_NS,"pageBreakBefore"));k!==void 0&&(n.pageBreakBefore=k,r=true),q(t,W_NS,"sectPr")&&(n.hasSectionBreak=true,r=true);}return r?n:void 0}function Tb(t){if(!t)return;let e=[];for(let n of yt(t,W_NS,"tab")){let r=n.getAttributeNS(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(W_NS,"leader"),s=a==="none"||a==="dot"||a==="hyphen"||a==="underscore"||a==="heavy"||a==="middleDot"?a:void 0;e.push(v({alignment:o,position:i},s?{leader:s}:{}));}return e.length>0?e:void 0}function Cc(t,e){let n={};return Ic(t,n,e)?n:void 0}function Ic(t,e,n,r=true){if(!t)return false;let o=false,i=Rc(t,n);i&&(e.fontFamily=i,o=true);let a=q(t,W_NS,"sz"),s=a?Ae(a,"val"):void 0;s!==void 0&&(e.fontSize=s/2,o=true);let l=st(q(t,W_NS,"b"));if(l!==void 0&&(e.bold=l,o=true),r){let f=Mc(q(t,W_NS,"color"),n);f&&(e.color=f,o=true);}let d=Pc(t);d!==void 0&&(e.characterSpacing=d,o=true);let u=Tc(q(t,W_NS,"highlight"));u&&(e.highlight=u,o=true);let p=oi(q(t,W_NS,"shd"),n);return p&&(e.shading=p,o=true),o}function Pb(t,e){let n=q(t,W_NS,"pBdr");if(!n)return false;let r={};for(let o of ["top","right","bottom","left","between","bar"]){let i=Rb(q(n,W_NS,o));i&&(r[o]=i);}return Object.keys(r).length===0?false:(e.borders=r,r.bottom&&(e.borderBottom=r.bottom),true)}function Ht(t,e){var r,o,i,a,s,l;if(!t&&!e)return;let n=v(v({},t!=null?t:{}),e!=null?e:{});return (t!=null&&t.indent||e!=null&&e.indent)&&(n.indent=v(v({},(r=t==null?void 0:t.indent)!=null?r:{}),(o=e==null?void 0:e.indent)!=null?o:{})),(t!=null&&t.spacing||e!=null&&e.spacing)&&(n.spacing=v(v({},(i=t==null?void 0:t.spacing)!=null?i:{}),(a=e==null?void 0:e.spacing)!=null?a:{})),(t&&"borders"in t&&t.borders||e&&"borders"in e&&e.borders)&&(n.borders=v(v({},(s=t==null?void 0:t.borders)!=null?s:{}),(l=e==null?void 0:e.borders)!=null?l:{}),n.borders.bottom&&(n.borderBottom=n.borders.bottom)),e&&"tabStops"in e&&e.tabStops!==void 0?n.tabStops=e.tabStops.map(d=>v({},d)):t&&"tabStops"in t&&t.tabStops!==void 0&&(n.tabStops=t.tabStops.map(d=>v({},d))),n}function Ae(t,e){let n=t.getAttributeNS(W_NS,e);if(n===null)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function Rb(t){var a;if(!t)return;let e=(a=t.getAttributeNS(W_NS,"val"))!=null?a:void 0;if(e==="none"||e==="nil")return;let n={val:e},r=t.getAttributeNS(W_NS,"color"),o=Ae(t,"sz"),i=Ae(t,"space");return r&&(n.color=r),o!==void 0&&(n.size=o),i!==void 0&&(n.space=i),n}function nn(t,e){let n=q(t,W_NS,"rPr");if(!n)return;let r=Nc(n,e);return r&&Object.keys(r).length>0?r:void 0}function Nc(t,e){let n={},r=Rc(t,e);r&&(n.fontFamily=r);let o=st(q(t,W_NS,"b"));o!==void 0&&(n.bold=o);let i=st(q(t,W_NS,"i"));i!==void 0&&(n.italic=i);let a=q(t,W_NS,"u");if(a){let x=a.getAttributeNS(W_NS,"val");n.underline=x!=="none"&&x!=="0"&&x!=="false";}let s=st(q(t,W_NS,"strike"));s!==void 0&&(n.strike=s);let l=st(q(t,W_NS,"dstrike"));l!==void 0&&(n.doubleStrike=l);let d=st(q(t,W_NS,"caps"));d!==void 0&&(n.caps=d);let u=st(q(t,W_NS,"smallCaps"));u!==void 0&&(n.smallCaps=u);let p=q(t,W_NS,"sz");if(p){let x=p.getAttributeNS(W_NS,"val"),S=x!==null?Number(x):NaN;Number.isFinite(S)&&(n.fontSize=S/2);}let f=q(t,W_NS,"color");if(f){let x=Mc(f,e);x&&(n.color=x);}let b=Pc(t);b!==void 0&&(n.characterSpacing=b);let w=Mb(q(t,W_NS,"vertAlign"));w&&(n.verticalAlign=w);let g=Tc(q(t,W_NS,"highlight"));g&&(n.highlight=g);let h=oi(q(t,W_NS,"shd"),e);return h&&(n.shading=h),Object.keys(n).length>0?n:void 0}function Tc(t){var n;let e=(n=t==null?void 0:t.getAttributeNS(W_NS,"val"))!=null?n:void 0;return e&&e!=="none"?e:void 0}function Pc(t){let e=q(t,W_NS,"spacing");return e?Ae(e,"val"):void 0}function Mb(t){let e=t==null?void 0:t.getAttributeNS(W_NS,"val");return e==="baseline"||e==="superscript"||e==="subscript"?e:void 0}function Rc(t,e){let n=q(t,W_NS,"rFonts");if(!n)return;let r=n.getAttributeNS(W_NS,"eastAsia")||Qo(e,n.getAttributeNS(W_NS,"eastAsiaTheme")),o=n.getAttributeNS(W_NS,"ascii")||n.getAttributeNS(W_NS,"hAnsi")||Qo(e,n.getAttributeNS(W_NS,"asciiTheme"))||Qo(e,n.getAttributeNS(W_NS,"hAnsiTheme"));return o&&r&&Ab(o)?o===r?o:`${o}, ${r}`:r||o||n.getAttributeNS(W_NS,"cs")||Qo(e,n.getAttributeNS(W_NS,"csTheme"))||void 0}function Ab(t){let e=t.trim().toLowerCase();return e==="calibri"||e==="aptos"||e==="arial"}function Mc(t,e){if(!t)return;let n=Wr(t.getAttributeNS(W_NS,"val")),r=n!=null?n:ls(e,t.getAttributeNS(W_NS,"themeColor"));if(r)return Ac(r,t.getAttributeNS(W_NS,"themeTint"),t.getAttributeNS(W_NS,"themeShade"))}function ls(t,e){if(!(!t||!e))return t.colors.get(e)}function Qo(t,e){if(!(!t||!e))return t.fonts.get(Lb(e))}function Lb(t){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"}[t])!=null?n:t}function Wr(t){if(!(!t||t==="auto")){if(/^[0-9a-f]{6}$/i.test(t))return t.toUpperCase();if(/^[0-9a-f]{8}$/i.test(t))return t.slice(2).toUpperCase()}}function Ac(t,e,n){let r=rc(e);if(r!==void 0)return Db(t,r/255);let o=rc(n);return o!==void 0?Wb(t,o/255):t}function rc(t){if(!t||!/^[0-9a-f]{2}$/i.test(t))return;let e=Number.parseInt(t,16);return Number.isFinite(e)?e:void 0}function Db(t,e){return Lc(t,n=>n+(255-n)*e)}function Wb(t,e){return Lc(t,n=>n*e)}function Lc(t,e){return [0,2,4].map(r=>Number.parseInt(t.slice(r,r+2),16)).map(r=>Math.max(0,Math.min(255,Math.round(e(r))))).map(r=>r.toString(16).toUpperCase().padStart(2,"0")).join("")}function st(t){if(!t)return;let e=t.getAttributeNS(W_NS,"val");return Dc(e)}function Dc(t){return t!=="0"&&t!=="false"&&t!=="off"}function Wc(t){if(t.namespaceURI!==W_NS||t.localName!=="sdt")return false;let e=q(t,W_NS,"sdtPr");return e?st(q(e,W_NS,"showingPlcHdr"))===true:false}function q(t,e,n){for(let r=0;r<t.childNodes.length;r++){let o=t.childNodes[r];if((o==null?void 0:o.nodeType)===1&&o.namespaceURI===e&&o.localName===n)return o}return null}function Bb(t,e,n){for(let r=t.childNodes.length-1;r>=0;r--){let o=t.childNodes[r];if((o==null?void 0:o.nodeType)===1&&o.namespaceURI===e&&o.localName===n)return o}return null}function yt(t,e,n){let r=[];for(let o=0;o<t.childNodes.length;o++){let i=t.childNodes[o];(i==null?void 0:i.nodeType)===1&&i.namespaceURI===e&&i.localName===n&&r.push(i);}return r}function ei(t,e,n){let r=t;for(let o of n)if(r=r?q(r,e,o):null,!r)return null;return r}function Fb(t,e,n,r,o,i){var l,d;let a=t.commentIdx.get(e);if(!(a!=null&&a.comment))return null;let s=ds(a.comment,"t");return {kind:"comment",id:`comment:${e}`,commentId:e,paraId:n,from:r,to:o,text:i.slice(r,o),rangeKind:r===0&&o===i.length?"paragraph":"text",author:(l=a.comment.getAttributeNS(W_NS,"author"))!=null?l:"",date:(d=a.comment.getAttributeNS(W_NS,"date"))!=null?d:"",body:s}}function Hb(t,e){var r,o;let n=[];for(let[i,a]of t.commentIdx)e.has(i)||!a.comment||n.push({id:i,author:(r=a.comment.getAttributeNS(W_NS,"author"))!=null?r:"",date:(o=a.comment.getAttributeNS(W_NS,"date"))!=null?o:"",text:ds(a.comment,"t"),rangeKind:"complex"});return n}function oc(t,e){if(t.namespaceURI!==W_NS||t.localName!==e)return null;let n=t.getAttributeNS(W_NS,"id");if(n===null)return null;let r=Number(n);return Number.isFinite(r)?r:null}function Bc(t,e=false){let n="";function r(o){var a;if(o.nodeType!==1)return;let i=o;if(i.namespaceURI===W_NS&&!(e&&Wc(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(W_NS,"type");(s===null||s===""||s==="textWrapping")&&(n+=`
|
|
1
|
+
import {fromZip,fromFlatOpc,markDirty,createXmlPart,setPart,createBinaryPart,getPart}from'@coco-vexel/coco-office/pack';import {buildIndices,listTables,listDrawings,listStories,W_NS,listSections,W14_NS,buildParagraphInfo,getImageBytesSync}from'@coco-vexel/coco-office/word-view';import {writeWordTableBorders}from'@coco-vexel/coco-office/word';import {PluginKey,Plugin}from'prosemirror-state';import {Schema}from'prosemirror-model';import'prosemirror-commands';import'prosemirror-keymap';import'prosemirror-view';import {parseCellAddress,parseRangeAddress,formatCellAddress,captureExcelCellStyle,shiftFormulaReferences,formatRangeAddress,ExcelWorkbook,SpreadsheetFormulaEngine,diffExcelWorkbookModels,rewriteFormulaForRowSort,equalExcelCellStyles,columnIndexToName,rewriteFormulaReferences,splitSheetQualifiedAddress,readExcelEmbeddedObjectPreviews,columnNameToIndex}from'@coco-vexel/coco-office/excel';import {resolvePptEffectivePlaceholderProperties,Presentation}from'@coco-vexel/coco-office/ppt';var bg=Object.defineProperty,wg=Object.defineProperties;var xg=Object.getOwnPropertyDescriptors;var Jo=Object.getOwnPropertySymbols;var Kd=Object.prototype.hasOwnProperty,_d=Object.prototype.propertyIsEnumerable;var Za=(t,e,n)=>e in t?bg(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n,v=(t,e)=>{for(var n in e||(e={}))Kd.call(e,n)&&Za(t,n,e[n]);if(Jo)for(var n of Jo(e))_d.call(e,n)&&Za(t,n,e[n]);return t},H=(t,e)=>wg(t,xg(e));var Wn=(t,e)=>{var n={};for(var r in t)Kd.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&Jo)for(var r of Jo(t))e.indexOf(r)<0&&_d.call(t,r)&&(n[r]=t[r]);return n};var W=(t,e,n)=>Za(t,typeof e!="symbol"?e+"":e,n);var hn=class extends Error{constructor(n){super(`${n} editor is read-only`);W(this,"code","EDITOR_READ_ONLY");this.name="EditorReadOnlyError";}};var qd=[{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"}],yg=qd[3];function qt(t,e=yg){var a;let n=t.split(",").map(s=>s.trim()).filter(Boolean),r=n.join(" "),o=(a=qd.find(s=>s.matches.test(r)))!=null?a:e;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 Dr(t,e="\u6C49\u5B57Aa0"){var n;typeof document=="undefined"||!((n=document.fonts)!=null&&n.load)||await Promise.all([...new Set(t)].map(r=>document.fonts.load(r,e).catch(()=>[])));}var sc="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Pg="http://schemas.openxmlformats.org/package/2006/relationships",xt="http://schemas.openxmlformats.org/drawingml/2006/main",Ja="http://schemas.openxmlformats.org/markup-compatibility/2006",Rg="urn:schemas-microsoft-com:office:office",ts="urn:schemas-microsoft-com:vml",Mg={firstRow:true,lastRow:false,firstColumn:true,lastColumn:false,noHorizontalBand:false,noVerticalBand:true};async function ZC(t){let e=await fromZip(t);return rs(e,buildIndices(e))}function JC(t){let e=fromFlatOpc(t);return rs(e,buildIndices(e))}async function QC(t){return rs(t._getPackage(),t._getIndices())}function rs(t,e){var g;let n=[],r=[],o=[],i=new Set,a=new Map(listTables(t,e,{scope:"all",includeNested:true,includeCellTexts:true}).map(h=>[h.tableId,h])),s=new Map;for(let[h,x]of e.tblIdx)s.set(x,h);let l=new Map,d=new Map(listDrawings(t,e,{scope:"all"}).map(h=>[h.drawingId,h])),u=new Map;for(let h of d.values()){if(!h.anchorParaId)continue;let x=(g=u.get(h.anchorParaId))!=null?g:[];x.push(h),u.set(h.anchorParaId,x);}let f=new Map;for(let[h,x]of e.drawingIdx){l.set(x,h);let S=ub(t,e,h,d.get(h));S&&f.set(h,S);}let p=Wg(t),b={indices:e,drawingIdByElement:l,drawingInfoById:d,drawingsByAnchorParaId:u,imagesByDrawingId:f,theme:p,documentDefaults:hb(t,p),numbering:mb(t),numberingCounters:new Map,defaultParagraphStyleId:nc(t,"paragraph"),defaultTableStyleId:nc(t,"table"),paragraphStyleFormats:vb(t,e,p),tableStyleFormats:Sb(t,p),hyperlinkByElement:$g(t)};for(let h of listStories(t,{kinds:["body"]})){let x=uc(h.id,h.root,{context:b,attachedCommentIds:i,tableIdByElement:s,tableInfoById:a,flattenSdt:true});n.push(...x.blocks),r.push(...x.paragraphs),o.push(...x.tables);}let w=Vg(t,{context:b,attachedCommentIds:i,tableIdByElement:s,tableInfoById:a});return {kind:"word",defaults:b.documentDefaults,pageLayout:Ag(t),sections:Fg(t),headers:w.headers,footers:w.footers,blocks:n,paragraphs:r,tables:o,detachedComments:Hb(e,i),detachedRevisions:[]}}function Ag(t){let e=t.parts.get("word/document.xml"),n=e==null?void 0:e.xmlDom;if(!n)return;let r=n.getElementsByTagNameNS(W_NS,"body")[0];if(!r)return;let o=Dg(r);if(o)return lc(o)}function lc(t){var p,b,w,g,h;let e=q(t,W_NS,"pgSz"),n=q(t,W_NS,"pgMar"),r=Bb(t,W_NS,"docGrid"),o=e?Le(e,"w"):void 0,i=e?Le(e,"h"):void 0;if(o===void 0||i===void 0)return;let a=e?e.getAttributeNS(W_NS,"orient"):null,s={width:o,height:i,margin:{top:n&&(p=Le(n,"top"))!=null?p:1440,right:n&&(b=Le(n,"right"))!=null?b:1440,bottom:n&&(w=Le(n,"bottom"))!=null?w:1440,left:n&&(g=Le(n,"left"))!=null?g:1440}},l=n?Le(n,"header"):void 0,d=n?Le(n,"footer"):void 0;l!==void 0&&(s.headerDistance=l),d!==void 0&&(s.footerDistance=d);let u=r?Lg(r):void 0;u&&(s.docGrid=u),a==="landscape"?s.orientation="landscape":a==="portrait"&&(s.orientation="portrait");let f=(h=q(t,W_NS,"vAlign"))==null?void 0:h.getAttributeNS(W_NS,"val");return (f==="top"||f==="center"||f==="bottom"||f==="both")&&(s.verticalAlignment=f),s}function Lg(t){let e=t.getAttributeNS(W_NS,"type"),n=e==="default"||e==="lines"||e==="linesAndChars"||e==="snapToChars"?e:void 0,r=Le(t,"linePitch"),o=Le(t,"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(t){for(let e=t.childNodes.length-1;e>=0;e--){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===W_NS){if(r.localName==="sectPr")return r;if(r.localName==="p"){let o=q(r,W_NS,"pPr"),i=o?q(o,W_NS,"sectPr"):null;if(i)return i}}}return null}function Wg(t){var i;let e={colors:new Map,fonts:new Map},n=(i=t.parts.get("word/theme/theme1.xml"))==null?void 0:i.xmlDom;if(!n)return e;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=Bg(r,a);s&&e.colors.set(a,s);}let o=n.getElementsByTagNameNS(xt,"fontScheme")[0];return o&&(Xd(e.fonts,q(o,xt,"majorFont"),"major"),Xd(e.fonts,q(o,xt,"minorFont"),"minor")),e}function Bg(t,e){var r;let n=q(t,xt,e);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=Wr(s);if(l)return l}}function Xd(t,e,n){if(!e)return;let r=Qa(q(e,xt,"latin")),o=Qa(q(e,xt,"ea"))||r,i=Qa(q(e,xt,"cs"))||r;r&&(t.set(`${n}Ascii`,r),t.set(`${n}HAnsi`,r)),o&&t.set(`${n}EastAsia`,o),i&&t.set(`${n}Bidi`,i);}function Qa(t){var n;let e=(n=t==null?void 0:t.getAttribute("typeface"))!=null?n:void 0;return e&&e.length>0?e:void 0}function Fg(t){let e=Hg(t);if(e.length>0)return e;let n=listSections(t);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 Hg(t){let e=listStories(t,{kinds:["body"]})[0];if(!e)return [];let n=cc(e.partPath),r=[],o,i,a=0;for(let l of is(e.root)){if(l.localName==="p"){let d=os("body",l,a++);o||(o=d),i=d;let u=ei(l,W_NS,["pPr","sectPr"]);u&&o&&i&&(r.push(Yd(r.length,o,i,u,t,n)),o=void 0);continue}if(l.localName==="tbl"){a++;continue}}let s=q(e.root,W_NS,"sectPr");return s&&o&&i&&r.push(Yd(r.length,o,i,s,t,n)),r}function Yd(t,e,n,r,o,i){var f;let a={sectionIndex:t,firstParaId:e,lastParaId:n,headerRefs:Zd(o,r,i,"headerReference"),footerRefs:Zd(o,r,i,"footerReference"),titlePage:q(r,W_NS,"titlePg")!==null},s=lc(r);s&&(a.pageLayout=s);let l=q(r,W_NS,"pgNumType"),d=l?Le(l,"start"):void 0;d!==void 0&&(a.pageNumberStart=d);let u=(f=q(r,W_NS,"type"))==null?void 0:f.getAttributeNS(W_NS,"val");return (u==="nextPage"||u==="continuous"||u==="evenPage"||u==="oddPage"||u==="nextColumn")&&(a.type=u),a}function Zd(t,e,n,r){if(!n)return [];let o=dc(t,n);if(!o)return [];let i=[];for(let a of yt(e,W_NS,r)){let s=a.getAttributeNS(sc,"id");if(!s)continue;let l=o.get(s);if(!l)continue;let d=a.getAttributeNS(W_NS,"type");i.push({type:d==="first"||d==="even"?d:"default",partName:Og(n,l)});}return i}function dc(t,e){let n=t.parts.get(e),r=n==null?void 0:n.xmlDom;if(!r)return null;let o=new Map,i=r.getElementsByTagNameNS(Pg,"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 Og(t,e){if(e.startsWith("/"))return e.slice(1);let r=t.lastIndexOf("/_rels/");return r<0?e:`${t.slice(0,r)}/${e}`.replace(/\\/g,"/")}function cc(t){let e=t.lastIndexOf("/"),n=e>=0?t.slice(0,e):"",r=t.slice(e+1);return n.length>0?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function $g(t){var n,r;let e=new Map;for(let o of listStories(t,{kinds:["body","header","footer"]})){let i=cc(o.partPath),a=i?dc(t,i):null,s=o.root.getElementsByTagNameNS(W_NS,"hyperlink");for(let l=0;l<s.length;l+=1){let d=s[l];if(!d)continue;let u=d.getAttributeNS(sc,"id"),f=u?a==null?void 0:a.get(u):void 0,p=(n=d.getAttributeNS(W_NS,"anchor"))!=null?n:void 0,b=(r=d.getAttributeNS(W_NS,"tooltip"))!=null?r:void 0;!f&&!p||e.set(d,v(v(v({},f?{target:f}:{}),p?{anchor:p}:{}),b?{tooltip:b}:{}));}}return e}function os(t,e,n){var r;return ((r=e.getAttributeNS(W14_NS,"paraId"))==null?void 0:r.toUpperCase())||`${t}:p:${n}`}function uc(t,e,n){let r=[],o=[],i=[],a=n.flattenSdt?is(e,n.suppressPlaceholderSdtContent===true):zg(e);for(let s=0;s<a.length;s++){let l=a[s];if(l.localName==="p"){let d=ni(t,l,n.context,n.attachedCommentIds,os(t,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=fc(u,l,t,n.context,n.attachedCommentIds,n.tableIdByElement,n.tableInfoById,n.suppressPlaceholderSdtContent===true);r.push(f),i.push(f),o.push(...pc(f)),i.push(...hc(f));}}return {blocks:r,paragraphs:o,tables:i}}function zg(t){let e=[];for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];if(!r||r.nodeType!==1||r.namespaceURI!==W_NS)continue;let o=r;(o.localName==="p"||o.localName==="tbl")&&e.push(o);}return e}function is(t,e=false){let n=[],r=o=>{if(o.namespaceURI===W_NS&&!(e&&Wc(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<t.childNodes.length;o++){let i=t.childNodes[o];(i==null?void 0:i.nodeType)===1&&r(i);}return n}function Vg(t,e){let n=[],r=[];for(let o of listStories(t,{kinds:["header","footer"]})){if(o.kind!=="header"&&o.kind!=="footer")continue;let i=uc(o.id,o.root,H(v({},e),{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 ni(t,e,n,r,o,i=false){let a=buildParagraphInfo(t,e,"full",true,{structuralWhitespace:true}),s=a.paraId||o||"",l=sb(e,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=Gg(e,n.theme),p=Br(ei(e,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=wb(w.numbering,n),gb(w,n)),w!==void 0&&(d.format=w),a.table!==void 0&&(d.table=a.table),d}function Gg(t,e){for(let n of yt(t,W_NS,"r")){let r=nn(n,e);if(r)return r}for(let n of yt(t,W_NS,"hyperlink")){let r=yt(n,W_NS,"r")[0],o=r?nn(r,e):void 0;if(o)return o}for(let n of ["ins","del","fldSimple"])for(let r of yt(t,W_NS,n)){let o=yt(r,W_NS,"r")[0],i=o?nn(o,e):void 0;if(i)return i}}function fc(t,e,n,r,o,i,a,s=false){var S,k,I,D,F,A;let l=ob((S=t.cellGrid)!=null?S:[]),d=Yg(e),u=Xg(e),f=t.tableStyleId?r.tableStyleFormats.get(t.tableStyleId):void 0,p=(k=Zg(e))!=null?k:f==null?void 0:f.cellMargin,b=(I=eb(e))!=null?I:f==null?void 0:f.borders,w=f!=null?f:r.tableStyleFormats.get((D=r.defaultTableStyleId)!=null?D:""),g=Kg(e,w==null?void 0:w.layoutMode),h=bc(f==null?void 0:f.tableLook,_g(e)),x=0;return H(v(v(v(H(v({type:"table",tableId:t.tableId},t.tableStyleId?{tableStyleId:t.tableStyleId}:{}),{columnWidths:t.columnWidths}),g?{layout:g}:{}),h?{tableLook:h}:{}),b?{borders:b}:{}),{rows:(A=(F=t.cellGrid)==null?void 0:F.map((O,ee)=>{let le=Ug(d[ee]);return H(v(v(v({},t.rowHeights[ee]?{height:t.rowHeights[ee]}:{}),le.isHeader?{isHeader:true}:{}),le.cantSplit?{cantSplit:true}:{}),{cells:O.map((oe,ie)=>{var et,kt,fn,ut,Rt,ht,Ze,Kt,ft,Qt,Kn,mt,Tn,Pn;let ae=f?ib(f,ee,ie,(et=t.cellGrid)!=null?et:[],h):void 0,_=u[x++],Y=_?jg(_,{storyId:n,tableId:t.tableId,context:r,attachedCommentIds:o,tableIdByElement:i,tableInfoById:a,suppressPlaceholderSdtContent:s}):void 0,B=Y!=null&&Y.paragraphs.length?Y.paragraphs:oe.paragraphIds.map(gt=>r.indices.paraIdx.get(gt.toUpperCase())).filter(gt=>gt!==void 0).map(gt=>ni(n,gt,r,o,void 0,s)),U=B.length>0?B:rb(t.tableId,ee,ie,oe.text),G={text:oe.text||((kt=Y==null?void 0:Y.directParagraphs.map(gt=>gt.text).join(`
|
|
2
|
+
`))!=null?kt:""),gridSpan:oe.gridSpan,vMerge:oe.vMerge,blocks:Y!=null&&Y.blocks.length?Y.blocks:U,paragraphs:U};if(ae!=null&&ae.paragraphFormat)for(let gt of (fn=Y==null?void 0:Y.directParagraphs)!=null?fn:G.paragraphs)gt.format=Ht(ae.paragraphFormat,gt.format);let K=l.get(`${ee}:${ie}`);K!==void 0&&K>1&&(G.rowSpan=K),oe.width!==void 0&&(G.width=oe.width);let Se=_?q(_,W_NS,"tcPr"):null,ke=Se&&((ut=q(Se,W_NS,"tcW"))==null?void 0:ut.getAttributeNS(W_NS,"type"));(ke==="pct"||ke==="auto")&&(G.widthType=ke);let ge=Jg(_,r.theme),Ce=Qg((Rt=f==null?void 0:f.cell)==null?void 0:Rt.margin,(ht=ae==null?void 0:ae.cell)==null?void 0:ht.margin,p,le.cellMargin,ge==null?void 0:ge.margin);Ce&&(G.margin=Ce);let Ge=(Qt=(Kt=ge==null?void 0:ge.borders)!=null?Kt:(Ze=ae==null?void 0:ae.cell)==null?void 0:Ze.borders)!=null?Qt:(ft=f==null?void 0:f.cell)==null?void 0:ft.borders;return Ge&&(G.borders=Ge),((Kn=f==null?void 0:f.cell)==null?void 0:Kn.shading)!==void 0&&(G.shading=f.cell.shading),((mt=ae==null?void 0:ae.cell)==null?void 0:mt.shading)!==void 0&&(G.shading=ae.cell.shading),oe.shading!==void 0&&(G.shading=oe.shading),(ge==null?void 0:ge.shading)!==void 0&&(G.shading=ge.shading),((Tn=f==null?void 0:f.cell)==null?void 0:Tn.verticalAlignment)!==void 0&&(G.verticalAlignment=f.cell.verticalAlignment),((Pn=ae==null?void 0:ae.cell)==null?void 0:Pn.verticalAlignment)!==void 0&&(G.verticalAlignment=ae.cell.verticalAlignment),(ge==null?void 0:ge.verticalAlignment)!==void 0&&(G.verticalAlignment=ge.verticalAlignment),oe.verticalAlignment!==void 0&&(G.verticalAlignment=oe.verticalAlignment),(ge==null?void 0:ge.noWrap)!==void 0&&(G.noWrap=ge.noWrap),G})})}))!=null?A:[]})}function jg(t,e){let n=[],r=[],o=[],i=is(t,e.suppressPlaceholderSdtContent);for(let a=0;a<i.length;a+=1){let s=i[a];if(s.localName==="p"){let f=ni(e.storyId,s,e.context,e.attachedCommentIds,os(e.storyId,s,a),e.suppressPlaceholderSdtContent);n.push(f),r.push(f),o.push(f);continue}let l=e.tableIdByElement.get(s),d=l?e.tableInfoById.get(l):void 0;if(!l||!d)continue;let u=fc(d,s,e.storyId,e.context,e.attachedCommentIds,e.tableIdByElement,e.tableInfoById,e.suppressPlaceholderSdtContent);n.push(u),r.push(...pc(u));}return {blocks:n,paragraphs:r,directParagraphs:o}}function pc(t){return t.rows.flatMap(e=>e.cells.flatMap(n=>n.paragraphs))}function hc(t){return t.rows.flatMap(e=>e.cells.flatMap(n=>n.blocks.flatMap(r=>r.type==="table"?[r,...hc(r)]:[])))}function Ug(t){let e={};if(!t)return e;let n=q(t,W_NS,"tblPrEx"),r=n?ri(q(n,W_NS,"tblCellMar")):void 0;r&&(e.cellMargin=r);let o=q(t,W_NS,"trPr");if(!o)return e;let i=st(q(o,W_NS,"tblHeader"));(i!==void 0?i:q(o,W_NS,"tblHeader")!==null)&&(e.isHeader=true);let a=st(q(o,W_NS,"cantSplit"));return (a!==void 0?a:q(o,W_NS,"cantSplit")!==null)&&(e.cantSplit=true),e}function mc(t){var n;let e=t&&((n=q(t,W_NS,"tblLayout"))==null?void 0:n.getAttributeNS(W_NS,"type"));return e==="autofit"||e==="fixed"?e:void 0}function Kg(t,e){var f;let n=q(t,W_NS,"tblPr");if(!n)return e?{mode:e}:void 0;let r={},o=(f=mc(n))!=null?f:e;o&&(r.mode=o);let i=q(n,W_NS,"tblW");if(i){let p=Le(i,"w"),b=Qd(i.getAttributeNS(W_NS,"type"));p!==void 0&&(r.width=p),b!==void 0&&(r.widthType=b);}let a=q(n,W_NS,"tblInd"),s=a?Le(a,"w"):void 0;s!==void 0&&(r.indent=s);let l=q(n,W_NS,"tblCellSpacing");if(l){let p=Le(l,"w"),b=Qd(l.getAttributeNS(W_NS,"type"));p!==void 0&&(r.cellSpacing=p),b!==void 0&&(r.cellSpacingType=b);}let d=q(n,W_NS,"jc"),u=d?qg(d.getAttributeNS(W_NS,"val")):void 0;return u!==void 0&&(r.alignment=u),Object.keys(r).length>0?r:void 0}function _g(t){let e=q(t,W_NS,"tblPr");if(e)return gc(e)}function gc(t){var g;let e=q(t,W_NS,"tblLook"),n={},r=(g=e==null?void 0:e.getAttributeNS(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,x)=>{var k;let S=(k=e==null?void 0:e.getAttributeNS(W_NS,h))!=null?k:null;return S!==null?Dc(S):i(x)},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=Jd(q(t,W_NS,"tblStyleRowBandSize"));b!==void 0&&(n.rowBandSize=b);let w=Jd(q(t,W_NS,"tblStyleColBandSize"));return w!==void 0&&(n.columnBandSize=w),Object.keys(n).length>0?n:void 0}function bc(t,e){if(!(!t&&!e))return v(v({},t!=null?t:{}),e!=null?e:{})}function Jd(t){let e=t?Le(t,"val"):void 0;return e!==void 0&&e>0?e:void 0}function Qd(t){if(t==="auto"||t==="dxa"||t==="pct")return t}function qg(t){if(t==="left"||t==="center"||t==="right")return t}function Xg(t){let e=[];for(let n of yt(t,W_NS,"tr"))e.push(...yt(n,W_NS,"tc"));return e}function Yg(t){return yt(t,W_NS,"tr")}function Zg(t){let e=q(t,W_NS,"tblPr"),n=e?q(e,W_NS,"tblCellMar"):null;return ri(n)}function Jg(t,e){if(t)return ss(q(t,W_NS,"tcPr"),e)}function ri(t){if(!t)return;let e={};for(let n of ["top","right","bottom","left"]){let r=q(t,W_NS,n),o=r?Le(r,"w"):void 0;o!==void 0&&(e[n]=o);}return Object.keys(e).length>0?e:void 0}function Qg(...t){let e=Object.assign({},...t.filter(n=>n!==void 0));return Object.keys(e).length>0?e:void 0}function eb(t){let e=q(t,W_NS,"tblPr");return e?wc(e):void 0}function wc(t){let e=q(t,W_NS,"tblBorders");if(!e)return;let n={};for(let r of ["top","right","bottom","left","insideH","insideV"]){let o=xc(q(e,W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function tb(t){let e=q(t,W_NS,"tcBorders");if(!e)return;let n={};for(let r of ["top","right","bottom","left"]){let o=xc(q(e,W_NS,r));o&&(n[r]=o);}return Object.keys(n).length>0?n:void 0}function oi(t,e){var i,a,s;if(!t)return;let n=(i=Wr(t.getAttributeNS(W_NS,"fill")))!=null?i:ls(e,t.getAttributeNS(W_NS,"themeFill")),r=(a=t.getAttributeNS(W_NS,"color"))!=null?a:void 0,o=(s=t.getAttributeNS(W_NS,"val"))!=null?s:void 0;return v(v(v({},n?{fill:Ac(n,t.getAttributeNS(W_NS,"themeFillTint"),t.getAttributeNS(W_NS,"themeFillShade"))}:{}),r?{color:r}:{}),o?{val:o}:{})}function nb(t){let e=t==null?void 0:t.getAttributeNS(W_NS,"val");return e==="top"||e==="center"||e==="bottom"||e==="both"?e:void 0}function xc(t){var o,i;if(!t)return;let e=(o=t.getAttributeNS(W_NS,"val"))!=null?o:void 0,n=(i=t.getAttributeNS(W_NS,"color"))!=null?i:void 0,r=Le(t,"sz");return v(v(v({},e?{val:e}:{}),n?{color:n}:{}),r!==void 0?{size:r}:{})}function rb(t,e,n,r){return r.length===0?[]:r.split(`
|
|
3
|
+
`).map((o,i)=>({type:"paragraph",paraId:`${t}:r${e}: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 ob(t){var r,o;let e=yc(t),n=new Map;for(let i=0;i<e.length;i++){let a=(r=e[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<e.length&&((o=e[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 yc(t){return t.map(e=>{let n=0;return e.map(r=>{let o=n,i=Math.max(1,r.gridSpan);return n+=i,{startColumn:o,endColumn:n-1,columnSpan:i,cell:r}})})}function ib(t,e,n,r,o){var w;let i=t.conditions;if(!i)return;let a=yc(r),s=(w=a[e])==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=ab(o),f=u.rowBandSize,p=u.columnBandSize,b;return !u.noHorizontalBand&&Math.floor(e/f)%2===0?b=Et(b,i.band1Horz):u.noHorizontalBand||(b=Et(b,i.band2Horz)),!u.noVerticalBand&&Math.floor(s.startColumn/p)%2===0?b=Et(b,i.band1Vert):u.noVerticalBand||(b=Et(b,i.band2Vert)),u.firstRow&&e===0&&(b=Et(b,i.firstRow)),u.lastRow&&e===l-1&&(b=Et(b,i.lastRow)),u.firstColumn&&s.startColumn===0&&(b=Et(b,i.firstCol)),u.lastColumn&&s.endColumn===d&&(b=Et(b,i.lastCol)),u.firstRow&&u.firstColumn&&e===0&&s.startColumn===0&&(b=Et(b,i.nwCell)),u.firstRow&&u.lastColumn&&e===0&&s.endColumn===d&&(b=Et(b,i.neCell)),u.lastRow&&u.firstColumn&&e===l-1&&s.startColumn===0&&(b=Et(b,i.swCell)),u.lastRow&&u.lastColumn&&e===l-1&&s.endColumn===d&&(b=Et(b,i.seCell)),b}function ab(t){var e,n;return H(v(v({},Mg),t!=null?t:{}),{rowBandSize:(e=t==null?void 0:t.rowBandSize)!=null?e:1,columnBandSize:(n=t==null?void 0:t.columnBandSize)!=null?n:1})}function sb(t,e,n,r=false){var ie,ae,_,Y;let o=[],i=[],a=new Map,s=new Set,l=new Set,d=0,u=null,f="",p=B=>Bc(B,r),b=B=>{let U=f.length;return f+=B,{from:U,to:f.length}},w=t.childNodes;for(let B=0;B<w.length;B++){let U=w[B];if(!U||U.nodeType!==1)continue;let z=U;if(z.namespaceURI!==W_NS){g("unknown",z);continue}if(z.localName==="pPr")continue;if(z.localName==="hyperlink"){h(z);continue}let G=oc(z,"commentRangeStart");if(G!==null){a.set(G,f.length);continue}let K=oc(z,"commentRangeEnd");if(K!==null){let ge=a.get(K);if(ge!==void 0){let Ce=Fb(n.indices,K,e,ge,f.length,f);Ce&&i.push(Ce),a.delete(K);}continue}if(z.localName==="ins"||z.localName==="del"){let ge=z.localName==="ins"?"insert":"delete",Ce=ds(z,ge==="delete"?"delText":"t"),{from:Ge,to:et}=b(Ce),kt=(ie=z.getAttributeNS(W_NS,"id"))!=null?ie:"",fn=yt(z,W_NS,"r")[0],ut=fn?nn(fn,n.theme):void 0,Rt=H(v({kind:"revision",from:Ge,to:et,text:Ce},ut?{format:ut}:{}),{revisionId:kt,revisionKind:ge,author:(ae=z.getAttributeNS(W_NS,"author"))!=null?ae:"",date:(_=z.getAttributeNS(W_NS,"date"))!=null?_:""});o.push(Rt),kt.length>0&&i.push({kind:"revision",id:`revision:${kt}`,revisionId:kt,revisionKind:ge,paraId:e,from:Ge,to:et,text:Ce,author:Rt.author,date:Rt.date});continue}if(z.localName==="r"&&Ob(z)){x(z);continue}if(u&&z.localName==="r"){k(z);continue}if(z.localName==="fldSimple"&&S(z)||z.localName==="r"&&Yb(z))continue;if(z.localName==="r"&&Vb(z)){O(z);continue}let Se=z.localName==="r"?Gb(z):[];if(Se.length>0){for(let ge of Se)ee(ge);continue}if(zb(z)){ee(z);continue}let ke=p(z);if(ke.length>0){let{from:ge,to:Ce}=b(ke),Ge={kind:"text",from:ge,to:Ce,text:ke};if(z.localName==="r"){let et=nn(z,n.theme);et&&(Ge.format=et);}o.push(Ge);}}F(),le(t);for(let B of (Y=n.drawingsByAnchorParaId.get(e))!=null?Y:[])s.has(B.drawingId)||oe(B);return {text:f,segments:o,spans:i.sort((B,U)=>B.from-U.from||B.to-U.to||B.id.localeCompare(U.id))};function g(B,U){let{from:z,to:G}=b("\uFFFC");o.push({kind:"placeholder",from:z,to:G,placeholderKind:B,sourceTag:U.localName});}function h(B){let U=n.hyperlinkByElement.get(B);for(let z=0;z<B.childNodes.length;z+=1){let G=B.childNodes[z];if(!G||G.nodeType!==1)continue;let K=G;if(K.namespaceURI!==W_NS||K.localName!=="r")continue;let Se=p(K);if(Se.length===0)continue;let{from:ke,to:ge}=b(Se),Ce={kind:"text",from:ke,to:ge,text:Se},Ge=nn(K,n.theme);Ge&&(Ce.format=Ge),U&&(Ce.hyperlink=v({},U)),o.push(Ce);}}function x(B){var z;let U=nn(B,n.theme);for(let G=0;G<B.childNodes.length;G++){let K=B.childNodes[G];if(!K||K.nodeType!==1)continue;let Se=K;if(Se.namespaceURI!==W_NS)continue;if(Se.localName==="fldChar"){let et=Se.getAttributeNS(W_NS,"fldCharType");et==="begin"?(F(),u={instruction:"",cachedText:"",inResult:false,format:U}):et==="separate"&&u?u.inResult=true:et==="end"&&u&&(I(u),u=null);continue}if(u&&Se.localName==="instrText"){u.instruction+=(z=Se.textContent)!=null?z:"";continue}let ke=$b(Se);if(ke.length===0)continue;if(u){u.inResult&&(u.cachedText+=ke);continue}let{from:ge,to:Ce}=b(ke),Ge={kind:"text",from:ge,to:Ce,text:ke};U&&(Ge.format=U),o.push(Ge);}}function S(B){var K;let U=(K=B.getAttributeNS(W_NS,"instr"))!=null?K:"",z=ic(U);if(!z)return false;let G=p(B);return D(z,U,G,nn(B,n.theme)),true}function k(B){let U=p(B);U.length>0&&(u!=null&&u.inResult)&&(u.cachedText+=U);}function I(B){let U=ic(B.instruction);if(U){D(U,B.instruction,B.cachedText,B.format);return}A(B);}function D(B,U,z,G){let{from:K,to:Se}=b("\uFFFC"),ke={kind:"field",from:K,to:Se,fieldKind:B,instruction:U,cachedText:z};G&&(ke.format=G),o.push(ke);}function F(){u&&(A(u),u=null);}function A(B){if(B.cachedText.length===0)return;let{from:U,to:z}=b(B.cachedText),G={kind:"text",from:U,to:z,text:B.cachedText};B.format&&(G.format=B.format),o.push(G);}function O(B){let U=nn(B,n.theme);for(let z=0;z<B.childNodes.length;z++){let G=B.childNodes[z];if(!G||G.nodeType!==1)continue;let K=G;if(K.namespaceURI!==W_NS)continue;if(K.localName==="br"&&K.getAttributeNS(W_NS,"type")==="page"){g("pageBreak",K);continue}let Se=p(K);if(Se.length===0)continue;let{from:ke,to:ge}=b(Se),Ce={kind:"text",from:ke,to:ge,text:Se};U&&(Ce.format=U),o.push(Ce);}}function ee(B){if(B.namespaceURI===W_NS&&B.localName==="pict"){if(jb(B)||Ub(B,t,e,n))return;let ge=_b(B,e,d);if(!ge||l.has(B))return;l.add(B),d+=1;let{from:Ce,to:Ge}=b("\uFFFC");o.push(H(v({},ge),{from:Ce,to:Ge}));return}let U=n.drawingIdByElement.get(B),z=U?n.imagesByDrawingId.get(U):void 0,G=U?n.drawingInfoById.get(U):void 0;if(U&&G&&G.kind!=="picture"){s.add(U),oe(G);return}if(!U||!z){g("drawing",B);return}let{from:K,to:Se}=b("\uFFFC");s.add(U);let ke={kind:"image",from:K,to:Se,drawingId:U,src:z.src,contentType:z.contentType};z.width!==void 0&&(ke.width=z.width),z.height!==void 0&&(ke.height=z.height),z.anchoringMode!==void 0&&(ke.anchoringMode=z.anchoringMode),z.wrap!==void 0&&(ke.wrap=z.wrap),z.position!==void 0&&(ke.position=z.position),o.push(ke);}function le(B){for(let U of ["drawing","pict"]){let z=B.getElementsByTagNameNS(W_NS,U);for(let G=0;G<z.length;G++){let K=z[G];if(!K)continue;if(U==="pict"){if(l.has(K))continue;ee(K);continue}let Se=n.drawingIdByElement.get(K);!Se||s.has(Se)||ee(K);}}}function oe(B){var ge;if(B.kind==="picture"||(s.add(B.drawingId),lb(B,n)))return;let U=B.kind==="textBox"&&(ge=B.innerText)!=null?ge:"",{from:z,to:G}=b(U.length>0?U:"\uFFFC"),K={kind:"drawing",from:z,to:G,drawingId:B.drawingId,drawingKind:B.kind};U.length>0&&(K.text=U);let Se=vc(B.extentEMU);if(Se.width!==void 0&&(K.width=Se.width),Se.height!==void 0&&(K.height=Se.height),B.anchoringMode!==void 0&&(K.anchoringMode=B.anchoringMode),B.wrap!==void 0&&(K.wrap=B.wrap),B.position!==void 0&&(K.position=B.position),B.hasBorder!==void 0&&(K.hasBorder=B.hasBorder),B.hasFill!==void 0&&(K.hasFill=B.hasFill),B.isLineOrConnector!==void 0&&(K.isLineOrConnector=B.isLineOrConnector),B.isLineOrConnector){let Ce=Kb(n.indices.drawingIdx.get(B.drawingId),n.theme);Ce.color&&(K.strokeColor=Ce.color),Ce.width!==void 0&&(K.strokeWidth=Ce.width);}B.innerTextAlign!==void 0&&(K.innerTextAlign=B.innerTextAlign);let ke=cb(B,n);ke.length>0&&(K.paragraphs=ke),o.push(K);}}var ec=127e3;function lb(t,e){var a,s,l,d;if(t.kind!=="textBox"||t.anchoringMode!=="anchor"||t.extentEMU.cx<=0||t.extentEMU.cy<=0||t.extentEMU.cx>ec||t.extentEMU.cy>ec)return false;let n=(s=(a=t.position)==null?void 0:a.horizontal)==null?void 0:s.posOffset,r=(d=(l=t.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=e.indices.drawingIdx.get(t.drawingId);if(!o)return false;let i=o.getElementsByTagNameNS(W_NS,"txbxContent")[0];return i?db(i):false}function db(t){var o,i;let e=[],n=0,r=t.getElementsByTagName("*");for(let a=0;a<r.length;a+=1){let s=r[a];if(!(!s||s.namespaceURI!==W_NS)){if(s.localName==="fldChar"){let l=s.getAttributeNS(W_NS,"fldCharType");if(l==="begin")e.push({instruction:""});else if(l==="end"){let d=e.pop();if(!d||!/^SET\b/i.test(d.instruction.trim()))return false;n+=1;}continue}if(s.localName==="instrText"){let l=e[e.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&&e.length===0)return false}}return e.length===0&&n>0}function cb(t,e){if(t.kind!=="textBox"||!t.innerParagraphIds||t.innerParagraphIds.length===0)return [];let n=new Set;return t.innerParagraphIds.flatMap(r=>{let o=e.indices.paraIdx.get(r);return o?[ni("body",o,e,n,r)]:[]})}function ub(t,e,n,r){let o=getImageBytesSync(t,e,n);if(!o)return null;let i={src:`data:${o.contentType};base64,${pb(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=fb(o);return a.width!==void 0&&(i.width=a.width),a.height!==void 0&&(i.height=a.height),i}function fb(t){return vc(t.extentEMU)}function vc(t){let{cx:e,cy:n}=t;return {width:e>0?Math.round(e/914400*96):void 0,height:n>0?Math.round(n/914400*96):void 0}}function pb(t){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",r=0;for(;r+2<t.length;r+=3){let o=t[r]<<16|t[r+1]<<8|t[r+2];n+=Bn(e,o>>18&63),n+=Bn(e,o>>12&63),n+=Bn(e,o>>6&63),n+=Bn(e,o&63);}if(r<t.length){let o=t[r],i=r+1<t.length?t[r+1]:0,a=o<<16|i<<8;n+=Bn(e,a>>18&63),n+=Bn(e,a>>12&63),n+=r+1<t.length?Bn(e,a>>6&63):"=",n+="=";}return n}function Bn(t,e){return t.charAt(e)}function hb(t,e){let n={},r=as(t);if(!r)return n;let o=r.getElementsByTagNameNS(W_NS,"docDefaults")[0];if(!o)return n;let i=ei(o,W_NS,["rPrDefault","rPr"]),a=i?Nc(i,e):void 0;a&&(n.run=a);let s=ei(o,W_NS,["pPrDefault","pPr"]);if(s){let l=Br(s,e);l&&(n.paragraph=l);}return n}function as(t){for(let e of t.parts.values())if(e.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"&&e.xmlDom)return e.xmlDom;return null}function mb(t){var a,s,l,d,u,f,p;let e=bb(t);if(!e)return {nums:new Map};let n=new Map,r=e.getElementsByTagNameNS(W_NS,"abstractNum");for(let b=0;b<r.length;b++){let w=r[b];if(!w)continue;let g=w.getAttributeNS(W_NS,"abstractNumId");if(!g)continue;let h=new Map;for(let x of yt(w,W_NS,"lvl")){let S=(a=Le(x,"ilvl"))!=null?a:0,k=(l=(s=q(x,W_NS,"numFmt"))==null?void 0:s.getAttributeNS(W_NS,"val"))!=null?l:void 0,I=(u=(d=q(x,W_NS,"lvlText"))==null?void 0:d.getAttributeNS(W_NS,"val"))!=null?u:void 0,D=q(x,W_NS,"start"),F=D&&(f=Le(D,"val"))!=null?f:1,A=Br(q(x,W_NS,"pPr"));h.set(S,v(v(v({ilvl:S,start:F},k?{numFmt:k}:{}),I?{lvlText:I}:{}),A?{paragraphFormat:A}:{}));}n.set(g,h);}let o=new Map,i=e.getElementsByTagNameNS(W_NS,"num");for(let b=0;b<i.length;b++){let w=i[b];if(!w)continue;let g=w.getAttributeNS(W_NS,"numId"),h=(p=q(w,W_NS,"abstractNumId"))==null?void 0:p.getAttributeNS(W_NS,"val");if(!g||!h)continue;let x=n.get(h);x&&o.set(g,x);}return {nums:o}}function gb(t,e){var o,i;if(!t.numbering)return;let n=(o=e.numbering.nums.get(t.numbering.numId))==null?void 0:o.get(t.numbering.ilvl),r=n==null?void 0:n.paragraphFormat;if(r){if(r.indent!==void 0){let a=(i=t.indent)!=null?i:{};t.indent=v({},a),r.indent.left!==void 0&&(a.left===void 0||a.left===0)&&(t.indent.left=r.indent.left),r.indent.right!==void 0&&a.right===void 0&&(t.indent.right=r.indent.right),r.indent.firstLine!==void 0&&a.firstLine===void 0&&(t.indent.firstLine=r.indent.firstLine);}t.spacing===void 0&&r.spacing!==void 0&&(t.spacing=v({},r.spacing)),t.alignment===void 0&&r.alignment!==void 0&&(t.alignment=r.alignment);}}function bb(t){for(let e of t.parts.values())if(e.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"&&e.xmlDom)return e.xmlDom;return null}function wb(t,e){var l,d,u,f,p;let n=(l=e.numbering.nums.get(t.numId))==null?void 0:l.get(t.ilvl),r=(d=t.numFmt)!=null?d:n==null?void 0:n.numFmt,o=(u=t.lvlText)!=null?u:n==null?void 0:n.lvlText,i=v(v(v(v({},t),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=xb(o),i;let s=((p=e.numberingCounters.get(a))!=null?p:((f=n==null?void 0:n.start)!=null?f:1)-1)+1;return e.numberingCounters.set(a,s),i.label=yb(s,r,o),i}function xb(t){let e=t==null?void 0:t.replace(/%\d+/g,"").trim();return e&&e.length>0?e:"\u2022"}function yb(t,e,n){let r=e==="lowerLetter"?tc(t,false):e==="upperLetter"?tc(t,true):String(t);return n?n.replace(/%\d+/g,r):`${r}.`}function tc(t,e){let n=Math.max(1,t),r="";for(;n>0;)n-=1,r=String.fromCharCode((e?65:97)+n%26)+r,n=Math.floor(n/26);return r}function vb(t,e,n){var i,a;let r=new Map;for(let s of t.parts.values()){if(s.contentType!=="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"||!s.xmlDom)continue;let l=s.xmlDom.getElementsByTagNameNS(W_NS,"style");for(let d=0;d<l.length;d++){let u=l[d];if(!u)continue;let f=u.getAttributeNS(W_NS,"styleId");if(!f||((i=u.getAttributeNS(W_NS,"type"))!=null?i:"paragraph")!=="paragraph")continue;let b={},w=(a=q(u,W_NS,"basedOn"))==null?void 0:a.getAttributeNS(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=Ec(s,r,new Set);l&&o.set(s,l);}for(let s of e.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 nc(t,e){var o;let n=as(t);if(!n)return;let r=n.getElementsByTagNameNS(W_NS,"style");for(let i=0;i<r.length;i++){let a=r[i];if(!a||((o=a.getAttributeNS(W_NS,"type"))!=null?o:"paragraph")!==e||a.getAttributeNS(W_NS,"default")!=="1")continue;let l=a.getAttributeNS(W_NS,"styleId");if(l)return l}}function Sb(t,e){var a,s;let n=new Map,r=as(t);if(!r)return new Map;let o=r.getElementsByTagNameNS(W_NS,"style");for(let l=0;l<o.length;l++){let d=o[l];if(!d)continue;let u=d.getAttributeNS(W_NS,"styleId");if(!u||((a=d.getAttributeNS(W_NS,"type"))!=null?a:"paragraph")!=="table")continue;let p={},b=(s=q(d,W_NS,"basedOn"))==null?void 0:s.getAttributeNS(W_NS,"val");b&&(p.basedOn=b);let w=kb(d,e);w&&(p.format=w),n.set(u,p);}let i=new Map;for(let l of n.keys()){let d=Sc(l,n,new Set);d&&i.set(l,d);}return i}function Sc(t,e,n){if(n.has(t))return;n.add(t);let r=e.get(t);if(!r)return;let o=r.basedOn?Sc(r.basedOn,e,n):void 0;return ns(o,r.format)}function kb(t,e){let n=ns(kc(q(t,W_NS,"tblPr"),q(t,W_NS,"tcPr"),e),Eb(t,e)),r=Cb(t,e);return r?ns(n,{conditions:r}):n}function Eb(t,e){for(let n of yt(t,W_NS,"tblStylePr"))if(n.getAttributeNS(W_NS,"type")==="wholeTable")return kc(q(n,W_NS,"tblPr"),q(n,W_NS,"tcPr"),e)}function Cb(t,e){let n={};for(let r of yt(t,W_NS,"tblStylePr")){let o=r.getAttributeNS(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=Ib(r,e);i&&(n[o]=i);}return Object.keys(n).length>0?n:void 0}function Ib(t,e){let n={},r=ss(q(t,W_NS,"tcPr"),e);r&&(n.cell=r);let o=Ht(Br(q(t,W_NS,"pPr"),e),Cc(q(t,W_NS,"rPr"),e));return o&&(n.paragraphFormat=o),Object.keys(n).length>0?n:void 0}function kc(t,e,n){let r={};if(t){let o=mc(t);o&&(r.layoutMode=o);let i=wc(t);i&&(r.borders=i);let a=ri(q(t,W_NS,"tblCellMar"));a&&(r.cellMargin=a);let s=gc(t);s&&(r.tableLook=s);}if(e){let o=ss(e,n);o&&(r.cell=o);}return Object.keys(r).length>0?r:void 0}function ss(t,e){if(!t)return;let n={},r=ri(q(t,W_NS,"tcMar"));r&&(n.margin=r);let o=tb(t);o&&(n.borders=o);let i=oi(q(t,W_NS,"shd"),e);i&&(n.shading=i);let a=nb(q(t,W_NS,"vAlign"));a&&(n.verticalAlignment=a);let s=st(q(t,W_NS,"noWrap"));return (s!==void 0?s:q(t,W_NS,"noWrap")!==null)&&(n.noWrap=true),Object.keys(n).length>0?n:void 0}function ns(t,e){var r,o,i,a,s,l,d,u,f,p,b,w,g,h,x,S,k,I,D,F;if(!t&&!e)return;let n=v(v({},t!=null?t:{}),e!=null?e:{});if((t!=null&&t.borders||e!=null&&e.borders)&&(n.borders=v(v({},(r=t==null?void 0:t.borders)!=null?r:{}),(o=e==null?void 0:e.borders)!=null?o:{})),(t!=null&&t.cellMargin||e!=null&&e.cellMargin)&&(n.cellMargin=v(v({},(i=t==null?void 0:t.cellMargin)!=null?i:{}),(a=e==null?void 0:e.cellMargin)!=null?a:{})),(t!=null&&t.tableLook||e!=null&&e.tableLook)&&(n.tableLook=bc(t==null?void 0:t.tableLook,e==null?void 0:e.tableLook)),(t!=null&&t.cell||e!=null&&e.cell)&&(n.cell=v(v({},(s=t==null?void 0:t.cell)!=null?s:{}),(l=e==null?void 0:e.cell)!=null?l:{}),((d=t==null?void 0:t.cell)!=null&&d.margin||(u=e==null?void 0:e.cell)!=null&&u.margin)&&(n.cell.margin=v(v({},(p=(f=t==null?void 0:t.cell)==null?void 0:f.margin)!=null?p:{}),(w=(b=e==null?void 0:e.cell)==null?void 0:b.margin)!=null?w:{})),((g=t==null?void 0:t.cell)!=null&&g.borders||(h=e==null?void 0:e.cell)!=null&&h.borders)&&(n.cell.borders=v(v({},(S=(x=t==null?void 0:t.cell)==null?void 0:x.borders)!=null?S:{}),(I=(k=e==null?void 0:e.cell)==null?void 0:k.borders)!=null?I:{}))),(t!=null&&t.paragraphFormat||e!=null&&e.paragraphFormat)&&(n.paragraphFormat=Ht(t==null?void 0:t.paragraphFormat,e==null?void 0:e.paragraphFormat)),t!=null&&t.conditions||e!=null&&e.conditions){n.conditions=v({},(D=t==null?void 0:t.conditions)!=null?D:{});for(let[A,O]of Object.entries((F=e==null?void 0:e.conditions)!=null?F:{}))n.conditions[A]=Et(n.conditions[A],O);}return n}function Et(t,e){var r,o,i,a,s,l,d,u,f,p,b,w,g,h;if(!t&&!e)return;let n=v(v({},t!=null?t:{}),e!=null?e:{});return (t!=null&&t.cell||e!=null&&e.cell)&&(n.cell=v(v({},(r=t==null?void 0:t.cell)!=null?r:{}),(o=e==null?void 0:e.cell)!=null?o:{}),((i=t==null?void 0:t.cell)!=null&&i.margin||(a=e==null?void 0:e.cell)!=null&&a.margin)&&(n.cell.margin=v(v({},(l=(s=t==null?void 0:t.cell)==null?void 0:s.margin)!=null?l:{}),(u=(d=e==null?void 0:e.cell)==null?void 0:d.margin)!=null?u:{})),((f=t==null?void 0:t.cell)!=null&&f.borders||(p=e==null?void 0:e.cell)!=null&&p.borders)&&(n.cell.borders=v(v({},(w=(b=t==null?void 0:t.cell)==null?void 0:b.borders)!=null?w:{}),(h=(g=e==null?void 0:e.cell)==null?void 0:g.borders)!=null?h:{}))),(t!=null&&t.paragraphFormat||e!=null&&e.paragraphFormat)&&(n.paragraphFormat=Ht(t==null?void 0:t.paragraphFormat,e==null?void 0:e.paragraphFormat)),n}function Ec(t,e,n){if(n.has(t))return;n.add(t);let r=e.get(t);if(!r)return;let o=r.basedOn?Ec(r.basedOn,e,n):void 0;return Ht(o,r.format)}function Nb(t,e){let n=Br(q(t,W_NS,"pPr"),e),r=Cc(q(t,W_NS,"rPr"),e);return Ht(n,r)}function Br(t,e){var o,i;let n={},r=false;if(t){let a=q(t,W_NS,"jc"),s=a==null?void 0:a.getAttributeNS(W_NS,"val");(s==="left"||s==="center"||s==="right"||s==="both"||s==="distribute")&&(n.alignment=s,r=true);let l=q(t,W_NS,"ind");if(l){let I=Le(l,"left"),D=Le(l,"right"),F=Le(l,"firstLine"),A=Le(l,"hanging"),O=F!==void 0?F:A!==void 0?-A:void 0;(I!==void 0||D!==void 0||O!==void 0)&&(n.indent={},I!==void 0&&(n.indent.left=I),D!==void 0&&(n.indent.right=D),O!==void 0&&(n.indent.firstLine=O),r=true);}let d=q(t,W_NS,"spacing");if(d){let I=Le(d,"before"),D=Le(d,"after"),F=Le(d,"line"),A=d.getAttributeNS(W_NS,"lineRule"),O=A==="auto"||A==="exact"||A==="atLeast"?A:void 0;(I!==void 0||D!==void 0||F!==void 0||O!==void 0)&&(n.spacing={},I!==void 0&&(n.spacing.before=I),D!==void 0&&(n.spacing.after=D),F!==void 0&&(n.spacing.line=F),O!==void 0&&(n.spacing.lineRule=O),r=true);}let u=Tb(q(t,W_NS,"tabs"));u!==void 0&&(n.tabStops=u,r=true);let f=q(t,W_NS,"outlineLvl"),p=f?Le(f,"val"):void 0;p!==void 0&&p>=0&&p<=9&&(n.outlineLevel=p,r=true);let b=q(t,W_NS,"numPr");if(b){let I=(o=q(b,W_NS,"numId"))==null?void 0:o.getAttributeNS(W_NS,"val");I&&I!=="0"&&(n.hasNumbering=true,n.numbering={numId:I,ilvl:q(b,W_NS,"ilvl")&&(i=Le(q(b,W_NS,"ilvl"),"val"))!=null?i:0},r=true);}Ic(q(t,W_NS,"rPr"),n,e,false)&&(r=true),Pb(t,n)&&(r=true);let w=oi(q(t,W_NS,"shd"),e);w&&(n.shading=w,r=true);let g=st(q(t,W_NS,"keepNext"));g!==void 0&&(n.keepNext=g,r=true);let h=st(q(t,W_NS,"keepLines"));h!==void 0&&(n.keepLines=h,r=true);let x=st(q(t,W_NS,"widowControl"));x!==void 0&&(n.widowControl=x,r=true);let S=st(q(t,W_NS,"snapToGrid"));S!==void 0&&(n.snapToGrid=S,r=true);let k=st(q(t,W_NS,"pageBreakBefore"));k!==void 0&&(n.pageBreakBefore=k,r=true),q(t,W_NS,"sectPr")&&(n.hasSectionBreak=true,r=true);}return r?n:void 0}function Tb(t){if(!t)return;let e=[];for(let n of yt(t,W_NS,"tab")){let r=n.getAttributeNS(W_NS,"val"),o=r==="left"||r==="center"||r==="right"||r==="decimal"||r==="bar"?r:void 0,i=Le(n,"pos");if(!o||i===void 0)continue;let a=n.getAttributeNS(W_NS,"leader"),s=a==="none"||a==="dot"||a==="hyphen"||a==="underscore"||a==="heavy"||a==="middleDot"?a:void 0;e.push(v({alignment:o,position:i},s?{leader:s}:{}));}return e.length>0?e:void 0}function Cc(t,e){let n={};return Ic(t,n,e)?n:void 0}function Ic(t,e,n,r=true){if(!t)return false;let o=false,i=Rc(t,n);i&&(e.fontFamily=i,o=true);let a=q(t,W_NS,"sz"),s=a?Le(a,"val"):void 0;s!==void 0&&(e.fontSize=s/2,o=true);let l=st(q(t,W_NS,"b"));if(l!==void 0&&(e.bold=l,o=true),r){let p=Mc(q(t,W_NS,"color"),n);p&&(e.color=p,o=true);}let d=Pc(t);d!==void 0&&(e.characterSpacing=d,o=true);let u=Tc(q(t,W_NS,"highlight"));u&&(e.highlight=u,o=true);let f=oi(q(t,W_NS,"shd"),n);return f&&(e.shading=f,o=true),o}function Pb(t,e){let n=q(t,W_NS,"pBdr");if(!n)return false;let r={};for(let o of ["top","right","bottom","left","between","bar"]){let i=Rb(q(n,W_NS,o));i&&(r[o]=i);}return Object.keys(r).length===0?false:(e.borders=r,r.bottom&&(e.borderBottom=r.bottom),true)}function Ht(t,e){var r,o,i,a,s,l;if(!t&&!e)return;let n=v(v({},t!=null?t:{}),e!=null?e:{});return (t!=null&&t.indent||e!=null&&e.indent)&&(n.indent=v(v({},(r=t==null?void 0:t.indent)!=null?r:{}),(o=e==null?void 0:e.indent)!=null?o:{})),(t!=null&&t.spacing||e!=null&&e.spacing)&&(n.spacing=v(v({},(i=t==null?void 0:t.spacing)!=null?i:{}),(a=e==null?void 0:e.spacing)!=null?a:{})),(t&&"borders"in t&&t.borders||e&&"borders"in e&&e.borders)&&(n.borders=v(v({},(s=t==null?void 0:t.borders)!=null?s:{}),(l=e==null?void 0:e.borders)!=null?l:{}),n.borders.bottom&&(n.borderBottom=n.borders.bottom)),e&&"tabStops"in e&&e.tabStops!==void 0?n.tabStops=e.tabStops.map(d=>v({},d)):t&&"tabStops"in t&&t.tabStops!==void 0&&(n.tabStops=t.tabStops.map(d=>v({},d))),n}function Le(t,e){let n=t.getAttributeNS(W_NS,e);if(n===null)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function Rb(t){var a;if(!t)return;let e=(a=t.getAttributeNS(W_NS,"val"))!=null?a:void 0;if(e==="none"||e==="nil")return;let n={val:e},r=t.getAttributeNS(W_NS,"color"),o=Le(t,"sz"),i=Le(t,"space");return r&&(n.color=r),o!==void 0&&(n.size=o),i!==void 0&&(n.space=i),n}function nn(t,e){let n=q(t,W_NS,"rPr");if(!n)return;let r=Nc(n,e);return r&&Object.keys(r).length>0?r:void 0}function Nc(t,e){var k;let n={},r=Rc(t,e);r&&(n.fontFamily=r);let o=st(q(t,W_NS,"b"));o!==void 0&&(n.bold=o);let i=st(q(t,W_NS,"i"));i!==void 0&&(n.italic=i);let a=q(t,W_NS,"u");if(a){let I=a.getAttributeNS(W_NS,"val");n.underline=I!=="none"&&I!=="0"&&I!=="false";}let s=st(q(t,W_NS,"strike"));s!==void 0&&(n.strike=s);let l=st(q(t,W_NS,"dstrike"));l!==void 0&&(n.doubleStrike=l);let d=st(q(t,W_NS,"caps"));d!==void 0&&(n.caps=d);let u=st(q(t,W_NS,"smallCaps"));u!==void 0&&(n.smallCaps=u);let f=q(t,W_NS,"sz");if(f){let I=f.getAttributeNS(W_NS,"val"),D=I!==null?Number(I):NaN;Number.isFinite(D)&&(n.fontSize=D/2);}let p=q(t,W_NS,"color");if(p){let I=Mc(p,e);I&&(n.color=I);}let b=Pc(t);b!==void 0&&(n.characterSpacing=b);let w=(k=q(t,W_NS,"w"))==null?void 0:k.getAttributeNS(W_NS,"val"),g=Number(w==null?void 0:w.replace(/%$/,""));Number.isInteger(g)&&g>=1&&g<=600&&(n.characterScale=g);let h=Mb(q(t,W_NS,"vertAlign"));h&&(n.verticalAlign=h);let x=Tc(q(t,W_NS,"highlight"));x&&(n.highlight=x);let S=oi(q(t,W_NS,"shd"),e);return S&&(n.shading=S),Object.keys(n).length>0?n:void 0}function Tc(t){var n;let e=(n=t==null?void 0:t.getAttributeNS(W_NS,"val"))!=null?n:void 0;return e&&e!=="none"?e:void 0}function Pc(t){let e=q(t,W_NS,"spacing");return e?Le(e,"val"):void 0}function Mb(t){let e=t==null?void 0:t.getAttributeNS(W_NS,"val");return e==="baseline"||e==="superscript"||e==="subscript"?e:void 0}function Rc(t,e){let n=q(t,W_NS,"rFonts");if(!n)return;let r=n.getAttributeNS(W_NS,"eastAsia")||Qo(e,n.getAttributeNS(W_NS,"eastAsiaTheme")),o=n.getAttributeNS(W_NS,"ascii")||n.getAttributeNS(W_NS,"hAnsi")||Qo(e,n.getAttributeNS(W_NS,"asciiTheme"))||Qo(e,n.getAttributeNS(W_NS,"hAnsiTheme"));return o&&r&&Ab(o)?o===r?o:`${o}, ${r}`:r||o||n.getAttributeNS(W_NS,"cs")||Qo(e,n.getAttributeNS(W_NS,"csTheme"))||void 0}function Ab(t){let e=t.trim().toLowerCase();return e==="calibri"||e==="aptos"||e==="arial"}function Mc(t,e){if(!t)return;let n=Wr(t.getAttributeNS(W_NS,"val")),r=n!=null?n:ls(e,t.getAttributeNS(W_NS,"themeColor"));if(r)return Ac(r,t.getAttributeNS(W_NS,"themeTint"),t.getAttributeNS(W_NS,"themeShade"))}function ls(t,e){if(!(!t||!e))return t.colors.get(e)}function Qo(t,e){if(!(!t||!e))return t.fonts.get(Lb(e))}function Lb(t){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"}[t])!=null?n:t}function Wr(t){if(!(!t||t==="auto")){if(/^[0-9a-f]{6}$/i.test(t))return t.toUpperCase();if(/^[0-9a-f]{8}$/i.test(t))return t.slice(2).toUpperCase()}}function Ac(t,e,n){let r=rc(e);if(r!==void 0)return Db(t,r/255);let o=rc(n);return o!==void 0?Wb(t,o/255):t}function rc(t){if(!t||!/^[0-9a-f]{2}$/i.test(t))return;let e=Number.parseInt(t,16);return Number.isFinite(e)?e:void 0}function Db(t,e){return Lc(t,n=>n+(255-n)*e)}function Wb(t,e){return Lc(t,n=>n*e)}function Lc(t,e){return [0,2,4].map(r=>Number.parseInt(t.slice(r,r+2),16)).map(r=>Math.max(0,Math.min(255,Math.round(e(r))))).map(r=>r.toString(16).toUpperCase().padStart(2,"0")).join("")}function st(t){if(!t)return;let e=t.getAttributeNS(W_NS,"val");return Dc(e)}function Dc(t){return t!=="0"&&t!=="false"&&t!=="off"}function Wc(t){if(t.namespaceURI!==W_NS||t.localName!=="sdt")return false;let e=q(t,W_NS,"sdtPr");return e?st(q(e,W_NS,"showingPlcHdr"))===true:false}function q(t,e,n){for(let r=0;r<t.childNodes.length;r++){let o=t.childNodes[r];if((o==null?void 0:o.nodeType)===1&&o.namespaceURI===e&&o.localName===n)return o}return null}function Bb(t,e,n){for(let r=t.childNodes.length-1;r>=0;r--){let o=t.childNodes[r];if((o==null?void 0:o.nodeType)===1&&o.namespaceURI===e&&o.localName===n)return o}return null}function yt(t,e,n){let r=[];for(let o=0;o<t.childNodes.length;o++){let i=t.childNodes[o];(i==null?void 0:i.nodeType)===1&&i.namespaceURI===e&&i.localName===n&&r.push(i);}return r}function ei(t,e,n){let r=t;for(let o of n)if(r=r?q(r,e,o):null,!r)return null;return r}function Fb(t,e,n,r,o,i){var l,d;let a=t.commentIdx.get(e);if(!(a!=null&&a.comment))return null;let s=ds(a.comment,"t");return {kind:"comment",id:`comment:${e}`,commentId:e,paraId:n,from:r,to:o,text:i.slice(r,o),rangeKind:r===0&&o===i.length?"paragraph":"text",author:(l=a.comment.getAttributeNS(W_NS,"author"))!=null?l:"",date:(d=a.comment.getAttributeNS(W_NS,"date"))!=null?d:"",body:s}}function Hb(t,e){var r,o;let n=[];for(let[i,a]of t.commentIdx)e.has(i)||!a.comment||n.push({id:i,author:(r=a.comment.getAttributeNS(W_NS,"author"))!=null?r:"",date:(o=a.comment.getAttributeNS(W_NS,"date"))!=null?o:"",text:ds(a.comment,"t"),rangeKind:"complex"});return n}function oc(t,e){if(t.namespaceURI!==W_NS||t.localName!==e)return null;let n=t.getAttributeNS(W_NS,"id");if(n===null)return null;let r=Number(n);return Number.isFinite(r)?r:null}function Bc(t,e=false){let n="";function r(o){var a;if(o.nodeType!==1)return;let i=o;if(i.namespaceURI===W_NS&&!(e&&Wc(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(W_NS,"type");(s===null||s===""||s==="textWrapping")&&(n+=`
|
|
4
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(t),n}function Ob(t){for(let e=0;e<t.childNodes.length;e++){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===W_NS&&(r.localName==="fldChar"||r.localName==="instrText"))return true}return false}function $b(t){var e;if(t.localName==="t")return (e=t.textContent)!=null?e:"";if(t.localName==="tab"||t.localName==="ptab")return " ";if(t.localName==="br"){let n=t.getAttributeNS(W_NS,"type");return n===null||n===""||n==="textWrapping"?`
|
|
5
|
-
`:""}return t.localName==="delText"||t.localName==="commentReference"||t.localName==="instrText"?"":Bc(t)}function ic(t){var r;let n=(r=t.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 ds(t,e){var o,i;let n=t.getElementsByTagNameNS(W_NS,e),r="";for(let a=0;a<n.length;a++)r+=(i=(o=n[a])==null?void 0:o.textContent)!=null?i:"";return r}function zb(t){return t.namespaceURI===W_NS&&(t.localName==="drawing"||t.localName==="pict")}function Vb(t){for(let e=0;e<t.childNodes.length;e++){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===W_NS&&r.localName==="br"&&r.getAttributeNS(W_NS,"type")==="page")return true}return false}function Gb(t){let e=[];for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];(r==null?void 0:r.nodeType)===1&&r.namespaceURI===W_NS&&(r.localName==="drawing"||r.localName==="pict")&&e.push(r);}return e}function jb(t){let e=t.parentElement;for(;e&&!(e.namespaceURI===Ja&&e.localName==="Fallback");)e=e.parentElement;let n=e==null?void 0:e.parentElement;if(!n||n.namespaceURI!==Ja||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!==Ja||o.localName!=="Choice")&&o.getElementsByTagNameNS(W_NS,"drawing").length>0)return true}return false}function Ub(t,e,n,r){var s,l;let o=t.getElementsByTagNameNS(ts,"line")[0];if(!o||!o.hasAttributeNS(Rg,"gfxdata"))return false;let i=new Set,a=e.getElementsByTagNameNS(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 Kb(t,e){var s;let n=t==null?void 0:t.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=Wr(l==null?void 0:l.getAttribute("val")),a!=null||(a=ls(e,(s=d==null?void 0:d.getAttribute("val"))!=null?s:null)),a!=null||(a=Wr(u==null?void 0:u.getAttribute("lastClr")));}return v(v({},a?{color:`#${a}`}:{}),o!==void 0?{width:o}:{})}function _b(t,e,n){var u,p;if(t.namespaceURI!==W_NS||t.localName!=="pict")return null;let r=t.getElementsByTagNameNS(ts,"line")[0];if(!r)return null;let o=qb(r.getAttribute("style")),i=r.getElementsByTagNameNS(ts,"stroke")[0],a=es(o.get("width")),s=es(o.get("height")),l=Xb((u=i==null?void 0:i.getAttribute("color"))!=null?u:r.getAttribute("strokecolor")),d=es((p=i==null?void 0:i.getAttribute("weight"))!=null?p:r.getAttribute("strokeweight"));return v(v(v(v({kind:"drawing",drawingId:`${e}: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 qb(t){var n;let e=new Map;for(let r of (n=t==null?void 0:t.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&&e.set(i,a);}return e}function es(t){var o,i;if(!t)return;let e=/^(-?(?:\d+\.?\d*|\.\d+))(pt|px|in|cm|mm)?$/i.exec(t.trim());if(!e)return;let n=Number(e[1]);if(!Number.isFinite(n))return;let r=(i=(o=e[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 Xb(t){if(!t)return;let e=t.trim();if(/^#[0-9a-f]{6}$/i.test(e))return e.toUpperCase();if(/^[0-9a-f]{6}$/i.test(e))return `#${e.toUpperCase()}`}function Yb(t){for(let e=0;e<t.childNodes.length;e++){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI!==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 Zb(t){let e=t.blocks.filter(o=>o.type==="paragraph"),n=Oc(t),r=Qb(t);return {topLevelBlocks:t.blocks.length,topLevelParagraphs:e.length,tableBlocks:t.tables.length,tableParagraphs:n.length,allParagraphs:r.length,topLevelImages:cs(e),tableImages:cs(n),allImages:cs(r),topLevelDrawings:us(e),tableDrawings:us(n),allDrawings:us(r),pageBreaks:nw(r)}}function nI(t,e){var i;let n=Zb(t),r=e?Jb(e):[],o=tw(r);return {editor:n,native:{blocks:(i=e==null?void 0:e.blocks.length)!=null?i:0,paragraphs:r.length,images:o,drawings:Fc(r),pageBreaks:Hc(r)},missing:{paragraphs:n.allParagraphs-r.length,images:n.allImages-o,drawings:n.allDrawings-Fc(r),pageBreaks:n.pageBreaks-Hc(r)}}}function rI(t){return [...Fr(t.blocks),...t.headers.flatMap(e=>Fr(e.blocks)),...t.footers.flatMap(e=>Fr(e.blocks))]}function Jb(t){return Fr(t.blocks)}function Fr(t){return t.flatMap(e=>e.kind==="paragraph"?[e]:e.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:Fr(r.blocks))))}function Qb(t){return [...t.blocks.filter(n=>n.type==="paragraph"),...Oc(t)]}function Oc(t){return ew(t.tables)}function ew(t){return t.flatMap(e=>e.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:r.paragraphs)))}function cs(t){return t.reduce((e,n)=>e+n.segments.filter(r=>r.kind==="image").length,0)}function us(t){return t.reduce((e,n)=>e+n.segments.filter(r=>r.kind==="drawing").length,0)}function tw(t){return t.reduce((e,n)=>e+n.content.filter(r=>r.kind==="image").length,0)}function Fc(t){return t.reduce((e,n)=>e+n.content.filter(r=>r.kind==="drawing").length,0)}function nw(t){return t.reduce((e,n)=>e+n.segments.filter(r=>r.kind==="placeholder"&&r.placeholderKind==="pageBreak").length,0)}function Hc(t){return t.reduce((e,n)=>e+n.content.filter(r=>r.kind==="pageBreak").length,0)}function Or(t){var o,i,a,s,l,d,u,p;let e={};if(!t)return Hr(e);ow(t,e),t.alignment&&(e["text-align"]=iw(t.alignment)),((o=t.indent)==null?void 0:o.left)!==void 0&&rw(t)&&(e["margin-left"]=Ct(t.indent.left)),((i=t.indent)==null?void 0:i.right)!==void 0&&(e["margin-right"]=Ct(t.indent.right)),((a=t.indent)==null?void 0:a.firstLine)!==void 0&&(e["text-indent"]=Ct(t.indent.firstLine)),((s=t.spacing)==null?void 0:s.before)!==void 0&&(e["margin-top"]=Ct(t.spacing.before)),((l=t.spacing)==null?void 0:l.after)!==void 0&&(e["margin-bottom"]=Ct(t.spacing.after));let n=fw((d=t.spacing)==null?void 0:d.line,(u=t.spacing)==null?void 0:u.lineRule,t.snapToGrid);n&&(e["line-height"]=n),t.fontSize!==void 0&&(e["font-size"]=`${t.fontSize}pt`),t.fontFamily!==void 0&&(e["font-family"]=qt(t.fontFamily)),t.characterSpacing!==void 0&&(e["letter-spacing"]=Ct(t.characterSpacing)),t.bold!==void 0&&(e["font-weight"]=t.bold?"700":"400");let r=(p=$c(t.shading))!=null?p:zc(t.highlight);return r&&(e["background-color"]=r),dw(t,e),Hr(e)}function rw(t){var e;return !(t.numbering&&((e=t.indent)==null?void 0:e.left)===0&&t.indent.firstLine===void 0)}function ow(t,e){t.outlineLevel!==void 0&&(t.outlineLevel===0?(e["font-size"]="16pt",e["font-weight"]="700",e["line-height"]="1.28"):t.outlineLevel===1?(e["font-size"]="14pt",e["font-weight"]="700",e["line-height"]="1.3"):t.outlineLevel===2&&(e["font-size"]="12pt",e["font-weight"]="700",e["line-height"]="1.35"));}function Jn(t){var o;let e={};if(!t)return Hr(e);t.bold!==void 0&&(e["font-weight"]=t.bold?"700":"400"),t.italic!==void 0&&(e["font-style"]=t.italic?"italic":"normal"),sw(t,e),t.caps&&(e["text-transform"]="uppercase"),t.smallCaps&&(e["font-variant-caps"]="small-caps"),t.fontSize!==void 0&&(e["font-size"]=`${t.fontSize}pt`),t.fontFamily!==void 0&&(e["font-family"]=qt(t.fontFamily)),t.characterSpacing!==void 0&&(e["letter-spacing"]=Ct(t.characterSpacing)),t.verticalAlign&&(e["vertical-align"]=lw(t.verticalAlign),t.verticalAlign!=="baseline"&&t.fontSize===void 0&&(e["font-size"]="smaller"));let n=Qn(t.color);n&&(e.color=n);let r=(o=zc(t.highlight))!=null?o:$c(t.shading);return r&&(e["background-color"]=r),Hr(e)}function si(t){var r;let e={};t.width!==void 0&&t.width>0&&t.widthType!=="auto"&&(e.width=t.widthType==="pct"?`${t.width/50}%`:Ct(t.width)),t.margin&&(t.margin.top!==void 0&&(e["padding-top"]=Ct(t.margin.top)),t.margin.right!==void 0&&(e["padding-right"]=Ct(t.margin.right)),t.margin.bottom!==void 0&&(e["padding-bottom"]=Ct(t.margin.bottom)),t.margin.left!==void 0&&(e["padding-left"]=Ct(t.margin.left)));let n=Qn((r=t.shading)==null?void 0:r.fill);return n&&(e["background-color"]=n),t.verticalAlignment&&(e["vertical-align"]=aw(t.verticalAlignment)),t.noWrap&&(e["white-space"]="nowrap"),t.borders&&(ai(e,"top",t.borders.top),ai(e,"right",t.borders.right),ai(e,"bottom",t.borders.bottom),ai(e,"left",t.borders.left)),Hr(e)}function Qn(t){return !t||t==="auto"?null:/^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}function $c(t){return !t||t.val==="nil"||t.val==="clear"&&!t.fill?null:Qn(t.fill)}function zc(t){var n;return !t||t==="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"}[t])!=null?n:Qn(t)}function Hr(t){return {declarations:t,cssText:Object.entries(t).map(([e,n])=>`${e}: ${n}`).join("; ")}}function iw(t){return t==="both"||t==="distribute"?"justify":t}function aw(t){return t==="center"||t==="both"?"middle":t}function sw(t,e){let n=[];if(t.underline&&n.push("underline"),(t.strike||t.doubleStrike)&&n.push("line-through"),n.length>0){e["text-decoration-line"]=n.join(" "),t.doubleStrike&&(e["text-decoration-style"]="double");return}(t.underline===false||t.strike===false||t.doubleStrike===false)&&(e["text-decoration-line"]="none");}function lw(t){return t==="superscript"?"super":t==="subscript"?"sub":"baseline"}function dw(t,e){var r,o,i;let n=(r=t.borders)!=null?r:t.borderBottom?{bottom:t.borderBottom}:void 0;n&&(ii(e,"top",n.top),ii(e,"right",n.right),ii(e,"bottom",(o=n.bottom)!=null?o:n.between),ii(e,"left",(i=n.left)!=null?i:n.bar));}function ii(t,e,n){let r=cw(n);r&&(t[`border-${e}`]=r,t[`padding-${e}`]=(n==null?void 0:n.space)!==void 0?`${n.space}pt`:"4pt");}function cw(t){var o;if(!t||t.val==="none"||t.val==="nil")return null;let e=(o=Qn(t.color))!=null?o:"#000000",n=t.size!==void 0?Math.max(.75,t.size/8):.75,r=t.val==="double"?"double":"solid";return `${n}pt ${r} ${e}`}function ai(t,e,n){if(!n)return;let r=uw(n);t[`border-${e}`]=r!=null?r:"0";}function uw(t){var o;if(t.val==="none"||t.val==="nil"||t.size===0)return null;let e=(o=Qn(t.color))!=null?o:"#000000",n=t.size!==void 0?Math.max(.5,t.size/8):.75,r=t.val==="double"?"double":"solid";return `${n}pt ${r} ${e}`}function fw(t,e,n){return t===void 0?null:e==="exact"||e==="atLeast"?Ct(t):n!==true?String(t/240):`calc(var(--coco-word-doc-grid-line-height, 1em) * ${t/240})`}function Ct(t){return `${t/20}pt`}function lI(t,e={}){var l,d;let n=ww((l=e.startBlock)!=null?l:0,0,t.blocks.length),r=Math.max(1,Math.floor((d=e.maxChars)!=null?d:12e3)),o=[],i=19,a=n;for(;a<t.blocks.length;){let u=Vc(t.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>
|
|
5
|
+
`:""}return t.localName==="delText"||t.localName==="commentReference"||t.localName==="instrText"?"":Bc(t)}function ic(t){var r;let n=(r=t.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 ds(t,e){var o,i;let n=t.getElementsByTagNameNS(W_NS,e),r="";for(let a=0;a<n.length;a++)r+=(i=(o=n[a])==null?void 0:o.textContent)!=null?i:"";return r}function zb(t){return t.namespaceURI===W_NS&&(t.localName==="drawing"||t.localName==="pict")}function Vb(t){for(let e=0;e<t.childNodes.length;e++){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI===W_NS&&r.localName==="br"&&r.getAttributeNS(W_NS,"type")==="page")return true}return false}function Gb(t){let e=[];for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];(r==null?void 0:r.nodeType)===1&&r.namespaceURI===W_NS&&(r.localName==="drawing"||r.localName==="pict")&&e.push(r);}return e}function jb(t){let e=t.parentElement;for(;e&&!(e.namespaceURI===Ja&&e.localName==="Fallback");)e=e.parentElement;let n=e==null?void 0:e.parentElement;if(!n||n.namespaceURI!==Ja||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!==Ja||o.localName!=="Choice")&&o.getElementsByTagNameNS(W_NS,"drawing").length>0)return true}return false}function Ub(t,e,n,r){var s,l;let o=t.getElementsByTagNameNS(ts,"line")[0];if(!o||!o.hasAttributeNS(Rg,"gfxdata"))return false;let i=new Set,a=e.getElementsByTagNameNS(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 Kb(t,e){var s;let n=t==null?void 0:t.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=Wr(l==null?void 0:l.getAttribute("val")),a!=null||(a=ls(e,(s=d==null?void 0:d.getAttribute("val"))!=null?s:null)),a!=null||(a=Wr(u==null?void 0:u.getAttribute("lastClr")));}return v(v({},a?{color:`#${a}`}:{}),o!==void 0?{width:o}:{})}function _b(t,e,n){var u,f;if(t.namespaceURI!==W_NS||t.localName!=="pict")return null;let r=t.getElementsByTagNameNS(ts,"line")[0];if(!r)return null;let o=qb(r.getAttribute("style")),i=r.getElementsByTagNameNS(ts,"stroke")[0],a=es(o.get("width")),s=es(o.get("height")),l=Xb((u=i==null?void 0:i.getAttribute("color"))!=null?u:r.getAttribute("strokecolor")),d=es((f=i==null?void 0:i.getAttribute("weight"))!=null?f:r.getAttribute("strokeweight"));return v(v(v(v({kind:"drawing",drawingId:`${e}: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 qb(t){var n;let e=new Map;for(let r of (n=t==null?void 0:t.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&&e.set(i,a);}return e}function es(t){var o,i;if(!t)return;let e=/^(-?(?:\d+\.?\d*|\.\d+))(pt|px|in|cm|mm)?$/i.exec(t.trim());if(!e)return;let n=Number(e[1]);if(!Number.isFinite(n))return;let r=(i=(o=e[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 Xb(t){if(!t)return;let e=t.trim();if(/^#[0-9a-f]{6}$/i.test(e))return e.toUpperCase();if(/^[0-9a-f]{6}$/i.test(e))return `#${e.toUpperCase()}`}function Yb(t){for(let e=0;e<t.childNodes.length;e++){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(r.namespaceURI!==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 Zb(t){let e=t.blocks.filter(o=>o.type==="paragraph"),n=Oc(t),r=Qb(t);return {topLevelBlocks:t.blocks.length,topLevelParagraphs:e.length,tableBlocks:t.tables.length,tableParagraphs:n.length,allParagraphs:r.length,topLevelImages:cs(e),tableImages:cs(n),allImages:cs(r),topLevelDrawings:us(e),tableDrawings:us(n),allDrawings:us(r),pageBreaks:nw(r)}}function nI(t,e){var i;let n=Zb(t),r=e?Jb(e):[],o=tw(r);return {editor:n,native:{blocks:(i=e==null?void 0:e.blocks.length)!=null?i:0,paragraphs:r.length,images:o,drawings:Fc(r),pageBreaks:Hc(r)},missing:{paragraphs:n.allParagraphs-r.length,images:n.allImages-o,drawings:n.allDrawings-Fc(r),pageBreaks:n.pageBreaks-Hc(r)}}}function rI(t){return [...Fr(t.blocks),...t.headers.flatMap(e=>Fr(e.blocks)),...t.footers.flatMap(e=>Fr(e.blocks))]}function Jb(t){return Fr(t.blocks)}function Fr(t){return t.flatMap(e=>e.kind==="paragraph"?[e]:e.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:Fr(r.blocks))))}function Qb(t){return [...t.blocks.filter(n=>n.type==="paragraph"),...Oc(t)]}function Oc(t){return ew(t.tables)}function ew(t){return t.flatMap(e=>e.rows.flatMap(n=>n.cells.flatMap(r=>r.vMerge==="continue"?[]:r.paragraphs)))}function cs(t){return t.reduce((e,n)=>e+n.segments.filter(r=>r.kind==="image").length,0)}function us(t){return t.reduce((e,n)=>e+n.segments.filter(r=>r.kind==="drawing").length,0)}function tw(t){return t.reduce((e,n)=>e+n.content.filter(r=>r.kind==="image").length,0)}function Fc(t){return t.reduce((e,n)=>e+n.content.filter(r=>r.kind==="drawing").length,0)}function nw(t){return t.reduce((e,n)=>e+n.segments.filter(r=>r.kind==="placeholder"&&r.placeholderKind==="pageBreak").length,0)}function Hc(t){return t.reduce((e,n)=>e+n.content.filter(r=>r.kind==="pageBreak").length,0)}function Or(t){var o,i,a,s,l,d,u,f;let e={};if(!t)return Hr(e);ow(t,e),t.alignment&&(e["text-align"]=iw(t.alignment)),((o=t.indent)==null?void 0:o.left)!==void 0&&rw(t)&&(e["margin-left"]=Ct(t.indent.left)),((i=t.indent)==null?void 0:i.right)!==void 0&&(e["margin-right"]=Ct(t.indent.right)),((a=t.indent)==null?void 0:a.firstLine)!==void 0&&(e["text-indent"]=Ct(t.indent.firstLine)),((s=t.spacing)==null?void 0:s.before)!==void 0&&(e["margin-top"]=Ct(t.spacing.before)),((l=t.spacing)==null?void 0:l.after)!==void 0&&(e["margin-bottom"]=Ct(t.spacing.after));let n=fw((d=t.spacing)==null?void 0:d.line,(u=t.spacing)==null?void 0:u.lineRule,t.snapToGrid);n&&(e["line-height"]=n),t.fontSize!==void 0&&(e["font-size"]=`${t.fontSize}pt`),t.fontFamily!==void 0&&(e["font-family"]=qt(t.fontFamily)),t.characterSpacing!==void 0&&(e["letter-spacing"]=Ct(t.characterSpacing)),t.bold!==void 0&&(e["font-weight"]=t.bold?"700":"400");let r=(f=$c(t.shading))!=null?f:zc(t.highlight);return r&&(e["background-color"]=r),dw(t,e),Hr(e)}function rw(t){var e;return !(t.numbering&&((e=t.indent)==null?void 0:e.left)===0&&t.indent.firstLine===void 0)}function ow(t,e){t.outlineLevel!==void 0&&(t.outlineLevel===0?(e["font-size"]="16pt",e["font-weight"]="700",e["line-height"]="1.28"):t.outlineLevel===1?(e["font-size"]="14pt",e["font-weight"]="700",e["line-height"]="1.3"):t.outlineLevel===2&&(e["font-size"]="12pt",e["font-weight"]="700",e["line-height"]="1.35"));}function Jn(t){var o;let e={};if(!t)return Hr(e);t.bold!==void 0&&(e["font-weight"]=t.bold?"700":"400"),t.italic!==void 0&&(e["font-style"]=t.italic?"italic":"normal"),sw(t,e),t.caps&&(e["text-transform"]="uppercase"),t.smallCaps&&(e["font-variant-caps"]="small-caps"),t.fontSize!==void 0&&(e["font-size"]=`${t.fontSize}pt`),t.fontFamily!==void 0&&(e["font-family"]=qt(t.fontFamily)),t.characterSpacing!==void 0&&(e["letter-spacing"]=Ct(t.characterSpacing)),t.verticalAlign&&(e["vertical-align"]=lw(t.verticalAlign),t.verticalAlign!=="baseline"&&t.fontSize===void 0&&(e["font-size"]="smaller"));let n=Qn(t.color);n&&(e.color=n);let r=(o=zc(t.highlight))!=null?o:$c(t.shading);return r&&(e["background-color"]=r),Hr(e)}function si(t){var r;let e={};t.width!==void 0&&t.width>0&&t.widthType!=="auto"&&(e.width=t.widthType==="pct"?`${t.width/50}%`:Ct(t.width)),t.margin&&(t.margin.top!==void 0&&(e["padding-top"]=Ct(t.margin.top)),t.margin.right!==void 0&&(e["padding-right"]=Ct(t.margin.right)),t.margin.bottom!==void 0&&(e["padding-bottom"]=Ct(t.margin.bottom)),t.margin.left!==void 0&&(e["padding-left"]=Ct(t.margin.left)));let n=Qn((r=t.shading)==null?void 0:r.fill);return n&&(e["background-color"]=n),t.verticalAlignment&&(e["vertical-align"]=aw(t.verticalAlignment)),t.noWrap&&(e["white-space"]="nowrap"),t.borders&&(ai(e,"top",t.borders.top),ai(e,"right",t.borders.right),ai(e,"bottom",t.borders.bottom),ai(e,"left",t.borders.left)),Hr(e)}function Qn(t){return !t||t==="auto"?null:/^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}function $c(t){return !t||t.val==="nil"||t.val==="clear"&&!t.fill?null:Qn(t.fill)}function zc(t){var n;return !t||t==="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"}[t])!=null?n:Qn(t)}function Hr(t){return {declarations:t,cssText:Object.entries(t).map(([e,n])=>`${e}: ${n}`).join("; ")}}function iw(t){return t==="both"||t==="distribute"?"justify":t}function aw(t){return t==="center"||t==="both"?"middle":t}function sw(t,e){let n=[];if(t.underline&&n.push("underline"),(t.strike||t.doubleStrike)&&n.push("line-through"),n.length>0){e["text-decoration-line"]=n.join(" "),t.doubleStrike&&(e["text-decoration-style"]="double");return}(t.underline===false||t.strike===false||t.doubleStrike===false)&&(e["text-decoration-line"]="none");}function lw(t){return t==="superscript"?"super":t==="subscript"?"sub":"baseline"}function dw(t,e){var r,o,i;let n=(r=t.borders)!=null?r:t.borderBottom?{bottom:t.borderBottom}:void 0;n&&(ii(e,"top",n.top),ii(e,"right",n.right),ii(e,"bottom",(o=n.bottom)!=null?o:n.between),ii(e,"left",(i=n.left)!=null?i:n.bar));}function ii(t,e,n){let r=cw(n);r&&(t[`border-${e}`]=r,t[`padding-${e}`]=(n==null?void 0:n.space)!==void 0?`${n.space}pt`:"4pt");}function cw(t){var o;if(!t||t.val==="none"||t.val==="nil")return null;let e=(o=Qn(t.color))!=null?o:"#000000",n=t.size!==void 0?Math.max(.75,t.size/8):.75,r=t.val==="double"?"double":"solid";return `${n}pt ${r} ${e}`}function ai(t,e,n){if(!n)return;let r=uw(n);t[`border-${e}`]=r!=null?r:"0";}function uw(t){var o;if(t.val==="none"||t.val==="nil"||t.size===0)return null;let e=(o=Qn(t.color))!=null?o:"#000000",n=t.size!==void 0?Math.max(.5,t.size/8):.75,r=t.val==="double"?"double":"solid";return `${n}pt ${r} ${e}`}function fw(t,e,n){return t===void 0?null:e==="exact"||e==="atLeast"?Ct(t):n!==true?String(t/240):`calc(var(--coco-word-doc-grid-line-height, 1em) * ${t/240})`}function Ct(t){return `${t/20}pt`}function lI(t,e={}){var l,d;let n=ww((l=e.startBlock)!=null?l:0,0,t.blocks.length),r=Math.max(1,Math.floor((d=e.maxChars)!=null?d:12e3)),o=[],i=19,a=n;for(;a<t.blocks.length;){let u=Vc(t.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
8
|
</article>`:"<article></article>";return a<t.blocks.length?{html:s,nextBlock:a}:{html:s}}function Vc(t){return t.type==="table"?bw(t):pw(t)}function pw(t){let e=hw(t),n=Or(t.format).cssText,r=[`data-para-id="${Xt(t.paraId)}"`,n?`style="${Xt(n)}"`:""].filter(Boolean).join(" "),o=mw(t);return `<${e} ${r}>${o||" "}</${e}>`}function hw(t){var n;let e=(n=t.format)==null?void 0:n.outlineLevel;return e===void 0||e<0||e>5?"p":`h${e+1}`}function mw(t){var r,o;let e=(o=(r=t.format)==null?void 0:r.numbering)==null?void 0:o.label,n=e?`${fs(e)} `:"";return t.segments.length===0?n+li(t.text):n+t.segments.map(gw).join("")}function gw(t){var o,i;if(t.kind==="image")return `<img data-drawing-id="${Xt(t.drawingId)}" alt="[\u56FE\u7247]">`;if(t.kind==="drawing"){let a=t.text?li(t.text):"[\u7ED8\u56FE]";return `<span data-drawing-id="${Xt(t.drawingId)}">${a}</span>`}if(t.kind==="placeholder")return t.placeholderKind==="pageBreak"?'<br data-page-break="true">':`<span data-object="${Xt(t.placeholderKind)}">[\u5BF9\u8C61]</span>`;if(t.kind==="field"){let a=li((o=t.cachedText)!=null?o:"");return `<span data-field="${Xt(t.fieldKind)}">${a}</span>`}let e=Jn(t.format).cssText,n=li(t.text),r=e?` style="${Xt(e)}"`:"";if(t.kind==="revision"){let a=t.revisionKind==="delete"?"del":"ins";return `<${a}${r}>${n}</${a}>`}if(t.hyperlink){let a=(i=t.hyperlink.target)!=null?i:t.hyperlink.anchor;return `<a${a?` href="${Xt(a)}"`:""}${r}>${n}</a>`}return e?`<span${r}>${n}</span>`:n}function bw(t){let e=t.rows.map(n=>`<tr>${n.cells.map(o=>{let i=si(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(Vc).join(`
|
|
9
9
|
`);return `<td${a?` ${a}`:""}>${s||" "}</td>`}).join("")}</tr>`).join(`
|
|
10
10
|
`);return `<table data-table-id="${Xt(t.tableId)}">
|
|
11
11
|
${e}
|
|
12
|
-
</table>`}function li(t){return fs(t).replace(/\t/g,"	").replace(/\r\n|\r|\n/g,"<br>")}function fs(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Xt(t){return fs(t).replace(/"/g,""")}function ww(t,e,n){return Math.min(n,Math.max(e,Math.floor(t)))}function hs(t){return F(v(v({kind:"word"},t.defaults?{defaults:t.defaults}:{}),t.pageLayout?{pageLayout:t.pageLayout}:{}),{sections:t.sections,headers:t.headers.map(Gc),footers:t.footers.map(Gc),blocks:t.blocks.map(e=>gs(e))})}function J(t,e){var n,r;return (r=(n=ve(t,e))==null?void 0:n.paragraph)!=null?r:null}function ms(t,e){var r,o;let n=ve(t,e);return (o=(r=n==null?void 0:n.previous)==null?void 0:r.paraId)!=null?o:null}function ve(t,e){var n,r;return (r=(n=ps(t.blocks,e))!=null?n:t.headers.reduce((o,i)=>o!=null?o:ps(i.blocks,e),null))!=null?r:t.footers.reduce((o,i)=>o!=null?o:ps(i.blocks,e),null)}function rn(t,e){var n,r;return (r=(n=ci(t.blocks,e))!=null?n:t.headers.reduce((o,i)=>o!=null?o:ci(i.blocks,e),null))!=null?r:t.footers.reduce((o,i)=>o!=null?o:ci(i.blocks,e),null)}function Oe(t,e){var n,r;return (r=(n=di(t.blocks,e))!=null?n:t.headers.reduce((o,i)=>o!=null?o:di(i.blocks,e),null))!=null?r:t.footers.reduce((o,i)=>o!=null?o:di(i.blocks,e),null)}function di(t,e){for(let n=0;n<t.length;n+=1){let r=t[n];if((r==null?void 0:r.kind)==="table"){if(r.tableId===e)return {table:r,container:t,tableIndex:n};for(let o of r.rows)for(let i of o.cells){let a=di(i.blocks,e);if(a)return a}}}return null}function ci(t,e){for(let n=0;n<t.length;n+=1){let r=t[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=ci(l.blocks,e);if(d)return d;if(l.blocks.some(u=>u.kind==="paragraph"&&u.paraId===e))return {table:r,container:t,tableIndex:n,row:i,rowIndex:o,cell:l,cellIndex:s,columnIndex:a};a+=Math.max(1,l.gridSpan);}}}return null}function ps(t,e){for(let n=0;n<t.length;n+=1){let r=t[n];if((r==null?void 0:r.kind)==="paragraph"&&r.paraId===e){let o=t[n-1];return {paragraph:r,previous:(o==null?void 0:o.kind)==="paragraph"?o:null,container:t,index:n,insertAfter(i){t.splice(n+1,0,i);},remove(){t.splice(n,1);}}}if((r==null?void 0:r.kind)==="table"){let o=Cw(r,e);if(o)return o}}return null}function _e(t){return [...$r(t.blocks),...t.headers.flatMap(e=>$r(e.blocks)),...t.footers.flatMap(e=>$r(e.blocks))]}function $r(t){return t.flatMap(e=>e.kind==="paragraph"?[e]:e.rows.flatMap(n=>n.cells.flatMap(r=>$r(r.blocks))))}function Te(t){return t.content.map(e=>{var n;return e.kind==="text"?e.text:e.kind==="field"?(n=e.cachedText)!=null?n:"\uFFFC":e.kind==="drawing"&&e.text?e.text:"\uFFFC"}).join("")}function Wn(t){let e=new Set(_e(t).map(r=>r.paraId).filter(Boolean)),n="";do n=Math.floor(Math.random()*4294967295).toString(16).toUpperCase().padStart(8,"0");while(!n||e.has(n));return n}function gs(t){return t.type==="table"?F(v(v(F(v({kind:"table",tableId:t.tableId},t.tableStyleId?{tableStyleId:t.tableStyleId}:{}),{columnWidths:t.columnWidths}),t.layout?{layout:t.layout}:{}),t.borders?{borders:t.borders}:{}),{rows:t.rows.map(e=>F(v(v(v({},e.height?{height:e.height}:{}),e.isHeader?{isHeader:true}:{}),e.cantSplit?{cantSplit:true}:{}),{cells:e.cells.map(n=>xw(n))}))}):jc(t)}function Gc(t){return {kind:t.kind,partName:t.partName,blocks:t.blocks.map(e=>gs(e))}}function xw(t){var o;let n=((o=t.blocks)!=null?o:t.paragraphs).map(i=>gs(i)),r={gridSpan:t.gridSpan,blocks:n,paragraphs:$r(n)};return t.rowSpan!==void 0&&(r.rowSpan=t.rowSpan),t.vMerge!==void 0&&(r.vMerge=t.vMerge),t.width!==void 0&&(r.width=t.width),t.widthType!==void 0&&(r.widthType=t.widthType),t.margin!==void 0&&(r.margin=t.margin),t.borders!==void 0&&(r.borders=t.borders),t.shading!==void 0&&(r.shading=t.shading),t.verticalAlignment!==void 0&&(r.verticalAlignment=t.verticalAlignment),t.noWrap!==void 0&&(r.noWrap=t.noWrap),r}function jc(t){var n,r;let e=t.spans.filter(o=>o.kind==="comment");return {kind:"paragraph",paraId:t.paraId,story:t.story,styleId:(n=t.styleId)!=null?n:null,format:(r=t.format)!=null?r:null,content:t.segments.flatMap(o=>o.kind==="text"?Sw(o,e):o.kind==="revision"?vw(o):o.kind==="field"?yw(o):o.kind==="image"?kw(o):o.kind==="drawing"?Ew(o):o.kind==="placeholder"&&o.placeholderKind==="pageBreak"?[{kind:"pageBreak"}]:[])}}function yw(t){var e;return [F(v({kind:"field",fieldKind:t.fieldKind,instruction:t.instruction},t.cachedText!==void 0?{cachedText:t.cachedText}:{}),{format:(e=t.format)!=null?e:null})]}function vw(t){var e;return t.text.length===0?[]:[{kind:"text",text:t.text,format:(e=t.format)!=null?e:null,marks:[{kind:"revision",id:`revision:${t.revisionId}`,revisionId:t.revisionId,revisionKind:t.revisionKind,author:t.author,date:t.date}]}]}function Sw(t,e){var o,i,a;if(t.text.length===0)return [];let n=[],r=t.from;for(let s of e){let l=Math.max(t.from,s.from),d=Math.min(t.to,s.to);d<=l||(l>r&&n.push(v({kind:"text",text:t.text.slice(r-t.from,l-t.from),format:(o=t.format)!=null?o:null},t.hyperlink?{hyperlink:v({},t.hyperlink)}:{})),n.push(F(v({kind:"text",text:t.text.slice(l-t.from,d-t.from),format:(i=t.format)!=null?i:null},t.hyperlink?{hyperlink:v({},t.hyperlink)}:{}),{marks:[{kind:"comment",id:s.id,commentId:s.commentId,author:s.author,date:s.date,body:s.body}]})),r=d);}return r<t.to&&n.push(v({kind:"text",text:t.text.slice(r-t.from),format:(a=t.format)!=null?a:null},t.hyperlink?{hyperlink:v({},t.hyperlink)}:{})),n}function kw(t){return [v(v(v(v(v({kind:"image",drawingId:t.drawingId,src:t.src},t.width!==void 0?{width:t.width}:{}),t.height!==void 0?{height:t.height}:{}),t.anchoringMode!==void 0?{anchoringMode:t.anchoringMode}:{}),t.wrap!==void 0?{wrap:t.wrap}:{}),t.position!==void 0?{position:t.position}:{})]}function Ew(t){let e={kind:"drawing",drawingId:t.drawingId,drawingKind:t.drawingKind};return t.text!==void 0&&(e.text=t.text),t.width!==void 0&&(e.width=t.width),t.height!==void 0&&(e.height=t.height),t.anchoringMode!==void 0&&(e.anchoringMode=t.anchoringMode),t.wrap!==void 0&&(e.wrap=t.wrap),t.position!==void 0&&(e.position=t.position),t.hasBorder!==void 0&&(e.hasBorder=t.hasBorder),t.hasFill!==void 0&&(e.hasFill=t.hasFill),t.isLineOrConnector!==void 0&&(e.isLineOrConnector=t.isLineOrConnector),t.strokeColor!==void 0&&(e.strokeColor=t.strokeColor),t.strokeWidth!==void 0&&(e.strokeWidth=t.strokeWidth),t.innerTextAlign!==void 0&&(e.innerTextAlign=t.innerTextAlign),t.paragraphs&&t.paragraphs.length>0&&(e.paragraphs=t.paragraphs.map(n=>jc(n))),[e]}function Cw(t,e){var n;for(let r of t.rows)for(let o of r.cells){let i=o.paragraphs.findIndex(s=>s.paraId===e),a=o.blocks.findIndex(s=>s.kind==="paragraph"&&s.paraId===e);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 ws(t){let e=Rw(t),n=t.cells.reduce((o,i)=>o+Uc(i),0),r=t.cells.reduce((o,i)=>o+Kc(i),0);return t.isHeader?{kind:"repeat-header",risks:e,textLength:r,paragraphCount:n}:e.includes("cant-split")?{kind:"keep-together",risks:e,textLength:r,paragraphCount:n}:e.length>0?{kind:"unsplittable",risks:e,textLength:r,paragraphCount:n}:r===0?{kind:"keep-together",risks:["empty-row"],textLength:r,paragraphCount:n}:n>t.cells.length?{kind:"block-fragmentable",risks:e,textLength:r,paragraphCount:n}:{kind:"text-fragmentable",risks:e,textLength:r,paragraphCount:n}}function fI(t){let e={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}};ui(t.blocks,e);for(let n of t.headers)ui(n.blocks,e);for(let n of t.footers)ui(n.blocks,e);return e}function pI(t,e){if(ws(t).kind!=="block-fragmentable"||e.cellBlockCounts.length!==t.cells.length)return null;let r=[],o=[],i=false,a=false;for(let s=0;s<t.cells.length;s+=1){let l=t.cells[s],d=Tw(l,e.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:F(v({},t),{height:void 0,cells:r}),tail:F(v({},t),{height:void 0,cells:o})}}function hI(t,e){if(ws(t).kind!=="text-fragmentable"||e.cellTextOffsets.length!==t.cells.length)return null;let r=[],o=[];for(let i=0;i<t.cells.length;i+=1){let a=Iw(t.cells[i],e.cellTextOffsets[i]);if(!a)return null;r.push(a.head),o.push(a.tail);}return {head:F(v({},t),{height:void 0,cells:r}),tail:F(v({},t),{height:void 0,cells:o})}}function Iw(t,e){if(t.blocks.length!==1)return null;let n=t.blocks[0];if(!n||n.kind!=="paragraph")return null;let r=Nw(n,e);return r?{head:F(v({},t),{blocks:[r.head],paragraphs:[r.head]}),tail:F(v({},t),{blocks:[r.tail],paragraphs:[r.tail]})}:null}function Nw(t,e){let n=t.content.reduce((a,s)=>a+(s.kind==="text"?s.text.length:0),0);if(!Number.isInteger(e)||e<=0||e>=n)return null;let r=[],o=[],i=0;for(let a of t.content){if(a.kind!=="text")return null;let s=i,l=i+a.text.length;if(i=l,l<=e){r.push(a);continue}if(s>=e){o.push(a);continue}let d=e-s;r.push(F(v({},a),{text:a.text.slice(0,d)})),o.push(F(v({},a),{text:a.text.slice(d)}));}return r.length===0||o.length===0?null:{head:F(v({},t),{content:r}),tail:F(v({},t),{content:o})}}function Tw(t,e){if(!Number.isInteger(e)||e<0||e>t.blocks.length)return null;let n=t.blocks.slice(0,e),r=t.blocks.slice(e);return n.length===0&&r.length===0||n.length===0||r.length===0?null:{head:F(v({},t),{blocks:n,paragraphs:n.flatMap(bs)}),tail:F(v({},t),{blocks:r,paragraphs:r.flatMap(bs)})}}function ui(t,e){for(let n of t)n.kind==="table"&&Pw(n,e);}function Pw(t,e){e.tables+=1;for(let n of t.rows){e.rows+=1;let r=ws(n);r.kind==="repeat-header"?e.repeatHeaderRows+=1:r.kind==="keep-together"?e.keepTogetherRows+=1:r.kind==="block-fragmentable"?e.blockFragmentableRows+=1:r.kind==="text-fragmentable"?e.textFragmentableRows+=1:e.unsplittableRows+=1;for(let o of r.risks)e.risks[o]+=1;for(let o of n.cells)ui(o.blocks,e);}}function Rw(t){var n;let e=new Set;t.cantSplit&&e.add("cant-split");for(let r of t.cells)((n=r.rowSpan)!=null?n:1)>1&&e.add("row-span"),(r.vMerge==="restart"||r.vMerge==="continue")&&e.add("vertical-merge"),Mw(r,e);return [...e]}function Mw(t,e){for(let n of t.blocks){if(n.kind==="table"){e.add("nested-table");continue}Aw(n,e);}}function Aw(t,e){for(let n of t.content)Lw(n,e);}function Lw(t,e){var n,r;(t.kind==="image"||t.kind==="drawing")&&e.add("media"),t.kind==="field"&&e.add("field"),t.kind==="pageBreak"&&e.add("page-break"),t.kind==="text"&&((n=t.marks)!=null&&n.some(o=>o.kind==="comment")&&e.add("comment"),(r=t.marks)!=null&&r.some(o=>o.kind==="revision")&&e.add("revision"));}function Uc(t){return t.blocks.reduce((e,n)=>n.kind==="paragraph"?e+1:e+n.rows.reduce((r,o)=>r+o.cells.reduce((i,a)=>i+Uc(a),0),0),0)}function Kc(t){return t.blocks.reduce((e,n)=>e+Dw(n),0)}function bs(t){return t.kind==="paragraph"?[t]:t.rows.flatMap(e=>e.cells.flatMap(n=>n.blocks.flatMap(bs)))}function Dw(t){return t.kind==="paragraph"?t.content.reduce((e,n)=>e+(n.kind==="text"?n.text.length:0),0):t.rows.reduce((e,n)=>e+n.cells.reduce((r,o)=>r+Kc(o),0),0)}function mn(t){return t?t.numFmt==="bullet"?"bullet":"numbered":null}function xs(t,e,n=0){let r=vs(n);return {numId:Ww(t,e),ilvl:r,numFmt:e==="bullet"?"bullet":Jc(r),lvlText:e==="bullet"?Zc(r):`%${r+1}.`,start:1}}function ys(t,e){var o,i;let n=vs(e),r=(o=mn(t))!=null?o:"numbered";return F(v({},t),{ilvl:n,numFmt:r==="bullet"?"bullet":Jc(n),lvlText:r==="bullet"?Zc(n):`%${n+1}.`,start:(i=t.start)!=null?i:1})}function fi(t){var n,r,o,i;let e=new Map;for(let a of _e(t)){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(mn(s)==="bullet"){s.label=Fw(s.lvlText);continue}let d=((i=e.get(l))!=null?i:((o=s.start)!=null?o:1)-1)+1;e.set(l,d),s.label=Hw(d,s.numFmt,s.lvlText);}}function Xc(t){return {left:(vs(t)+1)*720,firstLine:-360}}function Yc(t,e,n){let r=new Set(e);for(let o of e){let i=ve(t,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=Bw(s,n);if(l)return v({},l)}}return null}function Ww(t,e){let n=new Set(_e(t).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-${e}-${r}`,r+=1;while(n.has(o));return o}function Bw(t,e){var r;let n=(r=t.format)!=null&&r.hasNumbering?t.format.numbering:void 0;return !n||mn(n)!==e?null:n.numId.startsWith(`coco-${e}-`)?n:null}function vs(t){return Math.max(0,Math.min(8,Math.round(t)))}function Zc(t){return ["\u2022","\u25E6","\u25AA"][t%3]}function Jc(t){return ["decimal","lowerLetter","lowerRoman"][t%3]}function Fw(t){return (t==null?void 0:t.replace(/%\d+/g,"").trim())||"\u2022"}function Hw(t,e,n){let r=e==="lowerLetter"?_c(t,false):e==="upperLetter"?_c(t,true):e==="lowerRoman"?qc(t).toLowerCase():e==="upperRoman"?qc(t):String(t);return n?n.replace(/%\d+/g,r):`${r}.`}function _c(t,e){let n=Math.max(1,t),r="";for(;n>0;)n-=1,r=String.fromCharCode((e?65:97)+n%26)+r,n=Math.floor(n/26);return r}function qc(t){let e=Math.max(1,Math.min(3999,t)),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(;e>=o;)n+=i,e-=o;return n}function rt(t){return Ot(t)}function Gr(t){var n,r;if(t.rows.length===0)return false;let e=(r=(n=t.rows[0])==null?void 0:n.cells.length)!=null?r:0;return e>0&&t.rows.every(o=>o.cells.length===e&&o.cells.every(i=>i.gridSpan===1&&(i.rowSpan===void 0||i.rowSpan===1)&&i.vMerge==null))}function tu(t,e,n,r,o,i=()=>Wn(t),a=()=>_w(t)){var I,D,H,A,O,ee;let s=ve(t,e);if(!s||s.container!==t.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,Te(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,((D=(I=t.pageLayout)==null?void 0:I.width)!=null?D:11906)-((A=(H=t.pageLayout)==null?void 0:H.margin.left)!=null?A:1440)-((ee=(O=t.pageLayout)==null?void 0:O.margin.right)!=null?ee:1440)),x=Math.max(360,Math.floor(h/d)),S={kind:"table",tableId:g,columnWidths:Array.from({length:d},()=>x),layout:{width:x*d,widthType:"dxa",alignment:"left"},borders:Ss("000000"),rows:Array.from({length:l},()=>({cells:Array.from({length:d},()=>{let le={kind:"paragraph",paraId:i(),story:u.story,styleId:null,format:null,content:[{kind:"text",text:"",format:null}]};return {gridSpan:1,width:x,borders:Ss("000000"),blocks:[le],paragraphs:[le]}})}))},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:p,afterBlocks:Ot(k)}}function nu(t,e,n=()=>Wn(t)){var s,l,d;let r=Oe(t,e);if(!r||r.container!==t.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:e,rowIndex:0,columnIndex:0}],cursor:{paraId:i.paraId,offset:0},container:r.container,startIndex:r.tableIndex,beforeBlocks:a,afterBlocks:Ot([i])}}function ru(t,e,n,r=()=>Wn(t)){var u,p;let o=rn(t,e);if(!o||!Gr(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=$w(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,Cs(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 Es(t,e,n){var s;let r=rn(t,e);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=Qc(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=Qc(n.borderColor);if(n.borderColor!==null&&!l)return null;r.cell.borders=l?Ss(l):Ow(),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:e,offset:0}}}function tt(t,e){let n=Math.max(0,Math.min(e.anchor.rowIndex,e.focus.rowIndex)),r=Math.min(t.rows.length-1,Math.max(e.anchor.rowIndex,e.focus.rowIndex)),o=Math.max(0,Math.min(e.anchor.columnIndex,e.focus.columnIndex)),i=Math.max(e.anchor.columnIndex,e.focus.columnIndex),a=[];for(let s=n;s<=r;s+=1){let l=t.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 ou(t,e,n){let r=Oe(t,e);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,x=h[0],S=h.flatMap(I=>I.blocks.map(Yt)),k=S.flatMap(I=>I.kind==="paragraph"?[I]:Vr([I]));x.blocks=S,x.paragraphs=k,x.rowSpan=h.length,x.vMerge="restart";for(let I of h.slice(1)){let D=I.paragraphs[0];D&&(D.content=[{kind:"text",text:"",format:null}]),I.blocks=D?[D]:[],I.paragraphs=D?[D]:[],I.rowSpan=void 0,I.vMerge="continue";}return {change:{kind:"table",op:"merge-cells",tableId:e,rowIndex:o,columnIndex:a,endRowIndex:i},cursor:{paraId:x.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]:Vr([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:e,rowIndex:o,columnIndex:a,endColumnIndex:s},cursor:{paraId:u.cell.paragraphs[0].paraId,offset:0}})}function iu(t,e,n,r,o=()=>Wn(t)){var f,b;let i=Oe(t,e),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,x)=>!h||h.gridSpan!==1?true:x===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:e,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},()=>Cs(d,o));return a.cells.splice(l+1,0,...p),{change:{kind:"table",op:"split-cell",tableId:e,rowIndex:n,columnIndex:r},cursor:{paraId:d.paragraphs[0].paraId,offset:0}}}function au(t,e,n,r){let o=Oe(t,e);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=Es(t,l,r);d&&i.push(d.change);}return a&&i.length>0?{changes:i,cursor:a}:null}function su(t,e,n){var a;let r=Oe(t,e);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:e,rowIndex:l,columnIndex:d}));}return i&&o.length>0?{changes:o,cursor:i}:null}function lu(t,e,n,r){var u,p,f;let o=Oe(t,e);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 x=gn(b);if(d!=null||(d={paraId:x.paraId,offset:h.length}),b.paragraphs.map(I=>Te(I)).join(`
|
|
13
|
-
`)===h&&b.blocks.length===1)continue;let k=(
|
|
12
|
+
</table>`}function li(t){return fs(t).replace(/\t/g,"	").replace(/\r\n|\r|\n/g,"<br>")}function fs(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Xt(t){return fs(t).replace(/"/g,""")}function ww(t,e,n){return Math.min(n,Math.max(e,Math.floor(t)))}function hs(t){return H(v(v({kind:"word"},t.defaults?{defaults:t.defaults}:{}),t.pageLayout?{pageLayout:t.pageLayout}:{}),{sections:t.sections,headers:t.headers.map(Gc),footers:t.footers.map(Gc),blocks:t.blocks.map(e=>gs(e))})}function J(t,e){var n,r;return (r=(n=ve(t,e))==null?void 0:n.paragraph)!=null?r:null}function ms(t,e){var r,o;let n=ve(t,e);return (o=(r=n==null?void 0:n.previous)==null?void 0:r.paraId)!=null?o:null}function ve(t,e){var n,r;return (r=(n=ps(t.blocks,e))!=null?n:t.headers.reduce((o,i)=>o!=null?o:ps(i.blocks,e),null))!=null?r:t.footers.reduce((o,i)=>o!=null?o:ps(i.blocks,e),null)}function rn(t,e){var n,r;return (r=(n=ci(t.blocks,e))!=null?n:t.headers.reduce((o,i)=>o!=null?o:ci(i.blocks,e),null))!=null?r:t.footers.reduce((o,i)=>o!=null?o:ci(i.blocks,e),null)}function Oe(t,e){var n,r;return (r=(n=di(t.blocks,e))!=null?n:t.headers.reduce((o,i)=>o!=null?o:di(i.blocks,e),null))!=null?r:t.footers.reduce((o,i)=>o!=null?o:di(i.blocks,e),null)}function di(t,e){for(let n=0;n<t.length;n+=1){let r=t[n];if((r==null?void 0:r.kind)==="table"){if(r.tableId===e)return {table:r,container:t,tableIndex:n};for(let o of r.rows)for(let i of o.cells){let a=di(i.blocks,e);if(a)return a}}}return null}function ci(t,e){for(let n=0;n<t.length;n+=1){let r=t[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=ci(l.blocks,e);if(d)return d;if(l.blocks.some(u=>u.kind==="paragraph"&&u.paraId===e))return {table:r,container:t,tableIndex:n,row:i,rowIndex:o,cell:l,cellIndex:s,columnIndex:a};a+=Math.max(1,l.gridSpan);}}}return null}function ps(t,e){for(let n=0;n<t.length;n+=1){let r=t[n];if((r==null?void 0:r.kind)==="paragraph"&&r.paraId===e){let o=t[n-1];return {paragraph:r,previous:(o==null?void 0:o.kind)==="paragraph"?o:null,container:t,index:n,insertAfter(i){t.splice(n+1,0,i);},remove(){t.splice(n,1);}}}if((r==null?void 0:r.kind)==="table"){let o=Cw(r,e);if(o)return o}}return null}function _e(t){return [...$r(t.blocks),...t.headers.flatMap(e=>$r(e.blocks)),...t.footers.flatMap(e=>$r(e.blocks))]}function $r(t){return t.flatMap(e=>e.kind==="paragraph"?[e]:e.rows.flatMap(n=>n.cells.flatMap(r=>$r(r.blocks))))}function Pe(t){return t.content.map(e=>{var n;return e.kind==="text"?e.text:e.kind==="field"?(n=e.cachedText)!=null?n:"\uFFFC":e.kind==="drawing"&&e.text?e.text:"\uFFFC"}).join("")}function Fn(t){let e=new Set(_e(t).map(r=>r.paraId).filter(Boolean)),n="";do n=Math.floor(Math.random()*4294967295).toString(16).toUpperCase().padStart(8,"0");while(!n||e.has(n));return n}function gs(t){return t.type==="table"?H(v(v(H(v({kind:"table",tableId:t.tableId},t.tableStyleId?{tableStyleId:t.tableStyleId}:{}),{columnWidths:t.columnWidths}),t.layout?{layout:t.layout}:{}),t.borders?{borders:t.borders}:{}),{rows:t.rows.map(e=>H(v(v(v({},e.height?{height:e.height}:{}),e.isHeader?{isHeader:true}:{}),e.cantSplit?{cantSplit:true}:{}),{cells:e.cells.map(n=>xw(n))}))}):jc(t)}function Gc(t){return {kind:t.kind,partName:t.partName,blocks:t.blocks.map(e=>gs(e))}}function xw(t){var o;let n=((o=t.blocks)!=null?o:t.paragraphs).map(i=>gs(i)),r={gridSpan:t.gridSpan,blocks:n,paragraphs:$r(n)};return t.rowSpan!==void 0&&(r.rowSpan=t.rowSpan),t.vMerge!==void 0&&(r.vMerge=t.vMerge),t.width!==void 0&&(r.width=t.width),t.widthType!==void 0&&(r.widthType=t.widthType),t.margin!==void 0&&(r.margin=t.margin),t.borders!==void 0&&(r.borders=t.borders),t.shading!==void 0&&(r.shading=t.shading),t.verticalAlignment!==void 0&&(r.verticalAlignment=t.verticalAlignment),t.noWrap!==void 0&&(r.noWrap=t.noWrap),r}function jc(t){var n,r;let e=t.spans.filter(o=>o.kind==="comment");return {kind:"paragraph",paraId:t.paraId,story:t.story,styleId:(n=t.styleId)!=null?n:null,format:(r=t.format)!=null?r:null,content:t.segments.flatMap(o=>o.kind==="text"?Sw(o,e):o.kind==="revision"?vw(o):o.kind==="field"?yw(o):o.kind==="image"?kw(o):o.kind==="drawing"?Ew(o):o.kind==="placeholder"&&o.placeholderKind==="pageBreak"?[{kind:"pageBreak"}]:[])}}function yw(t){var e;return [H(v({kind:"field",fieldKind:t.fieldKind,instruction:t.instruction},t.cachedText!==void 0?{cachedText:t.cachedText}:{}),{format:(e=t.format)!=null?e:null})]}function vw(t){var e;return t.text.length===0?[]:[{kind:"text",text:t.text,format:(e=t.format)!=null?e:null,marks:[{kind:"revision",id:`revision:${t.revisionId}`,revisionId:t.revisionId,revisionKind:t.revisionKind,author:t.author,date:t.date}]}]}function Sw(t,e){var o,i,a;if(t.text.length===0)return [];let n=[],r=t.from;for(let s of e){let l=Math.max(t.from,s.from),d=Math.min(t.to,s.to);d<=l||(l>r&&n.push(v({kind:"text",text:t.text.slice(r-t.from,l-t.from),format:(o=t.format)!=null?o:null},t.hyperlink?{hyperlink:v({},t.hyperlink)}:{})),n.push(H(v({kind:"text",text:t.text.slice(l-t.from,d-t.from),format:(i=t.format)!=null?i:null},t.hyperlink?{hyperlink:v({},t.hyperlink)}:{}),{marks:[{kind:"comment",id:s.id,commentId:s.commentId,author:s.author,date:s.date,body:s.body}]})),r=d);}return r<t.to&&n.push(v({kind:"text",text:t.text.slice(r-t.from),format:(a=t.format)!=null?a:null},t.hyperlink?{hyperlink:v({},t.hyperlink)}:{})),n}function kw(t){return [v(v(v(v(v({kind:"image",drawingId:t.drawingId,src:t.src},t.width!==void 0?{width:t.width}:{}),t.height!==void 0?{height:t.height}:{}),t.anchoringMode!==void 0?{anchoringMode:t.anchoringMode}:{}),t.wrap!==void 0?{wrap:t.wrap}:{}),t.position!==void 0?{position:t.position}:{})]}function Ew(t){let e={kind:"drawing",drawingId:t.drawingId,drawingKind:t.drawingKind};return t.text!==void 0&&(e.text=t.text),t.width!==void 0&&(e.width=t.width),t.height!==void 0&&(e.height=t.height),t.anchoringMode!==void 0&&(e.anchoringMode=t.anchoringMode),t.wrap!==void 0&&(e.wrap=t.wrap),t.position!==void 0&&(e.position=t.position),t.hasBorder!==void 0&&(e.hasBorder=t.hasBorder),t.hasFill!==void 0&&(e.hasFill=t.hasFill),t.isLineOrConnector!==void 0&&(e.isLineOrConnector=t.isLineOrConnector),t.strokeColor!==void 0&&(e.strokeColor=t.strokeColor),t.strokeWidth!==void 0&&(e.strokeWidth=t.strokeWidth),t.innerTextAlign!==void 0&&(e.innerTextAlign=t.innerTextAlign),t.paragraphs&&t.paragraphs.length>0&&(e.paragraphs=t.paragraphs.map(n=>jc(n))),[e]}function Cw(t,e){var n;for(let r of t.rows)for(let o of r.cells){let i=o.paragraphs.findIndex(s=>s.paraId===e),a=o.blocks.findIndex(s=>s.kind==="paragraph"&&s.paraId===e);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 ws(t){let e=Rw(t),n=t.cells.reduce((o,i)=>o+Uc(i),0),r=t.cells.reduce((o,i)=>o+Kc(i),0);return t.isHeader?{kind:"repeat-header",risks:e,textLength:r,paragraphCount:n}:e.includes("cant-split")?{kind:"keep-together",risks:e,textLength:r,paragraphCount:n}:e.length>0?{kind:"unsplittable",risks:e,textLength:r,paragraphCount:n}:r===0?{kind:"keep-together",risks:["empty-row"],textLength:r,paragraphCount:n}:n>t.cells.length?{kind:"block-fragmentable",risks:e,textLength:r,paragraphCount:n}:{kind:"text-fragmentable",risks:e,textLength:r,paragraphCount:n}}function fI(t){let e={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}};ui(t.blocks,e);for(let n of t.headers)ui(n.blocks,e);for(let n of t.footers)ui(n.blocks,e);return e}function pI(t,e){if(ws(t).kind!=="block-fragmentable"||e.cellBlockCounts.length!==t.cells.length)return null;let r=[],o=[],i=false,a=false;for(let s=0;s<t.cells.length;s+=1){let l=t.cells[s],d=Tw(l,e.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({},t),{height:void 0,cells:r}),tail:H(v({},t),{height:void 0,cells:o})}}function hI(t,e){if(ws(t).kind!=="text-fragmentable"||e.cellTextOffsets.length!==t.cells.length)return null;let r=[],o=[];for(let i=0;i<t.cells.length;i+=1){let a=Iw(t.cells[i],e.cellTextOffsets[i]);if(!a)return null;r.push(a.head),o.push(a.tail);}return {head:H(v({},t),{height:void 0,cells:r}),tail:H(v({},t),{height:void 0,cells:o})}}function Iw(t,e){if(t.blocks.length!==1)return null;let n=t.blocks[0];if(!n||n.kind!=="paragraph")return null;let r=Nw(n,e);return r?{head:H(v({},t),{blocks:[r.head],paragraphs:[r.head]}),tail:H(v({},t),{blocks:[r.tail],paragraphs:[r.tail]})}:null}function Nw(t,e){let n=t.content.reduce((a,s)=>a+(s.kind==="text"?s.text.length:0),0);if(!Number.isInteger(e)||e<=0||e>=n)return null;let r=[],o=[],i=0;for(let a of t.content){if(a.kind!=="text")return null;let s=i,l=i+a.text.length;if(i=l,l<=e){r.push(a);continue}if(s>=e){o.push(a);continue}let d=e-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({},t),{content:r}),tail:H(v({},t),{content:o})}}function Tw(t,e){if(!Number.isInteger(e)||e<0||e>t.blocks.length)return null;let n=t.blocks.slice(0,e),r=t.blocks.slice(e);return n.length===0&&r.length===0||n.length===0||r.length===0?null:{head:H(v({},t),{blocks:n,paragraphs:n.flatMap(bs)}),tail:H(v({},t),{blocks:r,paragraphs:r.flatMap(bs)})}}function ui(t,e){for(let n of t)n.kind==="table"&&Pw(n,e);}function Pw(t,e){e.tables+=1;for(let n of t.rows){e.rows+=1;let r=ws(n);r.kind==="repeat-header"?e.repeatHeaderRows+=1:r.kind==="keep-together"?e.keepTogetherRows+=1:r.kind==="block-fragmentable"?e.blockFragmentableRows+=1:r.kind==="text-fragmentable"?e.textFragmentableRows+=1:e.unsplittableRows+=1;for(let o of r.risks)e.risks[o]+=1;for(let o of n.cells)ui(o.blocks,e);}}function Rw(t){var n;let e=new Set;t.cantSplit&&e.add("cant-split");for(let r of t.cells)((n=r.rowSpan)!=null?n:1)>1&&e.add("row-span"),(r.vMerge==="restart"||r.vMerge==="continue")&&e.add("vertical-merge"),Mw(r,e);return [...e]}function Mw(t,e){for(let n of t.blocks){if(n.kind==="table"){e.add("nested-table");continue}Aw(n,e);}}function Aw(t,e){for(let n of t.content)Lw(n,e);}function Lw(t,e){var n,r;(t.kind==="image"||t.kind==="drawing")&&e.add("media"),t.kind==="field"&&e.add("field"),t.kind==="pageBreak"&&e.add("page-break"),t.kind==="text"&&((n=t.marks)!=null&&n.some(o=>o.kind==="comment")&&e.add("comment"),(r=t.marks)!=null&&r.some(o=>o.kind==="revision")&&e.add("revision"));}function Uc(t){return t.blocks.reduce((e,n)=>n.kind==="paragraph"?e+1:e+n.rows.reduce((r,o)=>r+o.cells.reduce((i,a)=>i+Uc(a),0),0),0)}function Kc(t){return t.blocks.reduce((e,n)=>e+Dw(n),0)}function bs(t){return t.kind==="paragraph"?[t]:t.rows.flatMap(e=>e.cells.flatMap(n=>n.blocks.flatMap(bs)))}function Dw(t){return t.kind==="paragraph"?t.content.reduce((e,n)=>e+(n.kind==="text"?n.text.length:0),0):t.rows.reduce((e,n)=>e+n.cells.reduce((r,o)=>r+Kc(o),0),0)}function mn(t){return t?t.numFmt==="bullet"?"bullet":"numbered":null}function xs(t,e,n=0){let r=vs(n);return {numId:Ww(t,e),ilvl:r,numFmt:e==="bullet"?"bullet":Jc(r),lvlText:e==="bullet"?Zc(r):`%${r+1}.`,start:1}}function ys(t,e){var o,i;let n=vs(e),r=(o=mn(t))!=null?o:"numbered";return H(v({},t),{ilvl:n,numFmt:r==="bullet"?"bullet":Jc(n),lvlText:r==="bullet"?Zc(n):`%${n+1}.`,start:(i=t.start)!=null?i:1})}function fi(t){var n,r,o,i;let e=new Map;for(let a of _e(t)){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(mn(s)==="bullet"){s.label=Fw(s.lvlText);continue}let d=((i=e.get(l))!=null?i:((o=s.start)!=null?o:1)-1)+1;e.set(l,d),s.label=Hw(d,s.numFmt,s.lvlText);}}function Xc(t){return {left:(vs(t)+1)*720,firstLine:-360}}function Yc(t,e,n){let r=new Set(e);for(let o of e){let i=ve(t,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=Bw(s,n);if(l)return v({},l)}}return null}function Ww(t,e){let n=new Set(_e(t).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-${e}-${r}`,r+=1;while(n.has(o));return o}function Bw(t,e){var r;let n=(r=t.format)!=null&&r.hasNumbering?t.format.numbering:void 0;return !n||mn(n)!==e?null:n.numId.startsWith(`coco-${e}-`)?n:null}function vs(t){return Math.max(0,Math.min(8,Math.round(t)))}function Zc(t){return ["\u2022","\u25E6","\u25AA"][t%3]}function Jc(t){return ["decimal","lowerLetter","lowerRoman"][t%3]}function Fw(t){return (t==null?void 0:t.replace(/%\d+/g,"").trim())||"\u2022"}function Hw(t,e,n){let r=e==="lowerLetter"?_c(t,false):e==="upperLetter"?_c(t,true):e==="lowerRoman"?qc(t).toLowerCase():e==="upperRoman"?qc(t):String(t);return n?n.replace(/%\d+/g,r):`${r}.`}function _c(t,e){let n=Math.max(1,t),r="";for(;n>0;)n-=1,r=String.fromCharCode((e?65:97)+n%26)+r,n=Math.floor(n/26);return r}function qc(t){let e=Math.max(1,Math.min(3999,t)),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(;e>=o;)n+=i,e-=o;return n}function rt(t){return Ot(t)}function Gr(t){var n,r;if(t.rows.length===0)return false;let e=(r=(n=t.rows[0])==null?void 0:n.cells.length)!=null?r:0;return e>0&&t.rows.every(o=>o.cells.length===e&&o.cells.every(i=>i.gridSpan===1&&(i.rowSpan===void 0||i.rowSpan===1)&&i.vMerge==null))}function tu(t,e,n,r,o,i=()=>Fn(t),a=()=>_w(t)){var I,D,F,A,O,ee;let s=ve(t,e);if(!s||s.container!==t.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,Pe(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,((D=(I=t.pageLayout)==null?void 0:I.width)!=null?D:11906)-((A=(F=t.pageLayout)==null?void 0:F.margin.left)!=null?A:1440)-((ee=(O=t.pageLayout)==null?void 0:O.margin.right)!=null?ee:1440)),x=Math.max(360,Math.floor(h/d)),S={kind:"table",tableId:g,columnWidths:Array.from({length:d},()=>x),layout:{width:x*d,widthType:"dxa",alignment:"left"},borders:Ss("000000"),rows:Array.from({length:l},()=>({cells:Array.from({length:d},()=>{let le={kind:"paragraph",paraId:i(),story:u.story,styleId:null,format:null,content:[{kind:"text",text:"",format:null}]};return {gridSpan:1,width:x,borders:Ss("000000"),blocks:[le],paragraphs:[le]}})}))},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 nu(t,e,n=()=>Fn(t)){var s,l,d;let r=Oe(t,e);if(!r||r.container!==t.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:e,rowIndex:0,columnIndex:0}],cursor:{paraId:i.paraId,offset:0},container:r.container,startIndex:r.tableIndex,beforeBlocks:a,afterBlocks:Ot([i])}}function ru(t,e,n,r=()=>Fn(t)){var u,f;let o=rn(t,e);if(!o||!Gr(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=$w(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,Cs(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 Es(t,e,n){var s;let r=rn(t,e);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=Qc(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=Qc(n.borderColor);if(n.borderColor!==null&&!l)return null;r.cell.borders=l?Ss(l):Ow(),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:e,offset:0}}}function tt(t,e){let n=Math.max(0,Math.min(e.anchor.rowIndex,e.focus.rowIndex)),r=Math.min(t.rows.length-1,Math.max(e.anchor.rowIndex,e.focus.rowIndex)),o=Math.max(0,Math.min(e.anchor.columnIndex,e.focus.columnIndex)),i=Math.max(e.anchor.columnIndex,e.focus.columnIndex),a=[];for(let s=n;s<=r;s+=1){let l=t.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 ou(t,e,n){let r=Oe(t,e);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,x=h[0],S=h.flatMap(I=>I.blocks.map(Yt)),k=S.flatMap(I=>I.kind==="paragraph"?[I]:Vr([I]));x.blocks=S,x.paragraphs=k,x.rowSpan=h.length,x.vMerge="restart";for(let I of h.slice(1)){let D=I.paragraphs[0];D&&(D.content=[{kind:"text",text:"",format:null}]),I.blocks=D?[D]:[],I.paragraphs=D?[D]:[],I.rowSpan=void 0,I.vMerge="continue";}return {change:{kind:"table",op:"merge-cells",tableId:e,rowIndex:o,columnIndex:a,endRowIndex:i},cursor:{paraId:x.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]:Vr([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:e,rowIndex:o,columnIndex:a,endColumnIndex:s},cursor:{paraId:u.cell.paragraphs[0].paraId,offset:0}})}function iu(t,e,n,r,o=()=>Fn(t)){var p,b;let i=Oe(t,e),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,x)=>!h||h.gridSpan!==1?true:x===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:e,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},()=>Cs(d,o));return a.cells.splice(l+1,0,...f),{change:{kind:"table",op:"split-cell",tableId:e,rowIndex:n,columnIndex:r},cursor:{paraId:d.paragraphs[0].paraId,offset:0}}}function au(t,e,n,r){let o=Oe(t,e);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=Es(t,l,r);d&&i.push(d.change);}return a&&i.length>0?{changes:i,cursor:a}:null}function su(t,e,n){var a;let r=Oe(t,e);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:e,rowIndex:l,columnIndex:d}));}return i&&o.length>0?{changes:o,cursor:i}:null}function lu(t,e,n,r){var u,f,p;let o=Oe(t,e);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 x=gn(b);if(d!=null||(d={paraId:x.paraId,offset:h.length}),b.paragraphs.map(I=>Pe(I)).join(`
|
|
13
|
+
`)===h&&b.blocks.length===1)continue;let k=(p=(f=x.content.find(I=>I.kind==="text"))==null?void 0:f.format)!=null?p:null;x.content=[{kind:"text",text:h,format:k?Yt(k):null}],b.blocks=[x],b.paragraphs=[x],l.push({kind:"table",op:"replace-cell",tableId:e,rowIndex:w,columnIndex:g,text:h});}return d&&l.length>0?{changes:l,cursor:d}:null}function du(t,e,n,r){var d;let o=Oe(t,e);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=Pu(t,b.blocks),g=Vr(w);g.length!==0&&(u.blocks=w,u.paragraphs=g,zr(u,"margin",b.format.margin),zr(u,"borders",b.format.borders),zr(u,"shading",b.format.shading),zr(u,"verticalAlignment",b.format.verticalAlignment),zr(u,"noWrap",b.format.noWrap),l!=null||(l={paraId:g[0].paraId,offset:Pe(g[0]).length}),s.push({kind:"table",op:"replace-cell",tableId:e,rowIndex:f,columnIndex:p,cellSnapshot:Yt(u)}));}return l&&s.length>0?{changes:s,cursor:l}:null}function zr(t,e,n){n===void 0?delete t[e]:t[e]=Yt(n);}function Qc(t){if(t===null)return null;let e=t.trim().replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(e)?e:null}function Ss(t){let e={val:"single",color:t,size:4};return {top:v({},e),right:v({},e),bottom:v({},e),left:v({},e)}}function Ow(){let t={val:"nil"};return {top:v({},t),right:v({},t),bottom:v({},t),left:v({},t)}}function $w(t,e){let o=t,{cells:n}=o,r=Wn(o,["cells"]);return H(v({},Yt(r)),{cells:n.map(i=>Cs(i,e))})}function Cs(t,e){let s=t,{blocks:n,paragraphs:r}=s,o=Wn(s,["blocks","paragraphs"]),i=gn(t),a={kind:"paragraph",paraId:e(),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(t){let e=t.paragraphs[0];if(!e)throw new Error("Native table cell must contain at least one paragraph");return e}function Yt(t){return JSON.parse(JSON.stringify(t))}function on(t,e,n,r){let o=J(t,e);return !o||r.length===0?null:(o.content=Iu(o.content,n,r),{kind:"text",op:"insert",paraId:e,offset:n,text:r})}function cu(t,e,n,r,o={}){var u;let i=J(t,e);if(!i||!r)return null;let a=(u=o.drawingId)!=null?u:Gw(t),s=hi(o.width),l=hi(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:e,offset:n,drawingId:a,src:r},s?{width:s}:{}),l?{height:l}:{})}function uu(t,e,n){let r=J(t,e);if(!r)return null;let o=Math.max(0,Math.min(n,Pe(r).length)),i=wn(r.content,o);return r.content=$e([...i.before,{kind:"pageBreak"},...i.after]),{kind:"page-break",op:"insert",paraId:e,offset:o}}function gi(t,e,n){let r=J(t,e);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 fu(t,e,n,r){let o=J(t,e),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 pu(t,e,n,r){let o=J(t,e),i=o==null?void 0:o.content.find(d=>d.kind==="image"&&d.drawingId===n),a=hi(r.width),s=hi(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:e,offset:l,drawingId:n,width:a,height:s}}function jr(t,e,n){let r=ve(t,e);if(!r)return null;let{paragraph:o}=r;if(n>0)return Vw(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 Ur(t,e,n){let r=ve(t,e);if(!r)return null;let{paragraph:o}=r;if(n<pi(o.content))return Nu(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(t,e,n,r){let o=J(t,e),i=Mt(n,r);if(!o||i.from===i.to)return [];let a=jw(o,i.from,i.to);return o.content=a.content,a.changes}function bi(t,e,n){var b;if(e.paraId===n.paraId)return bn(t,e.paraId,e.offset,n.offset);let r=ve(t,e.paraId),o=ve(t,n.paraId);if(!r||!o)return [];if(r.container!==o.container)return [];let i=r.index<o.index?{start:r,end:o,startOffset:e.offset,endOffset:n.offset}:{start:o,end:r,startOffset:n.offset,endOffset:e.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=Pe(i.start.paragraph),l=Pe(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=Pe(g);h.length>0&&a.push({kind:"text",op:"delete",paraId:g.paraId,offset:0,text:h});}(b=ve(t,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:Ru(i.start.paragraph.content,d)}]:[],a}function hu(t,e,n,r){let o=ve(t,e.paraId),i=ve(t,n.paraId);if(!o||!i||o.container!==t.blocks||i.container!==t.blocks)return null;let a=o.index<i.index||o.index===i.index&&e.offset<=n.offset?{start:o,end:i,startOffset:e.offset,endOffset:n.offset}:{start:i,end:o,startOffset:n.offset,endOffset:e.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=t.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=Pe(a.start.paragraph).length,u=Pe(a.end.paragraph).length,f=Math.max(0,Math.min(a.startOffset,d)),p=Math.max(0,Math.min(a.endOffset,u)),b=[...bn(t,a.end.paragraph.paraId,0,p),...bn(t,a.start.paragraph.paraId,f,d)];if(a.start.paragraph.content=$e([...a.start.paragraph.content,...a.end.paragraph.content]),t.blocks.splice(a.start.index+1,a.end.index-a.start.index),r.length>0){let w=on(t,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(Tu)}),{changes:b,cursor:{paraId:a.start.paragraph.paraId,offset:f+r.length},container:t.blocks,startIndex:a.start.index,beforeBlocks:l,afterBlocks:Ot([a.start.paragraph])}}function Is(t,e,n){let r=Uw(t,e,n);if(!r||r.blocks.length<2&&!Kw(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 mu(t,e,n,r){if(e.paraId!==n.paraId||r.length===0)return null;let o=ve(t,e.paraId);if(!o||o.container!==t.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=Pe(o.paragraph).length,d=Math.max(0,Math.min(e.offset,n.offset,l)),u=Math.max(d,Math.min(Math.max(e.offset,n.offset),l)),f=wn(o.paragraph.content,d).before,p=wn(o.paragraph.content,u).after,b=Pu(t,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 x={paraId:o.paragraph.paraId,offset:pi(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)),x={paraId:g.paraId,offset:pi(g.content)-pi(p)}),t.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(Tu)}],cursor:x,container:t.blocks,startIndex:o.index,beforeBlocks:s,afterBlocks:k}}function Kr(t,e,n,r,o){let i=Mt(n,r),a=bn(t,e,i.from,i.to),s=on(t,e,i.from,o);return s?[...a,s]:a}function gu(t,e,n,r){if(e.paraId===n.paraId)return Kr(t,e.paraId,e.offset,n.offset,r);let o=ve(t,e.paraId),i=ve(t,n.paraId);if(!o||!i||o.container!==i.container)return [];let a=o.index<i.index?e:n,s=bi(t,e,n);if(s.length===0||r.length===0)return s;let l=on(t,a.paraId,a.offset,r);return l?[...s,l]:s}function Ns(t,e,n,r){var w,g,h,x,S,k,I,D;let o=ve(t,e.paraId),i=ve(t,n.paraId);if(!o||!i||o.container!==i.container)return null;let a=o.index<i.index||o.index===i.index&&e.offset<=n.offset?e:n,s=bi(t,e,n),l=J(t,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,Te(l).length)),b=on(t,p,f,(w=d[0])!=null?w:"");b&&s.push(b);for(let H=1;H<d.length;H+=1){let A=Wn(t),O=Ms(t,p,f+((h=(g=d[H-1])==null?void 0:g.length)!=null?h:0),A);if(!O)return null;s.push(O),u.push(A),p=A,f=0;let ee=on(t,p,0,(x=d[H])!=null?x:"");ee&&s.push(ee);}return {changes:s,cursor:{paraId:p,offset:d.length===1?f+((k=(S=d[0])==null?void 0:S.length)!=null?k:0):(D=(I=d[d.length-1])==null?void 0:I.length)!=null?D:0},paragraphIds:u}}function Ts(t,e,n,r,o){var u;let i=J(t,e),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=Ve(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(F(v({},p),{text:p.text.slice(0,b)})),w>b&&(d.push(F(v({},p),{text:p.text.slice(b,w),format:v(v({},(u=p.format)!=null?u:{}),o)})),l=true),w<f&&d.push(F(v({},p),{text:p.text.slice(w)})),s+=f;}return l?(i.content=$e(d),{kind:"format",op:"run",paraId:e,from:a.from,to:a.to,format:o}):null}function Ps(t,e,n,r,o){var p,f,b;let i=J(t,e),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=0,l=false,d=[],u=F(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),x=Math.min(g,a.to-s);if(h>0&&d.push(F(v({},w),{text:w.text.slice(0,h)})),x>h){let S=w.text.slice(h,x);if(o.preserveExistingComments&&((p=w.marks)!=null&&p.some(k=>k.kind==="comment")))d.push(F(v({},w),{text:S})),d.push(F(v({},w),{text:S,marks:[u,...(f=w.marks)!=null?f:[]]}));else {let k=((b=w.marks)!=null?b:[]).filter(I=>I.kind!=="comment");d.push(F(v({},w),{text:S,marks:[...k,u]}));}l=true;}x<g&&d.push(F(v({},w),{text:w.text.slice(x)})),s+=g;}return l?(i.content=$e(d),{kind:"annotation",op:"insert",paraId:e,from:a.from,to:a.to,commentId:o.commentId,body:o.body,parentCommentId:o.parentCommentId}):null}function bu(t,e,n){let r=[];for(let o of _e(t)){let i=0,a=null,s=null,l=false,d=o.content.map(u=>{var b,w;let p=Ve(u);return u.kind!=="text"||!((b=u.marks)==null?void 0:b.find(g=>g.kind==="comment"&&g.commentId===e))?(i+=p,u):(a=a===null?i:a,s=i+p,l=true,i+=p,F(v({},u),{marks:(w=u.marks)==null?void 0:w.map(g=>g.kind==="comment"&&g.commentId===e?F(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:e,body:n}));}return r}function wu(t,e){let n=[];for(let r of _e(t)){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===e))!=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===e));return f&&f.length>0?F(v({},d),{marks:f}):F(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:e}));}return n}function $t(t,e,n,r,o){var p,f;let i=J(t,e),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(F(v({},b),{text:b.text.slice(0,g)})),h>g){let x=((p=b.marks)!=null?p:[]).find(S=>S.kind==="revision");if(!(o.revisionKind==="delete"&&(x==null?void 0:x.revisionKind)==="insert")){let S=((f=b.marks)!=null?f:[]).filter(k=>k.kind!=="revision");d.push(F(v({},b),{text:b.text.slice(g,h),marks:[...S,u]}));}l=true;}h<w&&d.push(F(v({},b),{text:b.text.slice(h)})),s+=w;}return l?(i.content=$e(d),{kind:"revision",op:o.revisionKind,paraId:e,from:a.from,to:a.to,revisionId:o.revisionId,revisionKind:o.revisionKind}):null}function xu(t,e,n,r,o){var f,b,w,g;let i=J(t,e),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 x=Ve(h);if(h.kind!=="text"||s+x<=a.from||s>=a.to){p.push(h),s+=x;continue}let S=Math.max(0,a.from-s),k=Math.min(x,a.to-s);if(S>0&&p.push(F(v({},h),{text:h.text.slice(0,S)})),k>S){let I=h.text.slice(S,k),D=((f=h.marks)!=null?f:[]).find(H=>H.kind==="revision");D?(l=true,d=(b=D.revisionId)!=null?b:D.id.replace(/^revision:/,""),u=(w=D.revisionKind)!=null?w:"insert",(o==="accept"?u==="insert":u==="delete")&&p.push(F(v({},h),{text:I,marks:((g=h.marks)!=null?g:[]).filter(A=>A.kind!=="revision")}))):p.push(F(v({},h),{text:I}));}k<x&&p.push(F(v({},h),{text:h.text.slice(k)})),s+=x;}return l?(i.content=$e(p),{kind:"revision",op:o,paraId:e,from:a.from,to:a.to,revisionId:d,revisionKind:u}):null}function yu(t,e,n,r,o){let i=J(t,e),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=Ve(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(F(v({},p),{text:p.text.slice(0,b)})),w>b){let g=p.formatRevision;g?(d=g.revisionId,l=true,u.push(F(v({},p),{text:p.text.slice(b,w),format:o==="reject"?g.beforeFormat?v({},g.beforeFormat):null:p.format,formatRevision:void 0}))):u.push(F(v({},p),{text:p.text.slice(b,w)}));}w<f&&u.push(F(v({},p),{text:p.text.slice(w)})),s+=f;}return l?(i.content=$e(u),{kind:"format",op:o,paraId:e,from:a.from,to:a.to,format:{},revisionId:d,revisionKind:"format"}):null}function Rs(t,e,n,r,o){var p;let i=J(t,e),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=o?Xw(o):null;if(o&&!s)return null;let l=0,d=false,u=[];for(let f of i.content){let b=Ve(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(F(v({},f),{text:f.text.slice(0,w)})),g>w){let h=F(v({},f),{text:f.text.slice(w,g)});s?h.hyperlink=v({},s):delete h.hyperlink,u.push(h),ks((p=f.hyperlink)!=null?p:null,s)||(d=true);}g<b&&u.push(F(v({},f),{text:f.text.slice(g)})),l+=b;}return d?(i.content=$e(u),v({kind:"hyperlink",op:s?"set":"remove",paraId:e,from:a.from,to:a.to},s?{hyperlink:s}:{})):null}function er(t,e,n){var i,a,s;let r=J(t,e);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:e,format:n}}function vu(t,e,n,r){let o=J(t,e),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 p=Math.max(0,i.from-a),f=Math.min(u,i.to-a);p>0&&l.push(F(v({},d),{text:d.text.slice(0,p)})),f>p&&(l.push(F(v({},d),{text:d.text.slice(p,f),format:null})),d.format&&Object.keys(d.format).length>0&&(s=true)),f<u&&l.push(F(v({},d),{text:d.text.slice(f)})),a+=u;}return s?(o.content=$e(l),{kind:"format",op:"run",paraId:e,from:i.from,to:i.to,format:{},clear:true}):null}function _r(t,e,n){var i,a,s;let r=J(t,e);if(!r)return null;let o=(i=r.format)!=null?i:{};if(n)r.format=F(v({},o),{hasNumbering:true,numbering:v({},n),indent:v(v({},(a=o.indent)!=null?a:{}),Xc(n.ilvl))});else {let l=F(v({},o),{hasNumbering:false,indent:F(v({},(s=o.indent)!=null?s:{}),{left:0,firstLine:0})});delete l.numbering,r.format=l;}return {kind:"list",paraId:e,numbering:n?v({},n):null}}function SI(t,e,n,r){var l;let o=J(t,e),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 Su(t,e,n){let r=J(t,e);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:e,offset:o,drawingId:n}:i.push(s),o+=Ve(s);return a?(r.content=$e(i),a):null}function ku(t,e,n,r,o,i){var f;let a=J(t,e),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=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(F(v({},b),{text:b.text.slice(0,g)})),h>g&&(u.push(F(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(F(v({},b),{text:b.text.slice(h)})),l+=w;}return d?(a.content=$e(u),{kind:"format",op:"run",paraId:e,from:s.from,to:s.to,format:{},revisionId:i.revisionId,revisionKind:"format",beforeFormat:p(s.from)}):null}function Eu(t,e,n,r){let o=J(t,e);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:e,offset:i,drawingId:n,revisionId:l.revisionId,revisionKind:l.revisionKind}):null}return null}function Cu(t,e,n,r){let o=J(t,e);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:e,offset:i,drawingId:n,revisionId:l,revisionKind:"format"}}return null}function Ms(t,e,n,r=Wn(t)){let o=ve(t,e);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:e,newParaId:r,offset:n}}function qr(t,e,n){let r=J(t,e);if(!r||r.content.some(s=>s.kind!=="text"))return null;let o=Te(r);if(o===n)return null;let i=Yw(o,n),a=r.content;return i.deletedText.length>0&&(a=zw(a,i.offset,i.deletedText.length)),i.insertedText.length>0&&(a=Iu(a,i.offset,i.insertedText,Ru(r.content,i.offset))),r.content=a,i.deletedText.length===0?{kind:"text",op:"insert",paraId:e,offset:i.offset,text:i.insertedText}:i.insertedText.length===0?{kind:"text",op:"delete",paraId:e,offset:i.offset,text:i.deletedText}:{kind:"text",op:"replace",paraId:e,offset:i.offset,text:i.insertedText,deletedText:i.deletedText}}function Iu(t,e,n,r=null){let o=[],i=0,a=false;for(let s of t){let l=Ve(s);if(!a&&e<=i+l){if(s.kind==="text"){let d=Math.max(0,e-i);o.push(F(v({},s),{text:`${s.text.slice(0,d)}${n}${s.text.slice(d)}`}));}else e<=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 zw(t,e,n){if(n<=0)return t;let r=[],o=0,i=e+n;for(let a of t){let s=Ve(a),l=o+s;if(a.kind!=="text"||l<=e||o>=i)r.push(a);else {let d=Math.max(0,e-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(F(v({},a),{text:p}));}o=l;}return $e(r)}function Vw(t,e){return Nu(t,e-1)}function Gw(t){let e=new Set(_e(t).flatMap(r=>r.content.filter(o=>o.kind==="image"||o.kind==="drawing").map(o=>o.drawingId))),n=1;for(;e.has(`coco-clipboard-${n}`);)n+=1;return `coco-clipboard-${n}`}function Nu(t,e){if(e<0)return null;let n=[],r=0,o=null;for(let i of t.content){let a=Ve(i);if(!o&&e>=r&&e<r+a)if(i.kind==="image")o={kind:"image",op:"delete",paraId:t.paraId,offset:e,drawingId:i.drawingId};else if(i.kind==="pageBreak")o={kind:"page-break",op:"delete",paraId:t.paraId,offset:e};else if(i.kind==="text"){let s=e-r,l=i.text.slice(s,s+1),d=`${i.text.slice(0,s)}${i.text.slice(s+1)}`;d.length>0&&n.push(F(v({},i),{text:d})),o={kind:"text",op:"delete",paraId:t.paraId,offset:e,text:l};}else n.push(i);else n.push(i);r+=a;}return o?(t.content=$e(n),o):null}function jw(t,e,n){let r=[],o=[],i=0;for(let a of t.content){let s=Ve(a),l=i+s;if(!(e<l&&n>i)){r.push(a),i=l;continue}if(a.kind==="text"){let u=Math.max(0,e-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(F(v({},a),{text:b})),f.length>0&&o.push({kind:"text",op:"delete",paraId:t.paraId,offset:i+u,text:f});}else a.kind==="image"?o.push({kind:"image",op:"delete",paraId:t.paraId,offset:i,drawingId:a.drawingId}):a.kind==="pageBreak"?o.push({kind:"page-break",op:"delete",paraId:t.paraId,offset:i}):r.push(a);i=l;}return {content:$e(r),changes:o.sort((a,s)=>eu(s)-eu(a))}}function wn(t,e){let n=[],r=[],o=0,i=false;for(let a of t){let s=Ve(a);if(!i&&e<=o+s){if(a.kind==="text"){let l=Math.max(0,e-o);l>0&&n.push(F(v({},a),{text:a.text.slice(0,l)})),l<a.text.length&&r.push(F(v({},a),{text:a.text.slice(l)}));}else e<=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(t){return t.kind==="text"?t.text.length:1}function hi(t){if(!(!Number.isFinite(t)||t===void 0||t<=0))return Math.max(1,Math.round(t*100)/100)}function Mt(t,e){let n=Math.max(0,Math.min(t,e)),r=Math.max(0,Math.max(t,e));return {from:n,to:r}}function eu(t){return "offset"in t&&typeof t.offset=="number"?t.offset:0}function $e(t){var n,r,o,i;let e=[];for(let a of t)if(a.kind==="text"){if(a.text.length===0)continue;let s=e[e.length-1];(s==null?void 0:s.kind)==="text"&&qw(s.format,a.format)&&ks((n=s.hyperlink)!=null?n:null,(r=a.hyperlink)!=null?r:null)&&ks((o=s.marks)!=null?o:null,(i=a.marks)!=null?i:null)?s.text+=a.text:e.push(v({},a));}else e.push(a);return e}function Ot(t){let e=JSON.parse(JSON.stringify(t));return As(e),e}function Tu(t){return t.kind==="paragraph"?t.paraId:t.tableId}function Uw(t,e,n){let r=ve(t,e.paraId),o=ve(t,n.paraId);if(!r||!o||r.container!==t.blocks||o.container!==t.blocks)return null;let i=r.index<o.index||r.index===o.index&&e.offset<=n.offset?{start:r,end:o,startOffset:e.offset,endOffset:n.offset}:{start:o,end:r,startOffset:n.offset,endOffset:e.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:t.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 Kw(t){return t.slice(1,-1).some(e=>e.kind==="table"||e.content.some(n=>n.kind!=="text"))}function Pu(t,e){let n=Ot(e),r=new Set(_e(t).map(d=>d.paraId)),o=new Set,i=new Set;mi(t.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 mi(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();}),As(n),n}function _w(t){let e=new Set;for(let r of [t.blocks,...t.headers.map(o=>o.blocks),...t.footers.map(o=>o.blocks)])mi(r,o=>{o.kind==="table"&&e.add(o.tableId);});let n=1;for(;e.has(`coco-table-${n}`);)n+=1;return `coco-table-${n}`}function mi(t,e){for(let n of t)if(e(n),n.kind==="table")for(let r of n.rows)for(let o of r.cells)mi(o.blocks,e);}function As(t){for(let e of t)if(e.kind==="table")for(let n of e.rows)for(let r of n.cells)As(r.blocks),r.paragraphs=Vr(r.blocks);}function Vr(t){return t.flatMap(e=>e.kind==="paragraph"?[e]:e.rows.flatMap(n=>n.cells.flatMap(r=>Vr(r.blocks))))}function pi(t){return t.reduce((e,n)=>e+Ve(n),0)}function qw(t,e){return JSON.stringify(t!=null?t:null)===JSON.stringify(e!=null?e:null)}function Xw(t){var o,i,a;let e=(o=t.target)==null?void 0:o.trim(),n=(i=t.anchor)==null?void 0:i.trim().replace(/^#/,""),r=(a=t.tooltip)==null?void 0:a.trim();return !e&&!n?null:v(v(v({},e?{target:e}:{}),n?{anchor:n}:{}),r?{tooltip:r}:{})}function ks(t,e){return JSON.stringify(t)===JSON.stringify(e)}function Ru(t,e){let n=0,r=null;for(let o of t){let i=Ve(o);if(o.kind==="text"){if(e>=n&&e<=n+i)return o.format;r=o.format;}n+=i;}return r}function Yw(t,e){let n=0;for(;n<t.length&&n<e.length&&t.charCodeAt(n)===e.charCodeAt(n);)n+=1;let r=t.length,o=e.length;for(;r>n&&o>n&&t.charCodeAt(r-1)===e.charCodeAt(o-1);)r-=1,o-=1;return {offset:n,deletedText:t.slice(n,r),insertedText:e.slice(n,o)}}var Mu=/^data:(image\/(?:png|jpeg|gif|webp));base64,([a-z0-9+/]*={0,2})$/i,Zw=new Set(["http:","https:","mailto:","tel:"]);function Xr(t){let e=t.trim();return Mu.test(e)?e:null}function Au(t){let e=Xr(t),n=e?Mu.exec(e):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 Yr(t,e){if(t)try{let n=new URL(t.trim());if(Zw.has(n.protocol))return n.href}catch(n){}return e?`#${encodeURIComponent(e)}`:"#"}var Lu=260,Du=typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):void 0;function $u(){Bn("coco-word-native-document"),Bn("coco-word-native-page"),Bn("coco-word-native-page-body"),Bn("coco-word-native-story"),Bn("coco-word-native-p"),Bn("coco-word-native-drawing"),Bn("coco-word-native-table");}function zu(t){var a,s;let e=document.createElement("coco-word-native-document");e.contentEditable="true",e.spellcheck=false,Jw(t)&&e.classList.add("uses-natural-paragraph-flow"),ex(t)&&e.classList.add("uses-compact-latin-tables"),tx(t)&&e.classList.add("uses-rowspan-table-group-splitting");let n=Jn((a=t.defaults)==null?void 0:a.run).cssText;n.length>0&&e.setAttribute("style",n);for(let l of t.headers)e.appendChild(Hu(l));let r=Qw(t),o=r!==void 0&&Hs(t);for(let l of t.blocks)e.appendChild(to(l,{implicitGridForParagraphs:o,implicitGridLinePitch:r})),Xx(l)&&(o=false);for(let l of t.footers)e.appendChild(Hu(l));if(e.querySelector(".coco-word-comment, .coco-word-revision-insert, .coco-word-revision-delete, .coco-word-revision-format, [data-revision-id]")!==null)if(e.classList.add("has-annotation-rail"),((s=t.pageLayout)==null?void 0:s.width)!==void 0)e.style.minWidth=`${Us(t.pageLayout.width)+Lu}px`;else {let l=`calc(100% + ${Lu}px)`;e.style.width=l,e.style.minWidth=l;}return e}function Jw(t){if(t.blocks.length>300)return false;let e=[t.pageLayout,...t.sections.map(n=>n.pageLayout)].filter(n=>n!==void 0);return e.length===0?false:e.every(n=>n.docGrid===void 0)?true:!Hs(t)}function Qw(t){var n,r;return (r=(n=[t.pageLayout,...t.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 ex(t){return t.blocks.some(e=>e.kind==="table")&&!Hs(t)}function tx(t){return t.blocks.filter(n=>n.kind==="table").length<10?false:nx(t)<=5}function nx(t){return t.blocks.reduce((e,n)=>e+Vu(n),0)}function Vu(t){return t.kind==="paragraph"?t.content.filter(e=>e.kind==="image"||e.kind==="drawing").length:t.rows.reduce((e,n)=>e+n.cells.reduce((r,o)=>r+o.blocks.reduce((i,a)=>i+Vu(a),0),0),0)}function Hs(t){let e=0,n=0;for(let r of t.blocks.slice(0,160)){for(let o of rx(r))for(let i of o)/\s/.test(i)||(n++,/[\u3400-\u9FFF\uF900-\uFAFF]/.test(i)&&e++);if(n>=1200)break}return e>=24&&e/Math.max(n,1)>=.08}function rx(t){if(t.kind==="paragraph")return t.content.filter(n=>n.kind==="text").map(n=>n.text);let e=[];for(let n of t.rows)for(let r of n.cells)for(let o of r.paragraphs)e.push(...o.content.filter(i=>i.kind==="text").map(i=>i.text));return e}function Gu(t,e){let n=e.pageLayout;if(!n||t.dataset.paginated==="true")return;t.dataset.paginated="true",t.classList.add("is-paginated");let r=Array.from(t.children),o=r.filter(x=>x instanceof HTMLElement&&x.tagName.toLowerCase()==="coco-word-native-story"&&x.dataset.storyKind==="header"),i=r.filter(x=>x instanceof HTMLElement&&x.tagName.toLowerCase()==="coco-word-native-story"&&x.dataset.storyKind==="footer"),a=r.filter(x=>x instanceof HTMLElement&&x.tagName.toLowerCase()!=="coco-word-native-story");t.replaceChildren();let s=new Map,l=0,d=Jr(e,l,n),u=(x=l)=>{var k;let S=((k=s.get(x))!=null?k:0)+1;return s.set(x,S),l=x,d=Jr(e,x,n),df(t,e,d,o,i,t.children.length+1,x,S)},p=u(),f=p.querySelector("coco-word-native-page-body"),b=()=>Math.max(120,Math.round(f.getBoundingClientRect().height)||zx(d)),w=()=>(p=u(),f=p.querySelector("coco-word-native-page-body"),f),g=x=>{var I,D,H;if(x===l||f.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=((D=s.get(x))!=null?D:0)+1;s.set(x,k),l=x,d=Jr(e,x,n),cf(p,e,d,o,i,Number((H=p.dataset.pageNumber)!=null?H:"1"),x,k);},h=(x,S)=>{var O;let k=(O=px(x,e))!=null?O:l;f.children.length===0&&g(k),yi(x)&&f.children.length>0&&(w(),g(k)),f.appendChild(x);let I=Fx(x);I&&Si(p);let D=x.querySelector(".coco-word-page-break")!==null;if(f.scrollHeight>b()){let ee=ux(f,x);if(!gx(x,f,b,w)){f.removeChild(x),ee&&f.removeChild(ee);let le=ee?null:mx(x,f,b);w(),g(k),ee&&f.appendChild(ee),f.appendChild(le!=null?le:x);}}else if(x.matches("coco-word-native-table")){let ee=S&&vi(S,e),ae=S&&ee&&ee!=="continuous"&&ee!=="nextColumn"&&!lf(S)||S&&yi(S),te=p.querySelector(':scope > coco-word-native-story[data-story-kind="footer"]:not(.is-empty)');(!ae||te&&x.getBoundingClientRect().bottom>te.getBoundingClientRect().top)&&wx(x,f,b,w,!S);}I||Si(p);let H=vi(x,e),A=fx(x,e);A!==null&&(l=A),(D||H)&&hx(w,H);};for(let x=0;x<a.length;x+=1)h(a[x],a[x+1]);nf(t),rf(t),af(t),gf(t,e),yn(t);}function ju(t,e,n){let r=t.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||!e.pageLayout)return false;let i=an(t),a=i.indexOf(o);if(a<0)return false;let s=dx(t),l=false,d=false;for(let u=a;u<i.length;u+=1){let p=i[u],f=zt(p);if(f)for(;wi(f);){if(ax(t,e,p,i[u+1],s)){i=an(t),l=true;continue}let b=ix(f);if(b.length===0||b.length>=f.children.length)break;let w=i[u+1];(!w||xi(p,w,e))&&(w=Ku(t,e,p,w,s),i=an(t),d=true);let g=zt(w);if(!g)break;for(let h of [...b].reverse())g.insertBefore(h,g.firstChild);l=true;}}i=an(t),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||xi(p,f,e))){for(;sx(b,w);)l=true;for(;;){let g=$s(w);if(g.length===0||!Uu(b,g[0],e))break;for(let h of g)b.appendChild(h);if(wi(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),!wi(b,8)){l=true;continue}w.insertBefore(h,w.firstChild);}break}l=true;}of(f)&&(f.remove(),i=an(t),u-=1,d=true);}}return l?(nf(t),rf(t),af(t),d&&cx(t,e,s),gf(t,e),yn(t),true):false}function Os(t,e,n){let r={overflowPx:0,canBackfillPrevious:false,canBackfillNext:false},o=t.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(t),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&&$s(l).some(x=>_u(x,n))&&Wu(p,i,f,l,e)),w=a[s+1],g=w?zt(w):null,h=!!(w&&g&&Wu(i,w,l,g,e));return {overflowPx:u,canBackfillPrevious:b,canBackfillNext:h}}function Wu(t,e,n,r,o){if(xi(t,e,o))return false;let i=Math.max(0,Math.round(n.getBoundingClientRect().height)-tf(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=eo(d)[0];if(u&&!Hn(u)&&Xu(u)<=i+8)return true}let l=$s(r);return l.length===0||!Uu(n,l[0],o)?false:ox(l)<=i+8}function ox(t){return t.reduce((e,n)=>{let r=window.getComputedStyle(n),o=Number.parseFloat(r.marginTop)||0,i=Number.parseFloat(r.marginBottom)||0;return e+n.getBoundingClientRect().height+o+i},0)}function Vt(t,e,n){let r=t.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(t),a=o?i.indexOf(o):-1;if(a<0)return false;let s=false;for(let l of e.blocks){if(l.kind!=="table")continue;let d=Array.from(t.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(xf(l));for(let f of d.slice(1))f.remove();s=true;}}return s}function an(t){return Array.from(t.children).filter(e=>e instanceof HTMLElement&&e.tagName.toLowerCase()==="coco-word-native-page")}function zt(t){return t.querySelector(":scope > coco-word-native-page-body")}function wi(t,e=1){let n=Math.max(120,Math.round(t.getBoundingClientRect().height));return t.scrollHeight>n+e}function ix(t){let e=t.lastElementChild;if(!(e instanceof HTMLElement))return [];let n=[e],r=e.previousElementSibling;return r instanceof HTMLElement&&r.matches('coco-word-native-p[data-keep-next="true"]')&&n.unshift(r),n}function $s(t){let e=t.firstElementChild;if(!(e instanceof HTMLElement))return [];let n=[e],r=e.nextElementSibling;return e.matches('coco-word-native-p[data-keep-next="true"]')&&r instanceof HTMLElement&&n.push(r),n}function ax(t,e,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(Ci).filter(k=>k.dataset.repeatedHeader!=="true"),p=eo(u);if(p.length<2)return false;let f=p[p.length-1];if(Hn(f))return false;let b=r;(!b||xi(n,b,e))&&(b=Ku(t,e,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){zs(s),h=tr(a,s),w.insertBefore(h,w.firstChild);let k=h.querySelector(":scope > table > tbody");k&&Zr(k,lx(t,g));}let x=h.querySelector(":scope > table > tbody");if(!x)return false;let S=Array.from(x.children).find(k=>k instanceof HTMLTableRowElement&&k.dataset.repeatedHeader!=="true");Qr(l,f);for(let k of f)x.insertBefore(k,S!=null?S:null);return true}function sx(t,e){var d,u;let n=t.lastElementChild,r=e.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(Ci).filter(p=>p.dataset.repeatedHeader!=="true"),s=eo(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),wi(t,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 lx(t,e){if(!e)return [];let n=Array.from(t.querySelectorAll("coco-word-native-table")).find(r=>r.dataset.tableId===e&&r.querySelector('tr[data-repeat-header="true"]'));return n?Array.from(n.querySelectorAll('tr[data-repeat-header="true"]')):[]}function xi(t,e,n){if(t.dataset.sectionIndex!==e.dataset.sectionIndex)return true;let r=zt(t),o=zt(e),i=r==null?void 0:r.lastElementChild,a=o==null?void 0:o.firstElementChild;if(a instanceof HTMLElement&&yi(a))return true;if(!(i instanceof HTMLElement))return false;if(i.querySelector(".coco-word-page-break"))return true;let s=vi(i,n);return s!==null&&s!=="continuous"&&s!=="nextColumn"}function Uu(t,e,n){if(yi(e))return false;let r=t.lastElementChild;if(!(r instanceof HTMLElement))return true;if(r.querySelector(".coco-word-page-break"))return false;let o=vi(r,n);return o===null||o==="continuous"||o==="nextColumn"}function dx(t){var o;let e=new Set,n=[],r=[];for(let i of Array.from(t.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:""}`;e.has(s)||(e.add(s),a==="header"&&n.push(i),a==="footer"&&r.push(i));}return {headers:n,footers:r}}function Ku(t,e,n,r,o){let i=an(t),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=df(t,e,Jr(e,s,e.pageLayout),o.headers,o.footers,a+2,s,l);return r&&t.insertBefore(d,r),d}function cx(t,e,n){for(let r of an(t)){let o=xn(r.dataset.pageNumber,1),i=xn(r.dataset.sectionIndex,0),a=xn(r.dataset.sectionPageNumber,1);cf(r,e,Jr(e,i,e.pageLayout),n.headers,n.footers,o,i,a);}}function yi(t){return t.matches('coco-word-native-p[data-page-break-before="true"]')}function ux(t,e){let n=e.previousElementSibling;return !(n instanceof HTMLElement)||!n.matches('coco-word-native-p[data-keep-next="true"]')?null:n.previousElementSibling instanceof HTMLElement?n:null}function vi(t,e){var o;if(!t.matches('coco-word-native-p[data-section-break="true"]'))return null;let n=t.dataset.paraId;if(!n)return "nextPage";let r=e.sections.find(i=>i.lastParaId===n);return (o=r==null?void 0:r.type)!=null?o:"nextPage"}function fx(t,e){let n=e.sections.find(r=>r.lastParaId&&_u(t,r.lastParaId));return n?Math.min(n.sectionIndex+1,Math.max(0,e.sections.length-1)):null}function px(t,e){if(e.sections.length===0)return null;let n=qu(t);if(n.length===0)return null;let r=e.sections.find(i=>n.includes(i.firstParaId));if(r)return r.sectionIndex;let o=e.sections.find(i=>n.includes(i.lastParaId));return o?o.sectionIndex:null}function _u(t,e){return qu(t).includes(e)}function qu(t){if(t.matches("coco-word-native-p")){let e=t.dataset.paraId;return e?[e]:[]}return Array.from(t.querySelectorAll("coco-word-native-p")).map(e=>e.dataset.paraId).filter(e=>e!==void 0&&e.length>0)}function hx(t,e){var i;if(e==="continuous"||e==="nextColumn")return;let r=t().closest("coco-word-native-page"),o=Number((i=r==null?void 0:r.getAttribute("data-page-number"))!=null?i:"0");e==="oddPage"&&o%2===0&&t(),e==="evenPage"&&o%2===1&&t();}function mx(t,e,n){if(!t.matches("coco-word-native-p")||t.dataset.keepLines==="true"||t.dataset.pageBreakBefore==="true"||t.querySelector("img, coco-word-native-drawing, coco-word-native-table, .coco-word-page-break, .coco-word-tab-row"))return null;let r=At(t);if(r<2)return null;let o=null,i=1,a=r-1;for(;i<=a;){let s=Math.floor((i+a)/2),l=Yu(t,s);if(!l||At(l.head)===0||At(l.tail)===0){a=s-1;continue}e.appendChild(l.head),e.scrollHeight<=n()?((o==null?void 0:o.head.parentElement)===e&&e.removeChild(o.head),o=l,i=s+1):(e.removeChild(l.head),a=s-1);}return !o||o.head.parentElement!==e?null:o.tail}function gx(t,e,n,r){if(t.tagName.toLowerCase()!=="coco-word-native-table")return false;let o=t.querySelector(":scope > table"),i=o==null?void 0:o.querySelector(":scope > tbody"),a=i?Array.from(i.children).filter(Ci):[],s=eo(a);if(!o||s.length<2)return false;zs(o),t.remove();let l=e,d=tr(t,o),u=d.querySelector("tbody"),p=a.filter(w=>w.dataset.repeatHeader==="true"),f=bx(s,p),b=0;l.appendChild(d);for(let w of s){let g=Hn(w);if(!g&&b>=f&&(l=r(),d=tr(t,o),u=d.querySelector("tbody"),l.appendChild(d),Zr(u,p),b=0),nr(u,w),g||(b+=1),l.children.length<=1&&u.children.length<=w.length||l.scrollHeight<=n())continue;Qr(u,w),g||(b=Math.max(0,b-1));let h=xx(u,w,l,n()),x=h!=null?h:kx(u,w,l,n()),S=x!=null?x:Ex(u,w,l,n());if(S){g||(b+=1),l=r(),d=tr(t,o),u=d.querySelector("tbody"),l.appendChild(d),b=0,Zr(u,p),nr(u,S),g||(b=1);continue}u.children.length===0&&l.removeChild(d),l=r(),d=tr(t,o),u=d.querySelector("tbody"),l.appendChild(d),b=0,g||Zr(u,p),nr(u,w),g||(b=1);}return true}function bx(t,e){let n=t.filter(r=>!Hn(r)).length;return e.length===0||n<30?Number.POSITIVE_INFINITY:8}function wx(t,e,n,r,o){var k;let i=n(),a=i-tf(e),s=Dx(t,i);if(a>=s||o&&Ax(e,i))return false;let l=t.querySelector(":scope > table"),d=l==null?void 0:l.querySelector(":scope > tbody"),u=d?Array.from(d.children).filter(Ci):[],p=eo(u);if(!l||!d||p.length<4)return false;zs(l);let f=u.filter(I=>I.dataset.repeatHeader==="true"),b=a,w=0,g=[];for(;p.length>1&&b+w<s;){let I=p.pop();if(!I||Hn(I))break;w+=Xu(I),Qr(d,I),g.unshift(I);}if(g.length===0)return false;let h=r(),x=tr(t,l),S=x.querySelector("tbody");h.appendChild(x),Hn((k=g[0])!=null?k:[])||Zr(S,f);for(let I of g)nr(S,I);return true}function Xu(t){return t.reduce((e,n)=>e+n.getBoundingClientRect().height,0)}function xx(t,e,n,r){if(!t.closest("coco-word-native-document.uses-rowspan-table-group-splitting")||e.length<2||e.some(i=>i.dataset.repeatHeader==="true"||i.dataset.cantSplit==="true"))return null;let o=null;for(let i=1;i<e.length;i+=1){let a=yx(e,i);if(a){o&&Qr(t,o.head);for(let s of a.head)t.appendChild(s);if(n.scrollHeight<=r)o=a;else {Qr(t,a.head),o&&nr(t,o.head);break}}}return o?o.tail:null}function yx(t,e){if(e<=0||e>=t.length)return null;let n=vx(t),r=t.slice(0,e).map(a=>a.cloneNode(true)),o=t.slice(e).map(a=>a.cloneNode(true)),i=n.filter(a=>a.row<e&&a.row+a.rowSpan>e);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=e-a.row);let d=a.cell.cloneNode(false);d.rowSpan=a.row+a.rowSpan-e,d.colSpan=a.colSpan,d.dataset.rowFragmentContinuation="true",d.classList.add("is-rowspan-continuation"),Sx(o[0],d,a.column,n,e);}return {head:r,tail:o}}function vx(t){var r,o;let e=[],n=[];for(let i=0;i<t.length;i+=1){let a=t[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);e.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 e}function Sx(t,e,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?t.cells[a.cellIndex]:null;t.insertBefore(e,s!=null?s:null);}function kx(t,e,n,r){if(e.length!==1)return null;let o=e[0];if(!Px(o))return null;let i=null,a=0,s=1;for(let l=0;l<8;l+=1){let d=(a+s)/2,u=Rx(o,d);if(!u){s=d;continue}t.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===t&&t.removeChild(i.head),i=u,a=d):(t.removeChild(u.head),s=d);}return !i||i.head.parentElement!==t?null:[i.tail]}function Ex(t,e,n,r){if(e.length!==1)return null;let o=e[0];if(!Cx(o))return null;let i=null,a=0,s=1;for(let l=0;l<9;l+=1){let d=(a+s)/2,u=Ix(o,d);if(!u){s=d;continue}t.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===t&&t.removeChild(i.head),i=u,a=d):(t.removeChild(u.head),s=d);}return !i||i.head.parentElement!==t?null:[i.tail]}function Cx(t){if(t.dataset.repeatHeader==="true"||t.dataset.cantSplit==="true"||Array.from(t.cells).some(n=>n.rowSpan>1||n.colSpan>1))return false;let e=Array.from(t.cells);return e.some(n=>Ju(n))?false:Qu(t)?e.some(n=>Ds(n)):e.every(n=>Ds(n))}function Ix(t,e){let n=Fu(t),r=Fu(t);for(let o of Array.from(t.cells)){let i=Nx(o,e);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function Nx(t,e){if(!Ds(t))return ef(t);let n=Array.from(t.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*e))),i=Yu(n,o);if(!i||At(i.head)===0||At(i.tail)===0)return null;let a=t.cloneNode(false),s=t.cloneNode(false);return a.appendChild(i.head),s.appendChild(i.tail),{head:a,tail:s}}function Yu(t,e){let n=At(t);if(!Number.isInteger(e)||e<=0||e>=n)return null;let r=t.cloneNode(false),o=t.cloneNode(false);return Zu(Array.from(t.childNodes),e,r,o),r.dataset.splitFragment="head",o.dataset.splitFragment="tail",{head:r,tail:o}}function Zu(t,e,n,r){let o=e;for(let i of t){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}Tx(i,o,n,r),o=0;}}function Tx(t,e,n,r){var a;if(t.nodeType===Node.TEXT_NODE){let s=(a=t.textContent)!=null?a:"";n.appendChild(document.createTextNode(s.slice(0,e))),r.appendChild(document.createTextNode(s.slice(e)));return}if(!(t instanceof HTMLElement))return;let o=t.cloneNode(false),i=t.cloneNode(false);Zu(Array.from(t.childNodes),e,o,i),At(o)>0&&n.appendChild(o),At(i)>0&&r.appendChild(i);}function At(t){var e,n;return t.nodeType===Node.TEXT_NODE?(n=(e=t.textContent)==null?void 0:e.length)!=null?n:0:Array.from(t.childNodes).reduce((r,o)=>r+At(o),0)}function Px(t){if(t.dataset.repeatHeader==="true"||t.dataset.cantSplit==="true"||Array.from(t.cells).some(n=>n.rowSpan>1||n.colSpan>1))return false;let e=Array.from(t.cells);return e.some(n=>Ju(n))?false:Qu(t)?e.some(n=>Ls(n)):e.every(n=>Ls(n))}function Rx(t,e){let n=Bu(t),r=Bu(t);for(let o of Array.from(t.cells)){let i=Mx(o,e);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function Mx(t,e){if(!Ls(t))return ef(t);let n=Array.from(t.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*e))),o=t.cloneNode(false),i=t.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 Ju(t){return t.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 Qu(t){var e;return ((e=t.closest("coco-word-native-document"))==null?void 0:e.classList.contains("uses-natural-paragraph-flow"))===true}function Ls(t){return Array.from(t.childNodes).filter(e=>e instanceof HTMLElement).length>=2}function Ds(t){if(t.querySelector("img"))return false;let e=Array.from(t.children).filter(n=>n instanceof HTMLElement);return e.length===1&&e[0].tagName.toLowerCase()==="coco-word-native-p"&&At(e[0])>1}function ef(t){let e=t.cloneNode(true),n=t.cloneNode(false);return n.dataset.rowFragmentStatic="true",{head:e,tail:n}}function Bu(t){let e=t.cloneNode(false);return e.dataset.rowFragment="block",e.style.removeProperty("height"),e.style.removeProperty("--coco-word-row-height"),delete e.dataset.heightRule,e}function Fu(t){let e=t.cloneNode(false);return e.dataset.rowFragment="text",e.style.removeProperty("height"),e.style.removeProperty("--coco-word-row-height"),delete e.dataset.heightRule,e}function Ax(t,e){return t.scrollHeight>e+1?false:Lx(t)<=e*.75}function Lx(t){let e=0;for(let n of Array.from(t.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;e+=r.height+i+a;}return e}function tf(t){let e=t.getBoundingClientRect(),n=0;for(let r of Array.from(t.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-e.top+a);}return n}function Dx(t,e){if(e<700)return 0;let n=t.querySelectorAll("tr").length,r=t.closest("coco-word-native-document.uses-compact-latin-tables")?8:4;return n<r?0:96}function eo(t){let e=[],n=0,r=0;for(let o=0;o<t.length;o++){r=Math.max(r,o);for(let i of Array.from(t[o].cells))r=Math.max(r,o+Math.max(1,i.rowSpan)-1);o===r&&(e.push(t.slice(n,o+1)),n=o+1);}return n<t.length&&e.push(t.slice(n)),e}function nr(t,e){for(let r of e)t.appendChild(r);let n=t.closest("coco-word-native-table");n&&Vs(n);}function Hn(t){var e;return ((e=t[0])==null?void 0:e.dataset.repeatHeader)==="true"}function Zr(t,e){for(let r of e){let o=r.cloneNode(true);o.dataset.repeatedHeader="true",t.appendChild(o);}let n=t.closest("coco-word-native-table");n&&Vs(n);}function Qr(t,e){for(let n of e)n.parentElement===t&&t.removeChild(n);}function zs(t){if(t.dataset.layout!=="autofit"||t.hasAttribute("data-shared-grid"))return;let e=Array.from(t.querySelectorAll(":scope > colgroup > col")),n=getComputedStyle(t).width,r=e.map(o=>getComputedStyle(o).width);!n.endsWith("px")||parseFloat(n)<=0||!r.length||r.some(o=>!o.endsWith("px"))||(t.dataset.sharedGrid="true",t.style.tableLayout="fixed",t.style.width=n,e.forEach((o,i)=>{o.style.width=r[i];}));}function tr(t,e){let n=t.cloneNode(false);n.classList.add("is-table-fragment");let r=e.cloneNode(false),o=e.querySelector(":scope > colgroup");return o&&r.appendChild(o.cloneNode(true)),r.appendChild(document.createElement("tbody")),n.appendChild(r),n}function Vs(t){t.contentEditable="true";for(let e of Array.from(t.querySelectorAll("td, th")))e.contentEditable="true";for(let e of Array.from(t.querySelectorAll("coco-word-native-p")))e.contentEditable="true",e.childNodes.length===0&&e.appendChild(document.createTextNode(""));}function nf(t){for(;;){let e=Array.from(t.querySelectorAll(":scope > coco-word-native-page"));if(e.length<2)return;let n=e[e.length-1];if(!Wx(n))return;let r=e[e.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=Ws(r,"behind");for(let d of Array.from(s.children))l.appendChild(d);}if(a){let l=Ws(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 rf(t){for(let e of Array.from(t.querySelectorAll("coco-word-native-page")))of(e)&&e.remove();}function of(t){var r,o,i,a;let e=t.querySelector(":scope > coco-word-native-page-body");return !e||e.children.length>0?false:((o=(r=t.querySelector(":scope > .coco-word-native-page-overlay"))==null?void 0:r.children.length)!=null?o:0)+((a=(i=t.querySelector(":scope > .coco-word-native-page-behind-layer"))==null?void 0:i.children.length)!=null?a:0)===0}function af(t){let e=new Map;Array.from(t.querySelectorAll(":scope > coco-word-native-page")).forEach((r,o)=>{var s;let i=xn(r.dataset.sectionIndex,0),a=((s=e.get(i))!=null?s:0)+1;e.set(i,a),r.dataset.pageNumber=String(o+1),r.dataset.sectionPageNumber=String(a);});}function Wx(t){var a,s;let e=t.querySelector(":scope > coco-word-native-page-body"),n=t.querySelector(":scope > .coco-word-native-page-overlay"),r=t.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(!e||o===0)return false;let i=Array.from(e.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 Ci(t){return t instanceof HTMLTableRowElement}function Si(t){let e=new Set,n=Array.from(t.querySelectorAll(':scope .is-absolute-anchor:not([data-page-layer-anchor="true"])'));for(let r of n){if(!sf(r))continue;let o=r.closest("coco-word-native-p");o&&e.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"),Ws(t,a).appendChild(r);}for(let r of e)r.classList.toggle("is-flow-empty",!lf(r));Bx(t);}function Ws(t,e){let n=e==="behind"?"coco-word-native-page-behind-layer":"coco-word-native-page-overlay",r=t.querySelector(`:scope > .${n}`);if(r)return r;let o=document.createElement("div");if(o.className=n,o.contentEditable="false",e==="behind"){let i=Array.from(t.children).find(a=>a.tagName.toLowerCase()!=="coco-word-native-story");t.insertBefore(o,i!=null?i:t.firstChild);}else t.appendChild(o);return o}function Bx(t){var e,n;(e=t.querySelector(":scope > .coco-word-native-page-behind-layer:empty"))==null||e.remove(),(n=t.querySelector(":scope > .coco-word-native-page-overlay:empty"))==null||n.remove();}function sf(t){let e=t.dataset.positionVerticalRelativeFrom,n=t.dataset.positionHorizontalRelativeFrom;return Bs(e||n)}function Bs(t){return t==="page"||t==="margin"}function Fx(t){var n;if(!t.matches("coco-word-native-p")||((n=t.textContent)!=null?n:"").trim().length>0)return false;let e=Array.from(t.children);return e.length===0?false:e.every(r=>r instanceof HTMLElement&&r.classList.contains("is-absolute-anchor")&&sf(r))}function lf(t){var e;if(((e=t.textContent)!=null?e:"").trim().length>0)return true;for(let n of Array.from(t.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 df(t,e,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=hf(e,a,i,s);l.dataset.displayPageNumber=String(d),mf(l,n);for(let u of ki(e,"header",i,a,s,r))l.appendChild(Ei(u,d,s));l.appendChild(document.createElement("coco-word-native-page-body"));for(let u of ki(e,"footer",i,a,s,o))l.appendChild(Ei(u,d,s));return Si(l),t.appendChild(l),l}function cf(t,e,n,r,o,i,a,s){var u,p;let l=t.querySelector("coco-word-native-page-body");if(!l)return;t.dataset.sectionIndex=String(a),t.dataset.sectionPageNumber=String(s);let d=hf(e,a,i,s);t.dataset.displayPageNumber=String(d),mf(t,n),(u=t.querySelector(":scope > .coco-word-native-page-overlay"))==null||u.remove(),(p=t.querySelector(":scope > .coco-word-native-page-behind-layer"))==null||p.remove();for(let f of Array.from(t.querySelectorAll(":scope > coco-word-native-story")))t.removeChild(f);for(let f of ki(e,"header",i,a,s,r))t.insertBefore(Ei(f,d,s),l);for(let f of ki(e,"footer",i,a,s,o))t.appendChild(Ei(f,d,s));Si(t);}function yn(t){var e;for(let n of Array.from(t.querySelectorAll(":scope > coco-word-native-page"))){(e=n.querySelector(":scope > .coco-word-native-comment-layer"))==null||e.remove();let r=$x(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?uf(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);});}Hx(n),Ox(n);}}function Hx(t){var s,l,d,u,p,f,b,w,g,h,x;(s=t.querySelector(":scope > .coco-word-native-revision-layer"))==null||s.remove();let e=new Map,n=t.getBoundingClientRect();for(let S of Array.from(t.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",D=S.getBoundingClientRect(),H=`${I}:${k}`,A=e.get(H),O=ff(S);e.set(H,{id:k,kind:I,author:(d=S.dataset.revisionAuthor)!=null?d:"",date:(u=S.dataset.revisionDate)!=null?u:"",text:`${(p=A==null?void 0:A.text)!=null?p:""}${(b=(f=S.dataset.revisionText)!=null?f:S.textContent)!=null?b:""}`,top:(w=A==null?void 0:A.top)!=null?w:Math.max(0,D.top-n.top),paraId:(g=A==null?void 0:A.paraId)!=null?g:O==null?void 0:O.paraId,from:(h=A==null?void 0:A.from)!=null?h:O==null?void 0:O.from,to:(x=O==null?void 0:O.to)!=null?x:A==null?void 0:A.to});}if(e.size===0)return;let r=document.createElement("div");r.className="coco-word-native-revision-layer",r.contentEditable="false",t.appendChild(r);let o=Array.from(e.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 D=document.createElement("span");D.className="coco-word-native-revision-meta",D.textContent=[S.author||"User",uf(S.date)].filter(Boolean).join(" \xB7 "),I.appendChild(D),k.appendChild(I);let H=document.createElement("div");H.className="coco-word-native-revision-content",H.textContent=S.text||"(\u7A7A\u5185\u5BB9)",k.appendChild(H);let A=document.createElement("div");A.className="coco-word-native-revision-actions";for(let[O,ee,le]of [["accept","\u2713","\u63A5\u53D7\u4FEE\u8BA2"],["reject","\xD7","\u62D2\u7EDD\u4FEE\u8BA2"]]){let ae=document.createElement("button");ae.type="button",ae.dataset.revisionAction=O,ae.dataset.revisionId=S.id,ae.dataset.revisionKind=S.kind,ae.textContent=ee,ae.setAttribute("aria-label",le),ae.title=le,ae.className=`is-${O}`,A.appendChild(ae);}return k.appendChild(A),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 D=document.createElement("button");D.type="button",D.className="coco-word-native-revision-group-toggle",D.dataset.revisionGroupToggle="true",D.setAttribute("aria-expanded","false");let H=document.createElement("strong");H.textContent=`\u672C\u6BB5 ${S.length} \u6761\u4FEE\u8BA2`;let A=S.reduce((ae,te)=>(ae[te.kind]+=1,ae),{insert:0,delete:0,format:0}),O=document.createElement("span");O.textContent=[A.delete?`${A.delete} \u5220`:"",A.insert?`${A.insert} \u589E`:"",A.format?`${A.format} \u683C\u5F0F`:""].filter(Boolean).join(" \xB7 ");let ee=document.createElement("span");ee.className="coco-word-native-revision-group-affordance",ee.textContent="\u5C55\u5F00",D.append(H,O,ee);let le=document.createElement("div");le.className="coco-word-native-revision-group-list",le.hidden=true,S.forEach(ae=>le.appendChild(a(ae))),k.append(D,le),r.appendChild(k);}}function Ox(t){let n=Array.from(t.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(t.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 uf(t){if(!t)return "";let e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function $x(t){var r,o,i,a,s,l,d,u,p,f,b,w,g,h,x,S,k;let e=t.getBoundingClientRect(),n=new Map;for(let I of Array.from(t.querySelectorAll(".coco-word-comment[data-comment-id]"))){let D=Number(I.dataset.commentId);if(!Number.isFinite(D))continue;let H=I.getBoundingClientRect(),A=ff(I),O=n.get(D),ee=!(O!=null&&O.paraId)||!(A!=null&&A.paraId)||O.paraId===A.paraId;n.set(D,{commentId:D,author:(o=(r=O==null?void 0:O.author)!=null?r:I.dataset.commentAuthor)!=null?o:"",date:(a=(i=O==null?void 0:O.date)!=null?i:I.dataset.commentDate)!=null?a:"",body:(l=(s=O==null?void 0:O.body)!=null?s:I.dataset.commentBody)!=null?l:"",top:(d=O==null?void 0:O.top)!=null?d:Math.max(0,H.top-e.top),parentCommentId:(u=O==null?void 0:O.parentCommentId)!=null?u:I.dataset.parentCommentId?Number(I.dataset.parentCommentId):void 0,paraId:(p=O==null?void 0:O.paraId)!=null?p:A==null?void 0:A.paraId,from:ee?Math.min((b=(f=O==null?void 0:O.from)!=null?f:A==null?void 0:A.from)!=null?b:Number.POSITIVE_INFINITY,(w=A==null?void 0:A.from)!=null?w:Number.POSITIVE_INFINITY):(g=O==null?void 0:O.from)!=null?g:A==null?void 0:A.from,to:ee?Math.max((x=(h=O==null?void 0:O.to)!=null?h:A==null?void 0:A.to)!=null?x:Number.NEGATIVE_INFINITY,(S=A==null?void 0:A.to)!=null?S:Number.NEGATIVE_INFINITY):(k=O==null?void 0:O.to)!=null?k:A==null?void 0:A.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,D)=>I.top-D.top||I.commentId-D.commentId)}function ff(t){var a;let e=t.closest("coco-word-native-p[data-para-id]");if(!e)return null;let n=0,r=false,o=s=>{var l,d;if(!r){if(s===t){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(e),!r)return null;let i=Array.from(t.childNodes).reduce((s,l)=>s+pf(l),0);return {paraId:(a=e.dataset.paraId)!=null?a:"",from:n,to:n+Math.max(1,i)}}function pf(t){var e,n;return t.nodeType===Node.TEXT_NODE?(n=(e=t.textContent)==null?void 0:e.length)!=null?n:0:t instanceof HTMLElement&&t.classList.contains("coco-word-comment-widget")?0:t instanceof HTMLImageElement||t instanceof HTMLElement&&t.matches("coco-word-native-drawing, coco-word-native-table, .coco-word-page-break")?1:Array.from(t.childNodes).reduce((r,o)=>r+pf(o),0)}function Jr(t,e,n){var r,o;return (o=(r=t.sections.find(i=>i.sectionIndex===e))==null?void 0:r.pageLayout)!=null?o:n}function hf(t,e,n,r){let o=t.sections.find(i=>i.sectionIndex===e);return (o==null?void 0:o.pageNumberStart)!==void 0?o.pageNumberStart+r-1:n}function mf(t,e){var r,o,i;t.style.width=It(e.width),t.style.height=It(e.height);let n=Math.abs(e.margin.top);t.toggleAttribute("data-fixed-top-margin",e.margin.top<0),t.style.paddingTop=It(n),t.style.paddingRight=It(e.margin.right),t.style.paddingBottom=It(e.margin.bottom),t.style.paddingLeft=It(e.margin.left),t.style.setProperty("--coco-word-page-margin-top",It(n)),t.style.setProperty("--coco-word-page-margin-left",It(e.margin.left)),t.style.setProperty("--coco-word-page-margin-right",It(e.margin.right)),t.style.setProperty("--coco-word-page-margin-bottom",It(e.margin.bottom)),t.style.setProperty("--coco-word-header-distance",It((r=e.headerDistance)!=null?r:Math.round(n/2))),t.style.setProperty("--coco-word-footer-distance",It((o=e.footerDistance)!=null?o:Math.round(e.margin.bottom/2))),((i=e.docGrid)==null?void 0:i.linePitch)!==void 0&&e.docGrid.linePitch>0?t.style.setProperty("--coco-word-doc-grid-line-height",It(e.docGrid.linePitch)):t.style.removeProperty("--coco-word-doc-grid-line-height");}function zx(t){return Math.max(120,Us(t.height-Math.abs(t.margin.top)-t.margin.bottom))}function ki(t,e,n,r,o,i){var u,p;if(i.length<=1)return i;let a=(u=t.sections.find(f=>f.sectionIndex===r))!=null?u:t.sections[0],s=Vx(t,e,(p=a==null?void 0:a.sectionIndex)!=null?p:r),l=jx(s,(a==null?void 0:a.titlePage)===true,n,o);if(!l&&!Gx(t,e))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 Vx(t,e,n){for(let r=n;r>=0;r--){let o=t.sections.find(a=>a.sectionIndex===r),i=e==="header"?o==null?void 0:o.headerRefs:o==null?void 0:o.footerRefs;if(i&&i.length>0)return i}return []}function Gx(t,e){return t.sections.some(n=>e==="header"?n.headerRefs.length>0:n.footerRefs.length>0)}function jx(t,e,n,r){var o,i;if(t.length===0)return null;if(r===1&&e){let a=t.find(s=>s.type==="first");if(a)return a.partName}if(n%2===0){let a=t.find(s=>s.type==="even");if(a)return a.partName}return (i=(o=t.find(a=>a.type==="default"))==null?void 0:o.partName)!=null?i:t[0].partName}function Hu(t){let e=document.createElement("coco-word-native-story");e.setAttribute("data-story-kind",t.kind),e.setAttribute("data-part-name",t.partName),_x(t)||e.classList.add("is-empty");for(let n of t.blocks)e.appendChild(to(n));return e}function Ei(t,e,n){let r=t.cloneNode(true);for(let o of Array.from(r.querySelectorAll("[data-field-kind]")))o.dataset.fieldKind==="pageNumber"&&(o.textContent=String(e)),o.dataset.pageNumber=String(e),o.dataset.sectionPageNumber=String(n);return r}function gf(t,e){var i,a,s,l;let n=Array.from(t.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=Ux(e,n,r);for(let d of n){let u=Ou(d.dataset.pageNumber,1),p=xn(d.dataset.sectionIndex,0),f=Ou(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 Ux(t,e,n){let r=[],o=new Set;for(let i of e){let a=xn(i.dataset.sectionIndex,0);o.has(a)||(o.add(a),r.push(a));}return Kx(t.sections,r,n)}function Kx(t,e,n){var i,a;let r=new Map,o=1;for(let s of e){let l=t.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 Ou(t,e){let n=Number(t);return Number.isInteger(n)&&n>0?n:e}function xn(t,e){let n=Number(t);return Number.isInteger(n)&&n>=0?n:e}function _x(t){return t.blocks.some(e=>e.kind==="table"?e.rows.length>0:e.content.some(n=>n.kind==="text"?n.text.trim().length>0:(n.kind==="field",true)))}function to(t,e={}){return t.kind==="paragraph"?no(t,e):xf(t)}function no(t,e={}){var l,d,u,p,f,b,w,g,h,x,S,k,I,D,H,A,O,ee,le,ae;let n=document.createElement("coco-word-native-p");n.setAttribute("data-para-id",t.paraId),n.setAttribute("data-story",t.story),t.styleId&&n.setAttribute("data-style-id",t.styleId),((l=t.format)==null?void 0:l.outlineLevel)!==void 0&&n.setAttribute("data-outline-level",String(t.format.outlineLevel)),(d=t.format)!=null&&d.hasNumbering&&(n.setAttribute("data-numbering","true"),n.setAttribute("data-numbering-label",(p=(u=t.format.numbering)==null?void 0:u.label)!=null?p:"\u2022")),(f=t.format)!=null&&f.pageBreakBefore&&n.setAttribute("data-page-break-before","true"),(b=t.format)!=null&&b.hasSectionBreak&&n.setAttribute("data-section-break","true"),(w=t.format)!=null&&w.keepNext&&n.setAttribute("data-keep-next","true"),(g=t.format)!=null&&g.keepLines&&n.setAttribute("data-keep-lines","true"),((h=t.format)==null?void 0:h.widowControl)!==void 0&&n.setAttribute("data-widow-control",String(t.format.widowControl)),((x=t.format)==null?void 0:x.snapToGrid)!==void 0&&n.setAttribute("data-snap-to-grid",String(t.format.snapToGrid));let r=qx(t,e)?F(v({},t.format),{snapToGrid:true,spacing:F(v({},(k=(S=t.format)==null?void 0:S.spacing)!=null?k:{}),{line:e.implicitGridLinePitch,lineRule:"exact"})}):t.format,o=Or(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(t);if(i)return n.classList.add("has-tab-stops"),n.appendChild(i),n;let a=t.story.startsWith("header:")||t.story.startsWith("footer:");for(let te of t.content)if(te.kind==="text"){let oe=js(te),U=(A=(H=(I=te.format)==null?void 0:I.fontFamily)!=null?H:(D=t.format)==null?void 0:D.fontFamily)!=null?A:"";if(a&&/^(宋体|SimSun)$/i.test(U)&&/ {2}/.test(te.text)){let X=oe instanceof HTMLElement?oe:document.createElement("span");X.replaceChildren(...te.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(X);}else n.appendChild(oe);}else if(te.kind==="field")n.appendChild(bf(te));else if(te.kind==="image")n.appendChild(Gs(te));else if(te.kind==="drawing")n.appendChild(ey(te));else {let oe=document.createElement("span");oe.className="coco-word-page-break",oe.contentEditable="false",oe.setAttribute("data-kind","page-break"),oe.setAttribute("aria-label","Page break"),n.appendChild(oe);}n.childNodes.length===0&&n.appendChild(document.createTextNode(""));let s=(O=n.textContent)!=null?O:"";if(Du&&((ae=(le=(ee=t.format)==null?void 0:ee.indent)==null?void 0:le.firstLine)!=null?ae:0)>0&&/[\u3400-\u9fff]/.test(s)){let te=0;for(let oe of Du.segment(s))if(oe.isWordLike&&++te>1)break;te===1&&n.classList.add("is-single-cjk-word");}return n}function Gs(t){var r,o,i,a;let e=document.createElement("img"),n=Xr(t.src);return n&&(e.src=n),e.alt=t.drawingId,e.dataset.drawingId=t.drawingId,t.revision&&(e.classList.add(t.revision.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),e.dataset.revisionId=t.revision.revisionId,e.dataset.revisionKind=t.revision.revisionKind,e.dataset.revisionAuthor=(r=t.revision.author)!=null?r:"",e.dataset.revisionDate=(o=t.revision.date)!=null?o:"",e.dataset.revisionText="\u56FE\u7247"),t.formatRevision&&(e.classList.add("coco-word-revision-format"),e.dataset.revisionId=t.formatRevision.revisionId,e.dataset.revisionKind="format",e.dataset.revisionAuthor=(i=t.formatRevision.author)!=null?i:"",e.dataset.revisionDate=(a=t.formatRevision.date)!=null?a:"",e.dataset.revisionText="\u56FE\u7247\u5C3A\u5BF8"),t.anchoringMode&&(e.dataset.anchoringMode=t.anchoringMode),t.wrap&&(e.dataset.wrap=t.wrap),t.width&&(e.style.width=`${t.width}px`),t.height&&(e.style.height=`${t.height}px`),cy(e,t),e}function qx(t,e){var n,r,o;return !e.implicitGridForParagraphs||((n=t.format)==null?void 0:n.snapToGrid)!==void 0?false:((o=(r=t.format)==null?void 0:r.spacing)==null?void 0:o.line)===void 0&&e.implicitGridLinePitch!==void 0}function Xx(t){var e;return t.kind==="paragraph"?((e=t.format)==null?void 0:e.snapToGrid)===false:t.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(t){var p,f,b,w,g,h;let e=(p=t.format)==null?void 0:p.tabStops;if(!e||e.length===0)return null;let n=t.content.reduce((x,S)=>x+(S.kind==="text"?Qx(S.text):0),0);if(n!==1&&n!==2||!t.content.every(x=>x.kind==="text"))return null;let r=e.find(x=>x.alignment==="right");if(!r)return null;let o=r.leader!==void 0&&r.leader!=="none",i=n===1&&!o&&t.content.some(x=>{var S;return x.kind==="text"&&((S=x.format)==null?void 0:S.underline)===true&&x.text.includes(" ")}),a=Zx(t);if(!o&&!Jx(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},(x,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 x of t.content){if(x.kind!=="text")continue;let S=x.text.split(" ");for(let k=0;k<S.length;k++){let I=(f=S[k])!=null?f:"",D;if(I.length>0){let H=js(F(v({},x),{text:I}));H instanceof HTMLElement&&(D=H),((b=x.format)==null?void 0:b.underline)===true&&D&&(u[d]=D),(w=l[d])==null||w.appendChild(H);}k<S.length-1&&(i&&((g=x.format)==null?void 0:g.underline)===true&&((h=D!=null?D:u[d])==null||h.classList.add("coco-word-underlined-tab-run")),d=Math.min(d+1,l.length-1));}}for(let x=0;x<l.length;x++){if(x>0){let S=document.createElement("span");S.className="coco-word-tab-marker",S.textContent=" ",s.appendChild(S);}s.appendChild(l[x]);}return s}function Zx(t){var n,r;let e=[""];for(let o of t.content){if(o.kind!=="text")continue;let i=o.text.split(" ");e[e.length-1]+=(n=i[0])!=null?n:"";for(let a=1;a<i.length;a++)e.push((r=i[a])!=null?r:"");}return e}function Jx(t){return t.length<2||t.length>3?false:t.every(e=>e.trim().length<=32)}function Qx(t){return t.split(" ").length-1}function ey(t){var i,a,s,l;let e=document.createElement("coco-word-native-drawing");if(e.contentEditable="false",e.dataset.drawingId=t.drawingId,e.dataset.drawingKind=t.drawingKind,t.anchoringMode&&(e.dataset.anchoringMode=t.anchoringMode),t.wrap&&(e.dataset.wrap=t.wrap),e.classList.add(`is-${t.drawingKind.toLowerCase()}`),t.hasBorder&&!t.isLineOrConnector&&e.classList.add("has-border"),t.hasFill&&e.classList.add("has-fill"),t.isLineOrConnector){e.classList.add("is-line-or-connector");let d=ny(t);e.classList.add(d.vertical?"is-vertical-line":"is-horizontal-line"),e.style[d.property]=d.value;}let n=((a=(i=t.text)==null?void 0:i.trim().length)!=null?a:0)>0||((l=(s=t.paragraphs)==null?void 0:s.some(d=>d.content.some(u=>u.kind==="text"&&u.text.trim().length>0)))!=null?l:false);(t.drawingKind==="textBox"&&!n&&!t.hasBorder||!n&&!t.hasBorder&&!t.hasFill&&!t.isLineOrConnector)&&e.classList.add("is-empty");let o=oy(t);if(o&&(e.style.width=o),t.isLineOrConnector?t.height&&(e.style.height=`${t.height}px`):t.height&&ry(t)&&(e.style.minHeight=`${t.height}px`),dy(e,t),t.paragraphs&&t.paragraphs.length>0)for(let d of t.paragraphs)e.appendChild(ay(d));else if(t.text&&t.text.length>0){let d=document.createElement("span");d.className="coco-word-native-drawing-text",t.innerTextAlign&&(d.style.textAlign=hy(t.innerTextAlign)),d.textContent=t.text,e.appendChild(d);}else e.setAttribute("aria-label",t.drawingKind);return e}function ty(t){var e,n;return ((e=t.height)!=null?e:0)>Math.max(1,((n=t.width)!=null?n:0)*2)}function ny(t){var n,r;let e=ty(t);return {vertical:e,property:e?"borderLeft":"borderTop",value:`${(n=t.strokeWidth)!=null?n:1}px solid ${(r=t.strokeColor)!=null?r:"#111827"}`}}function ry(t){return !(t.drawingKind==="textBox"&&!t.hasBorder&&!t.hasFill)}function oy(t){if(!t.width)return;if(t.anchoringMode==="anchor"&&iy(t.wrap))return `${t.width}px`;let e=t.isLineOrConnector?"100%":"max(1px, calc(100% - 4pt))";return `min(${t.width}px, ${e})`}function iy(t){return t==="none"||t==="behind"||t==="inFront"}function ay(t){let e=document.createElement("div");e.className="coco-word-native-drawing-paragraph";let n=Or(t.format).cssText;n.length>0&&e.setAttribute("style",n);for(let r of t.content)r.kind==="text"?e.appendChild(js(r)):r.kind==="field"?e.appendChild(bf(r)):(r.kind==="image"||r.kind==="drawing")&&e.appendChild(document.createTextNode(r.kind==="drawing"&&r.text?r.text:"\uFFFC"));return e}function js(t){var a,s,l,d,u,p,f,b,w;if(t.kind!=="text")return document.createTextNode("");let e=Jn(t.format).cssText,n=(a=t.marks)==null?void 0:a.find(g=>g.kind==="comment"),r=(s=t.marks)==null?void 0:s.find(g=>g.kind==="revision"),o=t.formatRevision;if(!n&&!r&&!o&&!t.hyperlink&&e.length===0)return document.createTextNode(t.text);let i=t.hyperlink?document.createElement("a"):document.createElement("span");if(e.length>0&&i.setAttribute("style",e),t.hyperlink){let g=Yr(t.hyperlink.target,t.hyperlink.anchor);i.classList.add("coco-word-hyperlink"),i.setAttribute("href",g),i.dataset.hyperlinkTarget=(l=t.hyperlink.target)!=null?l:"",i.dataset.hyperlinkAnchor=(d=t.hyperlink.anchor)!=null?d:"",t.hyperlink.tooltip&&(i.title=t.hyperlink.tooltip),t.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=sy(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=ly(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(t.text)),i}function bf(t){var r;let e=document.createElement("span");e.className="coco-word-native-field",e.dataset.fieldKind=t.fieldKind,e.dataset.fieldInstruction=t.instruction;let n=Jn(t.format).cssText;return n.length>0&&e.setAttribute("style",n),e.contentEditable="false",e.textContent=(r=t.cachedText)!=null?r:"",e}function sy(t){var r,o;let e=t.author?`${t.author}: `:"",n=(o=(r=t.body)==null?void 0:r.trim())!=null?o:"";return n.length>0?`Comment ${t.commentId} ${e}${n}`:`Comment ${t.commentId}`}function ly(t){let e=t.revisionKind==="delete"?"Deleted":"Inserted",n=t.author?` by ${t.author}`:"",r=t.date?` on ${t.date}`:"",o=t.revisionId?` (${t.revisionId})`:"";return `${e}${n}${r}${o}`}function dy(t,e){e.anchoringMode==="anchor"&&(t.classList.add("coco-word-anchor-drawing"),wf(t,e));}function cy(t,e){e.anchoringMode==="anchor"&&(t.classList.add("coco-word-anchor-image"),wf(t,e));}function wf(t,e){let n=uy(e);for(let r of n.classNames)t.classList.add(r);for(let[r,o]of Object.entries(n.dataset))t.dataset[r]=o;for(let[r,o]of Object.entries(n.styleProperties))t.style.setProperty(r,o);}function uy(t){var s,l,d,u;let e=[],n={},r={};fy(t.position,n,r);let o=py(t.position),i=(l=(s=t.position)==null?void 0:s.horizontal)==null?void 0:l.relativeFrom,a=(u=(d=t.position)==null?void 0:d.vertical)==null?void 0:u.relativeFrom;return t.wrap==="square"||t.wrap==="tight"||t.wrap==="through"?o==="left"?e.push("is-float-left"):o==="right"?e.push("is-float-right"):o==="center"?e.push("is-centered"):e.push("is-float-right"):t.wrap==="behind"||t.wrap==="inFront"||t.wrap==="none"?(e.push("is-overlay-like"),e.push("is-absolute-anchor"),Bs(a)?e.push("is-page-relative-anchor"):e.push("is-paragraph-relative-anchor"),i==="column"&&e.push("is-column-relative-anchor"),o==="left"&&e.push("is-anchor-left"),o==="right"&&e.push("is-anchor-right"),o==="center"&&e.push("is-anchor-center"),t.wrap==="behind"&&e.push("is-behind-text"),t.wrap==="inFront"&&e.push("is-in-front-of-text")):t.wrap==="topAndBottom"&&(e.push("is-top-bottom"),o==="center"&&e.push("is-centered")),{classNames:e,dataset:n,styleProperties:r}}function fy(t,e,n){let r=t==null?void 0:t.horizontal,o=t==null?void 0:t.vertical;r!=null&&r.relativeFrom&&(e.positionHorizontalRelativeFrom=r.relativeFrom),o!=null&&o.relativeFrom&&(e.positionVerticalRelativeFrom=o.relativeFrom),r!=null&&r.align&&(e.positionHorizontalAlign=r.align),o!=null&&o.align&&(e.positionVerticalAlign=o.align),(r==null?void 0:r.posOffset)!==void 0&&(e.positionHorizontalOffset=String(r.posOffset),n["--coco-word-anchor-left"]=`${Fs(r.posOffset)}px`),(o==null?void 0:o.posOffset)!==void 0&&(e.positionVerticalOffset=String(o.posOffset),n["--coco-word-anchor-top"]=`${Fs(o.posOffset)}px`);}function py(t){let e=t==null?void 0:t.horizontal;if(!e)return null;if(e.align==="left"||e.align==="inside")return "left";if(e.align==="right"||e.align==="outside")return "right";if(e.align==="center")return "center";if(e.posOffset===void 0)return null;let n=Fs(e.posOffset);return n<=8?"left":n>=240?"right":null}function hy(t){return t==="both"?"justify":t}function xf(t){var s,l,d,u,p,f,b,w,g;let e=document.createElement("coco-word-native-table");e.setAttribute("data-table-id",t.tableId),t.revision&&(e.classList.add(t.revision.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),e.dataset.revisionId=t.revision.revisionId,e.dataset.revisionKind=t.revision.revisionKind,e.dataset.revisionAuthor=(s=t.revision.author)!=null?s:"",e.dataset.revisionDate=(l=t.revision.date)!=null?l:"",e.dataset.revisionText="\u8868\u683C\u7ED3\u6784"),t.tableStyleId&&e.setAttribute("data-style-id",t.tableStyleId);let n=document.createElement("table");n.dataset.layout=(u=(d=t.layout)==null?void 0:d.mode)!=null?u:"autofit",wy(n,t);let r=my(t),o=document.createElement("colgroup"),i=t.columnWidths.reduce((h,x)=>h+Math.max(0,x),0);for(let h=0;h<r;h++){let x=(p=t.columnWidths[h])!=null?p:0,S=document.createElement("col");x>0&&(S.style.width=((f=t.layout)==null?void 0:f.widthType)==="pct"?`${x/i*100}%`:Fn(x)),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<t.rows.length;h+=1){let x=t.rows[h],S=document.createElement("tr");if(S.dataset.rowIndex=String(h),x.isHeader&&(S.dataset.repeatHeader="true"),x.cantSplit&&(S.dataset.cantSplit="true"),x.height&&x.height.val>0){let I=Fn(x.height.val);S.dataset.heightRule=(b=x.height.hRule)!=null?b:"auto",S.style.setProperty("--coco-word-row-height",I),x.height.hRule,S.style.height=I;}let k=0;for(let I of x.cells){let D=Math.max(1,I.gridSpan),H=k;if(k+=D,I.vMerge==="continue")continue;let A=document.createElement("td");A.dataset.rowIndex=String(h),A.dataset.cellIndex=String(x.cells.indexOf(I)),A.dataset.columnIndex=String(H),I.gridSpan>1&&(A.colSpan=I.gridSpan),I.rowSpan&&I.rowSpan>1&&(A.rowSpan=I.rowSpan);let O=si(F(v({},I),{borders:gy(t,I,{rowIndex:h,rowCount:t.rows.length,columnIndex:H,columnSpan:D,columnCount:r})}));O.cssText&&A.setAttribute("style",O.cssText);let ee=((g=(w=t.layout)==null?void 0:w.cellSpacing)!=null?g:0)>0,le=["top","right","bottom","left"].map(ae=>{let te=O.declarations[`border-${ae}`];return te&&te!=="0"||!ee&&ae==="top"&&h!==0||!ee&&ae==="left"&&H!==0?"0":"1px"});le.includes("1px")&&(A.classList.add("has-editing-gridlines"),A.style.setProperty("--coco-word-grid-widths",le.join(" "))),A.contentEditable="true";for(let ae of I.blocks){let te=to(ae);for(let oe of [...te.matches("coco-word-native-p")?[te]:[],...Array.from(te.querySelectorAll("coco-word-native-p"))])oe.contentEditable="true";A.appendChild(te);}S.appendChild(A);}a.appendChild(S);}return n.appendChild(a),e.appendChild(n),Vs(e),e}function my(t){return Math.max(1,t.columnWidths.length,...t.rows.map(e=>e.cells.reduce((n,r)=>n+Math.max(1,r.gridSpan),0)))}function gy(t,e,n){var o,i;let r=t.borders;if(!(!r&&!e.borders))return v(v({},by(r,n,(o=e.rowSpan)!=null?o:1)),(i=e.borders)!=null?i:{})}function by(t,e,n){var l,d,u,p;if(!t)return {};let r={val:"nil"},o=e.rowIndex===0,i=e.rowIndex+n>=e.rowCount,a=e.columnIndex===0,s=e.columnIndex+e.columnSpan>=e.columnCount;return {top:(l=o?t.top:t.insideH)!=null?l:r,right:(d=s?t.right:t.insideV)!=null?d:r,bottom:(u=i?t.bottom:t.insideH)!=null?u:r,left:(p=a?t.left:t.insideV)!=null?p:r}}function wy(t,e){let n=e.layout;n&&(n.width!==void 0&&n.width>0&&(n.widthType==="pct"?t.style.width=`${n.width/50}%`:n.widthType!=="auto"&&(t.style.width=Fn(n.width))),n.alignment==="center"?(t.style.marginLeft="auto",t.style.marginRight="auto"):n.alignment==="right"?(t.style.marginLeft="auto",t.style.marginRight="0"):n.indent!==void 0&&n.indent>0&&(t.style.marginLeft=Fn(n.indent)),n.cellSpacing!==void 0&&n.cellSpacing>0&&(t.style.borderCollapse="separate",t.style.borderSpacing=n.cellSpacingType==="pct"?`${n.cellSpacing/50}%`:Fn(n.cellSpacing)));}function Fn(t){return `${t/20}pt`}function It(t){return `${Us(t)}px`}function Us(t){return t/15}function Fs(t){return t/914400*96}function Bn(t){customElements.get(t)||customElements.define(t,class extends HTMLElement{});}function Tt(t){var n,r;let e=t.getRootNode();return e instanceof ShadowRoot?(r=(n=e.getSelection)==null?void 0:n.call(e))!=null?r:null:t.ownerDocument.getSelection()}function pt(t){var o;let e=Tt(t);if(!e||e.rangeCount===0)return null;let n=e.getRangeAt(0),r=Nt(n.startContainer);return !r||!t.contains(r)?null:{paraId:(o=r.dataset.paraId)!=null?o:"",offset:Ii(r,n.startContainer,n.startOffset)}}function lt(t){let e=pt(t);return e?{kind:"caret",paraId:e.paraId,offset:e.offset}:null}function ze(t){var a,s;let e=Tt(t);if(!e||e.rangeCount===0||!e.anchorNode||!e.focusNode)return null;let n=Nt(e.anchorNode),r=Nt(e.focusNode);if(!n||!r||!t.contains(n)||!t.contains(r))return null;let o={paraId:(a=n.dataset.paraId)!=null?a:"",offset:Ii(n,e.anchorNode,e.anchorOffset)},i={paraId:(s=r.dataset.paraId)!=null?s:"",offset:Ii(r,e.focusNode,e.focusOffset)};return e.isCollapsed?{kind:"caret",paraId:o.paraId,offset:o.offset}:{kind:"text-range",anchor:o,focus:i}}function vf(t,e,n){var i;let r=xy(e,n);if(!r)return null;let o=Nt(r.node);return !o||!t.contains(o)?null:{paraId:(i=o.dataset.paraId)!=null?i:"",offset:Ii(o,r.node,r.offset)}}function dt(t,e){let n=t.querySelector(`coco-word-native-p[data-para-id="${e.paraId}"]`);if(!n)return;n.focus({preventScroll:true});let r=document.createRange(),o=On(n,e.offset);r.setStart(o.node,o.offset),r.setEnd(o.node,o.offset);let i=Tt(t);i&&(i.removeAllRanges(),i.addRange(r));}function vn(t,e,n){let r=t.querySelector(`coco-word-native-p[data-para-id="${e.paraId}"]`),o=t.querySelector(`coco-word-native-p[data-para-id="${n.paraId}"]`);if(!r||!o)return;let i=On(r,e.offset),a=On(o,n.offset),s=Tt(t);s&&(r.focus({preventScroll:true}),s.removeAllRanges(),s.setBaseAndExtent(i.node,i.offset,a.node,a.offset));}function Sf(t,e){let n=Nt(e);if(!n||!t.contains(n))return false;let r=document.createRange();r.selectNodeContents(e);let o=Tt(t);return o?(n.focus({preventScroll:true}),o.removeAllRanges(),o.addRange(r),true):false}function kf(t,e,n,r){let o=t.querySelector(`coco-word-native-p[data-para-id="${e}"]`);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 Ks(t,e,n){let r=t.querySelector(`coco-word-native-p[data-para-id="${e.paraId}"]`),o=t.querySelector(`coco-word-native-p[data-para-id="${n.paraId}"]`);if(!r||!o)return null;let i=On(r,e.offset),a=On(o,n.offset),s=document.createRange();return s.setStart(i.node,i.offset),s.setEnd(a.node,a.offset),s}function xy(t,e){var i,a;let n=document,r=(i=n.caretPositionFromPoint)==null?void 0:i.call(n,t,e);if(r)return {node:r.offsetNode,offset:r.offset};let o=(a=n.caretRangeFromPoint)==null?void 0:a.call(n,t,e);return o?{node:o.startContainer,offset:o.startOffset}:null}function Ef(t,e){Pt(t);let n=t.querySelector(`coco-word-native-p[data-para-id="${e.paraId}"] img[data-drawing-id="${e.drawingId}"]`);n==null||n.classList.add("is-selected");}function Pt(t){t.querySelectorAll("coco-word-native-p img.is-selected").forEach(e=>{e.classList.remove("is-selected");});}function Ni(t,e){var i,a;let n=0,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),o=r.nextNode();for(;o;){if(o===e)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(t){let e=t.nodeType===Node.ELEMENT_NODE?t:t.parentNode;for(;e;){if(e instanceof HTMLElement&&e.tagName==="COCO-WORD-NATIVE-P")return e;e=e.parentNode;}return null}function Ii(t,e,n){let r=0,o=null,i=a=>{var s,l,d,u;if(o===null){if(a===e){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+=Cf(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(t),o!=null?o:r}function Cf(t){var n,r;if(t.nodeType===Node.TEXT_NODE)return (r=(n=t.textContent)==null?void 0:n.length)!=null?r:0;if(_s(t))return 1;let e=0;for(let o=0;o<t.childNodes.length;o+=1)e+=Cf(t.childNodes[o]);return e}function On(t,e){var a,s;let n=document.createTreeWalker(t,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),r=n.nextNode(),o=e;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 yf(r,"before");if(o===1)return yf(r,"after");o-=1;}r=n.nextNode();}let i=document.createTextNode("");return t.appendChild(i),{node:i,offset:0}}function _s(t){return t instanceof HTMLElement&&(t instanceof HTMLImageElement||t.classList.contains("coco-word-page-break"))}function yf(t,e){let n=t.parentNode;if(!n)return {node:t,offset:0};let r=Array.prototype.indexOf.call(n.childNodes,t);return {node:n,offset:Math.max(0,r+(e==="after"?1:0))}}function qs(t,e){if(e.query.length===0)return [];let n=e.matchCase?"gu":"giu",r=new RegExp(vy(e.query),n),o=[];for(let i of Nf(t.blocks)){let a=Te(i);for(let s of a.matchAll(r)){let l=s.index,d=l+s[0].length;e.wholeWord&&!yy(a,l,d)||o.push({id:`${i.paraId}:${l}:${d}`,paraId:i.paraId,from:l,to:d,text:s[0]});}}return o}function Nf(t){return t.flatMap(e=>e.kind==="paragraph"?[e]:e.rows.flatMap(n=>n.cells.flatMap(r=>Nf(r.blocks))))}function yy(t,e,n){let r=e>0?t[e-1]:"",o=n<t.length?t[n]:"";return !If(r)&&!If(o)}function If(t){return t.length>0&&/[\p{L}\p{N}_]/u.test(t)}function vy(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Ti="application/x-coco-word-blocks+json";function Pf(t){let e=new DOMParser().parseFromString(t,"text/html"),n=Array.from(e.body.querySelectorAll("p, li, h1, h2, h3, h4, h5, h6")).filter(o=>o.tagName!=="LI"||!o.querySelector("p"));return (n.length>0?n:[e.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"),Df(o,{},i),i.text=i.text.replace(/\u00a0/g," "),i})}function Zs(t){var r;let e="",n=null;for(let o of t){o.listType!==n&&(n&&(e+=n==="numbered"?"</ol>":"</ul>"),n=(r=o.listType)!=null?r:null,n&&(e+=n==="numbered"?"<ol>":"<ul>"));let i=ky(o);e+=n?`<li>${i}</li>`:`<p>${i}</p>`;}return n&&(e+=n==="numbered"?"</ol>":"</ul>"),e}function Js(t){return JSON.stringify({version:1,blocks:t})}function Rf(t){if(!t||t.length>2e7)return null;try{let e=JSON.parse(t);return !ro(e)||e.version!==1||!Array.isArray(e.blocks)||e.blocks.length===0||e.blocks.length>1e3?null:e.blocks.every(Af)?e.blocks:null}catch(e){return null}}function Qs(t){return t.map(Mf).join(`
|
|
16
|
-
`)}function Mf(t){return t.kind==="paragraph"?
|
|
15
|
+
`),u=[a.paraId],f=a.paraId,p=Math.max(0,Math.min(a.offset,Pe(l).length)),b=on(t,f,p,(w=d[0])!=null?w:"");b&&s.push(b);for(let F=1;F<d.length;F+=1){let A=Fn(t),O=Ms(t,f,p+((h=(g=d[F-1])==null?void 0:g.length)!=null?h:0),A);if(!O)return null;s.push(O),u.push(A),f=A,p=0;let ee=on(t,f,0,(x=d[F])!=null?x:"");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):(D=(I=d[d.length-1])==null?void 0:I.length)!=null?D:0},paragraphIds:u}}function Ts(t,e,n,r,o){var u;let i=J(t,e),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(H(v({},f),{text:f.text.slice(0,b)})),w>b&&(d.push(H(v({},f),{text:f.text.slice(b,w),format:v(v({},(u=f.format)!=null?u:{}),o)})),l=true),w<p&&d.push(H(v({},f),{text:f.text.slice(w)})),s+=p;}return l?(i.content=$e(d),{kind:"format",op:"run",paraId:e,from:a.from,to:a.to,format:o}):null}function Ps(t,e,n,r,o){var f,p,b;let i=J(t,e),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=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),x=Math.min(g,a.to-s);if(h>0&&d.push(H(v({},w),{text:w.text.slice(0,h)})),x>h){let S=w.text.slice(h,x);if(o.preserveExistingComments&&((f=w.marks)!=null&&f.some(k=>k.kind==="comment")))d.push(H(v({},w),{text:S})),d.push(H(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(H(v({},w),{text:S,marks:[...k,u]}));}l=true;}x<g&&d.push(H(v({},w),{text:w.text.slice(x)})),s+=g;}return l?(i.content=$e(d),{kind:"annotation",op:"insert",paraId:e,from:a.from,to:a.to,commentId:o.commentId,body:o.body,parentCommentId:o.parentCommentId}):null}function bu(t,e,n){let r=[];for(let o of _e(t)){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===e))?(i+=f,u):(a=a===null?i:a,s=i+f,l=true,i+=f,H(v({},u),{marks:(w=u.marks)==null?void 0:w.map(g=>g.kind==="comment"&&g.commentId===e?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:e,body:n}));}return r}function wu(t,e){let n=[];for(let r of _e(t)){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===e))!=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===e));return p&&p.length>0?H(v({},d),{marks:p}):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:e}));}return n}function $t(t,e,n,r,o){var f,p;let i=J(t,e),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(H(v({},b),{text:b.text.slice(0,g)})),h>g){let x=((f=b.marks)!=null?f:[]).find(S=>S.kind==="revision");if(!(o.revisionKind==="delete"&&(x==null?void 0:x.revisionKind)==="insert")){let S=((p=b.marks)!=null?p:[]).filter(k=>k.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:e,from:a.from,to:a.to,revisionId:o.revisionId,revisionKind:o.revisionKind}):null}function xu(t,e,n,r,o){var p,b,w,g;let i=J(t,e),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 x=Ve(h);if(h.kind!=="text"||s+x<=a.from||s>=a.to){f.push(h),s+=x;continue}let S=Math.max(0,a.from-s),k=Math.min(x,a.to-s);if(S>0&&f.push(H(v({},h),{text:h.text.slice(0,S)})),k>S){let I=h.text.slice(S,k),D=((p=h.marks)!=null?p:[]).find(F=>F.kind==="revision");D?(l=true,d=(b=D.revisionId)!=null?b:D.id.replace(/^revision:/,""),u=(w=D.revisionKind)!=null?w:"insert",(o==="accept"?u==="insert":u==="delete")&&f.push(H(v({},h),{text:I,marks:((g=h.marks)!=null?g:[]).filter(A=>A.kind!=="revision")}))):f.push(H(v({},h),{text:I}));}k<x&&f.push(H(v({},h),{text:h.text.slice(k)})),s+=x;}return l?(i.content=$e(f),{kind:"revision",op:o,paraId:e,from:a.from,to:a.to,revisionId:d,revisionKind:u}):null}function yu(t,e,n,r,o){let i=J(t,e),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(H(v({},f),{text:f.text.slice(0,b)})),w>b){let g=f.formatRevision;g?(d=g.revisionId,l=true,u.push(H(v({},f),{text:f.text.slice(b,w),format:o==="reject"?g.beforeFormat?v({},g.beforeFormat):null:f.format,formatRevision:void 0}))):u.push(H(v({},f),{text:f.text.slice(b,w)}));}w<p&&u.push(H(v({},f),{text:f.text.slice(w)})),s+=p;}return l?(i.content=$e(u),{kind:"format",op:o,paraId:e,from:a.from,to:a.to,format:{},revisionId:d,revisionKind:"format"}):null}function Rs(t,e,n,r,o){var f;let i=J(t,e),a=Mt(n,r);if(!i||a.from===a.to)return null;let s=o?Xw(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(H(v({},p),{text:p.text.slice(0,w)})),g>w){let h=H(v({},p),{text:p.text.slice(w,g)});s?h.hyperlink=v({},s):delete h.hyperlink,u.push(h),ks((f=p.hyperlink)!=null?f:null,s)||(d=true);}g<b&&u.push(H(v({},p),{text:p.text.slice(g)})),l+=b;}return d?(i.content=$e(u),v({kind:"hyperlink",op:s?"set":"remove",paraId:e,from:a.from,to:a.to},s?{hyperlink:s}:{})):null}function er(t,e,n){var i,a,s;let r=J(t,e);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:e,format:n}}function vu(t,e,n,r){let o=J(t,e),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(H(v({},d),{text:d.text.slice(0,f)})),p>f&&(l.push(H(v({},d),{text:d.text.slice(f,p),format:null})),d.format&&Object.keys(d.format).length>0&&(s=true)),p<u&&l.push(H(v({},d),{text:d.text.slice(p)})),a+=u;}return s?(o.content=$e(l),{kind:"format",op:"run",paraId:e,from:i.from,to:i.to,format:{},clear:true}):null}function _r(t,e,n){var i,a,s;let r=J(t,e);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:{}),Xc(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:e,numbering:n?v({},n):null}}function SI(t,e,n,r){var l;let o=J(t,e),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 Su(t,e,n){let r=J(t,e);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:e,offset:o,drawingId:n}:i.push(s),o+=Ve(s);return a?(r.content=$e(i),a):null}function ku(t,e,n,r,o,i){var p;let a=J(t,e),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(H(v({},b),{text:b.text.slice(0,g)})),h>g&&(u.push(H(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(H(v({},b),{text:b.text.slice(h)})),l+=w;}return d?(a.content=$e(u),{kind:"format",op:"run",paraId:e,from:s.from,to:s.to,format:{},revisionId:i.revisionId,revisionKind:"format",beforeFormat:f(s.from)}):null}function Eu(t,e,n,r){let o=J(t,e);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:e,offset:i,drawingId:n,revisionId:l.revisionId,revisionKind:l.revisionKind}):null}return null}function Cu(t,e,n,r){let o=J(t,e);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:e,offset:i,drawingId:n,revisionId:l,revisionKind:"format"}}return null}function Ms(t,e,n,r=Fn(t)){let o=ve(t,e);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:e,newParaId:r,offset:n}}function qr(t,e,n){let r=J(t,e);if(!r||r.content.some(s=>s.kind!=="text"))return null;let o=Pe(r);if(o===n)return null;let i=Yw(o,n),a=r.content;return i.deletedText.length>0&&(a=zw(a,i.offset,i.deletedText.length)),i.insertedText.length>0&&(a=Iu(a,i.offset,i.insertedText,Ru(r.content,i.offset))),r.content=a,i.deletedText.length===0?{kind:"text",op:"insert",paraId:e,offset:i.offset,text:i.insertedText}:i.insertedText.length===0?{kind:"text",op:"delete",paraId:e,offset:i.offset,text:i.deletedText}:{kind:"text",op:"replace",paraId:e,offset:i.offset,text:i.insertedText,deletedText:i.deletedText}}function Iu(t,e,n,r=null){let o=[],i=0,a=false;for(let s of t){let l=Ve(s);if(!a&&e<=i+l){if(s.kind==="text"){let d=Math.max(0,e-i);o.push(H(v({},s),{text:`${s.text.slice(0,d)}${n}${s.text.slice(d)}`}));}else e<=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 zw(t,e,n){if(n<=0)return t;let r=[],o=0,i=e+n;for(let a of t){let s=Ve(a),l=o+s;if(a.kind!=="text"||l<=e||o>=i)r.push(a);else {let d=Math.max(0,e-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(H(v({},a),{text:f}));}o=l;}return $e(r)}function Vw(t,e){return Nu(t,e-1)}function Gw(t){let e=new Set(_e(t).flatMap(r=>r.content.filter(o=>o.kind==="image"||o.kind==="drawing").map(o=>o.drawingId))),n=1;for(;e.has(`coco-clipboard-${n}`);)n+=1;return `coco-clipboard-${n}`}function Nu(t,e){if(e<0)return null;let n=[],r=0,o=null;for(let i of t.content){let a=Ve(i);if(!o&&e>=r&&e<r+a)if(i.kind==="image")o={kind:"image",op:"delete",paraId:t.paraId,offset:e,drawingId:i.drawingId};else if(i.kind==="pageBreak")o={kind:"page-break",op:"delete",paraId:t.paraId,offset:e};else if(i.kind==="text"){let s=e-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:t.paraId,offset:e,text:l};}else n.push(i);else n.push(i);r+=a;}return o?(t.content=$e(n),o):null}function jw(t,e,n){let r=[],o=[],i=0;for(let a of t.content){let s=Ve(a),l=i+s;if(!(e<l&&n>i)){r.push(a),i=l;continue}if(a.kind==="text"){let u=Math.max(0,e-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(H(v({},a),{text:b})),p.length>0&&o.push({kind:"text",op:"delete",paraId:t.paraId,offset:i+u,text:p});}else a.kind==="image"?o.push({kind:"image",op:"delete",paraId:t.paraId,offset:i,drawingId:a.drawingId}):a.kind==="pageBreak"?o.push({kind:"page-break",op:"delete",paraId:t.paraId,offset:i}):r.push(a);i=l;}return {content:$e(r),changes:o.sort((a,s)=>eu(s)-eu(a))}}function wn(t,e){let n=[],r=[],o=0,i=false;for(let a of t){let s=Ve(a);if(!i&&e<=o+s){if(a.kind==="text"){let l=Math.max(0,e-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 e<=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(t){return t.kind==="text"?t.text.length:1}function hi(t){if(!(!Number.isFinite(t)||t===void 0||t<=0))return Math.max(1,Math.round(t*100)/100)}function Mt(t,e){let n=Math.max(0,Math.min(t,e)),r=Math.max(0,Math.max(t,e));return {from:n,to:r}}function eu(t){return "offset"in t&&typeof t.offset=="number"?t.offset:0}function $e(t){var n,r,o,i;let e=[];for(let a of t)if(a.kind==="text"){if(a.text.length===0)continue;let s=e[e.length-1];(s==null?void 0:s.kind)==="text"&&qw(s.format,a.format)&&ks((n=s.hyperlink)!=null?n:null,(r=a.hyperlink)!=null?r:null)&&ks((o=s.marks)!=null?o:null,(i=a.marks)!=null?i:null)?s.text+=a.text:e.push(v({},a));}else e.push(a);return e}function Ot(t){let e=JSON.parse(JSON.stringify(t));return As(e),e}function Tu(t){return t.kind==="paragraph"?t.paraId:t.tableId}function Uw(t,e,n){let r=ve(t,e.paraId),o=ve(t,n.paraId);if(!r||!o||r.container!==t.blocks||o.container!==t.blocks)return null;let i=r.index<o.index||r.index===o.index&&e.offset<=n.offset?{start:r,end:o,startOffset:e.offset,endOffset:n.offset}:{start:o,end:r,startOffset:n.offset,endOffset:e.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:t.blocks.slice(i.start.index,i.end.index+1),startOffset:Math.max(0,Math.min(i.startOffset,Pe(i.start.paragraph).length)),endOffset:Math.max(0,Math.min(i.endOffset,Pe(i.end.paragraph).length))}}function Kw(t){return t.slice(1,-1).some(e=>e.kind==="table"||e.content.some(n=>n.kind!=="text"))}function Pu(t,e){let n=Ot(e),r=new Set(_e(t).map(d=>d.paraId)),o=new Set,i=new Set;mi(t.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 mi(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();}),As(n),n}function _w(t){let e=new Set;for(let r of [t.blocks,...t.headers.map(o=>o.blocks),...t.footers.map(o=>o.blocks)])mi(r,o=>{o.kind==="table"&&e.add(o.tableId);});let n=1;for(;e.has(`coco-table-${n}`);)n+=1;return `coco-table-${n}`}function mi(t,e){for(let n of t)if(e(n),n.kind==="table")for(let r of n.rows)for(let o of r.cells)mi(o.blocks,e);}function As(t){for(let e of t)if(e.kind==="table")for(let n of e.rows)for(let r of n.cells)As(r.blocks),r.paragraphs=Vr(r.blocks);}function Vr(t){return t.flatMap(e=>e.kind==="paragraph"?[e]:e.rows.flatMap(n=>n.cells.flatMap(r=>Vr(r.blocks))))}function pi(t){return t.reduce((e,n)=>e+Ve(n),0)}function qw(t,e){return JSON.stringify(t!=null?t:null)===JSON.stringify(e!=null?e:null)}function Xw(t){var o,i,a;let e=(o=t.target)==null?void 0:o.trim(),n=(i=t.anchor)==null?void 0:i.trim().replace(/^#/,""),r=(a=t.tooltip)==null?void 0:a.trim();return !e&&!n?null:v(v(v({},e?{target:e}:{}),n?{anchor:n}:{}),r?{tooltip:r}:{})}function ks(t,e){return JSON.stringify(t)===JSON.stringify(e)}function Ru(t,e){let n=0,r=null;for(let o of t){let i=Ve(o);if(o.kind==="text"){if(e>=n&&e<=n+i)return o.format;r=o.format;}n+=i;}return r}function Yw(t,e){let n=0;for(;n<t.length&&n<e.length&&t.charCodeAt(n)===e.charCodeAt(n);)n+=1;let r=t.length,o=e.length;for(;r>n&&o>n&&t.charCodeAt(r-1)===e.charCodeAt(o-1);)r-=1,o-=1;return {offset:n,deletedText:t.slice(n,r),insertedText:e.slice(n,o)}}var Mu=/^data:(image\/(?:png|jpeg|gif|webp));base64,([a-z0-9+/]*={0,2})$/i,Zw=new Set(["http:","https:","mailto:","tel:"]);function Xr(t){let e=t.trim();return Mu.test(e)?e:null}function Au(t){let e=Xr(t),n=e?Mu.exec(e):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 Yr(t,e){if(t)try{let n=new URL(t.trim());if(Zw.has(n.protocol))return n.href}catch(n){}return e?`#${encodeURIComponent(e)}`:"#"}var Lu=260,Du=typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):void 0;function $u(){Hn("coco-word-native-document"),Hn("coco-word-native-page"),Hn("coco-word-native-page-body"),Hn("coco-word-native-story"),Hn("coco-word-native-p"),Hn("coco-word-native-drawing"),Hn("coco-word-native-table"),customElements.get("coco-word-native-scaled-run")||customElements.define("coco-word-native-scaled-run",class extends HTMLElement{constructor(){super(...arguments);W(this,"observer");}connectedCallback(){let e=this.firstElementChild;if(!(e instanceof HTMLElement))return;let n=Number(this.dataset.characterScale)/100,r=()=>{this.style.width=`${e.offsetWidth*n}px`;};r(),typeof ResizeObserver=="function"&&(this.observer=new ResizeObserver(r),this.observer.observe(e));}disconnectedCallback(){var e;(e=this.observer)==null||e.disconnect(),this.observer=void 0;}});}function zu(t){var a,s;let e=document.createElement("coco-word-native-document");e.contentEditable="true",e.spellcheck=false,Jw(t)&&e.classList.add("uses-natural-paragraph-flow"),ex(t)&&e.classList.add("uses-compact-latin-tables"),tx(t)&&e.classList.add("uses-rowspan-table-group-splitting");let n=Jn((a=t.defaults)==null?void 0:a.run).cssText;n.length>0&&e.setAttribute("style",n);for(let l of t.headers)e.appendChild(Hu(l));let r=Qw(t),o=r!==void 0&&Hs(t);for(let l of t.blocks)e.appendChild(to(l,{implicitGridForParagraphs:o,implicitGridLinePitch:r})),Xx(l)&&(o=false);for(let l of t.footers)e.appendChild(Hu(l));if(e.querySelector(".coco-word-comment, .coco-word-revision-insert, .coco-word-revision-delete, .coco-word-revision-format, [data-revision-id]")!==null)if(e.classList.add("has-annotation-rail"),((s=t.pageLayout)==null?void 0:s.width)!==void 0)e.style.minWidth=`${Us(t.pageLayout.width)+Lu}px`;else {let l=`calc(100% + ${Lu}px)`;e.style.width=l,e.style.minWidth=l;}return e}function Jw(t){if(t.blocks.length>300)return false;let e=[t.pageLayout,...t.sections.map(n=>n.pageLayout)].filter(n=>n!==void 0);return e.length===0?false:e.every(n=>n.docGrid===void 0)?true:!Hs(t)}function Qw(t){var n,r;return (r=(n=[t.pageLayout,...t.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 ex(t){return t.blocks.some(e=>e.kind==="table")&&!Hs(t)}function tx(t){return t.blocks.filter(n=>n.kind==="table").length<10?false:nx(t)<=5}function nx(t){return t.blocks.reduce((e,n)=>e+Vu(n),0)}function Vu(t){return t.kind==="paragraph"?t.content.filter(e=>e.kind==="image"||e.kind==="drawing").length:t.rows.reduce((e,n)=>e+n.cells.reduce((r,o)=>r+o.blocks.reduce((i,a)=>i+Vu(a),0),0),0)}function Hs(t){let e=0,n=0;for(let r of t.blocks.slice(0,160)){for(let o of rx(r))for(let i of o)/\s/.test(i)||(n++,/[\u3400-\u9FFF\uF900-\uFAFF]/.test(i)&&e++);if(n>=1200)break}return e>=24&&e/Math.max(n,1)>=.08}function rx(t){if(t.kind==="paragraph")return t.content.filter(n=>n.kind==="text").map(n=>n.text);let e=[];for(let n of t.rows)for(let r of n.cells)for(let o of r.paragraphs)e.push(...o.content.filter(i=>i.kind==="text").map(i=>i.text));return e}function Gu(t,e){let n=e.pageLayout;if(!n||t.dataset.paginated==="true")return;t.dataset.paginated="true",t.classList.add("is-paginated");let r=Array.from(t.children),o=r.filter(x=>x instanceof HTMLElement&&x.tagName.toLowerCase()==="coco-word-native-story"&&x.dataset.storyKind==="header"),i=r.filter(x=>x instanceof HTMLElement&&x.tagName.toLowerCase()==="coco-word-native-story"&&x.dataset.storyKind==="footer"),a=r.filter(x=>x instanceof HTMLElement&&x.tagName.toLowerCase()!=="coco-word-native-story");t.replaceChildren();let s=new Map,l=0,d=Jr(e,l,n),u=(x=l)=>{var k;let S=((k=s.get(x))!=null?k:0)+1;return s.set(x,S),l=x,d=Jr(e,x,n),df(t,e,d,o,i,t.children.length+1,x,S)},f=u(),p=f.querySelector("coco-word-native-page-body"),b=()=>Math.max(120,Math.round(p.getBoundingClientRect().height)||zx(d)),w=()=>(f=u(),p=f.querySelector("coco-word-native-page-body"),p),g=x=>{var I,D,F;if(x===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=((D=s.get(x))!=null?D:0)+1;s.set(x,k),l=x,d=Jr(e,x,n),cf(f,e,d,o,i,Number((F=f.dataset.pageNumber)!=null?F:"1"),x,k);},h=(x,S)=>{var O;let k=(O=px(x,e))!=null?O:l;p.children.length===0&&g(k),yi(x)&&p.children.length>0&&(w(),g(k)),p.appendChild(x);let I=Fx(x);I&&Si(f);let D=x.querySelector(".coco-word-page-break")!==null;if(p.scrollHeight>b()){let ee=ux(p,x);if(!gx(x,p,b,w)){p.removeChild(x),ee&&p.removeChild(ee);let le=ee?null:mx(x,p,b);w(),g(k),ee&&p.appendChild(ee),p.appendChild(le!=null?le:x);}}else if(x.matches("coco-word-native-table")){let ee=S&&vi(S,e),oe=S&&ee&&ee!=="continuous"&&ee!=="nextColumn"&&!lf(S)||S&&yi(S),ie=f.querySelector(':scope > coco-word-native-story[data-story-kind="footer"]:not(.is-empty)');(!oe||ie&&x.getBoundingClientRect().bottom>ie.getBoundingClientRect().top)&&wx(x,p,b,w,!S);}I||Si(f);let F=vi(x,e),A=fx(x,e);A!==null&&(l=A),(D||F)&&hx(w,F);};for(let x=0;x<a.length;x+=1)h(a[x],a[x+1]);nf(t),rf(t),af(t),gf(t,e),vn(t);}function ju(t,e,n){let r=t.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||!e.pageLayout)return false;let i=an(t),a=i.indexOf(o);if(a<0)return false;let s=dx(t),l=false,d=false;for(let u=a;u<i.length;u+=1){let f=i[u],p=zt(f);if(p)for(;wi(p);){if(ax(t,e,f,i[u+1],s)){i=an(t),l=true;continue}let b=ix(p);if(b.length===0||b.length>=p.children.length)break;let w=i[u+1];(!w||xi(f,w,e))&&(w=Ku(t,e,f,w,s),i=an(t),d=true);let g=zt(w);if(!g)break;for(let h of [...b].reverse())g.insertBefore(h,g.firstChild);l=true;}}i=an(t),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||xi(f,p,e))){for(;sx(b,w);)l=true;for(;;){let g=$s(w);if(g.length===0||!Uu(b,g[0],e))break;for(let h of g)b.appendChild(h);if(wi(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),!wi(b,8)){l=true;continue}w.insertBefore(h,w.firstChild);}break}l=true;}of(p)&&(p.remove(),i=an(t),u-=1,d=true);}}return l?(nf(t),rf(t),af(t),d&&cx(t,e,s),gf(t,e),vn(t),true):false}function Os(t,e,n){let r={overflowPx:0,canBackfillPrevious:false,canBackfillNext:false},o=t.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(t),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&&$s(l).some(x=>_u(x,n))&&Wu(f,i,p,l,e)),w=a[s+1],g=w?zt(w):null,h=!!(w&&g&&Wu(i,w,l,g,e));return {overflowPx:u,canBackfillPrevious:b,canBackfillNext:h}}function Wu(t,e,n,r,o){if(xi(t,e,o))return false;let i=Math.max(0,Math.round(n.getBoundingClientRect().height)-tf(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=eo(d)[0];if(u&&!On(u)&&Xu(u)<=i+8)return true}let l=$s(r);return l.length===0||!Uu(n,l[0],o)?false:ox(l)<=i+8}function ox(t){return t.reduce((e,n)=>{let r=window.getComputedStyle(n),o=Number.parseFloat(r.marginTop)||0,i=Number.parseFloat(r.marginBottom)||0;return e+n.getBoundingClientRect().height+o+i},0)}function Vt(t,e,n){let r=t.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(t),a=o?i.indexOf(o):-1;if(a<0)return false;let s=false;for(let l of e.blocks){if(l.kind!=="table")continue;let d=Array.from(t.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(xf(l));for(let p of d.slice(1))p.remove();s=true;}}return s}function an(t){return Array.from(t.children).filter(e=>e instanceof HTMLElement&&e.tagName.toLowerCase()==="coco-word-native-page")}function zt(t){return t.querySelector(":scope > coco-word-native-page-body")}function wi(t,e=1){let n=Math.max(120,Math.round(t.getBoundingClientRect().height));return t.scrollHeight>n+e}function ix(t){let e=t.lastElementChild;if(!(e instanceof HTMLElement))return [];let n=[e],r=e.previousElementSibling;return r instanceof HTMLElement&&r.matches('coco-word-native-p[data-keep-next="true"]')&&n.unshift(r),n}function $s(t){let e=t.firstElementChild;if(!(e instanceof HTMLElement))return [];let n=[e],r=e.nextElementSibling;return e.matches('coco-word-native-p[data-keep-next="true"]')&&r instanceof HTMLElement&&n.push(r),n}function ax(t,e,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(Ci).filter(k=>k.dataset.repeatedHeader!=="true"),f=eo(u);if(f.length<2)return false;let p=f[f.length-1];if(On(p))return false;let b=r;(!b||xi(n,b,e))&&(b=Ku(t,e,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){zs(s),h=tr(a,s),w.insertBefore(h,w.firstChild);let k=h.querySelector(":scope > table > tbody");k&&Zr(k,lx(t,g));}let x=h.querySelector(":scope > table > tbody");if(!x)return false;let S=Array.from(x.children).find(k=>k instanceof HTMLTableRowElement&&k.dataset.repeatedHeader!=="true");Qr(l,p);for(let k of p)x.insertBefore(k,S!=null?S:null);return true}function sx(t,e){var d,u;let n=t.lastElementChild,r=e.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(Ci).filter(f=>f.dataset.repeatedHeader!=="true"),s=eo(a)[0];if(!s||On(s))return false;let l=(u=(d=s[s.length-1])==null?void 0:d.nextElementSibling)!=null?u:null;if(nr(o,s),wi(t,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 lx(t,e){if(!e)return [];let n=Array.from(t.querySelectorAll("coco-word-native-table")).find(r=>r.dataset.tableId===e&&r.querySelector('tr[data-repeat-header="true"]'));return n?Array.from(n.querySelectorAll('tr[data-repeat-header="true"]')):[]}function xi(t,e,n){if(t.dataset.sectionIndex!==e.dataset.sectionIndex)return true;let r=zt(t),o=zt(e),i=r==null?void 0:r.lastElementChild,a=o==null?void 0:o.firstElementChild;if(a instanceof HTMLElement&&yi(a))return true;if(!(i instanceof HTMLElement))return false;if(i.querySelector(".coco-word-page-break"))return true;let s=vi(i,n);return s!==null&&s!=="continuous"&&s!=="nextColumn"}function Uu(t,e,n){if(yi(e))return false;let r=t.lastElementChild;if(!(r instanceof HTMLElement))return true;if(r.querySelector(".coco-word-page-break"))return false;let o=vi(r,n);return o===null||o==="continuous"||o==="nextColumn"}function dx(t){var o;let e=new Set,n=[],r=[];for(let i of Array.from(t.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:""}`;e.has(s)||(e.add(s),a==="header"&&n.push(i),a==="footer"&&r.push(i));}return {headers:n,footers:r}}function Ku(t,e,n,r,o){let i=an(t),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=df(t,e,Jr(e,s,e.pageLayout),o.headers,o.footers,a+2,s,l);return r&&t.insertBefore(d,r),d}function cx(t,e,n){for(let r of an(t)){let o=xn(r.dataset.pageNumber,1),i=xn(r.dataset.sectionIndex,0),a=xn(r.dataset.sectionPageNumber,1);cf(r,e,Jr(e,i,e.pageLayout),n.headers,n.footers,o,i,a);}}function yi(t){return t.matches('coco-word-native-p[data-page-break-before="true"]')}function ux(t,e){let n=e.previousElementSibling;return !(n instanceof HTMLElement)||!n.matches('coco-word-native-p[data-keep-next="true"]')?null:n.previousElementSibling instanceof HTMLElement?n:null}function vi(t,e){var o;if(!t.matches('coco-word-native-p[data-section-break="true"]'))return null;let n=t.dataset.paraId;if(!n)return "nextPage";let r=e.sections.find(i=>i.lastParaId===n);return (o=r==null?void 0:r.type)!=null?o:"nextPage"}function fx(t,e){let n=e.sections.find(r=>r.lastParaId&&_u(t,r.lastParaId));return n?Math.min(n.sectionIndex+1,Math.max(0,e.sections.length-1)):null}function px(t,e){if(e.sections.length===0)return null;let n=qu(t);if(n.length===0)return null;let r=e.sections.find(i=>n.includes(i.firstParaId));if(r)return r.sectionIndex;let o=e.sections.find(i=>n.includes(i.lastParaId));return o?o.sectionIndex:null}function _u(t,e){return qu(t).includes(e)}function qu(t){if(t.matches("coco-word-native-p")){let e=t.dataset.paraId;return e?[e]:[]}return Array.from(t.querySelectorAll("coco-word-native-p")).map(e=>e.dataset.paraId).filter(e=>e!==void 0&&e.length>0)}function hx(t,e){var i;if(e==="continuous"||e==="nextColumn")return;let r=t().closest("coco-word-native-page"),o=Number((i=r==null?void 0:r.getAttribute("data-page-number"))!=null?i:"0");e==="oddPage"&&o%2===0&&t(),e==="evenPage"&&o%2===1&&t();}function mx(t,e,n){if(!t.matches("coco-word-native-p")||t.dataset.keepLines==="true"||t.dataset.pageBreakBefore==="true"||t.querySelector("img, coco-word-native-drawing, coco-word-native-table, .coco-word-page-break, .coco-word-tab-row"))return null;let r=At(t);if(r<2)return null;let o=null,i=1,a=r-1;for(;i<=a;){let s=Math.floor((i+a)/2),l=Yu(t,s);if(!l||At(l.head)===0||At(l.tail)===0){a=s-1;continue}e.appendChild(l.head),e.scrollHeight<=n()?((o==null?void 0:o.head.parentElement)===e&&e.removeChild(o.head),o=l,i=s+1):(e.removeChild(l.head),a=s-1);}return !o||o.head.parentElement!==e?null:o.tail}function gx(t,e,n,r){if(t.tagName.toLowerCase()!=="coco-word-native-table")return false;let o=t.querySelector(":scope > table"),i=o==null?void 0:o.querySelector(":scope > tbody"),a=i?Array.from(i.children).filter(Ci):[],s=eo(a);if(!o||s.length<2)return false;zs(o),t.remove();let l=e,d=tr(t,o),u=d.querySelector("tbody"),f=a.filter(w=>w.dataset.repeatHeader==="true"),p=bx(s,f),b=0;l.appendChild(d);for(let w of s){let g=On(w);if(!g&&b>=p&&(l=r(),d=tr(t,o),u=d.querySelector("tbody"),l.appendChild(d),Zr(u,f),b=0),nr(u,w),g||(b+=1),l.children.length<=1&&u.children.length<=w.length||l.scrollHeight<=n())continue;Qr(u,w),g||(b=Math.max(0,b-1));let h=xx(u,w,l,n()),x=h!=null?h:kx(u,w,l,n()),S=x!=null?x:Ex(u,w,l,n());if(S){g||(b+=1),l=r(),d=tr(t,o),u=d.querySelector("tbody"),l.appendChild(d),b=0,Zr(u,f),nr(u,S),g||(b=1);continue}u.children.length===0&&l.removeChild(d),l=r(),d=tr(t,o),u=d.querySelector("tbody"),l.appendChild(d),b=0,g||Zr(u,f),nr(u,w),g||(b=1);}return true}function bx(t,e){let n=t.filter(r=>!On(r)).length;return e.length===0||n<30?Number.POSITIVE_INFINITY:8}function wx(t,e,n,r,o){var k;let i=n(),a=i-tf(e),s=Dx(t,i);if(a>=s||o&&Ax(e,i))return false;let l=t.querySelector(":scope > table"),d=l==null?void 0:l.querySelector(":scope > tbody"),u=d?Array.from(d.children).filter(Ci):[],f=eo(u);if(!l||!d||f.length<4)return false;zs(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||On(I))break;w+=Xu(I),Qr(d,I),g.unshift(I);}if(g.length===0)return false;let h=r(),x=tr(t,l),S=x.querySelector("tbody");h.appendChild(x),On((k=g[0])!=null?k:[])||Zr(S,p);for(let I of g)nr(S,I);return true}function Xu(t){return t.reduce((e,n)=>e+n.getBoundingClientRect().height,0)}function xx(t,e,n,r){if(!t.closest("coco-word-native-document.uses-rowspan-table-group-splitting")||e.length<2||e.some(i=>i.dataset.repeatHeader==="true"||i.dataset.cantSplit==="true"))return null;let o=null;for(let i=1;i<e.length;i+=1){let a=yx(e,i);if(a){o&&Qr(t,o.head);for(let s of a.head)t.appendChild(s);if(n.scrollHeight<=r)o=a;else {Qr(t,a.head),o&&nr(t,o.head);break}}}return o?o.tail:null}function yx(t,e){if(e<=0||e>=t.length)return null;let n=vx(t),r=t.slice(0,e).map(a=>a.cloneNode(true)),o=t.slice(e).map(a=>a.cloneNode(true)),i=n.filter(a=>a.row<e&&a.row+a.rowSpan>e);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=e-a.row);let d=a.cell.cloneNode(false);d.rowSpan=a.row+a.rowSpan-e,d.colSpan=a.colSpan,d.dataset.rowFragmentContinuation="true",d.classList.add("is-rowspan-continuation"),Sx(o[0],d,a.column,n,e);}return {head:r,tail:o}}function vx(t){var r,o;let e=[],n=[];for(let i=0;i<t.length;i+=1){let a=t[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);e.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 e}function Sx(t,e,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?t.cells[a.cellIndex]:null;t.insertBefore(e,s!=null?s:null);}function kx(t,e,n,r){if(e.length!==1)return null;let o=e[0];if(!Px(o))return null;let i=null,a=0,s=1;for(let l=0;l<8;l+=1){let d=(a+s)/2,u=Rx(o,d);if(!u){s=d;continue}t.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===t&&t.removeChild(i.head),i=u,a=d):(t.removeChild(u.head),s=d);}return !i||i.head.parentElement!==t?null:[i.tail]}function Ex(t,e,n,r){if(e.length!==1)return null;let o=e[0];if(!Cx(o))return null;let i=null,a=0,s=1;for(let l=0;l<9;l+=1){let d=(a+s)/2,u=Ix(o,d);if(!u){s=d;continue}t.appendChild(u.head),n.scrollHeight<=r?((i==null?void 0:i.head.parentElement)===t&&t.removeChild(i.head),i=u,a=d):(t.removeChild(u.head),s=d);}return !i||i.head.parentElement!==t?null:[i.tail]}function Cx(t){if(t.dataset.repeatHeader==="true"||t.dataset.cantSplit==="true"||Array.from(t.cells).some(n=>n.rowSpan>1||n.colSpan>1))return false;let e=Array.from(t.cells);return e.some(n=>Ju(n))?false:Qu(t)?e.some(n=>Ds(n)):e.every(n=>Ds(n))}function Ix(t,e){let n=Fu(t),r=Fu(t);for(let o of Array.from(t.cells)){let i=Nx(o,e);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function Nx(t,e){if(!Ds(t))return ef(t);let n=Array.from(t.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*e))),i=Yu(n,o);if(!i||At(i.head)===0||At(i.tail)===0)return null;let a=t.cloneNode(false),s=t.cloneNode(false);return a.appendChild(i.head),s.appendChild(i.tail),{head:a,tail:s}}function Yu(t,e){let n=At(t);if(!Number.isInteger(e)||e<=0||e>=n)return null;let r=t.cloneNode(false),o=t.cloneNode(false);return Zu(Array.from(t.childNodes),e,r,o),r.dataset.splitFragment="head",o.dataset.splitFragment="tail",{head:r,tail:o}}function Zu(t,e,n,r){let o=e;for(let i of t){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}Tx(i,o,n,r),o=0;}}function Tx(t,e,n,r){var a;if(t.nodeType===Node.TEXT_NODE){let s=(a=t.textContent)!=null?a:"";n.appendChild(document.createTextNode(s.slice(0,e))),r.appendChild(document.createTextNode(s.slice(e)));return}if(!(t instanceof HTMLElement))return;let o=t.cloneNode(false),i=t.cloneNode(false);Zu(Array.from(t.childNodes),e,o,i),At(o)>0&&n.appendChild(o),At(i)>0&&r.appendChild(i);}function At(t){var e,n;return t.nodeType===Node.TEXT_NODE?(n=(e=t.textContent)==null?void 0:e.length)!=null?n:0:Array.from(t.childNodes).reduce((r,o)=>r+At(o),0)}function Px(t){if(t.dataset.repeatHeader==="true"||t.dataset.cantSplit==="true"||Array.from(t.cells).some(n=>n.rowSpan>1||n.colSpan>1))return false;let e=Array.from(t.cells);return e.some(n=>Ju(n))?false:Qu(t)?e.some(n=>Ls(n)):e.every(n=>Ls(n))}function Rx(t,e){let n=Bu(t),r=Bu(t);for(let o of Array.from(t.cells)){let i=Mx(o,e);if(!i)return null;n.appendChild(i.head),r.appendChild(i.tail);}return {head:n,tail:r}}function Mx(t,e){if(!Ls(t))return ef(t);let n=Array.from(t.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*e))),o=t.cloneNode(false),i=t.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 Ju(t){return t.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 Qu(t){var e;return ((e=t.closest("coco-word-native-document"))==null?void 0:e.classList.contains("uses-natural-paragraph-flow"))===true}function Ls(t){return Array.from(t.childNodes).filter(e=>e instanceof HTMLElement).length>=2}function Ds(t){if(t.querySelector("img"))return false;let e=Array.from(t.children).filter(n=>n instanceof HTMLElement);return e.length===1&&e[0].tagName.toLowerCase()==="coco-word-native-p"&&At(e[0])>1}function ef(t){let e=t.cloneNode(true),n=t.cloneNode(false);return n.dataset.rowFragmentStatic="true",{head:e,tail:n}}function Bu(t){let e=t.cloneNode(false);return e.dataset.rowFragment="block",e.style.removeProperty("height"),e.style.removeProperty("--coco-word-row-height"),delete e.dataset.heightRule,e}function Fu(t){let e=t.cloneNode(false);return e.dataset.rowFragment="text",e.style.removeProperty("height"),e.style.removeProperty("--coco-word-row-height"),delete e.dataset.heightRule,e}function Ax(t,e){return t.scrollHeight>e+1?false:Lx(t)<=e*.75}function Lx(t){let e=0;for(let n of Array.from(t.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;e+=r.height+i+a;}return e}function tf(t){let e=t.getBoundingClientRect(),n=0;for(let r of Array.from(t.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-e.top+a);}return n}function Dx(t,e){if(e<700)return 0;let n=t.querySelectorAll("tr").length,r=t.closest("coco-word-native-document.uses-compact-latin-tables")?8:4;return n<r?0:96}function eo(t){let e=[],n=0,r=0;for(let o=0;o<t.length;o++){r=Math.max(r,o);for(let i of Array.from(t[o].cells))r=Math.max(r,o+Math.max(1,i.rowSpan)-1);o===r&&(e.push(t.slice(n,o+1)),n=o+1);}return n<t.length&&e.push(t.slice(n)),e}function nr(t,e){for(let r of e)t.appendChild(r);let n=t.closest("coco-word-native-table");n&&Vs(n);}function On(t){var e;return ((e=t[0])==null?void 0:e.dataset.repeatHeader)==="true"}function Zr(t,e){for(let r of e){let o=r.cloneNode(true);o.dataset.repeatedHeader="true",t.appendChild(o);}let n=t.closest("coco-word-native-table");n&&Vs(n);}function Qr(t,e){for(let n of e)n.parentElement===t&&t.removeChild(n);}function zs(t){if(t.dataset.layout!=="autofit"||t.hasAttribute("data-shared-grid"))return;let e=Array.from(t.querySelectorAll(":scope > colgroup > col")),n=getComputedStyle(t).width,r=e.map(o=>getComputedStyle(o).width);!n.endsWith("px")||parseFloat(n)<=0||!r.length||r.some(o=>!o.endsWith("px"))||(t.dataset.sharedGrid="true",t.style.tableLayout="fixed",t.style.width=n,e.forEach((o,i)=>{o.style.width=r[i];}));}function tr(t,e){let n=t.cloneNode(false);n.classList.add("is-table-fragment");let r=e.cloneNode(false),o=e.querySelector(":scope > colgroup");return o&&r.appendChild(o.cloneNode(true)),r.appendChild(document.createElement("tbody")),n.appendChild(r),n}function Vs(t){t.contentEditable="true";for(let e of Array.from(t.querySelectorAll("td, th")))e.contentEditable="true";for(let e of Array.from(t.querySelectorAll("coco-word-native-p")))e.contentEditable="true",e.childNodes.length===0&&e.appendChild(document.createTextNode(""));}function nf(t){for(;;){let e=Array.from(t.querySelectorAll(":scope > coco-word-native-page"));if(e.length<2)return;let n=e[e.length-1];if(!Wx(n))return;let r=e[e.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=Ws(r,"behind");for(let d of Array.from(s.children))l.appendChild(d);}if(a){let l=Ws(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 rf(t){for(let e of Array.from(t.querySelectorAll("coco-word-native-page")))of(e)&&e.remove();}function of(t){var r,o,i,a;let e=t.querySelector(":scope > coco-word-native-page-body");return !e||e.children.length>0?false:((o=(r=t.querySelector(":scope > .coco-word-native-page-overlay"))==null?void 0:r.children.length)!=null?o:0)+((a=(i=t.querySelector(":scope > .coco-word-native-page-behind-layer"))==null?void 0:i.children.length)!=null?a:0)===0}function af(t){let e=new Map;Array.from(t.querySelectorAll(":scope > coco-word-native-page")).forEach((r,o)=>{var s;let i=xn(r.dataset.sectionIndex,0),a=((s=e.get(i))!=null?s:0)+1;e.set(i,a),r.dataset.pageNumber=String(o+1),r.dataset.sectionPageNumber=String(a);});}function Wx(t){var a,s;let e=t.querySelector(":scope > coco-word-native-page-body"),n=t.querySelector(":scope > .coco-word-native-page-overlay"),r=t.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(!e||o===0)return false;let i=Array.from(e.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 Ci(t){return t instanceof HTMLTableRowElement}function Si(t){let e=new Set,n=Array.from(t.querySelectorAll(':scope .is-absolute-anchor:not([data-page-layer-anchor="true"])'));for(let r of n){if(!sf(r))continue;let o=r.closest("coco-word-native-p");o&&e.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"),Ws(t,a).appendChild(r);}for(let r of e)r.classList.toggle("is-flow-empty",!lf(r));Bx(t);}function Ws(t,e){let n=e==="behind"?"coco-word-native-page-behind-layer":"coco-word-native-page-overlay",r=t.querySelector(`:scope > .${n}`);if(r)return r;let o=document.createElement("div");if(o.className=n,o.contentEditable="false",e==="behind"){let i=Array.from(t.children).find(a=>a.tagName.toLowerCase()!=="coco-word-native-story");t.insertBefore(o,i!=null?i:t.firstChild);}else t.appendChild(o);return o}function Bx(t){var e,n;(e=t.querySelector(":scope > .coco-word-native-page-behind-layer:empty"))==null||e.remove(),(n=t.querySelector(":scope > .coco-word-native-page-overlay:empty"))==null||n.remove();}function sf(t){let e=t.dataset.positionVerticalRelativeFrom,n=t.dataset.positionHorizontalRelativeFrom;return Bs(e||n)}function Bs(t){return t==="page"||t==="margin"}function Fx(t){var n;if(!t.matches("coco-word-native-p")||((n=t.textContent)!=null?n:"").trim().length>0)return false;let e=Array.from(t.children);return e.length===0?false:e.every(r=>r instanceof HTMLElement&&r.classList.contains("is-absolute-anchor")&&sf(r))}function lf(t){var e;if(((e=t.textContent)!=null?e:"").trim().length>0)return true;for(let n of Array.from(t.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 df(t,e,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=hf(e,a,i,s);l.dataset.displayPageNumber=String(d),mf(l,n);for(let u of ki(e,"header",i,a,s,r))l.appendChild(Ei(u,d,s));l.appendChild(document.createElement("coco-word-native-page-body"));for(let u of ki(e,"footer",i,a,s,o))l.appendChild(Ei(u,d,s));return Si(l),t.appendChild(l),l}function cf(t,e,n,r,o,i,a,s){var u,f;let l=t.querySelector("coco-word-native-page-body");if(!l)return;t.dataset.sectionIndex=String(a),t.dataset.sectionPageNumber=String(s);let d=hf(e,a,i,s);t.dataset.displayPageNumber=String(d),mf(t,n),(u=t.querySelector(":scope > .coco-word-native-page-overlay"))==null||u.remove(),(f=t.querySelector(":scope > .coco-word-native-page-behind-layer"))==null||f.remove();for(let p of Array.from(t.querySelectorAll(":scope > coco-word-native-story")))t.removeChild(p);for(let p of ki(e,"header",i,a,s,r))t.insertBefore(Ei(p,d,s),l);for(let p of ki(e,"footer",i,a,s,o))t.appendChild(Ei(p,d,s));Si(t);}function vn(t){var e;for(let n of Array.from(t.querySelectorAll(":scope > coco-word-native-page"))){(e=n.querySelector(":scope > .coco-word-native-comment-layer"))==null||e.remove();let r=$x(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?uf(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);});}Hx(n),Ox(n);}}function Hx(t){var s,l,d,u,f,p,b,w,g,h,x;(s=t.querySelector(":scope > .coco-word-native-revision-layer"))==null||s.remove();let e=new Map,n=t.getBoundingClientRect();for(let S of Array.from(t.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",D=S.getBoundingClientRect(),F=`${I}:${k}`,A=e.get(F),O=ff(S);e.set(F,{id:k,kind:I,author:(d=S.dataset.revisionAuthor)!=null?d:"",date:(u=S.dataset.revisionDate)!=null?u:"",text:`${(f=A==null?void 0:A.text)!=null?f:""}${(b=(p=S.dataset.revisionText)!=null?p:S.textContent)!=null?b:""}`,top:(w=A==null?void 0:A.top)!=null?w:Math.max(0,D.top-n.top),paraId:(g=A==null?void 0:A.paraId)!=null?g:O==null?void 0:O.paraId,from:(h=A==null?void 0:A.from)!=null?h:O==null?void 0:O.from,to:(x=O==null?void 0:O.to)!=null?x:A==null?void 0:A.to});}if(e.size===0)return;let r=document.createElement("div");r.className="coco-word-native-revision-layer",r.contentEditable="false",t.appendChild(r);let o=Array.from(e.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 D=document.createElement("span");D.className="coco-word-native-revision-meta",D.textContent=[S.author||"User",uf(S.date)].filter(Boolean).join(" \xB7 "),I.appendChild(D),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 A=document.createElement("div");A.className="coco-word-native-revision-actions";for(let[O,ee,le]of [["accept","\u2713","\u63A5\u53D7\u4FEE\u8BA2"],["reject","\xD7","\u62D2\u7EDD\u4FEE\u8BA2"]]){let oe=document.createElement("button");oe.type="button",oe.dataset.revisionAction=O,oe.dataset.revisionId=S.id,oe.dataset.revisionKind=S.kind,oe.textContent=ee,oe.setAttribute("aria-label",le),oe.title=le,oe.className=`is-${O}`,A.appendChild(oe);}return k.appendChild(A),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 D=document.createElement("button");D.type="button",D.className="coco-word-native-revision-group-toggle",D.dataset.revisionGroupToggle="true",D.setAttribute("aria-expanded","false");let F=document.createElement("strong");F.textContent=`\u672C\u6BB5 ${S.length} \u6761\u4FEE\u8BA2`;let A=S.reduce((oe,ie)=>(oe[ie.kind]+=1,oe),{insert:0,delete:0,format:0}),O=document.createElement("span");O.textContent=[A.delete?`${A.delete} \u5220`:"",A.insert?`${A.insert} \u589E`:"",A.format?`${A.format} \u683C\u5F0F`:""].filter(Boolean).join(" \xB7 ");let ee=document.createElement("span");ee.className="coco-word-native-revision-group-affordance",ee.textContent="\u5C55\u5F00",D.append(F,O,ee);let le=document.createElement("div");le.className="coco-word-native-revision-group-list",le.hidden=true,S.forEach(oe=>le.appendChild(a(oe))),k.append(D,le),r.appendChild(k);}}function Ox(t){let n=Array.from(t.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(t.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 uf(t){if(!t)return "";let e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function $x(t){var r,o,i,a,s,l,d,u,f,p,b,w,g,h,x,S,k;let e=t.getBoundingClientRect(),n=new Map;for(let I of Array.from(t.querySelectorAll(".coco-word-comment[data-comment-id]"))){let D=Number(I.dataset.commentId);if(!Number.isFinite(D))continue;let F=I.getBoundingClientRect(),A=ff(I),O=n.get(D),ee=!(O!=null&&O.paraId)||!(A!=null&&A.paraId)||O.paraId===A.paraId;n.set(D,{commentId:D,author:(o=(r=O==null?void 0:O.author)!=null?r:I.dataset.commentAuthor)!=null?o:"",date:(a=(i=O==null?void 0:O.date)!=null?i:I.dataset.commentDate)!=null?a:"",body:(l=(s=O==null?void 0:O.body)!=null?s:I.dataset.commentBody)!=null?l:"",top:(d=O==null?void 0:O.top)!=null?d:Math.max(0,F.top-e.top),parentCommentId:(u=O==null?void 0:O.parentCommentId)!=null?u:I.dataset.parentCommentId?Number(I.dataset.parentCommentId):void 0,paraId:(f=O==null?void 0:O.paraId)!=null?f:A==null?void 0:A.paraId,from:ee?Math.min((b=(p=O==null?void 0:O.from)!=null?p:A==null?void 0:A.from)!=null?b:Number.POSITIVE_INFINITY,(w=A==null?void 0:A.from)!=null?w:Number.POSITIVE_INFINITY):(g=O==null?void 0:O.from)!=null?g:A==null?void 0:A.from,to:ee?Math.max((x=(h=O==null?void 0:O.to)!=null?h:A==null?void 0:A.to)!=null?x:Number.NEGATIVE_INFINITY,(S=A==null?void 0:A.to)!=null?S:Number.NEGATIVE_INFINITY):(k=O==null?void 0:O.to)!=null?k:A==null?void 0:A.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,D)=>I.top-D.top||I.commentId-D.commentId)}function ff(t){var a;let e=t.closest("coco-word-native-p[data-para-id]");if(!e)return null;let n=0,r=false,o=s=>{var l,d;if(!r){if(s===t){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(e),!r)return null;let i=Array.from(t.childNodes).reduce((s,l)=>s+pf(l),0);return {paraId:(a=e.dataset.paraId)!=null?a:"",from:n,to:n+Math.max(1,i)}}function pf(t){var e,n;return t.nodeType===Node.TEXT_NODE?(n=(e=t.textContent)==null?void 0:e.length)!=null?n:0:t instanceof HTMLElement&&t.classList.contains("coco-word-comment-widget")?0:t instanceof HTMLImageElement||t instanceof HTMLElement&&t.matches("coco-word-native-drawing, coco-word-native-table, .coco-word-page-break")?1:Array.from(t.childNodes).reduce((r,o)=>r+pf(o),0)}function Jr(t,e,n){var r,o;return (o=(r=t.sections.find(i=>i.sectionIndex===e))==null?void 0:r.pageLayout)!=null?o:n}function hf(t,e,n,r){let o=t.sections.find(i=>i.sectionIndex===e);return (o==null?void 0:o.pageNumberStart)!==void 0?o.pageNumberStart+r-1:n}function mf(t,e){var r,o,i;t.style.width=It(e.width),t.style.height=It(e.height),e.verticalAlignment&&e.verticalAlignment!=="top"?t.dataset.verticalAlignment=e.verticalAlignment:delete t.dataset.verticalAlignment;let n=Math.abs(e.margin.top);t.toggleAttribute("data-fixed-top-margin",e.margin.top<0),t.style.paddingTop=It(n),t.style.paddingRight=It(e.margin.right),t.style.paddingBottom=It(e.margin.bottom),t.style.paddingLeft=It(e.margin.left),t.style.setProperty("--coco-word-page-margin-top",It(n)),t.style.setProperty("--coco-word-page-margin-left",It(e.margin.left)),t.style.setProperty("--coco-word-page-margin-right",It(e.margin.right)),t.style.setProperty("--coco-word-page-margin-bottom",It(e.margin.bottom)),t.style.setProperty("--coco-word-header-distance",It((r=e.headerDistance)!=null?r:Math.round(n/2))),t.style.setProperty("--coco-word-footer-distance",It((o=e.footerDistance)!=null?o:Math.round(e.margin.bottom/2))),((i=e.docGrid)==null?void 0:i.linePitch)!==void 0&&e.docGrid.linePitch>0?t.style.setProperty("--coco-word-doc-grid-line-height",It(e.docGrid.linePitch)):t.style.removeProperty("--coco-word-doc-grid-line-height");}function zx(t){return Math.max(120,Us(t.height-Math.abs(t.margin.top)-t.margin.bottom))}function ki(t,e,n,r,o,i){var u,f;if(i.length<=1)return i;let a=(u=t.sections.find(p=>p.sectionIndex===r))!=null?u:t.sections[0],s=Vx(t,e,(f=a==null?void 0:a.sectionIndex)!=null?f:r),l=jx(s,(a==null?void 0:a.titlePage)===true,n,o);if(!l&&!Gx(t,e))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 Vx(t,e,n){for(let r=n;r>=0;r--){let o=t.sections.find(a=>a.sectionIndex===r),i=e==="header"?o==null?void 0:o.headerRefs:o==null?void 0:o.footerRefs;if(i&&i.length>0)return i}return []}function Gx(t,e){return t.sections.some(n=>e==="header"?n.headerRefs.length>0:n.footerRefs.length>0)}function jx(t,e,n,r){var o,i;if(t.length===0)return null;if(r===1&&e){let a=t.find(s=>s.type==="first");if(a)return a.partName}if(n%2===0){let a=t.find(s=>s.type==="even");if(a)return a.partName}return (i=(o=t.find(a=>a.type==="default"))==null?void 0:o.partName)!=null?i:t[0].partName}function Hu(t){let e=document.createElement("coco-word-native-story");e.setAttribute("data-story-kind",t.kind),e.setAttribute("data-part-name",t.partName),_x(t)||e.classList.add("is-empty");for(let n of t.blocks)e.appendChild(to(n));return e}function Ei(t,e,n){let r=t.cloneNode(true);for(let o of Array.from(r.querySelectorAll("[data-field-kind]")))o.dataset.fieldKind==="pageNumber"&&(o.textContent=String(e)),o.dataset.pageNumber=String(e),o.dataset.sectionPageNumber=String(n);return r}function gf(t,e){var i,a,s,l;let n=Array.from(t.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=Ux(e,n,r);for(let d of n){let u=Ou(d.dataset.pageNumber,1),f=xn(d.dataset.sectionIndex,0),p=Ou(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 Ux(t,e,n){let r=[],o=new Set;for(let i of e){let a=xn(i.dataset.sectionIndex,0);o.has(a)||(o.add(a),r.push(a));}return Kx(t.sections,r,n)}function Kx(t,e,n){var i,a;let r=new Map,o=1;for(let s of e){let l=t.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 Ou(t,e){let n=Number(t);return Number.isInteger(n)&&n>0?n:e}function xn(t,e){let n=Number(t);return Number.isInteger(n)&&n>=0?n:e}function _x(t){return t.blocks.some(e=>e.kind==="table"?e.rows.length>0:e.content.some(n=>n.kind==="text"?n.text.trim().length>0:(n.kind==="field",true)))}function to(t,e={}){return t.kind==="paragraph"?no(t,e):xf(t)}function no(t,e={}){var d,u,f,p,b,w,g,h,x,S,k,I,D,F,A,O,ee,le,oe,ie,ae,_,Y,B,U,z;let n=document.createElement("coco-word-native-p");n.setAttribute("data-para-id",t.paraId),n.setAttribute("data-story",t.story),t.styleId&&n.setAttribute("data-style-id",t.styleId),((d=t.format)==null?void 0:d.outlineLevel)!==void 0&&n.setAttribute("data-outline-level",String(t.format.outlineLevel)),(u=t.format)!=null&&u.hasNumbering&&(n.setAttribute("data-numbering","true"),n.setAttribute("data-numbering-label",(p=(f=t.format.numbering)==null?void 0:f.label)!=null?p:"\u2022")),(b=t.format)!=null&&b.pageBreakBefore&&n.setAttribute("data-page-break-before","true"),(w=t.format)!=null&&w.hasSectionBreak&&n.setAttribute("data-section-break","true"),(g=t.format)!=null&&g.keepNext&&n.setAttribute("data-keep-next","true"),(h=t.format)!=null&&h.keepLines&&n.setAttribute("data-keep-lines","true"),((x=t.format)==null?void 0:x.widowControl)!==void 0&&n.setAttribute("data-widow-control",String(t.format.widowControl)),((S=t.format)==null?void 0:S.snapToGrid)!==void 0&&n.setAttribute("data-snap-to-grid",String(t.format.snapToGrid));let r=qx(t,e)?H(v({},t.format),{snapToGrid:true,spacing:H(v({},(I=(k=t.format)==null?void 0:k.spacing)!=null?I:{}),{line:e.implicitGridLinePitch,lineRule:"exact"})}):t.format,o=Or(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(t);if(i)return n.classList.add("has-tab-stops"),n.appendChild(i),n;let a=t.story.startsWith("header:")||t.story.startsWith("footer:"),s=(D=t.format)==null?void 0:D.spacing;for(let G of t.content)if(G.kind==="text"){let K=js(G);t.content.length===1&&(s==null?void 0:s.lineRule)==="exact"&&s.line!==void 0&&s.line>0&&((F=G.format)==null?void 0:F.characterScale)!==void 0&&!/[\r\n\t]/.test(G.text)&&K instanceof HTMLElement&&(n.style.minHeight="0",K.style.display="flex",K.style.height=yn(s.line),K.style.lineHeight="1",K.style.alignItems="center",K.style.justifyContent=((A=t.format)==null?void 0:A.alignment)==="center"?"center":((O=t.format)==null?void 0:O.alignment)==="right"?"flex-end":"flex-start",K.style.overflow="hidden");let Se=(ie=(oe=(ee=G.format)==null?void 0:ee.fontFamily)!=null?oe:(le=t.format)==null?void 0:le.fontFamily)!=null?ie:"";if(a&&((_=(ae=G.format)==null?void 0:ae.characterScale)!=null?_:100)===100&&/^(宋体|SimSun)$/i.test(Se)&&/ {2}/.test(G.text)){let ke=K instanceof HTMLElement?K:document.createElement("span");ke.replaceChildren(...G.text.split(/( {2,})/).filter(Boolean).map(ge=>{if(ge[0]!==" "||ge.trim())return document.createTextNode(ge);let Ce=document.createElement("span");return Ce.className="coco-word-songti-spaces",Ce.textContent=ge,Ce})),n.appendChild(ke);}else n.appendChild(K);}else if(G.kind==="field")n.appendChild(bf(G));else if(G.kind==="image")n.appendChild(Gs(G));else if(G.kind==="drawing")n.appendChild(ey(G));else {let K=document.createElement("span");K.className="coco-word-page-break",K.contentEditable="false",K.setAttribute("data-kind","page-break"),K.setAttribute("aria-label","Page break"),n.appendChild(K);}n.childNodes.length===0&&n.appendChild(document.createTextNode(""));let l=(Y=n.textContent)!=null?Y:"";if(Du&&((z=(U=(B=t.format)==null?void 0:B.indent)==null?void 0:U.firstLine)!=null?z:0)>0&&/[\u3400-\u9fff]/.test(l)){let G=0;for(let K of Du.segment(l))if(K.isWordLike&&++G>1)break;G===1&&n.classList.add("is-single-cjk-word");}return n}function Gs(t){var r,o,i,a;let e=document.createElement("img"),n=Xr(t.src);return n&&(e.src=n),e.alt=t.drawingId,e.dataset.drawingId=t.drawingId,t.revision&&(e.classList.add(t.revision.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),e.dataset.revisionId=t.revision.revisionId,e.dataset.revisionKind=t.revision.revisionKind,e.dataset.revisionAuthor=(r=t.revision.author)!=null?r:"",e.dataset.revisionDate=(o=t.revision.date)!=null?o:"",e.dataset.revisionText="\u56FE\u7247"),t.formatRevision&&(e.classList.add("coco-word-revision-format"),e.dataset.revisionId=t.formatRevision.revisionId,e.dataset.revisionKind="format",e.dataset.revisionAuthor=(i=t.formatRevision.author)!=null?i:"",e.dataset.revisionDate=(a=t.formatRevision.date)!=null?a:"",e.dataset.revisionText="\u56FE\u7247\u5C3A\u5BF8"),t.anchoringMode&&(e.dataset.anchoringMode=t.anchoringMode),t.wrap&&(e.dataset.wrap=t.wrap),t.width&&(e.style.width=`${t.width}px`),t.height&&(e.style.height=`${t.height}px`),cy(e,t),e}function qx(t,e){var n,r,o;return !e.implicitGridForParagraphs||((n=t.format)==null?void 0:n.snapToGrid)!==void 0?false:((o=(r=t.format)==null?void 0:r.spacing)==null?void 0:o.line)===void 0&&e.implicitGridLinePitch!==void 0}function Xx(t){var e;return t.kind==="paragraph"?((e=t.format)==null?void 0:e.snapToGrid)===false:t.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(t){var f,p,b,w,g,h;let e=(f=t.format)==null?void 0:f.tabStops;if(!e||e.length===0)return null;let n=t.content.reduce((x,S)=>x+(S.kind==="text"?Qx(S.text):0),0);if(n!==1&&n!==2||!t.content.every(x=>x.kind==="text"))return null;let r=e.find(x=>x.alignment==="right");if(!r)return null;let o=r.leader!==void 0&&r.leader!=="none",i=n===1&&!o&&t.content.some(x=>{var S;return x.kind==="text"&&((S=x.format)==null?void 0:S.underline)===true&&x.text.includes(" ")}),a=Zx(t);if(!o&&!Jx(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",yn(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},(x,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 x of t.content){if(x.kind!=="text")continue;let S=x.text.split(" ");for(let k=0;k<S.length;k++){let I=(p=S[k])!=null?p:"",D;if(I.length>0){let F=js(H(v({},x),{text:I}));F instanceof HTMLElement&&(D=F),((b=x.format)==null?void 0:b.underline)===true&&D&&(u[d]=D),(w=l[d])==null||w.appendChild(F);}k<S.length-1&&(i&&((g=x.format)==null?void 0:g.underline)===true&&((h=D!=null?D:u[d])==null||h.classList.add("coco-word-underlined-tab-run")),d=Math.min(d+1,l.length-1));}}for(let x=0;x<l.length;x++){if(x>0){let S=document.createElement("span");S.className="coco-word-tab-marker",S.textContent=" ",s.appendChild(S);}s.appendChild(l[x]);}return s}function Zx(t){var n,r;let e=[""];for(let o of t.content){if(o.kind!=="text")continue;let i=o.text.split(" ");e[e.length-1]+=(n=i[0])!=null?n:"";for(let a=1;a<i.length;a++)e.push((r=i[a])!=null?r:"");}return e}function Jx(t){return t.length<2||t.length>3?false:t.every(e=>e.trim().length<=32)}function Qx(t){return t.split(" ").length-1}function ey(t){var i,a,s,l;let e=document.createElement("coco-word-native-drawing");if(e.contentEditable="false",e.dataset.drawingId=t.drawingId,e.dataset.drawingKind=t.drawingKind,t.anchoringMode&&(e.dataset.anchoringMode=t.anchoringMode),t.wrap&&(e.dataset.wrap=t.wrap),e.classList.add(`is-${t.drawingKind.toLowerCase()}`),t.hasBorder&&!t.isLineOrConnector&&e.classList.add("has-border"),t.hasFill&&e.classList.add("has-fill"),t.isLineOrConnector){e.classList.add("is-line-or-connector");let d=ny(t);e.classList.add(d.vertical?"is-vertical-line":"is-horizontal-line"),e.style[d.property]=d.value;}let n=((a=(i=t.text)==null?void 0:i.trim().length)!=null?a:0)>0||((l=(s=t.paragraphs)==null?void 0:s.some(d=>d.content.some(u=>u.kind==="text"&&u.text.trim().length>0)))!=null?l:false);(t.drawingKind==="textBox"&&!n&&!t.hasBorder||!n&&!t.hasBorder&&!t.hasFill&&!t.isLineOrConnector)&&e.classList.add("is-empty");let o=oy(t);if(o&&(e.style.width=o),t.isLineOrConnector?t.height&&(e.style.height=`${t.height}px`):t.height&&ry(t)&&(e.style.minHeight=`${t.height}px`),dy(e,t),t.paragraphs&&t.paragraphs.length>0)for(let d of t.paragraphs)e.appendChild(ay(d));else if(t.text&&t.text.length>0){let d=document.createElement("span");d.className="coco-word-native-drawing-text",t.innerTextAlign&&(d.style.textAlign=hy(t.innerTextAlign)),d.textContent=t.text,e.appendChild(d);}else e.setAttribute("aria-label",t.drawingKind);return e}function ty(t){var e,n;return ((e=t.height)!=null?e:0)>Math.max(1,((n=t.width)!=null?n:0)*2)}function ny(t){var n,r;let e=ty(t);return {vertical:e,property:e?"borderLeft":"borderTop",value:`${(n=t.strokeWidth)!=null?n:1}px solid ${(r=t.strokeColor)!=null?r:"#111827"}`}}function ry(t){return !(t.drawingKind==="textBox"&&!t.hasBorder&&!t.hasFill)}function oy(t){if(!t.width)return;if(t.anchoringMode==="anchor"&&iy(t.wrap))return `${t.width}px`;let e=t.isLineOrConnector?"100%":"max(1px, calc(100% - 4pt))";return `min(${t.width}px, ${e})`}function iy(t){return t==="none"||t==="behind"||t==="inFront"}function ay(t){let e=document.createElement("div");e.className="coco-word-native-drawing-paragraph";let n=Or(t.format).cssText;n.length>0&&e.setAttribute("style",n);for(let r of t.content)r.kind==="text"?e.appendChild(js(r)):r.kind==="field"?e.appendChild(bf(r)):(r.kind==="image"||r.kind==="drawing")&&e.appendChild(document.createTextNode(r.kind==="drawing"&&r.text?r.text:"\uFFFC"));return e}function js(t){var s,l,d,u,f,p,b,w,g,h,x;if(t.kind!=="text")return document.createTextNode("");let e=Jn(t.format).cssText,n=(l=(s=t.format)==null?void 0:s.characterScale)!=null?l:100,r=(d=t.marks)==null?void 0:d.find(S=>S.kind==="comment"),o=(u=t.marks)==null?void 0:u.find(S=>S.kind==="revision"),i=t.formatRevision;if(!r&&!o&&!i&&!t.hyperlink&&e.length===0&&n===100)return document.createTextNode(t.text);let a=t.hyperlink?document.createElement("a"):document.createElement("span");if(e.length>0&&a.setAttribute("style",e),t.hyperlink){let S=Yr(t.hyperlink.target,t.hyperlink.anchor);a.classList.add("coco-word-hyperlink"),a.setAttribute("href",S),a.dataset.hyperlinkTarget=(f=t.hyperlink.target)!=null?f:"",a.dataset.hyperlinkAnchor=(p=t.hyperlink.anchor)!=null?p:"",t.hyperlink.tooltip&&(a.title=t.hyperlink.tooltip),t.hyperlink.target&&(a.setAttribute("target","_blank"),a.setAttribute("rel","noopener noreferrer"));}if(r&&(a.classList.add("coco-word-comment"),a.dataset.commentId=String(r.commentId),a.dataset.commentAuthor=r.author,a.dataset.commentDate=r.date,a.dataset.commentBody=r.body,r.parentCommentId!==void 0&&(a.dataset.parentCommentId=String(r.parentCommentId),a.classList.add("coco-word-comment-reply")),a.title=sy(r)),o&&(a.classList.add(o.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),a.dataset.revisionId=(b=o.revisionId)!=null?b:"",a.dataset.revisionKind=o.revisionKind,a.dataset.revisionAuthor=(w=o.author)!=null?w:"",a.dataset.revisionDate=(g=o.date)!=null?g:"",a.title=ly(o)),i&&(a.classList.add("coco-word-revision-format"),a.dataset.revisionId=i.revisionId,a.dataset.revisionKind="format",a.dataset.revisionAuthor=(h=i.author)!=null?h:"",a.dataset.revisionDate=(x=i.date)!=null?x:"",a.title="\u683C\u5F0F\u4FEE\u8BA2"),n===100)a.textContent=t.text;else {let S=document.createElement("coco-word-native-scaled-run");S.dataset.characterScale=String(n),S.style.display="inline-block",S.style.overflowX="clip";let k=document.createElement("span");k.style.display="inline-block",k.style.whiteSpace="pre",k.style.transform=`scaleX(${n/100})`,k.style.transformOrigin="left",k.textContent=t.text,S.appendChild(k),a.appendChild(S);}return a}function bf(t){var r;let e=document.createElement("span");e.className="coco-word-native-field",e.dataset.fieldKind=t.fieldKind,e.dataset.fieldInstruction=t.instruction;let n=Jn(t.format).cssText;return n.length>0&&e.setAttribute("style",n),e.contentEditable="false",e.textContent=(r=t.cachedText)!=null?r:"",e}function sy(t){var r,o;let e=t.author?`${t.author}: `:"",n=(o=(r=t.body)==null?void 0:r.trim())!=null?o:"";return n.length>0?`Comment ${t.commentId} ${e}${n}`:`Comment ${t.commentId}`}function ly(t){let e=t.revisionKind==="delete"?"Deleted":"Inserted",n=t.author?` by ${t.author}`:"",r=t.date?` on ${t.date}`:"",o=t.revisionId?` (${t.revisionId})`:"";return `${e}${n}${r}${o}`}function dy(t,e){e.anchoringMode==="anchor"&&(t.classList.add("coco-word-anchor-drawing"),wf(t,e));}function cy(t,e){e.anchoringMode==="anchor"&&(t.classList.add("coco-word-anchor-image"),wf(t,e));}function wf(t,e){let n=uy(e);for(let r of n.classNames)t.classList.add(r);for(let[r,o]of Object.entries(n.dataset))t.dataset[r]=o;for(let[r,o]of Object.entries(n.styleProperties))t.style.setProperty(r,o);}function uy(t){var s,l,d,u;let e=[],n={},r={};fy(t.position,n,r);let o=py(t.position),i=(l=(s=t.position)==null?void 0:s.horizontal)==null?void 0:l.relativeFrom,a=(u=(d=t.position)==null?void 0:d.vertical)==null?void 0:u.relativeFrom;return t.wrap==="square"||t.wrap==="tight"||t.wrap==="through"?o==="left"?e.push("is-float-left"):o==="right"?e.push("is-float-right"):o==="center"?e.push("is-centered"):e.push("is-float-right"):t.wrap==="behind"||t.wrap==="inFront"||t.wrap==="none"?(e.push("is-overlay-like"),e.push("is-absolute-anchor"),Bs(a)?e.push("is-page-relative-anchor"):e.push("is-paragraph-relative-anchor"),i==="column"&&e.push("is-column-relative-anchor"),o==="left"&&e.push("is-anchor-left"),o==="right"&&e.push("is-anchor-right"),o==="center"&&e.push("is-anchor-center"),t.wrap==="behind"&&e.push("is-behind-text"),t.wrap==="inFront"&&e.push("is-in-front-of-text")):t.wrap==="topAndBottom"&&(e.push("is-top-bottom"),o==="center"&&e.push("is-centered")),{classNames:e,dataset:n,styleProperties:r}}function fy(t,e,n){let r=t==null?void 0:t.horizontal,o=t==null?void 0:t.vertical;r!=null&&r.relativeFrom&&(e.positionHorizontalRelativeFrom=r.relativeFrom),o!=null&&o.relativeFrom&&(e.positionVerticalRelativeFrom=o.relativeFrom),r!=null&&r.align&&(e.positionHorizontalAlign=r.align),o!=null&&o.align&&(e.positionVerticalAlign=o.align),(r==null?void 0:r.posOffset)!==void 0&&(e.positionHorizontalOffset=String(r.posOffset),n["--coco-word-anchor-left"]=`${Fs(r.posOffset)}px`),(o==null?void 0:o.posOffset)!==void 0&&(e.positionVerticalOffset=String(o.posOffset),n["--coco-word-anchor-top"]=`${Fs(o.posOffset)}px`);}function py(t){let e=t==null?void 0:t.horizontal;if(!e)return null;if(e.align==="left"||e.align==="inside")return "left";if(e.align==="right"||e.align==="outside")return "right";if(e.align==="center")return "center";if(e.posOffset===void 0)return null;let n=Fs(e.posOffset);return n<=8?"left":n>=240?"right":null}function hy(t){return t==="both"?"justify":t}function xf(t){var s,l,d,u,f,p,b,w,g;let e=document.createElement("coco-word-native-table");e.setAttribute("data-table-id",t.tableId),t.revision&&(e.classList.add(t.revision.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert"),e.dataset.revisionId=t.revision.revisionId,e.dataset.revisionKind=t.revision.revisionKind,e.dataset.revisionAuthor=(s=t.revision.author)!=null?s:"",e.dataset.revisionDate=(l=t.revision.date)!=null?l:"",e.dataset.revisionText="\u8868\u683C\u7ED3\u6784"),t.tableStyleId&&e.setAttribute("data-style-id",t.tableStyleId);let n=document.createElement("table");n.dataset.layout=(u=(d=t.layout)==null?void 0:d.mode)!=null?u:"autofit",wy(n,t);let r=my(t),o=document.createElement("colgroup"),i=t.columnWidths.reduce((h,x)=>h+Math.max(0,x),0);for(let h=0;h<r;h++){let x=(f=t.columnWidths[h])!=null?f:0,S=document.createElement("col");x>0&&(S.style.width=((p=t.layout)==null?void 0:p.widthType)==="pct"?`${x/i*100}%`:yn(x)),o.appendChild(S);}n.appendChild(o),i>0&&!n.style.width&&(n.style.width=yn(i));let a=document.createElement("tbody");for(let h=0;h<t.rows.length;h+=1){let x=t.rows[h],S=document.createElement("tr");if(S.dataset.rowIndex=String(h),x.isHeader&&(S.dataset.repeatHeader="true"),x.cantSplit&&(S.dataset.cantSplit="true"),x.height&&x.height.val>0){let I=yn(x.height.val);S.dataset.heightRule=(b=x.height.hRule)!=null?b:"auto",S.style.setProperty("--coco-word-row-height",I),x.height.hRule,S.style.height=I;}let k=0;for(let I of x.cells){let D=Math.max(1,I.gridSpan),F=k;if(k+=D,I.vMerge==="continue")continue;let A=document.createElement("td");A.dataset.rowIndex=String(h),A.dataset.cellIndex=String(x.cells.indexOf(I)),A.dataset.columnIndex=String(F),I.gridSpan>1&&(A.colSpan=I.gridSpan),I.rowSpan&&I.rowSpan>1&&(A.rowSpan=I.rowSpan);let O=si(H(v({},I),{borders:gy(t,I,{rowIndex:h,rowCount:t.rows.length,columnIndex:F,columnSpan:D,columnCount:r})}));O.cssText&&A.setAttribute("style",O.cssText);let ee=((g=(w=t.layout)==null?void 0:w.cellSpacing)!=null?g:0)>0,le=["top","right","bottom","left"].map(oe=>{let ie=O.declarations[`border-${oe}`];return ie&&ie!=="0"||!ee&&oe==="top"&&h!==0||!ee&&oe==="left"&&F!==0?"0":"1px"});le.includes("1px")&&(A.classList.add("has-editing-gridlines"),A.style.setProperty("--coco-word-grid-widths",le.join(" "))),A.contentEditable="true";for(let oe of I.blocks){let ie=to(oe);for(let ae of [...ie.matches("coco-word-native-p")?[ie]:[],...Array.from(ie.querySelectorAll("coco-word-native-p"))])ae.contentEditable="true";A.appendChild(ie);}S.appendChild(A);}a.appendChild(S);}return n.appendChild(a),e.appendChild(n),Vs(e),e}function my(t){return Math.max(1,t.columnWidths.length,...t.rows.map(e=>e.cells.reduce((n,r)=>n+Math.max(1,r.gridSpan),0)))}function gy(t,e,n){var o,i;let r=t.borders;if(!(!r&&!e.borders))return v(v({},by(r,n,(o=e.rowSpan)!=null?o:1)),(i=e.borders)!=null?i:{})}function by(t,e,n){var l,d,u,f;if(!t)return {};let r={val:"nil"},o=e.rowIndex===0,i=e.rowIndex+n>=e.rowCount,a=e.columnIndex===0,s=e.columnIndex+e.columnSpan>=e.columnCount;return {top:(l=o?t.top:t.insideH)!=null?l:r,right:(d=s?t.right:t.insideV)!=null?d:r,bottom:(u=i?t.bottom:t.insideH)!=null?u:r,left:(f=a?t.left:t.insideV)!=null?f:r}}function wy(t,e){let n=e.layout;n&&(n.width!==void 0&&n.width>0&&(n.widthType==="pct"?t.style.width=`${n.width/50}%`:n.widthType!=="auto"&&(t.style.width=yn(n.width))),n.alignment==="center"?(t.style.marginLeft="auto",t.style.marginRight="auto"):n.alignment==="right"?(t.style.marginLeft="auto",t.style.marginRight="0"):n.indent!==void 0&&n.indent>0&&(t.style.marginLeft=yn(n.indent)),n.cellSpacing!==void 0&&n.cellSpacing>0&&(t.style.borderCollapse="separate",t.style.borderSpacing=n.cellSpacingType==="pct"?`${n.cellSpacing/50}%`:yn(n.cellSpacing)));}function yn(t){return `${t/20}pt`}function It(t){return `${Us(t)}px`}function Us(t){return t/15}function Fs(t){return t/914400*96}function Hn(t){customElements.get(t)||customElements.define(t,class extends HTMLElement{});}function Tt(t){var n,r;let e=t.getRootNode();return e instanceof ShadowRoot?(r=(n=e.getSelection)==null?void 0:n.call(e))!=null?r:null:t.ownerDocument.getSelection()}function pt(t){var o;let e=Tt(t);if(!e||e.rangeCount===0)return null;let n=e.getRangeAt(0),r=Nt(n.startContainer);return !r||!t.contains(r)?null:{paraId:(o=r.dataset.paraId)!=null?o:"",offset:Ii(r,n.startContainer,n.startOffset)}}function lt(t){let e=pt(t);return e?{kind:"caret",paraId:e.paraId,offset:e.offset}:null}function ze(t){var a,s;let e=Tt(t);if(!e||e.rangeCount===0||!e.anchorNode||!e.focusNode)return null;let n=Nt(e.anchorNode),r=Nt(e.focusNode);if(!n||!r||!t.contains(n)||!t.contains(r))return null;let o={paraId:(a=n.dataset.paraId)!=null?a:"",offset:Ii(n,e.anchorNode,e.anchorOffset)},i={paraId:(s=r.dataset.paraId)!=null?s:"",offset:Ii(r,e.focusNode,e.focusOffset)};return e.isCollapsed?{kind:"caret",paraId:o.paraId,offset:o.offset}:{kind:"text-range",anchor:o,focus:i}}function vf(t,e,n){var i;let r=xy(e,n);if(!r)return null;let o=Nt(r.node);return !o||!t.contains(o)?null:{paraId:(i=o.dataset.paraId)!=null?i:"",offset:Ii(o,r.node,r.offset)}}function dt(t,e){let n=t.querySelector(`coco-word-native-p[data-para-id="${e.paraId}"]`);if(!n)return;n.focus({preventScroll:true});let r=document.createRange(),o=$n(n,e.offset);r.setStart(o.node,o.offset),r.setEnd(o.node,o.offset);let i=Tt(t);i&&(i.removeAllRanges(),i.addRange(r));}function Sn(t,e,n){let r=t.querySelector(`coco-word-native-p[data-para-id="${e.paraId}"]`),o=t.querySelector(`coco-word-native-p[data-para-id="${n.paraId}"]`);if(!r||!o)return;let i=$n(r,e.offset),a=$n(o,n.offset),s=Tt(t);s&&(r.focus({preventScroll:true}),s.removeAllRanges(),s.setBaseAndExtent(i.node,i.offset,a.node,a.offset));}function Sf(t,e){let n=Nt(e);if(!n||!t.contains(n))return false;let r=document.createRange();r.selectNodeContents(e);let o=Tt(t);return o?(n.focus({preventScroll:true}),o.removeAllRanges(),o.addRange(r),true):false}function kf(t,e,n,r){let o=t.querySelector(`coco-word-native-p[data-para-id="${e}"]`);if(!o)return null;let i=$n(o,n),a=$n(o,r),s=document.createRange();return s.setStart(i.node,i.offset),s.setEnd(a.node,a.offset),s}function Ks(t,e,n){let r=t.querySelector(`coco-word-native-p[data-para-id="${e.paraId}"]`),o=t.querySelector(`coco-word-native-p[data-para-id="${n.paraId}"]`);if(!r||!o)return null;let i=$n(r,e.offset),a=$n(o,n.offset),s=document.createRange();return s.setStart(i.node,i.offset),s.setEnd(a.node,a.offset),s}function xy(t,e){var i,a;let n=document,r=(i=n.caretPositionFromPoint)==null?void 0:i.call(n,t,e);if(r)return {node:r.offsetNode,offset:r.offset};let o=(a=n.caretRangeFromPoint)==null?void 0:a.call(n,t,e);return o?{node:o.startContainer,offset:o.startOffset}:null}function Ef(t,e){Pt(t);let n=t.querySelector(`coco-word-native-p[data-para-id="${e.paraId}"] img[data-drawing-id="${e.drawingId}"]`);n==null||n.classList.add("is-selected");}function Pt(t){t.querySelectorAll("coco-word-native-p img.is-selected").forEach(e=>{e.classList.remove("is-selected");});}function Ni(t,e){var i,a;let n=0,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),o=r.nextNode();for(;o;){if(o===e)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(t){let e=t.nodeType===Node.ELEMENT_NODE?t:t.parentNode;for(;e;){if(e instanceof HTMLElement&&e.tagName==="COCO-WORD-NATIVE-P")return e;e=e.parentNode;}return null}function Ii(t,e,n){let r=0,o=null,i=a=>{var s,l,d,u;if(o===null){if(a===e){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+=Cf(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(t),o!=null?o:r}function Cf(t){var n,r;if(t.nodeType===Node.TEXT_NODE)return (r=(n=t.textContent)==null?void 0:n.length)!=null?r:0;if(_s(t))return 1;let e=0;for(let o=0;o<t.childNodes.length;o+=1)e+=Cf(t.childNodes[o]);return e}function $n(t,e){var a,s;let n=document.createTreeWalker(t,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),r=n.nextNode(),o=e;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 yf(r,"before");if(o===1)return yf(r,"after");o-=1;}r=n.nextNode();}let i=document.createTextNode("");return t.appendChild(i),{node:i,offset:0}}function _s(t){return t instanceof HTMLElement&&(t instanceof HTMLImageElement||t.classList.contains("coco-word-page-break"))}function yf(t,e){let n=t.parentNode;if(!n)return {node:t,offset:0};let r=Array.prototype.indexOf.call(n.childNodes,t);return {node:n,offset:Math.max(0,r+(e==="after"?1:0))}}function qs(t,e){if(e.query.length===0)return [];let n=e.matchCase?"gu":"giu",r=new RegExp(vy(e.query),n),o=[];for(let i of Nf(t.blocks)){let a=Pe(i);for(let s of a.matchAll(r)){let l=s.index,d=l+s[0].length;e.wholeWord&&!yy(a,l,d)||o.push({id:`${i.paraId}:${l}:${d}`,paraId:i.paraId,from:l,to:d,text:s[0]});}}return o}function Nf(t){return t.flatMap(e=>e.kind==="paragraph"?[e]:e.rows.flatMap(n=>n.cells.flatMap(r=>Nf(r.blocks))))}function yy(t,e,n){let r=e>0?t[e-1]:"",o=n<t.length?t[n]:"";return !If(r)&&!If(o)}function If(t){return t.length>0&&/[\p{L}\p{N}_]/u.test(t)}function vy(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Ti="application/x-coco-word-blocks+json";function Pf(t){let e=new DOMParser().parseFromString(t,"text/html"),n=Array.from(e.body.querySelectorAll("p, li, h1, h2, h3, h4, h5, h6")).filter(o=>o.tagName!=="LI"||!o.querySelector("p"));return (n.length>0?n:[e.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"),Df(o,{},i),i.text=i.text.replace(/\u00a0/g," "),i})}function Zs(t){var r;let e="",n=null;for(let o of t){o.listType!==n&&(n&&(e+=n==="numbered"?"</ol>":"</ul>"),n=(r=o.listType)!=null?r:null,n&&(e+=n==="numbered"?"<ol>":"<ul>"));let i=ky(o);e+=n?`<li>${i}</li>`:`<p>${i}</p>`;}return n&&(e+=n==="numbered"?"</ol>":"</ul>"),e}function Js(t){return JSON.stringify({version:1,blocks:t})}function Rf(t){if(!t||t.length>2e7)return null;try{let e=JSON.parse(t);return !ro(e)||e.version!==1||!Array.isArray(e.blocks)||e.blocks.length===0||e.blocks.length>1e3?null:e.blocks.every(Af)?e.blocks:null}catch(e){return null}}function Qs(t){return t.map(Mf).join(`
|
|
16
|
+
`)}function Mf(t){return t.kind==="paragraph"?Pe(t):t.rows.map(e=>e.cells.map(n=>n.blocks.map(Mf).join(`
|
|
17
17
|
`)).join(" ")).join(`
|
|
18
|
-
`)}function Af(t){return ro(t)?t.kind==="paragraph"?typeof t.paraId=="string"&&typeof t.story=="string"&&Array.isArray(t.content)&&t.content.length<=1e5&&t.content.every(Sy):t.kind!=="table"||typeof t.tableId!="string"||!Array.isArray(t.rows)||t.rows.length>1e4?false:t.rows.every(e=>ro(e)&&Array.isArray(e.cells)&&e.cells.length<=1e3&&e.cells.every(n=>ro(n)&&Array.isArray(n.blocks)&&n.blocks.length<=1e4&&n.blocks.every(Af))):false}function Sy(t){return !ro(t)||typeof t.kind!="string"?false:t.kind==="text"?typeof t.text=="string":t.kind==="image"?typeof t.drawingId=="string"&&typeof t.src=="string":t.kind==="drawing"?typeof t.drawingId=="string":t.kind==="pageBreak"?true:t.kind==="field"?typeof t.fieldKind=="string"&&typeof t.instruction=="string":false}function ro(t){return typeof t=="object"&&t!==null}function ky(t){let e="",n=0,r=[...t.runs].map(o=>
|
|
19
|
-
`;return}let o=v(v({},e),Iy(t)),i=t.tagName==="A"?Cy(t):r;for(let s of Array.from(t.childNodes))Df(s,o,n,i);}function Cy(t){var o,i;let e=(o=t.getAttribute("href"))==null?void 0:o.trim();if(!e)return;let n=(i=t.getAttribute("title"))==null?void 0:i.trim();if(e.startsWith("#")){let a=e.slice(1);try{a=decodeURIComponent(a);}catch(s){return}return a?v({anchor:a},n?{tooltip:n}:{}):void 0}let r=Yr(e,void 0);return r==="#"?void 0:v({target:r},n?{tooltip:n}:{})}function Iy(t){let e=t.style,n={};(t.matches("b, strong")||Number.parseInt(e.fontWeight,10)>=600)&&(n.bold=true),(t.matches("i, em")||e.fontStyle==="italic")&&(n.italic=true);let r=e.textDecorationLine||e.textDecoration;(t.matches("u")||r.includes("underline"))&&(n.underline=true),(t.matches("s, strike, del")||r.includes("line-through"))&&(n.strike=true),e.fontFamily&&(n.fontFamily=e.fontFamily.replace(/["']/g,""));let o=Ny(e.fontSize);o!==null&&(n.fontSize=o);let i=Tf(e.color),a=Tf(e.backgroundColor);return i&&(n.color=i),a&&(n.highlight=a),n}function Tf(t){let e=t.trim();if(!e||e==="transparent")return null;let n=/^#([\da-f]{3}|[\da-f]{6})$/i.exec(e);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(e);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(t){var r;let e=/^([\d.]+)(pt|px)$/i.exec(t.trim());if(!e)return null;let n=Number(e[1]);return Number.isFinite(n)?((r=e[2])==null?void 0:r.toLowerCase())==="px"?n*.75:n:null}var il="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",Ri="http://schemas.openxmlformats.org/package/2006/content-types",Gf="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Wf="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",Bf="http://schemas.microsoft.com/office/2011/relationships/commentsExtended",sn="http://schemas.microsoft.com/office/word/2012/wordml",Ff=`${Vn}/hyperlink`,jf="application/vnd.openxmlformats-package.relationships+xml";function Py(t){let e=[],n=[],r=new Map;for(let o of t)o.kind==="table"&&o.revisionId&&o.revisionAction&&r.set(o.revisionId,o.revisionAction);for(let o of t){if(o.kind==="table"&&o.revisionAction||o.kind==="table"&&o.revisionId&&r.get(o.revisionId)==="reject")continue;let i=Ry(o,{allowTrackedTable:o.kind==="table"&&!!o.revisionId&&r.get(o.revisionId)==="accept"});i?e.push(i):n.push({change:o,reason:Ly(o)});}return {target:"word/document.xml",patches:e,unsupported:n}}function zI(t,e,n=buildIndices(t)){let r=Py(e),o=Ay(t,n,r.patches);return v({plan:r},o)}function Ry(t,e={}){var n;if(t.kind==="text")return v({kind:"paragraph-text",op:t.op,paraId:t.paraId,offset:t.offset,text:t.text},t.deletedText!==void 0?{deletedText:t.deletedText}:{});if(t.kind==="format"&&t.op==="run"&&t.revisionId&&t.revisionKind==="format")return v({kind:"format-revision",op:"run",paraId:t.paraId,from:t.from,to:t.to,revisionId:t.revisionId},t.beforeFormat!==void 0?{beforeFormat:t.beforeFormat}:{});if(t.kind==="format"&&t.op==="run")return {kind:"paragraph-format",paraId:t.paraId,from:t.from,to:t.to,format:t.format};if(t.kind==="format"&&(t.op==="accept"||t.op==="reject")&&t.revisionId)return {kind:"format-revision",op:t.op,paraId:t.paraId,from:t.from,to:t.to,revisionId:t.revisionId};if(t.kind==="image"&&t.op==="delete")return {kind:"drawing-delete",paraId:t.paraId,drawingId:t.drawingId,offset:t.offset};if(t.kind==="image"&&t.op==="resize"&&t.width&&t.height)return {kind:"drawing-resize",paraId:t.paraId,drawingId:t.drawingId,offset:t.offset,width:t.width,height:t.height};if(t.kind==="image"&&t.op==="insert"&&t.src&&t.width&&t.height)return {kind:"drawing-insert",paraId:t.paraId,drawingId:t.drawingId,offset:t.offset,src:t.src,width:t.width,height:t.height};if(t.kind==="image"&&(t.op==="accept"||t.op==="reject")&&t.revisionId&&(t.revisionKind==="insert"||t.revisionKind==="delete"))return {kind:"drawing-revision",op:t.op,paraId:t.paraId,drawingId:t.drawingId,offset:t.offset,revisionId:t.revisionId,revisionKind:t.revisionKind};if(t.kind==="block"&&t.op==="split"&&t.newParaId&&t.offset!==void 0)return {kind:"paragraph-split",paraId:t.paraId,newParaId:t.newParaId,offset:t.offset};if(t.kind==="block"&&t.op==="merge")return {kind:"paragraph-merge",paraId:t.paraId};if(t.kind==="hyperlink"){if(t.from>=t.to)return null;let r=t.hyperlink;return t.op==="set"&&(!(r!=null&&r.target)||!Kf(r.target)||r.anchor)?null:v({kind:"hyperlink",op:t.op,paraId:t.paraId,from:t.from,to:t.to},t.op==="set"&&r?{hyperlink:r}:{})}return t.kind==="table"&&(!t.revisionId||e.allowTrackedTable===true)&&t.op!=="insert-table"&&t.op!=="delete-table"&&t.op!=="format-cell"&&t.op!=="clear-cell"&&t.op!=="replace-cell"?v(v({kind:"table-structure",op:t.op,tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex},t.endColumnIndex!==void 0?{endColumnIndex:t.endColumnIndex}:{}),t.endRowIndex!==void 0?{endRowIndex:t.endRowIndex}:{}):t.kind==="table"&&t.op==="insert-table"&&t.tableSnapshot&&t.anchorParaId?{kind:"table-insert",anchorParaId:t.anchorParaId,anchorOffset:(n=t.anchorOffset)!=null?n:0,table:t.tableSnapshot}:t.kind==="table"&&t.op==="format-cell"&&t.format?{kind:"table-cell-format",tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex,format:t.format}:t.kind==="table"&&t.op==="clear-cell"?{kind:"table-cell-clear",tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex}:t.kind==="table"&&t.op==="replace-cell"&&t.text!==void 0?{kind:"table-cell-replace",tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex,text:t.text}:t.kind==="table"&&t.op==="replace-cell"&&t.cellSnapshot?Uf(t.cellSnapshot)?null:{kind:"table-cell-replace-rich",tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex,cell:t.cellSnapshot}:t.kind==="annotation"&&(t.op==="insert"||t.op==="delete"||t.op==="update")?v(v({kind:"comment",op:t.op,paraId:t.paraId,from:t.from,to:t.to,commentId:t.commentId},t.parentCommentId!==void 0?{parentCommentId:t.parentCommentId}:{}),t.body!==void 0?{body:t.body}:{}):t.kind==="revision"?{kind:"revision",op:t.op,paraId:t.paraId,from:t.from,to:t.to,revisionId:t.revisionId,revisionKind:t.revisionKind}:t.kind==="table"&&t.op==="delete-table"&&e.allowTrackedTable===true?{kind:"table-delete",tableId:t.tableId}:null}function My(t,e,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=e.drawingIdx.get(s.drawingId);if(!u&&s.kind==="drawing-revision"){let f=e.paraIdx.get(s.paraId.toUpperCase());u=f&&(i=ev(f,s.offset))!=null?i:void 0;}if(!u){o.push({patch:s,reason:`drawing not found: ${s.drawingId}`});continue}let p=or(t,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=e.paraIdx.get(s.paraId.toUpperCase()))!=null?a:null});continue}if(s.kind==="drawing-insert"){let u=e.paraIdx.get(s.paraId.toUpperCase());if(!u){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let p=or(t,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=e.paraIdx.get(s.paraId.toUpperCase());if(!u){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let p=or(t,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=e.paraIdx.get(s.anchorParaId.toUpperCase());if(!u){o.push({patch:s,reason:`anchor paragraph not found: ${s.anchorParaId}`});continue}let p=or(t,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=e.tblIdx.get(s.tableId);if(!u){o.push({patch:s,reason:`table not found: ${s.tableId}`});continue}let p=or(t,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=e.paraIdx.get(s.paraId.toUpperCase());if(!l){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let d=or(t,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 Ay(t,e,n){var l,d;let r=[],o=[],i=[],a=new Set,s=e;for(let u of n){let p=My(t,s,[u]);if(p.unresolved.length>0){i.push(...p.unresolved);continue}let f=p.resolved[0];if(!f)continue;let b=Yf(t,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=uv(t,f.partPath,(l=f.paragraph)!=null?l:f.drawing,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="drawing-revision"){(f.patch.revisionKind==="insert"&&f.patch.op==="reject"||f.patch.revisionKind==="delete"&&f.patch.op==="accept")&&zf(f.drawing),markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="drawing-resize"){let g=cv(f.drawing,f.patch.width,f.patch.height);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}zf(f.drawing),markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.kind==="table"){if(f.patch.kind==="table-insert"){let h=Hy(f.table.ownerDocument,f.patch.table,t,f.partPath);(d=f.table.parentNode)==null||d.insertBefore(h,f.table.nextSibling),markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="table-cell-format"){let h=Oy(f.table,f.patch);if(!h.ok){o.push({patch:f.patch,reason:h.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="table-cell-clear"){let h=$y(f.table,f.patch);if(!h.ok){o.push({patch:f.patch,reason:h.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="table-cell-replace"){let h=zy(f.table,f.patch);if(!h.ok){o.push({patch:f.patch,reason:h.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="table-cell-replace-rich"){let h=Vy(t,f.partPath,f.table,f.patch);if(!h.ok){o.push({patch:f.patch,reason:h.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="table-delete"){Ue(f.table),markDirty(b),r.push(f.patch),s=buildIndices(t);continue}let g=Gy(f.table,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.kind==="comment"){let g=yv(t,f.partPath,f.paragraph,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="revision"){let g=pv(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}markDirty(b),r.push(f.patch),(f.patch.op==="accept"||f.patch.op==="reject")&&a.add(f.patch.revisionId),s=buildIndices(t);continue}if(f.patch.kind==="paragraph-format"){let g=hv(f.paragraph,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="format-revision"){let g=mv(f.paragraph,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="paragraph-split"){let g=rv(f.paragraph,f.patch.offset,f.patch.newParaId);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="paragraph-merge"){let g=ov(f.paragraph);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}if(f.patch.kind==="hyperlink"){let g=Dy(t,f.partPath,f.paragraph,f.patch);if(!g.ok){o.push({patch:f.patch,reason:g.reason});continue}markDirty(b),r.push(f.patch),s=buildIndices(t);continue}let w=Zy(f.paragraph,f.patch);if(!w.ok){o.push({patch:f.patch,reason:w.reason});continue}markDirty(b),r.push(f.patch);}return {applied:r,skipped:o,unresolved:i}}function Ly(t){var e;return t.kind==="block"&&t.op==="split"?"paragraph split change is missing newParaId or offset":t.kind==="hyperlink"?t.op==="set"&&((e=t.hyperlink)!=null&&e.anchor)?"hyperlink anchors are not yet written back":"only external http/https hyperlinks can be written back":t.kind==="image"&&t.op==="resize"?"image resize is missing width or height":t.kind==="image"&&t.op==="insert"?"image insert requires data URL, width, and height":t.kind==="table"?t.op==="replace-cell"&&t.cellSnapshot&&Uf(t.cellSnapshot)?"table cell rich replacement does not yet write back drawings or hyperlink anchors":t.revisionId||t.revisionKind?"table revision writeback requires an original table structure snapshot":"table structure change is not supported for DOCX writeback":`unsupported native change: ${t.kind}/${"op"in t?t.op:"unknown"}`}function Uf(t){return t.blocks.some(e=>e.kind!=="paragraph"||e.content.some(n=>n.kind==="drawing"||n.kind==="text"&&n.hyperlink!==void 0&&!n.hyperlink.target))}function Kf(t){try{let e=new URL(t).protocol.toLowerCase();return e==="http:"||e==="https:"}catch(e){return false}}function Dy(t,e,n,r){var p,f,b;let o=ce(n).filter(w=>!(w.namespaceURI===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!==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=(p=r.hyperlink)==null?void 0:p.target;if(!w||!Kf(w))return {ok:false,reason:"only external http/https hyperlinks can be written back"};let g=qf(t,e,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),x=Math.min(g,r.to-d);if(!(h<x)){l.push(w),d+=g;continue}if(h>0){let I=ar(w,0,h);I&&l.push(I);}let k=ar(w,h,x);if(k&&u.push(...By(k)),x<g){let I=ar(w,x,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(W_NS,"w:hyperlink");g.setAttributeNS(Vn,"r:id",a);let h=(b=(f=r.hyperlink)==null?void 0:f.tooltip)==null?void 0:b.trim();h&&g.setAttributeNS(W_NS,"w:tooltip",h);for(let x of u)g.appendChild(x);Wy(l,g,r);}else _f(l,u,r);for(let w of o)Ue(w);for(let w of l)n.appendChild(w);return s&&markDirty(s),{ok:true}}function Wy(t,e,n){_f(t,[e],n);}function _f(t,e,n){let r=0,o=false,i=[];for(let a of t)!o&&r>=n.from&&(i.push(...e),o=true),i.push(a),r+=jt(a);o||i.push(...e),t.splice(0,t.length,...i);}function ar(t,e,n){if(n<=e)return null;let r=t.cloneNode(true);return nl(r,e,n),jt(r)>0?r:null}function By(t){return t.namespaceURI===W_NS&&t.localName==="hyperlink"?ce(t).filter(e=>e.namespaceURI===W_NS&&e.localName==="r"):[t]}function Fy(t){return t.getElementsByTagNameNS(W_NS,"drawing").length>0||t.getElementsByTagNameNS(W_NS,"pict").length>0}function qf(t,e,n){var u,p,f,b,w;let r=Ai(e),o=t.parts.get(r);if(!(o!=null&&o.xmlDom)){let g=(u=Array.from(t.parts.values()).find(x=>x.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=createXmlPart({path:r,contentType:jf,xmlDom:h}),setPart(t,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"))===Ff&&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",Ff),d.setAttribute("Target",n),d.setAttribute("TargetMode","External"),(w=i.documentElement)==null||w.appendChild(d),{id:`rId${l}`,part:o}}function Ai(t){let e=t.lastIndexOf("/"),n=e>=0?t.slice(0,e):"",r=t.slice(e+1);return n?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function Hy(t,e,n,r){var u,p,f,b,w,g,h,x,S;let o=k=>t.createElementNS(W_NS,`w:${k}`),i=o("tbl"),a=o("tblPr"),s=o("tblW");s.setAttributeNS(W_NS,"w:w",String(Math.max(0,Math.round((p=(u=e.layout)==null?void 0:u.width)!=null?p:0)))),s.setAttributeNS(W_NS,"w:type",(b=(f=e.layout)==null?void 0:f.widthType)!=null?b:"dxa"),a.appendChild(s);let l={};for(let k of ["top","left","bottom","right","insideH","insideV"]){let I=(w=e.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:(x=I==null?void 0:I.size)!=null?x:4};}if(writeWordTableBorders(a,"table",l),(S=e.layout)!=null&&S.mode){let k=o("tblLayout");k.setAttributeNS(W_NS,"w:type",e.layout.mode),a.appendChild(k);}i.appendChild(a);let d=o("tblGrid");for(let k of e.columnWidths){let I=o("gridCol");I.setAttributeNS(W_NS,"w:w",String(Math.max(1,Math.round(k)))),d.appendChild(I);}i.appendChild(d);for(let k of e.rows){let I=o("tr");for(let D of k.cells)I.appendChild(Xf(t,D,n,r));i.appendChild(I);}return i}function Xf(t,e,n,r){var u,p,f,b,w,g,h;let o=x=>t.createElementNS(W_NS,`w:${x}`),i=o("tc"),a=o("tcPr"),s=o("tcW");if(s.setAttributeNS(W_NS,"w:w",String(e.widthType==="auto"?0:Math.max(1,Math.round((u=e.width)!=null?u:0)))),s.setAttributeNS(W_NS,"w:type",(p=e.widthType)!=null?p:"dxa"),a.appendChild(s),(f=e.shading)!=null&&f.fill){let x=o("shd");x.setAttributeNS(W_NS,"w:val",(b=e.shading.val)!=null?b:"clear"),x.setAttributeNS(W_NS,"w:fill",e.shading.fill.replace(/^#/,"").toUpperCase()),a.appendChild(x);}if(e.verticalAlignment){let x=o("vAlign");x.setAttributeNS(W_NS,"w:val",e.verticalAlignment),a.appendChild(x);}i.appendChild(a);let l=e.blocks.filter(x=>x.kind==="paragraph"),d=l.length>0?l:[null];for(let x of d){let S=o("p");if(x)for(let k of x.content){if(k.kind==="image"){let H=np(k.src);if(!H)continue;let A=rp(n,r,H.bytes,H.extension,H.contentType);S.appendChild(tp(t,A.id,k.drawingId,(w=k.width)!=null?w:96,(g=k.height)!=null?g:96)),markDirty(A.part),markDirty(A.mediaPart),op(n,H.extension,H.contentType);continue}if(k.kind!=="text")continue;let I=o("r");if(k.format){let H=o("rPr");if(k.format.bold&&H.appendChild(o("b")),k.format.italic&&H.appendChild(o("i")),k.format.underline){let A=o("u");A.setAttributeNS(W_NS,"w:val","single"),H.appendChild(A);}if(k.format.strike&&H.appendChild(o("strike")),k.format.color){let A=o("color");A.setAttributeNS(W_NS,"w:val",k.format.color.replace(/^#/,"").toUpperCase()),H.appendChild(A);}if(k.format.fontSize){let A=o("sz");A.setAttributeNS(W_NS,"w:val",String(Math.round(k.format.fontSize*2))),H.appendChild(A);}if(k.format.fontFamily){let A=o("rFonts");for(let O of ["ascii","hAnsi","eastAsia"])A.setAttributeNS(W_NS,`w:${O}`,k.format.fontFamily);H.appendChild(A);}H.childNodes.length>0&&I.appendChild(H);}let D=o("t");if(D.textContent=k.text,/^\s|\s$/.test(k.text)&&D.setAttributeNS(il,"xml:space","preserve"),I.appendChild(D),(h=k.hyperlink)!=null&&h.target){let H=qf(n,r,k.hyperlink.target),A=t.createElementNS(W_NS,"w:hyperlink");A.setAttributeNS(Vn,"r:id",H.id),A.appendChild(I),S.appendChild(A),markDirty(H.part);}else S.appendChild(I);}S.firstChild||S.appendChild(o("r")),i.appendChild(S);}return i}function Oy(t,e){let r=ce(t).filter(l=>l.namespaceURI===W_NS&&l.localName==="tr")[e.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${e.rowIndex}`};let i=ce(r).filter(l=>l.namespaceURI===W_NS&&l.localName==="tc")[e.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${e.columnIndex}`};let a=t.ownerDocument,s=ce(i).find(l=>l.namespaceURI===W_NS&&l.localName==="tcPr");if(s||(s=a.createElementNS(W_NS,"w:tcPr"),i.insertBefore(s,i.firstChild)),e.format.backgroundColor!==void 0){let l=ce(s).find(d=>d.namespaceURI===W_NS&&d.localName==="shd");if(e.format.backgroundColor===null)l&&Ue(l);else {let d=l!=null?l:a.createElementNS(W_NS,"w:shd");d.setAttributeNS(W_NS,"w:val","clear"),d.setAttributeNS(W_NS,"w:fill",e.format.backgroundColor.replace(/^#/,"").toUpperCase()),l||s.appendChild(d);}}if(e.format.verticalAlignment!==void 0){let l=ce(s).find(d=>d.namespaceURI===W_NS&&d.localName==="vAlign");if(e.format.verticalAlignment===null)l&&Ue(l);else {let d=l!=null?l:a.createElementNS(W_NS,"w:vAlign");d.setAttributeNS(W_NS,"w:val",e.format.verticalAlignment),l||s.appendChild(d);}}if(e.format.borderColor!==void 0){let l=e.format.borderColor===null?{val:"nil"}:{val:"single",size:4,color:e.format.borderColor.replace(/^#/,"").toUpperCase()},d={top:v({},l),left:v({},l),bottom:v({},l),right:v({},l),insideH:v({},l),insideV:v({},l)};writeWordTableBorders(s,"cell",d);}return {ok:true}}function $y(t,e){let r=ce(t).filter(s=>s.namespaceURI===W_NS&&s.localName==="tr")[e.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${e.rowIndex}`};let i=ce(r).filter(s=>s.namespaceURI===W_NS&&s.localName==="tc")[e.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${e.columnIndex}`};let a=ce(i).find(s=>s.namespaceURI===W_NS&&s.localName==="tcPr");for(let s of ce(i))s!==a&&Ue(s);return i.appendChild(i.ownerDocument.createElementNS(W_NS,"w:p")),{ok:true}}function zy(t,e){let r=ce(t).filter(f=>f.namespaceURI===W_NS&&f.localName==="tr")[e.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${e.rowIndex}`};let i=ce(r).filter(f=>f.namespaceURI===W_NS&&f.localName==="tc")[e.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${e.columnIndex}`};let a=ce(i).find(f=>f.namespaceURI===W_NS&&f.localName==="tcPr"),s=ce(i).find(f=>f.namespaceURI===W_NS&&f.localName==="p");for(let f of ce(i))f!==a&&Ue(f);let l=i.ownerDocument.createElementNS(W_NS,"w:p"),d=s&&ce(s).find(f=>f.namespaceURI===W_NS&&f.localName==="pPr");d&&l.appendChild(d.cloneNode(true));let u=i.ownerDocument.createElementNS(W_NS,"w:r"),p=i.ownerDocument.createElementNS(W_NS,"w:t");return p.textContent=e.text,/^\s|\s$/.test(e.text)&&p.setAttributeNS(il,"xml:space","preserve"),u.appendChild(p),l.appendChild(u),i.appendChild(l),{ok:true}}function Vy(t,e,n,r){let i=ce(n).filter(d=>d.namespaceURI===W_NS&&d.localName==="tr")[r.rowIndex];if(!i)return {ok:false,reason:`table row out of range: ${r.rowIndex}`};let s=ce(i).filter(d=>d.namespaceURI===W_NS&&d.localName==="tc")[r.columnIndex];if(!s)return {ok:false,reason:`table column out of range: ${r.columnIndex}`};let l=Xf(n.ownerDocument,r.cell,t,e);for(let d of ce(s))Ue(d);for(let d of ce(l))s.appendChild(d.cloneNode(true));return {ok:true}}function Gy(t,e){var u,p,f,b;let n=ce(t).filter(w=>w.namespaceURI===W_NS&&w.localName==="tr");if(n.length===0)return {ok:false,reason:"table has no rows"};if(e.op==="insert-row"||e.op==="delete-row"){if(e.rowIndex<0||e.rowIndex>=n.length+(e.op==="insert-row"?1:0))return {ok:false,reason:`table row out of range: ${e.rowIndex}`};if(e.op==="delete-row")return n.length<=1?{ok:false,reason:"cannot delete the only table row"}:(Ue(n[e.rowIndex]),{ok:true});let w=n[Math.min(e.rowIndex,n.length-1)],g=Uy(w);return t.insertBefore(g,(u=n[e.rowIndex])!=null?u:null),{ok:true}}let r=n[e.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${e.rowIndex}`};let o=ce(r).filter(w=>w.namespaceURI===W_NS&&w.localName==="tc");if(e.op==="insert-column"||e.op==="delete-column"){if(o.length===0)return {ok:false,reason:"table row has no cells"};if(e.columnIndex<0||e.columnIndex>=o.length+(e.op==="insert-column"?1:0))return {ok:false,reason:`table column out of range: ${e.columnIndex}`};let w=n.map(g=>ce(g).filter(h=>h.namespaceURI===W_NS&&h.localName==="tc"));if(w.some(g=>g.length!==o.length||g.some(h=>$n(h)!==1||Pi(h))))return {ok:false,reason:"table column structure is not a regular non-merged grid"};for(let g of w)if(e.op==="delete-column"){if(g.length<=1)return {ok:false,reason:"cannot delete the only table column"};Ue(g[e.columnIndex]);}else {let h=g[Math.min(e.columnIndex,g.length-1)],x=el(h);(f=g[0].parentNode)==null||f.insertBefore(x,(p=g[e.columnIndex])!=null?p:null);}return Yy(t,e.op==="insert-column"?"insert":"delete",e.columnIndex),{ok:true}}if(e.op==="merge-cells"){if(e.endRowIndex!==void 0&&e.endRowIndex>e.rowIndex){if(e.columnIndex<0||e.endRowIndex>=n.length)return {ok:false,reason:`vertical merge row out of range: ${e.rowIndex}:${e.endRowIndex}`};let h=n.slice(e.rowIndex,e.endRowIndex+1).map(x=>ce(x).filter(S=>S.namespaceURI===W_NS&&S.localName==="tc")[e.columnIndex]);if(h.some(x=>!x||$n(x)!==1||Pi(x)))return {ok:false,reason:"vertical merge requires a regular non-merged column"};Hf(h[0],"restart");for(let x of h.slice(1)){Hf(x,"continue");let S=ce(x).find(k=>k.namespaceURI===W_NS&&k.localName==="tcPr");for(let k of ce(x))k!==S&&Ue(k);x.appendChild(x.ownerDocument.createElementNS(W_NS,"w:p"));}return {ok:true}}let w=(b=e.endColumnIndex)!=null?b:e.columnIndex+1;if(e.columnIndex<0||w>=o.length||w<=e.columnIndex)return {ok:false,reason:`merge start column out of range: ${e.columnIndex}`};if(o.some(h=>$n(h)!==1||Pi(h)))return {ok:false,reason:"cell merge requires a regular non-merged row"};let g=o[e.columnIndex];for(let h=e.columnIndex+1;h<=w;h+=1){let x=o[h];Ky(g,x),Ue(x);}return _y(g,w-e.columnIndex+1),{ok:true}}if(e.endRowIndex!==void 0&&e.endRowIndex>e.rowIndex){if(e.columnIndex<0||e.endRowIndex>=n.length)return {ok:false,reason:`vertical split row out of range: ${e.rowIndex}:${e.endRowIndex}`};let w=n.slice(e.rowIndex,e.endRowIndex+1).map(g=>ce(g).filter(h=>h.namespaceURI===W_NS&&h.localName==="tc")[e.columnIndex]);if(w.some((g,h)=>{var k;if(!g||$n(g)!==1)return true;let x=(k=ce(g).find(I=>I.namespaceURI===W_NS&&I.localName==="tcPr"))==null?void 0:k.getElementsByTagNameNS(W_NS,"vMerge")[0],S=x==null?void 0:x.getAttributeNS(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)jy(g);return {ok:true}}let i=n[e.rowIndex],a=ce(i).filter(w=>w.namespaceURI===W_NS&&w.localName==="tc"),s=0,l=a.find(w=>{let g=s===e.columnIndex;return s+=$n(w),g});if(!l)return {ok:false,reason:`split column out of range: ${e.columnIndex}`};if(Pi(l)||$n(l)<=1)return {ok:false,reason:"cell is not a horizontally merged cell"};let d=$n(l);qy(l);for(let w=1;w<d;w+=1){let g=el(l);i.insertBefore(g,l.nextSibling);}return {ok:true}}function Hf(t,e){var i;let n=t.ownerDocument,r=ce(t).find(a=>a.namespaceURI===W_NS&&a.localName==="tcPr");r||(r=n.createElementNS(W_NS,"w:tcPr"),t.insertBefore(r,t.firstChild));let o=(i=ce(r).find(a=>a.namespaceURI===W_NS&&a.localName==="vMerge"))!=null?i:n.createElementNS(W_NS,"w:vMerge");o.setAttributeNS(W_NS,"w:val",e),o.parentNode||r.appendChild(o);}function jy(t){let e=ce(t).find(r=>r.namespaceURI===W_NS&&r.localName==="tcPr"),n=e&&ce(e).find(r=>r.namespaceURI===W_NS&&r.localName==="vMerge");n&&Ue(n);}function Uy(t){let e=t.cloneNode(true),n=ce(e).filter(r=>r.namespaceURI===W_NS&&r.localName==="tc");for(let r of n){let o=el(r);ep(r,o);}return e}function el(t){let e=t.ownerDocument,n=e.createElementNS(W_NS,"w:tc"),r=ce(t).find(s=>s.namespaceURI===W_NS&&s.localName==="tcPr");r&&n.appendChild(r.cloneNode(true));let o=e.createElementNS(W_NS,"w:p"),i=ce(t).find(s=>s.namespaceURI===W_NS&&s.localName==="p"),a=i&&ce(i).find(s=>s.namespaceURI===W_NS&&s.localName==="pPr");return a&&o.appendChild(a.cloneNode(true)),o.appendChild(e.createElementNS(W_NS,"w:r")),n.appendChild(o),n}function Ky(t,e){for(let n of ce(e))n.namespaceURI===W_NS&&n.localName==="tcPr"||t.appendChild(n.cloneNode(true));}function $n(t){var r,o;let e=(o=(r=ce(t).find(i=>i.namespaceURI===W_NS&&i.localName==="tcPr"))==null?void 0:r.getElementsByTagNameNS(W_NS,"gridSpan")[0])==null?void 0:o.getAttributeNS(W_NS,"val"),n=Number(e);return Number.isFinite(n)&&n>0?n:1}function Pi(t){var e;return !!((e=ce(t).find(n=>n.namespaceURI===W_NS&&n.localName==="tcPr"))!=null&&e.getElementsByTagNameNS(W_NS,"vMerge").length)}function _y(t,e){let n=Xy(t,"tcPr"),r=ce(n).find(o=>o.namespaceURI===W_NS&&o.localName==="gridSpan");r||(r=t.ownerDocument.createElementNS(W_NS,"w:gridSpan"),n.appendChild(r)),r.setAttributeNS(W_NS,"w:val",String(e));}function qy(t){let e=ce(t).find(r=>r.namespaceURI===W_NS&&r.localName==="tcPr"),n=e&&ce(e).find(r=>r.namespaceURI===W_NS&&r.localName==="gridSpan");n&&Ue(n);}function Xy(t,e){let n=ce(t).find(o=>o.namespaceURI===W_NS&&o.localName===e);if(n)return n;let r=t.ownerDocument.createElementNS(W_NS,`w:${e}`);return t.insertBefore(r,t.firstChild),r}function Yy(t,e,n){var s;let r=ce(t).find(l=>l.namespaceURI===W_NS&&l.localName==="tblGrid");if(!r)return;let o=ce(r).filter(l=>l.namespaceURI===W_NS&&l.localName==="gridCol");if(e==="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(t,e){var n,r;return (r=(n=Yf(t,e))==null?void 0:n.path)!=null?r:null}function Yf(t,e){let n=e.nodeType===9?e:e.ownerDocument;if(!n)return null;for(let r of t.parts.values())if(r.xmlDom===n)return r;return null}function Zy(t,e){var n,r;return e.op==="insert"?Zf(t,e.offset,e.text):e.op==="delete"?Of(t,e.offset,e.text.length,""):Of(t,e.offset,(r=(n=e.deletedText)==null?void 0:n.length)!=null?r:0,e.text)}function Zf(t,e,n){var s,l,d;if(n.length===0)return {ok:true};let r=ao(t),o=r.reduce((u,p)=>u+p.length,0);if(Jy(t)&&e===o)return $f(t,n),{ok:true};if(r.every(u=>u.kind!=="text"))return e!==0?{ok:false,reason:`insert offset out of range: ${e}`}:($f(t,n),{ok:true});let i=tl(r,e,true);if(!i)return {ok:false,reason:`insert offset out of range: ${e}`};if(i.node.localName==="delText"&&i.localOffset===((l=(s=i.node.textContent)==null?void 0:s.length)!=null?l:0)){let u=Qy(i.node,"del"),p=u==null?void 0:u.parentNode;if(u&&p===t){let f=t.ownerDocument;if(!f)return {ok:false,reason:"paragraph has no owner document"};let b=f.createElementNS(W_NS,"w:r"),w=f.createElementNS(W_NS,"w:t");return w.textContent=n,Sn(w),b.appendChild(w),t.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 Of(t,e,n,r){var f,b;if(n===0)return Zf(t,e,r);let o=ao(t),i=o.filter(w=>w.kind==="text").map(w=>w.node),a=tl(o,e,false),s=tl(o,e+n,true);if(!a||!s)return {ok:false,reason:`text range out of range: ${e}:${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: ${e}:${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 ao(t){let e=[];return Qf(t,e),e}function Jy(t){return t.getElementsByTagNameNS(W_NS,"fldChar").length>0||t.getElementsByTagNameNS(W_NS,"instrText").length>0}function Jf(t){return ao(t).filter(e=>e.kind==="text").map(e=>e.node)}function Qf(t,e){var r,o,i,a;if(t.nodeType!==1)return;let n=t;if(n.namespaceURI===W_NS&&n.localName==="t"){e.push({kind:"text",node:n,length:(o=(r=n.textContent)==null?void 0:r.length)!=null?o:0});return}if(n.namespaceURI===W_NS&&n.localName==="delText"){e.push({kind:"text",node:n,length:(a=(i=n.textContent)==null?void 0:i.length)!=null?a:0});return}if(n.namespaceURI===W_NS&&n.localName==="drawing"||n.namespaceURI===W_NS&&n.localName==="pict"){e.push({kind:"object",node:n,length:1});return}for(let s=0;s<n.childNodes.length;s+=1){let l=n.childNodes[s];l&&Qf(l,e);}}function Qy(t,e){let n=t.parentNode;for(;n&&n.nodeType===1;){let r=n;if(r.namespaceURI===W_NS&&r.localName===e)return r;if(r.namespaceURI===W_NS&&r.localName==="p")return null;n=n.parentNode;}return null}function ev(t,e){let n=0,r=ao(t);for(let o of r){if(o.kind==="object"&&e>=n&&e<=n+o.length)return o.node;n+=o.length;}return null}function tl(t,e,n){var o;let r=0;for(let i=0;i<t.length;i+=1){let a=t[i],s=r+a.length;if(a.kind==="text"){if(e>=r&&(e<s||n&&e===s))return {node:a.node,localOffset:e-r}}else if(e>=r&&e<=s)return (o=tv(t,i))!=null?o:nv(t,i);r=s;}return null}function tv(t,e){for(let n=e+1;n<t.length;n+=1){let r=t[n];if(r.kind==="text")return {node:r.node,localOffset:0}}return null}function nv(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r.kind==="text")return {node:r.node,localOffset:r.length}}return null}function $f(t,e){let n=t.ownerDocument;if(!n)return;let r=n.createElementNS(W_NS,"w:r"),o=n.createElementNS(W_NS,"w:t");o.textContent=e,Sn(o),r.appendChild(o),t.appendChild(r);}function Sn(t){var n;let e=(n=t.textContent)!=null?n:"";/^\s|\s$|\s{2,}/.test(e)&&t.setAttributeNS(il,"xml:space","preserve");}function rv(t,e,n){let r=t.parentNode,o=t.ownerDocument;if(!r||!o)return {ok:false,reason:"paragraph has no parent document"};let i=ce(t).filter(u=>!(u.namespaceURI===W_NS&&u.localName==="pPr")),a=i.reduce((u,p)=>u+jt(p),0);if(e<0||e>a)return {ok:false,reason:`split offset out of range: ${e}`};let s=iv(o,i,e),l=o.createElementNS(W_NS,"w:p");sv(t,l,n);let d=ce(t).find(u=>u.namespaceURI===W_NS&&u.localName==="pPr");d&&l.appendChild(d.cloneNode(true));for(let u of s)l.appendChild(u);return r.insertBefore(l,t.nextSibling),{ok:true}}function ov(t){let e=lv(t);if(!e)return {ok:false,reason:"next paragraph not found for merge"};for(let n of ce(e))n.namespaceURI===W_NS&&n.localName==="pPr"||t.appendChild(n.cloneNode(true));return Ue(e),{ok:true}}function iv(t,e,n){let r=[],o=0,i=false;for(let a of e){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=av(t,a,n-o);d.after&&r.push(d.after),i=true;}!i&&n===l&&(i=true),o=l;}return r}function av(t,e,n){let r=e.cloneNode(true),o=e.cloneNode(true);return nl(r,0,n),nl(o,n,jt(e)),ep(e,r),dv(o)||jt(o)>0?{after:o}:{after:null}}function nl(t,e,n){var i;let r=Jf(t),o=0;for(let a of r){let s=(i=a.textContent)!=null?i:"",l=o+s.length,d=Math.max(0,e-o),u=Math.min(s.length,n-o);a.textContent=d<u?s.slice(d,u):"",Sn(a),o=l;}}function jt(t){var o,i,a;if(t.namespaceURI===W_NS&&t.localName==="drawing")return 1;let e=0,n=t.getElementsByTagNameNS(W_NS,"t");for(let s=0;s<n.length;s++)e+=(a=(i=(o=n[s])==null?void 0:o.textContent)==null?void 0:i.length)!=null?a:0;let r=t.getElementsByTagNameNS(W_NS,"drawing");return e+=r.length,e}function sv(t,e,n){for(let r=0;r<t.attributes.length;r++){let o=t.attributes[r];o&&(o.namespaceURI===W14_NS&&o.localName==="paraId"||e.setAttributeNS(o.namespaceURI,o.name,o.value));}e.setAttributeNS(W14_NS,"w14:paraId",n);}function ce(t){let e=[];for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];(r==null?void 0:r.nodeType)===1&&e.push(r);}return e}function lv(t){let e=t.nextSibling;for(;e;){if(e.nodeType===1){let n=e;return n.namespaceURI===W_NS&&n.localName==="p"?n:null}e=e.nextSibling;}return null}function dv(t){return Jf(t).some(e=>{var n;return ((n=e.textContent)!=null?n:"").length>0})}function Ue(t){var e;(e=t.parentNode)==null||e.removeChild(t);}function ep(t,e){var n;(n=t.parentNode)==null||n.replaceChild(e,t);}function zf(t){var n;let e=t.parentNode;if(e){if(Av(e)&&e.namespaceURI===W_NS&&e.localName==="r"&&Mv(e)){(n=e.parentNode)==null||n.removeChild(e);return}e.removeChild(t);}}function cv(t,e,n){if(!Number.isFinite(e)||!Number.isFinite(n)||e<=0||n<=0)return {ok:false,reason:"image size must be positive finite pixels"};let r=Math.round(e/96*914400),o=Math.round(n/96*914400),i=ce(t).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=ce(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&&ce(d).find(p=>p.namespaceURI===Lt&&p.localName==="ext");u&&(u.setAttribute("cx",String(r)),u.setAttribute("cy",String(o)));}return {ok:true}}function uv(t,e,n,r){let o=np(r.src);if(!o)return {ok:false,reason:"image insert requires a base64 data:image URL"};let i=rp(t,e,o.bytes,o.extension,o.contentType),a=tp(n.ownerDocument,i.id,r.drawingId,r.width,r.height),s=ce(n).filter(f=>!(f.namespaceURI===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===W_NS&&f.localName==="r"){let w=ar(f,0,r.offset-u),g=ar(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 markDirty(i.part),markDirty(i.mediaPart),op(t,o.extension,o.contentType),{ok:true}}function tp(t,e,n,r,o){let i=Math.round(r/96*914400),a=Math.round(o/96*914400),s=t.createElementNS(W_NS,"w:r"),l=t.createElementNS(W_NS,"w:drawing"),d=t.createElementNS(ir,"wp:inline"),u=t.createElementNS(ir,"wp:extent");u.setAttribute("cx",String(i)),u.setAttribute("cy",String(a)),d.appendChild(u);let p=t.createElementNS(ir,"wp:docPr");p.setAttribute("id",String(Math.abs(fv(n))+1)),p.setAttribute("name",`Picture ${n}`),d.appendChild(p),d.appendChild(t.createElementNS(ir,"wp:cNvGraphicFramePr"));let f=t.createElementNS(Lt,"a:graphic"),b=t.createElementNS(Lt,"a:graphicData");b.setAttribute("uri","http://schemas.openxmlformats.org/drawingml/2006/picture");let w=t.createElementNS(rr,"pic:pic"),g=t.createElementNS(rr,"pic:nvPicPr"),h=t.createElementNS(rr,"pic:cNvPr");h.setAttribute("id","0"),h.setAttribute("name",`image-${n}`),g.appendChild(h),g.appendChild(t.createElementNS(rr,"pic:cNvPicPr")),w.appendChild(g);let x=t.createElementNS(rr,"pic:blipFill"),S=t.createElementNS(Lt,"a:blip");S.setAttributeNS(Vn,"r:embed",e),x.appendChild(S);let k=t.createElementNS(Lt,"a:stretch");k.appendChild(t.createElementNS(Lt,"a:fillRect")),x.appendChild(k),w.appendChild(x);let I=t.createElementNS(rr,"pic:spPr"),D=t.createElementNS(Lt,"a:xfrm"),H=t.createElementNS(Lt,"a:ext");H.setAttribute("cx",String(i)),H.setAttribute("cy",String(a)),D.appendChild(t.createElementNS(Lt,"a:off")),D.appendChild(H),I.appendChild(D);let A=t.createElementNS(Lt,"a:prstGeom");return A.setAttribute("prst","rect"),A.appendChild(t.createElementNS(Lt,"a:avLst")),I.appendChild(A),w.appendChild(I),b.appendChild(w),f.appendChild(b),d.appendChild(f),l.appendChild(d),s.appendChild(l),s}function np(t){let e=/^data:(image\/(png|jpeg|jpg|gif|bmp|webp));base64,([a-z0-9+/=\s]+)$/i.exec(t.trim());if(!e)return null;let n=e[1].toLowerCase()==="image/jpg"?"image/jpeg":e[1].toLowerCase(),r=n==="image/jpeg"?"jpeg":n.slice(6),o=atob(e[3].replace(/\s/g,""));return {bytes:Uint8Array.from(o,i=>i.charCodeAt(0)),extension:r,contentType:n}}function rp(t,e,n,r,o){var g,h,x,S;let i=Ai(e),a=t.parts.get(i);if(!(a!=null&&a.xmlDom)){let k=(g=Array.from(t.parts.values()).find(D=>D.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=createXmlPart({path:i,contentType:jf,xmlDom:I}),setPart(t,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=(x=l[k])==null?void 0:x.getAttribute("Id");I&&u.add(I);}for(;u.has(`rId${d}`);)d+=1;let p=1;for(;t.parts.has(`word/media/image${p}.${r}`);)p+=1;let f=`word/media/image${p}.${r}`,b=createBinaryPart({path:f,contentType:o,bytes:n});setPart(t,b);let w=s.createElementNS(Gt,"Relationship");return w.setAttribute("Id",`rId${d}`),w.setAttribute("Type",`${Vn}/image`),w.setAttribute("Target",`media/image${p}.${r}`),(S=s.documentElement)==null||S.appendChild(w),{id:`rId${d}`,part:a,mediaPart:b}}function op(t,e,n){var s,l,d;let r=getPart(t,"[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())===e.toLowerCase())return;let a=o.createElementNS("http://schemas.openxmlformats.org/package/2006/content-types","Default");a.setAttribute("Extension",e),a.setAttribute("ContentType",n),(d=o.documentElement)==null||d.appendChild(a),markDirty(r);}function fv(t){let e=0;for(let n=0;n<t.length;n+=1)e=e*31+t.charCodeAt(n)|0;return e}function pv(t,e){var l,d,u;if(e.op==="accept"||e.op==="reject"){let p=e.revisionKind==="insert"?"ins":"del",b=Array.from(t.getElementsByTagNameNS(W_NS,p)).filter(w=>w.getAttributeNS(W_NS,"id")===e.revisionId);if(b.length===0)return {ok:false,reason:`revision not found: ${e.revisionId}`};for(let w of b){let g=w.parentNode;if(!g)continue;if(!(p==="ins"&&e.op==="accept"||p==="del"&&e.op==="reject")){g.removeChild(w);continue}let x=Array.from(w.childNodes);if(p==="del")for(let S of x)S.nodeType===1&&xv(S);for(let S of x)g.insertBefore(S,w);g.removeChild(w);}return {ok:true}}if(e.from<0||e.to<=e.from)return {ok:false,reason:"revision range is empty or invalid"};let n=0,r=[],o=-1,i=[];for(let p of Array.from(t.childNodes)){if(p.nodeType!==1||p.namespaceURI!==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(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<=e.from||g>=e.to){i.push(f);continue}let x=Math.max(0,e.from-g),S=Math.min(w.length,e.to-g);x>0&&i.push(sr(f,w.slice(0,x))),S>x&&(o<0&&(o=i.length),r.push(sr(f,w.slice(x,S)))),S<w.length&&i.push(sr(f,w.slice(S)));}if(r.length===0||e.to>n)return {ok:false,reason:`revision range out of range: ${e.from}:${e.to}`};let a=t.ownerDocument;if(!a)return {ok:false,reason:"revision paragraph has no owner document"};let s=a.createElementNS(W_NS,e.revisionKind==="insert"?"w:ins":"w:del");s.setAttributeNS(W_NS,"w:id",e.revisionId),s.setAttributeNS(W_NS,"w:author","User"),s.setAttributeNS(W_NS,"w:date",new Date().toISOString());for(let p of r)e.revisionKind==="delete"&&wv(p),s.appendChild(p);for(i.splice(o<0?i.length:o,0,s),bv(i);t.firstChild;)t.removeChild(t.firstChild);for(let p of i)t.appendChild(p);return {ok:true}}function hv(t,e){var a;if(e.from<0||e.to<=e.from)return {ok:false,reason:"format range is empty or invalid"};if(t.getElementsByTagNameNS(W_NS,"ins").length>0||t.getElementsByTagNameNS(W_NS,"del").length>0){let s=Array.from(t.getElementsByTagNameNS(W_NS,"r")),l=0,d=0;for(let u of s){let p=ip(u);if(p.length===0)continue;let f=l,b=l+p.length;if(l=b,!(b<=e.from||f>=e.to)){if(e.from>f||e.to<b)return {ok:false,reason:"format writeback requires whole runs inside tracked content"};rl(u,e.format),d+=p.length;}}return d===0||e.to>l?{ok:false,reason:`format range out of range: ${e.from}:${e.to}`}:{ok:true}}let r=[],o=0,i=0;for(let s of Array.from(t.childNodes)){if(s.nodeType!==1||s.namespaceURI!==W_NS||s.localName!=="r"){r.push(s);continue}let l=s,d=Array.from(l.getElementsByTagNameNS(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<=e.from||p>=e.to){r.push(l);continue}let b=Math.max(0,e.from-p),w=Math.min(u.length,e.to-p);if(b>0&&r.push(sr(l,u.slice(0,b))),w>b){let g=sr(l,u.slice(b,w));rl(g,e.format),r.push(g),i+=w-b;}w<u.length&&r.push(sr(l,u.slice(w)));}if(i===0||e.to>o)return {ok:false,reason:`format range out of range: ${e.from}:${e.to}`};for(;t.firstChild;)t.removeChild(t.firstChild);for(let s of r)t.appendChild(s);return {ok:true}}function mv(t,e){var o;let n=Array.from(t.getElementsByTagNameNS(W_NS,"r"));if(e.op==="run"){if(e.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=ip(s),d=i,u=i+l.length;if(i=u,u<=e.from||d>=e.to)continue;if(e.from>d||e.to<u)return {ok:false,reason:"format revision currently requires whole runs"};let p=gv(s);zn(p,"rPrChange");let f=p.ownerDocument.createElementNS(W_NS,"w:rPrChange");f.setAttributeNS(W_NS,"w:id",e.revisionId),f.setAttributeNS(W_NS,"w:author","User"),f.setAttributeNS(W_NS,"w:date",new Date().toISOString());let b=p.ownerDocument.createElementNS(W_NS,"w:r");rl(b,(o=e.beforeFormat)!=null?o:{});let w=ce(b).find(g=>g.namespaceURI===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||e.to>i?{ok:false,reason:`format revision range not found: ${e.from}:${e.to}`}:{ok:true}}let r=0;for(let i of n){let a=ce(i).find(l=>l.namespaceURI===W_NS&&l.localName==="rPr"),s=a&&ce(a).find(l=>l.namespaceURI===W_NS&&l.localName==="rPrChange"&&l.getAttributeNS(W_NS,"id")===e.revisionId);if(!(!s||!a)){if(e.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: ${e.revisionId}`}}function ip(t){return Array.from(t.getElementsByTagNameNS(W_NS,"t")).concat(Array.from(t.getElementsByTagNameNS(W_NS,"delText"))).map(e=>{var n;return (n=e.textContent)!=null?n:""}).join("")}function gv(t){let e=ce(t).find(r=>r.namespaceURI===W_NS&&r.localName==="rPr");if(e)return e;let n=t.ownerDocument.createElementNS(W_NS,"w:rPr");return t.insertBefore(n,t.firstChild),n}function rl(t,e){var i,a,s;let n=t.ownerDocument,r=(i=ce(t).find(l=>l.namespaceURI===W_NS&&l.localName==="rPr"))!=null?i:null;r||(r=n.createElementNS(W_NS,"w:rPr"),t.insertBefore(r,t.firstChild));let o=[["bold","b"],["italic","i"],["strike","strike"],["doubleStrike","dstrike"],["caps","caps"],["smallCaps","smallCaps"]];for(let[l,d]of o)e[l]!==void 0&&(zn(r,d),e[l]&&r.appendChild(n.createElementNS(W_NS,`w:${d}`)));if(e.underline!==void 0&&(zn(r,"u"),e.underline)){let l=n.createElementNS(W_NS,"w:u");l.setAttribute("val","single"),r.appendChild(l);}if(e.color!==void 0&&(zn(r,"color"),e.color)){let l=n.createElementNS(W_NS,"w:color");l.setAttribute("val",e.color.replace(/^#/,"").toUpperCase()),r.appendChild(l);}if(e.highlight!==void 0||e.shading!==void 0){zn(r,"shd");let l=(s=(a=e.shading)==null?void 0:a.fill)!=null?s:e.highlight;if(l){let d=n.createElementNS(W_NS,"w:shd");d.setAttribute("val","clear"),d.setAttribute("fill",l.replace(/^#/,"").toUpperCase()),r.appendChild(d);}}if(e.fontSize!==void 0){zn(r,"sz");let l=n.createElementNS(W_NS,"w:sz");l.setAttribute("val",String(Math.round(e.fontSize*2))),r.appendChild(l);}if(e.fontFamily!==void 0){zn(r,"rFonts");let l=n.createElementNS(W_NS,"w:rFonts");l.setAttribute("ascii",e.fontFamily),l.setAttribute("hAnsi",e.fontFamily),l.setAttribute("eastAsia",e.fontFamily),l.setAttribute("cs",e.fontFamily),r.appendChild(l);}}function zn(t,e){for(let n of ce(t))n.namespaceURI===W_NS&&n.localName===e&&t.removeChild(n);}function bv(t){for(let e=1;e<t.length;e+=1){let n=t[e-1],r=t[e];if((n==null?void 0:n.nodeType)!==1||(r==null?void 0:r.nodeType)!==1)continue;let o=n,i=r;if(!(o.namespaceURI!==W_NS||i.namespaceURI!==W_NS||o.localName!==i.localName||o.localName!=="ins"&&o.localName!=="del"||o.getAttributeNS(W_NS,"id")!==i.getAttributeNS(W_NS,"id"))){for(let a of Array.from(i.childNodes))o.appendChild(a);t.splice(e,1),e-=1;}}}function sr(t,e){let n=t.cloneNode(true),r=n.getElementsByTagNameNS(W_NS,"t")[0];return r&&(r.textContent=e),n}function wv(t){var r;let e=t.ownerDocument,n=Array.from(t.getElementsByTagNameNS(W_NS,"t"));for(let o of n){let i=e.createElementNS(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 xv(t){var r;let e=t.ownerDocument,n=Array.from(t.getElementsByTagNameNS(W_NS,"delText"));for(let o of n){let i=e.createElementNS(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 yv(t,e,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=ao(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}`};vv(t,e),Pv(n,r.from,r.to,r.commentId);let l=new Date().toISOString();return Ev(t,r.commentId,(a=r.body)!=null?a:"","User",l),r.parentCommentId!==void 0&&Cv(t,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=t.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(W_NS,"comment");for(let u=0;u<d.length;u+=1){let p=d[u];if((p==null?void 0:p.getAttributeNS(W_NS,"id"))!==String(r.commentId))continue;let f=p.getElementsByTagNameNS(W_NS,"t");if(f.length===0){let b=l.createElementNS(W_NS,"w:p"),w=l.createElementNS(W_NS,"w:r"),g=l.createElementNS(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 markDirty(s),{ok:true}}return {ok:false,reason:`comment not found: ${r.commentId}`}}Rv(t,r.commentId),Nv(t,r.commentId);let o=t.parts.get("word/comments.xml"),i=o==null?void 0:o.xmlDom;if(i){let s=i.getElementsByTagNameNS(W_NS,"comment");for(let l=0;l<s.length;l+=1){let d=s[l];(d==null?void 0:d.getAttributeNS(W_NS,"id"))===String(r.commentId)&&Ue(d);}markDirty(o);}return {ok:true}}function vv(t,e){var r,o;let n=t.parts.get("word/comments.xml");if(!(n!=null&&n.xmlDom)){let i=(r=Array.from(t.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(W_NS,"w:comments",null);if(!a)throw new Error("XML implementation cannot create comments.xml");n=createXmlPart({path:"word/comments.xml",contentType:Gf,xmlDom:a}),setPart(t,n),Sv(t);}return kv(t,e),n}function Sv(t){var i,a;let e=getPart(t,"[Content_Types].xml"),n=e==null?void 0:e.xmlDom;if(!e||!n)return;let r=n.getElementsByTagNameNS(Ri,"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(Ri,"Override");o.setAttribute("PartName","/word/comments.xml"),o.setAttribute("ContentType",Gf),(a=n.documentElement)==null||a.appendChild(o),markDirty(e);}function kv(t,e){var d,u,p;let n=Ai(e),r=t.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"))===`${Vn}/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",`${Vn}/comments`),l.setAttribute("Target","comments.xml"),(p=o.documentElement)==null||p.appendChild(l),markDirty(r);}function Ev(t,e,n,r,o){let i=t.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(W_NS,"comment")).some(f=>f.getAttributeNS(W_NS,"id")===String(e)))return;let l=a.createElementNS(W_NS,"w:comment");l.setAttributeNS(W_NS,"w:id",String(e)),l.setAttributeNS(W_NS,"w:author",r),l.setAttributeNS(W_NS,"w:date",o),l.setAttributeNS(W_NS,"w:initials",r.slice(0,1));let d=a.createElementNS(W_NS,"w:p");d.setAttributeNS(W14_NS,"w14:paraId",Iv(e));let u=a.createElementNS(W_NS,"w:r"),p=a.createElementNS(W_NS,"w:t");p.textContent=n,Sn(p),u.appendChild(p),d.appendChild(u),l.appendChild(d),s.appendChild(l),markDirty(i);}function Cv(t,e,n){let r=t.parts.get("word/comments.xml"),o=r==null?void 0:r.xmlDom;if(!o)return;let i=b=>{var g,h,x;let w=o.getElementsByTagNameNS(W_NS,"comment");for(let S=0;S<w.length;S+=1){if(((g=w[S])==null?void 0:g.getAttributeNS(W_NS,"id"))!==String(b))continue;let k=(h=w[S])==null?void 0:h.getElementsByTagNameNS(W_NS,"p")[0];return (x=k==null?void 0:k.getAttributeNS(W14_NS,"paraId"))!=null?x:null}return null},a=i(e),s=i(n);if(!a||!s)return;let l=Tv(t,"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),markDirty(l);}function Iv(t){return t.toString(16).padStart(8,"0").slice(-8)}function Nv(t,e){var d,u,p,f;let n=t.parts.get("word/comments.xml"),r=n==null?void 0:n.xmlDom,o=t.parts.get("word/commentsExtended.xml"),i=o==null?void 0:o.xmlDom;if(!r||!i)return;let a=r.getElementsByTagNameNS(W_NS,"comment"),s=null;for(let b=0;b<a.length;b+=1)if(((d=a[b])==null?void 0:d.getAttributeNS(W_NS,"id"))===String(e)){s=(f=(p=(u=a[b])==null?void 0:u.getElementsByTagNameNS(W_NS,"p")[0])==null?void 0:p.getAttributeNS(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),markDirty(o));}function Tv(t,e){var a,s,l,d,u,p;let n=t.parts.get("word/commentsExtended.xml");if(!(n!=null&&n.xmlDom)){let f=(l=(a=t.parts.get(e))==null?void 0:a.xmlDom)!=null?l:(s=Array.from(t.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=createXmlPart({path:"word/commentsExtended.xml",contentType:Wf,xmlDom:b}),setPart(t,n);}let r=getPart(t,"[Content_Types].xml");if(r!=null&&r.xmlDom){let f=r.xmlDom.getElementsByTagNameNS(Ri,"Override");if(!Array.from(f).some(b=>b.getAttribute("PartName")==="/word/commentsExtended.xml")){let b=r.xmlDom.createElementNS(Ri,"Override");b.setAttribute("PartName","/word/commentsExtended.xml"),b.setAttribute("ContentType",Wf),(u=r.xmlDom.documentElement)==null||u.appendChild(b),markDirty(r);}}let o=t.parts.get(Ai(e)),i=o==null?void 0:o.xmlDom;if(i&&!Array.from(i.getElementsByTagNameNS(Gt,"Relationship")).some(f=>f.getAttribute("Type")===Bf)){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",Bf),g.setAttribute("Target","commentsExtended.xml"),(p=i.documentElement)==null||p.appendChild(g),markDirty(o);}return n}function Pv(t,e,n,r){let o=t.ownerDocument,i=o.createElementNS(W_NS,"w:commentRangeStart");i.setAttributeNS(W_NS,"w:id",String(r));let a=o.createElementNS(W_NS,"w:commentRangeEnd");a.setAttributeNS(W_NS,"w:id",String(r));let s=o.createElementNS(W_NS,"w:r"),l=o.createElementNS(W_NS,"w:commentReference");l.setAttributeNS(W_NS,"w:id",String(r)),s.appendChild(l);let d=new Map;d.set(e,[i]),d.set(n,[a,s]);let u=ce(t).filter(b=>!(b.namespaceURI===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=[e,n].filter(S=>S>f&&S<f+g).sort((S,k)=>S-k),x=0;for(let S of [...h,f+g]){let k=ar(b,x,S-f);k&&p.push(k);let I=S,D=d.get(I);D&&p.push(...D),x=S-f;}g===0&&p.push(b),f+=g;}for(let b of [e,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)t.appendChild(b);}function Rv(t,e){for(let n of t.parts.values()){let r=n.xmlDom;if(r)for(let o of ["commentRangeStart","commentRangeEnd","commentReference"]){let i=r.getElementsByTagNameNS(W_NS,o),a=[];for(let s=0;s<i.length;s+=1){let l=i[s];(l==null?void 0:l.getAttributeNS(W_NS,"id"))===String(e)&&a.push(l);}for(let s of a){let l=s.parentNode;o==="commentReference"&&(l==null?void 0:l.nodeType)===1&&l.namespaceURI===W_NS&&l.localName==="r"?Ue(l):Ue(s);}a.length>0&&markDirty(n);}}}function Mv(t){for(let e=0;e<t.childNodes.length;e++){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(!(r.namespaceURI===W_NS&&(r.localName==="rPr"||r.localName==="drawing")))return false}return true}function Av(t){return t.nodeType===1}var Zt=new 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:t=>["p",Dv(t.attrs),0]},table:{group:"block",content:"table_row+",attrs:{tableId:{default:""},columnWidths:{default:null}},tableRole:"table",toDOM:t=>["div",{class:"coco-word-table-scroll"},["table",Wv(t.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:t=>["td",Bv(t.attrs),0]},image:{inline:true,group:"inline",atom:true,attrs:{src:{},alt:{default:""},width:{default:null},height:{default:null},drawingId:{default:null}},toDOM:t=>["img",Fv(t.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:t=>["span",Ov(t.attrs),0]}}});new PluginKey("coco-word-decorations");var sp=new PluginKey("coco-word-structure-normalization");function Dv(t){let e={};typeof t.paraId=="string"&&t.paraId.length>0&&(e["data-para-id"]=t.paraId),typeof t.story=="string"&&t.story.length>0&&(e["data-story"]=t.story),typeof t.styleId=="string"&&t.styleId.length>0&&(e["data-style-id"]=t.styleId);let n=$v(t.format)?t.format:null;(n==null?void 0:n.outlineLevel)!==void 0&&(e["data-outline-level"]=String(n.outlineLevel));let r=zv(n);return r.length>0&&(e.style=r),e}function Wv(t){let e={};return typeof t.tableId=="string"&&t.tableId.length>0&&(e["data-table-id"]=t.tableId),e}function Bv(t){let e={};typeof t.colspan=="number"&&t.colspan>1&&(e.colspan=String(t.colspan)),typeof t.rowspan=="number"&&t.rowspan>1&&(e.rowspan=String(t.rowspan));let n=[];if(typeof t.width=="number"&&t.width>0&&n.push(`width: ${Gn(t.width)}`),Hv(t.shading)){let r=al(t.shading.fill);r&&n.push(`background-color: ${r}`);}return typeof t.verticalAlignment=="string"&&n.push(`vertical-align: ${t.verticalAlignment==="center"?"middle":t.verticalAlignment}`),n.length>0&&(e.style=n.join("; ")),e}function Fv(t){let e={src:typeof t.src=="string"?t.src:"",alt:typeof t.alt=="string"?t.alt:""};typeof t.drawingId=="string"&&(e["data-drawing-id"]=t.drawingId);let n=[];return typeof t.width=="number"&&t.width>0&&n.push(`width: ${t.width}px`),typeof t.height=="number"&&t.height>0&&n.push(`height: ${t.height}px`),n.length>0&&(e.style=n.join("; ")),e}function Hv(t){return t!==null&&typeof t=="object"}function Ov(t){let e=[],n=typeof t.color=="string"?al(t.color):null;return n&&e.push(`color: ${n}`),typeof t.fontSize=="number"&&e.push(`font-size: ${t.fontSize}pt`),e.length>0?{style:e.join("; ")}:{}}function $v(t){return t!==null&&typeof t=="object"}function zv(t){var o,i,a,s,l,d,u,p,f;if(!t)return "";let e=[];t.alignment&&e.push(`text-align: ${Vv(t.alignment)}`),((o=t.indent)==null?void 0:o.left)!==void 0&&e.push(`margin-left: ${Gn(t.indent.left)}`),((i=t.indent)==null?void 0:i.right)!==void 0&&e.push(`margin-right: ${Gn(t.indent.right)}`),((a=t.indent)==null?void 0:a.firstLine)!==void 0&&e.push(`text-indent: ${Gn(t.indent.firstLine)}`),((s=t.spacing)==null?void 0:s.before)!==void 0&&e.push(`margin-top: ${Gn(t.spacing.before)}`),((l=t.spacing)==null?void 0:l.after)!==void 0&&e.push(`margin-bottom: ${Gn(t.spacing.after)}`);let n=jv((d=t.spacing)==null?void 0:d.line,(u=t.spacing)==null?void 0:u.lineRule);n&&e.push(`line-height: ${n}`),t.fontSize!==void 0&&e.push(`font-size: ${t.fontSize}pt`),t.bold!==void 0&&e.push(`font-weight: ${t.bold?"700":"400"}`);let r=Gv(t.borderBottom);return r&&(e.push(`border-bottom: ${r}`),e.push(`padding-bottom: ${(f=(p=t.borderBottom)==null?void 0:p.space)!=null?f:4}pt`)),e.join("; ")}function Vv(t){return t==="both"||t==="distribute"?"justify":t}function Gv(t){var o;if(!t||t.val==="none"||t.val==="nil")return null;let e=(o=al(t.color))!=null?o:"#000000",n=t.size!==void 0?Math.max(.75,t.size/8):.75,r=t.val==="double"?"double":"solid";return `${n}pt ${r} ${e}`}function jv(t,e){return t===void 0?null:e==="exact"||e==="atLeast"?Gn(t):String(t/240)}function Gn(t){return `${t/20}pt`}function al(t){return !t||t==="auto"?null:/^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}var lo=new PluginKey("coco-word-editing"),_v=0;function aN(t={}){return new Plugin({key:lo,appendTransaction(e,n,r){if(!e.some(a=>a.docChanged)||e.every(a=>a.getMeta(sp)))return null;let o=Xv(n.doc,r.doc),i=o.length>0?o:Qv(n.doc,r.doc);return i.length>0?pp(r.tr,i):null},state:{init:()=>({changes:[]}),apply(e,n){var i,a;let r=e.getMeta(lo);if(!((i=r==null?void 0:r.changes)!=null&&i.length))return n;let o={changes:[...n.changes,...r.changes]};return (a=t.onChangeSet)==null||a.call(t,o),o}}})}function sN(t){var e;return (e=lo.getState(t))!=null?e:{changes:[]}}function lN(t){var s,l;let{from:e,to:n,empty:r}=t.selection,o=t.selection.$from,i=oS(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:e,to:n,empty:r,selectedText:t.doc.textBetween(e,n,`
|
|
20
|
-
`),paragraphs:dl(t,e,n),tableCell:a}}function
|
|
18
|
+
`)}function Af(t){return ro(t)?t.kind==="paragraph"?typeof t.paraId=="string"&&typeof t.story=="string"&&Array.isArray(t.content)&&t.content.length<=1e5&&t.content.every(Sy):t.kind!=="table"||typeof t.tableId!="string"||!Array.isArray(t.rows)||t.rows.length>1e4?false:t.rows.every(e=>ro(e)&&Array.isArray(e.cells)&&e.cells.length<=1e3&&e.cells.every(n=>ro(n)&&Array.isArray(n.blocks)&&n.blocks.length<=1e4&&n.blocks.every(Af))):false}function Sy(t){return !ro(t)||typeof t.kind!="string"?false:t.kind==="text"?typeof t.text=="string":t.kind==="image"?typeof t.drawingId=="string"&&typeof t.src=="string":t.kind==="drawing"?typeof t.drawingId=="string":t.kind==="pageBreak"?true:t.kind==="field"?typeof t.fieldKind=="string"&&typeof t.instruction=="string":false}function ro(t){return typeof t=="object"&&t!==null}function ky(t){let e="",n=0,r=[...t.runs].map(o=>H(v({},o),{from:Math.max(0,o.from),to:Math.min(t.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&&(e+=Xs(t.text.slice(n,o.from))),o.from<n)continue;let i=Xs(t.text.slice(o.from,o.to)),a=Ey(o.format),s=a?`<span style="${Ys(a)}">${i}</span>`:i;if(o.hyperlink){let l=Yr(o.hyperlink.target,o.hyperlink.anchor),d=o.hyperlink.tooltip?` title="${Ys(o.hyperlink.tooltip)}"`:"";s=`<a href="${Ys(l)}"${d}>${s}</a>`;}e+=s,n=o.to;}return n<t.text.length&&(e+=Xs(t.text.slice(n))),e||"<br>"}function Ey(t){let e=[];t.bold!==void 0&&e.push(`font-weight:${t.bold?"700":"400"}`),t.italic!==void 0&&e.push(`font-style:${t.italic?"italic":"normal"}`);let n=[];return t.underline&&n.push("underline"),(t.strike||t.doubleStrike)&&n.push("line-through"),n.length>0?e.push(`text-decoration-line:${n.join(" ")}`):(t.underline===false||t.strike===false||t.doubleStrike===false)&&e.push("text-decoration-line:none"),t.fontFamily&&e.push(`font-family:${t.fontFamily}`),t.fontSize!==void 0&&e.push(`font-size:${t.fontSize}pt`),t.color&&e.push(`color:#${t.color.replace(/^#/,"")}`),t.highlight&&t.highlight!=="none"&&e.push(`background-color:#${t.highlight.replace(/^#/,"")}`),t.verticalAlign&&e.push(`vertical-align:${t.verticalAlign}`),t.caps&&e.push("text-transform:uppercase"),t.smallCaps&&e.push("font-variant-caps:small-caps"),t.characterSpacing!==void 0&&e.push(`letter-spacing:${t.characterSpacing/20}pt`),e.join(";")}function Xs(t){return Lf(t).replace(/\r\n?|\n/g,"<br>")}function Lf(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Ys(t){return Lf(t).replace(/"/g,""")}function Df(t,e,n,r){var a;if(t.nodeType===Node.TEXT_NODE){let s=(a=t.textContent)!=null?a:"";if(!s)return;let l=n.text.length;n.text+=s,(Object.keys(e).length>0||r)&&n.runs.push(v({from:l,to:n.text.length,format:e},r?{hyperlink:r}:{}));return}if(!(t instanceof HTMLElement))return;if(t.tagName==="BR"){n.text+=`
|
|
19
|
+
`;return}let o=v(v({},e),Iy(t)),i=t.tagName==="A"?Cy(t):r;for(let s of Array.from(t.childNodes))Df(s,o,n,i);}function Cy(t){var o,i;let e=(o=t.getAttribute("href"))==null?void 0:o.trim();if(!e)return;let n=(i=t.getAttribute("title"))==null?void 0:i.trim();if(e.startsWith("#")){let a=e.slice(1);try{a=decodeURIComponent(a);}catch(s){return}return a?v({anchor:a},n?{tooltip:n}:{}):void 0}let r=Yr(e,void 0);return r==="#"?void 0:v({target:r},n?{tooltip:n}:{})}function Iy(t){let e=t.style,n={};(t.matches("b, strong")||Number.parseInt(e.fontWeight,10)>=600)&&(n.bold=true),(t.matches("i, em")||e.fontStyle==="italic")&&(n.italic=true);let r=e.textDecorationLine||e.textDecoration;(t.matches("u")||r.includes("underline"))&&(n.underline=true),(t.matches("s, strike, del")||r.includes("line-through"))&&(n.strike=true),e.fontFamily&&(n.fontFamily=e.fontFamily.replace(/["']/g,""));let o=Ny(e.fontSize);o!==null&&(n.fontSize=o);let i=Tf(e.color),a=Tf(e.backgroundColor);return i&&(n.color=i),a&&(n.highlight=a),n}function Tf(t){let e=t.trim();if(!e||e==="transparent")return null;let n=/^#([\da-f]{3}|[\da-f]{6})$/i.exec(e);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(e);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(t){var r;let e=/^([\d.]+)(pt|px)$/i.exec(t.trim());if(!e)return null;let n=Number(e[1]);return Number.isFinite(n)?((r=e[2])==null?void 0:r.toLowerCase())==="px"?n*.75:n:null}var il="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",Ri="http://schemas.openxmlformats.org/package/2006/content-types",Gf="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Wf="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",Bf="http://schemas.microsoft.com/office/2011/relationships/commentsExtended",sn="http://schemas.microsoft.com/office/word/2012/wordml",Ff=`${Vn}/hyperlink`,jf="application/vnd.openxmlformats-package.relationships+xml";function Py(t){let e=[],n=[],r=new Map;for(let o of t)o.kind==="table"&&o.revisionId&&o.revisionAction&&r.set(o.revisionId,o.revisionAction);for(let o of t){if(o.kind==="table"&&o.revisionAction||o.kind==="table"&&o.revisionId&&r.get(o.revisionId)==="reject")continue;let i=Ry(o,{allowTrackedTable:o.kind==="table"&&!!o.revisionId&&r.get(o.revisionId)==="accept"});i?e.push(i):n.push({change:o,reason:Ly(o)});}return {target:"word/document.xml",patches:e,unsupported:n}}function VI(t,e,n=buildIndices(t)){let r=Py(e),o=Ay(t,n,r.patches);return v({plan:r},o)}function Ry(t,e={}){var n;if(t.kind==="text")return v({kind:"paragraph-text",op:t.op,paraId:t.paraId,offset:t.offset,text:t.text},t.deletedText!==void 0?{deletedText:t.deletedText}:{});if(t.kind==="format"&&t.op==="run"&&t.revisionId&&t.revisionKind==="format")return v({kind:"format-revision",op:"run",paraId:t.paraId,from:t.from,to:t.to,revisionId:t.revisionId},t.beforeFormat!==void 0?{beforeFormat:t.beforeFormat}:{});if(t.kind==="format"&&t.op==="run")return {kind:"paragraph-format",paraId:t.paraId,from:t.from,to:t.to,format:t.format};if(t.kind==="format"&&(t.op==="accept"||t.op==="reject")&&t.revisionId)return {kind:"format-revision",op:t.op,paraId:t.paraId,from:t.from,to:t.to,revisionId:t.revisionId};if(t.kind==="image"&&t.op==="delete")return {kind:"drawing-delete",paraId:t.paraId,drawingId:t.drawingId,offset:t.offset};if(t.kind==="image"&&t.op==="resize"&&t.width&&t.height)return {kind:"drawing-resize",paraId:t.paraId,drawingId:t.drawingId,offset:t.offset,width:t.width,height:t.height};if(t.kind==="image"&&t.op==="insert"&&t.src&&t.width&&t.height)return {kind:"drawing-insert",paraId:t.paraId,drawingId:t.drawingId,offset:t.offset,src:t.src,width:t.width,height:t.height};if(t.kind==="image"&&(t.op==="accept"||t.op==="reject")&&t.revisionId&&(t.revisionKind==="insert"||t.revisionKind==="delete"))return {kind:"drawing-revision",op:t.op,paraId:t.paraId,drawingId:t.drawingId,offset:t.offset,revisionId:t.revisionId,revisionKind:t.revisionKind};if(t.kind==="block"&&t.op==="split"&&t.newParaId&&t.offset!==void 0)return {kind:"paragraph-split",paraId:t.paraId,newParaId:t.newParaId,offset:t.offset};if(t.kind==="block"&&t.op==="merge")return {kind:"paragraph-merge",paraId:t.paraId};if(t.kind==="hyperlink"){if(t.from>=t.to)return null;let r=t.hyperlink;return t.op==="set"&&(!(r!=null&&r.target)||!Kf(r.target)||r.anchor)?null:v({kind:"hyperlink",op:t.op,paraId:t.paraId,from:t.from,to:t.to},t.op==="set"&&r?{hyperlink:r}:{})}return t.kind==="table"&&(!t.revisionId||e.allowTrackedTable===true)&&t.op!=="insert-table"&&t.op!=="delete-table"&&t.op!=="format-cell"&&t.op!=="clear-cell"&&t.op!=="replace-cell"?v(v({kind:"table-structure",op:t.op,tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex},t.endColumnIndex!==void 0?{endColumnIndex:t.endColumnIndex}:{}),t.endRowIndex!==void 0?{endRowIndex:t.endRowIndex}:{}):t.kind==="table"&&t.op==="insert-table"&&t.tableSnapshot&&t.anchorParaId?{kind:"table-insert",anchorParaId:t.anchorParaId,anchorOffset:(n=t.anchorOffset)!=null?n:0,table:t.tableSnapshot}:t.kind==="table"&&t.op==="format-cell"&&t.format?{kind:"table-cell-format",tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex,format:t.format}:t.kind==="table"&&t.op==="clear-cell"?{kind:"table-cell-clear",tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex}:t.kind==="table"&&t.op==="replace-cell"&&t.text!==void 0?{kind:"table-cell-replace",tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex,text:t.text}:t.kind==="table"&&t.op==="replace-cell"&&t.cellSnapshot?Uf(t.cellSnapshot)?null:{kind:"table-cell-replace-rich",tableId:t.tableId,rowIndex:t.rowIndex,columnIndex:t.columnIndex,cell:t.cellSnapshot}:t.kind==="annotation"&&(t.op==="insert"||t.op==="delete"||t.op==="update")?v(v({kind:"comment",op:t.op,paraId:t.paraId,from:t.from,to:t.to,commentId:t.commentId},t.parentCommentId!==void 0?{parentCommentId:t.parentCommentId}:{}),t.body!==void 0?{body:t.body}:{}):t.kind==="revision"?{kind:"revision",op:t.op,paraId:t.paraId,from:t.from,to:t.to,revisionId:t.revisionId,revisionKind:t.revisionKind}:t.kind==="table"&&t.op==="delete-table"&&e.allowTrackedTable===true?{kind:"table-delete",tableId:t.tableId}:null}function My(t,e,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=e.drawingIdx.get(s.drawingId);if(!u&&s.kind==="drawing-revision"){let p=e.paraIdx.get(s.paraId.toUpperCase());u=p&&(i=ev(p,s.offset))!=null?i:void 0;}if(!u){o.push({patch:s,reason:`drawing not found: ${s.drawingId}`});continue}let f=or(t,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=e.paraIdx.get(s.paraId.toUpperCase()))!=null?a:null});continue}if(s.kind==="drawing-insert"){let u=e.paraIdx.get(s.paraId.toUpperCase());if(!u){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let f=or(t,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=e.paraIdx.get(s.paraId.toUpperCase());if(!u){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let f=or(t,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=e.paraIdx.get(s.anchorParaId.toUpperCase());if(!u){o.push({patch:s,reason:`anchor paragraph not found: ${s.anchorParaId}`});continue}let f=or(t,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=e.tblIdx.get(s.tableId);if(!u){o.push({patch:s,reason:`table not found: ${s.tableId}`});continue}let f=or(t,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=e.paraIdx.get(s.paraId.toUpperCase());if(!l){o.push({patch:s,reason:`paragraph not found: ${s.paraId}`});continue}let d=or(t,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 Ay(t,e,n){var l,d;let r=[],o=[],i=[],a=new Set,s=e;for(let u of n){let f=My(t,s,[u]);if(f.unresolved.length>0){i.push(...f.unresolved);continue}let p=f.resolved[0];if(!p)continue;let b=Yf(t,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=uv(t,p.partPath,(l=p.paragraph)!=null?l:p.drawing,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="drawing-revision"){(p.patch.revisionKind==="insert"&&p.patch.op==="reject"||p.patch.revisionKind==="delete"&&p.patch.op==="accept")&&zf(p.drawing),markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="drawing-resize"){let g=cv(p.drawing,p.patch.width,p.patch.height);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}zf(p.drawing),markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.kind==="table"){if(p.patch.kind==="table-insert"){let h=Hy(p.table.ownerDocument,p.patch.table,t,p.partPath);(d=p.table.parentNode)==null||d.insertBefore(h,p.table.nextSibling),markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="table-cell-format"){let h=Oy(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="table-cell-clear"){let h=$y(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="table-cell-replace"){let h=zy(p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="table-cell-replace-rich"){let h=Vy(t,p.partPath,p.table,p.patch);if(!h.ok){o.push({patch:p.patch,reason:h.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="table-delete"){Ue(p.table),markDirty(b),r.push(p.patch),s=buildIndices(t);continue}let g=Gy(p.table,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.kind==="comment"){let g=yv(t,p.partPath,p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="revision"){let g=pv(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}markDirty(b),r.push(p.patch),(p.patch.op==="accept"||p.patch.op==="reject")&&a.add(p.patch.revisionId),s=buildIndices(t);continue}if(p.patch.kind==="paragraph-format"){let g=hv(p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="format-revision"){let g=mv(p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="paragraph-split"){let g=rv(p.paragraph,p.patch.offset,p.patch.newParaId);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="paragraph-merge"){let g=ov(p.paragraph);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}if(p.patch.kind==="hyperlink"){let g=Dy(t,p.partPath,p.paragraph,p.patch);if(!g.ok){o.push({patch:p.patch,reason:g.reason});continue}markDirty(b),r.push(p.patch),s=buildIndices(t);continue}let w=Zy(p.paragraph,p.patch);if(!w.ok){o.push({patch:p.patch,reason:w.reason});continue}markDirty(b),r.push(p.patch);}return {applied:r,skipped:o,unresolved:i}}function Ly(t){var e;return t.kind==="block"&&t.op==="split"?"paragraph split change is missing newParaId or offset":t.kind==="hyperlink"?t.op==="set"&&((e=t.hyperlink)!=null&&e.anchor)?"hyperlink anchors are not yet written back":"only external http/https hyperlinks can be written back":t.kind==="image"&&t.op==="resize"?"image resize is missing width or height":t.kind==="image"&&t.op==="insert"?"image insert requires data URL, width, and height":t.kind==="table"?t.op==="replace-cell"&&t.cellSnapshot&&Uf(t.cellSnapshot)?"table cell rich replacement does not yet write back drawings or hyperlink anchors":t.revisionId||t.revisionKind?"table revision writeback requires an original table structure snapshot":"table structure change is not supported for DOCX writeback":`unsupported native change: ${t.kind}/${"op"in t?t.op:"unknown"}`}function Uf(t){return t.blocks.some(e=>e.kind!=="paragraph"||e.content.some(n=>n.kind==="drawing"||n.kind==="text"&&n.hyperlink!==void 0&&!n.hyperlink.target))}function Kf(t){try{let e=new URL(t).protocol.toLowerCase();return e==="http:"||e==="https:"}catch(e){return false}}function Dy(t,e,n,r){var f,p,b;let o=ce(n).filter(w=>!(w.namespaceURI===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!==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||!Kf(w))return {ok:false,reason:"only external http/https hyperlinks can be written back"};let g=qf(t,e,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),x=Math.min(g,r.to-d);if(!(h<x)){l.push(w),d+=g;continue}if(h>0){let I=ar(w,0,h);I&&l.push(I);}let k=ar(w,h,x);if(k&&u.push(...By(k)),x<g){let I=ar(w,x,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(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(W_NS,"w:tooltip",h);for(let x of u)g.appendChild(x);Wy(l,g,r);}else _f(l,u,r);for(let w of o)Ue(w);for(let w of l)n.appendChild(w);return s&&markDirty(s),{ok:true}}function Wy(t,e,n){_f(t,[e],n);}function _f(t,e,n){let r=0,o=false,i=[];for(let a of t)!o&&r>=n.from&&(i.push(...e),o=true),i.push(a),r+=jt(a);o||i.push(...e),t.splice(0,t.length,...i);}function ar(t,e,n){if(n<=e)return null;let r=t.cloneNode(true);return nl(r,e,n),jt(r)>0?r:null}function By(t){return t.namespaceURI===W_NS&&t.localName==="hyperlink"?ce(t).filter(e=>e.namespaceURI===W_NS&&e.localName==="r"):[t]}function Fy(t){return t.getElementsByTagNameNS(W_NS,"drawing").length>0||t.getElementsByTagNameNS(W_NS,"pict").length>0}function qf(t,e,n){var u,f,p,b,w;let r=Ai(e),o=t.parts.get(r);if(!(o!=null&&o.xmlDom)){let g=(u=Array.from(t.parts.values()).find(x=>x.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=createXmlPart({path:r,contentType:jf,xmlDom:h}),setPart(t,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"))===Ff&&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",Ff),d.setAttribute("Target",n),d.setAttribute("TargetMode","External"),(w=i.documentElement)==null||w.appendChild(d),{id:`rId${l}`,part:o}}function Ai(t){let e=t.lastIndexOf("/"),n=e>=0?t.slice(0,e):"",r=t.slice(e+1);return n?`${n}/_rels/${r}.rels`:`_rels/${r}.rels`}function Hy(t,e,n,r){var u,f,p,b,w,g,h,x,S;let o=k=>t.createElementNS(W_NS,`w:${k}`),i=o("tbl"),a=o("tblPr"),s=o("tblW");s.setAttributeNS(W_NS,"w:w",String(Math.max(0,Math.round((f=(u=e.layout)==null?void 0:u.width)!=null?f:0)))),s.setAttributeNS(W_NS,"w:type",(b=(p=e.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=e.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:(x=I==null?void 0:I.size)!=null?x:4};}if(writeWordTableBorders(a,"table",l),(S=e.layout)!=null&&S.mode){let k=o("tblLayout");k.setAttributeNS(W_NS,"w:type",e.layout.mode),a.appendChild(k);}i.appendChild(a);let d=o("tblGrid");for(let k of e.columnWidths){let I=o("gridCol");I.setAttributeNS(W_NS,"w:w",String(Math.max(1,Math.round(k)))),d.appendChild(I);}i.appendChild(d);for(let k of e.rows){let I=o("tr");for(let D of k.cells)I.appendChild(Xf(t,D,n,r));i.appendChild(I);}return i}function Xf(t,e,n,r){var u,f,p,b,w,g,h;let o=x=>t.createElementNS(W_NS,`w:${x}`),i=o("tc"),a=o("tcPr"),s=o("tcW");if(s.setAttributeNS(W_NS,"w:w",String(e.widthType==="auto"?0:Math.max(1,Math.round((u=e.width)!=null?u:0)))),s.setAttributeNS(W_NS,"w:type",(f=e.widthType)!=null?f:"dxa"),a.appendChild(s),(p=e.shading)!=null&&p.fill){let x=o("shd");x.setAttributeNS(W_NS,"w:val",(b=e.shading.val)!=null?b:"clear"),x.setAttributeNS(W_NS,"w:fill",e.shading.fill.replace(/^#/,"").toUpperCase()),a.appendChild(x);}if(e.verticalAlignment){let x=o("vAlign");x.setAttributeNS(W_NS,"w:val",e.verticalAlignment),a.appendChild(x);}i.appendChild(a);let l=e.blocks.filter(x=>x.kind==="paragraph"),d=l.length>0?l:[null];for(let x of d){let S=o("p");if(x)for(let k of x.content){if(k.kind==="image"){let F=np(k.src);if(!F)continue;let A=rp(n,r,F.bytes,F.extension,F.contentType);S.appendChild(tp(t,A.id,k.drawingId,(w=k.width)!=null?w:96,(g=k.height)!=null?g:96)),markDirty(A.part),markDirty(A.mediaPart),op(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 A=o("u");A.setAttributeNS(W_NS,"w:val","single"),F.appendChild(A);}if(k.format.strike&&F.appendChild(o("strike")),k.format.color){let A=o("color");A.setAttributeNS(W_NS,"w:val",k.format.color.replace(/^#/,"").toUpperCase()),F.appendChild(A);}if(k.format.fontSize){let A=o("sz");A.setAttributeNS(W_NS,"w:val",String(Math.round(k.format.fontSize*2))),F.appendChild(A);}if(k.format.characterScale!==void 0){let A=o("w");A.setAttributeNS(W_NS,"w:val",String(k.format.characterScale)),F.appendChild(A);}if(k.format.fontFamily){let A=o("rFonts");for(let O of ["ascii","hAnsi","eastAsia"])A.setAttributeNS(W_NS,`w:${O}`,k.format.fontFamily);F.appendChild(A);}F.childNodes.length>0&&I.appendChild(F);}let D=o("t");if(D.textContent=k.text,/^\s|\s$/.test(k.text)&&D.setAttributeNS(il,"xml:space","preserve"),I.appendChild(D),(h=k.hyperlink)!=null&&h.target){let F=qf(n,r,k.hyperlink.target),A=t.createElementNS(W_NS,"w:hyperlink");A.setAttributeNS(Vn,"r:id",F.id),A.appendChild(I),S.appendChild(A),markDirty(F.part);}else S.appendChild(I);}S.firstChild||S.appendChild(o("r")),i.appendChild(S);}return i}function Oy(t,e){let r=ce(t).filter(l=>l.namespaceURI===W_NS&&l.localName==="tr")[e.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${e.rowIndex}`};let i=ce(r).filter(l=>l.namespaceURI===W_NS&&l.localName==="tc")[e.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${e.columnIndex}`};let a=t.ownerDocument,s=ce(i).find(l=>l.namespaceURI===W_NS&&l.localName==="tcPr");if(s||(s=a.createElementNS(W_NS,"w:tcPr"),i.insertBefore(s,i.firstChild)),e.format.backgroundColor!==void 0){let l=ce(s).find(d=>d.namespaceURI===W_NS&&d.localName==="shd");if(e.format.backgroundColor===null)l&&Ue(l);else {let d=l!=null?l:a.createElementNS(W_NS,"w:shd");d.setAttributeNS(W_NS,"w:val","clear"),d.setAttributeNS(W_NS,"w:fill",e.format.backgroundColor.replace(/^#/,"").toUpperCase()),l||s.appendChild(d);}}if(e.format.verticalAlignment!==void 0){let l=ce(s).find(d=>d.namespaceURI===W_NS&&d.localName==="vAlign");if(e.format.verticalAlignment===null)l&&Ue(l);else {let d=l!=null?l:a.createElementNS(W_NS,"w:vAlign");d.setAttributeNS(W_NS,"w:val",e.format.verticalAlignment),l||s.appendChild(d);}}if(e.format.borderColor!==void 0){let l=e.format.borderColor===null?{val:"nil"}:{val:"single",size:4,color:e.format.borderColor.replace(/^#/,"").toUpperCase()},d={top:v({},l),left:v({},l),bottom:v({},l),right:v({},l),insideH:v({},l),insideV:v({},l)};writeWordTableBorders(s,"cell",d);}return {ok:true}}function $y(t,e){let r=ce(t).filter(s=>s.namespaceURI===W_NS&&s.localName==="tr")[e.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${e.rowIndex}`};let i=ce(r).filter(s=>s.namespaceURI===W_NS&&s.localName==="tc")[e.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${e.columnIndex}`};let a=ce(i).find(s=>s.namespaceURI===W_NS&&s.localName==="tcPr");for(let s of ce(i))s!==a&&Ue(s);return i.appendChild(i.ownerDocument.createElementNS(W_NS,"w:p")),{ok:true}}function zy(t,e){let r=ce(t).filter(p=>p.namespaceURI===W_NS&&p.localName==="tr")[e.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${e.rowIndex}`};let i=ce(r).filter(p=>p.namespaceURI===W_NS&&p.localName==="tc")[e.columnIndex];if(!i)return {ok:false,reason:`table column out of range: ${e.columnIndex}`};let a=ce(i).find(p=>p.namespaceURI===W_NS&&p.localName==="tcPr"),s=ce(i).find(p=>p.namespaceURI===W_NS&&p.localName==="p");for(let p of ce(i))p!==a&&Ue(p);let l=i.ownerDocument.createElementNS(W_NS,"w:p"),d=s&&ce(s).find(p=>p.namespaceURI===W_NS&&p.localName==="pPr");d&&l.appendChild(d.cloneNode(true));let u=i.ownerDocument.createElementNS(W_NS,"w:r"),f=i.ownerDocument.createElementNS(W_NS,"w:t");return f.textContent=e.text,/^\s|\s$/.test(e.text)&&f.setAttributeNS(il,"xml:space","preserve"),u.appendChild(f),l.appendChild(u),i.appendChild(l),{ok:true}}function Vy(t,e,n,r){let i=ce(n).filter(d=>d.namespaceURI===W_NS&&d.localName==="tr")[r.rowIndex];if(!i)return {ok:false,reason:`table row out of range: ${r.rowIndex}`};let s=ce(i).filter(d=>d.namespaceURI===W_NS&&d.localName==="tc")[r.columnIndex];if(!s)return {ok:false,reason:`table column out of range: ${r.columnIndex}`};let l=Xf(n.ownerDocument,r.cell,t,e);for(let d of ce(s))Ue(d);for(let d of ce(l))s.appendChild(d.cloneNode(true));return {ok:true}}function Gy(t,e){var u,f,p,b;let n=ce(t).filter(w=>w.namespaceURI===W_NS&&w.localName==="tr");if(n.length===0)return {ok:false,reason:"table has no rows"};if(e.op==="insert-row"||e.op==="delete-row"){if(e.rowIndex<0||e.rowIndex>=n.length+(e.op==="insert-row"?1:0))return {ok:false,reason:`table row out of range: ${e.rowIndex}`};if(e.op==="delete-row")return n.length<=1?{ok:false,reason:"cannot delete the only table row"}:(Ue(n[e.rowIndex]),{ok:true});let w=n[Math.min(e.rowIndex,n.length-1)],g=Uy(w);return t.insertBefore(g,(u=n[e.rowIndex])!=null?u:null),{ok:true}}let r=n[e.rowIndex];if(!r)return {ok:false,reason:`table row out of range: ${e.rowIndex}`};let o=ce(r).filter(w=>w.namespaceURI===W_NS&&w.localName==="tc");if(e.op==="insert-column"||e.op==="delete-column"){if(o.length===0)return {ok:false,reason:"table row has no cells"};if(e.columnIndex<0||e.columnIndex>=o.length+(e.op==="insert-column"?1:0))return {ok:false,reason:`table column out of range: ${e.columnIndex}`};let w=n.map(g=>ce(g).filter(h=>h.namespaceURI===W_NS&&h.localName==="tc"));if(w.some(g=>g.length!==o.length||g.some(h=>zn(h)!==1||Pi(h))))return {ok:false,reason:"table column structure is not a regular non-merged grid"};for(let g of w)if(e.op==="delete-column"){if(g.length<=1)return {ok:false,reason:"cannot delete the only table column"};Ue(g[e.columnIndex]);}else {let h=g[Math.min(e.columnIndex,g.length-1)],x=el(h);(p=g[0].parentNode)==null||p.insertBefore(x,(f=g[e.columnIndex])!=null?f:null);}return Yy(t,e.op==="insert-column"?"insert":"delete",e.columnIndex),{ok:true}}if(e.op==="merge-cells"){if(e.endRowIndex!==void 0&&e.endRowIndex>e.rowIndex){if(e.columnIndex<0||e.endRowIndex>=n.length)return {ok:false,reason:`vertical merge row out of range: ${e.rowIndex}:${e.endRowIndex}`};let h=n.slice(e.rowIndex,e.endRowIndex+1).map(x=>ce(x).filter(S=>S.namespaceURI===W_NS&&S.localName==="tc")[e.columnIndex]);if(h.some(x=>!x||zn(x)!==1||Pi(x)))return {ok:false,reason:"vertical merge requires a regular non-merged column"};Hf(h[0],"restart");for(let x of h.slice(1)){Hf(x,"continue");let S=ce(x).find(k=>k.namespaceURI===W_NS&&k.localName==="tcPr");for(let k of ce(x))k!==S&&Ue(k);x.appendChild(x.ownerDocument.createElementNS(W_NS,"w:p"));}return {ok:true}}let w=(b=e.endColumnIndex)!=null?b:e.columnIndex+1;if(e.columnIndex<0||w>=o.length||w<=e.columnIndex)return {ok:false,reason:`merge start column out of range: ${e.columnIndex}`};if(o.some(h=>zn(h)!==1||Pi(h)))return {ok:false,reason:"cell merge requires a regular non-merged row"};let g=o[e.columnIndex];for(let h=e.columnIndex+1;h<=w;h+=1){let x=o[h];Ky(g,x),Ue(x);}return _y(g,w-e.columnIndex+1),{ok:true}}if(e.endRowIndex!==void 0&&e.endRowIndex>e.rowIndex){if(e.columnIndex<0||e.endRowIndex>=n.length)return {ok:false,reason:`vertical split row out of range: ${e.rowIndex}:${e.endRowIndex}`};let w=n.slice(e.rowIndex,e.endRowIndex+1).map(g=>ce(g).filter(h=>h.namespaceURI===W_NS&&h.localName==="tc")[e.columnIndex]);if(w.some((g,h)=>{var k;if(!g||zn(g)!==1)return true;let x=(k=ce(g).find(I=>I.namespaceURI===W_NS&&I.localName==="tcPr"))==null?void 0:k.getElementsByTagNameNS(W_NS,"vMerge")[0],S=x==null?void 0:x.getAttributeNS(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)jy(g);return {ok:true}}let i=n[e.rowIndex],a=ce(i).filter(w=>w.namespaceURI===W_NS&&w.localName==="tc"),s=0,l=a.find(w=>{let g=s===e.columnIndex;return s+=zn(w),g});if(!l)return {ok:false,reason:`split column out of range: ${e.columnIndex}`};if(Pi(l)||zn(l)<=1)return {ok:false,reason:"cell is not a horizontally merged cell"};let d=zn(l);qy(l);for(let w=1;w<d;w+=1){let g=el(l);i.insertBefore(g,l.nextSibling);}return {ok:true}}function Hf(t,e){var i;let n=t.ownerDocument,r=ce(t).find(a=>a.namespaceURI===W_NS&&a.localName==="tcPr");r||(r=n.createElementNS(W_NS,"w:tcPr"),t.insertBefore(r,t.firstChild));let o=(i=ce(r).find(a=>a.namespaceURI===W_NS&&a.localName==="vMerge"))!=null?i:n.createElementNS(W_NS,"w:vMerge");o.setAttributeNS(W_NS,"w:val",e),o.parentNode||r.appendChild(o);}function jy(t){let e=ce(t).find(r=>r.namespaceURI===W_NS&&r.localName==="tcPr"),n=e&&ce(e).find(r=>r.namespaceURI===W_NS&&r.localName==="vMerge");n&&Ue(n);}function Uy(t){let e=t.cloneNode(true),n=ce(e).filter(r=>r.namespaceURI===W_NS&&r.localName==="tc");for(let r of n){let o=el(r);ep(r,o);}return e}function el(t){let e=t.ownerDocument,n=e.createElementNS(W_NS,"w:tc"),r=ce(t).find(s=>s.namespaceURI===W_NS&&s.localName==="tcPr");r&&n.appendChild(r.cloneNode(true));let o=e.createElementNS(W_NS,"w:p"),i=ce(t).find(s=>s.namespaceURI===W_NS&&s.localName==="p"),a=i&&ce(i).find(s=>s.namespaceURI===W_NS&&s.localName==="pPr");return a&&o.appendChild(a.cloneNode(true)),o.appendChild(e.createElementNS(W_NS,"w:r")),n.appendChild(o),n}function Ky(t,e){for(let n of ce(e))n.namespaceURI===W_NS&&n.localName==="tcPr"||t.appendChild(n.cloneNode(true));}function zn(t){var r,o;let e=(o=(r=ce(t).find(i=>i.namespaceURI===W_NS&&i.localName==="tcPr"))==null?void 0:r.getElementsByTagNameNS(W_NS,"gridSpan")[0])==null?void 0:o.getAttributeNS(W_NS,"val"),n=Number(e);return Number.isFinite(n)&&n>0?n:1}function Pi(t){var e;return !!((e=ce(t).find(n=>n.namespaceURI===W_NS&&n.localName==="tcPr"))!=null&&e.getElementsByTagNameNS(W_NS,"vMerge").length)}function _y(t,e){let n=Xy(t,"tcPr"),r=ce(n).find(o=>o.namespaceURI===W_NS&&o.localName==="gridSpan");r||(r=t.ownerDocument.createElementNS(W_NS,"w:gridSpan"),n.appendChild(r)),r.setAttributeNS(W_NS,"w:val",String(e));}function qy(t){let e=ce(t).find(r=>r.namespaceURI===W_NS&&r.localName==="tcPr"),n=e&&ce(e).find(r=>r.namespaceURI===W_NS&&r.localName==="gridSpan");n&&Ue(n);}function Xy(t,e){let n=ce(t).find(o=>o.namespaceURI===W_NS&&o.localName===e);if(n)return n;let r=t.ownerDocument.createElementNS(W_NS,`w:${e}`);return t.insertBefore(r,t.firstChild),r}function Yy(t,e,n){var s;let r=ce(t).find(l=>l.namespaceURI===W_NS&&l.localName==="tblGrid");if(!r)return;let o=ce(r).filter(l=>l.namespaceURI===W_NS&&l.localName==="gridCol");if(e==="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(t,e){var n,r;return (r=(n=Yf(t,e))==null?void 0:n.path)!=null?r:null}function Yf(t,e){let n=e.nodeType===9?e:e.ownerDocument;if(!n)return null;for(let r of t.parts.values())if(r.xmlDom===n)return r;return null}function Zy(t,e){var n,r;return e.op==="insert"?Zf(t,e.offset,e.text):e.op==="delete"?Of(t,e.offset,e.text.length,""):Of(t,e.offset,(r=(n=e.deletedText)==null?void 0:n.length)!=null?r:0,e.text)}function Zf(t,e,n){var s,l,d;if(n.length===0)return {ok:true};let r=ao(t),o=r.reduce((u,f)=>u+f.length,0);if(Jy(t)&&e===o)return $f(t,n),{ok:true};if(r.every(u=>u.kind!=="text"))return e!==0?{ok:false,reason:`insert offset out of range: ${e}`}:($f(t,n),{ok:true});let i=tl(r,e,true);if(!i)return {ok:false,reason:`insert offset out of range: ${e}`};if(i.node.localName==="delText"&&i.localOffset===((l=(s=i.node.textContent)==null?void 0:s.length)!=null?l:0)){let u=Qy(i.node,"del"),f=u==null?void 0:u.parentNode;if(u&&f===t){let p=t.ownerDocument;if(!p)return {ok:false,reason:"paragraph has no owner document"};let b=p.createElementNS(W_NS,"w:r"),w=p.createElementNS(W_NS,"w:t");return w.textContent=n,En(w),b.appendChild(w),t.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)}`,En(i.node),{ok:true}}function Of(t,e,n,r){var p,b;if(n===0)return Zf(t,e,r);let o=ao(t),i=o.filter(w=>w.kind==="text").map(w=>w.node),a=tl(o,e,false),s=tl(o,e+n,true);if(!a||!s)return {ok:false,reason:`text range out of range: ${e}:${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)}`,En(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: ${e}:${n}`};let f=(b=s.node.textContent)!=null?b:"";a.node.textContent=`${l.slice(0,a.localOffset)}${r}`,En(a.node);for(let w=d+1;w<u;w++)i[w].textContent="";return s.node.textContent=f.slice(s.localOffset),En(s.node),{ok:true}}function ao(t){let e=[];return Qf(t,e),e}function Jy(t){return t.getElementsByTagNameNS(W_NS,"fldChar").length>0||t.getElementsByTagNameNS(W_NS,"instrText").length>0}function Jf(t){return ao(t).filter(e=>e.kind==="text").map(e=>e.node)}function Qf(t,e){var r,o,i,a;if(t.nodeType!==1)return;let n=t;if(n.namespaceURI===W_NS&&n.localName==="t"){e.push({kind:"text",node:n,length:(o=(r=n.textContent)==null?void 0:r.length)!=null?o:0});return}if(n.namespaceURI===W_NS&&n.localName==="delText"){e.push({kind:"text",node:n,length:(a=(i=n.textContent)==null?void 0:i.length)!=null?a:0});return}if(n.namespaceURI===W_NS&&n.localName==="drawing"||n.namespaceURI===W_NS&&n.localName==="pict"){e.push({kind:"object",node:n,length:1});return}for(let s=0;s<n.childNodes.length;s+=1){let l=n.childNodes[s];l&&Qf(l,e);}}function Qy(t,e){let n=t.parentNode;for(;n&&n.nodeType===1;){let r=n;if(r.namespaceURI===W_NS&&r.localName===e)return r;if(r.namespaceURI===W_NS&&r.localName==="p")return null;n=n.parentNode;}return null}function ev(t,e){let n=0,r=ao(t);for(let o of r){if(o.kind==="object"&&e>=n&&e<=n+o.length)return o.node;n+=o.length;}return null}function tl(t,e,n){var o;let r=0;for(let i=0;i<t.length;i+=1){let a=t[i],s=r+a.length;if(a.kind==="text"){if(e>=r&&(e<s||n&&e===s))return {node:a.node,localOffset:e-r}}else if(e>=r&&e<=s)return (o=tv(t,i))!=null?o:nv(t,i);r=s;}return null}function tv(t,e){for(let n=e+1;n<t.length;n+=1){let r=t[n];if(r.kind==="text")return {node:r.node,localOffset:0}}return null}function nv(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r.kind==="text")return {node:r.node,localOffset:r.length}}return null}function $f(t,e){let n=t.ownerDocument;if(!n)return;let r=n.createElementNS(W_NS,"w:r"),o=n.createElementNS(W_NS,"w:t");o.textContent=e,En(o),r.appendChild(o),t.appendChild(r);}function En(t){var n;let e=(n=t.textContent)!=null?n:"";/^\s|\s$|\s{2,}/.test(e)&&t.setAttributeNS(il,"xml:space","preserve");}function rv(t,e,n){let r=t.parentNode,o=t.ownerDocument;if(!r||!o)return {ok:false,reason:"paragraph has no parent document"};let i=ce(t).filter(u=>!(u.namespaceURI===W_NS&&u.localName==="pPr")),a=i.reduce((u,f)=>u+jt(f),0);if(e<0||e>a)return {ok:false,reason:`split offset out of range: ${e}`};let s=iv(o,i,e),l=o.createElementNS(W_NS,"w:p");sv(t,l,n);let d=ce(t).find(u=>u.namespaceURI===W_NS&&u.localName==="pPr");d&&l.appendChild(d.cloneNode(true));for(let u of s)l.appendChild(u);return r.insertBefore(l,t.nextSibling),{ok:true}}function ov(t){let e=lv(t);if(!e)return {ok:false,reason:"next paragraph not found for merge"};for(let n of ce(e))n.namespaceURI===W_NS&&n.localName==="pPr"||t.appendChild(n.cloneNode(true));return Ue(e),{ok:true}}function iv(t,e,n){let r=[],o=0,i=false;for(let a of e){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=av(t,a,n-o);d.after&&r.push(d.after),i=true;}!i&&n===l&&(i=true),o=l;}return r}function av(t,e,n){let r=e.cloneNode(true),o=e.cloneNode(true);return nl(r,0,n),nl(o,n,jt(e)),ep(e,r),dv(o)||jt(o)>0?{after:o}:{after:null}}function nl(t,e,n){var i;let r=Jf(t),o=0;for(let a of r){let s=(i=a.textContent)!=null?i:"",l=o+s.length,d=Math.max(0,e-o),u=Math.min(s.length,n-o);a.textContent=d<u?s.slice(d,u):"",En(a),o=l;}}function jt(t){var o,i,a;if(t.namespaceURI===W_NS&&t.localName==="drawing")return 1;let e=0,n=t.getElementsByTagNameNS(W_NS,"t");for(let s=0;s<n.length;s++)e+=(a=(i=(o=n[s])==null?void 0:o.textContent)==null?void 0:i.length)!=null?a:0;let r=t.getElementsByTagNameNS(W_NS,"drawing");return e+=r.length,e}function sv(t,e,n){for(let r=0;r<t.attributes.length;r++){let o=t.attributes[r];o&&(o.namespaceURI===W14_NS&&o.localName==="paraId"||e.setAttributeNS(o.namespaceURI,o.name,o.value));}e.setAttributeNS(W14_NS,"w14:paraId",n);}function ce(t){let e=[];for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];(r==null?void 0:r.nodeType)===1&&e.push(r);}return e}function lv(t){let e=t.nextSibling;for(;e;){if(e.nodeType===1){let n=e;return n.namespaceURI===W_NS&&n.localName==="p"?n:null}e=e.nextSibling;}return null}function dv(t){return Jf(t).some(e=>{var n;return ((n=e.textContent)!=null?n:"").length>0})}function Ue(t){var e;(e=t.parentNode)==null||e.removeChild(t);}function ep(t,e){var n;(n=t.parentNode)==null||n.replaceChild(e,t);}function zf(t){var n;let e=t.parentNode;if(e){if(Av(e)&&e.namespaceURI===W_NS&&e.localName==="r"&&Mv(e)){(n=e.parentNode)==null||n.removeChild(e);return}e.removeChild(t);}}function cv(t,e,n){if(!Number.isFinite(e)||!Number.isFinite(n)||e<=0||n<=0)return {ok:false,reason:"image size must be positive finite pixels"};let r=Math.round(e/96*914400),o=Math.round(n/96*914400),i=ce(t).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=ce(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&&ce(d).find(f=>f.namespaceURI===Lt&&f.localName==="ext");u&&(u.setAttribute("cx",String(r)),u.setAttribute("cy",String(o)));}return {ok:true}}function uv(t,e,n,r){let o=np(r.src);if(!o)return {ok:false,reason:"image insert requires a base64 data:image URL"};let i=rp(t,e,o.bytes,o.extension,o.contentType),a=tp(n.ownerDocument,i.id,r.drawingId,r.width,r.height),s=ce(n).filter(p=>!(p.namespaceURI===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===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 markDirty(i.part),markDirty(i.mediaPart),op(t,o.extension,o.contentType),{ok:true}}function tp(t,e,n,r,o){let i=Math.round(r/96*914400),a=Math.round(o/96*914400),s=t.createElementNS(W_NS,"w:r"),l=t.createElementNS(W_NS,"w:drawing"),d=t.createElementNS(ir,"wp:inline"),u=t.createElementNS(ir,"wp:extent");u.setAttribute("cx",String(i)),u.setAttribute("cy",String(a)),d.appendChild(u);let f=t.createElementNS(ir,"wp:docPr");f.setAttribute("id",String(Math.abs(fv(n))+1)),f.setAttribute("name",`Picture ${n}`),d.appendChild(f),d.appendChild(t.createElementNS(ir,"wp:cNvGraphicFramePr"));let p=t.createElementNS(Lt,"a:graphic"),b=t.createElementNS(Lt,"a:graphicData");b.setAttribute("uri","http://schemas.openxmlformats.org/drawingml/2006/picture");let w=t.createElementNS(rr,"pic:pic"),g=t.createElementNS(rr,"pic:nvPicPr"),h=t.createElementNS(rr,"pic:cNvPr");h.setAttribute("id","0"),h.setAttribute("name",`image-${n}`),g.appendChild(h),g.appendChild(t.createElementNS(rr,"pic:cNvPicPr")),w.appendChild(g);let x=t.createElementNS(rr,"pic:blipFill"),S=t.createElementNS(Lt,"a:blip");S.setAttributeNS(Vn,"r:embed",e),x.appendChild(S);let k=t.createElementNS(Lt,"a:stretch");k.appendChild(t.createElementNS(Lt,"a:fillRect")),x.appendChild(k),w.appendChild(x);let I=t.createElementNS(rr,"pic:spPr"),D=t.createElementNS(Lt,"a:xfrm"),F=t.createElementNS(Lt,"a:ext");F.setAttribute("cx",String(i)),F.setAttribute("cy",String(a)),D.appendChild(t.createElementNS(Lt,"a:off")),D.appendChild(F),I.appendChild(D);let A=t.createElementNS(Lt,"a:prstGeom");return A.setAttribute("prst","rect"),A.appendChild(t.createElementNS(Lt,"a:avLst")),I.appendChild(A),w.appendChild(I),b.appendChild(w),p.appendChild(b),d.appendChild(p),l.appendChild(d),s.appendChild(l),s}function np(t){let e=/^data:(image\/(png|jpeg|jpg|gif|bmp|webp));base64,([a-z0-9+/=\s]+)$/i.exec(t.trim());if(!e)return null;let n=e[1].toLowerCase()==="image/jpg"?"image/jpeg":e[1].toLowerCase(),r=n==="image/jpeg"?"jpeg":n.slice(6),o=atob(e[3].replace(/\s/g,""));return {bytes:Uint8Array.from(o,i=>i.charCodeAt(0)),extension:r,contentType:n}}function rp(t,e,n,r,o){var g,h,x,S;let i=Ai(e),a=t.parts.get(i);if(!(a!=null&&a.xmlDom)){let k=(g=Array.from(t.parts.values()).find(D=>D.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=createXmlPart({path:i,contentType:jf,xmlDom:I}),setPart(t,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=(x=l[k])==null?void 0:x.getAttribute("Id");I&&u.add(I);}for(;u.has(`rId${d}`);)d+=1;let f=1;for(;t.parts.has(`word/media/image${f}.${r}`);)f+=1;let p=`word/media/image${f}.${r}`,b=createBinaryPart({path:p,contentType:o,bytes:n});setPart(t,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 op(t,e,n){var s,l,d;let r=getPart(t,"[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())===e.toLowerCase())return;let a=o.createElementNS("http://schemas.openxmlformats.org/package/2006/content-types","Default");a.setAttribute("Extension",e),a.setAttribute("ContentType",n),(d=o.documentElement)==null||d.appendChild(a),markDirty(r);}function fv(t){let e=0;for(let n=0;n<t.length;n+=1)e=e*31+t.charCodeAt(n)|0;return e}function pv(t,e){var l,d,u;if(e.op==="accept"||e.op==="reject"){let f=e.revisionKind==="insert"?"ins":"del",b=Array.from(t.getElementsByTagNameNS(W_NS,f)).filter(w=>w.getAttributeNS(W_NS,"id")===e.revisionId);if(b.length===0)return {ok:false,reason:`revision not found: ${e.revisionId}`};for(let w of b){let g=w.parentNode;if(!g)continue;if(!(f==="ins"&&e.op==="accept"||f==="del"&&e.op==="reject")){g.removeChild(w);continue}let x=Array.from(w.childNodes);if(f==="del")for(let S of x)S.nodeType===1&&xv(S);for(let S of x)g.insertBefore(S,w);g.removeChild(w);}return {ok:true}}if(e.from<0||e.to<=e.from)return {ok:false,reason:"revision range is empty or invalid"};let n=0,r=[],o=-1,i=[];for(let f of Array.from(t.childNodes)){if(f.nodeType!==1||f.namespaceURI!==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(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<=e.from||g>=e.to){i.push(p);continue}let x=Math.max(0,e.from-g),S=Math.min(w.length,e.to-g);x>0&&i.push(sr(p,w.slice(0,x))),S>x&&(o<0&&(o=i.length),r.push(sr(p,w.slice(x,S)))),S<w.length&&i.push(sr(p,w.slice(S)));}if(r.length===0||e.to>n)return {ok:false,reason:`revision range out of range: ${e.from}:${e.to}`};let a=t.ownerDocument;if(!a)return {ok:false,reason:"revision paragraph has no owner document"};let s=a.createElementNS(W_NS,e.revisionKind==="insert"?"w:ins":"w:del");s.setAttributeNS(W_NS,"w:id",e.revisionId),s.setAttributeNS(W_NS,"w:author","User"),s.setAttributeNS(W_NS,"w:date",new Date().toISOString());for(let f of r)e.revisionKind==="delete"&&wv(f),s.appendChild(f);for(i.splice(o<0?i.length:o,0,s),bv(i);t.firstChild;)t.removeChild(t.firstChild);for(let f of i)t.appendChild(f);return {ok:true}}function hv(t,e){var a;if(e.from<0||e.to<=e.from)return {ok:false,reason:"format range is empty or invalid"};if(t.getElementsByTagNameNS(W_NS,"ins").length>0||t.getElementsByTagNameNS(W_NS,"del").length>0){let s=Array.from(t.getElementsByTagNameNS(W_NS,"r")),l=0,d=0;for(let u of s){let f=ip(u);if(f.length===0)continue;let p=l,b=l+f.length;if(l=b,!(b<=e.from||p>=e.to)){if(e.from>p||e.to<b)return {ok:false,reason:"format writeback requires whole runs inside tracked content"};rl(u,e.format),d+=f.length;}}return d===0||e.to>l?{ok:false,reason:`format range out of range: ${e.from}:${e.to}`}:{ok:true}}let r=[],o=0,i=0;for(let s of Array.from(t.childNodes)){if(s.nodeType!==1||s.namespaceURI!==W_NS||s.localName!=="r"){r.push(s);continue}let l=s,d=Array.from(l.getElementsByTagNameNS(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<=e.from||f>=e.to){r.push(l);continue}let b=Math.max(0,e.from-f),w=Math.min(u.length,e.to-f);if(b>0&&r.push(sr(l,u.slice(0,b))),w>b){let g=sr(l,u.slice(b,w));rl(g,e.format),r.push(g),i+=w-b;}w<u.length&&r.push(sr(l,u.slice(w)));}if(i===0||e.to>o)return {ok:false,reason:`format range out of range: ${e.from}:${e.to}`};for(;t.firstChild;)t.removeChild(t.firstChild);for(let s of r)t.appendChild(s);return {ok:true}}function mv(t,e){var o;let n=Array.from(t.getElementsByTagNameNS(W_NS,"r"));if(e.op==="run"){if(e.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=ip(s),d=i,u=i+l.length;if(i=u,u<=e.from||d>=e.to)continue;if(e.from>d||e.to<u)return {ok:false,reason:"format revision currently requires whole runs"};let f=gv(s);kn(f,"rPrChange");let p=f.ownerDocument.createElementNS(W_NS,"w:rPrChange");p.setAttributeNS(W_NS,"w:id",e.revisionId),p.setAttributeNS(W_NS,"w:author","User"),p.setAttributeNS(W_NS,"w:date",new Date().toISOString());let b=f.ownerDocument.createElementNS(W_NS,"w:r");rl(b,(o=e.beforeFormat)!=null?o:{});let w=ce(b).find(g=>g.namespaceURI===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||e.to>i?{ok:false,reason:`format revision range not found: ${e.from}:${e.to}`}:{ok:true}}let r=0;for(let i of n){let a=ce(i).find(l=>l.namespaceURI===W_NS&&l.localName==="rPr"),s=a&&ce(a).find(l=>l.namespaceURI===W_NS&&l.localName==="rPrChange"&&l.getAttributeNS(W_NS,"id")===e.revisionId);if(!(!s||!a)){if(e.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: ${e.revisionId}`}}function ip(t){return Array.from(t.getElementsByTagNameNS(W_NS,"t")).concat(Array.from(t.getElementsByTagNameNS(W_NS,"delText"))).map(e=>{var n;return (n=e.textContent)!=null?n:""}).join("")}function gv(t){let e=ce(t).find(r=>r.namespaceURI===W_NS&&r.localName==="rPr");if(e)return e;let n=t.ownerDocument.createElementNS(W_NS,"w:rPr");return t.insertBefore(n,t.firstChild),n}function rl(t,e){var i,a,s;let n=t.ownerDocument,r=(i=ce(t).find(l=>l.namespaceURI===W_NS&&l.localName==="rPr"))!=null?i:null;r||(r=n.createElementNS(W_NS,"w:rPr"),t.insertBefore(r,t.firstChild));let o=[["bold","b"],["italic","i"],["strike","strike"],["doubleStrike","dstrike"],["caps","caps"],["smallCaps","smallCaps"]];for(let[l,d]of o)e[l]!==void 0&&(kn(r,d),e[l]&&r.appendChild(n.createElementNS(W_NS,`w:${d}`)));if(e.underline!==void 0&&(kn(r,"u"),e.underline)){let l=n.createElementNS(W_NS,"w:u");l.setAttribute("val","single"),r.appendChild(l);}if(e.color!==void 0&&(kn(r,"color"),e.color)){let l=n.createElementNS(W_NS,"w:color");l.setAttribute("val",e.color.replace(/^#/,"").toUpperCase()),r.appendChild(l);}if(e.highlight!==void 0||e.shading!==void 0){kn(r,"shd");let l=(s=(a=e.shading)==null?void 0:a.fill)!=null?s:e.highlight;if(l){let d=n.createElementNS(W_NS,"w:shd");d.setAttribute("val","clear"),d.setAttribute("fill",l.replace(/^#/,"").toUpperCase()),r.appendChild(d);}}if(e.fontSize!==void 0){kn(r,"sz");let l=n.createElementNS(W_NS,"w:sz");l.setAttribute("val",String(Math.round(e.fontSize*2))),r.appendChild(l);}if(e.characterScale!==void 0){kn(r,"w");let l=n.createElementNS(W_NS,"w:w");l.setAttributeNS(W_NS,"w:val",String(e.characterScale)),r.appendChild(l);}if(e.fontFamily!==void 0){kn(r,"rFonts");let l=n.createElementNS(W_NS,"w:rFonts");l.setAttribute("ascii",e.fontFamily),l.setAttribute("hAnsi",e.fontFamily),l.setAttribute("eastAsia",e.fontFamily),l.setAttribute("cs",e.fontFamily),r.appendChild(l);}}function kn(t,e){for(let n of ce(t))n.namespaceURI===W_NS&&n.localName===e&&t.removeChild(n);}function bv(t){for(let e=1;e<t.length;e+=1){let n=t[e-1],r=t[e];if((n==null?void 0:n.nodeType)!==1||(r==null?void 0:r.nodeType)!==1)continue;let o=n,i=r;if(!(o.namespaceURI!==W_NS||i.namespaceURI!==W_NS||o.localName!==i.localName||o.localName!=="ins"&&o.localName!=="del"||o.getAttributeNS(W_NS,"id")!==i.getAttributeNS(W_NS,"id"))){for(let a of Array.from(i.childNodes))o.appendChild(a);t.splice(e,1),e-=1;}}}function sr(t,e){let n=t.cloneNode(true),r=n.getElementsByTagNameNS(W_NS,"t")[0];return r&&(r.textContent=e),n}function wv(t){var r;let e=t.ownerDocument,n=Array.from(t.getElementsByTagNameNS(W_NS,"t"));for(let o of n){let i=e.createElementNS(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 xv(t){var r;let e=t.ownerDocument,n=Array.from(t.getElementsByTagNameNS(W_NS,"delText"));for(let o of n){let i=e.createElementNS(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 yv(t,e,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=ao(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}`};vv(t,e),Pv(n,r.from,r.to,r.commentId);let l=new Date().toISOString();return Ev(t,r.commentId,(a=r.body)!=null?a:"","User",l),r.parentCommentId!==void 0&&Cv(t,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=t.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(W_NS,"comment");for(let u=0;u<d.length;u+=1){let f=d[u];if((f==null?void 0:f.getAttributeNS(W_NS,"id"))!==String(r.commentId))continue;let p=f.getElementsByTagNameNS(W_NS,"t");if(p.length===0){let b=l.createElementNS(W_NS,"w:p"),w=l.createElementNS(W_NS,"w:r"),g=l.createElementNS(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 markDirty(s),{ok:true}}return {ok:false,reason:`comment not found: ${r.commentId}`}}Rv(t,r.commentId),Nv(t,r.commentId);let o=t.parts.get("word/comments.xml"),i=o==null?void 0:o.xmlDom;if(i){let s=i.getElementsByTagNameNS(W_NS,"comment");for(let l=0;l<s.length;l+=1){let d=s[l];(d==null?void 0:d.getAttributeNS(W_NS,"id"))===String(r.commentId)&&Ue(d);}markDirty(o);}return {ok:true}}function vv(t,e){var r,o;let n=t.parts.get("word/comments.xml");if(!(n!=null&&n.xmlDom)){let i=(r=Array.from(t.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(W_NS,"w:comments",null);if(!a)throw new Error("XML implementation cannot create comments.xml");n=createXmlPart({path:"word/comments.xml",contentType:Gf,xmlDom:a}),setPart(t,n),Sv(t);}return kv(t,e),n}function Sv(t){var i,a;let e=getPart(t,"[Content_Types].xml"),n=e==null?void 0:e.xmlDom;if(!e||!n)return;let r=n.getElementsByTagNameNS(Ri,"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(Ri,"Override");o.setAttribute("PartName","/word/comments.xml"),o.setAttribute("ContentType",Gf),(a=n.documentElement)==null||a.appendChild(o),markDirty(e);}function kv(t,e){var d,u,f;let n=Ai(e),r=t.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),markDirty(r);}function Ev(t,e,n,r,o){let i=t.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(W_NS,"comment")).some(p=>p.getAttributeNS(W_NS,"id")===String(e)))return;let l=a.createElementNS(W_NS,"w:comment");l.setAttributeNS(W_NS,"w:id",String(e)),l.setAttributeNS(W_NS,"w:author",r),l.setAttributeNS(W_NS,"w:date",o),l.setAttributeNS(W_NS,"w:initials",r.slice(0,1));let d=a.createElementNS(W_NS,"w:p");d.setAttributeNS(W14_NS,"w14:paraId",Iv(e));let u=a.createElementNS(W_NS,"w:r"),f=a.createElementNS(W_NS,"w:t");f.textContent=n,En(f),u.appendChild(f),d.appendChild(u),l.appendChild(d),s.appendChild(l),markDirty(i);}function Cv(t,e,n){let r=t.parts.get("word/comments.xml"),o=r==null?void 0:r.xmlDom;if(!o)return;let i=b=>{var g,h,x;let w=o.getElementsByTagNameNS(W_NS,"comment");for(let S=0;S<w.length;S+=1){if(((g=w[S])==null?void 0:g.getAttributeNS(W_NS,"id"))!==String(b))continue;let k=(h=w[S])==null?void 0:h.getElementsByTagNameNS(W_NS,"p")[0];return (x=k==null?void 0:k.getAttributeNS(W14_NS,"paraId"))!=null?x:null}return null},a=i(e),s=i(n);if(!a||!s)return;let l=Tv(t,"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),markDirty(l);}function Iv(t){return t.toString(16).padStart(8,"0").slice(-8)}function Nv(t,e){var d,u,f,p;let n=t.parts.get("word/comments.xml"),r=n==null?void 0:n.xmlDom,o=t.parts.get("word/commentsExtended.xml"),i=o==null?void 0:o.xmlDom;if(!r||!i)return;let a=r.getElementsByTagNameNS(W_NS,"comment"),s=null;for(let b=0;b<a.length;b+=1)if(((d=a[b])==null?void 0:d.getAttributeNS(W_NS,"id"))===String(e)){s=(p=(f=(u=a[b])==null?void 0:u.getElementsByTagNameNS(W_NS,"p")[0])==null?void 0:f.getAttributeNS(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),markDirty(o));}function Tv(t,e){var a,s,l,d,u,f;let n=t.parts.get("word/commentsExtended.xml");if(!(n!=null&&n.xmlDom)){let p=(l=(a=t.parts.get(e))==null?void 0:a.xmlDom)!=null?l:(s=Array.from(t.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=createXmlPart({path:"word/commentsExtended.xml",contentType:Wf,xmlDom:b}),setPart(t,n);}let r=getPart(t,"[Content_Types].xml");if(r!=null&&r.xmlDom){let p=r.xmlDom.getElementsByTagNameNS(Ri,"Override");if(!Array.from(p).some(b=>b.getAttribute("PartName")==="/word/commentsExtended.xml")){let b=r.xmlDom.createElementNS(Ri,"Override");b.setAttribute("PartName","/word/commentsExtended.xml"),b.setAttribute("ContentType",Wf),(u=r.xmlDom.documentElement)==null||u.appendChild(b),markDirty(r);}}let o=t.parts.get(Ai(e)),i=o==null?void 0:o.xmlDom;if(i&&!Array.from(i.getElementsByTagNameNS(Gt,"Relationship")).some(p=>p.getAttribute("Type")===Bf)){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",Bf),g.setAttribute("Target","commentsExtended.xml"),(f=i.documentElement)==null||f.appendChild(g),markDirty(o);}return n}function Pv(t,e,n,r){let o=t.ownerDocument,i=o.createElementNS(W_NS,"w:commentRangeStart");i.setAttributeNS(W_NS,"w:id",String(r));let a=o.createElementNS(W_NS,"w:commentRangeEnd");a.setAttributeNS(W_NS,"w:id",String(r));let s=o.createElementNS(W_NS,"w:r"),l=o.createElementNS(W_NS,"w:commentReference");l.setAttributeNS(W_NS,"w:id",String(r)),s.appendChild(l);let d=new Map;d.set(e,[i]),d.set(n,[a,s]);let u=ce(t).filter(b=>!(b.namespaceURI===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=[e,n].filter(S=>S>p&&S<p+g).sort((S,k)=>S-k),x=0;for(let S of [...h,p+g]){let k=ar(b,x,S-p);k&&f.push(k);let I=S,D=d.get(I);D&&f.push(...D),x=S-p;}g===0&&f.push(b),p+=g;}for(let b of [e,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)t.appendChild(b);}function Rv(t,e){for(let n of t.parts.values()){let r=n.xmlDom;if(r)for(let o of ["commentRangeStart","commentRangeEnd","commentReference"]){let i=r.getElementsByTagNameNS(W_NS,o),a=[];for(let s=0;s<i.length;s+=1){let l=i[s];(l==null?void 0:l.getAttributeNS(W_NS,"id"))===String(e)&&a.push(l);}for(let s of a){let l=s.parentNode;o==="commentReference"&&(l==null?void 0:l.nodeType)===1&&l.namespaceURI===W_NS&&l.localName==="r"?Ue(l):Ue(s);}a.length>0&&markDirty(n);}}}function Mv(t){for(let e=0;e<t.childNodes.length;e++){let n=t.childNodes[e];if(!n||n.nodeType!==1)continue;let r=n;if(!(r.namespaceURI===W_NS&&(r.localName==="rPr"||r.localName==="drawing")))return false}return true}function Av(t){return t.nodeType===1}var Zt=new 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:t=>["p",Dv(t.attrs),0]},table:{group:"block",content:"table_row+",attrs:{tableId:{default:""},columnWidths:{default:null}},tableRole:"table",toDOM:t=>["div",{class:"coco-word-table-scroll"},["table",Wv(t.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:t=>["td",Bv(t.attrs),0]},image:{inline:true,group:"inline",atom:true,attrs:{src:{},alt:{default:""},width:{default:null},height:{default:null},drawingId:{default:null}},toDOM:t=>["img",Fv(t.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:t=>["span",Ov(t.attrs),0]}}});new PluginKey("coco-word-decorations");var sp=new PluginKey("coco-word-structure-normalization");function Dv(t){let e={};typeof t.paraId=="string"&&t.paraId.length>0&&(e["data-para-id"]=t.paraId),typeof t.story=="string"&&t.story.length>0&&(e["data-story"]=t.story),typeof t.styleId=="string"&&t.styleId.length>0&&(e["data-style-id"]=t.styleId);let n=$v(t.format)?t.format:null;(n==null?void 0:n.outlineLevel)!==void 0&&(e["data-outline-level"]=String(n.outlineLevel));let r=zv(n);return r.length>0&&(e.style=r),e}function Wv(t){let e={};return typeof t.tableId=="string"&&t.tableId.length>0&&(e["data-table-id"]=t.tableId),e}function Bv(t){let e={};typeof t.colspan=="number"&&t.colspan>1&&(e.colspan=String(t.colspan)),typeof t.rowspan=="number"&&t.rowspan>1&&(e.rowspan=String(t.rowspan));let n=[];if(typeof t.width=="number"&&t.width>0&&n.push(`width: ${Gn(t.width)}`),Hv(t.shading)){let r=al(t.shading.fill);r&&n.push(`background-color: ${r}`);}return typeof t.verticalAlignment=="string"&&n.push(`vertical-align: ${t.verticalAlignment==="center"?"middle":t.verticalAlignment}`),n.length>0&&(e.style=n.join("; ")),e}function Fv(t){let e={src:typeof t.src=="string"?t.src:"",alt:typeof t.alt=="string"?t.alt:""};typeof t.drawingId=="string"&&(e["data-drawing-id"]=t.drawingId);let n=[];return typeof t.width=="number"&&t.width>0&&n.push(`width: ${t.width}px`),typeof t.height=="number"&&t.height>0&&n.push(`height: ${t.height}px`),n.length>0&&(e.style=n.join("; ")),e}function Hv(t){return t!==null&&typeof t=="object"}function Ov(t){let e=[],n=typeof t.color=="string"?al(t.color):null;return n&&e.push(`color: ${n}`),typeof t.fontSize=="number"&&e.push(`font-size: ${t.fontSize}pt`),e.length>0?{style:e.join("; ")}:{}}function $v(t){return t!==null&&typeof t=="object"}function zv(t){var o,i,a,s,l,d,u,f,p;if(!t)return "";let e=[];t.alignment&&e.push(`text-align: ${Vv(t.alignment)}`),((o=t.indent)==null?void 0:o.left)!==void 0&&e.push(`margin-left: ${Gn(t.indent.left)}`),((i=t.indent)==null?void 0:i.right)!==void 0&&e.push(`margin-right: ${Gn(t.indent.right)}`),((a=t.indent)==null?void 0:a.firstLine)!==void 0&&e.push(`text-indent: ${Gn(t.indent.firstLine)}`),((s=t.spacing)==null?void 0:s.before)!==void 0&&e.push(`margin-top: ${Gn(t.spacing.before)}`),((l=t.spacing)==null?void 0:l.after)!==void 0&&e.push(`margin-bottom: ${Gn(t.spacing.after)}`);let n=jv((d=t.spacing)==null?void 0:d.line,(u=t.spacing)==null?void 0:u.lineRule);n&&e.push(`line-height: ${n}`),t.fontSize!==void 0&&e.push(`font-size: ${t.fontSize}pt`),t.bold!==void 0&&e.push(`font-weight: ${t.bold?"700":"400"}`);let r=Gv(t.borderBottom);return r&&(e.push(`border-bottom: ${r}`),e.push(`padding-bottom: ${(p=(f=t.borderBottom)==null?void 0:f.space)!=null?p:4}pt`)),e.join("; ")}function Vv(t){return t==="both"||t==="distribute"?"justify":t}function Gv(t){var o;if(!t||t.val==="none"||t.val==="nil")return null;let e=(o=al(t.color))!=null?o:"#000000",n=t.size!==void 0?Math.max(.75,t.size/8):.75,r=t.val==="double"?"double":"solid";return `${n}pt ${r} ${e}`}function jv(t,e){return t===void 0?null:e==="exact"||e==="atLeast"?Gn(t):String(t/240)}function Gn(t){return `${t/20}pt`}function al(t){return !t||t==="auto"?null:/^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}var lo=new PluginKey("coco-word-editing"),_v=0;function sN(t={}){return new Plugin({key:lo,appendTransaction(e,n,r){if(!e.some(a=>a.docChanged)||e.every(a=>a.getMeta(sp)))return null;let o=Xv(n.doc,r.doc),i=o.length>0?o:Qv(n.doc,r.doc);return i.length>0?pp(r.tr,i):null},state:{init:()=>({changes:[]}),apply(e,n){var i,a;let r=e.getMeta(lo);if(!((i=r==null?void 0:r.changes)!=null&&i.length))return n;let o={changes:[...n.changes,...r.changes]};return (a=t.onChangeSet)==null||a.call(t,o),o}}})}function lN(t){var e;return (e=lo.getState(t))!=null?e:{changes:[]}}function dN(t){var s,l;let{from:e,to:n,empty:r}=t.selection,o=t.selection.$from,i=oS(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:e,to:n,empty:r,selectedText:t.doc.textBetween(e,n,`
|
|
20
|
+
`),paragraphs:dl(t,e,n),tableCell:a}}function cN(t,e,n){let r=Zt.marks.strong;return ll(t,e,n,r,{},"strong")}function uN(t){return (e,n,r)=>!Number.isFinite(t)||t<=0?false:ll(e,n,r,Zt.marks.textStyle,{fontSize:t},"textStyle")}function fN(t){return (e,n,r)=>{let o=rS(t);return o?ll(e,n,r,Zt.marks.textStyle,{color:o},"textStyle"):false}}function pN(t){return (e,n)=>{let r=dl(e,e.selection.from,e.selection.to);if(r.length===0)return false;if(!n)return true;let o=e.tr;return e.doc.nodesBetween(e.selection.from,e.selection.to,(i,a)=>{if(i.type!==Zt.nodes.paragraph)return true;let s=nS(i.attrs.format,{alignment:t});return o=o.setNodeMarkup(a,void 0,H(v({},i.attrs),{format:s})),false}),o=fp(o,{kind:"paragraph",from:e.selection.from,to:e.selection.to,paragraphs:r,target:Li(r),status:"captured",attr:"alignment",value:t}),n(o.scrollIntoView()),true}}function ll(t,e,n,r,o,i){let{from:a,to:s,empty:l}=t.selection;if(l)return false;let d=dl(t,a,s);if(d.length===0)return false;let u=i==="strong"&&qv(t.doc,a,s,r);if(!e)return true;let f=t.tr;return u?f=f.removeMark(a,s,r):f=f.addMark(a,s,r.create(o)),f=fp(f,{kind:"mark",from:a,to:s,paragraphs:d,target:Li(d),status:"captured",mark:i,value:i==="strong"?!u:o}),e(f.scrollIntoView()),n==null||n.focus(),true}function dl(t,e,n){let r=[],o=Math.max(n,e+1);return t.doc.nodesBetween(e,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(e,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 Li(t){var n;let e=t[0];return v({story:(n=e==null?void 0:e.story)!=null?n:"body"},e!=null&&e.paraId?{paraId:e.paraId}:{})}function qv(t,e,n,r){let o=false;return t.nodesBetween(e,n,i=>(o||!i.isText||(o=r.isInSet(i.marks)!==void 0),!o)),o}function fp(t,e){return pp(t,[e])}function pp(t,e){var o,i;let n=(o=t.getMeta(lo))!=null?o:{},r=(i=n.changes)!=null?i:[];return t.setMeta(lo,H(v({},n),{changes:[...r,...e.map(a=>H(v({},a),{id:`word-edit:${++_v}`,createdAt:Date.now()}))]}))}function Xv(t,e){let n=dp(t),r=dp(e),o=Yv(n,r);if(o)return [o];let i=Zv(n,r);if(i)return [i];let a=Jv(n,r);return a?[a]:[]}function Yv(t,e){if(e.length!==t.length+1)return null;for(let n=0;n<t.length;n+=1){if(!Di(t.slice(0,n),e.slice(0,n))||!Di(t.slice(n+1),e.slice(n+2)))continue;let r=t[n],o=e[n],i=e[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:cl([o,i]),target:ul(r.block),status:"captured",blocks:[o.block,i.block],deletedBlocks:[r.block],value:{before:r.block,after:[o.block,i.block]}}}return null}function Zv(t,e){if(t.length!==e.length+1)return null;for(let n=0;n<e.length;n+=1){if(!Di(t.slice(0,n),e.slice(0,n))||!Di(t.slice(n+2),e.slice(n+1)))continue;let r=t[n],o=t[n+1],i=e[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:cl([i]),target:ul(i.block),status:"captured",blocks:[i.block],deletedBlocks:[r.block,o.block],value:{before:[r.block,o.block],after:i.block}}}return null}function Jv(t,e){var f,p,b,w,g;let n=0,r=Math.min(t.length,e.length);for(;n<r&&sl(t[n],e[n]);)n+=1;let o=0,i=Math.min(t.length-n,e.length-n);for(;o<i&&sl(t[t.length-1-o],e[e.length-1-o]);)o+=1;let a=t.slice(n,t.length-o),s=e.slice(n,e.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:cl(s.length>0?s:a),target:l?ul(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 Qv(t,e){let n=lp(t),r=lp(e),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||mp(s.content,a.content))continue;let l=tS(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(cp(l.insertedContent)&&cp(l.deletedContent)){i.push({kind:"text",from:d,to:u,paragraphs:[f],target:Li([f]),status:"captured",textOp:l.operation,text:up(l.insertedContent),deletedText:up(l.deletedContent),value:{operation:l.operation,before:s.text,after:a.text}});continue}i.push({kind:"content",from:d,to:u,paragraphs:[f],target:Li([f]),status:"captured",contentOp:l.operation,content:so(l.insertedContent),deletedContent:so(l.deletedContent),value:{operation:l.operation,before:so(s.content.map(p=>p.content)),after:so(a.content.map(p=>p.content))}});}return i}function lp(t){let e=[];return t.descendants((n,r)=>n.type!==Zt.nodes.paragraph?true:(e.push({paraId:typeof n.attrs.paraId=="string"?n.attrs.paraId:"",pos:r,text:n.textContent,content:hp(n),styleId:typeof n.attrs.styleId=="string"?n.attrs.styleId:null,story:typeof n.attrs.story=="string"?n.attrs.story:"body"}),false)),e}function dp(t){let e=[];return t.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:so(hp(n).map(l=>l.content))};e.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};e.push({key:`table:${i||o}`,pos:r,size:n.nodeSize,block:a});}}),e}function Di(t,e){return t.length===e.length&&t.every((n,r)=>sl(n,e[r]))}function sl(t,e){return t.key===e.key}function cl(t){return t.flatMap(e=>e.block.kind!=="paragraph"?[]:[{paraId:e.block.paraId,from:0,to:e.block.text.length,text:e.block.text,styleId:e.block.styleId,story:e.block.story}])}function ul(t){return t.kind==="table"?v({story:"body"},t.tableId?{tableId:t.tableId}:{}):v({story:t.story},t.paraId?{paraId:t.paraId}:{})}function hp(t){let e=[];return t.forEach(n=>{var r,o;if(n.isText){for(let i of (r=n.text)!=null?r:"")e.push({key:`text:${i}`,content:{kind:"text",text:i}});return}if(n.type===Zt.nodes.image){let i=eS(n);e.push({key:`image:${(o=i.drawingId)!=null?o:i.src}`,content:i});return}e.push({key:`${n.type.name}:${JSON.stringify(n.attrs)}`,content:{kind:"text",text:n.textContent}});}),e}function eS(t){return {kind:"image",drawingId:typeof t.attrs.drawingId=="string"?t.attrs.drawingId:null,alt:typeof t.attrs.alt=="string"?t.attrs.alt:"",src:typeof t.attrs.src=="string"?t.attrs.src:"",width:typeof t.attrs.width=="number"?t.attrs.width:null,height:typeof t.attrs.height=="number"?t.attrs.height:null}}function tS(t,e){var f,p,b,w;if(mp(t,e))return null;let n=0,r=Math.min(t.length,e.length);for(;n<r&&((f=t[n])==null?void 0:f.key)===((p=e[n])==null?void 0:p.key);)n+=1;let o=0,i=Math.min(t.length-n,e.length-n);for(;o<i&&((b=t[t.length-1-o])==null?void 0:b.key)===((w=e[e.length-1-o])==null?void 0:w.key);)o+=1;let a=t.length-o,s=e.length-o,l=e.slice(n,s).map(g=>g.content),d=t.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 mp(t,e){return t.length===e.length&&t.every((n,r)=>{var o;return n.key===((o=e[r])==null?void 0:o.key)})}function cp(t){return t.every(e=>e.kind==="text")}function up(t){return t.map(e=>e.kind==="text"?e.text:"").join("")}function so(t){let e=[];for(let n of t){let r=e[e.length-1];n.kind==="text"&&(r==null?void 0:r.kind)==="text"?r.text+=n.text:e.push(v({},n));}return e}function nS(t,e){return v(v({},t!==null&&typeof t=="object"?t:{}),e)}function rS(t){let e=t.trim().replace(/^#/,"");return /^[0-9a-f]{6}$/i.test(e)?e.toUpperCase():null}function oS(t,e){for(let n=t.depth;n>0;n-=1)if(t.node(n).type.name===e)return n;return null}var gp=`.coco-word-editor {
|
|
21
21
|
background: #f4f5f7;
|
|
22
22
|
color: #202124;
|
|
23
23
|
font-family:
|
|
@@ -282,8 +282,7 @@ coco-word-native-page {
|
|
|
282
282
|
box-sizing: border-box;
|
|
283
283
|
max-width: 100%;
|
|
284
284
|
background: #ffffff;
|
|
285
|
-
|
|
286
|
-
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
|
|
285
|
+
box-shadow: 0 0 0 1px #d8dbe2, 0 10px 24px rgba(15, 23, 42, 0.08);
|
|
287
286
|
}
|
|
288
287
|
|
|
289
288
|
coco-word-native-page-body {
|
|
@@ -308,6 +307,22 @@ coco-word-native-document.uses-natural-paragraph-flow coco-word-native-page-body
|
|
|
308
307
|
display: block;
|
|
309
308
|
}
|
|
310
309
|
|
|
310
|
+
coco-word-native-page[data-vertical-alignment] > coco-word-native-page-body {
|
|
311
|
+
display: flex;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
coco-word-native-page[data-vertical-alignment="center"] > coco-word-native-page-body {
|
|
315
|
+
justify-content: safe center;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
coco-word-native-page[data-vertical-alignment="bottom"] > coco-word-native-page-body {
|
|
319
|
+
justify-content: safe end;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
coco-word-native-page[data-vertical-alignment="both"] > coco-word-native-page-body {
|
|
323
|
+
justify-content: space-between;
|
|
324
|
+
}
|
|
325
|
+
|
|
311
326
|
.coco-word-native-page-behind-layer,
|
|
312
327
|
.coco-word-native-page-overlay {
|
|
313
328
|
position: absolute;
|
|
@@ -1584,32 +1599,32 @@ coco-word-native-table.coco-word-revision-delete {
|
|
|
1584
1599
|
.coco-word-dialog-button:hover {
|
|
1585
1600
|
filter: brightness(0.96);
|
|
1586
1601
|
}
|
|
1587
|
-
`;function yp(t,e){var a,s,l,d,u,p,f,b,w;let n=iS(t,e),r=kp(t,e),o=vp(t,e),i=co(t,e);return {selectionKind:(a=e==null?void 0:e.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=>uo(g.color)),null),highlightColor:Ye(n.map(g=>dS(g.highlight)),null),hyperlink:Sp(t,e),paragraphAlignment:Ye(r.map(g=>{var h;return xp((h=g.format)==null?void 0:h.alignment)}),null),leftIndent:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.indent)==null?void 0:x.left)!=null?S:0}),0),rightIndent:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.indent)==null?void 0:x.right)!=null?S:0}),0),firstLineIndent:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.indent)==null?void 0:x.firstLine)!=null?S:0}),0),spacingBefore:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.spacing)==null?void 0:x.before)!=null?S:0}),0),spacingAfter:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.spacing)==null?void 0:x.after)!=null?S:0}),0),lineSpacing:Ep(r.map(g=>{var x,S,k,I,D;let h=(S=(x=g.format)==null?void 0:x.spacing)==null?void 0:S.line;return h===void 0?null:{line:h,lineRule:(D=(I=(k=g.format)==null?void 0:k.spacing)==null?void 0:I.lineRule)!=null?D:"auto"}})),listType:Ye(r.map(g=>{var h;return (h=g.format)!=null&&h.hasNumbering?mn(g.format.numbering):null}),null),listLevel:Ye(r.map(g=>{var h,x,S;return (h=g.format)!=null&&h.hasNumbering?(S=(x=g.format.numbering)==null?void 0:x.ilvl)!=null?S:0:null}),null),image:o&&(e==null?void 0:e.kind)==="object"?{objectId:o.drawingId,width:(p=o.width)!=null?p:null,height:(f=o.height)!=null?f:null,alignment:xp((w=(b=r[0])==null?void 0:b.format)==null?void 0:w.alignment)}:null,table:i}}function Dt(t,e,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(!e)return false;if(n.kind==="insert-image")return (e.kind==="caret"||e.kind==="text-range")&&n.src.trim().length>0;if(n.kind==="insert-table")return e.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(t,e.paraId))==null?void 0:r.container)===t.blocks;if(n.kind==="delete-table"){let d=co(t,e);return !!d&&((o=Oe(t,d.tableId))==null?void 0:o.container)===t.blocks}if(n.kind==="set-image-size"||n.kind==="set-image-alignment")return e.kind==="object"&&e.objectKind==="image"&&e.objectId===n.objectId&&!!vp(t,e);if(n.kind==="insert-table-row"||n.kind==="delete-table-row"||n.kind==="insert-table-column"||n.kind==="delete-table-column"){let d=co(t,e);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 co(t,e)!==null;if(n.kind==="merge-table-cells"||n.kind==="split-table-cell"){if(e.kind!=="table-cell-range")return false;let d=Oe(t,e.tableId);if(!d)return false;let u=tt(d.table,e);if(n.kind==="merge-table-cells")return Gr(d.table)?e.anchor.rowIndex===e.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"?e.kind==="table-cell-range"&&co(t,e)!==null:n.kind==="set-hyperlink"?e.kind==="text-range"&&!!((s=n.hyperlink.target)!=null&&s.trim()||(l=n.hyperlink.anchor)!=null&&l.trim()):n.kind==="remove-hyperlink"?e.kind==="text-range"&&Sp(t,e)!==null:n.kind==="insert-text"||n.kind==="split-paragraph"||n.kind==="insert-page-break"?e.kind==="caret"&&!!J(t,e.paraId):n.kind==="delete-object"?e.kind==="object"&&e.objectKind===n.objectKind:n.kind==="replace-range"||n.kind==="delete-range"?n.anchor.paraId===n.focus.paraId&&!!J(t,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"?e.kind==="text-range"&&Bi(t,e).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"?kp(t,e).length>0:n.kind==="delete-backward"?e.kind==="caret"||e.kind==="object"||e.kind==="table-cell-range":n.kind==="delete-forward"&&(e.kind==="caret"||e.kind==="table-cell-range")}function co(t,e){var o,i,a,s;if(!e)return null;if(e.kind==="table-cell-range"){let l=Oe(t,e.tableId);if(!l)return null;let d=tt(l.table,e);if(d.length===0)return null;let u=Math.min(e.anchor.rowIndex,e.focus.rowIndex),p=Math.max(e.anchor.rowIndex,e.focus.rowIndex),f=Math.min(e.anchor.columnIndex,e.focus.columnIndex),b=Math.max(e.anchor.columnIndex,e.focus.columnIndex);return {tableId:l.table.tableId,rowIndex:e.anchor.rowIndex,rowCount:l.table.rows.length,columnIndex:e.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:Gr(l.table),backgroundColor:Ye(d.map(({cell:w})=>{var g;return uo((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})=>bp(w.borders)),null),bordersVisible:Ye(d.map(({cell:w})=>wp(w.borders)),false)}}let n=e.kind==="text-range"?e.anchor.paraId:e.paraId,r=rn(t,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:Gr(r.table),backgroundColor:uo((a=r.cell.shading)==null?void 0:a.fill),verticalAlignment:(s=r.cell.verticalAlignment)!=null?s:null,borderColor:bp(r.cell.borders),bordersVisible:wp(r.cell.borders)}:null}function bp(t){let e=[t==null?void 0:t.top,t==null?void 0:t.right,t==null?void 0:t.bottom,t==null?void 0:t.left].find(n=>n&&n.val!=="nil"&&n.val!=="none");return uo(e==null?void 0:e.color)}function wp(t){return [t==null?void 0:t.top,t==null?void 0:t.right,t==null?void 0:t.bottom,t==null?void 0:t.left].some(e=>!!e&&e.val!=="nil"&&e.val!=="none")}function vp(t,e){var r;if((e==null?void 0:e.kind)!=="object"||e.objectKind!=="image")return null;let n=J(t,e.paraId);return (r=n==null?void 0:n.content.find(o=>o.kind==="image"&&o.drawingId===e.objectId))!=null?r:null}function iS(t,e){if(!e||e.kind==="object"||e.kind==="table-cell-range")return [];if(e.kind==="caret"){let n=J(t,e.paraId);if(!n)return [];let r=sS(t,n,e.offset);return r?[r]:[]}return Bi(t,e).flatMap(n=>aS(t,n))}function Sp(t,e){var r,o,i,a,s;if(!e||e.kind==="object"||e.kind==="table-cell-range")return null;if(e.kind==="caret"){let l=J(t,e.paraId);if(!l)return null;let d=0,u=null;for(let p of l.content){let f=Wi(p);if(p.kind==="text"){if(e.offset>d&&e.offset<=d+f)return (r=p.hyperlink)!=null?r:null;if(e.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=Bi(t,e).flatMap(l=>{var f;let d=J(t,l.paraId);if(!d)return [];let u=[],p=0;for(let b of d.content){let w=Wi(b);b.kind==="text"&&p+w>l.from&&p<l.to&&u.push((f=b.hyperlink)!=null?f:null),p+=w;}return u});return Ep(n)}function aS(t,e){let n=J(t,e.paraId);if(!n)return [];let r=[],o=0;for(let i of n.content){let a=Wi(i);i.kind==="text"&&o+a>e.from&&o<e.to&&r.push(fl(t,n,i.format)),o+=a;}return r}function sS(t,e,n){let r=0,o=null;for(let i of e.content){let a=Wi(i);if(i.kind==="text"){let s=fl(t,e,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:fl(t,e,null)}function fl(t,e,n){var o,i;let r=e.format;return v(v(v({},(i=(o=t.defaults)==null?void 0:o.run)!=null?i:{}),r!=null?r:{}),n!=null?n:{})}function kp(t,e){var n;if(!e)return [];if(e.kind==="table-cell-range"){let r=(n=Oe(t,e.tableId))==null?void 0:n.table;return r?tt(r,e).flatMap(({cell:o})=>o.paragraphs):[]}if(e.kind==="caret"||e.kind==="object"){let r=J(t,e.paraId);return r?[r]:[]}return Bi(t,e).map(r=>J(t,r.paraId)).filter(r=>r!==null)}function Bi(t,e){let n=lS(t,e);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(t,n.anchor.paraId),o=ve(t,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 lS(t,e){if(e.anchor.paraId===e.focus.paraId)return e.anchor.offset<=e.focus.offset?{anchor:e.anchor,focus:e.focus}:{anchor:e.focus,focus:e.anchor};let n=ve(t,e.anchor.paraId),r=ve(t,e.focus.paraId);return !n||!r||n.container!==r.container?null:n.index<r.index?{anchor:e.anchor,focus:e.focus}:{anchor:e.focus,focus:e.anchor}}function Wi(t){var e;return t.kind==="text"?t.text.length:t.kind==="field"?((e=t.cachedText)!=null?e:"\uFFFC").length:t.kind==="drawing"&&t.text?t.text.length:1}function Ye(t,e){return t.length===0?e:t.every(n=>n===t[0])?t[0]:"mixed"}function Ep(t){var n;if(t.length===0||t.every(r=>r===null))return null;let e=JSON.stringify(t[0]);return t.every(r=>JSON.stringify(r)===e)?(n=t[0])!=null?n:null:"mixed"}function uo(t){if(!t||t.toLowerCase()==="auto")return null;let e=t.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(e)?`#${e}`:t}function dS(t){var e;return !t||t.toLowerCase()==="none"?null:(e=uo(t))!=null?e:t}function xp(t){return t==="center"||t==="right"||t==="both"?t:t==="distribute"?"both":"left"}function Cp(t,e,n){let r=0;for(;r<t.length&&r<e.length&&t[r]===e[r];)r+=1;return {revision:n,changes:e.slice(r),revertedChanges:t.slice(r),totalChangeCount:e.length}}var fo=new WeakMap,pl="application/x-coco-word-table-cells+json",po="application/x-coco-word-image",Rp="coco-image:",ho=new Map,hl=0,cS=0,ml=0,gl=0;function LN(t,e,n={}){var Gd,jd,Ud;$u();let r=t,o=null;if(n.styleIsolation!=="none"){r.replaceChildren(),o=(Gd=r.shadowRoot)!=null?Gd:r.attachShadow({mode:"open"}),o.replaceChildren();let c=r.ownerDocument.createElement("style");c.textContent=`
|
|
1602
|
+
`;function yp(t,e){var a,s,l,d,u,f,p,b,w;let n=iS(t,e),r=kp(t,e),o=vp(t,e),i=co(t,e);return {selectionKind:(a=e==null?void 0:e.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=>uo(g.color)),null),highlightColor:Ye(n.map(g=>dS(g.highlight)),null),hyperlink:Sp(t,e),paragraphAlignment:Ye(r.map(g=>{var h;return xp((h=g.format)==null?void 0:h.alignment)}),null),leftIndent:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.indent)==null?void 0:x.left)!=null?S:0}),0),rightIndent:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.indent)==null?void 0:x.right)!=null?S:0}),0),firstLineIndent:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.indent)==null?void 0:x.firstLine)!=null?S:0}),0),spacingBefore:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.spacing)==null?void 0:x.before)!=null?S:0}),0),spacingAfter:Ye(r.map(g=>{var h,x,S;return (S=(x=(h=g.format)==null?void 0:h.spacing)==null?void 0:x.after)!=null?S:0}),0),lineSpacing:Ep(r.map(g=>{var x,S,k,I,D;let h=(S=(x=g.format)==null?void 0:x.spacing)==null?void 0:S.line;return h===void 0?null:{line:h,lineRule:(D=(I=(k=g.format)==null?void 0:k.spacing)==null?void 0:I.lineRule)!=null?D:"auto"}})),listType:Ye(r.map(g=>{var h;return (h=g.format)!=null&&h.hasNumbering?mn(g.format.numbering):null}),null),listLevel:Ye(r.map(g=>{var h,x,S;return (h=g.format)!=null&&h.hasNumbering?(S=(x=g.format.numbering)==null?void 0:x.ilvl)!=null?S:0:null}),null),image:o&&(e==null?void 0:e.kind)==="object"?{objectId:o.drawingId,width:(f=o.width)!=null?f:null,height:(p=o.height)!=null?p:null,alignment:xp((w=(b=r[0])==null?void 0:b.format)==null?void 0:w.alignment)}:null,table:i}}function Dt(t,e,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(!e)return false;if(n.kind==="insert-image")return (e.kind==="caret"||e.kind==="text-range")&&n.src.trim().length>0;if(n.kind==="insert-table")return e.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(t,e.paraId))==null?void 0:r.container)===t.blocks;if(n.kind==="delete-table"){let d=co(t,e);return !!d&&((o=Oe(t,d.tableId))==null?void 0:o.container)===t.blocks}if(n.kind==="set-image-size"||n.kind==="set-image-alignment")return e.kind==="object"&&e.objectKind==="image"&&e.objectId===n.objectId&&!!vp(t,e);if(n.kind==="insert-table-row"||n.kind==="delete-table-row"||n.kind==="insert-table-column"||n.kind==="delete-table-column"){let d=co(t,e);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 co(t,e)!==null;if(n.kind==="merge-table-cells"||n.kind==="split-table-cell"){if(e.kind!=="table-cell-range")return false;let d=Oe(t,e.tableId);if(!d)return false;let u=tt(d.table,e);if(n.kind==="merge-table-cells")return Gr(d.table)?e.anchor.rowIndex===e.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"?e.kind==="table-cell-range"&&co(t,e)!==null:n.kind==="set-hyperlink"?e.kind==="text-range"&&!!((s=n.hyperlink.target)!=null&&s.trim()||(l=n.hyperlink.anchor)!=null&&l.trim()):n.kind==="remove-hyperlink"?e.kind==="text-range"&&Sp(t,e)!==null:n.kind==="insert-text"||n.kind==="split-paragraph"||n.kind==="insert-page-break"?e.kind==="caret"&&!!J(t,e.paraId):n.kind==="delete-object"?e.kind==="object"&&e.objectKind===n.objectKind:n.kind==="replace-range"||n.kind==="delete-range"?n.anchor.paraId===n.focus.paraId&&!!J(t,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"?e.kind==="text-range"&&Bi(t,e).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"?kp(t,e).length>0:n.kind==="delete-backward"?e.kind==="caret"||e.kind==="object"||e.kind==="table-cell-range":n.kind==="delete-forward"&&(e.kind==="caret"||e.kind==="table-cell-range")}function co(t,e){var o,i,a,s;if(!e)return null;if(e.kind==="table-cell-range"){let l=Oe(t,e.tableId);if(!l)return null;let d=tt(l.table,e);if(d.length===0)return null;let u=Math.min(e.anchor.rowIndex,e.focus.rowIndex),f=Math.max(e.anchor.rowIndex,e.focus.rowIndex),p=Math.min(e.anchor.columnIndex,e.focus.columnIndex),b=Math.max(e.anchor.columnIndex,e.focus.columnIndex);return {tableId:l.table.tableId,rowIndex:e.anchor.rowIndex,rowCount:l.table.rows.length,columnIndex:e.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:Gr(l.table),backgroundColor:Ye(d.map(({cell:w})=>{var g;return uo((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})=>bp(w.borders)),null),bordersVisible:Ye(d.map(({cell:w})=>wp(w.borders)),false)}}let n=e.kind==="text-range"?e.anchor.paraId:e.paraId,r=rn(t,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:Gr(r.table),backgroundColor:uo((a=r.cell.shading)==null?void 0:a.fill),verticalAlignment:(s=r.cell.verticalAlignment)!=null?s:null,borderColor:bp(r.cell.borders),bordersVisible:wp(r.cell.borders)}:null}function bp(t){let e=[t==null?void 0:t.top,t==null?void 0:t.right,t==null?void 0:t.bottom,t==null?void 0:t.left].find(n=>n&&n.val!=="nil"&&n.val!=="none");return uo(e==null?void 0:e.color)}function wp(t){return [t==null?void 0:t.top,t==null?void 0:t.right,t==null?void 0:t.bottom,t==null?void 0:t.left].some(e=>!!e&&e.val!=="nil"&&e.val!=="none")}function vp(t,e){var r;if((e==null?void 0:e.kind)!=="object"||e.objectKind!=="image")return null;let n=J(t,e.paraId);return (r=n==null?void 0:n.content.find(o=>o.kind==="image"&&o.drawingId===e.objectId))!=null?r:null}function iS(t,e){if(!e||e.kind==="object"||e.kind==="table-cell-range")return [];if(e.kind==="caret"){let n=J(t,e.paraId);if(!n)return [];let r=sS(t,n,e.offset);return r?[r]:[]}return Bi(t,e).flatMap(n=>aS(t,n))}function Sp(t,e){var r,o,i,a,s;if(!e||e.kind==="object"||e.kind==="table-cell-range")return null;if(e.kind==="caret"){let l=J(t,e.paraId);if(!l)return null;let d=0,u=null;for(let f of l.content){let p=Wi(f);if(f.kind==="text"){if(e.offset>d&&e.offset<=d+p)return (r=f.hyperlink)!=null?r:null;if(e.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=Bi(t,e).flatMap(l=>{var p;let d=J(t,l.paraId);if(!d)return [];let u=[],f=0;for(let b of d.content){let w=Wi(b);b.kind==="text"&&f+w>l.from&&f<l.to&&u.push((p=b.hyperlink)!=null?p:null),f+=w;}return u});return Ep(n)}function aS(t,e){let n=J(t,e.paraId);if(!n)return [];let r=[],o=0;for(let i of n.content){let a=Wi(i);i.kind==="text"&&o+a>e.from&&o<e.to&&r.push(fl(t,n,i.format)),o+=a;}return r}function sS(t,e,n){let r=0,o=null;for(let i of e.content){let a=Wi(i);if(i.kind==="text"){let s=fl(t,e,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:fl(t,e,null)}function fl(t,e,n){var o,i;let r=e.format;return v(v(v({},(i=(o=t.defaults)==null?void 0:o.run)!=null?i:{}),r!=null?r:{}),n!=null?n:{})}function kp(t,e){var n;if(!e)return [];if(e.kind==="table-cell-range"){let r=(n=Oe(t,e.tableId))==null?void 0:n.table;return r?tt(r,e).flatMap(({cell:o})=>o.paragraphs):[]}if(e.kind==="caret"||e.kind==="object"){let r=J(t,e.paraId);return r?[r]:[]}return Bi(t,e).map(r=>J(t,r.paraId)).filter(r=>r!==null)}function Bi(t,e){let n=lS(t,e);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(t,n.anchor.paraId),o=ve(t,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:Pe(s).length});}return i}function lS(t,e){if(e.anchor.paraId===e.focus.paraId)return e.anchor.offset<=e.focus.offset?{anchor:e.anchor,focus:e.focus}:{anchor:e.focus,focus:e.anchor};let n=ve(t,e.anchor.paraId),r=ve(t,e.focus.paraId);return !n||!r||n.container!==r.container?null:n.index<r.index?{anchor:e.anchor,focus:e.focus}:{anchor:e.focus,focus:e.anchor}}function Wi(t){var e;return t.kind==="text"?t.text.length:t.kind==="field"?((e=t.cachedText)!=null?e:"\uFFFC").length:t.kind==="drawing"&&t.text?t.text.length:1}function Ye(t,e){return t.length===0?e:t.every(n=>n===t[0])?t[0]:"mixed"}function Ep(t){var n;if(t.length===0||t.every(r=>r===null))return null;let e=JSON.stringify(t[0]);return t.every(r=>JSON.stringify(r)===e)?(n=t[0])!=null?n:null:"mixed"}function uo(t){if(!t||t.toLowerCase()==="auto")return null;let e=t.replace(/^#/,"").toUpperCase();return /^[0-9A-F]{6}$/.test(e)?`#${e}`:t}function dS(t){var e;return !t||t.toLowerCase()==="none"?null:(e=uo(t))!=null?e:t}function xp(t){return t==="center"||t==="right"||t==="both"?t:t==="distribute"?"both":"left"}function Cp(t,e,n){let r=0;for(;r<t.length&&r<e.length&&t[r]===e[r];)r+=1;return {revision:n,changes:e.slice(r),revertedChanges:t.slice(r),totalChangeCount:e.length}}var fo=new WeakMap,pl="application/x-coco-word-table-cells+json",po="application/x-coco-word-image",Rp="coco-image:",ho=new Map,hl=0,cS=0,ml=0,gl=0;function DN(t,e,n={}){var Gd,jd,Ud;$u();let r=t,o=null;if(n.styleIsolation!=="none"){r.replaceChildren(),o=(Gd=r.shadowRoot)!=null?Gd:r.attachShadow({mode:"open"}),o.replaceChildren();let c=r.ownerDocument.createElement("style");c.textContent=`
|
|
1588
1603
|
:host { display: block; position: relative; min-width: 0; min-height: 0; }
|
|
1589
1604
|
*, *::before, *::after { box-sizing: border-box; }
|
|
1590
1605
|
button, input, textarea, select { font: inherit; line-height: normal; }
|
|
1591
1606
|
button { margin: 0; }
|
|
1592
|
-
${(jd=n.styleText)!=null?jd:gp}`,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",t=m;}let i=r;t.classList.add("coco-word-native-editor-host");let a=e,s=hs(a),l=false,d=n.readOnly===true,u=[],
|
|
1607
|
+
${(jd=n.styleText)!=null?jd:gp}`,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",t=m;}let i=r;t.classList.add("coco-word-native-editor-host");let a=e,s=hs(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,x=null,S=n.trackRevisions===true,k=null,I=false,D=null,F=null,A=null,O=null,ee=null,le=null,oe=null,ie=null,ae=false,_=null,Y=null,B=null,U=null,z=null,G=[],K=[],Se=new WeakSet,ke=false,Ce=false,Ge=false,et=false,kt={change:new Set,selectionChange:new Set},fn=(c,m)=>{for(let y of kt[c])y(m);},ut=()=>fo.set(document,t),Rt=c=>H(v({},yp(s,c)),{trackRevisions:S}),ht=null,Ze=null,Kt=null,ft=null,Qt=false,Kn=false,mt=()=>{Kt==null||Kt.remove(),Kt=null;},Tn=c=>{var N;if(!(c instanceof Element))return null;let m=c.closest("coco-word-native-table td[data-row-index][data-column-index]"),y=m==null?void 0:m.closest("coco-word-native-table[data-table-id]"),E=Number(m==null?void 0:m.dataset.rowIndex),C=Number(m==null?void 0:m.dataset.columnIndex);return !m||!y||!Number.isInteger(E)||!Number.isInteger(C)?null:{tableId:(N=y.dataset.tableId)!=null?N:"",point:{rowIndex:E,columnIndex:C},element:m}},Pn=c=>{for(let T of Array.from(t.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(t.querySelectorAll("coco-word-native-table[data-table-id]")).find(T=>T.dataset.tableId===c.tableId);if(!m)return;let y=Math.min(c.anchor.rowIndex,c.focus.rowIndex),E=Math.max(c.anchor.rowIndex,c.focus.rowIndex),C=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 R=Number(T.dataset.rowIndex),M=Number(T.dataset.columnIndex),$=R+Math.max(1,T.rowSpan)-1,V=M+Math.max(1,T.colSpan)-1;R<=E&&$>=y&&M<=N&&V>=C&&(T.classList.add("is-cell-range-selected"),T.setAttribute("aria-selected","true"),R===c.anchor.rowIndex&&M===c.anchor.columnIndex&&T.classList.add("is-cell-range-anchor"),R===c.focus.rowIndex&&M===c.focus.columnIndex&&T.classList.add("is-cell-range-focus"));}},gt=++cS,Ta=`coco-word-search-match-${gt}`,Pa=`coco-word-search-active-${gt}`,Ra=`coco-word-preserved-selection-${gt}`,Ma=document.createElement("style");Ma.textContent=`
|
|
1593
1608
|
::highlight(${Ta}) { background-color: rgb(250 204 21 / 42%); }
|
|
1594
1609
|
::highlight(${Pa}) { background-color: rgb(249 115 22 / 68%); color: inherit; }
|
|
1595
1610
|
::highlight(${Ra}) { background-color: rgb(0 120 215 / 34%); color: inherit; }
|
|
1596
|
-
`,(o!=null?o:document.head).appendChild(Ma);let bt=(Ud=globalThis.CSS)==null?void 0:Ud.highlights,Ir=globalThis.Highlight,id=()=>{bt==null||bt.delete(Ta),bt==null||bt.delete(Pa);},Aa=()=>{bt==null||bt.delete(Ra);},at=(c=false)=>{if(Aa(),(h==null?void 0:h.kind)!=="text-range"||!c&&(document.activeElement===i||t.contains(document.activeElement))||!bt||!Ir)return;let m=nt(s,h),y=Ks(t,m.anchor,m.focus);y&&!y.collapsed&&bt.set(Ra,new Ir(y));},Wo=()=>{if(id(),!k||!bt||!Ir)return;let c=[],m=null;k.matches.forEach((y,E)=>{let C=kf(t,y.paraId,y.from,y.to);C&&(E===k.activeIndex?m=C:c.push(C));}),c.length>0&&bt.set(Ta,new Ir(...c)),m&&bt.set(Pa,new Ir(m));},Bo=()=>k?{options:v({},k.options),matches:k.matches.map(c=>v({},c)),activeIndex:k.activeIndex}:null,Um=()=>{if(!k)return;let c=qs(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)},Wo(),at();},ad=()=>{let c=k&&k.activeIndex>=0?k.matches[k.activeIndex]:null,m=c?t.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"]`):null;m==null||m.scrollIntoView({block:"center",inline:"nearest"});},Km=c=>{let m={query:c.query,matchCase:!!c.matchCase,wholeWord:!!c.wholeWord},y=qs(s,m);return k={options:m,matches:y,activeIndex:y.length>0?0:-1},Wo(),ad(),Bo()},_m=(c="forward")=>{if(!k||k.matches.length===0)return Bo();let m=c==="backward"?-1:1;return k=F(v({},k),{activeIndex:(k.activeIndex+m+k.matches.length)%k.matches.length}),Wo(),ad(),Bo()},La=()=>{k=null,id();},_n=()=>{ht==null||ht.remove(),ht=null;},Da=()=>{if(!ht||!g)return;let c=t.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`);if(!c){_n();return}let m=t.getBoundingClientRect(),y=c.getBoundingClientRect();ht.style.left=`${y.right-m.left+t.scrollLeft-6}px`,ht.style.top=`${y.bottom-m.top+t.scrollTop-6}px`;},_t=()=>{if(d){_n();return}if(!g){_n();return}if(Ef(t,g),!!t.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",y=>{y.preventDefault(),y.stopPropagation();}),m.addEventListener("pointerdown",y=>{if(!g||y.button!==0)return;ut();let E=v({},g),C=t.querySelector(`coco-word-native-p[data-para-id="${E.paraId}"] img[data-drawing-id="${E.drawingId}"]`);if(!C)return;Ze==null||Ze(),y.preventDefault(),y.stopPropagation(),m.setPointerCapture(y.pointerId);let N=C.getBoundingClientRect(),T=y.clientX,P=y.clientY,M=Math.max(1,N.width),$=Math.max(1,N.height),V=M/$,j=M,ie=$,ue=Me=>{let _=Me.clientX-T,Q=Me.clientY-P;if(Me.shiftKey)j=Math.max(24,M+_),ie=Math.max(24,$+Q);else {let ne=Math.abs(_)>=Math.abs(Q)?_:Q*V;j=Math.max(24,M+ne),ie=Math.max(24,j/V);}C.style.width=`${j}px`,C.style.height=`${ie}px`,Da();},ye=Me=>{Ze==null||Ze(),Ze=null,m.hasPointerCapture(Me.pointerId)&&m.releasePointerCapture(Me.pointerId),ke({kind:"set-image-size",objectId:E.drawingId,width:Math.round(j*100)/100,height:Math.round(ie*100)/100});};document.addEventListener("pointermove",ue,true),document.addEventListener("pointerup",ye,true),document.addEventListener("pointercancel",ye,true),Ze=()=>{document.removeEventListener("pointermove",ue,true),document.removeEventListener("pointerup",ye,true),document.removeEventListener("pointercancel",ye,true);};}),t.appendChild(m),ht=m;}Da();}},Fo=()=>Da();window.addEventListener("resize",Fo),document.addEventListener("scroll",Fo,true);let sd=()=>{if(r.setAttribute("aria-readonly",String(d)),t.dataset.readOnly=String(d),!!d){for(let c of Array.from(t.querySelectorAll('[contenteditable="true"]')))c.contentEditable="false";_n();}},Pe=(c,m)=>{H!==null&&(window.clearTimeout(H),H=null),A!==null&&(window.clearTimeout(A),A=null),fi(s);let y=zu(s);t.replaceChildren(y),Gu(y,s),sd(),Fa(y);let E=(m==null?void 0:m.kind)==="table-cell-range"?m:(h==null?void 0:h.kind)==="table-cell-range"?h:null;Nn(E),Wo(),at(),g&&_t(),(m==null?void 0:m.kind)==="text-range"?vn(t,m.anchor,m.focus):c&&dt(t,c);},Wa=(c,m)=>{var N;let y=J(s,c);if(!y){Pe(m);return}let E=Array.from(t.querySelectorAll(`coco-word-native-p[data-para-id="${c}"]`));if(E.length===0){Pe(m);return}for(let T of E)T.replaceWith(no(y));sd();let C=(N=t.querySelector(":scope > coco-word-native-document"))!=null?N:t.querySelector("coco-word-native-document");C&&yn(C),g&&_t(),m&&dt(t,m);},ld=(c,m)=>c.querySelector(`table[data-shared-grid] coco-word-native-p[data-para-id="${m}"]`)!==null,Be=(c,m,y)=>{var N;let E=t.querySelector(":scope > coco-word-native-document");if(!E)return false;if(ld(E,c)){let T=y!=null?y:m?void 0:(N=ze(t))!=null?N:void 0;return Pe(m!=null?m:(T==null?void 0:T.kind)==="caret"?T:void 0,T),true}let C=ju(E,s,c);Fa(E);for(let T of Array.from(E.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img`)))T.complete||Se.has(T)||(Se.add(T),T.addEventListener("load",()=>{Se.delete(T),Be(c);},{once:true}));return (y==null?void 0:y.kind)==="text-range"?vn(t,y.anchor,y.focus):m&&dt(t,m),C},pn=(c,m=180,y)=>{oe||te||(A!==null&&window.clearTimeout(A),A=window.setTimeout(()=>{var N;if(A=null,oe||te)return;let E=(N=t.querySelector(":scope > coco-word-native-document"))!=null?N:t.querySelector("coco-word-native-document");if(!E||y&&!y(E))return;let C=(h==null?void 0:h.kind)==="object"?h:ze(t);if((C==null?void 0:C.kind)==="text-range")Be(c,void 0,C);else if((C==null?void 0:C.kind)==="object")Be(c),g={paraId:C.paraId,drawingId:C.objectId},_t();else {let T=(C==null?void 0:C.kind)==="caret"?C:pt(t);Be(c,T!=null?T:void 0);}},m));},Ho=(c,m=80)=>{var C;let y=(C=t.querySelector(":scope > coco-word-native-document"))!=null?C:t.querySelector("coco-word-native-document");if(!y)return;let E=false;for(let N of Array.from(y.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img`)))N.complete||Se.has(N)||(E=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,E?800:m);},Nr=c=>{var y;if((U==null?void 0:U.paraId)===c)return;let m=(y=t.querySelector(":scope > coco-word-native-document"))!=null?y:t.querySelector("coco-word-native-document");m&&(U={paraId:c,measurement:Os(m,s,c)});},Ba=c=>{pn(c,700,m=>{let y=U;if(U=null,!y||y.paraId!==c)return false;if(ld(m,c))return true;let E=Os(m,s,c);return E.overflowPx>Math.max(1,y.measurement.overflowPx+1)||!y.measurement.canBackfillPrevious&&E.canBackfillPrevious||!y.measurement.canBackfillNext&&E.canBackfillNext});},Oo=new WeakMap,$o=new ResizeObserver(c=>{var m,y;for(let E of c){let C=E.target;if(!(C instanceof HTMLElement))continue;let N=Math.round(E.contentRect.height),T=Oo.get(C);if(Oo.set(C,N),T===void 0||Math.abs(T-N)<=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 $=(y=M.closest("coco-word-native-p[data-para-id]"))==null?void 0:y.dataset.paraId;Ba($!=null?$:P);}else pn(P);}}}),Fa=c=>{for(let m of Array.from(c.querySelectorAll("coco-word-native-table")))Oo.has(m)||(Oo.set(m,Math.round(m.getBoundingClientRect().height)),$o.observe(m));},Re=(c="immediate")=>{if(l)return;let m=()=>{var E;Um();let y=Cp(p,u,++f);p=u.slice(),(E=n.onChange)==null||E.call(n,y),fn("change",y);};if(c==="immediate"){ee!==null&&(window.clearTimeout(ee),ee=null),m();return}ee!==null&&window.clearTimeout(ee),ee=window.setTimeout(()=>{ee=null,m();},180);},Ha=()=>{l||(le!==null&&window.clearTimeout(le),le=window.setTimeout(()=>{var y,E;le=null;let c=(y=h!=null?h:ze(t))!=null?y:lt(t),m={selection:c,commandState:Rt(c)};(E=n.onSelectionChange)==null||E.call(n,m),fn("selectionChange",m);},80));},dd=c=>{B=c,G!==null&&window.clearTimeout(G),G=window.setTimeout(()=>{B=null,G=null;},1e3);},qm=(c,m,y)=>{let E=Array.from(t.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img[data-drawing-id="${m}"]`));for(let C of E)C.remove();Pt(t),y&&dt(t,y);},Tn=(c,m,y={})=>{Array.isArray(c)?u.push(...c):c&&u.push(c),c&&(Y.length=0),y.localParaId?(Wa(y.localParaId,m),pn(y.localParaId)):Pe(m),Re();},zo=c=>{let m=J(s,c);return !!m&&m.content.every(y=>y.kind==="text")},Oa=c=>{let m=J(s,c);return m?Te(m).length:0},Tr=(c,m,y,E)=>{var P,M;let C=J(s,c);if(!C)return null;let N=E==="before"?m-1:E==="after"?m+1:m;if(N<0)return null;let T=0;for(let $ of C.content){let V=$.kind==="text"?$.text.length:1;if(N>=T&&N<T+V){let j=$.kind==="text"?(P=$.marks)==null?void 0:P.find(ie=>ie.kind==="revision"&&ie.revisionKind===y):void 0;return j&&"revisionId"in j&&(M=j.revisionId)!=null?M:null}T+=V;}return null},cd=(c,m)=>{var y;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:(y=Tr(c,m.offset,"insert","before"))!=null?y:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()})},$a=c=>{let m=ve(s,c.anchor.paraId),y=ve(s,c.focus.paraId);if(!m||!y||m.container!==y.container)return null;let E=Math.min(m.index,y.index),C=Math.max(m.index,y.index),N=[];for(let T=E;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;N.push(ge(P));}return N},ud=c=>{let m=$a(c);return m&&m.length>1?m:null},Xm=c=>{let m=ud(c);return m?(ae={range:c,beforeParagraphs:m,changesStart:u.length},true):false},Vo=c=>{var T;let m=c.anchor.paraId;if(c.focus.paraId!==m)return;let y=t.querySelector(`coco-word-native-p[data-para-id="${m}"]`),E=J(s,m);if(!(y!=null&&y.closest("coco-word-native-table"))||!E||((T=z==null?void 0:z.afterParagraphs[0])==null?void 0:T.paraId)===m)return;let C=ge(E),N={source:"browser",patchMode:"individual",skipDeferredRender:true,range:c,beforeParagraphs:[C],afterParagraphs:[C],changesStart:u.length,changes:[]};K.push(N),Y.length=0,z=N;},fd=c=>{if(d){c.preventDefault();return}oe=true,X!==null&&(window.clearTimeout(X),X=null),te&&za(),H!==null&&(window.clearTimeout(H),H=null),A!==null&&(window.clearTimeout(A),A=null),ee!==null&&(window.clearTimeout(ee),ee=null),le!==null&&(window.clearTimeout(le),le=null);let m=ze(t),y=c.target instanceof Node?Nt(c.target):null,E=y==null?void 0:y.dataset.paraId,C=pt(t),N=E?{paraId:E,offset:(C==null?void 0:C.paraId)===E?C.offset:Oa(E)}:C,T=N?J(s,N.paraId):null;if(!N||!T||T.content.some(M=>M.kind!=="text"))return;Nr(N.paraId),z=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};te={paraId:N.paraId,beforeParagraph:ge(T),changesStart:u.length,range:P};},za=()=>{var M;X=null;let c=te;if(te=null,!c)return;let m=J(s,c.paraId);if(!m)return;let y=t.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"]`);if(!y)return;let E=qr(s,c.paraId,(M=y.textContent)!=null?M:"");E&&u.push(E);let C=cd(c.paraId,E);C&&u.push(C);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),Y.length=0;let P=pt(t);P&&se(v({kind:"caret"},P)),Ba(c.paraId),C&&Wa(c.paraId,P!=null?P:void 0),Re("deferred");},pd=()=>{oe=false,X!==null&&window.clearTimeout(X),X=window.setTimeout(za,80);},Go=(c,m)=>{var M,$;let y=new Set([...c.beforeParagraphs,...c.afterParagraphs].map(V=>V.paraId)),E=(M=[...c.beforeParagraphs,...c.afterParagraphs].find(V=>J(s,V.paraId)))==null?void 0:M.paraId;if(!E)return false;let C=ve(s,E);if(!C)return false;if(c.patchMode==="individual"){for(let V of m){let j=ve(s,V.paraId);if(!j)return false;Object.assign(j.paragraph,ge(V));}return true}let N=Array.from(y).filter(V=>J(s,V));if(N.length===0||m.length===0)return false;let T=ge(m[0]);Object.assign(C.paragraph,T);for(let V of N)V!==E&&(($=ve(s,V))==null||$.remove());let P=T.paraId;for(let V of m.slice(1)){let j=ve(s,P);if(!j)return false;let ie=ge(V);j.insertAfter(ie),P=ie.paraId;}return true},Ym=()=>{var T;if(!ae)return false;let c=ae;ae=null;let m=c.beforeParagraphs.map(P=>Mp(t,P.paraId)),y=m.every(P=>P!==null),E=[];if(y)for(let P=0;P<c.beforeParagraphs.length;P+=1){let M=c.beforeParagraphs[P],$=qr(s,M.paraId,(T=m[P])!=null?T:"");$&&E.push($);}else E.push(...bi(s,c.range.anchor,c.range.focus));if(E.length===0)return false;u.push(...E);let C=c.beforeParagraphs.map(P=>J(s,P.paraId)).filter(P=>P!==null);if(C.length>0){let P=F(v({},c),{source:"browser",afterParagraphs:C.map(ge),changes:E});K.push(P),z=null,Y.length=0;}let N=pt(t);return N&&se({kind:"caret",paraId:N.paraId,offset:N.offset}),Be(c.beforeParagraphs[0].paraId,N!=null?N:void 0),Re("deferred"),true},Zm=()=>{let c=K[K.length-1];if(!c||lr(c)||!Fi(t,c.beforeParagraphs)||!Go(c,c.beforeParagraphs))return false;K.pop(),Y.push(c),u.splice(c.changesStart);let m=pt(t);return m&&se({kind:"caret",paraId:m.paraId,offset:m.offset}),Be(c.beforeParagraphs[0].paraId,m!=null?m:void 0),Re("deferred"),true},Jm=()=>{let c=Y[Y.length-1];if(!c||lr(c)||!Fi(t,c.afterParagraphs)||!Go(c,c.afterParagraphs))return false;Y.pop(),K.push(c),u.splice(c.changesStart),u.push(...c.changes);let m=pt(t);return m&&se({kind:"caret",paraId:m.paraId,offset:m.offset}),Be(c.beforeParagraphs[0].paraId,m!=null?m:void 0),Re("deferred"),true},Wt=(c,m,y)=>{var $,V,j;if(c.patchMode==="individual"){let ie=false;for(let ye of m){let Me=Array.from(t.querySelectorAll(`coco-word-native-p[data-para-id="${ye.paraId}"]`));for(let _ of Me)_.replaceWith(no(ye)),ie=true;}y&&dt(t,y);let ue=t.querySelector(":scope > coco-word-native-document");return ue&&yn(ue),ie}let E=new Set([...c.beforeParagraphs,...c.afterParagraphs].map(ie=>ie.paraId)),C=Array.from(E).flatMap(ie=>Array.from(t.querySelectorAll(`coco-word-native-p[data-para-id="${ie}"]`))),N=($=c.beforeParagraphs[0])==null?void 0:$.paraId,T=(V=C.find(ie=>ie.dataset.paraId===N))!=null?V:C[0];if(!T)return false;let P=m.map(ie=>no(ie));T.replaceWith(...P);for(let ie of C)ie!==T&&ie.isConnected&&ie.remove();y&&dt(t,y);let M=(j=t.querySelector(":scope > coco-word-native-document"))!=null?j:t.querySelector("coco-word-native-document");return M&&yn(M),true},hd=(c,m,y)=>(c.container.splice(c.startIndex,y,...rt(m)),true),Bt=(c,m,y,E)=>{var $,V;let C=[...c.beforeBlocks,...c.afterBlocks].flatMap(j=>pS(t,j)),N=(($=c.afterBlocks[0])==null?void 0:$.kind)==="paragraph"?c.afterBlocks[0].paraId:((V=c.beforeBlocks[0])==null?void 0:V.kind)==="paragraph"?c.beforeBlocks[0].paraId:null,T=N?t.querySelector(`coco-word-native-p[data-para-id="${N}"]`):C[0];if(!T)return false;let P=m.map(j=>to(j));T.replaceWith(...P);for(let j of C)j!==T&&j.isConnected&&j.remove();let M=t.querySelector(":scope > coco-word-native-document");return M&&Fa(M),M&&yn(M),E?vn(t,E.anchor,E.focus):y&&dt(t,y),true},Qm=c=>{let m=t.querySelector(`coco-word-native-p[data-para-id="${c.anchor.paraId}"]`),y=t.querySelector(`coco-word-native-p[data-para-id="${c.focus.paraId}"]`);return !!m&&!!y&&m.closest("coco-word-native-page")!==y.closest("coco-word-native-page")},md=(c,m)=>{let y=ud(c);if(!y)return false;let E={range:c,beforeParagraphs:y,changesStart:u.length},C=gu(s,c.anchor,c.focus,m);if(C.length===0)return false;let N=y.map(M=>J(s,M.paraId)).filter(M=>M!==null).map(ge);if(N.length===0)return false;let T=F(v({},E),{source:"local",afterParagraphs:N,changes:C}),P={paraId:c.anchor.paraId,offset:c.anchor.offset+m.length};return u.push(...C),K.push(T),z=m.length>0?T:null,Y.length=0,Wt(T,N,P)?Be(y[0].paraId,P):Pe(P),se(v({kind:"caret"},P)),Re("deferred"),true},jo=(c,m)=>{let y=hu(s,c.anchor,c.focus,m);if(!y)return false;let E={source:"local",range:c,container:y.container,startIndex:y.startIndex,beforeBlocks:y.beforeBlocks,afterBlocks:y.afterBlocks,changesStart:u.length,changes:y.changes};if(u.push(...y.changes),K.push(E),Y.length=0,z=null,g=null,!Bt(E,y.afterBlocks,y.cursor))Pe(y.cursor);else {let C=t.querySelector(":scope > coco-word-native-document");C&&Vt(C,s,y.cursor.paraId),Be(y.cursor.paraId,y.cursor);}return se(v({kind:"caret"},y.cursor)),Re("deferred"),true},eg=(c,m)=>{let y=mu(s,c.anchor,c.focus,m);if(!y)return false;let E={source:"local",range:c,container:y.container,startIndex:y.startIndex,beforeBlocks:y.beforeBlocks,afterBlocks:y.afterBlocks,changesStart:u.length,changes:y.changes};u.push(...y.changes),K.push(E),Y.length=0,z=null,g=null;for(let C of _e(s))b.add(C.paraId);if(!Bt(E,y.afterBlocks,y.cursor))Pe(y.cursor);else {let C=t.querySelector(":scope > coco-word-native-document");C&&Vt(C,s,y.cursor.paraId),Be(y.cursor.paraId,y.cursor);}return se(v({kind:"caret"},y.cursor)),Re("deferred"),true},tg=(c,m)=>{let y=c.kind==="table-cell-range"?(()=>{var Me,_,Q;let ie=(Me=Oe(s,c.tableId))==null?void 0:Me.table,ue=ie?(_=tt(ie,c)[0])==null?void 0:_.cell:null,ye=(Q=ue==null?void 0:ue.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(!y)return false;let E=rn(s,y.paraId);if(!E)return false;let C=rt([E.table])[0];if(!C||C.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=ru(s,y.paraId,N,Ar);if(!T)return false;let P=rt([E.table])[0];if(!P||P.kind!=="table")return false;let M=S?ot(s):null,$=m.kind==="insert-table-row"||m.kind==="insert-table-column"?"insert":"delete";M&&(E.table.revision={kind:"revision",id:`revision:${M}`,revisionId:M,revisionKind:$,author:"User",date:new Date().toISOString()},P.revision=v({},E.table.revision),T.change.kind==="table"&&(T.change.revisionId=M,T.change.revisionKind=$,T.change.beforeTable=C));let V=v({kind:"caret"},T.cursor),j={source:"local",range:{anchor:y,focus:y},container:E.container,startIndex:E.tableIndex,beforeBlocks:[C],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:c,afterSelection:V};if(u.push(T.change),K.push(j),Y.length=0,z=null,g=null,!Bt(j,j.afterBlocks,T.cursor))Pe(T.cursor);else {let ie=t.querySelector(":scope > coco-word-native-document");ie&&Vt(ie,s,T.cursor.paraId),Be(T.cursor.paraId,T.cursor);}return se(V),Re("deferred"),true},ng=(c,m)=>{let y=Oe(s,c.tableId);if(!y)return false;let E=rt([y.table])[0];if(!E||E.kind!=="table")return false;let N=tt(y.table,c)[0],T=m.kind==="merge-table-cells"?ou(s,c.tableId,c):N?iu(s,c.tableId,N.rowIndex,N.columnIndex,Ar):null;if(!T)return false;let P=rt([y.table])[0];if(!P||P.kind!=="table")return false;let M=S?ot(s):null,$=m.kind==="merge-table-cells"?"insert":"delete";M&&(y.table.revision={kind:"revision",id:`revision:${M}`,revisionId:M,revisionKind:$,author:"User",date:new Date().toISOString()},P.revision=v({},y.table.revision),T.change.kind==="table"&&(T.change.revisionId=M,T.change.revisionKind=$,T.change.beforeTable=E));let V={source:"local",range:{anchor:{paraId:T.cursor.paraId,offset:T.cursor.offset},focus:{paraId:T.cursor.paraId,offset:T.cursor.offset}},container:y.container,startIndex:y.tableIndex,beforeBlocks:[E],afterBlocks:[P],changesStart:u.length,changes:[T.change],beforeSelection:c,afterSelection:v({kind:"caret"},T.cursor)};if(u.push(T.change),K.push(V),Y.length=0,z=null,g=null,!Bt(V,V.afterBlocks,T.cursor))Pe(T.cursor);else {let j=t.querySelector(":scope > coco-word-native-document");j&&Vt(j,s,T.cursor.paraId),Be(T.cursor.paraId,T.cursor);}return se(v({kind:"caret"},T.cursor)),Re("deferred"),true},rg=(c,m)=>{let y=c.kind==="text-range"?c.anchor:c.kind==="table-cell-range"?(()=>{var V,j;let M=(V=Oe(s,c.tableId))==null?void 0:V.table,$=M?(j=tt(M,c)[0])==null?void 0:j.cell.paragraphs[0]:null;return $?{paraId:$.paraId,offset:0}:null})():{paraId:c.paraId,offset:c.offset};if(!y)return false;let E=m.kind==="insert-table"?c.kind==="caret"?tu(s,c.paraId,c.offset,m.rows,m.columns,Ar):null:(()=>{var $;let M=($=Rt(c).table)==null?void 0:$.tableId;return M?nu(s,M,Ar):null})();if(!E)return false;let C=S?ot(s):null,N=m.kind==="insert-table"?"insert":"delete";if(C){let M=E.afterBlocks.find($=>$.kind==="table");(M==null?void 0:M.kind)==="table"&&(M.revision={kind:"revision",id:`revision:${C}`,revisionId:C,revisionKind:N,author:"User",date:new Date().toISOString()},E.changes.forEach($=>{if($.kind==="table"){$.revisionId=C,$.revisionKind=N;let V=E.beforeBlocks.find(j=>j.kind==="table");if((V==null?void 0:V.kind)==="table"&&($.beforeTable=V),$.op==="insert-table"){$.anchorParaId=y.paraId,$.anchorOffset=y.offset;let j=E.afterBlocks.find(ie=>ie.kind==="table");(j==null?void 0:j.kind)==="table"&&($.tableSnapshot=j);}}}));}for(let M of E.changes){if(M.kind!=="table"||M.op!=="insert-table")continue;M.anchorParaId=y.paraId,M.anchorOffset=y.offset;let $=E.afterBlocks.find(V=>V.kind==="table");($==null?void 0:$.kind)==="table"&&(M.tableSnapshot=$);}let T=v({kind:"caret"},E.cursor),P={source:"local",range:{anchor:y,focus:c.kind==="text-range"?c.focus:y},container:E.container,startIndex:E.startIndex,beforeBlocks:E.beforeBlocks,afterBlocks:E.afterBlocks,changesStart:u.length,changes:E.changes,beforeSelection:c,afterSelection:T};u.push(...E.changes),K.push(P),Y.length=0,z=null,g=null;for(let M of _e(s))b.add(M.paraId);if(!Bt(P,P.afterBlocks,E.cursor))Pe(E.cursor);else {let M=t.querySelector(":scope > coco-word-native-document");M&&Vt(M,s,E.cursor.paraId),Be(E.cursor.paraId,E.cursor);}return se(T),Re("deferred"),true},og=(c,m)=>{var ue,ye;let y=c.kind==="table-cell-range"?Oe(s,c.tableId):null,E=c.kind==="table-cell-range"&&y?(ue=tt(y.table,c)[0])==null?void 0:ue.cell:null,C=c.kind==="table-cell-range"?(ye=E==null?void 0:E.paragraphs[0])!=null&&ye.paraId?{paraId:E.paragraphs[0].paraId,offset:0}:null:c.kind==="text-range"?c.anchor:{paraId:c.paraId,offset:c.offset};if(!C)return false;let N=y!=null?y:rn(s,C.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"?au(s,c.tableId,c,P):Es(s,C.paraId,P);if(!M)return false;let $=rt([N.table])[0];if(!$||$.kind!=="table")return false;let V={source:"local",range:{anchor:C,focus:C},container:N.container,startIndex:N.tableIndex,beforeBlocks:[T],afterBlocks:[$],changesStart:u.length,changes:"changes"in M?M.changes:[M.change],beforeSelection:c,afterSelection:c};u.push(...V.changes),K.push(V),Y.length=0,z=null;let j=c.kind==="caret"?c:void 0,ie=c.kind==="text-range"?c:void 0;if(!Bt(V,V.afterBlocks,j,ie))Pe(j,c);else {Ft(c);let Me=t.querySelector(":scope > coco-word-native-document");Me&&Vt(Me,s,C.paraId),Be(C.paraId,j,ie),Ft(c);}return se(c),Re("deferred"),true},qn=c=>{let m=Oe(s,c.tableId);if(!m)return false;let y=rt([m.table])[0];if(!y||y.kind!=="table")return false;let E=su(s,c.tableId,c);if(!E)return false;let C=rt([m.table])[0];if(!C||C.kind!=="table")return false;let N={source:"local",range:{anchor:E.cursor,focus:E.cursor},container:m.container,startIndex:m.tableIndex,beforeBlocks:[y],afterBlocks:[C],changesStart:u.length,changes:E.changes,beforeSelection:c,afterSelection:c};if(u.push(...E.changes),K.push(N),Y.length=0,z=null,!Bt(N,N.afterBlocks))Pe(void 0,c);else {let T=t.querySelector(":scope > coco-word-native-document");T&&Vt(T,s,E.cursor.paraId),Be(E.cursor.paraId);}return se(c),Re("deferred"),true},Va=(c,m)=>{var ie,ue,ye;let y=Oe(s,c.tableId);if(!y)return false;let E=rt([y.table])[0];if(!E||E.kind!=="table")return false;let C={rowIndex:Math.min(c.anchor.rowIndex,c.focus.rowIndex),columnIndex:Math.min(c.anchor.columnIndex,c.focus.columnIndex)},N=(ue=(ie=m.content)!=null?ie:m.text)!=null?ue:[],T=m.content?du(s,c.tableId,C,m.content):lu(s,c.tableId,C,(ye=m.text)!=null?ye:[]);if(!T)return false;let P=rt([y.table])[0];if(!P||P.kind!=="table")return false;let M=N.length,$=Math.max(1,...N.map(Me=>Me.length)),V={kind:"table-cell-range",tableId:c.tableId,anchor:C,focus:{rowIndex:Math.min(y.table.rows.length-1,C.rowIndex+M-1),columnIndex:C.columnIndex+$-1}},j={source:"local",range:{anchor:T.cursor,focus:T.cursor},container:y.container,startIndex:y.tableIndex,beforeBlocks:[E],afterBlocks:[P],changesStart:u.length,changes:T.changes,beforeSelection:c,afterSelection:V};if(u.push(...T.changes),K.push(j),Y.length=0,z=null,!Bt(j,j.afterBlocks))Pe(void 0,V);else {let Me=t.querySelector(":scope > coco-word-native-document");Me&&Vt(Me,s,T.cursor.paraId),Be(T.cursor.paraId);}return se(V),Re("deferred"),true},Ft=c=>{if(c){if(c.kind==="text-range"){vn(t,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(t,c);}},ig=()=>{var E;let c=K[K.length-1];if(!c)return false;if(lr(c)){let C=(E=c.beforeSelection)!=null?E:{kind:"text-range",anchor:c.range.anchor,focus:c.range.focus},N=C.kind==="caret"?C:void 0,T=C.kind==="text-range"?C:void 0;if(!hd(c,c.beforeBlocks,c.afterBlocks.length));Bt(c,c.beforeBlocks,N,T)||Pe(N,C),Ft(C),K.pop(),Y.push(c),z=null,u.splice(c.changesStart),se(C);let P=t.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 Be(M,N,T),Re("deferred"),true}if(c.source==="browser"&&!c.skipDeferredRender&&!Fi(t,c.afterParagraphs))return false;let m={paraId:c.beforeParagraphs[0].paraId,offset:c.range.anchor.offset};if(!Go(c,c.beforeParagraphs))return false;let y=Np(c,"before");if(c.forceFullRender){K.pop(),Y.push(c),z=null,u.splice(c.changesStart);let C=y!=null?y:v({kind:"caret"},m);return se(C),Pe(C.kind==="caret"?C:void 0,C),Ft(C),Re("deferred"),true}if(!Wt(c,c.beforeParagraphs,y?void 0:m))return false;if(Ft(y),K.pop(),Y.push(c),z=null,u.splice(c.changesStart),se(y!=null?y:v({kind:"caret"},m)),Tp(c)||c.skipDeferredRender){let C=c.beforeParagraphs[0].paraId;c.deferLayoutReflow?Ho(C):Be(C,y?void 0:m,(y==null?void 0:y.kind)==="text-range"?y:void 0),Ft(y),c.deferLayoutReflow||pn(C);}return Re("deferred"),true},ag=()=>{var E;let c=Y[Y.length-1];if(!c)return false;if(lr(c)){let C=(E=c.afterSelection)!=null?E:{kind:"caret",paraId:c.afterBlocks[0].kind==="paragraph"?c.afterBlocks[0].paraId:c.range.anchor.paraId,offset:c.range.anchor.offset},N=C.kind==="caret"?C:void 0,T=C.kind==="text-range"?C:void 0;if(!hd(c,c.afterBlocks,c.beforeBlocks.length));Bt(c,c.afterBlocks,N,T)||Pe(N,C),Ft(C),Y.pop(),K.push(c),z=null,u.splice(c.changesStart),u.push(...c.changes),se(C);let P=C.kind==="text-range"?C.anchor.paraId:C.kind==="table-cell-range"?c.range.anchor.paraId:C.paraId,M=t.querySelector(":scope > coco-word-native-document");return M&&Vt(M,s,P),Be(P,N,T),Re("deferred"),true}if(c.source==="browser"&&!c.skipDeferredRender&&!Fi(t,c.beforeParagraphs))return false;let m={paraId:c.afterParagraphs[0].paraId,offset:c.range.anchor.offset};if(!Go(c,c.afterParagraphs))return false;let y=Np(c,"after");if(c.forceFullRender){Y.pop(),K.push(c),z=null,u.splice(c.changesStart),u.push(...c.changes);let C=y!=null?y:v({kind:"caret"},m);return se(C),Pe(C.kind==="caret"?C:void 0,C),Ft(C),Re("deferred"),true}if(!Wt(c,c.afterParagraphs,y?void 0:m))return false;if(Ft(y),Y.pop(),K.push(c),z=null,u.splice(c.changesStart),u.push(...c.changes),se(y!=null?y:v({kind:"caret"},m)),Tp(c)||c.skipDeferredRender){let C=c.beforeParagraphs[0].paraId;c.deferLayoutReflow?Ho(C):Be(C,y?void 0:m,(y==null?void 0:y.kind)==="text-range"?y:void 0),Ft(y),c.deferLayoutReflow||pn(C);}return Re("deferred"),true},Pr=()=>l||d||K.length===0?false:(ut(),ig()),Rr=()=>l||d||Y.length===0?false:(ut(),ag()),se=c=>{if(c&&ut(),(c==null?void 0:c.kind)!=="object"&&_n(),Nn(c),hS(h,c)){at();return}h=c,at(),Ha();},Mr=(c,m,y)=>{if(!c||(m==null?void 0:m.kind)!=="image")return false;let E=J(s,m.paraId);if(!E)return false;let C={source:"local",patchMode:"individual",deferLayoutReflow:true,range:{anchor:y,focus:y},beforeParagraphs:[c],afterParagraphs:[ge(E)],changesStart:u.length,changes:[m],beforeSelection:{kind:"object",paraId:m.paraId,objectKind:"image",objectId:m.drawingId,offset:m.offset},afterSelection:v({kind:"caret"},y)};return u.push(m),K.push(C),Y.length=0,z=null,qm(m.paraId,m.drawingId,y),Ho(m.paraId),g=null,se(v({kind:"caret"},y)),Re("deferred"),true},Pn=(c,m,y)=>{let E=J(s,c),C=E==null?void 0:E.content.find(T=>T.kind==="image"&&T.drawingId===m);if(S&&E&&(C==null?void 0:C.kind)==="image"){let T=ge(E),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:y.offset},[T],[{kind:"image",op:"delete",paraId:c,offset:y.offset,drawingId:m,revisionId:P,revisionKind:"delete"}],true)}let N=E?ge(E):null;return Mr(N,Su(s,c,m),y)},Rn=(c,m,y=v({kind:"caret"},c),E)=>{let C=J(s,c.paraId);if(!C)return false;let N=m==="delete-backward"?c.offset-1:c.offset;if(m!=="insert"&&!gi(s,c.paraId,N))return false;let T=ge(C),P=m==="insert"?uu(s,c.paraId,c.offset):m==="delete-backward"?jr(s,c.paraId,c.offset):Ur(s,c.paraId,c.offset),M=J(s,c.paraId);if(!P||P.kind!=="page-break"||!M)return false;let $={paraId:c.paraId,offset:m==="insert"?c.offset+1:m==="delete-backward"?Math.max(0,c.offset-1):c.offset},V=E!=null?E:v({kind:"caret"},$),j=V.kind==="caret"?V:$,ie={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:c,focus:c},beforeParagraphs:[T],afterParagraphs:[ge(M)],changesStart:u.length,changes:[P],beforeSelection:y,afterSelection:V};return u.push(P),K.push(ie),Y.length=0,z=null,g=null,Pe(j,V),se(V),Re("deferred"),true},Uo=c=>{if(c.anchor.paraId!==c.focus.paraId)return false;let m=Hi(c.anchor.offset,c.focus.offset);if(!fu(s,c.anchor.paraId,m.from,m.to))return false;let y=J(s,c.anchor.paraId);if(!y)return false;let E=ge(y),C=bn(s,c.anchor.paraId,m.from,m.to),N=J(s,c.anchor.paraId);if(!N||!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:[E],afterParagraphs:[ge(N)],changesStart:u.length,changes:C,beforeSelection:c,afterSelection:T};return u.push(...C),K.push(P),Y.length=0,z=null,Pe(T,T),se(T),Re("deferred"),true},Ko=(c,m)=>{let y=ve(s,c.paraId);if(!y)return false;if(m==="backward"&&c.offset===0&&y.previous){let N=Te(y.previous).length;return gi(s,y.previous.paraId,N-1)?Rn({paraId:y.previous.paraId,offset:N},"delete-backward",c,c):false}let E=y.container[y.index+1],C=(E==null?void 0:E.kind)==="paragraph"?E:null;return m==="forward"&&c.offset===Te(y.paragraph).length&&C&&gi(s,C.paraId,0)?Rn({paraId:C.paraId,offset:0},"delete-forward",c,c):false},Mn=(c,m,y,E)=>{if(c.anchor.paraId!==c.focus.paraId)return false;let C=J(s,c.anchor.paraId);if(!C)return false;let N=ge(C),T=E(),P=Array.isArray(T)?T:T?[T]:[],M=J(s,c.anchor.paraId);if(P.length===0||!M)return false;let $=v({kind:"caret"},y),V={source:"local",patchMode:"individual",range:c,beforeParagraphs:[N],afterParagraphs:[ge(M)],changesStart:u.length,changes:P,beforeSelection:m,afterSelection:$};return u.push(...P),K.push(V),Y.length=0,z=null,Wt(V,V.afterParagraphs,y)?Be(c.anchor.paraId,y):Pe(y),se($),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 y=ve(s,m.anchor.paraId),E=ve(s,m.focus.paraId);if(!y||!E||y.container!==E.container)return [];let C=[];for(let N=y.index;N<=E.index;N+=1){let T=y.container[N];if((T==null?void 0:T.kind)!=="paragraph")return [];C.push({paraId:T.paraId,from:N===y.index?m.anchor.offset:0,to:N===E.index?m.focus.offset:Te(T).length});}return C},gd=c=>{var m;if(!c)return [];if(c.kind==="caret"||c.kind==="object")return [c.paraId];if(c.kind==="table-cell-range"){let y=(m=Oe(s,c.tableId))==null?void 0:m.table;return y?tt(y,c).flatMap(({cell:E})=>E.paragraphs.map(C=>C.paraId)):[]}return en(c).map(y=>y.paraId)},bd=c=>{if((c==null?void 0:c.kind)!=="text-range")return null;let m=en(c);return m.length===0?null:m.map(y=>Te(J(s,y.paraId)).slice(y.from,y.to)).join(`
|
|
1597
|
-
`)},wd=c=>en(c).map(m=>{var P;let y=J(s,m.paraId),E=Te(y).slice(m.from,m.to),C=[],N=0;for(let M of y.content){let $=gS(M),V=N+$.length,j=Math.max(m.from,N),ie=Math.min(m.to,V),ue=M.kind==="text"||M.kind==="field"?M.format:null,ye=M.kind==="text"?M.hyperlink:void 0;(ue||ye)&&ie>j&&C.push(v({from:j-m.from,to:ie-m.from,format:v({},ue!=null?ue:{})},ye?{hyperlink:v({},ye)}:{})),N=V;}let T=(P=y.format)!=null&&P.hasNumbering&&y.format.numbering?mn(y.format.numbering):null;return v({text:E,runs:C},T?{listType:T}:{})}),Xn=(c,m,y)=>{var M;if(S&&!y&&c.anchor.paraId===c.focus.paraId)return ke({kind:"replace-range",anchor:c.anchor,focus:c.focus,text:m});if(jo(c,m))return true;let E=$a(c);if(!E)return false;let C=Ns(s,c.anchor,c.focus,m);if(!C||C.changes.length===0)return false;for(let $ of C.paragraphIds)b.add($);let N=null;for(let $=0;$<((M=y==null?void 0:y.length)!=null?M:0);$+=1){let V=y[$],j=C.paragraphIds[$];if(!j)break;let ie=$===0?c.anchor.offset:0;for(let ue of V.runs){if(Object.keys(ue.format).length>0){let ye=Ts(s,j,ie+ue.from,ie+ue.to,ue.format);ye&&C.changes.push(ye);}if(ue.hyperlink){let ye=Rs(s,j,ie+ue.from,ie+ue.to,ue.hyperlink);ye&&C.changes.push(ye);}}if(V.listType){(!N||N.type!==V.listType)&&(N={type:V.listType,numbering:xs(s,V.listType)});let ue=_r(s,j,N.numbering);ue&&C.changes.push(ue);}else N=null;}if(S){let $=ot(s),V=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:$,revisionKind:"insert",author:"User",date:new Date().toISOString()})).filter(j=>j!==null);C.changes.push(...V);}fi(s);let T=C.paragraphIds.map($=>J(s,$)).filter($=>$!==null).map(ge),P={source:"local",range:c,beforeParagraphs:E,afterParagraphs:T,changesStart:u.length,changes:C.changes};return u.push(...C.changes),K.push(P),Y.length=0,z=null,g=null,Wt(P,T,C.cursor)?Be(E[0].paraId,C.cursor):Pe(C.cursor),se(v({kind:"caret"},C.cursor)),Re("deferred"),true},Ga=(c,m,y={})=>{var j,ie;let E=$a(c);if(!E)return false;let C=Ns(s,c.anchor,c.focus,"");if(!C)return false;for(let ue of C.paragraphIds)b.add(ue);let N=cu(s,C.cursor.paraId,C.cursor.offset,m,y);if(!N||N.kind!=="image")return false;let T=[...C.changes,N];if(S){let ue=ot(s),ye=(j=J(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:${ue}`,revisionId:ue,revisionKind:"insert",author:"User",date:new Date().toISOString()},T.push({kind:"image",op:"insert",paraId:N.paraId,offset:N.offset,drawingId:N.drawingId,revisionId:ue,revisionKind:"insert"}));}let P={paraId:C.cursor.paraId,offset:C.cursor.offset+1},M=C.paragraphIds.map(ue=>J(s,ue)).filter(ue=>ue!==null).map(ge),$=v({source:"local",patchMode:"individual",deferLayoutReflow:true,range:c,beforeParagraphs:E,afterParagraphs:M,changesStart:u.length,changes:T},y.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:N.drawingId,offset:C.cursor.offset}}:{});u.push(...T),K.push($),Y.length=0,g=y.select?{paraId:C.cursor.paraId,drawingId:N.drawingId}:null,z=null;let V=(ie=J(s,N.paraId))==null?void 0:ie.content.find(ue=>ue.kind==="image"&&ue.drawingId===N.drawingId);return (!V||V.kind!=="image"||!sg(c,V,P))&&(Wt($,M,P)||Pe(P)),Ho(E[0].paraId),g&&_t(),se(g?{kind:"object",paraId:g.paraId,objectKind:"image",objectId:g.drawingId,offset:C.cursor.offset}:v({kind:"caret"},P)),Re("deferred"),true},sg=(c,m,y)=>{if(c.anchor.paraId!==c.focus.paraId)return false;let E=Ks(t,c.anchor,c.focus);if(!E)return false;let C=t.querySelector(`coco-word-native-p[data-para-id="${c.anchor.paraId}"]`);return !C||!C.contains(E.commonAncestorContainer)?false:(E.deleteContents(),E.insertNode(Gs(m)),dt(t,y),true)},Ar=()=>{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},ja=(c,m=Ar())=>{let y=J(s,c.paraId);if(!y)return false;let E=ge(y),C=Ms(s,c.paraId,c.offset,m);if(!C)return false;let N=[c.paraId,m].map(M=>J(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:[E],afterParagraphs:N,changesStart:u.length,changes:[C]};return u.push(C),K.push(P),Y.length=0,z=null,g=null,Wt(P,N,T)?Be(c.paraId,T):Pe(T),se(v({kind:"caret"},T)),Re("deferred"),true},xd=c=>{if(c.offset!==0)return false;let m=ve(s,c.paraId),y=m==null?void 0:m.previous;if(!m||!y)return false;let E=[ge(y),ge(m.paragraph)],C={paraId:y.paraId,offset:Te(y).length},N=u.length,T=jr(s,c.paraId,0),P=J(s,y.paraId);if(!T||T.kind!=="block"||!P)return false;let M={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:E,afterParagraphs:[ge(P)],changesStart:N,changes:[T]};return u.push(T),K.push(M),Y.length=0,z=null,g=null,Wt(M,M.afterParagraphs,C)?Be(y.paraId,C):Pe(C),se(v({kind:"caret"},C)),Re("deferred"),true},yd=c=>{let m=ve(s,c.paraId);if(!m||c.offset!==Te(m.paragraph).length)return false;let y=m.container[m.index+1];if((y==null?void 0:y.kind)!=="paragraph")return false;let E=[ge(m.paragraph),ge(y)],C=u.length,N=Ur(s,c.paraId,c.offset),T=J(s,c.paraId);if(!N||N.kind!=="block"||!T)return false;let P={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:E,afterParagraphs:[ge(T)],changesStart:C,changes:[N]};return u.push(N),K.push(P),Y.length=0,z=null,g=null,Wt(P,P.afterParagraphs,c)?Be(c.paraId,c):Pe(c),se(v({kind:"caret"},c)),Re("deferred"),true},wt=(c,m,y,E=false)=>{if(y.length===0||m.length===0)return false;let C=m.map(M=>J(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:C,changesStart:u.length,changes:y,beforeSelection:c,afterSelection:c};u.push(...y),K.push(T),Y.length=0,z=null,Wt(T,C)||Pe();let P=t.querySelector(":scope > coco-word-native-document");if(P&&yn(P),c.kind==="text-range"?vn(t,c.anchor,c.focus):c.kind==="object"?(g={paraId:c.paraId,drawingId:c.objectId},_t()):c.kind==="caret"&&dt(t,{paraId:c.paraId,offset:c.offset}),E){let M=c.kind==="caret"||c.kind==="object"?{paraId:c.paraId,offset:c.offset}:void 0;Be(m[0].paraId,M,c);}return c.kind==="object"&&g&&_t(),se(c),Re("deferred"),true},vd=(c,m)=>{if(c.length===0)return 0;let y=Array.from(new Set(c.map(V=>V.paraId))),E=y.map(V=>J(s,V)).filter(V=>V!==null).map(ge);if(E.length===0)return 0;let C=u.length,N=[],T=[...c].sort((V,j)=>V.paraId===j.paraId?j.from-V.from:y.indexOf(j.paraId)-y.indexOf(V.paraId));for(let V of T)N.push(...Kr(s,V.paraId,V.from,V.to,m));if(N.length===0)return 0;let P=E.map(V=>J(s,V.paraId)).filter(V=>V!==null).map(ge),M=c[0],$=v({source:"local",patchMode:"individual",range:{anchor:{paraId:M.paraId,offset:M.from},focus:{paraId:M.paraId,offset:M.to}},beforeParagraphs:E,afterParagraphs:P,changesStart:C,changes:N},h?{beforeSelection:h,afterSelection:h}:{});return u.push(...N),K.push($),Y.length=0,z=null,Wt($,P)?Ft(h):Pe(void 0,h!=null?h:void 0),Be(M.paraId),Re(),c.length},lg=c=>{if(d)return false;let m=k&&k.activeIndex>=0?k.matches[k.activeIndex]:null;return m?vd([m],c)>0:false},dg=c=>d?0:k?vd(k.matches,c):0,ke=c=>{var y,E,C,N,T,P,M,$,V,j,ie,ue,ye,Me;if(l||d)return false;ut();let m=(y=h!=null?h:ze(t))!=null?y:lt(t);if(c.kind==="toggle-track-revisions")return S=!S,Ha(),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,ne=c.kind==="accept-all-revisions"||c.kind==="reject-all-revisions",re=new Set(K.flatMap(me=>lr(me)?me.changes.filter(we=>we.kind==="table"&&!!(we.revisionAction&&we.revisionId)).map(we=>we.revisionId):[])),he=me=>(me&&ne&&ke(c),me),pe=K.filter(me=>lr(me)&&me.changes.some(we=>we.kind==="table"&&!we.revisionAction&&!!we.revisionId&&!re.has(we.revisionId))&&me.afterBlocks.some(we=>{var Ne,de,Ke;if(we.kind!=="table"||((Ne=we.revision)==null?void 0:Ne.kind)!=="revision"||re.has(we.revision.revisionId))return false;let De=(Ke=(de=Oe(s,we.tableId))==null?void 0:de.table.revision)==null?void 0:Ke.revisionId;return ne?!!De:De===we.revision.revisionId&&we.revision.revisionId===_&&(!Q||we.revision.revisionKind===Q)}));if(pe.length>0){let me=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",we=new Map;for(let De of pe){let Ne=De.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 de=(E=we.get(Ne.tableId))!=null?E:[];de.push(De),we.set(Ne.tableId,de);}for(let[De,Ne]of we){let de=Ne[Ne.length-1];if(!de)continue;let Ke=de.afterBlocks.find(Zo=>{var Zn;return Zo.kind==="table"&&((Zn=Zo.revision)==null?void 0:Zn.kind)==="revision"});if(!Ke||Ke.kind!=="table"||!Ke.revision)continue;let je=Oe(s,De);if(!je)continue;let tn=[rt([je.table])[0]],An=rt([je.table])[0];if(!An||An.kind!=="table")continue;me==="accept"&&(An.revision=void 0,je.table.revision=void 0);let Yn=me==="accept"?[An]:rt((N=(C=Ne[0])==null?void 0:C.beforeBlocks)!=null?N:de.beforeBlocks);me==="reject"&&je.container.splice(je.tableIndex,1,...rt(Yn));let Yo=Ne.flatMap(Zo=>Zo.changes.filter(Zn=>Zn.kind==="table").map(Zn=>F(v({},Zn),{revisionAction:me}))),Ya={source:"local",range:de.range,container:je.container,startIndex:je.tableIndex,beforeBlocks:tn,afterBlocks:Yn,changesStart:u.length,changes:Yo,beforeSelection:m!=null?m:void 0,afterSelection:m!=null?m:void 0};u.push(...Ya.changes),K.push(Ya),Y.length=0,Bt(Ya,Yn,void 0)?Be(((T=tn[0])==null?void 0:T.kind)==="paragraph"?tn[0].paraId:(V=($=(M=(P=je.table.rows[0])==null?void 0:P.cells[0])==null?void 0:M.paragraphs[0])==null?void 0:$.paraId)!=null?V:"",void 0):Pe(),Re("deferred");}return he(true)}let Z=_e(s).flatMap(me=>{var Ne;let we=0,De=[];for(let de of me.content)de.kind==="image"&&(((Ne=de.revision)==null?void 0:Ne.kind)==="revision"&&(ne||de.revision.revisionId===_&&(!Q||de.revision.revisionKind===Q))||de.formatRevision&&(ne||de.formatRevision.revisionId===_&&(!Q||Q==="format")))&&De.push({paraId:me.paraId,drawingId:de.drawingId,offset:we}),we+=de.kind==="text"?de.text.length:1;return De});if(Z.length>0){let me=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",we=Array.from(new Set(Z.map(de=>de.paraId))).map(de=>J(s,de)).filter(de=>de!==null).map(ge),De=Z.map(de=>{var je;let Ke=(je=J(s,de.paraId))==null?void 0:je.content.find(tn=>tn.kind==="image"&&tn.drawingId===de.drawingId);return (Ke==null?void 0:Ke.kind)==="image"&&Ke.formatRevision?Cu(s,de.paraId,de.drawingId,me):Eu(s,de.paraId,de.drawingId,me)}).filter(de=>de!==null);if(De.length===0)return false;let Ne=Z[0];return he(wt({kind:"caret",paraId:Ne.paraId,offset:Ne.offset},we,De,true))}let Ie=_e(s).flatMap(me=>{let we=0,De=[];for(let Ne of me.content){let de=Ne.kind==="text"?Ne.text.length:1;Ne.kind==="text"&&Ne.formatRevision&&(ne||Ne.formatRevision.revisionId===_&&(!Q||Q==="format"))&&De.push({paraId:me.paraId,from:we,to:we+de}),we+=de;}return De});if(Ie.length>0){let me=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",we=Array.from(new Set(Ie.map(de=>de.paraId))).map(de=>J(s,de)).filter(de=>de!==null).map(ge),De=Ie.map(de=>yu(s,de.paraId,de.from,de.to,me)).filter(de=>de!==null);if(De.length===0)return false;let Ne=Ie[0];return he(wt({kind:"caret",paraId:Ne.paraId,offset:Ne.from},we,De,true))}let He=ne?_e(s).flatMap(me=>{var Ne;let we=[],De=0;for(let de of me.content){let Ke=de.kind==="text"?de.text.length:1;de.kind==="text"&&((Ne=de.marks)!=null&&Ne.some(je=>je.kind==="revision"))&&we.push({paraId:me.paraId,from:De,to:De+Ke}),De+=Ke;}return we}):_?_e(s).flatMap(me=>{var Ne;let we=[],De=0;for(let de of me.content){let Ke=de.kind==="text"?de.text.length:1;de.kind==="text"&&((Ne=de.marks)!=null&&Ne.some(je=>je.kind==="revision"&&je.revisionId===_&&(!Q||je.revisionKind===Q)))&&we.push({paraId:me.paraId,from:De,to:De+Ke}),De+=Ke;}return we}):en(m);if(He.length===0)return false;(ne||_)&&He.sort((me,we)=>me.paraId===we.paraId?we.from-me.from||we.to-me.to:we.paraId.localeCompare(me.paraId));let be=He.map(me=>J(s,me.paraId)).filter(me=>me!==null).map(ge),Fe=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",fe=He.map(me=>xu(s,me.paraId,me.from,me.to,Fe)).filter(me=>me!==null);if(fe.length===0)return false;let Je=m!=null?m:{kind:"caret",paraId:He[0].paraId,offset:He[0].from};return he(wt(Je,be,fe,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 re;let Q=on(s,m.paraId,m.offset,c.text);if(!S||!Q||c.text.length===0)return Q;let ne=$t(s,m.paraId,m.offset,_.offset,{revisionId:(re=Tr(m.paraId,m.offset,"insert","before"))!=null?re:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()});return ne?[Q,ne]:Q})}if(c.kind==="replace-range"&&c.anchor.paraId===c.focus.paraId){let _=Hi(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 ne=[],re=$t(s,c.anchor.paraId,_.from,_.to,{revisionId:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()});if(re&&ne.push(re),c.text.length>0){let he=on(s,c.anchor.paraId,_.to,c.text);he&&ne.push(he);let pe=$t(s,c.anchor.paraId,_.to,_.to+c.text.length,{revisionId:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()});pe&&ne.push(pe);}return ne}):Mn({anchor:c.anchor,focus:c.focus},Q,{paraId:c.anchor.paraId,offset:_.from+c.text.length},()=>Kr(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 ne=Array.from(new Map(Q.map(Z=>J(s,Z.paraId)).filter(Z=>Z!==null).map(Z=>[Z.paraId,ge(Z)])).values()),re=ot(s),he=Q.map(Z=>$t(s,Z.paraId,Z.from,Z.to,{revisionId:re,revisionKind:"delete",author:"User",date:new Date().toISOString()})).filter(Z=>Z!==null);if(he.length===0)return false;let pe=wt(_,ne,he,false);if(pe){let Z=nt(s,_),Ie={paraId:Z.anchor.paraId,offset:Z.anchor.offset};dt(t,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(Uo(_))return true;let Q=Hi(c.anchor.offset,c.focus.offset);return S?Mn({anchor:c.anchor,focus:c.focus},_,{paraId:c.anchor.paraId,offset:Q.from},()=>{var ne;return $t(s,c.anchor.paraId,Q.from,Q.to,{revisionId:(ne=Tr(c.anchor.paraId,Q.from,"delete","at"))!=null?ne: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 ja({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 Ga(_,c.src,F(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 _=J(s,m.paraId);if(!_)return false;let Q=ge(_),ne=_.content.find(Z=>Z.kind==="image"&&Z.drawingId===m.objectId),re=(ne==null?void 0:ne.kind)==="image"?ne.width:void 0,he=(ne==null?void 0:ne.kind)==="image"?ne.height:void 0,pe=pu(s,m.paraId,m.objectId,{width:c.width,height:c.height});if(S&&pe){let Z=_.content.find(Ie=>Ie.kind==="image"&&Ie.drawingId===m.objectId);(Z==null?void 0:Z.kind)==="image"&&(Z.formatRevision={kind:"format",revisionId:ot(s),beforeWidth:re,beforeHeight:he,afterWidth:c.width,afterHeight:c.height,author:"User",date:new Date().toISOString()},pe.kind==="image"&&(pe.revisionId=Z.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 rg(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 tg(m,c);if((m==null?void 0:m.kind)==="table-cell-range"&&(c.kind==="merge-table-cells"||c.kind==="split-table-cell"))return ng(m,c);if(m&&(c.kind==="set-table-cell-background"||c.kind==="set-table-cell-vertical-alignment"||c.kind==="set-table-cell-borders"))return og(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 Uo(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 he=m.offset-1;return Mn({anchor:m,focus:m},m,{paraId:m.paraId,offset:he},()=>{var pe;return $t(s,m.paraId,he,m.offset,{revisionId:(pe=Tr(m.paraId,he,"delete","after"))!=null?pe:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})})}if(Rn(m,"delete-backward")||Ko(m,"backward")||xd({paraId:m.paraId,offset:m.offset}))return true;let _=J(s,m.paraId),Q=_?ge(_):null,ne=jr(s,m.paraId,m.offset),re={paraId:m.offset>0?m.paraId:(j=ms(s,m.paraId))!=null?j:m.paraId,offset:Math.max(0,m.offset-1)};return (ne==null?void 0:ne.kind)==="image"?Mr(Q,ne,re):Tn(ne,re,(ne==null?void 0:ne.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 Uo(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<Oa(m.paraId))return Mn({anchor:m,focus:m},m,m,()=>{var he;return $t(s,m.paraId,m.offset,m.offset+1,{revisionId:(he=Tr(m.paraId,m.offset,"delete","at"))!=null?he:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})});if(Rn(m,"delete-forward")||Ko(m,"forward")||yd({paraId:m.paraId,offset:m.offset}))return true;let _=J(s,m.paraId),Q=_?ge(_):null,ne=Ur(s,m.paraId,m.offset),re={paraId:m.paraId,offset:m.offset};return (ne==null?void 0:ne.kind)==="image"?Mr(Q,ne,re):Tn(ne,re,{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(re=>J(s,re.paraId)).filter(re=>re!==null).map(ge),ne=_.map(re=>Rs(s,re.paraId,re.from,re.to,c.kind==="set-hyperlink"?c.hyperlink:null)).filter(re=>re!==null);return wt(m,Q,ne,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(Z=>J(s,Z.paraId)).filter(Z=>Z!==null).map(ge),ne=Ip(s),re=(ie=c.date)!=null?ie:new Date().toISOString(),he=_.map(Z=>{var Ie;return Ps(s,Z.paraId,Z.from,Z.to,{commentId:ne,author:(Ie=c.author)!=null?Ie:"User",date:re,body:c.body.trim()})}).filter(Z=>Z!==null),pe=wt(m,Q,he,false);return pe&&he.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(re=>re.content.some(he=>{var pe;return he.kind==="text"&&((pe=he.marks)==null?void 0:pe.some(Z=>Z.kind==="comment"&&Z.commentId===c.commentId))})).map(ge);if(_.length===0)return false;let Q=c.kind==="edit-comment"?bu(s,c.commentId,c.body.trim()):wu(s,c.commentId);if(Q.length===0)return false;let ne=m!=null?m:{kind:"caret",paraId:_[0].paraId,offset:0};return wt(ne,_,Q,false)}if(c.kind==="reply-comment"){let _=c.body.trim();if(!_)return false;let Q=null;for(let pe of _e(s)){let Z=0;for(let Ie of pe.content){let He=Ie.kind==="text"?Ie.text.length:1;if(Ie.kind==="text"&&((ue=Ie.marks)!=null&&ue.some(be=>be.kind==="comment"&&be.commentId===c.commentId))){Q={paragraph:pe,from:Z,to:Z+He};break}Z+=He;}if(Q)break}if(!Q)return false;let ne=ge(Q.paragraph),re=Ip(s),he=Ps(s,Q.paragraph.paraId,Q.from,Q.to,{commentId:re,parentCommentId:c.commentId,preserveExistingComments:true,author:"User",date:new Date().toISOString(),body:_});return he?(Pe(),wt(m!=null?m:{kind:"caret",paraId:Q.paragraph.paraId,offset:Q.from},[ne],[he],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=>J(s,pe.paraId)).filter(pe=>pe!==null).map(ge),ne=ot(s),re=(ye=c.date)!=null?ye:new Date().toISOString(),he=_.map(pe=>{var Z;return $t(s,pe.paraId,pe.from,pe.to,{revisionId:ne,revisionKind:c.revisionKind,author:(Z=c.author)!=null?Z:"User",date:re})}).filter(pe=>pe!==null);return wt(m,Q,he,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(Z=>J(s,Z.paraId)).filter(Z=>Z!==null).map(ge),ne=Rt(m),re=null;if(c.kind==="toggle-bold"&&(re={bold:ne.bold!==true}),c.kind==="toggle-italic"&&(re={italic:ne.italic!==true}),c.kind==="toggle-underline"&&(re={underline:ne.underline!==true}),c.kind==="toggle-strike"&&(re={strike:ne.strike!==true}),c.kind==="set-font-family"&&c.fontFamily.trim()&&(re={fontFamily:c.fontFamily.trim()}),c.kind==="set-font-size"&&(re={fontSize:c.fontSize}),c.kind==="set-text-color"&&(re={color:c.color.replace(/^#/,"").toUpperCase()}),c.kind==="set-highlight-color"&&(re={highlight:c.color?c.color.replace(/^#/,"").toUpperCase():"none"}),c.kind!=="clear-text-format"&&!re)return false;let he=_.map(Z=>c.kind==="clear-text-format"?vu(s,Z.paraId,Z.from,Z.to):Ts(s,Z.paraId,Z.from,Z.to,re)).filter(Z=>Z!==null);if(S){let Z=ot(s),Ie=_.map(He=>ku(s,He.paraId,He.from,He.to,Q.find(be=>be.paraId===He.paraId),{revisionId:Z,author:"User",date:new Date().toISOString()})).filter(He=>He!==null);he.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,he,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(gd(m)));if(!m||_.length===0)return false;let Q=_.map(re=>J(s,re)).filter(re=>re!==null).map(ge),ne=_.map(re=>{var pe,Z,Ie;let he=J(s,re);if(!he)return null;if(c.kind==="set-paragraph-alignment")return er(s,re,{alignment:c.alignment});if(c.kind==="set-paragraph-indent")return er(s,re,{indent:wS(c.indent)});if(c.kind==="adjust-paragraph-left-indent"){let He=Math.max(0,((Ie=(Z=(pe=he.format)==null?void 0:pe.indent)==null?void 0:Z.left)!=null?Ie:0)+c.delta);return er(s,re,{indent:{left:He}})}return c.kind==="set-paragraph-spacing"?er(s,re,{spacing:xS(c.spacing)}):er(s,re,{spacing:{line:Math.max(0,c.line),lineRule:c.lineRule}})}).filter(re=>re!==null);return wt(m,Q,ne,c.kind!=="set-paragraph-alignment")}if(c.kind==="toggle-list"||c.kind==="remove-list"||c.kind==="adjust-list-level"){let _=Array.from(new Set(gd(m)));if(!m||_.length===0)return false;let Q=_.map(Z=>J(s,Z)).filter(Z=>Z!==null),ne=Q.map(ge),re=c.kind==="toggle-list"&&Q.every(Z=>{var Ie;return ((Ie=Z.format)==null?void 0:Ie.hasNumbering)&&mn(Z.format.numbering)===c.listType}),he=c.kind==="toggle-list"&&!re?(Me=Yc(s,_,c.listType))!=null?Me:xs(s,c.listType):null,pe=Q.map(Z=>{var Ie,He,be,Fe,fe;if(c.kind==="remove-list"||re)return (Ie=Z.format)!=null&&Ie.hasNumbering?_r(s,Z.paraId,null):null;if(c.kind==="toggle-list"&&he){let Je=(Fe=(be=(He=Z.format)==null?void 0:He.numbering)==null?void 0:be.ilvl)!=null?Fe:0;return _r(s,Z.paraId,ys(he,Je))}if(c.kind==="adjust-list-level"){let Je=(fe=Z.format)!=null&&fe.hasNumbering?Z.format.numbering:void 0;return Je?_r(s,Z.paraId,ys(Je,Je.ilvl+c.delta)):null}return null}).filter(Z=>Z!==null);return fi(s),wt(m,ne,pe,true)}return false},Sd=c=>{var P;let m=(P=Oe(s,c.tableId))==null?void 0:P.table;if(!m)return null;let y=Math.min(c.anchor.rowIndex,c.focus.rowIndex),E=Math.max(c.anchor.rowIndex,c.focus.rowIndex),C=Math.min(c.anchor.columnIndex,c.focus.columnIndex),N=Math.max(c.anchor.columnIndex,c.focus.columnIndex),T=Array.from({length:E-y+1},()=>Array.from({length:N-C+1},()=>null));for(let{cell:M,rowIndex:$,columnIndex:V}of tt(m,c)){let j=T[$-y];j&&V>=C&&V<=N&&(j[V-C]={text:M.paragraphs.map(ie=>Te(ie)).join(`
|
|
1611
|
+
`,(o!=null?o:document.head).appendChild(Ma);let bt=(Ud=globalThis.CSS)==null?void 0:Ud.highlights,Ir=globalThis.Highlight,id=()=>{bt==null||bt.delete(Ta),bt==null||bt.delete(Pa);},Aa=()=>{bt==null||bt.delete(Ra);},at=(c=false)=>{if(Aa(),(h==null?void 0:h.kind)!=="text-range"||!c&&(document.activeElement===i||t.contains(document.activeElement))||!bt||!Ir)return;let m=nt(s,h),y=Ks(t,m.anchor,m.focus);y&&!y.collapsed&&bt.set(Ra,new Ir(y));},Wo=()=>{if(id(),!k||!bt||!Ir)return;let c=[],m=null;k.matches.forEach((y,E)=>{let C=kf(t,y.paraId,y.from,y.to);C&&(E===k.activeIndex?m=C:c.push(C));}),c.length>0&&bt.set(Ta,new Ir(...c)),m&&bt.set(Pa,new Ir(m));},Bo=()=>k?{options:v({},k.options),matches:k.matches.map(c=>v({},c)),activeIndex:k.activeIndex}:null,Um=()=>{if(!k)return;let c=qs(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)},Wo(),at();},ad=()=>{let c=k&&k.activeIndex>=0?k.matches[k.activeIndex]:null,m=c?t.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"]`):null;m==null||m.scrollIntoView({block:"center",inline:"nearest"});},Km=c=>{let m={query:c.query,matchCase:!!c.matchCase,wholeWord:!!c.wholeWord},y=qs(s,m);return k={options:m,matches:y,activeIndex:y.length>0?0:-1},Wo(),ad(),Bo()},_m=(c="forward")=>{if(!k||k.matches.length===0)return Bo();let m=c==="backward"?-1:1;return k=H(v({},k),{activeIndex:(k.activeIndex+m+k.matches.length)%k.matches.length}),Wo(),ad(),Bo()},La=()=>{k=null,id();},_n=()=>{ht==null||ht.remove(),ht=null;},Da=()=>{if(!ht||!g)return;let c=t.querySelector(`coco-word-native-p[data-para-id="${g.paraId}"] img[data-drawing-id="${g.drawingId}"]`);if(!c){_n();return}let m=t.getBoundingClientRect(),y=c.getBoundingClientRect();ht.style.left=`${y.right-m.left+t.scrollLeft-6}px`,ht.style.top=`${y.bottom-m.top+t.scrollTop-6}px`;},_t=()=>{if(d){_n();return}if(!g){_n();return}if(Ef(t,g),!!t.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",y=>{y.preventDefault(),y.stopPropagation();}),m.addEventListener("pointerdown",y=>{if(!g||y.button!==0)return;ut();let E=v({},g),C=t.querySelector(`coco-word-native-p[data-para-id="${E.paraId}"] img[data-drawing-id="${E.drawingId}"]`);if(!C)return;Ze==null||Ze(),y.preventDefault(),y.stopPropagation(),m.setPointerCapture(y.pointerId);let N=C.getBoundingClientRect(),T=y.clientX,R=y.clientY,M=Math.max(1,N.width),$=Math.max(1,N.height),V=M/$,j=M,re=$,ue=Ae=>{let X=Ae.clientX-T,Q=Ae.clientY-R;if(Ae.shiftKey)j=Math.max(24,M+X),re=Math.max(24,$+Q);else {let te=Math.abs(X)>=Math.abs(Q)?X:Q*V;j=Math.max(24,M+te),re=Math.max(24,j/V);}C.style.width=`${j}px`,C.style.height=`${re}px`,Da();},ye=Ae=>{Ze==null||Ze(),Ze=null,m.hasPointerCapture(Ae.pointerId)&&m.releasePointerCapture(Ae.pointerId),Ee({kind:"set-image-size",objectId:E.drawingId,width:Math.round(j*100)/100,height:Math.round(re*100)/100});};document.addEventListener("pointermove",ue,true),document.addEventListener("pointerup",ye,true),document.addEventListener("pointercancel",ye,true),Ze=()=>{document.removeEventListener("pointermove",ue,true),document.removeEventListener("pointerup",ye,true),document.removeEventListener("pointercancel",ye,true);};}),t.appendChild(m),ht=m;}Da();}},Fo=()=>Da();window.addEventListener("resize",Fo),document.addEventListener("scroll",Fo,true);let sd=()=>{if(r.setAttribute("aria-readonly",String(d)),t.dataset.readOnly=String(d),!!d){for(let c of Array.from(t.querySelectorAll('[contenteditable="true"]')))c.contentEditable="false";_n();}},Re=(c,m)=>{F!==null&&(window.clearTimeout(F),F=null),A!==null&&(window.clearTimeout(A),A=null),fi(s);let y=zu(s);t.replaceChildren(y),Gu(y,s),sd(),Fa(y);let E=(m==null?void 0:m.kind)==="table-cell-range"?m:(h==null?void 0:h.kind)==="table-cell-range"?h:null;Pn(E),Wo(),at(),g&&_t(),(m==null?void 0:m.kind)==="text-range"?Sn(t,m.anchor,m.focus):c&&dt(t,c);},Wa=(c,m)=>{var N;let y=J(s,c);if(!y){Re(m);return}let E=Array.from(t.querySelectorAll(`coco-word-native-p[data-para-id="${c}"]`));if(E.length===0){Re(m);return}for(let T of E)T.replaceWith(no(y));sd();let C=(N=t.querySelector(":scope > coco-word-native-document"))!=null?N:t.querySelector("coco-word-native-document");C&&vn(C),g&&_t(),m&&dt(t,m);},ld=(c,m)=>c.querySelector(`table[data-shared-grid] coco-word-native-p[data-para-id="${m}"]`)!==null,Be=(c,m,y)=>{var N;let E=t.querySelector(":scope > coco-word-native-document");if(!E)return false;if(ld(E,c)){let T=y!=null?y:m?void 0:(N=ze(t))!=null?N:void 0;return Re(m!=null?m:(T==null?void 0:T.kind)==="caret"?T:void 0,T),true}let C=ju(E,s,c);Fa(E);for(let T of Array.from(E.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img`)))T.complete||Se.has(T)||(Se.add(T),T.addEventListener("load",()=>{Se.delete(T),Be(c);},{once:true}));return (y==null?void 0:y.kind)==="text-range"?Sn(t,y.anchor,y.focus):m&&dt(t,m),C},pn=(c,m=180,y)=>{ae||ie||(A!==null&&window.clearTimeout(A),A=window.setTimeout(()=>{var N;if(A=null,ae||ie)return;let E=(N=t.querySelector(":scope > coco-word-native-document"))!=null?N:t.querySelector("coco-word-native-document");if(!E||y&&!y(E))return;let C=(h==null?void 0:h.kind)==="object"?h:ze(t);if((C==null?void 0:C.kind)==="text-range")Be(c,void 0,C);else if((C==null?void 0:C.kind)==="object")Be(c),g={paraId:C.paraId,drawingId:C.objectId},_t();else {let T=(C==null?void 0:C.kind)==="caret"?C:pt(t);Be(c,T!=null?T:void 0);}},m));},Ho=(c,m=80)=>{var C;let y=(C=t.querySelector(":scope > coco-word-native-document"))!=null?C:t.querySelector("coco-word-native-document");if(!y)return;let E=false;for(let N of Array.from(y.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img`)))N.complete||Se.has(N)||(E=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,E?800:m);},Nr=c=>{var y;if((_==null?void 0:_.paraId)===c)return;let m=(y=t.querySelector(":scope > coco-word-native-document"))!=null?y:t.querySelector("coco-word-native-document");m&&(_={paraId:c,measurement:Os(m,s,c)});},Ba=c=>{pn(c,700,m=>{let y=_;if(_=null,!y||y.paraId!==c)return false;if(ld(m,c))return true;let E=Os(m,s,c);return E.overflowPx>Math.max(1,y.measurement.overflowPx+1)||!y.measurement.canBackfillPrevious&&E.canBackfillPrevious||!y.measurement.canBackfillNext&&E.canBackfillNext});},Oo=new WeakMap,$o=new ResizeObserver(c=>{var m,y;for(let E of c){let C=E.target;if(!(C instanceof HTMLElement))continue;let N=Math.round(E.contentRect.height),T=Oo.get(C);if(Oo.set(C,N),T===void 0||Math.abs(T-N)<=1)continue;let R=(m=C.querySelector("coco-word-native-p[data-para-id]"))==null?void 0:m.dataset.paraId;if(R){let M=document.activeElement;if(M&&C.contains(M)){let $=(y=M.closest("coco-word-native-p[data-para-id]"))==null?void 0:y.dataset.paraId;Ba($!=null?$:R);}else pn(R);}}}),Fa=c=>{for(let m of Array.from(c.querySelectorAll("coco-word-native-table")))Oo.has(m)||(Oo.set(m,Math.round(m.getBoundingClientRect().height)),$o.observe(m));},Me=(c="immediate")=>{if(l)return;let m=()=>{var E;Um();let y=Cp(f,u,++p);f=u.slice(),(E=n.onChange)==null||E.call(n,y),fn("change",y);};if(c==="immediate"){ee!==null&&(window.clearTimeout(ee),ee=null),m();return}ee!==null&&window.clearTimeout(ee),ee=window.setTimeout(()=>{ee=null,m();},180);},Ha=()=>{l||(le!==null&&window.clearTimeout(le),le=window.setTimeout(()=>{var y,E;le=null;let c=(y=h!=null?h:ze(t))!=null?y:lt(t),m={selection:c,commandState:Rt(c)};(E=n.onSelectionChange)==null||E.call(n,m),fn("selectionChange",m);},80));},dd=c=>{B=c,U!==null&&window.clearTimeout(U),U=window.setTimeout(()=>{B=null,U=null;},1e3);},qm=(c,m,y)=>{let E=Array.from(t.querySelectorAll(`coco-word-native-p[data-para-id="${c}"] img[data-drawing-id="${m}"]`));for(let C of E)C.remove();Pt(t),y&&dt(t,y);},Rn=(c,m,y={})=>{Array.isArray(c)?u.push(...c):c&&u.push(c),c&&(K.length=0),y.localParaId?(Wa(y.localParaId,m),pn(y.localParaId)):Re(m),Me();},zo=c=>{let m=J(s,c);return !!m&&m.content.every(y=>y.kind==="text")},Oa=c=>{let m=J(s,c);return m?Pe(m).length:0},Tr=(c,m,y,E)=>{var R,M;let C=J(s,c);if(!C)return null;let N=E==="before"?m-1:E==="after"?m+1:m;if(N<0)return null;let T=0;for(let $ of C.content){let V=$.kind==="text"?$.text.length:1;if(N>=T&&N<T+V){let j=$.kind==="text"?(R=$.marks)==null?void 0:R.find(re=>re.kind==="revision"&&re.revisionKind===y):void 0;return j&&"revisionId"in j&&(M=j.revisionId)!=null?M:null}T+=V;}return null},cd=(c,m)=>{var y;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:(y=Tr(c,m.offset,"insert","before"))!=null?y:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()})},$a=c=>{let m=ve(s,c.anchor.paraId),y=ve(s,c.focus.paraId);if(!m||!y||m.container!==y.container)return null;let E=Math.min(m.index,y.index),C=Math.max(m.index,y.index),N=[];for(let T=E;T<=C;T+=1){let R=m.container[T];if((R==null?void 0:R.kind)!=="paragraph"||R.content.some(M=>M.kind!=="text"))return null;N.push(be(R));}return N},ud=c=>{let m=$a(c);return m&&m.length>1?m:null},Xm=c=>{let m=ud(c);return m?(oe={range:c,beforeParagraphs:m,changesStart:u.length},true):false},Vo=c=>{var T;let m=c.anchor.paraId;if(c.focus.paraId!==m)return;let y=t.querySelector(`coco-word-native-p[data-para-id="${m}"]`),E=J(s,m);if(!(y!=null&&y.closest("coco-word-native-table"))||!E||((T=z==null?void 0:z.afterParagraphs[0])==null?void 0:T.paraId)===m)return;let C=be(E),N={source:"browser",patchMode:"individual",skipDeferredRender:true,range:c,beforeParagraphs:[C],afterParagraphs:[C],changesStart:u.length,changes:[]};G.push(N),K.length=0,z=N;},fd=c=>{if(d){c.preventDefault();return}ae=true,Y!==null&&(window.clearTimeout(Y),Y=null),ie&&za(),F!==null&&(window.clearTimeout(F),F=null),A!==null&&(window.clearTimeout(A),A=null),ee!==null&&(window.clearTimeout(ee),ee=null),le!==null&&(window.clearTimeout(le),le=null);let m=ze(t),y=c.target instanceof Node?Nt(c.target):null,E=y==null?void 0:y.dataset.paraId,C=pt(t),N=E?{paraId:E,offset:(C==null?void 0:C.paraId)===E?C.offset:Oa(E)}:C,T=N?J(s,N.paraId):null;if(!N||!T||T.content.some(M=>M.kind!=="text"))return;Nr(N.paraId),z=null;let R=(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};ie={paraId:N.paraId,beforeParagraph:be(T),changesStart:u.length,range:R};},za=()=>{var M;Y=null;let c=ie;if(ie=null,!c)return;let m=J(s,c.paraId);if(!m)return;let y=t.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"]`);if(!y)return;let E=qr(s,c.paraId,(M=y.textContent)!=null?M:"");E&&u.push(E);let C=cd(c.paraId,E);C&&u.push(C);let N=be(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)};G.push(T),K.length=0;let R=pt(t);R&&se(v({kind:"caret"},R)),Ba(c.paraId),C&&Wa(c.paraId,R!=null?R:void 0),Me("deferred");},pd=()=>{ae=false,Y!==null&&window.clearTimeout(Y),Y=window.setTimeout(za,80);},Go=(c,m)=>{var M,$;let y=new Set([...c.beforeParagraphs,...c.afterParagraphs].map(V=>V.paraId)),E=(M=[...c.beforeParagraphs,...c.afterParagraphs].find(V=>J(s,V.paraId)))==null?void 0:M.paraId;if(!E)return false;let C=ve(s,E);if(!C)return false;if(c.patchMode==="individual"){for(let V of m){let j=ve(s,V.paraId);if(!j)return false;Object.assign(j.paragraph,be(V));}return true}let N=Array.from(y).filter(V=>J(s,V));if(N.length===0||m.length===0)return false;let T=be(m[0]);Object.assign(C.paragraph,T);for(let V of N)V!==E&&(($=ve(s,V))==null||$.remove());let R=T.paraId;for(let V of m.slice(1)){let j=ve(s,R);if(!j)return false;let re=be(V);j.insertAfter(re),R=re.paraId;}return true},Ym=()=>{var T;if(!oe)return false;let c=oe;oe=null;let m=c.beforeParagraphs.map(R=>Mp(t,R.paraId)),y=m.every(R=>R!==null),E=[];if(y)for(let R=0;R<c.beforeParagraphs.length;R+=1){let M=c.beforeParagraphs[R],$=qr(s,M.paraId,(T=m[R])!=null?T:"");$&&E.push($);}else E.push(...bi(s,c.range.anchor,c.range.focus));if(E.length===0)return false;u.push(...E);let C=c.beforeParagraphs.map(R=>J(s,R.paraId)).filter(R=>R!==null);if(C.length>0){let R=H(v({},c),{source:"browser",afterParagraphs:C.map(be),changes:E});G.push(R),z=null,K.length=0;}let N=pt(t);return N&&se({kind:"caret",paraId:N.paraId,offset:N.offset}),Be(c.beforeParagraphs[0].paraId,N!=null?N:void 0),Me("deferred"),true},Zm=()=>{let c=G[G.length-1];if(!c||lr(c)||!Fi(t,c.beforeParagraphs)||!Go(c,c.beforeParagraphs))return false;G.pop(),K.push(c),u.splice(c.changesStart);let m=pt(t);return m&&se({kind:"caret",paraId:m.paraId,offset:m.offset}),Be(c.beforeParagraphs[0].paraId,m!=null?m:void 0),Me("deferred"),true},Jm=()=>{let c=K[K.length-1];if(!c||lr(c)||!Fi(t,c.afterParagraphs)||!Go(c,c.afterParagraphs))return false;K.pop(),G.push(c),u.splice(c.changesStart),u.push(...c.changes);let m=pt(t);return m&&se({kind:"caret",paraId:m.paraId,offset:m.offset}),Be(c.beforeParagraphs[0].paraId,m!=null?m:void 0),Me("deferred"),true},Wt=(c,m,y)=>{var $,V,j;if(c.patchMode==="individual"){let re=false;for(let ye of m){let Ae=Array.from(t.querySelectorAll(`coco-word-native-p[data-para-id="${ye.paraId}"]`));for(let X of Ae)X.replaceWith(no(ye)),re=true;}y&&dt(t,y);let ue=t.querySelector(":scope > coco-word-native-document");return ue&&vn(ue),re}let E=new Set([...c.beforeParagraphs,...c.afterParagraphs].map(re=>re.paraId)),C=Array.from(E).flatMap(re=>Array.from(t.querySelectorAll(`coco-word-native-p[data-para-id="${re}"]`))),N=($=c.beforeParagraphs[0])==null?void 0:$.paraId,T=(V=C.find(re=>re.dataset.paraId===N))!=null?V:C[0];if(!T)return false;let R=m.map(re=>no(re));T.replaceWith(...R);for(let re of C)re!==T&&re.isConnected&&re.remove();y&&dt(t,y);let M=(j=t.querySelector(":scope > coco-word-native-document"))!=null?j:t.querySelector("coco-word-native-document");return M&&vn(M),true},hd=(c,m,y)=>(c.container.splice(c.startIndex,y,...rt(m)),true),Bt=(c,m,y,E)=>{var $,V;let C=[...c.beforeBlocks,...c.afterBlocks].flatMap(j=>pS(t,j)),N=(($=c.afterBlocks[0])==null?void 0:$.kind)==="paragraph"?c.afterBlocks[0].paraId:((V=c.beforeBlocks[0])==null?void 0:V.kind)==="paragraph"?c.beforeBlocks[0].paraId:null,T=N?t.querySelector(`coco-word-native-p[data-para-id="${N}"]`):C[0];if(!T)return false;let R=m.map(j=>to(j));T.replaceWith(...R);for(let j of C)j!==T&&j.isConnected&&j.remove();let M=t.querySelector(":scope > coco-word-native-document");return M&&Fa(M),M&&vn(M),E?Sn(t,E.anchor,E.focus):y&&dt(t,y),true},Qm=c=>{let m=t.querySelector(`coco-word-native-p[data-para-id="${c.anchor.paraId}"]`),y=t.querySelector(`coco-word-native-p[data-para-id="${c.focus.paraId}"]`);return !!m&&!!y&&m.closest("coco-word-native-page")!==y.closest("coco-word-native-page")},md=(c,m)=>{let y=ud(c);if(!y)return false;let E={range:c,beforeParagraphs:y,changesStart:u.length},C=gu(s,c.anchor,c.focus,m);if(C.length===0)return false;let N=y.map(M=>J(s,M.paraId)).filter(M=>M!==null).map(be);if(N.length===0)return false;let T=H(v({},E),{source:"local",afterParagraphs:N,changes:C}),R={paraId:c.anchor.paraId,offset:c.anchor.offset+m.length};return u.push(...C),G.push(T),z=m.length>0?T:null,K.length=0,Wt(T,N,R)?Be(y[0].paraId,R):Re(R),se(v({kind:"caret"},R)),Me("deferred"),true},jo=(c,m)=>{let y=hu(s,c.anchor,c.focus,m);if(!y)return false;let E={source:"local",range:c,container:y.container,startIndex:y.startIndex,beforeBlocks:y.beforeBlocks,afterBlocks:y.afterBlocks,changesStart:u.length,changes:y.changes};if(u.push(...y.changes),G.push(E),K.length=0,z=null,g=null,!Bt(E,y.afterBlocks,y.cursor))Re(y.cursor);else {let C=t.querySelector(":scope > coco-word-native-document");C&&Vt(C,s,y.cursor.paraId),Be(y.cursor.paraId,y.cursor);}return se(v({kind:"caret"},y.cursor)),Me("deferred"),true},eg=(c,m)=>{let y=mu(s,c.anchor,c.focus,m);if(!y)return false;let E={source:"local",range:c,container:y.container,startIndex:y.startIndex,beforeBlocks:y.beforeBlocks,afterBlocks:y.afterBlocks,changesStart:u.length,changes:y.changes};u.push(...y.changes),G.push(E),K.length=0,z=null,g=null;for(let C of _e(s))b.add(C.paraId);if(!Bt(E,y.afterBlocks,y.cursor))Re(y.cursor);else {let C=t.querySelector(":scope > coco-word-native-document");C&&Vt(C,s,y.cursor.paraId),Be(y.cursor.paraId,y.cursor);}return se(v({kind:"caret"},y.cursor)),Me("deferred"),true},tg=(c,m)=>{let y=c.kind==="table-cell-range"?(()=>{var Ae,X,Q;let re=(Ae=Oe(s,c.tableId))==null?void 0:Ae.table,ue=re?(X=tt(re,c)[0])==null?void 0:X.cell:null,ye=(Q=ue==null?void 0:ue.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(!y)return false;let E=rn(s,y.paraId);if(!E)return false;let C=rt([E.table])[0];if(!C||C.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=ru(s,y.paraId,N,Ar);if(!T)return false;let R=rt([E.table])[0];if(!R||R.kind!=="table")return false;let M=S?ot(s):null,$=m.kind==="insert-table-row"||m.kind==="insert-table-column"?"insert":"delete";M&&(E.table.revision={kind:"revision",id:`revision:${M}`,revisionId:M,revisionKind:$,author:"User",date:new Date().toISOString()},R.revision=v({},E.table.revision),T.change.kind==="table"&&(T.change.revisionId=M,T.change.revisionKind=$,T.change.beforeTable=C));let V=v({kind:"caret"},T.cursor),j={source:"local",range:{anchor:y,focus:y},container:E.container,startIndex:E.tableIndex,beforeBlocks:[C],afterBlocks:[R],changesStart:u.length,changes:[T.change],beforeSelection:c,afterSelection:V};if(u.push(T.change),G.push(j),K.length=0,z=null,g=null,!Bt(j,j.afterBlocks,T.cursor))Re(T.cursor);else {let re=t.querySelector(":scope > coco-word-native-document");re&&Vt(re,s,T.cursor.paraId),Be(T.cursor.paraId,T.cursor);}return se(V),Me("deferred"),true},ng=(c,m)=>{let y=Oe(s,c.tableId);if(!y)return false;let E=rt([y.table])[0];if(!E||E.kind!=="table")return false;let N=tt(y.table,c)[0],T=m.kind==="merge-table-cells"?ou(s,c.tableId,c):N?iu(s,c.tableId,N.rowIndex,N.columnIndex,Ar):null;if(!T)return false;let R=rt([y.table])[0];if(!R||R.kind!=="table")return false;let M=S?ot(s):null,$=m.kind==="merge-table-cells"?"insert":"delete";M&&(y.table.revision={kind:"revision",id:`revision:${M}`,revisionId:M,revisionKind:$,author:"User",date:new Date().toISOString()},R.revision=v({},y.table.revision),T.change.kind==="table"&&(T.change.revisionId=M,T.change.revisionKind=$,T.change.beforeTable=E));let V={source:"local",range:{anchor:{paraId:T.cursor.paraId,offset:T.cursor.offset},focus:{paraId:T.cursor.paraId,offset:T.cursor.offset}},container:y.container,startIndex:y.tableIndex,beforeBlocks:[E],afterBlocks:[R],changesStart:u.length,changes:[T.change],beforeSelection:c,afterSelection:v({kind:"caret"},T.cursor)};if(u.push(T.change),G.push(V),K.length=0,z=null,g=null,!Bt(V,V.afterBlocks,T.cursor))Re(T.cursor);else {let j=t.querySelector(":scope > coco-word-native-document");j&&Vt(j,s,T.cursor.paraId),Be(T.cursor.paraId,T.cursor);}return se(v({kind:"caret"},T.cursor)),Me("deferred"),true},rg=(c,m)=>{let y=c.kind==="text-range"?c.anchor:c.kind==="table-cell-range"?(()=>{var V,j;let M=(V=Oe(s,c.tableId))==null?void 0:V.table,$=M?(j=tt(M,c)[0])==null?void 0:j.cell.paragraphs[0]:null;return $?{paraId:$.paraId,offset:0}:null})():{paraId:c.paraId,offset:c.offset};if(!y)return false;let E=m.kind==="insert-table"?c.kind==="caret"?tu(s,c.paraId,c.offset,m.rows,m.columns,Ar):null:(()=>{var $;let M=($=Rt(c).table)==null?void 0:$.tableId;return M?nu(s,M,Ar):null})();if(!E)return false;let C=S?ot(s):null,N=m.kind==="insert-table"?"insert":"delete";if(C){let M=E.afterBlocks.find($=>$.kind==="table");(M==null?void 0:M.kind)==="table"&&(M.revision={kind:"revision",id:`revision:${C}`,revisionId:C,revisionKind:N,author:"User",date:new Date().toISOString()},E.changes.forEach($=>{if($.kind==="table"){$.revisionId=C,$.revisionKind=N;let V=E.beforeBlocks.find(j=>j.kind==="table");if((V==null?void 0:V.kind)==="table"&&($.beforeTable=V),$.op==="insert-table"){$.anchorParaId=y.paraId,$.anchorOffset=y.offset;let j=E.afterBlocks.find(re=>re.kind==="table");(j==null?void 0:j.kind)==="table"&&($.tableSnapshot=j);}}}));}for(let M of E.changes){if(M.kind!=="table"||M.op!=="insert-table")continue;M.anchorParaId=y.paraId,M.anchorOffset=y.offset;let $=E.afterBlocks.find(V=>V.kind==="table");($==null?void 0:$.kind)==="table"&&(M.tableSnapshot=$);}let T=v({kind:"caret"},E.cursor),R={source:"local",range:{anchor:y,focus:c.kind==="text-range"?c.focus:y},container:E.container,startIndex:E.startIndex,beforeBlocks:E.beforeBlocks,afterBlocks:E.afterBlocks,changesStart:u.length,changes:E.changes,beforeSelection:c,afterSelection:T};u.push(...E.changes),G.push(R),K.length=0,z=null,g=null;for(let M of _e(s))b.add(M.paraId);if(!Bt(R,R.afterBlocks,E.cursor))Re(E.cursor);else {let M=t.querySelector(":scope > coco-word-native-document");M&&Vt(M,s,E.cursor.paraId),Be(E.cursor.paraId,E.cursor);}return se(T),Me("deferred"),true},og=(c,m)=>{var ue,ye;let y=c.kind==="table-cell-range"?Oe(s,c.tableId):null,E=c.kind==="table-cell-range"&&y?(ue=tt(y.table,c)[0])==null?void 0:ue.cell:null,C=c.kind==="table-cell-range"?(ye=E==null?void 0:E.paragraphs[0])!=null&&ye.paraId?{paraId:E.paragraphs[0].paraId,offset:0}:null:c.kind==="text-range"?c.anchor:{paraId:c.paraId,offset:c.offset};if(!C)return false;let N=y!=null?y:rn(s,C.paraId);if(!N)return false;let T=rt([N.table])[0];if(!T||T.kind!=="table")return false;let R=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"?au(s,c.tableId,c,R):Es(s,C.paraId,R);if(!M)return false;let $=rt([N.table])[0];if(!$||$.kind!=="table")return false;let V={source:"local",range:{anchor:C,focus:C},container:N.container,startIndex:N.tableIndex,beforeBlocks:[T],afterBlocks:[$],changesStart:u.length,changes:"changes"in M?M.changes:[M.change],beforeSelection:c,afterSelection:c};u.push(...V.changes),G.push(V),K.length=0,z=null;let j=c.kind==="caret"?c:void 0,re=c.kind==="text-range"?c:void 0;if(!Bt(V,V.afterBlocks,j,re))Re(j,c);else {Ft(c);let Ae=t.querySelector(":scope > coco-word-native-document");Ae&&Vt(Ae,s,C.paraId),Be(C.paraId,j,re),Ft(c);}return se(c),Me("deferred"),true},qn=c=>{let m=Oe(s,c.tableId);if(!m)return false;let y=rt([m.table])[0];if(!y||y.kind!=="table")return false;let E=su(s,c.tableId,c);if(!E)return false;let C=rt([m.table])[0];if(!C||C.kind!=="table")return false;let N={source:"local",range:{anchor:E.cursor,focus:E.cursor},container:m.container,startIndex:m.tableIndex,beforeBlocks:[y],afterBlocks:[C],changesStart:u.length,changes:E.changes,beforeSelection:c,afterSelection:c};if(u.push(...E.changes),G.push(N),K.length=0,z=null,!Bt(N,N.afterBlocks))Re(void 0,c);else {let T=t.querySelector(":scope > coco-word-native-document");T&&Vt(T,s,E.cursor.paraId),Be(E.cursor.paraId);}return se(c),Me("deferred"),true},Va=(c,m)=>{var re,ue,ye;let y=Oe(s,c.tableId);if(!y)return false;let E=rt([y.table])[0];if(!E||E.kind!=="table")return false;let C={rowIndex:Math.min(c.anchor.rowIndex,c.focus.rowIndex),columnIndex:Math.min(c.anchor.columnIndex,c.focus.columnIndex)},N=(ue=(re=m.content)!=null?re:m.text)!=null?ue:[],T=m.content?du(s,c.tableId,C,m.content):lu(s,c.tableId,C,(ye=m.text)!=null?ye:[]);if(!T)return false;let R=rt([y.table])[0];if(!R||R.kind!=="table")return false;let M=N.length,$=Math.max(1,...N.map(Ae=>Ae.length)),V={kind:"table-cell-range",tableId:c.tableId,anchor:C,focus:{rowIndex:Math.min(y.table.rows.length-1,C.rowIndex+M-1),columnIndex:C.columnIndex+$-1}},j={source:"local",range:{anchor:T.cursor,focus:T.cursor},container:y.container,startIndex:y.tableIndex,beforeBlocks:[E],afterBlocks:[R],changesStart:u.length,changes:T.changes,beforeSelection:c,afterSelection:V};if(u.push(...T.changes),G.push(j),K.length=0,z=null,!Bt(j,j.afterBlocks))Re(void 0,V);else {let Ae=t.querySelector(":scope > coco-word-native-document");Ae&&Vt(Ae,s,T.cursor.paraId),Be(T.cursor.paraId);}return se(V),Me("deferred"),true},Ft=c=>{if(c){if(c.kind==="text-range"){Sn(t,c.anchor,c.focus);return}if(c.kind==="object"){g={paraId:c.paraId,drawingId:c.objectId},_t();return}if(c.kind==="table-cell-range"){Pn(c);return}dt(t,c);}},ig=()=>{var E;let c=G[G.length-1];if(!c)return false;if(lr(c)){let C=(E=c.beforeSelection)!=null?E:{kind:"text-range",anchor:c.range.anchor,focus:c.range.focus},N=C.kind==="caret"?C:void 0,T=C.kind==="text-range"?C:void 0;if(!hd(c,c.beforeBlocks,c.afterBlocks.length));Bt(c,c.beforeBlocks,N,T)||Re(N,C),Ft(C),G.pop(),K.push(c),z=null,u.splice(c.changesStart),se(C);let R=t.querySelector(":scope > coco-word-native-document");R&&Vt(R,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 Be(M,N,T),Me("deferred"),true}if(c.source==="browser"&&!c.skipDeferredRender&&!Fi(t,c.afterParagraphs))return false;let m={paraId:c.beforeParagraphs[0].paraId,offset:c.range.anchor.offset};if(!Go(c,c.beforeParagraphs))return false;let y=Np(c,"before");if(c.forceFullRender){G.pop(),K.push(c),z=null,u.splice(c.changesStart);let C=y!=null?y:v({kind:"caret"},m);return se(C),Re(C.kind==="caret"?C:void 0,C),Ft(C),Me("deferred"),true}if(!Wt(c,c.beforeParagraphs,y?void 0:m))return false;if(Ft(y),G.pop(),K.push(c),z=null,u.splice(c.changesStart),se(y!=null?y:v({kind:"caret"},m)),Tp(c)||c.skipDeferredRender){let C=c.beforeParagraphs[0].paraId;c.deferLayoutReflow?Ho(C):Be(C,y?void 0:m,(y==null?void 0:y.kind)==="text-range"?y:void 0),Ft(y),c.deferLayoutReflow||pn(C);}return Me("deferred"),true},ag=()=>{var E;let c=K[K.length-1];if(!c)return false;if(lr(c)){let C=(E=c.afterSelection)!=null?E:{kind:"caret",paraId:c.afterBlocks[0].kind==="paragraph"?c.afterBlocks[0].paraId:c.range.anchor.paraId,offset:c.range.anchor.offset},N=C.kind==="caret"?C:void 0,T=C.kind==="text-range"?C:void 0;if(!hd(c,c.afterBlocks,c.beforeBlocks.length));Bt(c,c.afterBlocks,N,T)||Re(N,C),Ft(C),K.pop(),G.push(c),z=null,u.splice(c.changesStart),u.push(...c.changes),se(C);let R=C.kind==="text-range"?C.anchor.paraId:C.kind==="table-cell-range"?c.range.anchor.paraId:C.paraId,M=t.querySelector(":scope > coco-word-native-document");return M&&Vt(M,s,R),Be(R,N,T),Me("deferred"),true}if(c.source==="browser"&&!c.skipDeferredRender&&!Fi(t,c.beforeParagraphs))return false;let m={paraId:c.afterParagraphs[0].paraId,offset:c.range.anchor.offset};if(!Go(c,c.afterParagraphs))return false;let y=Np(c,"after");if(c.forceFullRender){K.pop(),G.push(c),z=null,u.splice(c.changesStart),u.push(...c.changes);let C=y!=null?y:v({kind:"caret"},m);return se(C),Re(C.kind==="caret"?C:void 0,C),Ft(C),Me("deferred"),true}if(!Wt(c,c.afterParagraphs,y?void 0:m))return false;if(Ft(y),K.pop(),G.push(c),z=null,u.splice(c.changesStart),u.push(...c.changes),se(y!=null?y:v({kind:"caret"},m)),Tp(c)||c.skipDeferredRender){let C=c.beforeParagraphs[0].paraId;c.deferLayoutReflow?Ho(C):Be(C,y?void 0:m,(y==null?void 0:y.kind)==="text-range"?y:void 0),Ft(y),c.deferLayoutReflow||pn(C);}return Me("deferred"),true},Pr=()=>l||d||G.length===0?false:(ut(),ig()),Rr=()=>l||d||K.length===0?false:(ut(),ag()),se=c=>{if(c&&ut(),(c==null?void 0:c.kind)!=="object"&&_n(),Pn(c),hS(h,c)){at();return}h=c,at(),Ha();},Mr=(c,m,y)=>{if(!c||(m==null?void 0:m.kind)!=="image")return false;let E=J(s,m.paraId);if(!E)return false;let C={source:"local",patchMode:"individual",deferLayoutReflow:true,range:{anchor:y,focus:y},beforeParagraphs:[c],afterParagraphs:[be(E)],changesStart:u.length,changes:[m],beforeSelection:{kind:"object",paraId:m.paraId,objectKind:"image",objectId:m.drawingId,offset:m.offset},afterSelection:v({kind:"caret"},y)};return u.push(m),G.push(C),K.length=0,z=null,qm(m.paraId,m.drawingId,y),Ho(m.paraId),g=null,se(v({kind:"caret"},y)),Me("deferred"),true},Mn=(c,m,y)=>{let E=J(s,c),C=E==null?void 0:E.content.find(T=>T.kind==="image"&&T.drawingId===m);if(S&&E&&(C==null?void 0:C.kind)==="image"){let T=be(E),R=ot(s);return C.revision={kind:"revision",id:`revision:${R}`,revisionId:R,revisionKind:"delete",author:"User",date:new Date().toISOString()},wt({kind:"object",paraId:c,objectKind:"image",objectId:m,offset:y.offset},[T],[{kind:"image",op:"delete",paraId:c,offset:y.offset,drawingId:m,revisionId:R,revisionKind:"delete"}],true)}let N=E?be(E):null;return Mr(N,Su(s,c,m),y)},An=(c,m,y=v({kind:"caret"},c),E)=>{let C=J(s,c.paraId);if(!C)return false;let N=m==="delete-backward"?c.offset-1:c.offset;if(m!=="insert"&&!gi(s,c.paraId,N))return false;let T=be(C),R=m==="insert"?uu(s,c.paraId,c.offset):m==="delete-backward"?jr(s,c.paraId,c.offset):Ur(s,c.paraId,c.offset),M=J(s,c.paraId);if(!R||R.kind!=="page-break"||!M)return false;let $={paraId:c.paraId,offset:m==="insert"?c.offset+1:m==="delete-backward"?Math.max(0,c.offset-1):c.offset},V=E!=null?E:v({kind:"caret"},$),j=V.kind==="caret"?V:$,re={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:c,focus:c},beforeParagraphs:[T],afterParagraphs:[be(M)],changesStart:u.length,changes:[R],beforeSelection:y,afterSelection:V};return u.push(R),G.push(re),K.length=0,z=null,g=null,Re(j,V),se(V),Me("deferred"),true},Uo=c=>{if(c.anchor.paraId!==c.focus.paraId)return false;let m=Hi(c.anchor.offset,c.focus.offset);if(!fu(s,c.anchor.paraId,m.from,m.to))return false;let y=J(s,c.anchor.paraId);if(!y)return false;let E=be(y),C=bn(s,c.anchor.paraId,m.from,m.to),N=J(s,c.anchor.paraId);if(!N||!C.some(M=>M.kind==="page-break"))return false;let T={kind:"caret",paraId:c.anchor.paraId,offset:m.from},R={source:"local",patchMode:"individual",forceFullRender:true,range:{anchor:c.anchor,focus:c.focus},beforeParagraphs:[E],afterParagraphs:[be(N)],changesStart:u.length,changes:C,beforeSelection:c,afterSelection:T};return u.push(...C),G.push(R),K.length=0,z=null,Re(T,T),se(T),Me("deferred"),true},Ko=(c,m)=>{let y=ve(s,c.paraId);if(!y)return false;if(m==="backward"&&c.offset===0&&y.previous){let N=Pe(y.previous).length;return gi(s,y.previous.paraId,N-1)?An({paraId:y.previous.paraId,offset:N},"delete-backward",c,c):false}let E=y.container[y.index+1],C=(E==null?void 0:E.kind)==="paragraph"?E:null;return m==="forward"&&c.offset===Pe(y.paragraph).length&&C&&gi(s,C.paraId,0)?An({paraId:C.paraId,offset:0},"delete-forward",c,c):false},Ln=(c,m,y,E)=>{if(c.anchor.paraId!==c.focus.paraId)return false;let C=J(s,c.anchor.paraId);if(!C)return false;let N=be(C),T=E(),R=Array.isArray(T)?T:T?[T]:[],M=J(s,c.anchor.paraId);if(R.length===0||!M)return false;let $=v({kind:"caret"},y),V={source:"local",patchMode:"individual",range:c,beforeParagraphs:[N],afterParagraphs:[be(M)],changesStart:u.length,changes:R,beforeSelection:m,afterSelection:$};return u.push(...R),G.push(V),K.length=0,z=null,Wt(V,V.afterParagraphs,y)?Be(c.anchor.paraId,y):Re(y),se($),Me("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 y=ve(s,m.anchor.paraId),E=ve(s,m.focus.paraId);if(!y||!E||y.container!==E.container)return [];let C=[];for(let N=y.index;N<=E.index;N+=1){let T=y.container[N];if((T==null?void 0:T.kind)!=="paragraph")return [];C.push({paraId:T.paraId,from:N===y.index?m.anchor.offset:0,to:N===E.index?m.focus.offset:Pe(T).length});}return C},gd=c=>{var m;if(!c)return [];if(c.kind==="caret"||c.kind==="object")return [c.paraId];if(c.kind==="table-cell-range"){let y=(m=Oe(s,c.tableId))==null?void 0:m.table;return y?tt(y,c).flatMap(({cell:E})=>E.paragraphs.map(C=>C.paraId)):[]}return en(c).map(y=>y.paraId)},bd=c=>{if((c==null?void 0:c.kind)!=="text-range")return null;let m=en(c);return m.length===0?null:m.map(y=>Pe(J(s,y.paraId)).slice(y.from,y.to)).join(`
|
|
1612
|
+
`)},wd=c=>en(c).map(m=>{var R;let y=J(s,m.paraId),E=Pe(y).slice(m.from,m.to),C=[],N=0;for(let M of y.content){let $=gS(M),V=N+$.length,j=Math.max(m.from,N),re=Math.min(m.to,V),ue=M.kind==="text"||M.kind==="field"?M.format:null,ye=M.kind==="text"?M.hyperlink:void 0;(ue||ye)&&re>j&&C.push(v({from:j-m.from,to:re-m.from,format:v({},ue!=null?ue:{})},ye?{hyperlink:v({},ye)}:{})),N=V;}let T=(R=y.format)!=null&&R.hasNumbering&&y.format.numbering?mn(y.format.numbering):null;return v({text:E,runs:C},T?{listType:T}:{})}),Xn=(c,m,y)=>{var M;if(S&&!y&&c.anchor.paraId===c.focus.paraId)return Ee({kind:"replace-range",anchor:c.anchor,focus:c.focus,text:m});if(jo(c,m))return true;let E=$a(c);if(!E)return false;let C=Ns(s,c.anchor,c.focus,m);if(!C||C.changes.length===0)return false;for(let $ of C.paragraphIds)b.add($);let N=null;for(let $=0;$<((M=y==null?void 0:y.length)!=null?M:0);$+=1){let V=y[$],j=C.paragraphIds[$];if(!j)break;let re=$===0?c.anchor.offset:0;for(let ue of V.runs){if(Object.keys(ue.format).length>0){let ye=Ts(s,j,re+ue.from,re+ue.to,ue.format);ye&&C.changes.push(ye);}if(ue.hyperlink){let ye=Rs(s,j,re+ue.from,re+ue.to,ue.hyperlink);ye&&C.changes.push(ye);}}if(V.listType){(!N||N.type!==V.listType)&&(N={type:V.listType,numbering:xs(s,V.listType)});let ue=_r(s,j,N.numbering);ue&&C.changes.push(ue);}else N=null;}if(S){let $=ot(s),V=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:$,revisionKind:"insert",author:"User",date:new Date().toISOString()})).filter(j=>j!==null);C.changes.push(...V);}fi(s);let T=C.paragraphIds.map($=>J(s,$)).filter($=>$!==null).map(be),R={source:"local",range:c,beforeParagraphs:E,afterParagraphs:T,changesStart:u.length,changes:C.changes};return u.push(...C.changes),G.push(R),K.length=0,z=null,g=null,Wt(R,T,C.cursor)?Be(E[0].paraId,C.cursor):Re(C.cursor),se(v({kind:"caret"},C.cursor)),Me("deferred"),true},Ga=(c,m,y={})=>{var j,re;let E=$a(c);if(!E)return false;let C=Ns(s,c.anchor,c.focus,"");if(!C)return false;for(let ue of C.paragraphIds)b.add(ue);let N=cu(s,C.cursor.paraId,C.cursor.offset,m,y);if(!N||N.kind!=="image")return false;let T=[...C.changes,N];if(S){let ue=ot(s),ye=(j=J(s,N.paraId))==null?void 0:j.content.find(Ae=>Ae.kind==="image"&&Ae.drawingId===N.drawingId);(ye==null?void 0:ye.kind)==="image"&&(ye.revision={kind:"revision",id:`revision:${ue}`,revisionId:ue,revisionKind:"insert",author:"User",date:new Date().toISOString()},T.push({kind:"image",op:"insert",paraId:N.paraId,offset:N.offset,drawingId:N.drawingId,revisionId:ue,revisionKind:"insert"}));}let R={paraId:C.cursor.paraId,offset:C.cursor.offset+1},M=C.paragraphIds.map(ue=>J(s,ue)).filter(ue=>ue!==null).map(be),$=v({source:"local",patchMode:"individual",deferLayoutReflow:true,range:c,beforeParagraphs:E,afterParagraphs:M,changesStart:u.length,changes:T},y.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:N.drawingId,offset:C.cursor.offset}}:{});u.push(...T),G.push($),K.length=0,g=y.select?{paraId:C.cursor.paraId,drawingId:N.drawingId}:null,z=null;let V=(re=J(s,N.paraId))==null?void 0:re.content.find(ue=>ue.kind==="image"&&ue.drawingId===N.drawingId);return (!V||V.kind!=="image"||!sg(c,V,R))&&(Wt($,M,R)||Re(R)),Ho(E[0].paraId),g&&_t(),se(g?{kind:"object",paraId:g.paraId,objectKind:"image",objectId:g.drawingId,offset:C.cursor.offset}:v({kind:"caret"},R)),Me("deferred"),true},sg=(c,m,y)=>{if(c.anchor.paraId!==c.focus.paraId)return false;let E=Ks(t,c.anchor,c.focus);if(!E)return false;let C=t.querySelector(`coco-word-native-p[data-para-id="${c.anchor.paraId}"]`);return !C||!C.contains(E.commonAncestorContainer)?false:(E.deleteContents(),E.insertNode(Gs(m)),dt(t,y),true)},Ar=()=>{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},ja=(c,m=Ar())=>{let y=J(s,c.paraId);if(!y)return false;let E=be(y),C=Ms(s,c.paraId,c.offset,m);if(!C)return false;let N=[c.paraId,m].map(M=>J(s,M)).filter(M=>M!==null).map(be);if(N.length!==2)return false;let T={paraId:m,offset:0},R={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:[E],afterParagraphs:N,changesStart:u.length,changes:[C]};return u.push(C),G.push(R),K.length=0,z=null,g=null,Wt(R,N,T)?Be(c.paraId,T):Re(T),se(v({kind:"caret"},T)),Me("deferred"),true},xd=c=>{if(c.offset!==0)return false;let m=ve(s,c.paraId),y=m==null?void 0:m.previous;if(!m||!y)return false;let E=[be(y),be(m.paragraph)],C={paraId:y.paraId,offset:Pe(y).length},N=u.length,T=jr(s,c.paraId,0),R=J(s,y.paraId);if(!T||T.kind!=="block"||!R)return false;let M={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:E,afterParagraphs:[be(R)],changesStart:N,changes:[T]};return u.push(T),G.push(M),K.length=0,z=null,g=null,Wt(M,M.afterParagraphs,C)?Be(y.paraId,C):Re(C),se(v({kind:"caret"},C)),Me("deferred"),true},yd=c=>{let m=ve(s,c.paraId);if(!m||c.offset!==Pe(m.paragraph).length)return false;let y=m.container[m.index+1];if((y==null?void 0:y.kind)!=="paragraph")return false;let E=[be(m.paragraph),be(y)],C=u.length,N=Ur(s,c.paraId,c.offset),T=J(s,c.paraId);if(!N||N.kind!=="block"||!T)return false;let R={source:"local",skipDeferredRender:true,range:{anchor:c,focus:c},beforeParagraphs:E,afterParagraphs:[be(T)],changesStart:C,changes:[N]};return u.push(N),G.push(R),K.length=0,z=null,g=null,Wt(R,R.afterParagraphs,c)?Be(c.paraId,c):Re(c),se(v({kind:"caret"},c)),Me("deferred"),true},wt=(c,m,y,E=false)=>{if(y.length===0||m.length===0)return false;let C=m.map(M=>J(s,M.paraId)).filter(M=>M!==null).map(be),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:Pe(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:y,beforeSelection:c,afterSelection:c};u.push(...y),G.push(T),K.length=0,z=null,Wt(T,C)||Re();let R=t.querySelector(":scope > coco-word-native-document");if(R&&vn(R),c.kind==="text-range"?Sn(t,c.anchor,c.focus):c.kind==="object"?(g={paraId:c.paraId,drawingId:c.objectId},_t()):c.kind==="caret"&&dt(t,{paraId:c.paraId,offset:c.offset}),E){let M=c.kind==="caret"||c.kind==="object"?{paraId:c.paraId,offset:c.offset}:void 0;Be(m[0].paraId,M,c);}return c.kind==="object"&&g&&_t(),se(c),Me("deferred"),true},vd=(c,m)=>{if(c.length===0)return 0;let y=Array.from(new Set(c.map(V=>V.paraId))),E=y.map(V=>J(s,V)).filter(V=>V!==null).map(be);if(E.length===0)return 0;let C=u.length,N=[],T=[...c].sort((V,j)=>V.paraId===j.paraId?j.from-V.from:y.indexOf(j.paraId)-y.indexOf(V.paraId));for(let V of T)N.push(...Kr(s,V.paraId,V.from,V.to,m));if(N.length===0)return 0;let R=E.map(V=>J(s,V.paraId)).filter(V=>V!==null).map(be),M=c[0],$=v({source:"local",patchMode:"individual",range:{anchor:{paraId:M.paraId,offset:M.from},focus:{paraId:M.paraId,offset:M.to}},beforeParagraphs:E,afterParagraphs:R,changesStart:C,changes:N},h?{beforeSelection:h,afterSelection:h}:{});return u.push(...N),G.push($),K.length=0,z=null,Wt($,R)?Ft(h):Re(void 0,h!=null?h:void 0),Be(M.paraId),Me(),c.length},lg=c=>{if(d)return false;let m=k&&k.activeIndex>=0?k.matches[k.activeIndex]:null;return m?vd([m],c)>0:false},dg=c=>d?0:k?vd(k.matches,c):0,Ee=c=>{var y,E,C,N,T,R,M,$,V,j,re,ue,ye,Ae;if(l||d)return false;ut();let m=(y=h!=null?h:ze(t))!=null?y:lt(t);if(c.kind==="toggle-track-revisions")return S=!S,Ha(),true;if(c.kind==="accept-revision"||c.kind==="reject-revision"||c.kind==="accept-all-revisions"||c.kind==="reject-all-revisions"){let X=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(G.flatMap(me=>lr(me)?me.changes.filter(xe=>xe.kind==="table"&&!!(xe.revisionAction&&xe.revisionId)).map(xe=>xe.revisionId):[])),he=me=>(me&&te&&Ee(c),me),pe=G.filter(me=>lr(me)&&me.changes.some(xe=>xe.kind==="table"&&!xe.revisionAction&&!!xe.revisionId&&!ne.has(xe.revisionId))&&me.afterBlocks.some(xe=>{var Te,de,Ke;if(xe.kind!=="table"||((Te=xe.revision)==null?void 0:Te.kind)!=="revision"||ne.has(xe.revision.revisionId))return false;let De=(Ke=(de=Oe(s,xe.tableId))==null?void 0:de.table.revision)==null?void 0:Ke.revisionId;return te?!!De:De===xe.revision.revisionId&&xe.revision.revisionId===X&&(!Q||xe.revision.revisionKind===Q)}));if(pe.length>0){let me=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",xe=new Map;for(let De of pe){let Te=De.afterBlocks.find(Ke=>{var je;return Ke.kind==="table"&&((je=Ke.revision)==null?void 0:je.kind)==="revision"});if(!Te||Te.kind!=="table"||!Te.revision)continue;let de=(E=xe.get(Te.tableId))!=null?E:[];de.push(De),xe.set(Te.tableId,de);}for(let[De,Te]of xe){let de=Te[Te.length-1];if(!de)continue;let Ke=de.afterBlocks.find(Zo=>{var Zn;return Zo.kind==="table"&&((Zn=Zo.revision)==null?void 0:Zn.kind)==="revision"});if(!Ke||Ke.kind!=="table"||!Ke.revision)continue;let je=Oe(s,De);if(!je)continue;let tn=[rt([je.table])[0]],Dn=rt([je.table])[0];if(!Dn||Dn.kind!=="table")continue;me==="accept"&&(Dn.revision=void 0,je.table.revision=void 0);let Yn=me==="accept"?[Dn]:rt((N=(C=Te[0])==null?void 0:C.beforeBlocks)!=null?N:de.beforeBlocks);me==="reject"&&je.container.splice(je.tableIndex,1,...rt(Yn));let Yo=Te.flatMap(Zo=>Zo.changes.filter(Zn=>Zn.kind==="table").map(Zn=>H(v({},Zn),{revisionAction:me}))),Ya={source:"local",range:de.range,container:je.container,startIndex:je.tableIndex,beforeBlocks:tn,afterBlocks:Yn,changesStart:u.length,changes:Yo,beforeSelection:m!=null?m:void 0,afterSelection:m!=null?m:void 0};u.push(...Ya.changes),G.push(Ya),K.length=0,Bt(Ya,Yn,void 0)?Be(((T=tn[0])==null?void 0:T.kind)==="paragraph"?tn[0].paraId:(V=($=(M=(R=je.table.rows[0])==null?void 0:R.cells[0])==null?void 0:M.paragraphs[0])==null?void 0:$.paraId)!=null?V:"",void 0):Re(),Me("deferred");}return he(true)}let Z=_e(s).flatMap(me=>{var Te;let xe=0,De=[];for(let de of me.content)de.kind==="image"&&(((Te=de.revision)==null?void 0:Te.kind)==="revision"&&(te||de.revision.revisionId===X&&(!Q||de.revision.revisionKind===Q))||de.formatRevision&&(te||de.formatRevision.revisionId===X&&(!Q||Q==="format")))&&De.push({paraId:me.paraId,drawingId:de.drawingId,offset:xe}),xe+=de.kind==="text"?de.text.length:1;return De});if(Z.length>0){let me=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",xe=Array.from(new Set(Z.map(de=>de.paraId))).map(de=>J(s,de)).filter(de=>de!==null).map(be),De=Z.map(de=>{var je;let Ke=(je=J(s,de.paraId))==null?void 0:je.content.find(tn=>tn.kind==="image"&&tn.drawingId===de.drawingId);return (Ke==null?void 0:Ke.kind)==="image"&&Ke.formatRevision?Cu(s,de.paraId,de.drawingId,me):Eu(s,de.paraId,de.drawingId,me)}).filter(de=>de!==null);if(De.length===0)return false;let Te=Z[0];return he(wt({kind:"caret",paraId:Te.paraId,offset:Te.offset},xe,De,true))}let Ne=_e(s).flatMap(me=>{let xe=0,De=[];for(let Te of me.content){let de=Te.kind==="text"?Te.text.length:1;Te.kind==="text"&&Te.formatRevision&&(te||Te.formatRevision.revisionId===X&&(!Q||Q==="format"))&&De.push({paraId:me.paraId,from:xe,to:xe+de}),xe+=de;}return De});if(Ne.length>0){let me=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",xe=Array.from(new Set(Ne.map(de=>de.paraId))).map(de=>J(s,de)).filter(de=>de!==null).map(be),De=Ne.map(de=>yu(s,de.paraId,de.from,de.to,me)).filter(de=>de!==null);if(De.length===0)return false;let Te=Ne[0];return he(wt({kind:"caret",paraId:Te.paraId,offset:Te.from},xe,De,true))}let He=te?_e(s).flatMap(me=>{var Te;let xe=[],De=0;for(let de of me.content){let Ke=de.kind==="text"?de.text.length:1;de.kind==="text"&&((Te=de.marks)!=null&&Te.some(je=>je.kind==="revision"))&&xe.push({paraId:me.paraId,from:De,to:De+Ke}),De+=Ke;}return xe}):X?_e(s).flatMap(me=>{var Te;let xe=[],De=0;for(let de of me.content){let Ke=de.kind==="text"?de.text.length:1;de.kind==="text"&&((Te=de.marks)!=null&&Te.some(je=>je.kind==="revision"&&je.revisionId===X&&(!Q||je.revisionKind===Q)))&&xe.push({paraId:me.paraId,from:De,to:De+Ke}),De+=Ke;}return xe}):en(m);if(He.length===0)return false;(te||X)&&He.sort((me,xe)=>me.paraId===xe.paraId?xe.from-me.from||xe.to-me.to:xe.paraId.localeCompare(me.paraId));let we=He.map(me=>J(s,me.paraId)).filter(me=>me!==null).map(be),Fe=c.kind==="accept-revision"||c.kind==="accept-all-revisions"?"accept":"reject",fe=He.map(me=>xu(s,me.paraId,me.from,me.to,Fe)).filter(me=>me!==null);if(fe.length===0)return false;let Je=m!=null?m:{kind:"caret",paraId:He[0].paraId,offset:He[0].from};return he(wt(Je,we,fe,false))}if(c.kind==="insert-text"&&(m==null?void 0:m.kind)==="caret"){let X={paraId:m.paraId,offset:m.offset+c.text.length};return Ln({anchor:m,focus:m},m,X,()=>{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,X.offset,{revisionId:(ne=Tr(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 X=Hi(c.anchor.offset,c.focus.offset),Q={kind:"text-range",anchor:c.anchor,focus:c.focus};return S?Ln({anchor:c.anchor,focus:c.focus},Q,{paraId:c.anchor.paraId,offset:X.to+c.text.length},()=>{let te=[],ne=$t(s,c.anchor.paraId,X.from,X.to,{revisionId:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()});if(ne&&te.push(ne),c.text.length>0){let he=on(s,c.anchor.paraId,X.to,c.text);he&&te.push(he);let pe=$t(s,c.anchor.paraId,X.to,X.to+c.text.length,{revisionId:ot(s),revisionKind:"insert",author:"User",date:new Date().toISOString()});pe&&te.push(pe);}return te}):Ln({anchor:c.anchor,focus:c.focus},Q,{paraId:c.anchor.paraId,offset:X.from+c.text.length},()=>Kr(s,c.anchor.paraId,X.from,X.to,c.text))}if(c.kind==="delete-range"&&S){let X={kind:"text-range",anchor:c.anchor,focus:c.focus},Q=en(X);if(Q.length===0)return false;let te=Array.from(new Map(Q.map(Z=>J(s,Z.paraId)).filter(Z=>Z!==null).map(Z=>[Z.paraId,be(Z)])).values()),ne=ot(s),he=Q.map(Z=>$t(s,Z.paraId,Z.from,Z.to,{revisionId:ne,revisionKind:"delete",author:"User",date:new Date().toISOString()})).filter(Z=>Z!==null);if(he.length===0)return false;let pe=wt(X,te,he,false);if(pe){let Z=nt(s,X),Ne={paraId:Z.anchor.paraId,offset:Z.anchor.offset};dt(t,Ne),se(v({kind:"caret"},Ne));}return pe}if(c.kind==="delete-range"&&c.anchor.paraId===c.focus.paraId){let X={kind:"text-range",anchor:c.anchor,focus:c.focus};if(Uo(X))return true;let Q=Hi(c.anchor.offset,c.focus.offset);return S?Ln({anchor:c.anchor,focus:c.focus},X,{paraId:c.anchor.paraId,offset:Q.from},()=>{var te;return $t(s,c.anchor.paraId,Q.from,Q.to,{revisionId:(te=Tr(c.anchor.paraId,Q.from,"delete","at"))!=null?te:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})}):Ln({anchor:c.anchor,focus:c.focus},X,{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 ja({paraId:m.paraId,offset:m.offset});if(c.kind==="insert-page-break"&&(m==null?void 0:m.kind)==="caret")return An(m,"insert");if(c.kind==="insert-image"&&m&&(m.kind==="caret"||m.kind==="text-range")){let X=m.kind==="text-range"?nt(s,m):{anchor:{paraId:m.paraId,offset:m.offset},focus:{paraId:m.paraId,offset:m.offset}};return Ga(X,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 X=J(s,m.paraId);if(!X)return false;let Q=be(X),te=X.content.find(Z=>Z.kind==="image"&&Z.drawingId===m.objectId),ne=(te==null?void 0:te.kind)==="image"?te.width:void 0,he=(te==null?void 0:te.kind)==="image"?te.height:void 0,pe=pu(s,m.paraId,m.objectId,{width:c.width,height:c.height});if(S&&pe){let Z=X.content.find(Ne=>Ne.kind==="image"&&Ne.drawingId===m.objectId);(Z==null?void 0:Z.kind)==="image"&&(Z.formatRevision={kind:"format",revisionId:ot(s),beforeWidth:ne,beforeHeight:he,afterWidth:c.width,afterHeight:c.height,author:"User",date:new Date().toISOString()},pe.kind==="image"&&(pe.revisionId=Z.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 Ee({kind:"set-paragraph-alignment",alignment:c.alignment});if(m&&(c.kind==="insert-table"||c.kind==="delete-table"))return rg(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 tg(m,c);if((m==null?void 0:m.kind)==="table-cell-range"&&(c.kind==="merge-table-cells"||c.kind==="split-table-cell"))return ng(m,c);if(m&&(c.kind==="set-table-cell-background"||c.kind==="set-table-cell-vertical-alignment"||c.kind==="set-table-cell-borders"))return og(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 Uo(m)?true:S?Ee({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 X={paraId:m.paraId,offset:m.offset};return Mn(m.paraId,m.objectId,X)}if((m==null?void 0:m.kind)==="caret"){if(S&&m.offset>0){let he=m.offset-1;return Ln({anchor:m,focus:m},m,{paraId:m.paraId,offset:he},()=>{var pe;return $t(s,m.paraId,he,m.offset,{revisionId:(pe=Tr(m.paraId,he,"delete","after"))!=null?pe:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})})}if(An(m,"delete-backward")||Ko(m,"backward")||xd({paraId:m.paraId,offset:m.offset}))return true;let X=J(s,m.paraId),Q=X?be(X):null,te=jr(s,m.paraId,m.offset),ne={paraId:m.offset>0?m.paraId:(j=ms(s,m.paraId))!=null?j:m.paraId,offset:Math.max(0,m.offset-1)};return (te==null?void 0:te.kind)==="image"?Mr(Q,te,ne):Rn(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 Uo(m)?true:S?Ee({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<Oa(m.paraId))return Ln({anchor:m,focus:m},m,m,()=>{var he;return $t(s,m.paraId,m.offset,m.offset+1,{revisionId:(he=Tr(m.paraId,m.offset,"delete","at"))!=null?he:ot(s),revisionKind:"delete",author:"User",date:new Date().toISOString()})});if(An(m,"delete-forward")||Ko(m,"forward")||yd({paraId:m.paraId,offset:m.offset}))return true;let X=J(s,m.paraId),Q=X?be(X):null,te=Ur(s,m.paraId,m.offset),ne={paraId:m.paraId,offset:m.offset};return (te==null?void 0:te.kind)==="image"?Mr(Q,te,ne):Rn(te,ne,{localParaId:m.paraId}),true}if(c.kind==="delete-object"&&(m==null?void 0:m.kind)==="object"){let X={paraId:m.paraId,offset:m.offset};return Mn(m.paraId,c.objectId,X)}if((c.kind==="set-hyperlink"||c.kind==="remove-hyperlink")&&(m==null?void 0:m.kind)==="text-range"){let X=en(m),Q=X.map(ne=>J(s,ne.paraId)).filter(ne=>ne!==null).map(be),te=X.map(ne=>Rs(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 X=en(m);if(X.length===0||!c.body.trim())return false;let Q=X.map(Z=>J(s,Z.paraId)).filter(Z=>Z!==null).map(be),te=Ip(s),ne=(re=c.date)!=null?re:new Date().toISOString(),he=X.map(Z=>{var Ne;return Ps(s,Z.paraId,Z.from,Z.to,{commentId:te,author:(Ne=c.author)!=null?Ne:"User",date:ne,body:c.body.trim()})}).filter(Z=>Z!==null),pe=wt(m,Q,he,false);return pe&&he.length>1&&Re(),pe}if(c.kind==="edit-comment"||c.kind==="delete-comment"){if(c.kind==="edit-comment"&&!c.body.trim())return false;let X=_e(s).filter(ne=>ne.content.some(he=>{var pe;return he.kind==="text"&&((pe=he.marks)==null?void 0:pe.some(Z=>Z.kind==="comment"&&Z.commentId===c.commentId))})).map(be);if(X.length===0)return false;let Q=c.kind==="edit-comment"?bu(s,c.commentId,c.body.trim()):wu(s,c.commentId);if(Q.length===0)return false;let te=m!=null?m:{kind:"caret",paraId:X[0].paraId,offset:0};return wt(te,X,Q,false)}if(c.kind==="reply-comment"){let X=c.body.trim();if(!X)return false;let Q=null;for(let pe of _e(s)){let Z=0;for(let Ne of pe.content){let He=Ne.kind==="text"?Ne.text.length:1;if(Ne.kind==="text"&&((ue=Ne.marks)!=null&&ue.some(we=>we.kind==="comment"&&we.commentId===c.commentId))){Q={paragraph:pe,from:Z,to:Z+He};break}Z+=He;}if(Q)break}if(!Q)return false;let te=be(Q.paragraph),ne=Ip(s),he=Ps(s,Q.paragraph.paraId,Q.from,Q.to,{commentId:ne,parentCommentId:c.commentId,preserveExistingComments:true,author:"User",date:new Date().toISOString(),body:X});return he?(Re(),wt(m!=null?m:{kind:"caret",paraId:Q.paragraph.paraId,offset:Q.from},[te],[he],false)):false}if(c.kind==="add-revision"&&(m==null?void 0:m.kind)==="text-range"){let X=en(m);if(X.length===0)return false;let Q=X.map(pe=>J(s,pe.paraId)).filter(pe=>pe!==null).map(be),te=ot(s),ne=(ye=c.date)!=null?ye:new Date().toISOString(),he=X.map(pe=>{var Z;return $t(s,pe.paraId,pe.from,pe.to,{revisionId:te,revisionKind:c.revisionKind,author:(Z=c.author)!=null?Z:"User",date:ne})}).filter(pe=>pe!==null);return wt(m,Q,he,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 X=en(m);if((m==null?void 0:m.kind)!=="text-range"||X.length===0)return false;let Q=X.map(Z=>J(s,Z.paraId)).filter(Z=>Z!==null).map(be),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 he=X.map(Z=>c.kind==="clear-text-format"?vu(s,Z.paraId,Z.from,Z.to):Ts(s,Z.paraId,Z.from,Z.to,ne)).filter(Z=>Z!==null);if(S){let Z=ot(s),Ne=X.map(He=>ku(s,He.paraId,He.from,He.to,Q.find(we=>we.paraId===He.paraId),{revisionId:Z,author:"User",date:new Date().toISOString()})).filter(He=>He!==null);he.push(...Ne);}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,he,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 X=Array.from(new Set(gd(m)));if(!m||X.length===0)return false;let Q=X.map(ne=>J(s,ne)).filter(ne=>ne!==null).map(be),te=X.map(ne=>{var pe,Z,Ne;let he=J(s,ne);if(!he)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:wS(c.indent)});if(c.kind==="adjust-paragraph-left-indent"){let He=Math.max(0,((Ne=(Z=(pe=he.format)==null?void 0:pe.indent)==null?void 0:Z.left)!=null?Ne:0)+c.delta);return er(s,ne,{indent:{left:He}})}return c.kind==="set-paragraph-spacing"?er(s,ne,{spacing:xS(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 X=Array.from(new Set(gd(m)));if(!m||X.length===0)return false;let Q=X.map(Z=>J(s,Z)).filter(Z=>Z!==null),te=Q.map(be),ne=c.kind==="toggle-list"&&Q.every(Z=>{var Ne;return ((Ne=Z.format)==null?void 0:Ne.hasNumbering)&&mn(Z.format.numbering)===c.listType}),he=c.kind==="toggle-list"&&!ne?(Ae=Yc(s,X,c.listType))!=null?Ae:xs(s,c.listType):null,pe=Q.map(Z=>{var Ne,He,we,Fe,fe;if(c.kind==="remove-list"||ne)return (Ne=Z.format)!=null&&Ne.hasNumbering?_r(s,Z.paraId,null):null;if(c.kind==="toggle-list"&&he){let Je=(Fe=(we=(He=Z.format)==null?void 0:He.numbering)==null?void 0:we.ilvl)!=null?Fe:0;return _r(s,Z.paraId,ys(he,Je))}if(c.kind==="adjust-list-level"){let Je=(fe=Z.format)!=null&&fe.hasNumbering?Z.format.numbering:void 0;return Je?_r(s,Z.paraId,ys(Je,Je.ilvl+c.delta)):null}return null}).filter(Z=>Z!==null);return fi(s),wt(m,te,pe,true)}return false},Sd=c=>{var R;let m=(R=Oe(s,c.tableId))==null?void 0:R.table;if(!m)return null;let y=Math.min(c.anchor.rowIndex,c.focus.rowIndex),E=Math.max(c.anchor.rowIndex,c.focus.rowIndex),C=Math.min(c.anchor.columnIndex,c.focus.columnIndex),N=Math.max(c.anchor.columnIndex,c.focus.columnIndex),T=Array.from({length:E-y+1},()=>Array.from({length:N-C+1},()=>null));for(let{cell:M,rowIndex:$,columnIndex:V}of tt(m,c)){let j=T[$-y];j&&V>=C&&V<=N&&(j[V-C]={text:M.paragraphs.map(re=>Pe(re)).join(`
|
|
1598
1613
|
`),blocks:rt(M.blocks),format:cg(M)});}return {version:1,cells:T}},cg=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}:{}))),kd=c=>c.cells.map(m=>m.map(y=>{var E;return ((E=y==null?void 0:y.text)!=null?E:"").replace(/[\t\r\n]+/g," ")}).join(" ")).join(`
|
|
1599
1614
|
`),ug=c=>{var y,E;let m=(E=(y=c.clipboardData)==null?void 0:y.getData(pl))!=null?E:"";if(!m)return null;try{let C=JSON.parse(m);if(C.version===1&&Array.isArray(C.cells)&&C.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 C}catch(C){return null}return null},fg=c=>{var E,C;let m=(C=(E=c.clipboardData)==null?void 0:E.getData("text/plain"))!=null?C:"";if(!m)return [];let y=m.replace(/\r\n?/g,`
|
|
1600
1615
|
`).split(`
|
|
1601
|
-
`);return y[y.length-1]===""&&y.pop(),y.map(N=>N.split(" "))},Ua=c=>{var C,N,T;if(g&&c.clipboardData){let
|
|
1602
|
-
`):(He=c.clipboardData)==null?void 0:He.getData("text/plain");if(
|
|
1616
|
+
`);return y[y.length-1]===""&&y.pop(),y.map(N=>N.split(" "))},Ua=c=>{var C,N,T;if(g&&c.clipboardData){let R=g,M=(C=J(s,R.paraId))==null?void 0:C.content.find($=>$.kind==="image"&&$.drawingId===R.drawingId);if(!M||M.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(po,Oi(M.src)),c.clipboardData.setData("text/html",`<img src="${$i(M.src)}">`),Ka(R).catch($=>{console.warn("Unable to copy the selected image",$);});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(N=ze(t))!=null?N:h;if((m==null?void 0:m.kind)==="table-cell-range"&&c.clipboardData){let R=Sd(m);if(!R)return;c.preventDefault(),c.clipboardData.setData(pl,JSON.stringify(R)),c.clipboardData.setData("text/plain",kd(R));return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&c.clipboardData){let R=(T=J(s,m.paraId))==null?void 0:T.content.find(M=>M.kind==="image"&&M.drawingId===m.objectId);if(!R||R.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(po,Oi(R.src)),c.clipboardData.setData("text/html",`<img src="${$i(R.src)}">`),Ka({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 R=nt(s,m),M=Is(s,R.anchor,R.focus);if(M){c.preventDefault(),c.clipboardData.setData(Ti,Js(M)),c.clipboardData.setData("text/plain",Qs(M));return}}let y=bd(m);if(y===null||!c.clipboardData)return;c.preventDefault(),c.clipboardData.setData("text/plain",y);let E=wd(m);E.length>0&&c.clipboardData.setData("text/html",Zs(E));},Ka=async c=>{var E;let m=(E=J(s,c.paraId))==null?void 0:E.content.find(C=>C.kind==="image"&&C.drawingId===c.drawingId);if(!m||m.kind!=="image")return;let y=await bS(m.src);await navigator.clipboard.write([new ClipboardItem({"image/png":y})]);},Ed=c=>{var C,N,T;if(d){Ua(c);return}if(g&&c.clipboardData){let R=g,M=(C=J(s,R.paraId))==null?void 0:C.content.find(j=>j.kind==="image"&&j.drawingId===R.drawingId);if(!M||M.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(po,Oi(M.src)),c.clipboardData.setData("text/html",`<img src="${$i(M.src)}">`);let $=t.querySelector(`coco-word-native-p[data-para-id="${R.paraId}"]`),V=t.querySelector(`img[data-drawing-id="${R.drawingId}"]`);if(!$||!V)return;Mn(R.paraId,R.drawingId,{paraId:R.paraId,offset:Ni($,V)});return}let m=(h==null?void 0:h.kind)==="object"||(h==null?void 0:h.kind)==="table-cell-range"?h:(N=ze(t))!=null?N:h;if((m==null?void 0:m.kind)==="table-cell-range"&&c.clipboardData){let R=Sd(m);if(!R)return;c.preventDefault(),c.clipboardData.setData(pl,JSON.stringify(R)),c.clipboardData.setData("text/plain",kd(R)),qn(m);return}if((m==null?void 0:m.kind)==="object"&&m.objectKind==="image"&&c.clipboardData){let R=(T=J(s,m.paraId))==null?void 0:T.content.find(M=>M.kind==="image"&&M.drawingId===m.objectId);if(!R||R.kind!=="image")return;c.preventDefault(),c.clipboardData.setData(po,Oi(R.src)),c.clipboardData.setData("text/html",`<img src="${$i(R.src)}">`),Mn(m.paraId,m.objectId,{paraId:m.paraId,offset:m.offset});return}if((m==null?void 0:m.kind)==="text-range"&&c.clipboardData){let R=nt(s,m),M=Is(s,R.anchor,R.focus);if(M){c.preventDefault(),c.clipboardData.setData(Ti,Js(M)),c.clipboardData.setData("text/plain",Qs(M)),jo(R,"");return}}let y=bd(m);if(y===null||(m==null?void 0:m.kind)!=="text-range"||!c.clipboardData)return;c.preventDefault(),c.clipboardData.setData("text/plain",y);let E=wd(m);E.length>0&&c.clipboardData.setData("text/html",Zs(E)),Xn(nt(s,m),"");},Cd=c=>{var V,j,re,ue,ye,Ae,X,Q,te,ne,he,pe,Z,Ne,He,we,Fe;if(d){c.preventDefault();return}let m=(h==null?void 0:h.kind)==="table-cell-range"?h:null;if(m){let fe=ug(c),Je=fe?[]:fg(c);(fe&&Va(m,{content:fe.cells})||Je.length>0&&Va(m,{text:Je}))&&c.preventDefault();return}let y=Rf((j=(V=c.clipboardData)==null?void 0:V.getData(Ti))!=null?j:"");if(y){let fe=(ue=(re=ze(t))!=null?re:h)!=null?ue:lt(t);if(!fe||fe.kind==="object"||fe.kind==="table-cell-range")return;let Je=fe.kind==="text-range"?nt(s,fe):{anchor:{paraId:fe.paraId,offset:fe.offset},focus:{paraId:fe.paraId,offset:fe.offset}};if(eg(Je,y)){c.preventDefault();return}}let E=mS((Ae=(ye=c.clipboardData)==null?void 0:ye.getData(po))!=null?Ae:"");if(E){let fe=(Q=(X=ze(t))!=null?X:h)!=null?Q:lt(t);if(!fe||fe.kind==="object"||fe.kind==="table-cell-range")return;let Je=fe.kind==="text-range"?nt(s,fe):{anchor:{paraId:fe.paraId,offset:fe.offset},focus:{paraId:fe.paraId,offset:fe.offset}};c.preventDefault(),Ga(Je,E);return}let C=Array.from((ne=(te=c.clipboardData)==null?void 0:te.files)!=null?ne:[]).find(fe=>fe.type.startsWith("image/"));if(C){let fe=(pe=(he=ze(t))!=null?he:h)!=null?pe:lt(t);if(!fe||fe.kind==="object"||fe.kind==="table-cell-range")return;let Je=fe.kind==="text-range"?nt(s,fe):{anchor:{paraId:fe.paraId,offset:fe.offset},focus:{paraId:fe.paraId,offset:fe.offset}};c.preventDefault(),Pp(C).then(me=>Ga(Je,me));return}let N=(Ne=(Z=c.clipboardData)==null?void 0:Z.getData("text/html"))!=null?Ne:"",T=N?Pf(N):[],R=T.length>0?T.map(fe=>fe.text).join(`
|
|
1617
|
+
`):(He=c.clipboardData)==null?void 0:He.getData("text/plain");if(R===void 0)return;let M=(Fe=(we=ze(t))!=null?we:h)!=null?Fe:lt(t);if(!M||M.kind==="object"||M.kind==="table-cell-range")return;let $=M.kind==="text-range"?nt(s,M):{anchor:{paraId:M.paraId,offset:M.offset},focus:{paraId:M.paraId,offset:M.offset}};c.preventDefault(),Xn($,R,T.length>0?T:void 0);},pg=()=>{var m;let c=(m=h!=null?h:ze(t))!=null?m:lt(t);return (c==null?void 0:c.kind)==="object"&&c.objectKind==="image"?Mn(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},hg=async()=>{var c,m;if(typeof((c=navigator.clipboard)==null?void 0:c.readText)=="function")try{let y=await navigator.clipboard.readText(),E=(m=h!=null?h:ze(t))!=null?m:lt(t);if(!E||E.kind==="object")return;if(E.kind==="table-cell-range"){let N=y.replace(/\r\n?/g,`
|
|
1603
1618
|
`).split(`
|
|
1604
|
-
`).map(T=>T.split(" "));Va(E,{text:N});return}let C=E.kind==="text-range"?nt(s,E):{anchor:{paraId:E.paraId,offset:E.offset},focus:{paraId:E.paraId,offset:E.offset}};Xn(C,y);}catch(y){console.warn("Unable to paste from the context menu",y);}},_a=(c="add",m,y="")=>{let E=document.createElement("div");E.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 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=y;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 $=document.createElement("button");$.type="button",$.className="coco-word-dialog-button is-primary",$.textContent="\u786E\u5B9A";let V=()=>E.remove();M.addEventListener("click",V),E.addEventListener("click",j=>{j.target===E&&V();}),C.addEventListener("keydown",j=>{j.key==="Escape"&&V(),j.key==="Enter"&&(j.ctrlKey||j.metaKey)&&(j.preventDefault(),$.click());}),$.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}),V();}),P.append(M,$),C.append(N,T,P),E.appendChild(C),(o!=null?o:document.body).appendChild(E),T.focus();},mg=()=>{var C,N,T;let c=(C=h!=null?h:ze(t))!=null?C:lt(t),m=Rt(c),y=(c==null?void 0:c.kind)==="text-range"||(c==null?void 0:c.kind)==="object"||(c==null?void 0:c.kind)==="table-cell-range",E=[{label:"\u526A\u5207",disabled:!y,action:()=>document.execCommand("cut")},{label:"\u590D\u5236",disabled:!y,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:hg},{label:"\u5220\u9664",disabled:!y,action:()=>pg()}];if((c==null?void 0:c.kind)==="text-range"&&(E.push({label:"\u6DFB\u52A0\u6279\u6CE8",separatorBefore:true,action:_a}),E.push({label:"\u6807\u8BB0\u4E3A\u63D2\u5165\u4FEE\u8BA2",action:()=>ke({kind:"add-revision",revisionKind:"insert"})}),E.push({label:"\u6807\u8BB0\u4E3A\u5220\u9664\u4FEE\u8BA2",action:()=>ke({kind:"add-revision",revisionKind:"delete"})}),E.push({label:m.bold===true?"\u53D6\u6D88\u52A0\u7C97":"\u52A0\u7C97",separatorBefore:true,disabled:!Dt(s,c,{kind:"toggle-bold"}),action:()=>ke({kind:"toggle-bold"})}),E.push({label:"\u6E05\u9664\u6587\u672C\u683C\u5F0F",action:()=>ke({kind:"clear-text-format"})}),m.hyperlink!==null&&E.push({label:"\u79FB\u9664\u8D85\u94FE\u63A5",disabled:!Dt(s,c,{kind:"remove-hyperlink"}),action:()=>ke({kind:"remove-hyperlink"})})),(c==null?void 0:c.kind)==="caret"&&Dt(s,c,{kind:"insert-table",rows:2,columns:2})&&E.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"&&(E.push({label:"\u56FE\u7247\u5DE6\u5BF9\u9F50",separatorBefore:true,action:()=>ke({kind:"set-image-alignment",objectId:c.objectId,alignment:"left"})}),E.push({label:"\u56FE\u7247\u5C45\u4E2D",action:()=>ke({kind:"set-image-alignment",objectId:c.objectId,alignment:"center"})}),E.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};E.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)}})}),E.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}})}),E.push({label:"\u5728\u4E0A\u65B9\u63D2\u5165\u884C",disabled:!Dt(s,c,{kind:"insert-table-row"}),action:()=>ke({kind:"insert-table-row",position:"before"})}),E.push({label:"\u5728\u4E0B\u65B9\u63D2\u5165\u884C",disabled:!Dt(s,c,{kind:"insert-table-row"}),action:()=>ke({kind:"insert-table-row",position:"after"})}),E.push({label:"\u5220\u9664\u5F53\u524D\u884C",disabled:!Dt(s,c,{kind:"delete-table-row"}),action:()=>ke({kind:"delete-table-row"})}),E.push({label:"\u5728\u5DE6\u4FA7\u63D2\u5165\u5217",disabled:!Dt(s,c,{kind:"insert-table-column"}),action:()=>ke({kind:"insert-table-column",position:"before"})}),E.push({label:"\u5728\u53F3\u4FA7\u63D2\u5165\u5217",disabled:!Dt(s,c,{kind:"insert-table-column"}),action:()=>ke({kind:"insert-table-column",position:"after"})}),E.push({label:"\u5220\u9664\u5F53\u524D\u5217",disabled:!Dt(s,c,{kind:"delete-table-column"}),action:()=>ke({kind:"delete-table-column"})}),E.push({label:"\u5220\u9664\u8868\u683C",separatorBefore:true,disabled:!Dt(s,c,{kind:"delete-table"}),action:()=>ke({kind:"delete-table"})});for(let[M,$]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"]])E.push({label:M,action:()=>ke({kind:"set-table-cell-vertical-alignment",alignment:$})});}return E.push({label:"\u64A4\u9500",separatorBefore:true,disabled:!K.length,action:()=>Pr()},{label:"\u91CD\u505A",disabled:!Y.length,action:()=>Rr()}),E},gg=c=>{var N,T;let m=c.target;if(m instanceof HTMLImageElement){let P=Nt(m),M=P==null?void 0:P.dataset.paraId,$=m.dataset.drawingId;if(P&&M&&$){let V={kind:"object",paraId:M,objectKind:"image",objectId:$,offset:Ni(P,m)};return g={paraId:M,drawingId:$},_t(),se(V),V}}let y=In(m);if(y){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===y.tableId){let M=Math.min(h.anchor.rowIndex,h.focus.rowIndex),$=Math.max(h.anchor.rowIndex,h.focus.rowIndex),V=Math.min(h.anchor.columnIndex,h.focus.columnIndex),j=Math.max(h.anchor.columnIndex,h.focus.columnIndex);if(y.point.rowIndex>=M&&y.point.rowIndex<=$&&y.point.columnIndex>=V&&y.point.columnIndex<=j)return h}let P={kind:"table-cell-range",tableId:y.tableId,anchor:y.point,focus:y.point};return (N=Tt(t))==null||N.removeAllRanges(),se(P),P}let E=(T=vf(t,c.clientX,c.clientY))!=null?T:pt(t);if(!E)return h;if((h==null?void 0:h.kind)==="text-range"){let P=nt(s,h),M=ve(s,P.anchor.paraId),$=ve(s,P.focus.paraId),V=ve(s,E.paraId);if(M&&$&&V&&M.container===$.container&&M.container===V.container){let j=V.index>M.index||V.index===M.index&&E.offset>=P.anchor.offset,ie=V.index<$.index||V.index===$.index&&E.offset<=P.focus.offset;if(j&&ie)return h}}g=null,Pt(t),dt(t,E);let C=v({kind:"caret"},E);return se(C),C},Id=c=>{var E;if(d||n.contextMenu===false)return;c.preventDefault(),c.stopPropagation(),ut(),mt(),gg(c);let m=document.createElement("div");m.className="coco-word-context-menu",m.setAttribute("role","menu"),m.contentEditable="false";for(let C of mg()){if(C.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=C.label,N.disabled=(E=C.disabled)!=null?E:false,N.setAttribute("role","menuitem"),N.addEventListener("mousedown",T=>T.preventDefault()),N.addEventListener("click",()=>{let T=C.action();mt(),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 y=m.getBoundingClientRect();m.style.left=`${Math.max(4,Math.min(c.clientX,window.innerWidth-y.width-4))}px`,m.style.top=`${Math.max(4,Math.min(c.clientY,window.innerHeight-y.height-4))}px`;},Nd=c=>{Kt&&!Kt.contains(c.target)&&mt();},Td=c=>{c.key==="Escape"&&mt();},Pd=c=>{var C;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"&&Pr()){c.preventDefault(),c.stopPropagation();return}if(c.inputType==="historyRedo"&&Rr()){c.preventDefault(),c.stopPropagation();return}if(c.isComposing||oe||te||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(t),y=(m==null?void 0:m.kind)==="text-range"?m:(h==null?void 0:h.kind)==="text-range"?h:m;if(S&&y&&(c.inputType==="insertText"||c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){if(y.kind==="caret"||y.kind==="text-range"&&y.anchor.paraId===y.focus.paraId){c.preventDefault(),c.inputType==="insertText"&&c.data?y.kind==="caret"?ke({kind:"insert-text",text:c.data}):ke({kind:"replace-range",anchor:y.anchor,focus:y.focus,text:c.data}):c.inputType==="deleteContentBackward"?y.kind==="text-range"&&y.anchor.offset!==y.focus.offset?ke({kind:"delete-range",anchor:y.anchor,focus:y.focus}):ke({kind:"delete-backward"}):c.inputType==="deleteContentForward"&&(y.kind==="text-range"&&y.anchor.offset!==y.focus.offset?ke({kind:"delete-range",anchor:y.anchor,focus:y.focus}):ke({kind:"delete-forward"}));return}if(y.kind==="text-range"&&(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){c.preventDefault(),ke({kind:"delete-range",anchor:y.anchor,focus:y.focus});return}}if((y==null?void 0:y.kind)==="text-range"&&y.anchor.paraId===y.focus.paraId){let N=Hi(y.anchor.offset,y.focus.offset);if(zo(y.anchor.paraId)&&(c.inputType==="insertText"&&c.data||c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){g=null,Nr(y.anchor.paraId),Vo({anchor:{paraId:y.anchor.paraId,offset:N.from},focus:{paraId:y.focus.paraId,offset:N.to}}),se(y);return}if(c.inputType==="insertText"&&c.data){c.preventDefault(),g=null,se({kind:"caret",paraId:y.anchor.paraId,offset:N.from+c.data.length}),Tn(Kr(s,y.anchor.paraId,N.from,N.to,c.data),{paraId:y.anchor.paraId,offset:N.from+c.data.length},{localParaId:y.anchor.paraId});return}if(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward"){if(c.preventDefault(),g=null,Uo(y))return;se({kind:"caret",paraId:y.anchor.paraId,offset:N.from}),Tn(bn(s,y.anchor.paraId,N.from,N.to),{paraId:y.anchor.paraId,offset:N.from},{localParaId:y.anchor.paraId});return}}if((y==null?void 0:y.kind)==="text-range"&&y.anchor.paraId!==y.focus.paraId){let N=nt(s,y);if(c.inputType==="insertText"&&c.data){if(c.preventDefault(),g=null,jo(N,c.data))return;md(N,c.data);return}if(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward"){if(jo(N,"")){c.preventDefault();return}if(!Qm(N)&&Xm(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}),md(N,"");return}c.preventDefault(),se(y);return}let E=(y==null?void 0:y.kind)==="caret"?y:pt(t);if(E){if(g=null,se({kind:"caret",paraId:E.paraId,offset:E.offset}),c.inputType==="insertText"&&c.data&&c.data!==`
|
|
1619
|
+
`).map(T=>T.split(" "));Va(E,{text:N});return}let C=E.kind==="text-range"?nt(s,E):{anchor:{paraId:E.paraId,offset:E.offset},focus:{paraId:E.paraId,offset:E.offset}};Xn(C,y);}catch(y){console.warn("Unable to paste from the context menu",y);}},_a=(c="add",m,y="")=>{let E=document.createElement("div");E.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 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=y;let R=document.createElement("div");R.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 $=document.createElement("button");$.type="button",$.className="coco-word-dialog-button is-primary",$.textContent="\u786E\u5B9A";let V=()=>E.remove();M.addEventListener("click",V),E.addEventListener("click",j=>{j.target===E&&V();}),C.addEventListener("keydown",j=>{j.key==="Escape"&&V(),j.key==="Enter"&&(j.ctrlKey||j.metaKey)&&(j.preventDefault(),$.click());}),$.addEventListener("click",()=>{let j=T.value.trim();if(!j){T.focus();return}Ee(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}),V();}),R.append(M,$),C.append(N,T,R),E.appendChild(C),(o!=null?o:document.body).appendChild(E),T.focus();},mg=()=>{var C,N,T;let c=(C=h!=null?h:ze(t))!=null?C:lt(t),m=Rt(c),y=(c==null?void 0:c.kind)==="text-range"||(c==null?void 0:c.kind)==="object"||(c==null?void 0:c.kind)==="table-cell-range",E=[{label:"\u526A\u5207",disabled:!y,action:()=>document.execCommand("cut")},{label:"\u590D\u5236",disabled:!y,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:hg},{label:"\u5220\u9664",disabled:!y,action:()=>pg()}];if((c==null?void 0:c.kind)==="text-range"&&(E.push({label:"\u6DFB\u52A0\u6279\u6CE8",separatorBefore:true,action:_a}),E.push({label:"\u6807\u8BB0\u4E3A\u63D2\u5165\u4FEE\u8BA2",action:()=>Ee({kind:"add-revision",revisionKind:"insert"})}),E.push({label:"\u6807\u8BB0\u4E3A\u5220\u9664\u4FEE\u8BA2",action:()=>Ee({kind:"add-revision",revisionKind:"delete"})}),E.push({label:m.bold===true?"\u53D6\u6D88\u52A0\u7C97":"\u52A0\u7C97",separatorBefore:true,disabled:!Dt(s,c,{kind:"toggle-bold"}),action:()=>Ee({kind:"toggle-bold"})}),E.push({label:"\u6E05\u9664\u6587\u672C\u683C\u5F0F",action:()=>Ee({kind:"clear-text-format"})}),m.hyperlink!==null&&E.push({label:"\u79FB\u9664\u8D85\u94FE\u63A5",disabled:!Dt(s,c,{kind:"remove-hyperlink"}),action:()=>Ee({kind:"remove-hyperlink"})})),(c==null?void 0:c.kind)==="caret"&&Dt(s,c,{kind:"insert-table",rows:2,columns:2})&&E.push({label:"\u63D2\u5165 2 \xD7 2 \u8868\u683C",separatorBefore:true,action:()=>Ee({kind:"insert-table",rows:2,columns:2})}),(c==null?void 0:c.kind)==="object"&&c.objectKind==="image"&&(E.push({label:"\u56FE\u7247\u5DE6\u5BF9\u9F50",separatorBefore:true,action:()=>Ee({kind:"set-image-alignment",objectId:c.objectId,alignment:"left"})}),E.push({label:"\u56FE\u7247\u5C45\u4E2D",action:()=>Ee({kind:"set-image-alignment",objectId:c.objectId,alignment:"center"})}),E.push({label:"\u56FE\u7247\u53F3\u5BF9\u9F50",action:()=>Ee({kind:"set-image-alignment",objectId:c.objectId,alignment:"right"})})),m.table){let R=(T=m.table.range)!=null?T:{startRow:m.table.rowIndex,endRow:m.table.rowIndex,startColumn:m.table.columnIndex,endColumn:m.table.columnIndex};E.push({label:"\u9009\u62E9\u6574\u884C",separatorBefore:true,action:()=>se({kind:"table-cell-range",tableId:m.table.tableId,anchor:{rowIndex:R.startRow,columnIndex:0},focus:{rowIndex:R.endRow,columnIndex:Math.max(0,m.table.columnCount-1)}})}),E.push({label:"\u9009\u62E9\u6574\u5217",action:()=>se({kind:"table-cell-range",tableId:m.table.tableId,anchor:{rowIndex:0,columnIndex:R.startColumn},focus:{rowIndex:Math.max(0,m.table.rowCount-1),columnIndex:R.endColumn}})}),E.push({label:"\u5728\u4E0A\u65B9\u63D2\u5165\u884C",disabled:!Dt(s,c,{kind:"insert-table-row"}),action:()=>Ee({kind:"insert-table-row",position:"before"})}),E.push({label:"\u5728\u4E0B\u65B9\u63D2\u5165\u884C",disabled:!Dt(s,c,{kind:"insert-table-row"}),action:()=>Ee({kind:"insert-table-row",position:"after"})}),E.push({label:"\u5220\u9664\u5F53\u524D\u884C",disabled:!Dt(s,c,{kind:"delete-table-row"}),action:()=>Ee({kind:"delete-table-row"})}),E.push({label:"\u5728\u5DE6\u4FA7\u63D2\u5165\u5217",disabled:!Dt(s,c,{kind:"insert-table-column"}),action:()=>Ee({kind:"insert-table-column",position:"before"})}),E.push({label:"\u5728\u53F3\u4FA7\u63D2\u5165\u5217",disabled:!Dt(s,c,{kind:"insert-table-column"}),action:()=>Ee({kind:"insert-table-column",position:"after"})}),E.push({label:"\u5220\u9664\u5F53\u524D\u5217",disabled:!Dt(s,c,{kind:"delete-table-column"}),action:()=>Ee({kind:"delete-table-column"})}),E.push({label:"\u5220\u9664\u8868\u683C",separatorBefore:true,disabled:!Dt(s,c,{kind:"delete-table"}),action:()=>Ee({kind:"delete-table"})});for(let[M,$]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"]])E.push({label:M,action:()=>Ee({kind:"set-table-cell-vertical-alignment",alignment:$})});}return E.push({label:"\u64A4\u9500",separatorBefore:true,disabled:!G.length,action:()=>Pr()},{label:"\u91CD\u505A",disabled:!K.length,action:()=>Rr()}),E},gg=c=>{var N,T;let m=c.target;if(m instanceof HTMLImageElement){let R=Nt(m),M=R==null?void 0:R.dataset.paraId,$=m.dataset.drawingId;if(R&&M&&$){let V={kind:"object",paraId:M,objectKind:"image",objectId:$,offset:Ni(R,m)};return g={paraId:M,drawingId:$},_t(),se(V),V}}let y=Tn(m);if(y){if((h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===y.tableId){let M=Math.min(h.anchor.rowIndex,h.focus.rowIndex),$=Math.max(h.anchor.rowIndex,h.focus.rowIndex),V=Math.min(h.anchor.columnIndex,h.focus.columnIndex),j=Math.max(h.anchor.columnIndex,h.focus.columnIndex);if(y.point.rowIndex>=M&&y.point.rowIndex<=$&&y.point.columnIndex>=V&&y.point.columnIndex<=j)return h}let R={kind:"table-cell-range",tableId:y.tableId,anchor:y.point,focus:y.point};return (N=Tt(t))==null||N.removeAllRanges(),se(R),R}let E=(T=vf(t,c.clientX,c.clientY))!=null?T:pt(t);if(!E)return h;if((h==null?void 0:h.kind)==="text-range"){let R=nt(s,h),M=ve(s,R.anchor.paraId),$=ve(s,R.focus.paraId),V=ve(s,E.paraId);if(M&&$&&V&&M.container===$.container&&M.container===V.container){let j=V.index>M.index||V.index===M.index&&E.offset>=R.anchor.offset,re=V.index<$.index||V.index===$.index&&E.offset<=R.focus.offset;if(j&&re)return h}}g=null,Pt(t),dt(t,E);let C=v({kind:"caret"},E);return se(C),C},Id=c=>{var E;if(d||n.contextMenu===false)return;c.preventDefault(),c.stopPropagation(),ut(),mt(),gg(c);let m=document.createElement("div");m.className="coco-word-context-menu",m.setAttribute("role","menu"),m.contentEditable="false";for(let C of mg()){if(C.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=C.label,N.disabled=(E=C.disabled)!=null?E:false,N.setAttribute("role","menuitem"),N.addEventListener("mousedown",T=>T.preventDefault()),N.addEventListener("click",()=>{let T=C.action();mt(),T instanceof Promise&&T.catch(R=>console.warn("Context menu action failed",R));}),m.appendChild(N);}(o!=null?o:document.body).appendChild(m),Kt=m;let y=m.getBoundingClientRect();m.style.left=`${Math.max(4,Math.min(c.clientX,window.innerWidth-y.width-4))}px`,m.style.top=`${Math.max(4,Math.min(c.clientY,window.innerHeight-y.height-4))}px`;},Nd=c=>{Kt&&!Kt.contains(c.target)&&mt();},Td=c=>{c.key==="Escape"&&mt();},Pd=c=>{var C;if(d){c.preventDefault();return}if(c.inputType===B){c.preventDefault(),B=null,U!==null&&window.clearTimeout(U),U=null;return}if(c.inputType==="historyUndo"&&Pr()){c.preventDefault(),c.stopPropagation();return}if(c.inputType==="historyRedo"&&Rr()){c.preventDefault(),c.stopPropagation();return}if(c.isComposing||ae||ie||c.inputType==="insertCompositionText"||c.inputType==="deleteCompositionText"||c.inputType==="insertFromComposition")return;if(g&&c.inputType==="deleteContentBackward"){c.preventDefault();let N={paraId:g.paraId,offset:0};Mn(g.paraId,g.drawingId,N);return}let m=ze(t),y=(m==null?void 0:m.kind)==="text-range"?m:(h==null?void 0:h.kind)==="text-range"?h:m;if(S&&y&&(c.inputType==="insertText"||c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){if(y.kind==="caret"||y.kind==="text-range"&&y.anchor.paraId===y.focus.paraId){c.preventDefault(),c.inputType==="insertText"&&c.data?y.kind==="caret"?Ee({kind:"insert-text",text:c.data}):Ee({kind:"replace-range",anchor:y.anchor,focus:y.focus,text:c.data}):c.inputType==="deleteContentBackward"?y.kind==="text-range"&&y.anchor.offset!==y.focus.offset?Ee({kind:"delete-range",anchor:y.anchor,focus:y.focus}):Ee({kind:"delete-backward"}):c.inputType==="deleteContentForward"&&(y.kind==="text-range"&&y.anchor.offset!==y.focus.offset?Ee({kind:"delete-range",anchor:y.anchor,focus:y.focus}):Ee({kind:"delete-forward"}));return}if(y.kind==="text-range"&&(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){c.preventDefault(),Ee({kind:"delete-range",anchor:y.anchor,focus:y.focus});return}}if((y==null?void 0:y.kind)==="text-range"&&y.anchor.paraId===y.focus.paraId){let N=Hi(y.anchor.offset,y.focus.offset);if(zo(y.anchor.paraId)&&(c.inputType==="insertText"&&c.data||c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward")){g=null,Nr(y.anchor.paraId),Vo({anchor:{paraId:y.anchor.paraId,offset:N.from},focus:{paraId:y.focus.paraId,offset:N.to}}),se(y);return}if(c.inputType==="insertText"&&c.data){c.preventDefault(),g=null,se({kind:"caret",paraId:y.anchor.paraId,offset:N.from+c.data.length}),Rn(Kr(s,y.anchor.paraId,N.from,N.to,c.data),{paraId:y.anchor.paraId,offset:N.from+c.data.length},{localParaId:y.anchor.paraId});return}if(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward"){if(c.preventDefault(),g=null,Uo(y))return;se({kind:"caret",paraId:y.anchor.paraId,offset:N.from}),Rn(bn(s,y.anchor.paraId,N.from,N.to),{paraId:y.anchor.paraId,offset:N.from},{localParaId:y.anchor.paraId});return}}if((y==null?void 0:y.kind)==="text-range"&&y.anchor.paraId!==y.focus.paraId){let N=nt(s,y);if(c.inputType==="insertText"&&c.data){if(c.preventDefault(),g=null,jo(N,c.data))return;md(N,c.data);return}if(c.inputType==="deleteContentBackward"||c.inputType==="deleteContentForward"){if(jo(N,"")){c.preventDefault();return}if(!Qm(N)&&Xm(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}),md(N,"");return}c.preventDefault(),se(y);return}let E=(y==null?void 0:y.kind)==="caret"?y:pt(t);if(E){if(g=null,se({kind:"caret",paraId:E.paraId,offset:E.offset}),c.inputType==="insertText"&&c.data&&c.data!==`
|
|
1605
1620
|
`&&c.data!=="\r"&&zo(E.paraId)){Nr(E.paraId),Vo({anchor:E,focus:E});return}if(c.inputType==="deleteContentBackward"&&E.offset>0&&zo(E.paraId)){Nr(E.paraId),Vo({anchor:E,focus:E});return}if(c.inputType==="deleteContentForward"&&E.offset<Oa(E.paraId)&&zo(E.paraId)){Nr(E.paraId),Vo({anchor:E,focus:E});return}if(c.inputType==="insertText"&&(c.data===`
|
|
1606
|
-
`||c.data==="\r")||c.inputType==="insertParagraph"){if(c.preventDefault(),I){I=false,D!==null&&window.clearTimeout(D),D=null;return}ja(E);}else if(c.inputType==="insertText"&&c.data)c.preventDefault(),Tn(on(s,E.paraId,E.offset,c.data),{paraId:E.paraId,offset:E.offset+c.data.length},{localParaId:E.paraId});else if(c.inputType==="deleteContentBackward"){if(c.preventDefault(),Rn(E,"delete-backward")||Ko(v({kind:"caret"},E),"backward")||xd(E))return;let N=J(s,E.paraId),T=N?ge(N):null,P=jr(s,E.paraId,E.offset),M={paraId:E.offset>0?E.paraId:(C=ms(s,E.paraId))!=null?C:E.paraId,offset:Math.max(0,E.offset-1)};(P==null?void 0:P.kind)==="image"?Mr(T,P,M):Tn(P,M,(P==null?void 0:P.kind)==="block"?{}:{localParaId:E.paraId});}else if(c.inputType==="deleteContentForward"){if(c.preventDefault(),Rn(E,"delete-forward")||Ko(v({kind:"caret"},E),"forward")||yd(E))return;let N=J(s,E.paraId),T=N?ge(N):null,P=Ur(s,E.paraId,E.offset),M={paraId:E.paraId,offset:E.offset};(P==null?void 0:P.kind)==="image"?Mr(T,P,M):Tn(P,M,{localParaId:E.paraId});}}},_o=c=>{var M,$,V,j,ie,ue,ye,Me;if(l)return;if(c.currentTarget===document){if(c.composedPath().includes(t)||fo.get(document)!==t)return}else ut();if(oe||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(),Ka(_).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 y=(c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key.toLowerCase()==="z",E=(c.ctrlKey||c.metaKey)&&c.shiftKey&&c.key.toLowerCase()==="z"||(c.ctrlKey||c.metaKey)&&c.key.toLowerCase()==="y";(y||E)&&B&&(B=null,G!==null&&window.clearTimeout(G),G=null);let C=y||E?pt(t):null,N=($=C==null?void 0:C.paraId)!=null?$:h&&"paraId"in h?h.paraId:null;if(y&&Pr()){dd("historyUndo"),c.preventDefault(),c.stopPropagation();return}if(E&&Rr()){dd("historyRedo"),c.preventDefault(),c.stopPropagation();return}if((c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key==="Enter"){let _=(V=h!=null?h:ze(t))!=null?V:lt(t);(_==null?void 0:_.kind)==="caret"&&ke({kind:"insert-page-break"})&&(c.preventDefault(),c.stopPropagation());return}if((y||E)&&(O!==null&&window.clearTimeout(O),$o.disconnect(),O=window.setTimeout(()=>{var he,pe;O=null;let _=pt(t),Q=(he=_==null?void 0:_.paraId)!=null?he:N;if(!Q)return;let ne=t.querySelector(`coco-word-native-p[data-para-id="${Q}"]`),re=J(s,Q);if(ne&&re&&re.content.every(Z=>Z.kind==="text")){let Z=qr(s,Q,(pe=ne.textContent)!=null?pe:"");Z&&(u.push(Z),Re("deferred"));}Be(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,ne=Q?(ie=tt(Q,h)[0])==null?void 0:ie.cell:null,re=ne==null?void 0:ne.paragraphs[0];if(re){c.preventDefault();let he={paraId:re.paraId,offset:Te(re).length};dt(t,he),se(v({kind:"caret"},he));}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=(ue=Oe(s,h.tableId))==null?void 0:ue.table,ne=Q?Math.max(1,...Q.rows.map(he=>he.cells.reduce((pe,Z)=>pe+Math.max(1,Z.gridSpan),0))):1,re={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(ne-1,h.focus.columnIndex+_.column))};c.preventDefault(),se({kind:"table-cell-range",tableId:h.tableId,anchor:c.shiftKey?h.anchor:re,focus:re});return}}if(!c.shiftKey&&["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(c.key)&&(z=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(t);if(!T)return;c.preventDefault(),c.stopPropagation();let P=J(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,D!==null&&window.clearTimeout(D),D=window.setTimeout(()=>{I=false,D=null;},0),ja(T);},Rd=c=>{if(!(l||c.composedPath().includes(t)||fo.get(document)!==t)){if(d){c.preventDefault(),c.stopPropagation();return}(c.inputType==="historyUndo"&&Pr()||c.inputType==="historyRedo"&&Rr())&&(c.preventDefault(),c.stopPropagation());}},qa=(c,m)=>{let y=c.querySelector(":scope > .coco-word-native-revision-group-list"),E=c.querySelector(":scope > .coco-word-native-revision-group-toggle");if(!y||!E)return;c.classList.toggle("is-expanded",m),y.hidden=!m,E.setAttribute("aria-expanded",String(m));let C=E.querySelector(".coco-word-native-revision-group-affordance");C&&(C.textContent=m?"\u6536\u8D77":"\u5C55\u5F00");},Md=c=>{t.querySelectorAll(".coco-word-native-revision-group.is-expanded").forEach(m=>{m!==c&&qa(m,false);});},Ad=c=>{var Me,_,Q,ne,re,he,pe,Z,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 y=(_=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(y){c.preventDefault(),c.stopPropagation();let be=y.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 fe=Fe.hidden;Md(be),qa(be,fe);return}let E=(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(E){c.preventDefault(),c.stopPropagation();let be=E.dataset.commentId;if(!be)return;let Fe=(ne=E.parentElement)==null?void 0:ne.querySelector(`[data-comment-menu-for="${CSS.escape(be)}"]`);if(!Fe)return;t.querySelectorAll(".coco-word-native-comment-menu:not([hidden])").forEach(fe=>{fe!==Fe&&(fe.hidden=true);}),Fe.hidden=!Fe.hidden;return}let C=(re=c.composedPath().find(be=>be instanceof HTMLButtonElement&&be.matches("[data-comment-action][data-comment-id]")))!=null?re:c.target instanceof Element?c.target.closest("[data-comment-action][data-comment-id]"):null;if(C){c.preventDefault(),c.stopPropagation();let be=Number(C.dataset.commentId);if(!Number.isFinite(be))return;let Fe=C.closest(".coco-word-native-comment-bubble");C.dataset.commentAction==="edit"?_a("edit",be,(he=Fe==null?void 0:Fe.dataset.commentBody)!=null?he:""):C.dataset.commentAction==="reply"?_a("reply",be):ke({kind:"delete-comment",commentId:be});return}if(Le){Le=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(),z=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,$=M!=null?M:T?t.querySelector(`.coco-word-native-comment-bubble[data-comment-id="${CSS.escape((pe=T.dataset.commentId)!=null?pe:"")}"]`):P?t.querySelector(`.coco-word-native-revision-bubble[data-revision-id="${CSS.escape((Z=P.dataset.revisionId)!=null?Z:"")}"][data-revision-kind="${CSS.escape((Ie=P.dataset.revisionKind)!=null?Ie:P.classList.contains("coco-word-revision-delete")?"delete":"insert")}"]`):null;if($){let be=$.closest(".coco-word-native-revision-group");be&&(Md(be),qa(be,true));let Fe=$.dataset.paraId,fe=Number($.dataset.from),Je=Number($.dataset.to);if(Fe&&Number.isFinite(fe)&&Number.isFinite(Je)){c.preventDefault(),c.stopPropagation(),t.querySelectorAll(".coco-word-native-comment-bubble.is-selected, .coco-word-native-revision-bubble.is-selected").forEach(De=>De.classList.remove("is-selected")),$.classList.add("is-selected");let me={kind:"text-range",anchor:{paraId:Fe,offset:fe},focus:{paraId:Fe,offset:Math.max(fe+1,Je)}};se(me);let we=T!=null?T:(()=>{var Ke,je,tn,An,Yn,Yo;let De=M==null?void 0:M.closest("coco-word-native-page");if(!De)return null;let de=$.dataset.revisionKind?`.coco-word-revision-insert[data-revision-id="${CSS.escape((Ke=$.dataset.revisionId)!=null?Ke:"")}"], .coco-word-revision-delete[data-revision-id="${CSS.escape((je=$.dataset.revisionId)!=null?je:"")}"], .coco-word-revision-format[data-revision-id="${CSS.escape((tn=$.dataset.revisionId)!=null?tn:"")}"], img[data-revision-id="${CSS.escape((An=$.dataset.revisionId)!=null?An:"")}"], coco-word-native-table[data-revision-id="${CSS.escape((Yn=$.dataset.revisionId)!=null?Yn:"")}"]`:`.coco-word-comment[data-comment-id="${CSS.escape((Yo=$.dataset.commentId)!=null?Yo:"")}"]`;return De.querySelector(de)})();(!we||!Sf(t,we))&&vn(t,me.anchor,me.focus);return}}let V=In(N);if(V){if(c.preventDefault(),c.stopPropagation(),g=null,Pt(t),(He=Tt(t))==null||He.removeAllRanges(),(h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===V.tableId&&V.point.rowIndex>=Math.min(h.anchor.rowIndex,h.focus.rowIndex)&&V.point.rowIndex<=Math.max(h.anchor.rowIndex,h.focus.rowIndex)&&V.point.columnIndex>=Math.min(h.anchor.columnIndex,h.focus.columnIndex)&&V.point.columnIndex<=Math.max(h.anchor.columnIndex,h.focus.columnIndex))return;se({kind:"table-cell-range",tableId:V.tableId,anchor:V.point,focus:V.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)&&fS(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(t);if(g=null,Pt(t),be)return;if((Fe==null?void 0:Fe.kind)==="text-range"){se(Fe);return}let fe=pt(t);fe&&dt(t,fe),se(fe?{kind:"caret",paraId:fe.paraId,offset:fe.offset}:null);return}let ie=Nt(N),ue=ie==null?void 0:ie.dataset.paraId,ye=N.dataset.drawingId;!ie||!ue||!ye||(ie.focus(),g={paraId:ue,drawingId:ye},Pt(t),_t(),se({kind:"object",paraId:ue,objectKind:"image",objectId:ye,offset:Ni(ie,N)}));},Ld=c=>{var P;if(c.button!==0||(et=false,c.target instanceof Node&&Nt(c.target)&&(x=null),c.target instanceof HTMLImageElement))return;let m=c.target instanceof Element?c.target:null,y=m?Nt(m):null,E=(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");!y&&!E&&!C&&(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,Ee=true;return}Ee=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,$=rn(s,M);($==null?void 0:$.table.tableId)===N.tableId&&(T={rowIndex:$.rowIndex,columnIndex:$.columnIndex});}c.preventDefault(),(P=Tt(t))==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;},Dd=c=>{var y;if(Ee&&(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(),(y=Tt(t))==null||y.removeAllRanges(),Qt=true,se({kind:"table-cell-range",tableId:ft.tableId,anchor:ft.point,focus:m.point}));},qo=()=>{var m;if(Ee){let y=ze(t);(y==null?void 0:y.kind)==="text-range"&&(x=y,se(y),Le=true),Ee=false;}if(Qt){(m=Tt(t))==null||m.removeAllRanges(),Nn(h),Kn=true,Qt=false,ft=null;return}ft=null;let c=ze(t);(c==null?void 0:c.kind)==="text-range"&&(x=c,g=null,Pt(t),se(c));},Wd=()=>{(ft||Ee)&&qo();},Bd=()=>{var y;if(l||oe||te||(h==null?void 0:h.kind)==="object"&&g||(h==null?void 0:h.kind)==="table-cell-range")return;if(Le&&x){se(x),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&&!t.contains(c)){at();return}Aa();let m=(y=ze(t))!=null?y:lt(t);(m==null?void 0:m.kind)==="text-range"&&(x=m),m&&(ut(),se(m));},Fd=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);},Lr=c=>{let m=c.composedPath(),y=m.some(N=>N instanceof Element&&N.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table")),E=m.some(N=>N instanceof HTMLButtonElement&&N.matches("[data-revision-action][data-revision-id], [data-revision-group-toggle]"));if(l||c.button!==0||y||E)return;let C=x!=null?x:(h==null?void 0:h.kind)==="text-range"?h:ze(t);(C==null?void 0:C.kind)==="text-range"&&(h!==C&&se(C),et=true,Ge=true,at(true),queueMicrotask(()=>at(true)),window.setTimeout(()=>at(true),0));},Hd=c=>{Lr(c),window.setTimeout(()=>at(true),0);},Od=c=>{d&&c.preventDefault();},Xo=c=>{t.classList.toggle("is-hyperlink-navigation-mode",c.ctrlKey||c.metaKey);},$d=()=>{t.classList.remove("is-hyperlink-navigation-mode");},zd=c=>{var M,$,V,j;if(d)return;let m=c;if(m.inputType===B){B=null,G!==null&&window.clearTimeout(G),G=null;return}if(m.isComposing||oe||m.inputType==="insertCompositionText"||m.inputType==="deleteCompositionText")return;if(te){X!==null&&window.clearTimeout(X),za();return}if(Ym()||m.inputType==="historyUndo"&&Zm()||m.inputType==="historyRedo"&&Jm())return;let y=pt(t),E=(M=Nt(c.target))!=null?M:y?t.querySelector(`coco-word-native-p[data-para-id="${y.paraId}"]`):null;if(!E||!t.contains(E))return;let C=($=E.dataset.paraId)!=null?$:"",N=J(s,C);if(!N||N.content.some(ie=>ie.kind!=="text"))return;let T=qr(s,C,(V=E.textContent)!=null?V:"");if(!T){(m.inputType==="historyUndo"||m.inputType==="historyRedo")&&pn(C);return}u.push(T);let P=cd(C,T);P&&u.push(P),z&&m.inputType!=="historyUndo"&&m.inputType!=="historyRedo"&&((j=z.afterParagraphs[0])==null?void 0:j.paraId)===C?(z.changes.push(T),z.afterParagraphs=[ge(N)]):z=null,Y.length=0,Ba(C),y&&se({kind:"caret",paraId:y.paraId,offset:y.offset}),P&&Wa(C,y!=null?y:void 0),Re("deferred");},Xa=c=>{var y,E;if(l)return false;if(!c){let C=Tt(t);return C&&(t.contains(C.anchorNode)||t.contains(C.focusNode))&&C.removeAllRanges(),g=null,Pt(t),se(null),true}if(c.kind==="caret")return J(s,c.paraId)?(g=null,Pt(t),dt(t,c),se(c),true):false;if(c.kind==="text-range")return !J(s,c.anchor.paraId)||!J(s,c.focus.paraId)?false:(g=null,Pt(t),vn(t,c.anchor,c.focus),se(c),true);if(c.kind==="table-cell-range"){let C=(y=Oe(s,c.tableId))==null?void 0:y.table;return !C||tt(C,c).length===0?false:(g=null,Pt(t),(E=Tt(t))==null||E.removeAllRanges(),se(c),true)}let m=t.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"] img[data-drawing-id="${c.objectId}"]`);return !J(s,c.paraId)||!m?false:(g={paraId:c.paraId,drawingId:c.objectId},Pt(t),_t(),se(c),true)},Vd=()=>{H!==null&&window.clearTimeout(H),A!==null&&window.clearTimeout(A),O!==null&&window.clearTimeout(O),ee!==null&&window.clearTimeout(ee),le!==null&&window.clearTimeout(le),D!==null&&window.clearTimeout(D),X!==null&&window.clearTimeout(X),G!==null&&window.clearTimeout(G),H=null,A=null,O=null,ee=null,le=null,D=null,X=null,G=null;};return t.addEventListener("beforeinput",Pd),t.addEventListener("compositionstart",fd),t.addEventListener("compositionend",pd),t.addEventListener("copy",Ua),t.addEventListener("cut",Ed),t.addEventListener("paste",Cd),t.addEventListener("drop",Od),t.addEventListener("keydown",_o),t.addEventListener("mousedown",Ld),t.addEventListener("click",Ad),t.addEventListener("mouseup",qo),t.addEventListener("input",zd),t.addEventListener("contextmenu",Id),document.addEventListener("keydown",_o,true),document.addEventListener("beforeinput",Rd,true),document.addEventListener("selectionchange",Bd),document.addEventListener("focusin",Fd),document.addEventListener("pointerdown",Lr,true),document.addEventListener("pointerup",Lr,true),document.addEventListener("click",Hd,true),document.addEventListener("keydown",Xo,true),document.addEventListener("keyup",Xo,true),document.addEventListener("mousemove",Dd),document.addEventListener("pointerdown",Nd,true),document.addEventListener("keydown",Td,true),document.addEventListener("scroll",mt,true),window.addEventListener("resize",mt),window.addEventListener("mouseup",Wd),window.addEventListener("blur",$d),Pe(),{kind:"native-word",get destroyed(){return l},isReadOnly(){return d},setReadOnly(c){l||d===c||(d=c,mt(),d&&(Ze==null||Ze(),Ze=null,ae=null,te=null,z=null,oe=false),Pe(void 0,h!=null?h:void 0));},destroy(){l||(l=true,t.removeEventListener("beforeinput",Pd),t.removeEventListener("compositionstart",fd),t.removeEventListener("compositionend",pd),t.removeEventListener("copy",Ua),t.removeEventListener("cut",Ed),t.removeEventListener("paste",Cd),t.removeEventListener("drop",Od),t.removeEventListener("keydown",_o),t.removeEventListener("mousedown",Ld),t.removeEventListener("click",Ad),t.removeEventListener("mouseup",qo),t.removeEventListener("input",zd),t.removeEventListener("contextmenu",Id),document.removeEventListener("keydown",_o,true),document.removeEventListener("beforeinput",Rd,true),document.removeEventListener("selectionchange",Bd),document.removeEventListener("focusin",Fd),document.removeEventListener("pointerdown",Lr,true),document.removeEventListener("pointerup",Lr,true),document.removeEventListener("click",Hd,true),document.removeEventListener("keydown",Xo,true),document.removeEventListener("keyup",Xo,true),document.removeEventListener("mousemove",Dd),document.removeEventListener("pointerdown",Nd,true),document.removeEventListener("keydown",Td,true),document.removeEventListener("scroll",mt,true),window.removeEventListener("resize",mt),window.removeEventListener("mouseup",Wd),window.removeEventListener("blur",$d),window.removeEventListener("resize",Fo),document.removeEventListener("scroll",Fo,true),Ze==null||Ze(),Ze=null,mt(),La(),Aa(),Ma.remove(),Vd(),$o.disconnect(),fo.get(document)===t&&fo.delete(document),kt.change.clear(),kt.selectionChange.clear(),o?o.replaceChildren():t.replaceChildren(),t.classList.remove("coco-word-native-editor-host"),t.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");Vd(),$o.disconnect(),a=c,mt(),La(),s=hs(a),u.length=0,p=[],b.clear();for(let m of _e(s))b.add(m.paraId);w=Date.now()>>>0,g=null,_n(),h=null,ae=null,te=null,z=null,oe=false,U=null,B=null,K.length=0,Y.length=0,Pe(),Ha();},getSourceView(){return a},getDocument(){return s},getSelection(){var c;return (c=h!=null?h:ze(t))!=null?c:lt(t)},setSelection(c){return Xa(c)},focus(){var y;if(l)return false;let c=(y=h!=null?h:ze(t))!=null?y:lt(t);if(c)return Xa(c);let m=_e(s)[0];return m?Xa({kind:"caret",paraId:m.paraId,offset:0}):false},async insertImage(c,m={}){if(l)return false;let y=typeof c=="string"?c:await Pp(c);return ke(v({kind:"insert-image",src:y},m))},search:Km,getSearchState(){return Bo()},findNext:_m,replaceCurrent:lg,replaceAll:dg,clearSearch:La,getCommandState(){var m;let c=(m=h!=null?h:ze(t))!=null?m:lt(t);return Rt(c)},getChanges(){return u.slice()},canUndo(){return !l&&!d&&K.length>0},canRedo(){return !l&&!d&&Y.length>0},undo:Pr,redo:Rr,canDispatch(c){var y;if(l||d)return false;let m=(y=h!=null?h:ze(t))!=null?y:lt(t);return Dt(s,m,c)},dispatch:ke,subscribe(c,m){if(l)return ()=>{};let y=m;return kt[c].add(y),()=>kt[c].delete(y)}}}function ge(t){return F(v({},t),{format:t.format?mo(t.format):null,content:t.content.map(uS)})}function uS(t){return t.kind==="pageBreak"?{kind:"pageBreak"}:t.kind==="text"?v(v(F(v({},t),{format:t.format?mo(t.format):null}),t.marks?{marks:t.marks.map(e=>v({},e))}:{}),t.hyperlink?{hyperlink:v({},t.hyperlink)}:{}):t.kind==="field"?F(v({},t),{format:t.format?mo(t.format):null}):t.kind==="image"?v(v({},t),t.position?{position:mo(t.position)}:{}):v(v(v({},t),t.position?{position:mo(t.position)}:{}),t.paragraphs?{paragraphs:t.paragraphs.map(ge)}:{})}function mo(t){return JSON.parse(JSON.stringify(t))}function fS(t){return !!t&&/^(https?:|mailto:|tel:)/i.test(t.trim())}function lr(t){return "beforeBlocks"in t}function pS(t,e){let n=e.kind==="paragraph"?`coco-word-native-p[data-para-id="${e.paraId}"]`:`coco-word-native-table[data-table-id="${e.tableId}"]`;return Array.from(t.querySelectorAll(n))}function Ip(t){var n;let e=ml;for(let r of _e(t))for(let o of r.content)if(o.kind==="text")for(let i of (n=o.marks)!=null?n:[])i.kind==="comment"&&(e=Math.max(e,i.commentId));return ml=e+1,ml}function ot(t){var n,r,o,i;let e=gl;for(let a of _e(t))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)&&(e=Math.max(e,p));}let l=s.formatRevision,d=Number(l==null?void 0:l.revisionId);Number.isInteger(d)&&(e=Math.max(e,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)&&(e=Math.max(e,l));}return gl=e+1,String(gl)}function hS(t,e){return (t==null?void 0:t.kind)!==(e==null?void 0:e.kind)?false:!t||!e?t===e:t.kind==="caret"&&e.kind==="caret"?t.paraId===e.paraId&&t.offset===e.offset:t.kind==="object"&&e.kind==="object"?t.paraId===e.paraId&&t.objectKind===e.objectKind&&t.objectId===e.objectId:t.kind==="text-range"&&e.kind==="text-range"?t.anchor.paraId===e.anchor.paraId&&t.anchor.offset===e.anchor.offset&&t.focus.paraId===e.focus.paraId&&t.focus.offset===e.focus.offset:t.kind==="table-cell-range"&&e.kind==="table-cell-range"?t.tableId===e.tableId&&t.anchor.rowIndex===e.anchor.rowIndex&&t.anchor.columnIndex===e.anchor.columnIndex&&t.focus.rowIndex===e.focus.rowIndex&&t.focus.columnIndex===e.focus.columnIndex:false}function Np(t,e){let n=e==="before"?t.beforeSelection:t.afterSelection;return n||(!t.changes.every(r=>r.kind==="format"||r.kind==="list")||t.range.anchor.paraId===t.range.focus.paraId&&t.range.anchor.offset===t.range.focus.offset?null:{kind:"text-range",anchor:t.range.anchor,focus:t.range.focus})}function Tp(t){return t.skipDeferredRender?false:t.changes.some(e=>e.kind==="block"||e.kind==="image"||e.kind==="page-break"||e.kind==="list"?true:e.kind!=="format"?false:e.op==="paragraph"?e.format.alignment===void 0:e.clear===true||e.format.bold!==void 0||e.format.italic!==void 0||e.format.fontFamily!==void 0||e.format.fontSize!==void 0)}function Mp(t,e){var n,r;return (r=(n=t.querySelector(`coco-word-native-p[data-para-id="${e}"]`))==null?void 0:n.textContent)!=null?r:null}function Fi(t,e){return e.every(n=>Mp(t,n.paraId)===Te(n))}function Hi(t,e){return {from:Math.max(0,Math.min(t,e)),to:Math.max(0,Math.max(t,e))}}function Pp(t){return new Promise((e,n)=>{let r=new FileReader;r.addEventListener("load",()=>{var o;return e(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(t);})}function Oi(t){let e=Xr(t);if(!e)return "";hl=hl+1>>>0;let n=`${Rp}${Date.now().toString(36)}-${hl.toString(36)}`;for(ho.set(n,e);ho.size>8;){let r=ho.keys().next().value;if(!r)break;ho.delete(r);}return n}function mS(t){var e;return t.startsWith(Rp)?(e=ho.get(t))!=null?e:"":t}function gS(t){var e;return t.kind==="text"?t.text:t.kind==="field"?(e=t.cachedText)!=null?e:"\uFFFC":t.kind==="drawing"&&t.text?t.text:"\uFFFC"}async function bS(t){let e=Au(t);if(e.type==="image/png")return e;let n=await createImageBitmap(e);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 $i(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<")}function wS(t){let e={};return Number.isFinite(t.left)&&(e.left=Math.max(0,t.left)),Number.isFinite(t.right)&&(e.right=Math.max(0,t.right)),Number.isFinite(t.firstLine)&&(e.firstLine=t.firstLine),e}function xS(t){let e={};return Number.isFinite(t.before)&&(e.before=Math.max(0,t.before)),Number.isFinite(t.after)&&(e.after=Math.max(0,t.after)),e}function nt(t,e){if(e.anchor.paraId===e.focus.paraId&&e.anchor.offset<=e.focus.offset)return {anchor:e.anchor,focus:e.focus};if(e.anchor.paraId!==e.focus.paraId){let n=ve(t,e.anchor.paraId),r=ve(t,e.focus.paraId);if(n&&r&&n.container===r.container)return n.index<=r.index?{anchor:e.anchor,focus:e.focus}:{anchor:e.focus,focus:e.anchor}}return {anchor:e.focus,focus:e.anchor}}function zi(t,e){return `${t}:${e}`}function go(t,e,n={}){var p,f,b,w;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 g of t.rows)i.set(g.index,g),d=Math.max(d,g.index);for(let g of t.columns){for(let h=g.min;h<=g.max;h++)a.set(h,g);u=Math.max(u,g.max);}for(let g of t.drawings)for(let h of g.anchors)if(!((b=h.object)!=null&&b.hidden))for(let x of [h.from,h.to])(x==null?void 0:x.row)!==void 0&&x.row>=0&&x.row<1048576&&(d=Math.max(d,Math.floor(x.row)+1)),(x==null?void 0:x.column)!==void 0&&x.column>=0&&x.column<16384&&(u=Math.max(u,Math.floor(x.column)+1));for(let g of t.cells){let h=Lp(g,e,n.formulaResults,n.date1904);r.set(g.address,h),o.set(zi(g.row,g.column),h),d=Math.max(d,g.row),u=Math.max(u,g.column);}for(let[g,h]of (w=n.formulaResults)!=null?w:[]){if(r.has(g)||h.error)continue;let x=parseCellAddress(g),S={address:g,row:x.row,column:x.column,kind:"formula",value:null},k=Lp(S,e,n.formulaResults,n.date1904);r.set(g,k),o.set(zi(x.row,x.column),k),d=Math.max(d,x.row),u=Math.max(u,x.column);}for(let g of t.mergedRanges){let h=parseRangeAddress(g.address),x=h.startRow+h.rowCount-1,S=h.startColumn+h.columnCount-1,k={startRow:h.startRow,startColumn:h.startColumn,endRow:x,endColumn:S},I=formatCellAddress(h.startRow,h.startColumn),D={address:g.address,range:k,masterAddress:I,source:g};s.set(I,D),d=Math.max(d,x),u=Math.max(u,S);for(let H=h.startRow;H<=x;H++)for(let A=h.startColumn;A<=S;A++){let O=formatCellAddress(H,A);O!==I&&l.set(O,I);}}return {sheetId:t.id,sheetName:t.name,source:t,styles:e,cellsByAddress:r,cellsByRowColumn:o,rowMetaByIndex:i,columnMetaByIndex:a,mergeMasterByAddress:s,mergeFollowerByAddress:l,maxRow:d,maxColumn:u}}function qe(t,e,n){return t.cellsByRowColumn.get(zi(e,n))}function Lp(t,e,n,r=false){var s,l;let o=n==null?void 0:n.get(t.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:t.value;return {row:t.row,column:t.column,address:t.address,kind:t.kind,value:a,displayText:SS(t,e,a,o,r),formula:t.formula,styleId:t.styleId,source:t}}function SS(t,e,n,r,o=false){return r!=null&&r.error?r.displayText:n!==null?ES(n,kS(t,e),o):""}function kS(t,e){var n,r;return (r=e.cellFormats[(n=t.styleId)!=null?n:0])==null?void 0:r.numberFormatCode}function ES(t,e,n=false){if(t===null)return "";if(typeof t!="number"||!e)return String(t);let r=e.toLowerCase();return r.includes("%")?`${Gi(t*100,Vi(e))}%`:r.includes("$")?`$${Gi(t,Vi(e),true)}`:CS(r)?IS(t,r,n):e.includes(",")?Gi(t,Vi(e),true):e.includes(".")?Gi(t,Vi(e)):String(t)}function Vi(t){var n,r;let e=/\.(0+)/.exec(t);return (r=(n=e==null?void 0:e[1])==null?void 0:n.length)!=null?r:0}function Gi(t,e,n=false){return new Intl.NumberFormat("en-US",{minimumFractionDigits:e,maximumFractionDigits:e,useGrouping:n}).format(t)}function CS(t){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(t)?true:/(^|[^a-z])y{2,4}([^a-z]|$)/.test(t)&&/(^|[^a-z])d{1,2}([^a-z]|$)/.test(t)}function IS(t,e,n){if(!Number.isFinite(t))return String(t);let r=Math.floor(t),o=t-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=H=>String(H).padStart(2,"0");if(e==="h:mm am/pm")return `${d}:${p(s)} ${u}`;if(e==="h:mm:ss am/pm")return `${d}:${p(s)}:${p(l)} ${u}`;if(e==="h:mm")return `${a}:${p(s)}`;if(e==="h:mm:ss")return `${a}:${p(s)}:${p(l)}`;if(e==="mm:ss")return `${p(s)}:${p(l)}`;if(e==="[h]:mm:ss")return `${Math.floor(t*24)}:${p(s)}:${p(l)}`;if(e==="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,x=f?29:w.getUTCDate(),S=p(h),k=p(x),I=p(g%100),D=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][h-1];return e==="mm-dd-yy"?`${S}-${k}-${I}`:e==="d-mmm-yy"?`${x}-${D}-${I}`:e==="d-mmm"?`${x}-${D}`:e==="mmm-yy"?`${D}-${I}`:e==="m/d/yy h:mm"?`${h}/${x}/${I} ${a}:${p(s)}`:`${g}-${S}-${k}`}var TS=22,PS=96,RS=48,MS=24,AS=1.2,bo=7,Dp=5,ji=class{constructor(e,n={}){W(this,"model",e);W(this,"defaultRowHeight");W(this,"defaultColumnWidth");W(this,"pointsToCssPixels");W(this,"maximumDigitWidth");W(this,"rowHeaderWidth");W(this,"columnHeaderHeight");W(this,"rowCount");W(this,"columnCount");W(this,"rowOffsets");W(this,"columnOffsets");W(this,"rowHeights");W(this,"columnWidths");var r,o,i,a,s,l;this.defaultRowHeight=(r=n.defaultRowHeight)!=null?r:TS,this.defaultColumnWidth=(o=n.defaultColumnWidth)!=null?o:PS,this.pointsToCssPixels=Ui(n.pointsToCssPixels,AS),this.maximumDigitWidth=Ui(n.maximumDigitWidth,bo),this.rowHeaderWidth=(i=n.rowHeaderWidth)!=null?i:RS,this.columnHeaderHeight=(a=n.columnHeaderHeight)!=null?a:MS,this.rowCount=Math.max((s=n.rowCount)!=null?s:0,e.maxRow),this.columnCount=Math.max((l=n.columnCount)!=null?l:0,e.maxColumn),this.rowHeights=LS(e,this.rowCount,this.defaultRowHeight,this.pointsToCssPixels),this.columnWidths=DS(e,this.columnCount,this.defaultColumnWidth,this.maximumDigitWidth),this.rowOffsets=Wp(this.rowHeights),this.columnOffsets=Wp(this.columnWidths);}totalWidth(){var e;return (e=this.columnOffsets[this.columnOffsets.length-1])!=null?e:0}totalHeight(){var e;return (e=this.rowOffsets[this.rowOffsets.length-1])!=null?e:0}getColumnWidth(e){var n;return (n=this.columnWidths[e-1])!=null?n:this.defaultColumnWidth}getRowHeight(e){var n;return (n=this.rowHeights[e-1])!=null?n:this.defaultRowHeight}getColumnX(e){var n;return (n=this.columnOffsets[Math.max(0,e-1)])!=null?n:0}getRowY(e){var n;return (n=this.rowOffsets[Math.max(0,e-1)])!=null?n:0}emuToCssPixels(e){return Number.isFinite(e)?(e!=null?e:0)/12700*this.pointsToCssPixels:0}cssPixelsToEmu(e){return Number.isFinite(e)?Math.round(e/this.pointsToCssPixels*12700):0}getCellLogicalRect(e,n){return {x:this.getColumnX(n),y:this.getRowY(e),width:this.getColumnWidth(n),height:this.getRowHeight(e)}}getRangeLogicalRect(e){let n=this.getColumnX(e.startColumn),r=this.getRowY(e.startRow),o=this.getColumnX(e.endColumn)+this.getColumnWidth(e.endColumn),i=this.getRowY(e.endRow)+this.getRowHeight(e.endRow);return {x:n,y:r,width:o-n,height:i-r}}getVisibleRange(e,n,r,o=1,i=1){let a=Math.max(i,this.columnAt(e)),s=Math.max(o,this.rowAt(n)),l=Math.max(a,Math.min(this.columnCount,this.columnAt(e+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(e){return Fp(Bp(this.rowOffsets,e),this.rowCount)}columnAt(e){return Fp(Bp(this.columnOffsets,e),this.columnCount)}hitTestLogical(e,n){let r=this.columnAt(e),o=this.rowAt(n);return o<1||r<1||o>this.rowCount||r>this.columnCount?{kind:"none"}:{kind:"cell",row:o,column:r,address:formatCellAddress(o,r)}}};function LS(t,e,n,r){let o=[];for(let i=1;i<=e;i++){let a=t.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(t,e,n,r){let o=[];for(let i=1;i<=e;i++){let a=t.columnMetaByIndex.get(i);o.push(a!=null&&a.hidden?0:(a==null?void 0:a.width)===void 0?n:WS(a.width,r));}return o}function WS(t,e=bo){if(!Number.isFinite(t)||t<=0)return 0;let n=Ui(e,bo);return Math.floor((256*t+Math.floor(128/n))/256*n)}function Ki(t,e=bo){if(!Number.isFinite(t)||t<=0)return 0;let n=Ui(e,bo),r=Math.floor((t-Dp)/n*100+.5)/100;return Math.floor((r*n+Dp)/n*256)/256}function Ui(t,e){return Number.isFinite(t)&&(t!=null?t:0)>0?t:e}function Wp(t){var n;let e=[0];for(let r of t)e.push(((n=e[e.length-1])!=null?n:0)+r);return e}function Bp(t,e){var o;if(e<=0)return 1;let n=0,r=t.length-1;for(;n<r;){let i=Math.floor((n+r+1)/2);((o=t[i])!=null?o:0)<=e?n=i:r=i-1;}return n+1}function Fp(t,e){return Math.max(1,Math.min(e,t))}var _i=class{constructor(e,n){W(this,"layout",e);W(this,"scroll");W(this,"freeze");W(this,"viewportSize");W(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(e,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=HS(e,this.viewportSize,this.scroll,this.freeze);}hitTest(e){let n=this.findViewport(e);if(!n)return {kind:"none"};if(n.kind==="corner")return {kind:"corner"};let r=e.x-n.screenRect.x+n.originX,o=e.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(e){for(let n=this.viewports.length-1;n>=0;n--){let r=this.viewports[n];if(r&&OS(r.screenRect,e))return r}}cellScreenRect(e,n,r){let o=this.layout.getCellLogicalRect(e,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 qi(t){var n;let e=(n=t.sheetViews[0])==null?void 0:n.pane;return BS(e)}function BS(t){var e,n;return !t||t.state!=="frozen"?{frozenRows:0,frozenColumns:0}:{frozenRows:Math.max(0,Math.floor((e=t.ySplit)!=null?e:0)),frozenColumns:Math.max(0,Math.floor((n=t.xSplit)!=null?n:0))}}function FS(t,e,n,r){let o=t.getColumnX(e.frozenColumns+1),i=t.getRowY(e.frozenRows+1),a=Math.max(0,n.width-t.rowHeaderWidth-o),s=Math.max(0,n.height-t.columnHeaderHeight-i),l=Math.max(0,t.totalWidth()-o-a),d=Math.max(0,t.totalHeight()-i-s);return {x:Math.max(0,Math.min(l,r.x)),y:Math.max(0,Math.min(d,r.y))}}function HS(t,e,n,r){let o=t.rowHeaderWidth,i=t.columnHeaderHeight,a=t.getColumnX(r.frozenColumns+1),s=t.getRowY(r.frozenRows+1),l=a+n.x,d=s+n.y,u=Math.max(0,e.width-o),p=Math.max(0,e.height-i),f=o+a,b=i+s,w=Math.max(0,e.width-f),g=Math.max(0,e.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,e.width-o-a),height:i},originX:l,originY:0,rows:{start:1,end:0},columns:wl(t,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,e.height-i-s)},originX:0,originY:d,rows:bl(t,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:wl(t,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:bl(t,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:bl(t,d,g,r.frozenRows+1),columns:wl(t,l,w,r.frozenColumns+1)}),h.filter(x=>x.screenRect.width>0&&x.screenRect.height>0)}function bl(t,e,n,r){let o=t.getVisibleRange(0,e,{width:1,height:n},r,1);return {start:o.startRow,end:o.endRow}}function wl(t,e,n,r){let o=t.getVisibleRange(e,0,{width:n,height:1},1,r);return {start:o.startColumn,end:o.endColumn}}function OS(t,e){return e.x>=t.x&&e.y>=t.y&&e.x<t.x+t.width&&e.y<t.y+t.height}function wo(t,e,n){var s,l,d,u,p,f,b,w,g,h;let r=(s=t.cellFormats[e!=null?e:0])!=null?s:{},o=(d=t.fonts[(l=r.fontId)!=null?l:0])!=null?d:{},i=(p=t.fills[(u=r.fillId)!=null?u:0])!=null?p:{},a=(b=t.borders[(f=r.borderId)!=null?f:0])!=null?b:{};return F(v({},xl(o)),{fillColor:(g=(w=i.foregroundColor)==null?void 0:w.rgb)!=null?g:"#FFFFFF",hasFill:i.foregroundColor!==void 0&&i.patternType!=="none",wrapText:((h=r.alignment)==null?void 0:h.wrapText)===true,border:a,horizontalAlign:zS(r,n),verticalAlign:VS(r)})}function xo(t,e,n){var u,p,f;let r=(f=t.fonts[(p=(u=t.cellFormats[e!=null?e:0])==null?void 0:u.fontId)!=null?p:0])!=null?f:{};if(!n.font)return xl(r);let{name:o,size:i,color:a,bold:s,italic:l,underline:d}=n.font;return xl({name:o!=null?o:r.name,size:i!=null?i:r.size,color:a!=null?a:r.color,bold:s,italic:l,underline:d})}function xl(t){var n,r,o,i;let e=(n=t.size)!=null?n:11;return {font:$S(t.bold,t.italic,e,(r=t.name)!=null?r:"Arial"),fontSize:e,underline:t.underline===true,fontColor:(i=(o=t.color)==null?void 0:o.rgb)!=null?i:"#111827"}}function Hp(t,e){let n={};for(let s=e.startColumn;s<=e.endColumn;s++)(n.top)!=null||(n.top=Xi(t,e.startRow,s,"top")),(n.bottom)!=null||(n.bottom=Xi(t,e.endRow,s,"bottom"));for(let s=e.startRow;s<=e.endRow;s++)(n.left)!=null||(n.left=Xi(t,s,e.startColumn,"left")),(n.right)!=null||(n.right=Xi(t,s,e.endColumn,"right"));return n}function Xi(t,e,n,r){var a,s,l,d;let o=qe(t,e,n),i=(s=t.styles.cellFormats[(a=o==null?void 0:o.styleId)!=null?a:0])!=null?s:{};return (d=t.styles.borders[(l=i.borderId)!=null?l:0])==null?void 0:d[r]}function $S(t,e,n,r){let o=[];return e&&o.push("italic"),t&&o.push("600"),o.push(`${n}pt`),o.push(qt(r,{families:[]})),o.join(" ")}function zS(t,e){var n;switch((n=t.alignment)==null?void 0:n.horizontal){case "left":return "left";case "center":return "center";case "right":return "right"}return (e==null?void 0:e.kind)==="number"||(e==null?void 0:e.kind)==="formula"&&typeof e.value=="number"?"right":(e==null?void 0:e.kind)==="boolean"||(e==null?void 0:e.kind)==="error"?"center":"left"}function VS(t){var e;switch((e=t.alignment)==null?void 0:e.vertical){case "top":return "top";case "center":case "middle":return "middle";case "bottom":return "bottom";default:return "bottom"}}var Op=typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"grapheme"}):void 0;function zp(t,e,n,r){let o=[],i=new Map,a=$p(),s=false,l,d=(f,b)=>{let w=i.get(f.font);w||(w=t.measureText("\u56FDAg"),i.set(f.font,w)),a.ascent=Math.max(a.ascent,w.actualBoundingBoxAscent||f.fontSize,(b==null?void 0:b.actualBoundingBoxAscent)||0),a.descent=Math.max(a.descent,w.actualBoundingBoxDescent||f.fontSize*.22,(b==null?void 0:b.actualBoundingBoxDescent)||0);let g=(w.fontBoundingBoxAscent||0)+(w.fontBoundingBoxDescent||0);a.minimumHeight=Math.max(a.minimumHeight,g||f.fontSize*1.2);},u=(f,b)=>{if(!f)return;let w=t.measureText(f);d(b,w),a.fragments.push({text:f,style:b,width:w.width}),a.width+=w.width;},p=()=>{o.push(a),a=$p();};for(let{text:f,style:b}of e){if(!f)continue;l=b,t.font=b.font;let w=f.split(/\r\n?|\n/);for(let[g,h]of w.entries()){if(g>0&&(a.fragments.length===0&&d(b),p(),s=true),!h)continue;if(s=false,!r){u(h,b);continue}let x="",S=Op?Array.from(Op.segment(h),({segment:k})=>k):Array.from(h);for(let k of S){let I=x+k;(x||a.fragments.length>0)&&a.width+t.measureText(I).width>n?(u(x,b),p(),x=k):x=I;}u(x,b);}}return s&&l&&d(l),(a.fragments.length>0||s)&&p(),o.map(f=>{let b=Math.max(f.minimumHeight,f.ascent+f.descent);return F(v({},f),{height:b,baseline:f.ascent+(b-f.ascent-f.descent)/2})})}function $p(){return {fragments:[],width:0,ascent:0,descent:0,minimumHeight:0}}var Qi=class{constructor(e){W(this,"options",e);W(this,"baseCtx");W(this,"headerCtx");W(this,"overlayCtx");W(this,"cssWidth",1);W(this,"cssHeight",1);W(this,"scaleX",1);W(this,"scaleY",1);W(this,"headerFiltersEnabled",true);W(this,"headerFilterColumns",null);W(this,"activeHeaderFilterColumns",new Set);this.baseCtx=Yi(e.baseCanvas),this.headerCtx=Yi(e.headerCanvas),this.overlayCtx=Yi(e.overlayCanvas);}resize(e,n,r=globalThis.devicePixelRatio||1){this.cssWidth=Math.max(1,e),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=Yi(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(e){this.headerFiltersEnabled=e;}setHeaderFilterColumns(e){this.headerFilterColumns=e===null?null:new Set(e);}setActiveHeaderFilterColumns(e){this.activeHeaderFilterColumns=new Set(e);}render(e,n){this.clearAll(e,n),this.drawCells(e,n),this.drawHeaders(e,n);}clearOverlay(){Zi(this.overlayCtx,this.options.overlayCanvas);}renderSelection(e,n,r,o={}){this.clearOverlay();let i=this.overlayCtx;for(let a of n.viewports){if(!Ji(a))continue;let s=Vp(r,{startRow:a.rows.start,endRow:a.rows.end,startColumn:a.columns.start,endColumn:a.columns.end});if(!s)continue;let l=e.getRangeLogicalRect(s),d=yl(l,a);yo(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([]),So(i,Sl(d,1),this.scaleX,this.scaleY);});}o.showFillHandle&&this.drawFillHandle(e,n,r);}fillHandleRect(e,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(e,n,r){this.renderDashedRange(e,n,r,{stroke:"#1D4ED8"});}renderDashedRange(e,n,r,o){let i=this.overlayCtx;for(let a of n.viewports){if(!Ji(a))continue;let s=Vp(r,{startRow:a.rows.start,endRow:a.rows.end,startColumn:a.columns.start,endColumn:a.columns.end});if(!s)continue;let l=e.getRangeLogicalRect(s),d=yl(l,a);yo(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,So(i,Sl(d,2),this.scaleX,this.scaleY),i.restore();});}}clearAll(e,n){Zi(this.baseCtx,this.options.baseCanvas),Zi(this.headerCtx,this.options.headerCanvas),Zi(this.overlayCtx,this.options.overlayCanvas);}drawFillHandle(e,n,r){let o=this.fillHandleRect(e,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,So(i,Sl(o,.5),this.scaleX,this.scaleY),i.restore();}drawCells(e,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)&&yo(r,o.screenRect,()=>{let i=[...jS(e,o)];for(let{row:a,column:s}of i)if(this.drawCell(r,e,n,o,a,s,{drawBorder:false,reserveTrailingSpace:this.headerFiltersEnabled&&a===1}),this.headerFiltersEnabled&&a===1&&(this.headerFilterColumns===null||this.headerFilterColumns.has(s))){let l=n.cellScreenRect(a,s,o);US(r,l,this.scaleX,this.scaleY,this.activeHeaderFilterColumns.has(s));}for(let{row:a,column:s}of i)this.drawCell(r,e,n,o,a,s,{drawContent:false});});}drawCell(e,n,r,o,i,a,s={}){var x,S;let l=qe(n.model,i,a),d=n.model.mergeMasterByAddress.get((x=l==null?void 0:l.address)!=null?x:formatCellAddress(i,a)),u=d?yl(n.getRangeLogicalRect(d.range),o):r.cellScreenRect(i,a,o),p=wo(n.model.styles,l==null?void 0:l.styleId,l),f=d?Hp(n.model,d.range):p.border;if(s.drawContent!==false&&(e.fillStyle=p.fillColor,e.fillRect(u.x,u.y,u.width,u.height),!p.hasFill&&((S=n.model.source.sheetViews[0])==null?void 0:S.showGridLines)!==false&&(e.strokeStyle="#E5E7EB",e.lineWidth=1/this.scaleX,So(e,u,this.scaleX,this.scaleY))),s.drawBorder!==false&&KS(e,u,f,this.scaleX,this.scaleY),s.drawContent===false||!(l!=null&&l.displayText))return;e.save(),e.font=p.font,e.fillStyle=p.fontColor,e.textAlign=p.horizontalAlign,e.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;yo(e,g,()=>{let k=l.kind==="string"?l.source.richText:void 0;if(k!=null&&k.length&&k.map(O=>O.text).join("")===l.displayText){e.textBaseline="alphabetic",e.textAlign="left";let O=zp(e,k.map(te=>({text:te.text,style:xo(n.model.styles,l.styleId,te)})),Math.max(1,g.width-b*2),p.wrapText||l.displayText.includes(`
|
|
1607
|
-
`)),ee=O.reduce((
|
|
1608
|
-
`)?_S(e,l.displayText,Math.max(1,g.width-b*2)):[l.displayText],D=p.fontSize*1.2,H=I.length*D,A=Gp(u,p,b,H,D);for(let O=0;O<I.length;O++){let ee=I[O],le=A+O*D;e.fillText(ee,h,le),p.underline&&jp(e,ee,h,le,p,this.scaleX,this.scaleY);}}),e.restore();}drawHeaders(e,n){let r=this.headerCtx;for(let o of n.viewports)yo(r,o.screenRect,()=>{if(o.kind==="corner")vl(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=e.getCellLogicalRect(1,i),s={x:o.screenRect.x+a.x-o.originX,y:o.screenRect.y,width:a.width,height:o.screenRect.height};vl(r,s,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=e.getCellLogicalRect(i,1),s={x:o.screenRect.x,y:o.screenRect.y+a.y-o.originY,width:o.screenRect.width,height:a.height};vl(r,s,String(i),this.scaleX,this.scaleY);}});}};function*jS(t,e){var i;let n=new Set,{mergeFollowerByAddress:r,mergeMasterByAddress:o}=t.model;for(let a=e.rows.start;a<=e.rows.end;a++)for(let s=e.columns.start;s<=e.columns.end;s++){let l=formatCellAddress(a,s),d=(i=r.get(l))!=null?i:l,u=o.get(d);u?n.has(d)||(n.add(d),yield {row:u.range.startRow,column:u.range.startColumn}):yield {row:a,column:s};}}function US(t,e,n,r,o=false){if(e.width<28)return;let i=e.x+e.width-10,a=e.y+e.height/2;t.save(),t.strokeStyle=o?"#2563EB":"#64748B",t.lineWidth=1/n,t.lineCap="round",t.beginPath(),t.moveTo(i-4,a-3),t.lineTo(i+4,a-3),t.lineTo(i+1,a+1),t.lineTo(i+1,a+4),t.lineTo(i-1,a+3),t.lineTo(i-1,a+1),t.closePath(),t.stroke(),t.restore();}function Vp(t,e){let n=Math.max(t.startRow,e.startRow),r=Math.max(t.startColumn,e.startColumn),o=Math.min(t.endRow,e.endRow),i=Math.min(t.endColumn,e.endColumn);return n>o||r>i?null:{startRow:n,startColumn:r,endRow:o,endColumn:i}}function Yi(t){let e=t.getContext("2d");if(!e)throw new Error("SpreadsheetCanvasRenderer: 2D canvas context is unavailable");return e}function Zi(t,e){let n=Number.parseFloat(e.style.width)||e.width,r=Number.parseFloat(e.style.height)||e.height;t.clearRect(0,0,n,r);}function yo(t,e,n){t.save(),t.beginPath(),t.rect(e.x,e.y,e.width,e.height),t.clip(),n(),t.restore();}function Ji(t){return t.kind==="main"||t.kind==="frozenTop"||t.kind==="frozenLeft"||t.kind==="frozenTopLeft"}function yl(t,e){return {x:e.screenRect.x+t.x-e.originX,y:e.screenRect.y+t.y-e.originY,width:t.width,height:t.height}}function vl(t,e,n,r,o){t.fillStyle="#F3F4F6",t.fillRect(e.x,e.y,e.width,e.height),t.strokeStyle="#D1D5DB",t.lineWidth=1/r,So(t,e,r,o),n&&(t.font="12px Arial",t.fillStyle="#374151",t.textAlign="center",t.textBaseline="middle",t.fillText(n,e.x+e.width/2,e.y+e.height/2));}function KS(t,e,n,r,o){var i,a,s,l,d,u,p,f;!n.left&&!n.right&&!n.top&&!n.bottom||(t.save(),t.lineWidth=1/r,t.setLineDash([]),n.top&&(t.strokeStyle=(a=(i=n.top.color)==null?void 0:i.rgb)!=null?a:"#111827",vo(t,e.x,e.y,e.x+e.width,e.y,r,o)),n.right&&(t.strokeStyle=(l=(s=n.right.color)==null?void 0:s.rgb)!=null?l:"#111827",vo(t,e.x+e.width,e.y,e.x+e.width,e.y+e.height,r,o)),n.bottom&&(t.strokeStyle=(u=(d=n.bottom.color)==null?void 0:d.rgb)!=null?u:"#111827",vo(t,e.x,e.y+e.height,e.x+e.width,e.y+e.height,r,o)),n.left&&(t.strokeStyle=(f=(p=n.left.color)==null?void 0:p.rgb)!=null?f:"#111827",vo(t,e.x,e.y,e.x,e.y+e.height,r,o)),t.restore());}function Gp(t,e,n,r,o){return e.verticalAlign==="top"?t.y+n+o/2:e.verticalAlign==="bottom"?t.y+t.height-n-r+o/2:t.y+(t.height-r)/2+o/2}function _S(t,e,n){let r=[];for(let o of e.split(/\r?\n/)){if(o===""){r.push("");continue}let i="";for(let a of o){let s=i+a;i&&t.measureText(s).width>n?(r.push(i),i=a):i=s;}i&&r.push(i);}return r.length>0?r:[""]}function vo(t,e,n,r,o,i,a){t.beginPath(),t.moveTo(kn(e,i),kn(n,a)),t.lineTo(kn(r,i),kn(o,a)),t.stroke();}function jp(t,e,n,r,o,i,a){let s=t.measureText(e),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);t.save(),t.strokeStyle=o.fontColor,t.lineWidth=1/i,vo(t,d,r+u,d+l,r+u,i,a),t.restore();}function Sl(t,e){return {x:t.x+e,y:t.y+e,width:Math.max(0,t.width-e*2),height:Math.max(0,t.height-e*2)}}function So(t,e,n,r){let o=kn(e.x,n),i=kn(e.y,r),a=kn(e.x+e.width,n),s=kn(e.y+e.height,r);t.strokeRect(o,i,Math.max(0,a-o),Math.max(0,s-i));}function kn(t,e){return (Math.round(t*e)+.5)/e}function it(t,e){return {kind:"cell",active:{row:t,column:e},range:{startRow:t,startColumn:e,endRow:t,endColumn:e}}}function ea(t,e){return {kind:"row",active:{row:t,column:1},range:{startRow:t,startColumn:1,endRow:t,endColumn:e.columnCount}}}function pT(t,e,n){let r=We({startRow:t,startColumn:1,endRow:e,endColumn:n.columnCount});return {kind:"row",active:{row:r.startRow,column:1},range:r}}function ta(t,e){return {kind:"column",active:{row:1,column:t},range:{startRow:1,startColumn:t,endRow:e.rowCount,endColumn:t}}}function hT(t,e,n){let r=We({startRow:1,startColumn:t,endRow:n.rowCount,endColumn:e});return {kind:"column",active:{row:1,column:r.startColumn},range:r}}function We(t){return {startRow:Math.min(t.startRow,t.endRow),startColumn:Math.min(t.startColumn,t.endColumn),endRow:Math.max(t.startRow,t.endRow),endColumn:Math.max(t.startColumn,t.endColumn)}}function cr(t,e,n,r){var o,i;return t.kind==="row"?{kind:"row",active:t.active,range:We({startRow:t.active.row,startColumn:1,endRow:e,endColumn:(o=r==null?void 0:r.columnCount)!=null?o:t.range.endColumn})}:t.kind==="column"?{kind:"column",active:t.active,range:We({startRow:1,startColumn:t.active.column,endRow:(i=r==null?void 0:r.rowCount)!=null?i:t.range.endRow,endColumn:n})}:{kind:"cell",active:t.active,range:We({startRow:t.active.row,startColumn:t.active.column,endRow:e,endColumn:n})}}function mT(t,e,n,r){return it(dr(t.active.row+e,1,r.rowCount),dr(t.active.column+n,1,r.columnCount))}function ct(t,e){var r;if(t.kind!=="cell")return t;let n=(r=ZS(t.active.row,t.active.column,e))!=null?r:t.active;return F(v({},t),{active:n,range:XS(t.range,e)})}function XS(t,e){let n=We(t),r=true;for(;r;){r=false;for(let o of e.mergeMasterByAddress.values()){if(!YS(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 gT(t,e,n,r,o){let i=dr(Kp(t.active.row,e,n),1,r.rowCount),a=dr(t.active.column,1,r.columnCount);return t.kind==="row"?ea(i,{columnCount:r.columnCount}):ct(it(i,a),o)}function bT(t,e,n,r,o){let i=dr(t.active.row,1,r.rowCount),a=dr(Kp(t.active.column,e,n),1,r.columnCount);return t.kind==="column"?ta(a,{rowCount:r.rowCount}):ct(it(i,a),o)}function Kp(t,e,n){let r=e+n-1;return t<e?t:t>r?t-n:e}function YS(t,e){return !(t.endRow<e.startRow||t.startRow>e.endRow||t.endColumn<e.startColumn||t.startColumn>e.endColumn)}function ZS(t,e,n){let r=n.mergeFollowerByAddress.get(formatCellAddress(t,e));if(!r)return null;let o=n.mergeMasterByAddress.get(r);return o?{row:o.range.startRow,column:o.range.startColumn}:null}function dr(t,e,n){return Math.max(e,Math.min(n,t))}var ur="application/x-coco-spreadsheet";function ko(t){return JSON.stringify(F(v({},t),{schema:1}))}function _p(t){var r;let e=t.getData(ur);if(e.trimStart().startsWith("{"))return e;let n=(r=new RegExp(`\\bdata-coco-spreadsheet-payload\\s*=\\s*(["'])(.*?)\\1`,"is").exec(t.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 Eo(t){var n;let e=_p(t);if(e){if(e.length>33554432)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{let r=JSON.parse(e);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 t.getData(ur)||((n=/\bdata-coco-spreadsheet="([^"]+)"/i.exec(t.getData("text/html")))==null?void 0:n[1])||null}function Il(t){let e=_p(t);if(!e)return null;if(e.length>33554432)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{return e0(JSON.parse(e))}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(t){if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Expected object");if(Object.keys(t).some(e=>e==="__proto__"||e==="constructor"||e==="prototype"))throw new Error("Invalid property");return t}function ln(t,e=32768){if(typeof t!="string"||t.length>e)throw new Error("Invalid string");return t}function Jt(t,e,n=1){if(typeof t!="number"||!Number.isInteger(t)||t<n||t>e)throw new Error("Invalid integer");return t}function JS(t){if(t===null||typeof t=="boolean"||typeof t=="string"||typeof t=="number"&&Number.isFinite(t))return t;throw new Error("Invalid cell value")}function kl(t,e,n,r){if(!Array.isArray(t)||t.length!==e)throw new Error("Invalid rows");return t.map(o=>{if(!Array.isArray(o)||o.length!==n)throw new Error("Invalid columns");return o.map(r)})}function El(t){let e=ln(Ut(t).rgb,7);if(!/^#[0-9a-f]{6}$/i.test(e))throw new Error("Invalid color");return {rgb:e}}function Cl(t,e,n,r){let o=Ut(t),i={};for(let a of e)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 QS(t){let e=Ut(t),n=Cl(e.font,["name","scheme"],["size","family","charset"],["bold","italic","underline"]),r=Ut(e.font);r.color!==void 0&&(n.color=El(r.color));let o=Cl(e.fill,["patternType"],[],[]),i=Ut(e.fill);for(let l of ["foregroundColor","backgroundColor"])i[l]!==void 0&&(o[l]=El(i[l]));let a=Ut(e.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:El(d.color)}:{});}return v(v(v({font:n,fill:o,border:s},e.alignment!==void 0?{alignment:Cl(e.alignment,["horizontal","vertical"],["textRotation","indent"],["wrapText","shrinkToFit"])}:{}),e.numberFormatId!==void 0?{numberFormatId:Jt(e.numberFormatId,65535,0)}:{}),e.numberFormatCode!==void 0?{numberFormatCode:ln(e.numberFormatCode,4096)}:{})}function e0(t){let e=Ut(t);if(e.schema!==1)throw new Error("Unsupported clipboard schema");let n=Ut(e.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=kl(e.values,o,i,JS),s=kl(e.formulas,o,i,f=>f===null?null:ln(f)),l=kl(e.styleIds,o,i,f=>f==null?void 0:Jt(f,1048576,0));if(!Array.isArray(e.merges)||e.merges.length>o*i)throw new Error("Invalid merges");let d=new Set,u=e.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 x=g*i+h;if(d.has(x))throw new Error("Overlapping merges");d.add(x);}return w}),p={};for(let[f,b]of Object.entries(Ut(e.styles))){if(f!=="default"&&!/^(0|[1-9]\d{0,6})$/.test(f))throw new Error("Invalid style key");p[f]=QS(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 F(v({schema:1,id:ln(e.id,256),sourceSheet:ln(e.sourceSheet,128)},e.sourceWorkbookId!==void 0?{sourceWorkbookId:ln(e.sourceWorkbookId,512)}:{}),{sourceRange:r,text:ln(e.text,33554432),values:a,formulas:s,styleIds:l,styles:p,merges:u})}function na(t,e,n={}){var s,l,d;let r=o0(t,e),o=d0(t,e),i={};for(let u of o)for(let p of u){let f=p===void 0?"default":String(p);(i[f])!=null||(i[f]=captureExcelCellStyle(t.styles,p));}return F(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:t.source.name,sourceRange:v({},e),text:r,values:s0(t,e),formulas:Array.from({length:e.endRow-e.startRow+1},(u,p)=>Array.from({length:e.endColumn-e.startColumn+1},(f,b)=>{var h,x;let w=e.startRow+p,g=e.startColumn+b;return t.mergeFollowerByAddress.has(formatCellAddress(w,g))?null:(x=(h=qe(t,w,g))==null?void 0:h.formula)!=null?x:null})),styleIds:o,styles:i,merges:l0(t,e)})}function o0(t,e){let n=[];for(let r=e.startRow;r<=e.endRow;r++){let o=[];for(let i=e.startColumn;i<=e.endColumn;i++)o.push(i0(a0(t,r,i)));n.push(o.join(" "));}return n.join(`
|
|
1621
|
+
`||c.data==="\r")||c.inputType==="insertParagraph"){if(c.preventDefault(),I){I=false,D!==null&&window.clearTimeout(D),D=null;return}ja(E);}else if(c.inputType==="insertText"&&c.data)c.preventDefault(),Rn(on(s,E.paraId,E.offset,c.data),{paraId:E.paraId,offset:E.offset+c.data.length},{localParaId:E.paraId});else if(c.inputType==="deleteContentBackward"){if(c.preventDefault(),An(E,"delete-backward")||Ko(v({kind:"caret"},E),"backward")||xd(E))return;let N=J(s,E.paraId),T=N?be(N):null,R=jr(s,E.paraId,E.offset),M={paraId:E.offset>0?E.paraId:(C=ms(s,E.paraId))!=null?C:E.paraId,offset:Math.max(0,E.offset-1)};(R==null?void 0:R.kind)==="image"?Mr(T,R,M):Rn(R,M,(R==null?void 0:R.kind)==="block"?{}:{localParaId:E.paraId});}else if(c.inputType==="deleteContentForward"){if(c.preventDefault(),An(E,"delete-forward")||Ko(v({kind:"caret"},E),"forward")||yd(E))return;let N=J(s,E.paraId),T=N?be(N):null,R=Ur(s,E.paraId,E.offset),M={paraId:E.paraId,offset:E.offset};(R==null?void 0:R.kind)==="image"?Mr(T,R,M):Rn(R,M,{localParaId:E.paraId});}}},_o=c=>{var M,$,V,j,re,ue,ye,Ae;if(l)return;if(c.currentTarget===document){if(c.composedPath().includes(t)||fo.get(document)!==t)return}else ut();if(ae||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 X=g;c.preventDefault(),c.stopPropagation(),Ka(X).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 y=(c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key.toLowerCase()==="z",E=(c.ctrlKey||c.metaKey)&&c.shiftKey&&c.key.toLowerCase()==="z"||(c.ctrlKey||c.metaKey)&&c.key.toLowerCase()==="y";(y||E)&&B&&(B=null,U!==null&&window.clearTimeout(U),U=null);let C=y||E?pt(t):null,N=($=C==null?void 0:C.paraId)!=null?$:h&&"paraId"in h?h.paraId:null;if(y&&Pr()){dd("historyUndo"),c.preventDefault(),c.stopPropagation();return}if(E&&Rr()){dd("historyRedo"),c.preventDefault(),c.stopPropagation();return}if((c.ctrlKey||c.metaKey)&&!c.shiftKey&&c.key==="Enter"){let X=(V=h!=null?h:ze(t))!=null?V:lt(t);(X==null?void 0:X.kind)==="caret"&&Ee({kind:"insert-page-break"})&&(c.preventDefault(),c.stopPropagation());return}if((y||E)&&(O!==null&&window.clearTimeout(O),$o.disconnect(),O=window.setTimeout(()=>{var he,pe;O=null;let X=pt(t),Q=(he=X==null?void 0:X.paraId)!=null?he:N;if(!Q)return;let te=t.querySelector(`coco-word-native-p[data-para-id="${Q}"]`),ne=J(s,Q);if(te&&ne&&ne.content.every(Z=>Z.kind==="text")){let Z=qr(s,Q,(pe=te.textContent)!=null?pe:"");Z&&(u.push(Z),Me("deferred"));}Be(Q,X!=null?X: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 he={paraId:ne.paraId,offset:Pe(ne).length};dt(t,he),se(v({kind:"caret"},he));}return}let X=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(X){let Q=(ue=Oe(s,h.tableId))==null?void 0:ue.table,te=Q?Math.max(1,...Q.rows.map(he=>he.cells.reduce((pe,Z)=>pe+Math.max(1,Z.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+X.row)),columnIndex:Math.max(0,Math.min(te-1,h.focus.columnIndex+X.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)&&(z=null),g&&(c.key==="Backspace"||c.key==="Delete")){c.preventDefault();let X={paraId:g.paraId,offset:0};Mn(g.paraId,g.drawingId,X);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(t);if(!T)return;c.preventDefault(),c.stopPropagation();let R=J(s,T.paraId);if((Ae=R==null?void 0:R.format)!=null&&Ae.hasNumbering&&R.format.numbering&&Pe(R).length===0){g=null,se({kind:"caret",paraId:T.paraId,offset:0}),Ee({kind:"remove-list"});return}g=null,I=true,D!==null&&window.clearTimeout(D),D=window.setTimeout(()=>{I=false,D=null;},0),ja(T);},Rd=c=>{if(!(l||c.composedPath().includes(t)||fo.get(document)!==t)){if(d){c.preventDefault(),c.stopPropagation();return}(c.inputType==="historyUndo"&&Pr()||c.inputType==="historyRedo"&&Rr())&&(c.preventDefault(),c.stopPropagation());}},qa=(c,m)=>{let y=c.querySelector(":scope > .coco-word-native-revision-group-list"),E=c.querySelector(":scope > .coco-word-native-revision-group-toggle");if(!y||!E)return;c.classList.toggle("is-expanded",m),y.hidden=!m,E.setAttribute("aria-expanded",String(m));let C=E.querySelector(".coco-word-native-revision-group-affordance");C&&(C.textContent=m?"\u6536\u8D77":"\u5C55\u5F00");},Md=c=>{t.querySelectorAll(".coco-word-native-revision-group.is-expanded").forEach(m=>{m!==c&&qa(m,false);});},Ad=c=>{var Ae,X,Q,te,ne,he,pe,Z,Ne,He;let m=(Ae=c.composedPath().find(we=>we instanceof HTMLButtonElement&&we.matches("[data-revision-action][data-revision-id]")))!=null?Ae:c.target instanceof Element?c.target.closest("[data-revision-action][data-revision-id]"):null;if(m){c.preventDefault(),c.stopPropagation();let we=m.dataset.revisionId;we&&Ee({kind:m.dataset.revisionAction==="accept"?"accept-revision":"reject-revision",revisionId:we,revisionKind:m.dataset.revisionKind});return}let y=(X=c.composedPath().find(we=>we instanceof HTMLButtonElement&&we.matches("[data-revision-group-toggle]")))!=null?X:c.target instanceof Element?c.target.closest("[data-revision-group-toggle]"):null;if(y){c.preventDefault(),c.stopPropagation();let we=y.closest(".coco-word-native-revision-group"),Fe=we==null?void 0:we.querySelector(":scope > .coco-word-native-revision-group-list");if(!we||!Fe)return;let fe=Fe.hidden;Md(we),qa(we,fe);return}let E=(Q=c.composedPath().find(we=>we instanceof HTMLButtonElement&&we.matches("[data-comment-menu][data-comment-id]")))!=null?Q:c.target instanceof Element?c.target.closest("[data-comment-menu][data-comment-id]"):null;if(E){c.preventDefault(),c.stopPropagation();let we=E.dataset.commentId;if(!we)return;let Fe=(te=E.parentElement)==null?void 0:te.querySelector(`[data-comment-menu-for="${CSS.escape(we)}"]`);if(!Fe)return;t.querySelectorAll(".coco-word-native-comment-menu:not([hidden])").forEach(fe=>{fe!==Fe&&(fe.hidden=true);}),Fe.hidden=!Fe.hidden;return}let C=(ne=c.composedPath().find(we=>we instanceof HTMLButtonElement&&we.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 we=Number(C.dataset.commentId);if(!Number.isFinite(we))return;let Fe=C.closest(".coco-word-native-comment-bubble");C.dataset.commentAction==="edit"?_a("edit",we,(he=Fe==null?void 0:Fe.dataset.commentBody)!=null?he:""):C.dataset.commentAction==="reply"?_a("reply",we):Ee({kind:"delete-comment",commentId:we});return}if(Ce){Ce=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(),z=null;let N=c.target,T=N instanceof Element?N.closest(".coco-word-comment[data-comment-id]"):null,R=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,$=M!=null?M:T?t.querySelector(`.coco-word-native-comment-bubble[data-comment-id="${CSS.escape((pe=T.dataset.commentId)!=null?pe:"")}"]`):R?t.querySelector(`.coco-word-native-revision-bubble[data-revision-id="${CSS.escape((Z=R.dataset.revisionId)!=null?Z:"")}"][data-revision-kind="${CSS.escape((Ne=R.dataset.revisionKind)!=null?Ne:R.classList.contains("coco-word-revision-delete")?"delete":"insert")}"]`):null;if($){let we=$.closest(".coco-word-native-revision-group");we&&(Md(we),qa(we,true));let Fe=$.dataset.paraId,fe=Number($.dataset.from),Je=Number($.dataset.to);if(Fe&&Number.isFinite(fe)&&Number.isFinite(Je)){c.preventDefault(),c.stopPropagation(),t.querySelectorAll(".coco-word-native-comment-bubble.is-selected, .coco-word-native-revision-bubble.is-selected").forEach(De=>De.classList.remove("is-selected")),$.classList.add("is-selected");let me={kind:"text-range",anchor:{paraId:Fe,offset:fe},focus:{paraId:Fe,offset:Math.max(fe+1,Je)}};se(me);let xe=T!=null?T:(()=>{var Ke,je,tn,Dn,Yn,Yo;let De=M==null?void 0:M.closest("coco-word-native-page");if(!De)return null;let de=$.dataset.revisionKind?`.coco-word-revision-insert[data-revision-id="${CSS.escape((Ke=$.dataset.revisionId)!=null?Ke:"")}"], .coco-word-revision-delete[data-revision-id="${CSS.escape((je=$.dataset.revisionId)!=null?je:"")}"], .coco-word-revision-format[data-revision-id="${CSS.escape((tn=$.dataset.revisionId)!=null?tn:"")}"], img[data-revision-id="${CSS.escape((Dn=$.dataset.revisionId)!=null?Dn:"")}"], coco-word-native-table[data-revision-id="${CSS.escape((Yn=$.dataset.revisionId)!=null?Yn:"")}"]`:`.coco-word-comment[data-comment-id="${CSS.escape((Yo=$.dataset.commentId)!=null?Yo:"")}"]`;return De.querySelector(de)})();(!xe||!Sf(t,xe))&&Sn(t,me.anchor,me.focus);return}}let V=Tn(N);if(V){if(c.preventDefault(),c.stopPropagation(),g=null,Pt(t),(He=Tt(t))==null||He.removeAllRanges(),(h==null?void 0:h.kind)==="table-cell-range"&&h.tableId===V.tableId&&V.point.rowIndex>=Math.min(h.anchor.rowIndex,h.focus.rowIndex)&&V.point.rowIndex<=Math.max(h.anchor.rowIndex,h.focus.rowIndex)&&V.point.columnIndex>=Math.min(h.anchor.columnIndex,h.focus.columnIndex)&&V.point.columnIndex<=Math.max(h.anchor.columnIndex,h.focus.columnIndex))return;se({kind:"table-cell-range",tableId:V.tableId,anchor:V.point,focus:V.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)&&fS(j.dataset.hyperlinkTarget)){window.open(j.dataset.hyperlinkTarget,"_blank","noopener,noreferrer");return}}if(!(N instanceof HTMLImageElement)){let we=N instanceof Node?Nt(N):null,Fe=ze(t);if(g=null,Pt(t),we)return;if((Fe==null?void 0:Fe.kind)==="text-range"){se(Fe);return}let fe=pt(t);fe&&dt(t,fe),se(fe?{kind:"caret",paraId:fe.paraId,offset:fe.offset}:null);return}let re=Nt(N),ue=re==null?void 0:re.dataset.paraId,ye=N.dataset.drawingId;!re||!ue||!ye||(re.focus(),g={paraId:ue,drawingId:ye},Pt(t),_t(),se({kind:"object",paraId:ue,objectKind:"image",objectId:ye,offset:Ni(re,N)}));},Ld=c=>{var R;if(c.button!==0||(et=false,c.target instanceof Node&&Nt(c.target)&&(x=null),c.target instanceof HTMLImageElement))return;let m=c.target instanceof Element?c.target:null,y=m?Nt(m):null,E=(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");!y&&!E&&!C&&(h==null?void 0:h.kind)==="text-range"?(Ge=true,at(true)):Ge=false;let N=Tn(c.target);if(N&&(Ge=false),!N){ft=null,ke=true;return}ke=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,$=rn(s,M);($==null?void 0:$.table.tableId)===N.tableId&&(T={rowIndex:$.rowIndex,columnIndex:$.columnIndex});}c.preventDefault(),(R=Tt(t))==null||R.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;},Dd=c=>{var y;if(ke&&(c.buttons&1)!==0){return}if(!ft||(c.buttons&1)===0)return;let m=Tn(c.target);!m||m.tableId!==ft.tableId||!Qt&&m.point.rowIndex===ft.point.rowIndex&&m.point.columnIndex===ft.point.columnIndex||(c.preventDefault(),(y=Tt(t))==null||y.removeAllRanges(),Qt=true,se({kind:"table-cell-range",tableId:ft.tableId,anchor:ft.point,focus:m.point}));},qo=()=>{var m;if(ke){let y=ze(t);(y==null?void 0:y.kind)==="text-range"&&(x=y,se(y),Ce=true),ke=false;}if(Qt){(m=Tt(t))==null||m.removeAllRanges(),Pn(h),Kn=true,Qt=false,ft=null;return}ft=null;let c=ze(t);(c==null?void 0:c.kind)==="text-range"&&(x=c,g=null,Pt(t),se(c));},Wd=()=>{(ft||ke)&&qo();},Bd=()=>{var y;if(l||ae||ie||(h==null?void 0:h.kind)==="object"&&g||(h==null?void 0:h.kind)==="table-cell-range")return;if(Ce&&x){se(x),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&&!t.contains(c)){at();return}Aa();let m=(y=ze(t))!=null?y:lt(t);(m==null?void 0:m.kind)==="text-range"&&(x=m),m&&(ut(),se(m));},Fd=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);},Lr=c=>{let m=c.composedPath(),y=m.some(N=>N instanceof Element&&N.matches("coco-word-native-page, coco-word-native-p, coco-word-native-table")),E=m.some(N=>N instanceof HTMLButtonElement&&N.matches("[data-revision-action][data-revision-id], [data-revision-group-toggle]"));if(l||c.button!==0||y||E)return;let C=x!=null?x:(h==null?void 0:h.kind)==="text-range"?h:ze(t);(C==null?void 0:C.kind)==="text-range"&&(h!==C&&se(C),et=true,Ge=true,at(true),queueMicrotask(()=>at(true)),window.setTimeout(()=>at(true),0));},Hd=c=>{Lr(c),window.setTimeout(()=>at(true),0);},Od=c=>{d&&c.preventDefault();},Xo=c=>{t.classList.toggle("is-hyperlink-navigation-mode",c.ctrlKey||c.metaKey);},$d=()=>{t.classList.remove("is-hyperlink-navigation-mode");},zd=c=>{var M,$,V,j;if(d)return;let m=c;if(m.inputType===B){B=null,U!==null&&window.clearTimeout(U),U=null;return}if(m.isComposing||ae||m.inputType==="insertCompositionText"||m.inputType==="deleteCompositionText")return;if(ie){Y!==null&&window.clearTimeout(Y),za();return}if(Ym()||m.inputType==="historyUndo"&&Zm()||m.inputType==="historyRedo"&&Jm())return;let y=pt(t),E=(M=Nt(c.target))!=null?M:y?t.querySelector(`coco-word-native-p[data-para-id="${y.paraId}"]`):null;if(!E||!t.contains(E))return;let C=($=E.dataset.paraId)!=null?$:"",N=J(s,C);if(!N||N.content.some(re=>re.kind!=="text"))return;let T=qr(s,C,(V=E.textContent)!=null?V:"");if(!T){(m.inputType==="historyUndo"||m.inputType==="historyRedo")&&pn(C);return}u.push(T);let R=cd(C,T);R&&u.push(R),z&&m.inputType!=="historyUndo"&&m.inputType!=="historyRedo"&&((j=z.afterParagraphs[0])==null?void 0:j.paraId)===C?(z.changes.push(T),z.afterParagraphs=[be(N)]):z=null,K.length=0,Ba(C),y&&se({kind:"caret",paraId:y.paraId,offset:y.offset}),R&&Wa(C,y!=null?y:void 0),Me("deferred");},Xa=c=>{var y,E;if(l)return false;if(!c){let C=Tt(t);return C&&(t.contains(C.anchorNode)||t.contains(C.focusNode))&&C.removeAllRanges(),g=null,Pt(t),se(null),true}if(c.kind==="caret")return J(s,c.paraId)?(g=null,Pt(t),dt(t,c),se(c),true):false;if(c.kind==="text-range")return !J(s,c.anchor.paraId)||!J(s,c.focus.paraId)?false:(g=null,Pt(t),Sn(t,c.anchor,c.focus),se(c),true);if(c.kind==="table-cell-range"){let C=(y=Oe(s,c.tableId))==null?void 0:y.table;return !C||tt(C,c).length===0?false:(g=null,Pt(t),(E=Tt(t))==null||E.removeAllRanges(),se(c),true)}let m=t.querySelector(`coco-word-native-p[data-para-id="${c.paraId}"] img[data-drawing-id="${c.objectId}"]`);return !J(s,c.paraId)||!m?false:(g={paraId:c.paraId,drawingId:c.objectId},Pt(t),_t(),se(c),true)},Vd=()=>{F!==null&&window.clearTimeout(F),A!==null&&window.clearTimeout(A),O!==null&&window.clearTimeout(O),ee!==null&&window.clearTimeout(ee),le!==null&&window.clearTimeout(le),D!==null&&window.clearTimeout(D),Y!==null&&window.clearTimeout(Y),U!==null&&window.clearTimeout(U),F=null,A=null,O=null,ee=null,le=null,D=null,Y=null,U=null;};return t.addEventListener("beforeinput",Pd),t.addEventListener("compositionstart",fd),t.addEventListener("compositionend",pd),t.addEventListener("copy",Ua),t.addEventListener("cut",Ed),t.addEventListener("paste",Cd),t.addEventListener("drop",Od),t.addEventListener("keydown",_o),t.addEventListener("mousedown",Ld),t.addEventListener("click",Ad),t.addEventListener("mouseup",qo),t.addEventListener("input",zd),t.addEventListener("contextmenu",Id),document.addEventListener("keydown",_o,true),document.addEventListener("beforeinput",Rd,true),document.addEventListener("selectionchange",Bd),document.addEventListener("focusin",Fd),document.addEventListener("pointerdown",Lr,true),document.addEventListener("pointerup",Lr,true),document.addEventListener("click",Hd,true),document.addEventListener("keydown",Xo,true),document.addEventListener("keyup",Xo,true),document.addEventListener("mousemove",Dd),document.addEventListener("pointerdown",Nd,true),document.addEventListener("keydown",Td,true),document.addEventListener("scroll",mt,true),window.addEventListener("resize",mt),window.addEventListener("mouseup",Wd),window.addEventListener("blur",$d),Re(),{kind:"native-word",get destroyed(){return l},isReadOnly(){return d},setReadOnly(c){l||d===c||(d=c,mt(),d&&(Ze==null||Ze(),Ze=null,oe=null,ie=null,z=null,ae=false),Re(void 0,h!=null?h:void 0));},destroy(){l||(l=true,t.removeEventListener("beforeinput",Pd),t.removeEventListener("compositionstart",fd),t.removeEventListener("compositionend",pd),t.removeEventListener("copy",Ua),t.removeEventListener("cut",Ed),t.removeEventListener("paste",Cd),t.removeEventListener("drop",Od),t.removeEventListener("keydown",_o),t.removeEventListener("mousedown",Ld),t.removeEventListener("click",Ad),t.removeEventListener("mouseup",qo),t.removeEventListener("input",zd),t.removeEventListener("contextmenu",Id),document.removeEventListener("keydown",_o,true),document.removeEventListener("beforeinput",Rd,true),document.removeEventListener("selectionchange",Bd),document.removeEventListener("focusin",Fd),document.removeEventListener("pointerdown",Lr,true),document.removeEventListener("pointerup",Lr,true),document.removeEventListener("click",Hd,true),document.removeEventListener("keydown",Xo,true),document.removeEventListener("keyup",Xo,true),document.removeEventListener("mousemove",Dd),document.removeEventListener("pointerdown",Nd,true),document.removeEventListener("keydown",Td,true),document.removeEventListener("scroll",mt,true),window.removeEventListener("resize",mt),window.removeEventListener("mouseup",Wd),window.removeEventListener("blur",$d),window.removeEventListener("resize",Fo),document.removeEventListener("scroll",Fo,true),Ze==null||Ze(),Ze=null,mt(),La(),Aa(),Ma.remove(),Vd(),$o.disconnect(),fo.get(document)===t&&fo.delete(document),kt.change.clear(),kt.selectionChange.clear(),o?o.replaceChildren():t.replaceChildren(),t.classList.remove("coco-word-native-editor-host"),t.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");Vd(),$o.disconnect(),a=c,mt(),La(),s=hs(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,oe=null,ie=null,z=null,ae=false,_=null,B=null,G.length=0,K.length=0,Re(),Ha();},getSourceView(){return a},getDocument(){return s},getSelection(){var c;return (c=h!=null?h:ze(t))!=null?c:lt(t)},setSelection(c){return Xa(c)},focus(){var y;if(l)return false;let c=(y=h!=null?h:ze(t))!=null?y:lt(t);if(c)return Xa(c);let m=_e(s)[0];return m?Xa({kind:"caret",paraId:m.paraId,offset:0}):false},async insertImage(c,m={}){if(l)return false;let y=typeof c=="string"?c:await Pp(c);return Ee(v({kind:"insert-image",src:y},m))},search:Km,getSearchState(){return Bo()},findNext:_m,replaceCurrent:lg,replaceAll:dg,clearSearch:La,getCommandState(){var m;let c=(m=h!=null?h:ze(t))!=null?m:lt(t);return Rt(c)},getChanges(){return u.slice()},canUndo(){return !l&&!d&&G.length>0},canRedo(){return !l&&!d&&K.length>0},undo:Pr,redo:Rr,canDispatch(c){var y;if(l||d)return false;let m=(y=h!=null?h:ze(t))!=null?y:lt(t);return Dt(s,m,c)},dispatch:Ee,subscribe(c,m){if(l)return ()=>{};let y=m;return kt[c].add(y),()=>kt[c].delete(y)}}}function be(t){return H(v({},t),{format:t.format?mo(t.format):null,content:t.content.map(uS)})}function uS(t){return t.kind==="pageBreak"?{kind:"pageBreak"}:t.kind==="text"?v(v(H(v({},t),{format:t.format?mo(t.format):null}),t.marks?{marks:t.marks.map(e=>v({},e))}:{}),t.hyperlink?{hyperlink:v({},t.hyperlink)}:{}):t.kind==="field"?H(v({},t),{format:t.format?mo(t.format):null}):t.kind==="image"?v(v({},t),t.position?{position:mo(t.position)}:{}):v(v(v({},t),t.position?{position:mo(t.position)}:{}),t.paragraphs?{paragraphs:t.paragraphs.map(be)}:{})}function mo(t){return JSON.parse(JSON.stringify(t))}function fS(t){return !!t&&/^(https?:|mailto:|tel:)/i.test(t.trim())}function lr(t){return "beforeBlocks"in t}function pS(t,e){let n=e.kind==="paragraph"?`coco-word-native-p[data-para-id="${e.paraId}"]`:`coco-word-native-table[data-table-id="${e.tableId}"]`;return Array.from(t.querySelectorAll(n))}function Ip(t){var n;let e=ml;for(let r of _e(t))for(let o of r.content)if(o.kind==="text")for(let i of (n=o.marks)!=null?n:[])i.kind==="comment"&&(e=Math.max(e,i.commentId));return ml=e+1,ml}function ot(t){var n,r,o,i;let e=gl;for(let a of _e(t))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)&&(e=Math.max(e,f));}let l=s.formatRevision,d=Number(l==null?void 0:l.revisionId);Number.isInteger(d)&&(e=Math.max(e,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)&&(e=Math.max(e,l));}return gl=e+1,String(gl)}function hS(t,e){return (t==null?void 0:t.kind)!==(e==null?void 0:e.kind)?false:!t||!e?t===e:t.kind==="caret"&&e.kind==="caret"?t.paraId===e.paraId&&t.offset===e.offset:t.kind==="object"&&e.kind==="object"?t.paraId===e.paraId&&t.objectKind===e.objectKind&&t.objectId===e.objectId:t.kind==="text-range"&&e.kind==="text-range"?t.anchor.paraId===e.anchor.paraId&&t.anchor.offset===e.anchor.offset&&t.focus.paraId===e.focus.paraId&&t.focus.offset===e.focus.offset:t.kind==="table-cell-range"&&e.kind==="table-cell-range"?t.tableId===e.tableId&&t.anchor.rowIndex===e.anchor.rowIndex&&t.anchor.columnIndex===e.anchor.columnIndex&&t.focus.rowIndex===e.focus.rowIndex&&t.focus.columnIndex===e.focus.columnIndex:false}function Np(t,e){let n=e==="before"?t.beforeSelection:t.afterSelection;return n||(!t.changes.every(r=>r.kind==="format"||r.kind==="list")||t.range.anchor.paraId===t.range.focus.paraId&&t.range.anchor.offset===t.range.focus.offset?null:{kind:"text-range",anchor:t.range.anchor,focus:t.range.focus})}function Tp(t){return t.skipDeferredRender?false:t.changes.some(e=>e.kind==="block"||e.kind==="image"||e.kind==="page-break"||e.kind==="list"?true:e.kind!=="format"?false:e.op==="paragraph"?e.format.alignment===void 0:e.clear===true||e.format.bold!==void 0||e.format.italic!==void 0||e.format.fontFamily!==void 0||e.format.fontSize!==void 0)}function Mp(t,e){var n,r;return (r=(n=t.querySelector(`coco-word-native-p[data-para-id="${e}"]`))==null?void 0:n.textContent)!=null?r:null}function Fi(t,e){return e.every(n=>Mp(t,n.paraId)===Pe(n))}function Hi(t,e){return {from:Math.max(0,Math.min(t,e)),to:Math.max(0,Math.max(t,e))}}function Pp(t){return new Promise((e,n)=>{let r=new FileReader;r.addEventListener("load",()=>{var o;return e(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(t);})}function Oi(t){let e=Xr(t);if(!e)return "";hl=hl+1>>>0;let n=`${Rp}${Date.now().toString(36)}-${hl.toString(36)}`;for(ho.set(n,e);ho.size>8;){let r=ho.keys().next().value;if(!r)break;ho.delete(r);}return n}function mS(t){var e;return t.startsWith(Rp)?(e=ho.get(t))!=null?e:"":t}function gS(t){var e;return t.kind==="text"?t.text:t.kind==="field"?(e=t.cachedText)!=null?e:"\uFFFC":t.kind==="drawing"&&t.text?t.text:"\uFFFC"}async function bS(t){let e=Au(t);if(e.type==="image/png")return e;let n=await createImageBitmap(e);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 $i(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<")}function wS(t){let e={};return Number.isFinite(t.left)&&(e.left=Math.max(0,t.left)),Number.isFinite(t.right)&&(e.right=Math.max(0,t.right)),Number.isFinite(t.firstLine)&&(e.firstLine=t.firstLine),e}function xS(t){let e={};return Number.isFinite(t.before)&&(e.before=Math.max(0,t.before)),Number.isFinite(t.after)&&(e.after=Math.max(0,t.after)),e}function nt(t,e){if(e.anchor.paraId===e.focus.paraId&&e.anchor.offset<=e.focus.offset)return {anchor:e.anchor,focus:e.focus};if(e.anchor.paraId!==e.focus.paraId){let n=ve(t,e.anchor.paraId),r=ve(t,e.focus.paraId);if(n&&r&&n.container===r.container)return n.index<=r.index?{anchor:e.anchor,focus:e.focus}:{anchor:e.focus,focus:e.anchor}}return {anchor:e.focus,focus:e.anchor}}function zi(t,e){return `${t}:${e}`}function go(t,e,n={}){var f,p,b,w;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 g of t.rows)i.set(g.index,g),d=Math.max(d,g.index);for(let g of t.columns){for(let h=g.min;h<=g.max;h++)a.set(h,g);u=Math.max(u,g.max);}for(let g of t.drawings)for(let h of g.anchors)if(!((b=h.object)!=null&&b.hidden))for(let x of [h.from,h.to])(x==null?void 0:x.row)!==void 0&&x.row>=0&&x.row<1048576&&(d=Math.max(d,Math.floor(x.row)+1)),(x==null?void 0:x.column)!==void 0&&x.column>=0&&x.column<16384&&(u=Math.max(u,Math.floor(x.column)+1));for(let g of t.cells){let h=Lp(g,e,n.formulaResults,n.date1904);r.set(g.address,h),o.set(zi(g.row,g.column),h),d=Math.max(d,g.row),u=Math.max(u,g.column);}for(let[g,h]of (w=n.formulaResults)!=null?w:[]){if(r.has(g)||h.error)continue;let x=parseCellAddress(g),S={address:g,row:x.row,column:x.column,kind:"formula",value:null},k=Lp(S,e,n.formulaResults,n.date1904);r.set(g,k),o.set(zi(x.row,x.column),k),d=Math.max(d,x.row),u=Math.max(u,x.column);}for(let g of t.mergedRanges){let h=parseRangeAddress(g.address),x=h.startRow+h.rowCount-1,S=h.startColumn+h.columnCount-1,k={startRow:h.startRow,startColumn:h.startColumn,endRow:x,endColumn:S},I=formatCellAddress(h.startRow,h.startColumn),D={address:g.address,range:k,masterAddress:I,source:g};s.set(I,D),d=Math.max(d,x),u=Math.max(u,S);for(let F=h.startRow;F<=x;F++)for(let A=h.startColumn;A<=S;A++){let O=formatCellAddress(F,A);O!==I&&l.set(O,I);}}return {sheetId:t.id,sheetName:t.name,source:t,styles:e,cellsByAddress:r,cellsByRowColumn:o,rowMetaByIndex:i,columnMetaByIndex:a,mergeMasterByAddress:s,mergeFollowerByAddress:l,maxRow:d,maxColumn:u}}function qe(t,e,n){return t.cellsByRowColumn.get(zi(e,n))}function Lp(t,e,n,r=false){var s,l;let o=n==null?void 0:n.get(t.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:t.value;return {row:t.row,column:t.column,address:t.address,kind:t.kind,value:a,displayText:SS(t,e,a,o,r),formula:t.formula,styleId:t.styleId,source:t}}function SS(t,e,n,r,o=false){return r!=null&&r.error?r.displayText:n!==null?ES(n,kS(t,e),o):""}function kS(t,e){var n,r;return (r=e.cellFormats[(n=t.styleId)!=null?n:0])==null?void 0:r.numberFormatCode}function ES(t,e,n=false){if(t===null)return "";if(typeof t!="number"||!e)return String(t);let r=e.toLowerCase();return r.includes("%")?`${Gi(t*100,Vi(e))}%`:r.includes("$")?`$${Gi(t,Vi(e),true)}`:CS(r)?IS(t,r,n):e.includes(",")?Gi(t,Vi(e),true):e.includes(".")?Gi(t,Vi(e)):String(t)}function Vi(t){var n,r;let e=/\.(0+)/.exec(t);return (r=(n=e==null?void 0:e[1])==null?void 0:n.length)!=null?r:0}function Gi(t,e,n=false){return new Intl.NumberFormat("en-US",{minimumFractionDigits:e,maximumFractionDigits:e,useGrouping:n}).format(t)}function CS(t){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(t)?true:/(^|[^a-z])y{2,4}([^a-z]|$)/.test(t)&&/(^|[^a-z])d{1,2}([^a-z]|$)/.test(t)}function IS(t,e,n){if(!Number.isFinite(t))return String(t);let r=Math.floor(t),o=t-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(e==="h:mm am/pm")return `${d}:${f(s)} ${u}`;if(e==="h:mm:ss am/pm")return `${d}:${f(s)}:${f(l)} ${u}`;if(e==="h:mm")return `${a}:${f(s)}`;if(e==="h:mm:ss")return `${a}:${f(s)}:${f(l)}`;if(e==="mm:ss")return `${f(s)}:${f(l)}`;if(e==="[h]:mm:ss")return `${Math.floor(t*24)}:${f(s)}:${f(l)}`;if(e==="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,x=p?29:w.getUTCDate(),S=f(h),k=f(x),I=f(g%100),D=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][h-1];return e==="mm-dd-yy"?`${S}-${k}-${I}`:e==="d-mmm-yy"?`${x}-${D}-${I}`:e==="d-mmm"?`${x}-${D}`:e==="mmm-yy"?`${D}-${I}`:e==="m/d/yy h:mm"?`${h}/${x}/${I} ${a}:${f(s)}`:`${g}-${S}-${k}`}var TS=22,PS=96,RS=48,MS=24,AS=1.2,bo=7,Dp=5,ji=class{constructor(e,n={}){W(this,"model",e);W(this,"defaultRowHeight");W(this,"defaultColumnWidth");W(this,"pointsToCssPixels");W(this,"maximumDigitWidth");W(this,"rowHeaderWidth");W(this,"columnHeaderHeight");W(this,"rowCount");W(this,"columnCount");W(this,"rowOffsets");W(this,"columnOffsets");W(this,"rowHeights");W(this,"columnWidths");var r,o,i,a,s,l;this.defaultRowHeight=(r=n.defaultRowHeight)!=null?r:TS,this.defaultColumnWidth=(o=n.defaultColumnWidth)!=null?o:PS,this.pointsToCssPixels=Ui(n.pointsToCssPixels,AS),this.maximumDigitWidth=Ui(n.maximumDigitWidth,bo),this.rowHeaderWidth=(i=n.rowHeaderWidth)!=null?i:RS,this.columnHeaderHeight=(a=n.columnHeaderHeight)!=null?a:MS,this.rowCount=Math.max((s=n.rowCount)!=null?s:0,e.maxRow),this.columnCount=Math.max((l=n.columnCount)!=null?l:0,e.maxColumn),this.rowHeights=LS(e,this.rowCount,this.defaultRowHeight,this.pointsToCssPixels),this.columnWidths=DS(e,this.columnCount,this.defaultColumnWidth,this.maximumDigitWidth),this.rowOffsets=Wp(this.rowHeights),this.columnOffsets=Wp(this.columnWidths);}totalWidth(){var e;return (e=this.columnOffsets[this.columnOffsets.length-1])!=null?e:0}totalHeight(){var e;return (e=this.rowOffsets[this.rowOffsets.length-1])!=null?e:0}getColumnWidth(e){var n;return (n=this.columnWidths[e-1])!=null?n:this.defaultColumnWidth}getRowHeight(e){var n;return (n=this.rowHeights[e-1])!=null?n:this.defaultRowHeight}getColumnX(e){var n;return (n=this.columnOffsets[Math.max(0,e-1)])!=null?n:0}getRowY(e){var n;return (n=this.rowOffsets[Math.max(0,e-1)])!=null?n:0}emuToCssPixels(e){return Number.isFinite(e)?(e!=null?e:0)/12700*this.pointsToCssPixels:0}cssPixelsToEmu(e){return Number.isFinite(e)?Math.round(e/this.pointsToCssPixels*12700):0}getCellLogicalRect(e,n){return {x:this.getColumnX(n),y:this.getRowY(e),width:this.getColumnWidth(n),height:this.getRowHeight(e)}}getRangeLogicalRect(e){let n=this.getColumnX(e.startColumn),r=this.getRowY(e.startRow),o=this.getColumnX(e.endColumn)+this.getColumnWidth(e.endColumn),i=this.getRowY(e.endRow)+this.getRowHeight(e.endRow);return {x:n,y:r,width:o-n,height:i-r}}getVisibleRange(e,n,r,o=1,i=1){let a=Math.max(i,this.columnAt(e)),s=Math.max(o,this.rowAt(n)),l=Math.max(a,Math.min(this.columnCount,this.columnAt(e+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(e){return Fp(Bp(this.rowOffsets,e),this.rowCount)}columnAt(e){return Fp(Bp(this.columnOffsets,e),this.columnCount)}hitTestLogical(e,n){let r=this.columnAt(e),o=this.rowAt(n);return o<1||r<1||o>this.rowCount||r>this.columnCount?{kind:"none"}:{kind:"cell",row:o,column:r,address:formatCellAddress(o,r)}}};function LS(t,e,n,r){let o=[];for(let i=1;i<=e;i++){let a=t.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(t,e,n,r){let o=[];for(let i=1;i<=e;i++){let a=t.columnMetaByIndex.get(i);o.push(a!=null&&a.hidden?0:(a==null?void 0:a.width)===void 0?n:WS(a.width,r));}return o}function WS(t,e=bo){if(!Number.isFinite(t)||t<=0)return 0;let n=Ui(e,bo);return Math.floor((256*t+Math.floor(128/n))/256*n)}function Ki(t,e=bo){if(!Number.isFinite(t)||t<=0)return 0;let n=Ui(e,bo),r=Math.floor((t-Dp)/n*100+.5)/100;return Math.floor((r*n+Dp)/n*256)/256}function Ui(t,e){return Number.isFinite(t)&&(t!=null?t:0)>0?t:e}function Wp(t){var n;let e=[0];for(let r of t)e.push(((n=e[e.length-1])!=null?n:0)+r);return e}function Bp(t,e){var o;if(e<=0)return 1;let n=0,r=t.length-1;for(;n<r;){let i=Math.floor((n+r+1)/2);((o=t[i])!=null?o:0)<=e?n=i:r=i-1;}return n+1}function Fp(t,e){return Math.max(1,Math.min(e,t))}var _i=class{constructor(e,n){W(this,"layout",e);W(this,"scroll");W(this,"freeze");W(this,"viewportSize");W(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(e,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=HS(e,this.viewportSize,this.scroll,this.freeze);}hitTest(e){let n=this.findViewport(e);if(!n)return {kind:"none"};if(n.kind==="corner")return {kind:"corner"};let r=e.x-n.screenRect.x+n.originX,o=e.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(e){for(let n=this.viewports.length-1;n>=0;n--){let r=this.viewports[n];if(r&&OS(r.screenRect,e))return r}}cellScreenRect(e,n,r){let o=this.layout.getCellLogicalRect(e,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 qi(t){var n;let e=(n=t.sheetViews[0])==null?void 0:n.pane;return BS(e)}function BS(t){var e,n;return !t||t.state!=="frozen"?{frozenRows:0,frozenColumns:0}:{frozenRows:Math.max(0,Math.floor((e=t.ySplit)!=null?e:0)),frozenColumns:Math.max(0,Math.floor((n=t.xSplit)!=null?n:0))}}function FS(t,e,n,r){let o=t.getColumnX(e.frozenColumns+1),i=t.getRowY(e.frozenRows+1),a=Math.max(0,n.width-t.rowHeaderWidth-o),s=Math.max(0,n.height-t.columnHeaderHeight-i),l=Math.max(0,t.totalWidth()-o-a),d=Math.max(0,t.totalHeight()-i-s);return {x:Math.max(0,Math.min(l,r.x)),y:Math.max(0,Math.min(d,r.y))}}function HS(t,e,n,r){let o=t.rowHeaderWidth,i=t.columnHeaderHeight,a=t.getColumnX(r.frozenColumns+1),s=t.getRowY(r.frozenRows+1),l=a+n.x,d=s+n.y,u=Math.max(0,e.width-o),f=Math.max(0,e.height-i),p=o+a,b=i+s,w=Math.max(0,e.width-p),g=Math.max(0,e.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,e.width-o-a),height:i},originX:l,originY:0,rows:{start:1,end:0},columns:wl(t,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,e.height-i-s)},originX:0,originY:d,rows:bl(t,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:wl(t,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:bl(t,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:bl(t,d,g,r.frozenRows+1),columns:wl(t,l,w,r.frozenColumns+1)}),h.filter(x=>x.screenRect.width>0&&x.screenRect.height>0)}function bl(t,e,n,r){let o=t.getVisibleRange(0,e,{width:1,height:n},r,1);return {start:o.startRow,end:o.endRow}}function wl(t,e,n,r){let o=t.getVisibleRange(e,0,{width:n,height:1},1,r);return {start:o.startColumn,end:o.endColumn}}function OS(t,e){return e.x>=t.x&&e.y>=t.y&&e.x<t.x+t.width&&e.y<t.y+t.height}function wo(t,e,n){var s,l,d,u,f,p,b,w,g,h;let r=(s=t.cellFormats[e!=null?e:0])!=null?s:{},o=(d=t.fonts[(l=r.fontId)!=null?l:0])!=null?d:{},i=(f=t.fills[(u=r.fillId)!=null?u:0])!=null?f:{},a=(b=t.borders[(p=r.borderId)!=null?p:0])!=null?b:{};return H(v({},xl(o)),{fillColor:(g=(w=i.foregroundColor)==null?void 0:w.rgb)!=null?g:"#FFFFFF",hasFill:i.foregroundColor!==void 0&&i.patternType!=="none",wrapText:((h=r.alignment)==null?void 0:h.wrapText)===true,border:a,horizontalAlign:zS(r,n),verticalAlign:VS(r)})}function xo(t,e,n){var u,f,p;let r=(p=t.fonts[(f=(u=t.cellFormats[e!=null?e:0])==null?void 0:u.fontId)!=null?f:0])!=null?p:{};if(!n.font)return xl(r);let{name:o,size:i,color:a,bold:s,italic:l,underline:d}=n.font;return xl({name:o!=null?o:r.name,size:i!=null?i:r.size,color:a!=null?a:r.color,bold:s,italic:l,underline:d})}function xl(t){var n,r,o,i;let e=(n=t.size)!=null?n:11;return {font:$S(t.bold,t.italic,e,(r=t.name)!=null?r:"Arial"),fontSize:e,underline:t.underline===true,fontColor:(i=(o=t.color)==null?void 0:o.rgb)!=null?i:"#111827"}}function Hp(t,e){let n={};for(let s=e.startColumn;s<=e.endColumn;s++)(n.top)!=null||(n.top=Xi(t,e.startRow,s,"top")),(n.bottom)!=null||(n.bottom=Xi(t,e.endRow,s,"bottom"));for(let s=e.startRow;s<=e.endRow;s++)(n.left)!=null||(n.left=Xi(t,s,e.startColumn,"left")),(n.right)!=null||(n.right=Xi(t,s,e.endColumn,"right"));return n}function Xi(t,e,n,r){var a,s,l,d;let o=qe(t,e,n),i=(s=t.styles.cellFormats[(a=o==null?void 0:o.styleId)!=null?a:0])!=null?s:{};return (d=t.styles.borders[(l=i.borderId)!=null?l:0])==null?void 0:d[r]}function $S(t,e,n,r){let o=[];return e&&o.push("italic"),t&&o.push("600"),o.push(`${n}pt`),o.push(qt(r,{families:[]})),o.join(" ")}function zS(t,e){var n;switch((n=t.alignment)==null?void 0:n.horizontal){case "left":return "left";case "center":return "center";case "right":return "right"}return (e==null?void 0:e.kind)==="number"||(e==null?void 0:e.kind)==="formula"&&typeof e.value=="number"?"right":(e==null?void 0:e.kind)==="boolean"||(e==null?void 0:e.kind)==="error"?"center":"left"}function VS(t){var e;switch((e=t.alignment)==null?void 0:e.vertical){case "top":return "top";case "center":case "middle":return "middle";case "bottom":return "bottom";default:return "bottom"}}var Op=typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"grapheme"}):void 0;function zp(t,e,n,r){let o=[],i=new Map,a=$p(),s=false,l,d=(p,b)=>{let w=i.get(p.font);w||(w=t.measureText("\u56FDAg"),i.set(p.font,w)),a.ascent=Math.max(a.ascent,w.actualBoundingBoxAscent||p.fontSize,(b==null?void 0:b.actualBoundingBoxAscent)||0),a.descent=Math.max(a.descent,w.actualBoundingBoxDescent||p.fontSize*.22,(b==null?void 0:b.actualBoundingBoxDescent)||0);let g=(w.fontBoundingBoxAscent||0)+(w.fontBoundingBoxDescent||0);a.minimumHeight=Math.max(a.minimumHeight,g||p.fontSize*1.2);},u=(p,b)=>{if(!p)return;let w=t.measureText(p);d(b,w),a.fragments.push({text:p,style:b,width:w.width}),a.width+=w.width;},f=()=>{o.push(a),a=$p();};for(let{text:p,style:b}of e){if(!p)continue;l=b,t.font=b.font;let w=p.split(/\r\n?|\n/);for(let[g,h]of w.entries()){if(g>0&&(a.fragments.length===0&&d(b),f(),s=true),!h)continue;if(s=false,!r){u(h,b);continue}let x="",S=Op?Array.from(Op.segment(h),({segment:k})=>k):Array.from(h);for(let k of S){let I=x+k;(x||a.fragments.length>0)&&a.width+t.measureText(I).width>n?(u(x,b),f(),x=k):x=I;}u(x,b);}}return s&&l&&d(l),(a.fragments.length>0||s)&&f(),o.map(p=>{let b=Math.max(p.minimumHeight,p.ascent+p.descent);return H(v({},p),{height:b,baseline:p.ascent+(b-p.ascent-p.descent)/2})})}function $p(){return {fragments:[],width:0,ascent:0,descent:0,minimumHeight:0}}var Qi=class{constructor(e){W(this,"options",e);W(this,"baseCtx");W(this,"headerCtx");W(this,"overlayCtx");W(this,"cssWidth",1);W(this,"cssHeight",1);W(this,"scaleX",1);W(this,"scaleY",1);W(this,"headerFiltersEnabled",true);W(this,"headerFilterColumns",null);W(this,"activeHeaderFilterColumns",new Set);this.baseCtx=Yi(e.baseCanvas),this.headerCtx=Yi(e.headerCanvas),this.overlayCtx=Yi(e.overlayCanvas);}resize(e,n,r=globalThis.devicePixelRatio||1){this.cssWidth=Math.max(1,e),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=Yi(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(e){this.headerFiltersEnabled=e;}setHeaderFilterColumns(e){this.headerFilterColumns=e===null?null:new Set(e);}setActiveHeaderFilterColumns(e){this.activeHeaderFilterColumns=new Set(e);}render(e,n){this.clearAll(e,n),this.drawCells(e,n),this.drawHeaders(e,n);}clearOverlay(){Zi(this.overlayCtx,this.options.overlayCanvas);}renderSelection(e,n,r,o={}){this.clearOverlay();let i=this.overlayCtx;for(let a of n.viewports){if(!Ji(a))continue;let s=Vp(r,{startRow:a.rows.start,endRow:a.rows.end,startColumn:a.columns.start,endColumn:a.columns.end});if(!s)continue;let l=e.getRangeLogicalRect(s),d=yl(l,a);yo(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([]),So(i,Sl(d,1),this.scaleX,this.scaleY);});}o.showFillHandle&&this.drawFillHandle(e,n,r);}fillHandleRect(e,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(e,n,r){this.renderDashedRange(e,n,r,{stroke:"#1D4ED8"});}renderDashedRange(e,n,r,o){let i=this.overlayCtx;for(let a of n.viewports){if(!Ji(a))continue;let s=Vp(r,{startRow:a.rows.start,endRow:a.rows.end,startColumn:a.columns.start,endColumn:a.columns.end});if(!s)continue;let l=e.getRangeLogicalRect(s),d=yl(l,a);yo(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,So(i,Sl(d,2),this.scaleX,this.scaleY),i.restore();});}}clearAll(e,n){Zi(this.baseCtx,this.options.baseCanvas),Zi(this.headerCtx,this.options.headerCanvas),Zi(this.overlayCtx,this.options.overlayCanvas);}drawFillHandle(e,n,r){let o=this.fillHandleRect(e,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,So(i,Sl(o,.5),this.scaleX,this.scaleY),i.restore();}drawCells(e,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)&&yo(r,o.screenRect,()=>{let i=[...jS(e,o)];for(let{row:a,column:s}of i)if(this.drawCell(r,e,n,o,a,s,{drawBorder:false,reserveTrailingSpace:this.headerFiltersEnabled&&a===1}),this.headerFiltersEnabled&&a===1&&(this.headerFilterColumns===null||this.headerFilterColumns.has(s))){let l=n.cellScreenRect(a,s,o);US(r,l,this.scaleX,this.scaleY,this.activeHeaderFilterColumns.has(s));}for(let{row:a,column:s}of i)this.drawCell(r,e,n,o,a,s,{drawContent:false});});}drawCell(e,n,r,o,i,a,s={}){var x,S;let l=qe(n.model,i,a),d=n.model.mergeMasterByAddress.get((x=l==null?void 0:l.address)!=null?x:formatCellAddress(i,a)),u=d?yl(n.getRangeLogicalRect(d.range),o):r.cellScreenRect(i,a,o),f=wo(n.model.styles,l==null?void 0:l.styleId,l),p=d?Hp(n.model,d.range):f.border;if(s.drawContent!==false&&(e.fillStyle=f.fillColor,e.fillRect(u.x,u.y,u.width,u.height),!f.hasFill&&((S=n.model.source.sheetViews[0])==null?void 0:S.showGridLines)!==false&&(e.strokeStyle="#E5E7EB",e.lineWidth=1/this.scaleX,So(e,u,this.scaleX,this.scaleY))),s.drawBorder!==false&&KS(e,u,p,this.scaleX,this.scaleY),s.drawContent===false||!(l!=null&&l.displayText))return;e.save(),e.font=f.font,e.fillStyle=f.fontColor,e.textAlign=f.horizontalAlign,e.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;yo(e,g,()=>{let k=l.kind==="string"?l.source.richText:void 0;if(k!=null&&k.length&&k.map(O=>O.text).join("")===l.displayText){e.textBaseline="alphabetic",e.textAlign="left";let O=zp(e,k.map(ie=>({text:ie.text,style:xo(n.model.styles,l.styleId,ie)})),Math.max(1,g.width-b*2),f.wrapText||l.displayText.includes(`
|
|
1622
|
+
`)),ee=O.reduce((ie,ae)=>ie+ae.height,0),le=Gp(g,f,b,ee,0),oe=f.verticalAlign==="middle"?Math.max(g.y+b,le):le;for(let ie of O){let ae=f.horizontalAlign==="right"?h-ie.width:f.horizontalAlign==="center"?h-ie.width/2:h,_=oe+ie.baseline;for(let Y of ie.fragments)e.font=Y.style.font,e.fillStyle=Y.style.fontColor,e.fillText(Y.text,ae,_),Y.style.underline&&jp(e,Y.text,ae,_,H(v({},Y.style),{horizontalAlign:"left"}),this.scaleX,this.scaleY),ae+=Y.width;oe+=ie.height;}return}let I=f.wrapText||l.displayText.includes(`
|
|
1623
|
+
`)?_S(e,l.displayText,Math.max(1,g.width-b*2)):[l.displayText],D=f.fontSize*1.2,F=I.length*D,A=Gp(u,f,b,F,D);for(let O=0;O<I.length;O++){let ee=I[O],le=A+O*D;e.fillText(ee,h,le),f.underline&&jp(e,ee,h,le,f,this.scaleX,this.scaleY);}}),e.restore();}drawHeaders(e,n){let r=this.headerCtx;for(let o of n.viewports)yo(r,o.screenRect,()=>{if(o.kind==="corner")vl(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=e.getCellLogicalRect(1,i),s={x:o.screenRect.x+a.x-o.originX,y:o.screenRect.y,width:a.width,height:o.screenRect.height};vl(r,s,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=e.getCellLogicalRect(i,1),s={x:o.screenRect.x,y:o.screenRect.y+a.y-o.originY,width:o.screenRect.width,height:a.height};vl(r,s,String(i),this.scaleX,this.scaleY);}});}};function*jS(t,e){var i;let n=new Set,{mergeFollowerByAddress:r,mergeMasterByAddress:o}=t.model;for(let a=e.rows.start;a<=e.rows.end;a++)for(let s=e.columns.start;s<=e.columns.end;s++){let l=formatCellAddress(a,s),d=(i=r.get(l))!=null?i:l,u=o.get(d);u?n.has(d)||(n.add(d),yield {row:u.range.startRow,column:u.range.startColumn}):yield {row:a,column:s};}}function US(t,e,n,r,o=false){if(e.width<28)return;let i=e.x+e.width-10,a=e.y+e.height/2;t.save(),t.strokeStyle=o?"#2563EB":"#64748B",t.lineWidth=1/n,t.lineCap="round",t.beginPath(),t.moveTo(i-4,a-3),t.lineTo(i+4,a-3),t.lineTo(i+1,a+1),t.lineTo(i+1,a+4),t.lineTo(i-1,a+3),t.lineTo(i-1,a+1),t.closePath(),t.stroke(),t.restore();}function Vp(t,e){let n=Math.max(t.startRow,e.startRow),r=Math.max(t.startColumn,e.startColumn),o=Math.min(t.endRow,e.endRow),i=Math.min(t.endColumn,e.endColumn);return n>o||r>i?null:{startRow:n,startColumn:r,endRow:o,endColumn:i}}function Yi(t){let e=t.getContext("2d");if(!e)throw new Error("SpreadsheetCanvasRenderer: 2D canvas context is unavailable");return e}function Zi(t,e){let n=Number.parseFloat(e.style.width)||e.width,r=Number.parseFloat(e.style.height)||e.height;t.clearRect(0,0,n,r);}function yo(t,e,n){t.save(),t.beginPath(),t.rect(e.x,e.y,e.width,e.height),t.clip(),n(),t.restore();}function Ji(t){return t.kind==="main"||t.kind==="frozenTop"||t.kind==="frozenLeft"||t.kind==="frozenTopLeft"}function yl(t,e){return {x:e.screenRect.x+t.x-e.originX,y:e.screenRect.y+t.y-e.originY,width:t.width,height:t.height}}function vl(t,e,n,r,o){t.fillStyle="#F3F4F6",t.fillRect(e.x,e.y,e.width,e.height),t.strokeStyle="#D1D5DB",t.lineWidth=1/r,So(t,e,r,o),n&&(t.font="12px Arial",t.fillStyle="#374151",t.textAlign="center",t.textBaseline="middle",t.fillText(n,e.x+e.width/2,e.y+e.height/2));}function KS(t,e,n,r,o){var i,a,s,l,d,u,f,p;!n.left&&!n.right&&!n.top&&!n.bottom||(t.save(),t.lineWidth=1/r,t.setLineDash([]),n.top&&(t.strokeStyle=(a=(i=n.top.color)==null?void 0:i.rgb)!=null?a:"#111827",vo(t,e.x,e.y,e.x+e.width,e.y,r,o)),n.right&&(t.strokeStyle=(l=(s=n.right.color)==null?void 0:s.rgb)!=null?l:"#111827",vo(t,e.x+e.width,e.y,e.x+e.width,e.y+e.height,r,o)),n.bottom&&(t.strokeStyle=(u=(d=n.bottom.color)==null?void 0:d.rgb)!=null?u:"#111827",vo(t,e.x,e.y+e.height,e.x+e.width,e.y+e.height,r,o)),n.left&&(t.strokeStyle=(p=(f=n.left.color)==null?void 0:f.rgb)!=null?p:"#111827",vo(t,e.x,e.y,e.x,e.y+e.height,r,o)),t.restore());}function Gp(t,e,n,r,o){return e.verticalAlign==="top"?t.y+n+o/2:e.verticalAlign==="bottom"?t.y+t.height-n-r+o/2:t.y+(t.height-r)/2+o/2}function _S(t,e,n){let r=[];for(let o of e.split(/\r?\n/)){if(o===""){r.push("");continue}let i="";for(let a of o){let s=i+a;i&&t.measureText(s).width>n?(r.push(i),i=a):i=s;}i&&r.push(i);}return r.length>0?r:[""]}function vo(t,e,n,r,o,i,a){t.beginPath(),t.moveTo(Cn(e,i),Cn(n,a)),t.lineTo(Cn(r,i),Cn(o,a)),t.stroke();}function jp(t,e,n,r,o,i,a){let s=t.measureText(e),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);t.save(),t.strokeStyle=o.fontColor,t.lineWidth=1/i,vo(t,d,r+u,d+l,r+u,i,a),t.restore();}function Sl(t,e){return {x:t.x+e,y:t.y+e,width:Math.max(0,t.width-e*2),height:Math.max(0,t.height-e*2)}}function So(t,e,n,r){let o=Cn(e.x,n),i=Cn(e.y,r),a=Cn(e.x+e.width,n),s=Cn(e.y+e.height,r);t.strokeRect(o,i,Math.max(0,a-o),Math.max(0,s-i));}function Cn(t,e){return (Math.round(t*e)+.5)/e}function it(t,e){return {kind:"cell",active:{row:t,column:e},range:{startRow:t,startColumn:e,endRow:t,endColumn:e}}}function ea(t,e){return {kind:"row",active:{row:t,column:1},range:{startRow:t,startColumn:1,endRow:t,endColumn:e.columnCount}}}function hT(t,e,n){let r=We({startRow:t,startColumn:1,endRow:e,endColumn:n.columnCount});return {kind:"row",active:{row:r.startRow,column:1},range:r}}function ta(t,e){return {kind:"column",active:{row:1,column:t},range:{startRow:1,startColumn:t,endRow:e.rowCount,endColumn:t}}}function mT(t,e,n){let r=We({startRow:1,startColumn:t,endRow:n.rowCount,endColumn:e});return {kind:"column",active:{row:1,column:r.startColumn},range:r}}function We(t){return {startRow:Math.min(t.startRow,t.endRow),startColumn:Math.min(t.startColumn,t.endColumn),endRow:Math.max(t.startRow,t.endRow),endColumn:Math.max(t.startColumn,t.endColumn)}}function cr(t,e,n,r){var o,i;return t.kind==="row"?{kind:"row",active:t.active,range:We({startRow:t.active.row,startColumn:1,endRow:e,endColumn:(o=r==null?void 0:r.columnCount)!=null?o:t.range.endColumn})}:t.kind==="column"?{kind:"column",active:t.active,range:We({startRow:1,startColumn:t.active.column,endRow:(i=r==null?void 0:r.rowCount)!=null?i:t.range.endRow,endColumn:n})}:{kind:"cell",active:t.active,range:We({startRow:t.active.row,startColumn:t.active.column,endRow:e,endColumn:n})}}function gT(t,e,n,r){return it(dr(t.active.row+e,1,r.rowCount),dr(t.active.column+n,1,r.columnCount))}function ct(t,e){var r;if(t.kind!=="cell")return t;let n=(r=ZS(t.active.row,t.active.column,e))!=null?r:t.active;return H(v({},t),{active:n,range:XS(t.range,e)})}function XS(t,e){let n=We(t),r=true;for(;r;){r=false;for(let o of e.mergeMasterByAddress.values()){if(!YS(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 bT(t,e,n,r,o){let i=dr(Kp(t.active.row,e,n),1,r.rowCount),a=dr(t.active.column,1,r.columnCount);return t.kind==="row"?ea(i,{columnCount:r.columnCount}):ct(it(i,a),o)}function wT(t,e,n,r,o){let i=dr(t.active.row,1,r.rowCount),a=dr(Kp(t.active.column,e,n),1,r.columnCount);return t.kind==="column"?ta(a,{rowCount:r.rowCount}):ct(it(i,a),o)}function Kp(t,e,n){let r=e+n-1;return t<e?t:t>r?t-n:e}function YS(t,e){return !(t.endRow<e.startRow||t.startRow>e.endRow||t.endColumn<e.startColumn||t.startColumn>e.endColumn)}function ZS(t,e,n){let r=n.mergeFollowerByAddress.get(formatCellAddress(t,e));if(!r)return null;let o=n.mergeMasterByAddress.get(r);return o?{row:o.range.startRow,column:o.range.startColumn}:null}function dr(t,e,n){return Math.max(e,Math.min(n,t))}var ur="application/x-coco-spreadsheet";function ko(t){return JSON.stringify(H(v({},t),{schema:1}))}function _p(t){var r;let e=t.getData(ur);if(e.trimStart().startsWith("{"))return e;let n=(r=new RegExp(`\\bdata-coco-spreadsheet-payload\\s*=\\s*(["'])(.*?)\\1`,"is").exec(t.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 Eo(t){var n;let e=_p(t);if(e){if(e.length>33554432)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{let r=JSON.parse(e);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 t.getData(ur)||((n=/\bdata-coco-spreadsheet="([^"]+)"/i.exec(t.getData("text/html")))==null?void 0:n[1])||null}function Il(t){let e=_p(t);if(!e)return null;if(e.length>33554432)throw new Error("\u590D\u5236\u7684\u5355\u5143\u683C\u6570\u636E\u8FC7\u5927\u3002");try{return e0(JSON.parse(e))}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(t){if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Expected object");if(Object.keys(t).some(e=>e==="__proto__"||e==="constructor"||e==="prototype"))throw new Error("Invalid property");return t}function ln(t,e=32768){if(typeof t!="string"||t.length>e)throw new Error("Invalid string");return t}function Jt(t,e,n=1){if(typeof t!="number"||!Number.isInteger(t)||t<n||t>e)throw new Error("Invalid integer");return t}function JS(t){if(t===null||typeof t=="boolean"||typeof t=="string"||typeof t=="number"&&Number.isFinite(t))return t;throw new Error("Invalid cell value")}function kl(t,e,n,r){if(!Array.isArray(t)||t.length!==e)throw new Error("Invalid rows");return t.map(o=>{if(!Array.isArray(o)||o.length!==n)throw new Error("Invalid columns");return o.map(r)})}function El(t){let e=ln(Ut(t).rgb,7);if(!/^#[0-9a-f]{6}$/i.test(e))throw new Error("Invalid color");return {rgb:e}}function Cl(t,e,n,r){let o=Ut(t),i={};for(let a of e)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 QS(t){let e=Ut(t),n=Cl(e.font,["name","scheme"],["size","family","charset"],["bold","italic","underline"]),r=Ut(e.font);r.color!==void 0&&(n.color=El(r.color));let o=Cl(e.fill,["patternType"],[],[]),i=Ut(e.fill);for(let l of ["foregroundColor","backgroundColor"])i[l]!==void 0&&(o[l]=El(i[l]));let a=Ut(e.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:El(d.color)}:{});}return v(v(v({font:n,fill:o,border:s},e.alignment!==void 0?{alignment:Cl(e.alignment,["horizontal","vertical"],["textRotation","indent"],["wrapText","shrinkToFit"])}:{}),e.numberFormatId!==void 0?{numberFormatId:Jt(e.numberFormatId,65535,0)}:{}),e.numberFormatCode!==void 0?{numberFormatCode:ln(e.numberFormatCode,4096)}:{})}function e0(t){let e=Ut(t);if(e.schema!==1)throw new Error("Unsupported clipboard schema");let n=Ut(e.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=kl(e.values,o,i,JS),s=kl(e.formulas,o,i,p=>p===null?null:ln(p)),l=kl(e.styleIds,o,i,p=>p==null?void 0:Jt(p,1048576,0));if(!Array.isArray(e.merges)||e.merges.length>o*i)throw new Error("Invalid merges");let d=new Set,u=e.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 x=g*i+h;if(d.has(x))throw new Error("Overlapping merges");d.add(x);}return w}),f={};for(let[p,b]of Object.entries(Ut(e.styles))){if(p!=="default"&&!/^(0|[1-9]\d{0,6})$/.test(p))throw new Error("Invalid style key");f[p]=QS(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 H(v({schema:1,id:ln(e.id,256),sourceSheet:ln(e.sourceSheet,128)},e.sourceWorkbookId!==void 0?{sourceWorkbookId:ln(e.sourceWorkbookId,512)}:{}),{sourceRange:r,text:ln(e.text,33554432),values:a,formulas:s,styleIds:l,styles:f,merges:u})}function na(t,e,n={}){var s,l,d;let r=o0(t,e),o=d0(t,e),i={};for(let u of o)for(let f of u){let p=f===void 0?"default":String(f);(i[p])!=null||(i[p]=captureExcelCellStyle(t.styles,f));}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:t.source.name,sourceRange:v({},e),text:r,values:s0(t,e),formulas:Array.from({length:e.endRow-e.startRow+1},(u,f)=>Array.from({length:e.endColumn-e.startColumn+1},(p,b)=>{var h,x;let w=e.startRow+f,g=e.startColumn+b;return t.mergeFollowerByAddress.has(formatCellAddress(w,g))?null:(x=(h=qe(t,w,g))==null?void 0:h.formula)!=null?x:null})),styleIds:o,styles:i,merges:l0(t,e)})}function o0(t,e){let n=[];for(let r=e.startRow;r<=e.endRow;r++){let o=[];for(let i=e.startColumn;i<=e.endColumn;i++)o.push(i0(a0(t,r,i)));n.push(o.join(" "));}return n.join(`
|
|
1609
1624
|
`)}function Xp(t){if(t==="")return [[null]];let e=[],n=[],r="",o=false,i=false;for(let a=0;a<t.length;a++){let s=t[a];i=false,s==='"'?o&&t[a+1]==='"'?(r+='"',a++):o||r===""?o=!o:r+=s:!o&&(s===" "||s===`
|
|
1610
1625
|
`||s==="\r")?(n.push(qp(r)),r="",s!==" "&&(e.push(n),n=[],i=true,s==="\r"&&t[a+1]===`
|
|
1611
|
-
`&&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(qp(r)),e.push(n)),e}function Tl(t){let e=r=>r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),n=(r,o)=>{var s,l,d,u,p,
|
|
1612
|
-
`),e)}function g0(t){return t===null?"":String(t)}function Ll(t,e){let n=t.trim();return e?n:n.toLocaleLowerCase()}function nh(t,e){return t.row===e.row?t.column-e.column:t.row-e.row}function rh(t,e,n,r){if(!e)return t;let o=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return t.replace(new RegExp(o,r?"g":"gi"),n)}function Dl(t,e,n){var o,i;let r=new Set;for(let a=e.startRow+1;a<=e.endRow;a+=1)r.add((i=(o=qe(t,a,n))==null?void 0:o.displayText)!=null?i:"");return [...r].sort((a,s)=>a.localeCompare(s,void 0,{numeric:true}))}function KT(t,e,n){var o,i,a;let r=new Set;for(let s=e.startRow+1;s<=e.endRow;s+=1)(o=t.rowMetaByIndex.get(s))!=null&&o.hidden||r.add((a=(i=qe(t,s,n))==null?void 0:i.displayText)!=null?a:"");return [...r].sort((s,l)=>s.localeCompare(l,void 0,{numeric:true}))}function ah(t,e,n,r){var a,s;let o=new Set(typeof r=="string"?[r]:r),i=[];for(let l=e.startRow+1;l<=e.endRow;l+=1)o.has((s=(a=qe(t,l,n))==null?void 0:a.displayText)!=null?s:"")||i.push(l);return i}function sh(t,e,n){let r=n.map(i=>[i.column,new Set(i.values)]),o=[];for(let i=e.startRow+1;i<=e.endRow;i+=1)r.every(([s,l])=>{var d,u;return l.has((u=(d=qe(t,i,s))==null?void 0:d.displayText)!=null?u:"")})||o.push(i);return o}function lh(t,e,n,r){let o=Array.from({length:e.endRow-e.startRow},(i,a)=>e.startRow+a+1);return o.sort((i,a)=>{var u,p,f,b;let s=(p=(u=qe(t,i,n))==null?void 0:u.displayText)!=null?p:"",l=(b=(f=qe(t,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 Wl(t,e){let n=ch(e.source,e.rowOffset,e.columnOffset),r=Co(e.sourceSheet,e.targetSheet)?v0(n,e.source):[n];return rewriteFormulaReferences(t,o=>{var w;let i=splitSheetQualifiedAddress(o),a=(w=i.sheetName)!=null?w:e.formulaSheet,s=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(Co(a,e.targetSheet)){for(let g of r)if(l=uh(l,g),!l)return {ok:false,address:"#REF!"}}let u=Co(a,e.sourceSheet)&&fh(e.source,l),p=u?e.targetSheet:a;if(u?l=ch(l,e.rowOffset,e.columnOffset):Co(a,e.sourceSheet)&&(l=uh(l,e.source)),!u&&Co(e.formulaSheet,e.resultSheet)&&l.startRow===d.startRow&&l.endRow===d.endRow&&l.startColumn===d.startColumn&&l.endColumn===d.endColumn)return {ok:true,address:o};let f=S0(i.address,l);return {ok:true,address:`${i.sheetName||p!==e.resultSheet?`'${p.replace(/'/g,"''")}'!`:""}${f}`}})}function Co(t,e){return t.toLowerCase()===e.toLowerCase()}function fh(t,e){return t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startColumn<=e.startColumn&&t.endColumn>=e.endColumn}function ch(t,e,n){return {startRow:t.startRow+e,endRow:t.endRow+e,startColumn:t.startColumn+n,endColumn:t.endColumn+n}}function v0(t,e){let n=Math.max(t.startRow,e.startRow),r=Math.min(t.endRow,e.endRow),o=Math.max(t.startColumn,e.startColumn),i=Math.min(t.endColumn,e.endColumn);if(n>r||o>i)return [t];let a=[];return t.startRow<n&&a.push(F(v({},t),{endRow:n-1})),r<t.endRow&&a.push(F(v({},t),{startRow:r+1})),t.startColumn<o&&a.push({startRow:n,endRow:r,startColumn:t.startColumn,endColumn:o-1}),i<t.endColumn&&a.push({startRow:n,endRow:r,startColumn:i+1,endColumn:t.endColumn}),a}function uh(t,e){if(fh(e,t))return null;let n=v({},t);return e.startColumn<=t.startColumn&&e.endColumn>=t.endColumn&&(e.startRow<=t.startRow&&e.endRow>=t.startRow&&(n.startRow=e.endRow+1),e.endRow>=t.endRow&&e.startRow<=t.endRow&&(n.endRow=e.startRow-1)),e.startRow<=t.startRow&&e.endRow>=t.endRow&&(e.startColumn<=t.startColumn&&e.endColumn>=t.startColumn&&(n.startColumn=e.endColumn+1),e.endColumn>=t.endColumn&&e.startColumn<=t.endColumn&&(n.endColumn=e.startColumn-1)),n}function S0(t,e){var d;let n=t.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=columnNameToIndex(r[2])>columnNameToIndex(o[2]),s=(u,p,f)=>`${u[1]}${columnIndexToName(f)}${u[3]}${p}`,l=s(r,i?e.endRow:e.startRow,a?e.endColumn:e.startColumn);return n.length===1?l:`${l}:${s(o,i?e.startRow:e.endRow,a?e.startColumn:e.endColumn)}`}var ra=class t{constructor(e,n={}){W(this,"state",e);W(this,"activeTransaction",null);W(this,"activeTransactionSource",null);W(this,"transactionNeedsRefresh",false);W(this,"readOnlyValue");this.readOnlyValue=n.readOnly===true;}static async fromZip(e,n={}){let a=n,{readOnly:r}=a,o=Ln(a,["readOnly"]),i=await ExcelWorkbook.fromZip(e,o);return t.fromWorkbook(i,{readOnly:r})}static async fromWorkbook(e,n={}){var s;let r=await e.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 SpreadsheetFormulaEngine(o,{sheets:r.sheets}),a=i.calculate();return new t({workbook:e,model:r,activeSheetName:o.name,formulaResults:a,formulaEngine:i,activeSheet:go(o,r.styles,{formulaResults:a,date1904:r.date1904})},n)}isReadOnly(){return this.readOnlyValue}setReadOnly(e){if(this.activeTransaction)throw new Error("SpreadsheetEditorRuntime: cannot change read-only state during a transaction");this.readOnlyValue=e;}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 e=await this.state.workbook.history().undo();return e?(await this.refresh(),e):null}async redo(){this.assertWritable();let e=await this.state.workbook.history().redo();return e?(await this.refresh(),e):null}async runUserTransaction(e,n){return this.assertWritable(),this.runScopedTransaction("user",r=>this.state.workbook.history().runGroup(F(v({},e),{source:"user"}),r),n)}async runAgentTransaction(e,n){return this.assertWritable(),this.runScopedTransaction("agent",r=>this.state.workbook.history().runAgentGroup(e,r),()=>n(this))}async previewAgentTransaction(e,n){var a;let r=mh(this.state.model),o=await ExcelWorkbook.fromModel(r,{mode:"inline"}),i=await t.fromWorkbook(o);await i.setActiveSheet(this.state.activeSheetName);try{let s=await i.runAgentTransaction(e,n),l=mh(i.model()),d=diffExcelWorkbookModels(r,l);return {result:s,summary:(a=s==null?void 0:s.summary)!=null?a:null,diff:d,diffSummary:L0(d),beforeModel:r,afterModel:l,activeSheetName:i.activeSheetName()}}finally{await i.dispose();}}async setActiveSheet(e){let n=this.state.model.sheets.find(i=>i.name===e);if(!n)throw new Error(`SpreadsheetEditorRuntime: sheet not found: ${e}`);if(!this.readOnlyValue){for(let i of await this.state.workbook.worksheets.items()){let a=await i.name(),s=await i.sheetViews(),l=a===e;await i.setSheetViews(s.length>0?s.map(d=>F(v({},d),{tabSelected:l})):[{workbookViewId:0,tabSelected:l,selections:[]}]);}for(let i of this.state.model.sheets){let a=i.name===e;i.sheetViews=i.sheetViews.length>0?i.sheetViews.map(s=>F(v({},s),{tabSelected:a})):[{workbookViewId:0,tabSelected:a,selections:[]}];}}let r=new 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=go(n,this.state.model.styles,{formulaResults:o,date1904:this.state.model.date1904});}async addSheet(e){await this.runWorksheetStructureMutation(n=>n.addSheet(e),()=>this.state.workbook.worksheets.add(e).then(()=>{})),await this.setActiveSheet(e);}async renameSheet(e,n){let r=e===this.state.activeSheetName;await this.runWorksheetStructureMutation(o=>o.renameSheet(e,n),()=>this.state.workbook.worksheets.getItem(e).rename(n)),r&&await this.setActiveSheet(n);}async copySheet(e,n){await this.runWorksheetStructureMutation(r=>r.copySheet(e,n),()=>this.state.workbook.worksheets.copy(e,n).then(()=>{})),await this.setActiveSheet(n);}async deleteSheet(e){var i;let n=this.state.model.sheets.findIndex(a=>a.name===e);if(n===-1)throw new Error(`SpreadsheetEditorRuntime: sheet not found: ${e}`);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=e===this.state.activeSheetName;await this.runWorksheetStructureMutation(a=>a.deleteSheet(e),()=>this.state.workbook.worksheets.deleteItem(e)),o&&r&&await this.setActiveSheet(r.name);}async moveSheet(e,n){await this.runWorksheetStructureMutation(r=>r.moveSheet(e,n),()=>this.state.workbook.worksheets.move(e,n));}async refresh(){var i;let e=await this.state.workbook.toModel(),n=(i=e.sheets.find(a=>a.name===this.state.activeSheetName))!=null?i:e.sheets[0];if(!n)throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");let r=new SpreadsheetFormulaEngine(n,{sheets:e.sheets}),o=r.calculate();this.state=F(v({},this.state),{model:e,activeSheetName:n.name,formulaResults:o,formulaEngine:r,activeSheet:go(n,e.styles,{formulaResults:o,date1904:e.date1904})});}async setCellValue(e,n,r={}){let o=this.editableCellAddress(e);await this.runUserMutation(this.cellEditHistoryGroup(`Set ${o}`,o,r),async i=>{await i.setCellValue(this.state.activeSheetName,o,n);});}async setCellFormula(e,n,r={}){let o=this.editableCellAddress(e);await this.runUserMutation(this.cellEditHistoryGroup(`Set ${o} formula`,o,r),async i=>{await i.setCellFormula(this.state.activeSheetName,o,n);});}async setCellRichText(e,n){let r=this.editableCellAddress(e);await this.runUserMutation({label:`Set ${r}`},async o=>{await o.setCellRichText(this.state.activeSheetName,r,n);});}async replaceAll(e,n,r=false){let o=oh(this.state.activeSheet,{query:e,replacement:n,matchCase:r});return o.length===0?0:(await this.runUserMutation({label:`Replace ${e}`},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(e,n,r,o){let i={startRow:e,startColumn:r,endRow:n,endColumn:r},a=o===null?[]:ah(this.state.activeSheet,F(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(`
|
|
1626
|
+
`&&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(qp(r)),e.push(n)),e}function Tl(t){let e=r=>r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),n=(r,o)=>{var s,l,d,u,f,p,b;let i=(d=t.styles)==null?void 0:d[String((l=(s=t.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="${e(t.id)}" data-coco-spreadsheet-payload="${encodeURIComponent(ko(t))}">${t.values.map((r,o)=>`<tr>${r.map((i,a)=>`<td style="${e(n(o,a))}">${e(String(i!=null?i:""))}</td>`).join("")}</tr>`).join("")}</table>`}function Pl(t,e,n,r=false){return t.formulas.map(o=>o.map(i=>i===null||r?i:shiftFormulaReferences(i,e-t.sourceRange.startRow,n-t.sourceRange.startColumn)))}function IT(t,e,n){let r=Math.max(1,n.length),o=Math.max(1,n.reduce((i,a)=>Math.max(i,a.length),0));return formatRangeAddress(t,e,r,o)}function i0(t){return /[\t\r\n"]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function a0(t,e,n){var o,i;let r=formatCellAddress(e,n);return t.mergeFollowerByAddress.has(r)?"":(i=(o=qe(t,e,n))==null?void 0:o.displayText)!=null?i:""}function s0(t,e){var r,o;let n=[];for(let i=e.startRow;i<=e.endRow;i++){let a=[];for(let s=e.startColumn;s<=e.endColumn;s++){let l=formatCellAddress(i,s);a.push(t.mergeFollowerByAddress.has(l)?null:(o=(r=qe(t,i,s))==null?void 0:r.value)!=null?o:null);}n.push(a);}return n}function l0(t,e){let n=[];for(let r of t.mergeMasterByAddress.values())c0(e,r.range)&&n.push({startRowOffset:r.range.startRow-e.startRow,startColumnOffset:r.range.startColumn-e.startColumn,rowCount:r.range.endRow-r.range.startRow+1,columnCount:r.range.endColumn-r.range.startColumn+1});return n}function d0(t,e){var r;let n=[];for(let o=e.startRow;o<=e.endRow;o++){let i=[];for(let a=e.startColumn;a<=e.endColumn;a++)i.push((r=qe(t,o,a))==null?void 0:r.styleId);n.push(i);}return n}function c0(t,e){return e.startRow>=t.startRow&&e.endRow<=t.endRow&&e.startColumn>=t.startColumn&&e.endColumn<=t.endColumn}function qp(t){if(t==="")return null;let e=Number(t);return Number.isFinite(e)&&t.trim()!==""?e:t.toUpperCase()==="TRUE"?true:t.toUpperCase()==="FALSE"?false:t}function Zp(t,e,n){var s;let r=Ml(e),o=Ml(n),i=f0(r,o);if(Rl(r,t)||Rl(o,t))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(h0(l,d,r))continue;let u=i==="down"?r.startRow+Yp(l-r.startRow,Jp(r)):l,f=i==="right"?r.startColumn+Yp(d-r.startColumn,Qp(r)):d,p=qe(t,u,f),b=p0(t,r,i,l,d),w=p!=null&&p.formula?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 Al(t,e){return !Rl(Ml(e),t)}function f0(t,e){if(e.startRow===t.startRow&&e.startColumn===t.startColumn&&e.endColumn===t.endColumn&&e.endRow>t.endRow)return "down";if(e.startRow===t.startRow&&e.endRow===t.endRow&&e.startColumn===t.startColumn&&e.endColumn>t.endColumn)return "right";throw new Error("Auto fill target must extend the source selection down or right")}function p0(t,e,n,r,o){let i=n==="down"?Jp(e):Qp(e);if(i<2)return;let a=Array.from({length:i},(d,u)=>{let f=n==="down"?e.startRow+u:r,p=n==="right"?e.startColumn+u:o,b=qe(t,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-e.startRow:o-e.startColumn;return a[0]+s*l}function Rl(t,e){for(let n of e.mergeMasterByAddress.values())if(m0(t,n.range))return true;return false}function Ml(t){return {startRow:Math.min(t.startRow,t.endRow),startColumn:Math.min(t.startColumn,t.endColumn),endRow:Math.max(t.startRow,t.endRow),endColumn:Math.max(t.startColumn,t.endColumn)}}function Jp(t){return t.endRow-t.startRow+1}function Qp(t){return t.endColumn-t.startColumn+1}function h0(t,e,n){return t>=n.startRow&&t<=n.endRow&&e>=n.startColumn&&e<=n.endColumn}function m0(t,e){return !(t.endRow<e.startRow||t.startRow>e.endRow||t.endColumn<e.startColumn||t.startColumn>e.endColumn)}function Yp(t,e){return (t%e+e)%e}async function WT(t,e,n,r){await t.worksheets.getItem(e).getCell(n).setValue(r);}async function BT(t,e,n,r){await t.worksheets.getItem(e).getCell(n).setFormula(r);}async function FT(t,e,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 t.worksheets.getItem(e).getRange(formatRangeAddress(n,r,i,a)).setValues(s);}async function HT(t,e,n,r,o,i){await t.worksheets.getItem(e).getRange(formatRangeAddress(n,r,o,i)).clear();}async function OT(t,e,n,r){await t.worksheets.getItem(e).getRange(formatCellAddress(n,1)).setRowHeight(r);}async function $T(t,e,n,r){await t.worksheets.getItem(e).getRange(formatCellAddress(1,n)).setColumnWidth(Ki(r));}function oh(t,e){let n=e.query.trim();if(!n)return [];let r=[],o=[...t.cellsByAddress.values()].sort((i,a)=>i.row-a.row||i.column-a.column);for(let i of o)if(ih(i,e.matchCase===true).includes(Ll(n,e.matchCase===true)))if(i.formula){let a=n.startsWith("=")?n.slice(1):n;r.push({address:i.address,formula:rh(i.formula,a,e.replacement,e.matchCase===true)});}else {let a=i.value===null?"":String(i.value);r.push({address:i.address,value:rh(a,n,e.replacement,e.matchCase===true)});}return r}function VT(t,e){let n=Ll(e.query,e.matchCase===true);if(!n)return [];let r=[],o=[...t.cellsByAddress.values()].sort((i,a)=>i.row-a.row||i.column-a.column);for(let i of o)ih(i,e.matchCase===true).includes(n)&&r.push({row:i.row,column:i.column,address:i.address,text:i.displayText});return r}function GT(t,e,n="forward"){var r,o,i,a;return t.length===0?null:n==="backward"?(o=(r=[...t].reverse().find(s=>nh(s,e)<0))!=null?r:t[t.length-1])!=null?o:null:(a=(i=t.find(s=>nh(s,e)>0))!=null?i:t[0])!=null?a:null}function jT(t){return {startRow:t.row,startColumn:t.column,endRow:t.row,endColumn:t.column}}function ih(t,e){let n=[t.displayText,g0(t.value),t.formula?`=${t.formula}`:""].filter(Boolean);return Ll(n.join(`
|
|
1627
|
+
`),e)}function g0(t){return t===null?"":String(t)}function Ll(t,e){let n=t.trim();return e?n:n.toLocaleLowerCase()}function nh(t,e){return t.row===e.row?t.column-e.column:t.row-e.row}function rh(t,e,n,r){if(!e)return t;let o=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return t.replace(new RegExp(o,r?"g":"gi"),n)}function Dl(t,e,n){var o,i;let r=new Set;for(let a=e.startRow+1;a<=e.endRow;a+=1)r.add((i=(o=qe(t,a,n))==null?void 0:o.displayText)!=null?i:"");return [...r].sort((a,s)=>a.localeCompare(s,void 0,{numeric:true}))}function _T(t,e,n){var o,i,a;let r=new Set;for(let s=e.startRow+1;s<=e.endRow;s+=1)(o=t.rowMetaByIndex.get(s))!=null&&o.hidden||r.add((a=(i=qe(t,s,n))==null?void 0:i.displayText)!=null?a:"");return [...r].sort((s,l)=>s.localeCompare(l,void 0,{numeric:true}))}function ah(t,e,n,r){var a,s;let o=new Set(typeof r=="string"?[r]:r),i=[];for(let l=e.startRow+1;l<=e.endRow;l+=1)o.has((s=(a=qe(t,l,n))==null?void 0:a.displayText)!=null?s:"")||i.push(l);return i}function sh(t,e,n){let r=n.map(i=>[i.column,new Set(i.values)]),o=[];for(let i=e.startRow+1;i<=e.endRow;i+=1)r.every(([s,l])=>{var d,u;return l.has((u=(d=qe(t,i,s))==null?void 0:d.displayText)!=null?u:"")})||o.push(i);return o}function lh(t,e,n,r){let o=Array.from({length:e.endRow-e.startRow},(i,a)=>e.startRow+a+1);return o.sort((i,a)=>{var u,f,p,b;let s=(f=(u=qe(t,i,n))==null?void 0:u.displayText)!=null?f:"",l=(b=(p=qe(t,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 Wl(t,e){let n=ch(e.source,e.rowOffset,e.columnOffset),r=Co(e.sourceSheet,e.targetSheet)?v0(n,e.source):[n];return rewriteFormulaReferences(t,o=>{var w;let i=splitSheetQualifiedAddress(o),a=(w=i.sheetName)!=null?w:e.formulaSheet,s=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(Co(a,e.targetSheet)){for(let g of r)if(l=uh(l,g),!l)return {ok:false,address:"#REF!"}}let u=Co(a,e.sourceSheet)&&fh(e.source,l),f=u?e.targetSheet:a;if(u?l=ch(l,e.rowOffset,e.columnOffset):Co(a,e.sourceSheet)&&(l=uh(l,e.source)),!u&&Co(e.formulaSheet,e.resultSheet)&&l.startRow===d.startRow&&l.endRow===d.endRow&&l.startColumn===d.startColumn&&l.endColumn===d.endColumn)return {ok:true,address:o};let p=S0(i.address,l);return {ok:true,address:`${i.sheetName||f!==e.resultSheet?`'${f.replace(/'/g,"''")}'!`:""}${p}`}})}function Co(t,e){return t.toLowerCase()===e.toLowerCase()}function fh(t,e){return t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startColumn<=e.startColumn&&t.endColumn>=e.endColumn}function ch(t,e,n){return {startRow:t.startRow+e,endRow:t.endRow+e,startColumn:t.startColumn+n,endColumn:t.endColumn+n}}function v0(t,e){let n=Math.max(t.startRow,e.startRow),r=Math.min(t.endRow,e.endRow),o=Math.max(t.startColumn,e.startColumn),i=Math.min(t.endColumn,e.endColumn);if(n>r||o>i)return [t];let a=[];return t.startRow<n&&a.push(H(v({},t),{endRow:n-1})),r<t.endRow&&a.push(H(v({},t),{startRow:r+1})),t.startColumn<o&&a.push({startRow:n,endRow:r,startColumn:t.startColumn,endColumn:o-1}),i<t.endColumn&&a.push({startRow:n,endRow:r,startColumn:i+1,endColumn:t.endColumn}),a}function uh(t,e){if(fh(e,t))return null;let n=v({},t);return e.startColumn<=t.startColumn&&e.endColumn>=t.endColumn&&(e.startRow<=t.startRow&&e.endRow>=t.startRow&&(n.startRow=e.endRow+1),e.endRow>=t.endRow&&e.startRow<=t.endRow&&(n.endRow=e.startRow-1)),e.startRow<=t.startRow&&e.endRow>=t.endRow&&(e.startColumn<=t.startColumn&&e.endColumn>=t.startColumn&&(n.startColumn=e.endColumn+1),e.endColumn>=t.endColumn&&e.startColumn<=t.endColumn&&(n.endColumn=e.startColumn-1)),n}function S0(t,e){var d;let n=t.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=columnNameToIndex(r[2])>columnNameToIndex(o[2]),s=(u,f,p)=>`${u[1]}${columnIndexToName(p)}${u[3]}${f}`,l=s(r,i?e.endRow:e.startRow,a?e.endColumn:e.startColumn);return n.length===1?l:`${l}:${s(o,i?e.startRow:e.endRow,a?e.startColumn:e.endColumn)}`}var ra=class t{constructor(e,n={}){W(this,"state",e);W(this,"activeTransaction",null);W(this,"activeTransactionSource",null);W(this,"transactionNeedsRefresh",false);W(this,"readOnlyValue");this.readOnlyValue=n.readOnly===true;}static async fromZip(e,n={}){let a=n,{readOnly:r}=a,o=Wn(a,["readOnly"]),i=await ExcelWorkbook.fromZip(e,o);return t.fromWorkbook(i,{readOnly:r})}static async fromWorkbook(e,n={}){var s;let r=await e.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 SpreadsheetFormulaEngine(o,{sheets:r.sheets}),a=i.calculate();return new t({workbook:e,model:r,activeSheetName:o.name,formulaResults:a,formulaEngine:i,activeSheet:go(o,r.styles,{formulaResults:a,date1904:r.date1904})},n)}isReadOnly(){return this.readOnlyValue}setReadOnly(e){if(this.activeTransaction)throw new Error("SpreadsheetEditorRuntime: cannot change read-only state during a transaction");this.readOnlyValue=e;}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 e=await this.state.workbook.history().undo();return e?(await this.refresh(),e):null}async redo(){this.assertWritable();let e=await this.state.workbook.history().redo();return e?(await this.refresh(),e):null}async runUserTransaction(e,n){return this.assertWritable(),this.runScopedTransaction("user",r=>this.state.workbook.history().runGroup(H(v({},e),{source:"user"}),r),n)}async runAgentTransaction(e,n){return this.assertWritable(),this.runScopedTransaction("agent",r=>this.state.workbook.history().runAgentGroup(e,r),()=>n(this))}async previewAgentTransaction(e,n){var a;let r=mh(this.state.model),o=await ExcelWorkbook.fromModel(r,{mode:"inline"}),i=await t.fromWorkbook(o);await i.setActiveSheet(this.state.activeSheetName);try{let s=await i.runAgentTransaction(e,n),l=mh(i.model()),d=diffExcelWorkbookModels(r,l);return {result:s,summary:(a=s==null?void 0:s.summary)!=null?a:null,diff:d,diffSummary:L0(d),beforeModel:r,afterModel:l,activeSheetName:i.activeSheetName()}}finally{await i.dispose();}}async setActiveSheet(e){let n=this.state.model.sheets.find(i=>i.name===e);if(!n)throw new Error(`SpreadsheetEditorRuntime: sheet not found: ${e}`);if(!this.readOnlyValue){for(let i of await this.state.workbook.worksheets.items()){let a=await i.name(),s=await i.sheetViews(),l=a===e;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===e;i.sheetViews=i.sheetViews.length>0?i.sheetViews.map(s=>H(v({},s),{tabSelected:a})):[{workbookViewId:0,tabSelected:a,selections:[]}];}}let r=new 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=go(n,this.state.model.styles,{formulaResults:o,date1904:this.state.model.date1904});}async addSheet(e){await this.runWorksheetStructureMutation(n=>n.addSheet(e),()=>this.state.workbook.worksheets.add(e).then(()=>{})),await this.setActiveSheet(e);}async renameSheet(e,n){let r=e===this.state.activeSheetName;await this.runWorksheetStructureMutation(o=>o.renameSheet(e,n),()=>this.state.workbook.worksheets.getItem(e).rename(n)),r&&await this.setActiveSheet(n);}async copySheet(e,n){await this.runWorksheetStructureMutation(r=>r.copySheet(e,n),()=>this.state.workbook.worksheets.copy(e,n).then(()=>{})),await this.setActiveSheet(n);}async deleteSheet(e){var i;let n=this.state.model.sheets.findIndex(a=>a.name===e);if(n===-1)throw new Error(`SpreadsheetEditorRuntime: sheet not found: ${e}`);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=e===this.state.activeSheetName;await this.runWorksheetStructureMutation(a=>a.deleteSheet(e),()=>this.state.workbook.worksheets.deleteItem(e)),o&&r&&await this.setActiveSheet(r.name);}async moveSheet(e,n){await this.runWorksheetStructureMutation(r=>r.moveSheet(e,n),()=>this.state.workbook.worksheets.move(e,n));}async refresh(){var i;let e=await this.state.workbook.toModel(),n=(i=e.sheets.find(a=>a.name===this.state.activeSheetName))!=null?i:e.sheets[0];if(!n)throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");let r=new SpreadsheetFormulaEngine(n,{sheets:e.sheets}),o=r.calculate();this.state=H(v({},this.state),{model:e,activeSheetName:n.name,formulaResults:o,formulaEngine:r,activeSheet:go(n,e.styles,{formulaResults:o,date1904:e.date1904})});}async setCellValue(e,n,r={}){let o=this.editableCellAddress(e);await this.runUserMutation(this.cellEditHistoryGroup(`Set ${o}`,o,r),async i=>{await i.setCellValue(this.state.activeSheetName,o,n);});}async setCellFormula(e,n,r={}){let o=this.editableCellAddress(e);await this.runUserMutation(this.cellEditHistoryGroup(`Set ${o} formula`,o,r),async i=>{await i.setCellFormula(this.state.activeSheetName,o,n);});}async setCellRichText(e,n){let r=this.editableCellAddress(e);await this.runUserMutation({label:`Set ${r}`},async o=>{await o.setCellRichText(this.state.activeSheetName,r,n);});}async replaceAll(e,n,r=false){let o=oh(this.state.activeSheet,{query:e,replacement:n,matchCase:r});return o.length===0?0:(await this.runUserMutation({label:`Replace ${e}`},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(e,n,r,o){let i={startRow:e,startColumn:r,endRow:n,endColumn:r},a=o===null?[]:ah(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(`
|
|
1613
1628
|
const sheet = workbook.worksheets.getItem(args.sheetName);
|
|
1614
1629
|
const hidden = new Set(args.hiddenRows);
|
|
1615
1630
|
for (let index = args.startRow + 1; index <= args.endRow; index += 1) {
|
|
@@ -1665,21 +1680,21 @@ coco-word-native-table.coco-word-revision-delete {
|
|
|
1665
1680
|
}
|
|
1666
1681
|
sheet.model.cells.sort((left, right) => left.row - right.row || left.column - right.column);
|
|
1667
1682
|
sheet.model.rows.sort((left, right) => left.index - right.index);
|
|
1668
|
-
`,{sheetName:this.state.activeSheetName,rowMap:[...s.entries()],formulas:l});});});}async setRangeValues(e,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,formatRangeAddress(e,n,o,i),a);});}async autoFillRange(e,n){let r=Zp(this.state.activeSheet,e,n);r.cells.length!==0&&await this.runUserMutation({label:"Auto fill"},async o=>{for(let i of r.cells){let a=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(e,n,r,o=[],i=[]){await this.pasteRange(e,n,r,{mode:"all",merges:o,styleIds:i});}async pasteRange(e,n,r,o={}){var w,g;let i=(w=o.mode)!=null?w:"all",a=r.length,s=r.reduce((h,x)=>Math.max(h,x.length),0);if(a===0||s===0)return;let l=r.map(h=>{let x=h.slice();for(;x.length<s;)x.push(null);return x}),d=Math.max(1,a),u=Math.max(1,s),
|
|
1683
|
+
`,{sheetName:this.state.activeSheetName,rowMap:[...s.entries()],formulas:l});});});}async setRangeValues(e,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,formatRangeAddress(e,n,o,i),a);});}async autoFillRange(e,n){let r=Zp(this.state.activeSheet,e,n);r.cells.length!==0&&await this.runUserMutation({label:"Auto fill"},async o=>{for(let i of r.cells){let a=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(e,n,r,o=[],i=[]){await this.pasteRange(e,n,r,{mode:"all",merges:o,styleIds:i});}async pasteRange(e,n,r,o={}){var w,g;let i=(w=o.mode)!=null?w:"all",a=r.length,s=r.reduce((h,x)=>Math.max(h,x.length),0);if(a===0||s===0)return;let l=r.map(h=>{let x=h.slice();for(;x.length<s;)x.push(null);return x}),d=Math.max(1,a),u=Math.max(1,s),f={startRow:e,startColumn:n,endRow:e+d-1,endColumn:n+u-1},p=[...this.state.activeSheet.mergeMasterByAddress.values()].filter(h=>Fl(f,h.range)).map(h=>h.address);for(let h of p){let x=parseRangeAddress(h);if(x.startRow<e||x.startColumn<n||x.startRow+x.rowCount>e+d||x.startColumn+x.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(x=>typeof x=="string"&&x.startsWith("=")?x.slice(1):null));if(i==="all"&&b.some(h=>h.some(x=>x!==null&&x.trim()==="")))throw new Error("\u7C98\u8D34\u6570\u636E\u5305\u542B\u7A7A\u516C\u5F0F\u3002");await this.runUserMutation({label:A0(i)},async h=>{var x,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,formatRangeAddress(e,n,d,u),l),i==="all")for(let k=0;k<b.length;k++)for(let I=0;I<b[k].length;I++){let D=b[k][I];D!=null&&await h.setCellFormula(this.state.activeSheetName,formatCellAddress(e+k,n+I),D);}}i!=="values"&&await R0(h,this.state.activeSheetName,e,n,u,(x=o.styleIds)!=null?x:[]),i==="all"&&await M0(h,this.state.activeSheetName,e,n,(S=o.merges)!=null?S:[]);});}async pasteClipboard(e,n,r={}){var A,O,ee,le,oe,ie,ae;let o=e.values.length,i=e.values.reduce((_,Y)=>Math.max(_,Y.length),0);if(!o||!i)return n;if(this.assertWritable(),!r.valuesOnly&&e.formulas.some(_=>_.some(Y=>Y!==null&&Y.trim()==="")))throw new Error("\u7C98\u8D34\u6570\u636E\u5305\u542B\u7A7A\u516C\u5F0F\u3002");let a=this.state.activeSheet.mergeMasterByAddress.get(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 _=formatRangeAddress(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1),Y=r.valuesOnly?[]:await this.resolveClipboardStyles(e);return await this.runUserMutation({label:"Paste into merged cell"},async B=>{var z,G;await B.setRangeValues(this.state.activeSheetName,_,Array.from({length:n.endRow-n.startRow+1},()=>Array(n.endColumn-n.startColumn+1).fill(null))),await B.setCellValue(this.state.activeSheetName,formatCellAddress(n.startRow,n.startColumn),e.values[0][0]);let U=(z=Pl(e,n.startRow,n.startColumn)[0])==null?void 0:z[0];!r.valuesOnly&&U&&await B.setCellFormula(this.state.activeSheetName,formatCellAddress(n.startRow,n.startColumn),U),!r.valuesOnly&&Y.length&&await B.setRangeStyleId(this.state.activeSheetName,_,(G=Y[0])==null?void 0:G[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=H(v({},n),{endRow:n.startRow+d-1,endColumn:n.startColumn+u-1}),p=Array.from({length:d},(_,Y)=>Array.from({length:u},(B,U)=>{var z,G;return (G=(z=e.values[Y%o])==null?void 0:z[U%i])!=null?G:null})),b=e.styleIds.length?Array.from({length:d},(_,Y)=>Array.from({length:u},(B,U)=>{var z;return (z=e.styleIds[Y%o])==null?void 0:z[U%i]})):[],w=Array.from({length:d},()=>Array(u).fill(null)),g=[];for(let _=0;_<d;_+=o)for(let Y=0;Y<u;Y+=i){let B=Pl(e,n.startRow+_,n.startColumn+Y,r.cut);for(let U=0;U<o;U++)for(let z=0;z<i;z++)w[_+U][Y+z]=(O=(A=B[U])==null?void 0:A[z])!=null?O:null;g.push(...e.merges.map(U=>H(v({},U),{startRowOffset:U.startRowOffset+_,startColumnOffset:U.startColumnOffset+Y})));}if(!r.cut){formatRangeAddress(f.startRow,f.startColumn,d,u);for(let _ of this.state.activeSheet.mergeMasterByAddress.values())if(Fl(f,_.range)&&(_.range.startRow<f.startRow||_.range.startColumn<f.startColumn||_.range.endRow>f.endRow||_.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&&e.styleIds.length){let _=await this.resolveClipboardStyles(e);b=Array.from({length:d},(Y,B)=>Array.from({length:u},(U,z)=>{var G;return (G=_[B%o])==null?void 0:G[z%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(_=>_.name===e.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 x=e.sourceRange,S=this.state.activeSheetName,k=(_,Y,B)=>_>=B.startRow&&_<=B.endRow&&Y>=B.startColumn&&Y<=B.endColumn;formatRangeAddress(f.startRow,f.startColumn,d,u);for(let _ of this.state.activeSheet.mergeMasterByAddress.values())if(!(e.sourceSheet===S&&k(_.range.startRow,_.range.startColumn,x)&&k(_.range.endRow,_.range.endColumn,x))&&Fl(f,_.range)&&(!k(_.range.startRow,_.range.startColumn,f)||!k(_.range.endRow,_.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(_=>[_.address,_]));for(let _=0;_<o;_++)for(let Y=0;Y<i;Y++){let B=I.get(formatCellAddress(x.startRow+_,x.startColumn+Y));if((B==null?void 0:B.styleId)!==((ee=e.styleIds[_])==null?void 0:ee[Y]))throw new Error("\u526A\u5207\u6765\u6E90\u683C\u5F0F\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u526A\u5207\u3002");if(!e.merges.some(U=>_>=U.startRowOffset&&_<U.startRowOffset+U.rowCount&&Y>=U.startColumnOffset&&Y<U.startColumnOffset+U.columnCount&&(_!==U.startRowOffset||Y!==U.startColumnOffset))&&(((le=B==null?void 0:B.formula)!=null?le:null)!==((ie=(oe=e.formulas[_])==null?void 0:oe[Y])!=null?ie:null)||!(B!=null&&B.formula)&&((ae=B==null?void 0:B.value)!=null?ae:null)!==e.values[_][Y]))throw new Error("\u526A\u5207\u6765\u6E90\u5185\u5BB9\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u526A\u5207\u3002")}if(e.sourceSheet===S&&x.startRow===n.startRow&&x.startColumn===n.startColumn)return f;let D=[];for(let _ of this.state.model.sheets)for(let Y of _.cells){if(!Y.formula)continue;let B=_.name===e.sourceSheet&&k(Y.row,Y.column,x);if(!B&&_.name===S&&k(Y.row,Y.column,f))continue;let U=B?S:_.name,z=Wl(Y.formula,{sourceSheet:e.sourceSheet,targetSheet:S,source:x,formulaSheet:_.name,resultSheet:U,rowOffset:n.startRow-x.startRow,columnOffset:n.startColumn-x.startColumn});(B||z!==Y.formula)&&D.push({sheet:U,address:B?formatCellAddress(n.startRow+Y.row-x.startRow,n.startColumn+Y.column-x.startColumn):Y.address,formula:z});}let F=this.state.model.definedNames.flatMap((_,Y)=>{var z,G,K;let B=(K=(G=this.state.model.sheets[(z=_.localSheetId)!=null?z:0])==null?void 0:G.name)!=null?K:e.sourceSheet,U=Wl(_.text,{sourceSheet:e.sourceSheet,targetSheet:S,source:x,formulaSheet:B,resultSheet:B,rowOffset:n.startRow-x.startRow,columnOffset:n.startColumn-x.startColumn});return U===_.text?[]:[{index:Y,text:U}]});return await this.runUserMutation({label:"Move cells"},async _=>{for(let Y of e.merges)await _.unmergeRange(e.sourceSheet,formatRangeAddress(x.startRow+Y.startRowOffset,x.startColumn+Y.startColumnOffset,Y.rowCount,Y.columnCount));await _.clearRange(e.sourceSheet,formatRangeAddress(x.startRow,x.startColumn,o,i)),await this.refresh(),await this.pasteRange(n.startRow,n.startColumn,p,{formulas:w,styleIds:b,merges:g});for(let Y of D)await _.setCellFormula(Y.sheet,Y.address,Y.formula);F.length&&await _.runSnapshot("Move named references","Cut updates defined-name references",async()=>{await this.state.workbook.executeCode(`
|
|
1669
1684
|
const names = workbook.names.items();
|
|
1670
1685
|
for (const update of args.updates) names[update.index].setText(update.text);
|
|
1671
|
-
`,{updates:H});});}),p}async resolveClipboardStyles(e){if(!e.styles)return e.styleIds;let n=this.state.model.styles,r=[...new Set(e.styleIds.flat().map(s=>s===void 0?"default":String(s)))],o=r.map(s=>{let l=e.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 e.styleIds.map(s=>s.map(l=>{let d=l===void 0?"default":String(l);return (l===void 0||n.cellFormats[l])&&equalExcelCellStyles(e.styles[d],captureExcelCellStyle(n,l))?l:a.get(d)}))}async clearRange(e,n,r,o){await this.runUserMutation({label:"Clear range"},async i=>{await i.setRangeValues(this.state.activeSheetName,formatRangeAddress(e,n,r,o),Array.from({length:r},()=>Array(o).fill(null)));});}async setRowHeight(e,n){await this.runUserMutation({label:"Set row height"},async r=>{await r.setRowHeight(this.state.activeSheetName,e,n);});}async setColumnWidth(e,n,r){await this.runUserMutation({label:"Set column width"},async o=>{await o.setColumnWidth(this.state.activeSheetName,e,Ki(n,r));});}async setFreezePanes(e,n){let r=hh(e),o=hh(n),i=P0(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(e,n=1){await this.runUserMutation({label:"Insert rows"},async r=>{await r.insertRows(this.state.activeSheetName,e,n);});}async deleteRows(e,n=1){await this.runUserMutation({label:"Delete rows"},async r=>{await r.deleteRows(this.state.activeSheetName,e,n);});}async insertColumns(e,n=1){await this.runUserMutation({label:"Insert columns"},async r=>{await r.insertColumns(this.state.activeSheetName,e,n);});}async deleteColumns(e,n=1){await this.runUserMutation({label:"Delete columns"},async r=>{await r.deleteColumns(this.state.activeSheetName,e,n);});}async setRangeBold(e,n,r,o,i){await this.runUserMutation({label:"Set bold"},async a=>{await a.setRangeBold(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeItalic(e,n,r,o,i){await this.runUserMutation({label:"Set italic"},async a=>{await a.setRangeItalic(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeUnderline(e,n,r,o,i){await this.runUserMutation({label:"Set underline"},async a=>{await a.setRangeUnderline(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeFontColor(e,n,r,o,i){await this.runUserMutation({label:"Set font color"},async a=>{await a.setRangeFontColor(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeFillColor(e,n,r,o,i){await this.runUserMutation({label:"Set fill color"},async a=>{await a.setRangeFillColor(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeHorizontalAlign(e,n,r,o,i){await this.runUserMutation({label:"Set horizontal align"},async a=>{await a.setRangeHorizontalAlign(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeVerticalAlign(e,n,r,o,i){await this.runUserMutation({label:"Set vertical align"},async a=>{await a.setRangeVerticalAlign(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeNumberFormat(e,n,r,o,i){await this.runUserMutation({label:"Set number format"},async a=>{await a.setRangeNumberFormat(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async clearRangeFormat(e,n,r,o){await this.runUserMutation({label:"Clear format"},async i=>{await i.clearRangeFormat(this.state.activeSheetName,formatRangeAddress(e,n,r,o));});}async mergeRange(e,n,r,o){let i=formatRangeAddress(e,n,r,o),a=await this.cellStyleId(formatCellAddress(e,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(e){if(e.length===0)return;let n=e.map(r=>{let o=[...this.state.activeSheet.mergeMasterByAddress.values()].find(a=>a.address===r),i=o?formatCellAddress(o.range.startRow,o.range.startColumn):D0(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(e,n,r,o,i){if(i==="clear"){await this.runUserMutation({label:"Clear border"},async s=>{await s.setRangeBorder(this.state.activeSheetName,formatRangeAddress(e,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,formatRangeAddress(e,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,formatRangeAddress(e,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,formatCellAddress(e+l,n+d),u);}});}async toZip(){return this.state.workbook.toZip()}async moveChart(e,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[e];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 setDrawingPosition(e,n,r,o){var s,l;let i=this.activeSheet().source;if(i.id!==e)return;let a=(l=(s=i.drawings[n])==null?void 0:s.anchors[r])==null?void 0:l.object;a!=null&&a.hidden||(a==null?void 0:a.kind)!=="image"&&(a==null?void 0:a.kind)!=="shape"||await this.runUserMutation({label:"Position drawing"},async d=>{await d.runSnapshot("Position drawing","spreadsheet drawing position",async()=>{var p;await((p=(await this.state.workbook.worksheets.getItem(i.name).drawings.items())[n])==null?void 0:p.anchors.getItem(r).setPosition(o));});});}async dispose(){await this.state.workbook.dispose();}editableCellAddress(e){var o;let n=parseCellAddress(e),r=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=go(this.state.activeSheet.source,this.state.model.styles,{formulaResults:this.state.formulaResults,date1904:this.state.model.date1904});}async runUserMutation(e,n){if(this.assertWritable(),this.activeTransaction){await n(this.activeTransaction),this.transactionNeedsRefresh=true;return}await this.runScopedTransaction("user",r=>this.state.workbook.history().runGroup(F(v({},e),{source:"user"}),r),async()=>{if(!this.activeTransaction)throw new Error("SpreadsheetEditorRuntime: transaction not active");await n(this.activeTransaction),this.transactionNeedsRefresh=true;});}async runWorksheetStructureMutation(e,n){if(this.assertWritable(),this.activeTransactionSource==="agent"&&this.activeTransaction){await e(this.activeTransaction),this.transactionNeedsRefresh=true,await this.refresh();return}await n(),await this.refresh();}async cellStyleId(e){var n;return (n=(await this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(e).styleIds())[0])==null?void 0:n[0]}async runScopedTransaction(e,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=e;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 hn("spreadsheet")}cellEditHistoryGroup(e,n,r){var i;let o={label:e};return r.mergeUndo?F(v({},o),{mergeKey:`edit:${this.state.activeSheetName}!${n}`,mergeWindowMs:(i=r.mergeWindowMs)!=null?i:1e3}):o}range(e,n,r,o){return this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(formatRangeAddress(e,n,r,o))}};function T0(){return {style:"thin",color:{rgb:"#111827"}}}function hh(t){return Number.isFinite(t)?Math.max(0,Math.floor(t)):0}function P0(t,e,n){var i;if(!e&&!n)return t.map((a,s)=>F(v({},a),{pane:s===0?void 0:a.pane?v({},a.pane):void 0,selections:a.selections.map(l=>v({},l))}));let r=(i=t[0])!=null?i:{workbookViewId:0,selections:[]},o={xSplit:n||void 0,ySplit:e||void 0,topLeftCell:formatCellAddress(e+1,n+1),activePane:e&&n?"bottomRight":e?"bottomLeft":"topRight",state:"frozen"};return [F(v({},r),{pane:o,selections:r.selections.map(a=>v({},a))}),...t.slice(1).map(a=>F(v({},a),{pane:a.pane?v({},a.pane):void 0,selections:a.selections.map(s=>v({},s))}))]}async function R0(t,e,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 t.setRangeStyleId(e,formatCellAddress(n+a,r+l),s[l]);}}async function M0(t,e,n,r,o){for(let i of o)await t.mergeRange(e,formatRangeAddress(n+i.startRowOffset,r+i.startColumnOffset,i.rowCount,i.columnCount));}function A0(t){switch(t){case "values":return "Paste values";case "formats":return "Paste formats";default:return "Paste range"}}function mh(t){return JSON.parse(JSON.stringify(t))}function L0(t){var r,o,i,a,s,l;let e={total:0,added:0,modified:0,deleted:0},n=[];for(let d of t.sheets)for(let u of d.cells)e.total+=1,e[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:t.changed,changedSheets:t.sheets.length,sheetNames:t.sheets.map(d=>{var u,p;return (p=(u=d.afterName)!=null?u:d.beforeName)!=null?p:d.sheetId}),cellChanges:e,structuralChanged:t.sheets.some(d=>d.structuralChanged),objectChanged:t.sheets.some(d=>d.objectChanged),sampleCells:n}}function Fl(t,e){return !(t.endRow<e.startRow||t.startRow>e.endRow||t.endColumn<e.startColumn||t.startColumn>e.endColumn)}function D0(t){let e=parseRangeAddress(t);return formatCellAddress(e.startRow,e.startColumn)}async function dP(t,e,n={}){return {action:e,context:n,transaction:await t.previewAgentTransaction(bh(e),r=>e.run(r,n))}}async function cP(t,e,n={}){return {action:e,context:n,transaction:await t.runAgentTransaction(bh(e),r=>e.run(r,n))}}function bh(t){var e;return {label:t.label,actor:t.actor,description:t.description,agentRunId:t.agentRunId,agentStepId:t.agentStepId,agentActionId:(e=t.agentActionId)!=null?e:t.id,metadata:t.metadata}}function wh(t,e){t.replaceChildren(...e.map(({text:n,style:r},o)=>{let i=t.ownerDocument.createElement("span");return i.dataset.runIndex=String(o),i.textContent=n,Object.assign(i.style,{font:r.font,color:r.fontColor,textDecoration:r.underline?"underline":"none"}),i}));}function xh(t,e){let n=[],r,o=0,i=(s,l)=>{var u;if(!s)return;o+=s.length;let d=n[n.length-1];if(d&&r===l)d.text+=s;else {let p=l===void 0||(u=e[l])==null?void 0:u.font;n.push(p?{text:s,font:p}:{text:s}),r=l;}},a=(s,l)=>{var p;let d=false,u=false;for(let f of Array.from(s.childNodes)){let b=f.nodeType===1?f:void 0,w=(b==null?void 0:b.tagName)==="DIV"||(b==null?void 0:b.tagName)==="P",g=n[n.length-1];(w||d)&&(g||d)&&(!(g!=null&&g.text.endsWith(`
|
|
1686
|
+
`,{updates:F});});}),f}async resolveClipboardStyles(e){if(!e.styles)return e.styleIds;let n=this.state.model.styles,r=[...new Set(e.styleIds.flat().map(s=>s===void 0?"default":String(s)))],o=r.map(s=>{let l=e.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 e.styleIds.map(s=>s.map(l=>{let d=l===void 0?"default":String(l);return (l===void 0||n.cellFormats[l])&&equalExcelCellStyles(e.styles[d],captureExcelCellStyle(n,l))?l:a.get(d)}))}async clearRange(e,n,r,o){await this.runUserMutation({label:"Clear range"},async i=>{await i.setRangeValues(this.state.activeSheetName,formatRangeAddress(e,n,r,o),Array.from({length:r},()=>Array(o).fill(null)));});}async setRowHeight(e,n){await this.runUserMutation({label:"Set row height"},async r=>{await r.setRowHeight(this.state.activeSheetName,e,n);});}async setColumnWidth(e,n,r){await this.runUserMutation({label:"Set column width"},async o=>{await o.setColumnWidth(this.state.activeSheetName,e,Ki(n,r));});}async setFreezePanes(e,n){let r=hh(e),o=hh(n),i=P0(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(e,n=1){await this.runUserMutation({label:"Insert rows"},async r=>{await r.insertRows(this.state.activeSheetName,e,n);});}async deleteRows(e,n=1){await this.runUserMutation({label:"Delete rows"},async r=>{await r.deleteRows(this.state.activeSheetName,e,n);});}async insertColumns(e,n=1){await this.runUserMutation({label:"Insert columns"},async r=>{await r.insertColumns(this.state.activeSheetName,e,n);});}async deleteColumns(e,n=1){await this.runUserMutation({label:"Delete columns"},async r=>{await r.deleteColumns(this.state.activeSheetName,e,n);});}async setRangeBold(e,n,r,o,i){await this.runUserMutation({label:"Set bold"},async a=>{await a.setRangeBold(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeItalic(e,n,r,o,i){await this.runUserMutation({label:"Set italic"},async a=>{await a.setRangeItalic(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeUnderline(e,n,r,o,i){await this.runUserMutation({label:"Set underline"},async a=>{await a.setRangeUnderline(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeFontColor(e,n,r,o,i){await this.runUserMutation({label:"Set font color"},async a=>{await a.setRangeFontColor(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeFillColor(e,n,r,o,i){await this.runUserMutation({label:"Set fill color"},async a=>{await a.setRangeFillColor(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeHorizontalAlign(e,n,r,o,i){await this.runUserMutation({label:"Set horizontal align"},async a=>{await a.setRangeHorizontalAlign(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeVerticalAlign(e,n,r,o,i){await this.runUserMutation({label:"Set vertical align"},async a=>{await a.setRangeVerticalAlign(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async setRangeNumberFormat(e,n,r,o,i){await this.runUserMutation({label:"Set number format"},async a=>{await a.setRangeNumberFormat(this.state.activeSheetName,formatRangeAddress(e,n,r,o),i);});}async clearRangeFormat(e,n,r,o){await this.runUserMutation({label:"Clear format"},async i=>{await i.clearRangeFormat(this.state.activeSheetName,formatRangeAddress(e,n,r,o));});}async mergeRange(e,n,r,o){let i=formatRangeAddress(e,n,r,o),a=await this.cellStyleId(formatCellAddress(e,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(e){if(e.length===0)return;let n=e.map(r=>{let o=[...this.state.activeSheet.mergeMasterByAddress.values()].find(a=>a.address===r),i=o?formatCellAddress(o.range.startRow,o.range.startColumn):D0(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(e,n,r,o,i){if(i==="clear"){await this.runUserMutation({label:"Clear border"},async s=>{await s.setRangeBorder(this.state.activeSheetName,formatRangeAddress(e,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,formatRangeAddress(e,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,formatRangeAddress(e,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,formatCellAddress(e+l,n+d),u);}});}async toZip(){return this.state.workbook.toZip()}async moveChart(e,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[e];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 setDrawingPosition(e,n,r,o){var s,l;let i=this.activeSheet().source;if(i.id!==e)return;let a=(l=(s=i.drawings[n])==null?void 0:s.anchors[r])==null?void 0:l.object;a!=null&&a.hidden||(a==null?void 0:a.kind)!=="image"&&(a==null?void 0:a.kind)!=="shape"||await this.runUserMutation({label:"Position drawing"},async d=>{await d.runSnapshot("Position drawing","spreadsheet drawing position",async()=>{var f;await((f=(await this.state.workbook.worksheets.getItem(i.name).drawings.items())[n])==null?void 0:f.anchors.getItem(r).setPosition(o));});});}async dispose(){await this.state.workbook.dispose();}editableCellAddress(e){var o;let n=parseCellAddress(e),r=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=go(this.state.activeSheet.source,this.state.model.styles,{formulaResults:this.state.formulaResults,date1904:this.state.model.date1904});}async runUserMutation(e,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({},e),{source:"user"}),r),async()=>{if(!this.activeTransaction)throw new Error("SpreadsheetEditorRuntime: transaction not active");await n(this.activeTransaction),this.transactionNeedsRefresh=true;});}async runWorksheetStructureMutation(e,n){if(this.assertWritable(),this.activeTransactionSource==="agent"&&this.activeTransaction){await e(this.activeTransaction),this.transactionNeedsRefresh=true,await this.refresh();return}await n(),await this.refresh();}async cellStyleId(e){var n;return (n=(await this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(e).styleIds())[0])==null?void 0:n[0]}async runScopedTransaction(e,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=e;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 hn("spreadsheet")}cellEditHistoryGroup(e,n,r){var i;let o={label:e};return r.mergeUndo?H(v({},o),{mergeKey:`edit:${this.state.activeSheetName}!${n}`,mergeWindowMs:(i=r.mergeWindowMs)!=null?i:1e3}):o}range(e,n,r,o){return this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(formatRangeAddress(e,n,r,o))}};function T0(){return {style:"thin",color:{rgb:"#111827"}}}function hh(t){return Number.isFinite(t)?Math.max(0,Math.floor(t)):0}function P0(t,e,n){var i;if(!e&&!n)return t.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=t[0])!=null?i:{workbookViewId:0,selections:[]},o={xSplit:n||void 0,ySplit:e||void 0,topLeftCell:formatCellAddress(e+1,n+1),activePane:e&&n?"bottomRight":e?"bottomLeft":"topRight",state:"frozen"};return [H(v({},r),{pane:o,selections:r.selections.map(a=>v({},a))}),...t.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(t,e,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 t.setRangeStyleId(e,formatCellAddress(n+a,r+l),s[l]);}}async function M0(t,e,n,r,o){for(let i of o)await t.mergeRange(e,formatRangeAddress(n+i.startRowOffset,r+i.startColumnOffset,i.rowCount,i.columnCount));}function A0(t){switch(t){case "values":return "Paste values";case "formats":return "Paste formats";default:return "Paste range"}}function mh(t){return JSON.parse(JSON.stringify(t))}function L0(t){var r,o,i,a,s,l;let e={total:0,added:0,modified:0,deleted:0},n=[];for(let d of t.sheets)for(let u of d.cells)e.total+=1,e[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:t.changed,changedSheets:t.sheets.length,sheetNames:t.sheets.map(d=>{var u,f;return (f=(u=d.afterName)!=null?u:d.beforeName)!=null?f:d.sheetId}),cellChanges:e,structuralChanged:t.sheets.some(d=>d.structuralChanged),objectChanged:t.sheets.some(d=>d.objectChanged),sampleCells:n}}function Fl(t,e){return !(t.endRow<e.startRow||t.startRow>e.endRow||t.endColumn<e.startColumn||t.startColumn>e.endColumn)}function D0(t){let e=parseRangeAddress(t);return formatCellAddress(e.startRow,e.startColumn)}async function cP(t,e,n={}){return {action:e,context:n,transaction:await t.previewAgentTransaction(bh(e),r=>e.run(r,n))}}async function uP(t,e,n={}){return {action:e,context:n,transaction:await t.runAgentTransaction(bh(e),r=>e.run(r,n))}}function bh(t){var e;return {label:t.label,actor:t.actor,description:t.description,agentRunId:t.agentRunId,agentStepId:t.agentStepId,agentActionId:(e=t.agentActionId)!=null?e:t.id,metadata:t.metadata}}function wh(t,e){t.replaceChildren(...e.map(({text:n,style:r},o)=>{let i=t.ownerDocument.createElement("span");return i.dataset.runIndex=String(o),i.textContent=n,Object.assign(i.style,{font:r.font,color:r.fontColor,textDecoration:r.underline?"underline":"none"}),i}));}function xh(t,e){let n=[],r,o=0,i=(s,l)=>{var u;if(!s)return;o+=s.length;let d=n[n.length-1];if(d&&r===l)d.text+=s;else {let f=l===void 0||(u=e[l])==null?void 0:u.font;n.push(f?{text:s,font:f}:{text:s}),r=l;}},a=(s,l)=>{var f;let d=false,u=false;for(let p of Array.from(s.childNodes)){let b=p.nodeType===1?p:void 0,w=(b==null?void 0:b.tagName)==="DIV"||(b==null?void 0:b.tagName)==="P",g=n[n.length-1];(w||d)&&(g||d)&&(!(g!=null&&g.text.endsWith(`
|
|
1672
1687
|
`))||u)&&i(`
|
|
1673
|
-
`,r);let h=o;if(
|
|
1688
|
+
`,r);let h=o;if(p.nodeType===3)i((f=p.textContent)!=null?f:"",l);else if((b==null?void 0:b.tagName)==="BR")s.childNodes.length>1&&i(`
|
|
1674
1689
|
`,l);else if(b){let x=b.dataset.runIndex===void 0?l:Number(b.dataset.runIndex);a(b,x);}d=w,u=w&&o===h;}};return a(t),n}function yh(t){var n,r;let e=t.getRootNode();return (r=(n=e.getSelection)==null?void 0:n.call(e))!=null?r:t.ownerDocument.getSelection()}function vh(t){var o;t.focus({preventScroll:true});let e=yh(t);if(!e)return;let n=t.ownerDocument.createRange(),r=(o=t.firstElementChild)==null?void 0:o.firstChild;r?n.setStart(r,0):n.selectNodeContents(t),n.collapse(true),e.removeAllRanges(),e.addRange(n);}function Hl(t,e){var s;let n=t.ownerDocument,r=e.replace(/\r\n?/g,`
|
|
1675
1690
|
`);if((s=n.execCommand)!=null&&s.call(n,"insertText",false,r))return;let o=yh(t);if(!(o!=null&&o.rangeCount))return;let i=o.getRangeAt(0);if(!t.contains(i.commonAncestorContainer))return;let a=n.createTextNode(r);i.deleteContents(),i.insertNode(a),i.setStartAfter(a),i.collapse(true),o.removeAllRanges(),o.addRange(i);}var oa=class{constructor(e){W(this,"options",e);W(this,"active",false);W(this,"richRuns");W(this,"pendingCommit",Promise.resolve());W(this,"handleBlur",()=>{this.commit().catch(e=>{var n,r;return (r=(n=this.options).onError)==null?void 0:r.call(n,e)});});W(this,"handleInput",()=>{var n;if(!this.active||!this.options.onInput)return;let e=this.richRuns?(n=this.options.richInput.textContent)!=null?n:"":this.options.textarea.value;this.options.onInput(e);});W(this,"handleRichPaste",e=>{var n;e.preventDefault(),(n=e.clipboardData)!=null&&n.types.includes("text/plain")&&(Hl(this.options.richInput,e.clipboardData.getData("text/plain")),this.handleInput());});W(this,"handleKeyDown",e=>{e.isComposing||e.keyCode===229||(e.key==="Escape"?(e.preventDefault(),e.stopPropagation(),this.cancel()):this.richRuns&&e.key==="Enter"&&e.altKey&&!e.ctrlKey&&!e.metaKey?(e.preventDefault(),e.stopPropagation(),Hl(this.options.richInput,`
|
|
1676
|
-
`),this.handleInput()):(e.key==="Enter"||e.key==="Tab")&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&(e.preventDefault(),e.stopPropagation(),this.commit({key:e.key,reverse:e.shiftKey}).catch(n=>{var r,o;return (o=(r=this.options).onError)==null?void 0:o.call(r,n)})));});for(let n of [e.textarea,e.richInput])n.addEventListener("keydown",this.handleKeyDown),n.addEventListener("blur",this.handleBlur),n.addEventListener("input",this.handleInput);e.richInput.addEventListener("paste",this.handleRichPaste);}isRich(){return this.richRuns!==void 0}contains(e){let n=e.composedPath();return n.includes(this.options.textarea)||n.includes(this.options.richFrame)}open(e,n,r){if(this.active=true,this.richRuns=r,r){let{richFrame:i,richInput:a}=this.options;wh(a,r),this.place(e),vh(a),i.scrollTop=0,i.scrollLeft=0;return}let o=this.options.textarea;o.value=n,this.place(e),o.focus({preventScroll:true}),o.setSelectionRange(n.length,n.length);}place(e){if(!this.active)return;let n=this.richRuns?this.options.richFrame:this.options.textarea;if(!e){n.style.display="none";return}Object.assign(n.style,{display:this.richRuns?"flex":"block",left:`${e.x}px`,top:`${e.y}px`,width:`${Math.max(1,e.width)}px`,height:`${Math.max(1,e.height)}px`});}commit(e){if(!this.active)return this.pendingCommit;this.active=false;let n=this.richRuns&&xh(this.options.richInput,this.richRuns),r=n?n.map(o=>o.text).join(""):this.options.textarea.value;try{this.pendingCommit=Promise.resolve(this.options.onCommit(r,n)),e&&(this.pendingCommit=this.pendingCommit.then(()=>{var o,i;return (i=(o=this.options).onNavigate)==null?void 0:i.call(o,e.key,e.reverse)}));}catch(o){this.pendingCommit=Promise.reject(o);}return this.close(),this.pendingCommit}cancel(){var e,n;this.active=false,this.close(),(n=(e=this.options).onCancel)==null||n.call(e);}close(){this.options.textarea.style.display="none",this.options.richFrame.style.display="none",this.richRuns=void 0;}destroy(){this.active=false;for(let e of [this.options.textarea,this.options.richInput])e.removeEventListener("keydown",this.handleKeyDown),e.removeEventListener("blur",this.handleBlur),e.removeEventListener("input",this.handleInput);this.options.richInput.removeEventListener("paste",this.handleRichPaste),this.close();}};function kh(t,e,n){return {x:Math.max(0,t.x+e),y:Math.max(0,t.y+n)}}function Eh(t,e,n,r,o=12){let i=t.getColumnX(n.frozenColumns+1),a=t.getRowY(n.frozenRows+1),s=Math.max(0,e.width-t.rowHeaderWidth-i-o),l=Math.max(0,e.height-t.columnHeaderHeight-a-o),d=s,u=l,p=Math.max(0,t.totalWidth()-i),f=Math.max(0,t.totalHeight()-a);return {horizontal:Sh(p,d,s,r.x),vertical:Sh(f,u,l,r.y)}}function ia(t,e){if(t.maxScroll<=0)return 0;let n=Math.max(0,t.trackLength-t.thumbLength);return n<=0?0:Math.max(0,Math.min(n,e))/n*t.maxScroll}function Sh(t,e,n,r){let o=Math.max(0,t-e);if(n<=0||t<=0||o<=0)return {trackLength:n,thumbStart:0,thumbLength:n,maxScroll:0};let i=Math.max(24,Math.min(n,e/t*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 bP=24,wP=12,xP=4;function Ol(t,e,n){for(let r of e){if(r.kind==="columnHeaderFrozen"||r.kind==="columnHeaderScrollable"){let o=W0(t,r,n);if(o)return o}if(r.kind==="rowHeaderFrozen"||r.kind==="rowHeaderScrollable"){let o=B0(t,r,n);if(o)return o}}return null}function Ch(t,e){return F(v({},t),{startClientX:e.clientX,startClientY:e.clientY,currentSize:t.startSize,currentGuidePosition:t.guidePosition})}function $l(t,e){let n=t.kind==="column"?e.clientX-t.startClientX:e.clientY-t.startClientY,r=Math.max(t.minSize,Math.round(t.startSize+n));return F(v({},t),{currentSize:r,currentGuidePosition:t.guidePosition+r-t.startSize})}function W0(t,e,n){if(!Ih(e.screenRect,n,4))return null;for(let r=e.columns.start;r<=e.columns.end;r++){let o=t.getCellLogicalRect(1,r),a=e.screenRect.x+o.x-e.originX+o.width;if(Math.abs(n.x-a)<=4)return {kind:"column",index:r,startSize:t.getColumnWidth(r),guidePosition:a,minSize:24}}return null}function B0(t,e,n){if(!Ih(e.screenRect,n,4))return null;for(let r=e.rows.start;r<=e.rows.end;r++){let o=t.getCellLogicalRect(r,1),a=e.screenRect.y+o.y-e.originY+o.height;if(Math.abs(n.y-a)<=4)return {kind:"row",index:r,startSize:t.getRowHeight(r),guidePosition:a,minSize:12}}return null}function Ih(t,e,n=0){return e.x>=t.x-n&&e.y>=t.y-n&&e.x<=t.x+t.width+n&&e.y<=t.y+t.height+n}function EP(t,e){var o,i,a,s,l,d;let n=F0(),r=We(e.range);for(let u=r.startRow;u<=r.endRow;u++)for(let p=r.startColumn;p<=r.endColumn;p++){let f=H0(t,u,p),b=(i=t.styles.fonts[(o=f.fontId)!=null?o:0])!=null?i:{},w=(s=t.styles.fills[(a=f.fillId)!=null?a:0])!=null?s:{},g=(d=t.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,O0(f)),cn(n.vertical,$0(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 F0(){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(t,e){if(!t.hasValue){t.hasValue=true,t.value=e;return}z0(t.value,e)||(t.mixed=true);}function un(t){return t.mixed?"mixed":t.value}function H0(t,e,n){var o,i;let r=qe(t,e,n);return (i=t.styles.cellFormats[(o=r==null?void 0:r.styleId)!=null?o:0])!=null?i:{}}function O0(t){var e,n;return ((e=t.alignment)==null?void 0:e.horizontal)==="center"||((n=t.alignment)==null?void 0:n.horizontal)==="right"?t.alignment.horizontal:"left"}function $0(t){var e,n;return ((e=t.alignment)==null?void 0:e.vertical)==="top"||((n=t.alignment)==null?void 0:n.vertical)==="center"?t.alignment.vertical:"bottom"}function z0(t,e){return JSON.stringify(t!=null?t:null)===JSON.stringify(e!=null?e:null)}var aa="http://www.w3.org/2000/svg",j0=new Set(["image/png","image/jpeg","image/gif","image/webp","image/bmp","image/svg+xml"]),sa=class{constructor(e){W(this,"pkg",e);W(this,"urls",new Map);W(this,"embedded",new Map);}embeddedOnSheet(e){let n=this.embedded.get(e);if(n)return n;let r=readExcelEmbeddedObjectPreviews(this.pkg,e);return this.embedded.set(e,r),r}render(e,n,r){var a;if(e.hidden)return null;if(e.kind==="shape")return U0(e,n);if(e.kind!=="image"||e.targetMode==="External")return null;let o=e.targetPath&&this.imageUrl(e.targetPath);if(!o)return r?Nh(e.name):null;let i=document.createElement("img");return i.alt=(a=e.name)!=null?a:"",i.draggable=false,r&&i.addEventListener("error",()=>{let s=Nh(e.name);s.style.cssText+=i.style.cssText,i.replaceWith(s);},{once:true}),i.src=o,i}dispose(){for(let e of this.urls.values())URL.revokeObjectURL(e);this.urls.clear(),this.embedded.clear();}imageUrl(e){let n=this.urls.get(e);if(n)return n;let r=getPart(this.pkg,e),o=r==null?void 0:r.contentType.toLowerCase();if(!(r!=null&&r.bytes)||!o||!j0.has(o))return;let i=URL.createObjectURL(new Blob([new Uint8Array(r.bytes)],{type:o}));return this.urls.set(e,i),i}};function U0(t,{width:e,height:n}){var i,a,s;let r;switch(t.presetGeometry){case "rightArrow":case "leftArrow":{let l=e-Math.min(e,n)/2;r=document.createElementNS(aa,"path"),r.setAttribute("d",`M 0 ${n/4} H ${l} V 0 L ${e} ${n/2} L ${l} ${n} V ${n*.75} H 0 Z`),t.presetGeometry==="leftArrow"&&r.setAttribute("transform",`translate(${e} 0) scale(-1 1)`);break}case "rect":r=document.createElementNS(aa,"rect"),r.setAttribute("width",String(e)),r.setAttribute("height",String(n));break;case "ellipse":r=document.createElementNS(aa,"ellipse"),r.setAttribute("cx",String(e/2)),r.setAttribute("cy",String(n/2)),r.setAttribute("rx",String(e/2)),r.setAttribute("ry",String(n/2));break;default:return null}r.setAttribute("fill",(i=t.fillColor)!=null?i:"#4472C4"),r.setAttribute("stroke",(a=t.lineColor)!=null?a:"#2F528F"),r.setAttribute("stroke-width",String(Math.max(0,((s=t.lineWidth)!=null?s:12700)/9525)));let o=document.createElementNS(aa,"svg");return o.setAttribute("viewBox",`0 0 ${e} ${n}`),o.setAttribute("aria-hidden","true"),o.appendChild(r),o}function Nh(t){let e=document.createElement("div");Object.assign(e.style,{display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"3px",font:"10px Arial, sans-serif",color:"#1f2937"});let n=document.createElement("span");Object.assign(n.style,{background:"#107c41",color:"#fff",borderRadius:"2px",padding:"2px 5px",font:"bold 12px Arial, sans-serif"}),n.textContent=/\.xlsx?$/i.test(t!=null?t:"")?"X":"\u2197";let r=document.createElement("span");return Object.assign(r.style,{maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),r.textContent=t!=null?t:"\u5D4C\u5165\u6587\u4EF6",e.append(n,r),e}var Th=["nw","n","ne","e","se","s","sw","w"];function Ph(t,e){let r=t.x+(e.includes("w")?0:e.includes("e")?t.width:t.width/2),o=t.y+(e.includes("n")?0:e.includes("s")?t.height:t.height/2);return {x:r-8/2,y:o-8/2,width:8,height:8}}function Rh(t,e,n,r){if(!r)return F(v({},t),{x:fr(t.x+e.x,0,n.width-t.width),y:fr(t.y+e.y,0,n.height-t.height)});let o=Math.min(8,t.width),i=Math.min(8,t.height),a=t.x+t.width,s=t.y+t.height,l=r.includes("w")?fr(t.x+e.x,0,a-o):t.x,d=r.includes("n")?fr(t.y+e.y,0,s-i):t.y;return {x:l,y:d,width:(r.includes("e")?fr(a+e.x,l+o,n.width):a)-l,height:(r.includes("s")?fr(s+e.y,d+i,n.height):s)-d}}function fr(t,e,n){return Math.max(e,Math.min(n,t))}function Mh(t,e,n,r){let o=t.cssPixelsToEmu(e.x),i=t.cssPixelsToEmu(e.y),a=t.cssPixelsToEmu(e.width),s=t.cssPixelsToEmu(e.height),l=(f,b,w=-1/0)=>f===void 0?void 0:Math.max(w,f+t.cssPixelsToEmu(b)),d=r.transform&&{x:l(r.transform.x,e.x-n.x),y:l(r.transform.y,e.y-n.y),width:l(r.transform.width,e.width-n.width,1),height:l(r.transform.height,e.height-n.height,1)};if(r.kind==="absolute")return {kind:"absolute",x:o,y:i,width:a,height:s,transform:d};let u=Io(t,e.x,e.y);if(r.kind==="oneCell")return {kind:"oneCell",from:u,width:a,height:s,transform:d};let p=Io(t,e.x+e.width,e.y+e.height);return {kind:"twoCell",from:u,to:p,transform:d}}function Io(t,e,n){let r=t.columnAt(Math.max(0,e)),o=t.rowAt(Math.max(0,n));return {column:r-1,row:o-1,columnOffset:t.cssPixelsToEmu(e-t.getColumnX(r)),rowOffset:t.cssPixelsToEmu(n-t.getRowY(o))}}function Ah(t,e,n,r,o){var b,w,g;let i=We(t.range),a=t.active,s=(b=t.focus)!=null?b:{row:i.endRow===a.row?i.startRow:i.endRow,column:i.endColumn===a.column?i.startColumn:i.endColumn},l=n.shift&&e!=="Tab"&&e!=="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]}[e];if(!u&&e!=="Home"&&!(e==="End"&&n.command))return null;let p=l.row,f=l.column;if(e==="Home")f=1,n.command&&(p=1);else if(e==="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&&e.startsWith("Arrow")){let h=u,x=h[0]?o.rowCount:o.columnCount,S=h[0]?p:f,k=h[0]||h[1],I=H=>{let A=r.cellsByAddress.get(formatCellAddress(h[0]?H:p,h[1]?H:f));return !!(A!=null&&A.formula)||(A==null?void 0:A.value)!==void 0&&A.value!==null&&A.value!==""},D=Math.max(1,Math.min(x,S+k));if(I(S)&&I(D))for(;D+k>=1&&D+k<=x&&I(D+k);)D+=k;else for(;D>1&&D<x&&!I(D);)D+=k;h[0]?p=D:f=D;}else {let h=[...r.mergeMasterByAddress.values()].find(x=>p>=x.range.startRow&&p<=x.range.endRow&&f>=x.range.startColumn&&f<=x.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]),(e==="Tab"||e==="Enter")&&(i.startRow!==i.endRow||i.startColumn!==i.endColumn)&&!h)return e==="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:t.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&&e!=="Tab"&&e!=="Enter"?F(v({},ct(cr(t,p,f,o),r)),{focus:{row:p,column:f}}):ct(it(p,f),r)}function Lh(t,e,n){let{row:r,column:o}=t.active,i=[...e.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=We(t.range),u=Object.keys(a).every(p=>a[p]===d[p]);return ct({kind:"cell",active:t.active,range:l||u?{startRow:1,startColumn:1,endRow:n.rowCount,endColumn:n.columnCount}:a},e)}var la=class{constructor(e,n){W(this,"host",e);W(this,"element",document.createElement("div"));W(this,"anchor",null);W(this,"handleOutsideInteraction",e=>{let n=e.composedPath();!n.includes(this.element)&&(!this.anchor||!n.includes(this.anchor))&&this.hide(false);});W(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(e,n){if(this.anchor===e){this.hide();return}this.hide(false),this.anchor=e,e.setAttribute("aria-expanded","true"),e.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 e=this.host.getBoundingClientRect(),n=this.anchor.getBoundingClientRect(),r=this.element.getBoundingClientRect();this.element.style.left=`${Math.max(4,Math.min(n.left-e.left,e.width-r.width-4))}px`,this.element.style.top=`${Math.max(4,n.top-e.top-r.height-6)}px`;}hide(e=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),e&&(n!=null&&n.isConnected)&&n.focus({preventScroll:true});}destroy(){this.hide(false),this.element.remove();}button(e,n){let r=document.createElement("button");return r.type="button",r.textContent=e,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 aR(t,e,n={}){let r=new jl(t,n);return await r.loadWorkbook(e),r}var jl=class{constructor(e,n){W(this,"host",e);W(this,"options",n);W(this,"renderRoot");W(this,"runtimeValue",null);W(this,"renderer",null);W(this,"layout",null);W(this,"viewport",null);W(this,"scroll",{x:0,y:0});W(this,"scrollbarState",null);W(this,"listeners",new Set);W(this,"stateListeners",new Set);W(this,"baseCanvas",document.createElement("canvas"));W(this,"headerCanvas",document.createElement("canvas"));W(this,"overlayCanvas",document.createElement("canvas"));W(this,"unsupportedObjectLayer",document.createElement("div"));W(this,"drawingPreviews",null);W(this,"drawingHits",[]);W(this,"selectedDrawing",null);W(this,"drawingDrag",null);W(this,"suppressGridClick",false);W(this,"workbookLoadId",0);W(this,"sheetTabs",document.createElement("div"));W(this,"horizontalScrollbar",document.createElement("div"));W(this,"verticalScrollbar",document.createElement("div"));W(this,"horizontalThumb",document.createElement("div"));W(this,"verticalThumb",document.createElement("div"));W(this,"cellEditorElement",document.createElement("textarea"));W(this,"richEditorFrame",document.createElement("div"));W(this,"richEditorInput",document.createElement("div"));W(this,"resizeGuide",document.createElement("div"));W(this,"contextMenu",document.createElement("div"));W(this,"filterMenu",document.createElement("div"));W(this,"sheetDeleteConfirmation");W(this,"cellEditor");W(this,"resizeObserver");W(this,"disposed",false);W(this,"drag",null);W(this,"selectionState",it(1,1));W(this,"editingCell",null);W(this,"editingCellInitialValue",null);W(this,"pendingGridMutation",Promise.resolve());W(this,"editingCellStyle",null);W(this,"clipboardPayload",null);W(this,"clipboardCut",false);W(this,"clipboardActive",false);W(this,"nextPasteValuesOnly",false);W(this,"selecting",false);W(this,"resizeDrag",null);W(this,"autoFillDrag",null);W(this,"selectedChartIndex",null);W(this,"chartDrag",null);W(this,"columnFilters",new Map);W(this,"filterMenuColumn",null);W(this,"copiedRange",null);W(this,"formulaReferenceRanges",[]);W(this,"lastStateKey","");W(this,"transactionDepth",0);W(this,"transactionChanged",false);W(this,"readOnlyValue");W(this,"sheetActionPending",false);W(this,"handleClick",e=>{if(this.suppressGridClick){this.suppressGridClick=false,e.preventDefault();return}if(this.eventPathContains(e,this.contextMenu)||this.eventPathContains(e,this.filterMenu))return;if(this.filterMenu.style.display==="block"&&this.hideFilterMenu(),this.editingCell){if(this.cellEditor.contains(e))return;this.cellEditor.commit().catch(a=>this.reportError(a));}if(!this.viewport||!this.layout)return;let n=this.eventPoint(e),r=this.drawingAtPoint(n),o=r!=null&&r.handle?null:this.chartAtPoint(n);if(o){this.clearDrawingSelection(),this.selectedChartIndex=o.chartIndex,this.render(),e.preventDefault();return}if(this.selectedChartIndex=null,r){this.selectedDrawing=r.target.reference,this.host.focus({preventScroll:true}),this.render(),e.preventDefault();return}this.clearDrawingSelection();let i=this.viewport.hitTest(n);if(!(i.kind!=="cell"&&i.kind!=="rowHeader"&&i.kind!=="columnHeader")){if(i.kind==="cell"&&i.row===1&&this.isFilterIconHit(i.column,e)){if(this.isReadOnly())return;this.openFilterMenu(i.column,e.clientX,e.clientY),e.preventDefault();return}if(i.kind==="cell"){let a=this.runtime().activeSheet();this.selectionState=ct(it(i.row,i.column),a);}this.host.focus(),this.render();}});W(this,"handleFilterMenuClick",e=>{var i;if(this.isReadOnly()){this.hideFilterMenu();return}let r=(i=e.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();});W(this,"handleDoubleClick",e=>{if(!this.viewport||!this.layout||this.cellEditor.contains(e))return;let n=this.eventPoint(e);if(this.drawingAtPoint(n))return;let r=this.viewport.hitTest(n);if(r.kind==="cell"){if(this.selectionState=ct(it(r.row,r.column),this.runtime().activeSheet()),this.isReadOnly()){this.render();return}this.openCellEditor().catch(o=>this.reportError(o)),e.preventDefault();}});W(this,"handlePointerDown",e=>{var u,p;if(this.drawingDrag)return;if(this.suppressGridClick=false,this.editingCell){if(this.cellEditor.contains(e))return;this.cellEditor.commit().catch(f=>this.reportError(f));}if(e.button!==0||!this.viewport||!this.layout)return;let n=this.eventPoint(e),r=this.drawingAtPoint(n),o=r!=null&&r.handle?null:this.chartAtPoint(n);if(o){if(this.clearDrawingSelection(),this.selectedChartIndex=o.chartIndex,this.isReadOnly()){this.render(),e.preventDefault();return}this.chartDrag={chartIndex:o.chartIndex,pointer:n,startRect:o.logicalRect,previewRect:o.logicalRect},this.host.setPointerCapture(e.pointerId),this.render(),e.preventDefault();return}if(this.selectedChartIndex=null,r&&!this.isReadOnly()){let{target:f,handle:b}=r;this.selectedDrawing=f.reference,this.drawingDrag={target:f,handle:b,pointerId:e.pointerId,startScreen:n,startPoint:(u=Bh(this.viewport,n))!=null?u:n,previewRect:f.rect},this.suppressGridClick=true,this.host.focus({preventScroll:true}),this.host.setPointerCapture(e.pointerId),this.host.style.cursor=b?`${b}-resize`:"grabbing",this.render(),e.preventDefault();return}this.clearDrawingSelection();let i=Ol(this.layout,this.viewport.viewports,n);if(i&&!this.isReadOnly()){this.resizeDrag=Ch(i,e),this.host.setPointerCapture(e.pointerId),this.host.style.cursor=i.kind==="column"?"col-resize":"row-resize",this.updateResizeGuide(this.resizeDrag),e.preventDefault();return}let a=We(this.selectionState.range),s=(p=this.renderer)==null?void 0:p.fillHandleRect(this.layout,this.viewport,a);if(!this.isReadOnly()&&s&&zl(s,n)&&Al(this.runtime().activeSheet(),a)){this.autoFillDrag={source:a,preview:null},this.host.setPointerCapture(e.pointerId),e.preventDefault();return}let l=this.viewport.hitTest(n);if(l.kind!=="cell"&&l.kind!=="rowHeader"&&l.kind!=="columnHeader")return;this.host.focus({preventScroll:true});let d=this.runtime().activeSheet();l.kind==="cell"?this.selectionState=ct(it(l.row,l.column),d):l.kind==="rowHeader"?this.selectionState=ea(l.row,{columnCount:this.layout.columnCount}):this.selectionState=ta(l.column,{rowCount:this.layout.rowCount}),this.selecting=true,this.host.setPointerCapture(e.pointerId),this.render(),e.preventDefault();});W(this,"handlePointerMove",e=>{if(!this.viewport||!this.layout)return;if(this.drawingDrag){if(this.drawingDrag.pointerId!==e.pointerId)return;this.drawingDrag.previewRect=this.drawingDragRect(this.drawingDrag,this.eventPoint(e)),this.render(),e.preventDefault();return}if(this.chartDrag){let a=this.eventPoint(e),s=a.x-this.chartDrag.pointer.x,l=a.y-this.chartDrag.pointer.y;this.chartDrag.previewRect=F(v({},this.chartDrag.startRect),{x:Math.max(0,this.chartDrag.startRect.x+s),y:Math.max(0,this.chartDrag.startRect.y+l)}),this.host.style.cursor="grabbing",this.render(),e.preventDefault();return}if(!this.resizeDrag&&!this.autoFillDrag&&!this.selecting&&!this.editingCell){let a=this.eventPoint(e),s=this.drawingAtPoint(a),l=this.isReadOnly()||s?null:Ol(this.layout,this.viewport.viewports,a);this.host.style.cursor=s?s.handle?`${s.handle}-resize`:"move":l?l.kind==="column"?"col-resize":"row-resize":"";}if(this.resizeDrag){this.resizeDrag=$l(this.resizeDrag,e),this.updateResizeGuide(this.resizeDrag);return}if(this.autoFillDrag){let a=this.viewport.hitTest(this.eventPoint(e));this.autoFillDrag.preview=tk(this.autoFillDrag.source,a),this.render(),e.preventDefault();return}if(!this.selecting)return;let n=this.viewport.hitTest(this.eventPoint(e));if(n.kind==="none"||n.kind==="corner")return;let r=this.runtime().activeSheet(),o=this.selectionState.range;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}));let i=this.selectionState.range;(i.startRow!==o.startRow||i.endRow!==o.endRow||i.startColumn!==o.startColumn||i.endColumn!==o.endColumn)&&(this.suppressGridClick=true),this.render(),e.preventDefault();});W(this,"handlePointerUp",e=>{if(this.drawingDrag){let n=this.drawingDrag;if(n.pointerId!==e.pointerId)return;let r=this.drawingDragRect(n,this.eventPoint(e));this.cancelDrawingDrag();let o=n.target.rect;if(this.layout&&!this.isReadOnly()&&(r.x!==o.x||r.y!==o.y||r.width!==o.width||r.height!==o.height)){let i=this.layout,a=this.runtime(),{sheetId:s,drawingIndex:l,anchorIndex:d}=n.target.reference,u=Mh(i,r,o,n.target.anchor);this.queueGridMutation(async()=>{this.disposed||this.isReadOnly()||this.runtimeValue!==a||a.activeSheet().source.id!==s||(await a.setDrawingPosition(s,l,d,u),this.render(),await this.emitChange());}).catch(p=>{this.render(),this.reportError(p);});}else this.render();e.preventDefault();return}if(this.chartDrag){let n=this.chartDrag;if(this.chartDrag=null,this.host.style.cursor="",this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),n.previewRect.x===n.startRect.x&&n.previewRect.y===n.startRect.y){this.render(),e.preventDefault();return}let r=this.chartAnchorAtIndex(n.chartIndex);if(r&&this.layout){let o=J0(this.layout,n.previewRect,r);this.runtime().moveChart(n.chartIndex,o).then(async()=>{this.render(),await this.emitChange();});}else this.render();e.preventDefault();return}if(this.resizeDrag){let n=$l(this.resizeDrag,e);this.resizeDrag=null,this.host.style.cursor="",this.hideResizeGuide(),this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),this.commitResizeDrag(n),e.preventDefault();return}if(this.autoFillDrag){let n=this.autoFillDrag;this.autoFillDrag=null,this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),n.preview?this.runtime().autoFillRange(n.source,n.preview).then(async()=>{this.selectionState=F(v({},this.selectionState),{range:n.preview}),this.render(),await this.emitChange();}):this.render(),e.preventDefault();return}this.selecting&&(this.selecting=false,this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),this.host.style.cursor="");});W(this,"handlePointerCancel",e=>{var n;((n=this.drawingDrag)==null?void 0:n.pointerId)===e.pointerId&&(this.cancelDrawingDrag(),this.render()),this.selecting=false;});W(this,"handlePointerLeave",()=>{!this.resizeDrag&&!this.autoFillDrag&&!this.chartDrag&&!this.drawingDrag&&(this.host.style.cursor="");});W(this,"handleKeyDown",e=>{if(e.defaultPrevented||e.isComposing||e.keyCode===229||this.editingCell||this.isControlEvent(e))return;let n=e.ctrlKey||e.metaKey,r=e.key.toLowerCase();if(this.selectedDrawing&&!(n&&(r==="z"||r==="y"))){r==="escape"&&(this.clearDrawingSelection(),this.render()),!n&&r!=="tab"&&e.preventDefault();return}if(n&&!e.altKey){if(r==="c"||r==="x"||r==="v"){r==="v"&&(this.nextPasteValuesOnly=e.shiftKey);return}if(r==="z"||r==="y"&&!e.shiftKey){e.preventDefault(),this.isReadOnly()||(r==="y"||e.shiftKey?this.redo():this.undo()).catch(o=>this.reportError(o));return}if(r==="a"&&!e.shiftKey){e.preventDefault(),this.selectionState=Lh(this.selectionState,this.runtime().activeSheet(),this.gridBounds()),this.render();return}if(!e.shiftKey&&(r==="b"||r==="i"||r==="u")){e.preventDefault(),this.isReadOnly()||this.formatSelection(r==="b"?"bold":r==="i"?"italic":"underline").catch(o=>this.reportError(o));return}if(!e.shiftKey&&(r==="d"||r==="r")){e.preventDefault(),this.isReadOnly()||this.fillSelectionFromEdge(r==="d"?"down":"right").catch(o=>this.reportError(o));return}if(!e.shiftKey&&(e.key==="PageUp"||e.key==="PageDown")){e.preventDefault();let o=this.runtime().model().sheets.map(a=>a.name),i=o.indexOf(this.activeSheetName())+(e.key==="PageUp"?-1:1);o[i]&&this.setActiveSheet(o[i]).catch(a=>this.reportError(a));return}}if(!e.altKey&&(e.code==="Space"||e.key===" ")&&(n||e.shiftKey)){e.preventDefault();let{row:o,column:i}=this.selectionState.active,a=this.gridBounds();this.selectionState=n&&e.shiftKey?F(v({},it(o,i)),{range:{startRow:1,startColumn:1,endRow:a.rowCount,endColumn:a.columnCount}}):n?ta(i,a):ea(o,a),this.render();return}if(e.key==="Delete"||e.key==="Backspace"){if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||this.selectedChartIndex!==null)return;e.preventDefault(),this.isReadOnly()||this.clearSelection().catch(o=>this.reportError(o));return}if(e.key==="Escape"&&(this.copiedRange||this.clipboardActive)){this.cancelCopyOutline(),this.render(),e.preventDefault();return}if(e.key==="Enter"&&!n&&!e.shiftKey&&!e.altKey&&this.clipboardActive&&this.clipboardPayload&&!this.isReadOnly()){e.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(e.key==="F2"&&!n&&!e.altKey&&!e.shiftKey){if(this.isReadOnly())return;e.preventDefault(),this.openCellEditor().catch(o=>this.reportError(o));return}if(!(n&&!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(e.key))){if(!e.altKey&&this.navigateGrid(e.key,e.shiftKey,n)){e.preventDefault();return}!n&&!e.altKey&&Array.from(e.key).length===1&&!this.isReadOnly()&&(e.preventDefault(),this.openCellEditor(e.key).catch(o=>this.reportError(o)));}});W(this,"handleKeyUp",e=>{e.key.toLowerCase()==="v"&&(this.nextPasteValuesOnly=false);});W(this,"handleCopy",e=>{var o;if(this.selectedDrawing||this.editingCell||this.isControlEvent(e)||!e.clipboardData)return;let n=We(this.selectionState.range),r=na(this.runtime().activeSheet(),n,{sourceWorkbookId:this.runtime().workbook().workbookId});this.clipboardPayload=r,this.clipboardCut=false,this.clipboardActive=true,this.copiedRange=n,(o=e.clipboardData)==null||o.setData("text/plain",r.text),e.clipboardData.setData(ur,ko(r)),e.clipboardData.setData("text/html",Tl(r)),e.preventDefault(),this.render();});W(this,"handleCut",e=>{if(!(this.selectedDrawing||this.editingCell||this.isControlEvent(e))){if(this.isReadOnly()){e.preventDefault();return}this.handleCopy(e),e.defaultPrevented&&this.clipboardPayload&&(this.clipboardCut=true);}});W(this,"handlePaste",e=>{if(this.selectedDrawing||this.editingCell||this.isControlEvent(e))return;if(this.isReadOnly()){e.preventDefault();return}let n=e.clipboardData;if(!n)return;try{if(!n.types.includes("text/plain")&&!Eo(n))return}catch(o){e.preventDefault(),this.reportError(o);return}e.preventDefault();let r=this.nextPasteValuesOnly;this.nextPasteValuesOnly=false,this.pasteClipboardData(n,r).catch(o=>this.reportError(o));});W(this,"handleContextMenu",e=>{if(!this.viewport||!this.layout)return;let n=this.eventPoint(e),r=this.drawingAtPoint(n),o=r!=null&&r.handle?null:this.chartAtPoint(n);if(o){this.clearDrawingSelection(),this.selectedChartIndex=o.chartIndex,this.hideContextMenu(),this.hideFilterMenu(),this.render(),e.preventDefault();return}if(r){this.selectedDrawing=r.target.reference,this.selectedChartIndex=null,this.hideContextMenu(),this.hideFilterMenu(),this.render(),e.preventDefault();return}this.selectedDrawing&&(this.clearDrawingSelection(),this.render());let i=this.viewport.hitTest(n);i.kind==="cell"&&!this.selectionContainsCell(i.row,i.column)&&(this.selectionState=ct(it(i.row,i.column),this.runtime().activeSheet()),this.render()),!(i.kind!=="cell"&&i.kind!=="rowHeader"&&i.kind!=="columnHeader")&&(e.preventDefault(),this.renderContextMenu(e.clientX,e.clientY,this.isReadOnly()?void 0:i.kind==="columnHeader"?i.column:void 0));});W(this,"handleDocumentPointerDown",e=>{let n=e.composedPath();n.includes(this.contextMenu)||n.includes(this.filterMenu)||(this.hideContextMenu(),this.hideFilterMenu());});W(this,"handleWheel",e=>{if(!this.runtimeValue||this.cellEditor.contains(e))return;e.preventDefault();let n=kh(this.scroll,e.deltaX,e.deltaY);this.setScroll(n.x,n.y);});var r;if(this.readOnlyValue=n.readOnly===true,e.replaceChildren(),this.renderRoot=n.styleIsolation==="none"?e:(r=e.shadowRoot)!=null?r:e.attachShadow({mode:"open"}),this.renderRoot.replaceChildren(),this.renderRoot instanceof ShadowRoot){let o=document.createElement("style");o.textContent=`
|
|
1691
|
+
`),this.handleInput()):(e.key==="Enter"||e.key==="Tab")&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&(e.preventDefault(),e.stopPropagation(),this.commit({key:e.key,reverse:e.shiftKey}).catch(n=>{var r,o;return (o=(r=this.options).onError)==null?void 0:o.call(r,n)})));});for(let n of [e.textarea,e.richInput])n.addEventListener("keydown",this.handleKeyDown),n.addEventListener("blur",this.handleBlur),n.addEventListener("input",this.handleInput);e.richInput.addEventListener("paste",this.handleRichPaste);}isRich(){return this.richRuns!==void 0}contains(e){let n=e.composedPath();return n.includes(this.options.textarea)||n.includes(this.options.richFrame)}open(e,n,r){if(this.active=true,this.richRuns=r,r){let{richFrame:i,richInput:a}=this.options;wh(a,r),this.place(e),vh(a),i.scrollTop=0,i.scrollLeft=0;return}let o=this.options.textarea;o.value=n,this.place(e),o.focus({preventScroll:true}),o.setSelectionRange(n.length,n.length);}place(e){if(!this.active)return;let n=this.richRuns?this.options.richFrame:this.options.textarea;if(!e){n.style.display="none";return}Object.assign(n.style,{display:this.richRuns?"flex":"block",left:`${e.x}px`,top:`${e.y}px`,width:`${Math.max(1,e.width)}px`,height:`${Math.max(1,e.height)}px`});}commit(e){if(!this.active)return this.pendingCommit;this.active=false;let n=this.richRuns&&xh(this.options.richInput,this.richRuns),r=n?n.map(o=>o.text).join(""):this.options.textarea.value;try{this.pendingCommit=Promise.resolve(this.options.onCommit(r,n)),e&&(this.pendingCommit=this.pendingCommit.then(()=>{var o,i;return (i=(o=this.options).onNavigate)==null?void 0:i.call(o,e.key,e.reverse)}));}catch(o){this.pendingCommit=Promise.reject(o);}return this.close(),this.pendingCommit}cancel(){var e,n;this.active=false,this.close(),(n=(e=this.options).onCancel)==null||n.call(e);}close(){this.options.textarea.style.display="none",this.options.richFrame.style.display="none",this.richRuns=void 0;}destroy(){this.active=false;for(let e of [this.options.textarea,this.options.richInput])e.removeEventListener("keydown",this.handleKeyDown),e.removeEventListener("blur",this.handleBlur),e.removeEventListener("input",this.handleInput);this.options.richInput.removeEventListener("paste",this.handleRichPaste),this.close();}};function kh(t,e,n){return {x:Math.max(0,t.x+e),y:Math.max(0,t.y+n)}}function Eh(t,e,n,r,o=12){let i=t.getColumnX(n.frozenColumns+1),a=t.getRowY(n.frozenRows+1),s=Math.max(0,e.width-t.rowHeaderWidth-i-o),l=Math.max(0,e.height-t.columnHeaderHeight-a-o),d=s,u=l,f=Math.max(0,t.totalWidth()-i),p=Math.max(0,t.totalHeight()-a);return {horizontal:Sh(f,d,s,r.x),vertical:Sh(p,u,l,r.y)}}function ia(t,e){if(t.maxScroll<=0)return 0;let n=Math.max(0,t.trackLength-t.thumbLength);return n<=0?0:Math.max(0,Math.min(n,e))/n*t.maxScroll}function Sh(t,e,n,r){let o=Math.max(0,t-e);if(n<=0||t<=0||o<=0)return {trackLength:n,thumbStart:0,thumbLength:n,maxScroll:0};let i=Math.max(24,Math.min(n,e/t*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 wP=24,xP=12,yP=4;function Ol(t,e,n){for(let r of e){if(r.kind==="columnHeaderFrozen"||r.kind==="columnHeaderScrollable"){let o=W0(t,r,n);if(o)return o}if(r.kind==="rowHeaderFrozen"||r.kind==="rowHeaderScrollable"){let o=B0(t,r,n);if(o)return o}}return null}function Ch(t,e){return H(v({},t),{startClientX:e.clientX,startClientY:e.clientY,currentSize:t.startSize,currentGuidePosition:t.guidePosition})}function $l(t,e){let n=t.kind==="column"?e.clientX-t.startClientX:e.clientY-t.startClientY,r=Math.max(t.minSize,Math.round(t.startSize+n));return H(v({},t),{currentSize:r,currentGuidePosition:t.guidePosition+r-t.startSize})}function W0(t,e,n){if(!Ih(e.screenRect,n,4))return null;for(let r=e.columns.start;r<=e.columns.end;r++){let o=t.getCellLogicalRect(1,r),a=e.screenRect.x+o.x-e.originX+o.width;if(Math.abs(n.x-a)<=4)return {kind:"column",index:r,startSize:t.getColumnWidth(r),guidePosition:a,minSize:24}}return null}function B0(t,e,n){if(!Ih(e.screenRect,n,4))return null;for(let r=e.rows.start;r<=e.rows.end;r++){let o=t.getCellLogicalRect(r,1),a=e.screenRect.y+o.y-e.originY+o.height;if(Math.abs(n.y-a)<=4)return {kind:"row",index:r,startSize:t.getRowHeight(r),guidePosition:a,minSize:12}}return null}function Ih(t,e,n=0){return e.x>=t.x-n&&e.y>=t.y-n&&e.x<=t.x+t.width+n&&e.y<=t.y+t.height+n}function CP(t,e){var o,i,a,s,l,d;let n=F0(),r=We(e.range);for(let u=r.startRow;u<=r.endRow;u++)for(let f=r.startColumn;f<=r.endColumn;f++){let p=H0(t,u,f),b=(i=t.styles.fonts[(o=p.fontId)!=null?o:0])!=null?i:{},w=(s=t.styles.fills[(a=p.fillId)!=null?a:0])!=null?s:{},g=(d=t.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,O0(p)),cn(n.vertical,$0(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 F0(){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(t,e){if(!t.hasValue){t.hasValue=true,t.value=e;return}z0(t.value,e)||(t.mixed=true);}function un(t){return t.mixed?"mixed":t.value}function H0(t,e,n){var o,i;let r=qe(t,e,n);return (i=t.styles.cellFormats[(o=r==null?void 0:r.styleId)!=null?o:0])!=null?i:{}}function O0(t){var e,n;return ((e=t.alignment)==null?void 0:e.horizontal)==="center"||((n=t.alignment)==null?void 0:n.horizontal)==="right"?t.alignment.horizontal:"left"}function $0(t){var e,n;return ((e=t.alignment)==null?void 0:e.vertical)==="top"||((n=t.alignment)==null?void 0:n.vertical)==="center"?t.alignment.vertical:"bottom"}function z0(t,e){return JSON.stringify(t!=null?t:null)===JSON.stringify(e!=null?e:null)}var aa="http://www.w3.org/2000/svg",j0=new Set(["image/png","image/jpeg","image/gif","image/webp","image/bmp","image/svg+xml"]),sa=class{constructor(e){W(this,"pkg",e);W(this,"urls",new Map);W(this,"embedded",new Map);}embeddedOnSheet(e){let n=this.embedded.get(e);if(n)return n;let r=readExcelEmbeddedObjectPreviews(this.pkg,e);return this.embedded.set(e,r),r}render(e,n,r){var a;if(e.hidden)return null;if(e.kind==="shape")return U0(e,n);if(e.kind!=="image"||e.targetMode==="External")return null;let o=e.targetPath&&this.imageUrl(e.targetPath);if(!o)return r?Nh(e.name):null;let i=document.createElement("img");return i.alt=(a=e.name)!=null?a:"",i.draggable=false,r&&i.addEventListener("error",()=>{let s=Nh(e.name);s.style.cssText+=i.style.cssText,i.replaceWith(s);},{once:true}),i.src=o,i}dispose(){for(let e of this.urls.values())URL.revokeObjectURL(e);this.urls.clear(),this.embedded.clear();}imageUrl(e){let n=this.urls.get(e);if(n)return n;let r=getPart(this.pkg,e),o=r==null?void 0:r.contentType.toLowerCase();if(!(r!=null&&r.bytes)||!o||!j0.has(o))return;let i=URL.createObjectURL(new Blob([new Uint8Array(r.bytes)],{type:o}));return this.urls.set(e,i),i}};function U0(t,{width:e,height:n}){var i,a,s;let r;switch(t.presetGeometry){case "rightArrow":case "leftArrow":{let l=e-Math.min(e,n)/2;r=document.createElementNS(aa,"path"),r.setAttribute("d",`M 0 ${n/4} H ${l} V 0 L ${e} ${n/2} L ${l} ${n} V ${n*.75} H 0 Z`),t.presetGeometry==="leftArrow"&&r.setAttribute("transform",`translate(${e} 0) scale(-1 1)`);break}case "rect":r=document.createElementNS(aa,"rect"),r.setAttribute("width",String(e)),r.setAttribute("height",String(n));break;case "ellipse":r=document.createElementNS(aa,"ellipse"),r.setAttribute("cx",String(e/2)),r.setAttribute("cy",String(n/2)),r.setAttribute("rx",String(e/2)),r.setAttribute("ry",String(n/2));break;default:return null}r.setAttribute("fill",(i=t.fillColor)!=null?i:"#4472C4"),r.setAttribute("stroke",(a=t.lineColor)!=null?a:"#2F528F"),r.setAttribute("stroke-width",String(Math.max(0,((s=t.lineWidth)!=null?s:12700)/9525)));let o=document.createElementNS(aa,"svg");return o.setAttribute("viewBox",`0 0 ${e} ${n}`),o.setAttribute("aria-hidden","true"),o.appendChild(r),o}function Nh(t){let e=document.createElement("div");Object.assign(e.style,{display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"3px",font:"10px Arial, sans-serif",color:"#1f2937"});let n=document.createElement("span");Object.assign(n.style,{background:"#107c41",color:"#fff",borderRadius:"2px",padding:"2px 5px",font:"bold 12px Arial, sans-serif"}),n.textContent=/\.xlsx?$/i.test(t!=null?t:"")?"X":"\u2197";let r=document.createElement("span");return Object.assign(r.style,{maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),r.textContent=t!=null?t:"\u5D4C\u5165\u6587\u4EF6",e.append(n,r),e}var Th=["nw","n","ne","e","se","s","sw","w"];function Ph(t,e){let r=t.x+(e.includes("w")?0:e.includes("e")?t.width:t.width/2),o=t.y+(e.includes("n")?0:e.includes("s")?t.height:t.height/2);return {x:r-8/2,y:o-8/2,width:8,height:8}}function Rh(t,e,n,r){if(!r)return H(v({},t),{x:fr(t.x+e.x,0,n.width-t.width),y:fr(t.y+e.y,0,n.height-t.height)});let o=Math.min(8,t.width),i=Math.min(8,t.height),a=t.x+t.width,s=t.y+t.height,l=r.includes("w")?fr(t.x+e.x,0,a-o):t.x,d=r.includes("n")?fr(t.y+e.y,0,s-i):t.y;return {x:l,y:d,width:(r.includes("e")?fr(a+e.x,l+o,n.width):a)-l,height:(r.includes("s")?fr(s+e.y,d+i,n.height):s)-d}}function fr(t,e,n){return Math.max(e,Math.min(n,t))}function Mh(t,e,n,r){let o=t.cssPixelsToEmu(e.x),i=t.cssPixelsToEmu(e.y),a=t.cssPixelsToEmu(e.width),s=t.cssPixelsToEmu(e.height),l=(p,b,w=-1/0)=>p===void 0?void 0:Math.max(w,p+t.cssPixelsToEmu(b)),d=r.transform&&{x:l(r.transform.x,e.x-n.x),y:l(r.transform.y,e.y-n.y),width:l(r.transform.width,e.width-n.width,1),height:l(r.transform.height,e.height-n.height,1)};if(r.kind==="absolute")return {kind:"absolute",x:o,y:i,width:a,height:s,transform:d};let u=Io(t,e.x,e.y);if(r.kind==="oneCell")return {kind:"oneCell",from:u,width:a,height:s,transform:d};let f=Io(t,e.x+e.width,e.y+e.height);return {kind:"twoCell",from:u,to:f,transform:d}}function Io(t,e,n){let r=t.columnAt(Math.max(0,e)),o=t.rowAt(Math.max(0,n));return {column:r-1,row:o-1,columnOffset:t.cssPixelsToEmu(e-t.getColumnX(r)),rowOffset:t.cssPixelsToEmu(n-t.getRowY(o))}}function Ah(t,e,n,r,o){var b,w,g;let i=We(t.range),a=t.active,s=(b=t.focus)!=null?b:{row:i.endRow===a.row?i.startRow:i.endRow,column:i.endColumn===a.column?i.startColumn:i.endColumn},l=n.shift&&e!=="Tab"&&e!=="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]}[e];if(!u&&e!=="Home"&&!(e==="End"&&n.command))return null;let f=l.row,p=l.column;if(e==="Home")p=1,n.command&&(f=1);else if(e==="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&&e.startsWith("Arrow")){let h=u,x=h[0]?o.rowCount:o.columnCount,S=h[0]?f:p,k=h[0]||h[1],I=F=>{let A=r.cellsByAddress.get(formatCellAddress(h[0]?F:f,h[1]?F:p));return !!(A!=null&&A.formula)||(A==null?void 0:A.value)!==void 0&&A.value!==null&&A.value!==""},D=Math.max(1,Math.min(x,S+k));if(I(S)&&I(D))for(;D+k>=1&&D+k<=x&&I(D+k);)D+=k;else for(;D>1&&D<x&&!I(D);)D+=k;h[0]?f=D:p=D;}else {let h=[...r.mergeMasterByAddress.values()].find(x=>f>=x.range.startRow&&f<=x.range.endRow&&p>=x.range.startColumn&&p<=x.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]),(e==="Tab"||e==="Enter")&&(i.startRow!==i.endRow||i.startColumn!==i.endColumn)&&!h)return e==="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:t.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&&e!=="Tab"&&e!=="Enter"?H(v({},ct(cr(t,f,p,o),r)),{focus:{row:f,column:p}}):ct(it(f,p),r)}function Lh(t,e,n){let{row:r,column:o}=t.active,i=[...e.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=We(t.range),u=Object.keys(a).every(f=>a[f]===d[f]);return ct({kind:"cell",active:t.active,range:l||u?{startRow:1,startColumn:1,endRow:n.rowCount,endColumn:n.columnCount}:a},e)}var la=class{constructor(e,n){W(this,"host",e);W(this,"element",document.createElement("div"));W(this,"anchor",null);W(this,"handleOutsideInteraction",e=>{let n=e.composedPath();!n.includes(this.element)&&(!this.anchor||!n.includes(this.anchor))&&this.hide(false);});W(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(e,n){if(this.anchor===e){this.hide();return}this.hide(false),this.anchor=e,e.setAttribute("aria-expanded","true"),e.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 e=this.host.getBoundingClientRect(),n=this.anchor.getBoundingClientRect(),r=this.element.getBoundingClientRect();this.element.style.left=`${Math.max(4,Math.min(n.left-e.left,e.width-r.width-4))}px`,this.element.style.top=`${Math.max(4,n.top-e.top-r.height-6)}px`;}hide(e=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),e&&(n!=null&&n.isConnected)&&n.focus({preventScroll:true});}destroy(){this.hide(false),this.element.remove();}button(e,n){let r=document.createElement("button");return r.type="button",r.textContent=e,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 sR(t,e,n={}){let r=new jl(t,n);return await r.loadWorkbook(e),r}var jl=class{constructor(e,n){W(this,"host",e);W(this,"options",n);W(this,"renderRoot");W(this,"runtimeValue",null);W(this,"renderer",null);W(this,"layout",null);W(this,"viewport",null);W(this,"scroll",{x:0,y:0});W(this,"scrollbarState",null);W(this,"listeners",new Set);W(this,"stateListeners",new Set);W(this,"baseCanvas",document.createElement("canvas"));W(this,"headerCanvas",document.createElement("canvas"));W(this,"overlayCanvas",document.createElement("canvas"));W(this,"unsupportedObjectLayer",document.createElement("div"));W(this,"drawingPreviews",null);W(this,"drawingHits",[]);W(this,"selectedDrawing",null);W(this,"drawingDrag",null);W(this,"suppressGridClick",false);W(this,"workbookLoadId",0);W(this,"sheetTabs",document.createElement("div"));W(this,"horizontalScrollbar",document.createElement("div"));W(this,"verticalScrollbar",document.createElement("div"));W(this,"horizontalThumb",document.createElement("div"));W(this,"verticalThumb",document.createElement("div"));W(this,"cellEditorElement",document.createElement("textarea"));W(this,"richEditorFrame",document.createElement("div"));W(this,"richEditorInput",document.createElement("div"));W(this,"resizeGuide",document.createElement("div"));W(this,"contextMenu",document.createElement("div"));W(this,"filterMenu",document.createElement("div"));W(this,"sheetDeleteConfirmation");W(this,"cellEditor");W(this,"resizeObserver");W(this,"disposed",false);W(this,"drag",null);W(this,"selectionState",it(1,1));W(this,"editingCell",null);W(this,"editingCellInitialValue",null);W(this,"pendingGridMutation",Promise.resolve());W(this,"editingCellStyle",null);W(this,"clipboardPayload",null);W(this,"clipboardCut",false);W(this,"clipboardActive",false);W(this,"nextPasteValuesOnly",false);W(this,"selecting",false);W(this,"resizeDrag",null);W(this,"autoFillDrag",null);W(this,"selectedChartIndex",null);W(this,"chartDrag",null);W(this,"columnFilters",new Map);W(this,"filterMenuColumn",null);W(this,"copiedRange",null);W(this,"formulaReferenceRanges",[]);W(this,"lastStateKey","");W(this,"transactionDepth",0);W(this,"transactionChanged",false);W(this,"readOnlyValue");W(this,"sheetActionPending",false);W(this,"handleClick",e=>{if(this.suppressGridClick){this.suppressGridClick=false,e.preventDefault();return}if(this.eventPathContains(e,this.contextMenu)||this.eventPathContains(e,this.filterMenu))return;if(this.filterMenu.style.display==="block"&&this.hideFilterMenu(),this.editingCell){if(this.cellEditor.contains(e))return;this.cellEditor.commit().catch(a=>this.reportError(a));}if(!this.viewport||!this.layout)return;let n=this.eventPoint(e),r=this.drawingAtPoint(n),o=r!=null&&r.handle?null:this.chartAtPoint(n);if(o){this.clearDrawingSelection(),this.selectedChartIndex=o.chartIndex,this.render(),e.preventDefault();return}if(this.selectedChartIndex=null,r){this.selectedDrawing=r.target.reference,this.host.focus({preventScroll:true}),this.render(),e.preventDefault();return}this.clearDrawingSelection();let i=this.viewport.hitTest(n);if(!(i.kind!=="cell"&&i.kind!=="rowHeader"&&i.kind!=="columnHeader")){if(i.kind==="cell"&&i.row===1&&this.isFilterIconHit(i.column,e)){if(this.isReadOnly())return;this.openFilterMenu(i.column,e.clientX,e.clientY),e.preventDefault();return}if(i.kind==="cell"){let a=this.runtime().activeSheet();this.selectionState=ct(it(i.row,i.column),a);}this.host.focus(),this.render();}});W(this,"handleFilterMenuClick",e=>{var i;if(this.isReadOnly()){this.hideFilterMenu();return}let r=(i=e.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();});W(this,"handleDoubleClick",e=>{if(!this.viewport||!this.layout||this.cellEditor.contains(e))return;let n=this.eventPoint(e);if(this.drawingAtPoint(n))return;let r=this.viewport.hitTest(n);if(r.kind==="cell"){if(this.selectionState=ct(it(r.row,r.column),this.runtime().activeSheet()),this.isReadOnly()){this.render();return}this.openCellEditor().catch(o=>this.reportError(o)),e.preventDefault();}});W(this,"handlePointerDown",e=>{var u,f;if(this.drawingDrag)return;if(this.suppressGridClick=false,this.editingCell){if(this.cellEditor.contains(e))return;this.cellEditor.commit().catch(p=>this.reportError(p));}if(e.button!==0||!this.viewport||!this.layout)return;let n=this.eventPoint(e),r=this.drawingAtPoint(n),o=r!=null&&r.handle?null:this.chartAtPoint(n);if(o){if(this.clearDrawingSelection(),this.selectedChartIndex=o.chartIndex,this.isReadOnly()){this.render(),e.preventDefault();return}this.chartDrag={chartIndex:o.chartIndex,pointer:n,startRect:o.logicalRect,previewRect:o.logicalRect},this.host.setPointerCapture(e.pointerId),this.render(),e.preventDefault();return}if(this.selectedChartIndex=null,r&&!this.isReadOnly()){let{target:p,handle:b}=r;this.selectedDrawing=p.reference,this.drawingDrag={target:p,handle:b,pointerId:e.pointerId,startScreen:n,startPoint:(u=Bh(this.viewport,n))!=null?u:n,previewRect:p.rect},this.suppressGridClick=true,this.host.focus({preventScroll:true}),this.host.setPointerCapture(e.pointerId),this.host.style.cursor=b?`${b}-resize`:"grabbing",this.render(),e.preventDefault();return}this.clearDrawingSelection();let i=Ol(this.layout,this.viewport.viewports,n);if(i&&!this.isReadOnly()){this.resizeDrag=Ch(i,e),this.host.setPointerCapture(e.pointerId),this.host.style.cursor=i.kind==="column"?"col-resize":"row-resize",this.updateResizeGuide(this.resizeDrag),e.preventDefault();return}let a=We(this.selectionState.range),s=(f=this.renderer)==null?void 0:f.fillHandleRect(this.layout,this.viewport,a);if(!this.isReadOnly()&&s&&zl(s,n)&&Al(this.runtime().activeSheet(),a)){this.autoFillDrag={source:a,preview:null},this.host.setPointerCapture(e.pointerId),e.preventDefault();return}let l=this.viewport.hitTest(n);if(l.kind!=="cell"&&l.kind!=="rowHeader"&&l.kind!=="columnHeader")return;this.host.focus({preventScroll:true});let d=this.runtime().activeSheet();l.kind==="cell"?this.selectionState=ct(it(l.row,l.column),d):l.kind==="rowHeader"?this.selectionState=ea(l.row,{columnCount:this.layout.columnCount}):this.selectionState=ta(l.column,{rowCount:this.layout.rowCount}),this.selecting=true,this.host.setPointerCapture(e.pointerId),this.render(),e.preventDefault();});W(this,"handlePointerMove",e=>{if(!this.viewport||!this.layout)return;if(this.drawingDrag){if(this.drawingDrag.pointerId!==e.pointerId)return;this.drawingDrag.previewRect=this.drawingDragRect(this.drawingDrag,this.eventPoint(e)),this.render(),e.preventDefault();return}if(this.chartDrag){let a=this.eventPoint(e),s=a.x-this.chartDrag.pointer.x,l=a.y-this.chartDrag.pointer.y;this.chartDrag.previewRect=H(v({},this.chartDrag.startRect),{x:Math.max(0,this.chartDrag.startRect.x+s),y:Math.max(0,this.chartDrag.startRect.y+l)}),this.host.style.cursor="grabbing",this.render(),e.preventDefault();return}if(!this.resizeDrag&&!this.autoFillDrag&&!this.selecting&&!this.editingCell){let a=this.eventPoint(e),s=this.drawingAtPoint(a),l=this.isReadOnly()||s?null:Ol(this.layout,this.viewport.viewports,a);this.host.style.cursor=s?s.handle?`${s.handle}-resize`:"move":l?l.kind==="column"?"col-resize":"row-resize":"";}if(this.resizeDrag){this.resizeDrag=$l(this.resizeDrag,e),this.updateResizeGuide(this.resizeDrag);return}if(this.autoFillDrag){let a=this.viewport.hitTest(this.eventPoint(e));this.autoFillDrag.preview=tk(this.autoFillDrag.source,a),this.render(),e.preventDefault();return}if(!this.selecting)return;let n=this.viewport.hitTest(this.eventPoint(e));if(n.kind==="none"||n.kind==="corner")return;let r=this.runtime().activeSheet(),o=this.selectionState.range;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}));let i=this.selectionState.range;(i.startRow!==o.startRow||i.endRow!==o.endRow||i.startColumn!==o.startColumn||i.endColumn!==o.endColumn)&&(this.suppressGridClick=true),this.render(),e.preventDefault();});W(this,"handlePointerUp",e=>{if(this.drawingDrag){let n=this.drawingDrag;if(n.pointerId!==e.pointerId)return;let r=this.drawingDragRect(n,this.eventPoint(e));this.cancelDrawingDrag();let o=n.target.rect;if(this.layout&&!this.isReadOnly()&&(r.x!==o.x||r.y!==o.y||r.width!==o.width||r.height!==o.height)){let i=this.layout,a=this.runtime(),{sheetId:s,drawingIndex:l,anchorIndex:d}=n.target.reference,u=Mh(i,r,o,n.target.anchor);this.queueGridMutation(async()=>{this.disposed||this.isReadOnly()||this.runtimeValue!==a||a.activeSheet().source.id!==s||(await a.setDrawingPosition(s,l,d,u),this.render(),await this.emitChange());}).catch(f=>{this.render(),this.reportError(f);});}else this.render();e.preventDefault();return}if(this.chartDrag){let n=this.chartDrag;if(this.chartDrag=null,this.host.style.cursor="",this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),n.previewRect.x===n.startRect.x&&n.previewRect.y===n.startRect.y){this.render(),e.preventDefault();return}let r=this.chartAnchorAtIndex(n.chartIndex);if(r&&this.layout){let o=J0(this.layout,n.previewRect,r);this.runtime().moveChart(n.chartIndex,o).then(async()=>{this.render(),await this.emitChange();});}else this.render();e.preventDefault();return}if(this.resizeDrag){let n=$l(this.resizeDrag,e);this.resizeDrag=null,this.host.style.cursor="",this.hideResizeGuide(),this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),this.commitResizeDrag(n),e.preventDefault();return}if(this.autoFillDrag){let n=this.autoFillDrag;this.autoFillDrag=null,this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.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(),e.preventDefault();return}this.selecting&&(this.selecting=false,this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),this.host.style.cursor="");});W(this,"handlePointerCancel",e=>{var n;((n=this.drawingDrag)==null?void 0:n.pointerId)===e.pointerId&&(this.cancelDrawingDrag(),this.render()),this.selecting=false;});W(this,"handlePointerLeave",()=>{!this.resizeDrag&&!this.autoFillDrag&&!this.chartDrag&&!this.drawingDrag&&(this.host.style.cursor="");});W(this,"handleKeyDown",e=>{if(e.defaultPrevented||e.isComposing||e.keyCode===229||this.editingCell||this.isControlEvent(e))return;let n=e.ctrlKey||e.metaKey,r=e.key.toLowerCase();if(this.selectedDrawing&&!(n&&(r==="z"||r==="y"))){r==="escape"&&(this.clearDrawingSelection(),this.render()),!n&&r!=="tab"&&e.preventDefault();return}if(n&&!e.altKey){if(r==="c"||r==="x"||r==="v"){r==="v"&&(this.nextPasteValuesOnly=e.shiftKey);return}if(r==="z"||r==="y"&&!e.shiftKey){e.preventDefault(),this.isReadOnly()||(r==="y"||e.shiftKey?this.redo():this.undo()).catch(o=>this.reportError(o));return}if(r==="a"&&!e.shiftKey){e.preventDefault(),this.selectionState=Lh(this.selectionState,this.runtime().activeSheet(),this.gridBounds()),this.render();return}if(!e.shiftKey&&(r==="b"||r==="i"||r==="u")){e.preventDefault(),this.isReadOnly()||this.formatSelection(r==="b"?"bold":r==="i"?"italic":"underline").catch(o=>this.reportError(o));return}if(!e.shiftKey&&(r==="d"||r==="r")){e.preventDefault(),this.isReadOnly()||this.fillSelectionFromEdge(r==="d"?"down":"right").catch(o=>this.reportError(o));return}if(!e.shiftKey&&(e.key==="PageUp"||e.key==="PageDown")){e.preventDefault();let o=this.runtime().model().sheets.map(a=>a.name),i=o.indexOf(this.activeSheetName())+(e.key==="PageUp"?-1:1);o[i]&&this.setActiveSheet(o[i]).catch(a=>this.reportError(a));return}}if(!e.altKey&&(e.code==="Space"||e.key===" ")&&(n||e.shiftKey)){e.preventDefault();let{row:o,column:i}=this.selectionState.active,a=this.gridBounds();this.selectionState=n&&e.shiftKey?H(v({},it(o,i)),{range:{startRow:1,startColumn:1,endRow:a.rowCount,endColumn:a.columnCount}}):n?ta(i,a):ea(o,a),this.render();return}if(e.key==="Delete"||e.key==="Backspace"){if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||this.selectedChartIndex!==null)return;e.preventDefault(),this.isReadOnly()||this.clearSelection().catch(o=>this.reportError(o));return}if(e.key==="Escape"&&(this.copiedRange||this.clipboardActive)){this.cancelCopyOutline(),this.render(),e.preventDefault();return}if(e.key==="Enter"&&!n&&!e.shiftKey&&!e.altKey&&this.clipboardActive&&this.clipboardPayload&&!this.isReadOnly()){e.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(e.key==="F2"&&!n&&!e.altKey&&!e.shiftKey){if(this.isReadOnly())return;e.preventDefault(),this.openCellEditor().catch(o=>this.reportError(o));return}if(!(n&&!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(e.key))){if(!e.altKey&&this.navigateGrid(e.key,e.shiftKey,n)){e.preventDefault();return}!n&&!e.altKey&&Array.from(e.key).length===1&&!this.isReadOnly()&&(e.preventDefault(),this.openCellEditor(e.key).catch(o=>this.reportError(o)));}});W(this,"handleKeyUp",e=>{e.key.toLowerCase()==="v"&&(this.nextPasteValuesOnly=false);});W(this,"handleCopy",e=>{var o;if(this.selectedDrawing||this.editingCell||this.isControlEvent(e)||!e.clipboardData)return;let n=We(this.selectionState.range),r=na(this.runtime().activeSheet(),n,{sourceWorkbookId:this.runtime().workbook().workbookId});this.clipboardPayload=r,this.clipboardCut=false,this.clipboardActive=true,this.copiedRange=n,(o=e.clipboardData)==null||o.setData("text/plain",r.text),e.clipboardData.setData(ur,ko(r)),e.clipboardData.setData("text/html",Tl(r)),e.preventDefault(),this.render();});W(this,"handleCut",e=>{if(!(this.selectedDrawing||this.editingCell||this.isControlEvent(e))){if(this.isReadOnly()){e.preventDefault();return}this.handleCopy(e),e.defaultPrevented&&this.clipboardPayload&&(this.clipboardCut=true);}});W(this,"handlePaste",e=>{if(this.selectedDrawing||this.editingCell||this.isControlEvent(e))return;if(this.isReadOnly()){e.preventDefault();return}let n=e.clipboardData;if(!n)return;try{if(!n.types.includes("text/plain")&&!Eo(n))return}catch(o){e.preventDefault(),this.reportError(o);return}e.preventDefault();let r=this.nextPasteValuesOnly;this.nextPasteValuesOnly=false,this.pasteClipboardData(n,r).catch(o=>this.reportError(o));});W(this,"handleContextMenu",e=>{if(!this.viewport||!this.layout)return;let n=this.eventPoint(e),r=this.drawingAtPoint(n),o=r!=null&&r.handle?null:this.chartAtPoint(n);if(o){this.clearDrawingSelection(),this.selectedChartIndex=o.chartIndex,this.hideContextMenu(),this.hideFilterMenu(),this.render(),e.preventDefault();return}if(r){this.selectedDrawing=r.target.reference,this.selectedChartIndex=null,this.hideContextMenu(),this.hideFilterMenu(),this.render(),e.preventDefault();return}this.selectedDrawing&&(this.clearDrawingSelection(),this.render());let i=this.viewport.hitTest(n);i.kind==="cell"&&!this.selectionContainsCell(i.row,i.column)&&(this.selectionState=ct(it(i.row,i.column),this.runtime().activeSheet()),this.render()),!(i.kind!=="cell"&&i.kind!=="rowHeader"&&i.kind!=="columnHeader")&&(e.preventDefault(),this.renderContextMenu(e.clientX,e.clientY,this.isReadOnly()?void 0:i.kind==="columnHeader"?i.column:void 0));});W(this,"handleDocumentPointerDown",e=>{let n=e.composedPath();n.includes(this.contextMenu)||n.includes(this.filterMenu)||(this.hideContextMenu(),this.hideFilterMenu());});W(this,"handleWheel",e=>{if(!this.runtimeValue||this.cellEditor.contains(e))return;e.preventDefault();let n=kh(this.scroll,e.deltaX,e.deltaY);this.setScroll(n.x,n.y);});var r;if(this.readOnlyValue=n.readOnly===true,e.replaceChildren(),this.renderRoot=n.styleIsolation==="none"?e:(r=e.shadowRoot)!=null?r:e.attachShadow({mode:"open"}),this.renderRoot.replaceChildren(),this.renderRoot instanceof ShadowRoot){let o=document.createElement("style");o.textContent=`
|
|
1677
1692
|
:host { display: block; position: relative; min-width: 0; min-height: 0; }
|
|
1678
1693
|
*, *::before, *::after { box-sizing: border-box; }
|
|
1679
1694
|
button, input, textarea, select { font: 13px Arial, sans-serif; line-height: normal; }
|
|
1680
1695
|
button { margin: 0; }
|
|
1681
|
-
`,this.renderRoot.appendChild(o);}e.classList.add("coco-spreadsheet-editor-host"),Object.assign(e.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.richEditorFrame.className="coco-spreadsheet-rich-editor",Object.assign(this.richEditorFrame.style,{position:"absolute",zIndex:"20",display:"none",flexDirection:"column",boxSizing:"border-box",border:"2px solid #2563eb",padding:"2px 4px",overflow:"auto"}),this.richEditorInput.className="coco-spreadsheet-rich-editor-input",this.richEditorInput.setAttribute("contenteditable","true"),this.richEditorInput.setAttribute("role","textbox"),this.richEditorInput.setAttribute("aria-label","\u7F16\u8F91\u5355\u5143\u683C"),this.richEditorInput.setAttribute("aria-multiline","true"),this.richEditorInput.setAttribute("tabindex","-1"),Object.assign(this.richEditorInput.style,{outline:"none",whiteSpace:"pre-wrap",overflowWrap:"anywhere",flexShrink:"0",minHeight:"1em"}),this.richEditorFrame.appendChild(this.richEditorInput),this.renderRoot.appendChild(this.richEditorFrame),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 la(e,this.renderRoot),this.cellEditor=new oa({textarea:this.cellEditorElement,richFrame:this.richEditorFrame,richInput:this.richEditorInput,onCommit:async(o,i)=>this.commitCellEdit(o,i),onInput:o=>{this.editingCell&&(this.formulaReferenceRanges=Fh(o),this.render());},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.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}),e.addEventListener("wheel",this.handleWheel,{passive:false}),e.addEventListener("click",this.handleClick),e.addEventListener("dblclick",this.handleDoubleClick),e.addEventListener("pointerdown",this.handlePointerDown),e.addEventListener("pointermove",this.handlePointerMove),e.addEventListener("pointerup",this.handlePointerUp),e.addEventListener("pointercancel",this.handlePointerCancel),e.addEventListener("pointerleave",this.handlePointerLeave),e.addEventListener("keydown",this.handleKeyDown),e.addEventListener("keyup",this.handleKeyUp),e.addEventListener("copy",this.handleCopy),e.addEventListener("cut",this.handleCut),e.addEventListener("paste",this.handlePaste),e.addEventListener("contextmenu",this.handleContextMenu),document.addEventListener("pointerdown",this.handleDocumentPointerDown),this.filterMenu.addEventListener("click",this.handleFilterMenuClick),e.tabIndex=0,this.resizeObserver=new ResizeObserver(()=>this.render()),this.resizeObserver.observe(e);}runtime(){if(!this.runtimeValue)throw new Error("SpreadsheetEditor: workbook is not loaded");return this.runtimeValue}isReadOnly(){return this.readOnlyValue}setReadOnly(e){var n;this.disposed||this.isReadOnly()===e||(this.cellEditor.cancel(),this.resizeDrag=null,this.autoFillDrag=null,this.chartDrag=null,this.clearDrawingSelection(),this.selecting=false,this.hideResizeGuide(),this.hideContextMenu(),this.hideFilterMenu(),(n=this.runtimeValue)==null||n.setReadOnly(e),this.readOnlyValue=e,this.host.setAttribute("aria-readonly",String(e)),this.renderTabs(),this.render());}selection(){return this.selectionState}cellState(e){var i,a,s,l;let n=this.runtime().activeSheet(),r=n.cellsByAddress.get(e);if(!r){let d=e.match(/^([A-Z]+)(\d+)$/i);if(!d)throw new Error(`SpreadsheetEditor: invalid cell address ${e}`);let u=Q0(d[1]),p=Number(d[2]);return {address:e.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 qi(this.runtime().activeSheet().source)}filterState(){return new Map([...this.columnFilters.entries()].map(([e,n])=>[e,[...n]]))}activeSheetName(){return this.runtime().activeSheetName()}setActiveSheet(e){return this.queueGridMutation(async()=>{await this.runtime().setActiveSheet(e),this.clearDrawingSelection(),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(e){await this.flushEdits(),await this.runtime().addSheet(e),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async renameSheet(e,n){await this.flushEdits(),await this.runtime().renameSheet(e,n),this.copiedRange=null,this.renderTabs(),this.render(),await this.emitChange();}async copySheet(e,n){await this.flushEdits(),await this.runtime().copySheet(e,n),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async deleteSheet(e){await this.flushEdits(),await this.runtime().deleteSheet(e),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(e,n){await this.flushEdits(),await this.runtime().moveSheet(e,n),this.copiedRange=null,this.renderTabs(),this.render(),await this.emitChange();}async setCellValue(e,n){await this.flushEdits(),await this.runtime().setCellValue(e,n,{mergeUndo:true}),this.render(),await this.emitChange();}async setCellFormula(e,n){await this.flushEdits(),await this.runtime().setCellFormula(e,n,{mergeUndo:true}),this.render(),await this.emitChange();}formatSelection(e){let n=We(this.selectionState.range),r=formatCellAddress(this.selectionState.active.row,this.selectionState.active.column);return this.queueGridMutation(async()=>this.applyFormat(e,n,r))}async setSelectionFontColor(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeFontColor(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async setSelectionFillColor(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeFillColor(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async setSelectionHorizontalAlign(e){await this.flushEdits(),await this.applyAlignment(e);}async setSelectionVerticalAlign(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeVerticalAlign(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async setSelectionNumberFormat(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeNumberFormat(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async setSelectionBorder(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeBorder(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async loadWorkbook(e){var d,u;this.assertAlive();let n=++this.workbookLoadId;if(await this.flushEdits(),this.disposed||n!==this.workbookLoadId)return;let r=this.runtimeValue;this.runtimeValue=null,this.clearDrawingSelection(),(d=this.drawingPreviews)==null||d.dispose(),this.drawingPreviews=null,this.copiedRange=null,this.clipboardPayload=null,this.clipboardCut=false,this.clipboardActive=false,this.scroll={x:0,y:0},r&&await r.dispose();let o=await fromZip(e);if(this.disposed||n!==this.workbookLoadId)return;let i=ExcelWorkbook.fromPackage(o,{workbookId:this.options.workbookId,mode:"inline"}),a=await ra.fromWorkbook(i,{readOnly:this.readOnlyValue});if(this.disposed||n!==this.workbookLoadId){await a.dispose();return}this.runtimeValue=a,this.drawingPreviews=new sa(o);let s=this.runtimeValue.activeSheet();this.selectionState=ct(it(1,1),s);let l=new Set(s.styles.cellFormats.map((p,f)=>wo(s.styles,f).font));for(let p of a.model().sheets)for(let f of p.cells)for(let b of (u=f.richText)!=null?u:[])l.add(xo(s.styles,f.styleId,b).font);await Dr(l),!(this.disposed||n!==this.workbookLoadId)&&(this.host.setAttribute("aria-readonly",String(this.isReadOnly())),this.renderTabs(),this.render());}async toZip(){return await this.flushEdits(),this.runtime().toZip()}async flushEdits(){let e=this.pendingGridMutation;await this.cellEditor.commit(),await e;}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(e){return this.listeners.add(e),()=>this.listeners.delete(e)}subscribeState(e){return this.stateListeners.add(e),()=>this.stateListeners.delete(e)}async runTransaction(e,n){await this.flushEdits(),this.transactionDepth+=1;try{await this.runtime().runUserTransaction(e,()=>n(this));}finally{this.transactionDepth-=1,this.transactionDepth===0&&this.transactionChanged&&(this.transactionChanged=false,this.render(),await this.emitChange());}}destroy(){var r;if(this.disposed)return;let e=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("pointercancel",this.handlePointerCancel),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.clearDrawingSelection(),(r=this.drawingPreviews)==null||r.dispose(),this.drawingPreviews=null,this.unsupportedObjectLayer.remove(),this.host.replaceChildren();let n=this.runtimeValue;e.catch(o=>this.reportError(o)).finally(()=>{this.runtimeValue=null,n==null||n.dispose();});}render(){var p;let e=this.runtimeValue,n=this.renderer;if(!e||!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 ji(e.activeSheet(),{maximumDigitWidth:ek(e.activeSheet(),this.baseCanvas)}),s={width:Math.max(1,o-12),height:Math.max(1,i-12)},l=new _i(a,{viewportSize:s,scroll:this.scroll,freeze:qi(e.activeSheet().source)});this.layout=a,this.viewport=l,this.scroll=l.scroll,this.scrollbarState=Eh(a,s,qi(e.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=We(this.selectionState.range);n.renderSelection(a,l,u,{showFillHandle:!this.isReadOnly()&&Al(e.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(e.activeSheetName()),this.updateScrollbars();}renderDrawingOverlays(e,n){var i,a,s;this.unsupportedObjectLayer.replaceChildren(),this.drawingHits=[];let r=(i=this.runtimeValue)==null?void 0:i.activeSheet().source;if(!r)return;this.selectedDrawing&&this.selectedDrawing.sheetId!==r.id&&this.clearDrawingSelection();for(let[l,d]of r.drawings.entries())for(let[u,p]of d.anchors.entries()){let f=Y0(p);if(!f){this.renderDrawingPreview(p,e,n,{sheetId:r.id,drawingIndex:l,anchorIndex:u});continue}let b=da(e,p);if(b)for(let w of pr(b,n)){let g=document.createElement("div");g.setAttribute("aria-hidden","true"),Object.assign(g.style,v({position:"absolute",left:`${w.x}px`,top:`${w.y}px`,width:`${Math.max(1,w.width)}px`,height:`${Math.max(1,w.height)}px`,boxSizing:"border-box",pointerEvents:"none",opacity:f.dash==="dashed"?"0.72":"1"},f.orientation==="horizontal"?{borderTop:`1px ${f.dash} #4F9185`}:{borderLeft:`1px ${f.dash} #4F9185`})),this.unsupportedObjectLayer.appendChild(g);}}if(r.path&&this.drawingPreviews)for(let l of this.drawingPreviews.embeddedOnSheet(r.path))this.renderDrawingPreview(l,e,n);for(let l=0;l<r.charts.length;l+=1){let d=r.charts[l];if(!d)continue;let u=Gl(r.drawings,d),p=((a=this.chartDrag)==null?void 0:a.chartIndex)===l?this.chartDrag.previewRect:da(e,u);if(p)for(let f of pr(p,n)){let b=document.createElement("div");b.className="coco-spreadsheet-unsupported-chart",Object.assign(b.style,{position:"absolute",left:`${f.x}px`,top:`${f.y}px`,width:`${Math.max(1,f.width)}px`,height:`${Math.max(1,f.height)}px`,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"6px",padding:"12px",boxSizing:"border-box",overflow:"hidden",background:"rgba(248, 250, 252, 0.94)",color:"#475569",textAlign:"center",font:"13px Arial, sans-serif",lineHeight:"1.4",cursor:this.isReadOnly()?"default":((s=this.chartDrag)==null?void 0:s.chartIndex)===l?"grabbing":"move",border:this.selectedChartIndex===l?"2px solid #2563eb":"1px dashed #94a3b8",boxShadow:this.selectedChartIndex===l?"0 0 0 1px rgba(37, 99, 235, 0.18)":"none"});let w=document.createElement("strong");w.textContent=d.title?`\u56FE\u8868\uFF1A${d.title}`:"\u56FE\u8868",w.style.color="#334155";let g=document.createElement("span");g.textContent="\u5F53\u524D\u7F16\u8F91\u5668\u6682\u4E0D\u652F\u6301\u56FE\u8868\u6E32\u67D3";let h=document.createElement("span");h.textContent="\u8BF7\u4F7F\u7528 Excel \u6216 WPS \u6253\u5F00\u6587\u4EF6\u67E5\u770B",b.append(w,g,h),this.unsupportedObjectLayer.appendChild(b);}}let o=this.drawingHits.find(({target:l})=>Wh(l.reference,this.selectedDrawing));o&&this.renderDrawingSelection(o.target,n);}renderDrawingPreview(e,n,r,o){if(!this.drawingPreviews||!e.object)return;let i=this.drawingDrag,a=o&&i&&Wh(o,i.target.reference)?i.previewRect:Z0(n,e);if(!a)return;let s=o&&!this.isReadOnly()?{reference:o,anchor:e,rect:a}:null;for(let l of pr(a,r)){let d=this.drawingPreviews.render(e.object,a,!o);if(!d)return;let u=document.createElement("div");u.className="coco-spreadsheet-drawing-preview",Object.assign(u.style,Vl(l),{overflow:"hidden"}),Object.assign(d.style,{position:"absolute",maxWidth:"none",left:`${-l.clipLeft}px`,top:`${-l.clipTop}px`,width:`${a.width}px`,height:`${a.height}px`}),u.appendChild(d),this.unsupportedObjectLayer.appendChild(u),s&&this.drawingHits.push({target:s,screenRect:l});}}renderDrawingSelection(e,n){let{rect:r}=e;for(let o of pr(r,n)){let i=document.createElement("div");i.className="coco-spreadsheet-drawing-selection",Object.assign(i.style,Vl(o),{boxSizing:"border-box",border:"1px solid #2563eb",borderLeftWidth:o.clipLeft>0?"0":"1px",borderTopWidth:o.clipTop>0?"0":"1px",borderRightWidth:o.clipLeft+o.width<r.width?"0":"1px",borderBottomWidth:o.clipTop+o.height<r.height?"0":"1px"}),this.unsupportedObjectLayer.appendChild(i);}for(let o of Th)for(let i of pr(Ph(r,o),n)){let a=document.createElement("div");a.className="coco-spreadsheet-drawing-resize-handle",a.dataset.handle=o,Object.assign(a.style,Vl(i),{boxSizing:"border-box",border:"1px solid #2563eb",background:"#fff"}),this.unsupportedObjectLayer.appendChild(a),this.drawingHits.push({target:e,screenRect:i,handle:o});}}drawingAtPoint(e){for(let n=this.drawingHits.length-1;n>=0;n--){let r=this.drawingHits[n];if(zl(r.screenRect,e))return r}}clearDrawingSelection(){this.selectedDrawing=null,this.cancelDrawingDrag();}cancelDrawingDrag(){let e=this.drawingDrag;e&&(this.drawingDrag=null,this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),this.host.style.cursor="");}drawingDragRect(e,n){let r=this.layout,o=Bh(this.viewport,n),i=o?{x:o.x-e.startPoint.x,y:o.y-e.startPoint.y}:{x:n.x-e.startScreen.x,y:n.y-e.startScreen.y};return Rh(e.target.rect,i,{width:r.totalWidth(),height:r.totalHeight()},e.handle)}chartAnchorAtIndex(e){var o;let n=(o=this.runtimeValue)==null?void 0:o.activeSheet().source,r=n==null?void 0:n.charts[e];return r?Gl(n.drawings,r):void 0}chartAtPoint(e){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=Gl(n.drawings,i),s=da(this.layout,a);if(s&&pr(s,this.viewport).some(l=>zl(l,e)))return {chartIndex:o,logicalRect:s}}return null}updateResizeGuide(e){e.kind==="column"?Object.assign(this.resizeGuide.style,{display:"block",left:`${Math.round(e.currentGuidePosition)}px`,top:"0",bottom:"0",width:"2px",height:""}):Object.assign(this.resizeGuide.style,{display:"block",left:"0",top:`${Math.round(e.currentGuidePosition)}px`,right:"0",height:"2px",width:""});}hideResizeGuide(){this.resizeGuide.style.display="none";}fillSelectionFromEdge(e){let n=We(this.selectionState.range),r=v({},n);if(e==="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=na(this.runtime().activeSheet(),r);await this.runtime().pasteClipboard(o,n),this.cancelCopyOutline(),this.render(),await this.emitChange();})}gridBounds(){var e,n,r,o;return {rowCount:(n=(e=this.layout)==null?void 0:e.rowCount)!=null?n:this.runtime().activeSheet().maxRow,columnCount:(o=(r=this.layout)==null?void 0:r.columnCount)!=null?o:this.runtime().activeSheet().maxColumn}}navigateGrid(e,n=false,r=false){var a,s;let o=Ah(this.selectionState,e,{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(e){return this.cellEditor.contains(e)||[this.sheetTabs,this.contextMenu,this.filterMenu].some(n=>this.eventPathContains(e,n))||e.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(e,n=false,r=false){var f,b,w;if(!e.types.includes("text/plain")&&!Eo(e))return Promise.resolve();let o=e.getData("text/plain"),i=Eo(e),a=((f=this.clipboardPayload)==null?void 0:f.id)===i?this.clipboardPayload:void 0,s=(b=a!=null?a:Il(e))!=null?b:void 0,l=We(this.selectionState.range),d=this.selectionState,u=!!a&&this.clipboardCut&&!n,p=(w=s==null?void 0:s.values)!=null?w:Xp(o);return p.length?this.queueGridMutation(async()=>{let g,h=s!=null?s:{id:"external",text:o,values:p,sourceSheet:this.activeSheetName(),sourceRange:F(v({},l),{endRow:l.startRow+p.length-1,endColumn:l.startColumn+p.reduce((x,S)=>Math.max(x,S.length),0)-1}),formulas:p.map(x=>x.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(e,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,e,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,e,n);}showContextMenu(e,n,r){var i;this.contextMenu.replaceChildren();for(let a of e){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(e,n,r){var d;if(this.filterMenu.style.display==="block"&&this.filterMenuColumn===e){this.hideFilterMenu();return}let o=this.runtime().activeSheet(),i={startRow:1,endRow:o.maxRow,endColumn:o.maxColumn},a=new Set((d=this.columnFilters.get(e))!=null?d:Dl(o,i,e));this.filterMenuColumn=e,this.filterMenu.replaceChildren();let s=document.createElement("strong");s.textContent=`Filter ${e}`,s.style.display="block",s.style.marginBottom="6px",this.filterMenu.appendChild(s);for(let u of Dl(o,i,e)){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(e,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,e,o);return i.width>=28&&r.x>=i.x+i.width-22&&r.x<=i.x+i.width}async applyColumnFilters(){let e=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,e.maxRow,n),this.render(),await this.emitChange();}async sortColumn(e,n){await this.flushEdits();let r=this.runtime().activeSheet();await this.runtime().sortRows(1,r.maxRow,e,n),this.render(),await this.emitChange();}async sortActiveColumn(e){await this.flushEdits(),await this.sortColumn(this.selectionState.active.column,e);}async filterColumn(e,n){await this.flushEdits(),this.assertWritable(),n===null?this.columnFilters.delete(e):this.columnFilters.set(e,[...n]),await this.applyColumnFilters();}hideContextMenu(){this.contextMenu.style.display="none";}selectionContainsCell(e,n){let r=We(this.selectionState.range);return e>=r.startRow&&e<=r.endRow&&n>=r.startColumn&&n<=r.endColumn}async copySelection(e=false){await this.flushEdits(),e&&this.assertWritable();let n=We(this.selectionState.range),r=na(this.runtime().activeSheet(),n,{sourceWorkbookId:this.runtime().workbook().workbookId});this.clipboardPayload=r,this.clipboardCut=e,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([Tl(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 e=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)&&e.setData(o,await(await r.getType(o)).text());}else e.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(e);}clearSelection(){let e=We(this.selectionState.range);return this.queueGridMutation(async()=>{await this.runtime().clearRange(e.startRow,e.startColumn,e.endRow-e.startRow+1,e.endColumn-e.startColumn+1),this.cancelCopyOutline(),this.render(),await this.emitChange();})}queueGridMutation(e){let n=this.flushEdits().then(e);this.pendingGridMutation=n;let r=()=>{this.pendingGridMutation===n&&(this.pendingGridMutation=Promise.resolve());};return n.then(r,r),n}async clearSelectionFormat(){await this.flushEdits();let e=We(this.selectionState.range);await this.runtime().clearRangeFormat(e.startRow,e.startColumn,e.endRow-e.startRow+1,e.endColumn-e.startColumn+1),this.render(),await this.emitChange();}async applyFormat(e,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[e])!==true;e==="bold"&&await this.runtime().setRangeBold(n.startRow,n.startColumn,o,i,u),e==="italic"&&await this.runtime().setRangeItalic(n.startRow,n.startColumn,o,i,u),e==="underline"&&await this.runtime().setRangeUnderline(n.startRow,n.startColumn,o,i,u),this.cancelCopyOutline(),this.render(),await this.emitChange();}async applyAlignment(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeHorizontalAlign(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async mergeSelection(){await this.flushEdits();let e=We(this.selectionState.range);e.startRow===e.endRow&&e.startColumn===e.endColumn||(await this.runtime().mergeRange(e.startRow,e.startColumn,e.endRow-e.startRow+1,e.endColumn-e.startColumn+1),this.selectionState=ct(this.selectionState,this.runtime().activeSheet()),this.render(),await this.emitChange());}async unmergeSelection(){await this.flushEdits();let e=We(this.selectionState.range),n=[...this.runtime().activeSheet().mergeMasterByAddress.values()].filter(r=>nk(e,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 e=this.selectionState.active;await this.runtime().setFreezePanes(Math.max(0,e.row-1),Math.max(0,e.column-1)),this.render(),await this.emitChange();}async commitResizeDrag(e){var n,r,o;if(await this.flushEdits(),e.currentSize===e.startSize){this.render();return}if(e.kind==="column")await this.runtime().setColumnWidth(e.index,e.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(e.index,e.currentSize/i);}this.render(),await this.emitChange();}async openCellEditor(e){var p;if(await this.flushEdits(),this.disposed||this.isReadOnly()||!this.layout||!this.viewport)return;this.cancelCopyOutline();let n=this.selectionState.active,r=this.runtime().activeSheet(),o=qe(r,n.row,n.column),i=wo(r.styles,o==null?void 0:o.styleId,o),a=o!=null&&o.formula?`=${o.formula}`:(p=o==null?void 0:o.displayText)!=null?p:"",s=e===void 0&&(o==null?void 0:o.kind)==="string"?o.source.richText:void 0,l=s!=null&&s.length&&s.map(f=>f.text).join("")===a?s.map(f=>F(v({},f),{style:xo(r.styles,o==null?void 0:o.styleId,f)})):void 0,d=this.cellEditorRect(n,l!==void 0);if(!d)return;Object.assign(this.cellEditorElement.style,{font:i.font,color:i.fontColor,backgroundColor:i.fillColor,textDecoration:i.underline?"underline":"none",textAlign:i.horizontalAlign}),l&&(this.richEditorFrame.style.backgroundColor=i.fillColor,Object.assign(this.richEditorInput.style,{font:i.font,color:i.fontColor,textAlign:i.horizontalAlign,whiteSpace:i.wrapText||/[\r\n]/.test(a)?"pre-wrap":"pre",marginTop:i.verticalAlign==="top"?"0":"auto",marginBottom:i.verticalAlign==="bottom"?"0":"auto"})),this.editingCell=n,this.editingCellStyle=i,this.editingCellInitialValue=a;let u=e!=null?e:a;this.formulaReferenceRanges=Fh(u),this.cellEditor.open(d,u,l),this.render();}async commitCellEdit(e,n){let r=this.editingCell,o=this.editingCellInitialValue;if(this.editingCell=null,this.editingCellInitialValue=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],!r)return;if(e===o){this.render();return}this.assertWritable();let i=formatCellAddress(r.row,r.column);n!=null&&n.length?await this.runtime().setCellRichText(i,n):e.startsWith("=")?await this.runtime().setCellFormula(i,e.slice(1)):await this.runtime().setCellValue(i,X0(e)),this.render(),await this.emitChange();}eventPoint(e){let n=this.host.getBoundingClientRect();return {x:e.clientX-n.left,y:e.clientY-n.top}}assertWritable(){if(this.isReadOnly())throw new hn("spreadsheet")}eventPathContains(e,n){return e.composedPath().includes(n)}updateCellEditorPosition(){let e=this.editingCell;if(!e)return;let n=this.cellEditor.isRich(),r=this.cellEditorRect(e,n);this.cellEditor.place(r),!n&&r&&this.editingCellStyle&&this.alignCellEditor(r,this.editingCellStyle);}cellEditorRect(e,n){var h;let r=this.layout,o=this.viewport;if(!r||!o)return null;let i=We(this.selectionState.range),a=o.viewports.filter(Ul),s=(h=a.find(x=>e.row>=x.rows.start&&e.row<=x.rows.end&&e.column>=x.columns.start&&e.column<=x.columns.end))!=null?h:a.find(({rows:x,columns:S})=>x.start<=i.endRow&&x.end>=i.startRow&&S.start<=i.endColumn&&S.end>=i.startColumn);if(!s)return null;let l=o.cellScreenRect(i.startRow,i.startColumn,s),d=o.cellScreenRect(i.endRow,i.endColumn,s),u={x:l.x,y:l.y,width:d.x+d.width-l.x,height:d.y+d.height-l.y};if(!n)return u;let p=s.screenRect,f=Math.max(u.x,p.x),b=Math.max(u.y,p.y),w=Math.min(u.x+u.width,p.x+p.width)-f,g=Math.min(u.y+u.height,p.y+p.height)-b;return w>0&&g>0?{x:f,y:b,width:w,height:g}:null}alignCellEditor(e,n){let r=this.cellEditorElement,o=4,i=2;r.style.padding=`${i}px ${o}px`;let a=Math.max(0,e.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 e={kind:"workbookChange",bytes:await this.runtime().toZip()};for(let o of this.listeners)o(e);await((r=(n=this.options).onChange)==null?void 0:r.call(n,e));}emitStateIfChanged(e){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=`${e}|${r}`;if(o===this.lastStateKey)return;this.lastStateKey=o;let i={kind:"stateChange",activeSheetName:e,selection:n,editingCell:this.editingCell};for(let u of this.stateListeners)u(i);}reportError(e){let n=e instanceof Error?e:new Error(String(e));this.options.onError?this.options.onError(n):console.error("[spreadsheet-editor]",n);}async runSheetUiAction(e){if(!this.sheetActionPending){this.sheetActionPending=true,this.hideContextMenu(),this.hideFilterMenu(),this.renderTabs();try{await this.flushEdits(),await e(),this.host.focus({preventScroll:!0});}catch(n){this.reportError(n);}finally{this.sheetActionPending=false,this.disposed||this.renderTabs();}}}async createSheetFromTabs(){let e=new Set(this.runtime().model().sheets.map(r=>r.name.toLowerCase())),n=1;for(;e.has(`sheet${n}`);)n+=1;await this.addSheet(`Sheet${n}`);}requestSheetDeletion(e,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:e,onConfirm:()=>{this.runSheetUiAction(async()=>{this.isReadOnly()||this.runtime().model().sheets.length<=1||await this.deleteSheet(e);});}}));}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 e of this.runtimeValue.model().sheets){let n=e.name===this.runtimeValue.activeSheetName(),r=document.createElement("button");r.type="button",r.textContent=e.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(e.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${e.name}\u201D`),i.title=a?"\u5DE5\u4F5C\u7C3F\u81F3\u5C11\u4FDD\u7559\u4E00\u5F20\u5DE5\u4F5C\u8868":`\u5220\u9664\u5DE5\u4F5C\u8868\u201C${e.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(e.name,i)),o.appendChild(i);}this.sheetTabs.appendChild(o);}if(!this.isReadOnly()){let e=document.createElement("button");e.type="button",e.setAttribute("aria-label","\u65B0\u5EFA\u5DE5\u4F5C\u8868"),e.title="\u65B0\u5EFA\u5DE5\u4F5C\u8868",e.disabled=this.sheetActionPending,e.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(e.style,{width:"32px",height:"32px",display:"grid",placeItems:"center",flexShrink:"0",border:"0",borderRadius:"4px",background:"transparent",color:"#475569",cursor:"pointer"}),e.addEventListener("mouseenter",()=>{e.style.background="#e2e8f0";}),e.addEventListener("mouseleave",()=>{e.style.background="transparent";}),e.addEventListener("click",()=>{this.runSheetUiAction(()=>this.createSheetFromTabs());}),this.sheetTabs.appendChild(e);}}}configureScrollbar(e,n,r){e.className="coco-spreadsheet-editor-scrollbar",Object.assign(e.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"}),e.appendChild(n),e.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=e.getBoundingClientRect(),s=r?o.clientX-a.left:o.clientY-a.top;this.drag={axis:r?"horizontal":"vertical",pointer:s,thumb:i.thumbStart},e.setPointerCapture(o.pointerId),this.setScroll(r?ia(i,s-i.thumbLength/2):this.scroll.x,r?this.scroll.y:ia(i,s-i.thumbLength/2));}),e.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=e.getBoundingClientRect(),l=r?o.clientX-s.left:o.clientY-s.top,d=ia(a,i.thumb+l-i.pointer);this.setScroll(r?d:this.scroll.x,r?this.scroll.y:d);}),e.addEventListener("pointerup",()=>{this.drag=null;});}updateScrollbars(){let e=this.scrollbarState,n=this.layout,r=this.viewport;if(!e||!n||!r)return;let o=e.horizontal,i=e.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(e,n){this.scroll={x:e,y:n},this.render();}assertAlive(){if(this.disposed)throw new Error("SpreadsheetEditor: editor has been destroyed")}};function X0(t){if(t==="")return null;if(t==="TRUE")return true;if(t==="FALSE")return false;let e=Number(t);return Number.isFinite(e)&&t.trim()!==""?e:t}function zl(t,e){return e.x>=t.x&&e.y>=t.y&&e.x<=t.x+t.width&&e.y<=t.y+t.height}function Vl(t){return {position:"absolute",left:`${t.x}px`,top:`${t.y}px`,width:`${t.width}px`,height:`${t.height}px`}}function Wh(t,e){return e!==null&&t.sheetId===e.sheetId&&t.drawingIndex===e.drawingIndex&&t.anchorIndex===e.anchorIndex}function Bh(t,e){let n=t.findViewport(e);if(!(!n||!Ul(n)))return {x:e.x-n.screenRect.x+n.originX,y:e.y-n.screenRect.y+n.originY}}function Gl(t,e){var o;let n=t.find(i=>i.path===e.drawingPath);return ((o=n==null?void 0:n.anchors)!=null?o:t.flatMap(i=>i.anchors)).find(i=>{var a;return ((a=i.object)==null?void 0:a.kind)==="chart"&&(!e.relationshipId||i.object.relationshipId===e.relationshipId)})}function Y0(t){var o,i;if(((o=t.object)==null?void 0:o.kind)!=="shape")return null;let e=(i=t.object.name)!=null?i:"",n=e.match(/^coco-tianzige-(horizontal|vertical)-/);if(n!=null&&n[1])return {orientation:n[1],dash:"dashed"};if(/^coco-pinyin-guide-/.test(e))return {orientation:"horizontal",dash:"dashed"};let r=e.match(/^coco-(?:tianzige|pinyin)-outline-\d+-(top|bottom|vertical)(?:-|$)/);return r!=null&&r[1]?{orientation:r[1]==="vertical"?"vertical":"horizontal",dash:"solid"}:null}function da(t,e){var u,p;if(!e||e.kind==="absolute"||!e.from)return null;let n=hr(e.from.column),r=hr(e.from.row),o=e.to?hr(e.to.column):n+5,i=e.to?hr(e.to.row):r+12,a=t.getColumnX(n)+t.emuToCssPixels(e.from.columnOffset),s=t.getRowY(r)+t.emuToCssPixels(e.from.rowOffset),l=t.getColumnX(o)+t.emuToCssPixels((u=e.to)==null?void 0:u.columnOffset),d=t.getRowY(i)+t.emuToCssPixels((p=e.to)==null?void 0:p.rowOffset);return {x:a,y:s,width:Math.max(1,l-a),height:Math.max(1,d-s)}}function Z0(t,e){if(e.kind==="twoCell")return e.from&&e.to?da(t,e):null;let n=t.emuToCssPixels(e.width),r=t.emuToCssPixels(e.height);return n<=0||r<=0?null:e.kind==="absolute"?{x:t.emuToCssPixels(e.x),y:t.emuToCssPixels(e.y),width:n,height:r}:e.from?{x:t.getColumnX(hr(e.from.column))+t.emuToCssPixels(e.from.columnOffset),y:t.getRowY(hr(e.from.row))+t.emuToCssPixels(e.from.rowOffset),width:n,height:r}:null}function pr(t,e){let n=[];for(let r of e.viewports){if(!Ul(r))continue;let o=r.originX,i=r.originY,a=r.originX+r.screenRect.width,s=r.originY+r.screenRect.height,l=Math.max(t.x,o),d=Math.max(t.y,i),u=Math.min(t.x+t.width,a),p=Math.min(t.y+t.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,clipLeft:l-t.x,clipTop:d-t.y});}return n}function J0(t,e,n){let r=Io(t,e.x,e.y),o=n.to?Io(t,e.x+e.width,e.y+e.height):void 0;return {from:r,to:o}}function Ul(t){return t.kind==="main"||t.kind==="frozenTop"||t.kind==="frozenLeft"||t.kind==="frozenTopLeft"}function hr(t){return Math.max(1,Math.floor(t!=null?t:0)+1)}function Q0(t){let e=0;for(let n of t.toUpperCase())e=e*26+n.charCodeAt(0)-64;return e}function ek(t,e){var l,d,u,p,f;let n=e.getContext("2d");if(!n)return 7;let r=(l=t.styles.cellFormats[0])!=null?l:{},o=(u=t.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 tk(t,e){if(e.kind!=="cell")return null;let n=Math.max(0,e.row-t.endRow),r=Math.max(0,e.column-t.endColumn);return !n&&!r?null:n>=r?F(v({},t),{endRow:t.endRow+n}):F(v({},t),{endColumn:t.endColumn+r})}function nk(t,e){return !(t.endRow<e.startRow||t.startRow>e.endRow||t.endColumn<e.startColumn||t.startColumn>e.endColumn)}function Fh(t){var r;if(!t.startsWith("="))return [];let e=(r=t.match(/(?:\$?[A-Z]{1,3}\$?\d+)(?::(?:\$?[A-Z]{1,3}\$?\d+))?/g))!=null?r:[],n=["#DC2626","#16A34A","#7C3AED","#EA580C","#0891B2"];return e.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=Hh(s),u=Hh(l);return !d||!u?[]:[{range:We({startRow:d.row,startColumn:d.column,endRow:u.row,endColumn:u.column}),stroke:(b=n[i%n.length])!=null?b:"#DC2626"}]})}function Hh(t){var o,i;let e=t.replace(/\$/g,"").match(/^([A-Z]{1,3})(\d+)$/);if(!e)return null;let n=0;for(let a of (o=e[1])!=null?o:"")n=n*26+a.charCodeAt(0)-64;let r=Number((i=e[2])!=null?i:"");return Number.isFinite(r)&&r>0&&n>0?{row:r,column:n}:null}var ok={width:9144e3,height:5143500},ua=new Set(["placeholder","textBox","geometricShape","line"]),Vh=new WeakMap;function Po(t){var n;let e=(n=t.slideSize)!=null?n:ok;return {size:e,slides:t.slides.map(r=>ik(r,e))}}function ik(t,e){var l,d,u,p,f,b,w,g,h,x;let n=(d=(l=t.layout)==null?void 0:l.shapes)!=null?d:[],o=[...[...((f=(p=(u=t.layout)==null?void 0:u.master)==null?void 0:p.shapes)!=null?f:[]).map(S=>Kl(S,"master")),...n.map(S=>Kl(S,"layout"))].filter(sk),...t.shapes.map(S=>dk(S,t.layout))],i=o.flatMap(Gh),a=(x=(w=t.background)!=null?w:(b=t.layout)==null?void 0:b.background)!=null?x:(h=(g=t.layout)==null?void 0:g.master)==null?void 0:h.background,s=a!=null?a:ak(o,e);return F(v({id:t.id,index:t.index,name:t.name,title:t.title,size:e},a?{background:a}:{}),{nodes:i.map((S,k)=>Ro(S,{slideSize:e,index:k,background:a,backgroundFill:s})),groups:o.flatMap(S=>jh(S,{background:a,backgroundFill:s})),source:t})}function ak(t,e){var r;let n=t.find(o=>{var a;let i=To(o.geometry);return o.kind==="picture"&&!!((a=o.image)!=null&&a.targetPath)&&i.left<=e.width*.02&&i.top<=e.height*.02&&i.width>=e.width*.96&&i.height>=e.height*.96});return (r=n==null?void 0:n.image)!=null&&r.targetPath?{imagePath:n.image.targetPath}:void 0}function Kl(t,e){var n;return F(v({},t),{id:`${e}:${t.id}`,children:(n=t.children)==null?void 0:n.map(r=>Kl(r,e))})}function sk(t){return t.placeholder?false:t.kind==="group"||t.kind==="picture"||t.kind==="geometricShape"||t.kind==="line"||t.kind==="textBox"}function Gh(t){var e;return t.kind!=="group"?[t]:((e=t.children)!=null?e:[]).flatMap(n=>Gh(Uh(t,n)))}function jh(t,e={}){var n;return t.kind!=="group"?[]:[Ro(t,{background:e.background,backgroundFill:e.backgroundFill}),...((n=t.children)!=null?n:[]).map(r=>Uh(t,r)).flatMap(r=>jh(r,e))]}function Uh(t,e){var I,D,H,A,O;let n=To(t.geometry),r=(I=t.raw)==null?void 0:I.groupTransform,o=To(e.geometry),i=(D=r==null?void 0:r.childLeft)!=null?D:n.left,a=(H=r==null?void 0:r.childTop)!=null?H: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,x=lk({left:g,top:h,width:b,height:w},n),S=Kh(((A=n.rotation)!=null?A:0)+((O=o.rotation)!=null?O:0)),k=F(v({},e),{id:`${t.id}:${e.id}`,geometry:F(v({},e.geometry),{left:x.left,top:x.top,width:b,height:w,rotation:S,flipHorizontal:!!n.flipHorizontal!=!!o.flipHorizontal,flipVertical:!!n.flipVertical!=!!o.flipVertical}),children:e.children});return Vh.set(k,{parentId:t.id,parentName:t.name,parentBounds:n,parentTransform:{childLeft:i,childTop:a,childWidth:s,childHeight:l}}),k}function lk(t,e){if(!e.rotation)return t;let n=e.rotation*Math.PI/180,r=e.left+e.width/2,o=e.top+e.height/2,i=t.left+t.width/2,a=t.top+t.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 F(v({},t),{left:d-t.width/2,top:u-t.height/2})}function Kh(t){let e=(t%360+360)%360;return e===0?void 0:e}function dk(t,e){if(!t.placeholder)return t;let n=resolvePptEffectivePlaceholderProperties(t,e);return v(F(v({},t),{placeholder:n.placeholder,geometry:n.geometry,style:n.style}),t.text?{text:F(v({},t.text),{style:n.textStyle,body:n.textBody})}:{})}function Ro(t,e={}){var d,u,p,f,b,w,g,h,x,S,k,I,D,H,A,O,ee;let n=_h(t),r=n.editText||n.editTextStyle||n.editTableCells||n.editGeometry||n.editShapeStyle,o=t.style,i=((d=t.raw)==null?void 0:d.useBackgroundFill)===true,a=i?void 0:(p=(u=t.style)==null?void 0:u.fillColor)!=null?p:fk(t,e),s=pk((f=t.text)==null?void 0:f.style,{fillColor:a,background:e.background}),l=To(t.geometry);return F(v({id:t.id,name:t.name,kind:t.kind,bounds:uk(t,l),text:(w=(b=t.text)==null?void 0:b.text)!=null?w:ck(t),textStyle:s,textParagraphs:(g=t.text)==null?void 0:g.paragraphs,textBody:(h=t.text)==null?void 0:h.body,imagePath:(x=t.image)==null?void 0:x.targetPath,imageCrop:(S=t.image)==null?void 0:S.crop,imageFillRect:(k=t.image)==null?void 0:k.fillRect,imageOpacity:(I=t.image)==null?void 0:I.opacity,chart:t.chart,table:t.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:(D=t.raw)==null?void 0:D.presetGeometry,presetAdjustments:(H=t.raw)==null?void 0:H.presetAdjustments,customGeometry:(A=t.raw)==null?void 0:A.customGeometry,threeD:(O=t.raw)==null?void 0:O.threeD,usesBackgroundFill:i},i&&e.backgroundFill?{backgroundFill:e.backgroundFill}:{}),{locked:!r,editable:r,capabilities:n,groupContext:wk(t),source:t,children:((ee=t.children)!=null?ee:[]).map(le=>Ro(le,{background:e.background,backgroundFill:e.backgroundFill}))})}function ck(t){if(t.table)return t.table.values.map(e=>e.join(" ")).join(`
|
|
1682
|
-
`)}function uk(t,e){if(!t.table)return e;let n=Oh(t.table.columnWidths),r=Oh(t.table.rowHeights);return n===void 0&&r===void 0?e:v(v(v({},e),$h(e.width,n)?{width:n}:{}),$h(e.height,r)?{height:r}:{})}function Oh(t){if(!(t!=null&&t.length))return;let e=t.reduce((n,r)=>n+r,0);return Number.isFinite(e)&&e>0?e:void 0}function $h(t,e){return e===void 0?false:!Number.isFinite(t)||t<=0?true:e/t>1.15}function fk(t,e){var o;let n=To(t.geometry),r=e.slideSize;if(e.index===0&&t.kind==="geometricShape"&&!((o=t.text)!=null&&o.text)&&r&&n.left<=0&&n.top<=0&&n.width>=r.width*.95&&n.height>=r.height*.95)return "#1D3F80"}function pk(t,e){var r,o;if(t!=null&&t.color)return t;let n=(o=e.fillColor)!=null?o:(r=e.background)==null?void 0:r.fillColor;return !n||!hk(n)?t:F(v({},t),{color:"#FFFFFF"})}function hk(t){let e=/^#?([0-9a-f]{6})$/i.exec(t);if(!e)return false;let n=e[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 cR(t){let e=_h(t);return e.editText||e.editTextStyle||e.editTableCells||e.editGeometry||e.editShapeStyle}function _h(t){if(gk(t))return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:false,editShapeStyle:false,reason:"Inherited from layout/master",reasons:zh("\u7EE7\u627F\u81EA\u6BCD\u7248/\u7248\u5F0F\uFF0C\u5F53\u524D\u53EA\u652F\u6301\u67E5\u770B")};if(bk(t)){let n=!!t.text&&ua.has(t.kind),r=t.kind==="table"&&!!t.table;return {select:true,editText:n,editTextStyle:n,editTableCells:r,editGeometry:true,editShapeStyle:false,reason:"Flattened group child",reasons:No({editText:n?void 0:ca(t),editTextStyle:n?void 0:ca(t),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(t.kind==="table")return {select:true,editText:false,editTextStyle:false,editTableCells:true,editGeometry:true,editShapeStyle:true,reasons:No({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(t.kind==="picture")return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:No({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(t.kind==="chart"||t.kind==="smartArt"||t.kind==="group"){let n=mk(t.kind);return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:false,reason:"Limited editor support for this object type",reasons:No({editText:n.text,editTextStyle:n.textStyle,editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C",editShapeStyle:n.shapeStyle})}}let e=!!t.text&&ua.has(t.kind);return ua.has(t.kind)?{select:true,editText:e,editTextStyle:e,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:No({editText:e?void 0:ca(t),editTextStyle:e?void 0:ca(t),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:zh("\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B\u6682\u4E0D\u652F\u6301\u5E38\u89C4\u7F16\u8F91")}}function No(t){return Object.fromEntries(Object.entries(t).filter(e=>!!e[1]))}function zh(t){return {editText:t,editTextStyle:t,editTableCells:t,editGeometry:t,editShapeStyle:t}}function ca(t){return t.text?ua.has(t.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 mk(t){return t==="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"}:t==="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 gk(t){return t.id.startsWith("layout:")||t.id.startsWith("master:")}function bk(t){return t.id.includes(":")}function qh(t,e){var b;if(!t.groupContext)return e;let n=t.groupContext.parentBounds,r=t.groupContext.parentTransform,o=v(v({},t.bounds),e),i=n.width/(r.childWidth||n.width||1),a=n.height/(r.childHeight||n.height||1),s=xk(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 e.left!==void 0&&(f.left=u/i+r.childLeft),e.top!==void 0&&(f.top=p/a+r.childTop),e.width!==void 0&&(f.width=o.width/i),e.height!==void 0&&(f.height=o.height/a),e.rotation!==void 0&&(f.rotation=Kh(e.rotation-((b=n.rotation)!=null?b:0))),e.flipHorizontal!==void 0&&(f.flipHorizontal=!!n.flipHorizontal!=!!e.flipHorizontal),e.flipVertical!==void 0&&(f.flipVertical=!!n.flipVertical!=!!e.flipVertical),f}function wk(t){return Vh.get(t)}function xk(t,e,n){if(!n.rotation)return {x:t,y:e};let r=-n.rotation*Math.PI/180,o=n.left+n.width/2,i=n.top+n.height/2,a=t-o,s=e-i;return {x:o+a*Math.cos(r)-s*Math.sin(r),y:i+a*Math.sin(r)+s*Math.cos(r)}}function To(t={}){var e,n,r,o;return {left:(e=t.left)!=null?e:0,top:(n=t.top)!=null?n:0,width:(r=t.width)!=null?r:0,height:(o=t.height)!=null?o:0,rotation:t.rotation,flipHorizontal:t.flipHorizontal,flipVertical:t.flipVertical}}function mr(t,e){var n,r;return typeof e=="number"?(n=t.slides.find(o=>o.index===e))!=null?n:null:(r=t.slides.find(o=>o.id===e||o.name===e))!=null?r:null}function Mo(t,e){let n=[...t.nodes,...t.groups];for(;n.length>0;){let r=n.shift();if(r.id===e||r.name===e)return r;n.unshift(...r.children);}return null}async function mR(t,e={}){let n=await Presentation.fromZip(t,{presentationId:e.presentationId,mode:"inline"});return Yh(n,e)}async function gR(t,e={}){var r;let n=await Presentation.fromModel(t,{presentationId:(r=e.presentationId)!=null?r:t.id,mode:"inline"});return Yh(n,e)}async function Yh(t,e={}){let[n,r,o]=await Promise.all([t.toModel(),yk(t,e),vk(t)]);return {presentation:t,model:n,scene:Po(n),images:r,fonts:o}}async function yk(t,e){if(typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return {};let n=await t.exportImages(),r=await Promise.all(n.map(async o=>{var a;let i=await((a=e.resolveImagePreview)==null?void 0:a.call(e,{path:o.path,contentType:o.contentType,bytes:o.bytes}));return [o.path,i!=null?i:{url:URL.createObjectURL(new Blob([Zh(o.bytes)],{type:o.contentType})),contentType:o.contentType}]}));return Object.fromEntries(r)}async function vk(t){return typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function"?[]:(await t.exportFonts()).map(n=>v(v({url:URL.createObjectURL(new Blob([Zh(n.bytes)],{type:n.contentType})),contentType:n.contentType,family:n.family},n.weight?{weight:n.weight}:{}),n.style?{style:n.style}:{}))}function Zh(t){let e=new Uint8Array(t.byteLength);return e.set(t),e.buffer}var fa=class{constructor(e,n={}){W(this,"presentationValue");W(this,"modelValue");W(this,"sceneValue");W(this,"selectionValue",null);W(this,"revisionValue",0);W(this,"undoStack",[]);W(this,"redoStack",[]);W(this,"textBodyOverrides",new Map);W(this,"maxHistory");W(this,"readOnlyValue");W(this,"changeListeners",new Set);W(this,"selectionListeners",new Set);var r;this.presentationValue=e.presentation,this.modelValue=e.model,this.sceneValue=e.scene,this.maxHistory=(r=n.maxHistory)!=null?r:50,this.readOnlyValue=n.readOnly===true,this.selectionValue=e.scene.slides[0]?{kind:"slide",slideId:e.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(e){this.readOnlyValue=e;}canUndo(){return !this.readOnlyValue&&this.undoStack.length>0}canRedo(){return !this.readOnlyValue&&this.redoStack.length>0}subscribe(e,n){let r=e==="change"?this.changeListeners:this.selectionListeners;return r.add(n),()=>r.delete(n)}async dispatch(e){if(e.kind==="select-slide"||e.kind==="select-shape"){await this.applySelectionCommand(e);return}this.assertWritable();let n=await this.presentationValue.toZip(),r=await this.applyEditCommand(e);this.pushUndo(n),this.redoStack.length=0,await this.refreshAfterChange(e),r!==void 0&&this.setSelection(r);}async undo(){this.assertWritable();let e=this.undoStack.pop();if(!e)return;let n=this.selectionValue;this.redoStack.push(this.historyEntry(await this.presentationValue.toZip())),this.restoreTextBodyOverrides(e.textBodyOverrides),await this.replacePresentation(e.bytes,n);}async redo(){this.assertWritable();let e=this.redoStack.pop();if(!e)return;let n=this.selectionValue;this.undoStack.push(this.historyEntry(await this.presentationValue.toZip())),this.restoreTextBodyOverrides(e.textBodyOverrides),await this.replacePresentation(e.bytes,n);}async loadPresentation(e){this.undoStack.length=0,this.redoStack.length=0,this.textBodyOverrides.clear(),await this.replacePresentation(e);}async toPptx(){return this.presentationValue.toZip()}async verifyExport(){let e=await this.toPptx(),n=await Presentation.fromZip(e,{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 hn("ppt")}async applySelectionCommand(e){let n=mr(this.sceneValue,e.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(e.slideIdOrIndex)}`);if(e.kind==="select-slide"){this.setSelection({kind:"slide",slideId:n.id});return}let r=Mo(n,e.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${e.shapeIdOrName}`);this.setSelection({kind:"shape",slideId:n.id,shapeId:r.id});}async applyEditCommand(e){var a,s;if(e.kind==="delete-shape"||e.kind==="duplicate-shape"||e.kind==="paste-shape"||e.kind==="bring-shape-to-front"||e.kind==="send-shape-to-back")return this.applyShapeCollectionCommand(e);let n=this.assertEditableSceneNodeForCommand(e),r=mr(this.sceneValue,e.slideIdOrIndex);if(!r)throw new Error(`PPT slide not found: ${String(e.slideIdOrIndex)}`);let o=this.presentationValue.slides.getItem(e.slideIdOrIndex),i=Ik(o.shapes,e.shapeIdOrName);if(e.kind==="set-shape-text"){await i.text.setText(e.text,{preserveFirstRunStyle:true});return}if(e.kind==="set-shape-text-style"){await i.text.setTextStyle(e.style);return}if(e.kind==="set-table-cell-text"){await i.table.setCellText(e.row,e.column,e.text);return}if(e.kind==="set-shape-geometry"){if(e.preserveTextSizeOnResize&&kk(n)){let l=F(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(Sk(r.id,n.id),l);}await i.setGeometry(qh(n,e.geometry));return}await i.setStyle(e.style);}assertEditableSceneNodeForCommand(e){var o;let n=mr(this.sceneValue,e.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(e.slideIdOrIndex)}`);let r=(o=Mo(n,e.shapeIdOrName))!=null?o:Ck(n,e.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${e.shapeIdOrName}`);if(Nk(e)&&(r.locked||r.id.includes(":")||!r.editable))throw new Error(`PPT shape collection operation is not editable: ${r.id}`);if(e.kind==="set-shape-text"&&!r.capabilities.editText)throw new Error(`PPT shape is not text-editable: ${r.id}`);if(e.kind==="set-shape-text-style"&&!r.capabilities.editTextStyle)throw new Error(`PPT shape text style is not editable: ${r.id}`);if(e.kind==="set-table-cell-text"&&!r.capabilities.editTableCells)throw new Error(`PPT shape table cells are not editable: ${r.id}`);if(e.kind==="set-shape-geometry"&&!r.capabilities.editGeometry)throw new Error(`PPT shape geometry is not editable: ${r.id}`);if(e.kind==="set-shape-style"&&!r.capabilities.editShapeStyle)throw new Error(`PPT shape style is not editable: ${r.id}`);return r}async applyShapeCollectionCommand(e){var d,u,p,f,b,w,g,h;this.assertEditableSceneNodeForCommand(e);let n=mr(this.sceneValue,e.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(e.slideIdOrIndex)}`);let r=Mo(n,e.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${e.shapeIdOrName}`);let i=this.presentationValue.slides.getItem(e.slideIdOrIndex).shapes.getItem(e.shapeIdOrName);if(e.kind==="delete-shape")return await i.delete(),{kind:"slide",slideId:n.id};if(e.kind==="bring-shape-to-front")return await i.bringToFront(),{kind:"shape",slideId:n.id,shapeId:r.id};if(e.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=e.offset)==null?void 0:d.left)!=null?u:18e4):r.bounds.left,top:typeof r.bounds.top=="number"?r.bounds.top+((f=(p=e.offset)==null?void 0:p.top)!=null?f:18e4):r.bounds.top,width:(w=(b=e.offset)==null?void 0:b.width)!=null?w:r.bounds.width,height:(h=(g=e.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(e){this.modelValue=await this.presentationValue.toModel(),this.sceneValue=Po(this.modelValue),this.applyTextBodyOverrides(),this.revisionValue+=1,this.changeListeners.forEach(n=>n({revision:this.revisionValue,command:e,model:this.modelValue,scene:this.sceneValue}));}async replacePresentation(e,n=null){let r=await Presentation.fromZip(e,{mode:"inline"});if(await this.presentationValue.dispose(),this.presentationValue=r,this.modelValue=await r.toModel(),this.sceneValue=Po(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(e){this.selectionValue=e,this.selectionListeners.forEach(n=>n({selection:e}));}pushUndo(e){this.undoStack.push(this.historyEntry(e)),this.undoStack.length>this.maxHistory&&this.undoStack.shift();}historyEntry(e){return {bytes:e,textBodyOverrides:new Map(this.textBodyOverrides)}}restoreTextBodyOverrides(e){this.textBodyOverrides.clear(),e.forEach((n,r)=>this.textBodyOverrides.set(r,v({},n)));}applyTextBodyOverrides(){var e;for(let[n,r]of this.textBodyOverrides){let[o,i]=n.split("\0");if(!o||!i)continue;let a=mr(this.sceneValue,o),s=a?Mo(a,i):null;!s||!s.text&&!((e=s.textParagraphs)!=null&&e.length)||(s.textBody=v(v({},s.textBody),r));}}};function Sk(t,e){return `${t}\0${e}`}function kk(t){var e;return !!(t.capabilities.editGeometry&&Ek(t)&&(t.text||(e=t.textParagraphs)!=null&&e.length))}function Ek(t){return t.kind==="placeholder"||t.kind==="textBox"||t.kind==="geometricShape"}function Ck(t,e){let n=t.source.shapes.find(r=>r.id===e||r.name===e);return n?Ro(n,{slideSize:t.size,background:t.background}):null}function Ik(t,e){let n=e.split(":").filter(Boolean);if(n.length<=1)return t.getItem(e);let r=t.getItem(n[0]);for(let o of n.slice(1))r=r.group.getItem(o);return r}function Nk(t){return t.kind==="delete-shape"||t.kind==="duplicate-shape"||t.kind==="paste-shape"||t.kind==="bring-shape-to-front"||t.kind==="send-shape-to-back"}var Qh=24e4,Lo=91440,Tk=91440,_l=4,em=7,gr=128,Pk=8,pa=2,Rk=2,ha=4;function TR(t,e,n={}){return new Yl(t,e,n)}function Mk(t){if(t.kind==="line"||t.kind!=="geometricShape"||t.customGeometry||t.presetGeometry&&t.presetGeometry!=="ellipse"||t.text||!t.fillColor)return false;let e=Math.min(t.bounds.width,t.bounds.height),n=Math.max(t.bounds.width,t.bounds.height);return e<=0?false:n/e<1.2}function En(t,e,n){var d,u,p,f;let r=Math.max(Lo,(d=n.width)!=null?d:t.width),o=Math.max(Lo,(u=n.height)!=null?u:t.height),i=Math.min(Qh,r),a=Math.min(Qh,o),s=Sa((p=n.left)!=null?p:t.left,-r+i,e.width-i),l=Sa((f=n.top)!=null?f:t.top,-o+a,e.height-a);return F(v({},t),{left:s,top:l,width:r,height:o})}function Sa(t,e,n){return Math.max(e,Math.min(n,t))}function ma(t,e,n){let r=n==="x"?t.size.width:t.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 t.nodes){if(!Ak(i,e))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 Ak(t,e){return t.id!==e&&t.kind!=="line"&&!t.locked&&!t.id.includes(":")&&t.capabilities.select&&t.capabilities.editGeometry&&t.bounds.width>Lo&&t.bounds.height>Lo}function ga(t,e,n,r={}){let o=null;for(let i of t)for(let a of e){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 tm(t,e,n,r){let o=e/2,i=Math.abs(n.offset-o)<1?(r-t)*2:r-t;return Math.max(Lo,i)}function jn(t){return !t.locked&&!t.id.includes(":")&&(t.capabilities.editGeometry||t.capabilities.editText||t.capabilities.editShapeStyle||t.capabilities.editTableCells)}function Lk(t){let e=t.groupContext;return e?F(v({},t),{id:e.parentId,name:e.parentName,kind:"group",bounds:e.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:[]}):t}function Dk(t){var i,a;if(t.kind!=="picture"||!t.customGeometry||t.customGeometry.paths.length!==1)return false;let e=Math.min(t.bounds.width,t.bounds.height),n=Math.max(t.bounds.width,t.bounds.height);if(e<=0||n/e>1.12)return false;let r=(a=(i=t.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 Yl=class{constructor(e,n,r){W(this,"root");W(this,"sessionValue");W(this,"imageResources");W(this,"fontResources");W(this,"referencedFontFamilies");W(this,"slideList",document.createElement("div"));W(this,"canvas",document.createElement("div"));W(this,"contextMenu",document.createElement("div"));W(this,"snapGuides",document.createElement("div"));W(this,"options");W(this,"handleCanvasClick",()=>{this.dispatchCurrentSlideSelection();});W(this,"handleWindowMouseMove",e=>{this.updateDrag(e);});W(this,"handleWindowMouseUp",e=>{this.finishDrag(e);});W(this,"handleWindowKeyDown",e=>{this.handleKeyDown(e);});W(this,"handleWindowPointerDown",e=>{this.dismissContextMenu(e);});W(this,"handleWindowScroll",()=>this.hideContextMenu());W(this,"handleCanvasSelectStart",e=>this.handleSelectStart(e));W(this,"handleSlideListScroll",()=>this.scheduleThumbnailRender());W(this,"dragState",null);W(this,"suppressClickAfterDrag",false);W(this,"clipboardShape",null);W(this,"thumbnailFrame",0);W(this,"thumbnailRasterEpoch",0);W(this,"thumbnailCanvasCache",new Map);W(this,"pendingCommands",new Set);this.options=r,this.root=r.styleIsolation==="none"?e:e.attachShadow({mode:"open"}),this.sessionValue=new fa(n,{readOnly:r.readOnly}),this.imageResources=n.images,this.fontResources=n.fonts,this.referencedFontFamilies=_k(n);let o=Kk(this.fontResources,this.referencedFontFamilies);qk(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(e){if(this.isReadOnly()===e)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(e),this.render();}async dispatch(e){let n=this.dispatchAndRender(e);this.pendingCommands.add(n);try{await n;}finally{this.pendingCommands.delete(n);}}async dispatchAndRender(e){var r,o;let n=(r=this.currentSlide())==null?void 0:r.id;if(await this.sessionValue.dispatch(e),e.kind==="select-slide"||e.kind==="select-shape"){if(((o=this.currentSlide())==null?void 0:o.id)!==n){this.render();return}this.renderSelection();return}this.render();}async loadPresentation(e){await this.sessionValue.loadPresentation(e),this.thumbnailCanvasCache.clear(),this.thumbnailRasterEpoch++,this.render();}async toPptx(){var e;return (e=this.root.querySelector('[contenteditable="true"]'))==null||e.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 e=document.createElement("style");e.textContent=`
|
|
1696
|
+
`,this.renderRoot.appendChild(o);}e.classList.add("coco-spreadsheet-editor-host"),Object.assign(e.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.richEditorFrame.className="coco-spreadsheet-rich-editor",Object.assign(this.richEditorFrame.style,{position:"absolute",zIndex:"20",display:"none",flexDirection:"column",boxSizing:"border-box",border:"2px solid #2563eb",padding:"2px 4px",overflow:"auto"}),this.richEditorInput.className="coco-spreadsheet-rich-editor-input",this.richEditorInput.setAttribute("contenteditable","true"),this.richEditorInput.setAttribute("role","textbox"),this.richEditorInput.setAttribute("aria-label","\u7F16\u8F91\u5355\u5143\u683C"),this.richEditorInput.setAttribute("aria-multiline","true"),this.richEditorInput.setAttribute("tabindex","-1"),Object.assign(this.richEditorInput.style,{outline:"none",whiteSpace:"pre-wrap",overflowWrap:"anywhere",flexShrink:"0",minHeight:"1em"}),this.richEditorFrame.appendChild(this.richEditorInput),this.renderRoot.appendChild(this.richEditorFrame),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 la(e,this.renderRoot),this.cellEditor=new oa({textarea:this.cellEditorElement,richFrame:this.richEditorFrame,richInput:this.richEditorInput,onCommit:async(o,i)=>this.commitCellEdit(o,i),onInput:o=>{this.editingCell&&(this.formulaReferenceRanges=Fh(o),this.render());},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.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}),e.addEventListener("wheel",this.handleWheel,{passive:false}),e.addEventListener("click",this.handleClick),e.addEventListener("dblclick",this.handleDoubleClick),e.addEventListener("pointerdown",this.handlePointerDown),e.addEventListener("pointermove",this.handlePointerMove),e.addEventListener("pointerup",this.handlePointerUp),e.addEventListener("pointercancel",this.handlePointerCancel),e.addEventListener("pointerleave",this.handlePointerLeave),e.addEventListener("keydown",this.handleKeyDown),e.addEventListener("keyup",this.handleKeyUp),e.addEventListener("copy",this.handleCopy),e.addEventListener("cut",this.handleCut),e.addEventListener("paste",this.handlePaste),e.addEventListener("contextmenu",this.handleContextMenu),document.addEventListener("pointerdown",this.handleDocumentPointerDown),this.filterMenu.addEventListener("click",this.handleFilterMenuClick),e.tabIndex=0,this.resizeObserver=new ResizeObserver(()=>this.render()),this.resizeObserver.observe(e);}runtime(){if(!this.runtimeValue)throw new Error("SpreadsheetEditor: workbook is not loaded");return this.runtimeValue}isReadOnly(){return this.readOnlyValue}setReadOnly(e){var n;this.disposed||this.isReadOnly()===e||(this.cellEditor.cancel(),this.resizeDrag=null,this.autoFillDrag=null,this.chartDrag=null,this.clearDrawingSelection(),this.selecting=false,this.hideResizeGuide(),this.hideContextMenu(),this.hideFilterMenu(),(n=this.runtimeValue)==null||n.setReadOnly(e),this.readOnlyValue=e,this.host.setAttribute("aria-readonly",String(e)),this.renderTabs(),this.render());}selection(){return this.selectionState}cellState(e){var i,a,s,l;let n=this.runtime().activeSheet(),r=n.cellsByAddress.get(e);if(!r){let d=e.match(/^([A-Z]+)(\d+)$/i);if(!d)throw new Error(`SpreadsheetEditor: invalid cell address ${e}`);let u=Q0(d[1]),f=Number(d[2]);return {address:e.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 qi(this.runtime().activeSheet().source)}filterState(){return new Map([...this.columnFilters.entries()].map(([e,n])=>[e,[...n]]))}activeSheetName(){return this.runtime().activeSheetName()}setActiveSheet(e){return this.queueGridMutation(async()=>{await this.runtime().setActiveSheet(e),this.clearDrawingSelection(),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(e){await this.flushEdits(),await this.runtime().addSheet(e),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async renameSheet(e,n){await this.flushEdits(),await this.runtime().renameSheet(e,n),this.copiedRange=null,this.renderTabs(),this.render(),await this.emitChange();}async copySheet(e,n){await this.flushEdits(),await this.runtime().copySheet(e,n),this.copiedRange=null,this.scroll={x:0,y:0},this.selectionState=it(1,1),this.renderTabs(),this.render(),await this.emitChange();}async deleteSheet(e){await this.flushEdits(),await this.runtime().deleteSheet(e),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(e,n){await this.flushEdits(),await this.runtime().moveSheet(e,n),this.copiedRange=null,this.renderTabs(),this.render(),await this.emitChange();}async setCellValue(e,n){await this.flushEdits(),await this.runtime().setCellValue(e,n,{mergeUndo:true}),this.render(),await this.emitChange();}async setCellFormula(e,n){await this.flushEdits(),await this.runtime().setCellFormula(e,n,{mergeUndo:true}),this.render(),await this.emitChange();}formatSelection(e){let n=We(this.selectionState.range),r=formatCellAddress(this.selectionState.active.row,this.selectionState.active.column);return this.queueGridMutation(async()=>this.applyFormat(e,n,r))}async setSelectionFontColor(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeFontColor(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async setSelectionFillColor(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeFillColor(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async setSelectionHorizontalAlign(e){await this.flushEdits(),await this.applyAlignment(e);}async setSelectionVerticalAlign(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeVerticalAlign(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async setSelectionNumberFormat(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeNumberFormat(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async setSelectionBorder(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeBorder(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async loadWorkbook(e){var d,u;this.assertAlive();let n=++this.workbookLoadId;if(await this.flushEdits(),this.disposed||n!==this.workbookLoadId)return;let r=this.runtimeValue;this.runtimeValue=null,this.clearDrawingSelection(),(d=this.drawingPreviews)==null||d.dispose(),this.drawingPreviews=null,this.copiedRange=null,this.clipboardPayload=null,this.clipboardCut=false,this.clipboardActive=false,this.scroll={x:0,y:0},r&&await r.dispose();let o=await fromZip(e);if(this.disposed||n!==this.workbookLoadId)return;let i=ExcelWorkbook.fromPackage(o,{workbookId:this.options.workbookId,mode:"inline"}),a=await ra.fromWorkbook(i,{readOnly:this.readOnlyValue});if(this.disposed||n!==this.workbookLoadId){await a.dispose();return}this.runtimeValue=a,this.drawingPreviews=new sa(o);let s=this.runtimeValue.activeSheet();this.selectionState=ct(it(1,1),s);let l=new Set(s.styles.cellFormats.map((f,p)=>wo(s.styles,p).font));for(let f of a.model().sheets)for(let p of f.cells)for(let b of (u=p.richText)!=null?u:[])l.add(xo(s.styles,p.styleId,b).font);await Dr(l),!(this.disposed||n!==this.workbookLoadId)&&(this.host.setAttribute("aria-readonly",String(this.isReadOnly())),this.renderTabs(),this.render());}async toZip(){return await this.flushEdits(),this.runtime().toZip()}async flushEdits(){let e=this.pendingGridMutation;await this.cellEditor.commit(),await e;}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(e){return this.listeners.add(e),()=>this.listeners.delete(e)}subscribeState(e){return this.stateListeners.add(e),()=>this.stateListeners.delete(e)}async runTransaction(e,n){await this.flushEdits(),this.transactionDepth+=1;try{await this.runtime().runUserTransaction(e,()=>n(this));}finally{this.transactionDepth-=1,this.transactionDepth===0&&this.transactionChanged&&(this.transactionChanged=false,this.render(),await this.emitChange());}}destroy(){var r;if(this.disposed)return;let e=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("pointercancel",this.handlePointerCancel),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.clearDrawingSelection(),(r=this.drawingPreviews)==null||r.dispose(),this.drawingPreviews=null,this.unsupportedObjectLayer.remove(),this.host.replaceChildren();let n=this.runtimeValue;e.catch(o=>this.reportError(o)).finally(()=>{this.runtimeValue=null,n==null||n.dispose();});}render(){var f;let e=this.runtimeValue,n=this.renderer;if(!e||!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 ji(e.activeSheet(),{maximumDigitWidth:ek(e.activeSheet(),this.baseCanvas)}),s={width:Math.max(1,o-12),height:Math.max(1,i-12)},l=new _i(a,{viewportSize:s,scroll:this.scroll,freeze:qi(e.activeSheet().source)});this.layout=a,this.viewport=l,this.scroll=l.scroll,this.scrollbarState=Eh(a,s,qi(e.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=We(this.selectionState.range);n.renderSelection(a,l,u,{showFillHandle:!this.isReadOnly()&&Al(e.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(e.activeSheetName()),this.updateScrollbars();}renderDrawingOverlays(e,n){var i,a,s;this.unsupportedObjectLayer.replaceChildren(),this.drawingHits=[];let r=(i=this.runtimeValue)==null?void 0:i.activeSheet().source;if(!r)return;this.selectedDrawing&&this.selectedDrawing.sheetId!==r.id&&this.clearDrawingSelection();for(let[l,d]of r.drawings.entries())for(let[u,f]of d.anchors.entries()){let p=Y0(f);if(!p){this.renderDrawingPreview(f,e,n,{sheetId:r.id,drawingIndex:l,anchorIndex:u});continue}let b=da(e,f);if(b)for(let w of pr(b,n)){let g=document.createElement("div");g.setAttribute("aria-hidden","true"),Object.assign(g.style,v({position:"absolute",left:`${w.x}px`,top:`${w.y}px`,width:`${Math.max(1,w.width)}px`,height:`${Math.max(1,w.height)}px`,boxSizing:"border-box",pointerEvents:"none",opacity:p.dash==="dashed"?"0.72":"1"},p.orientation==="horizontal"?{borderTop:`1px ${p.dash} #4F9185`}:{borderLeft:`1px ${p.dash} #4F9185`})),this.unsupportedObjectLayer.appendChild(g);}}if(r.path&&this.drawingPreviews)for(let l of this.drawingPreviews.embeddedOnSheet(r.path))this.renderDrawingPreview(l,e,n);for(let l=0;l<r.charts.length;l+=1){let d=r.charts[l];if(!d)continue;let u=Gl(r.drawings,d),f=((a=this.chartDrag)==null?void 0:a.chartIndex)===l?this.chartDrag.previewRect:da(e,u);if(f)for(let p of pr(f,n)){let b=document.createElement("div");b.className="coco-spreadsheet-unsupported-chart",Object.assign(b.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":((s=this.chartDrag)==null?void 0:s.chartIndex)===l?"grabbing":"move",border:this.selectedChartIndex===l?"2px solid #2563eb":"1px dashed #94a3b8",boxShadow:this.selectedChartIndex===l?"0 0 0 1px rgba(37, 99, 235, 0.18)":"none"});let w=document.createElement("strong");w.textContent=d.title?`\u56FE\u8868\uFF1A${d.title}`:"\u56FE\u8868",w.style.color="#334155";let g=document.createElement("span");g.textContent="\u5F53\u524D\u7F16\u8F91\u5668\u6682\u4E0D\u652F\u6301\u56FE\u8868\u6E32\u67D3";let h=document.createElement("span");h.textContent="\u8BF7\u4F7F\u7528 Excel \u6216 WPS \u6253\u5F00\u6587\u4EF6\u67E5\u770B",b.append(w,g,h),this.unsupportedObjectLayer.appendChild(b);}}let o=this.drawingHits.find(({target:l})=>Wh(l.reference,this.selectedDrawing));o&&this.renderDrawingSelection(o.target,n);}renderDrawingPreview(e,n,r,o){if(!this.drawingPreviews||!e.object)return;let i=this.drawingDrag,a=o&&i&&Wh(o,i.target.reference)?i.previewRect:Z0(n,e);if(!a)return;let s=o&&!this.isReadOnly()?{reference:o,anchor:e,rect:a}:null;for(let l of pr(a,r)){let d=this.drawingPreviews.render(e.object,a,!o);if(!d)return;let u=document.createElement("div");u.className="coco-spreadsheet-drawing-preview",Object.assign(u.style,Vl(l),{overflow:"hidden"}),Object.assign(d.style,{position:"absolute",maxWidth:"none",left:`${-l.clipLeft}px`,top:`${-l.clipTop}px`,width:`${a.width}px`,height:`${a.height}px`}),u.appendChild(d),this.unsupportedObjectLayer.appendChild(u),s&&this.drawingHits.push({target:s,screenRect:l});}}renderDrawingSelection(e,n){let{rect:r}=e;for(let o of pr(r,n)){let i=document.createElement("div");i.className="coco-spreadsheet-drawing-selection",Object.assign(i.style,Vl(o),{boxSizing:"border-box",border:"1px solid #2563eb",borderLeftWidth:o.clipLeft>0?"0":"1px",borderTopWidth:o.clipTop>0?"0":"1px",borderRightWidth:o.clipLeft+o.width<r.width?"0":"1px",borderBottomWidth:o.clipTop+o.height<r.height?"0":"1px"}),this.unsupportedObjectLayer.appendChild(i);}for(let o of Th)for(let i of pr(Ph(r,o),n)){let a=document.createElement("div");a.className="coco-spreadsheet-drawing-resize-handle",a.dataset.handle=o,Object.assign(a.style,Vl(i),{boxSizing:"border-box",border:"1px solid #2563eb",background:"#fff"}),this.unsupportedObjectLayer.appendChild(a),this.drawingHits.push({target:e,screenRect:i,handle:o});}}drawingAtPoint(e){for(let n=this.drawingHits.length-1;n>=0;n--){let r=this.drawingHits[n];if(zl(r.screenRect,e))return r}}clearDrawingSelection(){this.selectedDrawing=null,this.cancelDrawingDrag();}cancelDrawingDrag(){let e=this.drawingDrag;e&&(this.drawingDrag=null,this.host.hasPointerCapture(e.pointerId)&&this.host.releasePointerCapture(e.pointerId),this.host.style.cursor="");}drawingDragRect(e,n){let r=this.layout,o=Bh(this.viewport,n),i=o?{x:o.x-e.startPoint.x,y:o.y-e.startPoint.y}:{x:n.x-e.startScreen.x,y:n.y-e.startScreen.y};return Rh(e.target.rect,i,{width:r.totalWidth(),height:r.totalHeight()},e.handle)}chartAnchorAtIndex(e){var o;let n=(o=this.runtimeValue)==null?void 0:o.activeSheet().source,r=n==null?void 0:n.charts[e];return r?Gl(n.drawings,r):void 0}chartAtPoint(e){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=Gl(n.drawings,i),s=da(this.layout,a);if(s&&pr(s,this.viewport).some(l=>zl(l,e)))return {chartIndex:o,logicalRect:s}}return null}updateResizeGuide(e){e.kind==="column"?Object.assign(this.resizeGuide.style,{display:"block",left:`${Math.round(e.currentGuidePosition)}px`,top:"0",bottom:"0",width:"2px",height:""}):Object.assign(this.resizeGuide.style,{display:"block",left:"0",top:`${Math.round(e.currentGuidePosition)}px`,right:"0",height:"2px",width:""});}hideResizeGuide(){this.resizeGuide.style.display="none";}fillSelectionFromEdge(e){let n=We(this.selectionState.range),r=v({},n);if(e==="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=na(this.runtime().activeSheet(),r);await this.runtime().pasteClipboard(o,n),this.cancelCopyOutline(),this.render(),await this.emitChange();})}gridBounds(){var e,n,r,o;return {rowCount:(n=(e=this.layout)==null?void 0:e.rowCount)!=null?n:this.runtime().activeSheet().maxRow,columnCount:(o=(r=this.layout)==null?void 0:r.columnCount)!=null?o:this.runtime().activeSheet().maxColumn}}navigateGrid(e,n=false,r=false){var a,s;let o=Ah(this.selectionState,e,{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(e){return this.cellEditor.contains(e)||[this.sheetTabs,this.contextMenu,this.filterMenu].some(n=>this.eventPathContains(e,n))||e.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(e,n=false,r=false){var p,b,w;if(!e.types.includes("text/plain")&&!Eo(e))return Promise.resolve();let o=e.getData("text/plain"),i=Eo(e),a=((p=this.clipboardPayload)==null?void 0:p.id)===i?this.clipboardPayload:void 0,s=(b=a!=null?a:Il(e))!=null?b:void 0,l=We(this.selectionState.range),d=this.selectionState,u=!!a&&this.clipboardCut&&!n,f=(w=s==null?void 0:s.values)!=null?w:Xp(o);return f.length?this.queueGridMutation(async()=>{let g,h=s!=null?s:{id:"external",text:o,values:f,sourceSheet:this.activeSheetName(),sourceRange:H(v({},l),{endRow:l.startRow+f.length-1,endColumn:l.startColumn+f.reduce((x,S)=>Math.max(x,S.length),0)-1}),formulas:f.map(x=>x.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(e,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,e,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,e,n);}showContextMenu(e,n,r){var i;this.contextMenu.replaceChildren();for(let a of e){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(e,n,r){var d;if(this.filterMenu.style.display==="block"&&this.filterMenuColumn===e){this.hideFilterMenu();return}let o=this.runtime().activeSheet(),i={startRow:1,endRow:o.maxRow,endColumn:o.maxColumn},a=new Set((d=this.columnFilters.get(e))!=null?d:Dl(o,i,e));this.filterMenuColumn=e,this.filterMenu.replaceChildren();let s=document.createElement("strong");s.textContent=`Filter ${e}`,s.style.display="block",s.style.marginBottom="6px",this.filterMenu.appendChild(s);for(let u of Dl(o,i,e)){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(e,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,e,o);return i.width>=28&&r.x>=i.x+i.width-22&&r.x<=i.x+i.width}async applyColumnFilters(){let e=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,e.maxRow,n),this.render(),await this.emitChange();}async sortColumn(e,n){await this.flushEdits();let r=this.runtime().activeSheet();await this.runtime().sortRows(1,r.maxRow,e,n),this.render(),await this.emitChange();}async sortActiveColumn(e){await this.flushEdits(),await this.sortColumn(this.selectionState.active.column,e);}async filterColumn(e,n){await this.flushEdits(),this.assertWritable(),n===null?this.columnFilters.delete(e):this.columnFilters.set(e,[...n]),await this.applyColumnFilters();}hideContextMenu(){this.contextMenu.style.display="none";}selectionContainsCell(e,n){let r=We(this.selectionState.range);return e>=r.startRow&&e<=r.endRow&&n>=r.startColumn&&n<=r.endColumn}async copySelection(e=false){await this.flushEdits(),e&&this.assertWritable();let n=We(this.selectionState.range),r=na(this.runtime().activeSheet(),n,{sourceWorkbookId:this.runtime().workbook().workbookId});this.clipboardPayload=r,this.clipboardCut=e,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([Tl(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 e=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)&&e.setData(o,await(await r.getType(o)).text());}else e.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(e);}clearSelection(){let e=We(this.selectionState.range);return this.queueGridMutation(async()=>{await this.runtime().clearRange(e.startRow,e.startColumn,e.endRow-e.startRow+1,e.endColumn-e.startColumn+1),this.cancelCopyOutline(),this.render(),await this.emitChange();})}queueGridMutation(e){let n=this.flushEdits().then(e);this.pendingGridMutation=n;let r=()=>{this.pendingGridMutation===n&&(this.pendingGridMutation=Promise.resolve());};return n.then(r,r),n}async clearSelectionFormat(){await this.flushEdits();let e=We(this.selectionState.range);await this.runtime().clearRangeFormat(e.startRow,e.startColumn,e.endRow-e.startRow+1,e.endColumn-e.startColumn+1),this.render(),await this.emitChange();}async applyFormat(e,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[e])!==true;e==="bold"&&await this.runtime().setRangeBold(n.startRow,n.startColumn,o,i,u),e==="italic"&&await this.runtime().setRangeItalic(n.startRow,n.startColumn,o,i,u),e==="underline"&&await this.runtime().setRangeUnderline(n.startRow,n.startColumn,o,i,u),this.cancelCopyOutline(),this.render(),await this.emitChange();}async applyAlignment(e){await this.flushEdits();let n=We(this.selectionState.range);await this.runtime().setRangeHorizontalAlign(n.startRow,n.startColumn,n.endRow-n.startRow+1,n.endColumn-n.startColumn+1,e),this.render(),await this.emitChange();}async mergeSelection(){await this.flushEdits();let e=We(this.selectionState.range);e.startRow===e.endRow&&e.startColumn===e.endColumn||(await this.runtime().mergeRange(e.startRow,e.startColumn,e.endRow-e.startRow+1,e.endColumn-e.startColumn+1),this.selectionState=ct(this.selectionState,this.runtime().activeSheet()),this.render(),await this.emitChange());}async unmergeSelection(){await this.flushEdits();let e=We(this.selectionState.range),n=[...this.runtime().activeSheet().mergeMasterByAddress.values()].filter(r=>nk(e,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 e=this.selectionState.active;await this.runtime().setFreezePanes(Math.max(0,e.row-1),Math.max(0,e.column-1)),this.render(),await this.emitChange();}async commitResizeDrag(e){var n,r,o;if(await this.flushEdits(),e.currentSize===e.startSize){this.render();return}if(e.kind==="column")await this.runtime().setColumnWidth(e.index,e.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(e.index,e.currentSize/i);}this.render(),await this.emitChange();}async openCellEditor(e){var f;if(await this.flushEdits(),this.disposed||this.isReadOnly()||!this.layout||!this.viewport)return;this.cancelCopyOutline();let n=this.selectionState.active,r=this.runtime().activeSheet(),o=qe(r,n.row,n.column),i=wo(r.styles,o==null?void 0:o.styleId,o),a=o!=null&&o.formula?`=${o.formula}`:(f=o==null?void 0:o.displayText)!=null?f:"",s=e===void 0&&(o==null?void 0:o.kind)==="string"?o.source.richText:void 0,l=s!=null&&s.length&&s.map(p=>p.text).join("")===a?s.map(p=>H(v({},p),{style:xo(r.styles,o==null?void 0:o.styleId,p)})):void 0,d=this.cellEditorRect(n,l!==void 0);if(!d)return;Object.assign(this.cellEditorElement.style,{font:i.font,color:i.fontColor,backgroundColor:i.fillColor,textDecoration:i.underline?"underline":"none",textAlign:i.horizontalAlign}),l&&(this.richEditorFrame.style.backgroundColor=i.fillColor,Object.assign(this.richEditorInput.style,{font:i.font,color:i.fontColor,textAlign:i.horizontalAlign,whiteSpace:i.wrapText||/[\r\n]/.test(a)?"pre-wrap":"pre",marginTop:i.verticalAlign==="top"?"0":"auto",marginBottom:i.verticalAlign==="bottom"?"0":"auto"})),this.editingCell=n,this.editingCellStyle=i,this.editingCellInitialValue=a;let u=e!=null?e:a;this.formulaReferenceRanges=Fh(u),this.cellEditor.open(d,u,l),this.render();}async commitCellEdit(e,n){let r=this.editingCell,o=this.editingCellInitialValue;if(this.editingCell=null,this.editingCellInitialValue=null,this.editingCellStyle=null,this.formulaReferenceRanges=[],!r)return;if(e===o){this.render();return}this.assertWritable();let i=formatCellAddress(r.row,r.column);n!=null&&n.length?await this.runtime().setCellRichText(i,n):e.startsWith("=")?await this.runtime().setCellFormula(i,e.slice(1)):await this.runtime().setCellValue(i,X0(e)),this.render(),await this.emitChange();}eventPoint(e){let n=this.host.getBoundingClientRect();return {x:e.clientX-n.left,y:e.clientY-n.top}}assertWritable(){if(this.isReadOnly())throw new hn("spreadsheet")}eventPathContains(e,n){return e.composedPath().includes(n)}updateCellEditorPosition(){let e=this.editingCell;if(!e)return;let n=this.cellEditor.isRich(),r=this.cellEditorRect(e,n);this.cellEditor.place(r),!n&&r&&this.editingCellStyle&&this.alignCellEditor(r,this.editingCellStyle);}cellEditorRect(e,n){var h;let r=this.layout,o=this.viewport;if(!r||!o)return null;let i=We(this.selectionState.range),a=o.viewports.filter(Ul),s=(h=a.find(x=>e.row>=x.rows.start&&e.row<=x.rows.end&&e.column>=x.columns.start&&e.column<=x.columns.end))!=null?h:a.find(({rows:x,columns:S})=>x.start<=i.endRow&&x.end>=i.startRow&&S.start<=i.endColumn&&S.end>=i.startColumn);if(!s)return null;let l=o.cellScreenRect(i.startRow,i.startColumn,s),d=o.cellScreenRect(i.endRow,i.endColumn,s),u={x:l.x,y:l.y,width:d.x+d.width-l.x,height:d.y+d.height-l.y};if(!n)return u;let f=s.screenRect,p=Math.max(u.x,f.x),b=Math.max(u.y,f.y),w=Math.min(u.x+u.width,f.x+f.width)-p,g=Math.min(u.y+u.height,f.y+f.height)-b;return w>0&&g>0?{x:p,y:b,width:w,height:g}:null}alignCellEditor(e,n){let r=this.cellEditorElement,o=4,i=2;r.style.padding=`${i}px ${o}px`;let a=Math.max(0,e.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 e={kind:"workbookChange",bytes:await this.runtime().toZip()};for(let o of this.listeners)o(e);await((r=(n=this.options).onChange)==null?void 0:r.call(n,e));}emitStateIfChanged(e){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=`${e}|${r}`;if(o===this.lastStateKey)return;this.lastStateKey=o;let i={kind:"stateChange",activeSheetName:e,selection:n,editingCell:this.editingCell};for(let u of this.stateListeners)u(i);}reportError(e){let n=e instanceof Error?e:new Error(String(e));this.options.onError?this.options.onError(n):console.error("[spreadsheet-editor]",n);}async runSheetUiAction(e){if(!this.sheetActionPending){this.sheetActionPending=true,this.hideContextMenu(),this.hideFilterMenu(),this.renderTabs();try{await this.flushEdits(),await e(),this.host.focus({preventScroll:!0});}catch(n){this.reportError(n);}finally{this.sheetActionPending=false,this.disposed||this.renderTabs();}}}async createSheetFromTabs(){let e=new Set(this.runtime().model().sheets.map(r=>r.name.toLowerCase())),n=1;for(;e.has(`sheet${n}`);)n+=1;await this.addSheet(`Sheet${n}`);}requestSheetDeletion(e,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:e,onConfirm:()=>{this.runSheetUiAction(async()=>{this.isReadOnly()||this.runtime().model().sheets.length<=1||await this.deleteSheet(e);});}}));}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 e of this.runtimeValue.model().sheets){let n=e.name===this.runtimeValue.activeSheetName(),r=document.createElement("button");r.type="button",r.textContent=e.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(e.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${e.name}\u201D`),i.title=a?"\u5DE5\u4F5C\u7C3F\u81F3\u5C11\u4FDD\u7559\u4E00\u5F20\u5DE5\u4F5C\u8868":`\u5220\u9664\u5DE5\u4F5C\u8868\u201C${e.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(e.name,i)),o.appendChild(i);}this.sheetTabs.appendChild(o);}if(!this.isReadOnly()){let e=document.createElement("button");e.type="button",e.setAttribute("aria-label","\u65B0\u5EFA\u5DE5\u4F5C\u8868"),e.title="\u65B0\u5EFA\u5DE5\u4F5C\u8868",e.disabled=this.sheetActionPending,e.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(e.style,{width:"32px",height:"32px",display:"grid",placeItems:"center",flexShrink:"0",border:"0",borderRadius:"4px",background:"transparent",color:"#475569",cursor:"pointer"}),e.addEventListener("mouseenter",()=>{e.style.background="#e2e8f0";}),e.addEventListener("mouseleave",()=>{e.style.background="transparent";}),e.addEventListener("click",()=>{this.runSheetUiAction(()=>this.createSheetFromTabs());}),this.sheetTabs.appendChild(e);}}}configureScrollbar(e,n,r){e.className="coco-spreadsheet-editor-scrollbar",Object.assign(e.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"}),e.appendChild(n),e.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=e.getBoundingClientRect(),s=r?o.clientX-a.left:o.clientY-a.top;this.drag={axis:r?"horizontal":"vertical",pointer:s,thumb:i.thumbStart},e.setPointerCapture(o.pointerId),this.setScroll(r?ia(i,s-i.thumbLength/2):this.scroll.x,r?this.scroll.y:ia(i,s-i.thumbLength/2));}),e.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=e.getBoundingClientRect(),l=r?o.clientX-s.left:o.clientY-s.top,d=ia(a,i.thumb+l-i.pointer);this.setScroll(r?d:this.scroll.x,r?this.scroll.y:d);}),e.addEventListener("pointerup",()=>{this.drag=null;});}updateScrollbars(){let e=this.scrollbarState,n=this.layout,r=this.viewport;if(!e||!n||!r)return;let o=e.horizontal,i=e.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(e,n){this.scroll={x:e,y:n},this.render();}assertAlive(){if(this.disposed)throw new Error("SpreadsheetEditor: editor has been destroyed")}};function X0(t){if(t==="")return null;if(t==="TRUE")return true;if(t==="FALSE")return false;let e=Number(t);return Number.isFinite(e)&&t.trim()!==""?e:t}function zl(t,e){return e.x>=t.x&&e.y>=t.y&&e.x<=t.x+t.width&&e.y<=t.y+t.height}function Vl(t){return {position:"absolute",left:`${t.x}px`,top:`${t.y}px`,width:`${t.width}px`,height:`${t.height}px`}}function Wh(t,e){return e!==null&&t.sheetId===e.sheetId&&t.drawingIndex===e.drawingIndex&&t.anchorIndex===e.anchorIndex}function Bh(t,e){let n=t.findViewport(e);if(!(!n||!Ul(n)))return {x:e.x-n.screenRect.x+n.originX,y:e.y-n.screenRect.y+n.originY}}function Gl(t,e){var o;let n=t.find(i=>i.path===e.drawingPath);return ((o=n==null?void 0:n.anchors)!=null?o:t.flatMap(i=>i.anchors)).find(i=>{var a;return ((a=i.object)==null?void 0:a.kind)==="chart"&&(!e.relationshipId||i.object.relationshipId===e.relationshipId)})}function Y0(t){var o,i;if(((o=t.object)==null?void 0:o.kind)!=="shape")return null;let e=(i=t.object.name)!=null?i:"",n=e.match(/^coco-tianzige-(horizontal|vertical)-/);if(n!=null&&n[1])return {orientation:n[1],dash:"dashed"};if(/^coco-pinyin-guide-/.test(e))return {orientation:"horizontal",dash:"dashed"};let r=e.match(/^coco-(?:tianzige|pinyin)-outline-\d+-(top|bottom|vertical)(?:-|$)/);return r!=null&&r[1]?{orientation:r[1]==="vertical"?"vertical":"horizontal",dash:"solid"}:null}function da(t,e){var u,f;if(!e||e.kind==="absolute"||!e.from)return null;let n=hr(e.from.column),r=hr(e.from.row),o=e.to?hr(e.to.column):n+5,i=e.to?hr(e.to.row):r+12,a=t.getColumnX(n)+t.emuToCssPixels(e.from.columnOffset),s=t.getRowY(r)+t.emuToCssPixels(e.from.rowOffset),l=t.getColumnX(o)+t.emuToCssPixels((u=e.to)==null?void 0:u.columnOffset),d=t.getRowY(i)+t.emuToCssPixels((f=e.to)==null?void 0:f.rowOffset);return {x:a,y:s,width:Math.max(1,l-a),height:Math.max(1,d-s)}}function Z0(t,e){if(e.kind==="twoCell")return e.from&&e.to?da(t,e):null;let n=t.emuToCssPixels(e.width),r=t.emuToCssPixels(e.height);return n<=0||r<=0?null:e.kind==="absolute"?{x:t.emuToCssPixels(e.x),y:t.emuToCssPixels(e.y),width:n,height:r}:e.from?{x:t.getColumnX(hr(e.from.column))+t.emuToCssPixels(e.from.columnOffset),y:t.getRowY(hr(e.from.row))+t.emuToCssPixels(e.from.rowOffset),width:n,height:r}:null}function pr(t,e){let n=[];for(let r of e.viewports){if(!Ul(r))continue;let o=r.originX,i=r.originY,a=r.originX+r.screenRect.width,s=r.originY+r.screenRect.height,l=Math.max(t.x,o),d=Math.max(t.y,i),u=Math.min(t.x+t.width,a),f=Math.min(t.y+t.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,clipLeft:l-t.x,clipTop:d-t.y});}return n}function J0(t,e,n){let r=Io(t,e.x,e.y),o=n.to?Io(t,e.x+e.width,e.y+e.height):void 0;return {from:r,to:o}}function Ul(t){return t.kind==="main"||t.kind==="frozenTop"||t.kind==="frozenLeft"||t.kind==="frozenTopLeft"}function hr(t){return Math.max(1,Math.floor(t!=null?t:0)+1)}function Q0(t){let e=0;for(let n of t.toUpperCase())e=e*26+n.charCodeAt(0)-64;return e}function ek(t,e){var l,d,u,f,p;let n=e.getContext("2d");if(!n)return 7;let r=(l=t.styles.cellFormats[0])!=null?l:{},o=(u=t.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 tk(t,e){if(e.kind!=="cell")return null;let n=Math.max(0,e.row-t.endRow),r=Math.max(0,e.column-t.endColumn);return !n&&!r?null:n>=r?H(v({},t),{endRow:t.endRow+n}):H(v({},t),{endColumn:t.endColumn+r})}function nk(t,e){return !(t.endRow<e.startRow||t.startRow>e.endRow||t.endColumn<e.startColumn||t.startColumn>e.endColumn)}function Fh(t){var r;if(!t.startsWith("="))return [];let e=(r=t.match(/(?:\$?[A-Z]{1,3}\$?\d+)(?::(?:\$?[A-Z]{1,3}\$?\d+))?/g))!=null?r:[],n=["#DC2626","#16A34A","#7C3AED","#EA580C","#0891B2"];return e.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=Hh(s),u=Hh(l);return !d||!u?[]:[{range:We({startRow:d.row,startColumn:d.column,endRow:u.row,endColumn:u.column}),stroke:(b=n[i%n.length])!=null?b:"#DC2626"}]})}function Hh(t){var o,i;let e=t.replace(/\$/g,"").match(/^([A-Z]{1,3})(\d+)$/);if(!e)return null;let n=0;for(let a of (o=e[1])!=null?o:"")n=n*26+a.charCodeAt(0)-64;let r=Number((i=e[2])!=null?i:"");return Number.isFinite(r)&&r>0&&n>0?{row:r,column:n}:null}var ok={width:9144e3,height:5143500},ua=new Set(["placeholder","textBox","geometricShape","line"]),Vh=new WeakMap;function Po(t){var n;let e=(n=t.slideSize)!=null?n:ok;return {size:e,slides:t.slides.map(r=>ik(r,e))}}function ik(t,e){var l,d,u,f,p,b,w,g,h,x;let n=(d=(l=t.layout)==null?void 0:l.shapes)!=null?d:[],o=[...[...((p=(f=(u=t.layout)==null?void 0:u.master)==null?void 0:f.shapes)!=null?p:[]).map(S=>Kl(S,"master")),...n.map(S=>Kl(S,"layout"))].filter(sk),...t.shapes.map(S=>dk(S,t.layout))],i=o.flatMap(Gh),a=(x=(w=t.background)!=null?w:(b=t.layout)==null?void 0:b.background)!=null?x:(h=(g=t.layout)==null?void 0:g.master)==null?void 0:h.background,s=a!=null?a:ak(o,e);return H(v({id:t.id,index:t.index,name:t.name,title:t.title,size:e},a?{background:a}:{}),{nodes:i.map((S,k)=>Ro(S,{slideSize:e,index:k,background:a,backgroundFill:s})),groups:o.flatMap(S=>jh(S,{background:a,backgroundFill:s})),source:t})}function ak(t,e){var r;let n=t.find(o=>{var a;let i=To(o.geometry);return o.kind==="picture"&&!!((a=o.image)!=null&&a.targetPath)&&i.left<=e.width*.02&&i.top<=e.height*.02&&i.width>=e.width*.96&&i.height>=e.height*.96});return (r=n==null?void 0:n.image)!=null&&r.targetPath?{imagePath:n.image.targetPath}:void 0}function Kl(t,e){var n;return H(v({},t),{id:`${e}:${t.id}`,children:(n=t.children)==null?void 0:n.map(r=>Kl(r,e))})}function sk(t){return t.placeholder?false:t.kind==="group"||t.kind==="picture"||t.kind==="geometricShape"||t.kind==="line"||t.kind==="textBox"}function Gh(t){var e;return t.kind!=="group"?[t]:((e=t.children)!=null?e:[]).flatMap(n=>Gh(Uh(t,n)))}function jh(t,e={}){var n;return t.kind!=="group"?[]:[Ro(t,{background:e.background,backgroundFill:e.backgroundFill}),...((n=t.children)!=null?n:[]).map(r=>Uh(t,r)).flatMap(r=>jh(r,e))]}function Uh(t,e){var I,D,F,A,O;let n=To(t.geometry),r=(I=t.raw)==null?void 0:I.groupTransform,o=To(e.geometry),i=(D=r==null?void 0:r.childLeft)!=null?D: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,x=lk({left:g,top:h,width:b,height:w},n),S=Kh(((A=n.rotation)!=null?A:0)+((O=o.rotation)!=null?O:0)),k=H(v({},e),{id:`${t.id}:${e.id}`,geometry:H(v({},e.geometry),{left:x.left,top:x.top,width:b,height:w,rotation:S,flipHorizontal:!!n.flipHorizontal!=!!o.flipHorizontal,flipVertical:!!n.flipVertical!=!!o.flipVertical}),children:e.children});return Vh.set(k,{parentId:t.id,parentName:t.name,parentBounds:n,parentTransform:{childLeft:i,childTop:a,childWidth:s,childHeight:l}}),k}function lk(t,e){if(!e.rotation)return t;let n=e.rotation*Math.PI/180,r=e.left+e.width/2,o=e.top+e.height/2,i=t.left+t.width/2,a=t.top+t.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({},t),{left:d-t.width/2,top:u-t.height/2})}function Kh(t){let e=(t%360+360)%360;return e===0?void 0:e}function dk(t,e){if(!t.placeholder)return t;let n=resolvePptEffectivePlaceholderProperties(t,e);return v(H(v({},t),{placeholder:n.placeholder,geometry:n.geometry,style:n.style}),t.text?{text:H(v({},t.text),{style:n.textStyle,body:n.textBody})}:{})}function Ro(t,e={}){var d,u,f,p,b,w,g,h,x,S,k,I,D,F,A,O,ee;let n=_h(t),r=n.editText||n.editTextStyle||n.editTableCells||n.editGeometry||n.editShapeStyle,o=t.style,i=((d=t.raw)==null?void 0:d.useBackgroundFill)===true,a=i?void 0:(f=(u=t.style)==null?void 0:u.fillColor)!=null?f:fk(t,e),s=pk((p=t.text)==null?void 0:p.style,{fillColor:a,background:e.background}),l=To(t.geometry);return H(v({id:t.id,name:t.name,kind:t.kind,bounds:uk(t,l),text:(w=(b=t.text)==null?void 0:b.text)!=null?w:ck(t),textStyle:s,textParagraphs:(g=t.text)==null?void 0:g.paragraphs,textBody:(h=t.text)==null?void 0:h.body,imagePath:(x=t.image)==null?void 0:x.targetPath,imageCrop:(S=t.image)==null?void 0:S.crop,imageFillRect:(k=t.image)==null?void 0:k.fillRect,imageOpacity:(I=t.image)==null?void 0:I.opacity,chart:t.chart,table:t.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:(D=t.raw)==null?void 0:D.presetGeometry,presetAdjustments:(F=t.raw)==null?void 0:F.presetAdjustments,customGeometry:(A=t.raw)==null?void 0:A.customGeometry,threeD:(O=t.raw)==null?void 0:O.threeD,usesBackgroundFill:i},i&&e.backgroundFill?{backgroundFill:e.backgroundFill}:{}),{locked:!r,editable:r,capabilities:n,groupContext:wk(t),source:t,children:((ee=t.children)!=null?ee:[]).map(le=>Ro(le,{background:e.background,backgroundFill:e.backgroundFill}))})}function ck(t){if(t.table)return t.table.values.map(e=>e.join(" ")).join(`
|
|
1697
|
+
`)}function uk(t,e){if(!t.table)return e;let n=Oh(t.table.columnWidths),r=Oh(t.table.rowHeights);return n===void 0&&r===void 0?e:v(v(v({},e),$h(e.width,n)?{width:n}:{}),$h(e.height,r)?{height:r}:{})}function Oh(t){if(!(t!=null&&t.length))return;let e=t.reduce((n,r)=>n+r,0);return Number.isFinite(e)&&e>0?e:void 0}function $h(t,e){return e===void 0?false:!Number.isFinite(t)||t<=0?true:e/t>1.15}function fk(t,e){var o;let n=To(t.geometry),r=e.slideSize;if(e.index===0&&t.kind==="geometricShape"&&!((o=t.text)!=null&&o.text)&&r&&n.left<=0&&n.top<=0&&n.width>=r.width*.95&&n.height>=r.height*.95)return "#1D3F80"}function pk(t,e){var r,o;if(t!=null&&t.color)return t;let n=(o=e.fillColor)!=null?o:(r=e.background)==null?void 0:r.fillColor;return !n||!hk(n)?t:H(v({},t),{color:"#FFFFFF"})}function hk(t){let e=/^#?([0-9a-f]{6})$/i.exec(t);if(!e)return false;let n=e[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 uR(t){let e=_h(t);return e.editText||e.editTextStyle||e.editTableCells||e.editGeometry||e.editShapeStyle}function _h(t){if(gk(t))return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:false,editShapeStyle:false,reason:"Inherited from layout/master",reasons:zh("\u7EE7\u627F\u81EA\u6BCD\u7248/\u7248\u5F0F\uFF0C\u5F53\u524D\u53EA\u652F\u6301\u67E5\u770B")};if(bk(t)){let n=!!t.text&&ua.has(t.kind),r=t.kind==="table"&&!!t.table;return {select:true,editText:n,editTextStyle:n,editTableCells:r,editGeometry:true,editShapeStyle:false,reason:"Flattened group child",reasons:No({editText:n?void 0:ca(t),editTextStyle:n?void 0:ca(t),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(t.kind==="table")return {select:true,editText:false,editTextStyle:false,editTableCells:true,editGeometry:true,editShapeStyle:true,reasons:No({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(t.kind==="picture")return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:No({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(t.kind==="chart"||t.kind==="smartArt"||t.kind==="group"){let n=mk(t.kind);return {select:true,editText:false,editTextStyle:false,editTableCells:false,editGeometry:true,editShapeStyle:false,reason:"Limited editor support for this object type",reasons:No({editText:n.text,editTextStyle:n.textStyle,editTableCells:"\u5F53\u524D\u5BF9\u8C61\u4E0D\u662F\u8868\u683C",editShapeStyle:n.shapeStyle})}}let e=!!t.text&&ua.has(t.kind);return ua.has(t.kind)?{select:true,editText:e,editTextStyle:e,editTableCells:false,editGeometry:true,editShapeStyle:true,reasons:No({editText:e?void 0:ca(t),editTextStyle:e?void 0:ca(t),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:zh("\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B\u6682\u4E0D\u652F\u6301\u5E38\u89C4\u7F16\u8F91")}}function No(t){return Object.fromEntries(Object.entries(t).filter(e=>!!e[1]))}function zh(t){return {editText:t,editTextStyle:t,editTableCells:t,editGeometry:t,editShapeStyle:t}}function ca(t){return t.text?ua.has(t.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 mk(t){return t==="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"}:t==="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 gk(t){return t.id.startsWith("layout:")||t.id.startsWith("master:")}function bk(t){return t.id.includes(":")}function qh(t,e){var b;if(!t.groupContext)return e;let n=t.groupContext.parentBounds,r=t.groupContext.parentTransform,o=v(v({},t.bounds),e),i=n.width/(r.childWidth||n.width||1),a=n.height/(r.childHeight||n.height||1),s=xk(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 e.left!==void 0&&(p.left=u/i+r.childLeft),e.top!==void 0&&(p.top=f/a+r.childTop),e.width!==void 0&&(p.width=o.width/i),e.height!==void 0&&(p.height=o.height/a),e.rotation!==void 0&&(p.rotation=Kh(e.rotation-((b=n.rotation)!=null?b:0))),e.flipHorizontal!==void 0&&(p.flipHorizontal=!!n.flipHorizontal!=!!e.flipHorizontal),e.flipVertical!==void 0&&(p.flipVertical=!!n.flipVertical!=!!e.flipVertical),p}function wk(t){return Vh.get(t)}function xk(t,e,n){if(!n.rotation)return {x:t,y:e};let r=-n.rotation*Math.PI/180,o=n.left+n.width/2,i=n.top+n.height/2,a=t-o,s=e-i;return {x:o+a*Math.cos(r)-s*Math.sin(r),y:i+a*Math.sin(r)+s*Math.cos(r)}}function To(t={}){var e,n,r,o;return {left:(e=t.left)!=null?e:0,top:(n=t.top)!=null?n:0,width:(r=t.width)!=null?r:0,height:(o=t.height)!=null?o:0,rotation:t.rotation,flipHorizontal:t.flipHorizontal,flipVertical:t.flipVertical}}function mr(t,e){var n,r;return typeof e=="number"?(n=t.slides.find(o=>o.index===e))!=null?n:null:(r=t.slides.find(o=>o.id===e||o.name===e))!=null?r:null}function Mo(t,e){let n=[...t.nodes,...t.groups];for(;n.length>0;){let r=n.shift();if(r.id===e||r.name===e)return r;n.unshift(...r.children);}return null}async function gR(t,e={}){let n=await Presentation.fromZip(t,{presentationId:e.presentationId,mode:"inline"});return Yh(n,e)}async function bR(t,e={}){var r;let n=await Presentation.fromModel(t,{presentationId:(r=e.presentationId)!=null?r:t.id,mode:"inline"});return Yh(n,e)}async function Yh(t,e={}){let[n,r,o]=await Promise.all([t.toModel(),yk(t,e),vk(t)]);return {presentation:t,model:n,scene:Po(n),images:r,fonts:o}}async function yk(t,e){if(typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return {};let n=await t.exportImages(),r=await Promise.all(n.map(async o=>{var a;let i=await((a=e.resolveImagePreview)==null?void 0:a.call(e,{path:o.path,contentType:o.contentType,bytes:o.bytes}));return [o.path,i!=null?i:{url:URL.createObjectURL(new Blob([Zh(o.bytes)],{type:o.contentType})),contentType:o.contentType}]}));return Object.fromEntries(r)}async function vk(t){return typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function"?[]:(await t.exportFonts()).map(n=>v(v({url:URL.createObjectURL(new Blob([Zh(n.bytes)],{type:n.contentType})),contentType:n.contentType,family:n.family},n.weight?{weight:n.weight}:{}),n.style?{style:n.style}:{}))}function Zh(t){let e=new Uint8Array(t.byteLength);return e.set(t),e.buffer}var fa=class{constructor(e,n={}){W(this,"presentationValue");W(this,"modelValue");W(this,"sceneValue");W(this,"selectionValue",null);W(this,"revisionValue",0);W(this,"undoStack",[]);W(this,"redoStack",[]);W(this,"textBodyOverrides",new Map);W(this,"maxHistory");W(this,"readOnlyValue");W(this,"changeListeners",new Set);W(this,"selectionListeners",new Set);var r;this.presentationValue=e.presentation,this.modelValue=e.model,this.sceneValue=e.scene,this.maxHistory=(r=n.maxHistory)!=null?r:50,this.readOnlyValue=n.readOnly===true,this.selectionValue=e.scene.slides[0]?{kind:"slide",slideId:e.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(e){this.readOnlyValue=e;}canUndo(){return !this.readOnlyValue&&this.undoStack.length>0}canRedo(){return !this.readOnlyValue&&this.redoStack.length>0}subscribe(e,n){let r=e==="change"?this.changeListeners:this.selectionListeners;return r.add(n),()=>r.delete(n)}async dispatch(e){if(e.kind==="select-slide"||e.kind==="select-shape"){await this.applySelectionCommand(e);return}this.assertWritable();let n=await this.presentationValue.toZip(),r=await this.applyEditCommand(e);this.pushUndo(n),this.redoStack.length=0,await this.refreshAfterChange(e),r!==void 0&&this.setSelection(r);}async undo(){this.assertWritable();let e=this.undoStack.pop();if(!e)return;let n=this.selectionValue;this.redoStack.push(this.historyEntry(await this.presentationValue.toZip())),this.restoreTextBodyOverrides(e.textBodyOverrides),await this.replacePresentation(e.bytes,n);}async redo(){this.assertWritable();let e=this.redoStack.pop();if(!e)return;let n=this.selectionValue;this.undoStack.push(this.historyEntry(await this.presentationValue.toZip())),this.restoreTextBodyOverrides(e.textBodyOverrides),await this.replacePresentation(e.bytes,n);}async loadPresentation(e){this.undoStack.length=0,this.redoStack.length=0,this.textBodyOverrides.clear(),await this.replacePresentation(e);}async toPptx(){return this.presentationValue.toZip()}async verifyExport(){let e=await this.toPptx(),n=await Presentation.fromZip(e,{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 hn("ppt")}async applySelectionCommand(e){let n=mr(this.sceneValue,e.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(e.slideIdOrIndex)}`);if(e.kind==="select-slide"){this.setSelection({kind:"slide",slideId:n.id});return}let r=Mo(n,e.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${e.shapeIdOrName}`);this.setSelection({kind:"shape",slideId:n.id,shapeId:r.id});}async applyEditCommand(e){var a,s;if(e.kind==="delete-shape"||e.kind==="duplicate-shape"||e.kind==="paste-shape"||e.kind==="bring-shape-to-front"||e.kind==="send-shape-to-back")return this.applyShapeCollectionCommand(e);let n=this.assertEditableSceneNodeForCommand(e),r=mr(this.sceneValue,e.slideIdOrIndex);if(!r)throw new Error(`PPT slide not found: ${String(e.slideIdOrIndex)}`);let o=this.presentationValue.slides.getItem(e.slideIdOrIndex),i=Ik(o.shapes,e.shapeIdOrName);if(e.kind==="set-shape-text"){await i.text.setText(e.text,{preserveFirstRunStyle:true});return}if(e.kind==="set-shape-text-style"){await i.text.setTextStyle(e.style);return}if(e.kind==="set-table-cell-text"){await i.table.setCellText(e.row,e.column,e.text);return}if(e.kind==="set-shape-geometry"){if(e.preserveTextSizeOnResize&&kk(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(Sk(r.id,n.id),l);}await i.setGeometry(qh(n,e.geometry));return}await i.setStyle(e.style);}assertEditableSceneNodeForCommand(e){var o;let n=mr(this.sceneValue,e.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(e.slideIdOrIndex)}`);let r=(o=Mo(n,e.shapeIdOrName))!=null?o:Ck(n,e.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${e.shapeIdOrName}`);if(Nk(e)&&(r.locked||r.id.includes(":")||!r.editable))throw new Error(`PPT shape collection operation is not editable: ${r.id}`);if(e.kind==="set-shape-text"&&!r.capabilities.editText)throw new Error(`PPT shape is not text-editable: ${r.id}`);if(e.kind==="set-shape-text-style"&&!r.capabilities.editTextStyle)throw new Error(`PPT shape text style is not editable: ${r.id}`);if(e.kind==="set-table-cell-text"&&!r.capabilities.editTableCells)throw new Error(`PPT shape table cells are not editable: ${r.id}`);if(e.kind==="set-shape-geometry"&&!r.capabilities.editGeometry)throw new Error(`PPT shape geometry is not editable: ${r.id}`);if(e.kind==="set-shape-style"&&!r.capabilities.editShapeStyle)throw new Error(`PPT shape style is not editable: ${r.id}`);return r}async applyShapeCollectionCommand(e){var d,u,f,p,b,w,g,h;this.assertEditableSceneNodeForCommand(e);let n=mr(this.sceneValue,e.slideIdOrIndex);if(!n)throw new Error(`PPT slide not found: ${String(e.slideIdOrIndex)}`);let r=Mo(n,e.shapeIdOrName);if(!r)throw new Error(`PPT shape not found: ${e.shapeIdOrName}`);let i=this.presentationValue.slides.getItem(e.slideIdOrIndex).shapes.getItem(e.shapeIdOrName);if(e.kind==="delete-shape")return await i.delete(),{kind:"slide",slideId:n.id};if(e.kind==="bring-shape-to-front")return await i.bringToFront(),{kind:"shape",slideId:n.id,shapeId:r.id};if(e.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=e.offset)==null?void 0:d.left)!=null?u:18e4):r.bounds.left,top:typeof r.bounds.top=="number"?r.bounds.top+((p=(f=e.offset)==null?void 0:f.top)!=null?p:18e4):r.bounds.top,width:(w=(b=e.offset)==null?void 0:b.width)!=null?w:r.bounds.width,height:(h=(g=e.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(e){this.modelValue=await this.presentationValue.toModel(),this.sceneValue=Po(this.modelValue),this.applyTextBodyOverrides(),this.revisionValue+=1,this.changeListeners.forEach(n=>n({revision:this.revisionValue,command:e,model:this.modelValue,scene:this.sceneValue}));}async replacePresentation(e,n=null){let r=await Presentation.fromZip(e,{mode:"inline"});if(await this.presentationValue.dispose(),this.presentationValue=r,this.modelValue=await r.toModel(),this.sceneValue=Po(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(e){this.selectionValue=e,this.selectionListeners.forEach(n=>n({selection:e}));}pushUndo(e){this.undoStack.push(this.historyEntry(e)),this.undoStack.length>this.maxHistory&&this.undoStack.shift();}historyEntry(e){return {bytes:e,textBodyOverrides:new Map(this.textBodyOverrides)}}restoreTextBodyOverrides(e){this.textBodyOverrides.clear(),e.forEach((n,r)=>this.textBodyOverrides.set(r,v({},n)));}applyTextBodyOverrides(){var e;for(let[n,r]of this.textBodyOverrides){let[o,i]=n.split("\0");if(!o||!i)continue;let a=mr(this.sceneValue,o),s=a?Mo(a,i):null;!s||!s.text&&!((e=s.textParagraphs)!=null&&e.length)||(s.textBody=v(v({},s.textBody),r));}}};function Sk(t,e){return `${t}\0${e}`}function kk(t){var e;return !!(t.capabilities.editGeometry&&Ek(t)&&(t.text||(e=t.textParagraphs)!=null&&e.length))}function Ek(t){return t.kind==="placeholder"||t.kind==="textBox"||t.kind==="geometricShape"}function Ck(t,e){let n=t.source.shapes.find(r=>r.id===e||r.name===e);return n?Ro(n,{slideSize:t.size,background:t.background}):null}function Ik(t,e){let n=e.split(":").filter(Boolean);if(n.length<=1)return t.getItem(e);let r=t.getItem(n[0]);for(let o of n.slice(1))r=r.group.getItem(o);return r}function Nk(t){return t.kind==="delete-shape"||t.kind==="duplicate-shape"||t.kind==="paste-shape"||t.kind==="bring-shape-to-front"||t.kind==="send-shape-to-back"}var Qh=24e4,Lo=91440,Tk=91440,_l=4,em=7,gr=128,Pk=8,pa=2,Rk=2,ha=4;function PR(t,e,n={}){return new Yl(t,e,n)}function Mk(t){if(t.kind==="line"||t.kind!=="geometricShape"||t.customGeometry||t.presetGeometry&&t.presetGeometry!=="ellipse"||t.text||!t.fillColor)return false;let e=Math.min(t.bounds.width,t.bounds.height),n=Math.max(t.bounds.width,t.bounds.height);return e<=0?false:n/e<1.2}function In(t,e,n){var d,u,f,p;let r=Math.max(Lo,(d=n.width)!=null?d:t.width),o=Math.max(Lo,(u=n.height)!=null?u:t.height),i=Math.min(Qh,r),a=Math.min(Qh,o),s=Sa((f=n.left)!=null?f:t.left,-r+i,e.width-i),l=Sa((p=n.top)!=null?p:t.top,-o+a,e.height-a);return H(v({},t),{left:s,top:l,width:r,height:o})}function Sa(t,e,n){return Math.max(e,Math.min(n,t))}function ma(t,e,n){let r=n==="x"?t.size.width:t.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 t.nodes){if(!Ak(i,e))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 Ak(t,e){return t.id!==e&&t.kind!=="line"&&!t.locked&&!t.id.includes(":")&&t.capabilities.select&&t.capabilities.editGeometry&&t.bounds.width>Lo&&t.bounds.height>Lo}function ga(t,e,n,r={}){let o=null;for(let i of t)for(let a of e){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 tm(t,e,n,r){let o=e/2,i=Math.abs(n.offset-o)<1?(r-t)*2:r-t;return Math.max(Lo,i)}function jn(t){return !t.locked&&!t.id.includes(":")&&(t.capabilities.editGeometry||t.capabilities.editText||t.capabilities.editShapeStyle||t.capabilities.editTableCells)}function Lk(t){let e=t.groupContext;return e?H(v({},t),{id:e.parentId,name:e.parentName,kind:"group",bounds:e.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:[]}):t}function Dk(t){var i,a;if(t.kind!=="picture"||!t.customGeometry||t.customGeometry.paths.length!==1)return false;let e=Math.min(t.bounds.width,t.bounds.height),n=Math.max(t.bounds.width,t.bounds.height);if(e<=0||n/e>1.12)return false;let r=(a=(i=t.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 Yl=class{constructor(e,n,r){W(this,"root");W(this,"sessionValue");W(this,"imageResources");W(this,"fontResources");W(this,"referencedFontFamilies");W(this,"slideList",document.createElement("div"));W(this,"canvas",document.createElement("div"));W(this,"contextMenu",document.createElement("div"));W(this,"snapGuides",document.createElement("div"));W(this,"options");W(this,"handleCanvasClick",()=>{this.dispatchCurrentSlideSelection();});W(this,"handleWindowMouseMove",e=>{this.updateDrag(e);});W(this,"handleWindowMouseUp",e=>{this.finishDrag(e);});W(this,"handleWindowKeyDown",e=>{this.handleKeyDown(e);});W(this,"handleWindowPointerDown",e=>{this.dismissContextMenu(e);});W(this,"handleWindowScroll",()=>this.hideContextMenu());W(this,"handleCanvasSelectStart",e=>this.handleSelectStart(e));W(this,"handleSlideListScroll",()=>this.scheduleThumbnailRender());W(this,"dragState",null);W(this,"suppressClickAfterDrag",false);W(this,"clipboardShape",null);W(this,"thumbnailFrame",0);W(this,"thumbnailRasterEpoch",0);W(this,"thumbnailCanvasCache",new Map);W(this,"pendingCommands",new Set);this.options=r,this.root=r.styleIsolation==="none"?e:e.attachShadow({mode:"open"}),this.sessionValue=new fa(n,{readOnly:r.readOnly}),this.imageResources=n.images,this.fontResources=n.fonts,this.referencedFontFamilies=_k(n);let o=Kk(this.fontResources,this.referencedFontFamilies);qk(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(e){if(this.isReadOnly()===e)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(e),this.render();}async dispatch(e){let n=this.dispatchAndRender(e);this.pendingCommands.add(n);try{await n;}finally{this.pendingCommands.delete(n);}}async dispatchAndRender(e){var r,o;let n=(r=this.currentSlide())==null?void 0:r.id;if(await this.sessionValue.dispatch(e),e.kind==="select-slide"||e.kind==="select-shape"){if(((o=this.currentSlide())==null?void 0:o.id)!==n){this.render();return}this.renderSelection();return}this.render();}async loadPresentation(e){await this.sessionValue.loadPresentation(e),this.thumbnailCanvasCache.clear(),this.thumbnailRasterEpoch++,this.render();}async toPptx(){var e;return (e=this.root.querySelector('[contenteditable="true"]'))==null||e.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 e=document.createElement("style");e.textContent=`
|
|
1683
1698
|
${jk(this.fontResources)}
|
|
1684
1699
|
:host, .coco-ppt-editor { box-sizing: border-box; width: 100%; height: 100%; min-height: 360px; }
|
|
1685
1700
|
.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; }
|
|
@@ -1752,7 +1767,7 @@ coco-word-native-table.coco-word-revision-delete {
|
|
|
1752
1767
|
.coco-ppt-context-menu button:disabled { color: #94a3b8; cursor: default; }
|
|
1753
1768
|
.coco-ppt-context-menu span { color: #64748b; font-size: 11px; }
|
|
1754
1769
|
.coco-ppt-context-menu hr { border: 0; border-top: 1px solid #e2e8f0; margin: 4px 0; }
|
|
1755
|
-
`;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(e,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(e){return typeof document=="undefined"||!document.fonts?Promise.resolve():e.then(()=>Dr([...this.fontResources.map(n=>n.family),...this.referencedFontFamilies].map(n=>`16px ${Im(n)}`))).then(()=>{this.render();}).catch(()=>{})}render(){let e=this.root.querySelector(".coco-ppt-editor");e&&(e.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(e){let n=Array.from(this.slideList.querySelectorAll(".coco-ppt-thumb")),r=this.visibleThumbnailRange(e.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=e[i];if(!l)return;let d=ql(l),u=this.thumbnailCanvasCache.get(l.id);(u==null?void 0:u.fingerprint)===d?(a.replaceChildren(rm(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(e){let n=gr*.5625+Pk,r=this.slideList.clientHeight||n*Math.min(e,5),o=Math.max(0,Math.floor(this.slideList.scrollTop/n)-pa),i=Math.ceil(r/n)+pa*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-pa)):o,d=s>=0?Math.max(o+i,Math.min(e,s+pa+1)):o+i;return {start:l,end:Math.min(e,d)}}renderThumbnailSlide(e){let n=document.createElement("div");n.className="coco-ppt-thumb-slide";let o=gr*ha/e.size.width;return n.style.width=`${e.size.width*o}px`,n.style.height=`${e.size.height*o}px`,n.style.transform=`scale(${1/ha})`,n.style.background=Zl(e.background,this.imageResources),n.replaceChildren(...e.nodes.map(i=>this.renderNode(i,o,e,false))),n}async rasterizeThumbnail(e,n){var d,u;let r=this.thumbnailRasterEpoch,o=ql(n);if(await nm(),await nm(),r!==this.thumbnailRasterEpoch||!e.isConnected)return;let i=e.querySelector(".coco-ppt-thumb-preview"),a=i==null?void 0:i.querySelector(".coco-ppt-thumb-slide");if(!i||!a)return;let s=await Hk(a,gr,gr*(n.size.height/n.size.width),Rk,(u=(d=this.root.querySelector("style"))==null?void 0:d.textContent)!=null?u:"",gr*ha,gr*ha*(n.size.height/n.size.width));if(!s||r!==this.thumbnailRasterEpoch||!e.isConnected)return;let l=this.sessionValue.scene().slides.find(p=>p.id===n.id);!l||ql(l)!==o||(this.thumbnailCanvasCache.set(n.id,{fingerprint:o,canvas:s}),i.replaceChildren(rm(s)),e.dataset.previewMode="canvas");}scheduleThumbnailRender(){this.thumbnailFrame||(this.thumbnailFrame=requestAnimationFrame(()=>{this.thumbnailFrame=0,this.renderVisibleThumbnails(this.sessionValue.scene().slides);}));}renderNode(e,n,r,o=true){var h,x,S;let i=document.createElement("div"),a=Mm(e),s=e.presetGeometry==="frame",l=a?Am(e):"horizontal",d=Math.max(a&&l==="vertical"?12:1,e.bounds.width*n),u=Math.max(a&&l==="horizontal"?12:1,e.bounds.height*n);i.className=o?"coco-ppt-node":"coco-ppt-thumb-node",i.dataset.kind=e.kind,i.dataset.locked=String(e.locked),o&&(i.dataset.draggable=String(!this.isReadOnly()&&e.capabilities.editGeometry),i.dataset.resizable=String(!this.isReadOnly()&&e.capabilities.editGeometry),i.dataset.shapeId=e.id),i.style.left=`${e.bounds.left*n-(a&&l==="vertical"?d/2:0)}px`,i.style.top=`${e.bounds.top*n-(a&&l==="horizontal"?u/2:0)}px`,i.style.width=`${d}px`,i.style.height=`${u}px`;let p=[];e.bounds.rotation&&p.push(`rotate(${e.bounds.rotation}deg)`),e.bounds.flipHorizontal&&p.push("scaleX(-1)"),e.bounds.flipVertical&&p.push("scaleY(-1)"),p.length>0&&(i.style.transform=p.join(" "));let f=Wm(e),b=VE(e.presetGeometry),w=!!(b&&e.text&&!e.customGeometry&&!f);if(e.usesBackgroundFill&&e.backgroundFill?WE(i,e.backgroundFill,e,r,n,this.imageResources):e.customGeometry||f||w||e.kind==="table"||a||s?i.style.background="transparent":e.fillGradient&&e.fillGradient.colors.length>1?i.style.background=Er(e.fillGradient,kr(e)):e.fillColor&&(i.style.background=Sr(e.fillColor,kr(e))),SE(e)&&(i.style.overflow="visible"),(e.presetGeometry==="roundRect"||e.presetGeometry==="round1Rect")&&(i.style.borderRadius=`${yr(e)*n}px`),e.presetGeometry==="round2DiagRect"){let k=`${yr(e)*n}px`;i.style.borderRadius=`${k} 0 ${k} 0`;}if(e.presetGeometry==="round2SameRect"){let k=`${yr(e)*n}px`;i.style.borderRadius=`${k} ${k} 0 0`;}if((e.presetGeometry==="ellipse"||Mk(e)||Dk(e))&&(i.style.borderRadius="9999px"),b&&!w&&!f&&(i.style.clipPath=b),s?(i.style.borderStyle="solid",i.style.borderWidth=`${BE(e,n)}px`,e.fillGradient&&e.fillGradient.colors.length>1?(i.style.borderImageSource=Er(e.fillGradient),i.style.borderImageSlice="1"):e.fillColor&&(i.style.borderColor=e.fillColor)):!e.customGeometry&&!f&&!w&&!a&&e.kind!=="picture"&&e.lineColor&&(i.style.borderStyle=td(e.lineDash),i.style.borderWidth=`${Math.max(1,((h=e.lineWidth)!=null?h:9525)*n)}px`,i.style.borderColor=Sr(e.lineColor,e.lineOpacity)),e.shadow&&(i.style.boxShadow=Hm(e.shadow,n)),this.applyTextStyle(i,e,n),pE(i,e,n),w&&b&&i.append(HE(e,n,b)),e.customGeometry&&e.kind!=="picture"&&i.append(nC(e)),f&&i.append(GE(e,n)),a)i.append(sC(e,n));else if(e.kind==="chart")i.append(bC(e));else if(e.kind==="table"){let k=uC(e,n,o);o&&(k.addEventListener("click",I=>{I.stopPropagation(),!this.consumeSuppressedClick()&&(this.notifyTableCellSelection(r,e,I),this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:e.id}));}),k.addEventListener("dblclick",I=>{if(this.isReadOnly())return;let D=im(I);if(!D||!e.capabilities.editTableCells)return;I.stopPropagation();let H=Number(D.dataset.row),A=Number(D.dataset.column);!Number.isInteger(H)||!Number.isInteger(A)||this.startTableCellEdit(D,r,e,H,A);})),i.append(k);}else if(e.kind==="picture"){let k=e.imagePath?this.imageResources[e.imagePath]:void 0,I=k==null?void 0:k.url;if(I&&Ql(k.contentType,e.imagePath)){if(ZE(e,r))i.append(eC(e,I));else {let D=document.createElement("img");D.src=I,D.alt=(x=e.name)!=null?x:"",aE(D,e),e.imageOpacity!==void 0&&(D.style.opacity=String(Math.max(0,Math.min(1,e.imageOpacity)))),i.append(D);}e.lineColor&&i.append(aC(e,n));}else i.dataset.unsupportedImage=e.imagePath?"true":"missing",k!=null&&k.contentType&&(i.dataset.imageContentType=k.contentType),e.imagePath&&(i.dataset.imagePath=e.imagePath),i.append(dE(e,k==null?void 0:k.contentType));}else {let k=(S=e.text)!=null?S:"";if(e.customGeometry||f||w||uE(e)){let I=document.createElement("div");I.className="coco-ppt-text-layer",fE(I,e),cm(I,e,n,k),i.append(I),um(I,e),fm(I,e);}else cm(i,e,n,k),um(i,e),fm(i,e);}if(FE(e)&&i.append(iC(e,n)),!o)return i;let g=document.createElement("div");return g.className="coco-ppt-resize-handle",g.addEventListener("mousedown",k=>{this.isReadOnly()||!e.capabilities.editGeometry||(k.preventDefault(),k.stopPropagation(),this.startDrag(k,"resize",r,e,n,i));}),i.append(g),i.addEventListener("click",k=>{var D,H;if(this.hideContextMenu(),k.stopPropagation(),this.consumeSuppressedClick())return;if(k.altKey){let A=this.selection(),O=Qk(r,k,n,(A==null?void 0:A.kind)==="shape"?A.shapeId:e.id);if(O){this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:O.node.id}),(H=(D=this.options).onObjectAction)==null||H.call(D,{action:"cycle-selection",slideId:r.id,shapeId:O.node.id,kind:O.node.kind,name:O.node.name,reason:`\u5DF2\u5207\u6362\u5230\u91CD\u53E0\u5BF9\u8C61 ${O.index+1}/${O.count}`,candidateIndex:O.index,candidateCount:O.count});return}}let I=this.pointerOperationNode(r,e,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:e.id});}),i.addEventListener("contextmenu",k=>{var D;if(this.isReadOnly())return;k.preventDefault(),k.stopPropagation();let I=(D=this.pointerOperationNode(r,e,k,n))!=null?D:e;this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:I.id}).then(()=>this.showContextMenu(k,r,I));}),i.addEventListener("mousedown",k=>{var H,A;let I=(H=this.pointerOperationNode(r,e,k,n))!=null?H:e,D=(A=Xl(this.canvas,I.id))!=null?A:i;Zk(D,k.target)||this.isReadOnly()||k.button!==0||!I.capabilities.editGeometry||(k.preventDefault(),k.stopPropagation(),this.startDrag(k,"move",r,I,n,D));}),i.addEventListener("dblclick",k=>{var D,H,A;if(this.isReadOnly())return;k.stopPropagation();let I=lm(r,e,k,n);if(I){this.startTextEdit((D=Xl(this.canvas,I.id))!=null?D:i,r,I);return}if(!e.capabilities.editText){this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:e.id}).then(()=>this.renderSelection()),(A=(H=this.options).onObjectAction)==null||A.call(H,{action:"blocked-text-edit",slideId:r.id,shapeId:e.id,kind:e.kind,name:e.name,reason:nE(e)});return}this.startTextEdit(i,r,e);}),i}pointerOperationNode(e,n,r,o){let i=this.selection();return (i==null?void 0:i.kind)==="shape"&&i.slideId===e.id&&i.shapeId===n.id?n:lm(e,n,r,o)}notifyTableCellSelection(e,n,r){var s,l;let o=im(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:e.id,shapeId:n.id,row:i,column:a,text:wm(o,n,i,a)});}applyTextStyle(e,n,r){var a,s,l,d;let o=n.textStyle;o&&(Jl(e,Jk(n,o),r),o.alignment&&(ed(e,o.alignment),o.alignment==="center"&&(e.style.justifyContent="center"),o.alignment==="right"&&(e.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=hE(n,r);e.style.padding=`${p*r+w}px ${f*r}px ${b*r}px ${u*r}px`,Nm(i)&&(e.style.writingMode="vertical-rl",e.style.textOrientation="upright"),i.anchor==="middle"&&(e.style.alignItems="center"),i.anchor==="bottom"&&(e.style.alignItems="flex-end"),i.anchor==="top"&&(e.style.alignItems="flex-start");}}startTextEdit(e,n,r){var f,b,w,g;if(this.isReadOnly())return;let o=(f=r.text)!=null?f:"",i=Xk(e),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"),e.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,D,H;if(a)return;a=true,i.contentEditable="false",i.removeAttribute("role"),i.removeAttribute("aria-label"),delete e.dataset.editing,delete this.canvas.dataset.interactionMode,i.removeEventListener("blur",p),i.removeEventListener("keydown",d),i.removeEventListener("paste",u);let x=(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}(H=(D=this.options).onTextEditStateChange)==null||H.call(D,{state:"commit",slideId:n.id,shapeId:r.id,text:x}),x!==o?this.dispatch({kind:"set-shape-text",slideIdOrIndex:n.id,shapeIdOrName:r.id,text:x}):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 x=(S=h.clipboardData)==null?void 0:S.getData("text/plain");x!==void 0&&(h.preventDefault(),dm(i,x));},p=()=>l(true);i.addEventListener("blur",p),i.addEventListener("keydown",d),i.addEventListener("paste",u);}startTableCellEdit(e,n,r,o,i){var b,w,g;if(this.isReadOnly())return;let a=wm(e,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}),e.contentEditable="true",e.spellcheck=false,this.canvas.dataset.interactionMode="editing",e.setAttribute("role","textbox"),e.setAttribute("aria-label",`${(g=r.name)!=null?g:"PPT table"} cell ${o+1},${i+1}`),e.textContent=a,e.focus();let l=e.ownerDocument.getSelection();if(l){let h=e.ownerDocument.createRange();h.selectNodeContents(e),h.collapse(false),l.removeAllRanges(),l.addRange(h);}let d=h=>{var S;if(s)return;s=true,e.contentEditable="false",delete this.canvas.dataset.interactionMode,e.removeAttribute("role"),e.removeAttribute("aria-label"),e.removeEventListener("blur",f),e.removeEventListener("keydown",u),e.removeEventListener("paste",p);let x=(S=e.textContent)!=null?S:"";if(!h){e.textContent=a,e.dataset.cellText=a;return}x!==a?(e.dataset.cellText=x,this.dispatch({kind:"set-table-cell-text",slideIdOrIndex:n.id,shapeIdOrName:r.id,row:o,column:i,text:x})):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 x=(S=h.clipboardData)==null?void 0:S.getData("text/plain");x!==void 0&&(h.preventDefault(),dm(e,x));},f=()=>d(true);e.addEventListener("blur",f),e.addEventListener("keydown",u),e.addEventListener("paste",p);}startDrag(e,n,r,o,i,a){this.isReadOnly()||(n==="resize"&&Wk(a,o),this.dragState={mode:n,slideId:r.id,shapeId:o.id,slideSize:r.size,startClientX:e.clientX,startClientY:e.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(e){let n=this.dragState;if(!n)return;if(Math.hypot(e.clientX-n.startClientX,e.clientY-n.startClientY)<=_l){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=(e.clientX-n.startClientX)/n.scale,i=(e.clientY-n.startClientY)/n.scale;if(n.mode==="move"){let{bounds:s}=e.altKey?{bounds:En(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});e.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}=e.altKey?{bounds:En(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});e.altKey&&this.hideSnapGuides(),n.element.style.width=`${a.width*n.scale}px`,n.element.style.height=`${a.height*n.scale}px`;}async finishDrag(e){var s,l;let n=this.dragState;if(!n)return;this.dragState=null;let r=(e.clientX-n.startClientX)/n.scale,o=(e.clientY-n.startClientY)/n.scale,i=Math.hypot(e.clientX-n.startClientX,e.clientY-n.startClientY);if(i<=_l||!n.active){this.hideSnapGuides(),this.clearDragVisualState(n.element);return}this.suppressClickAfterDrag=this.suppressClickAfterDrag||i>_l;let a=e.altKey?En(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(e,n){let r=[...new Set(e.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(e,n){let r=En(e.startBounds,e.slideSize,n),o=this.sessionValue.scene().slides.find(u=>u.id===e.slideId);if(!o)return this.hideSnapGuides(),{bounds:r,guides:[],snapped:false};let i=Math.min(18e4,em/e.scale),a=ga([{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"}],ma(o,e.shapeId,"x"),i),s=ga([{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"}],ma(o,e.shapeId,"y"),i),l=En(e.startBounds,e.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,e.scale),{bounds:l,guides:d,snapped:d.length>0}}snapResizeBounds(e,n){let r=En(e.startBounds,e.slideSize,n),o=this.sessionValue.scene().slides.find(u=>u.id===e.slideId);if(!o)return this.hideSnapGuides(),{bounds:r,guides:[],snapped:false};let i=Math.min(18e4,em/e.scale),a=ga([{offset:r.width/2,value:r.left+r.width/2,role:"center"},{offset:r.width,value:r.left+r.width,role:"end"}],ma(o,e.shapeId,"x"),i,{matchRole:false}),s=ga([{offset:r.height/2,value:r.top+r.height/2,role:"center"},{offset:r.height,value:r.top+r.height,role:"end"}],ma(o,e.shapeId,"y"),i,{matchRole:false}),l=En(e.startBounds,e.slideSize,{width:a?tm(r.left,r.width,a.source,a.target.value):r.width,height:s?tm(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,e.scale),{bounds:l,guides:d,snapped:d.length>0}}renderSnapGuides(e,n){this.clearSnapReferenceHighlights();let r=new Set(e.map(o=>o.referenceShapeId).filter(o=>!!o));for(let o of r){let i=Xl(this.canvas,o);i&&(i.dataset.snapReference="true");}this.snapGuides.replaceChildren(...e.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(e,n=false){delete e.dataset.dragging,(n||!this.dragState)&&delete this.canvas.dataset.interactionMode;}restoreDragElementBounds(e){if(e.mode==="move"){e.element.style.left=`${e.startBounds.left*e.scale}px`,e.element.style.top=`${e.startBounds.top*e.scale}px`;return}e.element.style.width=`${e.startBounds.width*e.scale}px`,e.element.style.height=`${e.startBounds.height*e.scale}px`;}clearSnapReferenceHighlights(){this.canvas.querySelectorAll('.coco-ppt-node[data-snap-reference="true"]').forEach(e=>{delete e.dataset.snapReference;});}handleKeyDown(e){if(e.defaultPrevented||this.dragState||sm(e.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=e.ctrlKey||e.metaKey;if(this.isReadOnly())return;if(i&&e.key.toLowerCase()==="c"){e.preventDefault(),this.copySelectedShape(r,o);return}if(i&&e.key.toLowerCase()==="v"){e.preventDefault(),this.pasteClipboardShape(r,o);return}if(i&&e.key.toLowerCase()==="d"){e.preventDefault(),this.duplicateSelectedShape(r,o);return}if(i&&e.shiftKey&&e.key==="]"){e.preventDefault(),this.bringSelectedShapeToFront(r,o);return}if(i&&e.shiftKey&&e.key==="["){e.preventDefault(),this.sendSelectedShapeToBack(r,o);return}if(e.key==="Delete"||e.key==="Backspace"){if(!jn(o))return;e.preventDefault(),this.deleteSelectedShape(r,o);return}let a=Yk(e.key);if(!a||!o.capabilities.editGeometry)return;let s=Tk*(e.shiftKey?10:1),l=En(o.bounds,r.size,{left:o.bounds.left+a.dx*s,top:o.bounds.top+a.dy*s});e.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}${e.shiftKey?" 10\u6B65":" 1\u6B65"}`});});}handleSelectStart(e){this.isReadOnly()||sm(e.target)||e.target instanceof HTMLElement&&e.target.closest('[contenteditable="true"]')||e.preventDefault();}copySelectedShape(e,n){var r,o;jn(n)&&(this.clipboardShape={slideId:e.id,shapeId:n.id},(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"copy-shape",slideId:e.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u590D\u5236\u5BF9\u8C61"}));}pasteClipboardShape(e,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(e,n){jn(n)&&this.dispatch({kind:"duplicate-shape",slideIdOrIndex:e.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:e.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(e,n){jn(n)&&this.dispatch({kind:"bring-shape-to-front",slideIdOrIndex:e.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"bring-shape-to-front",slideId:e.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7F6E\u4E8E\u9876\u5C42"});});}sendSelectedShapeToBack(e,n){jn(n)&&this.dispatch({kind:"send-shape-to-back",slideIdOrIndex:e.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"send-shape-to-back",slideId:e.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7F6E\u4E8E\u5E95\u5C42"});});}showContextMenu(e,n,r){if(this.isReadOnly())return;let o=jn(r),i=!!this.clipboardShape,a=u=>()=>{this.hideContextMenu(),u();};this.contextMenu.replaceChildren(br("\u590D\u5236","Ctrl+C",o,a(()=>this.copySelectedShape(n,r))),br("\u7C98\u8D34","Ctrl+V",i,a(()=>this.pasteClipboardShape(n,r))),br("\u91CD\u590D","Ctrl+D",o,a(()=>this.duplicateSelectedShape(n,r))),am(),br("\u7F6E\u4E8E\u9876\u5C42","Ctrl+Shift+]",o,a(()=>this.bringSelectedShapeToFront(n,r))),br("\u7F6E\u4E8E\u5E95\u5C42","Ctrl+Shift+[",o,a(()=>this.sendSelectedShapeToBack(n,r))),am(),br("\u5220\u9664","Del",o,a(()=>this.deleteSelectedShape(n,r))));let s=this.root instanceof ShadowRoot?this.root.host.getBoundingClientRect():this.root.getBoundingClientRect(),l=Sa(e.clientX,s.left+4,window.innerWidth-170),d=Sa(e.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(e,n){jn(n)&&this.dispatch({kind:"delete-shape",slideIdOrIndex:e.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"delete-shape",slideId:e.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u5220\u9664\u5BF9\u8C61"});});}async dispatchCurrentSlideSelection(){if(this.consumeSuppressedClick())return;let e=this.currentSlide();e&&await this.dispatch({kind:"select-slide",slideIdOrIndex:e.id});}consumeSuppressedClick(){return this.suppressClickAfterDrag?(this.suppressClickAfterDrag=false,true):false}dismissContextMenu(e){let n=e.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 e=this.sessionValue.selection();this.slideList.querySelectorAll(".coco-ppt-thumb").forEach((n,r)=>{let o=this.sessionValue.scene().slides[r];n.dataset.selected=(e==null?void 0:e.slideId)===(o==null?void 0:o.id)?"true":"false";}),this.canvas.querySelectorAll(".coco-ppt-node").forEach(n=>{n.dataset.selected=(e==null?void 0:e.kind)==="shape"&&n.dataset.shapeId===e.shapeId?"true":"false";}),this.renderParentGroupSelection(e);}renderParentGroupSelection(e){var d,u;if((e==null?void 0:e.kind)!=="shape")return;let n=this.sessionValue.scene().slides.find(p=>p.id===e.slideId),r=(d=n==null?void 0:n.nodes.find(p=>p.id===e.shapeId))!=null?d:n==null?void 0:n.groups.find(p=>p.id===e.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:Lk(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=e.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 e=this.sessionValue.scene(),n=this.sessionValue.selection();return (n==null?void 0:n.kind)==="slide"||(n==null?void 0:n.kind)==="shape"?(o=(r=e.slides.find(a=>a.id===n.slideId))!=null?r:e.slides[0])!=null?o:null:(i=e.slides[0])!=null?i:null}computeScale(e){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/e.size.width,540/e.size.height,r/e.size.width,o/e.size.height)}};function Wk(t,e){var r,o;if(!Bk(e))return;let n=(o=(r=t.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?r:t.querySelector(".coco-ppt-text-layer"))!=null?o:t;t.dataset.textResizePreview="wrap",n.dataset.textResizePreview="wrap",n.style.transform="",n.style.transformOrigin="",n.style.width="",t.style.whiteSpace="pre-wrap",t.style.overflowWrap="anywhere",t.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(i=>{i.style.whiteSpace="pre-wrap",i.style.overflowWrap="anywhere";});}function Bk(t){var e;return !!(t.capabilities.editGeometry&&Fk(t)&&(t.text||(e=t.textParagraphs)!=null&&e.length))}function Fk(t){return t.kind==="placeholder"||t.kind==="textBox"||t.kind==="geometricShape"}function nm(){return new Promise(t=>requestAnimationFrame(()=>t()))}async function Hk(t,e,n,r,o,i=e,a=n){if(typeof XMLSerializer=="undefined"||typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return null;await Ok(t);let s=document.createElement("canvas");s.width=Math.max(1,Math.round(e*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=t.cloneNode(true);await $k(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 Gk(w);return l.drawImage(g,0,0,s.width,s.height),s}catch(g){return null}finally{URL.revokeObjectURL(w);}}function rm(t){let e=document.createElement("canvas");e.className="coco-ppt-thumb-canvas",e.width=t.width,e.height=t.height;let n=e.getContext("2d");return n&&n.drawImage(t,0,0),e}function ql(t){return JSON.stringify({size:t.size,background:t.background,nodes:t.nodes.map(e=>km(e))})}function km(t){return {id:t.id,kind:t.kind,bounds:t.bounds,text:t.text,textParagraphs:t.textParagraphs,textStyle:t.textStyle,textBody:t.textBody,table:t.table,fillColor:t.fillColor,fillGradient:t.fillGradient,opacity:t.opacity,lineColor:t.lineColor,lineGradient:t.lineGradient,lineOpacity:t.lineOpacity,lineWidth:t.lineWidth,lineDash:t.lineDash,presetGeometry:t.presetGeometry,presetAdjustments:t.presetAdjustments,customGeometry:t.customGeometry,imagePath:t.imagePath,imageCrop:t.imageCrop,imageFillRect:t.imageFillRect,imageOpacity:t.imageOpacity,shadow:t.shadow,threeD:t.threeD,children:t.children.map(e=>km(e))}}async function Ok(t){let e=Array.from(t.querySelectorAll("img"));await Promise.all(e.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 $k(t){let e=Array.from(t.querySelectorAll("img"));await Promise.all(e.map(async n=>{n.alt="";let r=n.getAttribute("src");if(!r||r.startsWith("data:"))return;let o=await zk(r).catch(()=>{});o&&n.setAttribute("src",o);}));}async function zk(t){let e=await fetch(t);if(!e.ok)throw new Error(`Failed to inline thumbnail image: ${e.status}`);let n=await e.blob();return Vk(n)}function Vk(t){return new Promise((e,n)=>{let r=new FileReader;r.onload=()=>{typeof r.result=="string"?e(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(t);})}function Gk(t){return new Promise((e,n)=>{let r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error("Failed to rasterize PPT thumbnail.")),r.src=t;})}function jk(t){return t.filter(Uk).map(n=>{var a,s;let r=oE(n.family),o=(a=n.weight)!=null?a:400,i=(s=n.style)!=null?s:"normal";return `@font-face { font-family: ${r}; src: url(${iE(n.url)}); font-weight: ${o}; font-style: ${i}; }`}).join(`
|
|
1756
|
-
`)}function Uk(t){return /font\/(ttf|otf|woff|woff2)|application\/font-(sfnt|woff|woff2)/i.test(t.contentType)}function Kk(t,e=[]){if(typeof document=="undefined")return Promise.resolve();let n=new Set(t.map(o=>o.family));for(let o of e)n.add(o);let r=[];for(let o of n){let i=rE(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(om(s));continue}let l=document.createElement("link");l.id=a,l.rel="stylesheet",l.href=i,r.push(om(l)),document.head.append(l);}return Promise.all(r).then(()=>{})}function _k(t){let e=new Set,n=o=>{o!=null&&o.trim()&&e.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 t.scene.slides)for(let i of o.nodes)r(i);return [...e]}function qk(t){globalThis.__cocoPptFontRenderReady=t;}function om(t){return t.sheet?Promise.resolve():new Promise(e=>{let n=()=>e();t.addEventListener("load",n,{once:true}),t.addEventListener("error",n,{once:true}),window.setTimeout(n,5e3);})}function Xk(t){var e;return (e=t.querySelector(".coco-ppt-text-layer"))!=null?e:t}function im(t){let e=t.target;return e instanceof HTMLElement?e.closest("td[data-row][data-column]"):null}function br(t,e,n,r){let o=document.createElement("button");o.type="button",o.disabled=!n;let i=document.createElement("strong");i.textContent=t;let a=document.createElement("span");return a.textContent=e,o.append(i,a),o.addEventListener("click",()=>{o.disabled||r();}),o}function am(){return document.createElement("hr")}function Yk(t){return t==="ArrowLeft"?{dx:-1,dy:0,label:"\u5DE6"}:t==="ArrowRight"?{dx:1,dy:0,label:"\u53F3"}:t==="ArrowUp"?{dx:0,dy:-1,label:"\u4E0A"}:t==="ArrowDown"?{dx:0,dy:1,label:"\u4E0B"}:null}function sm(t){if(!(t instanceof HTMLElement))return false;if(t.isContentEditable)return true;let e=t.tagName.toLowerCase();return e==="input"||e==="textarea"||e==="select"}function Zk(t,e){return t.isContentEditable||e instanceof HTMLElement&&e.isContentEditable?true:!!t.querySelector('[contenteditable="true"]')}function Jk(t,e){var s;let n=(s=t.textParagraphs)==null?void 0:s.filter(d=>d.runs.length>0);if(!(n!=null&&n.length)||!Rm(t,n))return e;let l=e,{textGradient:r,textFill:o,textOutlineColor:i}=l;return Ln(l,["textGradient","textFill","textOutlineColor"])}function lm(t,e,n,r){if(e.capabilities.editText||tE(e))return null;let o=Em(n,r);if(!o)return null;let i=t.nodes.findIndex(s=>s.id===e.id),a=t.nodes.slice(0,i<0?t.nodes.length:i);for(let s=a.length-1;s>=0;s--){let l=a[s];if(l.capabilities.editText&&Cm(o.x,o.y,l.bounds))return l}return null}function Qk(t,e,n,r){let o=eE(t,e,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 eE(t,e,n){let r=Em(e,n);if(!r)return [];let o=[];for(let i=t.nodes.length-1;i>=0;i--){let a=t.nodes[i];a.capabilities.select&&Cm(r.x,r.y,a.bounds)&&o.push(a);}return o}function tE(t){return t.kind==="table"||t.kind==="chart"||t.kind==="smartArt"}function Em(t,e){var o;let n=t.currentTarget&&typeof t.currentTarget.parentElement=="object"&&(o=t.currentTarget.parentElement)!=null?o:null,r=n==null?void 0:n.getBoundingClientRect();return r?{x:(t.clientX-r.left)/e,y:(t.clientY-r.top)/e}:null}function Cm(t,e,n){return t>=n.left&&t<=n.left+n.width&&e>=n.top&&e<=n.top+n.height}function Xl(t,e){for(let n of Array.from(t.querySelectorAll(".coco-ppt-node")))if(n.dataset.shapeId===e)return n;return null}function dm(t,e){var a,s;let n=t.ownerDocument.getSelection();if(!n||n.rangeCount===0){t.textContent=`${(a=t.textContent)!=null?a:""}${e}`;return}let r=n.getRangeAt(0);if(!(t===r.commonAncestorContainer||t.contains(r.commonAncestorContainer))){t.textContent=`${(s=t.textContent)!=null?s:""}${e}`;return}r.deleteContents();let i=t.ownerDocument.createTextNode(e);r.insertNode(i),r.setStartAfter(i),r.setEndAfter(i),n.removeAllRanges(),n.addRange(r);}function nE(t){var e;return (e=t.capabilities.reasons)!=null&&e.editText?t.capabilities.reasons.editText:t.capabilities.reason?t.capabilities.reason:t.kind==="table"?"\u8868\u683C\u8BF7\u4F7F\u7528\u5355\u5143\u683C\u7F16\u8F91":t.kind==="picture"?"\u56FE\u7247\u5BF9\u8C61\u4E0D\u652F\u6301\u6587\u5B57\u7F16\u8F91":t.kind==="chart"?"\u56FE\u8868\u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":t.kind==="smartArt"?"SmartArt \u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":t.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 rE(t){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"}[t]}function Im(t){return qt(t,{families:["Calibri","Microsoft YaHei","Segoe UI"],generic:"sans-serif"})}function oE(t){return `"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function iE(t){return `"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Sr(t,e){var s;if(e===void 0||e>=1)return t;let n=Math.max(0,Math.min(1,e)),r=(s=t.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:s[1];if(!r)return t;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 kr(t){var e;return t.opacity!==void 0?Math.max(0,Math.min(1,t.opacity)):((e=t.threeD)==null?void 0:e.material)==="translucentPowder"?.52:void 0}function aE(t,e){if(e.imageFillRect){lE(t,e);return}sE(t,e);}function sE(t,e){var d,u,p,f;let n=e.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);t.style.position="absolute",t.style.left=`${-r/s*100}%`,t.style.top=`${-i/l*100}%`,t.style.width=`${1/s*100}%`,t.style.height=`${1/l*100}%`;}function lE(t,e){var s,l,d,u;let n=e.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;t.style.position="absolute",t.style.left=`${r*100}%`,t.style.top=`${i*100}%`,t.style.width=`${Math.max(.01,1-r-o)*100}%`,t.style.height=`${Math.max(.01,1-i-a)*100}%`;}function dE(t,e){var o,i;let n=document.createElement("div");n.className="coco-ppt-unsupported-image";let r=(i=(o=t.imagePath)==null?void 0:o.split(".").pop())==null?void 0:i.toUpperCase();return n.textContent=r||cE(e)||"IMAGE",n.title=t.imagePath?`Unsupported image: ${t.imagePath}`:"Missing image resource",n}function cE(t){if(t)return t.includes("emf")?"EMF":t.includes("wmf")?"WMF":t.includes("svg")?"SVG":"IMAGE"}function cm(t,e,n,r){var s,l;let o=(s=e.textParagraphs)==null?void 0:s.filter(d=>d.runs.length>0),i=Nm(e.textBody);if(!(o!=null&&o.length)||!Rm(e,o)){!i&&((l=e.textStyle)==null?void 0:l.alignment)==="distributed"&&Array.from(r).length>1?CE(t,r):t.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&&ed(u,d.style.alignment),NE(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),PE(h,d.style,n,d.text),u.append(h);}d.runs.forEach((h,x)=>{(p?Array.from(h.text):[h.text]).forEach(k=>{let I=document.createElement("span");I.textContent=k;let D=AE(e,d,h,x);D&&Jl(I,D,n),u.append(I);});}),a.append(u);}),t.append(a);}function Nm(t){return (t==null?void 0:t.vertical)==="eastAsian"||(t==null?void 0:t.vertical)==="vertical"}function um(t,e){var n;((n=e.textBody)==null?void 0:n.wrap)==="none"&&Tm(t);}function fm(t,e){var n,r;((n=e.textBody)==null?void 0:n.autoFit)==="normal"&&(!e.text&&!((r=e.textParagraphs)!=null&&r.length)||(wE(e)&&!yE(e)&&Tm(t),requestAnimationFrame(()=>{var f;if(t.dataset.textResizePreview==="wrap")return;let o=t.clientWidth,i=t.clientHeight;if(o<=0||i<=0)return;let a=t.scrollWidth,s=t.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=t.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?f:t;p.dataset.textResizePreview!=="wrap"&&(p.style.transformOrigin=vE(e),p.style.transform=`scale(${u})`,p.style.width=`${100/u}%`);})));}function uE(t){var e;return !!((t.text||(e=t.textParagraphs)!=null&&e.length)&&(t.bounds.flipHorizontal||t.bounds.flipVertical))}function fE(t,e){let n=[];e.bounds.flipHorizontal&&n.push("scaleX(-1)"),e.bounds.flipVertical&&n.push("scaleY(-1)"),n.length!==0&&(t.style.transform=n.join(" "),t.style.transformOrigin="center");}function Tm(t){t.style.whiteSpace="nowrap",t.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(e=>{e.style.whiteSpace="nowrap";});}function pE(t,e,n){var o,i,a;if(!gE(e,n))return;let r=((a=(i=(o=e.textStyle)==null?void 0:o.fontSize)!=null?i:Ca(e))!=null?a:28)*12700*n;t.style.letterSpacing=`${Math.max(1,Math.min(2.4,r*.035))}px`;}function hE(t,e){var r,o;if(!mE(t))return 0;let n=(o=(r=t.textStyle)==null?void 0:r.fontSize)!=null?o:Ca(t);return n?n*12700*e*.18:0}function mE(t){var i,a,s,l,d,u,p,f,b;if(t.kind!=="textBox"&&t.kind!=="placeholder"||((i=t.textBody)==null?void 0:i.anchor)!=="top"||t.textBody.wrap!=="square"||t.fillColor||t.fillGradient||t.lineColor||t.lineGradient)return false;let e=(s=(a=t.textStyle)==null?void 0:a.fontFamily)!=null?s:Pm(t);if(!e||!/\bCuprum\b/i.test(e))return false;let n=(d=(l=t.textStyle)==null?void 0:l.fontSize)!=null?d:Ca(t);if(!n||n<72)return false;let r=(u=t.textParagraphs)==null?void 0:u.filter(w=>{var h;return ((h=w.text)!=null?h:w.runs.map(x=>x.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:t.text)!=null?b:"").trim();return o.length>=12&&!/[\u3400-\u9fff]/.test(o)}function gE(t,e){var l,d,u,p,f,b,w,g,h,x,S,k,I,D,H,A,O,ee,le,ae;if(((l=t.textBody)==null?void 0:l.wrap)!=="square"||bE(t)||((b=(d=t.textStyle)==null?void 0:d.alignment)!=null?b:(f=(p=(u=t.textParagraphs)==null?void 0:u[0])==null?void 0:p.style)==null?void 0:f.alignment)!=="center")return false;let r=(g=(w=t.textStyle)==null?void 0:w.fontFamily)!=null?g:Pm(t);if(!r||!/\bJosefin Sans\b/i.test(r))return false;let o=((k=(S=(x=(h=t.textParagraphs)==null?void 0:h[0])==null?void 0:x.text)!=null?S:t.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=(D=(I=t.textStyle)==null?void 0:I.fontSize)!=null?D:Ca(t);if(!i)return false;let a=(ae=(le=(H=t.textStyle)==null?void 0:H.lineHeight)!=null?le:(ee=(O=(A=t.textParagraphs)==null?void 0:A[0])==null?void 0:O.style)==null?void 0:ee.lineHeight)!=null?ae:1.2,s=i*12700*e*a;return t.bounds.height*e>=s*1.75}function bE(t){var e,n;return !!(((e=t.textStyle)==null?void 0:e.characterSpacing)!==void 0||(n=t.textParagraphs)!=null&&n.some(r=>r.runs.some(o=>{var i;return ((i=o.style)==null?void 0:i.characterSpacing)!==void 0})))}function Ca(t){var e,n;for(let r of (e=t.textParagraphs)!=null?e:[])for(let o of r.runs)if(((n=o.style)==null?void 0:n.fontSize)!==void 0)return o.style.fontSize}function Pm(t){var e,n;for(let r of (e=t.textParagraphs)!=null?e:[])for(let o of r.runs)if((n=o.style)!=null&&n.fontFamily)return o.style.fontFamily}function wE(t){var r,o,i,a,s,l;let e=(r=t.textParagraphs)==null?void 0:r.filter(d=>d.runs.length>0);if(e&&e.length!==1||(i=(o=e==null?void 0:e[0])==null?void 0:o.style)!=null&&i.bullet)return false;let n=(l=(s=(a=e==null?void 0:e[0])==null?void 0:a.text)!=null?s:t.text)!=null?l:"";return n.length>0&&!n.includes(`
|
|
1757
|
-
`)&&!n.includes("\r")}function xE(t){var o,i,a,s,l,d,u,p,f,b;if(((o=t.textBody)==null?void 0:o.wrap)!=="square"||((d=(i=t.textStyle)==null?void 0:i.alignment)!=null?d:(l=(s=(a=t.textParagraphs)==null?void 0:a[0])==null?void 0:s.style)==null?void 0:l.alignment)!=="center")return false;let e=((b=(f=(p=(u=t.textParagraphs)==null?void 0:u[0])==null?void 0:p.text)!=null?f:t.text)!=null?b:"").trim();if(!/^[\u3400-\u9fff]{4,6}$/.test(e))return false;let n=Math.min(t.bounds.width,t.bounds.height),r=Math.max(t.bounds.width,t.bounds.height);return n>0&&r<=11e5&&r/n<1.25}function yE(t){var r,o,i,a,s,l,d;if(xE(t))return true;if(((r=t.textBody)==null?void 0:r.wrap)!=="square")return false;let e=((s=(a=(i=(o=t.textParagraphs)==null?void 0:o[0])==null?void 0:i.text)!=null?a:t.text)!=null?s:"").trim();return e.length<18?false:((d=(l=e.match(/[\u3400-\u9fff]/g))==null?void 0:l.length)!=null?d:0)>=12?true:/[\s,。;、,.]/.test(e)}function vE(t){var n,r,o,i,a;let e=(a=(n=t.textStyle)==null?void 0:n.alignment)!=null?a:(i=(o=(r=t.textParagraphs)==null?void 0:r[0])==null?void 0:o.style)==null?void 0:i.alignment;return e==="right"?"right top":e==="center"?"center top":"top left"}function SE(t){var e;return t.kind!=="textBox"||!t.text&&!((e=t.textParagraphs)!=null&&e.length)||t.customGeometry||Wm(t)||Mm(t)?false:!kE(t)&&!EE(t)}function kE(t){var e,n;return (e=t.fillGradient)!=null&&e.colors.length?((n=t.fillGradient.opacities)!=null?n:[]).some(r=>r>0)||!t.fillGradient.opacities:!!(t.fillColor&&t.opacity!==0)}function EE(t){var e,n;return !t.lineColor&&!((e=t.lineGradient)!=null&&e.colors.length)||t.lineOpacity===0?false:((n=t.lineWidth)!=null?n:9525)>0}function CE(t,e){let n=document.createElement("div");n.className="coco-ppt-distributed-text",Array.from(e).forEach(r=>{let o=document.createElement("span");o.textContent=r,n.append(o);}),t.append(n);}function Rm(t,e){return e.some(n=>{var r;return !!((r=n.style)!=null&&r.bullet)||IE(n.style)||n.runs.some(o=>!!o.hyperlink||o.style!==void 0&&ME(o.style,t.textStyle))})}function IE(t){return (t==null?void 0:t.lineHeight)!==void 0||(t==null?void 0:t.marginLeft)!==void 0||(t==null?void 0:t.textIndent)!==void 0||(t==null?void 0:t.spaceBefore)!==void 0||(t==null?void 0:t.spaceAfter)!==void 0}function NE(t,e,n,r={}){if(e){if(e.lineHeight!==void 0&&(t.style.lineHeight=String(TE(e))),e.marginLeft!==void 0&&(t.style.paddingLeft=`${e.marginLeft*n}px`),e.textIndent!==void 0&&(t.style.textIndent=`${e.textIndent*n}px`),r.verticalText){e.spaceBefore!==void 0&&(t.style.marginRight=ba(e.spaceBefore,n)),e.spaceAfter!==void 0&&(t.style.marginLeft=ba(e.spaceAfter,n));return}e.spaceBefore!==void 0&&(t.style.marginTop=ba(e.spaceBefore,n)),e.spaceAfter!==void 0&&(t.style.marginBottom=ba(e.spaceAfter,n));}}function TE(t){var n;let e=(n=t.lineHeight)!=null?n:1.2;return t.bullet?e*1.15:e}function PE(t,e,n,r=""){(e==null?void 0:e.bulletSize)!==void 0&&(e.bulletSize>4?t.style.fontSize=`${e.bulletSize*12700*n}px`:e.bulletSize>0&&(t.style.fontSize=`${e.bulletSize}em`)),RE(e,r)&&(t.style.width="0.5em",t.style.marginRight="0.12em",t.style.transform="scale(0.62)",t.style.transformOrigin="center",t.style.verticalAlign="middle");}function RE(t,e=""){var o,i;if(!t)return false;let n=(i=(o=t.bulletFontFamily)==null?void 0:o.toLowerCase())!=null?i:"",r=Array.from(e.trim()).length;return t.bullet==="\u25A1"&&t.alignment==="center"&&r>0&&r<=4&&(n.includes("wingdings")||n.includes("webdings"))&&t.textIndent!==void 0&&t.textIndent<0&&t.marginLeft!==void 0&&t.marginLeft<=Math.abs(t.textIndent)*1.25}function ba(t,e){return t>10?`${t*e}px`:`${t}em`}function ME(t,e){let n=t,r=e;return t.fontSize!==void 0&&t.fontSize!==(e==null?void 0:e.fontSize)||t.fontFamily!==void 0&&t.fontFamily!==(e==null?void 0:e.fontFamily)||t.color!==void 0&&t.color!==(e==null?void 0:e.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)||t.bold!==void 0&&t.bold!==(e==null?void 0:e.bold)||t.italic!==void 0&&t.italic!==(e==null?void 0:e.italic)||t.underline!==void 0&&t.underline!==(e==null?void 0:e.underline)||t.characterSpacing!==void 0&&t.characterSpacing!==(e==null?void 0:e.characterSpacing)}function AE(t,e,n,r){var i,a,s,l;if(!LE(t,e,n,r))return pm(n,n.style);let o=DE(e.runs.slice(0,r));return pm(n,F(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 pm(t,e){if(!t.hyperlink)return e;let n=v({},e!=null?e:{});return n.textFill===void 0&&n.textGradient===void 0&&(n.color="#0563C1"),n.underline===void 0&&(n.underline=true),n}function LE(t,e,n,r){var s,l,d;if(r<=0||(s=n.style)!=null&&s.color&&n.style.fontSize!==void 0||((l=t.textBody)==null?void 0:l.autoFit)!=="shape"||!/[\u3400-\u9fff]/.test(n.text))return false;let o=e.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:e.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 DE(t){var e;for(let n of t)if(((e=n.style)==null?void 0:e.fontSize)!==void 0)return n.style.fontSize}function Jl(t,e,n){var r,o,i;e.fontSize&&(t.style.fontSize=`${Math.max(1,e.fontSize*12700*n)}px`),e.fontFamily&&(t.style.fontFamily=Im(e.fontFamily)),e.lineHeight&&(t.style.lineHeight=String(e.lineHeight)),e.characterSpacing!==void 0&&(t.style.letterSpacing=`${e.characterSpacing*12700*n}px`),e.color&&(t.style.color=e.color),(r=e.textGradient)!=null&&r.colors.length&&e.textGradient.colors.length>1&&(t.style.backgroundImage=Er(e.textGradient),t.style.backgroundClip="text",t.style.setProperty("-webkit-background-clip","text"),t.style.color="transparent",t.style.setProperty("-webkit-text-fill-color","transparent")),e.textFill==="none"&&(t.style.color=(i=(o=e.textOutlineColor)!=null?o:e.color)!=null?i:"transparent",t.style.setProperty("-webkit-text-fill-color","transparent")),e.textOutlineColor&&t.style.setProperty("-webkit-text-stroke",`1px ${e.textOutlineColor}`),e.textShadow&&(t.style.textShadow=Hm(e.textShadow,n)),e.bold!==void 0&&(t.style.fontWeight=e.bold?"700":"400"),e.italic!==void 0&&(t.style.fontStyle=e.italic?"italic":"normal"),e.underline!==void 0&&(t.style.textDecorationLine=e.underline?"underline":"none");}function Ql(t,e){var r;let n=(r=t==null?void 0:t.toLowerCase())!=null?r:"";return n==="image/png"||n==="image/jpeg"||n==="image/jpg"||n==="image/gif"||n==="image/webp"||n==="image/svg+xml"?true:!!(e&&/\.(?:png|jpe?g|gif|webp|svg)$/i.test(e))}function ed(t,e){if(e==="distributed"){t.style.textAlign="justify",t.style.textAlignLast="justify";return}t.style.textAlign=e==="justify"?"justify":e;}function Mm(t){if(t.customGeometry)return false;let e=t.presetGeometry,n=Math.min(t.bounds.width,t.bounds.height),r=Math.max(t.bounds.width,t.bounds.height);return (e==="line"||e==="straightConnector1")&&r>0&&(n===0||n/r<.02)}function Am(t){return t.bounds.height>t.bounds.width?"vertical":"horizontal"}function Zl(t,e={}){var n;if(t!=null&&t.imagePath){let r=e[t.imagePath],o=r==null?void 0:r.url;if(o&&Ql(r.contentType,t.imagePath))return `url("${o}") center / cover no-repeat`}return t!=null&&t.fillGradient&&t.fillGradient.colors.length>1?Er(t.fillGradient):(n=t==null?void 0:t.fillColor)!=null?n:"#fff"}function WE(t,e,n,r,o,i){if(e!=null&&e.imagePath){let a=i[e.imagePath],s=a==null?void 0:a.url;if(s&&Ql(a.contentType,e.imagePath)){t.style.backgroundImage=`url("${s}")`,t.style.backgroundRepeat="no-repeat",t.style.backgroundSize=`${r.size.width*o}px ${r.size.height*o}px`,t.style.backgroundPosition=`${-n.bounds.left*o}px ${-n.bounds.top*o}px`;return}}t.style.background=Zl(e,i);}function yr(t){var r;let e=(r=t.presetAdjustments)==null?void 0:r.adj,n=e===void 0?.08:Math.max(0,Math.min(.5,e/1e5));return Math.min(t.bounds.width,t.bounds.height)*n}function BE(t,e){var o,i,a;let n=(a=(o=t.presetAdjustments)==null?void 0:o.adj)!=null?a:(i=t.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(t.bounds.width,t.bounds.height)*r*e)}function FE(t){return !t.customGeometry&&t.kind!=="line"&&!t.lineColor&&!!t.lineGradient&&t.lineGradient.colors.length>1&&(t.presetGeometry==="roundRect"||t.presetGeometry==="round1Rect"||t.presetGeometry==="ellipse")}function HE(t,e,n){var o;let r=document.createElement("div");return r.className="coco-ppt-css-geometry",r.style.clipPath=n,t.fillGradient&&t.fillGradient.colors.length>1?r.style.background=Er(t.fillGradient,kr(t)):t.fillColor&&(r.style.background=Sr(t.fillColor,kr(t))),t.lineColor&&(r.style.borderStyle=td(t.lineDash),r.style.borderWidth=`${Math.max(1,((o=t.lineWidth)!=null?o:9525)*e)}px`,r.style.borderColor=Sr(t.lineColor,t.lineOpacity)),r}function Er(t,e=1){return `linear-gradient(${Lm(t)}deg, ${$E(t,e).join(", ")})`}function Lm(t){return t.angle===void 0?160:OE(t.angle+90)}function OE(t){return (t%360+360)%360}function $E(t,e=1){return zE(t).map(n=>{let r=Math.max(0,Math.min(1,n.opacity*e)),o=r<1?Dm(n.color,r):n.color;return n.position===void 0?o:`${o} ${n.position}%`})}function zE(t){return t.colors.map((e,n)=>{var a,s,l,d,u;let r=nd(e),o=(a=t.positions)==null?void 0:a[n],i=Math.max(0,Math.min(1,(d=(l=(s=t.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:e,position:o===void 0?void 0:Math.max(0,Math.min(100,o)),opacity:i,index:n}}).sort((e,n)=>e.position===void 0&&n.position===void 0?e.index-n.index:e.position===void 0?1:n.position===void 0?-1:e.position-n.position||e.index-n.index).map(({color:e,position:n,opacity:r})=>({color:e,position:n,opacity:r}))}function Dm(t,e){var a;let n=(a=t.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:a[1];if(!n)return t;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,e))})`}function VE(t){switch(t){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 td(t){return t==="dot"||t==="sysDot"?"dotted":t&&t!=="solid"?"dashed":"solid"}function Ia(t,e){if(!t||t==="solid"||e<=0)return;let n=Math.max(1,e),r=/^cust:(\d+):(\d+)$/i.exec(t);if(r){let o=Number(r[1])/1e5,i=Number(r[2])/1e5;if(o>0&&i>=0)return `${n*o} ${n*i}`}switch(t){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 Wm(t){return t.presetGeometry==="curvedUpArrow"||t.presetGeometry==="donut"||t.presetGeometry==="arc"||t.presetGeometry==="blockArc"||t.presetGeometry==="plaque"||t.presetGeometry==="parallelogram"||t.presetGeometry==="trapezoid"||t.presetGeometry==="snip2DiagRect"||t.presetGeometry==="rtTriangle"||t.presetGeometry==="triangle"||t.presetGeometry==="diamond"||t.presetGeometry==="pentagon"||t.presetGeometry==="hexagon"||t.presetGeometry==="homePlate"||t.presetGeometry==="leftRightArrow"||t.presetGeometry==="chevron"||t.presetGeometry==="rightArrow"||t.presetGeometry==="leftArrow"||t.presetGeometry==="bentArrow"}function GE(t,e){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,t.bounds.width*e),o=Math.max(1,t.bounds.height*e),i=jE(t,e,r,o);(t.shadow||i>0)&&(n.style.overflow="visible"),n.setAttribute("viewBox","0 0 100 100"),n.setAttribute("preserveAspectRatio","none");let a=t.fillGradient&&t.fillGradient.colors.length>1?`coco-ppt-preset-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,s=t.lineGradient&&t.lineGradient.colors.length>1?`coco-ppt-preset-line-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;if(a&&t.fillGradient&&Un(n,a,t.fillGradient),s&&t.lineGradient&&Un(n,s,t.lineGradient),i>0){let g=document.createElementNS("http://www.w3.org/2000/svg","path");g.classList.add("coco-ppt-preset-extrusion"),g.setAttribute("d",hm(t)),(t.presetGeometry==="donut"||t.presetGeometry==="blockArc")&&g.setAttribute("fill-rule","evenodd"),g.setAttribute("fill",UE(t)),g.setAttribute("transform",`translate(${wr(i*.38)} ${wr(i)})`),g.setAttribute("stroke","none"),n.append(g);}let l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",hm(t)),(t.presetGeometry==="donut"||t.presetGeometry==="blockArc")&&l.setAttribute("fill-rule","evenodd");let d=t.lineColor||t.lineGradient?Math.max(.5,((f=t.lineWidth)!=null?f:9525)*e*100/Math.max(r,o)):0;l.setAttribute("fill",t.presetGeometry==="arc"?"none":a?`url(#${a})`:(b=t.fillColor)!=null?b:"none");let u=kr(t);u!==void 0&&t.presetGeometry!=="arc"&&l.setAttribute("fill-opacity",String(u)),l.setAttribute("stroke",s?`url(#${s})`:(w=t.lineColor)!=null?w:"none"),l.setAttribute("stroke-width",String(d)),t.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,t.lineOpacity))));let p=Ia(t.lineDash,d);return p&&l.setAttribute("stroke-dasharray",p),l.setAttribute("stroke-linejoin","round"),t.presetGeometry==="arc"&&(l.setAttribute("stroke-linecap","round"),YE(n,l,t)),n.append(l),n}function jE(t,e,n,r){var a,s;let o=(s=(a=t.threeD)==null?void 0:a.extrusionHeight)!=null?s:0;if(o<=0||t.presetGeometry==="arc")return 0;let i=o*e*100/Math.max(n,r);return Math.max(.8,Math.min(3,i))}function UE(t){var o,i,a,s,l;let e=(a=(i=(o=t.fillGradient)==null?void 0:o.colors[0])!=null?i:t.fillColor)!=null?a:"#64748B",n=nd(e),r=((s=t.threeD)==null?void 0:s.material)==="translucentPowder"?.12:.18;return Dm(KE((l=n==null?void 0:n.color)!=null?l:e,.8),r)}function KE(t,e){let n=/^#?([0-9a-f]{6})$/i.exec(t);if(!n)return t;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 `#${vr(o*e)}${vr(i*e)}${vr(a*e)}`}function hm(t){switch(t.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 _E(t);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 XE(t);default:return ""}}function _E(t){var g,h,x,S,k,I;let e=((h=(g=t.presetAdjustments)==null?void 0:g.adj1)!=null?h:0)/6e4,n=((S=(x=t.presetAdjustments)==null?void 0:x.adj2)!=null?S:54e5)/6e4,r=qE(n-e),o=e+r,i=48,a=Math.max(.08,Math.min(.42,((I=(k=t.presetAdjustments)==null?void 0:k.adj3)!=null?I:25e3)/1e5)),s=i*(1-a),l=Ao(e,i),d=Ao(o,i),u=Ao(o,s),p=Ao(e,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 qE(t){if(!Number.isFinite(t)||t===0)return 90;let e=t%360;return e>330&&(e=330),e<-330&&(e=-330),Math.abs(e)<8&&(e=e<0?-8:8),e}function XE(t){var s,l,d,u,p,f,b,w;let e=mm((l=(s=t.presetAdjustments)==null?void 0:s.adj1)!=null?l:18e6),n=mm((u=(d=t.presetAdjustments)==null?void 0:d.adj2)!=null?u:0),r=((f=(p=t.presetAdjustments)==null?void 0:p.adj1)!=null?f:18e6)/6e4,a=((((w=(b=t.presetAdjustments)==null?void 0:b.adj2)!=null?w:0)/6e4-r)%360+360)%360>180?1:0;return `M ${e.x.toFixed(3)} ${e.y.toFixed(3)} A 48 48 0 ${a} 1 ${n.x.toFixed(3)} ${n.y.toFixed(3)}`}function mm(t){return Ao(t/6e4,48)}function Ao(t,e){let n=t/180*Math.PI;return {x:50+e*Math.cos(n),y:50+e*Math.sin(n)}}function YE(t,e,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),t.append(o),n.lineHeadEnd==="triangle"&&e.setAttribute("marker-start",`url(#${r})`),n.lineTailEnd==="triangle"&&e.setAttribute("marker-end",`url(#${r})`);}function ZE(t,e){if(!t.customGeometry||JE(t.customGeometry))return false;let n=Math.max(0,t.bounds.width)*Math.max(0,t.bounds.height),r=Math.max(1,e.size.width*e.size.height),o=n/r>.85,i=Math.abs(t.bounds.left)<e.size.width*.05&&Math.abs(t.bounds.top)<e.size.height*.05;return !(o&&i)}function JE(t){var s,l;if(t.paths.length!==1)return false;let e=t.paths[0];if(!e)return false;let n=(s=e.width)!=null?s:0,r=(l=e.height)!=null?l:0;if(n<=0||r<=0)return false;let o=[];for(let d of e.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=QE(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=>ka(u.x,d.x)&&ka(u.y,d.y)))}function QE(t){let e=[];for(let n of t)e.some(r=>ka(r.x,n.x)&&ka(r.y,n.y))||e.push(n);return e}function ka(t,e){return Math.abs(t-e)<=1}function eC(t,e){var u,p,f,b,w,g,h,x;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=t.customGeometry)==null?void 0:u.paths[0])==null?void 0:p.width)!=null?f:t.bounds.width),o=Math.max(1,(g=(w=(b=t.customGeometry)==null?void 0:b.paths[0])==null?void 0:w.height)!=null?g:t.bounds.height);n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none");let i=`coco-ppt-picture-clip-${t.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 (x=(h=t.customGeometry)==null?void 0:h.paths)!=null?x:[]){let k=document.createElementNS("http://www.w3.org/2000/svg","path");k.setAttribute("d",Fm(S.commands)),Bm(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",e),l.setAttributeNS("http://www.w3.org/1999/xlink","href",e);let d=tC(t,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})`),t.imageOpacity!==void 0&&l.setAttribute("opacity",String(Math.max(0,Math.min(1,t.imageOpacity)))),n.append(l),n}function tC(t,e,n){var u,p,f,b,w,g,h,x;if(t.imageFillRect){let S=(u=t.imageFillRect.left)!=null?u:0,k=(p=t.imageFillRect.right)!=null?p:0,I=(f=t.imageFillRect.top)!=null?f:0,D=(b=t.imageFillRect.bottom)!=null?b:0;return {x:S*e,y:I*n,width:Math.max(.01,1-S-k)*e,height:Math.max(.01,1-I-D)*n}}let r=t.imageCrop;if(!r)return {x:0,y:0,width:e,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=(x=r.bottom)!=null?x:0,l=Math.max(.01,1-o-i),d=Math.max(.01,1-a-s);return {x:-o/l*e,y:-a/d*n,width:1/l*e,height:1/d*n}}function nC(t,e){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=t.customGeometry)==null?void 0:s.paths[0])==null?void 0:l.width)!=null?d:t.bounds.width,o=(f=(p=(u=t.customGeometry)==null?void 0:u.paths[0])==null?void 0:p.height)!=null?f:t.bounds.height;n.setAttribute("viewBox",`0 0 ${Math.max(1,r)} ${Math.max(1,o)}`),n.setAttribute("preserveAspectRatio","none");let i=t.fillGradient&&t.fillGradient.colors.length>1?`coco-ppt-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,a=t.lineGradient&&t.lineGradient.colors.length>1?`coco-ppt-custom-line-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;i&&t.fillGradient&&Un(n,i,t.fillGradient),a&&t.lineGradient&&Un(n,a,t.lineGradient);for(let x of (w=(b=t.customGeometry)==null?void 0:b.paths)!=null?w:[]){let S=oC(t,x),k=rC(x),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",Fm(x.commands)),Bm(x.commands)&&I.setAttribute("fill-rule","evenodd"));let D=!(t.kind==="line"&&t.lineDash);I.setAttribute("fill",D?i?`url(#${i})`:(g=t.fillColor)!=null?g:"none":"none");let H=kr(t);D&&H!==void 0&&I.setAttribute("fill-opacity",String(H)),I.setAttribute("stroke",a?`url(#${a})`:(h=t.lineColor)!=null?h:"none"),I.setAttribute("stroke-width",String(S)),t.lineOpacity!==void 0&&I.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,t.lineOpacity))));let A=Ia(t.lineDash,S);A&&I.setAttribute("stroke-dasharray",A),I.setAttribute("stroke-linejoin","round"),I.setAttribute("stroke-linecap","round"),n.append(I);}return n}function rC(t){var u,p,f,b,w,g;let e=t.width,n=t.height;if(!e||!n||e<=0||n<=0)return;let r=t.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=e/2,i=n/2,a=[r[0],r[1],r[2],r[3],r[4]],s=[{x:e,y:i},{x:o,y:n},{x:0,y:i},{x:o,y:0},{x:e,y:i}],l=Math.max(e,n)*.003;return a.every((h,x)=>h.kind!=="moveTo"&&h.kind!=="cubicBezierTo"?false:Math.abs(h.x-s[x].x)<=l&&Math.abs(h.y-s[x].y)<=l)?{cx:o,cy:i,rx:e/2,ry:n/2}:void 0}function Bm(t){return t.filter(e=>e.kind==="moveTo").length>1}function oC(t,e){if(!t.lineWidth)return 0;let n=e.width&&t.bounds.width?e.width/t.bounds.width:void 0,r=e.height&&t.bounds.height?e.height/t.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,t.lineWidth*i)}function iC(t,e){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,t.bounds.width*e),o=Math.max(1,t.bounds.height*e),i=Math.max(1,((u=t.lineWidth)!=null?u:9525)*e),a=i/2,s=`coco-ppt-line-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`;n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none"),Un(n,s,t.lineGradient);let l=t.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,yr(t)*e-a))),l.setAttribute("ry",String(Math.max(0,yr(t)*e-a)))),l.setAttribute("fill","none"),l.setAttribute("stroke",`url(#${s})`),l.setAttribute("stroke-width",String(i)),t.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,t.lineOpacity))));let d=Ia(t.lineDash,i);return d&&l.setAttribute("stroke-dasharray",d),n.append(l),n}function aC(t,e){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,t.bounds.width*e),o=Math.max(1,t.bounds.height*e),i=Math.max(1,((u=t.lineWidth)!=null?u:9525)*e),a=t.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=t.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=t.presetGeometry==="roundRect"||t.presetGeometry==="round1Rect"?Math.max(0,yr(t)*e-s):0;l.setAttribute("rx",String(f)),l.setAttribute("ry",String(f));}l.setAttribute("fill","none"),l.setAttribute("stroke",(p=t.lineColor)!=null?p:"none"),l.setAttribute("stroke-width",String(i)),t.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,t.lineOpacity))));let d=Ia(t.lineDash,i);return d&&l.setAttribute("stroke-dasharray",d),n.append(l),n}function sC(t,e){var w,g;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-line-geometry");let r=Am(t)==="vertical",o=Math.max(r?12:1,t.bounds.width*e),i=Math.max(r?1:12,t.bounds.height*e);n.setAttribute("viewBox",`0 0 ${o} ${i}`),n.setAttribute("preserveAspectRatio","none");let a=Math.max(1,((w=t.lineWidth)!=null?w:9525)*e),s=t.lineGradient&&t.lineGradient.colors.length>1?`coco-ppt-connector-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;s&&t.lineGradient&&Un(n,s,t.lineGradient);let l=s?`url(#${s})`:Sr((g=t.lineColor)!=null?g:"#000000",t.lineOpacity),d=lC(a),u=Math.max(5,a*3.2),p=Math.max(5,a*2.6),f=gm(t.lineHeadEnd),b=gm(t.lineTailEnd);if(r){let h=o/2,x=f?Math.min(i,u):0,S=b?Math.max(0,i-u):i;Cr(n,h,x,h,S,l,a,t.lineOpacity,t.lineCap),t.lineHeadEnd==="oval"&&Cn(n,h,0,d,l),t.lineTailEnd==="oval"&&Cn(n,h,i,d,l),f&&ya(n,h,0,"up",u,p,l,t.lineOpacity),b&&ya(n,h,i,"down",u,p,l,t.lineOpacity);}else {let h=i/2,x=f?Math.min(o,u):0,S=b?Math.max(0,o-u):o;Cr(n,x,h,S,h,l,a,t.lineOpacity,t.lineCap),t.lineHeadEnd==="oval"&&Cn(n,0,h,d,l),t.lineTailEnd==="oval"&&Cn(n,o,h,d,l),f&&ya(n,0,h,"left",u,p,l,t.lineOpacity),b&&ya(n,o,h,"right",u,p,l,t.lineOpacity);}return n}function lC(t){return Math.max(3,t*3)}function gm(t){return t==="arrow"||t==="triangle"}function Fm(t){let e=[],n;for(let r of t)if(r.kind==="moveTo")e.push(`M ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="lineTo")e.push(`L ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="cubicBezierTo")e.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=dC(r,n);o&&(e.push(o.path),n=o.end);}else e.push("Z");return e.join(" ")}function dC(t,e){if(!e||t.wR<=0||t.hR<=0||t.swAng===0)return;let n=t.stAng/6e4,r=t.swAng/6e4,o=n+r,i=bm(t.wR,t.hR,n),a={x:e.x-i.x,y:e.y-i.y},s=bm(t.wR,t.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 ${wr(t.wR)} ${wr(t.hR)} 0 ${d} ${u} ${wr(l.x)} ${wr(l.y)}`,end:l}}function bm(t,e,n){let r=n/180*Math.PI;return {x:t*Math.cos(r),y:e*Math.sin(r)}}function wr(t){return Number.isInteger(t)?String(t):t.toFixed(3).replace(/\.?0+$/,"")}function Un(t,e,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}:cC(Lm(n));s.setAttribute("id",e),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,x;let p=(w=i==null?void 0:i[u])!=null?w:u/Math.max(1,o.length-1)*100,f=nd(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:(x=f==null?void 0:f.color)!=null?x: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),t.append(r);}function cC(t){let e=t*Math.PI/180,n=Math.sin(e),r=-Math.cos(e),o=50/Math.max(Math.abs(n),Math.abs(r),1e-4);return {x1:wa(50-n*o),y1:wa(50-r*o),x2:wa(50+n*o),y2:wa(50+r*o)}}function wa(t){return Math.round(Math.max(0,Math.min(100,t))*1e3)/1e3}function nd(t){let e=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*([0-9.]+)\s*)?\)$/i.exec(t);if(!e)return;let n=Math.max(0,Math.min(255,Number(e[1]))),r=Math.max(0,Math.min(255,Number(e[2]))),o=Math.max(0,Math.min(255,Number(e[3]))),i=e[4]===void 0?1:Math.max(0,Math.min(1,Number(e[4])));return {color:`#${vr(n)}${vr(r)}${vr(o)}`,opacity:i}}function vr(t){return Math.round(t).toString(16).padStart(2,"0").toUpperCase()}function uC(t,e,n=true){var d,u,p,f,b,w,g,h,x,S,k,I,D,H,A;let r=document.createElement("table");r.className="coco-ppt-table";let o=t.table;if(!o)return r;let i=Math.max(o.rowCount,o.values.length),a=Math.max(o.columnCount,...o.values.map(O=>O.length),1),s=(u=(d=o.columnWidths)==null?void 0:d.reduce((O,ee)=>O+ee,0))!=null?u:0;if(s>0){let O=document.createElement("colgroup");for(let ee=0;ee<a;ee++){let le=document.createElement("col"),ae=(p=o.columnWidths)==null?void 0:p[ee];ae&&(le.style.width=`${ae/s*100}%`),O.append(le);}r.append(O);}let l=(b=(f=o.rowHeights)==null?void 0:f.reduce((O,ee)=>O+ee,0))!=null?b:0;for(let O=0;O<i;O++){let ee=document.createElement("tr"),le=(w=o.rowHeights)==null?void 0:w[O];ee.style.height=l>0&&le?`${le/l*100}%`:`${100/i}%`;for(let ae=0;ae<a;ae++){let te=gC(o,O,ae);if(te!=null&&te.hMerge||te!=null&&te.vMerge)continue;let oe=document.createElement("td"),U=(h=(g=o.cellStyles)==null?void 0:g[O])==null?void 0:h[ae];n&&(oe.dataset.row=String(O),oe.dataset.column=String(ae));let X=(S=(x=o.values[O])==null?void 0:x[ae])!=null?S:"";if(oe.dataset.cellText=X,pC(oe,X),te!=null&&te.columnSpan&&te.columnSpan>1&&(oe.colSpan=te.columnSpan),te!=null&&te.rowSpan&&te.rowSpan>1&&(oe.rowSpan=te.rowSpan),U!=null&&U.fillGradient&&U.fillGradient.colors.length>1?oe.style.background=Er(U.fillGradient):U!=null&&U.fillColor&&!hC(U.fillColor)&&(oe.style.background=U.fillColor),U!=null&&U.body){let B=U.body,G=(k=B.insetLeft)!=null?k:91440,z=(I=B.insetTop)!=null?I:45720,K=(D=B.insetRight)!=null?D:91440,Y=(H=B.insetBottom)!=null?H:45720;oe.style.padding=`${z*e}px ${K*e}px ${Y*e}px ${G*e}px`,B.anchor==="middle"&&(oe.style.verticalAlign="middle"),B.anchor==="bottom"&&(oe.style.verticalAlign="bottom"),B.anchor==="top"&&(oe.style.verticalAlign="top");}U!=null&&U.textStyle&&Jl(oe,U.textStyle,e),(A=U==null?void 0:U.textStyle)!=null&&A.alignment&&ed(oe,U.textStyle.alignment),fC(oe,U,e),ee.append(oe);}r.append(ee);}return r}function fC(t,e,n){let r=e==null?void 0:e.borders;r&&(xa(t,"Left",r.left,n),xa(t,"Right",r.right,n),xa(t,"Top",r.top,n),xa(t,"Bottom",r.bottom,n));}function xa(t,e,n,r){var s,l;if(!n)return;let o=`border${e}Style`,i=`border${e}Width`,a=`border${e}Color`;if(n.hidden){t.style[o]="none",t.style[i]="0";return}t.style[o]=td(n.dash),t.style[i]=`${Math.max(1,((s=n.width)!=null?s:9525)*r)}px`,t.style[a]=Sr((l=n.color)!=null?l:"#94A3B8",n.opacity);}function pC(t,e){let n=e.split(/\r?\n/);if(n.length<=1){t.textContent=e;return}n.forEach((r,o)=>{o>0&&t.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"),t.append(i);});}function wm(t,e,n,r){var o,i,a,s,l;return (l=(s=(a=t.dataset.cellText)!=null?a:(i=(o=e.table)==null?void 0:o.values[n])==null?void 0:i[r])!=null?s:t.textContent)!=null?l:""}function hC(t){let e=/^#?([0-9a-f]{6})$/i.exec(t);if(!e)return false;let n=e[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 Hm(t,e){var s,l,d;let n=((s=t.distance)!=null?s:0)*e,r=((l=t.direction)!=null?l:0)*Math.PI/180,o=Math.cos(r)*n,i=Math.sin(r)*n,a=((d=t.blur)!=null?d:0)*e;return `${o}px ${i}px ${a}px ${mC(t)}`}function mC(t){var l,d;let e=(l=t.color)!=null?l:"#000000",n=(d=t.opacity)!=null?d:.25,r=/^#?([0-9a-f]{6})$/i.exec(e);if(!r)return e;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 gC(t,e,n){var r;return (r=t.mergedCells)==null?void 0:r.find(o=>o.row===e&&o.column===n)}function bC(t){var h,x,S,k,I,D,H,A,O,ee,le,ae,te,oe,U,X;let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 100 60"),e.setAttribute("width","100%"),e.setAttribute("height","100%"),e.setAttribute("preserveAspectRatio","none");let n=(h=t.chart)==null?void 0:h.data;if(!(n!=null&&n.series.length))return St(e,(x=t.name)!=null?x:"Chart",4,8,4,"#17202a"),e;let r=(k=(S=t.chart)==null?void 0:S.type)!=null?k:"",o=(I=t.chart)==null?void 0:I.grouping,i=wC(n.series,r,o),a=Math.max(...i,1),s=Math.min(...i,0),l=(H=(D=t.chart)==null?void 0:D.axes)==null?void 0:H.value,d=(O=(A=t.chart)==null?void 0:A.axes)==null?void 0:O.category,u=(ee=l==null?void 0:l.min)!=null?ee:s>=0?0:s,p=(le=l==null?void 0:l.max)!=null?le:s>=0?vC(a):a,f=xC(t),b=SC(u,p,l==null?void 0:l.majorUnit);if(r.includes("doughnut")||r.includes("pie"))return DC(e,n.series,f),e;if(r.includes("radar"))return HC(e,n.series,f,(ae=l==null?void 0:l.max)!=null?ae:a),e;(l==null?void 0:l.majorGridlines)!==false&&CC(e,f,b,t,l,d),(l==null?void 0:l.deleted)!==true&&(l==null?void 0:l.tickLabelPosition)!=="none"&&IC(e,f,u,p,b),kC(e,t,f);let w=n.series.filter(B=>{var G,z,K;return ((K=(z=B.type)!=null?z:(G=t.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?(PC(e,w,f,u,p,t,o),vm(e,(oe=(te=w[0])==null?void 0:te.categories)!=null?oe:[],f),w.some(B=>B.showValueLabels)&&LC(e,w,f,u,p),g.length>0&&xm(e,g,f,u,p,void 0,t),g.some(B=>B.showValueLabels)&&Sm(e,g,f,u,p)):(xm(e,n.series,f,u,p,["#22C7F2","#22C7F2","#94A3B8","#F59E0B"],t),vm(e,(X=(U=n.series.find(B=>{var G;return (G=B.categories)==null?void 0:G.length}))==null?void 0:U.categories)!=null?X:[],f),n.series.some(B=>B.showValueLabels)&&Sm(e,n.series,f,u,p)),e}function wC(t,e,n){var a;let r=t.filter(s=>{var l;return ((l=s.type)!=null?l:e).includes("bar")});if(!$m(n)||r.length<=1)return t.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 xC(t){var u,p,f,b,w,g,h,x,S,k,I,D,H,A,O,ee;let e=(u=t.chart)==null?void 0:u.plotLayout,n=(f=(p=t.chart)==null?void 0:p.type)!=null?f:"";if(!e)return zm((g=(w=(b=t.chart)==null?void 0:b.data)==null?void 0:w.series)!=null?g:[])?{left:7,top:8,width:88,height:40}:yC(t)?{left:18,top:8,width:72,height:40}:((S=(x=(h=t.chart)==null?void 0:h.axes)==null?void 0:x.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=((D=(I=(k=t.chart)==null?void 0:k.axes)==null?void 0:I.value)==null?void 0:D.deleted)!==true&&!n.includes("doughnut")&&!n.includes("pie")&&!n.includes("radar")?14:4,i=((H=e.x)!=null?H:.12)*100,a=((A=e.y)!=null?A:.13)*60,s=((O=e.width)!=null?O:.82)*100,l=((ee=e.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 yC(t){var i,a,s,l,d,u,p,f;let e=t.chart,n=(i=e==null?void 0:e.type)!=null?i:"";if(!e||!n.includes("bar")||e.plotLayout)return false;let r=(s=(a=e.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(t){if(t<=0)return 1;if(t<=10)return Math.max(1,Math.ceil(t));let e=t*1.1,n=10**Math.floor(Math.log10(e));return Math.ceil(e/n)*n}function SC(t,e,n){let r=Math.abs(e-t);return n&&n>0?Math.max(1,Math.min(8,Math.round(r/n))):Number.isInteger(r)&&r>0&&r<=6?r:4}function kC(t,e,n){var d,u,p,f,b,w,g;let r=(f=(d=e.chart)==null?void 0:d.title)!=null?f:(p=(u=e.chart)==null?void 0:u.data)==null?void 0:p.title;r&&St(t,r,n.left+n.width*.5,Math.max(4,n.top-3.2),3.1,"#17202A","middle");let o=(g=(w=(b=e.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,x)=>{var I,D,H,A,O,ee;let S=(I=o.find(le=>le.name===h))!=null?I:o[x],k=S?EC(t,S,x,a):a[x];S&&((D=S.type)!=null?D:"").includes("line")?(Cr(t,s,l-1.1,s+2.3,l-1.1,k,.45),Cn(t,s+1.15,l-1.1,.45,(A=(H=S.marker)==null?void 0:H.fillColor)!=null?A:"#FFFFFF",(ee=(O=S.marker)==null?void 0:O.lineColor)!=null?ee:k,.32),St(t,h,s+2.8,l-.45,2.2,"#64748B")):(Do(t,s,l-1.8,1.4,1.4,k),St(t,h,s+2,l-.45,2.2,"#64748B")),s+=Math.max(9,Array.from(h).length*2.2+4.5);});}function EC(t,e,n,r){var o,i;return ((o=e.type)!=null?o:"").includes("line")?(i=e.lineColor)!=null?i:r[n]:Na(t,e,n,r)}function CC(t,e,n,r,o,i){var l,d;let a=(l=o==null?void 0:o.gridlineColor)!=null?l:"#E8EDF3",s=ym(o==null?void 0:o.gridlineWidth,r,.35);for(let u=0;u<=n;u++){let p=e.top+e.height/n*u;Cr(t,e.left,p,e.left+e.width,p,a,s);}Cr(t,e.left,e.top+e.height,e.left+e.width,e.top+e.height,(d=i==null?void 0:i.lineColor)!=null?d:"#CBD5E1",ym(i==null?void 0:i.lineWidth,r,.45));}function IC(t,e,n,r,o){for(let i=0;i<=o;i++){let a=r-(r-n)/o*i,s=e.top+e.height/o*i+1;St(t,rd(a),e.left-1.8,s,3,"#9AA6B2","end");}}function rd(t){return Number.isInteger(t)?String(t):t.toFixed(1).replace(/\.0$/,"")}function xm(t,e,n,r,o,i=["#CBD5E1","#94A3B8","#F59E0B","#A3E635"],a){e.forEach((s,l)=>{var f,b,w,g,h,x,S;if(s.values.length===0)return;let d=s.values.map((k,I)=>{let D=n.left+(s.values.length===1?n.width/2:n.width*I/(s.values.length-1)),H=n.top+n.height-(k-r)/Math.max(1,o-r)*n.height;return {x:D,y:H}}),u=TC(d,s.smooth===true),p=(f=s.lineColor)!=null?f:i[l%i.length];if(jm(t,u,p,Om(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=(x=(h=s.marker)==null?void 0:h.fillColor)!=null?x:p,D=(S=s.marker)==null?void 0:S.lineColor,H=NC(s,a);d.forEach(A=>Cn(t,A.x,A.y,k,I,D,H));}});}function NC(t,e){var n;if(!(!((n=t.marker)!=null&&n.lineWidth)||!(e!=null&&e.bounds.width)))return Math.max(.25,Math.min(1,t.marker.lineWidth/e.bounds.width*100))}function Om(t,e){return !t.lineWidth||!(e!=null&&e.bounds.width)?.8:Math.max(.3,Math.min(1.2,t.lineWidth/e.bounds.width*100))}function TC(t,e){if(t.length===0)return "";if(!e||t.length<3)return t.map((r,o)=>`${o===0?"M":"L"} ${r.x} ${r.y}`).join(" ");let n=[`M ${t[0].x} ${t[0].y}`];for(let r=0;r<t.length-1;r++){let o=t[Math.max(0,r-1)],i=t[r],a=t[r+1],s=t[Math.min(t.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 PC(t,e,n,r,o,i,a){if($m(a)&&e.length>1){MC(t,e,n,r,o,i);return}if(zm(e)){RC(t,e,n,r,o,i);return}let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],l=Math.max(...e.map(p=>p.values.length),1),d=n.width/l,u=Math.max(1,d*.48/Math.max(e.length,1));e.forEach((p,f)=>{let b=Na(t,p,f,s);p.values.forEach((w,g)=>{var k,I;let h=(w-r)/Math.max(1,o-r)*n.height,x=n.left+g*d+(d-u*e.length)/2+f*u,S=n.top+n.height-h;Do(t,x,S,u,h,(I=(k=p.pointColors)==null?void 0:k[g])!=null?I:b,p.borderColor,od(p,i));});});}function RC(t,e,n,r,o,i){let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=Math.max(...e.map(u=>u.values.length),1),l=n.width/s,d=Math.max(1,l*.34);e.forEach((u,p)=>{let f=Na(t,u,p,a);u.values.forEach((b,w)=>{var S,k;let g=Ea(b,n,r,o),h=Ea(0,n,r,o),x=n.left+w*l+(l-d)/2;Do(t,x,Math.min(g,h),d,Math.max(.1,Math.abs(h-g)),(k=(S=u.pointColors)==null?void 0:S[w])!=null?k:f,u.borderColor,od(u,i));});});}function MC(t,e,n,r,o,i){let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=Math.max(...e.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));e.forEach((f,b)=>{let w=Na(t,f,b,a);f.values.forEach((g,h)=>{var H,A;let x=g>=0?u[h]:p[h],S=x+g,k=Ea(x,n,r,o),I=Ea(S,n,r,o),D=n.left+h*l+(l-d)/2;Do(t,D,Math.min(k,I),d,Math.max(.1,Math.abs(I-k)),(A=(H=f.pointColors)==null?void 0:H[h])!=null?A:w,f.borderColor,od(f,i)),g>=0?u[h]=S:p[h]=S;});});}function Ea(t,e,n,r){return e.top+e.height-(t-n)/Math.max(1,r-n)*e.height}function $m(t){return t==="stacked"||t==="percentStacked"}function zm(t){return new Set(t.map(n=>{var r;return (r=n.chartGroup)!=null?r:0})).size>1&&t.every(n=>!n.type||n.type.includes("bar"))}function od(t,e){if(t.borderWidth)return Vm(e!=null&&e.bounds.width?t.borderWidth/e.bounds.width*100:void 0,void 0)}function ym(t,e,n){var r;return (r=Vm(t!==void 0&&e.bounds.width?t/e.bounds.width*100:void 0,n))!=null?r:n}function Vm(t,e){return t===void 0?e:Math.max(.15,Math.min(1.4,t))}function Na(t,e,n,r){var o,i;if((o=e.fillGradient)!=null&&o.colors.length&&e.fillGradient.colors.length>1){let a=`coco-chart-gradient-${n}-${e.fillGradient.colors.join("-").replace(/[^a-zA-Z0-9_-]/g,"_")}`;return Un(t,a,e.fillGradient),`url(#${a})`}return (i=e.fillColor)!=null?i:r[n%r.length]}function AC(t,e,n){var r,o,i;return (i=(o=(r=t.pointColors)==null?void 0:r[e])!=null?o:t.fillColor)!=null?i:n[e%n.length]}function vm(t,e,n){if(e.length===0)return;let r=n.width/e.length;e.forEach((o,i)=>{St(t,o,n.left+r*i+r/2,n.top+n.height+5.2,3.2,"#64748B","middle");});}function LC(t,e,n,r,o){let i=Math.max(...e.map(l=>l.values.length),1),a=n.width/i,s=Math.max(1,a*.48/Math.max(e.length,1));e.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*e.length)/2+d*s+s/2,w=n.top+n.height-f-2;St(t,String(u),b,w,3,"#A7AEB8","middle");});});}function Sm(t,e,n,r,o){e.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(t,String(a),l,Math.max(n.top+2,d-2.2),2.6,"#374151","middle");});});}function DC(t,e,n){var b;let r=e[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,x=u,S=u+h;if(OC(t,a,s,l,d,x,S,AC(r,g,o)),r.showCategoryNameLabels||r.showPercentLabels||r.showValueLabels){let k=WC(r,w,g,i);if(k.length>0){let I=BC(r,g,a,s,l+3.6,n,(x+S)/2);GC(t,k,I.x,I.y,1.9,"#334155",I.x>=a?"start":"end");}}u+=h;}),Cn(t,a,s,d*.92,"#FFFFFF");let p=FC(r.name);p&&St(t,p,a,s-1.8,1.8,"#64748B","middle");let f=r.values[0];f!==void 0&&St(t,Gm(f,i),a,s+3.4,3.9,"#1E3A8A","middle"),$C(t,(b=r.categories)!=null?b:[],o,n.left+n.width*.72,n.top+9);}function WC(t,e,n,r){var a;let o=[],i=(a=t.categories)==null?void 0:a[n];return t.showCategoryNameLabels&&i&&o.push(i),t.showValueLabels&&o.push(rd(e)),t.showPercentLabels&&o.push(Gm(e,r)),o}function BC(t,e,n,r,o,i,a){return xr(n,r,o,a)}function Gm(t,e){let r=(t>0&&t<=1&&e<=2?t:t/Math.max(1,e))*100;return `${Number.isInteger(r)?r.toFixed(0):r.toFixed(1)}%`}function FC(t){let e=(t!=null?t:"").trim();if(!e)return "";let n=Array.from(e);return n.length<=6?e:`${n.slice(0,5).join("")}\u2026`}function HC(t,e,n,r){var d;let o=e[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++)jm(t,zC(i,a,s,l*u/4),"#CBD5E1",.25);for(let u=0;u<i;u++){let p=va(u,i,a,s,l);Cr(t,a,s,p.x,p.y,"#E2E8F0",.25);}e.forEach((u,p)=>{var w;if(!u.values.length)return;let f=u.values.slice(0,i).map((g,h)=>va(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(Om(u,void 0))),t.append(b),u.marker&&u.marker.symbol!=="none"&&f.forEach(g=>{var h;return Cn(t,g.x,g.y,.9,(h=u.lineColor)!=null?h:"#2563EB")}),u.showValueLabels&&u.values.slice(0,i).forEach((g,h)=>{var S;let x=f[h];St(t,rd(g),x.x,x.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=va(p,i,a,s,l+5);St(t,u,f.x,f.y+1,2.6,"#64748B","middle");});}function OC(t,e,n,r,o,i,a,s){let d=Math.max(.01,a-i)>180?1:0,u=xr(e,n,r,i),p=xr(e,n,r,a),f=xr(e,n,o,a),b=xr(e,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),t.append(w);}function $C(t,e,n,r,o){e.slice(0,6).forEach((i,a)=>{Do(t,r,o+a*5,2.4,2.4,n[a%n.length]),St(t,i,r+3.6,o+a*5+2.2,2.7,"#334155");});}function zC(t,e,n,r,o){return Array.from({length:t},(i,a)=>{let s=va(a,t,e,n,r);return `${a===0?"M":"L"} ${s.x} ${s.y}`}).join(" ")+(" Z")}function va(t,e,n,r,o){return xr(n,r,o,-90+360*t/e)}function xr(t,e,n,r){let o=r*Math.PI/180;return {x:t+Math.cos(o)*n,y:e+Math.sin(o)*n}}function Cr(t,e,n,r,o,i,a,s,l){let d=document.createElementNS("http://www.w3.org/2000/svg","line");d.setAttribute("x1",String(e)),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",VC(l)),s!==void 0&&d.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,s)))),t.append(d);}function VC(t){return t==="rnd"?"round":t==="sq"?"square":"butt"}function jm(t,e,n,r){let o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",e),o.setAttribute("fill","none"),o.setAttribute("stroke",n),o.setAttribute("stroke-width",String(r)),o.setAttribute("stroke-linejoin","round"),o.setAttribute("stroke-linecap","round"),t.append(o);}function Cn(t,e,n,r,o,i,a){let s=document.createElementNS("http://www.w3.org/2000/svg","circle");s.setAttribute("cx",String(e)),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)),t.append(s);}function ya(t,e,n,r,o,i,a,s){let l=i/2,d=r==="right"?[[e,n],[e-o,n-l],[e-o,n+l]]:r==="left"?[[e,n],[e+o,n-l],[e+o,n+l]]:r==="down"?[[e,n],[e-l,n-o],[e+l,n-o]]:[[e,n],[e-l,n+o],[e+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)))),t.append(u);}function Do(t,e,n,r,o,i,a,s){let l=document.createElementNS("http://www.w3.org/2000/svg","rect");l.setAttribute("x",String(e)),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))),t.append(l);}function St(t,e,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=e,t.append(s);}function GC(t,e,n,r,o,i,a="start"){e.forEach((s,l)=>{St(t,s,n,r+l*o*1.2,o,i,a);});}
|
|
1758
|
-
export{ok as DEFAULT_PPT_SLIDE_SIZE,hn as EditorReadOnlyError,Ti as NATIVE_BLOCK_CLIPBOARD_TYPE,fa as PptEditorSession,ur as SPREADSHEET_CLIPBOARD_MIME,
|
|
1770
|
+
`;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(e,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(e){return typeof document=="undefined"||!document.fonts?Promise.resolve():e.then(()=>Dr([...this.fontResources.map(n=>n.family),...this.referencedFontFamilies].map(n=>`16px ${Im(n)}`))).then(()=>{this.render();}).catch(()=>{})}render(){let e=this.root.querySelector(".coco-ppt-editor");e&&(e.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(e){let n=Array.from(this.slideList.querySelectorAll(".coco-ppt-thumb")),r=this.visibleThumbnailRange(e.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=e[i];if(!l)return;let d=ql(l),u=this.thumbnailCanvasCache.get(l.id);(u==null?void 0:u.fingerprint)===d?(a.replaceChildren(rm(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(e){let n=gr*.5625+Pk,r=this.slideList.clientHeight||n*Math.min(e,5),o=Math.max(0,Math.floor(this.slideList.scrollTop/n)-pa),i=Math.ceil(r/n)+pa*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-pa)):o,d=s>=0?Math.max(o+i,Math.min(e,s+pa+1)):o+i;return {start:l,end:Math.min(e,d)}}renderThumbnailSlide(e){let n=document.createElement("div");n.className="coco-ppt-thumb-slide";let o=gr*ha/e.size.width;return n.style.width=`${e.size.width*o}px`,n.style.height=`${e.size.height*o}px`,n.style.transform=`scale(${1/ha})`,n.style.background=Zl(e.background,this.imageResources),n.replaceChildren(...e.nodes.map(i=>this.renderNode(i,o,e,false))),n}async rasterizeThumbnail(e,n){var d,u;let r=this.thumbnailRasterEpoch,o=ql(n);if(await nm(),await nm(),r!==this.thumbnailRasterEpoch||!e.isConnected)return;let i=e.querySelector(".coco-ppt-thumb-preview"),a=i==null?void 0:i.querySelector(".coco-ppt-thumb-slide");if(!i||!a)return;let s=await Hk(a,gr,gr*(n.size.height/n.size.width),Rk,(u=(d=this.root.querySelector("style"))==null?void 0:d.textContent)!=null?u:"",gr*ha,gr*ha*(n.size.height/n.size.width));if(!s||r!==this.thumbnailRasterEpoch||!e.isConnected)return;let l=this.sessionValue.scene().slides.find(f=>f.id===n.id);!l||ql(l)!==o||(this.thumbnailCanvasCache.set(n.id,{fingerprint:o,canvas:s}),i.replaceChildren(rm(s)),e.dataset.previewMode="canvas");}scheduleThumbnailRender(){this.thumbnailFrame||(this.thumbnailFrame=requestAnimationFrame(()=>{this.thumbnailFrame=0,this.renderVisibleThumbnails(this.sessionValue.scene().slides);}));}renderNode(e,n,r,o=true){var h,x,S;let i=document.createElement("div"),a=Mm(e),s=e.presetGeometry==="frame",l=a?Am(e):"horizontal",d=Math.max(a&&l==="vertical"?12:1,e.bounds.width*n),u=Math.max(a&&l==="horizontal"?12:1,e.bounds.height*n);i.className=o?"coco-ppt-node":"coco-ppt-thumb-node",i.dataset.kind=e.kind,i.dataset.locked=String(e.locked),o&&(i.dataset.draggable=String(!this.isReadOnly()&&e.capabilities.editGeometry),i.dataset.resizable=String(!this.isReadOnly()&&e.capabilities.editGeometry),i.dataset.shapeId=e.id),i.style.left=`${e.bounds.left*n-(a&&l==="vertical"?d/2:0)}px`,i.style.top=`${e.bounds.top*n-(a&&l==="horizontal"?u/2:0)}px`,i.style.width=`${d}px`,i.style.height=`${u}px`;let f=[];e.bounds.rotation&&f.push(`rotate(${e.bounds.rotation}deg)`),e.bounds.flipHorizontal&&f.push("scaleX(-1)"),e.bounds.flipVertical&&f.push("scaleY(-1)"),f.length>0&&(i.style.transform=f.join(" "));let p=Wm(e),b=VE(e.presetGeometry),w=!!(b&&e.text&&!e.customGeometry&&!p);if(e.usesBackgroundFill&&e.backgroundFill?WE(i,e.backgroundFill,e,r,n,this.imageResources):e.customGeometry||p||w||e.kind==="table"||a||s?i.style.background="transparent":e.fillGradient&&e.fillGradient.colors.length>1?i.style.background=Er(e.fillGradient,kr(e)):e.fillColor&&(i.style.background=Sr(e.fillColor,kr(e))),SE(e)&&(i.style.overflow="visible"),(e.presetGeometry==="roundRect"||e.presetGeometry==="round1Rect")&&(i.style.borderRadius=`${yr(e)*n}px`),e.presetGeometry==="round2DiagRect"){let k=`${yr(e)*n}px`;i.style.borderRadius=`${k} 0 ${k} 0`;}if(e.presetGeometry==="round2SameRect"){let k=`${yr(e)*n}px`;i.style.borderRadius=`${k} ${k} 0 0`;}if((e.presetGeometry==="ellipse"||Mk(e)||Dk(e))&&(i.style.borderRadius="9999px"),b&&!w&&!p&&(i.style.clipPath=b),s?(i.style.borderStyle="solid",i.style.borderWidth=`${BE(e,n)}px`,e.fillGradient&&e.fillGradient.colors.length>1?(i.style.borderImageSource=Er(e.fillGradient),i.style.borderImageSlice="1"):e.fillColor&&(i.style.borderColor=e.fillColor)):!e.customGeometry&&!p&&!w&&!a&&e.kind!=="picture"&&e.lineColor&&(i.style.borderStyle=td(e.lineDash),i.style.borderWidth=`${Math.max(1,((h=e.lineWidth)!=null?h:9525)*n)}px`,i.style.borderColor=Sr(e.lineColor,e.lineOpacity)),e.shadow&&(i.style.boxShadow=Hm(e.shadow,n)),this.applyTextStyle(i,e,n),pE(i,e,n),w&&b&&i.append(HE(e,n,b)),e.customGeometry&&e.kind!=="picture"&&i.append(nC(e)),p&&i.append(GE(e,n)),a)i.append(sC(e,n));else if(e.kind==="chart")i.append(bC(e));else if(e.kind==="table"){let k=uC(e,n,o);o&&(k.addEventListener("click",I=>{I.stopPropagation(),!this.consumeSuppressedClick()&&(this.notifyTableCellSelection(r,e,I),this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:e.id}));}),k.addEventListener("dblclick",I=>{if(this.isReadOnly())return;let D=im(I);if(!D||!e.capabilities.editTableCells)return;I.stopPropagation();let F=Number(D.dataset.row),A=Number(D.dataset.column);!Number.isInteger(F)||!Number.isInteger(A)||this.startTableCellEdit(D,r,e,F,A);})),i.append(k);}else if(e.kind==="picture"){let k=e.imagePath?this.imageResources[e.imagePath]:void 0,I=k==null?void 0:k.url;if(I&&Ql(k.contentType,e.imagePath)){if(ZE(e,r))i.append(eC(e,I));else {let D=document.createElement("img");D.src=I,D.alt=(x=e.name)!=null?x:"",aE(D,e),e.imageOpacity!==void 0&&(D.style.opacity=String(Math.max(0,Math.min(1,e.imageOpacity)))),i.append(D);}e.lineColor&&i.append(aC(e,n));}else i.dataset.unsupportedImage=e.imagePath?"true":"missing",k!=null&&k.contentType&&(i.dataset.imageContentType=k.contentType),e.imagePath&&(i.dataset.imagePath=e.imagePath),i.append(dE(e,k==null?void 0:k.contentType));}else {let k=(S=e.text)!=null?S:"";if(e.customGeometry||p||w||uE(e)){let I=document.createElement("div");I.className="coco-ppt-text-layer",fE(I,e),cm(I,e,n,k),i.append(I),um(I,e),fm(I,e);}else cm(i,e,n,k),um(i,e),fm(i,e);}if(FE(e)&&i.append(iC(e,n)),!o)return i;let g=document.createElement("div");return g.className="coco-ppt-resize-handle",g.addEventListener("mousedown",k=>{this.isReadOnly()||!e.capabilities.editGeometry||(k.preventDefault(),k.stopPropagation(),this.startDrag(k,"resize",r,e,n,i));}),i.append(g),i.addEventListener("click",k=>{var D,F;if(this.hideContextMenu(),k.stopPropagation(),this.consumeSuppressedClick())return;if(k.altKey){let A=this.selection(),O=Qk(r,k,n,(A==null?void 0:A.kind)==="shape"?A.shapeId:e.id);if(O){this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:O.node.id}),(F=(D=this.options).onObjectAction)==null||F.call(D,{action:"cycle-selection",slideId:r.id,shapeId:O.node.id,kind:O.node.kind,name:O.node.name,reason:`\u5DF2\u5207\u6362\u5230\u91CD\u53E0\u5BF9\u8C61 ${O.index+1}/${O.count}`,candidateIndex:O.index,candidateCount:O.count});return}}let I=this.pointerOperationNode(r,e,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:e.id});}),i.addEventListener("contextmenu",k=>{var D;if(this.isReadOnly())return;k.preventDefault(),k.stopPropagation();let I=(D=this.pointerOperationNode(r,e,k,n))!=null?D:e;this.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:I.id}).then(()=>this.showContextMenu(k,r,I));}),i.addEventListener("mousedown",k=>{var F,A;let I=(F=this.pointerOperationNode(r,e,k,n))!=null?F:e,D=(A=Xl(this.canvas,I.id))!=null?A:i;Zk(D,k.target)||this.isReadOnly()||k.button!==0||!I.capabilities.editGeometry||(k.preventDefault(),k.stopPropagation(),this.startDrag(k,"move",r,I,n,D));}),i.addEventListener("dblclick",k=>{var D,F,A;if(this.isReadOnly())return;k.stopPropagation();let I=lm(r,e,k,n);if(I){this.startTextEdit((D=Xl(this.canvas,I.id))!=null?D:i,r,I);return}if(!e.capabilities.editText){this.sessionValue.dispatch({kind:"select-shape",slideIdOrIndex:r.id,shapeIdOrName:e.id}).then(()=>this.renderSelection()),(A=(F=this.options).onObjectAction)==null||A.call(F,{action:"blocked-text-edit",slideId:r.id,shapeId:e.id,kind:e.kind,name:e.name,reason:nE(e)});return}this.startTextEdit(i,r,e);}),i}pointerOperationNode(e,n,r,o){let i=this.selection();return (i==null?void 0:i.kind)==="shape"&&i.slideId===e.id&&i.shapeId===n.id?n:lm(e,n,r,o)}notifyTableCellSelection(e,n,r){var s,l;let o=im(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:e.id,shapeId:n.id,row:i,column:a,text:wm(o,n,i,a)});}applyTextStyle(e,n,r){var a,s,l,d;let o=n.textStyle;o&&(Jl(e,Jk(n,o),r),o.alignment&&(ed(e,o.alignment),o.alignment==="center"&&(e.style.justifyContent="center"),o.alignment==="right"&&(e.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=hE(n,r);e.style.padding=`${f*r+w}px ${p*r}px ${b*r}px ${u*r}px`,Nm(i)&&(e.style.writingMode="vertical-rl",e.style.textOrientation="upright"),i.anchor==="middle"&&(e.style.alignItems="center"),i.anchor==="bottom"&&(e.style.alignItems="flex-end"),i.anchor==="top"&&(e.style.alignItems="flex-start");}}startTextEdit(e,n,r){var p,b,w,g;if(this.isReadOnly())return;let o=(p=r.text)!=null?p:"",i=Xk(e),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"),e.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,D,F;if(a)return;a=true,i.contentEditable="false",i.removeAttribute("role"),i.removeAttribute("aria-label"),delete e.dataset.editing,delete this.canvas.dataset.interactionMode,i.removeEventListener("blur",f),i.removeEventListener("keydown",d),i.removeEventListener("paste",u);let x=(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=(D=this.options).onTextEditStateChange)==null||F.call(D,{state:"commit",slideId:n.id,shapeId:r.id,text:x}),x!==o?this.dispatch({kind:"set-shape-text",slideIdOrIndex:n.id,shapeIdOrName:r.id,text:x}):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 x=(S=h.clipboardData)==null?void 0:S.getData("text/plain");x!==void 0&&(h.preventDefault(),dm(i,x));},f=()=>l(true);i.addEventListener("blur",f),i.addEventListener("keydown",d),i.addEventListener("paste",u);}startTableCellEdit(e,n,r,o,i){var b,w,g;if(this.isReadOnly())return;let a=wm(e,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}),e.contentEditable="true",e.spellcheck=false,this.canvas.dataset.interactionMode="editing",e.setAttribute("role","textbox"),e.setAttribute("aria-label",`${(g=r.name)!=null?g:"PPT table"} cell ${o+1},${i+1}`),e.textContent=a,e.focus();let l=e.ownerDocument.getSelection();if(l){let h=e.ownerDocument.createRange();h.selectNodeContents(e),h.collapse(false),l.removeAllRanges(),l.addRange(h);}let d=h=>{var S;if(s)return;s=true,e.contentEditable="false",delete this.canvas.dataset.interactionMode,e.removeAttribute("role"),e.removeAttribute("aria-label"),e.removeEventListener("blur",p),e.removeEventListener("keydown",u),e.removeEventListener("paste",f);let x=(S=e.textContent)!=null?S:"";if(!h){e.textContent=a,e.dataset.cellText=a;return}x!==a?(e.dataset.cellText=x,this.dispatch({kind:"set-table-cell-text",slideIdOrIndex:n.id,shapeIdOrName:r.id,row:o,column:i,text:x})):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 x=(S=h.clipboardData)==null?void 0:S.getData("text/plain");x!==void 0&&(h.preventDefault(),dm(e,x));},p=()=>d(true);e.addEventListener("blur",p),e.addEventListener("keydown",u),e.addEventListener("paste",f);}startDrag(e,n,r,o,i,a){this.isReadOnly()||(n==="resize"&&Wk(a,o),this.dragState={mode:n,slideId:r.id,shapeId:o.id,slideSize:r.size,startClientX:e.clientX,startClientY:e.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(e){let n=this.dragState;if(!n)return;if(Math.hypot(e.clientX-n.startClientX,e.clientY-n.startClientY)<=_l){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=(e.clientX-n.startClientX)/n.scale,i=(e.clientY-n.startClientY)/n.scale;if(n.mode==="move"){let{bounds:s}=e.altKey?{bounds:In(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});e.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}=e.altKey?{bounds:In(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});e.altKey&&this.hideSnapGuides(),n.element.style.width=`${a.width*n.scale}px`,n.element.style.height=`${a.height*n.scale}px`;}async finishDrag(e){var s,l;let n=this.dragState;if(!n)return;this.dragState=null;let r=(e.clientX-n.startClientX)/n.scale,o=(e.clientY-n.startClientY)/n.scale,i=Math.hypot(e.clientX-n.startClientX,e.clientY-n.startClientY);if(i<=_l||!n.active){this.hideSnapGuides(),this.clearDragVisualState(n.element);return}this.suppressClickAfterDrag=this.suppressClickAfterDrag||i>_l;let a=e.altKey?In(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(e,n){let r=[...new Set(e.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(e,n){let r=In(e.startBounds,e.slideSize,n),o=this.sessionValue.scene().slides.find(u=>u.id===e.slideId);if(!o)return this.hideSnapGuides(),{bounds:r,guides:[],snapped:false};let i=Math.min(18e4,em/e.scale),a=ga([{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"}],ma(o,e.shapeId,"x"),i),s=ga([{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"}],ma(o,e.shapeId,"y"),i),l=In(e.startBounds,e.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,e.scale),{bounds:l,guides:d,snapped:d.length>0}}snapResizeBounds(e,n){let r=In(e.startBounds,e.slideSize,n),o=this.sessionValue.scene().slides.find(u=>u.id===e.slideId);if(!o)return this.hideSnapGuides(),{bounds:r,guides:[],snapped:false};let i=Math.min(18e4,em/e.scale),a=ga([{offset:r.width/2,value:r.left+r.width/2,role:"center"},{offset:r.width,value:r.left+r.width,role:"end"}],ma(o,e.shapeId,"x"),i,{matchRole:false}),s=ga([{offset:r.height/2,value:r.top+r.height/2,role:"center"},{offset:r.height,value:r.top+r.height,role:"end"}],ma(o,e.shapeId,"y"),i,{matchRole:false}),l=In(e.startBounds,e.slideSize,{width:a?tm(r.left,r.width,a.source,a.target.value):r.width,height:s?tm(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,e.scale),{bounds:l,guides:d,snapped:d.length>0}}renderSnapGuides(e,n){this.clearSnapReferenceHighlights();let r=new Set(e.map(o=>o.referenceShapeId).filter(o=>!!o));for(let o of r){let i=Xl(this.canvas,o);i&&(i.dataset.snapReference="true");}this.snapGuides.replaceChildren(...e.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(e,n=false){delete e.dataset.dragging,(n||!this.dragState)&&delete this.canvas.dataset.interactionMode;}restoreDragElementBounds(e){if(e.mode==="move"){e.element.style.left=`${e.startBounds.left*e.scale}px`,e.element.style.top=`${e.startBounds.top*e.scale}px`;return}e.element.style.width=`${e.startBounds.width*e.scale}px`,e.element.style.height=`${e.startBounds.height*e.scale}px`;}clearSnapReferenceHighlights(){this.canvas.querySelectorAll('.coco-ppt-node[data-snap-reference="true"]').forEach(e=>{delete e.dataset.snapReference;});}handleKeyDown(e){if(e.defaultPrevented||this.dragState||sm(e.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=e.ctrlKey||e.metaKey;if(this.isReadOnly())return;if(i&&e.key.toLowerCase()==="c"){e.preventDefault(),this.copySelectedShape(r,o);return}if(i&&e.key.toLowerCase()==="v"){e.preventDefault(),this.pasteClipboardShape(r,o);return}if(i&&e.key.toLowerCase()==="d"){e.preventDefault(),this.duplicateSelectedShape(r,o);return}if(i&&e.shiftKey&&e.key==="]"){e.preventDefault(),this.bringSelectedShapeToFront(r,o);return}if(i&&e.shiftKey&&e.key==="["){e.preventDefault(),this.sendSelectedShapeToBack(r,o);return}if(e.key==="Delete"||e.key==="Backspace"){if(!jn(o))return;e.preventDefault(),this.deleteSelectedShape(r,o);return}let a=Yk(e.key);if(!a||!o.capabilities.editGeometry)return;let s=Tk*(e.shiftKey?10:1),l=In(o.bounds,r.size,{left:o.bounds.left+a.dx*s,top:o.bounds.top+a.dy*s});e.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}${e.shiftKey?" 10\u6B65":" 1\u6B65"}`});});}handleSelectStart(e){this.isReadOnly()||sm(e.target)||e.target instanceof HTMLElement&&e.target.closest('[contenteditable="true"]')||e.preventDefault();}copySelectedShape(e,n){var r,o;jn(n)&&(this.clipboardShape={slideId:e.id,shapeId:n.id},(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"copy-shape",slideId:e.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u590D\u5236\u5BF9\u8C61"}));}pasteClipboardShape(e,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(e,n){jn(n)&&this.dispatch({kind:"duplicate-shape",slideIdOrIndex:e.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:e.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(e,n){jn(n)&&this.dispatch({kind:"bring-shape-to-front",slideIdOrIndex:e.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"bring-shape-to-front",slideId:e.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7F6E\u4E8E\u9876\u5C42"});});}sendSelectedShapeToBack(e,n){jn(n)&&this.dispatch({kind:"send-shape-to-back",slideIdOrIndex:e.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"send-shape-to-back",slideId:e.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u7F6E\u4E8E\u5E95\u5C42"});});}showContextMenu(e,n,r){if(this.isReadOnly())return;let o=jn(r),i=!!this.clipboardShape,a=u=>()=>{this.hideContextMenu(),u();};this.contextMenu.replaceChildren(br("\u590D\u5236","Ctrl+C",o,a(()=>this.copySelectedShape(n,r))),br("\u7C98\u8D34","Ctrl+V",i,a(()=>this.pasteClipboardShape(n,r))),br("\u91CD\u590D","Ctrl+D",o,a(()=>this.duplicateSelectedShape(n,r))),am(),br("\u7F6E\u4E8E\u9876\u5C42","Ctrl+Shift+]",o,a(()=>this.bringSelectedShapeToFront(n,r))),br("\u7F6E\u4E8E\u5E95\u5C42","Ctrl+Shift+[",o,a(()=>this.sendSelectedShapeToBack(n,r))),am(),br("\u5220\u9664","Del",o,a(()=>this.deleteSelectedShape(n,r))));let s=this.root instanceof ShadowRoot?this.root.host.getBoundingClientRect():this.root.getBoundingClientRect(),l=Sa(e.clientX,s.left+4,window.innerWidth-170),d=Sa(e.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(e,n){jn(n)&&this.dispatch({kind:"delete-shape",slideIdOrIndex:e.id,shapeIdOrName:n.id}).then(()=>{var r,o;(o=(r=this.options).onObjectAction)==null||o.call(r,{action:"delete-shape",slideId:e.id,shapeId:n.id,kind:n.kind,name:n.name,reason:"\u5DF2\u5220\u9664\u5BF9\u8C61"});});}async dispatchCurrentSlideSelection(){if(this.consumeSuppressedClick())return;let e=this.currentSlide();e&&await this.dispatch({kind:"select-slide",slideIdOrIndex:e.id});}consumeSuppressedClick(){return this.suppressClickAfterDrag?(this.suppressClickAfterDrag=false,true):false}dismissContextMenu(e){let n=e.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 e=this.sessionValue.selection();this.slideList.querySelectorAll(".coco-ppt-thumb").forEach((n,r)=>{let o=this.sessionValue.scene().slides[r];n.dataset.selected=(e==null?void 0:e.slideId)===(o==null?void 0:o.id)?"true":"false";}),this.canvas.querySelectorAll(".coco-ppt-node").forEach(n=>{n.dataset.selected=(e==null?void 0:e.kind)==="shape"&&n.dataset.shapeId===e.shapeId?"true":"false";}),this.renderParentGroupSelection(e);}renderParentGroupSelection(e){var d,u;if((e==null?void 0:e.kind)!=="shape")return;let n=this.sessionValue.scene().slides.find(f=>f.id===e.slideId),r=(d=n==null?void 0:n.nodes.find(f=>f.id===e.shapeId))!=null?d:n==null?void 0:n.groups.find(f=>f.id===e.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:Lk(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=e.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 e=this.sessionValue.scene(),n=this.sessionValue.selection();return (n==null?void 0:n.kind)==="slide"||(n==null?void 0:n.kind)==="shape"?(o=(r=e.slides.find(a=>a.id===n.slideId))!=null?r:e.slides[0])!=null?o:null:(i=e.slides[0])!=null?i:null}computeScale(e){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/e.size.width,540/e.size.height,r/e.size.width,o/e.size.height)}};function Wk(t,e){var r,o;if(!Bk(e))return;let n=(o=(r=t.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?r:t.querySelector(".coco-ppt-text-layer"))!=null?o:t;t.dataset.textResizePreview="wrap",n.dataset.textResizePreview="wrap",n.style.transform="",n.style.transformOrigin="",n.style.width="",t.style.whiteSpace="pre-wrap",t.style.overflowWrap="anywhere",t.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(i=>{i.style.whiteSpace="pre-wrap",i.style.overflowWrap="anywhere";});}function Bk(t){var e;return !!(t.capabilities.editGeometry&&Fk(t)&&(t.text||(e=t.textParagraphs)!=null&&e.length))}function Fk(t){return t.kind==="placeholder"||t.kind==="textBox"||t.kind==="geometricShape"}function nm(){return new Promise(t=>requestAnimationFrame(()=>t()))}async function Hk(t,e,n,r,o,i=e,a=n){if(typeof XMLSerializer=="undefined"||typeof Blob=="undefined"||typeof URL=="undefined"||typeof URL.createObjectURL!="function")return null;await Ok(t);let s=document.createElement("canvas");s.width=Math.max(1,Math.round(e*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=t.cloneNode(true);await $k(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 Gk(w);return l.drawImage(g,0,0,s.width,s.height),s}catch(g){return null}finally{URL.revokeObjectURL(w);}}function rm(t){let e=document.createElement("canvas");e.className="coco-ppt-thumb-canvas",e.width=t.width,e.height=t.height;let n=e.getContext("2d");return n&&n.drawImage(t,0,0),e}function ql(t){return JSON.stringify({size:t.size,background:t.background,nodes:t.nodes.map(e=>km(e))})}function km(t){return {id:t.id,kind:t.kind,bounds:t.bounds,text:t.text,textParagraphs:t.textParagraphs,textStyle:t.textStyle,textBody:t.textBody,table:t.table,fillColor:t.fillColor,fillGradient:t.fillGradient,opacity:t.opacity,lineColor:t.lineColor,lineGradient:t.lineGradient,lineOpacity:t.lineOpacity,lineWidth:t.lineWidth,lineDash:t.lineDash,presetGeometry:t.presetGeometry,presetAdjustments:t.presetAdjustments,customGeometry:t.customGeometry,imagePath:t.imagePath,imageCrop:t.imageCrop,imageFillRect:t.imageFillRect,imageOpacity:t.imageOpacity,shadow:t.shadow,threeD:t.threeD,children:t.children.map(e=>km(e))}}async function Ok(t){let e=Array.from(t.querySelectorAll("img"));await Promise.all(e.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 $k(t){let e=Array.from(t.querySelectorAll("img"));await Promise.all(e.map(async n=>{n.alt="";let r=n.getAttribute("src");if(!r||r.startsWith("data:"))return;let o=await zk(r).catch(()=>{});o&&n.setAttribute("src",o);}));}async function zk(t){let e=await fetch(t);if(!e.ok)throw new Error(`Failed to inline thumbnail image: ${e.status}`);let n=await e.blob();return Vk(n)}function Vk(t){return new Promise((e,n)=>{let r=new FileReader;r.onload=()=>{typeof r.result=="string"?e(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(t);})}function Gk(t){return new Promise((e,n)=>{let r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error("Failed to rasterize PPT thumbnail.")),r.src=t;})}function jk(t){return t.filter(Uk).map(n=>{var a,s;let r=oE(n.family),o=(a=n.weight)!=null?a:400,i=(s=n.style)!=null?s:"normal";return `@font-face { font-family: ${r}; src: url(${iE(n.url)}); font-weight: ${o}; font-style: ${i}; }`}).join(`
|
|
1771
|
+
`)}function Uk(t){return /font\/(ttf|otf|woff|woff2)|application\/font-(sfnt|woff|woff2)/i.test(t.contentType)}function Kk(t,e=[]){if(typeof document=="undefined")return Promise.resolve();let n=new Set(t.map(o=>o.family));for(let o of e)n.add(o);let r=[];for(let o of n){let i=rE(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(om(s));continue}let l=document.createElement("link");l.id=a,l.rel="stylesheet",l.href=i,r.push(om(l)),document.head.append(l);}return Promise.all(r).then(()=>{})}function _k(t){let e=new Set,n=o=>{o!=null&&o.trim()&&e.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 t.scene.slides)for(let i of o.nodes)r(i);return [...e]}function qk(t){globalThis.__cocoPptFontRenderReady=t;}function om(t){return t.sheet?Promise.resolve():new Promise(e=>{let n=()=>e();t.addEventListener("load",n,{once:true}),t.addEventListener("error",n,{once:true}),window.setTimeout(n,5e3);})}function Xk(t){var e;return (e=t.querySelector(".coco-ppt-text-layer"))!=null?e:t}function im(t){let e=t.target;return e instanceof HTMLElement?e.closest("td[data-row][data-column]"):null}function br(t,e,n,r){let o=document.createElement("button");o.type="button",o.disabled=!n;let i=document.createElement("strong");i.textContent=t;let a=document.createElement("span");return a.textContent=e,o.append(i,a),o.addEventListener("click",()=>{o.disabled||r();}),o}function am(){return document.createElement("hr")}function Yk(t){return t==="ArrowLeft"?{dx:-1,dy:0,label:"\u5DE6"}:t==="ArrowRight"?{dx:1,dy:0,label:"\u53F3"}:t==="ArrowUp"?{dx:0,dy:-1,label:"\u4E0A"}:t==="ArrowDown"?{dx:0,dy:1,label:"\u4E0B"}:null}function sm(t){if(!(t instanceof HTMLElement))return false;if(t.isContentEditable)return true;let e=t.tagName.toLowerCase();return e==="input"||e==="textarea"||e==="select"}function Zk(t,e){return t.isContentEditable||e instanceof HTMLElement&&e.isContentEditable?true:!!t.querySelector('[contenteditable="true"]')}function Jk(t,e){var s;let n=(s=t.textParagraphs)==null?void 0:s.filter(d=>d.runs.length>0);if(!(n!=null&&n.length)||!Rm(t,n))return e;let l=e,{textGradient:r,textFill:o,textOutlineColor:i}=l;return Wn(l,["textGradient","textFill","textOutlineColor"])}function lm(t,e,n,r){if(e.capabilities.editText||tE(e))return null;let o=Em(n,r);if(!o)return null;let i=t.nodes.findIndex(s=>s.id===e.id),a=t.nodes.slice(0,i<0?t.nodes.length:i);for(let s=a.length-1;s>=0;s--){let l=a[s];if(l.capabilities.editText&&Cm(o.x,o.y,l.bounds))return l}return null}function Qk(t,e,n,r){let o=eE(t,e,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 eE(t,e,n){let r=Em(e,n);if(!r)return [];let o=[];for(let i=t.nodes.length-1;i>=0;i--){let a=t.nodes[i];a.capabilities.select&&Cm(r.x,r.y,a.bounds)&&o.push(a);}return o}function tE(t){return t.kind==="table"||t.kind==="chart"||t.kind==="smartArt"}function Em(t,e){var o;let n=t.currentTarget&&typeof t.currentTarget.parentElement=="object"&&(o=t.currentTarget.parentElement)!=null?o:null,r=n==null?void 0:n.getBoundingClientRect();return r?{x:(t.clientX-r.left)/e,y:(t.clientY-r.top)/e}:null}function Cm(t,e,n){return t>=n.left&&t<=n.left+n.width&&e>=n.top&&e<=n.top+n.height}function Xl(t,e){for(let n of Array.from(t.querySelectorAll(".coco-ppt-node")))if(n.dataset.shapeId===e)return n;return null}function dm(t,e){var a,s;let n=t.ownerDocument.getSelection();if(!n||n.rangeCount===0){t.textContent=`${(a=t.textContent)!=null?a:""}${e}`;return}let r=n.getRangeAt(0);if(!(t===r.commonAncestorContainer||t.contains(r.commonAncestorContainer))){t.textContent=`${(s=t.textContent)!=null?s:""}${e}`;return}r.deleteContents();let i=t.ownerDocument.createTextNode(e);r.insertNode(i),r.setStartAfter(i),r.setEndAfter(i),n.removeAllRanges(),n.addRange(r);}function nE(t){var e;return (e=t.capabilities.reasons)!=null&&e.editText?t.capabilities.reasons.editText:t.capabilities.reason?t.capabilities.reason:t.kind==="table"?"\u8868\u683C\u8BF7\u4F7F\u7528\u5355\u5143\u683C\u7F16\u8F91":t.kind==="picture"?"\u56FE\u7247\u5BF9\u8C61\u4E0D\u652F\u6301\u6587\u5B57\u7F16\u8F91":t.kind==="chart"?"\u56FE\u8868\u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":t.kind==="smartArt"?"SmartArt \u5F53\u524D\u4EC5\u652F\u6301\u9009\u62E9\u548C\u4F4D\u7F6E\u7F16\u8F91":t.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 rE(t){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"}[t]}function Im(t){return qt(t,{families:["Calibri","Microsoft YaHei","Segoe UI"],generic:"sans-serif"})}function oE(t){return `"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function iE(t){return `"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Sr(t,e){var s;if(e===void 0||e>=1)return t;let n=Math.max(0,Math.min(1,e)),r=(s=t.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:s[1];if(!r)return t;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 kr(t){var e;return t.opacity!==void 0?Math.max(0,Math.min(1,t.opacity)):((e=t.threeD)==null?void 0:e.material)==="translucentPowder"?.52:void 0}function aE(t,e){if(e.imageFillRect){lE(t,e);return}sE(t,e);}function sE(t,e){var d,u,f,p;let n=e.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);t.style.position="absolute",t.style.left=`${-r/s*100}%`,t.style.top=`${-i/l*100}%`,t.style.width=`${1/s*100}%`,t.style.height=`${1/l*100}%`;}function lE(t,e){var s,l,d,u;let n=e.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;t.style.position="absolute",t.style.left=`${r*100}%`,t.style.top=`${i*100}%`,t.style.width=`${Math.max(.01,1-r-o)*100}%`,t.style.height=`${Math.max(.01,1-i-a)*100}%`;}function dE(t,e){var o,i;let n=document.createElement("div");n.className="coco-ppt-unsupported-image";let r=(i=(o=t.imagePath)==null?void 0:o.split(".").pop())==null?void 0:i.toUpperCase();return n.textContent=r||cE(e)||"IMAGE",n.title=t.imagePath?`Unsupported image: ${t.imagePath}`:"Missing image resource",n}function cE(t){if(t)return t.includes("emf")?"EMF":t.includes("wmf")?"WMF":t.includes("svg")?"SVG":"IMAGE"}function cm(t,e,n,r){var s,l;let o=(s=e.textParagraphs)==null?void 0:s.filter(d=>d.runs.length>0),i=Nm(e.textBody);if(!(o!=null&&o.length)||!Rm(e,o)){!i&&((l=e.textStyle)==null?void 0:l.alignment)==="distributed"&&Array.from(r).length>1?CE(t,r):t.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&&ed(u,d.style.alignment),NE(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),PE(h,d.style,n,d.text),u.append(h);}d.runs.forEach((h,x)=>{(f?Array.from(h.text):[h.text]).forEach(k=>{let I=document.createElement("span");I.textContent=k;let D=AE(e,d,h,x);D&&Jl(I,D,n),u.append(I);});}),a.append(u);}),t.append(a);}function Nm(t){return (t==null?void 0:t.vertical)==="eastAsian"||(t==null?void 0:t.vertical)==="vertical"}function um(t,e){var n;((n=e.textBody)==null?void 0:n.wrap)==="none"&&Tm(t);}function fm(t,e){var n,r;((n=e.textBody)==null?void 0:n.autoFit)==="normal"&&(!e.text&&!((r=e.textParagraphs)!=null&&r.length)||(wE(e)&&!yE(e)&&Tm(t),requestAnimationFrame(()=>{var p;if(t.dataset.textResizePreview==="wrap")return;let o=t.clientWidth,i=t.clientHeight;if(o<=0||i<=0)return;let a=t.scrollWidth,s=t.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=t.querySelector(".coco-ppt-rich-text, .coco-ppt-distributed-text"))!=null?p:t;f.dataset.textResizePreview!=="wrap"&&(f.style.transformOrigin=vE(e),f.style.transform=`scale(${u})`,f.style.width=`${100/u}%`);})));}function uE(t){var e;return !!((t.text||(e=t.textParagraphs)!=null&&e.length)&&(t.bounds.flipHorizontal||t.bounds.flipVertical))}function fE(t,e){let n=[];e.bounds.flipHorizontal&&n.push("scaleX(-1)"),e.bounds.flipVertical&&n.push("scaleY(-1)"),n.length!==0&&(t.style.transform=n.join(" "),t.style.transformOrigin="center");}function Tm(t){t.style.whiteSpace="nowrap",t.querySelectorAll(".coco-ppt-rich-text, .coco-ppt-paragraph").forEach(e=>{e.style.whiteSpace="nowrap";});}function pE(t,e,n){var o,i,a;if(!gE(e,n))return;let r=((a=(i=(o=e.textStyle)==null?void 0:o.fontSize)!=null?i:Ca(e))!=null?a:28)*12700*n;t.style.letterSpacing=`${Math.max(1,Math.min(2.4,r*.035))}px`;}function hE(t,e){var r,o;if(!mE(t))return 0;let n=(o=(r=t.textStyle)==null?void 0:r.fontSize)!=null?o:Ca(t);return n?n*12700*e*.18:0}function mE(t){var i,a,s,l,d,u,f,p,b;if(t.kind!=="textBox"&&t.kind!=="placeholder"||((i=t.textBody)==null?void 0:i.anchor)!=="top"||t.textBody.wrap!=="square"||t.fillColor||t.fillGradient||t.lineColor||t.lineGradient)return false;let e=(s=(a=t.textStyle)==null?void 0:a.fontFamily)!=null?s:Pm(t);if(!e||!/\bCuprum\b/i.test(e))return false;let n=(d=(l=t.textStyle)==null?void 0:l.fontSize)!=null?d:Ca(t);if(!n||n<72)return false;let r=(u=t.textParagraphs)==null?void 0:u.filter(w=>{var h;return ((h=w.text)!=null?h:w.runs.map(x=>x.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:t.text)!=null?b:"").trim();return o.length>=12&&!/[\u3400-\u9fff]/.test(o)}function gE(t,e){var l,d,u,f,p,b,w,g,h,x,S,k,I,D,F,A,O,ee,le,oe;if(((l=t.textBody)==null?void 0:l.wrap)!=="square"||bE(t)||((b=(d=t.textStyle)==null?void 0:d.alignment)!=null?b:(p=(f=(u=t.textParagraphs)==null?void 0:u[0])==null?void 0:f.style)==null?void 0:p.alignment)!=="center")return false;let r=(g=(w=t.textStyle)==null?void 0:w.fontFamily)!=null?g:Pm(t);if(!r||!/\bJosefin Sans\b/i.test(r))return false;let o=((k=(S=(x=(h=t.textParagraphs)==null?void 0:h[0])==null?void 0:x.text)!=null?S:t.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=(D=(I=t.textStyle)==null?void 0:I.fontSize)!=null?D:Ca(t);if(!i)return false;let a=(oe=(le=(F=t.textStyle)==null?void 0:F.lineHeight)!=null?le:(ee=(O=(A=t.textParagraphs)==null?void 0:A[0])==null?void 0:O.style)==null?void 0:ee.lineHeight)!=null?oe:1.2,s=i*12700*e*a;return t.bounds.height*e>=s*1.75}function bE(t){var e,n;return !!(((e=t.textStyle)==null?void 0:e.characterSpacing)!==void 0||(n=t.textParagraphs)!=null&&n.some(r=>r.runs.some(o=>{var i;return ((i=o.style)==null?void 0:i.characterSpacing)!==void 0})))}function Ca(t){var e,n;for(let r of (e=t.textParagraphs)!=null?e:[])for(let o of r.runs)if(((n=o.style)==null?void 0:n.fontSize)!==void 0)return o.style.fontSize}function Pm(t){var e,n;for(let r of (e=t.textParagraphs)!=null?e:[])for(let o of r.runs)if((n=o.style)!=null&&n.fontFamily)return o.style.fontFamily}function wE(t){var r,o,i,a,s,l;let e=(r=t.textParagraphs)==null?void 0:r.filter(d=>d.runs.length>0);if(e&&e.length!==1||(i=(o=e==null?void 0:e[0])==null?void 0:o.style)!=null&&i.bullet)return false;let n=(l=(s=(a=e==null?void 0:e[0])==null?void 0:a.text)!=null?s:t.text)!=null?l:"";return n.length>0&&!n.includes(`
|
|
1772
|
+
`)&&!n.includes("\r")}function xE(t){var o,i,a,s,l,d,u,f,p,b;if(((o=t.textBody)==null?void 0:o.wrap)!=="square"||((d=(i=t.textStyle)==null?void 0:i.alignment)!=null?d:(l=(s=(a=t.textParagraphs)==null?void 0:a[0])==null?void 0:s.style)==null?void 0:l.alignment)!=="center")return false;let e=((b=(p=(f=(u=t.textParagraphs)==null?void 0:u[0])==null?void 0:f.text)!=null?p:t.text)!=null?b:"").trim();if(!/^[\u3400-\u9fff]{4,6}$/.test(e))return false;let n=Math.min(t.bounds.width,t.bounds.height),r=Math.max(t.bounds.width,t.bounds.height);return n>0&&r<=11e5&&r/n<1.25}function yE(t){var r,o,i,a,s,l,d;if(xE(t))return true;if(((r=t.textBody)==null?void 0:r.wrap)!=="square")return false;let e=((s=(a=(i=(o=t.textParagraphs)==null?void 0:o[0])==null?void 0:i.text)!=null?a:t.text)!=null?s:"").trim();return e.length<18?false:((d=(l=e.match(/[\u3400-\u9fff]/g))==null?void 0:l.length)!=null?d:0)>=12?true:/[\s,。;、,.]/.test(e)}function vE(t){var n,r,o,i,a;let e=(a=(n=t.textStyle)==null?void 0:n.alignment)!=null?a:(i=(o=(r=t.textParagraphs)==null?void 0:r[0])==null?void 0:o.style)==null?void 0:i.alignment;return e==="right"?"right top":e==="center"?"center top":"top left"}function SE(t){var e;return t.kind!=="textBox"||!t.text&&!((e=t.textParagraphs)!=null&&e.length)||t.customGeometry||Wm(t)||Mm(t)?false:!kE(t)&&!EE(t)}function kE(t){var e,n;return (e=t.fillGradient)!=null&&e.colors.length?((n=t.fillGradient.opacities)!=null?n:[]).some(r=>r>0)||!t.fillGradient.opacities:!!(t.fillColor&&t.opacity!==0)}function EE(t){var e,n;return !t.lineColor&&!((e=t.lineGradient)!=null&&e.colors.length)||t.lineOpacity===0?false:((n=t.lineWidth)!=null?n:9525)>0}function CE(t,e){let n=document.createElement("div");n.className="coco-ppt-distributed-text",Array.from(e).forEach(r=>{let o=document.createElement("span");o.textContent=r,n.append(o);}),t.append(n);}function Rm(t,e){return e.some(n=>{var r;return !!((r=n.style)!=null&&r.bullet)||IE(n.style)||n.runs.some(o=>!!o.hyperlink||o.style!==void 0&&ME(o.style,t.textStyle))})}function IE(t){return (t==null?void 0:t.lineHeight)!==void 0||(t==null?void 0:t.marginLeft)!==void 0||(t==null?void 0:t.textIndent)!==void 0||(t==null?void 0:t.spaceBefore)!==void 0||(t==null?void 0:t.spaceAfter)!==void 0}function NE(t,e,n,r={}){if(e){if(e.lineHeight!==void 0&&(t.style.lineHeight=String(TE(e))),e.marginLeft!==void 0&&(t.style.paddingLeft=`${e.marginLeft*n}px`),e.textIndent!==void 0&&(t.style.textIndent=`${e.textIndent*n}px`),r.verticalText){e.spaceBefore!==void 0&&(t.style.marginRight=ba(e.spaceBefore,n)),e.spaceAfter!==void 0&&(t.style.marginLeft=ba(e.spaceAfter,n));return}e.spaceBefore!==void 0&&(t.style.marginTop=ba(e.spaceBefore,n)),e.spaceAfter!==void 0&&(t.style.marginBottom=ba(e.spaceAfter,n));}}function TE(t){var n;let e=(n=t.lineHeight)!=null?n:1.2;return t.bullet?e*1.15:e}function PE(t,e,n,r=""){(e==null?void 0:e.bulletSize)!==void 0&&(e.bulletSize>4?t.style.fontSize=`${e.bulletSize*12700*n}px`:e.bulletSize>0&&(t.style.fontSize=`${e.bulletSize}em`)),RE(e,r)&&(t.style.width="0.5em",t.style.marginRight="0.12em",t.style.transform="scale(0.62)",t.style.transformOrigin="center",t.style.verticalAlign="middle");}function RE(t,e=""){var o,i;if(!t)return false;let n=(i=(o=t.bulletFontFamily)==null?void 0:o.toLowerCase())!=null?i:"",r=Array.from(e.trim()).length;return t.bullet==="\u25A1"&&t.alignment==="center"&&r>0&&r<=4&&(n.includes("wingdings")||n.includes("webdings"))&&t.textIndent!==void 0&&t.textIndent<0&&t.marginLeft!==void 0&&t.marginLeft<=Math.abs(t.textIndent)*1.25}function ba(t,e){return t>10?`${t*e}px`:`${t}em`}function ME(t,e){let n=t,r=e;return t.fontSize!==void 0&&t.fontSize!==(e==null?void 0:e.fontSize)||t.fontFamily!==void 0&&t.fontFamily!==(e==null?void 0:e.fontFamily)||t.color!==void 0&&t.color!==(e==null?void 0:e.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)||t.bold!==void 0&&t.bold!==(e==null?void 0:e.bold)||t.italic!==void 0&&t.italic!==(e==null?void 0:e.italic)||t.underline!==void 0&&t.underline!==(e==null?void 0:e.underline)||t.characterSpacing!==void 0&&t.characterSpacing!==(e==null?void 0:e.characterSpacing)}function AE(t,e,n,r){var i,a,s,l;if(!LE(t,e,n,r))return pm(n,n.style);let o=DE(e.runs.slice(0,r));return pm(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 pm(t,e){if(!t.hyperlink)return e;let n=v({},e!=null?e:{});return n.textFill===void 0&&n.textGradient===void 0&&(n.color="#0563C1"),n.underline===void 0&&(n.underline=true),n}function LE(t,e,n,r){var s,l,d;if(r<=0||(s=n.style)!=null&&s.color&&n.style.fontSize!==void 0||((l=t.textBody)==null?void 0:l.autoFit)!=="shape"||!/[\u3400-\u9fff]/.test(n.text))return false;let o=e.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:e.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 DE(t){var e;for(let n of t)if(((e=n.style)==null?void 0:e.fontSize)!==void 0)return n.style.fontSize}function Jl(t,e,n){var r,o,i;e.fontSize&&(t.style.fontSize=`${Math.max(1,e.fontSize*12700*n)}px`),e.fontFamily&&(t.style.fontFamily=Im(e.fontFamily)),e.lineHeight&&(t.style.lineHeight=String(e.lineHeight)),e.characterSpacing!==void 0&&(t.style.letterSpacing=`${e.characterSpacing*12700*n}px`),e.color&&(t.style.color=e.color),(r=e.textGradient)!=null&&r.colors.length&&e.textGradient.colors.length>1&&(t.style.backgroundImage=Er(e.textGradient),t.style.backgroundClip="text",t.style.setProperty("-webkit-background-clip","text"),t.style.color="transparent",t.style.setProperty("-webkit-text-fill-color","transparent")),e.textFill==="none"&&(t.style.color=(i=(o=e.textOutlineColor)!=null?o:e.color)!=null?i:"transparent",t.style.setProperty("-webkit-text-fill-color","transparent")),e.textOutlineColor&&t.style.setProperty("-webkit-text-stroke",`1px ${e.textOutlineColor}`),e.textShadow&&(t.style.textShadow=Hm(e.textShadow,n)),e.bold!==void 0&&(t.style.fontWeight=e.bold?"700":"400"),e.italic!==void 0&&(t.style.fontStyle=e.italic?"italic":"normal"),e.underline!==void 0&&(t.style.textDecorationLine=e.underline?"underline":"none");}function Ql(t,e){var r;let n=(r=t==null?void 0:t.toLowerCase())!=null?r:"";return n==="image/png"||n==="image/jpeg"||n==="image/jpg"||n==="image/gif"||n==="image/webp"||n==="image/svg+xml"?true:!!(e&&/\.(?:png|jpe?g|gif|webp|svg)$/i.test(e))}function ed(t,e){if(e==="distributed"){t.style.textAlign="justify",t.style.textAlignLast="justify";return}t.style.textAlign=e==="justify"?"justify":e;}function Mm(t){if(t.customGeometry)return false;let e=t.presetGeometry,n=Math.min(t.bounds.width,t.bounds.height),r=Math.max(t.bounds.width,t.bounds.height);return (e==="line"||e==="straightConnector1")&&r>0&&(n===0||n/r<.02)}function Am(t){return t.bounds.height>t.bounds.width?"vertical":"horizontal"}function Zl(t,e={}){var n;if(t!=null&&t.imagePath){let r=e[t.imagePath],o=r==null?void 0:r.url;if(o&&Ql(r.contentType,t.imagePath))return `url("${o}") center / cover no-repeat`}return t!=null&&t.fillGradient&&t.fillGradient.colors.length>1?Er(t.fillGradient):(n=t==null?void 0:t.fillColor)!=null?n:"#fff"}function WE(t,e,n,r,o,i){if(e!=null&&e.imagePath){let a=i[e.imagePath],s=a==null?void 0:a.url;if(s&&Ql(a.contentType,e.imagePath)){t.style.backgroundImage=`url("${s}")`,t.style.backgroundRepeat="no-repeat",t.style.backgroundSize=`${r.size.width*o}px ${r.size.height*o}px`,t.style.backgroundPosition=`${-n.bounds.left*o}px ${-n.bounds.top*o}px`;return}}t.style.background=Zl(e,i);}function yr(t){var r;let e=(r=t.presetAdjustments)==null?void 0:r.adj,n=e===void 0?.08:Math.max(0,Math.min(.5,e/1e5));return Math.min(t.bounds.width,t.bounds.height)*n}function BE(t,e){var o,i,a;let n=(a=(o=t.presetAdjustments)==null?void 0:o.adj)!=null?a:(i=t.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(t.bounds.width,t.bounds.height)*r*e)}function FE(t){return !t.customGeometry&&t.kind!=="line"&&!t.lineColor&&!!t.lineGradient&&t.lineGradient.colors.length>1&&(t.presetGeometry==="roundRect"||t.presetGeometry==="round1Rect"||t.presetGeometry==="ellipse")}function HE(t,e,n){var o;let r=document.createElement("div");return r.className="coco-ppt-css-geometry",r.style.clipPath=n,t.fillGradient&&t.fillGradient.colors.length>1?r.style.background=Er(t.fillGradient,kr(t)):t.fillColor&&(r.style.background=Sr(t.fillColor,kr(t))),t.lineColor&&(r.style.borderStyle=td(t.lineDash),r.style.borderWidth=`${Math.max(1,((o=t.lineWidth)!=null?o:9525)*e)}px`,r.style.borderColor=Sr(t.lineColor,t.lineOpacity)),r}function Er(t,e=1){return `linear-gradient(${Lm(t)}deg, ${$E(t,e).join(", ")})`}function Lm(t){return t.angle===void 0?160:OE(t.angle+90)}function OE(t){return (t%360+360)%360}function $E(t,e=1){return zE(t).map(n=>{let r=Math.max(0,Math.min(1,n.opacity*e)),o=r<1?Dm(n.color,r):n.color;return n.position===void 0?o:`${o} ${n.position}%`})}function zE(t){return t.colors.map((e,n)=>{var a,s,l,d,u;let r=nd(e),o=(a=t.positions)==null?void 0:a[n],i=Math.max(0,Math.min(1,(d=(l=(s=t.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:e,position:o===void 0?void 0:Math.max(0,Math.min(100,o)),opacity:i,index:n}}).sort((e,n)=>e.position===void 0&&n.position===void 0?e.index-n.index:e.position===void 0?1:n.position===void 0?-1:e.position-n.position||e.index-n.index).map(({color:e,position:n,opacity:r})=>({color:e,position:n,opacity:r}))}function Dm(t,e){var a;let n=(a=t.match(/^#([0-9a-fA-F]{6})$/))==null?void 0:a[1];if(!n)return t;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,e))})`}function VE(t){switch(t){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 td(t){return t==="dot"||t==="sysDot"?"dotted":t&&t!=="solid"?"dashed":"solid"}function Ia(t,e){if(!t||t==="solid"||e<=0)return;let n=Math.max(1,e),r=/^cust:(\d+):(\d+)$/i.exec(t);if(r){let o=Number(r[1])/1e5,i=Number(r[2])/1e5;if(o>0&&i>=0)return `${n*o} ${n*i}`}switch(t){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 Wm(t){return t.presetGeometry==="curvedUpArrow"||t.presetGeometry==="donut"||t.presetGeometry==="arc"||t.presetGeometry==="blockArc"||t.presetGeometry==="plaque"||t.presetGeometry==="parallelogram"||t.presetGeometry==="trapezoid"||t.presetGeometry==="snip2DiagRect"||t.presetGeometry==="rtTriangle"||t.presetGeometry==="triangle"||t.presetGeometry==="diamond"||t.presetGeometry==="pentagon"||t.presetGeometry==="hexagon"||t.presetGeometry==="homePlate"||t.presetGeometry==="leftRightArrow"||t.presetGeometry==="chevron"||t.presetGeometry==="rightArrow"||t.presetGeometry==="leftArrow"||t.presetGeometry==="bentArrow"}function GE(t,e){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,t.bounds.width*e),o=Math.max(1,t.bounds.height*e),i=jE(t,e,r,o);(t.shadow||i>0)&&(n.style.overflow="visible"),n.setAttribute("viewBox","0 0 100 100"),n.setAttribute("preserveAspectRatio","none");let a=t.fillGradient&&t.fillGradient.colors.length>1?`coco-ppt-preset-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,s=t.lineGradient&&t.lineGradient.colors.length>1?`coco-ppt-preset-line-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;if(a&&t.fillGradient&&Un(n,a,t.fillGradient),s&&t.lineGradient&&Un(n,s,t.lineGradient),i>0){let g=document.createElementNS("http://www.w3.org/2000/svg","path");g.classList.add("coco-ppt-preset-extrusion"),g.setAttribute("d",hm(t)),(t.presetGeometry==="donut"||t.presetGeometry==="blockArc")&&g.setAttribute("fill-rule","evenodd"),g.setAttribute("fill",UE(t)),g.setAttribute("transform",`translate(${wr(i*.38)} ${wr(i)})`),g.setAttribute("stroke","none"),n.append(g);}let l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",hm(t)),(t.presetGeometry==="donut"||t.presetGeometry==="blockArc")&&l.setAttribute("fill-rule","evenodd");let d=t.lineColor||t.lineGradient?Math.max(.5,((p=t.lineWidth)!=null?p:9525)*e*100/Math.max(r,o)):0;l.setAttribute("fill",t.presetGeometry==="arc"?"none":a?`url(#${a})`:(b=t.fillColor)!=null?b:"none");let u=kr(t);u!==void 0&&t.presetGeometry!=="arc"&&l.setAttribute("fill-opacity",String(u)),l.setAttribute("stroke",s?`url(#${s})`:(w=t.lineColor)!=null?w:"none"),l.setAttribute("stroke-width",String(d)),t.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,t.lineOpacity))));let f=Ia(t.lineDash,d);return f&&l.setAttribute("stroke-dasharray",f),l.setAttribute("stroke-linejoin","round"),t.presetGeometry==="arc"&&(l.setAttribute("stroke-linecap","round"),YE(n,l,t)),n.append(l),n}function jE(t,e,n,r){var a,s;let o=(s=(a=t.threeD)==null?void 0:a.extrusionHeight)!=null?s:0;if(o<=0||t.presetGeometry==="arc")return 0;let i=o*e*100/Math.max(n,r);return Math.max(.8,Math.min(3,i))}function UE(t){var o,i,a,s,l;let e=(a=(i=(o=t.fillGradient)==null?void 0:o.colors[0])!=null?i:t.fillColor)!=null?a:"#64748B",n=nd(e),r=((s=t.threeD)==null?void 0:s.material)==="translucentPowder"?.12:.18;return Dm(KE((l=n==null?void 0:n.color)!=null?l:e,.8),r)}function KE(t,e){let n=/^#?([0-9a-f]{6})$/i.exec(t);if(!n)return t;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 `#${vr(o*e)}${vr(i*e)}${vr(a*e)}`}function hm(t){switch(t.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 _E(t);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 XE(t);default:return ""}}function _E(t){var g,h,x,S,k,I;let e=((h=(g=t.presetAdjustments)==null?void 0:g.adj1)!=null?h:0)/6e4,n=((S=(x=t.presetAdjustments)==null?void 0:x.adj2)!=null?S:54e5)/6e4,r=qE(n-e),o=e+r,i=48,a=Math.max(.08,Math.min(.42,((I=(k=t.presetAdjustments)==null?void 0:k.adj3)!=null?I:25e3)/1e5)),s=i*(1-a),l=Ao(e,i),d=Ao(o,i),u=Ao(o,s),f=Ao(e,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 qE(t){if(!Number.isFinite(t)||t===0)return 90;let e=t%360;return e>330&&(e=330),e<-330&&(e=-330),Math.abs(e)<8&&(e=e<0?-8:8),e}function XE(t){var s,l,d,u,f,p,b,w;let e=mm((l=(s=t.presetAdjustments)==null?void 0:s.adj1)!=null?l:18e6),n=mm((u=(d=t.presetAdjustments)==null?void 0:d.adj2)!=null?u:0),r=((p=(f=t.presetAdjustments)==null?void 0:f.adj1)!=null?p:18e6)/6e4,a=((((w=(b=t.presetAdjustments)==null?void 0:b.adj2)!=null?w:0)/6e4-r)%360+360)%360>180?1:0;return `M ${e.x.toFixed(3)} ${e.y.toFixed(3)} A 48 48 0 ${a} 1 ${n.x.toFixed(3)} ${n.y.toFixed(3)}`}function mm(t){return Ao(t/6e4,48)}function Ao(t,e){let n=t/180*Math.PI;return {x:50+e*Math.cos(n),y:50+e*Math.sin(n)}}function YE(t,e,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),t.append(o),n.lineHeadEnd==="triangle"&&e.setAttribute("marker-start",`url(#${r})`),n.lineTailEnd==="triangle"&&e.setAttribute("marker-end",`url(#${r})`);}function ZE(t,e){if(!t.customGeometry||JE(t.customGeometry))return false;let n=Math.max(0,t.bounds.width)*Math.max(0,t.bounds.height),r=Math.max(1,e.size.width*e.size.height),o=n/r>.85,i=Math.abs(t.bounds.left)<e.size.width*.05&&Math.abs(t.bounds.top)<e.size.height*.05;return !(o&&i)}function JE(t){var s,l;if(t.paths.length!==1)return false;let e=t.paths[0];if(!e)return false;let n=(s=e.width)!=null?s:0,r=(l=e.height)!=null?l:0;if(n<=0||r<=0)return false;let o=[];for(let d of e.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=QE(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=>ka(u.x,d.x)&&ka(u.y,d.y)))}function QE(t){let e=[];for(let n of t)e.some(r=>ka(r.x,n.x)&&ka(r.y,n.y))||e.push(n);return e}function ka(t,e){return Math.abs(t-e)<=1}function eC(t,e){var u,f,p,b,w,g,h,x;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=t.customGeometry)==null?void 0:u.paths[0])==null?void 0:f.width)!=null?p:t.bounds.width),o=Math.max(1,(g=(w=(b=t.customGeometry)==null?void 0:b.paths[0])==null?void 0:w.height)!=null?g:t.bounds.height);n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none");let i=`coco-ppt-picture-clip-${t.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 (x=(h=t.customGeometry)==null?void 0:h.paths)!=null?x:[]){let k=document.createElementNS("http://www.w3.org/2000/svg","path");k.setAttribute("d",Fm(S.commands)),Bm(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",e),l.setAttributeNS("http://www.w3.org/1999/xlink","href",e);let d=tC(t,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})`),t.imageOpacity!==void 0&&l.setAttribute("opacity",String(Math.max(0,Math.min(1,t.imageOpacity)))),n.append(l),n}function tC(t,e,n){var u,f,p,b,w,g,h,x;if(t.imageFillRect){let S=(u=t.imageFillRect.left)!=null?u:0,k=(f=t.imageFillRect.right)!=null?f:0,I=(p=t.imageFillRect.top)!=null?p:0,D=(b=t.imageFillRect.bottom)!=null?b:0;return {x:S*e,y:I*n,width:Math.max(.01,1-S-k)*e,height:Math.max(.01,1-I-D)*n}}let r=t.imageCrop;if(!r)return {x:0,y:0,width:e,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=(x=r.bottom)!=null?x:0,l=Math.max(.01,1-o-i),d=Math.max(.01,1-a-s);return {x:-o/l*e,y:-a/d*n,width:1/l*e,height:1/d*n}}function nC(t,e){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=t.customGeometry)==null?void 0:s.paths[0])==null?void 0:l.width)!=null?d:t.bounds.width,o=(p=(f=(u=t.customGeometry)==null?void 0:u.paths[0])==null?void 0:f.height)!=null?p:t.bounds.height;n.setAttribute("viewBox",`0 0 ${Math.max(1,r)} ${Math.max(1,o)}`),n.setAttribute("preserveAspectRatio","none");let i=t.fillGradient&&t.fillGradient.colors.length>1?`coco-ppt-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0,a=t.lineGradient&&t.lineGradient.colors.length>1?`coco-ppt-custom-line-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;i&&t.fillGradient&&Un(n,i,t.fillGradient),a&&t.lineGradient&&Un(n,a,t.lineGradient);for(let x of (w=(b=t.customGeometry)==null?void 0:b.paths)!=null?w:[]){let S=oC(t,x),k=rC(x),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",Fm(x.commands)),Bm(x.commands)&&I.setAttribute("fill-rule","evenodd"));let D=!(t.kind==="line"&&t.lineDash);I.setAttribute("fill",D?i?`url(#${i})`:(g=t.fillColor)!=null?g:"none":"none");let F=kr(t);D&&F!==void 0&&I.setAttribute("fill-opacity",String(F)),I.setAttribute("stroke",a?`url(#${a})`:(h=t.lineColor)!=null?h:"none"),I.setAttribute("stroke-width",String(S)),t.lineOpacity!==void 0&&I.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,t.lineOpacity))));let A=Ia(t.lineDash,S);A&&I.setAttribute("stroke-dasharray",A),I.setAttribute("stroke-linejoin","round"),I.setAttribute("stroke-linecap","round"),n.append(I);}return n}function rC(t){var u,f,p,b,w,g;let e=t.width,n=t.height;if(!e||!n||e<=0||n<=0)return;let r=t.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=e/2,i=n/2,a=[r[0],r[1],r[2],r[3],r[4]],s=[{x:e,y:i},{x:o,y:n},{x:0,y:i},{x:o,y:0},{x:e,y:i}],l=Math.max(e,n)*.003;return a.every((h,x)=>h.kind!=="moveTo"&&h.kind!=="cubicBezierTo"?false:Math.abs(h.x-s[x].x)<=l&&Math.abs(h.y-s[x].y)<=l)?{cx:o,cy:i,rx:e/2,ry:n/2}:void 0}function Bm(t){return t.filter(e=>e.kind==="moveTo").length>1}function oC(t,e){if(!t.lineWidth)return 0;let n=e.width&&t.bounds.width?e.width/t.bounds.width:void 0,r=e.height&&t.bounds.height?e.height/t.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,t.lineWidth*i)}function iC(t,e){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,t.bounds.width*e),o=Math.max(1,t.bounds.height*e),i=Math.max(1,((u=t.lineWidth)!=null?u:9525)*e),a=i/2,s=`coco-ppt-line-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`;n.setAttribute("viewBox",`0 0 ${r} ${o}`),n.setAttribute("preserveAspectRatio","none"),Un(n,s,t.lineGradient);let l=t.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,yr(t)*e-a))),l.setAttribute("ry",String(Math.max(0,yr(t)*e-a)))),l.setAttribute("fill","none"),l.setAttribute("stroke",`url(#${s})`),l.setAttribute("stroke-width",String(i)),t.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,t.lineOpacity))));let d=Ia(t.lineDash,i);return d&&l.setAttribute("stroke-dasharray",d),n.append(l),n}function aC(t,e){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,t.bounds.width*e),o=Math.max(1,t.bounds.height*e),i=Math.max(1,((u=t.lineWidth)!=null?u:9525)*e),a=t.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=t.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=t.presetGeometry==="roundRect"||t.presetGeometry==="round1Rect"?Math.max(0,yr(t)*e-s):0;l.setAttribute("rx",String(p)),l.setAttribute("ry",String(p));}l.setAttribute("fill","none"),l.setAttribute("stroke",(f=t.lineColor)!=null?f:"none"),l.setAttribute("stroke-width",String(i)),t.lineOpacity!==void 0&&l.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,t.lineOpacity))));let d=Ia(t.lineDash,i);return d&&l.setAttribute("stroke-dasharray",d),n.append(l),n}function sC(t,e){var w,g;let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.classList.add("coco-ppt-line-geometry");let r=Am(t)==="vertical",o=Math.max(r?12:1,t.bounds.width*e),i=Math.max(r?1:12,t.bounds.height*e);n.setAttribute("viewBox",`0 0 ${o} ${i}`),n.setAttribute("preserveAspectRatio","none");let a=Math.max(1,((w=t.lineWidth)!=null?w:9525)*e),s=t.lineGradient&&t.lineGradient.colors.length>1?`coco-ppt-connector-gradient-${t.id.replace(/[^a-zA-Z0-9_-]/g,"_")}`:void 0;s&&t.lineGradient&&Un(n,s,t.lineGradient);let l=s?`url(#${s})`:Sr((g=t.lineColor)!=null?g:"#000000",t.lineOpacity),d=lC(a),u=Math.max(5,a*3.2),f=Math.max(5,a*2.6),p=gm(t.lineHeadEnd),b=gm(t.lineTailEnd);if(r){let h=o/2,x=p?Math.min(i,u):0,S=b?Math.max(0,i-u):i;Cr(n,h,x,h,S,l,a,t.lineOpacity,t.lineCap),t.lineHeadEnd==="oval"&&Nn(n,h,0,d,l),t.lineTailEnd==="oval"&&Nn(n,h,i,d,l),p&&ya(n,h,0,"up",u,f,l,t.lineOpacity),b&&ya(n,h,i,"down",u,f,l,t.lineOpacity);}else {let h=i/2,x=p?Math.min(o,u):0,S=b?Math.max(0,o-u):o;Cr(n,x,h,S,h,l,a,t.lineOpacity,t.lineCap),t.lineHeadEnd==="oval"&&Nn(n,0,h,d,l),t.lineTailEnd==="oval"&&Nn(n,o,h,d,l),p&&ya(n,0,h,"left",u,f,l,t.lineOpacity),b&&ya(n,o,h,"right",u,f,l,t.lineOpacity);}return n}function lC(t){return Math.max(3,t*3)}function gm(t){return t==="arrow"||t==="triangle"}function Fm(t){let e=[],n;for(let r of t)if(r.kind==="moveTo")e.push(`M ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="lineTo")e.push(`L ${r.x} ${r.y}`),n={x:r.x,y:r.y};else if(r.kind==="cubicBezierTo")e.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=dC(r,n);o&&(e.push(o.path),n=o.end);}else e.push("Z");return e.join(" ")}function dC(t,e){if(!e||t.wR<=0||t.hR<=0||t.swAng===0)return;let n=t.stAng/6e4,r=t.swAng/6e4,o=n+r,i=bm(t.wR,t.hR,n),a={x:e.x-i.x,y:e.y-i.y},s=bm(t.wR,t.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 ${wr(t.wR)} ${wr(t.hR)} 0 ${d} ${u} ${wr(l.x)} ${wr(l.y)}`,end:l}}function bm(t,e,n){let r=n/180*Math.PI;return {x:t*Math.cos(r),y:e*Math.sin(r)}}function wr(t){return Number.isInteger(t)?String(t):t.toFixed(3).replace(/\.?0+$/,"")}function Un(t,e,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}:cC(Lm(n));s.setAttribute("id",e),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,x;let f=(w=i==null?void 0:i[u])!=null?w:u/Math.max(1,o.length-1)*100,p=nd(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:(x=p==null?void 0:p.color)!=null?x: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),t.append(r);}function cC(t){let e=t*Math.PI/180,n=Math.sin(e),r=-Math.cos(e),o=50/Math.max(Math.abs(n),Math.abs(r),1e-4);return {x1:wa(50-n*o),y1:wa(50-r*o),x2:wa(50+n*o),y2:wa(50+r*o)}}function wa(t){return Math.round(Math.max(0,Math.min(100,t))*1e3)/1e3}function nd(t){let e=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*([0-9.]+)\s*)?\)$/i.exec(t);if(!e)return;let n=Math.max(0,Math.min(255,Number(e[1]))),r=Math.max(0,Math.min(255,Number(e[2]))),o=Math.max(0,Math.min(255,Number(e[3]))),i=e[4]===void 0?1:Math.max(0,Math.min(1,Number(e[4])));return {color:`#${vr(n)}${vr(r)}${vr(o)}`,opacity:i}}function vr(t){return Math.round(t).toString(16).padStart(2,"0").toUpperCase()}function uC(t,e,n=true){var d,u,f,p,b,w,g,h,x,S,k,I,D,F,A;let r=document.createElement("table");r.className="coco-ppt-table";let o=t.table;if(!o)return r;let i=Math.max(o.rowCount,o.values.length),a=Math.max(o.columnCount,...o.values.map(O=>O.length),1),s=(u=(d=o.columnWidths)==null?void 0:d.reduce((O,ee)=>O+ee,0))!=null?u:0;if(s>0){let O=document.createElement("colgroup");for(let ee=0;ee<a;ee++){let le=document.createElement("col"),oe=(f=o.columnWidths)==null?void 0:f[ee];oe&&(le.style.width=`${oe/s*100}%`),O.append(le);}r.append(O);}let l=(b=(p=o.rowHeights)==null?void 0:p.reduce((O,ee)=>O+ee,0))!=null?b:0;for(let O=0;O<i;O++){let ee=document.createElement("tr"),le=(w=o.rowHeights)==null?void 0:w[O];ee.style.height=l>0&&le?`${le/l*100}%`:`${100/i}%`;for(let oe=0;oe<a;oe++){let ie=gC(o,O,oe);if(ie!=null&&ie.hMerge||ie!=null&&ie.vMerge)continue;let ae=document.createElement("td"),_=(h=(g=o.cellStyles)==null?void 0:g[O])==null?void 0:h[oe];n&&(ae.dataset.row=String(O),ae.dataset.column=String(oe));let Y=(S=(x=o.values[O])==null?void 0:x[oe])!=null?S:"";if(ae.dataset.cellText=Y,pC(ae,Y),ie!=null&&ie.columnSpan&&ie.columnSpan>1&&(ae.colSpan=ie.columnSpan),ie!=null&&ie.rowSpan&&ie.rowSpan>1&&(ae.rowSpan=ie.rowSpan),_!=null&&_.fillGradient&&_.fillGradient.colors.length>1?ae.style.background=Er(_.fillGradient):_!=null&&_.fillColor&&!hC(_.fillColor)&&(ae.style.background=_.fillColor),_!=null&&_.body){let B=_.body,U=(k=B.insetLeft)!=null?k:91440,z=(I=B.insetTop)!=null?I:45720,G=(D=B.insetRight)!=null?D:91440,K=(F=B.insetBottom)!=null?F:45720;ae.style.padding=`${z*e}px ${G*e}px ${K*e}px ${U*e}px`,B.anchor==="middle"&&(ae.style.verticalAlign="middle"),B.anchor==="bottom"&&(ae.style.verticalAlign="bottom"),B.anchor==="top"&&(ae.style.verticalAlign="top");}_!=null&&_.textStyle&&Jl(ae,_.textStyle,e),(A=_==null?void 0:_.textStyle)!=null&&A.alignment&&ed(ae,_.textStyle.alignment),fC(ae,_,e),ee.append(ae);}r.append(ee);}return r}function fC(t,e,n){let r=e==null?void 0:e.borders;r&&(xa(t,"Left",r.left,n),xa(t,"Right",r.right,n),xa(t,"Top",r.top,n),xa(t,"Bottom",r.bottom,n));}function xa(t,e,n,r){var s,l;if(!n)return;let o=`border${e}Style`,i=`border${e}Width`,a=`border${e}Color`;if(n.hidden){t.style[o]="none",t.style[i]="0";return}t.style[o]=td(n.dash),t.style[i]=`${Math.max(1,((s=n.width)!=null?s:9525)*r)}px`,t.style[a]=Sr((l=n.color)!=null?l:"#94A3B8",n.opacity);}function pC(t,e){let n=e.split(/\r?\n/);if(n.length<=1){t.textContent=e;return}n.forEach((r,o)=>{o>0&&t.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"),t.append(i);});}function wm(t,e,n,r){var o,i,a,s,l;return (l=(s=(a=t.dataset.cellText)!=null?a:(i=(o=e.table)==null?void 0:o.values[n])==null?void 0:i[r])!=null?s:t.textContent)!=null?l:""}function hC(t){let e=/^#?([0-9a-f]{6})$/i.exec(t);if(!e)return false;let n=e[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 Hm(t,e){var s,l,d;let n=((s=t.distance)!=null?s:0)*e,r=((l=t.direction)!=null?l:0)*Math.PI/180,o=Math.cos(r)*n,i=Math.sin(r)*n,a=((d=t.blur)!=null?d:0)*e;return `${o}px ${i}px ${a}px ${mC(t)}`}function mC(t){var l,d;let e=(l=t.color)!=null?l:"#000000",n=(d=t.opacity)!=null?d:.25,r=/^#?([0-9a-f]{6})$/i.exec(e);if(!r)return e;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 gC(t,e,n){var r;return (r=t.mergedCells)==null?void 0:r.find(o=>o.row===e&&o.column===n)}function bC(t){var h,x,S,k,I,D,F,A,O,ee,le,oe,ie,ae,_,Y;let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 100 60"),e.setAttribute("width","100%"),e.setAttribute("height","100%"),e.setAttribute("preserveAspectRatio","none");let n=(h=t.chart)==null?void 0:h.data;if(!(n!=null&&n.series.length))return St(e,(x=t.name)!=null?x:"Chart",4,8,4,"#17202a"),e;let r=(k=(S=t.chart)==null?void 0:S.type)!=null?k:"",o=(I=t.chart)==null?void 0:I.grouping,i=wC(n.series,r,o),a=Math.max(...i,1),s=Math.min(...i,0),l=(F=(D=t.chart)==null?void 0:D.axes)==null?void 0:F.value,d=(O=(A=t.chart)==null?void 0:A.axes)==null?void 0:O.category,u=(ee=l==null?void 0:l.min)!=null?ee:s>=0?0:s,f=(le=l==null?void 0:l.max)!=null?le:s>=0?vC(a):a,p=xC(t),b=SC(u,f,l==null?void 0:l.majorUnit);if(r.includes("doughnut")||r.includes("pie"))return DC(e,n.series,p),e;if(r.includes("radar"))return HC(e,n.series,p,(oe=l==null?void 0:l.max)!=null?oe:a),e;(l==null?void 0:l.majorGridlines)!==false&&CC(e,p,b,t,l,d),(l==null?void 0:l.deleted)!==true&&(l==null?void 0:l.tickLabelPosition)!=="none"&&IC(e,p,u,f,b),kC(e,t,p);let w=n.series.filter(B=>{var U,z,G;return ((G=(z=B.type)!=null?z:(U=t.chart)==null?void 0:U.type)!=null?G:"").includes("bar")}),g=n.series.filter(B=>{var U;return ((U=B.type)!=null?U:"").includes("line")});return w.length>0?(PC(e,w,p,u,f,t,o),vm(e,(ae=(ie=w[0])==null?void 0:ie.categories)!=null?ae:[],p),w.some(B=>B.showValueLabels)&&LC(e,w,p,u,f),g.length>0&&xm(e,g,p,u,f,void 0,t),g.some(B=>B.showValueLabels)&&Sm(e,g,p,u,f)):(xm(e,n.series,p,u,f,["#22C7F2","#22C7F2","#94A3B8","#F59E0B"],t),vm(e,(Y=(_=n.series.find(B=>{var U;return (U=B.categories)==null?void 0:U.length}))==null?void 0:_.categories)!=null?Y:[],p),n.series.some(B=>B.showValueLabels)&&Sm(e,n.series,p,u,f)),e}function wC(t,e,n){var a;let r=t.filter(s=>{var l;return ((l=s.type)!=null?l:e).includes("bar")});if(!$m(n)||r.length<=1)return t.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 xC(t){var u,f,p,b,w,g,h,x,S,k,I,D,F,A,O,ee;let e=(u=t.chart)==null?void 0:u.plotLayout,n=(p=(f=t.chart)==null?void 0:f.type)!=null?p:"";if(!e)return zm((g=(w=(b=t.chart)==null?void 0:b.data)==null?void 0:w.series)!=null?g:[])?{left:7,top:8,width:88,height:40}:yC(t)?{left:18,top:8,width:72,height:40}:((S=(x=(h=t.chart)==null?void 0:h.axes)==null?void 0:x.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=((D=(I=(k=t.chart)==null?void 0:k.axes)==null?void 0:I.value)==null?void 0:D.deleted)!==true&&!n.includes("doughnut")&&!n.includes("pie")&&!n.includes("radar")?14:4,i=((F=e.x)!=null?F:.12)*100,a=((A=e.y)!=null?A:.13)*60,s=((O=e.width)!=null?O:.82)*100,l=((ee=e.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 yC(t){var i,a,s,l,d,u,f,p;let e=t.chart,n=(i=e==null?void 0:e.type)!=null?i:"";if(!e||!n.includes("bar")||e.plotLayout)return false;let r=(s=(a=e.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 vC(t){if(t<=0)return 1;if(t<=10)return Math.max(1,Math.ceil(t));let e=t*1.1,n=10**Math.floor(Math.log10(e));return Math.ceil(e/n)*n}function SC(t,e,n){let r=Math.abs(e-t);return n&&n>0?Math.max(1,Math.min(8,Math.round(r/n))):Number.isInteger(r)&&r>0&&r<=6?r:4}function kC(t,e,n){var d,u,f,p,b,w,g;let r=(p=(d=e.chart)==null?void 0:d.title)!=null?p:(f=(u=e.chart)==null?void 0:u.data)==null?void 0:f.title;r&&St(t,r,n.left+n.width*.5,Math.max(4,n.top-3.2),3.1,"#17202A","middle");let o=(g=(w=(b=e.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,x)=>{var I,D,F,A,O,ee;let S=(I=o.find(le=>le.name===h))!=null?I:o[x],k=S?EC(t,S,x,a):a[x];S&&((D=S.type)!=null?D:"").includes("line")?(Cr(t,s,l-1.1,s+2.3,l-1.1,k,.45),Nn(t,s+1.15,l-1.1,.45,(A=(F=S.marker)==null?void 0:F.fillColor)!=null?A:"#FFFFFF",(ee=(O=S.marker)==null?void 0:O.lineColor)!=null?ee:k,.32),St(t,h,s+2.8,l-.45,2.2,"#64748B")):(Do(t,s,l-1.8,1.4,1.4,k),St(t,h,s+2,l-.45,2.2,"#64748B")),s+=Math.max(9,Array.from(h).length*2.2+4.5);});}function EC(t,e,n,r){var o,i;return ((o=e.type)!=null?o:"").includes("line")?(i=e.lineColor)!=null?i:r[n]:Na(t,e,n,r)}function CC(t,e,n,r,o,i){var l,d;let a=(l=o==null?void 0:o.gridlineColor)!=null?l:"#E8EDF3",s=ym(o==null?void 0:o.gridlineWidth,r,.35);for(let u=0;u<=n;u++){let f=e.top+e.height/n*u;Cr(t,e.left,f,e.left+e.width,f,a,s);}Cr(t,e.left,e.top+e.height,e.left+e.width,e.top+e.height,(d=i==null?void 0:i.lineColor)!=null?d:"#CBD5E1",ym(i==null?void 0:i.lineWidth,r,.45));}function IC(t,e,n,r,o){for(let i=0;i<=o;i++){let a=r-(r-n)/o*i,s=e.top+e.height/o*i+1;St(t,rd(a),e.left-1.8,s,3,"#9AA6B2","end");}}function rd(t){return Number.isInteger(t)?String(t):t.toFixed(1).replace(/\.0$/,"")}function xm(t,e,n,r,o,i=["#CBD5E1","#94A3B8","#F59E0B","#A3E635"],a){e.forEach((s,l)=>{var p,b,w,g,h,x,S;if(s.values.length===0)return;let d=s.values.map((k,I)=>{let D=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:D,y:F}}),u=TC(d,s.smooth===true),f=(p=s.lineColor)!=null?p:i[l%i.length];if(jm(t,u,f,Om(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=(x=(h=s.marker)==null?void 0:h.fillColor)!=null?x:f,D=(S=s.marker)==null?void 0:S.lineColor,F=NC(s,a);d.forEach(A=>Nn(t,A.x,A.y,k,I,D,F));}});}function NC(t,e){var n;if(!(!((n=t.marker)!=null&&n.lineWidth)||!(e!=null&&e.bounds.width)))return Math.max(.25,Math.min(1,t.marker.lineWidth/e.bounds.width*100))}function Om(t,e){return !t.lineWidth||!(e!=null&&e.bounds.width)?.8:Math.max(.3,Math.min(1.2,t.lineWidth/e.bounds.width*100))}function TC(t,e){if(t.length===0)return "";if(!e||t.length<3)return t.map((r,o)=>`${o===0?"M":"L"} ${r.x} ${r.y}`).join(" ");let n=[`M ${t[0].x} ${t[0].y}`];for(let r=0;r<t.length-1;r++){let o=t[Math.max(0,r-1)],i=t[r],a=t[r+1],s=t[Math.min(t.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 PC(t,e,n,r,o,i,a){if($m(a)&&e.length>1){MC(t,e,n,r,o,i);return}if(zm(e)){RC(t,e,n,r,o,i);return}let s=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],l=Math.max(...e.map(f=>f.values.length),1),d=n.width/l,u=Math.max(1,d*.48/Math.max(e.length,1));e.forEach((f,p)=>{let b=Na(t,f,p,s);f.values.forEach((w,g)=>{var k,I;let h=(w-r)/Math.max(1,o-r)*n.height,x=n.left+g*d+(d-u*e.length)/2+p*u,S=n.top+n.height-h;Do(t,x,S,u,h,(I=(k=f.pointColors)==null?void 0:k[g])!=null?I:b,f.borderColor,od(f,i));});});}function RC(t,e,n,r,o,i){let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=Math.max(...e.map(u=>u.values.length),1),l=n.width/s,d=Math.max(1,l*.34);e.forEach((u,f)=>{let p=Na(t,u,f,a);u.values.forEach((b,w)=>{var S,k;let g=Ea(b,n,r,o),h=Ea(0,n,r,o),x=n.left+w*l+(l-d)/2;Do(t,x,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,od(u,i));});});}function MC(t,e,n,r,o,i){let a=["#C50D13","#0EA5E9","#F59E0B","#A3E635"],s=Math.max(...e.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));e.forEach((p,b)=>{let w=Na(t,p,b,a);p.values.forEach((g,h)=>{var F,A;let x=g>=0?u[h]:f[h],S=x+g,k=Ea(x,n,r,o),I=Ea(S,n,r,o),D=n.left+h*l+(l-d)/2;Do(t,D,Math.min(k,I),d,Math.max(.1,Math.abs(I-k)),(A=(F=p.pointColors)==null?void 0:F[h])!=null?A:w,p.borderColor,od(p,i)),g>=0?u[h]=S:f[h]=S;});});}function Ea(t,e,n,r){return e.top+e.height-(t-n)/Math.max(1,r-n)*e.height}function $m(t){return t==="stacked"||t==="percentStacked"}function zm(t){return new Set(t.map(n=>{var r;return (r=n.chartGroup)!=null?r:0})).size>1&&t.every(n=>!n.type||n.type.includes("bar"))}function od(t,e){if(t.borderWidth)return Vm(e!=null&&e.bounds.width?t.borderWidth/e.bounds.width*100:void 0,void 0)}function ym(t,e,n){var r;return (r=Vm(t!==void 0&&e.bounds.width?t/e.bounds.width*100:void 0,n))!=null?r:n}function Vm(t,e){return t===void 0?e:Math.max(.15,Math.min(1.4,t))}function Na(t,e,n,r){var o,i;if((o=e.fillGradient)!=null&&o.colors.length&&e.fillGradient.colors.length>1){let a=`coco-chart-gradient-${n}-${e.fillGradient.colors.join("-").replace(/[^a-zA-Z0-9_-]/g,"_")}`;return Un(t,a,e.fillGradient),`url(#${a})`}return (i=e.fillColor)!=null?i:r[n%r.length]}function AC(t,e,n){var r,o,i;return (i=(o=(r=t.pointColors)==null?void 0:r[e])!=null?o:t.fillColor)!=null?i:n[e%n.length]}function vm(t,e,n){if(e.length===0)return;let r=n.width/e.length;e.forEach((o,i)=>{St(t,o,n.left+r*i+r/2,n.top+n.height+5.2,3.2,"#64748B","middle");});}function LC(t,e,n,r,o){let i=Math.max(...e.map(l=>l.values.length),1),a=n.width/i,s=Math.max(1,a*.48/Math.max(e.length,1));e.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*e.length)/2+d*s+s/2,w=n.top+n.height-p-2;St(t,String(u),b,w,3,"#A7AEB8","middle");});});}function Sm(t,e,n,r,o){e.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(t,String(a),l,Math.max(n.top+2,d-2.2),2.6,"#374151","middle");});});}function DC(t,e,n){var b;let r=e[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,x=u,S=u+h;if(OC(t,a,s,l,d,x,S,AC(r,g,o)),r.showCategoryNameLabels||r.showPercentLabels||r.showValueLabels){let k=WC(r,w,g,i);if(k.length>0){let I=BC(r,g,a,s,l+3.6,n,(x+S)/2);GC(t,k,I.x,I.y,1.9,"#334155",I.x>=a?"start":"end");}}u+=h;}),Nn(t,a,s,d*.92,"#FFFFFF");let f=FC(r.name);f&&St(t,f,a,s-1.8,1.8,"#64748B","middle");let p=r.values[0];p!==void 0&&St(t,Gm(p,i),a,s+3.4,3.9,"#1E3A8A","middle"),$C(t,(b=r.categories)!=null?b:[],o,n.left+n.width*.72,n.top+9);}function WC(t,e,n,r){var a;let o=[],i=(a=t.categories)==null?void 0:a[n];return t.showCategoryNameLabels&&i&&o.push(i),t.showValueLabels&&o.push(rd(e)),t.showPercentLabels&&o.push(Gm(e,r)),o}function BC(t,e,n,r,o,i,a){return xr(n,r,o,a)}function Gm(t,e){let r=(t>0&&t<=1&&e<=2?t:t/Math.max(1,e))*100;return `${Number.isInteger(r)?r.toFixed(0):r.toFixed(1)}%`}function FC(t){let e=(t!=null?t:"").trim();if(!e)return "";let n=Array.from(e);return n.length<=6?e:`${n.slice(0,5).join("")}\u2026`}function HC(t,e,n,r){var d;let o=e[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++)jm(t,zC(i,a,s,l*u/4),"#CBD5E1",.25);for(let u=0;u<i;u++){let f=va(u,i,a,s,l);Cr(t,a,s,f.x,f.y,"#E2E8F0",.25);}e.forEach((u,f)=>{var w;if(!u.values.length)return;let p=u.values.slice(0,i).map((g,h)=>va(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(Om(u,void 0))),t.append(b),u.marker&&u.marker.symbol!=="none"&&p.forEach(g=>{var h;return Nn(t,g.x,g.y,.9,(h=u.lineColor)!=null?h:"#2563EB")}),u.showValueLabels&&u.values.slice(0,i).forEach((g,h)=>{var S;let x=p[h];St(t,rd(g),x.x,x.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=va(f,i,a,s,l+5);St(t,u,p.x,p.y+1,2.6,"#64748B","middle");});}function OC(t,e,n,r,o,i,a,s){let d=Math.max(.01,a-i)>180?1:0,u=xr(e,n,r,i),f=xr(e,n,r,a),p=xr(e,n,o,a),b=xr(e,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),t.append(w);}function $C(t,e,n,r,o){e.slice(0,6).forEach((i,a)=>{Do(t,r,o+a*5,2.4,2.4,n[a%n.length]),St(t,i,r+3.6,o+a*5+2.2,2.7,"#334155");});}function zC(t,e,n,r,o){return Array.from({length:t},(i,a)=>{let s=va(a,t,e,n,r);return `${a===0?"M":"L"} ${s.x} ${s.y}`}).join(" ")+(" Z")}function va(t,e,n,r,o){return xr(n,r,o,-90+360*t/e)}function xr(t,e,n,r){let o=r*Math.PI/180;return {x:t+Math.cos(o)*n,y:e+Math.sin(o)*n}}function Cr(t,e,n,r,o,i,a,s,l){let d=document.createElementNS("http://www.w3.org/2000/svg","line");d.setAttribute("x1",String(e)),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",VC(l)),s!==void 0&&d.setAttribute("stroke-opacity",String(Math.max(0,Math.min(1,s)))),t.append(d);}function VC(t){return t==="rnd"?"round":t==="sq"?"square":"butt"}function jm(t,e,n,r){let o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",e),o.setAttribute("fill","none"),o.setAttribute("stroke",n),o.setAttribute("stroke-width",String(r)),o.setAttribute("stroke-linejoin","round"),o.setAttribute("stroke-linecap","round"),t.append(o);}function Nn(t,e,n,r,o,i,a){let s=document.createElementNS("http://www.w3.org/2000/svg","circle");s.setAttribute("cx",String(e)),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)),t.append(s);}function ya(t,e,n,r,o,i,a,s){let l=i/2,d=r==="right"?[[e,n],[e-o,n-l],[e-o,n+l]]:r==="left"?[[e,n],[e+o,n-l],[e+o,n+l]]:r==="down"?[[e,n],[e-l,n-o],[e+l,n-o]]:[[e,n],[e-l,n+o],[e+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)))),t.append(u);}function Do(t,e,n,r,o,i,a,s){let l=document.createElementNS("http://www.w3.org/2000/svg","rect");l.setAttribute("x",String(e)),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))),t.append(l);}function St(t,e,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=e,t.append(s);}function GC(t,e,n,r,o,i,a="start"){e.forEach((s,l)=>{St(t,s,n,r+l*o*1.2,o,i,a);});}
|
|
1773
|
+
export{ok as DEFAULT_PPT_SLIDE_SIZE,hn as EditorReadOnlyError,Ti as NATIVE_BLOCK_CLIPBOARD_TYPE,fa as PptEditorSession,ur as SPREADSHEET_CLIPBOARD_MIME,wP as SPREADSHEET_COLUMN_RESIZE_MIN,yP as SPREADSHEET_RESIZE_HIT_TOLERANCE,xP as SPREADSHEET_ROW_RESIZE_MIN,Qi as SpreadsheetCanvasRenderer,oa as SpreadsheetCellEditor,ra as SpreadsheetEditorRuntime,ji as SpreadsheetLayout,_i as SpreadsheetViewportManager,Yc as adjacentNativeListNumbering,_e as allNativeParagraphs,ws as analyzeNativeTableRowPagination,VI as applyNativeWordChangesToPackage,uP as applySpreadsheetAgentAction,kh as applyWheelDelta,Ay as applyWordOoxmlPatches,Nf as bodyParagraphs,bR as buildPptEditorViewFromModel,gR as buildPptEditorViewFromPptx,Yh as buildPptEditorViewFromPresentation,Po as buildPptPresentationScene,Ro as buildPptSceneNode,ik as buildPptSlideScene,Zp as buildSpreadsheetAutoFillPlan,na as buildSpreadsheetClipboardPayload,oh as buildSpreadsheetReplacePlan,go as buildSpreadsheetSheetRenderModel,QC as buildWordEditorView,ZC as buildWordEditorViewFromDocx,JC as buildWordEditorViewFromFlatOpc,rs as buildWordEditorViewFromPackage,Dt as canDispatchNativeWordCommand,FS as clampScroll,Pt as clearNativeImageSelection,HT as clearSpreadsheetRange,Tl as clipboardHtml,Eo as clipboardToken,rt as cloneNativeWordBlocks,rI as collectNativeParagraphs,Qn as colorToCss,Eh as computeScrollbarState,Y0 as copybookGuideAppearance,mT as createColumnRangeSelection,ta as createColumnSelection,xs as createNativeListNumbering,Fn as createNativeParaId,Ks as createNativeSelectionRange,kf as createNativeTextRange,hs as createNativeWordDocument,hT as createRowRangeSelection,ea as createRowSelection,it as createSelection,sN as createWordEditingPlugin,Ki as cssPixelsToExcelColumnWidth,pt as currentNativeCursor,ze as currentNativeSelection,$u as defineNativeWordElements,WS as excelColumnWidthToCssPixels,XS as expandRangeForMergedRanges,ct as expandSelectionForMergedRanges,cr as extendSelection,J as findNativeParagraph,ve as findNativeParagraphLocation,rn as findNativeTableCellLocation,Oe as findNativeTableLocation,Mo as findPptSceneNode,mr as findPptSceneSlide,VT as findSpreadsheetMatches,ES as formatSpreadsheetDisplayValue,Pl as formulasForPaste,BS as freezeStateFromPane,qi as freezeStateFromSheet,yp as getNativeWordCommandState,qe as getRenderCell,lN as getWordChangeSet,dN as getWordSelectionInfo,Ol as hitSpreadsheetResizeHandle,Ni as imageOffset,uR as isPptShapeEditable,Ox as layoutNativePageAnnotationBubbles,Dr as loadOfficeFonts,Os as measureNativeDocumentReflowFromParagraph,gT as moveSelection,Ps as nativeAddComment,ku as nativeAddFormatRevision,$t as nativeAddRevision,uy as nativeAnchorLayoutMetadata,Qs as nativeBlockClipboardText,vu as nativeClearRunFormat,su as nativeClearTableCellRange,Is as nativeCopyBlockRange,vf as nativeCursorFromPoint,jr as nativeDeleteBackward,wu as nativeDeleteComment,Ur as nativeDeleteForward,Su as nativeDeleteImage,bn as nativeDeleteRange,nu as nativeDeleteTable,bi as nativeDeleteTextRangeAcrossParagraphs,oy as nativeDrawingWidthCss,ru as nativeEditTableStructure,cu as nativeInsertImage,uu as nativeInsertPageBreak,tu as nativeInsertTable,on as nativeInsertText,ny as nativeLineStrokeStyle,Xc as nativeListIndent,mn as nativeListType,ou as nativeMergeTableCells,ys as nativeNumberingAtLevel,gi as nativePageBreakAt,Pe as nativeParagraphText,fu as nativeRangeContainsPageBreak,hu as nativeReplaceBlockRangeAcrossParagraphs,Kr as nativeReplaceRange,mu as nativeReplaceRangeWithBlocks,du as nativeReplaceTableCellRangeContent,lu as nativeReplaceTableCellRangeText,gu as nativeReplaceTextRangeAcrossParagraphs,Ns as nativeReplaceTextRangeWithParagraphs,yu as nativeResolveFormatRevision,Cu as nativeResolveImageFormatRevision,Eu as nativeResolveImageRevision,xu as nativeResolveRevision,Tt as nativeSelection,lt as nativeSelectionFromCursor,Rs as nativeSetHyperlink,pu as nativeSetImageSize,er as nativeSetParagraphFormat,_r as nativeSetParagraphList,Ts as nativeSetRunFormat,Es as nativeSetTableCellFormat,au as nativeSetTableCellRangeFormat,Ms as nativeSplitParagraph,iu as nativeSplitTableCell,qr as nativeSyncParagraphText,tt as nativeTableCellsInRange,Gr as nativeTableSupportsStructuralEditing,SI as nativeTextRangeIsBold,bu as nativeUpdateComment,GT as nextSpreadsheetMatch,To as normalizePptGeometry,We as normalizeSelectionRange,Gu as paginateNativeDocument,Nt as parentNativeParagraph,Rf as parseNativeBlockClipboard,Pf as parseNativeClipboardHtml,Xp as parseTsv,Ry as planWordOoxmlPatch,Py as planWordOoxmlPatches,qh as pptSceneGeometryToSourceGeometry,_h as pptSceneNodeCapabilities,cP as previewSpreadsheetAgentAction,ms as previousNativeParagraphId,IT as rangeAddressForMatrix,jT as rangeForSpreadsheetMatch,Il as readSpreadsheetClipboardPayload,Vt as rebuildNativeTableFragmentsFromParagraph,ju as reflowNativeDocumentFromParagraph,fi as refreshNativeNumberingLabels,vn as refreshNativePageCommentBubbles,to as renderNativeBlock,zu as renderNativeDocument,Gs as renderNativeImage,no as renderNativeParagraph,PR as renderNativePptEditor,xf as renderNativeTable,DN as renderNativeWordEditor,lI as renderNormalizedDocumentHtmlPage,sR as renderSpreadsheetEditor,Kx as resolveNativeSectionPageNumberStarts,gy as resolveNativeTableCellBorders,qt as resolveOfficeFontFamily,Or as resolveParagraphStyle,Jn as resolveRunStyle,wo as resolveSpreadsheetCellStyle,Hp as resolveSpreadsheetRangeBorder,xo as resolveSpreadsheetRunStyle,si as resolveTableCellStyle,My as resolveWordOoxmlPatchTargets,dt as restoreNativeCursor,Sf as restoreNativeElementSelection,Sn as restoreNativeTextSelection,zi as rowColumnKey,ia as scrollFromThumbPosition,qs as searchNativeWordDocument,Ef as selectNativeImage,wT as selectionAfterColumnDeletion,bT as selectionAfterRowDeletion,Js as serializeNativeBlockClipboard,Zs as serializeNativeClipboardHtml,o0 as serializeRangeToTsv,ko as serializeSpreadsheetClipboardPayload,fN as setColor,uN as setFontSize,pN as setParagraphAlign,BT as setSpreadsheetCellFormula,WT as setSpreadsheetCellValue,$T as setSpreadsheetColumnWidth,FT as setSpreadsheetRangeValues,OT as setSpreadsheetRowHeight,pI as splitNativeTableRowAtBlockBoundary,hI as splitNativeTableRowAtTextOffset,Dl as spreadsheetFilterValues,sh as spreadsheetRowsForColumnFilters,ah as spreadsheetRowsForFilter,lh as spreadsheetSortRows,_T as spreadsheetVisibleFilterValues,Ch as startSpreadsheetResizeDrag,Zb as summarizeEditorCoverage,nI as summarizeNativeCoverage,fI as summarizeNativeTablePagination,CP as summarizeSpreadsheetSelectionFormat,Al as supportsSpreadsheetAutoFill,cN as toggleBold,$l as updateSpreadsheetResizeDrag,lo as wordEditingPluginKey};
|