@docx-editor.dev/pro 2.27.0 → 2.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/chunk-CNXDNDD3.js +1 -0
  2. package/dist/{chunk-PVRTSPHN.cjs → chunk-FD2KDBHX.cjs} +1 -1
  3. package/dist/chunk-JRHEYVVY.cjs +1 -0
  4. package/dist/chunk-L567WP3J.js +5 -0
  5. package/dist/chunk-MJECUVHQ.cjs +5 -0
  6. package/dist/chunk-MWO2ZUEJ.js +1 -0
  7. package/dist/chunk-N34IUO36.cjs +1 -0
  8. package/dist/chunk-OT5R3IYV.cjs +1 -0
  9. package/dist/chunk-P2EF7WMV.js +1 -0
  10. package/dist/chunk-Q5JTCGJI.js +1 -0
  11. package/dist/chunk-SNQCYZLT.js +1 -0
  12. package/dist/chunk-ZSAAX6HV.cjs +1 -0
  13. package/dist/collaboration/hocuspocus.cjs +1 -1
  14. package/dist/collaboration/hocuspocus.d.cts +18 -11
  15. package/dist/collaboration/hocuspocus.d.ts +18 -11
  16. package/dist/collaboration/hocuspocus.js +1 -1
  17. package/dist/collaboration/index.cjs +2 -2
  18. package/dist/collaboration/index.d.cts +333 -18
  19. package/dist/collaboration/index.d.ts +333 -18
  20. package/dist/collaboration/index.js +2 -2
  21. package/dist/collaboration/webrtc.cjs +2 -2
  22. package/dist/collaboration/webrtc.d.cts +26 -3
  23. package/dist/collaboration/webrtc.d.ts +26 -3
  24. package/dist/collaboration/webrtc.js +2 -2
  25. package/dist/{collaboration-module-DlSv0oAd.d.cts → collaboration-module-DWn2heE1.d.cts} +1 -0
  26. package/dist/{collaboration-module-DlSv0oAd.d.ts → collaboration-module-DWn2heE1.d.ts} +1 -0
  27. package/dist/{define-custom-node-DUJ4ZZdo.d.ts → define-custom-node-CNRQG1TI.d.cts} +12 -4
  28. package/dist/{define-custom-node-DG5gpRa5.d.cts → define-custom-node-D0c36PpZ.d.ts} +12 -4
  29. package/dist/document-session-3VC43WNI.cjs +1 -0
  30. package/dist/{document-session-BKKfJzKB.d.cts → document-session-Bxs4_GgX.d.ts} +55 -33
  31. package/dist/document-session-J2YKWERI.js +1 -0
  32. package/dist/{document-session-BQ4nBDTd.d.ts → document-session-_v9vqiSX.d.cts} +55 -33
  33. package/dist/document-session-options-CfKypp9c.d.cts +37 -0
  34. package/dist/document-session-options-DelOC7PX.d.ts +37 -0
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.d.cts +29 -4
  37. package/dist/index.d.ts +29 -4
  38. package/dist/index.js +1 -1
  39. package/dist/react/hocuspocus.cjs +1 -1
  40. package/dist/react/hocuspocus.d.cts +52 -8
  41. package/dist/react/hocuspocus.d.ts +52 -8
  42. package/dist/react/hocuspocus.js +1 -1
  43. package/dist/react/index.cjs +2 -2
  44. package/dist/react/index.d.cts +354 -156
  45. package/dist/react/index.d.ts +354 -156
  46. package/dist/react/index.js +2 -2
  47. package/dist/react/webrtc.cjs +1 -1
  48. package/dist/react/webrtc.d.cts +35 -7
  49. package/dist/react/webrtc.d.ts +35 -7
  50. package/dist/react/webrtc.js +1 -1
  51. package/dist/{session-okdqygLg.d.cts → types-6EmrEn4n.d.cts} +26 -4
  52. package/dist/{session-okdqygLg.d.ts → types-6EmrEn4n.d.ts} +26 -4
  53. package/dist/{session-B-ds4k64.d.cts → types-BQ1vBt5Q.d.cts} +32 -54
  54. package/dist/{session-B-ds4k64.d.ts → types-BQ1vBt5Q.d.ts} +32 -54
  55. package/dist/vue/hocuspocus.cjs +1 -1
  56. package/dist/vue/hocuspocus.d.cts +52 -7
  57. package/dist/vue/hocuspocus.d.ts +52 -7
  58. package/dist/vue/hocuspocus.js +1 -1
  59. package/dist/vue/index.cjs +2 -2
  60. package/dist/vue/index.d.cts +235 -24
  61. package/dist/vue/index.d.ts +235 -24
  62. package/dist/vue/index.js +2 -2
  63. package/dist/vue/webrtc.cjs +1 -1
  64. package/dist/vue/webrtc.d.cts +36 -6
  65. package/dist/vue/webrtc.d.ts +36 -6
  66. package/dist/vue/webrtc.js +1 -1
  67. package/package.json +5 -5
  68. package/dist/chunk-6CDC4KCE.js +0 -4
  69. package/dist/chunk-6SR5OK66.cjs +0 -4
  70. package/dist/chunk-GDTCNTK7.cjs +0 -1
  71. package/dist/chunk-HJB77VBO.js +0 -1
  72. package/dist/chunk-HZEWGK5A.cjs +0 -4
  73. package/dist/chunk-Q4YPX2DT.cjs +0 -1
  74. package/dist/chunk-Q7P2DQ33.js +0 -1
  75. package/dist/chunk-RGR2BLZD.js +0 -4
  76. package/dist/chunk-W3V54DWZ.js +0 -1
  77. package/dist/document-session-32FPPQHT.js +0 -1
  78. package/dist/document-session-32ULDU2C.js +0 -1
  79. package/dist/document-session-HCU2O55L.cjs +0 -1
  80. package/dist/document-session-ZOM2KHHX.cjs +0 -1
  81. package/dist/hocuspocus-BMF7MTMJ.js +0 -1
  82. package/dist/hocuspocus-JPJOC6ZV.cjs +0 -1
  83. package/dist/webrtc-MM3LDVLU.cjs +0 -2
  84. package/dist/webrtc-RYONN7E7.js +0 -2
@@ -1,8 +1,19 @@
1
- export { C as CollaborationModuleOptions, c as collaborationModule } from '../collaboration-module-DlSv0oAd.js';
2
- export { a as CollaborationBootstrap, c as CollaborationHandle, b as CollaborationIdentityUpdate, C as CollaborationSession, d as CreateTextCollaborationOptions, T as TextCollaborationHandle, e as TextCollaborationSession, f as createTextCollaboration } from '../session-B-ds4k64.js';
3
- export { a as CollaborationResourceUsage, C as CreateDocumentCollaborationOptions, D as DocumentCollaborationHandle, b as DocumentCollaborationSession, c as createDocumentCollaboration, r as readCollaborationResourceUsage } from '../document-session-BQ4nBDTd.js';
4
- import { CollaborationFailureCode } from '@docx-editor.dev/core/collaboration';
1
+ /**
2
+ * `@docx-editor.dev/pro/collaboration` — Yjs replica factories and the module factory.
3
+ *
4
+ * The default entry imports no network provider. Import
5
+ * `@docx-editor.dev/pro/collaboration/webrtc` for the WebRTC wrapper and
6
+ * `@docx-editor.dev/pro/collaboration/hocuspocus` for the Hocuspocus wrapper.
7
+ *
8
+ * @packageDocumentation
9
+ * @public
10
+ */
11
+ export { C as CollaborationModuleOptions, c as collaborationModule } from '../collaboration-module-DWn2heE1.js';
12
+ export { a as CollaborationBootstrap, c as CollaborationHandle, b as CollaborationIdentityUpdate, C as CollaborationSession } from '../types-BQ1vBt5Q.js';
13
+ export { C as CollaborationResourceUsage, D as DocumentCollaborationHandle, a as DocumentCollaborationSession, c as createDocumentCollaboration, r as readCollaborationResourceUsage } from '../document-session-Bxs4_GgX.js';
5
14
  import * as Y from 'yjs';
15
+ import { CollaborationFailureCode, EditorCollaborationSession } from '@docx-editor.dev/core/collaboration';
16
+ export { C as CreateDocumentCollaborationOptions } from '../document-session-options-DelOC7PX.js';
6
17
  import '@docx-editor.dev/core/editor';
7
18
  import 'y-protocols/awareness';
8
19
 
