lib0 0.2.42 → 0.2.43

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 (74) hide show
  1. package/README.md +78 -72
  2. package/bin/gendocs.js +1 -1
  3. package/component.d.ts +4 -1
  4. package/component.d.ts.map +1 -1
  5. package/component.js +4 -1
  6. package/dist/{broadcastchannel-8a61b21a.cjs → broadcastchannel-044f32d2.cjs} +2 -2
  7. package/dist/{broadcastchannel-8a61b21a.cjs.map → broadcastchannel-044f32d2.cjs.map} +1 -1
  8. package/dist/broadcastchannel.cjs +3 -3
  9. package/dist/{buffer-ac2cdedf.cjs → buffer-49880125.cjs} +2 -2
  10. package/dist/{buffer-ac2cdedf.cjs.map → buffer-49880125.cjs.map} +1 -1
  11. package/dist/buffer.cjs +2 -2
  12. package/dist/component.cjs +5 -2
  13. package/dist/component.cjs.map +1 -1
  14. package/dist/component.d.ts +4 -1
  15. package/dist/component.d.ts.map +1 -1
  16. package/dist/decoding.cjs +2 -2
  17. package/dist/encoding.cjs +2 -2
  18. package/dist/{error-55a9a8c8.cjs → error-873c9cbf.cjs} +4 -4
  19. package/dist/error-873c9cbf.cjs.map +1 -0
  20. package/dist/error.cjs +1 -1
  21. package/dist/error.d.ts.map +1 -1
  22. package/dist/index.cjs +7 -7
  23. package/dist/{indexeddb-44227700.cjs → indexeddb-5b4b0e13.cjs} +27 -25
  24. package/dist/indexeddb-5b4b0e13.cjs.map +1 -0
  25. package/dist/indexeddb.cjs +3 -3
  26. package/dist/indexeddb.d.ts +2 -2
  27. package/dist/indexeddb.d.ts.map +1 -1
  28. package/dist/isomorphic.cjs +2 -6
  29. package/dist/isomorphic.cjs.map +1 -1
  30. package/dist/{number-24f1eabe.cjs → number-e62129bc.cjs} +5 -2
  31. package/dist/number-e62129bc.cjs.map +1 -0
  32. package/dist/number.cjs +2 -1
  33. package/dist/number.cjs.map +1 -1
  34. package/dist/number.d.ts +1 -0
  35. package/dist/number.d.ts.map +1 -1
  36. package/dist/{prng-695120cc.cjs → prng-97174619.cjs} +2 -2
  37. package/dist/{prng-695120cc.cjs.map → prng-97174619.cjs.map} +1 -1
  38. package/dist/prng.cjs +3 -3
  39. package/dist/{promise-f0a086b2.cjs → promise-1a9fe712.cjs} +10 -1
  40. package/dist/{promise-f0a086b2.cjs.map → promise-1a9fe712.cjs.map} +1 -1
  41. package/dist/promise.cjs +2 -1
  42. package/dist/promise.cjs.map +1 -1
  43. package/dist/promise.d.ts +1 -0
  44. package/dist/promise.d.ts.map +1 -1
  45. package/dist/string.cjs +1 -3
  46. package/dist/string.cjs.map +1 -1
  47. package/dist/test.cjs +30 -25
  48. package/dist/test.cjs.map +1 -1
  49. package/dist/test.js +31 -26
  50. package/dist/test.js.map +1 -1
  51. package/dist/testing.cjs +8 -5
  52. package/dist/testing.cjs.map +1 -1
  53. package/dist/testing.d.ts.map +1 -1
  54. package/dist/websocket.d.ts +1 -1
  55. package/dist/websocket.d.ts.map +1 -1
  56. package/error.d.ts.map +1 -1
  57. package/error.js +3 -3
  58. package/indexeddb.d.ts +2 -2
  59. package/indexeddb.d.ts.map +1 -1
  60. package/indexeddb.js +25 -23
  61. package/number.d.ts +1 -0
  62. package/number.d.ts.map +1 -1
  63. package/number.js +1 -0
  64. package/package.json +3 -3
  65. package/promise.d.ts +1 -0
  66. package/promise.d.ts.map +1 -1
  67. package/promise.js +7 -0
  68. package/testing.d.ts.map +1 -1
  69. package/testing.js +5 -2
  70. package/websocket.d.ts +1 -1
  71. package/websocket.d.ts.map +1 -1
  72. package/dist/error-55a9a8c8.cjs.map +0 -1
  73. package/dist/indexeddb-44227700.cjs.map +0 -1
  74. package/dist/number-24f1eabe.cjs.map +0 -1
package/README.md CHANGED
@@ -75,7 +75,7 @@ import module from 'lib0/[module].js'
75
75
  ## Modules
76
76
 
77
77
  <details><summary><b>[lib0/array]</b> Utility module to work with Arrays.</summary>
78
- <pre>import * as array from 'lib0/array.js'</pre>
78
+ <pre>import * as array from 'lib0/array'</pre>
79
79
  <dl>
80
80
  <b><code>array.last(arr: Array&lt;L&gt;): L</code></b><br>
81
81
  <dd><p>Return the last element of an array. The element must exist</p></dd>
@@ -94,7 +94,7 @@ import module from 'lib0/[module].js'
94
94
  </dl>
95
95
  </details>
96
96
  <details><summary><b>[lib0/binary]</b> Binary data constants.</summary>
97
- <pre>import * as binary from 'lib0/binary.js'</pre>
97
+ <pre>import * as binary from 'lib0/binary'</pre>
98
98
  <dl>
99
99
  <b><code>binary.BIT1: number</code></b><br>
100
100
  <dd><p>n-th bit activated.</p></dd>
@@ -166,7 +166,7 @@ import module from 'lib0/[module].js'
166
166
  </dl>
167
167
  </details>
168
168
  <details><summary><b>[lib0/broadcastchannel]</b> Helpers for cross-tab communication using broadcastchannel with LocalStorage fallback.</summary>
169
- <pre>import * as broadcastchannel from 'lib0/broadcastchannel.js'</pre>
169
+ <pre>import * as broadcastchannel from 'lib0/broadcastchannel'</pre>
170
170
 
171
171
  <pre class="prettyprint source lang-js"><code>// In browser window A:
172
172
  broadcastchannel.subscribe('my events', data => console.log(data))
@@ -185,7 +185,7 @@ broadcastchannel.publish('my events', 'hello from tab B') // => A: 'hello from t
185
185
  </dl>
186
186
  </details>
187
187
  <details><summary><b>[lib0/buffer]</b> Utility functions to work with buffers (Uint8Array).</summary>
