@docx-editor.dev/pro 2.30.0 → 2.32.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 (75) hide show
  1. package/README.md +24 -0
  2. package/dist/chunk-3WTOHPAB.js +1 -0
  3. package/dist/chunk-AVZO5ZHZ.js +1 -0
  4. package/dist/{chunk-CNXDNDD3.js → chunk-DLYVBBO7.js} +1 -1
  5. package/dist/chunk-GAGYRL3L.js +5 -0
  6. package/dist/chunk-HMSOWKXT.js +1 -0
  7. package/dist/chunk-I6HVINA4.cjs +1 -0
  8. package/dist/chunk-MHB6ID2P.cjs +1 -0
  9. package/dist/chunk-PMS3PGOE.cjs +1 -0
  10. package/dist/{chunk-N34IUO36.cjs → chunk-RYF4SNKX.cjs} +1 -1
  11. package/dist/chunk-YOWEY5F3.cjs +5 -0
  12. package/dist/collaboration/hocuspocus.cjs +1 -1
  13. package/dist/collaboration/hocuspocus.d.cts +3 -3
  14. package/dist/collaboration/hocuspocus.d.ts +3 -3
  15. package/dist/collaboration/hocuspocus.js +1 -1
  16. package/dist/collaboration/index.cjs +2 -2
  17. package/dist/collaboration/index.d.cts +63 -7
  18. package/dist/collaboration/index.d.ts +63 -7
  19. package/dist/collaboration/index.js +2 -2
  20. package/dist/collaboration/webrtc.cjs +2 -2
  21. package/dist/collaboration/webrtc.d.cts +34 -15
  22. package/dist/collaboration/webrtc.d.ts +34 -15
  23. package/dist/collaboration/webrtc.js +2 -2
  24. package/dist/{document-session-_v9vqiSX.d.cts → document-session-B-MlORjE.d.cts} +105 -9
  25. package/dist/{document-session-Bxs4_GgX.d.ts → document-session-B-iH-YCU.d.ts} +105 -9
  26. package/dist/document-session-B35ZX2W4.js +1 -0
  27. package/dist/document-session-V3O7XBJY.cjs +1 -0
  28. package/dist/{document-session-options-DelOC7PX.d.ts → document-session-options-CdOH-TNn.d.ts} +1 -1
  29. package/dist/{document-session-options-CfKypp9c.d.cts → document-session-options-CxR0F5xT.d.cts} +1 -1
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.d.cts +2 -1
  32. package/dist/index.d.ts +2 -1
  33. package/dist/index.js +1 -1
  34. package/dist/react/hocuspocus.d.cts +2 -2
  35. package/dist/react/hocuspocus.d.ts +2 -2
  36. package/dist/react/index.cjs +2 -2
  37. package/dist/react/index.d.cts +283 -16
  38. package/dist/react/index.d.ts +283 -16
  39. package/dist/react/index.js +2 -2
  40. package/dist/react/webrtc.d.cts +9 -4
  41. package/dist/react/webrtc.d.ts +9 -4
  42. package/dist/{types-BQ1vBt5Q.d.ts → types-DvGpDOcZ.d.cts} +9 -1
  43. package/dist/{types-BQ1vBt5Q.d.cts → types-DvGpDOcZ.d.ts} +9 -1
  44. package/dist/{types-6EmrEn4n.d.cts → types-bt2k1VO0.d.cts} +9 -1
  45. package/dist/{types-6EmrEn4n.d.ts → types-bt2k1VO0.d.ts} +9 -1
  46. package/dist/vue/hocuspocus.cjs +1 -1
  47. package/dist/vue/hocuspocus.d.cts +2 -2
  48. package/dist/vue/hocuspocus.d.ts +2 -2
  49. package/dist/vue/hocuspocus.js +1 -1
  50. package/dist/vue/index.cjs +2 -2
  51. package/dist/vue/index.d.cts +285 -16
  52. package/dist/vue/index.d.ts +285 -16
  53. package/dist/vue/index.js +2 -2
  54. package/dist/vue/webrtc.cjs +1 -1
  55. package/dist/vue/webrtc.d.cts +9 -4
  56. package/dist/vue/webrtc.d.ts +9 -4
  57. package/dist/vue/webrtc.js +1 -1
  58. package/docs/accept-reject-without-scrolling.md +95 -0
  59. package/docs/comment-on-found-text.md +72 -0
  60. package/docs/custom-review-cards.md +178 -0
  61. package/docs/highlight-ranges.md +48 -0
  62. package/docs/index.md +36 -0
  63. package/docs/propose-rewrite.md +247 -0
  64. package/docs/tracked-replacement.md +68 -0
  65. package/package.json +5 -4
  66. package/dist/chunk-FD2KDBHX.cjs +0 -1
  67. package/dist/chunk-JRHEYVVY.cjs +0 -1
  68. package/dist/chunk-L567WP3J.js +0 -5
  69. package/dist/chunk-MJECUVHQ.cjs +0 -5
  70. package/dist/chunk-P2EF7WMV.js +0 -1
  71. package/dist/chunk-Q5JTCGJI.js +0 -1
  72. package/dist/chunk-SNQCYZLT.js +0 -1
  73. package/dist/chunk-ZSAAX6HV.cjs +0 -1
  74. package/dist/document-session-3VC43WNI.cjs +0 -1
  75. package/dist/document-session-J2YKWERI.js +0 -1
@@ -1 +1 @@
1
- 'use strict';var chunkZSAAX6HV_cjs=require('../chunk-ZSAAX6HV.cjs'),chunkLUUFBXJ5_cjs=require('../chunk-LUUFBXJ5.cjs'),chunkMJECUVHQ_cjs=require('../chunk-MJECUVHQ.cjs'),w=require('yjs'),awareness=require('y-protocols/awareness'),provider=require('@hocuspocus/provider'),collaboration=require('@docx-editor.dev/core/collaboration');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 w__namespace=/*#__PURE__*/_interopNamespace(w);var S=Symbol("createHocuspocusCollaboration.provider");var R=3e4,h=o=>new provider.HocuspocusProvider({url:o.url,name:o.name,document:o.document,awareness:o.awareness,...o.token!==void 0?{token:o.token}:{}});function E(o,i){return new Promise((d,t)=>{if(o.isSynced){d();return}let r=()=>{clearTimeout(s),o.off("synced",c),o.off("authenticationFailed",a);},c=()=>{r(),d();},a=n=>{r(),t(new chunkMJECUVHQ_cjs.b(collaboration.isCollaborationFailureCode(n.reason)?n.reason:"initialization-aborted",`authentication failed: ${n.reason}`));},s=setTimeout(()=>{r(),t(new chunkMJECUVHQ_cjs.b("initialization-timeout"));},i);o.on("synced",c),o.on("authenticationFailed",a);})}async function V(o){let i=chunkLUUFBXJ5_cjs.b(o.roomId),d=o[S]??h,t=new w__namespace.Doc,r=new awareness.Awareness(t),c=()=>{let e=d({url:o.url,name:i,document:t,awareness:r,...o.token!==void 0?{token:o.token}:{}});return e.on("open",()=>e.sendStateless?.(chunkZSAAX6HV_cjs.d(t))),e},a=null,s=null;try{a=c(),await E(a,o.syncedTimeoutMs??R);let e=o.bootstrap.kind==="create-or-join"&&o.bootstrap.probeTimeoutMs===void 0?{...o.bootstrap,probeTimeoutMs:0}:o.bootstrap;s=await chunkMJECUVHQ_cjs.q({ydoc:t,awareness:r,documentId:i,identity:o.identity,bootstrap:e,offlineEditing:o.offlineEditing});}catch(e){throw s?.destroy(),a?.destroy(),r.destroy(),t.destroy(),e}let n=a,u=s,l=u.session,p=e=>{l.setTransportStatus(e.status==="connected"?"ready":"disconnected",e.status==="connected"?void 0:"transport-disconnected",e.status==="connected"?void 0:"websocket disconnected");};n.on("status",p);let b=e=>{l.setTransportStatus("error",collaboration.isCollaborationFailureCode(e.reason)?e.reason:"authentication-failed");};n.on("authenticationFailed",b);let m=false,C=e=>{m||!e.event||!chunkZSAAX6HV_cjs.e(e.event)||(m=true,l.setTransportStatus("error","room-generation-changed"),n.destroy());};n.on("close",C);let g=false;return Object.freeze({document:u.document,session:l,ydoc:t,provider:n,destroy(){g||(g=true,n.off("status",p),n.off("authenticationFailed",b),n.off("close",C),u.destroy(),m||n.destroy(),r.destroy(),t.destroy());}})}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.createHocuspocusCollaboration=V;
1
+ 'use strict';var chunkMHB6ID2P_cjs=require('../chunk-MHB6ID2P.cjs'),chunkLUUFBXJ5_cjs=require('../chunk-LUUFBXJ5.cjs'),chunkYOWEY5F3_cjs=require('../chunk-YOWEY5F3.cjs'),H=require('yjs'),awareness=require('y-protocols/awareness'),provider=require('@hocuspocus/provider'),collaboration=require('@docx-editor.dev/core/collaboration');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);var S=Symbol("createHocuspocusCollaboration.provider");var E=3e4,I=o=>new provider.HocuspocusProvider({url:o.url,name:o.name,document:o.document,awareness:o.awareness,...o.token!==void 0?{token:o.token}:{}});function R(o,m,l){return new Promise((n,r)=>{if(l?.aborted){r(new chunkYOWEY5F3_cjs.b("initialization-aborted"));return}if(o.isSynced){n();return}let i=()=>{clearTimeout(u),o.off("synced",d),o.off("authenticationFailed",t),l?.removeEventListener("abort",s);},s=()=>{i(),r(new chunkYOWEY5F3_cjs.b("initialization-aborted"));},d=()=>{i(),n();},t=a=>{i(),r(new chunkYOWEY5F3_cjs.b(collaboration.isCollaborationFailureCode(a.reason)?a.reason:"initialization-aborted",`authentication failed: ${a.reason}`));},u=setTimeout(()=>{i(),r(new chunkYOWEY5F3_cjs.b("initialization-timeout"));},m);o.on("synced",d),o.on("authenticationFailed",t),l?.addEventListener("abort",s,{once:true});})}async function L(o){let m=chunkLUUFBXJ5_cjs.b(o.roomId),l=o[S]??I,n=new H__namespace.Doc,r=new awareness.Awareness(n),i=()=>{let e=l({url:o.url,name:m,document:n,awareness:r,...o.token!==void 0?{token:o.token}:{}});return e.on("open",()=>e.sendStateless?.(chunkMHB6ID2P_cjs.d(n))),e},s=null,d=null;try{if(o.bootstrap.kind!=="create"&&o.bootstrap.signal?.aborted)throw new chunkYOWEY5F3_cjs.b("initialization-aborted");s=i(),await R(s,o.syncedTimeoutMs??E,o.bootstrap.kind==="create"?void 0:o.bootstrap.signal);let e=o.bootstrap.kind==="create-or-join"&&o.bootstrap.probeTimeoutMs===void 0?{...o.bootstrap,probeTimeoutMs:0}:o.bootstrap;d=await chunkYOWEY5F3_cjs.r({ydoc:n,awareness:r,documentId:m,identity:o.identity,bootstrap:e,offlineEditing:o.offlineEditing});}catch(e){throw d?.destroy(),s?.destroy(),r.destroy(),n.destroy(),e}let t=s,u=d,a=u.session,b=e=>{a.setTransportStatus(e.status==="connected"?"ready":"disconnected",e.status==="connected"?void 0:"transport-disconnected",e.status==="connected"?void 0:"websocket disconnected");};t.on("status",b);let p=e=>{a.setTransportStatus("error",collaboration.isCollaborationFailureCode(e.reason)?e.reason:"authentication-failed",`authentication failed: ${e.reason}`);};t.on("authenticationFailed",p);let y=false,v=e=>{y||!e.event||!chunkMHB6ID2P_cjs.e(e.event)||(y=true,a.setTransportStatus("error","room-generation-changed"),t.destroy());};t.on("close",v);let g=false;return Object.freeze({document:u.document,session:a,ydoc:n,provider:t,destroy(){g||(g=true,t.off("status",b),t.off("authenticationFailed",p),t.off("close",v),u.destroy(),y||t.destroy(),r.destroy(),n.destroy());}})}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.createHocuspocusCollaboration=L;
@@ -8,10 +8,10 @@
8
8
  import * as Y from 'yjs';
