@betteroffice/docx 0.4.2 → 0.5.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/LICENSE +1 -1
- package/README.md +108 -598
- package/dist/chunk-25WGDXBF.mjs +1 -0
- package/dist/chunk-2CCPNW44.mjs +1 -0
- package/dist/chunk-32A4I3T4.mjs +1 -0
- package/dist/chunk-4LO3PSLZ.mjs +2 -0
- package/dist/chunk-67MGRMP3.mjs +1 -0
- package/dist/chunk-6AUR4AA2.mjs +1 -0
- package/dist/chunk-6WT6HKAY.mjs +1 -0
- package/dist/chunk-77ZWGQZN.mjs +1 -0
- package/dist/chunk-7C3Y7LIH.mjs +1 -0
- package/dist/chunk-7WIUNGQW.mjs +1 -0
- package/dist/chunk-7WWFGMMF.mjs +1 -0
- package/dist/chunk-AK2NG7PT.mjs +1 -0
- package/dist/chunk-BR5BFOHF.mjs +1 -0
- package/dist/chunk-CDNWHQH2.mjs +1 -0
- package/dist/chunk-CRTTEHZN.mjs +1 -0
- package/dist/chunk-ETDMQ5GE.mjs +1 -0
- package/dist/{wasm-QXYYV7LU.mjs → chunk-GBOHQ3CJ.mjs} +1 -1
- package/dist/chunk-H7K4SJKK.mjs +1 -0
- package/dist/chunk-ICJH7QUY.mjs +1 -0
- package/dist/chunk-IHETKRDA.mjs +1 -0
- package/dist/chunk-ISBZLVIF.mjs +1 -0
- package/dist/chunk-JSYH6HNV.mjs +2 -0
- package/dist/chunk-KICHSQFN.mjs +1 -0
- package/dist/chunk-KXIGXLFA.mjs +5 -0
- package/dist/chunk-KXLTK7AT.mjs +57 -0
- package/dist/chunk-L3JRNJ34.mjs +1 -0
- package/dist/chunk-LKDHP22R.mjs +1 -0
- package/dist/chunk-LPOEM5WH.mjs +1 -0
- package/dist/chunk-M44BABH2.mjs +1 -0
- package/dist/chunk-MAYPJU23.mjs +1 -0
- package/dist/chunk-N5RE2S3U.mjs +2 -0
- package/dist/chunk-NLYHFVF5.mjs +1 -0
- package/dist/chunk-ONYCW7VV.mjs +4 -0
- package/dist/chunk-QGZ2AB3M.mjs +1 -0
- package/dist/chunk-QWHU7YIW.mjs +2 -0
- package/dist/{chunk-VH7P4734.mjs → chunk-QX2CDKPG.mjs} +1 -1
- package/dist/chunk-RGDE6YQB.mjs +1 -0
- package/dist/chunk-TE3AU2JK.mjs +1 -0
- package/dist/chunk-UDVEZ722.mjs +1 -0
- package/dist/chunk-UQSVFDRV.mjs +2 -0
- package/dist/chunk-VHOOSS4D.mjs +1 -0
- package/dist/chunk-WIDM4EMT.mjs +1 -0
- package/dist/chunk-YITJ4QAO.mjs +1 -0
- package/dist/collaboration/index.d.mts +111 -11
- package/dist/collaboration/index.mjs +1 -1
- package/dist/{content-DSb-6a9T.d.mts → content-DVT06V_6.d.mts} +24 -3
- package/dist/core.d.mts +9 -9
- package/dist/core.mjs +1 -1
- package/dist/displayListQueries-6XjS7B5e.d.mts +1473 -0
- package/dist/docx/index.d.mts +8 -7
- package/dist/docx/index.mjs +1 -2
- package/dist/docxWorker.mjs +1 -0
- package/dist/editor/index.d.mts +14 -12
- package/dist/editor/index.mjs +1 -1
- package/dist/{fontLoader-BNSs0E8K.d.mts → fontLoader-CBkmh4ps.d.mts} +1 -1
- package/dist/{formatting-gqLFeJ9X.d.mts → formatting-p5MneNuy.d.mts} +32 -1
- 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-C-KKULi5.d.mts +5596 -0
- package/dist/layout/index.d.mts +4 -4
- package/dist/layout/index.mjs +1 -1
- package/dist/layout/pagination/index.d.mts +4 -4
- package/dist/layout/render/index.d.mts +37 -53
- package/dist/layout/render/index.mjs +3 -1
- package/dist/{pagedExport-BmSlEhoP.d.mts → pagedExport-DDgA5O7E.d.mts} +92 -9
- package/dist/plugin-api/RenderedDomContext.d.mts +5 -7
- package/dist/plugin-api/index.d.mts +3 -3
- package/dist/plugin-api/resolveItemPositions.d.mts +3 -3
- package/dist/{rezip-Bxiq4Z_R.d.mts → rezip-CfwAYdV4.d.mts} +7 -1
- package/dist/styles/index.d.mts +3 -3
- package/dist/styles/index.mjs +1 -1
- package/dist/{styles-AryxLAhx.d.mts → styles-DZZz2oRy.d.mts} +2 -2
- package/dist/types/content.d.mts +2 -2
- package/dist/types/document.d.mts +6 -6
- package/dist/{types-Cz7S77Ut.d.mts → types-bvPg3KsF.d.mts} +16 -3
- package/dist/utils/comments.d.mts +2 -2
- package/dist/utils/findReplace.mjs +1 -2
- package/dist/utils/index.d.mts +5 -5
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/listState.d.mts +2 -5
- package/dist/utils/stylePreview.d.mts +2 -2
- package/dist/utils/stylePreview.mjs +1 -1
- package/dist/wasm-edit.d.mts +233 -48
- package/dist/wasm-edit.mjs +1 -1
- package/dist/wasm-layout.d.mts +7 -1
- package/dist/wasm-layout.mjs +1 -1
- package/dist/wasm-opc.mjs +1 -1
- package/dist/wasm-parse.d.mts +7 -1
- package/dist/wasm-parse.mjs +1 -1
- package/dist/worker.d.mts +60 -0
- package/dist/worker.mjs +1 -0
- package/dist/yrs/docxWorker.d.mts +20 -0
- package/dist/yrs/docxWorker.mjs +3 -0
- package/dist/yrs/index.d.mts +12 -7
- package/dist/yrs/index.mjs +1 -1
- package/package.json +14 -4
- package/dist/chunk-47Q2FMFF.mjs +0 -1
- package/dist/chunk-4PRCO6EC.mjs +0 -1
- package/dist/chunk-5Z22FORG.mjs +0 -1
- package/dist/chunk-7SUVUKWT.mjs +0 -1
- package/dist/chunk-7ZV6P6NZ.mjs +0 -57
- package/dist/chunk-AXFMDV66.mjs +0 -1
- package/dist/chunk-EBYC3CX7.mjs +0 -1
- package/dist/chunk-GKWXOZZH.mjs +0 -1
- package/dist/chunk-LIOWZSE7.mjs +0 -1
- package/dist/chunk-ML6E23W2.mjs +0 -1
- package/dist/chunk-MLEMGJP7.mjs +0 -1
- package/dist/chunk-QBMNRD5V.mjs +0 -2
- package/dist/chunk-RNNTXPXC.mjs +0 -1
- package/dist/compareDocx-CWOYEBCE.mjs +0 -1
- package/dist/computeLayout-ZTO6TBWX.mjs +0 -1
- package/dist/displayListQueries-BVBDVXoP.d.mts +0 -306
- package/dist/frameDelta-CLeO7K5z.d.mts +0 -807
- package/dist/index-DzZVJC8-.d.mts +0 -2467
- package/dist/parseWasm-BESKFFA3.mjs +0 -1
- package/dist/rustDisplayList-B7uPoItK.d.mts +0 -315
- package/dist/wasm-GFT55YT6.mjs +0 -1
- package/dist/wasm-QI7MWC5D.mjs +0 -1
- package/dist/yrs/residentEngineWorker.d.mts +0 -2
- package/dist/yrs/residentEngineWorker.mjs +0 -1
package/dist/wasm-parse.d.mts
CHANGED
|
@@ -8,12 +8,18 @@ import { W as WasmAsyncInput } from './loadWasmAsset-Cr95TImt.mjs';
|
|
|
8
8
|
|
|
9
9
|
/** Load + instantiate the parser wasm (browser path). Idempotent. */
|
|
10
10
|
declare function preloadParseWasm(input?: WasmAsyncInput): Promise<void>;
|
|
11
|
+
declare const PARAGRAPH_PATCH_WRITER_VERSION = 1;
|
|
12
|
+
declare function paragraphPatchWriterVersionWire(): number | null | undefined;
|
|
11
13
|
declare function parseDocxS9Wire(data: Uint8Array, optionsJson: string): string;
|
|
12
14
|
declare function parseRelationshipsXmlWire(data: Uint8Array, partPath: string): string;
|
|
13
15
|
declare function serializeDocxS10Wire(requestJson: string): string;
|
|
14
16
|
declare function serializeDocxS11Wire(requestJson: string): string;
|
|
15
17
|
declare function serializeDocxS12Wire(requestJson: string): string;
|
|
16
18
|
declare function writeDocxS13Wire(requestJson: string, originalDocx: Uint8Array): Uint8Array;
|
|
19
|
+
declare function writeDocxS13WithWarningsWire(requestJson: string, originalDocx: Uint8Array): {
|
|
20
|
+
bytes: Uint8Array;
|
|
21
|
+
warnings: string[];
|
|
22
|
+
};
|
|
17
23
|
declare function decodeTiffImage(bytes: Uint8Array): Uint8Array;
|
|
18
24
|
|
|
19
|
-
export { decodeTiffImage, parseDocxS9Wire, parseRelationshipsXmlWire, preloadParseWasm, serializeDocxS10Wire, serializeDocxS11Wire, serializeDocxS12Wire, writeDocxS13Wire };
|
|
25
|
+
export { PARAGRAPH_PATCH_WRITER_VERSION, decodeTiffImage, paragraphPatchWriterVersionWire, parseDocxS9Wire, parseRelationshipsXmlWire, preloadParseWasm, serializeDocxS10Wire, serializeDocxS11Wire, serializeDocxS12Wire, writeDocxS13Wire, writeDocxS13WithWarningsWire };
|
package/dist/wasm-parse.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{b as PARAGRAPH_PATCH_WRITER_VERSION,k as decodeTiffImage,c as paragraphPatchWriterVersionWire,d as parseDocxS9Wire,e as parseRelationshipsXmlWire,a as preloadParseWasm,f as serializeDocxS10Wire,g as serializeDocxS11Wire,h as serializeDocxS12Wire,i as writeDocxS13Wire,j as writeDocxS13WithWarningsWire}from'./chunk-YITJ4QAO.mjs';import'./chunk-HGKSOBXK.mjs';import'./chunk-TTRUPDAB.mjs';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { b as DocxCommandClient, c as DocxCommandInitRequest, d as DocxCommandInitReply, e as DocxCommandConnection, f as DocxWorkerEditSessionOptions, g as DocxWorkerEditSession, h as DocxCommandFrame, i as DocxEchoGlyphSet } from './index-C-KKULi5.mjs';
|
|
2
|
+
export { B as BuildCommandFrameInput, j as DocxCommandAck, k as DocxCommandApplyContext, l as DocxCommandApplyResult, m as DocxCommandCheckpoint, n as DocxCommandEchoContext, o as DocxCommandEnvelope, p as DocxCommandFramePayload, q as DocxCommandHooks, r as DocxCommandHooksEnvironment, D as DocxCommandHooksFactory, s as DocxCommandHost, t as DocxCommandHostOptions, u as DocxCommandIntent, v as DocxCommandKind, w as DocxCommandMethods, x as DocxCommandPageIdentity, y as DocxCommandPayload, z as DocxCommandPayloads, A as DocxCommandPosition, C as DocxCommandPreflightResult, E as DocxCommandRecoveryState, F as DocxCommandRegistry, G as DocxCommandReply, H as DocxCommandSelection, I as DocxCommandStagedPresentation, J as DocxCommandTableContext, K as DocxCommandViewportRequest, M as DocxCommentChangeResult, N as DocxCommentResult, O as DocxEchoDamageDependency, P as DocxEchoGlyphLine, Q as DocxEchoGraphemeBoundary, R as DocxEchoRect, S as DocxEchoStyleRun, T as DocxEchoTransform, U as DocxEditState, V as DocxEffectiveFormatting, W as DocxEngineWorkerSourceOpened, X as DocxFrameReservations, Z as DocxHostImage, _ as DocxHostProposalGrant, $ as DocxNavigationIntent, a0 as DocxPointModifiers, a1 as DocxSelectionIntent, a2 as DocxSelectionPointIntent, a3 as DocxSourceWorkerClient, a4 as DocxStagedPageBitmap, a5 as DocxStoredMarks, a6 as DocxSvgMedia, a7 as DocxWorkerCommandEngine, a8 as DocxWorkerCommandState, a9 as PreparedDocxCommand, aa as ResolvedDocxCommandSelection, ab as SessionFailure, ac as takePreloadedDocxSourceWorker } from './index-C-KKULi5.mjs';
|
|
3
|
+
import './pagedExport-DDgA5O7E.mjs';
|
|
4
|
+
import './content-DVT06V_6.mjs';
|
|
5
|
+
import './formatting-p5MneNuy.mjs';
|
|
6
|
+
import './docx/wrapTypes.mjs';
|
|
7
|
+
import './types-bvPg3KsF.mjs';
|
|
8
|
+
import './displayListQueries-6XjS7B5e.mjs';
|
|
9
|
+
import './layout/pagination/index.mjs';
|
|
10
|
+
import './types/document.mjs';
|
|
11
|
+
import './styles-DZZz2oRy.mjs';
|
|
12
|
+
import './plugin-api/index.mjs';
|
|
13
|
+
import './utils/comments.mjs';
|
|
14
|
+
import './utils/findReplace.mjs';
|
|
15
|
+
import './utils/stylePreview.mjs';
|
|
16
|
+
import './loadWasmAsset-Cr95TImt.mjs';
|
|
17
|
+
import './rezip-CfwAYdV4.mjs';
|
|
18
|
+
|
|
19
|
+
declare function createDocxCommandConnection(client: DocxCommandClient, init: DocxCommandInitRequest | DocxCommandInitReply): Promise<DocxCommandConnection>;
|
|
20
|
+
|
|
21
|
+
declare function createDocxWorkerEditSession<O, X = never>(options: DocxWorkerEditSessionOptions<O, X>): DocxWorkerEditSession<X>;
|
|
22
|
+
|
|
23
|
+
declare function closeCommandBitmap(bitmap: ImageBitmap): void;
|
|
24
|
+
declare function discardCommandPresentation(frame: DocxCommandFrame | undefined): void;
|
|
25
|
+
|
|
26
|
+
/** @internal A glyph set with its lookups. */
|
|
27
|
+
interface EchoGlyphIndex {
|
|
28
|
+
set: DocxEchoGlyphSet;
|
|
29
|
+
/** The f32 scale exactly; JSON carries its shortest decimal. */
|
|
30
|
+
horizontal: number;
|
|
31
|
+
/** Pixel advance of a unit count, widened from f32 as layout widens it. */
|
|
32
|
+
advance(units: number): number;
|
|
33
|
+
chars: ReadonlyMap<string, number>;
|
|
34
|
+
kerning: ReadonlyMap<number, number>;
|
|
35
|
+
unsafe: ReadonlySet<number>;
|
|
36
|
+
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
interface EchoGlyphPlacement {
|
|
39
|
+
glyphIds: number[];
|
|
40
|
+
xs: number[];
|
|
41
|
+
advances: number[];
|
|
42
|
+
end: number;
|
|
43
|
+
}
|
|
44
|
+
/** @internal */
|
|
45
|
+
declare function indexEchoGlyphSet(set: DocxEchoGlyphSet): EchoGlyphIndex;
|
|
46
|
+
/**
|
|
47
|
+
* Places `text` as the engine lays out a cluster-positioned line from pen `x`: each character's
|
|
48
|
+
* advance is its shaped units plus the pair adjustment with the character after it, scaled in f32.
|
|
49
|
+
* Undefined when a character or a pair is outside the glyph set.
|
|
50
|
+
*/
|
|
51
|
+
declare function placeEchoGlyphs(glyphs: EchoGlyphIndex, text: string, next: string, x: number): EchoGlyphPlacement | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Places `text` on a line starting at `x`; with `center`, the pen starts where the engine centers
|
|
54
|
+
* the line's width in that space, at half the free width and never left of `x`.
|
|
55
|
+
*/
|
|
56
|
+
declare function placeEchoLine(glyphs: EchoGlyphIndex, text: string, next: string, x: number, center?: number): EchoGlyphPlacement | undefined;
|
|
57
|
+
/** Width of the leading letters and digits, which no line break can split. */
|
|
58
|
+
declare function leadingWordWidth(text: string, advances: readonly number[]): number;
|
|
59
|
+
|
|
60
|
+
export { DocxCommandClient, DocxCommandConnection, DocxCommandFrame, DocxCommandInitReply, DocxCommandInitRequest, DocxEchoGlyphSet, DocxWorkerEditSession, DocxWorkerEditSessionOptions, type EchoGlyphIndex, closeCommandBitmap, createDocxCommandConnection, createDocxWorkerEditSession, discardCommandPresentation, indexEchoGlyphSet, leadingWordWidth, placeEchoGlyphs, placeEchoLine };
|
package/dist/worker.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a,b as b$1,d,i as i$1}from'./chunk-RGDE6YQB.mjs';import {l,a as a$1,d as d$2}from'./chunk-KICHSQFN.mjs';export{f as indexEchoGlyphSet,j as leadingWordWidth,h as placeEchoGlyphs,i as placeEchoLine}from'./chunk-KICHSQFN.mjs';import {i,k,g,h,d as d$1}from'./chunk-6WT6HKAY.mjs';export{i as SessionFailure,j as closeCommandBitmap,k as discardCommandPresentation}from'./chunk-6WT6HKAY.mjs';import'./chunk-EUUIJVM6.mjs';import'./chunk-LPOEM5WH.mjs';import'./chunk-CRTTEHZN.mjs';import'./chunk-25WGDXBF.mjs';import'./chunk-HGKSOBXK.mjs';import {b}from'./chunk-TTRUPDAB.mjs';async function _t(n,f){let c="outcomes"in f?n.commandInitialGeneration(f):n.commandGeneration;if(c===void 0||c!==n.commandGeneration)throw "outcomes"in f&&k(f.frame),new i("disposed","Worker command document was replaced");let u,d,r=new Set,h$1=new Set,C=new Set;function S(p,N=false){if(u)return u;u=p instanceof i?p:new i("crash",p instanceof Error?p.message:String(p));let W=u;for(let T of C)T();C.clear();for(let T of h$1)T(W);h$1.clear();let E=()=>{for(let T of [...r])try{T(W);}catch{}};return N?queueMicrotask(E):E(),u}function k$1(p,N){return n.commandGeneration!==c?Promise.reject(S(new i("disposed","Worker command document was replaced"))):u?Promise.reject(u):d?Promise.reject(new i("disposed","Command connection was disposed")):new Promise((W,E)=>{h$1.add(E);let T;try{T=p();}catch(I){T=Promise.reject(I);}T.then(I=>{h$1.delete(E),u||d||n.commandGeneration!==c?(N?.(I),E(u??S(new i("disposed","Worker command document was replaced")))):W(I);},I=>{h$1.delete(E),h(I)?(E(I),S(I,true)):E(S(I));});})}function A(){return d||(d=Promise.resolve().then(()=>{let p=n.commandGeneration===c;p&&n.onFailure(null),S(new i("disposed","Command connection was disposed")),r.clear(),p&&n.destroy();}),d)}n.onFailure(p=>{S(p);}),n.commandFailure&&S(n.commandFailure);try{let N=function(E){let T=E?.frame;if(!g(E))throw k(T),new i("message","Malformed worker command acknowledgement");if(E.session!==p.session||E.incarnation!==p.incarnation||E.epoch!==p.epoch)throw k(E.frame),S(new i("disposed","Worker command document was replaced"));return E};var U=N;let p="outcomes"in f?f:await k$1(()=>n.commandInit(f),E=>k(E.frame));if(n.commandGeneration!==c||n.commandInitialGeneration(p)!==c)throw k(p.frame),new i("disposed","Worker command document was replaced");if(!g(p)||p.session!==f.session||p.incarnation!==f.incarnation||p.epoch!==f.epoch||p.version!==(f.version??0)||p.throughSeq!==(f.throughSeq??0)||p.selection===void 0||p.editState===void 0||!p.frame||p.frame.baseRevision!==void 0||p.frame.coversThroughSeq!==p.throughSeq)throw k(p.frame),new i("message","Worker command initialization has invalid state");let W=E=>k(E.frame);return {initial:p,requestFullFrame:()=>k$1(()=>n.requestFullFrame().then(N),W),requestViewport:n.requestViewport?E=>k$1(()=>n.requestViewport(E)):void 0,client:{onFrame(E){if(u||d)return ()=>{};let T=n.onFrame?.(I=>{!u&&!d&&n.commandGeneration===c?E(I):n.commandGeneration===c&&k(I);})??(()=>{});return C.add(T),()=>{C.delete(T),T();}},call:{edit:E=>k$1(()=>n.edit(E).then(N),W),checkpoint:()=>k$1(()=>n.checkpoint())},get failure(){return u},onFailure(E){return u?(E(u),()=>{}):(r.add(E),()=>{r.delete(E);})},dispose:A}}}catch(p){throw await A(),p}}var Ye=new WeakMap;function vt(n){Ye.get(n)?.fence();}function Ze(n,f){return Ye.get(n)?.cancel(f)??[]}function Ke(){let n=new Map,f=Array.from({length:11},()=>new Map);function c(r,h){n.set(r,h);let C=r;for(let S of f){let k=Math.floor(C/32),A=S.get(k)??0;if(S.set(k,A|1<<C%32),A!==0)break;C=k;}}function u(r){if(!n.delete(r))return;let h=r;for(let C of f){let S=Math.floor(h/32),k=(C.get(S)??0)&~(1<<h%32);if(k!==0){C.set(S,k);break}C.delete(S),h=S;}}function*d(r,h){let C=f[r].get(h)??0;for(;C!==0;){let S=31-Math.clz32(C&-C),k=h*32+S;r===0?yield n.get(k):yield*d(r-1,k),C&=C-1;}}return {set:c,delete:u,values:()=>d(f.length-1,0)}}function Je(){return {size:0,lanes:{input:Ke(),collab:Ke(),background:Ke()}}}function gt(n){let f=new Map,c=new WeakMap,u=new Map,d=new Set,r=Je(),h=r,C,S=0,k=Number.isSafeInteger(n.inputBurstCap)&&n.inputBurstCap>0?n.inputBurstCap:8,A=0;function U(){if(h.size===0)return;let y=Je();h.next=y,h=y;}function p(y){y.segment.lanes[ye(y.entry.draft)].set(y.order,y);}function N(y,x){let P=y.entry.draft,F=x.options.after,q=F&&c.get(F)===c.get(y.tickets[0])?{...x,options:{...x.options,after:P.options.after}}:x,a=Kt(P,q)?n.coalesce?.(P,q):void 0;return a&&ye(a)===ye(P)&&a.options.after===P.options.after&&!a.options.fence?a:void 0}function W(y,x){let P=C?.segment===h?C:void 0,F=P&&N(P,y);if(F&&P)return P.tickets.push(x),P.entry={id:P.entry.id,draft:F,tickets:P.tickets},c.set(x,c.get(P.tickets[0])),P.entry;if(y.options.fence&&U(),S===Number.MAX_SAFE_INTEGER)throw new RangeError("Outbox order space is exhausted");let q=[x],a={id:x.id,draft:y,tickets:q},v={entry:a,tickets:q,segment:h,order:++S,previous:C};C&&(C.next=v),C=v,f.set(a.id,v),c.set(x,{id:a.id}),h.size+=1;let b=y.options.after;if(b){v.afterId=c.get(b)?.id??b.id;let w=u.get(v.afterId);w||u.set(v.afterId,w=new Set),w.add(v);}return (!b||!f.has(v.afterId))&&p(v),y.options.fence&&U(),a}function E(y){if(f.delete(y.entry.id),y.segment.lanes[ye(y.entry.draft)].delete(y.order),y.segment.size-=1,y.previous&&(y.previous.next=y.next),y.next&&(y.next.previous=y.previous),C===y&&(C=y.previous),y.afterId!==void 0){let P=u.get(y.afterId);P?.delete(y),P?.size===0&&u.delete(y.afterId);}let x=u.get(y.entry.id);if(x)for(let P of x)p(P);for(;r.size===0&&r.next;)r=r.next;f.size===0&&(A=0);}function T(y,x,P){for(let F of r.lanes[y].values()){if(P?.(F.entry))return;let q=F.entry.draft.options.after;if(!(q&&(f.has(F.afterId)||q.seq===void 0))&&x(F.entry))return F}}function I(y,x){for(;r.size===0&&r.next;)r=r.next;let F=(A>=k?T("collab",y,x):void 0)??T("input",y,x)??T("collab",y,x)??T("background",y,x);if(!F)return;let q=ye(F.entry.draft)==="input"?Math.min(k,A+1):0;return E(F),A=q,F.entry}function j(y,x){let P=y.map(F=>c.get(F)?.id??F.id);for(let F=0;F<P.length;F+=1){let q=u.get(P[F]);if(q)for(let a of q)x.has(a)||(x.add(a),P.push(a.entry.id));}}function z(y){for(let P of y){let F=c.get(P)?.id??P.id,q=u.get(F);q&&(d.add(q.values()),u.delete(F));}let x=[];for(;d.size&&x.length<64;){let P=d.values().next().value,F=P.next();if(F.done){d.delete(P);continue}let q=F.value;if(!f.has(q.entry.id))continue;let a=u.get(q.entry.id);a&&(d.add(a.values()),u.delete(q.entry.id)),x.push(q.entry),E(q);}return x}function ie(y){let x=new Set,P=[];for(let q of f.values())y(q.entry)&&(x.add(q),P.push(q.tickets[0]));j(P,x);let F=[];for(let q of f.values())x.has(q)&&(F.push(q.entry),E(q));return F}let _={get size(){return f.size},get entries(){return [...f.values()].map(y=>y.entry)},enqueue:W,takeNext:I,remove:ie,clear(){let y=[...f.values()].map(x=>x.entry);return f.clear(),c=new WeakMap,u.clear(),d.clear(),r=Je(),h=r,C=void 0,A=0,y}};return Ye.set(_,{fence:U,cancel:z}),_}function ye(n){return n.options.lane??"input"}function Kt(n,f){let c=n.options,u=f.options;return !c.fence&&!u.fence&&c.coalesceKey!==void 0&&c.coalesceKey===u.coalesceKey&&n.kind===f.kind&&ye(n)===ye(f)&&c.group===u.group&&c.after?.id===u.after?.id&&(c.expectVersion??false)===(u.expectVersion??false)}function yt(n){let f=Number.isSafeInteger(n.maxEchoEntries)&&n.maxEchoEntries>=0?n.maxEchoEntries:64,c=n.now??Date.now,u=new Map,d=new Set,r=[],h=-1,C=-1,S=-1,k,A,U=0,p=false,N=0,W=0;function E(a){N===0&&(W=0),N+=1;try{return a()}finally{N-=1;}}function T(a,v){let b=I(),w=W;try{return v(),!0}catch{return false}finally{let O=Math.max(0,I()-b);if(W=w+O,W>2)try{n.onEchoOverrun?.({hook:a,elapsedMs:O,eventTotalMs:W});}catch{}}}function I(){try{let a=c();return Number.isFinite(a)?a:0}catch{return 0}}function j(a,v){let b=u.get(a);b&&(u.delete(a),b.resolve(v));}function z(a){d.has(a)||(d.size>=256&&d.delete(d.values().next().value),d.add(a)),j(a,"dropped");}function ie(a){return E(()=>{if(p||f===0)return !1;if(r.length>=f){if(n.echoOverflow!=="evict-oldest")return !1;r=r.slice(r.length-f+1);}return r=[...r,a],n.echo&&T("paint",()=>n.echo.paint(r)),!0})}function _(a){return E(()=>{if(p)return !1;let v=[...r,...a].sort((b,w)=>b.ticket.id-w.ticket.id);return v.length>f?!1:(r=v,a.length>0&&n.echo&&T("paint",()=>n.echo.paint(r)),!0)})}function y(a,v){E(()=>{if(p)return;let b=new Set(a.map(K=>K.id)),w=r.filter(K=>!b.has(K.ticket.id)),O=w.length!==r.length;v!==void 0&&f>0&&w.length>=f&&n.echoOverflow==="evict-oldest"&&(w=w.slice(w.length-f+1));let Q=v!==void 0&&w.length<f;r=Q?[...w,v]:w,(O||Q)&&n.echo&&T("paint",()=>n.echo.paint(r));});}function x(a,v){E(()=>{if(p)return;let b=new Set(a.map(O=>O.id)),w=r.filter(O=>b.has(O.ticket.id));r=r.filter(O=>!b.has(O.ticket.id));for(let O of w){let Q=O.seq??O.ticket.seq;Q!==void 0&&z(Q);}for(let O of a)O.seq!==void 0&&z(O.seq);w.length>0&&n.echo&&T("drop",()=>n.echo.drop(w,v));});}function P(a,v,b){let w=[],O=[];for(let J of r){let Y=J.seq??J.ticket.seq;(!v&&Y!==void 0&&Y<=a.coversThroughSeq?w:O).push(J);}let Q=A,K=U;A={coverage:a.coversThroughSeq,revision:a.revision};try{if(!b(w,O)||p||K!==U)return "stale";if(h=Math.max(h,a.coversThroughSeq),k=k===void 0?a.revision:Math.max(k,a.revision),v)return "presented";let J=new Set(w);r=r.filter(Z=>!J.has(Z));let Y=Math.min(h,a.coversThroughSeq);S=Math.max(S,Y);for(let Z of u.keys())Z<=Y&&j(Z,d.has(Z)?"dropped":"presented");return C=Math.max(C,Y),"presented"}finally{K===U&&(A=Q);}}function F(a){return E(()=>{let v=!1;function b(w,O){return n.echo?T("present",()=>{let K=n.echo.present(a,w,O);v=!n.transactionalPresentation||K!==!1;})&&v:(v=!0,!0)}try{let w=a.coversThroughSeq===h;if(p||a.coversThroughSeq<h||w&&(!n.sameCoverageFrames||h<0||k===void 0||a.revision<=k)||A&&(a.coversThroughSeq<A.coverage||a.coversThroughSeq===A.coverage&&(!n.sameCoverageFrames||a.revision<=A.revision)))return "stale";if(a.baseRevision!==void 0&&a.baseRevision!==k)return n.requestFullFrame(),"base-mismatch";if(n.transactionalPresentation&&n.echo)return P(a,w,b);if(w)return k=a.revision,b([],r),p?"stale":"presented";let O=[],Q=[],K=h,J=S;for(let B of r){let ne=B.seq??B.ticket.seq;(ne!==void 0&&ne<=a.coversThroughSeq?O:Q).push(B);}r=Q,h=a.coversThroughSeq,k=a.revision;let Y=b(O,Q);if(p)return "stale";let Z=Math.min(h,a.coversThroughSeq);if(Y&&(S=Math.max(S,Z)),!Y)for(let B of O){let ne=B.seq??B.ticket.seq;ne!==void 0&&ne<=a.coversThroughSeq&&(S===J||ne>S)&&z(ne);}for(let B of u.keys())B>Z||(Y?j(B,d.has(B)?"dropped":"presented"):B>K&&z(B));if(!Y)for(let B=Math.max(K+1,S+1,Z-256+1);B<=Z;B+=1)z(B);return C=Math.max(C,Z),"presented"}finally{if(!v)try{n.discardFrame?.(a);}catch{}}})}function q(a){if(p||d.has(a))return Promise.resolve("dropped");if(a<=C)return Promise.resolve("presented");let v=u.get(a);if(v)return v.promise;u.size>=1024&&z(u.keys().next().value);let b,w=new Promise(O=>{b=O;});return u.set(a,{promise:w,resolve:b}),w}return {get presentedThroughSeq(){return h},get revision(){return k},get pending(){return r.slice()},event:E,add:ie,attach:_,replace:y,drop:x,present:F,whenPresented:q,reset(){p||(U+=1,A=void 0,h=-1,C=-1,S=-1,k=void 0);},dispose(){E(()=>{if(p)return;p=!0;let a=r;r=[];for(let v of u.keys())j(v,"dropped");d.clear(),a.length>0&&n.echo&&T("drop",()=>n.echo.drop(a,"disposed"));});}}}var Jt=4096;function St(){let n=[];function f(u){let d=0,r=n.length;for(;d<r;){let h=Math.floor((d+r)/2),C=n[h];if(u<C[0])r=h;else if(u>C[1])d=h+1;else return true}return false}function c(u){let d=0;for(;d<n.length&&n[d][1]<u-1;)d+=1;let r=n[d];if(r&&r[0]<=u+1){r[0]=Math.min(r[0],u),r[1]=Math.max(r[1],u);let h=n[d+1];h&&h[0]<=r[1]+1&&(r[1]=Math.max(r[1],h[1]),n.splice(d+1,1));return}if(n.length===Jt)throw new i("out-of-memory","Command replay ledger exhausted: 4096 disjoint ranges per epoch");n.splice(d,0,[u,u]);}return {contains:f,add:c,values(){let u=[];for(let[d,r]of n)for(let h=d;h<=r;h+=1)u.push(h);return u},clear(){n.length=0;}}}function we(){let n,f,c=new Promise((u,d)=>{n=u,f=d;});return c.catch(()=>{}),{promise:c,resolve:n,reject:f}}function G(n){return n instanceof i?n:new i("crash",n instanceof Error?n.message:String(n))}function $e(n){return n.code==="crash"||n.code==="trap"||n.code==="out-of-memory"||n.code==="silence"}function de(n){return n?.status==="refused"||n?.status==="cancelled"}function Te(n){return n?.status==="applied"&&n.committed!==false}function bt(n,f){return n!==void 0&&Number.isSafeInteger(n)&&n>0?n:f}function kt(n){let f=n.connection.initial,c=n.maxRecoveryAttempts===0?0:bt(n.maxRecoveryAttempts,2),u=c===0?void 0:a$1(n.source),d=f.session,r=f.epoch,h$1=bt(n.maxInFlight,4),C=n.enqueue??queueMicrotask,S=new WeakMap,k=new WeakMap,A=new Set,U=new Set,p=new Map,N=new Map,W=new Set,E=false,T,I=new Map,j=new Map,z=new Map,ie=St(),_=new Map,y=0,x=f.throughSeq,P=f.incarnation,F,q,a={epoch:r,version:f.version,throughSeq:f.throughSeq,presentedThroughSeq:-1,selection:f.selection,editState:f.editState},v=false,b,w=false,O=false,Q=false,K=-1,J=true,Y=f.throughSeq,Z=0,B,ne=0,ze=f.throughSeq,Be=f.throughSeq,qe=f.throughSeq,De=f.revisions?.selection??0,Xe=f.revisions?.layout??0,Pe=0,He=0,Oe=0,me=new Set,Ee=n.holdTimeoutMs??2e3;if(!Number.isFinite(Ee)||Ee<0)throw new TypeError("Invalid hold timeout");let Me=n.now??Date.now,qt=n.timer??((e,t)=>{let o=setTimeout(e,t);return ()=>{clearTimeout(o);}}),Ae=new Map,Fe=new Set,ae=new Set,he=gt({inputBurstCap:n.inputBurstCap,coalesce:n.coalesce}),M=yt({echo:n.echo&&{paint:e=>n.echo.paint(e),drop:(e,t)=>n.echo.drop(e,t),present(e,t,o){J=false;let i=n.echo.present(e,t,o);return J=!n.transactionalPresentation||i!==false,i}},maxEchoEntries:n.maxEchoEntries,now:n.now,sameCoverageFrames:n.sameCoverageFrames,transactionalPresentation:n.transactionalPresentation,echoOverflow:n.echoOverflow,discardFrame:te,onEchoOverrun:n.onEchoOverrun,requestFullFrame:()=>Dt(Y,Z)});function L(e){return !v&&!b&&e.active&&q===e}function ee(e,t){e.done||(e.done=true,Fe.delete(e),ae.delete(e),e.cleanup(),t instanceof i?e.result.reject(t):e.result.resolve(t));}function se(e,t){return {ok:false,refusal:{code:e,...t===void 0?{}:{detail:t}}}}function Ce(){if(v||b||w)return;let e=q;if(!(!e||!L(e)))for(let t of ae){if(!L(e)||w)return;if(t.signal?.aborted){ee(t,se("superseded","aborted"));continue}let o=false;for(let g of A)if(g.ticket.id<=t.watermark&&g.seq===void 0&&!g.ackSettled){o=true;break}if(o)continue;ae.delete(t);let i$1=e.connection.client.call.query;if(!i$1){ee(t,se("unsupported"));continue}let l={session:d,incarnation:P,epoch:r,afterSeq:x>e.seenMark?x:e.seenSeq},s=++t.attempt;t.connection=e;let m=()=>!t.done&&t.attempt===s&&L(e);try{i$1.call(e.connection.client.call,l,t.kind,t.args).then(g=>{if(!m())return;if(!d$2(g)||g.ok&&(g.at.incarnation!==l.incarnation||g.at.epoch!==l.epoch||g.at.throughSeq<l.afterSeq)){V(new i("message","Malformed or unfenced query reply"));return}let D=n.queries[t.kind].stale;g.ok&&D!=="answer-at-fence"&&D.reject.some(X=>(X==="doc"?a.version:X==="selection"?De:Xe)>g.at[X])?ee(t,se("superseded")):ee(t,g);},g=>{m()&&V(G(g));}).catch(g=>{m()&&V(G(g));});}catch(g){m()&&V(G(g));}}}function Pt(e,t={}){let o=v||b!==void 0,i={hold:void 0,opened:Me(),waiters:new Set},l=t.signal,s={reason:e,get released(){return o},release(){if(!o){o=true,Ae.delete(s),l?.removeEventListener("abort",s.release);for(let m of i.waiters)m();i.waiters.clear();}}};return i.hold=s,o||(Ae.set(s,i),l?.aborted?s.release():l?.addEventListener("abort",s.release,{once:true})),s}function Et(e,t,o={}){let i=we(),l={kind:e,args:t,watermark:y,attempt:0,done:false,signal:o.signal,result:i,cleanup:()=>{}},s=[...Ae.values()].filter(X=>X.hold!==o.within),m=new Map,g=o.signal,D=()=>ee(l,se("superseded","aborted"));if(l.cleanup=()=>{g?.removeEventListener("abort",D);for(let[X,H]of m)X.waiters.delete(H.release),H.cancel();m.clear();},Fe.add(l),v)ee(l,se("disposed"));else if(b)ee(l,b);else if(!n.queries||!d$1(n.queries,e)||!q?.connection.client.call.query)ee(l,se("unsupported"));else if(g?.aborted)D();else if(s.some(X=>Me()-X.opened>=Ee))ee(l,se("busy"));else if(g?.addEventListener("abort",D,{once:true}),s.length===0)ae.add(l),Ce();else for(let X of s){let H=()=>{if(g?.aborted){D();return}if(Me()-X.opened>=Ee){ee(l,se("busy"));return}m.get(X).cancel(),m.delete(X),X.waiters.delete(H),m.size===0&&!l.done&&(l.watermark=y,ae.add(l),Ce());},ke={release:H,cancel:()=>{}};m.set(X,ke),X.waiters.add(H),ke.cancel=qt(()=>ee(l,se("busy")),Math.max(0,Ee-(Me()-X.opened)));}return i.promise}function et(){for(let e of Ae.keys())e.release();}function te(e){if(e!==void 0)try{n.discardFrame?.(e);}catch{}}function tt(){a={...a,presentedThroughSeq:M.presentedThroughSeq};let e=a;for(let t of [...U]){if(v||b||a!==e)break;if(U.has(t))try{t(e);}catch{}}}function nt(e){!e.ackSettled||!e.presentationSettled||e.released||(e.released=true,A.delete(e));}function re(e,t){e.presentationSettled||(e.presentationSettled=true,k.delete(e),e.presentation.resolve(t),e.seq!==void 0&&(I.delete(e.seq),j.delete(e.seq),z.get(e.seq)?.resolve(t),z.delete(e.seq)),nt(e));}function Se(e,t){e.ackSettled||(e.ackSettled=true,e.outcome=t,e.ack.resolve(t),nt(e));}function Ft(){let e=we(),t=we(),o={ticket:{id:++y,get seq(){return S.get(o.ticket).seq},get ack(){return S.get(o.ticket).ack.promise},get presented(){return S.get(o.ticket).presentation.promise}},ack:e,presentation:t,ackSettled:false,presentationSettled:false};return S.set(o.ticket,o),A.add(o),o}function Ct(e,t){for(let o of e){let i=S.get(o);Se(i,{seq:i.seq,status:"cancelled",reason:t}),re(i,"dropped");}M.drop(e,t);}function We(e,t=false){let o=Ze(he,e);for(;;){if(Ct(o.map(i=>i.tickets[0]),"dependency-refused"),o.length<64){ae.size&&Ce();return}if(!t){ot(()=>We([]));return}o=Ze(he,[]);}}function ot(e){try{C(()=>{if(!(v||b))try{M.event(e);}catch(t){$(G(t));}});}catch(t){$(G(t));}}function rt(e){let t=S.get(e);if(t?.seq!==void 0&&ie.contains(t.seq))return true;let o=t?.seq===void 0?void 0:p.get(t.seq);return de(o?.outcome??t?.outcome)}function it(e){try{ie.add(e);}catch(t){throw $(G(t)),t}}function Ie(e,t){try{n.recovery.onRecovery?.({phase:e,incarnation:P,attempt:ne,diverged:[...me].sort((o,i)=>o-i),historyReset:F!==void 0,failure:t});}catch{}}function st(e,t,o,i=false){if(e.outcome&&!o&&!i||e.outcome&&t.status==="duplicate")return;let l=e.outcome,s=e.group;if(l||(Oe-=1),Te(l)&&(Pe-=1),e.outcome=t,Te(t)&&(Pe+=1),_.delete(t.seq),de(t)&&it(t.seq),s.outcome=t,Se(s,t),!de(t)){e.presentationStatus!==void 0&&re(s,e.presentationStatus);return}re(s,"dropped"),M.drop([e.ticket],t.reason??t.status),We([e.ticket]),o&&!de(l)&&(me.add(e.envelope.seq),at(e.envelope.seq),Ie("diverged"));}function at(e){let t=N.get(e);t&&(W.add(t.values()),N.delete(e)),!E&&Qe();}function Qe(e=false){if(E=true,v||b)return;let t=e?1/0:64;for(;W.size&&t>0;){t-=1;let o=W.values().next().value,i=o.next();if(i.done){W.delete(o);continue}let l=N.get(i.value);l&&(W.add(l.values()),N.delete(i.value));let s=p.get(i.value);!s||de(s.outcome)||(it(s.envelope.seq),s.outcome||(Oe-=1),Te(s.outcome)&&(Pe-=1),s.outcome={seq:s.envelope.seq,status:"cancelled",reason:"dependency-refused"},_.delete(s.envelope.seq),w&&me.add(s.envelope.seq),s.group.outcome=s.outcome,Se(s.group,s.outcome),re(s.group,"dropped"),M.drop([s.ticket],"dependency-refused"),We([s.ticket],e));}W.size?(T??(T=we()),ot(Qe)):(E=false,T?.resolve(),T=void 0);}function be(e,t,o=false){let i$1=t?.frame;if(!L(e))return te(i$1),false;if(!g(t))return te(i$1),V(new i("message","Malformed command acknowledgement")),false;if(t.session!==d||t.incarnation!==P||t.epoch!==r)return te(t.frame),false;if(t.throughSeq>x||t.frame&&t.frame.coversThroughSeq>x||t.outcomes.some(m=>m.seq>t.throughSeq))return te(t.frame),V(new i("message","Command acknowledgement exceeds sent coverage")),false;let l=false,s=false;try{M.event(()=>{for(let g of t.outcomes){let D=p.get(g.seq);D&&st(D,g,o);}let m=p.get(t.throughSeq);m&&(m.confirmedVersion=t.version),(t.throughSeq>a.throughSeq||t.throughSeq===a.throughSeq&&t.version>=a.version)&&(a={...a,throughSeq:t.throughSeq,version:t.version}),"selection"in t&&t.throughSeq>=ze&&(a={...a,selection:t.selection},ze=t.throughSeq),"editState"in t&&t.throughSeq>=Be&&(a={...a,editState:t.editState},Be=t.throughSeq),t.revisions&&t.throughSeq>=qe&&(De=t.throughSeq===qe?Math.max(De,t.revisions.selection):t.revisions.selection,Xe=t.throughSeq===qe?Math.max(Xe,t.revisions.layout):t.revisions.layout,qe=t.throughSeq),t.frame&&(s=!0,l=ct(t.frame)),c===0&&W.size===0&&Ue(a.throughSeq,!0),tt(),n.onAck?.(t);});}catch(m){return s||te(t.frame),$(m instanceof i?m:new i("message",m instanceof Error?m.message:String(m))),false}return pe(),l}function ct(e){let t=M.presentedThroughSeq,o=J;J=true,Y=e.coversThroughSeq,Z=e.revision;try{let i=M.present(e),l=!!n.transactionalPresentation&&!J;if(i!=="presented"||M.presentedThroughSeq<=t)return l;let s=J?"presented":"dropped",m=Math.min(M.presentedThroughSeq,e.coversThroughSeq);for(let[g,D]of j){if(g>m)break;j.delete(g),D.presentationStatus=s,!(!D.outcome||de(D.outcome))&&re(D.group,s);}return l}finally{J=o;}}function xt(e,t){if(!L(e)||w){te(t);return}if(t===void 0||!g({session:d,incarnation:P,epoch:r,throughSeq:a.throughSeq,version:a.version,outcomes:[],frame:t})){te(t),V(new i("message","Malformed command frame"));return}if(t.coversThroughSeq>a.throughSeq){te(t);return}try{M.event(()=>{ct(t),tt();});}catch(o){$(o instanceof i?o:new i("message",o instanceof Error?o.message:String(o)));}}function ce(e,t){if(!e.active)return Promise.resolve();e.active=false,e.failure=t;try{e.unsubscribe();}catch{}try{e.unsubscribeFrame?.();}catch{}try{e.unsubscribeAck?.();}catch{}for(let o of Fe)o.connection===e&&(o.connection=void 0,o.attempt+=1,ae.add(o));e.cancelReplay?.(t),e.cancelReplay=void 0;try{return Promise.resolve(e.connection.client.dispose()).catch(()=>{})}catch{return Promise.resolve()}}function ut(e){let t={connection:e,active:true,fullFrameBusy:false,fullFrameThroughSeq:-1,fullFrameRetries:0,seenSeq:x,seenMark:x,unsubscribe:()=>{}};q=t;let o=e.client.onFailure(i=>{L(t)&&(w?ce(t,i):V(i));});if(t.active?t.unsubscribe=o:o(),t.active&&e.client.onFrame){let i=e.client.onFrame(l=>xt(t,l));t.active?t.unsubscribeFrame=i:i();}if(t.active&&e.client.onAck){let i=e.client.onAck(l=>be(t,l));t.active?t.unsubscribeAck=i:i();}return t}function $(e){if(!(v||b)){b=e,w=false;for(let t of Fe)ee(t,e);et(),q&&ce(q,e),he.clear(),_.clear(),M.dispose();for(let t of [...A])t.ackSettled||(t.ackSettled=true,t.ack.reject(e)),re(t,"dropped");p.clear(),N.clear(),W.clear(),T?.resolve(),T=void 0,I.clear(),j.clear();for(let t of z.values())t.resolve("dropped");z.clear(),ie.clear(),U.clear(),Ie("failed",e),me.clear();}}function V(e){if(!(v||b)){if(w){q&&ce(q,e);return}if(c===0||!$e(e)){if(c===0&&$e(e))try{M.event(()=>{We([],!0),Qe(!0);});}catch(t){$(G(t));return}$(e);return}w=true,ne=0,me.clear(),q&&ce(q,e),_.clear(),Q=false,Tt(e).catch(t=>$(G(t)));}}function Ge(e,t,o){let i=h(t)?t.refusal.seq:e.envelope.seq,l=p.get(i)??e;return M.event(()=>{st(l,{seq:l.envelope.seq,status:"refused",reason:"unknown-outcome"},o,true),at(l.envelope.seq);}),G(t)}function Rt(e,t){return new Promise((o,i$1)=>{let l=false;function s(g){l||(l=true,e.cancelReplay===m&&(e.cancelReplay=void 0),g());}let m=g=>s(()=>i$1(g));if(e.cancelReplay=m,!L(e)){m(e.failure??new i("disposed","Command connection is closed"));return}try{e.connection.client.call.edit(n.copyCommandForDispatch?.(t)??a$1(t)).then(g=>{l?te(g?.frame):s(()=>o(g));},g=>s(()=>i$1(g)));}catch(g){s(()=>i$1(g));}})}async function Tt(e){let t=e;for(;!v&&!b&&ne<c;){if(ne+=1,P+=1,Ie("recovering",t),v||b)return;let o;try{if(T&&await T.promise,v||b)return;let i$1=F&&{...F,state:F.state.slice()},l=await n.recovery.reopen({source:a$1(u),checkpoint:i$1,session:d,incarnation:P,epoch:r,refusedSeqs:ie.values(),replayAppliedSeqs:[...p.values()].filter(X=>Te(X.outcome)).map(X=>X.envelope.seq)}),s=l.initial;if(o=s?.frame,v||b){te(o),o=void 0;try{await l.client.dispose();}catch{}return}let m=ut(l);if(!g(s)||s.session!==d||s.incarnation!==P||s.epoch!==r||s.throughSeq!==(F?.throughSeq??f.throughSeq)||s.version!==(F?.version??f.version))throw new i("message","Reopened command connection has invalid initial state");if(l.client.failure)throw l.client.failure;M.reset(),j.clear();for(let[X,H]of I)H.presentationStatus=void 0,j.set(X,H);a={epoch:r,version:s.version,throughSeq:s.throughSeq,presentedThroughSeq:-1,selection:s.selection,editState:s.editState},ze=s.throughSeq,Be=s.throughSeq,qe=s.throughSeq,De=s.revisions?.selection??0,Xe=s.revisions?.layout??0,o=void 0,be(m,s);let g$1=[...p.values()].sort((X,H)=>X.envelope.seq-H.envelope.seq),D=s.throughSeq;for(let X of g$1){if(!L(m))throw m.failure;if(de(X.outcome))continue;let H={...X.envelope,incarnation:P,replay:!0},ke;try{ke=await Rt(m,H);}catch(xe){throw xe instanceof i?xe:Ge(X,xe,!0)}if(D=Math.max(D,X.envelope.seq),be(m,ke,!0),T&&await T.promise,!L(m)){if(v||b)return;throw m.failure}if(!ke.outcomes.some(xe=>xe.seq===X.envelope.seq))throw new i("message","Replay acknowledgement omitted command outcome")}if(!L(m))throw m.failure;m.seenSeq=D,m.seenMark=x,w=!1,K=-1,Ie("recovered"),me.clear(),ae.size&&Ce(),pe();return}catch(i){if(t=G(i),q&&ce(q,t),v||b)return;if(!$e(t))break}finally{te(o);}}!v&&!b&&$(t);}function Dt(e,t){let o=q;!o||!L(o)||((o.fullFrameRevision===void 0||e>o.fullFrameThroughSeq||e===o.fullFrameThroughSeq&&t>o.fullFrameRevision)&&(o.fullFrameThroughSeq=e,o.fullFrameRevision=t),Ve(o));}function dt(e){return M.presentedThroughSeq>e.fullFrameThroughSeq||M.presentedThroughSeq===e.fullFrameThroughSeq&&(!n.sameCoverageFrames||M.revision!==void 0&&M.revision>=e.fullFrameRevision)}function Ve(e){if(!L(e)||e.fullFrameBusy)return;e.fullFrameBusy=true;let t=e.fullFrameThroughSeq,o=e.fullFrameRevision;try{n.requestFullFrame(e.connection).then(i$1=>{if(!L(e)){te(i$1?.frame);return}let l=M.presentedThroughSeq,s=be(e,i$1);if(e.fullFrameBusy=!1,!!L(e)){if(s){if(e.fullFrameRetries=0,(e.fullFrameThroughSeq>t||e.fullFrameThroughSeq===t&&e.fullFrameRevision>o)&&!dt(e)){Ve(e);return}e.fullFrameThroughSeq=-1,e.fullFrameRevision=void 0;return}if(dt(e)){e.fullFrameRetries=0,e.fullFrameThroughSeq=-1,e.fullFrameRevision=void 0;return}if(e.fullFrameRetries=M.presentedThroughSeq>l?0:e.fullFrameRetries+1,e.fullFrameRetries>=4){let m=new i("message","Full frame responses did not satisfy requested coverage and revision");w?ce(e,m):$(m);return}Ve(e);}},i=>{L(e)&&(e.fullFrameBusy=!1,w?ce(e,G(i)):V(G(i)));}).catch(i=>{L(e)&&(e.fullFrameBusy=!1,V(G(i)));});}catch(i){e.fullFrameBusy=false,w?ce(e,G(i)):V(G(i));}}function Xt(){if(c===0||!n.recovery.checkpoint||a.throughSeq===K)return false;let e=Pe,t=He;return e===0&&t===0?false:n.checkpointPolicy?n.checkpointPolicy({applied:e,bytes:t}):e>=128||t>=1024*1024}function Ot(e){if(!e||typeof e!="object"||!(e.state instanceof Uint8Array)||e.epoch!==r||!Number.isSafeInteger(e.throughSeq)||e.throughSeq<0||e.throughSeq>a.throughSeq||!Number.isFinite(e.version)||e.version>a.version||F&&(e.throughSeq<F.throughSeq||e.version<F.version)||e.throughSeq===a.throughSeq&&e.version!==a.version)return false;let t=p.get(e.throughSeq),o=F?.throughSeq===e.throughSeq?F.version:f.throughSeq===e.throughSeq?f.version:t?.confirmedVersion;if(o===void 0||o!==e.version)return false;for(let i of p.values())if(i.envelope.seq<=e.throughSeq&&!i.outcome)return false;return true}function Mt(e){Q=true,K=a.throughSeq;let t=n.recovery.checkpoint,o;try{o=t(e.connection);}catch(i$1){Q=false,i$1 instanceof i?V(i$1):pe();return}o.then(i=>{L(e)&&(Ot(i)&&(F={...i,state:i.state.slice()},Ue(i.throughSeq)),Q=false,pe());},i$1=>{L(e)&&(Q=false,i$1 instanceof i?V(i$1):pe());}).catch(i=>{L(e)&&(Q=false,V(G(i)));});}function Ue(e,t=false){for(let[o,i]of p){if(o>e||t&&(!i.outcome||!i.rpcSettled))break;Te(i.outcome)&&(Pe-=1),He-=i.bytes;let l=i.envelope.afterSeq;if(l!==void 0){let s=N.get(l);s?.delete(o),s?.size===0&&N.delete(l);}p.delete(o);}}function je(e){e.rpcSettled=true,c===0&&W.size===0&&Ue(a.throughSeq,true);}function At(e){if(n.holdForCoalescing?.(e.draft)!==true)return false;let t=e.draft.options.after;if(t)return t.seq!==void 0&&_.get(t.seq)===true;for(let o of _.values())if(o)return true;return false}function Wt(e){let t=e.draft.options.after;if(!t)return true;let o=S.get(t);return o!==void 0&&o.seq!==void 0&&!rt(t)}function It(e,t){if(x>=Number.MAX_SAFE_INTEGER){$(new i("message","Command sequence space is exhausted"));return}let o=++x,i$1=e.draft,l=i$1.options,s={session:d,incarnation:P,seq:o,basis:{epoch:r,version:a.version},kind:i$1.kind,payload:i$1.payload,...l.after?{afterSeq:l.after.seq}:{},...l.expectVersion!==void 0?{expectVersion:l.expectVersion}:{},...l.inputTime!==void 0?{inputTime:l.inputTime}:{},...l.lastInputTime!==void 0?{lastInputTime:l.lastInputTime}:{},...l.group!==void 0?{group:l.group}:{}},m=S.get(e.tickets[0]),g={envelope:s,ticket:e.tickets[0],group:m,rpcSettled:false,bytes:0};if(p.set(o,g),I.set(o,g),j.set(o,g),Oe+=1,m.seq=o,s.afterSeq!==void 0){let D=N.get(s.afterSeq);D||N.set(s.afterSeq,D=new Set),D.add(o);}if(I.size>1024){let D=I.values().next().value;D.presentationStatus="dropped",re(D.group,"dropped"),M.drop([D.ticket],"presentation-overflow");}if(L(t)){_.set(o,n.holdForCoalescing?.(i$1)===true);try{g.envelope=a$1(s);let D=n.commandBytes?.(g.envelope)??0;g.bytes=Number.isFinite(D)&&D>=0?D:0,He+=g.bytes;let X=n.copyCommandForDispatch?.(s)??a$1(g.envelope);t.connection.client.call.edit(X).then(H=>{try{be(t,H);}finally{je(g);}},H=>{try{L(t)&&V(H instanceof i?H:Ge(g,H,!1));}finally{je(g);}}).catch(H=>{L(t)&&V(G(H));});}catch(D){try{L(t)&&V(D instanceof i?D:Ge(g,D,!1));}finally{je(g);}}ae.size&&Ce();}}function Lt(){let e=q;if(!(!e||!L(e)||w||Q)){if(Xt()){_.size===0&&Oe===0&&Mt(e);return}for(;L(e)&&!w&&_.size<h$1;){let t=he.takeNext(Wt,n.holdForCoalescing?At:void 0);if(!t)break;It(t,e);}}}function pe(){if(!(v||b||w||O)){O=true;try{C(()=>{O=!1;try{Lt();}catch(e){$(G(e));}});}catch(e){O=false,$(G(e));}}}function Nt(e,t,o={}){let i=Ft();if(v)return Se(i,{status:"cancelled",reason:"disposed"}),re(i,"dropped"),i.ticket;if(b)return i.ackSettled=true,i.ack.reject(b),re(i,"dropped"),i.ticket;let l=o.after&&S.get(o.after);if(o.after&&(!l||rt(o.after)))return Se(i,{status:"cancelled",reason:"dependency-refused"}),re(i,"dropped"),i.ticket;let s={kind:e,payload:t,options:{...o}};try{M.event(()=>{let m=he.enqueue(s,i.ticket);m.tickets.length>1&&(S.set(i.ticket,S.get(m.tickets[0])),A.delete(i)),k.set(S.get(m.tickets[0]),{draft:m.draft,originalIntentCount:m.tickets.length});let g=m.draft.options.echo,D=g===void 0?void 0:{ticket:m.tickets[0],value:g};m.tickets.length>1?M.replace([m.tickets[0]],D):D&&M.add(D);});}catch(m){$(G(m));}return pe(),i.ticket}function zt(e,t){if(v||b||w)return false;let o=new Set,i=[];for(let l of e){let s=S.get(l);if(!s||s.presentationSettled||de(s.outcome)||s.seq!==void 0&&s.seq<=M.presentedThroughSeq)return false;o.add(s);}for(let l of [...o].sort((s,m)=>s.ticket.id-m.ticket.id)){let s=k.get(l);if(!s||s.draft.options.echo!==void 0)return false;let m=t(s.draft,s.originalIntentCount);if(m===void 0)return false;i.push({record:l,entry:s,value:m});}return M.event(()=>{if(v||b||w||i.some(({record:s,entry:m})=>s.presentationSettled||de(s.outcome)||s.seq!==void 0&&s.seq<=M.presentedThroughSeq||k.get(s)!==m||m.draft.options.echo!==void 0))return false;for(let{entry:s,value:m}of i)s.draft.options.echo=m;let l=M.attach(i.map(({record:s,value:m})=>({ticket:s.ticket,value:m})));if(!l)for(let{entry:s}of i)s.draft.options.echo=void 0;return l})}let Bt={backend:"worker",get state(){return a},submit:Nt,attachEcho:zt,read:Et,hold:Pt,get stage(){return v?"disposed":b?"failed":w?"recovering":"ready"},whenPresented(e){if(v||b)return Promise.resolve("dropped");let t=p.get(e)??I.get(e);if(ie.contains(e))return Promise.resolve("dropped");let o=t&&S.get(t.ticket);if(o)return o.presentation.promise;if(e<=x)return M.whenPresented(e);let i=z.get(e);if(i)return i.promise;if(z.size>=1024){let s=z.keys().next().value;z.get(s).resolve("dropped"),z.delete(s);}let l=we();return z.set(e,l),l.promise},subscribe(e){return v||b?()=>{}:(U.add(e),()=>{U.delete(e);})},flush(){if(vt(he),b)return Promise.reject(b);let e=[...A].filter(o=>!o.ackSettled).map(o=>o.ack.promise);pe();let t=Promise.all(e).then(()=>{});return t.catch(()=>{}),t},dispose(){if(B)return B;let e=we();B=e.promise,v=true,w=false;for(let o of Fe)ee(o,se("disposed"));et();let t=q?ce(q,new i("disposed","Edit session was disposed")):Promise.resolve();he.clear(),_.clear(),M.dispose();for(let o of [...A])Se(o,{seq:o.seq,status:"cancelled",reason:"disposed"}),re(o,"dropped");p.clear(),N.clear(),W.clear(),T?.resolve(),T=void 0,I.clear(),j.clear();for(let o of z.values())o.resolve("dropped");return z.clear(),ie.clear(),U.clear(),me.clear(),t.then(()=>e.resolve()),B}},Ht=ut(n.connection);return be(Ht,f),n.connection.client.failure&&V(n.connection.client.failure),Bt}function Yt(n){let f=new WeakMap([[n.connection,n.connection]]),c=new Set,u=kt({...n,onAck(d){n.onAck?.(d);for(let r of c)r(d);},copyCommandForDispatch:d=>d.kind==="applyRemoteUpdate"||d.kind==="applyRemoteUpdateChunks"||d.kind==="collabPipe"?d:a$1(d),discardFrame:k,sameCoverageFrames:true,transactionalPresentation:true,echoOverflow:"decline",maxEchoEntries:256,recovery:{...n.recovery,async reopen(d){let r=await n.recovery.reopen(d);return f.set(r,r),r}},requestFullFrame(d){let r=f.get(d);return r?r.requestFullFrame():Promise.reject(new i("message","Command connection cannot request a full frame"))}});return Object.assign(u,{subscribeAck(d){return c.add(d),()=>{c.delete(d);}}})}var Ne=class n extends a{constructor(c){super(c);b(this,"fontListeners",new Set);b(this,"memoryListeners",new Set);b(this,"presentedFontsRevision",0);b(this,"cutReservation",null);this.observe();}static adopt(c){if(c instanceof n)return c;Object.setPrototypeOf(c,n.prototype);let u=c;return u.fontListeners=new Set,u.memoryListeners=new Set,u.presentedFontsRevision=0,u.observe(),u}observe(){let c=this.worker.onmessage;this.worker.onmessage=u=>{if(c(u),this.terminalError)return;let d=u.data;if(d.ok&&d.commandFrame){let r=d.commandFrame,h=this.commandIdentity;if(!h||r.session!==h.session||r.incarnation!==h.incarnation||r.epoch!==h.epoch)return}if(d.memory)for(let r of this.memoryListeners)try{r(structuredClone(d.memory));}catch{}if(d.ok&&d.fontEnvironmentEvent){let r=d.fontEnvironmentEvent,h=this.commandIdentity;if(h&&r.session===h.session&&r.incarnation===h.incarnation&&r.epoch===h.epoch)for(let C of this.fontListeners)try{C(structuredClone(r));}catch{}}if(d.ok){let r=d.commandAck,h=this.commandIdentity,S=h&&r&&g(r)&&r.session===h.session&&r.incarnation===h.incarnation&&r.epoch===h.epoch?r.frame:d.commandFrame?.frame,k=S?.payload.fontEnvironment;if(S&&k&&k.revision>this.presentedFontsRevision){this.presentedFontsRevision=k.revision;for(let A of this.fontListeners)try{A(structuredClone({...k,phase:"presentation",frameEpoch:S.revision}));}catch{}}}};}async openSourceCut(c){if(l(c),this.openedHeapLimit||this.bootstrapped)throw new b$1("Document worker already holds a document");let u={bytes:c.heapLimitBytes};this.openedHeapLimit=u,this.cutReservation=u;try{let d={...c,bytes:c.bytes.slice()},r=await this.request({type:"openSource",source:d},[d.bytes.buffer]);if(r.previewRefused)return this.releaseCut(u),null;if(!r.sourceDocument)throw new b$1("Document worker omitted the opened source");return r.sourceDocument}catch(d){throw this.releaseCut(u),d}}releaseCut(c){this.openedHeapLimit===c&&(this.openedHeapLimit=null),this.cutReservation===c&&(this.cutReservation=null);}async openSource(c){if(l(c),c.cut)throw new TypeError("A source cut opens through openSourceCut");if(this.openedHeapLimit&&this.openedHeapLimit!==this.cutReservation||this.bootstrapped)throw new b$1("Document worker already holds a document");let u=this.cutReservation,d$1={bytes:c.heapLimitBytes};this.openedHeapLimit=d$1;try{let r=c.bytes?{...c,bytes:c.bytes.slice(),...c.state?{state:c.state.slice()}:{}}:c,h=c.collaboration?.initialUpdate===void 0?void 0:new Uint8Array(c.collaboration.initialUpdate),C=h?{...r,collaboration:{...r.collaboration,initialUpdate:h}}:r,S=r.bytes?[r.bytes.buffer]:[];r.state&&S.push(r.state.buffer),h&&S.push(h.buffer);let k=await this.request({type:"openSource",source:C},S);if(!k.sourceDocument||!k.stateVector)throw new b$1("Document worker omitted the opened source");return this.cutReservation===u&&(this.cutReservation=null),k.layoutRevision!==void 0&&(this.revision=k.layoutRevision),{document:k.sourceDocument,hostJson:k.hostJson,clientId:k.clientId,clientClock:k.clientClock,stateVector:new Uint8Array(k.stateVector),...k.frame?{preview:wt(k)}:{},...k.svgMedia?{svgMedia:k.svgMedia}:{}}}catch(r){let h=r instanceof d&&this.cutReservation===u?u:null;throw this.openedHeapLimit===d$1&&(this.openedHeapLimit=h),this.cutReservation===u&&(this.cutReservation=h),r}}async previewSource(c){let u=await this.request({type:"previewSource",preview:c});return u.layoutRevision!==void 0&&(this.revision=u.layoutRevision),wt(u)}async prewarm(){await this.warm();}onFontEnvironment(c){return this.fontListeners.add(c),()=>{this.fontListeners.delete(c);}}onMemory(c){return this.memoryListeners.add(c),()=>{this.memoryListeners.delete(c);}}frameRequestPending(c=true){return [...this.pending.values()].some(({type:u})=>u==="openSource"||u==="previewSource")||super.frameRequestPending(c)}request(...c){return c[0].type==="openSource"&&(this.documentSequence+=1),super.request(...c)}fenceCommands(){this.presentedFontsRevision=0,super.fenceCommands();}fail(c,u=true){this.fontListeners?.clear(),this.memoryListeners?.clear(),super.fail(c,u);}};function Zt(){let n=i$1();return n?Ne.adopt(n):null}function wt(n){if(!n.frame)throw new b$1("Document worker response omitted its FrameDelta");if(!n.caret)throw new b$1("Document worker response omitted its caret snapshot");if(n.selection===void 0)throw new b$1("Document worker response omitted its selection");return {frame:new Uint8Array(n.frame),...n.pageFrames?{pageFrames:n.pageFrames.map(f=>new Uint8Array(f))}:{},updates:(n.updates??[]).map(f=>new Uint8Array(f)),engineMs:n.engineMs??0,workerTotalMs:n.workerTotalMs??0,engineProfile:n.engineProfile,caret:n.caret,selection:n.selection,selectionCursor:n.selectionCursor??null,caretPainted:n.caretPainted??false,replayMs:n.replayMs??0,replayedPages:n.replayedPages??0,layoutRevision:n.layoutRevision??0,...n.documentVersion===void 0?{}:{documentVersion:n.documentVersion},...n.documentPreview===void 0?{}:{documentPreview:n.documentPreview},...n.documentAsOpened===void 0?{}:{documentAsOpened:n.documentAsOpened},deletedUnits:n.deletedUnits??0,...n.layoutJson!==void 0?{layoutJson:n.layoutJson}:{},...n.layoutMeta!==void 0?{layoutMeta:n.layoutMeta}:{},...n.layoutProvisional?{layoutProvisional:true}:{}}}export{Ne as DocxSourceWorkerClient,_t as createDocxCommandConnection,Yt as createDocxWorkerEditSession,Zt as takePreloadedDocxSourceWorker};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { D as DocxCommandHooksFactory } from '../index-C-KKULi5.mjs';
|
|
2
|
+
import '../pagedExport-DDgA5O7E.mjs';
|
|
3
|
+
import '../content-DVT06V_6.mjs';
|
|
4
|
+
import '../formatting-p5MneNuy.mjs';
|
|
5
|
+
import '../docx/wrapTypes.mjs';
|
|
6
|
+
import '../types-bvPg3KsF.mjs';
|
|
7
|
+
import '../displayListQueries-6XjS7B5e.mjs';
|
|
8
|
+
import '../layout/pagination/index.mjs';
|
|
9
|
+
import '../types/document.mjs';
|
|
10
|
+
import '../styles-DZZz2oRy.mjs';
|
|
11
|
+
import '../plugin-api/index.mjs';
|
|
12
|
+
import '../utils/comments.mjs';
|
|
13
|
+
import '../utils/findReplace.mjs';
|
|
14
|
+
import '../utils/stylePreview.mjs';
|
|
15
|
+
import '../loadWasmAsset-Cr95TImt.mjs';
|
|
16
|
+
import '../rezip-CfwAYdV4.mjs';
|
|
17
|
+
|
|
18
|
+
declare function setResidentCommandHooksFactory(factory: DocxCommandHooksFactory): void;
|
|
19
|
+
|
|
20
|
+
export { setResidentCommandHooksFactory };
|