kritzel-stencil 0.0.165 → 0.0.166

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/{default-line-tool.config-DEuVgTP4.js → default-line-tool.config-BNBO4I1t.js} +47 -32
  2. package/dist/cjs/default-line-tool.config-BNBO4I1t.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +1 -1
  4. package/dist/cjs/kritzel-color_22.cjs.entry.js +1 -1
  5. package/dist/collection/classes/tools/brush-tool.class.js +45 -30
  6. package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
  7. package/dist/components/index.js +3 -3
  8. package/dist/components/kritzel-controls.js +1 -1
  9. package/dist/components/kritzel-editor.js +3 -3
  10. package/dist/components/kritzel-engine.js +1 -1
  11. package/dist/components/{p-Dz2XHHqa.js → p-Bwv1dxAB.js} +47 -32
  12. package/dist/components/{p-Dz2XHHqa.js.map → p-Bwv1dxAB.js.map} +1 -1
  13. package/dist/components/{p-BDX0tuVV.js → p-CIXaR1a8.js} +3 -3
  14. package/dist/components/{p-BDX0tuVV.js.map → p-CIXaR1a8.js.map} +1 -1
  15. package/dist/components/{p-tp96UZ0l.js → p-CRtmNOp1.js} +3 -3
  16. package/dist/components/{p-tp96UZ0l.js.map → p-CRtmNOp1.js.map} +1 -1
  17. package/dist/esm/{default-line-tool.config-D-XCKjDC.js → default-line-tool.config-DJ488kil.js} +47 -32
  18. package/dist/esm/default-line-tool.config-DJ488kil.js.map +1 -0
  19. package/dist/esm/index.js +2 -2
  20. package/dist/esm/kritzel-color_22.entry.js +1 -1
  21. package/dist/stencil/index.esm.js +1 -1
  22. package/dist/stencil/{p-eac6fcb8.entry.js → p-3df115ed.entry.js} +2 -2
  23. package/dist/stencil/p-DJ488kil.js +2 -0
  24. package/dist/stencil/p-DJ488kil.js.map +1 -0
  25. package/dist/stencil/stencil.esm.js +1 -1
  26. package/dist/types/classes/tools/brush-tool.class.d.ts +1 -0
  27. package/package.json +1 -1
  28. package/dist/cjs/default-line-tool.config-DEuVgTP4.js.map +0 -1
  29. package/dist/esm/default-line-tool.config-D-XCKjDC.js.map +0 -1
  30. package/dist/stencil/p-D-XCKjDC.js +0 -2
  31. package/dist/stencil/p-D-XCKjDC.js.map +0 -1
  32. /package/dist/stencil/{p-eac6fcb8.entry.js.map → p-3df115ed.entry.js.map} +0 -0
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { w as writeVarUint, a as writeVarUint8Array, t as toUint8Array, r as readVarUint, b as readVarUint8Array, e as encodeStateAsUpdate, c as applyUpdate, d as encodeStateVector, f as createEncoder, g as createDecoder, s as setIfUndefined, h as create, i as fromBase64, v as varStorage, j as toBase64, o as onChange, k as createUint8ArrayFromArrayBuffer, l as offChange, m as readVarString, O as Observable, n as floor, p as getUnixTime, q as equalityDeep, u as writeVarString, x as map, y as ObservableV2, z as length, A as isNode, B as min, C as pow, H as HocuspocusProvider, D as HocuspocusProviderWebsocket } from './default-line-tool.config-D-XCKjDC.js';
2
- export { V as DEFAULT_BRUSH_CONFIG, X as DEFAULT_LINE_TOOL_CONFIG, W as DEFAULT_TEXT_CONFIG, R as IndexedDBSyncProvider, U as KritzelAnchorManager, S as KritzelAppStateMap, I as KritzelBrushTool, P as KritzelCursorHelper, L as KritzelEraserTool, F as KritzelImage, M as KritzelImageTool, G as KritzelLine, J as KritzelLineTool, E as KritzelPath, Q as KritzelSelectionTool, K as KritzelText, N as KritzelTextTool, T as KritzelWorkspace } from './default-line-tool.config-D-XCKjDC.js';
1
+ import { w as writeVarUint, a as writeVarUint8Array, t as toUint8Array, r as readVarUint, b as readVarUint8Array, e as encodeStateAsUpdate, c as applyUpdate, d as encodeStateVector, f as createEncoder, g as createDecoder, s as setIfUndefined, h as create, i as fromBase64, v as varStorage, j as toBase64, o as onChange, k as createUint8ArrayFromArrayBuffer, l as offChange, m as readVarString, O as Observable, n as floor, p as getUnixTime, q as equalityDeep, u as writeVarString, x as map, y as ObservableV2, z as length, A as isNode, B as min, C as pow, H as HocuspocusProvider, D as HocuspocusProviderWebsocket } from './default-line-tool.config-DJ488kil.js';
2
+ export { V as DEFAULT_BRUSH_CONFIG, X as DEFAULT_LINE_TOOL_CONFIG, W as DEFAULT_TEXT_CONFIG, R as IndexedDBSyncProvider, U as KritzelAnchorManager, S as KritzelAppStateMap, I as KritzelBrushTool, P as KritzelCursorHelper, L as KritzelEraserTool, F as KritzelImage, M as KritzelImageTool, G as KritzelLine, J as KritzelLineTool, E as KritzelPath, Q as KritzelSelectionTool, K as KritzelText, N as KritzelTextTool, T as KritzelWorkspace } from './default-line-tool.config-DJ488kil.js';
3
3
 
