Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dommatrix

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dommatrix - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3-a

2

dist/dommatrix.esm.js
/*!
* DOMMatrix v0.0.2 (https://github.com/thednp/dommatrix)
* DOMMatrix v0.0.3a (https://github.com/thednp/dommatrix)
* Copyright 2020 © thednp

@@ -4,0 +4,0 @@ * Licensed under MIT (https://github.com/thednp/DOMMatrix/blob/master/LICENSE)

@@ -1,2 +0,2 @@

// DOMMatrix v0.0.2 | thednp © 2020 | MIT-License
// DOMMatrix v0.0.3a | thednp © 2020 | MIT-License
function m(m,n){var i=n.m11*m.m11+n.m12*m.m21+n.m13*m.m31+n.m14*m.m41,e=n.m11*m.m12+n.m12*m.m22+n.m13*m.m32+n.m14*m.m42,r=n.m11*m.m13+n.m12*m.m23+n.m13*m.m33+n.m14*m.m43,a=n.m11*m.m14+n.m12*m.m24+n.m13*m.m34+n.m14*m.m44,s=n.m21*m.m11+n.m22*m.m21+n.m23*m.m31+n.m24*m.m41,o=n.m21*m.m12+n.m22*m.m22+n.m23*m.m32+n.m24*m.m42,u=n.m21*m.m13+n.m22*m.m23+n.m23*m.m33+n.m24*m.m43,h=n.m21*m.m14+n.m22*m.m24+n.m23*m.m34+n.m24*m.m44,l=n.m31*m.m11+n.m32*m.m21+n.m33*m.m31+n.m34*m.m41,f=n.m31*m.m12+n.m32*m.m22+n.m33*m.m32+n.m34*m.m42,c=n.m31*m.m13+n.m32*m.m23+n.m33*m.m33+n.m34*m.m43,p=n.m31*m.m14+n.m32*m.m24+n.m33*m.m34+n.m34*m.m44,d=n.m41*m.m11+n.m42*m.m21+n.m43*m.m31+n.m44*m.m41,y=n.m41*m.m12+n.m42*m.m22+n.m43*m.m32+n.m44*m.m42,M=n.m41*m.m13+n.m42*m.m23+n.m43*m.m33+n.m44*m.m43,v=n.m41*m.m14+n.m42*m.m24+n.m43*m.m34+n.m44*m.m44;return new t(i,e,r,a,s,o,u,h,l,f,c,p,d,y,M,v)}var t=function(){var m=[].slice.call(arguments),t=this;if(m.length)for(var n=m.length;n--;)Math.abs(m[n])<1e-6&&(m[n]=0);if(t.setIdentity(),16==m.length)t.is2D=!1,t.isIdentity=!1,t.m11=t.a=m[0],t.m12=t.b=m[1],t.m13=m[2],t.m14=m[3],t.m21=t.c=m[4],t.m22=t.d=m[5],t.m23=m[6],t.m24=m[7],t.m31=m[8],t.m32=m[9],t.m33=m[10],t.m34=m[11],t.m41=t.e=m[12],t.m42=t.f=m[13],t.m43=m[14],t.m44=m[15];else if(6==m.length)t.is2D=!0,t.isIdentity=!1,t.m11=t.a=m[0],t.m12=t.b=m[1],t.m14=t.e=m[4],t.m21=t.c=m[2],t.m22=t.d=m[3],t.m24=t.f=m[5];else if(1===m.length&&"string"==typeof m[0])t.setMatrixValue(m[0]);else if(m.length>0)throw new TypeError("Invalid Matrix Value")};t.prototype.setMatrixValue=function(m){m=String(m).trim();var t=this;if(t.setIdentity(),"none"==m)return t;var n,i,e=m.slice(0,m.indexOf("("));if("matrix3d"==e){for(t.is2D=!1,t.isIdentity=!1,i=(n=m.slice(9,-1).split(",")).length;i--;)n[i]=+n[i];t.m11=t.a=n[0],t.m12=t.b=n[1],t.m13=n[2],t.m14=n[3],t.m21=t.c=n[4],t.m22=t.d=n[5],t.m23=n[6],t.m24=n[7],t.m31=n[8],t.m32=n[9],t.m33=n[10],t.m34=n[11],t.m41=t.e=n[12],t.m42=t.f=n[13],t.m43=n[14],t.m44=n[15]}else{if("matrix"!=e)throw new TypeError("Invalid Matrix Value");for(t.is2D=!0,t.isIdentity=!1,i=(n=m.slice(7,-1).split(",")).length;i--;)n[i]=+n[i];t.m11=t.a=n[0],t.m12=t.b=n[2],t.m41=t.e=n[4],t.m21=t.c=n[1],t.m22=t.d=n[3],t.m42=t.f=n[5]}return t},t.prototype.multiply=function(t){return m(this,t)},t.prototype.translate=function(n,i,e){return null==e&&(e=0),null==i&&(i=0),0!==this.m34&&e&&(this.is2D=!1),m(this,function(m,n,i){var e=new t;return e.m41=e.e=m,e.m42=e.f=n,e.m43=i,e}(n,i,e))},t.prototype.scale=function(n,i,e){return null==i&&(i=n),null==e&&(e=1),0!==this.m34&&(n!==i||n!==e||i!==e)&&(this.is2D=!1),m(this,function(m,n,i){var e=new t;return e.m11=e.a=m,e.m22=e.d=n,e.m33=i,e}(n,i,e))},t.prototype.rotate=function(n,i,e){return null==i&&(i=n),null==e&&(e=n),0!==this.m34&&(n||i)&&(this.is2D=!1),m(this,function(m,n,i){m*=Math.PI/180,n*=Math.PI/180,i*=Math.PI/180;var e=Math.cos(m),r=-Math.sin(m),a=Math.cos(n),s=-Math.sin(n),o=Math.cos(i),u=-Math.sin(i),h=new t;return h.m11=h.a=a*o,h.m12=h.b=-a*u,h.m13=s,h.m21=h.c=r*s*o+e*u,h.m22=h.d=e*o-r*s*u,h.m23=-r*a,h.m31=r*u-e*s*o,h.m32=r*o+e*s*u,h.m33=e*a,h}(n,i,e))},t.prototype.rotateAxisAngle=function(n,i,e,r){return 0!==this.m34&&(n||i)&&(this.is2D=!1),null==i&&(i=n),null==e&&(e=n),m(this,function(m,n,i,e){e*=Math.PI/360;var r=Math.sin(e),a=Math.cos(e),s=r*r,o=Math.sqrt(m*m+n*n+i*i);0===o?(m=0,n=0,i=1):(m/=o,n/=o,i/=o);var u=m*m,h=n*n,l=i*i,f=new t;return f.m11=f.a=1-2*(h+l)*s,f.m12=f.b=2*(m*n*s+i*r*a),f.m13=2*(m*i*s-n*r*a),f.m21=f.c=2*(n*m*s-i*r*a),f.m22=f.d=1-2*(l+u)*s,f.m23=2*(n*i*s+m*r*a),f.m31=2*(i*m*s+n*r*a),f.m32=2*(i*n*s-m*r*a),f.m33=1-2*(u+h)*s,f.m14=f.m24=f.m34=0,f.m41=f.e=f.m42=f.f=f.m43=0,f.m44=1,f}(n,i,e,r))},t.prototype.skewX=function(n){return m(this,function(m){m*=Math.PI/180;var n=new t;return n.m21=n.c=Math.tan(m),n}(n))},t.prototype.skewY=function(n){return m(this,function(m){m*=Math.PI/180;var n=new t;return n.m12=n.b=Math.tan(m),n}(n))},t.prototype.toString=function(){var m=this;return m.is2D?"matrix("+[m.a,m.b,m.c,m.d,m.e,m.f].join(", ")+")":"matrix3d("+[m.m11,m.m12,m.m13,m.m14,m.m21,m.m22,m.m23,m.m24,m.m31,m.m32,m.m33,m.m34,m.m41,m.m42,m.m43,m.m44].join(", ")+")"},t.prototype.setIdentity=function(){var m=this;return m.is2D=!0,m.isIdentity=!0,m.m11=m.a=1,m.m12=m.b=0,m.m13=0,m.m14=0,m.m21=m.c=0,m.m22=m.d=1,m.m23=0,m.m24=0,m.m31=0,m.m32=0,m.m33=1,m.m34=0,m.m41=m.e=0,m.m42=m.f=0,m.m43=0,m.m44=1,this};export default t;
/*!
* DOMMatrix v0.0.2 (https://github.com/thednp/dommatrix)
* DOMMatrix v0.0.3a (https://github.com/thednp/dommatrix)
* Copyright 2020 © thednp

@@ -4,0 +4,0 @@ * Licensed under MIT (https://github.com/thednp/DOMMatrix/blob/master/LICENSE)

@@ -1,2 +0,2 @@

// DOMMatrix v0.0.2 | thednp © 2020 | MIT-License
// DOMMatrix v0.0.3a | thednp © 2020 | MIT-License
!function(m,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(m="undefined"!=typeof globalThis?globalThis:m||self).CSSMatrix=t()}(this,(function(){"use strict";function m(m,n){var e=n.m11*m.m11+n.m12*m.m21+n.m13*m.m31+n.m14*m.m41,i=n.m11*m.m12+n.m12*m.m22+n.m13*m.m32+n.m14*m.m42,r=n.m11*m.m13+n.m12*m.m23+n.m13*m.m33+n.m14*m.m43,s=n.m11*m.m14+n.m12*m.m24+n.m13*m.m34+n.m14*m.m44,o=n.m21*m.m11+n.m22*m.m21+n.m23*m.m31+n.m24*m.m41,a=n.m21*m.m12+n.m22*m.m22+n.m23*m.m32+n.m24*m.m42,u=n.m21*m.m13+n.m22*m.m23+n.m23*m.m33+n.m24*m.m43,l=n.m21*m.m14+n.m22*m.m24+n.m23*m.m34+n.m24*m.m44,f=n.m31*m.m11+n.m32*m.m21+n.m33*m.m31+n.m34*m.m41,h=n.m31*m.m12+n.m32*m.m22+n.m33*m.m32+n.m34*m.m42,c=n.m31*m.m13+n.m32*m.m23+n.m33*m.m33+n.m34*m.m43,d=n.m31*m.m14+n.m32*m.m24+n.m33*m.m34+n.m34*m.m44,p=n.m41*m.m11+n.m42*m.m21+n.m43*m.m31+n.m44*m.m41,y=n.m41*m.m12+n.m42*m.m22+n.m43*m.m32+n.m44*m.m42,M=n.m41*m.m13+n.m42*m.m23+n.m43*m.m33+n.m44*m.m43,v=n.m41*m.m14+n.m42*m.m24+n.m43*m.m34+n.m44*m.m44;return new t(e,i,r,s,o,a,u,l,f,h,c,d,p,y,M,v)}var t=function(){var m=[].slice.call(arguments),t=this;if(m.length)for(var n=m.length;n--;)Math.abs(m[n])<1e-6&&(m[n]=0);if(t.setIdentity(),16==m.length)t.is2D=!1,t.isIdentity=!1,t.m11=t.a=m[0],t.m12=t.b=m[1],t.m13=m[2],t.m14=m[3],t.m21=t.c=m[4],t.m22=t.d=m[5],t.m23=m[6],t.m24=m[7],t.m31=m[8],t.m32=m[9],t.m33=m[10],t.m34=m[11],t.m41=t.e=m[12],t.m42=t.f=m[13],t.m43=m[14],t.m44=m[15];else if(6==m.length)t.is2D=!0,t.isIdentity=!1,t.m11=t.a=m[0],t.m12=t.b=m[1],t.m14=t.e=m[4],t.m21=t.c=m[2],t.m22=t.d=m[3],t.m24=t.f=m[5];else if(1===m.length&&"string"==typeof m[0])t.setMatrixValue(m[0]);else if(m.length>0)throw new TypeError("Invalid Matrix Value")};return t.prototype.setMatrixValue=function(m){m=String(m).trim();var t=this;if(t.setIdentity(),"none"==m)return t;var n,e,i=m.slice(0,m.indexOf("("));if("matrix3d"==i){for(t.is2D=!1,t.isIdentity=!1,e=(n=m.slice(9,-1).split(",")).length;e--;)n[e]=+n[e];t.m11=t.a=n[0],t.m12=t.b=n[1],t.m13=n[2],t.m14=n[3],t.m21=t.c=n[4],t.m22=t.d=n[5],t.m23=n[6],t.m24=n[7],t.m31=n[8],t.m32=n[9],t.m33=n[10],t.m34=n[11],t.m41=t.e=n[12],t.m42=t.f=n[13],t.m43=n[14],t.m44=n[15]}else{if("matrix"!=i)throw new TypeError("Invalid Matrix Value");for(t.is2D=!0,t.isIdentity=!1,e=(n=m.slice(7,-1).split(",")).length;e--;)n[e]=+n[e];t.m11=t.a=n[0],t.m12=t.b=n[2],t.m41=t.e=n[4],t.m21=t.c=n[1],t.m22=t.d=n[3],t.m42=t.f=n[5]}return t},t.prototype.multiply=function(t){return m(this,t)},t.prototype.translate=function(n,e,i){return null==i&&(i=0),null==e&&(e=0),0!==this.m34&&i&&(this.is2D=!1),m(this,function(m,n,e){var i=new t;return i.m41=i.e=m,i.m42=i.f=n,i.m43=e,i}(n,e,i))},t.prototype.scale=function(n,e,i){return null==e&&(e=n),null==i&&(i=1),0!==this.m34&&(n!==e||n!==i||e!==i)&&(this.is2D=!1),m(this,function(m,n,e){var i=new t;return i.m11=i.a=m,i.m22=i.d=n,i.m33=e,i}(n,e,i))},t.prototype.rotate=function(n,e,i){return null==e&&(e=n),null==i&&(i=n),0!==this.m34&&(n||e)&&(this.is2D=!1),m(this,function(m,n,e){m*=Math.PI/180,n*=Math.PI/180,e*=Math.PI/180;var i=Math.cos(m),r=-Math.sin(m),s=Math.cos(n),o=-Math.sin(n),a=Math.cos(e),u=-Math.sin(e),l=new t;return l.m11=l.a=s*a,l.m12=l.b=-s*u,l.m13=o,l.m21=l.c=r*o*a+i*u,l.m22=l.d=i*a-r*o*u,l.m23=-r*s,l.m31=r*u-i*o*a,l.m32=r*a+i*o*u,l.m33=i*s,l}(n,e,i))},t.prototype.rotateAxisAngle=function(n,e,i,r){return 0!==this.m34&&(n||e)&&(this.is2D=!1),null==e&&(e=n),null==i&&(i=n),m(this,function(m,n,e,i){i*=Math.PI/360;var r=Math.sin(i),s=Math.cos(i),o=r*r,a=Math.sqrt(m*m+n*n+e*e);0===a?(m=0,n=0,e=1):(m/=a,n/=a,e/=a);var u=m*m,l=n*n,f=e*e,h=new t;return h.m11=h.a=1-2*(l+f)*o,h.m12=h.b=2*(m*n*o+e*r*s),h.m13=2*(m*e*o-n*r*s),h.m21=h.c=2*(n*m*o-e*r*s),h.m22=h.d=1-2*(f+u)*o,h.m23=2*(n*e*o+m*r*s),h.m31=2*(e*m*o+n*r*s),h.m32=2*(e*n*o-m*r*s),h.m33=1-2*(u+l)*o,h.m14=h.m24=h.m34=0,h.m41=h.e=h.m42=h.f=h.m43=0,h.m44=1,h}(n,e,i,r))},t.prototype.skewX=function(n){return m(this,function(m){m*=Math.PI/180;var n=new t;return n.m21=n.c=Math.tan(m),n}(n))},t.prototype.skewY=function(n){return m(this,function(m){m*=Math.PI/180;var n=new t;return n.m12=n.b=Math.tan(m),n}(n))},t.prototype.toString=function(){var m=this;return m.is2D?"matrix("+[m.a,m.b,m.c,m.d,m.e,m.f].join(", ")+")":"matrix3d("+[m.m11,m.m12,m.m13,m.m14,m.m21,m.m22,m.m23,m.m24,m.m31,m.m32,m.m33,m.m34,m.m41,m.m42,m.m43,m.m44].join(", ")+")"},t.prototype.setIdentity=function(){var m=this;return m.is2D=!0,m.isIdentity=!0,m.m11=m.a=1,m.m12=m.b=0,m.m13=0,m.m14=0,m.m21=m.c=0,m.m22=m.d=1,m.m23=0,m.m24=0,m.m31=0,m.m32=0,m.m33=1,m.m34=0,m.m41=m.e=0,m.m42=m.f=0,m.m43=0,m.m44=1,this},t}));
{
"name": "dommatrix",
"version": "0.0.2",
"version": "0.0.3a",
"description": "ES6/ES7 shim for DOMMatrix",

@@ -10,3 +10,2 @@ "main": "dist/dommatrix.min.js",

"dist/*.{js,map}",
"src/**/*.{js,map}",
"src/*.{js,map}"

@@ -13,0 +12,0 @@ ],

# DOMMatrix (Constructor) shim
An ES6/ES7 sourced [DOMMatrix](https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix) shim for Node.js apps and legacy browsers originally authored by Arian Stolwijk with his [CSSMatrix](https://github.com/arian/CSSMatrix/).
An ES6/ES7 sourced [DOMMatrix](https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix) shim for Node.js apps and legacy browsers originally authored by Arian Stolwijk with his [CSSMatrix](https://github.com/arian/CSSMatrix/). The constructor should work as defined by the [W3C CSS3 3D Transforms](http://www.w3.org/TR/2011/WD-css3-2d-transforms-20111215/#cssmatrix-interface) specification.
The constructor should work as defined by the [w3c CSS3 3d Transforms](http://www.w3.org/TR/2011/WD-css3-2d-transforms-20111215/#cssmatrix-interface) specification.
This version comes with the following changes:
* removed `afine` property and replaced it with `is2D` to be more inline with DOMMatrix
* added `isIdentity` property
* removed inverse() instance method
* removed transform() instance method
* removed toFullString() instance method
* while applying methods the above properties change
* fixed the `translate()` instance method to work with one axis transformation, also inline with DOMMatrix
* removed `inverse()` instance method
* removed `transform()` instance method
* removed `toFullString()` instance method

@@ -14,0 +14,0 @@

@@ -1,3 +0,409 @@

import CSSMatrix from './DOMMatrix.js'
/**
* DOMMatrix (Constructor) shim
* @constructor
* Arian Stolwijk @ https://github.com/arian/CSSMatrix/
* http://www.w3.org/TR/css3-3d-transforms/#cssmatrix-interface
* http://www.w3.org/TR/css3-2d-transforms/#cssmatrix-interface
*
* ES6 version by thednp
* https://github.com/thednp/DOMMatrix/
*/
export default CSSMatrix
// Transform Functions
// http://en.wikipedia.org/wiki/Rotation_matrix
function Rotate(rx, ry, rz){
rx *= Math.PI / 180;
ry *= Math.PI / 180;
rz *= Math.PI / 180;
// minus sin() because of right-handed system
let cosx = Math.cos(rx), sinx = - Math.sin(rx);
let cosy = Math.cos(ry), siny = - Math.sin(ry);
let cosz = Math.cos(rz), sinz = - Math.sin(rz);
let m = new CSSMatrix();
m.m11 = m.a = cosy * cosz;
m.m12 = m.b = - cosy * sinz;
m.m13 = siny;
m.m21 = m.c = sinx * siny * cosz + cosx * sinz;
m.m22 = m.d = cosx * cosz - sinx * siny * sinz;
m.m23 = - sinx * cosy;
m.m31 = sinx * sinz - cosx * siny * cosz;
m.m32 = sinx * cosz + cosx * siny * sinz;
m.m33 = cosx * cosy;
return m
}
function RotateAxisAngle(x, y, z, angle){
angle *= Math.PI / 360;
let sinA = Math.sin(angle), cosA = Math.cos(angle), sinA2 = sinA * sinA;
let length = Math.sqrt(x * x + y * y + z * z);
if (length === 0){
// bad vector length, use something reasonable
x = 0;
y = 0;
z = 1;
} else {
x /= length;
y /= length;
z /= length;
}
let x2 = x * x, y2 = y * y, z2 = z * z;
let m = new CSSMatrix();
m.m11 = m.a = 1 - 2 * (y2 + z2) * sinA2;
m.m12 = m.b = 2 * (x * y * sinA2 + z * sinA * cosA);
m.m13 = 2 * (x * z * sinA2 - y * sinA * cosA);
m.m21 = m.c = 2 * (y * x * sinA2 - z * sinA * cosA);
m.m22 = m.d = 1 - 2 * (z2 + x2) * sinA2;
m.m23 = 2 * (y * z * sinA2 + x * sinA * cosA);
m.m31 = 2 * (z * x * sinA2 + y * sinA * cosA);
m.m32 = 2 * (z * y * sinA2 - x * sinA * cosA);
m.m33 = 1 - 2 * (x2 + y2) * sinA2;
m.m14 = m.m24 = m.m34 = 0;
m.m41 = m.e = m.m42 = m.f = m.m43 = 0;
m.m44 = 1;
return m
}
// function ScaleX(x){
// let m = new CSSMatrix();
// m.m11 = m.a = x;
// return m
// }
// function ScaleY(y){
// let m = new CSSMatrix();
// m.m22 = m.d = y;
// return m
// }
// function ScaleZ(z){
// let m = new CSSMatrix();
// m.m33 = z;
// return m
// }
function Scale(x, y, z){
let m = new CSSMatrix();
m.m11 = m.a = x;
m.m22 = m.d = y;
m.m33 = z;
return m
}
function SkewX(angle){
angle *= Math.PI / 180;
let m = new CSSMatrix();
m.m21 = m.c = Math.tan(angle);
return m
}
function SkewY(angle){
angle *= Math.PI / 180;
let m = new CSSMatrix();
m.m12 = m.b = Math.tan(angle);
return m
}
function Translate(x, y, z){
let m = new CSSMatrix();
m.m41 = m.e = x;
m.m42 = m.f = y;
m.m43 = z;
return m
}
function multiply(m1, m2){
let m11 = m2.m11 * m1.m11 + m2.m12 * m1.m21 + m2.m13 * m1.m31 + m2.m14 * m1.m41,
m12 = m2.m11 * m1.m12 + m2.m12 * m1.m22 + m2.m13 * m1.m32 + m2.m14 * m1.m42,
m13 = m2.m11 * m1.m13 + m2.m12 * m1.m23 + m2.m13 * m1.m33 + m2.m14 * m1.m43,
m14 = m2.m11 * m1.m14 + m2.m12 * m1.m24 + m2.m13 * m1.m34 + m2.m14 * m1.m44,
m21 = m2.m21 * m1.m11 + m2.m22 * m1.m21 + m2.m23 * m1.m31 + m2.m24 * m1.m41,
m22 = m2.m21 * m1.m12 + m2.m22 * m1.m22 + m2.m23 * m1.m32 + m2.m24 * m1.m42,
m23 = m2.m21 * m1.m13 + m2.m22 * m1.m23 + m2.m23 * m1.m33 + m2.m24 * m1.m43,
m24 = m2.m21 * m1.m14 + m2.m22 * m1.m24 + m2.m23 * m1.m34 + m2.m24 * m1.m44,
m31 = m2.m31 * m1.m11 + m2.m32 * m1.m21 + m2.m33 * m1.m31 + m2.m34 * m1.m41,
m32 = m2.m31 * m1.m12 + m2.m32 * m1.m22 + m2.m33 * m1.m32 + m2.m34 * m1.m42,
m33 = m2.m31 * m1.m13 + m2.m32 * m1.m23 + m2.m33 * m1.m33 + m2.m34 * m1.m43,
m34 = m2.m31 * m1.m14 + m2.m32 * m1.m24 + m2.m33 * m1.m34 + m2.m34 * m1.m44,
m41 = m2.m41 * m1.m11 + m2.m42 * m1.m21 + m2.m43 * m1.m31 + m2.m44 * m1.m41,
m42 = m2.m41 * m1.m12 + m2.m42 * m1.m22 + m2.m43 * m1.m32 + m2.m44 * m1.m42,
m43 = m2.m41 * m1.m13 + m2.m42 * m1.m23 + m2.m43 * m1.m33 + m2.m44 * m1.m43,
m44 = m2.m41 * m1.m14 + m2.m42 * m1.m24 + m2.m43 * m1.m34 + m2.m44 * m1.m44;
return new CSSMatrix(
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44
)
}
export default class CSSMatrix {
constructor(){
let a = [].slice.call(arguments), m = this
if (a.length) for (let i = a.length; i--;){
if (Math.abs(a[i]) < 1e-6) a[i] = 0;
}
m.setIdentity();
if (a.length == 16){
m.is2D = false;
m.isIdentity = false;
m.m11 = m.a = a[0]; m.m12 = m.b = a[1]; m.m13 = a[2]; m.m14 = a[3];
m.m21 = m.c = a[4]; m.m22 = m.d = a[5]; m.m23 = a[6]; m.m24 = a[7];
m.m31 = a[8]; m.m32 = a[9]; m.m33 = a[10]; m.m34 = a[11];
m.m41 = m.e = a[12]; m.m42 = m.f = a[13]; m.m43 = a[14]; m.m44 = a[15];
} else if (a.length == 6) {
m.is2D = true;
m.isIdentity = false;
m.m11 = m.a = a[0]; m.m12 = m.b = a[1]; m.m14 = m.e = a[4];
m.m21 = m.c = a[2]; m.m22 = m.d = a[3]; m.m24 = m.f = a[5];
} else if (a.length === 1 && typeof a[0] == 'string') {
m.setMatrixValue(a[0]);
} else if (a.length > 0) {
throw new TypeError('Invalid Matrix Value');
}
}
// w3c defined methods
/**
* The setMatrixValue method replaces the existing matrix with one computed
* from parsing the passed string as though it had been assigned to the
* transform property in a CSS style rule.
* @param {String} string The string to parse.
*/
setMatrixValue(string){
string = String(string).trim();
let m = this;
m.setIdentity();
if (string == 'none') return m;
let type = string.slice(0, string.indexOf('(')), parts, i;
if (type == 'matrix3d'){
m.is2D = false;
m.isIdentity = false;
parts = string.slice(9, -1).split(',');
for (i = parts.length; i--;) parts[i] = +(parts[i]);
m.m11 = m.a = parts[0]; m.m12 = m.b = parts[1]; m.m13 = parts[2]; m.m14 = parts[3];
m.m21 = m.c = parts[4]; m.m22 = m.d = parts[5]; m.m23 = parts[6]; m.m24 = parts[7];
m.m31 = parts[8]; m.m32 = parts[9]; m.m33 = parts[10]; m.m34 = parts[11];
m.m41 = m.e = parts[12]; m.m42 = m.f = parts[13]; m.m43 = parts[14]; m.m44 = parts[15];
} else if (type == 'matrix'){
m.is2D = true;
m.isIdentity = false;
parts = string.slice(7, -1).split(',');
for (i = parts.length; i--;) parts[i] = +(parts[i]);
m.m11 = m.a = parts[0]; m.m12 = m.b = parts[2]; m.m41 = m.e = parts[4];
m.m21 = m.c = parts[1]; m.m22 = m.d = parts[3]; m.m42 = m.f = parts[5];
} else {
throw new TypeError('Invalid Matrix Value');
}
return m
}
/**
* The multiply method returns a new CSSMatrix which is the result of this
* matrix multiplied by the passed matrix, with the passed matrix to the right.
* This matrix is not modified.
*
* @param {CSSMatrix} m2
* @return {CSSMatrix} The result matrix.
*/
multiply(m2){
return multiply(this, m2)
}
/**
* The inverse method returns a new matrix which is the inverse of this matrix.
* This matrix is not modified.
*
* method not implemented yet
*/
// inverse = function(){
// throw new Error('the inverse() method is not implemented (yet).');
// }
/**
* The translate method returns a new matrix which is this matrix post
* multiplied by a translation matrix containing the passed values. If the z
* component is undefined, a 0 value is used in its place. This matrix is not
* modified.
*
* @param {number} x X component of the translation value.
* @param {number} y Y component of the translation value.
* @param {number=} z Z component of the translation value.
* @return {CSSMatrix} The result matrix
*/
translate(x, y, z){
if (z == null) z = 0;
if (y == null) y = 0;
this.m34 !== 0 && z && (this.is2D = false)
return multiply(this, Translate(x, y, z))
}
/**
* The scale method returns a new matrix which is this matrix post multiplied by
* a scale matrix containing the passed values. If the z component is undefined,
* a 1 value is used in its place. If the y component is undefined, the x
* component value is used in its place. This matrix is not modified.
*
* @param {number} x The X component of the scale value.
* @param {number=} y The Y component of the scale value.
* @param {number=} z The Z component of the scale value.
* @return {CSSMatrix} The result matrix
*/
scale(x, y, z){
if (y == null) y = x;
if (z == null) z = 1;
this.m34 !== 0 && (x !== y || x !== z || y !== z) && (this.is2D = false)
return multiply(this, Scale(x, y, z))
}
/**
* The rotate method returns a new matrix which is this matrix post multiplied
* by each of 3 rotation matrices about the major axes, first X, then Y, then Z.
* If the y and z components are undefined, the x value is used to rotate the
* object about the z axis, as though the vector (0,0,x) were passed. All
* rotation values are in degrees. This matrix is not modified.
*
* @param {number} rx The X component of the rotation value, or the Z component if the rotY and rotZ parameters are undefined.
* @param {number=} ry The (optional) Y component of the rotation value.
* @param {number=} rz The (optional) Z component of the rotation value.
* @return {CSSMatrix} The result matrix
*/
rotate(rx, ry, rz){
if (ry == null) ry = rx;
if (rz == null) rz = rx;
this.m34 !== 0 && (rx || ry) && (this.is2D = false)
return multiply(this, Rotate(rx, ry, rz))
}
/**
* The rotateAxisAngle method returns a new matrix which is this matrix post
* multiplied by a rotation matrix with the given axis and angle. The right-hand
* rule is used to determine the direction of rotation. All rotation values are
* in degrees. This matrix is not modified.
*
* @param {number} x The X component of the axis vector.
* @param {number=} y The Y component of the axis vector.
* @param {number=} z The Z component of the axis vector.
* @param {number} angle The angle of rotation about the axis vector, in degrees.
* @return {CSSMatrix} The result matrix
*/
rotateAxisAngle(x, y, z, angle){
this.m34 !== 0 && (x || y) && (this.is2D = false) // ??
if (y == null) y = x;
if (z == null) z = x;
return multiply(this, RotateAxisAngle(x, y, z, angle))
}
// Defined in WebKitCSSMatrix, but not in the w3c draft
/**
* Specifies a skew transformation along the x-axis by the given angle.
*
* @param {number} angle The angle amount in degrees to skew.
* @return {CSSMatrix} The result matrix
*/
skewX(angle){
return multiply(this, SkewX(angle))
}
/**
* Specifies a skew transformation along the x-axis by the given angle.
*
* @param {number} angle The angle amount in degrees to skew.
* @return {CSSMatrix} The result matrix
*/
skewY(angle){
return multiply(this, SkewY(angle))
}
/**
* Returns a string representation of the matrix.
* @return {string}
*/
toString(){
let m = this;
if (m.is2D){
return 'matrix(' + [
m.a, m.b,
m.c, m.d,
m.e, m.f
].join(', ') + ')';
}
// note: the elements here are transposed
return 'matrix3d(' + [
m.m11, m.m12, m.m13, m.m14,
m.m21, m.m22, m.m23, m.m24,
m.m31, m.m32, m.m33, m.m34,
m.m41, m.m42, m.m43, m.m44
].join(', ') + ')'
}
// Additional methods
/**
* Set the current matrix to the identity form
*
* @return {CSSMatrix} this matrix
*/
setIdentity(){
let m = this;
m.is2D = true;
m.isIdentity = true;
m.m11 = m.a = 1; m.m12 = m.b = 0; m.m13 = 0; m.m14 = 0;
m.m21 = m.c = 0; m.m22 = m.d = 1; m.m23 = 0; m.m24 = 0;
m.m31 = 0; m.m32 = 0; m.m33 = 1; m.m34 = 0;
m.m41 = m.e = 0; m.m42 = m.f = 0; m.m43 = 0; m.m44 = 1;
return this
}
/**
* Transform a tuple (3d point) with this CSSMatrix
*
* @param {Tuple} an object with x, y, z and w properties
* @return {Tuple} the passed tuple
* might use later ;)
*/
// transform = function(t /* tuple */ ){
// let m = this,
// x = m.m11 * t.x + m.m12 * t.y + m.m13 * t.z + m.m14 * t.w,
// y = m.m21 * t.x + m.m22 * t.y + m.m23 * t.z + m.m24 * t.w,
// z = m.m31 * t.x + m.m32 * t.y + m.m33 * t.z + m.m34 * t.w,
// w = m.m41 * t.x + m.m42 * t.y + m.m43 * t.z + m.m44 * t.w;
// t.x = x / w;
// t.y = y / w;
// t.z = z / w;
// return t;
// }
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc