ddan-js 2.8.10 → 2.8.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lerpAverage = void 0;
4
+ const lerp = (start, end, t) => {
5
+ // (1 - t) * p0.x + t * p1.x,
6
+ return start * (1 - t) + end * t;
7
+ };
8
+ const bezier1 = (p0, p1, t) => {
9
+ return {
10
+ x: lerp(p0.x, p1.x, t),
11
+ y: lerp(p0.y, p1.y, t),
12
+ };
13
+ };
14
+ const bezier2 = (p0, p1, p2, t) => {
15
+ const q0 = bezier1(p0, p1, t);
16
+ const q1 = bezier1(p1, p2, t);
17
+ return bezier1(q0, q1, t);
18
+ };
19
+ const bezier3 = (p0, p1, p2, p3, t) => {
20
+ const q0 = bezier2(p0, p1, p2, t);
21
+ const q1 = bezier2(p1, p2, p3, t);
22
+ return bezier1(q0, q1, t);
23
+ };
24
+ /**
25
+ * 贝塞尔曲线
26
+ * @param points
27
+ * @param t [0, 1]
28
+ * @returns
29
+ */
30
+ const bezier = (points, t) => {
31
+ if (points.length === 1) {
32
+ return points[0]; // 递归终点
33
+ }
34
+ const nextPoints = [];
35
+ for (let i = 0; i < points.length - 1; i++) {
36
+ nextPoints.push({
37
+ x: (1 - t) * points[i].x + t * points[i + 1].x,
38
+ y: (1 - t) * points[i].y + t * points[i + 1].y,
39
+ });
40
+ }
41
+ return bezier(nextPoints, t);
42
+ };
43
+ /**
44
+ * 计算二项式系数 C(n, k)
45
+ * @param n 阶数
46
+ * @param k 选择的点数
47
+ * @returns 二项式系数
48
+ */
49
+ const binomialCoefficient = (n, k) => {
50
+ if (k === 0 || k === n)
51
+ return 1;
52
+ let res = 1;
53
+ for (let i = 1; i <= k; i++) {
54
+ res = (res * (n - i + 1)) / i;
55
+ }
56
+ return res;
57
+ };
58
+ /**
59
+ * 贝塞尔曲线
60
+ * @param points
61
+ * @param t [0, 1]
62
+ * @returns
63
+ */
64
+ const bezierCurve = (points, t) => {
65
+ const n = points.length - 1;
66
+ let x = 0;
67
+ let y = 0;
68
+ for (let i = 0; i <= n; i++) {
69
+ const coefficient = binomialCoefficient(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i);
70
+ x += coefficient * points[i].x;
71
+ y += coefficient * points[i].y;
72
+ }
73
+ return { x, y };
74
+ };
75
+ const lerpAverage = (points, step //
76
+ ) => {
77
+ if (points.length <= 0)
78
+ return 0;
79
+ if (points.length === 1)
80
+ return points[0].x;
81
+ if (points.length === 2)
82
+ return lerp(points[0].y, points[1].y, 0.5);
83
+ const values = [];
84
+ // 调整下排序
85
+ const _points = points.slice().sort((a, b) => a.x - b.x);
86
+ const start = _points[0].x;
87
+ const end = _points[_points.length - 1].x;
88
+ // 遍历每个插值点
89
+ for (let axis = start; axis <= end; axis += step) {
90
+ let value = 0;
91
+ // 找到 t 所在区间 [t1, t2]
92
+ for (let i = 0; i < _points.length - 1; i++) {
93
+ const p1 = _points[i];
94
+ const p2 = _points[i + 1];
95
+ if (axis >= p1.x && axis <= p2.x) {
96
+ if (p1.x === p2.x) {
97
+ value = p1.y;
98
+ }
99
+ else {
100
+ const t = (axis - p1.x) / (p2.x - p1.x);
101
+ value = bezier1(p1, p2, t).y;
102
+ }
103
+ // 线性插值公式
104
+ break;
105
+ }
106
+ }
107
+ // 如果 t 超出范围,使用最后一个已知值
108
+ if (axis > _points[_points.length - 1].x) {
109
+ value = _points[_points.length - 1].y;
110
+ }
111
+ values.push(value);
112
+ }
113
+ const sum = values.reduce((acc, val) => acc + val, 0) / values.length;
114
+ return sum / values.length;
115
+ };
116
+ exports.lerpAverage = lerpAverage;
117
+ exports.default = { bezier1, bezier2, bezier3, bezier, bezierCurve, lerp, lerpAverage: exports.lerpAverage };
@@ -168,7 +168,7 @@ class Socks5 {
168
168
  const destination = await this.parseClientRequest(clientSocket);
169
169
  const addr = destination.addr;
170
170
  addrport = `${addr}:${destination.port}`;
171
- this.__debug && this.__logger?.info(`[socks5] handle connection`, addrport);
171
+ this.__debug && this.__logger?.info(`[socks5] connection`, addrport);
172
172
  const proxyConfig = this.findProxyConfig(addr);
173
173
  if (proxyConfig) {
174
174
  // 走上游代理
@@ -334,6 +334,12 @@ declare const dHook: {
334
334
  pipe: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/pipeline").default;
335
335
  pipeline: (max?: number) => import("./modules/hook/modules/pipeline").default;
336
336
  safeTask: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/safeTask").default;
337
+ bezier1: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
338
+ bezier2: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, p2: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
339
+ bezier3: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, p2: import("./typings").Ddan.IPoint, p3: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
340
+ bezier: (points: import("./typings").Ddan.IPoint[], t: number) => import("./typings").Ddan.IPoint;
341
+ bezierCurve: (points: import("./typings").Ddan.IPoint[], t: number) => import("./typings").Ddan.IPoint;
342
+ lerpAverage: (points: import("./typings").Ddan.IPoint[], step: number) => number;
337
343
  logString: (data: any) => string;
338
344
  logParse: (logStr: string) => string;
339
345
  logRString: (data: any) => Promise<string>;
@@ -685,6 +691,13 @@ declare const _default: {
685
691
  pipe: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/pipeline").default;
686
692
  pipeline: (max?: number) => import("./modules/hook/modules/pipeline").default;
687
693
  safeTask: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/safeTask").default;
694
+ bezier1: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
695
+ bezier2: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, p2: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
696
+ bezier3: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, p2: import("./typings").Ddan.IPoint, p3: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
697
+ bezier: (points: import("./typings").Ddan.IPoint[], t: number) => import("./typings").Ddan.IPoint;
698
+ bezierCurve: (points: import("./typings").Ddan.IPoint[], t: number) => import("./typings").Ddan.IPoint;
699
+ lerp: (start: number, end: number, t: number) => number;
700
+ lerpAverage: (points: import("./typings").Ddan.IPoint[], step: number) => number;
688
701
  logString: (data: any) => string;
689
702
  logParse: (logStr: string) => string;
690
703
  logRString: (data: any) => Promise<string>;
@@ -334,6 +334,12 @@ declare const dHook: {
334
334
  pipe: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/pipeline").default;
335
335
  pipeline: (max?: number) => import("./modules/hook/modules/pipeline").default;
336
336
  safeTask: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/safeTask").default;
337
+ bezier1: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
338
+ bezier2: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, p2: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
339
+ bezier3: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, p2: import("./typings").Ddan.IPoint, p3: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
340
+ bezier: (points: import("./typings").Ddan.IPoint[], t: number) => import("./typings").Ddan.IPoint;
341
+ bezierCurve: (points: import("./typings").Ddan.IPoint[], t: number) => import("./typings").Ddan.IPoint;
342
+ lerpAverage: (points: import("./typings").Ddan.IPoint[], step: number) => number;
337
343
  logString: (data: any) => string;
338
344
  logParse: (logStr: string) => string;
339
345
  logRString: (data: any) => Promise<string>;
@@ -721,6 +727,13 @@ declare const _default: {
721
727
  pipe: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/pipeline").default;
722
728
  pipeline: (max?: number) => import("./modules/hook/modules/pipeline").default;
723
729
  safeTask: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/safeTask").default;
730
+ bezier1: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
731
+ bezier2: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, p2: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
732
+ bezier3: (p0: import("./typings").Ddan.IPoint, p1: import("./typings").Ddan.IPoint, p2: import("./typings").Ddan.IPoint, p3: import("./typings").Ddan.IPoint, t: number) => import("./typings").Ddan.IPoint;
733
+ bezier: (points: import("./typings").Ddan.IPoint[], t: number) => import("./typings").Ddan.IPoint;
734
+ bezierCurve: (points: import("./typings").Ddan.IPoint[], t: number) => import("./typings").Ddan.IPoint;
735
+ lerp: (start: number, end: number, t: number) => number;
736
+ lerpAverage: (points: import("./typings").Ddan.IPoint[], step: number) => number;
724
737
  logString: (data: any) => string;
725
738
  logParse: (logStr: string) => string;
726
739
  logRString: (data: any) => Promise<string>;
@@ -25,6 +25,13 @@ declare const _default: {
25
25
  pipe: (func: Ddan.Function, callback?: ((result: Ddan.SafeResult<any>) => void) | undefined) => DPipeline;
26
26
  pipeline: (max?: number) => DPipeline;
27
27
  safeTask: (func: Ddan.Function, callback?: ((result: Ddan.SafeResult<any>) => void) | undefined) => DSafeTask;
28
+ bezier1: (p0: Ddan.IPoint, p1: Ddan.IPoint, t: number) => Ddan.IPoint;
29
+ bezier2: (p0: Ddan.IPoint, p1: Ddan.IPoint, p2: Ddan.IPoint, t: number) => Ddan.IPoint;
30
+ bezier3: (p0: Ddan.IPoint, p1: Ddan.IPoint, p2: Ddan.IPoint, p3: Ddan.IPoint, t: number) => Ddan.IPoint;
31
+ bezier: (points: Ddan.IPoint[], t: number) => Ddan.IPoint;
32
+ bezierCurve: (points: Ddan.IPoint[], t: number) => Ddan.IPoint;
33
+ lerp: (start: number, end: number, t: number) => number;
34
+ lerpAverage: (points: Ddan.IPoint[], step: number) => number;
28
35
  logString: (data: any) => string;
29
36
  logParse: (logStr: string) => string;
30
37
  logRString: (data: any) => Promise<string>;
@@ -0,0 +1,12 @@
1
+ import { Ddan } from '../../../typings';
2
+ export declare const lerpAverage: (points: Ddan.IPoint[], step: number) => number;
3
+ declare const _default: {
4
+ bezier1: (p0: Ddan.IPoint, p1: Ddan.IPoint, t: number) => Ddan.IPoint;
5
+ bezier2: (p0: Ddan.IPoint, p1: Ddan.IPoint, p2: Ddan.IPoint, t: number) => Ddan.IPoint;
6
+ bezier3: (p0: Ddan.IPoint, p1: Ddan.IPoint, p2: Ddan.IPoint, p3: Ddan.IPoint, t: number) => Ddan.IPoint;
7
+ bezier: (points: Ddan.IPoint[], t: number) => Ddan.IPoint;
8
+ bezierCurve: (points: Ddan.IPoint[], t: number) => Ddan.IPoint;
9
+ lerp: (start: number, end: number, t: number) => number;
10
+ lerpAverage: (points: Ddan.IPoint[], step: number) => number;
11
+ };
12
+ export default _default;
@@ -4,6 +4,10 @@ export declare namespace Ddan {
4
4
  key: string;
5
5
  value: T;
6
6
  }
7
+ interface IPoint {
8
+ x: number;
9
+ y: number;
10
+ }
7
11
  type KeyValue<T = any> = Required<IKeyValuePart<T>>;
8
12
  type Function = (...args: any[]) => void;
9
13
  type PFunction<T = any> = Promise<T> | Function;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.8.10",
3
+ "version": "2.8.12",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",