@@ -20,10 +31,14 @@ interface DocumentCollaborationVersions {
20
31
  /**
21
32
  * Versions supported by this full-document collaboration release.
22
33
  *
23
- * Use assertDocumentCollaborationCompatibility before admitting a client to synchronization. These values
24
- * describe the application schema, not the DOCX format or the Yjs binary update format.
25
- * Releases with the same tuple can share rooms. A changed tuple requires a coordinated
26
- * upgrade. This descriptor does not migrate persisted rooms or authenticate clients.
34
+ * These values describe the application schema, not the DOCX format or the Yjs binary
35
+ * update format. Releases with the same tuple can share rooms. A changed tuple requires a
36
+ * coordinated upgrade. This descriptor does not migrate persisted rooms or authenticate
37
+ * clients.
38
+ *
39
+ * @deprecated Send `COLLABORATION_FORMAT_VERSION` in the connection handshake and check it
40
+ * with `assertCollaborationFormatCompatibility`. This tuple stays supported for existing
41
+ * handshakes.
27
42
  * @public
28
43
  */
29
44
  declare const DOCUMENT_COLLABORATION_VERSIONS: DocumentCollaborationVersions;
@@ -39,6 +54,9 @@ declare const DOCUMENT_COLLABORATION_VERSIONS: DocumentCollaborationVersions;
39
54
  *
40
55
  * @throws CollaborationSchemaError with `protocol-version-mismatch` or
41
56
  * `schema-version-mismatch`, including the field and expected/received version in `detail`.
57
+ * Both codes mean that this client and the room have different collaboration formats.
58
+ * @deprecated Use `assertCollaborationFormatCompatibility` with
59
+ * `COLLABORATION_FORMAT_VERSION`. This function stays supported for existing handshakes.
42
60
  * @public
43
61
  */
44
62
  declare function assertDocumentCollaborationCompatibility(versions: unknown): void;
@@ -76,12 +94,272 @@ declare function assertDocumentCollaborationCompatibility(versions: unknown): vo
76
94
  */
77
95
  declare function readCollaborationDocument(ydoc: Y.Doc): Uint8Array;
78
96
 
79
- /** Wire protocol for experimental text-only collaboration. Full-document clients use DOCUMENT_COLLABORATION_VERSIONS. @public */
80
- declare const PROTOCOL_VERSION = 1;
81
- /** Schema for experimental text-only collaboration. Full-document clients use DOCUMENT_COLLABORATION_VERSIONS. @public */
82
- declare const SCHEMA_VERSION = 1;
83
- /** Maximum accepted creator baseline size in bytes. @public */
84
- declare const MAX_BASELINE_BYTES: number;
97
+ /**
98
+ * Prepare a room's `Y.Doc` on a server that holds it, such as a Hocuspocus server. Call it
99
+ * once when the server creates or loads the document, before it applies any update.
100
+ *
101
+ * @remarks
102
+ * Paragraph text keeps formatting in Yjs formatting markers. After a remote update, Yjs
103
+ * removes the markers it finds redundant from the document that received it. On a server,
104
+ * that removal is a change of the server's own, which the server sends to every participant,
105
+ * and it can remove the formatting of text a participant is typing. A prepared document does
106
+ * not remove markers. Every editor replica is prepared already.
107
+ *
108
+ * @param document - The room document the server holds.
109
+ * @returns A function that stops the preparation. Call it only when the server discards the
110
+ * document.
111
+ * @public
112
+ */
113
+ declare function prepareCollaborationServerDocument(document: Y.Doc): () => void;
114
+
115
+ /**
116
+ * Room compaction by generation.
117
+ *
118
+ * Yjs state only grows: deleted text, deleted records, formatting markers, and media nobody
119
+ * references stay in a room. A server compacts a room by building a new generation: a fresh
120
+ * document seeded from the room's current content, with a new generation ID. It does so when
121
+ * it loads the room, before any participant syncs, so no participant connected at the time
122
+ * can lose an edit.
123
+ *
124
+ * A replica that still holds the previous generation must not sync with the new one: its
125
+ * items would merge into the fresh document as unrelated state. Every client therefore sends
126
+ * the generation it holds before its first sync message, and the server refuses a mismatch
127
+ * with `room-generation-changed`. The replica keeps its document; it rejoins to continue.
128
+ */
129
+
130
+ /**
131
+ * The generation ID of the room a document holds: empty for a room never compacted, and
132
+ * empty for a document that holds no room yet.
133
+ *
134
+ * @public
135
+ */
136
+ declare function readCollaborationRoomGeneration(document: Y.Doc): string;
137
+ /** Options for {@link compactCollaborationState}. @public */
138
+ interface CompactCollaborationStateOptions {
139
+ /**
140
+ * Compact only when the stored state is at least this many times the size of the compacted
141
+ * state. Default 2. Pass 1 to compact whenever it makes the room smaller.
142
+ */
143
+ readonly minimumGain?: number;
144
+ }
145
+ /**
146
+ * Build a new generation of a room from its stored state, or return null when compaction
147
+ * would gain less than `minimumGain`.
148
+ *
149
+ * The new generation holds the room's current content, read as a `.docx` package, under the
150
+ * same document ID and a new generation ID. Deleted text and records, formatting history, and
151
+ * unreferenced media are gone. Call it when the server loads a room, before any participant
152
+ * syncs, and store the result in place of the old state.
153
+ *
154
+ * A check reads the whole room and builds it again. The answer for a state found not worth
155
+ * compacting is remembered in this process, so the same bytes are checked once. A state that
156
+ * changed is checked again.
157
+ *
158
+ * Throws `CollaborationSchemaError` when the stored state cannot be read, as
159
+ * `readCollaborationDocument` does.
160
+ *
161
+ * @public
162
+ */
163
+ declare function compactCollaborationState(state: Uint8Array, options?: CompactCollaborationStateOptions): Promise<Uint8Array | null>;
164
+ /** What the gate reads of a Hocuspocus `beforeHandleMessage` payload. @public */
165
+ interface CollaborationRoomGatePayload {
166
+ /** The connection's context object, which the gate marks once the generation matched. */
167
+ readonly context: object;
168
+ /** The room's server-side `Y.Doc`. */
169
+ readonly document: Y.Doc;
170
+ /** The incoming message bytes. */
171
+ readonly update: Uint8Array;
172
+ }
173
+ /**
174
+ * Refuse a connection whose replica holds another generation of the room. Call it from the
175
+ * Hocuspocus `beforeHandleMessage` hook. A client sends the generation it holds before its
176
+ * first sync message; on a mismatch, or a sync message without one, this throws an error
177
+ * that closes the connection with `room-generation-changed` before any of its state merges.
178
+ * A message the gate cannot read is refused the same way.
179
+ *
180
+ * A replica that holds no room yet names no generation and passes: it has no state of an
181
+ * earlier generation to merge. The gate keeps honest replicas of two generations apart. It
182
+ * is not access control: a client that may write to the room can send any update, so
183
+ * authenticate connections in `onAuthenticate`.
184
+ *
185
+ * @public
186
+ */
187
+ declare function checkCollaborationRoomGeneration(payload: CollaborationRoomGatePayload): void;
188
+
189
+ /**
190
+ * How saved room state relates to the format this build writes.
191
+ *
192
+ * - `current`: the room is in this build's format; it needs no migration.
193
+ * - `earlier-format`: an earlier build wrote it; export it with that build and migrate it.
194
+ * - `later-format`: a later build wrote it; this build must not open or replace it.
195
+ *
196
+ * @public
197
+ */
198
+ type CollaborationMigrationNeed = 'current' | 'earlier-format' | 'later-format';
199
+ /**
200
+ * Whether saved room state needs a migration before this build can serve it.
201
+ *
202
+ * A room whose version information is missing or malformed was written before collaboration
203
+ * formats were versioned, and counts as `earlier-format`.
204
+ *
205
+ * Throws `CollaborationSchemaError` with code `not-initialized` for state that holds no room,
206
+ * and with code `invalid-baseline` for bytes that are not room state.
207
+ *
208
+ * @public
209
+ */
210
+ declare function collaborationMigrationNeed(state: Uint8Array): CollaborationMigrationNeed;
211
+ /**
212
+ * A check that a migration runs on the new room, compared with the export.
213
+ *
214
+ * - `paragraphs`: the new room holds a different number of paragraphs.
215
+ * - `text`: a paragraph's text differs.
216
+ * - `formatting`: a paragraph's properties, or the character formatting of its text, differ.
217
+ * - `structure`: an XML part differs in something the other checks do not cover, such as
218
+ * tables, sections, styles, numbering, tracked changes, comments, or notes.
219
+ * - `media`: a media part's bytes are missing.
220
+ * - `links`: an external link target is missing.
221
+ *
222
+ * @public
223
+ */
224
+ type CollaborationMigrationCheck = 'paragraphs' | 'text' | 'formatting' | 'structure' | 'media' | 'links';
225
+ /** A paragraph by its part and its position in that part, from 1. @public */
226
+ interface CollaborationMigrationPosition {
227
+ /** The package part that holds the paragraph, such as `/word/document.xml`. */
228
+ readonly part: string;
229
+ /** The paragraph's position in its part, from 1, in document order. */
230
+ readonly paragraph: number;
231
+ }
232
+ /**
233
+ * One paragraph that differs between the export and the new room.
234
+ *
235
+ * `expected` and `actual` hold document text. Treat them as document content: keep them out
236
+ * of logs that people without access to the document can read.
237
+ *
238
+ * @public
239
+ */
240
+ interface CollaborationMigrationDifference extends CollaborationMigrationPosition {
241
+ /**
242
+ * - `text`: the paragraph's text differs.
243
+ * - `formatting`: its text is the same, but its properties or character formatting differ.
244
+ * - `missing`: the export has the paragraph and the new room does not.
245
+ * - `added`: the new room has a paragraph the export does not.
246
+ */
247
+ readonly kind: 'text' | 'formatting' | 'missing' | 'added';
248
+ /** The paragraph's text in the export, or null when the export has no such paragraph. */
249
+ readonly expected: string | null;
250
+ /** The paragraph's text in the new room, or null when the new room has no such paragraph. */
251
+ readonly actual: string | null;
252
+ }
253
+ /**
254
+ * What a migration found, comparing the new room with the export it was seeded from.
255
+ *
256
+ * The check compares each XML part of the export with the new room's. It ignores only what
257
+ * every save writes anew: namespace declarations, the values of paragraph IDs
258
+ * (`w14:paraId`, `w14:textId`) and of `w:id`, and the relationship parts. A reference to an ID,
259
+ * such as a comment anchor or a comment extension, must still name the same element. Revision
260
+ * IDs are not compared: they only have to be unique. For each paragraph it also
261
+ * reports its text and formatting, to locate a difference. It compares every media part by its
262
+ * bytes, and every external link target.
263
+ *
264
+ * @public
265
+ */
266
+ interface CollaborationMigrationReport {
267
+ /** True when every check passed. */
268
+ readonly ok: boolean;
269
+ /** The checks that failed. Empty when `ok` is true. */
270
+ readonly failed: readonly CollaborationMigrationCheck[];
271
+ /** The earlier room's format, or `unversioned` for a room written before formats had one. */
272
+ readonly from: string;
273
+ /** The format of the new room: this build's. */
274
+ readonly to: string;
275
+ /** The document ID of the new room. Every client must open the room with this ID. */
276
+ readonly documentId: string;
277
+ /**
278
+ * Paragraphs in the export, in every part: body, tables, headers, footers, notes, and
279
+ * comments. A paragraph inside another, as in a text box, counts with the one that holds it.
280
+ */
281
+ readonly paragraphs: number;
282
+ /**
283
+ * Paragraphs the new room keeps but the editor can neither show nor edit. They save back
284
+ * unchanged, and they do not fail the check. Check such rooms before people edit them.
285
+ */
286
+ readonly hidden: number;
287
+ /** Where the first hidden paragraphs are, at most 20. */
288
+ readonly hiddenAt: readonly CollaborationMigrationPosition[];
289
+ /**
290
+ * XML parts that differ, by name, or that one side does not have. A part whose paragraphs
291
+ * differ is listed too.
292
+ */
293
+ readonly changedParts: readonly string[];
294
+ /** How many paragraphs differ. `differences` lists at most the first 20. */
295
+ readonly differenceCount: number;
296
+ /** The first paragraphs that differ, at most 20. */
297
+ readonly differences: readonly CollaborationMigrationDifference[];
298
+ /** Media parts of the export, by name, whose bytes the new room does not hold. */
299
+ readonly missingMedia: readonly string[];
300
+ /** External link targets of the export that the new room does not hold. */
301
+ readonly missingLinks: readonly string[];
302
+ }
303
+ /**
304
+ * The result of `migrateCollaborationRoom`.
305
+ *
306
+ * - `ok: true`: the check passed. Store `state` in place of the earlier room's state.
307
+ * - `reason: 'check-failed'`: the new room differs from the export. Nothing is returned to
308
+ * store; `report` says what differs.
309
+ * - `reason: 'current'`: the room is already in this build's format. Leave it as it is.
310
+ * - `reason: 'later-format'`: a later build wrote the room. Do not open or replace it.
311
+ *
312
+ * @public
313
+ */
314
+ type CollaborationMigration = {
315
+ readonly ok: true;
316
+ readonly state: Uint8Array;
317
+ readonly report: CollaborationMigrationReport;
318
+ } | {
319
+ readonly ok: false;
320
+ readonly reason: 'check-failed';
321
+ readonly report: CollaborationMigrationReport;
322
+ } | {
323
+ readonly ok: false;
324
+ readonly reason: 'current' | 'later-format';
325
+ };
326
+ /** Options for {@link migrateCollaborationRoom}. @public */
327
+ interface MigrateCollaborationRoomOptions {
328
+ /** The earlier room's saved state: the exact bytes that `exported` was exported from. */
329
+ readonly state: Uint8Array;
330
+ /**
331
+ * The `.docx` that the build which created the room exported from `state`, with
332
+ * `readCollaborationDocument`.
333
+ */
334
+ readonly exported: Uint8Array;
335
+ /**
336
+ * The document ID of the new room. Omit it to keep the earlier room's ID, which is what its
337
+ * clients open the room with: a client whose ID differs is refused with
338
+ * `document-id-mismatch`. Pass it only to give the room a new ID, and open it with that ID.
339
+ */
340
+ readonly documentId?: string;
341
+ }
342
+ /**
343
+ * Seed a room in this build's format from the `.docx` that the earlier build exported, and
344
+ * check the new room against that export.
345
+ *
346
+ * The new room keeps the earlier room's document ID unless `documentId` gives another. It is a
347
+ * new room generation: a replica that still holds the earlier room is refused with
348
+ * `room-generation-changed` and rejoins.
349
+ *
350
+ * This function does not check that `exported` was made from `state`. Store a digest of the
351
+ * state with each export, and compare it before you call this function: an export made before
352
+ * later edits would lose them.
353
+ *
354
+ * Throws `CollaborationSchemaError` when the inputs cannot be used: `invalid-baseline` for
355
+ * bytes that are not room state or not a `.docx`, `not-initialized` for state that holds no
356
+ * room, `invalid-document-id` for an unusable document ID, and a limit code such as
357
+ * `too-many-nodes` for an export larger than a room's limits.
358
+ *
359
+ * @public
360
+ */
361
+ declare function migrateCollaborationRoom(options: MigrateCollaborationRoomOptions): Promise<CollaborationMigration>;
362
+
85
363
  /**
86
364
  * Typed collaboration schema or trust-boundary failure.
87
365
  * Version-mismatch messages include recovery guidance and a documentation link.
@@ -89,9 +367,15 @@ declare const MAX_BASELINE_BYTES: number;
89
367
  * @public
90
368
  */
91
369
  declare class CollaborationSchemaError extends Error {
370
+ /** Stable failure code. Branch on it. */
92
371
  readonly code: CollaborationFailureCode;
372
+ /** Bounded diagnostic text for logs. Not a parsing contract. */
93
373
  readonly detail?: string | undefined;
94
- constructor(code: CollaborationFailureCode, detail?: string | undefined);
374
+ constructor(
375
+ /** Stable failure code. Branch on it. */
376
+ code: CollaborationFailureCode,
377
+ /** Bounded diagnostic text for logs. Not a parsing contract. */
378
+ detail?: string | undefined);
95
379
  }
96
380
 
97
381
  /**
@@ -113,7 +397,10 @@ declare const COLLABORATION_FORMAT_VERSION: string;
113
397
  * This check does not authenticate clients, validate room content, or migrate data.
114
398
  *
115
399
  * @throws CollaborationSchemaError with `collaboration-format-mismatch` for an
116
- * incompatible, missing, or malformed version. Use `code` for application logic.
400
+ * incompatible, missing, or malformed version. Use `code` for application logic. This code,
401
+ * `protocol-version-mismatch`, and `schema-version-mismatch` all mean that this client and
402
+ * the room have different collaboration formats. Refuse the connection and direct the user
403
+ * to a compatible deployment; reconnecting does not help.
117
404
  * @public
118
405
  */
119
406
  declare function assertCollaborationFormatCompatibility(version: unknown): void;
@@ -132,5 +419,33 @@ declare function assertCollaborationFormatCompatibility(version: unknown): void;
132
419
  */
133
420
  declare function readCollaborationFormatVersion(ydoc: Y.Doc): string;
134
421
 
135
- export { COLLABORATION_FORMAT_VERSION, CollaborationSchemaError, DOCUMENT_COLLABORATION_VERSIONS, MAX_BASELINE_BYTES, PROTOCOL_VERSION, SCHEMA_VERSION, assertCollaborationFormatCompatibility, assertDocumentCollaborationCompatibility, readCollaborationDocument, readCollaborationFormatVersion };
136
- export type { DocumentCollaborationVersions };
422
+ /**
423
+ * Protocol identifier for the retired text-only collaboration format.
424
+ * @deprecated Use COLLABORATION_FORMAT_VERSION for full-document connection checks.
425
+ * @public
426
+ */
427
+ declare const PROTOCOL_VERSION = 1;
428
+ /**
429
+ * Schema identifier for the retired text-only collaboration format.
430
+ * @deprecated Use COLLABORATION_FORMAT_VERSION for full-document connection checks.
431
+ * @public
432
+ */
433
+ declare const SCHEMA_VERSION = 1;
434
+ /**
435
+ * Historical baseline byte limit for the retired text-only collaboration factory.
436
+ * This value does not configure full-document collaboration limits.
437
+ * @deprecated Use the full-document factory's validation and typed failure codes.
438
+ * @public
439
+ */
440
+ declare const MAX_BASELINE_BYTES: number;
441
+ /**
442
+ * Retained type for integrations with the retired text-only collaboration factory.
443
+ * @deprecated Use DocumentCollaborationSession for full-document collaboration.
444
+ * @public
445
+ */
446
+ interface TextCollaborationSession extends EditorCollaborationSession {
447
+ setTransportStatus(status: 'ready' | 'disconnected' | 'error', reason?: CollaborationFailureCode, detail?: string): void;
448
+ }
449
+
450
+ export { COLLABORATION_FORMAT_VERSION, CollaborationSchemaError, DOCUMENT_COLLABORATION_VERSIONS, MAX_BASELINE_BYTES, PROTOCOL_VERSION, SCHEMA_VERSION, assertCollaborationFormatCompatibility, assertDocumentCollaborationCompatibility, checkCollaborationRoomGeneration, collaborationMigrationNeed, compactCollaborationState, migrateCollaborationRoom, prepareCollaborationServerDocument, readCollaborationDocument, readCollaborationFormatVersion, readCollaborationRoomGeneration };
451
+ export type { CollaborationMigration, CollaborationMigrationCheck, CollaborationMigrationDifference, CollaborationMigrationNeed, CollaborationMigrationPosition, CollaborationMigrationReport, CollaborationRoomGatePayload, CompactCollaborationStateOptions, DocumentCollaborationVersions, MigrateCollaborationRoomOptions, TextCollaborationSession };
@@ -1,2 +1,2 @@
1
- export{b as collaborationModule}from'../chunk-Q2VBO66F.js';import {j,d,l as l$1,f,g,h as h$1,i,e,a,b}from'../chunk-6CDC4KCE.js';export{d as CollaborationSchemaError,j as DOCUMENT_COLLABORATION_VERSIONS,c as MAX_BASELINE_BYTES,a as PROTOCOL_VERSION,b as SCHEMA_VERSION,k as assertDocumentCollaborationCompatibility,p as createDocumentCollaboration,n as readCollaborationDocument,m as readCollaborationResourceUsage}from'../chunk-6CDC4KCE.js';import*as l from'yjs';import {ORIGIN_IDS}from'@docx-editor.dev/core/store';import {createCollaborationStatusTracker,isCollaborationFailureCode}from'@docx-editor.dev/core/collaboration';var w="docxEditor",h=256,L=256,v=1e6,$=3e4;function X(n){let t=n.actorId.trim(),a=n.name.trim();if(t.length===0||t.length>h||a.length===0||a.length>h)throw new d("invalid-identity");if(n.color!==void 0&&n.color.length>64)throw new d("invalid-identity-color");return Object.freeze({actorId:t,name:a,...n.color?{color:n.color}:{},role:n.role??"human"})}function G(n){let t=n.trim();if(t.length===0||t.length>h)throw new d("invalid-document-id");return t}function J(n){let t=n?.trim()||globalThis.crypto.randomUUID();if(t.length===0||t.length>h)throw new d("invalid-session-id");return t}function Z(n,t){let a=n.toString();if(a===t)return;let o=0;for(;o<a.length&&o<t.length&&a.charCodeAt(o)===t.charCodeAt(o);)o+=1;let e=0;for(;e<a.length-o&&e<t.length-o&&a.charCodeAt(a.length-e-1)===t.charCodeAt(t.length-e-1);)e+=1;let r=a.length-o-e;r>0&&n.delete(o,r);let i=t.slice(o,t.length-e);i.length>0&&n.insert(o,i);}function M(n){if(typeof n!="object"||n===null||Array.isArray(n))return null;let t=n;return typeof t.paragraphId!="string"||t.paragraphId.length!==8||typeof t.position!="string"||t.position.length===0||t.position.length>2048||!/^[A-Za-z0-9_-]+$/.test(t.position)?null:{paragraphId:t.paragraphId,position:t.position}}function W(n){if(n===void 0||typeof n!="object"||n===null||Array.isArray(n))return;let t=n,a=M(t.anchor),o=M(t.head);if(a&&o)return {anchor:a,head:o};if(typeof t.paragraphId=="string"&&t.paragraphId.length===8&&typeof t.anchor=="string"&&typeof t.head=="string"&&t.anchor.length>0&&t.head.length>0&&t.anchor.length<=2048&&t.head.length<=2048&&/^[A-Za-z0-9_-]+$/.test(t.anchor)&&/^[A-Za-z0-9_-]+$/.test(t.head))return {anchor:{paragraphId:t.paragraphId,position:t.anchor},head:{paragraphId:t.paragraphId,position:t.head}}}function _(n){if(typeof n!="object"||n===null||Array.isArray(n))return null;let t=n;if(typeof t.actorId!="string"||t.actorId.length===0||t.actorId.length>h||typeof t.name!="string"||t.name.length===0||t.name.length>h)return null;let a=typeof t.color=="string"&&t.color.length<=64?t.color:void 0,o=t.role==="agent"?"agent":"human",e=W(t.selection);return {actorId:t.actorId,name:t.name,...a?{color:a}:{},role:o,...e?{selection:e}:{}}}function K(n){let t="";for(let a of n)t+=String.fromCharCode(a);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function q(n){let t=n.replace(/-/g,"+").replace(/_/g,"/"),a=atob(t+"=".repeat((4-t.length%4)%4));return Uint8Array.from(a,o=>o.charCodeAt(0))}var A=class{constructor(t,a,o,e$1,r,i){this.ydoc=t;this.awareness=a;this.baseline=i;this.documentId=o,this.sessionId=e$1,this.identity=r;let{root:d,paragraphs:p}=e(t);this.baselineSha256=String(d.get("baselineSha256")),this.initializedBy=String(d.get("initializedBy")),this.undoManager=new l.UndoManager([...p.values()],{trackedOrigins:new Set([this.localOrigin]),captureTimeout:0}),t.on("afterTransaction",this.onYjsTransaction),a.on("change",this.onAwarenessChange),this.publishAwareness(),this.setStatus("ready");}ydoc;awareness;baseline;documentId;sessionId;identity;statusState=createCollaborationStatusTracker();statusListeners=new Set;selectionListeners=new Set;participantListeners=new Set;localOrigin=Object.freeze({kind:"docx-collaboration-local"});undoManager;baselineSha256;initializedBy;port=null;detachPort=null;applyingSharedState=false;remoteCounter=0;destroyed=false;status(){return this.statusState.status()}statusSnapshot(){return this.statusState.snapshot()}subscribeStatus(t){return this.statusListeners.add(t),()=>this.statusListeners.delete(t)}setTransportStatus(t,a,o){if(!this.destroyed&&!(this.statusState.status()==="error"&&t!=="error")){if(a!==void 0){this.setStatus(t,a,o);return}this.setStatus(t);}}get attached(){return this.port!==null}attach(t){if(this.destroyed)return ()=>{};if(this.port)return ()=>{};if(t.documentId!==this.documentId)return this.setStatus("error","document-id-mismatch"),()=>{};this.validateParagraphSet(t),this.port=t,this.reconcilePortFromYjs();let a=t.subscribe(o=>{if(!(this.destroyed||this.applyingSharedState)&&!(o.origin===ORIGIN_IDS.mutationRemote||o.origin===ORIGIN_IDS.projection||o.origin===ORIGIN_IDS.awareness))try{this.reconcileYjsFromPort();}catch(e){this.setStatus("error",e instanceof d?e.code:"local-mirror-failed",e instanceof d?e.detail:void 0);}});return this.detachPort=()=>{this.flushPendingJournals(),a(),this.port===t&&(this.port=null),this.detachPort=null;},()=>this.detachPort?.()}gateOperations(t,a){if(this.destroyed)return "collaboration-session-destroyed";if(this.statusState.status()!=="ready")return "collaboration-session-not-ready";if(!this.port)return "collaboration-session-not-attached";if(a.kind!=="body")return "experimental-collaboration-body-text-only";let o=new Map(this.port.paragraphs().map(e=>[e.nodeId,e.text.length]));for(let e of t){if(e.op!=="insertText"&&e.op!=="deleteText")return "experimental-collaboration-text-only";if("revision"in e&&e.revision!==void 0)return "experimental-collaboration-untracked-text-only";if(!this.port.paragraphByNodeId(e.paragraphId))return "experimental-collaboration-existing-paragraphs-only";let r=o.get(e.paragraphId);if(r===void 0)return "experimental-collaboration-existing-paragraphs-only";let i=e.op==="insertText"?r+e.text.length:r-Math.max(0,e.end-e.start);if(i>v)return "collaboration-text-limit";o.set(e.paragraphId,Math.max(0,i));}return null}canUndo(){return !this.destroyed&&this.statusState.status()==="ready"&&this.undoManager.undoStack.length>0}canRedo(){return !this.destroyed&&this.statusState.status()==="ready"&&this.undoManager.redoStack.length>0}undo(){return this.canUndo()?(this.undoManager.undo(),true):false}redo(){return this.canRedo()?(this.undoManager.redo(),true):false}setLocalSelection(t){if(this.destroyed)return;let{paragraphs:a}=e(this.ydoc),o=(r,i)=>{let d=a.get(r.toUpperCase());if(d)return {paragraphId:r.toUpperCase(),position:K(l.encodeRelativePosition(l.createRelativePositionFromTypeIndex(d,Math.max(0,Math.min(i,d.length)))))}},e$1;if(t){let r=o(t.anchor.paragraphId,t.anchor.offset),i=o(t.head.paragraphId,t.head.offset);r&&i&&(e$1={anchor:r,head:i});}this.publishAwareness(e$1);}participants(){let t=[],a=[...this.awareness.getStates().entries()].slice(0,L);for(let[o,e]of a){let r=_(e[w]);r&&t.push({actorId:r.actorId,name:r.name,...r.color?{color:r.color}:{},role:r.role??"human",isLocal:o===this.awareness.clientID});}return Object.freeze(t)}subscribeParticipants(t){return this.participantListeners.add(t),()=>this.participantListeners.delete(t)}remoteSelections(){if(!this.port)return [];let t=[...this.awareness.getStates().entries()].slice(0,L),{paragraphs:a}=e(this.ydoc),o=[];for(let[e,r]of t){if(e===this.awareness.clientID)continue;let i=_(r[w]);if(!i?.selection)continue;let d=y=>{let T=a.get(y.paragraphId);if(!T)return null;let u;try{u=l.createAbsolutePositionFromRelativePosition(l.decodeRelativePosition(q(y.position)),this.ydoc);}catch{return null}if(!u||u.type!==T)return null;let f=this.port?.paragraphs().find(U=>U.paragraphId===y.paragraphId);return f?{paragraphId:f.paragraphId,nodeId:f.nodeId,offset:u.index}:null},p=d(i.selection.anchor),x=d(i.selection.head);!p||!x||o.push(Object.freeze({actorId:i.actorId,name:i.name,...i.color?{color:i.color}:{},anchor:Object.freeze(p),head:Object.freeze(x)}));}return Object.freeze(o)}subscribeRemoteSelections(t){return this.selectionListeners.add(t),()=>this.selectionListeners.delete(t)}destroy(){this.destroyed||(this.flushPendingJournals(),this.detachPort?.(),this.destroyed=true,this.ydoc.off("afterTransaction",this.onYjsTransaction),this.awareness.off("change",this.onAwarenessChange),this.awareness.setLocalState(null),this.undoManager.destroy(),this.setStatus("destroyed"),this.statusListeners.clear(),this.selectionListeners.clear(),this.participantListeners.clear());}flushPendingJournals(){this.port?.flushPendingJournals();}onYjsTransaction=t=>{if(!this.destroyed&&t.origin!==this.localOrigin){try{this.validateImmutableSchema();}catch(a){this.setStatus("error",a instanceof d?a.code:"shared-schema-invalid",a instanceof d?a.detail:void 0);return}this.port&&this.reconcilePortFromYjs();}};onAwarenessChange=()=>{if(this.destroyed)return;let t=this.remoteSelections();for(let o of [...this.selectionListeners])o(t);let a=this.participants();for(let o of [...this.participantListeners])o(a);};publishAwareness(t){let a={actorId:this.identity.actorId,name:this.identity.name,...this.identity.color?{color:this.identity.color}:{},role:this.identity.role??"human",...t?{selection:t}:{}};this.awareness.setLocalStateField(w,a);}validateParagraphSet(t){let{paragraphs:a}=e(this.ydoc),o=t.paragraphs();if(o.length!==a.size||o.some(e=>!a.has(e.paragraphId)||!(a.get(e.paragraphId)instanceof l.Text)||a.get(e.paragraphId).length>v))throw new d("paragraph-set-mismatch")}validateImmutableSchema(){let{root:t,paragraphs:a$1}=e(this.ydoc),o=new Set(["protocolVersion","schemaVersion","documentId","baselineSha256","baselineByteLength","initializedBy","baseline","initialized"]);if([...t.keys()].some(r=>!o.has(r)))throw new d("unsupported-root-key");if(t.get("protocolVersion")!==a||t.get("schemaVersion")!==b||t.get("documentId")!==this.documentId||t.get("baselineSha256")!==this.baselineSha256||t.get("baselineByteLength")!==this.baseline.bytes.byteLength||t.get("initializedBy")!==this.initializedBy||t.get("initialized")!==true)throw new d("immutable-metadata-changed");let e$1=t.get("baseline");if(!(e$1 instanceof Uint8Array)||e$1.byteLength!==this.baseline.bytes.byteLength||e$1.some((r,i)=>r!==this.baseline.bytes[i]))throw new d("immutable-baseline-changed");for(let[r,i]of a$1)if(!this.baseline.paragraphs.some(d=>d.paragraphId===r)||!(i instanceof l.Text)||i.length>v)throw new d("paragraph-set-mismatch")}reconcileYjsFromPort(){let t=this.port;if(!t)return;let{paragraphs:a}=e(this.ydoc);this.ydoc.transact(()=>{for(let o of t.paragraphs()){let e=a.get(o.paragraphId);if(!e)throw new d("paragraph-set-mismatch");Z(e,o.text);}},this.localOrigin),this.undoManager.stopCapturing();}reconcilePortFromYjs(){let t=this.port;if(!t||this.applyingSharedState)return;let{paragraphs:a}=e(this.ydoc);this.applyingSharedState=true;try{this.validateParagraphSet(t);let o=[];for(let e of t.paragraphs()){let r=a.get(e.paragraphId);if(!r)throw new d("paragraph-set-mismatch");let i=r.toString();i!==e.text&&o.push({paragraphId:e.paragraphId,text:i});}if(o.length>0){this.remoteCounter+=1;let e=t.applyParagraphTexts(o,{origin:ORIGIN_IDS.mutationRemote,actorId:"remote",operationId:`remote:${this.remoteCounter}`});if(!e.ok)throw new d(isCollaborationFailureCode(e.reason)?e.reason:"remote-apply-failed",isCollaborationFailureCode(e.reason)?void 0:e.reason)}}catch(o){this.setStatus("error",o instanceof d?o.code:"remote-apply-failed",o instanceof d?o.detail:void 0);}finally{this.applyingSharedState=false;}}setStatus(t,a,o){if(!this.statusState.set(t,a,o))return;let e=this.statusState.snapshot();for(let r of [...this.statusListeners])r(e.status,e.reason?.code,e.reason?.detail);}};async function Q(n,t,a){if(n.bootstrap.kind==="create-or-join")throw new TypeError("createTextCollaboration does not support bootstrap kind 'create-or-join'. Use createDocumentCollaboration.");if(n.bootstrap.kind==="create"){let o=f(n.bootstrap.document,t);return await g(n.ydoc,t,a.actorId,o),h$1(n.ydoc,t)}return await i(n.ydoc,n.bootstrap.timeoutMs??$,n.bootstrap.signal),h$1(n.ydoc,t)}async function tt(n){let t=G(n.documentId),a=J(n.sessionId),o=X(n.identity),e=await Q(n,t,o),r=new A(n.ydoc,n.awareness,t,a,o,e);return Object.freeze({document:new Uint8Array(e.bytes),session:r,destroy:()=>r.destroy()})}var D=["protocolVersion","sharedSchemaVersion","repairVersion","canonicalModelVersion"];function Y(n){return `docx-collaboration:${n.join(".")}`}var F=Y(D.map(n=>j[n]));function et(n){if(n!==F)throw new d("collaboration-format-mismatch","The collaboration format version is missing or incompatible with this deployment.")}function ot(n){if(!n.share.has(l$1))throw new d("not-initialized");let t;try{t=n.getMap(l$1);}catch{throw new d("collaboration-format-mismatch","The saved room has invalid collaboration version information.")}if(t.get("initialized")!==true||typeof t.get("documentId")!="string")throw new d("not-initialized");let a=D.map(o=>{let e=t.get(o);if(typeof e!="number"||!Number.isSafeInteger(e)||e<0)throw new d("collaboration-format-mismatch","The saved room has missing or invalid collaboration version information.");return e});return Y(a)}
2
- export{F as COLLABORATION_FORMAT_VERSION,et as assertCollaborationFormatCompatibility,tt as createTextCollaboration,ot as readCollaborationFormatVersion};
1
+ import {c as c$1}from'../chunk-SNQCYZLT.js';export{f as checkCollaborationRoomGeneration,b as compactCollaborationState,a as readCollaborationRoomGeneration}from'../chunk-SNQCYZLT.js';import {c,a,b as b$1,e,h,o}from'../chunk-L567WP3J.js';export{b as CollaborationSchemaError,c as DOCUMENT_COLLABORATION_VERSIONS,d as assertDocumentCollaborationCompatibility,q as createDocumentCollaboration,o as readCollaborationDocument,n as readCollaborationResourceUsage}from'../chunk-L567WP3J.js';export{b as collaborationModule}from'../chunk-Q2VBO66F.js';import*as C from'yjs';import {readOoxmlPackage,canonicalOoxmlFingerprint}from'@docx-editor.dev/core/store';function z(o){return a(o)}var A=["protocolVersion","sharedSchemaVersion","repairVersion","canonicalModelVersion"];function E(o){return `docx-collaboration:${o.join(".")}`}var b=E(A.map(o=>c[o]));function H(o){if(o!==b)throw new b$1("collaboration-format-mismatch","The collaboration format version is missing or incompatible with this deployment.")}function O(o){if(!o.share.has(e))throw new b$1("not-initialized");let t;try{t=o.getMap(e);}catch{throw new b$1("collaboration-format-mismatch","The saved room has invalid collaboration version information.")}if(t.get("initialized")!==true||typeof t.get("documentId")!="string")throw new b$1("not-initialized");let n=A.map(l=>{let r=t.get(l);if(typeof r!="number"||!Number.isSafeInteger(r)||r<0)throw new b$1("collaboration-format-mismatch","The saved room has missing or invalid collaboration version information.");return r});return E(n)}function K(o){return k(o,t=>P(_(t)))}async function J(o$1){let t=k(o$1.state,i=>({format:_(i),documentId:W(i)})),n=P(t.format);if(n==="current")return {ok:false,reason:"current"};if(n==="later-format")return {ok:false,reason:"later-format"};let l=o$1.documentId??t.documentId;if(typeof l!="string")throw new b$1("invalid-document-id","The earlier room holds no document ID. Pass the ID its clients use as documentId.");let r=h(l),a=await c$1(o$1.exported,r),p=k(a,i=>o(i)),m=await D(o$1.exported),e=q(m,await D(p),{from:t.format??"unversioned",to:b,documentId:r});return e.ok?{ok:true,state:a,report:e}:{ok:false,reason:"check-failed",report:e}}function k(o,t){let n=new C.Doc;try{try{C.applyUpdate(n,o);}catch{throw new b$1("invalid-baseline","The bytes are not room state.")}return t(n)}finally{n.destroy();}}function W(o){try{return o.getMap(e).get("documentId")}catch{return}}function _(o){try{return O(o)}catch(t){if(t instanceof b$1&&t.code==="collaboration-format-mismatch")return null;throw t}}function P(o){if(o===null)return "earlier-format";let t=eo(o,b);return t===0?"current":t<0?"earlier-format":"later-format"}var T=20;function q(o,t,n){let l=[],r=0,a=new Set;o.paragraphs.length!==t.paragraphs.length&&a.add("paragraphs");let p=Math.max(o.paragraphs.length,t.paragraphs.length);for(let d=0;d<p;d+=1){let g=o.paragraphs[d],u=t.paragraphs[d],y=u?g?g.text!==u.text?"text":g.formatting!==u.formatting?"formatting":null:"added":"missing";if(y===null||((y==="text"||y==="formatting")&&a.add(y),r+=1,l.length>=T))continue;let S=g??u;l.push({part:S.part,paragraph:S.index,kind:y,expected:g?.text??null,actual:u?.text??null});}let m=[...o.media].filter(([d])=>!t.media.has(d)).map(([,d])=>d).sort();m.length>0&&a.add("media");let e=Q(o.links,t.links);e.length>0&&a.add("links");let i=[...new Set([...o.parts.keys(),...t.parts.keys()])].filter(d=>o.parts.get(d)!==t.parts.get(d)).sort();i.length>0&&a.add("structure");let c=t.paragraphs.filter(d=>!d.shown),s=["paragraphs","text","formatting","structure","media","links"];return {ok:a.size===0,failed:s.filter(d=>a.has(d)),from:n.from,to:n.to,documentId:n.documentId,paragraphs:o.paragraphs.length,hidden:c.length,hiddenAt:c.slice(0,T).map(d=>({part:d.part,paragraph:d.index})),changedParts:i,differenceCount:r,differences:l,missingMedia:m,missingLinks:e}}function Q(o,t){let n=new Map;for(let r of t)n.set(r,(n.get(r)??0)+1);let l=new Set;for(let r of o){let a=n.get(r)??0;a===0?l.add(r):n.set(r,a-1);}return [...l].sort()}function N(o){if(o.kind==="textValue")return o.value;let t=l=>o.attributes.find(r=>r.localName===l)?.value??"";return (o.localName==="fldSimple"?`[${t("instr")}]`:o.localName==="sym"?`[${t("font")} ${t("char")}]`:"")+o.children.map(N).join("")}function Z(o){let t=[],n=[],l=r=>{if(!(r.kind==="textValue"||r.localName==="p")){if(r.localName==="r"){let a=N(r);if(a==="")return;let p=r.children.find(c=>c.kind!=="textValue"&&c.localName==="rPr"),e=!p||p.kind==="textValue"||p.children.length===0&&p.attributes.length===0?"":canonicalOoxmlFingerprint(p),i=n.at(-1);i&&i.format===e?i.text+=a:n.push({format:e,text:a});return}for(let a of r.children)l(a);}};for(let r of o.children)r.kind!=="textValue"&&r.localName==="pPr"?t.push(canonicalOoxmlFingerprint(r)):l(r);return JSON.stringify([t,n.map(r=>[r.format,r.text.length])])}async function D(o){let t=readOoxmlPackage(o);if(!t.ok)throw new b$1("invalid-baseline",t.reason);let n=to(t.package.parts),l=[];for(let[m,e]of n){let i=0,c=s=>{if(s.kind!=="textValue"){if(s.localName==="p"){i+=1,l.push({part:m,index:i,text:N(s),formatting:Z(s),shown:s.kind==="paragraph"});return}for(let d of s.children)c(d);}};c(e);}let r=new Map;for(let[m,e]of [...t.package.partBytes].sort(([i],[c])=>i<c?-1:1)){if(t.package.parts.has(m)||/\.(xml|rels)$/i.test(m))continue;let i=await ro(e);r.has(i)||r.set(i,m);}let a=t.package.externalTargets.map(m=>`${m.type} ${m.rawTarget}`),p=new Map;for(let[m,e]of n)/\.rels$/i.test(m)||p.set(m,canonicalOoxmlFingerprint(e));return {paragraphs:l,media:r,links:a,parts:p}}var oo="http://schemas.openxmlformats.org/wordprocessingml/2006/main",V=new Set(["paraId","paraIdParent"]),F={moveFromRangeStart:"moveFrom",moveFromRangeEnd:"moveFrom",moveToRangeStart:"moveTo",moveToRangeEnd:"moveTo",customXmlInsRangeStart:"customXmlIns",customXmlInsRangeEnd:"customXmlIns",customXmlDelRangeStart:"customXmlDel",customXmlDelRangeEnd:"customXmlDel",customXmlMoveFromRangeStart:"customXmlMoveFrom",customXmlMoveFromRangeEnd:"customXmlMoveFrom",customXmlMoveToRangeStart:"customXmlMoveTo",customXmlMoveToRangeEnd:"customXmlMoveTo",comment:"comment",commentRangeStart:"comment",commentRangeEnd:"comment",commentReference:"comment",footnote:"footnote",footnoteReference:"footnote",endnote:"endnote",endnoteReference:"endnote",bookmarkStart:"bookmark",bookmarkEnd:"bookmark",permStart:"permission",permEnd:"permission"};function to(o){let t=new Map,n=(e,i)=>{let c=t.get(e);c||t.set(e,c=new Map);let s=c.get(i);return s===void 0&&c.set(i,s=c.size),String(s)},l=[...o.keys()].sort(),r=new Map,a=e=>{if(e.kind!=="textValue"){if(e.localName==="p"){let i=e.attributes.find(c=>c.localName==="paraId")?.value;i!==void 0&&!r.has(i)&&r.set(i,r.size);}for(let i of e.children)a(i);}};for(let e of l)a(o.get(e).root);let p=e=>{if(e.kind==="textValue")return e;let i=Object.hasOwn(F,e.localName)?F[e.localName]:null,c=e.localName==="p";return {...e,attributes:e.attributes.filter(s=>s.localName!=="textId"&&!(c&&V.has(s.localName))).map(s=>s.localName==="id"&&s.namespaceUri===oo?{...s,value:i?n(i,s.value):""}:V.has(s.localName)?{...s,value:`p${r.get(s.value)??"?"}`}:s),children:e.children.map(p)}},m=new Map;for(let e of l)m.set(e,p(o.get(e).root));return m}async function ro(o){let t=o.buffer instanceof ArrayBuffer?o:o.slice(),n=new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",t)),l="";for(let r of n)l+=r.toString(16).padStart(2,"0");return l}function eo(o,t){let n=a=>a.slice(a.indexOf(":")+1).split(".").map(Number),l=n(o),r=n(t);for(let a=0;a<Math.max(l.length,r.length);a+=1){let p=(l[a]??0)-(r[a]??0);if(p!==0)return p}return 0}var no=1,ao=1,io=20971520;
2
+ export{b as COLLABORATION_FORMAT_VERSION,io as MAX_BASELINE_BYTES,no as PROTOCOL_VERSION,ao as SCHEMA_VERSION,H as assertCollaborationFormatCompatibility,K as collaborationMigrationNeed,J as migrateCollaborationRoom,z as prepareCollaborationServerDocument,O as readCollaborationFormatVersion};
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkLUUFBXJ5_cjs=require('../chunk-LUUFBXJ5.cjs'),chunk6SR5OK66_cjs=require('../chunk-6SR5OK66.cjs'),F=require('yjs'),awareness=require('y-protocols/awareness'),yWebrtc=require('y-webrtc');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var F__namespace=/*#__PURE__*/_interopNamespace(F);var D=new WeakSet,T=(e,n)=>(e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3])>>>0,w=(e,n,i)=>{e[n]=i>>>24&255,e[n+1]=i>>>16&255,e[n+2]=i>>>8&255,e[n+3]=i&255;},B=e=>e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):null,Y=e=>new Promise(n=>{setTimeout(n,e);});function L(e,n){if(D.has(e))return;D.add(e);let i=e.send.bind(e),o=e._onChannelMessage.bind(e),d=n?.partialTimeoutMs,c=typeof d=="number"&&Number.isFinite(d)&&d>0?d:3e4,l=n?.onAbandonedMessage,f=[],s=new Map,b=false,E=1,h=t=>{let r=s.get(t);r&&(r.timer!==void 0&&clearTimeout(r.timer),s.delete(t),e.destroyed!==true&&l?.());},S=t=>{let r=s.get(t);r&&(r.timer!==void 0&&clearTimeout(r.timer),r.timer=setTimeout(()=>{h(t);},c));},u=()=>e._channel?.bufferedAmount??0,p=async()=>{let t=0;for(;u()>1048576;){if(e.destroyed===true||t>=3e4)return false;await Y(20),t+=20;}return e.destroyed!==true},I=async t=>{let r=Math.ceil(t.byteLength/16371);if(r>8192)throw new Error(`collaboration message needs ${r} chunks, above the 8192 limit`);let g=E;E=E+1>>>0||1;for(let A=0;A<r;A+=1){if(!await p())return;let y=A*16371,a=t.subarray(y,Math.min(y+16371,t.byteLength)),m=new Uint8Array(13+a.byteLength);m[0]=251,w(m,1,g),w(m,5,A),w(m,9,r),m.set(a,13),i(m);}},k=async()=>{if(!b){b=true;try{for(;f.length>0;){let t=f.shift();if(t){if(e.destroyed===!0)return;await I(t);}}}finally{b=false;}}};e.send=t=>{if(typeof t=="string"||t.byteLength<=16371){i(t);return}f.push(t),k();},e._onChannelMessage=t=>{let r=B(t.data);if(!r||r.byteLength<13||r[0]!==251){o(t);return}let g=T(r,1),A=T(r,5),y=T(r,9);if(y===0||y>8192||A>=y)return;let a=s.get(g);if(!a){if(s.size>=4){let _=s.keys().next();_.done||h(_.value);}a={chunks:new Array(y),count:y,received:0,bytes:0,timer:void 0},s.set(g,a);}if(a.count!==y||a.chunks[A])return;let m=r.subarray(13);if(a.chunks[A]=m,a.received+=1,a.bytes+=m.byteLength,a.received!==a.count){S(g);return}a.timer!==void 0&&clearTimeout(a.timer),s.delete(g);let v=new Uint8Array(a.bytes),P=0;for(let _ of a.chunks){if(!_)return;v.set(_,P),P+=_.byteLength;}e.destroyed!==true&&e.push(v);};}var W=Object.freeze(["wss://turn.0docker.com/ws"]),R=false;function H(e){e===void 0&&(R||(R=true,console.warn("[docx-editor] createWebrtcCollaboration was called without `signaling`, so it uses the public demo endpoints. They are shared, unauthenticated, and can go away. Pass your own `signaling` URLs (and TURN `iceServers`) in production, or pass `signaling: DEMO_SIGNALING_ENDPOINTS` explicitly to accept the demo endpoints.")));}function V(){R=false;}var G=/^[A-Za-z0-9_-]{24,256}$/,U="#collab=";function X(e){let n=e.password?.trim()??"";return n.length>0?n:K(e.href)}var K=e=>{let n=e??(typeof globalThis.location=="object"&&globalThis.location!==null?String(globalThis.location.href??""):"");if(n.length===0)return;let i;try{i=new URL(n).hash;}catch{return}if(!i.startsWith(U))return;let o;try{o=decodeURIComponent(i.slice(U.length));}catch{return}if(G.test(o))return o},z=(e,n)=>{Promise.resolve(e.key).then(()=>{let i=e.room;if(!i)return;let o=i.webrtcConns,d=l=>{L(l.peer,{onAbandonedMessage:n});};for(let l of o.values())d(l);let c=o.set.bind(o);o.set=(l,f)=>(d(f),c(l,f));});};async function ee(e){let n=chunkLUUFBXJ5_cjs.b(e.roomId);H(e.signaling);let i=X({password:e.password}),o=new F__namespace.Doc,d=new awareness.Awareness(o),c=null,l=()=>{},f=()=>{let u=new yWebrtc.WebrtcProvider(n,o,{awareness:d,signaling:[...e.signaling??W],...i!==void 0?{password:i}:{},...e.iceServers?{peerOpts:{config:{iceServers:e.iceServers.map(p=>({...p}))}}}:{}});return z(u,()=>l()),u},s;try{e.bootstrap.kind!=="create"&&(c=f()),s=await chunk6SR5OK66_cjs.p({ydoc:o,awareness:d,documentId:n,identity:e.identity,bootstrap:e.bootstrap,offlineEditing:e.offlineEditing}),c||(c=f());}catch(u){throw c?.destroy(),d.destroy(),o.destroy(),u}if(!c)throw s.destroy(),d.destroy(),o.destroy(),new Error("WebRTC provider did not initialize");let b=c,E=s.session;l=()=>{E.setTransportStatus("error","transport","incomplete chunk");};let h=u=>{E.setTransportStatus(u.connected?"ready":"disconnected",u.connected?void 0:"transport-disconnected",u.connected?void 0:"webrtc disconnected");};b.on("status",h);let S=false;return Object.freeze({document:s.document,session:E,ydoc:o,provider:b,destroy(){S||(S=true,b.off("status",h),s.destroy(),b.destroy(),d.destroy(),o.destroy());}})}
2
- Object.defineProperty(exports,"createCollaborationRoomId",{enumerable:true,get:function(){return chunkLUUFBXJ5_cjs.a}});Object.defineProperty(exports,"validateRoomId",{enumerable:true,get:function(){return chunkLUUFBXJ5_cjs.b}});exports.DEMO_SIGNALING_ENDPOINTS=W;exports.createWebrtcCollaboration=ee;exports.resetDemoSignalingWarningForTests=V;exports.resolveWebrtcRoomPassword=X;exports.warnOnDemoSignalingFallback=H;
1
+ 'use strict';var chunkLUUFBXJ5_cjs=require('../chunk-LUUFBXJ5.cjs'),chunkMJECUVHQ_cjs=require('../chunk-MJECUVHQ.cjs'),H=require('yjs'),awareness=require('y-protocols/awareness'),yWebrtc=require('y-webrtc');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var H__namespace=/*#__PURE__*/_interopNamespace(H);function U(e,n){let t=0,r=null,i=new Set,l=()=>{r!==null&&clearInterval(r),r=null;},o=d=>{if(d!==t){t=d,t===0&&l();for(let b of [...i])b();}},c=()=>{let d=n.room;if(d===null)return false;if(d.bcConns.size>0)return true;for(let b of d.webrtcConns.values())if(b.connected&&b.synced)return true;return false},u=()=>{t>0&&c()&&o(0);},m=(d,b)=>{b===n.room||c()||(o(t+1),r??=setInterval(u,1e3));};return e.on("update",m),n.on("peers",u),n.on("synced",u),{count:()=>t,subscribe(d){return i.add(d),()=>{i.delete(d);}},destroy(){l(),e.off("update",m),n.off("peers",u),n.off("synced",u),i.clear();}}}var x=new WeakSet,R=(e,n)=>(e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3])>>>0,C=(e,n,t)=>{e[n]=t>>>24&255,e[n+1]=t>>>16&255,e[n+2]=t>>>8&255,e[n+3]=t&255;},G=e=>e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):null,K=e=>new Promise(n=>{setTimeout(n,e);});function B(e,n){if(x.has(e))return;x.add(e);let t=e.send.bind(e),r=e._onChannelMessage.bind(e),i=n?.partialTimeoutMs,l=typeof i=="number"&&Number.isFinite(i)&&i>0?i:3e4,o=n?.onAbandonedMessage,c=n?.onDeliveredMessage,u=Math.min(n?.maxPartialBytes??1/0,134111232),m=[],d=new Map,b=false,_=1,p=0,M=(s,a)=>{a.timer!==void 0&&clearTimeout(a.timer),d.delete(s),p-=a.bytes;},S=s=>{let a=d.get(s);a&&(M(s,a),e.destroyed!==true&&(o?.(),e.destroy?.()));},y=s=>{let a=d.get(s);a&&(a.timer!==void 0&&clearTimeout(a.timer),a.timer=setTimeout(()=>{S(s);},l));},v=()=>e._channel?.bufferedAmount??0,O=async()=>{let s=0;for(;v()>1048576;){if(e.destroyed===true||s>=3e4)return false;await K(20),s+=20;}return e.destroyed!==true},N=async s=>{let a=Math.ceil(s.byteLength/16371);if(a>8192)throw new Error(`collaboration message needs ${a} chunks, above the 8192 limit`);let h=_;_=_+1>>>0||1;for(let E=0;E<a;E+=1){if(!await O()){e.destroyed!==true&&e.destroy?.();return}let A=E*16371,f=s.subarray(A,Math.min(A+16371,s.byteLength)),g=new Uint8Array(13+f.byteLength);g[0]=251,C(g,1,h),C(g,5,E),C(g,9,a),g.set(f,13),t(g);}},W=async()=>{if(!b){b=true;try{for(;m.length>0;){let s=m.shift();if(s){if(e.destroyed===!0)return;await N(s);}}}finally{b=false;}}};e.send=s=>{if(typeof s=="string"||s.byteLength<=16371){t(s);return}m.push(s),W();},e._onChannelMessage=s=>{let a=G(s.data);if(!a||a.byteLength<13||a[0]!==251){r(s);return}let h=R(a,1),E=R(a,5),A=R(a,9);if(A===0||A>8192||E>=A)return;if(a.byteLength>16384){S(h);return}let f=d.get(h);if(!f){if(d.size>=4){let T=d.keys().next();T.done||S(T.value);}f={chunks:new Array(A),count:A,received:0,bytes:0,timer:void 0},d.set(h,f);}if(f.count!==A||f.chunks[E])return;let g=a.subarray(13);if(f.chunks[E]=g,f.received+=1,f.bytes+=g.byteLength,p+=g.byteLength,p>u){S(h);return}if(f.received!==f.count){y(h);return}M(h,f);let k=new Uint8Array(f.bytes),L=0;for(let T of f.chunks){if(!T)return;k.set(T,L),L+=T.byteLength;}e.destroyed!==true&&(e.push(k),c?.());};}function F(e,n){return t=>{n()&&(t?e.setTransportStatus("ready","transport-disconnected","a peer link cannot carry large updates"):e.setTransportStatus("ready"));}}var z=3,j=6e4;function Y(e,n={set:(t,r)=>setTimeout(t,r),clear:t=>clearTimeout(t)}){let t=new Map,r=new Map,i=new Set,l=o=>{t.delete(o);let c=r.get(o);c!==void 0&&n.clear(c),r.delete(o),i.delete(o)&&i.size===0&&e(false);};return {abandoned(o){let c=(t.get(o)??0)+1;t.set(o,c);let u=r.get(o);u!==void 0&&n.clear(u),r.set(o,n.set(()=>l(o),j)),!(c<z||i.has(o))&&(i.add(o),i.size===1&&e(true));},delivered:l,reset(){for(let o of [...t.keys(),...i])l(o);},destroy(){for(let o of r.values())n.clear(o);r.clear(),t.clear(),i.clear();}}}var Z=Object.freeze(["wss://turn.0docker.com/ws"]),P=false;function J(e){e===void 0&&(P||(P=true,console.warn("[docx-editor] createWebrtcCollaboration was called without `signaling`, so it uses the public demo endpoints. They are shared, unauthenticated, and can go away. Pass your own `signaling` URLs (and TURN `iceServers`) in production, or pass `signaling: DEMO_SIGNALING_ENDPOINTS` explicitly to accept the demo endpoints.")));}function fe(){P=false;}var Q=/^[A-Za-z0-9_-]{24,256}$/,I="#collab=";function V(e){let n=e.password?.trim()??"";return n.length>0?n:ee(e.href)}var ee=e=>{let n=e??(typeof globalThis.location=="object"&&globalThis.location!==null?String(globalThis.location.href??""):"");if(n.length===0)return;let t;try{t=new URL(n).hash;}catch{return}if(!t.startsWith(I))return;let r;try{r=decodeURIComponent(t.slice(I.length));}catch{return}if(Q.test(r))return r},ne=(e,n)=>{Promise.resolve(e.key).then(()=>{let t=e.room;if(!t)return;let r=t.webrtcConns,i=(o,c)=>{B(c.peer,{onAbandonedMessage:()=>n.abandoned(o),onDeliveredMessage:()=>n.delivered(o)});};for(let[o,c]of r)i(o,c);let l=r.set.bind(r);r.set=(o,c)=>(i(o,c),l(o,c));});};async function ye(e){let n=chunkLUUFBXJ5_cjs.b(e.roomId);J(e.signaling);let t=V({password:e.password}),r=new H__namespace.Doc,i=new awareness.Awareness(r),l=null,o={abandoned(){},delivered(){}},c=()=>{let y=new yWebrtc.WebrtcProvider(n,r,{awareness:i,signaling:[...e.signaling??Z],...t!==void 0?{password:t}:{},...e.iceServers?{peerOpts:{config:{iceServers:e.iceServers.map(v=>({...v}))}}}:{}});return ne(y,{abandoned:v=>o.abandoned(v),delivered:v=>o.delivered(v)}),y},u;try{e.bootstrap.kind!=="create"&&(l=c()),u=await chunkMJECUVHQ_cjs.q({ydoc:r,awareness:i,documentId:n,identity:e.identity,bootstrap:e.bootstrap,offlineEditing:e.offlineEditing}),l||(l=c());}catch(y){throw l?.destroy(),i.destroy(),r.destroy(),y}if(!l)throw u.destroy(),i.destroy(),r.destroy(),new Error("WebRTC provider did not initialize");let m=l,d=u.session,b=true,_=Y(F(d,()=>b));o=_;let p=y=>{b=y.connected,y.connected&&_.reset(),d.setTransportStatus(y.connected?"ready":"disconnected",y.connected?void 0:"transport-disconnected",y.connected?void 0:"webrtc disconnected");};m.on("status",p);let M=U(r,m),S=false;return Object.freeze({document:u.document,session:d,ydoc:r,provider:m,unsyncedChanges:()=>M.count(),subscribeUnsyncedChanges:y=>M.subscribe(y),destroy(){S||(S=true,m.off("status",p),M.destroy(),_.destroy(),u.destroy(),m.destroy(),i.destroy(),r.destroy());}})}
2
+ Object.defineProperty(exports,"createCollaborationRoomId",{enumerable:true,get:function(){return chunkLUUFBXJ5_cjs.a}});Object.defineProperty(exports,"validateRoomId",{enumerable:true,get:function(){return chunkLUUFBXJ5_cjs.b}});exports.DEMO_SIGNALING_ENDPOINTS=Z;exports.createWebrtcCollaboration=ye;exports.resetDemoSignalingWarningForTests=fe;exports.resolveWebrtcRoomPassword=V;exports.warnOnDemoSignalingFallback=J;
@@ -1,9 +1,17 @@
1
+ /**
2
+ * Peer-to-peer convenience wrapper: one owned `y-webrtc` room over the
3
+ * full-document collaboration replica.
4
+ *
5
+ * @packageDocumentation
6
+ * @public
7
+ */
1
8
  import * as Y from 'yjs';
