lib0 0.2.50 → 0.2.51

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/README.md CHANGED
@@ -177,9 +177,9 @@ broadcastchannel.publish('my events', 'Hello world!') // => A: 'Hello world!' fi
177
177
  broadcastchannel.publish('my events', 'hello from tab B') // => A: 'hello from tab B'
178
178
  </code></pre>
179
179
  <dl>
180
- <b><code>broadcastchannel.subscribe(room: string, f: function(any):any)</code></b><br>
180
+ <b><code>broadcastchannel.subscribe(room: string, f: function(any, any):any)</code></b><br>
181
181
  <dd><p>Subscribe to global <code>publish</code> events.</p></dd>
182
- <b><code>broadcastchannel.unsubscribe(room: string, f: function(any):any)</code></b><br>
182
+ <b><code>broadcastchannel.unsubscribe(room: string, f: function(any, any):any)</code></b><br>
183
183
  <dd><p>Unsubscribe from <code>publish</code> global events.</p></dd>
184
184
  <b><code>broadcastchannel.publish(room: string, data: any, origin: any)</code></b><br>
185
185
  <dd><p>Publish data to all subscribers (including subscribers on this tab)</p></dd>
@@ -1,5 +1,5 @@
1
- export function subscribe(room: string, f: (arg0: any) => any): Set<(arg0: any, arg1: any) => any>;
2
- export function unsubscribe(room: string, f: (arg0: any) => any): boolean;
1
+ export function subscribe(room: string, f: (arg0: any, arg1: any) => any): Set<(arg0: any, arg1: any) => any>;
2
+ export function unsubscribe(room: string, f: (arg0: any, arg1: any) => any): boolean;
3
3
  export function publish(room: string, data: any, origin?: any): void;
