@inditextech/weave-store-websockets 0.1.1 → 0.2.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.
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJS = (cb, mod) => function() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
+ key = keys[i];
15
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: ((k) => from[k]).bind(null, key),
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ const http = __toESM(require("http"));
29
+ const yjs = __toESM(require("yjs"));
30
+
31
+ //#region src/constants.ts
32
+ const WEAVE_STORE_WEBSOCKETS = "store-websockets";
33
+ const WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS = {
34
+ ["CONNECTING"]: "connecting",
35
+ ["CONNECTED"]: "connected",
36
+ ["DISCONNECTED"]: "disconnected"
37
+ };
38
+
39
+ //#endregion
40
+ Object.defineProperty(exports, 'WEAVE_STORE_WEBSOCKETS', {
41
+ enumerable: true,
42
+ get: function () {
43
+ return WEAVE_STORE_WEBSOCKETS;
44
+ }
45
+ });
46
+ Object.defineProperty(exports, 'WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS', {
47
+ enumerable: true,
48
+ get: function () {
49
+ return WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS;
50
+ }
51
+ });
52
+ Object.defineProperty(exports, '__commonJS', {
53
+ enumerable: true,
54
+ get: function () {
55
+ return __commonJS;
56
+ }
57
+ });
58
+ Object.defineProperty(exports, '__toESM', {
59
+ enumerable: true,
60
+ get: function () {
61
+ return __toESM;
62
+ }
63
+ });
@@ -0,0 +1,13 @@
1
+ import { IncomingMessage } from "http";
2
+ import "yjs";
3
+
4
+ //#region src/constants.ts
5
+ const WEAVE_STORE_WEBSOCKETS = "store-websockets";
6
+ const WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS = {
7
+ ["CONNECTING"]: "connecting",
8
+ ["CONNECTED"]: "connected",
9
+ ["DISCONNECTED"]: "disconnected"
10
+ };
11
+
12
+ //#endregion
13
+ export { WEAVE_STORE_WEBSOCKETS, WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS };
@@ -0,0 +1,33 @@
1
+ import { IncomingMessage } from "http";
2
+ import * as Y from "yjs";
3
+
4
+ //#region src/constants.d.ts
5
+ declare const WEAVE_STORE_WEBSOCKETS = "store-websockets";
6
+ declare const WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS: {
7
+ readonly "CONNECTING": "connecting";
8
+ readonly "CONNECTED": "connected";
9
+ readonly "DISCONNECTED": "disconnected";
10
+ };
11
+
12
+ //#endregion
13
+ //#region src/types.d.ts
14
+ type WeaveStoreWebsocketsConnectionStatusKeys = keyof typeof WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS;
15
+ type WeaveStoreWebsocketsConnectionStatus = (typeof WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS)[WeaveStoreWebsocketsConnectionStatusKeys];
16
+ type WeaveStoreWebsocketsOptions = {
17
+ roomId: string;
18
+ wsOptions: {
19
+ serverUrl: string;
20
+ };
21
+ callbacks?: WeaveStoreWebsocketsCallbacks;
22
+ };
23
+ type WeaveStoreWebsocketsCallbacks = {
24
+ onConnectionStatusChange?: (status: WeaveStoreWebsocketsConnectionStatus) => void;
25
+ };
26
+ type PerformUpgrade = (req: IncomingMessage) => Promise<boolean>;
27
+ type ExtractRoomId = (req: IncomingMessage) => string | undefined;
28
+ type FetchInitialState = (doc: Y.Doc) => void;
29
+ type PersistRoom = (roomId: string, actualState: Uint8Array<ArrayBufferLike>) => Promise<void>;
30
+ type FetchRoom = (roomId: string) => Promise<Uint8Array | null>;
31
+
32
+ //#endregion
33
+ export { ExtractRoomId, FetchInitialState, FetchRoom, PerformUpgrade, PersistRoom, WEAVE_STORE_WEBSOCKETS as WEAVE_STORE_WEBSOCKETS$1, WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS as WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS$1, WeaveStoreWebsocketsCallbacks, WeaveStoreWebsocketsConnectionStatus, WeaveStoreWebsocketsConnectionStatusKeys, WeaveStoreWebsocketsOptions };
@@ -0,0 +1,33 @@
1
+ import * as Y from "yjs";
2
+ import { IncomingMessage } from "http";
3
+
4
+ //#region src/constants.d.ts
5
+ declare const WEAVE_STORE_WEBSOCKETS = "store-websockets";
6
+ declare const WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS: {
7
+ readonly "CONNECTING": "connecting";
8
+ readonly "CONNECTED": "connected";
9
+ readonly "DISCONNECTED": "disconnected";
10
+ };
11
+
12
+ //#endregion
13
+ //#region src/types.d.ts
14
+ type WeaveStoreWebsocketsConnectionStatusKeys = keyof typeof WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS;
15
+ type WeaveStoreWebsocketsConnectionStatus = (typeof WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS)[WeaveStoreWebsocketsConnectionStatusKeys];
16
+ type WeaveStoreWebsocketsOptions = {
17
+ roomId: string;
18
+ wsOptions: {
19
+ serverUrl: string;
20
+ };
21
+ callbacks?: WeaveStoreWebsocketsCallbacks;
22
+ };
23
+ type WeaveStoreWebsocketsCallbacks = {
24
+ onConnectionStatusChange?: (status: WeaveStoreWebsocketsConnectionStatus) => void;
25
+ };
26
+ type PerformUpgrade = (req: IncomingMessage) => Promise<boolean>;
27
+ type ExtractRoomId = (req: IncomingMessage) => string | undefined;
28
+ type FetchInitialState = (doc: Y.Doc) => void;
29
+ type PersistRoom = (roomId: string, actualState: Uint8Array<ArrayBufferLike>) => Promise<void>;
30
+ type FetchRoom = (roomId: string) => Promise<Uint8Array | null>;
31
+
32
+ //#endregion
33
+ export { ExtractRoomId, FetchInitialState, FetchRoom, PerformUpgrade, PersistRoom, WEAVE_STORE_WEBSOCKETS, WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS, WeaveStoreWebsocketsCallbacks, WeaveStoreWebsocketsConnectionStatus, WeaveStoreWebsocketsConnectionStatusKeys, WeaveStoreWebsocketsOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inditextech/weave-store-websockets",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
@@ -27,8 +27,8 @@
27
27
  "dist"
28
28
  ],
