lyb-js 1.6.16 → 1.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lyb.js DELETED
@@ -1,3929 +0,0 @@
1
- (function(factory) {
2
- typeof define === "function" && define.amd ? define(factory) : factory();
3
- })(function() {
4
- "use strict";
5
- const libJsGetDataType = (v) => {
6
- return Object.prototype.toString.call(v).substring(8).replace(/]/g, "").toLowerCase();
7
- };
8
- const libJsPromiseTimeout = (delay = 1, fn) => {
9
- let timeoutId;
10
- let remainingTime = delay;
11
- let startTime = Date.now();
12
- let isPaused = false;
13
- return new Promise((resolve) => {
14
- const handleVisibilityChange = () => {
15
- if (document.hidden) {
16
- isPaused = true;
17
- clearTimeout(timeoutId);
18
- remainingTime -= Date.now() - startTime;
19
- } else {
20
- if (isPaused) {
21
- isPaused = false;
22
- startTime = Date.now();
23
- startTimeout(resolve);
24
- }
25
- }
26
- };
27
- const startTimeout = (resolve2) => {
28
- timeoutId = setTimeout(() => {
29
- fn == null ? void 0 : fn();
30
- resolve2();
31
- document.removeEventListener(
32
- "visibilitychange",
33
- handleVisibilityChange
34
- );
35
- }, remainingTime);
36
- };
37
- document.addEventListener("visibilitychange", handleVisibilityChange);
38
- startTimeout(resolve);
39
- });
40
- };
41
- const libJsColorConsole = (title, color, logs = []) => {
42
- const colors = {
43
- red: "#c0392b",
44
- orange: "#d35400",
45
- yellow: "#f1c40f",
46
- green: "#27ae60",
47
- blue: "#2980b9",
48
- purple: "#be2edd"
49
- };
50
- const getTimestamp = () => {
51
- const now = /* @__PURE__ */ new Date();
52
- const hour = String(now.getHours()).padStart(2, "0");
53
- const minutes = String(now.getMinutes()).padStart(2, "0");
54
- const seconds = String(now.getSeconds()).padStart(2, "0");
55
- return `[${hour}:${minutes}:${seconds}]`;
56
- };
57
- if (Array.isArray(logs)) {
58
- const v = logs.map((log3) => {
59
- return [`
60
- ${log3.label}:`, log3.value];
61
- });
62
- console.log(
63
- `%c${getTimestamp()}-${title}`,
64
- `color: #fff;background: ${colors[color]}; font-size:14px;border-radius:5px;padding:0.25em;margin:0.5em 0`,
65
- ...v.flat(Infinity)
66
- );
67
- } else {
68
- console.log(
69
- `%c${getTimestamp()}-${title}`,
70
- `color: #fff;background: ${colors[color]}; font-size:14px;border-radius:5px;padding:0.25em;margin:0.5em 0`,
71
- logs
72
- );
73
- }
74
- };
75
- const libJsIsMobile = () => {
76
- const ua = navigator.userAgent.toLowerCase();
77
- return /mobile|android|iphone|ipod/.test(ua);
78
- };
79
- const libJsIsPad = () => {
80
- const ua = navigator.userAgent.toLowerCase();
81
- const width = Math.max(window.screen.width, window.screen.height);
82
- const height = Math.min(window.screen.width, window.screen.height);
83
- const aspectRatio = width / height;
84
- const isTabletUserAgent = /ipad|tablet|playbook|silk/.test(ua) && !/mobile/.test(ua);
85
- const isTabletWidth = width >= 768 && width <= 1366;
86
- const isTabletAspectRatio = aspectRatio >= 1.3 && aspectRatio <= 1.6;
87
- return isTabletUserAgent || isTabletWidth && isTabletAspectRatio;
88
- };
89
- const libJsPathParams = (path) => {
90
- const v = path || location.href;
91
- const url = v.split("?")[1];
92
- if (!url)
93
- return {};
94
- const params = url.split("&").reduce((pre, cur) => {
95
- const [k, v2] = cur.split(/=(.+)/).map(decodeURIComponent);
96
- return pre[k] = v2, pre;
97
- }, {}) || {};
98
- return params;
99
- };
100
- const libJsSetTitleIcon = (title, url) => {
101
- document.title = title;
102
- const link = document.createElement("link");
103
- link.setAttribute("rel", "icon");
104
- link.setAttribute("href", url);
105
- const head = document.head || document.getElementsByTagName("head")[0];
106
- head.appendChild(link);
107
- };
108
- const libJsTagTitleTip = (backTitle, leaveTitle) => {
109
- let document_title = "";
110
- let timer;
111
- window.addEventListener("visibilitychange", () => {
112
- clearTimeout(timer);
113
- if (document.hidden) {
114
- if (document.title !== backTitle) {
115
- document_title = document.title;
116
- }
117
- document.title = leaveTitle;
118
- return;
119
- }
120
- document.title = backTitle;
121
- timer = setTimeout(() => {
122
- document.title = document_title;
123
- }, 1e3);
124
- });
125
- };
126
- const libJsObjToUrlParams = (params) => {
127
- return Object.entries(params).map(([key, value]) => `${key}=${value}`).join("&");
128
- };
129
- const libJsChunkArray = (arr, chunkSize) => {
130
- const result = [];
131
- for (let i = 0; i < arr.length; i += chunkSize) {
132
- result.push(arr.slice(i, i + chunkSize));
133
- }
134
- return result;
135
- };
136
- const libJsDeepJSONParse = (data) => {
137
- if (typeof data === "string") {
138
- const trimmed = data.trim();
139
- if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
140
- try {
141
- return libJsDeepJSONParse(JSON.parse(trimmed));
142
- } catch {
143
- return data;
144
- }
145
- }
146
- return data;
147
- }
148
- if (Array.isArray(data)) {
149
- return data.map((item) => libJsDeepJSONParse(item));
150
- }
151
- if (data !== null && typeof data === "object") {
152
- return Object.keys(data).reduce((acc, key) => {
153
- acc[key] = libJsDeepJSONParse(data[key]);
154
- return acc;
155
- }, {});
156
- }
157
- return data;
158
- };
159
- const libJsGroupArrayByKey = (arr = [], key) => {
160
- return key ? arr.reduce((t, v) => {
161
- if (!t[v[key]]) {
162
- t[v[key]] = [];
163
- }
164
- t[v[key]].push(v);
165
- return t;
166
- }, {}) : {};
167
- };
168
- const libJsMatchEmail = (str, emailList) => {
169
- return str.includes("@") ? emailList.filter((item) => item.includes(str.slice(str.indexOf("@")))).map((item) => (str.includes("@") ? str.split("@")[0] : str) + item) : emailList.map((item) => str + item);
170
- };
171
- const libJsShuffleArray = (arr) => {
172
- const newArr = [...arr];
173
- for (let i = newArr.length - 1; i > 0; i--) {
174
- const j = Math.floor(Math.random() * (i + 1));
175
- [newArr[i], newArr[j]] = [newArr[j], newArr[i]];
176
- }
177
- return newArr;
178
- };
179
- const libJsStepArray = (arr, step) => {
180
- const length = arr.length;
181
- if (length === 0 || step % length === 0)
182
- return arr;
183
- const normalizedStep = (step % length + length) % length;
184
- return arr.slice(-normalizedStep).concat(arr.slice(0, -normalizedStep));
185
- };
186
- const libReverseArrayFromIndex = (arr, index) => {
187
- if (index < 0 || index >= arr.length) {
188
- throw new Error("Index out of bounds");
189
- }
190
- const subArray = arr.slice(index + 1).reverse();
191
- return [...arr.slice(0, index + 1), ...subArray];
192
- };
193
- const libJsDownloadImageLink = (link, name) => {
194
- fetch(link).then((res) => res.blob()).then((blob) => {
195
- const a = document.createElement("a");
196
- const url = window.URL.createObjectURL(blob);
197
- a.href = url;
198
- a.download = name;
199
- a.click();
200
- });
201
- };
202
- const libJsImageOptimizer = (obj) => {
203
- const canvas = document.createElement("canvas");
204
- canvas.classList.add("imageOptimizer");
205
- document.body.appendChild(canvas);
206
- const files = obj.file;
207
- if (!files)
208
- return;
209
- const name = files.name;
210
- const extension = name.split(".").pop().toLowerCase();
211
- const ratio = obj.ratio || 1;
212
- const maxSize = obj.maxSize || 1024;
213
- const width = obj.width || 1e4;
214
- const mimeType = files.type;
215
- function dataURLtoFile(dataURL, filename) {
216
- const arr = dataURL.split(",");
217
- const mime = arr[0].match(/:(.*?);/)[1];
218
- const bstr = window.atob(arr[1]);
219
- const n = bstr.length;
220
- const u8arr = new Uint8Array(n);
221
- for (let i = 0; i < n; i++) {
222
- u8arr[i] = bstr.charCodeAt(i);
223
- }
224
- return new File([u8arr], filename, { type: mime });
225
- }
226
- function formData(file) {
227
- const data = new FormData();
228
- data.append("file", file);
229
- return data;
230
- }
231
- const reader = new FileReader();
232
- reader.readAsDataURL(files);
233
- reader.onload = (e) => {
234
- const result = e.target.result;
235
- if (e.total / 1024 > maxSize) {
236
- const image = new Image();
237
- image.src = result;
238
- image.onload = () => {
239
- const context = canvas.getContext("2d");
240
- const scale = width / image.width;
241
- if (scale < 1) {
242
- canvas.width = image.width * scale;
243
- canvas.height = image.height * scale;
244
- context.drawImage(
245
- image,
246
- 0,
247
- 0,
248
- image.width * scale,
249
- image.height * scale
250
- );
251
- } else {
252
- canvas.width = image.width;
253
- canvas.height = image.height;
254
- context.drawImage(image, 0, 0, image.width, image.height);
255
- }
256
- const dataUrl = canvas.toDataURL(mimeType, ratio);
257
- const newName = `${name.split(".")[0]}.${extension}`;
258
- const file = dataURLtoFile(dataUrl, newName);
259
- obj.success(formData(file), file, dataUrl);
260
- canvas.remove();
261
- };
262
- image.onerror = obj.fail;
263
- } else {
264
- const newName = `${name.split(".")[0]}.${extension}`;
265
- const file = dataURLtoFile(result, newName);
266
- obj.success(formData(file), file, result);
267
- canvas.remove();
268
- }
269
- };
270
- reader.onerror = obj.fail;
271
- };
272
- const libJsSaveJson = (name, data) => {
273
- const urlObject = window.URL || window.webkitURL;
274
- const exportBlob = new Blob([data]);
275
- const saveLink = document.createElement("a");
276
- saveLink.href = urlObject.createObjectURL(exportBlob);
277
- saveLink.download = name;
278
- saveLink.click();
279
- urlObject.revokeObjectURL(saveLink.href);
280
- };
281
- const libJsConvertAngle = (value, type) => {
282
- if (type === "rad") {
283
- return value * (Math.PI / 180);
284
- } else if (type === "deg") {
285
- return value * (180 / Math.PI);
286
- } else {
287
- throw new Error("请使用正确类型");
288
- }
289
- };
290
- const libJsCoordsAngle = (coord1, coord2, mode = "deg") => {
291
- const deltaX = coord2.x - coord1.x;
292
- const deltaY = coord2.y - coord1.y;
293
- const angleRad = Math.atan2(deltaY, deltaX);
294
- if (mode === "deg") {
295
- let angleDeg = angleRad * (180 / Math.PI);
296
- angleDeg = -angleDeg + 90;
297
- if (angleDeg < 0) {
298
- angleDeg += 360;
299
- }
300
- return angleDeg;
301
- }
302
- return angleRad;
303
- };
304
- const libJsCoordsDistance = (coord1, coord2) => {
305
- const deltaX = coord2.x - coord1.x;
306
- const deltaY = coord2.y - coord1.y;
307
- const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
308
- return distance;
309
- };
310
- /*!
311
- * decimal.js v10.4.3
312
- * An arbitrary-precision Decimal type for JavaScript.
313
- * https://github.com/MikeMcl/decimal.js
314
- * Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
315
- * MIT Licence
316
- */
317
- var EXP_LIMIT = 9e15, MAX_DIGITS = 1e9, NUMERALS = "0123456789abcdef", LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058", PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789", DEFAULTS = {
318
- // These values must be integers within the stated ranges (inclusive).
319
- // Most of these values can be changed at run-time using the `Decimal.config` method.
320
- // The maximum number of significant digits of the result of a calculation or base conversion.
321
- // E.g. `Decimal.config({ precision: 20 });`
322
- precision: 20,
323
- // 1 to MAX_DIGITS
324
- // The rounding mode used when rounding to `precision`.
325
- //
326
- // ROUND_UP 0 Away from zero.
327
- // ROUND_DOWN 1 Towards zero.
328
- // ROUND_CEIL 2 Towards +Infinity.
329
- // ROUND_FLOOR 3 Towards -Infinity.
330
- // ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
331
- // ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
332
- // ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
333
- // ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
334
- // ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
335
- //
336
- // E.g.
337
- // `Decimal.rounding = 4;`
338
- // `Decimal.rounding = Decimal.ROUND_HALF_UP;`
339
- rounding: 4,
340
- // 0 to 8
341
- // The modulo mode used when calculating the modulus: a mod n.
342
- // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
343
- // The remainder (r) is calculated as: r = a - n * q.
344
- //
345
- // UP 0 The remainder is positive if the dividend is negative, else is negative.
346
- // DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
347
- // FLOOR 3 The remainder has the same sign as the divisor (Python %).
348
- // HALF_EVEN 6 The IEEE 754 remainder function.
349
- // EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
350
- //
351
- // Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
352
- // division (9) are commonly used for the modulus operation. The other rounding modes can also
353
- // be used, but they may not give useful results.
354
- modulo: 1,
355
- // 0 to 9
356
- // The exponent value at and beneath which `toString` returns exponential notation.
357
- // JavaScript numbers: -7
358
- toExpNeg: -7,
359
- // 0 to -EXP_LIMIT
360
- // The exponent value at and above which `toString` returns exponential notation.
361
- // JavaScript numbers: 21
362
- toExpPos: 21,
363
- // 0 to EXP_LIMIT
364
- // The minimum exponent value, beneath which underflow to zero occurs.
365
- // JavaScript numbers: -324 (5e-324)
366
- minE: -EXP_LIMIT,
367
- // -1 to -EXP_LIMIT
368
- // The maximum exponent value, above which overflow to Infinity occurs.
369
- // JavaScript numbers: 308 (1.7976931348623157e+308)
370
- maxE: EXP_LIMIT,
371
- // 1 to EXP_LIMIT
372
- // Whether to use cryptographically-secure random number generation, if available.
373
- crypto: false
374
- // true/false
375
- }, inexact, quadrant, external = true, decimalError = "[DecimalError] ", invalidArgument = decimalError + "Invalid argument: ", precisionLimitExceeded = decimalError + "Precision limit exceeded", cryptoUnavailable = decimalError + "crypto unavailable", tag = "[object Decimal]", mathfloor = Math.floor, mathpow = Math.pow, isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i, isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i, isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i, isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, BASE = 1e7, LOG_BASE = 7, MAX_SAFE_INTEGER = 9007199254740991, LN10_PRECISION = LN10.length - 1, PI_PRECISION = PI.length - 1, P = { toStringTag: tag };
376
- P.absoluteValue = P.abs = function() {
377
- var x = new this.constructor(this);
378
- if (x.s < 0)
379
- x.s = 1;
380
- return finalise(x);
381
- };
382
- P.ceil = function() {
383
- return finalise(new this.constructor(this), this.e + 1, 2);
384
- };
385
- P.clampedTo = P.clamp = function(min2, max2) {
386
- var k, x = this, Ctor = x.constructor;
387
- min2 = new Ctor(min2);
388
- max2 = new Ctor(max2);
389
- if (!min2.s || !max2.s)
390
- return new Ctor(NaN);
391
- if (min2.gt(max2))
392
- throw Error(invalidArgument + max2);
393
- k = x.cmp(min2);
394
- return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
395
- };
396
- P.comparedTo = P.cmp = function(y) {
397
- var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
398
- if (!xd || !yd) {
399
- return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
400
- }
401
- if (!xd[0] || !yd[0])
402
- return xd[0] ? xs : yd[0] ? -ys : 0;
403
- if (xs !== ys)
404
- return xs;
405
- if (x.e !== y.e)
406
- return x.e > y.e ^ xs < 0 ? 1 : -1;
407
- xdL = xd.length;
408
- ydL = yd.length;
409
- for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
410
- if (xd[i] !== yd[i])
411
- return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
412
- }
413
- return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
414
- };
415
- P.cosine = P.cos = function() {
416
- var pr, rm, x = this, Ctor = x.constructor;
417
- if (!x.d)
418
- return new Ctor(NaN);
419
- if (!x.d[0])
420
- return new Ctor(1);
421
- pr = Ctor.precision;
422
- rm = Ctor.rounding;
423
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
424
- Ctor.rounding = 1;
425
- x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
426
- Ctor.precision = pr;
427
- Ctor.rounding = rm;
428
- return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
429
- };
430
- P.cubeRoot = P.cbrt = function() {
431
- var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
432
- if (!x.isFinite() || x.isZero())
433
- return new Ctor(x);
434
- external = false;
435
- s = x.s * mathpow(x.s * x, 1 / 3);
436
- if (!s || Math.abs(s) == 1 / 0) {
437
- n = digitsToString(x.d);
438
- e = x.e;
439
- if (s = (e - n.length + 1) % 3)
440
- n += s == 1 || s == -2 ? "0" : "00";
441
- s = mathpow(n, 1 / 3);
442
- e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
443
- if (s == 1 / 0) {
444
- n = "5e" + e;
445
- } else {
446
- n = s.toExponential();
447
- n = n.slice(0, n.indexOf("e") + 1) + e;
448
- }
449
- r = new Ctor(n);
450
- r.s = x.s;
451
- } else {
452
- r = new Ctor(s.toString());
453
- }
454
- sd = (e = Ctor.precision) + 3;
455
- for (; ; ) {
456
- t = r;
457
- t3 = t.times(t).times(t);
458
- t3plusx = t3.plus(x);
459
- r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
460
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
461
- n = n.slice(sd - 3, sd + 1);
462
- if (n == "9999" || !rep && n == "4999") {
463
- if (!rep) {
464
- finalise(t, e + 1, 0);
465
- if (t.times(t).times(t).eq(x)) {
466
- r = t;
467
- break;
468
- }
469
- }
470
- sd += 4;
471
- rep = 1;
472
- } else {
473
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
474
- finalise(r, e + 1, 1);
475
- m = !r.times(r).times(r).eq(x);
476
- }
477
- break;
478
- }
479
- }
480
- }
481
- external = true;
482
- return finalise(r, e, Ctor.rounding, m);
483
- };
484
- P.decimalPlaces = P.dp = function() {
485
- var w, d = this.d, n = NaN;
486
- if (d) {
487
- w = d.length - 1;
488
- n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
489
- w = d[w];
490
- if (w)
491
- for (; w % 10 == 0; w /= 10)
492
- n--;
493
- if (n < 0)
494
- n = 0;
495
- }
496
- return n;
497
- };
498
- P.dividedBy = P.div = function(y) {
499
- return divide(this, new this.constructor(y));
500
- };
501
- P.dividedToIntegerBy = P.divToInt = function(y) {
502
- var x = this, Ctor = x.constructor;
503
- return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
504
- };
505
- P.equals = P.eq = function(y) {
506
- return this.cmp(y) === 0;
507
- };
508
- P.floor = function() {
509
- return finalise(new this.constructor(this), this.e + 1, 3);
510
- };
511
- P.greaterThan = P.gt = function(y) {
512
- return this.cmp(y) > 0;
513
- };
514
- P.greaterThanOrEqualTo = P.gte = function(y) {
515
- var k = this.cmp(y);
516
- return k == 1 || k === 0;
517
- };
518
- P.hyperbolicCosine = P.cosh = function() {
519
- var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
520
- if (!x.isFinite())
521
- return new Ctor(x.s ? 1 / 0 : NaN);
522
- if (x.isZero())
523
- return one;
524
- pr = Ctor.precision;
525
- rm = Ctor.rounding;
526
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
527
- Ctor.rounding = 1;
528
- len = x.d.length;
529
- if (len < 32) {
530
- k = Math.ceil(len / 3);
531
- n = (1 / tinyPow(4, k)).toString();
532
- } else {
533
- k = 16;
534
- n = "2.3283064365386962890625e-10";
535
- }
536
- x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
537
- var cosh2_x, i = k, d8 = new Ctor(8);
538
- for (; i--; ) {
539
- cosh2_x = x.times(x);
540
- x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
541
- }
542
- return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
543
- };
544
- P.hyperbolicSine = P.sinh = function() {
545
- var k, pr, rm, len, x = this, Ctor = x.constructor;
546
- if (!x.isFinite() || x.isZero())
547
- return new Ctor(x);
548
- pr = Ctor.precision;
549
- rm = Ctor.rounding;
550
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
551
- Ctor.rounding = 1;
552
- len = x.d.length;
553
- if (len < 3) {
554
- x = taylorSeries(Ctor, 2, x, x, true);
555
- } else {
556
- k = 1.4 * Math.sqrt(len);
557
- k = k > 16 ? 16 : k | 0;
558
- x = x.times(1 / tinyPow(5, k));
559
- x = taylorSeries(Ctor, 2, x, x, true);
560
- var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
561
- for (; k--; ) {
562
- sinh2_x = x.times(x);
563
- x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
564
- }
565
- }
566
- Ctor.precision = pr;
567
- Ctor.rounding = rm;
568
- return finalise(x, pr, rm, true);
569
- };
570
- P.hyperbolicTangent = P.tanh = function() {
571
- var pr, rm, x = this, Ctor = x.constructor;
572
- if (!x.isFinite())
573
- return new Ctor(x.s);
574
- if (x.isZero())
575
- return new Ctor(x);
576
- pr = Ctor.precision;
577
- rm = Ctor.rounding;
578
- Ctor.precision = pr + 7;
579
- Ctor.rounding = 1;
580
- return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
581
- };
582
- P.inverseCosine = P.acos = function() {
583
- var halfPi, x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
584
- if (k !== -1) {
585
- return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
586
- }
587
- if (x.isZero())
588
- return getPi(Ctor, pr + 4, rm).times(0.5);
589
- Ctor.precision = pr + 6;
590
- Ctor.rounding = 1;
591
- x = x.asin();
592
- halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
593
- Ctor.precision = pr;
594
- Ctor.rounding = rm;
595
- return halfPi.minus(x);
596
- };
597
- P.inverseHyperbolicCosine = P.acosh = function() {
598
- var pr, rm, x = this, Ctor = x.constructor;
599
- if (x.lte(1))
600
- return new Ctor(x.eq(1) ? 0 : NaN);
601
- if (!x.isFinite())
602
- return new Ctor(x);
603
- pr = Ctor.precision;
604
- rm = Ctor.rounding;
605
- Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
606
- Ctor.rounding = 1;
607
- external = false;
608
- x = x.times(x).minus(1).sqrt().plus(x);
609
- external = true;
610
- Ctor.precision = pr;
611
- Ctor.rounding = rm;
612
- return x.ln();
613
- };
614
- P.inverseHyperbolicSine = P.asinh = function() {
615
- var pr, rm, x = this, Ctor = x.constructor;
616
- if (!x.isFinite() || x.isZero())
617
- return new Ctor(x);
618
- pr = Ctor.precision;
619
- rm = Ctor.rounding;
620
- Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
621
- Ctor.rounding = 1;
622
- external = false;
623
- x = x.times(x).plus(1).sqrt().plus(x);
624
- external = true;
625
- Ctor.precision = pr;
626
- Ctor.rounding = rm;
627
- return x.ln();
628
- };
629
- P.inverseHyperbolicTangent = P.atanh = function() {
630
- var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
631
- if (!x.isFinite())
632
- return new Ctor(NaN);
633
- if (x.e >= 0)
634
- return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
635
- pr = Ctor.precision;
636
- rm = Ctor.rounding;
637
- xsd = x.sd();
638
- if (Math.max(xsd, pr) < 2 * -x.e - 1)
639
- return finalise(new Ctor(x), pr, rm, true);
640
- Ctor.precision = wpr = xsd - x.e;
641
- x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
642
- Ctor.precision = pr + 4;
643
- Ctor.rounding = 1;
644
- x = x.ln();
645
- Ctor.precision = pr;
646
- Ctor.rounding = rm;
647
- return x.times(0.5);
648
- };
649
- P.inverseSine = P.asin = function() {
650
- var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
651
- if (x.isZero())
652
- return new Ctor(x);
653
- k = x.abs().cmp(1);
654
- pr = Ctor.precision;
655
- rm = Ctor.rounding;
656
- if (k !== -1) {
657
- if (k === 0) {
658
- halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
659
- halfPi.s = x.s;
660
- return halfPi;
661
- }
662
- return new Ctor(NaN);
663
- }
664
- Ctor.precision = pr + 6;
665
- Ctor.rounding = 1;
666
- x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
667
- Ctor.precision = pr;
668
- Ctor.rounding = rm;
669
- return x.times(2);
670
- };
671
- P.inverseTangent = P.atan = function() {
672
- var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
673
- if (!x.isFinite()) {
674
- if (!x.s)
675
- return new Ctor(NaN);
676
- if (pr + 4 <= PI_PRECISION) {
677
- r = getPi(Ctor, pr + 4, rm).times(0.5);
678
- r.s = x.s;
679
- return r;
680
- }
681
- } else if (x.isZero()) {
682
- return new Ctor(x);
683
- } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
684
- r = getPi(Ctor, pr + 4, rm).times(0.25);
685
- r.s = x.s;
686
- return r;
687
- }
688
- Ctor.precision = wpr = pr + 10;
689
- Ctor.rounding = 1;
690
- k = Math.min(28, wpr / LOG_BASE + 2 | 0);
691
- for (i = k; i; --i)
692
- x = x.div(x.times(x).plus(1).sqrt().plus(1));
693
- external = false;
694
- j = Math.ceil(wpr / LOG_BASE);
695
- n = 1;
696
- x2 = x.times(x);
697
- r = new Ctor(x);
698
- px = x;
699
- for (; i !== -1; ) {
700
- px = px.times(x2);
701
- t = r.minus(px.div(n += 2));
702
- px = px.times(x2);
703
- r = t.plus(px.div(n += 2));
704
- if (r.d[j] !== void 0)
705
- for (i = j; r.d[i] === t.d[i] && i--; )
706
- ;
707
- }
708
- if (k)
709
- r = r.times(2 << k - 1);
710
- external = true;
711
- return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
712
- };
713
- P.isFinite = function() {
714
- return !!this.d;
715
- };
716
- P.isInteger = P.isInt = function() {
717
- return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
718
- };
719
- P.isNaN = function() {
720
- return !this.s;
721
- };
722
- P.isNegative = P.isNeg = function() {
723
- return this.s < 0;
724
- };
725
- P.isPositive = P.isPos = function() {
726
- return this.s > 0;
727
- };
728
- P.isZero = function() {
729
- return !!this.d && this.d[0] === 0;
730
- };
731
- P.lessThan = P.lt = function(y) {
732
- return this.cmp(y) < 0;
733
- };
734
- P.lessThanOrEqualTo = P.lte = function(y) {
735
- return this.cmp(y) < 1;
736
- };
737
- P.logarithm = P.log = function(base) {
738
- var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
739
- if (base == null) {
740
- base = new Ctor(10);
741
- isBase10 = true;
742
- } else {
743
- base = new Ctor(base);
744
- d = base.d;
745
- if (base.s < 0 || !d || !d[0] || base.eq(1))
746
- return new Ctor(NaN);
747
- isBase10 = base.eq(10);
748
- }
749
- d = arg.d;
750
- if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
751
- return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
752
- }
753
- if (isBase10) {
754
- if (d.length > 1) {
755
- inf = true;
756
- } else {
757
- for (k = d[0]; k % 10 === 0; )
758
- k /= 10;
759
- inf = k !== 1;
760
- }
761
- }
762
- external = false;
763
- sd = pr + guard;
764
- num = naturalLogarithm(arg, sd);
765
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
766
- r = divide(num, denominator, sd, 1);
767
- if (checkRoundingDigits(r.d, k = pr, rm)) {
768
- do {
769
- sd += 10;
770
- num = naturalLogarithm(arg, sd);
771
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
772
- r = divide(num, denominator, sd, 1);
773
- if (!inf) {
774
- if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
775
- r = finalise(r, pr + 1, 0);
776
- }
777
- break;
778
- }
779
- } while (checkRoundingDigits(r.d, k += 10, rm));
780
- }
781
- external = true;
782
- return finalise(r, pr, rm);
783
- };
784
- P.minus = P.sub = function(y) {
785
- var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
786
- y = new Ctor(y);
787
- if (!x.d || !y.d) {
788
- if (!x.s || !y.s)
789
- y = new Ctor(NaN);
790
- else if (x.d)
791
- y.s = -y.s;
792
- else
793
- y = new Ctor(y.d || x.s !== y.s ? x : NaN);
794
- return y;
795
- }
796
- if (x.s != y.s) {
797
- y.s = -y.s;
798
- return x.plus(y);
799
- }
800
- xd = x.d;
801
- yd = y.d;
802
- pr = Ctor.precision;
803
- rm = Ctor.rounding;
804
- if (!xd[0] || !yd[0]) {
805
- if (yd[0])
806
- y.s = -y.s;
807
- else if (xd[0])
808
- y = new Ctor(x);
809
- else
810
- return new Ctor(rm === 3 ? -0 : 0);
811
- return external ? finalise(y, pr, rm) : y;
812
- }
813
- e = mathfloor(y.e / LOG_BASE);
814
- xe = mathfloor(x.e / LOG_BASE);
815
- xd = xd.slice();
816
- k = xe - e;
817
- if (k) {
818
- xLTy = k < 0;
819
- if (xLTy) {
820
- d = xd;
821
- k = -k;
822
- len = yd.length;
823
- } else {
824
- d = yd;
825
- e = xe;
826
- len = xd.length;
827
- }
828
- i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
829
- if (k > i) {
830
- k = i;
831
- d.length = 1;
832
- }
833
- d.reverse();
834
- for (i = k; i--; )
835
- d.push(0);
836
- d.reverse();
837
- } else {
838
- i = xd.length;
839
- len = yd.length;
840
- xLTy = i < len;
841
- if (xLTy)
842
- len = i;
843
- for (i = 0; i < len; i++) {
844
- if (xd[i] != yd[i]) {
845
- xLTy = xd[i] < yd[i];
846
- break;
847
- }
848
- }
849
- k = 0;
850
- }
851
- if (xLTy) {
852
- d = xd;
853
- xd = yd;
854
- yd = d;
855
- y.s = -y.s;
856
- }
857
- len = xd.length;
858
- for (i = yd.length - len; i > 0; --i)
859
- xd[len++] = 0;
860
- for (i = yd.length; i > k; ) {
861
- if (xd[--i] < yd[i]) {
862
- for (j = i; j && xd[--j] === 0; )
863
- xd[j] = BASE - 1;
864
- --xd[j];
865
- xd[i] += BASE;
866
- }
867
- xd[i] -= yd[i];
868
- }
869
- for (; xd[--len] === 0; )
870
- xd.pop();
871
- for (; xd[0] === 0; xd.shift())
872
- --e;
873
- if (!xd[0])
874
- return new Ctor(rm === 3 ? -0 : 0);
875
- y.d = xd;
876
- y.e = getBase10Exponent(xd, e);
877
- return external ? finalise(y, pr, rm) : y;
878
- };
879
- P.modulo = P.mod = function(y) {
880
- var q, x = this, Ctor = x.constructor;
881
- y = new Ctor(y);
882
- if (!x.d || !y.s || y.d && !y.d[0])
883
- return new Ctor(NaN);
884
- if (!y.d || x.d && !x.d[0]) {
885
- return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
886
- }
887
- external = false;
888
- if (Ctor.modulo == 9) {
889
- q = divide(x, y.abs(), 0, 3, 1);
890
- q.s *= y.s;
891
- } else {
892
- q = divide(x, y, 0, Ctor.modulo, 1);
893
- }
894
- q = q.times(y);
895
- external = true;
896
- return x.minus(q);
897
- };
898
- P.naturalExponential = P.exp = function() {
899
- return naturalExponential(this);
900
- };
901
- P.naturalLogarithm = P.ln = function() {
902
- return naturalLogarithm(this);
903
- };
904
- P.negated = P.neg = function() {
905
- var x = new this.constructor(this);
906
- x.s = -x.s;
907
- return finalise(x);
908
- };
909
- P.plus = P.add = function(y) {
910
- var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
911
- y = new Ctor(y);
912
- if (!x.d || !y.d) {
913
- if (!x.s || !y.s)
914
- y = new Ctor(NaN);
915
- else if (!x.d)
916
- y = new Ctor(y.d || x.s === y.s ? x : NaN);
917
- return y;
918
- }
919
- if (x.s != y.s) {
920
- y.s = -y.s;
921
- return x.minus(y);
922
- }
923
- xd = x.d;
924
- yd = y.d;
925
- pr = Ctor.precision;
926
- rm = Ctor.rounding;
927
- if (!xd[0] || !yd[0]) {
928
- if (!yd[0])
929
- y = new Ctor(x);
930
- return external ? finalise(y, pr, rm) : y;
931
- }
932
- k = mathfloor(x.e / LOG_BASE);
933
- e = mathfloor(y.e / LOG_BASE);
934
- xd = xd.slice();
935
- i = k - e;
936
- if (i) {
937
- if (i < 0) {
938
- d = xd;
939
- i = -i;
940
- len = yd.length;
941
- } else {
942
- d = yd;
943
- e = k;
944
- len = xd.length;
945
- }
946
- k = Math.ceil(pr / LOG_BASE);
947
- len = k > len ? k + 1 : len + 1;
948
- if (i > len) {
949
- i = len;
950
- d.length = 1;
951
- }
952
- d.reverse();
953
- for (; i--; )
954
- d.push(0);
955
- d.reverse();
956
- }
957
- len = xd.length;
958
- i = yd.length;
959
- if (len - i < 0) {
960
- i = len;
961
- d = yd;
962
- yd = xd;
963
- xd = d;
964
- }
965
- for (carry = 0; i; ) {
966
- carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
967
- xd[i] %= BASE;
968
- }
969
- if (carry) {
970
- xd.unshift(carry);
971
- ++e;
972
- }
973
- for (len = xd.length; xd[--len] == 0; )
974
- xd.pop();
975
- y.d = xd;
976
- y.e = getBase10Exponent(xd, e);
977
- return external ? finalise(y, pr, rm) : y;
978
- };
979
- P.precision = P.sd = function(z) {
980
- var k, x = this;
981
- if (z !== void 0 && z !== !!z && z !== 1 && z !== 0)
982
- throw Error(invalidArgument + z);
983
- if (x.d) {
984
- k = getPrecision(x.d);
985
- if (z && x.e + 1 > k)
986
- k = x.e + 1;
987
- } else {
988
- k = NaN;
989
- }
990
- return k;
991
- };
992
- P.round = function() {
993
- var x = this, Ctor = x.constructor;
994
- return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
995
- };
996
- P.sine = P.sin = function() {
997
- var pr, rm, x = this, Ctor = x.constructor;
998
- if (!x.isFinite())
999
- return new Ctor(NaN);
1000
- if (x.isZero())
1001
- return new Ctor(x);
1002
- pr = Ctor.precision;
1003
- rm = Ctor.rounding;
1004
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
1005
- Ctor.rounding = 1;
1006
- x = sine(Ctor, toLessThanHalfPi(Ctor, x));
1007
- Ctor.precision = pr;
1008
- Ctor.rounding = rm;
1009
- return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
1010
- };
1011
- P.squareRoot = P.sqrt = function() {
1012
- var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
1013
- if (s !== 1 || !d || !d[0]) {
1014
- return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
1015
- }
1016
- external = false;
1017
- s = Math.sqrt(+x);
1018
- if (s == 0 || s == 1 / 0) {
1019
- n = digitsToString(d);
1020
- if ((n.length + e) % 2 == 0)
1021
- n += "0";
1022
- s = Math.sqrt(n);
1023
- e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
1024
- if (s == 1 / 0) {
1025
- n = "5e" + e;
1026
- } else {
1027
- n = s.toExponential();
1028
- n = n.slice(0, n.indexOf("e") + 1) + e;
1029
- }
1030
- r = new Ctor(n);
1031
- } else {
1032
- r = new Ctor(s.toString());
1033
- }
1034
- sd = (e = Ctor.precision) + 3;
1035
- for (; ; ) {
1036
- t = r;
1037
- r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
1038
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
1039
- n = n.slice(sd - 3, sd + 1);
1040
- if (n == "9999" || !rep && n == "4999") {
1041
- if (!rep) {
1042
- finalise(t, e + 1, 0);
1043
- if (t.times(t).eq(x)) {
1044
- r = t;
1045
- break;
1046
- }
1047
- }
1048
- sd += 4;
1049
- rep = 1;
1050
- } else {
1051
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
1052
- finalise(r, e + 1, 1);
1053
- m = !r.times(r).eq(x);
1054
- }
1055
- break;
1056
- }
1057
- }
1058
- }
1059
- external = true;
1060
- return finalise(r, e, Ctor.rounding, m);
1061
- };
1062
- P.tangent = P.tan = function() {
1063
- var pr, rm, x = this, Ctor = x.constructor;
1064
- if (!x.isFinite())
1065
- return new Ctor(NaN);
1066
- if (x.isZero())
1067
- return new Ctor(x);
1068
- pr = Ctor.precision;
1069
- rm = Ctor.rounding;
1070
- Ctor.precision = pr + 10;
1071
- Ctor.rounding = 1;
1072
- x = x.sin();
1073
- x.s = 1;
1074
- x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
1075
- Ctor.precision = pr;
1076
- Ctor.rounding = rm;
1077
- return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
1078
- };
1079
- P.times = P.mul = function(y) {
1080
- var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
1081
- y.s *= x.s;
1082
- if (!xd || !xd[0] || !yd || !yd[0]) {
1083
- return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
1084
- }
1085
- e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
1086
- xdL = xd.length;
1087
- ydL = yd.length;
1088
- if (xdL < ydL) {
1089
- r = xd;
1090
- xd = yd;
1091
- yd = r;
1092
- rL = xdL;
1093
- xdL = ydL;
1094
- ydL = rL;
1095
- }
1096
- r = [];
1097
- rL = xdL + ydL;
1098
- for (i = rL; i--; )
1099
- r.push(0);
1100
- for (i = ydL; --i >= 0; ) {
1101
- carry = 0;
1102
- for (k = xdL + i; k > i; ) {
1103
- t = r[k] + yd[i] * xd[k - i - 1] + carry;
1104
- r[k--] = t % BASE | 0;
1105
- carry = t / BASE | 0;
1106
- }
1107
- r[k] = (r[k] + carry) % BASE | 0;
1108
- }
1109
- for (; !r[--rL]; )
1110
- r.pop();
1111
- if (carry)
1112
- ++e;
1113
- else
1114
- r.shift();
1115
- y.d = r;
1116
- y.e = getBase10Exponent(r, e);
1117
- return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
1118
- };
1119
- P.toBinary = function(sd, rm) {
1120
- return toStringBinary(this, 2, sd, rm);
1121
- };
1122
- P.toDecimalPlaces = P.toDP = function(dp, rm) {
1123
- var x = this, Ctor = x.constructor;
1124
- x = new Ctor(x);
1125
- if (dp === void 0)
1126
- return x;
1127
- checkInt32(dp, 0, MAX_DIGITS);
1128
- if (rm === void 0)
1129
- rm = Ctor.rounding;
1130
- else
1131
- checkInt32(rm, 0, 8);
1132
- return finalise(x, dp + x.e + 1, rm);
1133
- };
1134
- P.toExponential = function(dp, rm) {
1135
- var str, x = this, Ctor = x.constructor;
1136
- if (dp === void 0) {
1137
- str = finiteToString(x, true);
1138
- } else {
1139
- checkInt32(dp, 0, MAX_DIGITS);
1140
- if (rm === void 0)
1141
- rm = Ctor.rounding;
1142
- else
1143
- checkInt32(rm, 0, 8);
1144
- x = finalise(new Ctor(x), dp + 1, rm);
1145
- str = finiteToString(x, true, dp + 1);
1146
- }
1147
- return x.isNeg() && !x.isZero() ? "-" + str : str;
1148
- };
1149
- P.toFixed = function(dp, rm) {
1150
- var str, y, x = this, Ctor = x.constructor;
1151
- if (dp === void 0) {
1152
- str = finiteToString(x);
1153
- } else {
1154
- checkInt32(dp, 0, MAX_DIGITS);
1155
- if (rm === void 0)
1156
- rm = Ctor.rounding;
1157
- else
1158
- checkInt32(rm, 0, 8);
1159
- y = finalise(new Ctor(x), dp + x.e + 1, rm);
1160
- str = finiteToString(y, false, dp + y.e + 1);
1161
- }
1162
- return x.isNeg() && !x.isZero() ? "-" + str : str;
1163
- };
1164
- P.toFraction = function(maxD) {
1165
- var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
1166
- if (!xd)
1167
- return new Ctor(x);
1168
- n1 = d0 = new Ctor(1);
1169
- d1 = n0 = new Ctor(0);
1170
- d = new Ctor(d1);
1171
- e = d.e = getPrecision(xd) - x.e - 1;
1172
- k = e % LOG_BASE;
1173
- d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
1174
- if (maxD == null) {
1175
- maxD = e > 0 ? d : n1;
1176
- } else {
1177
- n = new Ctor(maxD);
1178
- if (!n.isInt() || n.lt(n1))
1179
- throw Error(invalidArgument + n);
1180
- maxD = n.gt(d) ? e > 0 ? d : n1 : n;
1181
- }
1182
- external = false;
1183
- n = new Ctor(digitsToString(xd));
1184
- pr = Ctor.precision;
1185
- Ctor.precision = e = xd.length * LOG_BASE * 2;
1186
- for (; ; ) {
1187
- q = divide(n, d, 0, 1, 1);
1188
- d2 = d0.plus(q.times(d1));
1189
- if (d2.cmp(maxD) == 1)
1190
- break;
1191
- d0 = d1;
1192
- d1 = d2;
1193
- d2 = n1;
1194
- n1 = n0.plus(q.times(d2));
1195
- n0 = d2;
1196
- d2 = d;
1197
- d = n.minus(q.times(d2));
1198
- n = d2;
1199
- }
1200
- d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
1201
- n0 = n0.plus(d2.times(n1));
1202
- d0 = d0.plus(d2.times(d1));
1203
- n0.s = n1.s = x.s;
1204
- r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
1205
- Ctor.precision = pr;
1206
- external = true;
1207
- return r;
1208
- };
1209
- P.toHexadecimal = P.toHex = function(sd, rm) {
1210
- return toStringBinary(this, 16, sd, rm);
1211
- };
1212
- P.toNearest = function(y, rm) {
1213
- var x = this, Ctor = x.constructor;
1214
- x = new Ctor(x);
1215
- if (y == null) {
1216
- if (!x.d)
1217
- return x;
1218
- y = new Ctor(1);
1219
- rm = Ctor.rounding;
1220
- } else {
1221
- y = new Ctor(y);
1222
- if (rm === void 0) {
1223
- rm = Ctor.rounding;
1224
- } else {
1225
- checkInt32(rm, 0, 8);
1226
- }
1227
- if (!x.d)
1228
- return y.s ? x : y;
1229
- if (!y.d) {
1230
- if (y.s)
1231
- y.s = x.s;
1232
- return y;
1233
- }
1234
- }
1235
- if (y.d[0]) {
1236
- external = false;
1237
- x = divide(x, y, 0, rm, 1).times(y);
1238
- external = true;
1239
- finalise(x);
1240
- } else {
1241
- y.s = x.s;
1242
- x = y;
1243
- }
1244
- return x;
1245
- };
1246
- P.toNumber = function() {
1247
- return +this;
1248
- };
1249
- P.toOctal = function(sd, rm) {
1250
- return toStringBinary(this, 8, sd, rm);
1251
- };
1252
- P.toPower = P.pow = function(y) {
1253
- var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
1254
- if (!x.d || !y.d || !x.d[0] || !y.d[0])
1255
- return new Ctor(mathpow(+x, yn));
1256
- x = new Ctor(x);
1257
- if (x.eq(1))
1258
- return x;
1259
- pr = Ctor.precision;
1260
- rm = Ctor.rounding;
1261
- if (y.eq(1))
1262
- return finalise(x, pr, rm);
1263
- e = mathfloor(y.e / LOG_BASE);
1264
- if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
1265
- r = intPow(Ctor, x, k, pr);
1266
- return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
1267
- }
1268
- s = x.s;
1269
- if (s < 0) {
1270
- if (e < y.d.length - 1)
1271
- return new Ctor(NaN);
1272
- if ((y.d[e] & 1) == 0)
1273
- s = 1;
1274
- if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
1275
- x.s = s;
1276
- return x;
1277
- }
1278
- }
1279
- k = mathpow(+x, yn);
1280
- e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
1281
- if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
1282
- return new Ctor(e > 0 ? s / 0 : 0);
1283
- external = false;
1284
- Ctor.rounding = x.s = 1;
1285
- k = Math.min(12, (e + "").length);
1286
- r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
1287
- if (r.d) {
1288
- r = finalise(r, pr + 5, 1);
1289
- if (checkRoundingDigits(r.d, pr, rm)) {
1290
- e = pr + 10;
1291
- r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
1292
- if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
1293
- r = finalise(r, pr + 1, 0);
1294
- }
1295
- }
1296
- }
1297
- r.s = s;
1298
- external = true;
1299
- Ctor.rounding = rm;
1300
- return finalise(r, pr, rm);
1301
- };
1302
- P.toPrecision = function(sd, rm) {
1303
- var str, x = this, Ctor = x.constructor;
1304
- if (sd === void 0) {
1305
- str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1306
- } else {
1307
- checkInt32(sd, 1, MAX_DIGITS);
1308
- if (rm === void 0)
1309
- rm = Ctor.rounding;
1310
- else
1311
- checkInt32(rm, 0, 8);
1312
- x = finalise(new Ctor(x), sd, rm);
1313
- str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
1314
- }
1315
- return x.isNeg() && !x.isZero() ? "-" + str : str;
1316
- };
1317
- P.toSignificantDigits = P.toSD = function(sd, rm) {
1318
- var x = this, Ctor = x.constructor;
1319
- if (sd === void 0) {
1320
- sd = Ctor.precision;
1321
- rm = Ctor.rounding;
1322
- } else {
1323
- checkInt32(sd, 1, MAX_DIGITS);
1324
- if (rm === void 0)
1325
- rm = Ctor.rounding;
1326
- else
1327
- checkInt32(rm, 0, 8);
1328
- }
1329
- return finalise(new Ctor(x), sd, rm);
1330
- };
1331
- P.toString = function() {
1332
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1333
- return x.isNeg() && !x.isZero() ? "-" + str : str;
1334
- };
1335
- P.truncated = P.trunc = function() {
1336
- return finalise(new this.constructor(this), this.e + 1, 1);
1337
- };
1338
- P.valueOf = P.toJSON = function() {
1339
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
1340
- return x.isNeg() ? "-" + str : str;
1341
- };
1342
- function digitsToString(d) {
1343
- var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
1344
- if (indexOfLastWord > 0) {
1345
- str += w;
1346
- for (i = 1; i < indexOfLastWord; i++) {
1347
- ws = d[i] + "";
1348
- k = LOG_BASE - ws.length;
1349
- if (k)
1350
- str += getZeroString(k);
1351
- str += ws;
1352
- }
1353
- w = d[i];
1354
- ws = w + "";
1355
- k = LOG_BASE - ws.length;
1356
- if (k)
1357
- str += getZeroString(k);
1358
- } else if (w === 0) {
1359
- return "0";
1360
- }
1361
- for (; w % 10 === 0; )
1362
- w /= 10;
1363
- return str + w;
1364
- }
1365
- function checkInt32(i, min2, max2) {
1366
- if (i !== ~~i || i < min2 || i > max2) {
1367
- throw Error(invalidArgument + i);
1368
- }
1369
- }
1370
- function checkRoundingDigits(d, i, rm, repeating) {
1371
- var di, k, r, rd;
1372
- for (k = d[0]; k >= 10; k /= 10)
1373
- --i;
1374
- if (--i < 0) {
1375
- i += LOG_BASE;
1376
- di = 0;
1377
- } else {
1378
- di = Math.ceil((i + 1) / LOG_BASE);
1379
- i %= LOG_BASE;
1380
- }
1381
- k = mathpow(10, LOG_BASE - i);
1382
- rd = d[di] % k | 0;
1383
- if (repeating == null) {
1384
- if (i < 3) {
1385
- if (i == 0)
1386
- rd = rd / 100 | 0;
1387
- else if (i == 1)
1388
- rd = rd / 10 | 0;
1389
- r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
1390
- } else {
1391
- r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
1392
- }
1393
- } else {
1394
- if (i < 4) {
1395
- if (i == 0)
1396
- rd = rd / 1e3 | 0;
1397
- else if (i == 1)
1398
- rd = rd / 100 | 0;
1399
- else if (i == 2)
1400
- rd = rd / 10 | 0;
1401
- r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
1402
- } else {
1403
- r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1e3 | 0) == mathpow(10, i - 3) - 1;
1404
- }
1405
- }
1406
- return r;
1407
- }
1408
- function convertBase(str, baseIn, baseOut) {
1409
- var j, arr = [0], arrL, i = 0, strL = str.length;
1410
- for (; i < strL; ) {
1411
- for (arrL = arr.length; arrL--; )
1412
- arr[arrL] *= baseIn;
1413
- arr[0] += NUMERALS.indexOf(str.charAt(i++));
1414
- for (j = 0; j < arr.length; j++) {
1415
- if (arr[j] > baseOut - 1) {
1416
- if (arr[j + 1] === void 0)
1417
- arr[j + 1] = 0;
1418
- arr[j + 1] += arr[j] / baseOut | 0;
1419
- arr[j] %= baseOut;
1420
- }
1421
- }
1422
- }
1423
- return arr.reverse();
1424
- }
1425
- function cosine(Ctor, x) {
1426
- var k, len, y;
1427
- if (x.isZero())
1428
- return x;
1429
- len = x.d.length;
1430
- if (len < 32) {
1431
- k = Math.ceil(len / 3);
1432
- y = (1 / tinyPow(4, k)).toString();
1433
- } else {
1434
- k = 16;
1435
- y = "2.3283064365386962890625e-10";
1436
- }
1437
- Ctor.precision += k;
1438
- x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
1439
- for (var i = k; i--; ) {
1440
- var cos2x = x.times(x);
1441
- x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
1442
- }
1443
- Ctor.precision -= k;
1444
- return x;
1445
- }
1446
- var divide = function() {
1447
- function multiplyInteger(x, k, base) {
1448
- var temp, carry = 0, i = x.length;
1449
- for (x = x.slice(); i--; ) {
1450
- temp = x[i] * k + carry;
1451
- x[i] = temp % base | 0;
1452
- carry = temp / base | 0;
1453
- }
1454
- if (carry)
1455
- x.unshift(carry);
1456
- return x;
1457
- }
1458
- function compare(a, b, aL, bL) {
1459
- var i, r;
1460
- if (aL != bL) {
1461
- r = aL > bL ? 1 : -1;
1462
- } else {
1463
- for (i = r = 0; i < aL; i++) {
1464
- if (a[i] != b[i]) {
1465
- r = a[i] > b[i] ? 1 : -1;
1466
- break;
1467
- }
1468
- }
1469
- }
1470
- return r;
1471
- }
1472
- function subtract(a, b, aL, base) {
1473
- var i = 0;
1474
- for (; aL--; ) {
1475
- a[aL] -= i;
1476
- i = a[aL] < b[aL] ? 1 : 0;
1477
- a[aL] = i * base + a[aL] - b[aL];
1478
- }
1479
- for (; !a[0] && a.length > 1; )
1480
- a.shift();
1481
- }
1482
- return function(x, y, pr, rm, dp, base) {
1483
- var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign2 = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
1484
- if (!xd || !xd[0] || !yd || !yd[0]) {
1485
- return new Ctor(
1486
- // Return NaN if either NaN, or both Infinity or 0.
1487
- !x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
1488
- // Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
1489
- xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
1490
- )
1491
- );
1492
- }
1493
- if (base) {
1494
- logBase = 1;
1495
- e = x.e - y.e;
1496
- } else {
1497
- base = BASE;
1498
- logBase = LOG_BASE;
1499
- e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
1500
- }
1501
- yL = yd.length;
1502
- xL = xd.length;
1503
- q = new Ctor(sign2);
1504
- qd = q.d = [];
1505
- for (i = 0; yd[i] == (xd[i] || 0); i++)
1506
- ;
1507
- if (yd[i] > (xd[i] || 0))
1508
- e--;
1509
- if (pr == null) {
1510
- sd = pr = Ctor.precision;
1511
- rm = Ctor.rounding;
1512
- } else if (dp) {
1513
- sd = pr + (x.e - y.e) + 1;
1514
- } else {
1515
- sd = pr;
1516
- }
1517
- if (sd < 0) {
1518
- qd.push(1);
1519
- more = true;
1520
- } else {
1521
- sd = sd / logBase + 2 | 0;
1522
- i = 0;
1523
- if (yL == 1) {
1524
- k = 0;
1525
- yd = yd[0];
1526
- sd++;
1527
- for (; (i < xL || k) && sd--; i++) {
1528
- t = k * base + (xd[i] || 0);
1529
- qd[i] = t / yd | 0;
1530
- k = t % yd | 0;
1531
- }
1532
- more = k || i < xL;
1533
- } else {
1534
- k = base / (yd[0] + 1) | 0;
1535
- if (k > 1) {
1536
- yd = multiplyInteger(yd, k, base);
1537
- xd = multiplyInteger(xd, k, base);
1538
- yL = yd.length;
1539
- xL = xd.length;
1540
- }
1541
- xi = yL;
1542
- rem = xd.slice(0, yL);
1543
- remL = rem.length;
1544
- for (; remL < yL; )
1545
- rem[remL++] = 0;
1546
- yz = yd.slice();
1547
- yz.unshift(0);
1548
- yd0 = yd[0];
1549
- if (yd[1] >= base / 2)
1550
- ++yd0;
1551
- do {
1552
- k = 0;
1553
- cmp = compare(yd, rem, yL, remL);
1554
- if (cmp < 0) {
1555
- rem0 = rem[0];
1556
- if (yL != remL)
1557
- rem0 = rem0 * base + (rem[1] || 0);
1558
- k = rem0 / yd0 | 0;
1559
- if (k > 1) {
1560
- if (k >= base)
1561
- k = base - 1;
1562
- prod = multiplyInteger(yd, k, base);
1563
- prodL = prod.length;
1564
- remL = rem.length;
1565
- cmp = compare(prod, rem, prodL, remL);
1566
- if (cmp == 1) {
1567
- k--;
1568
- subtract(prod, yL < prodL ? yz : yd, prodL, base);
1569
- }
1570
- } else {
1571
- if (k == 0)
1572
- cmp = k = 1;
1573
- prod = yd.slice();
1574
- }
1575
- prodL = prod.length;
1576
- if (prodL < remL)
1577
- prod.unshift(0);
1578
- subtract(rem, prod, remL, base);
1579
- if (cmp == -1) {
1580
- remL = rem.length;
1581
- cmp = compare(yd, rem, yL, remL);
1582
- if (cmp < 1) {
1583
- k++;
1584
- subtract(rem, yL < remL ? yz : yd, remL, base);
1585
- }
1586
- }
1587
- remL = rem.length;
1588
- } else if (cmp === 0) {
1589
- k++;
1590
- rem = [0];
1591
- }
1592
- qd[i++] = k;
1593
- if (cmp && rem[0]) {
1594
- rem[remL++] = xd[xi] || 0;
1595
- } else {
1596
- rem = [xd[xi]];
1597
- remL = 1;
1598
- }
1599
- } while ((xi++ < xL || rem[0] !== void 0) && sd--);
1600
- more = rem[0] !== void 0;
1601
- }
1602
- if (!qd[0])
1603
- qd.shift();
1604
- }
1605
- if (logBase == 1) {
1606
- q.e = e;
1607
- inexact = more;
1608
- } else {
1609
- for (i = 1, k = qd[0]; k >= 10; k /= 10)
1610
- i++;
1611
- q.e = i + e * logBase - 1;
1612
- finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
1613
- }
1614
- return q;
1615
- };
1616
- }();
1617
- function finalise(x, sd, rm, isTruncated) {
1618
- var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
1619
- out:
1620
- if (sd != null) {
1621
- xd = x.d;
1622
- if (!xd)
1623
- return x;
1624
- for (digits = 1, k = xd[0]; k >= 10; k /= 10)
1625
- digits++;
1626
- i = sd - digits;
1627
- if (i < 0) {
1628
- i += LOG_BASE;
1629
- j = sd;
1630
- w = xd[xdi = 0];
1631
- rd = w / mathpow(10, digits - j - 1) % 10 | 0;
1632
- } else {
1633
- xdi = Math.ceil((i + 1) / LOG_BASE);
1634
- k = xd.length;
1635
- if (xdi >= k) {
1636
- if (isTruncated) {
1637
- for (; k++ <= xdi; )
1638
- xd.push(0);
1639
- w = rd = 0;
1640
- digits = 1;
1641
- i %= LOG_BASE;
1642
- j = i - LOG_BASE + 1;
1643
- } else {
1644
- break out;
1645
- }
1646
- } else {
1647
- w = k = xd[xdi];
1648
- for (digits = 1; k >= 10; k /= 10)
1649
- digits++;
1650
- i %= LOG_BASE;
1651
- j = i - LOG_BASE + digits;
1652
- rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
1653
- }
1654
- }
1655
- isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
1656
- roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
1657
- (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
1658
- if (sd < 1 || !xd[0]) {
1659
- xd.length = 0;
1660
- if (roundUp) {
1661
- sd -= x.e + 1;
1662
- xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
1663
- x.e = -sd || 0;
1664
- } else {
1665
- xd[0] = x.e = 0;
1666
- }
1667
- return x;
1668
- }
1669
- if (i == 0) {
1670
- xd.length = xdi;
1671
- k = 1;
1672
- xdi--;
1673
- } else {
1674
- xd.length = xdi + 1;
1675
- k = mathpow(10, LOG_BASE - i);
1676
- xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
1677
- }
1678
- if (roundUp) {
1679
- for (; ; ) {
1680
- if (xdi == 0) {
1681
- for (i = 1, j = xd[0]; j >= 10; j /= 10)
1682
- i++;
1683
- j = xd[0] += k;
1684
- for (k = 1; j >= 10; j /= 10)
1685
- k++;
1686
- if (i != k) {
1687
- x.e++;
1688
- if (xd[0] == BASE)
1689
- xd[0] = 1;
1690
- }
1691
- break;
1692
- } else {
1693
- xd[xdi] += k;
1694
- if (xd[xdi] != BASE)
1695
- break;
1696
- xd[xdi--] = 0;
1697
- k = 1;
1698
- }
1699
- }
1700
- }
1701
- for (i = xd.length; xd[--i] === 0; )
1702
- xd.pop();
1703
- }
1704
- if (external) {
1705
- if (x.e > Ctor.maxE) {
1706
- x.d = null;
1707
- x.e = NaN;
1708
- } else if (x.e < Ctor.minE) {
1709
- x.e = 0;
1710
- x.d = [0];
1711
- }
1712
- }
1713
- return x;
1714
- }
1715
- function finiteToString(x, isExp, sd) {
1716
- if (!x.isFinite())
1717
- return nonFiniteToString(x);
1718
- var k, e = x.e, str = digitsToString(x.d), len = str.length;
1719
- if (isExp) {
1720
- if (sd && (k = sd - len) > 0) {
1721
- str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
1722
- } else if (len > 1) {
1723
- str = str.charAt(0) + "." + str.slice(1);
1724
- }
1725
- str = str + (x.e < 0 ? "e" : "e+") + x.e;
1726
- } else if (e < 0) {
1727
- str = "0." + getZeroString(-e - 1) + str;
1728
- if (sd && (k = sd - len) > 0)
1729
- str += getZeroString(k);
1730
- } else if (e >= len) {
1731
- str += getZeroString(e + 1 - len);
1732
- if (sd && (k = sd - e - 1) > 0)
1733
- str = str + "." + getZeroString(k);
1734
- } else {
1735
- if ((k = e + 1) < len)
1736
- str = str.slice(0, k) + "." + str.slice(k);
1737
- if (sd && (k = sd - len) > 0) {
1738
- if (e + 1 === len)
1739
- str += ".";
1740
- str += getZeroString(k);
1741
- }
1742
- }
1743
- return str;
1744
- }
1745
- function getBase10Exponent(digits, e) {
1746
- var w = digits[0];
1747
- for (e *= LOG_BASE; w >= 10; w /= 10)
1748
- e++;
1749
- return e;
1750
- }
1751
- function getLn10(Ctor, sd, pr) {
1752
- if (sd > LN10_PRECISION) {
1753
- external = true;
1754
- if (pr)
1755
- Ctor.precision = pr;
1756
- throw Error(precisionLimitExceeded);
1757
- }
1758
- return finalise(new Ctor(LN10), sd, 1, true);
1759
- }
1760
- function getPi(Ctor, sd, rm) {
1761
- if (sd > PI_PRECISION)
1762
- throw Error(precisionLimitExceeded);
1763
- return finalise(new Ctor(PI), sd, rm, true);
1764
- }
1765
- function getPrecision(digits) {
1766
- var w = digits.length - 1, len = w * LOG_BASE + 1;
1767
- w = digits[w];
1768
- if (w) {
1769
- for (; w % 10 == 0; w /= 10)
1770
- len--;
1771
- for (w = digits[0]; w >= 10; w /= 10)
1772
- len++;
1773
- }
1774
- return len;
1775
- }
1776
- function getZeroString(k) {
1777
- var zs = "";
1778
- for (; k--; )
1779
- zs += "0";
1780
- return zs;
1781
- }
1782
- function intPow(Ctor, x, n, pr) {
1783
- var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
1784
- external = false;
1785
- for (; ; ) {
1786
- if (n % 2) {
1787
- r = r.times(x);
1788
- if (truncate(r.d, k))
1789
- isTruncated = true;
1790
- }
1791
- n = mathfloor(n / 2);
1792
- if (n === 0) {
1793
- n = r.d.length - 1;
1794
- if (isTruncated && r.d[n] === 0)
1795
- ++r.d[n];
1796
- break;
1797
- }
1798
- x = x.times(x);
1799
- truncate(x.d, k);
1800
- }
1801
- external = true;
1802
- return r;
1803
- }
1804
- function isOdd(n) {
1805
- return n.d[n.d.length - 1] & 1;
1806
- }
1807
- function maxOrMin(Ctor, args, ltgt) {
1808
- var y, x = new Ctor(args[0]), i = 0;
1809
- for (; ++i < args.length; ) {
1810
- y = new Ctor(args[i]);
1811
- if (!y.s) {
1812
- x = y;
1813
- break;
1814
- } else if (x[ltgt](y)) {
1815
- x = y;
1816
- }
1817
- }
1818
- return x;
1819
- }
1820
- function naturalExponential(x, sd) {
1821
- var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1822
- if (!x.d || !x.d[0] || x.e > 17) {
1823
- return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
1824
- }
1825
- if (sd == null) {
1826
- external = false;
1827
- wpr = pr;
1828
- } else {
1829
- wpr = sd;
1830
- }
1831
- t = new Ctor(0.03125);
1832
- while (x.e > -2) {
1833
- x = x.times(t);
1834
- k += 5;
1835
- }
1836
- guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
1837
- wpr += guard;
1838
- denominator = pow2 = sum2 = new Ctor(1);
1839
- Ctor.precision = wpr;
1840
- for (; ; ) {
1841
- pow2 = finalise(pow2.times(x), wpr, 1);
1842
- denominator = denominator.times(++i);
1843
- t = sum2.plus(divide(pow2, denominator, wpr, 1));
1844
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1845
- j = k;
1846
- while (j--)
1847
- sum2 = finalise(sum2.times(sum2), wpr, 1);
1848
- if (sd == null) {
1849
- if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1850
- Ctor.precision = wpr += 10;
1851
- denominator = pow2 = t = new Ctor(1);
1852
- i = 0;
1853
- rep++;
1854
- } else {
1855
- return finalise(sum2, Ctor.precision = pr, rm, external = true);
1856
- }
1857
- } else {
1858
- Ctor.precision = pr;
1859
- return sum2;
1860
- }
1861
- }
1862
- sum2 = t;
1863
- }
1864
- }
1865
- function naturalLogarithm(y, sd) {
1866
- var c, c0, denominator, e, numerator, rep, sum2, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1867
- if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
1868
- return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
1869
- }
1870
- if (sd == null) {
1871
- external = false;
1872
- wpr = pr;
1873
- } else {
1874
- wpr = sd;
1875
- }
1876
- Ctor.precision = wpr += guard;
1877
- c = digitsToString(xd);
1878
- c0 = c.charAt(0);
1879
- if (Math.abs(e = x.e) < 15e14) {
1880
- while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
1881
- x = x.times(y);
1882
- c = digitsToString(x.d);
1883
- c0 = c.charAt(0);
1884
- n++;
1885
- }
1886
- e = x.e;
1887
- if (c0 > 1) {
1888
- x = new Ctor("0." + c);
1889
- e++;
1890
- } else {
1891
- x = new Ctor(c0 + "." + c.slice(1));
1892
- }
1893
- } else {
1894
- t = getLn10(Ctor, wpr + 2, pr).times(e + "");
1895
- x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
1896
- Ctor.precision = pr;
1897
- return sd == null ? finalise(x, pr, rm, external = true) : x;
1898
- }
1899
- x1 = x;
1900
- sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
1901
- x2 = finalise(x.times(x), wpr, 1);
1902
- denominator = 3;
1903
- for (; ; ) {
1904
- numerator = finalise(numerator.times(x2), wpr, 1);
1905
- t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
1906
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1907
- sum2 = sum2.times(2);
1908
- if (e !== 0)
1909
- sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
1910
- sum2 = divide(sum2, new Ctor(n), wpr, 1);
1911
- if (sd == null) {
1912
- if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1913
- Ctor.precision = wpr += guard;
1914
- t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
1915
- x2 = finalise(x.times(x), wpr, 1);
1916
- denominator = rep = 1;
1917
- } else {
1918
- return finalise(sum2, Ctor.precision = pr, rm, external = true);
1919
- }
1920
- } else {
1921
- Ctor.precision = pr;
1922
- return sum2;
1923
- }
1924
- }
1925
- sum2 = t;
1926
- denominator += 2;
1927
- }
1928
- }
1929
- function nonFiniteToString(x) {
1930
- return String(x.s * x.s / 0);
1931
- }
1932
- function parseDecimal(x, str) {
1933
- var e, i, len;
1934
- if ((e = str.indexOf(".")) > -1)
1935
- str = str.replace(".", "");
1936
- if ((i = str.search(/e/i)) > 0) {
1937
- if (e < 0)
1938
- e = i;
1939
- e += +str.slice(i + 1);
1940
- str = str.substring(0, i);
1941
- } else if (e < 0) {
1942
- e = str.length;
1943
- }
1944
- for (i = 0; str.charCodeAt(i) === 48; i++)
1945
- ;
1946
- for (len = str.length; str.charCodeAt(len - 1) === 48; --len)
1947
- ;
1948
- str = str.slice(i, len);
1949
- if (str) {
1950
- len -= i;
1951
- x.e = e = e - i - 1;
1952
- x.d = [];
1953
- i = (e + 1) % LOG_BASE;
1954
- if (e < 0)
1955
- i += LOG_BASE;
1956
- if (i < len) {
1957
- if (i)
1958
- x.d.push(+str.slice(0, i));
1959
- for (len -= LOG_BASE; i < len; )
1960
- x.d.push(+str.slice(i, i += LOG_BASE));
1961
- str = str.slice(i);
1962
- i = LOG_BASE - str.length;
1963
- } else {
1964
- i -= len;
1965
- }
1966
- for (; i--; )
1967
- str += "0";
1968
- x.d.push(+str);
1969
- if (external) {
1970
- if (x.e > x.constructor.maxE) {
1971
- x.d = null;
1972
- x.e = NaN;
1973
- } else if (x.e < x.constructor.minE) {
1974
- x.e = 0;
1975
- x.d = [0];
1976
- }
1977
- }
1978
- } else {
1979
- x.e = 0;
1980
- x.d = [0];
1981
- }
1982
- return x;
1983
- }
1984
- function parseOther(x, str) {
1985
- var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
1986
- if (str.indexOf("_") > -1) {
1987
- str = str.replace(/(\d)_(?=\d)/g, "$1");
1988
- if (isDecimal.test(str))
1989
- return parseDecimal(x, str);
1990
- } else if (str === "Infinity" || str === "NaN") {
1991
- if (!+str)
1992
- x.s = NaN;
1993
- x.e = NaN;
1994
- x.d = null;
1995
- return x;
1996
- }
1997
- if (isHex.test(str)) {
1998
- base = 16;
1999
- str = str.toLowerCase();
2000
- } else if (isBinary.test(str)) {
2001
- base = 2;
2002
- } else if (isOctal.test(str)) {
2003
- base = 8;
2004
- } else {
2005
- throw Error(invalidArgument + str);
2006
- }
2007
- i = str.search(/p/i);
2008
- if (i > 0) {
2009
- p = +str.slice(i + 1);
2010
- str = str.substring(2, i);
2011
- } else {
2012
- str = str.slice(2);
2013
- }
2014
- i = str.indexOf(".");
2015
- isFloat = i >= 0;
2016
- Ctor = x.constructor;
2017
- if (isFloat) {
2018
- str = str.replace(".", "");
2019
- len = str.length;
2020
- i = len - i;
2021
- divisor = intPow(Ctor, new Ctor(base), i, i * 2);
2022
- }
2023
- xd = convertBase(str, base, BASE);
2024
- xe = xd.length - 1;
2025
- for (i = xe; xd[i] === 0; --i)
2026
- xd.pop();
2027
- if (i < 0)
2028
- return new Ctor(x.s * 0);
2029
- x.e = getBase10Exponent(xd, xe);
2030
- x.d = xd;
2031
- external = false;
2032
- if (isFloat)
2033
- x = divide(x, divisor, len * 4);
2034
- if (p)
2035
- x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
2036
- external = true;
2037
- return x;
2038
- }
2039
- function sine(Ctor, x) {
2040
- var k, len = x.d.length;
2041
- if (len < 3) {
2042
- return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
2043
- }
2044
- k = 1.4 * Math.sqrt(len);
2045
- k = k > 16 ? 16 : k | 0;
2046
- x = x.times(1 / tinyPow(5, k));
2047
- x = taylorSeries(Ctor, 2, x, x);
2048
- var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
2049
- for (; k--; ) {
2050
- sin2_x = x.times(x);
2051
- x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
2052
- }
2053
- return x;
2054
- }
2055
- function taylorSeries(Ctor, n, x, y, isHyperbolic) {
2056
- var j, t, u, x2, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
2057
- external = false;
2058
- x2 = x.times(x);
2059
- u = new Ctor(y);
2060
- for (; ; ) {
2061
- t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
2062
- u = isHyperbolic ? y.plus(t) : y.minus(t);
2063
- y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
2064
- t = u.plus(y);
2065
- if (t.d[k] !== void 0) {
2066
- for (j = k; t.d[j] === u.d[j] && j--; )
2067
- ;
2068
- if (j == -1)
2069
- break;
2070
- }
2071
- j = u;
2072
- u = y;
2073
- y = t;
2074
- t = j;
2075
- }
2076
- external = true;
2077
- t.d.length = k + 1;
2078
- return t;
2079
- }
2080
- function tinyPow(b, e) {
2081
- var n = b;
2082
- while (--e)
2083
- n *= b;
2084
- return n;
2085
- }
2086
- function toLessThanHalfPi(Ctor, x) {
2087
- var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
2088
- x = x.abs();
2089
- if (x.lte(halfPi)) {
2090
- quadrant = isNeg ? 4 : 1;
2091
- return x;
2092
- }
2093
- t = x.divToInt(pi);
2094
- if (t.isZero()) {
2095
- quadrant = isNeg ? 3 : 2;
2096
- } else {
2097
- x = x.minus(t.times(pi));
2098
- if (x.lte(halfPi)) {
2099
- quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
2100
- return x;
2101
- }
2102
- quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
2103
- }
2104
- return x.minus(pi).abs();
2105
- }
2106
- function toStringBinary(x, baseOut, sd, rm) {
2107
- var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
2108
- if (isExp) {
2109
- checkInt32(sd, 1, MAX_DIGITS);
2110
- if (rm === void 0)
2111
- rm = Ctor.rounding;
2112
- else
2113
- checkInt32(rm, 0, 8);
2114
- } else {
2115
- sd = Ctor.precision;
2116
- rm = Ctor.rounding;
2117
- }
2118
- if (!x.isFinite()) {
2119
- str = nonFiniteToString(x);
2120
- } else {
2121
- str = finiteToString(x);
2122
- i = str.indexOf(".");
2123
- if (isExp) {
2124
- base = 2;
2125
- if (baseOut == 16) {
2126
- sd = sd * 4 - 3;
2127
- } else if (baseOut == 8) {
2128
- sd = sd * 3 - 2;
2129
- }
2130
- } else {
2131
- base = baseOut;
2132
- }
2133
- if (i >= 0) {
2134
- str = str.replace(".", "");
2135
- y = new Ctor(1);
2136
- y.e = str.length - i;
2137
- y.d = convertBase(finiteToString(y), 10, base);
2138
- y.e = y.d.length;
2139
- }
2140
- xd = convertBase(str, 10, base);
2141
- e = len = xd.length;
2142
- for (; xd[--len] == 0; )
2143
- xd.pop();
2144
- if (!xd[0]) {
2145
- str = isExp ? "0p+0" : "0";
2146
- } else {
2147
- if (i < 0) {
2148
- e--;
2149
- } else {
2150
- x = new Ctor(x);
2151
- x.d = xd;
2152
- x.e = e;
2153
- x = divide(x, y, sd, rm, 0, base);
2154
- xd = x.d;
2155
- e = x.e;
2156
- roundUp = inexact;
2157
- }
2158
- i = xd[sd];
2159
- k = base / 2;
2160
- roundUp = roundUp || xd[sd + 1] !== void 0;
2161
- roundUp = rm < 4 ? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
2162
- xd.length = sd;
2163
- if (roundUp) {
2164
- for (; ++xd[--sd] > base - 1; ) {
2165
- xd[sd] = 0;
2166
- if (!sd) {
2167
- ++e;
2168
- xd.unshift(1);
2169
- }
2170
- }
2171
- }
2172
- for (len = xd.length; !xd[len - 1]; --len)
2173
- ;
2174
- for (i = 0, str = ""; i < len; i++)
2175
- str += NUMERALS.charAt(xd[i]);
2176
- if (isExp) {
2177
- if (len > 1) {
2178
- if (baseOut == 16 || baseOut == 8) {
2179
- i = baseOut == 16 ? 4 : 3;
2180
- for (--len; len % i; len++)
2181
- str += "0";
2182
- xd = convertBase(str, base, baseOut);
2183
- for (len = xd.length; !xd[len - 1]; --len)
2184
- ;
2185
- for (i = 1, str = "1."; i < len; i++)
2186
- str += NUMERALS.charAt(xd[i]);
2187
- } else {
2188
- str = str.charAt(0) + "." + str.slice(1);
2189
- }
2190
- }
2191
- str = str + (e < 0 ? "p" : "p+") + e;
2192
- } else if (e < 0) {
2193
- for (; ++e; )
2194
- str = "0" + str;
2195
- str = "0." + str;
2196
- } else {
2197
- if (++e > len)
2198
- for (e -= len; e--; )
2199
- str += "0";
2200
- else if (e < len)
2201
- str = str.slice(0, e) + "." + str.slice(e);
2202
- }
2203
- }
2204
- str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
2205
- }
2206
- return x.s < 0 ? "-" + str : str;
2207
- }
2208
- function truncate(arr, len) {
2209
- if (arr.length > len) {
2210
- arr.length = len;
2211
- return true;
2212
- }
2213
- }
2214
- function abs(x) {
2215
- return new this(x).abs();
2216
- }
2217
- function acos(x) {
2218
- return new this(x).acos();
2219
- }
2220
- function acosh(x) {
2221
- return new this(x).acosh();
2222
- }
2223
- function add(x, y) {
2224
- return new this(x).plus(y);
2225
- }
2226
- function asin(x) {
2227
- return new this(x).asin();
2228
- }
2229
- function asinh(x) {
2230
- return new this(x).asinh();
2231
- }
2232
- function atan(x) {
2233
- return new this(x).atan();
2234
- }
2235
- function atanh(x) {
2236
- return new this(x).atanh();
2237
- }
2238
- function atan2(y, x) {
2239
- y = new this(y);
2240
- x = new this(x);
2241
- var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
2242
- if (!y.s || !x.s) {
2243
- r = new this(NaN);
2244
- } else if (!y.d && !x.d) {
2245
- r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
2246
- r.s = y.s;
2247
- } else if (!x.d || y.isZero()) {
2248
- r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
2249
- r.s = y.s;
2250
- } else if (!y.d || x.isZero()) {
2251
- r = getPi(this, wpr, 1).times(0.5);
2252
- r.s = y.s;
2253
- } else if (x.s < 0) {
2254
- this.precision = wpr;
2255
- this.rounding = 1;
2256
- r = this.atan(divide(y, x, wpr, 1));
2257
- x = getPi(this, wpr, 1);
2258
- this.precision = pr;
2259
- this.rounding = rm;
2260
- r = y.s < 0 ? r.minus(x) : r.plus(x);
2261
- } else {
2262
- r = this.atan(divide(y, x, wpr, 1));
2263
- }
2264
- return r;
2265
- }
2266
- function cbrt(x) {
2267
- return new this(x).cbrt();
2268
- }
2269
- function ceil(x) {
2270
- return finalise(x = new this(x), x.e + 1, 2);
2271
- }
2272
- function clamp(x, min2, max2) {
2273
- return new this(x).clamp(min2, max2);
2274
- }
2275
- function config(obj) {
2276
- if (!obj || typeof obj !== "object")
2277
- throw Error(decimalError + "Object expected");
2278
- var i, p, v, useDefaults = obj.defaults === true, ps = [
2279
- "precision",
2280
- 1,
2281
- MAX_DIGITS,
2282
- "rounding",
2283
- 0,
2284
- 8,
2285
- "toExpNeg",
2286
- -EXP_LIMIT,
2287
- 0,
2288
- "toExpPos",
2289
- 0,
2290
- EXP_LIMIT,
2291
- "maxE",
2292
- 0,
2293
- EXP_LIMIT,
2294
- "minE",
2295
- -EXP_LIMIT,
2296
- 0,
2297
- "modulo",
2298
- 0,
2299
- 9
2300
- ];
2301
- for (i = 0; i < ps.length; i += 3) {
2302
- if (p = ps[i], useDefaults)
2303
- this[p] = DEFAULTS[p];
2304
- if ((v = obj[p]) !== void 0) {
2305
- if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
2306
- this[p] = v;
2307
- else
2308
- throw Error(invalidArgument + p + ": " + v);
2309
- }
2310
- }
2311
- if (p = "crypto", useDefaults)
2312
- this[p] = DEFAULTS[p];
2313
- if ((v = obj[p]) !== void 0) {
2314
- if (v === true || v === false || v === 0 || v === 1) {
2315
- if (v) {
2316
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
2317
- this[p] = true;
2318
- } else {
2319
- throw Error(cryptoUnavailable);
2320
- }
2321
- } else {
2322
- this[p] = false;
2323
- }
2324
- } else {
2325
- throw Error(invalidArgument + p + ": " + v);
2326
- }
2327
- }
2328
- return this;
2329
- }
2330
- function cos(x) {
2331
- return new this(x).cos();
2332
- }
2333
- function cosh(x) {
2334
- return new this(x).cosh();
2335
- }
2336
- function clone(obj) {
2337
- var i, p, ps;
2338
- function Decimal2(v) {
2339
- var e, i2, t, x = this;
2340
- if (!(x instanceof Decimal2))
2341
- return new Decimal2(v);
2342
- x.constructor = Decimal2;
2343
- if (isDecimalInstance(v)) {
2344
- x.s = v.s;
2345
- if (external) {
2346
- if (!v.d || v.e > Decimal2.maxE) {
2347
- x.e = NaN;
2348
- x.d = null;
2349
- } else if (v.e < Decimal2.minE) {
2350
- x.e = 0;
2351
- x.d = [0];
2352
- } else {
2353
- x.e = v.e;
2354
- x.d = v.d.slice();
2355
- }
2356
- } else {
2357
- x.e = v.e;
2358
- x.d = v.d ? v.d.slice() : v.d;
2359
- }
2360
- return;
2361
- }
2362
- t = typeof v;
2363
- if (t === "number") {
2364
- if (v === 0) {
2365
- x.s = 1 / v < 0 ? -1 : 1;
2366
- x.e = 0;
2367
- x.d = [0];
2368
- return;
2369
- }
2370
- if (v < 0) {
2371
- v = -v;
2372
- x.s = -1;
2373
- } else {
2374
- x.s = 1;
2375
- }
2376
- if (v === ~~v && v < 1e7) {
2377
- for (e = 0, i2 = v; i2 >= 10; i2 /= 10)
2378
- e++;
2379
- if (external) {
2380
- if (e > Decimal2.maxE) {
2381
- x.e = NaN;
2382
- x.d = null;
2383
- } else if (e < Decimal2.minE) {
2384
- x.e = 0;
2385
- x.d = [0];
2386
- } else {
2387
- x.e = e;
2388
- x.d = [v];
2389
- }
2390
- } else {
2391
- x.e = e;
2392
- x.d = [v];
2393
- }
2394
- return;
2395
- } else if (v * 0 !== 0) {
2396
- if (!v)
2397
- x.s = NaN;
2398
- x.e = NaN;
2399
- x.d = null;
2400
- return;
2401
- }
2402
- return parseDecimal(x, v.toString());
2403
- } else if (t !== "string") {
2404
- throw Error(invalidArgument + v);
2405
- }
2406
- if ((i2 = v.charCodeAt(0)) === 45) {
2407
- v = v.slice(1);
2408
- x.s = -1;
2409
- } else {
2410
- if (i2 === 43)
2411
- v = v.slice(1);
2412
- x.s = 1;
2413
- }
2414
- return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
2415
- }
2416
- Decimal2.prototype = P;
2417
- Decimal2.ROUND_UP = 0;
2418
- Decimal2.ROUND_DOWN = 1;
2419
- Decimal2.ROUND_CEIL = 2;
2420
- Decimal2.ROUND_FLOOR = 3;
2421
- Decimal2.ROUND_HALF_UP = 4;
2422
- Decimal2.ROUND_HALF_DOWN = 5;
2423
- Decimal2.ROUND_HALF_EVEN = 6;
2424
- Decimal2.ROUND_HALF_CEIL = 7;
2425
- Decimal2.ROUND_HALF_FLOOR = 8;
2426
- Decimal2.EUCLID = 9;
2427
- Decimal2.config = Decimal2.set = config;
2428
- Decimal2.clone = clone;
2429
- Decimal2.isDecimal = isDecimalInstance;
2430
- Decimal2.abs = abs;
2431
- Decimal2.acos = acos;
2432
- Decimal2.acosh = acosh;
2433
- Decimal2.add = add;
2434
- Decimal2.asin = asin;
2435
- Decimal2.asinh = asinh;
2436
- Decimal2.atan = atan;
2437
- Decimal2.atanh = atanh;
2438
- Decimal2.atan2 = atan2;
2439
- Decimal2.cbrt = cbrt;
2440
- Decimal2.ceil = ceil;
2441
- Decimal2.clamp = clamp;
2442
- Decimal2.cos = cos;
2443
- Decimal2.cosh = cosh;
2444
- Decimal2.div = div;
2445
- Decimal2.exp = exp;
2446
- Decimal2.floor = floor;
2447
- Decimal2.hypot = hypot;
2448
- Decimal2.ln = ln;
2449
- Decimal2.log = log;
2450
- Decimal2.log10 = log10;
2451
- Decimal2.log2 = log2;
2452
- Decimal2.max = max;
2453
- Decimal2.min = min;
2454
- Decimal2.mod = mod;
2455
- Decimal2.mul = mul;
2456
- Decimal2.pow = pow;
2457
- Decimal2.random = random;
2458
- Decimal2.round = round;
2459
- Decimal2.sign = sign;
2460
- Decimal2.sin = sin;
2461
- Decimal2.sinh = sinh;
2462
- Decimal2.sqrt = sqrt;
2463
- Decimal2.sub = sub;
2464
- Decimal2.sum = sum;
2465
- Decimal2.tan = tan;
2466
- Decimal2.tanh = tanh;
2467
- Decimal2.trunc = trunc;
2468
- if (obj === void 0)
2469
- obj = {};
2470
- if (obj) {
2471
- if (obj.defaults !== true) {
2472
- ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
2473
- for (i = 0; i < ps.length; )
2474
- if (!obj.hasOwnProperty(p = ps[i++]))
2475
- obj[p] = this[p];
2476
- }
2477
- }
2478
- Decimal2.config(obj);
2479
- return Decimal2;
2480
- }
2481
- function div(x, y) {
2482
- return new this(x).div(y);
2483
- }
2484
- function exp(x) {
2485
- return new this(x).exp();
2486
- }
2487
- function floor(x) {
2488
- return finalise(x = new this(x), x.e + 1, 3);
2489
- }
2490
- function hypot() {
2491
- var i, n, t = new this(0);
2492
- external = false;
2493
- for (i = 0; i < arguments.length; ) {
2494
- n = new this(arguments[i++]);
2495
- if (!n.d) {
2496
- if (n.s) {
2497
- external = true;
2498
- return new this(1 / 0);
2499
- }
2500
- t = n;
2501
- } else if (t.d) {
2502
- t = t.plus(n.times(n));
2503
- }
2504
- }
2505
- external = true;
2506
- return t.sqrt();
2507
- }
2508
- function isDecimalInstance(obj) {
2509
- return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
2510
- }
2511
- function ln(x) {
2512
- return new this(x).ln();
2513
- }
2514
- function log(x, y) {
2515
- return new this(x).log(y);
2516
- }
2517
- function log2(x) {
2518
- return new this(x).log(2);
2519
- }
2520
- function log10(x) {
2521
- return new this(x).log(10);
2522
- }
2523
- function max() {
2524
- return maxOrMin(this, arguments, "lt");
2525
- }
2526
- function min() {
2527
- return maxOrMin(this, arguments, "gt");
2528
- }
2529
- function mod(x, y) {
2530
- return new this(x).mod(y);
2531
- }
2532
- function mul(x, y) {
2533
- return new this(x).mul(y);
2534
- }
2535
- function pow(x, y) {
2536
- return new this(x).pow(y);
2537
- }
2538
- function random(sd) {
2539
- var d, e, k, n, i = 0, r = new this(1), rd = [];
2540
- if (sd === void 0)
2541
- sd = this.precision;
2542
- else
2543
- checkInt32(sd, 1, MAX_DIGITS);
2544
- k = Math.ceil(sd / LOG_BASE);
2545
- if (!this.crypto) {
2546
- for (; i < k; )
2547
- rd[i++] = Math.random() * 1e7 | 0;
2548
- } else if (crypto.getRandomValues) {
2549
- d = crypto.getRandomValues(new Uint32Array(k));
2550
- for (; i < k; ) {
2551
- n = d[i];
2552
- if (n >= 429e7) {
2553
- d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
2554
- } else {
2555
- rd[i++] = n % 1e7;
2556
- }
2557
- }
2558
- } else if (crypto.randomBytes) {
2559
- d = crypto.randomBytes(k *= 4);
2560
- for (; i < k; ) {
2561
- n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
2562
- if (n >= 214e7) {
2563
- crypto.randomBytes(4).copy(d, i);
2564
- } else {
2565
- rd.push(n % 1e7);
2566
- i += 4;
2567
- }
2568
- }
2569
- i = k / 4;
2570
- } else {
2571
- throw Error(cryptoUnavailable);
2572
- }
2573
- k = rd[--i];
2574
- sd %= LOG_BASE;
2575
- if (k && sd) {
2576
- n = mathpow(10, LOG_BASE - sd);
2577
- rd[i] = (k / n | 0) * n;
2578
- }
2579
- for (; rd[i] === 0; i--)
2580
- rd.pop();
2581
- if (i < 0) {
2582
- e = 0;
2583
- rd = [0];
2584
- } else {
2585
- e = -1;
2586
- for (; rd[0] === 0; e -= LOG_BASE)
2587
- rd.shift();
2588
- for (k = 1, n = rd[0]; n >= 10; n /= 10)
2589
- k++;
2590
- if (k < LOG_BASE)
2591
- e -= LOG_BASE - k;
2592
- }
2593
- r.e = e;
2594
- r.d = rd;
2595
- return r;
2596
- }
2597
- function round(x) {
2598
- return finalise(x = new this(x), x.e + 1, this.rounding);
2599
- }
2600
- function sign(x) {
2601
- x = new this(x);
2602
- return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
2603
- }
2604
- function sin(x) {
2605
- return new this(x).sin();
2606
- }
2607
- function sinh(x) {
2608
- return new this(x).sinh();
2609
- }
2610
- function sqrt(x) {
2611
- return new this(x).sqrt();
2612
- }
2613
- function sub(x, y) {
2614
- return new this(x).sub(y);
2615
- }
2616
- function sum() {
2617
- var i = 0, args = arguments, x = new this(args[i]);
2618
- external = false;
2619
- for (; x.s && ++i < args.length; )
2620
- x = x.plus(args[i]);
2621
- external = true;
2622
- return finalise(x, this.precision, this.rounding);
2623
- }
2624
- function tan(x) {
2625
- return new this(x).tan();
2626
- }
2627
- function tanh(x) {
2628
- return new this(x).tanh();
2629
- }
2630
- function trunc(x) {
2631
- return finalise(x = new this(x), x.e + 1, 1);
2632
- }
2633
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
2634
- P[Symbol.toStringTag] = "Decimal";
2635
- var Decimal = P.constructor = clone(DEFAULTS);
2636
- LN10 = new Decimal(LN10);
2637
- PI = new Decimal(PI);
2638
- const libJsDecimal = (num1, num2, operator, point = 2) => {
2639
- const calc = {
2640
- "+": (a, b) => a.add(b),
2641
- "-": (a, b) => a.sub(b),
2642
- "*": (a, b) => a.mul(b),
2643
- "/": (a, b) => {
2644
- if (b.eq(0)) {
2645
- throw new Error("除数不能为0");
2646
- }
2647
- return a.div(b);
2648
- }
2649
- };
2650
- const result = calc[operator](new Decimal(num1), new Decimal(num2));
2651
- return Number(result.toFixed(point, Decimal.ROUND_DOWN));
2652
- };
2653
- const libJsRegFormValidate = (form, rules) => {
2654
- return rules.reduce((result, rule) => {
2655
- const { key, verify, msg, name } = rule;
2656
- const value = form[key];
2657
- if (value === "" || value === void 0 || value === null) {
2658
- result.push({ key, msg: "必填项", name });
2659
- } else if (typeof verify === "function" ? !verify(value) : !verify.test(value)) {
2660
- result.push({ key, msg, name });
2661
- }
2662
- return result;
2663
- }, []);
2664
- };
2665
- const libJsRetryRequest = ({
2666
- promiseFn,
2667
- maxRetries = 3,
2668
- retryDelay = 2e3,
2669
- params = void 0
2670
- }) => {
2671
- return new Promise((resolve, reject) => {
2672
- let count = 0;
2673
- const makeRequest = () => {
2674
- promiseFn(params).then((res) => {
2675
- resolve(res);
2676
- }).catch((err) => {
2677
- count++;
2678
- if (count >= maxRetries) {
2679
- reject(err);
2680
- return;
2681
- }
2682
- setTimeout(makeRequest, retryDelay);
2683
- });
2684
- };
2685
- makeRequest();
2686
- });
2687
- };
2688
- const libJsProbabilityResult = (probability) => Math.random() * 100 < probability;
2689
- const libJsRandom = (min2, max2, num = 0) => {
2690
- return parseFloat((Math.random() * (max2 - min2) + min2).toFixed(num));
2691
- };
2692
- const libJsRandomColor = (alpha = 1) => {
2693
- const r = Math.floor(Math.random() * 256);
2694
- const g = Math.floor(Math.random() * 256);
2695
- const b = Math.floor(Math.random() * 256);
2696
- return `rgba(${r}, ${g}, ${b}, ${alpha})`;
2697
- };
2698
- const libJsUniqueRandomNumbers = (min2, max2, count) => {
2699
- const numbers = Array.from({ length: max2 - min2 + 1 }, (_, i) => i + min2);
2700
- for (let i = numbers.length - 1; i > 0; i--) {
2701
- const j = Math.floor(Math.random() * (i + 1));
2702
- [numbers[i], numbers[j]] = [numbers[j], numbers[i]];
2703
- }
2704
- return numbers.slice(0, count);
2705
- };
2706
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
2707
- function getDefaultExportFromCjs(x) {
2708
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
2709
- }
2710
- var dayjs_min = { exports: {} };
2711
- (function(module, exports) {
2712
- !function(t, e) {
2713
- module.exports = e();
2714
- }(commonjsGlobal, function() {
2715
- var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(t2) {
2716
- var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
2717
- return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
2718
- } }, m = function(t2, e2, n2) {
2719
- var r2 = String(t2);
2720
- return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
2721
- }, v = { s: m, z: function(t2) {
2722
- var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
2723
- return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
2724
- }, m: function t2(e2, n2) {
2725
- if (e2.date() < n2.date())
2726
- return -t2(n2, e2);
2727
- var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
2728
- return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
2729
- }, a: function(t2) {
2730
- return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
2731
- }, p: function(t2) {
2732
- return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
2733
- }, u: function(t2) {
2734
- return void 0 === t2;
2735
- } }, g = "en", D = {};
2736
- D[g] = M;
2737
- var p = "$isDayjsObject", S = function(t2) {
2738
- return t2 instanceof _ || !(!t2 || !t2[p]);
2739
- }, w = function t2(e2, n2, r2) {
2740
- var i2;
2741
- if (!e2)
2742
- return g;
2743
- if ("string" == typeof e2) {
2744
- var s2 = e2.toLowerCase();
2745
- D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
2746
- var u2 = e2.split("-");
2747
- if (!i2 && u2.length > 1)
2748
- return t2(u2[0]);
2749
- } else {
2750
- var a2 = e2.name;
2751
- D[a2] = e2, i2 = a2;
2752
- }
2753
- return !r2 && i2 && (g = i2), i2 || !r2 && g;
2754
- }, O = function(t2, e2) {
2755
- if (S(t2))
2756
- return t2.clone();
2757
- var n2 = "object" == typeof e2 ? e2 : {};
2758
- return n2.date = t2, n2.args = arguments, new _(n2);
2759
- }, b = v;
2760
- b.l = w, b.i = S, b.w = function(t2, e2) {
2761
- return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
2762
- };
2763
- var _ = function() {
2764
- function M2(t2) {
2765
- this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
2766
- }
2767
- var m2 = M2.prototype;
2768
- return m2.parse = function(t2) {
2769
- this.$d = function(t3) {
2770
- var e2 = t3.date, n2 = t3.utc;
2771
- if (null === e2)
2772
- return /* @__PURE__ */ new Date(NaN);
2773
- if (b.u(e2))
2774
- return /* @__PURE__ */ new Date();
2775
- if (e2 instanceof Date)
2776
- return new Date(e2);
2777
- if ("string" == typeof e2 && !/Z$/i.test(e2)) {
2778
- var r2 = e2.match($);
2779
- if (r2) {
2780
- var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
2781
- return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
2782
- }
2783
- }
2784
- return new Date(e2);
2785
- }(t2), this.init();
2786
- }, m2.init = function() {
2787
- var t2 = this.$d;
2788
- this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
2789
- }, m2.$utils = function() {
2790
- return b;
2791
- }, m2.isValid = function() {
2792
- return !(this.$d.toString() === l);
2793
- }, m2.isSame = function(t2, e2) {
2794
- var n2 = O(t2);
2795
- return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
2796
- }, m2.isAfter = function(t2, e2) {
2797
- return O(t2) < this.startOf(e2);
2798
- }, m2.isBefore = function(t2, e2) {
2799
- return this.endOf(e2) < O(t2);
2800
- }, m2.$g = function(t2, e2, n2) {
2801
- return b.u(t2) ? this[e2] : this.set(n2, t2);
2802
- }, m2.unix = function() {
2803
- return Math.floor(this.valueOf() / 1e3);
2804
- }, m2.valueOf = function() {
2805
- return this.$d.getTime();
2806
- }, m2.startOf = function(t2, e2) {
2807
- var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
2808
- var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
2809
- return r2 ? i2 : i2.endOf(a);
2810
- }, $2 = function(t3, e3) {
2811
- return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
2812
- }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
2813
- switch (f2) {
2814
- case h:
2815
- return r2 ? l2(1, 0) : l2(31, 11);
2816
- case c:
2817
- return r2 ? l2(1, M3) : l2(0, M3 + 1);
2818
- case o:
2819
- var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
2820
- return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
2821
- case a:
2822
- case d:
2823
- return $2(v2 + "Hours", 0);
2824
- case u:
2825
- return $2(v2 + "Minutes", 1);
2826
- case s:
2827
- return $2(v2 + "Seconds", 2);
2828
- case i:
2829
- return $2(v2 + "Milliseconds", 3);
2830
- default:
2831
- return this.clone();
2832
- }
2833
- }, m2.endOf = function(t2) {
2834
- return this.startOf(t2, false);
2835
- }, m2.$set = function(t2, e2) {
2836
- var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
2837
- if (o2 === c || o2 === h) {
2838
- var y2 = this.clone().set(d, 1);
2839
- y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
2840
- } else
2841
- l2 && this.$d[l2]($2);
2842
- return this.init(), this;
2843
- }, m2.set = function(t2, e2) {
2844
- return this.clone().$set(t2, e2);
2845
- }, m2.get = function(t2) {
2846
- return this[b.p(t2)]();
2847
- }, m2.add = function(r2, f2) {
2848
- var d2, l2 = this;
2849
- r2 = Number(r2);
2850
- var $2 = b.p(f2), y2 = function(t2) {
2851
- var e2 = O(l2);
2852
- return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
2853
- };
2854
- if ($2 === c)
2855
- return this.set(c, this.$M + r2);
2856
- if ($2 === h)
2857
- return this.set(h, this.$y + r2);
2858
- if ($2 === a)
2859
- return y2(1);
2860
- if ($2 === o)
2861
- return y2(7);
2862
- var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
2863
- return b.w(m3, this);
2864
- }, m2.subtract = function(t2, e2) {
2865
- return this.add(-1 * t2, e2);
2866
- }, m2.format = function(t2) {
2867
- var e2 = this, n2 = this.$locale();
2868
- if (!this.isValid())
2869
- return n2.invalidDate || l;
2870
- var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
2871
- return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
2872
- }, d2 = function(t3) {
2873
- return b.s(s2 % 12 || 12, t3, "0");
2874
- }, $2 = f2 || function(t3, e3, n3) {
2875
- var r3 = t3 < 12 ? "AM" : "PM";
2876
- return n3 ? r3.toLowerCase() : r3;
2877
- };
2878
- return r2.replace(y, function(t3, r3) {
2879
- return r3 || function(t4) {
2880
- switch (t4) {
2881
- case "YY":
2882
- return String(e2.$y).slice(-2);
2883
- case "YYYY":
2884
- return b.s(e2.$y, 4, "0");
2885
- case "M":
2886
- return a2 + 1;
2887
- case "MM":
2888
- return b.s(a2 + 1, 2, "0");
2889
- case "MMM":
2890
- return h2(n2.monthsShort, a2, c2, 3);
2891
- case "MMMM":
2892
- return h2(c2, a2);
2893
- case "D":
2894
- return e2.$D;
2895
- case "DD":
2896
- return b.s(e2.$D, 2, "0");
2897
- case "d":
2898
- return String(e2.$W);
2899
- case "dd":
2900
- return h2(n2.weekdaysMin, e2.$W, o2, 2);
2901
- case "ddd":
2902
- return h2(n2.weekdaysShort, e2.$W, o2, 3);
2903
- case "dddd":
2904
- return o2[e2.$W];
2905
- case "H":
2906
- return String(s2);
2907
- case "HH":
2908
- return b.s(s2, 2, "0");
2909
- case "h":
2910
- return d2(1);
2911
- case "hh":
2912
- return d2(2);
2913
- case "a":
2914
- return $2(s2, u2, true);
2915
- case "A":
2916
- return $2(s2, u2, false);
2917
- case "m":
2918
- return String(u2);
2919
- case "mm":
2920
- return b.s(u2, 2, "0");
2921
- case "s":
2922
- return String(e2.$s);
2923
- case "ss":
2924
- return b.s(e2.$s, 2, "0");
2925
- case "SSS":
2926
- return b.s(e2.$ms, 3, "0");
2927
- case "Z":
2928
- return i2;
2929
- }
2930
- return null;
2931
- }(t3) || i2.replace(":", "");
2932
- });
2933
- }, m2.utcOffset = function() {
2934
- return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
2935
- }, m2.diff = function(r2, d2, l2) {
2936
- var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
2937
- return b.m(y2, m3);
2938
- };
2939
- switch (M3) {
2940
- case h:
2941
- $2 = D2() / 12;
2942
- break;
2943
- case c:
2944
- $2 = D2();
2945
- break;
2946
- case f:
2947
- $2 = D2() / 3;
2948
- break;
2949
- case o:
2950
- $2 = (g2 - v2) / 6048e5;
2951
- break;
2952
- case a:
2953
- $2 = (g2 - v2) / 864e5;
2954
- break;
2955
- case u:
2956
- $2 = g2 / n;
2957
- break;
2958
- case s:
2959
- $2 = g2 / e;
2960
- break;
2961
- case i:
2962
- $2 = g2 / t;
2963
- break;
2964
- default:
2965
- $2 = g2;
2966
- }
2967
- return l2 ? $2 : b.a($2);
2968
- }, m2.daysInMonth = function() {
2969
- return this.endOf(c).$D;
2970
- }, m2.$locale = function() {
2971
- return D[this.$L];
2972
- }, m2.locale = function(t2, e2) {
2973
- if (!t2)
2974
- return this.$L;
2975
- var n2 = this.clone(), r2 = w(t2, e2, true);
2976
- return r2 && (n2.$L = r2), n2;
2977
- }, m2.clone = function() {
2978
- return b.w(this.$d, this);
2979
- }, m2.toDate = function() {
2980
- return new Date(this.valueOf());
2981
- }, m2.toJSON = function() {
2982
- return this.isValid() ? this.toISOString() : null;
2983
- }, m2.toISOString = function() {
2984
- return this.$d.toISOString();
2985
- }, m2.toString = function() {
2986
- return this.$d.toUTCString();
2987
- }, M2;
2988
- }(), k = _.prototype;
2989
- return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
2990
- k[t2[1]] = function(e2) {
2991
- return this.$g(e2, t2[0], t2[1]);
2992
- };
2993
- }), O.extend = function(t2, e2) {
2994
- return t2.$i || (t2(e2, _, O), t2.$i = true), O;
2995
- }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
2996
- return O(1e3 * t2);
2997
- }, O.en = D[g], O.Ls = D, O.p = {}, O;
2998
- });
2999
- })(dayjs_min);
3000
- var dayjs_minExports = dayjs_min.exports;
3001
- const dayjs = /* @__PURE__ */ getDefaultExportFromCjs(dayjs_minExports);
3002
- const libJsSameTimeCheck = (timestamp, unit) => {
3003
- const inputTime = dayjs(timestamp).startOf(unit);
3004
- const currentTime = dayjs().startOf(unit);
3005
- if (inputTime.isSame(currentTime)) {
3006
- return 0;
3007
- } else if (inputTime.isBefore(currentTime)) {
3008
- return 1;
3009
- } else {
3010
- return -1;
3011
- }
3012
- };
3013
- const libJsTimeAgo = (timestamp) => {
3014
- const timeUnits = [
3015
- { unit: "年", milliseconds: 365 * 24 * 60 * 60 * 1e3 },
3016
- { unit: "月", milliseconds: 30 * 24 * 60 * 60 * 1e3 },
3017
- { unit: "周", milliseconds: 7 * 24 * 60 * 60 * 1e3 },
3018
- { unit: "天", milliseconds: 24 * 60 * 60 * 1e3 },
3019
- { unit: "小时", milliseconds: 60 * 60 * 1e3 },
3020
- { unit: "分钟", milliseconds: 60 * 1e3 }
3021
- ];
3022
- const currentTime = Date.now();
3023
- const timeDifference = currentTime - timestamp;
3024
- for (const { unit, milliseconds } of timeUnits) {
3025
- if (timeDifference >= milliseconds) {
3026
- const count = Math.floor(timeDifference / milliseconds);
3027
- return `${count} ${unit}前`;
3028
- }
3029
- }
3030
- return "刚刚";
3031
- };
3032
- const libJsTimeGreeting = (greet = {}) => {
3033
- const {
3034
- midnight = "午夜好",
3035
- morning = "早上好",
3036
- forenoon = "上午好",
3037
- noon = "中午好",
3038
- afternoon = "下午好",
3039
- evening = "晚上好"
3040
- } = greet;
3041
- const now = (/* @__PURE__ */ new Date()).getHours();
3042
- return now < 4 ? midnight : now < 10 ? morning : now < 12 ? forenoon : now < 14 ? noon : now < 18 ? afternoon : evening;
3043
- };
3044
- class LibJsNumberStepper {
3045
- /**
3046
- * @param numsLength 数字长度
3047
- * @param onChange 数字变动时触发
3048
- */
3049
- constructor(onChange) {
3050
- this._isDown = false;
3051
- this._onChange = onChange;
3052
- window.addEventListener("pointerup", () => {
3053
- this._isDown && this._up();
3054
- });
3055
- }
3056
- /** @description 按下
3057
- * @param type 操作类型 add:加 sub:减
3058
- */
3059
- down(type) {
3060
- this._isDown = true;
3061
- this._handleChange(type);
3062
- this._timerId = setTimeout(() => {
3063
- if (this._isDown) {
3064
- this._intervalId = setInterval(() => {
3065
- this._handleChange(type);
3066
- }, 100);
3067
- }
3068
- }, 100);
3069
- }
3070
- /** @description 抬起 */
3071
- _up() {
3072
- this._isDown = false;
3073
- clearTimeout(this._timerId);
3074
- clearInterval(this._intervalId);
3075
- }
3076
- /** @description 处理数字变化
3077
- * @param type 操作类型 add:加 sub:减
3078
- */
3079
- _handleChange(type) {
3080
- if (type === "add") {
3081
- this._onChange("add");
3082
- } else if (type === "sub") {
3083
- this._onChange("sub");
3084
- }
3085
- }
3086
- }
3087
- const libJsFormatterByte = (bytes) => {
3088
- if (bytes <= 0)
3089
- return [0, "B", "0 B"];
3090
- const k = 1024;
3091
- const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
3092
- const i = Math.min(
3093
- Math.floor(Math.log(bytes) / Math.log(k)),
3094
- sizes.length - 1
3095
- );
3096
- const size = (bytes / k ** i).toFixed(2);
3097
- return [size, sizes[i], `${size} ${sizes[i]}`];
3098
- };
3099
- const libJsMaskPhoneNumber = (mobile) => {
3100
- const m = mobile.toString();
3101
- return m.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
3102
- };
3103
- const libJsNumComma = (num, reserve = 2) => {
3104
- const str = num.toFixed(reserve).toString();
3105
- const reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
3106
- return str.replace(reg, "$1,");
3107
- };
3108
- const libJsNumberUnit = (num, units, retain = 0) => {
3109
- const decimalValue = new Decimal(num);
3110
- const sortedUnits = Object.entries(units).sort(([, a], [, b]) => b - a);
3111
- for (const [unit, threshold] of sortedUnits) {
3112
- const decimalThreshold = new Decimal(threshold);
3113
- if (decimalValue.greaterThanOrEqualTo(decimalThreshold)) {
3114
- const formattedValue = decimalValue.dividedBy(decimalThreshold);
3115
- const v2 = libJsNumComma(Number(formattedValue), retain);
3116
- return v2 + unit;
3117
- }
3118
- }
3119
- const v = libJsNumComma(Number(decimalValue), retain);
3120
- return v;
3121
- };
3122
- var duration$1 = { exports: {} };
3123
- (function(module, exports) {
3124
- !function(t, s) {
3125
- module.exports = s();
3126
- }(commonjsGlobal, function() {
3127
- var t, s, n = 1e3, i = 6e4, e = 36e5, r = 864e5, o = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, u = 31536e6, d = 2628e6, a = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/, h = { years: u, months: d, days: r, hours: e, minutes: i, seconds: n, milliseconds: 1, weeks: 6048e5 }, c = function(t2) {
3128
- return t2 instanceof g;
3129
- }, f = function(t2, s2, n2) {
3130
- return new g(t2, n2, s2.$l);
3131
- }, m = function(t2) {
3132
- return s.p(t2) + "s";
3133
- }, l = function(t2) {
3134
- return t2 < 0;
3135
- }, $ = function(t2) {
3136
- return l(t2) ? Math.ceil(t2) : Math.floor(t2);
3137
- }, y = function(t2) {
3138
- return Math.abs(t2);
3139
- }, v = function(t2, s2) {
3140
- return t2 ? l(t2) ? { negative: true, format: "" + y(t2) + s2 } : { negative: false, format: "" + t2 + s2 } : { negative: false, format: "" };
3141
- }, g = function() {
3142
- function l2(t2, s2, n2) {
3143
- var i2 = this;
3144
- if (this.$d = {}, this.$l = n2, void 0 === t2 && (this.$ms = 0, this.parseFromMilliseconds()), s2)
3145
- return f(t2 * h[m(s2)], this);
3146
- if ("number" == typeof t2)
3147
- return this.$ms = t2, this.parseFromMilliseconds(), this;
3148
- if ("object" == typeof t2)
3149
- return Object.keys(t2).forEach(function(s3) {
3150
- i2.$d[m(s3)] = t2[s3];
3151
- }), this.calMilliseconds(), this;
3152
- if ("string" == typeof t2) {
3153
- var e2 = t2.match(a);
3154
- if (e2) {
3155
- var r2 = e2.slice(2).map(function(t3) {
3156
- return null != t3 ? Number(t3) : 0;
3157
- });
3158
- return this.$d.years = r2[0], this.$d.months = r2[1], this.$d.weeks = r2[2], this.$d.days = r2[3], this.$d.hours = r2[4], this.$d.minutes = r2[5], this.$d.seconds = r2[6], this.calMilliseconds(), this;
3159
- }
3160
- }
3161
- return this;
3162
- }
3163
- var y2 = l2.prototype;
3164
- return y2.calMilliseconds = function() {
3165
- var t2 = this;
3166
- this.$ms = Object.keys(this.$d).reduce(function(s2, n2) {
3167
- return s2 + (t2.$d[n2] || 0) * h[n2];
3168
- }, 0);
3169
- }, y2.parseFromMilliseconds = function() {
3170
- var t2 = this.$ms;
3171
- this.$d.years = $(t2 / u), t2 %= u, this.$d.months = $(t2 / d), t2 %= d, this.$d.days = $(t2 / r), t2 %= r, this.$d.hours = $(t2 / e), t2 %= e, this.$d.minutes = $(t2 / i), t2 %= i, this.$d.seconds = $(t2 / n), t2 %= n, this.$d.milliseconds = t2;
3172
- }, y2.toISOString = function() {
3173
- var t2 = v(this.$d.years, "Y"), s2 = v(this.$d.months, "M"), n2 = +this.$d.days || 0;
3174
- this.$d.weeks && (n2 += 7 * this.$d.weeks);
3175
- var i2 = v(n2, "D"), e2 = v(this.$d.hours, "H"), r2 = v(this.$d.minutes, "M"), o2 = this.$d.seconds || 0;
3176
- this.$d.milliseconds && (o2 += this.$d.milliseconds / 1e3, o2 = Math.round(1e3 * o2) / 1e3);
3177
- var u2 = v(o2, "S"), d2 = t2.negative || s2.negative || i2.negative || e2.negative || r2.negative || u2.negative, a2 = e2.format || r2.format || u2.format ? "T" : "", h2 = (d2 ? "-" : "") + "P" + t2.format + s2.format + i2.format + a2 + e2.format + r2.format + u2.format;
3178
- return "P" === h2 || "-P" === h2 ? "P0D" : h2;
3179
- }, y2.toJSON = function() {
3180
- return this.toISOString();
3181
- }, y2.format = function(t2) {
3182
- var n2 = t2 || "YYYY-MM-DDTHH:mm:ss", i2 = { Y: this.$d.years, YY: s.s(this.$d.years, 2, "0"), YYYY: s.s(this.$d.years, 4, "0"), M: this.$d.months, MM: s.s(this.$d.months, 2, "0"), D: this.$d.days, DD: s.s(this.$d.days, 2, "0"), H: this.$d.hours, HH: s.s(this.$d.hours, 2, "0"), m: this.$d.minutes, mm: s.s(this.$d.minutes, 2, "0"), s: this.$d.seconds, ss: s.s(this.$d.seconds, 2, "0"), SSS: s.s(this.$d.milliseconds, 3, "0") };
3183
- return n2.replace(o, function(t3, s2) {
3184
- return s2 || String(i2[t3]);
3185
- });
3186
- }, y2.as = function(t2) {
3187
- return this.$ms / h[m(t2)];
3188
- }, y2.get = function(t2) {
3189
- var s2 = this.$ms, n2 = m(t2);
3190
- return "milliseconds" === n2 ? s2 %= 1e3 : s2 = "weeks" === n2 ? $(s2 / h[n2]) : this.$d[n2], s2 || 0;
3191
- }, y2.add = function(t2, s2, n2) {
3192
- var i2;
3193
- return i2 = s2 ? t2 * h[m(s2)] : c(t2) ? t2.$ms : f(t2, this).$ms, f(this.$ms + i2 * (n2 ? -1 : 1), this);
3194
- }, y2.subtract = function(t2, s2) {
3195
- return this.add(t2, s2, true);
3196
- }, y2.locale = function(t2) {
3197
- var s2 = this.clone();
3198
- return s2.$l = t2, s2;
3199
- }, y2.clone = function() {
3200
- return f(this.$ms, this);
3201
- }, y2.humanize = function(s2) {
3202
- return t().add(this.$ms, "ms").locale(this.$l).fromNow(!s2);
3203
- }, y2.valueOf = function() {
3204
- return this.asMilliseconds();
3205
- }, y2.milliseconds = function() {
3206
- return this.get("milliseconds");
3207
- }, y2.asMilliseconds = function() {
3208
- return this.as("milliseconds");
3209
- }, y2.seconds = function() {
3210
- return this.get("seconds");
3211
- }, y2.asSeconds = function() {
3212
- return this.as("seconds");
3213
- }, y2.minutes = function() {
3214
- return this.get("minutes");
3215
- }, y2.asMinutes = function() {
3216
- return this.as("minutes");
3217
- }, y2.hours = function() {
3218
- return this.get("hours");
3219
- }, y2.asHours = function() {
3220
- return this.as("hours");
3221
- }, y2.days = function() {
3222
- return this.get("days");
3223
- }, y2.asDays = function() {
3224
- return this.as("days");
3225
- }, y2.weeks = function() {
3226
- return this.get("weeks");
3227
- }, y2.asWeeks = function() {
3228
- return this.as("weeks");
3229
- }, y2.months = function() {
3230
- return this.get("months");
3231
- }, y2.asMonths = function() {
3232
- return this.as("months");
3233
- }, y2.years = function() {
3234
- return this.get("years");
3235
- }, y2.asYears = function() {
3236
- return this.as("years");
3237
- }, l2;
3238
- }(), p = function(t2, s2, n2) {
3239
- return t2.add(s2.years() * n2, "y").add(s2.months() * n2, "M").add(s2.days() * n2, "d").add(s2.hours() * n2, "h").add(s2.minutes() * n2, "m").add(s2.seconds() * n2, "s").add(s2.milliseconds() * n2, "ms");
3240
- };
3241
- return function(n2, i2, e2) {
3242
- t = e2, s = e2().$utils(), e2.duration = function(t2, s2) {
3243
- var n3 = e2.locale();
3244
- return f(t2, { $l: n3 }, s2);
3245
- }, e2.isDuration = c;
3246
- var r2 = i2.prototype.add, o2 = i2.prototype.subtract;
3247
- i2.prototype.add = function(t2, s2) {
3248
- return c(t2) ? p(this, t2, 1) : r2.bind(this)(t2, s2);
3249
- }, i2.prototype.subtract = function(t2, s2) {
3250
- return c(t2) ? p(this, t2, -1) : o2.bind(this)(t2, s2);
3251
- };
3252
- };
3253
- });
3254
- })(duration$1);
3255
- var durationExports = duration$1.exports;
3256
- const duration = /* @__PURE__ */ getDefaultExportFromCjs(durationExports);
3257
- dayjs.extend(duration);
3258
- const libJsSecondsFormatterChinese = (seconds) => {
3259
- const duration2 = dayjs.duration(seconds, "seconds");
3260
- const years = Math.floor(duration2.asYears());
3261
- const months = Math.floor(duration2.asMonths() % 12);
3262
- const days = Math.floor(duration2.asDays() % 30);
3263
- const hours = duration2.hours();
3264
- const minutes = duration2.minutes();
3265
- const remainingSeconds = duration2.seconds();
3266
- const timeParts = [];
3267
- if (years > 0) {
3268
- timeParts.push(`${years}年`);
3269
- }
3270
- if (months > 0) {
3271
- timeParts.push(`${months}月`);
3272
- }
3273
- if (days > 0) {
3274
- timeParts.push(`${days}天`);
3275
- }
3276
- if (hours > 0) {
3277
- timeParts.push(`${hours}小时`);
3278
- }
3279
- if (minutes > 0) {
3280
- timeParts.push(`${minutes}分`);
3281
- }
3282
- if (timeParts.length === 0 || remainingSeconds > 0) {
3283
- timeParts.push(`${remainingSeconds}秒`);
3284
- }
3285
- return timeParts.join("");
3286
- };
3287
- const libJsCalculateExpression = (expression, point = 2) => {
3288
- expression = expression.replace(/\s+/g, "");
3289
- const operators = {
3290
- "+": 1,
3291
- "-": 1,
3292
- "*": 2,
3293
- "/": 2
3294
- };
3295
- const toDecimal = (value) => new Decimal(value);
3296
- const isOperator = (char) => ["+", "-", "*", "/"].includes(char);
3297
- const isNumber = (char) => /[0-9.]/.test(char);
3298
- const evaluate = (expression2) => {
3299
- const outputQueue = [];
3300
- const operatorStack = [];
3301
- let i = 0;
3302
- while (i < expression2.length) {
3303
- const char = expression2[i];
3304
- if (isNumber(char)) {
3305
- let numStr = "";
3306
- while (i < expression2.length && isNumber(expression2[i])) {
3307
- numStr += expression2[i];
3308
- i++;
3309
- }
3310
- outputQueue.push(toDecimal(numStr));
3311
- } else if (char === "(") {
3312
- operatorStack.push(char);
3313
- i++;
3314
- } else if (char === ")") {
3315
- while (operatorStack.length > 0 && operatorStack[operatorStack.length - 1] !== "(") {
3316
- outputQueue.push(operatorStack.pop());
3317
- }
3318
- operatorStack.pop();
3319
- i++;
3320
- } else if (isOperator(char)) {
3321
- while (operatorStack.length > 0 && operators[operatorStack[operatorStack.length - 1]] >= operators[char]) {
3322
- outputQueue.push(operatorStack.pop());
3323
- }
3324
- operatorStack.push(char);
3325
- i++;
3326
- } else {
3327
- throw new Error(`无效字符: ${char}`);
3328
- }
3329
- }
3330
- while (operatorStack.length > 0) {
3331
- outputQueue.push(operatorStack.pop());
3332
- }
3333
- const calcStack = [];
3334
- for (let token of outputQueue) {
3335
- if (typeof token === "string") {
3336
- const b = calcStack.pop();
3337
- const a = calcStack.pop();
3338
- switch (token) {
3339
- case "+":
3340
- calcStack.push(a.add(b));
3341
- break;
3342
- case "-":
3343
- calcStack.push(a.sub(b));
3344
- break;
3345
- case "*":
3346
- calcStack.push(a.mul(b));
3347
- break;
3348
- case "/":
3349
- if (b.eq(0))
3350
- throw new Error("除数不能为零");
3351
- calcStack.push(a.div(b));
3352
- break;
3353
- }
3354
- } else {
3355
- calcStack.push(token);
3356
- }
3357
- }
3358
- return calcStack.pop();
3359
- };
3360
- try {
3361
- const result = evaluate(expression);
3362
- return Number(result.toFixed(point, Decimal.ROUND_DOWN));
3363
- } catch (error) {
3364
- throw new Error("表达式计算失败:" + error.message);
3365
- }
3366
- };
3367
- const LibJsEmitter = () => {
3368
- const _eventMap = /* @__PURE__ */ new Map();
3369
- const on = (event, listener) => {
3370
- if (!_eventMap.has(event)) {
3371
- _eventMap.set(event, []);
3372
- }
3373
- _eventMap.get(event).push(listener);
3374
- };
3375
- const emit = (event, ...args) => {
3376
- var _a;
3377
- (_a = _eventMap.get(event)) == null ? void 0 : _a.forEach((listener) => listener(...args));
3378
- };
3379
- const off = (event, listener) => {
3380
- if (!listener) {
3381
- _eventMap.delete(event);
3382
- } else {
3383
- const listeners = _eventMap.get(event);
3384
- if (listeners) {
3385
- _eventMap.set(
3386
- event,
3387
- listeners.filter((l) => l !== listener)
3388
- );
3389
- }
3390
- }
3391
- };
3392
- const clear = () => _eventMap.clear();
3393
- return { on, emit, off, clear };
3394
- };
3395
- const LibJsLerp = (start, end, value) => {
3396
- const t = Math.min(Math.max(value, 0), 1);
3397
- return start * (1 - t) + end * t;
3398
- };
3399
- const LibJsNormalizeInRange = (start, end, value) => {
3400
- return Math.max(0, Math.min((start - value) / (start - end), 1));
3401
- };
3402
- class LibJsClassObservable {
3403
- /**
3404
- * @param initialData 监听的数据
3405
- */
3406
- constructor(initialData) {
3407
- this.listeners = /* @__PURE__ */ new Map();
3408
- this.index = 0;
3409
- this.data = { ...initialData };
3410
- }
3411
- /** @description 获取值、
3412
- * @param key 要获取的键
3413
- * @returns 对应的值
3414
- */
3415
- getValue(key) {
3416
- return this.data[key];
3417
- }
3418
- /** @description 设置值
3419
- * @param key 要设置的键
3420
- * @param value 要设置的值
3421
- * @param immediately 是否立即通知监听器
3422
- * @returns 设置后的值
3423
- */
3424
- setValue(key, value, immediately = true) {
3425
- var _a;
3426
- const oldValue = this.data[key];
3427
- if (oldValue === value)
3428
- return value;
3429
- this.data[key] = value;
3430
- immediately && ((_a = this.listeners.get(key)) == null ? void 0 : _a.forEach((fn) => fn(value, oldValue)));
3431
- return value;
3432
- }
3433
- /** @description 监听值
3434
- * @param key 要监听的键
3435
- * @param callback 回调函数
3436
- * @param immediately 是否立即触发一次回调函数
3437
- * @returns 取消监听的函数
3438
- */
3439
- onValue(key, callback, immediately = true) {
3440
- const id = this.index++;
3441
- if (!this.listeners.has(key)) {
3442
- this.listeners.set(key, /* @__PURE__ */ new Map());
3443
- }
3444
- this.listeners.get(key).set(id, callback);
3445
- immediately && callback(this.data[key], this.data[key]);
3446
- return () => {
3447
- this.listeners.get(key).delete(id);
3448
- };
3449
- }
3450
- /** @description 触发某个键名的所有回调函数,适用于同时监听了多个值的场景,用于切换要显示的值,或者延迟在特定时机通知监听器
3451
- * @param key 要触发的键名
3452
- * @returns 触发的键值
3453
- */
3454
- updateFake(key) {
3455
- var _a;
3456
- const value = this.data[key];
3457
- (_a = this.listeners.get(key)) == null ? void 0 : _a.forEach((fn) => fn(value, value));
3458
- return value;
3459
- }
3460
- /** @description 数字类型的键值累加或累减
3461
- * @param key 要累加或累减的键
3462
- * @param type 要累加还是要累减
3463
- * @param value 要累加或累减的值
3464
- * @param immediately 是否立即通知监听器
3465
- */
3466
- setNumberValue(key, type, value = 1, immediately = true) {
3467
- let v;
3468
- if (type === "add") {
3469
- v = libJsDecimal(this.data[key], value, "+");
3470
- this.setValue(key, v, immediately);
3471
- } else {
3472
- v = libJsDecimal(this.data[key], value, "-");
3473
- this.setValue(key, v, immediately);
3474
- }
3475
- return v;
3476
- }
3477
- /** @description 针对布尔类型的键值取反
3478
- * @param key 要取反的键
3479
- * @param immediately 是否立即通知监听器
3480
- */
3481
- setBooleanValue(key, immediately = true) {
3482
- const v = !this.data[key];
3483
- this.setValue(key, v, immediately);
3484
- return v;
3485
- }
3486
- }
3487
- const fallbackCopy = (text) => {
3488
- const textarea = document.createElement("textarea");
3489
- textarea.value = text;
3490
- textarea.style.position = "fixed";
3491
- textarea.style.opacity = "0";
3492
- document.body.appendChild(textarea);
3493
- textarea.select();
3494
- document.execCommand("copy");
3495
- document.body.removeChild(textarea);
3496
- };
3497
- const libJsCopy = (text) => {
3498
- if (navigator.clipboard) {
3499
- navigator.clipboard.writeText(text).catch(() => fallbackCopy(text));
3500
- } else {
3501
- fallbackCopy(text);
3502
- }
3503
- };
3504
- class LibJsResizeWatcher {
3505
- constructor(mode = "hv") {
3506
- this._listeners = [];
3507
- this._handleResize = () => {
3508
- const w = window.innerWidth;
3509
- const h = window.innerHeight;
3510
- let s;
3511
- const orientation = w > h ? "h" : "v";
3512
- if (orientation === "h") {
3513
- s = Math.min(w / 1920, h / 1080);
3514
- } else {
3515
- s = Math.min(w / 1080, h / 1920);
3516
- }
3517
- this._listeners.forEach(({ cb }) => cb(w, h, s));
3518
- };
3519
- this._mode = mode;
3520
- if (mode === "h" || mode === "v")
3521
- return;
3522
- window.addEventListener("resize", this._handleResize);
3523
- window.addEventListener("orientationchange", this._handleResize);
3524
- }
3525
- /**
3526
- * @description 注册一个窗口尺寸变化的监听器
3527
- * @param cb 回调函数,参数为当前窗口宽度和高度
3528
- * @param immediate 是否在注册时立即执行一次回调,默认为 true
3529
- * @returns 一个函数,用于移除该监听器
3530
- */
3531
- on(cb, immediate = true) {
3532
- const w = window.innerWidth;
3533
- const h = window.innerHeight;
3534
- const orientation = w > h ? "h" : "v";
3535
- if (this._mode === "h") {
3536
- immediate && cb(1920, 1080, Math.min(w / 1920, h / 1080));
3537
- return () => {
3538
- };
3539
- } else if (this._mode === "v") {
3540
- immediate && cb(1080, 1920, Math.min(w / 1080, h / 1920));
3541
- return () => {
3542
- };
3543
- }
3544
- let s;
3545
- if (orientation === "h") {
3546
- s = Math.min(w / 1920, h / 1080);
3547
- } else {
3548
- s = Math.min(w / 1080, h / 1920);
3549
- }
3550
- const item = { cb, immediate };
3551
- this._listeners.push(item);
3552
- if (immediate)
3553
- cb(window.innerWidth, window.innerHeight, s);
3554
- return () => {
3555
- this._listeners = this._listeners.filter((l) => l !== item);
3556
- };
3557
- }
3558
- }
3559
- class LibJsPullUpLoad extends LibJsClassObservable {
3560
- constructor(params) {
3561
- super({
3562
- statusText: "加载中...",
3563
- loadStatus: "idle"
3564
- });
3565
- const { scrollEl, loadStatusEl, onLoad } = params;
3566
- this.checkAutoLoad(onLoad, scrollEl);
3567
- this.onValue("loadStatus", (v) => {
3568
- if (v === "idle") {
3569
- this.checkAutoLoad(onLoad, scrollEl);
3570
- }
3571
- });
3572
- scrollEl.addEventListener("scroll", () => {
3573
- if (["noMore", "empty", "loading"].includes(this.getValue("loadStatus")))
3574
- return;
3575
- const y = scrollEl.scrollTop;
3576
- const loadDistance = scrollEl.scrollHeight - scrollEl.clientHeight - y - loadStatusEl.offsetHeight;
3577
- if (loadDistance <= 0) {
3578
- this.setValue("loadStatus", "loading");
3579
- this.setValue("statusText", "加载中...");
3580
- setTimeout(() => {
3581
- onLoad();
3582
- }, 500);
3583
- }
3584
- });
3585
- }
3586
- // 1. 新增方法
3587
- checkAutoLoad(onLoad, scrollEl) {
3588
- if (!["noMore", "empty", "loading"].includes(this.getValue("loadStatus")) && scrollEl.scrollHeight <= scrollEl.clientHeight) {
3589
- this.setValue("loadStatus", "loading");
3590
- this.setValue("statusText", "加载中...");
3591
- setTimeout(() => {
3592
- onLoad();
3593
- }, 500);
3594
- }
3595
- }
3596
- }
3597
- const libJsPickUnique = (pool, used = []) => {
3598
- const usedSet = new Set(used);
3599
- const available = pool.filter((item) => !usedSet.has(item));
3600
- if (available.length === 0)
3601
- return void 0;
3602
- return available[libJsRandom(0, available.length - 1)];
3603
- };
3604
- dayjs.extend(duration);
3605
- const libJsCountdown = (endTime) => {
3606
- const startTime = dayjs();
3607
- const diff = dayjs(endTime).diff(startTime);
3608
- const time = dayjs.duration(diff);
3609
- const pad = (n) => n.toString().padStart(2, "0");
3610
- return {
3611
- years: pad(time.years()),
3612
- months: pad(time.months()),
3613
- days: pad(time.days()),
3614
- hours: pad(time.hours()),
3615
- minutes: pad(time.minutes()),
3616
- seconds: pad(time.seconds()),
3617
- ended: diff <= 0
3618
- };
3619
- };
3620
- const Base = {
3621
- /**
3622
- * @description 返回数据类型
3623
- * @param v 需要判断类型的数据
3624
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
3625
- */
3626
- libJsGetDataType,
3627
- /**
3628
- * @description 延时执行,切换到其他页面会暂停
3629
- * @param delay 延时毫秒数
3630
- * @param fn 延时执行函数
3631
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPromiseTimeout-延时执行
3632
- */
3633
- libJsPromiseTimeout,
3634
- /** @description 监听窗口变化,内部只注册一次resize事件,调用监听自身可取消监听 */
3635
- LibJsResizeWatcher
3636
- };
3637
- const Browser = {
3638
- /** @description console颜色打印
3639
- * @param title 标题
3640
- * @param color 颜色
3641
- * @param logs 信息
3642
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
3643
- */
3644
- libJsColorConsole,
3645
- /** @description 判断是否为移动设备
3646
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsIsMobile-判断手机
3647
- */
3648
- libJsIsMobile,
3649
- /** @description 判断是否为平板
3650
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsIsPad-判断平板
3651
- */
3652
- libJsIsPad,
3653
- /** @description 获取浏览器地址栏参数
3654
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPathParams-地址栏参数
3655
- */
3656
- libJsPathParams,
3657
- /** @description 动态设置网站标题及图标
3658
- * @param title 网站标题
3659
- * @param url 网站图标地址
3660
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSetTitleIcon-网站标题图标
3661
- */
3662
- libJsSetTitleIcon,
3663
- /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
3664
- * @param backTitle 从其他网页返回时显示的标题
3665
- * @param leaveTitle 从当前网页离开时显示的标题
3666
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTagTitleTip-网站标题交互
3667
- */
3668
- libJsTagTitleTip,
3669
- /** @description 对象转为url参数
3670
- * @param params 对象参数
3671
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
3672
- */
3673
- libJsObjToUrlParams,
3674
- /** @description 复制文本到剪贴板
3675
- * @param text 要复制的文本
3676
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#libJsCopy-复制文本到剪贴板
3677
- */
3678
- libJsCopy
3679
- };
3680
- const Data = {
3681
- /**
3682
- * @description 将数组拆分成指定数组元素数量的多个数组
3683
- * @param arr 需要拆分的数组
3684
- * @param chunkSize 每个数组的元素数量
3685
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsChunkArray-数组拆分
3686
- */
3687
- libJsChunkArray,
3688
- /** @description 递归将JSON字符串深度解析为对象
3689
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDeepJSONParse-深度解析JSON
3690
- */
3691
- libJsDeepJSONParse,
3692
- /**
3693
- * @description 分类汇总,将数组对象按照指定键值整理成一个以键值为键名的对象
3694
- * @param arr 要分组的数组
3695
- * @param key 分组的键
3696
- * @returns 分组后的对象
3697
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsGroupArrayByKey-分类汇总
3698
- */
3699
- libJsGroupArrayByKey,
3700
- /**
3701
- * @description 匹配电子邮件,可用于实时输入时,自动补全常用邮箱后缀
3702
- * @param str 要匹配的字符串
3703
- * @param emailList 电子邮件后缀列表
3704
- * @returns 匹配结果数组
3705
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsMatchEmail-匹配E-Mail
3706
- */
3707
- libJsMatchEmail,
3708
- /** @description 数组乱序
3709
- * @param arr 需要乱序的数组
3710
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsShuffleArray-数组乱序
3711
- */
3712
- libJsShuffleArray,
3713
- /** @description 数组元素整体步数移动
3714
- * @param arr 移动的数组
3715
- * @param step 负数为向后移动,正数为向前移动
3716
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsStepArray-数组偏移
3717
- */
3718
- libJsStepArray,
3719
- /** @description 翻转指定索引后面的数组
3720
- * @param arr 数组
3721
- * @param index 开始索引
3722
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibReverseArrayFromIndex-数组定位翻转
3723
- */
3724
- libReverseArrayFromIndex,
3725
- /** @description 随机选择未使用元素 */
3726
- libJsPickUnique
3727
- };
3728
- const File$1 = {
3729
- /** @description 下载图片链接
3730
- * @param link 图片链接
3731
- * @param name 图片名称
3732
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDownloadImageLink-图片下载
3733
- */
3734
- libJsDownloadImageLink,
3735
- /** @description 图片压缩
3736
- * @param obj 压缩参数
3737
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsImageOptimizer-图片压缩
3738
- */
3739
- libJsImageOptimizer,
3740
- /**
3741
- * @description 保存文件到本地
3742
- * @param data 要保存的数据
3743
- * @param name 文件名
3744
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSaveJson-保存文件
3745
- */
3746
- libJsSaveJson
3747
- };
3748
- const Formatter = {
3749
- /**
3750
- * @description 格式化字节大小
3751
- * @param bytes 字节数
3752
- * @returns ['大小', '单位', '大小及单位']
3753
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsFormatterByte-字节格式化
3754
- */
3755
- libJsFormatterByte,
3756
- /**
3757
- * @description 隐藏手机号码中间的四位数字
3758
- * @param mobile 需要处理的手机号码
3759
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsMaskPhoneNumber-隐藏手机号码
3760
- */
3761
- libJsMaskPhoneNumber,
3762
- /**
3763
- * @description 数字每三位添加逗号
3764
- * @param num 需要格式化的数字
3765
- * @param reserve 保留小数位数
3766
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumComma-数字逗号
3767
- */
3768
- libJsNumComma,
3769
- /** @description 将大于1000的数字使用k为单位
3770
- * @param num 数字
3771
- * @param units 单位组,key为单位,value为格式化阈值
3772
- * @returns [数字, 单位]
3773
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumberUnit-数字单位
3774
- */
3775
- libJsNumberUnit,
3776
- /**
3777
- * @description 将秒数格式化为中文时间描述,支持扩展到年和月
3778
- * @param seconds 秒数
3779
- * @returns 格式化后的中文时间
3780
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSecondsFormatterChinese-中文时间
3781
- */
3782
- libJsSecondsFormatterChinese
3783
- };
3784
- const Math$1 = {
3785
- /** @description 计算表达式字符串
3786
- * @param expression 表达式字符串
3787
- * @param point 小数点精度
3788
- * @returns 计算结果
3789
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCalculateExpression-表达式字符串
3790
- */
3791
- libJsCalculateExpression,
3792
- /**
3793
- * @description 角度和弧度互相转换
3794
- * @param value 角度值或弧度值
3795
- * @param type 角度类型或弧度类型
3796
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsConvertAngle-角弧度互转
3797
- */
3798
- libJsConvertAngle,
3799
- /** @description 计算两点角度
3800
- * @param coord1 起点坐标
3801
- * @param coord2 终点坐标
3802
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsAngle-两点角度
3803
- */
3804
- libJsCoordsAngle,
3805
- /** @description 计算两点距离
3806
- * @param coord1 起点坐标
3807
- * @param coord2 终点坐标
3808
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsDistance-两点距离
3809
- */
3810
- libJsCoordsDistance,
3811
- /** @description 计算两个数的运算结果,并保留指定位数的小数
3812
- * @param num1 第一个数
3813
- * @param num2 第二个数
3814
- * @param operator 运算符,支持加减乘除
3815
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDecimal-高精度计算
3816
- */
3817
- libJsDecimal
3818
- };
3819
- const Misc = {
3820
- /**
3821
- * @description 表单验证函数
3822
- * @param form 表单数据对象
3823
- * @param rules 验证规则数组
3824
- * @returns 验证结果数组,包含未通过验证的项
3825
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRegFormValidate-表单验证
3826
- */
3827
- libJsRegFormValidate,
3828
- /** @description 请求失败重连
3829
- * @param promiseFn 请求函数
3830
- * @param maxRetries 最大重试次数
3831
- * @param retryDelay 重试间隔时间
3832
- * @param params 请求参数
3833
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRetryRequest-请求重连
3834
- */
3835
- libJsRetryRequest,
3836
- /** @description 数字步进器
3837
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumberStepper-数字步进器
3838
- */
3839
- LibJsNumberStepper,
3840
- /** @description 线性插值
3841
- * @param start 当 value = 0 时,返回 start
3842
- * @param end 当 value = 1 时,返回 end
3843
- * @param value 插值比例,取值范围 0~1
3844
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsLerp-线性插值
3845
- */
3846
- LibJsLerp,
3847
- /** @description 值介于起点与终点之间时返回一个介于0与1之间的数
3848
- * @param start 起点
3849
- * @param end 终点
3850
- * @param value 动态值
3851
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNormalizeInRange-范围归一化
3852
- */
3853
- LibJsNormalizeInRange,
3854
- /** @description 事件发射器
3855
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsEmitter-事件发射器
3856
- */
3857
- LibJsEmitter,
3858
- /** @description 类属性监听器
3859
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsClassObservable-类属性监听器
3860
- */
3861
- LibJsClassObservable,
3862
- /** @description 上拉加载 */
3863
- LibJsPullUpLoad
3864
- };
3865
- const Random = {
3866
- /** @description 百分比概率结果
3867
- * @param probability 触发概率,百分比,0-100
3868
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsProbabilityResult-概率触发
3869
- */
3870
- libJsProbabilityResult,
3871
- /** @description 随机数
3872
- * @param min 最小值
3873
- * @param max 最大值
3874
- * @param num 保留小数位数
3875
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandom-随机数
3876
- */
3877
- libJsRandom,
3878
- /** @description 随机 RGBA 颜色
3879
- * @param alpha 透明度
3880
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandomColor-随机色
3881
- */
3882
- libJsRandomColor,
3883
- /** @description 随机生成n个指定范围的随机数数组
3884
- * @param min 最小值
3885
- * @param max 最大值
3886
- * @param count 数组长度
3887
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsUniqueRandomNumbers-随机数数组
3888
- */
3889
- libJsUniqueRandomNumbers
3890
- };
3891
- const Time = {
3892
- /**
3893
- * @description 传入时间戳与当前时间判断是否为同一天或同一周
3894
- * @param timestamp 毫秒时间戳
3895
- * @param unit 判断单位
3896
- * @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
3897
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSameTimeCheck-时间比对
3898
- */
3899
- libJsSameTimeCheck,
3900
- /** @description 时间差计算
3901
- * @param timestamp 毫秒时间戳
3902
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeAgo-中文时间差
3903
- */
3904
- libJsTimeAgo,
3905
- /**
3906
- * @description 根据当前时间返回问候语
3907
- * @param greet 自定义问候语对象
3908
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
3909
- */
3910
- libJsTimeGreeting,
3911
- /** @description 倒计时
3912
- * @param endTime 毫秒时间戳
3913
- */
3914
- libJsCountdown
3915
- };
3916
- const LibJs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3917
- __proto__: null,
3918
- Base,
3919
- Browser,
3920
- Data,
3921
- File: File$1,
3922
- Formatter,
3923
- Math: Math$1,
3924
- Misc,
3925
- Random,
3926
- Time
3927
- }, Symbol.toStringTag, { value: "Module" }));
3928
- window.LibJs = LibJs;
3929
- });