@leafer/canvas 1.0.0-alpha.30 → 1.0.0-alpha.31

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/canvas",
3
- "version": "1.0.0-alpha.30",
3
+ "version": "1.0.0-alpha.31",
4
4
  "description": "@leafer/canvas",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,9 +19,9 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/list": "1.0.0-alpha.30"
22
+ "@leafer/list": "1.0.0-alpha.31"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-alpha.30"
25
+ "@leafer/interface": "1.0.0-alpha.31"
26
26
  }
27
27
  }
package/src/Canvas.ts CHANGED
@@ -30,7 +30,6 @@ export class Canvas implements ICanvasAttr {
30
30
 
31
31
  public context: ICanvasContext2D
32
32
 
33
-
34
33
  // canvas attr
35
34
 
36
35
  @contextAttr('imageSmoothingEnabled')
@@ -6,7 +6,6 @@ import { DataHelper } from '@leafer/data'
6
6
  import { Canvas } from './Canvas'
7
7
 
8
8
 
9
-
10
9
  const temp = new Bounds()
11
10
  const minSize: IScreenSizeData = { width: 1, height: 1, pixelRatio: 1 }
12
11
 
@@ -40,7 +39,9 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
40
39
 
41
40
  public recycled?: boolean
42
41
 
43
- protected savedblendMode: string
42
+ public worldTransform: IMatrixData = {} as IMatrixData
43
+
44
+ protected savedBlendMode: string
44
45
 
45
46
  constructor(config?: ILeaferCanvasConfig, manager?: ICanvasManager) {
46
47
  super()
@@ -97,46 +98,43 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
97
98
 
98
99
  public setWorld(matrix: IMatrixData, parentMatrix?: IMatrixData, onlyTranslate?: boolean): void {
99
100
  const { pixelRatio } = this
101
+ const w = this.worldTransform
100
102
  if (parentMatrix) {
101
103
 
102
104
  if (onlyTranslate) {
103
105
  this.setTransform(
104
- matrix.a * pixelRatio,
105
- matrix.b * pixelRatio,
106
- matrix.c * pixelRatio,
107
- matrix.d * pixelRatio,
108
- (matrix.e + parentMatrix.e) * pixelRatio,
109
- (matrix.f + parentMatrix.f) * pixelRatio
106
+ w.a = matrix.a * pixelRatio,
107
+ w.b = matrix.b * pixelRatio,
108
+ w.c = matrix.c * pixelRatio,
109
+ w.d = matrix.d * pixelRatio,
110
+ w.e = (matrix.e + parentMatrix.e) * pixelRatio,
111
+ w.f = (matrix.f + parentMatrix.f) * pixelRatio
110
112
  )
111
113
  } else {
112
114
  const { a, b, c, d, e, f } = parentMatrix
113
115
  this.setTransform(
114
- ((matrix.a * a) + (matrix.b * c)) * pixelRatio,
115
- ((matrix.a * b) + (matrix.b * d)) * pixelRatio,
116
- ((matrix.c * a) + (matrix.d * c)) * pixelRatio,
117
- ((matrix.c * b) + (matrix.d * d)) * pixelRatio,
118
- (((matrix.e * a) + (matrix.f * c) + e)) * pixelRatio,
119
- (((matrix.e * b) + (matrix.f * d) + f)) * pixelRatio
116
+ w.a = ((matrix.a * a) + (matrix.b * c)) * pixelRatio,
117
+ w.b = ((matrix.a * b) + (matrix.b * d)) * pixelRatio,
118
+ w.c = ((matrix.c * a) + (matrix.d * c)) * pixelRatio,
119
+ w.d = ((matrix.c * b) + (matrix.d * d)) * pixelRatio,
120
+ w.e = (((matrix.e * a) + (matrix.f * c) + e)) * pixelRatio,
121
+ w.f = (((matrix.e * b) + (matrix.f * d) + f)) * pixelRatio
120
122
  )
121
123
  }
122
124
 
123
125
  } else {
124
126
 
125
127
  this.setTransform(
126
- matrix.a * pixelRatio,
127
- matrix.b * pixelRatio,
128
- matrix.c * pixelRatio,
129
- matrix.d * pixelRatio,
130
- matrix.e * pixelRatio,
131
- matrix.f * pixelRatio
128
+ w.a = matrix.a * pixelRatio,
129
+ w.b = matrix.b * pixelRatio,
130
+ w.c = matrix.c * pixelRatio,
131
+ w.d = matrix.d * pixelRatio,
132
+ w.e = matrix.e * pixelRatio,
133
+ w.f = matrix.f * pixelRatio
132
134
  )
133
135
  }
134
136
  }
135
137
 
136
- public useSameTransform(canvas: ILeaferCanvas): void {
137
- this.setTransform(canvas.getTransform())
138
- }
139
-
140
138
  public setStroke(color: string | object, strokeWidth: number, options?: ICanvasStrokeOptions): void {
141
139
  if (strokeWidth) this.strokeWidth = strokeWidth
142
140
  if (color) this.strokeStyle = color
@@ -152,12 +150,12 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
152
150
  }
153
151
 
154
152
  public saveBlendMode(blendMode: string): void {
155
- this.savedblendMode = this.blendMode
153
+ this.savedBlendMode = this.blendMode
156
154
  this.blendMode = blendMode
157
155
  }
158
156
 
159
157
  public restoreBlendMode(): void {
160
- this.blendMode = this.savedblendMode
158
+ this.blendMode = this.savedBlendMode
161
159
  }
162
160
 
163
161
  public hitFill(point: IPointData, fillRule?: IWindingRule): boolean {
@@ -193,7 +191,7 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
193
191
  } else {
194
192
  this.drawImage(canvas.view as HTMLCanvasElement, 0, 0)
195
193
  }
196
- if (blendMode) this.blendMode = 'normal'
194
+ if (blendMode) this.blendMode = 'source-over'
197
195
  }
198
196
 
199
197
  public copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: string): void {
@@ -207,7 +205,7 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
207
205
  const { pixelRatio } = this
208
206
  this.drawImage(canvas.view as HTMLCanvasElement, fromWorld.x * pixelRatio, fromWorld.y * pixelRatio, fromWorld.width * pixelRatio, fromWorld.height * pixelRatio, toInnerBounds.x, toInnerBounds.y, toInnerBounds.width, toInnerBounds.height)
209
207
  }