9
9
  import { HocuspocusProvider } from '@hocuspocus/provider';
10
10
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
11
- import { D as DocumentCollaborationHandle } from '../document-session-_v9vqiSX.cjs';
12
- import { a as CollaborationBootstrap } from '../types-BQ1vBt5Q.cjs';
11
+ import { D as DocumentCollaborationHandle } from '../document-session-B-MlORjE.cjs';
12
+ import { a as CollaborationBootstrap } from '../types-DvGpDOcZ.cjs';
13
13
  export { c as createCollaborationRoomId, v as validateRoomId } from '../room-id-BfudXOZz.cjs';
14
- import '../document-session-options-CfKypp9c.cjs';
14
+ import '../document-session-options-CxR0F5xT.cjs';
15
15
  import 'y-protocols/awareness';
16
16
 
17
17
  /**
@@ -8,10 +8,10 @@
8
8
  import * as Y from 'yjs';
9
9
  import { HocuspocusProvider } from '@hocuspocus/provider';
10
10
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
11
- import { D as DocumentCollaborationHandle } from '../document-session-Bxs4_GgX.js';
12
- import { a as CollaborationBootstrap } from '../types-BQ1vBt5Q.js';
11
+ import { D as DocumentCollaborationHandle } from '../document-session-B-iH-YCU.js';
12
+ import { a as CollaborationBootstrap } from '../types-DvGpDOcZ.js';
13
13
  export { c as createCollaborationRoomId, v as validateRoomId } from '../room-id-BfudXOZz.js';
14
- import '../document-session-options-DelOC7PX.js';
14
+ import '../document-session-options-CdOH-TNn.js';
15
15
  import 'y-protocols/awareness';
16
16
 
17
17
  /**
@@ -1 +1 @@
1
- import {d,e}from'../chunk-SNQCYZLT.js';import {b}from'../chunk-6DEUT2RQ.js';export{a as createCollaborationRoomId,b as validateRoomId}from'../chunk-6DEUT2RQ.js';import {q,b as b$1}from'../chunk-L567WP3J.js';import*as w from'yjs';import {Awareness}from'y-protocols/awareness';import {HocuspocusProvider}from'@hocuspocus/provider';import {isCollaborationFailureCode}from'@docx-editor.dev/core/collaboration';var S=Symbol("createHocuspocusCollaboration.provider");var R=3e4,h=o=>new HocuspocusProvider({url:o.url,name:o.name,document:o.document,awareness:o.awareness,...o.token!==void 0?{token:o.token}:{}});function E(o,i){return new Promise((d,t)=>{if(o.isSynced){d();return}let r=()=>{clearTimeout(s),o.off("synced",c),o.off("authenticationFailed",a);},c=()=>{r(),d();},a=n=>{r(),t(new b$1(isCollaborationFailureCode(n.reason)?n.reason:"initialization-aborted",`authentication failed: ${n.reason}`));},s=setTimeout(()=>{r(),t(new b$1("initialization-timeout"));},i);o.on("synced",c),o.on("authenticationFailed",a);})}async function V(o){let i=b(o.roomId),d$1=o[S]??h,t=new w.Doc,r=new Awareness(t),c=()=>{let e=d$1({url:o.url,name:i,document:t,awareness:r,...o.token!==void 0?{token:o.token}:{}});return e.on("open",()=>e.sendStateless?.(d(t))),e},a=null,s=null;try{a=c(),await E(a,o.syncedTimeoutMs??R);let e=o.bootstrap.kind==="create-or-join"&&o.bootstrap.probeTimeoutMs===void 0?{...o.bootstrap,probeTimeoutMs:0}:o.bootstrap;s=await q({ydoc:t,awareness:r,documentId:i,identity:o.identity,bootstrap:e,offlineEditing:o.offlineEditing});}catch(e){throw s?.destroy(),a?.destroy(),r.destroy(),t.destroy(),e}let n=a,u=s,l=u.session,p=e=>{l.setTransportStatus(e.status==="connected"?"ready":"disconnected",e.status==="connected"?void 0:"transport-disconnected",e.status==="connected"?void 0:"websocket disconnected");};n.on("status",p);let b$1=e=>{l.setTransportStatus("error",isCollaborationFailureCode(e.reason)?e.reason:"authentication-failed");};n.on("authenticationFailed",b$1);let m=false,C=e$1=>{m||!e$1.event||!e(e$1.event)||(m=true,l.setTransportStatus("error","room-generation-changed"),n.destroy());};n.on("close",C);let g=false;return Object.freeze({document:u.document,session:l,ydoc:t,provider:n,destroy(){g||(g=true,n.off("status",p),n.off("authenticationFailed",b$1),n.off("close",C),u.destroy(),m||n.destroy(),r.destroy(),t.destroy());}})}export{V as createHocuspocusCollaboration};
1
+ import {d,e}from'../chunk-3WTOHPAB.js';import {b}from'../chunk-6DEUT2RQ.js';export{a as createCollaborationRoomId,b as validateRoomId}from'../chunk-6DEUT2RQ.js';import {b as b$1,r}from'../chunk-GAGYRL3L.js';import*as H from'yjs';import {Awareness}from'y-protocols/awareness';import {HocuspocusProvider}from'@hocuspocus/provider';import {isCollaborationFailureCode}from'@docx-editor.dev/core/collaboration';var S=Symbol("createHocuspocusCollaboration.provider");var E=3e4,I=o=>new HocuspocusProvider({url:o.url,name:o.name,document:o.document,awareness:o.awareness,...o.token!==void 0?{token:o.token}:{}});function R(o,m,l){return new Promise((n,r)=>{if(l?.aborted){r(new b$1("initialization-aborted"));return}if(o.isSynced){n();return}let i=()=>{clearTimeout(u),o.off("synced",d),o.off("authenticationFailed",t),l?.removeEventListener("abort",s);},s=()=>{i(),r(new b$1("initialization-aborted"));},d=()=>{i(),n();},t=a=>{i(),r(new b$1(isCollaborationFailureCode(a.reason)?a.reason:"initialization-aborted",`authentication failed: ${a.reason}`));},u=setTimeout(()=>{i(),r(new b$1("initialization-timeout"));},m);o.on("synced",d),o.on("authenticationFailed",t),l?.addEventListener("abort",s,{once:true});})}async function L(o){let m=b(o.roomId),l=o[S]??I,n=new H.Doc,r$1=new Awareness(n),i=()=>{let e=l({url:o.url,name:m,document:n,awareness:r$1,...o.token!==void 0?{token:o.token}:{}});return e.on("open",()=>e.sendStateless?.(d(n))),e},s=null,d$1=null;try{if(o.bootstrap.kind!=="create"&&o.bootstrap.signal?.aborted)throw new b$1("initialization-aborted");s=i(),await R(s,o.syncedTimeoutMs??E,o.bootstrap.kind==="create"?void 0:o.bootstrap.signal);let e=o.bootstrap.kind==="create-or-join"&&o.bootstrap.probeTimeoutMs===void 0?{...o.bootstrap,probeTimeoutMs:0}:o.bootstrap;d$1=await r({ydoc:n,awareness:r$1,documentId:m,identity:o.identity,bootstrap:e,offlineEditing:o.offlineEditing});}catch(e){throw d$1?.destroy(),s?.destroy(),r$1.destroy(),n.destroy(),e}let t=s,u=d$1,a=u.session,b$2=e=>{a.setTransportStatus(e.status==="connected"?"ready":"disconnected",e.status==="connected"?void 0:"transport-disconnected",e.status==="connected"?void 0:"websocket disconnected");};t.on("status",b$2);let p=e=>{a.setTransportStatus("error",isCollaborationFailureCode(e.reason)?e.reason:"authentication-failed",`authentication failed: ${e.reason}`);};t.on("authenticationFailed",p);let y=false,v=e$1=>{y||!e$1.event||!e(e$1.event)||(y=true,a.setTransportStatus("error","room-generation-changed"),t.destroy());};t.on("close",v);let g=false;return Object.freeze({document:u.document,session:a,ydoc:n,provider:t,destroy(){g||(g=true,t.off("status",b$2),t.off("authenticationFailed",p),t.off("close",v),u.destroy(),y||t.destroy(),r$1.destroy(),n.destroy());}})}export{L as createHocuspocusCollaboration};
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkZSAAX6HV_cjs=require('../chunk-ZSAAX6HV.cjs'),chunkMJECUVHQ_cjs=require('../chunk-MJECUVHQ.cjs'),chunkQLZH2Q2C_cjs=require('../chunk-QLZH2Q2C.cjs'),C=require('yjs'),store=require('@docx-editor.dev/core/store');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 C__namespace=/*#__PURE__*/_interopNamespace(C);function z(o){return chunkMJECUVHQ_cjs.a(o)}var A=["protocolVersion","sharedSchemaVersion","repairVersion","canonicalModelVersion"];function E(o){return `docx-collaboration:${o.join(".")}`}var b=E(A.map(o=>chunkMJECUVHQ_cjs.c[o]));function H(o){if(o!==b)throw new chunkMJECUVHQ_cjs.b("collaboration-format-mismatch","The collaboration format version is missing or incompatible with this deployment.")}function O(o){if(!o.share.has(chunkMJECUVHQ_cjs.e))throw new chunkMJECUVHQ_cjs.b("not-initialized");let t;try{t=o.getMap(chunkMJECUVHQ_cjs.e);}catch{throw new chunkMJECUVHQ_cjs.b("collaboration-format-mismatch","The saved room has invalid collaboration version information.")}if(t.get("initialized")!==true||typeof t.get("documentId")!="string")throw new chunkMJECUVHQ_cjs.b("not-initialized");let n=A.map(l=>{let r=t.get(l);if(typeof r!="number"||!Number.isSafeInteger(r)||r<0)throw new chunkMJECUVHQ_cjs.b("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){let t=k(o.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.documentId??t.documentId;if(typeof l!="string")throw new chunkMJECUVHQ_cjs.b("invalid-document-id","The earlier room holds no document ID. Pass the ID its clients use as documentId.");let r=chunkMJECUVHQ_cjs.h(l),a=await chunkZSAAX6HV_cjs.c(o.exported,r),p=k(a,i=>chunkMJECUVHQ_cjs.o(i)),m=await D(o.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__namespace.Doc;try{try{C__namespace.applyUpdate(n,o);}catch{throw new chunkMJECUVHQ_cjs.b("invalid-baseline","The bytes are not room state.")}return t(n)}finally{n.destroy();}}function W(o){try{return o.getMap(chunkMJECUVHQ_cjs.e).get("documentId")}catch{return}}function _(o){try{return O(o)}catch(t){if(t instanceof chunkMJECUVHQ_cjs.b&&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?"":store.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(store.canonicalOoxmlFingerprint(r)):l(r);return JSON.stringify([t,n.map(r=>[r.format,r.text.length])])}async function D(o){let t=store.readOoxmlPackage(o);if(!t.ok)throw new chunkMJECUVHQ_cjs.b("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,store.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
- Object.defineProperty(exports,"checkCollaborationRoomGeneration",{enumerable:true,get:function(){return chunkZSAAX6HV_cjs.f}});Object.defineProperty(exports,"compactCollaborationState",{enumerable:true,get:function(){return chunkZSAAX6HV_cjs.b}});Object.defineProperty(exports,"readCollaborationRoomGeneration",{enumerable:true,get:function(){return chunkZSAAX6HV_cjs.a}});Object.defineProperty(exports,"CollaborationSchemaError",{enumerable:true,get:function(){return chunkMJECUVHQ_cjs.b}});Object.defineProperty(exports,"DOCUMENT_COLLABORATION_VERSIONS",{enumerable:true,get:function(){return chunkMJECUVHQ_cjs.c}});Object.defineProperty(exports,"assertDocumentCollaborationCompatibility",{enumerable:true,get:function(){return chunkMJECUVHQ_cjs.d}});Object.defineProperty(exports,"createDocumentCollaboration",{enumerable:true,get:function(){return chunkMJECUVHQ_cjs.q}});Object.defineProperty(exports,"readCollaborationDocument",{enumerable:true,get:function(){return chunkMJECUVHQ_cjs.o}});Object.defineProperty(exports,"readCollaborationResourceUsage",{enumerable:true,get:function(){return chunkMJECUVHQ_cjs.n}});Object.defineProperty(exports,"collaborationModule",{enumerable:true,get:function(){return chunkQLZH2Q2C_cjs.b}});exports.COLLABORATION_FORMAT_VERSION=b;exports.MAX_BASELINE_BYTES=io;exports.PROTOCOL_VERSION=no;exports.SCHEMA_VERSION=ao;exports.assertCollaborationFormatCompatibility=H;exports.collaborationMigrationNeed=K;exports.migrateCollaborationRoom=J;exports.prepareCollaborationServerDocument=z;exports.readCollaborationFormatVersion=O;
1
+ 'use strict';var chunkMHB6ID2P_cjs=require('../chunk-MHB6ID2P.cjs'),chunkYOWEY5F3_cjs=require('../chunk-YOWEY5F3.cjs'),chunkQLZH2Q2C_cjs=require('../chunk-QLZH2Q2C.cjs'),O=require('yjs'),store=require('@docx-editor.dev/core/store');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 O__namespace=/*#__PURE__*/_interopNamespace(O);var j=1,K=1,M=20971520;function J(o){return chunkYOWEY5F3_cjs.a(o)}async function W(o,t){let n=chunkYOWEY5F3_cjs.h(t.documentId),a=t.maxBytes??20971520;if(!Number.isSafeInteger(a)||a<=0||a>20971520)throw new TypeError(`maxBytes must be a whole number of bytes from 1 to ${20971520}`);return chunkMHB6ID2P_cjs.c(o,n,a)}var A=["protocolVersion","sharedSchemaVersion","repairVersion","canonicalModelVersion"];function T(o){return `docx-collaboration:${o.join(".")}`}var b=T(A.map(o=>chunkYOWEY5F3_cjs.c[o]));function q(o){if(o!==b)throw new chunkYOWEY5F3_cjs.b("collaboration-format-mismatch","The collaboration format version is missing or incompatible with this deployment.")}function R(o){if(!o.share.has(chunkYOWEY5F3_cjs.e))throw new chunkYOWEY5F3_cjs.b("not-initialized");let t;try{t=o.getMap(chunkYOWEY5F3_cjs.e);}catch{throw new chunkYOWEY5F3_cjs.b("collaboration-format-mismatch","The saved room has invalid collaboration version information.")}if(t.get("initialized")!==true||typeof t.get("documentId")!="string")throw new chunkYOWEY5F3_cjs.b("not-initialized");let n=A.map(a=>{let r=t.get(a);if(typeof r!="number"||!Number.isSafeInteger(r)||r<0)throw new chunkYOWEY5F3_cjs.b("collaboration-format-mismatch","The saved room has missing or invalid collaboration version information.");return r});return T(n)}function Z(o){return w(o,t=>U(P(t)))}async function oo(o){let t=w(o.state,l=>({format:P(l),documentId:to(l)})),n=U(t.format);if(n==="current")return {ok:false,reason:"current"};if(n==="later-format")return {ok:false,reason:"later-format"};let a=o.documentId??t.documentId;if(typeof a!="string")throw new chunkYOWEY5F3_cjs.b("invalid-document-id","The earlier room holds no document ID. Pass the ID its clients use as documentId.");let r=chunkYOWEY5F3_cjs.h(a),i=await chunkMHB6ID2P_cjs.c(o.exported,r),p=w(i,l=>chunkYOWEY5F3_cjs.p(l)),m=await _(o.exported),e=ro(m,await _(p),{from:t.format??"unversioned",to:b,documentId:r});return e.ok?{ok:true,state:i,report:e}:{ok:false,reason:"check-failed",report:e}}function w(o,t){let n=new O__namespace.Doc;try{try{O__namespace.applyUpdate(n,o);}catch{throw new chunkYOWEY5F3_cjs.b("invalid-baseline","The bytes are not room state.")}return t(n)}finally{n.destroy();}}function to(o){try{return o.getMap(chunkYOWEY5F3_cjs.e).get("documentId")}catch{return}}function P(o){try{return R(o)}catch(t){if(t instanceof chunkYOWEY5F3_cjs.b&&t.code==="collaboration-format-mismatch")return null;throw t}}function U(o){if(o===null)return "earlier-format";let t=so(o,b);return t===0?"current":t<0?"earlier-format":"later-format"}var D=20;function ro(o,t,n){let a=[],r=0,i=new Set;o.paragraphs.length!==t.paragraphs.length&&i.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")&&i.add(y),r+=1,a.length>=D))continue;let v=g??u;a.push({part:v.part,paragraph:v.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&&i.add("media");let e=eo(o.links,t.links);e.length>0&&i.add("links");let l=[...new Set([...o.parts.keys(),...t.parts.keys()])].filter(d=>o.parts.get(d)!==t.parts.get(d)).sort();l.length>0&&i.add("structure");let c=t.paragraphs.filter(d=>!d.shown),s=["paragraphs","text","formatting","structure","media","links"];return {ok:i.size===0,failed:s.filter(d=>i.has(d)),from:n.from,to:n.to,documentId:n.documentId,paragraphs:o.paragraphs.length,hidden:c.length,hiddenAt:c.slice(0,D).map(d=>({part:d.part,paragraph:d.index})),changedParts:l,differenceCount:r,differences:a,missingMedia:m,missingLinks:e}}function eo(o,t){let n=new Map;for(let r of t)n.set(r,(n.get(r)??0)+1);let a=new Set;for(let r of o){let i=n.get(r)??0;i===0?a.add(r):n.set(r,i-1);}return [...a].sort()}function I(o){if(o.kind==="textValue")return o.value;let t=a=>o.attributes.find(r=>r.localName===a)?.value??"";return (o.localName==="fldSimple"?`[${t("instr")}]`:o.localName==="sym"?`[${t("font")} ${t("char")}]`:"")+o.children.map(I).join("")}function no(o){let t=[],n=[],a=r=>{if(!(r.kind==="textValue"||r.localName==="p")){if(r.localName==="r"){let i=I(r);if(i==="")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?"":store.canonicalOoxmlFingerprint(p),l=n.at(-1);l&&l.format===e?l.text+=i:n.push({format:e,text:i});return}for(let i of r.children)a(i);}};for(let r of o.children)r.kind!=="textValue"&&r.localName==="pPr"?t.push(store.canonicalOoxmlFingerprint(r)):a(r);return JSON.stringify([t,n.map(r=>[r.format,r.text.length])])}async function _(o){let t=store.readOoxmlPackage(o);if(!t.ok)throw new chunkYOWEY5F3_cjs.b("invalid-baseline",t.reason);let n=io(t.package.parts),a=[];for(let[m,e]of n){let l=0,c=s=>{if(s.kind!=="textValue"){if(s.localName==="p"){l+=1,a.push({part:m,index:l,text:I(s),formatting:no(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(([l],[c])=>l<c?-1:1)){if(t.package.parts.has(m)||/\.(xml|rels)$/i.test(m))continue;let l=await lo(e);r.has(l)||r.set(l,m);}let i=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,store.canonicalOoxmlFingerprint(e));return {paragraphs:a,media:r,links:i,parts:p}}var ao="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 io(o){let t=new Map,n=(e,l)=>{let c=t.get(e);c||t.set(e,c=new Map);let s=c.get(l);return s===void 0&&c.set(l,s=c.size),String(s)},a=[...o.keys()].sort(),r=new Map,i=e=>{if(e.kind!=="textValue"){if(e.localName==="p"){let l=e.attributes.find(c=>c.localName==="paraId")?.value;l!==void 0&&!r.has(l)&&r.set(l,r.size);}for(let l of e.children)i(l);}};for(let e of a)i(o.get(e).root);let p=e=>{if(e.kind==="textValue")return e;let l=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===ao?{...s,value:l?n(l,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 a)m.set(e,p(o.get(e).root));return m}async function lo(o){let t=o.buffer instanceof ArrayBuffer?o:o.slice(),n=new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",t)),a="";for(let r of n)a+=r.toString(16).padStart(2,"0");return a}function so(o,t){let n=i=>i.slice(i.indexOf(":")+1).split(".").map(Number),a=n(o),r=n(t);for(let i=0;i<Math.max(a.length,r.length);i+=1){let p=(a[i]??0)-(r[i]??0);if(p!==0)return p}return 0}
2
+ Object.defineProperty(exports,"checkCollaborationRoomGeneration",{enumerable:true,get:function(){return chunkMHB6ID2P_cjs.f}});Object.defineProperty(exports,"compactCollaborationState",{enumerable:true,get:function(){return chunkMHB6ID2P_cjs.b}});Object.defineProperty(exports,"readCollaborationRoomGeneration",{enumerable:true,get:function(){return chunkMHB6ID2P_cjs.a}});Object.defineProperty(exports,"CollaborationSchemaError",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.b}});Object.defineProperty(exports,"CollaborationUndoGroupError",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.o}});Object.defineProperty(exports,"DOCUMENT_COLLABORATION_VERSIONS",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.c}});Object.defineProperty(exports,"assertDocumentCollaborationCompatibility",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.d}});Object.defineProperty(exports,"createDocumentCollaboration",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.r}});Object.defineProperty(exports,"readCollaborationDocument",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.p}});Object.defineProperty(exports,"readCollaborationResourceUsage",{enumerable:true,get:function(){return chunkYOWEY5F3_cjs.n}});Object.defineProperty(exports,"collaborationModule",{enumerable:true,get:function(){return chunkQLZH2Q2C_cjs.b}});exports.COLLABORATION_FORMAT_VERSION=b;exports.MAX_BASELINE_BYTES=M;exports.PROTOCOL_VERSION=j;exports.SCHEMA_VERSION=K;exports.assertCollaborationFormatCompatibility=q;exports.collaborationMigrationNeed=Z;exports.createCollaborationState=W;exports.migrateCollaborationRoom=oo;exports.prepareCollaborationServerDocument=J;exports.readCollaborationFormatVersion=R;
@@ -9,11 +9,11 @@
9
9
  * @public
10
10
  */
11
11
  export { C as CollaborationModuleOptions, c as collaborationModule } from '../collaboration-module-DWn2heE1.cjs';
12
- export { a as CollaborationBootstrap, c as CollaborationHandle, b as CollaborationIdentityUpdate, C as CollaborationSession } from '../types-BQ1vBt5Q.cjs';
13
- export { C as CollaborationResourceUsage, D as DocumentCollaborationHandle, a as DocumentCollaborationSession, c as createDocumentCollaboration, r as readCollaborationResourceUsage } from '../document-session-_v9vqiSX.cjs';
12
+ export { a as CollaborationBootstrap, c as CollaborationHandle, b as CollaborationIdentityUpdate, C as CollaborationSession } from '../types-DvGpDOcZ.cjs';
13
+ export { C as CollaborationResourceUsage, a as CollaborationUndoGroup, b as CollaborationUndoGroupError, c as CollaborationUndoGroupErrorCode, D as DocumentCollaborationHandle, d as DocumentCollaborationSession, e as createDocumentCollaboration, r as readCollaborationResourceUsage } from '../document-session-B-MlORjE.cjs';
14
14
  import * as Y from 'yjs';
15
15
  import { CollaborationFailureCode, EditorCollaborationSession } from '@docx-editor.dev/core/collaboration';