29
29
  "scripts": {
30
- "build:snapshot": "vite build --mode=development --sourcemap --emptyOutDir",
31
- "build": "vite build --mode=production --minify --emptyOutDir",
30
+ "build:snapshot": "tsdown --sourcemap",
31
+ "build": "tsdown",
32
32
  "bump:snapshot": "npm version $npm_package_version.$(date \"+%s\")",
33
33
  "bundle:analyze": "vite-bundle-visualizer",
34
34
  "check": "echo \"Monorepo test script\" && exit 0",
@@ -42,15 +42,22 @@
42
42
  "publish:snapshot": "npm publish",
43
43
  "release:perform": "npm publish --access public",
44
44
  "release:prepare": "npm run verify",
45
- "test": "vitest --passWithNoTests",
45
+ "test": "vitest --passWithNoTests --coverage --watch=false",
46
46
  "types:check": "tsc --noEmit",
47
47
  "verify": "npm run lint && npm run test && npm run build",
48
48
  "version:development": "npm version $(npm version minor)-SNAPSHOT",
49
49
  "version:release": "npm version $RELEASE_VERSION -m \"[npm-scripts] prepare release $RELEASE_VERSION\" --tag-version-prefix \"\""
50
50
  },
51
+ "dependencies": {
52
+ "@syncedstore/core": "0.6.0",
53
+ "@inditextech/weave-sdk": "0.2.0",
54
+ "@inditextech/weave-types": "0.2.0",
55
+ "konva": "9.3.20",
56
+ "ws": "8.18.1",
57
+ "y-websocket": "3.0.0",
58
+ "yjs": "13.6.26"
59
+ },
51
60
  "devDependencies": {
52
- "@inditextech/weave-sdk": "0.1.1",
53
- "@inditextech/weave-types": "0.1.1",
54
61
  "@types/express": "^5.0.1",
55
62
  "@types/lodash.debounce": "^4.0.9",
56
63
  "@types/ws": "^8.18.1",
@@ -67,12 +74,7 @@
67
74
  "vite-plugin-compression2": "1.0.0",
68
75
  "vite-plugin-dts": "4.0.3",
69
76
  "vitest": "1.6.0",
70
- "vitest-sonar-reporter": "2.0.0",
71
- "ws": "^8.18.1"
72
- },
73
- "peerDependencies": {
74
- "y-websocket": ">= 2.1.0",
75
- "yjs": ">= 13.6.23"
77
+ "vitest-sonar-reporter": "2.0.0"
76
78
  },
