@vertexvis/utils 0.15.1-canary.0 → 0.15.1-canary.3

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.
@@ -260,7 +260,7 @@ var create$2 = function (r, g, b, a) {
260
260
  * Converts a numeric color value containing red, green and blue values to a
261
261
  * `Color`. The alpha channel will default to fully opaque.
262
262
  */
263
- var fromNumber = function (num) {
263
+ var fromNumber$1 = function (num) {
264
264
  // tslint:disable:no-bitwise
265
265
  var normalized = num & 0xffffff;
266
266
  return create$2((normalized >> 16) & 0xff, (normalized >> 8) & 0xff, normalized & 0xff);
@@ -274,7 +274,7 @@ var fromNumber = function (num) {
274
274
  var fromHexString = function (str) {
275
275
  var match = hexRegex.exec(str);
276
276
  if (match != null) {
277
- return fromNumber(parseInt(match[2], 16));
277
+ return fromNumber$1(parseInt(match[2], 16));
278
278
  }
279
279
  };
280
280
  /**
@@ -329,7 +329,7 @@ var componentToHex = function (num) {
329
329
  var color = /*#__PURE__*/Object.freeze({
330
330
  __proto__: null,
331
331
  create: create$2,
332
- fromNumber: fromNumber,
332
+ fromNumber: fromNumber$1,
333
333
  fromHexString: fromHexString,
334
334
  fromCss: fromCss,
335
335
  fromArray: fromArray,
@@ -2946,7 +2946,7 @@ var head = function (comparator) {
2946
2946
  *
2947
2947
  * @param uri The URI to parse.
2948
2948
  */
2949
- var parse = function (uri) {
2949
+ var parse$1 = function (uri) {
2950
2950
  var regex = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
2951
2951
  var match = regex.exec(uri);
2952
2952
  if (match != null) {
@@ -2968,7 +2968,7 @@ var parse = function (uri) {
2968
2968
  * @param params
2969
2969
  */
2970
2970
  var parseAndAddParams = function (baseStr, params) {
2971
- var base = parse(baseStr);
2971
+ var base = parse$1(baseStr);
2972
2972
  return params ? addQueryParams(params, base) : base;
2973
2973
  };
2974
2974
  var isEqual = function (a, b) {
@@ -3088,7 +3088,7 @@ var sortByQueryName = function (entries) {
3088
3088
 
3089
3089
  var uri = /*#__PURE__*/Object.freeze({
3090
3090
  __proto__: null,
3091
- parse: parse,
3091
+ parse: parse$1,
3092
3092
  parseAndAddParams: parseAndAddParams,
3093
3093
  isEqual: isEqual,
3094
3094
  replacePath: replacePath,
@@ -3104,6 +3104,1472 @@ var uri = /*#__PURE__*/Object.freeze({
3104
3104
  toString: toString
3105
3105
  });
3106
3106
 
3107
+ /**
3108
+ * @license
3109
+ * Copyright 2009 The Closure Library Authors
3110
+ * Copyright 2020 Daniel Wirtz / The long.js Authors.
3111
+ *
3112
+ * Licensed under the Apache License, Version 2.0 (the "License");
3113
+ * you may not use this file except in compliance with the License.
3114
+ * You may obtain a copy of the License at
3115
+ *
3116
+ * http://www.apache.org/licenses/LICENSE-2.0
3117
+ *
3118
+ * Unless required by applicable law or agreed to in writing, software
3119
+ * distributed under the License is distributed on an "AS IS" BASIS,
3120
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3121
+ * See the License for the specific language governing permissions and
3122
+ * limitations under the License.
3123
+ *
3124
+ * SPDX-License-Identifier: Apache-2.0
3125
+ */
3126
+
3127
+ // WebAssembly optimizations to do native i64 multiplication and divide
3128
+ var wasm = null;
3129
+ try {
3130
+ wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
3131
+ 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11
3132
+ ])), {}).exports;
3133
+ } catch (e) {
3134
+ // no wasm support :(
3135
+ }
3136
+
3137
+ /**
3138
+ * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
3139
+ * See the from* functions below for more convenient ways of constructing Longs.
3140
+ * @exports Long
3141
+ * @class A Long class for representing a 64 bit two's-complement integer value.
3142
+ * @param {number} low The low (signed) 32 bits of the long
3143
+ * @param {number} high The high (signed) 32 bits of the long
3144
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3145
+ * @constructor
3146
+ */
3147
+ function Long(low, high, unsigned) {
3148
+
3149
+ /**
3150
+ * The low 32 bits as a signed value.
3151
+ * @type {number}
3152
+ */
3153
+ this.low = low | 0;
3154
+
3155
+ /**
3156
+ * The high 32 bits as a signed value.
3157
+ * @type {number}
3158
+ */
3159
+ this.high = high | 0;
3160
+
3161
+ /**
3162
+ * Whether unsigned or not.
3163
+ * @type {boolean}
3164
+ */
3165
+ this.unsigned = !!unsigned;
3166
+ }
3167
+
3168
+ // The internal representation of a long is the two given signed, 32-bit values.
3169
+ // We use 32-bit pieces because these are the size of integers on which
3170
+ // Javascript performs bit-operations. For operations like addition and
3171
+ // multiplication, we split each number into 16 bit pieces, which can easily be
3172
+ // multiplied within Javascript's floating-point representation without overflow
3173
+ // or change in sign.
3174
+ //
3175
+ // In the algorithms below, we frequently reduce the negative case to the
3176
+ // positive case by negating the input(s) and then post-processing the result.
3177
+ // Note that we must ALWAYS check specially whether those values are MIN_VALUE
3178
+ // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
3179
+ // a positive number, it overflows back into a negative). Not handling this
3180
+ // case would often result in infinite recursion.
3181
+ //
3182
+ // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from*
3183
+ // methods on which they depend.
3184
+
3185
+ /**
3186
+ * An indicator used to reliably determine if an object is a Long or not.
3187
+ * @type {boolean}
3188
+ * @const
3189
+ * @private
3190
+ */
3191
+ Long.prototype.__isLong__;
3192
+
3193
+ Object.defineProperty(Long.prototype, "__isLong__", { value: true });
3194
+
3195
+ /**
3196
+ * @function
3197
+ * @param {*} obj Object
3198
+ * @returns {boolean}
3199
+ * @inner
3200
+ */
3201
+ function isLong(obj) {
3202
+ return (obj && obj["__isLong__"]) === true;
3203
+ }
3204
+
3205
+ /**
3206
+ * @function
3207
+ * @param {*} value number
3208
+ * @returns {number}
3209
+ * @inner
3210
+ */
3211
+ function ctz32(value) {
3212
+ var c = Math.clz32(value & -value);
3213
+ return value ? 31 - c : c;
3214
+ }
3215
+
3216
+ /**
3217
+ * Tests if the specified object is a Long.
3218
+ * @function
3219
+ * @param {*} obj Object
3220
+ * @returns {boolean}
3221
+ */
3222
+ Long.isLong = isLong;
3223
+
3224
+ /**
3225
+ * A cache of the Long representations of small integer values.
3226
+ * @type {!Object}
3227
+ * @inner
3228
+ */
3229
+ var INT_CACHE = {};
3230
+
3231
+ /**
3232
+ * A cache of the Long representations of small unsigned integer values.
3233
+ * @type {!Object}
3234
+ * @inner
3235
+ */
3236
+ var UINT_CACHE = {};
3237
+
3238
+ /**
3239
+ * @param {number} value
3240
+ * @param {boolean=} unsigned
3241
+ * @returns {!Long}
3242
+ * @inner
3243
+ */
3244
+ function fromInt(value, unsigned) {
3245
+ var obj, cachedObj, cache;
3246
+ if (unsigned) {
3247
+ value >>>= 0;
3248
+ if (cache = (0 <= value && value < 256)) {
3249
+ cachedObj = UINT_CACHE[value];
3250
+ if (cachedObj)
3251
+ return cachedObj;
3252
+ }
3253
+ obj = fromBits(value, 0, true);
3254
+ if (cache)
3255
+ UINT_CACHE[value] = obj;
3256
+ return obj;
3257
+ } else {
3258
+ value |= 0;
3259
+ if (cache = (-128 <= value && value < 128)) {
3260
+ cachedObj = INT_CACHE[value];
3261
+ if (cachedObj)
3262
+ return cachedObj;
3263
+ }
3264
+ obj = fromBits(value, value < 0 ? -1 : 0, false);
3265
+ if (cache)
3266
+ INT_CACHE[value] = obj;
3267
+ return obj;
3268
+ }
3269
+ }
3270
+
3271
+ /**
3272
+ * Returns a Long representing the given 32 bit integer value.
3273
+ * @function
3274
+ * @param {number} value The 32 bit integer in question
3275
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3276
+ * @returns {!Long} The corresponding Long value
3277
+ */
3278
+ Long.fromInt = fromInt;
3279
+
3280
+ /**
3281
+ * @param {number} value
3282
+ * @param {boolean=} unsigned
3283
+ * @returns {!Long}
3284
+ * @inner
3285
+ */
3286
+ function fromNumber(value, unsigned) {
3287
+ if (isNaN(value))
3288
+ return unsigned ? UZERO : ZERO;
3289
+ if (unsigned) {
3290
+ if (value < 0)
3291
+ return UZERO;
3292
+ if (value >= TWO_PWR_64_DBL)
3293
+ return MAX_UNSIGNED_VALUE;
3294
+ } else {
3295
+ if (value <= -TWO_PWR_63_DBL)
3296
+ return MIN_VALUE;
3297
+ if (value + 1 >= TWO_PWR_63_DBL)
3298
+ return MAX_VALUE;
3299
+ }
3300
+ if (value < 0)
3301
+ return fromNumber(-value, unsigned).neg();
3302
+ return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
3303
+ }
3304
+
3305
+ /**
3306
+ * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
3307
+ * @function
3308
+ * @param {number} value The number in question
3309
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3310
+ * @returns {!Long} The corresponding Long value
3311
+ */
3312
+ Long.fromNumber = fromNumber;
3313
+
3314
+ /**
3315
+ * @param {number} lowBits
3316
+ * @param {number} highBits
3317
+ * @param {boolean=} unsigned
3318
+ * @returns {!Long}
3319
+ * @inner
3320
+ */
3321
+ function fromBits(lowBits, highBits, unsigned) {
3322
+ return new Long(lowBits, highBits, unsigned);
3323
+ }
3324
+
3325
+ /**
3326
+ * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is
3327
+ * assumed to use 32 bits.
3328
+ * @function
3329
+ * @param {number} lowBits The low 32 bits
3330
+ * @param {number} highBits The high 32 bits
3331
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3332
+ * @returns {!Long} The corresponding Long value
3333
+ */
3334
+ Long.fromBits = fromBits;
3335
+
3336
+ /**
3337
+ * @function
3338
+ * @param {number} base
3339
+ * @param {number} exponent
3340
+ * @returns {number}
3341
+ * @inner
3342
+ */
3343
+ var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
3344
+
3345
+ /**
3346
+ * @param {string} str
3347
+ * @param {(boolean|number)=} unsigned
3348
+ * @param {number=} radix
3349
+ * @returns {!Long}
3350
+ * @inner
3351
+ */
3352
+ function fromString(str, unsigned, radix) {
3353
+ if (str.length === 0)
3354
+ throw Error('empty string');
3355
+ if (typeof unsigned === 'number') {
3356
+ // For goog.math.long compatibility
3357
+ radix = unsigned;
3358
+ unsigned = false;
3359
+ } else {
3360
+ unsigned = !!unsigned;
3361
+ }
3362
+ if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
3363
+ return unsigned ? UZERO : ZERO;
3364
+ radix = radix || 10;
3365
+ if (radix < 2 || 36 < radix)
3366
+ throw RangeError('radix');
3367
+
3368
+ var p;
3369
+ if ((p = str.indexOf('-')) > 0)
3370
+ throw Error('interior hyphen');
3371
+ else if (p === 0) {
3372
+ return fromString(str.substring(1), unsigned, radix).neg();
3373
+ }
3374
+
3375
+ // Do several (8) digits each time through the loop, so as to
3376
+ // minimize the calls to the very expensive emulated div.
3377
+ var radixToPower = fromNumber(pow_dbl(radix, 8));
3378
+
3379
+ var result = ZERO;
3380
+ for (var i = 0; i < str.length; i += 8) {
3381
+ var size = Math.min(8, str.length - i),
3382
+ value = parseInt(str.substring(i, i + size), radix);
3383
+ if (size < 8) {
3384
+ var power = fromNumber(pow_dbl(radix, size));
3385
+ result = result.mul(power).add(fromNumber(value));
3386
+ } else {
3387
+ result = result.mul(radixToPower);
3388
+ result = result.add(fromNumber(value));
3389
+ }
3390
+ }
3391
+ result.unsigned = unsigned;
3392
+ return result;
3393
+ }
3394
+
3395
+ /**
3396
+ * Returns a Long representation of the given string, written using the specified radix.
3397
+ * @function
3398
+ * @param {string} str The textual representation of the Long
3399
+ * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed
3400
+ * @param {number=} radix The radix in which the text is written (2-36), defaults to 10
3401
+ * @returns {!Long} The corresponding Long value
3402
+ */
3403
+ Long.fromString = fromString;
3404
+
3405
+ /**
3406
+ * @function
3407
+ * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val
3408
+ * @param {boolean=} unsigned
3409
+ * @returns {!Long}
3410
+ * @inner
3411
+ */
3412
+ function fromValue(val, unsigned) {
3413
+ if (typeof val === 'number')
3414
+ return fromNumber(val, unsigned);
3415
+ if (typeof val === 'string')
3416
+ return fromString(val, unsigned);
3417
+ // Throws for non-objects, converts non-instanceof Long:
3418
+ return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
3419
+ }
3420
+
3421
+ /**
3422
+ * Converts the specified value to a Long using the appropriate from* function for its type.
3423
+ * @function
3424
+ * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
3425
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3426
+ * @returns {!Long}
3427
+ */
3428
+ Long.fromValue = fromValue;
3429
+
3430
+ // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
3431
+ // no runtime penalty for these.
3432
+
3433
+ /**
3434
+ * @type {number}
3435
+ * @const
3436
+ * @inner
3437
+ */
3438
+ var TWO_PWR_16_DBL = 1 << 16;
3439
+
3440
+ /**
3441
+ * @type {number}
3442
+ * @const
3443
+ * @inner
3444
+ */
3445
+ var TWO_PWR_24_DBL = 1 << 24;
3446
+
3447
+ /**
3448
+ * @type {number}
3449
+ * @const
3450
+ * @inner
3451
+ */
3452
+ var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
3453
+
3454
+ /**
3455
+ * @type {number}
3456
+ * @const
3457
+ * @inner
3458
+ */
3459
+ var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
3460
+
3461
+ /**
3462
+ * @type {number}
3463
+ * @const
3464
+ * @inner
3465
+ */
3466
+ var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
3467
+
3468
+ /**
3469
+ * @type {!Long}
3470
+ * @const
3471
+ * @inner
3472
+ */
3473
+ var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
3474
+
3475
+ /**
3476
+ * @type {!Long}
3477
+ * @inner
3478
+ */
3479
+ var ZERO = fromInt(0);
3480
+
3481
+ /**
3482
+ * Signed zero.
3483
+ * @type {!Long}
3484
+ */
3485
+ Long.ZERO = ZERO;
3486
+
3487
+ /**
3488
+ * @type {!Long}
3489
+ * @inner
3490
+ */
3491
+ var UZERO = fromInt(0, true);
3492
+
3493
+ /**
3494
+ * Unsigned zero.
3495
+ * @type {!Long}
3496
+ */
3497
+ Long.UZERO = UZERO;
3498
+
3499
+ /**
3500
+ * @type {!Long}
3501
+ * @inner
3502
+ */
3503
+ var ONE = fromInt(1);
3504
+
3505
+ /**
3506
+ * Signed one.
3507
+ * @type {!Long}
3508
+ */
3509
+ Long.ONE = ONE;
3510
+
3511
+ /**
3512
+ * @type {!Long}
3513
+ * @inner
3514
+ */
3515
+ var UONE = fromInt(1, true);
3516
+
3517
+ /**
3518
+ * Unsigned one.
3519
+ * @type {!Long}
3520
+ */
3521
+ Long.UONE = UONE;
3522
+
3523
+ /**
3524
+ * @type {!Long}
3525
+ * @inner
3526
+ */
3527
+ var NEG_ONE = fromInt(-1);
3528
+
3529
+ /**
3530
+ * Signed negative one.
3531
+ * @type {!Long}
3532
+ */
3533
+ Long.NEG_ONE = NEG_ONE;
3534
+
3535
+ /**
3536
+ * @type {!Long}
3537
+ * @inner
3538
+ */
3539
+ var MAX_VALUE = fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false);
3540
+
3541
+ /**
3542
+ * Maximum signed value.
3543
+ * @type {!Long}
3544
+ */
3545
+ Long.MAX_VALUE = MAX_VALUE;
3546
+
3547
+ /**
3548
+ * @type {!Long}
3549
+ * @inner
3550
+ */
3551
+ var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true);
3552
+
3553
+ /**
3554
+ * Maximum unsigned value.
3555
+ * @type {!Long}
3556
+ */
3557
+ Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
3558
+
3559
+ /**
3560
+ * @type {!Long}
3561
+ * @inner
3562
+ */
3563
+ var MIN_VALUE = fromBits(0, 0x80000000 | 0, false);
3564
+
3565
+ /**
3566
+ * Minimum signed value.
3567
+ * @type {!Long}
3568
+ */
3569
+ Long.MIN_VALUE = MIN_VALUE;
3570
+
3571
+ /**
3572
+ * @alias Long.prototype
3573
+ * @inner
3574
+ */
3575
+ var LongPrototype = Long.prototype;
3576
+
3577
+ /**
3578
+ * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
3579
+ * @this {!Long}
3580
+ * @returns {number}
3581
+ */
3582
+ LongPrototype.toInt = function toInt() {
3583
+ return this.unsigned ? this.low >>> 0 : this.low;
3584
+ };
3585
+
3586
+ /**
3587
+ * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
3588
+ * @this {!Long}
3589
+ * @returns {number}
3590
+ */
3591
+ LongPrototype.toNumber = function toNumber() {
3592
+ if (this.unsigned)
3593
+ return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
3594
+ return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
3595
+ };
3596
+
3597
+ /**
3598
+ * Converts the Long to a string written in the specified radix.
3599
+ * @this {!Long}
3600
+ * @param {number=} radix Radix (2-36), defaults to 10
3601
+ * @returns {string}
3602
+ * @override
3603
+ * @throws {RangeError} If `radix` is out of range
3604
+ */
3605
+ LongPrototype.toString = function toString(radix) {
3606
+ radix = radix || 10;
3607
+ if (radix < 2 || 36 < radix)
3608
+ throw RangeError('radix');
3609
+ if (this.isZero())
3610
+ return '0';
3611
+ if (this.isNegative()) { // Unsigned Longs are never negative
3612
+ if (this.eq(MIN_VALUE)) {
3613
+ // We need to change the Long value before it can be negated, so we remove
3614
+ // the bottom-most digit in this base and then recurse to do the rest.
3615
+ var radixLong = fromNumber(radix),
3616
+ div = this.div(radixLong),
3617
+ rem1 = div.mul(radixLong).sub(this);
3618
+ return div.toString(radix) + rem1.toInt().toString(radix);
3619
+ } else
3620
+ return '-' + this.neg().toString(radix);
3621
+ }
3622
+
3623
+ // Do several (6) digits each time through the loop, so as to
3624
+ // minimize the calls to the very expensive emulated div.
3625
+ var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
3626
+ rem = this;
3627
+ var result = '';
3628
+ while (true) {
3629
+ var remDiv = rem.div(radixToPower),
3630
+ intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
3631
+ digits = intval.toString(radix);
3632
+ rem = remDiv;
3633
+ if (rem.isZero())
3634
+ return digits + result;
3635
+ else {
3636
+ while (digits.length < 6)
3637
+ digits = '0' + digits;
3638
+ result = '' + digits + result;
3639
+ }
3640
+ }
3641
+ };
3642
+
3643
+ /**
3644
+ * Gets the high 32 bits as a signed integer.
3645
+ * @this {!Long}
3646
+ * @returns {number} Signed high bits
3647
+ */
3648
+ LongPrototype.getHighBits = function getHighBits() {
3649
+ return this.high;
3650
+ };
3651
+
3652
+ /**
3653
+ * Gets the high 32 bits as an unsigned integer.
3654
+ * @this {!Long}
3655
+ * @returns {number} Unsigned high bits
3656
+ */
3657
+ LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
3658
+ return this.high >>> 0;
3659
+ };
3660
+
3661
+ /**
3662
+ * Gets the low 32 bits as a signed integer.
3663
+ * @this {!Long}
3664
+ * @returns {number} Signed low bits
3665
+ */
3666
+ LongPrototype.getLowBits = function getLowBits() {
3667
+ return this.low;
3668
+ };
3669
+
3670
+ /**
3671
+ * Gets the low 32 bits as an unsigned integer.
3672
+ * @this {!Long}
3673
+ * @returns {number} Unsigned low bits
3674
+ */
3675
+ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
3676
+ return this.low >>> 0;
3677
+ };
3678
+
3679
+ /**
3680
+ * Gets the number of bits needed to represent the absolute value of this Long.
3681
+ * @this {!Long}
3682
+ * @returns {number}
3683
+ */
3684
+ LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
3685
+ if (this.isNegative()) // Unsigned Longs are never negative
3686
+ return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
3687
+ var val = this.high != 0 ? this.high : this.low;
3688
+ for (var bit = 31; bit > 0; bit--)
3689
+ if ((val & (1 << bit)) != 0)
3690
+ break;
3691
+ return this.high != 0 ? bit + 33 : bit + 1;
3692
+ };
3693
+
3694
+ /**
3695
+ * Tests if this Long's value equals zero.
3696
+ * @this {!Long}
3697
+ * @returns {boolean}
3698
+ */
3699
+ LongPrototype.isZero = function isZero() {
3700
+ return this.high === 0 && this.low === 0;
3701
+ };
3702
+
3703
+ /**
3704
+ * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}.
3705
+ * @returns {boolean}
3706
+ */
3707
+ LongPrototype.eqz = LongPrototype.isZero;
3708
+
3709
+ /**
3710
+ * Tests if this Long's value is negative.
3711
+ * @this {!Long}
3712
+ * @returns {boolean}
3713
+ */
3714
+ LongPrototype.isNegative = function isNegative() {
3715
+ return !this.unsigned && this.high < 0;
3716
+ };
3717
+
3718
+ /**
3719
+ * Tests if this Long's value is positive or zero.
3720
+ * @this {!Long}
3721
+ * @returns {boolean}
3722
+ */
3723
+ LongPrototype.isPositive = function isPositive() {
3724
+ return this.unsigned || this.high >= 0;
3725
+ };
3726
+
3727
+ /**
3728
+ * Tests if this Long's value is odd.
3729
+ * @this {!Long}
3730
+ * @returns {boolean}
3731
+ */
3732
+ LongPrototype.isOdd = function isOdd() {
3733
+ return (this.low & 1) === 1;
3734
+ };
3735
+
3736
+ /**
3737
+ * Tests if this Long's value is even.
3738
+ * @this {!Long}
3739
+ * @returns {boolean}
3740
+ */
3741
+ LongPrototype.isEven = function isEven() {
3742
+ return (this.low & 1) === 0;
3743
+ };
3744
+
3745
+ /**
3746
+ * Tests if this Long's value equals the specified's.
3747
+ * @this {!Long}
3748
+ * @param {!Long|number|string} other Other value
3749
+ * @returns {boolean}
3750
+ */
3751
+ LongPrototype.equals = function equals(other) {
3752
+ if (!isLong(other))
3753
+ other = fromValue(other);
3754
+ if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
3755
+ return false;
3756
+ return this.high === other.high && this.low === other.low;
3757
+ };
3758
+
3759
+ /**
3760
+ * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.
3761
+ * @function
3762
+ * @param {!Long|number|string} other Other value
3763
+ * @returns {boolean}
3764
+ */
3765
+ LongPrototype.eq = LongPrototype.equals;
3766
+
3767
+ /**
3768
+ * Tests if this Long's value differs from the specified's.
3769
+ * @this {!Long}
3770
+ * @param {!Long|number|string} other Other value
3771
+ * @returns {boolean}
3772
+ */
3773
+ LongPrototype.notEquals = function notEquals(other) {
3774
+ return !this.eq(/* validates */ other);
3775
+ };
3776
+
3777
+ /**
3778
+ * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
3779
+ * @function
3780
+ * @param {!Long|number|string} other Other value
3781
+ * @returns {boolean}
3782
+ */
3783
+ LongPrototype.neq = LongPrototype.notEquals;
3784
+
3785
+ /**
3786
+ * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
3787
+ * @function
3788
+ * @param {!Long|number|string} other Other value
3789
+ * @returns {boolean}
3790
+ */
3791
+ LongPrototype.ne = LongPrototype.notEquals;
3792
+
3793
+ /**
3794
+ * Tests if this Long's value is less than the specified's.
3795
+ * @this {!Long}
3796
+ * @param {!Long|number|string} other Other value
3797
+ * @returns {boolean}
3798
+ */
3799
+ LongPrototype.lessThan = function lessThan(other) {
3800
+ return this.comp(/* validates */ other) < 0;
3801
+ };
3802
+
3803
+ /**
3804
+ * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.
3805
+ * @function
3806
+ * @param {!Long|number|string} other Other value
3807
+ * @returns {boolean}
3808
+ */
3809
+ LongPrototype.lt = LongPrototype.lessThan;
3810
+
3811
+ /**
3812
+ * Tests if this Long's value is less than or equal the specified's.
3813
+ * @this {!Long}
3814
+ * @param {!Long|number|string} other Other value
3815
+ * @returns {boolean}
3816
+ */
3817
+ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
3818
+ return this.comp(/* validates */ other) <= 0;
3819
+ };
3820
+
3821
+ /**
3822
+ * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
3823
+ * @function
3824
+ * @param {!Long|number|string} other Other value
3825
+ * @returns {boolean}
3826
+ */
3827
+ LongPrototype.lte = LongPrototype.lessThanOrEqual;
3828
+
3829
+ /**
3830
+ * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
3831
+ * @function
3832
+ * @param {!Long|number|string} other Other value
3833
+ * @returns {boolean}
3834
+ */
3835
+ LongPrototype.le = LongPrototype.lessThanOrEqual;
3836
+
3837
+ /**
3838
+ * Tests if this Long's value is greater than the specified's.
3839
+ * @this {!Long}
3840
+ * @param {!Long|number|string} other Other value
3841
+ * @returns {boolean}
3842
+ */
3843
+ LongPrototype.greaterThan = function greaterThan(other) {
3844
+ return this.comp(/* validates */ other) > 0;
3845
+ };
3846
+
3847
+ /**
3848
+ * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.
3849
+ * @function
3850
+ * @param {!Long|number|string} other Other value
3851
+ * @returns {boolean}
3852
+ */
3853
+ LongPrototype.gt = LongPrototype.greaterThan;
3854
+
3855
+ /**
3856
+ * Tests if this Long's value is greater than or equal the specified's.
3857
+ * @this {!Long}
3858
+ * @param {!Long|number|string} other Other value
3859
+ * @returns {boolean}
3860
+ */
3861
+ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
3862
+ return this.comp(/* validates */ other) >= 0;
3863
+ };
3864
+
3865
+ /**
3866
+ * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
3867
+ * @function
3868
+ * @param {!Long|number|string} other Other value
3869
+ * @returns {boolean}
3870
+ */
3871
+ LongPrototype.gte = LongPrototype.greaterThanOrEqual;
3872
+
3873
+ /**
3874
+ * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
3875
+ * @function
3876
+ * @param {!Long|number|string} other Other value
3877
+ * @returns {boolean}
3878
+ */
3879
+ LongPrototype.ge = LongPrototype.greaterThanOrEqual;
3880
+
3881
+ /**
3882
+ * Compares this Long's value with the specified's.
3883
+ * @this {!Long}
3884
+ * @param {!Long|number|string} other Other value
3885
+ * @returns {number} 0 if they are the same, 1 if the this is greater and -1
3886
+ * if the given one is greater
3887
+ */
3888
+ LongPrototype.compare = function compare(other) {
3889
+ if (!isLong(other))
3890
+ other = fromValue(other);
3891
+ if (this.eq(other))
3892
+ return 0;
3893
+ var thisNeg = this.isNegative(),
3894
+ otherNeg = other.isNegative();
3895
+ if (thisNeg && !otherNeg)
3896
+ return -1;
3897
+ if (!thisNeg && otherNeg)
3898
+ return 1;
3899
+ // At this point the sign bits are the same
3900
+ if (!this.unsigned)
3901
+ return this.sub(other).isNegative() ? -1 : 1;
3902
+ // Both are positive if at least one is unsigned
3903
+ return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
3904
+ };
3905
+
3906
+ /**
3907
+ * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.
3908
+ * @function
3909
+ * @param {!Long|number|string} other Other value
3910
+ * @returns {number} 0 if they are the same, 1 if the this is greater and -1
3911
+ * if the given one is greater
3912
+ */
3913
+ LongPrototype.comp = LongPrototype.compare;
3914
+
3915
+ /**
3916
+ * Negates this Long's value.
3917
+ * @this {!Long}
3918
+ * @returns {!Long} Negated Long
3919
+ */
3920
+ LongPrototype.negate = function negate() {
3921
+ if (!this.unsigned && this.eq(MIN_VALUE))
3922
+ return MIN_VALUE;
3923
+ return this.not().add(ONE);
3924
+ };
3925
+
3926
+ /**
3927
+ * Negates this Long's value. This is an alias of {@link Long#negate}.
3928
+ * @function
3929
+ * @returns {!Long} Negated Long
3930
+ */
3931
+ LongPrototype.neg = LongPrototype.negate;
3932
+
3933
+ /**
3934
+ * Returns the sum of this and the specified Long.
3935
+ * @this {!Long}
3936
+ * @param {!Long|number|string} addend Addend
3937
+ * @returns {!Long} Sum
3938
+ */
3939
+ LongPrototype.add = function add(addend) {
3940
+ if (!isLong(addend))
3941
+ addend = fromValue(addend);
3942
+
3943
+ // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
3944
+
3945
+ var a48 = this.high >>> 16;
3946
+ var a32 = this.high & 0xFFFF;
3947
+ var a16 = this.low >>> 16;
3948
+ var a00 = this.low & 0xFFFF;
3949
+
3950
+ var b48 = addend.high >>> 16;
3951
+ var b32 = addend.high & 0xFFFF;
3952
+ var b16 = addend.low >>> 16;
3953
+ var b00 = addend.low & 0xFFFF;
3954
+
3955
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
3956
+ c00 += a00 + b00;
3957
+ c16 += c00 >>> 16;
3958
+ c00 &= 0xFFFF;
3959
+ c16 += a16 + b16;
3960
+ c32 += c16 >>> 16;
3961
+ c16 &= 0xFFFF;
3962
+ c32 += a32 + b32;
3963
+ c48 += c32 >>> 16;
3964
+ c32 &= 0xFFFF;
3965
+ c48 += a48 + b48;
3966
+ c48 &= 0xFFFF;
3967
+ return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
3968
+ };
3969
+
3970
+ /**
3971
+ * Returns the difference of this and the specified Long.
3972
+ * @this {!Long}
3973
+ * @param {!Long|number|string} subtrahend Subtrahend
3974
+ * @returns {!Long} Difference
3975
+ */
3976
+ LongPrototype.subtract = function subtract(subtrahend) {
3977
+ if (!isLong(subtrahend))
3978
+ subtrahend = fromValue(subtrahend);
3979
+ return this.add(subtrahend.neg());
3980
+ };
3981
+
3982
+ /**
3983
+ * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.
3984
+ * @function
3985
+ * @param {!Long|number|string} subtrahend Subtrahend
3986
+ * @returns {!Long} Difference
3987
+ */
3988
+ LongPrototype.sub = LongPrototype.subtract;
3989
+
3990
+ /**
3991
+ * Returns the product of this and the specified Long.
3992
+ * @this {!Long}
3993
+ * @param {!Long|number|string} multiplier Multiplier
3994
+ * @returns {!Long} Product
3995
+ */
3996
+ LongPrototype.multiply = function multiply(multiplier) {
3997
+ if (this.isZero())
3998
+ return this;
3999
+ if (!isLong(multiplier))
4000
+ multiplier = fromValue(multiplier);
4001
+
4002
+ // use wasm support if present
4003
+ if (wasm) {
4004
+ var low = wasm["mul"](this.low,
4005
+ this.high,
4006
+ multiplier.low,
4007
+ multiplier.high);
4008
+ return fromBits(low, wasm["get_high"](), this.unsigned);
4009
+ }
4010
+
4011
+ if (multiplier.isZero())
4012
+ return this.unsigned ? UZERO : ZERO;
4013
+ if (this.eq(MIN_VALUE))
4014
+ return multiplier.isOdd() ? MIN_VALUE : ZERO;
4015
+ if (multiplier.eq(MIN_VALUE))
4016
+ return this.isOdd() ? MIN_VALUE : ZERO;
4017
+
4018
+ if (this.isNegative()) {
4019
+ if (multiplier.isNegative())
4020
+ return this.neg().mul(multiplier.neg());
4021
+ else
4022
+ return this.neg().mul(multiplier).neg();
4023
+ } else if (multiplier.isNegative())
4024
+ return this.mul(multiplier.neg()).neg();
4025
+
4026
+ // If both longs are small, use float multiplication
4027
+ if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
4028
+ return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
4029
+
4030
+ // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
4031
+ // We can skip products that would overflow.
4032
+
4033
+ var a48 = this.high >>> 16;
4034
+ var a32 = this.high & 0xFFFF;
4035
+ var a16 = this.low >>> 16;
4036
+ var a00 = this.low & 0xFFFF;
4037
+
4038
+ var b48 = multiplier.high >>> 16;
4039
+ var b32 = multiplier.high & 0xFFFF;
4040
+ var b16 = multiplier.low >>> 16;
4041
+ var b00 = multiplier.low & 0xFFFF;
4042
+
4043
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
4044
+ c00 += a00 * b00;
4045
+ c16 += c00 >>> 16;
4046
+ c00 &= 0xFFFF;
4047
+ c16 += a16 * b00;
4048
+ c32 += c16 >>> 16;
4049
+ c16 &= 0xFFFF;
4050
+ c16 += a00 * b16;
4051
+ c32 += c16 >>> 16;
4052
+ c16 &= 0xFFFF;
4053
+ c32 += a32 * b00;
4054
+ c48 += c32 >>> 16;
4055
+ c32 &= 0xFFFF;
4056
+ c32 += a16 * b16;
4057
+ c48 += c32 >>> 16;
4058
+ c32 &= 0xFFFF;
4059
+ c32 += a00 * b32;
4060
+ c48 += c32 >>> 16;
4061
+ c32 &= 0xFFFF;
4062
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
4063
+ c48 &= 0xFFFF;
4064
+ return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
4065
+ };
4066
+
4067
+ /**
4068
+ * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.
4069
+ * @function
4070
+ * @param {!Long|number|string} multiplier Multiplier
4071
+ * @returns {!Long} Product
4072
+ */
4073
+ LongPrototype.mul = LongPrototype.multiply;
4074
+
4075
+ /**
4076
+ * Returns this Long divided by the specified. The result is signed if this Long is signed or
4077
+ * unsigned if this Long is unsigned.
4078
+ * @this {!Long}
4079
+ * @param {!Long|number|string} divisor Divisor
4080
+ * @returns {!Long} Quotient
4081
+ */
4082
+ LongPrototype.divide = function divide(divisor) {
4083
+ if (!isLong(divisor))
4084
+ divisor = fromValue(divisor);
4085
+ if (divisor.isZero())
4086
+ throw Error('division by zero');
4087
+
4088
+ // use wasm support if present
4089
+ if (wasm) {
4090
+ // guard against signed division overflow: the largest
4091
+ // negative number / -1 would be 1 larger than the largest
4092
+ // positive number, due to two's complement.
4093
+ if (!this.unsigned &&
4094
+ this.high === -0x80000000 &&
4095
+ divisor.low === -1 && divisor.high === -1) {
4096
+ // be consistent with non-wasm code path
4097
+ return this;
4098
+ }
4099
+ var low = (this.unsigned ? wasm["div_u"] : wasm["div_s"])(
4100
+ this.low,
4101
+ this.high,
4102
+ divisor.low,
4103
+ divisor.high
4104
+ );
4105
+ return fromBits(low, wasm["get_high"](), this.unsigned);
4106
+ }
4107
+
4108
+ if (this.isZero())
4109
+ return this.unsigned ? UZERO : ZERO;
4110
+ var approx, rem, res;
4111
+ if (!this.unsigned) {
4112
+ // This section is only relevant for signed longs and is derived from the
4113
+ // closure library as a whole.
4114
+ if (this.eq(MIN_VALUE)) {
4115
+ if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
4116
+ return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
4117
+ else if (divisor.eq(MIN_VALUE))
4118
+ return ONE;
4119
+ else {
4120
+ // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
4121
+ var halfThis = this.shr(1);
4122
+ approx = halfThis.div(divisor).shl(1);
4123
+ if (approx.eq(ZERO)) {
4124
+ return divisor.isNegative() ? ONE : NEG_ONE;
4125
+ } else {
4126
+ rem = this.sub(divisor.mul(approx));
4127
+ res = approx.add(rem.div(divisor));
4128
+ return res;
4129
+ }
4130
+ }
4131
+ } else if (divisor.eq(MIN_VALUE))
4132
+ return this.unsigned ? UZERO : ZERO;
4133
+ if (this.isNegative()) {
4134
+ if (divisor.isNegative())
4135
+ return this.neg().div(divisor.neg());
4136
+ return this.neg().div(divisor).neg();
4137
+ } else if (divisor.isNegative())
4138
+ return this.div(divisor.neg()).neg();
4139
+ res = ZERO;
4140
+ } else {
4141
+ // The algorithm below has not been made for unsigned longs. It's therefore
4142
+ // required to take special care of the MSB prior to running it.
4143
+ if (!divisor.unsigned)
4144
+ divisor = divisor.toUnsigned();
4145
+ if (divisor.gt(this))
4146
+ return UZERO;
4147
+ if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
4148
+ return UONE;
4149
+ res = UZERO;
4150
+ }
4151
+
4152
+ // Repeat the following until the remainder is less than other: find a
4153
+ // floating-point that approximates remainder / other *from below*, add this
4154
+ // into the result, and subtract it from the remainder. It is critical that
4155
+ // the approximate value is less than or equal to the real value so that the
4156
+ // remainder never becomes negative.
4157
+ rem = this;
4158
+ while (rem.gte(divisor)) {
4159
+ // Approximate the result of division. This may be a little greater or
4160
+ // smaller than the actual value.
4161
+ approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
4162
+
4163
+ // We will tweak the approximate result by changing it in the 48-th digit or
4164
+ // the smallest non-fractional digit, whichever is larger.
4165
+ var log2 = Math.ceil(Math.log(approx) / Math.LN2),
4166
+ delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48),
4167
+
4168
+ // Decrease the approximation until it is smaller than the remainder. Note
4169
+ // that if it is too large, the product overflows and is negative.
4170
+ approxRes = fromNumber(approx),
4171
+ approxRem = approxRes.mul(divisor);
4172
+ while (approxRem.isNegative() || approxRem.gt(rem)) {
4173
+ approx -= delta;
4174
+ approxRes = fromNumber(approx, this.unsigned);
4175
+ approxRem = approxRes.mul(divisor);
4176
+ }
4177
+
4178
+ // We know the answer can't be zero... and actually, zero would cause
4179
+ // infinite recursion since we would make no progress.
4180
+ if (approxRes.isZero())
4181
+ approxRes = ONE;
4182
+
4183
+ res = res.add(approxRes);
4184
+ rem = rem.sub(approxRem);
4185
+ }
4186
+ return res;
4187
+ };
4188
+
4189
+ /**
4190
+ * Returns this Long divided by the specified. This is an alias of {@link Long#divide}.
4191
+ * @function
4192
+ * @param {!Long|number|string} divisor Divisor
4193
+ * @returns {!Long} Quotient
4194
+ */
4195
+ LongPrototype.div = LongPrototype.divide;
4196
+
4197
+ /**
4198
+ * Returns this Long modulo the specified.
4199
+ * @this {!Long}
4200
+ * @param {!Long|number|string} divisor Divisor
4201
+ * @returns {!Long} Remainder
4202
+ */
4203
+ LongPrototype.modulo = function modulo(divisor) {
4204
+ if (!isLong(divisor))
4205
+ divisor = fromValue(divisor);
4206
+
4207
+ // use wasm support if present
4208
+ if (wasm) {
4209
+ var low = (this.unsigned ? wasm["rem_u"] : wasm["rem_s"])(
4210
+ this.low,
4211
+ this.high,
4212
+ divisor.low,
4213
+ divisor.high
4214
+ );
4215
+ return fromBits(low, wasm["get_high"](), this.unsigned);
4216
+ }
4217
+
4218
+ return this.sub(this.div(divisor).mul(divisor));
4219
+ };
4220
+
4221
+ /**
4222
+ * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
4223
+ * @function
4224
+ * @param {!Long|number|string} divisor Divisor
4225
+ * @returns {!Long} Remainder
4226
+ */
4227
+ LongPrototype.mod = LongPrototype.modulo;
4228
+
4229
+ /**
4230
+ * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
4231
+ * @function
4232
+ * @param {!Long|number|string} divisor Divisor
4233
+ * @returns {!Long} Remainder
4234
+ */
4235
+ LongPrototype.rem = LongPrototype.modulo;
4236
+
4237
+ /**
4238
+ * Returns the bitwise NOT of this Long.
4239
+ * @this {!Long}
4240
+ * @returns {!Long}
4241
+ */
4242
+ LongPrototype.not = function not() {
4243
+ return fromBits(~this.low, ~this.high, this.unsigned);
4244
+ };
4245
+
4246
+ /**
4247
+ * Returns count leading zeros of this Long.
4248
+ * @this {!Long}
4249
+ * @returns {!number}
4250
+ */
4251
+ LongPrototype.countLeadingZeros = function countLeadingZeros() {
4252
+ return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32;
4253
+ };
4254
+
4255
+ /**
4256
+ * Returns count leading zeros. This is an alias of {@link Long#countLeadingZeros}.
4257
+ * @function
4258
+ * @param {!Long}
4259
+ * @returns {!number}
4260
+ */
4261
+ LongPrototype.clz = LongPrototype.countLeadingZeros;
4262
+
4263
+ /**
4264
+ * Returns count trailing zeros of this Long.
4265
+ * @this {!Long}
4266
+ * @returns {!number}
4267
+ */
4268
+ LongPrototype.countTrailingZeros = function countTrailingZeros() {
4269
+ return this.low ? ctz32(this.low) : ctz32(this.high) + 32;
4270
+ };
4271
+
4272
+ /**
4273
+ * Returns count trailing zeros. This is an alias of {@link Long#countTrailingZeros}.
4274
+ * @function
4275
+ * @param {!Long}
4276
+ * @returns {!number}
4277
+ */
4278
+ LongPrototype.ctz = LongPrototype.countTrailingZeros;
4279
+
4280
+ /**
4281
+ * Returns the bitwise AND of this Long and the specified.
4282
+ * @this {!Long}
4283
+ * @param {!Long|number|string} other Other Long
4284
+ * @returns {!Long}
4285
+ */
4286
+ LongPrototype.and = function and(other) {
4287
+ if (!isLong(other))
4288
+ other = fromValue(other);
4289
+ return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
4290
+ };
4291
+
4292
+ /**
4293
+ * Returns the bitwise OR of this Long and the specified.
4294
+ * @this {!Long}
4295
+ * @param {!Long|number|string} other Other Long
4296
+ * @returns {!Long}
4297
+ */
4298
+ LongPrototype.or = function or(other) {
4299
+ if (!isLong(other))
4300
+ other = fromValue(other);
4301
+ return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
4302
+ };
4303
+
4304
+ /**
4305
+ * Returns the bitwise XOR of this Long and the given one.
4306
+ * @this {!Long}
4307
+ * @param {!Long|number|string} other Other Long
4308
+ * @returns {!Long}
4309
+ */
4310
+ LongPrototype.xor = function xor(other) {
4311
+ if (!isLong(other))
4312
+ other = fromValue(other);
4313
+ return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
4314
+ };
4315
+
4316
+ /**
4317
+ * Returns this Long with bits shifted to the left by the given amount.
4318
+ * @this {!Long}
4319
+ * @param {number|!Long} numBits Number of bits
4320
+ * @returns {!Long} Shifted Long
4321
+ */
4322
+ LongPrototype.shiftLeft = function shiftLeft(numBits) {
4323
+ if (isLong(numBits))
4324
+ numBits = numBits.toInt();
4325
+ if ((numBits &= 63) === 0)
4326
+ return this;
4327
+ else if (numBits < 32)
4328
+ return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
4329
+ else
4330
+ return fromBits(0, this.low << (numBits - 32), this.unsigned);
4331
+ };
4332
+
4333
+ /**
4334
+ * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}.
4335
+ * @function
4336
+ * @param {number|!Long} numBits Number of bits
4337
+ * @returns {!Long} Shifted Long
4338
+ */
4339
+ LongPrototype.shl = LongPrototype.shiftLeft;
4340
+
4341
+ /**
4342
+ * Returns this Long with bits arithmetically shifted to the right by the given amount.
4343
+ * @this {!Long}
4344
+ * @param {number|!Long} numBits Number of bits
4345
+ * @returns {!Long} Shifted Long
4346
+ */
4347
+ LongPrototype.shiftRight = function shiftRight(numBits) {
4348
+ if (isLong(numBits))
4349
+ numBits = numBits.toInt();
4350
+ if ((numBits &= 63) === 0)
4351
+ return this;
4352
+ else if (numBits < 32)
4353
+ return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
4354
+ else
4355
+ return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
4356
+ };
4357
+
4358
+ /**
4359
+ * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}.
4360
+ * @function
4361
+ * @param {number|!Long} numBits Number of bits
4362
+ * @returns {!Long} Shifted Long
4363
+ */
4364
+ LongPrototype.shr = LongPrototype.shiftRight;
4365
+
4366
+ /**
4367
+ * Returns this Long with bits logically shifted to the right by the given amount.
4368
+ * @this {!Long}
4369
+ * @param {number|!Long} numBits Number of bits
4370
+ * @returns {!Long} Shifted Long
4371
+ */
4372
+ LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
4373
+ if (isLong(numBits)) numBits = numBits.toInt();
4374
+ if ((numBits &= 63) === 0) return this;
4375
+ if (numBits < 32) return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >>> numBits, this.unsigned);
4376
+ if (numBits === 32) return fromBits(this.high, 0, this.unsigned);
4377
+ return fromBits(this.high >>> (numBits - 32), 0, this.unsigned);
4378
+ };
4379
+
4380
+ /**
4381
+ * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
4382
+ * @function
4383
+ * @param {number|!Long} numBits Number of bits
4384
+ * @returns {!Long} Shifted Long
4385
+ */
4386
+ LongPrototype.shru = LongPrototype.shiftRightUnsigned;
4387
+
4388
+ /**
4389
+ * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
4390
+ * @function
4391
+ * @param {number|!Long} numBits Number of bits
4392
+ * @returns {!Long} Shifted Long
4393
+ */
4394
+ LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
4395
+
4396
+ /**
4397
+ * Returns this Long with bits rotated to the left by the given amount.
4398
+ * @this {!Long}
4399
+ * @param {number|!Long} numBits Number of bits
4400
+ * @returns {!Long} Rotated Long
4401
+ */
4402
+ LongPrototype.rotateLeft = function rotateLeft(numBits) {
4403
+ var b;
4404
+ if (isLong(numBits)) numBits = numBits.toInt();
4405
+ if ((numBits &= 63) === 0) return this;
4406
+ if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
4407
+ if (numBits < 32) {
4408
+ b = (32 - numBits);
4409
+ return fromBits(((this.low << numBits) | (this.high >>> b)), ((this.high << numBits) | (this.low >>> b)), this.unsigned);
4410
+ }
4411
+ numBits -= 32;
4412
+ b = (32 - numBits);
4413
+ return fromBits(((this.high << numBits) | (this.low >>> b)), ((this.low << numBits) | (this.high >>> b)), this.unsigned);
4414
+ };
4415
+ /**
4416
+ * Returns this Long with bits rotated to the left by the given amount. This is an alias of {@link Long#rotateLeft}.
4417
+ * @function
4418
+ * @param {number|!Long} numBits Number of bits
4419
+ * @returns {!Long} Rotated Long
4420
+ */
4421
+ LongPrototype.rotl = LongPrototype.rotateLeft;
4422
+
4423
+ /**
4424
+ * Returns this Long with bits rotated to the right by the given amount.
4425
+ * @this {!Long}
4426
+ * @param {number|!Long} numBits Number of bits
4427
+ * @returns {!Long} Rotated Long
4428
+ */
4429
+ LongPrototype.rotateRight = function rotateRight(numBits) {
4430
+ var b;
4431
+ if (isLong(numBits)) numBits = numBits.toInt();
4432
+ if ((numBits &= 63) === 0) return this;
4433
+ if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
4434
+ if (numBits < 32) {
4435
+ b = (32 - numBits);
4436
+ return fromBits(((this.high << b) | (this.low >>> numBits)), ((this.low << b) | (this.high >>> numBits)), this.unsigned);
4437
+ }
4438
+ numBits -= 32;
4439
+ b = (32 - numBits);
4440
+ return fromBits(((this.low << b) | (this.high >>> numBits)), ((this.high << b) | (this.low >>> numBits)), this.unsigned);
4441
+ };
4442
+ /**
4443
+ * Returns this Long with bits rotated to the right by the given amount. This is an alias of {@link Long#rotateRight}.
4444
+ * @function
4445
+ * @param {number|!Long} numBits Number of bits
4446
+ * @returns {!Long} Rotated Long
4447
+ */
4448
+ LongPrototype.rotr = LongPrototype.rotateRight;
4449
+
4450
+ /**
4451
+ * Converts this Long to signed.
4452
+ * @this {!Long}
4453
+ * @returns {!Long} Signed long
4454
+ */
4455
+ LongPrototype.toSigned = function toSigned() {
4456
+ if (!this.unsigned)
4457
+ return this;
4458
+ return fromBits(this.low, this.high, false);
4459
+ };
4460
+
4461
+ /**
4462
+ * Converts this Long to unsigned.
4463
+ * @this {!Long}
4464
+ * @returns {!Long} Unsigned long
4465
+ */
4466
+ LongPrototype.toUnsigned = function toUnsigned() {
4467
+ if (this.unsigned)
4468
+ return this;
4469
+ return fromBits(this.low, this.high, true);
4470
+ };
4471
+
4472
+ /**
4473
+ * Converts this Long to its byte representation.
4474
+ * @param {boolean=} le Whether little or big endian, defaults to big endian
4475
+ * @this {!Long}
4476
+ * @returns {!Array.<number>} Byte representation
4477
+ */
4478
+ LongPrototype.toBytes = function toBytes(le) {
4479
+ return le ? this.toBytesLE() : this.toBytesBE();
4480
+ };
4481
+
4482
+ /**
4483
+ * Converts this Long to its little endian byte representation.
4484
+ * @this {!Long}
4485
+ * @returns {!Array.<number>} Little endian byte representation
4486
+ */
4487
+ LongPrototype.toBytesLE = function toBytesLE() {
4488
+ var hi = this.high,
4489
+ lo = this.low;
4490
+ return [
4491
+ lo & 0xff,
4492
+ lo >>> 8 & 0xff,
4493
+ lo >>> 16 & 0xff,
4494
+ lo >>> 24,
4495
+ hi & 0xff,
4496
+ hi >>> 8 & 0xff,
4497
+ hi >>> 16 & 0xff,
4498
+ hi >>> 24
4499
+ ];
4500
+ };
4501
+
4502
+ /**
4503
+ * Converts this Long to its big endian byte representation.
4504
+ * @this {!Long}
4505
+ * @returns {!Array.<number>} Big endian byte representation
4506
+ */
4507
+ LongPrototype.toBytesBE = function toBytesBE() {
4508
+ var hi = this.high,
4509
+ lo = this.low;
4510
+ return [
4511
+ hi >>> 24,
4512
+ hi >>> 16 & 0xff,
4513
+ hi >>> 8 & 0xff,
4514
+ hi & 0xff,
4515
+ lo >>> 24,
4516
+ lo >>> 16 & 0xff,
4517
+ lo >>> 8 & 0xff,
4518
+ lo & 0xff
4519
+ ];
4520
+ };
4521
+
4522
+ /**
4523
+ * Creates a Long from its byte representation.
4524
+ * @param {!Array.<number>} bytes Byte representation
4525
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
4526
+ * @param {boolean=} le Whether little or big endian, defaults to big endian
4527
+ * @returns {Long} The corresponding Long value
4528
+ */
4529
+ Long.fromBytes = function fromBytes(bytes, unsigned, le) {
4530
+ return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
4531
+ };
4532
+
4533
+ /**
4534
+ * Creates a Long from its little endian byte representation.
4535
+ * @param {!Array.<number>} bytes Little endian byte representation
4536
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
4537
+ * @returns {Long} The corresponding Long value
4538
+ */
4539
+ Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
4540
+ return new Long(
4541
+ bytes[0] |
4542
+ bytes[1] << 8 |
4543
+ bytes[2] << 16 |
4544
+ bytes[3] << 24,
4545
+ bytes[4] |
4546
+ bytes[5] << 8 |
4547
+ bytes[6] << 16 |
4548
+ bytes[7] << 24,
4549
+ unsigned
4550
+ );
4551
+ };
4552
+
4553
+ /**
4554
+ * Creates a Long from its big endian byte representation.
4555
+ * @param {!Array.<number>} bytes Big endian byte representation
4556
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
4557
+ * @returns {Long} The corresponding Long value
4558
+ */
4559
+ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
4560
+ return new Long(
4561
+ bytes[4] << 24 |
4562
+ bytes[5] << 16 |
4563
+ bytes[6] << 8 |
4564
+ bytes[7],
4565
+ bytes[0] << 24 |
4566
+ bytes[1] << 16 |
4567
+ bytes[2] << 8 |
4568
+ bytes[3],
4569
+ unsigned
4570
+ );
4571
+ };
4572
+
3107
4573
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
3108
4574
  // require the crypto API and do not support built-in fallback to lower quality random number
