@betteroffice/docx 0.1.0 → 0.2.0

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.
Files changed (63) hide show
  1. package/README.md +2 -6
  2. package/dist/chunk-47Q2FMFF.mjs +1 -0
  3. package/dist/chunk-6LQJAKOC.mjs +1 -0
  4. package/dist/chunk-ACGKK7IB.mjs +1 -0
  5. package/dist/{chunk-PI2I3TO5.mjs → chunk-AFMVSI4Z.mjs} +2 -2
  6. package/dist/chunk-GD4VNJ64.mjs +1 -0
  7. package/dist/{chunk-BUZ2X5CT.mjs → chunk-JHJLG4I6.mjs} +1 -1
  8. package/dist/chunk-PGMXWI5X.mjs +1 -0
  9. package/dist/{chunk-VRGUAKOC.mjs → chunk-WTFRNX5K.mjs} +1 -1
  10. package/dist/collaboration/index.d.mts +6 -6
  11. package/dist/{content-DrqzbIr7.d.mts → content-CvEtPl0c.d.mts} +59 -6
  12. package/dist/core.d.mts +7 -7
  13. package/dist/core.mjs +1 -1
  14. package/dist/{displayListQueries-DGDR-OWc.d.mts → displayListQueries-DF8F6fMl.d.mts} +2 -2
  15. package/dist/docx/index.d.mts +3 -3
  16. package/dist/docx/index.mjs +1 -1
  17. package/dist/editor/index.d.mts +20 -11
  18. package/dist/editor/index.mjs +1 -1
  19. package/dist/{fontLoader-DnixuYST.d.mts → fontLoader-b8eicJKV.d.mts} +1 -1
  20. package/dist/{formatting-BqrFPeev.d.mts → formatting-7zKCTu5a.d.mts} +3 -2
  21. package/dist/{frameDelta-DMgR8n13.d.mts → frameDelta-pA4jrQ1G.d.mts} +3 -2
  22. package/dist/generated/edit/docx_edit_bg.wasm +0 -0
  23. package/dist/generated/layout/docx_layout_bg.wasm +0 -0
  24. package/dist/generated/opc/ooxml_opc_bg.wasm +0 -0
  25. package/dist/generated/parse/docx_parse_bg.wasm +0 -0
  26. package/dist/{index-ImoMd0Ju.d.mts → index-CHl2zLJ7.d.mts} +117 -15
  27. package/dist/layout/index.d.mts +4 -4
  28. package/dist/layout/index.mjs +1 -1
  29. package/dist/layout/pagination/index.d.mts +4 -4
  30. package/dist/layout/pagination/index.mjs +1 -1
  31. package/dist/layout/render/index.d.mts +10 -10
  32. package/dist/layout/render/index.mjs +1 -1
  33. package/dist/plugin-api/RenderedDomContext.d.mts +7 -7
  34. package/dist/plugin-api/index.d.mts +3 -3
  35. package/dist/plugin-api/resolveItemPositions.d.mts +3 -3
  36. package/dist/{rustDisplayList-B9dQoLHI.d.mts → rustDisplayList-BJqaN9tt.d.mts} +2 -2
  37. package/dist/styles/index.d.mts +5 -9
  38. package/dist/styles/index.mjs +1 -1
  39. package/dist/{styles-CMybYYHS.d.mts → styles-7e-mq3c-.d.mts} +1 -1
  40. package/dist/types/content.d.mts +2 -2
  41. package/dist/types/document.d.mts +7 -6
  42. package/dist/{types-CXLxVF1t.d.mts → types-C4A8mWjU.d.mts} +19 -3
  43. package/dist/utils/comments.d.mts +2 -2
  44. package/dist/utils/index.d.mts +4 -4
  45. package/dist/utils/index.mjs +1 -1
  46. package/dist/utils/stylePreview.d.mts +2 -2
  47. package/dist/wasm-7SOSHNGP.mjs +1 -0
  48. package/dist/{wasm-T2CRCO7S.mjs → wasm-ZQAVP7P2.mjs} +1 -1
  49. package/dist/wasm-edit.d.mts +35 -27
  50. package/dist/wasm-edit.mjs +1 -1
  51. package/dist/wasm-layout.mjs +1 -1
  52. package/dist/wasm-parse.d.mts +2 -1
  53. package/dist/wasm-parse.mjs +1 -1
  54. package/dist/yrs/index.d.mts +5 -5
  55. package/dist/yrs/index.mjs +1 -1
  56. package/dist/yrs/residentEngineWorker.mjs +1 -1
  57. package/package.json +2 -2
  58. package/dist/chunk-24DL53QL.mjs +0 -1
  59. package/dist/chunk-GHEHBYQK.mjs +0 -1
  60. package/dist/chunk-HTDNSQ44.mjs +0 -1
  61. package/dist/chunk-TMHG7OAZ.mjs +0 -1
  62. package/dist/chunk-WBH3SXI6.mjs +0 -1
  63. package/dist/wasm-CJHQHBDE.mjs +0 -1
