@betteroffice/docx 0.4.3 → 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-KSZTTO3B.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-3RPZ44TT.mjs +0 -1
- package/dist/chunk-47Q2FMFF.mjs +0 -1
- package/dist/chunk-5Z22FORG.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-FK7X7557.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-SHVHVJUB.mjs +0 -1
- package/dist/compareDocx-URPCPAQT.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-JPDPN2B2.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
|
@@ -1,28 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import '../
|
|
4
|
-
import '../
|
|
5
|
-
import '../
|
|
1
|
+
import { ad as CollaborationReplica, ae as CollaborationTransport, af as CollaborationProviderOptions, ag as CollaborationStatus, ah as CollaborationPeer, ai as CollaborationCursor, aj as CollaborationPeerListener, ak as CollaborationStatusListener, al as CollaborationErrorListener, am as PipeCursor, an as PipePeer, ao as PipeOutput, ap as PipeOp, aq as AsyncCollaborationReplica, ar as YrsSelection, Y as YrsSession } from '../index-C-KKULi5.mjs';
|
|
2
|
+
export { as as CollaborationAwarenessState, at as CollaborationError, au as CollaborationErrorCode, av as CollaborationPresence, aw as CollaborationResolvedUser, ax as CollaborationStatusChange, ay as CollaborationTextInsertion, az as CollaborationTransportEvent, aA as CollaborationUpdateOrigin, aB as CollaborationUser } from '../index-C-KKULi5.mjs';
|
|
3
|
+
import '../pagedExport-DDgA5O7E.mjs';
|
|
4
|
+
import '../content-DVT06V_6.mjs';
|
|
5
|
+
import '../formatting-p5MneNuy.mjs';
|
|
6
6
|
import '../docx/wrapTypes.mjs';
|
|
7
|
-
import '../
|
|
8
|
-
import '../
|
|
9
|
-
import '../
|
|
10
|
-
import '../
|
|
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';
|
|
11
12
|
import '../plugin-api/index.mjs';
|
|
12
|
-
import '../
|
|
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';
|
|
13
18
|
|
|
14
19
|
declare class CollaborationProvider {
|
|
15
20
|
private readonly replica;
|
|
21
|
+
private readonly piped;
|
|
22
|
+
private readonly asyncReplica;
|
|
23
|
+
private replicaTail;
|
|
24
|
+
private replicaBytes;
|
|
25
|
+
private openEpoch;
|
|
16
26
|
private readonly transport;
|
|
17
27
|
private readonly maxFrameBytes;
|
|
18
28
|
private readonly maxMessagesPerFrame;
|
|
19
29
|
private readonly maxPendingBytes;
|
|
30
|
+
private readonly syncChunkBytes;
|
|
31
|
+
private readonly maxSyncBytes;
|
|
32
|
+
private syncHeld;
|
|
33
|
+
private syncHeldBytes;
|
|
34
|
+
private syncJoinPending;
|
|
35
|
+
private syncRequestOwed;
|
|
36
|
+
private updateBatch;
|
|
20
37
|
private readonly localUser;
|
|
21
38
|
private readonly statusListeners;
|
|
22
39
|
private readonly errorListeners;
|
|
23
40
|
private readonly peerListeners;
|
|
24
41
|
private readonly pendingFrames;
|
|
25
42
|
private awarenessRecords;
|
|
43
|
+
private readonly awarenessGenerations;
|
|
44
|
+
private awarenessGeneration;
|
|
45
|
+
private awarenessFloor;
|
|
46
|
+
private readonly arrivalsInFlight;
|
|
26
47
|
private unsubscribeReplica;
|
|
27
48
|
private unsubscribeTransport;
|
|
28
49
|
private hasTransportSubscription;
|
|
@@ -36,6 +57,8 @@ declare class CollaborationProvider {
|
|
|
36
57
|
private nextListenerId;
|
|
37
58
|
private queuedBytes;
|
|
38
59
|
private isFlushing;
|
|
60
|
+
/** Whether the merge the replica is handed now may report typing; a SyncStep2 may not. */
|
|
61
|
+
private arrivalInfers;
|
|
39
62
|
private localClock;
|
|
40
63
|
private reportedClockExhaustion;
|
|
41
64
|
private localCursor;
|
|
@@ -61,9 +84,56 @@ declare class CollaborationProvider {
|
|
|
61
84
|
private cleanupTransport;
|
|
62
85
|
private handleTransportEvent;
|
|
63
86
|
private handleOpen;
|
|
87
|
+
private sendHandshake;
|
|
88
|
+
private sendFullUpdate;
|
|
64
89
|
private handleMessage;
|
|
90
|
+
private isCurrentOpen;
|
|
91
|
+
private resetReplicaQueue;
|
|
92
|
+
private enqueueReplicaMessages;
|
|
93
|
+
/** Queues a remote update; updates arriving while the replica is busy merge in one `applyUpdateChunks` call. */
|
|
94
|
+
private enqueueRemoteUpdate;
|
|
65
95
|
private respondToSyncStep1;
|
|
96
|
+
/**
|
|
97
|
+
* Whether the SyncStep1 owed to an opening peer waits for the held join to merge. Only a provider that chunks its
|
|
98
|
+
* answers waits; one that does not asks at once with its current state vector, so a first joiner whose open nobody
|
|
99
|
+
* answered still gets the SyncStep2 that ends its hold.
|
|
100
|
+
*/
|
|
101
|
+
private defersSyncRequest;
|
|
102
|
+
/**
|
|
103
|
+
* Once the join merges, sends the SyncStep1 put off while it was held: the answer carries only what the join missed,
|
|
104
|
+
* not a second, unchunked copy of the joined state.
|
|
105
|
+
*/
|
|
106
|
+
private sendOwedSyncRequest;
|
|
107
|
+
private sendWorkerSyncRequest;
|
|
108
|
+
/**
|
|
109
|
+
* A SyncStep1 sent before the held join merges asks for chunks: its state vector predates the join, so the answer can
|
|
110
|
+
* be as large as the join.
|
|
111
|
+
*/
|
|
112
|
+
private syncRequestVector;
|
|
113
|
+
private sendSyncRequest;
|
|
114
|
+
/**
|
|
115
|
+
* Chunks only when `syncChunkBytes` is set and the SyncStep1 asks for it: that peer holds the chunks and applies them
|
|
116
|
+
* as one change. A peer applying them one at a time, such as another peer in a room, would run its repairs on
|
|
117
|
+
* partial states.
|
|
118
|
+
*/
|
|
119
|
+
private chunksAnswer;
|
|
120
|
+
/** Largest update a chunked sync answer may carry: `syncChunkBytes`, within one frame. */
|
|
121
|
+
private syncChunkLimit;
|
|
122
|
+
/**
|
|
123
|
+
* Sends every update but the last as an Update and the last as the SyncStep2 that completes the answer, encoding one
|
|
124
|
+
* frame at a time once all are known to fit.
|
|
125
|
+
*/
|
|
126
|
+
private sendSyncAnswer;
|
|
127
|
+
/** Holds a pre-sync update for the SyncStep2; past `maxSyncBytes` the connection fails. */
|
|
128
|
+
private holdSyncUpdate;
|
|
129
|
+
/** Ends holding for this connection and returns what was held. */
|
|
130
|
+
private takeSyncHeld;
|
|
131
|
+
private applySyncStep2;
|
|
66
132
|
private applyRemoteUpdate;
|
|
133
|
+
private beginArrival;
|
|
134
|
+
private settleArrival;
|
|
135
|
+
private setAwarenessRecords;
|
|
136
|
+
private applyTypingInference;
|
|
67
137
|
private forwardLocalUpdate;
|
|
68
138
|
private nextAwarenessClock;
|
|
69
139
|
private encodeLocalAwareness;
|
|
@@ -72,6 +142,7 @@ declare class CollaborationProvider {
|
|
|
72
142
|
private clearCursorBroadcastTimer;
|
|
73
143
|
private startPresence;
|
|
74
144
|
private stopPresence;
|
|
145
|
+
private leaveFrame;
|
|
75
146
|
private sendLeaveBestEffort;
|
|
76
147
|
private emitPeers;
|
|
77
148
|
private sendFrame;
|
|
@@ -84,10 +155,39 @@ declare class CollaborationProvider {
|
|
|
84
155
|
|
|
85
156
|
declare function resolvePresenceColor(clientId: number, color: unknown): string;
|
|
86
157
|
|
|
158
|
+
/** One provider's line to the worker that runs it. */
|
|
159
|
+
interface CollaborationPipeEndpoint<C = PipeCursor> {
|
|
160
|
+
/** Runs `ops` in the worker, in order after earlier posts; settles once the worker has run them. */
|
|
161
|
+
post(ops: PipeOp<C>[], transfer: ArrayBuffer[]): Promise<unknown>;
|
|
162
|
+
close(): void;
|
|
163
|
+
}
|
|
164
|
+
/** What a worker replica offers a provider that can run in its worker. */
|
|
165
|
+
interface CollaborationPipeChannel<C = PipeCursor, P = PipePeer> {
|
|
166
|
+
/** `receive` takes the worker's output for this provider; `lost` reports the worker is gone for it. */
|
|
167
|
+
open(receive: (out: readonly PipeOutput<P>[]) => void, lost: (reason: string) => void): CollaborationPipeEndpoint<C>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @experimental A `CollaborationReplica` whose state lives in a worker. `CollaborationProvider` reads it
|
|
172
|
+
* through `async`. The synchronous `encodeStateVector`, `encodeStateAsUpdate` and `encodeStateAsUpdateChunks`
|
|
173
|
+
* throw; use their `async` counterparts, or open the editor with `legacySyncApi` for a synchronous replica.
|
|
174
|
+
* `applyUpdate` and `async`'s apply methods copy the caller's updates, which stay usable.
|
|
175
|
+
*/
|
|
176
|
+
interface AsyncReplicaAdapter extends CollaborationReplica {
|
|
177
|
+
readonly async: AsyncCollaborationReplica;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* @internal Lets a `CollaborationProvider` built on `replica` run its protocol in the worker that hosts the
|
|
181
|
+
* replica, through `channel`; the provider on the calling thread then only moves transport bytes.
|
|
182
|
+
*/
|
|
183
|
+
declare function attachCollaborationPipe(replica: AsyncReplicaAdapter, channel: CollaborationPipeChannel): void;
|
|
184
|
+
/** @experimental Wraps a worker replica so `CollaborationProvider` and `onReplica` accept it unchanged. */
|
|
185
|
+
declare function createAsyncCollaborationReplica(replica: AsyncCollaborationReplica): AsyncReplicaAdapter;
|
|
186
|
+
|
|
87
187
|
interface WorkerCollaborationTarget {
|
|
88
188
|
invalidate(update: Uint8Array, selection: YrsSelection | null): void;
|
|
89
189
|
}
|
|
90
190
|
declare function createDirectCollaborationReplica(session: YrsSession): CollaborationReplica;
|
|
91
191
|
declare function createWorkerCollaborationReplica(session: YrsSession, worker: WorkerCollaborationTarget): CollaborationReplica;
|
|
92
192
|
|
|
93
|
-
export { CollaborationCursor, CollaborationErrorListener, CollaborationPeer, CollaborationPeerListener, CollaborationProvider, CollaborationProviderOptions, CollaborationReplica, CollaborationStatus, CollaborationStatusListener, CollaborationTransport, type WorkerCollaborationTarget, createDirectCollaborationReplica, createWorkerCollaborationReplica, resolvePresenceColor };
|
|
193
|
+
export { AsyncCollaborationReplica, type AsyncReplicaAdapter, CollaborationCursor, CollaborationErrorListener, CollaborationPeer, CollaborationPeerListener, CollaborationProvider, CollaborationProviderOptions, CollaborationReplica, CollaborationStatus, CollaborationStatusListener, CollaborationTransport, type WorkerCollaborationTarget, attachCollaborationPipe, createAsyncCollaborationReplica, createDirectCollaborationReplica, createWorkerCollaborationReplica, resolvePresenceColor };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b as b$1}from'../chunk-TTRUPDAB.mjs';var B=["#0B57D0","#B3261E","#137333","#7B1FA2","#A142F4","#A04B00","#006A6A","#455A64"],oe=/^#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3})?$/;function S(r,e){if(typeof e=="string"&&oe.test(e))return e;let t=Number.isSafeInteger(r)&&r>=0?r%B.length:0;return B[t]}function D(r,e){return r.byteLength===e.byteLength&&r.every((t,n)=>t===e[n])}function ae(r,e){return r===e||!!(r&&e&&r.story===e.story&&D(r.anchor,e.anchor)&&D(r.head,e.head))}function ie(r,e){return r?.clientId===e.clientId&&r.story===e.story&&r.paraId===e.paraId&&r.endOffset===e.endOffset}function V(r){return r?{story:r.story,anchor:r.anchor.slice(),head:r.head.slice()}:null}function ce(r){return r?{user:{...r.user},cursor:V(r.cursor)}:null}function X(r,e,t,n){let s=r,o=false;for(let a of e){if(a.clientId===t)continue;let u=s.get(a.clientId);if(!u&&s.size>=1024)continue;if(u&&a.clock<=u.clock){a.clock===u.clock&&n>u.lastSeenAt&&(s===r&&(s=new Map(r)),s.set(a.clientId,{...u,lastSeenAt:n}));continue}s===r&&(s=new Map(r));let h=a.state?.cursor!=null&&(u?.inferredCursor!=null||u?.state==null||!ae(u.state.cursor,a.state.cursor));s.set(a.clientId,{clientId:a.clientId,clock:a.clock,state:ce(a.state),lastSeenAt:n,cursorMovedAt:h?n:u?.cursorMovedAt??0,inferredCursor:null}),o=true;}return {records:s,peersChanged:o}}function $(r,e,t,n){if(e.clientId===t)return {records:r,peersChanged:false};let s=r.get(e.clientId);if(!s&&r.size>=1024)return {records:r,peersChanged:false};let o=new Map(r);return o.set(e.clientId,{clientId:e.clientId,clock:s?.clock??-1,state:s?.state??null,lastSeenAt:s?.lastSeenAt??n,cursorMovedAt:ie(s?.inferredCursor??null,e)?s?.cursorMovedAt??n:n,inferredCursor:{...e}}),{records:o,peersChanged:s?.state!=null}}function Y(r,e,t){let n=r,s=false;for(let[o,a]of r)e-a.lastSeenAt<t||(n===r&&(n=new Map(r)),n.delete(o),a.state&&(s=true));return {records:n,peersChanged:s}}function I(r){let e=[];for(let t of r.values()){if(!t.state)continue;let n={clientId:t.clientId,clock:t.clock,user:{...t.state.user},cursor:V(t.state.cursor)};e.push({...n,lastSeenAt:t.lastSeenAt,cursorMovedAt:t.cursorMovedAt,inferredCursor:t.inferredCursor?{...t.inferredCursor}:null});}return e.sort((t,n)=>t.clientId-n.clientId),e}var b=16777216,_=4096,q=0,j=1,ue=2,H=3,z=0,K=1,J=2,de=0,pe=Number.MAX_SAFE_INTEGER,c=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},f=class extends c{},U=class{constructor(e){b$1(this,"bytes",e);b$1(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,t=1,n=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new c("Truncated varUint");let s=this.bytes[this.offset++],o=s&127;if(o>Math.floor((pe-e)/t))throw new c("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=o*t,n+=1,(s&128)===0){if(n>1&&o===0)throw new c("Non-canonical varUint");return e}if(n>=8)throw new c("varUint exceeds Number.MAX_SAFE_INTEGER");t*=128;}}readVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new c("Truncated varUint8Array");let n=this.bytes.slice(this.offset,this.offset+e);return this.offset+=e,n}skipVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new c("Truncated varUint8Array");this.offset+=e;}readVarString(){let e=this.readVarUint8Array();try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch(t){throw new c(`Invalid UTF-8 string${t instanceof Error?`: ${t.message}`:""}`)}}};function p(r){if(!Number.isSafeInteger(r)||r<0)throw new c("varUint value must be a non-negative safe integer");let e=[],t=r;for(;t>=128;)e.push(t%128|128),t=Math.floor(t/128);return e.push(t),Uint8Array.from(e)}function g(r,e){let t=0;for(let o of r)if(t+=o.byteLength,t>e)throw new c(`Frame exceeds ${e} bytes`);let n=new Uint8Array(t),s=0;for(let o of r)n.set(o,s),s+=o.byteLength;return n}function he(r){let e=new TextEncoder().encode(r);return g([p(e.byteLength),e],Number.MAX_SAFE_INTEGER)}function P(r,e,t){return g([p(q),p(r),p(e.byteLength),e],t)}function Q(r,e=b){return P(z,r,e)}function Z(r,e=b){return P(K,r,e)}function ee(r,e=b){return P(J,r,e)}function ye(r){return r.state===null?"null":JSON.stringify({user:r.state.user,cursor:r.state.cursor?{story:r.state.cursor.story,anchor:[...r.state.cursor.anchor],head:[...r.state.cursor.head]}:null})}function fe(r){let e=[p(r.length)];for(let t of r)e.push(p(t.clientId),p(t.clock),he(ye(t)));return g(e,Number.MAX_SAFE_INTEGER)}function R(r,e=b){let t=fe(r);return g([p(j),p(t.byteLength),t],e)}function L(r=b){return g([p(H)],r)}function G(r,e){if(!Array.isArray(r))throw new c(`${e} must be a byte array`);if(r.length>1024)throw new f(`${e} exceeds ${1024} bytes`);if(r.some(t=>!Number.isInteger(t)||t<0||t>255))throw new c(`${e} must be a byte array`);return Uint8Array.from(r)}function be(r,e){let t;try{t=JSON.parse(r);}catch{throw new c("Invalid awareness JSON")}if(t===null)return null;if(typeof t!="object"||Array.isArray(t))throw new c("Awareness state must be an object or null");let n=t,s=n.user;if(typeof s!="object"||s===null||Array.isArray(s))throw new c("Awareness user must be an object");let o=s;if(typeof o.name!="string")throw new c("Awareness user requires a string name");if(o.name.length>1024)throw new f(`Awareness user name exceeds ${1024} characters`);let a={name:o.name,color:S(e,o.color)},u=n.cursor;if(u==null)return {user:a,cursor:null};if(typeof u!="object"||Array.isArray(u))throw new c("Awareness cursor must be an object or null");let h=u;if(typeof h.story!="string")throw new c("Awareness cursor requires a string story");if(h.story.length>1024)throw new f(`Awareness cursor story exceeds ${1024} characters`);return {user:a,cursor:{story:h.story,anchor:G(h.anchor,"Awareness cursor anchor"),head:G(h.head,"Awareness cursor head")}}}function te(r,e={}){let t=new U(r),n=t.readVarUint();if(n>r.byteLength)throw new c("Invalid awareness entry count");let s=new Set(e.trackedClientIds);e.localClientId!==void 0&&s.delete(e.localClientId);let o=new Set,a=m=>{o.has(m.message)||(o.add(m.message),e.onDiscard?.(m));};n>1024&&a(new f(`Awareness update exceeds ${1024} entries`));let u=[],h=Math.min(n,1024);for(let m=0;m<h;m+=1){let A=t.readVarUint(),ne=t.readVarUint();if(!(A===e.localClientId||s.has(A))&&s.size>=1024){t.skipVarUint8Array(),a(new f(`Awareness peer limit of ${1024} reached`));continue}let se=t.readVarString(),O;try{O=be(se,A);}catch(x){if(!(x instanceof f))throw x;a(x);continue}u.push({clientId:A,clock:ne,state:O}),A!==e.localClientId&&s.add(A);}if(n<=1024&&!t.done)throw new c("Trailing awareness data");return u}function re(r,e=b,t=_){if(!(r instanceof Uint8Array))throw new c("Frame must be a Uint8Array");if(r.byteLength===0)throw new c("Frame is empty");if(r.byteLength>e)throw new c(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(t)||t<1)throw new c("Message limit must be a positive integer");let n=new U(r),s=[];for(;!n.done;){if(s.length>=t)throw new c(`Frame exceeds ${t} messages`);let o=n.readVarUint();switch(o){case q:{let a=n.readVarUint(),u=n.readVarUint8Array();if(a===z)s.push({type:"sync-step-1",stateVector:u});else if(a===K)s.push({type:"sync-step-2",update:u});else if(a===J)s.push({type:"update",update:u});else throw new c(`Unknown sync message type ${a}`);break}case j:s.push({type:"awareness",update:n.readVarUint8Array()});break;case ue:{let a=n.readVarUint();if(a!==de)throw new c(`Unknown auth message type ${a}`);s.push({type:"auth",reason:n.readVarString()});break}case H:s.push({type:"query-awareness"});break;default:throw new c(`Unknown top-level message type ${o}`)}}return s}var d=class extends Error{constructor(t,n,s){super(n);b$1(this,"code");b$1(this,"cause");this.name="CollaborationError",this.code=t,this.cause=s;}};var me=16*1024*1024,Ae=80,Ce=2e4,we=45e3,Ee=5e3;function F(r,e,t){if(!Number.isSafeInteger(e)||e<(t?0:1))throw new RangeError(`${r} must be ${t?"a non-negative":"a positive"} integer`);return e}function Se(r){return r instanceof Error&&r.message?r.message:typeof r=="string"&&r?r:"Unknown error"}function l(r,e,t){return t instanceof d?t:new d(r,`${e}: ${Se(t)}`,t)}function M(r,e){if(!(r instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return r.slice()}function v(){return globalThis.performance?.now?.()??Date.now()}function k(r){r.unref?.();}function ge(r,e){if(!r)return null;if(!Number.isSafeInteger(e)||e<0)throw new RangeError("clientId must be a non-negative safe integer for awareness");if(typeof r.name!="string"||r.name.trim().length===0)throw new TypeError("user.name must be a non-empty string");return {name:r.name.trim().slice(0,1024),color:S(e,r.color)}}function ve(r){if(r===null)return null;if(typeof r.story!="string"||!r.story||!(r.anchor instanceof Uint8Array)||!(r.head instanceof Uint8Array))throw new TypeError("cursor requires a story and Uint8Array anchor/head");return {story:r.story,anchor:r.anchor.slice(),head:r.head.slice()}}function Te(r){return r.story.length<=1024&&r.anchor.byteLength<=1024&&r.head.byteLength<=1024}function Ue(r){if(typeof r!="object"||r===null)return null;let e=r;return !Number.isSafeInteger(e.clientId)||(e.clientId??-1)<0||typeof e.story!="string"||typeof e.paraId!="string"||!Number.isSafeInteger(e.endOffset)||(e.endOffset??-1)<0?null:{clientId:e.clientId,story:e.story,paraId:e.paraId,endOffset:e.endOffset}}var N=class{constructor(e,t,n={}){b$1(this,"replica");b$1(this,"transport");b$1(this,"maxFrameBytes");b$1(this,"maxMessagesPerFrame");b$1(this,"maxPendingBytes");b$1(this,"localUser");b$1(this,"statusListeners",new Map);b$1(this,"errorListeners",new Map);b$1(this,"peerListeners",new Map);b$1(this,"pendingFrames",[]);b$1(this,"awarenessRecords",new Map);b$1(this,"unsubscribeReplica");b$1(this,"unsubscribeTransport",()=>{});b$1(this,"hasTransportSubscription",false);b$1(this,"connectionStatus","disconnected");b$1(this,"isSynced",false);b$1(this,"wantsConnection",false);b$1(this,"isOpen",false);b$1(this,"isDestroyed",false);b$1(this,"epoch",0);b$1(this,"connectAttempt",0);b$1(this,"nextListenerId",0);b$1(this,"queuedBytes",0);b$1(this,"isFlushing",false);b$1(this,"localClock",0);b$1(this,"reportedClockExhaustion",false);b$1(this,"localCursor",null);b$1(this,"lastAwarenessSentAt",Number.NEGATIVE_INFINITY);b$1(this,"cursorBroadcastTimer",null);b$1(this,"heartbeatTimer",null);b$1(this,"expiryTimer",null);this.replica=e,this.transport=t,this.maxFrameBytes=F("maxFrameBytes",n.maxFrameBytes??b,false),this.maxMessagesPerFrame=F("maxMessagesPerFrame",n.maxMessagesPerFrame??_,false),this.maxPendingBytes=F("maxPendingBytes",n.maxPendingBytes??me,true),this.localUser=ge(n.user,e.clientId);try{this.unsubscribeReplica=e.onUpdate((s,o)=>{o==="local"&&this.forwardLocalUpdate(s);});}catch(s){throw l("replica","Failed to observe replica updates",s)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}get peers(){return I(this.awarenessRecords)}setCursor(e,t=true){if(this.isDestroyed||!this.localUser)return;let n=ve(e);if(this.localCursor=!n||Te(n)?n:null,n&&!this.localCursor&&this.report(new d("protocol",`Presence cursor exceeds ${1024} story characters or ${1024} position bytes; cursor dropped`)),!t){this.clearCursorBroadcastTimer();return}this.scheduleCursorBroadcast();}onPeers(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("peer listener must be a function");let t=this.nextListenerId++;return this.peerListeners.set(t,e),e(this.peers),()=>this.peerListeners.delete(t)}connect(){if(this.isDestroyed||this.isOpen||this.connectionStatus==="connecting")return;this.wantsConnection=true;let e=this.hasTransportSubscription?this.epoch:++this.epoch,t=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(e)){if(!this.hasTransportSubscription){let n;try{if(n=this.transport.onEvent(s=>this.handleTransportEvent(e,s)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(s){this.failConnection(e,l("transport","Failed to subscribe to transport events",s));return}if(!this.isCurrent(e)){try{n();}catch(s){this.isDestroyed||this.report(l("transport","Failed to unsubscribe from stale transport events",s));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(s=>{this.isCurrent(e)&&this.connectAttempt===t&&this.failConnection(e,l("transport","Transport connect failed",s));});}catch(n){this.failConnection(e,l("transport","Transport connect failed",n));}}}disconnect(){if(this.isDestroyed||!(this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus!=="disconnected"))return;this.sendLeaveBestEffort(),this.stopPresence(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(t,true);this.setStatus("disconnected",false);for(let s of n)this.report(s);}destroy(){if(this.isDestroyed)return;let e=this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus==="connecting"||this.connectionStatus==="connected";this.sendLeaveBestEffort(),this.stopPresence(),this.isDestroyed=true,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(t,e);this.setStatus("destroyed",false);for(let s of n)this.report(s);try{this.unsubscribeReplica();}catch(s){this.report(l("replica","Failed to unsubscribe from replica updates",s));}this.unsubscribeReplica=()=>{},this.statusListeners.clear(),this.errorListeners.clear(),this.peerListeners.clear();}onStatus(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("status listener must be a function");let t=this.nextListenerId++;return this.statusListeners.set(t,e),()=>this.statusListeners.delete(t)}onError(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("error listener must be a function");let t=this.nextListenerId++;return this.errorListeners.set(t,e),()=>this.errorListeners.delete(t)}isCurrent(e){return !this.isDestroyed&&this.wantsConnection&&e===this.epoch}failConnection(e,t){if(!this.isCurrent(e))return;this.stopPresence(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let n=this.takeTransportSubscription();this.clearPending();let s=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(t);for(let o of s)this.report(o);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,t){let n=[];try{e();}catch(s){n.push(l("transport","Failed to unsubscribe from transport events",s));}if(!t)return n;try{let s=this.transport.disconnect();s&&s.catch(o=>{this.isDestroyed||this.report(l("transport","Transport disconnect failed",o));});}catch(s){n.push(l("transport","Transport disconnect failed",s));}return n}handleTransportEvent(e,t){if(this.isCurrent(e))switch(t.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(e,t.data);break;case "close":this.isOpen=false,this.connectAttempt+=1,this.stopPresence(),this.clearPending(),this.setStatus("disconnected",false);break;case "error":this.failConnection(e,l("transport","Transport error",t.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new d("transport","Unknown transport event"));}}handleOpen(e){if(this.isOpen||(this.isOpen=true,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(e)||!this.isOpen))return;let t;try{t=M(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,l("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(Q(t,this.maxFrameBytes));}catch(n){this.failConnection(e,l("protocol","Failed to encode collaboration handshake",n));return}if(!(!this.localUser||!this.isCurrent(e)||!this.isOpen)){try{this.sendFrame(L(this.maxFrameBytes));}catch(n){this.report(l("protocol","Failed to encode awareness query",n));}!this.isCurrent(e)||!this.isOpen||(this.broadcastLocalAwareness(),!(!this.isCurrent(e)||!this.isOpen)&&this.startPresence());}}handleMessage(e,t){let n;try{n=re(t.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(s){this.failConnection(e,l("protocol","Invalid collaboration frame",s));return}for(let s of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(s.type){case "sync-step-1":this.respondToSyncStep1(e,s.stateVector);break;case "sync-step-2":if(this.applyRemoteUpdate(e,s.update,false)&&this.isCurrent(e)&&(this.setStatus("connected",true),this.localUser))try{this.sendFrame(L(this.maxFrameBytes));}catch(o){this.report(l("protocol","Failed to query awareness after sync",o));}break;case "update":this.applyRemoteUpdate(e,s.update,true);break;case "awareness":{let o=[];try{let a=X(this.awarenessRecords,te(s.update,{trackedClientIds:this.awarenessRecords.keys(),localClientId:this.replica.clientId,onDiscard:u=>o.push(u)}),this.replica.clientId,v());this.awarenessRecords=a.records,a.peersChanged&&this.emitPeers();}catch(a){this.report(l("protocol","Failed to apply awareness update",a));}for(let a of o)this.report(l("protocol","Discarded over-limit awareness data",a));break}case "auth":this.failConnection(e,new d("protocol",s.reason?`Authentication denied: ${s.reason}`:"Authentication denied"));return;case "query-awareness":try{this.localUser?this.broadcastLocalAwareness():this.sendFrame(R([],this.maxFrameBytes));}catch(o){this.report(l("protocol","Failed to encode awareness response",o));}break}}}respondToSyncStep1(e,t){let n;try{n=M(this.replica.encodeStateAsUpdate(t.slice()),"encodeStateAsUpdate");}catch(s){this.failConnection(e,l("replica","Failed to encode replica update",s));return}try{this.sendFrame(Z(n,this.maxFrameBytes));}catch(s){this.failConnection(e,l("protocol","Failed to encode SyncStep2",s));}}applyRemoteUpdate(e,t,n){try{let s=this.replica.applyUpdate(t.slice()),o=n?Ue(s):null;if(o){let a=$(this.awarenessRecords,o,this.replica.clientId,v());this.awarenessRecords=a.records,a.peersChanged&&this.emitPeers();}return !0}catch(s){return this.failConnection(e,l("replica","Failed to apply remote update",s)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let t=this.epoch,n;try{n=M(e,"Replica update");}catch(s){this.failConnection(t,l("replica","Invalid replica update",s));return}try{this.sendFrame(ee(n,this.maxFrameBytes));}catch(s){this.failConnection(t,l("protocol","Failed to encode update",s));}}nextAwarenessClock(){if(this.localClock>=Number.MAX_SAFE_INTEGER)throw new RangeError("Awareness clock exceeds Number.MAX_SAFE_INTEGER");return this.localClock+=1,this.localClock}encodeLocalAwareness(e,t,n){return R([{clientId:this.replica.clientId,clock:t,state:{user:e,cursor:n}}],this.maxFrameBytes)}broadcastLocalAwareness(){if(!this.localUser||!this.isOpen||this.isDestroyed||!this.wantsConnection)return;if(this.clearCursorBroadcastTimer(),this.localClock>=Number.MAX_SAFE_INTEGER){this.reportedClockExhaustion||(this.reportedClockExhaustion=true,this.report(new d("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}let e=this.localUser,t=this.nextAwarenessClock(),n;try{n=this.encodeLocalAwareness(e,t,this.localCursor);}catch(s){let o=this.localCursor;if(this.localCursor=null,!o){this.report(l("protocol","Failed to encode local awareness",s));return}try{n=this.encodeLocalAwareness(e,t,null);}catch(a){this.report(l("protocol","Failed to encode local awareness",a));return}this.report(l("protocol","Dropped an unencodable presence cursor",s));}this.sendFrame(n),this.lastAwarenessSentAt=v();}scheduleCursorBroadcast(){if(!this.localUser||!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let e=Ae-(v()-this.lastAwarenessSentAt);if(e<=0){this.broadcastLocalAwareness();return}this.cursorBroadcastTimer||(this.cursorBroadcastTimer=setTimeout(()=>{this.cursorBroadcastTimer=null,!(!this.isOpen||this.isDestroyed||!this.wantsConnection)&&this.broadcastLocalAwareness();},e),k(this.cursorBroadcastTimer));}clearCursorBroadcastTimer(){this.cursorBroadcastTimer&&clearTimeout(this.cursorBroadcastTimer),this.cursorBroadcastTimer=null;}startPresence(){!this.localUser||!this.isOpen||this.isDestroyed||!this.wantsConnection||this.heartbeatTimer||this.expiryTimer||(this.heartbeatTimer=setInterval(()=>{this.broadcastLocalAwareness();},Ce),this.expiryTimer=setInterval(()=>{let e=Y(this.awarenessRecords,v(),we);this.awarenessRecords=e.records,e.peersChanged&&this.emitPeers();},Ee),k(this.heartbeatTimer),k(this.expiryTimer));}stopPresence(){this.clearCursorBroadcastTimer(),this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.expiryTimer&&clearInterval(this.expiryTimer),this.heartbeatTimer=null,this.expiryTimer=null;let e=I(this.awarenessRecords).length>0;this.awarenessRecords=new Map,e&&this.emitPeers();}sendLeaveBestEffort(){if(!(!this.localUser||!this.isOpen||this.isDestroyed||!this.wantsConnection)){this.clearCursorBroadcastTimer();try{let e=R([{clientId:this.replica.clientId,clock:this.nextAwarenessClock(),state:null}],this.maxFrameBytes);this.transport.send(e.slice());}catch(e){this.report(l("transport","Failed to send awareness leave",e));}}}emitPeers(){let e=this.peers;for(let[t,n]of [...this.peerListeners])if(this.peerListeners.get(t)===n)try{n(e);}catch{}}sendFrame(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let t=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(t,e);return}let n;try{n=this.transport.send(e.slice());}catch(s){this.failConnection(t,l("transport","Transport send failed",s));return}if(typeof n!="boolean"){this.failConnection(t,new d("transport","Transport send must return a boolean"));return}!n&&this.isCurrent(t)&&this.isOpen&&this.queueFrame(t,e);}queueFrame(e,t){if(t.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new d("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let n=t.slice();this.pendingFrames.push(n),this.queuedBytes+=n.byteLength;}flushPending(){if(!this.isFlushing){this.isFlushing=true;try{for(;this.isOpen&&!this.isDestroyed&&this.pendingFrames.length>0;){let e=this.epoch,t=this.pendingFrames[0],n;try{n=this.transport.send(t.slice());}catch(s){this.failConnection(e,l("transport","Transport send failed",s));return}if(typeof n!="boolean"){this.failConnection(e,new d("transport","Transport send must return a boolean"));return}if(!n||!this.isOpen||this.pendingFrames[0]!==t)return;this.pendingFrames.shift(),this.queuedBytes-=t.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(e,t){if(this.connectionStatus===e&&this.isSynced===t)return;this.connectionStatus=e,this.isSynced=t;let n={status:e,synced:t};for(let[s,o]of [...this.statusListeners])if(this.statusListeners.get(s)===o)try{o(n);}catch{}}report(e){for(let[t,n]of [...this.errorListeners])if(this.errorListeners.get(t)===n)try{n(e);}catch{}}};function Re(r){return r}function xe(r,e){return {clientId:r.clientId,encodeStateVector:()=>r.encodeStateVector(),encodeStateAsUpdate:t=>r.encodeStateAsUpdate(t?.slice()),applyUpdate:t=>{let n=t.slice();r.applyUpdate(n),e.invalidate(n,r.selection());},onUpdate:t=>r.onUpdate(t)}}export{d as CollaborationError,N as CollaborationProvider,Re as createDirectCollaborationReplica,xe as createWorkerCollaborationReplica,S as resolvePresenceColor};
|
|
1
|
+
export{a as CollaborationError,f as CollaborationProvider,b as attachCollaborationPipe,c as createAsyncCollaborationReplica}from'../chunk-M44BABH2.mjs';export{a as resolvePresenceColor}from'../chunk-VHOOSS4D.mjs';import'../chunk-LPOEM5WH.mjs';import'../chunk-TTRUPDAB.mjs';function b(o){return o}function y(o,r){return {clientId:o.clientId,encodeStateVector:()=>o.encodeStateVector(),encodeStateAsUpdate:e=>o.encodeStateAsUpdate(e?.slice()),encodeStateAsUpdateChunks:(e,t)=>o.encodeStateAsUpdateChunks(e.slice(),t),applyUpdate:e=>{let t=e.slice();o.applyUpdate(t),r.invalidate(t,o.selection());},onUpdate:e=>o.onUpdate(e)}}export{b as createDirectCollaborationReplica,y as createWorkerCollaborationReplica};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ColorValue,
|
|
1
|
+
import { C as ColorValue, A as ThemeColorSlot, P as ParagraphFormatting, T as TextFormatting, c as TableFormatting, d as TableRowFormatting, e as TableCellFormatting, B as BorderSpec, o as ShapeType, m as ShapeFill, n as ShapeOutline, H as ShapeTextBody$1, b as PresetGeometryPathCommand } from './formatting-p5MneNuy.mjs';
|
|
2
2
|
import { WrapType } from './docx/wrapTypes.mjs';
|
|
3
3
|
|
|
4
4
|
interface ShapeFillPaint {
|
|
@@ -340,6 +340,10 @@ interface TableCell {
|
|
|
340
340
|
*/
|
|
341
341
|
interface TableRow {
|
|
342
342
|
type: 'tableRow';
|
|
343
|
+
extraAttributes?: {
|
|
344
|
+
name: string;
|
|
345
|
+
value: string;
|
|
346
|
+
}[];
|
|
343
347
|
/** Row formatting */
|
|
344
348
|
formatting?: TableRowFormatting;
|
|
345
349
|
/** Row-level tracked property changes (w:trPrChange) */
|
|
@@ -1606,10 +1610,23 @@ interface ChartContent {
|
|
|
1606
1610
|
/** Parsed chart data */
|
|
1607
1611
|
chart: Chart;
|
|
1608
1612
|
}
|
|
1613
|
+
/**
|
|
1614
|
+
* A drawing the parser does not model, replayed verbatim on save.
|
|
1615
|
+
*/
|
|
1616
|
+
interface OpaqueDrawingContent {
|
|
1617
|
+
type: 'opaqueDrawing';
|
|
1618
|
+
/** Authored element kind (`drawing`, `pict`, `object`, `alternateContent`). */
|
|
1619
|
+
kind: string;
|
|
1620
|
+
/** Original markup, written back verbatim at the run position. */
|
|
1621
|
+
xml: string;
|
|
1622
|
+
preview?: Image;
|
|
1623
|
+
previews?: Image[];
|
|
1624
|
+
textBox?: Shape;
|
|
1625
|
+
}
|
|
1609
1626
|
/**
|
|
1610
1627
|
* All possible run content types
|
|
1611
1628
|
*/
|
|
1612
|
-
type RunContent = TextContent | TabContent | BreakContent | SymbolContent | NoteReferenceContent | NoteRefMarkContent | SeparatorContent | HorizontalRuleContent | CommentReferenceContent | FieldCharContent | InstrTextContent | SoftHyphenContent | NoBreakHyphenContent | DrawingContent | ShapeContent | ChartContent;
|
|
1629
|
+
type RunContent = TextContent | TabContent | BreakContent | SymbolContent | NoteReferenceContent | NoteRefMarkContent | SeparatorContent | HorizontalRuleContent | CommentReferenceContent | FieldCharContent | InstrTextContent | SoftHyphenContent | NoBreakHyphenContent | DrawingContent | ShapeContent | ChartContent | OpaqueDrawingContent;
|
|
1613
1630
|
/**
|
|
1614
1631
|
* A run (`w:r`) — a contiguous span of inline content sharing one set of
|
|
1615
1632
|
* character properties (bold, italic, font, color, etc.). Runs are the
|
|
@@ -1990,6 +2007,10 @@ interface Image {
|
|
|
1990
2007
|
opacity?: number;
|
|
1991
2008
|
/** Whether this is a decorative image */
|
|
1992
2009
|
decorative?: boolean;
|
|
2010
|
+
/** Whether the picture's aspect ratio is locked. */
|
|
2011
|
+
noChangeAspect?: boolean;
|
|
2012
|
+
/** VML `o:hr`: Word lays the picture's line at the picture's own height. */
|
|
2013
|
+
horizontalRule?: boolean;
|
|
1993
2014
|
/**
|
|
1994
2015
|
* `wp:anchor layoutInCell` — when true (default), an anchored image inside
|
|
1995
2016
|
* a table cell is constrained to the cell. When false, the image escapes
|
|
@@ -2208,4 +2229,4 @@ interface Chart {
|
|
|
2208
2229
|
drawingXml?: string;
|
|
2209
2230
|
}
|
|
2210
2231
|
|
|
2211
|
-
export { type FieldInlineContent as $, type AbstractNumbering as A, type BlockContent as B, type CellMarker as C, type DrawingScene as D, type EndnoteProperties as E, type FootnoteProperties as F, type CommentAnchorRange as G, type HeaderFooter as H, type CommentAuthor as I, type CommentRangeEnd as J, type CommentRangeStart as K, type CommentReferenceContent as L, type ComplexField as M, type NoteKind as N, type ContentPosition as O, type Paragraph as P, DEFAULT_WATERMARK_PRESETS as Q, type RevisionInfo as R, type SdtControlState as S, type Deletion as T, type DrawingContent as U, type DrawingSceneNode as V, type Watermark as W, type EndnotePosition as X, type Field as Y, type FieldCharContent as Z, type FieldFormData as _, type SdtProperties as a, type
|
|
2232
|
+
export { type FieldInlineContent as $, type AbstractNumbering as A, type BlockContent as B, type CellMarker as C, type DrawingScene as D, type EndnoteProperties as E, type FootnoteProperties as F, type CommentAnchorRange as G, type HeaderFooter as H, type CommentAuthor as I, type CommentRangeEnd as J, type CommentRangeStart as K, type CommentReferenceContent as L, type ComplexField as M, type NoteKind as N, type ContentPosition as O, type Paragraph as P, DEFAULT_WATERMARK_PRESETS as Q, type RevisionInfo as R, type SdtControlState as S, type Deletion as T, type DrawingContent as U, type DrawingSceneNode as V, type Watermark as W, type EndnotePosition as X, type Field as Y, type FieldCharContent as Z, type FieldFormData as _, type SdtProperties as a, type SimpleField as a$, type FieldType as a0, type FooterReference as a1, type FootnotePosition as a2, type HeaderFooterType as a3, type HeaderReference as a4, type HorizontalRuleContent as a5, type Hyperlink as a6, type HyperlinkContent as a7, type Image as a8, type ImageCrop as a9, type NoteReferenceContent as aA, type NoteSeparatorReference as aB, type NumberFormat as aC, type NumberingInstance as aD, type OpaqueDrawingContent as aE, type PageNumberingProperties as aF, type PageOrientation as aG, type ParagraphContent as aH, type ParagraphPropertyChange as aI, type PictureWatermark as aJ, type PropertyChangeInfo as aK, type Run as aL, type RunContent as aM, type RunPropertyChange as aN, type SdtCheckboxGlyph as aO, type SdtDataBinding as aP, type SdtDateState as aQ, type SdtGalleryState as aR, type SdtType as aS, type Section as aT, type SectionStart as aU, type SeparatorContent as aV, type Shape as aW, type ShapeContent as aX, type ShapeFillPaint as aY, type ShapeStrokePaint as aZ, type ShapeTextBody as a_, type ImageEffect as aa, type ImageHyperlink as ab, type ImagePadding as ac, type ImagePosition as ad, type ImageRotationBounds as ae, type ImageSize as af, type ImageTransform as ag, type ImageWrap as ah, type ImageWrapPoint as ai, type InlineSdt as aj, type Insertion as ak, type InstrTextContent as al, type LevelSuffix as am, type LineNumberRestart as an, type ListLevel as ao, type ListRendering as ap, type MathEquation as aq, type MoveFrom as ar, type MoveFromRangeEnd as as, type MoveFromRangeStart as at, type MoveTo as au, type MoveToRangeEnd as av, type MoveToRangeStart as aw, type NoBreakHyphenContent as ax, type NoteNumberRestart as ay, type NoteRefMarkContent as az, type ShapeEffect as b, type SoftHyphenContent as b0, type StructuredFieldContent as b1, type StructuredFieldTree as b2, type SymbolContent as b3, type TabContent as b4, type Table as b5, type TableCell as b6, type TableCellPropertyChange as b7, type TablePropertyChange as b8, type TableRow as b9, type TableRowPropertyChange as ba, type TableStructuralChangeInfo as bb, type TextBox as bc, type TextContent as bd, type TextWatermark as be, type TrackedChangeInfo as bf, type TrackedRunChange as bg, type VerticalAlign as bh, pictureWatermarkDisplayEmu as bi, type RawXml as bj, type ShapeTextBodyProperties as c, type Chart as d, type Comment as e, type SectionProperties as f, type DocumentBody as g, type NumberingDefinitions as h, type Footnote as i, type Endnote as j, type BookmarkRange as k, type BlockSdt as l, type BookmarkEnd as m, type BookmarkStart as n, type BreakContent as o, type ChartAxis as p, type ChartContent as q, type ChartDataLabels as r, type ChartGrouping as s, type ChartLegend as t, type ChartPlotGroup as u, type ChartPoint as v, type ChartPointLabel as w, type ChartSeries as x, type ChartType as y, type Column as z };
|
package/dist/core.d.mts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
export { a as attemptSelectiveSave, p as parseDocx } from './selectiveSave-r-NMK6aI.mjs';
|
|
2
2
|
import { Document } from './types/document.mjs';
|
|
3
3
|
export { DocxPackage } from './types/document.mjs';
|
|
4
|
-
import { g as DocumentBody, f as SectionProperties,
|
|
5
|
-
export { B as BlockContent, m as BookmarkEnd, n as BookmarkStart, e as Comment, J as CommentRangeEnd, K as CommentRangeStart, T as Deletion, j as Endnote, Y as Field, a1 as FooterReference, i as Footnote, H as HeaderFooter, a4 as HeaderReference, a6 as Hyperlink, a8 as Image, ak as Insertion, ao as ListLevel, ar as MoveFrom, au as MoveTo, h as NumberingDefinitions, P as Paragraph,
|
|
6
|
-
export { c as createDocx, r as repackDocx, u as updateMultipleFiles } from './rezip-
|
|
7
|
-
import { D as DocxExportFailure, a as DocxExportOptions, b as DocxMarkdownContent, c as DocxStructuredContent, d as DocxPageExportOptions, e as DocxHeadlessLayoutOptions, f as DocxPagedStructuredContent, g as DocxSnapshotLayoutMap, h as DocxMarkdownOptions, i as DocxLayoutMap, j as DocxPageMarkdownOptions, k as DocxContentControlReadFailure, l as DocxContentControlQuery, m as DocxContentControlsOptions, n as DocxContentControlsSnapshot } from './pagedExport-
|
|
8
|
-
export { o as DocxAnchor, p as DocxAnchorScope, q as DocxCachedResult, r as DocxCommentMetadata, s as DocxContentControl, t as DocxContentControlDiagnostic, u as DocxContentControlSelector, v as DocxContentControlValue, w as DocxContentControlsResult, x as DocxControlMetadata, y as DocxExportBlock, z as DocxExportCell, A as DocxExportDiagnostic, B as DocxExportDiagnosticCode, C as DocxExportFailureCode, E as DocxExportInline, F as DocxExportPage, G as DocxExportRefusal, H as DocxExportResult, I as DocxExportStory, J as DocxExportTable, K as DocxFormattingMark, L as DocxFragmentGeometry, M as DocxHeadingInfo, N as DocxHeadlessFont, O as DocxInlineRevision, P as DocxLayoutProvenance, Q as DocxListInfo, R as DocxPageDiagnostic, S as DocxPageFragment, T as DocxPageMapContent, U as DocxParagraphData, V as DocxParagraphHeading, W as DocxRevisionView, X as DocxSnapshotLayoutProvenance, Y as DocxStoryKind, Z as DocxStoryOccurrence, _ as DocxStorySelection, $ as DocxUnlocatedReason } from './pagedExport-
|
|
4
|
+
import { g as DocumentBody, f as SectionProperties, b5 as Table } from './content-DVT06V_6.mjs';
|
|
5
|
+
export { B as BlockContent, m as BookmarkEnd, n as BookmarkStart, e as Comment, J as CommentRangeEnd, K as CommentRangeStart, T as Deletion, j as Endnote, Y as Field, a1 as FooterReference, i as Footnote, H as HeaderFooter, a4 as HeaderReference, a6 as Hyperlink, a8 as Image, ak as Insertion, ao as ListLevel, ar as MoveFrom, au as MoveTo, h as NumberingDefinitions, P as Paragraph, aH as ParagraphContent, aL as Run, aM as RunContent, aW as Shape, b6 as TableCell, b9 as TableRow, bc as TextBox, bd as TextContent, bf as TrackedChangeInfo, bg as TrackedRunChange } from './content-DVT06V_6.mjs';
|
|
6
|
+
export { R as RepackResult, c as createDocx, r as repackDocx, a as repackDocxWithWarnings, u as updateMultipleFiles } from './rezip-CfwAYdV4.mjs';
|
|
7
|
+
import { D as DocxExportFailure, a as DocxExportOptions, b as DocxMarkdownContent, c as DocxStructuredContent, d as DocxPageExportOptions, e as DocxHeadlessLayoutOptions, f as DocxPagedStructuredContent, g as DocxSnapshotLayoutMap, h as DocxMarkdownOptions, i as DocxLayoutMap, j as DocxPageMarkdownOptions, k as DocxContentControlReadFailure, l as DocxContentControlQuery, m as DocxContentControlsOptions, n as DocxContentControlsSnapshot } from './pagedExport-DDgA5O7E.mjs';
|
|
8
|
+
export { o as DocxAnchor, p as DocxAnchorScope, q as DocxCachedResult, r as DocxCommentMetadata, s as DocxContentControl, t as DocxContentControlDiagnostic, u as DocxContentControlSelector, v as DocxContentControlValue, w as DocxContentControlsResult, x as DocxControlMetadata, y as DocxExportBlock, z as DocxExportCell, A as DocxExportDiagnostic, B as DocxExportDiagnosticCode, C as DocxExportFailureCode, E as DocxExportInline, F as DocxExportPage, G as DocxExportRefusal, H as DocxExportResult, I as DocxExportStory, J as DocxExportTable, K as DocxFormattingMark, L as DocxFragmentGeometry, M as DocxHeadingInfo, N as DocxHeadlessFont, O as DocxInlineRevision, P as DocxLayoutProvenance, Q as DocxListInfo, R as DocxPageDiagnostic, S as DocxPageFragment, T as DocxPageMapContent, U as DocxParagraphData, V as DocxParagraphHeading, W as DocxRevisionView, X as DocxSnapshotLayoutProvenance, Y as DocxStoryKind, Z as DocxStoryOccurrence, _ as DocxStorySelection, $ as DocxUnlocatedReason } from './pagedExport-DDgA5O7E.mjs';
|
|
9
9
|
export { emuToPixels, emuToTwips, formatPx, halfPointsToPixels, pixelsToEmu, pixelsToTwips, pointsToPixels, twipsToEmu, twipsToPixels } from './utils/units.mjs';
|
|
10
|
-
export { T as ThemeMatrixCell, b as blendColors, c as canRenderFont, a as colorsEqual, d as createRgbColor, e as createThemeColor, f as darkenColor, g as ensureHexPrefix, h as generateThemeTintShadeMatrix, i as getContrastingColor, j as getLoadedFonts, k as getThemeTintShadeHex, l as isBlack, m as isFontLoaded, n as isFontsLoading, o as isGoogleFontsEnabled, p as isWhite, q as lightenColor, r as loadFont, s as loadFontFromBuffer, t as loadFonts, u as onFontsLoaded, v as parseColorString, w as preloadCommonFonts, x as resolveColor, y as resolveHighlightColor, z as resolveHighlightToCss, A as resolveShadingColor, B as setGoogleFontsEnabled } from './fontLoader-
|
|
10
|
+
export { T as ThemeMatrixCell, b as blendColors, c as canRenderFont, a as colorsEqual, d as createRgbColor, e as createThemeColor, f as darkenColor, g as ensureHexPrefix, h as generateThemeTintShadeMatrix, i as getContrastingColor, j as getLoadedFonts, k as getThemeTintShadeHex, l as isBlack, m as isFontLoaded, n as isFontsLoading, o as isGoogleFontsEnabled, p as isWhite, q as lightenColor, r as loadFont, s as loadFontFromBuffer, t as loadFonts, u as onFontsLoaded, v as parseColorString, w as preloadCommonFonts, x as resolveColor, y as resolveHighlightColor, z as resolveHighlightToCss, A as resolveShadingColor, B as setGoogleFontsEnabled } from './fontLoader-CBkmh4ps.mjs';
|
|
11
11
|
export { D as DocxInput, t as toArrayBuffer } from './docxInput-DTbCa48g.mjs';
|
|
12
12
|
export { EditorPluginCore, PanelConfig, PluginPanelProps, PointPosition, PositionCoordinates, RenderedDomContext } from './plugin-api/index.mjs';
|
|
13
|
-
export { B as BlockExtent, F as FootnoteContent, L as Layout, b as LayoutBlock, P as Page, R as ResolvedLine, c as ResolvedSegment } from './types-
|
|
14
|
-
export {
|
|
15
|
-
export { d as Relationship, a as Style, S as StyleDefinitions } from './styles-
|
|
13
|
+
export { B as BlockExtent, F as FootnoteContent, L as Layout, b as LayoutBlock, P as Page, R as ResolvedLine, c as ResolvedSegment } from './types-bvPg3KsF.mjs';
|
|
14
|
+
export { P as ParagraphFormatting, T as TextFormatting, f as Theme, z as ThemeColorScheme, D as ThemeFont, G as ThemeFontScheme } from './formatting-p5MneNuy.mjs';
|
|
15
|
+
export { d as Relationship, a as Style, S as StyleDefinitions } from './styles-DZZz2oRy.mjs';
|
|
16
16
|
import './docx/wrapTypes.mjs';
|
|
17
17
|
|
|
18
18
|
/**
|
package/dist/core.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{b as attemptSelectiveSave,a as parseDocx}from'./chunk-2CCPNW44.mjs';export{g as createDocx,d as repackDocx,e as repackDocxWithWarnings,b as serializeDocumentBody,a as serializeDocx,c as serializeSectionProperties,f as updateMultipleFiles}from'./chunk-KXLTK7AT.mjs';import'./chunk-UQSVFDRV.mjs';import'./chunk-QWHU7YIW.mjs';import'./chunk-MAYPJU23.mjs';export{f as blendColors,r as colorsEqual,o as createRgbColor,n as createThemeColor,d as darkenColor,p as ensureHexPrefix,h as generateThemeTintShadeMatrix,c as getContrastingColor,g as getThemeTintShadeHex,k as isBlack,l as isWhite,e as lightenColor,m as parseColorString,a as resolveColor,i as resolveHighlightColor,q as resolveHighlightToCss,j as resolveShadingColor}from'./chunk-LTVVQMHB.mjs';export{b as emuToPixels,i as emuToTwips,q as formatPx,k as halfPointsToPixels,c as pixelsToEmu,h as pixelsToTwips,d as pointsToPixels,j as twipsToEmu,g as twipsToPixels}from'./chunk-CTBUQRYQ.mjs';export{n as canRenderFont,k as getLoadedFonts,g as isFontLoaded,j as isFontsLoading,i as isGoogleFontsEnabled,e as loadFont,o as loadFontFromBuffer,f as loadFonts,l as onFontsLoaded,w as preloadCommonFonts,h as setGoogleFontsEnabled,a as toArrayBuffer}from'./chunk-QX2CDKPG.mjs';import'./chunk-HPZFJGGM.mjs';import'./chunk-QGZ2AB3M.mjs';import'./chunk-LT2GCWZ3.mjs';import'./chunk-YITJ4QAO.mjs';import'./chunk-UBUTIWXN.mjs';import'./chunk-7WIUNGQW.mjs';import'./chunk-DLXIZBB6.mjs';import'./chunk-HGKSOBXK.mjs';import {b as b$1}from'./chunk-TTRUPDAB.mjs';var v="0.5.0";var f=class extends Error{constructor(t){super(t.message);b$1(this,"failure");this.name="DocxExportError",this.failure=t;}};async function g(){let e=await import('./wasm-edit.mjs');return await e.preloadEditWasm(),e}function D(e){let o=JSON.parse(e);if(!o.ok)throw new f(o.failure);return o.content}async function It(e,o){let t=await g();return D(t.exportDocxStructuredJson(e,JSON.stringify(o)))}async function Ft(e,o){let t=await g();return D(t.exportDocxMarkdownJson(e,JSON.stringify(o)))}async function Nt(e,o={}){let t=await g();return D(t.renderDocxMarkdownJson(JSON.stringify(e),JSON.stringify(o)))}function At(e,o){let t={};for(let[n,r]of Object.entries(e.package.theme?.colorScheme??{}))typeof r=="string"&&(t[n]=r);return {themeColors:t,defaultTabStopTwips:o?.defaultTabStopTwips??e.package.settings?.defaultTabStop??null,numericIds:{},showHiddenText:o?.showHiddenText??false}}function Lt(e){let o;try{o=atob(e.data);}catch{throw new TypeError(`font ${JSON.stringify(e.key)} is not base64`)}let t=new Uint8Array(o.length);for(let n=0;n<o.length;n+=1)t[n]=o.charCodeAt(n);return t}async function Mt(e,o,t){await g();let[{createYrsSession:n},{buildResidentRegionLayoutRequest:r}]=await Promise.all([import('./yrs/index.mjs'),import('./chunk-67MGRMP3.mjs')]),i=new Map,a=t.fonts.map((l,p)=>{if(i.has(l.key))throw new TypeError(`font key ${JSON.stringify(l.key)} is repeated`);return i.set(l.key,p),Lt(l)}),h=l=>l.map(p=>{let x=i.get(p);if(x===void 0)throw new TypeError(`font key ${JSON.stringify(p)} is not a font`);return x}),C=await n({clientId:1});try{let{document:l}=C.openDocx(e,!0),p=r(l,0,At(l,t.renderEnvironment)),x=l.package.settings?.compatibilityFlags,E={};p.measurement={fontChains:E,defaults:{fontSize:t.measurementDefaults?.fontSize??11,fontFamily:t.measurementDefaults?.fontFamily??"Calibri"},compat:{noLeading:t.compatibility?.noLeading??x?.noLeading??!1,doNotExpandShiftReturn:t.compatibility?.doNotExpandShiftReturn??x?.doNotExpandShiftReturn??!1},authoritativeShaping:!0};let L=JSON.parse(C.layoutFontRequirementsJson(JSON.stringify(p)));for(let d of L)E[d.key]=h(t.fontChains?.[d.key]??t.fontChains?.[d.family.toLowerCase()]??t.defaultChain);let k=new Uint8Array(a.reduce((d,M)=>d+M.length,0)),P=0;for(let d of a)k.set(d,P),P+=d.length;let T=C.exportSnapshotWithPrivateFonts(k,Uint32Array.from(a,d=>d.length),JSON.stringify(p),o);if(!T.ok)throw new f(T.failure);return T.content}finally{C.destroy();}}async function jt(e,o={}){let t=await g();return D(t.renderDocxMarkdownWithPagesJson(JSON.stringify(e),JSON.stringify(o)))}async function Bt(e,o,t){let{compareDocxInSession:n}=await import('./chunk-H7K4SJKK.mjs');return n(e,o,t)}var b=class extends Error{constructor(t){super(t.message);b$1(this,"failure");this.name="DocxContentControlsError",this.failure=t;}};async function O(){let e=await import('./wasm-edit.mjs');return await e.preloadEditWasm(),e}function R(e){let o=JSON.parse(e);if(!o.ok)throw new b(o.failure);return o.content}async function Jt(e,o={}){let t=await O();return R(t.listDocxContentControlsJson(e,JSON.stringify(o)))}async function Wt(e,o,t={}){let n=await O();return R(n.findDocxContentControlsJson(e,JSON.stringify(o),JSON.stringify(t)))}var Ut={includeHeaders:true,includeFooters:true,includePageNumbers:true,pageRange:null,scale:1,printBackground:true,margins:"default"};function Ht(){return {...Ut}}function _t(){typeof window<"u"&&window.print();}var $t="@media print { body { margin: 0; padding: 0; } @page { margin: 0; } }";function zt(e="Document",o){if(typeof window>"u")return null;let t=window.open("","_blank");if(!t)return null;t.opener=null;let n=t.document;n.title=e;let r=n.createElement("style");r.textContent=$t,n.head.appendChild(r);let i=new DOMParser().parseFromString(o,"text/html");for(let a of Array.from(i.body.childNodes))n.body.appendChild(n.importNode(a,true));return t}function Xt(e,o){if(!e||!e.trim())return null;let t=e.trim();if(/^\d+$/.test(t)){let r=parseInt(t,10);return r>=1&&r<=o?{start:r,end:r}:null}let n=t.match(/^(\d+)-(\d+)$/);if(n){let r=parseInt(n[1],10),i=parseInt(n[2],10);if(r>=1&&i<=o&&r<=i)return {start:r,end:i}}return null}function Vt(e,o){return e?e.start===e.end?`Page ${e.start}`:`Pages ${e.start}-${e.end}`:`All (${o} pages)`}function qt(){return typeof window<"u"&&typeof window.print=="function"}var m=class{constructor(o){b$1(this,"listeners",new Set);b$1(this,"snapshot");b$1(this,"subscribe",o=>(this.listeners.add(o),()=>{this.listeners.delete(o);}));b$1(this,"getSnapshot",()=>this.snapshot);this.snapshot=o;}setSnapshot(o){this.snapshot=o,this.notify();}notify(){for(let o of this.listeners)o();}};var y={TABLE_INDEX:"data-table-index",ROW_INDEX:"data-row",COLUMN_INDEX:"data-col",TABLE_CELL:"data-table-cell"};function I(e,o){if(!(e instanceof Element))return null;let t=e;for(;t&&t!==o;){if(t.tagName==="TD"||t.tagName==="TH"){let n=t.getAttribute(y.ROW_INDEX),r=t.getAttribute(y.COLUMN_INDEX);if(n!==null&&r!==null){let i=t;for(;i&&i!==o;){if(i.tagName==="TABLE"){let a=i.getAttribute(y.TABLE_INDEX);if(a!==null)return {tableIndex:parseInt(a,10),rowIndex:parseInt(n,10),columnIndex:parseInt(r,10)};break}i=i.parentElement;}}break}t=t.parentElement;}return null}function F(e,o){if(!e.package?.document?.content)return null;let t=0;for(let n of e.package.document.content)if(n.type==="table"){if(t===o)return n;t++;}return null}function N(e,o,t){if(!e.package?.document?.content)return e;let n=0,r=e.package.document.content.map(i=>{if(i.type==="table"){if(n===o)return n++,t;n++;}return i});return {...e,package:{...e.package,document:{...e.package.document,content:r}}}}function A(e,o){if(!e.package?.document?.content)return e;let t=0,n=e.package.document.content.filter(r=>{if(r.type==="table"){let i=t===o;return t++,!i}return true});return {...e,package:{...e.package,document:{...e.package.document,content:n}}}}var S=class extends m{constructor(){super({selectedCell:null});}selectCell(o){this.setSnapshot({selectedCell:o});}clearSelection(){this.setSnapshot({selectedCell:null});}isCellSelected(o,t,n){let{selectedCell:r}=this.getSnapshot();return r?r.tableIndex===o&&r.rowIndex===t&&r.columnIndex===n:false}getSelectedCell(){return this.getSnapshot().selectedCell}};var w=class extends m{constructor(){super({notifications:[]});b$1(this,"notifications",[]);b$1(this,"idCounter",0);b$1(this,"timers",new Set);}showError(t,n){return this.addNotification(t,"error",n)}showWarning(t,n){return this.addNotification(t,"warning",n)}showInfo(t,n){return this.addNotification(t,"info",n)}dismiss(t){this.notifications=this.notifications.map(r=>r.id===t?{...r,dismissed:true}:r),this.emitSnapshot();let n=setTimeout(()=>{this.timers.delete(n),this.notifications=this.notifications.filter(r=>r.id!==t),this.emitSnapshot();},300);this.timers.add(n);}clearAll(){this.notifications=[];for(let t of this.timers)clearTimeout(t);this.timers.clear(),this.emitSnapshot();}destroy(){for(let t of this.timers)clearTimeout(t);this.timers.clear(),this.notifications=[];}addNotification(t,n,r){let i=`error-${++this.idCounter}-${Date.now()}`,a={id:i,message:t,severity:n,details:r,timestamp:Date.now()};if(this.notifications=[...this.notifications,a],this.emitSnapshot(),n!=="error"){let h=setTimeout(()=>{this.timers.delete(h),this.dismiss(i);},5e3);this.timers.add(h);}return i}emitSnapshot(){this.setSnapshot({notifications:this.notifications});}};var we=v;export{b as DocxContentControlsError,f as DocxExportError,w as ErrorManager,m as Subscribable,y as TABLE_DATA_ATTRIBUTES,S as TableSelectionManager,we as VERSION,Bt as compareDocx,A as deleteTableFromDocument,Ft as exportDocxMarkdown,It as exportDocxStructured,Mt as exportDocxStructuredWithPages,Wt as findDocxContentControls,I as findTableFromClick,Vt as formatPageRange,Ht as getDefaultPrintOptions,F as getTableFromDocument,qt as isPrintSupported,Jt as listDocxContentControls,zt as openPrintWindow,Xt as parsePageRange,Nt as renderDocxMarkdown,jt as renderDocxMarkdownWithPages,_t as triggerPrint,N as updateTableInDocument};
|