@leafer/path 1.0.0-rc.11 → 1.0.0-rc.16

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/path",
3
- "version": "1.0.0-rc.11",
3
+ "version": "1.0.0-rc.16",
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.11",
26
- "@leafer/debug": "1.0.0-rc.11"
25
+ "@leafer/math": "1.0.0-rc.16",
26
+ "@leafer/debug": "1.0.0-rc.16"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.11"
29
+ "@leafer/interface": "1.0.0-rc.16"
30
30
  }
31
31
  }
@@ -88,18 +88,13 @@ export const PathCommandDataHelper = {
88
88
  // new
89
89
 
90
90
  drawEllipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
91
- if (rotation === undefined) rotation = 0
92
- if (startAngle === undefined) startAngle = 0
93
- if (endAngle === undefined) endAngle = 360
94
- 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)
95
92
  data.push(M, startPoint.x, startPoint.y)
96
93
  ellipse(data, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
97
94
  },
98
95
 
99
96
  drawArc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
100
- if (startAngle === undefined) startAngle = 0
101
- if (endAngle === undefined) endAngle = 360
102
- 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)
103
98
  data.push(M, startPoint.x, startPoint.y)
104
99
  arc(data, x, y, radius, startAngle, endAngle, anticlockwise)
105
100
  },
@@ -7,89 +7,92 @@ const { moveTo, lineTo, quadraticCurveTo, bezierCurveTo, closePath, beginPath, r
7
7
 
8
8
  export class PathCreator implements IPathDrawer {
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) {
13
16
  if (path) {
14
- this.path = typeof path === 'string' ? PathHelper.parse(path) : path
17
+ this.__path = typeof path === 'string' ? PathHelper.parse(path) : path
15
18
  } else {
16
- this.path = []
19
+ this.__path = []
17
20
  }
18
21
  }
19
22
 
20
23
  public beginPath(): PathCreator {
21
- beginPath(this.path)
24
+ beginPath(this.__path)
22
25
  return this
23
26
  }
24
27
 
25
28
  // svg and canvas
26
29
 
27
30
  public moveTo(x: number, y: number): PathCreator {
28
- moveTo(this.path, x, y)
31
+ moveTo(this.__path, x, y)
29
32
  return this
30
33
  }
31
34
 
32
35
  public lineTo(x: number, y: number): PathCreator {
33
- lineTo(this.path, x, y)
36
+ lineTo(this.__path, x, y)
34
37
  return this
35
38
  }
36
39
 
37
40
  public bezierCurveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): PathCreator {
38
- bezierCurveTo(this.path, x1, y1, x2, y2, x, y)
41
+ bezierCurveTo(this.__path, x1, y1, x2, y2, x, y)
39
42
  return this
40
43
  }
41
44
 
42
45
  public quadraticCurveTo(x1: number, y1: number, x: number, y: number): PathCreator {
43
- quadraticCurveTo(this.path, x1, y1, x, y)
46
+ quadraticCurveTo(this.__path, x1, y1, x, y)
44
47
  return this
45
48
  }
46
49
 
47
50
  public closePath(): PathCreator {
48
- closePath(this.path)
51
+ closePath(this.__path)
49
52
  return this
50
53
  }
51
54
 
52
55
  // canvas
53
56
 
54
57
  public rect(x: number, y: number, width: number, height: number): PathCreator {
55
- rect(this.path, x, y, width, height)
58
+ rect(this.__path, x, y, width, height)
56
59
  return this
57
60
  }
58
61
 
59
62
  public roundRect(x: number, y: number, width: number, height: number, cornerRadius: number | number[]): PathCreator {
60
- roundRect(this.path, x, y, width, height, cornerRadius)
63
+ roundRect(this.__path, x, y, width, height, cornerRadius)
61
64
  return this
62
65
  }
63
66
 
64
67
  public ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator {
65
- ellipse(this.path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
68
+ ellipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
66
69
  return this
67
70
  }
68
71
 
69
72
  public arc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator {
70
- arc(this.path, x, y, radius, startAngle, endAngle, anticlockwise)
73
+ arc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise)
71
74
  return this
72
75
  }
73
76
 
74
77
  public arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): PathCreator {
75
- arcTo(this.path, x1, y1, x2, y2, radius)
78
+ arcTo(this.__path, x1, y1, x2, y2, radius)
76
79
  return this
77
80
  }
78
81
 
79
82
  // moveTo, then draw
80
83
 
81
84
  public drawEllipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator {
82
- drawEllipse(this.path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
85
+ drawEllipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
83
86
  return this
84
87
  }
85
88
 
86
89
  public drawArc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): PathCreator {
87
- drawArc(this.path, x, y, radius, startAngle, endAngle, anticlockwise)
90
+ drawArc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise)
88
91
  return this
89
92
  }
90
93
 
91
94
  public drawPoints(points: number[], curve?: boolean | number, close?: boolean): PathCreator {
92
- drawPoints(this.path, points, curve, close)
95
+ drawPoints(this.__path, points, curve, close)
93
96
  return this
94
97
  }
95
98
 
package/types/index.d.ts CHANGED
@@ -22,7 +22,9 @@ declare const PathConvert: {
22
22
  };
23
23
 
24
24
  declare class PathCreator implements IPathDrawer {
25
- path: IPathCommandData;
25
+ set path(value: IPathCommandData);
26
+ get path(): IPathCommandData;
27
+ __path: IPathCommandData;
26
28
  constructor(path?: IPathCommandData | IPathString);
27
29
  beginPath(): PathCreator;
28
30
  moveTo(x: number, y: number): PathCreator;