4
4
  /**
5
5
  * BroadcastChannel sync provider for cross-tab synchronization
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, h, H as Host, c as createEvent, g as getElement } from './index-SGde3HXB.js';
2
- import { Y as KritzelDevicesHelper, I as KritzelBrushTool, N as KritzelTextTool, Z as KritzelMouseButton, _ as KritzelBaseObject, $ as Schema, a0 as schema, a1 as addListNodes, a2 as EditorView, a3 as EditorState, a4 as keymap, a5 as TextSelection, a6 as KritzelKeyboardHelper, a7 as KritzelToolRegistry, a8 as KritzelGeometryHelper, a9 as baseKeymap, aa as KritzelBaseTool, ab as KritzelEventHelper, Q as KritzelSelectionTool, V as DEFAULT_BRUSH_CONFIG, X as DEFAULT_LINE_TOOL_CONFIG, J as KritzelLineTool, L as KritzelEraserTool, W as DEFAULT_TEXT_CONFIG, M as KritzelImageTool, T as KritzelWorkspace, ac as KritzelIconRegistry, ad as KritzelBaseHandler, ae as KritzelSelectionBox, af as KritzelSelectionGroup, F as KritzelImage, K as KritzelText, G as KritzelLine, E as KritzelPath, ag as Doc, ah as DEFAULT_SYNC_CONFIG, ai as UndoManager, P as KritzelCursorHelper, S as KritzelAppStateMap, U as KritzelAnchorManager, aj as ObjectHelper, ak as KritzelClassHelper } from './default-line-tool.config-D-XCKjDC.js';
2
+ import { Y as KritzelDevicesHelper, I as KritzelBrushTool, N as KritzelTextTool, Z as KritzelMouseButton, _ as KritzelBaseObject, $ as Schema, a0 as schema, a1 as addListNodes, a2 as EditorView, a3 as EditorState, a4 as keymap, a5 as TextSelection, a6 as KritzelKeyboardHelper, a7 as KritzelToolRegistry, a8 as KritzelGeometryHelper, a9 as baseKeymap, aa as KritzelBaseTool, ab as KritzelEventHelper, Q as KritzelSelectionTool, V as DEFAULT_BRUSH_CONFIG, X as DEFAULT_LINE_TOOL_CONFIG, J as KritzelLineTool, L as KritzelEraserTool, W as DEFAULT_TEXT_CONFIG, M as KritzelImageTool, T as KritzelWorkspace, ac as KritzelIconRegistry, ad as KritzelBaseHandler, ae as KritzelSelectionBox, af as KritzelSelectionGroup, F as KritzelImage, K as KritzelText, G as KritzelLine, E as KritzelPath, ag as Doc, ah as DEFAULT_SYNC_CONFIG, ai as UndoManager, P as KritzelCursorHelper, S as KritzelAppStateMap, U as KritzelAnchorManager, aj as ObjectHelper, ak as KritzelClassHelper } from './default-line-tool.config-DJ488kil.js';
3
3
 
4
4
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
5
5
 
@@ -1,2 +1,2 @@
1
- import{w as s,a as t,t as e,r as i,b as n,e as o,c,d as a,f as h,g as r,s as l,h as d,i as u,v as f,j as p,o as m,k as y,l as w,m as k,O as b,n as v,p as g,q as C,u as z,x as $,y as x,z as B,A as H,B as D,C as A,H as O,D as _}from"./p-D-XCKjDC.js";export{V as DEFAULT_BRUSH_CONFIG,X as DEFAULT_LINE_TOOL_CONFIG,W as DEFAULT_TEXT_CONFIG,R as IndexedDBSyncProvider,U as KritzelAnchorManager,S as KritzelAppStateMap,I as KritzelBrushTool,P as KritzelCursorHelper,L as KritzelEraserTool,F as KritzelImage,M as KritzelImageTool,G as KritzelLine,J as KritzelLineTool,E as KritzelPath,Q as KritzelSelectionTool,K as KritzelText,N as KritzelTextTool,T as KritzelWorkspace}from"./p-D-XCKjDC.js";class j{doc;channel;_synced=false;constructor(s,t,e){this.doc=t;this.channel=new BroadcastChannel(s);this.channel.onmessage=s=>{this.handleMessage(s.data)};this.doc.on("update",this.handleDocUpdate);this.broadcastSync();setTimeout((()=>{this._synced=true}),100);console.info(`BroadcastChannel Provider initialized: ${s}`)}handleDocUpdate=(i,n)=>{if(n!==this){const n=h();s(n,0);t(n,i);this.channel.postMessage(e(n))}};handleMessage(a){const l=r(new Uint8Array(a));const d=i(l);switch(d){case 0:const i=n(l);c(this.doc,i,this);break;case 1:this.broadcastSync();break;case 2:const a=n(l);const r=o(this.doc,a);if(r.length>0){const i=h();s(i,0);t(i,r);this.channel.postMessage(e(i))}break}}broadcastSync(){const i=h();s(i,2);t(i,a(this.doc));this.channel.postMessage(e(i))}async connect(){if(this._synced){return}return new Promise((s=>{const t=()=>{if(this._synced){s()}else{setTimeout(t,50)}};t()}))}disconnect(){}destroy(){this.doc.off("update",this.handleDocUpdate);this.channel.close()}}const q=new Map;class Y{constructor(s){this.room=s;this.onmessage=null;this._onChange=t=>t.key===s&&this.onmessage!==null&&this.onmessage({data:u(t.newValue||"")});m(this._onChange)}postMessage(s){f.setItem(this.room,p(y(s)))}close(){w(this._onChange)}}const Z=typeof BroadcastChannel==="undefined"?Y:BroadcastChannel;const ss=s=>l(q,s,(()=>{const t=d();const e=new Z(s);e.onmessage=s=>t.forEach((t=>t(s.data,"broadcastchannel")));return{bc:e,subs:t}}));const ts=(s,t)=>{ss(s).subs.add(t);return t};const es=(s,t)=>{const e=ss(s);const i=e.subs.delete(t);if(i&&e.subs.size===0){e.bc.close();q.delete(s)}return i};const is=(s,t,e=null)=>{const i=ss(s);i.bc.postMessage(t);i.subs.forEach((s=>s(t,e)))};const ns=0;const os=1;const cs=2;const as=(e,i)=>{s(e,ns);const n=a(i);t(e,n)};const hs=(e,i,n)=>{s(e,os);t(e,o(i,n))};const rs=(s,t,e)=>hs(t,e,n(s));const ls=(s,t,e)=>{try{c(t,n(s),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}};const ds=(e,i)=>{s(e,cs);t(e,i)};const us=ls;const fs=(s,t,e,n)=>{const o=i(s);switch(o){case ns:rs(s,t,e);break;case os:ls(s,e,n);break;case cs:us(s,e,n);break;default:throw new Error("Unknown message type")}return o};const ps=0;const ms=(s,t,e)=>{switch(i(s)){case ps:e(t,k(s))}};const ys=3e4;class Ss extends b{constructor(s){super();this.doc=s;this.clientID=s.clientID;this.states=new Map;this.meta=new Map;this._checkInterval=setInterval((()=>{const s=g();if(this.getLocalState()!==null&&ys/2<=s-this.meta.get(this.clientID).lastUpdated){this.setLocalState(this.getLocalState())}const t=[];this.meta.forEach(((e,i)=>{if(i!==this.clientID&&ys<=s-e.lastUpdated&&this.states.has(i)){t.push(i)}}));if(t.length>0){ws(this,t,"timeout")}}),v(ys/10));s.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(s){const t=this.clientID;const e=this.meta.get(t);const i=e===undefined?0:e.clock+1;const n=this.states.get(t);if(s===null){this.states.delete(t)}else{this.states.set(t,s)}this.meta.set(t,{clock:i,lastUpdated:g()});const o=[];const c=[];const a=[];const h=[];if(s===null){h.push(t)}else if(n==null){if(s!=null){o.push(t)}}else{c.push(t);if(!C(n,s)){a.push(t)}}if(o.length>0||a.length>0||h.length>0){this.emit("change",[{added:o,updated:a,removed:h},"local"])}this.emit("update",[{added:o,updated:c,removed:h},"local"])}setLocalStateField(s,t){const e=this.getLocalState();if(e!==null){this.setLocalState({...e,[s]:t})}}getStates(){return this.states}}const ws=(s,t,e)=>{const i=[];for(let e=0;e<t.length;e++){const n=t[e];if(s.states.has(n)){s.states.delete(n);if(n===s.clientID){const t=s.meta.get(n);s.meta.set(n,{clock:t.clock+1,lastUpdated:g()})}i.push(n)}}if(i.length>0){s.emit("change",[{added:[],updated:[],removed:i},e]);s.emit("update",[{added:[],updated:[],removed:i},e])}};const ks=(t,i,n=t.states)=>{const o=i.length;const c=h();s(c,o);for(let e=0;e<o;e++){const o=i[e];const a=n.get(o)||null;const h=t.meta.get(o).clock;s(c,o);s(c,h);z(c,JSON.stringify(a))}return e(c)};const bs=(s,t,e)=>{const n=r(t);const o=g();const c=[];const a=[];const h=[];const l=[];const d=i(n);for(let t=0;t<d;t++){const t=i(n);let e=i(n);const r=JSON.parse(k(n));const d=s.meta.get(t);const u=s.states.get(t);const f=d===undefined?0:d.clock;if(f<e||f===e&&r===null&&s.states.has(t)){if(r===null){if(t===s.clientID&&s.getLocalState()!=null){e++}else{s.states.delete(t)}}else{s.states.set(t,r)}s.meta.set(t,{clock:e,lastUpdated:o});if(d===undefined&&r!==null){c.push(t)}else if(d!==undefined&&r===null){l.push(t)}else if(r!==null){if(!C(r,u)){h.push(t)}a.push(t)}}}if(c.length>0||h.length>0||l.length>0){s.emit("change",[{added:c,updated:h,removed:l},e])}if(c.length>0||a.length>0||l.length>0){s.emit("update",[{added:c,updated:a,removed:l},e])}};const Ts=s=>$(s,((s,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(s)}`)).join("&");const vs=0;const gs=3;const Cs=1;const zs=2;const Ws=[];Ws[vs]=(t,e,i,n,o)=>{s(t,vs);const c=fs(e,t,i.doc,i);if(n&&c===os&&!i.synced){i.synced=true}};Ws[gs]=(e,i,n,o,c)=>{s(e,Cs);t(e,ks(n.awareness,Array.from(n.awareness.getStates().keys())))};Ws[Cs]=(s,t,e,i,o)=>{bs(e.awareness,n(t),e)};Ws[zs]=(s,t,e,i,n)=>{ms(t,e.doc,((s,t)=>Ks(e,t)))};const Is=3e4;const Ks=(s,t)=>console.warn(`Permission denied to access ${s.url}.\n${t}`);const $s=(s,t,e)=>{const n=r(t);const o=h();const c=i(n);const a=s.messageHandlers[c];if(a){a(o,n,s,e,c)}else{console.error("Unable to compute message")}return o};const Us=(s,t,e)=>{if(t===s.ws){s.emit("connection-close",[e,s]);s.ws=null;t.close();s.wsconnecting=false;if(s.wsconnected){s.wsconnected=false;s.synced=false;ws(s.awareness,Array.from(s.awareness.getStates().keys()).filter((t=>t!==s.doc.clientID)),s);s.emit("status",[{status:"disconnected"}])}else{s.wsUnsuccessfulReconnects++}setTimeout(xs,D(A(2,s.wsUnsuccessfulReconnects)*100,s.maxBackoffTime),s)}};const xs=i=>{if(i.shouldConnect&&i.ws===null){const n=new i._WS(i.url,i.protocols);n.binaryType="arraybuffer";i.ws=n;i.wsconnecting=true;i.wsconnected=false;i.synced=false;n.onmessage=s=>{i.wsLastMessageReceived=g();const t=$s(i,new Uint8Array(s.data),true);if(B(t)>1){n.send(e(t))}};n.onerror=s=>{i.emit("connection-error",[s,i])};n.onclose=s=>{Us(i,n,s)};n.onopen=()=>{i.wsLastMessageReceived=g();i.wsconnecting=false;i.wsconnected=true;i.wsUnsuccessfulReconnects=0;i.emit("status",[{status:"connected"}]);const o=h();s(o,vs);as(o,i.doc);n.send(e(o));if(i.awareness.getLocalState()!==null){const o=h();s(o,Cs);t(o,ks(i.awareness,[i.doc.clientID]));n.send(e(o))}};i.emit("status",[{status:"connecting"}])}};const Ps=(s,t)=>{const e=s.ws;if(s.wsconnected&&e&&e.readyState===e.OPEN){e.send(t)}if(s.bcconnected){is(s.bcChannel,t,s)}};class Bs extends x{constructor(i,n,o,{connect:c=true,awareness:a=new Ss(o),params:r={},protocols:l=[],WebSocketPolyfill:d=WebSocket,resyncInterval:u=-1,maxBackoffTime:f=2500,disableBc:p=false}={}){super();while(i[i.length-1]==="/"){i=i.slice(0,i.length-1)}this.serverUrl=i;this.bcChannel=i+"/"+n;this.maxBackoffTime=f;this.params=r;this.protocols=l;this.roomname=n;this.doc=o;this._WS=d;this.awareness=a;this.wsconnected=false;this.wsconnecting=false;this.bcconnected=false;this.disableBc=p;this.wsUnsuccessfulReconnects=0;this.messageHandlers=Ws.slice();this._synced=false;this.ws=null;this.wsLastMessageReceived=0;this.shouldConnect=c;this._resyncInterval=0;if(u>0){this._resyncInterval=setInterval((()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const t=h();s(t,vs);as(t,o);this.ws.send(e(t))}}),u)}this._bcSubscriber=(s,t)=>{if(t!==this){const t=$s(this,new Uint8Array(s),false);if(B(t)>1){is(this.bcChannel,e(t),this)}}};this._updateHandler=(t,i)=>{if(i!==this){const i=h();s(i,vs);ds(i,t);Ps(this,e(i))}};this.doc.on("update",this._updateHandler);this._awarenessUpdateHandler=({added:i,updated:n,removed:o},c)=>{const r=i.concat(n).concat(o);const l=h();s(l,Cs);t(l,ks(a,r));Ps(this,e(l))};this._exitHandler=()=>{ws(this.awareness,[o.clientID],"app closed")};if(H&&typeof process!=="undefined"){process.on("exit",this._exitHandler)}a.on("update",this._awarenessUpdateHandler);this._checkInterval=setInterval((()=>{if(this.wsconnected&&Is<g()-this.wsLastMessageReceived){Us(this,this.ws,null)}}),Is/10);if(c){this.connect()}}get url(){const s=Ts(this.params);return this.serverUrl+"/"+this.roomname+(s.length===0?"":"?"+s)}get synced(){return this._synced}set synced(s){if(this._synced!==s){this._synced=s;this.emit("synced",[s]);this.emit("sync",[s])}}destroy(){if(this._resyncInterval!==0){clearInterval(this._resyncInterval)}clearInterval(this._checkInterval);this.disconnect();if(H&&typeof process!=="undefined"){process.off("exit",this._exitHandler)}this.awareness.off("update",this._awarenessUpdateHandler);this.doc.off("update",this._updateHandler);super.destroy()}connectBc(){if(this.disableBc){return}if(!this.bcconnected){ts(this.bcChannel,this._bcSubscriber);this.bcconnected=true}const i=h();s(i,vs);as(i,this.doc);is(this.bcChannel,e(i),this);const n=h();s(n,vs);hs(n,this.doc);is(this.bcChannel,e(n),this);const o=h();s(o,gs);is(this.bcChannel,e(o),this);const c=h();s(c,Cs);t(c,ks(this.awareness,[this.doc.clientID]));is(this.bcChannel,e(c),this)}disconnectBc(){const i=h();s(i,Cs);t(i,ks(this.awareness,[this.doc.clientID],new Map));Ps(this,e(i));if(this.bcconnected){es(this.bcChannel,this._bcSubscriber);this.bcconnected=false}}disconnect(){this.shouldConnect=false;this.disconnectBc();if(this.ws!==null){Us(this,this.ws,null)}}connect(){this.shouldConnect=true;if(!this.wsconnected&&this.ws===null){xs(this);this.connectBc()}}}class Hs{provider;isConnected=false;constructor(s,t,e){const i=e?.url||"ws://localhost:1234";const n=e?.roomName||s;this.provider=new Bs(i,n,t,{params:e?.params,protocols:e?.protocols,WebSocketPolyfill:e?.WebSocketPolyfill,awareness:e?.awareness,maxBackoffTime:e?.maxBackoffTime,disableBc:true});this.setupEventListeners();console.info(`WebSocket Provider initialized: ${i}/${n}`)}static with(s){return{create:(t,e)=>new Hs(t,e,s)}}setupEventListeners(){this.provider.on("status",(({status:s})=>{if(s==="connected"){this.isConnected=true;console.info("WebSocket connected")}else if(s==="disconnected"){this.isConnected=false;console.info("WebSocket disconnected")}}));this.provider.on("sync",(s=>{if(s){console.info("WebSocket synced")}}))}async connect(){if(this.isConnected){return}return new Promise(((s,t)=>{const e=setTimeout((()=>{t(new Error("WebSocket connection timeout"))}),1e4);const i=({status:t})=>{if(t==="connected"){clearTimeout(e);this.provider.off("status",i);this.isConnected=true;s()}};this.provider.on("status",i);if(this.provider.wsconnected){clearTimeout(e);this.provider.off("status",i);this.isConnected=true;s()}}))}disconnect(){if(this.provider){this.provider.disconnect()}this.isConnected=false}destroy(){if(this.provider){this.provider.destroy()}this.isConnected=false}}class Ds{provider;isConnected=false;isSynced=false;usesSharedSocket=false;static sharedWebSocketProvider=null;constructor(s,t,e){const i=e?.name||s;const n=e?.url||"ws://localhost:1234";const o=e?.websocketProvider||Ds.sharedWebSocketProvider;if(o){this.usesSharedSocket=true;const s={websocketProvider:o,name:i,document:t,token:e?.token||null,onConnect:()=>{this.isConnected=true;if(!e?.quiet){console.info(`Hocuspocus connected: ${i}`)}if(e?.onConnect){e.onConnect()}},onDisconnect:()=>{this.isConnected=false;this.isSynced=false;if(!e?.quiet){console.info(`Hocuspocus disconnected: ${i}`)}if(e?.onDisconnect){e.onDisconnect()}},onSynced:()=>{this.isSynced=true;if(!e?.quiet){console.info(`Hocuspocus synced: ${i}`)}if(e?.onSynced){e.onSynced()}}};if(e?.forceSyncInterval!==undefined){s.forceSyncInterval=e.forceSyncInterval}if(e?.onAuthenticationFailed){s.onAuthenticationFailed=e.onAuthenticationFailed}if(e?.onStatus){s.onStatus=e.onStatus}this.provider=new O(s);this.provider.attach();if(!e?.quiet){console.info(`Hocuspocus Provider initialized (multiplexed): ${i}`)}}else{this.usesSharedSocket=false;const s={url:n,name:i,document:t,token:e?.token||null,onConnect:()=>{this.isConnected=true;if(!e?.quiet){console.info(`Hocuspocus connected: ${i}`)}if(e?.onConnect){e.onConnect()}},onDisconnect:()=>{this.isConnected=false;this.isSynced=false;if(!e?.quiet){console.info(`Hocuspocus disconnected: ${i}`)}if(e?.onDisconnect){e.onDisconnect()}},onSynced:()=>{this.isSynced=true;if(!e?.quiet){console.info(`Hocuspocus synced: ${i}`)}if(e?.onSynced){e.onSynced()}}};if(e?.forceSyncInterval!==undefined){s.forceSyncInterval=e.forceSyncInterval}if(e?.onAuthenticationFailed){s.onAuthenticationFailed=e.onAuthenticationFailed}if(e?.onStatus){s.onStatus=e.onStatus}if(e?.WebSocketPolyfill){s.WebSocketPolyfill=e.WebSocketPolyfill}this.provider=new O(s);if(!e?.quiet){console.info(`Hocuspocus Provider initialized: ${n}/${i}`)}}}static createSharedWebSocket(s){if(Ds.sharedWebSocketProvider){console.warn("Shared WebSocket already exists. Returning existing instance.");return Ds.sharedWebSocketProvider}const t={url:s.url};if(s.WebSocketPolyfill){t.WebSocketPolyfill=s.WebSocketPolyfill}if(s.onConnect){t.onConnect=s.onConnect}if(s.onDisconnect){t.onDisconnect=s.onDisconnect}if(s.onStatus){t.onStatus=s.onStatus}Ds.sharedWebSocketProvider=new _(t);console.info(`Shared Hocuspocus WebSocket created: ${s.url}`);return Ds.sharedWebSocketProvider}static destroySharedWebSocket(){if(Ds.sharedWebSocketProvider){Ds.sharedWebSocketProvider.destroy();Ds.sharedWebSocketProvider=null;console.info("Shared Hocuspocus WebSocket destroyed")}}static getSharedWebSocket(){return Ds.sharedWebSocketProvider}static with(s){return{create:(t,e)=>new Ds(t,e,s)}}async connect(){if(this.isSynced){return}return new Promise(((s,t)=>{const e=setTimeout((()=>{t(new Error("Hocuspocus connection timeout"))}),1e4);const i=()=>{clearTimeout(e);this.provider.off("synced",i);s()};this.provider.on("synced",i);if(this.provider.isSynced){clearTimeout(e);this.provider.off("synced",i);s();return}if(!this.isConnected&&!this.usesSharedSocket){this.provider.connect()}}))}disconnect(){if(this.provider){if(this.usesSharedSocket){this.provider.detach()}else{this.provider.disconnect()}}this.isConnected=false;this.isSynced=false}destroy(){if(this.provider){this.provider.destroy()}this.isConnected=false;this.isSynced=false}}export{j as BroadcastSyncProvider,Ds as HocuspocusSyncProvider,Hs as WebSocketSyncProvider};
1
+ import{w as s,a as t,t as e,r as i,b as n,e as o,c,d as a,f as h,g as r,s as l,h as d,i as u,v as f,j as p,o as m,k as y,l as w,m as k,O as b,n as v,p as g,q as z,u as $,x as C,y as x,z as B,A as H,B as A,C as D,H as O,D as _}from"./p-DJ488kil.js";export{V as DEFAULT_BRUSH_CONFIG,X as DEFAULT_LINE_TOOL_CONFIG,W as DEFAULT_TEXT_CONFIG,R as IndexedDBSyncProvider,U as KritzelAnchorManager,S as KritzelAppStateMap,I as KritzelBrushTool,P as KritzelCursorHelper,L as KritzelEraserTool,F as KritzelImage,M as KritzelImageTool,G as KritzelLine,J as KritzelLineTool,E as KritzelPath,Q as KritzelSelectionTool,K as KritzelText,N as KritzelTextTool,T as KritzelWorkspace}from"./p-DJ488kil.js";class j{doc;channel;_synced=false;constructor(s,t,e){this.doc=t;this.channel=new BroadcastChannel(s);this.channel.onmessage=s=>{this.handleMessage(s.data)};this.doc.on("update",this.handleDocUpdate);this.broadcastSync();setTimeout((()=>{this._synced=true}),100);console.info(`BroadcastChannel Provider initialized: ${s}`)}handleDocUpdate=(i,n)=>{if(n!==this){const n=h();s(n,0);t(n,i);this.channel.postMessage(e(n))}};handleMessage(a){const l=r(new Uint8Array(a));const d=i(l);switch(d){case 0:const i=n(l);c(this.doc,i,this);break;case 1:this.broadcastSync();break;case 2:const a=n(l);const r=o(this.doc,a);if(r.length>0){const i=h();s(i,0);t(i,r);this.channel.postMessage(e(i))}break}}broadcastSync(){const i=h();s(i,2);t(i,a(this.doc));this.channel.postMessage(e(i))}async connect(){if(this._synced){return}return new Promise((s=>{const t=()=>{if(this._synced){s()}else{setTimeout(t,50)}};t()}))}disconnect(){}destroy(){this.doc.off("update",this.handleDocUpdate);this.channel.close()}}const q=new Map;class Y{constructor(s){this.room=s;this.onmessage=null;this._onChange=t=>t.key===s&&this.onmessage!==null&&this.onmessage({data:u(t.newValue||"")});m(this._onChange)}postMessage(s){f.setItem(this.room,p(y(s)))}close(){w(this._onChange)}}const Z=typeof BroadcastChannel==="undefined"?Y:BroadcastChannel;const ss=s=>l(q,s,(()=>{const t=d();const e=new Z(s);e.onmessage=s=>t.forEach((t=>t(s.data,"broadcastchannel")));return{bc:e,subs:t}}));const ts=(s,t)=>{ss(s).subs.add(t);return t};const es=(s,t)=>{const e=ss(s);const i=e.subs.delete(t);if(i&&e.subs.size===0){e.bc.close();q.delete(s)}return i};const is=(s,t,e=null)=>{const i=ss(s);i.bc.postMessage(t);i.subs.forEach((s=>s(t,e)))};const ns=0;const os=1;const cs=2;const as=(e,i)=>{s(e,ns);const n=a(i);t(e,n)};const hs=(e,i,n)=>{s(e,os);t(e,o(i,n))};const rs=(s,t,e)=>hs(t,e,n(s));const ls=(s,t,e)=>{try{c(t,n(s),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}};const ds=(e,i)=>{s(e,cs);t(e,i)};const us=ls;const fs=(s,t,e,n)=>{const o=i(s);switch(o){case ns:rs(s,t,e);break;case os:ls(s,e,n);break;case cs:us(s,e,n);break;default:throw new Error("Unknown message type")}return o};const ps=0;const ms=(s,t,e)=>{switch(i(s)){case ps:e(t,k(s))}};const ys=3e4;class Ss extends b{constructor(s){super();this.doc=s;this.clientID=s.clientID;this.states=new Map;this.meta=new Map;this._checkInterval=setInterval((()=>{const s=g();if(this.getLocalState()!==null&&ys/2<=s-this.meta.get(this.clientID).lastUpdated){this.setLocalState(this.getLocalState())}const t=[];this.meta.forEach(((e,i)=>{if(i!==this.clientID&&ys<=s-e.lastUpdated&&this.states.has(i)){t.push(i)}}));if(t.length>0){ws(this,t,"timeout")}}),v(ys/10));s.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(s){const t=this.clientID;const e=this.meta.get(t);const i=e===undefined?0:e.clock+1;const n=this.states.get(t);if(s===null){this.states.delete(t)}else{this.states.set(t,s)}this.meta.set(t,{clock:i,lastUpdated:g()});const o=[];const c=[];const a=[];const h=[];if(s===null){h.push(t)}else if(n==null){if(s!=null){o.push(t)}}else{c.push(t);if(!z(n,s)){a.push(t)}}if(o.length>0||a.length>0||h.length>0){this.emit("change",[{added:o,updated:a,removed:h},"local"])}this.emit("update",[{added:o,updated:c,removed:h},"local"])}setLocalStateField(s,t){const e=this.getLocalState();if(e!==null){this.setLocalState({...e,[s]:t})}}getStates(){return this.states}}const ws=(s,t,e)=>{const i=[];for(let e=0;e<t.length;e++){const n=t[e];if(s.states.has(n)){s.states.delete(n);if(n===s.clientID){const t=s.meta.get(n);s.meta.set(n,{clock:t.clock+1,lastUpdated:g()})}i.push(n)}}if(i.length>0){s.emit("change",[{added:[],updated:[],removed:i},e]);s.emit("update",[{added:[],updated:[],removed:i},e])}};const ks=(t,i,n=t.states)=>{const o=i.length;const c=h();s(c,o);for(let e=0;e<o;e++){const o=i[e];const a=n.get(o)||null;const h=t.meta.get(o).clock;s(c,o);s(c,h);$(c,JSON.stringify(a))}return e(c)};const bs=(s,t,e)=>{const n=r(t);const o=g();const c=[];const a=[];const h=[];const l=[];const d=i(n);for(let t=0;t<d;t++){const t=i(n);let e=i(n);const r=JSON.parse(k(n));const d=s.meta.get(t);const u=s.states.get(t);const f=d===undefined?0:d.clock;if(f<e||f===e&&r===null&&s.states.has(t)){if(r===null){if(t===s.clientID&&s.getLocalState()!=null){e++}else{s.states.delete(t)}}else{s.states.set(t,r)}s.meta.set(t,{clock:e,lastUpdated:o});if(d===undefined&&r!==null){c.push(t)}else if(d!==undefined&&r===null){l.push(t)}else if(r!==null){if(!z(r,u)){h.push(t)}a.push(t)}}}if(c.length>0||h.length>0||l.length>0){s.emit("change",[{added:c,updated:h,removed:l},e])}if(c.length>0||a.length>0||l.length>0){s.emit("update",[{added:c,updated:a,removed:l},e])}};const Ts=s=>C(s,((s,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(s)}`)).join("&");const vs=0;const gs=3;const zs=1;const Ws=2;const Is=[];Is[vs]=(t,e,i,n,o)=>{s(t,vs);const c=fs(e,t,i.doc,i);if(n&&c===os&&!i.synced){i.synced=true}};Is[gs]=(e,i,n,o,c)=>{s(e,zs);t(e,ks(n.awareness,Array.from(n.awareness.getStates().keys())))};Is[zs]=(s,t,e,i,o)=>{bs(e.awareness,n(t),e)};Is[Ws]=(s,t,e,i,n)=>{ms(t,e.doc,((s,t)=>Cs(e,t)))};const $s=3e4;const Cs=(s,t)=>console.warn(`Permission denied to access ${s.url}.\n${t}`);const Us=(s,t,e)=>{const n=r(t);const o=h();const c=i(n);const a=s.messageHandlers[c];if(a){a(o,n,s,e,c)}else{console.error("Unable to compute message")}return o};const xs=(s,t,e)=>{if(t===s.ws){s.emit("connection-close",[e,s]);s.ws=null;t.close();s.wsconnecting=false;if(s.wsconnected){s.wsconnected=false;s.synced=false;ws(s.awareness,Array.from(s.awareness.getStates().keys()).filter((t=>t!==s.doc.clientID)),s);s.emit("status",[{status:"disconnected"}])}else{s.wsUnsuccessfulReconnects++}setTimeout(Ks,A(D(2,s.wsUnsuccessfulReconnects)*100,s.maxBackoffTime),s)}};const Ks=i=>{if(i.shouldConnect&&i.ws===null){const n=new i._WS(i.url,i.protocols);n.binaryType="arraybuffer";i.ws=n;i.wsconnecting=true;i.wsconnected=false;i.synced=false;n.onmessage=s=>{i.wsLastMessageReceived=g();const t=Us(i,new Uint8Array(s.data),true);if(B(t)>1){n.send(e(t))}};n.onerror=s=>{i.emit("connection-error",[s,i])};n.onclose=s=>{xs(i,n,s)};n.onopen=()=>{i.wsLastMessageReceived=g();i.wsconnecting=false;i.wsconnected=true;i.wsUnsuccessfulReconnects=0;i.emit("status",[{status:"connected"}]);const o=h();s(o,vs);as(o,i.doc);n.send(e(o));if(i.awareness.getLocalState()!==null){const o=h();s(o,zs);t(o,ks(i.awareness,[i.doc.clientID]));n.send(e(o))}};i.emit("status",[{status:"connecting"}])}};const Ps=(s,t)=>{const e=s.ws;if(s.wsconnected&&e&&e.readyState===e.OPEN){e.send(t)}if(s.bcconnected){is(s.bcChannel,t,s)}};class Bs extends x{constructor(i,n,o,{connect:c=true,awareness:a=new Ss(o),params:r={},protocols:l=[],WebSocketPolyfill:d=WebSocket,resyncInterval:u=-1,maxBackoffTime:f=2500,disableBc:p=false}={}){super();while(i[i.length-1]==="/"){i=i.slice(0,i.length-1)}this.serverUrl=i;this.bcChannel=i+"/"+n;this.maxBackoffTime=f;this.params=r;this.protocols=l;this.roomname=n;this.doc=o;this._WS=d;this.awareness=a;this.wsconnected=false;this.wsconnecting=false;this.bcconnected=false;this.disableBc=p;this.wsUnsuccessfulReconnects=0;this.messageHandlers=Is.slice();this._synced=false;this.ws=null;this.wsLastMessageReceived=0;this.shouldConnect=c;this._resyncInterval=0;if(u>0){this._resyncInterval=setInterval((()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const t=h();s(t,vs);as(t,o);this.ws.send(e(t))}}),u)}this._bcSubscriber=(s,t)=>{if(t!==this){const t=Us(this,new Uint8Array(s),false);if(B(t)>1){is(this.bcChannel,e(t),this)}}};this._updateHandler=(t,i)=>{if(i!==this){const i=h();s(i,vs);ds(i,t);Ps(this,e(i))}};this.doc.on("update",this._updateHandler);this._awarenessUpdateHandler=({added:i,updated:n,removed:o},c)=>{const r=i.concat(n).concat(o);const l=h();s(l,zs);t(l,ks(a,r));Ps(this,e(l))};this._exitHandler=()=>{ws(this.awareness,[o.clientID],"app closed")};if(H&&typeof process!=="undefined"){process.on("exit",this._exitHandler)}a.on("update",this._awarenessUpdateHandler);this._checkInterval=setInterval((()=>{if(this.wsconnected&&$s<g()-this.wsLastMessageReceived){xs(this,this.ws,null)}}),$s/10);if(c){this.connect()}}get url(){const s=Ts(this.params);return this.serverUrl+"/"+this.roomname+(s.length===0?"":"?"+s)}get synced(){return this._synced}set synced(s){if(this._synced!==s){this._synced=s;this.emit("synced",[s]);this.emit("sync",[s])}}destroy(){if(this._resyncInterval!==0){clearInterval(this._resyncInterval)}clearInterval(this._checkInterval);this.disconnect();if(H&&typeof process!=="undefined"){process.off("exit",this._exitHandler)}this.awareness.off("update",this._awarenessUpdateHandler);this.doc.off("update",this._updateHandler);super.destroy()}connectBc(){if(this.disableBc){return}if(!this.bcconnected){ts(this.bcChannel,this._bcSubscriber);this.bcconnected=true}const i=h();s(i,vs);as(i,this.doc);is(this.bcChannel,e(i),this);const n=h();s(n,vs);hs(n,this.doc);is(this.bcChannel,e(n),this);const o=h();s(o,gs);is(this.bcChannel,e(o),this);const c=h();s(c,zs);t(c,ks(this.awareness,[this.doc.clientID]));is(this.bcChannel,e(c),this)}disconnectBc(){const i=h();s(i,zs);t(i,ks(this.awareness,[this.doc.clientID],new Map));Ps(this,e(i));if(this.bcconnected){es(this.bcChannel,this._bcSubscriber);this.bcconnected=false}}disconnect(){this.shouldConnect=false;this.disconnectBc();if(this.ws!==null){xs(this,this.ws,null)}}connect(){this.shouldConnect=true;if(!this.wsconnected&&this.ws===null){Ks(this);this.connectBc()}}}class Hs{provider;isConnected=false;constructor(s,t,e){const i=e?.url||"ws://localhost:1234";const n=e?.roomName||s;this.provider=new Bs(i,n,t,{params:e?.params,protocols:e?.protocols,WebSocketPolyfill:e?.WebSocketPolyfill,awareness:e?.awareness,maxBackoffTime:e?.maxBackoffTime,disableBc:true});this.setupEventListeners();console.info(`WebSocket Provider initialized: ${i}/${n}`)}static with(s){return{create:(t,e)=>new Hs(t,e,s)}}setupEventListeners(){this.provider.on("status",(({status:s})=>{if(s==="connected"){this.isConnected=true;console.info("WebSocket connected")}else if(s==="disconnected"){this.isConnected=false;console.info("WebSocket disconnected")}}));this.provider.on("sync",(s=>{if(s){console.info("WebSocket synced")}}))}async connect(){if(this.isConnected){return}return new Promise(((s,t)=>{const e=setTimeout((()=>{t(new Error("WebSocket connection timeout"))}),1e4);const i=({status:t})=>{if(t==="connected"){clearTimeout(e);this.provider.off("status",i);this.isConnected=true;s()}};this.provider.on("status",i);if(this.provider.wsconnected){clearTimeout(e);this.provider.off("status",i);this.isConnected=true;s()}}))}disconnect(){if(this.provider){this.provider.disconnect()}this.isConnected=false}destroy(){if(this.provider){this.provider.destroy()}this.isConnected=false}}class Ls{provider;isConnected=false;isSynced=false;usesSharedSocket=false;static sharedWebSocketProvider=null;constructor(s,t,e){const i=e?.name||s;const n=e?.url||"ws://localhost:1234";const o=e?.websocketProvider||Ls.sharedWebSocketProvider;if(o){this.usesSharedSocket=true;const s={websocketProvider:o,name:i,document:t,token:e?.token||null,onConnect:()=>{this.isConnected=true;if(!e?.quiet){console.info(`Hocuspocus connected: ${i}`)}if(e?.onConnect){e.onConnect()}},onDisconnect:()=>{this.isConnected=false;this.isSynced=false;if(!e?.quiet){console.info(`Hocuspocus disconnected: ${i}`)}if(e?.onDisconnect){e.onDisconnect()}},onSynced:()=>{this.isSynced=true;if(!e?.quiet){console.info(`Hocuspocus synced: ${i}`)}if(e?.onSynced){e.onSynced()}}};if(e?.forceSyncInterval!==undefined){s.forceSyncInterval=e.forceSyncInterval}if(e?.onAuthenticationFailed){s.onAuthenticationFailed=e.onAuthenticationFailed}if(e?.onStatus){s.onStatus=e.onStatus}this.provider=new O(s);this.provider.attach();if(!e?.quiet){console.info(`Hocuspocus Provider initialized (multiplexed): ${i}`)}}else{this.usesSharedSocket=false;const s={url:n,name:i,document:t,token:e?.token||null,onConnect:()=>{this.isConnected=true;if(!e?.quiet){console.info(`Hocuspocus connected: ${i}`)}if(e?.onConnect){e.onConnect()}},onDisconnect:()=>{this.isConnected=false;this.isSynced=false;if(!e?.quiet){console.info(`Hocuspocus disconnected: ${i}`)}if(e?.onDisconnect){e.onDisconnect()}},onSynced:()=>{this.isSynced=true;if(!e?.quiet){console.info(`Hocuspocus synced: ${i}`)}if(e?.onSynced){e.onSynced()}}};if(e?.forceSyncInterval!==undefined){s.forceSyncInterval=e.forceSyncInterval}if(e?.onAuthenticationFailed){s.onAuthenticationFailed=e.onAuthenticationFailed}if(e?.onStatus){s.onStatus=e.onStatus}if(e?.WebSocketPolyfill){s.WebSocketPolyfill=e.WebSocketPolyfill}this.provider=new O(s);if(!e?.quiet){console.info(`Hocuspocus Provider initialized: ${n}/${i}`)}}}static createSharedWebSocket(s){if(Ls.sharedWebSocketProvider){console.warn("Shared WebSocket already exists. Returning existing instance.");return Ls.sharedWebSocketProvider}const t={url:s.url};if(s.WebSocketPolyfill){t.WebSocketPolyfill=s.WebSocketPolyfill}if(s.onConnect){t.onConnect=s.onConnect}if(s.onDisconnect){t.onDisconnect=s.onDisconnect}if(s.onStatus){t.onStatus=s.onStatus}Ls.sharedWebSocketProvider=new _(t);console.info(`Shared Hocuspocus WebSocket created: ${s.url}`);return Ls.sharedWebSocketProvider}static destroySharedWebSocket(){if(Ls.sharedWebSocketProvider){Ls.sharedWebSocketProvider.destroy();Ls.sharedWebSocketProvider=null;console.info("Shared Hocuspocus WebSocket destroyed")}}static getSharedWebSocket(){return Ls.sharedWebSocketProvider}static with(s){return{create:(t,e)=>new Ls(t,e,s)}}async connect(){if(this.isSynced){return}return new Promise(((s,t)=>{const e=setTimeout((()=>{t(new Error("Hocuspocus connection timeout"))}),1e4);const i=()=>{clearTimeout(e);this.provider.off("synced",i);s()};this.provider.on("synced",i);if(this.provider.isSynced){clearTimeout(e);this.provider.off("synced",i);s();return}if(!this.isConnected&&!this.usesSharedSocket){this.provider.connect()}}))}disconnect(){if(this.provider){if(this.usesSharedSocket){this.provider.detach()}else{this.provider.disconnect()}}this.isConnected=false;this.isSynced=false}destroy(){if(this.provider){this.provider.destroy()}this.isConnected=false;this.isSynced=false}}export{j as BroadcastSyncProvider,Ls as HocuspocusSyncProvider,Hs as WebSocketSyncProvider};
2
2
  //# sourceMappingURL=index.esm.js.map