ddan-js 2.9.3 → 2.9.5

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 (133) hide show
  1. package/bin/ddan-js.browser.js +1 -1
  2. package/bin/ddan-js.esm.js +1 -1
  3. package/bin/ddan-js.js +1 -1
  4. package/bin/types/browser.d.ts +3 -3
  5. package/bin/types/index.d.ts +4 -3
  6. package/bin/types/modules/fetch.d.ts +1 -1
  7. package/bin/types/modules/node/index.d.ts +2 -0
  8. package/package.json +18 -13
  9. package/bin/lib/browser.js +0 -111
  10. package/bin/lib/class/event.js +0 -104
  11. package/bin/lib/class/getset.js +0 -12
  12. package/bin/lib/class/icon.js +0 -94
  13. package/bin/lib/class/joker.js +0 -121
  14. package/bin/lib/class/kvalue.js +0 -29
  15. package/bin/lib/class/mapping.js +0 -82
  16. package/bin/lib/class/persist.js +0 -65
  17. package/bin/lib/class/pipeTask.js +0 -42
  18. package/bin/lib/class/pipeparallel.js +0 -24
  19. package/bin/lib/class/store.js +0 -87
  20. package/bin/lib/class/tracker.js +0 -125
  21. package/bin/lib/class/watermark.js +0 -63
  22. package/bin/lib/common/_Symbol.js +0 -5
  23. package/bin/lib/common/_freeGlobal.js +0 -5
  24. package/bin/lib/common/_object.js +0 -40
  25. package/bin/lib/common/_root.js +0 -10
  26. package/bin/lib/common/internal/asciiToArray.js +0 -13
  27. package/bin/lib/common/internal/castSlice.js +0 -18
  28. package/bin/lib/common/internal/createCaseFirst.js +0 -30
  29. package/bin/lib/common/internal/hasUnicode.js +0 -26
  30. package/bin/lib/common/internal/nodeTypes.js +0 -26
  31. package/bin/lib/common/internal/slice.js +0 -46
  32. package/bin/lib/common/internal/stringToArray.js +0 -18
  33. package/bin/lib/common/internal/unicodeToArray.js +0 -40
  34. package/bin/lib/common/internal/unicodeWords.js +0 -67
  35. package/bin/lib/index.js +0 -114
  36. package/bin/lib/modules/browser/ecdh.js +0 -124
  37. package/bin/lib/modules/browser/index.js +0 -4
  38. package/bin/lib/modules/cdn.js +0 -62
  39. package/bin/lib/modules/convert/base.js +0 -125
  40. package/bin/lib/modules/convert/base64.js +0 -114
  41. package/bin/lib/modules/convert/index.js +0 -99
  42. package/bin/lib/modules/convert/md5.js +0 -222
  43. package/bin/lib/modules/convert/pkcs.js +0 -16
  44. package/bin/lib/modules/convert/utf8.js +0 -106
  45. package/bin/lib/modules/crypto/base64.js +0 -14
  46. package/bin/lib/modules/crypto/const.js +0 -7
  47. package/bin/lib/modules/crypto/index.js +0 -30
  48. package/bin/lib/modules/crypto/rsa.js +0 -143
  49. package/bin/lib/modules/crypto/tea.js +0 -79
  50. package/bin/lib/modules/crypto/uuid.js +0 -34
  51. package/bin/lib/modules/css.js +0 -137
  52. package/bin/lib/modules/decorator.js +0 -14
  53. package/bin/lib/modules/fetch.js +0 -82
  54. package/bin/lib/modules/gbk.js +0 -46
  55. package/bin/lib/modules/hook/base.js +0 -60
  56. package/bin/lib/modules/hook/hooker.js +0 -39
  57. package/bin/lib/modules/hook/index.js +0 -49
  58. package/bin/lib/modules/hook/log.js +0 -54
  59. package/bin/lib/modules/hook/modules/bezier.js +0 -121
  60. package/bin/lib/modules/hook/modules/debounce.js +0 -127
  61. package/bin/lib/modules/hook/modules/mutex.js +0 -22
  62. package/bin/lib/modules/hook/modules/pipeline.js +0 -59
  63. package/bin/lib/modules/hook/modules/polling.js +0 -20
  64. package/bin/lib/modules/hook/modules/safeTask.js +0 -25
  65. package/bin/lib/modules/hook/modules/throttle.js +0 -30
  66. package/bin/lib/modules/html.js +0 -293
  67. package/bin/lib/modules/http/index.js +0 -171
  68. package/bin/lib/modules/http/interceptor.js +0 -22
  69. package/bin/lib/modules/list/base.js +0 -37
  70. package/bin/lib/modules/list/index.js +0 -90
  71. package/bin/lib/modules/logger.js +0 -55
  72. package/bin/lib/modules/math/index.js +0 -118
  73. package/bin/lib/modules/mini/diff.js +0 -97
  74. package/bin/lib/modules/mini/http/index.js +0 -155
  75. package/bin/lib/modules/mini/index.js +0 -71
  76. package/bin/lib/modules/node/aliyun.js +0 -156
  77. package/bin/lib/modules/node/brotli.js +0 -46
  78. package/bin/lib/modules/node/child.js +0 -18
  79. package/bin/lib/modules/node/ecdh-web.js +0 -11
  80. package/bin/lib/modules/node/ecdh.js +0 -115
  81. package/bin/lib/modules/node/file.js +0 -25
  82. package/bin/lib/modules/node/index.js +0 -11
  83. package/bin/lib/modules/node/proxy.js +0 -147
  84. package/bin/lib/modules/node/rsa-web.js +0 -19
  85. package/bin/lib/modules/node/socks5.js +0 -424
  86. package/bin/lib/modules/obj/index.js +0 -184
  87. package/bin/lib/modules/qs/base.js +0 -5
  88. package/bin/lib/modules/qs/decode.js +0 -45
  89. package/bin/lib/modules/qs/encode.js +0 -53
  90. package/bin/lib/modules/qs/index.js +0 -114
  91. package/bin/lib/modules/regex.js +0 -16
  92. package/bin/lib/modules/rsa.js +0 -18
  93. package/bin/lib/modules/rule/async-validator/index.js +0 -306
  94. package/bin/lib/modules/rule/async-validator/interface.js +0 -2
  95. package/bin/lib/modules/rule/async-validator/messages.js +0 -59
  96. package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
  97. package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
  98. package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
  99. package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
  100. package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
  101. package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
  102. package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
  103. package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
  104. package/bin/lib/modules/rule/async-validator/util.js +0 -255
  105. package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
  106. package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
  107. package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
  108. package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
  109. package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
  110. package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
  111. package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
  112. package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
  113. package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
  114. package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
  115. package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
  116. package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
  117. package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
  118. package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
  119. package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
  120. package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
  121. package/bin/lib/modules/rule/index.js +0 -67
  122. package/bin/lib/modules/string/index.js +0 -121
  123. package/bin/lib/modules/string/words.js +0 -33
  124. package/bin/lib/modules/time/const.js +0 -11
  125. package/bin/lib/modules/time/dtime.js +0 -132
  126. package/bin/lib/modules/time/frame.js +0 -49
  127. package/bin/lib/modules/time/index.js +0 -84
  128. package/bin/lib/typings/index.js +0 -2
  129. package/bin/lib/util/function.js +0 -33
  130. package/bin/lib/util/includes.js +0 -96
  131. package/bin/lib/util/index.js +0 -26
  132. package/bin/lib/util/is.js +0 -148
  133. package/bin/lib/util/to.js +0 -47
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const convert_1 = require("../convert");
4
- const RSAPublicKey = `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApiLWsPmoaiGdr02AmPYS
5
- 4/VgxyJNNJSK2VICirXl4P8qAP3b/6GIs7Hwnsmmuj7gledJ0XiZodFjDNgQEZEG
6
- j4K9KX8NixcrJwnTQV5UebiERdj+64ihwqPVWo9dIOj43ZPJ8f4dritJv5tnQaBb
7
- b9zTkU3Ofzk1g8RU00Ith6quOGZcU2IWC4OQ+5YiZvzrCBKEvjFwK2OvGq43tI51
8
- GaZdI9H09jisypqefsMvv6esjEQQOtl+WGlI5fof7KZUt3dppvuDI4CYgeXIoKKL
9
- 9T9qDl8F9aNSs3XHx32YyA7L1FraFD6PjqRjueIFp2emsXQcIMeMqqgVyV+4qb+0
10
- uwIDAQAB`;
11
- const RSAPrivateKey = `MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmItaw+ahqIZ2v
12
- TYCY9hLj9WDHIk00lIrZUgKKteXg/yoA/dv/oYizsfCeyaa6PuCV50nReJmh0WMM
13
- 2BARkQaPgr0pfw2LFysnCdNBXlR5uIRF2P7riKHCo9Vaj10g6Pjdk8nx/h2uK0m/
14
- m2dBoFtv3NORTc5/OTWDxFTTQi2Hqq44ZlxTYhYLg5D7liJm/OsIEoS+MXArY68a
15
- rje0jnUZpl0j0fT2OKzKmp5+wy+/p6yMRBA62X5YaUjl+h/splS3d2mm+4MjgJiB
16
- 5cigoov1P2oOXwX1o1KzdcfHfZjIDsvUWtoUPo+OpGO54gWnZ6axdBwgx4yqqBXJ
17
- X7ipv7S7AgMBAAECggEAE1kuWLkSsJ2OoDpt9iJ+a7cJmNd5V1zPWOTwr9fkWFJP
18
- QYNPKlPVOFxKUivY84rcHAkuMyuQ9OQOXZISOQGDWpZW0mzeFmtR1r+Rr2S9gNmI
19
- 6huOAL9OW306HUxiA7GuPhv2omy+Zyjac2q1WVLEI2B78Um2+WEfxuNIH7xu0gRR
20
- z/wluevMBQlv6hSeMESP6e9s2kB+FuM4bL7+1sexwS1TudKbHybujaiB8un9E2V3
21
- C9BkE6yf00Rhvii6Q4E4w3PFQfcBEFnjOD0S2Watx8GIbYjlYvtquy8Yj7OtyZB6
22
- w5sxyaYhKVVnkpGAbOgaCj94ABYF47VuwXr45I4PzQKBgQDp6svzD+QKlARjcWgO
23
- rH7UEpFX6m49G6Ib4c63xEg9+GesTgfDxoYxtXDKsC7I8OwMrmffJGbyfjaAvzmg
24
- icM3Y7kF6UPO9+q2mBRsyhoJSNONTeUVyoFSc+QDsVgndlTZIjqC5XLrONGaSPLJ
25
- 7jJzqKhp3NQcpO8+xY0d7Efm1QKBgQC10fCNuF1LUTYgsWvvGxTiCCAIBurZmHU+
26
- GMb2Okfoco/P+QNl1jEba91AC7FudW3g/lRn0vTnDajlNoz2/CKunrTKN4/9lEBI
27
- tiwEOvhc5FtapRifSfrrNwFqPM+LijvOkcteWVhAUWCEP1eLmpnXGqfmZxnTaaVe
28
- 5DyDgyAVTwKBgQDhEawfOQEANJ9sV2f6BnsZ7quuXcCoR3hZP5G5O8EO735BSesq
29
- sk/YcG4QeCjr6vQU15LWH552YH5srpHyJ9uP5gHW8DTwZZaPDhFJA8S9fjcfVP3B
30
- U9HO1fdknjTl83N8YPTPkZpbPZZfzyTcqrYclwFEqtfkn8YbLdW0Hu6n6QKBgDEv
31
- jvS3uD1ExfDILlurptWSvx+Mx4F/1c+roj8/+u3t9+uaAIpPDE/PuTW3NBOens/r
32
- 3WeM0QWkU1lWjYHPKY61jlDaARDnRxCkf3nRfhibCf+Wg/erar6wzagwtTCZf55d
33
- IHfwkYgsu4BrJkK02wMuydbxczIW9U6bTaeCFG7PAoGAN3oHYzTEBwZ7ZKv11QiQ
34
- Ep/HeHBvD8fH/e1uVyBel4Co7NO5pV2s8qjS8+3+jxumKLNXCirjqwHo03YCdzxi
35
- cy4GFDsukHmDQ7FF9VC4QV0fJ0F7jGYE9nNZ+K9qwS5KrihOSBPxj0HptrF6TSOw
36
- BTSwr0byL3TC0m0StkSNKpo=`;
37
- const generateKeys = async (subtle) => {
38
- try {
39
- // 生成RSA密钥对
40
- const keyPair = await subtle.generateKey({
41
- name: 'RSA-OAEP',
42
- modulusLength: 2048,
43
- publicExponent: new Uint8Array([1, 0, 1]),
44
- hash: 'SHA-256',
45
- }, true, // 是否可导出密钥
46
- ['encrypt', 'decrypt']);
47
- // 导出公钥为SPKI格式(可共享)
48
- const publicBuffer = await window.crypto.subtle.exportKey('spki', keyPair.publicKey);
49
- const publicKey = format_pem_content(publicBuffer);
50
- const publicKeyPem = format_pem_key(publicKey, 'PUBLIC KEY');
51
- // 导出私钥为PKCS#8格式(需保护)
52
- const privateBuffer = await window.crypto.subtle.exportKey('pkcs8', keyPair.privateKey);
53
- const privateKey = format_pem_content(privateBuffer);
54
- const privateKeyPem = format_pem_key(privateKey, 'PRIVATE KEY');
55
- return {
56
- publicKey,
57
- publicKeyPem,
58
- privateKey,
59
- privateKeyPem,
60
- };
61
- }
62
- catch (err) {
63
- console.error('generateKeys failed:', err);
64
- return {
65
- publicKey: '',
66
- publicKeyPem: '',
67
- privateKey: '',
68
- privateKeyPem: '',
69
- };
70
- }
71
- };
72
- const format_pem_content = (buffer) => {
73
- try {
74
- const base64String = convert_1.default.ab2str(buffer, true);
75
- return base64String.match(/.{1,64}/g)?.join('\n') || '';
76
- }
77
- catch (error) {
78
- return '';
79
- }
80
- };
81
- const format_pem_key = (pemContent = '', label = 'PUBLIC KEY') => {
82
- return `-----BEGIN ${label}-----\n${pemContent}\n-----END ${label}-----`;
83
- };
84
- // SHA256: 256 - 2 - 2*32 = 190
85
- // SHA1: 256 - 2 - 2*20 = 214
86
- const maxChunkSize = 190;
87
- const encrypt = async (subtle, data, publicKey) => {
88
- try {
89
- const bytes = new TextEncoder().encode(data);
90
- const key = await subtle.importKey('spki', convert_1.default.str2ab(publicKey, true), {
91
- name: 'RSA-OAEP',
92
- hash: 'SHA-256',
93
- }, true, ['encrypt']);
94
- const encryptedChunks = [];
95
- for (let i = 0; i < bytes.length; i += maxChunkSize) {
96
- let chunk = bytes.slice(i, i + maxChunkSize);
97
- let encryptedChunk = await subtle.encrypt({
98
- name: 'RSA-OAEP',
99
- }, key, chunk);
100
- encryptedChunks.push(new Uint8Array(encryptedChunk));
101
- }
102
- const enctryptedBytes = convert_1.default.concatBytes(...encryptedChunks);
103
- return convert_1.default.bytesToBase64(enctryptedBytes);
104
- }
105
- catch (error) {
106
- console.error(`[debug] encrypt`, error);
107
- return '';
108
- }
109
- };
110
- const decrypt = async (subtle, encryptedBase64, privateKey) => {
111
- try {
112
- const encrypted = convert_1.default.base64ToBytes(encryptedBase64);
113
- const key = await subtle.importKey('pkcs8', convert_1.default.str2ab(privateKey, true), {
114
- name: 'RSA-OAEP',
115
- hash: 'SHA-256',
116
- }, true, ['decrypt']);
117
- const decryptedChunks = [];
118
- const chunkSize = 256; // 每个加密块的大小(2048位 RSA 的加密输出为 256 字节)
119
- for (let i = 0; i < encrypted.length; i += chunkSize) {
120
- let chunk = encrypted.slice(i, i + chunkSize);
121
- let decryptedChunk = await subtle.decrypt({
122
- name: 'RSA-OAEP',
123
- }, key, chunk);
124
- // 添加解密后的数据
125
- decryptedChunks.push(new Uint8Array(decryptedChunk));
126
- }
127
- const encryptedBytes = convert_1.default.concatBytes(...decryptedChunks);
128
- return new TextDecoder().decode(encryptedBytes);
129
- }
130
- catch (err) {
131
- console.error('decrypt failed:', err);
132
- return '';
133
- }
134
- };
135
- exports.default = {
136
- RSAPublicKey,
137
- RSAPrivateKey,
138
- generateKeys,
139
- format_pem_key,
140
- format_pem_content,
141
- encrypt,
142
- decrypt,
143
- };
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const convert_1 = require("../convert");
4
- const delta = 0x9e3779b9; // 常量 Delta
5
- const TEAKey = "33576f37387276645054657a6831686e454664424e5652456f47794835795942";
6
- const encrypt = (v, teaKey) => {
7
- let sum = 0;
8
- const n = 32; // 32轮加密
9
- for (let i = 0; i < n; i++) {
10
- sum = (sum + delta) >>> 0;
11
- v[0] = (v[0] + (((v[1] << 4) + teaKey[0]) ^ (v[1] + sum) ^ ((v[1] >>> 5) + teaKey[1]))) >>> 0;
12
- v[1] = (v[1] + (((v[0] << 4) + teaKey[2]) ^ (v[0] + sum) ^ ((v[0] >>> 5) + teaKey[3]))) >>> 0;
13
- }
14
- return v;
15
- };
16
- const decrypt = (v, teaKey) => {
17
- const n = 32; // 32轮解密
18
- let sum = (delta * n) >>> 0;
19
- for (let i = 0; i < n; i++) {
20
- v[1] = (v[1] - (((v[0] << 4) + teaKey[2]) ^ (v[0] + sum) ^ ((v[0] >>> 5) + teaKey[3]))) >>> 0;
21
- v[0] = (v[0] - (((v[1] << 4) + teaKey[0]) ^ (v[1] + sum) ^ ((v[1] >>> 5) + teaKey[1]))) >>> 0;
22
- sum = (sum - delta) >>> 0;
23
- }
24
- return v;
25
- };
26
- /**
27
- * TEA KEY
28
- * @param str 位
29
- * @returns 4组32位
30
- */
31
- const toTeaKey = (str) => {
32
- const keyBytes = convert_1.default.str2bytes(str);
33
- const key = new Uint32Array(4);
34
- key[0] = (keyBytes[0] << 24) | (keyBytes[1] << 16) | (keyBytes[2] << 8) | keyBytes[3];
35
- key[1] = (keyBytes[4] << 24) | (keyBytes[5] << 16) | (keyBytes[6] << 8) | keyBytes[7];
36
- key[2] = (keyBytes[8] << 24) | (keyBytes[9] << 16) | (keyBytes[10] << 8) | keyBytes[11];
37
- key[3] = (keyBytes[12] << 24) | (keyBytes[13] << 16) | (keyBytes[14] << 8) | keyBytes[15];
38
- return key;
39
- };
40
- const encodeBytes = (plainbytes, key) => {
41
- // 转换明文为字节数组并进行PKCS#7填充
42
- const padded = convert_1.default.pkcs7Padding(plainbytes, 8);
43
- // 将明文分块并加密
44
- const key4LongBytes = toTeaKey(key);
45
- const encryptedBlocks = [];
46
- for (let i = 0; i < padded.length; i += 8) {
47
- const block = convert_1.default.bytesToUint32(padded.slice(i, i + 8));
48
- const encryptedBlock = encrypt(block, key4LongBytes);
49
- encryptedBlocks.push(convert_1.default.uint32ToBytes(encryptedBlock));
50
- }
51
- const encoded = convert_1.default.concatBytes(...encryptedBlocks);
52
- return encoded;
53
- };
54
- const decodeBytes = (cipherbytes, key) => {
55
- // 将密文分块并解密
56
- const key4LongBytes = toTeaKey(key);
57
- const decryptedBlocks = [];
58
- for (let i = 0; i < cipherbytes.length; i += 8) {
59
- const block = convert_1.default.bytesToUint32(cipherbytes.slice(i, i + 8));
60
- const decryptedBlock = decrypt(block, key4LongBytes);
61
- decryptedBlocks.push(convert_1.default.uint32ToBytes(decryptedBlock));
62
- }
63
- const decryptedBytes = convert_1.default.concatBytes(...decryptedBlocks);
64
- // 去除填充并返回明文
65
- const decryptedUnpaddBytes = convert_1.default.pkcs7Unpadding(decryptedBytes);
66
- return decryptedUnpaddBytes;
67
- };
68
- const encode = (plaintext, key) => {
69
- // 转换明文为字节数组并进行PKCS#7填充
70
- const plainBytes = convert_1.default.textEncode(plaintext);
71
- const encoded = encodeBytes(plainBytes, key);
72
- return convert_1.default.bytesToBase64(encoded);
73
- };
74
- const decode = (ciphertext, key) => {
75
- const cipherBytes = convert_1.default.base64ToBytes(ciphertext);
76
- const decryptedBytes = decodeBytes(cipherBytes, key);
77
- return convert_1.default.textDecode(decryptedBytes.buffer);
78
- };
79
- exports.default = { TEAKey, encrypt, decrypt, toTeaKey, encode, decode, encodeBytes, decodeBytes };
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const const_1 = require("./const");
4
- /**
5
- * 生成随机ID
6
- * @param len id长度,0默认为uuid xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx 格式
7
- * @param radix KeyChars 涉及的长度
8
- * @returns
9
- */
10
- const uuid = (len = 0, radix = 0) => {
11
- const chars = const_1.default.keyChars.split('');
12
- const result = [];
13
- let i;
14
- radix = radix || chars.length;
15
- if (len) {
16
- // Compact form
17
- for (i = 0; i < len; i++)
18
- result[i] = chars[0 | Math.random() * radix];
19
- }
20
- else {
21
- let r;
22
- result[8] = result[13] = result[18] = result[23] = '-';
23
- result[14] = '4';
24
- // Fill in random data. At i==19 set the high bits of clock sequence as
25
- for (i = 0; i < 36; i++) {
26
- if (!result[i]) {
27
- r = 0 | Math.random() * 16;
28
- result[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
29
- }
30
- }
31
- }
32
- return result.join('');
33
- };
34
- exports.default = uuid;
@@ -1,137 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../util");
4
- const qs_1 = require("./qs");
5
- const rule_1 = require("./rule");
6
- const string_1 = require("./string");
7
- const stringify = (styleObj) => {
8
- if (!styleObj)
9
- return '';
10
- if (!util_1.default.isObject(styleObj))
11
- return '';
12
- let result = '';
13
- util_1.default.forof(styleObj, (k, v) => {
14
- if (!v)
15
- return;
16
- result += `${string_1.default.kebabCase(k)}:${v};`;
17
- });
18
- return result;
19
- };
20
- const parse = (styleStr, { camel = false, pure = true } = {}) => {
21
- if (!styleStr.trim())
22
- return undefined;
23
- const ret = qs_1.default.parse(styleStr, { sep: ';', eq: ':', uri: false });
24
- const result = {};
25
- util_1.default.forof(ret, (k, v) => {
26
- if (!v)
27
- return;
28
- const _k = camel ? ((pure && k.startsWith("_")) ? k : string_1.default.camelCase(k)) : k;
29
- if (rule_1.default.isFloat(v)) {
30
- result[_k] = +v;
31
- }
32
- else if (v.length >= 2 && v.startsWith('.') && rule_1.default.isNumber(v.substr(1))) {
33
- result[_k] = +v;
34
- }
35
- else {
36
- result[_k] = v;
37
- }
38
- });
39
- return result;
40
- };
41
- const commonFields = [
42
- "display",
43
- "position",
44
- "top",
45
- "bottom",
46
- "left",
47
- "right",
48
- "padding",
49
- "margin",
50
- "marginTop",
51
- "marginRight",
52
- "marginBottom",
53
- "marginLeft",
54
- "paddingTop",
55
- "paddingRight",
56
- "paddingBottom",
57
- "paddingLeft",
58
- "height",
59
- "width",
60
- "fontSize",
61
- "textAlign",
62
- "fontFamily",
63
- "border",
64
- "borderLeft",
65
- "borderRight",
66
- "borderTop",
67
- "borderBottom",
68
- "borderColor",
69
- "borderRadius",
70
- "background",
71
- "backgroundImage",
72
- "backgroundRepeat",
73
- "backgroundSize",
74
- "backgroundPosition",
75
- "color",
76
- "overflow",
77
- "opacity",
78
- "flexDirection",
79
- "justifyContent",
80
- "alignItems",
81
- "flexWrap",
82
- "alignContent",
83
- "alignSelf",
84
- "flex",
85
- "flexBasis",
86
- "flexFlow",
87
- "flexShrink",
88
- "pointerEvents",
89
- ];
90
- const fixFields = [
91
- "top",
92
- "bottom",
93
- "left",
94
- "right",
95
- "padding",
96
- "margin",
97
- "marginTop",
98
- "marginRight",
99
- "marginBottom",
100
- "marginLeft",
101
- "paddingTop",
102
- "paddingRight",
103
- "paddingBottom",
104
- "paddingLeft",
105
- "height",
106
- "width",
107
- "border",
108
- "borderLeft",
109
- "borderRight",
110
- "borderTop",
111
- "borderBottom",
112
- "borderColor",
113
- "borderRadius",
114
- ];
115
- const style = (cssKV, unit = 'px') => {
116
- if (!cssKV)
117
- return "";
118
- const _kv = util_1.default.copy(cssKV, { fields: commonFields });
119
- util_1.default.forof(_kv, (k, v) => {
120
- if (fixFields.includes(k) || fixFields.includes(string_1.default.camelCase(k))) {
121
- _kv[k] = fixValue(v, unit);
122
- }
123
- });
124
- const result = stringify(_kv);
125
- return result;
126
- };
127
- const fixValue = (value, unit = 'px') => {
128
- if (!value || !unit)
129
- return value;
130
- if (value === '0')
131
- return value;
132
- if (rule_1.default.isFloat(value.toString())) {
133
- return `${value}${unit}`;
134
- }
135
- return value;
136
- };
137
- exports.default = { stringify, parse, fixValue, style, commonFields };
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.catchMethod = void 0;
4
- const catchMethod = (_target, _methodName, descriptor) => {
5
- const originalMethod = descriptor.value;
6
- descriptor.value = function (...args) {
7
- try {
8
- return originalMethod.apply(this, args);
9
- }
10
- catch (err) {
11
- }
12
- };
13
- };
14
- exports.catchMethod = catchMethod;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const base_1 = require("./hook/base");
4
- const convert_1 = require("./convert");
5
- const math_1 = require("./math");
6
- const getDataURL = (url, cache) => {
7
- const result = {
8
- contentType: '',
9
- dataUrl: '',
10
- };
11
- return base_1.default.to(fetch(url, { cache })
12
- .then((response) => {
13
- result.contentType = response.headers.get('content-type') || '';
14
- return response.arrayBuffer();
15
- })
16
- .then((data) => {
17
- result.dataUrl = `data:${result.contentType};base64,` + convert_1.default.ab2str(data, true);
18
- return result;
19
- }));
20
- };
21
- const getArrayBuffer = async (url, cache) => {
22
- return base_1.default.to(fetch(url, { cache }).then((response) => {
23
- return response.arrayBuffer();
24
- }));
25
- };
26
- const getJson = async (url, cache) => {
27
- return base_1.default.to(fetch(url, { cache }).then((response) => {
28
- return response.json();
29
- }));
30
- };
31
- const getText = async (url, cache) => {
32
- return base_1.default.to(fetch(url, { cache }).then((response) => {
33
- return response.text();
34
- }));
35
- };
36
- const cache = async (url, cache) => {
37
- return base_1.default.to(fetch(url, { cache }).then(() => {
38
- return true;
39
- }));
40
- };
41
- const download = (url, opts = {}) => {
42
- return new Promise((resolve) => fetch(url)
43
- .then(async (response) => {
44
- if (!response.ok || response.status !== 200) {
45
- throw new Error(response.statusText);
46
- }
47
- const contentLength = +(response.headers.get('content-length') || '');
48
- const reader = response.body?.getReader();
49
- let receivedLength = 0;
50
- const chunks = [];
51
- while (true) {
52
- const { done, value } = await reader.read();
53
- if (done) {
54
- break;
55
- }
56
- chunks.push(value);
57
- receivedLength += value.length;
58
- const percentage = math_1.default.float((100.0 * receivedLength) / contentLength, { digits: 2 });
59
- opts?.progress && opts?.progress(percentage, receivedLength, contentLength);
60
- }
61
- const chunksAll = new Uint8Array(receivedLength);
62
- let position = 0;
63
- for (const chunk of chunks) {
64
- chunksAll.set(chunk, position);
65
- position += chunk.length;
66
- }
67
- opts?.success && opts?.success(chunksAll);
68
- resolve(chunksAll);
69
- })
70
- .catch((err) => {
71
- opts?.fail && opts?.fail(err);
72
- resolve(undefined);
73
- }));
74
- };
75
- exports.default = {
76
- getDataURL,
77
- getArrayBuffer,
78
- getJson,
79
- download,
80
- getText,
81
- cache,
82
- };
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- *
5
- * @param str
6
- * @returns
7
- */
8
- function gbkLength(str) {
9
- let len = 0;
10
- if (!str)
11
- return 0;
12
- for (let i = 0; i < str.length; i++) {
13
- if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
14
- len += 2;
15
- }
16
- else {
17
- len++;
18
- }
19
- }
20
- return len;
21
- }
22
- /**
23
- * 根据gbk字符长度截取内容
24
- * @param {string} source
25
- * @param {number} len
26
- */
27
- function gbkCut(source, len) {
28
- if (!source || len <= 0)
29
- return "";
30
- let n = 0;
31
- let idx = 0;
32
- for (let i = 0; i < source.length; i++) {
33
- if (source.charCodeAt(i) > 127 || source.charCodeAt(i) === 94) {
34
- n += 2;
35
- }
36
- else {
37
- n++;
38
- }
39
- if (n > len) {
40
- break;
41
- }
42
- idx = i;
43
- }
44
- return source.substr(0, idx + 1);
45
- }
46
- exports.default = { gbkLength, gbkCut };
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const is_1 = require("../../util/is");
4
- async function to(promise, errorExt, fn) {
5
- return promise
6
- .then((data) => {
7
- fn && fn();
8
- return [null, data];
9
- })
10
- .catch((err) => {
11
- if (errorExt) {
12
- Object.assign(err, errorExt);
13
- }
14
- fn && fn();
15
- return [err, undefined];
16
- });
17
- }
18
- /**
19
- * 延迟处理
20
- * @param ms 延迟时间(ms),默认:1000ms
21
- * @returns
22
- */
23
- const delay = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
24
- const safeRun = (func, fn) => {
25
- try {
26
- let temp;
27
- if (is_1.default.isFunction(func)) {
28
- temp = func();
29
- }
30
- else {
31
- temp = func;
32
- }
33
- // promise = is.isPromise(temp) ? temp : Promise.resolve(temp);
34
- return to(Promise.resolve(temp), undefined, fn);
35
- }
36
- catch (err) {
37
- fn && fn();
38
- return Promise.resolve([err, undefined]);
39
- }
40
- };
41
- const go = (task, fn) => safeRun(task, fn);
42
- const toError = (value) => {
43
- value = typeof value === 'function' ? value() : value;
44
- return typeof value === 'string' ? new Error(value) : value;
45
- };
46
- const timeout = (task, ms = 0, desc = 'timeout') => {
47
- if (ms <= 0) {
48
- return safeRun(task);
49
- }
50
- let timerid;
51
- function clear() {
52
- timerid && clearTimeout(timerid);
53
- }
54
- const fn = new Promise((resolve) => {
55
- clear();
56
- timerid = setTimeout(() => resolve([toError(desc || 'timeout'), undefined]), ms);
57
- });
58
- return Promise.race([safeRun(task, clear), fn]);
59
- };
60
- exports.default = { to, go, delay, safeRun, toError, timeout };
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const base_1 = require("./base");
4
- const function_1 = require("../../util/function");
5
- const pipeline_1 = require("./modules/pipeline");
6
- class DHooker extends function_1.default.singleton() {
7
- __lockedMap = new Map();
8
- pipeline = new pipeline_1.default();
9
- constructor() {
10
- super();
11
- }
12
- lock(id, func) {
13
- if (!id || !func)
14
- return undefined;
15
- const task = base_1.default.safeRun(func);
16
- this.__lockedMap.set(id, task);
17
- return task;
18
- }
19
- unlock(id) {
20
- if (!id)
21
- return;
22
- this.__lockedMap.has(id) && this.__lockedMap.delete(id);
23
- }
24
- async exec(func, taskId) {
25
- if (!func || !taskId) {
26
- return base_1.default.safeRun(func);
27
- }
28
- const _task = this.__lockedMap.get(taskId);
29
- if (_task)
30
- return _task;
31
- const _newTask = this.lock(taskId, func);
32
- if (!_newTask)
33
- return base_1.default.safeRun(func);
34
- const result = await _newTask;
35
- this.unlock(taskId);
36
- return result;
37
- }
38
- }
39
- exports.default = DHooker;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const debounce_1 = require("./modules/debounce");
4
- const throttle_1 = require("./modules/throttle");
5
- const mutex_1 = require("./modules/mutex");
6
- const pipeTask_1 = require("../../class/pipeTask");
7
- const base_1 = require("./base");
8
- const polling_1 = require("./modules/polling");
9
- const hooker_1 = require("./hooker");
10
- const pipeline_1 = require("./modules/pipeline");
11
- const safeTask_1 = require("./modules/safeTask");
12
- const log_1 = require("./log");
13
- const bezier_1 = require("./modules/bezier");
14
- /**
15
- *
16
- * @param task 任务
17
- * @param wait 最小等待时间,单位毫秒
18
- * @returns
19
- */
20
- async function run(task, wait = 0) {
21
- if (wait <= 0)
22
- return base_1.default.safeRun(task);
23
- const _time = wait > 0 ? Date.now() : 0;
24
- const result = await base_1.default.safeRun(task);
25
- const delta = Date.now() - _time;
26
- delta < wait && (await base_1.default.delay(wait - delta));
27
- return result;
28
- }
29
- const exec = (func, taskId = '') => hooker_1.default.I.exec(func, taskId);
30
- const pipe = (func, callback) => hooker_1.default.I.pipeline.push(func, callback);
31
- const pipeline = (max = 1) => new pipeline_1.default(max);
32
- const task = (param) => new pipeTask_1.default(param);
33
- const safeTask = (func, callback) => new safeTask_1.default(func, callback);
34
- exports.default = {
35
- ...base_1.default,
36
- ...log_1.default,
37
- ...bezier_1.default,
38
- sleep: base_1.default.delay,
39
- run,
40
- exec,
41
- debounce: debounce_1.default,
42
- throttle: throttle_1.default,
43
- task,
44
- mutex: mutex_1.default,
45
- polling: polling_1.default,
46
- pipe,
47
- pipeline,
48
- safeTask,
49
- };