kritzel-stencil 0.1.55 → 0.1.56

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 (40) hide show
  1. package/dist/cjs/{alignment.enum-BS253Ylf.js → alignment.enum-DM2SB8lK.js} +254 -2
  2. package/dist/cjs/index.cjs.js +5 -252
  3. package/dist/cjs/kritzel-active-users_38.cjs.entry.js +128 -4
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stencil.cjs.js +1 -1
  6. package/dist/collection/classes/core/core.class.js +23 -0
  7. package/dist/collection/classes/core/viewport.class.js +3 -0
  8. package/dist/collection/classes/providers/hocuspocus-sync-provider.class.js +3 -0
  9. package/dist/collection/classes/providers/websocket-sync-provider.class.js +3 -0
  10. package/dist/collection/classes/structures/object-map.structure.js +73 -0
  11. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +32 -4
  12. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +73 -0
  13. package/dist/collection/constants/version.js +1 -1
  14. package/dist/components/index.js +1 -1
  15. package/dist/components/kritzel-editor.js +1 -1
  16. package/dist/components/kritzel-engine.js +1 -1
  17. package/dist/components/kritzel-settings.js +1 -1
  18. package/dist/components/p-BbWIRdou.js +9 -0
  19. package/dist/components/{p-iTMeCm1k.js → p-Dq3xfuFo.js} +1 -1
  20. package/dist/esm/{alignment.enum-CbEIUdk6.js → alignment.enum-DGrwm-y2.js} +254 -1
  21. package/dist/esm/index.js +5 -253
  22. package/dist/esm/kritzel-active-users_38.entry.js +128 -4
  23. package/dist/esm/loader.js +1 -1
  24. package/dist/esm/stencil.js +1 -1
  25. package/dist/stencil/index.esm.js +1 -1
  26. package/dist/stencil/p-70b0fb0d.entry.js +9 -0
  27. package/dist/stencil/{p-CbEIUdk6.js → p-DGrwm-y2.js} +1 -1
  28. package/dist/stencil/stencil.esm.js +1 -1
  29. package/dist/types/classes/core/core.class.d.ts +11 -0
  30. package/dist/types/classes/providers/hocuspocus-sync-provider.class.d.ts +2 -0
  31. package/dist/types/classes/providers/websocket-sync-provider.class.d.ts +2 -0
  32. package/dist/types/classes/structures/object-map.structure.d.ts +28 -0
  33. package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +2 -0
  34. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +8 -0
  35. package/dist/types/components.d.ts +17 -2
  36. package/dist/types/constants/version.d.ts +1 -1
  37. package/dist/types/interfaces/sync-provider.interface.d.ts +7 -0
  38. package/package.json +1 -1
  39. package/dist/components/p-Da1QJ-RQ.js +0 -9
  40. package/dist/stencil/p-374d3c86.entry.js +0 -9
@@ -25110,6 +25110,259 @@ class HocuspocusProvider extends EventEmitter {
25110
25110
  }
25111
25111
  }
25112
25112
 
