@leafer/path 2.1.2 → 2.1.4

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/PathConvert.ts +11 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/path",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "@leafer/path",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/data": "2.1.2",
26
- "@leafer/math": "2.1.2",
27
- "@leafer/debug": "2.1.2"
25
+ "@leafer/data": "2.1.4",
26
+ "@leafer/math": "2.1.4",
27
+ "@leafer/debug": "2.1.4"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "2.1.2"
30
+ "@leafer/interface": "2.1.4"
31
31
  }
32
32
  }
@@ -79,6 +79,10 @@ export const PathConvert = {
79
79
  current.index = 0
80
80
  pushData(data, current.name)
81
81
 
82
+ // m/M命令连续数据需转成l/L: m1 1 2 2m5 5 6 6
83
+ if (char === 'm') current.name = Command['l']
84
+ else if (char === 'M') current.name = Command['L']
85
+
82
86
  if (!needConvert && convertCommand[char]) needConvert = true
83
87
 
84
88
  } else {
@@ -122,12 +126,9 @@ export const PathConvert = {
122
126
  old[i + 1] += x
123
127
  old[i + 2] += y
124
128
  case M:
125
- x = old[i + 1]
126
- y = old[i + 2]
127
-
128
- if (lastCommand === command) data.push(L, x, y) // M command followed by multiple coordinates
129
- else data.push(M, x, y), startX = x, startY = y
130
-
129
+ x = startX = old[i + 1]
130
+ y = startY = old[i + 2]
131
+ data.push(M, x, y)
131
132
  i += 3
132
133
  break
133
134
 
@@ -169,8 +170,8 @@ export const PathConvert = {
169
170
  command = S
170
171
  case S:
171
172
  smooth = (lastCommand === C) || (lastCommand === S)
172
- x1 = smooth ? (x * 2 - controlX) : old[i + 1]
173
- y1 = smooth ? (y * 2 - controlY) : old[i + 2]
173
+ x1 = smooth ? (x * 2 - controlX) : x
174
+ y1 = smooth ? (y * 2 - controlY) : y
174
175
  controlX = old[i + 1]
175
176
  controlY = old[i + 2]
176
177
  x = old[i + 3]
@@ -204,8 +205,8 @@ export const PathConvert = {
204
205
  command = T
205
206
  case T: //smooth
206
207
  smooth = (lastCommand === Q) || (lastCommand === T)
207
- controlX = smooth ? (x * 2 - controlX) : old[i + 1]
208
- controlY = smooth ? (y * 2 - controlY) : old[i + 2]
208
+ controlX = smooth ? (x * 2 - controlX) : x
209
+ controlY = smooth ? (y * 2 - controlY) : y
209
210
  curveMode ? quadraticCurveTo(data, x, y, controlX, controlY, old[i + 1], old[i + 2]) : data.push(Q, controlX, controlY, old[i + 1], old[i + 2])
210
211
  x = old[i + 1]
211
212
  y = old[i + 2]