@leafer/path 1.0.0-beta.7 → 1.0.0-beta.9
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/PathConvert.ts +16 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/path",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "@leafer/path",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/math": "1.0.0-beta.
|
|
23
|
-
"@leafer/debug": "1.0.0-beta.
|
|
22
|
+
"@leafer/math": "1.0.0-beta.9",
|
|
23
|
+
"@leafer/debug": "1.0.0-beta.9"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-beta.
|
|
26
|
+
"@leafer/interface": "1.0.0-beta.9"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/PathConvert.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface ICurrentCommand {
|
|
|
11
11
|
name?: number
|
|
12
12
|
length?: number
|
|
13
13
|
index?: number
|
|
14
|
+
dot?: number
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
|
|
@@ -23,7 +24,7 @@ const setEndPoint = {} as IPointData
|
|
|
23
24
|
|
|
24
25
|
export const PathConvert = {
|
|
25
26
|
|
|
26
|
-
current: {} as ICurrentCommand,
|
|
27
|
+
current: { dot: 0 } as ICurrentCommand,
|
|
27
28
|
|
|
28
29
|
stringify(data: IPathCommandData): string {
|
|
29
30
|
let i = 0, len = data.length, count: number, str: string = '', command: number, lastCommand: number
|
|
@@ -59,11 +60,18 @@ export const PathConvert = {
|
|
|
59
60
|
|
|
60
61
|
if (StringNumberMap[char]) {
|
|
61
62
|
|
|
63
|
+
if (char === '.') {
|
|
64
|
+
current.dot++
|
|
65
|
+
if (current.dot > 1) {
|
|
66
|
+
pushData(data, num); num = '' // .375.375
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
62
70
|
num += char
|
|
63
71
|
|
|
64
72
|
} else if (Command[char]) {
|
|
65
73
|
|
|
66
|
-
if (num) { pushData(data,
|
|
74
|
+
if (num) { pushData(data, num); num = '' }
|
|
67
75
|
|
|
68
76
|
current.name = Command[char]
|
|
69
77
|
current.length = PathCommandLengthMap[char]
|
|
@@ -79,12 +87,12 @@ export const PathConvert = {
|
|
|
79
87
|
if (lastChar === 'e' || lastChar === 'E') { // L45e-12 21e+22
|
|
80
88
|
num += char
|
|
81
89
|
} else {
|
|
82
|
-
if (num) pushData(data,
|
|
90
|
+
if (num) pushData(data, num) // L-34-35 L+12+28
|
|
83
91
|
num = char
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
} else {
|
|
87
|
-
if (num) { pushData(data,
|
|
95
|
+
if (num) { pushData(data, num); num = '' }
|
|
88
96
|
}
|
|
89
97
|
|
|
90
98
|
}
|
|
@@ -93,7 +101,7 @@ export const PathConvert = {
|
|
|
93
101
|
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
if (num) pushData(data,
|
|
104
|
+
if (num) pushData(data, num)
|
|
97
105
|
|
|
98
106
|
return needConvert ? PathConvert.toCanvasData(data, curveMode) : data
|
|
99
107
|
},
|
|
@@ -301,14 +309,15 @@ export const PathConvert = {
|
|
|
301
309
|
}
|
|
302
310
|
},
|
|
303
311
|
|
|
304
|
-
pushData(data: IPathCommandData,
|
|
312
|
+
pushData(data: IPathCommandData, strNum: string | number) {
|
|
305
313
|
if (current.index === current.length) { // 单个命令,多个数据的情况
|
|
306
314
|
current.index = 1
|
|
307
315
|
data.push(current.name)
|
|
308
316
|
}
|
|
309
317
|
|
|
310
|
-
data.push(
|
|
318
|
+
data.push(Number(strNum))
|
|
311
319
|
current.index++
|
|
320
|
+
current.dot = 0
|
|
312
321
|
}
|
|
313
322
|
|
|
314
323
|
}
|