@betteroffice/docx 0.0.4 → 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.
- package/README.md +4 -7
- package/dist/chunk-47Q2FMFF.mjs +1 -0
- package/dist/chunk-5F6DLQZP.mjs +1 -0
- package/dist/chunk-6LQJAKOC.mjs +1 -0
- package/dist/chunk-ACGKK7IB.mjs +1 -0
- package/dist/{chunk-NTSSE5QK.mjs → chunk-AFMVSI4Z.mjs} +2 -2
- package/dist/chunk-GD4VNJ64.mjs +1 -0
- package/dist/{chunk-NJHOPXZW.mjs → chunk-HLDJMU3R.mjs} +1 -1
- package/dist/{chunk-YTILOUAA.mjs → chunk-JHJLG4I6.mjs} +1 -1
- package/dist/chunk-PGMXWI5X.mjs +1 -0
- package/dist/{chunk-NBSLB77E.mjs → chunk-WTFRNX5K.mjs} +1 -1
- package/dist/collaboration/index.d.mts +6 -6
- package/dist/{content-C3sTRz-u.d.mts → content-CvEtPl0c.d.mts} +124 -22
- package/dist/core.d.mts +8 -8
- package/dist/core.mjs +1 -1
- package/dist/{displayListQueries-DLzpvJV6.d.mts → displayListQueries-DF8F6fMl.d.mts} +87 -50
- package/dist/docx/index.d.mts +5 -5
- package/dist/docx/index.mjs +1 -1
- package/dist/editor/index.d.mts +21 -12
- package/dist/editor/index.mjs +1 -1
- package/dist/{fontLoader-CMH3bZ2Z.d.mts → fontLoader-b8eicJKV.d.mts} +1 -1
- package/dist/{formatting-BEkIBePP.d.mts → formatting-7zKCTu5a.d.mts} +11 -2
- package/dist/{frameDelta-B2kC6XiP.d.mts → frameDelta-pA4jrQ1G.d.mts} +16 -10
- package/dist/generated/edit/docx_edit_bg.wasm +0 -0
- package/dist/generated/layout/docx_layout_bg.wasm +0 -0
- package/dist/generated/opc/ooxml_opc_bg.wasm +0 -0
- package/dist/generated/parse/docx_parse_bg.wasm +0 -0
- package/dist/{index-2piKi4gO.d.mts → index-CHl2zLJ7.d.mts} +146 -77
- package/dist/layout/index.d.mts +40 -13
- package/dist/layout/index.mjs +1 -1
- package/dist/layout/pagination/index.d.mts +4 -4
- package/dist/layout/pagination/index.mjs +1 -1
- package/dist/layout/render/index.d.mts +33 -77
- package/dist/layout/render/index.mjs +1 -1
- package/dist/plugin-api/RenderedDomContext.d.mts +7 -7
- package/dist/plugin-api/index.d.mts +3 -3
- package/dist/plugin-api/resolveItemPositions.d.mts +3 -3
- package/dist/{rustDisplayList-B0M2eBkU.d.mts → rustDisplayList-BJqaN9tt.d.mts} +74 -50
- package/dist/{rustMeasureSource-D1KsQvVC.d.mts → rustMeasureSource-C0EZB055.d.mts} +5 -2
- package/dist/{selectiveSave-CVoajSKE.d.mts → selectiveSave-CRh-_Y_C.d.mts} +3 -3
- package/dist/styles/index.d.mts +6 -10
- package/dist/styles/index.mjs +1 -1
- package/dist/{styles-BK3Jecxs.d.mts → styles-7e-mq3c-.d.mts} +1 -1
- package/dist/types/content.d.mts +2 -2
- package/dist/types/document.d.mts +8 -7
- package/dist/{types-C1rv3KM-.d.mts → types-C4A8mWjU.d.mts} +44 -24
- package/dist/utils/comments.d.mts +2 -2
- package/dist/utils/index.d.mts +11 -13
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/stylePreview.d.mts +2 -2
- package/dist/wasm-7SOSHNGP.mjs +1 -0
- package/dist/{wasm-JE7B3ROD.mjs → wasm-ZQAVP7P2.mjs} +1 -1
- package/dist/wasm-edit.d.mts +525 -185
- package/dist/wasm-edit.mjs +1 -1
- package/dist/wasm-layout.d.mts +31 -28
- package/dist/wasm-layout.mjs +1 -1
- package/dist/wasm-opc.mjs +1 -1
- package/dist/wasm-parse.d.mts +2 -1
- package/dist/wasm-parse.mjs +1 -1
- package/dist/yrs/index.d.mts +5 -5
- package/dist/yrs/index.mjs +1 -1
- package/dist/yrs/residentEngineWorker.mjs +1 -1
- package/package.json +19 -2
- package/dist/chunk-4V6MDZIK.mjs +0 -1
- package/dist/chunk-6KDV6AIL.mjs +0 -1
- package/dist/chunk-B4IR6YP4.mjs +0 -1
- package/dist/chunk-GGEGIQRK.mjs +0 -1
- package/dist/chunk-T4EZMUXM.mjs +0 -1
- package/dist/chunk-WBH3SXI6.mjs +0 -1
- package/dist/wasm-F2ETFAYL.mjs +0 -1
package/dist/wasm-edit.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{b as createEditSession,a as preloadEditWasm}from'./chunk-
|
|
1
|
+
export{b as createEditSession,a as preloadEditWasm}from'./chunk-GD4VNJ64.mjs';import'./chunk-5F6DLQZP.mjs';import'./chunk-TTRUPDAB.mjs';
|
package/dist/wasm-layout.d.mts
CHANGED
|
@@ -16,15 +16,16 @@ import { W as WasmAsyncInput } from './loadWasmAsset-CMvnVkfA.mjs';
|
|
|
16
16
|
declare function preloadLayoutWasm(input?: WasmAsyncInput): Promise<void>;
|
|
17
17
|
/**
|
|
18
18
|
* Region-aware hit test over a display list: page-local point in,
|
|
19
|
-
* `{"region":"body"|"header"|"footer","rId"?,"pos":n|null
|
|
20
|
-
* an out-of-range page) JSON out. Header/footer hits identify
|
|
21
|
-
* by `rId`; their `pos` refers to that doc, not the body doc.
|
|
19
|
+
* `{"region":"body"|"header"|"footer","rId"?,"pos":n|null,"target":"text"|"image"|"none"}`
|
|
20
|
+
* (or `"null"` for an out-of-range page) JSON out. Header/footer hits identify
|
|
21
|
+
* the HF doc by `rId`; their `pos` refers to that doc, not the body doc.
|
|
22
|
+
* `target` is what sits under the point, which is what a pointer cursor needs.
|
|
22
23
|
*/
|
|
23
24
|
declare function hitTestRegionsJson(displayList: string, pageIndex: number, x: number, y: number): string;
|
|
24
25
|
/**
|
|
25
|
-
* Highlight rects for a body
|
|
26
|
+
* Highlight rects for a body document range over a display list: JSON array of
|
|
26
27
|
* `{pageIndex, x, y, width, height}` in page-local px. Body-only — HF doc
|
|
27
|
-
* positions live in different
|
|
28
|
+
* positions live in different docs and are never consulted.
|
|
28
29
|
*/
|
|
29
30
|
declare function rangeRectsJson(displayList: string, from: number, to: number): string;
|
|
30
31
|
/**
|
|
@@ -33,17 +34,18 @@ declare function rangeRectsJson(displayList: string, from: number, to: number):
|
|
|
33
34
|
*/
|
|
34
35
|
declare function hasDisplayListSession(): boolean;
|
|
35
36
|
/**
|
|
36
|
-
* True when the embedded layout wasm carries the region-aware range-rect
|
|
37
|
-
* (`range_rects_region_json` and its by-handle twin). Callers gate
|
|
38
|
-
* selection
|
|
39
|
-
* avoids
|
|
40
|
-
* export
|
|
37
|
+
* True when the embedded layout wasm carries the region-aware range-rect
|
|
38
|
+
* exports (`range_rects_region_json` and its by-handle twin). Callers gate
|
|
39
|
+
* header/footer selection and caret geometry on this and otherwise return
|
|
40
|
+
* `[]`; probing avoids invoking — and so dropping the session handle over — an
|
|
41
|
+
* absent export.
|
|
41
42
|
*/
|
|
42
43
|
declare function hasRangeRectsRegion(): boolean;
|
|
43
44
|
/**
|
|
44
|
-
* Parse a display list once and return
|
|
45
|
-
*
|
|
46
|
-
* the query facade catches
|
|
45
|
+
* Parse a display list once and return the handle the by-handle queries reuse.
|
|
46
|
+
* The caller owns it and must `closeDisplayList` it. Throws when the export is
|
|
47
|
+
* absent or the JSON is malformed; the query facade catches that and stays on
|
|
48
|
+
* the JSON-arg path.
|
|
47
49
|
*/
|
|
48
50
|
declare function openDisplayList(displayList: string): number;
|
|
49
51
|
/** Drop a display-list handle so its parsed list is freed. No-op when the export is absent. */
|
|
@@ -63,23 +65,24 @@ declare function hasDisplayListUpdate(): boolean;
|
|
|
63
65
|
* and falls back to `hitTestRegionsJson`.
|
|
64
66
|
*/
|
|
65
67
|
declare function hitTestRegionsByHandle(handle: number, pageIndex: number, x: number, y: number): string;
|
|
66
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Closest caret position on the adjacent visual line: `{"position","goalX"}`
|
|
70
|
+
* JSON, or `"null"` when there is no line in that direction. `goalX` is the
|
|
71
|
+
* page-local x the caret holds across successive moves.
|
|
72
|
+
*/
|
|
67
73
|
declare function verticalMoveJson(displayList: string, position: number, direction: 'up' | 'down', goalX: number): string;
|
|
68
74
|
/** Resolve the closest caret position on the adjacent visual line by handle. */
|
|
69
75
|
declare function verticalMoveByHandle(handle: number, position: number, direction: 'up' | 'down', goalX: number): string;
|
|
70
76
|
/**
|
|
71
|
-
* Highlight rects for a body
|
|
77
|
+
* Highlight rects for a body document range against a stored display list (by handle).
|
|
72
78
|
* Throws when the export is absent or the handle is unknown/closed.
|
|
73
79
|
*/
|
|
74
80
|
declare function rangeRectsByHandle(handle: number, from: number, to: number): string;
|
|
75
81
|
/**
|
|
76
|
-
* Region-aware highlight rects
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* pipeline is safe to ship before the integrator re-embeds; throws when absent
|
|
81
|
-
* so the facade falls back to `[]` (HF selection geometry stays a documented
|
|
82
|
-
* gap until the re-embed lands).
|
|
82
|
+
* Region-aware highlight rects: `region` is `"body" | "header" | "footer"`,
|
|
83
|
+
* and `rId` scopes a header/footer to one part (empty string for body, or to
|
|
84
|
+
* match any). `from`/`to` are positions in THAT region's document. Throws when
|
|
85
|
+
* the export is absent, so the facade falls back to `[]`.
|
|
83
86
|
*/
|
|
84
87
|
declare function rangeRectsRegionJson(displayList: string, region: string, rId: string, from: number, to: number): string;
|
|
85
88
|
/**
|
|
@@ -113,12 +116,12 @@ declare function clearMeasureFonts(): void;
|
|
|
113
116
|
declare function measureParagraphJson(input: string): string;
|
|
114
117
|
/**
|
|
115
118
|
* Glyph outline for `(fontId, glyphId)` as JSON:
|
|
116
|
-
* `{"upem":2048,"cmds":[{"t":"M"
|
|
117
|
-
* — commands in font units, y-up
|
|
118
|
-
* measurement
|
|
119
|
-
* from shaping. Throws when the export is absent
|
|
120
|
-
*
|
|
121
|
-
*
|
|
119
|
+
* `{"upem":2048,"cmds":[{"t":"M",…},{"t":"L",…},{"t":"Q",…},{"t":"C",…},{"t":"Z"}]}`
|
|
120
|
+
* — commands in font units, y-up per the font convention. `fontId` is a
|
|
121
|
+
* measurement FontStore id from {@link registerMeasureFont}, `glyphId` a glyph
|
|
122
|
+
* index from shaping. Throws when the export is absent or the glyph cannot be
|
|
123
|
+
* extracted; the canvas backend catches that and paints the run via
|
|
124
|
+
* `fillText`, so text is never invisible.
|
|
122
125
|
*/
|
|
123
126
|
declare function outlineGlyphJson(fontId: number, glyphId: number): string;
|
|
124
127
|
|
package/dist/wasm-layout.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{p as buildDisplayListJson,s as clearMeasureFonts,g as closeDisplayList,d as hasDisplayListSession,i as hasDisplayListUpdate,e as hasRangeRectsRegion,j as hitTestRegionsByHandle,b as hitTestRegionsJson,q as layoutDocumentJson,t as measureParagraphJson,f as openDisplayList,u as outlineGlyphJson,a as preloadLayoutWasm,m as rangeRectsByHandle,c as rangeRectsJson,o as rangeRectsRegionByHandle,n as rangeRectsRegionJson,r as registerMeasureFont,h as updateDisplayList,l as verticalMoveByHandle,k as verticalMoveJson}from'./chunk-
|
|
1
|
+
export{p as buildDisplayListJson,s as clearMeasureFonts,g as closeDisplayList,d as hasDisplayListSession,i as hasDisplayListUpdate,e as hasRangeRectsRegion,j as hitTestRegionsByHandle,b as hitTestRegionsJson,q as layoutDocumentJson,t as measureParagraphJson,f as openDisplayList,u as outlineGlyphJson,a as preloadLayoutWasm,m as rangeRectsByHandle,c as rangeRectsJson,o as rangeRectsRegionByHandle,n as rangeRectsRegionJson,r as registerMeasureFont,h as updateDisplayList,l as verticalMoveByHandle,k as verticalMoveJson}from'./chunk-WTFRNX5K.mjs';import'./chunk-5F6DLQZP.mjs';import'./chunk-TTRUPDAB.mjs';
|
package/dist/wasm-opc.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as preloadOpcWasm,c as rezipContainer,b as unzipContainer}from'./chunk-
|
|
1
|
+
export{a as preloadOpcWasm,c as rezipContainer,b as unzipContainer}from'./chunk-HLDJMU3R.mjs';import'./chunk-5F6DLQZP.mjs';import'./chunk-TTRUPDAB.mjs';
|
package/dist/wasm-parse.d.mts
CHANGED
|
@@ -14,5 +14,6 @@ declare function serializeDocxS10Wire(requestJson: string): string;
|
|
|
14
14
|
declare function serializeDocxS11Wire(requestJson: string): string;
|
|
15
15
|
declare function serializeDocxS12Wire(requestJson: string): string;
|
|
16
16
|
declare function writeDocxS13Wire(requestJson: string, originalDocx: Uint8Array): Uint8Array;
|
|
17
|
+
declare function decodeTiffImage(bytes: Uint8Array): Uint8Array;
|
|
17
18
|
|
|
18
|
-
export { parseDocxS9Wire, parseRelationshipsXmlWire, preloadParseWasm, serializeDocxS10Wire, serializeDocxS11Wire, serializeDocxS12Wire, writeDocxS13Wire };
|
|
19
|
+
export { decodeTiffImage, parseDocxS9Wire, parseRelationshipsXmlWire, preloadParseWasm, serializeDocxS10Wire, serializeDocxS11Wire, serializeDocxS12Wire, writeDocxS13Wire };
|
package/dist/wasm-parse.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{b as parseDocxS9Wire,c as parseRelationshipsXmlWire,a as preloadParseWasm,d as serializeDocxS10Wire,e as serializeDocxS11Wire,f as serializeDocxS12Wire,g as writeDocxS13Wire}from'./chunk-
|
|
1
|
+
export{h as decodeTiffImage,b as parseDocxS9Wire,c as parseRelationshipsXmlWire,a as preloadParseWasm,d as serializeDocxS10Wire,e as serializeDocxS11Wire,f as serializeDocxS12Wire,g as writeDocxS13Wire}from'./chunk-ACGKK7IB.mjs';import'./chunk-5F6DLQZP.mjs';import'./chunk-TTRUPDAB.mjs';
|
package/dist/yrs/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../types/document.mjs';
|
|
2
|
-
export { w as CreateYrsSessionOptions, R as ResidentCaretPaintStyle, x as ResidentEngineOffscreenPage, y as ResidentEngineWorkerApplyResult, z as ResidentEngineWorkerClient, A as ResidentEngineWorkerFrame, B as
|
|
3
|
-
import '../content-
|
|
4
|
-
import '../formatting-
|
|
2
|
+
export { w as CreateYrsSessionOptions, R as ResidentCaretPaintStyle, x as ResidentEngineOffscreenPage, y as ResidentEngineWorkerApplyResult, z as ResidentEngineWorkerClient, A as ResidentEngineWorkerFrame, B as ResidentWorkerFailureError, D as YrsAuthor, E as YrsCellBorder, F as YrsCellBorders, G as YrsCellLoc, H as YrsChangeTarget, I as YrsCommentReceipt, J as YrsContentControlValue, K as YrsDocxHost, L as YrsEngineApplyProfile, M as YrsHyperlinkAttrs, N as YrsImageGeometry, O as YrsInlineFormatDelta, P as YrsInputParagraphSeed, Q as YrsInputParagraphSpan, S as YrsInputPositionMap, u as YrsLoc, T as YrsNumberingProperties, U as YrsParaOffset, V as YrsParagraph, W as YrsParagraphAttrs, X as YrsParagraphLength, Z as YrsParagraphReceipt, _ as YrsParagraphSeed, $ as YrsParagraphSpan, a0 as YrsParagraphTabStop, a1 as YrsRawOp, a as YrsRenderEnv, a2 as YrsResidentCaretRect, a3 as YrsResidentCaretSnapshot, a4 as YrsResidentWorkerSnapshot, a5 as YrsResidentWorkerSyncOptions, a6 as YrsResolveReceipt, a7 as YrsResolvedCommentAnchor, v as YrsRevisionInfo, a8 as YrsRevisionReceipt, a9 as YrsRunMark, j as YrsSelection, aa as YrsSelectionContext, Y as YrsSession, ab as YrsSplitReceipt, ac as YrsStickyPosition, ad as YrsStoryRange, ae as YrsStorySeed, af as YrsStorySegment, ag as YrsTableLoc, ah as YrsTableRange, ai as YrsTableReceipt, aj as YrsTextColor, ak as YrsTriState, al as YrsWatermark, am as canUseResidentEngineWorker, an as compareYrsLocs, ao as createYrsInputPositionMap, ap as createYrsSession, aq as displayPositionToYrsLoc, ar as documentToYrs, as as residentCaretDeviceRect, at as residentCaretSnapshotForFrame, au as sameYrsSelection, av as yrsLocToDisplayPosition, aw as yrsToDocument } from '../index-CHl2zLJ7.mjs';
|
|
3
|
+
import '../content-CvEtPl0c.mjs';
|
|
4
|
+
import '../formatting-7zKCTu5a.mjs';
|
|
5
5
|
import '../docx/wrapTypes.mjs';
|
|
6
|
-
import '../styles-
|
|
7
|
-
import '../frameDelta-
|
|
6
|
+
import '../styles-7e-mq3c-.mjs';
|
|
7
|
+
import '../frameDelta-pA4jrQ1G.mjs';
|
package/dist/yrs/index.mjs
CHANGED
|
@@ -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-6KDV6AIL.mjs';import'../chunk-B4IR6YP4.mjs';import'../chunk-T4EZMUXM.mjs';import {b}from'../chunk-TTRUPDAB.mjs';function Ln(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 Oe(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 Dn(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 Jn(e,t,n){return Oe(e,t)-Oe(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(Ct(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},Be(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},Be(t)),a=K(s);return this.recordSync(s,l),this.ready=true,this.revision=a.layoutRevision,a}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(a=>a.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 a=r?setTimeout(()=>{let d=this.pending.get(o);if(!d)return;this.pending.delete(o);let f=new Error(`Resident engine worker did not acknowledge ${t.type} within ${r}ms`);d.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:a}),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 Ct(e,t=false){return t?new q(e):new Error(e)}function Be(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 Pt(){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 It={styleId:"pStyle",_sectionProperties:"sectPr"},vt=new Set(["paraId","textId","renderedPageBreakBefore","numPrFromStyle"]);function Ne(e){let t={};for(let[n,r]of Object.entries(e))vt.has(n)||r===null||r===void 0||(t[It[n]??n]=L(r));return t}var At=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 Ee(e){return ee(e,At)}function Le(e){let t=e.columnWidths;return Array.isArray(t)?t.map(L):[]}function De(e){return ee(e)}function Je(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 Ue(e,t){return `${e}:sdt${t}`}function We(e){return ee(e)}function te(e){return `hf:${e}`}function je(e){return `fn:${e}`}function $e(e){return `en:${e}`}var Ft=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 Yt(e,t){if(!e||!t)return e;let n=t.resolveRunStyle(e.styleId);return n?a(n,e):e}function Ve(e){if(!e)return [];let t=[],n=(s,a={})=>t.push({name:s,attrs:a});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 Ke(e){let t={};for(let n of e)n.name==="comment"||n.name==="footnoteRef"||(Ft.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 Mt(e,t){return [...e.filter(n=>n.name!==t.name),t]}function X(e,t,n){return {kind:"text",text:e,attrs:Ke(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:Ke(n),pmSize:o,...r!==void 0?{commentId:r}:{},marks:[...n]}}function qe(e,t,n){let r=e.formatting?.styleId?n?.getRunStyleOwnProperties(e.formatting.styleId):void 0;return Ve(a(a(t,r),e.formatting))}function Ot(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 a=r==="inline"?"inline":r==="topAndBottom"?"block":b$4(r)||s&&s!=="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 f,c,p;if(e.outline?.width){f=Math.round(e.outline.width/914400*96*100)/100,e.outline.color?.rgb&&(c=`#${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"};p=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:a,cssFloat:s??null,transform:d.length>0?d.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:c??null,borderStyle:p??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 Bt(e){return {shapeJson:JSON.stringify(e)}}function Nt(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 a of o)if(a.type==="run"){for(let d of a.content)d.type==="text"&&(n+=d.text);!r&&a.formatting&&(r=a.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:Ve(a(t,l))}}function me(e){return {display:e.display,ommlXml:e.ommlXml,plainText:e.plainText||""}}function Et(e){return {name:"hyperlink",attrs:{href:e.href||(e.anchor?`#${e.anchor}`:""),tooltip:e.tooltip??null,rId:e.rId??null}}}function He(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,String(e).length)}function Xe(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),Mt(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",Ot(e.image))];case "shape":return [v("shape",Bt(e.shape))];case "chart":return [v("chart",Nt(e.chart))];case "footnoteRef":return [He(e.id,"footnote",t,n)];case "endnoteRef":return [He(e.id,"endnote",t,n)];default:return []}}function ne(e,t,n,r,o=[]){let l=[...qe(e,t,n),...o];return e.content.flatMap(s=>Xe(s,l,r))}function he(e,t,n,r=[]){let o=[],l=Et(e);for(let s of e.structuredChildren??e.children)if(s.type==="run"){let a=[...qe(s,t,n),...r,l];for(let d of s.content)o.push(...Xe(d,a));}else if(s.type==="simpleField"||s.type==="complexField"){let a=ge(s,t);o.push(v("field",a.payload,[...a.marks,...r,l]));}else s.type==="mathEquation"&&o.push(v("math",me(s),[...r,l]));return o}function Lt(e,t,n){return {name:t,attrs:{revisionId:e.id,author:e.author,date:e.date??null,isMovePair:n}}}function Dt(e,t,n,r){let o=e.type==="insertion"||e.type==="moveTo"?"insertion":"deletion",l=Lt(e.info,o,e.type==="moveFrom"||e.type==="moveTo"),s=[];for(let a of e.content)if(a.type==="run")s.push(...ne(a,t,n,r,[l]));else {let d=he(a,t,n,[l]);for(let f of d)r!==void 0&&(f.commentId=r);s.push(...d);}return s}function Ge(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 a=r[r.length-1];a&&"text"in a&&z(a.attrs)===z(l.attrs)?a.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",Ge(l,t,n))):l.type==="mathEquation"&&o(v("math",me(l)));return L({...ue(e.properties),propertiesJson:JSON.stringify(e.properties),content:r})}function Jt(e,t,n){let r=t?t.resolveParagraphStyle(e.formatting?.styleId).runFormatting:void 0;return a(r,n)}function Ut(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=r.map(a=>{if(a.kind==="text")return a.text;let d=a.payload.footnoteRefId??a.payload.endnoteRefId;return String(d??"")}).join(""),s=o[0];return {text:l,...s!==void 0?{marksKey:s}:{},...e.formatting?{formatting:e.formatting}:{},...e.propertyChanges?{propertyChanges:e.propertyChanges}:{}}}function Wt(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 c=t.resolveParagraphStyle(l),p=c.paragraphFormatting;s.alignment=o?.alignment??p?.alignment??null,s.spaceBefore=o?.spaceBefore??p?.spaceBefore??null,s.spaceAfter=o?.spaceAfter??p?.spaceAfter??null,s.lineSpacing=o?.lineSpacing??p?.lineSpacing??null,s.lineSpacingRule=o?.lineSpacingRule??p?.lineSpacingRule??null,s.spacingExplicit=o?.spacingExplicit||null,s.indentLeft=o?.indentLeft??p?.indentLeft??null,s.indentRight=o?.indentRight??p?.indentRight??null;let h=o?.numPr?.numId===0&&p?.numPr&&p.numPr.numId!==0?void 0:p;s.indentFirstLine=o?.indentFirstLine??h?.indentFirstLine??null,s.hangingIndent=o?.hangingIndent??h?.hangingIndent??false,s.borders=o?.borders??p?.borders??null,s.shading=o?.shading??p?.shading??null,s.tabs=o?.tabs??p?.tabs??null,s.pageBreakBefore=o?.pageBreakBefore??p?.pageBreakBefore??null,s.keepNext=o?.keepNext??p?.keepNext??null,s.keepLines=o?.keepLines??p?.keepLines??null,s.contextualSpacing=o?.contextualSpacing??p?.contextualSpacing??null,s.outlineLevel=o?.outlineLevel??p?.outlineLevel??null,s.bidi=o?.bidi??p?.bidi??null;let y=t.getDefaultCharacterStyle()?.rPr,k=y?a(c.runFormatting,y):c.runFormatting;s.defaultTextFormatting=a(k,Yt(o?.runProperties,t))??null,!o?.numPr&&p?.numPr&&p.numPr.numId!==0&&(s.numPr=p.numPr,s.numPrFromStyle=p.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.outlineLevel=o?.outlineLevel??null,s.bidi=o?.bidi??null,s.defaultTextFormatting=o?.runProperties??null;if(e.sectionProperties){s._sectionProperties=e.sectionProperties;let c=e.sectionProperties.sectionStart;(c==="nextPage"||c==="continuous"||c==="oddPage"||c==="evenPage")&&(s.sectionBreakType=c);}e.renderedPageBreakBefore&&(s.renderedPageBreakBefore=true),Ht(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 a$1=[],d=0,f=0;for(let c of e.content)if(c.type==="bookmarkStart")a$1.push({id:c.id,name:c.name,kind:"start",offset:f,...c.colFirst!==void 0?{colFirst:c.colFirst}:{},...c.colLast!==void 0?{colLast:c.colLast}:{}});else if(c.type==="bookmarkEnd")a$1.push({id:c.id,kind:"end",offset:f});else {let p=jt(c);for(let g=0;g<p;g+=1)f+=n[d]?.pmSize??0,d+=1;}return a$1.length>0&&(s.bookmarks=a$1),r?.length&&(s._originalRunBoundaries=r),s}var Ze=new WeakMap;function jt(e){return Ze.get(e)??0}function $t(e,t,n){let r=[],o=new Set,l=[],s=Jt(e,t,n);for(let d of e.content){let f=r.length,c=o.values().next().value;if(d.type==="commentRangeStart")o.add(d.id);else if(d.type==="commentRangeEnd")o.delete(d.id);else if(d.type==="run"){let p=Ut(d,s,t);p&&l?l.push(p):l=void 0,r.push(...ne(d,s,t,c));}else if(d.type==="hyperlink")l=void 0,r.push(...he(d,s,t));else if(d.type==="simpleField"||d.type==="complexField"){l=void 0;let p=ge(d,s);r.push(v("field",p.payload,p.marks));}else d.type==="inlineSdt"?(l=void 0,r.push(v("sdt",Ge(d,s,t),[],void 0,2))):d.type==="insertion"||d.type==="deletion"||d.type==="moveFrom"||d.type==="moveTo"?(l=void 0,r.push(...Dt(d,s,t,c))):d.type==="mathEquation"?(l=void 0,r.push(v("math",me(d)))):d.type!=="bookmarkStart"&&d.type!=="bookmarkEnd"&&(l=void 0);Ze.set(d,r.length-f);}let a=Wt(e,t,r,l);return {units:r,ppr:Ne(a)}}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 Ht(e){let t=[];return ye(e.content,t),t[0]==="pageBreak"}function zt(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 Vt(e){let t=new Map,n=new Map;return e.rows.forEach((r,o)=>{let l=0,s=r.cells.map(d=>{let f=l;return l+=d.formatting?.gridSpan??1,{column:f,vMerge:d.formatting?.vMerge,key:`${o}-${f}`}});if(s.length>0&&s.every(d=>d.vMerge==="continue"&&n.has(d.column))){for(let d of s)n.delete(d.column),t.set(d.key,{rowSpan:1,skip:false});return}for(let d of s)if(d.vMerge==="restart")n.set(d.column,o),t.set(d.key,{rowSpan:1,skip:false});else if(d.vMerge==="continue"){let f=n.get(d.column);if(f===void 0)t.set(d.key,{rowSpan:1,skip:false});else {let c=t.get(`${f}-${d.column}`);c&&(c.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 fe(e){return {revisionId:e.id,author:e.author,date:e.date??null}}function Kt(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 ze(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:Kt(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 a=e.structuralChange,d=fe(a.info);a.type==="tableCellInsertion"?s.cellMarker={kind:"ins",info:d}:a.type==="tableCellDeletion"?s.cellMarker={kind:"del",info:d}:a.type==="tableCellMerge"&&(s.cellMarker={kind:"merge",info:d,vMerge:a.vMerge??"cont",...a.vMergeOrig?{vMergeOrig:a.vMergeOrig}:{}});}return e.propertyChanges?.length&&(s.tcPrChange=e.propertyChanges),{attrs:Je(s,t.isHeader),content:e.content.length>0?e.content:[{type:"paragraph",content:[]}]}}function qt(e,t,n,r,o,l,s){let a={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"?a.trIns=fe(e.structuralChange.info):e.structuralChange.type==="tableRowDeletion"&&(a.trDel=fe(e.structuralChange.info))),e.propertyChanges?.length&&(a.trPrChange=e.propertyChanges);let d=t.columnWidths,f=d?.reduce((h,y)=>h+y,0)??0,c=d?.length??Math.max(0,...t.rows.map(h=>h.cells.reduce((y,k)=>y+(k.formatting?.gridSpan??1),0))),p=0,g=[];return e.cells.forEach(h=>{let y=h.formatting?.gridSpan??1,k=p,R=r.get(`${n}-${k}`),x;if(d&&f>0){let I=0;for(let P=0;P<y&&k+P<d.length;P+=1)I+=d[k+P];x=Math.round(I/f*100);}p+=y,!R?.skip&&g.push(ze(h,{isHeader:n===0&&!!t.formatting?.look?.firstRow,rowspan:R?.rowSpan??1,gridWidth:x,firstRow:n===0,lastRow:n===t.rows.length-1,firstColumn:k===0,lastColumn:p===c,tableBorders:o,defaultMargins:l,theme:s,tableBidi:!!t.formatting?.bidi}));}),g.length===0&&g.push(ze({formatting:c>1?{gridSpan:c}: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:De(a),cells:g}}function Xt(e,t,n){let r=t?.getDefaultTableStyle(),o=e.formatting?.styleId,l=o??r?.styleId,s=l?t?.getStyle(l):void 0,a=e.formatting?.borders??s?.tblPr?.borders??r?.tblPr?.borders,d=e.formatting?.cellMargins??s?.tblPr?.cellMargins??r?.tblPr?.cellMargins,f=e.formatting?.bidi?d?.end:d?.start,c=e.formatting?.bidi?d?.start:d?.end,p=d?{top:d.top?.value,bottom:d.bottom?.value,left:d.left?.value??f?.value,right:d.right?.value??c?.value}:void 0,g=[],h=new Set,y=s;for(;y?.basedOn&&g.length<32&&!h.has(y.basedOn);)h.add(y.basedOn),g.unshift(y.basedOn),y=t?.getStyle(y.basedOn);let k={...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:p??null,look:e.formatting?.look??null,bidi:e.formatting?.bidi||null,_originalFormatting:k};e.propertyChanges?.length&&(R.tblPrChange=e.propertyChanges);let x=Vt(e);return {attrs:R,rows:e.rows.map((I,P)=>qt(I,e,P,x,a,p,n))}}function Gt(e){return We(ue(e))}function Zt(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,a=0,d=0,f=null;for(let c of l){if(c.type==="paragraph"){let h=$t(c,e.styleResolver,r.extraRunFormatting);o.units.push(...h.units),o.units.push(v("pilcrow",{...h.ppr,paraId:c.paraId||`${t}:p${d}`})),d+=1,r.includePageBreaks&&zt(c)&&o.units.push(v("pageBreak",{})),f="paragraph";continue}if(c.type==="table"){let h=s++,y=Xt(c,e.styleResolver,e.theme),k=y.rows.map((R,x)=>({trPr:R.attrs,cells:R.cells.map((I,P)=>({tcPr:I.attrs,story:pe(t,h,x,P)}))}));o.units.push(v("table",{tblPr:Ee(y.attrs),grid:Le(y.attrs),rows:k})),y.rows.forEach((R,x)=>{R.cells.forEach((I,P)=>{$(e,pe(t,h,x,P),I.content,{includePageBreaks:false,appendBodyTail:false,seedComments:false,extraRunFormatting:I.extraRunFormatting});});}),f="table";continue}let p=a++,g=Ue(t,p);o.units.push(v("blockSdt",{...Gt(c.properties),story:g})),$(e,g,c.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${d}`})),r.seedComments&&Zt(o);}function Qt(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 a of e)if(a.kind==="text"){let d=z(a.attrs);r&&d!==l&&s(),o=a.attrs,l=d,r+=a.text;}else s(),t.push({op:"insertEmbed",index:n,kind:a.embedKind,payload:a.payload,attrs:a.attrs}),n+=1;return s(),t}function en(e,t){e.applyRawOps(t.storyId,Qt(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 tn(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,je(r.id),r.content,{includePageBreaks:false,appendBodyTail:false,seedComments:true});for(let r of t.package.endnotes??[])$(n,$e(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)en(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],a=l[1]==="/",d=s.slice(1,a?-2:-1),c=new RegExp(`\\b${n}="[^"]*"`).test(d)?d.replace(new RegExp(`\\b${n}="[^"]*"`),()=>`${n}="${r}"`):`${d} ${n}="${r}"`;return e.replace(s,()=>`<${c}${a?"/>":">"}`)}function nn(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function rn(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 on(e,t,n){let[r,o,l]=e.slice(0,10).split("-").map(p=>parseInt(p,10));if(!Qe(r,o,l))return e;let s=t&&t.trim()?t:"M/d/yyyy",a=p=>String(p).padStart(2,"0"),d=new Date(Date.UTC(r,o-1,l)),f=p=>{try{return new Intl.DateTimeFormat(n||"en",{month:p,timeZone:"UTC"}).format(d)}catch{return new Intl.DateTimeFormat("en",{month:p,timeZone:"UTC"}).format(d)}},c={yyyy:String(r),yy:String(r).slice(-2),MMMM:f("long"),MMM:f("short"),MM:a(o),M:String(o),dd:a(l),d:String(l)};return s.replace(/yyyy|yy|MMMM|MMM|MM|M|dd|d/g,p=>c[p])}function Qe(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 sn(e){return e&&e.replace(/<w:showingPlcHdr\b[^>]*\/>/g,"").replace(/<w:showingPlcHdr\b[^>]*>[\s\S]*?<\/w:showingPlcHdr>/g,"")}function Se(e,t){let n=sn(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,a=e.sdtType==="comboBox"?"w:comboBox":"w:dropDownList",d=be(n,a,"w:lastValue",nn(o));return {properties:{...Se(e,d),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=rn(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(!Qe(o,l,s))throw new j(`Date must be ISO yyyy-mm-dd, got '${t.date}'.`);let a=`${r}T00:00:00`,d=be(n,"w:date","w:fullDate",a),f=e.dateState?.format??e.dateFormat??re(n,"w:dateFormat","w:val"),c=e.dateState?.language,p=on(r,f,c);return {properties:{...Se(e,d),dateFormat:f,dateState:{...e.dateState,fullDate:a,format:f},controlState:{...e.controlState,value:r,placeholder:false}},content:[ke(p)]}}}}function et(e){return e.numPrFromStyle!=null&&e.numPr!=null&&JSON.stringify(e.numPr)===JSON.stringify(e.numPrFromStyle)}function rt(e){if(e._originalFormatting){let n=e._originalFormatting,r={...n};return e.alignment!==(n.alignment||void 0)&&(r.alignment=e.alignment||void 0),et(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.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.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:et(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,bidi:e.bidi||void 0}}function ot(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=tt(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?tt(e.cellMargins):void 0,look:e.look||void 0,bidi:e.bidi||void 0}}function tt(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 it(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 st(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=nt(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?nt(e.margins):void 0}}function nt(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 ln={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,contextualSpacing:null,defaultTextFormatting:null,sectionBreakType:null,bidi:null,outlineLevel:null,bookmarks:null,_originalFormatting:null,_originalRunBoundaries:null,_sectionProperties:null,pPrIns:null,pPrDel:null,pPrChange:null},an={styleId:null,width:null,widthType:null,justification:null,columnWidths:null,tableLayout:null,floating:null,cellMargins:null,look:null,bidi:null,_originalFormatting:null,tblPrChange:null},dn={height:null,heightRule:null,isHeader:false,_originalFormatting:null,trIns:null,trDel:null,trPrChange:null},un={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},cn=new Set(["bold","italic","superscript","subscript","allCaps","smallCaps","emboss","imprint","textShadow","textOutline","hidden","rtl"]);function w(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function B(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=w(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=w(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=w(e.underline);n&&(t.underline={style:S(n.style)||"single",color:w(n.color)??null});let r=w(e.strike);r&&(r.double?t.doubleStrike=true:t.strike=true);let o=w(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=w(e.fontSize);if(l){let h=B(l.size),y=B(l.sizeCs)??h;h!==void 0&&(t.fontSize=h),y!==void 0&&(t.fontSizeCs=y);}let s=w(e.fontFamily);if(s){let h=S(s.ascii);t.fontFamily={ascii:h??null,hAnsi:S(s.hAnsi)??null,eastAsia:S(s.eastAsia),cs:S(s.cs)||h,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 a=w(e.characterSpacing);if(a){let h=B(a.spacing),y=B(a.position),k=B(a.scale),R=B(a.kerning);h!==void 0&&(t.spacing=h),y!==void 0&&(t.position=y),k!==void 0&&(t.scale=k),R!==void 0&&(t.kerning=R);}e.emboss&&(t.emboss=true),e.imprint&&(t.imprint=true),e.textShadow&&(t.shadow=true);let d=w(e.emphasisMark);d&&(t.emphasisMark=S(d.type)||"dot"),e.textOutline&&(t.outline=true),e.hidden&&(t.hidden=true),e.rtl&&(t.rtl=true);let f=w(e.textEffect);f&&(t.effect=S(f.effect)||"blinkBackground");let c=w(e.modernTextEffects);c?.effects&&(t.modernEffects=c.effects);let p=w(e.runStyle),g=S(p?.styleId);return g&&(t.styleId=g),t}function ut(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(a=>!!a):[],s=l.length>0&&l.every(a=>a===l[0])?l[0]:null;for(let a of e){let d=a.codePointAt(0)??0;a==="\xAD"?(o(),n.push({type:"softHyphen"})):a==="\u2011"?(o(),n.push({type:"noBreakHyphen"})):s&&d>=61440&&d<=63743?(o(),n.push({type:"symbol",font:s,char:d.toString(16).toUpperCase().padStart(4,"0")})):r+=a;}return o(),n}function we(e,t){let n=le(Q(t));return {type:"run",formatting:Object.keys(n).length>0?n:void 0,content:ut(e,n)}}function pn(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 fn(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:fn(e)}return 0}function V(e,t=false){let n=w(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 gn(e){let t=w(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 mn(e){let t=w(e.hyperlink);return t?S(t.href)||"":null}function ct(e,t){let n=S(e.fieldData);if(n&&n.length<=2e6)try{let c=JSON.parse(n),p=c.type==="simpleField"?c.content:c.fieldResult;if((c.type==="simpleField"||c.type==="complexField")&&typeof c.instruction=="string"&&Array.isArray(p)){let g=S(e.displayMode);return c.fieldTree&&g&&(c.fieldTree.displayMode=g),c}}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",a=e.fldLock===true||void 0,d=e.dirty===true||void 0,f=S(e.displayMode)||"result";return e.fieldKind==="complex"?{type:"complexField",instruction:l,fieldType:s,fieldCode:[],fieldResult:[o],fldLock:a,dirty:d,fieldTree:{version:1,displayMode:f}}:{type:"simpleField",instruction:l,fieldType:s,content:[o],fldLock:a,dirty:d,fieldTree:{version:1,displayMode:f}}}function pt(e){return {type:"mathEquation",display:S(e.display)||"inline",ommlXml:S(e.ommlXml)||"",plainText:S(e.plainText)||void 0}}function ft(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={},a=t.transform.match(/rotate\(([-\d.]+)deg\)/)?.[1];a&&(s.rotation=Number.parseFloat(a)),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 gt(e){let t={type:"shape",shapeType:S(e.shapeType)||"rect",id:S(e.shapeId)||void 0,size:{width:e.width?c$2(Number(e.width)):0,height:e.height?c$2(Number(e.height)):0}};if(Array.isArray(e.geometryPath)&&e.geometryPath.length>0&&(t.geometryPath=e.geometryPath),e.fillType==="gradient"&&typeof e.gradientStops=="string")try{let r=JSON.parse(e.gradientStops);t.fill={type:"gradient",gradient:{type:S(e.gradientType)||"linear",angle:B(e.gradientAngle)||void 0,stops:r.map(o=>({position:o.position,color:{rgb:o.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 r={solid:"solid",dotted:"dot",dashed:"dash"},o=S(e.outlineStyle);t.outline={width:c$2(e.outlineWidth),color:typeof e.outlineColor=="string"?{rgb:e.outlineColor.replace("#","")}:void 0,style:o&&r[o]||"solid"};}let n={};if(typeof e.rotation=="number")n.rotation=e.rotation;else if(typeof e.transform=="string"){let r=e.transform.match(/rotate\(([-\d.]+)deg\)/)?.[1];r&&(n.rotation=Number.parseFloat(r));}return (e.flipH||String(e.transform||"").includes("scaleX(-1)"))&&(n.flipH=true),(e.flipV||String(e.transform||"").includes("scaleY(-1)"))&&(n.flipV=true),(n.rotation||n.flipH||n.flipV)&&(t.transform=n),{type:"run",content:[{type:"shape",shape:t}]}}function hn(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 a=w(s),d=S(a?.kind);if(!a||!d)continue;let f=w(a.attrs)??{};if(d==="text"){let c=S(a.text);c!==void 0&&r.push({kind:"text",text:c,attributes:f});continue}r.push({kind:"embed",embedKind:d,payload:w(a.payload)??{},attributes:f});}let o=lt(Ce(r)),l=mt(e.value);if(l)try{let s=Re(t,l);t=s.properties;let a=s.content[0];o=lt(a?.type==="paragraph"?a.content:[]);}catch{}return {type:"inlineSdt",properties:t,content:o}}function lt(e){return e.filter(t=>t.type==="run"||t.type==="hyperlink"||t.type==="simpleField"||t.type==="complexField"||t.type==="inlineSdt"||t.type==="mathEquation")}function mt(e){let t=w(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 ht(e){if(e.modelKind!=="commentReference")return null;let t=B(e.commentId);return {type:"run",content:[{type:"commentReference",...t!==void 0?{id:t}:{}}]}}function at(e){if(e.kind==="text")return we(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 ft(e.payload);case "shape":return gt(e.payload);case "field":return ht(e.payload)??ct(e.payload,e.attributes);case "math":return pt(e.payload);case "sdt":return hn(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 yn(e,t){let n;if(e.kind==="embed"&&e.embedKind==="image")n=ft(e.payload);else if(e.kind==="embed"&&e.embedKind==="shape")n=gt(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=(w(e.attributes.ins)??w(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 bn(e,t){if(t.kind==="text"){e.children.push(we(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=ht(t.payload)??ct(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(pt(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 a of e){if(a.kind==="embed"&&a.embedKind==="noteRef"){l(),s();let p=at(a);p&&t.push(p);continue}let d=V(a.attributes.ins??a.attributes.del);if(d){l(),s(),t.push(yn(a,d));continue}let f=mn(a.attributes);if(f!==null){l();let p=o?o.href||(o.anchor?`#${o.anchor}`:""):null;(!o||p!==f)&&(s(),o=gn(a.attributes)),o&&bn(o,a);continue}if(s(),a.kind==="text"){let p=Z(Q(a.attributes)),g=we(a.text,a.attributes);n&&r===p?pn(n,g):(l(),n=g,r=p);continue}l();let c=at(a);c&&t.push(c);}return l(),s(),t}function kn(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"||(cn.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 Sn(e,t,n){if(!n?.length||!e.every(a=>a.type==="run"&&a.content.every(d=>d.type==="text"))||t.some(a=>a.kind!=="text"||a.attributes.hyperlink)||t.map(a=>a.kind==="text"?a.text:"").join("")!==n.map(a=>a.text).join(""))return e;let o=0,l=0,s=[];for(let a of n){let d=kn(a.marksKey);if(!d)return e;s.push(d);let f=a.text.length;for(;f>0;){let c=t[o];if(!c||Z(Q(c.attributes))!==Z(d))return e;let p=c.text.length-l,g=Math.min(f,p);f-=g,l+=g,l===c.text.length&&(o+=1,l=0);}}return n.map((a,d)=>{let f=a.text.length===0?a.formatting:le(s[d]),c={type:"run",content:ut(a.text,f??{})};return f&&Object.keys(f).length>0&&(c.formatting=f),a.propertyChanges?.length&&(c.propertyChanges=a.propertyChanges),c})}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"?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 Rn(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 dt(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,f)=>d.offset-f.offset||(d.kind===f.kind?d.id-f.id:d.kind==="end"?-1:1)),o=[],l=0,s=0,a=d=>{for(;s<r.length&&r[s].offset===d;){let f=r[s++];o.push(n(f));}};a(0);for(let d of e){let f=se(d),c=r.slice(s).map(p=>p.offset).filter(p=>p>l&&p<l+f);if(d.type==="run"&&d.content.every(p=>p.type==="text")){let p=d,g=0;for(let h of c){if(!p)break;let[y,k]=Rn(p,h-l-g);y&&o.push(y),a(h),p=k,g=h-l;}p&&o.push(p);}else o.push(d);l+=f,a(l);}return a(l),o}function Tn(e){if(!Array.isArray(e.bookmarks))return [];let t=[];for(let n of e.bookmarks){let r=w(n),o=B(r?.id);if(!r||o===void 0)continue;let l=B(r.offset)??0,s={name:S(r.name),colFirst:B(r.colFirst),colLast:B(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 xn(e){let t={...ln,...e};return t.styleId=e.pStyle??null,t._sectionProperties=e.sectPr??null,delete t.pStyle,delete t.sectPr,t}function wn(e,t,n,r,o){let l=xn(t),s=Ce(n);s=Sn(s,n,Array.isArray(l._originalRunBoundaries)?l._originalRunBoundaries:void 0),s=dt(s,r);let a=Tn(t).map(p=>({...p,offset:p.offset===Number.MAX_SAFE_INTEGER?s.reduce((g,h)=>g+se(h),0):p.offset}));a.length>0&&(s=dt(s,a,p=>{let g=p;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 d={type:"paragraph",paraId:e||void 0,textId:o?.textId,formatting:rt(l),content:s};o?.renderedPageBreakBefore&&(d.renderedPageBreakBefore=true);let f=V(t.pPrIns,true),c=V(t.pPrDel,true);return f&&(d.pPrIns=f),c&&(d.pPrDel=c),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 Cn(e){for(let t of e)for(let n of t.cells){let r=n.formatting?.borders;if(!r)continue;let o=r.top||r.left||r.right||r.bottom||r.insideH||r.insideV;return o?{top:r.top??o,bottom:r.bottom??o,left:r.left??o,right:r.right??o,insideH:r.insideH??r.bottom??o,insideV:r.insideV??r.right??o}:void 0}}function Pn(e){let t=new Map;e.forEach((r,o)=>{let l=0;for(let s of r.cells){let a=l;if(l+=s.formatting?.gridSpan??1,s.formatting?.vMerge){let d=t.get(a)??[];d.push({rowIndex:o,cell:s}),t.set(a,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 o=null,l=0,s=-1,a=()=>{o&&l<2&&n(o),o=null,l=0;};for(let d of r){let f=d.cell.formatting?.vMerge;f==="restart"?(a(),o=d.cell,l=1,s=d.rowIndex):f==="continue"&&(o&&d.rowIndex===s+1?(l+=1,s=d.rowIndex):(a(),n(d.cell)));}a();}}function In(e,t){let n={...un,...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:st(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 vn(e,t){let n=Array.isArray(t.rows)?t.rows:[],r=[],o=[],l=0;n.forEach((h,y)=>{let k=0;for(let R of Array.isArray(h.cells)?h.cells:[]){for(;r[y]?.[k];)k+=1;let x=R.tcPr??{},I=B(x.rowspan)||1,P=B(x.colspan)||1;o.push({row:y,col:k,rowspan:I,colspan:P,cell:In(e,R)});for(let A=y;A<y+I;A+=1){r[A]??(r[A]=[]);for(let F=k;F<k+P;F+=1)r[A][F]=true;}k+=P,l=Math.max(l,k);}});let s=new Map(o.map(h=>[`${h.row}-${h.col}`,h])),a=new Map;for(let h of o)for(let y=h.row;y<h.row+h.rowspan;y+=1)for(let k=h.col;k<h.col+h.colspan;k+=1)a.set(`${y}-${k}`,h);let d=n.map((h,y)=>{let k=[];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,k.push({...F.cell,formatting:Object.keys(E).length>0?E:void 0}),A+=F.colspan;continue}let D=a.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",k.push({...D.cell,content:[],formatting:H}),A+=D.colspan;}let R={...dn,...h.trPr??{}},x={type:"tableRow",formatting:it(R),cells:k},I=V(R.trIns,true),P=V(R.trDel,true);return I?x.structuralChange={type:"tableRowInsertion",info:I}:P&&(x.structuralChange={type:"tableRowDeletion",info:P}),Array.isArray(R.trPrChange)&&R.trPrChange.length>0&&(x.propertyChanges=R.trPrChange),x});Pn(d);let f=Array.isArray(t.grid)?t.grid.filter(h=>typeof h=="number"):[],c={...an,...t.tblPr??{},columnWidths:f.length>0?f:void 0},p=ot(c);if(!p?.borders){let h=Cn(d);h&&(p={...p??{},borders:h});}let g={type:"table",columnWidths:c.columnWidths||void 0,formatting:p,rows:d};return Array.isArray(c.tblPrChange)&&c.tblPrChange.length>0&&(g.propertyChanges=c.tblPrChange),g}function An(){return {type:"paragraph",content:[{type:"run",content:[{type:"break",breakType:"page"}]}]}}function Fn(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 Yn(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 a=l++;s.rows.forEach((d,f)=>{d.cells.forEach((c,p)=>{n(`${r}:t${a}:r${f}c${p}`,c.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);return t}function _n(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 a=l.get(s.story)??[];a.push(s),l.set(s.story,a);}for(let[s,a]of l){if(a.length===0)continue;let d=Math.min(...a.map(p=>p.start)),f=Math.max(...a.map(p=>p.end)),c=n.get(s)??[];c.push({id:r.id,start:d,end:f}),n.set(s,c);}}return n}var xe=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=Fn(n),this.baseStories=Yn(n),this.comments=_n(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=[],a=0,d=0,f=0,c=g=>{let h=[];for(let y of l)y.start>=a&&y.start<=g&&h.push({id:y.id,kind:"start",offset:y.start-a}),y.end>=a&&y.end<=g&&h.push({id:y.id,kind:"end",offset:y.end-a});return h},p=(g,h)=>{let y=0;for(let k=0;k<g.length;k+=1)g[k]===" "&&(k>y&&s.push({kind:"text",text:g.slice(y,k),attributes:h}),s.push({kind:"embed",embedKind:"tab",payload:{},attributes:h}),y=k+1);y<g.length&&s.push({kind:"text",text:g.slice(y),attributes:h});};for(let g of o){if(g.kind==="text"){p(g.text,g.attributes),f+=g.text.length;continue}if(g.kind==="pilcrow"){let h=`${t}:p${d}`,y=g.paraId===h&&!this.baseParagraphs.has(g.paraId)?"":g.paraId;n.push(wn(y,g.properties,s,c(f),this.baseParagraphs.get(g.paraId))),s=[],d+=1,f+=1,a=f;continue}if(g.embedKind==="table")n.push(vn(this,g.payload));else if(g.embedKind==="blockSdt"){let h=S(g.payload.story),y=ce(g.payload),k=h&&this.storyIds.has(h)?this.storyToBlocks(h):[],R=mt(g.payload.value);if(R)try{let x=Re(y,R);y=x.properties,k=x.content;}catch{}n.push({type:"blockSdt",properties:y,content:k});}else if(g.embedKind==="opaque"){let h=w(g.payload.blob);if(h?.type==="pageBreak")n.push(An());else {let y=r?.[n.length];h?.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 Mn(e,t,n={}){let r=new xe(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,p])=>{let g=`hf:${c}`;return [c,r.storyIds.has(g)&&o(g)?{...p,content:r.storyToBlocks(g)}:p]})));let a=t.package.footers;a&&(n.storyIds===void 0||[...a.keys()].some(c=>o(`hf:${c}`)))&&(a=new Map([...a].map(([c,p])=>{let g=`hf:${c}`;return [c,r.storyIds.has(g)&&o(g)?{...p,content:r.storyToBlocks(g)}:p]})));let f=n.storyIds===void 0||t.package.footnotes?.some(c=>o(`fn:${c.id}`))?t.package.footnotes?.map(c=>{let p=`fn:${c.id}`;return r.storyIds.has(p)&&o(p)?{...c,content:r.storyToBlocks(p),verbatimXml:void 0}:c}):t.package.footnotes;return {...t,package:{...t.package,document:{...t.package.document,content:l},...s?{headers:s}:{},...a?{footers:a}:{},...f?{footnotes:f}:{}}}}function yr(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 On(){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 yt(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 Bn(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 bt(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.slice().buffer}function Nn(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,bt(t));return {document:o.document,referencedFonts:r.referencedFonts,embeddedFonts:o.embeddedFonts,...o.fontTableRelationshipsXml===void 0?{}:{fontTableRelationshipsXml:o.fontTableRelationshipsXml}}}function En(e,t){let n=new Map,r=[],o=false,l=false,s=0,a=0,d=false,f=null,c,p=null,g=new Map,h=new Map,y=[],k=new Map,R=new Map,x=null,I=false,P=0,A=0,F=false,D=null,H=()=>{c=void 0,p=null;},E=()=>{if(!(l||d||a!==0)){d=true;try{for(;!l&&r.length>0;){let i=r.shift();if(!i)break;for(let[u,m]of [...n]){if(l)return;if(n.get(u)===m)try{m(i.update.slice(),i.origin);}catch{}}}}finally{d=false,l&&(r.length=0);}}},b=i=>{H(),a+=1;try{return i()}finally{a-=1,a===0&&E();}},Pe=i=>i?{anchor:{...i.anchor},head:{...i.head}}:null,C=i=>{f!==i&&(e.track_undo(i),f=i);},M=i=>{let u=`table:${i}`;f!==u&&(e.track_table_undo(i),f=u);},kt=i=>{let u=m=>typeof m=="string"&&m===i||typeof m=="number"&&Number.isFinite(m)&&String(m)===i;for(let m of e.story_ids())if(JSON.parse(e.story_segments(m)).some(O=>O.kind==="embed"&&(u(O.payload.embedId)||u(O.payload.id)||u(O.payload.rId))))return m;return null},ae=i=>{let u=kt(i);u&&C(u);},St=()=>{o||(e.set_update_observer((i,u)=>{u!==0&&u!==1||(r.push({update:i.slice(),origin:u===0?"local":"remote"}),E());}),o=true);},Rt=()=>{!o||n.size>0||l||(r.length=0,e.clear_update_observer(),o=false);},Ie=(i,u)=>{let m=i.slice(),T=b(()=>e.open_docx(m,u)),O=Nn(T,m);return D=m,O};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 x=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 x=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 m=c?.head.story??"body";return C(m),b(()=>e.apply_input(i,u))},applyDelete:(i,u)=>{let m=c?.head.story??"body";return C(m),b(()=>e.apply_delete(i,u))},applyInputProfiled:(i,u)=>{let m=c?.head.story??"body";C(m);let T=b(()=>e.apply_input_profiled(i,u)),O=JSON.parse(e.apply_input_profile_json());return {frame:T,profile:O}},applyDeleteProfiled:(i,u)=>{let m=c?.head.story??"body";C(m);let T=b(()=>e.apply_delete_profiled(i,u)),O=JSON.parse(e.apply_input_profile_json());return {frame:T,profile:O}},residentWorkerSnapshot:i=>{if(!x||!I&&k.size===0)return null;let u=e.selection(),m=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:m?[]:y.map(O=>O.slice()),fontsRevision:A,renderInputs:[...k].map(([O,Tt])=>({story:O,env:structuredClone(Tt)})),measureInputs:[...R.values()],layoutInput:x,layoutWithRegions:I,layoutRevision:P}},residentWorkerProbe:()=>!x||!I&&k.size===0?null:{layoutRevision:P},displayHitTestRegionsJson:(i,u,m)=>e.display_hit_test_regions_json(i,u,m),displayVerticalMoveJson:(i,u,m)=>e.display_vertical_move_json(i,u,m),displayRangeRectsJson:(i,u)=>e.display_range_rects_json(i,u),displayRangeRectsRegionJson:(i,u,m,T)=>e.display_range_rects_region_json(i,u,m,T),outlineGlyphJson:(i,u)=>e.outline_glyph_json(i,u),loadState:i=>b(()=>e.load(i)),seedFromDocx:i=>Ie(i,true),openDocx:Ie,materializeDocx:()=>{let i=D,u=e.materialize_docx();return !i||u===void 0?null:b$1(u,bt(i)).document},loadStories:i=>b(()=>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=>b(()=>JSON.parse(e.apply_update_with_inference(i))),applyLocalUpdate:(i,u)=>{C(u),b(()=>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),St();let m=true;return ()=>{m&&(m=false,n.delete(u),Rt());}},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),c={anchor:{...i},head:{...u}};},selection:()=>(c!==void 0||(c=JSON.parse(e.selection())),Pe(c)),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?M(i):C(i),markUndoGroup:i=>{let u=e.undo_depth(),m=Math.max(0,u-i);m>1&&g.set(u,m),h.clear();},undo:()=>b(()=>{let i=e.undo_depth(),u=g.get(i)??1,m=!1;for(let T=0;T<u;T+=1)m=e.undo()||m;return m&&u>1&&(g.delete(i),h.set(e.redo_depth(),u)),m}),redo:()=>b(()=>{let i=e.redo_depth(),u=h.get(i)??1,m=!1;for(let T=0;T<u;T+=1)m=e.redo()||m;return m&&u>1&&(h.delete(i),g.set(e.undo_depth(),u)),m}),canUndo:()=>e.can_undo(),canRedo:()=>e.can_redo(),undoDepth:()=>e.undo_depth(),redoDepth:()=>e.redo_depth(),createStory:(i,u,m="Normal",T="left")=>b(()=>JSON.parse(e.create_story(i,u,m,T))),deleteStory:i=>b(()=>e.delete_story(i)),insertTable:(i,u,m,T)=>(M(i.story),b(()=>JSON.parse(e.insert_table(i.story,i.paraId,i.offset,u,m,T?.name,T?.date)))),insertRow:(i,u,m)=>(M(i.story),b(()=>JSON.parse(e.insert_row(JSON.stringify(i),u==="below",m?.name,m?.date)))),insertColumn:(i,u)=>(M(i.story),b(()=>JSON.parse(e.insert_column(JSON.stringify(i),u==="right")))),deleteRow:(i,u)=>(M(i.anchor.story),b(()=>JSON.parse(e.delete_row(JSON.stringify(i),u?.name,u?.date)))),deleteColumn:i=>(M(i.anchor.story),b(()=>JSON.parse(e.delete_column(JSON.stringify(i))))),deleteTable:i=>(M(i.story),b(()=>JSON.parse(e.delete_table(JSON.stringify(i))))),mergeCells:i=>(M(i.anchor.story),b(()=>JSON.parse(e.merge_cells(JSON.stringify(i))))),splitCell:(i,u,m)=>(M(i.story),b(()=>JSON.parse(e.split_cell(JSON.stringify(i),u,m)))),setCellShading:(i,u)=>(M(i.anchor.story),b(()=>JSON.parse(e.set_cell_shading(JSON.stringify(i),u??void 0)))),setCellTextFormat:(i,u)=>(M(i.anchor.story),b(()=>JSON.parse(e.set_cell_text_format(JSON.stringify(i),JSON.stringify(u))))),setCellBorders:(i,u)=>(M(i.anchor.story),b(()=>JSON.parse(e.set_cell_borders(JSON.stringify(i),JSON.stringify(u))))),setColumnWidth:(i,u)=>(M(i.story),b(()=>JSON.parse(e.set_column_width(JSON.stringify(i),u)))),setTableWidth:(i,u)=>(M(i.story),b(()=>JSON.parse(e.set_table_width(JSON.stringify(i),u)))),insertText:(i,u,m)=>(C(i.story),b(()=>JSON.parse(e.insert_text(i.story,i.paraId,i.offset,u,m?.name,m?.date)))),deleteRange:(i,u)=>(C(i.story),b(()=>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,m)=>(C(i.story),b(()=>JSON.parse(e.replace_range(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,u,m?.name,m?.date)))),splitParagraph:(i,u)=>(C(i.story),b(()=>JSON.parse(e.split_paragraph(i.story,i.paraId,i.offset,u?.name,u?.date)))),mergeParagraphs:(i,u,m)=>(C(i),b(()=>JSON.parse(e.merge_paragraphs(i,u,m?.name,m?.date)))),toggleMark:(i,u)=>{C(i.story),b(()=>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),b(()=>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),b(()=>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),b(()=>e.clear_formatting(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset));},applyParagraphStyle:(i,u,m)=>{C(i.story),b(()=>e.apply_paragraph_style(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,u,m?.name,m?.date));},setParagraphAttrs:(i,u,m)=>{C(i.story),b(()=>e.set_paragraph_attrs(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset,JSON.stringify(u),m?.name,m?.date));},insertImage:(i,u,m)=>(C(i.story),b(()=>JSON.parse(e.insert_image(i.story,i.paraId,i.offset,JSON.stringify(u),m?.name,m?.date)))),setContentControlValue:(i,u)=>{ae(i),b(()=>e.set_content_control_value(i,JSON.stringify(u)));},setContentControlValueAt:(i,u)=>{C(i.story),b(()=>e.set_content_control_value_at(i.story,i.paraId,i.offset,JSON.stringify(u)));},clearContentControlValue:i=>{ae(i),b(()=>e.clear_content_control_value(i));},setImageGeometry:(i,u)=>{ae(i),b(()=>e.set_image_geometry(i,JSON.stringify(u)));},insertPageBreak:i=>{C(i.story),b(()=>e.insert_page_break(i.story,i.paraId,i.offset));},insertSectionBreak:(i,u)=>{C(i.story),b(()=>e.insert_section_break(i.story,i.paraId,i.offset,u));},insertWatermark:(i,u)=>{C(i.story),b(()=>e.insert_watermark(i.story,i.paraId,i.offset,JSON.stringify(u)));},applyRawOps:(i,u)=>b(()=>e.apply_raw_ops(i,JSON.stringify(u))),setParagraphAttr:(i,u,m)=>b(()=>e.set_paragraph_attr(i,u,JSON.stringify(m??null))),addComment:(i,u,m,T)=>b(()=>JSON.parse(e.add_comment(Bn(i),u,m,JSON.stringify(T??null)))),acceptChange:i=>b(()=>JSON.parse(e.accept_change(yt(i)))),rejectChange:i=>b(()=>JSON.parse(e.reject_change(yt(i)))),selectionContext:i=>{let u=JSON.stringify(i);if(p?.key===u)return JSON.parse(p.json);let m=e.selection_context(i.story,i.start.paraId,i.start.offset,i.end.paraId,i.end.offset),T=JSON.parse(m);return p={key:u,json:m},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 m=e.yrs_blocks_for_story(i,JSON.stringify(u)),T=JSON.parse(m);return k.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 br(e){let t=e?.clientId??On(),n=await import('../wasm-F2ETFAYL.mjs');return await n.preloadEditWasm(),En(n.createEditSession(t),t)}export{de as ResidentEngineWorkerClient,Pt as canUseResidentEngineWorker,Jn as compareYrsLocs,Ln as createYrsInputPositionMap,br as createYrsSession,Dn as displayPositionToYrsLoc,tn as documentToYrs,yr as sameYrsSelection,Oe as yrsLocToDisplayPosition,Mn 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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}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};
|