lib0 0.2.51 → 0.2.52
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/.github/workflows/node.js.yml +1 -1
- package/README.md +19 -20
- package/decoding.d.ts +2 -0
- package/decoding.d.ts.map +1 -1
- package/decoding.js +39 -14
- package/dist/{broadcastchannel-1e999014.cjs → broadcastchannel-7655b66f.cjs} +2 -2
- package/dist/{broadcastchannel-1e999014.cjs.map → broadcastchannel-7655b66f.cjs.map} +1 -1
- package/dist/broadcastchannel.cjs +2 -2
- package/dist/{buffer-c98f67d5.cjs → buffer-d3ba308b.cjs} +92 -28
- package/dist/buffer-d3ba308b.cjs.map +1 -0
- package/dist/buffer.cjs +1 -1
- package/dist/cache.cjs +3 -0
- package/dist/cache.cjs.map +1 -1
- package/dist/decoding.cjs +4 -2
- package/dist/decoding.cjs.map +1 -1
- package/dist/decoding.d.ts +2 -0
- package/dist/decoding.d.ts.map +1 -1
- package/dist/encoding.cjs +4 -1
- package/dist/encoding.cjs.map +1 -1
- package/dist/encoding.d.ts +3 -0
- package/dist/encoding.d.ts.map +1 -1
- package/dist/encoding.test.d.ts +6 -1
- package/dist/encoding.test.d.ts.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/list.cjs +52 -1
- package/dist/list.cjs.map +1 -1
- package/dist/list.d.ts +5 -0
- package/dist/list.d.ts.map +1 -1
- package/dist/list.test.d.ts.map +1 -1
- package/dist/number.test.d.ts +1 -0
- package/dist/number.test.d.ts.map +1 -1
- package/dist/{prng-bbec83e2.cjs → prng-76a2f4be.cjs} +2 -2
- package/dist/{prng-bbec83e2.cjs.map → prng-76a2f4be.cjs.map} +1 -1
- package/dist/prng.cjs +2 -2
- package/dist/testing.cjs +5 -5
- package/dist/testing.cjs.map +1 -1
- package/encoding.d.ts +3 -0
- package/encoding.d.ts.map +1 -1
- package/encoding.js +46 -14
- package/encoding.test.d.ts +6 -1
- package/encoding.test.d.ts.map +1 -1
- package/list.d.ts +5 -0
- package/list.d.ts.map +1 -1
- package/list.js +46 -1
- package/list.test.d.ts.map +1 -1
- package/number.test.d.ts +1 -0
- package/number.test.d.ts.map +1 -1
- package/package.json +2 -2
- package/testing.js +3 -3
- package/.circleci/config.yml +0 -7
- package/dist/buffer-c98f67d5.cjs.map +0 -1
- package/dist/test.cjs +0 -7637
- package/dist/test.cjs.map +0 -1
- package/dist/test.d.ts +0 -2
- package/dist/test.d.ts.map +0 -1
- package/dist/test.js +0 -7664
- package/dist/test.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ export const stringify = JSON.stringify
|
|
|
12
12
|
export const parse = JSON.parse
|
|
13
13
|
|
|
14
14
|
// index.js
|
|
15
|
-
import * as json from 'lib0/json
|
|
15
|
+
import * as json from 'lib0/json'
|
|
16
16
|
export const f = (arg1, arg2) => json.stringify(arg1) + json.stringify(arg2)
|
|
17
17
|
|
|
18
18
|
// compiled with rollup and uglifyjs:
|
|
@@ -321,15 +321,7 @@ to the next byte and read it as unsigned integer.</p></dd>
|
|
|
321
321
|
<dd><p>Look ahead and read varUint without incrementing position</p></dd>
|
|
322
322
|
<b><code>decoding.peekVarInt(decoder: module:decoding.Decoder): number</code></b><br>
|
|
323
323
|
<dd><p>Look ahead and read varUint without incrementing position</p></dd>
|
|
324
|
-
<b><code>decoding.readVarString
|
|
325
|
-
<dd><p>Read string of variable length</p>
|
|
326
|
-
<ul>
|
|
327
|
-
<li>varUint is used to store the length of the string</li>
|
|
328
|
-
</ul>
|
|
329
|
-
<p>Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
330
|
-
when String.fromCodePoint is fed with all characters as arguments.
|
|
331
|
-
But most environments have a maximum number of arguments per functions.
|
|
332
|
-
For effiency reasons we apply a maximum of 10000 characters at once.</p></dd>
|
|
324
|
+
<b><code>decoding.readVarString</code></b><br>
|
|
333
325
|
<b><code>decoding.peekVarString(decoder: module:decoding.Decoder): string</code></b><br>
|
|
334
326
|
<dd><p>Look ahead and read varString without incrementing position</p></dd>
|
|
335
327
|
<b><code>decoding.readFromDataView(decoder: module:decoding.Decoder, len: number): DataView</code></b><br>
|
|
@@ -480,6 +472,9 @@ decoding.hasContent(decoder) // => false - all data is read
|
|
|
480
472
|
<dd><p>The current length of the encoded data.</p></dd>
|
|
481
473
|
<b><code>encoding.toUint8Array(encoder: module:encoding.Encoder): Uint8Array</code></b><br>
|
|
482
474
|
<dd><p>Transform to Uint8Array.</p></dd>
|
|
475
|
+
<b><code>encoding.verifyLen(encoder: module:encoding.Encoder, len: number)</code></b><br>
|
|
476
|
+
<dd><p>Verify that it is possible to write <code>len</code> bytes wtihout checking. If
|
|
477
|
+
necessary, a new Buffer with the required length is attached.</p></dd>
|
|
483
478
|
<b><code>encoding.write(encoder: module:encoding.Encoder, num: number)</code></b><br>
|
|
484
479
|
<dd><p>Write one byte to the encoder.</p></dd>
|
|
485
480
|
<b><code>encoding.set(encoder: module:encoding.Encoder, pos: number, num: number)</code></b><br>
|
|
@@ -501,16 +496,11 @@ Position must already be written (i.e. encoder.length > pos)</p></dd>
|
|
|
501
496
|
<b><code>encoding.setUint32(encoder: module:encoding.Encoder, pos: number, num: number)</code></b><br>
|
|
502
497
|
<dd><p>Write two bytes as an unsigned integer at a specific location.</p></dd>
|
|
503
498
|
<b><code>encoding.writeVarUint(encoder: module:encoding.Encoder, num: number)</code></b><br>
|
|
504
|
-
<dd><p>Write a variable length unsigned integer.</p>
|
|
505
|
-
<p>Encodes integers in the range from [0, 4294967295] / [0, 0xffffffff]. (max 32 bit unsigned integer)</p></dd>
|
|
499
|
+
<dd><p>Write a variable length unsigned integer. Max encodable integer is 2^53.</p></dd>
|
|
506
500
|
<b><code>encoding.writeVarInt(encoder: module:encoding.Encoder, num: number)</code></b><br>
|
|
507
501
|
<dd><p>Write a variable length integer.</p>
|
|
508
|
-
<p>Encodes integers in the range from [-2147483648, -2147483647].</p>
|
|
509
|
-
<p>We don't use zig-zag encoding because we want to keep the option open
|
|
510
|
-
to use the same function for BigInt and 53bit integers (doubles).</p>
|
|
511
502
|
<p>We use the 7th bit instead for signaling that this is a negative number.</p></dd>
|
|
512
|
-
<b><code>encoding.writeVarString
|
|
513
|
-
<dd><p>Write a variable length string.</p></dd>
|
|
503
|
+
<b><code>encoding.writeVarString</code></b><br>
|
|
514
504
|
<b><code>encoding.writeBinaryEncoder(encoder: module:encoding.Encoder, append: module:encoding.Encoder)</code></b><br>
|
|
515
505
|
<dd><p>Write the content of another Encoder.</p></dd>
|
|
516
506
|
<b><code>encoding.writeUint8Array(encoder: module:encoding.Encoder, uint8Array: Uint8Array)</code></b><br>
|
|
@@ -819,11 +809,16 @@ In practice, when decoding several million small strings, the GC will kick in mo
|
|
|
819
809
|
<b><code>()</code></b><br>
|
|
820
810
|
<b><code>(queue: module:list.List<N>)</code></b><br>
|
|
821
811
|
<b><code>()</code></b><br>
|
|
822
|
-
<b><code>
|
|
812
|
+
<b><code>(queue: module:list.List<N>, node: N)</code></b><br>
|
|
823
813
|
<dd><p>Remove a single node from the queue. Only works with Queues that operate on Doubly-linked lists of nodes.</p></dd>
|
|
814
|
+
<b><code>()</code></b><br>
|
|
815
|
+
<b><code>ode</code></b><br>
|
|
824
816
|
<b><code>ode()</code></b><br>
|
|
825
817
|
<b><code>etween(queue: module:list.List<N>, left: N| null, right: N| null, node: N)</code></b><br>
|
|
826
818
|
<b><code>etween()</code></b><br>
|
|
819
|
+
<b><code>(queue: module:list.List<N>, node: N, newNode: N)</code></b><br>
|
|
820
|
+
<dd><p>Remove a single node from the queue. Only works with Queues that operate on Doubly-linked lists of nodes.</p></dd>
|
|
821
|
+
<b><code>()</code></b><br>
|
|
827
822
|
<b><code>(queue: module:list.List<N>, n: N)</code></b><br>
|
|
828
823
|
<b><code>()</code></b><br>
|
|
829
824
|
<b><code>nt(queue: module:list.List<N>, n: N)</code></b><br>
|
|
@@ -834,6 +829,10 @@ In practice, when decoding several million small strings, the GC will kick in mo
|
|
|
834
829
|
<b><code>()</code></b><br>
|
|
835
830
|
<b><code>(list: module:list.List<N>, f: function(N):M): Array<M></code></b><br>
|
|
836
831
|
<b><code>()</code></b><br>
|
|
832
|
+
<b><code>(list: module:list.List<N>)</code></b><br>
|
|
833
|
+
<b><code>()</code></b><br>
|
|
834
|
+
<b><code>(list: module:list.List<N>, f: function(N):M)</code></b><br>
|
|
835
|
+
<b><code>()</code></b><br>
|
|
837
836
|
</dl>
|
|
838
837
|
</details>
|
|
839
838
|
<details><summary><b>[lib0/logging]</b> Isomorphic logging module with support for colors!</summary>
|
|
@@ -1171,8 +1170,8 @@ integrate this algorithm.</p>
|
|
|
1171
1170
|
<pre>import * as testing from 'lib0/testing'</pre>
|
|
1172
1171
|
|
|
1173
1172
|
<pre class="prettyprint source lang-js"><code>// test.js template for creating a test executable
|
|
1174
|
-
import { runTests } from 'lib0/testing
|
|
1175
|
-
import * as log from 'lib0/logging
|
|
1173
|
+
import { runTests } from 'lib0/testing'
|
|
1174
|
+
import * as log from 'lib0/logging'
|
|
1176
1175
|
import * as mod1 from './mod1.test.js'
|
|
1177
1176
|
import * as mod2 from './mod2.test.js'
|
|
1178
1177
|
import { isBrowser, isNode } from 'lib0/environment.js'
|
package/decoding.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export function readVarUint(decoder: Decoder): number;
|
|
|
37
37
|
export function readVarInt(decoder: Decoder): number;
|
|
38
38
|
export function peekVarUint(decoder: Decoder): number;
|
|
39
39
|
export function peekVarInt(decoder: Decoder): number;
|
|
40
|
+
export function _readVarStringPolyfill(decoder: Decoder): string;
|
|
41
|
+
export function _readVarStringNative(decoder: Decoder): string;
|
|
40
42
|
export function readVarString(decoder: Decoder): string;
|
|
41
43
|
export function peekVarString(decoder: Decoder): string;
|
|
42
44
|
export function readFromDataView(decoder: Decoder, len: number): DataView;
|
package/decoding.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decoding.d.ts","sourceRoot":"","sources":["decoding.js"],"names":[],"mappings":"
|
|
1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;;;OAGG;IACH,wBAHW,UAAU,iBACD,OAAO,KAAE,CAAC,EAc7B;IAVC;;OAEG;IACH,eAPkB,OAAO,KAAE,CAAC,CAOR;IACpB;;;OAGG;IACH,GAFU,CAAC,GAAC,IAAI,CAEH;IACb,cAAc;IAGhB,UAWC;CACF;AAED;IACE;;;OAGG;IACH,wBAHW,UAAU,SACV,MAAM,EAShB;IALC;;;OAGG;IACH,GAFU,MAAM,CAEF;IAGhB;;OAEG;IACH,QAFY,MAAM,CAKjB;CACF;AAED;IACE;;;OAGG;IACH,wBAHW,UAAU,SACV,MAAM,EAUhB;IANC;;;OAGG;IACH,GAFU,MAAM,CAEF;IACd,cAAc;IAGhB;;OAEG;IACH,QAFY,MAAM,CAajB;CACF;AAED;IAMI;;OAEG;IACH,GAFU,MAAM,CAEN;IACV,cAAc;IAGhB,eAaC;CACF;AAED;IAMI;;OAEG;IACH,GAFU,MAAM,CAEN;IACV,cAAc;IAGhB,eAaC;CACF;AAED;IAMI;;OAEG;IACH,GAFU,MAAM,CAEN;IACV,cAAc;IACd,aAAa;IAGf;;OAEG;IACH,QAFY,MAAM,CAgBjB;CACF;AAED;IACE;;OAEG;IACH,wBAFW,UAAU,EASpB;IANC,2BAAgD;IAChD,YAAsC;IACtC;;OAEG;IACH,MAFU,MAAM,CAEH;IAGf;;OAEG;IACH,QAFY,MAAM,CAOjB;CACF"}
|
package/decoding.js
CHANGED
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
import * as buffer from './buffer.js'
|
|
30
30
|
import * as binary from './binary.js'
|
|
31
31
|
import * as math from './math.js'
|
|
32
|
+
import * as number from './number.js'
|
|
33
|
+
import * as string from './string.js'
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* A Decoder handles the decoding of an Uint8Array.
|
|
@@ -234,16 +236,17 @@ export const peekUint32 = decoder => (
|
|
|
234
236
|
*/
|
|
235
237
|
export const readVarUint = decoder => {
|
|
236
238
|
let num = 0
|
|
237
|
-
let
|
|
239
|
+
let mult = 1
|
|
238
240
|
while (true) {
|
|
239
241
|
const r = decoder.arr[decoder.pos++]
|
|
240
|
-
num = num | ((r & binary.BITS7) << len)
|
|
241
|
-
|
|
242
|
+
// num = num | ((r & binary.BITS7) << len)
|
|
243
|
+
num = num + (r & binary.BITS7) * mult // shift $r << (7*#iterations) and add it to num
|
|
244
|
+
mult *= 128 // next iteration, shift 7 "more" to the left
|
|
242
245
|
if (r < binary.BIT8) {
|
|
243
|
-
return num
|
|
246
|
+
return num
|
|
244
247
|
}
|
|
245
248
|
/* istanbul ignore if */
|
|
246
|
-
if (
|
|
249
|
+
if (num > number.MAX_SAFE_INTEGER) {
|
|
247
250
|
throw new Error('Integer out of range!')
|
|
248
251
|
}
|
|
249
252
|
}
|
|
@@ -263,7 +266,7 @@ export const readVarUint = decoder => {
|
|
|
263
266
|
export const readVarInt = decoder => {
|
|
264
267
|
let r = decoder.arr[decoder.pos++]
|
|
265
268
|
let num = r & binary.BITS6
|
|
266
|
-
let
|
|
269
|
+
let mult = 64
|
|
267
270
|
const sign = (r & binary.BIT7) > 0 ? -1 : 1
|
|
268
271
|
if ((r & binary.BIT8) === 0) {
|
|
269
272
|
// don't continue reading
|
|
@@ -271,13 +274,14 @@ export const readVarInt = decoder => {
|
|
|
271
274
|
}
|
|
272
275
|
while (true) {
|
|
273
276
|
r = decoder.arr[decoder.pos++]
|
|
274
|
-
num = num | ((r & binary.BITS7) << len)
|
|
275
|
-
|
|
277
|
+
// num = num | ((r & binary.BITS7) << len)
|
|
278
|
+
num = num + (r & binary.BITS7) * mult
|
|
279
|
+
mult *= 128
|
|
276
280
|
if (r < binary.BIT8) {
|
|
277
|
-
return sign *
|
|
281
|
+
return sign * num
|
|
278
282
|
}
|
|
279
283
|
/* istanbul ignore if */
|
|
280
|
-
if (
|
|
284
|
+
if (num > number.MAX_SAFE_INTEGER) {
|
|
281
285
|
throw new Error('Integer out of range!')
|
|
282
286
|
}
|
|
283
287
|
}
|
|
@@ -312,8 +316,8 @@ export const peekVarInt = decoder => {
|
|
|
312
316
|
}
|
|
313
317
|
|
|
314
318
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
319
|
+
* We don't test this function anymore as we use native decoding/encoding by default now.
|
|
320
|
+
* Better not modify this anymore..
|
|
317
321
|
*
|
|
318
322
|
* Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
319
323
|
* when String.fromCodePoint is fed with all characters as arguments.
|
|
@@ -324,7 +328,8 @@ export const peekVarInt = decoder => {
|
|
|
324
328
|
* @param {Decoder} decoder
|
|
325
329
|
* @return {String} The read String.
|
|
326
330
|
*/
|
|
327
|
-
|
|
331
|
+
/* istanbul ignore next */
|
|
332
|
+
export const _readVarStringPolyfill = decoder => {
|
|
328
333
|
let remainingLen = readVarUint(decoder)
|
|
329
334
|
if (remainingLen === 0) {
|
|
330
335
|
return ''
|
|
@@ -349,6 +354,26 @@ export const readVarString = decoder => {
|
|
|
349
354
|
}
|
|
350
355
|
}
|
|
351
356
|
|
|
357
|
+
/**
|
|
358
|
+
* @function
|
|
359
|
+
* @param {Decoder} decoder
|
|
360
|
+
* @return {String} The read String
|
|
361
|
+
*/
|
|
362
|
+
export const _readVarStringNative = decoder =>
|
|
363
|
+
/** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder))
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Read string of variable length
|
|
367
|
+
* * varUint is used to store the length of the string
|
|
368
|
+
*
|
|
369
|
+
* @function
|
|
370
|
+
* @param {Decoder} decoder
|
|
371
|
+
* @return {String} The read String
|
|
372
|
+
*
|
|
373
|
+
*/
|
|
374
|
+
/* istanbul ignore next */
|
|
375
|
+
export const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill
|
|
376
|
+
|
|
352
377
|
/**
|
|
353
378
|
* Look ahead and read varString without incrementing position
|
|
354
379
|
*
|
|
@@ -608,7 +633,7 @@ export class IntDiffOptRleDecoder extends Decoder {
|
|
|
608
633
|
const diff = readVarInt(this)
|
|
609
634
|
// if the first bit is set, we read more data
|
|
610
635
|
const hasCount = diff & 1
|
|
611
|
-
this.diff = diff >> 1
|
|
636
|
+
this.diff = math.floor(diff / 2) // shift >> 1
|
|
612
637
|
this.count = 1
|
|
613
638
|
if (hasCount) {
|
|
614
639
|
this.count = readVarUint(this) + 2
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var map = require('./map-28a001c9.cjs');
|
|
4
|
-
var encoding = require('./buffer-
|
|
4
|
+
var encoding = require('./buffer-d3ba308b.cjs');
|
|
5
5
|
var storage = require('./storage.cjs');
|
|
6
6
|
|
|
7
7
|
/* eslint-env browser */
|
|
@@ -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-
|
|
104
|
+
//# sourceMappingURL=broadcastchannel-7655b66f.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcastchannel-
|
|
1
|
+
{"version":3,"file":"broadcastchannel-7655b66f.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;A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C,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;AACA;AACY,MAAC,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK;AACtD,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,EAAE,MAAM,CAAC,EAAC;AAC1C;;;;;;;;;;;;;;"}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
require('./map-28a001c9.cjs');
|
|
6
|
-
require('./buffer-
|
|
6
|
+
require('./buffer-d3ba308b.cjs');
|
|
7
7
|
require('./storage.cjs');
|
|
8
|
-
var broadcastchannel = require('./broadcastchannel-
|
|
8
|
+
var broadcastchannel = require('./broadcastchannel-7655b66f.cjs');
|
|
9
9
|
require('./string-ad04f734.cjs');
|
|
10
10
|
require('./environment-60b83194.cjs');
|
|
11
11
|
require('./conditions-fb475c70.cjs');
|
|
@@ -235,9 +235,7 @@ const setUint32 = (encoder, pos, num) => {
|
|
|
235
235
|
};
|
|
236
236
|
|
|
237
237
|
/**
|
|
238
|
-
* Write a variable length unsigned integer.
|
|
239
|
-
*
|
|
240
|
-
* Encodes integers in the range from [0, 4294967295] / [0, 0xffffffff]. (max 32 bit unsigned integer)
|
|
238
|
+
* Write a variable length unsigned integer. Max encodable integer is 2^53.
|
|
241
239
|
*
|
|
242
240
|
* @function
|
|
243
241
|
* @param {Encoder} encoder
|
|
@@ -246,7 +244,7 @@ const setUint32 = (encoder, pos, num) => {
|
|
|
246
244
|
const writeVarUint = (encoder, num) => {
|
|
247
245
|
while (num > binary.BITS7) {
|
|
248
246
|
write(encoder, binary.BIT8 | (binary.BITS7 & num));
|
|
249
|
-
num
|
|
247
|
+
num = math.floor(num / 128); // shift >>> 7
|
|
250
248
|
}
|
|
251
249
|
write(encoder, binary.BITS7 & num);
|
|
252
250
|
};
|
|
@@ -254,11 +252,6 @@ const writeVarUint = (encoder, num) => {
|
|
|
254
252
|
/**
|
|
255
253
|
* Write a variable length integer.
|
|
256
254
|
*
|
|
257
|
-
* Encodes integers in the range from [-2147483648, -2147483647].
|
|
258
|
-
*
|
|
259
|
-
* We don't use zig-zag encoding because we want to keep the option open
|
|
260
|
-
* to use the same function for BigInt and 53bit integers (doubles).
|
|
261
|
-
*
|
|
262
255
|
* We use the 7th bit instead for signaling that this is a negative number.
|
|
263
256
|
*
|
|
264
257
|
* @function
|
|
@@ -272,15 +265,21 @@ const writeVarInt = (encoder, num) => {
|
|
|
272
265
|
}
|
|
273
266
|
// |- whether to continue reading |- whether is negative |- number
|
|
274
267
|
write(encoder, (num > binary.BITS6 ? binary.BIT8 : 0) | (isNegative ? binary.BIT7 : 0) | (binary.BITS6 & num));
|
|
275
|
-
num
|
|
268
|
+
num = math.floor(num / 64); // shift >>> 6
|
|
276
269
|
// We don't need to consider the case of num === 0 so we can use a different
|
|
277
270
|
// pattern here than above.
|
|
278
271
|
while (num > 0) {
|
|
279
272
|
write(encoder, (num > binary.BITS7 ? binary.BIT8 : 0) | (binary.BITS7 & num));
|
|
280
|
-
num
|
|
273
|
+
num = math.floor(num / 128); // shift >>> 7
|
|
281
274
|
}
|
|
282
275
|
};
|
|
283
276
|
|
|
277
|
+
/**
|
|
278
|
+
* A cache to store strings temporarily
|
|
279
|
+
*/
|
|
280
|
+
const _strBuffer = new Uint8Array(30000);
|
|
281
|
+
const _maxStrBSize = _strBuffer.length / 3;
|
|
282
|
+
|
|
284
283
|
/**
|
|
285
284
|
* Write a variable length string.
|
|
286
285
|
*
|
|
@@ -288,7 +287,28 @@ const writeVarInt = (encoder, num) => {
|
|
|
288
287
|
* @param {Encoder} encoder
|
|
289
288
|
* @param {String} str The string that is to be encoded.
|
|
290
289
|
*/
|
|
291
|
-
const
|
|
290
|
+
const _writeVarStringNative = (encoder, str) => {
|
|
291
|
+
if (str.length < _maxStrBSize) {
|
|
292
|
+
// We can encode the string into the existing buffer
|
|
293
|
+
/* istanbul ignore else */
|
|
294
|
+
const written = string.utf8TextEncoder.encodeInto(str, _strBuffer).written || 0;
|
|
295
|
+
writeVarUint(encoder, written);
|
|
296
|
+
for (let i = 0; i < written; i++) {
|
|
297
|
+
write(encoder, _strBuffer[i]);
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
writeVarUint8Array(encoder, string.encodeUtf8(str));
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Write a variable length string.
|
|
306
|
+
*
|
|
307
|
+
* @function
|
|
308
|
+
* @param {Encoder} encoder
|
|
309
|
+
* @param {String} str The string that is to be encoded.
|
|
310
|
+
*/
|
|
311
|
+
const _writeVarStringPolyfill = (encoder, str) => {
|
|
292
312
|
const encodedString = unescape(encodeURIComponent(str));
|
|
293
313
|
const len = encodedString.length;
|
|
294
314
|
writeVarUint(encoder, len);
|
|
@@ -297,6 +317,16 @@ const writeVarString = (encoder, str) => {
|
|
|
297
317
|
}
|
|
298
318
|
};
|
|
299
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Write a variable length string.
|
|
322
|
+
*
|
|
323
|
+
* @function
|
|
324
|
+
* @param {Encoder} encoder
|
|
325
|
+
* @param {String} str The string that is to be encoded.
|
|
326
|
+
*/
|
|
327
|
+
/* istanbul ignore next */
|
|
328
|
+
const writeVarString = string.utf8TextEncoder ? _writeVarStringNative : _writeVarStringPolyfill;
|
|
329
|
+
|
|
300
330
|
/**
|
|
301
331
|
* Write the content of another Encoder.
|
|
302
332
|
*
|
|
@@ -724,7 +754,8 @@ class IncUintOptRleEncoder {
|
|
|
724
754
|
const flushIntDiffOptRleEncoder = encoder => {
|
|
725
755
|
if (encoder.count > 0) {
|
|
726
756
|
// 31 bit making up the diff | wether to write the counter
|
|
727
|
-
const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)
|
|
757
|
+
// const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)
|
|
758
|
+
const encodedDiff = encoder.diff * 2 + (encoder.count === 1 ? 0 : 1);
|
|
728
759
|
// flush counter, unless this is the first value (count = 0)
|
|
729
760
|
// case 1: just a single value. set first bit to positive
|
|
730
761
|
// case 2: write several values. set first bit to negative to indicate that there is a length coming
|
|
@@ -832,6 +863,7 @@ var encoding = /*#__PURE__*/Object.freeze({
|
|
|
832
863
|
createEncoder: createEncoder,
|
|
833
864
|
length: length,
|
|
834
865
|
toUint8Array: toUint8Array,
|
|
866
|
+
verifyLen: verifyLen,
|
|
835
867
|
write: write,
|
|
836
868
|
set: set,
|
|
837
869
|
writeUint8: writeUint8,
|
|
@@ -843,6 +875,8 @@ var encoding = /*#__PURE__*/Object.freeze({
|
|
|
843
875
|
setUint32: setUint32,
|
|
844
876
|
writeVarUint: writeVarUint,
|
|
845
877
|
writeVarInt: writeVarInt,
|
|
878
|
+
_writeVarStringNative: _writeVarStringNative,
|
|
879
|
+
_writeVarStringPolyfill: _writeVarStringPolyfill,
|
|
846
880
|
writeVarString: writeVarString,
|
|
847
881
|
writeBinaryEncoder: writeBinaryEncoder,
|
|
848
882
|
writeUint8Array: writeUint8Array,
|
|
@@ -1094,16 +1128,17 @@ const peekUint32 = decoder => (
|
|
|
1094
1128
|
*/
|
|
1095
1129
|
const readVarUint = decoder => {
|
|
1096
1130
|
let num = 0;
|
|
1097
|
-
let
|
|
1131
|
+
let mult = 1;
|
|
1098
1132
|
while (true) {
|
|
1099
1133
|
const r = decoder.arr[decoder.pos++];
|
|
1100
|
-
num = num | ((r & binary.BITS7) << len)
|
|
1101
|
-
|
|
1134
|
+
// num = num | ((r & binary.BITS7) << len)
|
|
1135
|
+
num = num + (r & binary.BITS7) * mult; // shift $r << (7*#iterations) and add it to num
|
|
1136
|
+
mult *= 128; // next iteration, shift 7 "more" to the left
|
|
1102
1137
|
if (r < binary.BIT8) {
|
|
1103
|
-
return num
|
|
1138
|
+
return num
|
|
1104
1139
|
}
|
|
1105
1140
|
/* istanbul ignore if */
|
|
1106
|
-
if (
|
|
1141
|
+
if (num > number.MAX_SAFE_INTEGER) {
|
|
1107
1142
|
throw new Error('Integer out of range!')
|
|
1108
1143
|
}
|
|
1109
1144
|
}
|
|
@@ -1123,7 +1158,7 @@ const readVarUint = decoder => {
|
|
|
1123
1158
|
const readVarInt = decoder => {
|
|
1124
1159
|
let r = decoder.arr[decoder.pos++];
|
|
1125
1160
|
let num = r & binary.BITS6;
|
|
1126
|
-
let
|
|
1161
|
+
let mult = 64;
|
|
1127
1162
|
const sign = (r & binary.BIT7) > 0 ? -1 : 1;
|
|
1128
1163
|
if ((r & binary.BIT8) === 0) {
|
|
1129
1164
|
// don't continue reading
|
|
@@ -1131,13 +1166,14 @@ const readVarInt = decoder => {
|
|
|
1131
1166
|
}
|
|
1132
1167
|
while (true) {
|
|
1133
1168
|
r = decoder.arr[decoder.pos++];
|
|
1134
|
-
num = num | ((r & binary.BITS7) << len)
|
|
1135
|
-
|
|
1169
|
+
// num = num | ((r & binary.BITS7) << len)
|
|
1170
|
+
num = num + (r & binary.BITS7) * mult;
|
|
1171
|
+
mult *= 128;
|
|
1136
1172
|
if (r < binary.BIT8) {
|
|
1137
|
-
return sign *
|
|
1173
|
+
return sign * num
|
|
1138
1174
|
}
|
|
1139
1175
|
/* istanbul ignore if */
|
|
1140
|
-
if (
|
|
1176
|
+
if (num > number.MAX_SAFE_INTEGER) {
|
|
1141
1177
|
throw new Error('Integer out of range!')
|
|
1142
1178
|
}
|
|
1143
1179
|
}
|
|
@@ -1172,8 +1208,8 @@ const peekVarInt = decoder => {
|
|
|
1172
1208
|
};
|
|
1173
1209
|
|
|
1174
1210
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
1211
|
+
* We don't test this function anymore as we use native decoding/encoding by default now.
|
|
1212
|
+
* Better not modify this anymore..
|
|
1177
1213
|
*
|
|
1178
1214
|
* Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
1179
1215
|
* when String.fromCodePoint is fed with all characters as arguments.
|
|
@@ -1184,7 +1220,8 @@ const peekVarInt = decoder => {
|
|
|
1184
1220
|
* @param {Decoder} decoder
|
|
1185
1221
|
* @return {String} The read String.
|
|
1186
1222
|
*/
|
|
1187
|
-
|
|
1223
|
+
/* istanbul ignore next */
|
|
1224
|
+
const _readVarStringPolyfill = decoder => {
|
|
1188
1225
|
let remainingLen = readVarUint(decoder);
|
|
1189
1226
|
if (remainingLen === 0) {
|
|
1190
1227
|
return ''
|
|
@@ -1209,6 +1246,26 @@ const readVarString = decoder => {
|
|
|
1209
1246
|
}
|
|
1210
1247
|
};
|
|
1211
1248
|
|
|
1249
|
+
/**
|
|
1250
|
+
* @function
|
|
1251
|
+
* @param {Decoder} decoder
|
|
1252
|
+
* @return {String} The read String
|
|
1253
|
+
*/
|
|
1254
|
+
const _readVarStringNative = decoder =>
|
|
1255
|
+
/** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder));
|
|
1256
|
+
|
|
1257
|
+
/**
|
|
1258
|
+
* Read string of variable length
|
|
1259
|
+
* * varUint is used to store the length of the string
|
|
1260
|
+
*
|
|
1261
|
+
* @function
|
|
1262
|
+
* @param {Decoder} decoder
|
|
1263
|
+
* @return {String} The read String
|
|
1264
|
+
*
|
|
1265
|
+
*/
|
|
1266
|
+
/* istanbul ignore next */
|
|
1267
|
+
const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
1268
|
+
|
|
1212
1269
|
/**
|
|
1213
1270
|
* Look ahead and read varString without incrementing position
|
|
1214
1271
|
*
|
|
@@ -1468,7 +1525,7 @@ class IntDiffOptRleDecoder extends Decoder {
|
|
|
1468
1525
|
const diff = readVarInt(this);
|
|
1469
1526
|
// if the first bit is set, we read more data
|
|
1470
1527
|
const hasCount = diff & 1;
|
|
1471
|
-
this.diff = diff >> 1
|
|
1528
|
+
this.diff = math.floor(diff / 2); // shift >> 1
|
|
1472
1529
|
this.count = 1;
|
|
1473
1530
|
if (hasCount) {
|
|
1474
1531
|
this.count = readVarUint(this) + 2;
|
|
@@ -1525,6 +1582,8 @@ var decoding = /*#__PURE__*/Object.freeze({
|
|
|
1525
1582
|
readVarInt: readVarInt,
|
|
1526
1583
|
peekVarUint: peekVarUint,
|
|
1527
1584
|
peekVarInt: peekVarInt,
|
|
1585
|
+
_readVarStringPolyfill: _readVarStringPolyfill,
|
|
1586
|
+
_readVarStringNative: _readVarStringNative,
|
|
1528
1587
|
readVarString: readVarString,
|
|
1529
1588
|
peekVarString: peekVarString,
|
|
1530
1589
|
readFromDataView: readFromDataView,
|
|
@@ -1679,6 +1738,10 @@ exports.StringDecoder = StringDecoder;
|
|
|
1679
1738
|
exports.StringEncoder = StringEncoder;
|
|
1680
1739
|
exports.UintOptRleDecoder = UintOptRleDecoder;
|
|
1681
1740
|
exports.UintOptRleEncoder = UintOptRleEncoder;
|
|
1741
|
+
exports._readVarStringNative = _readVarStringNative;
|
|
1742
|
+
exports._readVarStringPolyfill = _readVarStringPolyfill;
|
|
1743
|
+
exports._writeVarStringNative = _writeVarStringNative;
|
|
1744
|
+
exports._writeVarStringPolyfill = _writeVarStringPolyfill;
|
|
1682
1745
|
exports.buffer = buffer;
|
|
1683
1746
|
exports.clone = clone;
|
|
1684
1747
|
exports.copyUint8Array = copyUint8Array;
|
|
@@ -1723,6 +1786,7 @@ exports.setUint8 = setUint8;
|
|
|
1723
1786
|
exports.skip8 = skip8;
|
|
1724
1787
|
exports.toBase64 = toBase64;
|
|
1725
1788
|
exports.toUint8Array = toUint8Array;
|
|
1789
|
+
exports.verifyLen = verifyLen;
|
|
1726
1790
|
exports.write = write;
|
|
1727
1791
|
exports.writeAny = writeAny;
|
|
1728
1792
|
exports.writeBigInt64 = writeBigInt64;
|
|
@@ -1740,4 +1804,4 @@ exports.writeVarInt = writeVarInt;
|
|
|
1740
1804
|
exports.writeVarString = writeVarString;
|
|
1741
1805
|
exports.writeVarUint = writeVarUint;
|
|
1742
1806
|
exports.writeVarUint8Array = writeVarUint8Array;
|
|
1743
|
-
//# sourceMappingURL=buffer-
|
|
1807
|
+
//# sourceMappingURL=buffer-d3ba308b.cjs.map
|