storybook 10.0.0-beta.0 → 10.0.0-beta.10
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/assets/server/openBrowser.applescript +94 -0
- package/dist/_browser-chunks/Color-KPLIACXP.js +1569 -0
- package/dist/_browser-chunks/{WithTooltip-2E62HIBN.js → WithTooltip-SK46ZJ2J.js} +1 -1
- package/dist/_browser-chunks/{chunk-YY5GICNT.js → chunk-6E2SHJSL.js} +175 -32
- package/dist/_browser-chunks/{chunk-FWKO3E35.js → chunk-BOOOPFZF.js} +10 -3
- package/dist/_browser-chunks/{chunk-YWDKX534.js → chunk-FA42P6MO.js} +49 -4
- package/dist/_browser-chunks/chunk-G33S6YM3.js +521 -0
- package/dist/_browser-chunks/{chunk-MZNYTCNT.js → chunk-HMIIJ6UD.js} +6 -6
- package/dist/_browser-chunks/{chunk-4QPX7WIQ.js → chunk-JJZMHC3A.js} +57 -166
- package/dist/_browser-chunks/{chunk-MD2FTHCZ.js → chunk-JVSKG4YS.js} +3 -16
- package/dist/_browser-chunks/{chunk-E7VLET3C.js → chunk-KSCAWCCE.js} +3947 -4291
- package/dist/_browser-chunks/{chunk-PYK5ZTFK.js → chunk-PS3AOQI4.js} +48 -25
- package/dist/_browser-chunks/chunk-QK3L5AXO.js +372 -0
- package/dist/_browser-chunks/chunk-SHR3NNR3.js +5810 -0
- package/dist/_browser-chunks/{chunk-O5R5CGFA.js → chunk-TMDZCWME.js} +1 -2
- package/dist/_browser-chunks/chunk-VUAFL5XK.js +20 -0
- package/dist/_browser-chunks/{chunk-T7RCAJIX.js → chunk-Y3M7TW6K.js} +43 -47
- package/dist/_browser-chunks/{syntaxhighlighter-YYAA4CS4.js → syntaxhighlighter-R46XOLMC.js} +1 -1
- package/dist/_node-chunks/{builder-manager-OW6YGKXV.js → builder-manager-SJGIDEN6.js} +45 -155
- package/dist/_node-chunks/camelcase-VZHWABQV.js +18 -0
- package/dist/_node-chunks/{chunk-6JSVPEAU.js → chunk-6CZW7AGN.js} +7 -7
- package/dist/_node-chunks/{chunk-CD3IP6HA.js → chunk-6XT5OLNL.js} +12 -12
- package/dist/_node-chunks/{chunk-2H7LZ2SD.js → chunk-AHRH5RPR.js} +7 -7
- package/dist/_node-chunks/{chunk-5HLANIBM.js → chunk-AOH6ABSV.js} +7 -7
- package/dist/_node-chunks/chunk-C5V22GP7.js +79 -0
- package/dist/_node-chunks/{chunk-IBXERYDG.js → chunk-FIROF4DV.js} +7 -7
- package/dist/_node-chunks/{chunk-I3YCPGZJ.js → chunk-GUJVZUYI.js} +7 -7
- package/dist/_node-chunks/chunk-IHPLRRAR.js +4741 -0
- package/dist/_node-chunks/{chunk-7TISOZS6.js → chunk-JMXKCRWR.js} +30 -21
- package/dist/_node-chunks/{chunk-YWGNEBRO.js → chunk-JUMUXWEV.js} +162 -103
- package/dist/_node-chunks/{chunk-UIREEOC7.js → chunk-KGX33KXX.js} +7 -7
- package/dist/_node-chunks/{chunk-3QB3ZG6H.js → chunk-KLVABNEU.js} +7 -7
- package/dist/_node-chunks/{chunk-H5LTFJHQ.js → chunk-OL6DY6BT.js} +631 -752
- package/dist/_node-chunks/{chunk-X5GAZ3EW.js → chunk-ONJV3K2L.js} +399 -116
- package/dist/_node-chunks/{chunk-LKB7KRSV.js → chunk-PTHTD4RO.js} +223 -243
- package/dist/_node-chunks/{chunk-UHHZPSP7.js → chunk-QQ3Z5KGJ.js} +6 -6
- package/dist/_node-chunks/{chunk-MUD3GH3L.js → chunk-QRTDDTZJ.js} +9 -9
- package/dist/_node-chunks/chunk-R54K4KSM.js +1540 -0
- package/dist/_node-chunks/{chunk-IQAUGVYR.js → chunk-S2LZC6JK.js} +8 -8
- package/dist/_node-chunks/chunk-SFJFSPRT.js +62 -0
- package/dist/_node-chunks/{chunk-LH3BEEIR.js → chunk-SSN5PKIY.js} +6 -6
- package/dist/_node-chunks/{chunk-NOQITS3C.js → chunk-SXR2DITB.js} +7 -7
- package/dist/_node-chunks/{chunk-FWUE7SRE.js → chunk-TH5QVQRL.js} +7 -7
- package/dist/_node-chunks/chunk-U34NWAU2.js +18 -0
- package/dist/_node-chunks/{chunk-FBMMEEO4.js → chunk-UV3CZ3KS.js} +7 -7
- package/dist/_node-chunks/{chunk-NZGJJABJ.js → chunk-UVUGJDAI.js} +60 -102
- package/dist/_node-chunks/{chunk-GZUNYRFU.js → chunk-VOUNSD2E.js} +7 -7
- package/dist/_node-chunks/chunk-WFCPBKQJ.js +64656 -0
- package/dist/_node-chunks/{chunk-BFXER3XW.js → chunk-XHF3WWNP.js} +623 -750
- package/dist/_node-chunks/{chunk-ANEKBWDX.js → chunk-XU45KXNQ.js} +16 -25
- package/dist/_node-chunks/{camelcase-2K3EMR6G.js → chunk-YHO6XR7U.js} +9 -8
- package/dist/_node-chunks/{dist-465RSKRC.js → dist-IIC5PBL7.js} +9 -9
- package/dist/_node-chunks/{globby-LJ3MVB6M.js → globby-CJACC3HJ.js} +17 -13
- package/dist/_node-chunks/{lib-OW3DENXB.js → lib-ZY4TKSOR.js} +40 -16
- package/dist/_node-chunks/{mdx-N42X6CFJ-PYX2IFUO.js → mdx-N42X6CFJ-3XNW3DFO.js} +8 -8
- package/dist/_node-chunks/{p-limit-X4OG45RB.js → p-limit-R2OFT5HE.js} +76 -10
- package/dist/_node-chunks/{plugin-ALTIQMDE.js → plugin-5XD5R2KD.js} +10 -10
- package/dist/_node-chunks/{plugin-GE36R32R.js → plugin-WAWVQMVR.js} +10 -12
- package/dist/_node-chunks/{webpack-inject-mocker-runtime-plugin-NLCAF7S6.js → webpack-inject-mocker-runtime-plugin-SCRGJLIS.js} +1307 -847
- package/dist/_node-chunks/{webpack-mock-plugin-BRYODMCC.js → webpack-mock-plugin-3VAXEGG2.js} +9 -11
- package/dist/babel/index.d.ts +1 -1
- package/dist/babel/index.js +11 -12
- package/dist/bin/core.js +638 -187
- package/dist/bin/dispatcher.js +11 -11
- package/dist/bin/loader.js +8 -8
- package/dist/cli/index.d.ts +62 -75
- package/dist/cli/index.js +66 -56
- package/dist/common/index.d.ts +3 -1
- package/dist/common/index.js +22 -22
- package/dist/components/index.d.ts +234 -2
- package/dist/components/index.js +74 -5741
- package/dist/core-events/index.d.ts +18 -2
- package/dist/core-events/index.js +7 -1
- package/dist/core-server/index.d.ts +540 -39
- package/dist/core-server/index.js +4647 -4182
- package/dist/core-server/presets/common-manager.js +1570 -1272
- package/dist/core-server/presets/common-override-preset.js +9 -9
- package/dist/core-server/presets/common-preset.js +691 -38
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +9 -11
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +10 -12
- package/dist/csf/index.d.ts +9 -4
- package/dist/csf/index.js +50 -15
- package/dist/csf-tools/index.d.ts +47 -6
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +4 -4
- package/dist/instrumenter/index.js +1 -1
- package/dist/manager/globals-runtime.js +9233 -18113
- package/dist/manager/globals.d.ts +0 -4
- package/dist/manager/globals.js +1 -6
- package/dist/manager/runtime.js +13396 -11518
- package/dist/manager-api/index.d.ts +540 -32
- package/dist/manager-api/index.js +364 -90
- package/dist/manager-errors.d.ts +527 -0
- package/dist/node-logger/index.d.ts +1 -1
- package/dist/node-logger/index.js +1136 -662
- package/dist/preview/globals.js +1 -1
- package/dist/preview/runtime.js +12103 -21579
- package/dist/preview-api/index.d.ts +3 -3
- package/dist/preview-api/index.js +10 -10
- package/dist/preview-errors.d.ts +527 -0
- package/dist/router/index.d.ts +668 -10
- package/dist/router/index.js +2 -2
- package/dist/server-errors.d.ts +527 -0
- package/dist/server-errors.js +10 -10
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +23 -25
- package/dist/test/index.js +1874 -4024
- package/dist/theming/index.d.ts +2 -2
- package/dist/theming/index.js +6 -6
- package/dist/types/index.d.ts +553 -16
- package/dist/viewport/index.d.ts +36 -4
- package/dist/viewport/index.js +1 -1
- package/package.json +9 -46
- package/dist/_browser-chunks/Color-SFYJJKWL.js +0 -605
- package/dist/_browser-chunks/chunk-DHO2SA6L.js +0 -12
- package/dist/_browser-chunks/chunk-WPHPDNUA.js +0 -974
- package/dist/_node-chunks/chunk-27W2Z6VL.js +0 -28502
- package/dist/_node-chunks/chunk-G46DWX7Z.js +0 -266
- package/dist/_node-chunks/chunk-GZZDIJIB.js +0 -80
- package/dist/_node-chunks/chunk-JDKH3XYB.js +0 -9845
- package/dist/_node-chunks/chunk-R7RKO2DC.js +0 -35783
- package/dist/_node-chunks/chunk-T23YQHYB.js +0 -62
- package/dist/_node-chunks/chunk-VKKLKNFC.js +0 -2377
- package/dist/_node-chunks/chunk-W6GKFQ7F.js +0 -87
- package/dist/_node-chunks/chunk-YUYBO6S7.js +0 -18
- package/dist/_node-chunks/default-browser-id-Z6WQ7DZA.js +0 -1719
|
@@ -1,1719 +0,0 @@
|
|
|
1
|
-
import CJS_COMPAT_NODE_URL_qlimw951jq from 'node:url';
|
|
2
|
-
import CJS_COMPAT_NODE_PATH_qlimw951jq from 'node:path';
|
|
3
|
-
import CJS_COMPAT_NODE_MODULE_qlimw951jq from "node:module";
|
|
4
|
-
|
|
5
|
-
var __filename = CJS_COMPAT_NODE_URL_qlimw951jq.fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = CJS_COMPAT_NODE_PATH_qlimw951jq.dirname(__filename);
|
|
7
|
-
var require = CJS_COMPAT_NODE_MODULE_qlimw951jq.createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
// ------------------------------------------------------------
|
|
10
|
-
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
-
// ------------------------------------------------------------
|
|
12
|
-
import {
|
|
13
|
-
__commonJS,
|
|
14
|
-
__esm,
|
|
15
|
-
__name,
|
|
16
|
-
__require,
|
|
17
|
-
__toESM
|
|
18
|
-
} from "./chunk-LH3BEEIR.js";
|
|
19
|
-
|
|
20
|
-
// ../node_modules/big-integer/BigInteger.js
|
|
21
|
-
var require_BigInteger = __commonJS({
|
|
22
|
-
"../node_modules/big-integer/BigInteger.js"(exports, module) {
|
|
23
|
-
var bigInt = function(undefined) {
|
|
24
|
-
"use strict";
|
|
25
|
-
var BASE = 1e7, LOG_BASE = 7, MAX_INT = 9007199254740992, MAX_INT_ARR = smallToArray(MAX_INT), DEFAULT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
26
|
-
var supportsNativeBigInt = typeof BigInt === "function";
|
|
27
|
-
function Integer(v, radix, alphabet, caseSensitive) {
|
|
28
|
-
if (typeof v === "undefined") return Integer[0];
|
|
29
|
-
if (typeof radix !== "undefined") return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive);
|
|
30
|
-
return parseValue(v);
|
|
31
|
-
}
|
|
32
|
-
__name(Integer, "Integer");
|
|
33
|
-
function BigInteger(value, sign) {
|
|
34
|
-
this.value = value;
|
|
35
|
-
this.sign = sign;
|
|
36
|
-
this.isSmall = false;
|
|
37
|
-
}
|
|
38
|
-
__name(BigInteger, "BigInteger");
|
|
39
|
-
BigInteger.prototype = Object.create(Integer.prototype);
|
|
40
|
-
function SmallInteger(value) {
|
|
41
|
-
this.value = value;
|
|
42
|
-
this.sign = value < 0;
|
|
43
|
-
this.isSmall = true;
|
|
44
|
-
}
|
|
45
|
-
__name(SmallInteger, "SmallInteger");
|
|
46
|
-
SmallInteger.prototype = Object.create(Integer.prototype);
|
|
47
|
-
function NativeBigInt(value) {
|
|
48
|
-
this.value = value;
|
|
49
|
-
}
|
|
50
|
-
__name(NativeBigInt, "NativeBigInt");
|
|
51
|
-
NativeBigInt.prototype = Object.create(Integer.prototype);
|
|
52
|
-
function isPrecise(n) {
|
|
53
|
-
return -MAX_INT < n && n < MAX_INT;
|
|
54
|
-
}
|
|
55
|
-
__name(isPrecise, "isPrecise");
|
|
56
|
-
function smallToArray(n) {
|
|
57
|
-
if (n < 1e7)
|
|
58
|
-
return [n];
|
|
59
|
-
if (n < 1e14)
|
|
60
|
-
return [n % 1e7, Math.floor(n / 1e7)];
|
|
61
|
-
return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)];
|
|
62
|
-
}
|
|
63
|
-
__name(smallToArray, "smallToArray");
|
|
64
|
-
function arrayToSmall(arr) {
|
|
65
|
-
trim(arr);
|
|
66
|
-
var length = arr.length;
|
|
67
|
-
if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {
|
|
68
|
-
switch (length) {
|
|
69
|
-
case 0:
|
|
70
|
-
return 0;
|
|
71
|
-
case 1:
|
|
72
|
-
return arr[0];
|
|
73
|
-
case 2:
|
|
74
|
-
return arr[0] + arr[1] * BASE;
|
|
75
|
-
default:
|
|
76
|
-
return arr[0] + (arr[1] + arr[2] * BASE) * BASE;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return arr;
|
|
80
|
-
}
|
|
81
|
-
__name(arrayToSmall, "arrayToSmall");
|
|
82
|
-
function trim(v) {
|
|
83
|
-
var i2 = v.length;
|
|
84
|
-
while (v[--i2] === 0) ;
|
|
85
|
-
v.length = i2 + 1;
|
|
86
|
-
}
|
|
87
|
-
__name(trim, "trim");
|
|
88
|
-
function createArray(length) {
|
|
89
|
-
var x = new Array(length);
|
|
90
|
-
var i2 = -1;
|
|
91
|
-
while (++i2 < length) {
|
|
92
|
-
x[i2] = 0;
|
|
93
|
-
}
|
|
94
|
-
return x;
|
|
95
|
-
}
|
|
96
|
-
__name(createArray, "createArray");
|
|
97
|
-
function truncate(n) {
|
|
98
|
-
if (n > 0) return Math.floor(n);
|
|
99
|
-
return Math.ceil(n);
|
|
100
|
-
}
|
|
101
|
-
__name(truncate, "truncate");
|
|
102
|
-
function add(a, b) {
|
|
103
|
-
var l_a = a.length, l_b = b.length, r = new Array(l_a), carry = 0, base = BASE, sum, i2;
|
|
104
|
-
for (i2 = 0; i2 < l_b; i2++) {
|
|
105
|
-
sum = a[i2] + b[i2] + carry;
|
|
106
|
-
carry = sum >= base ? 1 : 0;
|
|
107
|
-
r[i2] = sum - carry * base;
|
|
108
|
-
}
|
|
109
|
-
while (i2 < l_a) {
|
|
110
|
-
sum = a[i2] + carry;
|
|
111
|
-
carry = sum === base ? 1 : 0;
|
|
112
|
-
r[i2++] = sum - carry * base;
|
|
113
|
-
}
|
|
114
|
-
if (carry > 0) r.push(carry);
|
|
115
|
-
return r;
|
|
116
|
-
}
|
|
117
|
-
__name(add, "add");
|
|
118
|
-
function addAny(a, b) {
|
|
119
|
-
if (a.length >= b.length) return add(a, b);
|
|
120
|
-
return add(b, a);
|
|
121
|
-
}
|
|
122
|
-
__name(addAny, "addAny");
|
|
123
|
-
function addSmall(a, carry) {
|
|
124
|
-
var l = a.length, r = new Array(l), base = BASE, sum, i2;
|
|
125
|
-
for (i2 = 0; i2 < l; i2++) {
|
|
126
|
-
sum = a[i2] - base + carry;
|
|
127
|
-
carry = Math.floor(sum / base);
|
|
128
|
-
r[i2] = sum - carry * base;
|
|
129
|
-
carry += 1;
|
|
130
|
-
}
|
|
131
|
-
while (carry > 0) {
|
|
132
|
-
r[i2++] = carry % base;
|
|
133
|
-
carry = Math.floor(carry / base);
|
|
134
|
-
}
|
|
135
|
-
return r;
|
|
136
|
-
}
|
|
137
|
-
__name(addSmall, "addSmall");
|
|
138
|
-
BigInteger.prototype.add = function(v) {
|
|
139
|
-
var n = parseValue(v);
|
|
140
|
-
if (this.sign !== n.sign) {
|
|
141
|
-
return this.subtract(n.negate());
|
|
142
|
-
}
|
|
143
|
-
var a = this.value, b = n.value;
|
|
144
|
-
if (n.isSmall) {
|
|
145
|
-
return new BigInteger(addSmall(a, Math.abs(b)), this.sign);
|
|
146
|
-
}
|
|
147
|
-
return new BigInteger(addAny(a, b), this.sign);
|
|
148
|
-
};
|
|
149
|
-
BigInteger.prototype.plus = BigInteger.prototype.add;
|
|
150
|
-
SmallInteger.prototype.add = function(v) {
|
|
151
|
-
var n = parseValue(v);
|
|
152
|
-
var a = this.value;
|
|
153
|
-
if (a < 0 !== n.sign) {
|
|
154
|
-
return this.subtract(n.negate());
|
|
155
|
-
}
|
|
156
|
-
var b = n.value;
|
|
157
|
-
if (n.isSmall) {
|
|
158
|
-
if (isPrecise(a + b)) return new SmallInteger(a + b);
|
|
159
|
-
b = smallToArray(Math.abs(b));
|
|
160
|
-
}
|
|
161
|
-
return new BigInteger(addSmall(b, Math.abs(a)), a < 0);
|
|
162
|
-
};
|
|
163
|
-
SmallInteger.prototype.plus = SmallInteger.prototype.add;
|
|
164
|
-
NativeBigInt.prototype.add = function(v) {
|
|
165
|
-
return new NativeBigInt(this.value + parseValue(v).value);
|
|
166
|
-
};
|
|
167
|
-
NativeBigInt.prototype.plus = NativeBigInt.prototype.add;
|
|
168
|
-
function subtract(a, b) {
|
|
169
|
-
var a_l = a.length, b_l = b.length, r = new Array(a_l), borrow = 0, base = BASE, i2, difference;
|
|
170
|
-
for (i2 = 0; i2 < b_l; i2++) {
|
|
171
|
-
difference = a[i2] - borrow - b[i2];
|
|
172
|
-
if (difference < 0) {
|
|
173
|
-
difference += base;
|
|
174
|
-
borrow = 1;
|
|
175
|
-
} else borrow = 0;
|
|
176
|
-
r[i2] = difference;
|
|
177
|
-
}
|
|
178
|
-
for (i2 = b_l; i2 < a_l; i2++) {
|
|
179
|
-
difference = a[i2] - borrow;
|
|
180
|
-
if (difference < 0) difference += base;
|
|
181
|
-
else {
|
|
182
|
-
r[i2++] = difference;
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
r[i2] = difference;
|
|
186
|
-
}
|
|
187
|
-
for (; i2 < a_l; i2++) {
|
|
188
|
-
r[i2] = a[i2];
|
|
189
|
-
}
|
|
190
|
-
trim(r);
|
|
191
|
-
return r;
|
|
192
|
-
}
|
|
193
|
-
__name(subtract, "subtract");
|
|
194
|
-
function subtractAny(a, b, sign) {
|
|
195
|
-
var value;
|
|
196
|
-
if (compareAbs(a, b) >= 0) {
|
|
197
|
-
value = subtract(a, b);
|
|
198
|
-
} else {
|
|
199
|
-
value = subtract(b, a);
|
|
200
|
-
sign = !sign;
|
|
201
|
-
}
|
|
202
|
-
value = arrayToSmall(value);
|
|
203
|
-
if (typeof value === "number") {
|
|
204
|
-
if (sign) value = -value;
|
|
205
|
-
return new SmallInteger(value);
|
|
206
|
-
}
|
|
207
|
-
return new BigInteger(value, sign);
|
|
208
|
-
}
|
|
209
|
-
__name(subtractAny, "subtractAny");
|
|
210
|
-
function subtractSmall(a, b, sign) {
|
|
211
|
-
var l = a.length, r = new Array(l), carry = -b, base = BASE, i2, difference;
|
|
212
|
-
for (i2 = 0; i2 < l; i2++) {
|
|
213
|
-
difference = a[i2] + carry;
|
|
214
|
-
carry = Math.floor(difference / base);
|
|
215
|
-
difference %= base;
|
|
216
|
-
r[i2] = difference < 0 ? difference + base : difference;
|
|
217
|
-
}
|
|
218
|
-
r = arrayToSmall(r);
|
|
219
|
-
if (typeof r === "number") {
|
|
220
|
-
if (sign) r = -r;
|
|
221
|
-
return new SmallInteger(r);
|
|
222
|
-
}
|
|
223
|
-
return new BigInteger(r, sign);
|
|
224
|
-
}
|
|
225
|
-
__name(subtractSmall, "subtractSmall");
|
|
226
|
-
BigInteger.prototype.subtract = function(v) {
|
|
227
|
-
var n = parseValue(v);
|
|
228
|
-
if (this.sign !== n.sign) {
|
|
229
|
-
return this.add(n.negate());
|
|
230
|
-
}
|
|
231
|
-
var a = this.value, b = n.value;
|
|
232
|
-
if (n.isSmall)
|
|
233
|
-
return subtractSmall(a, Math.abs(b), this.sign);
|
|
234
|
-
return subtractAny(a, b, this.sign);
|
|
235
|
-
};
|
|
236
|
-
BigInteger.prototype.minus = BigInteger.prototype.subtract;
|
|
237
|
-
SmallInteger.prototype.subtract = function(v) {
|
|
238
|
-
var n = parseValue(v);
|
|
239
|
-
var a = this.value;
|
|
240
|
-
if (a < 0 !== n.sign) {
|
|
241
|
-
return this.add(n.negate());
|
|
242
|
-
}
|
|
243
|
-
var b = n.value;
|
|
244
|
-
if (n.isSmall) {
|
|
245
|
-
return new SmallInteger(a - b);
|
|
246
|
-
}
|
|
247
|
-
return subtractSmall(b, Math.abs(a), a >= 0);
|
|
248
|
-
};
|
|
249
|
-
SmallInteger.prototype.minus = SmallInteger.prototype.subtract;
|
|
250
|
-
NativeBigInt.prototype.subtract = function(v) {
|
|
251
|
-
return new NativeBigInt(this.value - parseValue(v).value);
|
|
252
|
-
};
|
|
253
|
-
NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract;
|
|
254
|
-
BigInteger.prototype.negate = function() {
|
|
255
|
-
return new BigInteger(this.value, !this.sign);
|
|
256
|
-
};
|
|
257
|
-
SmallInteger.prototype.negate = function() {
|
|
258
|
-
var sign = this.sign;
|
|
259
|
-
var small = new SmallInteger(-this.value);
|
|
260
|
-
small.sign = !sign;
|
|
261
|
-
return small;
|
|
262
|
-
};
|
|
263
|
-
NativeBigInt.prototype.negate = function() {
|
|
264
|
-
return new NativeBigInt(-this.value);
|
|
265
|
-
};
|
|
266
|
-
BigInteger.prototype.abs = function() {
|
|
267
|
-
return new BigInteger(this.value, false);
|
|
268
|
-
};
|
|
269
|
-
SmallInteger.prototype.abs = function() {
|
|
270
|
-
return new SmallInteger(Math.abs(this.value));
|
|
271
|
-
};
|
|
272
|
-
NativeBigInt.prototype.abs = function() {
|
|
273
|
-
return new NativeBigInt(this.value >= 0 ? this.value : -this.value);
|
|
274
|
-
};
|
|
275
|
-
function multiplyLong(a, b) {
|
|
276
|
-
var a_l = a.length, b_l = b.length, l = a_l + b_l, r = createArray(l), base = BASE, product, carry, i2, a_i, b_j;
|
|
277
|
-
for (i2 = 0; i2 < a_l; ++i2) {
|
|
278
|
-
a_i = a[i2];
|
|
279
|
-
for (var j = 0; j < b_l; ++j) {
|
|
280
|
-
b_j = b[j];
|
|
281
|
-
product = a_i * b_j + r[i2 + j];
|
|
282
|
-
carry = Math.floor(product / base);
|
|
283
|
-
r[i2 + j] = product - carry * base;
|
|
284
|
-
r[i2 + j + 1] += carry;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
trim(r);
|
|
288
|
-
return r;
|
|
289
|
-
}
|
|
290
|
-
__name(multiplyLong, "multiplyLong");
|
|
291
|
-
function multiplySmall(a, b) {
|
|
292
|
-
var l = a.length, r = new Array(l), base = BASE, carry = 0, product, i2;
|
|
293
|
-
for (i2 = 0; i2 < l; i2++) {
|
|
294
|
-
product = a[i2] * b + carry;
|
|
295
|
-
carry = Math.floor(product / base);
|
|
296
|
-
r[i2] = product - carry * base;
|
|
297
|
-
}
|
|
298
|
-
while (carry > 0) {
|
|
299
|
-
r[i2++] = carry % base;
|
|
300
|
-
carry = Math.floor(carry / base);
|
|
301
|
-
}
|
|
302
|
-
return r;
|
|
303
|
-
}
|
|
304
|
-
__name(multiplySmall, "multiplySmall");
|
|
305
|
-
function shiftLeft(x, n) {
|
|
306
|
-
var r = [];
|
|
307
|
-
while (n-- > 0) r.push(0);
|
|
308
|
-
return r.concat(x);
|
|
309
|
-
}
|
|
310
|
-
__name(shiftLeft, "shiftLeft");
|
|
311
|
-
function multiplyKaratsuba(x, y) {
|
|
312
|
-
var n = Math.max(x.length, y.length);
|
|
313
|
-
if (n <= 30) return multiplyLong(x, y);
|
|
314
|
-
n = Math.ceil(n / 2);
|
|
315
|
-
var b = x.slice(n), a = x.slice(0, n), d = y.slice(n), c = y.slice(0, n);
|
|
316
|
-
var ac = multiplyKaratsuba(a, c), bd = multiplyKaratsuba(b, d), abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d));
|
|
317
|
-
var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n));
|
|
318
|
-
trim(product);
|
|
319
|
-
return product;
|
|
320
|
-
}
|
|
321
|
-
__name(multiplyKaratsuba, "multiplyKaratsuba");
|
|
322
|
-
function useKaratsuba(l1, l2) {
|
|
323
|
-
return -0.012 * l1 - 0.012 * l2 + 15e-6 * l1 * l2 > 0;
|
|
324
|
-
}
|
|
325
|
-
__name(useKaratsuba, "useKaratsuba");
|
|
326
|
-
BigInteger.prototype.multiply = function(v) {
|
|
327
|
-
var n = parseValue(v), a = this.value, b = n.value, sign = this.sign !== n.sign, abs;
|
|
328
|
-
if (n.isSmall) {
|
|
329
|
-
if (b === 0) return Integer[0];
|
|
330
|
-
if (b === 1) return this;
|
|
331
|
-
if (b === -1) return this.negate();
|
|
332
|
-
abs = Math.abs(b);
|
|
333
|
-
if (abs < BASE) {
|
|
334
|
-
return new BigInteger(multiplySmall(a, abs), sign);
|
|
335
|
-
}
|
|
336
|
-
b = smallToArray(abs);
|
|
337
|
-
}
|
|
338
|
-
if (useKaratsuba(a.length, b.length))
|
|
339
|
-
return new BigInteger(multiplyKaratsuba(a, b), sign);
|
|
340
|
-
return new BigInteger(multiplyLong(a, b), sign);
|
|
341
|
-
};
|
|
342
|
-
BigInteger.prototype.times = BigInteger.prototype.multiply;
|
|
343
|
-
function multiplySmallAndArray(a, b, sign) {
|
|
344
|
-
if (a < BASE) {
|
|
345
|
-
return new BigInteger(multiplySmall(b, a), sign);
|
|
346
|
-
}
|
|
347
|
-
return new BigInteger(multiplyLong(b, smallToArray(a)), sign);
|
|
348
|
-
}
|
|
349
|
-
__name(multiplySmallAndArray, "multiplySmallAndArray");
|
|
350
|
-
SmallInteger.prototype._multiplyBySmall = function(a) {
|
|
351
|
-
if (isPrecise(a.value * this.value)) {
|
|
352
|
-
return new SmallInteger(a.value * this.value);
|
|
353
|
-
}
|
|
354
|
-
return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign);
|
|
355
|
-
};
|
|
356
|
-
BigInteger.prototype._multiplyBySmall = function(a) {
|
|
357
|
-
if (a.value === 0) return Integer[0];
|
|
358
|
-
if (a.value === 1) return this;
|
|
359
|
-
if (a.value === -1) return this.negate();
|
|
360
|
-
return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign);
|
|
361
|
-
};
|
|
362
|
-
SmallInteger.prototype.multiply = function(v) {
|
|
363
|
-
return parseValue(v)._multiplyBySmall(this);
|
|
364
|
-
};
|
|
365
|
-
SmallInteger.prototype.times = SmallInteger.prototype.multiply;
|
|
366
|
-
NativeBigInt.prototype.multiply = function(v) {
|
|
367
|
-
return new NativeBigInt(this.value * parseValue(v).value);
|
|
368
|
-
};
|
|
369
|
-
NativeBigInt.prototype.times = NativeBigInt.prototype.multiply;
|
|
370
|
-
function square(a) {
|
|
371
|
-
var l = a.length, r = createArray(l + l), base = BASE, product, carry, i2, a_i, a_j;
|
|
372
|
-
for (i2 = 0; i2 < l; i2++) {
|
|
373
|
-
a_i = a[i2];
|
|
374
|
-
carry = 0 - a_i * a_i;
|
|
375
|
-
for (var j = i2; j < l; j++) {
|
|
376
|
-
a_j = a[j];
|
|
377
|
-
product = 2 * (a_i * a_j) + r[i2 + j] + carry;
|
|
378
|
-
carry = Math.floor(product / base);
|
|
379
|
-
r[i2 + j] = product - carry * base;
|
|
380
|
-
}
|
|
381
|
-
r[i2 + l] = carry;
|
|
382
|
-
}
|
|
383
|
-
trim(r);
|
|
384
|
-
return r;
|
|
385
|
-
}
|
|
386
|
-
__name(square, "square");
|
|
387
|
-
BigInteger.prototype.square = function() {
|
|
388
|
-
return new BigInteger(square(this.value), false);
|
|
389
|
-
};
|
|
390
|
-
SmallInteger.prototype.square = function() {
|
|
391
|
-
var value = this.value * this.value;
|
|
392
|
-
if (isPrecise(value)) return new SmallInteger(value);
|
|
393
|
-
return new BigInteger(square(smallToArray(Math.abs(this.value))), false);
|
|
394
|
-
};
|
|
395
|
-
NativeBigInt.prototype.square = function(v) {
|
|
396
|
-
return new NativeBigInt(this.value * this.value);
|
|
397
|
-
};
|
|
398
|
-
function divMod1(a, b) {
|
|
399
|
-
var a_l = a.length, b_l = b.length, base = BASE, result = createArray(b.length), divisorMostSignificantDigit = b[b_l - 1], lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)), remainder = multiplySmall(a, lambda), divisor = multiplySmall(b, lambda), quotientDigit, shift, carry, borrow, i2, l, q;
|
|
400
|
-
if (remainder.length <= a_l) remainder.push(0);
|
|
401
|
-
divisor.push(0);
|
|
402
|
-
divisorMostSignificantDigit = divisor[b_l - 1];
|
|
403
|
-
for (shift = a_l - b_l; shift >= 0; shift--) {
|
|
404
|
-
quotientDigit = base - 1;
|
|
405
|
-
if (remainder[shift + b_l] !== divisorMostSignificantDigit) {
|
|
406
|
-
quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);
|
|
407
|
-
}
|
|
408
|
-
carry = 0;
|
|
409
|
-
borrow = 0;
|
|
410
|
-
l = divisor.length;
|
|
411
|
-
for (i2 = 0; i2 < l; i2++) {
|
|
412
|
-
carry += quotientDigit * divisor[i2];
|
|
413
|
-
q = Math.floor(carry / base);
|
|
414
|
-
borrow += remainder[shift + i2] - (carry - q * base);
|
|
415
|
-
carry = q;
|
|
416
|
-
if (borrow < 0) {
|
|
417
|
-
remainder[shift + i2] = borrow + base;
|
|
418
|
-
borrow = -1;
|
|
419
|
-
} else {
|
|
420
|
-
remainder[shift + i2] = borrow;
|
|
421
|
-
borrow = 0;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
while (borrow !== 0) {
|
|
425
|
-
quotientDigit -= 1;
|
|
426
|
-
carry = 0;
|
|
427
|
-
for (i2 = 0; i2 < l; i2++) {
|
|
428
|
-
carry += remainder[shift + i2] - base + divisor[i2];
|
|
429
|
-
if (carry < 0) {
|
|
430
|
-
remainder[shift + i2] = carry + base;
|
|
431
|
-
carry = 0;
|
|
432
|
-
} else {
|
|
433
|
-
remainder[shift + i2] = carry;
|
|
434
|
-
carry = 1;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
borrow += carry;
|
|
438
|
-
}
|
|
439
|
-
result[shift] = quotientDigit;
|
|
440
|
-
}
|
|
441
|
-
remainder = divModSmall(remainder, lambda)[0];
|
|
442
|
-
return [arrayToSmall(result), arrayToSmall(remainder)];
|
|
443
|
-
}
|
|
444
|
-
__name(divMod1, "divMod1");
|
|
445
|
-
function divMod2(a, b) {
|
|
446
|
-
var a_l = a.length, b_l = b.length, result = [], part = [], base = BASE, guess, xlen, highx, highy, check;
|
|
447
|
-
while (a_l) {
|
|
448
|
-
part.unshift(a[--a_l]);
|
|
449
|
-
trim(part);
|
|
450
|
-
if (compareAbs(part, b) < 0) {
|
|
451
|
-
result.push(0);
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
xlen = part.length;
|
|
455
|
-
highx = part[xlen - 1] * base + part[xlen - 2];
|
|
456
|
-
highy = b[b_l - 1] * base + b[b_l - 2];
|
|
457
|
-
if (xlen > b_l) {
|
|
458
|
-
highx = (highx + 1) * base;
|
|
459
|
-
}
|
|
460
|
-
guess = Math.ceil(highx / highy);
|
|
461
|
-
do {
|
|
462
|
-
check = multiplySmall(b, guess);
|
|
463
|
-
if (compareAbs(check, part) <= 0) break;
|
|
464
|
-
guess--;
|
|
465
|
-
} while (guess);
|
|
466
|
-
result.push(guess);
|
|
467
|
-
part = subtract(part, check);
|
|
468
|
-
}
|
|
469
|
-
result.reverse();
|
|
470
|
-
return [arrayToSmall(result), arrayToSmall(part)];
|
|
471
|
-
}
|
|
472
|
-
__name(divMod2, "divMod2");
|
|
473
|
-
function divModSmall(value, lambda) {
|
|
474
|
-
var length = value.length, quotient = createArray(length), base = BASE, i2, q, remainder, divisor;
|
|
475
|
-
remainder = 0;
|
|
476
|
-
for (i2 = length - 1; i2 >= 0; --i2) {
|
|
477
|
-
divisor = remainder * base + value[i2];
|
|
478
|
-
q = truncate(divisor / lambda);
|
|
479
|
-
remainder = divisor - q * lambda;
|
|
480
|
-
quotient[i2] = q | 0;
|
|
481
|
-
}
|
|
482
|
-
return [quotient, remainder | 0];
|
|
483
|
-
}
|
|
484
|
-
__name(divModSmall, "divModSmall");
|
|
485
|
-
function divModAny(self, v) {
|
|
486
|
-
var value, n = parseValue(v);
|
|
487
|
-
if (supportsNativeBigInt) {
|
|
488
|
-
return [new NativeBigInt(self.value / n.value), new NativeBigInt(self.value % n.value)];
|
|
489
|
-
}
|
|
490
|
-
var a = self.value, b = n.value;
|
|
491
|
-
var quotient;
|
|
492
|
-
if (b === 0) throw new Error("Cannot divide by zero");
|
|
493
|
-
if (self.isSmall) {
|
|
494
|
-
if (n.isSmall) {
|
|
495
|
-
return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
|
|
496
|
-
}
|
|
497
|
-
return [Integer[0], self];
|
|
498
|
-
}
|
|
499
|
-
if (n.isSmall) {
|
|
500
|
-
if (b === 1) return [self, Integer[0]];
|
|
501
|
-
if (b == -1) return [self.negate(), Integer[0]];
|
|
502
|
-
var abs = Math.abs(b);
|
|
503
|
-
if (abs < BASE) {
|
|
504
|
-
value = divModSmall(a, abs);
|
|
505
|
-
quotient = arrayToSmall(value[0]);
|
|
506
|
-
var remainder = value[1];
|
|
507
|
-
if (self.sign) remainder = -remainder;
|
|
508
|
-
if (typeof quotient === "number") {
|
|
509
|
-
if (self.sign !== n.sign) quotient = -quotient;
|
|
510
|
-
return [new SmallInteger(quotient), new SmallInteger(remainder)];
|
|
511
|
-
}
|
|
512
|
-
return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];
|
|
513
|
-
}
|
|
514
|
-
b = smallToArray(abs);
|
|
515
|
-
}
|
|
516
|
-
var comparison = compareAbs(a, b);
|
|
517
|
-
if (comparison === -1) return [Integer[0], self];
|
|
518
|
-
if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]];
|
|
519
|
-
if (a.length + b.length <= 200)
|
|
520
|
-
value = divMod1(a, b);
|
|
521
|
-
else value = divMod2(a, b);
|
|
522
|
-
quotient = value[0];
|
|
523
|
-
var qSign = self.sign !== n.sign, mod = value[1], mSign = self.sign;
|
|
524
|
-
if (typeof quotient === "number") {
|
|
525
|
-
if (qSign) quotient = -quotient;
|
|
526
|
-
quotient = new SmallInteger(quotient);
|
|
527
|
-
} else quotient = new BigInteger(quotient, qSign);
|
|
528
|
-
if (typeof mod === "number") {
|
|
529
|
-
if (mSign) mod = -mod;
|
|
530
|
-
mod = new SmallInteger(mod);
|
|
531
|
-
} else mod = new BigInteger(mod, mSign);
|
|
532
|
-
return [quotient, mod];
|
|
533
|
-
}
|
|
534
|
-
__name(divModAny, "divModAny");
|
|
535
|
-
BigInteger.prototype.divmod = function(v) {
|
|
536
|
-
var result = divModAny(this, v);
|
|
537
|
-
return {
|
|
538
|
-
quotient: result[0],
|
|
539
|
-
remainder: result[1]
|
|
540
|
-
};
|
|
541
|
-
};
|
|
542
|
-
NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod = BigInteger.prototype.divmod;
|
|
543
|
-
BigInteger.prototype.divide = function(v) {
|
|
544
|
-
return divModAny(this, v)[0];
|
|
545
|
-
};
|
|
546
|
-
NativeBigInt.prototype.over = NativeBigInt.prototype.divide = function(v) {
|
|
547
|
-
return new NativeBigInt(this.value / parseValue(v).value);
|
|
548
|
-
};
|
|
549
|
-
SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;
|
|
550
|
-
BigInteger.prototype.mod = function(v) {
|
|
551
|
-
return divModAny(this, v)[1];
|
|
552
|
-
};
|
|
553
|
-
NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = function(v) {
|
|
554
|
-
return new NativeBigInt(this.value % parseValue(v).value);
|
|
555
|
-
};
|
|
556
|
-
SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;
|
|
557
|
-
BigInteger.prototype.pow = function(v) {
|
|
558
|
-
var n = parseValue(v), a = this.value, b = n.value, value, x, y;
|
|
559
|
-
if (b === 0) return Integer[1];
|
|
560
|
-
if (a === 0) return Integer[0];
|
|
561
|
-
if (a === 1) return Integer[1];
|
|
562
|
-
if (a === -1) return n.isEven() ? Integer[1] : Integer[-1];
|
|
563
|
-
if (n.sign) {
|
|
564
|
-
return Integer[0];
|
|
565
|
-
}
|
|
566
|
-
if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large.");
|
|
567
|
-
if (this.isSmall) {
|
|
568
|
-
if (isPrecise(value = Math.pow(a, b)))
|
|
569
|
-
return new SmallInteger(truncate(value));
|
|
570
|
-
}
|
|
571
|
-
x = this;
|
|
572
|
-
y = Integer[1];
|
|
573
|
-
while (true) {
|
|
574
|
-
if (b & true) {
|
|
575
|
-
y = y.times(x);
|
|
576
|
-
--b;
|
|
577
|
-
}
|
|
578
|
-
if (b === 0) break;
|
|
579
|
-
b /= 2;
|
|
580
|
-
x = x.square();
|
|
581
|
-
}
|
|
582
|
-
return y;
|
|
583
|
-
};
|
|
584
|
-
SmallInteger.prototype.pow = BigInteger.prototype.pow;
|
|
585
|
-
NativeBigInt.prototype.pow = function(v) {
|
|
586
|
-
var n = parseValue(v);
|
|
587
|
-
var a = this.value, b = n.value;
|
|
588
|
-
var _0 = BigInt(0), _1 = BigInt(1), _2 = BigInt(2);
|
|
589
|
-
if (b === _0) return Integer[1];
|
|
590
|
-
if (a === _0) return Integer[0];
|
|
591
|
-
if (a === _1) return Integer[1];
|
|
592
|
-
if (a === BigInt(-1)) return n.isEven() ? Integer[1] : Integer[-1];
|
|
593
|
-
if (n.isNegative()) return new NativeBigInt(_0);
|
|
594
|
-
var x = this;
|
|
595
|
-
var y = Integer[1];
|
|
596
|
-
while (true) {
|
|
597
|
-
if ((b & _1) === _1) {
|
|
598
|
-
y = y.times(x);
|
|
599
|
-
--b;
|
|
600
|
-
}
|
|
601
|
-
if (b === _0) break;
|
|
602
|
-
b /= _2;
|
|
603
|
-
x = x.square();
|
|
604
|
-
}
|
|
605
|
-
return y;
|
|
606
|
-
};
|
|
607
|
-
BigInteger.prototype.modPow = function(exp, mod) {
|
|
608
|
-
exp = parseValue(exp);
|
|
609
|
-
mod = parseValue(mod);
|
|
610
|
-
if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0");
|
|
611
|
-
var r = Integer[1], base = this.mod(mod);
|
|
612
|
-
if (exp.isNegative()) {
|
|
613
|
-
exp = exp.multiply(Integer[-1]);
|
|
614
|
-
base = base.modInv(mod);
|
|
615
|
-
}
|
|
616
|
-
while (exp.isPositive()) {
|
|
617
|
-
if (base.isZero()) return Integer[0];
|
|
618
|
-
if (exp.isOdd()) r = r.multiply(base).mod(mod);
|
|
619
|
-
exp = exp.divide(2);
|
|
620
|
-
base = base.square().mod(mod);
|
|
621
|
-
}
|
|
622
|
-
return r;
|
|
623
|
-
};
|
|
624
|
-
NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow = BigInteger.prototype.modPow;
|
|
625
|
-
function compareAbs(a, b) {
|
|
626
|
-
if (a.length !== b.length) {
|
|
627
|
-
return a.length > b.length ? 1 : -1;
|
|
628
|
-
}
|
|
629
|
-
for (var i2 = a.length - 1; i2 >= 0; i2--) {
|
|
630
|
-
if (a[i2] !== b[i2]) return a[i2] > b[i2] ? 1 : -1;
|
|
631
|
-
}
|
|
632
|
-
return 0;
|
|
633
|
-
}
|
|
634
|
-
__name(compareAbs, "compareAbs");
|
|
635
|
-
BigInteger.prototype.compareAbs = function(v) {
|
|
636
|
-
var n = parseValue(v), a = this.value, b = n.value;
|
|
637
|
-
if (n.isSmall) return 1;
|
|
638
|
-
return compareAbs(a, b);
|
|
639
|
-
};
|
|
640
|
-
SmallInteger.prototype.compareAbs = function(v) {
|
|
641
|
-
var n = parseValue(v), a = Math.abs(this.value), b = n.value;
|
|
642
|
-
if (n.isSmall) {
|
|
643
|
-
b = Math.abs(b);
|
|
644
|
-
return a === b ? 0 : a > b ? 1 : -1;
|
|
645
|
-
}
|
|
646
|
-
return -1;
|
|
647
|
-
};
|
|
648
|
-
NativeBigInt.prototype.compareAbs = function(v) {
|
|
649
|
-
var a = this.value;
|
|
650
|
-
var b = parseValue(v).value;
|
|
651
|
-
a = a >= 0 ? a : -a;
|
|
652
|
-
b = b >= 0 ? b : -b;
|
|
653
|
-
return a === b ? 0 : a > b ? 1 : -1;
|
|
654
|
-
};
|
|
655
|
-
BigInteger.prototype.compare = function(v) {
|
|
656
|
-
if (v === Infinity) {
|
|
657
|
-
return -1;
|
|
658
|
-
}
|
|
659
|
-
if (v === -Infinity) {
|
|
660
|
-
return 1;
|
|
661
|
-
}
|
|
662
|
-
var n = parseValue(v), a = this.value, b = n.value;
|
|
663
|
-
if (this.sign !== n.sign) {
|
|
664
|
-
return n.sign ? 1 : -1;
|
|
665
|
-
}
|
|
666
|
-
if (n.isSmall) {
|
|
667
|
-
return this.sign ? -1 : 1;
|
|
668
|
-
}
|
|
669
|
-
return compareAbs(a, b) * (this.sign ? -1 : 1);
|
|
670
|
-
};
|
|
671
|
-
BigInteger.prototype.compareTo = BigInteger.prototype.compare;
|
|
672
|
-
SmallInteger.prototype.compare = function(v) {
|
|
673
|
-
if (v === Infinity) {
|
|
674
|
-
return -1;
|
|
675
|
-
}
|
|
676
|
-
if (v === -Infinity) {
|
|
677
|
-
return 1;
|
|
678
|
-
}
|
|
679
|
-
var n = parseValue(v), a = this.value, b = n.value;
|
|
680
|
-
if (n.isSmall) {
|
|
681
|
-
return a == b ? 0 : a > b ? 1 : -1;
|
|
682
|
-
}
|
|
683
|
-
if (a < 0 !== n.sign) {
|
|
684
|
-
return a < 0 ? -1 : 1;
|
|
685
|
-
}
|
|
686
|
-
return a < 0 ? 1 : -1;
|
|
687
|
-
};
|
|
688
|
-
SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;
|
|
689
|
-
NativeBigInt.prototype.compare = function(v) {
|
|
690
|
-
if (v === Infinity) {
|
|
691
|
-
return -1;
|
|
692
|
-
}
|
|
693
|
-
if (v === -Infinity) {
|
|
694
|
-
return 1;
|
|
695
|
-
}
|
|
696
|
-
var a = this.value;
|
|
697
|
-
var b = parseValue(v).value;
|
|
698
|
-
return a === b ? 0 : a > b ? 1 : -1;
|
|
699
|
-
};
|
|
700
|
-
NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare;
|
|
701
|
-
BigInteger.prototype.equals = function(v) {
|
|
702
|
-
return this.compare(v) === 0;
|
|
703
|
-
};
|
|
704
|
-
NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;
|
|
705
|
-
BigInteger.prototype.notEquals = function(v) {
|
|
706
|
-
return this.compare(v) !== 0;
|
|
707
|
-
};
|
|
708
|
-
NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;
|
|
709
|
-
BigInteger.prototype.greater = function(v) {
|
|
710
|
-
return this.compare(v) > 0;
|
|
711
|
-
};
|
|
712
|
-
NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;
|
|
713
|
-
BigInteger.prototype.lesser = function(v) {
|
|
714
|
-
return this.compare(v) < 0;
|
|
715
|
-
};
|
|
716
|
-
NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;
|
|
717
|
-
BigInteger.prototype.greaterOrEquals = function(v) {
|
|
718
|
-
return this.compare(v) >= 0;
|
|
719
|
-
};
|
|
720
|
-
NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;
|
|
721
|
-
BigInteger.prototype.lesserOrEquals = function(v) {
|
|
722
|
-
return this.compare(v) <= 0;
|
|
723
|
-
};
|
|
724
|
-
NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;
|
|
725
|
-
BigInteger.prototype.isEven = function() {
|
|
726
|
-
return (this.value[0] & 1) === 0;
|
|
727
|
-
};
|
|
728
|
-
SmallInteger.prototype.isEven = function() {
|
|
729
|
-
return (this.value & 1) === 0;
|
|
730
|
-
};
|
|
731
|
-
NativeBigInt.prototype.isEven = function() {
|
|
732
|
-
return (this.value & BigInt(1)) === BigInt(0);
|
|
733
|
-
};
|
|
734
|
-
BigInteger.prototype.isOdd = function() {
|
|
735
|
-
return (this.value[0] & 1) === 1;
|
|
736
|
-
};
|
|
737
|
-
SmallInteger.prototype.isOdd = function() {
|
|
738
|
-
return (this.value & 1) === 1;
|
|
739
|
-
};
|
|
740
|
-
NativeBigInt.prototype.isOdd = function() {
|
|
741
|
-
return (this.value & BigInt(1)) === BigInt(1);
|
|
742
|
-
};
|
|
743
|
-
BigInteger.prototype.isPositive = function() {
|
|
744
|
-
return !this.sign;
|
|
745
|
-
};
|
|
746
|
-
SmallInteger.prototype.isPositive = function() {
|
|
747
|
-
return this.value > 0;
|
|
748
|
-
};
|
|
749
|
-
NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive;
|
|
750
|
-
BigInteger.prototype.isNegative = function() {
|
|
751
|
-
return this.sign;
|
|
752
|
-
};
|
|
753
|
-
SmallInteger.prototype.isNegative = function() {
|
|
754
|
-
return this.value < 0;
|
|
755
|
-
};
|
|
756
|
-
NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative;
|
|
757
|
-
BigInteger.prototype.isUnit = function() {
|
|
758
|
-
return false;
|
|
759
|
-
};
|
|
760
|
-
SmallInteger.prototype.isUnit = function() {
|
|
761
|
-
return Math.abs(this.value) === 1;
|
|
762
|
-
};
|
|
763
|
-
NativeBigInt.prototype.isUnit = function() {
|
|
764
|
-
return this.abs().value === BigInt(1);
|
|
765
|
-
};
|
|
766
|
-
BigInteger.prototype.isZero = function() {
|
|
767
|
-
return false;
|
|
768
|
-
};
|
|
769
|
-
SmallInteger.prototype.isZero = function() {
|
|
770
|
-
return this.value === 0;
|
|
771
|
-
};
|
|
772
|
-
NativeBigInt.prototype.isZero = function() {
|
|
773
|
-
return this.value === BigInt(0);
|
|
774
|
-
};
|
|
775
|
-
BigInteger.prototype.isDivisibleBy = function(v) {
|
|
776
|
-
var n = parseValue(v);
|
|
777
|
-
if (n.isZero()) return false;
|
|
778
|
-
if (n.isUnit()) return true;
|
|
779
|
-
if (n.compareAbs(2) === 0) return this.isEven();
|
|
780
|
-
return this.mod(n).isZero();
|
|
781
|
-
};
|
|
782
|
-
NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
|
|
783
|
-
function isBasicPrime(v) {
|
|
784
|
-
var n = v.abs();
|
|
785
|
-
if (n.isUnit()) return false;
|
|
786
|
-
if (n.equals(2) || n.equals(3) || n.equals(5)) return true;
|
|
787
|
-
if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
|
|
788
|
-
if (n.lesser(49)) return true;
|
|
789
|
-
}
|
|
790
|
-
__name(isBasicPrime, "isBasicPrime");
|
|
791
|
-
function millerRabinTest(n, a) {
|
|
792
|
-
var nPrev = n.prev(), b = nPrev, r = 0, d, t, i2, x;
|
|
793
|
-
while (b.isEven()) b = b.divide(2), r++;
|
|
794
|
-
next: for (i2 = 0; i2 < a.length; i2++) {
|
|
795
|
-
if (n.lesser(a[i2])) continue;
|
|
796
|
-
x = bigInt(a[i2]).modPow(b, n);
|
|
797
|
-
if (x.isUnit() || x.equals(nPrev)) continue;
|
|
798
|
-
for (d = r - 1; d != 0; d--) {
|
|
799
|
-
x = x.square().mod(n);
|
|
800
|
-
if (x.isUnit()) return false;
|
|
801
|
-
if (x.equals(nPrev)) continue next;
|
|
802
|
-
}
|
|
803
|
-
return false;
|
|
804
|
-
}
|
|
805
|
-
return true;
|
|
806
|
-
}
|
|
807
|
-
__name(millerRabinTest, "millerRabinTest");
|
|
808
|
-
BigInteger.prototype.isPrime = function(strict) {
|
|
809
|
-
var isPrime = isBasicPrime(this);
|
|
810
|
-
if (isPrime !== undefined) return isPrime;
|
|
811
|
-
var n = this.abs();
|
|
812
|
-
var bits = n.bitLength();
|
|
813
|
-
if (bits <= 64)
|
|
814
|
-
return millerRabinTest(n, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]);
|
|
815
|
-
var logN = Math.log(2) * bits.toJSNumber();
|
|
816
|
-
var t = Math.ceil(strict === true ? 2 * Math.pow(logN, 2) : logN);
|
|
817
|
-
for (var a = [], i2 = 0; i2 < t; i2++) {
|
|
818
|
-
a.push(bigInt(i2 + 2));
|
|
819
|
-
}
|
|
820
|
-
return millerRabinTest(n, a);
|
|
821
|
-
};
|
|
822
|
-
NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
|
|
823
|
-
BigInteger.prototype.isProbablePrime = function(iterations, rng) {
|
|
824
|
-
var isPrime = isBasicPrime(this);
|
|
825
|
-
if (isPrime !== undefined) return isPrime;
|
|
826
|
-
var n = this.abs();
|
|
827
|
-
var t = iterations === undefined ? 5 : iterations;
|
|
828
|
-
for (var a = [], i2 = 0; i2 < t; i2++) {
|
|
829
|
-
a.push(bigInt.randBetween(2, n.minus(2), rng));
|
|
830
|
-
}
|
|
831
|
-
return millerRabinTest(n, a);
|
|
832
|
-
};
|
|
833
|
-
NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
|
|
834
|
-
BigInteger.prototype.modInv = function(n) {
|
|
835
|
-
var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR;
|
|
836
|
-
while (!newR.isZero()) {
|
|
837
|
-
q = r.divide(newR);
|
|
838
|
-
lastT = t;
|
|
839
|
-
lastR = r;
|
|
840
|
-
t = newT;
|
|
841
|
-
r = newR;
|
|
842
|
-
newT = lastT.subtract(q.multiply(newT));
|
|
843
|
-
newR = lastR.subtract(q.multiply(newR));
|
|
844
|
-
}
|
|
845
|
-
if (!r.isUnit()) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime");
|
|
846
|
-
if (t.compare(0) === -1) {
|
|
847
|
-
t = t.add(n);
|
|
848
|
-
}
|
|
849
|
-
if (this.isNegative()) {
|
|
850
|
-
return t.negate();
|
|
851
|
-
}
|
|
852
|
-
return t;
|
|
853
|
-
};
|
|
854
|
-
NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv = BigInteger.prototype.modInv;
|
|
855
|
-
BigInteger.prototype.next = function() {
|
|
856
|
-
var value = this.value;
|
|
857
|
-
if (this.sign) {
|
|
858
|
-
return subtractSmall(value, 1, this.sign);
|
|
859
|
-
}
|
|
860
|
-
return new BigInteger(addSmall(value, 1), this.sign);
|
|
861
|
-
};
|
|
862
|
-
SmallInteger.prototype.next = function() {
|
|
863
|
-
var value = this.value;
|
|
864
|
-
if (value + 1 < MAX_INT) return new SmallInteger(value + 1);
|
|
865
|
-
return new BigInteger(MAX_INT_ARR, false);
|
|
866
|
-
};
|
|
867
|
-
NativeBigInt.prototype.next = function() {
|
|
868
|
-
return new NativeBigInt(this.value + BigInt(1));
|
|
869
|
-
};
|
|
870
|
-
BigInteger.prototype.prev = function() {
|
|
871
|
-
var value = this.value;
|
|
872
|
-
if (this.sign) {
|
|
873
|
-
return new BigInteger(addSmall(value, 1), true);
|
|
874
|
-
}
|
|
875
|
-
return subtractSmall(value, 1, this.sign);
|
|
876
|
-
};
|
|
877
|
-
SmallInteger.prototype.prev = function() {
|
|
878
|
-
var value = this.value;
|
|
879
|
-
if (value - 1 > -MAX_INT) return new SmallInteger(value - 1);
|
|
880
|
-
return new BigInteger(MAX_INT_ARR, true);
|
|
881
|
-
};
|
|
882
|
-
NativeBigInt.prototype.prev = function() {
|
|
883
|
-
return new NativeBigInt(this.value - BigInt(1));
|
|
884
|
-
};
|
|
885
|
-
var powersOfTwo = [1];
|
|
886
|
-
while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);
|
|
887
|
-
var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];
|
|
888
|
-
function shift_isSmall(n) {
|
|
889
|
-
return Math.abs(n) <= BASE;
|
|
890
|
-
}
|
|
891
|
-
__name(shift_isSmall, "shift_isSmall");
|
|
892
|
-
BigInteger.prototype.shiftLeft = function(v) {
|
|
893
|
-
var n = parseValue(v).toJSNumber();
|
|
894
|
-
if (!shift_isSmall(n)) {
|
|
895
|
-
throw new Error(String(n) + " is too large for shifting.");
|
|
896
|
-
}
|
|
897
|
-
if (n < 0) return this.shiftRight(-n);
|
|
898
|
-
var result = this;
|
|
899
|
-
if (result.isZero()) return result;
|
|
900
|
-
while (n >= powers2Length) {
|
|
901
|
-
result = result.multiply(highestPower2);
|
|
902
|
-
n -= powers2Length - 1;
|
|
903
|
-
}
|
|
904
|
-
return result.multiply(powersOfTwo[n]);
|
|
905
|
-
};
|
|
906
|
-
NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;
|
|
907
|
-
BigInteger.prototype.shiftRight = function(v) {
|
|
908
|
-
var remQuo;
|
|
909
|
-
var n = parseValue(v).toJSNumber();
|
|
910
|
-
if (!shift_isSmall(n)) {
|
|
911
|
-
throw new Error(String(n) + " is too large for shifting.");
|
|
912
|
-
}
|
|
913
|
-
if (n < 0) return this.shiftLeft(-n);
|
|
914
|
-
var result = this;
|
|
915
|
-
while (n >= powers2Length) {
|
|
916
|
-
if (result.isZero() || result.isNegative() && result.isUnit()) return result;
|
|
917
|
-
remQuo = divModAny(result, highestPower2);
|
|
918
|
-
result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
|
|
919
|
-
n -= powers2Length - 1;
|
|
920
|
-
}
|
|
921
|
-
remQuo = divModAny(result, powersOfTwo[n]);
|
|
922
|
-
return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
|
|
923
|
-
};
|
|
924
|
-
NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;
|
|
925
|
-
function bitwise(x, y, fn) {
|
|
926
|
-
y = parseValue(y);
|
|
927
|
-
var xSign = x.isNegative(), ySign = y.isNegative();
|
|
928
|
-
var xRem = xSign ? x.not() : x, yRem = ySign ? y.not() : y;
|
|
929
|
-
var xDigit = 0, yDigit = 0;
|
|
930
|
-
var xDivMod = null, yDivMod = null;
|
|
931
|
-
var result = [];
|
|
932
|
-
while (!xRem.isZero() || !yRem.isZero()) {
|
|
933
|
-
xDivMod = divModAny(xRem, highestPower2);
|
|
934
|
-
xDigit = xDivMod[1].toJSNumber();
|
|
935
|
-
if (xSign) {
|
|
936
|
-
xDigit = highestPower2 - 1 - xDigit;
|
|
937
|
-
}
|
|
938
|
-
yDivMod = divModAny(yRem, highestPower2);
|
|
939
|
-
yDigit = yDivMod[1].toJSNumber();
|
|
940
|
-
if (ySign) {
|
|
941
|
-
yDigit = highestPower2 - 1 - yDigit;
|
|
942
|
-
}
|
|
943
|
-
xRem = xDivMod[0];
|
|
944
|
-
yRem = yDivMod[0];
|
|
945
|
-
result.push(fn(xDigit, yDigit));
|
|
946
|
-
}
|
|
947
|
-
var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0);
|
|
948
|
-
for (var i2 = result.length - 1; i2 >= 0; i2 -= 1) {
|
|
949
|
-
sum = sum.multiply(highestPower2).add(bigInt(result[i2]));
|
|
950
|
-
}
|
|
951
|
-
return sum;
|
|
952
|
-
}
|
|
953
|
-
__name(bitwise, "bitwise");
|
|
954
|
-
BigInteger.prototype.not = function() {
|
|
955
|
-
return this.negate().prev();
|
|
956
|
-
};
|
|
957
|
-
NativeBigInt.prototype.not = SmallInteger.prototype.not = BigInteger.prototype.not;
|
|
958
|
-
BigInteger.prototype.and = function(n) {
|
|
959
|
-
return bitwise(this, n, function(a, b) {
|
|
960
|
-
return a & b;
|
|
961
|
-
});
|
|
962
|
-
};
|
|
963
|
-
NativeBigInt.prototype.and = SmallInteger.prototype.and = BigInteger.prototype.and;
|
|
964
|
-
BigInteger.prototype.or = function(n) {
|
|
965
|
-
return bitwise(this, n, function(a, b) {
|
|
966
|
-
return a | b;
|
|
967
|
-
});
|
|
968
|
-
};
|
|
969
|
-
NativeBigInt.prototype.or = SmallInteger.prototype.or = BigInteger.prototype.or;
|
|
970
|
-
BigInteger.prototype.xor = function(n) {
|
|
971
|
-
return bitwise(this, n, function(a, b) {
|
|
972
|
-
return a ^ b;
|
|
973
|
-
});
|
|
974
|
-
};
|
|
975
|
-
NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor;
|
|
976
|
-
var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
|
|
977
|
-
function roughLOB(n) {
|
|
978
|
-
var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : typeof v === "bigint" ? v | BigInt(LOBMASK_I) : v[0] + v[1] * BASE | LOBMASK_BI;
|
|
979
|
-
return x & -x;
|
|
980
|
-
}
|
|
981
|
-
__name(roughLOB, "roughLOB");
|
|
982
|
-
function integerLogarithm(value, base) {
|
|
983
|
-
if (base.compareTo(value) <= 0) {
|
|
984
|
-
var tmp = integerLogarithm(value, base.square(base));
|
|
985
|
-
var p = tmp.p;
|
|
986
|
-
var e = tmp.e;
|
|
987
|
-
var t = p.multiply(base);
|
|
988
|
-
return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p, e: e * 2 };
|
|
989
|
-
}
|
|
990
|
-
return { p: bigInt(1), e: 0 };
|
|
991
|
-
}
|
|
992
|
-
__name(integerLogarithm, "integerLogarithm");
|
|
993
|
-
BigInteger.prototype.bitLength = function() {
|
|
994
|
-
var n = this;
|
|
995
|
-
if (n.compareTo(bigInt(0)) < 0) {
|
|
996
|
-
n = n.negate().subtract(bigInt(1));
|
|
997
|
-
}
|
|
998
|
-
if (n.compareTo(bigInt(0)) === 0) {
|
|
999
|
-
return bigInt(0);
|
|
1000
|
-
}
|
|
1001
|
-
return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1));
|
|
1002
|
-
};
|
|
1003
|
-
NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength;
|
|
1004
|
-
function max(a, b) {
|
|
1005
|
-
a = parseValue(a);
|
|
1006
|
-
b = parseValue(b);
|
|
1007
|
-
return a.greater(b) ? a : b;
|
|
1008
|
-
}
|
|
1009
|
-
__name(max, "max");
|
|
1010
|
-
function min(a, b) {
|
|
1011
|
-
a = parseValue(a);
|
|
1012
|
-
b = parseValue(b);
|
|
1013
|
-
return a.lesser(b) ? a : b;
|
|
1014
|
-
}
|
|
1015
|
-
__name(min, "min");
|
|
1016
|
-
function gcd(a, b) {
|
|
1017
|
-
a = parseValue(a).abs();
|
|
1018
|
-
b = parseValue(b).abs();
|
|
1019
|
-
if (a.equals(b)) return a;
|
|
1020
|
-
if (a.isZero()) return b;
|
|
1021
|
-
if (b.isZero()) return a;
|
|
1022
|
-
var c = Integer[1], d, t;
|
|
1023
|
-
while (a.isEven() && b.isEven()) {
|
|
1024
|
-
d = min(roughLOB(a), roughLOB(b));
|
|
1025
|
-
a = a.divide(d);
|
|
1026
|
-
b = b.divide(d);
|
|
1027
|
-
c = c.multiply(d);
|
|
1028
|
-
}
|
|
1029
|
-
while (a.isEven()) {
|
|
1030
|
-
a = a.divide(roughLOB(a));
|
|
1031
|
-
}
|
|
1032
|
-
do {
|
|
1033
|
-
while (b.isEven()) {
|
|
1034
|
-
b = b.divide(roughLOB(b));
|
|
1035
|
-
}
|
|
1036
|
-
if (a.greater(b)) {
|
|
1037
|
-
t = b;
|
|
1038
|
-
b = a;
|
|
1039
|
-
a = t;
|
|
1040
|
-
}
|
|
1041
|
-
b = b.subtract(a);
|
|
1042
|
-
} while (!b.isZero());
|
|
1043
|
-
return c.isUnit() ? a : a.multiply(c);
|
|
1044
|
-
}
|
|
1045
|
-
__name(gcd, "gcd");
|
|
1046
|
-
function lcm(a, b) {
|
|
1047
|
-
a = parseValue(a).abs();
|
|
1048
|
-
b = parseValue(b).abs();
|
|
1049
|
-
return a.divide(gcd(a, b)).multiply(b);
|
|
1050
|
-
}
|
|
1051
|
-
__name(lcm, "lcm");
|
|
1052
|
-
function randBetween(a, b, rng) {
|
|
1053
|
-
a = parseValue(a);
|
|
1054
|
-
b = parseValue(b);
|
|
1055
|
-
var usedRNG = rng || Math.random;
|
|
1056
|
-
var low = min(a, b), high = max(a, b);
|
|
1057
|
-
var range = high.subtract(low).add(1);
|
|
1058
|
-
if (range.isSmall) return low.add(Math.floor(usedRNG() * range));
|
|
1059
|
-
var digits = toBase(range, BASE).value;
|
|
1060
|
-
var result = [], restricted = true;
|
|
1061
|
-
for (var i2 = 0; i2 < digits.length; i2++) {
|
|
1062
|
-
var top = restricted ? digits[i2] + (i2 + 1 < digits.length ? digits[i2 + 1] / BASE : 0) : BASE;
|
|
1063
|
-
var digit = truncate(usedRNG() * top);
|
|
1064
|
-
result.push(digit);
|
|
1065
|
-
if (digit < digits[i2]) restricted = false;
|
|
1066
|
-
}
|
|
1067
|
-
return low.add(Integer.fromArray(result, BASE, false));
|
|
1068
|
-
}
|
|
1069
|
-
__name(randBetween, "randBetween");
|
|
1070
|
-
var parseBase = /* @__PURE__ */ __name(function(text, base, alphabet, caseSensitive) {
|
|
1071
|
-
alphabet = alphabet || DEFAULT_ALPHABET;
|
|
1072
|
-
text = String(text);
|
|
1073
|
-
if (!caseSensitive) {
|
|
1074
|
-
text = text.toLowerCase();
|
|
1075
|
-
alphabet = alphabet.toLowerCase();
|
|
1076
|
-
}
|
|
1077
|
-
var length = text.length;
|
|
1078
|
-
var i2;
|
|
1079
|
-
var absBase = Math.abs(base);
|
|
1080
|
-
var alphabetValues = {};
|
|
1081
|
-
for (i2 = 0; i2 < alphabet.length; i2++) {
|
|
1082
|
-
alphabetValues[alphabet[i2]] = i2;
|
|
1083
|
-
}
|
|
1084
|
-
for (i2 = 0; i2 < length; i2++) {
|
|
1085
|
-
var c = text[i2];
|
|
1086
|
-
if (c === "-") continue;
|
|
1087
|
-
if (c in alphabetValues) {
|
|
1088
|
-
if (alphabetValues[c] >= absBase) {
|
|
1089
|
-
if (c === "1" && absBase === 1) continue;
|
|
1090
|
-
throw new Error(c + " is not a valid digit in base " + base + ".");
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
base = parseValue(base);
|
|
1095
|
-
var digits = [];
|
|
1096
|
-
var isNegative = text[0] === "-";
|
|
1097
|
-
for (i2 = isNegative ? 1 : 0; i2 < text.length; i2++) {
|
|
1098
|
-
var c = text[i2];
|
|
1099
|
-
if (c in alphabetValues) digits.push(parseValue(alphabetValues[c]));
|
|
1100
|
-
else if (c === "<") {
|
|
1101
|
-
var start = i2;
|
|
1102
|
-
do {
|
|
1103
|
-
i2++;
|
|
1104
|
-
} while (text[i2] !== ">" && i2 < text.length);
|
|
1105
|
-
digits.push(parseValue(text.slice(start + 1, i2)));
|
|
1106
|
-
} else throw new Error(c + " is not a valid character");
|
|
1107
|
-
}
|
|
1108
|
-
return parseBaseFromArray(digits, base, isNegative);
|
|
1109
|
-
}, "parseBase");
|
|
1110
|
-
function parseBaseFromArray(digits, base, isNegative) {
|
|
1111
|
-
var val = Integer[0], pow = Integer[1], i2;
|
|
1112
|
-
for (i2 = digits.length - 1; i2 >= 0; i2--) {
|
|
1113
|
-
val = val.add(digits[i2].times(pow));
|
|
1114
|
-
pow = pow.times(base);
|
|
1115
|
-
}
|
|
1116
|
-
return isNegative ? val.negate() : val;
|
|
1117
|
-
}
|
|
1118
|
-
__name(parseBaseFromArray, "parseBaseFromArray");
|
|
1119
|
-
function stringify(digit, alphabet) {
|
|
1120
|
-
alphabet = alphabet || DEFAULT_ALPHABET;
|
|
1121
|
-
if (digit < alphabet.length) {
|
|
1122
|
-
return alphabet[digit];
|
|
1123
|
-
}
|
|
1124
|
-
return "<" + digit + ">";
|
|
1125
|
-
}
|
|
1126
|
-
__name(stringify, "stringify");
|
|
1127
|
-
function toBase(n, base) {
|
|
1128
|
-
base = bigInt(base);
|
|
1129
|
-
if (base.isZero()) {
|
|
1130
|
-
if (n.isZero()) return { value: [0], isNegative: false };
|
|
1131
|
-
throw new Error("Cannot convert nonzero numbers to base 0.");
|
|
1132
|
-
}
|
|
1133
|
-
if (base.equals(-1)) {
|
|
1134
|
-
if (n.isZero()) return { value: [0], isNegative: false };
|
|
1135
|
-
if (n.isNegative())
|
|
1136
|
-
return {
|
|
1137
|
-
value: [].concat.apply(
|
|
1138
|
-
[],
|
|
1139
|
-
Array.apply(null, Array(-n.toJSNumber())).map(Array.prototype.valueOf, [1, 0])
|
|
1140
|
-
),
|
|
1141
|
-
isNegative: false
|
|
1142
|
-
};
|
|
1143
|
-
var arr = Array.apply(null, Array(n.toJSNumber() - 1)).map(Array.prototype.valueOf, [0, 1]);
|
|
1144
|
-
arr.unshift([1]);
|
|
1145
|
-
return {
|
|
1146
|
-
value: [].concat.apply([], arr),
|
|
1147
|
-
isNegative: false
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
var neg = false;
|
|
1151
|
-
if (n.isNegative() && base.isPositive()) {
|
|
1152
|
-
neg = true;
|
|
1153
|
-
n = n.abs();
|
|
1154
|
-
}
|
|
1155
|
-
if (base.isUnit()) {
|
|
1156
|
-
if (n.isZero()) return { value: [0], isNegative: false };
|
|
1157
|
-
return {
|
|
1158
|
-
value: Array.apply(null, Array(n.toJSNumber())).map(Number.prototype.valueOf, 1),
|
|
1159
|
-
isNegative: neg
|
|
1160
|
-
};
|
|
1161
|
-
}
|
|
1162
|
-
var out = [];
|
|
1163
|
-
var left = n, divmod;
|
|
1164
|
-
while (left.isNegative() || left.compareAbs(base) >= 0) {
|
|
1165
|
-
divmod = left.divmod(base);
|
|
1166
|
-
left = divmod.quotient;
|
|
1167
|
-
var digit = divmod.remainder;
|
|
1168
|
-
if (digit.isNegative()) {
|
|
1169
|
-
digit = base.minus(digit).abs();
|
|
1170
|
-
left = left.next();
|
|
1171
|
-
}
|
|
1172
|
-
out.push(digit.toJSNumber());
|
|
1173
|
-
}
|
|
1174
|
-
out.push(left.toJSNumber());
|
|
1175
|
-
return { value: out.reverse(), isNegative: neg };
|
|
1176
|
-
}
|
|
1177
|
-
__name(toBase, "toBase");
|
|
1178
|
-
function toBaseString(n, base, alphabet) {
|
|
1179
|
-
var arr = toBase(n, base);
|
|
1180
|
-
return (arr.isNegative ? "-" : "") + arr.value.map(function(x) {
|
|
1181
|
-
return stringify(x, alphabet);
|
|
1182
|
-
}).join("");
|
|
1183
|
-
}
|
|
1184
|
-
__name(toBaseString, "toBaseString");
|
|
1185
|
-
BigInteger.prototype.toArray = function(radix) {
|
|
1186
|
-
return toBase(this, radix);
|
|
1187
|
-
};
|
|
1188
|
-
SmallInteger.prototype.toArray = function(radix) {
|
|
1189
|
-
return toBase(this, radix);
|
|
1190
|
-
};
|
|
1191
|
-
NativeBigInt.prototype.toArray = function(radix) {
|
|
1192
|
-
return toBase(this, radix);
|
|
1193
|
-
};
|
|
1194
|
-
BigInteger.prototype.toString = function(radix, alphabet) {
|
|
1195
|
-
if (radix === undefined) radix = 10;
|
|
1196
|
-
if (radix !== 10 || alphabet) return toBaseString(this, radix, alphabet);
|
|
1197
|
-
var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit;
|
|
1198
|
-
while (--l >= 0) {
|
|
1199
|
-
digit = String(v[l]);
|
|
1200
|
-
str += zeros.slice(digit.length) + digit;
|
|
1201
|
-
}
|
|
1202
|
-
var sign = this.sign ? "-" : "";
|
|
1203
|
-
return sign + str;
|
|
1204
|
-
};
|
|
1205
|
-
SmallInteger.prototype.toString = function(radix, alphabet) {
|
|
1206
|
-
if (radix === undefined) radix = 10;
|
|
1207
|
-
if (radix != 10 || alphabet) return toBaseString(this, radix, alphabet);
|
|
1208
|
-
return String(this.value);
|
|
1209
|
-
};
|
|
1210
|
-
NativeBigInt.prototype.toString = SmallInteger.prototype.toString;
|
|
1211
|
-
NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function() {
|
|
1212
|
-
return this.toString();
|
|
1213
|
-
};
|
|
1214
|
-
BigInteger.prototype.valueOf = function() {
|
|
1215
|
-
return parseInt(this.toString(), 10);
|
|
1216
|
-
};
|
|
1217
|
-
BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;
|
|
1218
|
-
SmallInteger.prototype.valueOf = function() {
|
|
1219
|
-
return this.value;
|
|
1220
|
-
};
|
|
1221
|
-
SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;
|
|
1222
|
-
NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function() {
|
|
1223
|
-
return parseInt(this.toString(), 10);
|
|
1224
|
-
};
|
|
1225
|
-
function parseStringValue(v) {
|
|
1226
|
-
if (isPrecise(+v)) {
|
|
1227
|
-
var x = +v;
|
|
1228
|
-
if (x === truncate(x))
|
|
1229
|
-
return supportsNativeBigInt ? new NativeBigInt(BigInt(x)) : new SmallInteger(x);
|
|
1230
|
-
throw new Error("Invalid integer: " + v);
|
|
1231
|
-
}
|
|
1232
|
-
var sign = v[0] === "-";
|
|
1233
|
-
if (sign) v = v.slice(1);
|
|
1234
|
-
var split = v.split(/e/i);
|
|
1235
|
-
if (split.length > 2) throw new Error("Invalid integer: " + split.join("e"));
|
|
1236
|
-
if (split.length === 2) {
|
|
1237
|
-
var exp = split[1];
|
|
1238
|
-
if (exp[0] === "+") exp = exp.slice(1);
|
|
1239
|
-
exp = +exp;
|
|
1240
|
-
if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent.");
|
|
1241
|
-
var text = split[0];
|
|
1242
|
-
var decimalPlace = text.indexOf(".");
|
|
1243
|
-
if (decimalPlace >= 0) {
|
|
1244
|
-
exp -= text.length - decimalPlace - 1;
|
|
1245
|
-
text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);
|
|
1246
|
-
}
|
|
1247
|
-
if (exp < 0) throw new Error("Cannot include negative exponent part for integers");
|
|
1248
|
-
text += new Array(exp + 1).join("0");
|
|
1249
|
-
v = text;
|
|
1250
|
-
}
|
|
1251
|
-
var isValid = /^([0-9][0-9]*)$/.test(v);
|
|
1252
|
-
if (!isValid) throw new Error("Invalid integer: " + v);
|
|
1253
|
-
if (supportsNativeBigInt) {
|
|
1254
|
-
return new NativeBigInt(BigInt(sign ? "-" + v : v));
|
|
1255
|
-
}
|
|
1256
|
-
var r = [], max2 = v.length, l = LOG_BASE, min2 = max2 - l;
|
|
1257
|
-
while (max2 > 0) {
|
|
1258
|
-
r.push(+v.slice(min2, max2));
|
|
1259
|
-
min2 -= l;
|
|
1260
|
-
if (min2 < 0) min2 = 0;
|
|
1261
|
-
max2 -= l;
|
|
1262
|
-
}
|
|
1263
|
-
trim(r);
|
|
1264
|
-
return new BigInteger(r, sign);
|
|
1265
|
-
}
|
|
1266
|
-
__name(parseStringValue, "parseStringValue");
|
|
1267
|
-
function parseNumberValue(v) {
|
|
1268
|
-
if (supportsNativeBigInt) {
|
|
1269
|
-
return new NativeBigInt(BigInt(v));
|
|
1270
|
-
}
|
|
1271
|
-
if (isPrecise(v)) {
|
|
1272
|
-
if (v !== truncate(v)) throw new Error(v + " is not an integer.");
|
|
1273
|
-
return new SmallInteger(v);
|
|
1274
|
-
}
|
|
1275
|
-
return parseStringValue(v.toString());
|
|
1276
|
-
}
|
|
1277
|
-
__name(parseNumberValue, "parseNumberValue");
|
|
1278
|
-
function parseValue(v) {
|
|
1279
|
-
if (typeof v === "number") {
|
|
1280
|
-
return parseNumberValue(v);
|
|
1281
|
-
}
|
|
1282
|
-
if (typeof v === "string") {
|
|
1283
|
-
return parseStringValue(v);
|
|
1284
|
-
}
|
|
1285
|
-
if (typeof v === "bigint") {
|
|
1286
|
-
return new NativeBigInt(v);
|
|
1287
|
-
}
|
|
1288
|
-
return v;
|
|
1289
|
-
}
|
|
1290
|
-
__name(parseValue, "parseValue");
|
|
1291
|
-
for (var i = 0; i < 1e3; i++) {
|
|
1292
|
-
Integer[i] = parseValue(i);
|
|
1293
|
-
if (i > 0) Integer[-i] = parseValue(-i);
|
|
1294
|
-
}
|
|
1295
|
-
Integer.one = Integer[1];
|
|
1296
|
-
Integer.zero = Integer[0];
|
|
1297
|
-
Integer.minusOne = Integer[-1];
|
|
1298
|
-
Integer.max = max;
|
|
1299
|
-
Integer.min = min;
|
|
1300
|
-
Integer.gcd = gcd;
|
|
1301
|
-
Integer.lcm = lcm;
|
|
1302
|
-
Integer.isInstance = function(x) {
|
|
1303
|
-
return x instanceof BigInteger || x instanceof SmallInteger || x instanceof NativeBigInt;
|
|
1304
|
-
};
|
|
1305
|
-
Integer.randBetween = randBetween;
|
|
1306
|
-
Integer.fromArray = function(digits, base, isNegative) {
|
|
1307
|
-
return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative);
|
|
1308
|
-
};
|
|
1309
|
-
return Integer;
|
|
1310
|
-
}();
|
|
1311
|
-
if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
|
|
1312
|
-
module.exports = bigInt;
|
|
1313
|
-
}
|
|
1314
|
-
if (typeof define === "function" && define.amd) {
|
|
1315
|
-
define(function() {
|
|
1316
|
-
return bigInt;
|
|
1317
|
-
});
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
});
|
|
1321
|
-
|
|
1322
|
-
// ../node_modules/bplist-parser/bplistParser.js
|
|
1323
|
-
var require_bplistParser = __commonJS({
|
|
1324
|
-
"../node_modules/bplist-parser/bplistParser.js"(exports) {
|
|
1325
|
-
"use strict";
|
|
1326
|
-
var fs2 = __require("fs");
|
|
1327
|
-
var bigInt = require_BigInteger();
|
|
1328
|
-
var debug = false;
|
|
1329
|
-
exports.maxObjectSize = 100 * 1e3 * 1e3;
|
|
1330
|
-
exports.maxObjectCount = 32768;
|
|
1331
|
-
var EPOCH = 9783072e5;
|
|
1332
|
-
var UID = exports.UID = function(id) {
|
|
1333
|
-
this.UID = id;
|
|
1334
|
-
};
|
|
1335
|
-
var parseFile = exports.parseFile = function(fileNameOrBuffer, callback) {
|
|
1336
|
-
return new Promise(function(resolve, reject) {
|
|
1337
|
-
function tryParseBuffer(buffer) {
|
|
1338
|
-
let err = null;
|
|
1339
|
-
let result;
|
|
1340
|
-
try {
|
|
1341
|
-
result = parseBuffer(buffer);
|
|
1342
|
-
resolve(result);
|
|
1343
|
-
} catch (ex) {
|
|
1344
|
-
err = ex;
|
|
1345
|
-
reject(err);
|
|
1346
|
-
} finally {
|
|
1347
|
-
if (callback) callback(err, result);
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
__name(tryParseBuffer, "tryParseBuffer");
|
|
1351
|
-
if (Buffer.isBuffer(fileNameOrBuffer)) {
|
|
1352
|
-
return tryParseBuffer(fileNameOrBuffer);
|
|
1353
|
-
}
|
|
1354
|
-
fs2.readFile(fileNameOrBuffer, function(err, data) {
|
|
1355
|
-
if (err) {
|
|
1356
|
-
reject(err);
|
|
1357
|
-
return callback(err);
|
|
1358
|
-
}
|
|
1359
|
-
tryParseBuffer(data);
|
|
1360
|
-
});
|
|
1361
|
-
});
|
|
1362
|
-
};
|
|
1363
|
-
var parseBuffer = exports.parseBuffer = function(buffer) {
|
|
1364
|
-
const header = buffer.slice(0, "bplist".length).toString("utf8");
|
|
1365
|
-
if (header !== "bplist") {
|
|
1366
|
-
throw new Error("Invalid binary plist. Expected 'bplist' at offset 0.");
|
|
1367
|
-
}
|
|
1368
|
-
const trailer = buffer.slice(buffer.length - 32, buffer.length);
|
|
1369
|
-
const offsetSize = trailer.readUInt8(6);
|
|
1370
|
-
if (debug) {
|
|
1371
|
-
console.log("offsetSize: " + offsetSize);
|
|
1372
|
-
}
|
|
1373
|
-
const objectRefSize = trailer.readUInt8(7);
|
|
1374
|
-
if (debug) {
|
|
1375
|
-
console.log("objectRefSize: " + objectRefSize);
|
|
1376
|
-
}
|
|
1377
|
-
const numObjects = readUInt64BE(trailer, 8);
|
|
1378
|
-
if (debug) {
|
|
1379
|
-
console.log("numObjects: " + numObjects);
|
|
1380
|
-
}
|
|
1381
|
-
const topObject = readUInt64BE(trailer, 16);
|
|
1382
|
-
if (debug) {
|
|
1383
|
-
console.log("topObject: " + topObject);
|
|
1384
|
-
}
|
|
1385
|
-
const offsetTableOffset = readUInt64BE(trailer, 24);
|
|
1386
|
-
if (debug) {
|
|
1387
|
-
console.log("offsetTableOffset: " + offsetTableOffset);
|
|
1388
|
-
}
|
|
1389
|
-
if (numObjects > exports.maxObjectCount) {
|
|
1390
|
-
throw new Error("maxObjectCount exceeded");
|
|
1391
|
-
}
|
|
1392
|
-
const offsetTable = [];
|
|
1393
|
-
for (let i = 0; i < numObjects; i++) {
|
|
1394
|
-
const offsetBytes = buffer.slice(offsetTableOffset + i * offsetSize, offsetTableOffset + (i + 1) * offsetSize);
|
|
1395
|
-
offsetTable[i] = readUInt(offsetBytes, 0);
|
|
1396
|
-
if (debug) {
|
|
1397
|
-
console.log("Offset for Object #" + i + " is " + offsetTable[i] + " [" + offsetTable[i].toString(16) + "]");
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
function parseObject(tableOffset) {
|
|
1401
|
-
const offset = offsetTable[tableOffset];
|
|
1402
|
-
const type = buffer[offset];
|
|
1403
|
-
const objType = (type & 240) >> 4;
|
|
1404
|
-
const objInfo = type & 15;
|
|
1405
|
-
switch (objType) {
|
|
1406
|
-
case 0:
|
|
1407
|
-
return parseSimple();
|
|
1408
|
-
case 1:
|
|
1409
|
-
return parseInteger();
|
|
1410
|
-
case 8:
|
|
1411
|
-
return parseUID();
|
|
1412
|
-
case 2:
|
|
1413
|
-
return parseReal();
|
|
1414
|
-
case 3:
|
|
1415
|
-
return parseDate();
|
|
1416
|
-
case 4:
|
|
1417
|
-
return parseData();
|
|
1418
|
-
case 5:
|
|
1419
|
-
return parsePlistString();
|
|
1420
|
-
case 6:
|
|
1421
|
-
return parsePlistString(true);
|
|
1422
|
-
case 10:
|
|
1423
|
-
return parseArray();
|
|
1424
|
-
case 13:
|
|
1425
|
-
return parseDictionary();
|
|
1426
|
-
default:
|
|
1427
|
-
throw new Error("Unhandled type 0x" + objType.toString(16));
|
|
1428
|
-
}
|
|
1429
|
-
function parseSimple() {
|
|
1430
|
-
switch (objInfo) {
|
|
1431
|
-
case 0:
|
|
1432
|
-
return null;
|
|
1433
|
-
case 8:
|
|
1434
|
-
return false;
|
|
1435
|
-
case 9:
|
|
1436
|
-
return true;
|
|
1437
|
-
case 15:
|
|
1438
|
-
return null;
|
|
1439
|
-
default:
|
|
1440
|
-
throw new Error("Unhandled simple type 0x" + objType.toString(16));
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
__name(parseSimple, "parseSimple");
|
|
1444
|
-
function bufferToHexString(buffer2) {
|
|
1445
|
-
let str = "";
|
|
1446
|
-
let i;
|
|
1447
|
-
for (i = 0; i < buffer2.length; i++) {
|
|
1448
|
-
if (buffer2[i] != 0) {
|
|
1449
|
-
break;
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
for (; i < buffer2.length; i++) {
|
|
1453
|
-
const part = "00" + buffer2[i].toString(16);
|
|
1454
|
-
str += part.substr(part.length - 2);
|
|
1455
|
-
}
|
|
1456
|
-
return str;
|
|
1457
|
-
}
|
|
1458
|
-
__name(bufferToHexString, "bufferToHexString");
|
|
1459
|
-
function parseInteger() {
|
|
1460
|
-
const length = Math.pow(2, objInfo);
|
|
1461
|
-
if (objInfo == 4) {
|
|
1462
|
-
const data = buffer.slice(offset + 1, offset + 1 + length);
|
|
1463
|
-
const str = bufferToHexString(data);
|
|
1464
|
-
return bigInt(str, 16);
|
|
1465
|
-
}
|
|
1466
|
-
if (objInfo == 3) {
|
|
1467
|
-
return buffer.readInt32BE(offset + 1);
|
|
1468
|
-
}
|
|
1469
|
-
if (length < exports.maxObjectSize) {
|
|
1470
|
-
return readUInt(buffer.slice(offset + 1, offset + 1 + length));
|
|
1471
|
-
}
|
|
1472
|
-
throw new Error("To little heap space available! Wanted to read " + length + " bytes, but only " + exports.maxObjectSize + " are available.");
|
|
1473
|
-
}
|
|
1474
|
-
__name(parseInteger, "parseInteger");
|
|
1475
|
-
function parseUID() {
|
|
1476
|
-
const length = objInfo + 1;
|
|
1477
|
-
if (length < exports.maxObjectSize) {
|
|
1478
|
-
return new UID(readUInt(buffer.slice(offset + 1, offset + 1 + length)));
|
|
1479
|
-
}
|
|
1480
|
-
throw new Error("To little heap space available! Wanted to read " + length + " bytes, but only " + exports.maxObjectSize + " are available.");
|
|
1481
|
-
}
|
|
1482
|
-
__name(parseUID, "parseUID");
|
|
1483
|
-
function parseReal() {
|
|
1484
|
-
const length = Math.pow(2, objInfo);
|
|
1485
|
-
if (length < exports.maxObjectSize) {
|
|
1486
|
-
const realBuffer = buffer.slice(offset + 1, offset + 1 + length);
|
|
1487
|
-
if (length === 4) {
|
|
1488
|
-
return realBuffer.readFloatBE(0);
|
|
1489
|
-
}
|
|
1490
|
-
if (length === 8) {
|
|
1491
|
-
return realBuffer.readDoubleBE(0);
|
|
1492
|
-
}
|
|
1493
|
-
} else {
|
|
1494
|
-
throw new Error("To little heap space available! Wanted to read " + length + " bytes, but only " + exports.maxObjectSize + " are available.");
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
__name(parseReal, "parseReal");
|
|
1498
|
-
function parseDate() {
|
|
1499
|
-
if (objInfo != 3) {
|
|
1500
|
-
console.error("Unknown date type :" + objInfo + ". Parsing anyway...");
|
|
1501
|
-
}
|
|
1502
|
-
const dateBuffer = buffer.slice(offset + 1, offset + 9);
|
|
1503
|
-
return new Date(EPOCH + 1e3 * dateBuffer.readDoubleBE(0));
|
|
1504
|
-
}
|
|
1505
|
-
__name(parseDate, "parseDate");
|
|
1506
|
-
function parseData() {
|
|
1507
|
-
let dataoffset = 1;
|
|
1508
|
-
let length = objInfo;
|
|
1509
|
-
if (objInfo == 15) {
|
|
1510
|
-
const int_type = buffer[offset + 1];
|
|
1511
|
-
const intType = (int_type & 240) / 16;
|
|
1512
|
-
if (intType != 1) {
|
|
1513
|
-
console.error("0x4: UNEXPECTED LENGTH-INT TYPE! " + intType);
|
|
1514
|
-
}
|
|
1515
|
-
const intInfo = int_type & 15;
|
|
1516
|
-
const intLength = Math.pow(2, intInfo);
|
|
1517
|
-
dataoffset = 2 + intLength;
|
|
1518
|
-
if (intLength < 3) {
|
|
1519
|
-
length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
|
|
1520
|
-
} else {
|
|
1521
|
-
length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
if (length < exports.maxObjectSize) {
|
|
1525
|
-
return buffer.slice(offset + dataoffset, offset + dataoffset + length);
|
|
1526
|
-
}
|
|
1527
|
-
throw new Error("To little heap space available! Wanted to read " + length + " bytes, but only " + exports.maxObjectSize + " are available.");
|
|
1528
|
-
}
|
|
1529
|
-
__name(parseData, "parseData");
|
|
1530
|
-
function parsePlistString(isUtf16) {
|
|
1531
|
-
isUtf16 = isUtf16 || 0;
|
|
1532
|
-
let enc = "utf8";
|
|
1533
|
-
let length = objInfo;
|
|
1534
|
-
let stroffset = 1;
|
|
1535
|
-
if (objInfo == 15) {
|
|
1536
|
-
const int_type = buffer[offset + 1];
|
|
1537
|
-
const intType = (int_type & 240) / 16;
|
|
1538
|
-
if (intType != 1) {
|
|
1539
|
-
console.err("UNEXPECTED LENGTH-INT TYPE! " + intType);
|
|
1540
|
-
}
|
|
1541
|
-
const intInfo = int_type & 15;
|
|
1542
|
-
const intLength = Math.pow(2, intInfo);
|
|
1543
|
-
stroffset = 2 + intLength;
|
|
1544
|
-
if (intLength < 3) {
|
|
1545
|
-
length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
|
|
1546
|
-
} else {
|
|
1547
|
-
length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
length *= isUtf16 + 1;
|
|
1551
|
-
if (length < exports.maxObjectSize) {
|
|
1552
|
-
let plistString = Buffer.from(buffer.slice(offset + stroffset, offset + stroffset + length));
|
|
1553
|
-
if (isUtf16) {
|
|
1554
|
-
plistString = swapBytes(plistString);
|
|
1555
|
-
enc = "ucs2";
|
|
1556
|
-
}
|
|
1557
|
-
return plistString.toString(enc);
|
|
1558
|
-
}
|
|
1559
|
-
throw new Error("To little heap space available! Wanted to read " + length + " bytes, but only " + exports.maxObjectSize + " are available.");
|
|
1560
|
-
}
|
|
1561
|
-
__name(parsePlistString, "parsePlistString");
|
|
1562
|
-
function parseArray() {
|
|
1563
|
-
let length = objInfo;
|
|
1564
|
-
let arrayoffset = 1;
|
|
1565
|
-
if (objInfo == 15) {
|
|
1566
|
-
const int_type = buffer[offset + 1];
|
|
1567
|
-
const intType = (int_type & 240) / 16;
|
|
1568
|
-
if (intType != 1) {
|
|
1569
|
-
console.error("0xa: UNEXPECTED LENGTH-INT TYPE! " + intType);
|
|
1570
|
-
}
|
|
1571
|
-
const intInfo = int_type & 15;
|
|
1572
|
-
const intLength = Math.pow(2, intInfo);
|
|
1573
|
-
arrayoffset = 2 + intLength;
|
|
1574
|
-
if (intLength < 3) {
|
|
1575
|
-
length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
|
|
1576
|
-
} else {
|
|
1577
|
-
length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
if (length * objectRefSize > exports.maxObjectSize) {
|
|
1581
|
-
throw new Error("To little heap space available!");
|
|
1582
|
-
}
|
|
1583
|
-
const array = [];
|
|
1584
|
-
for (let i = 0; i < length; i++) {
|
|
1585
|
-
const objRef = readUInt(buffer.slice(offset + arrayoffset + i * objectRefSize, offset + arrayoffset + (i + 1) * objectRefSize));
|
|
1586
|
-
array[i] = parseObject(objRef);
|
|
1587
|
-
}
|
|
1588
|
-
return array;
|
|
1589
|
-
}
|
|
1590
|
-
__name(parseArray, "parseArray");
|
|
1591
|
-
function parseDictionary() {
|
|
1592
|
-
let length = objInfo;
|
|
1593
|
-
let dictoffset = 1;
|
|
1594
|
-
if (objInfo == 15) {
|
|
1595
|
-
const int_type = buffer[offset + 1];
|
|
1596
|
-
const intType = (int_type & 240) / 16;
|
|
1597
|
-
if (intType != 1) {
|
|
1598
|
-
console.error("0xD: UNEXPECTED LENGTH-INT TYPE! " + intType);
|
|
1599
|
-
}
|
|
1600
|
-
const intInfo = int_type & 15;
|
|
1601
|
-
const intLength = Math.pow(2, intInfo);
|
|
1602
|
-
dictoffset = 2 + intLength;
|
|
1603
|
-
if (intLength < 3) {
|
|
1604
|
-
length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
|
|
1605
|
-
} else {
|
|
1606
|
-
length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
if (length * 2 * objectRefSize > exports.maxObjectSize) {
|
|
1610
|
-
throw new Error("To little heap space available!");
|
|
1611
|
-
}
|
|
1612
|
-
if (debug) {
|
|
1613
|
-
console.log("Parsing dictionary #" + tableOffset);
|
|
1614
|
-
}
|
|
1615
|
-
const dict = {};
|
|
1616
|
-
for (let i = 0; i < length; i++) {
|
|
1617
|
-
const keyRef = readUInt(buffer.slice(offset + dictoffset + i * objectRefSize, offset + dictoffset + (i + 1) * objectRefSize));
|
|
1618
|
-
const valRef = readUInt(buffer.slice(offset + dictoffset + length * objectRefSize + i * objectRefSize, offset + dictoffset + length * objectRefSize + (i + 1) * objectRefSize));
|
|
1619
|
-
const key = parseObject(keyRef);
|
|
1620
|
-
const val = parseObject(valRef);
|
|
1621
|
-
if (debug) {
|
|
1622
|
-
console.log(" DICT #" + tableOffset + ": Mapped " + key + " to " + val);
|
|
1623
|
-
}
|
|
1624
|
-
dict[key] = val;
|
|
1625
|
-
}
|
|
1626
|
-
return dict;
|
|
1627
|
-
}
|
|
1628
|
-
__name(parseDictionary, "parseDictionary");
|
|
1629
|
-
}
|
|
1630
|
-
__name(parseObject, "parseObject");
|
|
1631
|
-
return [parseObject(topObject)];
|
|
1632
|
-
};
|
|
1633
|
-
function readUInt(buffer, start) {
|
|
1634
|
-
start = start || 0;
|
|
1635
|
-
let l = 0;
|
|
1636
|
-
for (let i = start; i < buffer.length; i++) {
|
|
1637
|
-
l <<= 8;
|
|
1638
|
-
l |= buffer[i] & 255;
|
|
1639
|
-
}
|
|
1640
|
-
return l;
|
|
1641
|
-
}
|
|
1642
|
-
__name(readUInt, "readUInt");
|
|
1643
|
-
function readUInt64BE(buffer, start) {
|
|
1644
|
-
const data = buffer.slice(start, start + 8);
|
|
1645
|
-
return data.readUInt32BE(4, 8);
|
|
1646
|
-
}
|
|
1647
|
-
__name(readUInt64BE, "readUInt64BE");
|
|
1648
|
-
function swapBytes(buffer) {
|
|
1649
|
-
const len = buffer.length;
|
|
1650
|
-
for (let i = 0; i < len; i += 2) {
|
|
1651
|
-
const a = buffer[i];
|
|
1652
|
-
buffer[i] = buffer[i + 1];
|
|
1653
|
-
buffer[i + 1] = a;
|
|
1654
|
-
}
|
|
1655
|
-
return buffer;
|
|
1656
|
-
}
|
|
1657
|
-
__name(swapBytes, "swapBytes");
|
|
1658
|
-
}
|
|
1659
|
-
});
|
|
1660
|
-
|
|
1661
|
-
// ../node_modules/untildify/index.js
|
|
1662
|
-
var require_untildify = __commonJS({
|
|
1663
|
-
"../node_modules/untildify/index.js"(exports, module) {
|
|
1664
|
-
"use strict";
|
|
1665
|
-
var os2 = __require("os");
|
|
1666
|
-
var homeDirectory = os2.homedir();
|
|
1667
|
-
module.exports = (pathWithTilde) => {
|
|
1668
|
-
if (typeof pathWithTilde !== "string") {
|
|
1669
|
-
throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`);
|
|
1670
|
-
}
|
|
1671
|
-
return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde;
|
|
1672
|
-
};
|
|
1673
|
-
}
|
|
1674
|
-
});
|
|
1675
|
-
|
|
1676
|
-
// ../node_modules/@aw-web-design/x-default-browser/node_modules/default-browser-id/index.js
|
|
1677
|
-
import os from "os";
|
|
1678
|
-
import { promises as fs } from "fs";
|
|
1679
|
-
async function defaultBrowserId() {
|
|
1680
|
-
if (process.platform !== "darwin") {
|
|
1681
|
-
throw new Error("macOS only");
|
|
1682
|
-
}
|
|
1683
|
-
let bundleId = "com.apple.Safari";
|
|
1684
|
-
let buffer;
|
|
1685
|
-
try {
|
|
1686
|
-
buffer = await fs.readFile(filePath);
|
|
1687
|
-
} catch (error) {
|
|
1688
|
-
if (error.code === "ENOENT") {
|
|
1689
|
-
return bundleId;
|
|
1690
|
-
}
|
|
1691
|
-
throw error;
|
|
1692
|
-
}
|
|
1693
|
-
const data = import_bplist_parser.default.parseBuffer(buffer);
|
|
1694
|
-
const handlers = data && data[0].LSHandlers;
|
|
1695
|
-
if (!handlers || handlers.length === 0) {
|
|
1696
|
-
return bundleId;
|
|
1697
|
-
}
|
|
1698
|
-
for (const handler of handlers) {
|
|
1699
|
-
if (handler.LSHandlerURLScheme === "http" && handler.LSHandlerRoleAll) {
|
|
1700
|
-
bundleId = handler.LSHandlerRoleAll;
|
|
1701
|
-
break;
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
return bundleId;
|
|
1705
|
-
}
|
|
1706
|
-
var import_bplist_parser, import_untildify, macOsVersion, filePath;
|
|
1707
|
-
var init_default_browser_id = __esm({
|
|
1708
|
-
"../node_modules/@aw-web-design/x-default-browser/node_modules/default-browser-id/index.js"() {
|
|
1709
|
-
import_bplist_parser = __toESM(require_bplistParser(), 1);
|
|
1710
|
-
import_untildify = __toESM(require_untildify(), 1);
|
|
1711
|
-
macOsVersion = Number(os.release().split(".")[0]);
|
|
1712
|
-
filePath = (0, import_untildify.default)(macOsVersion >= 14 ? "~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist" : "~/Library/Preferences/com.apple.LaunchServices.plist");
|
|
1713
|
-
__name(defaultBrowserId, "defaultBrowserId");
|
|
1714
|
-
}
|
|
1715
|
-
});
|
|
1716
|
-
init_default_browser_id();
|
|
1717
|
-
export {
|
|
1718
|
-
defaultBrowserId as default
|
|
1719
|
-
};
|