@kwiz/fluentui 1.0.40 → 1.0.41
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/controls/ColorPickerDialog.d.ts +13 -0
- package/dist/controls/ColorPickerDialog.js +34 -0
- package/dist/controls/ColorPickerDialog.js.map +1 -0
- package/dist/controls/canvas/CustomEventTargetBase.d.ts +7 -0
- package/dist/controls/canvas/CustomEventTargetBase.js +22 -0
- package/dist/controls/canvas/CustomEventTargetBase.js.map +1 -0
- package/dist/controls/canvas/DrawPad.d.ts +15 -0
- package/dist/controls/canvas/DrawPad.js +151 -0
- package/dist/controls/canvas/DrawPad.js.map +1 -0
- package/dist/controls/canvas/DrawPadManager.d.ts +84 -0
- package/dist/controls/canvas/DrawPadManager.js +478 -0
- package/dist/controls/canvas/DrawPadManager.js.map +1 -0
- package/dist/controls/canvas/bezier.d.ts +17 -0
- package/dist/controls/canvas/bezier.js +65 -0
- package/dist/controls/canvas/bezier.js.map +1 -0
- package/dist/controls/canvas/point.d.ts +16 -0
- package/dist/controls/canvas/point.js +26 -0
- package/dist/controls/canvas/point.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/controls/ColorPickerDialog.tsx +76 -0
- package/src/controls/canvas/CustomEventTargetBase.ts +33 -0
- package/src/controls/canvas/DrawPad.tsx +195 -0
- package/src/controls/canvas/DrawPadManager.ts +668 -0
- package/src/controls/canvas/bezier.ts +110 -0
- package/src/controls/canvas/point.ts +45 -0
- package/src/index.ts +2 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
import { BasicPoint, Point } from './point';
|
2
|
+
|
3
|
+
export class Bezier {
|
4
|
+
public static fromPoints(
|
5
|
+
points: Point[],
|
6
|
+
widths: { start: number; end: number; },
|
7
|
+
): Bezier {
|
8
|
+
const c2 = this.calculateControlPoints(points[0], points[1], points[2]).c2;
|
9
|
+
const c3 = this.calculateControlPoints(points[1], points[2], points[3]).c1;
|
10
|
+
|
11
|
+
return new Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
|
12
|
+
}
|
13
|
+
|
14
|
+
private static calculateControlPoints(
|
15
|
+
s1: BasicPoint,
|
16
|
+
s2: BasicPoint,
|
17
|
+
s3: BasicPoint,
|
18
|
+
): {
|
19
|
+
c1: BasicPoint;
|
20
|
+
c2: BasicPoint;
|
21
|
+
} {
|
22
|
+
const dx1 = s1.x - s2.x;
|
23
|
+
const dy1 = s1.y - s2.y;
|
24
|
+
const dx2 = s2.x - s3.x;
|
25
|
+
const dy2 = s2.y - s3.y;
|
26
|
+
|
27
|
+
const m1 = { x: (s1.x + s2.x) / 2.0, y: (s1.y + s2.y) / 2.0 };
|
28
|
+
const m2 = { x: (s2.x + s3.x) / 2.0, y: (s2.y + s3.y) / 2.0 };
|
29
|
+
|
30
|
+
const l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
|
31
|
+
const l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
|
32
|
+
|
33
|
+
const dxm = m1.x - m2.x;
|
34
|
+
const dym = m1.y - m2.y;
|
35
|
+
|
36
|
+
const k = (l1 + l2) === 0 ? l2 : l2 / (l1 + l2);
|
37
|
+
|
38
|
+
const cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
|
39
|
+
|
40
|
+
const tx = s2.x - cm.x;
|
41
|
+
const ty = s2.y - cm.y;
|
42
|
+
|
43
|
+
return {
|
44
|
+
c1: new Point(m1.x + tx, m1.y + ty),
|
45
|
+
c2: new Point(m2.x + tx, m2.y + ty),
|
46
|
+
};
|
47
|
+
}
|
48
|
+
|
49
|
+
public constructor(
|
50
|
+
public startPoint: Point,
|
51
|
+
public control2: BasicPoint,
|
52
|
+
public control1: BasicPoint,
|
53
|
+
public endPoint: Point,
|
54
|
+
public startWidth: number,
|
55
|
+
public endWidth: number,
|
56
|
+
) { }
|
57
|
+
|
58
|
+
// Returns approximated length. Code taken from https://www.lemoda.net/maths/bezier-length/index.html.
|
59
|
+
public length(): number {
|
60
|
+
const steps = 10;
|
61
|
+
let length = 0;
|
62
|
+
let px;
|
63
|
+
let py;
|
64
|
+
|
65
|
+
for (let i = 0; i <= steps; i += 1) {
|
66
|
+
const t = i / steps;
|
67
|
+
const cx = this.point(
|
68
|
+
t,
|
69
|
+
this.startPoint.x,
|
70
|
+
this.control1.x,
|
71
|
+
this.control2.x,
|
72
|
+
this.endPoint.x,
|
73
|
+
);
|
74
|
+
const cy = this.point(
|
75
|
+
t,
|
76
|
+
this.startPoint.y,
|
77
|
+
this.control1.y,
|
78
|
+
this.control2.y,
|
79
|
+
this.endPoint.y,
|
80
|
+
);
|
81
|
+
|
82
|
+
if (i > 0) {
|
83
|
+
const xdiff = cx - (px as number);
|
84
|
+
const ydiff = cy - (py as number);
|
85
|
+
|
86
|
+
length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
|
87
|
+
}
|
88
|
+
|
89
|
+
px = cx;
|
90
|
+
py = cy;
|
91
|
+
}
|
92
|
+
|
93
|
+
return length;
|
94
|
+
}
|
95
|
+
|
96
|
+
// Calculate parametric value of x or y given t and the four point coordinates of a cubic bezier curve.
|
97
|
+
private point(
|
98
|
+
t: number,
|
99
|
+
start: number,
|
100
|
+
c1: number,
|
101
|
+
c2: number,
|
102
|
+
end: number,
|
103
|
+
): number {
|
104
|
+
// prettier-ignore
|
105
|
+
return (start * (1.0 - t) * (1.0 - t) * (1.0 - t))
|
106
|
+
+ (3.0 * c1 * (1.0 - t) * (1.0 - t) * t)
|
107
|
+
+ (3.0 * c2 * (1.0 - t) * t * t)
|
108
|
+
+ (end * t * t * t);
|
109
|
+
}
|
110
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// Interface for point data structure used e.g. in SignaturePad#fromData method
|
2
|
+
export interface BasicPoint {
|
3
|
+
x: number;
|
4
|
+
y: number;
|
5
|
+
pressure: number;
|
6
|
+
time: number;
|
7
|
+
}
|
8
|
+
|
9
|
+
export class Point implements BasicPoint {
|
10
|
+
public x: number;
|
11
|
+
public y: number;
|
12
|
+
public pressure: number;
|
13
|
+
public time: number;
|
14
|
+
|
15
|
+
public constructor(x: number, y: number, pressure?: number, time?: number) {
|
16
|
+
if (isNaN(x) || isNaN(y)) {
|
17
|
+
throw new Error(`Point is invalid: (${x}, ${y})`);
|
18
|
+
}
|
19
|
+
this.x = +x;
|
20
|
+
this.y = +y;
|
21
|
+
this.pressure = pressure || 0;
|
22
|
+
this.time = time || Date.now();
|
23
|
+
}
|
24
|
+
|
25
|
+
public distanceTo(start: BasicPoint): number {
|
26
|
+
return Math.sqrt(
|
27
|
+
Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2),
|
28
|
+
);
|
29
|
+
}
|
30
|
+
|
31
|
+
public equals(other: BasicPoint): boolean {
|
32
|
+
return (
|
33
|
+
this.x === other.x &&
|
34
|
+
this.y === other.y &&
|
35
|
+
this.pressure === other.pressure &&
|
36
|
+
this.time === other.time
|
37
|
+
);
|
38
|
+
}
|
39
|
+
|
40
|
+
public velocityFrom(start: BasicPoint): number {
|
41
|
+
return this.time !== start.time
|
42
|
+
? this.distanceTo(start) / (this.time - start.time)
|
43
|
+
: 0;
|
44
|
+
}
|
45
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
export * from './controls/accordion';
|
2
2
|
export * from './controls/button';
|
3
|
+
export * from './controls/canvas/DrawPad';
|
3
4
|
export * from './controls/centered';
|
5
|
+
export * from './controls/ColorPickerDialog';
|
4
6
|
export * from './controls/date';
|
5
7
|
export * from './controls/divider';
|
6
8
|
export * from './controls/dropdown';
|