@@ -1 +1 @@
1
- export{a as residentCaretDeviceRect,b as residentCaretSnapshotForFrame}from'../chunk-J7LNO6SM.mjs';import {b as b$4}from'../chunk-OBQGPMPQ.mjs';import {c,a}from'../chunk-WBH3SXI6.mjs';import {p,b as b$2}from'../chunk-LTVVQMHB.mjs';import {c as c$2,b as b$3}from'../chunk-CTBUQRYQ.mjs';import {b as b$1,c as c$1}from'../chunk-TMHG7OAZ.mjs';import'../chunk-GHEHBYQK.mjs';import'../chunk-5F6DLQZP.mjs';import {b}from'../chunk-TTRUPDAB.mjs';function $n(e,t){let n=0,r=t.map(o=>{let l={paraId:o.paraId,length:Math.max(0,Math.trunc(o.length)),displayStart:n};return n+=l.length+2,l});return {story:e,paragraphs:r}}function Ne(e,t){let n=e.paragraphs.find(r=>r.paraId===t.paraId);return !n||t.story!==e.story?e.paragraphs[0]?.displayStart??0:n.displayStart+1+Math.min(Math.max(0,t.offset),n.length)}function Hn(e,t){if(e.paragraphs.length===0)return null;let n=Math.max(0,Math.trunc(t)),r=e.paragraphs[0];for(let o of e.paragraphs){if(o.displayStart>n)break;r=o;}return {story:e.story,paraId:r.paraId,offset:Math.min(Math.max(0,n-(r.displayStart+1)),r.length)}}function zn(e,t,n){return Ne(e,t)-Ne(e,n)}var de=class{constructor(){b(this,"worker");b(this,"pending",new Map);b(this,"nextId",1);b(this,"destroyed",false);b(this,"ready",false);b(this,"revision",0);b(this,"remoteVector",null);b(this,"appliedFontsRevision",null);this.worker=new Worker(new URL("./residentEngineWorker.mjs",import.meta.url),{type:"module",name:"openooxml-resident-engine"}),this.worker.onmessage=t=>{let n=t.data;n.ok&&n.stateVector&&(this.remoteVector=new Uint8Array(n.stateVector));let r=this.pending.get(n.id);r&&(this.pending.delete(n.id),r.timeout&&clearTimeout(r.timeout),n.ok?r.resolve(n):r.reject(Pt(n.error,n.residentUnavailable)));},this.worker.onerror=t=>{this.failAll(new Error(`Resident engine worker failed: ${t.message}`)),this.ready=false;},this.worker.onmessageerror=()=>{this.failAll(new Error("Resident engine worker returned an unreadable message")),this.ready=false;};}isReady(){return this.ready}layoutRevision(){return this.revision}remoteStateVector(){return this.remoteVector}syncedFontsRevision(){return this.appliedFontsRevision}async bootstrap(t,n){let r=t.fontsRevision,o=await this.request({type:"bootstrap",snapshot:t,extras:n,expectedFrameEpoch:0},Oe(t),15e3),l=K(o);return this.recordSync(o,r),this.ready=true,this.revision=l.layoutRevision,l}async sync(t,n,r,o=false){let l=t.fontsRevision,s=await this.request({type:"sync",snapshot:t,extras:n,expectedFrameEpoch:r,paintCaret:o},Oe(t)),d=K(s);return this.recordSync(s,l),this.ready=true,this.revision=d.layoutRevision,d}async buildFrame(t,n,r=false){return K(await this.request({type:"buildFrame",extras:t,expectedFrameEpoch:n,paintCaret:r}))}async applyInput(t,n,r,o=false,l=false){if(!this.ready)return {applied:false};try{return {applied:!0,...K(await this.request({type:"applyInput",text:t,selection:n,expectedFrameEpoch:r,profile:o,paintCaret:l}))}}catch(s){if(s instanceof q)return {applied:false};throw s}}async applyDelete(t,n,r,o=false,l=false){if(!this.ready)return {applied:false};try{return {applied:!0,...K(await this.request({type:"applyDelete",direction:t,selection:n,expectedFrameEpoch:r,profile:o,paintCaret:l}))}}catch(s){if(s instanceof q)return {applied:false};throw s}}eraseCaret(){if(this.destroyed)return;let n={id:this.nextId++,type:"eraseCaret"};this.worker.postMessage(n);}invalidate(t,n){if(this.destroyed)return;this.ready=false;let r=t.slice(),l={id:this.nextId++,type:"applyUpdate",update:r,selection:n};this.worker.postMessage(l,[r.buffer]);}async attachCanvases(t,n,r,o,l){let s=t.map(d=>d.canvas);await this.request({type:"attachCanvases",pages:t,activePageIds:n,devicePixelRatio:r,zoom:o,caretStyle:l},s);}destroy(){if(this.destroyed)return;this.destroyed=true;let n={id:this.nextId++,type:"destroy"};this.worker.postMessage(n),this.worker.terminate(),this.failAll(new Error("Resident engine worker was destroyed")),this.ready=false;}request(t,n=[],r){if(this.destroyed)return Promise.reject(new Error("Resident engine worker was destroyed"));let o=this.nextId++;return new Promise((l,s)=>{let d=r?setTimeout(()=>{let a=this.pending.get(o);if(!a)return;this.pending.delete(o);let f=new Error(`Resident engine worker did not acknowledge ${t.type} within ${r}ms`);a.reject(f),this.failAll(f),this.ready=false,this.destroyed=true,this.worker.terminate();},r):null;this.pending.set(o,{resolve:l,reject:s,timeout:d}),this.worker.postMessage({...t,id:o},n);})}recordSync(t,n){this.appliedFontsRevision=n;}failAll(t){for(let n of this.pending.values())n.timeout&&clearTimeout(n.timeout),n.reject(t);this.pending.clear();}},q=class extends Error{};function Pt(e,t=false){return t?new q(e):new Error(e)}function Oe(e){return [e.state.buffer,...e.fonts.map(t=>t.buffer)]}function K(e){if(!e.frame)throw new Error("Resident engine worker response omitted its FrameDelta");if(!e.caret)throw new Error("Resident engine worker response omitted its caret snapshot");if(e.selection===void 0)throw new Error("Resident engine worker response omitted its selection");return {frame:new Uint8Array(e.frame),updates:(e.updates??[]).map(t=>new Uint8Array(t)),engineMs:e.engineMs??0,workerTotalMs:e.workerTotalMs??0,engineProfile:e.engineProfile,caret:e.caret,selection:e.selection,caretPainted:e.caretPainted??false,replayMs:e.replayMs??0,replayedPages:e.replayedPages??0,layoutRevision:e.layoutRevision??0}}function It(){return typeof Worker<"u"}function ue(e){return {sdtType:e.sdtType,id:e.id??null,alias:e.alias??null,tag:e.tag??null,lock:e.lock??null,placeholder:e.placeholder??null,showingPlaceholder:e.showingPlaceholder??false,dateFormat:e.dateFormat??null,listItems:e.listItems?JSON.stringify(e.listItems):null,checked:e.checked??null,dataBinding:e.dataBinding?JSON.stringify(e.dataBinding):null,rawPropertiesXml:e.rawPropertiesXml??null,rawEndPropertiesXml:e.rawEndPropertiesXml??null}}function ce(e){let t={sdtType:e.sdtType??"richText"};if(typeof e.id=="number"&&(t.id=e.id),e.alias!=null&&(t.alias=String(e.alias)),e.tag!=null&&(t.tag=String(e.tag)),e.lock!=null&&(t.lock=e.lock),e.placeholder!=null&&(t.placeholder=String(e.placeholder)),e.showingPlaceholder&&(t.showingPlaceholder=true),e.dateFormat!=null&&(t.dateFormat=String(e.dateFormat)),typeof e.listItems=="string"&&e.listItems)try{t.listItems=JSON.parse(e.listItems);}catch{}if(e.checked!=null&&(t.checked=e.checked),typeof e.dataBinding=="string"&&e.dataBinding)try{t.dataBinding=JSON.parse(e.dataBinding);}catch{}return e.rawPropertiesXml!=null&&(t.rawPropertiesXml=String(e.rawPropertiesXml)),e.rawEndPropertiesXml!=null&&(t.rawEndPropertiesXml=String(e.rawEndPropertiesXml)),t}function L(e){if(Array.isArray(e))return e.map(L);if(e!==null&&typeof e=="object"){let t={};for(let[n,r]of Object.entries(e))r!=null&&(t[n]=L(r));return t}return e}var vt={styleId:"pStyle",_sectionProperties:"sectPr"},At=new Set(["paraId","textId","renderedPageBreakBefore","numPrFromStyle"]);function Ee(e){let t={};for(let[n,r]of Object.entries(e))At.has(n)||r===null||r===void 0||(t[vt[n]??n]=L(r));return t}var Ft=new Set(["columnWidths"]);function ee(e,t=new Set){let n={};for(let[r,o]of Object.entries(e))t.has(r)||o===null||o===void 0||(n[r]=L(o));return n}function Le(e){return ee(e,Ft)}function De(e){let t=e.columnWidths;return Array.isArray(t)?t.map(L):[]}function Je(e){return ee(e)}function Ue(e,t){let n=ee(e);return t&&(n.header=true),n}function pe(e,t,n,r){return `${e}:t${t}:r${n}c${r}`}function We(e,t){return `${e}:sdt${t}`}function je(e){return ee(e)}function te(e){return `hf:${e}`}function $e(e){return `fn:${e}`}function He(e){return `en:${e}`}var Yt=new Set(["bold","italic","superscript","subscript","allCaps","smallCaps","emboss","imprint","textShadow","textOutline","hidden","rtl"]);function z(e){if(e==null)return "null";if(Array.isArray(e))return `[${e.map(z).join(",")}]`;if(typeof e=="object"){let t=e;return `{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${z(t[n])}`).join(",")}}`}return JSON.stringify(e)}function Mt(e,t){if(!e||!t)return e;let n=t.resolveRunStyle(e.styleId);return n?a(n,e):e}function Ke(e){if(!e)return [];let t=[],n=(s,d={})=>t.push({name:s,attrs:d});e.bold&&n("bold"),e.italic&&n("italic"),e.underline&&e.underline.style!=="none"&&n("underline",{style:e.underline.style,color:e.underline.color??null}),(e.strike||e.doubleStrike)&&n("strike",{double:e.doubleStrike||false}),e.color&&!e.color.auto&&n("textColor",{rgb:e.color.rgb??null,themeColor:e.color.themeColor??null,themeTint:e.color.themeTint??null,themeShade:e.color.themeShade??null});let r=e.shading?.fill,o=(!e.shading?.pattern||e.shading.pattern==="clear")&&r?.rgb&&!r.auto?p(r.rgb):void 0,l=e.highlight&&e.highlight!=="none"?e.highlight:o;return l&&n("highlight",{color:l}),(e.fontSize!=null||e.fontSizeCs!=null)&&n("fontSize",{size:e.fontSize??null,sizeCs:e.fontSizeCs??null}),e.fontFamily&&n("fontFamily",{ascii:e.fontFamily.ascii??null,hAnsi:e.fontFamily.hAnsi??null,eastAsia:e.fontFamily.eastAsia??null,cs:e.fontFamily.cs??null,asciiTheme:e.fontFamily.asciiTheme??null,hAnsiTheme:e.fontFamily.hAnsiTheme??null,eastAsiaTheme:e.fontFamily.eastAsiaTheme??null,csTheme:e.fontFamily.csTheme??null}),e.vertAlign==="superscript"?n("superscript"):e.vertAlign==="subscript"&&n("subscript"),e.allCaps&&n("allCaps"),e.smallCaps&&n("smallCaps"),(e.spacing!=null||e.position!=null||e.scale!=null||e.kerning!=null)&&n("characterSpacing",{spacing:e.spacing??null,position:e.position??null,scale:e.scale??null,kerning:e.kerning??null}),e.emboss&&n("emboss"),e.imprint&&n("imprint"),e.shadow&&n("textShadow"),e.emphasisMark&&e.emphasisMark!=="none"&&n("emphasisMark",{type:e.emphasisMark}),e.outline&&n("textOutline"),e.hidden&&n("hidden"),e.rtl&&n("rtl"),e.effect&&e.effect!=="none"&&n("textEffect",{effect:e.effect}),e.modernEffects&&n("modernTextEffects",{effects:e.modernEffects}),e.styleId&&n("runStyle",{styleId:e.styleId}),t}function qe(e){let t={};for(let n of e)n.name==="comment"||n.name==="footnoteRef"||(Yt.has(n.name)?t[n.name]=true:n.name==="highlight"?t.highlight=n.attrs.color:n.name==="insertion"||n.name==="deletion"?t[n.name==="insertion"?"ins":"del"]=L({id:n.attrs.revisionId,author:n.attrs.author,date:n.attrs.date}):t[n.name]=L(n.attrs));return t}function _t(e){return e.filter(t=>t.name!=="hyperlink"&&t.name!=="comment").map(t=>`${t.name}:${JSON.stringify(t.attrs)}`).sort().join("|")}function Bt(e,t){return [...e.filter(n=>n.name!==t.name),t]}function X(e,t,n){return {kind:"text",text:e,attrs:qe(t),pmSize:e.length,...n!==void 0?{commentId:n}:{},marks:[...t]}}function v(e,t,n=[],r,o=1){return {kind:"embed",embedKind:e,payload:t,attrs:qe(n),pmSize:o,...r!==void 0?{commentId:r}:{},marks:[...n]}}function Xe(e,t,n){let r=e.formatting?.styleId?n?.getRunStyleOwnProperties(e.formatting.styleId):void 0;return Ke(a(a(t,r),e.formatting))}function Nt(e){let t=e.size?.width?b$3(e.size.width):void 0,n=e.size?.height?b$3(e.size.height):void 0,r=e.wrap.type,o=e.wrap.wrapText,l=e.position?.horizontal?.alignment,s;r==="inline"||r==="topAndBottom"?s="none":r==="square"||r==="tight"||r==="through"?o==="left"?s="right":o==="right"?s="left":l==="left"||l==="right"?s=l:s="none":s="none";let d=r==="inline"?"inline":r==="topAndBottom"?"block":b$4(r)||s&&s!=="none"?"float":"block",a=[];e.transform?.rotation&&a.push(`rotate(${e.transform.rotation}deg)`),e.transform?.flipH&&a.push("scaleX(-1)"),e.transform?.flipV&&a.push("scaleY(-1)");let f,p,c;if(e.outline?.width){f=Math.round(e.outline.width/914400*96*100)/100,e.outline.color?.rgb&&(p=`#${e.outline.color.rgb}`);let g={solid:"solid",dot:"dotted",dash:"dashed",lgDash:"dashed",dashDot:"dashed",lgDashDot:"dashed",lgDashDotDot:"dashed",sysDot:"dotted",sysDash:"dashed",sysDashDot:"dashed",sysDashDotDot:"dashed"};c=e.outline.style&&g[e.outline.style]||"solid";}return L({src:e.src||"",alt:e.alt??null,title:e.title??null,width:t??null,height:n??null,rId:e.rId??null,wrapType:r,displayMode:d,cssFloat:s??null,transform:a.length>0?a.join(" "):null,distTop:e.wrap.distT!=null?b$3(e.wrap.distT):null,distBottom:e.wrap.distB!=null?b$3(e.wrap.distB):null,distLeft:e.wrap.distL!=null?b$3(e.wrap.distL):null,distRight:e.wrap.distR!=null?b$3(e.wrap.distR):null,position:e.position?{horizontal:e.position.horizontal?{relativeTo:e.position.horizontal.relativeTo,posOffset:e.position.horizontal.posOffset,align:e.position.horizontal.alignment}:void 0,vertical:e.position.vertical?{relativeTo:e.position.vertical.relativeTo,posOffset:e.position.vertical.posOffset,align:e.position.vertical.alignment}:void 0}:null,borderWidth:f??null,borderColor:p??null,borderStyle:c??null,wrapText:o??null,hlinkHref:e.hlinkHref??null,cropTop:e.crop?.top??null,cropRight:e.crop?.right??null,cropBottom:e.crop?.bottom??null,cropLeft:e.crop?.left??null,opacity:e.opacity??null,effectExtentTop:e.padding?.top?b$3(e.padding.top):null,effectExtentBottom:e.padding?.bottom?b$3(e.padding.bottom):null,effectExtentLeft:e.padding?.left?b$3(e.padding.left):null,effectExtentRight:e.padding?.right?b$3(e.padding.right):null,layoutInCell:e.layoutInCell??null,allowOverlap:e.allowOverlap??null})}function Ot(e){return {shapeJson:JSON.stringify(e)}}function Et(e){return L({chartJson:JSON.stringify(e),chartType:e.chartType??null,title:e.title??null,width:e.size?.width?b$3(e.size.width):320,height:e.size?.height?b$3(e.size.height):220,rId:e.rId??null,path:e.path??null})}function ge(e,t){let n="",r,o=e.type==="simpleField"?e.content:e.fieldResult;for(let d of o)if(d.type==="run"){for(let a of d.content)a.type==="text"&&(n+=a.text);!r&&d.formatting&&(r=d.formatting);}let l=r??(e.type==="complexField"?e.formatting:void 0),s=e.fieldTree?.displayMode??"result";return {payload:{fieldType:e.fieldType,instruction:e.instruction,displayText:n,fieldKind:e.type==="simpleField"?"simple":"complex",fldLock:e.fldLock??false,dirty:e.dirty??false,displayMode:s,hasCachedResult:n.length>0,fieldData:JSON.stringify(e),modelKind:"field"},marks:Ke(a(t,l))}}function me(e){return {display:e.display,ommlXml:e.ommlXml,plainText:e.plainText||""}}function Lt(e){return {name:"hyperlink",attrs:{href:e.href||(e.anchor?`#${e.anchor}`:""),tooltip:e.tooltip??null,rId:e.rId??null}}}function ze(e,t,n,r){let o={name:"footnoteRef",attrs:{id:String(e),noteType:t}},l=[...n,o];return v("noteRef",t==="endnote"?{endnoteRefId:e}:{footnoteRefId:e},l,r)}function Ge(e,t,n){switch(e.type){case "text":return e.text?[X(e.text,t,n)]:[];case "tab":return [X(" ",t,n)];case "break":return e.breakType===void 0||e.breakType==="textWrapping"?[v("break",{},t,n)]:[];case "softHyphen":return [X("\xAD",t,n)];case "noBreakHyphen":return [X("\u2011",t,n)];case "symbol":{let r=Number.parseInt(e.char,16);if(!Number.isInteger(r)||r<0||r>1114111)return [];let o={name:"fontFamily",attrs:{ascii:e.font||null,hAnsi:e.font||null,eastAsia:e.font||null,cs:e.font||null,asciiTheme:null,hAnsiTheme:null,eastAsiaTheme:null,csTheme:null}};return [X(String.fromCodePoint(r),Bt(t,o),n)]}case "commentReference":return [v("field",{fieldType:"COMMENT",instruction:"",displayText:"",fieldKind:"simple",fldLock:false,dirty:false,displayMode:"result",hasCachedResult:false,modelKind:"commentReference",...e.id!==void 0?{commentId:e.id}:{}})];case "drawing":return [v("image",Nt(e.image))];case "shape":return [v("shape",Ot(e.shape))];case "chart":return [v("chart",Et(e.chart))];case "footnoteRef":return [ze(e.id,"footnote",t,n)];case "endnoteRef":return [ze(e.id,"endnote",t,n)];default:return []}}function ne(e,t,n,r,o=[]){let l=[...Xe(e,t,n),...o];return e.content.flatMap(s=>Ge(s,l,r))}function he(e,t,n,r=[]){let o=[],l=Lt(e);for(let s of e.structuredChildren??e.children)if(s.type==="run"){let d=[...Xe(s,t,n),...r,l];for(let a of s.content)o.push(...Ge(a,d));}else if(s.type==="simpleField"||s.type==="complexField"){let d=ge(s,t);o.push(v("field",d.payload,[...d.marks,...r,l]));}else s.type==="mathEquation"&&o.push(v("math",me(s),[...r,l]));return o}function Dt(e,t,n){return {name:t,attrs:{revisionId:e.id,author:e.author,date:e.date??null,isMovePair:n}}}function Jt(e,t,n,r){let o=e.type==="insertion"||e.type==="moveTo"?"insertion":"deletion",l=Dt(e.info,o,e.type==="moveFrom"||e.type==="moveTo"),s=[];for(let d of e.content)if(d.type==="run")s.push(...ne(d,t,n,r,[l]));else {let a=he(d,t,n,[l]);for(let f of a)r!==void 0&&(f.commentId=r);s.push(...a);}return s}function Ze(e,t,n){let r=[],o=l=>{if(l.kind==="text"){if((l.text===" "?"tab":"text")==="tab"){r.push({kind:"tab",attrs:l.attrs});return}let d=r[r.length-1];d&&"text"in d&&z(d.attrs)===z(l.attrs)?d.text+=l.text:r.push({kind:"text",text:l.text,attrs:l.attrs});return}r.push({kind:l.embedKind,payload:l.payload,attrs:l.attrs});};for(let l of e.content)if(l.type==="run")ne(l,t,n).forEach(o);else if(l.type==="hyperlink")he(l,t,n).forEach(o);else if(l.type==="simpleField"||l.type==="complexField"){let s=ge(l,t);o(v("field",s.payload,s.marks));}else l.type==="inlineSdt"?o(v("sdt",Ze(l,t,n))):l.type==="mathEquation"&&o(v("math",me(l)));return L({...ue(e.properties),propertiesJson:JSON.stringify(e.properties),content:r})}function Ut(e,t,n){let r=t?t.resolveParagraphStyle(e.formatting?.styleId).runFormatting:void 0;return a(r,n)}function Wt(e){let t=[];for(let n of e.content)n.type==="footnoteRefMark"?t.push("footnote"):n.type==="endnoteRefMark"&&t.push("endnote");return t}function jt(e,t,n){let r=ne(e,t,n);if(r.some(a=>a.kind!=="text"&&a.embedKind!=="noteRef"))return null;let o=r.map(a=>_t(a.marks));if(o.some(a=>a!==o[0]))return null;let l=Wt(e),s=r.map(a=>{if(a.kind==="text")return a.text;let f=a.payload.footnoteRefId??a.payload.endnoteRefId;return String(f??"")}).join(""),d=o[0];return {text:s,...l.length>0?{noteMarks:l}:{},...d!==void 0?{marksKey:d}:{},...e.formatting?{formatting:e.formatting}:{},...e.propertyChanges?{propertyChanges:e.propertyChanges}:{}}}function $t(e,t,n,r){let o=e.formatting,l=o?.styleId,s={paraId:e.paraId??null,textId:e.textId??null,styleId:l??null,numPr:o?.numPr??null,numPrFromStyle:o?.numPrFromStyle??null,listNumFmt:e.listRendering?.numFmt??null,listIsBullet:e.listRendering?.isBullet??null,listMarker:e.listRendering?.marker??null,listMarkerHidden:e.listRendering?.markerHidden||null,listMarkerFontFamily:e.listRendering?.markerFontFamily||null,listMarkerFontSize:e.listRendering?.markerFontSize||null,listMarkerSuffix:e.listRendering?.markerSuffix||null,listLevelNumFmts:e.listRendering?.levelNumFmts||null,listAbstractNumId:e.listRendering?.abstractNumId??null,listStartOverride:e.listRendering?.startOverride??null,_originalFormatting:o??null};if(t){let p=t.resolveParagraphStyle(l),c=p.paragraphFormatting;s.alignment=o?.alignment??c?.alignment??null,s.spaceBefore=o?.spaceBefore??c?.spaceBefore??null,s.spaceAfter=o?.spaceAfter??c?.spaceAfter??null,s.lineSpacing=o?.lineSpacing??c?.lineSpacing??null,s.lineSpacingRule=o?.lineSpacingRule??c?.lineSpacingRule??null,s.spacingExplicit=o?.spacingExplicit||null,s.indentLeft=o?.indentLeft??c?.indentLeft??null,s.indentRight=o?.indentRight??c?.indentRight??null;let m=o?.numPr?.numId===0&&c?.numPr&&c.numPr.numId!==0?void 0:c;s.indentFirstLine=o?.indentFirstLine??m?.indentFirstLine??null,s.hangingIndent=o?.hangingIndent??m?.hangingIndent??false,s.borders=o?.borders??c?.borders??null,s.shading=o?.shading??c?.shading??null,s.tabs=o?.tabs??c?.tabs??null,s.pageBreakBefore=o?.pageBreakBefore??c?.pageBreakBefore??null,s.keepNext=o?.keepNext??c?.keepNext??null,s.keepLines=o?.keepLines??c?.keepLines??null,s.widowControl=o?.widowControl??c?.widowControl??null,s.contextualSpacing=o?.contextualSpacing??c?.contextualSpacing??null,s.outlineLevel=o?.outlineLevel??c?.outlineLevel??null,s.bidi=o?.bidi??c?.bidi??null;let y=t.getDefaultCharacterStyle()?.rPr,b=y?a(p.runFormatting,y):p.runFormatting;s.defaultTextFormatting=a(b,Mt(o?.runProperties,t))??null,!o?.numPr&&c?.numPr&&c.numPr.numId!==0&&(s.numPr=c.numPr,s.numPrFromStyle=c.numPr);}else s.alignment=o?.alignment??null,s.spaceBefore=o?.spaceBefore??null,s.spaceAfter=o?.spaceAfter??null,s.lineSpacing=o?.lineSpacing??null,s.lineSpacingRule=o?.lineSpacingRule??null,s.spacingExplicit=o?.spacingExplicit||null,s.indentLeft=o?.indentLeft??null,s.indentRight=o?.indentRight??null,s.indentFirstLine=o?.indentFirstLine??null,s.hangingIndent=o?.hangingIndent??false,s.borders=o?.borders??null,s.shading=o?.shading??null,s.tabs=o?.tabs??null,s.pageBreakBefore=o?.pageBreakBefore??null,s.keepNext=o?.keepNext??null,s.keepLines=o?.keepLines??null,s.widowControl=o?.widowControl??null,s.outlineLevel=o?.outlineLevel??null,s.bidi=o?.bidi??null,s.defaultTextFormatting=o?.runProperties??null;if(e.sectionProperties){s._sectionProperties=e.sectionProperties;let p=e.sectionProperties.sectionStart;(p==="nextPage"||p==="continuous"||p==="oddPage"||p==="evenPage"||p==="nextColumn")&&(s.sectionBreakType=p);}e.renderedPageBreakBefore&&(s.renderedPageBreakBefore=true),Vt(e)&&(s.pageBreakBefore=true),e.pPrIns&&(s.pPrIns={revisionId:e.pPrIns.id,author:e.pPrIns.author,date:e.pPrIns.date??null}),e.pPrDel&&(s.pPrDel={revisionId:e.pPrDel.id,author:e.pPrDel.author,date:e.pPrDel.date??null}),e.propertyChanges?.length&&(s.pPrChange=e.propertyChanges);let d=[],a$1=0,f=0;for(let p of e.content)if(p.type==="bookmarkStart")d.push({id:p.id,name:p.name,kind:"start",offset:f,...p.colFirst!==void 0?{colFirst:p.colFirst}:{},...p.colLast!==void 0?{colLast:p.colLast}:{}});else if(p.type==="bookmarkEnd")d.push({id:p.id,kind:"end",offset:f});else {let c=Ht(p);for(let g=0;g<c;g+=1)f+=n[a$1]?.pmSize??0,a$1+=1;}return d.length>0&&(s.bookmarks=d),r?.length&&(s._originalRunBoundaries=r),s}var Qe=new WeakMap;function Ht(e){return Qe.get(e)??0}function zt(e,t,n){let r=[],o=new Set,l=[],s=Ut(e,t,n);for(let a of e.content){let f=r.length,p=o.values().next().value;if(a.type==="commentRangeStart")o.add(a.id);else if(a.type==="commentRangeEnd")o.delete(a.id);else if(a.type==="run"){let c=jt(a,s,t);c&&l?l.push(c):l=void 0,r.push(...ne(a,s,t,p));}else if(a.type==="hyperlink")l=void 0,r.push(...he(a,s,t));else if(a.type==="simpleField"||a.type==="complexField"){l=void 0;let c=ge(a,s);r.push(v("field",c.payload,c.marks));}else a.type==="inlineSdt"?(l=void 0,r.push(v("sdt",Ze(a,s,t),[],void 0,2))):a.type==="insertion"||a.type==="deletion"||a.type==="moveFrom"||a.type==="moveTo"?(l=void 0,r.push(...Jt(a,s,t,p))):a.type==="mathEquation"?(l=void 0,r.push(v("math",me(a)))):a.type!=="bookmarkStart"&&a.type!=="bookmarkEnd"&&(l=void 0);Qe.set(a,r.length-f);}let d=$t(e,t,r,l);return {units:r,ppr:Ee(d)}}function G(e,t){for(let n of e.content)n.type==="break"&&n.breakType==="page"?t.push("pageBreak"):(n.type!=="text"||n.text.length>0)&&t.push("visible");}function ye(e,t){for(let n of e)if(n.type==="run")G(n,t);else if(n.type==="hyperlink")for(let r of n.children)r.type==="run"&&G(r,t);else if(n.type==="simpleField")for(let r of n.content)r.type==="run"&&G(r,t);else if(n.type==="complexField")for(let r of [...n.fieldCode,...n.fieldResult])G(r,t);else if(n.type==="inlineSdt")ye(n.content,t);else if(n.type==="insertion"||n.type==="deletion"||n.type==="moveFrom"||n.type==="moveTo")for(let r of n.content)r.type==="run"&&G(r,t);else n.type==="mathEquation"&&t.push("visible");}function Vt(e){let t=[];return ye(e.content,t),t[0]==="pageBreak"}function Kt(e){let t=[];ye(e.content,t);let n=false,r=false;for(let o of t)if(o==="pageBreak"){if(r||n)return true;n=true;}else r=true;return false}function qt(e){let t=new Map,n=new Map;return e.rows.forEach((r,o)=>{let l=0,s=r.cells.map(a=>{let f=l;return l+=a.formatting?.gridSpan??1,{column:f,vMerge:a.formatting?.vMerge,key:`${o}-${f}`}});if(s.length>0&&s.every(a=>a.vMerge==="continue"&&n.has(a.column))){for(let a of s)n.delete(a.column),t.set(a.key,{rowSpan:1,skip:false});return}for(let a of s)if(a.vMerge==="restart")n.set(a.column,o),t.set(a.key,{rowSpan:1,skip:false});else if(a.vMerge==="continue"){let f=n.get(a.column);if(f===void 0)t.set(a.key,{rowSpan:1,skip:false});else {let p=t.get(`${f}-${a.column}`);p&&(p.rowSpan+=1),t.set(a.key,{rowSpan:1,skip:true});}}else n.delete(a.column),t.set(a.key,{rowSpan:1,skip:false});}),t}function fe(e){return {revisionId:e.id,author:e.author,date:e.date??null}}function Xt(e,t,n,r,o,l){let s=t?{top:n?t.top:t.insideH,bottom:r?t.bottom:t.insideH,left:o?t.left:t.insideV,right:l?t.right:t.insideV}:void 0;return s||e?.borders?{...s??{},...e?.borders??{}}:void 0}function Ve(e,t){let n=e.formatting,r=b$2(n?.shading?.fill,t.theme),o=n?.width?.value??t.gridWidth,l=n?.width?.type??(t.gridWidth!==void 0?"pct":null),s={colspan:n?.gridSpan??1,rowspan:t.rowspan,width:o??null,widthType:l,verticalAlign:n?.verticalAlign??null,backgroundColor:r??null,borders:Xt(n,t.tableBorders,t.firstRow,t.lastRow,t.firstColumn,t.lastColumn)??null,margins:n?.margins?{top:n.margins.top?.value,bottom:n.margins.bottom?.value,left:n.margins.left?.value??(t.tableBidi?n.margins.end?.value:n.margins.start?.value),right:n.margins.right?.value??(t.tableBidi?n.margins.start?.value:n.margins.end?.value)}:t.defaultMargins??null,textDirection:n?.textDirection??null,noWrap:n?.noWrap??false,_originalFormatting:n??null,_originalResolvedFill:r??null};if(e.structuralChange){let d=e.structuralChange,a=fe(d.info);d.type==="tableCellInsertion"?s.cellMarker={kind:"ins",info:a}:d.type==="tableCellDeletion"?s.cellMarker={kind:"del",info:a}:d.type==="tableCellMerge"&&(s.cellMarker={kind:"merge",info:a,vMerge:d.vMerge??"cont",...d.vMergeOrig?{vMergeOrig:d.vMergeOrig}:{}});}return e.propertyChanges?.length&&(s.tcPrChange=e.propertyChanges),{attrs:Ue(s,t.isHeader),content:e.content.length>0?e.content:[{type:"paragraph",content:[]}]}}function Gt(e,t,n,r,o,l,s){let d={height:e.formatting?.height?.value??null,heightRule:e.formatting?.heightRule??null,isHeader:!!e.formatting?.header,_originalFormatting:e.formatting??null};e.structuralChange&&(e.structuralChange.type==="tableRowInsertion"?d.trIns=fe(e.structuralChange.info):e.structuralChange.type==="tableRowDeletion"&&(d.trDel=fe(e.structuralChange.info))),e.propertyChanges?.length&&(d.trPrChange=e.propertyChanges);let a=t.columnWidths,f=a?.reduce((m,y)=>m+y,0)??0,p=a?.length??Math.max(0,...t.rows.map(m=>m.cells.reduce((y,b)=>y+(b.formatting?.gridSpan??1),0))),c=0,g=[];return e.cells.forEach(m=>{let y=m.formatting?.gridSpan??1,b=c,R=r.get(`${n}-${b}`),w;if(a&&f>0){let I=0;for(let P=0;P<y&&b+P<a.length;P+=1)I+=a[b+P];w=Math.round(I/f*100);}c+=y,!R?.skip&&g.push(Ve(m,{isHeader:n===0&&!!t.formatting?.look?.firstRow,rowspan:R?.rowSpan??1,gridWidth:w,firstRow:n===0,lastRow:n===t.rows.length-1,firstColumn:b===0,lastColumn:c===p,tableBorders:o,defaultMargins:l,theme:s,tableBidi:!!t.formatting?.bidi}));}),g.length===0&&g.push(Ve({formatting:p>1?{gridSpan:p}:void 0,content:[{type:"paragraph",content:[]}]},{isHeader:n===0&&!!t.formatting?.look?.firstRow,rowspan:1,gridWidth:f>0?100:void 0,firstRow:n===0,lastRow:n===t.rows.length-1,firstColumn:true,lastColumn:true,tableBorders:o,defaultMargins:l,theme:s,tableBidi:!!t.formatting?.bidi})),{attrs:Je(d),cells:g}}function Zt(e,t,n){let r=t?.getDefaultTableStyle(),o=e.formatting?.styleId,l=o??r?.styleId,s=l?t?.getStyle(l):void 0,d=e.formatting?.borders??s?.tblPr?.borders??r?.tblPr?.borders,a=e.formatting?.cellMargins??s?.tblPr?.cellMargins??r?.tblPr?.cellMargins,f=e.formatting?.bidi?a?.end:a?.start,p=e.formatting?.bidi?a?.start:a?.end,c=a?{top:a.top?.value,bottom:a.bottom?.value,left:a.left?.value??f?.value,right:a.right?.value??p?.value}:void 0,g=[],m=new Set,y=s;for(;y?.basedOn&&g.length<32&&!m.has(y.basedOn);)m.add(y.basedOn),g.unshift(y.basedOn),y=t?.getStyle(y.basedOn);let b={...e.formatting??{},styleCascade:{...o?{selectedStyleId:o}:{},...r?.styleId?{defaultStyleId:r.styleId}:{},...g.length>0?{basedOnStyleIds:g}:{}}},R={styleId:o??null,width:e.formatting?.width?.value??null,widthType:e.formatting?.width?.type??null,justification:e.formatting?.justification??null,columnWidths:e.columnWidths??null,tableLayout:e.formatting?.layout??null,floating:e.formatting?.floating??null,cellMargins:c??null,look:e.formatting?.look??null,bidi:e.formatting?.bidi||null,_originalFormatting:b};e.propertyChanges?.length&&(R.tblPrChange=e.propertyChanges);let w=qt(e);return {attrs:R,rows:e.rows.map((I,P)=>Gt(I,e,P,w,d,c,n))}}function Qt(e){return je(ue(e))}function en(e){let t=0;for(let n of e.units){let r=n.kind==="text"?n.text.length:1;if(n.commentId!==void 0&&n.commentId!==0){let o=e.commentCoverage.get(n.commentId),l=o?.[o.length-1];l&&l[1]===t?l[1]=t+r:o?o.push([t,t+r]):e.commentCoverage.set(n.commentId,[[t,t+r]]);}t+=r;}}function $(e,t,n,r){let o={storyId:t,units:[],commentCoverage:new Map};e.plans.push(o);let l=n.length>0?[...n]:[{type:"paragraph",content:[]}],s=0,d=0,a=0,f=null;for(let p of l){if(p.type==="paragraph"){let m=zt(p,e.styleResolver,r.extraRunFormatting);o.units.push(...m.units),o.units.push(v("pilcrow",{...m.ppr,paraId:p.paraId||`${t}:p${a}`})),a+=1,r.includePageBreaks&&Kt(p)&&o.units.push(v("pageBreak",{})),f="paragraph";continue}if(p.type==="table"){let m=s++,y=Zt(p,e.styleResolver,e.theme),b=y.rows.map((R,w)=>({trPr:R.attrs,cells:R.cells.map((I,P)=>({tcPr:I.attrs,story:pe(t,m,w,P)}))}));o.units.push(v("table",{tblPr:Le(y.attrs),grid:De(y.attrs),rows:b})),y.rows.forEach((R,w)=>{R.cells.forEach((I,P)=>{$(e,pe(t,m,w,P),I.content,{includePageBreaks:false,appendBodyTail:false,seedComments:false,extraRunFormatting:I.extraRunFormatting});});}),f="table";continue}let c=d++,g=We(t,c);o.units.push(v("blockSdt",{...Qt(p.properties),story:g})),$(e,g,p.content,{includePageBreaks:r.includePageBreaks,appendBodyTail:false,seedComments:false}),f="blockSdt";}r.appendBodyTail&&(f==="table"||f==="blockSdt")&&o.units.push(v("pilcrow",{hangingIndent:false,paraId:`${t}:p${a}`})),r.seedComments&&en(o);}function tn(e){let t=[{op:"delete",index:0,len:1}],n=0,r="",o={},l=z(o),s=()=>{r&&(t.push({op:"insert",index:n,text:r,attrs:o}),n+=r.length,r="");};for(let d of e)if(d.kind==="text"){let a=z(d.attrs);r&&a!==l&&s(),o=d.attrs,l=a,r+=d.text;}else s(),t.push({op:"insertEmbed",index:n,kind:d.embedKind,payload:d.payload,attrs:d.attrs}),n+=1;return s(),t}function nn(e,t){e.applyRawOps(t.storyId,tn(t.units));let n=[];for(let[r,o]of t.commentCoverage)n.push({op:"setComment",id:String(r),ranges:o,author:"",date:"",body:null});n.length>0&&e.applyRawOps(t.storyId,n);}function rn(e,t){let n={styleResolver:t.package.styles?c(t.package.styles):null,theme:t.package.theme??null,plans:[]};$(n,"body",t.package.document.content,{includePageBreaks:true,appendBodyTail:true,seedComments:true});for(let[r,o]of t.package.headers??[])$(n,te(r),o.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let[r,o]of t.package.footers??[])n.plans.some(l=>l.storyId===te(r))||$(n,te(r),o.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let r of t.package.footnotes??[])$(n,$e(r.id),r.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let r of t.package.endnotes??[])$(n,He(r.id),r.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let r of n.plans)e.createStory(r.storyId,"","Normal","left");for(let r of n.plans)nn(e,r);}var j=class extends Error{constructor(t){super(t),this.name="ContentControlValueError";}};function re(e,t,n){let r=new RegExp(`<${t}\\b[^>]*>`).exec(e);if(!r)return;let o=new RegExp(`\\b${n}="([^"]*)"`).exec(r[0]);return o?o[1]:void 0}function be(e,t,n,r){let l=new RegExp(`<${t}\\b[^>]*?(/?)>`).exec(e);if(!l)return e;let s=l[0],d=l[1]==="/",a=s.slice(1,d?-2:-1),p=new RegExp(`\\b${n}="[^"]*"`).test(a)?a.replace(new RegExp(`\\b${n}="[^"]*"`),()=>`${n}="${r}"`):`${a} ${n}="${r}"`;return e.replace(s,()=>`<${p}${d?"/>":">"}`)}function on(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function sn(e,t){if(!e)return t;let n=parseInt(e,16);return Number.isNaN(n)||n<0||n>1114111||n>=55296&&n<=57343?t:String.fromCodePoint(n)}function ln(e,t,n){let[r,o,l]=e.slice(0,10).split("-").map(c=>parseInt(c,10));if(!et(r,o,l))return e;let s=t&&t.trim()?t:"M/d/yyyy",d=c=>String(c).padStart(2,"0"),a=new Date(Date.UTC(r,o-1,l)),f=c=>{try{return new Intl.DateTimeFormat(n||"en",{month:c,timeZone:"UTC"}).format(a)}catch{return new Intl.DateTimeFormat("en",{month:c,timeZone:"UTC"}).format(a)}},p={yyyy:String(r),yy:String(r).slice(-2),MMMM:f("long"),MMM:f("short"),MM:d(o),M:String(o),dd:d(l),d:String(l)};return s.replace(/yyyy|yy|MMMM|MMM|MM|M|dd|d/g,c=>p[c])}function et(e,t,n){if(!e||!t||!n)return false;let r=new Date(Date.UTC(e,t-1,n));return r.getUTCFullYear()===e&&r.getUTCMonth()===t-1&&r.getUTCDate()===n}function ke(e,t){return e?{type:"paragraph",content:[{type:"run",content:[{type:"text",text:e}],...t?{formatting:{fontFamily:{ascii:t,hAnsi:t,eastAsia:t,cs:t}}}:{}}]}:{type:"paragraph",content:[]}}function an(e){return e&&e.replace(/<w:showingPlcHdr\b[^>]*\/>/g,"").replace(/<w:showingPlcHdr\b[^>]*>[\s\S]*?<\/w:showingPlcHdr>/g,"")}function Se(e,t){let n=an(t);return {...e,showingPlaceholder:false,rawPropertiesXml:(n??t)||void 0}}function Re(e,t){let n=e.rawPropertiesXml??"";switch(t.kind){case "dropdown":{if(e.sdtType!=="dropDownList"&&e.sdtType!=="comboBox")throw new j(`Control is '${e.sdtType}', not a dropdown/combo box.`);let r=e.listItems?.find(f=>f.value===t.value||f.displayText===t.value);if(!r&&e.sdtType==="dropDownList")throw new j(`'${t.value}' is not one of the control's list items.`);let o=r?.value??t.value,l=r?.displayText??t.value,s=r?e.listItems?.indexOf(r):void 0,d=e.sdtType==="comboBox"?"w:comboBox":"w:dropDownList",a=be(n,d,"w:lastValue",on(o));return {properties:{...Se(e,a),listLastValue:o,controlState:{...e.controlState,value:l,selectedValue:o,selectedIndex:s,placeholder:false}},content:[ke(l)]}}case "checkbox":{if(e.sdtType!=="checkbox")throw new j(`Control is '${e.sdtType}', not a checkbox.`);if(re(n,"w14:checked","w14:val")==null)throw new j("Checkbox control has no <w14:checked> state to update (not a Word checkbox).");let r=t.checked?"w14:checkedState":"w14:uncheckedState",o=sn(re(n,r,"w14:val"),t.checked?"\u2612":"\u2610"),l=re(n,r,"w14:font"),s=be(n,"w14:checked","w14:val",t.checked?"1":"0");return {properties:{...Se(e,s),checked:t.checked,controlState:{...e.controlState,checked:t.checked,value:o,placeholder:false}},content:[ke(o,l)]}}case "date":{if(e.sdtType!=="date")throw new j(`Control is '${e.sdtType}', not a date control.`);let r=t.date.slice(0,10),[o,l,s]=/^\d{4}-\d{2}-\d{2}$/.test(r)?r.split("-").map(Number):[];if(!et(o,l,s))throw new j(`Date must be ISO yyyy-mm-dd, got '${t.date}'.`);let d=`${r}T00:00:00`,a=be(n,"w:date","w:fullDate",d),f=e.dateState?.format??e.dateFormat??re(n,"w:dateFormat","w:val"),p=e.dateState?.language,c=ln(r,f,p);return {properties:{...Se(e,a),dateFormat:f,dateState:{...e.dateState,fullDate:d,format:f},controlState:{...e.controlState,value:r,placeholder:false}},content:[ke(c)]}}}}function tt(e){return e.numPrFromStyle!=null&&e.numPr!=null&&JSON.stringify(e.numPr)===JSON.stringify(e.numPrFromStyle)}function ot(e){if(e._originalFormatting){let n=e._originalFormatting,r={...n};return e.alignment!==(n.alignment||void 0)&&(r.alignment=e.alignment||void 0),tt(e)?(delete r.numPr,delete r.numPrFromStyle):e.numPr!==n.numPr&&JSON.stringify(e.numPr)!==JSON.stringify(n.numPr)&&(r.numPr=e.numPr||void 0,delete r.numPrFromStyle),e.styleId!==(n.styleId||void 0)&&(r.styleId=e.styleId||void 0),e.pageBreakBefore!==(n.pageBreakBefore||void 0)&&(r.pageBreakBefore=e.pageBreakBefore||void 0),e.widowControl!==(n.widowControl??void 0)&&(r.widowControl=e.widowControl??void 0),e.bidi!==(n.bidi||void 0)&&(r.bidi=e.bidi||void 0),r}if(e.alignment||e.spaceBefore||e.spaceAfter||e.lineSpacing||e.indentLeft||e.indentRight||e.indentFirstLine||e.numPr||e.styleId||e.borders||e.shading||e.tabs||e.outlineLevel!=null||e.contextualSpacing||e.pageBreakBefore||e.widowControl!=null||e.bidi)return {alignment:e.alignment||void 0,spaceBefore:e.spaceBefore||void 0,spaceAfter:e.spaceAfter||void 0,lineSpacing:e.lineSpacing||void 0,lineSpacingRule:e.lineSpacingRule||void 0,indentLeft:e.indentLeft||void 0,indentRight:e.indentRight||void 0,indentFirstLine:e.indentFirstLine||void 0,hangingIndent:e.hangingIndent||void 0,numPr:tt(e)?void 0:e.numPr||void 0,styleId:e.styleId||void 0,borders:e.borders||void 0,shading:e.shading||void 0,tabs:e.tabs||void 0,outlineLevel:e.outlineLevel??void 0,contextualSpacing:e.contextualSpacing||void 0,pageBreakBefore:e.pageBreakBefore||void 0,widowControl:e.widowControl??void 0,bidi:e.bidi||void 0}}function it(e){if(e._originalFormatting){let n=e._originalFormatting,r={...n};return e.styleId!==(n.styleId||void 0)&&(r.styleId=e.styleId||void 0),e.justification!==(n.justification||void 0)&&(r.justification=e.justification||void 0),e.floating!==(n.floating||void 0)&&(r.floating=e.floating||void 0),e.tableLayout!==(n.layout||void 0)&&(r.layout=e.tableLayout||void 0),e.look!==(n.look||void 0)&&(r.look=e.look||void 0),e.bidi!==(n.bidi||void 0)&&(r.bidi=e.bidi||void 0),(e.width!==n.width?.value||e.widthType!==n.width?.type)&&(r.width=e.width!=null||e.widthType?{value:e.width??0,type:e.widthType||"dxa"}:void 0),e.cellMargins&&(r.cellMargins=nt(e.cellMargins)),r}if(e.styleId||e.width!=null||e.widthType||e.justification||e.tableLayout||e.floating||e.cellMargins||e.look||e.bidi)return {styleId:e.styleId||void 0,width:e.width!=null||e.widthType?{value:e.width??0,type:e.widthType||"dxa"}:void 0,justification:e.justification||void 0,layout:e.tableLayout||void 0,floating:e.floating||void 0,cellMargins:e.cellMargins?nt(e.cellMargins):void 0,look:e.look||void 0,bidi:e.bidi||void 0}}function nt(e){return {top:e.top!=null?{value:e.top,type:"dxa"}:void 0,bottom:e.bottom!=null?{value:e.bottom,type:"dxa"}:void 0,left:e.left!=null?{value:e.left,type:"dxa"}:void 0,right:e.right!=null?{value:e.right,type:"dxa"}:void 0}}function st(e){if(e._originalFormatting){let t=e._originalFormatting,n={...t};return e.height!==(t.height?.value||void 0)&&(n.height=e.height?{value:e.height,type:"dxa"}:void 0),e.heightRule!==(t.heightRule||void 0)&&(n.heightRule=e.heightRule||void 0),e.isHeader!==(t.header||void 0)&&(n.header=e.isHeader||void 0),n}if(!(!e.height&&!e.isHeader))return {height:e.height?{value:e.height,type:"dxa"}:void 0,heightRule:e.heightRule||void 0,header:e.isHeader||void 0}}function lt(e){if(e._originalFormatting){let n=e._originalFormatting,r={...n};return e.colspan>1&&(r.gridSpan=e.colspan),e.width!=null&&(r.width={value:e.width,type:e.widthType||"dxa"}),e.verticalAlign!==(n.verticalAlign||void 0)&&(r.verticalAlign=e.verticalAlign||void 0),e.backgroundColor?r.shading=e._originalResolvedFill===e.backgroundColor&&n.shading?n.shading:{fill:{rgb:e.backgroundColor}}:n.shading&&(r.shading=void 0),e.borders&&(r.borders=e.borders),e.margins&&(r.margins=rt(e.margins)),e.textDirection!==(n.textDirection||void 0)&&(r.textDirection=e.textDirection||void 0),r}if(e.colspan>1||e.rowspan>1||e.width!=null||e.verticalAlign||e.backgroundColor||e.borders||e.margins||e.textDirection)return {gridSpan:e.colspan>1?e.colspan:void 0,width:e.width!=null?{value:e.width,type:e.widthType||"dxa"}:void 0,verticalAlign:e.verticalAlign||void 0,textDirection:e.textDirection||void 0,shading:e.backgroundColor?{fill:{rgb:e.backgroundColor}}:void 0,borders:e.borders,margins:e.margins?rt(e.margins):void 0}}function rt(e){let t={};return e.top!=null&&(t.top={value:e.top,type:"dxa"}),e.bottom!=null&&(t.bottom={value:e.bottom,type:"dxa"}),e.left!=null&&(t.left={value:e.left,type:"dxa"}),e.right!=null&&(t.right={value:e.right,type:"dxa"}),t}var dn={paraId:null,textId:null,alignment:null,spaceBefore:null,spaceAfter:null,lineSpacing:null,lineSpacingRule:null,spacingExplicit:null,indentLeft:null,indentRight:null,indentFirstLine:null,hangingIndent:false,numPr:null,numPrFromStyle:null,listNumFmt:null,listIsBullet:null,listMarker:null,listMarkerHidden:null,listMarkerFontFamily:null,listMarkerFontSize:null,listMarkerSuffix:null,listLevelNumFmts:null,listAbstractNumId:null,listStartOverride:null,styleId:null,borders:null,shading:null,tabs:null,pageBreakBefore:null,renderedPageBreakBefore:null,keepNext:null,keepLines:null,widowControl:null,contextualSpacing:null,defaultTextFormatting:null,sectionBreakType:null,bidi:null,outlineLevel:null,bookmarks:null,_originalFormatting:null,_originalRunBoundaries:null,_sectionProperties:null,pPrIns:null,pPrDel:null,pPrChange:null},un={styleId:null,width:null,widthType:null,justification:null,columnWidths:null,tableLayout:null,floating:null,cellMargins:null,look:null,bidi:null,_originalFormatting:null,tblPrChange:null},cn={height:null,heightRule:null,isHeader:false,_originalFormatting:null,trIns:null,trDel:null,trPrChange:null},pn={colspan:1,rowspan:1,colwidth:null,width:null,widthType:null,verticalAlign:null,backgroundColor:null,borders:null,margins:null,textDirection:null,noWrap:false,_originalFormatting:null,_originalResolvedFill:null,cellMarker:null,tcPrChange:null},fn=new Set(["bold","italic","superscript","subscript","allCaps","smallCaps","emboss","imprint","textShadow","textOutline","hidden","rtl"]);function x(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function N(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function S(e){return typeof e=="string"?e:void 0}function ie(e){if(Array.isArray(e))return e.map(ie);let t=x(e);if(!t)return e;let n={};for(let[r,o]of Object.entries(t))o!=null&&(n[r]=ie(o));return n}function Z(e){if(e==null)return "null";if(Array.isArray(e))return `[${e.map(Z).join(",")}]`;let t=x(e);return t?`{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${Z(t[n])}`).join(",")}}`:JSON.stringify(e)}function Q(e){let t={...e};return delete t.hyperlink,delete t.ins,delete t.del,t}function le(e){let t={};e.bold&&(t.bold=true,t.boldCs=true),e.italic&&(t.italic=true,t.italicCs=true);let n=x(e.underline);n&&(t.underline={style:S(n.style)||"single",color:x(n.color)??null});let r=x(e.strike);r&&(r.double?t.doubleStrike=true:t.strike=true);let o=x(e.textColor);o&&(t.color={rgb:S(o.rgb)??null,themeColor:o.themeColor??null,themeTint:S(o.themeTint)??null,themeShade:S(o.themeShade)??null}),typeof e.highlight=="string"&&(t.highlight=e.highlight);let l=x(e.fontSize);if(l){let m=N(l.size),y=N(l.sizeCs)??m;m!==void 0&&(t.fontSize=m),y!==void 0&&(t.fontSizeCs=y);}let s=x(e.fontFamily);if(s){let m=S(s.ascii);t.fontFamily={ascii:m??null,hAnsi:S(s.hAnsi)??null,eastAsia:S(s.eastAsia),cs:S(s.cs)||m,asciiTheme:s.asciiTheme??null,hAnsiTheme:S(s.hAnsiTheme),eastAsiaTheme:S(s.eastAsiaTheme),csTheme:S(s.csTheme)};}e.superscript&&(t.vertAlign="superscript"),e.subscript&&(t.vertAlign="subscript"),e.allCaps&&(t.allCaps=true),e.smallCaps&&(t.smallCaps=true);let d=x(e.characterSpacing);if(d){let m=N(d.spacing),y=N(d.position),b=N(d.scale),R=N(d.kerning);m!==void 0&&(t.spacing=m),y!==void 0&&(t.position=y),b!==void 0&&(t.scale=b),R!==void 0&&(t.kerning=R);}e.emboss&&(t.emboss=true),e.imprint&&(t.imprint=true),e.textShadow&&(t.shadow=true);let a=x(e.emphasisMark);a&&(t.emphasisMark=S(a.type)||"dot"),e.textOutline&&(t.outline=true),e.hidden&&(t.hidden=true),e.rtl&&(t.rtl=true);let f=x(e.textEffect);f&&(t.effect=S(f.effect)||"blinkBackground");let p=x(e.modernTextEffects);p?.effects&&(t.modernEffects=p.effects);let c=x(e.runStyle),g=S(c?.styleId);return g&&(t.styleId=g),t}function ct(e,t){let n=[],r="",o=()=>{r&&(n.push({type:"text",text:r}),r="");},l=t.fontFamily?[t.fontFamily.ascii,t.fontFamily.hAnsi,t.fontFamily.eastAsia,t.fontFamily.cs].filter(d=>!!d):[],s=l.length>0&&l.every(d=>d===l[0])?l[0]:null;for(let d of e){let a=d.codePointAt(0)??0;d==="\xAD"?(o(),n.push({type:"softHyphen"})):d==="\u2011"?(o(),n.push({type:"noBreakHyphen"})):s&&a>=61440&&a<=63743?(o(),n.push({type:"symbol",font:s,char:a.toString(16).toUpperCase().padStart(4,"0")})):r+=d;}return o(),n}function xe(e,t){let n=le(Q(t));return {type:"run",formatting:Object.keys(n).length>0?n:void 0,content:ct(e,n)}}function gn(e,t){for(let n of t.content){let r=e.content[e.content.length-1];r?.type==="text"&&n.type==="text"?r.text+=n.text:e.content.push(n);}}function mn(e){let t=0xcbf29ce484222325n;for(let n of new TextEncoder().encode(e))t=(t^BigInt(n))*0x100000001b3n,t&=0xffffffffffffffffn;return Number(t&(1n<<53n)-1n)}function Te(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){let t=Number(e);return Number.isFinite(t)?t:mn(e)}return 0}function V(e,t=false){let n=x(e);if(!n)return null;let r=S(n.author)||"Unknown",o=S(n.date);return {id:Te(n.revisionId??n.id),author:r,...o?{date:o}:{}}}function hn(e){let t=x(e.hyperlink);if(!t)return null;let n=S(t.href)||"";return n.startsWith("#")?{type:"hyperlink",anchor:n.slice(1),tooltip:S(t.tooltip)||void 0,children:[]}:{type:"hyperlink",href:n,tooltip:S(t.tooltip)||void 0,rId:S(t.rId)||void 0,children:[]}}function yn(e){let t=x(e.hyperlink);return t?S(t.href)||"":null}function pt(e,t){let n=S(e.fieldData);if(n&&n.length<=2e6)try{let p=JSON.parse(n),c=p.type==="simpleField"?p.content:p.fieldResult;if((p.type==="simpleField"||p.type==="complexField")&&typeof p.instruction=="string"&&Array.isArray(c)){let g=S(e.displayMode);return p.fieldTree&&g&&(p.fieldTree.displayMode=g),p}}catch{}let r=le(Q(t)),o={type:"run",content:[{type:"text",text:S(e.displayText)||""}],...Object.keys(r).length>0?{formatting:r}:{}},l=S(e.instruction)||"",s=S(e.fieldType)||"UNKNOWN",d=e.fldLock===true||void 0,a=e.dirty===true||void 0,f=S(e.displayMode)||"result";return e.fieldKind==="complex"?{type:"complexField",instruction:l,fieldType:s,fieldCode:[],fieldResult:[o],fldLock:d,dirty:a,fieldTree:{version:1,displayMode:f}}:{type:"simpleField",instruction:l,fieldType:s,content:[o],fldLock:d,dirty:a,fieldTree:{version:1,displayMode:f}}}function ft(e){return {type:"mathEquation",display:S(e.display)||"inline",ommlXml:S(e.ommlXml)||"",plainText:S(e.plainText)||void 0}}function gt(e){let t=e,n={type:S(t.wrapType)||"inline"};t.distTop!==void 0&&(n.distT=c$2(Number(t.distTop))),t.distBottom!==void 0&&(n.distB=c$2(Number(t.distBottom))),t.distLeft!==void 0&&(n.distL=c$2(Number(t.distLeft))),t.distRight!==void 0&&(n.distR=c$2(Number(t.distRight))),t.wrapText&&(n.wrapText=t.wrapText);let r={type:"image",rId:S(t.rId)||"",src:S(t.src)||"",alt:S(t.alt)||void 0,title:S(t.title)||void 0,size:{width:c$2(Number(t.width)||0),height:c$2(Number(t.height)||0)},wrap:n};if(t.transform){let s={},d=t.transform.match(/rotate\(([-\d.]+)deg\)/)?.[1];d&&(s.rotation=Number.parseFloat(d)),t.transform.includes("scaleX(-1)")&&(s.flipH=true),t.transform.includes("scaleY(-1)")&&(s.flipV=true),(s.rotation||s.flipH||s.flipV)&&(r.transform=s);}if(t.position?.horizontal&&t.position.vertical&&(r.position={horizontal:{relativeTo:t.position.horizontal.relativeTo||"column",alignment:t.position.horizontal.align,posOffset:t.position.horizontal.posOffset},vertical:{relativeTo:t.position.vertical.relativeTo||"paragraph",alignment:t.position.vertical.align,posOffset:t.position.vertical.posOffset}}),t.borderWidth&&t.borderWidth>0){let s={solid:"solid",dotted:"dot",dashed:"dash",double:"solid",groove:"solid",ridge:"solid",inset:"solid",outset:"solid"};r.outline={width:c$2(t.borderWidth),color:t.borderColor?{rgb:t.borderColor.replace("#","")}:void 0,style:t.borderStyle&&s[t.borderStyle]||"solid"};}t.hlinkHref&&(r.hlinkHref=t.hlinkHref);let o={};t.cropTop!=null&&(o.top=t.cropTop),t.cropRight!=null&&(o.right=t.cropRight),t.cropBottom!=null&&(o.bottom=t.cropBottom),t.cropLeft!=null&&(o.left=t.cropLeft),Object.keys(o).length>0&&(r.crop=o),t.opacity!=null&&t.opacity<1&&(r.opacity=t.opacity),t.layoutInCell!=null&&(r.layoutInCell=t.layoutInCell),t.allowOverlap!=null&&(r.allowOverlap=t.allowOverlap);let l={};return t.effectExtentTop&&(l.top=c$2(t.effectExtentTop)),t.effectExtentBottom&&(l.bottom=c$2(t.effectExtentBottom)),t.effectExtentLeft&&(l.left=c$2(t.effectExtentLeft)),t.effectExtentRight&&(l.right=c$2(t.effectExtentRight)),Object.keys(l).length>0&&(r.padding=l),{type:"run",content:[{type:"drawing",image:r}]}}function bn(e){let t=S(e);if(!(!t||t.length>2e6))try{let n=JSON.parse(t);return n?.type!=="shape"||typeof n.shapeType!="string"?void 0:(x(n.size)||(n.size={width:0,height:0}),n)}catch{return}}function mt(e){let t=bn(e.shapeJson)??{type:"shape",shapeType:"rect",size:{width:0,height:0}},n=S(e.shapeType);n&&(t.shapeType=n);let r=S(e.shapeId);if(r&&(t.id=r),e.width&&(t.size={...t.size,width:c$2(Number(e.width))}),e.height&&(t.size={...t.size,height:c$2(Number(e.height))}),Array.isArray(e.geometryPath)&&e.geometryPath.length>0&&(t.geometryPath=e.geometryPath),e.fillType==="gradient"&&typeof e.gradientStops=="string")try{let l=JSON.parse(e.gradientStops);t.fill={type:"gradient",gradient:{type:S(e.gradientType)||"linear",angle:N(e.gradientAngle)||void 0,stops:l.map(s=>({position:s.position,color:{rgb:s.color.replace("#","")}}))}};}catch{t.fill={type:"solid",color:{rgb:(S(e.fillColor)||"000000").replace("#","")}};}else typeof e.fillColor=="string"?t.fill={type:S(e.fillType)||"solid",color:{rgb:e.fillColor.replace("#","")}}:e.fillType==="none"&&(t.fill={type:"none"});if(typeof e.outlineWidth=="number"&&e.outlineWidth>0){let l={solid:"solid",dotted:"dot",dashed:"dash"},s=S(e.outlineStyle);t.outline={width:c$2(e.outlineWidth),color:typeof e.outlineColor=="string"?{rgb:e.outlineColor.replace("#","")}:void 0,style:s&&l[s]||"solid"};}let o={};if(typeof e.rotation=="number")o.rotation=e.rotation;else if(typeof e.transform=="string"){let l=e.transform.match(/rotate\(([-\d.]+)deg\)/)?.[1];l&&(o.rotation=Number.parseFloat(l));}return (e.flipH||String(e.transform||"").includes("scaleX(-1)"))&&(o.flipH=true),(e.flipV||String(e.transform||"").includes("scaleY(-1)"))&&(o.flipV=true),(o.rotation||o.flipH||o.flipV)&&(t.transform=o),{type:"run",content:[{type:"shape",shape:t}]}}function kn(e){let t=ce(e),n=S(e.propertiesJson);if(n&&n.length<=1e6)try{let s=JSON.parse(n);s&&typeof s=="object"&&typeof s.sdtType=="string"&&(t=s);}catch{}let r=[];for(let s of Array.isArray(e.content)?e.content:[]){let d=x(s),a=S(d?.kind);if(!d||!a)continue;let f=x(d.attrs)??{};if(a==="text"){let p=S(d.text);p!==void 0&&r.push({kind:"text",text:p,attributes:f});continue}r.push({kind:"embed",embedKind:a,payload:x(d.payload)??{},attributes:f});}let o=at(Ce(r)),l=ht(e.value);if(l)try{let s=Re(t,l);t=s.properties;let d=s.content[0];o=at(d?.type==="paragraph"?d.content:[]);}catch{}return {type:"inlineSdt",properties:t,content:o}}function at(e){return e.filter(t=>t.type==="run"||t.type==="hyperlink"||t.type==="simpleField"||t.type==="complexField"||t.type==="inlineSdt"||t.type==="mathEquation")}function ht(e){let t=x(e);return t?.kind==="checkbox"&&typeof t.checked=="boolean"?{kind:"checkbox",checked:t.checked}:t?.kind==="dropdown"&&typeof t.value=="string"?{kind:"dropdown",value:t.value}:t?.kind==="date"&&typeof t.date=="string"?{kind:"date",date:t.date}:null}function yt(e){if(e.modelKind!=="commentReference")return null;let t=N(e.commentId);return {type:"run",content:[{type:"commentReference",...t!==void 0?{id:t}:{}}]}}function dt(e){if(e.kind==="text")return xe(e.text,e.attributes);switch(e.embedKind){case "break":return {type:"run",content:[{type:"break",breakType:"textWrapping"}]};case "tab":return {type:"run",content:[{type:"tab"}]};case "image":return gt(e.payload);case "shape":return mt(e.payload);case "field":return yt(e.payload)??pt(e.payload,e.attributes);case "math":return ft(e.payload);case "sdt":return kn(e.payload);case "noteRef":{let t=e.payload.footnoteRefId,n=e.payload.endnoteRefId;return {type:"run",content:[t!==void 0?{type:"footnoteRef",id:Te(t)}:{type:"endnoteRef",id:Te(n)}]}}default:return null}}function Sn(e,t){let n;if(e.kind==="embed"&&e.embedKind==="image")n=gt(e.payload);else if(e.kind==="embed"&&e.embedKind==="shape")n=mt(e.payload);else if(e.kind==="text"){let l=le(Q(e.attributes));n={type:"run",content:[{type:"text",text:e.text}],...Object.keys(l).length>0?{formatting:l}:{}};}else n={type:"run",content:[]};let o=(x(e.attributes.ins)??x(e.attributes.del))?.isMovePair===true;return e.attributes.ins?o?{type:"moveTo",info:t,content:[n]}:{type:"insertion",info:t,content:[n]}:o?{type:"moveFrom",info:t,content:[n]}:{type:"deletion",info:t,content:[n]}}function Rn(e,t){if(t.kind==="text"){e.children.push(xe(t.text,t.attributes));return}if(t.embedKind==="break")e.children.push({type:"run",content:[{type:"break",breakType:"textWrapping"}]});else if(t.embedKind==="tab")e.children.push({type:"run",content:[{type:"tab"}]});else if(t.embedKind==="field"){let n=yt(t.payload)??pt(t.payload,t.attributes);n.type==="run"?e.children.push(n):(e.structuredChildren??(e.structuredChildren=[...e.children])).push(n);}else t.embedKind==="math"&&(e.structuredChildren??(e.structuredChildren=[...e.children])).push(ft(t.payload));}function Ce(e){let t=[],n=null,r=null,o=null,l=()=>{n&&t.push(n),n=null,r=null;},s=()=>{o&&t.push(o),o=null;};for(let d of e){if(d.kind==="embed"&&d.embedKind==="noteRef"){l(),s();let c=dt(d);c&&t.push(c);continue}let a=V(d.attributes.ins??d.attributes.del);if(a){l(),s(),t.push(Sn(d,a));continue}let f=yn(d.attributes);if(f!==null){l();let c=o?o.href||(o.anchor?`#${o.anchor}`:""):null;(!o||c!==f)&&(s(),o=hn(d.attributes)),o&&Rn(o,d);continue}if(s(),d.kind==="text"){let c=Z(Q(d.attributes)),g=xe(d.text,d.attributes);n&&r===c?gn(n,g):(l(),n=g,r=c);continue}l();let p=dt(d);p&&t.push(p);}return l(),s(),t}function Tn(e){if(!e)return {};let t={};for(let n of e.split("|")){let r=n.indexOf(":");if(r<=0)return null;let o=n.slice(0,r),l;try{l=JSON.parse(n.slice(r+1));}catch{return null}o==="comment"||o==="footnoteRef"||(fn.has(o)?t[o]=true:o==="highlight"?t.highlight=l.color:o==="insertion"||o==="deletion"?t[o==="insertion"?"ins":"del"]=ie({id:l.revisionId,author:l.author,date:l.date,isMovePair:l.isMovePair}):t[o]=ie(l));}return t}function wn(e){return e.noteMarks?.length?e.noteMarks.map(t=>({type:t==="endnote"?"endnoteRefMark":"footnoteRefMark"})):null}function xn(e,t,n){if(!n?.length||!e.every(d=>d.type==="run"&&d.content.every(a=>a.type==="text"))||t.some(d=>d.kind!=="text"||d.attributes.hyperlink)||n.some(d=>d.noteMarks?.length&&d.text.length>0)||t.map(d=>d.kind==="text"?d.text:"").join("")!==n.map(d=>d.text).join(""))return e;let o=0,l=0,s=[];for(let d of n){let a=Tn(d.marksKey);if(!a)return e;s.push(a);let f=d.text.length;for(;f>0;){let p=t[o];if(p?.kind!=="text"||Z(Q(p.attributes))!==Z(a))return e;let c=p.text.length-l,g=Math.min(f,c);f-=g,l+=g,l===p.text.length&&(o+=1,l=0);}}return o!==t.length||l!==0?e:n.map((d,a)=>{let f=d.text.length===0?d.formatting:le(s[a]),p={type:"run",content:wn(d)??ct(d.text,f??{})};return f&&Object.keys(f).length>0&&(p.formatting=f),d.propertyChanges?.length&&(p.propertyChanges=d.propertyChanges),p})}function oe(e){return e.content.reduce((t,n)=>n.type==="text"||n.type==="instrText"?t+n.text.length:n.type==="symbol"?t+n.char.length:n.type==="tab"||n.type==="softHyphen"||n.type==="noBreakHyphen"||n.type==="footnoteRef"||n.type==="endnoteRef"?t+1:t,0)}function se(e){switch(e.type){case "run":return oe(e);case "hyperlink":return e.children.reduce((t,n)=>t+(n.type==="run"?oe(n):0),0);case "simpleField":return e.content.reduce((t,n)=>t+se(n),0);case "complexField":return e.fieldResult.reduce((t,n)=>t+oe(n),0);case "inlineSdt":return e.content.reduce((t,n)=>t+se(n),0);case "insertion":case "deletion":case "moveFrom":case "moveTo":return e.content.reduce((t,n)=>t+(n.type==="run"?oe(n):0),0);case "mathEquation":return e.plainText?.length??0;default:return 0}}function Cn(e,t){if(!e.content.every(o=>o.type==="text"))return [e,null];let n=e.content.map(o=>o.type==="text"?o.text:"").join(""),r=o=>o?{type:"run",...e.formatting?{formatting:e.formatting}:{},...e.propertyChanges?{propertyChanges:e.propertyChanges}:{},content:[{type:"text",text:o}]}:null;return [r(n.slice(0,t)),r(n.slice(t))]}function ut(e,t,n=r=>r.kind==="start"?{type:"commentRangeStart",id:r.id}:{type:"commentRangeEnd",id:r.id}){if(t.length===0)return e;let r=[...t].sort((a,f)=>a.offset-f.offset||(a.kind===f.kind?a.id-f.id:a.kind==="end"?-1:1)),o=[],l=0,s=0,d=a=>{for(;s<r.length&&r[s].offset===a;){let f=r[s++];o.push(n(f));}};d(0);for(let a of e){let f=se(a),p=r.slice(s).map(c=>c.offset).filter(c=>c>l&&c<l+f);if(a.type==="run"&&a.content.every(c=>c.type==="text")){let c=a,g=0;for(let m of p){if(!c)break;let[y,b]=Cn(c,m-l-g);y&&o.push(y),d(m),c=b,g=m-l;}c&&o.push(c);}else o.push(a);l+=f,d(l);}return d(l),o}function Pn(e){if(!Array.isArray(e.bookmarks))return [];let t=[];for(let n of e.bookmarks){let r=x(n),o=N(r?.id);if(!r||o===void 0)continue;let l=N(r.offset)??0,s={name:S(r.name),colFirst:N(r.colFirst),colLast:N(r.colLast)};r.kind==="start"?t.push({id:o,kind:"start",offset:l,...s}):r.kind==="end"?t.push({id:o,kind:"end",offset:l,...s}):(t.push({id:o,kind:"start",offset:0,...s}),t.push({id:o,kind:"end",offset:Number.MAX_SAFE_INTEGER,...s}));}return t}function In(e){let t={...dn,...e};return t.styleId=e.pStyle??null,t._sectionProperties=e.sectPr??null,delete t.pStyle,delete t.sectPr,t}function vn(e,t,n,r,o){let l=In(t),s=Ce(n);s=xn(s,n,Array.isArray(l._originalRunBoundaries)?l._originalRunBoundaries:void 0),s=ut(s,r);let d=Pn(t).map(c=>({...c,offset:c.offset===Number.MAX_SAFE_INTEGER?s.reduce((g,m)=>g+se(m),0):c.offset}));d.length>0&&(s=ut(s,d,c=>{let g=c;return g.kind==="start"?{type:"bookmarkStart",id:g.id,name:g.name||"",...g.colFirst!==void 0?{colFirst:g.colFirst}:{},...g.colLast!==void 0?{colLast:g.colLast}:{},position:{offset:g.offset}}:{type:"bookmarkEnd",id:g.id,position:{offset:g.offset}}}));let a={type:"paragraph",paraId:e||void 0,textId:o?.textId,formatting:ot(l),content:s};o?.renderedPageBreakBefore&&(a.renderedPageBreakBefore=true);let f=V(t.pPrIns,true),p=V(t.pPrDel,true);return f&&(a.pPrIns=f),p&&(a.pPrDel=p),Array.isArray(t.pPrChange)&&t.pPrChange.length>0&&(a.propertyChanges=t.pPrChange),t.sectPr?a.sectionProperties=t.sectPr:t.sectionBreakType&&(a.sectionProperties={sectionStart:t.sectionBreakType}),a}function An(e){let t=e[0]?.cells,n=e[e.length-1]?.cells,r=t?.[0]?.formatting?.borders;if(!t||!n||!r)return;let o={top:r.top,left:r.left,bottom:n[0]?.formatting?.borders?.bottom,right:t[t.length-1]?.formatting?.borders?.right,insideH:e.length>1?r.bottom:void 0,insideV:t.length>1?r.right:void 0},l=Object.entries(o).filter(([,s])=>s!==void 0);return l.length>0?Object.fromEntries(l):void 0}function Fn(e){let t=new Map;e.forEach((r,o)=>{let l=0;for(let s of r.cells){let d=l;if(l+=s.formatting?.gridSpan??1,s.formatting?.vMerge){let a=t.get(d)??[];a.push({rowIndex:o,cell:s}),t.set(d,a);}}});let n=r=>{r.formatting&&(delete r.formatting.vMerge,Object.keys(r.formatting).length===0&&(r.formatting=void 0));};for(let r of t.values()){let o=null,l=0,s=-1,d=()=>{o&&l<2&&n(o),o=null,l=0;};for(let a of r){let f=a.cell.formatting?.vMerge;f==="restart"?(d(),o=a.cell,l=1,s=a.rowIndex):f==="continue"&&(o&&a.rowIndex===s+1?(l+=1,s=a.rowIndex):(d(),n(a.cell)));}d();}}function Yn(e,t){let n={...pn,...t.tcPr??{}},r=t.story&&e.storyIds.has(t.story)?e.storyToBlocks(t.story).filter(s=>s.type==="paragraph"||s.type==="table"):[],o={type:"tableCell",formatting:lt(n),content:r},l=n.cellMarker;if(l){let s=V(l.info,true)??{id:0,author:"Unknown"};l.kind==="ins"?o.structuralChange={type:"tableCellInsertion",info:s}:l.kind==="del"?o.structuralChange={type:"tableCellDeletion",info:s}:o.structuralChange={type:"tableCellMerge",info:s,...l.vMerge?{vMerge:l.vMerge}:{},...l.vMergeOrig?{vMergeOrig:l.vMergeOrig}:{}};}return Array.isArray(n.tcPrChange)&&n.tcPrChange.length>0&&(o.propertyChanges=n.tcPrChange),o}function Mn(e,t){let n=Array.isArray(t.rows)?t.rows:[],r=[],o=[],l=0;n.forEach((m,y)=>{let b=0;for(let R of Array.isArray(m.cells)?m.cells:[]){for(;r[y]?.[b];)b+=1;let w=R.tcPr??{},I=N(w.rowspan)||1,P=N(w.colspan)||1;o.push({row:y,col:b,rowspan:I,colspan:P,cell:Yn(e,R)});for(let A=y;A<y+I;A+=1){r[A]??(r[A]=[]);for(let F=b;F<b+P;F+=1)r[A][F]=true;}b+=P,l=Math.max(l,b);}});let s=new Map(o.map(m=>[`${m.row}-${m.col}`,m])),d=new Map;for(let m of o)for(let y=m.row;y<m.row+m.rowspan;y+=1)for(let b=m.col;b<m.col+m.colspan;b+=1)d.set(`${y}-${b}`,m);let a=n.map((m,y)=>{let b=[];for(let A=0;A<l;){let F=s.get(`${y}-${A}`);if(F){let E={...F.cell.formatting??{}};F.colspan>1?E.gridSpan=F.colspan:delete E.gridSpan,F.rowspan>1?E.vMerge="restart":E.vMerge!=="restart"&&E.vMerge!=="continue"&&delete E.vMerge,b.push({...F.cell,formatting:Object.keys(E).length>0?E:void 0}),A+=F.colspan;continue}let D=d.get(`${y}-${A}`);if(!D){A+=1;continue}let H={...D.cell.formatting??{}};D.colspan>1?H.gridSpan=D.colspan:delete H.gridSpan,H.vMerge="continue",b.push({...D.cell,content:[],formatting:H}),A+=D.colspan;}let R={...cn,...m.trPr??{}},w={type:"tableRow",formatting:st(R),cells:b},I=V(R.trIns,true),P=V(R.trDel,true);return I?w.structuralChange={type:"tableRowInsertion",info:I}:P&&(w.structuralChange={type:"tableRowDeletion",info:P}),Array.isArray(R.trPrChange)&&R.trPrChange.length>0&&(w.propertyChanges=R.trPrChange),w});Fn(a);let f=Array.isArray(t.grid)?t.grid.filter(m=>typeof m=="number"):[],p={...un,...t.tblPr??{},columnWidths:f.length>0?f:void 0},c=it(p);if(!c?.borders){let m=An(a);m&&(c={...c??{},borders:m});}let g={type:"table",columnWidths:p.columnWidths||void 0,formatting:c,rows:a};return Array.isArray(p.tblPrChange)&&p.tblPrChange.length>0&&(g.propertyChanges=p.tblPrChange),g}function _n(){return {type:"paragraph",content:[{type:"run",content:[{type:"break",breakType:"page"}]}]}}function Pe(e){return e.type==="insertion"||e.type==="deletion"||e.type==="moveFrom"||e.type==="moveTo"?e.content.length>0&&e.content.every(Pe):e.type==="run"&&e.content.length>0&&e.content.every(t=>t.type==="footnoteRefMark"||t.type==="endnoteRefMark")}function Bn(e){return e.some(t=>t.type==="paragraph"&&t.content.some(Pe))}function Nn(e,t){if(Bn(e))return e;let n=t.find(a=>a.type==="paragraph")?.content??[],r=n.findIndex(a=>!Pe(a)),o=n.slice(0,r<0?n.length:r);if(o.length===0)return e;let l=e.findIndex(a=>a.type==="paragraph");if(l<0)return e;let s=e[l],d=[...e];return d[l]={...s,content:[...o,...s.content]},d}function On(e){let t=new Map,n=r=>{for(let o of r)if(o.type==="paragraph")o.paraId&&!t.has(o.paraId)&&t.set(o.paraId,o);else if(o.type==="table")for(let l of o.rows)for(let s of l.cells)n(s.content);else n(o.content);};n(e.package.document.content);for(let r of e.package.headers?.values()??[])n(r.content);for(let r of e.package.footers?.values()??[])n(r.content);for(let r of e.package.footnotes??[])n(r.content);for(let r of e.package.endnotes??[])n(r.content);return t}function En(e){let t=new Map,n=(r,o)=>{t.set(r,o);let l=0;for(let s of o){if(s.type!=="table")continue;let d=l++;s.rows.forEach((a,f)=>{a.cells.forEach((p,c)=>{n(`${r}:t${d}:r${f}c${c}`,p.content);});});}};n("body",e.package.document.content);for(let[r,o]of e.package.headers??[])n(`hf:${r}`,o.content);for(let[r,o]of e.package.footers??[])n(`hf:${r}`,o.content);for(let r of e.package.footnotes??[])n(`fn:${r.id}`,r.content);for(let r of e.package.endnotes??[])n(`en:${r.id}`,r.content);return t}function Ln(e,t){let n=new Map;for(let r of t??[]){let o;try{o=e.resolveComment(String(r.id));}catch{continue}let l=new Map;for(let s of o){let d=l.get(s.story)??[];d.push(s),l.set(s.story,d);}for(let[s,d]of l){if(d.length===0)continue;let a=Math.min(...d.map(c=>c.start)),f=Math.max(...d.map(c=>c.end)),p=n.get(s)??[];p.push({id:r.id,start:a,end:f}),n.set(s,p);}}return n}var we=class{constructor(t,n){b(this,"session",t);b(this,"storyIds");b(this,"baseParagraphs");b(this,"baseStories");b(this,"comments");this.storyIds=new Set(t.storyIds()),this.baseParagraphs=On(n),this.baseStories=En(n),this.comments=Ln(t,n.package.document.comments);}storyToBlocks(t){let n=[],r=this.baseStories.get(t),o=this.session.storySegments(t),l=this.comments.get(t)??[],s=[],d=0,a=0,f=0,p=g=>{let m=[];for(let y of l)y.start>=d&&y.start<=g&&m.push({id:y.id,kind:"start",offset:y.start-d}),y.end>=d&&y.end<=g&&m.push({id:y.id,kind:"end",offset:y.end-d});return m},c=(g,m)=>{let y=0;for(let b=0;b<g.length;b+=1)g[b]===" "&&(b>y&&s.push({kind:"text",text:g.slice(y,b),attributes:m}),s.push({kind:"embed",embedKind:"tab",payload:{},attributes:m}),y=b+1);y<g.length&&s.push({kind:"text",text:g.slice(y),attributes:m});};for(let g of o){if(g.kind==="text"){c(g.text,g.attributes),f+=g.text.length;continue}if(g.kind==="pilcrow"){let m=`${t}:p${a}`,y=g.paraId===m&&!this.baseParagraphs.has(g.paraId)?"":g.paraId;n.push(vn(y,g.properties,s,p(f),this.baseParagraphs.get(g.paraId))),s=[],a+=1,f+=1,d=f;continue}if(g.embedKind==="table")n.push(Mn(this,g.payload));else if(g.embedKind==="blockSdt"){let m=S(g.payload.story),y=ce(g.payload),b=m&&this.storyIds.has(m)?this.storyToBlocks(m):[],R=ht(g.payload.value);if(R)try{let w=Re(y,R);y=w.properties,b=w.content;}catch{}n.push({type:"blockSdt",properties:y,content:b});}else if(g.embedKind==="opaque"){let m=x(g.payload.blob);if(m?.type==="pageBreak")n.push(_n());else {let y=r?.[n.length];m?.type==="blockSdt"&&y?.type==="blockSdt"&&n.push(y);}}else s.push(g);f+=1;}return s.length>0&&n.push({type:"paragraph",content:Ce(s)}),n}};function Dn(e,t,n={}){let r=new we(e,t),o=c=>n.storyIds===void 0||n.storyIds.has(c),l=r.storyIds.has("body")&&o("body")?r.storyToBlocks("body"):t.package.document.content,s=t.package.headers;s&&(n.storyIds===void 0||[...s.keys()].some(c=>o(`hf:${c}`)))&&(s=new Map([...s].map(([c,g])=>{let m=`hf:${c}`;return [c,r.storyIds.has(m)&&o(m)?{...g,content:r.storyToBlocks(m)}:g]})));let d=t.package.footers;d&&(n.storyIds===void 0||[...d.keys()].some(c=>o(`hf:${c}`)))&&(d=new Map([...d].map(([c,g])=>{let m=`hf:${c}`;return [c,r.storyIds.has(m)&&o(m)?{...g,content:r.storyToBlocks(m)}:g]})));let a=(c,g)=>n.storyIds===void 0||c?.some(y=>o(`${g}${y.id}`))?c?.map(y=>{let b=`${g}${y.id}`;return r.storyIds.has(b)&&o(b)?{...y,content:Nn(r.storyToBlocks(b),y.content),verbatimXml:void 0}:y}):c,f=a(t.package.footnotes,"fn:"),p=a(t.package.endnotes,"en:");return {...t,package:{...t.package,document:{...t.package.document,content:l},...s?{headers:s}:{},...d?{footers:d}:{},...f?{footnotes:f}:{},...p?{endnotes:p}:{}}}}function wr(e,t){return !e||!t?e===t:e.anchor.story===t.anchor.story&&e.anchor.paraId===t.anchor.paraId&&e.anchor.offset===t.anchor.offset&&e.head.story===t.head.story&&e.head.paraId===t.head.paraId&&e.head.offset===t.head.offset}function Jn(){if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function"){let e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return Math.floor(Math.random()*4294967295)}function bt(e){return JSON.stringify("revisionId"in e?{revisionId:e.revisionId}:{story:e.story,startPara:e.start.paraId,startOffset:e.start.offset,endPara:e.end.paraId,endOffset:e.end.offset})}function Un(e){return JSON.stringify(e.map(t=>({story:t.story,startPara:t.start.paraId,startOffset:t.start.offset,endPara:t.end.paraId,endOffset:t.end.offset})))}function kt(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.slice().buffer}function Wn(e,t){let n=JSON.parse(e);if(typeof n!="object"||n===null||Array.isArray(n))throw new TypeError("DOCX host metadata must be an object");let r=n;if(!Array.isArray(r.referencedFonts)||!r.referencedFonts.every(l=>typeof l=="string"))throw new TypeError("DOCX host referencedFonts must be a string array");let o=c$1(r.envelope,kt(t));return {document:o.document,referencedFonts:r.referencedFonts,embeddedFonts:o.embeddedFonts,...o.fontTableRelationshipsXml===void 0?{}:{fontTableRelationshipsXml:o.fontTableRelationshipsXml}}}function jn(e,t){let n=new Map,r=[],o=false,l=false,s=0,d=0,a=false,f=null,p,c=null,g=new Map,m=new Map,y=[],b=new Map,R=new Map,w=null,I=false,P=0,A=0,F=false,D=null,H=()=>{p=void 0,c=null;},E=()=>{if(!(l||a||d!==0)){a=true;try{for(;!l&&r.length>0;){let i=r.shift();if(!i)break;for(let[u,h]of [...n]){if(l)return;if(n.get(u)===h)try{h(i.update.slice(),i.origin);}catch{}}}}finally{a=false,l&&(r.length=0);}}},k=i=>{H(),d+=1;try{return i()}finally{d-=1,d===0&&E();}},Ie=i=>i?{anchor:{...i.anchor},head:{...i.head}}:null,C=i=>{f!==i&&(e.track_undo(i),f=i);},_=i=>{let u=`table:${i}`;f!==u&&(e.track_table_undo(i),f=u);},St=i=>{let u=h=>typeof h=="string"&&h===i||typeof h=="number"&&Number.isFinite(h)&&String(h)===i;for(let h of e.story_ids())if(JSON.parse(e.story_segments(h)).some(B=>B.kind==="embed"&&(u(B.payload.embedId)||u(B.payload.id)||u(B.payload.rId))))return h;return null},ae=i=>{let u=St(i);u&&C(u);},Rt=()=>{o||(e.set_update_observer((i,u)=>{u!==0&&u!==1||(r.push({update:i.slice(),origin:u===0?"local":"remote"}),E());}),o=true);},Tt=()=>{!o||n.size>0||l||(r.length=0,e.clear_update_observer(),o=false);},ve=(i,u)=>{let h=i.slice(),T=k(()=>e.open_docx(h,u)),B=Wn(T,h);return D=h,B};return {clientId:t,registerFont:i=>{F||(e.clear_measure_fonts(),F=true);let u=e.register_measure_font(i);return y.push(i.slice()),A+=1,u},clearFonts:()=>{e.clear_measure_fonts(),y.length=0,R.clear(),A+=1,F=true;},measureParagraphJson:i=>{let u=e.measure_paragraph_json(i);return R.set(i,i),u},layoutDocumentJson:i=>{let u=e.layout_document_json(i);return w=i,I=false,P+=1,u},layoutFontRequirementsJson:i=>e.layout_font_requirements_json(i),layoutDocumentWithRegionsJson:i=>{let u=e.layout_document_with_regions_json(i);return w=i,I=true,P+=1,u},buildDisplayListJson:i=>e.build_display_list_json(i),buildDisplayListFrame:(i,u)=>e.build_display_list_frame(i,u),residentCaretSnapshot:()=>JSON.parse(e.resident_caret_snapshot_json()),applyInput:(i,u)=>{let h=p?.head.story??"body";return C(h),k(()=>e.apply_input(i,u))},applyDelete:(i,u)=>{let h=p?.head.story??"body";return C(h),k(()=>e.apply_delete(i,u))},applyInputProfiled:(i,u)=>{let h=p?.head.story??"body";C(h);let T=k(()=>e.apply_input_profiled(i,u)),B=JSON.parse(e.apply_input_profile_json());return {frame:T,profile:B}},applyDeleteProfiled:(i,u)=>{let h=p?.head.story??"body";C(h);let T=k(()=>e.apply_delete_profiled(i,u)),B=JSON.parse(e.apply_input_profile_json());return {frame:T,profile:B}},residentWorkerSnapshot:i=>{if(!w||!I&&b.size===0)return null;let u=e.selection(),h=i?.knownFontsRevision===A,T=null;if(i?.knownStateVector)try{T=e.encode_diff(i.knownStateVector.slice());}catch{T=null;}return {clientId:t,state:T??e.encode_state(),selection:JSON.parse(u),fonts:h?[]:y.map(B=>B.slice()),fontsRevision:A,renderInputs:[...b].map(([B,wt])=>({story:B,env:structuredClone(wt)})),measureInputs:[...R.values()],layoutInput:w,layoutWithRegions:I,layoutRevision:P}},residentWorkerProbe:()=>!w||!I&&b.size===0?null:{layoutRevision:P},displayHitTestRegionsJson:(i,u,h)=>e.display_hit_test_regions_json(i,u,h),displayVerticalMoveJson:(i,u,h)=>e.display_vertical_move_json(i,u,h),displayRangeRectsJson:(i,u)=>e.display_range_rects_json(i,u),displayRangeRectsRegionJson:(i,u,h,T)=>e.display_range_rects_region_json(i,u,h,T),outlineGlyphJson:(i,u)=>e.outline_glyph_json(i,u),loadState:i=>k(()=>e.load(i)),seedFromDocx:i=>ve(i,true),openDocx:ve,materializeDocx:()=>{let i=D,u=e.materialize_docx();return !i||u===void 0?null:b$1(u,kt(i)).document},loadStories:i=>k(()=>JSON.parse(e.load_json(JSON.stringify(i)))),encodeState:()=>e.encode_state(),encodeStateVector:()=>e.encode_state_vector(),encodeStateAsUpdate:i=>i===void 0?e.encode_state():e.encode_diff(i.slice()),applyUpdate:i=>k(()=>JSON.parse(e.apply_update_with_inference(i))),applyLocalUpdate:(i,u)=>{C(u),k(()=>e.apply_local_update(i));},onUpdate:i=>{if(l)throw new Error("yrs session is destroyed");if(typeof i!="function")throw new TypeError("update listener must be a function");let u=s++;n.set(u,i),Rt();let h=true;return ()=>{h&&(h=false,n.delete(u),Tt());}},encodeStickyPosition:i=>({story:i.story,encoded:e.encode_sticky_position(i.story,i.paraId,i.offset)}),resolveStickyPosition:i=>{try{return JSON.parse(e.resolve_sticky_position(i.story,i.encoded))}catch{return null}},setSelection:(i,u=i)=>{if(i.story!==u.story)throw new Error("yrs selection must stay inside one story");e.set_selection(i.story,i.paraId,i.offset,u.paraId,u.offset),p={anchor:{...i},head:{...u}};},selection:()=>(p!==void 0||(p=JSON.parse(e.selection())),Ie(p)),encodeSelection:()=>{let i=JSON.parse(e.encoded_selection());return i?{story:i.story,anchor:Uint8Array.from(i.anchor),head:Uint8Array.from(i.head)}:null},resolveSelection:i=>{try{return JSON.parse(e.resolve_encoded_selection(i.story,i.anchor,i.head))}catch{return null}},setCellSelection:i=>e.set_cell_selection(JSON.stringify(i)),cellSelection:()=>JSON.parse(e.cell_selection()),beginUndoCapture:(i,u=false)=>u?_(i):C(i),historyStory:()=>f?.startsWith("table:")?f.slice(6):f,markUndoGroup:i=>{let u=e.undo_depth(),h=Math.max(0,u-i);h>1&&g.set(u,h),m.clear();},undo:()=>k(()=>{let i=e.undo_depth(),u=g.get(i)??1,h=!1;for(let T=0;T<u;T+=1)h=e.undo()||h;return h&&u>1&&(g.delete(i),m.set(e.redo_depth(),u)),h}),redo:()=>k(()=>{let i=e.redo_depth(),u=m.get(i)??1,h=!1;for(let T=0;T<u;T+=1)h=e.redo()||h;return h&&u>1&&(m.delete(i),g.set(e.undo_depth(),u)),h}),canUndo:()=>e.can_undo(),canRedo:()=>e.can_redo(),undoDepth:()=>e.undo_depth(),redoDepth:()=>e.redo_depth(),createStory:(i,u,h="Normal",T="left")=>k(()=>JSON.parse(e.create_story(i,u,h,T))),deleteStory:i=>k(()=>e.delete_story(i)),insertTable:(i,u,h,T)=>(_(i.story),k(()=>JSON.parse(e.insert_table(i.story,i.paraId,i.offset,u,h,T?.name,T?.date)))),insertRow:(i,u,h)=>(_(i.story),k(()=>JSON.parse(e.insert_row(JSON.stringify(i),u==="below",h?.name,h?.date)))),insertColumn:(i,u)=>(_(i.story),k(()=>JSON.parse(e.insert_column(JSON.stringify(i),u==="right")))),deleteRow:(i,u)=>(_(i.anchor.story),k(()=>JSON.parse(e.delete_row(JSON.stringify(i),u?.name,u?.date)))),deleteColumn:i=>(_(i.anchor.story),k(()=>JSON.parse(e.delete_column(JSON.stringify(i))))),deleteTable:i=>(_(i.story),k(()=>JSON.parse(e.delete_table(JSON.stringify(i))))),mergeCells:i=>(_(i.anchor.story),k(()=>JSON.parse(e.merge_cells(JSON.stringify(i))))),splitCell:(i,u,h)=>(_(i.story),k(()=>JSON.parse(e.split_cell(JSON.stringify(i),u,h)))),setCellShading:(i,u)=>(_(i.anchor.story),k(()=>JSON.parse(e.set_cell_shading(JSON.stringify(i),u??void 0)))),setCellTextFormat:(i,u)=>(_(i.anchor.story),k(()=>JSON.parse(e.set_cell_text_format(JSON.stringify(i),JSON.stringify(u))))),setCellBorders:(i,u)=>(_(i.anchor.story),k(()=>JSON.parse(e.set_cell_borders(JSON.stringify(i),JSON.stringify(u))))),setColumnWidth:(i,u)=>(_(i.story),k(()=>JSON.parse(e.set_column_width(JSON.stringify(i),u)))),setTableWidth:(i,u)=>(_(i.story),k(()=>JSON.parse(e.set_table_width(JSON.stringify(i),u)))),insertText:(i,u,h)=>(C(i.story),k(()=>JSON.parse(e.insert_text(i.story,i.paraId,i.offset,u,h?.name,h?.date)))),deleteRange:(i,u)=>(C(i.story),k(()=>JSON.parse(e.delete_range(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,u?.name,u?.date)))),replaceRange:(i,u,h)=>(C(i.story),k(()=>JSON.parse(e.replace_range(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,u,h?.name,h?.date)))),splitParagraph:(i,u)=>(C(i.story),k(()=>JSON.parse(e.split_paragraph(i.story,i.paraId,i.offset,u?.name,u?.date)))),mergeParagraphs:(i,u,h)=>(C(i),k(()=>JSON.parse(e.merge_paragraphs(i,u,h?.name,h?.date)))),toggleMark:(i,u)=>{C(i.story),k(()=>e.toggle_mark(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,JSON.stringify(u)));},formatRange:(i,u)=>{C(i.story),k(()=>e.format_range(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,JSON.stringify(u)));},setHyperlink:(i,u)=>{C(i.story),k(()=>e.set_hyperlink(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,JSON.stringify(u)));},clearFormatting:i=>{C(i.story),k(()=>e.clear_formatting(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset));},applyParagraphStyle:(i,u,h)=>{C(i.story),k(()=>e.apply_paragraph_style(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,u,h?.name,h?.date));},setParagraphAttrs:(i,u,h)=>{C(i.story),k(()=>e.set_paragraph_attrs(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,JSON.stringify(u),h?.name,h?.date));},insertImage:(i,u,h)=>(C(i.story),k(()=>JSON.parse(e.insert_image(i.story,i.paraId,i.offset,JSON.stringify(u),h?.name,h?.date)))),setContentControlValue:(i,u)=>{ae(i),k(()=>e.set_content_control_value(i,JSON.stringify(u)));},setContentControlValueAt:(i,u)=>{C(i.story),k(()=>e.set_content_control_value_at(i.story,i.paraId,i.offset,JSON.stringify(u)));},clearContentControlValue:i=>{ae(i),k(()=>e.clear_content_control_value(i));},setImageGeometry:(i,u)=>{ae(i),k(()=>e.set_image_geometry(i,JSON.stringify(u)));},insertPageBreak:i=>{C(i.story),k(()=>e.insert_page_break(i.story,i.paraId,i.offset));},insertSectionBreak:(i,u)=>{C(i.story),k(()=>e.insert_section_break(i.story,i.paraId,i.offset,u));},insertWatermark:(i,u)=>{C(i.story),k(()=>e.insert_watermark(i.story,i.paraId,i.offset,JSON.stringify(u)));},applyRawOps:(i,u)=>k(()=>e.apply_raw_ops(i,JSON.stringify(u))),setParagraphAttr:(i,u,h)=>k(()=>e.set_paragraph_attr(i,u,JSON.stringify(h??null))),addComment:(i,u,h,T)=>k(()=>JSON.parse(e.add_comment(Un(i),u,h,JSON.stringify(T??null)))),acceptChange:i=>k(()=>JSON.parse(e.accept_change(bt(i)))),rejectChange:i=>k(()=>JSON.parse(e.reject_change(bt(i)))),selectionContext:i=>{let u=JSON.stringify(i);if(c?.key===u)return JSON.parse(c.json);let h=e.selection_context(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset),T=JSON.parse(h);return c={key:u,json:h},T},listRevisions:()=>JSON.parse(e.list_revisions()),resolveComment:i=>JSON.parse(e.resolve_comment(i)),storyIds:()=>e.story_ids(),storyLength:i=>e.story_len(i),storyChecksum:i=>BigInt(e.story_checksum(i)),yrsBlocksForStory:(i,u={})=>{let h=e.yrs_blocks_for_story(i,JSON.stringify(u)),T=JSON.parse(h);return b.set(i,structuredClone(u)),T},paragraphs:i=>JSON.parse(e.paragraphs(i)),paragraphSpans:i=>JSON.parse(e.paragraph_spans(i)),storySegments:i=>JSON.parse(e.story_segments(i)),locateParagraph:(i,u)=>JSON.parse(e.locate_paragraph(i,u)),destroy:()=>{l||(l=true,n.clear(),r.length=0,o&&e.clear_update_observer(),e.free());}}}async function xr(e){let t=e?.clientId??Jn(),n=await import('../wasm-CJHQHBDE.mjs');return await n.preloadEditWasm(),jn(n.createEditSession(t),t)}export{de as ResidentEngineWorkerClient,It as canUseResidentEngineWorker,zn as compareYrsLocs,$n as createYrsInputPositionMap,xr as createYrsSession,Hn as displayPositionToYrsLoc,rn as documentToYrs,wr as sameYrsSelection,Ne as yrsLocToDisplayPosition,Dn as yrsToDocument};
1
+ export{a as residentCaretDeviceRect,b as residentCaretSnapshotForFrame}from'../chunk-J7LNO6SM.mjs';import {b as b$5}from'../chunk-OBQGPMPQ.mjs';import {d,a,b as b$3}from'../chunk-47Q2FMFF.mjs';import {b as b$2,p}from'../chunk-LTVVQMHB.mjs';import {c as c$1,b as b$4}from'../chunk-CTBUQRYQ.mjs';import {b as b$1,c}from'../chunk-6LQJAKOC.mjs';import'../chunk-ACGKK7IB.mjs';import'../chunk-5F6DLQZP.mjs';import {b}from'../chunk-TTRUPDAB.mjs';function Qn(e,t){let n=0,r=t.map(i=>{let o={paraId:i.paraId,length:Math.max(0,Math.trunc(i.length)),displayStart:n};return n+=o.length+2,o});return {story:e,paragraphs:r}}function De(e,t){let n=e.paragraphs.find(r=>r.paraId===t.paraId);return !n||t.story!==e.story?e.paragraphs[0]?.displayStart??0:n.displayStart+1+Math.min(Math.max(0,t.offset),n.length)}function er(e,t){if(e.paragraphs.length===0)return null;let n=Math.max(0,Math.trunc(t)),r=e.paragraphs[0];for(let i of e.paragraphs){if(i.displayStart>n)break;r=i;}return {story:e.story,paraId:r.paraId,offset:Math.min(Math.max(0,n-(r.displayStart+1)),r.length)}}function tr(e,t,n){return De(e,t)-De(e,n)}var At={bootstrap:15e3,sync:15e3,attachCanvases:15e3,buildFrame:5e3,applyInput:5e3,applyDelete:5e3};function Ft(){return new Worker(new URL("./residentEngineWorker.mjs",import.meta.url),{type:"module",name:"openooxml-resident-engine"})}var ce=class{constructor(t=Ft()){b(this,"worker",t);b(this,"pending",new Map);b(this,"nextId",1);b(this,"terminalError",null);b(this,"ready",false);b(this,"revision",0);b(this,"remoteVector",null);b(this,"appliedFontsRevision",null);this.worker.onmessage=n=>{let r=n.data;if(r.ok&&r.stateVector&&(this.remoteVector=new Uint8Array(r.stateVector)),!r.ok&&r.terminal){this.fail(new $(r.error));return}let i=this.pending.get(r.id);i&&(this.pending.delete(r.id),clearTimeout(i.timeout),r.ok?i.resolve(r):i.reject(Yt(r.error,r.residentUnavailable)));},this.worker.onerror=n=>{this.fail(new J(`Resident engine worker failed: ${n.message}`));},this.worker.onmessageerror=()=>{this.fail(new J("Resident engine worker returned an unreadable message"));};}isReady(){return this.ready}layoutRevision(){return this.revision}remoteStateVector(){return this.remoteVector}syncedFontsRevision(){return this.appliedFontsRevision}async bootstrap(t,n){let r=t.fontsRevision,i=await this.request({type:"bootstrap",snapshot:t,extras:n,expectedFrameEpoch:0},Je(t)),o=G(i);return this.recordSync(i,r),this.ready=true,this.revision=o.layoutRevision,o}async sync(t,n,r,i=false){let o=t.fontsRevision,a=await this.request({type:"sync",snapshot:t,extras:n,expectedFrameEpoch:r,paintCaret:i},Je(t)),l=G(a);return this.recordSync(a,o),this.ready=true,this.revision=l.layoutRevision,l}async buildFrame(t,n,r=false){return G(await this.request({type:"buildFrame",extras:t,expectedFrameEpoch:n,paintCaret:r}))}async applyInput(t,n,r,i=false,o=false){if(!this.ready)return {applied:false};try{return {applied:!0,...G(await this.request({type:"applyInput",text:t,selection:n,expectedFrameEpoch:r,profile:i,paintCaret:o}))}}catch(a){if(a instanceof $)return {applied:false};throw a}}async applyDelete(t,n,r,i=false,o=false){if(!this.ready)return {applied:false};try{return {applied:!0,...G(await this.request({type:"applyDelete",direction:t,selection:n,expectedFrameEpoch:r,profile:i,paintCaret:o}))}}catch(a){if(a instanceof $)return {applied:false};throw a}}eraseCaret(){if(this.terminalError)return;let n={id:this.nextId++,type:"eraseCaret"};this.worker.postMessage(n);}invalidate(t,n){if(this.terminalError)return;this.ready=false;let r=t.slice(),o={id:this.nextId++,type:"applyUpdate",update:r,selection:n};this.worker.postMessage(o,[r.buffer]);}async attachCanvases(t,n,r,i,o){let a=t.map(l=>l.canvas);await this.request({type:"attachCanvases",pages:t,activePageIds:n,devicePixelRatio:r,zoom:i,caretStyle:o},a);}destroy(){if(this.terminalError)return;let n={id:this.nextId++,type:"destroy"};this.worker.postMessage(n),this.fail(new J("Resident engine worker was destroyed"));}request(t,n=[]){if(this.terminalError)return Promise.reject(this.terminalError);let r=this.nextId++,i=At[t.type];return new Promise((o,a)=>{let l=setTimeout(()=>{this.fail(new J(`Resident engine worker did not answer ${t.type} within ${i}ms`));},i);this.pending.set(r,{resolve:o,reject:a,timeout:l}),this.worker.postMessage({...t,id:r},n);})}recordSync(t,n){this.appliedFontsRevision=n;}fail(t){this.terminalError=t,this.ready=false,this.worker.terminate();for(let n of this.pending.values())clearTimeout(n.timeout),n.reject(t);this.pending.clear();}},$=class extends Error{},J=class extends Error{};function Yt(e,t=false){return t?new $(e):new Error(e)}function Je(e){return [e.state.buffer,...e.fonts.map(t=>t.buffer)]}function G(e){if(!e.frame)throw new J("Resident engine worker response omitted its FrameDelta");if(!e.caret)throw new J("Resident engine worker response omitted its caret snapshot");if(e.selection===void 0)throw new J("Resident engine worker response omitted its selection");return {frame:new Uint8Array(e.frame),updates:(e.updates??[]).map(t=>new Uint8Array(t)),engineMs:e.engineMs??0,workerTotalMs:e.workerTotalMs??0,engineProfile:e.engineProfile,caret:e.caret,selection:e.selection,caretPainted:e.caretPainted??false,replayMs:e.replayMs??0,replayedPages:e.replayedPages??0,layoutRevision:e.layoutRevision??0}}function Mt(){return typeof Worker<"u"}function ne(e){return e.type==="rawXml"}function pe(e){return {sdtType:e.sdtType,id:e.id??null,alias:e.alias??null,tag:e.tag??null,lock:e.lock??null,placeholder:e.placeholder??null,showingPlaceholder:e.showingPlaceholder??false,dateFormat:e.dateFormat??null,listItems:e.listItems?JSON.stringify(e.listItems):null,checked:e.checked??null,dataBinding:e.dataBinding?JSON.stringify(e.dataBinding):null,rawPropertiesXml:e.rawPropertiesXml??null,rawEndPropertiesXml:e.rawEndPropertiesXml??null}}function fe(e){let t={sdtType:e.sdtType??"richText"};if(typeof e.id=="number"&&(t.id=e.id),e.alias!=null&&(t.alias=String(e.alias)),e.tag!=null&&(t.tag=String(e.tag)),e.lock!=null&&(t.lock=e.lock),e.placeholder!=null&&(t.placeholder=String(e.placeholder)),e.showingPlaceholder&&(t.showingPlaceholder=true),e.dateFormat!=null&&(t.dateFormat=String(e.dateFormat)),typeof e.listItems=="string"&&e.listItems)try{t.listItems=JSON.parse(e.listItems);}catch{}if(e.checked!=null&&(t.checked=e.checked),typeof e.dataBinding=="string"&&e.dataBinding)try{t.dataBinding=JSON.parse(e.dataBinding);}catch{}return e.rawPropertiesXml!=null&&(t.rawPropertiesXml=String(e.rawPropertiesXml)),e.rawEndPropertiesXml!=null&&(t.rawEndPropertiesXml=String(e.rawEndPropertiesXml)),t}function ge(e,t,n,r,i,o){let a=t?.pPr;if(!t?.tblStylePr?.some(I=>I.pPr))return a;let l=e.formatting?.look??t.tblPr?.look,d=(I,M)=>l?.[I]??(Number.parseInt(l?.value??(l?"0":"04A0"),16)&M)!==0,m=d("firstRow",32),u=d("lastRow",64),c=d("firstColumn",128),y=d("lastColumn",256),f=e.rows[n].formatting?.gridBefore??0;r+=f,i+=f;let h=!!m&&n===0,g=!!u&&n===e.rows.length-1,k=!!c&&r===0,w=!!y&&i===o,T=e.formatting?.styleRowBandSize??t.tblPr?.styleRowBandSize??1,v=e.formatting?.styleColBandSize??t.tblPr?.styleColBandSize??1,P=[];!d("noHBand",512)&&!h&&!g&&T>0&&P.push(Math.floor((n-+!!m)/T)%2===0?"band1Horz":"band2Horz"),!d("noVBand",1024)&&!k&&!w&&v>0&&P.push(Math.floor((r-+!!c)/v)%2===0?"band1Vert":"band2Vert");for(let[I,M]of [["firstCol",k],["lastCol",w],["firstRow",h],["lastRow",g],["nwCell",h&&k],["neCell",h&&w],["swCell",g&&k],["seCell",g&&w]])M&&P.push(I);for(let I of P)a=b$3(a,t.tblStylePr.find(M=>M.type===I)?.pPr);return a}function Ue(e){return Math.max(e.columnWidths?.length??0,...e.rows.map(t=>t.cells.reduce((n,r)=>n+(r.formatting?.gridSpan??1),(t.formatting?.gridBefore??0)+(t.formatting?.gridAfter??0))))}function E(e){if(Array.isArray(e))return e.map(E);if(e!==null&&typeof e=="object"){let t={};for(let[n,r]of Object.entries(e))r!=null&&(t[n]=E(r));return t}return e}var _t={styleId:"pStyle",_sectionProperties:"sectPr"},Bt=new Set(["paraId","textId","renderedPageBreakBefore","numPrFromStyle"]);function We(e){let t={};for(let[n,r]of Object.entries(e))Bt.has(n)||r===null||r===void 0||(t[_t[n]??n]=E(r));return t}var Ot=new Set(["columnWidths"]);function re(e,t=new Set){let n={};for(let[r,i]of Object.entries(e))t.has(r)||i===null||i===void 0||(n[r]=E(i));return n}function je(e){return re(e,Ot)}function ze(e){let t=e.columnWidths;return Array.isArray(t)?t.map(E):[]}function $e(e){return re(e)}function He(e,t){let n=re(e);return t&&(n.header=true),n}function me(e,t,n,r){return `${e}:t${t}:r${n}c${r}`}function Ve(e,t){return `${e}:sdt${t}`}function Ke(e){return re(e)}function oe(e){return `hf:${e}`}function Xe(e){return `fn:${e}`}function qe(e){return `en:${e}`}var Nt=new Set(["bold","italic","superscript","subscript","allCaps","smallCaps","emboss","imprint","textShadow","textOutline","hidden","rtl"]);function H(e){if(e==null)return "null";if(Array.isArray(e))return `[${e.map(H).join(",")}]`;if(typeof e=="object"){let t=e;return `{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${H(t[n])}`).join(",")}}`}return JSON.stringify(e)}function Et(e,t){if(!e||!t)return e;let n=t.resolveRunStyle(e.styleId);return n?a(n,e):e}function Qe(e){if(!e)return [];let t=[],n=(a,l={})=>t.push({name:a,attrs:l});e.bold&&n("bold"),e.italic&&n("italic"),e.underline&&e.underline.style!=="none"&&n("underline",{style:e.underline.style,color:e.underline.color??null}),(e.strike||e.doubleStrike)&&n("strike",{double:e.doubleStrike||false}),e.color&&!e.color.auto&&n("textColor",{rgb:e.color.rgb??null,themeColor:e.color.themeColor??null,themeTint:e.color.themeTint??null,themeShade:e.color.themeShade??null});let r=e.shading?.fill,i=(!e.shading?.pattern||e.shading.pattern==="clear")&&r?.rgb&&!r.auto?p(r.rgb):void 0,o=e.highlight&&e.highlight!=="none"?e.highlight:i;return o&&n("highlight",{color:o}),(e.fontSize!=null||e.fontSizeCs!=null)&&n("fontSize",{size:e.fontSize??null,sizeCs:e.fontSizeCs??null}),e.fontFamily&&n("fontFamily",{ascii:e.fontFamily.ascii??null,hAnsi:e.fontFamily.hAnsi??null,eastAsia:e.fontFamily.eastAsia??null,cs:e.fontFamily.cs??null,asciiTheme:e.fontFamily.asciiTheme??null,hAnsiTheme:e.fontFamily.hAnsiTheme??null,eastAsiaTheme:e.fontFamily.eastAsiaTheme??null,csTheme:e.fontFamily.csTheme??null}),e.vertAlign==="superscript"?n("superscript"):e.vertAlign==="subscript"&&n("subscript"),e.allCaps&&n("allCaps"),e.smallCaps&&n("smallCaps"),(e.spacing!=null||e.position!=null||e.scale!=null||e.kerning!=null)&&n("characterSpacing",{spacing:e.spacing??null,position:e.position??null,scale:e.scale??null,kerning:e.kerning??null}),e.emboss&&n("emboss"),e.imprint&&n("imprint"),e.shadow&&n("textShadow"),e.emphasisMark&&e.emphasisMark!=="none"&&n("emphasisMark",{type:e.emphasisMark}),e.outline&&n("textOutline"),e.hidden&&n("hidden"),e.rtl&&n("rtl"),e.effect&&e.effect!=="none"&&n("textEffect",{effect:e.effect}),e.modernEffects&&n("modernTextEffects",{effects:e.modernEffects}),e.styleId&&n("runStyle",{styleId:e.styleId}),t}function et(e){let t={};for(let n of e)n.name==="comment"||n.name==="footnoteRef"||(Nt.has(n.name)?t[n.name]=true:n.name==="highlight"?t.highlight=n.attrs.color:n.name==="insertion"||n.name==="deletion"?t[n.name==="insertion"?"ins":"del"]=E({id:n.attrs.revisionId,author:n.attrs.author,date:n.attrs.date}):t[n.name]=E(n.attrs));return t}function Lt(e){return e.filter(t=>t.name!=="hyperlink"&&t.name!=="comment").map(t=>`${t.name}:${JSON.stringify(t.attrs)}`).sort().join("|")}function Dt(e,t){return [...e.filter(n=>n.name!==t.name),t]}function Z(e,t,n){return {kind:"text",text:e,attrs:et(t),pmSize:e.length,...n!==void 0?{commentId:n}:{},marks:[...t]}}function Y(e,t,n=[],r,i=1){return {kind:"embed",embedKind:e,payload:t,attrs:et(n),pmSize:i,...r!==void 0?{commentId:r}:{},marks:[...n]}}function tt(e,t,n){let r=e.formatting?.styleId?n?.getRunStyleOwnProperties(e.formatting.styleId):void 0,i=Qe(a(a(t,r),e.formatting)),o=e.formatting?.styleId,a$1=o?n?.getStyle(o)?.name:void 0;if([o,a$1].some(l=>/^(?:Followed)?Hyperlink$/i.test(l??""))){for(let[l,d]of [["color","textColor"],["underline","underline"]])if(e.formatting?.[l]===void 0&&r?.[l]!==void 0){let m=i.find(u=>u.name===d);m&&(m.attrs.inheritedHyperlink=true);}}return i}function Jt(e){let t=e.size?.width?b$4(e.size.width):void 0,n=e.size?.height?b$4(e.size.height):void 0,r=e.wrap.type,i=e.wrap.wrapText,o=e.position?.horizontal?.alignment,a;r==="inline"||r==="topAndBottom"?a="none":r==="square"||r==="tight"||r==="through"?i==="left"?a="right":i==="right"?a="left":o==="left"||o==="right"?a=o:a="none":a="none";let l=r==="inline"?"inline":r==="topAndBottom"?"block":b$5(r)||a&&a!=="none"?"float":"block",d=[];e.transform?.rotation&&d.push(`rotate(${e.transform.rotation}deg)`),e.transform?.flipH&&d.push("scaleX(-1)"),e.transform?.flipV&&d.push("scaleY(-1)");let m,u,c;if(e.outline?.width){m=Math.round(e.outline.width/914400*96*100)/100,e.outline.color?.rgb&&(u=`#${e.outline.color.rgb}`);let y={solid:"solid",dot:"dotted",dash:"dashed",lgDash:"dashed",dashDot:"dashed",lgDashDot:"dashed",lgDashDotDot:"dashed",sysDot:"dotted",sysDash:"dashed",sysDashDot:"dashed",sysDashDotDot:"dashed"};c=e.outline.style&&y[e.outline.style]||"solid";}return E({src:e.src||"",alt:e.alt??null,title:e.title??null,width:t??null,height:n??null,rId:e.rId??null,wrapType:r,displayMode:l,cssFloat:a??null,transform:d.length>0?d.join(" "):null,distTop:e.wrap.distT!=null?b$4(e.wrap.distT):null,distBottom:e.wrap.distB!=null?b$4(e.wrap.distB):null,distLeft:e.wrap.distL!=null?b$4(e.wrap.distL):null,distRight:e.wrap.distR!=null?b$4(e.wrap.distR):null,position:e.position?{relativeHeight:e.position.relativeHeight,horizontal:e.position.horizontal?{relativeTo:e.position.horizontal.relativeTo,posOffset:e.position.horizontal.posOffset,align:e.position.horizontal.alignment}:void 0,vertical:e.position.vertical?{relativeTo:e.position.vertical.relativeTo,posOffset:e.position.vertical.posOffset,align:e.position.vertical.alignment}:void 0}:null,borderWidth:m??null,borderColor:u??null,borderStyle:c??null,wrapText:i??null,hlinkHref:e.hlinkHref??null,cropTop:e.crop?.top??null,cropRight:e.crop?.right??null,cropBottom:e.crop?.bottom??null,cropLeft:e.crop?.left??null,shapeType:e.shapeType??null,opacity:e.opacity??null,effectExtentTop:e.padding?.top?b$4(e.padding.top):null,effectExtentBottom:e.padding?.bottom?b$4(e.padding.bottom):null,effectExtentLeft:e.padding?.left?b$4(e.padding.left):null,effectExtentRight:e.padding?.right?b$4(e.padding.right):null,layoutInCell:e.layoutInCell??null,allowOverlap:e.allowOverlap??null})}function Ut(e){return {shapeJson:JSON.stringify(e)}}function Wt(e){return E({chartJson:JSON.stringify(e),chartType:e.chartType??null,title:e.title??null,width:e.size?.width?b$4(e.size.width):320,height:e.size?.height?b$4(e.size.height):220,rId:e.rId??null,path:e.path??null})}function ee(e,t){let n="",r,i=e.type==="simpleField"?e.content:e.fieldResult;for(let l of i)if(l.type==="run"){for(let d of l.content)d.type==="text"&&(n+=d.text);!r&&l.formatting&&(r=l.formatting);}let o=r??(e.type==="complexField"?e.formatting:void 0),a$1=e.fieldTree?.displayMode??"result";return {payload:{fieldType:e.fieldType,instruction:e.instruction,displayText:n,fieldKind:e.type==="simpleField"?"simple":"complex",fldLock:e.fldLock??false,dirty:e.dirty??false,displayMode:a$1,hasCachedResult:n.length>0,fieldData:JSON.stringify(e),modelKind:"field"},marks:Qe(a(t,o))}}function ye(e){return {display:e.display,ommlXml:e.ommlXml,plainText:e.plainText||""}}function jt(e){return {name:"hyperlink",attrs:{href:e.href||(e.anchor?`#${e.anchor}`:""),tooltip:e.tooltip??null,rId:e.rId??null}}}function zt(e,t,n,r){let i=e.structuredResult?.inline??[],a=[...(e.type==="complexField"?e.structuredCode?.inline??[]:[]).map((c,y)=>({child:c,index:-y-1})),...i.map((c,y)=>({child:c,index:y}))];if(e.type!=="complexField"||!a.some(({child:c})=>c.type==="hyperlink"||c.type==="simpleField")){let c=ee(e,t);return [Y("field",c.payload,c.marks)]}let l=[],d=[];a.forEach(({child:c,index:y})=>{if(c.type!=="hyperlink"&&c.type!=="simpleField")return;let f=c.type==="simpleField"?ee(c,t):null,h=c.type==="hyperlink"?se(c,t,n):[Y("field",f.payload,f.marks)];d.push({index:y,items:h.map(g=>g.kind==="text"?{kind:"text",text:g.text,attributes:g.attrs}:{kind:"embed",embedKind:g.embedKind,payload:g.payload,attributes:g.attrs})});for(let g of h)g.attrs={...g.attrs,fieldResult:{id:r,index:y}};l.push(...h);});let m={...e,fieldResult:i.filter(c=>c.type==="run")},u=ee(m,t);return u.payload.fieldData=JSON.stringify(e),u.payload.resultProjection={id:r,children:d},l.push(Y("field",u.payload,u.marks)),l}function Ge(e,t,n,r){let i={name:"footnoteRef",attrs:{id:String(e),noteType:t}},o=[...n,i];return Y("noteRef",t==="endnote"?{endnoteRefId:e}:{footnoteRefId:e},o,r)}function nt(e,t,n){switch(e.type){case "text":return e.text?[Z(e.text,t,n)]:[];case "tab":return [Z(" ",t,n)];case "break":return e.breakType===void 0||e.breakType==="textWrapping"?[Y("break",{},t,n)]:[];case "softHyphen":return [Z("\xAD",t,n)];case "noBreakHyphen":return [Z("\u2011",t,n)];case "symbol":{let r=Number.parseInt(e.char,16);if(!Number.isInteger(r)||r<0||r>1114111)return [];let i={name:"fontFamily",attrs:{ascii:e.font||null,hAnsi:e.font||null,eastAsia:e.font||null,cs:e.font||null,asciiTheme:null,hAnsiTheme:null,eastAsiaTheme:null,csTheme:null}};return [Z(String.fromCodePoint(r),Dt(t,i),n)]}case "commentReference":return [Y("field",{fieldType:"COMMENT",instruction:"",displayText:"",fieldKind:"simple",fldLock:false,dirty:false,displayMode:"result",hasCachedResult:false,modelKind:"commentReference",...e.id!==void 0?{commentId:e.id}:{}})];case "drawing":return [Y("image",Jt(e.image))];case "horizontalRule":return [Y("horizontalRule",{rule:e.rule},t,n)];case "shape":return [Y("shape",Ut(e.shape))];case "chart":return [Y("chart",Wt(e.chart))];case "footnoteRef":return [Ge(e.id,"footnote",t,n)];case "endnoteRef":return [Ge(e.id,"endnote",t,n)];default:return []}}function ie(e,t,n,r,i=[]){let o=[...tt(e,t,n),...i];return e.content.flatMap(a=>nt(a,o,r))}function se(e,t,n,r=[]){let i=[],o=jt(e);for(let a of e.structuredChildren??e.children)if(a.type==="run"){let l=[...tt(a,t,n),...r,o];for(let d of a.content)i.push(...nt(d,l));}else if(a.type==="simpleField"||a.type==="complexField"){let l=ee(a,t);i.push(Y("field",l.payload,[...l.marks,...r,o]));}else a.type==="mathEquation"&&i.push(Y("math",ye(a),[...r,o]));return i}function $t(e,t,n){return {name:t,attrs:{revisionId:e.id,author:e.author,date:e.date??null,isMovePair:n}}}function Ht(e,t,n,r){let i=e.type==="insertion"||e.type==="moveTo"?"insertion":"deletion",o=$t(e.info,i,e.type==="moveFrom"||e.type==="moveTo"),a=[];for(let l of e.content)if(l.type==="run")a.push(...ie(l,t,n,r,[o]));else {let d=se(l,t,n,[o]);for(let m of d)r!==void 0&&(m.commentId=r);a.push(...d);}return a}function rt(e,t,n){let r=[],i=o=>{if(o.kind==="text"){if((o.text===" "?"tab":"text")==="tab"){r.push({kind:"tab",attrs:o.attrs});return}let l=r[r.length-1];l&&"text"in l&&H(l.attrs)===H(o.attrs)?l.text+=o.text:r.push({kind:"text",text:o.text,attrs:o.attrs});return}r.push({kind:o.embedKind,payload:o.payload,attrs:o.attrs});};for(let o of e.content)if(o.type==="run")ie(o,t,n).forEach(i);else if(o.type==="hyperlink")se(o,t,n).forEach(i);else if(o.type==="simpleField"||o.type==="complexField"){let a=ee(o,t);i(Y("field",a.payload,a.marks));}else o.type==="inlineSdt"?i(Y("sdt",rt(o,t,n))):o.type==="mathEquation"&&i(Y("math",ye(o)));return E({...pe(e.properties),propertiesJson:JSON.stringify(e.properties),content:r})}function Vt(e,t,n){let r=t?t.resolveParagraphStyle(e.formatting?.styleId).runFormatting:void 0;return a(r,n)}function Kt(e){let t=[];for(let n of e.content)n.type==="footnoteRefMark"?t.push("footnote"):n.type==="endnoteRefMark"&&t.push("endnote");return t}function Xt(e,t,n){let r=ie(e,t,n);if(r.some(d=>d.kind!=="text"&&d.embedKind!=="noteRef"))return null;let i=r.map(d=>Lt(d.marks));if(i.some(d=>d!==i[0]))return null;let o=Kt(e),a=r.map(d=>{if(d.kind==="text")return d.text;let m=d.payload.footnoteRefId??d.payload.endnoteRefId;return String(m??"")}).join(""),l=i[0];return {text:a,...o.length>0?{noteMarks:o}:{},...l!==void 0?{marksKey:l}:{},...e.formatting?{formatting:e.formatting}:{},...e.propertyChanges?{propertyChanges:e.propertyChanges}:{}}}function qt(e,t,n,r,i){let o=e.formatting,a$1=o?.styleId,l=o?.indentFirstLine===0?void 0:o?.indentFirstLine,d=l??e.listRendering?.indentFirstLine??o?.indentFirstLine,m=l===void 0&&e.listRendering?.indentFirstLine!==void 0?e.listRendering.hangingIndent:o?.hangingIndent??e.listRendering?.hangingIndent,u={paraId:e.paraId??null,textId:e.textId??null,styleId:a$1??null,numPr:o?.numPr??null,numPrFromStyle:o?.numPrFromStyle??null,listNumFmt:e.listRendering?.numFmt??null,listIsBullet:e.listRendering?.isBullet??null,listMarker:e.listRendering?.marker??null,listMarkerHidden:e.listRendering?.markerHidden||null,listMarkerFontFamily:e.listRendering?.markerFontFamily||null,listMarkerFontSize:e.listRendering?.markerFontSize||null,listMarkerSuffix:e.listRendering?.markerSuffix||null,listLevelNumFmts:e.listRendering?.levelNumFmts||null,listAbstractNumId:e.listRendering?.abstractNumId??null,listStartOverride:e.listRendering?.startOverride??null,_originalFormatting:o??null};if(t){let h=t.resolveParagraphStyle(a$1,i),g=h.paragraphFormatting;u.alignment=o?.alignment??g?.alignment??null,u.spaceBefore=o?.spaceBefore??g?.spaceBefore??null,u.spaceAfter=o?.spaceAfter??g?.spaceAfter??null,u.spaceBeforeLines=o?.spaceBeforeLines??g?.spaceBeforeLines??null,u.spaceAfterLines=o?.spaceAfterLines??g?.spaceAfterLines??null,u.beforeAutospacing=o?.beforeAutospacing??g?.beforeAutospacing??null,u.afterAutospacing=o?.afterAutospacing??g?.afterAutospacing??null,u.lineSpacing=o?.lineSpacing??g?.lineSpacing??null,u.lineSpacingRule=o?.lineSpacingRule??g?.lineSpacingRule??null,u.spacingExplicit=o?.spacingExplicit||null,u.indentLeft=o?.indentLeft??e.listRendering?.indentLeft??g?.indentLeft??null,u.indentRight=o?.indentRight??g?.indentRight??null;let w=o?.numPr?.numId===0&&g?.numPr&&g.numPr.numId!==0?void 0:g;u.indentFirstLine=d??w?.indentFirstLine??null,u.hangingIndent=m??w?.hangingIndent??false,u.borders=o?.borders??g?.borders??null,u.shading=o?.shading??g?.shading??null,u.tabs=o?.tabs??g?.tabs??null,u.pageBreakBefore=o?.pageBreakBefore??g?.pageBreakBefore??null,u.keepNext=o?.keepNext??g?.keepNext??null,u.keepLines=o?.keepLines??g?.keepLines??null,u.widowControl=o?.widowControl??g?.widowControl??null,u.contextualSpacing=o?.contextualSpacing??g?.contextualSpacing??null,u.outlineLevel=o?.outlineLevel??g?.outlineLevel??null,u.bidi=o?.bidi??g?.bidi??null;let T=t.getDefaultCharacterStyle()?.rPr,v=T?a(h.runFormatting,T):h.runFormatting;u.defaultTextFormatting=a(v,Et(o?.runProperties,t))??null,!o?.numPr&&g?.numPr&&g.numPr.numId!==0&&(u.numPr=g.numPr,u.numPrFromStyle=g.numPr);}else u.alignment=o?.alignment??null,u.spaceBefore=o?.spaceBefore??null,u.spaceAfter=o?.spaceAfter??null,u.spaceBeforeLines=o?.spaceBeforeLines??null,u.spaceAfterLines=o?.spaceAfterLines??null,u.beforeAutospacing=o?.beforeAutospacing??null,u.afterAutospacing=o?.afterAutospacing??null,u.lineSpacing=o?.lineSpacing??null,u.lineSpacingRule=o?.lineSpacingRule??null,u.spacingExplicit=o?.spacingExplicit||null,u.indentLeft=o?.indentLeft??e.listRendering?.indentLeft??null,u.indentRight=o?.indentRight??null,u.indentFirstLine=d??null,u.hangingIndent=m??false,u.borders=o?.borders??null,u.shading=o?.shading??null,u.tabs=o?.tabs??null,u.pageBreakBefore=o?.pageBreakBefore??null,u.keepNext=o?.keepNext??null,u.keepLines=o?.keepLines??null,u.widowControl=o?.widowControl??null,u.outlineLevel=o?.outlineLevel??null,u.bidi=o?.bidi??null,u.defaultTextFormatting=o?.runProperties??null;if(e.sectionProperties){u._sectionProperties=e.sectionProperties;let h=e.sectionProperties.sectionStart;(h==="nextPage"||h==="continuous"||h==="oddPage"||h==="evenPage"||h==="nextColumn")&&(u.sectionBreakType=h);}e.renderedPageBreakBefore&&(u.renderedPageBreakBefore=true),Qt(e)&&(u.pageBreakBefore=true),e.pPrIns&&(u.pPrIns={revisionId:e.pPrIns.id,author:e.pPrIns.author,date:e.pPrIns.date??null}),e.pPrDel&&(u.pPrDel={revisionId:e.pPrDel.id,author:e.pPrDel.author,date:e.pPrDel.date??null}),e.propertyChanges?.length&&(u.pPrChange=e.propertyChanges);let c=[],y=0,f=0;for(let h of e.content)if(h.type==="bookmarkStart")c.push({id:h.id,name:h.name,kind:"start",offset:f,...h.colFirst!==void 0?{colFirst:h.colFirst}:{},...h.colLast!==void 0?{colLast:h.colLast}:{}});else if(h.type==="bookmarkEnd")c.push({id:h.id,kind:"end",offset:f});else {let g=Gt(h);for(let k=0;k<g;k+=1)f+=n[y]?.pmSize??0,y+=1;}return c.length>0&&(u.bookmarks=c),r?.length&&(u._originalRunBoundaries=r),u}var ot=new WeakMap;function Gt(e){return ot.get(e)??0}function Zt(e,t,n,r){let i=[],o=new Set,a=[],l=Vt(e,t,n);for(let[m,u]of e.content.entries()){let c=i.length,y=o.values().next().value;if(u.type==="commentRangeStart")o.add(u.id);else if(u.type==="commentRangeEnd")o.delete(u.id);else if(u.type==="run"){let f=Xt(u,l,t);f&&a?a.push(f):a=void 0,i.push(...ie(u,l,t,y));}else u.type==="hyperlink"?(a=void 0,i.push(...se(u,l,t))):u.type==="simpleField"||u.type==="complexField"?(a=void 0,i.push(...zt(u,l,t,m))):u.type==="inlineSdt"?(a=void 0,i.push(Y("sdt",rt(u,l,t),[],void 0,2))):u.type==="insertion"||u.type==="deletion"||u.type==="moveFrom"||u.type==="moveTo"?(a=void 0,i.push(...Ht(u,l,t,y))):u.type==="mathEquation"?(a=void 0,i.push(Y("math",ye(u)))):u.type!=="bookmarkStart"&&u.type!=="bookmarkEnd"&&u.type!=="rawXml"&&(a=void 0);ot.set(u,i.length-c);}let d=qt(e,t,i,a,r);return {units:i,ppr:We(d)}}function Q(e,t){for(let n of e.content)n.type==="break"&&n.breakType==="page"?t.push("pageBreak"):(n.type!=="text"||n.text.length>0)&&t.push("visible");}function be(e,t){for(let n of e)if(n.type==="run")Q(n,t);else if(n.type==="hyperlink")for(let r of n.children)r.type==="run"&&Q(r,t);else if(n.type==="simpleField")for(let r of n.content)r.type==="run"&&Q(r,t);else if(n.type==="complexField")for(let r of [...n.fieldCode,...n.fieldResult])Q(r,t);else if(n.type==="inlineSdt")be(n.content,t);else if(n.type==="insertion"||n.type==="deletion"||n.type==="moveFrom"||n.type==="moveTo")for(let r of n.content)r.type==="run"&&Q(r,t);else n.type==="mathEquation"&&t.push("visible");}function Qt(e){let t=[];return be(e.content,t),t[0]==="pageBreak"}function en(e){let t=[];be(e.content,t);let n=false,r=false;for(let i of t)if(i==="pageBreak"){if(r||n)return true;n=true;}else r=true;return false}function tn(e){let t=new Map,n=new Map;return e.rows.forEach((r,i)=>{let o=0,a=r.cells.map(d=>{let m=o;return o+=d.formatting?.gridSpan??1,{column:m,vMerge:d.formatting?.vMerge,key:`${i}-${m}`}});if(a.length>0&&a.every(d=>d.vMerge==="continue"&&n.has(d.column))){for(let d of a)n.delete(d.column),t.set(d.key,{rowSpan:1,skip:false});return}for(let d of a)if(d.vMerge==="restart")n.set(d.column,i),t.set(d.key,{rowSpan:1,skip:false});else if(d.vMerge==="continue"){let m=n.get(d.column);if(m===void 0)t.set(d.key,{rowSpan:1,skip:false});else {let u=t.get(`${m}-${d.column}`);u&&(u.rowSpan+=1),t.set(d.key,{rowSpan:1,skip:true});}}else n.delete(d.column),t.set(d.key,{rowSpan:1,skip:false});}),t}function he(e){return {revisionId:e.id,author:e.author,date:e.date??null}}function nn(e,t,n,r,i,o){let a=t?{top:n?t.top:t.insideH,bottom:r?t.bottom:t.insideH,left:i?t.left:t.insideV,right:o?t.right:t.insideV}:void 0;return a||e?.borders?{...a??{},...e?.borders??{}}:void 0}function Ze(e,t){let n=e.formatting,r=b$2(n?.shading?.fill,t.theme),i=n?.width?.value??t.gridWidth,o=n?.width?.type??(t.gridWidth!==void 0?"pct":null),a={colspan:n?.gridSpan??1,rowspan:t.rowspan,width:i??null,widthType:o,verticalAlign:n?.verticalAlign??null,backgroundColor:r??null,borders:nn(n,t.tableBorders,t.firstRow,t.lastRow,t.firstColumn,t.lastColumn)??null,margins:n?.margins?{top:n.margins.top?.value,bottom:n.margins.bottom?.value,left:n.margins.left?.value??(t.tableBidi?n.margins.end?.value:n.margins.start?.value),right:n.margins.right?.value??(t.tableBidi?n.margins.start?.value:n.margins.end?.value)}:t.defaultMargins??null,textDirection:n?.textDirection??null,noWrap:n?.noWrap??false,_originalFormatting:n??null,_originalResolvedFill:r??null};if(e.structuralChange){let l=e.structuralChange,d=he(l.info);l.type==="tableCellInsertion"?a.cellMarker={kind:"ins",info:d}:l.type==="tableCellDeletion"?a.cellMarker={kind:"del",info:d}:l.type==="tableCellMerge"&&(a.cellMarker={kind:"merge",info:d,vMerge:l.vMerge??"cont",...l.vMergeOrig?{vMergeOrig:l.vMergeOrig}:{}});}return e.propertyChanges?.length&&(a.tcPrChange=e.propertyChanges),{attrs:He(a,t.isHeader),content:e.content.length>0?e.content:[{type:"paragraph",content:[]}]}}function rn(e,t,n,r,i,o,a,l,d){let m={height:e.formatting?.height?.value??null,heightRule:e.formatting?.heightRule??null,isHeader:!!e.formatting?.header,_originalFormatting:e.formatting??null};e.structuralChange&&(e.structuralChange.type==="tableRowInsertion"?m.trIns=he(e.structuralChange.info):e.structuralChange.type==="tableRowDeletion"&&(m.trDel=he(e.structuralChange.info))),e.propertyChanges?.length&&(m.trPrChange=e.propertyChanges);let u=t.columnWidths,c=u?.reduce((g,k)=>g+k,0)??0,y=u?.length??Math.max(0,...t.rows.map(g=>g.cells.reduce((k,w)=>k+(w.formatting?.gridSpan??1),0))),f=0,h=[];return e.cells.forEach(g=>{let k=g.formatting?.gridSpan??1,w=f,T=r.get(`${n}-${w}`),v;if(u&&c>0){let P=0;for(let I=0;I<k&&w+I<u.length;I+=1)P+=u[w+I];v=Math.round(P/c*100);}f+=k,!T?.skip&&h.push({paragraphFormatting:ge(t,l,n,w,f,d),...Ze(g,{isHeader:n===0&&!!t.formatting?.look?.firstRow,rowspan:T?.rowSpan??1,gridWidth:v,firstRow:n===0,lastRow:n===t.rows.length-1,firstColumn:w===0,lastColumn:f===y,tableBorders:i,defaultMargins:o,theme:a,tableBidi:!!t.formatting?.bidi})});}),h.length===0&&h.push({paragraphFormatting:ge(t,l,n,0,y,d),...Ze({formatting:y>1?{gridSpan:y}:void 0,content:[{type:"paragraph",content:[]}]},{isHeader:n===0&&!!t.formatting?.look?.firstRow,rowspan:1,gridWidth:c>0?100:void 0,firstRow:n===0,lastRow:n===t.rows.length-1,firstColumn:true,lastColumn:true,tableBorders:i,defaultMargins:o,theme:a,tableBidi:!!t.formatting?.bidi})}),{attrs:$e(m),cells:h}}function on(e,t,n){let r=t?.getDefaultTableStyle(),i=e.formatting?.styleId,o=i??r?.styleId,a=o?t?.getStyle(o):void 0,l=e.formatting?.borders??a?.tblPr?.borders??r?.tblPr?.borders,d=e.formatting?.cellMargins??a?.tblPr?.cellMargins??r?.tblPr?.cellMargins,m=e.formatting?.bidi?d?.end:d?.start,u=e.formatting?.bidi?d?.start:d?.end,c=d?{top:d.top?.value,bottom:d.bottom?.value,left:d.left?.value??m?.value,right:d.right?.value??u?.value}:void 0,y=[],f=new Set,h=a;for(;h?.basedOn&&y.length<32&&!f.has(h.basedOn);)f.add(h.basedOn),y.unshift(h.basedOn),h=t?.getStyle(h.basedOn);let g={...e.formatting??{},styleCascade:{...i?{selectedStyleId:i}:{},...r?.styleId?{defaultStyleId:r.styleId}:{},...y.length>0?{basedOnStyleIds:y}:{}}},k={styleId:i??null,width:e.formatting?.width?.value??null,widthType:e.formatting?.width?.type??null,justification:e.formatting?.justification??null,columnWidths:e.columnWidths??null,tableLayout:e.formatting?.layout??null,floating:e.formatting?.floating??null,cellMargins:c??null,look:e.formatting?.look??null,bidi:e.formatting?.bidi||null,_originalFormatting:g};e.propertyChanges?.length&&(k.tblPrChange=e.propertyChanges);let w=tn(e),T=Ue(e);return {attrs:k,rows:e.rows.map((v,P)=>rn(v,e,P,w,l,c,n,a??r,T))}}function sn(e){return Ke(pe(e))}function an(e){let t=0;for(let n of e.units){let r=n.kind==="text"?n.text.length:1;if(n.commentId!==void 0&&n.commentId!==0){let i=e.commentCoverage.get(n.commentId),o=i?.[i.length-1];o&&o[1]===t?o[1]=t+r:i?i.push([t,t+r]):e.commentCoverage.set(n.commentId,[[t,t+r]]);}t+=r;}}function z(e,t,n,r){let i={storyId:t,units:[],commentCoverage:new Map};e.plans.push(i);let o=n.length>0?[...n]:[{type:"paragraph",content:[]}],a=0,l=0,d=0,m=null;for(let u of o){if(ne(u))continue;if(u.type==="paragraph"){let f=Zt(u,e.styleResolver,r.extraRunFormatting,r.tableParagraphFormatting);i.units.push(...f.units),i.units.push(Y("pilcrow",{...f.ppr,paraId:u.paraId||`${t}:p${d}`})),d+=1,r.includePageBreaks&&en(u)&&i.units.push(Y("pageBreak",{})),m="paragraph";continue}if(u.type==="table"){let f=a++,h=on(u,e.styleResolver,e.theme),g=h.rows.map((k,w)=>({trPr:k.attrs,cells:k.cells.map((T,v)=>({tcPr:T.attrs,story:me(t,f,w,v)}))}));i.units.push(Y("table",{tblPr:je(h.attrs),grid:ze(h.attrs),rows:g})),h.rows.forEach((k,w)=>{k.cells.forEach((T,v)=>{z(e,me(t,f,w,v),T.content,{includePageBreaks:false,appendBodyTail:false,seedComments:false,extraRunFormatting:T.extraRunFormatting,tableParagraphFormatting:T.paragraphFormatting});});}),m="table";continue}let c=l++,y=Ve(t,c);i.units.push(Y("blockSdt",{...sn(u.properties),story:y})),z(e,y,u.content,{includePageBreaks:r.includePageBreaks,appendBodyTail:false,seedComments:false,tableParagraphFormatting:r.tableParagraphFormatting}),m="blockSdt";}r.appendBodyTail&&(m==="table"||m==="blockSdt")&&i.units.push(Y("pilcrow",{hangingIndent:false,paraId:`${t}:p${d}`})),r.seedComments&&an(i);}function ln(e){let t=[{op:"delete",index:0,len:1}],n=0,r="",i={},o=H(i),a=()=>{r&&(t.push({op:"insert",index:n,text:r,attrs:i}),n+=r.length,r="");};for(let l of e)if(l.kind==="text"){let d=H(l.attrs);r&&d!==o&&a(),i=l.attrs,o=d,r+=l.text;}else a(),t.push({op:"insertEmbed",index:n,kind:l.embedKind,payload:l.payload,attrs:l.attrs}),n+=1;return a(),t}function dn(e,t){let n=ln(t.units);for(let[r,i]of t.commentCoverage)n.push({op:"setComment",id:String(r),ranges:i,author:"",date:"",body:null});e.applySeedRawOps(t.storyId,n);}function un(e,t){let n={styleResolver:t.package.styles?d(t.package.styles):null,theme:t.package.theme??null,plans:[]};z(n,"body",t.package.document.content,{includePageBreaks:true,appendBodyTail:true,seedComments:true});for(let[r,i]of t.package.headers??[])z(n,oe(r),i.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let[r,i]of t.package.footers??[])n.plans.some(o=>o.storyId===oe(r))||z(n,oe(r),i.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let r of t.package.footnotes??[])z(n,Xe(r.id),r.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let r of t.package.endnotes??[])z(n,qe(r.id),r.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let r of n.plans)e.createStory(r.storyId,"","Normal","left");for(let r of n.plans)dn(e,r);}var W=class extends Error{constructor(t){super(t),this.name="ContentControlValueError";}};function ae(e,t,n){let r=new RegExp(`<${t}\\b[^>]*>`).exec(e);if(!r)return;let i=new RegExp(`\\b${n}="([^"]*)"`).exec(r[0]);return i?i[1]:void 0}function ke(e,t,n,r){let o=new RegExp(`<${t}\\b[^>]*?(/?)>`).exec(e);if(!o)return e;let a=o[0],l=o[1]==="/",d=a.slice(1,l?-2:-1),u=new RegExp(`\\b${n}="[^"]*"`).test(d)?d.replace(new RegExp(`\\b${n}="[^"]*"`),()=>`${n}="${r}"`):`${d} ${n}="${r}"`;return e.replace(a,()=>`<${u}${l?"/>":">"}`)}function cn(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function pn(e,t){if(!e)return t;let n=parseInt(e,16);return Number.isNaN(n)||n<0||n>1114111||n>=55296&&n<=57343?t:String.fromCodePoint(n)}function fn(e,t,n){let[r,i,o]=e.slice(0,10).split("-").map(c=>parseInt(c,10));if(!it(r,i,o))return e;let a=t&&t.trim()?t:"M/d/yyyy",l=c=>String(c).padStart(2,"0"),d=new Date(Date.UTC(r,i-1,o)),m=c=>{try{return new Intl.DateTimeFormat(n||"en",{month:c,timeZone:"UTC"}).format(d)}catch{return new Intl.DateTimeFormat("en",{month:c,timeZone:"UTC"}).format(d)}},u={yyyy:String(r),yy:String(r).slice(-2),MMMM:m("long"),MMM:m("short"),MM:l(i),M:String(i),dd:l(o),d:String(o)};return a.replace(/yyyy|yy|MMMM|MMM|MM|M|dd|d/g,c=>u[c])}function it(e,t,n){if(!e||!t||!n)return false;let r=new Date(Date.UTC(e,t-1,n));return r.getUTCFullYear()===e&&r.getUTCMonth()===t-1&&r.getUTCDate()===n}function Se(e,t){return e?{type:"paragraph",content:[{type:"run",content:[{type:"text",text:e}],...t?{formatting:{fontFamily:{ascii:t,hAnsi:t,eastAsia:t,cs:t}}}:{}}]}:{type:"paragraph",content:[]}}function gn(e){return e&&e.replace(/<w:showingPlcHdr\b[^>]*\/>/g,"").replace(/<w:showingPlcHdr\b[^>]*>[\s\S]*?<\/w:showingPlcHdr>/g,"")}function Re(e,t){let n=gn(t);return {...e,showingPlaceholder:false,rawPropertiesXml:(n??t)||void 0}}function we(e,t){let n=e.rawPropertiesXml??"";switch(t.kind){case "dropdown":{if(e.sdtType!=="dropDownList"&&e.sdtType!=="comboBox")throw new W(`Control is '${e.sdtType}', not a dropdown/combo box.`);let r=e.listItems?.find(m=>m.value===t.value||m.displayText===t.value);if(!r&&e.sdtType==="dropDownList")throw new W(`'${t.value}' is not one of the control's list items.`);let i=r?.value??t.value,o=r?.displayText??t.value,a=r?e.listItems?.indexOf(r):void 0,l=e.sdtType==="comboBox"?"w:comboBox":"w:dropDownList",d=ke(n,l,"w:lastValue",cn(i));return {properties:{...Re(e,d),listLastValue:i,controlState:{...e.controlState,value:o,selectedValue:i,selectedIndex:a,placeholder:false}},content:[Se(o)]}}case "checkbox":{if(e.sdtType!=="checkbox")throw new W(`Control is '${e.sdtType}', not a checkbox.`);if(ae(n,"w14:checked","w14:val")==null)throw new W("Checkbox control has no <w14:checked> state to update (not a Word checkbox).");let r=t.checked?"w14:checkedState":"w14:uncheckedState",i=pn(ae(n,r,"w14:val"),t.checked?"\u2612":"\u2610"),o=ae(n,r,"w14:font"),a=ke(n,"w14:checked","w14:val",t.checked?"1":"0");return {properties:{...Re(e,a),checked:t.checked,controlState:{...e.controlState,checked:t.checked,value:i,placeholder:false}},content:[Se(i,o)]}}case "date":{if(e.sdtType!=="date")throw new W(`Control is '${e.sdtType}', not a date control.`);let r=t.date.slice(0,10),[i,o,a]=/^\d{4}-\d{2}-\d{2}$/.test(r)?r.split("-").map(Number):[];if(!it(i,o,a))throw new W(`Date must be ISO yyyy-mm-dd, got '${t.date}'.`);let l=`${r}T00:00:00`,d=ke(n,"w:date","w:fullDate",l),m=e.dateState?.format??e.dateFormat??ae(n,"w:dateFormat","w:val"),u=e.dateState?.language,c=fn(r,m,u);return {properties:{...Re(e,d),dateFormat:m,dateState:{...e.dateState,fullDate:l,format:m},controlState:{...e.controlState,value:r,placeholder:false}},content:[Se(c)]}}}}function st(e){return e.numPrFromStyle!=null&&e.numPr!=null&&JSON.stringify(e.numPr)===JSON.stringify(e.numPrFromStyle)}function dt(e){if(e._originalFormatting){let n=e._originalFormatting,r={...n};return e.alignment!==(n.alignment||void 0)&&(r.alignment=e.alignment||void 0),st(e)?(delete r.numPr,delete r.numPrFromStyle):e.numPr!==n.numPr&&JSON.stringify(e.numPr)!==JSON.stringify(n.numPr)&&(r.numPr=e.numPr||void 0,delete r.numPrFromStyle),e.styleId!==(n.styleId||void 0)&&(r.styleId=e.styleId||void 0),e.pageBreakBefore!==(n.pageBreakBefore||void 0)&&(r.pageBreakBefore=e.pageBreakBefore||void 0),e.widowControl!==(n.widowControl??void 0)&&(r.widowControl=e.widowControl??void 0),e.bidi!==(n.bidi||void 0)&&(r.bidi=e.bidi||void 0),r}if(e.alignment||e.spaceBefore!=null||e.spaceAfter!=null||e.spaceBeforeLines!=null||e.spaceAfterLines!=null||e.beforeAutospacing!=null||e.afterAutospacing!=null||e.lineSpacing||e.indentLeft||e.indentRight||e.indentFirstLine||e.numPr||e.styleId||e.borders||e.shading||e.tabs||e.outlineLevel!=null||e.contextualSpacing||e.pageBreakBefore||e.widowControl!=null||e.bidi)return {alignment:e.alignment||void 0,spaceBefore:e.spaceBefore??void 0,spaceAfter:e.spaceAfter??void 0,spaceBeforeLines:e.spaceBeforeLines??void 0,spaceAfterLines:e.spaceAfterLines??void 0,beforeAutospacing:e.beforeAutospacing??void 0,afterAutospacing:e.afterAutospacing??void 0,lineSpacing:e.lineSpacing||void 0,lineSpacingRule:e.lineSpacingRule||void 0,indentLeft:e.indentLeft||void 0,indentRight:e.indentRight||void 0,indentFirstLine:e.indentFirstLine||void 0,hangingIndent:e.hangingIndent||void 0,numPr:st(e)?void 0:e.numPr||void 0,styleId:e.styleId||void 0,borders:e.borders||void 0,shading:e.shading||void 0,tabs:e.tabs||void 0,outlineLevel:e.outlineLevel??void 0,contextualSpacing:e.contextualSpacing||void 0,pageBreakBefore:e.pageBreakBefore||void 0,widowControl:e.widowControl??void 0,bidi:e.bidi||void 0}}function ut(e){if(e._originalFormatting){let n=e._originalFormatting,r={...n};return e.styleId!==(n.styleId||void 0)&&(r.styleId=e.styleId||void 0),e.justification!==(n.justification||void 0)&&(r.justification=e.justification||void 0),e.floating!==(n.floating||void 0)&&(r.floating=e.floating||void 0),e.tableLayout!==(n.layout||void 0)&&(r.layout=e.tableLayout||void 0),e.look!==(n.look||void 0)&&(r.look=e.look||void 0),e.bidi!==(n.bidi||void 0)&&(r.bidi=e.bidi||void 0),(e.width!==n.width?.value||e.widthType!==n.width?.type)&&(r.width=e.width!=null||e.widthType?{value:e.width??0,type:e.widthType||"dxa"}:void 0),e.cellMargins&&(r.cellMargins=at(e.cellMargins)),r}if(e.styleId||e.width!=null||e.widthType||e.justification||e.tableLayout||e.floating||e.cellMargins||e.look||e.bidi)return {styleId:e.styleId||void 0,width:e.width!=null||e.widthType?{value:e.width??0,type:e.widthType||"dxa"}:void 0,justification:e.justification||void 0,layout:e.tableLayout||void 0,floating:e.floating||void 0,cellMargins:e.cellMargins?at(e.cellMargins):void 0,look:e.look||void 0,bidi:e.bidi||void 0}}function at(e){return {top:e.top!=null?{value:e.top,type:"dxa"}:void 0,bottom:e.bottom!=null?{value:e.bottom,type:"dxa"}:void 0,left:e.left!=null?{value:e.left,type:"dxa"}:void 0,right:e.right!=null?{value:e.right,type:"dxa"}:void 0}}function ct(e){if(e._originalFormatting){let t=e._originalFormatting,n={...t};return e.height!==(t.height?.value||void 0)&&(n.height=e.height?{value:e.height,type:"dxa"}:void 0),e.heightRule!==(t.heightRule||void 0)&&(n.heightRule=e.heightRule||void 0),e.isHeader!==(t.header||void 0)&&(n.header=e.isHeader||void 0),n}if(!(!e.height&&!e.isHeader))return {height:e.height?{value:e.height,type:"dxa"}:void 0,heightRule:e.heightRule||void 0,header:e.isHeader||void 0}}function pt(e){if(e._originalFormatting){let n=e._originalFormatting,r={...n};return e.colspan>1&&(r.gridSpan=e.colspan),e.width!=null&&(r.width={value:e.width,type:e.widthType||"dxa"}),e.verticalAlign!==(n.verticalAlign||void 0)&&(r.verticalAlign=e.verticalAlign||void 0),e.backgroundColor?r.shading=e._originalResolvedFill===e.backgroundColor&&n.shading?n.shading:{fill:{rgb:e.backgroundColor}}:n.shading&&(r.shading=void 0),e.borders&&(r.borders=e.borders),e.margins&&(r.margins=lt(e.margins)),e.textDirection!==(n.textDirection||void 0)&&(r.textDirection=e.textDirection||void 0),r}if(e.colspan>1||e.rowspan>1||e.width!=null||e.verticalAlign||e.backgroundColor||e.borders||e.margins||e.textDirection)return {gridSpan:e.colspan>1?e.colspan:void 0,width:e.width!=null?{value:e.width,type:e.widthType||"dxa"}:void 0,verticalAlign:e.verticalAlign||void 0,textDirection:e.textDirection||void 0,shading:e.backgroundColor?{fill:{rgb:e.backgroundColor}}:void 0,borders:e.borders,margins:e.margins?lt(e.margins):void 0}}function lt(e){let t={};return e.top!=null&&(t.top={value:e.top,type:"dxa"}),e.bottom!=null&&(t.bottom={value:e.bottom,type:"dxa"}),e.left!=null&&(t.left={value:e.left,type:"dxa"}),e.right!=null&&(t.right={value:e.right,type:"dxa"}),t}var mn={paraId:null,textId:null,alignment:null,spaceBefore:null,spaceAfter:null,lineSpacing:null,lineSpacingRule:null,spacingExplicit:null,indentLeft:null,indentRight:null,indentFirstLine:null,hangingIndent:false,numPr:null,numPrFromStyle:null,listNumFmt:null,listIsBullet:null,listMarker:null,listMarkerHidden:null,listMarkerFontFamily:null,listMarkerFontSize:null,listMarkerSuffix:null,listLevelNumFmts:null,listAbstractNumId:null,listStartOverride:null,styleId:null,borders:null,shading:null,tabs:null,pageBreakBefore:null,renderedPageBreakBefore:null,keepNext:null,keepLines:null,widowControl:null,contextualSpacing:null,defaultTextFormatting:null,sectionBreakType:null,bidi:null,outlineLevel:null,bookmarks:null,_originalFormatting:null,_originalRunBoundaries:null,_sectionProperties:null,pPrIns:null,pPrDel:null,pPrChange:null},hn={styleId:null,width:null,widthType:null,justification:null,columnWidths:null,tableLayout:null,floating:null,cellMargins:null,look:null,bidi:null,_originalFormatting:null,tblPrChange:null},yn={height:null,heightRule:null,isHeader:false,_originalFormatting:null,trIns:null,trDel:null,trPrChange:null},bn={colspan:1,rowspan:1,colwidth:null,width:null,widthType:null,verticalAlign:null,backgroundColor:null,borders:null,margins:null,textDirection:null,noWrap:false,_originalFormatting:null,_originalResolvedFill:null,cellMarker:null,tcPrChange:null},kn=new Set(["bold","italic","superscript","subscript","allCaps","smallCaps","emboss","imprint","textShadow","textOutline","hidden","rtl"]);function C(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function A(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function R(e){return typeof e=="string"?e:void 0}function de(e){if(Array.isArray(e))return e.map(de);let t=C(e);if(!t)return e;let n={};for(let[r,i]of Object.entries(t))i!=null&&(n[r]=de(i));return n}function j(e){if(e==null)return "null";if(Array.isArray(e))return `[${e.map(j).join(",")}]`;let t=C(e);return t?`{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${j(t[n])}`).join(",")}}`:JSON.stringify(e)}function X(e){let t={...e};return delete t.hyperlink,delete t.ins,delete t.del,t}function te(e){let t={};e.bold&&(t.bold=true,t.boldCs=true),e.italic&&(t.italic=true,t.italicCs=true);let n=C(e.underline);n&&n.inheritedHyperlink!==true&&(t.underline={style:R(n.style)||"single",color:C(n.color)??null});let r=C(e.strike);r&&(r.double?t.doubleStrike=true:t.strike=true);let i=C(e.textColor);i&&i.inheritedHyperlink!==true&&(t.color={rgb:R(i.rgb)??null,themeColor:i.themeColor??null,themeTint:R(i.themeTint)??null,themeShade:R(i.themeShade)??null}),typeof e.highlight=="string"&&(t.highlight=e.highlight);let o=C(e.fontSize);if(o){let f=A(o.size),h=A(o.sizeCs)??f;f!==void 0&&(t.fontSize=f),h!==void 0&&(t.fontSizeCs=h);}let a=C(e.fontFamily);if(a){let f=R(a.ascii);t.fontFamily={ascii:f??null,hAnsi:R(a.hAnsi)??null,eastAsia:R(a.eastAsia),cs:R(a.cs)||f,asciiTheme:a.asciiTheme??null,hAnsiTheme:R(a.hAnsiTheme),eastAsiaTheme:R(a.eastAsiaTheme),csTheme:R(a.csTheme)};}e.superscript&&(t.vertAlign="superscript"),e.subscript&&(t.vertAlign="subscript"),e.allCaps&&(t.allCaps=true),e.smallCaps&&(t.smallCaps=true);let l=C(e.characterSpacing);if(l){let f=A(l.spacing),h=A(l.position),g=A(l.scale),k=A(l.kerning);f!==void 0&&(t.spacing=f),h!==void 0&&(t.position=h),g!==void 0&&(t.scale=g),k!==void 0&&(t.kerning=k);}e.emboss&&(t.emboss=true),e.imprint&&(t.imprint=true),e.textShadow&&(t.shadow=true);let d=C(e.emphasisMark);d&&(t.emphasisMark=R(d.type)||"dot"),e.textOutline&&(t.outline=true),e.hidden&&(t.hidden=true),e.rtl&&(t.rtl=true);let m=C(e.textEffect);m&&(t.effect=R(m.effect)||"blinkBackground");let u=C(e.modernTextEffects);u?.effects&&(t.modernEffects=u.effects);let c=C(e.runStyle),y=R(c?.styleId);return y&&(t.styleId=y),t}function mt(e,t){let n=[],r="",i=()=>{r&&(n.push({type:"text",text:r}),r="");},o=t.fontFamily?[t.fontFamily.ascii,t.fontFamily.hAnsi,t.fontFamily.eastAsia,t.fontFamily.cs].filter(l=>!!l):[],a=o.length>0&&o.every(l=>l===o[0])?o[0]:null;for(let l of e){let d=l.codePointAt(0)??0;l==="\xAD"?(i(),n.push({type:"softHyphen"})):l==="\u2011"?(i(),n.push({type:"noBreakHyphen"})):a&&d>=61440&&d<=63743?(i(),n.push({type:"symbol",font:a,char:d.toString(16).toUpperCase().padStart(4,"0")})):r+=l;}return i(),n}function Ie(e,t){let n=te(X(t));return {type:"run",formatting:Object.keys(n).length>0?n:void 0,content:mt(e,n)}}function Sn(e,t){for(let n of t.content){let r=e.content[e.content.length-1];r?.type==="text"&&n.type==="text"?r.text+=n.text:e.content.push(n);}}function Rn(e){let t=0xcbf29ce484222325n;for(let n of new TextEncoder().encode(e))t=(t^BigInt(n))*0x100000001b3n,t&=0xffffffffffffffffn;return Number(t&(1n<<53n)-1n)}function xe(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){let t=Number(e);return Number.isFinite(t)?t:Rn(e)}return 0}function V(e,t=false){let n=C(e);if(!n)return null;let r=R(n.author)||"Unknown",i=R(n.date);return {id:xe(n.revisionId??n.id),author:r,...i?{date:i}:{}}}function wn(e){let t=C(e.hyperlink);if(!t)return null;let n=R(t.href)||"";return n.startsWith("#")?{type:"hyperlink",anchor:n.slice(1),tooltip:R(t.tooltip)||void 0,children:[]}:{type:"hyperlink",href:n,tooltip:R(t.tooltip)||void 0,rId:R(t.rId)||void 0,children:[]}}function xn(e){let t=C(e.hyperlink);return t?R(t.href)||"":null}function ve(e,t){let n=R(e.fieldData);if(n&&n.length<=2e6)try{let u=JSON.parse(n),c=u.type==="simpleField"?u.content:u.fieldResult;if((u.type==="simpleField"||u.type==="complexField")&&typeof u.instruction=="string"&&Array.isArray(c)){let y=R(e.displayMode);return u.fieldTree&&y&&(u.fieldTree.displayMode=y),u}}catch{}let r=te(X(t)),i={type:"run",content:[{type:"text",text:R(e.displayText)||""}],...Object.keys(r).length>0?{formatting:r}:{}},o=R(e.instruction)||"",a=R(e.fieldType)||"UNKNOWN",l=e.fldLock===true||void 0,d=e.dirty===true||void 0,m=R(e.displayMode)||"result";return e.fieldKind==="complex"?{type:"complexField",instruction:o,fieldType:a,fieldCode:[],fieldResult:[i],fldLock:l,dirty:d,fieldTree:{version:1,displayMode:m}}:{type:"simpleField",instruction:o,fieldType:a,content:[i],fldLock:l,dirty:d,fieldTree:{version:1,displayMode:m}}}function ht(e){return {type:"mathEquation",display:R(e.display)||"inline",ommlXml:R(e.ommlXml)||"",plainText:R(e.plainText)||void 0}}function Ae(e,t){let n=C(e.rule),r=A(n?.height);if(!n||r===void 0||n.width!=null&&A(n.width)===void 0||n.widthPercent!=null&&A(n.widthPercent)===void 0||typeof n.alignment!="string"||typeof n.noShade!="boolean"||typeof n.color!="string"||typeof n.xml!="string")throw new Error("Malformed horizontalRule embed payload");let i={width:A(n.width)??null,widthPercent:A(n.widthPercent)??null,height:r,alignment:n.alignment,noShade:n.noShade,color:n.color,xml:n.xml},o=te(X(t));return {type:"run",content:[{type:"horizontalRule",rule:i}],...Object.keys(o).length>0?{formatting:o}:{}}}function yt(e){let t=e,n={type:R(t.wrapType)||"inline"};t.distTop!==void 0&&(n.distT=c$1(Number(t.distTop))),t.distBottom!==void 0&&(n.distB=c$1(Number(t.distBottom))),t.distLeft!==void 0&&(n.distL=c$1(Number(t.distLeft))),t.distRight!==void 0&&(n.distR=c$1(Number(t.distRight))),t.wrapText&&(n.wrapText=t.wrapText);let r={type:"image",rId:R(t.rId)||"",src:R(t.src)||"",alt:R(t.alt)||void 0,title:R(t.title)||void 0,shapeType:R(t.shapeType)||void 0,size:{width:c$1(Number(t.width)||0),height:c$1(Number(t.height)||0)},wrap:n};if(t.transform){let a={},l=t.transform.match(/rotate\(([-\d.]+)deg\)/)?.[1];l&&(a.rotation=Number.parseFloat(l)),t.transform.includes("scaleX(-1)")&&(a.flipH=true),t.transform.includes("scaleY(-1)")&&(a.flipV=true),(a.rotation||a.flipH||a.flipV)&&(r.transform=a);}if(t.position?.horizontal&&t.position.vertical&&(r.position={relativeHeight:t.position.relativeHeight,horizontal:{relativeTo:t.position.horizontal.relativeTo||"column",alignment:t.position.horizontal.align,posOffset:t.position.horizontal.posOffset},vertical:{relativeTo:t.position.vertical.relativeTo||"paragraph",alignment:t.position.vertical.align,posOffset:t.position.vertical.posOffset}}),t.borderWidth&&t.borderWidth>0){let a={solid:"solid",dotted:"dot",dashed:"dash",double:"solid",groove:"solid",ridge:"solid",inset:"solid",outset:"solid"};r.outline={width:c$1(t.borderWidth),color:t.borderColor?{rgb:t.borderColor.replace("#","")}:void 0,style:t.borderStyle&&a[t.borderStyle]||"solid"};}t.hlinkHref&&(r.hlinkHref=t.hlinkHref);let i={};t.cropTop!=null&&(i.top=t.cropTop),t.cropRight!=null&&(i.right=t.cropRight),t.cropBottom!=null&&(i.bottom=t.cropBottom),t.cropLeft!=null&&(i.left=t.cropLeft),Object.keys(i).length>0&&(r.crop=i),t.opacity!=null&&t.opacity<1&&(r.opacity=t.opacity),t.layoutInCell!=null&&(r.layoutInCell=t.layoutInCell),t.allowOverlap!=null&&(r.allowOverlap=t.allowOverlap);let o={};return t.effectExtentTop&&(o.top=c$1(t.effectExtentTop)),t.effectExtentBottom&&(o.bottom=c$1(t.effectExtentBottom)),t.effectExtentLeft&&(o.left=c$1(t.effectExtentLeft)),t.effectExtentRight&&(o.right=c$1(t.effectExtentRight)),Object.keys(o).length>0&&(r.padding=o),{type:"run",content:[{type:"drawing",image:r}]}}function Tn(e){let t=R(e);if(!(!t||t.length>2e6))try{let n=JSON.parse(t);return n?.type!=="shape"||typeof n.shapeType!="string"?void 0:(C(n.size)||(n.size={width:0,height:0}),n)}catch{return}}function bt(e){let t=R(e.chartJson);if(!t)return null;try{let n=JSON.parse(t);return n?.type!=="chart"||typeof n.chartType!="string"?null:{type:"run",content:[{type:"chart",chart:n}]}}catch{return null}}function kt(e){let t=Tn(e.shapeJson)??{type:"shape",shapeType:"rect",size:{width:0,height:0}},n=R(e.shapeType);n&&(t.shapeType=n);let r=R(e.shapeId);if(r&&(t.id=r),e.width&&(t.size={...t.size,width:c$1(Number(e.width))}),e.height&&(t.size={...t.size,height:c$1(Number(e.height))}),Array.isArray(e.geometryPath)&&e.geometryPath.length>0&&(t.geometryPath=e.geometryPath),e.fillType==="gradient"&&typeof e.gradientStops=="string")try{let o=JSON.parse(e.gradientStops);t.fill={type:"gradient",gradient:{type:R(e.gradientType)||"linear",angle:A(e.gradientAngle)||void 0,stops:o.map(a=>({position:a.position,color:{rgb:a.color.replace("#","")}}))}};}catch{t.fill={type:"solid",color:{rgb:(R(e.fillColor)||"000000").replace("#","")}};}else typeof e.fillColor=="string"?t.fill={type:R(e.fillType)||"solid",color:{rgb:e.fillColor.replace("#","")}}:e.fillType==="none"&&(t.fill={type:"none"});if(typeof e.outlineWidth=="number"&&e.outlineWidth>0){let o={solid:"solid",dotted:"dot",dashed:"dash"},a=R(e.outlineStyle);t.outline={width:c$1(e.outlineWidth),color:typeof e.outlineColor=="string"?{rgb:e.outlineColor.replace("#","")}:void 0,style:a&&o[a]||"solid"};}let i={};if(typeof e.rotation=="number")i.rotation=e.rotation;else if(typeof e.transform=="string"){let o=e.transform.match(/rotate\(([-\d.]+)deg\)/)?.[1];o&&(i.rotation=Number.parseFloat(o));}return (e.flipH||String(e.transform||"").includes("scaleX(-1)"))&&(i.flipH=true),(e.flipV||String(e.transform||"").includes("scaleY(-1)"))&&(i.flipV=true),(i.rotation||i.flipH||i.flipV)&&(t.transform=i),{type:"run",content:[{type:"shape",shape:t}]}}function Cn(e){let t=fe(e),n=R(e.propertiesJson);if(n&&n.length<=1e6)try{let a=JSON.parse(n);a&&typeof a=="object"&&typeof a.sdtType=="string"&&(t=a);}catch{}let r=[];for(let a of Array.isArray(e.content)?e.content:[]){let l=C(a),d=R(l?.kind);if(!l||!d)continue;let m=C(l.attrs)??{};if(d==="text"){let u=R(l.text);u!==void 0&&r.push({kind:"text",text:u,attributes:m});continue}r.push({kind:"embed",embedKind:d,payload:C(l.payload)??{},attributes:m});}let i=Te(ue(r)),o=St(e.value);if(o)try{let a=we(t,o);t=a.properties;let l=a.content[0];i=Te(l?.type==="paragraph"?l.content:[]);}catch{}return {type:"inlineSdt",properties:t,content:i}}function Te(e){return e.filter(t=>t.type==="run"||t.type==="hyperlink"||t.type==="simpleField"||t.type==="complexField"||t.type==="inlineSdt"||t.type==="mathEquation")}function St(e){let t=C(e);return t?.kind==="checkbox"&&typeof t.checked=="boolean"?{kind:"checkbox",checked:t.checked}:t?.kind==="dropdown"&&typeof t.value=="string"?{kind:"dropdown",value:t.value}:t?.kind==="date"&&typeof t.date=="string"?{kind:"date",date:t.date}:null}function Rt(e){if(e.modelKind!=="commentReference")return null;let t=A(e.commentId);return {type:"run",content:[{type:"commentReference",...t!==void 0?{id:t}:{}}]}}function ft(e){if(e.kind==="text")return Ie(e.text,e.attributes);switch(e.embedKind){case "break":return {type:"run",content:[{type:"break",breakType:"textWrapping"}]};case "tab":return {type:"run",content:[{type:"tab"}]};case "image":return yt(e.payload);case "horizontalRule":return Ae(e.payload,e.attributes);case "shape":return kt(e.payload);case "chart":return bt(e.payload);case "field":return Rt(e.payload)??ve(e.payload,e.attributes);case "math":return ht(e.payload);case "sdt":return Cn(e.payload);case "noteRef":{let t=e.payload.footnoteRefId,n=e.payload.endnoteRefId;return {type:"run",content:[t!==void 0?{type:"footnoteRef",id:xe(t)}:{type:"endnoteRef",id:xe(n)}]}}default:return null}}function Pn(e,t){let n;if(e.kind==="embed"&&e.embedKind==="image")n=yt(e.payload);else if(e.kind==="embed"&&e.embedKind==="horizontalRule")n=Ae(e.payload,e.attributes);else if(e.kind==="embed"&&e.embedKind==="shape")n=kt(e.payload);else if(e.kind==="embed"&&e.embedKind==="chart")n=bt(e.payload)??{type:"run",content:[]};else if(e.kind==="text"){let o=te(X(e.attributes));n={type:"run",content:[{type:"text",text:e.text}],...Object.keys(o).length>0?{formatting:o}:{}};}else n={type:"run",content:[]};let i=(C(e.attributes.ins)??C(e.attributes.del))?.isMovePair===true;return e.attributes.ins?i?{type:"moveTo",info:t,content:[n]}:{type:"insertion",info:t,content:[n]}:i?{type:"moveFrom",info:t,content:[n]}:{type:"deletion",info:t,content:[n]}}function In(e,t){if(t.kind==="text"){e.children.push(Ie(t.text,t.attributes));return}if(t.embedKind==="break")e.children.push({type:"run",content:[{type:"break",breakType:"textWrapping"}]});else if(t.embedKind==="tab")e.children.push({type:"run",content:[{type:"tab"}]});else if(t.embedKind==="horizontalRule")e.children.push(Ae(t.payload,t.attributes));else if(t.embedKind==="field"){let n=Rt(t.payload)??ve(t.payload,t.attributes);n.type==="run"?e.children.push(n):(e.structuredChildren??(e.structuredChildren=[...e.children])).push(n);}else t.embedKind==="math"&&(e.structuredChildren??(e.structuredChildren=[...e.children])).push(ht(t.payload));}function gt(e){let t=[];for(let n of e){let r={...n.attributes};delete r.fieldResult;let i=n.kind==="embed"&&n.embedKind==="tab"?{kind:"text",text:" ",attributes:r}:{...n,attributes:r},o=t.at(-1);i.kind==="text"&&o?.kind==="text"&&j(o.attributes)===j(r)?o.text+=i.text:t.push(i);}return j(t)}function vn(e){let t=[];for(let[i,o]of e.entries()){if(o.kind!=="embed"||o.embedKind!=="field")continue;let a=A(C(o.payload.resultProjection)?.id);a!==void 0&&t.push({id:a,owner:o,position:i});}if(t.length===0)return e;let n=new Map,r=e.filter((i,o)=>{let a=C(i.attributes.fieldResult),l=A(a?.id),d=A(a?.index),m=t.find(f=>f.id===l&&f.position>o)?.owner;if(d===void 0||!m)return true;let u=n.get(m)??new Map,c=u.get(d)??[],y={...i.attributes};return delete y.fieldResult,c.push({...i,attributes:y}),u.set(d,c),n.set(m,u),false});for(let{owner:i}of t){let o=ve(i.payload,i.attributes);if(o.type!=="complexField")continue;let a=C(i.payload.resultProjection),l=Array.isArray(a?.children)?a.children:[],d=new Map;for(let c of l){let y=C(c),f=A(y?.index);if(f===void 0||!Array.isArray(y?.items))continue;let h=n.get(i)?.get(f)??[];if(gt(h)===gt(y.items))continue;let g=Te(ue(h)),k=f<0?o.structuredCode?.inline?.[-f-1]:o.structuredResult?.inline?.[f];k?.type==="hyperlink"&&g.length===1&&g[0]?.type==="hyperlink"&&(g[0]={...k,...g[0],structuredChildren:g[0].structuredChildren}),d.set(f,g);}if(d.size===0)continue;let m=(o.structuredResult?.inline??[]).flatMap((c,y)=>d.get(y)??[c]),u=o.structuredCode?.inline?.flatMap((c,y)=>d.get(-y-1)??[c]);o.structuredResult={...o.structuredResult,inline:m},u&&(o.structuredCode={...o.structuredCode,inline:u}),o.fieldTree&&(o.fieldTree.result={...o.fieldTree.result,inline:m},u&&(o.fieldTree.code={...o.fieldTree.code,inline:u})),o.fieldResult=m.flatMap(c=>c.type==="run"?[c]:c.type==="hyperlink"?c.children.filter(y=>y.type==="run"):[]),i.payload={...i.payload,fieldData:JSON.stringify(o)};}return r}function ue(e){e=vn(e);let t=[],n=null,r=null,i=null,o=()=>{n&&t.push(n),n=null,r=null;},a=()=>{i&&t.push(i),i=null;};for(let l of e){if(l.kind==="embed"&&l.embedKind==="noteRef"){o(),a();let c=ft(l);c&&t.push(c);continue}let d=V(l.attributes.ins??l.attributes.del);if(d){o(),a(),t.push(Pn(l,d));continue}let m=xn(l.attributes);if(m!==null){o();let c=i?i.href||(i.anchor?`#${i.anchor}`:""):null;(!i||c!==m)&&(a(),i=wn(l.attributes)),i&&In(i,l);continue}if(a(),l.kind==="text"){let c=j(X(l.attributes)),y=Ie(l.text,l.attributes);n&&r===c?Sn(n,y):(o(),n=y,r=c);continue}o();let u=ft(l);u&&t.push(u);}return o(),a(),t}function An(e){if(!e)return {};let t={};for(let n of e.split("|")){let r=n.indexOf(":");if(r<=0)return null;let i=n.slice(0,r),o;try{o=JSON.parse(n.slice(r+1));}catch{return null}i==="comment"||i==="footnoteRef"||(kn.has(i)?t[i]=true:i==="highlight"?t.highlight=o.color:i==="insertion"||i==="deletion"?t[i==="insertion"?"ins":"del"]=de({id:o.revisionId,author:o.author,date:o.date,isMovePair:o.isMovePair}):t[i]=de(o));}return t}function Fn(e){return e.noteMarks?.length?e.noteMarks.map(t=>({type:t==="endnote"?"endnoteRefMark":"footnoteRefMark"})):null}function Yn(e,t,n){if(!n?.length||!e.every(l=>l.type==="run"&&l.content.every(d=>d.type==="text"))||t.some(l=>l.kind!=="text"||l.attributes.hyperlink)||n.some(l=>l.noteMarks?.length&&l.text.length>0)||t.map(l=>l.kind==="text"?l.text:"").join("")!==n.map(l=>l.text).join(""))return e;let i=0,o=0,a=[];for(let l of n){let d=An(l.marksKey);if(!d)return e;a.push(d);let m=l.text.length;for(;m>0;){let u=t[i];if(u?.kind!=="text"||j(X(u.attributes))!==j(d))return e;let c=u.text.length-o,y=Math.min(m,c);m-=y,o+=y,o===u.text.length&&(i+=1,o=0);}}return i!==t.length||o!==0?e:n.map((l,d)=>{let m=l.text.length===0?l.formatting:te(a[d]),u={type:"run",content:Fn(l)??mt(l.text,m??{})};return m&&Object.keys(m).length>0&&(u.formatting=m),l.propertyChanges?.length&&(u.propertyChanges=l.propertyChanges),u})}function le(e){return e.content.reduce((t,n)=>n.type==="text"||n.type==="instrText"?t+n.text.length:n.type==="symbol"?t+n.char.length:n.type==="tab"||n.type==="softHyphen"||n.type==="noBreakHyphen"||n.type==="footnoteRef"||n.type==="endnoteRef"||n.type==="horizontalRule"?t+1:t,0)}function K(e){switch(e.type){case "run":return le(e);case "hyperlink":return e.children.reduce((t,n)=>t+(n.type==="run"?le(n):0),0);case "simpleField":return e.content.reduce((t,n)=>t+K(n),0);case "complexField":return e.fieldResult.reduce((t,n)=>t+le(n),0);case "inlineSdt":return e.content.reduce((t,n)=>t+K(n),0);case "insertion":case "deletion":case "moveFrom":case "moveTo":return e.content.reduce((t,n)=>t+(n.type==="run"?le(n):0),0);case "mathEquation":return e.plainText?.length??0;default:return 0}}function Mn(e,t){if(!e.content.every(i=>i.type==="text"))return [e,null];let n=e.content.map(i=>i.type==="text"?i.text:"").join(""),r=i=>i?{type:"run",...e.formatting?{formatting:e.formatting}:{},...e.propertyChanges?{propertyChanges:e.propertyChanges}:{},content:[{type:"text",text:i}]}:null;return [r(n.slice(0,t)),r(n.slice(t))]}function Ce(e,t,n=r=>r.kind==="start"?{type:"commentRangeStart",id:r.id}:{type:"commentRangeEnd",id:r.id}){if(t.length===0)return e;let r=[...t].sort((d,m)=>d.offset-m.offset||(d.kind===m.kind?d.id-m.id:d.kind==="end"?-1:1)),i=[],o=0,a=0,l=d=>{for(;a<r.length&&r[a].offset===d;){let m=r[a++];i.push(n(m));}};l(0);for(let d of e){let m=K(d),u=r.slice(a).map(c=>c.offset).filter(c=>c>o&&c<o+m);if(d.type==="run"&&d.content.every(c=>c.type==="text")){let c=d,y=0;for(let f of u){if(!c)break;let[h,g]=Mn(c,f-o-y);h&&i.push(h),l(f),c=g,y=f-o;}c&&i.push(c);}else i.push(d);o+=m,l(o);}return l(o),i}function _n(e){if(!Array.isArray(e.bookmarks))return [];let t=[];for(let n of e.bookmarks){let r=C(n),i=A(r?.id);if(!r||i===void 0)continue;let o=A(r.offset)??0,a={name:R(r.name),colFirst:A(r.colFirst),colLast:A(r.colLast)};r.kind==="start"?t.push({id:i,kind:"start",offset:o,...a}):r.kind==="end"?t.push({id:i,kind:"end",offset:o,...a}):(t.push({id:i,kind:"start",offset:0,...a}),t.push({id:i,kind:"end",offset:Number.MAX_SAFE_INTEGER,...a}));}return t}function Bn(e,t){if(!t)return e;let n=e.reduce((o,a)=>o+K(a),0),r=[],i=0;for(let[o,a]of t.content.entries())a.type==="rawXml"&&r.push({id:o,kind:"start",offset:Math.min(i,n)}),i+=K(a);return Ce(e,r,o=>t.content[o.id])}function On(e){let t={...mn,...e};return t.styleId=e.pStyle??null,t._sectionProperties=e.sectPr??null,delete t.pStyle,delete t.sectPr,t}function Nn(e,t,n,r,i){let o=On(t),a=ue(n);a=Yn(a,n,Array.isArray(o._originalRunBoundaries)?o._originalRunBoundaries:void 0),a=Bn(a,i),a=Ce(a,r);let l=_n(t).map(c=>({...c,offset:c.offset===Number.MAX_SAFE_INTEGER?a.reduce((y,f)=>y+K(f),0):c.offset}));l.length>0&&(a=Ce(a,l,c=>{let y=c;return y.kind==="start"?{type:"bookmarkStart",id:y.id,name:y.name||"",...y.colFirst!==void 0?{colFirst:y.colFirst}:{},...y.colLast!==void 0?{colLast:y.colLast}:{},position:{offset:y.offset}}:{type:"bookmarkEnd",id:y.id,position:{offset:y.offset}}}));let d={type:"paragraph",paraId:e||void 0,textId:i?.textId,formatting:dt(o),content:a};i?.renderedPageBreakBefore&&(d.renderedPageBreakBefore=true);let m=V(t.pPrIns,true),u=V(t.pPrDel,true);return m&&(d.pPrIns=m),u&&(d.pPrDel=u),Array.isArray(t.pPrChange)&&t.pPrChange.length>0&&(d.propertyChanges=t.pPrChange),t.sectPr?d.sectionProperties=t.sectPr:t.sectionBreakType&&(d.sectionProperties={sectionStart:t.sectionBreakType}),d}function En(e){let t=e[0]?.cells,n=e[e.length-1]?.cells,r=t?.[0]?.formatting?.borders;if(!t||!n||!r)return;let i={top:r.top,left:r.left,bottom:n[0]?.formatting?.borders?.bottom,right:t[t.length-1]?.formatting?.borders?.right,insideH:e.length>1?r.bottom:void 0,insideV:t.length>1?r.right:void 0},o=Object.entries(i).filter(([,a])=>a!==void 0);return o.length>0?Object.fromEntries(o):void 0}function Ln(e){let t=new Map;e.forEach((r,i)=>{let o=0;for(let a of r.cells){let l=o;if(o+=a.formatting?.gridSpan??1,a.formatting?.vMerge){let d=t.get(l)??[];d.push({rowIndex:i,cell:a}),t.set(l,d);}}});let n=r=>{r.formatting&&(delete r.formatting.vMerge,Object.keys(r.formatting).length===0&&(r.formatting=void 0));};for(let r of t.values()){let i=null,o=0,a=-1,l=()=>{i&&o<2&&n(i),i=null,o=0;};for(let d of r){let m=d.cell.formatting?.vMerge;m==="restart"?(l(),i=d.cell,o=1,a=d.rowIndex):m==="continue"&&(i&&d.rowIndex===a+1?(o+=1,a=d.rowIndex):(l(),n(d.cell)));}l();}}function Dn(e,t){let n={...bn,...t.tcPr??{}},r=t.story&&e.storyIds.has(t.story)?e.storyToBlocks(t.story):[],i={type:"tableCell",formatting:pt(n),content:r},o=n.cellMarker;if(o){let a=V(o.info,true)??{id:0,author:"Unknown"};o.kind==="ins"?i.structuralChange={type:"tableCellInsertion",info:a}:o.kind==="del"?i.structuralChange={type:"tableCellDeletion",info:a}:i.structuralChange={type:"tableCellMerge",info:a,...o.vMerge?{vMerge:o.vMerge}:{},...o.vMergeOrig?{vMergeOrig:o.vMergeOrig}:{}};}return Array.isArray(n.tcPrChange)&&n.tcPrChange.length>0&&(i.propertyChanges=n.tcPrChange),i}function Jn(e,t){let n=Array.isArray(t.rows)?t.rows:[],r=[],i=[],o=0;n.forEach((f,h)=>{let g=0;for(let k of Array.isArray(f.cells)?f.cells:[]){for(;r[h]?.[g];)g+=1;let w=k.tcPr??{},T=A(w.rowspan)||1,v=A(w.colspan)||1;i.push({row:h,col:g,rowspan:T,colspan:v,cell:Dn(e,k)});for(let P=h;P<h+T;P+=1){r[P]??(r[P]=[]);for(let I=g;I<g+v;I+=1)r[P][I]=true;}g+=v,o=Math.max(o,g);}});let a=new Map(i.map(f=>[`${f.row}-${f.col}`,f])),l=new Map;for(let f of i)for(let h=f.row;h<f.row+f.rowspan;h+=1)for(let g=f.col;g<f.col+f.colspan;g+=1)l.set(`${h}-${g}`,f);let d=n.map((f,h)=>{let g=[];for(let P=0;P<o;){let I=a.get(`${h}-${P}`);if(I){let N={...I.cell.formatting??{}};I.colspan>1?N.gridSpan=I.colspan:delete N.gridSpan,I.rowspan>1?N.vMerge="restart":N.vMerge!=="restart"&&N.vMerge!=="continue"&&delete N.vMerge,g.push({...I.cell,formatting:Object.keys(N).length>0?N:void 0}),P+=I.colspan;continue}let M=l.get(`${h}-${P}`);if(!M){P+=1;continue}let S={...M.cell.formatting??{}};M.colspan>1?S.gridSpan=M.colspan:delete S.gridSpan,S.vMerge="continue",g.push({...M.cell,content:[],formatting:S}),P+=M.colspan;}let k={...yn,...f.trPr??{}},w={type:"tableRow",formatting:ct(k),cells:g},T=V(k.trIns,true),v=V(k.trDel,true);return T?w.structuralChange={type:"tableRowInsertion",info:T}:v&&(w.structuralChange={type:"tableRowDeletion",info:v}),Array.isArray(k.trPrChange)&&k.trPrChange.length>0&&(w.propertyChanges=k.trPrChange),w});Ln(d);let m=Array.isArray(t.grid)?t.grid.filter(f=>typeof f=="number"):[],u={...hn,...t.tblPr??{},columnWidths:m.length>0?m:void 0},c=ut(u);if(!c?.borders){let f=En(d);f&&(c={...c??{},borders:f});}let y={type:"table",columnWidths:u.columnWidths||void 0,formatting:c,rows:d};return Array.isArray(u.tblPrChange)&&u.tblPrChange.length>0&&(y.propertyChanges=u.tblPrChange),y}function Un(){return {type:"paragraph",content:[{type:"run",content:[{type:"break",breakType:"page"}]}]}}function Fe(e){return e.type==="insertion"||e.type==="deletion"||e.type==="moveFrom"||e.type==="moveTo"?e.content.length>0&&e.content.every(Fe):e.type==="run"&&e.content.length>0&&e.content.every(t=>t.type==="footnoteRefMark"||t.type==="endnoteRefMark")}function Wn(e){return e.some(t=>t.type==="paragraph"&&t.content.some(Fe))}function jn(e,t){if(Wn(e))return e;let n=t.find(d=>d.type==="paragraph")?.content??[],r=n.findIndex(d=>!Fe(d)),i=n.slice(0,r<0?n.length:r);if(i.length===0)return e;let o=e.findIndex(d=>d.type==="paragraph");if(o<0)return e;let a=e[o],l=[...e];return l[o]={...a,content:[...i,...a.content]},l}function zn(e){let t=new Map,n=r=>{for(let i of r)if(i.type==="paragraph")i.paraId&&!t.has(i.paraId)&&t.set(i.paraId,i);else if(i.type==="table")for(let o of i.rows)for(let a of o.cells)n(a.content);else i.type==="blockSdt"&&n(i.content);};n(e.package.document.content);for(let r of e.package.headers?.values()??[])n(r.content);for(let r of e.package.footers?.values()??[])n(r.content);for(let r of e.package.footnotes??[])n(r.content);for(let r of e.package.endnotes??[])n(r.content);return t}function $n(e){let t=new Map,n=(r,i)=>{t.set(r,i);let o=0,a=0;for(let l of i){if(l.type==="blockSdt"){n(`${r}:sdt${a++}`,l.content);continue}if(l.type!=="table")continue;let d=o++;l.rows.forEach((m,u)=>{m.cells.forEach((c,y)=>{n(`${r}:t${d}:r${u}c${y}`,c.content);});});}};n("body",e.package.document.content);for(let[r,i]of e.package.headers??[])n(`hf:${r}`,i.content);for(let[r,i]of e.package.footers??[])n(`hf:${r}`,i.content);for(let r of e.package.footnotes??[])n(`fn:${r.id}`,r.content);for(let r of e.package.endnotes??[])n(`en:${r.id}`,r.content);return t}function Hn(e,t){let n=new Map;for(let r of t??[]){let i;try{i=e.resolveComment(String(r.id));}catch{continue}let o=new Map;for(let a of i){let l=o.get(a.story)??[];l.push(a),o.set(a.story,l);}for(let[a,l]of o){if(l.length===0)continue;let d=Math.min(...l.map(c=>c.start)),m=Math.max(...l.map(c=>c.end)),u=n.get(a)??[];u.push({id:r.id,start:d,end:m}),n.set(a,u);}}return n}function Vn(e,t){let n=0;for(let r=0;r<t.length;r+=1){let i=t[r];if(!ne(i))continue;let o=t.slice(r+1).find(d=>d.type==="paragraph"&&d.paraId&&e.some(m=>m.type==="paragraph"&&m.paraId===d.paraId)),a=o?.type==="paragraph"?e.findIndex(d=>d.type==="paragraph"&&d.paraId===o.paraId):-1,l=a>=0?a:Math.min(r+n,e.length);e.splice(l,0,i),n=Math.max(0,l-r);}return e}var Pe=class{constructor(t,n){b(this,"session",t);b(this,"storyIds");b(this,"baseParagraphs");b(this,"baseStories");b(this,"comments");this.storyIds=new Set(t.storyIds()),this.baseParagraphs=zn(n),this.baseStories=$n(n),this.comments=Hn(t,n.package.document.comments);}storyToBlocks(t){let n=[],r=this.baseStories.get(t),i=r?.filter(f=>f.type==="paragraph"),o=this.session.storySegments(t),a=this.comments.get(t)??[],l=[],d=0,m=0,u=0,c=f=>{let h=[];for(let g of a)g.start>=d&&g.start<=f&&h.push({id:g.id,kind:"start",offset:g.start-d}),g.end>=d&&g.end<=f&&h.push({id:g.id,kind:"end",offset:g.end-d});return h},y=(f,h)=>{let g=0;for(let k=0;k<f.length;k+=1)f[k]===" "&&(k>g&&l.push({kind:"text",text:f.slice(g,k),attributes:h}),l.push({kind:"embed",embedKind:"tab",payload:{},attributes:h}),g=k+1);g<f.length&&l.push({kind:"text",text:f.slice(g),attributes:h});};for(let f of o){if(f.kind==="text"){y(f.text,f.attributes),u+=f.text.length;continue}if(f.kind==="pilcrow"){let h=`${t}:p${m}`,g=f.paraId===h&&!this.baseParagraphs.has(f.paraId)?"":f.paraId;n.push(Nn(g,f.properties,l,c(u),this.baseParagraphs.get(f.paraId)??(f.paraId===h?i?.[m]:void 0))),l=[],m+=1,u+=1,d=u;continue}if(f.embedKind==="table")n.push(Jn(this,f.payload));else if(f.embedKind==="blockSdt"){let h=R(f.payload.story),g=fe(f.payload),k=h&&this.storyIds.has(h)?this.storyToBlocks(h):[],w=St(f.payload.value);if(w)try{let T=we(g,w);g=T.properties,k=T.content;}catch{}n.push({type:"blockSdt",properties:g,content:k});}else if(f.embedKind==="opaque"){let h=C(f.payload.blob);if(h?.type==="pageBreak")n.push(Un());else {let g=r?.[n.length];h?.type==="blockSdt"&&g?.type==="blockSdt"&&n.push(g);}}else l.push(f);u+=1;}return l.length>0&&n.push({type:"paragraph",content:ue(l)}),Vn(n,r??[])}};function Kn(e,t,n={}){let r=new Pe(e,t),i=c=>n.storyIds===void 0||n.storyIds.has(c),o=r.storyIds.has("body")&&i("body")?r.storyToBlocks("body"):t.package.document.content,a=t.package.headers;a&&(n.storyIds===void 0||[...a.keys()].some(c=>i(`hf:${c}`)))&&(a=new Map([...a].map(([c,y])=>{let f=`hf:${c}`;return [c,r.storyIds.has(f)&&i(f)?{...y,content:r.storyToBlocks(f)}:y]})));let l=t.package.footers;l&&(n.storyIds===void 0||[...l.keys()].some(c=>i(`hf:${c}`)))&&(l=new Map([...l].map(([c,y])=>{let f=`hf:${c}`;return [c,r.storyIds.has(f)&&i(f)?{...y,content:r.storyToBlocks(f)}:y]})));let d=(c,y)=>n.storyIds===void 0||c?.some(h=>i(`${y}${h.id}`))?c?.map(h=>{let g=`${y}${h.id}`;return r.storyIds.has(g)&&i(g)?{...h,content:jn(r.storyToBlocks(g),h.content),verbatimXml:void 0}:h}):c,m=d(t.package.footnotes,"fn:"),u=d(t.package.endnotes,"en:");return {...t,package:{...t.package,document:{...t.package.document,content:o},...a?{headers:a}:{},...l?{footers:l}:{},...m?{footnotes:m}:{},...u?{endnotes:u}:{}}}}function Jr(e,t){return !e||!t?e===t:e.anchor.story===t.anchor.story&&e.anchor.paraId===t.anchor.paraId&&e.anchor.offset===t.anchor.offset&&e.head.story===t.head.story&&e.head.paraId===t.head.paraId&&e.head.offset===t.head.offset}function Xn(){if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function"){let e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return Math.floor(Math.random()*4294967295)}function wt(e){return JSON.stringify("revisionId"in e?{revisionId:e.revisionId}:{story:e.story,startPara:e.start.paraId,startOffset:e.start.offset,endPara:e.end.paraId,endOffset:e.end.offset})}function qn(e){return JSON.stringify(e.map(t=>({story:t.story,startPara:t.start.paraId,startOffset:t.start.offset,endPara:t.end.paraId,endOffset:t.end.offset})))}function xt(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.slice().buffer}function Gn(e,t){let n=JSON.parse(e);if(typeof n!="object"||n===null||Array.isArray(n))throw new TypeError("DOCX host metadata must be an object");let r=n;if(!Array.isArray(r.referencedFonts)||!r.referencedFonts.every(o=>typeof o=="string"))throw new TypeError("DOCX host referencedFonts must be a string array");let i=c(r.envelope,xt(t));return {document:i.document,referencedFonts:r.referencedFonts,embeddedFonts:i.embeddedFonts,...i.fontTableRelationshipsXml===void 0?{}:{fontTableRelationshipsXml:i.fontTableRelationshipsXml}}}function Zn(e,t){let n=new Map,r=[],i=false,o=false,a=0,l=0,d=false,m=false,u,c=null,y=[],f=new Map,h=new Map,g=null,k=false,w=0,T=0,v=false,P=null,I=()=>{u=void 0,c=null;},M=()=>{if(!(o||d||l!==0)){d=true;try{for(;!o&&r.length>0;){let s=r.shift();if(!s)break;for(let[p,b]of [...n]){if(o)return;if(n.get(p)===b)try{b(s.update.slice(),s.origin);}catch{}}}}finally{d=false,o&&(r.length=0);}}},S=s=>{I(),l+=1;try{return s()}finally{l-=1,l===0&&M();}},N=s=>s?{anchor:{...s.anchor},head:{...s.head}}:null,x=s=>{m||(e.track_undo(),m=true),s!==void 0&&e.select_story(s);},Tt=()=>{i||(e.set_update_observer((s,p)=>{p!==0&&p!==1||(r.push({update:s.slice(),origin:p===0?"local":"remote"}),M());}),i=true);},Ct=()=>{!i||n.size>0||o||(r.length=0,e.clear_update_observer(),i=false);},Ye=(s,p)=>{let b=s.slice(),F=S(()=>e.open_docx(b,p)),q=Gn(F,b);return P=b,q};return {clientId:t,registerFont:s=>{v||(e.clear_measure_fonts(),v=true);let p=e.register_measure_font(s);return y.push(s.slice()),T+=1,p},clearFonts:()=>{e.clear_measure_fonts(),y.length=0,h.clear(),T+=1,v=true;},measureParagraphJson:s=>{let p=e.measure_paragraph_json(s);return h.set(s,s),p},layoutDocumentJson:s=>{let p=e.layout_document_json(s);return g=s,k=false,w+=1,p},layoutFontRequirementsJson:s=>e.layout_font_requirements_json(s),layoutDocumentWithRegionsJson:s=>{let p=e.layout_document_with_regions_json(s);return g=s,k=true,w+=1,p},layoutDocumentWithRegionsRetainedJson:s=>{let p=e.layout_document_with_regions_retained_json(s);return g=s,k=true,w+=1,p},retainedKernelInputsJson:s=>{if(s!==w)throw new Error(`retained layout revision mismatch: expected ${s}, current ${w}`);return e.retained_kernel_inputs_json()},buildDisplayListJson:s=>e.build_display_list_json(s),buildDisplayListFrame:(s,p)=>e.build_display_list_frame(s,p),residentCaretSnapshot:()=>JSON.parse(e.resident_caret_snapshot_json()),applyInput:(s,p)=>(x(),S(()=>e.apply_input(s,p))),applyDelete:(s,p)=>(x(),S(()=>e.apply_delete(s,p))),applyInputProfiled:(s,p)=>{x();let b=S(()=>e.apply_input_profiled(s,p)),F=JSON.parse(e.apply_input_profile_json());return {frame:b,profile:F}},applyDeleteProfiled:(s,p)=>{x();let b=S(()=>e.apply_delete_profiled(s,p)),F=JSON.parse(e.apply_input_profile_json());return {frame:b,profile:F}},residentWorkerSnapshot:s=>{if(!g||!k&&f.size===0)return null;let p=e.selection(),b=s?.knownFontsRevision===T,F=null;if(s?.knownStateVector)try{F=e.encode_diff(s.knownStateVector.slice());}catch{F=null;}return {clientId:t,state:F??e.encode_state(),selection:JSON.parse(p),fonts:b?[]:y.map(q=>q.slice()),fontsRevision:T,renderInputs:[...f].map(([q,Pt])=>({story:q,env:structuredClone(Pt)})),measureInputs:[...h.values()],layoutInput:g,layoutWithRegions:k,layoutRevision:w}},residentWorkerProbe:()=>!g||!k&&f.size===0?null:{layoutRevision:w},displayHitTestRegionsJson:(s,p,b)=>e.display_hit_test_regions_json(s,p,b),displayVerticalMoveJson:(s,p,b)=>e.display_vertical_move_json(s,p,b),displayRangeRectsJson:(s,p)=>e.display_range_rects_json(s,p),displayRangeRectsRegionJson:(s,p,b,F)=>e.display_range_rects_region_json(s,p,b,F),outlineGlyphJson:(s,p)=>e.outline_glyph_json(s,p),loadState:s=>S(()=>e.load(s)),seedFromDocx:s=>Ye(s,true),openDocx:Ye,materializeDocx:()=>{let s=P,p=e.materialize_docx();return !s||p===void 0?null:b$1(p,xt(s)).document},loadStories:s=>S(()=>JSON.parse(e.load_json(JSON.stringify(s)))),encodeState:()=>e.encode_state(),encodeStateVector:()=>e.encode_state_vector(),encodeStateAsUpdate:s=>s===void 0?e.encode_state():e.encode_diff(s.slice()),applyUpdate:s=>S(()=>JSON.parse(e.apply_update_with_inference(s))),applyLocalUpdate:s=>{x(),S(()=>e.apply_local_update(s));},onUpdate:s=>{if(o)throw new Error("yrs session is destroyed");if(typeof s!="function")throw new TypeError("update listener must be a function");let p=a++;n.set(p,s),Tt();let b=true;return ()=>{b&&(b=false,n.delete(p),Ct());}},encodeStickyPosition:s=>({story:s.story,encoded:e.encode_sticky_position(s.story,s.paraId,s.offset)}),resolveStickyPosition:s=>{try{return JSON.parse(e.resolve_sticky_position(s.story,s.encoded))}catch{return null}},setSelection:(s,p=s)=>{if(s.story!==p.story)throw new Error("yrs selection must stay inside one story");e.set_selection(s.story,s.paraId,s.offset,p.paraId,p.offset),u={anchor:{...s},head:{...p}};},selection:()=>(u!==void 0||(u=JSON.parse(e.selection())),N(u)),encodeSelection:()=>{let s=JSON.parse(e.encoded_selection());return s?{story:s.story,anchor:Uint8Array.from(s.anchor),head:Uint8Array.from(s.head)}:null},resolveSelection:s=>{try{return JSON.parse(e.resolve_encoded_selection(s.story,s.anchor,s.head))}catch{return null}},setCellSelection:s=>e.set_cell_selection(JSON.stringify(s)),cellSelection:()=>JSON.parse(e.cell_selection()),beginUndoCapture:x,historyStories:()=>e.history_stories(),undo:()=>S(()=>e.undo()),redo:()=>S(()=>e.redo()),canUndo:()=>e.can_undo(),canRedo:()=>e.can_redo(),createStory:(s,p,b="Normal",F="left")=>S(()=>JSON.parse(e.create_story(s,p,b,F))),deleteStory:s=>S(()=>e.delete_story(s)),insertTable:(s,p,b,F)=>(x(s.story),S(()=>JSON.parse(e.insert_table(s.story,s.paraId,s.offset,p,b,F?.name,F?.date)))),insertRow:(s,p,b)=>(x(s.story),S(()=>JSON.parse(e.insert_row(JSON.stringify(s),p==="below",b?.name,b?.date)))),insertColumn:(s,p)=>(x(s.story),S(()=>JSON.parse(e.insert_column(JSON.stringify(s),p==="right")))),deleteRow:(s,p)=>(x(s.anchor.story),S(()=>JSON.parse(e.delete_row(JSON.stringify(s),p?.name,p?.date)))),deleteColumn:s=>(x(s.anchor.story),S(()=>JSON.parse(e.delete_column(JSON.stringify(s))))),deleteTable:s=>(x(s.story),S(()=>JSON.parse(e.delete_table(JSON.stringify(s))))),mergeCells:s=>(x(s.anchor.story),S(()=>JSON.parse(e.merge_cells(JSON.stringify(s))))),splitCell:(s,p,b)=>(x(s.story),S(()=>JSON.parse(e.split_cell(JSON.stringify(s),p,b)))),setCellShading:(s,p)=>(x(s.anchor.story),S(()=>JSON.parse(e.set_cell_shading(JSON.stringify(s),p??void 0)))),setCellTextFormat:(s,p)=>(x(s.anchor.story),S(()=>JSON.parse(e.set_cell_text_format(JSON.stringify(s),JSON.stringify(p))))),setCellBorders:(s,p)=>(x(s.anchor.story),S(()=>JSON.parse(e.set_cell_borders(JSON.stringify(s),JSON.stringify(p))))),setColumnWidth:(s,p)=>(x(s.story),S(()=>JSON.parse(e.set_column_width(JSON.stringify(s),p)))),setTableWidth:(s,p)=>(x(s.story),S(()=>JSON.parse(e.set_table_width(JSON.stringify(s),p)))),insertText:(s,p,b)=>(x(s.story),S(()=>JSON.parse(e.insert_text(s.story,s.paraId,s.offset,p,b?.name,b?.date)))),deleteRange:(s,p)=>(x(s.story),S(()=>JSON.parse(e.delete_range(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset,p?.name,p?.date)))),replaceRange:(s,p,b)=>(x(s.story),S(()=>JSON.parse(e.replace_range(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset,p,b?.name,b?.date)))),splitParagraph:(s,p)=>(x(s.story),S(()=>JSON.parse(e.split_paragraph(s.story,s.paraId,s.offset,p?.name,p?.date)))),mergeParagraphs:(s,p,b)=>(x(s),S(()=>JSON.parse(e.merge_paragraphs(s,p,b?.name,b?.date)))),toggleMark:(s,p)=>{x(s.story),S(()=>e.toggle_mark(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset,JSON.stringify(p)));},formatRange:(s,p)=>{x(s.story),S(()=>e.format_range(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset,JSON.stringify(p)));},setHyperlink:(s,p)=>{x(s.story),S(()=>e.set_hyperlink(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset,JSON.stringify(p)));},clearFormatting:s=>{x(s.story),S(()=>e.clear_formatting(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset));},applyParagraphStyle:(s,p,b)=>{x(s.story),S(()=>e.apply_paragraph_style(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset,p,b?.name,b?.date));},setParagraphAttrs:(s,p,b)=>{x(s.story),S(()=>e.set_paragraph_attrs(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset,JSON.stringify(p),b?.name,b?.date));},insertImage:(s,p,b)=>(x(s.story),S(()=>JSON.parse(e.insert_image(s.story,s.paraId,s.offset,JSON.stringify(p),b?.name,b?.date)))),setContentControlValue:(s,p)=>{x(),S(()=>e.set_content_control_value(s,JSON.stringify(p)));},setContentControlValueAt:(s,p)=>{x(s.story),S(()=>e.set_content_control_value_at(s.story,s.paraId,s.offset,JSON.stringify(p)));},clearContentControlValue:s=>{x(),S(()=>e.clear_content_control_value(s));},setImageGeometry:(s,p)=>{x(),S(()=>e.set_image_geometry(s,JSON.stringify(p)));},insertPageBreak:s=>{x(s.story),S(()=>e.insert_page_break(s.story,s.paraId,s.offset));},insertSectionBreak:(s,p)=>{x(s.story),S(()=>e.insert_section_break(s.story,s.paraId,s.offset,p));},insertWatermark:(s,p)=>{x(s.story),S(()=>e.insert_watermark(s.story,s.paraId,s.offset,JSON.stringify(p)));},applyRawOps:(s,p)=>S(()=>e.apply_raw_ops(s,JSON.stringify(p))),applySeedRawOps:(s,p)=>S(()=>e.apply_seed_raw_ops(s,JSON.stringify(p))),setParagraphAttr:(s,p,b)=>S(()=>e.set_paragraph_attr(s,p,JSON.stringify(b??null))),addComment:(s,p,b,F)=>S(()=>JSON.parse(e.add_comment(qn(s),p,b,JSON.stringify(F??null)))),acceptChange:s=>S(()=>JSON.parse(e.accept_change(wt(s)))),rejectChange:s=>S(()=>JSON.parse(e.reject_change(wt(s)))),selectionContext:s=>{let p=JSON.stringify(s);if(c?.key===p)return JSON.parse(c.json);let b=e.selection_context(s.story,s.start.paraId,s.start.offset,s.end.paraId,s.end.offset),F=JSON.parse(b);return c={key:p,json:b},F},listRevisions:()=>JSON.parse(e.list_revisions()),resolveComment:s=>JSON.parse(e.resolve_comment(s)),storyIds:()=>e.story_ids(),storyLength:s=>e.story_len(s),storyChecksum:s=>BigInt(e.story_checksum(s)),yrsBlocksForStory:(s,p={})=>{let b=e.yrs_blocks_for_story(s,JSON.stringify(p)),F=JSON.parse(b);return f.set(s,structuredClone(p)),F},paragraphs:s=>JSON.parse(e.paragraphs(s)),paragraphSpans:s=>JSON.parse(e.paragraph_spans(s)),storySegments:s=>JSON.parse(e.story_segments(s)),locateParagraph:(s,p)=>JSON.parse(e.locate_paragraph(s,p)),destroy:()=>{o||(o=true,n.clear(),r.length=0,i&&e.clear_update_observer(),e.free());}}}async function Ur(e){let t=e?.clientId??Xn(),n=await import('../wasm-7SOSHNGP.mjs');return await n.preloadEditWasm(),Zn(n.createEditSession(t),t)}export{ce as ResidentEngineWorkerClient,J as ResidentWorkerFailureError,Mt as canUseResidentEngineWorker,tr as compareYrsLocs,Qn as createYrsInputPositionMap,Ur as createYrsSession,er as displayPositionToYrsLoc,un as documentToYrs,Jr as sameYrsSelection,De as yrsLocToDisplayPosition,Kn as yrsToDocument};
@@ -1 +1 @@
1
- import'../chunk-EUUIJVM6.mjs';import {b as b$1,a as a$1}from'../chunk-J7LNO6SM.mjs';import {a as a$2,b as b$2}from'../chunk-HTDNSQ44.mjs';import {u as u$1,s,a,g as g$1,j as j$1,i}from'../chunk-24DL53QL.mjs';import'../chunk-5F6DLQZP.mjs';import'../chunk-TTRUPDAB.mjs';async function X(){await a$2();let e=b$2(se()),i=new Set,o=false,a=false,s=null,p=null,y=n=>{s!==n&&(e.track_undo(n),s=n);},S=()=>{o||(e.set_update_observer((n,t)=>{if(!(t!==0&&t!==1))for(let c of [...i])c(n,t===0?"local":"remote");}),o=true);};return {registerFont:n=>e.register_measure_font(n),clearFonts:()=>e.clear_measure_fonts(),encodeStateVector:()=>e.encode_state_vector(),measureParagraphJson:n=>e.measure_paragraph_json(n),layoutDocumentJson:n=>e.layout_document_json(n),layoutFontRequirementsJson:n=>e.layout_font_requirements_json(n),layoutDocumentWithRegionsJson:n=>e.layout_document_with_regions_json(n),buildDisplayListFrame:(n,t)=>e.build_display_list_frame(n,t),residentCaretSnapshot:()=>JSON.parse(e.resident_caret_snapshot_json()),selection:()=>JSON.parse(e.selection()),applyInput:(n,t)=>(y(p?.story??"body"),e.apply_input(n,t)),applyDelete:(n,t)=>(y(p?.story??"body"),e.apply_delete(n,t)),applyInputProfiled:(n,t)=>{y(p?.story??"body");let c=e.apply_input_profiled(n,t),l=JSON.parse(e.apply_input_profile_json());return {frame:c,profile:l}},applyDeleteProfiled:(n,t)=>{y(p?.story??"body");let c=e.apply_delete_profiled(n,t),l=JSON.parse(e.apply_input_profile_json());return {frame:c,profile:l}},outlineGlyphJson:(n,t)=>e.outline_glyph_json(n,t),loadState:n=>e.load(n),applyUpdate:n=>JSON.parse(e.apply_update_with_inference(n)),onUpdate:n=>(i.add(n),S(),()=>i.delete(n)),setSelection:(n,t=n)=>{if(n.story!==t.story)throw new Error("yrs selection must stay inside one story");e.set_selection(n.story,n.paraId,n.offset,t.paraId,t.offset),p={...t};},yrsBlocksForStory:(n,t={})=>JSON.parse(e.yrs_blocks_for_story(n,JSON.stringify(t))),destroy:()=>{a||(a=true,i.clear(),o&&e.clear_update_observer(),e.free());}}}function se(){if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function"){let e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return Math.floor(Math.random()*4294967295)}var re=self,r=null,C=null,u=[],M=0,L=-1,q=Promise.resolve(),d=null,x=null,h=new Map,E=new Map,R=new Set,J=1,B=1,D={color:"#000",width:2},P=null,g=null,v=null,O=null,b=new Set;re.onmessage=e=>{q=q.then(()=>le(e.data)).catch(i=>{I({id:e.data.id,ok:false,error:i instanceof Error?i.message:String(i)});});};async function le(e){if(e.type==="destroy"){te();return}if(e.type==="bootstrap"){te(),r=await X(),ee(e.snapshot),ne();let o=performance.now(),a=r.buildDisplayListFrame(e.extras,e.expectedFrameEpoch);await k(e.id,a,performance.now()-o,u,void 0,o);return}if(e.type==="eraseCaret"){P=null,g!==null&&await j(false),I({id:e.id,ok:true});return}if(!r)throw new Error("Resident engine worker is not initialized");if(e.type==="sync"){C?.(),C=null,ee(e.snapshot),ne();let o=performance.now(),a=r.buildDisplayListFrame(e.extras,e.expectedFrameEpoch);await k(e.id,a,performance.now()-o,u,void 0,o,false,e.paintCaret);return}if(e.type==="buildFrame"){u=[];let o=performance.now(),a=r.buildDisplayListFrame(e.extras,e.expectedFrameEpoch);await k(e.id,a,performance.now()-o,u,void 0,o,false,e.paintCaret);return}if(e.type==="applyUpdate"){r.applyUpdate(e.update),e.selection&&r.setSelection(e.selection.anchor,e.selection.head);return}if(e.type==="attachCanvases"){let o=h.size>0&&(J!==e.devicePixelRatio||B!==e.zoom),a=new Set(e.pages.map(s=>s.pageId));for(let s of e.activePageIds)R.has(s)||a.add(s);for(let{pageId:s,canvas:p}of e.pages)h.set(s,p);R=new Set(e.activePageIds),J=e.devicePixelRatio,B=e.zoom,D=e.caretStyle;for(let[s,p]of h)R.has(s)||(p.width=0,p.height=0,E.delete(s),oe(s));await j(o?true:a),I({id:e.id,ok:true});return}r.setSelection(e.selection.anchor,e.selection.head),u=[];let i=performance.now();try{let o=e.type==="applyDelete"?e.profile?r.applyDeleteProfiled(e.direction,e.expectedFrameEpoch):{frame:r.applyDelete(e.direction,e.expectedFrameEpoch),profile:void 0}:e.profile?r.applyInputProfiled(e.text,e.expectedFrameEpoch):{frame:r.applyInput(e.text,e.expectedFrameEpoch),profile:void 0};await k(e.id,o.frame,performance.now()-i,u,o.profile,i,!0,e.paintCaret);}catch(o){let a=o instanceof Error?o.message:String(o);I({id:e.id,ok:false,error:a,residentUnavailable:a.includes("resident input state is not ready")});}finally{u=[];}}function ee(e){if(!r)throw new Error("Resident engine worker is not initialized");if(r.loadState(e.state),e.fontsRevision!==L){r.clearFonts();for(let i of e.fonts)r.registerFont(i);L=e.fontsRevision;}for(let{story:i,env:o}of e.renderInputs)r.yrsBlocksForStory(i,o);for(let i of e.measureInputs)r.measureParagraphJson(i);e.layoutWithRegions?r.layoutDocumentWithRegionsJson(e.layoutInput):r.layoutDocumentJson(e.layoutInput),e.selection&&r.setSelection(e.selection.anchor,e.selection.head),M=e.layoutRevision,u=[];}function ne(){r&&(C=r.onUpdate(e=>u.push(e.slice())));}function te(){C?.(),C=null,r?.destroy(),r=null,u=[],M=0,L=-1,d=null,x=null,h.clear(),E.clear(),R.clear(),P=null,g=null,v=null,O=null,b.clear();}function oe(e){b.delete(e),g===e&&(g=null,v=null);}async function k(e,i,o,a=u,s$1,p=performance.now(),y=false,S=false){d=u$1(d,s(i)),d={...d,pages:d.pages.map(f=>({...f,primitiveIds:f.primitiveIds.slice()}))};let n=r?.residentCaretSnapshot();if(!n||!b$1(n,d))throw new Error("Resident caret snapshot does not match the produced frame");if(y&&!n.caretRect)throw new Error("Resident input frame omitted collapsed caret geometry");let t=r?.selection()??null;P=S?n.caretRect??null:null;let c=new Set(d.pages.map(f=>f.pageId.toString()));for(let f of h.keys())c.has(f)||(h.delete(f),E.delete(f),oe(f));let l=performance.now(),{replayedPages:F,caretPainted:U}=await j(false),Y=performance.now()-l,w=A(i),_=a.map(A),m=r?A(r.encodeStateVector()):void 0;I({id:e,ok:true,frame:w,updates:_,engineMs:o,workerTotalMs:performance.now()-p,engineProfile:s$1,caret:n,selection:t,caretPainted:U,replayMs:Y,replayedPages:F,layoutRevision:M,...m?{stateVector:m}:{}},[w,..._,...m?[m]:[]]);}async function j(e){if(!d||h.size===0)return {replayedPages:0,caretPainted:false};!x&&r&&(x=new a({provider:(t,c)=>r.outlineGlyphJson(t,c)}));let i$1=e===true,o=e instanceof Set?e:null,a$2=P&&R.has(P.pageId)?P:null,s=a$2?a$1(a$2,D,J,B):null,p=a$2&&s?`${a$2.pageId}|${s.x}|${s.y}|${s.width}|${s.height}|${D.color}`:null,y=[];for(let t=0;t<d.pages.length;t+=1){let c=d.pages[t],l=c.pageId.toString();if(!R.has(l))continue;let F=i$1||o?.has(l)===true||d.damagedPageIds.has(c.pageId),U=l===a$2?.pageId&&!(g===l&&v===p),Y=l===g&&l!==a$2?.pageId;if(!F&&!U&&!Y)continue;let w=h.get(l),_=d.displayList.pages[t];if(!w||!_)continue;let m=l,f=E.get(m);f||(f=new OffscreenCanvas(1,1),E.set(m,f));let W=f;if(!F&&b.has(m)){y.push(Promise.resolve({canvas:w,buffer:W,pageId:m}));continue}y.push(g$1(W,_,{glyphCache:x??void 0},J,B).then(()=>({canvas:w,buffer:W,pageId:m})));}let S=await Promise.all(y),n=a$2!==null&&g===a$2.pageId&&v===p;for(let{canvas:t,buffer:c,pageId:l}of S)a$2&&s&&l===a$2.pageId?(O||(O=new OffscreenCanvas(1,1)),j$1(t,c,O,{...s,color:D.color}),b.add(l),g=l,v=p,n=true):(i(t,c),b.delete(l),g===l&&(g=null,v=null));return {replayedPages:S.length,caretPainted:n}}function A(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.slice().buffer}function I(e,i=[]){re.postMessage(e,i);}
1
+ import'../chunk-EUUIJVM6.mjs';import {b,a as a$2}from'../chunk-J7LNO6SM.mjs';import {a as a$3,b as b$1}from'../chunk-GD4VNJ64.mjs';import {u as u$1,s,a as a$1,g,j as j$1,i}from'../chunk-PGMXWI5X.mjs';import'../chunk-5F6DLQZP.mjs';import'../chunk-TTRUPDAB.mjs';async function q(){await a$3();let e=b$1(le()),o=new Set,r=false,i=false,l=false,c=()=>{l||(e.track_undo(),l=true);},R=()=>{r||(e.set_update_observer((t,n)=>{if(!(n!==0&&n!==1))for(let d of [...o])d(t,n===0?"local":"remote");}),r=true);};return {registerFont:t=>e.register_measure_font(t),clearFonts:()=>e.clear_measure_fonts(),encodeStateVector:()=>e.encode_state_vector(),measureParagraphJson:t=>e.measure_paragraph_json(t),layoutDocumentJson:t=>e.layout_document_json(t),layoutFontRequirementsJson:t=>e.layout_font_requirements_json(t),layoutDocumentWithRegionsRetainedJson:t=>e.layout_document_with_regions_retained_json(t),buildDisplayListFrame:(t,n)=>e.build_display_list_frame(t,n),residentCaretSnapshot:()=>JSON.parse(e.resident_caret_snapshot_json()),selection:()=>JSON.parse(e.selection()),applyInput:(t,n)=>(c(),e.apply_input(t,n)),applyDelete:(t,n)=>(c(),e.apply_delete(t,n)),applyInputProfiled:(t,n)=>{c();let d=e.apply_input_profiled(t,n),s=JSON.parse(e.apply_input_profile_json());return {frame:d,profile:s}},applyDeleteProfiled:(t,n)=>{c();let d=e.apply_delete_profiled(t,n),s=JSON.parse(e.apply_input_profile_json());return {frame:d,profile:s}},outlineGlyphJson:(t,n)=>e.outline_glyph_json(t,n),loadState:t=>e.load(t),applyUpdate:t=>JSON.parse(e.apply_update_with_inference(t)),onUpdate:t=>(o.add(t),R(),()=>o.delete(t)),setSelection:(t,n=t)=>{if(t.story!==n.story)throw new Error("yrs selection must stay inside one story");e.set_selection(t.story,t.paraId,t.offset,n.paraId,n.offset);},yrsBlocksForStory:(t,n={})=>JSON.parse(e.yrs_blocks_for_story(t,JSON.stringify(n))),destroy:()=>{i||(i=true,o.clear(),r&&e.clear_update_observer(),e.free());}}}function le(){if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function"){let e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return Math.floor(Math.random()*4294967295)}var ae=self,a=null,E=null,u=[],z=0,L=-1,ee=Promise.resolve(),f=null,D=null,h=new Map,k=new Map,S=new Set,w=new Set,B=1,U=1,O={color:"#000",width:2},v=null,y=null,P=null,J=null,C=new Set,Y=null;ae.onmessage=e=>{ee=ee.then(()=>{if(Y)throw Y;return pe(e.data)}).catch(o=>{if(o instanceof WebAssembly.RuntimeError){Y=o,_({id:e.data.id,ok:false,error:`Resident engine worker trapped: ${o.message}`,terminal:true});return}_({id:e.data.id,ok:false,error:o instanceof Error?o.message:String(o)});});};async function pe(e){if(e.type==="destroy"){re();return}if(e.type==="bootstrap"){re(),a=await q(),te(e.snapshot),ne();let r=performance.now(),i=a.buildDisplayListFrame(e.extras,e.expectedFrameEpoch);await x(e.id,i,performance.now()-r,u,void 0,r);return}if(e.type==="eraseCaret"){v=null,y!==null&&await M(false),_({id:e.id,ok:true});return}if(!a)throw new Error("Resident engine worker is not initialized");if(e.type==="sync"){E?.(),E=null,te(e.snapshot),ne();let r=performance.now(),i=a.buildDisplayListFrame(e.extras,e.expectedFrameEpoch);await x(e.id,i,performance.now()-r,u,void 0,r,false,e.paintCaret);return}if(e.type==="buildFrame"){u=[];let r=performance.now(),i=a.buildDisplayListFrame(e.extras,e.expectedFrameEpoch);await x(e.id,i,performance.now()-r,u,void 0,r,false,e.paintCaret);return}if(e.type==="applyUpdate"){a.applyUpdate(e.update),e.selection&&a.setSelection(e.selection.anchor,e.selection.head);return}if(e.type==="attachCanvases"){let r=h.size>0&&(B!==e.devicePixelRatio||U!==e.zoom),i=new Set(e.pages.map(l=>l.pageId));for(let l of e.activePageIds)w.has(l)||i.add(l);for(let{pageId:l,canvas:c}of e.pages)h.set(l,c);w=new Set(e.activePageIds),B=e.devicePixelRatio,U=e.zoom,O=e.caretStyle;for(let[l,c]of h)w.has(l)||(c.width=0,c.height=0,k.delete(l),oe(l));await M(r?true:i),_({id:e.id,ok:true});return}a.setSelection(e.selection.anchor,e.selection.head),u=[];let o=performance.now();try{let r=e.type==="applyDelete"?e.profile?a.applyDeleteProfiled(e.direction,e.expectedFrameEpoch):{frame:a.applyDelete(e.direction,e.expectedFrameEpoch),profile:void 0}:e.profile?a.applyInputProfiled(e.text,e.expectedFrameEpoch):{frame:a.applyInput(e.text,e.expectedFrameEpoch),profile:void 0};await x(e.id,r.frame,performance.now()-o,u,r.profile,o,!0,e.paintCaret);}catch(r){if(r instanceof WebAssembly.RuntimeError)throw r;let i=r instanceof Error?r.message:String(r);_({id:e.id,ok:false,error:i,residentUnavailable:i.includes("resident input state is not ready")});}finally{u=[];}}function te(e){if(!a)throw new Error("Resident engine worker is not initialized");if(a.loadState(e.state),e.fontsRevision!==L){a.clearFonts();for(let o of e.fonts)a.registerFont(o);L=e.fontsRevision;}for(let{story:o,env:r}of e.renderInputs)a.yrsBlocksForStory(o,r);for(let o of e.measureInputs)a.measureParagraphJson(o);e.layoutWithRegions?a.layoutDocumentWithRegionsRetainedJson(e.layoutInput):a.layoutDocumentJson(e.layoutInput),e.selection&&a.setSelection(e.selection.anchor,e.selection.head),z=e.layoutRevision,u=[];}function ne(){a&&(E=a.onUpdate(e=>u.push(e.slice())));}function re(){E?.(),E=null,a?.destroy(),a=null,u=[],z=0,L=-1,f=null,D=null,h.clear(),k.clear(),S.clear(),w.clear(),v=null,y=null,P=null,J=null,C.clear();}function oe(e){C.delete(e),y===e&&(y=null,P=null);}async function x(e,o,r,i=u,l,c=performance.now(),R=false,t=false){f=u$1(f,s(o));for(let p of f.damagedPageIds)S.add(p.toString());f={...f,pages:f.pages.map(p=>({...p,primitiveIds:p.primitiveIds.slice()}))};let n=a?.residentCaretSnapshot();if(!n||!b(n,f))throw new Error("Resident caret snapshot does not match the produced frame");if(R&&!n.caretRect)throw new Error("Resident input frame omitted collapsed caret geometry");let d=a?.selection()??null;v=t?n.caretRect??null:null;let s$1=new Set(f.pages.map(p=>p.pageId.toString()));for(let p of S)s$1.has(p)||S.delete(p);for(let p of h.keys())s$1.has(p)||(h.delete(p),k.delete(p),oe(p));let F=performance.now(),{replayedPages:W,caretPainted:A}=await M(false),b$1=performance.now()-F,I=j(o),g=i.map(j),m=a?j(a.encodeStateVector()):void 0;_({id:e,ok:true,frame:I,updates:g,engineMs:r,workerTotalMs:performance.now()-c,engineProfile:l,caret:n,selection:d,caretPainted:A,replayMs:b$1,replayedPages:W,layoutRevision:z,...m?{stateVector:m}:{}},[I,...g,...m?[m]:[]]);}async function M(e){let o=e===true?w:e;if(o)for(let n of o)S.add(n);if(!f||h.size===0)return {replayedPages:0,caretPainted:false};!D&&a&&(D=new a$1({provider:(n,d)=>a.outlineGlyphJson(n,d)}));let r=v&&w.has(v.pageId)?v:null,i$1=r?a$2(r,O,B,U):null,l=r&&i$1?`${r.pageId}|${i$1.x}|${i$1.y}|${i$1.width}|${i$1.height}|${O.color}`:null,c=[];for(let n=0;n<f.pages.length;n+=1){let s=f.pages[n].pageId.toString();if(!w.has(s))continue;let F=S.has(s),W=s===r?.pageId&&!(y===s&&P===l),A=s===y&&s!==r?.pageId;if(!F&&!W&&!A)continue;let b=h.get(s),I=f.displayList.pages[n];if(!b||!I)continue;let g$1=s,m=k.get(g$1);m||(m=new OffscreenCanvas(1,1),k.set(g$1,m));let p=m;if(!F&&C.has(g$1)){c.push(Promise.resolve({canvas:b,buffer:p,pageId:g$1}));continue}c.push(g(p,I,{glyphCache:D??void 0},B,U).then(()=>({canvas:b,buffer:p,pageId:g$1})));}let R=await Promise.all(c).catch(async n=>{throw await Promise.allSettled(c),n}),t=r!==null&&y===r.pageId&&P===l;for(let{canvas:n,buffer:d,pageId:s}of R)r&&i$1&&s===r.pageId?(J||(J=new OffscreenCanvas(1,1)),j$1(n,d,J,{...i$1,color:O.color}),C.add(s),y=s,P=l,t=true):(i(n,d),C.delete(s),y===s&&(y=null,P=null)),S.delete(s);return {replayedPages:R.length,caretPainted:t}}function j(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.slice().buffer}function _(e,o=[]){ae.postMessage(e,o);}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betteroffice/docx",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "sideEffects": [
5
5
  "**/residentEngineWorker.*"
6
6
  ],
@@ -217,7 +217,7 @@
217
217
  }
218
218
  },
219
219
  "devDependencies": {
220
- "@betteroffice/fonts": "0.1.0",
220
+ "@betteroffice/fonts": "0.2.0",
221
221
  "tsup": "^8.0.1",
222
222
  "typescript": "^6.0.3",
223
223
  "@types/bun": "^1.0.0",