77
79
  "engines": {
78
80
  "node": "^18.12 || ^20.11 || ^22.11",
@@ -1 +0,0 @@
1
- "use strict";const Z=require("yjs");function H(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const O=H(Z),Q="store-websockets",tt={CONNECTING:"connecting",CONNECTED:"connected",DISCONNECTED:"disconnected"},h=()=>new Map,I=(t,e,s)=>{let n=t.get(e);return n===void 0&&t.set(e,n=s()),n},T=()=>new Set,x=Array.from,et=String.fromCharCode,st=t=>t.toLowerCase(),nt=/^\s*/g,rt=t=>t.replace(nt,""),ot=/([A-Z])/g,ct=(t,e)=>rt(t.replace(ot,s=>`${e}${st(s)}`)),it=t=>{const e=unescape(encodeURIComponent(t)),s=e.length,n=new Uint8Array(s);for(let r=0;r<s;r++)n[r]=e.codePointAt(r);return n},y=typeof TextEncoder<"u"?new TextEncoder:null,at=t=>y.encode(t),lt=y?at:it;let g=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});g&&g.decode(new Uint8Array).length===1&&(g=null);const ft=Object.keys,ut=(t,e)=>{const s=[];for(const n in t)s.push(e(t[n],n));return s},N=t=>ft(t).length,ht=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),pt=(t,e)=>t===e,S=(t,e)=>{if(t==null||e==null)return pt(t,e);if(t.constructor!==e.constructor)return!1;if(t===e)return!0;switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:{if(t.byteLength!==e.byteLength)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;break}case Set:{if(t.size!==e.size)return!1;for(const s of t)if(!e.has(s))return!1;break}case Map:{if(t.size!==e.size)return!1;for(const s of t.keys())if(!e.has(s)||!S(t.get(s),e.get(s)))return!1;break}case Object:if(N(t)!==N(e))return!1;for(const s in t)if(!ht(t,s)||!S(t[s],e[s]))return!1;break;case Array:if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(!S(t[s],e[s]))return!1;break;default:return!1}return!0},dt=(t,e)=>e.includes(t),M=Math.floor,P=(t,e)=>t<e?t:e,gt=(t,e)=>t>e?t:e,St=Math.pow,R=128,E=127,yt=Number.MAX_SAFE_INTEGER,mt=Number.parseInt;class Ut{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const j=()=>new Ut,B=t=>{let e=t.cpos;for(let s=0;s<t.bufs.length;s++)e+=t.bufs[s].length;return e},z=t=>{const e=new Uint8Array(B(t));let s=0;for(let n=0;n<t.bufs.length;n++){const r=t.bufs[n];e.set(r,s),s+=r.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),s),e},_=(t,e)=>{const s=t.cbuf.length;t.cpos===s&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(s*2),t.cpos=0),t.cbuf[t.cpos++]=e},l=(t,e)=>{for(;e>E;)_(t,R|E&e),e=M(e/128);_(t,E&e)},C=new Uint8Array(3e4),bt=C.length/3,wt=(t,e)=>{if(e.length<bt){const s=y.encodeInto(e,C).written||0;l(t,s);for(let n=0;n<s;n++)_(t,C[n])}else U(t,lt(e))},Et=(t,e)=>{const s=unescape(encodeURIComponent(e)),n=s.length;l(t,n);for(let r=0;r<n;r++)_(t,s.codePointAt(r))},_t=y&&y.encodeInto?wt:Et,At=(t,e)=>{const s=t.cbuf.length,n=t.cpos,r=P(s-n,e.length),o=e.length-r;t.cbuf.set(e.subarray(0,r),n),t.cpos+=r,o>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(gt(s*2,o)),t.cbuf.set(e.subarray(r)),t.cpos=o)},U=(t,e)=>{l(t,e.byteLength),At(t,e)},W=t=>new Error(t),vt=W("Unexpected end of array"),Ct=W("Integer out of Range");class Ot{constructor(e){this.arr=e,this.pos=0}}const Y=t=>new Ot(t),It=(t,e)=>{const s=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,s},A=t=>It(t,p(t)),V=t=>t.arr[t.pos++],p=t=>{let e=0,s=1;const n=t.arr.length;for(;t.pos<n;){const r=t.arr[t.pos++];if(e=e+(r&E)*s,s*=128,r<R)return e;if(e>yt)throw Ct}throw vt},Tt=t=>{let e=p(t);if(e===0)return"";{let s=String.fromCodePoint(V(t));if(--e<100)for(;e--;)s+=String.fromCodePoint(V(t));else for(;e>0;){const n=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+n);t.pos+=n,s+=String.fromCodePoint.apply(null,r),e-=n}return decodeURIComponent(escape(s))}},kt=t=>g.decode(A(t)),$=g?kt:Tt,m=Date.now,K=0,k=1,q=2,Dt=(t,e)=>{l(t,K);const s=O.encodeStateVector(e);U(t,s)},F=(t,e,s)=>{l(t,k),U(t,O.encodeStateAsUpdate(e,s))},Lt=(t,e,s)=>F(e,s,A(t)),G=(t,e,s)=>{try{O.applyUpdate(e,A(t),s)}catch(n){console.error("Caught error while handling a Yjs update",n)}},Nt=(t,e)=>{l(t,q),U(t,e)},Vt=G,xt=(t,e,s,n)=>{const r=p(t);switch(r){case K:Lt(t,e,s);break;case k:G(t,s,n);break;case q:Vt(t,s,n);break;default:throw new Error("Unknown message type")}return r};class Mt{constructor(){this._observers=h()}on(e,s){return I(this._observers,e,T).add(s),s}once(e,s){const n=(...r)=>{this.off(e,n),s(...r)};this.on(e,n)}off(e,s){const n=this._observers.get(e);n!==void 0&&(n.delete(s),n.size===0&&this._observers.delete(e))}emit(e,s){return x((this._observers.get(e)||h()).values()).forEach(n=>n(...s))}destroy(){this._observers=h()}}class Pt{constructor(){this._observers=h()}on(e,s){I(this._observers,e,T).add(s)}once(e,s){const n=(...r)=>{this.off(e,n),s(...r)};this.on(e,n)}off(e,s){const n=this._observers.get(e);n!==void 0&&(n.delete(s),n.size===0&&this._observers.delete(e))}emit(e,s){return x((this._observers.get(e)||h()).values()).forEach(n=>n(...s))}destroy(){this._observers=h()}}const v=3e4;class Rt extends Pt{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const s=m();this.getLocalState()!==null&&v/2<=s-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const n=[];this.meta.forEach((r,o)=>{o!==this.clientID&&v<=s-r.lastUpdated&&this.states.has(o)&&n.push(o)}),n.length>0&&J(this,n,"timeout")},M(v/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){const s=this.clientID,n=this.meta.get(s),r=n===void 0?0:n.clock+1,o=this.states.get(s);e===null?this.states.delete(s):this.states.set(s,e),this.meta.set(s,{clock:r,lastUpdated:m()});const c=[],f=[],i=[],d=[];e===null?d.push(s):o==null?e!=null&&c.push(s):(f.push(s),S(o,e)||i.push(s)),(c.length>0||i.length>0||d.length>0)&&this.emit("change",[{added:c,updated:i,removed:d},"local"]),this.emit("update",[{added:c,updated:f,removed:d},"local"])}setLocalStateField(e,s){const n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:s})}getStates(){return this.states}}const J=(t,e,s)=>{const n=[];for(let r=0;r<e.length;r++){const o=e[r];if(t.states.has(o)){if(t.states.delete(o),o===t.clientID){const c=t.meta.get(o);t.meta.set(o,{clock:c.clock+1,lastUpdated:m()})}n.push(o)}}n.length>0&&(t.emit("change",[{added:[],updated:[],removed:n},s]),t.emit("update",[{added:[],updated:[],removed:n},s]))},jt=(t,e,s=t.states)=>{const n=e.length,r=j();l(r,n);for(let o=0;o<n;o++){const c=e[o],f=s.get(c)||null,i=t.meta.get(c).clock;l(r,c),l(r,i),_t(r,JSON.stringify(f))}return z(r)},Bt=(t,e,s)=>{const n=Y(e),r=m(),o=[],c=[],f=[],i=[],d=p(n);for(let D=0;D<d;D++){const a=p(n);let b=p(n);const u=JSON.parse($(n)),w=t.meta.get(a),X=t.states.get(a),L=w===void 0?0:w.clock;(L<b||L===b&&u===null&&t.states.has(a))&&(u===null?a===t.clientID&&t.getLocalState()!=null?b++:t.states.delete(a):t.states.set(a,u),t.meta.set(a,{clock:b,lastUpdated:r}),w===void 0&&u!==null?o.push(a):w!==void 0&&u===null?i.push(a):u!==null&&(S(u,X)||f.push(a),c.push(a)))}(o.length>0||f.length>0||i.length>0)&&t.emit("change",[{added:o,updated:f,removed:i},s]),(o.length>0||c.length>0||i.length>0)&&t.emit("update",[{added:o,updated:c,removed:i},s])};exports.Awareness=Rt;exports.ObservableV2=Mt;exports.WEAVE_STORE_WEBSOCKETS=Q;exports.WEAVE_STORE_WEBSOCKETS_CONNECTION_STATUS=tt;exports.applyAwarenessUpdate=Bt;exports.create=h;exports.create$1=T;exports.createDecoder=Y;exports.createEncoder=j;exports.encodeAwarenessUpdate=jt;exports.fromCamelCase=ct;exports.fromCharCode=et;exports.getUnixTime=m;exports.isOneOf=dt;exports.length=B;exports.map=ut;exports.messageYjsSyncStep2=k;exports.min=P;exports.parseInt=mt;exports.pow=St;exports.readSyncMessage=xt;exports.readVarString=$;exports.readVarUint=p;exports.readVarUint8Array=A;exports.removeAwarenessStates=J;exports.setIfUndefined=I;exports.toUint8Array=z;exports.writeSyncStep1=Dt;exports.writeSyncStep2=F;exports.writeUpdate=Nt;exports.writeVarUint=l;exports.writeVarUint8Array=U;
Binary file
@@ -1,453 +0,0 @@
1
- import * as I from "yjs";
2
- const At = "store-websockets", Et = {
3
- CONNECTING: "connecting",
4
- CONNECTED: "connected",
5
- DISCONNECTED: "disconnected"
6
- }, p = () => /* @__PURE__ */ new Map(), T = (t, e, s) => {
7
- let n = t.get(e);
8
- return n === void 0 && t.set(e, n = s()), n;
9
- }, N = () => /* @__PURE__ */ new Set(), x = Array.from, It = String.fromCharCode, Y = (t) => t.toLowerCase(), $ = /^\s*/g, q = (t) => t.replace($, ""), F = /([A-Z])/g, Ct = (t, e) => q(t.replace(F, (s) => `${e}${Y(s)}`)), G = (t) => {
10
- const e = unescape(encodeURIComponent(t)), s = e.length, n = new Uint8Array(s);
11
- for (let o = 0; o < s; o++)
12
- n[o] = /** @type {number} */
13
- e.codePointAt(o);
14
- return n;
15
- }, S = (
16
- /** @type {TextEncoder} */
17
- typeof TextEncoder < "u" ? new TextEncoder() : null
18
- ), J = (t) => S.encode(t), K = S ? J : G;
19
- let g = typeof TextDecoder > "u" ? null : new TextDecoder("utf-8", { fatal: !0, ignoreBOM: !0 });
20
- g && g.decode(new Uint8Array()).length === 1 && (g = null);
21
- const X = Object.keys, kt = (t, e) => {
22
- const s = [];
23
- for (const n in t)
24
- s.push(e(t[n], n));
25
- return s;
26
- }, O = (t) => X(t).length, Z = (t, e) => Object.prototype.hasOwnProperty.call(t, e), H = (t, e) => t === e, y = (t, e) => {
27
- if (t == null || e == null)
28
- return H(t, e);
29
- if (t.constructor !== e.constructor)
30
- return !1;
31
- if (t === e)
32
- return !0;
33
- switch (t.constructor) {
34
- case ArrayBuffer:
35
- t = new Uint8Array(t), e = new Uint8Array(e);
36
- case Uint8Array: {
37
- if (t.byteLength !== e.byteLength)
38
- return !1;
39
- for (let s = 0; s < t.length; s++)
40
- if (t[s] !== e[s])
41
- return !1;
42
- break;
43
- }
44
- case Set: {
45
- if (t.size !== e.size)
46
- return !1;
47
- for (const s of t)
48
- if (!e.has(s))
49
- return !1;
50
- break;
51
- }
52
- case Map: {
53
- if (t.size !== e.size)
54
- return !1;
55
- for (const s of t.keys())
56
- if (!e.has(s) || !y(t.get(s), e.get(s)))
57
- return !1;
58
- break;
59
- }
60
- case Object:
61
- if (O(t) !== O(e))
62
- return !1;
63
- for (const s in t)
64
- if (!Z(t, s) || !y(t[s], e[s]))
65
- return !1;
66
- break;
67
- case Array:
68
- if (t.length !== e.length)
69
- return !1;
70
- for (let s = 0; s < t.length; s++)
71
- if (!y(t[s], e[s]))
72
- return !1;
73
- break;
74
- default:
75
- return !1;
76
- }
77
- return !0;
78
- }, Lt = (t, e) => e.includes(t), V = Math.floor, Q = (t, e) => t < e ? t : e, tt = (t, e) => t > e ? t : e, Ot = Math.pow, M = 128, b = 127, et = Number.MAX_SAFE_INTEGER, Dt = Number.parseInt;
79
- class st {
80
- constructor() {
81
- this.cpos = 0, this.cbuf = new Uint8Array(100), this.bufs = [];
82
- }
83
- }
84
- const nt = () => new st(), ot = (t) => {
85
- let e = t.cpos;
86
- for (let s = 0; s < t.bufs.length; s++)
87
- e += t.bufs[s].length;
88
- return e;
89
- }, rt = (t) => {
90
- const e = new Uint8Array(ot(t));
91
- let s = 0;
92
- for (let n = 0; n < t.bufs.length; n++) {
93
- const o = t.bufs[n];
94
- e.set(o, s), s += o.length;
95
- }
96
- return e.set(new Uint8Array(t.cbuf.buffer, 0, t.cpos), s), e;
97
- }, w = (t, e) => {
98
- const s = t.cbuf.length;
99
- t.cpos === s && (t.bufs.push(t.cbuf), t.cbuf = new Uint8Array(s * 2), t.cpos = 0), t.cbuf[t.cpos++] = e;
100
- }, l = (t, e) => {
101
- for (; e > b; )
102
- w(t, M | b & e), e = V(e / 128);
103
- w(t, b & e);
104
- }, E = new Uint8Array(3e4), ct = E.length / 3, at = (t, e) => {
105
- if (e.length < ct) {
106
- const s = S.encodeInto(e, E).written || 0;
107
- l(t, s);
108
- for (let n = 0; n < s; n++)
109
- w(t, E[n]);
110
- } else
111
- _(t, K(e));
112
- }, it = (t, e) => {
113
- const s = unescape(encodeURIComponent(e)), n = s.length;
114
- l(t, n);
115
- for (let o = 0; o < n; o++)
116
- w(
117
- t,
118
- /** @type {number} */
119
- s.codePointAt(o)
120
- );
121
- }, lt = S && /** @type {any} */
122
- S.encodeInto ? at : it, ft = (t, e) => {
123
- const s = t.cbuf.length, n = t.cpos, o = Q(s - n, e.length), r = e.length - o;
124
- t.cbuf.set(e.subarray(0, o), n), t.cpos += o, r > 0 && (t.bufs.push(t.cbuf), t.cbuf = new Uint8Array(tt(s * 2, r)), t.cbuf.set(e.subarray(o)), t.cpos = r);
125
- }, _ = (t, e) => {
126
- l(t, e.byteLength), ft(t, e);
127
- }, P = (t) => new Error(t), ut = P("Unexpected end of array"), ht = P("Integer out of Range");
128
- class pt {
129
- /**
130
- * @param {Uint8Array} uint8Array Binary data to decode
131
- */
132
- constructor(e) {
133
- this.arr = e, this.pos = 0;
134
- }
135
- }
136
- const dt = (t) => new pt(t), gt = (t, e) => {
137
- const s = new Uint8Array(t.arr.buffer, t.pos + t.arr.byteOffset, e);
138
- return t.pos += e, s;
139
- }, C = (t) => gt(t, d(t)), D = (t) => t.arr[t.pos++], d = (t) => {
140
- let e = 0, s = 1;
141
- const n = t.arr.length;
142
- for (; t.pos < n; ) {
143
- const o = t.arr[t.pos++];
144
- if (e = e + (o & b) * s, s *= 128, o < M)
145
- return e;
146
- if (e > et)
147
- throw ht;
148
- }
149
- throw ut;
150
- }, yt = (t) => {
151
- let e = d(t);
152
- if (e === 0)
153
- return "";
154
- {
155
- let s = String.fromCodePoint(D(t));
156
- if (--e < 100)
157
- for (; e--; )
158
- s += String.fromCodePoint(D(t));
159
- else
160
- for (; e > 0; ) {
161
- const n = e < 1e4 ? e : 1e4, o = t.arr.subarray(t.pos, t.pos + n);
162
- t.pos += n, s += String.fromCodePoint.apply(
163
- null,
164
- /** @type {any} */
165
- o
166
- ), e -= n;
167
- }
168
- return decodeURIComponent(escape(s));
169
- }
170
- }, St = (t) => (
171
- /** @type any */
172
- g.decode(C(t))
173
- ), mt = g ? St : yt, v = Date.now, R = 0, B = 1, z = 2, Tt = (t, e) => {
174
- l(t, R);
175
- const s = I.encodeStateVector(e);
176
- _(t, s);
177
- }, Ut = (t, e, s) => {
178
- l(t, B), _(t, I.encodeStateAsUpdate(e, s));
179
- }, bt = (t, e, s) => Ut(e, s, C(t)), j = (t, e, s) => {
180
- try {
181
- I.applyUpdate(e, C(t), s);
182
- } catch (n) {
183
- console.error("Caught error while handling a Yjs update", n);
184
- }
185
- }, Nt = (t, e) => {
186
- l(t, z), _(t, e);
187
- }, wt = j, xt = (t, e, s, n) => {
188
- const o = d(t);
189
- switch (o) {
190
- case R:
191
- bt(t, e, s);
192
- break;
193
- case B:
194
- j(t, s, n);
195
- break;
196
- case z:
197
- wt(t, s, n);
198
- break;
199
- default:
200
- throw new Error("Unknown message type");
201
- }
202
- return o;
203
- };
204
- class Vt {
205
- constructor() {
206
- this._observers = p();
207
- }
208
- /**
209
- * @template {keyof EVENTS & string} NAME
210
- * @param {NAME} name
211
- * @param {EVENTS[NAME]} f
212
- */
213
- on(e, s) {
214
- return T(
215
- this._observers,
216
- /** @type {string} */
217
- e,
218
- N
219
- ).add(s), s;
220
- }
221
- /**
222
- * @template {keyof EVENTS & string} NAME
223
- * @param {NAME} name
224
- * @param {EVENTS[NAME]} f
225
- */
226
- once(e, s) {
227
- const n = (...o) => {
228
- this.off(
229
- e,
230
- /** @type {any} */
231
- n
232
- ), s(...o);
233
- };
234
- this.on(
235
- e,
236
- /** @type {any} */
237
- n
238
- );
239
- }
240
- /**
241
- * @template {keyof EVENTS & string} NAME
242
- * @param {NAME} name
243
- * @param {EVENTS[NAME]} f
244
- */
245
- off(e, s) {
246
- const n = this._observers.get(e);
247
- n !== void 0 && (n.delete(s), n.size === 0 && this._observers.delete(e));
248
- }
249
- /**
250
- * Emit a named event. All registered event listeners that listen to the
251
- * specified name will receive the event.
252
- *
253
- * @todo This should catch exceptions
254
- *
255
- * @template {keyof EVENTS & string} NAME
256
- * @param {NAME} name The event name.
257
- * @param {Parameters<EVENTS[NAME]>} args The arguments that are applied to the event listener.
258
- */
259
- emit(e, s) {
260
- return x((this._observers.get(e) || p()).values()).forEach((n) => n(...s));
261
- }
262
- destroy() {
263
- this._observers = p();
264
- }
265
- }
266
- class vt {
267
- constructor() {
268
- this._observers = p();
269
- }
270
- /**
271
- * @param {N} name
272
- * @param {function} f
273
- */
274
- on(e, s) {
275
- T(this._observers, e, N).add(s);
276
- }
277
- /**
278
- * @param {N} name
279
- * @param {function} f
280
- */
281
- once(e, s) {
282
- const n = (...o) => {
283
- this.off(e, n), s(...o);
284
- };
285
- this.on(e, n);
286
- }
287
- /**
288
- * @param {N} name
289
- * @param {function} f
290
- */
291
- off(e, s) {
292
- const n = this._observers.get(e);
293
- n !== void 0 && (n.delete(s), n.size === 0 && this._observers.delete(e));
294
- }
295
- /**
296
- * Emit a named event. All registered event listeners that listen to the
297
- * specified name will receive the event.
298
- *
299
- * @todo This should catch exceptions
300
- *
301
- * @param {N} name The event name.
302
- * @param {Array<any>} args The arguments that are applied to the event listener.
303
- */
304
- emit(e, s) {
305
- return x((this._observers.get(e) || p()).values()).forEach((n) => n(...s));
306
- }
307
- destroy() {
308
- this._observers = p();
309
- }
310
- }
311
- const A = 3e4;
312
- class Mt extends vt {
313
- /**
314
- * @param {Y.Doc} doc
315
- */
316
- constructor(e) {
317
- super(), this.doc = e, this.clientID = e.clientID, this.states = /* @__PURE__ */ new Map(), this.meta = /* @__PURE__ */ new Map(), this._checkInterval = /** @type {any} */
318
- setInterval(() => {
319
- const s = v();
320
- this.getLocalState() !== null && A / 2 <= s - /** @type {{lastUpdated:number}} */
321
- this.meta.get(this.clientID).lastUpdated && this.setLocalState(this.getLocalState());
322
- const n = [];
323
- this.meta.forEach((o, r) => {
324
- r !== this.clientID && A <= s - o.lastUpdated && this.states.has(r) && n.push(r);
325
- }), n.length > 0 && _t(this, n, "timeout");
326
- }, V(A / 10)), e.on("destroy", () => {
327
- this.destroy();
328
- }), this.setLocalState({});
329
- }
330
- destroy() {
331
- this.emit("destroy", [this]), this.setLocalState(null), super.destroy(), clearInterval(this._checkInterval);
332
- }
333
- /**
334
- * @return {Object<string,any>|null}
335
- */
336
- getLocalState() {
337
- return this.states.get(this.clientID) || null;
338
- }
339
- /**
340
- * @param {Object<string,any>|null} state
341
- */
342
- setLocalState(e) {
343
- const s = this.clientID, n = this.meta.get(s), o = n === void 0 ? 0 : n.clock + 1, r = this.states.get(s);
344
- e === null ? this.states.delete(s) : this.states.set(s, e), this.meta.set(s, {
345
- clock: o,
346
- lastUpdated: v()
347
- });
348
- const c = [], f = [], a = [], h = [];
349
- e === null ? h.push(s) : r == null ? e != null && c.push(s) : (f.push(s), y(r, e) || a.push(s)), (c.length > 0 || a.length > 0 || h.length > 0) && this.emit("change", [{ added: c, updated: a, removed: h }, "local"]), this.emit("update", [{ added: c, updated: f, removed: h }, "local"]);
350
- }
351
- /**
352
- * @param {string} field
353
- * @param {any} value
354
- */
355
- setLocalStateField(e, s) {
356
- const n = this.getLocalState();
357
- n !== null && this.setLocalState({
358
- ...n,
359
- [e]: s
360
- });
361
- }
362
- /**
363
- * @return {Map<number,Object<string,any>>}
364
- */
365
- getStates() {
366
- return this.states;
367
- }
368
- }
369
- const _t = (t, e, s) => {
370
- const n = [];
371
- for (let o = 0; o < e.length; o++) {
372
- const r = e[o];
373
- if (t.states.has(r)) {
374
- if (t.states.delete(r), r === t.clientID) {
375
- const c = (
376
- /** @type {MetaClientState} */
377
- t.meta.get(r)
378
- );
379
- t.meta.set(r, {
380
- clock: c.clock + 1,
381
- lastUpdated: v()
382
- });
383
- }
384
- n.push(r);
385
- }
386
- }
387
- n.length > 0 && (t.emit("change", [{ added: [], updated: [], removed: n }, s]), t.emit("update", [{ added: [], updated: [], removed: n }, s]));
388
- }, Pt = (t, e, s = t.states) => {
389
- const n = e.length, o = nt();
390
- l(o, n);
391
- for (let r = 0; r < n; r++) {
392
- const c = e[r], f = s.get(c) || null, a = (
393
- /** @type {MetaClientState} */
394
- t.meta.get(c).clock
395
- );
396
- l(o, c), l(o, a), lt(o, JSON.stringify(f));
397
- }
398
- return rt(o);
399
- }, Rt = (t, e, s) => {
400
- const n = dt(e), o = v(), r = [], c = [], f = [], a = [], h = d(n);
401
- for (let k = 0; k < h; k++) {
402
- const i = d(n);
403
- let m = d(n);
404
- const u = JSON.parse(mt(n)), U = t.meta.get(i), W = t.states.get(i), L = U === void 0 ? 0 : U.clock;
405
- (L < m || L === m && u === null && t.states.has(i)) && (u === null ? i === t.clientID && t.getLocalState() != null ? m++ : t.states.delete(i) : t.states.set(i, u), t.meta.set(i, {
406
- clock: m,
407
- lastUpdated: o
408
- }), U === void 0 && u !== null ? r.push(i) : U !== void 0 && u === null ? a.push(i) : u !== null && (y(u, W) || f.push(i), c.push(i)));
409
- }
410
- (r.length > 0 || f.length > 0 || a.length > 0) && t.emit("change", [{
411
- added: r,
412
- updated: f,
413
- removed: a
414
- }, s]), (r.length > 0 || c.length > 0 || a.length > 0) && t.emit("update", [{
415
- added: r,
416
- updated: c,
417
- removed: a
418
- }, s]);
419
- };
420
- export {
421
- Mt as A,
422
- C as B,
423
- Et as C,
424
- Dt as D,
425
- Vt as O,
426
- At as W,
427
- It as a,
428
- N as b,
429
- p as c,
430
- mt as d,
431
- Tt as e,
432
- Ct as f,
433
- Nt as g,
434
- _ as h,
435
- Lt as i,
436
- Pt as j,
437
- _t as k,
438
- ot as l,
439
- kt as m,
440
- v as n,
441
- Ut as o,
442
- nt as p,
443
- dt as q,
444
- d as r,
445
- T as s,
446
- rt as t,
447
- Q as u,
448
- Ot as v,
449
- l as w,
450
- xt as x,
451
- B as y,
452
- Rt as z
453
- };
Binary file
Binary file
package/dist/client.js.gz DELETED
Binary file
Binary file
package/dist/server.js.gz DELETED
Binary file