@wzyjs/utils 0.3.3 → 0.3.6

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.
Files changed (39) hide show
  1. package/dist/common/base/index.d.ts +6 -0
  2. package/dist/common/index.d.ts +2 -10
  3. package/dist/node.cjs.js +281 -2764
  4. package/dist/node.d.ts +11 -2
  5. package/dist/node.esm.js +287 -2768
  6. package/dist/{browser.cjs.js → web.cjs.js} +18049 -20116
  7. package/dist/web.d.ts +15 -0
  8. package/dist/{browser.esm.js → web.esm.js} +17962 -20027
  9. package/package.json +14 -14
  10. package/dist/ai/index.d.ts +0 -1
  11. package/dist/ai/midjourney/index.d.ts +0 -1
  12. package/dist/ai/midjourney/utils.d.ts +0 -12
  13. package/dist/browser/index.d.ts +0 -10
  14. package/dist/browser.d.ts +0 -2
  15. package/dist/node/index.d.ts +0 -6
  16. /package/dist/{ai → common/ai}/302/axios.d.ts +0 -0
  17. /package/dist/{ai → common/ai}/302/chat/index.d.ts +0 -0
  18. /package/dist/{ai → common/ai}/302/image/index.d.ts +0 -0
  19. /package/dist/{ai → common/ai}/302/image/midjourney.d.ts +0 -0
  20. /package/dist/{ai → common/ai}/302/index.d.ts +0 -0
  21. /package/dist/{ai → common/ai}/keling/axios.d.ts +0 -0
  22. /package/dist/{ai → common/ai}/keling/index.d.ts +0 -0
  23. /package/dist/{ai → common/ai}/keling/utils.d.ts +0 -0
  24. /package/dist/common/{array.d.ts → base/array.d.ts} +0 -0
  25. /package/dist/common/{number.d.ts → base/number.d.ts} +0 -0
  26. /package/dist/common/{object.d.ts → base/object.d.ts} +0 -0
  27. /package/dist/common/{other.d.ts → base/other.d.ts} +0 -0
  28. /package/dist/common/{promise.d.ts → base/promise.d.ts} +0 -0
  29. /package/dist/common/{string.d.ts → base/string.d.ts} +0 -0
  30. /package/dist/node/{cron/index.d.ts → cron.d.ts} +0 -0
  31. /package/dist/node/{file/index.d.ts → file.d.ts} +0 -0
  32. /package/dist/node/{mail/index.d.ts → mail.d.ts} +0 -0
  33. /package/dist/node/{oss/index.d.ts → oss.d.ts} +0 -0
  34. /package/dist/{common → web}/antd.d.ts +0 -0
  35. /package/dist/{browser/other.d.ts → web/clipboard.d.ts} +0 -0
  36. /package/dist/{browser → web}/download.d.ts +0 -0
  37. /package/dist/{browser → web}/element.d.ts +0 -0
  38. /package/dist/{browser → web}/location.d.ts +0 -0
  39. /package/dist/{browser → web}/style.d.ts +0 -0