188
- <pre>import * as buffer from 'lib0/buffer.js'</pre>
188
+ <pre>import * as buffer from 'lib0/buffer'</pre>
189
189
  <dl>
190
190
  <b><code>buffer.createUint8ArrayFromLen(len: number)</code></b><br>
191
191
  <b><code>buffer.createUint8ArrayViewFromArrayBuffer(buffer: ArrayBuffer, byteOffset: number, length: number)</code></b><br>
@@ -204,11 +204,11 @@ See encoding.writeAny for more information.</p></dd>
204
204
  </dl>
205
205
  </details>
206
206
  <details><summary><b>[lib0/component]</b> Web components.</summary>
207
- <pre>import * as component from 'lib0/component.js'</pre>
207
+ <pre>import * as component from 'lib0/component'</pre>
208
208
  <dl>
209
- <b><code>component.registry</code></b><br>
209
+ <b><code>component.registry: CustomElementRegistry</code></b><br>
210
210
  <b><code>component.define(name: string, constr: any, opts: ElementDefinitionOptions)</code></b><br>
211
- <b><code>component.whenDefined(name: string): Promise&lt;void&gt;</code></b><br>
211
+ <b><code>component.whenDefined(name: string): Promise&lt;CustomElementConstructor&gt;</code></b><br>
212
212
  <b><code>new component.Lib0Component(state: S)</code></b><br>
213
213
  <b><code>component.Lib0Component#state: S|null</code></b><br>
214
214
  <b><code>component.Lib0Component#setState(state: S, forceStateUpdate: boolean)</code></b><br>
@@ -220,13 +220,13 @@ See encoding.writeAny for more information.</p></dd>
220
220
  </dl>
221
221
  </details>
222
222
  <details><summary><b>[lib0/conditions]</b> Often used conditions.</summary>
223
- <pre>import * as conditions from 'lib0/conditions.js'</pre>
223
+ <pre>import * as conditions from 'lib0/conditions'</pre>
224
224
  <dl>
225
225
  <b><code>conditions.undefinedToNull</code></b><br>
226
226
  </dl>
227
227
  </details>
228
228
  <details><summary><b>[lib0/decoding]</b> Efficient schema-less binary decoding with support for variable length encoding.</summary>
229
- <pre>import * as decoding from 'lib0/decoding.js'</pre>
229
+ <pre>import * as decoding from 'lib0/decoding'</pre>
230
230
 
231
231
  <p>Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.</p>
232
232
  <p>Encodes numbers in little-endian order (least to most significant byte order)
@@ -376,7 +376,7 @@ For effiency reasons we apply a maximum of 10000 characters at once.</p></dd>
376
376
  </dl>
377
377
  </details>
378
378
  <details><summary><b>[lib0/diff]</b> Efficient diffs.</summary>
379
- <pre>import * as diff from 'lib0/diff.js'</pre>
379
+ <pre>import * as diff from 'lib0/diff'</pre>
380
380
  <dl>
381
381
  <b><code>diff.simpleDiffString(a: string, b: string): module:diff~SimpleDiff&lt;string&gt;</code></b><br>
382
382
  <dd><p>Create a diff between two strings. This diff implementation is highly
@@ -390,7 +390,7 @@ can better optimize these function calls.</p></dd>
390
390
  </dl>
391
391
  </details>
392
392
  <details><summary><b>[lib0/dom]</b> Utility module to work with the DOM.</summary>
393
- <pre>import * as dom from 'lib0/dom.js'</pre>
393
+ <pre>import * as dom from 'lib0/dom'</pre>
394
394
  <dl>
395
395
  <b><code>dom.doc: Document</code></b><br>
396
396
  <b><code>dom.createElement</code></b><br>
@@ -434,7 +434,7 @@ can better optimize these function calls.</p></dd>
434
434
  </dl>
435
435
  </details>
436
436
  <details><summary><b>[lib0/encoding]</b> Efficient schema-less binary encoding with support for variable length encoding.</summary>
437
- <pre>import * as encoding from 'lib0/encoding.js'</pre>
437
+ <pre>import * as encoding from 'lib0/encoding'</pre>
438
438
 
439
439
  <p>Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.</p>
440
440
  <p>Encodes numbers in little-endian order (least to most significant byte order)
@@ -677,7 +677,7 @@ In practice, when decoding several million small strings, the GC will kick in mo
677
677
  </dl>
678
678
  </details>
679
679
  <details><summary><b>[lib0/map]</b> Isomorphic module to work access the environment (query params, env variables).</summary>
680
- <pre>import * as map from 'lib0/environment.js'</pre>
680
+ <pre>import * as map from 'lib0/environment'</pre>
681
681
  <dl>
682
682
  <b><code>map.isNode</code></b><br>
683
683
  <b><code>map.isBrowser</code></b><br>
@@ -691,15 +691,15 @@ In practice, when decoding several million small strings, the GC will kick in mo
691
691
  </dl>
692
692
  </details>
693
693
  <details><summary><b>[lib0/error]</b> Error helpers.</summary>
694
- <pre>import * as error from 'lib0/error.js'</pre>
694
+ <pre>import * as error from 'lib0/error'</pre>
695
695
  <dl>
696
- <b><code>error.create</code></b><br>
697
- <b><code>error.methodUnimplemented</code></b><br>
698
- <b><code>error.unexpectedCase</code></b><br>
696
+ <b><code>error.create(s: string): Error</code></b><br>
697
+ <b><code>error.methodUnimplemented(): never</code></b><br>
698
+ <b><code>error.unexpectedCase(): never</code></b><br>
699
699
  </dl>
700
700
  </details>
701
701
  <details><summary><b>[lib0/eventloop]</b> Utility module to work with EcmaScript's event loop.</summary>
702
- <pre>import * as eventloop from 'lib0/eventloop.js'</pre>
702
+ <pre>import * as eventloop from 'lib0/eventloop'</pre>
703
703
  <dl>
704
704
  <b><code>eventloop.enqueue(f: function():void)</code></b><br>
705
705
  <b><code>eventloop#destroy()</code></b><br>
@@ -713,7 +713,7 @@ In practice, when decoding several million small strings, the GC will kick in mo
713
713
  </dl>
714
714
  </details>
715
715
  <details><summary><b>[lib0/function]</b> Common functions and function call helpers.</summary>
716
- <pre>import * as function from 'lib0/function.js'</pre>
716
+ <pre>import * as function from 'lib0/function'</pre>
717
717
  <dl>
718
718
  <b><code>function.callAll(fs: Array&lt;function&gt;, args: Array&lt;any&gt;)</code></b><br>
719
719
  <dd><p>Calls all functions in <code>fs</code> with args. Only throws after all functions were called.</p></dd>
