@leafer/platform 1.12.2 → 1.12.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 +4 -4
  2. package/src/Platform.ts +7 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/platform",
3
- "version": "1.12.2",
3
+ "version": "1.12.4",
4
4
  "description": "@leafer/platform",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/data": "1.12.2",
26
- "@leafer/debug": "1.12.2"
25
+ "@leafer/data": "1.12.4",
26
+ "@leafer/debug": "1.12.4"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.12.2"
29
+ "@leafer/interface": "1.12.4"
30
30
  }
31
31
  }
package/src/Platform.ts CHANGED
@@ -33,11 +33,13 @@ export const Platform: IPlatform = {
33
33
  const ctx: ICanvasContext2D = canvas.getContext('2d')
34
34
  if (opacity) ctx.globalAlpha = opacity
35
35
  ctx.imageSmoothingEnabled = smooth === false ? false : true // 平滑绘制
36
- if (clip) {
37
- const scaleX = width / clip.width, scaleY = height / clip.height
38
- ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY)
39
- ctx.drawImage(image, 0, 0, image.width, image.height)
40
- } else ctx.drawImage(image, 0, 0, width, height)
36
+ if (image) {
37
+ if (clip) {
38
+ const scaleX = width / clip.width, scaleY = height / clip.height
39
+ ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY)
40
+ ctx.drawImage(image, 0, 0, image.width, image.height)
41
+ } else ctx.drawImage(image, 0, 0, width, height)
42
+ }
41
43
  return canvas
42
44
  },
43
45
  setPatternTransform(pattern: ICanvasPattern, transform?: IMatrixData, paint?: ILeaferImagePatternPaint): void {