3109
4575
  // generators (like Math.random()).
@@ -3158,103 +4624,78 @@ function stringify(arr) {
3158
4624
  return uuid;
3159
4625
  }
3160
4626
 
3161
- //
3162
- // Inspired by https://github.com/LiosK/UUID.js
3163
- // and http://docs.python.org/library/uuid.html
3164
-
3165
- var _nodeId;
3166
-
3167
- var _clockseq; // Previous uuid creation time
3168
-
3169
-
3170
- var _lastMSecs = 0;
3171
- var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
3172
-
3173
- function v1(options, buf, offset) {
3174
- var i = buf && offset || 0;
3175
- var b = buf || new Array(16);
3176
- options = options || {};
3177
- var node = options.node || _nodeId;
3178
- var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
3179
- // specified. We do this lazily to minimize issues related to insufficient
3180
- // system entropy. See #189
3181
-
3182
- if (node == null || clockseq == null) {
3183
- var seedBytes = options.random || (options.rng || rng)();
3184
-
3185
- if (node == null) {
3186
- // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
3187
- node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
3188
- }
3189
-
3190
- if (clockseq == null) {
3191
- // Per 4.2.2, randomize (14 bit) clockseq
3192
- clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
3193
- }
3194
- } // UUID timestamps are 100 nano-second units since the Gregorian epoch,
3195
- // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
3196
- // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
3197
- // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
3198
-
3199
-
3200
- var msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
3201
- // cycle to simulate higher resolution clock
3202
-
3203
- var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
3204
-
3205
- var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
3206
-
3207
- if (dt < 0 && options.clockseq === undefined) {
3208
- clockseq = clockseq + 1 & 0x3fff;
3209
- } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
3210
- // time interval
3211
-
3212
-
3213
- if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
3214
- nsecs = 0;
3215
- } // Per 4.2.1.2 Throw error if too many uuids are requested
4627
+ function parse(uuid) {
4628
+ if (!validate(uuid)) {
4629
+ throw TypeError('Invalid UUID');
4630
+ }
3216
4631
 
4632
+ var v;
4633
+ var arr = new Uint8Array(16); // Parse ########-....-....-....-............
3217
4634
 
3218
- if (nsecs >= 10000) {
3219
- throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
3220
- }
4635
+ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
4636
+ arr[1] = v >>> 16 & 0xff;
4637
+ arr[2] = v >>> 8 & 0xff;
4638
+ arr[3] = v & 0xff; // Parse ........-####-....-....-............
3221
4639
 
3222
- _lastMSecs = msecs;
3223
- _lastNSecs = nsecs;
3224
- _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
4640
+ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
4641
+ arr[5] = v & 0xff; // Parse ........-....-####-....-............
3225
4642
 
3226
- msecs += 12219292800000; // `time_low`
4643
+ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
4644
+ arr[7] = v & 0xff; // Parse ........-....-....-####-............
3227
4645
 
3228
- var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
3229
- b[i++] = tl >>> 24 & 0xff;
3230
- b[i++] = tl >>> 16 & 0xff;
3231
- b[i++] = tl >>> 8 & 0xff;
3232
- b[i++] = tl & 0xff; // `time_mid`
4646
+ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
4647
+ arr[9] = v & 0xff; // Parse ........-....-....-....-############
4648
+ // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
3233
4649
 
3234
- var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
3235
- b[i++] = tmh >>> 8 & 0xff;
3236
- b[i++] = tmh & 0xff; // `time_high_and_version`
4650
+ arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
4651
+ arr[11] = v / 0x100000000 & 0xff;
4652
+ arr[12] = v >>> 24 & 0xff;
4653
+ arr[13] = v >>> 16 & 0xff;
4654
+ arr[14] = v >>> 8 & 0xff;
4655
+ arr[15] = v & 0xff;
4656
+ return arr;
4657
+ }
3237
4658
 
