@leafer/path 1.0.0-alpha.21 → 1.0.0-alpha.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/src/PathHelper.ts CHANGED
@@ -1,115 +1,8 @@
1
- import { IPathDrawer, ITwoPointBoundsData, IPathCommandData } from '@leafer/interface'
2
- import { TwoPointBoundsHelper } from '@leafer/math'
3
-
4
- import { BezierHelper } from './BezierHelper'
5
- import { PathCommandMap as Command } from './PathCommandMap'
6
-
7
-
8
- const { M, L, C, Q, Z, ellipse: E } = Command
9
- const { toTwoPointBounds } = BezierHelper
10
- const { add, addPoint, setPoint } = TwoPointBoundsHelper
11
-
12
- const tempPointBounds = {} as ITwoPointBoundsData
1
+ import { IPathCommandData, IPathCreator } from '@leafer/interface'
13
2
 
14
3
  export const PathHelper = {
15
-
16
- smoothCorner(data: IPathCommandData, _cornerRadius: number, _cornerSmoothing?: number): IPathCommandData {
17
- return data
18
- },
19
-
20
- toTwoPointBounds(data: IPathCommandData, setPointBounds: ITwoPointBoundsData): void {
21
-
22
- let command: number
23
- let i: number = 0, x: number, y: number, x1: number, y1: number, toX: number, toY: number
24
-
25
- const len = data.length
26
-
27
- while (i < len) {
28
- command = data[i]
29
-
30
- if (i === 0) {
31
- (command === M) ? setPoint(setPointBounds, data[1], data[2]) : setPoint(setPointBounds, 0, 0)
32
- }
33
-
34
- switch (command) {
35
- case M: //moveto x,y
36
- case L: //lineto x,y
37
- x = data[i + 1]
38
- y = data[i + 2]
39
- addPoint(setPointBounds, x, y)
40
- i += 3
41
- break
42
- case C: //bezierCurveTo x1,y1,x2,y2,x,y
43
- toX = data[i + 5]
44
- toY = data[i + 6]
45
- toTwoPointBounds(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY, tempPointBounds)
46
- add(setPointBounds, tempPointBounds)
47
- x = toX
48
- y = toY
49
- i += 7
50
- break
51
- case Q: //quadraticCurveTo x1,y1,x,y
52
- x1 = data[i + 1]
53
- y1 = data[i + 2]
54
- toX = data[i + 3]
55
- toY = data[i + 4]
56
- toTwoPointBounds(x, y, x1, y1, x1, y1, toX, toY, tempPointBounds)
57
- add(setPointBounds, tempPointBounds)
58
- x = toX
59
- y = toY
60
- i += 5
61
- break
62
- case Z: //closepath
63
- i += 1
64
- break
65
- }
66
- }
67
-
68
- // 增加1px的扩展,否则会有问题
69
- setPointBounds.minX--
70
- setPointBounds.minY--
71
- setPointBounds.maxX++
72
- setPointBounds.maxY++
73
-
74
- },
75
-
76
- drawData(drawer: IPathDrawer, data: IPathCommandData): void {
77
- if (data) {
78
- let command: number
79
- let i = 0, len = data.length
80
-
81
- while (i < len) {
82
- command = data[i]
83
- switch (command) {
84
- case M: //moveto x,y
85
- drawer.moveTo(data[i + 1], data[i + 2])
86
- i += 3
87
- break
88
- case L: //lineto x,y
89
- drawer.lineTo(data[i + 1], data[i + 2])
90
- i += 3
91
- break
92
- case C: //bezierCurveTo x1,y1,x2,y2,x,y
93
- drawer.bezierCurveTo(data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6])
94
- i += 7
95
- break
96
- case Q: //quadraticCurveTo x1,y1,x,y
97
- drawer.quadraticCurveTo(data[i + 1], data[i + 2], data[i + 3], data[i + 4])
98
- i += 5
99
- break
100
- case Z: //closepath
101
- drawer.closePath()
102
- i += 1
103
- break
104
-
105
- // 非svg标准的canvas绘图命令
106
- case E:
107
- drawer.ellipse(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)
108
- i += 9
109
- break
110
- }
111
- }
112
- }
113
- }
114
-
4
+ // index.ts rewrite
5
+ creator: {} as IPathCreator,
6
+ parse(_pathString: string, _curveMode?: boolean): IPathCommandData { return undefined },
7
+ convertToCanvasData(_old: IPathCommandData, _curveMode?: boolean): IPathCommandData { return undefined }
115
8
  }
@@ -0,0 +1,22 @@
1
+ import { IPathDrawer } from '@leafer/interface'
2
+ import { MathHelper } from '@leafer/math'
3
+
4
+ export const RectHelper = {
5
+
6
+ drawRoundRect(drawer: IPathDrawer, x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void {
7
+ let [topLeft, topRight, bottomRight, bottomLeft] = MathHelper.fourNumber(cornerRadius)
8
+
9
+ const max = Math.min(width / 2, height / 2)
10
+ if (topLeft > max) topLeft = max
11
+ if (topRight > max) topRight = max
12
+ if (bottomRight > max) bottomRight = max
13
+ if (bottomLeft > max) bottomLeft = max
14
+
15
+ topLeft ? drawer.moveTo(x + topLeft, y) : drawer.moveTo(x, y)
16
+ topRight ? drawer.arcTo(x + width, y, x + width, y + height, topRight) : drawer.lineTo(x + width, y)
17
+ bottomRight ? drawer.arcTo(x + width, y + height, x, y + height, bottomRight) : drawer.lineTo(x + width, y + height)
18
+ bottomLeft ? drawer.arcTo(x, y + height, x, y, bottomLeft) : drawer.lineTo(x, y + height)
19
+ topLeft ? drawer.arcTo(x, y, x + width, y, topLeft) : drawer.lineTo(x, y)
20
+ }
21
+
22
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,21 @@
1
- export { PathConvert } from './PathConvert'
2
1
  export { PathHelper } from './PathHelper'
2
+ export { PathConvert } from './PathConvert'
3
3
  export { PathCreator } from './PathCreator'
4
+ export { PathCommandDataHelper } from './PathCommandDataHelper'
5
+ export { PathDrawer } from './PathDrawer'
6
+ export { PathBounds } from './PathBounds'
7
+ export { PathCorner } from './PathCorner'
4
8
  export { BezierHelper } from './BezierHelper'
5
- export { PathCommandMap, PathCommandNeedConvertMap, NumberPathCommandMap, NumberPathCommandLengthMap } from './PathCommandMap'
9
+ export { EllipseHelper } from './EllipseHelper'
10
+ export { RectHelper } from './RectHelper'
11
+ export { PathCommandMap, NeedConvertToCanvasCommandMap, PathNumberCommandMap, PathNumberCommandLengthMap } from './PathCommandMap'
12
+
13
+ // rewrite, prevent circular references
14
+
15
+ import { PathConvert } from './PathConvert'
16
+ import { PathCreator } from './PathCreator'
17
+ import { PathHelper } from './PathHelper'
18
+
19
+ PathHelper.creator = new PathCreator()
20
+ PathHelper.parse = PathConvert.parse
21
+ PathHelper.convertToCanvasData = PathConvert.toCanvasData