@leafer/path 1.0.0-rc.5 → 1.0.0-rc.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.
- package/package.json +4 -4
- package/src/EllipseHelper.ts +1 -1
- package/src/PathCorner.ts +59 -2
- package/types/index.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/path",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.6",
|
|
4
4
|
"description": "@leafer/path",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/math": "1.0.0-rc.
|
|
26
|
-
"@leafer/debug": "1.0.0-rc.
|
|
25
|
+
"@leafer/math": "1.0.0-rc.6",
|
|
26
|
+
"@leafer/debug": "1.0.0-rc.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.0-rc.
|
|
29
|
+
"@leafer/interface": "1.0.0-rc.6"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/EllipseHelper.ts
CHANGED
|
@@ -58,7 +58,7 @@ export const EllipseHelper = {
|
|
|
58
58
|
|
|
59
59
|
const anticlockwise = totalRadian < 0 ? 1 : 0
|
|
60
60
|
|
|
61
|
-
if (curveMode || Platform.
|
|
61
|
+
if (curveMode || Platform.ellipseToCurve) {
|
|
62
62
|
ellipse(data, centerX, centerY, radiusX, radiusY, rotation, startRadian / OneRadian, endRadian / OneRadian, anticlockwise as unknown as boolean)
|
|
63
63
|
} else {
|
|
64
64
|
if (radiusX === radiusY && !rotation) {
|
package/src/PathCorner.ts
CHANGED
|
@@ -1,10 +1,67 @@
|
|
|
1
1
|
import { IPathCommandData } from '@leafer/interface'
|
|
2
|
+
import { PathCommandMap as Command } from './PathCommandMap'
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const { M, L, C, Z, U } = Command
|
|
6
|
+
|
|
4
7
|
export const PathCorner = {
|
|
5
8
|
|
|
6
|
-
smooth(data: IPathCommandData,
|
|
7
|
-
|
|
9
|
+
smooth(data: IPathCommandData, cornerRadius: number, _cornerSmoothing?: number): IPathCommandData {
|
|
10
|
+
let command: number
|
|
11
|
+
let i: number = 0, x: number = 0, y: number = 0, startX: number, startY = 0, centerX: number = 0, centerY: number = 0
|
|
12
|
+
|
|
13
|
+
const len = data.length
|
|
14
|
+
const smooth: IPathCommandData = []
|
|
15
|
+
|
|
16
|
+
while (i < len) {
|
|
17
|
+
command = data[i]
|
|
18
|
+
switch (command) {
|
|
19
|
+
case M: //moveto(x, y)
|
|
20
|
+
startX = data[i + 1]
|
|
21
|
+
startY = data[i + 2]
|
|
22
|
+
i += 3
|
|
23
|
+
if (data[i] === L) { // next lineTo
|
|
24
|
+
centerX = startX + (data[i + 1] - startX) / 2
|
|
25
|
+
centerY = startY + (data[i + 2] - startY) / 2
|
|
26
|
+
smooth.push(M, centerX, centerY)
|
|
27
|
+
} else {
|
|
28
|
+
smooth.push(M, startX, startY)
|
|
29
|
+
}
|
|
30
|
+
break
|
|
31
|
+
case L: //lineto(x, y)
|
|
32
|
+
x = data[i + 1]
|
|
33
|
+
y = data[i + 2]
|
|
34
|
+
i += 3
|
|
35
|
+
switch (data[i]) { // next command
|
|
36
|
+
case L: // lineTo()
|
|
37
|
+
smooth.push(U, x, y, data[i + 1], data[i + 2], cornerRadius) // use arcTo(x1, y1, x2, y2, radius)
|
|
38
|
+
break
|
|
39
|
+
case Z: // closePath()
|
|
40
|
+
smooth.push(U, x, y, startX, startY, cornerRadius) // use arcTo(x1, y1, x2, y2, radius)
|
|
41
|
+
break
|
|
42
|
+
default:
|
|
43
|
+
smooth.push(L, x, y)
|
|
44
|
+
}
|
|
45
|
+
break
|
|
46
|
+
case C: //bezierCurveTo(x1, y1, x2, y2, x, y)
|
|
47
|
+
smooth.push(C, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6])
|
|
48
|
+
i += 7
|
|
49
|
+
break
|
|
50
|
+
case Z: //closepath()
|
|
51
|
+
smooth.push(U, startX, startY, centerX, centerY, cornerRadius) // use arcTo(x1, y1, x2, y2, radius)
|
|
52
|
+
smooth.push(Z)
|
|
53
|
+
i += 1
|
|
54
|
+
break
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (command !== Z) {
|
|
60
|
+
smooth[1] = startX
|
|
61
|
+
smooth[2] = startY
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return smooth
|
|
8
65
|
}
|
|
9
66
|
|
|
10
67
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ declare const PathBounds: {
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
declare const PathCorner: {
|
|
70
|
-
smooth(data: IPathCommandData,
|
|
70
|
+
smooth(data: IPathCommandData, cornerRadius: number, _cornerSmoothing?: number): IPathCommandData;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
declare const BezierHelper: {
|