kritzel-stencil 0.1.80 → 0.1.82
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/index.cjs.js +1 -1
- package/dist/cjs/kritzel-active-users_42.cjs.entry.js +30 -37
- package/dist/cjs/{workspace.migrations-DUXtSb7C.js → workspace.migrations-4HATwIMK.js} +46 -58
- package/dist/collection/classes/core/core.class.js +6 -6
- package/dist/collection/classes/core/store.class.js +0 -12
- package/dist/collection/classes/objects/base-object.class.js +1 -1
- package/dist/collection/classes/objects/custom-element.class.js +1 -1
- package/dist/collection/classes/objects/group.class.js +1 -1
- package/dist/collection/classes/objects/image.class.js +1 -1
- package/dist/collection/classes/objects/line.class.js +1 -1
- package/dist/collection/classes/objects/path.class.js +1 -1
- package/dist/collection/classes/objects/selection-box.class.js +1 -1
- package/dist/collection/classes/objects/selection-group.class.js +1 -1
- package/dist/collection/classes/objects/shape.class.js +15 -21
- package/dist/collection/classes/objects/text.class.js +24 -30
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +21 -16
- package/dist/collection/constants/version.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/kritzel-awareness-cursors.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-editor.js +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-settings.js +1 -1
- package/dist/components/kritzel-tool-config.js +1 -1
- package/dist/components/{p-xYCbKFih.js → p-B4h_tGG1.js} +1 -1
- package/dist/components/{p-BcwZ36sO.js → p-BPQOTise.js} +1 -1
- package/dist/components/{p-B-Gej_Ak.js → p-C35iuSnC.js} +1 -1
- package/dist/components/{p-BzQmBVwr.js → p-CgtykATT.js} +2 -2
- package/dist/components/{p-C_fSm7T4.js → p-DK_d3fKa.js} +1 -1
- package/dist/components/p-DQK_4lkI.js +1 -0
- package/dist/components/{p-CvyE2Wg-.js → p-DsfD4pGR.js} +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/kritzel-active-users_42.entry.js +30 -37
- package/dist/esm/{workspace.migrations-OzSSw5kt.js → workspace.migrations-Be65cOkQ.js} +46 -58
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/p-Be65cOkQ.js +1 -0
- package/dist/stencil/p-f318b7d5.entry.js +9 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/core/store.class.d.ts +0 -8
- package/dist/types/classes/objects/shape.class.d.ts +0 -1
- package/dist/types/classes/objects/text.class.d.ts +0 -1
- package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +1 -0
- package/dist/types/constants/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/components/p-C8WnYSHi.js +0 -1
- package/dist/stencil/p-OzSSw5kt.js +0 -1
- package/dist/stencil/p-f7be06a8.entry.js +0 -9
|
@@ -424,7 +424,7 @@ class KritzelBaseObject {
|
|
|
424
424
|
const object = new KritzelBaseObject();
|
|
425
425
|
object._core = core;
|
|
426
426
|
object.zIndex = core.store.currentZIndex;
|
|
427
|
-
object.workspaceId = core.store.activeWorkspace.id;
|
|
427
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
428
428
|
object.userId = core.user?.id;
|
|
429
429
|
return object;
|
|
430
430
|
}
|
|
@@ -15228,12 +15228,6 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15228
15228
|
isEditing = false;
|
|
15229
15229
|
editor = null;
|
|
15230
15230
|
content = null;
|
|
15231
|
-
get _editor() {
|
|
15232
|
-
if (!this._editor) {
|
|
15233
|
-
throw new Error('KritzelShape: editor is not initialized');
|
|
15234
|
-
}
|
|
15235
|
-
return this._editor;
|
|
15236
|
-
}
|
|
15237
15231
|
_schema = new Schema({
|
|
15238
15232
|
nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
|
|
15239
15233
|
marks: schema.spec.marks,
|
|
@@ -15245,10 +15239,10 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15245
15239
|
* @returns `true` if the editor is empty or contains only whitespace, `false` otherwise.
|
|
15246
15240
|
*/
|
|
15247
15241
|
get isEmpty() {
|
|
15248
|
-
if (!this.
|
|
15242
|
+
if (!this.editor) {
|
|
15249
15243
|
return true;
|
|
15250
15244
|
}
|
|
15251
|
-
const doc = this.
|
|
15245
|
+
const doc = this.editor.state.doc;
|
|
15252
15246
|
if (doc.content.size === 0) {
|
|
15253
15247
|
return true;
|
|
15254
15248
|
}
|
|
@@ -15321,7 +15315,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15321
15315
|
const object = new KritzelText();
|
|
15322
15316
|
object._core = core;
|
|
15323
15317
|
object.id = object.generateId();
|
|
15324
|
-
object.workspaceId = core.store.activeWorkspace.id;
|
|
15318
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
15325
15319
|
object.userId = core.user?.id;
|
|
15326
15320
|
object.fontSize = fontSize || 8;
|
|
15327
15321
|
object.fontFamily = fontFamily || 'Arial';
|
|
@@ -15352,7 +15346,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15352
15346
|
element.style.fontFamily = this.fontFamily;
|
|
15353
15347
|
element.style.fontSize = `${this.fontSize}pt`;
|
|
15354
15348
|
element.style.color = KritzelColorHelper.resolveThemeColor(this.fontColor);
|
|
15355
|
-
if (this.isMounted && this.elementRef === element && this.
|
|
15349
|
+
if (this.isMounted && this.elementRef === element && this.editor.dom.parentElement === element) {
|
|
15356
15350
|
if (!this._core.store.state.isScaling && !this._core.store.state.isPanning) {
|
|
15357
15351
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
15358
15352
|
}
|
|
@@ -15362,7 +15356,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15362
15356
|
this.elementRef.style.whiteSpace = 'pre-wrap';
|
|
15363
15357
|
this.elementRef.style.wordWrap = 'break-word';
|
|
15364
15358
|
this.elementRef.innerHTML = '';
|
|
15365
|
-
this.elementRef.appendChild(this.
|
|
15359
|
+
this.elementRef.appendChild(this.editor.dom);
|
|
15366
15360
|
this.isMounted = true;
|
|
15367
15361
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
15368
15362
|
}
|
|
@@ -15380,8 +15374,8 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15380
15374
|
}),
|
|
15381
15375
|
editable: () => false,
|
|
15382
15376
|
dispatchTransaction: transaction => {
|
|
15383
|
-
const newState = this.
|
|
15384
|
-
this.
|
|
15377
|
+
const newState = this.editor.state.apply(transaction);
|
|
15378
|
+
this.editor.updateState(newState);
|
|
15385
15379
|
if (transaction.docChanged) {
|
|
15386
15380
|
this.content = newState.doc.toJSON();
|
|
15387
15381
|
this.adjustSizeOnInput();
|
|
@@ -15399,11 +15393,11 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15399
15393
|
*/
|
|
15400
15394
|
setContent(content) {
|
|
15401
15395
|
this.content = content;
|
|
15402
|
-
if (this.
|
|
15403
|
-
const newDoc = this.
|
|
15404
|
-
const tr = this.
|
|
15396
|
+
if (this.editor && content) {
|
|
15397
|
+
const newDoc = this.editor.state.schema.nodeFromJSON(content);
|
|
15398
|
+
const tr = this.editor.state.tr.replaceWith(0, this.editor.state.doc.content.size, newDoc.content);
|
|
15405
15399
|
tr.setMeta('fromRemote', true);
|
|
15406
|
-
this.
|
|
15400
|
+
this.editor.dispatch(tr);
|
|
15407
15401
|
}
|
|
15408
15402
|
}
|
|
15409
15403
|
/**
|
|
@@ -15468,13 +15462,13 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15468
15462
|
* @param coords.y - Y coordinate for cursor placement.
|
|
15469
15463
|
*/
|
|
15470
15464
|
focus(coords) {
|
|
15471
|
-
if (this.
|
|
15472
|
-
const doc = this.
|
|
15465
|
+
if (this.editor) {
|
|
15466
|
+
const doc = this.editor.state.doc;
|
|
15473
15467
|
if (coords.x && coords.y && !this.isEmpty) {
|
|
15474
|
-
const pos = this.
|
|
15468
|
+
const pos = this.editor.posAtCoords({ left: coords.x, top: coords.y });
|
|
15475
15469
|
if (pos) {
|
|
15476
|
-
this.
|
|
15477
|
-
this.
|
|
15470
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, pos.pos)));
|
|
15471
|
+
this.editor.focus();
|
|
15478
15472
|
if (KritzelDevicesHelper.isIOS()) {
|
|
15479
15473
|
this.scrollIntoViewOnIOS();
|
|
15480
15474
|
}
|
|
@@ -15482,8 +15476,8 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15482
15476
|
}
|
|
15483
15477
|
}
|
|
15484
15478
|
const end = Math.max(1, doc.content.size - 1);
|
|
15485
|
-
this.
|
|
15486
|
-
this.
|
|
15479
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, end)));
|
|
15480
|
+
this.editor.focus();
|
|
15487
15481
|
if (KritzelDevicesHelper.isIOS()) {
|
|
15488
15482
|
this.scrollIntoViewOnIOS();
|
|
15489
15483
|
}
|
|
@@ -15495,8 +15489,8 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15495
15489
|
*/
|
|
15496
15490
|
scrollIntoViewOnIOS() {
|
|
15497
15491
|
setTimeout(() => {
|
|
15498
|
-
if (this.
|
|
15499
|
-
this.
|
|
15492
|
+
if (this.editor && this.editor.dom) {
|
|
15493
|
+
this.editor.dom.scrollIntoView({
|
|
15500
15494
|
behavior: 'smooth',
|
|
15501
15495
|
block: 'center',
|
|
15502
15496
|
inline: 'nearest',
|
|
@@ -15514,7 +15508,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15514
15508
|
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
15515
15509
|
this.uneditedObject = this.clone();
|
|
15516
15510
|
this._core.store.setState('activeTool', KritzelToolRegistry.getTool('text'));
|
|
15517
|
-
this.
|
|
15511
|
+
this.editor.setProps({ editable: () => true });
|
|
15518
15512
|
this.isEditing = true;
|
|
15519
15513
|
this._core.rerender();
|
|
15520
15514
|
this.adjustSizeOnInput();
|
|
@@ -15530,9 +15524,9 @@ class KritzelText extends KritzelBaseObject {
|
|
|
15530
15524
|
*/
|
|
15531
15525
|
save() {
|
|
15532
15526
|
requestAnimationFrame(() => this.adjustSizeOnInput());
|
|
15533
|
-
this.content = this.
|
|
15534
|
-
this.
|
|
15535
|
-
this.
|
|
15527
|
+
this.content = this.editor.state.doc.toJSON();
|
|
15528
|
+
this.editor.setProps({ editable: () => false });
|
|
15529
|
+
this.editor.dom.blur();
|
|
15536
15530
|
this.isEditing = false;
|
|
15537
15531
|
this._core.store.objects.consolidateTemporaryItems();
|
|
15538
15532
|
this._core.store.objects.update(this);
|
|
@@ -15713,7 +15707,7 @@ class KritzelPath extends KritzelBaseObject {
|
|
|
15713
15707
|
const object = new KritzelPath();
|
|
15714
15708
|
object._core = core;
|
|
15715
15709
|
object.id = object.generateId();
|
|
15716
|
-
object.workspaceId = core.store.activeWorkspace.id;
|
|
15710
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
15717
15711
|
object.userId = core.user?.id;
|
|
15718
15712
|
object.options = options;
|
|
15719
15713
|
object.points = options?.points ?? [];
|
|
@@ -16215,7 +16209,7 @@ class KritzelImage extends KritzelBaseObject {
|
|
|
16215
16209
|
const object = new KritzelImage();
|
|
16216
16210
|
object._core = core;
|
|
16217
16211
|
object.id = object.generateId();
|
|
16218
|
-
object.workspaceId = core.store.activeWorkspace.id;
|
|
16212
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
16219
16213
|
object.userId = core.user?.id;
|
|
16220
16214
|
object.x = 0;
|
|
16221
16215
|
object.y = 0;
|
|
@@ -16366,7 +16360,7 @@ class KritzelLine extends KritzelBaseObject {
|
|
|
16366
16360
|
const object = new KritzelLine();
|
|
16367
16361
|
object._core = core;
|
|
16368
16362
|
object.id = object.generateId();
|
|
16369
|
-
object.workspaceId = core.store.activeWorkspace.id;
|
|
16363
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
16370
16364
|
object.userId = core.user?.id;
|
|
16371
16365
|
object.options = options;
|
|
16372
16366
|
object.startX = options?.startX ?? 0;
|
|
@@ -17126,7 +17120,7 @@ class KritzelGroup extends KritzelBaseObject {
|
|
|
17126
17120
|
const group = new KritzelGroup();
|
|
17127
17121
|
group._core = core;
|
|
17128
17122
|
group.id = group.generateId();
|
|
17129
|
-
group.workspaceId = core.store.activeWorkspace.id;
|
|
17123
|
+
group.workspaceId = core.store.state.activeWorkspace.id;
|
|
17130
17124
|
group.userId = core.user?.id;
|
|
17131
17125
|
group.scale = core.store.state.scale;
|
|
17132
17126
|
group.zIndex = core.store.currentZIndex;
|
|
@@ -17623,12 +17617,6 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17623
17617
|
get viewBox() {
|
|
17624
17618
|
return `${this.x} ${this.y} ${this.width} ${this.height}`;
|
|
17625
17619
|
}
|
|
17626
|
-
get _editor() {
|
|
17627
|
-
if (!this.editor) {
|
|
17628
|
-
throw new Error('KritzelShape: editor is not initialized');
|
|
17629
|
-
}
|
|
17630
|
-
return this.editor;
|
|
17631
|
-
}
|
|
17632
17620
|
/**
|
|
17633
17621
|
* Creates a new KritzelShape instance with optional configuration.
|
|
17634
17622
|
* This constructor initializes the shape with default values that can be
|
|
@@ -17684,7 +17672,7 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17684
17672
|
const object = new KritzelShape();
|
|
17685
17673
|
object._core = core;
|
|
17686
17674
|
object.id = object.generateId();
|
|
17687
|
-
object.workspaceId = core.store.activeWorkspace.id;
|
|
17675
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
17688
17676
|
object.userId = core.user?.id;
|
|
17689
17677
|
object.x = config?.x ?? 0;
|
|
17690
17678
|
object.y = config?.y ?? 0;
|
|
@@ -17736,7 +17724,7 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17736
17724
|
if (element === null || this.isInViewport() === false) {
|
|
17737
17725
|
return;
|
|
17738
17726
|
}
|
|
17739
|
-
if (this.isMounted && this.elementRef === element && this.
|
|
17727
|
+
if (this.isMounted && this.elementRef === element && this.editor.dom.parentElement === element) {
|
|
17740
17728
|
return;
|
|
17741
17729
|
}
|
|
17742
17730
|
this.elementRef = element;
|
|
@@ -17752,7 +17740,7 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17752
17740
|
* @returns void
|
|
17753
17741
|
*/
|
|
17754
17742
|
mountTextEditor(element) {
|
|
17755
|
-
if (element === null
|
|
17743
|
+
if (element === null) {
|
|
17756
17744
|
return;
|
|
17757
17745
|
}
|
|
17758
17746
|
element.style.fontFamily = this.fontFamily;
|
|
@@ -17783,8 +17771,8 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17783
17771
|
}),
|
|
17784
17772
|
editable: () => false,
|
|
17785
17773
|
dispatchTransaction: transaction => {
|
|
17786
|
-
const newState = this.
|
|
17787
|
-
this.
|
|
17774
|
+
const newState = this.editor.state.apply(transaction);
|
|
17775
|
+
this.editor.updateState(newState);
|
|
17788
17776
|
if (transaction.docChanged) {
|
|
17789
17777
|
this.content = newState.doc.toJSON();
|
|
17790
17778
|
if (!transaction.getMeta('fromRemote')) {
|
|
@@ -17846,12 +17834,12 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17846
17834
|
* @returns void
|
|
17847
17835
|
*/
|
|
17848
17836
|
focus(coords) {
|
|
17849
|
-
const doc = this.
|
|
17837
|
+
const doc = this.editor.state.doc;
|
|
17850
17838
|
if (coords?.x && coords?.y) {
|
|
17851
|
-
const pos = this.
|
|
17839
|
+
const pos = this.editor.posAtCoords({ left: coords.x, top: coords.y });
|
|
17852
17840
|
if (pos) {
|
|
17853
|
-
this.
|
|
17854
|
-
this.
|
|
17841
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, pos.pos)));
|
|
17842
|
+
this.editor.focus();
|
|
17855
17843
|
if (KritzelDevicesHelper.isIOS()) {
|
|
17856
17844
|
this.scrollIntoViewOnIOS();
|
|
17857
17845
|
}
|
|
@@ -17859,8 +17847,8 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17859
17847
|
}
|
|
17860
17848
|
}
|
|
17861
17849
|
const end = Math.max(1, doc.content.size - 1);
|
|
17862
|
-
this.
|
|
17863
|
-
this.
|
|
17850
|
+
this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, end)));
|
|
17851
|
+
this.editor.focus();
|
|
17864
17852
|
if (KritzelDevicesHelper.isIOS()) {
|
|
17865
17853
|
this.scrollIntoViewOnIOS();
|
|
17866
17854
|
}
|
|
@@ -17898,7 +17886,7 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17898
17886
|
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
17899
17887
|
this.uneditedObject = this.clone();
|
|
17900
17888
|
this._core.store.setState('activeTool', KritzelToolRegistry.getTool('shape'));
|
|
17901
|
-
this.
|
|
17889
|
+
this.editor.setProps({ editable: () => true });
|
|
17902
17890
|
this.isEditing = true;
|
|
17903
17891
|
this._core.rerender();
|
|
17904
17892
|
if (event?.clientX && event?.clientY) {
|
|
@@ -17915,9 +17903,9 @@ class KritzelShape extends KritzelBaseObject {
|
|
|
17915
17903
|
* @returns void
|
|
17916
17904
|
*/
|
|
17917
17905
|
save() {
|
|
17918
|
-
this.content = this.
|
|
17919
|
-
this.
|
|
17920
|
-
this.
|
|
17906
|
+
this.content = this.editor.state.doc.toJSON();
|
|
17907
|
+
this.editor.setProps({ editable: () => false });
|
|
17908
|
+
this.editor.dom.blur();
|
|
17921
17909
|
this.isEditing = false;
|
|
17922
17910
|
this._core.store.objects.consolidateTemporaryItems();
|
|
17923
17911
|
this._core.store.objects.update(this);
|
|
@@ -18595,7 +18583,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
|
|
|
18595
18583
|
const object = new KritzelSelectionGroup();
|
|
18596
18584
|
object._core = core;
|
|
18597
18585
|
object.id = object.generateId();
|
|
18598
|
-
object.workspaceId = core.store.activeWorkspace.id;
|
|
18586
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
18599
18587
|
object.userId = core.user?.id;
|
|
18600
18588
|
object.clientId = core.store.objects?.localClientId ?? undefined;
|
|
18601
18589
|
object.scale = core.store.state.scale;
|
|
@@ -20922,7 +20910,7 @@ class KritzelSelectionBox extends KritzelBaseObject {
|
|
|
20922
20910
|
const object = new KritzelSelectionBox();
|
|
20923
20911
|
object._core = core;
|
|
20924
20912
|
object.id = object.generateId();
|
|
20925
|
-
object.workspaceId = core.store.activeWorkspace.id;
|
|
20913
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
20926
20914
|
object.userId = core.user?.id;
|
|
20927
20915
|
object.scale = core.store.state.scale;
|
|
20928
20916
|
object.zIndex = 99999;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{A as APP_STATE_MIGRATIONS,C as CURRENT_APP_STATE_SCHEMA_VERSION,v as CURRENT_WORKSPACE_SCHEMA_VERSION,D as DEFAULT_BRUSH_CONFIG,r as DEFAULT_LINE_TOOL_CONFIG,q as DEFAULT_TEXT_CONFIG,H as HocuspocusSyncProvider,I as IndexedDBSyncProvider,u as KritzelAlignment,o as KritzelAnchorManager,f as KritzelBrushTool,l as KritzelCursorHelper,h as KritzelEraserTool,d as KritzelGroup,b as KritzelImage,i as KritzelImageTool,c as KritzelLine,g as KritzelLineTool,a as KritzelPath,m as KritzelSelectionTool,e as KritzelShape,k as KritzelShapeTool,K as KritzelText,j as KritzelTextTool,p as KritzelThemeManager,n as KritzelWorkspace,S as ShapeType,W as WORKSPACE_EXPORT_VERSION,x as WORKSPACE_MIGRATIONS,t as darkTheme,s as lightTheme,w as runMigrations}from"./p-
|
|
1
|
+
export{A as APP_STATE_MIGRATIONS,C as CURRENT_APP_STATE_SCHEMA_VERSION,v as CURRENT_WORKSPACE_SCHEMA_VERSION,D as DEFAULT_BRUSH_CONFIG,r as DEFAULT_LINE_TOOL_CONFIG,q as DEFAULT_TEXT_CONFIG,H as HocuspocusSyncProvider,I as IndexedDBSyncProvider,u as KritzelAlignment,o as KritzelAnchorManager,f as KritzelBrushTool,l as KritzelCursorHelper,h as KritzelEraserTool,d as KritzelGroup,b as KritzelImage,i as KritzelImageTool,c as KritzelLine,g as KritzelLineTool,a as KritzelPath,m as KritzelSelectionTool,e as KritzelShape,k as KritzelShapeTool,K as KritzelText,j as KritzelTextTool,p as KritzelThemeManager,n as KritzelWorkspace,S as ShapeType,W as WORKSPACE_EXPORT_VERSION,x as WORKSPACE_MIGRATIONS,t as darkTheme,s as lightTheme,w as runMigrations}from"./p-Be65cOkQ.js";import*as T from"yjs";import{WebsocketProvider as y}from"y-websocket";import"y-indexeddb";const E=Math.floor,_=127,z=Number.MAX_SAFE_INTEGER;class P{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const O=()=>new P,R=t=>{const s=new Uint8Array((t=>{let s=t.cpos;for(let e=0;e<t.bufs.length;e++)s+=t.bufs[e].length;return s})(t));let e=0;for(let i=0;i<t.bufs.length;i++){const n=t.bufs[i];s.set(n,e),e+=n.length}return s.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),e),s},U=(t,s)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=s},N=(t,s)=>{for(;s>_;)U(t,128|_&s),s=E(s/128);U(t,_&s)},M=(t,s)=>{N(t,s.byteLength),((t,s)=>{const e=t.cbuf.length,i=t.cpos,n=((t,s)=>t<s?t:s)(e-i,s.length),r=s.length-n;t.cbuf.set(s.subarray(0,n),i),t.cpos+=n,r>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,s)=>t>s?t:s)(2*e,r)),t.cbuf.set(s.subarray(n)),t.cpos=r)})(t,s)},B=t=>new Error(t),L=B("Unexpected end of array"),F=B("Integer out of Range");class G{constructor(t){this.arr=t,this.pos=0}}const V=t=>((t,s)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,s);return t.pos+=s,e})(t,$(t)),$=t=>{let s=0,e=1;const i=t.arr.length;for(;t.pos<i;){const i=t.arr[t.pos++];if(s+=(i&_)*e,e*=128,i<128)return s;if(s>z)throw F}throw L};class X{type="local";doc;channel;_synced=!1;constructor(t,s,e){this.doc=s,this.channel=new BroadcastChannel(t),this.channel.onmessage=t=>{this.handleMessage(t.data)},this.doc.on("update",this.handleDocUpdate),this.broadcastSync(),setTimeout((()=>{this._synced=!0}),100),e?.quiet||console.info(`BroadcastChannel Provider initialized: ${t}`)}handleDocUpdate=(t,s)=>{if(s!==this){const s=O();N(s,0),M(s,t),this.channel.postMessage(R(s))}};handleMessage(t){const s=(e=new Uint8Array(t),new G(e));var e;switch($(s)){case 0:const t=V(s);T.applyUpdate(this.doc,t,this);break;case 1:this.broadcastSync();break;case 2:const e=V(s),i=T.encodeStateAsUpdate(this.doc,e);if(i.length>0){const t=O();N(t,0),M(t,i),this.channel.postMessage(R(t))}}}broadcastSync(){const t=O();N(t,2),M(t,T.encodeStateVector(this.doc)),this.channel.postMessage(R(t))}async connect(){if(!this._synced)return new Promise((t=>{const s=()=>{this._synced?t():setTimeout(s,50)};s()}))}disconnect(){}async reconnect(){return this.disconnect(),this.connect()}destroy(){this.doc.off("update",this.handleDocUpdate),this.channel.close()}}class Q{type="network";provider;isConnected=!1;_quiet=!1;get awareness(){return this.provider.awareness}constructor(t,s,e){const i=e?.url||"ws://localhost:1234",n=e?.roomName||t;this.provider=new y(i,n,s,{params:e?.params,protocols:e?.protocols,WebSocketPolyfill:e?.WebSocketPolyfill,awareness:e?.awareness,maxBackoffTime:e?.maxBackoffTime,disableBc:!0}),this._quiet=e?.quiet??!1,this.setupEventListeners(),this._quiet||console.info(`WebSocket Provider initialized: ${i}/${n}`)}static with(t){return{create:(s,e,i)=>{const n=i?{...t,...i}:t;return new Q(s,e,n)}}}setupEventListeners(){this.provider.on("status",(({status:t})=>{"connected"===t?(this.isConnected=!0,this._quiet||console.info("WebSocket connected")):"disconnected"===t&&(this.isConnected=!1,this._quiet||console.info("WebSocket disconnected"))})),this.provider.on("sync",(t=>{t&&!this._quiet&&console.info("WebSocket synced")}))}async connect(){if(!this.isConnected)return new Promise(((t,s)=>{const e=setTimeout((()=>{s(new Error("WebSocket connection timeout"))}),1e4),i=({status:s})=>{"connected"===s&&(clearTimeout(e),this.provider.off("status",i),this.isConnected=!0,t())};this.provider.on("status",i),this.provider.wsconnected&&(clearTimeout(e),this.provider.off("status",i),this.isConnected=!0,t())}))}disconnect(){this.provider&&this.provider.disconnect(),this.isConnected=!1}async reconnect(){return this.disconnect(),this.connect()}destroy(){this.provider&&this.provider.destroy(),this.isConnected=!1}}export{X as BroadcastSyncProvider,Q as WebSocketSyncProvider}
|