3238
- b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
4659
+ function v4(options, buf, offset) {
4660
+ options = options || {};
4661
+ var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
3239
4662
 
3240
- b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
4663
+ rnds[6] = rnds[6] & 0x0f | 0x40;
4664
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
3241
4665
 
3242
- b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
4666
+ if (buf) {
4667
+ offset = offset || 0;
3243
4668
 
3244
- b[i++] = clockseq & 0xff; // `node`
4669
+ for (var i = 0; i < 16; ++i) {
4670
+ buf[offset + i] = rnds[i];
4671
+ }
3245
4672
 
3246
- for (var n = 0; n < 6; ++n) {
3247
- b[i + n] = node[n];
4673
+ return buf;
3248
4674
  }
3249
4675
 
3250
- return buf || stringify(b);
4676
+ return stringify(rnds);
3251
4677
  }
3252
4678
 
3253
- var create = function () { return v1(); };
4679
+ function create() {
4680
+ return v4();
4681
+ }
4682
+ function toMsbLsb(id) {
4683
+ var bytes = parse(id);
4684
+ var msb = Long.fromInt(0);
4685
+ var lsb = Long.fromInt(0);
4686
+ for (var i = 0; i < 8; i++) {
4687
+ msb = msb.shiftLeft(8).or(bytes[i] & 0xff);
4688
+ }
4689
+ for (var i = 8; i < 16; i++) {
4690
+ lsb = lsb.shiftLeft(8).or(bytes[i] & 0xff);
4691
+ }
4692
+ return { msb: msb.toString(), lsb: lsb.toString() };
4693
+ }
3254
4694
 
3255
4695
  var uuid = /*#__PURE__*/Object.freeze({
3256
4696
  __proto__: null,
3257
- create: create
4697
+ create: create,
4698
+ toMsbLsb: toMsbLsb
3258
4699
  });
3259
4700
 
3260
4701
  var EventDispatcher = /** @class */ (function () {