@behance/helicropter
Advanced tools
Comparing version 15.1.0 to 15.1.1
{ | ||
"name": "@behance/helicropter", | ||
"version": "15.1.0", | ||
"version": "15.1.1", | ||
"description": "My helicropter goes \"whosh whosh whosh\"", | ||
@@ -5,0 +5,0 @@ "main": "src/js/index.js", |
@@ -310,2 +310,5 @@ import extend from '@behance/nbd/util/extend'; | ||
this._canvas = document.createElement('canvas'); | ||
this._ctx = this._canvas.getContext('2d'); | ||
this.relay(this._view, 'controls:enabled controls:disabled image:uploading image:uploaded image:loaded error:upload'); | ||
@@ -319,9 +322,6 @@ }, | ||
getCroppedImage({ width, height }) { | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = width; | ||
canvas.height = height; | ||
this._canvas.width = width; | ||
this._canvas.height = height; | ||
const ctx = canvas.getContext('2d'); | ||
const cropData = this.crop(); | ||
const image = new Image; | ||
@@ -331,8 +331,8 @@ | ||
image.onload = () => { | ||
ctx.drawImage( | ||
this._ctx.drawImage( | ||
image, | ||
cropData.dimensions.x, | ||
cropData.dimensions.y, | ||
width, | ||
height, | ||
cropData.dimensions.width, | ||
cropData.dimensions.height, | ||
0, | ||
@@ -344,3 +344,3 @@ 0, | ||
resolve(canvas.toDataURL('image/png')); | ||
resolve(this._canvas.toDataURL('image/png')); | ||
}; | ||
@@ -347,0 +347,0 @@ |
@@ -157,10 +157,20 @@ import $ from 'jquery'; | ||
const x = 1; | ||
const y = 1; | ||
const width = 1; | ||
const height = 1; | ||
const scaledWidth = 5; | ||
const scaledHeight = 10; | ||
const src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='; | ||
const image = new Image; | ||
image.src = src; | ||
const expectedArg = [x, y, scaledWidth, scaledHeight, 0, 0, width, height]; | ||
spyOn(this.helicropter, 'crop').and.returnValue({ | ||
dimensions: { | ||
x: 1, | ||
y: 1, | ||
x, | ||
y, | ||
width: scaledWidth, | ||
height: scaledHeight, | ||
}, | ||
@@ -170,3 +180,10 @@ src, | ||
spyOn(this.helicropter._ctx, 'drawImage'); | ||
this.helicropter.getCroppedImage({ width, height }).then(result => { | ||
const args = this.helicropter._ctx.drawImage.calls.allArgs()[0].slice(1); | ||
const imageArg = this.helicropter._ctx.drawImage.calls.allArgs()[0][0]; | ||
expect(args).toEqual(expectedArg); | ||
expect(imageArg.src).toEqual(image.src); | ||
expect(result).not.toEqual(src); | ||
@@ -173,0 +190,0 @@ expect(result).toContain('data:image/png;base64'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8659910
4154