@docx-editor.dev/pro 2.31.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.
- package/README.md +24 -0
- package/dist/chunk-3WTOHPAB.js +1 -0
- package/dist/chunk-AVZO5ZHZ.js +1 -0
- package/dist/chunk-GAGYRL3L.js +5 -0
- package/dist/chunk-HMSOWKXT.js +1 -0
- package/dist/chunk-I6HVINA4.cjs +1 -0
- package/dist/chunk-MHB6ID2P.cjs +1 -0
- package/dist/chunk-PMS3PGOE.cjs +1 -0
- package/dist/chunk-YOWEY5F3.cjs +5 -0
- package/dist/collaboration/hocuspocus.cjs +1 -1
- package/dist/collaboration/hocuspocus.d.cts +3 -3
- package/dist/collaboration/hocuspocus.d.ts +3 -3
- package/dist/collaboration/hocuspocus.js +1 -1
- package/dist/collaboration/index.cjs +2 -2
- package/dist/collaboration/index.d.cts +63 -7
- package/dist/collaboration/index.d.ts +63 -7
- package/dist/collaboration/index.js +2 -2
- package/dist/collaboration/webrtc.cjs +1 -1
- package/dist/collaboration/webrtc.d.cts +3 -3
- package/dist/collaboration/webrtc.d.ts +3 -3
- package/dist/collaboration/webrtc.js +1 -1
- package/dist/{document-session-_v9vqiSX.d.cts → document-session-B-MlORjE.d.cts} +105 -9
- package/dist/{document-session-Bxs4_GgX.d.ts → document-session-B-iH-YCU.d.ts} +105 -9
- package/dist/document-session-B35ZX2W4.js +1 -0
- package/dist/document-session-V3O7XBJY.cjs +1 -0
- package/dist/{document-session-options-DelOC7PX.d.ts → document-session-options-CdOH-TNn.d.ts} +1 -1
- package/dist/{document-session-options-CfKypp9c.d.cts → document-session-options-CxR0F5xT.d.cts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/react/hocuspocus.d.cts +2 -2
- package/dist/react/hocuspocus.d.ts +2 -2
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +95 -12
- package/dist/react/index.d.ts +95 -12
- package/dist/react/index.js +2 -2
- package/dist/react/webrtc.d.cts +2 -2
- package/dist/react/webrtc.d.ts +2 -2
- package/dist/{types-BQ1vBt5Q.d.ts → types-DvGpDOcZ.d.cts} +9 -1
- package/dist/{types-BQ1vBt5Q.d.cts → types-DvGpDOcZ.d.ts} +9 -1
- package/dist/{types-6EmrEn4n.d.cts → types-bt2k1VO0.d.cts} +9 -1
- package/dist/{types-6EmrEn4n.d.ts → types-bt2k1VO0.d.ts} +9 -1
- package/dist/vue/hocuspocus.d.cts +2 -2
- package/dist/vue/hocuspocus.d.ts +2 -2
- package/dist/vue/index.cjs +2 -2
- package/dist/vue/index.d.cts +89 -13
- package/dist/vue/index.d.ts +89 -13
- package/dist/vue/index.js +2 -2
- package/dist/vue/webrtc.d.cts +2 -2
- package/dist/vue/webrtc.d.ts +2 -2
- package/docs/accept-reject-without-scrolling.md +95 -0
- package/docs/comment-on-found-text.md +72 -0
- package/docs/custom-review-cards.md +178 -0
- package/docs/highlight-ranges.md +48 -0
- package/docs/index.md +36 -0
- package/docs/propose-rewrite.md +247 -0
- package/docs/tracked-replacement.md +68 -0
- package/package.json +5 -4
- package/dist/chunk-32WEH2XH.cjs +0 -1
- package/dist/chunk-FD2KDBHX.cjs +0 -1
- package/dist/chunk-L567WP3J.js +0 -5
- package/dist/chunk-MJECUVHQ.cjs +0 -5
- package/dist/chunk-Q5JTCGJI.js +0 -1
- package/dist/chunk-SNQCYZLT.js +0 -1
- package/dist/chunk-UOAEJRVX.js +0 -1
- package/dist/chunk-ZSAAX6HV.cjs +0 -1
- package/dist/document-session-3VC43WNI.cjs +0 -1
- package/dist/document-session-J2YKWERI.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
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-
|
|
12
|
-
import { a as CollaborationBootstrap } from '../types-
|
|
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-
|
|
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-
|
|
12
|
-
import { a as CollaborationBootstrap } from '../types-
|
|
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-
|
|
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-
|
|
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
|
|
2
|
-
Object.defineProperty(exports,"checkCollaborationRoomGeneration",{enumerable:true,get:function(){return
|
|
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-
|
|
13
|
-
export { C as CollaborationResourceUsage, D as DocumentCollaborationHandle,
|
|
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-
|
|
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
|
|
132
|
-
*
|
|
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-
|
|
13
|
-
export { C as CollaborationResourceUsage, D as DocumentCollaborationHandle,
|
|
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-
|
|
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
|
|
132
|
-
*
|
|
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-
|
|
2
|
-
export{b as COLLABORATION_FORMAT_VERSION,
|
|
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'),
|
|
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
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-
|
|
12
|
-
import { a as CollaborationBootstrap } from '../types-
|
|
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-
|
|
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 { WebrtcProvider } from 'y-webrtc';
|
|
10
10
|
import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
|
|
11
|
-
import { D as DocumentCollaborationHandle } from '../document-session-
|
|
12
|
-
import { a as CollaborationBootstrap } from '../types-
|
|
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-
|
|
14
|
+
import '../document-session-options-CdOH-TNn.js';
|
|
15
15
|
import 'y-protocols/awareness';
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {b}from'../chunk-6DEUT2RQ.js';export{a as createCollaborationRoomId,b as validateRoomId}from'../chunk-6DEUT2RQ.js';import {
|
|
1
|
+
import {b}from'../chunk-6DEUT2RQ.js';export{a as createCollaborationRoomId,b as validateRoomId}from'../chunk-6DEUT2RQ.js';import {r}from'../chunk-GAGYRL3L.js';import*as Q from'yjs';import {Awareness}from'y-protocols/awareness';import {WebrtcProvider,SignalingConn,Room}from'y-webrtc';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=SignalingConn.prototype;e[K]||(e[K]=true,w(SignalingConn.prototype,"send",n=>function(o){let i=de(this,o);i!==null&&n.call(this,i);}),w(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(Room.prototype,"connect",n=>function(){return se(this),n.call(this)}),w(Room.prototype,"disconnect",n=>function(){return ae(this),n.call(this)}),w(WebrtcProvider.prototype,"disconnect",n=>function(){this.shouldConnect&&(n.call(this),this.signalingConns=[...new Set(this.signalingConns.filter(o=>o.providers.has(this)))]);}),w(WebrtcProvider.prototype,"destroy",n=>function(){return z.add(this),this.shouldConnect&&this.disconnect(),n.call(this)}),w(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=b(e.roomId),t=be(e.signaling);Z();let o=he({password:e.password}),i=new Q.Doc,a=new Awareness(i),r$1=null,s={abandoned(){},delivered(){}},b$1=()=>{let y=new 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$1=b$1()),g=await r({ydoc:i,awareness:a,documentId:n,identity:e.identity,bootstrap:e.bootstrap,offlineEditing:e.offlineEditing}),r$1||(r$1=b$1());}catch(y){throw r$1?.destroy(),a.destroy(),i.destroy(),y}if(!r$1)throw g.destroy(),a.destroy(),i.destroy(),new Error("WebRTC provider did not initialize");let l=r$1,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
2
|
export{Ue as DEMO_SIGNALING_ENDPOINTS,xe as createWebrtcCollaboration,be as requireSignaling,he as resolveWebrtcRoomPassword};
|