@leafer/path 1.0.0-rc.3 → 1.0.0-rc.30
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 +3 -1
- package/src/PathBounds.ts +6 -6
- package/src/PathCommandDataHelper.ts +13 -10
- package/src/PathConvert.ts +6 -6
- package/src/PathCorner.ts +66 -2
- package/src/PathCreator.ts +29 -19
- package/src/RectHelper.ts +8 -11
- package/src/index.ts +2 -0
- package/types/index.d.ts +13 -7
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.30",
|
|
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.30",
|
|
26
|
+
"@leafer/debug": "1.0.0-rc.30"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.0-rc.
|
|
29
|
+
"@leafer/interface": "1.0.0-rc.30"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/EllipseHelper.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { IPathCommandData } from '@leafer/interface'
|
|
2
2
|
import { OneRadian, PI2 } from '@leafer/math'
|
|
3
|
+
import { Platform } from '@leafer/platform'
|
|
3
4
|
|
|
4
5
|
import { PathCommandMap } from './PathCommandMap'
|
|
5
6
|
import { BezierHelper } from './BezierHelper'
|
|
6
7
|
|
|
8
|
+
|
|
7
9
|
const { sin, cos, sqrt, atan2 } = Math
|
|
8
10
|
const { ellipse } = BezierHelper
|
|
9
11
|
|
|
@@ -56,7 +58,7 @@ export const EllipseHelper = {
|
|
|
56
58
|
|
|
57
59
|
const anticlockwise = totalRadian < 0 ? 1 : 0
|
|
58
60
|
|
|
59
|
-
if (curveMode) {
|
|
61
|
+
if (curveMode || Platform.ellipseToCurve) {
|
|
60
62
|
ellipse(data, centerX, centerY, radiusX, radiusY, rotation, startRadian / OneRadian, endRadian / OneRadian, anticlockwise as unknown as boolean)
|
|
61
63
|
} else {
|
|
62
64
|
if (radiusX === radiusY && !rotation) {
|
package/src/PathBounds.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { PathCommandMap as Command } from './PathCommandMap'
|
|
|
8
8
|
|
|
9
9
|
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = Command
|
|
10
10
|
const { toTwoPointBounds, toTwoPointBoundsByQuadraticCurve, arcTo, arc, ellipse } = BezierHelper
|
|
11
|
-
const {
|
|
11
|
+
const { addPointBounds, copy, addPoint, setPoint, addBounds, toBounds } = TwoPointBoundsHelper
|
|
12
12
|
const debug = Debug.get('PathBounds')
|
|
13
13
|
|
|
14
14
|
let radius: number, radiusX: number, radiusY: number
|
|
@@ -54,7 +54,7 @@ export const PathBounds = {
|
|
|
54
54
|
toX = data[i + 5]
|
|
55
55
|
toY = data[i + 6]
|
|
56
56
|
toTwoPointBounds(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY, tempPointBounds)
|
|
57
|
-
|
|
57
|
+
addPointBounds(setPointBounds, tempPointBounds)
|
|
58
58
|
x = toX
|
|
59
59
|
y = toY
|
|
60
60
|
i += 7
|
|
@@ -65,7 +65,7 @@ export const PathBounds = {
|
|
|
65
65
|
toX = data[i + 3]
|
|
66
66
|
toY = data[i + 4]
|
|
67
67
|
toTwoPointBoundsByQuadraticCurve(x, y, x1, y1, toX, toY, tempPointBounds)
|
|
68
|
-
|
|
68
|
+
addPointBounds(setPointBounds, tempPointBounds)
|
|
69
69
|
x = toX
|
|
70
70
|
y = toY
|
|
71
71
|
i += 5
|
|
@@ -91,7 +91,7 @@ export const PathBounds = {
|
|
|
91
91
|
break
|
|
92
92
|
case G: // ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
|
|
93
93
|
ellipse(null, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6], data[i + 7], data[i + 8] as unknown as boolean, tempPointBounds, setEndPoint)
|
|
94
|
-
i === 0 ? copy(setPointBounds, tempPointBounds) :
|
|
94
|
+
i === 0 ? copy(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds)
|
|
95
95
|
x = setEndPoint.x
|
|
96
96
|
y = setEndPoint.y
|
|
97
97
|
i += 9
|
|
@@ -107,7 +107,7 @@ export const PathBounds = {
|
|
|
107
107
|
break
|
|
108
108
|
case O: // arc(x, y, radius, startAngle, endAngle, anticlockwise)
|
|
109
109
|
arc(null, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6] as unknown as boolean, tempPointBounds, setEndPoint)
|
|
110
|
-
i === 0 ? copy(setPointBounds, tempPointBounds) :
|
|
110
|
+
i === 0 ? copy(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds)
|
|
111
111
|
x = setEndPoint.x
|
|
112
112
|
y = setEndPoint.y
|
|
113
113
|
i += 7
|
|
@@ -122,7 +122,7 @@ export const PathBounds = {
|
|
|
122
122
|
break
|
|
123
123
|
case U: // arcTo(x1, y1, x2, y2, radius)
|
|
124
124
|
arcTo(null, x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], tempPointBounds, setEndPoint)
|
|
125
|
-
i === 0 ? copy(setPointBounds, tempPointBounds) :
|
|
125
|
+
i === 0 ? copy(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds)
|
|
126
126
|
x = setEndPoint.x
|
|
127
127
|
y = setEndPoint.y
|
|
128
128
|
i += 6
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { IPathCommandData, IPointData } from '@leafer/interface'
|
|
2
|
+
import { MathHelper, PointHelper } from '@leafer/math'
|
|
3
|
+
|
|
2
4
|
import { PathCommandMap } from './PathCommandMap'
|
|
3
5
|
import { BezierHelper } from './BezierHelper'
|
|
4
|
-
import { MathHelper } from '@leafer/math'
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap
|
|
9
|
+
const { getMinDistanceFrom, getRadianFrom } = PointHelper
|
|
10
|
+
const { tan, min, abs } = Math
|
|
8
11
|
const startPoint = {} as IPointData
|
|
9
12
|
|
|
10
13
|
export const PathCommandDataHelper = {
|
|
@@ -73,25 +76,25 @@ export const PathCommandDataHelper = {
|
|
|
73
76
|
}
|
|
74
77
|
},
|
|
75
78
|
|
|
76
|
-
arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number): void {
|
|
77
|
-
|
|
79
|
+
arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number, lastX?: number, lastY?: number): void {
|
|
80
|
+
if (lastX !== undefined) {
|
|
81
|
+
const maxRadius = tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2) * (getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2) / 2)
|
|
82
|
+
data.push(U, x1, y1, x2, y2, min(radius, abs(maxRadius)))
|
|
83
|
+
} else {
|
|
84
|
+
data.push(U, x1, y1, x2, y2, radius)
|
|
85
|
+
}
|
|
78
86
|
},
|
|
79
87
|
|
|
80
88
|
// new
|
|
81
89
|
|
|
82
90
|
drawEllipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
|
|
83
|
-
|
|
84
|
-
if (startAngle === undefined) startAngle = 0
|
|
85
|
-
if (endAngle === undefined) endAngle = 360
|
|
86
|
-
BezierHelper.ellipse(null, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise, null, null, startPoint)
|
|
91
|
+
BezierHelper.ellipse(null, x, y, radiusX, radiusY, rotation === undefined ? 0 : rotation, startAngle === undefined ? 0 : startAngle, endAngle === undefined ? 360 : endAngle, anticlockwise, null, null, startPoint)
|
|
87
92
|
data.push(M, startPoint.x, startPoint.y)
|
|
88
93
|
ellipse(data, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
|
|
89
94
|
},
|
|
90
95
|
|
|
91
96
|
drawArc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
|
|
92
|
-
|
|
93
|
-
if (endAngle === undefined) endAngle = 360
|
|
94
|
-
BezierHelper.arc(null, x, y, radius, startAngle, endAngle, anticlockwise, null, null, startPoint)
|
|
97
|
+
BezierHelper.arc(null, x, y, radius, startAngle === undefined ? 0 : startAngle, endAngle === undefined ? 360 : endAngle, anticlockwise, null, null, startPoint)
|
|
95
98
|
data.push(M, startPoint.x, startPoint.y)
|
|
96
99
|
arc(data, x, y, radius, startAngle, endAngle, anticlockwise)
|
|
97
100
|
},
|
package/src/PathConvert.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPathCommandData, IPointData } from '@leafer/interface'
|
|
2
|
-
import { StringNumberMap } from '@leafer/math'
|
|
2
|
+
import { MathHelper, StringNumberMap } from '@leafer/math'
|
|
3
3
|
import { Debug } from '@leafer/debug'
|
|
4
4
|
|
|
5
5
|
import { PathCommandMap as Command, NeedConvertToCanvasCommandMap, NeedConvertToCurveCommandMap, PathCommandLengthMap, PathNumberCommandMap, PathNumberCommandLengthMap } from './PathCommandMap'
|
|
@@ -26,7 +26,7 @@ export const PathConvert = {
|
|
|
26
26
|
|
|
27
27
|
current: { dot: 0 } as ICurrentCommand,
|
|
28
28
|
|
|
29
|
-
stringify(data: IPathCommandData): string {
|
|
29
|
+
stringify(data: IPathCommandData, floatLength?: number): string {
|
|
30
30
|
let i = 0, len = data.length, count: number, str: string = '', command: number, lastCommand: number
|
|
31
31
|
while (i < len) {
|
|
32
32
|
command = data[i]
|
|
@@ -38,7 +38,7 @@ export const PathConvert = {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
for (let j = 1; j < count; j++) {
|
|
41
|
-
str += data[i + j];
|
|
41
|
+
str += MathHelper.float(data[i + j], floatLength);
|
|
42
42
|
(j === count - 1) || (str += ' ')
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -61,12 +61,12 @@ export const PathConvert = {
|
|
|
61
61
|
if (StringNumberMap[char]) {
|
|
62
62
|
|
|
63
63
|
if (char === '.') {
|
|
64
|
+
if (current.dot) { pushData(data, num); num = '' } // .375.375
|
|
64
65
|
current.dot++
|
|
65
|
-
if (current.dot > 1) {
|
|
66
|
-
pushData(data, num); num = '' // .375.375
|
|
67
|
-
}
|
|
68
66
|
}
|
|
69
67
|
|
|
68
|
+
if (num === '0' && char !== '.') { pushData(data, num); num = '' } // 00 01
|
|
69
|
+
|
|
70
70
|
num += char
|
|
71
71
|
|
|
72
72
|
} else if (Command[char]) {
|
package/src/PathCorner.ts
CHANGED
|
@@ -1,10 +1,74 @@
|
|
|
1
1
|
import { IPathCommandData } from '@leafer/interface'
|
|
2
|
+
import { PointHelper } from '@leafer/math'
|
|
2
3
|
|
|
4
|
+
import { PathCommandMap as Command } from './PathCommandMap'
|
|
5
|
+
import { PathCommandDataHelper } from './PathCommandDataHelper'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const { M, L, C, Z } = Command
|
|
9
|
+
const { getCenterX, getCenterY } = PointHelper
|
|
10
|
+
const { arcTo } = PathCommandDataHelper
|
|
3
11
|
|
|
4
12
|
export const PathCorner = {
|
|
5
13
|
|
|
6
|
-
smooth(data: IPathCommandData,
|
|
7
|
-
|
|
14
|
+
smooth(data: IPathCommandData, cornerRadius: number, _cornerSmoothing?: number): IPathCommandData {
|
|
15
|
+
let command: number
|
|
16
|
+
let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0
|
|
17
|
+
|
|
18
|
+
const len = data.length
|
|
19
|
+
const smooth: IPathCommandData = []
|
|
20
|
+
|
|
21
|
+
while (i < len) {
|
|
22
|
+
command = data[i]
|
|
23
|
+
switch (command) {
|
|
24
|
+
case M: //moveto(x, y)
|
|
25
|
+
startX = lastX = data[i + 1]
|
|
26
|
+
startY = lastY = data[i + 2]
|
|
27
|
+
i += 3
|
|
28
|
+
if (data[i] === L) { // next lineTo
|
|
29
|
+
secondX = data[i + 1]
|
|
30
|
+
secondY = data[i + 2]
|
|
31
|
+
smooth.push(M, getCenterX(startX, secondX), getCenterY(startY, secondY))
|
|
32
|
+
} else {
|
|
33
|
+
smooth.push(M, startX, startY)
|
|
34
|
+
}
|
|
35
|
+
break
|
|
36
|
+
case L: //lineto(x, y)
|
|
37
|
+
x = data[i + 1]
|
|
38
|
+
y = data[i + 2]
|
|
39
|
+
i += 3
|
|
40
|
+
switch (data[i]) { // next command
|
|
41
|
+
case L: // lineTo()
|
|
42
|
+
arcTo(smooth, x, y, data[i + 1], data[i + 2], cornerRadius, lastX, lastY) // use arcTo(x1, y1, x2, y2, radius)
|
|
43
|
+
break
|
|
44
|
+
case Z: // closePath()
|
|
45
|
+
arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY) // use arcTo(x1, y1, x2, y2, radius)
|
|
46
|
+
break
|
|
47
|
+
default:
|
|
48
|
+
smooth.push(L, x, y)
|
|
49
|
+
}
|
|
50
|
+
lastX = x
|
|
51
|
+
lastY = y
|
|
52
|
+
break
|
|
53
|
+
case C: //bezierCurveTo(x1, y1, x2, y2, x, y)
|
|
54
|
+
smooth.push(C, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6])
|
|
55
|
+
i += 7
|
|
56
|
+
break
|
|
57
|
+
case Z: //closepath()
|
|
58
|
+
arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY) // use arcTo(x1, y1, x2, y2, radius)
|
|
59
|
+
smooth.push(Z)
|
|
60
|
+
i += 1
|
|
61
|
+
break
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (command !== Z) {
|
|
67
|
+
smooth[1] = startX
|
|
68
|
+
smooth[2] = startY
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return smooth
|
|
8
72
|
}
|
|
9
73
|
|
|
10
74
|
}
|
package/src/PathCreator.ts
CHANGED
|
@@ -1,96 +1,106 @@
|
|
|
1
|
-
import { IPathCommandData,
|
|
1
|
+
import { IPathCommandData, IPathCreator, IPathString } from '@leafer/interface'
|
|
2
2
|
import { PathCommandDataHelper } from './PathCommandDataHelper'
|
|
3
3
|
import { PathHelper } from './PathHelper'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const { moveTo, lineTo, quadraticCurveTo, bezierCurveTo, closePath, beginPath, rect, roundRect, ellipse, arc, arcTo, drawEllipse, drawArc, drawPoints } = PathCommandDataHelper
|
|
7
7
|
|
|
8
|
-
export class PathCreator implements
|
|
8
|
+
export class PathCreator implements IPathCreator { // tip: rewrited Pen
|
|
9
9
|
|
|
10
|
-
public path: IPathCommandData
|
|
10
|
+
public set path(value: IPathCommandData) { this.__path = value }
|
|
11
|
+
public get path() { return this.__path }
|
|
12
|
+
|
|
13
|
+
public __path: IPathCommandData // 提供一个更安全的内部变量(比如覆盖给Pen时需要用到,避免与原有属性冲突)
|
|
11
14
|
|
|
12
15
|
constructor(path?: IPathCommandData | IPathString) {
|
|
16
|
+
this.set(path)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public set(path?: IPathCommandData | IPathString): PathCreator {
|
|
13
20
|
if (path) {
|
|
14
|
-
this.
|
|
21
|
+
this.__path = typeof path === 'string' ? PathHelper.parse(path) : path
|
|
15
22
|
} else {
|
|
16
|
-
this.
|
|
23
|
+
this.__path = []
|
|
17
24
|
}
|
|
25
|
+
return this
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
public beginPath(): PathCreator {
|
|
21
|
-
beginPath(this.
|
|
29
|
+
beginPath(this.__path)
|
|
22
30
|
return this
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
// svg and canvas
|
|
26
34
|
|
|
27
35
|
public moveTo(x: number, y: number): PathCreator {
|
|
28
|
-
moveTo(this.
|
|
36
|
+
moveTo(this.__path, x, y)
|
|
29
37
|
return this
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
public lineTo(x: number, y: number): PathCreator {
|
|
33
|
-
lineTo(this.
|
|
41
|
+
lineTo(this.__path, x, y)
|
|
34
42
|
return this
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
public bezierCurveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): PathCreator {
|
|
38
|
-
bezierCurveTo(this.
|
|
46
|
+
bezierCurveTo(this.__path, x1, y1, x2, y2, x, y)
|
|
39
47
|
return this
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
public quadraticCurveTo(x1: number, y1: number, x: number, y: number): PathCreator {
|
|
43
|
-
quadraticCurveTo(this.
|
|
51
|
+
quadraticCurveTo(this.__path, x1, y1, x, y)
|
|
44
52
|
return this
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
public closePath(): PathCreator {
|
|
48
|
-
closePath(this.
|
|
56
|
+
closePath(this.__path)
|
|
49
57
|
return this
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
// canvas
|
|
53
61
|
|
|
54
62
|
public rect(x: number, y: number, width: number, height: number): PathCreator {
|
|
55
|
-
rect(this.
|
|
63
|
+
rect(this.__path, x, y, width, height)
|
|
56
64
|
return this
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
public roundRect(x: number, y: number, width: number, height: number, cornerRadius: number | number[]): PathCreator {
|
|
60
|
-
roundRect(this.
|
|
68
|
+
roundRect(this.__path, x, y, width, height, cornerRadius)
|
|
61
69
|
return this
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
public ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator {
|
|
65
|
-
ellipse(this.
|
|
73
|
+
ellipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
|
|
66
74
|
return this
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
public arc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator {
|
|
70
|
-
arc(this.
|
|
78
|
+
arc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise)
|
|
71
79
|
return this
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
public arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): PathCreator {
|
|
75
|
-
arcTo(this.
|
|
83
|
+
arcTo(this.__path, x1, y1, x2, y2, radius)
|
|
76
84
|
return this
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
// moveTo, then draw
|
|
80
88
|
|
|
81
89
|
public drawEllipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator {
|
|
82
|
-
drawEllipse(this.
|
|
90
|
+
drawEllipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
|
|
83
91
|
return this
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
public drawArc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator {
|
|
87
|
-
drawArc(this.
|
|
95
|
+
drawArc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise)
|
|
88
96
|
return this
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
public drawPoints(points: number[], curve?: boolean | number, close?: boolean): PathCreator {
|
|
92
|
-
drawPoints(this.
|
|
100
|
+
drawPoints(this.__path, points, curve, close)
|
|
93
101
|
return this
|
|
94
102
|
}
|
|
95
103
|
|
|
104
|
+
public clearPath = this.beginPath
|
|
105
|
+
|
|
96
106
|
}
|
package/src/RectHelper.ts
CHANGED
|
@@ -4,19 +4,16 @@ import { MathHelper } from '@leafer/math'
|
|
|
4
4
|
export const RectHelper = {
|
|
5
5
|
|
|
6
6
|
drawRoundRect(drawer: IPathDrawer, x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void {
|
|
7
|
-
|
|
7
|
+
const data = MathHelper.fourNumber(cornerRadius, Math.min(width / 2, height / 2))
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
if (topRight > max) topRight = max
|
|
12
|
-
if (bottomRight > max) bottomRight = max
|
|
13
|
-
if (bottomLeft > max) bottomLeft = max
|
|
9
|
+
const right = x + width
|
|
10
|
+
const bottom = y + height
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
data[0] ? drawer.moveTo(x + data[0], y) : drawer.moveTo(x, y)
|
|
13
|
+
data[1] ? drawer.arcTo(right, y, right, bottom, data[1]) : drawer.lineTo(right, y)
|
|
14
|
+
data[2] ? drawer.arcTo(right, bottom, x, bottom, data[2]) : drawer.lineTo(right, bottom)
|
|
15
|
+
data[3] ? drawer.arcTo(x, bottom, x, y, data[3]) : drawer.lineTo(x, bottom)
|
|
16
|
+
data[0] ? drawer.arcTo(x, y, right, y, data[0]) : drawer.lineTo(x, y)
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
}
|
package/src/index.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IPathCreator, IPathCommandData,
|
|
1
|
+
import { IPathCreator, IPathCommandData, IPathString, IPathDrawer, IBoundsData, ITwoPointBoundsData, IPointData, INumberMap, IStringMap } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare const PathHelper: {
|
|
4
4
|
creator: IPathCreator;
|
|
@@ -14,16 +14,19 @@ interface ICurrentCommand {
|
|
|
14
14
|
}
|
|
15
15
|
declare const PathConvert: {
|
|
16
16
|
current: ICurrentCommand;
|
|
17
|
-
stringify(data: IPathCommandData): string;
|
|
17
|
+
stringify(data: IPathCommandData, floatLength?: number): string;
|
|
18
18
|
parse(pathString: string, curveMode?: boolean): IPathCommandData;
|
|
19
19
|
toCanvasData(old: IPathCommandData, curveMode?: boolean): IPathCommandData;
|
|
20
20
|
copyData(data: IPathCommandData, old: IPathCommandData, index: number, count: number): void;
|
|
21
21
|
pushData(data: IPathCommandData, strNum: string | number): void;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
declare class PathCreator implements
|
|
25
|
-
path: IPathCommandData;
|
|
24
|
+
declare class PathCreator implements IPathCreator {
|
|
25
|
+
set path(value: IPathCommandData);
|
|
26
|
+
get path(): IPathCommandData;
|
|
27
|
+
__path: IPathCommandData;
|
|
26
28
|
constructor(path?: IPathCommandData | IPathString);
|
|
29
|
+
set(path?: IPathCommandData | IPathString): PathCreator;
|
|
27
30
|
beginPath(): PathCreator;
|
|
28
31
|
moveTo(x: number, y: number): PathCreator;
|
|
29
32
|
lineTo(x: number, y: number): PathCreator;
|
|
@@ -38,6 +41,7 @@ declare class PathCreator implements IPathDrawer {
|
|
|
38
41
|
drawEllipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator;
|
|
39
42
|
drawArc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator;
|
|
40
43
|
drawPoints(points: number[], curve?: boolean | number, close?: boolean): PathCreator;
|
|
44
|
+
clearPath: () => PathCreator;
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
declare const PathCommandDataHelper: {
|
|
@@ -51,7 +55,7 @@ declare const PathCommandDataHelper: {
|
|
|
51
55
|
roundRect(data: IPathCommandData, x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void;
|
|
52
56
|
ellipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
|
|
53
57
|
arc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
|
|
54
|
-
arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
58
|
+
arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number, lastX?: number, lastY?: number): void;
|
|
55
59
|
drawEllipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
|
|
56
60
|
drawArc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
|
|
57
61
|
drawPoints(data: IPathCommandData, points: number[], curve?: boolean | number, close?: boolean): void;
|
|
@@ -67,7 +71,7 @@ declare const PathBounds: {
|
|
|
67
71
|
};
|
|
68
72
|
|
|
69
73
|
declare const PathCorner: {
|
|
70
|
-
smooth(data: IPathCommandData,
|
|
74
|
+
smooth(data: IPathCommandData, cornerRadius: number, _cornerSmoothing?: number): IPathCommandData;
|
|
71
75
|
};
|
|
72
76
|
|
|
73
77
|
declare const BezierHelper: {
|
|
@@ -97,4 +101,6 @@ declare const NeedConvertToCanvasCommandMap: INumberMap;
|
|
|
97
101
|
declare const PathNumberCommandMap: IStringMap;
|
|
98
102
|
declare const PathNumberCommandLengthMap: INumberMap;
|
|
99
103
|
|
|
100
|
-
|
|
104
|
+
declare const pen: PathCreator;
|
|
105
|
+
|
|
106
|
+
export { BezierHelper, EllipseHelper, NeedConvertToCanvasCommandMap, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, RectHelper, pen };
|