210
- if (blendMode) this.blendMode = 'normal'
208
+ if (blendMode) this.blendMode = 'source-over'
211
209
  }
212
210
 
213
211
  public useMask(maskCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void {
@@ -219,7 +217,7 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
219
217
  this.fillStyle = color
220
218
  temp.copy(bounds).scale(this.pixelRatio)
221
219
  this.fillRect(temp.x, temp.y, temp.width, temp.height)
222
- if (blendMode) this.blendMode = 'normal'
220
+ if (blendMode) this.blendMode = 'source-over'
223
221
  }
224
222
 
225
223
  public strokeWorld(bounds: IBoundsData, color: string | object, blendMode?: string): void {
@@ -227,7 +225,7 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
227
225
  this.strokeStyle = color
228
226
  temp.copy(bounds).scale(this.pixelRatio)
229
227
  this.strokeRect(temp.x, temp.y, temp.width, temp.height)
230
- if (blendMode) this.blendMode = 'normal'
228
+ if (blendMode) this.blendMode = 'source-over'
231
229
  }
232
230
 
233
231
  public clearWorld(bounds: IBoundsData, ceilPixel?: boolean): void {
@@ -258,14 +256,19 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
258
256
  }
259
257
 
260
258
  // 需要有 manager变量
261
- public getSameCanvas(useSameTransform?: boolean): ILeaferCanvas {
259
+ public getSameCanvas(useSameWorldTransform?: boolean): ILeaferCanvas {
262
260
  const { width, height, pixelRatio } = this
263
261
 
264
262
  const options = { width, height, pixelRatio }
265
263
  const canvas = this.manager ? this.manager.get(options) : Creator.canvas(options)
266
264
 
267
265
  canvas.save()
268
- if (useSameTransform) canvas.useSameTransform(this)
266
+
267
+ if (useSameWorldTransform) {
268
+ const w = this.worldTransform
269
+ canvas.setTransform(w.a, w.b, w.c, w.d, w.e, w.f)
270
+ }
271
+
269
272
  return canvas
270
273
  }
271
274