4
4
  export type Channel = {
5
5
  subs: Set<(arg0: any, arg1: any) => any>;
@@ -1 +1 @@
1
- {"version":3,"file":"broadcastchannel.d.ts","sourceRoot":"","sources":["broadcastchannel.js"],"names":[],"mappings":"AAkFO,gCAHI,MAAM,YACG,GAAG,KAAE,GAAG,cAvDD,GAAG,QAAE,GAAG,KAAE,GAAG,EAyD0B;AAS3D,kCAHI,MAAM,YACG,GAAG,KAAE,GAAG,WAE2C;AAUhE,8BAJI,MAAM,QACN,GAAG,WACH,GAAG,QAMb;;UAhFa,WAAa,GAAG,QAAE,GAAG,KAAE,GAAG,CAAC;QAC3B,GAAG"}
1
+ {"version":3,"file":"broadcastchannel.d.ts","sourceRoot":"","sources":["broadcastchannel.js"],"names":[],"mappings":"AAkFO,gCAHI,MAAM,YACG,GAAG,QAAE,GAAG,KAAE,GAAG,cAvDN,GAAG,QAAE,GAAG,KAAE,GAAG,EAyD0B;AAS3D,kCAHI,MAAM,YACG,GAAG,QAAE,GAAG,KAAE,GAAG,WAEsC;AAUhE,8BAJI,MAAM,QACN,GAAG,WACH,GAAG,QAMb;;UAhFa,WAAa,GAAG,QAAE,GAAG,KAAE,GAAG,CAAC;QAC3B,GAAG"}
@@ -78,7 +78,7 @@ const getChannel = room =>
78
78
  *
79
79
  * @function
80
80
  * @param {string} room
81
- * @param {function(any):any} f
81
+ * @param {function(any, any):any} f
82
82
  */
83
83
  export const subscribe = (room, f) => getChannel(room).subs.add(f)
84
84
 
@@ -87,7 +87,7 @@ export const subscribe = (room, f) => getChannel(room).subs.add(f)
87
87
  *
88
88
  * @function
89
89
  * @param {string} room
90
- * @param {function(any):any} f
90
+ * @param {function(any, any):any} f
91
91
  */
92
92
  export const unsubscribe = (room, f) => getChannel(room).subs.delete(f)
93
93
 
@@ -63,7 +63,7 @@ const getChannel = room =>
63
63
  *
64
64
  * @function
65
65
  * @param {string} room
66
- * @param {function(any):any} f
66
+ * @param {function(any, any):any} f
67
67
  */
68
68
  const subscribe = (room, f) => getChannel(room).subs.add(f);
69
69
 
@@ -72,7 +72,7 @@ const subscribe = (room, f) => getChannel(room).subs.add(f);
72
72
  *
73
73
  * @function
74
74
  * @param {string} room
75
- * @param {function(any):any} f
75
+ * @param {function(any, any):any} f
76
76
  */
77
77
  const unsubscribe = (room, f) => getChannel(room).subs.delete(f);
78
78
 
@@ -101,4 +101,4 @@ exports.broadcastchannel = broadcastchannel;
101
101
  exports.publish = publish;
102
102
  exports.subscribe = subscribe;
103
103
  exports.unsubscribe = unsubscribe;
104
- //# sourceMappingURL=broadcastchannel-6da71c2f.cjs.map
104
+ //# sourceMappingURL=broadcastchannel-1e999014.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcastchannel-1e999014.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(any, any):any>} 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, 'broadcastchannel'))\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):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):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 * @param {any} [origin]\n */\nexport const publish = (room, data, origin = null) => {\n const c = getChannel(room)\n c.bc.postMessage(data)\n c.subs.forEach(sub => sub(data, origin))\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,g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: true });
5
5
  require('./map-28a001c9.cjs');
6
6
  require('./buffer-c98f67d5.cjs');
7
7
  require('./storage.cjs');
8
- var broadcastchannel = require('./broadcastchannel-6da71c2f.cjs');
8
+ var broadcastchannel = require('./broadcastchannel-1e999014.cjs');
9
9
  require('./string-ad04f734.cjs');
10
10
  require('./environment-60b83194.cjs');
11
11
  require('./conditions-fb475c70.cjs');
@@ -1,5 +1,5 @@
1
- export function subscribe(room: string, f: (arg0: any) => any): Set<(arg0: any, arg1: any) => any>;
2
- export function unsubscribe(room: string, f: (arg0: any) => any): boolean;
1
+ export function subscribe(room: string, f: (arg0: any, arg1: any) => any): Set<(arg0: any, arg1: any) => any>;
2
+ export function unsubscribe(room: string, f: (arg0: any, arg1: any) => any): boolean;
3
3
  export function publish(room: string, data: any, origin?: any): void;
4
4
  export type Channel = {
5
5
  subs: Set<(arg0: any, arg1: any) => any>;
@@ -1 +1 @@
1
- {"version":3,"file":"broadcastchannel.d.ts","sourceRoot":"","sources":["../broadcastchannel.js"],"names":[],"mappings":"AAkFO,gCAHI,MAAM,YACG,GAAG,KAAE,GAAG,cAvDD,GAAG,QAAE,GAAG,KAAE,GAAG,EAyD0B;AAS3D,kCAHI,MAAM,YACG,GAAG,KAAE,GAAG,WAE2C;AAUhE,8BAJI,MAAM,QACN,GAAG,WACH,GAAG,QAMb;;UAhFa,WAAa,GAAG,QAAE,GAAG,KAAE,GAAG,CAAC;QAC3B,GAAG"}
1
+ {"version":3,"file":"broadcastchannel.d.ts","sourceRoot":"","sources":["../broadcastchannel.js"],"names":[],"mappings":"AAkFO,gCAHI,MAAM,YACG,GAAG,QAAE,GAAG,KAAE,GAAG,cAvDN,GAAG,QAAE,GAAG,KAAE,GAAG,EAyD0B;AAS3D,kCAHI,MAAM,YACG,GAAG,QAAE,GAAG,KAAE,GAAG,WAEsC;AAUhE,8BAJI,MAAM,QACN,GAAG,WACH,GAAG,QAMb;;UAhFa,WAAa,GAAG,QAAE,GAAG,KAAE,GAAG,CAAC;QAC3B,GAAG"}
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var array = require('./array-acefe0f2.cjs');
6
6
  var binary = require('./binary-ac8e39e2.cjs');
7
- var broadcastchannel = require('./broadcastchannel-6da71c2f.cjs');
7
+ var broadcastchannel = require('./broadcastchannel-1e999014.cjs');
8
8
  var encoding = require('./buffer-c98f67d5.cjs');
9
9
  var conditions = require('./conditions-fb475c70.cjs');
10
10
  var diff = require('./diff-2593547b.cjs');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib0",
3
- "version": "0.2.50",
3
+ "version": "0.2.51",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- {"version":3,"file":"broadcastchannel-6da71c2f.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(any, any):any>} 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, 'broadcastchannel'))\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 * @param {any} [origin]\n */\nexport const publish = (room, data, origin = null) => {\n const c = getChannel(room)\n c.bc.postMessage(data)\n c.subs.forEach(sub => sub(data, origin))\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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