@series-inc/rundot-game-sdk 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2088 @@
1
+ import { SDK_VERSION, createHost, initializeStorage, initializeRoomsApi, initializeAds, initializePopups, initializeAnalytics, initializeIap, initializeLeaderboard, initializeLocalNotifications, initializePreloader, initializeTime, initializeLifecycleApi, initializeHaptics, initializeCdn, initializeFeaturesApi, initializeLoggingApi, initializeProfile, initializeSystem, initializeAvatar3d, initializeStackNavigation, initializeAi, initializeSimulation, initializeSocial } from '../chunk-RT4CMCVW.js';
2
+ import { createProxiedObject, createProxiedMethod } from '../chunk-3GKY3LY5.js';
3
+
4
+ // src/rundot-game-api/systems/asset-loader.js
5
+ var RundotGameAssetLoader = class {
6
+ constructor() {
7
+ this.cache = /* @__PURE__ */ new Map();
8
+ this.blobUrls = /* @__PURE__ */ new Map();
9
+ this.isWebView = false;
10
+ this.rundotGameAPI = null;
11
+ }
12
+ // Set the RundotGameAPI reference during initialization
13
+ setRundotGameAPI(api2) {
14
+ this.rundotGameAPI = api2;
15
+ this.isWebView = typeof window !== "undefined" && typeof window.ReactNativeWebView !== "undefined";
16
+ }
17
+ /**
18
+ * Load any asset with automatic optimization
19
+ * @param {string} url - Asset URL
20
+ * @param {Object} options - Loading options
21
+ * @returns {Promise<string>} - URL to use (original, blob, or object URL)
22
+ */
23
+ async loadAsset(url, options = {}) {
24
+ const {
25
+ type = "auto",
26
+ // 'image', 'audio', 'video', 'text', 'json', 'auto'
27
+ cache = true,
28
+ // Use cache
29
+ timeout = 3e4,
30
+ isOptional = false
31
+ // New option to suppress error logging for optional assets
32
+ } = options;
33
+ const resolvedUrl = this.rundotGameAPI.cdn.resolveAssetUrl(url);
34
+ if (cache && this.cache.has(resolvedUrl)) {
35
+ return this.cache.get(resolvedUrl);
36
+ }
37
+ const assetType = type === "auto" ? this._detectType(resolvedUrl) : type;
38
+ try {
39
+ let resultUrl = resolvedUrl;
40
+ if (assetType === "text" || assetType === "json") {
41
+ const content = await this._fetchText(resolvedUrl, timeout);
42
+ this.cache.set(resolvedUrl, content);
43
+ return content;
44
+ }
45
+ const isMockMode = this.rundotGameAPI && this.rundotGameAPI.isMock && this.rundotGameAPI.isMock();
46
+ if (this.isWebView && !isMockMode && ["image", "audio", "video"].includes(assetType)) {
47
+ if (assetType === "video") {
48
+ resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
49
+ if (cache) {
50
+ this.cache.set(resolvedUrl, resultUrl);
51
+ }
52
+ return resultUrl;
53
+ } else if (assetType === "audio") {
54
+ resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
55
+ } else {
56
+ resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
57
+ }
58
+ }
59
+ if (!(this.isWebView && !isMockMode && assetType === "video")) {
60
+ await this._verifyAsset(resultUrl, assetType);
61
+ }
62
+ if (cache) {
63
+ this.cache.set(resolvedUrl, resultUrl);
64
+ }
65
+ return resultUrl;
66
+ } catch (error) {
67
+ if (!isOptional) {
68
+ console.error(`[RundotGameAssetLoader] Failed to load ${resolvedUrl}:`, error);
69
+ }
70
+ throw error;
71
+ }
72
+ }
73
+ async _fetchText(url, timeout) {
74
+ const controller = new AbortController();
75
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
76
+ try {
77
+ const response = await fetch(url, { signal: controller.signal });
78
+ clearTimeout(timeoutId);
79
+ if (!response.ok) {
80
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
81
+ }
82
+ return await response.text();
83
+ } catch (error) {
84
+ clearTimeout(timeoutId);
85
+ throw error;
86
+ }
87
+ }
88
+ async _loadAsBlob(url, type) {
89
+ if (this.blobUrls.has(url)) {
90
+ return this.blobUrls.get(url);
91
+ }
92
+ const mimeType = {
93
+ image: "image/*",
94
+ audio: "audio/*",
95
+ video: "video/*"
96
+ }[type] || "*/*";
97
+ const controller = new AbortController();
98
+ const timeoutId = setTimeout(() => controller.abort(), 3e4);
99
+ try {
100
+ const response = await fetch(url, {
101
+ mode: "cors",
102
+ credentials: "omit",
103
+ headers: { Accept: mimeType },
104
+ signal: controller.signal
105
+ });
106
+ clearTimeout(timeoutId);
107
+ if (!response.ok) {
108
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
109
+ }
110
+ const blob = await response.blob();
111
+ const blobUrl = URL.createObjectURL(blob);
112
+ this.blobUrls.set(url, blobUrl);
113
+ return blobUrl;
114
+ } catch (error) {
115
+ clearTimeout(timeoutId);
116
+ throw error;
117
+ }
118
+ }
119
+ async _checkStreamingSupport(url) {
120
+ try {
121
+ const response = await fetch(url, { method: "HEAD" });
122
+ const acceptRanges = response.headers.get("Accept-Ranges") === "bytes";
123
+ const contentLength = response.headers.get("Content-Length");
124
+ return acceptRanges && !!contentLength;
125
+ } catch {
126
+ return false;
127
+ }
128
+ }
129
+ async _verifyAsset(url, type) {
130
+ return new Promise((resolve, reject) => {
131
+ const timeout = setTimeout(() => {
132
+ reject(new Error(`Verification timeout for ${type} asset`));
133
+ }, 1e4);
134
+ if (type === "image") {
135
+ const img = new Image();
136
+ img.onload = () => {
137
+ clearTimeout(timeout);
138
+ resolve();
139
+ };
140
+ img.onerror = (error) => {
141
+ clearTimeout(timeout);
142
+ reject(new Error("Failed to load image"));
143
+ };
144
+ img.src = url;
145
+ } else if (type === "audio") {
146
+ const audio = new Audio();
147
+ audio.oncanplaythrough = () => {
148
+ clearTimeout(timeout);
149
+ resolve();
150
+ };
151
+ audio.onerror = () => {
152
+ clearTimeout(timeout);
153
+ reject(new Error("Failed to load audio"));
154
+ };
155
+ audio.src = url;
156
+ audio.load();
157
+ } else if (type === "video") {
158
+ const video = document.createElement("video");
159
+ video.onloadedmetadata = () => {
160
+ clearTimeout(timeout);
161
+ video.src = "";
162
+ resolve();
163
+ };
164
+ video.onerror = () => {
165
+ clearTimeout(timeout);
166
+ reject(new Error("Failed to load video"));
167
+ };
168
+ video.src = url;
169
+ } else {
170
+ clearTimeout(timeout);
171
+ resolve();
172
+ }
173
+ });
174
+ }
175
+ _detectType(url) {
176
+ const ext = url.split(".").pop()?.toLowerCase();
177
+ if (["jpg", "jpeg", "png", "gif", "webp", "svg"].includes(ext)) return "image";
178
+ if (["mp3", "wav", "ogg", "m4a", "aac"].includes(ext)) return "audio";
179
+ if (["mp4", "webm", "mov", "m4v"].includes(ext)) return "video";
180
+ if (["json"].includes(ext)) return "json";
181
+ return "text";
182
+ }
183
+ /**
184
+ * Preload multiple assets in parallel
185
+ * @param {(string|{url: string, isOptional?: boolean})[]} urls - Array of URLs or URL objects with optional metadata
186
+ * @param {Object} options - Loading options
187
+ */
188
+ async preloadAssets(urls, options = {}) {
189
+ const { onProgress } = options;
190
+ let loaded = 0;
191
+ const total = urls.length;
192
+ const normalizedUrls = urls.map((item) => {
193
+ if (typeof item === "string") {
194
+ return { url: item, isOptional: false };
195
+ }
196
+ return {
197
+ url: item.url,
198
+ isOptional: item.isOptional || false
199
+ };
200
+ });
201
+ const results = await Promise.allSettled(
202
+ normalizedUrls.map(async (item) => {
203
+ try {
204
+ const result = await this.loadAsset(item.url, { ...options, isOptional: item.isOptional });
205
+ loaded++;
206
+ if (onProgress) {
207
+ onProgress(loaded / total, { loaded, total, current: item.url });
208
+ }
209
+ return { url: item.url, result, success: true, isOptional: item.isOptional };
210
+ } catch (error) {
211
+ loaded++;
212
+ if (onProgress) {
213
+ onProgress(loaded / total, { loaded, total, current: item.url, error });
214
+ }
215
+ return { url: item.url, error, success: false, isOptional: item.isOptional };
216
+ }
217
+ })
218
+ );
219
+ const failedRequired = results.filter(
220
+ (r2) => (r2.status === "rejected" || !r2.value?.success) && !r2.value?.isOptional
221
+ );
222
+ if (failedRequired.length > 0) {
223
+ console.warn(`[RundotGameAssetLoader] ${failedRequired.length} required assets failed to load`);
224
+ failedRequired.forEach((r2) => {
225
+ console.warn(`[RundotGameAssetLoader] Failed required asset: ${r2.value?.url}`);
226
+ });
227
+ }
228
+ const failedOptional = results.filter(
229
+ (r2) => (r2.status === "rejected" || !r2.value?.success) && r2.value?.isOptional
230
+ );
231
+ if (failedOptional.length > 0) {
232
+ console.info(`[RundotGameAssetLoader] ${failedOptional.length} optional assets were not found (this is OK)`);
233
+ }
234
+ return results.map((r2) => r2.value);
235
+ }
236
+ /**
237
+ * Clean up blob URLs to prevent memory leaks
238
+ */
239
+ cleanup() {
240
+ for (const blobUrl of this.blobUrls.values()) {
241
+ URL.revokeObjectURL(blobUrl);
242
+ }
243
+ this.blobUrls.clear();
244
+ this.cache.clear();
245
+ }
246
+ /**
247
+ * Get a cached asset URL if available
248
+ */
249
+ getCached(url) {
250
+ const resolvedUrl = this.rundotGameAPI.cdn.resolveAssetUrl(url);
251
+ return this.cache.get(resolvedUrl);
252
+ }
253
+ };
254
+ if (typeof RundotGameAPI !== "undefined") {
255
+ RundotGameAPI.assetLoader = new RundotGameAssetLoader();
256
+ RundotGameAPI.loadAsset = (url, options) => RundotGameAPI.assetLoader.loadAsset(url, options);
257
+ RundotGameAPI.preloadAssets = (urls, options) => RundotGameAPI.assetLoader.preloadAssets(urls, options);
258
+ RundotGameAPI.cleanupAssets = () => RundotGameAPI.assetLoader.cleanup();
259
+ }
260
+ function initializeAssetLoader(rundotGameApi, createProxiedMethod2) {
261
+ const assetLoader = new RundotGameAssetLoader();
262
+ assetLoader.setRundotGameAPI(api);
263
+ api._assetLoader = assetLoader;
264
+ api.assetLoader = assetLoader;
265
+ if (createProxiedMethod2) {
266
+ api.loadAsset = createProxiedMethod2("loadAsset", function(url, options) {
267
+ return assetLoader.loadAsset(url, options);
268
+ });
269
+ api.preloadAssets = createProxiedMethod2("preloadAssets", function(urls, options) {
270
+ return assetLoader.preloadAssets(urls, options);
271
+ });
272
+ api.cleanupAssets = createProxiedMethod2("cleanupAssets", function() {
273
+ return assetLoader.cleanup();
274
+ });
275
+ } else {
276
+ api.loadAsset = function(url, options) {
277
+ return assetLoader.loadAsset(url, options);
278
+ };
279
+ api.preloadAssets = function(urls, options) {
280
+ return assetLoader.preloadAssets(urls, options);
281
+ };
282
+ api.cleanupAssets = function() {
283
+ return assetLoader.cleanup();
284
+ };
285
+ }
286
+ if (typeof window !== "undefined" && window.RundotGameAPI) {
287
+ window.RundotGameAPI.loadAsset = api.loadAsset;
288
+ window.RundotGameAPI.preloadAssets = api.preloadAssets;
289
+ window.RundotGameAPI.cleanupAssets = api.cleanupAssets;
290
+ }
291
+ }
292
+
293
+ // src/rundot-game-api/lib/break_eternity.js
294
+ function se(r2, n) {
295
+ if (!(r2 instanceof n)) throw new TypeError("Cannot call a class as a function");
296
+ }
297
+ function le(r2, n) {
298
+ for (var e = 0; e < n.length; e++) {
299
+ var t = n[e];
300
+ t.enumerable = t.enumerable || false, t.configurable = true, "value" in t && (t.writable = true), Object.defineProperty(r2, t.key, t);
301
+ }
302
+ }
303
+ function ue(r2, n, e) {
304
+ return n && le(r2.prototype, n), e && le(r2, e), Object.defineProperty(r2, "prototype", { writable: false }), r2;
305
+ }
306
+ var me = (function() {
307
+ function r2(n) {
308
+ se(this, r2), this.map = /* @__PURE__ */ new Map(), this.first = void 0, this.last = void 0, this.maxSize = n;
309
+ }
310
+ return ue(r2, [{ key: "size", get: function() {
311
+ return this.map.size;
312
+ } }, { key: "get", value: function(e) {
313
+ var t = this.map.get(e);
314
+ if (t !== void 0) return t !== this.first && (t === this.last ? (this.last = t.prev, this.last.next = void 0) : (t.prev.next = t.next, t.next.prev = t.prev), t.next = this.first, this.first.prev = t, this.first = t), t.value;
315
+ } }, { key: "set", value: function(e, t) {
316
+ if (!(this.maxSize < 1)) {
317
+ if (this.map.has(e)) throw new Error("Cannot update existing keys in the cache");
318
+ var i = new ge(e, t);
319
+ for (this.first === void 0 ? (this.first = i, this.last = i) : (i.next = this.first, this.first.prev = i, this.first = i), this.map.set(e, i); this.map.size > this.maxSize; ) {
320
+ var a = this.last;
321
+ this.map.delete(a.key), this.last = a.prev, this.last.next = void 0;
322
+ }
323
+ }
324
+ } }]), r2;
325
+ })();
326
+ var ge = ue(function r(n, e) {
327
+ se(this, r), this.next = void 0, this.prev = void 0, this.key = n, this.value = e;
328
+ });
329
+ var ne = 17;
330
+ var T = 9e15;
331
+ var ce = Math.log10(9e15);
332
+ var $ = 1 / 9e15;
333
+ var ve = 308;
334
+ var ye = -324;
335
+ var fe = 5;
336
+ var de = 1023;
337
+ var Ne = (function() {
338
+ for (var r2 = [], n = ye + 1; n <= ve; n++) r2.push(+("1e" + n));
339
+ var e = 323;
340
+ return function(t) {
341
+ return r2[t + e];
342
+ };
343
+ })();
344
+ var _ = [2, Math.E, 3, 4, 5, 6, 7, 8, 9, 10];
345
+ var be = [[1, 1.0891180521811203, 1.1789767925673957, 1.2701455431742086, 1.3632090180450092, 1.4587818160364217, 1.5575237916251419, 1.6601571006859253, 1.767485818836978, 1.8804192098842727, 2], [1, 1.1121114330934079, 1.231038924931609, 1.3583836963111375, 1.4960519303993531, 1.6463542337511945, 1.8121385357018724, 1.996971324618307, 2.2053895545527546, 2.4432574483385254, Math.E], [1, 1.1187738849693603, 1.2464963939368214, 1.38527004705667, 1.5376664685821402, 1.7068895236551784, 1.897001227148399, 2.1132403089001035, 2.362480153784171, 2.6539010333870774, 3], [1, 1.1367350847096405, 1.2889510672956703, 1.4606478703324786, 1.6570295196661111, 1.8850062585672889, 2.1539465047453485, 2.476829779693097, 2.872061932789197, 3.3664204535587183, 4], [1, 1.1494592900767588, 1.319708228183931, 1.5166291280087583, 1.748171114438024, 2.0253263297298045, 2.3636668498288547, 2.7858359149579424, 3.3257226212448145, 4.035730287722532, 5], [1, 1.159225940787673, 1.343712473580932, 1.5611293155111927, 1.8221199554561318, 2.14183924486326, 2.542468319282638, 3.0574682501653316, 3.7390572020926873, 4.6719550537360774, 6], [1, 1.1670905356972596, 1.3632807444991446, 1.5979222279405536, 1.8842640123816674, 2.2416069644878687, 2.69893426559423, 3.3012632110403577, 4.121250340630164, 5.281493033448316, 7], [1, 1.1736630594087796, 1.379783782386201, 1.6292821855668218, 1.9378971836180754, 2.3289975651071977, 2.8384347394720835, 3.5232708454565906, 4.478242031114584, 5.868592169644505, 8], [1, 1.1793017514670474, 1.394054150657457, 1.65664127441059, 1.985170999970283, 2.4069682290577457, 2.9647310119960752, 3.7278665320924946, 4.814462547283592, 6.436522247411611, 9], [1, 1.1840100246247336, 1.4061375836156955, 1.6802272208863964, 2.026757028388619, 2.4770056063449646, 3.080525271755482, 3.9191964192627284, 5.135152840833187, 6.989961179534715, 10]];
346
+ var we = [[-1, -0.9194161097107025, -0.8335625019330468, -0.7425599821143978, -0.6466611521029437, -0.5462617907227869, -0.4419033816638769, -0.3342645487554494, -0.224140440909962, -0.11241087890006762, 0], [-1, -0.90603157029014, -0.80786507256596, -0.7064666939634, -0.60294836853664, -0.49849837513117, -0.39430303318768, -0.29147201034755, -0.19097820800866, -0.09361896280296, 0], [-1, -0.9021579584316141, -0.8005762598234203, -0.6964780623319391, -0.5911906810998454, -0.486050182576545, -0.3823089430815083, -0.28106046722897615, -0.1831906535795894, -0.08935809204418144, 0], [-1, -0.8917227442365535, -0.781258746326964, -0.6705130326902455, -0.5612813129406509, -0.4551067709033134, -0.35319256652135966, -0.2563741554088552, -0.1651412821106526, -0.0796919581982668, 0], [-1, -0.8843387974366064, -0.7678744063886243, -0.6529563724510552, -0.5415870994657841, -0.4352842206588936, -0.33504449124791424, -0.24138853420685147, -0.15445285440944467, -0.07409659641336663, 0], [-1, -0.8786709358426346, -0.7577735191184886, -0.6399546189952064, -0.527284921869926, -0.4211627631006314, -0.3223479611761232, -0.23107655627789858, -0.1472057700818259, -0.07035171210706326, 0], [-1, -0.8740862815291583, -0.7497032990976209, -0.6297119746181752, -0.5161838335958787, -0.41036238255751956, -0.31277212146489963, -0.2233976621705518, -0.1418697367979619, -0.06762117662323441, 0], [-1, -0.8702632331800649, -0.7430366914122081, -0.6213373075161548, -0.5072025698095242, -0.40171437727184167, -0.30517930701410456, -0.21736343968190863, -0.137710238299109, -0.06550774483471955, 0], [-1, -0.8670016295947213, -0.7373984232432306, -0.6143173985094293, -0.49973884395492807, -0.394584953527678, -0.2989649949848695, -0.21245647317021688, -0.13434688362382652, -0.0638072667348083, 0], [-1, -0.8641642839543857, -0.732534623168535, -0.6083127477059322, -0.4934049257184696, -0.3885773075899922, -0.29376029055315767, -0.2083678561173622, -0.13155653399373268, -0.062401588652553186, 0]];
347
+ var s = function(n) {
348
+ return k.fromValue_noAlloc(n);
349
+ };
350
+ var m = function(n, e, t) {
351
+ return k.fromComponents(n, e, t);
352
+ };
353
+ var c = function(n, e, t) {
354
+ return k.fromComponents_noNormalize(n, e, t);
355
+ };
356
+ var K = function(n, e) {
357
+ var t = e + 1, i = Math.ceil(Math.log10(Math.abs(n))), a = Math.round(n * Math.pow(10, t - i)) * Math.pow(10, i - t);
358
+ return parseFloat(a.toFixed(Math.max(t - i, 0)));
359
+ };
360
+ var ie = function(n) {
361
+ return Math.sign(n) * Math.log10(Math.abs(n));
362
+ };
363
+ var ke = function(n) {
364
+ if (!isFinite(n)) return n;
365
+ if (n < -50) return n === Math.trunc(n) ? Number.NEGATIVE_INFINITY : 0;
366
+ for (var e = 1; n < 10; ) e = e * n, ++n;
367
+ n -= 1;
368
+ var t = 0.9189385332046727;
369
+ t = t + (n + 0.5) * Math.log(n), t = t - n;
370
+ var i = n * n, a = n;
371
+ return t = t + 1 / (12 * a), a = a * i, t = t - 1 / (360 * a), a = a * i, t = t + 1 / (1260 * a), a = a * i, t = t - 1 / (1680 * a), a = a * i, t = t + 1 / (1188 * a), a = a * i, t = t - 691 / (360360 * a), a = a * i, t = t + 7 / (1092 * a), a = a * i, t = t - 3617 / (122400 * a), Math.exp(t) / e;
372
+ };
373
+ var Me = 0.36787944117144233;
374
+ var oe = 0.5671432904097838;
375
+ var ae = function(n) {
376
+ var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1e-10, t = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true, i, a;
377
+ if (!Number.isFinite(n)) return n;
378
+ if (t) {
379
+ if (n === 0) return n;
380
+ if (n === 1) return oe;
381
+ n < 10 ? i = 0 : i = Math.log(n) - Math.log(Math.log(n));
382
+ } else {
383
+ if (n === 0) return -1 / 0;
384
+ n <= -0.1 ? i = -2 : i = Math.log(-n) - Math.log(-Math.log(-n));
385
+ }
386
+ for (var l = 0; l < 100; ++l) {
387
+ if (a = (n * Math.exp(-i) + i * i) / (i + 1), Math.abs(a - i) < e * Math.abs(a)) return a;
388
+ i = a;
389
+ }
390
+ throw Error("Iteration failed to converge: ".concat(n.toString()));
391
+ };
392
+ function he(r2) {
393
+ var n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1e-10, e = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true, t, i, a, l;
394
+ if (!Number.isFinite(r2.mag)) return new k(r2);
395
+ if (e) {
396
+ if (r2.eq(k.dZero)) return c(0, 0, 0);
397
+ if (r2.eq(k.dOne)) return k.fromNumber(oe);
398
+ t = k.ln(r2);
399
+ } else {
400
+ if (r2.eq(k.dZero)) return new k(k.dNegInf);
401
+ t = k.ln(r2.neg());
402
+ }
403
+ for (var f = 0; f < 100; ++f) {
404
+ if (i = t.neg().exp(), a = t.sub(r2.mul(i)), l = t.sub(a.div(t.add(1).sub(t.add(2).mul(a).div(k.mul(2, t).add(2))))), k.abs(l.sub(t)).lt(k.abs(l).mul(n))) return l;
405
+ t = l;
406
+ }
407
+ throw Error("Iteration failed to converge: ".concat(r2.toString()));
408
+ }
409
+ var k = (function() {
410
+ function r2(n) {
411
+ se(this, r2), this.sign = 0, this.mag = 0, this.layer = 0, n instanceof r2 ? this.fromDecimal(n) : typeof n == "number" ? this.fromNumber(n) : typeof n == "string" && this.fromString(n);
412
+ }
413
+ return ue(r2, [{ key: "m", get: function() {
414
+ if (this.sign === 0) return 0;
415
+ if (this.layer === 0) {
416
+ var e = Math.floor(Math.log10(this.mag)), t;
417
+ return this.mag === 5e-324 ? t = 5 : t = this.mag / Ne(e), this.sign * t;
418
+ } else if (this.layer === 1) {
419
+ var i = this.mag - Math.floor(this.mag);
420
+ return this.sign * Math.pow(10, i);
421
+ } else return this.sign;
422
+ }, set: function(e) {
423
+ this.layer <= 2 ? this.fromMantissaExponent(e, this.e) : (this.sign = Math.sign(e), this.sign === 0 && (this.layer = 0, this.exponent = 0));
424
+ } }, { key: "e", get: function() {
425
+ return this.sign === 0 ? 0 : this.layer === 0 ? Math.floor(Math.log10(this.mag)) : this.layer === 1 ? Math.floor(this.mag) : this.layer === 2 ? Math.floor(Math.sign(this.mag) * Math.pow(10, Math.abs(this.mag))) : this.mag * Number.POSITIVE_INFINITY;
426
+ }, set: function(e) {
427
+ this.fromMantissaExponent(this.m, e);
428
+ } }, { key: "s", get: function() {
429
+ return this.sign;
430
+ }, set: function(e) {
431
+ e === 0 ? (this.sign = 0, this.layer = 0, this.mag = 0) : this.sign = e;
432
+ } }, { key: "mantissa", get: function() {
433
+ return this.m;
434
+ }, set: function(e) {
435
+ this.m = e;
436
+ } }, { key: "exponent", get: function() {
437
+ return this.e;
438
+ }, set: function(e) {
439
+ this.e = e;
440
+ } }, { key: "normalize", value: function() {
441
+ if (this.sign === 0 || this.mag === 0 && this.layer === 0 || this.mag === Number.NEGATIVE_INFINITY && this.layer > 0 && Number.isFinite(this.layer)) return this.sign = 0, this.mag = 0, this.layer = 0, this;
442
+ if (this.layer === 0 && this.mag < 0 && (this.mag = -this.mag, this.sign = -this.sign), this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY || this.mag === Number.NEGATIVE_INFINITY || this.layer === Number.NEGATIVE_INFINITY) return this.mag = Number.POSITIVE_INFINITY, this.layer = Number.POSITIVE_INFINITY, this;
443
+ if (this.layer === 0 && this.mag < $) return this.layer += 1, this.mag = Math.log10(this.mag), this;
444
+ var e = Math.abs(this.mag), t = Math.sign(this.mag);
445
+ if (e >= T) return this.layer += 1, this.mag = t * Math.log10(e), this;
446
+ for (; e < ce && this.layer > 0; ) this.layer -= 1, this.layer === 0 ? this.mag = Math.pow(10, this.mag) : (this.mag = t * Math.pow(10, e), e = Math.abs(this.mag), t = Math.sign(this.mag));
447
+ return this.layer === 0 && (this.mag < 0 ? (this.mag = -this.mag, this.sign = -this.sign) : this.mag === 0 && (this.sign = 0)), (Number.isNaN(this.sign) || Number.isNaN(this.layer) || Number.isNaN(this.mag)) && (this.sign = Number.NaN, this.layer = Number.NaN, this.mag = Number.NaN), this;
448
+ } }, { key: "fromComponents", value: function(e, t, i) {
449
+ return this.sign = e, this.layer = t, this.mag = i, this.normalize(), this;
450
+ } }, { key: "fromComponents_noNormalize", value: function(e, t, i) {
451
+ return this.sign = e, this.layer = t, this.mag = i, this;
452
+ } }, { key: "fromMantissaExponent", value: function(e, t) {
453
+ return this.layer = 1, this.sign = Math.sign(e), e = Math.abs(e), this.mag = t + Math.log10(e), this.normalize(), this;
454
+ } }, { key: "fromMantissaExponent_noNormalize", value: function(e, t) {
455
+ return this.fromMantissaExponent(e, t), this;
456
+ } }, { key: "fromDecimal", value: function(e) {
457
+ return this.sign = e.sign, this.layer = e.layer, this.mag = e.mag, this;
458
+ } }, { key: "fromNumber", value: function(e) {
459
+ return this.mag = Math.abs(e), this.sign = Math.sign(e), this.layer = 0, this.normalize(), this;
460
+ } }, { key: "fromString", value: function(e) {
461
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, i = e, a = r2.fromStringCache.get(i);
462
+ if (a !== void 0) return this.fromDecimal(a);
463
+ e = e.replace(",", "");
464
+ var l = e.split("^^^");
465
+ if (l.length === 2) {
466
+ var f = parseFloat(l[0]), g = parseFloat(l[1]), h = l[1].split(";"), v = 1;
467
+ if (h.length === 2 && (v = parseFloat(h[1]), isFinite(v) || (v = 1)), isFinite(f) && isFinite(g)) {
468
+ var u = r2.pentate(f, g, v, t);
469
+ return this.sign = u.sign, this.layer = u.layer, this.mag = u.mag, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
470
+ }
471
+ }
472
+ var M = e.split("^^");
473
+ if (M.length === 2) {
474
+ var x = parseFloat(M[0]), w = parseFloat(M[1]), o = M[1].split(";"), F = 1;
475
+ if (o.length === 2 && (F = parseFloat(o[1]), isFinite(F) || (F = 1)), isFinite(x) && isFinite(w)) {
476
+ var A = r2.tetrate(x, w, F, t);
477
+ return this.sign = A.sign, this.layer = A.layer, this.mag = A.mag, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
478
+ }
479
+ }
480
+ var d = e.split("^");
481
+ if (d.length === 2) {
482
+ var S = parseFloat(d[0]), p = parseFloat(d[1]);
483
+ if (isFinite(S) && isFinite(p)) {
484
+ var q = r2.pow(S, p);
485
+ return this.sign = q.sign, this.layer = q.layer, this.mag = q.mag, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
486
+ }
487
+ }
488
+ e = e.trim().toLowerCase();
489
+ var I, N, y = e.split("pt");
490
+ if (y.length === 2) {
491
+ I = 10;
492
+ var V = false;
493
+ y[0][0] == "-" && (V = true, y[0] = y[0].slice(1)), N = parseFloat(y[0]), y[1] = y[1].replace("(", ""), y[1] = y[1].replace(")", "");
494
+ var C = parseFloat(y[1]);
495
+ if (isFinite(C) || (C = 1), isFinite(I) && isFinite(N)) {
496
+ var D = r2.tetrate(I, N, C, t);
497
+ return this.sign = D.sign, this.layer = D.layer, this.mag = D.mag, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), V && (this.sign *= -1), this;
498
+ }
499
+ }
500
+ if (y = e.split("p"), y.length === 2) {
501
+ I = 10;
502
+ var Y = false;
503
+ y[0][0] == "-" && (Y = true, y[0] = y[0].slice(1)), N = parseFloat(y[0]), y[1] = y[1].replace("(", ""), y[1] = y[1].replace(")", "");
504
+ var L = parseFloat(y[1]);
505
+ if (isFinite(L) || (L = 1), isFinite(I) && isFinite(N)) {
506
+ var G = r2.tetrate(I, N, L, t);
507
+ return this.sign = G.sign, this.layer = G.layer, this.mag = G.mag, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), Y && (this.sign *= -1), this;
508
+ }
509
+ }
510
+ if (y = e.split("f"), y.length === 2) {
511
+ I = 10;
512
+ var E = false;
513
+ y[0][0] == "-" && (E = true, y[0] = y[0].slice(1)), y[0] = y[0].replace("(", ""), y[0] = y[0].replace(")", "");
514
+ var X = parseFloat(y[0]);
515
+ if (y[1] = y[1].replace("(", ""), y[1] = y[1].replace(")", ""), N = parseFloat(y[1]), isFinite(X) || (X = 1), isFinite(I) && isFinite(N)) {
516
+ var Q = r2.tetrate(I, N, X, t);
517
+ return this.sign = Q.sign, this.layer = Q.layer, this.mag = Q.mag, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), E && (this.sign *= -1), this;
518
+ }
519
+ }
520
+ var J = e.split("e"), Z = J.length - 1;
521
+ if (Z === 0) {
522
+ var re = parseFloat(e);
523
+ if (isFinite(re)) return this.fromNumber(re), r2.fromStringCache.size >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
524
+ } else if (Z === 1) {
525
+ var W = parseFloat(e);
526
+ if (isFinite(W) && Math.abs(W) > 1e-307) return this.fromNumber(W), r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
527
+ }
528
+ var H = e.split("e^");
529
+ if (H.length === 2) {
530
+ this.sign = 1, H[0].charAt(0) == "-" && (this.sign = -1);
531
+ for (var te = "", U = 0; U < H[1].length; ++U) {
532
+ var P = H[1].charCodeAt(U);
533
+ if (P >= 43 && P <= 57 || P === 101) te += H[1].charAt(U);
534
+ else {
535
+ if (this.layer = parseFloat(te), this.mag = parseFloat(H[1].substr(U + 1)), this.layer < 0 || this.layer % 1 != 0) {
536
+ var B = r2.tetrate(10, this.layer, this.mag, t);
537
+ this.sign = B.sign, this.layer = B.layer, this.mag = B.mag;
538
+ }
539
+ return this.normalize(), r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
540
+ }
541
+ }
542
+ }
543
+ if (Z < 1) return this.sign = 0, this.layer = 0, this.mag = 0, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
544
+ var z = parseFloat(J[0]);
545
+ if (z === 0) return this.sign = 0, this.layer = 0, this.mag = 0, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
546
+ var R = parseFloat(J[J.length - 1]);
547
+ if (Z >= 2) {
548
+ var ee = parseFloat(J[J.length - 2]);
549
+ isFinite(ee) && (R *= Math.sign(ee), R += ie(ee));
550
+ }
551
+ if (!isFinite(z)) this.sign = J[0] === "-" ? -1 : 1, this.layer = Z, this.mag = R;
552
+ else if (Z === 1) this.sign = Math.sign(z), this.layer = 1, this.mag = R + Math.log10(Math.abs(z));
553
+ else if (this.sign = Math.sign(z), this.layer = Z, Z === 2) {
554
+ var j = r2.mul(m(1, 2, R), s(z));
555
+ return this.sign = j.sign, this.layer = j.layer, this.mag = j.mag, r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
556
+ } else this.mag = R;
557
+ return this.normalize(), r2.fromStringCache.maxSize >= 1 && r2.fromStringCache.set(i, r2.fromDecimal(this)), this;
558
+ } }, { key: "fromValue", value: function(e) {
559
+ return e instanceof r2 ? this.fromDecimal(e) : typeof e == "number" ? this.fromNumber(e) : typeof e == "string" ? this.fromString(e) : (this.sign = 0, this.layer = 0, this.mag = 0, this);
560
+ } }, { key: "toNumber", value: function() {
561
+ return this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY && this.sign === 1 ? Number.POSITIVE_INFINITY : this.mag === Number.POSITIVE_INFINITY && this.layer === Number.POSITIVE_INFINITY && this.sign === -1 ? Number.NEGATIVE_INFINITY : Number.isFinite(this.layer) ? this.layer === 0 ? this.sign * this.mag : this.layer === 1 ? this.sign * Math.pow(10, this.mag) : this.mag > 0 ? this.sign > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY : 0 : Number.NaN;
562
+ } }, { key: "mantissaWithDecimalPlaces", value: function(e) {
563
+ return isNaN(this.m) ? Number.NaN : this.m === 0 ? 0 : K(this.m, e);
564
+ } }, { key: "magnitudeWithDecimalPlaces", value: function(e) {
565
+ return isNaN(this.mag) ? Number.NaN : this.mag === 0 ? 0 : K(this.mag, e);
566
+ } }, { key: "toString", value: function() {
567
+ return isNaN(this.layer) || isNaN(this.sign) || isNaN(this.mag) ? "NaN" : this.mag === Number.POSITIVE_INFINITY || this.layer === Number.POSITIVE_INFINITY ? this.sign === 1 ? "Infinity" : "-Infinity" : this.layer === 0 ? this.mag < 1e21 && this.mag > 1e-7 || this.mag === 0 ? (this.sign * this.mag).toString() : this.m + "e" + this.e : this.layer === 1 ? this.m + "e" + this.e : this.layer <= fe ? (this.sign === -1 ? "-" : "") + "e".repeat(this.layer) + this.mag : (this.sign === -1 ? "-" : "") + "(e^" + this.layer + ")" + this.mag;
568
+ } }, { key: "toExponential", value: function(e) {
569
+ return this.layer === 0 ? (this.sign * this.mag).toExponential(e) : this.toStringWithDecimalPlaces(e);
570
+ } }, { key: "toFixed", value: function(e) {
571
+ return this.layer === 0 ? (this.sign * this.mag).toFixed(e) : this.toStringWithDecimalPlaces(e);
572
+ } }, { key: "toPrecision", value: function(e) {
573
+ return this.e <= -7 ? this.toExponential(e - 1) : e > this.e ? this.toFixed(e - this.exponent - 1) : this.toExponential(e - 1);
574
+ } }, { key: "valueOf", value: function() {
575
+ return this.toString();
576
+ } }, { key: "toJSON", value: function() {
577
+ return this.toString();
578
+ } }, { key: "toStringWithDecimalPlaces", value: function(e) {
579
+ return this.layer === 0 ? this.mag < 1e21 && this.mag > 1e-7 || this.mag === 0 ? (this.sign * this.mag).toFixed(e) : K(this.m, e) + "e" + K(this.e, e) : this.layer === 1 ? K(this.m, e) + "e" + K(this.e, e) : this.layer <= fe ? (this.sign === -1 ? "-" : "") + "e".repeat(this.layer) + K(this.mag, e) : (this.sign === -1 ? "-" : "") + "(e^" + this.layer + ")" + K(this.mag, e);
580
+ } }, { key: "abs", value: function() {
581
+ return c(this.sign === 0 ? 0 : 1, this.layer, this.mag);
582
+ } }, { key: "neg", value: function() {
583
+ return c(-this.sign, this.layer, this.mag);
584
+ } }, { key: "negate", value: function() {
585
+ return this.neg();
586
+ } }, { key: "negated", value: function() {
587
+ return this.neg();
588
+ } }, { key: "sgn", value: function() {
589
+ return this.sign;
590
+ } }, { key: "round", value: function() {
591
+ return this.mag < 0 ? c(0, 0, 0) : this.layer === 0 ? m(this.sign, 0, Math.round(this.mag)) : new r2(this);
592
+ } }, { key: "floor", value: function() {
593
+ return this.mag < 0 ? this.sign === -1 ? c(-1, 0, 1) : c(0, 0, 0) : this.sign === -1 ? this.neg().ceil().neg() : this.layer === 0 ? m(this.sign, 0, Math.floor(this.mag)) : new r2(this);
594
+ } }, { key: "ceil", value: function() {
595
+ return this.mag < 0 ? this.sign === 1 ? c(1, 0, 1) : c(0, 0, 0) : this.sign === -1 ? this.neg().floor().neg() : this.layer === 0 ? m(this.sign, 0, Math.ceil(this.mag)) : new r2(this);
596
+ } }, { key: "trunc", value: function() {
597
+ return this.mag < 0 ? c(0, 0, 0) : this.layer === 0 ? m(this.sign, 0, Math.trunc(this.mag)) : new r2(this);
598
+ } }, { key: "add", value: function(e) {
599
+ var t = s(e);
600
+ if (this.eq(r2.dInf) && t.eq(r2.dNegInf) || this.eq(r2.dNegInf) && t.eq(r2.dInf)) return new r2(r2.dNaN);
601
+ if (!Number.isFinite(this.layer)) return new r2(this);
602
+ if (!Number.isFinite(t.layer)) return new r2(t);
603
+ if (this.sign === 0) return new r2(t);
604
+ if (t.sign === 0) return new r2(this);
605
+ if (this.sign === -t.sign && this.layer === t.layer && this.mag === t.mag) return c(0, 0, 0);
606
+ var i, a;
607
+ if (this.layer >= 2 || t.layer >= 2) return this.maxabs(t);
608
+ if (r2.cmpabs(this, t) > 0 ? (i = new r2(this), a = new r2(t)) : (i = new r2(t), a = new r2(this)), i.layer === 0 && a.layer === 0) return r2.fromNumber(i.sign * i.mag + a.sign * a.mag);
609
+ var l = i.layer * Math.sign(i.mag), f = a.layer * Math.sign(a.mag);
610
+ if (l - f >= 2) return i;
611
+ if (l === 0 && f === -1) {
612
+ if (Math.abs(a.mag - Math.log10(i.mag)) > ne) return i;
613
+ var g = Math.pow(10, Math.log10(i.mag) - a.mag), h = a.sign + i.sign * g;
614
+ return m(Math.sign(h), 1, a.mag + Math.log10(Math.abs(h)));
615
+ }
616
+ if (l === 1 && f === 0) {
617
+ if (Math.abs(i.mag - Math.log10(a.mag)) > ne) return i;
618
+ var v = Math.pow(10, i.mag - Math.log10(a.mag)), u = a.sign + i.sign * v;
619
+ return m(Math.sign(u), 1, Math.log10(a.mag) + Math.log10(Math.abs(u)));
620
+ }
621
+ if (Math.abs(i.mag - a.mag) > ne) return i;
622
+ var M = Math.pow(10, i.mag - a.mag), x = a.sign + i.sign * M;
623
+ return m(Math.sign(x), 1, a.mag + Math.log10(Math.abs(x)));
624
+ } }, { key: "plus", value: function(e) {
625
+ return this.add(e);
626
+ } }, { key: "sub", value: function(e) {
627
+ return this.add(s(e).neg());
628
+ } }, { key: "subtract", value: function(e) {
629
+ return this.sub(e);
630
+ } }, { key: "minus", value: function(e) {
631
+ return this.sub(e);
632
+ } }, { key: "mul", value: function(e) {
633
+ var t = s(e);
634
+ if (this.eq(r2.dInf) && t.eq(r2.dNegInf) || this.eq(r2.dNegInf) && t.eq(r2.dInf)) return new r2(r2.dNegInf);
635
+ if (this.mag == Number.POSITIVE_INFINITY && t.eq(r2.dZero) || this.eq(r2.dZero) && this.mag == Number.POSITIVE_INFINITY) return new r2(r2.dNaN);
636
+ if (this.eq(r2.dNegInf) && t.eq(r2.dNegInf)) return new r2(r2.dInf);
637
+ if (!Number.isFinite(this.layer)) return new r2(this);
638
+ if (!Number.isFinite(t.layer)) return new r2(t);
639
+ if (this.sign === 0 || t.sign === 0) return c(0, 0, 0);
640
+ if (this.layer === t.layer && this.mag === -t.mag) return c(this.sign * t.sign, 0, 1);
641
+ var i, a;
642
+ if (this.layer > t.layer || this.layer == t.layer && Math.abs(this.mag) > Math.abs(t.mag) ? (i = new r2(this), a = new r2(t)) : (i = new r2(t), a = new r2(this)), i.layer === 0 && a.layer === 0) return r2.fromNumber(i.sign * a.sign * i.mag * a.mag);
643
+ if (i.layer >= 3 || i.layer - a.layer >= 2) return m(i.sign * a.sign, i.layer, i.mag);
644
+ if (i.layer === 1 && a.layer === 0) return m(i.sign * a.sign, 1, i.mag + Math.log10(a.mag));
645
+ if (i.layer === 1 && a.layer === 1) return m(i.sign * a.sign, 1, i.mag + a.mag);
646
+ if (i.layer === 2 && a.layer === 1) {
647
+ var l = m(Math.sign(i.mag), i.layer - 1, Math.abs(i.mag)).add(m(Math.sign(a.mag), a.layer - 1, Math.abs(a.mag)));
648
+ return m(i.sign * a.sign, l.layer + 1, l.sign * l.mag);
649
+ }
650
+ if (i.layer === 2 && a.layer === 2) {
651
+ var f = m(Math.sign(i.mag), i.layer - 1, Math.abs(i.mag)).add(m(Math.sign(a.mag), a.layer - 1, Math.abs(a.mag)));
652
+ return m(i.sign * a.sign, f.layer + 1, f.sign * f.mag);
653
+ }
654
+ throw Error("Bad arguments to mul: " + this + ", " + e);
655
+ } }, { key: "multiply", value: function(e) {
656
+ return this.mul(e);
657
+ } }, { key: "times", value: function(e) {
658
+ return this.mul(e);
659
+ } }, { key: "div", value: function(e) {
660
+ var t = s(e);
661
+ return this.mul(t.recip());
662
+ } }, { key: "divide", value: function(e) {
663
+ return this.div(e);
664
+ } }, { key: "divideBy", value: function(e) {
665
+ return this.div(e);
666
+ } }, { key: "dividedBy", value: function(e) {
667
+ return this.div(e);
668
+ } }, { key: "recip", value: function() {
669
+ return this.mag === 0 ? new r2(r2.dNaN) : this.mag === Number.POSITIVE_INFINITY ? c(0, 0, 0) : this.layer === 0 ? m(this.sign, 0, 1 / this.mag) : m(this.sign, this.layer, -this.mag);
670
+ } }, { key: "reciprocal", value: function() {
671
+ return this.recip();
672
+ } }, { key: "reciprocate", value: function() {
673
+ return this.recip();
674
+ } }, { key: "mod", value: function(e) {
675
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, i = s(e), a = i.abs();
676
+ if (this.eq(r2.dZero) || a.eq(r2.dZero)) return c(0, 0, 0);
677
+ if (t) {
678
+ var l = this.abs().mod(a);
679
+ return this.sign == -1 != (i.sign == -1) && (l = i.abs().sub(l)), l.mul(i.sign);
680
+ }
681
+ var f = this.toNumber(), g = a.toNumber();
682
+ return isFinite(f) && isFinite(g) && f != 0 && g != 0 ? new r2(f % g) : this.sub(a).eq(this) ? c(0, 0, 0) : a.sub(this).eq(a) ? new r2(this) : this.sign == -1 ? this.abs().mod(a).neg() : this.sub(this.div(a).floor().mul(a));
683
+ } }, { key: "modulo", value: function(e) {
684
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
685
+ return this.mod(e, t);
686
+ } }, { key: "modular", value: function(e) {
687
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
688
+ return this.mod(e, t);
689
+ } }, { key: "cmp", value: function(e) {
690
+ var t = s(e);
691
+ return this.sign > t.sign ? 1 : this.sign < t.sign ? -1 : this.sign * this.cmpabs(e);
692
+ } }, { key: "cmpabs", value: function(e) {
693
+ var t = s(e), i = this.mag > 0 ? this.layer : -this.layer, a = t.mag > 0 ? t.layer : -t.layer;
694
+ return i > a ? 1 : i < a ? -1 : this.mag > t.mag ? 1 : this.mag < t.mag ? -1 : 0;
695
+ } }, { key: "compare", value: function(e) {
696
+ return this.cmp(e);
697
+ } }, { key: "isNan", value: function() {
698
+ return isNaN(this.sign) || isNaN(this.layer) || isNaN(this.mag);
699
+ } }, { key: "isFinite", value: (function(n) {
700
+ function e() {
701
+ return n.apply(this, arguments);
702
+ }
703
+ return e.toString = function() {
704
+ return n.toString();
705
+ }, e;
706
+ })(function() {
707
+ return isFinite(this.sign) && isFinite(this.layer) && isFinite(this.mag);
708
+ }) }, { key: "eq", value: function(e) {
709
+ var t = s(e);
710
+ return this.sign === t.sign && this.layer === t.layer && this.mag === t.mag;
711
+ } }, { key: "equals", value: function(e) {
712
+ return this.eq(e);
713
+ } }, { key: "neq", value: function(e) {
714
+ return !this.eq(e);
715
+ } }, { key: "notEquals", value: function(e) {
716
+ return this.neq(e);
717
+ } }, { key: "lt", value: function(e) {
718
+ return this.cmp(e) === -1;
719
+ } }, { key: "lte", value: function(e) {
720
+ return !this.gt(e);
721
+ } }, { key: "gt", value: function(e) {
722
+ return this.cmp(e) === 1;
723
+ } }, { key: "gte", value: function(e) {
724
+ return !this.lt(e);
725
+ } }, { key: "max", value: function(e) {
726
+ var t = s(e);
727
+ return this.lt(t) ? new r2(t) : new r2(this);
728
+ } }, { key: "min", value: function(e) {
729
+ var t = s(e);
730
+ return this.gt(t) ? new r2(t) : new r2(this);
731
+ } }, { key: "maxabs", value: function(e) {
732
+ var t = s(e);
733
+ return this.cmpabs(t) < 0 ? new r2(t) : new r2(this);
734
+ } }, { key: "minabs", value: function(e) {
735
+ var t = s(e);
736
+ return this.cmpabs(t) > 0 ? new r2(t) : new r2(this);
737
+ } }, { key: "clamp", value: function(e, t) {
738
+ return this.max(e).min(t);
739
+ } }, { key: "clampMin", value: function(e) {
740
+ return this.max(e);
741
+ } }, { key: "clampMax", value: function(e) {
742
+ return this.min(e);
743
+ } }, { key: "cmp_tolerance", value: function(e, t) {
744
+ var i = s(e);
745
+ return this.eq_tolerance(i, t) ? 0 : this.cmp(i);
746
+ } }, { key: "compare_tolerance", value: function(e, t) {
747
+ return this.cmp_tolerance(e, t);
748
+ } }, { key: "eq_tolerance", value: function(e, t) {
749
+ var i = s(e);
750
+ if (t == null && (t = 1e-7), this.sign !== i.sign || Math.abs(this.layer - i.layer) > 1) return false;
751
+ var a = this.mag, l = i.mag;
752
+ return this.layer > i.layer && (l = ie(l)), this.layer < i.layer && (a = ie(a)), Math.abs(a - l) <= t * Math.max(Math.abs(a), Math.abs(l));
753
+ } }, { key: "equals_tolerance", value: function(e, t) {
754
+ return this.eq_tolerance(e, t);
755
+ } }, { key: "neq_tolerance", value: function(e, t) {
756
+ return !this.eq_tolerance(e, t);
757
+ } }, { key: "notEquals_tolerance", value: function(e, t) {
758
+ return this.neq_tolerance(e, t);
759
+ } }, { key: "lt_tolerance", value: function(e, t) {
760
+ var i = s(e);
761
+ return !this.eq_tolerance(i, t) && this.lt(i);
762
+ } }, { key: "lte_tolerance", value: function(e, t) {
763
+ var i = s(e);
764
+ return this.eq_tolerance(i, t) || this.lt(i);
765
+ } }, { key: "gt_tolerance", value: function(e, t) {
766
+ var i = s(e);
767
+ return !this.eq_tolerance(i, t) && this.gt(i);
768
+ } }, { key: "gte_tolerance", value: function(e, t) {
769
+ var i = s(e);
770
+ return this.eq_tolerance(i, t) || this.gt(i);
771
+ } }, { key: "pLog10", value: function() {
772
+ return this.lt(r2.dZero) ? c(0, 0, 0) : this.log10();
773
+ } }, { key: "absLog10", value: function() {
774
+ return this.sign === 0 ? new r2(r2.dNaN) : this.layer > 0 ? m(Math.sign(this.mag), this.layer - 1, Math.abs(this.mag)) : m(1, 0, Math.log10(this.mag));
775
+ } }, { key: "log10", value: function() {
776
+ return this.sign <= 0 ? new r2(r2.dNaN) : this.layer > 0 ? m(Math.sign(this.mag), this.layer - 1, Math.abs(this.mag)) : m(this.sign, 0, Math.log10(this.mag));
777
+ } }, { key: "log", value: function(e) {
778
+ return e = s(e), this.sign <= 0 ? new r2(r2.dNaN) : e.sign <= 0 ? new r2(r2.dNaN) : e.sign === 1 && e.layer === 0 && e.mag === 1 ? new r2(r2.dNaN) : this.layer === 0 && e.layer === 0 ? m(this.sign, 0, Math.log(this.mag) / Math.log(e.mag)) : r2.div(this.log10(), e.log10());
779
+ } }, { key: "log2", value: function() {
780
+ return this.sign <= 0 ? new r2(r2.dNaN) : this.layer === 0 ? m(this.sign, 0, Math.log2(this.mag)) : this.layer === 1 ? m(Math.sign(this.mag), 0, Math.abs(this.mag) * 3.321928094887362) : this.layer === 2 ? m(Math.sign(this.mag), 1, Math.abs(this.mag) + 0.5213902276543247) : m(Math.sign(this.mag), this.layer - 1, Math.abs(this.mag));
781
+ } }, { key: "ln", value: function() {
782
+ return this.sign <= 0 ? new r2(r2.dNaN) : this.layer === 0 ? m(this.sign, 0, Math.log(this.mag)) : this.layer === 1 ? m(Math.sign(this.mag), 0, Math.abs(this.mag) * 2.302585092994046) : this.layer === 2 ? m(Math.sign(this.mag), 1, Math.abs(this.mag) + 0.36221568869946325) : m(Math.sign(this.mag), this.layer - 1, Math.abs(this.mag));
783
+ } }, { key: "logarithm", value: function(e) {
784
+ return this.log(e);
785
+ } }, { key: "pow", value: function(e) {
786
+ var t = s(e), i = new r2(this), a = new r2(t);
787
+ if (i.sign === 0) return a.eq(0) ? c(1, 0, 1) : i;
788
+ if (i.sign === 1 && i.layer === 0 && i.mag === 1) return i;
789
+ if (a.sign === 0) return c(1, 0, 1);
790
+ if (a.sign === 1 && a.layer === 0 && a.mag === 1) return i;
791
+ var l = i.absLog10().mul(a).pow10();
792
+ return this.sign === -1 ? Math.abs(a.toNumber() % 2) % 2 === 1 ? l.neg() : Math.abs(a.toNumber() % 2) % 2 === 0 ? l : new r2(r2.dNaN) : l;
793
+ } }, { key: "pow10", value: function() {
794
+ if (this.eq(r2.dInf)) return new r2(r2.dInf);
795
+ if (this.eq(r2.dNegInf)) return c(0, 0, 0);
796
+ if (!Number.isFinite(this.layer) || !Number.isFinite(this.mag)) return new r2(r2.dNaN);
797
+ var e = new r2(this);
798
+ if (e.layer === 0) {
799
+ var t = Math.pow(10, e.sign * e.mag);
800
+ if (Number.isFinite(t) && Math.abs(t) >= 0.1) return m(1, 0, t);
801
+ if (e.sign === 0) return c(1, 0, 1);
802
+ e = c(e.sign, e.layer + 1, Math.log10(e.mag));
803
+ }
804
+ return e.sign > 0 && e.mag >= 0 ? m(e.sign, e.layer + 1, e.mag) : e.sign < 0 && e.mag >= 0 ? m(-e.sign, e.layer + 1, -e.mag) : c(1, 0, 1);
805
+ } }, { key: "pow_base", value: function(e) {
806
+ return s(e).pow(this);
807
+ } }, { key: "root", value: function(e) {
808
+ var t = s(e);
809
+ return this.lt(0) && t.mod(2, true).eq(1) ? this.neg().root(t).neg() : this.pow(t.recip());
810
+ } }, { key: "factorial", value: function() {
811
+ return this.mag < 0 ? this.add(1).gamma() : this.layer === 0 ? this.add(1).gamma() : this.layer === 1 ? r2.exp(r2.mul(this, r2.ln(this).sub(1))) : r2.exp(this);
812
+ } }, { key: "gamma", value: function() {
813
+ if (this.mag < 0) return this.recip();
814
+ if (this.layer === 0) {
815
+ if (this.lt(c(1, 0, 24))) return r2.fromNumber(ke(this.sign * this.mag));
816
+ var e = this.mag - 1, t = 0.9189385332046727;
817
+ t = t + (e + 0.5) * Math.log(e), t = t - e;
818
+ var i = e * e, a = e, l = 12 * a, f = 1 / l, g = t + f;
819
+ if (g === t || (t = g, a = a * i, l = 360 * a, f = 1 / l, g = t - f, g === t)) return r2.exp(t);
820
+ t = g, a = a * i, l = 1260 * a;
821
+ var h = 1 / l;
822
+ return t = t + h, a = a * i, l = 1680 * a, h = 1 / l, t = t - h, r2.exp(t);
823
+ } else return this.layer === 1 ? r2.exp(r2.mul(this, r2.ln(this).sub(1))) : r2.exp(this);
824
+ } }, { key: "lngamma", value: function() {
825
+ return this.gamma().ln();
826
+ } }, { key: "exp", value: function() {
827
+ return this.mag < 0 ? c(1, 0, 1) : this.layer === 0 && this.mag <= 709.7 ? r2.fromNumber(Math.exp(this.sign * this.mag)) : this.layer === 0 ? m(1, 1, this.sign * Math.log10(Math.E) * this.mag) : this.layer === 1 ? m(1, 2, this.sign * (Math.log10(0.4342944819032518) + this.mag)) : m(1, this.layer + 1, this.sign * this.mag);
828
+ } }, { key: "sqr", value: function() {
829
+ return this.pow(2);
830
+ } }, { key: "sqrt", value: function() {
831
+ if (this.layer === 0) return r2.fromNumber(Math.sqrt(this.sign * this.mag));
832
+ if (this.layer === 1) return m(1, 2, Math.log10(this.mag) - 0.3010299956639812);
833
+ var e = r2.div(c(this.sign, this.layer - 1, this.mag), c(1, 0, 2));
834
+ return e.layer += 1, e.normalize(), e;
835
+ } }, { key: "cube", value: function() {
836
+ return this.pow(3);
837
+ } }, { key: "cbrt", value: function() {
838
+ return this.lt(0) ? this.neg().pow(1 / 3).neg() : this.pow(1 / 3);
839
+ } }, { key: "tetrate", value: function() {
840
+ var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 2, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : c(1, 0, 1), i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
841
+ if (e === 1) return r2.pow(this, t);
842
+ if (e === 0) return new r2(t);
843
+ if (this.eq(r2.dOne)) return c(1, 0, 1);
844
+ if (this.eq(-1)) return r2.pow(this, t);
845
+ if (e === Number.POSITIVE_INFINITY) {
846
+ var a = this.toNumber();
847
+ if (a <= 1.444667861009766 && a >= 0.06598803584531254) {
848
+ var l = r2.ln(this).neg(), f = l.lambertw().div(l);
849
+ if (a < 1) return f;
850
+ var g = l.lambertw(false).div(l);
851
+ return a > 1.444667861009099 && (f = g = r2.fromNumber(Math.E)), t = s(t), t.eq(g) ? g : t.lt(g) ? f : new r2(r2.dInf);
852
+ } else return a > 1.444667861009766 ? new r2(r2.dInf) : new r2(r2.dNaN);
853
+ }
854
+ if (this.eq(r2.dZero)) {
855
+ var h = Math.abs((e + 1) % 2);
856
+ return h > 1 && (h = 2 - h), r2.fromNumber(h);
857
+ }
858
+ if (e < 0) return r2.iteratedlog(t, this, -e, i);
859
+ t = new r2(t);
860
+ var v = e;
861
+ e = Math.trunc(e);
862
+ var u = v - e;
863
+ if (this.gt(r2.dZero) && (this.lt(1) || this.lte(1.444667861009766) && t.lte(r2.ln(this).neg().lambertw(false).div(r2.ln(this).neg()))) && (v > 1e4 || !i)) {
864
+ var M = Math.min(1e4, e);
865
+ t.eq(r2.dOne) ? t = this.pow(u) : this.lt(1) ? t = t.pow(1 - u).mul(this.pow(t).pow(u)) : t = t.layeradd(u, this);
866
+ for (var x = 0; x < M; ++x) {
867
+ var w = t;
868
+ if (t = this.pow(t), w.eq(t)) return t;
869
+ }
870
+ return v > 1e4 && Math.ceil(v) % 2 == 1 ? this.pow(t) : t;
871
+ }
872
+ u !== 0 && (t.eq(r2.dOne) ? this.gt(10) || i ? t = this.pow(u) : (t = r2.fromNumber(r2.tetrate_critical(this.toNumber(), u)), this.lt(2) && (t = t.sub(1).mul(this.minus(1)).plus(1))) : this.eq(10) ? t = t.layeradd10(u, i) : this.lt(1) ? t = t.pow(1 - u).mul(this.pow(t).pow(u)) : t = t.layeradd(u, this, i));
873
+ for (var o = 0; o < e; ++o) {
874
+ if (t = this.pow(t), !isFinite(t.layer) || !isFinite(t.mag)) return t.normalize();
875
+ if (t.layer - this.layer > 3) return c(t.sign, t.layer + (e - o - 1), t.mag);
876
+ if (o > 1e4) return t;
877
+ }
878
+ return t;
879
+ } }, { key: "iteratedexp", value: function() {
880
+ var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 2, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : c(1, 0, 1), i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
881
+ return this.tetrate(e, t, i);
882
+ } }, { key: "iteratedlog", value: function() {
883
+ var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 10, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
884
+ if (t < 0) return r2.tetrate(e, -t, this, i);
885
+ e = s(e);
886
+ var a = r2.fromDecimal(this), l = t;
887
+ t = Math.trunc(t);
888
+ var f = l - t;
889
+ if (a.layer - e.layer > 3) {
890
+ var g = Math.min(t, a.layer - e.layer - 3);
891
+ t -= g, a.layer -= g;
892
+ }
893
+ for (var h = 0; h < t; ++h) {
894
+ if (a = a.log(e), !isFinite(a.layer) || !isFinite(a.mag)) return a.normalize();
895
+ if (h > 1e4) return a;
896
+ }
897
+ return f > 0 && f < 1 && (e.eq(10) ? a = a.layeradd10(-f, i) : a = a.layeradd(-f, e, i)), a;
898
+ } }, { key: "slog", value: function() {
899
+ for (var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 10, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 100, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false, a = 1e-3, l = false, f = false, g = this.slog_internal(e, i).toNumber(), h = 1; h < t; ++h) {
900
+ var v = new r2(e).tetrate(g, r2.dOne, i), u = v.gt(this);
901
+ if (h > 1 && f != u && (l = true), f = u, l ? a /= 2 : a *= 2, a = Math.abs(a) * (u ? -1 : 1), g += a, a === 0) break;
902
+ }
903
+ return r2.fromNumber(g);
904
+ } }, { key: "slog_internal", value: function() {
905
+ var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 10, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
906
+ if (e = s(e), e.lte(r2.dZero)) return new r2(r2.dNaN);
907
+ if (e.eq(r2.dOne)) return new r2(r2.dNaN);
908
+ if (e.lt(r2.dOne)) return this.eq(r2.dOne) ? c(0, 0, 0) : this.eq(r2.dZero) ? c(-1, 0, 1) : new r2(r2.dNaN);
909
+ if (this.mag < 0 || this.eq(r2.dZero)) return c(-1, 0, 1);
910
+ if (e.lt(1.444667861009766)) {
911
+ var i = r2.ln(e).neg(), a = i.lambertw().div(i);
912
+ if (this.eq(a)) return new r2(r2.dInf);
913
+ if (this.gt(a)) return new r2(r2.dNaN);
914
+ }
915
+ var l = 0, f = r2.fromDecimal(this);
916
+ if (f.layer - e.layer > 3) {
917
+ var g = f.layer - e.layer - 3;
918
+ l += g, f.layer -= g;
919
+ }
920
+ for (var h = 0; h < 100; ++h) if (f.lt(r2.dZero)) f = r2.pow(e, f), l -= 1;
921
+ else {
922
+ if (f.lte(r2.dOne)) return t ? r2.fromNumber(l + f.toNumber() - 1) : r2.fromNumber(l + r2.slog_critical(e.toNumber(), f.toNumber()));
923
+ l += 1, f = r2.log(f, e);
924
+ }
925
+ return r2.fromNumber(l);
926
+ } }, { key: "layeradd10", value: function(e) {
927
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
928
+ e = r2.fromValue_noAlloc(e).toNumber();
929
+ var i = r2.fromDecimal(this);
930
+ if (e >= 1) {
931
+ i.mag < 0 && i.layer > 0 ? (i.sign = 0, i.mag = 0, i.layer = 0) : i.sign === -1 && i.layer == 0 && (i.sign = 1, i.mag = -i.mag);
932
+ var a = Math.trunc(e);
933
+ e -= a, i.layer += a;
934
+ }
935
+ if (e <= -1) {
936
+ var l = Math.trunc(e);
937
+ if (e -= l, i.layer += l, i.layer < 0) for (var f = 0; f < 100; ++f) {
938
+ if (i.layer++, i.mag = Math.log10(i.mag), !isFinite(i.mag)) return i.sign === 0 && (i.sign = 1), i.layer < 0 && (i.layer = 0), i.normalize();
939
+ if (i.layer >= 0) break;
940
+ }
941
+ }
942
+ for (; i.layer < 0; ) i.layer++, i.mag = Math.log10(i.mag);
943
+ return i.sign === 0 && (i.sign = 1, i.mag === 0 && i.layer >= 1 && (i.layer -= 1, i.mag = 1)), i.normalize(), e !== 0 ? i.layeradd(e, 10, t) : i;
944
+ } }, { key: "layeradd", value: function(e, t) {
945
+ var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false, a = s(t);
946
+ if (a.gt(1) && a.lte(1.444667861009766)) {
947
+ var l = r2.excess_slog(this, t, i), f = l[0].toNumber(), g = l[1], h = f + e, v = r2.ln(t).neg(), u = v.lambertw().div(v), M = v.lambertw(false).div(v), x = r2.dOne;
948
+ g == 1 ? x = u.mul(M).sqrt() : g == 2 && (x = M.mul(2));
949
+ var w = a.pow(x), o = Math.floor(h), F = h - o, A = x.pow(1 - F).mul(w.pow(F));
950
+ return r2.tetrate(a, o, A, i);
951
+ }
952
+ var d = this.slog(t, 100, i).toNumber(), S = d + e;
953
+ return S >= 0 ? r2.tetrate(t, S, r2.dOne, i) : Number.isFinite(S) ? S >= -1 ? r2.log(r2.tetrate(t, S + 1, r2.dOne, i), t) : r2.log(r2.log(r2.tetrate(t, S + 2, r2.dOne, i), t), t) : new r2(r2.dNaN);
954
+ } }, { key: "lambertw", value: function() {
955
+ var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
956
+ return this.lt(-0.3678794411710499) ? new r2(r2.dNaN) : e ? this.abs().lt("1e-300") ? new r2(this) : this.mag < 0 ? r2.fromNumber(ae(this.toNumber())) : this.layer === 0 ? r2.fromNumber(ae(this.sign * this.mag)) : this.lt("eee15") ? he(this) : this.ln() : this.sign === 1 ? new r2(r2.dNaN) : this.layer === 0 ? r2.fromNumber(ae(this.sign * this.mag, 1e-10, false)) : this.layer == 1 ? he(this, 1e-10, false) : this.neg().recip().lambertw().neg();
957
+ } }, { key: "ssqrt", value: function() {
958
+ return this.linear_sroot(2);
959
+ } }, { key: "linear_sroot", value: function(e) {
960
+ if (e == 1) return this;
961
+ if (this.eq(r2.dInf)) return new r2(r2.dInf);
962
+ if (!this.isFinite()) return new r2(r2.dNaN);
963
+ if (e > 0 && e < 1) return this.root(e);
964
+ if (e > -2 && e < -1) return r2.fromNumber(e).add(2).pow(this.recip());
965
+ if (e <= 0) return new r2(r2.dNaN);
966
+ if (e == Number.POSITIVE_INFINITY) {
967
+ var t = this.toNumber();
968
+ return t < Math.E && t > Me ? this.pow(this.recip()) : new r2(r2.dNaN);
969
+ }
970
+ if (this.eq(1)) return c(1, 0, 1);
971
+ if (this.lt(0)) return new r2(r2.dNaN);
972
+ if (this.lte("1ee-16")) return e % 2 == 1 ? new r2(this) : new r2(r2.dNaN);
973
+ if (this.gt(1)) {
974
+ var i = r2.dTen;
975
+ this.gte(r2.tetrate(10, e, 1, true)) && (i = this.iteratedlog(10, e - 1, true)), e <= 1 && (i = this.root(e));
976
+ for (var a = r2.dZero, l = i.layer, f = i.iteratedlog(10, l, true), g = f, h = f.div(2), v = true; v; ) h = a.add(f).div(2), r2.iteratedexp(10, l, h, true).tetrate(e, 1, true).gt(this) ? f = h : a = h, h.eq(g) ? v = false : g = h;
977
+ return r2.iteratedexp(10, l, h, true);
978
+ } else {
979
+ for (var u = 1, M = m(1, 10, 1), x = m(1, 10, 1), w = m(1, 10, 1), o = m(1, 1, -16), F = r2.dZero, A = m(1, 10, 1), d = o.pow10().recip(), S = r2.dZero, p = d, q = d, I = Math.ceil(e) % 2 == 0, N = 0, y = m(1, 10, 1), V = false, C = r2.dZero, D = false; u < 4; ) {
980
+ if (u == 2) {
981
+ if (I) break;
982
+ w = m(1, 10, 1), o = M, u = 3, A = m(1, 10, 1), y = m(1, 10, 1);
983
+ }
984
+ for (V = false; o.neq(w); ) {
985
+ if (C = o, o.pow10().recip().tetrate(e, 1, true).eq(1) && o.pow10().recip().lt(0.4)) d = o.pow10().recip(), p = o.pow10().recip(), q = o.pow10().recip(), S = r2.dZero, N = -1, u == 3 && (y = o);
986
+ else if (o.pow10().recip().tetrate(e, 1, true).eq(o.pow10().recip()) && !I && o.pow10().recip().lt(0.4)) d = o.pow10().recip(), p = o.pow10().recip(), q = o.pow10().recip(), S = r2.dZero, N = 0;
987
+ else if (o.pow10().recip().tetrate(e, 1, true).eq(o.pow10().recip().mul(2).tetrate(e, 1, true))) d = o.pow10().recip(), p = r2.dZero, q = d.mul(2), S = d, I ? N = -1 : N = 0;
988
+ else {
989
+ for (F = o.mul(12e-17), d = o.pow10().recip(), p = o.add(F).pow10().recip(), S = d.sub(p), q = d.add(S); p.tetrate(e, 1, true).eq(d.tetrate(e, 1, true)) || q.tetrate(e, 1, true).eq(d.tetrate(e, 1, true)) || p.gte(d) || q.lte(d); ) F = F.mul(2), p = o.add(F).pow10().recip(), S = d.sub(p), q = d.add(S);
990
+ if ((u == 1 && q.tetrate(e, 1, true).gt(d.tetrate(e, 1, true)) && p.tetrate(e, 1, true).gt(d.tetrate(e, 1, true)) || u == 3 && q.tetrate(e, 1, true).lt(d.tetrate(e, 1, true)) && p.tetrate(e, 1, true).lt(d.tetrate(e, 1, true))) && (y = o), q.tetrate(e, 1, true).lt(d.tetrate(e, 1, true))) N = -1;
991
+ else if (I) N = 1;
992
+ else if (u == 3 && o.gt_tolerance(M, 1e-8)) N = 0;
993
+ else {
994
+ for (; p.tetrate(e, 1, true).eq_tolerance(d.tetrate(e, 1, true), 1e-8) || q.tetrate(e, 1, true).eq_tolerance(d.tetrate(e, 1, true), 1e-8) || p.gte(d) || q.lte(d); ) F = F.mul(2), p = o.add(F).pow10().recip(), S = d.sub(p), q = d.add(S);
995
+ q.tetrate(e, 1, true).sub(d.tetrate(e, 1, true)).lt(d.tetrate(e, 1, true).sub(p.tetrate(e, 1, true))) ? N = 0 : N = 1;
996
+ }
997
+ }
998
+ if (N == -1 && (D = true), u == 1 && N == 1 || u == 3 && N != 0) if (w.eq(m(1, 10, 1))) o = o.mul(2);
999
+ else {
1000
+ var Y = false;
1001
+ if (V && (N == 1 && u == 1 || N == -1 && u == 3) && (Y = true), o = o.add(w).div(2), Y) break;
1002
+ }
1003
+ else if (w.eq(m(1, 10, 1))) w = o, o = o.div(2);
1004
+ else {
1005
+ var L = false;
1006
+ if (V && (N == 1 && u == 1 || N == -1 && u == 3) && (L = true), w = w.sub(A), o = o.sub(A), L) break;
1007
+ }
1008
+ if (w.sub(o).div(2).abs().gt(A.mul(1.5)) && (V = true), A = w.sub(o).div(2).abs(), o.gt("1e18") || o.eq(C)) break;
1009
+ }
1010
+ if (o.gt("1e18") || !D || y == m(1, 10, 1)) break;
1011
+ u == 1 ? M = y : u == 3 && (x = y), u++;
1012
+ }
1013
+ w = M, o = m(1, 1, -18);
1014
+ for (var G = o, E = r2.dZero, X = true; X; ) if (w.eq(m(1, 10, 1)) ? E = o.mul(2) : E = w.add(o).div(2), r2.pow(10, E).recip().tetrate(e, 1, true).gt(this) ? o = E : w = E, E.eq(G) ? X = false : G = E, o.gt("1e18")) return new r2(r2.dNaN);
1015
+ if (E.eq_tolerance(M, 1e-15)) {
1016
+ if (x.eq(m(1, 10, 1))) return new r2(r2.dNaN);
1017
+ for (w = m(1, 10, 1), o = x, G = o, E = r2.dZero, X = true; X; ) if (w.eq(m(1, 10, 1)) ? E = o.mul(2) : E = w.add(o).div(2), r2.pow(10, E).recip().tetrate(e, 1, true).gt(this) ? o = E : w = E, E.eq(G) ? X = false : G = E, o.gt("1e18")) return new r2(r2.dNaN);
1018
+ return E.pow10().recip();
1019
+ } else return E.pow10().recip();
1020
+ }
1021
+ } }, { key: "pentate", value: function() {
1022
+ var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 2, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : c(1, 0, 1), i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1023
+ t = new r2(t);
1024
+ var a = e;
1025
+ e = Math.floor(e);
1026
+ var l = a - e, f = r2.dZero, g = r2.dZero;
1027
+ if (l !== 0) if (t.eq(r2.dOne)) ++e, t = r2.fromNumber(l);
1028
+ else return this.pentate(t.penta_log(this, void 0, i).plus(a).toNumber(), 1, i);
1029
+ if (e > 0) for (var h = 0; h < e; ) {
1030
+ if (g = f, f = t, t = this.tetrate(t.toNumber(), r2.dOne, i), ++h, this.gt(0) && this.lte(1) && t.gt(0) && t.lte(1)) return this.tetrate(e - h, t, i);
1031
+ if (t.eq(f) || t.eq(g) && h % 2 == e % 2 || !isFinite(t.layer) || !isFinite(t.mag)) return t.normalize();
1032
+ if (h > 1e4) return t;
1033
+ }
1034
+ else for (var v = 0; v < -e; ++v) {
1035
+ if (f = t, t = t.slog(this, void 0, i), t.eq(f) || !isFinite(t.layer) || !isFinite(t.mag)) return t.normalize();
1036
+ if (v > 100) return t;
1037
+ }
1038
+ return t;
1039
+ } }, { key: "penta_log", value: function() {
1040
+ var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 10, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 100, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1041
+ if (e = new r2(e), e.lte(1)) return new r2(r2.dNaN);
1042
+ if (this.eq(1)) return c(0, 0, 0);
1043
+ if (this.eq(r2.dInf)) return new r2(r2.dInf);
1044
+ var a = new r2(1), l = 0, f = 1;
1045
+ if (this.lt(-1)) {
1046
+ if (this.lte(-2)) return new r2(r2.dNaN);
1047
+ var g = e.tetrate(this.toNumber(), 1, i);
1048
+ if (this.eq(g)) return new r2(r2.dNegInf);
1049
+ if (this.gt(g)) return new r2(r2.dNaN);
1050
+ }
1051
+ if (this.gt(1)) {
1052
+ for (; a.lt(this); ) if (l++, a = r2.tetrate(e, a.toNumber(), 1, i), l > 1e3) return new r2(r2.dNaN);
1053
+ } else for (; a.gt(this); ) if (l--, a = r2.slog(a, e, i), l > 100) return new r2(r2.dNaN);
1054
+ for (var h = 1; h < t; ++h) {
1055
+ var v = e.pentate(l, r2.dOne, i);
1056
+ if (v.eq(this)) break;
1057
+ var u = v.gt(this);
1058
+ if (f = Math.abs(f) * (u ? -1 : 1), l += f, f /= 2, f === 0) break;
1059
+ }
1060
+ return r2.fromNumber(l);
1061
+ } }, { key: "linear_penta_root", value: function(e) {
1062
+ return e == 1 ? this : e < 0 ? new r2(r2.dNaN) : this.eq(r2.dInf) ? new r2(r2.dInf) : this.isFinite() ? e > 0 && e < 1 ? this.root(e) : this.eq(1) ? c(1, 0, 1) : this.lt(0) ? new r2(r2.dNaN) : this.lt(1) ? this.linear_sroot(e) : r2.increasingInverse(function(t) {
1063
+ return r2.pentate(t, e, 1, true);
1064
+ })(this) : new r2(r2.dNaN);
1065
+ } }, { key: "sin", value: function() {
1066
+ return this.mag < 0 ? new r2(this) : this.layer === 0 ? r2.fromNumber(Math.sin(this.sign * this.mag)) : c(0, 0, 0);
1067
+ } }, { key: "cos", value: function() {
1068
+ return this.mag < 0 ? c(1, 0, 1) : this.layer === 0 ? r2.fromNumber(Math.cos(this.sign * this.mag)) : c(0, 0, 0);
1069
+ } }, { key: "tan", value: function() {
1070
+ return this.mag < 0 ? new r2(this) : this.layer === 0 ? r2.fromNumber(Math.tan(this.sign * this.mag)) : c(0, 0, 0);
1071
+ } }, { key: "asin", value: function() {
1072
+ return this.mag < 0 ? new r2(this) : this.layer === 0 ? r2.fromNumber(Math.asin(this.sign * this.mag)) : new r2(r2.dNaN);
1073
+ } }, { key: "acos", value: function() {
1074
+ return this.mag < 0 ? r2.fromNumber(Math.acos(this.toNumber())) : this.layer === 0 ? r2.fromNumber(Math.acos(this.sign * this.mag)) : new r2(r2.dNaN);
1075
+ } }, { key: "atan", value: function() {
1076
+ return this.mag < 0 ? new r2(this) : this.layer === 0 ? r2.fromNumber(Math.atan(this.sign * this.mag)) : r2.fromNumber(Math.atan(this.sign * (1 / 0)));
1077
+ } }, { key: "sinh", value: function() {
1078
+ return this.exp().sub(this.negate().exp()).div(2);
1079
+ } }, { key: "cosh", value: function() {
1080
+ return this.exp().add(this.negate().exp()).div(2);
1081
+ } }, { key: "tanh", value: function() {
1082
+ return this.sinh().div(this.cosh());
1083
+ } }, { key: "asinh", value: function() {
1084
+ return r2.ln(this.add(this.sqr().add(1).sqrt()));
1085
+ } }, { key: "acosh", value: function() {
1086
+ return r2.ln(this.add(this.sqr().sub(1).sqrt()));
1087
+ } }, { key: "atanh", value: function() {
1088
+ return this.abs().gte(1) ? new r2(r2.dNaN) : r2.ln(this.add(1).div(r2.fromNumber(1).sub(this))).div(2);
1089
+ } }, { key: "ascensionPenalty", value: function(e) {
1090
+ return e === 0 ? new r2(this) : this.root(r2.pow(10, e));
1091
+ } }, { key: "egg", value: function() {
1092
+ return this.add(9);
1093
+ } }, { key: "lessThanOrEqualTo", value: function(e) {
1094
+ return this.cmp(e) < 1;
1095
+ } }, { key: "lessThan", value: function(e) {
1096
+ return this.cmp(e) < 0;
1097
+ } }, { key: "greaterThanOrEqualTo", value: function(e) {
1098
+ return this.cmp(e) > -1;
1099
+ } }, { key: "greaterThan", value: function(e) {
1100
+ return this.cmp(e) > 0;
1101
+ } }], [{ key: "fromComponents", value: function(e, t, i) {
1102
+ return new r2().fromComponents(e, t, i);
1103
+ } }, { key: "fromComponents_noNormalize", value: function(e, t, i) {
1104
+ return new r2().fromComponents_noNormalize(e, t, i);
1105
+ } }, { key: "fromMantissaExponent", value: function(e, t) {
1106
+ return new r2().fromMantissaExponent(e, t);
1107
+ } }, { key: "fromMantissaExponent_noNormalize", value: function(e, t) {
1108
+ return new r2().fromMantissaExponent_noNormalize(e, t);
1109
+ } }, { key: "fromDecimal", value: function(e) {
1110
+ return new r2().fromDecimal(e);
1111
+ } }, { key: "fromNumber", value: function(e) {
1112
+ return new r2().fromNumber(e);
1113
+ } }, { key: "fromString", value: function(e) {
1114
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1115
+ return new r2().fromString(e, t);
1116
+ } }, { key: "fromValue", value: function(e) {
1117
+ return new r2().fromValue(e);
1118
+ } }, { key: "fromValue_noAlloc", value: function(e) {
1119
+ if (e instanceof r2) return e;
1120
+ if (typeof e == "string") {
1121
+ var t = r2.fromStringCache.get(e);
1122
+ return t !== void 0 ? t : r2.fromString(e);
1123
+ } else return typeof e == "number" ? r2.fromNumber(e) : c(0, 0, 0);
1124
+ } }, { key: "abs", value: function(e) {
1125
+ return s(e).abs();
1126
+ } }, { key: "neg", value: function(e) {
1127
+ return s(e).neg();
1128
+ } }, { key: "negate", value: function(e) {
1129
+ return s(e).neg();
1130
+ } }, { key: "negated", value: function(e) {
1131
+ return s(e).neg();
1132
+ } }, { key: "sign", value: function(e) {
1133
+ return s(e).sign;
1134
+ } }, { key: "sgn", value: function(e) {
1135
+ return s(e).sign;
1136
+ } }, { key: "round", value: function(e) {
1137
+ return s(e).round();
1138
+ } }, { key: "floor", value: function(e) {
1139
+ return s(e).floor();
1140
+ } }, { key: "ceil", value: function(e) {
1141
+ return s(e).ceil();
1142
+ } }, { key: "trunc", value: function(e) {
1143
+ return s(e).trunc();
1144
+ } }, { key: "add", value: function(e, t) {
1145
+ return s(e).add(t);
1146
+ } }, { key: "plus", value: function(e, t) {
1147
+ return s(e).add(t);
1148
+ } }, { key: "sub", value: function(e, t) {
1149
+ return s(e).sub(t);
1150
+ } }, { key: "subtract", value: function(e, t) {
1151
+ return s(e).sub(t);
1152
+ } }, { key: "minus", value: function(e, t) {
1153
+ return s(e).sub(t);
1154
+ } }, { key: "mul", value: function(e, t) {
1155
+ return s(e).mul(t);
1156
+ } }, { key: "multiply", value: function(e, t) {
1157
+ return s(e).mul(t);
1158
+ } }, { key: "times", value: function(e, t) {
1159
+ return s(e).mul(t);
1160
+ } }, { key: "div", value: function(e, t) {
1161
+ return s(e).div(t);
1162
+ } }, { key: "divide", value: function(e, t) {
1163
+ return s(e).div(t);
1164
+ } }, { key: "recip", value: function(e) {
1165
+ return s(e).recip();
1166
+ } }, { key: "reciprocal", value: function(e) {
1167
+ return s(e).recip();
1168
+ } }, { key: "reciprocate", value: function(e) {
1169
+ return s(e).reciprocate();
1170
+ } }, { key: "mod", value: function(e, t) {
1171
+ var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1172
+ return s(e).mod(t, i);
1173
+ } }, { key: "modulo", value: function(e, t) {
1174
+ var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1175
+ return s(e).modulo(t, i);
1176
+ } }, { key: "modular", value: function(e, t) {
1177
+ var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1178
+ return s(e).modular(t, i);
1179
+ } }, { key: "cmp", value: function(e, t) {
1180
+ return s(e).cmp(t);
1181
+ } }, { key: "cmpabs", value: function(e, t) {
1182
+ return s(e).cmpabs(t);
1183
+ } }, { key: "compare", value: function(e, t) {
1184
+ return s(e).cmp(t);
1185
+ } }, { key: "isNaN", value: (function(n) {
1186
+ function e(t) {
1187
+ return n.apply(this, arguments);
1188
+ }
1189
+ return e.toString = function() {
1190
+ return n.toString();
1191
+ }, e;
1192
+ })(function(n) {
1193
+ return n = s(n), isNaN(n.sign) || isNaN(n.layer) || isNaN(n.mag);
1194
+ }) }, { key: "isFinite", value: (function(n) {
1195
+ function e(t) {
1196
+ return n.apply(this, arguments);
1197
+ }
1198
+ return e.toString = function() {
1199
+ return n.toString();
1200
+ }, e;
1201
+ })(function(n) {
1202
+ return n = s(n), isFinite(n.sign) && isFinite(n.layer) && isFinite(n.mag);
1203
+ }) }, { key: "eq", value: function(e, t) {
1204
+ return s(e).eq(t);
1205
+ } }, { key: "equals", value: function(e, t) {
1206
+ return s(e).eq(t);
1207
+ } }, { key: "neq", value: function(e, t) {
1208
+ return s(e).neq(t);
1209
+ } }, { key: "notEquals", value: function(e, t) {
1210
+ return s(e).notEquals(t);
1211
+ } }, { key: "lt", value: function(e, t) {
1212
+ return s(e).lt(t);
1213
+ } }, { key: "lte", value: function(e, t) {
1214
+ return s(e).lte(t);
1215
+ } }, { key: "gt", value: function(e, t) {
1216
+ return s(e).gt(t);
1217
+ } }, { key: "gte", value: function(e, t) {
1218
+ return s(e).gte(t);
1219
+ } }, { key: "max", value: function(e, t) {
1220
+ return s(e).max(t);
1221
+ } }, { key: "min", value: function(e, t) {
1222
+ return s(e).min(t);
1223
+ } }, { key: "minabs", value: function(e, t) {
1224
+ return s(e).minabs(t);
1225
+ } }, { key: "maxabs", value: function(e, t) {
1226
+ return s(e).maxabs(t);
1227
+ } }, { key: "clamp", value: function(e, t, i) {
1228
+ return s(e).clamp(t, i);
1229
+ } }, { key: "clampMin", value: function(e, t) {
1230
+ return s(e).clampMin(t);
1231
+ } }, { key: "clampMax", value: function(e, t) {
1232
+ return s(e).clampMax(t);
1233
+ } }, { key: "cmp_tolerance", value: function(e, t, i) {
1234
+ return s(e).cmp_tolerance(t, i);
1235
+ } }, { key: "compare_tolerance", value: function(e, t, i) {
1236
+ return s(e).cmp_tolerance(t, i);
1237
+ } }, { key: "eq_tolerance", value: function(e, t, i) {
1238
+ return s(e).eq_tolerance(t, i);
1239
+ } }, { key: "equals_tolerance", value: function(e, t, i) {
1240
+ return s(e).eq_tolerance(t, i);
1241
+ } }, { key: "neq_tolerance", value: function(e, t, i) {
1242
+ return s(e).neq_tolerance(t, i);
1243
+ } }, { key: "notEquals_tolerance", value: function(e, t, i) {
1244
+ return s(e).notEquals_tolerance(t, i);
1245
+ } }, { key: "lt_tolerance", value: function(e, t, i) {
1246
+ return s(e).lt_tolerance(t, i);
1247
+ } }, { key: "lte_tolerance", value: function(e, t, i) {
1248
+ return s(e).lte_tolerance(t, i);
1249
+ } }, { key: "gt_tolerance", value: function(e, t, i) {
1250
+ return s(e).gt_tolerance(t, i);
1251
+ } }, { key: "gte_tolerance", value: function(e, t, i) {
1252
+ return s(e).gte_tolerance(t, i);
1253
+ } }, { key: "pLog10", value: function(e) {
1254
+ return s(e).pLog10();
1255
+ } }, { key: "absLog10", value: function(e) {
1256
+ return s(e).absLog10();
1257
+ } }, { key: "log10", value: function(e) {
1258
+ return s(e).log10();
1259
+ } }, { key: "log", value: function(e, t) {
1260
+ return s(e).log(t);
1261
+ } }, { key: "log2", value: function(e) {
1262
+ return s(e).log2();
1263
+ } }, { key: "ln", value: function(e) {
1264
+ return s(e).ln();
1265
+ } }, { key: "logarithm", value: function(e, t) {
1266
+ return s(e).logarithm(t);
1267
+ } }, { key: "pow", value: function(e, t) {
1268
+ return s(e).pow(t);
1269
+ } }, { key: "pow10", value: function(e) {
1270
+ return s(e).pow10();
1271
+ } }, { key: "root", value: function(e, t) {
1272
+ return s(e).root(t);
1273
+ } }, { key: "factorial", value: function(e, t) {
1274
+ return s(e).factorial();
1275
+ } }, { key: "gamma", value: function(e, t) {
1276
+ return s(e).gamma();
1277
+ } }, { key: "lngamma", value: function(e, t) {
1278
+ return s(e).lngamma();
1279
+ } }, { key: "exp", value: function(e) {
1280
+ return s(e).exp();
1281
+ } }, { key: "sqr", value: function(e) {
1282
+ return s(e).sqr();
1283
+ } }, { key: "sqrt", value: function(e) {
1284
+ return s(e).sqrt();
1285
+ } }, { key: "cube", value: function(e) {
1286
+ return s(e).cube();
1287
+ } }, { key: "cbrt", value: function(e) {
1288
+ return s(e).cbrt();
1289
+ } }, { key: "tetrate", value: function(e) {
1290
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : c(1, 0, 1), a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
1291
+ return s(e).tetrate(t, i, a);
1292
+ } }, { key: "iteratedexp", value: function(e) {
1293
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : c(1, 0, 1), a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
1294
+ return s(e).iteratedexp(t, i, a);
1295
+ } }, { key: "iteratedlog", value: function(e) {
1296
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 10, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1, a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
1297
+ return s(e).iteratedlog(t, i, a);
1298
+ } }, { key: "layeradd10", value: function(e, t) {
1299
+ var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1300
+ return s(e).layeradd10(t, i);
1301
+ } }, { key: "layeradd", value: function(e, t) {
1302
+ var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 10, a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
1303
+ return s(e).layeradd(t, i, a);
1304
+ } }, { key: "slog", value: function(e) {
1305
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 10, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1306
+ return s(e).slog(t, 100, i);
1307
+ } }, { key: "lambertw", value: function(e, t) {
1308
+ return s(e).lambertw(t);
1309
+ } }, { key: "ssqrt", value: function(e) {
1310
+ return s(e).ssqrt();
1311
+ } }, { key: "linear_sroot", value: function(e, t) {
1312
+ return s(e).linear_sroot(t);
1313
+ } }, { key: "pentate", value: function(e) {
1314
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : c(1, 0, 1), a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
1315
+ return s(e).pentate(t, i, a);
1316
+ } }, { key: "penta_log", value: function(e) {
1317
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 10, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1318
+ return s(e).penta_log(t, 100, i);
1319
+ } }, { key: "linear_penta_root", value: function(e, t) {
1320
+ return s(e).linear_penta_root(t);
1321
+ } }, { key: "sin", value: function(e) {
1322
+ return s(e).sin();
1323
+ } }, { key: "cos", value: function(e) {
1324
+ return s(e).cos();
1325
+ } }, { key: "tan", value: function(e) {
1326
+ return s(e).tan();
1327
+ } }, { key: "asin", value: function(e) {
1328
+ return s(e).asin();
1329
+ } }, { key: "acos", value: function(e) {
1330
+ return s(e).acos();
1331
+ } }, { key: "atan", value: function(e) {
1332
+ return s(e).atan();
1333
+ } }, { key: "sinh", value: function(e) {
1334
+ return s(e).sinh();
1335
+ } }, { key: "cosh", value: function(e) {
1336
+ return s(e).cosh();
1337
+ } }, { key: "tanh", value: function(e) {
1338
+ return s(e).tanh();
1339
+ } }, { key: "asinh", value: function(e) {
1340
+ return s(e).asinh();
1341
+ } }, { key: "acosh", value: function(e) {
1342
+ return s(e).acosh();
1343
+ } }, { key: "atanh", value: function(e) {
1344
+ return s(e).atanh();
1345
+ } }, { key: "affordGeometricSeries", value: function(e, t, i, a) {
1346
+ return this.affordGeometricSeries_core(s(e), s(t), s(i), a);
1347
+ } }, { key: "sumGeometricSeries", value: function(e, t, i, a) {
1348
+ return this.sumGeometricSeries_core(e, s(t), s(i), a);
1349
+ } }, { key: "affordArithmeticSeries", value: function(e, t, i, a) {
1350
+ return this.affordArithmeticSeries_core(s(e), s(t), s(i), s(a));
1351
+ } }, { key: "sumArithmeticSeries", value: function(e, t, i, a) {
1352
+ return this.sumArithmeticSeries_core(s(e), s(t), s(i), s(a));
1353
+ } }, { key: "efficiencyOfPurchase", value: function(e, t, i) {
1354
+ return this.efficiencyOfPurchase_core(s(e), s(t), s(i));
1355
+ } }, { key: "randomDecimalForTesting", value: function(e) {
1356
+ if (Math.random() * 20 < 1) return c(0, 0, 0);
1357
+ var t = Math.random() > 0.5 ? 1 : -1;
1358
+ if (Math.random() * 20 < 1) return c(t, 0, 1);
1359
+ var i = Math.floor(Math.random() * (e + 1)), a = i === 0 ? Math.random() * 616 - 308 : Math.random() * 16;
1360
+ Math.random() > 0.9 && (a = Math.trunc(a));
1361
+ var l = Math.pow(10, a);
1362
+ return Math.random() > 0.9 && (l = Math.trunc(l)), m(t, i, l);
1363
+ } }, { key: "affordGeometricSeries_core", value: function(e, t, i, a) {
1364
+ var l = t.mul(i.pow(a));
1365
+ return r2.floor(e.div(l).mul(i.sub(1)).add(1).log10().div(i.log10()));
1366
+ } }, { key: "sumGeometricSeries_core", value: function(e, t, i, a) {
1367
+ return t.mul(i.pow(a)).mul(r2.sub(1, i.pow(e))).div(r2.sub(1, i));
1368
+ } }, { key: "affordArithmeticSeries_core", value: function(e, t, i, a) {
1369
+ var l = t.add(a.mul(i)), f = l.sub(i.div(2)), g = f.pow(2);
1370
+ return f.neg().add(g.add(i.mul(e).mul(2)).sqrt()).div(i).floor();
1371
+ } }, { key: "sumArithmeticSeries_core", value: function(e, t, i, a) {
1372
+ var l = t.add(a.mul(i));
1373
+ return e.div(2).mul(l.mul(2).plus(e.sub(1).mul(i)));
1374
+ } }, { key: "efficiencyOfPurchase_core", value: function(e, t, i) {
1375
+ return e.div(t).add(e.div(i));
1376
+ } }, { key: "slog_critical", value: function(e, t) {
1377
+ return e > 10 ? t - 1 : r2.critical_section(e, t, we);
1378
+ } }, { key: "tetrate_critical", value: function(e, t) {
1379
+ return r2.critical_section(e, t, be);
1380
+ } }, { key: "critical_section", value: function(e, t, i) {
1381
+ t *= 10, t < 0 && (t = 0), t > 10 && (t = 10), e < 2 && (e = 2), e > 10 && (e = 10);
1382
+ for (var a = 0, l = 0, f = 0; f < _.length; ++f) if (_[f] == e) {
1383
+ a = i[f][Math.floor(t)], l = i[f][Math.ceil(t)];
1384
+ break;
1385
+ } else if (_[f] < e && _[f + 1] > e) {
1386
+ var g = (e - _[f]) / (_[f + 1] - _[f]);
1387
+ a = i[f][Math.floor(t)] * (1 - g) + i[f + 1][Math.floor(t)] * g, l = i[f][Math.ceil(t)] * (1 - g) + i[f + 1][Math.ceil(t)] * g;
1388
+ break;
1389
+ }
1390
+ var h = t - Math.floor(t);
1391
+ return a <= 0 || l <= 0 ? a * (1 - h) + l * h : Math.pow(e, Math.log(a) / Math.log(e) * (1 - h) + Math.log(l) / Math.log(e) * h);
1392
+ } }, { key: "excess_slog", value: function(e, t) {
1393
+ var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1394
+ e = s(e), t = s(t);
1395
+ var a = t;
1396
+ if (t = t.toNumber(), t == 1 || t <= 0) return [new r2(r2.dNaN), 0];
1397
+ if (t > 1.444667861009766) return [e.slog(t, 100, i), 0];
1398
+ var l = r2.ln(t).neg(), f = l.lambertw().div(l), g = r2.dInf;
1399
+ if (t > 1 && (g = l.lambertw(false).div(l)), t > 1.444667861009099 && (f = g = r2.fromNumber(Math.E)), e.lt(f)) return [e.slog(t, 100, i), 0];
1400
+ if (e.eq(f)) return [new r2(r2.dInf), 0];
1401
+ if (e.eq(g)) return [new r2(r2.dNegInf), 2];
1402
+ if (e.gt(g)) {
1403
+ var h = g.mul(2), v = a.pow(h), u = 0;
1404
+ if (e.gte(h) && e.lt(v)) u = 0;
1405
+ else if (e.gte(v)) {
1406
+ var M = v;
1407
+ for (u = 1; M.lt(e); ) if (M = a.pow(M), u = u + 1, M.layer > 3) {
1408
+ var x = Math.floor(e.layer - M.layer + 1);
1409
+ M = a.iteratedexp(x, M, i), u = u + x;
1410
+ }
1411
+ M.gt(e) && (M = M.log(t), u = u - 1);
1412
+ } else if (e.lt(h)) {
1413
+ var w = h;
1414
+ for (u = 0; w.gt(e); ) w = w.log(t), u = u - 1;
1415
+ }
1416
+ for (var o = 0, F = 0, A = 0.5, d = h, S = r2.dZero; A > 1e-16; ) {
1417
+ if (F = o + A, d = h.pow(1 - F).mul(v.pow(F)), S = r2.iteratedexp(t, u, d), S.eq(e)) return [new r2(u + F), 2];
1418
+ S.lt(e) && (o += A), A /= 2;
1419
+ }
1420
+ return S.neq_tolerance(e, 1e-7) ? [new r2(r2.dNaN), 0] : [new r2(u + o), 2];
1421
+ }
1422
+ if (e.lt(g) && e.gt(f)) {
1423
+ var p = f.mul(g).sqrt(), q = a.pow(p), I = 0;
1424
+ if (e.lte(p) && e.gt(q)) I = 0;
1425
+ else if (e.lte(q)) {
1426
+ var N = q;
1427
+ for (I = 1; N.gt(e); ) N = a.pow(N), I = I + 1;
1428
+ N.lt(e) && (N = N.log(t), I = I - 1);
1429
+ } else if (e.gt(p)) {
1430
+ var y = p;
1431
+ for (I = 0; y.lt(e); ) y = y.log(t), I = I - 1;
1432
+ }
1433
+ for (var V = 0, C = 0, D = 0.5, Y = p, L = r2.dZero; D > 1e-16; ) {
1434
+ if (C = V + D, Y = p.pow(1 - C).mul(q.pow(C)), L = r2.iteratedexp(t, I, Y), L.eq(e)) return [new r2(I + C), 1];
1435
+ L.gt(e) && (V += D), D /= 2;
1436
+ }
1437
+ return L.neq_tolerance(e, 1e-7) ? [new r2(r2.dNaN), 0] : [new r2(I + V), 1];
1438
+ }
1439
+ throw new Error("Unhandled behavior in excess_slog");
1440
+ } }, { key: "increasingInverse", value: function(e) {
1441
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 120, a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : r2.dLayerMax.neg(), l = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : r2.dLayerMax, f = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : r2.dLayerMax.neg(), g = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : r2.dLayerMax;
1442
+ return function(h) {
1443
+ if (h = new r2(h), a = new r2(a), l = new r2(l), f = new r2(f), g = new r2(g), h.isNan() || l.lt(a) || h.lt(f) || h.gt(g)) return new r2(r2.dNaN);
1444
+ var v = function(b) {
1445
+ return new r2(b);
1446
+ }, u = true;
1447
+ if (l.lt(0)) u = false;
1448
+ else if (a.gt(0)) u = true;
1449
+ else {
1450
+ var M = e(r2.dZero);
1451
+ if (M.eq(h)) return c(0, 0, 0);
1452
+ u = h.gt(M), t && (u = !u);
1453
+ }
1454
+ var x = u, w;
1455
+ if (u) {
1456
+ if (l.lt($)) u = true;
1457
+ else if (a.gt($)) u = false;
1458
+ else {
1459
+ var o = e(new r2($));
1460
+ u = h.lt(o), t && (u = !u);
1461
+ }
1462
+ if (u) {
1463
+ w = true;
1464
+ var F = r2.pow(10, T).recip();
1465
+ if (l.lt(F)) u = false;
1466
+ else if (a.gt(F)) u = true;
1467
+ else {
1468
+ var A = e(new r2(F));
1469
+ u = h.gt(A), t && (u = !u);
1470
+ }
1471
+ if (u) v = function(b) {
1472
+ return r2.pow(10, b).recip();
1473
+ };
1474
+ else {
1475
+ var d = r2.tetrate(10, T);
1476
+ if (l.lt(d)) u = false;
1477
+ else if (a.gt(d)) u = true;
1478
+ else {
1479
+ var S = e(new r2(d));
1480
+ u = h.gt(S), t && (u = !u);
1481
+ }
1482
+ u ? v = function(b) {
1483
+ return r2.tetrate(10, new r2(b).toNumber()).recip();
1484
+ } : v = function(b) {
1485
+ return new r2(b).gt(Math.log10(Number.MAX_VALUE)) ? r2.dZero : r2.tetrate(10, r2.pow(10, b).toNumber()).recip();
1486
+ };
1487
+ }
1488
+ } else {
1489
+ if (w = false, l.lt(T)) u = true;
1490
+ else if (a.gt(T)) u = false;
1491
+ else {
1492
+ var p = e(new r2(T));
1493
+ u = h.lt(p), t && (u = !u);
1494
+ }
1495
+ if (u) v = function(b) {
1496
+ return new r2(b);
1497
+ };
1498
+ else {
1499
+ var q = r2.pow(10, T);
1500
+ if (l.lt(q)) u = true;
1501
+ else if (a.gt(q)) u = false;
1502
+ else {
1503
+ var I = e(new r2(q));
1504
+ u = h.lt(I), t && (u = !u);
1505
+ }
1506
+ if (u) v = function(b) {
1507
+ return r2.pow(10, b);
1508
+ };
1509
+ else {
1510
+ var N = r2.tetrate(10, T);
1511
+ if (l.lt(N)) u = true;
1512
+ else if (a.gt(N)) u = false;
1513
+ else {
1514
+ var y = e(new r2(N));
1515
+ u = h.lt(y), t && (u = !u);
1516
+ }
1517
+ u ? v = function(b) {
1518
+ return r2.tetrate(10, new r2(b).toNumber());
1519
+ } : v = function(b) {
1520
+ return new r2(b).gt(Math.log10(Number.MAX_VALUE)) ? r2.dInf : r2.tetrate(10, r2.pow(10, b).toNumber());
1521
+ };
1522
+ }
1523
+ }
1524
+ }
1525
+ } else {
1526
+ if (w = true, l.lt(-$)) u = false;
1527
+ else if (a.gt(-$)) u = true;
1528
+ else {
1529
+ var V = e(new r2(-$));
1530
+ u = h.gt(V), t && (u = !u);
1531
+ }
1532
+ if (u) {
1533
+ var C = r2.pow(10, T).recip().neg();
1534
+ if (l.lt(C)) u = true;
1535
+ else if (a.gt(C)) u = false;
1536
+ else {
1537
+ var D = e(new r2(C));
1538
+ u = h.lt(D), t && (u = !u);
1539
+ }
1540
+ if (u) v = function(b) {
1541
+ return r2.pow(10, b).recip().neg();
1542
+ };
1543
+ else {
1544
+ var Y = r2.tetrate(10, T).neg();
1545
+ if (l.lt(Y)) u = true;
1546
+ else if (a.gt(Y)) u = false;
1547
+ else {
1548
+ var L = e(new r2(Y));
1549
+ u = h.lt(L), t && (u = !u);
1550
+ }
1551
+ u ? v = function(b) {
1552
+ return r2.tetrate(10, new r2(b).toNumber()).recip().neg();
1553
+ } : v = function(b) {
1554
+ return new r2(b).gt(Math.log10(Number.MAX_VALUE)) ? r2.dZero : r2.tetrate(10, r2.pow(10, b).toNumber()).recip().neg();
1555
+ };
1556
+ }
1557
+ } else {
1558
+ if (w = false, l.lt(-T)) u = false;
1559
+ else if (a.gt(-T)) u = true;
1560
+ else {
1561
+ var G = e(new r2(-T));
1562
+ u = h.gt(G), t && (u = !u);
1563
+ }
1564
+ if (u) v = function(b) {
1565
+ return r2.neg(b);
1566
+ };
1567
+ else {
1568
+ var E = r2.pow(10, T).neg();
1569
+ if (l.lt(E)) u = false;
1570
+ else if (a.gt(E)) u = true;
1571
+ else {
1572
+ var X = e(new r2(E));
1573
+ u = h.gt(X), t && (u = !u);
1574
+ }
1575
+ if (u) v = function(b) {
1576
+ return r2.pow(10, b).neg();
1577
+ };
1578
+ else {
1579
+ var Q = r2.tetrate(10, T).neg();
1580
+ if (l.lt(Q)) u = false;
1581
+ else if (a.gt(Q)) u = true;
1582
+ else {
1583
+ var J = e(new r2(Q));
1584
+ u = h.gt(J), t && (u = !u);
1585
+ }
1586
+ u ? v = function(b) {
1587
+ return r2.tetrate(10, new r2(b).toNumber()).neg();
1588
+ } : v = function(b) {
1589
+ return new r2(b).gt(Math.log10(Number.MAX_VALUE)) ? r2.dNegInf : r2.tetrate(10, r2.pow(10, b).toNumber()).neg();
1590
+ };
1591
+ }
1592
+ }
1593
+ }
1594
+ }
1595
+ for (var Z = x != w != t, re = Z ? function(O, b) {
1596
+ return r2.gt(O, b);
1597
+ } : function(O, b) {
1598
+ return r2.lt(O, b);
1599
+ }, W = 1e-3, H = false, te = false, U = 1, P = r2.dOne, B = 0, z = false, R = 1; R < i; ++R) {
1600
+ z = false, B = U, P = v(U), P.gt(l) && (P = l, z = true), P.lt(a) && (P = a, z = true);
1601
+ var ee = e(P);
1602
+ if (ee.eq(h) && !z) break;
1603
+ var j = re(ee, h);
1604
+ if (R > 1 && te != j && (H = true), te = j, H ? W /= 2 : W *= 2, j != Z && P.eq(l) || j == Z && P.eq(a)) return new r2(r2.dNaN);
1605
+ if (W = Math.abs(W) * (j ? -1 : 1), U += W, W === 0 || B == U) break;
1606
+ }
1607
+ return v(U);
1608
+ };
1609
+ } }]), r2;
1610
+ })();
1611
+ k.dZero = c(0, 0, 0);
1612
+ k.dOne = c(1, 0, 1);
1613
+ k.dNegOne = c(-1, 0, 1);
1614
+ k.dTwo = c(1, 0, 2);
1615
+ k.dTen = c(1, 0, 10);
1616
+ k.dNaN = c(Number.NaN, Number.NaN, Number.NaN);
1617
+ k.dInf = c(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
1618
+ k.dNegInf = c(-1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
1619
+ k.dNumberMax = m(1, 0, Number.MAX_VALUE);
1620
+ k.dNumberMin = m(1, 0, Number.MIN_VALUE);
1621
+ k.dLayerSafeMax = m(1, Number.MAX_SAFE_INTEGER, T - 1);
1622
+ k.dLayerSafeMin = m(1, Number.MAX_SAFE_INTEGER, -8999999999999999);
1623
+ k.dLayerMax = m(1, Number.MAX_VALUE, T - 1);
1624
+ k.dLayerMin = m(1, Number.MAX_VALUE, -8999999999999999);
1625
+ k.fromStringCache = new me(de);
1626
+ s = k.fromValue_noAlloc;
1627
+ m = k.fromComponents;
1628
+ c = k.fromComponents_noNormalize;
1629
+ k.fromMantissaExponent;
1630
+ k.fromMantissaExponent_noNormalize;
1631
+
1632
+ // src/rundot-game-api/systems/numbers.js
1633
+ function createNumbersAPI() {
1634
+ const numbersAPI = {
1635
+ // Type detection helper
1636
+ isBigNumber: (value) => {
1637
+ if (typeof value === "string" && value.startsWith("BE:")) return true;
1638
+ if (value instanceof k) return true;
1639
+ if (typeof value === "number" && (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)) return true;
1640
+ return false;
1641
+ },
1642
+ // Normalize any input to Decimal (for API responses)
1643
+ normalize: (value) => {
1644
+ if (value instanceof k) return value;
1645
+ if (typeof value === "string" && value.startsWith("BE:")) {
1646
+ return new k(value.slice(3));
1647
+ }
1648
+ return new k(value);
1649
+ },
1650
+ // Common game formatters
1651
+ format: {
1652
+ incremental: (value) => {
1653
+ const decimal = value instanceof k ? value : new k(value);
1654
+ const suffixes = ["", "K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc", "No", "Dc"];
1655
+ if (decimal.lt(1e3)) return decimal.toFixed(0);
1656
+ const log = decimal.log10();
1657
+ const suffixIndex = Math.floor(log / 3);
1658
+ if (suffixIndex < suffixes.length) {
1659
+ const divisor = k.pow(1e3, suffixIndex);
1660
+ const value2 = decimal.div(divisor);
1661
+ return `${value2.toFixed(2)}${suffixes[suffixIndex]}`;
1662
+ }
1663
+ return decimal.toExponential(2);
1664
+ }
1665
+ },
1666
+ // NEW: Calculate geometric series cost with full Decimal precision
1667
+ calculateGeometricSeriesCost: (baseCost, multiplier, currentQuantity, purchaseAmount) => {
1668
+ try {
1669
+ const base = new k(baseCost);
1670
+ const r2 = new k(multiplier);
1671
+ const q = new k(currentQuantity);
1672
+ const n = new k(purchaseAmount);
1673
+ if (r2.eq(1)) {
1674
+ return base.mul(n);
1675
+ }
1676
+ const a = base.mul(r2.pow(q));
1677
+ const numerator = a.mul(r2.pow(n).sub(1));
1678
+ const denominator = r2.sub(1);
1679
+ return numerator.div(denominator);
1680
+ } catch (error) {
1681
+ console.error("[RUN.gameAPI] Decimal calculation failed, falling back to regular math:", error);
1682
+ const base = Number(baseCost);
1683
+ const r2 = Number(multiplier);
1684
+ if (r2 === 1) return base * purchaseAmount;
1685
+ const a = base * Math.pow(r2, currentQuantity);
1686
+ return a * (Math.pow(r2, purchaseAmount) - 1) / (r2 - 1);
1687
+ }
1688
+ },
1689
+ // NEW: Find maximum affordable amount using Decimal precision
1690
+ calculateMaxAffordableDecimal: (availableCash, baseCost, multiplier, currentQuantity) => {
1691
+ try {
1692
+ const cash = new k(availableCash);
1693
+ const costOne = numbersAPI.calculateGeometricSeriesCost(baseCost, multiplier, currentQuantity, 1);
1694
+ if (cash.lt(costOne)) return 0;
1695
+ let low = 1;
1696
+ let high = 1;
1697
+ while (high < 1e6) {
1698
+ const cost = numbersAPI.calculateGeometricSeriesCost(baseCost, multiplier, currentQuantity, high);
1699
+ if (cost.gt(cash)) break;
1700
+ low = high;
1701
+ high *= 2;
1702
+ }
1703
+ while (low < high) {
1704
+ const mid = Math.floor((low + high + 1) / 2);
1705
+ const cost = numbersAPI.calculateGeometricSeriesCost(baseCost, multiplier, currentQuantity, mid);
1706
+ if (cost.lte(cash)) {
1707
+ low = mid;
1708
+ } else {
1709
+ high = mid - 1;
1710
+ }
1711
+ }
1712
+ return low;
1713
+ } catch (error) {
1714
+ console.error("[RUN.gameAPI] Decimal max affordable calculation failed:", error);
1715
+ return Math.floor(Number(availableCash) / Number(baseCost));
1716
+ }
1717
+ },
1718
+ // NEW: Format Decimal value for currency display
1719
+ formatDecimalCurrency: (decimalValue) => {
1720
+ try {
1721
+ if (numbersAPI.isBigNumber(decimalValue)) {
1722
+ return `$${numbersAPI.format.incremental(decimalValue)}`;
1723
+ }
1724
+ return `$${numbersAPI.format.incremental(decimalValue)}`;
1725
+ } catch (error) {
1726
+ console.error("[RUN.gameAPI] Decimal formatting failed:", error);
1727
+ return `$${Number(decimalValue).toLocaleString()}`;
1728
+ }
1729
+ }
1730
+ };
1731
+ return numbersAPI;
1732
+ }
1733
+ async function initializeNumbers(rundotGameApiInstance) {
1734
+ const { createProxiedObject: createProxiedObject2, createProxiedMethod: createProxiedMethod2 } = await import('../core-6DQFSOBL.js');
1735
+ const numbersAPI = createNumbersAPI();
1736
+ rundotGameApiInstance.numbers = createProxiedObject2.call(
1737
+ rundotGameApiInstance,
1738
+ "numbers",
1739
+ {
1740
+ isBigNumber: numbersAPI.isBigNumber,
1741
+ normalize: numbersAPI.normalize,
1742
+ format: {
1743
+ incremental: numbersAPI.format.incremental
1744
+ },
1745
+ // NEW: Expose geometric series calculation methods
1746
+ calculateGeometricSeriesCost: numbersAPI.calculateGeometricSeriesCost,
1747
+ calculateMaxAffordableDecimal: numbersAPI.calculateMaxAffordableDecimal,
1748
+ formatDecimalCurrency: numbersAPI.formatDecimalCurrency,
1749
+ // Expose Decimal class for direct use
1750
+ Decimal: k
1751
+ }
1752
+ );
1753
+ }
1754
+
1755
+ // src/context/index.ts
1756
+ function initializeContext(rundotGameApi, host) {
1757
+ rundotGameApi.context = host.context || {
1758
+ initializeAsleep: false,
1759
+ launchParams: {},
1760
+ shareParams: {}
1761
+ };
1762
+ }
1763
+
1764
+ // src/rundot-game-api/index.js
1765
+ var HapticStyle = {
1766
+ LIGHT: "light",
1767
+ MEDIUM: "medium",
1768
+ HEAVY: "heavy",
1769
+ SUCCESS: "success",
1770
+ WARNING: "warning",
1771
+ ERROR: "error"
1772
+ };
1773
+ var RundotGameAPI2 = class {
1774
+ constructor() {
1775
+ console.log(`[Run.game SDK] SDK Version: ${SDK_VERSION}`);
1776
+ this._shared = {
1777
+ initialized: false,
1778
+ initPromise: null
1779
+ };
1780
+ this._bootstrap = {
1781
+ apiInjected: false,
1782
+ apiInjectionTimeout: null,
1783
+ rundotGame: null,
1784
+ isInsideHostedEnvironment: false,
1785
+ _localHandlers: {},
1786
+ // Store local handlers here
1787
+ _pendingMessages: []
1788
+ // Buffer messages until handlers are registered
1789
+ };
1790
+ const deterministicInstanceId = this._generateDeterministicInstanceId();
1791
+ this._mock = {
1792
+ // Essential config (matching H5ConfigProperties)
1793
+ appId: "mock-app",
1794
+ mode: "preview",
1795
+ instanceId: deterministicInstanceId,
1796
+ // Use deterministic ID instead of random
1797
+ appUrl: "mock-app/index.html",
1798
+ safeAreaInsets: {
1799
+ top: 10,
1800
+ right: 0,
1801
+ bottom: 10,
1802
+ left: 0
1803
+ },
1804
+ // NOTE: locale and languageCode are NOT part of static config
1805
+ // They are delivered via INIT_SDK handshake and accessed via getLocale()/getLanguageCode()
1806
+ // Complete environment info (matching buildStaticConfig)
1807
+ environment: {
1808
+ isDevelopment: true,
1809
+ platform: "web",
1810
+ platformVersion: "mock-1.0",
1811
+ browserInfo: {
1812
+ browser: "MockBrowser",
1813
+ userAgent: navigator.userAgent,
1814
+ isMobile: /Mobi|Android/i.test(navigator.userAgent),
1815
+ isTablet: /iPad|Tablet|Pad/i.test(navigator.userAgent),
1816
+ language: navigator.language || "en-US"
1817
+ }
1818
+ },
1819
+ // Complete device info (matching buildStaticConfig)
1820
+ device: {
1821
+ screenSize: { width: window.innerWidth, height: window.innerHeight },
1822
+ viewportSize: {
1823
+ width: window.innerWidth - 20,
1824
+ // account for safe area
1825
+ height: window.innerHeight - 20
1826
+ },
1827
+ orientation: window.innerWidth > window.innerHeight ? "landscape" : "portrait",
1828
+ pixelRatio: window.devicePixelRatio || 1,
1829
+ fontScale: 1,
1830
+ deviceType: window.innerWidth > 768 ? "tablet" : "phone",
1831
+ platform: "web",
1832
+ isWeb: true,
1833
+ isMobile: /Mobi|Android/i.test(navigator.userAgent),
1834
+ hapticsEnabled: false,
1835
+ // Mock environment doesn't support haptics
1836
+ haptics: {
1837
+ supported: false,
1838
+ enabled: false
1839
+ }
1840
+ },
1841
+ // Context structure (matching buildStaticConfig)
1842
+ context: {
1843
+ postData: void 0,
1844
+ stack: {
1845
+ isInStack: false,
1846
+ stackPosition: 0,
1847
+ parentInstanceId: void 0
1848
+ }
1849
+ },
1850
+ // Internal state (existing handlers and interaction data)
1851
+ handlers: {
1852
+ onPlay: null,
1853
+ onPause: null,
1854
+ onResume: null,
1855
+ onQuit: null,
1856
+ onHide: null,
1857
+ onShow: null
1858
+ },
1859
+ // Platform overrides for testing different environments
1860
+ platformOverrides: {
1861
+ isMobile: true,
1862
+ isWeb: false
1863
+ }
1864
+ };
1865
+ this._detectHostedEnvironment();
1866
+ this.config = createProxiedObject.call(this, "config", {});
1867
+ const originalConfig = this.config;
1868
+ this.config = new Proxy(originalConfig, {
1869
+ get(target, prop) {
1870
+ if (prop === "locale") {
1871
+ throw new Error("Use RundotGameAPI.getLocale() instead.");
1872
+ }
1873
+ if (prop === "languageCode") {
1874
+ throw new Error("Use RundotGameAPI.getLanguageCode() instead.");
1875
+ }
1876
+ if (prop === "user") {
1877
+ throw new Error("Use RundotGameAPI.getLocale() and RundotGameAPI.getLanguageCode() instead.");
1878
+ }
1879
+ if (prop === "device") {
1880
+ throw new Error("Use RundotGameAPI.system.getDevice() instead.");
1881
+ }
1882
+ if (prop === "environment") {
1883
+ throw new Error("Use RundotGameAPI.system.getEnvironment() instead.");
1884
+ }
1885
+ if (prop === "profile") {
1886
+ throw new Error("Use RundotGameAPI.getProfile() instead.");
1887
+ }
1888
+ if (prop === "rooms") {
1889
+ throw new Error("Rooms configuration is internal. Use RundotGameAPI.rooms methods instead.");
1890
+ }
1891
+ if (prop === "ui") {
1892
+ return new Proxy({}, {
1893
+ get(uiTarget, uiProp) {
1894
+ if (uiProp === "safeArea") {
1895
+ throw new Error("Use RundotGameAPI.system.getSafeArea() instead.");
1896
+ }
1897
+ if (uiProp === "hudInsets") {
1898
+ throw new Error("Use RundotGameAPI.system.getSafeArea() instead.");
1899
+ }
1900
+ if (uiProp === "controls") {
1901
+ throw new Error("UI controls are no longer supported.");
1902
+ }
1903
+ throw new Error(`RundotGameAPI.config.ui.${uiProp} is not supported.`);
1904
+ }
1905
+ });
1906
+ }
1907
+ return target[prop];
1908
+ },
1909
+ set(target, prop, value) {
1910
+ if (prop === "locale" || prop === "languageCode" || prop === "user" || prop === "device" || prop === "environment" || prop === "profile") {
1911
+ throw new Error(`RundotGameAPI.config.${prop} cannot be set. Configuration is read-only.`);
1912
+ }
1913
+ if (prop === "ui") {
1914
+ console.warn("[RUN.game SDK] Cannot set config.ui");
1915
+ return true;
1916
+ }
1917
+ target[prop] = value;
1918
+ return true;
1919
+ },
1920
+ has(target, prop) {
1921
+ if (prop === "ui") {
1922
+ return false;
1923
+ }
1924
+ return prop in target;
1925
+ },
1926
+ ownKeys(target) {
1927
+ return Reflect.ownKeys(target).filter((key) => key !== "ui");
1928
+ },
1929
+ getOwnPropertyDescriptor(target, prop) {
1930
+ if (prop === "ui") {
1931
+ return void 0;
1932
+ }
1933
+ return Reflect.getOwnPropertyDescriptor(target, prop);
1934
+ }
1935
+ });
1936
+ this._hostPromise = this._createHostAsync();
1937
+ initializeAssetLoader(this, createProxiedMethod);
1938
+ this.getLocale = () => {
1939
+ if (this._localeData) {
1940
+ return this._localeData;
1941
+ }
1942
+ if (typeof navigator !== "undefined" && navigator.language) {
1943
+ return navigator.language;
1944
+ }
1945
+ return "en-US";
1946
+ };
1947
+ this.getLanguageCode = () => {
1948
+ if (this._languageCodeData) {
1949
+ return this._languageCodeData;
1950
+ }
1951
+ const locale = this.getLocale();
1952
+ return locale.split("-")[0];
1953
+ };
1954
+ }
1955
+ // Generate deterministic instance ID based on current page URL
1956
+ _generateDeterministicInstanceId() {
1957
+ try {
1958
+ let url = window.location.href || "";
1959
+ let normalizedUrl = url.replace(/^https?:\/\/[^\/]+/, "");
1960
+ normalizedUrl = normalizedUrl.split("?")[0].split("#")[0].trim();
1961
+ if (!normalizedUrl.startsWith("/H5/") && !normalizedUrl.startsWith("H5/")) {
1962
+ if (!normalizedUrl.includes("/")) {
1963
+ normalizedUrl = `/H5/${normalizedUrl}/index.html`;
1964
+ } else if (!normalizedUrl.startsWith("/")) {
1965
+ normalizedUrl = `/${normalizedUrl}`;
1966
+ }
1967
+ }
1968
+ let hash = 0;
1969
+ for (let i = 0; i < normalizedUrl.length; i++) {
1970
+ const char = normalizedUrl.charCodeAt(i);
1971
+ hash = (hash << 5) - hash + char;
1972
+ hash = hash & hash;
1973
+ }
1974
+ const hashB36 = Math.abs(hash).toString(36);
1975
+ const paddedHash = hashB36.substring(0, 8).padEnd(8, "0");
1976
+ const deterministicId = `app-${paddedHash}`;
1977
+ return deterministicId;
1978
+ } catch (error) {
1979
+ console.error(
1980
+ "[Run.game Bootstrap] Error generating deterministic ID, falling back to random:",
1981
+ error
1982
+ );
1983
+ return "app-" + Math.random().toString(36).substr(2, 8);
1984
+ }
1985
+ }
1986
+ //---------------------------------------
1987
+ // BOOTSTRAP METHODS
1988
+ //---------------------------------------
1989
+ _detectHostedEnvironment() {
1990
+ const isInIframe = window.self !== window.top;
1991
+ const hasReactNativeWebView = typeof window.ReactNativeWebView !== "undefined";
1992
+ this._bootstrap.isInsideHostedEnvironment = isInIframe || hasReactNativeWebView;
1993
+ }
1994
+ //---------------------------------------
1995
+ // HOST CREATION (async for dynamic imports)
1996
+ //---------------------------------------
1997
+ /**
1998
+ * Create and initialize the Host asynchronously.
1999
+ *
2000
+ * This is async because createHost uses dynamic import for SandboxHost,
2001
+ * which prevents Firebase from being bundled in production builds.
2002
+ */
2003
+ async _createHostAsync() {
2004
+ const isInsideHostedEnv = this._bootstrap.isInsideHostedEnvironment;
2005
+ const host = await createHost(this, !isInsideHostedEnv);
2006
+ this.host = host;
2007
+ initializeStorage(this, host);
2008
+ initializeRoomsApi(this, host);
2009
+ initializeAds(this, host);
2010
+ initializePopups(this, host);
2011
+ initializeAnalytics(this, host);
2012
+ initializeIap(this, host);
2013
+ initializeLeaderboard(this, host);
2014
+ initializeLocalNotifications(this, host);
2015
+ initializePreloader(this, host);
2016
+ initializeTime(this, host);
2017
+ initializeLifecycleApi(this, host);
2018
+ initializeHaptics(this, host);
2019
+ initializeCdn(this, host);
2020
+ initializeFeaturesApi(this, host);
2021
+ initializeLoggingApi(this, host);
2022
+ const isAvatar3dDisabled = typeof window !== "undefined" && window.location.search.includes("EXPO_PUBLIC_DISABLE_3D_AVATARS=true");
2023
+ initializeProfile(this, host);
2024
+ initializeSystem(this, host);
2025
+ if (!isAvatar3dDisabled) {
2026
+ initializeAvatar3d(this, host);
2027
+ }
2028
+ initializeStackNavigation(this, host);
2029
+ initializeAi(this, host);
2030
+ initializeSimulation(this, host);
2031
+ initializeSocial(this, host);
2032
+ return host;
2033
+ }
2034
+ //---------------------------------------
2035
+ // PUBLIC API METHODS
2036
+ //---------------------------------------
2037
+ /**
2038
+ * @deprecated No longer need to call this method. This will get called on import.
2039
+ */
2040
+ async initializeAsync() {
2041
+ if (this._shared.initialized) {
2042
+ return Promise.resolve(this.host.context);
2043
+ }
2044
+ if (this._shared.initPromise) {
2045
+ return this._shared.initPromise;
2046
+ }
2047
+ this._shared.initPromise = new Promise(async (resolve, reject) => {
2048
+ try {
2049
+ await this._hostPromise;
2050
+ const result = await this.host.initialize();
2051
+ initializeContext(this, this.host);
2052
+ this._shared.initialized = true;
2053
+ resolve(result);
2054
+ } catch (err) {
2055
+ reject(err);
2056
+ }
2057
+ });
2058
+ return this._shared.initPromise;
2059
+ }
2060
+ };
2061
+ var instance = new RundotGameAPI2();
2062
+ var rundot_game_api_default = instance;
2063
+ window.RundotGameAPI = instance;
2064
+ instance.HapticStyle = HapticStyle;
2065
+ instance.isAvailable = function() {
2066
+ try {
2067
+ return !!(typeof window !== "undefined" && window.RundotGameAPI) || !!this;
2068
+ } catch {
2069
+ return false;
2070
+ }
2071
+ };
2072
+ try {
2073
+ await initializeNumbers(instance);
2074
+ } catch (error) {
2075
+ console.error("[RUN.game SDK] Failed to initialize numbers system:", error);
2076
+ }
2077
+ try {
2078
+ console.log(`[Run.game SDK] Initializing...`);
2079
+ await instance.initializeAsync();
2080
+ instance.log(`Initialized RUN.game SDK version ${SDK_VERSION} successfully.`);
2081
+ console.log(`[Run.game SDK] Initialized RUN.game SDK version ${SDK_VERSION} successfully.`);
2082
+ } catch (error) {
2083
+ console.error("[RUN.game SDK] Failed to initialize RUN.game SDK:", error);
2084
+ }
2085
+
2086
+ export { rundot_game_api_default as default };
2087
+ //# sourceMappingURL=index.js.map
2088
+ //# sourceMappingURL=index.js.map