kritzel-stencil 0.0.151 → 0.0.153
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/dist/cjs/{default-text-tool.config-BX6sjin6.js → default-text-tool.config-Cds94FE8.js} +18 -3
- package/dist/cjs/default-text-tool.config-Cds94FE8.js.map +1 -0
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/kritzel-color_22.cjs.entry.js +26 -21
- package/dist/collection/classes/core/viewport.class.js +10 -9
- package/dist/collection/classes/core/viewport.class.js.map +1 -1
- package/dist/collection/classes/objects/base-object.class.js +6 -0
- package/dist/collection/classes/objects/base-object.class.js.map +1 -1
- package/dist/collection/classes/objects/path.class.js +10 -1
- package/dist/collection/classes/objects/path.class.js.map +1 -1
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +15 -10
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
- package/dist/collection/configs/default-engine-config.js +0 -1
- package/dist/collection/configs/default-engine-config.js.map +1 -1
- package/dist/collection/interfaces/engine-state.interface.js.map +1 -1
- package/dist/components/index.js +3 -3
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-editor.js +3 -3
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/{p-D6oQxYXs.js → p-BDvBsqPy.js} +28 -23
- package/dist/components/p-BDvBsqPy.js.map +1 -0
- package/dist/components/{p-G2HGJcNm.js → p-BJ-T4laL.js} +18 -3
- package/dist/components/{p-G2HGJcNm.js.map → p-BJ-T4laL.js.map} +1 -1
- package/dist/components/{p-BP71Fape.js → p-CcqEzr-v.js} +3 -3
- package/dist/components/{p-BP71Fape.js.map → p-CcqEzr-v.js.map} +1 -1
- package/dist/esm/{default-text-tool.config-Bcel-KfG.js → default-text-tool.config-ClW1W-X4.js} +18 -3
- package/dist/esm/default-text-tool.config-ClW1W-X4.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/kritzel-color_22.entry.js +26 -21
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/{p-7d732b05.entry.js → p-843d013b.entry.js} +3 -3
- package/dist/stencil/{p-7d732b05.entry.js.map → p-843d013b.entry.js.map} +1 -1
- package/dist/stencil/{p-Bcel-KfG.js → p-ClW1W-X4.js} +2 -2
- package/dist/stencil/p-ClW1W-X4.js.map +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/core/viewport.class.d.ts +1 -0
- package/dist/types/classes/objects/path.class.d.ts +1 -0
- package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +1 -0
- package/dist/types/interfaces/engine-state.interface.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/default-text-tool.config-BX6sjin6.js.map +0 -1
- package/dist/components/p-D6oQxYXs.js.map +0 -1
- package/dist/esm/default-text-tool.config-Bcel-KfG.js.map +0 -1
- package/dist/stencil/p-Bcel-KfG.js.map +0 -1
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-text-tool.config-
|
|
2
|
-
export { R as DEFAULT_BRUSH_CONFIG, S as DEFAULT_TEXT_CONFIG, N as IndexedDBSyncProvider, P as KritzelAppStateMap, G as KritzelBrushTool, I as KritzelEraserTool, F as KritzelImage, J as KritzelImageTool, E as KritzelPath, M as KritzelSelectionTool, K as KritzelText, L as KritzelTextTool, Q as KritzelWorkspace } from './default-text-tool.config-
|
|
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-text-tool.config-ClW1W-X4.js';
|
|
2
|
+
export { R as DEFAULT_BRUSH_CONFIG, S as DEFAULT_TEXT_CONFIG, N as IndexedDBSyncProvider, P as KritzelAppStateMap, G as KritzelBrushTool, I as KritzelEraserTool, F as KritzelImage, J as KritzelImageTool, E as KritzelPath, M as KritzelSelectionTool, K as KritzelText, L as KritzelTextTool, Q as KritzelWorkspace } from './default-text-tool.config-ClW1W-X4.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 { T as KritzelDevicesHelper, G as KritzelBrushTool, L as KritzelTextTool, U as KritzelMouseButton, M as KritzelSelectionTool, R as DEFAULT_BRUSH_CONFIG, I as KritzelEraserTool, S as DEFAULT_TEXT_CONFIG, J as KritzelImageTool, Q as KritzelWorkspace, V as KritzelKeyboardHelper, W as KritzelBaseHandler, X as KritzelToolRegistry, Y as KritzelSelectionBox, Z as KritzelSelectionGroup, _ as KritzelBaseObject, F as KritzelImage, K as KritzelText, E as KritzelPath, $ as Doc, a0 as DEFAULT_SYNC_CONFIG, a1 as UndoManager, P as KritzelAppStateMap, a2 as ObjectHelper, a3 as KritzelEventHelper, a4 as KritzelBaseTool } from './default-text-tool.config-
|
|
2
|
+
import { T as KritzelDevicesHelper, G as KritzelBrushTool, L as KritzelTextTool, U as KritzelMouseButton, M as KritzelSelectionTool, R as DEFAULT_BRUSH_CONFIG, I as KritzelEraserTool, S as DEFAULT_TEXT_CONFIG, J as KritzelImageTool, Q as KritzelWorkspace, V as KritzelKeyboardHelper, W as KritzelBaseHandler, X as KritzelToolRegistry, Y as KritzelSelectionBox, Z as KritzelSelectionGroup, _ as KritzelBaseObject, F as KritzelImage, K as KritzelText, E as KritzelPath, $ as Doc, a0 as DEFAULT_SYNC_CONFIG, a1 as UndoManager, P as KritzelAppStateMap, a2 as ObjectHelper, a3 as KritzelEventHelper, a4 as KritzelBaseTool } from './default-text-tool.config-ClW1W-X4.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
|
|
|
@@ -18057,6 +18057,7 @@ var lodashExports = requireLodash();
|
|
|
18057
18057
|
class KritzelViewport {
|
|
18058
18058
|
_core;
|
|
18059
18059
|
_debounceUpdate;
|
|
18060
|
+
_debounceEndScaling;
|
|
18060
18061
|
initialTouchDistance = 0;
|
|
18061
18062
|
startX = 0;
|
|
18062
18063
|
startY = 0;
|
|
@@ -18072,6 +18073,10 @@ class KritzelViewport {
|
|
|
18072
18073
|
this._debounceUpdate = lodashExports.debounce(() => {
|
|
18073
18074
|
this._core.updateWorkspaceViewport(this._core.store.state.translateX, this._core.store.state.translateY, this._core.store.state.scale);
|
|
18074
18075
|
}, 300);
|
|
18076
|
+
this._debounceEndScaling = lodashExports.debounce(() => {
|
|
18077
|
+
this._core.store.state.isScaling = false;
|
|
18078
|
+
this._core.rerender();
|
|
18079
|
+
}, 100);
|
|
18075
18080
|
}
|
|
18076
18081
|
handleResize() {
|
|
18077
18082
|
this._core.store.state.viewportWidth = this._core.store.state.host.clientWidth;
|
|
@@ -18174,10 +18179,7 @@ class KritzelViewport {
|
|
|
18174
18179
|
}
|
|
18175
18180
|
if (event.pointerType === 'touch') {
|
|
18176
18181
|
if (this._core.store.state.pointers.size === 0) {
|
|
18177
|
-
|
|
18178
|
-
this._core.store.state.isScaling = false;
|
|
18179
|
-
this._core.rerender();
|
|
18180
|
-
}, 300);
|
|
18182
|
+
this._debounceEndScaling();
|
|
18181
18183
|
}
|
|
18182
18184
|
}
|
|
18183
18185
|
}
|
|
@@ -18216,8 +18218,9 @@ class KritzelViewport {
|
|
|
18216
18218
|
const yRelativeToHost = event.clientY - rect.top;
|
|
18217
18219
|
this._core.store.state.pointerX = (xRelativeToHost - this._core.store.state.translateX) / this._core.store.state.scale;
|
|
18218
18220
|
this._core.store.state.pointerY = (yRelativeToHost - this._core.store.state.translateY) / this._core.store.state.scale;
|
|
18219
|
-
const
|
|
18220
|
-
const
|
|
18221
|
+
const rawScaleFactor = 1 + (event.deltaY * -0.012);
|
|
18222
|
+
const scaleFactor = Math.max(0.8, Math.min(1.2, rawScaleFactor));
|
|
18223
|
+
const newScale = Math.min(this._core.store.state.scaleMax, Math.max(this._core.store.state.scaleMin, this._core.store.state.scale * scaleFactor));
|
|
18221
18224
|
const scaleRatio = newScale / this._core.store.state.scale;
|
|
18222
18225
|
const translateXAdjustment = (xRelativeToHost - this._core.store.state.translateX) * (scaleRatio - 1);
|
|
18223
18226
|
const translateYAdjustment = (yRelativeToHost - this._core.store.state.translateY) * (scaleRatio - 1);
|
|
@@ -18227,9 +18230,7 @@ class KritzelViewport {
|
|
|
18227
18230
|
this._core.store.state.hasViewportChanged = true;
|
|
18228
18231
|
this._core.rerender();
|
|
18229
18232
|
this._debounceUpdate();
|
|
18230
|
-
|
|
18231
|
-
this._core.store.state.isScaling = false;
|
|
18232
|
-
}, 300);
|
|
18233
|
+
this._debounceEndScaling();
|
|
18233
18234
|
}
|
|
18234
18235
|
handlePan(event) {
|
|
18235
18236
|
const panSpeed = 0.8;
|
|
@@ -18398,7 +18399,6 @@ const DEFAULT_ENGINE_CONFIG = {
|
|
|
18398
18399
|
scale: 1,
|
|
18399
18400
|
scaleMax: 1,
|
|
18400
18401
|
scaleMin: 1,
|
|
18401
|
-
scaleStep: 0.075,
|
|
18402
18402
|
startX: 0,
|
|
18403
18403
|
startY: 0,
|
|
18404
18404
|
translateX: 0,
|
|
@@ -19384,6 +19384,10 @@ const KritzelEngine = class {
|
|
|
19384
19384
|
workspacesChange;
|
|
19385
19385
|
longpress;
|
|
19386
19386
|
forceUpdate = 0;
|
|
19387
|
+
throttledWheel = lodashExports.throttle((ev) => {
|
|
19388
|
+
this.viewport.handleWheel(ev);
|
|
19389
|
+
this.core.store.state?.activeTool?.handleWheel(ev);
|
|
19390
|
+
}, 16);
|
|
19387
19391
|
handleWheel(ev) {
|
|
19388
19392
|
if (this.core.store.isDisabled) {
|
|
19389
19393
|
return;
|
|
@@ -19391,8 +19395,7 @@ const KritzelEngine = class {
|
|
|
19391
19395
|
if (this.core.store.state.isContextMenuVisible) {
|
|
19392
19396
|
this.hideContextMenu();
|
|
19393
19397
|
}
|
|
19394
|
-
this.
|
|
19395
|
-
this.core.store.state?.activeTool?.handleWheel(ev);
|
|
19398
|
+
this.throttledWheel(ev);
|
|
19396
19399
|
}
|
|
19397
19400
|
handlePointerDown(ev) {
|
|
19398
19401
|
if (this.core.store.isDisabled) {
|
|
@@ -19625,6 +19628,7 @@ const KritzelEngine = class {
|
|
|
19625
19628
|
this.core = new KritzelCore(this);
|
|
19626
19629
|
}
|
|
19627
19630
|
disconnectedCallback() {
|
|
19631
|
+
this.throttledWheel.cancel();
|
|
19628
19632
|
this.throttledPointerMoveMulti.cancel();
|
|
19629
19633
|
}
|
|
19630
19634
|
componentWillLoad() {
|
|
@@ -19677,11 +19681,12 @@ const KritzelEngine = class {
|
|
|
19677
19681
|
const baseHandleTouchSize = baseHandleSize * 2 < 14 ? 14 : baseHandleSize;
|
|
19678
19682
|
const viewportCenterX = this.core.store.state.viewportWidth / 2 + this.core.store.state.translateX;
|
|
19679
19683
|
const viewportCenterY = this.core.store.state.viewportHeight / 2 + this.core.store.state.translateY;
|
|
19680
|
-
|
|
19684
|
+
// Performance optimization: skip viewport filtering during scaling/panning
|
|
19685
|
+
const visibleObjects = this.core.store.state.objectsMap.allObjects().filter(obj => obj.isInViewport());
|
|
19686
|
+
return (h(Host, { key: '606a74a14c90cd906800b13ea7b2d3c0f66027f9' }, h("div", { key: '16bbc31eb41a73b7bf4a93ee03326f737ae5e913', class: "debug-panel", style: { display: this.core.store.state.debugInfo.showViewportInfo ? 'block' : 'none' } }, h("div", { key: 'fe676e4d3c0819aaba3c11ed59a228d13b07f230' }, "ActiveWorkspaceId: ", this.core.store.state?.activeWorkspace?.id), h("div", { key: '509fa7ffadb00292cb1eac48299441f6c02c0b41' }, "ActiveWorkspaceName: ", this.core.store.state?.activeWorkspace?.name), h("div", { key: '870d0d25fb058016f246c6d09f8484f2da7268c8' }, "TranslateX: ", this.core.store.state?.translateX), h("div", { key: '510f84b9c531847f211c5a30333e26687f9aa0a1' }, "TranslateY: ", this.core.store.state?.translateY), h("div", { key: 'f8893208caf4ef75c5e4719216e115aebdec7f58' }, "ViewportWidth: ", this.core.store.state?.viewportWidth), h("div", { key: '012219bffa89704491c2153e209ba1bf57adbeee' }, "ViewportHeight: ", this.core.store.state?.viewportHeight), h("div", { key: '9c899814bf36d3f8862fd7f49689508a1baf39e2' }, "PointerCount: ", this.core.store.state.pointers.size), h("div", { key: '4a5dc288955d617186819cce51a7077d8f0a27ee' }, "Scale: ", this.core.store.state?.scale), h("div", { key: 'f6b3e3db24cc1f6df5cacba49e7cbca3e855a1d5' }, "ActiveTool: ", this.core.store.state?.activeTool?.name), h("div", { key: '5159cfb7ba76274acafa9dd52cf035df0a638954' }, "HasViewportChanged: ", this.core.store.state?.hasViewportChanged ? 'true' : 'false'), h("div", { key: 'fb951bba9378e7edaa931c1f71172a1760f493f1' }, "IsEnabled: ", this.core.store.state?.isEnabled ? 'true' : 'false'), h("div", { key: '31e8257fdf8deca0036181fe08e7312e0f7e06ea' }, "IsScaling: ", this.core.store.state?.isScaling ? 'true' : 'false'), h("div", { key: 'eb9c0276321566c024dce3eb6e5b4c5ac8a2217b' }, "IsPanning: ", this.core.store.state?.isPanning ? 'true' : 'false'), h("div", { key: '4ccbbe93181ea8bca8008c495a87ecf32e0fc823' }, "IsSelecting: ", this.isSelecting ? 'true' : 'false'), h("div", { key: 'c8bb0d92069b152b3238b806302413c8ef565bfc' }, "IsSelectionActive: ", this.isSelectionActive ? 'true' : 'false'), h("div", { key: '6a8fa0e36c486f92c66b016efaf718d98876500a' }, "IsResizeHandleSelected: ", this.core.store.state.isResizeHandleSelected ? 'true' : 'false'), h("div", { key: 'a0c090c6de6183b0d217a14e637cc766f1d0ec70' }, "IsRotationHandleSelected: ", this.core.store.state.isRotationHandleSelected ? 'true' : 'false'), h("div", { key: '54a73257c6e60831e1945548ac90404d53c0c59a' }, "IsDrawing: ", this.core.store.state.isDrawing ? 'true' : 'false'), h("div", { key: 'eb05d42967f2503664da627a06e6428282614873' }, "IsWriting: ", this.core.store.state.isWriting ? 'true' : 'false'), h("div", { key: 'a6a7141369c33eca952f7aea7c9fefeeb4a5b1fa' }, "PointerX: ", this.core.store.state?.pointerX), h("div", { key: 'ffe702239f80b6ccb9d6623de37c63e3af13703c' }, "PointerY: ", this.core.store.state?.pointerY), h("div", { key: '3a48b1e2630298dd480295ba0c845a0eb4adbab5' }, "SelectedObjects: ", this.core.store.selectionGroup?.objects.length || 0), h("div", { key: 'b1dd6b5e2aa1c59d9c2ecd658bd7830ae599e24a' }, "ViewportCenter: (", viewportCenterX.toFixed(2), ", ", viewportCenterY.toFixed(2), ")")), h("div", { key: 'ada0f44f8a38cbdf8f90a70402ffbf6383638c0c', id: "origin", class: "origin", style: {
|
|
19681
19687
|
transform: `matrix(${this.core.store.state?.scale}, 0, 0, ${this.core.store.state?.scale}, ${this.core.store.state?.translateX}, ${this.core.store.state?.translateY})`,
|
|
19682
|
-
} },
|
|
19688
|
+
} }, visibleObjects?.map(object => {
|
|
19683
19689
|
return (h("div", { key: object.id, style: {
|
|
19684
|
-
display: object.isInViewport() ? 'block' : 'none',
|
|
19685
19690
|
transform: object?.transformationMatrix,
|
|
19686
19691
|
transformOrigin: 'top left',
|
|
19687
19692
|
zIndex: object.zIndex.toString(),
|
|
@@ -19711,12 +19716,12 @@ const KritzelEngine = class {
|
|
|
19711
19716
|
width: object?.width.toString(),
|
|
19712
19717
|
position: 'absolute',
|
|
19713
19718
|
overflow: 'visible',
|
|
19714
|
-
}, viewBox: object?.viewBox }, h("path", { d: object?.d, fill: object.fill, stroke: object?.stroke, "shape-rendering":
|
|
19719
|
+
}, viewBox: object?.viewBox }, h("path", { d: object?.d, fill: object.fill, stroke: object?.stroke, "shape-rendering": object.isLowRes() ? 'optimizeSpeed' : 'auto' }))), KritzelClassHelper.isInstanceOf(object, 'KritzelImage') && (h("img", { ref: el => object.mount(el), src: object.src, style: {
|
|
19715
19720
|
width: '100%',
|
|
19716
19721
|
height: '100%',
|
|
19717
19722
|
userSelect: 'none',
|
|
19718
19723
|
pointerEvents: 'none',
|
|
19719
|
-
imageRendering: this.core.store.state.isScaling ? 'pixelated' : 'auto',
|
|
19724
|
+
imageRendering: this.core.store.state.isScaling || this.core.store.state.isPanning ? 'pixelated' : 'auto',
|
|
19720
19725
|
}, draggable: false, onDragStart: e => e.preventDefault() })), KritzelClassHelper.isInstanceOf(object, 'KritzelText') && (h("div", { ref: el => object.mount(el), onPointerDown: e => object.handlePointerDown(e), onPointerMove: e => object.handlePointerMove(e), onPointerUp: e => object.handlePointerUp(e), style: {
|
|
19721
19726
|
minWidth: object.initialWidth + 'px',
|
|
19722
19727
|
minHeight: object.initialHeight + 'px',
|
|
@@ -19727,7 +19732,7 @@ const KritzelEngine = class {
|
|
|
19727
19732
|
transform: `scale(${object.scaleFactor})`,
|
|
19728
19733
|
backgroundColor: object.backgroundColor,
|
|
19729
19734
|
overflow: 'visible',
|
|
19730
|
-
textRendering: this.core.store.state.isScaling ? 'optimizeSpeed' : 'auto',
|
|
19735
|
+
textRendering: this.core.store.state.isScaling || this.core.store.state.isPanning ? 'optimizeSpeed' : 'auto',
|
|
19731
19736
|
} })), KritzelClassHelper.isInstanceOf(object, 'KritzelCustomElement') && (h("div", { ref: el => object.mount(el), style: {
|
|
19732
19737
|
width: '100%',
|
|
19733
19738
|
height: '100%',
|
|
@@ -19785,7 +19790,7 @@ const KritzelEngine = class {
|
|
|
19785
19790
|
fill: 'transparent',
|
|
19786
19791
|
cursor: 'grab',
|
|
19787
19792
|
}, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("g", { style: { display: this.core.store.state.debugInfo.showObjectInfo ? 'block' : 'none', pointerEvents: 'none' } }, h("foreignObject", { x: object.totalWidth.toString(), y: "0", width: "400px", height: "160px", style: { minHeight: '0', minWidth: '0', display: object.isDebugInfoVisible ? 'block' : 'none' } }, h("div", { style: { width: '100%', height: '100%' } }, h("div", { style: { whitespace: 'nowrap' } }, "Id: ", object.id), h("div", { style: { whiteSpace: 'nowrap' } }, "width: ", object.width), h("div", { style: { whiteSpace: 'nowrap' } }, "height: ", object.height), h("div", { style: { whiteSpace: 'nowrap' } }, "translateX: ", object.translateX), h("div", { style: { whiteSpace: 'nowrap' } }, "translateY: ", object.translateY)))))));
|
|
19788
|
-
})), this.core.store.state.isContextMenuVisible && (h("kritzel-context-menu", { key: '
|
|
19793
|
+
})), this.core.store.state.isContextMenuVisible && (h("kritzel-context-menu", { key: '0369b6579f87448c6c3c608ef10c47276fd58c92', class: "context-menu", ref: el => (this.contextMenuElement = el), items: this.core.store.state.contextMenuItems, objects: this.core.store.selectionGroup?.objects || [], style: {
|
|
19789
19794
|
position: 'fixed',
|
|
19790
19795
|
left: `${this.core.store.state.contextMenuX}px`,
|
|
19791
19796
|
top: `${this.core.store.state.contextMenuY}px`,
|
|
@@ -19796,7 +19801,7 @@ const KritzelEngine = class {
|
|
|
19796
19801
|
y: (-this.core.store.state.translateY + this.core.store.state.contextMenuY) / this.core.store.state.scale,
|
|
19797
19802
|
}, this.core.store.selectionGroup?.objects);
|
|
19798
19803
|
this.hideContextMenu();
|
|
19799
|
-
}, onClose: () => this.hideContextMenu() })), this.core.store.state?.activeTool instanceof KritzelEraserTool && !this.core.store.state.isScaling && h("kritzel-cursor-trail", { key: '
|
|
19804
|
+
}, onClose: () => this.hideContextMenu() })), this.core.store.state?.activeTool instanceof KritzelEraserTool && !this.core.store.state.isScaling && h("kritzel-cursor-trail", { key: '3692b5245247d082191144d3672e9733fe6d16fe', core: this.core })));
|
|
19800
19805
|
}
|
|
19801
19806
|
static get watchers() { return {
|
|
19802
19807
|
"workspace": ["onWorkspaceChange"],
|
|
@@ -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 T,q as g,u as W,x as $,y as B,z as x,A as z,B as C,C as U,H,D as A}from"./p-Bcel-KfG.js";export{R as DEFAULT_BRUSH_CONFIG,S as DEFAULT_TEXT_CONFIG,N as IndexedDBSyncProvider,P as KritzelAppStateMap,G as KritzelBrushTool,I as KritzelEraserTool,F as KritzelImage,J as KritzelImageTool,E as KritzelPath,M as KritzelSelectionTool,K as KritzelText,L as KritzelTextTool,Q as KritzelWorkspace}from"./p-Bcel-KfG.js";class D{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 O=new Map;class _{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 j=typeof BroadcastChannel==="undefined"?_:BroadcastChannel;const q=s=>l(O,s,(()=>{const t=d();const e=new j(s);e.onmessage=s=>t.forEach((t=>t(s.data,"broadcastchannel")));return{bc:e,subs:t}}));const X=(s,t)=>{q(s).subs.add(t);return t};const Y=(s,t)=>{const e=q(s);const i=e.subs.delete(t);if(i&&e.subs.size===0){e.bc.close();O.delete(s)}return i};const V=(s,t,e=null)=>{const i=q(s);i.bc.postMessage(t);i.subs.forEach((s=>s(t,e)))};const Z=0;const ss=1;const ts=2;const es=(e,i)=>{s(e,Z);const n=a(i);t(e,n)};const is=(e,i,n)=>{s(e,ss);t(e,o(i,n))};const ns=(s,t,e)=>is(t,e,n(s));const os=(s,t,e)=>{try{c(t,n(s),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}};const cs=(e,i)=>{s(e,ts);t(e,i)};const as=os;const hs=(s,t,e,n)=>{const o=i(s);switch(o){case Z:ns(s,t,e);break;case ss:os(s,e,n);break;case ts:as(s,e,n);break;default:throw new Error("Unknown message type")}return o};const rs=0;const ls=(s,t,e)=>{switch(i(s)){case rs:e(t,k(s))}};const ds=3e4;class us 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=T();if(this.getLocalState()!==null&&ds/2<=s-this.meta.get(this.clientID).lastUpdated){this.setLocalState(this.getLocalState())}const t=[];this.meta.forEach(((e,i)=>{if(i!==this.clientID&&ds<=s-e.lastUpdated&&this.states.has(i)){t.push(i)}}));if(t.length>0){fs(this,t,"timeout")}}),v(ds/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:T()});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(!g(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 fs=(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:T()})}i.push(n)}}if(i.length>0){s.emit("change",[{added:[],updated:[],removed:i},e]);s.emit("update",[{added:[],updated:[],removed:i},e])}};const ps=(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);W(c,JSON.stringify(a))}return e(c)};const ms=(s,t,e)=>{const n=r(t);const o=T();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(!g(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 ys=s=>$(s,((s,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(s)}`)).join("&");const Ss=0;const ws=3;const ks=1;const bs=2;const vs=[];vs[Ss]=(t,e,i,n,o)=>{s(t,Ss);const c=hs(e,t,i.doc,i);if(n&&c===ss&&!i.synced){i.synced=true}};vs[ws]=(e,i,n,o,c)=>{s(e,ks);t(e,ps(n.awareness,Array.from(n.awareness.getStates().keys())))};vs[ks]=(s,t,e,i,o)=>{ms(e.awareness,n(t),e)};vs[bs]=(s,t,e,i,n)=>{ls(t,e.doc,((s,t)=>gs(e,t)))};const Ts=3e4;const gs=(s,t)=>console.warn(`Permission denied to access ${s.url}.\n${t}`);const Ws=(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 $s=(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;fs(s.awareness,Array.from(s.awareness.getStates().keys()).filter((t=>t!==s.doc.clientID)),s);s.emit("status",[{status:"disconnected"}])}else{s.wsUnsuccessfulReconnects++}setTimeout(Bs,C(U(2,s.wsUnsuccessfulReconnects)*100,s.maxBackoffTime),s)}};const Bs=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=T();const t=Ws(i,new Uint8Array(s.data),true);if(x(t)>1){n.send(e(t))}};n.onerror=s=>{i.emit("connection-error",[s,i])};n.onclose=s=>{$s(i,n,s)};n.onopen=()=>{i.wsLastMessageReceived=T();i.wsconnecting=false;i.wsconnected=true;i.wsUnsuccessfulReconnects=0;i.emit("status",[{status:"connected"}]);const o=h();s(o,Ss);es(o,i.doc);n.send(e(o));if(i.awareness.getLocalState()!==null){const o=h();s(o,ks);t(o,ps(i.awareness,[i.doc.clientID]));n.send(e(o))}};i.emit("status",[{status:"connecting"}])}};const xs=(s,t)=>{const e=s.ws;if(s.wsconnected&&e&&e.readyState===e.OPEN){e.send(t)}if(s.bcconnected){V(s.bcChannel,t,s)}};class zs extends B{constructor(i,n,o,{connect:c=true,awareness:a=new us(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=vs.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,Ss);es(t,o);this.ws.send(e(t))}}),u)}this._bcSubscriber=(s,t)=>{if(t!==this){const t=Ws(this,new Uint8Array(s),false);if(x(t)>1){V(this.bcChannel,e(t),this)}}};this._updateHandler=(t,i)=>{if(i!==this){const i=h();s(i,Ss);cs(i,t);xs(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,ks);t(l,ps(a,r));xs(this,e(l))};this._exitHandler=()=>{fs(this.awareness,[o.clientID],"app closed")};if(z&&typeof process!=="undefined"){process.on("exit",this._exitHandler)}a.on("update",this._awarenessUpdateHandler);this._checkInterval=setInterval((()=>{if(this.wsconnected&&Ts<T()-this.wsLastMessageReceived){$s(this,this.ws,null)}}),Ts/10);if(c){this.connect()}}get url(){const s=ys(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(z&&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){X(this.bcChannel,this._bcSubscriber);this.bcconnected=true}const i=h();s(i,Ss);es(i,this.doc);V(this.bcChannel,e(i),this);const n=h();s(n,Ss);is(n,this.doc);V(this.bcChannel,e(n),this);const o=h();s(o,ws);V(this.bcChannel,e(o),this);const c=h();s(c,ks);t(c,ps(this.awareness,[this.doc.clientID]));V(this.bcChannel,e(c),this)}disconnectBc(){const i=h();s(i,ks);t(i,ps(this.awareness,[this.doc.clientID],new Map));xs(this,e(i));if(this.bcconnected){Y(this.bcChannel,this._bcSubscriber);this.bcconnected=false}}disconnect(){this.shouldConnect=false;this.disconnectBc();if(this.ws!==null){$s(this,this.ws,null)}}connect(){this.shouldConnect=true;if(!this.wsconnected&&this.ws===null){Bs(this);this.connectBc()}}}class Is{provider;isConnected=false;constructor(s,t,e){const i=e?.url||"ws://localhost:1234";const n=e?.roomName||s;this.provider=new zs(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 Is(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 Ps{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||Ps.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 H(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 H(s);if(!e?.quiet){console.info(`Hocuspocus Provider initialized: ${n}/${i}`)}}}static createSharedWebSocket(s){if(Ps.sharedWebSocketProvider){console.warn("Shared WebSocket already exists. Returning existing instance.");return Ps.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}Ps.sharedWebSocketProvider=new A(t);console.info(`Shared Hocuspocus WebSocket created: ${s.url}`);return Ps.sharedWebSocketProvider}static destroySharedWebSocket(){if(Ps.sharedWebSocketProvider){Ps.sharedWebSocketProvider.destroy();Ps.sharedWebSocketProvider=null;console.info("Shared Hocuspocus WebSocket destroyed")}}static getSharedWebSocket(){return Ps.sharedWebSocketProvider}static with(s){return{create:(t,e)=>new Ps(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{D as BroadcastSyncProvider,Ps as HocuspocusSyncProvider,Is 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 T,q as W,u as g,x as $,y as C,z as x,A as z,B,C as U,H,D as A}from"./p-ClW1W-X4.js";export{R as DEFAULT_BRUSH_CONFIG,S as DEFAULT_TEXT_CONFIG,N as IndexedDBSyncProvider,P as KritzelAppStateMap,G as KritzelBrushTool,I as KritzelEraserTool,F as KritzelImage,J as KritzelImageTool,E as KritzelPath,M as KritzelSelectionTool,K as KritzelText,L as KritzelTextTool,Q as KritzelWorkspace}from"./p-ClW1W-X4.js";class D{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 O=new Map;class _{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 j=typeof BroadcastChannel==="undefined"?_:BroadcastChannel;const X=s=>l(O,s,(()=>{const t=d();const e=new j(s);e.onmessage=s=>t.forEach((t=>t(s.data,"broadcastchannel")));return{bc:e,subs:t}}));const q=(s,t)=>{X(s).subs.add(t);return t};const Y=(s,t)=>{const e=X(s);const i=e.subs.delete(t);if(i&&e.subs.size===0){e.bc.close();O.delete(s)}return i};const V=(s,t,e=null)=>{const i=X(s);i.bc.postMessage(t);i.subs.forEach((s=>s(t,e)))};const Z=0;const ss=1;const ts=2;const es=(e,i)=>{s(e,Z);const n=a(i);t(e,n)};const is=(e,i,n)=>{s(e,ss);t(e,o(i,n))};const ns=(s,t,e)=>is(t,e,n(s));const os=(s,t,e)=>{try{c(t,n(s),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}};const cs=(e,i)=>{s(e,ts);t(e,i)};const as=os;const hs=(s,t,e,n)=>{const o=i(s);switch(o){case Z:ns(s,t,e);break;case ss:os(s,e,n);break;case ts:as(s,e,n);break;default:throw new Error("Unknown message type")}return o};const rs=0;const ls=(s,t,e)=>{switch(i(s)){case rs:e(t,k(s))}};const ds=3e4;class us 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=T();if(this.getLocalState()!==null&&ds/2<=s-this.meta.get(this.clientID).lastUpdated){this.setLocalState(this.getLocalState())}const t=[];this.meta.forEach(((e,i)=>{if(i!==this.clientID&&ds<=s-e.lastUpdated&&this.states.has(i)){t.push(i)}}));if(t.length>0){fs(this,t,"timeout")}}),v(ds/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:T()});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(!W(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 fs=(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:T()})}i.push(n)}}if(i.length>0){s.emit("change",[{added:[],updated:[],removed:i},e]);s.emit("update",[{added:[],updated:[],removed:i},e])}};const ps=(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);g(c,JSON.stringify(a))}return e(c)};const ms=(s,t,e)=>{const n=r(t);const o=T();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(!W(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 ys=s=>$(s,((s,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(s)}`)).join("&");const Ss=0;const ws=3;const ks=1;const bs=2;const vs=[];vs[Ss]=(t,e,i,n,o)=>{s(t,Ss);const c=hs(e,t,i.doc,i);if(n&&c===ss&&!i.synced){i.synced=true}};vs[ws]=(e,i,n,o,c)=>{s(e,ks);t(e,ps(n.awareness,Array.from(n.awareness.getStates().keys())))};vs[ks]=(s,t,e,i,o)=>{ms(e.awareness,n(t),e)};vs[bs]=(s,t,e,i,n)=>{ls(t,e.doc,((s,t)=>Ws(e,t)))};const Ts=3e4;const Ws=(s,t)=>console.warn(`Permission denied to access ${s.url}.\n${t}`);const gs=(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 $s=(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;fs(s.awareness,Array.from(s.awareness.getStates().keys()).filter((t=>t!==s.doc.clientID)),s);s.emit("status",[{status:"disconnected"}])}else{s.wsUnsuccessfulReconnects++}setTimeout(Cs,B(U(2,s.wsUnsuccessfulReconnects)*100,s.maxBackoffTime),s)}};const Cs=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=T();const t=gs(i,new Uint8Array(s.data),true);if(x(t)>1){n.send(e(t))}};n.onerror=s=>{i.emit("connection-error",[s,i])};n.onclose=s=>{$s(i,n,s)};n.onopen=()=>{i.wsLastMessageReceived=T();i.wsconnecting=false;i.wsconnected=true;i.wsUnsuccessfulReconnects=0;i.emit("status",[{status:"connected"}]);const o=h();s(o,Ss);es(o,i.doc);n.send(e(o));if(i.awareness.getLocalState()!==null){const o=h();s(o,ks);t(o,ps(i.awareness,[i.doc.clientID]));n.send(e(o))}};i.emit("status",[{status:"connecting"}])}};const xs=(s,t)=>{const e=s.ws;if(s.wsconnected&&e&&e.readyState===e.OPEN){e.send(t)}if(s.bcconnected){V(s.bcChannel,t,s)}};class zs extends C{constructor(i,n,o,{connect:c=true,awareness:a=new us(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=vs.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,Ss);es(t,o);this.ws.send(e(t))}}),u)}this._bcSubscriber=(s,t)=>{if(t!==this){const t=gs(this,new Uint8Array(s),false);if(x(t)>1){V(this.bcChannel,e(t),this)}}};this._updateHandler=(t,i)=>{if(i!==this){const i=h();s(i,Ss);cs(i,t);xs(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,ks);t(l,ps(a,r));xs(this,e(l))};this._exitHandler=()=>{fs(this.awareness,[o.clientID],"app closed")};if(z&&typeof process!=="undefined"){process.on("exit",this._exitHandler)}a.on("update",this._awarenessUpdateHandler);this._checkInterval=setInterval((()=>{if(this.wsconnected&&Ts<T()-this.wsLastMessageReceived){$s(this,this.ws,null)}}),Ts/10);if(c){this.connect()}}get url(){const s=ys(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(z&&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){q(this.bcChannel,this._bcSubscriber);this.bcconnected=true}const i=h();s(i,Ss);es(i,this.doc);V(this.bcChannel,e(i),this);const n=h();s(n,Ss);is(n,this.doc);V(this.bcChannel,e(n),this);const o=h();s(o,ws);V(this.bcChannel,e(o),this);const c=h();s(c,ks);t(c,ps(this.awareness,[this.doc.clientID]));V(this.bcChannel,e(c),this)}disconnectBc(){const i=h();s(i,ks);t(i,ps(this.awareness,[this.doc.clientID],new Map));xs(this,e(i));if(this.bcconnected){Y(this.bcChannel,this._bcSubscriber);this.bcconnected=false}}disconnect(){this.shouldConnect=false;this.disconnectBc();if(this.ws!==null){$s(this,this.ws,null)}}connect(){this.shouldConnect=true;if(!this.wsconnected&&this.ws===null){Cs(this);this.connectBc()}}}class Is{provider;isConnected=false;constructor(s,t,e){const i=e?.url||"ws://localhost:1234";const n=e?.roomName||s;this.provider=new zs(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 Is(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 Ps{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||Ps.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 H(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 H(s);if(!e?.quiet){console.info(`Hocuspocus Provider initialized: ${n}/${i}`)}}}static createSharedWebSocket(s){if(Ps.sharedWebSocketProvider){console.warn("Shared WebSocket already exists. Returning existing instance.");return Ps.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}Ps.sharedWebSocketProvider=new A(t);console.info(`Shared Hocuspocus WebSocket created: ${s.url}`);return Ps.sharedWebSocketProvider}static destroySharedWebSocket(){if(Ps.sharedWebSocketProvider){Ps.sharedWebSocketProvider.destroy();Ps.sharedWebSocketProvider=null;console.info("Shared Hocuspocus WebSocket destroyed")}}static getSharedWebSocket(){return Ps.sharedWebSocketProvider}static with(s){return{create:(t,e)=>new Ps(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{D as BroadcastSyncProvider,Ps as HocuspocusSyncProvider,Is as WebSocketSyncProvider};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|