@@ -726,47 +726,51 @@ In practice, when decoding several million small strings, the GC will kick in mo
726
726
  </dl>
727
727
  </details>
728
728
  <details><summary><b>[lib0/lib0]</b> Experimental method to import lib0.</summary>
729
- <pre>import * as lib0 from 'lib0/index.js'</pre>
729
+ <pre>import * as lib0 from 'lib0/index'</pre>
730
730
 
731
731
  <p>Not recommended if the module bundler doesn't support dead code elimination.</p>
732
732
  <dl>
733
733
  </dl>
734
734
  </details>
735
- <details><summary><b>[lib0/idb]</b> Helpers to work with IndexedDB.</summary>
736
- <pre>import * as idb from 'lib0/indexeddb.js'</pre>
735
+ <details><summary><b>[lib0/indexeddb]</b> Helpers to work with IndexedDB.</summary>
736
+ <pre>import * as indexeddb from 'lib0/indexeddb'</pre>
737
737
  <dl>
738
- <b><code>idb.rtop</code></b><br>
739
- <b><code>idb.openDB</code></b><br>
740
- <b><code>idb.deleteDB</code></b><br>
741
- <b><code>idb.createStores</code></b><br>
742
- <b><code>idb.transact(db: IDBDatabase, stores: Array&lt;string&gt;, access: "readwrite"|"readonly"): Array&lt;IDBObjectStore&gt;</code></b><br>
743
- <b><code>idb.count</code></b><br>
744
- <b><code>idb.get</code></b><br>
745
- <b><code>idb.del</code></b><br>
746
- <b><code>idb.put</code></b><br>
747
- <b><code>idb.add</code></b><br>
748
- <b><code>idb.addAutoKey</code></b><br>
749
- <b><code>idb.getAll</code></b><br>
750
- <b><code>idb.getAllKeys</code></b><br>
751
- <b><code>idb.queryFirst(store: IDBObjectStore, query: IDBKeyRange|null, direction: 'next'|'prev'|'nextunique'|'prevunique'): Promise&lt;any&gt;</code></b><br>
752
- <b><code>idb.getLastKey(store: IDBObjectStore): Promise&lt;any&gt;</code></b><br>
753
- <b><code>idb.getFirstKey(store: IDBObjectStore): Promise&lt;any&gt;</code></b><br>
754
- <b><code>idb.getAllKeysValues</code></b><br>
755
- <b><code>idb.iterate</code></b><br>
756
- <b><code>idb.iterateKeys</code></b><br>
757
- <b><code>idb.getStore</code></b><br>
758
- <b><code>idb.createIDBKeyRangeBound</code></b><br>
759
- <b><code>idb.createIDBKeyRangeUpperBound</code></b><br>
760
- <b><code>idb.createIDBKeyRangeLowerBound</code></b><br>
738
+ <b><code>indexeddb.rtop(request: IDBRequest): Promise&lt;any&gt;</code></b><br>
739
+ <dd><p>IDB Request to Promise transformer</p></dd>
740
+ <b><code>indexeddb.openDB(name: string, initDB: function(IDBDatabase):any): Promise&lt;IDBDatabase&gt;</code></b><br>
741
+ <b><code>indexeddb.deleteDB(name: string)</code></b><br>
742
+ <b><code>indexeddb.createStores(db: IDBDatabase, definitions: Array&lt;Array&lt;string&gt;|Array&lt;string|IDBObjectStoreParameters|undefined&gt;&gt;)</code></b><br>
743
+ <b><code>indexeddb.transact(db: IDBDatabase, stores: Array&lt;string&gt;, access: "readwrite"|"readonly"): Array&lt;IDBObjectStore&gt;</code></b><br>
744
+ <b><code>indexeddb.count(store: IDBObjectStore, range: IDBKeyRange): Promise&lt;number&gt;</code></b><br>
745
+ <b><code>indexeddb.get(store: IDBObjectStore, key: String | number | ArrayBuffer | Date | Array&lt;any&gt; ): Promise&lt;String | number | ArrayBuffer | Date | Array&lt;any&gt;&gt;</code></b><br>
746
+ <b><code>indexeddb.del(store: IDBObjectStore, key: String | number | ArrayBuffer | Date | IDBKeyRange | Array&lt;any&gt; )</code></b><br>
747
+ <b><code>indexeddb.put(store: IDBObjectStore, item: String | number | ArrayBuffer | Date | boolean, key: String | number | ArrayBuffer | Date | Array&lt;any&gt;)</code></b><br>
748
+ <b><code>indexeddb.add(store: IDBObjectStore, item: String|number|ArrayBuffer|Date|boolean, key: String|number|ArrayBuffer|Date|Array.&lt;any&gt;): Promise&lt;any&gt;</code></b><br>
749
+ <b><code>indexeddb.addAutoKey(store: IDBObjectStore, item: String|number|ArrayBuffer|Date): Promise&lt;number&gt;</code></b><br>
750
+ <b><code>indexeddb.getAll(store: IDBObjectStore, range: IDBKeyRange): Promise&lt;Array&lt;any&gt;&gt;</code></b><br>
751
+ <b><code>indexeddb.getAllKeys(store: IDBObjectStore, range: IDBKeyRange): Promise&lt;Array&lt;any&gt;&gt;</code></b><br>
752
+ <b><code>indexeddb.queryFirst(store: IDBObjectStore, query: IDBKeyRange|null, direction: 'next'|'prev'|'nextunique'|'prevunique'): Promise&lt;any&gt;</code></b><br>
753
+ <b><code>indexeddb.getLastKey(store: IDBObjectStore, range: IDBKeyRange?): Promise&lt;any&gt;</code></b><br>
754
+ <b><code>indexeddb.getFirstKey(store: IDBObjectStore, range: IDBKeyRange?): Promise&lt;any&gt;</code></b><br>
755
+ <b><code>indexeddb.getAllKeysValues(store: IDBObjectStore, range: IDBKeyRange): Promise&lt;Array&lt;KeyValuePair&gt;&gt;</code></b><br>
756
+ <b><code>indexeddb.iterate(store: IDBObjectStore, keyrange: IDBKeyRange|null, f: function(any,any):void|boolean, direction: 'next'|'prev'|'nextunique'|'prevunique')</code></b><br>
757
+ <dd><p>Iterate on keys and values</p></dd>
758
+ <b><code>indexeddb.iterateKeys(store: IDBObjectStore, keyrange: IDBKeyRange|null, f: function(any):void|boolean, direction: 'next'|'prev'|'nextunique'|'prevunique')</code></b><br>
759
+ <dd><p>Iterate on the keys (no values)</p></dd>
760
+ <b><code>indexeddb.getStore(t: IDBTransaction, store: String)IDBObjectStore</code></b><br>
761
+ <dd><p>Open store from transaction</p></dd>
762
+ <b><code>indexeddb.createIDBKeyRangeBound(lower: any, upper: any, lowerOpen: boolean, upperOpen: boolean)</code></b><br>
763
+ <b><code>indexeddb.createIDBKeyRangeUpperBound(upper: any, upperOpen: boolean)</code></b><br>
764
+ <b><code>indexeddb.createIDBKeyRangeLowerBound(lower: any, lowerOpen: boolean)</code></b><br>
761
765
  </dl>
762
766
  </details>
763
767
  <details><summary><b>[lib0/isomorphic]</b> Isomorphic library exports from isomorphic.js.</summary>
764
- <pre>import * as isomorphic from 'lib0/isomorphic.js'</pre>
768
+ <pre>import * as isomorphic from 'lib0/isomorphic'</pre>
765
769
  <dl>
766
770
  </dl>
767
771
  </details>
768
772
  <details><summary><b>[lib0/iterator]</b> Utility module to create and manipulate Iterators.</summary>
769
- <pre>import * as iterator from 'lib0/iterator.js'</pre>
773
+ <pre>import * as iterator from 'lib0/iterator'</pre>
770
774
  <dl>
771
775
  <b><code>iterator.mapIterator(iterator: Iterator&lt;T&gt;, f: function(T):R): IterableIterator&lt;R&gt;</code></b><br>
772
776
  <b><code>iterator.createIterator(next: function():IteratorResult&lt;T&gt;): IterableIterator&lt;T&gt;</code></b><br>
@@ -775,7 +779,7 @@ In practice, when decoding several million small strings, the GC will kick in mo
775
779
  </dl>
776
780
  </details>
777
781
  <details><summary><b>[lib0/json]</b> JSON utility functions.</summary>
778
- <pre>import * as json from 'lib0/json.js'</pre>
782
+ <pre>import * as json from 'lib0/json'</pre>
779
783
  <dl>
780
784
  <b><code>json.stringify(object: any): string</code></b><br>
781
785
  <dd><p>Transform JavaScript object to JSON.</p></dd>
@@ -784,7 +788,7 @@ In practice, when decoding several million small strings, the GC will kick in mo
784
788
  </dl>
785
789
  </details>
786
790
  <details><summary><b>[lib0/logging]</b> Isomorphic logging module with support for colors!</summary>
787
- <pre>import * as logging from 'lib0/logging.js'</pre>
791
+ <pre>import * as logging from 'lib0/logging'</pre>
788
792
  <dl>
789
793
  <b><code>logging.BOLD</code></b><br>
790
794
  <b><code>logging.UNBOLD</code></b><br>
@@ -821,7 +825,7 @@ In practice, when decoding several million small strings, the GC will kick in mo
821
825
  </dl>
822
826
  </details>
823
827
  <details><summary><b>[lib0/map]</b> Utility module to work with key-value stores.</summary>
824
- <pre>import * as map from 'lib0/map.js'</pre>
828
+ <pre>import * as map from 'lib0/map'</pre>
825
829
  <dl>
826
830
  <b><code>map.create(): Map&lt;any, any&gt;</code></b><br>
827
831
  <dd><p>Creates a new Map instance.</p></dd>
@@ -841,7 +845,7 @@ listeners.add(listener)
841
845
  </dl>
842
846
  </details>
843
847
  <details><summary><b>[lib0/math]</b> Common Math expressions.</summary>
844
- <pre>import * as math from 'lib0/math.js'</pre>
848
+ <pre>import * as math from 'lib0/math'</pre>
845
849
  <dl>
846
850
  <b><code>math.floor</code></b><br>
847
851
  <b><code>math.ceil</code></b><br>
@@ -864,7 +868,7 @@ listeners.add(listener)
864
868
  </dl>
865
869
  </details>
866
870
  <details><summary><b>[lib0/metric]</b> Utility module to convert metric values.</summary>
867
- <pre>import * as metric from 'lib0/metric.js'</pre>
871
+ <pre>import * as metric from 'lib0/metric'</pre>
868
872
  <dl>
869
873
  <b><code>metric.yotta</code></b><br>
870
874
  <b><code>metric.zetta</code></b><br>
@@ -891,7 +895,7 @@ listeners.add(listener)
891
895
  </dl>
892
896
  </details>
893
897
  <details><summary><b>[lib0/mutex]</b> Mutual exclude for JavaScript.</summary>
894
- <pre>import * as mutex from 'lib0/mutex.js'</pre>
898
+ <pre>import * as mutex from 'lib0/mutex'</pre>
895
899
  <dl>
896
900
  <b><code>mutex.createMutex(): mutex</code></b><br>
897
901
  <dd><p>Creates a mutual exclude function with the following property:</p>
