@leafer/path 1.0.5 → 1.0.7

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.5",
3
+ "version": "1.0.7",
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.5",
26
- "@leafer/debug": "1.0.5"
25
+ "@leafer/math": "1.0.7",
26
+ "@leafer/debug": "1.0.7"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.5"
29
+ "@leafer/interface": "1.0.7"
30
30
  }
31
31
  }
@@ -8,13 +8,16 @@ import { PathHelper } from './PathHelper'
8
8
 
9
9
  const { sin, cos, atan2, ceil, abs, PI, sqrt, pow } = Math
10
10
  const { setPoint, addPoint } = TwoPointBoundsHelper
11
- const { set } = PointHelper
11
+ const { set, toNumberPoints } = PointHelper
12
12
  const { M, L, C, Q, Z } = PathCommandMap
13
13
  const tempPoint = {} as IPointData
14
14
 
15
15
  export const BezierHelper = {
16
16
 
17
- points(data: IPathCommandData, points: number[], curve?: boolean | number, close?: boolean): void {
17
+ points(data: IPathCommandData, originPoints: number[] | IPointData[], curve?: boolean | number, close?: boolean): void {
18
+
19
+ let points = toNumberPoints(originPoints)
20
+
18
21
  data.push(M, points[0], points[1])
19
22
 
20
23
  if (curve && points.length > 5) {
@@ -99,7 +99,7 @@ export const PathCommandDataHelper = {
99
99
  arc(data, x, y, radius, startAngle, endAngle, anticlockwise)
100
100
  },
101
101
 
102
- drawPoints(data: IPathCommandData, points: number[], curve?: boolean | number, close?: boolean): void {
102
+ drawPoints(data: IPathCommandData, points: number[] | IPointData[], curve?: boolean | number, close?: boolean): void {
103
103
  BezierHelper.points(data, points, curve, close)
104
104
  }
105
105
 
@@ -1,4 +1,4 @@
1
- import { IPathCommandData, IPointData } from '@leafer/interface'
1
+ import { IPathCommandData, IPathCommandObject, IPointData } from '@leafer/interface'
2
2
  import { MathHelper, StringNumberMap } from '@leafer/math'
3
3
  import { Debug } from '@leafer/debug'
4
4
 
@@ -303,6 +303,20 @@ export const PathConvert = {
303
303
 
304
304
  },
305
305
 
306
+ objectToCanvasData(list: IPathCommandObject[]): IPathCommandData {
307
+ const data: IPathCommandData = []
308
+ list.forEach(item => {
309
+ switch (item.name) {
310
+ case 'M': data.push(M, item.x, item.y); break
311
+ case 'L': data.push(L, item.x, item.y); break
312
+ case 'C': data.push(C, item.x1, item.y1, item.x2, item.y2, item.x, item.y); break
313
+ case 'Q': data.push(Q, item.x1, item.y1, item.x, item.y); break
314
+ case 'Z': data.push(Z)
315
+ }
316
+ })
317
+ return data
318
+ },
319
+
306
320
  copyData(data: IPathCommandData, old: IPathCommandData, index: number, count: number): void {
307
321
  for (let i = index, end = index + count; i < end; i++) {
308
322
  data.push(old[i])
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IPathCreator, IPathCommandData, IPathString, IPathDrawer, IBoundsData, ITwoPointBoundsData, IPointData, INumberMap, IStringMap } from '@leafer/interface';
1
+ import { IPathCreator, IPathCommandData, IPathCommandObject, IPathString, IPointData, IPathDrawer, IBoundsData, ITwoPointBoundsData, INumberMap, IStringMap } from '@leafer/interface';
2
2
 
3
3
  declare const PathHelper: {
4
4
  creator: IPathCreator;
@@ -17,6 +17,7 @@ declare const PathConvert: {
17
17
  stringify(data: IPathCommandData, floatLength?: number): string;
18
18
  parse(pathString: string, curveMode?: boolean): IPathCommandData;
19
19
  toCanvasData(old: IPathCommandData, curveMode?: boolean): IPathCommandData;
20
+ objectToCanvasData(list: IPathCommandObject[]): IPathCommandData;
20
21
  copyData(data: IPathCommandData, old: IPathCommandData, index: number, count: number): void;
21
22
  pushData(data: IPathCommandData, strNum: string | number): void;
22
23
  };
@@ -59,7 +60,7 @@ declare const PathCommandDataHelper: {
59
60
  arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number, lastX?: number, lastY?: number): void;
60
61
  drawEllipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
61
62
  drawArc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
62
- drawPoints(data: IPathCommandData, points: number[], curve?: boolean | number, close?: boolean): void;
63
+ drawPoints(data: IPathCommandData, points: number[] | IPointData[], curve?: boolean | number, close?: boolean): void;
63
64
  };
64
65
 
65
66
  declare const PathDrawer: {
@@ -76,7 +77,7 @@ declare const PathCorner: {
76
77
  };
77
78
 
78
79
  declare const BezierHelper: {
79
- points(data: IPathCommandData, points: number[], curve?: boolean | number, close?: boolean): void;
80
+ points(data: IPathCommandData, originPoints: number[] | IPointData[], curve?: boolean | number, close?: boolean): void;
80
81
  rect(data: IPathCommandData, x: number, y: number, width: number, height: number): void;
81
82
  roundRect(data: IPathCommandData, x: number, y: number, width: number, height: number, radius: number | number[]): void;
82
83
  arcTo(data: IPathCommandData | null | void, fromX: number, fromY: number, x1: number, y1: number, toX: number, toY: number, radius: number, setPointBounds?: ITwoPointBoundsData, setEndPoint?: IPointData, setStartPoint?: IPointData): void;