2
9
  import { WebrtcProvider } from 'y-webrtc';
3
10
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
4
- import { D as DocumentCollaborationHandle } from '../document-session-BKKfJzKB.cjs';
5
- import { a as CollaborationBootstrap } from '../session-B-ds4k64.cjs';
11
+ import { D as DocumentCollaborationHandle } from '../document-session-_v9vqiSX.cjs';
12
+ import { a as CollaborationBootstrap } from '../types-BQ1vBt5Q.cjs';
6
13
  export { c as createCollaborationRoomId, v as validateRoomId } from '../room-id-BfudXOZz.cjs';
14
+ import '../document-session-options-CfKypp9c.cjs';
7
15
  import 'y-protocols/awareness';
8
16
 
9
17
  /**
@@ -35,15 +43,21 @@ declare function warnOnDemoSignalingFallback(signaling: readonly string[] | unde
35
43
  declare function resetDemoSignalingWarningForTests(): void;
36
44
  /** Options for the owned WebRTC collaboration convenience wrapper. @public */
37
45
  interface CreateWebrtcCollaborationOptions {
46
+ /** The room to join: a `createCollaborationRoomId` value every participant shares. */
38
47
  readonly roomId: string;
48
+ /** Who this participant is, as peers see them. */
39
49
  readonly identity: CollaborationIdentity;
50
+ /** Create the room from a document, or join one that peers already hold. */
40
51
  readonly bootstrap: CollaborationBootstrap;
41
52
  /**
42
53
  * Admit local edits while the transport is `disconnected`. Buffered updates merge on
43
- * reconnect. See {@link CreateDocumentCollaborationOptions.offlineEditing}.
54
+ * reconnect. On by default; pass `false` to pause editing while disconnected. See
55
+ * {@link CreateDocumentCollaborationOptions.offlineEditing}.
44
56
  */
45
57
  readonly offlineEditing?: boolean;
58
+ /** Signaling server URLs that introduce peers to each other. */
46
59
  readonly signaling?: readonly string[];
60
+ /** STUN and TURN servers for the peer connections. Use TURN across restrictive networks. */
47
61
  readonly iceServers?: readonly RTCIceServer[];
48
62
  /**
49
63
  * Signaling encryption secret for `y-webrtc`.
@@ -57,8 +71,17 @@ interface CreateWebrtcCollaborationOptions {
57
71
  }
58
72
  /** Owned WebRTC provider and provider-neutral collaboration resources. @public */
59
73
  interface WebrtcCollaborationHandle extends DocumentCollaborationHandle {
74
+ /** The room's shared Yjs document, owned by this handle. */
60
75
  readonly ydoc: Y.Doc;
76
+ /** The owned `y-webrtc` provider. `destroy()` destroys it. */
61
77
  readonly provider: WebrtcProvider;
78
+ /**
79
+ * Local changes no peer has received: made while no peer was connected, and not synced
80
+ * since. A WebRTC room has no server, so these changes exist only in this browser.
81
+ */
82
+ unsyncedChanges(): number;
83
+ /** Call `listener` when `unsyncedChanges()` changes. Returns the unsubscribe function. */
84
+ subscribeUnsyncedChanges(listener: () => void): () => void;
62
85
  }
63
86
 
64
87
  /**
@@ -1,9 +1,17 @@
1
+ /**
2
+ * Peer-to-peer convenience wrapper: one owned `y-webrtc` room over the
3
+ * full-document collaboration replica.
4
+ *
5
+ * @packageDocumentation
6
+ * @public
7
+ */
1
8
  import * as Y from 'yjs';
2
9
  import { WebrtcProvider } from 'y-webrtc';
3
10
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
4
- import { D as DocumentCollaborationHandle } from '../document-session-BQ4nBDTd.js';
5
- import { a as CollaborationBootstrap } from '../session-B-ds4k64.js';
11
+ import { D as DocumentCollaborationHandle } from '../document-session-Bxs4_GgX.js';
12
+ import { a as CollaborationBootstrap } from '../types-BQ1vBt5Q.js';
6
13
  export { c as createCollaborationRoomId, v as validateRoomId } from '../room-id-BfudXOZz.js';
14
+ import '../document-session-options-DelOC7PX.js';
7
15
  import 'y-protocols/awareness';
8
16
 
9
17
  /**
@@ -35,15 +43,21 @@ declare function warnOnDemoSignalingFallback(signaling: readonly string[] | unde
35
43
  declare function resetDemoSignalingWarningForTests(): void;
36
44
  /** Options for the owned WebRTC collaboration convenience wrapper. @public */
37
45
  interface CreateWebrtcCollaborationOptions {
46
+ /** The room to join: a `createCollaborationRoomId` value every participant shares. */
38
47
  readonly roomId: string;
48
+ /** Who this participant is, as peers see them. */
39
49
  readonly identity: CollaborationIdentity;
50
+ /** Create the room from a document, or join one that peers already hold. */
40
51
  readonly bootstrap: CollaborationBootstrap;
41
52
  /**
42
53
  * Admit local edits while the transport is `disconnected`. Buffered updates merge on
43
- * reconnect. See {@link CreateDocumentCollaborationOptions.offlineEditing}.
54
+ * reconnect. On by default; pass `false` to pause editing while disconnected. See
55
+ * {@link CreateDocumentCollaborationOptions.offlineEditing}.
44
56
  */
45
57
  readonly offlineEditing?: boolean;
58
+ /** Signaling server URLs that introduce peers to each other. */
46
59
  readonly signaling?: readonly string[];
60
+ /** STUN and TURN servers for the peer connections. Use TURN across restrictive networks. */
47
61
  readonly iceServers?: readonly RTCIceServer[];
48
62
  /**
49
63
  * Signaling encryption secret for `y-webrtc`.
@@ -57,8 +71,17 @@ interface CreateWebrtcCollaborationOptions {
57
71
  }
58
72
  /** Owned WebRTC provider and provider-neutral collaboration resources. @public */
59
73
  interface WebrtcCollaborationHandle extends DocumentCollaborationHandle {
74
+ /** The room's shared Yjs document, owned by this handle. */
60
75
  readonly ydoc: Y.Doc;
76
+ /** The owned `y-webrtc` provider. `destroy()` destroys it. */
61
77
  readonly provider: WebrtcProvider;
78
+ /**
79
+ * Local changes no peer has received: made while no peer was connected, and not synced
80
+ * since. A WebRTC room has no server, so these changes exist only in this browser.
81
+ */
82
+ unsyncedChanges(): number;
83
+ /** Call `listener` when `unsyncedChanges()` changes. Returns the unsubscribe function. */
84
+ subscribeUnsyncedChanges(listener: () => void): () => void;
62
85
  }
63
86
 
64
87
  /**