25113
+ /**
25114
+ * Hocuspocus sync provider for real-time collaboration
25115
+ * Supports multiplexing - multiple documents can share the same WebSocket connection
25116
+ */
25117
+ class HocuspocusSyncProvider {
25118
+ provider;
25119
+ isConnected = false;
25120
+ isSynced = false;
25121
+ usesSharedSocket = false;
25122
+ get awareness() {
25123
+ return this.provider.awareness;
25124
+ }
25125
+ // Static shared WebSocket instance for multiplexing
25126
+ static sharedWebSocketProvider = null;
25127
+ constructor(docName, doc, options) {
25128
+ const name = options?.name || docName;
25129
+ const url = options?.url || 'ws://localhost:1234';
25130
+ // Use provided websocketProvider or the static shared one
25131
+ const websocketProvider = options?.websocketProvider || HocuspocusSyncProvider.sharedWebSocketProvider;
25132
+ if (websocketProvider) {
25133
+ // Multiplexing mode - use shared WebSocket connection
25134
+ this.usesSharedSocket = true;
25135
+ const config = {
25136
+ websocketProvider,
25137
+ name,
25138
+ document: doc,
25139
+ token: options?.token || null,
25140
+ onConnect: () => {
25141
+ if (this.isConnected) {
25142
+ return;
25143
+ }
25144
+ this.isConnected = true;
25145
+ if (!options?.quiet) {
25146
+ console.info(`Hocuspocus connected: ${name}`);
25147
+ }
25148
+ if (options?.onConnect) {
25149
+ options.onConnect();
25150
+ }
25151
+ },
25152
+ onDisconnect: () => {
25153
+ if (!this.isConnected && !this.isSynced) {
25154
+ return;
25155
+ }
25156
+ this.isConnected = false;
25157
+ this.isSynced = false;
25158
+ if (!options?.quiet) {
25159
+ console.info(`Hocuspocus disconnected: ${name}`);
25160
+ }
25161
+ if (options?.onDisconnect) {
25162
+ options.onDisconnect();
25163
+ }
25164
+ },
25165
+ onSynced: () => {
25166
+ if (this.isSynced) {
25167
+ return;
25168
+ }
25169
+ this.isSynced = true;
25170
+ if (!options?.quiet) {
25171
+ console.info(`Hocuspocus synced: ${name}`);
25172
+ }
25173
+ if (options?.onSynced) {
25174
+ options.onSynced();
25175
+ }
25176
+ },
25177
+ };
25178
+ // Add optional settings
25179
+ if (options?.forceSyncInterval !== undefined) {
25180
+ config.forceSyncInterval = options.forceSyncInterval;
25181
+ }
25182
+ if (options?.onAuthenticationFailed) {
25183
+ config.onAuthenticationFailed = options.onAuthenticationFailed;
25184
+ }
25185
+ if (options?.onStatus) {
25186
+ config.onStatus = options.onStatus;
25187
+ }
25188
+ this.provider = new HocuspocusProvider(config);
25189
+ // Must call attach() explicitly when using shared socket
25190
+ this.provider.attach();
25191
+ if (!options?.quiet) {
25192
+ console.info(`Hocuspocus Provider initialized (multiplexed): ${name}`);
25193
+ }
25194
+ }
25195
+ else {
25196
+ // Standalone mode - create own WebSocket connection
25197
+ this.usesSharedSocket = false;
25198
+ const config = {
25199
+ url,
25200
+ name,
25201
+ document: doc,
25202
+ token: options?.token || null,
25203
+ onConnect: () => {
25204
+ if (this.isConnected) {
25205
+ return;
25206
+ }
25207
+ this.isConnected = true;
25208
+ if (!options?.quiet) {
25209
+ console.info(`Hocuspocus connected: ${name}`);
25210
+ }
25211
+ if (options?.onConnect) {
25212
+ options.onConnect();
25213
+ }
25214
+ },
25215
+ onDisconnect: () => {
25216
+ if (!this.isConnected && !this.isSynced) {
25217
+ return;
25218
+ }
25219
+ this.isConnected = false;
25220
+ this.isSynced = false;
25221
+ if (!options?.quiet) {
25222
+ console.info(`Hocuspocus disconnected: ${name}`);
25223
+ }
25224
+ if (options?.onDisconnect) {
25225
+ options.onDisconnect();
25226
+ }
25227
+ },
25228
+ onSynced: () => {
25229
+ if (this.isSynced) {
25230
+ return;
25231
+ }
25232
+ this.isSynced = true;
25233
+ if (!options?.quiet) {
25234
+ console.info(`Hocuspocus synced: ${name}`);
25235
+ }
25236
+ if (options?.onSynced) {
25237
+ options.onSynced();
25238
+ }
25239
+ },
25240
+ };
25241
+ // Add optional settings
25242
+ if (options?.forceSyncInterval !== undefined) {
25243
+ config.forceSyncInterval = options.forceSyncInterval;
25244
+ }
25245
+ if (options?.onAuthenticationFailed) {
25246
+ config.onAuthenticationFailed = options.onAuthenticationFailed;
25247
+ }
25248
+ if (options?.onStatus) {
25249
+ config.onStatus = options.onStatus;
25250
+ }
25251
+ if (options?.WebSocketPolyfill) {
25252
+ config.WebSocketPolyfill = options.WebSocketPolyfill;
25253
+ }
25254
+ this.provider = new HocuspocusProvider(config);
25255
+ if (!options?.quiet) {
25256
+ console.info(`Hocuspocus Provider initialized: ${url}/${name}`);
25257
+ }
25258
+ }
25259
+ }
25260
+ /**
25261
+ * Create a shared WebSocket connection for multiplexing
25262
+ * Call this once to create a shared connection that multiple providers can use
25263
+ */
25264
+ static createSharedWebSocket(options) {
25265
+ if (HocuspocusSyncProvider.sharedWebSocketProvider) {
25266
+ console.warn('Shared WebSocket already exists. Returning existing instance.');
25267
+ return HocuspocusSyncProvider.sharedWebSocketProvider;
25268
+ }
25269
+ const config = {
25270
+ url: options.url,
25271
+ };
25272
+ if (options.WebSocketPolyfill) {
25273
+ config.WebSocketPolyfill = options.WebSocketPolyfill;
25274
+ }
25275
+ if (options.onConnect) {
25276
+ config.onConnect = options.onConnect;
25277
+ }
25278
+ if (options.onDisconnect) {
25279
+ config.onDisconnect = options.onDisconnect;
25280
+ }
25281
+ if (options.onStatus) {
25282
+ config.onStatus = options.onStatus;
25283
+ }
25284
+ HocuspocusSyncProvider.sharedWebSocketProvider = new HocuspocusProviderWebsocket(config);
25285
+ console.info(`Shared Hocuspocus WebSocket created: ${options.url}`);
25286
+ return HocuspocusSyncProvider.sharedWebSocketProvider;
25287
+ }
25288
+ /**
25289
+ * Destroy the shared WebSocket connection
25290
+ * Call this when you're done with all multiplexed providers
25291
+ */
25292
+ static destroySharedWebSocket() {
25293
+ if (HocuspocusSyncProvider.sharedWebSocketProvider) {
25294
+ HocuspocusSyncProvider.sharedWebSocketProvider.destroy();
25295
+ HocuspocusSyncProvider.sharedWebSocketProvider = null;
25296
+ console.info('Shared Hocuspocus WebSocket destroyed');
25297
+ }
25298
+ }
25299
+ /**
25300
+ * Get the shared WebSocket provider instance (if it exists)
25301
+ */
25302
+ static getSharedWebSocket() {
25303
+ return HocuspocusSyncProvider.sharedWebSocketProvider;
25304
+ }
25305
+ /**
25306
+ * Static factory method for creating HocuspocusSyncProvider with configuration options
25307
+ * Returns a ProviderFactory that can be used in sync configuration
25308
+ */
25309
+ static with(options) {
25310
+ return {
25311
+ create: (docName, doc, runtimeOptions) => {
25312
+ const mergedOptions = runtimeOptions ? { ...options, ...runtimeOptions } : options;
25313
+ return new HocuspocusSyncProvider(docName, doc, mergedOptions);
25314
+ },
25315
+ };
25316
+ }
25317
+ async connect() {
25318
+ if (this.isSynced) {
25319
+ return;
25320
+ }
25321
+ return new Promise((resolve, reject) => {
25322
+ const timeout = setTimeout(() => {
25323
+ reject(new Error('Hocuspocus connection timeout'));
25324
+ }, 10000); // 10 second timeout
25325
+ const syncHandler = () => {
25326
+ clearTimeout(timeout);
25327
+ this.provider.off('synced', syncHandler);
25328
+ resolve();
25329
+ };
25330
+ this.provider.on('synced', syncHandler);
25331
+ // If already synced, resolve immediately
25332
+ if (this.provider.isSynced) {
25333
+ clearTimeout(timeout);
25334
+ this.provider.off('synced', syncHandler);
25335
+ resolve();
25336
+ return;
25337
+ }
25338
+ // Connect if not already connected (standalone mode only)
25339
+ if (!this.isConnected && !this.usesSharedSocket) {
25340
+ this.provider.connect();
25341
+ }
25342
+ });
25343
+ }
25344
+ disconnect() {
25345
+ if (this.provider) {
25346
+ if (this.usesSharedSocket) {
25347
+ // Detach from shared socket instead of disconnecting
25348
+ this.provider.detach();
25349
+ }
25350
+ else {
25351
+ this.provider.disconnect();
25352
+ }
25353
+ }
25354
+ this.isConnected = false;
25355
+ this.isSynced = false;
25356
+ }
25357
+ destroy() {
25358
+ if (this.provider) {
25359
+ this.provider.destroy();
25360
+ }
25361
+ this.isConnected = false;
25362
+ this.isSynced = false;
25363
+ }
25364
+ }
25365
+
25113
25366
  /** Current version of the workspace export format */
