@vicin/sigil 2.2.1 → 3.1.0

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.
@@ -1,14 +1,9 @@
1
1
  (function (exports) {
2
2
  'use strict';
3
3
 
4
- var __defProp = Object.defineProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
-
8
- // src/core/options.ts
4
+ // src/options.ts
9
5
  var OPTIONS = {
10
6
  labelValidation: null,
11
- skipLabelInheritanceCheck: false,
12
7
  autofillLabels: true
13
8
  };
14
9
  var updateSigilOptions = (opts) => {
@@ -17,11 +12,6 @@
17
12
  throw new Error("'updateSigilOptions.autofillLabels' must be boolean");
18
13
  OPTIONS.autofillLabels = opts.autofillLabels;
19
14
  }
20
- if ("skipLabelInheritanceCheck" in opts) {
21
- if (typeof opts.skipLabelInheritanceCheck !== "boolean")
22
- throw new Error("'updateSigilOptions.skipLabelInheritanceCheck' must be boolean");
23
- OPTIONS.skipLabelInheritanceCheck = opts.skipLabelInheritanceCheck;
24
- }
25
15
  if ("labelValidation" in opts) {
26
16
  const val = opts.labelValidation;
27
17
  if (val !== null && typeof val !== "function" && !(val instanceof RegExp))
@@ -31,1927 +21,191 @@
31
21
  };
32
22
  var DEFAULT_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
33
23
 
34
- // src/core/symbols.ts
35
- var __SIGIL__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL__");
36
- var __SIGIL_BASE__ = /* @__PURE__ */ Symbol.for("@Sigil.__SIGIL_BASE__");
37
- var __DECORATED__ = /* @__PURE__ */ Symbol.for("@Sigil.__DECORATED__");
38
- var __INHERITANCE_CHECKED__ = /* @__PURE__ */ Symbol.for("@Sigil.__INHERITANCE_CHECKED__");
39
- var __LABEL__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL__");
40
- var __EFFECTIVE_LABEL__ = /* @__PURE__ */ Symbol.for("@Sigil.__EFFECTIVE_LABEL__");
41
- var __LABEL_LINEAGE__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL_LINEAGE__");
42
- var __LABEL_SET__ = /* @__PURE__ */ Symbol.for("@Sigil.__LABEL_SET__");
43
-
44
- // node_modules/@noble/hashes/_u64.js
45
- var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
46
- var _32n = /* @__PURE__ */ BigInt(32);
47
- function fromBig(n, le = false) {
48
- if (le)
49
- return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
50
- return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
51
- }
52
- function split(lst, le = false) {
53
- const len = lst.length;
54
- let Ah = new Uint32Array(len);
55
- let Al = new Uint32Array(len);
56
- for (let i = 0; i < len; i++) {
57
- const { h, l } = fromBig(lst[i], le);
58
- [Ah[i], Al[i]] = [h, l];
59
- }
60
- return [Ah, Al];
61
- }
62
- var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
63
- var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
64
- var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
65
- var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
66
-
67
- // node_modules/@noble/hashes/utils.js
68
- function isBytes(a) {
69
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
70
- }
71
- function anumber(n, title = "") {
72
- if (!Number.isSafeInteger(n) || n < 0) {
73
- const prefix = title && `"${title}" `;
74
- throw new Error(`${prefix}expected integer >= 0, got ${n}`);
75
- }
76
- }
77
- function abytes(value, length, title = "") {
78
- const bytes = isBytes(value);
79
- const len = value == null ? void 0 : value.length;
80
- const needsLen = length !== void 0;
81
- if (!bytes || needsLen) {
82
- const prefix = title && `"${title}" `;
83
- const ofLen = "";
84
- const got = bytes ? `length=${len}` : `type=${typeof value}`;
85
- throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
86
- }
87
- return value;
88
- }
89
- function aexists(instance, checkFinished = true) {
90
- if (instance.destroyed)
91
- throw new Error("Hash instance has been destroyed");
92
- if (checkFinished && instance.finished)
93
- throw new Error("Hash#digest() has already been called");
94
- }
95
- function aoutput(out, instance) {
96
- abytes(out, void 0, "digestInto() output");
97
- const min = instance.outputLen;
98
- if (out.length < min) {
99
- throw new Error('"digestInto() output" expected to be of length >=' + min);
100
- }
101
- }
102
- function u32(arr) {
103
- return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
104
- }
105
- function clean(...arrays) {
106
- for (let i = 0; i < arrays.length; i++) {
107
- arrays[i].fill(0);
108
- }
109
- }
110
- var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
111
- function byteSwap(word) {
112
- return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
113
- }
114
- function byteSwap32(arr) {
115
- for (let i = 0; i < arr.length; i++) {
116
- arr[i] = byteSwap(arr[i]);
117
- }
118
- return arr;
119
- }
120
- var swap32IfBE = isLE ? (u) => u : byteSwap32;
121
- function createHasher(hashCons, info = {}) {
122
- const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
123
- const tmp = hashCons(void 0);
124
- hashC.outputLen = tmp.outputLen;
125
- hashC.blockLen = tmp.blockLen;
126
- hashC.create = (opts) => hashCons(opts);
127
- Object.assign(hashC, info);
128
- return Object.freeze(hashC);
129
- }
130
- var oidNist = (suffix) => ({
131
- oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
132
- });
24
+ // src/symbols.ts
25
+ var __SIGIL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL__");
26
+ var __LABEL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__LABEL__");
27
+ var __EFFECTIVE_LABEL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__EFFECTIVE_LABEL__");
28
+ var __LINEAGE__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__LINEAGE__");
133
29
 
134
- // node_modules/@noble/hashes/sha3.js
135
- var _0n = BigInt(0);
136
- var _1n = BigInt(1);
137
- var _2n = BigInt(2);
138
- var _7n = BigInt(7);
139
- var _256n = BigInt(256);
140
- var _0x71n = BigInt(113);
141
- var SHA3_PI = [];
142
- var SHA3_ROTL = [];
143
- var _SHA3_IOTA = [];
144
- for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
145
- [x, y] = [y, (2 * x + 3 * y) % 5];
146
- SHA3_PI.push(2 * (5 * y + x));
147
- SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
148
- let t = _0n;
149
- for (let j = 0; j < 7; j++) {
150
- R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
151
- if (R & _2n)
152
- t ^= _1n << (_1n << BigInt(j)) - _1n;
153
- }
154
- _SHA3_IOTA.push(t);
155
- }
156
- var IOTAS = split(_SHA3_IOTA, true);
157
- var SHA3_IOTA_H = IOTAS[0];
158
- var SHA3_IOTA_L = IOTAS[1];
159
- var rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
160
- var rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
161
- function keccakP(s, rounds = 24) {
162
- const B = new Uint32Array(5 * 2);
163
- for (let round = 24 - rounds; round < 24; round++) {
164
- for (let x = 0; x < 10; x++)
165
- B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
166
- for (let x = 0; x < 10; x += 2) {
167
- const idx1 = (x + 8) % 10;
168
- const idx0 = (x + 2) % 10;
169
- const B0 = B[idx0];
170
- const B1 = B[idx0 + 1];
171
- const Th = rotlH(B0, B1, 1) ^ B[idx1];
172
- const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
173
- for (let y = 0; y < 50; y += 10) {
174
- s[x + y] ^= Th;
175
- s[x + y + 1] ^= Tl;
176
- }
177
- }
178
- let curH = s[2];
179
- let curL = s[3];
180
- for (let t = 0; t < 24; t++) {
181
- const shift = SHA3_ROTL[t];
182
- const Th = rotlH(curH, curL, shift);
183
- const Tl = rotlL(curH, curL, shift);
184
- const PI = SHA3_PI[t];
185
- curH = s[PI];
186
- curL = s[PI + 1];
187
- s[PI] = Th;
188
- s[PI + 1] = Tl;
189
- }
190
- for (let y = 0; y < 50; y += 10) {
191
- for (let x = 0; x < 10; x++)
192
- B[x] = s[y + x];
193
- for (let x = 0; x < 10; x++)
194
- s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
195
- }
196
- s[0] ^= SHA3_IOTA_H[round];
197
- s[1] ^= SHA3_IOTA_L[round];
198
- }
199
- clean(B);
200
- }
201
- var Keccak = class _Keccak {
202
- // NOTE: we accept arguments in bytes instead of bits here.
203
- constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
204
- __publicField(this, "state");
205
- __publicField(this, "pos", 0);
206
- __publicField(this, "posOut", 0);
207
- __publicField(this, "finished", false);
208
- __publicField(this, "state32");
209
- __publicField(this, "destroyed", false);
210
- __publicField(this, "blockLen");
211
- __publicField(this, "suffix");
212
- __publicField(this, "outputLen");
213
- __publicField(this, "enableXOF", false);
214
- __publicField(this, "rounds");
215
- this.blockLen = blockLen;
216
- this.suffix = suffix;
217
- this.outputLen = outputLen;
218
- this.enableXOF = enableXOF;
219
- this.rounds = rounds;
220
- anumber(outputLen, "outputLen");
221
- if (!(0 < blockLen && blockLen < 200))
222
- throw new Error("only keccak-f1600 function is supported");
223
- this.state = new Uint8Array(200);
224
- this.state32 = u32(this.state);
225
- }
226
- clone() {
227
- return this._cloneInto();
228
- }
229
- keccak() {
230
- swap32IfBE(this.state32);
231
- keccakP(this.state32, this.rounds);
232
- swap32IfBE(this.state32);
233
- this.posOut = 0;
234
- this.pos = 0;
235
- }
236
- update(data) {
237
- aexists(this);
238
- abytes(data);
239
- const { blockLen, state } = this;
240
- const len = data.length;
241
- for (let pos = 0; pos < len; ) {
242
- const take = Math.min(blockLen - this.pos, len - pos);
243
- for (let i = 0; i < take; i++)
244
- state[this.pos++] ^= data[pos++];
245
- if (this.pos === blockLen)
246
- this.keccak();
247
- }
248
- return this;
249
- }
250
- finish() {
251
- if (this.finished)
252
- return;
253
- this.finished = true;
254
- const { state, suffix, pos, blockLen } = this;
255
- state[pos] ^= suffix;
256
- if ((suffix & 128) !== 0 && pos === blockLen - 1)
257
- this.keccak();
258
- state[blockLen - 1] ^= 128;
259
- this.keccak();
260
- }
261
- writeInto(out) {
262
- aexists(this, false);
263
- abytes(out);
264
- this.finish();
265
- const bufferOut = this.state;
266
- const { blockLen } = this;
267
- for (let pos = 0, len = out.length; pos < len; ) {
268
- if (this.posOut >= blockLen)
269
- this.keccak();
270
- const take = Math.min(blockLen - this.posOut, len - pos);
271
- out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
272
- this.posOut += take;
273
- pos += take;
274
- }
275
- return out;
276
- }
277
- xofInto(out) {
278
- if (!this.enableXOF)
279
- throw new Error("XOF is not possible for this instance");
280
- return this.writeInto(out);
281
- }
282
- xof(bytes) {
283
- anumber(bytes);
284
- return this.xofInto(new Uint8Array(bytes));
285
- }
286
- digestInto(out) {
287
- aoutput(out, this);
288
- if (this.finished)
289
- throw new Error("digest() was already called");
290
- this.writeInto(out);
291
- this.destroy();
292
- return out;
293
- }
294
- digest() {
295
- return this.digestInto(new Uint8Array(this.outputLen));
296
- }
297
- destroy() {
298
- this.destroyed = true;
299
- clean(this.state);
300
- }
301
- _cloneInto(to) {
302
- const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
303
- to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
304
- to.state32.set(this.state32);
305
- to.pos = this.pos;
306
- to.posOut = this.posOut;
307
- to.finished = this.finished;
308
- to.rounds = rounds;
309
- to.suffix = suffix;
310
- to.outputLen = outputLen;
311
- to.enableXOF = enableXOF;
312
- to.destroyed = this.destroyed;
313
- return to;
314
- }
315
- };
316
- var genKeccak = (suffix, blockLen, outputLen, info = {}) => createHasher(() => new Keccak(blockLen, suffix, outputLen), info);
317
- var sha3_512 = /* @__PURE__ */ genKeccak(
318
- 6,
319
- 72,
320
- 64,
321
- /* @__PURE__ */ oidNist(10)
322
- );
323
-
324
- // node_modules/bignumber.js/bignumber.mjs
325
- var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
326
- var mathceil = Math.ceil;
327
- var mathfloor = Math.floor;
328
- var bignumberError = "[BigNumber Error] ";
329
- var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
330
- var BASE = 1e14;
331
- var LOG_BASE = 14;
332
- var MAX_SAFE_INTEGER = 9007199254740991;
333
- var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
334
- var SQRT_BASE = 1e7;
335
- var MAX = 1e9;
336
- function clone(configObject) {
337
- var div, convertBase, parseNumeric, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
338
- prefix: "",
339
- groupSize: 3,
340
- secondaryGroupSize: 0,
341
- groupSeparator: ",",
342
- decimalSeparator: ".",
343
- fractionGroupSize: 0,
344
- fractionGroupSeparator: "\xA0",
345
- // non-breaking space
346
- suffix: ""
347
- }, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
348
- function BigNumber2(v, b) {
349
- var alphabet2, c, caseChanged, e, i, isNum, len, str, x = this;
350
- if (!(x instanceof BigNumber2)) return new BigNumber2(v, b);
351
- if (b == null) {
352
- if (v && v._isBigNumber === true) {
353
- x.s = v.s;
354
- if (!v.c || v.e > MAX_EXP) {
355
- x.c = x.e = null;
356
- } else if (v.e < MIN_EXP) {
357
- x.c = [x.e = 0];
358
- } else {
359
- x.e = v.e;
360
- x.c = v.c.slice();
361
- }
362
- return;
363
- }
364
- if ((isNum = typeof v == "number") && v * 0 == 0) {
365
- x.s = 1 / v < 0 ? (v = -v, -1) : 1;
366
- if (v === ~~v) {
367
- for (e = 0, i = v; i >= 10; i /= 10, e++) ;
368
- if (e > MAX_EXP) {
369
- x.c = x.e = null;
370
- } else {
371
- x.e = e;
372
- x.c = [v];
373
- }
374
- return;
375
- }
376
- str = String(v);
377
- } else {
378
- if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
379
- x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
380
- }
381
- if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
382
- if ((i = str.search(/e/i)) > 0) {
383
- if (e < 0) e = i;
384
- e += +str.slice(i + 1);
385
- str = str.substring(0, i);
386
- } else if (e < 0) {
387
- e = str.length;
388
- }
389
- } else {
390
- intCheck(b, 2, ALPHABET.length, "Base");
391
- if (b == 10 && alphabetHasNormalDecimalDigits) {
392
- x = new BigNumber2(v);
393
- return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
394
- }
395
- str = String(v);
396
- if (isNum = typeof v == "number") {
397
- if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
398
- x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
399
- if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
400
- throw Error(tooManyDigits + v);
401
- }
402
- } else {
403
- x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
404
- }
405
- alphabet2 = ALPHABET.slice(0, b);
406
- e = i = 0;
407
- for (len = str.length; i < len; i++) {
408
- if (alphabet2.indexOf(c = str.charAt(i)) < 0) {
409
- if (c == ".") {
410
- if (i > e) {
411
- e = len;
412
- continue;
413
- }
414
- } else if (!caseChanged) {
415
- if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
416
- caseChanged = true;
417
- i = -1;
418
- e = 0;
419
- continue;
420
- }
421
- }
422
- return parseNumeric(x, String(v), isNum, b);
423
- }
424
- }
425
- isNum = false;
426
- str = convertBase(str, b, 10, x.s);
427
- if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
428
- else e = str.length;
429
- }
430
- for (i = 0; str.charCodeAt(i) === 48; i++) ;
431
- for (len = str.length; str.charCodeAt(--len) === 48; ) ;
432
- if (str = str.slice(i, ++len)) {
433
- len -= i;
434
- if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
435
- throw Error(tooManyDigits + x.s * v);
436
- }
437
- if ((e = e - i - 1) > MAX_EXP) {
438
- x.c = x.e = null;
439
- } else if (e < MIN_EXP) {
440
- x.c = [x.e = 0];
441
- } else {
442
- x.e = e;
443
- x.c = [];
444
- i = (e + 1) % LOG_BASE;
445
- if (e < 0) i += LOG_BASE;
446
- if (i < len) {
447
- if (i) x.c.push(+str.slice(0, i));
448
- for (len -= LOG_BASE; i < len; ) {
449
- x.c.push(+str.slice(i, i += LOG_BASE));
450
- }
451
- i = LOG_BASE - (str = str.slice(i)).length;
452
- } else {
453
- i -= len;
454
- }
455
- for (; i--; str += "0") ;
456
- x.c.push(+str);
457
- }
458
- } else {
459
- x.c = [x.e = 0];
460
- }
461
- }
462
- BigNumber2.clone = clone;
463
- BigNumber2.ROUND_UP = 0;
464
- BigNumber2.ROUND_DOWN = 1;
465
- BigNumber2.ROUND_CEIL = 2;
466
- BigNumber2.ROUND_FLOOR = 3;
467
- BigNumber2.ROUND_HALF_UP = 4;
468
- BigNumber2.ROUND_HALF_DOWN = 5;
469
- BigNumber2.ROUND_HALF_EVEN = 6;
470
- BigNumber2.ROUND_HALF_CEIL = 7;
471
- BigNumber2.ROUND_HALF_FLOOR = 8;
472
- BigNumber2.EUCLID = 9;
473
- BigNumber2.config = BigNumber2.set = function(obj) {
474
- var p, v;
475
- if (obj != null) {
476
- if (typeof obj == "object") {
477
- if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
478
- v = obj[p];
479
- intCheck(v, 0, MAX, p);
480
- DECIMAL_PLACES = v;
481
- }
482
- if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
483
- v = obj[p];
484
- intCheck(v, 0, 8, p);
485
- ROUNDING_MODE = v;
486
- }
487
- if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
488
- v = obj[p];
489
- if (v && v.pop) {
490
- intCheck(v[0], -MAX, 0, p);
491
- intCheck(v[1], 0, MAX, p);
492
- TO_EXP_NEG = v[0];
493
- TO_EXP_POS = v[1];
494
- } else {
495
- intCheck(v, -MAX, MAX, p);
496
- TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
497
- }
498
- }
499
- if (obj.hasOwnProperty(p = "RANGE")) {
500
- v = obj[p];
501
- if (v && v.pop) {
502
- intCheck(v[0], -MAX, -1, p);
503
- intCheck(v[1], 1, MAX, p);
504
- MIN_EXP = v[0];
505
- MAX_EXP = v[1];
506
- } else {
507
- intCheck(v, -MAX, MAX, p);
508
- if (v) {
509
- MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
510
- } else {
511
- throw Error(bignumberError + p + " cannot be zero: " + v);
512
- }
513
- }
514
- }
515
- if (obj.hasOwnProperty(p = "CRYPTO")) {
516
- v = obj[p];
517
- if (v === !!v) {
518
- if (v) {
519
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
520
- CRYPTO = v;
521
- } else {
522
- CRYPTO = !v;
523
- throw Error(bignumberError + "crypto unavailable");
524
- }
525
- } else {
526
- CRYPTO = v;
527
- }
528
- } else {
529
- throw Error(bignumberError + p + " not true or false: " + v);
530
- }
531
- }
532
- if (obj.hasOwnProperty(p = "MODULO_MODE")) {
533
- v = obj[p];
534
- intCheck(v, 0, 9, p);
535
- MODULO_MODE = v;
536
- }
537
- if (obj.hasOwnProperty(p = "POW_PRECISION")) {
538
- v = obj[p];
539
- intCheck(v, 0, MAX, p);
540
- POW_PRECISION = v;
541
- }
542
- if (obj.hasOwnProperty(p = "FORMAT")) {
543
- v = obj[p];
544
- if (typeof v == "object") FORMAT = v;
545
- else throw Error(bignumberError + p + " not an object: " + v);
546
- }
547
- if (obj.hasOwnProperty(p = "ALPHABET")) {
548
- v = obj[p];
549
- if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
550
- alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
551
- ALPHABET = v;
552
- } else {
553
- throw Error(bignumberError + p + " invalid: " + v);
554
- }
555
- }
556
- } else {
557
- throw Error(bignumberError + "Object expected: " + obj);
558
- }
559
- }
560
- return {
561
- DECIMAL_PLACES,
562
- ROUNDING_MODE,
563
- EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
564
- RANGE: [MIN_EXP, MAX_EXP],
565
- CRYPTO,
566
- MODULO_MODE,
567
- POW_PRECISION,
568
- FORMAT,
569
- ALPHABET
570
- };
571
- };
572
- BigNumber2.isBigNumber = function(v) {
573
- if (!v || v._isBigNumber !== true) return false;
574
- if (!BigNumber2.DEBUG) return true;
575
- var i, n, c = v.c, e = v.e, s = v.s;
576
- out: if ({}.toString.call(c) == "[object Array]") {
577
- if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
578
- if (c[0] === 0) {
579
- if (e === 0 && c.length === 1) return true;
580
- break out;
581
- }
582
- i = (e + 1) % LOG_BASE;
583
- if (i < 1) i += LOG_BASE;
584
- if (String(c[0]).length == i) {
585
- for (i = 0; i < c.length; i++) {
586
- n = c[i];
587
- if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
588
- }
589
- if (n !== 0) return true;
590
- }
591
- }
592
- } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
593
- return true;
594
- }
595
- throw Error(bignumberError + "Invalid BigNumber: " + v);
596
- };
597
- BigNumber2.maximum = BigNumber2.max = function() {
598
- return maxOrMin(arguments, -1);
599
- };
600
- BigNumber2.minimum = BigNumber2.min = function() {
601
- return maxOrMin(arguments, 1);
602
- };
603
- BigNumber2.random = (function() {
604
- var pow2_53 = 9007199254740992;
605
- var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
606
- return mathfloor(Math.random() * pow2_53);
607
- } : function() {
608
- return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
609
- };
610
- return function(dp) {
611
- var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
612
- if (dp == null) dp = DECIMAL_PLACES;
613
- else intCheck(dp, 0, MAX);
614
- k = mathceil(dp / LOG_BASE);
615
- if (CRYPTO) {
616
- if (crypto.getRandomValues) {
617
- a = crypto.getRandomValues(new Uint32Array(k *= 2));
618
- for (; i < k; ) {
619
- v = a[i] * 131072 + (a[i + 1] >>> 11);
620
- if (v >= 9e15) {
621
- b = crypto.getRandomValues(new Uint32Array(2));
622
- a[i] = b[0];
623
- a[i + 1] = b[1];
624
- } else {
625
- c.push(v % 1e14);
626
- i += 2;
627
- }
628
- }
629
- i = k / 2;
630
- } else if (crypto.randomBytes) {
631
- a = crypto.randomBytes(k *= 7);
632
- for (; i < k; ) {
633
- v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
634
- if (v >= 9e15) {
635
- crypto.randomBytes(7).copy(a, i);
636
- } else {
637
- c.push(v % 1e14);
638
- i += 7;
639
- }
640
- }
641
- i = k / 7;
642
- } else {
643
- CRYPTO = false;
644
- throw Error(bignumberError + "crypto unavailable");
645
- }
646
- }
647
- if (!CRYPTO) {
648
- for (; i < k; ) {
649
- v = random53bitInt();
650
- if (v < 9e15) c[i++] = v % 1e14;
651
- }
652
- }
653
- k = c[--i];
654
- dp %= LOG_BASE;
655
- if (k && dp) {
656
- v = POWS_TEN[LOG_BASE - dp];
657
- c[i] = mathfloor(k / v) * v;
658
- }
659
- for (; c[i] === 0; c.pop(), i--) ;
660
- if (i < 0) {
661
- c = [e = 0];
662
- } else {
663
- for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE) ;
664
- for (i = 1, v = c[0]; v >= 10; v /= 10, i++) ;
665
- if (i < LOG_BASE) e -= LOG_BASE - i;
666
- }
667
- rand.e = e;
668
- rand.c = c;
669
- return rand;
670
- };
671
- })();
672
- BigNumber2.sum = function() {
673
- var i = 1, args = arguments, sum = new BigNumber2(args[0]);
674
- for (; i < args.length; ) sum = sum.plus(args[i++]);
675
- return sum;
676
- };
677
- convertBase = /* @__PURE__ */ (function() {
678
- var decimal = "0123456789";
679
- function toBaseOut(str, baseIn, baseOut, alphabet2) {
680
- var j, arr = [0], arrL, i = 0, len = str.length;
681
- for (; i < len; ) {
682
- for (arrL = arr.length; arrL--; arr[arrL] *= baseIn) ;
683
- arr[0] += alphabet2.indexOf(str.charAt(i++));
684
- for (j = 0; j < arr.length; j++) {
685
- if (arr[j] > baseOut - 1) {
686
- if (arr[j + 1] == null) arr[j + 1] = 0;
687
- arr[j + 1] += arr[j] / baseOut | 0;
688
- arr[j] %= baseOut;
689
- }
690
- }
691
- }
692
- return arr.reverse();
693
- }
694
- return function(str, baseIn, baseOut, sign, callerIsToString) {
695
- var alphabet2, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
696
- if (i >= 0) {
697
- k = POW_PRECISION;
698
- POW_PRECISION = 0;
699
- str = str.replace(".", "");
700
- y = new BigNumber2(baseIn);
701
- x = y.pow(str.length - i);
702
- POW_PRECISION = k;
703
- y.c = toBaseOut(
704
- toFixedPoint(coeffToString(x.c), x.e, "0"),
705
- 10,
706
- baseOut,
707
- decimal
708
- );
709
- y.e = y.c.length;
710
- }
711
- xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet2 = ALPHABET, decimal) : (alphabet2 = decimal, ALPHABET));
712
- e = k = xc.length;
713
- for (; xc[--k] == 0; xc.pop()) ;
714
- if (!xc[0]) return alphabet2.charAt(0);
715
- if (i < 0) {
716
- --e;
717
- } else {
718
- x.c = xc;
719
- x.e = e;
720
- x.s = sign;
721
- x = div(x, y, dp, rm, baseOut);
722
- xc = x.c;
723
- r = x.r;
724
- e = x.e;
725
- }
726
- d = e + dp + 1;
727
- i = xc[d];
728
- k = baseOut / 2;
729
- r = r || d < 0 || xc[d + 1] != null;
730
- r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
731
- if (d < 1 || !xc[0]) {
732
- str = r ? toFixedPoint(alphabet2.charAt(1), -dp, alphabet2.charAt(0)) : alphabet2.charAt(0);
733
- } else {
734
- xc.length = d;
735
- if (r) {
736
- for (--baseOut; ++xc[--d] > baseOut; ) {
737
- xc[d] = 0;
738
- if (!d) {
739
- ++e;
740
- xc = [1].concat(xc);
741
- }
742
- }
743
- }
744
- for (k = xc.length; !xc[--k]; ) ;
745
- for (i = 0, str = ""; i <= k; str += alphabet2.charAt(xc[i++])) ;
746
- str = toFixedPoint(str, e, alphabet2.charAt(0));
747
- }
748
- return str;
749
- };
750
- })();
751
- div = /* @__PURE__ */ (function() {
752
- function multiply(x, k, base) {
753
- var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
754
- for (x = x.slice(); i--; ) {
755
- xlo = x[i] % SQRT_BASE;
756
- xhi = x[i] / SQRT_BASE | 0;
757
- m = khi * xlo + xhi * klo;
758
- temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
759
- carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
760
- x[i] = temp % base;
761
- }
762
- if (carry) x = [carry].concat(x);
763
- return x;
764
- }
765
- function compare2(a, b, aL, bL) {
766
- var i, cmp;
767
- if (aL != bL) {
768
- cmp = aL > bL ? 1 : -1;
769
- } else {
770
- for (i = cmp = 0; i < aL; i++) {
771
- if (a[i] != b[i]) {
772
- cmp = a[i] > b[i] ? 1 : -1;
773
- break;
774
- }
775
- }
776
- }
777
- return cmp;
778
- }
779
- function subtract(a, b, aL, base) {
780
- var i = 0;
781
- for (; aL--; ) {
782
- a[aL] -= i;
783
- i = a[aL] < b[aL] ? 1 : 0;
784
- a[aL] = i * base + a[aL] - b[aL];
785
- }
786
- for (; !a[0] && a.length > 1; a.splice(0, 1)) ;
787
- }
788
- return function(x, y, dp, rm, base) {
789
- var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
790
- if (!xc || !xc[0] || !yc || !yc[0]) {
791
- return new BigNumber2(
792
- // Return NaN if either NaN, or both Infinity or 0.
793
- !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
794
- // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
795
- xc && xc[0] == 0 || !yc ? s * 0 : s / 0
796
- )
797
- );
798
- }
799
- q = new BigNumber2(s);
800
- qc = q.c = [];
801
- e = x.e - y.e;
802
- s = dp + e + 1;
803
- if (!base) {
804
- base = BASE;
805
- e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
806
- s = s / LOG_BASE | 0;
807
- }
808
- for (i = 0; yc[i] == (xc[i] || 0); i++) ;
809
- if (yc[i] > (xc[i] || 0)) e--;
810
- if (s < 0) {
811
- qc.push(1);
812
- more = true;
813
- } else {
814
- xL = xc.length;
815
- yL = yc.length;
816
- i = 0;
817
- s += 2;
818
- n = mathfloor(base / (yc[0] + 1));
819
- if (n > 1) {
820
- yc = multiply(yc, n, base);
821
- xc = multiply(xc, n, base);
822
- yL = yc.length;
823
- xL = xc.length;
824
- }
825
- xi = yL;
826
- rem = xc.slice(0, yL);
827
- remL = rem.length;
828
- for (; remL < yL; rem[remL++] = 0) ;
829
- yz = yc.slice();
830
- yz = [0].concat(yz);
831
- yc0 = yc[0];
832
- if (yc[1] >= base / 2) yc0++;
833
- do {
834
- n = 0;
835
- cmp = compare2(yc, rem, yL, remL);
836
- if (cmp < 0) {
837
- rem0 = rem[0];
838
- if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
839
- n = mathfloor(rem0 / yc0);
840
- if (n > 1) {
841
- if (n >= base) n = base - 1;
842
- prod = multiply(yc, n, base);
843
- prodL = prod.length;
844
- remL = rem.length;
845
- while (compare2(prod, rem, prodL, remL) == 1) {
846
- n--;
847
- subtract(prod, yL < prodL ? yz : yc, prodL, base);
848
- prodL = prod.length;
849
- cmp = 1;
850
- }
851
- } else {
852
- if (n == 0) {
853
- cmp = n = 1;
854
- }
855
- prod = yc.slice();
856
- prodL = prod.length;
857
- }
858
- if (prodL < remL) prod = [0].concat(prod);
859
- subtract(rem, prod, remL, base);
860
- remL = rem.length;
861
- if (cmp == -1) {
862
- while (compare2(yc, rem, yL, remL) < 1) {
863
- n++;
864
- subtract(rem, yL < remL ? yz : yc, remL, base);
865
- remL = rem.length;
866
- }
867
- }
868
- } else if (cmp === 0) {
869
- n++;
870
- rem = [0];
871
- }
872
- qc[i++] = n;
873
- if (rem[0]) {
874
- rem[remL++] = xc[xi] || 0;
875
- } else {
876
- rem = [xc[xi]];
877
- remL = 1;
878
- }
879
- } while ((xi++ < xL || rem[0] != null) && s--);
880
- more = rem[0] != null;
881
- if (!qc[0]) qc.splice(0, 1);
882
- }
883
- if (base == BASE) {
884
- for (i = 1, s = qc[0]; s >= 10; s /= 10, i++) ;
885
- round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
886
- } else {
887
- q.e = e;
888
- q.r = +more;
889
- }
890
- return q;
891
- };
892
- })();
893
- function format(n, i, rm, id) {
894
- var c0, e, ne, len, str;
895
- if (rm == null) rm = ROUNDING_MODE;
896
- else intCheck(rm, 0, 8);
897
- if (!n.c) return n.toString();
898
- c0 = n.c[0];
899
- ne = n.e;
900
- if (i == null) {
901
- str = coeffToString(n.c);
902
- str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
903
- } else {
904
- n = round(new BigNumber2(n), i, rm);
905
- e = n.e;
906
- str = coeffToString(n.c);
907
- len = str.length;
908
- if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
909
- for (; len < i; str += "0", len++) ;
910
- str = toExponential(str, e);
911
- } else {
912
- i -= ne + (id === 2 && e > ne);
913
- str = toFixedPoint(str, e, "0");
914
- if (e + 1 > len) {
915
- if (--i > 0) for (str += "."; i--; str += "0") ;
916
- } else {
917
- i += e - len;
918
- if (i > 0) {
919
- if (e + 1 == len) str += ".";
920
- for (; i--; str += "0") ;
921
- }
922
- }
923
- }
924
- }
925
- return n.s < 0 && c0 ? "-" + str : str;
926
- }
927
- function maxOrMin(args, n) {
928
- var k, y, i = 1, x = new BigNumber2(args[0]);
929
- for (; i < args.length; i++) {
930
- y = new BigNumber2(args[i]);
931
- if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
932
- x = y;
933
- }
934
- }
935
- return x;
936
- }
937
- function normalise(n, c, e) {
938
- var i = 1, j = c.length;
939
- for (; !c[--j]; c.pop()) ;
940
- for (j = c[0]; j >= 10; j /= 10, i++) ;
941
- if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
942
- n.c = n.e = null;
943
- } else if (e < MIN_EXP) {
944
- n.c = [n.e = 0];
945
- } else {
946
- n.e = e;
947
- n.c = c;
948
- }
949
- return n;
950
- }
951
- parseNumeric = /* @__PURE__ */ (function() {
952
- var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
953
- return function(x, str, isNum, b) {
954
- var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
955
- if (isInfinityOrNaN.test(s)) {
956
- x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
957
- } else {
958
- if (!isNum) {
959
- s = s.replace(basePrefix, function(m, p1, p2) {
960
- base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
961
- return !b || b == base ? p1 : m;
962
- });
963
- if (b) {
964
- base = b;
965
- s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
966
- }
967
- if (str != s) return new BigNumber2(s, base);
968
- }
969
- if (BigNumber2.DEBUG) {
970
- throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
971
- }
972
- x.s = null;
973
- }
974
- x.c = x.e = null;
975
- };
976
- })();
977
- function round(x, sd, rm, r) {
978
- var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
979
- if (xc) {
980
- out: {
981
- for (d = 1, k = xc[0]; k >= 10; k /= 10, d++) ;
982
- i = sd - d;
983
- if (i < 0) {
984
- i += LOG_BASE;
985
- j = sd;
986
- n = xc[ni = 0];
987
- rd = mathfloor(n / pows10[d - j - 1] % 10);
988
- } else {
989
- ni = mathceil((i + 1) / LOG_BASE);
990
- if (ni >= xc.length) {
991
- if (r) {
992
- for (; xc.length <= ni; xc.push(0)) ;
993
- n = rd = 0;
994
- d = 1;
995
- i %= LOG_BASE;
996
- j = i - LOG_BASE + 1;
997
- } else {
998
- break out;
999
- }
1000
- } else {
1001
- n = k = xc[ni];
1002
- for (d = 1; k >= 10; k /= 10, d++) ;
1003
- i %= LOG_BASE;
1004
- j = i - LOG_BASE + d;
1005
- rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
1006
- }
1007
- }
1008
- r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
1009
- // The expression n % pows10[d - j - 1] returns all digits of n to the right
1010
- // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
1011
- xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
1012
- r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
1013
- (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
1014
- if (sd < 1 || !xc[0]) {
1015
- xc.length = 0;
1016
- if (r) {
1017
- sd -= x.e + 1;
1018
- xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
1019
- x.e = -sd || 0;
1020
- } else {
1021
- xc[0] = x.e = 0;
1022
- }
1023
- return x;
1024
- }
1025
- if (i == 0) {
1026
- xc.length = ni;
1027
- k = 1;
1028
- ni--;
1029
- } else {
1030
- xc.length = ni + 1;
1031
- k = pows10[LOG_BASE - i];
1032
- xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
1033
- }
1034
- if (r) {
1035
- for (; ; ) {
1036
- if (ni == 0) {
1037
- for (i = 1, j = xc[0]; j >= 10; j /= 10, i++) ;
1038
- j = xc[0] += k;
1039
- for (k = 1; j >= 10; j /= 10, k++) ;
1040
- if (i != k) {
1041
- x.e++;
1042
- if (xc[0] == BASE) xc[0] = 1;
1043
- }
1044
- break;
1045
- } else {
1046
- xc[ni] += k;
1047
- if (xc[ni] != BASE) break;
1048
- xc[ni--] = 0;
1049
- k = 1;
1050
- }
1051
- }
1052
- }
1053
- for (i = xc.length; xc[--i] === 0; xc.pop()) ;
1054
- }
1055
- if (x.e > MAX_EXP) {
1056
- x.c = x.e = null;
1057
- } else if (x.e < MIN_EXP) {
1058
- x.c = [x.e = 0];
1059
- }
1060
- }
1061
- return x;
1062
- }
1063
- function valueOf(n) {
1064
- var str, e = n.e;
1065
- if (e === null) return n.toString();
1066
- str = coeffToString(n.c);
1067
- str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
1068
- return n.s < 0 ? "-" + str : str;
1069
- }
1070
- P.absoluteValue = P.abs = function() {
1071
- var x = new BigNumber2(this);
1072
- if (x.s < 0) x.s = 1;
1073
- return x;
1074
- };
1075
- P.comparedTo = function(y, b) {
1076
- return compare(this, new BigNumber2(y, b));
1077
- };
1078
- P.decimalPlaces = P.dp = function(dp, rm) {
1079
- var c, n, v, x = this;
1080
- if (dp != null) {
1081
- intCheck(dp, 0, MAX);
1082
- if (rm == null) rm = ROUNDING_MODE;
1083
- else intCheck(rm, 0, 8);
1084
- return round(new BigNumber2(x), dp + x.e + 1, rm);
1085
- }
1086
- if (!(c = x.c)) return null;
1087
- n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
1088
- if (v = c[v]) for (; v % 10 == 0; v /= 10, n--) ;
1089
- if (n < 0) n = 0;
1090
- return n;
1091
- };
1092
- P.dividedBy = P.div = function(y, b) {
1093
- return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
1094
- };
1095
- P.dividedToIntegerBy = P.idiv = function(y, b) {
1096
- return div(this, new BigNumber2(y, b), 0, 1);
1097
- };
1098
- P.exponentiatedBy = P.pow = function(n, m) {
1099
- var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
1100
- n = new BigNumber2(n);
1101
- if (n.c && !n.isInteger()) {
1102
- throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
1103
- }
1104
- if (m != null) m = new BigNumber2(m);
1105
- nIsBig = n.e > 14;
1106
- if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
1107
- y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
1108
- return m ? y.mod(m) : y;
1109
- }
1110
- nIsNeg = n.s < 0;
1111
- if (m) {
1112
- if (m.c ? !m.c[0] : !m.s) return new BigNumber2(NaN);
1113
- isModExp = !nIsNeg && x.isInteger() && m.isInteger();
1114
- if (isModExp) x = x.mod(m);
1115
- } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
1116
- k = x.s < 0 && isOdd(n) ? -0 : 0;
1117
- if (x.e > -1) k = 1 / k;
1118
- return new BigNumber2(nIsNeg ? 1 / k : k);
1119
- } else if (POW_PRECISION) {
1120
- k = mathceil(POW_PRECISION / LOG_BASE + 2);
1121
- }
1122
- if (nIsBig) {
1123
- half = new BigNumber2(0.5);
1124
- if (nIsNeg) n.s = 1;
1125
- nIsOdd = isOdd(n);
1126
- } else {
1127
- i = Math.abs(+valueOf(n));
1128
- nIsOdd = i % 2;
1129
- }
1130
- y = new BigNumber2(ONE);
1131
- for (; ; ) {
1132
- if (nIsOdd) {
1133
- y = y.times(x);
1134
- if (!y.c) break;
1135
- if (k) {
1136
- if (y.c.length > k) y.c.length = k;
1137
- } else if (isModExp) {
1138
- y = y.mod(m);
1139
- }
1140
- }
1141
- if (i) {
1142
- i = mathfloor(i / 2);
1143
- if (i === 0) break;
1144
- nIsOdd = i % 2;
1145
- } else {
1146
- n = n.times(half);
1147
- round(n, n.e + 1, 1);
1148
- if (n.e > 14) {
1149
- nIsOdd = isOdd(n);
1150
- } else {
1151
- i = +valueOf(n);
1152
- if (i === 0) break;
1153
- nIsOdd = i % 2;
1154
- }
1155
- }
1156
- x = x.times(x);
1157
- if (k) {
1158
- if (x.c && x.c.length > k) x.c.length = k;
1159
- } else if (isModExp) {
1160
- x = x.mod(m);
1161
- }
1162
- }
1163
- if (isModExp) return y;
1164
- if (nIsNeg) y = ONE.div(y);
1165
- return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
1166
- };
1167
- P.integerValue = function(rm) {
1168
- var n = new BigNumber2(this);
1169
- if (rm == null) rm = ROUNDING_MODE;
1170
- else intCheck(rm, 0, 8);
1171
- return round(n, n.e + 1, rm);
1172
- };
1173
- P.isEqualTo = P.eq = function(y, b) {
1174
- return compare(this, new BigNumber2(y, b)) === 0;
1175
- };
1176
- P.isFinite = function() {
1177
- return !!this.c;
1178
- };
1179
- P.isGreaterThan = P.gt = function(y, b) {
1180
- return compare(this, new BigNumber2(y, b)) > 0;
1181
- };
1182
- P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
1183
- return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
1184
- };
1185
- P.isInteger = function() {
1186
- return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
1187
- };
1188
- P.isLessThan = P.lt = function(y, b) {
1189
- return compare(this, new BigNumber2(y, b)) < 0;
1190
- };
1191
- P.isLessThanOrEqualTo = P.lte = function(y, b) {
1192
- return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
1193
- };
1194
- P.isNaN = function() {
1195
- return !this.s;
1196
- };
1197
- P.isNegative = function() {
1198
- return this.s < 0;
1199
- };
1200
- P.isPositive = function() {
1201
- return this.s > 0;
1202
- };
1203
- P.isZero = function() {
1204
- return !!this.c && this.c[0] == 0;
1205
- };
1206
- P.minus = function(y, b) {
1207
- var i, j, t, xLTy, x = this, a = x.s;
1208
- y = new BigNumber2(y, b);
1209
- b = y.s;
1210
- if (!a || !b) return new BigNumber2(NaN);
1211
- if (a != b) {
1212
- y.s = -b;
1213
- return x.plus(y);
1214
- }
1215
- var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
1216
- if (!xe || !ye) {
1217
- if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
1218
- if (!xc[0] || !yc[0]) {
1219
- return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
1220
- // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
1221
- ROUNDING_MODE == 3 ? -0 : 0
1222
- ));
1223
- }
1224
- }
1225
- xe = bitFloor(xe);
1226
- ye = bitFloor(ye);
1227
- xc = xc.slice();
1228
- if (a = xe - ye) {
1229
- if (xLTy = a < 0) {
1230
- a = -a;
1231
- t = xc;
1232
- } else {
1233
- ye = xe;
1234
- t = yc;
1235
- }
1236
- t.reverse();
1237
- for (b = a; b--; t.push(0)) ;
1238
- t.reverse();
1239
- } else {
1240
- j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
1241
- for (a = b = 0; b < j; b++) {
1242
- if (xc[b] != yc[b]) {
1243
- xLTy = xc[b] < yc[b];
1244
- break;
1245
- }
1246
- }
1247
- }
1248
- if (xLTy) {
1249
- t = xc;
1250
- xc = yc;
1251
- yc = t;
1252
- y.s = -y.s;
1253
- }
1254
- b = (j = yc.length) - (i = xc.length);
1255
- if (b > 0) for (; b--; xc[i++] = 0) ;
1256
- b = BASE - 1;
1257
- for (; j > a; ) {
1258
- if (xc[--j] < yc[j]) {
1259
- for (i = j; i && !xc[--i]; xc[i] = b) ;
1260
- --xc[i];
1261
- xc[j] += BASE;
1262
- }
1263
- xc[j] -= yc[j];
1264
- }
1265
- for (; xc[0] == 0; xc.splice(0, 1), --ye) ;
1266
- if (!xc[0]) {
1267
- y.s = ROUNDING_MODE == 3 ? -1 : 1;
1268
- y.c = [y.e = 0];
1269
- return y;
1270
- }
1271
- return normalise(y, xc, ye);
1272
- };
1273
- P.modulo = P.mod = function(y, b) {
1274
- var q, s, x = this;
1275
- y = new BigNumber2(y, b);
1276
- if (!x.c || !y.s || y.c && !y.c[0]) {
1277
- return new BigNumber2(NaN);
1278
- } else if (!y.c || x.c && !x.c[0]) {
1279
- return new BigNumber2(x);
1280
- }
1281
- if (MODULO_MODE == 9) {
1282
- s = y.s;
1283
- y.s = 1;
1284
- q = div(x, y, 0, 3);
1285
- y.s = s;
1286
- q.s *= s;
1287
- } else {
1288
- q = div(x, y, 0, MODULO_MODE);
1289
- }
1290
- y = x.minus(q.times(y));
1291
- if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
1292
- return y;
1293
- };
1294
- P.multipliedBy = P.times = function(y, b) {
1295
- var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
1296
- if (!xc || !yc || !xc[0] || !yc[0]) {
1297
- if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
1298
- y.c = y.e = y.s = null;
1299
- } else {
1300
- y.s *= x.s;
1301
- if (!xc || !yc) {
1302
- y.c = y.e = null;
1303
- } else {
1304
- y.c = [0];
1305
- y.e = 0;
1306
- }
1307
- }
1308
- return y;
1309
- }
1310
- e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
1311
- y.s *= x.s;
1312
- xcL = xc.length;
1313
- ycL = yc.length;
1314
- if (xcL < ycL) {
1315
- zc = xc;
1316
- xc = yc;
1317
- yc = zc;
1318
- i = xcL;
1319
- xcL = ycL;
1320
- ycL = i;
1321
- }
1322
- for (i = xcL + ycL, zc = []; i--; zc.push(0)) ;
1323
- base = BASE;
1324
- sqrtBase = SQRT_BASE;
1325
- for (i = ycL; --i >= 0; ) {
1326
- c = 0;
1327
- ylo = yc[i] % sqrtBase;
1328
- yhi = yc[i] / sqrtBase | 0;
1329
- for (k = xcL, j = i + k; j > i; ) {
1330
- xlo = xc[--k] % sqrtBase;
1331
- xhi = xc[k] / sqrtBase | 0;
1332
- m = yhi * xlo + xhi * ylo;
1333
- xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
1334
- c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
1335
- zc[j--] = xlo % base;
1336
- }
1337
- zc[j] = c;
1338
- }
1339
- if (c) {
1340
- ++e;
1341
- } else {
1342
- zc.splice(0, 1);
1343
- }
1344
- return normalise(y, zc, e);
1345
- };
1346
- P.negated = function() {
1347
- var x = new BigNumber2(this);
1348
- x.s = -x.s || null;
1349
- return x;
1350
- };
1351
- P.plus = function(y, b) {
1352
- var t, x = this, a = x.s;
1353
- y = new BigNumber2(y, b);
1354
- b = y.s;
1355
- if (!a || !b) return new BigNumber2(NaN);
1356
- if (a != b) {
1357
- y.s = -b;
1358
- return x.minus(y);
1359
- }
1360
- var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
1361
- if (!xe || !ye) {
1362
- if (!xc || !yc) return new BigNumber2(a / 0);
1363
- if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
1364
- }
1365
- xe = bitFloor(xe);
1366
- ye = bitFloor(ye);
1367
- xc = xc.slice();
1368
- if (a = xe - ye) {
1369
- if (a > 0) {
1370
- ye = xe;
1371
- t = yc;
1372
- } else {
1373
- a = -a;
1374
- t = xc;
1375
- }
1376
- t.reverse();
1377
- for (; a--; t.push(0)) ;
1378
- t.reverse();
1379
- }
1380
- a = xc.length;
1381
- b = yc.length;
1382
- if (a - b < 0) {
1383
- t = yc;
1384
- yc = xc;
1385
- xc = t;
1386
- b = a;
1387
- }
1388
- for (a = 0; b; ) {
1389
- a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
1390
- xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
1391
- }
1392
- if (a) {
1393
- xc = [a].concat(xc);
1394
- ++ye;
1395
- }
1396
- return normalise(y, xc, ye);
1397
- };
1398
- P.precision = P.sd = function(sd, rm) {
1399
- var c, n, v, x = this;
1400
- if (sd != null && sd !== !!sd) {
1401
- intCheck(sd, 1, MAX);
1402
- if (rm == null) rm = ROUNDING_MODE;
1403
- else intCheck(rm, 0, 8);
1404
- return round(new BigNumber2(x), sd, rm);
1405
- }
1406
- if (!(c = x.c)) return null;
1407
- v = c.length - 1;
1408
- n = v * LOG_BASE + 1;
1409
- if (v = c[v]) {
1410
- for (; v % 10 == 0; v /= 10, n--) ;
1411
- for (v = c[0]; v >= 10; v /= 10, n++) ;
1412
- }
1413
- if (sd && x.e + 1 > n) n = x.e + 1;
1414
- return n;
1415
- };
1416
- P.shiftedBy = function(k) {
1417
- intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
1418
- return this.times("1e" + k);
1419
- };
1420
- P.squareRoot = P.sqrt = function() {
1421
- var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
1422
- if (s !== 1 || !c || !c[0]) {
1423
- return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
1424
- }
1425
- s = Math.sqrt(+valueOf(x));
1426
- if (s == 0 || s == 1 / 0) {
1427
- n = coeffToString(c);
1428
- if ((n.length + e) % 2 == 0) n += "0";
1429
- s = Math.sqrt(+n);
1430
- e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
1431
- if (s == 1 / 0) {
1432
- n = "5e" + e;
1433
- } else {
1434
- n = s.toExponential();
1435
- n = n.slice(0, n.indexOf("e") + 1) + e;
1436
- }
1437
- r = new BigNumber2(n);
1438
- } else {
1439
- r = new BigNumber2(s + "");
1440
- }
1441
- if (r.c[0]) {
1442
- e = r.e;
1443
- s = e + dp;
1444
- if (s < 3) s = 0;
1445
- for (; ; ) {
1446
- t = r;
1447
- r = half.times(t.plus(div(x, t, dp, 1)));
1448
- if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
1449
- if (r.e < e) --s;
1450
- n = n.slice(s - 3, s + 1);
1451
- if (n == "9999" || !rep && n == "4999") {
1452
- if (!rep) {
1453
- round(t, t.e + DECIMAL_PLACES + 2, 0);
1454
- if (t.times(t).eq(x)) {
1455
- r = t;
1456
- break;
1457
- }
1458
- }
1459
- dp += 4;
1460
- s += 4;
1461
- rep = 1;
1462
- } else {
1463
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
1464
- round(r, r.e + DECIMAL_PLACES + 2, 1);
1465
- m = !r.times(r).eq(x);
1466
- }
1467
- break;
1468
- }
1469
- }
1470
- }
1471
- }
1472
- return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
1473
- };
1474
- P.toExponential = function(dp, rm) {
1475
- if (dp != null) {
1476
- intCheck(dp, 0, MAX);
1477
- dp++;
1478
- }
1479
- return format(this, dp, rm, 1);
1480
- };
1481
- P.toFixed = function(dp, rm) {
1482
- if (dp != null) {
1483
- intCheck(dp, 0, MAX);
1484
- dp = dp + this.e + 1;
1485
- }
1486
- return format(this, dp, rm);
1487
- };
1488
- P.toFormat = function(dp, rm, format2) {
1489
- var str, x = this;
1490
- if (format2 == null) {
1491
- if (dp != null && rm && typeof rm == "object") {
1492
- format2 = rm;
1493
- rm = null;
1494
- } else if (dp && typeof dp == "object") {
1495
- format2 = dp;
1496
- dp = rm = null;
1497
- } else {
1498
- format2 = FORMAT;
1499
- }
1500
- } else if (typeof format2 != "object") {
1501
- throw Error(bignumberError + "Argument not an object: " + format2);
1502
- }
1503
- str = x.toFixed(dp, rm);
1504
- if (x.c) {
1505
- var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
1506
- if (g2) {
1507
- i = g1;
1508
- g1 = g2;
1509
- g2 = i;
1510
- len -= i;
1511
- }
1512
- if (g1 > 0 && len > 0) {
1513
- i = len % g1 || g1;
1514
- intPart = intDigits.substr(0, i);
1515
- for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
1516
- if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
1517
- if (isNeg) intPart = "-" + intPart;
1518
- }
1519
- str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
1520
- new RegExp("\\d{" + g2 + "}\\B", "g"),
1521
- "$&" + (format2.fractionGroupSeparator || "")
1522
- ) : fractionPart) : intPart;
1523
- }
1524
- return (format2.prefix || "") + str + (format2.suffix || "");
1525
- };
1526
- P.toFraction = function(md) {
1527
- var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
1528
- if (md != null) {
1529
- n = new BigNumber2(md);
1530
- if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
1531
- throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
1532
- }
1533
- }
1534
- if (!xc) return new BigNumber2(x);
1535
- d = new BigNumber2(ONE);
1536
- n1 = d0 = new BigNumber2(ONE);
1537
- d1 = n0 = new BigNumber2(ONE);
1538
- s = coeffToString(xc);
1539
- e = d.e = s.length - x.e - 1;
1540
- d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
1541
- md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
1542
- exp = MAX_EXP;
1543
- MAX_EXP = 1 / 0;
1544
- n = new BigNumber2(s);
1545
- n0.c[0] = 0;
1546
- for (; ; ) {
1547
- q = div(n, d, 0, 1);
1548
- d2 = d0.plus(q.times(d1));
1549
- if (d2.comparedTo(md) == 1) break;
1550
- d0 = d1;
1551
- d1 = d2;
1552
- n1 = n0.plus(q.times(d2 = n1));
1553
- n0 = d2;
1554
- d = n.minus(q.times(d2 = d));
1555
- n = d2;
1556
- }
1557
- d2 = div(md.minus(d0), d1, 0, 1);
1558
- n0 = n0.plus(d2.times(n1));
1559
- d0 = d0.plus(d2.times(d1));
1560
- n0.s = n1.s = x.s;
1561
- e = e * 2;
1562
- r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
1563
- div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
1564
- ) < 1 ? [n1, d1] : [n0, d0];
1565
- MAX_EXP = exp;
1566
- return r;
1567
- };
1568
- P.toNumber = function() {
1569
- return +valueOf(this);
1570
- };
1571
- P.toPrecision = function(sd, rm) {
1572
- if (sd != null) intCheck(sd, 1, MAX);
1573
- return format(this, sd, rm, 2);
1574
- };
1575
- P.toString = function(b) {
1576
- var str, n = this, s = n.s, e = n.e;
1577
- if (e === null) {
1578
- if (s) {
1579
- str = "Infinity";
1580
- if (s < 0) str = "-" + str;
1581
- } else {
1582
- str = "NaN";
1583
- }
1584
- } else {
1585
- if (b == null) {
1586
- str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
1587
- } else if (b === 10 && alphabetHasNormalDecimalDigits) {
1588
- n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
1589
- str = toFixedPoint(coeffToString(n.c), n.e, "0");
1590
- } else {
1591
- intCheck(b, 2, ALPHABET.length, "Base");
1592
- str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
1593
- }
1594
- if (s < 0 && n.c[0]) str = "-" + str;
1595
- }
1596
- return str;
1597
- };
1598
- P.valueOf = P.toJSON = function() {
1599
- return valueOf(this);
1600
- };
1601
- P._isBigNumber = true;
1602
- P[Symbol.toStringTag] = "BigNumber";
1603
- P[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
1604
- if (configObject != null) BigNumber2.set(configObject);
1605
- return BigNumber2;
1606
- }
1607
- function bitFloor(n) {
1608
- var i = n | 0;
1609
- return n > 0 || n === i ? i : i - 1;
1610
- }
1611
- function coeffToString(a) {
1612
- var s, z, i = 1, j = a.length, r = a[0] + "";
1613
- for (; i < j; ) {
1614
- s = a[i++] + "";
1615
- z = LOG_BASE - s.length;
1616
- for (; z--; s = "0" + s) ;
1617
- r += s;
1618
- }
1619
- for (j = r.length; r.charCodeAt(--j) === 48; ) ;
1620
- return r.slice(0, j + 1 || 1);
1621
- }
1622
- function compare(x, y) {
1623
- var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
1624
- if (!i || !j) return null;
1625
- a = xc && !xc[0];
1626
- b = yc && !yc[0];
1627
- if (a || b) return a ? b ? 0 : -j : i;
1628
- if (i != j) return i;
1629
- a = i < 0;
1630
- b = k == l;
1631
- if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
1632
- if (!b) return k > l ^ a ? 1 : -1;
1633
- j = (k = xc.length) < (l = yc.length) ? k : l;
1634
- for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
1635
- return k == l ? 0 : k > l ^ a ? 1 : -1;
1636
- }
1637
- function intCheck(n, min, max, name) {
1638
- if (n < min || n > max || n !== mathfloor(n)) {
1639
- throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
1640
- }
1641
- }
1642
- function isOdd(n) {
1643
- var k = n.c.length - 1;
1644
- return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
1645
- }
1646
- function toExponential(str, e) {
1647
- return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
1648
- }
1649
- function toFixedPoint(str, e, z) {
1650
- var len, zs;
1651
- if (e < 0) {
1652
- for (zs = z + "."; ++e; zs += z) ;
1653
- str = zs + str;
1654
- } else {
1655
- len = str.length;
1656
- if (++e > len) {
1657
- for (zs = z, e -= len; --e; zs += z) ;
1658
- str += zs;
1659
- } else if (e < len) {
1660
- str = str.slice(0, e) + "." + str.slice(e);
1661
- }
1662
- }
1663
- return str;
1664
- }
1665
- var BigNumber = clone();
1666
- var bignumber_default = BigNumber;
1667
-
1668
- // node_modules/@paralleldrive/cuid2/src/index.js
1669
- var defaultLength = 24;
1670
- var bigLength = 32;
1671
- var createRandom = () => {
1672
- if (typeof globalThis !== "undefined" && globalThis.crypto && typeof globalThis.crypto.getRandomValues === "function") {
1673
- return () => {
1674
- const buffer = new Uint32Array(1);
1675
- globalThis.crypto.getRandomValues(buffer);
1676
- return buffer[0] / 4294967296;
1677
- };
1678
- }
1679
- return Math.random;
1680
- };
1681
- var random = createRandom();
1682
- var createEntropy = (length = 4, rand = random) => {
1683
- let entropy = "";
1684
- while (entropy.length < length) {
1685
- entropy = entropy + Math.floor(rand() * 36).toString(36);
1686
- }
1687
- return entropy;
1688
- };
1689
- function bufToBigInt(buf) {
1690
- let value = new bignumber_default(0);
1691
- for (const i of buf.values()) {
1692
- value = value.multipliedBy(256).plus(i);
1693
- }
1694
- return value;
1695
- }
1696
- var hash = (input = "") => {
1697
- const encoder = new TextEncoder();
1698
- return bufToBigInt(sha3_512(encoder.encode(input))).toString(36).slice(1);
1699
- };
1700
- var alphabet = Array.from(
1701
- { length: 26 },
1702
- (x, i) => String.fromCharCode(i + 97)
1703
- );
1704
- var randomLetter = (rand) => alphabet[Math.floor(rand() * alphabet.length)];
1705
- var createFingerprint = ({
1706
- globalObj = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {},
1707
- random: rand = random
1708
- } = {}) => {
1709
- const globals = Object.keys(globalObj).toString();
1710
- const sourceString = globals.length ? globals + createEntropy(bigLength, rand) : createEntropy(bigLength, rand);
1711
- return hash(sourceString).substring(0, bigLength);
1712
- };
1713
- var createCounter = (count) => () => {
1714
- return count++;
1715
- };
1716
- var initialCountMax = 476782367;
1717
- var init = ({
1718
- // Fallback if the user does not pass in a CSPRNG. This should be OK
1719
- // because we don't rely solely on the random number generator for entropy.
1720
- // We also use the host fingerprint, current time, and a session counter.
1721
- random: rand = random,
1722
- counter = createCounter(Math.floor(rand() * initialCountMax)),
1723
- length = defaultLength,
1724
- fingerprint = createFingerprint({ random: rand })
1725
- } = {}) => {
1726
- if (length > bigLength) {
30
+ // src/helpers.ts
31
+ var AUTO_LABEL_PREFEX = "@Sigil-auto";
32
+ var handledCtors = /* @__PURE__ */ new WeakSet();
33
+ function handleSigil(ctor, label, opts) {
34
+ if (handledCtors.has(ctor)) return;
35
+ handledCtors.add(ctor);
36
+ verifyLabel(ctor, label, opts);
37
+ const ancLabelsMap = handleAncestors(ctor, opts);
38
+ if (label && ancLabelsMap.has(label))
1727
39
  throw new Error(
1728
- `Length must be between 2 and ${bigLength}. Received: ${length}`
40
+ `[Sigil Error] Attempt to assign label '${label}' to ${ctor.name} but label is already used by parent '${ancLabelsMap.get(label)}', Make sure that every class has a unique label`
1729
41
  );
1730
- }
1731
- return function cuid2() {
1732
- const firstLetter = randomLetter(rand);
1733
- const time = Date.now().toString(36);
1734
- const count = counter().toString(36);
1735
- const salt = createEntropy(length, rand);
1736
- const hashInput = `${time + salt + count + fingerprint}`;
1737
- return `${firstLetter + hash(hashInput).substring(1, length)}`;
1738
- };
1739
- };
1740
- var createId = lazy(init);
1741
- function lazy(fn) {
1742
- let initialized;
1743
- return () => {
1744
- if (!initialized) {
1745
- initialized = fn();
1746
- }
1747
- return initialized();
1748
- };
1749
- }
1750
-
1751
- // src/core/helpers.ts
1752
- function decorateCtor(ctor, label, runtime) {
1753
- if (process.env.NODE_ENV !== "production") {
1754
- if (isDecorated(ctor))
1755
- throw new Error(
1756
- `Constructor ${ctor} is already decorated. if you are using 'withSigilTyped()' & '@WithSigil()' at the same time remove one of them.`
1757
- );
1758
- }
1759
- Object.defineProperty(ctor, __LABEL__, {
1760
- value: label,
1761
- configurable: true,
1762
- enumerable: false,
1763
- writable: false
1764
- });
1765
- if (!(runtime == null ? void 0 : runtime.isInheritanceCheck))
1766
- Object.defineProperty(ctor, __EFFECTIVE_LABEL__, {
1767
- value: label,
1768
- configurable: true,
1769
- enumerable: false,
1770
- writable: false
1771
- });
1772
- const parent = Object.getPrototypeOf(ctor);
1773
- const parentChain = parent && parent[__LABEL_LINEAGE__] ? parent[__LABEL_LINEAGE__] : [];
1774
- const ctorChain = (runtime == null ? void 0 : runtime.isMixin) && label !== "Sigil" ? ["Sigil", ...parentChain, label] : [...parentChain, label];
1775
- Object.defineProperty(ctor, __LABEL_LINEAGE__, {
1776
- value: ctorChain,
1777
- configurable: true,
1778
- enumerable: false,
1779
- writable: false
1780
- });
1781
- Object.defineProperty(ctor, __LABEL_SET__, {
1782
- value: new Set(ctorChain),
1783
- configurable: true,
1784
- enumerable: false,
1785
- writable: false
1786
- });
1787
- if (!(runtime == null ? void 0 : runtime.isInheritanceCheck)) markDecorated(ctor);
42
+ sigilify(ctor, label != null ? label : generateRandomLabel(ctor));
1788
43
  }
1789
- function checkInheritance(ctor, opts) {
1790
- var _a, _b;
1791
- if (isInheritanceChecked(ctor) || ((_a = opts == null ? void 0 : opts.skipLabelInheritanceCheck) != null ? _a : OPTIONS.skipLabelInheritanceCheck))
1792
- return;
1793
- const ctors = [ctor];
1794
- let ancestor = Object.getPrototypeOf(ctor);
1795
- while (isSigilCtor(ancestor)) {
1796
- ctors.push(ancestor);
1797
- ancestor = Object.getPrototypeOf(ancestor);
44
+ function handleAncestors(ctor, opts) {
45
+ var _a;
46
+ const autofillLabels = (_a = opts == null ? void 0 : opts.autofillLabels) != null ? _a : OPTIONS.autofillLabels;
47
+ const ancestors = [];
48
+ let a = Object.getPrototypeOf(ctor);
49
+ while (a && typeof a === "function" && a.prototype[__SIGIL__]) {
50
+ ancestors.unshift(a);
51
+ a = Object.getPrototypeOf(a);
1798
52
  }
1799
53
  const labelOwner = /* @__PURE__ */ new Map();
1800
- for (let i = ctors.length - 1; i >= 0; i--) {
1801
- const ctor2 = ctors[i];
1802
- if (!ctor2) continue;
1803
- let label = ctor2[__LABEL__];
1804
- if (labelOwner.has(label)) {
1805
- if (process.env.NODE_ENV !== "production") {
1806
- if (isDecorated(ctor2) || !((_b = opts == null ? void 0 : opts.autofillLabels) != null ? _b : OPTIONS.autofillLabels))
1807
- throw new Error(
1808
- `[Sigil Error] Class "${ctor2.name}" re-uses Sigil label "${label}" from ancestor "${labelOwner.get(label)}". Each Sigil subclass must use a unique label. Did you forget to use "WithSigil(newLabel)" on the subclass?`
1809
- );
1810
- }
1811
- label = generateRandomLabel();
1812
- decorateCtor(ctor2, label, { isInheritanceCheck: true });
1813
- }
1814
- labelOwner.set(label, ctor2.name);
1815
- }
1816
- markInheritanceChecked(ctor);
1817
- }
1818
- function verifyLabel(label, opts) {
1819
- var _a;
1820
- const labelValidation = (_a = opts == null ? void 0 : opts.labelValidation) != null ? _a : OPTIONS.labelValidation;
1821
- if (labelValidation) {
1822
- let valid;
1823
- if (labelValidation instanceof RegExp) valid = labelValidation.test(label);
1824
- else valid = labelValidation(label);
1825
- if (process.env.NODE_ENV !== "production") {
1826
- if (!valid)
54
+ for (const a2 of ancestors) {
55
+ const l = a2.prototype[__LABEL__];
56
+ if (labelOwner.has(l)) {
57
+ if (!autofillLabels)
1827
58
  throw new Error(
1828
- `[Sigil] Invalid identity label "${label}". Make sure that supplied label matches validation regex or function.`
59
+ `[Sigil Error] Class '${a2.name}' is not sigilified with 'autofillLabels' setted to 'false', Make sure to sigilify all Sigil classes or set 'autofillLabels' to 'true'`
1829
60
  );
61
+ sigilify(a2, generateRandomLabel(a2));
1830
62
  }
63
+ labelOwner.set(labelOf(a2), a2.name);
1831
64
  }
65
+ return labelOwner;
1832
66
  }
1833
- function generateRandomLabel() {
1834
- let label = createId();
1835
- return `@Sigil.auto-${label}`;
1836
- }
1837
- function markSigil(ctor) {
1838
- Object.defineProperty(ctor, __SIGIL__, {
1839
- value: true,
67
+ function sigilify(ctor, label) {
68
+ var _a;
69
+ const sym = Symbol.for(label);
70
+ Object.defineProperty(ctor.prototype, __SIGIL__, {
71
+ value: sym,
1840
72
  configurable: false,
1841
73
  enumerable: false,
1842
74
  writable: false
1843
75
  });
1844
- }
1845
- function markSigilBase(ctor) {
1846
- Object.defineProperty(ctor, __SIGIL_BASE__, {
76
+ Object.defineProperty(ctor.prototype, sym, {
1847
77
  value: true,
1848
78
  configurable: false,
1849
79
  enumerable: false,
1850
80
  writable: false
1851
81
  });
1852
- }
1853
- function markDecorated(ctor) {
1854
- Object.defineProperty(ctor, __DECORATED__, {
1855
- value: true,
82
+ Object.defineProperty(ctor.prototype, __LABEL__, {
83
+ value: label,
1856
84
  configurable: false,
1857
85
  enumerable: false,
1858
86
  writable: false
1859
87
  });
1860
- }
1861
- function markInheritanceChecked(ctor) {
1862
- Object.defineProperty(ctor, __INHERITANCE_CHECKED__, {
1863
- value: true,
88
+ if (!label.startsWith(AUTO_LABEL_PREFEX))
89
+ Object.defineProperty(ctor.prototype, __EFFECTIVE_LABEL__, {
90
+ value: label,
91
+ configurable: false,
92
+ enumerable: false,
93
+ writable: false
94
+ });
95
+ Object.defineProperty(ctor.prototype, __LINEAGE__, {
96
+ value: /* @__PURE__ */ new Set(["Sigil", ...(_a = lineageOf(ctor)) != null ? _a : [], label]),
1864
97
  configurable: false,
1865
98
  enumerable: false,
1866
99
  writable: false
1867
100
  });
101
+ const sigilSym = /* @__PURE__ */ Symbol.for("Sigil");
102
+ if (ctor.prototype[sigilSym] !== true)
103
+ Object.defineProperty(ctor.prototype, sigilSym, {
104
+ value: true,
105
+ configurable: false,
106
+ enumerable: false,
107
+ writable: false
108
+ });
1868
109
  }
1869
110
  function isSigilCtor(ctor) {
1870
- return typeof ctor === "function" && ctor[__SIGIL__] === true;
111
+ return typeof ctor === "function" && __SIGIL__ in ctor.prototype;
1871
112
  }
1872
113
  function isSigilInstance(inst) {
1873
- if (!inst || typeof inst !== "object") return false;
1874
- const ctor = getConstructor(inst);
1875
- return isSigilCtor(ctor);
114
+ return !!inst && typeof inst === "object" && __SIGIL__ in inst;
1876
115
  }
1877
- function isSigilBaseCtor(ctor) {
1878
- return Object.hasOwn(ctor, __SIGIL_BASE__);
116
+ function hasOwnSigil(ctor) {
117
+ return typeof ctor === "function" && Object.hasOwn(ctor.prototype, __SIGIL__);
1879
118
  }
1880
- function isSigilBaseInstance(inst) {
1881
- if (!inst || typeof inst !== "object") return false;
1882
- const ctor = getConstructor(inst);
1883
- return isSigilBaseCtor(ctor);
119
+ function labelOf(ctor) {
120
+ return ctor.prototype[__LABEL__];
1884
121
  }
1885
- function isDecorated(ctor) {
1886
- return Object.hasOwn(ctor, __DECORATED__);
122
+ function lineageOf(ctor) {
123
+ return ctor.prototype[__LINEAGE__];
1887
124
  }
1888
- function isInheritanceChecked(ctor) {
1889
- return Object.hasOwn(ctor, __INHERITANCE_CHECKED__);
125
+ function verifyLabel(ctor, label, opts) {
126
+ var _a, _b;
127
+ const labelValidation = (_a = opts == null ? void 0 : opts.labelValidation) != null ? _a : OPTIONS.labelValidation;
128
+ const autofillLabels = (_b = opts == null ? void 0 : opts.autofillLabels) != null ? _b : OPTIONS.autofillLabels;
129
+ if (!label) {
130
+ if (!autofillLabels)
131
+ throw new Error(
132
+ `[Sigil Error] Class '${ctor.name}' is not sigilified with 'autofillLabels' setted to 'false', Make sure to sigilify all Sigil classes or set 'autofillLabels' to 'true'`
133
+ );
134
+ return;
135
+ }
136
+ if (label.startsWith(AUTO_LABEL_PREFEX))
137
+ throw new Error(`'${AUTO_LABEL_PREFEX}' is a prefex reserved by the library`);
138
+ if (labelValidation) {
139
+ let valid;
140
+ if (labelValidation instanceof RegExp) valid = labelValidation.test(label);
141
+ else valid = labelValidation(label);
142
+ if (process.env.NODE_ENV !== "production") {
143
+ if (!valid)
144
+ throw new Error(
145
+ `[Sigil Error] Invalid identity label "${label}". Make sure that supplied label matches validation regex or function`
146
+ );
147
+ }
148
+ }
1890
149
  }
1891
- function getConstructor(obj) {
1892
- var _a, _b, _c;
1893
- if (!obj || typeof obj !== "object") return null;
1894
- return (_c = (_b = obj.constructor) != null ? _b : (_a = Object.getPrototypeOf(obj)) == null ? void 0 : _a.constructor) != null ? _c : null;
150
+ if (!globalThis.__SigilabelCounter) globalThis.__SigilabelCounter = 0;
151
+ function generateRandomLabel(ctor) {
152
+ const namePart = ctor && typeof ctor.name === "string" && ctor.name.length ? ctor.name : "C";
153
+ const counter = globalThis.__SigilabelCounter++;
154
+ const time = Date.now().toString(36);
155
+ const rand = Math.random().toString(36).slice(2, 6);
156
+ return `${AUTO_LABEL_PREFEX}:${namePart}:${time}:${counter.toString(36)}:${rand}`;
1895
157
  }
1896
158
 
1897
- // src/core/mixin.ts
159
+ // src/mixin.ts
1898
160
  function Sigilify(Base, label, opts) {
1899
- if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already sigilified.`);
1900
- let l;
1901
- if (label) {
1902
- verifyLabel(label, opts);
1903
- l = label;
1904
- } else l = generateRandomLabel();
161
+ if (hasOwnSigil(Base))
162
+ throw new Error(
163
+ `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`
164
+ );
1905
165
  class Sigilified extends Base {
1906
166
  /**
1907
167
  * Class-level identity label constant for this sigil constructor.
1908
168
  */
1909
169
  static get SigilLabel() {
1910
- if (!isInheritanceChecked(this)) checkInheritance(this);
1911
- return this[__LABEL__];
170
+ var _a;
171
+ handleSigil(this);
172
+ return (_a = this.prototype) == null ? void 0 : _a[__LABEL__];
1912
173
  }
1913
174
  /**
1914
175
  * Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
1915
176
  */
1916
177
  static get SigilEffectiveLabel() {
1917
- return this[__EFFECTIVE_LABEL__];
178
+ var _a;
179
+ handleSigil(this);
180
+ return (_a = this.prototype) == null ? void 0 : _a[__EFFECTIVE_LABEL__];
1918
181
  }
1919
182
  /**
1920
- * Copy of the linearized sigil type label chain for the current constructor.
183
+ * Linearized sigil type label chain for the current constructor.
1921
184
  *
1922
185
  * Useful for debugging and performing strict lineage comparisons.
1923
186
  *
1924
187
  * @returns An array of labels representing parent → child type labels.
1925
188
  */
1926
189
  static get SigilLabelLineage() {
1927
- var _a;
1928
- if (!isInheritanceChecked(this)) checkInheritance(this);
1929
- return [...(_a = this[__LABEL_LINEAGE__]) != null ? _a : []];
190
+ var _a, _b;
191
+ handleSigil(this);
192
+ return [...(_b = (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__]) != null ? _b : []];
1930
193
  }
1931
194
  /**
1932
- * Copy of the sigil type label set for the current constructor.
1933
- *
1934
- * Useful for quick membership checks (O(1) lookups) and debugging.
195
+ * Sigil type label set for the current constructor.
196
+ * Useful for debugging.
1935
197
  *
1936
198
  * @returns A Readonly Set of labels that represent the type lineage.
1937
199
  */
1938
200
  static get SigilLabelSet() {
1939
- if (!isInheritanceChecked(this)) checkInheritance(this);
1940
- const set = /* @__PURE__ */ new Set();
1941
- for (const s of this[__LABEL_SET__]) set.add(s);
1942
- return set;
201
+ var _a;
202
+ handleSigil(this);
203
+ return (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__];
1943
204
  }
1944
205
  constructor(...args) {
1945
206
  super(...args);
1946
- if (Object.getPrototypeOf(this) !== new.target.prototype)
1947
- Object.setPrototypeOf(this, new.target.prototype);
1948
- const ctor = getConstructor(this);
1949
- if (!ctor) {
1950
- if (process.env.NODE_ENV !== "production")
1951
- throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
1952
- return;
1953
- }
1954
- checkInheritance(ctor);
207
+ const ctor = new.target;
208
+ handleSigil(ctor);
1955
209
  }
1956
210
  /**
1957
211
  * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
@@ -1963,99 +217,86 @@
1963
217
  return isSigilInstance(obj);
1964
218
  }
1965
219
  /**
1966
- * Check whether `other` is (or inherits from) the type represented by the calling constructor.
220
+ * Check whether `other` is (or inherits from) the instance represented by the
221
+ * calling constructor.
1967
222
  *
1968
223
  * This replaces `instanceof` so that checks remain valid across bundles/realms
1969
224
  * and when subclassing.
1970
225
  *
1971
- * @typeParam T - The calling constructor type (narrowing the returned instance type).
1972
- * @param this - The constructor performing the check.
226
+ * @typeParam T - The specific sigil constructor (`this`).
227
+ * @param this - The constructor performing the type check.
1973
228
  * @param other - The object to test.
1974
- * @returns `true` if `other` is an instance of this type or a subtype.
229
+ * @returns A type guard asserting `other` is an instance of the constructor.
1975
230
  */
1976
231
  static isOfType(other) {
1977
232
  var _a;
1978
- if (!isSigilInstance(other)) return false;
1979
- const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
1980
- const thisType = this[__LABEL__];
1981
- return !!otherSet && otherSet.has(thisType);
233
+ handleSigil(this);
234
+ if (other == null || typeof other !== "object") return false;
235
+ return other[(_a = this.prototype) == null ? void 0 : _a[__SIGIL__]] === true;
1982
236
  }
1983
237
  /**
1984
- * Strict lineage check: compares the type label lineage arrays element-by-element.
238
+ * Check whether `other` is exactly the same instance represented by the
239
+ * calling constructor.
1985
240
  *
1986
- * @typeParam T - The calling constructor type.
1987
- * @param this - The constructor performing the check.
241
+ * @typeParam T - The specific sigil constructor (`this`).
242
+ * @param this - The constructor performing the type check.
1988
243
  * @param other - The object to test.
1989
- * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
244
+ * @returns A type guard asserting `other` is an instance of the constructor.
1990
245
  */
1991
- static isOfTypeStrict(other) {
1992
- var _a;
1993
- if (!isSigilInstance(other)) return false;
1994
- const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
1995
- const thisLineage = this[__LABEL_LINEAGE__];
1996
- return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
246
+ static isExactType(other) {
247
+ var _a, _b, _c;
248
+ handleSigil(this);
249
+ if (other == null || typeof other !== "object") return false;
250
+ if (((_a = this.prototype) == null ? void 0 : _a[__LINEAGE__].size) !== ((_b = other[__LINEAGE__]) == null ? void 0 : _b.size))
251
+ return false;
252
+ return other[(_c = this.prototype) == null ? void 0 : _c[__SIGIL__]] === true;
1997
253
  }
1998
254
  /**
1999
- * Check whether `other` is (or inherits from) the type instance.
255
+ * Check whether `other` is (or inherits from) the instance represented by the
256
+ * calling constructor.
2000
257
  *
2001
- * Allows 'instanceof' like checks but in instances.
258
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
259
+ * and when subclassing.
2002
260
  *
2003
- * @typeParam T - The instance type.
2004
- * @param this - The instance performing the check.
261
+ * @typeParam T - The specific sigil constructor (`this`).
262
+ * @param this - The constructor performing the type check.
2005
263
  * @param other - The object to test.
2006
- * @returns `true` if `other` is the same instance of this type or a subtype.
264
+ * @returns A type guard asserting `other` is an instance of the constructor.
2007
265
  */
2008
266
  isOfType(other) {
2009
- var _a;
2010
- if (!isSigilInstance(other)) return false;
2011
- const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
2012
- const thisType = getConstructor(this)[__LABEL__];
2013
- return !!otherSet && otherSet.has(thisType);
267
+ if (other == null || typeof other !== "object") return false;
268
+ return other[this[__SIGIL__]] === true;
2014
269
  }
2015
270
  /**
2016
- * Strict lineage check: compares the type label lineage arrays element-by-element.
271
+ * Check whether `other` is exactly the same instance represented by the
272
+ * calling constructor.
2017
273
  *
2018
- * Allows 'instanceof' like checks but in instances.
2019
- *
2020
- * @typeParam T - The instance type.
2021
- * @param this - The instance performing the check.
274
+ * @typeParam T - The specific sigil constructor (`this`).
275
+ * @param this - The constructor performing the type check.
2022
276
  * @param other - The object to test.
2023
- * @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
277
+ * @returns A type guard asserting `other` is an instance of the constructor.
2024
278
  */
2025
- isOfTypeStrict(other) {
2026
- var _a, _b;
2027
- if (!isSigilInstance(other)) return false;
2028
- const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
2029
- const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__LABEL_LINEAGE__];
2030
- return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
279
+ isExactType(other) {
280
+ var _a;
281
+ if (other == null || typeof other !== "object") return false;
282
+ if (this[__LINEAGE__].size !== ((_a = other[__LINEAGE__]) == null ? void 0 : _a.size)) return false;
283
+ return other[this[__SIGIL__]] === true;
2031
284
  }
2032
285
  /**
2033
286
  * Returns the identity sigil label of this instance's constructor.
2034
287
  *
2035
- * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil.auto-dq62ib6jnvmmlfbjhxh2937h') or '@Sigil.unknown' if constructor is missing.
288
+ * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:mm2gkdwn:0:g1sq').
2036
289
  */
2037
290
  getSigilLabel() {
2038
- const ctor = getConstructor(this);
2039
- if (!ctor) {
2040
- if (process.env.NODE_ENV !== "production")
2041
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
2042
- return "@Sigil.unknown";
2043
- }
2044
- return ctor.SigilLabel;
291
+ return this[__LABEL__];
2045
292
  }
2046
293
  /**
2047
294
  * Returns the human-readable sigil label of this instance's constructor.
2048
295
  *
2049
- * @returns The last passed label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' if constructor is missing.
296
+ * @returns The last passed label string (e.g. '@scope/pkg.ClassName').
2050
297
  */
2051
298
  getSigilEffectiveLabel() {
2052
- const ctor = getConstructor(this);
2053
- if (!ctor) {
2054
- if (process.env.NODE_ENV !== "production")
2055
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
2056
- return "@Sigil.unknown";
2057
- }
2058
- return ctor.SigilEffectiveLabel;
299
+ return this[__EFFECTIVE_LABEL__];
2059
300
  }
2060
301
  /**
2061
302
  * Returns a copy of the sigil type label lineage for this instance's constructor.
@@ -2063,91 +304,69 @@
2063
304
  * @returns readonly array of labels representing the type lineage.
2064
305
  */
2065
306
  getSigilLabelLineage() {
2066
- const ctor = getConstructor(this);
2067
- if (!ctor) {
2068
- if (process.env.NODE_ENV !== "production")
2069
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
2070
- return ["@Sigil.unknown"];
2071
- }
2072
- return ctor.SigilLabelLineage;
307
+ return [...this[__LINEAGE__]];
2073
308
  }
2074
309
  /**
2075
- * Returns a readonly copy of the sigil type label set for this instance's constructor.
310
+ * Returns a copy of the sigil type label lineage set for this instance's constructor.
2076
311
  *
2077
- * @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
312
+ * @returns readonly array of labels representing the type lineage.
2078
313
  */
2079
314
  getSigilLabelSet() {
2080
- const ctor = getConstructor(this);
2081
- if (!ctor) {
2082
- if (process.env.NODE_ENV !== "production")
2083
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
2084
- return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
2085
- }
2086
- return ctor.SigilLabelSet;
315
+ return this[__LINEAGE__];
2087
316
  }
2088
317
  }
2089
- decorateCtor(Sigilified, l, { isMixin: true });
2090
- markSigil(Sigilified);
2091
- markSigilBase(Sigilified);
318
+ handleSigil(Sigilified, label, opts);
2092
319
  return Sigilified;
2093
320
  }
2094
321
  function SigilifyAbstract(Base, label, opts) {
2095
- if (isSigilCtor(Base)) throw new Error(`[Sigil Error] 'Sigilify(${label})' already sigilified.`);
2096
- let l;
2097
- if (label) {
2098
- verifyLabel(label, opts);
2099
- l = label;
2100
- } else l = generateRandomLabel();
322
+ if (hasOwnSigil(Base))
323
+ throw new Error(
324
+ `[Sigil Error] Base class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`
325
+ );
2101
326
  class Sigilified extends Base {
2102
327
  /**
2103
328
  * Class-level identity label constant for this sigil constructor.
2104
329
  */
2105
330
  static get SigilLabel() {
2106
- if (!isInheritanceChecked(this)) checkInheritance(this);
2107
- return this[__LABEL__];
331
+ var _a;
332
+ handleSigil(this);
333
+ return (_a = this.prototype) == null ? void 0 : _a[__LABEL__];
2108
334
  }
2109
335
  /**
2110
336
  * Class-level human-readable label constant for this sigil constructor, last passed label in 'Sigil' chain by developer.
2111
337
  */
2112
338
  static get SigilEffectiveLabel() {
2113
- return this[__EFFECTIVE_LABEL__];
339
+ var _a;
340
+ handleSigil(this);
341
+ return (_a = this.prototype) == null ? void 0 : _a[__EFFECTIVE_LABEL__];
2114
342
  }
2115
343
  /**
2116
- * Copy of the linearized sigil type label chain for the current constructor.
344
+ * Linearized sigil type label chain for the current constructor.
2117
345
  *
2118
346
  * Useful for debugging and performing strict lineage comparisons.
2119
347
  *
2120
348
  * @returns An array of labels representing parent → child type labels.
2121
349
  */
2122
350
  static get SigilLabelLineage() {
2123
- var _a;
2124
- if (!isInheritanceChecked(this)) checkInheritance(this);
2125
- return [...(_a = this[__LABEL_LINEAGE__]) != null ? _a : []];
351
+ var _a, _b;
352
+ handleSigil(this);
353
+ return [...(_b = (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__]) != null ? _b : []];
2126
354
  }
2127
355
  /**
2128
- * Copy of the sigil type label set for the current constructor.
2129
- *
2130
- * Useful for quick membership checks (O(1) lookups) and debugging.
356
+ * Sigil type label set for the current constructor.
357
+ * Useful for debugging.
2131
358
  *
2132
359
  * @returns A Readonly Set of labels that represent the type lineage.
2133
360
  */
2134
361
  static get SigilLabelSet() {
2135
- if (!isInheritanceChecked(this)) checkInheritance(this);
2136
- const set = /* @__PURE__ */ new Set();
2137
- for (const s of this[__LABEL_SET__]) set.add(s);
2138
- return set;
362
+ var _a;
363
+ handleSigil(this);
364
+ return (_a = this.prototype) == null ? void 0 : _a[__LINEAGE__];
2139
365
  }
2140
366
  constructor(...args) {
2141
367
  super(...args);
2142
- if (Object.getPrototypeOf(this) !== new.target.prototype)
2143
- Object.setPrototypeOf(this, new.target.prototype);
2144
- const ctor = getConstructor(this);
2145
- if (!ctor) {
2146
- if (process.env.NODE_ENV !== "production")
2147
- throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
2148
- return;
2149
- }
2150
- checkInheritance(ctor);
368
+ const ctor = new.target;
369
+ handleSigil(ctor);
2151
370
  }
2152
371
  /**
2153
372
  * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
@@ -2159,107 +378,84 @@
2159
378
  return isSigilInstance(obj);
2160
379
  }
2161
380
  /**
2162
- * Check whether `other` is (or inherits from) the type represented by the calling constructor.
2163
- *
2164
- * Implementation detail:
2165
- * - Uses the other instance's `__LABEL_SET__` for O(1) membership test.
2166
- * - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
381
+ * Check whether `other` is (or inherits from) the instance represented by the
382
+ * calling constructor.
2167
383
  *
2168
384
  * This replaces `instanceof` so that checks remain valid across bundles/realms
2169
385
  * and when subclassing.
2170
386
  *
2171
- * @typeParam T - The calling constructor type (narrowing the returned instance type).
2172
- * @param this - The constructor performing the check.
387
+ * @typeParam T - The specific sigil constructor (`this`).
388
+ * @param this - The constructor performing the type check.
2173
389
  * @param other - The object to test.
2174
- * @returns `true` if `other` is an instance of this type or a subtype.
390
+ * @returns A type guard asserting `other` is an instance of the constructor.
2175
391
  */
2176
392
  static isOfType(other) {
2177
393
  var _a;
2178
- if (!isSigilInstance(other)) return false;
2179
- const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
2180
- const thisType = this[__LABEL__];
2181
- return !!otherSet && otherSet.has(thisType);
394
+ if (other == null || typeof other !== "object") return false;
395
+ return other[(_a = this.prototype) == null ? void 0 : _a[__SIGIL__]] === true;
2182
396
  }
2183
397
  /**
2184
- * Strict lineage check: compares the type label lineage arrays element-by-element.
2185
- *
2186
- * Implementation detail:
2187
- * - Works in O(n) time where n is the depth of the lineage.
2188
- * - Reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
398
+ * Check whether `other` is exactly the same instance represented by the
399
+ * calling constructor.
2189
400
  *
2190
- * @typeParam T - The calling constructor type.
2191
- * @param this - The constructor performing the check.
401
+ * @typeParam T - The specific sigil constructor (`this`).
402
+ * @param this - The constructor performing the type check.
2192
403
  * @param other - The object to test.
2193
- * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
404
+ * @returns A type guard asserting `other` is an instance of the constructor.
2194
405
  */
2195
- static isOfTypeStrict(other) {
2196
- var _a;
2197
- if (!isSigilInstance(other)) return false;
2198
- const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
2199
- const thisLineage = this[__LABEL_LINEAGE__];
2200
- return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
406
+ static isExactType(other) {
407
+ var _a, _b, _c;
408
+ if (other == null || typeof other !== "object") return false;
409
+ if (((_a = this.prototype) == null ? void 0 : _a[__LINEAGE__].size) !== ((_b = other[__LINEAGE__]) == null ? void 0 : _b.size))
410
+ return false;
411
+ return other[(_c = this.prototype) == null ? void 0 : _c[__SIGIL__]] === true;
2201
412
  }
2202
413
  /**
2203
- * Check whether `other` is (or inherits from) the type instance.
414
+ * Check whether `other` is (or inherits from) the instance represented by the
415
+ * calling constructor.
2204
416
  *
2205
- * Allows 'instanceof' like checks but in instances.
417
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
418
+ * and when subclassing.
2206
419
  *
2207
- * @typeParam T - The instance type.
2208
- * @param this - The instance performing the check.
420
+ * @typeParam T - The specific sigil constructor (`this`).
421
+ * @param this - The constructor performing the type check.
2209
422
  * @param other - The object to test.
2210
- * @returns `true` if `other` is the same instance of this type or a subtype.
423
+ * @returns A type guard asserting `other` is an instance of the constructor.
2211
424
  */
2212
425
  isOfType(other) {
2213
- var _a;
2214
- if (!isSigilInstance(other)) return false;
2215
- const otherSet = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_SET__];
2216
- const thisType = getConstructor(this)[__LABEL__];
2217
- return !!otherSet && otherSet.has(thisType);
426
+ if (other == null || typeof other !== "object") return false;
427
+ return other[this[__SIGIL__]] === true;
2218
428
  }
2219
429
  /**
2220
- * Strict lineage check: compares the type label lineage arrays element-by-element.
2221
- *
2222
- * Allows 'instanceof' like checks but in instances.
430
+ * Check whether `other` is exactly the same instance represented by the
431
+ * calling constructor.
2223
432
  *
2224
- * @typeParam T - The instance type.
2225
- * @param this - The instance performing the check.
433
+ * @typeParam T - The specific sigil constructor (`this`).
434
+ * @param this - The constructor performing the type check.
2226
435
  * @param other - The object to test.
2227
- * @returns `true` if `other` has an identical lineage up to the length of this instance's lineage.
436
+ * @returns A type guard asserting `other` is an instance of the constructor.
2228
437
  */
2229
- isOfTypeStrict(other) {
2230
- var _a, _b;
2231
- if (!isSigilInstance(other)) return false;
2232
- const otherLineage = (_a = getConstructor(other)) == null ? void 0 : _a[__LABEL_LINEAGE__];
2233
- const thisLineage = (_b = getConstructor(this)) == null ? void 0 : _b[__LABEL_LINEAGE__];
2234
- return !!otherLineage && thisLineage.every((s, i) => s === otherLineage[i]);
438
+ isExactType(other) {
439
+ var _a;
440
+ if (other == null || typeof other !== "object") return false;
441
+ if (this[__LINEAGE__].size !== ((_a = other[__LINEAGE__]) == null ? void 0 : _a.size)) return false;
442
+ return other[this[__SIGIL__]] === true;
2235
443
  }
2236
444
  /**
2237
445
  * Returns the identity sigil label of this instance's constructor.
2238
446
  *
2239
- * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil.auto-dq62ib6jnvmmlfbjhxh2937h') or '@Sigil.unknown' if constructor is missing.
447
+ * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:mm2gkdwn:0:g1sq').
2240
448
  */
2241
449
  getSigilLabel() {
2242
- const ctor = getConstructor(this);
2243
- if (!ctor) {
2244
- if (process.env.NODE_ENV !== "production")
2245
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
2246
- return "@Sigil.unknown";
2247
- }
2248
- return ctor.SigilLabel;
450
+ return this[__LABEL__];
2249
451
  }
2250
452
  /**
2251
453
  * Returns the human-readable sigil label of this instance's constructor.
2252
454
  *
2253
- * @returns The last passed label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' if constructor is missing.
455
+ * @returns The last passed label string (e.g. '@scope/pkg.ClassName').
2254
456
  */
2255
457
  getSigilEffectiveLabel() {
2256
- const ctor = getConstructor(this);
2257
- if (!ctor) {
2258
- if (process.env.NODE_ENV !== "production")
2259
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
2260
- return "@Sigil.unknown";
2261
- }
2262
- return ctor.SigilEffectiveLabel;
458
+ return this[__EFFECTIVE_LABEL__];
2263
459
  }
2264
460
  /**
2265
461
  * Returns a copy of the sigil type label lineage for this instance's constructor.
@@ -2267,96 +463,56 @@
2267
463
  * @returns readonly array of labels representing the type lineage.
2268
464
  */
2269
465
  getSigilLabelLineage() {
2270
- const ctor = getConstructor(this);
2271
- if (!ctor) {
2272
- if (process.env.NODE_ENV !== "production")
2273
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
2274
- return ["@Sigil.unknown"];
2275
- }
2276
- return ctor.SigilLabelLineage;
466
+ return [...this[__LINEAGE__]];
2277
467
  }
2278
468
  /**
2279
- * Returns a readonly copy of the sigil type label set for this instance's constructor.
469
+ * Returns a copy of the sigil type label lineage set for this instance's constructor.
2280
470
  *
2281
- * @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
471
+ * @returns readonly array of labels representing the type lineage.
2282
472
  */
2283
473
  getSigilLabelSet() {
2284
- const ctor = getConstructor(this);
2285
- if (!ctor) {
2286
- if (process.env.NODE_ENV !== "production")
2287
- throw new Error(`[Sigil Error] Sigil class instance without constructor`);
2288
- return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
2289
- }
2290
- return ctor.SigilLabelSet;
474
+ return this[__LINEAGE__];
2291
475
  }
2292
476
  }
2293
- decorateCtor(Sigilified, l, { isMixin: true });
2294
- markSigil(Sigilified);
2295
- markSigilBase(Sigilified);
477
+ handleSigil(Sigilified, label, opts);
2296
478
  return Sigilified;
2297
479
  }
2298
480
 
2299
- // src/core/classes.ts
481
+ // src/classes.ts
2300
482
  var Sigil = Sigilify(class {
2301
483
  }, "Sigil");
2302
484
  var SigilError = Sigilify(Error, "SigilError");
2303
485
 
2304
- // src/core/decorator.ts
486
+ // src/decorator.ts
2305
487
  function WithSigil(label, opts) {
2306
- let l;
2307
- if (label) {
2308
- verifyLabel(label, opts);
2309
- l = label;
2310
- } else l = generateRandomLabel();
2311
488
  return function(value, context) {
2312
489
  if (context.kind !== "class") return;
2313
490
  if (!isSigilCtor(value))
2314
491
  throw new Error(
2315
492
  `[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${value.name}`
2316
493
  );
2317
- decorateCtor(value, l);
2318
- checkInheritance(value, opts);
494
+ if (hasOwnSigil(value))
495
+ throw new Error(
496
+ `[Sigil Error] Class '${value.name}' with label '${value.SigilLabel}' is already sigilified`
497
+ );
498
+ handleSigil(value, label, opts);
2319
499
  };
2320
500
  }
2321
501
 
2322
- // src/core/hof.ts
502
+ // src/hof.ts
2323
503
  function withSigil(Class, label, opts) {
2324
504
  var _a;
2325
505
  if (!isSigilCtor(Class))
2326
506
  throw new Error(
2327
507
  `[Sigil Error] 'withSigil' HOF accept only Sigil classes but used on class ${(_a = Class == null ? void 0 : Class.name) != null ? _a : "unknown"}`
2328
508
  );
2329
- let l;
2330
- if (label) {
2331
- verifyLabel(label, opts);
2332
- l = label;
2333
- } else l = generateRandomLabel();
2334
- const ctor = Class;
2335
- decorateCtor(ctor, l);
2336
- checkInheritance(ctor, opts);
2337
- return Class;
2338
- }
2339
- function withSigilTyped(Class, label, opts) {
2340
- var _a;
2341
- if (!isSigilCtor(Class))
509
+ if (hasOwnSigil(Class))
2342
510
  throw new Error(
2343
- `[Sigil Error] 'withSigilTyped' HOF accept only Sigil classes but used on class ${(_a = Class == null ? void 0 : Class.name) != null ? _a : "unknown"}`
511
+ `[Sigil Error] Class '${Class.name}' with label '${Class.SigilLabel}' is already sigilified`
2344
512
  );
2345
- let l;
2346
- if (label) {
2347
- verifyLabel(label, opts);
2348
- l = label;
2349
- } else l = generateRandomLabel();
2350
- const ctor = Class;
2351
- decorateCtor(ctor, l);
2352
- checkInheritance(ctor, opts);
513
+ handleSigil(Class, label, opts);
2353
514
  return Class;
2354
515
  }
2355
- /*! Bundled license information:
2356
-
2357
- @noble/hashes/utils.js:
2358
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2359
- */
2360
516
 
2361
517
  exports.DEFAULT_LABEL_REGEX = DEFAULT_LABEL_REGEX;
2362
518
  exports.Sigil = Sigil;
@@ -2364,15 +520,10 @@
2364
520
  exports.Sigilify = Sigilify;
2365
521
  exports.SigilifyAbstract = SigilifyAbstract;
2366
522
  exports.WithSigil = WithSigil;
2367
- exports.isDecorated = isDecorated;
2368
- exports.isInheritanceChecked = isInheritanceChecked;
2369
- exports.isSigilBaseCtor = isSigilBaseCtor;
2370
- exports.isSigilBaseInstance = isSigilBaseInstance;
2371
523
  exports.isSigilCtor = isSigilCtor;
2372
524
  exports.isSigilInstance = isSigilInstance;
2373
525
  exports.updateSigilOptions = updateSigilOptions;
2374
526
  exports.withSigil = withSigil;
2375
- exports.withSigilTyped = withSigilTyped;
2376
527
 
2377
528
  return exports;
2378
529