package/dist/node.esm.js CHANGED
@@ -1189,7 +1189,7 @@ var require_lodash = __commonJS((exports, module) => {
1189
1189
  if (typeof func != "function") {
1190
1190
  throw new TypeError2(FUNC_ERROR_TEXT);
1191
1191
  }
1192
- return setTimeout2(function() {
1192
+ return setTimeout(function() {
1193
1193
  func.apply(undefined2, args);
1194
1194
  }, wait);
1195
1195
  }
@@ -2998,7 +2998,7 @@ var require_lodash = __commonJS((exports, module) => {
2998
2998
  return object[key];
2999
2999
  }
3000
3000
  var setData = shortOut(baseSetData);
3001
- var setTimeout2 = ctxSetTimeout || function(func, wait) {
3001
+ var setTimeout = ctxSetTimeout || function(func, wait) {
3002
3002
  return root.setTimeout(func, wait);
3003
3003
  };
3004
3004
  var setToString = shortOut(baseSetToString);
@@ -3788,7 +3788,7 @@ var require_lodash = __commonJS((exports, module) => {
3788
3788
  }
3789
3789
  function leadingEdge(time) {
3790
3790
  lastInvokeTime = time;
3791
- timerId = setTimeout2(timerExpired, wait);
3791
+ timerId = setTimeout(timerExpired, wait);
3792
3792
  return leading ? invokeFunc(time) : result2;
3793
3793
  }
3794
3794
  function remainingWait(time) {
@@ -3804,7 +3804,7 @@ var require_lodash = __commonJS((exports, module) => {
3804
3804
  if (shouldInvoke(time)) {
3805
3805
  return trailingEdge(time);
3806
3806
  }
3807
- timerId = setTimeout2(timerExpired, remainingWait(time));
3807
+ timerId = setTimeout(timerExpired, remainingWait(time));
3808
3808
  }
3809
3809
  function trailingEdge(time) {
3810
3810
  timerId = undefined2;
@@ -3835,12 +3835,12 @@ var require_lodash = __commonJS((exports, module) => {
3835
3835
  }
3836
3836
  if (maxing) {
3837
3837
  clearTimeout(timerId);
3838
- timerId = setTimeout2(timerExpired, wait);
3838
+ timerId = setTimeout(timerExpired, wait);
3839
3839
  return invokeFunc(lastCallTime);
3840
3840
  }
3841
3841
  }
3842
3842
  if (timerId === undefined2) {
3843
- timerId = setTimeout2(timerExpired, wait);
3843
+ timerId = setTimeout(timerExpired, wait);
3844
3844
  }
3845
3845
  return result2;
3846
3846
  }
@@ -4047,7 +4047,7 @@ var require_lodash = __commonJS((exports, module) => {
4047
4047
  var tag = baseGetTag(value);
4048
4048
  return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject(value);
4049
4049
  }
4050
- function isFinite2(value) {
4050
+ function isFinite(value) {
4051
4051
  return typeof value == "number" && nativeIsFinite(value);
4052
4052
  }
4053
4053
  function isFunction(value) {
@@ -4078,7 +4078,7 @@ var require_lodash = __commonJS((exports, module) => {
4078
4078
  customizer = typeof customizer == "function" ? customizer : undefined2;
4079
4079
  return baseIsMatch(object, source, getMatchData(source), customizer);
4080
4080
  }
4081
- function isNaN2(value) {
4081
+ function isNaN(value) {
4082
4082
  return isNumber(value) && value != +value;
4083
4083
  }
4084
4084
  function isNative(value) {
@@ -4737,7 +4737,7 @@ __p += '`;
4737
4737
  }
4738
4738
  return result2 + omission;
4739
4739
  }
4740
- function unescape2(string) {
4740
+ function unescape(string) {
4741
4741
  string = toString(string);
4742
4742
  return string && reHasEscapedHtml.test(string) ? string.replace(reEscapedHtml, unescapeHtmlChar) : string;
4743
4743
  }
@@ -5161,14 +5161,14 @@ __p += '`;
5161
5161
  lodash.isEqual = isEqual;
5162
5162
  lodash.isEqualWith = isEqualWith;
5163
5163
  lodash.isError = isError;
5164
- lodash.isFinite = isFinite2;
5164
+ lodash.isFinite = isFinite;
5165
5165
  lodash.isFunction = isFunction;
5166
5166
  lodash.isInteger = isInteger;
5167
5167
  lodash.isLength = isLength;
5168
5168
  lodash.isMap = isMap;
5169
5169
  lodash.isMatch = isMatch;
5170
5170
  lodash.isMatchWith = isMatchWith;
5171
- lodash.isNaN = isNaN2;
5171
+ lodash.isNaN = isNaN;
5172
5172
  lodash.isNative = isNative;
5173
5173
  lodash.isNil = isNil;
5174
5174
  lodash.isNull = isNull;
@@ -5250,7 +5250,7 @@ __p += '`;
5250
5250
  lodash.trimEnd = trimEnd;
5251
5251
  lodash.trimStart = trimStart;
5252
5252
  lodash.truncate = truncate;
5253
- lodash.unescape = unescape2;
5253
+ lodash.unescape = unescape;
5254
5254
  lodash.uniqueId = uniqueId;
5255
5255
  lodash.upperCase = upperCase;
5256
5256
  lodash.upperFirst = upperFirst;
@@ -5441,11 +5441,13 @@ __p += '`;
5441
5441
  }).call(exports);
5442
5442
  });
5443
5443
 
5444
- // src/common/index.ts
5444
+ // src/node.ts
5445
5445
  var import_lodash = __toESM(require_lodash(), 1);
5446
- import { default as default3 } from "axios";
5447
- import { default as default4 } from "json5";
5448
- import { default as default5 } from "consola";
5446
+ import { default as default2, DataStoreOptions } from "nedb";
5447
+ import * as cheerio from "cheerio";
5448
+ import { default as default4 } from "axios";
5449
+ import { default as default5 } from "json5";
5450
+ import { default as default6 } from "consola";
5449
5451
 
5450
5452
  // ../../node_modules/zod/v3/external.js
5451
5453
  var exports_external = {};
@@ -9420,2682 +9422,280 @@ var coerce = {
9420
9422
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
9421
9423
  };
9422
9424
  var NEVER = INVALID;
9423
- // src/common/string.ts
9424
- var getChineseByStr = (str) => {
9425
- if (!str) {
9426
- return "";
9427
- }
9428
- const match = str.match(/[\u4e00-\u9fa5]/g);
9429
- if (!match) {
9430
- return "";
9431
- }
9432
- return match.join("");
9433
- };
9434
- var getStrLength = (value) => {
9435
- if (!value) {
9436
- return 0;
9437
- }
9438
- const chineseLength = getChineseByStr(value).length;
9439
- return value.length - chineseLength + chineseLength * 2;
9440
- };
9441
- var replaceAll = (str, searchValue, replaceValue) => {
9442
- if (!str || !searchValue || !replaceValue) {
9443
- return str || "";
9444
- }
9445
- str = str.replace(searchValue, replaceValue);
9446
- if (!str.includes(searchValue)) {
9447
- return str;
9425
+ // src/common/ai/302/axios.ts
9426
+ import axios_ from "axios";
9427
+ var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
9428
+ var axios = axios_.create({
9429
+ baseURL: "https://api.302.ai",
9430
+ headers: {
9431
+ "mj-api-secret": key,
9432
+ Authorization: `Bearer ${key}`
9448
9433
  }
9449
- return replaceAll(str, searchValue, replaceValue);
9450
- };
9451
- var replaceByRules = (str, rules) => {
9452
- rules.forEach(([searchValue, replaceValue]) => {
9453
- str = str.replaceAll(searchValue, replaceValue);
9454
- });
9455
- return str;
9456
- };
9457
- var replaceByVariables = (prompt, variables) => {
9458
- if (!variables || Object.keys(variables).length === 0) {
9459
- return prompt;
9434
+ });
9435
+
9436
+ // src/common/ai/302/chat/index.ts
9437
+ import json5 from "json5";
9438
+ var chat = async (message, model = "gpt-4.1", isParse = true) => {
9439
+ try {
9440
+ let { data } = await axios({
9441
+ url: "/v1/chat/completions",
9442
+ method: "post",
9443
+ data: {
9444
+ model,
9445
+ message
9446
+ }
9447
+ });
9448
+ console.log(666, typeof data, data);
9449
+ const output = typeof data === "string" ? json5.parse(data)?.output : data?.output;
9450
+ if (isParse) {
9451
+ const match = /```(json)?(.*)```/s.exec(output);
9452
+ if (!match) {
9453
+ return json5.parse(output);
9454
+ } else {
9455
+ return json5.parse(match[2]);
9456
+ }
9457
+ }
9458
+ return output;
9459
+ } catch (error) {
9460
+ throw new Error(error?.response?.statusText || error?.message || "未知原因");
9460
9461
  }
9461
- const regex = /\{\{\s*(\w+)\s*\}\}/g;
9462
- return prompt.replace(regex, (match, p1) => {
9463
- return variables[p1] ?? match;
9464
- });
9465
- };
9466
- var getType = (value) => {
9467
- return Object.prototype.toString.call(value).slice(8, -1);
9468
9462
  };
9469
- var amount = (str) => {
9470
- const reg = /(?=(?!\b)(\d{3})+$)/g;
9471
- return str.replace(reg, ",");
9472
- };
9473
- var jsonParse = (value) => {
9474
- if (typeof value === "object") {
9475
- return value;
9463
+ // src/common/ai/keling/utils.ts
9464
+ import * as url from "url";
9465
+ import * as path from "path";
9466
+
9467
+ // src/common/ai/keling/axios.ts
9468
+ import axios_2 from "axios";
9469
+ var axios2 = axios_2.create({
9470
+ headers: {
9471
+ "Content-Type": "application/json",
9472
+ Cookie: "weblogger_did=web_52354269549862D; did=web_d22eeae73f6e4c74a76a4cc98e3a1188a5b0; anonymous-message-release-notice-1=true; anonymous-message-release-notice-2=true; dev-center-view-welcome-dialog-key=true; userId=2904283585; welcome-future-partner-key=true; old-user-time=1731936878621; kuaishou.ai.portal_st=ChVrdWFpc2hvdS5haS5wb3J0YWwuc3QSoAFuUNTARKNKXARahOJhWZ4iVBl2mIANSUfk2nCSr85bxCg2lrpE3PHj2Kn_kjPW0_KV8DfZS6UnNam4i6gaYeBmxRwOVAldYysCz7YtlsosEZRuiTe2iY7Ziq5SZeAP7jhTg8lxk7gvC-bEELmAc8HSrqN5HLWeU4GUFcEq-ChV7qsodJ8m42oBuvkFgX1qytVTIROpSS4cMmEiBhB3h99EGhLGi0v_iyPMOr2JVXM8LPzBvxQiIJrnuzAheyLtkeb55iZOUgZoAzXjYj0U1e4mLSonbXBGKAUwAQ; kuaishou.ai.portal_ph=2669d9adaa5c0629ac1053ab87e6c123880a"
9476
9473
  }
9474
+ });
9475
+
9476
+ // src/common/ai/keling/utils.ts
9477
+ var getToken = async (filename) => {
9477
9478
  try {
9478
- return JSON.parse(value);
9479
- } catch (err) {
9480
- return {};
9479
+ const response = await axios2.get("https://klingai.kuaishou.com/api/upload/issue/token", {
9480
+ params: { filename }
9481
+ });
9482
+ return response.data.data.token;
9483
+ } catch (error) {
9484
+ console.error("获取 token 失败:", error);
9485
+ throw error;
9481
9486
  }
9482
9487
  };
9483
- var isJson = (str) => {
9488
+ var uploadFragment = async (uploadToken, imageBuffer) => {
9484
9489
  try {
9485
- if (getType(JSON.parse(str)) === "Object") {
9486
- return true;
9487
- }
9488
- } catch (e) {}
9489
- return false;
9490
- };
9491
- var toString = (value) => {
9492
- return Object.prototype.toString.call(value).slice(8, -1) === "object" ? JSON.stringify(value) : String(value);
9493
- };
9494
- var getRandomColor = () => {
9495
- const color = Math.floor(Math.random() * 16777215).toString(16);
9496
- if (color.length === 6) {
9497
- return color;
9498
- } else {
9499
- return getRandomColor();
9500
- }
9501
- };
9502
- var getRandomString = (length = 4) => {
9503
- return Math.random().toString(36).substr(2, length);
9504
- };
9505
- var getChinese = (str) => {
9506
- if (str == null || str === "") {
9507
- return "";
9508
- }
9509
- const res = str.match(/[\u4e00-\u9fa5]/g);
9510
- if (!res) {
9511
- return "";
9490
+ const response = await axios2.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
9491
+ params: {
9492
+ upload_token: uploadToken,
9493
+ fragment_id: 0
9494
+ },
9495
+ headers: {
9496
+ "Content-Type": "application/octet-stream"
9497
+ }
9498
+ });
9499
+ return response.data;
9500
+ } catch (error) {
9501
+ console.error("上传片段失败:", error);
9502
+ throw error;
9512
9503
  }
9513
- return res.join("");
9514
9504
  };
9515
- var getSliceStr = (str, before, after) => {
9516
- return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
9517
- };
9518
- var getProxyUrl = (url) => {
9519
- const beforeUrl = "https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=";
9520
- return beforeUrl + url;
9521
- };
9522
- var getLength = (value) => {
9523
- const chineseLength = getChinese(value).length;
9524
- return value.length - chineseLength + chineseLength * 2;
9525
- };
9526
- var getCookie = (name) => {
9527
- const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
9528
- const arr = document.cookie.match(reg);
9529
- return arr ? unescape(arr[2]) : null;
9530
- };
9531
- var generateAlphabetArray = (n) => {
9532
- return Array.from({ length: n }, (_, i) => String.fromCharCode(97 + i));
9533
- };
9534
- var levenshteinDistance = (a, b) => {
9535
- const matrix = [];
9536
- for (let i = 0;i <= b.length; i++) {
9537
- matrix[i] = [i];
9538
- }
9539
- for (let j = 0;j <= a.length; j++) {
9540
- matrix[0][j] = j;
9541
- }
9542
- for (let i = 1;i <= b.length; i++) {
9543
- for (let j = 1;j <= a.length; j++) {
9544
- if (b[i - 1] === a[j - 1]) {
9545
- matrix[i][j] = matrix[i - 1][j - 1];
9546
- } else {
9547
- matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
9505
+ var completeUpload = async (uploadToken) => {
9506
+ try {
9507
+ const response = await axios2.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
9508
+ params: {
9509
+ upload_token: uploadToken,
9510
+ fragment_count: 1
9548
9511
  }
9549
- }
9512
+ });
9513
+ return response.data;
9514
+ } catch (error) {
9515
+ console.error("完成上传失败:", error);
9516
+ throw error;
9550
9517
  }
9551
- return matrix[b.length][a.length];
9552
9518
  };
9553
- var generateUniqueFileName = (name) => {
9554
- const match = name.match(/^(.*?)(\.[^.]*$|$)/);
9555
- if (match) {
9556
- const namePart = match[1];
9557
- const extensionPart = match[2];
9558
- if (extensionPart) {
9559
- return `${namePart}_${Date.now()}${extensionPart}`;
9519
+ var verifyUpload = async (token) => {
9520
+ try {
9521
+ const response = await axios2.get("https://klingai.kuaishou.com/api/upload/verify/token", {
9522
+ params: { token }
9523
+ });
9524
+ if (response.data?.result === 1 && response.data?.data?.status === 3) {
9525
+ return response.data.data?.url;
9560
9526
  } else {
9561
- return `${namePart}_${Date.now()}.dat`;
9527
+ throw new Error(`上传验证失败: ${response.data.message}`);
9562
9528
  }
9529
+ } catch (error) {
9530
+ console.error("获取上传结果失败:", error);
9531
+ throw error;
9563
9532
  }
9564
- throw new Error("Invalid filename format.");
9565
9533
  };
9566
- // src/common/object.ts
9567
- var findItem = (list, attr, value) => {
9568
- return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
9534
+ var downloadImage = async (imageUrl) => {
9535
+ try {
9536
+ const response = await axios2.get(imageUrl, {
9537
+ responseType: "arraybuffer"
9538
+ });
9539
+ return Buffer.from(response.data, "binary");
9540
+ } catch (error) {
9541
+ console.error("下载图片失败:", error);
9542
+ throw error;
9543
+ }
9569
9544
  };
9570
- var filterParams = (params, deep = false) => {
9571
- const clean = (value) => {
9572
- if (value === undefined || value === null) {
9545
+ var uploadImage = async (imageUrl) => {
9546
+ try {
9547
+ const parsedUrl = url.parse(imageUrl);
9548
+ if (!parsedUrl.pathname) {
9573
9549
  return;
9574
9550
  }
9575
- if (!deep) {
9576
- return value;
9577
- }
9578
- if (Array.isArray(value)) {
9579
- return value.map((v) => clean(v)).filter((v) => v !== undefined);
9580
- }
9581
- if (typeof value === "object") {
9582
- return Object.entries(value).reduce((acc, [k, v]) => {
9583
- const cleaned = clean(v);
9584
- if (cleaned !== undefined)
9585
- acc[k] = cleaned;
9586
- return acc;
9587
- }, {});
9588
- }
9589
- return value;
9590
- };
9591
- return clean(params);
9592
- };
9593
- var watch = {
9594
- observe(obj, key, watchFun) {
9595
- const val = obj[key];
9596
- Object.defineProperty(obj, key, {
9597
- configurable: true,
9598
- enumerable: true,
9599
- set(value) {
9600
- obj[key] = value;
9601
- watchFun(value, val);
9602
- },
9603
- get() {
9604
- return val;
9605
- }
9606
- });
9607
- },
9608
- setWatcher(data = {}, watch2 = {}) {
9609
- Object.keys(watch2).forEach((v) => {
9610
- this.observe(data, v, watch2[v]);
9611
- });
9551
+ const filename = path.basename(parsedUrl.pathname);
9552
+ const imageBuffer = await downloadImage(imageUrl);
9553
+ const token = await getToken(filename);
9554
+ await uploadFragment(token, imageBuffer);
9555
+ await completeUpload(token);
9556
+ return await verifyUpload(token);
9557
+ } catch (error) {
9558
+ console.error("上传图片失败:", error);
9559
+ throw error;
9612
9560
  }
9613
9561
  };
9614
- // ../../node_modules/decimal.js/decimal.mjs
9615
- /*!
9616
- * decimal.js v10.6.0
9617
- * An arbitrary-precision Decimal type for JavaScript.
9618
- * https://github.com/MikeMcl/decimal.js
9619
- * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
9620
- * MIT Licence
9621
- */
9622
- var EXP_LIMIT = 9000000000000000;
9623
- var MAX_DIGITS = 1e9;
9624
- var NUMERALS = "0123456789abcdef";
9625
- var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
9626
- var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
9627
- var DEFAULTS = {
9628
- precision: 20,
9629
- rounding: 4,
9630
- modulo: 1,
9631
- toExpNeg: -7,
9632
- toExpPos: 21,
9633
- minE: -EXP_LIMIT,
9634
- maxE: EXP_LIMIT,
9635
- crypto: false
9636
- };
9637
- var inexact;
9638
- var quadrant;
9639
- var external2 = true;
9640
- var decimalError = "[DecimalError] ";
9641
- var invalidArgument = decimalError + "Invalid argument: ";
9642
- var precisionLimitExceeded = decimalError + "Precision limit exceeded";
9643
- var cryptoUnavailable = decimalError + "crypto unavailable";
9644
- var tag = "[object Decimal]";
9645
- var mathfloor = Math.floor;
9646
- var mathpow = Math.pow;
9647
- var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
9648
- var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
9649
- var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
9650
- var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
9651
- var BASE = 1e7;
9652
- var LOG_BASE = 7;
9653
- var MAX_SAFE_INTEGER = 9007199254740991;
9654
- var LN10_PRECISION = LN10.length - 1;
9655
- var PI_PRECISION = PI.length - 1;
9656
- var P = { toStringTag: tag };
9657
- P.absoluteValue = P.abs = function() {
9658
- var x = new this.constructor(this);
9659
- if (x.s < 0)
9660
- x.s = 1;
9661
- return finalise(x);
9662
- };
9663
- P.ceil = function() {
9664
- return finalise(new this.constructor(this), this.e + 1, 2);
9665
- };
9666
- P.clampedTo = P.clamp = function(min, max) {
9667
- var k, x = this, Ctor = x.constructor;
9668
- min = new Ctor(min);
9669
- max = new Ctor(max);
9670
- if (!min.s || !max.s)
9671
- return new Ctor(NaN);
9672
- if (min.gt(max))
9673
- throw Error(invalidArgument + max);
9674
- k = x.cmp(min);
9675
- return k < 0 ? min : x.cmp(max) > 0 ? max : new Ctor(x);
9676
- };
9677
- P.comparedTo = P.cmp = function(y) {
9678
- var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
9679
- if (!xd || !yd) {
9680
- return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
9681
- }
9682
- if (!xd[0] || !yd[0])
9683
- return xd[0] ? xs : yd[0] ? -ys : 0;
9684
- if (xs !== ys)
9685
- return xs;
9686
- if (x.e !== y.e)
9687
- return x.e > y.e ^ xs < 0 ? 1 : -1;
9688
- xdL = xd.length;
9689
- ydL = yd.length;
9690
- for (i = 0, j = xdL < ydL ? xdL : ydL;i < j; ++i) {
9691
- if (xd[i] !== yd[i])
9692
- return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
9693
- }
9694
- return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
9695
- };
9696
- P.cosine = P.cos = function() {
9697
- var pr, rm, x = this, Ctor = x.constructor;
9698
- if (!x.d)
9699
- return new Ctor(NaN);
9700
- if (!x.d[0])
9701
- return new Ctor(1);
9702
- pr = Ctor.precision;
9703
- rm = Ctor.rounding;
9704
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
9705
- Ctor.rounding = 1;
9706
- x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
9707
- Ctor.precision = pr;
9708
- Ctor.rounding = rm;
9709
- return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
9710
- };
9711
- P.cubeRoot = P.cbrt = function() {
9712
- var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
9713
- if (!x.isFinite() || x.isZero())
9714
- return new Ctor(x);
9715
- external2 = false;
9716
- s = x.s * mathpow(x.s * x, 1 / 3);
9717
- if (!s || Math.abs(s) == 1 / 0) {
9718
- n = digitsToString(x.d);
9719
- e = x.e;
9720
- if (s = (e - n.length + 1) % 3)
9721
- n += s == 1 || s == -2 ? "0" : "00";
9722
- s = mathpow(n, 1 / 3);
9723
- e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
9724
- if (s == 1 / 0) {
9725
- n = "5e" + e;
9726
- } else {
9727
- n = s.toExponential();
9728
- n = n.slice(0, n.indexOf("e") + 1) + e;
9729
- }
9730
- r = new Ctor(n);
9731
- r.s = x.s;
9732
- } else {
9733
- r = new Ctor(s.toString());
9734
- }
9735
- sd = (e = Ctor.precision) + 3;
9736
- for (;; ) {
9737
- t = r;
9738
- t3 = t.times(t).times(t);
9739
- t3plusx = t3.plus(x);
9740
- r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
9741
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
9742
- n = n.slice(sd - 3, sd + 1);
9743
- if (n == "9999" || !rep && n == "4999") {
9744
- if (!rep) {
9745
- finalise(t, e + 1, 0);
9746
- if (t.times(t).times(t).eq(x)) {
9747
- r = t;
9748
- break;
9749
- }
9562
+ var sbumit = async (imageUrl, prompt) => {
9563
+ try {
9564
+ var data = JSON.stringify({
9565
+ arguments: [
9566
+ {
9567
+ name: "prompt",
9568
+ value: prompt || ""
9569
+ },
9570
+ {
9571
+ name: "negative_prompt",
9572
+ value: "闪烁、动画、模糊、变形、毁容、低质量、拼贴、颗粒状、抽象、计算机生成、扭曲"
9573
+ },
9574
+ {
9575
+ name: "cfg",
9576
+ value: "0.5"
9577
+ },
9578
+ {
9579
+ name: "duration",
9580
+ value: "5"
9581
+ },
9582
+ {
9583
+ name: "imageCount",
9584
+ value: "1"
9585
+ },
9586
+ {
9587
+ name: "kling_version",
9588
+ value: "1.5"
9589
+ },
9590
+ {
9591
+ name: "tail_image_enabled",
9592
+ value: "false"
9593
+ },
9594
+ {
9595
+ name: "camera_json",
9596
+ value: '{"type":"empty","horizontal":0,"vertical":0,"zoom":0,"tilt":0,"pan":0,"roll":0}'
9597
+ },
9598
+ {
9599
+ name: "camera_control_enabled",
9600
+ value: "false"
9601
+ },
9602
+ {
9603
+ name: "biz",
9604
+ value: "klingai"
9750
9605
  }
9751
- sd += 4;
9752
- rep = 1;
9753
- } else {
9754
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
9755
- finalise(r, e + 1, 1);
9756
- m = !r.times(r).times(r).eq(x);
9606
+ ],
9607
+ inputs: [
9608
+ {
9609
+ inputType: "URL",
9610
+ url: imageUrl,
9611
+ name: "input"
9757
9612
  }
9758
- break;
9759
- }
9760
- }
9761
- }
9762
- external2 = true;
9763
- return finalise(r, e, Ctor.rounding, m);
9764
- };
9765
- P.decimalPlaces = P.dp = function() {
9766
- var w, d = this.d, n = NaN;
9767
- if (d) {
9768
- w = d.length - 1;
9769
- n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
9770
- w = d[w];
9771
- if (w)
9772
- for (;w % 10 == 0; w /= 10)
9773
- n--;
9774
- if (n < 0)
9775
- n = 0;
9776
- }
9777
- return n;
9778
- };
9779
- P.dividedBy = P.div = function(y) {
9780
- return divide(this, new this.constructor(y));
9781
- };
9782
- P.dividedToIntegerBy = P.divToInt = function(y) {
9783
- var x = this, Ctor = x.constructor;
9784
- return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
9785
- };
9786
- P.equals = P.eq = function(y) {
9787
- return this.cmp(y) === 0;
9788
- };
9789
- P.floor = function() {
9790
- return finalise(new this.constructor(this), this.e + 1, 3);
9791
- };
9792
- P.greaterThan = P.gt = function(y) {
9793
- return this.cmp(y) > 0;
9794
- };
9795
- P.greaterThanOrEqualTo = P.gte = function(y) {
9796
- var k = this.cmp(y);
9797
- return k == 1 || k === 0;
9798
- };
9799
- P.hyperbolicCosine = P.cosh = function() {
9800
- var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
9801
- if (!x.isFinite())
9802
- return new Ctor(x.s ? 1 / 0 : NaN);
9803
- if (x.isZero())
9804
- return one;
9805
- pr = Ctor.precision;
9806
- rm = Ctor.rounding;
9807
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
9808
- Ctor.rounding = 1;
9809
- len = x.d.length;
9810
- if (len < 32) {
9811
- k = Math.ceil(len / 3);
9812
- n = (1 / tinyPow(4, k)).toString();
9813
- } else {
9814
- k = 16;
9815
- n = "2.3283064365386962890625e-10";
9816
- }
9817
- x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
9818
- var cosh2_x, i = k, d8 = new Ctor(8);
9819
- for (;i--; ) {
9820
- cosh2_x = x.times(x);
9821
- x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
9613
+ ],
9614
+ type: "m2v_img2video_hq"
9615
+ });
9616
+ const response = await axios2({
9617
+ method: "POST",
9618
+ url: "https://klingai.kuaishou.com/api/task/submit",
9619
+ data
9620
+ });
9621
+ return response.data?.data?.task?.id;
9622
+ } catch (error) {
9623
+ console.error("完成上传失败:", error);
9624
+ throw error;
9822
9625
  }
9823
- return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
9824
- };
9825
- P.hyperbolicSine = P.sinh = function() {
9826
- var k, pr, rm, len, x = this, Ctor = x.constructor;
9827
- if (!x.isFinite() || x.isZero())
9828
- return new Ctor(x);
9829
- pr = Ctor.precision;
9830
- rm = Ctor.rounding;
9831
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
9832
- Ctor.rounding = 1;
9833
- len = x.d.length;
9834
- if (len < 3) {
9835
- x = taylorSeries(Ctor, 2, x, x, true);
9836
- } else {
9837
- k = 1.4 * Math.sqrt(len);
9838
- k = k > 16 ? 16 : k | 0;
9839
- x = x.times(1 / tinyPow(5, k));
9840
- x = taylorSeries(Ctor, 2, x, x, true);
9841
- var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
9842
- for (;k--; ) {
9843
- sinh2_x = x.times(x);
9844
- x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
9845
- }
9846
- }
9847
- Ctor.precision = pr;
9848
- Ctor.rounding = rm;
9849
- return finalise(x, pr, rm, true);
9850
- };
9851
- P.hyperbolicTangent = P.tanh = function() {
9852
- var pr, rm, x = this, Ctor = x.constructor;
9853
- if (!x.isFinite())
9854
- return new Ctor(x.s);
9855
- if (x.isZero())
9856
- return new Ctor(x);
9857
- pr = Ctor.precision;
9858
- rm = Ctor.rounding;
9859
- Ctor.precision = pr + 7;
9860
- Ctor.rounding = 1;
9861
- return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
9862
- };
9863
- P.inverseCosine = P.acos = function() {
9864
- var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
9865
- if (k !== -1) {
9866
- return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
9867
- }
9868
- if (x.isZero())
9869
- return getPi(Ctor, pr + 4, rm).times(0.5);
9870
- Ctor.precision = pr + 6;
9871
- Ctor.rounding = 1;
9872
- x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
9873
- Ctor.precision = pr;
9874
- Ctor.rounding = rm;
9875
- return x.times(2);
9876
- };
9877
- P.inverseHyperbolicCosine = P.acosh = function() {
9878
- var pr, rm, x = this, Ctor = x.constructor;
9879
- if (x.lte(1))
9880
- return new Ctor(x.eq(1) ? 0 : NaN);
9881
- if (!x.isFinite())
9882
- return new Ctor(x);
9883
- pr = Ctor.precision;
9884
- rm = Ctor.rounding;
9885
- Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
9886
- Ctor.rounding = 1;
9887
- external2 = false;
9888
- x = x.times(x).minus(1).sqrt().plus(x);
9889
- external2 = true;
9890
- Ctor.precision = pr;
9891
- Ctor.rounding = rm;
9892
- return x.ln();
9893
- };
9894
- P.inverseHyperbolicSine = P.asinh = function() {
9895
- var pr, rm, x = this, Ctor = x.constructor;
9896
- if (!x.isFinite() || x.isZero())
9897
- return new Ctor(x);
9898
- pr = Ctor.precision;
9899
- rm = Ctor.rounding;
9900
- Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
9901
- Ctor.rounding = 1;
9902
- external2 = false;
9903
- x = x.times(x).plus(1).sqrt().plus(x);
9904
- external2 = true;
9905
- Ctor.precision = pr;
9906
- Ctor.rounding = rm;
9907
- return x.ln();
9908
- };
9909
- P.inverseHyperbolicTangent = P.atanh = function() {
9910
- var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
9911
- if (!x.isFinite())
9912
- return new Ctor(NaN);
9913
- if (x.e >= 0)
9914
- return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
9915
- pr = Ctor.precision;
9916
- rm = Ctor.rounding;
9917
- xsd = x.sd();
9918
- if (Math.max(xsd, pr) < 2 * -x.e - 1)
9919
- return finalise(new Ctor(x), pr, rm, true);
9920
- Ctor.precision = wpr = xsd - x.e;
9921
- x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
9922
- Ctor.precision = pr + 4;
9923
- Ctor.rounding = 1;
9924
- x = x.ln();
9925
- Ctor.precision = pr;
9926
- Ctor.rounding = rm;
9927
- return x.times(0.5);
9928
- };
9929
- P.inverseSine = P.asin = function() {
9930
- var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
9931
- if (x.isZero())
9932
- return new Ctor(x);
9933
- k = x.abs().cmp(1);
9934
- pr = Ctor.precision;
9935
- rm = Ctor.rounding;
9936
- if (k !== -1) {
9937
- if (k === 0) {
9938
- halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
9939
- halfPi.s = x.s;
9940
- return halfPi;
9941
- }
9942
- return new Ctor(NaN);
9943
- }
9944
- Ctor.precision = pr + 6;
9945
- Ctor.rounding = 1;
9946
- x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
9947
- Ctor.precision = pr;
9948
- Ctor.rounding = rm;
9949
- return x.times(2);
9950
- };
9951
- P.inverseTangent = P.atan = function() {
9952
- var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
9953
- if (!x.isFinite()) {
9954
- if (!x.s)
9955
- return new Ctor(NaN);
9956
- if (pr + 4 <= PI_PRECISION) {
9957
- r = getPi(Ctor, pr + 4, rm).times(0.5);
9958
- r.s = x.s;
9959
- return r;
9960
- }
9961
- } else if (x.isZero()) {
9962
- return new Ctor(x);
9963
- } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
9964
- r = getPi(Ctor, pr + 4, rm).times(0.25);
9965
- r.s = x.s;
9966
- return r;
9967
- }
9968
- Ctor.precision = wpr = pr + 10;
9969
- Ctor.rounding = 1;
9970
- k = Math.min(28, wpr / LOG_BASE + 2 | 0);
9971
- for (i = k;i; --i)
9972
- x = x.div(x.times(x).plus(1).sqrt().plus(1));
9973
- external2 = false;
9974
- j = Math.ceil(wpr / LOG_BASE);
9975
- n = 1;
9976
- x2 = x.times(x);
9977
- r = new Ctor(x);
9978
- px = x;
9979
- for (;i !== -1; ) {
9980
- px = px.times(x2);
9981
- t = r.minus(px.div(n += 2));
9982
- px = px.times(x2);
9983
- r = t.plus(px.div(n += 2));
9984
- if (r.d[j] !== undefined)
9985
- for (i = j;r.d[i] === t.d[i] && i--; )
9986
- ;
9987
- }
9988
- if (k)
9989
- r = r.times(2 << k - 1);
9990
- external2 = true;
9991
- return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
9992
9626
  };
9993
- P.isFinite = function() {
9994
- return !!this.d;
9995
- };
9996
- P.isInteger = P.isInt = function() {
9997
- return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
9998
- };
9999
- P.isNaN = function() {
10000
- return !this.s;
10001
- };
10002
- P.isNegative = P.isNeg = function() {
10003
- return this.s < 0;
10004
- };
10005
- P.isPositive = P.isPos = function() {
10006
- return this.s > 0;
10007
- };
10008
- P.isZero = function() {
10009
- return !!this.d && this.d[0] === 0;
10010
- };
10011
- P.lessThan = P.lt = function(y) {
10012
- return this.cmp(y) < 0;
10013
- };
10014
- P.lessThanOrEqualTo = P.lte = function(y) {
10015
- return this.cmp(y) < 1;
10016
- };
10017
- P.logarithm = P.log = function(base) {
10018
- var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
10019
- if (base == null) {
10020
- base = new Ctor(10);
10021
- isBase10 = true;
10022
- } else {
10023
- base = new Ctor(base);
10024
- d = base.d;
10025
- if (base.s < 0 || !d || !d[0] || base.eq(1))
10026
- return new Ctor(NaN);
10027
- isBase10 = base.eq(10);
10028
- }
10029
- d = arg.d;
10030
- if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
10031
- return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
10032
- }
10033
- if (isBase10) {
10034
- if (d.length > 1) {
10035
- inf = true;
10036
- } else {
10037
- for (k = d[0];k % 10 === 0; )
10038
- k /= 10;
10039
- inf = k !== 1;
10040
- }
10041
- }
10042
- external2 = false;
10043
- sd = pr + guard;
10044
- num = naturalLogarithm(arg, sd);
10045
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
10046
- r = divide(num, denominator, sd, 1);
10047
- if (checkRoundingDigits(r.d, k = pr, rm)) {
10048
- do {
10049
- sd += 10;
10050
- num = naturalLogarithm(arg, sd);
10051
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
10052
- r = divide(num, denominator, sd, 1);
10053
- if (!inf) {
10054
- if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 100000000000000) {
10055
- r = finalise(r, pr + 1, 0);
10056
- }
10057
- break;
10058
- }
10059
- } while (checkRoundingDigits(r.d, k += 10, rm));
10060
- }
10061
- external2 = true;
10062
- return finalise(r, pr, rm);
10063
- };
10064
- P.minus = P.sub = function(y) {
10065
- var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
10066
- y = new Ctor(y);
10067
- if (!x.d || !y.d) {
10068
- if (!x.s || !y.s)
10069
- y = new Ctor(NaN);
10070
- else if (x.d)
10071
- y.s = -y.s;
10072
- else
10073
- y = new Ctor(y.d || x.s !== y.s ? x : NaN);
10074
- return y;
10075
- }
10076
- if (x.s != y.s) {
10077
- y.s = -y.s;
10078
- return x.plus(y);
10079
- }
10080
- xd = x.d;
10081
- yd = y.d;
10082
- pr = Ctor.precision;
10083
- rm = Ctor.rounding;
10084
- if (!xd[0] || !yd[0]) {
10085
- if (yd[0])
10086
- y.s = -y.s;
10087
- else if (xd[0])
10088
- y = new Ctor(x);
10089
- else
10090
- return new Ctor(rm === 3 ? -0 : 0);
10091
- return external2 ? finalise(y, pr, rm) : y;
10092
- }
10093
- e = mathfloor(y.e / LOG_BASE);
10094
- xe = mathfloor(x.e / LOG_BASE);
10095
- xd = xd.slice();
10096
- k = xe - e;
10097
- if (k) {
10098
- xLTy = k < 0;
10099
- if (xLTy) {
10100
- d = xd;
10101
- k = -k;
10102
- len = yd.length;
10103
- } else {
10104
- d = yd;
10105
- e = xe;
10106
- len = xd.length;
10107
- }
10108
- i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
10109
- if (k > i) {
10110
- k = i;
10111
- d.length = 1;
10112
- }
10113
- d.reverse();
10114
- for (i = k;i--; )
10115
- d.push(0);
10116
- d.reverse();
10117
- } else {
10118
- i = xd.length;
10119
- len = yd.length;
10120
- xLTy = i < len;
10121
- if (xLTy)
10122
- len = i;
10123
- for (i = 0;i < len; i++) {
10124
- if (xd[i] != yd[i]) {
10125
- xLTy = xd[i] < yd[i];
10126
- break;
10127
- }
10128
- }
10129
- k = 0;
10130
- }
10131
- if (xLTy) {
10132
- d = xd;
10133
- xd = yd;
10134
- yd = d;
10135
- y.s = -y.s;
10136
- }
10137
- len = xd.length;
10138
- for (i = yd.length - len;i > 0; --i)
10139
- xd[len++] = 0;
10140
- for (i = yd.length;i > k; ) {
10141
- if (xd[--i] < yd[i]) {
10142
- for (j = i;j && xd[--j] === 0; )
10143
- xd[j] = BASE - 1;
10144
- --xd[j];
10145
- xd[i] += BASE;
10146
- }
10147
- xd[i] -= yd[i];
10148
- }
10149
- for (;xd[--len] === 0; )
10150
- xd.pop();
10151
- for (;xd[0] === 0; xd.shift())
10152
- --e;
10153
- if (!xd[0])
10154
- return new Ctor(rm === 3 ? -0 : 0);
10155
- y.d = xd;
10156
- y.e = getBase10Exponent(xd, e);
10157
- return external2 ? finalise(y, pr, rm) : y;
10158
- };
10159
- P.modulo = P.mod = function(y) {
10160
- var q, x = this, Ctor = x.constructor;
10161
- y = new Ctor(y);
10162
- if (!x.d || !y.s || y.d && !y.d[0])
10163
- return new Ctor(NaN);
10164
- if (!y.d || x.d && !x.d[0]) {
10165
- return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
10166
- }
10167
- external2 = false;
10168
- if (Ctor.modulo == 9) {
10169
- q = divide(x, y.abs(), 0, 3, 1);
10170
- q.s *= y.s;
10171
- } else {
10172
- q = divide(x, y, 0, Ctor.modulo, 1);
9627
+ var calculateProgress = (taskData) => {
9628
+ const createTime = taskData?.task?.createTime;
9629
+ const etaTime = taskData?.etaTime;
9630
+ const currentTime = Date.now();
9631
+ if (!createTime || !etaTime) {
9632
+ return 0;
10173
9633
  }
10174
- q = q.times(y);
10175
- external2 = true;
10176
- return x.minus(q);
10177
- };
10178
- P.naturalExponential = P.exp = function() {
10179
- return naturalExponential(this);
10180
- };
10181
- P.naturalLogarithm = P.ln = function() {
10182
- return naturalLogarithm(this);
10183
- };
10184
- P.negated = P.neg = function() {
10185
- var x = new this.constructor(this);
10186
- x.s = -x.s;
10187
- return finalise(x);
10188
- };
10189
- P.plus = P.add = function(y) {
10190
- var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
10191
- y = new Ctor(y);
10192
- if (!x.d || !y.d) {
10193
- if (!x.s || !y.s)
10194
- y = new Ctor(NaN);
10195
- else if (!x.d)
10196
- y = new Ctor(y.d || x.s === y.s ? x : NaN);
10197
- return y;
10198
- }
10199
- if (x.s != y.s) {
10200
- y.s = -y.s;
10201
- return x.minus(y);
10202
- }
10203
- xd = x.d;
10204
- yd = y.d;
10205
- pr = Ctor.precision;
10206
- rm = Ctor.rounding;
10207
- if (!xd[0] || !yd[0]) {
10208
- if (!yd[0])
10209
- y = new Ctor(x);
10210
- return external2 ? finalise(y, pr, rm) : y;
10211
- }
10212
- k = mathfloor(x.e / LOG_BASE);
10213
- e = mathfloor(y.e / LOG_BASE);
10214
- xd = xd.slice();
10215
- i = k - e;
10216
- if (i) {
10217
- if (i < 0) {
10218
- d = xd;
10219
- i = -i;
10220
- len = yd.length;
10221
- } else {
10222
- d = yd;
10223
- e = k;
10224
- len = xd.length;
10225
- }
10226
- k = Math.ceil(pr / LOG_BASE);
10227
- len = k > len ? k + 1 : len + 1;
10228
- if (i > len) {
10229
- i = len;
10230
- d.length = 1;
10231
- }
10232
- d.reverse();
10233
- for (;i--; )
10234
- d.push(0);
10235
- d.reverse();
10236
- }
10237
- len = xd.length;
10238
- i = yd.length;
10239
- if (len - i < 0) {
10240
- i = len;
10241
- d = yd;
10242
- yd = xd;
10243
- xd = d;
10244
- }
10245
- for (carry = 0;i; ) {
10246
- carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
10247
- xd[i] %= BASE;
10248
- }
10249
- if (carry) {
10250
- xd.unshift(carry);
10251
- ++e;
10252
- }
10253
- for (len = xd.length;xd[--len] == 0; )
10254
- xd.pop();
10255
- y.d = xd;
10256
- y.e = getBase10Exponent(xd, e);
10257
- return external2 ? finalise(y, pr, rm) : y;
10258
- };
10259
- P.precision = P.sd = function(z) {
10260
- var k, x = this;
10261
- if (z !== undefined && z !== !!z && z !== 1 && z !== 0)
10262
- throw Error(invalidArgument + z);
10263
- if (x.d) {
10264
- k = getPrecision(x.d);
10265
- if (z && x.e + 1 > k)
10266
- k = x.e + 1;
10267
- } else {
10268
- k = NaN;
9634
+ const totalTimeSpan = etaTime - createTime;
9635
+ const timeElapsed = currentTime - createTime;
9636
+ if (totalTimeSpan <= 0) {
9637
+ return 0;
10269
9638
  }
10270
- return k;
10271
- };
10272
- P.round = function() {
10273
- var x = this, Ctor = x.constructor;
10274
- return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
10275
- };
10276
- P.sine = P.sin = function() {
10277
- var pr, rm, x = this, Ctor = x.constructor;
10278
- if (!x.isFinite())
10279
- return new Ctor(NaN);
10280
- if (x.isZero())
10281
- return new Ctor(x);
10282
- pr = Ctor.precision;
10283
- rm = Ctor.rounding;
10284
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
10285
- Ctor.rounding = 1;
10286
- x = sine(Ctor, toLessThanHalfPi(Ctor, x));
10287
- Ctor.precision = pr;
10288
- Ctor.rounding = rm;
10289
- return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
10290
- };
10291
- P.squareRoot = P.sqrt = function() {
10292
- var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
10293
- if (s !== 1 || !d || !d[0]) {
10294
- return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
10295
- }
10296
- external2 = false;
10297
- s = Math.sqrt(+x);
10298
- if (s == 0 || s == 1 / 0) {
10299
- n = digitsToString(d);
10300
- if ((n.length + e) % 2 == 0)
10301
- n += "0";
10302
- s = Math.sqrt(n);
10303
- e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
10304
- if (s == 1 / 0) {
10305
- n = "5e" + e;
10306
- } else {
10307
- n = s.toExponential();
10308
- n = n.slice(0, n.indexOf("e") + 1) + e;
10309
- }
10310
- r = new Ctor(n);
10311
- } else {
10312
- r = new Ctor(s.toString());
10313
- }
10314
- sd = (e = Ctor.precision) + 3;
10315
- for (;; ) {
10316
- t = r;
10317
- r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
10318
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
10319
- n = n.slice(sd - 3, sd + 1);
10320
- if (n == "9999" || !rep && n == "4999") {
10321
- if (!rep) {
10322
- finalise(t, e + 1, 0);
10323
- if (t.times(t).eq(x)) {
10324
- r = t;
10325
- break;
10326
- }
10327
- }
10328
- sd += 4;
10329
- rep = 1;
10330
- } else {
10331
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
10332
- finalise(r, e + 1, 1);
10333
- m = !r.times(r).eq(x);
10334
- }
10335
- break;
10336
- }
10337
- }
9639
+ let progressRatio = timeElapsed / totalTimeSpan;
9640
+ if (progressRatio >= 1) {
9641
+ progressRatio = 0.99;
10338
9642
  }
10339
- external2 = true;
10340
- return finalise(r, e, Ctor.rounding, m);
10341
- };
10342
- P.tangent = P.tan = function() {
10343
- var pr, rm, x = this, Ctor = x.constructor;
10344
- if (!x.isFinite())
10345
- return new Ctor(NaN);
10346
- if (x.isZero())
10347
- return new Ctor(x);
10348
- pr = Ctor.precision;
10349
- rm = Ctor.rounding;
10350
- Ctor.precision = pr + 10;
10351
- Ctor.rounding = 1;
10352
- x = x.sin();
10353
- x.s = 1;
10354
- x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
10355
- Ctor.precision = pr;
10356
- Ctor.rounding = rm;
10357
- return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
10358
- };
10359
- P.times = P.mul = function(y) {
10360
- var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
10361
- y.s *= x.s;
10362
- if (!xd || !xd[0] || !yd || !yd[0]) {
10363
- return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
10364
- }
10365
- e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
10366
- xdL = xd.length;
10367
- ydL = yd.length;
10368
- if (xdL < ydL) {
10369
- r = xd;
10370
- xd = yd;
10371
- yd = r;
10372
- rL = xdL;
10373
- xdL = ydL;
10374
- ydL = rL;
10375
- }
10376
- r = [];
10377
- rL = xdL + ydL;
10378
- for (i = rL;i--; )
10379
- r.push(0);
10380
- for (i = ydL;--i >= 0; ) {
10381
- carry = 0;
10382
- for (k = xdL + i;k > i; ) {
10383
- t = r[k] + yd[i] * xd[k - i - 1] + carry;
10384
- r[k--] = t % BASE | 0;
10385
- carry = t / BASE | 0;
10386
- }
10387
- r[k] = (r[k] + carry) % BASE | 0;
10388
- }
10389
- for (;!r[--rL]; )
10390
- r.pop();
10391
- if (carry)
10392
- ++e;
10393
- else
10394
- r.shift();
10395
- y.d = r;
10396
- y.e = getBase10Exponent(r, e);
10397
- return external2 ? finalise(y, Ctor.precision, Ctor.rounding) : y;
10398
- };
10399
- P.toBinary = function(sd, rm) {
10400
- return toStringBinary(this, 2, sd, rm);
10401
- };
10402
- P.toDecimalPlaces = P.toDP = function(dp, rm) {
10403
- var x = this, Ctor = x.constructor;
10404
- x = new Ctor(x);
10405
- if (dp === undefined)
10406
- return x;
10407
- checkInt32(dp, 0, MAX_DIGITS);
10408
- if (rm === undefined)
10409
- rm = Ctor.rounding;
10410
- else
10411
- checkInt32(rm, 0, 8);
10412
- return finalise(x, dp + x.e + 1, rm);
10413
- };
10414
- P.toExponential = function(dp, rm) {
10415
- var str, x = this, Ctor = x.constructor;
10416
- if (dp === undefined) {
10417
- str = finiteToString(x, true);
10418
- } else {
10419
- checkInt32(dp, 0, MAX_DIGITS);
10420
- if (rm === undefined)
10421
- rm = Ctor.rounding;
10422
- else
10423
- checkInt32(rm, 0, 8);
10424
- x = finalise(new Ctor(x), dp + 1, rm);
10425
- str = finiteToString(x, true, dp + 1);
10426
- }
10427
- return x.isNeg() && !x.isZero() ? "-" + str : str;
10428
- };
10429
- P.toFixed = function(dp, rm) {
10430
- var str, y, x = this, Ctor = x.constructor;
10431
- if (dp === undefined) {
10432
- str = finiteToString(x);
10433
- } else {
10434
- checkInt32(dp, 0, MAX_DIGITS);
10435
- if (rm === undefined)
10436
- rm = Ctor.rounding;
10437
- else
10438
- checkInt32(rm, 0, 8);
10439
- y = finalise(new Ctor(x), dp + x.e + 1, rm);
10440
- str = finiteToString(y, false, dp + y.e + 1);
10441
- }
10442
- return x.isNeg() && !x.isZero() ? "-" + str : str;
10443
- };
10444
- P.toFraction = function(maxD) {
10445
- var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
10446
- if (!xd)
10447
- return new Ctor(x);
10448
- n1 = d0 = new Ctor(1);
10449
- d1 = n0 = new Ctor(0);
10450
- d = new Ctor(d1);
10451
- e = d.e = getPrecision(xd) - x.e - 1;
10452
- k = e % LOG_BASE;
10453
- d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
10454
- if (maxD == null) {
10455
- maxD = e > 0 ? d : n1;
10456
- } else {
10457
- n = new Ctor(maxD);
10458
- if (!n.isInt() || n.lt(n1))
10459
- throw Error(invalidArgument + n);
10460
- maxD = n.gt(d) ? e > 0 ? d : n1 : n;
10461
- }
10462
- external2 = false;
10463
- n = new Ctor(digitsToString(xd));
10464
- pr = Ctor.precision;
10465
- Ctor.precision = e = xd.length * LOG_BASE * 2;
10466
- for (;; ) {
10467
- q = divide(n, d, 0, 1, 1);
10468
- d2 = d0.plus(q.times(d1));
10469
- if (d2.cmp(maxD) == 1)
10470
- break;
10471
- d0 = d1;
10472
- d1 = d2;
10473
- d2 = n1;
10474
- n1 = n0.plus(q.times(d2));
10475
- n0 = d2;
10476
- d2 = d;
10477
- d = n.minus(q.times(d2));
10478
- n = d2;
10479
- }
10480
- d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
10481
- n0 = n0.plus(d2.times(n1));
10482
- d0 = d0.plus(d2.times(d1));
10483
- n0.s = n1.s = x.s;
10484
- r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
10485
- Ctor.precision = pr;
10486
- external2 = true;
10487
- return r;
9643
+ return progressRatio;
10488
9644
  };
10489
- P.toHexadecimal = P.toHex = function(sd, rm) {
10490
- return toStringBinary(this, 16, sd, rm);
9645
+ var setCookie = (newCookieValue) => {
9646
+ axios2.defaults.headers.Cookie = newCookieValue;
10491
9647
  };
10492
- P.toNearest = function(y, rm) {
10493
- var x = this, Ctor = x.constructor;
10494
- x = new Ctor(x);
10495
- if (y == null) {
10496
- if (!x.d)
10497
- return x;
10498
- y = new Ctor(1);
10499
- rm = Ctor.rounding;
10500
- } else {
10501
- y = new Ctor(y);
10502
- if (rm === undefined) {
10503
- rm = Ctor.rounding;
10504
- } else {
10505
- checkInt32(rm, 0, 8);
10506
- }
10507
- if (!x.d)
10508
- return y.s ? x : y;
10509
- if (!y.d) {
10510
- if (y.s)
10511
- y.s = x.s;
10512
- return y;
10513
- }
10514
- }
10515
- if (y.d[0]) {
10516
- external2 = false;
10517
- x = divide(x, y, 0, rm, 1).times(y);
10518
- external2 = true;
10519
- finalise(x);
10520
- } else {
10521
- y.s = x.s;
10522
- x = y;
9648
+
9649
+ // src/common/ai/keling/index.ts
9650
+ var getVideoStatus = async (taskId) => {
9651
+ if (!taskId) {
9652
+ return;
10523
9653
  }
10524
- return x;
10525
- };
10526
- P.toNumber = function() {
10527
- return +this;
10528
- };
10529
- P.toOctal = function(sd, rm) {
10530
- return toStringBinary(this, 8, sd, rm);
10531
- };
10532
- P.toPower = P.pow = function(y) {
10533
- var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
10534
- if (!x.d || !y.d || !x.d[0] || !y.d[0])
10535
- return new Ctor(mathpow(+x, yn));
10536
- x = new Ctor(x);
10537
- if (x.eq(1))
10538
- return x;
10539
- pr = Ctor.precision;
10540
- rm = Ctor.rounding;
10541
- if (y.eq(1))
10542
- return finalise(x, pr, rm);
10543
- e = mathfloor(y.e / LOG_BASE);
10544
- if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
10545
- r = intPow(Ctor, x, k, pr);
10546
- return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
10547
- }
10548
- s = x.s;
10549
- if (s < 0) {
10550
- if (e < y.d.length - 1)
10551
- return new Ctor(NaN);
10552
- if ((y.d[e] & 1) == 0)
10553
- s = 1;
10554
- if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
10555
- x.s = s;
10556
- return x;
10557
- }
10558
- }
10559
- k = mathpow(+x, yn);
10560
- e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
10561
- if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
10562
- return new Ctor(e > 0 ? s / 0 : 0);
10563
- external2 = false;
10564
- Ctor.rounding = x.s = 1;
10565
- k = Math.min(12, (e + "").length);
10566
- r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
10567
- if (r.d) {
10568
- r = finalise(r, pr + 5, 1);
10569
- if (checkRoundingDigits(r.d, pr, rm)) {
10570
- e = pr + 10;
10571
- r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
10572
- if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 100000000000000) {
10573
- r = finalise(r, pr + 1, 0);
10574
- }
10575
- }
10576
- }
10577
- r.s = s;
10578
- external2 = true;
10579
- Ctor.rounding = rm;
10580
- return finalise(r, pr, rm);
10581
- };
10582
- P.toPrecision = function(sd, rm) {
10583
- var str, x = this, Ctor = x.constructor;
10584
- if (sd === undefined) {
10585
- str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
10586
- } else {
10587
- checkInt32(sd, 1, MAX_DIGITS);
10588
- if (rm === undefined)
10589
- rm = Ctor.rounding;
10590
- else
10591
- checkInt32(rm, 0, 8);
10592
- x = finalise(new Ctor(x), sd, rm);
10593
- str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
10594
- }
10595
- return x.isNeg() && !x.isZero() ? "-" + str : str;
10596
- };
10597
- P.toSignificantDigits = P.toSD = function(sd, rm) {
10598
- var x = this, Ctor = x.constructor;
10599
- if (sd === undefined) {
10600
- sd = Ctor.precision;
10601
- rm = Ctor.rounding;
10602
- } else {
10603
- checkInt32(sd, 1, MAX_DIGITS);
10604
- if (rm === undefined)
10605
- rm = Ctor.rounding;
10606
- else
10607
- checkInt32(rm, 0, 8);
9654
+ try {
9655
+ const response = await axios2.get("https://klingai.kuaishou.com/api/task/status", {
9656
+ params: { taskId }
9657
+ });
9658
+ return {
9659
+ status: response.data?.data?.status,
9660
+ url: response.data?.data?.works?.[0]?.resource?.resource,
9661
+ cover: response.data?.data?.works?.[0]?.cover?.resource,
9662
+ progress: calculateProgress(response.data?.data) * 100
9663
+ };
9664
+ } catch (error) {
9665
+ console.error("获取 status 失败:", error);
9666
+ throw error;
10608
9667
  }
10609
- return finalise(new Ctor(x), sd, rm);
10610
- };
10611
- P.toString = function() {
10612
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
10613
- return x.isNeg() && !x.isZero() ? "-" + str : str;
10614
9668
  };
10615
- P.truncated = P.trunc = function() {
10616
- return finalise(new this.constructor(this), this.e + 1, 1);
9669
+ var generateVideo = async (imageUrl, prompt) => {
9670
+ const uploadedUrl = await uploadImage(imageUrl);
9671
+ console.log("图片上传成功,URL:", uploadedUrl);
9672
+ const taskId = await sbumit(uploadedUrl, prompt);
9673
+ console.log(666, "任务 id", taskId);
9674
+ return taskId;
10617
9675
  };
10618
- P.valueOf = P.toJSON = function() {
10619
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
10620
- return x.isNeg() ? "-" + str : str;
10621
- };
10622
- function digitsToString(d) {
10623
- var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
10624
- if (indexOfLastWord > 0) {
10625
- str += w;
10626
- for (i = 1;i < indexOfLastWord; i++) {
10627
- ws = d[i] + "";
10628
- k = LOG_BASE - ws.length;
10629
- if (k)
10630
- str += getZeroString(k);
10631
- str += ws;
10632
- }
10633
- w = d[i];
10634
- ws = w + "";
10635
- k = LOG_BASE - ws.length;
10636
- if (k)
10637
- str += getZeroString(k);
10638
- } else if (w === 0) {
10639
- return "0";
10640
- }
10641
- for (;w % 10 === 0; )
10642
- w /= 10;
10643
- return str + w;
10644
- }
10645
- function checkInt32(i, min, max) {
10646
- if (i !== ~~i || i < min || i > max) {
10647
- throw Error(invalidArgument + i);
9676
+ // src/common/image.ts
9677
+ import axios3 from "axios";
9678
+ async function imageToBase64(url2) {
9679
+ try {
9680
+ const response = await axios3.get(url2, {
9681
+ responseType: "arraybuffer"
9682
+ });
9683
+ const base64String = Buffer.from(response.data).toString("base64");
9684
+ return `data:image/*;base64,${base64String}`;
9685
+ } catch (error) {
9686
+ console.error("Failed to fetch the image:", error);
9687
+ throw error;
10648
9688
  }
10649
9689
  }
10650
- function checkRoundingDigits(d, i, rm, repeating) {
10651
- var di, k, r, rd;
10652
- for (k = d[0];k >= 10; k /= 10)
10653
- --i;
10654
- if (--i < 0) {
10655
- i += LOG_BASE;
10656
- di = 0;
10657
- } else {
10658
- di = Math.ceil((i + 1) / LOG_BASE);
10659
- i %= LOG_BASE;
10660
- }
10661
- k = mathpow(10, LOG_BASE - i);
10662
- rd = d[di] % k | 0;
10663
- if (repeating == null) {
10664
- if (i < 3) {
10665
- if (i == 0)
10666
- rd = rd / 100 | 0;
10667
- else if (i == 1)
10668
- rd = rd / 10 | 0;
10669
- r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
10670
- } else {
10671
- 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;
10672
- }
10673
- } else {
10674
- if (i < 4) {
10675
- if (i == 0)
10676
- rd = rd / 1000 | 0;
10677
- else if (i == 1)
10678
- rd = rd / 100 | 0;
10679
- else if (i == 2)
10680
- rd = rd / 10 | 0;
10681
- r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
10682
- } else {
10683
- r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1;
10684
- }
10685
- }
10686
- return r;
10687
- }
10688
- function convertBase(str, baseIn, baseOut) {
10689
- var j, arr = [0], arrL, i = 0, strL = str.length;
10690
- for (;i < strL; ) {
10691
- for (arrL = arr.length;arrL--; )
10692
- arr[arrL] *= baseIn;
10693
- arr[0] += NUMERALS.indexOf(str.charAt(i++));
10694
- for (j = 0;j < arr.length; j++) {
10695
- if (arr[j] > baseOut - 1) {
10696
- if (arr[j + 1] === undefined)
10697
- arr[j + 1] = 0;
10698
- arr[j + 1] += arr[j] / baseOut | 0;
10699
- arr[j] %= baseOut;
10700
- }
10701
- }
10702
- }
10703
- return arr.reverse();
10704
- }
10705
- function cosine(Ctor, x) {
10706
- var k, len, y;
10707
- if (x.isZero())
10708
- return x;
10709
- len = x.d.length;
10710
- if (len < 32) {
10711
- k = Math.ceil(len / 3);
10712
- y = (1 / tinyPow(4, k)).toString();
10713
- } else {
10714
- k = 16;
10715
- y = "2.3283064365386962890625e-10";
10716
- }
10717
- Ctor.precision += k;
10718
- x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
10719
- for (var i = k;i--; ) {
10720
- var cos2x = x.times(x);
10721
- x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
10722
- }
10723
- Ctor.precision -= k;
10724
- return x;
10725
- }
10726
- var divide = function() {
10727
- function multiplyInteger(x, k, base) {
10728
- var temp, carry = 0, i = x.length;
10729
- for (x = x.slice();i--; ) {
10730
- temp = x[i] * k + carry;
10731
- x[i] = temp % base | 0;
10732
- carry = temp / base | 0;
10733
- }
10734
- if (carry)
10735
- x.unshift(carry);
10736
- return x;
10737
- }
10738
- function compare(a, b, aL, bL) {
10739
- var i, r;
10740
- if (aL != bL) {
10741
- r = aL > bL ? 1 : -1;
10742
- } else {
10743
- for (i = r = 0;i < aL; i++) {
10744
- if (a[i] != b[i]) {
10745
- r = a[i] > b[i] ? 1 : -1;
10746
- break;
10747
- }
10748
- }
10749
- }
10750
- return r;
10751
- }
10752
- function subtract(a, b, aL, base) {
10753
- var i = 0;
10754
- for (;aL--; ) {
10755
- a[aL] -= i;
10756
- i = a[aL] < b[aL] ? 1 : 0;
10757
- a[aL] = i * base + a[aL] - b[aL];
10758
- }
10759
- for (;!a[0] && a.length > 1; )
10760
- a.shift();
10761
- }
10762
- return function(x, y, pr, rm, dp, base) {
10763
- var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
10764
- if (!xd || !xd[0] || !yd || !yd[0]) {
10765
- return new Ctor(!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
10766
- }
10767
- if (base) {
10768
- logBase = 1;
10769
- e = x.e - y.e;
10770
- } else {
10771
- base = BASE;
10772
- logBase = LOG_BASE;
10773
- e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
10774
- }
10775
- yL = yd.length;
10776
- xL = xd.length;
10777
- q = new Ctor(sign);
10778
- qd = q.d = [];
10779
- for (i = 0;yd[i] == (xd[i] || 0); i++)
10780
- ;
10781
- if (yd[i] > (xd[i] || 0))
10782
- e--;
10783
- if (pr == null) {
10784
- sd = pr = Ctor.precision;
10785
- rm = Ctor.rounding;
10786
- } else if (dp) {
10787
- sd = pr + (x.e - y.e) + 1;
10788
- } else {
10789
- sd = pr;
10790
- }
10791
- if (sd < 0) {
10792
- qd.push(1);
10793
- more = true;
10794
- } else {
10795
- sd = sd / logBase + 2 | 0;
10796
- i = 0;
10797
- if (yL == 1) {
10798
- k = 0;
10799
- yd = yd[0];
10800
- sd++;
10801
- for (;(i < xL || k) && sd--; i++) {
10802
- t = k * base + (xd[i] || 0);
10803
- qd[i] = t / yd | 0;
10804
- k = t % yd | 0;
10805
- }
10806
- more = k || i < xL;
10807
- } else {
10808
- k = base / (yd[0] + 1) | 0;
10809
- if (k > 1) {
10810
- yd = multiplyInteger(yd, k, base);
10811
- xd = multiplyInteger(xd, k, base);
10812
- yL = yd.length;
10813
- xL = xd.length;
10814
- }
10815
- xi = yL;
10816
- rem = xd.slice(0, yL);
10817
- remL = rem.length;
10818
- for (;remL < yL; )
10819
- rem[remL++] = 0;
10820
- yz = yd.slice();
10821
- yz.unshift(0);
10822
- yd0 = yd[0];
10823
- if (yd[1] >= base / 2)
10824
- ++yd0;
10825
- do {
10826
- k = 0;
10827
- cmp = compare(yd, rem, yL, remL);
10828
- if (cmp < 0) {
10829
- rem0 = rem[0];
10830
- if (yL != remL)
10831
- rem0 = rem0 * base + (rem[1] || 0);
10832
- k = rem0 / yd0 | 0;
10833
- if (k > 1) {
10834
- if (k >= base)
10835
- k = base - 1;
10836
- prod = multiplyInteger(yd, k, base);
10837
- prodL = prod.length;
10838
- remL = rem.length;
10839
- cmp = compare(prod, rem, prodL, remL);
10840
- if (cmp == 1) {
10841
- k--;
10842
- subtract(prod, yL < prodL ? yz : yd, prodL, base);
10843
- }
10844
- } else {
10845
- if (k == 0)
10846
- cmp = k = 1;
10847
- prod = yd.slice();
10848
- }
10849
- prodL = prod.length;
10850
- if (prodL < remL)
10851
- prod.unshift(0);
10852
- subtract(rem, prod, remL, base);
10853
- if (cmp == -1) {
10854
- remL = rem.length;
10855
- cmp = compare(yd, rem, yL, remL);
10856
- if (cmp < 1) {
10857
- k++;
10858
- subtract(rem, yL < remL ? yz : yd, remL, base);
10859
- }
10860
- }
10861
- remL = rem.length;
10862
- } else if (cmp === 0) {
10863
- k++;
10864
- rem = [0];
10865
- }
10866
- qd[i++] = k;
10867
- if (cmp && rem[0]) {
10868
- rem[remL++] = xd[xi] || 0;
10869
- } else {
10870
- rem = [xd[xi]];
10871
- remL = 1;
10872
- }
10873
- } while ((xi++ < xL || rem[0] !== undefined) && sd--);
10874
- more = rem[0] !== undefined;
10875
- }
10876
- if (!qd[0])
10877
- qd.shift();
10878
- }
10879
- if (logBase == 1) {
10880
- q.e = e;
10881
- inexact = more;
10882
- } else {
10883
- for (i = 1, k = qd[0];k >= 10; k /= 10)
10884
- i++;
10885
- q.e = i + e * logBase - 1;
10886
- finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
10887
- }
10888
- return q;
10889
- };
10890
- }();
10891
- function finalise(x, sd, rm, isTruncated) {
10892
- var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
10893
- out:
10894
- if (sd != null) {
10895
- xd = x.d;
10896
- if (!xd)
10897
- return x;
10898
- for (digits = 1, k = xd[0];k >= 10; k /= 10)
10899
- digits++;
10900
- i = sd - digits;
10901
- if (i < 0) {
10902
- i += LOG_BASE;
10903
- j = sd;
10904
- w = xd[xdi = 0];
10905
- rd = w / mathpow(10, digits - j - 1) % 10 | 0;
10906
- } else {
10907
- xdi = Math.ceil((i + 1) / LOG_BASE);
10908
- k = xd.length;
10909
- if (xdi >= k) {
10910
- if (isTruncated) {
10911
- for (;k++ <= xdi; )
10912
- xd.push(0);
10913
- w = rd = 0;
10914
- digits = 1;
10915
- i %= LOG_BASE;
10916
- j = i - LOG_BASE + 1;
10917
- } else {
10918
- break out;
10919
- }
10920
- } else {
10921
- w = k = xd[xdi];
10922
- for (digits = 1;k >= 10; k /= 10)
10923
- digits++;
10924
- i %= LOG_BASE;
10925
- j = i - LOG_BASE + digits;
10926
- rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
10927
- }
10928
- }
10929
- isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== undefined || (j < 0 ? w : w % mathpow(10, digits - j - 1));
10930
- roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
10931
- if (sd < 1 || !xd[0]) {
10932
- xd.length = 0;
10933
- if (roundUp) {
10934
- sd -= x.e + 1;
10935
- xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
10936
- x.e = -sd || 0;
10937
- } else {
10938
- xd[0] = x.e = 0;
10939
- }
10940
- return x;
10941
- }
10942
- if (i == 0) {
10943
- xd.length = xdi;
10944
- k = 1;
10945
- xdi--;
10946
- } else {
10947
- xd.length = xdi + 1;
10948
- k = mathpow(10, LOG_BASE - i);
10949
- xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
10950
- }
10951
- if (roundUp) {
10952
- for (;; ) {
10953
- if (xdi == 0) {
10954
- for (i = 1, j = xd[0];j >= 10; j /= 10)
10955
- i++;
10956
- j = xd[0] += k;
10957
- for (k = 1;j >= 10; j /= 10)
10958
- k++;
10959
- if (i != k) {
10960
- x.e++;
10961
- if (xd[0] == BASE)
10962
- xd[0] = 1;
10963
- }
10964
- break;
10965
- } else {
10966
- xd[xdi] += k;
10967
- if (xd[xdi] != BASE)
10968
- break;
10969
- xd[xdi--] = 0;
10970
- k = 1;
10971
- }
10972
- }
10973
- }
10974
- for (i = xd.length;xd[--i] === 0; )
10975
- xd.pop();
10976
- }
10977
- if (external2) {
10978
- if (x.e > Ctor.maxE) {
10979
- x.d = null;
10980
- x.e = NaN;
10981
- } else if (x.e < Ctor.minE) {
10982
- x.e = 0;
10983
- x.d = [0];
10984
- }
10985
- }
10986
- return x;
10987
- }
10988
- function finiteToString(x, isExp, sd) {
10989
- if (!x.isFinite())
10990
- return nonFiniteToString(x);
10991
- var k, e = x.e, str = digitsToString(x.d), len = str.length;
10992
- if (isExp) {
10993
- if (sd && (k = sd - len) > 0) {
10994
- str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
10995
- } else if (len > 1) {
10996
- str = str.charAt(0) + "." + str.slice(1);
10997
- }
10998
- str = str + (x.e < 0 ? "e" : "e+") + x.e;
10999
- } else if (e < 0) {
11000
- str = "0." + getZeroString(-e - 1) + str;
11001
- if (sd && (k = sd - len) > 0)
11002
- str += getZeroString(k);
11003
- } else if (e >= len) {
11004
- str += getZeroString(e + 1 - len);
11005
- if (sd && (k = sd - e - 1) > 0)
11006
- str = str + "." + getZeroString(k);
11007
- } else {
11008
- if ((k = e + 1) < len)
11009
- str = str.slice(0, k) + "." + str.slice(k);
11010
- if (sd && (k = sd - len) > 0) {
11011
- if (e + 1 === len)
11012
- str += ".";
11013
- str += getZeroString(k);
11014
- }
11015
- }
11016
- return str;
11017
- }
11018
- function getBase10Exponent(digits, e) {
11019
- var w = digits[0];
11020
- for (e *= LOG_BASE;w >= 10; w /= 10)
11021
- e++;
11022
- return e;
11023
- }
11024
- function getLn10(Ctor, sd, pr) {
11025
- if (sd > LN10_PRECISION) {
11026
- external2 = true;
11027
- if (pr)
11028
- Ctor.precision = pr;
11029
- throw Error(precisionLimitExceeded);
11030
- }
11031
- return finalise(new Ctor(LN10), sd, 1, true);
11032
- }
11033
- function getPi(Ctor, sd, rm) {
11034
- if (sd > PI_PRECISION)
11035
- throw Error(precisionLimitExceeded);
11036
- return finalise(new Ctor(PI), sd, rm, true);
11037
- }
11038
- function getPrecision(digits) {
11039
- var w = digits.length - 1, len = w * LOG_BASE + 1;
11040
- w = digits[w];
11041
- if (w) {
11042
- for (;w % 10 == 0; w /= 10)
11043
- len--;
11044
- for (w = digits[0];w >= 10; w /= 10)
11045
- len++;
11046
- }
11047
- return len;
11048
- }
11049
- function getZeroString(k) {
11050
- var zs = "";
11051
- for (;k--; )
11052
- zs += "0";
11053
- return zs;
11054
- }
11055
- function intPow(Ctor, x, n, pr) {
11056
- var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
11057
- external2 = false;
11058
- for (;; ) {
11059
- if (n % 2) {
11060
- r = r.times(x);
11061
- if (truncate(r.d, k))
11062
- isTruncated = true;
11063
- }
11064
- n = mathfloor(n / 2);
11065
- if (n === 0) {
11066
- n = r.d.length - 1;
11067
- if (isTruncated && r.d[n] === 0)
11068
- ++r.d[n];
11069
- break;
11070
- }
11071
- x = x.times(x);
11072
- truncate(x.d, k);
11073
- }
11074
- external2 = true;
11075
- return r;
11076
- }
11077
- function isOdd(n) {
11078
- return n.d[n.d.length - 1] & 1;
11079
- }
11080
- function maxOrMin(Ctor, args, n) {
11081
- var k, y, x = new Ctor(args[0]), i = 0;
11082
- for (;++i < args.length; ) {
11083
- y = new Ctor(args[i]);
11084
- if (!y.s) {
11085
- x = y;
11086
- break;
11087
- }
11088
- k = x.cmp(y);
11089
- if (k === n || k === 0 && x.s === n) {
11090
- x = y;
11091
- }
11092
- }
11093
- return x;
11094
- }
11095
- function naturalExponential(x, sd) {
11096
- var denominator, guard, j, pow, sum, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
11097
- if (!x.d || !x.d[0] || x.e > 17) {
11098
- return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
11099
- }
11100
- if (sd == null) {
11101
- external2 = false;
11102
- wpr = pr;
11103
- } else {
11104
- wpr = sd;
11105
- }
11106
- t = new Ctor(0.03125);
11107
- while (x.e > -2) {
11108
- x = x.times(t);
11109
- k += 5;
11110
- }
11111
- guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
11112
- wpr += guard;
11113
- denominator = pow = sum = new Ctor(1);
11114
- Ctor.precision = wpr;
11115
- for (;; ) {
11116
- pow = finalise(pow.times(x), wpr, 1);
11117
- denominator = denominator.times(++i);
11118
- t = sum.plus(divide(pow, denominator, wpr, 1));
11119
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
11120
- j = k;
11121
- while (j--)
11122
- sum = finalise(sum.times(sum), wpr, 1);
11123
- if (sd == null) {
11124
- if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
11125
- Ctor.precision = wpr += 10;
11126
- denominator = pow = t = new Ctor(1);
11127
- i = 0;
11128
- rep++;
11129
- } else {
11130
- return finalise(sum, Ctor.precision = pr, rm, external2 = true);
11131
- }
11132
- } else {
11133
- Ctor.precision = pr;
11134
- return sum;
11135
- }
11136
- }
11137
- sum = t;
11138
- }
11139
- }
11140
- function naturalLogarithm(y, sd) {
11141
- var c, c0, denominator, e, numerator, rep, sum, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
11142
- if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
11143
- return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
11144
- }
11145
- if (sd == null) {
11146
- external2 = false;
11147
- wpr = pr;
11148
- } else {
11149
- wpr = sd;
11150
- }
11151
- Ctor.precision = wpr += guard;
11152
- c = digitsToString(xd);
11153
- c0 = c.charAt(0);
11154
- if (Math.abs(e = x.e) < 1500000000000000) {
11155
- while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
11156
- x = x.times(y);
11157
- c = digitsToString(x.d);
11158
- c0 = c.charAt(0);
11159
- n++;
11160
- }
11161
- e = x.e;
11162
- if (c0 > 1) {
11163
- x = new Ctor("0." + c);
11164
- e++;
11165
- } else {
11166
- x = new Ctor(c0 + "." + c.slice(1));
11167
- }
11168
- } else {
11169
- t = getLn10(Ctor, wpr + 2, pr).times(e + "");
11170
- x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
11171
- Ctor.precision = pr;
11172
- return sd == null ? finalise(x, pr, rm, external2 = true) : x;
11173
- }
11174
- x1 = x;
11175
- sum = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
11176
- x2 = finalise(x.times(x), wpr, 1);
11177
- denominator = 3;
11178
- for (;; ) {
11179
- numerator = finalise(numerator.times(x2), wpr, 1);
11180
- t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
11181
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
11182
- sum = sum.times(2);
11183
- if (e !== 0)
11184
- sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
11185
- sum = divide(sum, new Ctor(n), wpr, 1);
11186
- if (sd == null) {
11187
- if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
11188
- Ctor.precision = wpr += guard;
11189
- t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
11190
- x2 = finalise(x.times(x), wpr, 1);
11191
- denominator = rep = 1;
11192
- } else {
11193
- return finalise(sum, Ctor.precision = pr, rm, external2 = true);
11194
- }
11195
- } else {
11196
- Ctor.precision = pr;
11197
- return sum;
11198
- }
11199
- }
11200
- sum = t;
11201
- denominator += 2;
11202
- }
11203
- }
11204
- function nonFiniteToString(x) {
11205
- return String(x.s * x.s / 0);
11206
- }
11207
- function parseDecimal(x, str) {
11208
- var e, i, len;
11209
- if ((e = str.indexOf(".")) > -1)
11210
- str = str.replace(".", "");
11211
- if ((i = str.search(/e/i)) > 0) {
11212
- if (e < 0)
11213
- e = i;
11214
- e += +str.slice(i + 1);
11215
- str = str.substring(0, i);
11216
- } else if (e < 0) {
11217
- e = str.length;
11218
- }
11219
- for (i = 0;str.charCodeAt(i) === 48; i++)
11220
- ;
11221
- for (len = str.length;str.charCodeAt(len - 1) === 48; --len)
11222
- ;
11223
- str = str.slice(i, len);
11224
- if (str) {
11225
- len -= i;
11226
- x.e = e = e - i - 1;
11227
- x.d = [];
11228
- i = (e + 1) % LOG_BASE;
11229
- if (e < 0)
11230
- i += LOG_BASE;
11231
- if (i < len) {
11232
- if (i)
11233
- x.d.push(+str.slice(0, i));
11234
- for (len -= LOG_BASE;i < len; )
11235
- x.d.push(+str.slice(i, i += LOG_BASE));
11236
- str = str.slice(i);
11237
- i = LOG_BASE - str.length;
11238
- } else {
11239
- i -= len;
11240
- }
11241
- for (;i--; )
11242
- str += "0";
11243
- x.d.push(+str);
11244
- if (external2) {
11245
- if (x.e > x.constructor.maxE) {
11246
- x.d = null;
11247
- x.e = NaN;
11248
- } else if (x.e < x.constructor.minE) {
11249
- x.e = 0;
11250
- x.d = [0];
11251
- }
11252
- }
11253
- } else {
11254
- x.e = 0;
11255
- x.d = [0];
11256
- }
11257
- return x;
11258
- }
11259
- function parseOther(x, str) {
11260
- var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
11261
- if (str.indexOf("_") > -1) {
11262
- str = str.replace(/(\d)_(?=\d)/g, "$1");
11263
- if (isDecimal.test(str))
11264
- return parseDecimal(x, str);
11265
- } else if (str === "Infinity" || str === "NaN") {
11266
- if (!+str)
11267
- x.s = NaN;
11268
- x.e = NaN;
11269
- x.d = null;
11270
- return x;
11271
- }
11272
- if (isHex.test(str)) {
11273
- base = 16;
11274
- str = str.toLowerCase();
11275
- } else if (isBinary.test(str)) {
11276
- base = 2;
11277
- } else if (isOctal.test(str)) {
11278
- base = 8;
11279
- } else {
11280
- throw Error(invalidArgument + str);
11281
- }
11282
- i = str.search(/p/i);
11283
- if (i > 0) {
11284
- p = +str.slice(i + 1);
11285
- str = str.substring(2, i);
11286
- } else {
11287
- str = str.slice(2);
11288
- }
11289
- i = str.indexOf(".");
11290
- isFloat = i >= 0;
11291
- Ctor = x.constructor;
11292
- if (isFloat) {
11293
- str = str.replace(".", "");
11294
- len = str.length;
11295
- i = len - i;
11296
- divisor = intPow(Ctor, new Ctor(base), i, i * 2);
11297
- }
11298
- xd = convertBase(str, base, BASE);
11299
- xe = xd.length - 1;
11300
- for (i = xe;xd[i] === 0; --i)
11301
- xd.pop();
11302
- if (i < 0)
11303
- return new Ctor(x.s * 0);
11304
- x.e = getBase10Exponent(xd, xe);
11305
- x.d = xd;
11306
- external2 = false;
11307
- if (isFloat)
11308
- x = divide(x, divisor, len * 4);
11309
- if (p)
11310
- x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
11311
- external2 = true;
11312
- return x;
11313
- }
11314
- function sine(Ctor, x) {
11315
- var k, len = x.d.length;
11316
- if (len < 3) {
11317
- return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
11318
- }
11319
- k = 1.4 * Math.sqrt(len);
11320
- k = k > 16 ? 16 : k | 0;
11321
- x = x.times(1 / tinyPow(5, k));
11322
- x = taylorSeries(Ctor, 2, x, x);
11323
- var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
11324
- for (;k--; ) {
11325
- sin2_x = x.times(x);
11326
- x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
11327
- }
11328
- return x;
11329
- }
11330
- function taylorSeries(Ctor, n, x, y, isHyperbolic) {
11331
- var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
11332
- external2 = false;
11333
- x2 = x.times(x);
11334
- u = new Ctor(y);
11335
- for (;; ) {
11336
- t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
11337
- u = isHyperbolic ? y.plus(t) : y.minus(t);
11338
- y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
11339
- t = u.plus(y);
11340
- if (t.d[k] !== undefined) {
11341
- for (j = k;t.d[j] === u.d[j] && j--; )
11342
- ;
11343
- if (j == -1)
11344
- break;
11345
- }
11346
- j = u;
11347
- u = y;
11348
- y = t;
11349
- t = j;
11350
- i++;
11351
- }
11352
- external2 = true;
11353
- t.d.length = k + 1;
11354
- return t;
11355
- }
11356
- function tinyPow(b, e) {
11357
- var n = b;
11358
- while (--e)
11359
- n *= b;
11360
- return n;
11361
- }
11362
- function toLessThanHalfPi(Ctor, x) {
11363
- var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
11364
- x = x.abs();
11365
- if (x.lte(halfPi)) {
11366
- quadrant = isNeg ? 4 : 1;
11367
- return x;
11368
- }
11369
- t = x.divToInt(pi);
11370
- if (t.isZero()) {
11371
- quadrant = isNeg ? 3 : 2;
11372
- } else {
11373
- x = x.minus(t.times(pi));
11374
- if (x.lte(halfPi)) {
11375
- quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
11376
- return x;
11377
- }
11378
- quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
11379
- }
11380
- return x.minus(pi).abs();
11381
- }
11382
- function toStringBinary(x, baseOut, sd, rm) {
11383
- var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== undefined;
11384
- if (isExp) {
11385
- checkInt32(sd, 1, MAX_DIGITS);
11386
- if (rm === undefined)
11387
- rm = Ctor.rounding;
11388
- else
11389
- checkInt32(rm, 0, 8);
11390
- } else {
11391
- sd = Ctor.precision;
11392
- rm = Ctor.rounding;
11393
- }
11394
- if (!x.isFinite()) {
11395
- str = nonFiniteToString(x);
11396
- } else {
11397
- str = finiteToString(x);
11398
- i = str.indexOf(".");
11399
- if (isExp) {
11400
- base = 2;
11401
- if (baseOut == 16) {
11402
- sd = sd * 4 - 3;
11403
- } else if (baseOut == 8) {
11404
- sd = sd * 3 - 2;
11405
- }
11406
- } else {
11407
- base = baseOut;
11408
- }
11409
- if (i >= 0) {
11410
- str = str.replace(".", "");
11411
- y = new Ctor(1);
11412
- y.e = str.length - i;
11413
- y.d = convertBase(finiteToString(y), 10, base);
11414
- y.e = y.d.length;
11415
- }
11416
- xd = convertBase(str, 10, base);
11417
- e = len = xd.length;
11418
- for (;xd[--len] == 0; )
11419
- xd.pop();
11420
- if (!xd[0]) {
11421
- str = isExp ? "0p+0" : "0";
11422
- } else {
11423
- if (i < 0) {
11424
- e--;
11425
- } else {
11426
- x = new Ctor(x);
11427
- x.d = xd;
11428
- x.e = e;
11429
- x = divide(x, y, sd, rm, 0, base);
11430
- xd = x.d;
11431
- e = x.e;
11432
- roundUp = inexact;
11433
- }
11434
- i = xd[sd];
11435
- k = base / 2;
11436
- roundUp = roundUp || xd[sd + 1] !== undefined;
11437
- roundUp = rm < 4 ? (i !== undefined || 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));
11438
- xd.length = sd;
11439
- if (roundUp) {
11440
- for (;++xd[--sd] > base - 1; ) {
11441
- xd[sd] = 0;
11442
- if (!sd) {
11443
- ++e;
11444
- xd.unshift(1);
11445
- }
11446
- }
11447
- }
11448
- for (len = xd.length;!xd[len - 1]; --len)
11449
- ;
11450
- for (i = 0, str = "";i < len; i++)
11451
- str += NUMERALS.charAt(xd[i]);
11452
- if (isExp) {
11453
- if (len > 1) {
11454
- if (baseOut == 16 || baseOut == 8) {
11455
- i = baseOut == 16 ? 4 : 3;
11456
- for (--len;len % i; len++)
11457
- str += "0";
11458
- xd = convertBase(str, base, baseOut);
11459
- for (len = xd.length;!xd[len - 1]; --len)
11460
- ;
11461
- for (i = 1, str = "1.";i < len; i++)
11462
- str += NUMERALS.charAt(xd[i]);
11463
- } else {
11464
- str = str.charAt(0) + "." + str.slice(1);
11465
- }
11466
- }
11467
- str = str + (e < 0 ? "p" : "p+") + e;
11468
- } else if (e < 0) {
11469
- for (;++e; )
11470
- str = "0" + str;
11471
- str = "0." + str;
11472
- } else {
11473
- if (++e > len)
11474
- for (e -= len;e--; )
11475
- str += "0";
11476
- else if (e < len)
11477
- str = str.slice(0, e) + "." + str.slice(e);
11478
- }
11479
- }
11480
- str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
11481
- }
11482
- return x.s < 0 ? "-" + str : str;
11483
- }
11484
- function truncate(arr, len) {
11485
- if (arr.length > len) {
11486
- arr.length = len;
11487
- return true;
11488
- }
11489
- }
11490
- function abs(x) {
11491
- return new this(x).abs();
11492
- }
11493
- function acos(x) {
11494
- return new this(x).acos();
11495
- }
11496
- function acosh(x) {
11497
- return new this(x).acosh();
11498
- }
11499
- function add(x, y) {
11500
- return new this(x).plus(y);
11501
- }
11502
- function asin(x) {
11503
- return new this(x).asin();
11504
- }
11505
- function asinh(x) {
11506
- return new this(x).asinh();
11507
- }
11508
- function atan(x) {
11509
- return new this(x).atan();
11510
- }
11511
- function atanh(x) {
11512
- return new this(x).atanh();
11513
- }
11514
- function atan2(y, x) {
11515
- y = new this(y);
11516
- x = new this(x);
11517
- var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
11518
- if (!y.s || !x.s) {
11519
- r = new this(NaN);
11520
- } else if (!y.d && !x.d) {
11521
- r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
11522
- r.s = y.s;
11523
- } else if (!x.d || y.isZero()) {
11524
- r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
11525
- r.s = y.s;
11526
- } else if (!y.d || x.isZero()) {
11527
- r = getPi(this, wpr, 1).times(0.5);
11528
- r.s = y.s;
11529
- } else if (x.s < 0) {
11530
- this.precision = wpr;
11531
- this.rounding = 1;
11532
- r = this.atan(divide(y, x, wpr, 1));
11533
- x = getPi(this, wpr, 1);
11534
- this.precision = pr;
11535
- this.rounding = rm;
11536
- r = y.s < 0 ? r.minus(x) : r.plus(x);
11537
- } else {
11538
- r = this.atan(divide(y, x, wpr, 1));
11539
- }
11540
- return r;
11541
- }
11542
- function cbrt(x) {
11543
- return new this(x).cbrt();
11544
- }
11545
- function ceil(x) {
11546
- return finalise(x = new this(x), x.e + 1, 2);
11547
- }
11548
- function clamp(x, min, max) {
11549
- return new this(x).clamp(min, max);
11550
- }
11551
- function config(obj) {
11552
- if (!obj || typeof obj !== "object")
11553
- throw Error(decimalError + "Object expected");
11554
- var i, p, v, useDefaults = obj.defaults === true, ps = [
11555
- "precision",
11556
- 1,
11557
- MAX_DIGITS,
11558
- "rounding",
11559
- 0,
11560
- 8,
11561
- "toExpNeg",
11562
- -EXP_LIMIT,
11563
- 0,
11564
- "toExpPos",
11565
- 0,
11566
- EXP_LIMIT,
11567
- "maxE",
11568
- 0,
11569
- EXP_LIMIT,
11570
- "minE",
11571
- -EXP_LIMIT,
11572
- 0,
11573
- "modulo",
11574
- 0,
11575
- 9
11576
- ];
11577
- for (i = 0;i < ps.length; i += 3) {
11578
- if (p = ps[i], useDefaults)
11579
- this[p] = DEFAULTS[p];
11580
- if ((v = obj[p]) !== undefined) {
11581
- if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
11582
- this[p] = v;
11583
- else
11584
- throw Error(invalidArgument + p + ": " + v);
11585
- }
11586
- }
11587
- if (p = "crypto", useDefaults)
11588
- this[p] = DEFAULTS[p];
11589
- if ((v = obj[p]) !== undefined) {
11590
- if (v === true || v === false || v === 0 || v === 1) {
11591
- if (v) {
11592
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
11593
- this[p] = true;
11594
- } else {
11595
- throw Error(cryptoUnavailable);
11596
- }
11597
- } else {
11598
- this[p] = false;
11599
- }
11600
- } else {
11601
- throw Error(invalidArgument + p + ": " + v);
11602
- }
11603
- }
11604
- return this;
11605
- }
11606
- function cos(x) {
11607
- return new this(x).cos();
11608
- }
11609
- function cosh(x) {
11610
- return new this(x).cosh();
11611
- }
11612
- function clone(obj) {
11613
- var i, p, ps;
11614
- function Decimal(v) {
11615
- var e, i2, t, x = this;
11616
- if (!(x instanceof Decimal))
11617
- return new Decimal(v);
11618
- x.constructor = Decimal;
11619
- if (isDecimalInstance(v)) {
11620
- x.s = v.s;
11621
- if (external2) {
11622
- if (!v.d || v.e > Decimal.maxE) {
11623
- x.e = NaN;
11624
- x.d = null;
11625
- } else if (v.e < Decimal.minE) {
11626
- x.e = 0;
11627
- x.d = [0];
11628
- } else {
11629
- x.e = v.e;
11630
- x.d = v.d.slice();
11631
- }
11632
- } else {
11633
- x.e = v.e;
11634
- x.d = v.d ? v.d.slice() : v.d;
11635
- }
11636
- return;
11637
- }
11638
- t = typeof v;
11639
- if (t === "number") {
11640
- if (v === 0) {
11641
- x.s = 1 / v < 0 ? -1 : 1;
11642
- x.e = 0;
11643
- x.d = [0];
11644
- return;
11645
- }
11646
- if (v < 0) {
11647
- v = -v;
11648
- x.s = -1;
11649
- } else {
11650
- x.s = 1;
11651
- }
11652
- if (v === ~~v && v < 1e7) {
11653
- for (e = 0, i2 = v;i2 >= 10; i2 /= 10)
11654
- e++;
11655
- if (external2) {
11656
- if (e > Decimal.maxE) {
11657
- x.e = NaN;
11658
- x.d = null;
11659
- } else if (e < Decimal.minE) {
11660
- x.e = 0;
11661
- x.d = [0];
11662
- } else {
11663
- x.e = e;
11664
- x.d = [v];
11665
- }
11666
- } else {
11667
- x.e = e;
11668
- x.d = [v];
11669
- }
11670
- return;
11671
- }
11672
- if (v * 0 !== 0) {
11673
- if (!v)
11674
- x.s = NaN;
11675
- x.e = NaN;
11676
- x.d = null;
11677
- return;
11678
- }
11679
- return parseDecimal(x, v.toString());
11680
- }
11681
- if (t === "string") {
11682
- if ((i2 = v.charCodeAt(0)) === 45) {
11683
- v = v.slice(1);
11684
- x.s = -1;
11685
- } else {
11686
- if (i2 === 43)
11687
- v = v.slice(1);
11688
- x.s = 1;
11689
- }
11690
- return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
11691
- }
11692
- if (t === "bigint") {
11693
- if (v < 0) {
11694
- v = -v;
11695
- x.s = -1;
11696
- } else {
11697
- x.s = 1;
11698
- }
11699
- return parseDecimal(x, v.toString());
11700
- }
11701
- throw Error(invalidArgument + v);
11702
- }
11703
- Decimal.prototype = P;
11704
- Decimal.ROUND_UP = 0;
11705
- Decimal.ROUND_DOWN = 1;
11706
- Decimal.ROUND_CEIL = 2;
11707
- Decimal.ROUND_FLOOR = 3;
11708
- Decimal.ROUND_HALF_UP = 4;
11709
- Decimal.ROUND_HALF_DOWN = 5;
11710
- Decimal.ROUND_HALF_EVEN = 6;
11711
- Decimal.ROUND_HALF_CEIL = 7;
11712
- Decimal.ROUND_HALF_FLOOR = 8;
11713
- Decimal.EUCLID = 9;
11714
- Decimal.config = Decimal.set = config;
11715
- Decimal.clone = clone;
11716
- Decimal.isDecimal = isDecimalInstance;
11717
- Decimal.abs = abs;
11718
- Decimal.acos = acos;
11719
- Decimal.acosh = acosh;
11720
- Decimal.add = add;
11721
- Decimal.asin = asin;
11722
- Decimal.asinh = asinh;
11723
- Decimal.atan = atan;
11724
- Decimal.atanh = atanh;
11725
- Decimal.atan2 = atan2;
11726
- Decimal.cbrt = cbrt;
11727
- Decimal.ceil = ceil;
11728
- Decimal.clamp = clamp;
11729
- Decimal.cos = cos;
11730
- Decimal.cosh = cosh;
11731
- Decimal.div = div;
11732
- Decimal.exp = exp;
11733
- Decimal.floor = floor;
11734
- Decimal.hypot = hypot;
11735
- Decimal.ln = ln;
11736
- Decimal.log = log;
11737
- Decimal.log10 = log10;
11738
- Decimal.log2 = log2;
11739
- Decimal.max = max;
11740
- Decimal.min = min;
11741
- Decimal.mod = mod;
11742
- Decimal.mul = mul;
11743
- Decimal.pow = pow;
11744
- Decimal.random = random;
11745
- Decimal.round = round;
11746
- Decimal.sign = sign;
11747
- Decimal.sin = sin;
11748
- Decimal.sinh = sinh;
11749
- Decimal.sqrt = sqrt;
11750
- Decimal.sub = sub;
11751
- Decimal.sum = sum;
11752
- Decimal.tan = tan;
11753
- Decimal.tanh = tanh;
11754
- Decimal.trunc = trunc;
11755
- if (obj === undefined)
11756
- obj = {};
11757
- if (obj) {
11758
- if (obj.defaults !== true) {
11759
- ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
11760
- for (i = 0;i < ps.length; )
11761
- if (!obj.hasOwnProperty(p = ps[i++]))
11762
- obj[p] = this[p];
11763
- }
11764
- }
11765
- Decimal.config(obj);
11766
- return Decimal;
11767
- }
11768
- function div(x, y) {
11769
- return new this(x).div(y);
11770
- }
11771
- function exp(x) {
11772
- return new this(x).exp();
11773
- }
11774
- function floor(x) {
11775
- return finalise(x = new this(x), x.e + 1, 3);
11776
- }
11777
- function hypot() {
11778
- var i, n, t = new this(0);
11779
- external2 = false;
11780
- for (i = 0;i < arguments.length; ) {
11781
- n = new this(arguments[i++]);
11782
- if (!n.d) {
11783
- if (n.s) {
11784
- external2 = true;
11785
- return new this(1 / 0);
11786
- }
11787
- t = n;
11788
- } else if (t.d) {
11789
- t = t.plus(n.times(n));
11790
- }
11791
- }
11792
- external2 = true;
11793
- return t.sqrt();
11794
- }
11795
- function isDecimalInstance(obj) {
11796
- return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
11797
- }
11798
- function ln(x) {
11799
- return new this(x).ln();
11800
- }
11801
- function log(x, y) {
11802
- return new this(x).log(y);
11803
- }
11804
- function log2(x) {
11805
- return new this(x).log(2);
11806
- }
11807
- function log10(x) {
11808
- return new this(x).log(10);
11809
- }
11810
- function max() {
11811
- return maxOrMin(this, arguments, -1);
11812
- }
11813
- function min() {
11814
- return maxOrMin(this, arguments, 1);
11815
- }
11816
- function mod(x, y) {
11817
- return new this(x).mod(y);
11818
- }
11819
- function mul(x, y) {
11820
- return new this(x).mul(y);
11821
- }
11822
- function pow(x, y) {
11823
- return new this(x).pow(y);
11824
- }
11825
- function random(sd) {
11826
- var d, e, k, n, i = 0, r = new this(1), rd = [];
11827
- if (sd === undefined)
11828
- sd = this.precision;
11829
- else
11830
- checkInt32(sd, 1, MAX_DIGITS);
11831
- k = Math.ceil(sd / LOG_BASE);
11832
- if (!this.crypto) {
11833
- for (;i < k; )
11834
- rd[i++] = Math.random() * 1e7 | 0;
11835
- } else if (crypto.getRandomValues) {
11836
- d = crypto.getRandomValues(new Uint32Array(k));
11837
- for (;i < k; ) {
11838
- n = d[i];
11839
- if (n >= 4290000000) {
11840
- d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
11841
- } else {
11842
- rd[i++] = n % 1e7;
11843
- }
11844
- }
11845
- } else if (crypto.randomBytes) {
11846
- d = crypto.randomBytes(k *= 4);
11847
- for (;i < k; ) {
11848
- n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
11849
- if (n >= 2140000000) {
11850
- crypto.randomBytes(4).copy(d, i);
11851
- } else {
11852
- rd.push(n % 1e7);
11853
- i += 4;
11854
- }
11855
- }
11856
- i = k / 4;
11857
- } else {
11858
- throw Error(cryptoUnavailable);
11859
- }
11860
- k = rd[--i];
11861
- sd %= LOG_BASE;
11862
- if (k && sd) {
11863
- n = mathpow(10, LOG_BASE - sd);
11864
- rd[i] = (k / n | 0) * n;
11865
- }
11866
- for (;rd[i] === 0; i--)
11867
- rd.pop();
11868
- if (i < 0) {
11869
- e = 0;
11870
- rd = [0];
11871
- } else {
11872
- e = -1;
11873
- for (;rd[0] === 0; e -= LOG_BASE)
11874
- rd.shift();
11875
- for (k = 1, n = rd[0];n >= 10; n /= 10)
11876
- k++;
11877
- if (k < LOG_BASE)
11878
- e -= LOG_BASE - k;
11879
- }
11880
- r.e = e;
11881
- r.d = rd;
11882
- return r;
11883
- }
11884
- function round(x) {
11885
- return finalise(x = new this(x), x.e + 1, this.rounding);
11886
- }
11887
- function sign(x) {
11888
- x = new this(x);
11889
- return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
11890
- }
11891
- function sin(x) {
11892
- return new this(x).sin();
11893
- }
11894
- function sinh(x) {
11895
- return new this(x).sinh();
11896
- }
11897
- function sqrt(x) {
11898
- return new this(x).sqrt();
11899
- }
11900
- function sub(x, y) {
11901
- return new this(x).sub(y);
11902
- }
11903
- function sum() {
11904
- var i = 0, args = arguments, x = new this(args[i]);
11905
- external2 = false;
11906
- for (;x.s && ++i < args.length; )
11907
- x = x.plus(args[i]);
11908
- external2 = true;
11909
- return finalise(x, this.precision, this.rounding);
11910
- }
11911
- function tan(x) {
11912
- return new this(x).tan();
11913
- }
11914
- function tanh(x) {
11915
- return new this(x).tanh();
11916
- }
11917
- function trunc(x) {
11918
- return finalise(x = new this(x), x.e + 1, 1);
11919
- }
11920
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
11921
- P[Symbol.toStringTag] = "Decimal";
11922
- var Decimal = P.constructor = clone(DEFAULTS);
11923
- LN10 = new Decimal(LN10);
11924
- PI = new Decimal(PI);
11925
- var decimal_default = Decimal;
11926
-
11927
- // src/common/other.ts
11928
- var delay = (time = 1000) => {
11929
- return new Promise((resolve) => setTimeout(resolve, time));
11930
- };
11931
- var calcJsText = (expr, context) => {
11932
- const keys = Object.keys(context);
11933
- const values = keys.map((key) => context[key]);
11934
- return Function(...keys, `return (${expr})`)(...values);
11935
- };
11936
- var optionsToEnum = (options, text, key) => {
11937
- return options.reduce((acc, cur) => {
11938
- acc[cur[key]] = {
11939
- text: cur[text]
11940
- };
11941
- return acc;
11942
- }, {});
11943
- };
11944
- var performDecimalOperation = (num1, num2, operator) => {
11945
- if (num1 === undefined || num2 === undefined || !operator) {
11946
- return;
11947
- }
11948
- const decimalNum1 = new decimal_default(Number(num1));
11949
- const decimalNum2 = new decimal_default(Number(num2));
11950
- switch (operator) {
11951
- case "+":
11952
- return decimalNum1.plus(decimalNum2).toNumber();
11953
- case "-":
11954
- return decimalNum1.minus(decimalNum2).toNumber();
11955
- case "*":
11956
- return decimalNum1.times(decimalNum2).toNumber();
11957
- case "/":
11958
- if (num2 !== 0) {
11959
- return decimalNum1.dividedBy(decimalNum2).toNumber();
11960
- } else {
11961
- console.error("Division by zero is not allowed.");
11962
- return NaN;
11963
- }
11964
- default:
11965
- console.error("Invalid operator:", operator);
11966
- return NaN;
11967
- }
11968
- };
11969
- var printConsoleLog = (type, path, params, response) => {
11970
- const styles = {
11971
- header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
11972
- value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
11973
- separator: "color: #409EFF; margin: 0 4px;"
11974
- };
11975
- console.groupCollapsed(`666 %c${type}%c${path}`, styles.header, styles.value);
11976
- if (params) {
11977
- console.table(params);
11978
- }
11979
- if (response) {
11980
- console.table(response);
11981
- }
11982
- console.groupEnd();
11983
- };
11984
- // src/common/number.ts
11985
- var getRandomNum = (min2, max2) => {
11986
- return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
11987
- };
11988
- var limitDecimals = (v, num = 2, isForce) => {
11989
- let value = parseFloat(v);
11990
- if (isNaN(value)) {
11991
- if (isForce) {
11992
- value = 0;
11993
- } else {
11994
- return "";
11995
- }
11996
- }
11997
- return value.toFixed(num).toString();
11998
- };
11999
- var getFileSize = (size) => {
12000
- let d = "G";
12001
- let s = size / 1024 / 1024 / 1024;
12002
- if (s < 1) {
12003
- d = "M";
12004
- s *= 1024;
12005
- }
12006
- return `${(s.toFixed(1) / 1).toString()}${d}`;
12007
- };
12008
- var isValidNumber = (value) => {
12009
- if (typeof value !== "number") {
12010
- return false;
12011
- }
12012
- if (isNaN(value)) {
12013
- return false;
12014
- }
12015
- if (value === Infinity || value === -Infinity) {
12016
- return false;
12017
- }
12018
- return true;
12019
- };
12020
- var numberWithCommas = (x) => {
12021
- if (x === undefined || x === null) {
12022
- return "";
12023
- }
12024
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
12025
- };
12026
- // src/common/array.ts
12027
- var shuffleArray = (array) => {
12028
- const shuffledArray = [...array];
12029
- for (let i = shuffledArray.length - 1;i > 0; i--) {
12030
- const j = Math.floor(Math.random() * (i + 1));
12031
- [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
12032
- }
12033
- return shuffledArray;
12034
- };
12035
- var removeSimilarDuplicates = (arr, threshold, isLog) => {
12036
- const uniqueArray = [];
12037
- const similarPairs = [];
12038
- for (const str of arr) {
12039
- const isSimilar = uniqueArray.some((uniqueStr) => {
12040
- const distance = levenshteinDistance(str, uniqueStr);
12041
- if (distance <= threshold) {
12042
- similarPairs.push([str, uniqueStr]);
12043
- return true;
12044
- }
12045
- return false;
12046
- });
12047
- if (!isSimilar) {
12048
- uniqueArray.push(str);
12049
- }
12050
- }
12051
- if (isLog) {
12052
- if (similarPairs.length > 0) {
12053
- similarPairs.forEach((pair) => {
12054
- console.log(pair[0]);
12055
- console.log(pair[1]);
12056
- console.log();
12057
- });
12058
- } else {
12059
- console.log("没有找到类似的字符串");
12060
- }
12061
- }
12062
- return uniqueArray;
12063
- };
12064
- var getTotal = (arr, key) => {
12065
- if (!Array.isArray(arr) || !key) {
12066
- return 0;
12067
- }
12068
- return arr.reduce((total, item) => {
12069
- const itemValue = Number(item[key]);
12070
- if (!isNaN(itemValue)) {
12071
- return performDecimalOperation(total, itemValue, "+");
12072
- }
12073
- return total;
12074
- }, 0);
12075
- };
12076
- // src/common/image.ts
12077
- import axios from "axios";
12078
- async function imageToBase64(url) {
12079
- try {
12080
- const response = await axios.get(url, {
12081
- responseType: "arraybuffer"
12082
- });
12083
- const base64String = Buffer.from(response.data).toString("base64");
12084
- return `data:image/*;base64,${base64String}`;
12085
- } catch (error) {
12086
- console.error("Failed to fetch the image:", error);
12087
- throw error;
12088
- }
12089
- }
12090
- // src/common/enum.ts
12091
- class EnumItem {
12092
- label;
12093
- value;
12094
- extra;
12095
- constructor(config2) {
12096
- this.value = config2.value;
12097
- this.label = config2.label;
12098
- this.extra = config2.extra;
9690
+ // src/common/enum.ts
9691
+ class EnumItem {
9692
+ label;
9693
+ value;
9694
+ extra;
9695
+ constructor(config) {
9696
+ this.value = config.value;
9697
+ this.label = config.label;
9698
+ this.extra = config.extra;
12099
9699
  }
12100
9700
  }
12101
9701
  var Enum = {
@@ -12107,8 +9707,8 @@ var Enum = {
12107
9707
  const extras = new Map;
12108
9708
  const labels = new Map;
12109
9709
  const enums = {};
12110
- for (const key in members) {
12111
- const member = members[key];
9710
+ for (const key2 in members) {
9711
+ const member = members[key2];
12112
9712
  if (!member)
12113
9713
  continue;
12114
9714
  if (usedValues.has(member.value)) {
@@ -12116,7 +9716,7 @@ var Enum = {
12116
9716
  }
12117
9717
  usedValues.add(member.value);
12118
9718
  const item = new EnumItem(member);
12119
- enumObj[key] = item;
9719
+ enumObj[key2] = item;
12120
9720
  map.set(item.value, item);
12121
9721
  labels.set(item.value, item.label);
12122
9722
  options.push(item);
@@ -12174,51 +9774,7 @@ var initChinaDayjs = () => {
12174
9774
  };
12175
9775
  var chinaDayjs = initChinaDayjs();
12176
9776
  var dayjs_default = dayjs;
12177
- // src/ai/302/index.ts
12178
- var exports_302 = {};
12179
- __export(exports_302, {
12180
- chat: () => chat
12181
- });
12182
-
12183
- // src/ai/302/axios.ts
12184
- import axios_ from "axios";
12185
- var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
12186
- var axios2 = axios_.create({
12187
- baseURL: "https://api.302.ai",
12188
- headers: {
12189
- "mj-api-secret": key,
12190
- Authorization: `Bearer ${key}`
12191
- }
12192
- });
12193
-
12194
- // src/ai/302/chat/index.ts
12195
- import json5 from "json5";
12196
- var chat = async (message, model = "gpt-4.1", isParse = true) => {
12197
- try {
12198
- let { data } = await axios2({
12199
- url: "/v1/chat/completions",
12200
- method: "post",
12201
- data: {
12202
- model,
12203
- message
12204
- }
12205
- });
12206
- console.log(666, typeof data, data);
12207
- const output = typeof data === "string" ? json5.parse(data)?.output : data?.output;
12208
- if (isParse) {
12209
- const match = /```(json)?(.*)```/s.exec(output);
12210
- if (!match) {
12211
- return json5.parse(output);
12212
- } else {
12213
- return json5.parse(match[2]);
12214
- }
12215
- }
12216
- return output;
12217
- } catch (error) {
12218
- throw new Error(error?.response?.statusText || error?.message || "未知原因");
12219
- }
12220
- };
12221
- // src/node/mail/index.ts
9777
+ // src/node/mail.ts
12222
9778
  import nodemailer from "nodemailer";
12223
9779
  var authMap = {
12224
9780
  163: {
@@ -12236,17 +9792,17 @@ var transporter = nodemailer.createTransport({
12236
9792
  secure: true,
12237
9793
  auth: authMap.gmail
12238
9794
  });
12239
- var sendMail = (config2) => {
9795
+ var sendMail = (config) => {
12240
9796
  return transporter.sendMail({
12241
9797
  from: authMap.gmail.user,
12242
- ...config2
9798
+ ...config
12243
9799
  });
12244
9800
  };
12245
- // src/node/file/index.ts
9801
+ // src/node/file.ts
12246
9802
  import fs from "fs-extra";
12247
- import axios3 from "axios";
12248
- import url from "url";
12249
- import * as path from "path";
9803
+ import axios4 from "axios";
9804
+ import url2 from "url";
9805
+ import * as path2 from "path";
12250
9806
  var replaceContentInFile = async (filePath, targetContent, replacement) => {
12251
9807
  try {
12252
9808
  const data = await fs.readFile(filePath, "utf8");
@@ -12268,15 +9824,15 @@ var replaceContentInFile = async (filePath, targetContent, replacement) => {
12268
9824
  };
12269
9825
  var downloadFile = async (httpUrl, outputPath) => {
12270
9826
  try {
12271
- let parsedUrl = url.parse(httpUrl);
12272
- let fileName = path.basename(parsedUrl.pathname);
9827
+ let parsedUrl = url2.parse(httpUrl);
9828
+ let fileName = path2.basename(parsedUrl.pathname);
12273
9829
  if (!outputPath) {
12274
9830
  if (!fs.existsSync(".tmp")) {
12275
9831
  fs.mkdirSync(".tmp", { recursive: true });
12276
9832
  }
12277
9833
  outputPath = ".tmp/" + decodeURIComponent(fileName);
12278
9834
  }
12279
- const response = await axios3({
9835
+ const response = await axios4({
12280
9836
  url: httpUrl,
12281
9837
  method: "get",
12282
9838
  responseType: "stream"
@@ -12293,11 +9849,11 @@ var downloadFile = async (httpUrl, outputPath) => {
12293
9849
  throw error;
12294
9850
  }
12295
9851
  };
12296
- // src/node/oss/index.ts
9852
+ // src/node/oss.ts
12297
9853
  import OSS from "ali-oss";
12298
- import axios4 from "axios";
9854
+ import axios5 from "axios";
12299
9855
  import fs2 from "fs-extra";
12300
- import * as path2 from "path";
9856
+ import * as path3 from "path";
12301
9857
  var oss = new OSS({
12302
9858
  region: process.env.VITE_OSS_REGION,
12303
9859
  accessKeyId: process.env.VITE_OSS_ACCESS_KEY_ID,
@@ -12310,14 +9866,14 @@ async function uploadFile(file, filename) {
12310
9866
  if (typeof file === "string") {
12311
9867
  if (/^https?:\/\//.test(file)) {
12312
9868
  try {
12313
- const response = await axios4.get(file, { responseType: "arraybuffer" });
9869
+ const response = await axios5.get(file, { responseType: "arraybuffer" });
12314
9870
  buffer = Buffer.from(response.data);
12315
9871
  } catch (error) {
12316
9872
  throw new Error(`无法从 URL 下载文件: ${error}`);
12317
9873
  }
12318
- const originalName = path2.basename(new URL(file).pathname);
12319
- const ext = path2.extname(originalName);
12320
- const nameWithoutExt = path2.basename(originalName, ext);
9874
+ const originalName = path3.basename(new URL(file).pathname);
9875
+ const ext = path3.extname(originalName);
9876
+ const nameWithoutExt = path3.basename(originalName, ext);
12321
9877
  finalFilename = `${nameWithoutExt}_${Date.now()}${ext}`;
12322
9878
  } else {
12323
9879
  try {
@@ -12325,9 +9881,9 @@ async function uploadFile(file, filename) {
12325
9881
  } catch (error) {
12326
9882
  throw new Error(`无法读取文件路径: ${error}`);
12327
9883
  }
12328
- const originalName = path2.basename(file);
12329
- const ext = path2.extname(originalName);
12330
- const nameWithoutExt = path2.basename(originalName, ext);
9884
+ const originalName = path3.basename(file);
9885
+ const ext = path3.extname(originalName);
9886
+ const nameWithoutExt = path3.basename(originalName, ext);
12331
9887
  finalFilename = `${nameWithoutExt}_${Date.now()}${ext}`;
12332
9888
  }
12333
9889
  } else if (Buffer.isBuffer(file)) {
@@ -12350,7 +9906,7 @@ async function uploadFile(file, filename) {
12350
9906
  throw new Error(`上传到 OSS 失败: ${error}`);
12351
9907
  }
12352
9908
  }
12353
- // src/node/cron/index.ts
9909
+ // src/node/cron.ts
12354
9910
  import cron from "node-cron";
12355
9911
  var interval = (intervalMinutes, immediately, fn) => {
12356
9912
  console.log(`定时任务已启动,将每${intervalMinutes}分钟执行一次`);
@@ -12372,15 +9928,10 @@ var schedule = (cronExpression, immediately, fn) => {
12372
9928
  timezone: "Asia/Shanghai"
12373
9929
  });
12374
9930
  };
12375
-
12376
- // src/node/index.ts
12377
- import { default as default6, DataStoreOptions } from "nedb";
12378
- import * as cheerio from "cheerio";
12379
9931
  var export__ = import_lodash.default;
12380
9932
 
12381
9933
  export {
12382
9934
  exports_external as z,
12383
- watch,
12384
9935
  voidType as void,
12385
9936
  util,
12386
9937
  uploadFile,
@@ -12389,35 +9940,26 @@ export {
12389
9940
  undefinedType as undefined,
12390
9941
  tupleType as tuple,
12391
9942
  effectsType as transformer,
12392
- toString,
12393
9943
  symbolType as symbol,
12394
9944
  stringType as string,
12395
9945
  strictObjectType as strictObject,
12396
- shuffleArray,
12397
9946
  setErrorMap,
9947
+ setCookie,
12398
9948
  setType as set,
12399
9949
  sendMail,
12400
9950
  schedule,
12401
9951
  replaceContentInFile,
12402
- replaceByVariables,
12403
- replaceByRules,
12404
- replaceAll,
12405
- removeSimilarDuplicates,
12406
9952
  recordType as record,
12407
9953
  quotelessJson,
12408
9954
  promiseType as promise,
12409
- printConsoleLog,
12410
9955
  preprocessType as preprocess,
12411
9956
  pipelineType as pipeline,
12412
- performDecimalOperation,
12413
9957
  ostring,
12414
- optionsToEnum,
12415
9958
  optionalType as optional,
12416
9959
  onumber,
12417
9960
  oboolean,
12418
9961
  objectUtil,
12419
9962
  objectType as object,
12420
- numberWithCommas,
12421
9963
  numberType as number,
12422
9964
  nullableType as nullable,
12423
9965
  nullType as null,
@@ -12427,15 +9969,10 @@ export {
12427
9969
  mapType as map,
12428
9970
  makeIssue,
12429
9971
  literalType as literal,
12430
- limitDecimals,
12431
- levenshteinDistance,
12432
9972
  lazyType as lazy,
12433
9973
  late,
12434
- jsonParse,
12435
- default4 as json5,
12436
- isValidNumber,
9974
+ default5 as json5,
12437
9975
  isValid,
12438
- isJson,
12439
9976
  isDirty,
12440
9977
  isAsync,
12441
9978
  isAborted,
@@ -12444,48 +9981,30 @@ export {
12444
9981
  instanceOfType as instanceof,
12445
9982
  initChinaDayjs,
12446
9983
  imageToBase64,
12447
- getType,
12448
- getTotal,
12449
- getStrLength,
12450
- getSliceStr,
12451
- getRandomString,
12452
- getRandomNum,
12453
- getRandomColor,
12454
- getProxyUrl,
9984
+ getVideoStatus,
12455
9985
  getParsedType,
12456
- getLength,
12457
- getFileSize,
12458
9986
  getErrorMap,
12459
- getCookie,
12460
- getChineseByStr,
12461
- getChinese,
12462
- generateUniqueFileName,
12463
- generateAlphabetArray,
9987
+ generateVideo,
12464
9988
  functionType as function,
12465
- findItem,
12466
- filterParams,
12467
9989
  enumType as enum,
12468
9990
  effectsType as effect,
12469
9991
  downloadFile,
12470
9992
  discriminatedUnionType as discriminatedUnion,
12471
- delay,
12472
9993
  en_default as defaultErrorMap,
12473
9994
  dayjs_default as dayjs,
12474
9995
  datetimeRegex,
12475
9996
  dateType as date,
12476
9997
  custom,
12477
- default5 as consola,
9998
+ default6 as consola,
12478
9999
  coerce,
12479
10000
  chinaDayjs,
12480
10001
  cheerio,
12481
- calcJsText,
10002
+ chat,
12482
10003
  booleanType as boolean,
12483
10004
  bigIntType as bigint,
12484
- default3 as axios,
10005
+ default4 as axios,
12485
10006
  arrayType as array,
12486
10007
  anyType as any,
12487
- amount,
12488
- exports_302 as ai302,
12489
10008
  addIssueToContext,
12490
10009
  export__ as _,
12491
10010
  ZodVoid,
@@ -12541,7 +10060,7 @@ export {
12541
10060
  EMPTY_PATH,
12542
10061
  Dayjs,
12543
10062
  DataStoreOptions,
12544
- default6 as DataStore,
10063
+ default2 as DataStore,
12545
10064
  DIRTY,
12546
10065
  BRAND
12547
10066
  };