16
- export { C as CreateDocumentCollaborationOptions } from '../document-session-options-CfKypp9c.cjs';
16
+ export { C as CreateDocumentCollaborationOptions } from '../document-session-options-CxR0F5xT.cjs';
17
17
  import '@docx-editor.dev/core/editor';
18
18
  import 'y-protocols/awareness';
19
19
 
@@ -111,6 +111,61 @@ declare function readCollaborationDocument(ydoc: Y.Doc): Uint8Array;
111
111
  * @public
112
112
  */
113
113
  declare function prepareCollaborationServerDocument(document: Y.Doc): () => void;
114
+ /** Options for {@link createCollaborationState}. @public */
115
+ interface CreateCollaborationStateOptions {
116
+ /**
117
+ * The room's document ID. Participants must use the same ID. With Hocuspocus it is the room
118
+ * name, the `documentName` of the server hooks.
119
+ */
120
+ readonly documentId: string;
121
+ /**
122
+ * Refuse a file whose size, or whose expanded package size, is over this many bytes, with
123
+ * `baseline-too-large`. The check runs before any part is parsed. Default and maximum
124
+ * `MAX_BASELINE_BYTES` (20 MiB). A value that is not a whole number in that range throws
125
+ * `TypeError`.
126
+ */
127
+ readonly maxBytes?: number;
128
+ }
129
+ /**
130
+ * Build the state of a new room from a `.docx` file, on a server.
131
+ *
132
+ * @remarks
133
+ * Call it only for a room that your application knows is new, for example from a durable
134
+ * record that it writes when it creates the room. Store the result with a create-only write
135
+ * before any participant syncs, then apply it to the room document with `Y.applyUpdate`.
136
+ * Participants find the room seeded and join it with a `join` or `create-or-join` bootstrap.
137
+ * No participant uploads the document, and none receives its own seed back.
138
+ *
139
+ * Do not seed a known room whose stored state is missing. A second seed replaces the room's
140
+ * content with the original file, and every edit made since is gone from the room. Refuse the
141
+ * room instead, for example with `saved-room-unavailable`: participants keep their copies, and
142
+ * you can restore the stored state. As a last defense, each seed carries a new room generation
143
+ * ID, so `checkCollaborationRoomGeneration` refuses a participant that holds the earlier state
144
+ * with `room-generation-changed` instead of merging a second copy of the document.
145
+ *
146
+ * Hocuspocus does not call `onStoreDocument` for state applied while it loads a room, so store
147
+ * the result yourself. Hocuspocus also holds back an update smaller than `flushMaxBytes` and
148
+ * then sends it to every connection, the first participant included, which would receive the
149
+ * room twice. Call `document.flush()` in `afterLoadDocument`, before the first participant joins.
150
+ *
151
+ * The work is synchronous for most of its run. Measured on a laptop, 4.4 MiB of expanded XML
152
+ * (10,000 paragraphs) took 5.2 s, held the event loop for up to 210 ms at a time, and used
153
+ * several hundred MiB of memory. Set `maxBytes` for the documents you accept, and seed in a
154
+ * worker thread or a job queue with a small concurrency limit, not on the thread that serves
155
+ * rooms.
156
+ *
157
+ * Throws `CollaborationSchemaError`: `baseline-too-large` for a file over `maxBytes`,
158
+ * `invalid-baseline` for a file that is not a usable `.docx` package, and
159
+ * `invalid-document-id` for a document ID that is empty or longer than 256 characters.
160
+ * Throws `TypeError` for a `maxBytes` that is not a whole number from 1 to
161
+ * `MAX_BASELINE_BYTES`.
162
+ *
163
+ * @param document - The `.docx` bytes the room starts from.
164
+ * @param options - The room's document ID and size limit.
165
+ * @returns The room's Yjs state, as one update.
166
+ * @public
167
+ */
168
+ declare function createCollaborationState(document: Uint8Array, options: CreateCollaborationStateOptions): Promise<Uint8Array>;
114
169
 
