ddan-js 2.9.4 → 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.
- package/bin/ddan-js.esm.js +1 -1
- package/bin/ddan-js.js +1 -1
- package/bin/types/browser.d.ts +1 -1
- package/bin/types/index.d.ts +2 -1
- package/bin/types/modules/node/index.d.ts +2 -0
- package/package.json +18 -13
- package/bin/lib/browser.js +0 -111
- package/bin/lib/class/event.js +0 -104
- package/bin/lib/class/getset.js +0 -12
- package/bin/lib/class/icon.js +0 -94
- package/bin/lib/class/joker.js +0 -121
- package/bin/lib/class/kvalue.js +0 -29
- package/bin/lib/class/mapping.js +0 -82
- package/bin/lib/class/persist.js +0 -65
- package/bin/lib/class/pipeTask.js +0 -42
- package/bin/lib/class/pipeparallel.js +0 -24
- package/bin/lib/class/store.js +0 -87
- package/bin/lib/class/tracker.js +0 -125
- package/bin/lib/class/watermark.js +0 -63
- package/bin/lib/common/_Symbol.js +0 -5
- package/bin/lib/common/_freeGlobal.js +0 -5
- package/bin/lib/common/_object.js +0 -40
- package/bin/lib/common/_root.js +0 -10
- package/bin/lib/common/internal/asciiToArray.js +0 -13
- package/bin/lib/common/internal/castSlice.js +0 -18
- package/bin/lib/common/internal/createCaseFirst.js +0 -30
- package/bin/lib/common/internal/hasUnicode.js +0 -26
- package/bin/lib/common/internal/nodeTypes.js +0 -26
- package/bin/lib/common/internal/slice.js +0 -46
- package/bin/lib/common/internal/stringToArray.js +0 -18
- package/bin/lib/common/internal/unicodeToArray.js +0 -40
- package/bin/lib/common/internal/unicodeWords.js +0 -67
- package/bin/lib/index.js +0 -114
- package/bin/lib/modules/browser/ecdh.js +0 -124
- package/bin/lib/modules/browser/index.js +0 -4
- package/bin/lib/modules/cdn.js +0 -62
- package/bin/lib/modules/convert/base.js +0 -125
- package/bin/lib/modules/convert/base64.js +0 -114
- package/bin/lib/modules/convert/index.js +0 -99
- package/bin/lib/modules/convert/md5.js +0 -222
- package/bin/lib/modules/convert/pkcs.js +0 -16
- package/bin/lib/modules/convert/utf8.js +0 -106
- package/bin/lib/modules/crypto/base64.js +0 -14
- package/bin/lib/modules/crypto/const.js +0 -7
- package/bin/lib/modules/crypto/index.js +0 -30
- package/bin/lib/modules/crypto/rsa.js +0 -143
- package/bin/lib/modules/crypto/tea.js +0 -79
- package/bin/lib/modules/crypto/uuid.js +0 -34
- package/bin/lib/modules/css.js +0 -137
- package/bin/lib/modules/decorator.js +0 -14
- package/bin/lib/modules/fetch.js +0 -82
- package/bin/lib/modules/gbk.js +0 -46
- package/bin/lib/modules/hook/base.js +0 -60
- package/bin/lib/modules/hook/hooker.js +0 -39
- package/bin/lib/modules/hook/index.js +0 -49
- package/bin/lib/modules/hook/log.js +0 -54
- package/bin/lib/modules/hook/modules/bezier.js +0 -121
- package/bin/lib/modules/hook/modules/debounce.js +0 -127
- package/bin/lib/modules/hook/modules/mutex.js +0 -22
- package/bin/lib/modules/hook/modules/pipeline.js +0 -59
- package/bin/lib/modules/hook/modules/polling.js +0 -20
- package/bin/lib/modules/hook/modules/safeTask.js +0 -25
- package/bin/lib/modules/hook/modules/throttle.js +0 -30
- package/bin/lib/modules/html.js +0 -293
- package/bin/lib/modules/http/index.js +0 -171
- package/bin/lib/modules/http/interceptor.js +0 -22
- package/bin/lib/modules/list/base.js +0 -37
- package/bin/lib/modules/list/index.js +0 -90
- package/bin/lib/modules/logger.js +0 -55
- package/bin/lib/modules/math/index.js +0 -118
- package/bin/lib/modules/mini/diff.js +0 -97
- package/bin/lib/modules/mini/http/index.js +0 -155
- package/bin/lib/modules/mini/index.js +0 -71
- package/bin/lib/modules/node/aliyun.js +0 -156
- package/bin/lib/modules/node/brotli.js +0 -46
- package/bin/lib/modules/node/child.js +0 -18
- package/bin/lib/modules/node/ecdh-web.js +0 -11
- package/bin/lib/modules/node/ecdh.js +0 -115
- package/bin/lib/modules/node/file.js +0 -25
- package/bin/lib/modules/node/index.js +0 -11
- package/bin/lib/modules/node/proxy.js +0 -147
- package/bin/lib/modules/node/rsa-web.js +0 -19
- package/bin/lib/modules/node/socks5.js +0 -424
- package/bin/lib/modules/obj/index.js +0 -184
- package/bin/lib/modules/qs/base.js +0 -5
- package/bin/lib/modules/qs/decode.js +0 -45
- package/bin/lib/modules/qs/encode.js +0 -53
- package/bin/lib/modules/qs/index.js +0 -152
- package/bin/lib/modules/regex.js +0 -16
- package/bin/lib/modules/rsa.js +0 -18
- package/bin/lib/modules/rule/async-validator/index.js +0 -306
- package/bin/lib/modules/rule/async-validator/interface.js +0 -2
- package/bin/lib/modules/rule/async-validator/messages.js +0 -59
- package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
- package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
- package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
- package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
- package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
- package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
- package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
- package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
- package/bin/lib/modules/rule/async-validator/util.js +0 -255
- package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
- package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
- package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
- package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
- package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
- package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
- package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
- package/bin/lib/modules/rule/index.js +0 -67
- package/bin/lib/modules/string/index.js +0 -121
- package/bin/lib/modules/string/words.js +0 -33
- package/bin/lib/modules/time/const.js +0 -11
- package/bin/lib/modules/time/dtime.js +0 -132
- package/bin/lib/modules/time/frame.js +0 -49
- package/bin/lib/modules/time/index.js +0 -84
- package/bin/lib/typings/index.js +0 -2
- package/bin/lib/util/function.js +0 -33
- package/bin/lib/util/includes.js +0 -96
- package/bin/lib/util/index.js +0 -26
- package/bin/lib/util/is.js +0 -148
- package/bin/lib/util/to.js +0 -47
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const lerp = (start, end, t) => {
|
|
4
|
-
// (1 - t) * p0.x + t * p1.x,
|
|
5
|
-
return start * (1 - t) + end * t;
|
|
6
|
-
};
|
|
7
|
-
const proportion = (start, end, current) => {
|
|
8
|
-
if (start === end)
|
|
9
|
-
return 0;
|
|
10
|
-
return (current - start) / (end - start);
|
|
11
|
-
};
|
|
12
|
-
const bezier1 = (p0, p1, t) => {
|
|
13
|
-
return {
|
|
14
|
-
x: lerp(p0.x, p1.x, t),
|
|
15
|
-
y: lerp(p0.y, p1.y, t),
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
const bezier2 = (p0, p1, p2, t) => {
|
|
19
|
-
const q0 = bezier1(p0, p1, t);
|
|
20
|
-
const q1 = bezier1(p1, p2, t);
|
|
21
|
-
return bezier1(q0, q1, t);
|
|
22
|
-
};
|
|
23
|
-
const bezier3 = (p0, p1, p2, p3, t) => {
|
|
24
|
-
const q0 = bezier2(p0, p1, p2, t);
|
|
25
|
-
const q1 = bezier2(p1, p2, p3, t);
|
|
26
|
-
return bezier1(q0, q1, t);
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* 贝塞尔曲线
|
|
30
|
-
* @param points
|
|
31
|
-
* @param t [0, 1]
|
|
32
|
-
* @returns
|
|
33
|
-
*/
|
|
34
|
-
const bezier = (points, t) => {
|
|
35
|
-
if (points.length === 1) {
|
|
36
|
-
return points[0]; // 递归终点
|
|
37
|
-
}
|
|
38
|
-
const nextPoints = [];
|
|
39
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
40
|
-
nextPoints.push({
|
|
41
|
-
x: (1 - t) * points[i].x + t * points[i + 1].x,
|
|
42
|
-
y: (1 - t) * points[i].y + t * points[i + 1].y,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return bezier(nextPoints, t);
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* 计算二项式系数 C(n, k)
|
|
49
|
-
* @param n 阶数
|
|
50
|
-
* @param k 选择的点数
|
|
51
|
-
* @returns 二项式系数
|
|
52
|
-
*/
|
|
53
|
-
const binomialCoefficient = (n, k) => {
|
|
54
|
-
if (k === 0 || k === n)
|
|
55
|
-
return 1;
|
|
56
|
-
let res = 1;
|
|
57
|
-
for (let i = 1; i <= k; i++) {
|
|
58
|
-
res = (res * (n - i + 1)) / i;
|
|
59
|
-
}
|
|
60
|
-
return res;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* 贝塞尔曲线
|
|
64
|
-
* @param points
|
|
65
|
-
* @param t [0, 1]
|
|
66
|
-
* @returns
|
|
67
|
-
*/
|
|
68
|
-
const bezierCurve = (points, t) => {
|
|
69
|
-
const n = points.length - 1;
|
|
70
|
-
let x = 0;
|
|
71
|
-
let y = 0;
|
|
72
|
-
for (let i = 0; i <= n; i++) {
|
|
73
|
-
const coefficient = binomialCoefficient(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i);
|
|
74
|
-
x += coefficient * points[i].x;
|
|
75
|
-
y += coefficient * points[i].y;
|
|
76
|
-
}
|
|
77
|
-
return { x, y };
|
|
78
|
-
};
|
|
79
|
-
const lerpAverage = (points, step, //
|
|
80
|
-
type = '') => {
|
|
81
|
-
if (points.length <= 0)
|
|
82
|
-
return 0;
|
|
83
|
-
if (points.length === 1)
|
|
84
|
-
return points[0].x;
|
|
85
|
-
if (points.length === 2)
|
|
86
|
-
return lerp(points[0].y, points[1].y, 0.5);
|
|
87
|
-
const values = [];
|
|
88
|
-
// 调整下排序
|
|
89
|
-
const _points = points.slice().sort((a, b) => a.x - b.x);
|
|
90
|
-
const size = _points.length;
|
|
91
|
-
const start = _points[0].x;
|
|
92
|
-
const end = _points[size - 1].x;
|
|
93
|
-
// 遍历每个插值点
|
|
94
|
-
for (let axis = start; axis <= end; axis += step) {
|
|
95
|
-
let value = 0;
|
|
96
|
-
// 找到 t 所在区间 [t1, t2]
|
|
97
|
-
for (let i = 0; i < size - 1; i++) {
|
|
98
|
-
const p1 = _points[i];
|
|
99
|
-
const p2 = _points[i + 1];
|
|
100
|
-
if (axis >= p1.x && axis <= p2.x) {
|
|
101
|
-
if (type === 'lerp') {
|
|
102
|
-
const t = proportion(p1.x, p2.x, axis);
|
|
103
|
-
value = bezier1(p1, p2, t).y;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// 取左侧值
|
|
107
|
-
value = p1.y;
|
|
108
|
-
}
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// 如果 t 超出范围,使用最后一个已知值
|
|
113
|
-
if (axis > _points[size - 1].x) {
|
|
114
|
-
value = _points[size - 1].y;
|
|
115
|
-
}
|
|
116
|
-
values.push(value);
|
|
117
|
-
}
|
|
118
|
-
const sum = values.reduce((acc, val) => acc + val, 0);
|
|
119
|
-
return sum / values.length;
|
|
120
|
-
};
|
|
121
|
-
exports.default = { bezier1, bezier2, bezier3, bezier, bezierCurve, lerp, lerpAverage, proportion };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const to_1 = require("../../../util/to");
|
|
4
|
-
const is_1 = require("../../../util/is");
|
|
5
|
-
const FUNC_ERROR_TEXT = 'Expected a function';
|
|
6
|
-
const nativeMax = Math.max;
|
|
7
|
-
const nativeMin = Math.min;
|
|
8
|
-
/**
|
|
9
|
-
* 防抖 一段时间内,规定时间间隔多次执行,回调触发一次
|
|
10
|
-
* @param func
|
|
11
|
-
* @param wait 默认 300
|
|
12
|
-
* @param options 参数:leading 开始执行, trailing结束执行
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
function debounce(func, wait = 300, options = {}) {
|
|
16
|
-
let lastArgs;
|
|
17
|
-
let lastThis;
|
|
18
|
-
let maxWait;
|
|
19
|
-
let result;
|
|
20
|
-
let timerId;
|
|
21
|
-
let lastCallTime;
|
|
22
|
-
let lastInvokeTime = 0;
|
|
23
|
-
let leading = false;
|
|
24
|
-
let maxing = false;
|
|
25
|
-
let trailing = true;
|
|
26
|
-
if (typeof func != 'function') {
|
|
27
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
28
|
-
}
|
|
29
|
-
wait = to_1.default.toNumber(wait) || 0;
|
|
30
|
-
if (is_1.default.isObject(options)) {
|
|
31
|
-
leading = !!options.leading;
|
|
32
|
-
maxing = 'maxWait' in options;
|
|
33
|
-
maxWait = maxing ? nativeMax(to_1.default.toNumber(options.maxWait) || 0, wait) : maxWait;
|
|
34
|
-
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
35
|
-
}
|
|
36
|
-
function invokeFunc(time) {
|
|
37
|
-
const args = lastArgs;
|
|
38
|
-
const thisArg = lastThis;
|
|
39
|
-
lastArgs = lastThis = undefined;
|
|
40
|
-
lastInvokeTime = time;
|
|
41
|
-
result = func.apply(thisArg, args);
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
function leadingEdge(time) {
|
|
45
|
-
// Reset any `maxWait` timer.
|
|
46
|
-
lastInvokeTime = time;
|
|
47
|
-
// Start the timer for the trailing edge.
|
|
48
|
-
timerId = setTimeout(timerExpired, wait);
|
|
49
|
-
// Invoke the leading edge.
|
|
50
|
-
return leading ? invokeFunc(time) : result;
|
|
51
|
-
}
|
|
52
|
-
function remainingWait(time) {
|
|
53
|
-
const timeSinceLastCall = time - lastCallTime;
|
|
54
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
55
|
-
const timeWaiting = wait - timeSinceLastCall;
|
|
56
|
-
return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
57
|
-
}
|
|
58
|
-
function shouldInvoke(time) {
|
|
59
|
-
const timeSinceLastCall = time - lastCallTime;
|
|
60
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
61
|
-
// Either this is the first call, activity has stopped and we're at the
|
|
62
|
-
// trailing edge, the system time has gone backwards and we're treating
|
|
63
|
-
// it as the trailing edge, or we've hit the `maxWait` limit.
|
|
64
|
-
return (lastCallTime === undefined ||
|
|
65
|
-
timeSinceLastCall >= wait ||
|
|
66
|
-
timeSinceLastCall < 0 ||
|
|
67
|
-
(maxing && timeSinceLastInvoke >= maxWait));
|
|
68
|
-
}
|
|
69
|
-
function timerExpired() {
|
|
70
|
-
const time = Date.now();
|
|
71
|
-
if (shouldInvoke(time)) {
|
|
72
|
-
return trailingEdge(time);
|
|
73
|
-
}
|
|
74
|
-
// Restart the timer.
|
|
75
|
-
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
function trailingEdge(time) {
|
|
79
|
-
timerId = undefined;
|
|
80
|
-
// Only invoke if we have `lastArgs` which means `func` has been
|
|
81
|
-
// debounced at least once.
|
|
82
|
-
if (trailing && lastArgs) {
|
|
83
|
-
return invokeFunc(time);
|
|
84
|
-
}
|
|
85
|
-
lastArgs = lastThis = undefined;
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
function cancel() {
|
|
89
|
-
if (timerId !== undefined) {
|
|
90
|
-
clearTimeout(timerId);
|
|
91
|
-
}
|
|
92
|
-
lastInvokeTime = 0;
|
|
93
|
-
lastArgs = lastCallTime = lastThis = timerId = undefined;
|
|
94
|
-
}
|
|
95
|
-
function flush() {
|
|
96
|
-
return timerId === undefined ? result : trailingEdge(Date.now());
|
|
97
|
-
}
|
|
98
|
-
function pending() {
|
|
99
|
-
return timerId !== undefined;
|
|
100
|
-
}
|
|
101
|
-
function debounced(...args) {
|
|
102
|
-
const time = Date.now();
|
|
103
|
-
const isInvoking = shouldInvoke(time);
|
|
104
|
-
lastArgs = args;
|
|
105
|
-
lastThis = this;
|
|
106
|
-
lastCallTime = time;
|
|
107
|
-
if (isInvoking) {
|
|
108
|
-
if (timerId === undefined) {
|
|
109
|
-
return leadingEdge(lastCallTime);
|
|
110
|
-
}
|
|
111
|
-
if (maxing) {
|
|
112
|
-
// Handle invocations in a tight loop.
|
|
113
|
-
timerId = setTimeout(timerExpired, wait);
|
|
114
|
-
return invokeFunc(lastCallTime);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (timerId === undefined) {
|
|
118
|
-
timerId = setTimeout(timerExpired, wait);
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
debounced.cancel = cancel;
|
|
123
|
-
debounced.flush = flush;
|
|
124
|
-
debounced.pending = pending;
|
|
125
|
-
return debounced;
|
|
126
|
-
}
|
|
127
|
-
exports.default = debounce;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function mutex(func) {
|
|
4
|
-
var lastThis = null;
|
|
5
|
-
async function mutexed(...args) {
|
|
6
|
-
lastThis = this || lastThis || {};
|
|
7
|
-
if (lastThis.__ddMutex)
|
|
8
|
-
return false;
|
|
9
|
-
lastThis.__ddMutex = true;
|
|
10
|
-
try {
|
|
11
|
-
func && (await Promise.resolve(func.apply(this, args)));
|
|
12
|
-
}
|
|
13
|
-
catch (err) {
|
|
14
|
-
console.log(err);
|
|
15
|
-
}
|
|
16
|
-
finally {
|
|
17
|
-
lastThis.__ddMutex = false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return mutexed;
|
|
21
|
-
}
|
|
22
|
-
exports.default = mutex;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("../base");
|
|
4
|
-
const safeTask_1 = require("./safeTask");
|
|
5
|
-
class DPipeline {
|
|
6
|
-
__list = [];
|
|
7
|
-
__count = 0;
|
|
8
|
-
__max = 1;
|
|
9
|
-
constructor(max = 1) {
|
|
10
|
-
this.__count = 0;
|
|
11
|
-
this.__max = max > 0 ? max : 1;
|
|
12
|
-
this.clear();
|
|
13
|
-
}
|
|
14
|
-
push(func, callback) {
|
|
15
|
-
const _sTask = new safeTask_1.default(func, callback);
|
|
16
|
-
this.__list.push(_sTask);
|
|
17
|
-
this._step();
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
clear() {
|
|
21
|
-
this.__list = [];
|
|
22
|
-
this.__count = 0;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
_step() {
|
|
26
|
-
if (this.__list.length <= 0)
|
|
27
|
-
return;
|
|
28
|
-
if (this.__count >= this.__max)
|
|
29
|
-
return;
|
|
30
|
-
const _sTask = this.__list.shift();
|
|
31
|
-
if (_sTask) {
|
|
32
|
-
this.__count += 1;
|
|
33
|
-
_sTask?.run().finally(() => {
|
|
34
|
-
try {
|
|
35
|
-
if (this.__count > 0) {
|
|
36
|
-
this.__count -= 1;
|
|
37
|
-
}
|
|
38
|
-
this._step();
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
console.error('[ddan] pipepine step finally', err);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
this._step();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async whenAll() {
|
|
50
|
-
do {
|
|
51
|
-
if (this.__count <= 0)
|
|
52
|
-
break;
|
|
53
|
-
await base_1.default.delay(100);
|
|
54
|
-
this._step();
|
|
55
|
-
} while (true);
|
|
56
|
-
return this.clear();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.default = DPipeline;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("../base");
|
|
4
|
-
async function polling(params = {}) {
|
|
5
|
-
const { func, interval = 100, times = 1000 } = params;
|
|
6
|
-
let _times = times;
|
|
7
|
-
const _interval = interval < 1 ? 100 : interval;
|
|
8
|
-
do {
|
|
9
|
-
if (!func)
|
|
10
|
-
break;
|
|
11
|
-
const [err, res] = await base_1.default.to(Promise.resolve(func()));
|
|
12
|
-
if (err || res === false)
|
|
13
|
-
break;
|
|
14
|
-
if (_times > 0) {
|
|
15
|
-
_times--;
|
|
16
|
-
}
|
|
17
|
-
(_times !== 0) && await base_1.default.delay(_interval);
|
|
18
|
-
} while (times === -1 || _times > 0);
|
|
19
|
-
}
|
|
20
|
-
exports.default = polling;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("../base");
|
|
4
|
-
class DSafeTask {
|
|
5
|
-
_func;
|
|
6
|
-
_callback;
|
|
7
|
-
constructor(task, callback) {
|
|
8
|
-
this._func = task;
|
|
9
|
-
this._callback = callback;
|
|
10
|
-
}
|
|
11
|
-
async run() {
|
|
12
|
-
return base_1.default.safeRun(this._func).then((res) => {
|
|
13
|
-
try {
|
|
14
|
-
this._callback && this._callback(res);
|
|
15
|
-
}
|
|
16
|
-
catch (err) {
|
|
17
|
-
console.log(`[ddan] task`, err);
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
return res;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.default = DSafeTask;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const is_1 = require("../../../util/is");
|
|
4
|
-
const debounce_1 = require("./debounce");
|
|
5
|
-
/** Error message constants. */
|
|
6
|
-
const FUNC_ERROR_TEXT = 'Expected a function';
|
|
7
|
-
/**
|
|
8
|
-
* 节流 每个间隔内,触发一次
|
|
9
|
-
* @param func
|
|
10
|
-
* @param wait 默认 300
|
|
11
|
-
* @param options 参数:leading 开始执行, trailing结束执行
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
function throttle(func, wait = 300, options = {}) {
|
|
15
|
-
let leading = true;
|
|
16
|
-
let trailing = true;
|
|
17
|
-
if (typeof func != 'function') {
|
|
18
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
19
|
-
}
|
|
20
|
-
if (is_1.default.isObject(options)) {
|
|
21
|
-
leading = options.leading ? !!options.leading : leading;
|
|
22
|
-
trailing = options.trailing ? !!options.trailing : trailing;
|
|
23
|
-
}
|
|
24
|
-
return (0, debounce_1.default)(func, wait, {
|
|
25
|
-
leading: leading,
|
|
26
|
-
maxWait: wait,
|
|
27
|
-
trailing: trailing
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
exports.default = throttle;
|
package/bin/lib/modules/html.js
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// import math from './math'
|
|
4
|
-
const qs_1 = require("./qs");
|
|
5
|
-
// interface IDowloadCallback {
|
|
6
|
-
// success?: () => void
|
|
7
|
-
// progress?: (percentage: number, current: number, total: number) => void
|
|
8
|
-
// fail?: (error: any) => void
|
|
9
|
-
// }
|
|
10
|
-
const dataURLtoFile = (dataurl, filename) => {
|
|
11
|
-
// const _dataurl = decodeURIComponent(dataurl);
|
|
12
|
-
let arr = dataurl.split(',');
|
|
13
|
-
let mime = arr[0].match(/:(.*?);/)[1];
|
|
14
|
-
let bstr = window.atob(arr[1]);
|
|
15
|
-
let n = bstr.length;
|
|
16
|
-
let u8arr = new Uint8Array(n);
|
|
17
|
-
while (n--) {
|
|
18
|
-
u8arr[n] = bstr.charCodeAt(n);
|
|
19
|
-
}
|
|
20
|
-
return new File([u8arr], filename, { type: mime });
|
|
21
|
-
};
|
|
22
|
-
const dataURLtoBlob = (dataurl) => {
|
|
23
|
-
let arr = dataurl.split(',');
|
|
24
|
-
let mime = arr[0].match(/:(.*?);/)[1];
|
|
25
|
-
let bstr = window.atob(arr[1]);
|
|
26
|
-
let n = bstr.length;
|
|
27
|
-
let u8arr = new Uint8Array(n);
|
|
28
|
-
while (n--) {
|
|
29
|
-
u8arr[n] = bstr.charCodeAt(n);
|
|
30
|
-
}
|
|
31
|
-
return new Blob([u8arr], { type: mime });
|
|
32
|
-
};
|
|
33
|
-
const blobToFile = (blob, fileName) => {
|
|
34
|
-
blob.lastModifiedDate = new Date();
|
|
35
|
-
blob.name = fileName;
|
|
36
|
-
return blob;
|
|
37
|
-
};
|
|
38
|
-
const readAsDataURL = (file, cb) => {
|
|
39
|
-
var reader = new FileReader();
|
|
40
|
-
reader.readAsDataURL(file);
|
|
41
|
-
// 监听文件读取结束后事件
|
|
42
|
-
reader.onloadend = function (e) {
|
|
43
|
-
cb && cb(e.target?.result);
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
const _downloadUrl = (url, filename) => {
|
|
47
|
-
try {
|
|
48
|
-
const ele = document.createElement('a');
|
|
49
|
-
ele.style.display = 'none';
|
|
50
|
-
ele.href = url;
|
|
51
|
-
ele.download = filename;
|
|
52
|
-
document.body.appendChild(ele);
|
|
53
|
-
ele.click();
|
|
54
|
-
document.body.removeChild(ele);
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
console.error(`[ddan] _downloadUrl ${url}`, err);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const downloadUrl = (url, filename = '', checkSomeOrigin = false
|
|
61
|
-
// opts?: {
|
|
62
|
-
// success?: () => void
|
|
63
|
-
// progress?: (percentage: number, current: number, total: number) => void
|
|
64
|
-
// fail?: (error: any) => void
|
|
65
|
-
// }
|
|
66
|
-
) => {
|
|
67
|
-
try {
|
|
68
|
-
if (!url)
|
|
69
|
-
return;
|
|
70
|
-
const map = qs_1.default.parseUrl(url);
|
|
71
|
-
const _filename = filename || map.name;
|
|
72
|
-
const sameOrigin = !filename || !checkSomeOrigin || !map.origin || map.origin === window.location.origin;
|
|
73
|
-
if (sameOrigin) {
|
|
74
|
-
_downloadUrl(url, _filename);
|
|
75
|
-
// opts?.success && opts?.success()
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
const params = map.params;
|
|
79
|
-
params.t = Date.now();
|
|
80
|
-
const _url = `${map.url}?${qs_1.default.stringify(params, { uri: false })}`;
|
|
81
|
-
const xhr = new XMLHttpRequest();
|
|
82
|
-
xhr.open('GET', _url, true);
|
|
83
|
-
xhr.responseType = 'blob';
|
|
84
|
-
// xhr.onprogress = function (ev) {
|
|
85
|
-
// if (ev.lengthComputable && opts?.progress) {
|
|
86
|
-
// const percentage = math.float((100.0 * ev.loaded) / ev.total, { digits: 2 })
|
|
87
|
-
// opts?.progress(percentage, ev.loaded, ev.total) // 调用回调函数更新进度
|
|
88
|
-
// }
|
|
89
|
-
// }
|
|
90
|
-
xhr.onload = function () {
|
|
91
|
-
downloadFile(xhr.response, _filename);
|
|
92
|
-
// opts?.success && opts?.success()
|
|
93
|
-
};
|
|
94
|
-
xhr.onerror = function (e) {
|
|
95
|
-
console.error(`[ddan] downloadUrl ${url}`, e);
|
|
96
|
-
// opts?.fail && opts?.fail(e)
|
|
97
|
-
};
|
|
98
|
-
xhr.send();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
console.error(`[ddan] downloadUrl ${url}`, err);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
const getBlob = (url) => {
|
|
106
|
-
return new Promise((resolve) => {
|
|
107
|
-
const xhr = new XMLHttpRequest();
|
|
108
|
-
xhr.open('GET', url, true);
|
|
109
|
-
xhr.responseType = 'blob';
|
|
110
|
-
xhr.onload = () => {
|
|
111
|
-
if (xhr.status === 200) {
|
|
112
|
-
resolve(xhr.response);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
xhr.send();
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
const downloadFile = (data, filename = '') => {
|
|
119
|
-
try {
|
|
120
|
-
if (!data)
|
|
121
|
-
return;
|
|
122
|
-
const href = URL?.createObjectURL(data);
|
|
123
|
-
if (!href)
|
|
124
|
-
return;
|
|
125
|
-
downloadUrl(href, filename);
|
|
126
|
-
URL?.revokeObjectURL(href);
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
console.error(`[ddan] downloadFile`, err);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
const download = (urlOrFile, filename = '') => {
|
|
133
|
-
if (!urlOrFile)
|
|
134
|
-
return;
|
|
135
|
-
if (typeof urlOrFile === 'string') {
|
|
136
|
-
downloadUrl(urlOrFile, filename);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
downloadFile(urlOrFile, filename);
|
|
140
|
-
};
|
|
141
|
-
const downloadImage = (url) => {
|
|
142
|
-
try {
|
|
143
|
-
if (!url)
|
|
144
|
-
return;
|
|
145
|
-
const name = url.match(/\/(\w+.\w+)$/)[1];
|
|
146
|
-
//下载群二维码
|
|
147
|
-
const img = new Image();
|
|
148
|
-
img.onload = () => {
|
|
149
|
-
let canvas = document.createElement('canvas');
|
|
150
|
-
canvas.width = img.width;
|
|
151
|
-
canvas.height = img.height;
|
|
152
|
-
let context = canvas.getContext('2d');
|
|
153
|
-
context && context.drawImage(img, 0, 0, img.width, img.height);
|
|
154
|
-
let base64 = canvas.toDataURL(); //得到图片的base64编码数据
|
|
155
|
-
downloadUrl(base64, name);
|
|
156
|
-
};
|
|
157
|
-
img.src = url; // 将canvas对象转换为图片的data url
|
|
158
|
-
img.setAttribute('crossOrigin', 'Anonymous');
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
console.error(`[ddan] downloadImage`, err);
|
|
162
|
-
}
|
|
163
|
-
return Promise.resolve();
|
|
164
|
-
};
|
|
165
|
-
const watermark = (text, { width = 400, height = 300, angle = 0, fillStyle = 'rgba(0, 0, 0, 0.2)', font = '16px Arial', textAlign = 'left', textBaseline = 'middle', } = {}) => {
|
|
166
|
-
try {
|
|
167
|
-
if (!text)
|
|
168
|
-
return '';
|
|
169
|
-
const canvas = document.createElement('canvas');
|
|
170
|
-
canvas.width = width;
|
|
171
|
-
canvas.height = height;
|
|
172
|
-
const ctx = canvas.getContext('2d');
|
|
173
|
-
if (!ctx)
|
|
174
|
-
return '';
|
|
175
|
-
angle && ctx.rotate((angle * Math.PI) / 180);
|
|
176
|
-
fillStyle && (ctx.fillStyle = fillStyle);
|
|
177
|
-
font && (ctx.font = font);
|
|
178
|
-
textAlign && (ctx.textAlign = textAlign);
|
|
179
|
-
textBaseline && (ctx.textBaseline = textBaseline);
|
|
180
|
-
ctx.fillText(text, canvas.width / 10, canvas.height / 2);
|
|
181
|
-
return `url(${canvas.toDataURL()})`; // "image/png" 默认
|
|
182
|
-
}
|
|
183
|
-
catch (err) {
|
|
184
|
-
console.error(`[ddan] watermark`, err);
|
|
185
|
-
return '';
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
const copyText = (text, legacy = false) => {
|
|
189
|
-
return new Promise((resolve) => {
|
|
190
|
-
if (legacy || !navigator.clipboard) {
|
|
191
|
-
resolve(legacyCopy(text));
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
queryPermission('clipboard-write')
|
|
195
|
-
.then((state) => {
|
|
196
|
-
if (isAllowed(state, false)) {
|
|
197
|
-
navigator.clipboard
|
|
198
|
-
.writeText(text)
|
|
199
|
-
.then(() => resolve(true))
|
|
200
|
-
.catch(() => resolve(legacyCopy(text)));
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
resolve(legacyCopy(text));
|
|
204
|
-
}
|
|
205
|
-
})
|
|
206
|
-
.catch(() => {
|
|
207
|
-
resolve(legacyCopy(text));
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
};
|
|
211
|
-
const legacyCopy = (text) => {
|
|
212
|
-
try {
|
|
213
|
-
const _textarea = document.createElement('textarea');
|
|
214
|
-
document.body.appendChild(_textarea);
|
|
215
|
-
// 隐藏此输入框
|
|
216
|
-
_textarea.style.position = 'fixed';
|
|
217
|
-
_textarea.style.clip = 'rect(0 0 0 0)';
|
|
218
|
-
_textarea.style.top = '10px';
|
|
219
|
-
_textarea.style.opacity = '0';
|
|
220
|
-
// 赋值
|
|
221
|
-
_textarea.value = text ?? '';
|
|
222
|
-
// 选中
|
|
223
|
-
_textarea.select();
|
|
224
|
-
// 复制
|
|
225
|
-
const result = document.execCommand('copy');
|
|
226
|
-
// 移除输入框
|
|
227
|
-
document.body.removeChild(_textarea);
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
catch (err) {
|
|
231
|
-
console.error(`[ddan] copyText`, err);
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
const queryPermission = (name, def = 'denied') => {
|
|
236
|
-
return new Promise((resolve) => {
|
|
237
|
-
const permissions = navigator?.permissions;
|
|
238
|
-
if (!permissions || !permissions.query)
|
|
239
|
-
return resolve(def);
|
|
240
|
-
const desc = { name };
|
|
241
|
-
permissions
|
|
242
|
-
.query(desc)
|
|
243
|
-
.then((res) => resolve(res.state))
|
|
244
|
-
.catch(() => resolve(def));
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
const isAllowed = (status, prompt = true) => {
|
|
248
|
-
if (prompt && status === 'prompt')
|
|
249
|
-
return true;
|
|
250
|
-
return status === 'granted';
|
|
251
|
-
};
|
|
252
|
-
const takeHtmlLinks = (htmlContent) => {
|
|
253
|
-
if (!htmlContent)
|
|
254
|
-
return [];
|
|
255
|
-
const regexs = [
|
|
256
|
-
/<script[^>]+src="([^"]+)"/g,
|
|
257
|
-
/<link[^>]+rel="stylesheet"[^>]+href="([^"]+)"/g,
|
|
258
|
-
/<link[^>]+rel="icon"[^>]+href="([^"]+)"/g,
|
|
259
|
-
];
|
|
260
|
-
const results = [];
|
|
261
|
-
regexs.forEach((e) => {
|
|
262
|
-
const r = takeHtml(htmlContent, e);
|
|
263
|
-
results.push(r);
|
|
264
|
-
});
|
|
265
|
-
return [].concat(...results);
|
|
266
|
-
};
|
|
267
|
-
const takeHtml = (htmlContent, regex) => {
|
|
268
|
-
if (!htmlContent || !regex)
|
|
269
|
-
return [];
|
|
270
|
-
const results = [];
|
|
271
|
-
let match;
|
|
272
|
-
while ((match = regex.exec(htmlContent)) !== null) {
|
|
273
|
-
results.push(match[1]);
|
|
274
|
-
}
|
|
275
|
-
return results;
|
|
276
|
-
};
|
|
277
|
-
exports.default = {
|
|
278
|
-
dataURLtoFile,
|
|
279
|
-
dataURLtoBlob,
|
|
280
|
-
blobToFile,
|
|
281
|
-
readAsDataURL,
|
|
282
|
-
downloadUrl,
|
|
283
|
-
download,
|
|
284
|
-
downloadFile,
|
|
285
|
-
downloadImage,
|
|
286
|
-
watermark,
|
|
287
|
-
copyText,
|
|
288
|
-
queryPermission,
|
|
289
|
-
isAllowed,
|
|
290
|
-
legacyCopy,
|
|
291
|
-
takeHtmlLinks,
|
|
292
|
-
takeHtml,
|
|
293
|
-
};
|