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