115
170
  /**
116
171
  * Room compaction by generation.
@@ -128,8 +183,9 @@ declare function prepareCollaborationServerDocument(document: Y.Doc): () => void
128
183
  */
129
184
 
130
185
  /**
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.
186
+ * The generation ID of the room a document holds. It is empty for a room that a participant
187
+ * seeded and nobody compacted since, and for a document that holds no room yet. A room that
188
+ * `createCollaborationState` or `compactCollaborationState` built has one.
133
189
  *
134
190
  * @public
135
191
  */
@@ -447,5 +503,5 @@ interface TextCollaborationSession extends EditorCollaborationSession {
447
503
  setTransportStatus(status: 'ready' | 'disconnected' | 'error', reason?: CollaborationFailureCode, detail?: string): void;
448
504
  }
449
505
 
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 };
506
+ export { COLLABORATION_FORMAT_VERSION, CollaborationSchemaError, DOCUMENT_COLLABORATION_VERSIONS, MAX_BASELINE_BYTES, PROTOCOL_VERSION, SCHEMA_VERSION, assertCollaborationFormatCompatibility, assertDocumentCollaborationCompatibility, checkCollaborationRoomGeneration, collaborationMigrationNeed, compactCollaborationState, createCollaborationState, migrateCollaborationRoom, prepareCollaborationServerDocument, readCollaborationDocument, readCollaborationFormatVersion, readCollaborationRoomGeneration };
507
+ export type { CollaborationMigration, CollaborationMigrationCheck, CollaborationMigrationDifference, CollaborationMigrationNeed, CollaborationMigrationPosition, CollaborationMigrationReport, CollaborationRoomGatePayload, CompactCollaborationStateOptions, CreateCollaborationStateOptions, DocumentCollaborationVersions, MigrateCollaborationRoomOptions, TextCollaborationSession };
@@ -9,11 +9,11 @@
9
9
  * @public
10
10
  */
11
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';
12
+ export { a as CollaborationBootstrap, c as CollaborationHandle, b as CollaborationIdentityUpdate, C as CollaborationSession } from '../types-DvGpDOcZ.js';
13
+ export { C as CollaborationResourceUsage, a as CollaborationUndoGroup, b as CollaborationUndoGroupError, c as CollaborationUndoGroupErrorCode, D as DocumentCollaborationHandle, d as DocumentCollaborationSession, e as createDocumentCollaboration, r as readCollaborationResourceUsage } from '../document-session-B-iH-YCU.js';
14
14
  import * as Y from 'yjs';
15
15
  import { CollaborationFailureCode, EditorCollaborationSession } from '@docx-editor.dev/core/collaboration';
16
- export { C as CreateDocumentCollaborationOptions } from '../document-session-options-DelOC7PX.js';
16
+ export { C as CreateDocumentCollaborationOptions } from '../document-session-options-CdOH-TNn.js';
17
17
  import '@docx-editor.dev/core/editor';
18
18
  import 'y-protocols/awareness';
19
19
 
@@ -111,6 +111,61 @@ declare function readCollaborationDocument(ydoc: Y.Doc): Uint8Array;
111
111
  * @public
112
112
  */
113
113
  declare function prepareCollaborationServerDocument(document: Y.Doc): () => void;
114
+ /** Options for {@link createCollaborationState}. @public */
115
+ interface CreateCollaborationStateOptions {
116
+ /**
117
+ * The room's document ID. Participants must use the same ID. With Hocuspocus it is the room
118
+ * name, the `documentName` of the server hooks.
119
+ */
120
+ readonly documentId: string;
121
+ /**
122
+ * Refuse a file whose size, or whose expanded package size, is over this many bytes, with
123
+ * `baseline-too-large`. The check runs before any part is parsed. Default and maximum
124
+ * `MAX_BASELINE_BYTES` (20 MiB). A value that is not a whole number in that range throws
125
+ * `TypeError`.
126
+ */
127
+ readonly maxBytes?: number;
128
+ }
129
+ /**
130
+ * Build the state of a new room from a `.docx` file, on a server.
131
+ *
132
+ * @remarks
133
+ * Call it only for a room that your application knows is new, for example from a durable
134
+ * record that it writes when it creates the room. Store the result with a create-only write
135
+ * before any participant syncs, then apply it to the room document with `Y.applyUpdate`.
136
+ * Participants find the room seeded and join it with a `join` or `create-or-join` bootstrap.
137
+ * No participant uploads the document, and none receives its own seed back.
138
+ *
139
+ * Do not seed a known room whose stored state is missing. A second seed replaces the room's
140
+ * content with the original file, and every edit made since is gone from the room. Refuse the
141
+ * room instead, for example with `saved-room-unavailable`: participants keep their copies, and
142
+ * you can restore the stored state. As a last defense, each seed carries a new room generation
143
+ * ID, so `checkCollaborationRoomGeneration` refuses a participant that holds the earlier state
144
+ * with `room-generation-changed` instead of merging a second copy of the document.
145
+ *
146
+ * Hocuspocus does not call `onStoreDocument` for state applied while it loads a room, so store
147
+ * the result yourself. Hocuspocus also holds back an update smaller than `flushMaxBytes` and
148
+ * then sends it to every connection, the first participant included, which would receive the
149
+ * room twice. Call `document.flush()` in `afterLoadDocument`, before the first participant joins.
150
+ *
151
+ * The work is synchronous for most of its run. Measured on a laptop, 4.4 MiB of expanded XML
152
+ * (10,000 paragraphs) took 5.2 s, held the event loop for up to 210 ms at a time, and used
153
+ * several hundred MiB of memory. Set `maxBytes` for the documents you accept, and seed in a
154
+ * worker thread or a job queue with a small concurrency limit, not on the thread that serves
155
+ * rooms.
156
+ *
157
+ * Throws `CollaborationSchemaError`: `baseline-too-large` for a file over `maxBytes`,
158
+ * `invalid-baseline` for a file that is not a usable `.docx` package, and
159
+ * `invalid-document-id` for a document ID that is empty or longer than 256 characters.
160
+ * Throws `TypeError` for a `maxBytes` that is not a whole number from 1 to
161
+ * `MAX_BASELINE_BYTES`.
162
+ *
163
+ * @param document - The `.docx` bytes the room starts from.
164
+ * @param options - The room's document ID and size limit.
165
+ * @returns The room's Yjs state, as one update.
166
+ * @public
167
+ */
168
+ declare function createCollaborationState(document: Uint8Array, options: CreateCollaborationStateOptions): Promise<Uint8Array>;
114
169
 