@@ -906,7 +910,7 @@ mutex(() => {
906
910
  </dl>
907
911
  </details>
908
912
  <details><summary><b>[lib0/number]</b> </summary>
909
- <pre>import * as number from 'lib0/number.js'</pre>
913
+ <pre>import * as number from 'lib0/number'</pre>
910
914
  <dl>
911
915
  <b><code>number.MAX_SAFE_INTEGER</code></b><br>
912
916
  <b><code>number.MIN_SAFE_INTEGER</code></b><br>
@@ -914,10 +918,11 @@ mutex(() => {
914
918
  <b><code>number.HIGHEST_INT32: number</code></b><br>
915
919
  <b><code>number.isInteger</code></b><br>
916
920
  <b><code>number.isNaN</code></b><br>
921
+ <b><code>number.parseInt</code></b><br>
917
922
  </dl>
918
923
  </details>
919
924
  <details><summary><b>[lib0/object]</b> Utility functions for working with EcmaScript objects.</summary>
920
- <pre>import * as object from 'lib0/object.js'</pre>
925
+ <pre>import * as object from 'lib0/object'</pre>
921
926
  <dl>
922
927
  <b><code>object.create(): Object&lt;string,any&gt;</code></b><br>
923
928
  <b><code>object.assign</code></b><br>
@@ -934,7 +939,7 @@ mutex(() => {
934
939
  </dl>
935
940
  </details>
936
941
  <details><summary><b>[lib0/observable]</b> Observable class prototype.</summary>
937
- <pre>import * as observable from 'lib0/observable.js'</pre>
942
+ <pre>import * as observable from 'lib0/observable'</pre>
938
943
  <dl>
939
944
  <b><code>new observable.Observable()</code></b><br>
940
945
  <dd><p>Handles named events.</p></dd>
@@ -954,7 +959,7 @@ specified name will receive the event.</p></dd>
954
959
  </dl>
955
960
  </details>
956
961
  <details><summary><b>[lib0/pair]</b> Working with value pairs.</summary>
957
- <pre>import * as pair from 'lib0/pair.js'</pre>
962
+ <pre>import * as pair from 'lib0/pair'</pre>
958
963
  <dl>
959
964
  <b><code>new pair.Pair(left: L, right: R)</code></b><br>
960
965
  <b><code>pair.create(left: L, right: R): module:pair.Pair&lt;L,R&gt;</code></b><br>
@@ -964,7 +969,7 @@ specified name will receive the event.</p></dd>
964
969
  </dl>
965
970
  </details>
966
971
  <details><summary><b>[lib0/prng]</b> Fast Pseudo Random Number Generators.</summary>
967
- <pre>import * as prng from 'lib0/prng.js'</pre>
972
+ <pre>import * as prng from 'lib0/prng'</pre>
968
973
 
969
974
  <p>Given a seed a PRNG generates a sequence of numbers that cannot be reasonably predicted.
970
975
  Two PRNGs must generate the same random sequence of numbers if given the same seed.</p>
@@ -1002,7 +1007,7 @@ But there are more PRNGs available in ./PRNG/.</p></dd>
1002
1007
  </dl>
1003
1008
  </details>
1004
1009
  <details><summary><b>[lib0/promise]</b> Utility helpers to work with promises.</summary>
1005
- <pre>import * as promise from 'lib0/promise.js'</pre>
1010
+ <pre>import * as promise from 'lib0/promise'</pre>
1006
1011
  <dl>
1007
1012
  <b><code>promise.create(f: function(PromiseResolve&lt;T&gt;,function(Error):void):any): Promise&lt;T&gt;</code></b><br>
1008
1013
  <b><code>promise.createEmpty(f: function(function():void,function(Error):void):void): Promise&lt;void&gt;</code></b><br>
@@ -1010,6 +1015,7 @@ But there are more PRNGs available in ./PRNG/.</p></dd>
1010
1015
  <dd><p><code>Promise.all</code> wait for all promises in the array to resolve and return the result</p></dd>
1011
1016
  <b><code>promise.reject(reason: Error): Promise&lt;never&gt;</code></b><br>
1012
1017
  <b><code>promise.resolve(res: T|void): Promise&lt;T|void&gt;</code></b><br>
1018
+ <b><code>promise.resolveWith(res: T): Promise&lt;T&gt;</code></b><br>
1013
1019
  <b><code>promise.until(timeout: number, check: function():boolean, intervalResolution: number): Promise&lt;void&gt;</code></b><br>
1014
1020
  <b><code>promise.wait(timeout: number): Promise&lt;undefined&gt;</code></b><br>
1015
1021
  <b><code>promise.isPromise(p: any): boolean</code></b><br>
@@ -1019,7 +1025,7 @@ library has some insane environment where global Promise objects are overwritten
1019
1025
  </dl>
1020
1026
  </details>
1021
1027
  <details><summary><b>[lib0/queue]</b> </summary>
1022
- <pre>import * as queue from 'lib0/queue.js'</pre>
1028
+ <pre>import * as queue from 'lib0/queue'</pre>
1023
1029
  <dl>
1024
1030
  <b><code>new de#QueueNode()</code></b><br>
1025
1031
  <b><code>de#next: module:queue.QueueNode|null</code></b><br>
@@ -1037,7 +1043,7 @@ library has some insane environment where global Promise objects are overwritten
1037
1043
  </dl>
1038
1044
  </details>
1039
1045
  <details><summary><b>[lib0/random]</b> Isomorphic module for true random numbers / buffers / uuids.</summary>
1040
- <pre>import * as random from 'lib0/random.js'</pre>
1046
+ <pre>import * as random from 'lib0/random'</pre>
1041
1047
 
1042
1048
  <p>Attention: falls back to Math.random if the browser does not support crypto.</p>
1043
1049
  <dl>
@@ -1048,14 +1054,14 @@ library has some insane environment where global Promise objects are overwritten
1048
1054
  </dl>
1049
1055
  </details>
1050
1056
  <details><summary><b>[lib0/set]</b> Utility module to work with sets.</summary>
1051
- <pre>import * as set from 'lib0/set.js'</pre>
1057
+ <pre>import * as set from 'lib0/set'</pre>
1052
1058
  <dl>
1053
1059
  <b><code>set.create</code></b><br>
1054
1060
  <b><code>set.toArray(set: Set&lt;T&gt;): Array&lt;T&gt;</code></b><br>
1055
1061
  </dl>
1056
1062
  </details>
1057
1063
  <details><summary><b>[lib0/sort]</b> Efficient sort implementations.</summary>
1058
- <pre>import * as sort from 'lib0/sort.js'</pre>
1064
+ <pre>import * as sort from 'lib0/sort'</pre>
1059
1065
 
1060
1066
  <p>Note: These sort implementations were created to compare different sorting algorithms in JavaScript.
1061
1067
  Don't use them if you don't know what you are doing. Native Array.sort is almost always a better choice.</p>
@@ -1069,14 +1075,14 @@ integrate this algorithm.</p>
1069
1075
  </dl>
1070
1076
  </details>
1071
1077
  <details><summary><b>[lib0/statistics]</b> Utility helpers for generating statistics.</summary>
1072
- <pre>import * as statistics from 'lib0/statistics.js'</pre>
1078
+ <pre>import * as statistics from 'lib0/statistics'</pre>
1073
1079
  <dl>
1074
1080
  <b><code>statistics.median(arr: Array&lt;number&gt;): number</code></b><br>
1075
1081
  <b><code>statistics.average(arr: Array&lt;number&gt;): number</code></b><br>
1076
1082
  </dl>
1077
1083
  </details>
1078
1084
  <details><summary><b>[lib0/storage]</b> Isomorphic variable storage.</summary>
1079
- <pre>import * as storage from 'lib0/storage.js'</pre>
1085
+ <pre>import * as storage from 'lib0/storage'</pre>
1080
1086
 
1081
1087
  <p>Uses LocalStorage in the browser and falls back to in-memory storage.</p>
1082
1088
  <dl>
@@ -1087,7 +1093,7 @@ integrate this algorithm.</p>
1087
1093
  </dl>
1088
1094
  </details>
1089
1095
  <details><summary><b>[lib0/string]</b> Utility module to work with strings.</summary>
1090
- <pre>import * as string from 'lib0/string.js'</pre>
1096
+ <pre>import * as string from 'lib0/string'</pre>
1091
1097
  <dl>
1092
1098
  <b><code>string.fromCharCode</code></b><br>
1093
1099
  <b><code>string.fromCodePoint</code></b><br>
@@ -1101,7 +1107,7 @@ integrate this algorithm.</p>
1101
1107
  </dl>
1102
1108
  </details>
1103
1109
  <details><summary><b>[lib0/symbol]</b> Utility module to work with EcmaScript Symbols.</summary>
1104
- <pre>import * as symbol from 'lib0/symbol.js'</pre>
1110
+ <pre>import * as symbol from 'lib0/symbol'</pre>
1105
1111
  <dl>
1106
1112
  <b><code>symbol.create(): Symbol</code></b><br>
1107
1113
  <dd><p>Return fresh symbol.</p></dd>
@@ -1109,7 +1115,7 @@ integrate this algorithm.</p>
1109
1115
  </dl>
1110
1116
  </details>
1111
1117
  <details><summary><b>[lib0/testing]</b> Testing framework with support for generating tests.</summary>
1112
- <pre>import * as testing from 'lib0/testing.js'</pre>
1118
+ <pre>import * as testing from 'lib0/testing'</pre>
1113
1119
 
1114
1120
  <pre class="prettyprint source lang-js"><code>// test.js template for creating a test executable
1115
1121
  import { runTests } from 'lib0/testing.js'
@@ -1227,7 +1233,7 @@ export const testMyFirstTest = tc => {
1227
1233
  </dl>
1228
1234
  </details>
1229
1235
  <details><summary><b>[lib0/time]</b> Utility module to work with time.</summary>
1230
- <pre>import * as time from 'lib0/time.js'</pre>
1236
+ <pre>import * as time from 'lib0/time'</pre>
1231
1237
  <dl>
1232
1238
  <b><code>time.getDate(): Date</code></b><br>
1233
1239
  <dd><p>Return current time.</p></dd>
@@ -1238,7 +1244,7 @@ export const testMyFirstTest = tc => {
1238
1244
  </dl>
1239
1245
  </details>
1240
1246
  <details><summary><b>[lib0/tree]</b> Red-black-tree implementation.</summary>
1241
- <pre>import * as tree from 'lib0/tree.js'</pre>
1247
+ <pre>import * as tree from 'lib0/tree'</pre>
1242
1248
  <dl>
1243
1249
  <b><code>new tree.Tree()</code></b><br>
1244
1250
  <dd><p>This is a Red Black Tree implementation</p></dd>
@@ -1257,7 +1263,7 @@ export const testMyFirstTest = tc => {
1257
1263
  </dl>
1258
1264
  </details>
1259
1265
  <details><summary><b>[lib0/url]</b> Utility module to work with urls.</summary>
1260
- <pre>import * as url from 'lib0/url.js'</pre>
1266
+ <pre>import * as url from 'lib0/url'</pre>
1261
1267
  <dl>
1262
1268
  <b><code>url.decodeQueryParams(url: string): Object&lt;string,string&gt;</code></b><br>
1263
1269
  <dd><p>Parse query parameters from an url.</p></dd>
@@ -1265,7 +1271,7 @@ export const testMyFirstTest = tc => {
1265
1271
  </dl>
1266
1272
  </details>
1267
1273
  <details><summary><b>[lib0/websocket]</b> Tiny websocket connection handler.</summary>
1268
- <pre>import * as websocket from 'lib0/websocket.js'</pre>
1274
+ <pre>import * as websocket from 'lib0/websocket'</pre>
1269
1275
 
1270
1276
  <p>Implements exponential backoff reconnects, ping/pong, and a nice event system using [lib0/observable].</p>
1271
1277
  <dl>
package/bin/gendocs.js CHANGED
@@ -39,7 +39,7 @@ jsdoc.explain({
39
39
  const descHead = desc ? desc[1] : ''
40
40
  const descRest = desc ? desc[2] : ''
41
41
  strBuilder.push(`<details><summary><b>[lib0/${mod.name}]</b> ${descHead}</summary>`)
42
- strBuilder.push(`<pre>import * as ${mod.name} from 'lib0/${fileName}'</pre>`)
42
+ strBuilder.push(`<pre>import * as ${mod.name} from 'lib0/${fileName.slice(0, -3)}'</pre>`)
43
43
  if (descRest.length > 0) {
44
44
  strBuilder.push(descRest)
45
45
  }
package/component.d.ts CHANGED
@@ -1,6 +1,9 @@
1
+ /**
2
+ * @type {CustomElementRegistry}
3
+ */
1
4
  export const registry: CustomElementRegistry;
2
5
  export function define(name: string, constr: any, opts?: ElementDefinitionOptions | undefined): void;
3
- export function whenDefined(name: string): Promise<void>;
6
+ export function whenDefined(name: string): Promise<CustomElementConstructor>;
4
7
  /**
5
8
  * @template S
6
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["component.js"],"names":[],"mappings":"AAiBA,6CAAsC;AAO/B,6BAJI,MAAM,UACN,GAAG,qDAGmE;AAM1E,kCAHI,MAAM,GACL,QAAQ,IAAI,CAAC,CAEoC;AAM7D;;GAEG;AACH;IACE;;OAEG;IACH,mCAUC;IARC;;OAEG;IACH,OAFU,CAAC,GAAC,IAAI,CAEuB;IACvC;;OAEG;IACH,WAFU,GAAG,CAEM;IAGrB;;;OAGG;IACH,gBAHW,CAAC,gDAGgC;IAC5C;;QAEI;IACJ,yBAFY,GAAG,QAEc;CAC9B;AA6DM,yCAJI,MAAM,2GAEL,oBAAoB,CAqM/B;AAKM,qEAWN;AANQ,2CAKN;AALM,kDAKN;;;;;;;;;;;;;;;;;;;4BAvOoB,CAAC,QAAC,CAAC,GAAC,IAAI,QAAC,cAAc,CAAC,CAAC,KAAE,IAAI;;;;;;;4BAEjB,GAAG,QAAE,GAAG,KAAE,MAAM;;;;;;;;;;;;;;4BAMf,WAAW,QAAE,cAAc,GAAG,CAAC,KAAE,OAAO,GAAC,IAAI;;;;;;oBAE5D,CAAC,QAAE,CAAC,QAAE,cAAc,CAAC,CAAC;YAAS,MAAM,GAAC,MAAM"}
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["component.js"],"names":[],"mappings":"AAiBA;;GAEG;AACH,uBAFU,qBAAqB,CAEO;AAO/B,6BAJI,MAAM,UACN,GAAG,qDAGmE;AAM1E,kCAHI,MAAM,GACL,QAAQ,wBAAwB,CAAC,CAEgB;AAM7D;;GAEG;AACH;IACE;;OAEG;IACH,mCAUC;IARC;;OAEG;IACH,OAFU,CAAC,GAAC,IAAI,CAEuB;IACvC;;OAEG;IACH,WAFU,GAAG,CAEM;IAGrB;;;OAGG;IACH,gBAHW,CAAC,gDAGgC;IAC5C;;QAEI;IACJ,yBAFY,GAAG,QAEc;CAC9B;AA6DM,yCAJI,MAAM,2GAEL,oBAAoB,CAqM/B;AAKM,qEAWN;AANQ,2CAKN;AALM,kDAKN;;;;;;;;;;;;;;;;;;;4BAvOoB,CAAC,QAAC,CAAC,GAAC,IAAI,QAAC,cAAc,CAAC,CAAC,KAAE,IAAI;;;;;;;4BAEjB,GAAG,QAAE,GAAG,KAAE,MAAM;;;;;;;;;;;;;;4BAMf,WAAW,QAAE,cAAc,GAAG,CAAC,KAAE,OAAO,GAAC,IAAI;;;;;;oBAE5D,CAAC,QAAE,CAAC,QAAE,cAAc,CAAC,CAAC;YAAS,MAAM,GAAC,MAAM"}
package/component.js CHANGED
@@ -15,6 +15,9 @@ import * as array from './array.js'
15
15
  import * as number from './number.js'
16
16
  import * as func from './function.js'
17
17
 
18
+ /**
19
+ * @type {CustomElementRegistry}
20
+ */
18
21
  export const registry = customElements
19
22
 
20
23
  /**
@@ -26,7 +29,7 @@ export const define = (name, constr, opts) => registry.define(name, constr, opts
26
29
 
27
30
  /**
28
31
  * @param {string} name
29
- * @return {Promise<void>}
32
+ * @return {Promise<CustomElementConstructor>}
30
33
  */
31
34
  export const whenDefined = name => registry.whenDefined(name)
32
35
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var map = require('./map-28a001c9.cjs');
4
- var encoding = require('./buffer-ac2cdedf.cjs');
4
+ var encoding = require('./buffer-49880125.cjs');
5
5
  var storage = require('./storage.cjs');
6
6
 
7
7
  /* eslint-env browser */
@@ -100,4 +100,4 @@ exports.broadcastchannel = broadcastchannel;
100
100
  exports.publish = publish;
101
101
  exports.subscribe = subscribe;
102
102
  exports.unsubscribe = unsubscribe;
103
- //# sourceMappingURL=broadcastchannel-8a61b21a.cjs.map
103
+ //# sourceMappingURL=broadcastchannel-044f32d2.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"broadcastchannel-8a61b21a.cjs","sources":["../broadcastchannel.js"],"sourcesContent":["/* eslint-env browser */\n\n/**\n * Helpers for cross-tab communication using broadcastchannel with LocalStorage fallback.\n *\n * ```js\n * // In browser window A:\n * broadcastchannel.subscribe('my events', data => console.log(data))\n * broadcastchannel.publish('my events', 'Hello world!') // => A: 'Hello world!' fires synchronously in same tab\n *\n * // In browser window B:\n * broadcastchannel.publish('my events', 'hello from tab B') // => A: 'hello from tab B'\n * ```\n *\n * @module broadcastchannel\n */\n\n// @todo before next major: use Uint8Array instead as buffer object\n\nimport * as map from './map.js'\nimport * as buffer from './buffer.js'\nimport * as storage from './storage.js'\n\n/**\n * @typedef {Object} Channel\n * @property {Set<Function>} Channel.subs\n * @property {any} Channel.bc\n */\n\n/**\n * @type {Map<string, Channel>}\n */\nconst channels = new Map()\n\nclass LocalStoragePolyfill {\n /**\n * @param {string} room\n */\n constructor (room) {\n this.room = room\n /**\n * @type {null|function({data:ArrayBuffer}):void}\n */\n this.onmessage = null\n storage.onChange(e => e.key === room && this.onmessage !== null && this.onmessage({ data: buffer.fromBase64(e.newValue || '') }))\n }\n\n /**\n * @param {ArrayBuffer} buf\n */\n postMessage (buf) {\n storage.varStorage.setItem(this.room, buffer.toBase64(buffer.createUint8ArrayFromArrayBuffer(buf)))\n }\n}\n\n// Use BroadcastChannel or Polyfill\nconst BC = typeof BroadcastChannel === 'undefined' ? LocalStoragePolyfill : BroadcastChannel\n\n/**\n * @param {string} room\n * @return {Channel}\n */\nconst getChannel = room =>\n map.setIfUndefined(channels, room, () => {\n const subs = new Set()\n const bc = new BC(room)\n /**\n * @param {{data:ArrayBuffer}} e\n */\n bc.onmessage = e => subs.forEach(sub => sub(e.data))\n return {\n bc, subs\n }\n })\n\n/**\n * Subscribe to global `publish` events.\n *\n * @function\n * @param {string} room\n * @param {function(any):any} f\n */\nexport const subscribe = (room, f) => getChannel(room).subs.add(f)\n\n/**\n * Unsubscribe from `publish` global events.\n *\n * @function\n * @param {string} room\n * @param {function(any):any} f\n */\nexport const unsubscribe = (room, f) => getChannel(room).subs.delete(f)\n\n/**\n * Publish data to all subscribers (including subscribers on this tab)\n *\n * @function\n * @param {string} room\n * @param {any} data\n */\nexport const publish = (room, data) => {\n const c = getChannel(room)\n c.bc.postMessage(data)\n c.subs.forEach(sub => sub(data))\n}\n"],"names":["storage.onChange","buffer.fromBase64","storage.varStorage","buffer.toBase64","buffer.createUint8ArrayFromArrayBuffer","map.setIfUndefined"],"mappings":";;;;;;AAAA;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,QAAQ,GAAG,IAAI,GAAG,GAAE;AAC1B;AACA,MAAM,oBAAoB,CAAC;AAC3B;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA;AACA;AACA,IAAI,IAAI,CAAC,SAAS,GAAG,KAAI;AACzB,IAAIA,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAEC,mBAAiB,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,CAAC,EAAC;AACrI,GAAG;AACH;AACA;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,GAAG,EAAE;AACpB,IAAIC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAEC,iBAAe,CAACC,wCAAsC,CAAC,GAAG,CAAC,CAAC,EAAC;AACvG,GAAG;AACH,CAAC;AACD;AACA;AACA,MAAM,EAAE,GAAG,OAAO,gBAAgB,KAAK,WAAW,GAAG,oBAAoB,GAAG,iBAAgB;AAC5F;AACA;AACA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI;AACvB,EAAEC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM;AAC3C,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,GAAE;AAC1B,IAAI,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,IAAI,EAAC;AAC3B;AACA;AACA;AACA,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAC;AACxD,IAAI,OAAO;AACX,MAAM,EAAE,EAAE,IAAI;AACd,KAAK;AACL,GAAG,EAAC;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAC;AAClE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAC;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK;AACvC,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,EAAC;AAC5B,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,EAAC;AACxB,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,EAAC;AAClC;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"broadcastchannel-044f32d2.cjs","sources":["../broadcastchannel.js"],"sourcesContent":["/* eslint-env browser */\n\n/**\n * Helpers for cross-tab communication using broadcastchannel with LocalStorage fallback.\n *\n * ```js\n * // In browser window A:\n * broadcastchannel.subscribe('my events', data => console.log(data))\n * broadcastchannel.publish('my events', 'Hello world!') // => A: 'Hello world!' fires synchronously in same tab\n *\n * // In browser window B:\n * broadcastchannel.publish('my events', 'hello from tab B') // => A: 'hello from tab B'\n * ```\n *\n * @module broadcastchannel\n */\n\n// @todo before next major: use Uint8Array instead as buffer object\n\nimport * as map from './map.js'\nimport * as buffer from './buffer.js'\nimport * as storage from './storage.js'\n\n/**\n * @typedef {Object} Channel\n * @property {Set<Function>} Channel.subs\n * @property {any} Channel.bc\n */\n\n/**\n * @type {Map<string, Channel>}\n */\nconst channels = new Map()\n\nclass LocalStoragePolyfill {\n /**\n * @param {string} room\n */\n constructor (room) {\n this.room = room\n /**\n * @type {null|function({data:ArrayBuffer}):void}\n */\n this.onmessage = null\n storage.onChange(e => e.key === room && this.onmessage !== null && this.onmessage({ data: buffer.fromBase64(e.newValue || '') }))\n }\n\n /**\n * @param {ArrayBuffer} buf\n */\n postMessage (buf) {\n storage.varStorage.setItem(this.room, buffer.toBase64(buffer.createUint8ArrayFromArrayBuffer(buf)))\n }\n}\n\n// Use BroadcastChannel or Polyfill\nconst BC = typeof BroadcastChannel === 'undefined' ? LocalStoragePolyfill : BroadcastChannel\n\n/**\n * @param {string} room\n * @return {Channel}\n */\nconst getChannel = room =>\n map.setIfUndefined(channels, room, () => {\n const subs = new Set()\n const bc = new BC(room)\n /**\n * @param {{data:ArrayBuffer}} e\n */\n bc.onmessage = e => subs.forEach(sub => sub(e.data))\n return {\n bc, subs\n }\n })\n\n/**\n * Subscribe to global `publish` events.\n *\n * @function\n * @param {string} room\n * @param {function(any):any} f\n */\nexport const subscribe = (room, f) => getChannel(room).subs.add(f)\n\n/**\n * Unsubscribe from `publish` global events.\n *\n * @function\n * @param {string} room\n * @param {function(any):any} f\n */\nexport const unsubscribe = (room, f) => getChannel(room).subs.delete(f)\n\n/**\n * Publish data to all subscribers (including subscribers on this tab)\n *\n * @function\n * @param {string} room\n * @param {any} data\n */\nexport const publish = (room, data) => {\n const c = getChannel(room)\n c.bc.postMessage(data)\n c.subs.forEach(sub => sub(data))\n}\n"],"names":["storage.onChange","buffer.fromBase64","storage.varStorage","buffer.toBase64","buffer.createUint8ArrayFromArrayBuffer","map.setIfUndefined"],"mappings":";;;;;;AAAA;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,QAAQ,GAAG,IAAI,GAAG,GAAE;AAC1B;AACA,MAAM,oBAAoB,CAAC;AAC3B;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA;AACA;AACA,IAAI,IAAI,CAAC,SAAS,GAAG,KAAI;AACzB,IAAIA,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAEC,mBAAiB,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,CAAC,EAAC;AACrI,GAAG;AACH;AACA;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,GAAG,EAAE;AACpB,IAAIC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAEC,iBAAe,CAACC,wCAAsC,CAAC,GAAG,CAAC,CAAC,EAAC;AACvG,GAAG;AACH,CAAC;AACD;AACA;AACA,MAAM,EAAE,GAAG,OAAO,gBAAgB,KAAK,WAAW,GAAG,oBAAoB,GAAG,iBAAgB;AAC5F;AACA;AACA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI;AACvB,EAAEC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM;AAC3C,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,GAAE;AAC1B,IAAI,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,IAAI,EAAC;AAC3B;AACA;AACA;AACA,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAC;AACxD,IAAI,OAAO;AACX,MAAM,EAAE,EAAE,IAAI;AACd,KAAK;AACL,GAAG,EAAC;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAC;AAClE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAC;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK;AACvC,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,EAAC;AAC5B,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,EAAC;AACxB,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,EAAC;AAClC;;;;;;;;;;;;;;"}
@@ -3,15 +3,15 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('./map-28a001c9.cjs');
6
- require('./buffer-ac2cdedf.cjs');
6
+ require('./buffer-49880125.cjs');
7
7
  require('./storage.cjs');
8
- var broadcastchannel = require('./broadcastchannel-8a61b21a.cjs');
8
+ var broadcastchannel = require('./broadcastchannel-044f32d2.cjs');
9
9
  require('./string-f3c3d805.cjs');
10
10
  require('./environment-7e2ffaea.cjs');
11
11
  require('./conditions-fb475c70.cjs');
12
12
  require('./binary-ac8e39e2.cjs');
13
13
  require('./math-08e068f9.cjs');
14
- require('./number-24f1eabe.cjs');
14
+ require('./number-e62129bc.cjs');
15
15
 
16
16
 
17
17
 
@@ -4,7 +4,7 @@ var string = require('./string-f3c3d805.cjs');
4
4
  var environment = require('./environment-7e2ffaea.cjs');
5
5
  var binary = require('./binary-ac8e39e2.cjs');
6
6
  var math = require('./math-08e068f9.cjs');
7
- var number = require('./number-24f1eabe.cjs');
7
+ var number = require('./number-e62129bc.cjs');
8
8
 
9
9
  /**
10
10
  * Efficient schema-less binary encoding with support for variable length encoding.
@@ -1740,4 +1740,4 @@ exports.writeVarInt = writeVarInt;
1740
1740
  exports.writeVarString = writeVarString;
1741
1741
  exports.writeVarUint = writeVarUint;
1742
1742
  exports.writeVarUint8Array = writeVarUint8Array;
1743
- //# sourceMappingURL=buffer-ac2cdedf.cjs.map
1743
+ //# sourceMappingURL=buffer-49880125.cjs.map