25114
25367
  const WORKSPACE_EXPORT_VERSION = '1.1.0';
25115
25368
  /**
@@ -26589,8 +26842,7 @@ exports.DEFAULT_BRUSH_CONFIG = DEFAULT_BRUSH_CONFIG;
26589
26842
  exports.DEFAULT_COLOR_PALETTE = DEFAULT_COLOR_PALETTE;
26590
26843
  exports.DEFAULT_LINE_TOOL_CONFIG = DEFAULT_LINE_TOOL_CONFIG;
26591
26844
  exports.DEFAULT_TEXT_CONFIG = DEFAULT_TEXT_CONFIG;
26592
- exports.HocuspocusProvider = HocuspocusProvider;
26593
- exports.HocuspocusProviderWebsocket = HocuspocusProviderWebsocket;
26845
+ exports.HocuspocusSyncProvider = HocuspocusSyncProvider;
26594
26846
  exports.IndexedDBSyncProvider = IndexedDBSyncProvider;
26595
26847
  exports.KritzelAnchorManager = KritzelAnchorManager;
26596
26848
  exports.KritzelBaseHandler = KritzelBaseHandler;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var alignment_enum = require('./alignment.enum-BS253Ylf.js');
3
+ var alignment_enum = require('./alignment.enum-DM2SB8lK.js');
4
4
  var Y = require('yjs');
5
5
  var yWebsocket = require('y-websocket');
6
6
  require('y-indexeddb');
@@ -454,6 +454,9 @@ class WebSocketSyncProvider {
454
454
  provider;
455
455
  isConnected = false;
456
456
  _quiet = false;
457
+ get awareness() {
458
+ return this.provider.awareness;
459
+ }
457
460
  constructor(docName, doc, options) {
458
461
  const url = options?.url || 'ws://localhost:1234';
459
462
  const roomName = options?.roomName || docName;
@@ -544,259 +547,10 @@ class WebSocketSyncProvider {
544
547
  }
545
548
  }
546
549
 
547
- /**
548
- * Hocuspocus sync provider for real-time collaboration
549
- * Supports multiplexing - multiple documents can share the same WebSocket connection
550
- */
551
- class HocuspocusSyncProvider {
552
- provider;
553
- isConnected = false;
554
- isSynced = false;
555
- usesSharedSocket = false;
556
- // Static shared WebSocket instance for multiplexing
557
- static sharedWebSocketProvider = null;
558
- constructor(docName, doc, options) {
559
- const name = options?.name || docName;
560
- const url = options?.url || 'ws://localhost:1234';
561
- // Use provided websocketProvider or the static shared one
562
- const websocketProvider = options?.websocketProvider || HocuspocusSyncProvider.sharedWebSocketProvider;
563
- if (websocketProvider) {
564
- // Multiplexing mode - use shared WebSocket connection
565
- this.usesSharedSocket = true;
566
- const config = {
567
- websocketProvider,
568
- name,
569
- document: doc,
570
- token: options?.token || null,
571
- onConnect: () => {
572
- if (this.isConnected) {
573
- return;
574
- }
575
- this.isConnected = true;
576
- if (!options?.quiet) {
577
- console.info(`Hocuspocus connected: ${name}`);
578
- }
579
- if (options?.onConnect) {
580
- options.onConnect();
581
- }
582
- },
583
- onDisconnect: () => {
584
- if (!this.isConnected && !this.isSynced) {
585
- return;
586
- }
587
- this.isConnected = false;
588
- this.isSynced = false;
589
- if (!options?.quiet) {
590
- console.info(`Hocuspocus disconnected: ${name}`);
591
- }
592
- if (options?.onDisconnect) {
593
- options.onDisconnect();
594
- }
595
- },
596
- onSynced: () => {
597
- if (this.isSynced) {
598
- return;
599
- }
600
- this.isSynced = true;
601
- if (!options?.quiet) {
602
- console.info(`Hocuspocus synced: ${name}`);
603
- }
604
- if (options?.onSynced) {
605
- options.onSynced();
606
- }
607
- },
608
- };
609
- // Add optional settings
610
- if (options?.forceSyncInterval !== undefined) {
611
- config.forceSyncInterval = options.forceSyncInterval;
612
- }
613
- if (options?.onAuthenticationFailed) {
614
- config.onAuthenticationFailed = options.onAuthenticationFailed;
615
- }
616
- if (options?.onStatus) {
617
- config.onStatus = options.onStatus;
618
- }
619
- this.provider = new alignment_enum.HocuspocusProvider(config);
620
- // Must call attach() explicitly when using shared socket
621
- this.provider.attach();
622
- if (!options?.quiet) {
623
- console.info(`Hocuspocus Provider initialized (multiplexed): ${name}`);
624
- }
625
- }
626
- else {
627
- // Standalone mode - create own WebSocket connection
628
- this.usesSharedSocket = false;
629
- const config = {
630
- url,
631
- name,
632
- document: doc,
633
- token: options?.token || null,
634
- onConnect: () => {
635
- if (this.isConnected) {
636
- return;
637
- }
638
- this.isConnected = true;
639
- if (!options?.quiet) {
640
- console.info(`Hocuspocus connected: ${name}`);
641
- }
642
- if (options?.onConnect) {
643
- options.onConnect();
644
- }
645
- },
646
- onDisconnect: () => {
647
- if (!this.isConnected && !this.isSynced) {
648
- return;
649
- }
650
- this.isConnected = false;
651
- this.isSynced = false;
652
- if (!options?.quiet) {
653
- console.info(`Hocuspocus disconnected: ${name}`);
654
- }
655
- if (options?.onDisconnect) {
656
- options.onDisconnect();
657
- }
658
- },
659
- onSynced: () => {
660
- if (this.isSynced) {
661
- return;
662
- }
663
- this.isSynced = true;
664
- if (!options?.quiet) {
665
- console.info(`Hocuspocus synced: ${name}`);
666
- }
667
- if (options?.onSynced) {
668
- options.onSynced();
669
- }
670
- },
671
- };
672
- // Add optional settings
673
- if (options?.forceSyncInterval !== undefined) {
674
- config.forceSyncInterval = options.forceSyncInterval;
675
- }
676
- if (options?.onAuthenticationFailed) {
677
- config.onAuthenticationFailed = options.onAuthenticationFailed;
678
- }
679
- if (options?.onStatus) {
680
- config.onStatus = options.onStatus;
681
- }
682
- if (options?.WebSocketPolyfill) {
683
- config.WebSocketPolyfill = options.WebSocketPolyfill;
684
- }
685
- this.provider = new alignment_enum.HocuspocusProvider(config);
686
- if (!options?.quiet) {
687
- console.info(`Hocuspocus Provider initialized: ${url}/${name}`);
688
- }
689
- }
690
- }
691
- /**
692
- * Create a shared WebSocket connection for multiplexing
693
- * Call this once to create a shared connection that multiple providers can use
694
- */
695
- static createSharedWebSocket(options) {
696
- if (HocuspocusSyncProvider.sharedWebSocketProvider) {
697
- console.warn('Shared WebSocket already exists. Returning existing instance.');
698
- return HocuspocusSyncProvider.sharedWebSocketProvider;
699
- }
700
- const config = {
701
- url: options.url,
702
- };
703
- if (options.WebSocketPolyfill) {
704
- config.WebSocketPolyfill = options.WebSocketPolyfill;
705
- }
706
- if (options.onConnect) {
707
- config.onConnect = options.onConnect;
708
- }
709
- if (options.onDisconnect) {
710
- config.onDisconnect = options.onDisconnect;
711
- }
712
- if (options.onStatus) {
713
- config.onStatus = options.onStatus;
714
- }
715
- HocuspocusSyncProvider.sharedWebSocketProvider = new alignment_enum.HocuspocusProviderWebsocket(config);
716
- console.info(`Shared Hocuspocus WebSocket created: ${options.url}`);
717
- return HocuspocusSyncProvider.sharedWebSocketProvider;
718
- }
719
- /**
720
- * Destroy the shared WebSocket connection
721
- * Call this when you're done with all multiplexed providers
722
- */
723
- static destroySharedWebSocket() {
724
- if (HocuspocusSyncProvider.sharedWebSocketProvider) {
725
- HocuspocusSyncProvider.sharedWebSocketProvider.destroy();
726
- HocuspocusSyncProvider.sharedWebSocketProvider = null;
727
- console.info('Shared Hocuspocus WebSocket destroyed');
728
- }
729
- }
730
- /**
731
- * Get the shared WebSocket provider instance (if it exists)
732
- */
733
- static getSharedWebSocket() {
734
- return HocuspocusSyncProvider.sharedWebSocketProvider;
735
- }
736
- /**
737
- * Static factory method for creating HocuspocusSyncProvider with configuration options
738
- * Returns a ProviderFactory that can be used in sync configuration
739
- */
740
- static with(options) {
741
- return {
742
- create: (docName, doc, runtimeOptions) => {
743
- const mergedOptions = runtimeOptions ? { ...options, ...runtimeOptions } : options;
744
- return new HocuspocusSyncProvider(docName, doc, mergedOptions);
745
- },
746
- };
747
- }
748
- async connect() {
749
- if (this.isSynced) {
750
- return;
751
- }
752
- return new Promise((resolve, reject) => {
753
- const timeout = setTimeout(() => {
754
- reject(new Error('Hocuspocus connection timeout'));
755
- }, 10000); // 10 second timeout
756
- const syncHandler = () => {
757
- clearTimeout(timeout);
758
- this.provider.off('synced', syncHandler);
759
- resolve();
760
- };
761
- this.provider.on('synced', syncHandler);
762
- // If already synced, resolve immediately
763
- if (this.provider.isSynced) {
764
- clearTimeout(timeout);
765
- this.provider.off('synced', syncHandler);
766
- resolve();
767
- return;
768
- }
769
- // Connect if not already connected (standalone mode only)
770
- if (!this.isConnected && !this.usesSharedSocket) {
771
- this.provider.connect();
772
- }
773
- });
774
- }
775
- disconnect() {
776
- if (this.provider) {
777
- if (this.usesSharedSocket) {
778
- // Detach from shared socket instead of disconnecting
779
- this.provider.detach();
780
- }
781
- else {
782
- this.provider.disconnect();
783
- }
784
- }
785
- this.isConnected = false;
786
- this.isSynced = false;
787
- }
788
- destroy() {
789
- if (this.provider) {
790
- this.provider.destroy();
791
- }
792
- this.isConnected = false;
793
- this.isSynced = false;
794
- }
795
- }
796
-
797
550
  exports.DEFAULT_BRUSH_CONFIG = alignment_enum.DEFAULT_BRUSH_CONFIG;
798
551
  exports.DEFAULT_LINE_TOOL_CONFIG = alignment_enum.DEFAULT_LINE_TOOL_CONFIG;
799
552
  exports.DEFAULT_TEXT_CONFIG = alignment_enum.DEFAULT_TEXT_CONFIG;
553
+ exports.HocuspocusSyncProvider = alignment_enum.HocuspocusSyncProvider;
800
554
  exports.IndexedDBSyncProvider = alignment_enum.IndexedDBSyncProvider;
801
555
  Object.defineProperty(exports, "KritzelAlignment", {
802
556
  enumerable: true,
@@ -827,5 +581,4 @@ exports.WORKSPACE_EXPORT_VERSION = alignment_enum.WORKSPACE_EXPORT_VERSION;
827
581
  exports.darkTheme = alignment_enum.darkTheme;
828
582
  exports.lightTheme = alignment_enum.lightTheme;
829
583
  exports.BroadcastSyncProvider = BroadcastSyncProvider;
830
- exports.HocuspocusSyncProvider = HocuspocusSyncProvider;
831
584
  exports.WebSocketSyncProvider = WebSocketSyncProvider;