115
170
  /**
116
171
  * Room compaction by generation.
@@ -128,8 +183,9 @@ declare function prepareCollaborationServerDocument(document: Y.Doc): () => void
128
183
  */
129
184
 
130
185
  /**
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.
186
+ * The generation ID of the room a document holds. It is empty for a room that a participant
187
+ * seeded and nobody compacted since, and for a document that holds no room yet. A room that
188
+ * `createCollaborationState` or `compactCollaborationState` built has one.
133
189
  *
134
190
  * @public
135
191
  */
@@ -447,5 +503,5 @@ interface TextCollaborationSession extends EditorCollaborationSession {
447
503
  setTransportStatus(status: 'ready' | 'disconnected' | 'error', reason?: CollaborationFailureCode, detail?: string): void;
448
504
  }
449
505
 
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 };
506
+ export { COLLABORATION_FORMAT_VERSION, CollaborationSchemaError, DOCUMENT_COLLABORATION_VERSIONS, MAX_BASELINE_BYTES, PROTOCOL_VERSION, SCHEMA_VERSION, assertCollaborationFormatCompatibility, assertDocumentCollaborationCompatibility, checkCollaborationRoomGeneration, collaborationMigrationNeed, compactCollaborationState, createCollaborationState, migrateCollaborationRoom, prepareCollaborationServerDocument, readCollaborationDocument, readCollaborationFormatVersion, readCollaborationRoomGeneration };
507
+ export type { CollaborationMigration, CollaborationMigrationCheck, CollaborationMigrationDifference, CollaborationMigrationNeed, CollaborationMigrationPosition, CollaborationMigrationReport, CollaborationRoomGatePayload, CompactCollaborationStateOptions, CreateCollaborationStateOptions, DocumentCollaborationVersions, MigrateCollaborationRoomOptions, TextCollaborationSession };
@@ -1,2 +1,2 @@
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
+ import {c as c$1}from'../chunk-3WTOHPAB.js';export{f as checkCollaborationRoomGeneration,b as compactCollaborationState,a as readCollaborationRoomGeneration}from'../chunk-3WTOHPAB.js';import {c,a,h,b as b$1,e,p}from'../chunk-GAGYRL3L.js';export{b as CollaborationSchemaError,o as CollaborationUndoGroupError,c as DOCUMENT_COLLABORATION_VERSIONS,d as assertDocumentCollaborationCompatibility,r as createDocumentCollaboration,p as readCollaborationDocument,n as readCollaborationResourceUsage}from'../chunk-GAGYRL3L.js';export{b as collaborationModule}from'../chunk-Q2VBO66F.js';import*as O from'yjs';import {readOoxmlPackage,canonicalOoxmlFingerprint}from'@docx-editor.dev/core/store';var j=1,K=1,M=20971520;function J(o){return a(o)}async function W(o,t){let n=h(t.documentId),a=t.maxBytes??20971520;if(!Number.isSafeInteger(a)||a<=0||a>20971520)throw new TypeError(`maxBytes must be a whole number of bytes from 1 to ${20971520}`);return c$1(o,n,a)}var A=["protocolVersion","sharedSchemaVersion","repairVersion","canonicalModelVersion"];function T(o){return `docx-collaboration:${o.join(".")}`}var b=T(A.map(o=>c[o]));function q(o){if(o!==b)throw new b$1("collaboration-format-mismatch","The collaboration format version is missing or incompatible with this deployment.")}function R(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(a=>{let r=t.get(a);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 T(n)}function Z(o){return w(o,t=>U(P(t)))}async function oo(o){let t=w(o.state,l=>({format:P(l),documentId:to(l)})),n=U(t.format);if(n==="current")return {ok:false,reason:"current"};if(n==="later-format")return {ok:false,reason:"later-format"};let a=o.documentId??t.documentId;if(typeof a!="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(a),i=await c$1(o.exported,r),p$1=w(i,l=>p(l)),m=await _(o.exported),e=ro(m,await _(p$1),{from:t.format??"unversioned",to:b,documentId:r});return e.ok?{ok:true,state:i,report:e}:{ok:false,reason:"check-failed",report:e}}function w(o,t){let n=new O.Doc;try{try{O.applyUpdate(n,o);}catch{throw new b$1("invalid-baseline","The bytes are not room state.")}return t(n)}finally{n.destroy();}}function to(o){try{return o.getMap(e).get("documentId")}catch{return}}function P(o){try{return R(o)}catch(t){if(t instanceof b$1&&t.code==="collaboration-format-mismatch")return null;throw t}}function U(o){if(o===null)return "earlier-format";let t=so(o,b);return t===0?"current":t<0?"earlier-format":"later-format"}var D=20;function ro(o,t,n){let a=[],r=0,i=new Set;o.paragraphs.length!==t.paragraphs.length&&i.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")&&i.add(y),r+=1,a.length>=D))continue;let v=g??u;a.push({part:v.part,paragraph:v.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&&i.add("media");let e=eo(o.links,t.links);e.length>0&&i.add("links");let l=[...new Set([...o.parts.keys(),...t.parts.keys()])].filter(d=>o.parts.get(d)!==t.parts.get(d)).sort();l.length>0&&i.add("structure");let c=t.paragraphs.filter(d=>!d.shown),s=["paragraphs","text","formatting","structure","media","links"];return {ok:i.size===0,failed:s.filter(d=>i.has(d)),from:n.from,to:n.to,documentId:n.documentId,paragraphs:o.paragraphs.length,hidden:c.length,hiddenAt:c.slice(0,D).map(d=>({part:d.part,paragraph:d.index})),changedParts:l,differenceCount:r,differences:a,missingMedia:m,missingLinks:e}}function eo(o,t){let n=new Map;for(let r of t)n.set(r,(n.get(r)??0)+1);let a=new Set;for(let r of o){let i=n.get(r)??0;i===0?a.add(r):n.set(r,i-1);}return [...a].sort()}function I(o){if(o.kind==="textValue")return o.value;let t=a=>o.attributes.find(r=>r.localName===a)?.value??"";return (o.localName==="fldSimple"?`[${t("instr")}]`:o.localName==="sym"?`[${t("font")} ${t("char")}]`:"")+o.children.map(I).join("")}function no(o){let t=[],n=[],a=r=>{if(!(r.kind==="textValue"||r.localName==="p")){if(r.localName==="r"){let i=I(r);if(i==="")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),l=n.at(-1);l&&l.format===e?l.text+=i:n.push({format:e,text:i});return}for(let i of r.children)a(i);}};for(let r of o.children)r.kind!=="textValue"&&r.localName==="pPr"?t.push(canonicalOoxmlFingerprint(r)):a(r);return JSON.stringify([t,n.map(r=>[r.format,r.text.length])])}async function _(o){let t=readOoxmlPackage(o);if(!t.ok)throw new b$1("invalid-baseline",t.reason);let n=io(t.package.parts),a=[];for(let[m,e]of n){let l=0,c=s=>{if(s.kind!=="textValue"){if(s.localName==="p"){l+=1,a.push({part:m,index:l,text:I(s),formatting:no(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(([l],[c])=>l<c?-1:1)){if(t.package.parts.has(m)||/\.(xml|rels)$/i.test(m))continue;let l=await lo(e);r.has(l)||r.set(l,m);}let i=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:a,media:r,links:i,parts:p}}var ao="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 io(o){let t=new Map,n=(e,l)=>{let c=t.get(e);c||t.set(e,c=new Map);let s=c.get(l);return s===void 0&&c.set(l,s=c.size),String(s)},a=[...o.keys()].sort(),r=new Map,i=e=>{if(e.kind!=="textValue"){if(e.localName==="p"){let l=e.attributes.find(c=>c.localName==="paraId")?.value;l!==void 0&&!r.has(l)&&r.set(l,r.size);}for(let l of e.children)i(l);}};for(let e of a)i(o.get(e).root);let p=e=>{if(e.kind==="textValue")return e;let l=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===ao?{...s,value:l?n(l,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 a)m.set(e,p(o.get(e).root));return m}async function lo(o){let t=o.buffer instanceof ArrayBuffer?o:o.slice(),n=new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",t)),a="";for(let r of n)a+=r.toString(16).padStart(2,"0");return a}function so(o,t){let n=i=>i.slice(i.indexOf(":")+1).split(".").map(Number),a=n(o),r=n(t);for(let i=0;i<Math.max(a.length,r.length);i+=1){let p=(a[i]??0)-(r[i]??0);if(p!==0)return p}return 0}
2
+ export{b as COLLABORATION_FORMAT_VERSION,M as MAX_BASELINE_BYTES,j as PROTOCOL_VERSION,K as SCHEMA_VERSION,q as assertCollaborationFormatCompatibility,Z as collaborationMigrationNeed,W as createCollaborationState,oo as migrateCollaborationRoom,J as prepareCollaborationServerDocument,R as readCollaborationFormatVersion};
@@ -1,2 +1,2 @@
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
+ 'use strict';var chunkLUUFBXJ5_cjs=require('../chunk-LUUFBXJ5.cjs'),chunkYOWEY5F3_cjs=require('../chunk-YOWEY5F3.cjs'),Q=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 Q__namespace=/*#__PURE__*/_interopNamespace(Q);function N(e,n){let t=0,o=null,i=new Set,a=()=>{o!==null&&clearInterval(o),o=null;},r=l=>{if(l!==t){t=l,t===0&&a();for(let f of [...i])f();}},s=()=>{let l=n.room;if(l===null)return false;if(l.bcConns.size>0)return true;for(let f of l.webrtcConns.values())if(f.connected&&f.synced)return true;return false},b=()=>{t>0&&s()&&r(0);},g=(l,f)=>{f===n.room||s()||(r(t+1),o??=setInterval(b,1e3));};return e.on("update",g),n.on("peers",b),n.on("synced",b),{count:()=>t,subscribe(l){return i.add(l),()=>{i.delete(l);}},destroy(){a(),e.off("update",g),n.off("peers",b),n.off("synced",b),i.clear();}}}var O=new WeakSet,k=(e,n)=>(e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3])>>>0,P=(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;},te=e=>e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):null,oe=e=>new Promise(n=>{setTimeout(n,e);});function W(e,n){if(O.has(e))return;O.add(e);let t=e.send.bind(e),o=e._onChannelMessage.bind(e),i=n?.partialTimeoutMs,a=typeof i=="number"&&Number.isFinite(i)&&i>0?i:3e4,r=n?.onAbandonedMessage,s=n?.onDeliveredMessage,b=Math.min(n?.maxPartialBytes??1/0,134111232),g=[],l=new Map,f=false,_=1,E=0,C=(c,d)=>{d.timer!==void 0&&clearTimeout(d.timer),l.delete(c),E-=d.bytes;},m=c=>{let d=l.get(c);d&&(C(c,d),e.destroyed!==true&&(r?.(),e.destroy?.()));},R=c=>{let d=l.get(c);d&&(d.timer!==void 0&&clearTimeout(d.timer),d.timer=setTimeout(()=>{m(c);},a));},y=()=>e._channel?.bufferedAmount??0,v=async()=>{let c=0;for(;y()>1048576;){if(e.destroyed===true||c>=3e4)return false;await oe(20),c+=20;}return e.destroyed!==true},V=async c=>{let d=Math.ceil(c.byteLength/16371);if(d>8192)throw new Error(`collaboration message needs ${d} chunks, above the 8192 limit`);let S=_;_=_+1>>>0||1;for(let A=0;A<d;A+=1){if(!await v()){e.destroyed!==true&&e.destroy?.();return}let h=A*16371,u=c.subarray(h,Math.min(h+16371,c.byteLength)),p=new Uint8Array(13+u.byteLength);p[0]=251,P(p,1,S),P(p,5,A),P(p,9,d),p.set(u,13),t(p);}},ee=async()=>{if(!f){f=true;try{for(;g.length>0;){let c=g.shift();if(c){if(e.destroyed===!0)return;await V(c);}}}finally{f=false;}}};e.send=c=>{if(typeof c=="string"||c.byteLength<=16371){t(c);return}g.push(c),ee();},e._onChannelMessage=c=>{let d=te(c.data);if(!d||d.byteLength<13||d[0]!==251){o(c);return}let S=k(d,1),A=k(d,5),h=k(d,9);if(h===0||h>8192||A>=h)return;if(d.byteLength>16384){m(S);return}let u=l.get(S);if(!u){if(l.size>=4){let M=l.keys().next();M.done||m(M.value);}u={chunks:new Array(h),count:h,received:0,bytes:0,timer:void 0},l.set(S,u);}if(u.count!==h||u.chunks[A])return;let p=d.subarray(13);if(u.chunks[A]=p,u.received+=1,u.bytes+=p.byteLength,E+=p.byteLength,E>b){m(S);return}if(u.received!==u.count){R(S);return}C(S,u);let Y=new Uint8Array(u.bytes),F=0;for(let M of u.chunks){if(!M)return;Y.set(M,F),F+=M.byteLength;}e.destroyed!==true&&(e.push(Y),s?.());};}function j(e,n){return t=>{n()&&(t?e.setTransportStatus("ready","transport-disconnected","a peer link cannot carry large updates"):e.setTransportStatus("ready"));}}var re=3,ie=6e4;function X(e,n={set:(t,o)=>setTimeout(t,o),clear:t=>clearTimeout(t)}){let t=new Map,o=new Map,i=new Set,a=r=>{t.delete(r);let s=o.get(r);s!==void 0&&n.clear(s),o.delete(r),i.delete(r)&&i.size===0&&e(false);};return {abandoned(r){let s=(t.get(r)??0)+1;t.set(r,s);let b=o.get(r);b!==void 0&&n.clear(b),o.set(r,n.set(()=>a(r),ie)),!(s<re||i.has(r))&&(i.add(r),i.size===1&&e(true));},delivered:a,reset(){for(let r of [...t.keys(),...i])a(r);},destroy(){for(let r of o.values())n.clear(r);o.clear(),t.clear(),i.clear();}}}var K=Symbol.for("docx-editor.webrtc-signaling-scope"),U=new WeakMap,I=new WeakSet,B=new WeakSet,z=new WeakSet,q=e=>{let n=U.get(e);return n||(n=new Set,U.set(e,n)),n};function se(e){B.add(e),I.add(e);}function ae(e){B.add(e),I.delete(e);}var ce=e=>e?B.has(e)?I.has(e):e.bcconnected===true:false;function x(e,n){if(typeof n!="string")return false;for(let t of e.providers)if(t.roomName===n&&t.shouldConnect!==false&&ce(t.room))return true;return false}var $=e=>Array.isArray(e)?e.filter(n=>typeof n=="string"):[];function de(e,n){if(n===null||typeof n!="object")return n;let{type:t,topic:o,topics:i}=n;switch(t){case "subscribe":{let a=$(i).filter(s=>x(e,s));if(a.length===0)return null;let r=q(e);for(let s of a)r.add(s);return {...n,topics:a}}case "unsubscribe":{let a=q(e),r=$(i).filter(s=>a.has(s));if(r.length===0)return null;for(let s of r)a.delete(s);return {...n,topics:r}}case "publish":return x(e,o)?n:null;default:return n}}function le(e,n){if(n===null||typeof n!="object")return true;let{type:t,topic:o}=n;return t!=="publish"||x(e,o)}function ue(e){U.delete(e);}var w=(e,n,t)=>{let o=e;o[n]=t(o[n]);};function Z(){let e=yWebrtc.SignalingConn.prototype;e[K]||(e[K]=true,w(yWebrtc.SignalingConn.prototype,"send",n=>function(o){let i=de(this,o);i!==null&&n.call(this,i);}),w(yWebrtc.SignalingConn.prototype,"emit",n=>function(o,i){o==="disconnect"&&ue(this);let a=Array.isArray(i)?i[0]:void 0;if(!(o==="message"&&!le(this,a)))return n.call(this,o,i)}),w(yWebrtc.Room.prototype,"connect",n=>function(){return se(this),n.call(this)}),w(yWebrtc.Room.prototype,"disconnect",n=>function(){return ae(this),n.call(this)}),w(yWebrtc.WebrtcProvider.prototype,"disconnect",n=>function(){this.shouldConnect&&(n.call(this),this.signalingConns=[...new Set(this.signalingConns.filter(o=>o.providers.has(this)))]);}),w(yWebrtc.WebrtcProvider.prototype,"destroy",n=>function(){return z.add(this),this.shouldConnect&&this.disconnect(),n.call(this)}),w(yWebrtc.WebrtcProvider.prototype,"connect",n=>function(){if(!z.has(this))return n.call(this)}));}var Ue=Object.freeze(["wss://turn.0docker.com/ws"]);function be(e){if(!Array.isArray(e))throw new TypeError("WebRTC collaboration requires `signaling`, an array of signaling server URLs. Pass your own URLs in production. For demos, pass `signaling: DEMO_SIGNALING_ENDPOINTS` from '@docx-editor.dev/pro/collaboration/webrtc'. To connect only tabs of the same browser, pass `signaling: []`.");return e.forEach((n,t)=>{if(!ge(n))throw new TypeError(`WebRTC collaboration needs signaling[${t}] to be a ws:// or wss:// URL without a #fragment.`)}),e}var ge=e=>{if(typeof e!="string")return false;try{let{protocol:n}=new URL(e);return (n==="ws:"||n==="wss:")&&!e.includes("#")}catch{return false}},pe=/^[A-Za-z0-9_-]{24,256}$/,J="#collab=";function he(e){let n=e.password?.trim()??"";return n.length>0?n:me(e.href)}var me=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(J))return;let o;try{o=decodeURIComponent(t.slice(J.length));}catch{return}if(pe.test(o))return o},Se=(e,n)=>{Promise.resolve(e.key).then(()=>{let t=e.room;if(!t)return;let o=t.webrtcConns,i=(r,s)=>{W(s.peer,{onAbandonedMessage:()=>n.abandoned(r),onDeliveredMessage:()=>n.delivered(r)});};for(let[r,s]of o)i(r,s);let a=o.set.bind(o);o.set=(r,s)=>(i(r,s),a(r,s));});};async function xe(e){let n=chunkLUUFBXJ5_cjs.b(e.roomId),t=be(e.signaling);Z();let o=he({password:e.password}),i=new Q__namespace.Doc,a=new awareness.Awareness(i),r=null,s={abandoned(){},delivered(){}},b=()=>{let y=new yWebrtc.WebrtcProvider(n,i,{awareness:a,signaling:[...t],...o!==void 0?{password:o}:{},...e.iceServers?{peerOpts:{config:{iceServers:e.iceServers.map(v=>({...v}))}}}:{}});return Se(y,{abandoned:v=>s.abandoned(v),delivered:v=>s.delivered(v)}),y},g;try{e.bootstrap.kind!=="create"&&(r=b()),g=await chunkYOWEY5F3_cjs.r({ydoc:i,awareness:a,documentId:n,identity:e.identity,bootstrap:e.bootstrap,offlineEditing:e.offlineEditing}),r||(r=b());}catch(y){throw r?.destroy(),a.destroy(),i.destroy(),y}if(!r)throw g.destroy(),a.destroy(),i.destroy(),new Error("WebRTC provider did not initialize");let l=r,f=g.session,_=true,E=X(j(f,()=>_));s=E;let C=y=>{_=y.connected,y.connected&&E.reset(),f.setTransportStatus(y.connected?"ready":"disconnected",y.connected?void 0:"transport-disconnected",y.connected?void 0:"webrtc disconnected");};l.on("status",C);let m=N(i,l),R=false;return Object.freeze({document:g.document,session:f,ydoc:i,provider:l,unsyncedChanges:()=>m.count(),subscribeUnsyncedChanges:y=>m.subscribe(y),destroy(){R||(R=true,l.off("status",C),m.destroy(),E.destroy(),g.destroy(),l.destroy(),a.destroy(),i.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=Ue;exports.createWebrtcCollaboration=xe;exports.requireSignaling=be;exports.resolveWebrtcRoomPassword=he;
@@ -8,10 +8,10 @@
8
8
  import * as Y from 'yjs';
9
9
  import { WebrtcProvider } from 'y-webrtc';
10
10
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
11
- import { D as DocumentCollaborationHandle } from '../document-session-_v9vqiSX.cjs';
12
- import { a as CollaborationBootstrap } from '../types-BQ1vBt5Q.cjs';
11
+ import { D as DocumentCollaborationHandle } from '../document-session-B-MlORjE.cjs';
12
+ import { a as CollaborationBootstrap } from '../types-DvGpDOcZ.cjs';
13
13
  export { c as createCollaborationRoomId, v as validateRoomId } from '../room-id-BfudXOZz.cjs';
14
- import '../document-session-options-CfKypp9c.cjs';
14
+ import '../document-session-options-CxR0F5xT.cjs';
15
15
  import 'y-protocols/awareness';
16
16
 
17
17
  /**
@@ -25,22 +25,25 @@ import 'y-protocols/awareness';
25
25
  /**
26
26
  * Public demo signaling endpoints. Use these endpoints for demos only.
27
27
  *
28
- * Production deployments must pass their own `signaling` URLs and TURN
29
- * servers. WebRTC peers cannot connect across many networks without TURN.
28
+ * The host is a shared, unauthenticated public service. It receives every room id and,
29
+ * without a `password`, every signaling message in plaintext. `createWebrtcCollaboration`
30
+ * never selects it for you: pass it as `signaling` to opt in. Production deployments pass
31
+ * their own `signaling` URLs and TURN servers. WebRTC peers cannot connect across many
32
+ * networks without TURN.
30
33
  * @public
31
34
  */
32
35
  declare const DEMO_SIGNALING_ENDPOINTS: readonly string[];
33
36
  /**
34
- * Warn once per process when a room silently falls back to the demo signaling endpoints.
37
+ * Refuse a room without explicit signaling endpoints.
35
38
  *
36
- * Passing `signaling: DEMO_SIGNALING_ENDPOINTS` is a deliberate choice and never warns —
37
- * only an omitted `signaling` does.
39
+ * A default would send room ids and signaling traffic to a host the integrator never chose,
40
+ * so a missing option fails before any connection opens. An empty list is explicit: it opens
41
+ * no signaling connection, and only tabs of the same browser find each other. Each entry
42
+ * must be a `ws://` or `wss://` URL, so a typo fails here and not inside the socket.
38
43
  *
39
44
  * @internal
40
45
  */
41
- declare function warnOnDemoSignalingFallback(signaling: readonly string[] | undefined): void;
42
- /** Test-only reset for the once-per-process demo signaling warning. @internal */
43
- declare function resetDemoSignalingWarningForTests(): void;
46
+ declare function requireSignaling(signaling: readonly string[] | undefined): readonly string[];
44
47
  /** Options for the owned WebRTC collaboration convenience wrapper. @public */
45
48
  interface CreateWebrtcCollaborationOptions {
46
49
  /** The room to join: a `createCollaborationRoomId` value every participant shares. */
@@ -55,8 +58,13 @@ interface CreateWebrtcCollaborationOptions {
55
58
  * {@link CreateDocumentCollaborationOptions.offlineEditing}.
56
59
  */
57
60
  readonly offlineEditing?: boolean;
58
- /** Signaling server URLs that introduce peers to each other. */
59
- readonly signaling?: readonly string[];
61
+ /**
62
+ * Signaling server URLs that introduce peers to each other. There is no default. Pass your
63
+ * own URLs in production, {@link DEMO_SIGNALING_ENDPOINTS} for demos, or `[]` to connect
64
+ * only tabs of the same browser. A call without this value rejects with a `TypeError`
65
+ * before any connection opens.
66
+ */
67
+ readonly signaling: readonly string[];
60
68
  /** STUN and TURN servers for the peer connections. Use TURN across restrictive networks. */
61
69
  readonly iceServers?: readonly RTCIceServer[];
62
70
  /**
@@ -103,8 +111,19 @@ declare function resolveWebrtcRoomPassword(options: {
103
111
  readonly password?: string;
104
112
  readonly href?: string;
105
113
  }): string | undefined;
106
- /** Create one owned `y-webrtc` room and provider-neutral collaboration session. @public */
114
+ /**
115
+ * Create one owned `y-webrtc` room and provider-neutral collaboration session.
116
+ *
117
+ * The room reaches only the signaling servers in `signaling`. It never falls back to public
118
+ * endpoints. The first room applies the same scoping to every `y-webrtc` provider in the
119
+ * page, including providers the host creates directly. A provider created before the first
120
+ * room keeps its own `destroy()`: call its `disconnect()` first to close its signaling.
121
+ *
122
+ * @throws `TypeError` (as a rejection) when `roomId` is invalid, or `signaling` is not an
123
+ * array of `ws://` or `wss://` URLs without a fragment. No connection opens.
124
+ * @public
125
+ */
107
126
  declare function createWebrtcCollaboration(options: CreateWebrtcCollaborationOptions): Promise<WebrtcCollaborationHandle>;
108
127
 
109
- export { DEMO_SIGNALING_ENDPOINTS, createWebrtcCollaboration, resetDemoSignalingWarningForTests, resolveWebrtcRoomPassword, warnOnDemoSignalingFallback };
128
+ export { DEMO_SIGNALING_ENDPOINTS, createWebrtcCollaboration, requireSignaling, resolveWebrtcRoomPassword };
110
129
  export type { CreateWebrtcCollaborationOptions, WebrtcCollaborationHandle };