Socket
Socket
Sign inDemoInstall

ctx-polyfill

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.2

ctx-polyfill.min.js

112

ctx-polyfill.js

@@ -13,10 +13,4 @@ (function() {

var CanvasRenderingContext2DHelper = {};
CanvasRenderingContext2DHelper.createSVGMatrix = function() {
return document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGMatrix();
};
CanvasRenderingContext2DHelper.arrayToSVGMatrix = function(array) {
var matrix = CanvasRenderingContext2DHelper.createSVGMatrix();
var arrayToSVGMatrix = function(array) {
var matrix = document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGMatrix();
matrix.a = array[0];

@@ -31,17 +25,14 @@ matrix.b = array[1];

CanvasRenderingContext2DHelper.svgMatrixToArray = function(matrix) {
return [
matrix.a,
matrix.b,
matrix.c,
matrix.d,
matrix.e,
matrix.f
];
};
CanvasRenderingContext2DHelper.createIdentityMatrix = function() {
return [ 1, 0, 0, 1, 0, 0 ];
};
// var svgMatrixToArray = function(matrix) {
// return [
// matrix.a,
// matrix.b,
// matrix.c,
// matrix.d,
// matrix.e,
// matrix.f
// ];
// };
if(!('currentTransform' in CanvasRenderingContext2D.prototype)) {

@@ -61,10 +52,9 @@ if('mozCurrentTransform' in CanvasRenderingContext2D.prototype) {

CanvasRenderingContext2DHelper.getContext = HTMLCanvasElement.prototype.getContext;
var getContext = HTMLCanvasElement.prototype.getContext;
HTMLCanvasElement.prototype.getContext = function(contextType, contextAttributes) {
var context = CanvasRenderingContext2DHelper.getContext.call(this, contextType, contextAttributes);
var context = getContext.call(this, contextType, contextAttributes);
switch(contextType) {
case '2d':
context._transformStack = [];
context._transformMatrix = CanvasRenderingContext2DHelper.createIdentityMatrix();
context._transformMatrix = [ 1, 0, 0, 1, 0, 0 ];
break;

@@ -89,3 +79,3 @@ }

CanvasRenderingContext2DHelper.translate = CanvasRenderingContext2D.prototype.translate;
var translate = CanvasRenderingContext2D.prototype.translate;
CanvasRenderingContext2D.prototype.translate = function(x, y) {

@@ -95,6 +85,6 @@ var matrix = this._transformMatrix;

matrix[5] = matrix[1] * x + matrix[3] * y + matrix[5];
CanvasRenderingContext2DHelper.translate.call(this, x, y);
translate.call(this, x, y);
};
CanvasRenderingContext2DHelper.scale = CanvasRenderingContext2D.prototype.scale;
var scale = CanvasRenderingContext2D.prototype.scale;
CanvasRenderingContext2D.prototype.scale = function(x, y) {

@@ -106,6 +96,6 @@ var matrix = this._transformMatrix;

matrix[3] *= y;
CanvasRenderingContext2DHelper.scale.call(this, x, y);
scale.call(this, x, y);
};
CanvasRenderingContext2DHelper.rotate = CanvasRenderingContext2D.prototype.rotate;
var rotate = CanvasRenderingContext2D.prototype.rotate;
CanvasRenderingContext2D.prototype.rotate = function(angle) {

@@ -125,6 +115,6 @@ var cosValue = Math.cos(angle);

CanvasRenderingContext2DHelper.rotate.call(this, angle);
rotate.call(this, angle);
};
CanvasRenderingContext2DHelper.transform = CanvasRenderingContext2D.prototype.transform;
var transform = CanvasRenderingContext2D.prototype.transform;
CanvasRenderingContext2D.prototype.transform = function(a, b, c, d, e, f) {

@@ -140,19 +130,19 @@ var matrix = this._transformMatrix;

];
CanvasRenderingContext2DHelper.transform.call(this, a, b, c, d, e, f);
transform.call(this, a, b, c, d, e, f);
};
CanvasRenderingContext2DHelper.setTransform = CanvasRenderingContext2D.prototype.setTransform ;
var setTransform = CanvasRenderingContext2D.prototype.setTransform ;
CanvasRenderingContext2D.prototype.setTransform = function(a, b, c, d, e, f) {
this._transformMatrix = [a, b, c, d, e, f];
CanvasRenderingContext2DHelper.transform.setTransform(this, a, b, c, d, e, f);
transform.setTransform(this, a, b, c, d, e, f);
};
CanvasRenderingContext2DHelper.save = CanvasRenderingContext2D.prototype.save;
var save = CanvasRenderingContext2D.prototype.save;
CanvasRenderingContext2D.prototype.save = function() {
this._transformStack.push(this._transformMatrix);
this._transformMatrix = this._transformMatrix.slice(0, 6); // copy
CanvasRenderingContext2DHelper.save.call(this);
save.call(this);
};
CanvasRenderingContext2DHelper.restore = CanvasRenderingContext2D.prototype.restore;
var restore = CanvasRenderingContext2D.prototype.restore;
CanvasRenderingContext2D.prototype.restore = function() {

@@ -163,3 +153,3 @@ var matrix = this._transformStack.pop();

}
CanvasRenderingContext2DHelper.restore.call(this);
restore.call(this);
};

@@ -197,3 +187,3 @@

if(!('resetTransform' in CanvasRenderingContext2D.prototype)) {
CanvasRenderingContext2D.prototype.resetTransform = function() {
CanvasRenderingContext2D.prototype.resetTransform = function() {
this.setTransform(1, 0, 0, 1, 0, 0);

@@ -203,3 +193,41 @@ };

CanvasRenderingContext2D.arrayToSVGMatrix = CanvasRenderingContext2DHelper.arrayToSVGMatrix;
if(!('imageSmoothingEnabled' in CanvasRenderingContext2D.prototype)) {
Object.defineProperty(CanvasRenderingContext2D.prototype, 'imageSmoothingEnabled', {
get: function () {
if(this.mozImageSmoothingEnabled !== void 0) {
return this.mozImageSmoothingEnabled;
} else if(this.webkitImageSmoothingEnabled !== void 0) {
return this.webkitImageSmoothingEnabled;
} else if(this.msImageSmoothingEnabled !== void 0) {
return this.msImageSmoothingEnabled;
} else {
return true;
}
},
set: function(enable) {
if(this.mozImageSmoothingEnabled !== void 0) {
this.mozImageSmoothingEnabled = enable;
} else if(this.webkitImageSmoothingEnabled !== void 0) {
this.webkitImageSmoothingEnabled = enable;
} else if(this.msImageSmoothingEnabled !== void 0) {
this.msImageSmoothingEnabled = enable;
}
},
enumerable: true,
configurable: true
});
// document.body.innerHTML = '';
// canvas = document.createElement('canvas');
// document.body.appendChild(canvas);
// canvas.width = 200;
// canvas.height = 200;
// ctx = canvas.getContext('2d');
//
// console.log(ctx.imageSmoothingEnabled);
}
CanvasRenderingContext2D.arrayToSVGMatrix = arrayToSVGMatrix;
})();
{
"name": "ctx-polyfill",
"version": "1.0.0",
"version": "1.0.2",
"description": "Polyfill CanvasRenderingContext2D : currentTransform, resetTransform",
"main": "ctx-polyfill.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "uglifyjs ctx-polyfill.js --stats -m -o ctx-polyfill.min.js"
},

@@ -14,3 +14,6 @@ "repository": {

"author": "valentin",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"uglify-js": "^2.7.5"
}
}

@@ -14,2 +14,3 @@ ### Polyfill CanvasRenderingContext2D to match last ES7 specifications

- [resetTransform](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/resetTransform) : resets the current transform by the identity matrix.
- [imageSmoothingEnabled](https://developer.mozilla.org/fr/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled) : enable or disabled image Smoothing

@@ -16,0 +17,0 @@ #### Helper

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc