Comparing version 0.0.4-d to 0.0.4-e
/*! | ||
* DOMMatrix v0.0.4d (https://github.com/thednp/dommatrix) | ||
* Copyright 2020 © thednp | ||
* DOMMatrix v0.0.4e (https://github.com/thednp/dommatrix) | ||
* Copyright 2021 © thednp | ||
* Licensed under MIT (https://github.com/thednp/DOMMatrix/blob/master/LICENSE) | ||
*/ | ||
function Translate(x, y, z){ | ||
var m = new CSSMatrix(); | ||
m.m41 = m.e = x; | ||
m.m42 = m.f = y; | ||
m.m43 = z; | ||
return m | ||
} | ||
function Rotate(rx, ry, rz){ | ||
var m = new CSSMatrix(); | ||
rx *= Math.PI / 180; | ||
ry *= Math.PI / 180; | ||
rz *= Math.PI / 180; | ||
var cosx = Math.cos(rx), sinx = -Math.sin(rx), | ||
cosy = Math.cos(ry), siny = -Math.sin(ry), | ||
cosz = Math.cos(rz), sinz = -Math.sin(rz); | ||
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; | ||
var sinA = Math.sin(angle), | ||
cosA = Math.cos(angle), | ||
sinA2 = sinA * sinA, | ||
length = Math.sqrt(x * x + y * y + z * z); | ||
if (length === 0){ | ||
x = 0; | ||
y = 0; | ||
z = 1; | ||
} else { | ||
x /= length; | ||
y /= length; | ||
z /= length; | ||
} | ||
var x2 = x * x, y2 = y * y, z2 = z * z; | ||
var 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 Scale(x, y, z){ | ||
var 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; | ||
var m = new CSSMatrix(); | ||
m.m21 = m.c = Math.tan(angle); | ||
return m | ||
} | ||
function SkewY(angle){ | ||
angle *= Math.PI / 180; | ||
var m = new CSSMatrix(); | ||
m.m12 = m.b = Math.tan(angle); | ||
return m | ||
} | ||
function Multiply(m1, m2){ | ||
var 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, m21, m31, m41, | ||
m12, m22, m32, m42, | ||
m13, m23, m33, m43, | ||
m14, m24, m34, m44]) | ||
} | ||
function fromMatrix(m){ | ||
return new CSSMatrix( | ||
[m.m11, m.m21, m.m31, m.m41, | ||
m.m12, m.m22, m.m32, m.m42, | ||
m.m13, m.m23, m.m33, m.m43, | ||
m.m14, m.m24, m.m34, m.m44]) | ||
} | ||
function fromArray(a){ | ||
return feedFromArray(new CSSMatrix(),a) | ||
} | ||
function feedFromArray(m,array){ | ||
var a = Array.from(array); | ||
if (a.length == 16){ | ||
m.m11 = m.a = a[0]; | ||
m.m21 = m.c = a[1]; | ||
m.m31 = a[2]; | ||
m.m41 = m.e = a[3]; | ||
m.m12 = m.b = a[4]; | ||
m.m22 = m.d = a[5]; | ||
m.m32 = a[6]; | ||
m.m42 = m.f = a[7]; | ||
m.m13 = a[8]; | ||
m.m23 = a[9]; | ||
m.m33 = a[10]; | ||
m.m43 = a[11]; | ||
m.m14 = a[12]; | ||
m.m24 = a[13]; | ||
m.m34 = a[14]; | ||
m.m44 = a[15]; | ||
} else if (a.length == 6) { | ||
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 { | ||
throw new TypeError("CSSMatrix: expecting a 6/16 values Array") | ||
} | ||
return m | ||
} | ||
var CSSMatrix = function CSSMatrix(){ | ||
@@ -116,3 +256,3 @@ var args = [], len = arguments.length; | ||
}; | ||
CSSMatrix.prototype.transform = function transform (t){ | ||
CSSMatrix.prototype.transform = function transform (t){ | ||
var m = this, | ||
@@ -129,145 +269,15 @@ x = m.m11 * t.x + m.m12 * t.y + m.m13 * t.z + m.m14 * t.w, | ||
} | ||
}; | ||
}; | ||
Object.defineProperties( CSSMatrix.prototype, prototypeAccessors ); | ||
CSSMatrix.Translate = function Translate(x, y, z){ | ||
var m = new CSSMatrix(); | ||
m.m41 = m.e = x; | ||
m.m42 = m.f = y; | ||
m.m43 = z; | ||
return m | ||
}; | ||
CSSMatrix.Rotate = function Rotate(rx, ry, rz){ | ||
var m = new CSSMatrix(); | ||
rx *= Math.PI / 180; | ||
ry *= Math.PI / 180; | ||
rz *= Math.PI / 180; | ||
var cosx = Math.cos(rx), sinx = -Math.sin(rx), | ||
cosy = Math.cos(ry), siny = -Math.sin(ry), | ||
cosz = Math.cos(rz), sinz = -Math.sin(rz); | ||
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 | ||
}; | ||
CSSMatrix.RotateAxisAngle = function RotateAxisAngle(x, y, z, angle){ | ||
angle *= Math.PI / 360; | ||
var sinA = Math.sin(angle), | ||
cosA = Math.cos(angle), | ||
sinA2 = sinA * sinA, | ||
length = Math.sqrt(x * x + y * y + z * z); | ||
if (length === 0){ | ||
x = 0; | ||
y = 0; | ||
z = 1; | ||
} else { | ||
x /= length; | ||
y /= length; | ||
z /= length; | ||
} | ||
var x2 = x * x, y2 = y * y, z2 = z * z; | ||
var 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 | ||
}; | ||
CSSMatrix.Scale = function Scale(x, y, z){ | ||
var m = new CSSMatrix(); | ||
m.m11 = m.a = x; | ||
m.m22 = m.d = y; | ||
m.m33 = z; | ||
return m | ||
}; | ||
CSSMatrix.SkewX = function SkewX(angle){ | ||
angle *= Math.PI / 180; | ||
var m = new CSSMatrix(); | ||
m.m21 = m.c = Math.tan(angle); | ||
return m | ||
}; | ||
CSSMatrix.SkewY = function SkewY(angle){ | ||
angle *= Math.PI / 180; | ||
var m = new CSSMatrix(); | ||
m.m12 = m.b = Math.tan(angle); | ||
return m | ||
}; | ||
CSSMatrix.Multiply = function Multiply(m1, m2){ | ||
var 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, m21, m31, m41, | ||
m12, m22, m32, m42, | ||
m13, m23, m33, m43, | ||
m14, m24, m34, m44]) | ||
}; | ||
CSSMatrix.fromMatrix = function fromMatrix(m){ | ||
return new CSSMatrix( | ||
[m.m11, m.m21, m.m31, m.m41, | ||
m.m12, m.m22, m.m32, m.m42, | ||
m.m13, m.m23, m.m33, m.m43, | ||
m.m14, m.m24, m.m34, m.m44]) | ||
}; | ||
CSSMatrix.fromArray = function fromArray(a){ | ||
return feedFromArray(new CSSMatrix(),a) | ||
}; | ||
CSSMatrix.feedFromArray = function feedFromArray(m,array){ | ||
var a = Array.from(array); | ||
if (a.length == 16){ | ||
m.m11 = m.a = a[0]; | ||
m.m21 = m.c = a[1]; | ||
m.m31 = a[2]; | ||
m.m41 = m.e = a[3]; | ||
m.m12 = m.b = a[4]; | ||
m.m22 = m.d = a[5]; | ||
m.m32 = a[6]; | ||
m.m42 = m.f = a[7]; | ||
m.m13 = a[8]; | ||
m.m23 = a[9]; | ||
m.m33 = a[10]; | ||
m.m43 = a[11]; | ||
m.m14 = a[12]; | ||
m.m24 = a[13]; | ||
m.m34 = a[14]; | ||
m.m44 = a[15]; | ||
} else if (a.length == 6) { | ||
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 { | ||
throw new TypeError("CSSMatrix: expecting a 6/16 values Array") | ||
} | ||
return m | ||
}; | ||
CSSMatrix.Translate = Translate; | ||
CSSMatrix.Rotate = Rotate; | ||
CSSMatrix.RotateAxisAngle = RotateAxisAngle; | ||
CSSMatrix.Scale = Scale; | ||
CSSMatrix.SkewX = SkewX; | ||
CSSMatrix.SkewY = SkewY; | ||
CSSMatrix.Multiply = Multiply; | ||
CSSMatrix.fromMatrix = fromMatrix; | ||
CSSMatrix.fromArray = fromArray; | ||
CSSMatrix.feedFromArray = feedFromArray; | ||
export default CSSMatrix; |
@@ -1,2 +0,2 @@ | ||
// DOMMatrix v0.0.4d | thednp © 2020 | MIT-License | ||
var m=function(){for(var m=[],t=arguments.length;t--;)m[t]=arguments[t];return this.setIdentity(),m&&m.length&&this.setMatrixValue(m)},t={isIdentity:{configurable:!0},is2D:{configurable:!0}};m.prototype.setMatrixValue=function(t){var r=this;if(!t||!t.length)return r;if(t.length&&"string"==typeof t[0]&&t[0].length){var e,n,i=String(t[0]).trim();if("none"==i)return r;if(e=i.slice(0,i.indexOf("(")),n=i.slice("matrix"===e?7:9,-1).split(",").map((function(m){return Math.abs(m)<1e-6?0:+m})),!([6,16].indexOf(n.length)>-1))throw new TypeError("CSSMatrix: expecting valid CSS matrix() / matrix3d() syntax");feedFromArray(r,n)}else t[0]instanceof m?feedFromArray(r,t[0].toArray()):Array.isArray(t[0])?feedFromArray(r,t[0]):Array.isArray(t)&&feedFromArray(r,t);return r},m.prototype.toString=function(){return(this.is2D?"matrix":"matrix3d")+"("+this.toArray(1).join(",")+")"},m.prototype.toArray=function(m){var t=this;return t.is2D?[t.a,t.b,t.c,t.d,t.e,t.f]:m?[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]:[t.m11,t.m21,t.m31,t.m41,t.m12,t.m22,t.m32,t.m42,t.m13,t.m23,t.m33,t.m43,t.m14,t.m24,t.m34,t.m44]},m.prototype.multiply=function(m){return Multiply(this,m)},m.prototype.translate=function(m,t,r){return null==r&&(r=0),null==t&&(t=0),Multiply(this,Translate(m,t,r))},m.prototype.scale=function(m,t,r){return null==t&&(t=m),null==r&&(r=m),Multiply(this,Scale(m,t,r))},m.prototype.rotate=function(m,t,r){return null==t&&(t=0),null==r&&(r=m,m=0),Multiply(this,Rotate(m,t,r))},m.prototype.rotateAxisAngle=function(m,t,r,e){if(4!==arguments.length)throw new TypeError("CSSMatrix: expecting 4 values");return Multiply(this,RotateAxisAngle(m,t,r,e))},m.prototype.skewX=function(m){return Multiply(this,SkewX(m))},m.prototype.skewY=function(m){return Multiply(this,SkewY(m))},m.prototype.setIdentity=function(){return feedFromArray(this,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])},t.isIdentity.get=function(){var m=this;return 1==m.m11&&0==m.m12&&0==m.m13&&0==m.m14&&0==m.m21&&1==m.m22&&0==m.m23&&0==m.m24&&0==m.m31&&0==m.m32&&1==m.m33&&0==m.m34&&0==m.m41&&0==m.m42&&0==m.m43&&1==m.m44},t.isIdentity.set=function(m){this.isIdentity=m},t.is2D.get=function(){var m=this;return 0==m.m31&&0==m.m32&&1==m.m33&&0==m.m34&&0==m.m43&&1==m.m44},t.is2D.set=function(m){this.is2D=m},m.prototype.transformPoint=function(m){var t=Translate(m.x,m.y,m.z);return t.m44=m.w||1,{x:(t=this.multiply(t)).m41,y:t.m42,z:t.m43,w:t.m44}},m.prototype.transform=function(m){var t=this,r=t.m11*m.x+t.m12*m.y+t.m13*m.z+t.m14*m.w,e=t.m21*m.x+t.m22*m.y+t.m23*m.z+t.m24*m.w,n=t.m31*m.x+t.m32*m.y+t.m33*m.z+t.m34*m.w,i=t.m41*m.x+t.m42*m.y+t.m43*m.z+t.m44*m.w;return{x:r/i,y:e/i,z:n/i,w:i}},Object.defineProperties(m.prototype,t),m.Translate=function(t,r,e){var n=new m;return n.m41=n.e=t,n.m42=n.f=r,n.m43=e,n},m.Rotate=function(t,r,e){var n=new m;t*=Math.PI/180,r*=Math.PI/180,e*=Math.PI/180;var i=Math.cos(t),a=-Math.sin(t),o=Math.cos(r),u=-Math.sin(r),s=Math.cos(e),l=-Math.sin(e);return n.m11=n.a=o*s,n.m12=n.b=-o*l,n.m13=u,n.m21=n.c=a*u*s+i*l,n.m22=n.d=i*s-a*u*l,n.m23=-a*o,n.m31=a*l-i*u*s,n.m32=a*s+i*u*l,n.m33=i*o,n},m.RotateAxisAngle=function(t,r,e,n){n*=Math.PI/360;var i=Math.sin(n),a=Math.cos(n),o=i*i,u=Math.sqrt(t*t+r*r+e*e);0===u?(t=0,r=0,e=1):(t/=u,r/=u,e/=u);var s=t*t,l=r*r,f=e*e,y=new m;return y.m11=y.a=1-2*(l+f)*o,y.m12=y.b=2*(t*r*o+e*i*a),y.m13=2*(t*e*o-r*i*a),y.m21=y.c=2*(r*t*o-e*i*a),y.m22=y.d=1-2*(f+s)*o,y.m23=2*(r*e*o+t*i*a),y.m31=2*(e*t*o+r*i*a),y.m32=2*(e*r*o-t*i*a),y.m33=1-2*(s+l)*o,y.m14=y.m24=y.m34=0,y.m41=y.e=y.m42=y.f=y.m43=0,y.m44=1,y},m.Scale=function(t,r,e){var n=new m;return n.m11=n.a=t,n.m22=n.d=r,n.m33=e,n},m.SkewX=function(t){t*=Math.PI/180;var r=new m;return r.m21=r.c=Math.tan(t),r},m.SkewY=function(t){t*=Math.PI/180;var r=new m;return r.m12=r.b=Math.tan(t),r},m.Multiply=function(t,r){var e=r.m11*t.m11+r.m12*t.m21+r.m13*t.m31+r.m14*t.m41,n=r.m11*t.m12+r.m12*t.m22+r.m13*t.m32+r.m14*t.m42,i=r.m11*t.m13+r.m12*t.m23+r.m13*t.m33+r.m14*t.m43,a=r.m11*t.m14+r.m12*t.m24+r.m13*t.m34+r.m14*t.m44,o=r.m21*t.m11+r.m22*t.m21+r.m23*t.m31+r.m24*t.m41,u=r.m21*t.m12+r.m22*t.m22+r.m23*t.m32+r.m24*t.m42,s=r.m21*t.m13+r.m22*t.m23+r.m23*t.m33+r.m24*t.m43,l=r.m21*t.m14+r.m22*t.m24+r.m23*t.m34+r.m24*t.m44,f=r.m31*t.m11+r.m32*t.m21+r.m33*t.m31+r.m34*t.m41,y=r.m31*t.m12+r.m32*t.m22+r.m33*t.m32+r.m34*t.m42,c=r.m31*t.m13+r.m32*t.m23+r.m33*t.m33+r.m34*t.m43,h=r.m31*t.m14+r.m32*t.m24+r.m33*t.m34+r.m34*t.m44,p=r.m41*t.m11+r.m42*t.m21+r.m43*t.m31+r.m44*t.m41,M=r.m41*t.m12+r.m42*t.m22+r.m43*t.m32+r.m44*t.m42,w=r.m41*t.m13+r.m42*t.m23+r.m43*t.m33+r.m44*t.m43,x=r.m41*t.m14+r.m42*t.m24+r.m43*t.m34+r.m44*t.m44;return new m([e,o,f,p,n,u,y,M,i,s,c,w,a,l,h,x])},m.fromMatrix=function(t){return new m([t.m11,t.m21,t.m31,t.m41,t.m12,t.m22,t.m32,t.m42,t.m13,t.m23,t.m33,t.m43,t.m14,t.m24,t.m34,t.m44])},m.fromArray=function(t){return feedFromArray(new m,t)},m.feedFromArray=function(m,t){var r=Array.from(t);if(16==r.length)m.m11=m.a=r[0],m.m21=m.c=r[1],m.m31=r[2],m.m41=m.e=r[3],m.m12=m.b=r[4],m.m22=m.d=r[5],m.m32=r[6],m.m42=m.f=r[7],m.m13=r[8],m.m23=r[9],m.m33=r[10],m.m43=r[11],m.m14=r[12],m.m24=r[13],m.m34=r[14],m.m44=r[15];else{if(6!=r.length)throw new TypeError("CSSMatrix: expecting a 6/16 values Array");m.m11=m.a=r[0],m.m12=m.b=r[1],m.m14=m.e=r[4],m.m21=m.c=r[2],m.m22=m.d=r[3],m.m24=m.f=r[5]}return m};export default m; | ||
// DOMMatrix v0.0.4e | thednp © 2021 | MIT-License | ||
function m(m,t,r){var n=new u;return n.m41=n.e=m,n.m42=n.f=t,n.m43=r,n}function t(m,t,r){var n=new u;m*=Math.PI/180,t*=Math.PI/180,r*=Math.PI/180;var e=Math.cos(m),i=-Math.sin(m),a=Math.cos(t),o=-Math.sin(t),s=Math.cos(r),f=-Math.sin(r);return n.m11=n.a=a*s,n.m12=n.b=-a*f,n.m13=o,n.m21=n.c=i*o*s+e*f,n.m22=n.d=e*s-i*o*f,n.m23=-i*a,n.m31=i*f-e*o*s,n.m32=i*s+e*o*f,n.m33=e*a,n}function r(m,t,r,n){n*=Math.PI/360;var e=Math.sin(n),i=Math.cos(n),a=e*e,o=Math.sqrt(m*m+t*t+r*r);0===o?(m=0,t=0,r=1):(m/=o,t/=o,r/=o);var s=m*m,f=t*t,c=r*r,h=new u;return h.m11=h.a=1-2*(f+c)*a,h.m12=h.b=2*(m*t*a+r*e*i),h.m13=2*(m*r*a-t*e*i),h.m21=h.c=2*(t*m*a-r*e*i),h.m22=h.d=1-2*(c+s)*a,h.m23=2*(t*r*a+m*e*i),h.m31=2*(r*m*a+t*e*i),h.m32=2*(r*t*a-m*e*i),h.m33=1-2*(s+f)*a,h.m14=h.m24=h.m34=0,h.m41=h.e=h.m42=h.f=h.m43=0,h.m44=1,h}function n(m,t,r){var n=new u;return n.m11=n.a=m,n.m22=n.d=t,n.m33=r,n}function e(m){m*=Math.PI/180;var t=new u;return t.m21=t.c=Math.tan(m),t}function i(m){m*=Math.PI/180;var t=new u;return t.m12=t.b=Math.tan(m),t}function a(m,t){var r=t.m11*m.m11+t.m12*m.m21+t.m13*m.m31+t.m14*m.m41,n=t.m11*m.m12+t.m12*m.m22+t.m13*m.m32+t.m14*m.m42,e=t.m11*m.m13+t.m12*m.m23+t.m13*m.m33+t.m14*m.m43,i=t.m11*m.m14+t.m12*m.m24+t.m13*m.m34+t.m14*m.m44,a=t.m21*m.m11+t.m22*m.m21+t.m23*m.m31+t.m24*m.m41,o=t.m21*m.m12+t.m22*m.m22+t.m23*m.m32+t.m24*m.m42,s=t.m21*m.m13+t.m22*m.m23+t.m23*m.m33+t.m24*m.m43,f=t.m21*m.m14+t.m22*m.m24+t.m23*m.m34+t.m24*m.m44,c=t.m31*m.m11+t.m32*m.m21+t.m33*m.m31+t.m34*m.m41,h=t.m31*m.m12+t.m32*m.m22+t.m33*m.m32+t.m34*m.m42,l=t.m31*m.m13+t.m32*m.m23+t.m33*m.m33+t.m34*m.m43,y=t.m31*m.m14+t.m32*m.m24+t.m33*m.m34+t.m34*m.m44,p=t.m41*m.m11+t.m42*m.m21+t.m43*m.m31+t.m44*m.m41,x=t.m41*m.m12+t.m42*m.m22+t.m43*m.m32+t.m44*m.m42,w=t.m41*m.m13+t.m42*m.m23+t.m43*m.m33+t.m44*m.m43,M=t.m41*m.m14+t.m42*m.m24+t.m43*m.m34+t.m44*m.m44;return new u([r,a,c,p,n,o,h,x,e,s,l,w,i,f,y,M])}function o(m,t){var r=Array.from(t);if(16==r.length)m.m11=m.a=r[0],m.m21=m.c=r[1],m.m31=r[2],m.m41=m.e=r[3],m.m12=m.b=r[4],m.m22=m.d=r[5],m.m32=r[6],m.m42=m.f=r[7],m.m13=r[8],m.m23=r[9],m.m33=r[10],m.m43=r[11],m.m14=r[12],m.m24=r[13],m.m34=r[14],m.m44=r[15];else{if(6!=r.length)throw new TypeError("CSSMatrix: expecting a 6/16 values Array");m.m11=m.a=r[0],m.m12=m.b=r[1],m.m14=m.e=r[4],m.m21=m.c=r[2],m.m22=m.d=r[3],m.m24=m.f=r[5]}return m}var u=function(){for(var m=[],t=arguments.length;t--;)m[t]=arguments[t];return this.setIdentity(),m&&m.length&&this.setMatrixValue(m)},s={isIdentity:{configurable:!0},is2D:{configurable:!0}};u.prototype.setMatrixValue=function(m){var t=this;if(!m||!m.length)return t;if(m.length&&"string"==typeof m[0]&&m[0].length){var r,n,e=String(m[0]).trim();if("none"==e)return t;if(r=e.slice(0,e.indexOf("(")),n=e.slice("matrix"===r?7:9,-1).split(",").map((function(m){return Math.abs(m)<1e-6?0:+m})),!([6,16].indexOf(n.length)>-1))throw new TypeError("CSSMatrix: expecting valid CSS matrix() / matrix3d() syntax");o(t,n)}else m[0]instanceof u?o(t,m[0].toArray()):Array.isArray(m[0])?o(t,m[0]):Array.isArray(m)&&o(t,m);return t},u.prototype.toString=function(){return(this.is2D?"matrix":"matrix3d")+"("+this.toArray(1).join(",")+")"},u.prototype.toArray=function(m){var t=this;return t.is2D?[t.a,t.b,t.c,t.d,t.e,t.f]:m?[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]:[t.m11,t.m21,t.m31,t.m41,t.m12,t.m22,t.m32,t.m42,t.m13,t.m23,t.m33,t.m43,t.m14,t.m24,t.m34,t.m44]},u.prototype.multiply=function(m){return a(this,m)},u.prototype.translate=function(t,r,n){return null==n&&(n=0),null==r&&(r=0),a(this,m(t,r,n))},u.prototype.scale=function(m,t,r){return null==t&&(t=m),null==r&&(r=m),a(this,n(m,t,r))},u.prototype.rotate=function(m,r,n){return null==r&&(r=0),null==n&&(n=m,m=0),a(this,t(m,r,n))},u.prototype.rotateAxisAngle=function(m,t,n,e){if(4!==arguments.length)throw new TypeError("CSSMatrix: expecting 4 values");return a(this,r(m,t,n,e))},u.prototype.skewX=function(m){return a(this,e(m))},u.prototype.skewY=function(m){return a(this,i(m))},u.prototype.setIdentity=function(){return o(this,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])},s.isIdentity.get=function(){var m=this;return 1==m.m11&&0==m.m12&&0==m.m13&&0==m.m14&&0==m.m21&&1==m.m22&&0==m.m23&&0==m.m24&&0==m.m31&&0==m.m32&&1==m.m33&&0==m.m34&&0==m.m41&&0==m.m42&&0==m.m43&&1==m.m44},s.isIdentity.set=function(m){this.isIdentity=m},s.is2D.get=function(){var m=this;return 0==m.m31&&0==m.m32&&1==m.m33&&0==m.m34&&0==m.m43&&1==m.m44},s.is2D.set=function(m){this.is2D=m},u.prototype.transformPoint=function(t){var r=m(t.x,t.y,t.z);return r.m44=t.w||1,{x:(r=this.multiply(r)).m41,y:r.m42,z:r.m43,w:r.m44}},u.prototype.transform=function(m){var t=this,r=t.m11*m.x+t.m12*m.y+t.m13*m.z+t.m14*m.w,n=t.m21*m.x+t.m22*m.y+t.m23*m.z+t.m24*m.w,e=t.m31*m.x+t.m32*m.y+t.m33*m.z+t.m34*m.w,i=t.m41*m.x+t.m42*m.y+t.m43*m.z+t.m44*m.w;return{x:r/i,y:n/i,z:e/i,w:i}},Object.defineProperties(u.prototype,s),u.Translate=m,u.Rotate=t,u.RotateAxisAngle=r,u.Scale=n,u.SkewX=e,u.SkewY=i,u.Multiply=a,u.fromMatrix=function(m){return new u([m.m11,m.m21,m.m31,m.m41,m.m12,m.m22,m.m32,m.m42,m.m13,m.m23,m.m33,m.m43,m.m14,m.m24,m.m34,m.m44])},u.fromArray=function(m){return o(new u,m)},u.feedFromArray=o;export default u; |
/*! | ||
* DOMMatrix v0.0.4d (https://github.com/thednp/dommatrix) | ||
* Copyright 2020 © thednp | ||
* DOMMatrix v0.0.4e (https://github.com/thednp/dommatrix) | ||
* Copyright 2021 © thednp | ||
* Licensed under MIT (https://github.com/thednp/DOMMatrix/blob/master/LICENSE) | ||
@@ -12,2 +12,142 @@ */ | ||
function Translate(x, y, z){ | ||
var m = new CSSMatrix(); | ||
m.m41 = m.e = x; | ||
m.m42 = m.f = y; | ||
m.m43 = z; | ||
return m | ||
} | ||
function Rotate(rx, ry, rz){ | ||
var m = new CSSMatrix(); | ||
rx *= Math.PI / 180; | ||
ry *= Math.PI / 180; | ||
rz *= Math.PI / 180; | ||
var cosx = Math.cos(rx), sinx = -Math.sin(rx), | ||
cosy = Math.cos(ry), siny = -Math.sin(ry), | ||
cosz = Math.cos(rz), sinz = -Math.sin(rz); | ||
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; | ||
var sinA = Math.sin(angle), | ||
cosA = Math.cos(angle), | ||
sinA2 = sinA * sinA, | ||
length = Math.sqrt(x * x + y * y + z * z); | ||
if (length === 0){ | ||
x = 0; | ||
y = 0; | ||
z = 1; | ||
} else { | ||
x /= length; | ||
y /= length; | ||
z /= length; | ||
} | ||
var x2 = x * x, y2 = y * y, z2 = z * z; | ||
var 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 Scale(x, y, z){ | ||
var 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; | ||
var m = new CSSMatrix(); | ||
m.m21 = m.c = Math.tan(angle); | ||
return m | ||
} | ||
function SkewY(angle){ | ||
angle *= Math.PI / 180; | ||
var m = new CSSMatrix(); | ||
m.m12 = m.b = Math.tan(angle); | ||
return m | ||
} | ||
function Multiply(m1, m2){ | ||
var 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, m21, m31, m41, | ||
m12, m22, m32, m42, | ||
m13, m23, m33, m43, | ||
m14, m24, m34, m44]) | ||
} | ||
function fromMatrix(m){ | ||
return new CSSMatrix( | ||
[m.m11, m.m21, m.m31, m.m41, | ||
m.m12, m.m22, m.m32, m.m42, | ||
m.m13, m.m23, m.m33, m.m43, | ||
m.m14, m.m24, m.m34, m.m44]) | ||
} | ||
function fromArray(a){ | ||
return feedFromArray(new CSSMatrix(),a) | ||
} | ||
function feedFromArray(m,array){ | ||
var a = Array.from(array); | ||
if (a.length == 16){ | ||
m.m11 = m.a = a[0]; | ||
m.m21 = m.c = a[1]; | ||
m.m31 = a[2]; | ||
m.m41 = m.e = a[3]; | ||
m.m12 = m.b = a[4]; | ||
m.m22 = m.d = a[5]; | ||
m.m32 = a[6]; | ||
m.m42 = m.f = a[7]; | ||
m.m13 = a[8]; | ||
m.m23 = a[9]; | ||
m.m33 = a[10]; | ||
m.m43 = a[11]; | ||
m.m14 = a[12]; | ||
m.m24 = a[13]; | ||
m.m34 = a[14]; | ||
m.m44 = a[15]; | ||
} else if (a.length == 6) { | ||
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 { | ||
throw new TypeError("CSSMatrix: expecting a 6/16 values Array") | ||
} | ||
return m | ||
} | ||
var CSSMatrix = function CSSMatrix(){ | ||
@@ -123,3 +263,3 @@ var args = [], len = arguments.length; | ||
}; | ||
CSSMatrix.prototype.transform = function transform (t){ | ||
CSSMatrix.prototype.transform = function transform (t){ | ||
var m = this, | ||
@@ -136,144 +276,14 @@ x = m.m11 * t.x + m.m12 * t.y + m.m13 * t.z + m.m14 * t.w, | ||
} | ||
}; | ||
}; | ||
Object.defineProperties( CSSMatrix.prototype, prototypeAccessors ); | ||
CSSMatrix.Translate = function Translate(x, y, z){ | ||
var m = new CSSMatrix(); | ||
m.m41 = m.e = x; | ||
m.m42 = m.f = y; | ||
m.m43 = z; | ||
return m | ||
}; | ||
CSSMatrix.Rotate = function Rotate(rx, ry, rz){ | ||
var m = new CSSMatrix(); | ||
rx *= Math.PI / 180; | ||
ry *= Math.PI / 180; | ||
rz *= Math.PI / 180; | ||
var cosx = Math.cos(rx), sinx = -Math.sin(rx), | ||
cosy = Math.cos(ry), siny = -Math.sin(ry), | ||
cosz = Math.cos(rz), sinz = -Math.sin(rz); | ||
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 | ||
}; | ||
CSSMatrix.RotateAxisAngle = function RotateAxisAngle(x, y, z, angle){ | ||
angle *= Math.PI / 360; | ||
var sinA = Math.sin(angle), | ||
cosA = Math.cos(angle), | ||
sinA2 = sinA * sinA, | ||
length = Math.sqrt(x * x + y * y + z * z); | ||
if (length === 0){ | ||
x = 0; | ||
y = 0; | ||
z = 1; | ||
} else { | ||
x /= length; | ||
y /= length; | ||
z /= length; | ||
} | ||
var x2 = x * x, y2 = y * y, z2 = z * z; | ||
var 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 | ||
}; | ||
CSSMatrix.Scale = function Scale(x, y, z){ | ||
var m = new CSSMatrix(); | ||
m.m11 = m.a = x; | ||
m.m22 = m.d = y; | ||
m.m33 = z; | ||
return m | ||
}; | ||
CSSMatrix.SkewX = function SkewX(angle){ | ||
angle *= Math.PI / 180; | ||
var m = new CSSMatrix(); | ||
m.m21 = m.c = Math.tan(angle); | ||
return m | ||
}; | ||
CSSMatrix.SkewY = function SkewY(angle){ | ||
angle *= Math.PI / 180; | ||
var m = new CSSMatrix(); | ||
m.m12 = m.b = Math.tan(angle); | ||
return m | ||
}; | ||
CSSMatrix.Multiply = function Multiply(m1, m2){ | ||
var 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, m21, m31, m41, | ||
m12, m22, m32, m42, | ||
m13, m23, m33, m43, | ||
m14, m24, m34, m44]) | ||
}; | ||
CSSMatrix.fromMatrix = function fromMatrix(m){ | ||
return new CSSMatrix( | ||
[m.m11, m.m21, m.m31, m.m41, | ||
m.m12, m.m22, m.m32, m.m42, | ||
m.m13, m.m23, m.m33, m.m43, | ||
m.m14, m.m24, m.m34, m.m44]) | ||
}; | ||
CSSMatrix.fromArray = function fromArray(a){ | ||
return feedFromArray(new CSSMatrix(),a) | ||
}; | ||
CSSMatrix.feedFromArray = function feedFromArray(m,array){ | ||
var a = Array.from(array); | ||
if (a.length == 16){ | ||
m.m11 = m.a = a[0]; | ||
m.m21 = m.c = a[1]; | ||
m.m31 = a[2]; | ||
m.m41 = m.e = a[3]; | ||
m.m12 = m.b = a[4]; | ||
m.m22 = m.d = a[5]; | ||
m.m32 = a[6]; | ||
m.m42 = m.f = a[7]; | ||
m.m13 = a[8]; | ||
m.m23 = a[9]; | ||
m.m33 = a[10]; | ||
m.m43 = a[11]; | ||
m.m14 = a[12]; | ||
m.m24 = a[13]; | ||
m.m34 = a[14]; | ||
m.m44 = a[15]; | ||
} else if (a.length == 6) { | ||
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 { | ||
throw new TypeError("CSSMatrix: expecting a 6/16 values Array") | ||
} | ||
return m | ||
}; | ||
CSSMatrix.Translate = Translate; | ||
CSSMatrix.Rotate = Rotate; | ||
CSSMatrix.RotateAxisAngle = RotateAxisAngle; | ||
CSSMatrix.Scale = Scale; | ||
CSSMatrix.SkewX = SkewX; | ||
CSSMatrix.SkewY = SkewY; | ||
CSSMatrix.Multiply = Multiply; | ||
CSSMatrix.fromMatrix = fromMatrix; | ||
CSSMatrix.fromArray = fromArray; | ||
CSSMatrix.feedFromArray = feedFromArray; | ||
@@ -280,0 +290,0 @@ return CSSMatrix; |
@@ -1,2 +0,2 @@ | ||
// DOMMatrix v0.0.4d | 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";var m=function(){for(var m=[],t=arguments.length;t--;)m[t]=arguments[t];return this.setIdentity(),m&&m.length&&this.setMatrixValue(m)},t={isIdentity:{configurable:!0},is2D:{configurable:!0}};return m.prototype.setMatrixValue=function(t){var r=this;if(!t||!t.length)return r;if(t.length&&"string"==typeof t[0]&&t[0].length){var e,n,i=String(t[0]).trim();if("none"==i)return r;if(e=i.slice(0,i.indexOf("(")),n=i.slice("matrix"===e?7:9,-1).split(",").map((function(m){return Math.abs(m)<1e-6?0:+m})),!([6,16].indexOf(n.length)>-1))throw new TypeError("CSSMatrix: expecting valid CSS matrix() / matrix3d() syntax");feedFromArray(r,n)}else t[0]instanceof m?feedFromArray(r,t[0].toArray()):Array.isArray(t[0])?feedFromArray(r,t[0]):Array.isArray(t)&&feedFromArray(r,t);return r},m.prototype.toString=function(){return(this.is2D?"matrix":"matrix3d")+"("+this.toArray(1).join(",")+")"},m.prototype.toArray=function(m){var t=this;return t.is2D?[t.a,t.b,t.c,t.d,t.e,t.f]:m?[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]:[t.m11,t.m21,t.m31,t.m41,t.m12,t.m22,t.m32,t.m42,t.m13,t.m23,t.m33,t.m43,t.m14,t.m24,t.m34,t.m44]},m.prototype.multiply=function(m){return Multiply(this,m)},m.prototype.translate=function(m,t,r){return null==r&&(r=0),null==t&&(t=0),Multiply(this,Translate(m,t,r))},m.prototype.scale=function(m,t,r){return null==t&&(t=m),null==r&&(r=m),Multiply(this,Scale(m,t,r))},m.prototype.rotate=function(m,t,r){return null==t&&(t=0),null==r&&(r=m,m=0),Multiply(this,Rotate(m,t,r))},m.prototype.rotateAxisAngle=function(m,t,r,e){if(4!==arguments.length)throw new TypeError("CSSMatrix: expecting 4 values");return Multiply(this,RotateAxisAngle(m,t,r,e))},m.prototype.skewX=function(m){return Multiply(this,SkewX(m))},m.prototype.skewY=function(m){return Multiply(this,SkewY(m))},m.prototype.setIdentity=function(){return feedFromArray(this,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])},t.isIdentity.get=function(){var m=this;return 1==m.m11&&0==m.m12&&0==m.m13&&0==m.m14&&0==m.m21&&1==m.m22&&0==m.m23&&0==m.m24&&0==m.m31&&0==m.m32&&1==m.m33&&0==m.m34&&0==m.m41&&0==m.m42&&0==m.m43&&1==m.m44},t.isIdentity.set=function(m){this.isIdentity=m},t.is2D.get=function(){var m=this;return 0==m.m31&&0==m.m32&&1==m.m33&&0==m.m34&&0==m.m43&&1==m.m44},t.is2D.set=function(m){this.is2D=m},m.prototype.transformPoint=function(m){var t=Translate(m.x,m.y,m.z);return t.m44=m.w||1,{x:(t=this.multiply(t)).m41,y:t.m42,z:t.m43,w:t.m44}},m.prototype.transform=function(m){var t=this,r=t.m11*m.x+t.m12*m.y+t.m13*m.z+t.m14*m.w,e=t.m21*m.x+t.m22*m.y+t.m23*m.z+t.m24*m.w,n=t.m31*m.x+t.m32*m.y+t.m33*m.z+t.m34*m.w,i=t.m41*m.x+t.m42*m.y+t.m43*m.z+t.m44*m.w;return{x:r/i,y:e/i,z:n/i,w:i}},Object.defineProperties(m.prototype,t),m.Translate=function(t,r,e){var n=new m;return n.m41=n.e=t,n.m42=n.f=r,n.m43=e,n},m.Rotate=function(t,r,e){var n=new m;t*=Math.PI/180,r*=Math.PI/180,e*=Math.PI/180;var i=Math.cos(t),o=-Math.sin(t),a=Math.cos(r),u=-Math.sin(r),s=Math.cos(e),f=-Math.sin(e);return n.m11=n.a=a*s,n.m12=n.b=-a*f,n.m13=u,n.m21=n.c=o*u*s+i*f,n.m22=n.d=i*s-o*u*f,n.m23=-o*a,n.m31=o*f-i*u*s,n.m32=o*s+i*u*f,n.m33=i*a,n},m.RotateAxisAngle=function(t,r,e,n){n*=Math.PI/360;var i=Math.sin(n),o=Math.cos(n),a=i*i,u=Math.sqrt(t*t+r*r+e*e);0===u?(t=0,r=0,e=1):(t/=u,r/=u,e/=u);var s=t*t,f=r*r,l=e*e,y=new m;return y.m11=y.a=1-2*(f+l)*a,y.m12=y.b=2*(t*r*a+e*i*o),y.m13=2*(t*e*a-r*i*o),y.m21=y.c=2*(r*t*a-e*i*o),y.m22=y.d=1-2*(l+s)*a,y.m23=2*(r*e*a+t*i*o),y.m31=2*(e*t*a+r*i*o),y.m32=2*(e*r*a-t*i*o),y.m33=1-2*(s+f)*a,y.m14=y.m24=y.m34=0,y.m41=y.e=y.m42=y.f=y.m43=0,y.m44=1,y},m.Scale=function(t,r,e){var n=new m;return n.m11=n.a=t,n.m22=n.d=r,n.m33=e,n},m.SkewX=function(t){t*=Math.PI/180;var r=new m;return r.m21=r.c=Math.tan(t),r},m.SkewY=function(t){t*=Math.PI/180;var r=new m;return r.m12=r.b=Math.tan(t),r},m.Multiply=function(t,r){var e=r.m11*t.m11+r.m12*t.m21+r.m13*t.m31+r.m14*t.m41,n=r.m11*t.m12+r.m12*t.m22+r.m13*t.m32+r.m14*t.m42,i=r.m11*t.m13+r.m12*t.m23+r.m13*t.m33+r.m14*t.m43,o=r.m11*t.m14+r.m12*t.m24+r.m13*t.m34+r.m14*t.m44,a=r.m21*t.m11+r.m22*t.m21+r.m23*t.m31+r.m24*t.m41,u=r.m21*t.m12+r.m22*t.m22+r.m23*t.m32+r.m24*t.m42,s=r.m21*t.m13+r.m22*t.m23+r.m23*t.m33+r.m24*t.m43,f=r.m21*t.m14+r.m22*t.m24+r.m23*t.m34+r.m24*t.m44,l=r.m31*t.m11+r.m32*t.m21+r.m33*t.m31+r.m34*t.m41,y=r.m31*t.m12+r.m32*t.m22+r.m33*t.m32+r.m34*t.m42,c=r.m31*t.m13+r.m32*t.m23+r.m33*t.m33+r.m34*t.m43,p=r.m31*t.m14+r.m32*t.m24+r.m33*t.m34+r.m34*t.m44,h=r.m41*t.m11+r.m42*t.m21+r.m43*t.m31+r.m44*t.m41,d=r.m41*t.m12+r.m42*t.m22+r.m43*t.m32+r.m44*t.m42,M=r.m41*t.m13+r.m42*t.m23+r.m43*t.m33+r.m44*t.m43,x=r.m41*t.m14+r.m42*t.m24+r.m43*t.m34+r.m44*t.m44;return new m([e,a,l,h,n,u,y,d,i,s,c,M,o,f,p,x])},m.fromMatrix=function(t){return new m([t.m11,t.m21,t.m31,t.m41,t.m12,t.m22,t.m32,t.m42,t.m13,t.m23,t.m33,t.m43,t.m14,t.m24,t.m34,t.m44])},m.fromArray=function(t){return feedFromArray(new m,t)},m.feedFromArray=function(m,t){var r=Array.from(t);if(16==r.length)m.m11=m.a=r[0],m.m21=m.c=r[1],m.m31=r[2],m.m41=m.e=r[3],m.m12=m.b=r[4],m.m22=m.d=r[5],m.m32=r[6],m.m42=m.f=r[7],m.m13=r[8],m.m23=r[9],m.m33=r[10],m.m43=r[11],m.m14=r[12],m.m24=r[13],m.m34=r[14],m.m44=r[15];else{if(6!=r.length)throw new TypeError("CSSMatrix: expecting a 6/16 values Array");m.m11=m.a=r[0],m.m12=m.b=r[1],m.m14=m.e=r[4],m.m21=m.c=r[2],m.m22=m.d=r[3],m.m24=m.f=r[5]}return m},m})); | ||
// DOMMatrix v0.0.4e | thednp © 2021 | 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,t,n){var r=new u;return r.m41=r.e=m,r.m42=r.f=t,r.m43=n,r}function t(m,t,n){var r=new u;m*=Math.PI/180,t*=Math.PI/180,n*=Math.PI/180;var e=Math.cos(m),i=-Math.sin(m),o=Math.cos(t),a=-Math.sin(t),s=Math.cos(n),f=-Math.sin(n);return r.m11=r.a=o*s,r.m12=r.b=-o*f,r.m13=a,r.m21=r.c=i*a*s+e*f,r.m22=r.d=e*s-i*a*f,r.m23=-i*o,r.m31=i*f-e*a*s,r.m32=i*s+e*a*f,r.m33=e*o,r}function n(m,t,n,r){r*=Math.PI/360;var e=Math.sin(r),i=Math.cos(r),o=e*e,a=Math.sqrt(m*m+t*t+n*n);0===a?(m=0,t=0,n=1):(m/=a,t/=a,n/=a);var s=m*m,f=t*t,c=n*n,h=new u;return h.m11=h.a=1-2*(f+c)*o,h.m12=h.b=2*(m*t*o+n*e*i),h.m13=2*(m*n*o-t*e*i),h.m21=h.c=2*(t*m*o-n*e*i),h.m22=h.d=1-2*(c+s)*o,h.m23=2*(t*n*o+m*e*i),h.m31=2*(n*m*o+t*e*i),h.m32=2*(n*t*o-m*e*i),h.m33=1-2*(s+f)*o,h.m14=h.m24=h.m34=0,h.m41=h.e=h.m42=h.f=h.m43=0,h.m44=1,h}function r(m,t,n){var r=new u;return r.m11=r.a=m,r.m22=r.d=t,r.m33=n,r}function e(m){m*=Math.PI/180;var t=new u;return t.m21=t.c=Math.tan(m),t}function i(m){m*=Math.PI/180;var t=new u;return t.m12=t.b=Math.tan(m),t}function o(m,t){var n=t.m11*m.m11+t.m12*m.m21+t.m13*m.m31+t.m14*m.m41,r=t.m11*m.m12+t.m12*m.m22+t.m13*m.m32+t.m14*m.m42,e=t.m11*m.m13+t.m12*m.m23+t.m13*m.m33+t.m14*m.m43,i=t.m11*m.m14+t.m12*m.m24+t.m13*m.m34+t.m14*m.m44,o=t.m21*m.m11+t.m22*m.m21+t.m23*m.m31+t.m24*m.m41,a=t.m21*m.m12+t.m22*m.m22+t.m23*m.m32+t.m24*m.m42,s=t.m21*m.m13+t.m22*m.m23+t.m23*m.m33+t.m24*m.m43,f=t.m21*m.m14+t.m22*m.m24+t.m23*m.m34+t.m24*m.m44,c=t.m31*m.m11+t.m32*m.m21+t.m33*m.m31+t.m34*m.m41,h=t.m31*m.m12+t.m32*m.m22+t.m33*m.m32+t.m34*m.m42,l=t.m31*m.m13+t.m32*m.m23+t.m33*m.m33+t.m34*m.m43,y=t.m31*m.m14+t.m32*m.m24+t.m33*m.m34+t.m34*m.m44,p=t.m41*m.m11+t.m42*m.m21+t.m43*m.m31+t.m44*m.m41,d=t.m41*m.m12+t.m42*m.m22+t.m43*m.m32+t.m44*m.m42,x=t.m41*m.m13+t.m42*m.m23+t.m43*m.m33+t.m44*m.m43,w=t.m41*m.m14+t.m42*m.m24+t.m43*m.m34+t.m44*m.m44;return new u([n,o,c,p,r,a,h,d,e,s,l,x,i,f,y,w])}function a(m,t){var n=Array.from(t);if(16==n.length)m.m11=m.a=n[0],m.m21=m.c=n[1],m.m31=n[2],m.m41=m.e=n[3],m.m12=m.b=n[4],m.m22=m.d=n[5],m.m32=n[6],m.m42=m.f=n[7],m.m13=n[8],m.m23=n[9],m.m33=n[10],m.m43=n[11],m.m14=n[12],m.m24=n[13],m.m34=n[14],m.m44=n[15];else{if(6!=n.length)throw new TypeError("CSSMatrix: expecting a 6/16 values Array");m.m11=m.a=n[0],m.m12=m.b=n[1],m.m14=m.e=n[4],m.m21=m.c=n[2],m.m22=m.d=n[3],m.m24=m.f=n[5]}return m}var u=function(){for(var m=[],t=arguments.length;t--;)m[t]=arguments[t];return this.setIdentity(),m&&m.length&&this.setMatrixValue(m)},s={isIdentity:{configurable:!0},is2D:{configurable:!0}};return u.prototype.setMatrixValue=function(m){var t=this;if(!m||!m.length)return t;if(m.length&&"string"==typeof m[0]&&m[0].length){var n,r,e=String(m[0]).trim();if("none"==e)return t;if(n=e.slice(0,e.indexOf("(")),r=e.slice("matrix"===n?7:9,-1).split(",").map((function(m){return Math.abs(m)<1e-6?0:+m})),!([6,16].indexOf(r.length)>-1))throw new TypeError("CSSMatrix: expecting valid CSS matrix() / matrix3d() syntax");a(t,r)}else m[0]instanceof u?a(t,m[0].toArray()):Array.isArray(m[0])?a(t,m[0]):Array.isArray(m)&&a(t,m);return t},u.prototype.toString=function(){return(this.is2D?"matrix":"matrix3d")+"("+this.toArray(1).join(",")+")"},u.prototype.toArray=function(m){var t=this;return t.is2D?[t.a,t.b,t.c,t.d,t.e,t.f]:m?[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]:[t.m11,t.m21,t.m31,t.m41,t.m12,t.m22,t.m32,t.m42,t.m13,t.m23,t.m33,t.m43,t.m14,t.m24,t.m34,t.m44]},u.prototype.multiply=function(m){return o(this,m)},u.prototype.translate=function(t,n,r){return null==r&&(r=0),null==n&&(n=0),o(this,m(t,n,r))},u.prototype.scale=function(m,t,n){return null==t&&(t=m),null==n&&(n=m),o(this,r(m,t,n))},u.prototype.rotate=function(m,n,r){return null==n&&(n=0),null==r&&(r=m,m=0),o(this,t(m,n,r))},u.prototype.rotateAxisAngle=function(m,t,r,e){if(4!==arguments.length)throw new TypeError("CSSMatrix: expecting 4 values");return o(this,n(m,t,r,e))},u.prototype.skewX=function(m){return o(this,e(m))},u.prototype.skewY=function(m){return o(this,i(m))},u.prototype.setIdentity=function(){return a(this,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])},s.isIdentity.get=function(){var m=this;return 1==m.m11&&0==m.m12&&0==m.m13&&0==m.m14&&0==m.m21&&1==m.m22&&0==m.m23&&0==m.m24&&0==m.m31&&0==m.m32&&1==m.m33&&0==m.m34&&0==m.m41&&0==m.m42&&0==m.m43&&1==m.m44},s.isIdentity.set=function(m){this.isIdentity=m},s.is2D.get=function(){var m=this;return 0==m.m31&&0==m.m32&&1==m.m33&&0==m.m34&&0==m.m43&&1==m.m44},s.is2D.set=function(m){this.is2D=m},u.prototype.transformPoint=function(t){var n=m(t.x,t.y,t.z);return n.m44=t.w||1,{x:(n=this.multiply(n)).m41,y:n.m42,z:n.m43,w:n.m44}},u.prototype.transform=function(m){var t=this,n=t.m11*m.x+t.m12*m.y+t.m13*m.z+t.m14*m.w,r=t.m21*m.x+t.m22*m.y+t.m23*m.z+t.m24*m.w,e=t.m31*m.x+t.m32*m.y+t.m33*m.z+t.m34*m.w,i=t.m41*m.x+t.m42*m.y+t.m43*m.z+t.m44*m.w;return{x:n/i,y:r/i,z:e/i,w:i}},Object.defineProperties(u.prototype,s),u.Translate=m,u.Rotate=t,u.RotateAxisAngle=n,u.Scale=r,u.SkewX=e,u.SkewY=i,u.Multiply=o,u.fromMatrix=function(m){return new u([m.m11,m.m21,m.m31,m.m41,m.m12,m.m22,m.m32,m.m42,m.m13,m.m23,m.m33,m.m43,m.m14,m.m24,m.m34,m.m44])},u.fromArray=function(m){return a(new u,m)},u.feedFromArray=a,u})); |
{ | ||
"name": "dommatrix", | ||
"version": "0.0.4d", | ||
"version": "0.0.4e", | ||
"description": "ES6+ shim for DOMMatrix", | ||
@@ -5,0 +5,0 @@ "main": "dist/dommatrix.min.js", |
321
README.md
@@ -11,320 +11,5 @@ # DOMMatrix shim | ||
# WIKI | ||
Head over to the [wiki pages](https://github.com/thednp/DOMMatrix/wiki) for developer guidelines. | ||
# Install | ||
``` | ||
npm install dommatrix | ||
``` | ||
# CDN | ||
Link available on [jsdelivr](https://www.jsdelivr.com/package/npm/dommatrix). | ||
# Standard Methods | ||
Main instance methods described in the [MDN specifications](https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix). | ||
## translate(*x, y, z*) | ||
The translate method returns a new matrix which is this matrix post multiplied by a translation matrix containing the passed values. If the `z` parameter is undefined, a 0 value is used in its place. This matrix is not | ||
modified. | ||
Parameters: | ||
* `x` the X axis component of the translation value. | ||
* `y` the Y axis component of the translation value. | ||
* `z` the Z axis component of the translation value. | ||
## rotate(*rx, ry, rz*) | ||
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 expected to be in degrees. This matrix is not modified. | ||
Parameters: | ||
* `rx` the X axis component of the rotation value. | ||
* `ry` the Y axis component of the rotation value. | ||
* `rz` the Z axis component of the rotation value. | ||
## rotateAxisAngle(*x, y, z, angle*) | ||
This 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. | ||
Parameters: | ||
* `x` The X component of the axis vector. | ||
* `y` The Y component of the axis vector. | ||
* `z` The Z component of the axis vector. | ||
* `angle` The angle of rotation about the axis vector, in degrees. | ||
## scale(*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. | ||
Parameters: | ||
* `x` the X axis component of the scale value. | ||
* `y` the Y axis component of the scale value. | ||
* `z` the Z axis component of the scale value. | ||
## skewX(*angle*) | ||
Specifies a skew transformation along the `x-axis` by the given angle. This matrix is not modified. | ||
The `angle` parameter sets the amount in degrees to skew. | ||
## skewY(*angle*) | ||
Specifies a skew transformation along the `y-axis` by the given angle. This matrix is not modified. | ||
The `angle` parameter sets the amount in degrees to skew. | ||
## toString() | ||
Creates and returns a string representation of the matrix in CSS matrix syntax, using the appropriate CSS matrix notation. | ||
The 16 items in the array 3D matrix array are *transposed* in row-major order. | ||
Depending on the value of `is2D`, the method will return the CSS matrix syntax in one of the two formats: | ||
* `matrix3d(m11,m12,m13,m14,m21,m22,m23,m24,m31,m32,m33,m34,m41,m42,m43,m44)` | ||
* `matrix(a, b, c, d, e, f)` | ||
# Additional Methods | ||
## multiply(*m2*) | ||
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 as well as the one passed are not modified. | ||
The `m2` parameter is expecting a `CSSMatrix` or `DOMMatrix` instance. | ||
## setMatrixValue(*string*) | ||
This method replaces the existing matrix with one computed in the browser. EG: `matrix(1,0.25,-0.25,1,0,0)`. | ||
The method also accepts 6/16 elements *Float64Array* / *Float32Array* / *Array* values, the result of `CSSMatrix` => `toArray()` / `DOMMatrix` => `toFloat64Array()` / `toFloat32Array()`. | ||
For simplicity reasons, this method expects only valid *matrix()* / *matrix3d()* string values, which means other transform functions like *translate()*, *rotate()* are not supported. | ||
Parameter: | ||
* The `source` parameter can be the *String* representing the CSS syntax of the matrix, which is also the result of `getComputedStyle()`. | ||
* The `source` can also be an *Array* resulted from `toArray()` method calls. | ||
## setIdentity() | ||
Set the current `CSSMatrix` instance to the identity form and returns it. | ||
## transformPoint(*point*) | ||
Transforms the specified point using the matrix, returning a new `DOMPoint` like *Object* containing the transformed point. | ||
Neither the matrix nor the original point are altered. | ||
The method is equivalent with `transformPoint()` method of the `DOMMatrix` constructor. | ||
The `point` parameter expects a `DOMPoint` or an *Object* with `x`, `y`, `z` and `w` components. | ||
## transform(*vector*) | ||
Transforms the specified vector using the matrix, returning a new `{x,y,z,w}` *Object* comprising the transformed vector. | ||
Neither the matrix nor the original vector are altered. This method was in the [original source](https://github.com/arian/CSSMatrix/) and I chose to keep it. | ||
The `vector` parameter expects an *Object* with `x`, `y`, `z` and `w` components. | ||
## toArray(*transposed*) | ||
Returns an *Array* containing all 16 elements which comprise the 3D matrix. The method can return either the elements in default column major order or row major order (what we call the *transposed* matrix, used by `toString`). | ||
If the matrix attribute `is2D` is `true`, the 6 elements array matrix is returned. | ||
Other methods make use of this method to feed their output values from this matrix. | ||
The `transposed` parameter changes the order of the elements in the output. By default the column major order is used, which is the standard representation of a typical 4x4 3D transformation matrix, however the `CSS` syntax requires the row major order, so we can set this parameter to `true` to facilitate that. | ||
There are also *toFloat64Array()* and *toFloat32Array()* which return a new `Float64Array` / `Float32Array` containing all 6/16 elements which comprise the matrix. The elements are stored into the array as double-precision floating-point numbers (`Float64Array`) or single-precision floating-point numbers (`Float32Array`), in column-major (colexographical access access or "colex") order. These last two methods are not yet present in the prototype, but are ready to go. | ||
The result can be immediatelly fed as parameter for the initialization of a new matrix. | ||
# Getters and Setters | ||
## isIdentity | ||
A `Boolean` whose value is `true` if the matrix is the identity matrix. The identity matrix is one in which every value is 0 except those on the main diagonal from top-left to bottom-right corner (in other words, where the offsets in each direction are equal). | ||
## is2D | ||
A `Boolean` flag whose value is `true` if the matrix was initialized as a 2D matrix and `false` if the matrix is 3D. | ||
# Static Methods | ||
The methods attached to the `CSSMatrix` *Object* but not included in the constructor prototype. Some methods aim to be equivalents while others provide utility. | ||
## fromMatrix(*m2*) | ||
Creates a new mutable `CSSMatrix` object given an existing matrix or a `DOMMatrix` *Object* which provides the values for its properties. The `m2` parameter is the matrix instance passed into the method and neither this matrix or the one passed are modified. | ||
## fromArray(*array*) | ||
Creates a new mutable `CSSMatrix` object given an array of values. If the array has six values, the result is a 2D matrix; if the array has 16 values, the result is a 3D matrix. Otherwise, a `console.error` is thrown and returns the current matrix. | ||
The `array` parameter is the source to feed the values for the new matrix. | ||
There are two more methods *fromFloat64Array(array)* and *fromFloat32Array(array)* which are only aliases for `fromArray` for now, but will be updated accordingly once DOMMatrix API is final. | ||
## feedFromArray(*array*) | ||
Feed a `CSSMatrix` object with the values of a 6/16 values array and returns the updated matrix. | ||
The `array` parameter is the source to feed the values for the new matrix. | ||
# Usage | ||
The initialization doesn't support CSS syntax strings with transform functions like `rotate()` or `translate()` only `matrix()` and `matrix3d()`, or 6/16 elements arrays. | ||
## Basics | ||
```js | ||
// ES6+ | ||
import CSSMatrix from 'dommatrix' | ||
// init | ||
let myMatrix = new CSSMatrix('matrix(1,0.25,-0.25,1,0,0)') | ||
``` | ||
OR | ||
```js | ||
// Node.js | ||
var CSSMatrix = require('dommatrix'); | ||
// init | ||
let myMatrix = new CSSMatrix('matrix(1,0.25,-0.25,1,0,0)') | ||
``` | ||
## Advanced API Examples** | ||
### Provide Values on Initialization | ||
```js | ||
// the above are equivalent with providing the values are arguments | ||
let myMatrix = new CSSMatrix(1,0.25,-0.25,1,0,0) | ||
// or by providing an Array, Float32Array, Float64Array | ||
let myMatrix = new CSSMatrix([1,0.25,-0.25,1,0,0]) | ||
``` | ||
### Use Static Methods to Initialize | ||
```js | ||
let myTranlateMatrix = new CSSMatrix(1,0,0,1,150,150) | ||
// fromMatrix will create a clone of the above matrix | ||
let myMatrix = CSSMatrix.fromMatrix(myTranlateMatrix) | ||
// create a new CSSMatrix from an Array, Float32Array, Float64Array | ||
let myMatrix = CSSMatrix.fromArray([1,0.25,-0.25,1,0,0]) | ||
``` | ||
### Using Main Methods | ||
```js | ||
// call methods to apply transformations | ||
let myMatrix = new CSSMatrix().translate(15) | ||
// equivalent to | ||
let myMatrix = new CSSMatrix().translate(15,0) | ||
// equivalent to | ||
let myMatrix = new CSSMatrix().translate(15,0,0) | ||
// rotations work as expected | ||
let myMatrix = new CSSMatrix().rotate(15) | ||
// equivalent to | ||
let myMatrix = new CSSMatrix().rotate(0,0,15) | ||
``` | ||
### Manipulate The Matrix values | ||
```js | ||
// reset the matrix to identity form | ||
// the equivalent of the CSS "transform: none" | ||
myMatrix.setIdentity() | ||
// replace existing matrix with values from array | ||
// it's best to use the above setIdentity() before | ||
// replacing the current matrix or feed from a 16 values Array | ||
CSSMatrix.feedFromArray(myMatrix, [1,0.25,-0.25,1,0,0]) | ||
// replace existing matrix with values from array | ||
// as if your're re-initializing the matrix | ||
myMatrix.setMatrixValue(1,0.25,-0.25,1,0,0) | ||
// apply additional transformations to an existing matrix | ||
// by calling instance methods | ||
myMatrix = myMatrix.translate(15).skewX(45) | ||
// apply additional transformations to an existing matrix | ||
// by calling a static method to create a new matrix; | ||
// the result of the multiply instance method and | ||
// the result of the Rotate static method combined create | ||
// a third CSSMatrix instance that replaces the original | ||
// matrix entirely | ||
myMatrix = myMatrix.multiply(CSSMatrix.Rotate(0,45)) | ||
``` | ||
Calling the transform function instance methods (translate,rotate) after initialization will not change the instance *Object* unless you put the "=" sign between your instance name and the return of the call. Only `setIdentity` and `setMatrixValue` instance methods as well as the `feedFromArray` static method can do that. | ||
### Exporting The Matrix | ||
```js | ||
// export to the CSS syntax transform | ||
let myMatrix = new CSSMatrix().translate(15).toString() | ||
// export to Array | ||
let myMatrix = new CSSMatrix().rotate(45).toArray() | ||
// if the matrix is 3D you can also export a transposed matrix array | ||
// which is compatible with the CSS syntax row major order representation | ||
let myMatrix = new CSSMatrix().translate(15,0,0).toArray(true) | ||
``` | ||
### Adding Perspective To Matrix | ||
```js | ||
import CSSMatrix from 'dommatrix' | ||
// perspective | ||
let perspective = 400 | ||
// init | ||
let myMatrix = new CSSMatrix() | ||
// set perspective | ||
myMatrix.m34 = -1/perspective | ||
// now your matrix is always 3D | ||
// we can apply any 3D transformation | ||
myMatrix = myMatrix.rotate(45,0,0) | ||
// this matrix is now equivalent with this | ||
// CSS transformation syntax | ||
// perspective(400px) rotateX(45deg) | ||
``` | ||
# More Info | ||
@@ -355,2 +40,2 @@ In contrast with the [original source](https://github.com/arian/CSSMatrix/) there have been a series of changes to the prototype for consistency, performance as well as requirements to better accomodate the **DOMMatrix** interface: | ||
# License | ||
DOMMatrix shim is [MIT Licensed](https://github.com/thednp/DOMMatrix/blob/master/LICENSE). | ||
DOMMatrix shim is [MIT Licensed](https://github.com/thednp/DOMMatrix/blob/master/LICENSE). |
609
src/index.js
@@ -16,2 +16,300 @@ /** | ||
// Transform Functions | ||
// https://www.w3.org/TR/css-transforms-1/#transform-functions | ||
/** | ||
* Creates a new `CSSMatrix` for the translation matrix and returns it. | ||
* This method is equivalent to the CSS `translate3d()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate3d | ||
* | ||
* @param {Number} x the `x-axis` position. | ||
* @param {Number} y the `y-axis` position. | ||
* @param {Number} z the `z-axis` position. | ||
*/ | ||
function Translate(x, y, z){ | ||
let m = new CSSMatrix(); | ||
m.m41 = m.e = x; | ||
m.m42 = m.f = y; | ||
m.m43 = z; | ||
return m | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the rotation matrix and returns it. | ||
* | ||
* http://en.wikipedia.org/wiki/Rotation_matrix | ||
* | ||
* @param {Number} rx the `x-axis` rotation. | ||
* @param {Number} ry the `y-axis` rotation. | ||
* @param {Number} rz the `z-axis` rotation. | ||
*/ | ||
function Rotate(rx, ry, rz){ | ||
let m = new CSSMatrix() | ||
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), | ||
cosy = Math.cos(ry), siny = -Math.sin(ry), | ||
cosz = Math.cos(rz), sinz = -Math.sin(rz); | ||
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 | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the rotation matrix and returns it. | ||
* This method is equivalent to the CSS `rotate3d()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate3d | ||
* | ||
* @param {Number} x the `x-axis` vector length. | ||
* @param {Number} y the `y-axis` vector length. | ||
* @param {Number} z the `z-axis` vector length. | ||
* @param {Number} angle the value in degrees of the rotation. | ||
*/ | ||
function RotateAxisAngle(x, y, z, angle){ | ||
angle *= Math.PI / 360; | ||
let sinA = Math.sin(angle), | ||
cosA = Math.cos(angle), | ||
sinA2 = sinA * sinA, | ||
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 | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the scale matrix and returns it. | ||
* This method is equivalent to the CSS `scale3d()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scale3d | ||
* | ||
* @param {Number} x the `x-axis` scale. | ||
* @param {Number} y the `y-axis` scale. | ||
* @param {Number} z the `z-axis` scale. | ||
*/ | ||
function Scale(x, y, z){ | ||
let m = new CSSMatrix(); | ||
m.m11 = m.a = x; | ||
m.m22 = m.d = y; | ||
m.m33 = z; | ||
return m | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the shear of the `x-axis` rotation matrix and | ||
* returns it. This method is equivalent to the CSS `skewX()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skewX | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
*/ | ||
function SkewX(angle){ | ||
angle *= Math.PI / 180; | ||
let m = new CSSMatrix(); | ||
m.m21 = m.c = Math.tan(angle); | ||
return m | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the shear of the `y-axis` rotation matrix and | ||
* returns it. This method is equivalent to the CSS `skewY()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skewY | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
*/ | ||
function SkewY(angle){ | ||
angle *= Math.PI / 180; | ||
let m = new CSSMatrix(); | ||
m.m12 = m.b = Math.tan(angle); | ||
return m | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` resulted from the multiplication of two matrixes | ||
* and returns it. Both matrixes are not changed. | ||
* | ||
* @param {CSSMatrix} m1 the first matrix. | ||
* @param {CSSMatrix} m2 the second matrix. | ||
*/ | ||
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, m21, m31, m41, | ||
m12, m22, m32, m42, | ||
m13, m23, m33, m43, | ||
m14, m24, m34, m44]) | ||
} | ||
/** | ||
* Returns a new *Float32Array* containing all 16 elements which comprise the matrix. | ||
* The elements are stored into the array as single-precision floating-point numbers | ||
* in column-major (colexographical access access or "colex") order. | ||
* | ||
* @return {Float32Array} matrix elements (m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44) | ||
*/ | ||
// toFloat32Array(){ | ||
// return Float32Array.from(this.toArray()) | ||
// } | ||
/** | ||
* Returns a new Float64Array containing all 16 elements which comprise the matrix. | ||
* The elements are stored into the array as double-precision floating-point numbers | ||
* in column-major (colexographical access access or "colex") order. | ||
* | ||
* @return {Float64Array} matrix elements (m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44) | ||
*/ | ||
// toFloat64Array(){ | ||
// return Float64Array.from(this.toArray()) | ||
// } | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an existing matrix or a | ||
* `DOMMatrix` *Object* which provides the values for its properties. | ||
* | ||
* @param {CSSMatrix} CSSMatrix the source `CSSMatrix` / `DOMMatrix` initialization to feed values from | ||
*/ | ||
function fromMatrix(m){ | ||
return new CSSMatrix( | ||
// DOMMatrix elements order | ||
[m.m11, m.m21, m.m31, m.m41, | ||
m.m12, m.m22, m.m32, m.m42, | ||
m.m13, m.m23, m.m33, m.m43, | ||
m.m14, m.m24, m.m34, m.m44]) | ||
} | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an array float values. | ||
* | ||
* If the array has six values, the result is a 2D matrix; if the array has 16 values, | ||
* the result is a 3D matrix. Otherwise, a TypeError exception is thrown. | ||
* | ||
* @param {Array} array The source `Array` to feed values from. | ||
* @return {CSSMatrix} a The source array to feed values from. | ||
*/ | ||
function fromArray(a){ | ||
return feedFromArray(new CSSMatrix(),a) | ||
} | ||
/** | ||
* Each create a new mutable `CSSMatrix` object given an array of single/double-precision | ||
* (32/64 bit) floating-point values. | ||
* | ||
* If the array has six values, the result is a 2D matrix; if the array has 16 values, | ||
* the result is a 3D matrix. Otherwise, a TypeError exception is thrown. | ||
* | ||
* @param {Float32Array|Float64Array} array The source `Float32Array` / `Float64Array` to feed values from. | ||
* @return {CSSMatrix} a The source array to feed values from. | ||
*/ | ||
// more of an alias for now, will update later if it's the case | ||
// function fromFloat32Array(a){ | ||
// return feedFromArray(new CSSMatrix(),a) | ||
// } | ||
// function fromFloat64Array(a){ // more of an alias | ||
// return feedFromArray(new CSSMatrix(),a) | ||
// } | ||
/** | ||
* Feed a CSSMatrix object with the values of a 6/16 values array and returns it. | ||
* | ||
* @param {Array} array The source `Array` to feed values from. | ||
* @return {CSSMatrix} a The source array to feed values from. | ||
*/ | ||
function feedFromArray(m,array){ | ||
let a = Array.from(array) | ||
if (a.length == 16){ | ||
m.m11 = m.a = a[0]; | ||
m.m21 = m.c = a[1]; | ||
m.m31 = a[2]; | ||
m.m41 = m.e = a[3]; | ||
m.m12 = m.b = a[4]; | ||
m.m22 = m.d = a[5]; | ||
m.m32 = a[6]; | ||
m.m42 = m.f = a[7]; | ||
m.m13 = a[8]; | ||
m.m23 = a[9]; | ||
m.m33 = a[10]; | ||
m.m43 = a[11]; | ||
m.m14 = a[12]; | ||
m.m24 = a[13]; | ||
m.m34 = a[14]; | ||
m.m44 = a[15]; | ||
} else if (a.length == 6) { | ||
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 { | ||
throw new TypeError(`CSSMatrix: expecting a 6/16 values Array`) | ||
} | ||
return m | ||
} | ||
export default class CSSMatrix { | ||
@@ -314,3 +612,3 @@ constructor(...args){ | ||
*/ | ||
transform(t){ | ||
transform(t){ | ||
let m = this, | ||
@@ -321,3 +619,3 @@ x = m.m11 * t.x + m.m12 * t.y + m.m13 * t.z + m.m14 * t.w, | ||
w = m.m41 * t.x + m.m42 * t.y + m.m43 * t.z + m.m44 * t.w | ||
return { | ||
@@ -329,300 +627,15 @@ x: x / w, | ||
} | ||
} | ||
} | ||
} | ||
// Transform Functions | ||
// https://www.w3.org/TR/css-transforms-1/#transform-functions | ||
/** | ||
* Creates a new `CSSMatrix` for the translation matrix and returns it. | ||
* This method is equivalent to the CSS `translate3d()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate3d | ||
* | ||
* @param {Number} x the `x-axis` position. | ||
* @param {Number} y the `y-axis` position. | ||
* @param {Number} z the `z-axis` position. | ||
*/ | ||
CSSMatrix.Translate = function Translate(x, y, z){ | ||
let m = new CSSMatrix(); | ||
m.m41 = m.e = x; | ||
m.m42 = m.f = y; | ||
m.m43 = z; | ||
return m | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the rotation matrix and returns it. | ||
* | ||
* http://en.wikipedia.org/wiki/Rotation_matrix | ||
* | ||
* @param {Number} rx the `x-axis` rotation. | ||
* @param {Number} ry the `y-axis` rotation. | ||
* @param {Number} rz the `z-axis` rotation. | ||
*/ | ||
CSSMatrix.Rotate = function Rotate(rx, ry, rz){ | ||
let m = new CSSMatrix() | ||
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), | ||
cosy = Math.cos(ry), siny = -Math.sin(ry), | ||
cosz = Math.cos(rz), sinz = -Math.sin(rz); | ||
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 | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the rotation matrix and returns it. | ||
* This method is equivalent to the CSS `rotate3d()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate3d | ||
* | ||
* @param {Number} x the `x-axis` vector length. | ||
* @param {Number} y the `y-axis` vector length. | ||
* @param {Number} z the `z-axis` vector length. | ||
* @param {Number} angle the value in degrees of the rotation. | ||
*/ | ||
CSSMatrix.RotateAxisAngle = function RotateAxisAngle(x, y, z, angle){ | ||
angle *= Math.PI / 360; | ||
let sinA = Math.sin(angle), | ||
cosA = Math.cos(angle), | ||
sinA2 = sinA * sinA, | ||
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 | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the scale matrix and returns it. | ||
* This method is equivalent to the CSS `scale3d()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scale3d | ||
* | ||
* @param {Number} x the `x-axis` scale. | ||
* @param {Number} y the `y-axis` scale. | ||
* @param {Number} z the `z-axis` scale. | ||
*/ | ||
CSSMatrix.Scale = function Scale(x, y, z){ | ||
let m = new CSSMatrix(); | ||
m.m11 = m.a = x; | ||
m.m22 = m.d = y; | ||
m.m33 = z; | ||
return m | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the shear of the `x-axis` rotation matrix and | ||
* returns it. This method is equivalent to the CSS `skewX()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skewX | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
*/ | ||
CSSMatrix.SkewX = function SkewX(angle){ | ||
angle *= Math.PI / 180; | ||
let m = new CSSMatrix(); | ||
m.m21 = m.c = Math.tan(angle); | ||
return m | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` for the shear of the `y-axis` rotation matrix and | ||
* returns it. This method is equivalent to the CSS `skewY()` function. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skewY | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
*/ | ||
CSSMatrix.SkewY = function SkewY(angle){ | ||
angle *= Math.PI / 180; | ||
let m = new CSSMatrix(); | ||
m.m12 = m.b = Math.tan(angle); | ||
return m | ||
} | ||
/** | ||
* Creates a new `CSSMatrix` resulted from the multiplication of two matrixes | ||
* and returns it. Both matrixes are not changed. | ||
* | ||
* @param {CSSMatrix} m1 the first matrix. | ||
* @param {CSSMatrix} m2 the second matrix. | ||
*/ | ||
CSSMatrix.Multiply = 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, m21, m31, m41, | ||
m12, m22, m32, m42, | ||
m13, m23, m33, m43, | ||
m14, m24, m34, m44]) | ||
} | ||
/** | ||
* Returns a new *Float32Array* containing all 16 elements which comprise the matrix. | ||
* The elements are stored into the array as single-precision floating-point numbers | ||
* in column-major (colexographical access access or "colex") order. | ||
* | ||
* @return {Float32Array} matrix elements (m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44) | ||
*/ | ||
// toFloat32Array(){ | ||
// return Float32Array.from(this.toArray()) | ||
// } | ||
/** | ||
* Returns a new Float64Array containing all 16 elements which comprise the matrix. | ||
* The elements are stored into the array as double-precision floating-point numbers | ||
* in column-major (colexographical access access or "colex") order. | ||
* | ||
* @return {Float64Array} matrix elements (m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44) | ||
*/ | ||
// toFloat64Array(){ | ||
// return Float64Array.from(this.toArray()) | ||
// } | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an existing matrix or a | ||
* `DOMMatrix` *Object* which provides the values for its properties. | ||
* | ||
* @param {CSSMatrix} CSSMatrix the source `CSSMatrix` / `DOMMatrix` initialization to feed values from | ||
*/ | ||
CSSMatrix.fromMatrix = function fromMatrix(m){ | ||
return new CSSMatrix( | ||
// DOMMatrix elements order | ||
[m.m11, m.m21, m.m31, m.m41, | ||
m.m12, m.m22, m.m32, m.m42, | ||
m.m13, m.m23, m.m33, m.m43, | ||
m.m14, m.m24, m.m34, m.m44]) | ||
} | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an array float values. | ||
* | ||
* If the array has six values, the result is a 2D matrix; if the array has 16 values, | ||
* the result is a 3D matrix. Otherwise, a TypeError exception is thrown. | ||
* | ||
* @param {Array} array The source `Array` to feed values from. | ||
* @return {CSSMatrix} a The source array to feed values from. | ||
*/ | ||
CSSMatrix.fromArray = function fromArray(a){ | ||
return feedFromArray(new CSSMatrix(),a) | ||
} | ||
/** | ||
* Each create a new mutable `CSSMatrix` object given an array of single/double-precision | ||
* (32/64 bit) floating-point values. | ||
* | ||
* If the array has six values, the result is a 2D matrix; if the array has 16 values, | ||
* the result is a 3D matrix. Otherwise, a TypeError exception is thrown. | ||
* | ||
* @param {Float32Array|Float64Array} array The source `Float32Array` / `Float64Array` to feed values from. | ||
* @return {CSSMatrix} a The source array to feed values from. | ||
*/ | ||
// more of an alias for now, will update later if it's the case | ||
// function fromFloat32Array(a){ | ||
// return feedFromArray(new CSSMatrix(),a) | ||
// } | ||
// function fromFloat64Array(a){ // more of an alias | ||
// return feedFromArray(new CSSMatrix(),a) | ||
// } | ||
/** | ||
* Feed a CSSMatrix object with the values of a 6/16 values array and returns it. | ||
* | ||
* @param {Array} array The source `Array` to feed values from. | ||
* @return {CSSMatrix} a The source array to feed values from. | ||
*/ | ||
CSSMatrix.feedFromArray = function feedFromArray(m,array){ | ||
let a = Array.from(array) | ||
if (a.length == 16){ | ||
m.m11 = m.a = a[0]; | ||
m.m21 = m.c = a[1]; | ||
m.m31 = a[2]; | ||
m.m41 = m.e = a[3]; | ||
m.m12 = m.b = a[4]; | ||
m.m22 = m.d = a[5]; | ||
m.m32 = a[6]; | ||
m.m42 = m.f = a[7]; | ||
m.m13 = a[8]; | ||
m.m23 = a[9]; | ||
m.m33 = a[10]; | ||
m.m43 = a[11]; | ||
m.m14 = a[12]; | ||
m.m24 = a[13]; | ||
m.m34 = a[14]; | ||
m.m44 = a[15]; | ||
} else if (a.length == 6) { | ||
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 { | ||
throw new TypeError(`CSSMatrix: expecting a 6/16 values Array`) | ||
} | ||
return m | ||
} | ||
CSSMatrix.Translate = Translate | ||
CSSMatrix.Rotate = Rotate | ||
CSSMatrix.RotateAxisAngle = RotateAxisAngle | ||
CSSMatrix.Scale = Scale | ||
CSSMatrix.SkewX = SkewX | ||
CSSMatrix.SkewY = SkewY | ||
CSSMatrix.Multiply = Multiply | ||
CSSMatrix.fromMatrix = fromMatrix | ||
CSSMatrix.fromArray = fromArray | ||
CSSMatrix.feedFromArray = feedFromArray |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
1181
57889
40
2