Comparing version 0.0.13 to 0.0.14
/*! | ||
* DOMMatrix v0.0.13 (https://thednp.github.io/DOMMatrix/) | ||
* DOMMatrix v0.0.14 (https://thednp.github.io/DOMMatrix/) | ||
* Copyright 2021 © thednp | ||
@@ -13,11 +13,16 @@ * Licensed under MIT (https://github.com/thednp/DOMMatrix/blob/master/LICENSE) | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an array float values. | ||
* Creates a new mutable `CSSMatrix` object given an array of floating point values. | ||
* | ||
* This static method invalidates arrays that contain non-number elements. | ||
* | ||
* 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 {Number[]} array an `Array` to feed values from. | ||
* @param {number[]} array an `Array` to feed values from. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromArray(array) { | ||
if (!array.every((n) => !Number.isNaN(n))) { | ||
throw TypeError(`CSSMatrix: "${array}" must only have numbers.`); | ||
} | ||
const m = new CSSMatrix(); | ||
@@ -83,3 +88,3 @@ const a = Array.from(array); | ||
} else { | ||
throw new TypeError('CSSMatrix: expecting a 6/16 values Array'); | ||
throw new TypeError('CSSMatrix: expecting an Array of 6/16 values.'); | ||
} | ||
@@ -90,9 +95,12 @@ return m; | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an existing matrix or a | ||
* `DOMMatrix` *Object* which provides the values for its properties. | ||
* Creates a new mutable `CSSMatrix` instance given an existing matrix or a | ||
* `DOMMatrix` instance which provides the values for its properties. | ||
* | ||
* @param {CSSMatrix | DOMMatrix} m the source matrix to feed values from. | ||
* @param {CSSMatrix | DOMMatrix | jsonMatrix} m the source matrix to feed values from. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromMatrix(m) { | ||
if (![CSSMatrix, DOMMatrix, Object].some((x) => m instanceof x)) { | ||
throw TypeError(`CSSMatrix: "${m}" is not a DOMMatrix / CSSMatrix compatible object.`); | ||
} | ||
return fromArray( | ||
@@ -107,7 +115,10 @@ [m.m11, m.m12, m.m13, m.m14, | ||
/** | ||
* Feed a CSSMatrix object with a valid CSS transform value. | ||
* * matrix(a, b, c, d, e, f) - valid matrix() transform function | ||
* * matrix3d(m11, m12, m13, ...m44) - valid matrix3d() transform function | ||
* * translate(tx, ty) rotateX(alpha) - any valid transform function(s) | ||
* Creates a new mutable `CSSMatrix` instance given any valid CSS transform string. | ||
* | ||
* * `matrix(a, b, c, d, e, f)` - valid matrix() transform function | ||
* * `matrix3d(m11, m12, m13, ...m44)` - valid matrix3d() transform function | ||
* * `translate(tx, ty) rotateX(alpha)` - any valid transform function(s) | ||
* | ||
* @copyright thednp © 2021 | ||
* | ||
* @param {string} source valid CSS transform string syntax. | ||
@@ -117,2 +128,5 @@ * @return {CSSMatrix} the resulted matrix. | ||
function fromString(source) { | ||
if (typeof source !== 'string') { | ||
throw TypeError(`CSSMatrix: "${source}" is not a string.`); | ||
} | ||
const str = String(source).replace(/\s/g, ''); | ||
@@ -125,13 +139,2 @@ let m = new CSSMatrix(); | ||
.map((n) => (n.includes('rad') ? parseFloat(n) * (180 / Math.PI) : parseFloat(n))); | ||
const [x, y, z, a] = components; | ||
// don't add perspective if is2D | ||
if (prop === 'matrix3d' | ||
|| (prop === 'rotate3d' && [x, y].every((n) => !Number.isNaN(+n) && n !== 0) && a) | ||
|| (['rotateX', 'rotateY'].includes(prop) && x) | ||
|| (prop === 'translate3d' && [x, y, z].every((n) => !Number.isNaN(+n)) && z) | ||
|| (prop === 'scale3d' && [x, y, z].every((n) => !Number.isNaN(+n) && n !== x)) | ||
) { | ||
is2D = false; | ||
} | ||
return { prop, components }; | ||
@@ -198,5 +201,5 @@ }); | ||
* | ||
* @param {Number} x the `x-axis` position. | ||
* @param {Number} y the `y-axis` position. | ||
* @param {Number} z the `z-axis` position. | ||
* @param {number} x the `x-axis` position. | ||
* @param {number} y the `y-axis` position. | ||
* @param {number} z the `z-axis` position. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -219,5 +222,5 @@ */ | ||
* | ||
* @param {Number} rx the `x-axis` rotation. | ||
* @param {Number} ry the `y-axis` rotation. | ||
* @param {Number} rz the `z-axis` rotation. | ||
* @param {number} rx the `x-axis` rotation. | ||
* @param {number} ry the `y-axis` rotation. | ||
* @param {number} rz the `z-axis` rotation. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -274,6 +277,6 @@ */ | ||
* | ||
* @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} alpha the value in degrees of the rotation. | ||
* @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} alpha the value in degrees of the rotation. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -339,5 +342,5 @@ */ | ||
* | ||
* @param {Number} x the `x-axis` scale. | ||
* @param {Number} y the `y-axis` scale. | ||
* @param {Number} z the `z-axis` scale. | ||
* @param {number} x the `x-axis` scale. | ||
* @param {number} y the `y-axis` scale. | ||
* @param {number} z the `z-axis` scale. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -363,3 +366,3 @@ */ | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
* @param {number} angle the angle in degrees. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -382,3 +385,3 @@ */ | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
* @param {number} angle the angle in degrees. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -531,3 +534,3 @@ */ | ||
* | ||
* @param {String | Number[] | CSSMatrix | DOMMatrix} source | ||
* @param {string | number[] | CSSMatrix | DOMMatrix} source | ||
* @return {CSSMatrix} the matrix instance | ||
@@ -559,3 +562,3 @@ */ | ||
* | ||
* @return {String} a string representation of the matrix | ||
* @return {string} a string representation of the matrix | ||
*/ | ||
@@ -575,3 +578,3 @@ toString() { | ||
* | ||
* @return {Number[]} an *Array* representation of the matrix | ||
* @return {number[]} an *Array* representation of the matrix | ||
*/ | ||
@@ -595,5 +598,24 @@ toArray() { | ||
} | ||
/** | ||
* @typedef {object} jsonMatrix | ||
* @property {number} m11 | ||
* @property {number} m12 | ||
* @property {number} m13 | ||
* @property {number} m14 | ||
* @property {number} m21 | ||
* @property {number} m22 | ||
* @property {number} m23 | ||
* @property {number} m24 | ||
* @property {number} m31 | ||
* @property {number} m32 | ||
* @property {number} m33 | ||
* @property {number} m34 | ||
* @property {number} m41 | ||
* @property {number} m42 | ||
* @property {number} m43 | ||
* @property {number} m44 | ||
*/ | ||
/** | ||
* Returns a JSON representation of the `CSSMatrix` object, a standard *Object* | ||
* Returns a JSON representation of the `CSSMatrix` instance, a standard *Object* | ||
* that includes `{a,b,c,d,e,f}` and `{m11,m12,m13,..m44}` properties and | ||
@@ -605,3 +627,3 @@ * excludes `is2D` & `isIdentity` properties. | ||
* | ||
* @return {Object} an *Object* with all matrix values. | ||
* @return {jsonMatrix} an *Object* with all matrix values. | ||
*/ | ||
@@ -617,3 +639,3 @@ toJSON() { | ||
* | ||
* @param {CSSMatrix | DOMMatrix} m2 CSSMatrix | ||
* @param {CSSMatrix | DOMMatrix | jsonMatrix} m2 CSSMatrix | ||
* @return {CSSMatrix} The resulted matrix. | ||
@@ -745,3 +767,3 @@ */ | ||
* | ||
* Copyright @ thednp | ||
* @copyright thednp © 2021 | ||
* | ||
@@ -748,0 +770,0 @@ * @param {Tuple | DOMPoint} v Tuple or DOMPoint |
@@ -1,2 +0,2 @@ | ||
// DOMMatrix v0.0.13 | thednp © 2021 | MIT-License | ||
function m(m){const t=new c,e=Array.from(m);if(16===e.length){const[m,r,n,s,a,i,o,l,c,u,f,h,y,p,M,d]=e;t.m11=m,t.a=m,t.m21=a,t.c=a,t.m31=c,t.m41=y,t.e=y,t.m12=r,t.b=r,t.m22=i,t.d=i,t.m32=u,t.m42=p,t.f=p,t.m13=n,t.m23=o,t.m33=f,t.m43=M,t.m14=s,t.m24=l,t.m34=h,t.m44=d}else{if(6!==e.length)throw new TypeError("CSSMatrix: expecting a 6/16 values Array");{const[m,r,n,s,a,i]=e;t.m11=m,t.a=m,t.m12=r,t.b=r,t.m21=n,t.c=n,t.m22=s,t.d=s,t.m41=a,t.e=a,t.m42=i,t.f=i}}return t}function t(t){return 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])}function e(t){const e=String(t).replace(/\s/g,"");let r=new c,n=!0;return e.split(")").filter(m=>m).map(m=>{const[t,e]=m.split("("),r=e.split(",").map(m=>m.includes("rad")?parseFloat(m)*(180/Math.PI):parseFloat(m)),[s,a,i,o]=r;return("matrix3d"===t||"rotate3d"===t&&[s,a].every(m=>!Number.isNaN(+m)&&0!==m)&&o||["rotateX","rotateY"].includes(t)&&s||"translate3d"===t&&[s,a,i].every(m=>!Number.isNaN(+m))&&i||"scale3d"===t&&[s,a,i].every(m=>!Number.isNaN(+m)&&m!==s))&&(n=!1),{prop:t,components:r}}).forEach(t=>{const{prop:e,components:s}=t,[a,i,o,l]=s,c=[a,i,o],u=[a,i,o,l];if("perspective"!==e||n)if(e.includes("matrix")){const t=s.map(m=>Math.abs(m)<1e-6?0:m);[6,16].includes(t.length)&&(r=r.multiply(m(t)))}else if(["translate","translate3d"].some(m=>e===m)&&a)r=r.translate(a,i||0,o||0);else if("rotate3d"===e&&u.every(m=>!Number.isNaN(+m))&&l)r=r.rotateAxisAngle(a,i,o,l);else if("scale3d"===e&&c.every(m=>!Number.isNaN(+m))&&c.some(m=>1!==m))r=r.scale(a,i,o);else if("rotate"===e&&a)r=r.rotate(0,0,a);else if("scale"!==e||Number.isNaN(a)||1===a){if("skew"===e&&(a||i))r=a?r.skewX(a):r,r=i?r.skewY(i):r;else if(/[XYZ]/.test(e)&&a)if(e.includes("skew"))r=r[e](a);else{const m=e.replace(/[XYZ]/,""),t=e.replace(m,""),n=["X","Y","Z"].indexOf(t),s=[0===n?a:0,1===n?a:0,2===n?a:0];r=r[m](...s)}}else{const m=Number.isNaN(+i)?a:i;r=r.scale(a,m,1)}else r.m34=-1/a}),r}function r(m,t,e){const r=new c;return r.m41=m,r.e=m,r.m42=t,r.f=t,r.m43=e,r}function n(m,t,e){const r=new c,n=Math.PI/180,s=m*n,a=t*n,i=e*n,o=Math.cos(s),l=-Math.sin(s),u=Math.cos(a),f=-Math.sin(a),h=Math.cos(i),y=-Math.sin(i),p=u*h,M=-u*y;r.m11=p,r.a=p,r.m12=M,r.b=M,r.m13=f;const d=l*f*h+o*y;r.m21=d,r.c=d;const w=o*h-l*f*y;return r.m22=w,r.d=w,r.m23=-l*u,r.m31=l*y-o*f*h,r.m32=l*h+o*f*y,r.m33=o*u,r}function s(m,t,e,r){const n=new c,s=r*(Math.PI/360),a=Math.sin(s),i=Math.cos(s),o=a*a,l=Math.sqrt(m*m+t*t+e*e);let u=m,f=t,h=e;0===l?(u=0,f=0,h=1):(u/=l,f/=l,h/=l);const y=u*u,p=f*f,M=h*h,d=1-2*(p+M)*o;n.m11=d,n.a=d;const w=2*(u*f*o+h*a*i);n.m12=w,n.b=w,n.m13=2*(u*h*o-f*a*i);const N=2*(f*u*o-h*a*i);n.m21=N,n.c=N;const x=1-2*(M+y)*o;return n.m22=x,n.d=x,n.m23=2*(f*h*o+u*a*i),n.m31=2*(h*u*o+f*a*i),n.m32=2*(h*f*o-u*a*i),n.m33=1-2*(y+p)*o,n}function a(m,t,e){const r=new c;return r.m11=m,r.a=m,r.m22=t,r.d=t,r.m33=e,r}function i(m){const t=new c,e=m*Math.PI/180,r=Math.tan(e);return t.m21=r,t.c=r,t}function o(m){const t=new c,e=m*Math.PI/180,r=Math.tan(e);return t.m12=r,t.b=r,t}function l(t,e){return m([e.m11*t.m11+e.m12*t.m21+e.m13*t.m31+e.m14*t.m41,e.m11*t.m12+e.m12*t.m22+e.m13*t.m32+e.m14*t.m42,e.m11*t.m13+e.m12*t.m23+e.m13*t.m33+e.m14*t.m43,e.m11*t.m14+e.m12*t.m24+e.m13*t.m34+e.m14*t.m44,e.m21*t.m11+e.m22*t.m21+e.m23*t.m31+e.m24*t.m41,e.m21*t.m12+e.m22*t.m22+e.m23*t.m32+e.m24*t.m42,e.m21*t.m13+e.m22*t.m23+e.m23*t.m33+e.m24*t.m43,e.m21*t.m14+e.m22*t.m24+e.m23*t.m34+e.m24*t.m44,e.m31*t.m11+e.m32*t.m21+e.m33*t.m31+e.m34*t.m41,e.m31*t.m12+e.m32*t.m22+e.m33*t.m32+e.m34*t.m42,e.m31*t.m13+e.m32*t.m23+e.m33*t.m33+e.m34*t.m43,e.m31*t.m14+e.m32*t.m24+e.m33*t.m34+e.m34*t.m44,e.m41*t.m11+e.m42*t.m21+e.m43*t.m31+e.m44*t.m41,e.m41*t.m12+e.m42*t.m22+e.m43*t.m32+e.m44*t.m42,e.m41*t.m13+e.m42*t.m23+e.m43*t.m33+e.m44*t.m43,e.m41*t.m14+e.m42*t.m24+e.m43*t.m34+e.m44*t.m44])}class c{constructor(...m){const t=this;if(t.a=1,t.b=0,t.c=0,t.d=1,t.e=0,t.f=0,t.m11=1,t.m12=0,t.m13=0,t.m14=0,t.m21=0,t.m22=1,t.m23=0,t.m24=0,t.m31=0,t.m32=0,t.m33=1,t.m34=0,t.m41=0,t.m42=0,t.m43=0,t.m44=1,m&&m.length){let e=m;return m instanceof Array&&(m[0]instanceof Array&&[16,6].includes(m[0].length)||"string"==typeof m[0]||[c,DOMMatrix].some(t=>m[0]instanceof t))&&([e]=m),t.setMatrixValue(e)}return t}set isIdentity(m){this.isIdentity=m}get isIdentity(){const 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}get is2D(){const m=this;return 0===m.m31&&0===m.m32&&1===m.m33&&0===m.m34&&0===m.m43&&1===m.m44}set is2D(m){this.is2D=m}setMatrixValue(r){return[DOMMatrix,c].some(m=>r instanceof m)?t(r):"string"==typeof r&&r.length&&"none"!==r?e(r):Array.isArray(r)?m(r):this}toString(){const m=this.toArray().join(",");return`${this.is2D?"matrix":"matrix3d"}(${m})`}toArray(){const m=this;let t;return t=m.is2D?[m.a,m.b,m.c,m.d,m.e,m.f]:[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],t.map(m=>Math.abs(m)<1e-6?0:(m*10**6>>0)/10**6)}toJSON(){return JSON.parse(JSON.stringify(this))}multiply(m){return l(this,m)}translate(m,t,e){let n=t,s=e;return null==s&&(s=0),null==n&&(n=0),l(this,r(m,n,s))}scale(m,t,e){let r=t,n=e;return null==r&&(r=m),null==n&&(n=m),l(this,a(m,r,n))}rotate(m,t,e){let r=m,s=t,a=e;return null==s&&(s=0),null==a&&(a=r,r=0),l(this,n(r,s,a))}rotateAxisAngle(m,t,e,r){if([m,t,e,r].some(m=>Number.isNaN(m)))throw new TypeError("CSSMatrix: expecting 4 values");return l(this,s(m,t,e,r))}skewX(m){return l(this,i(m))}skewY(m){return l(this,o(m))}transformPoint(m){let t=r(m.x,m.y,m.z);return t.m44=m.w||1,t=this.multiply(t),{x:t.m41,y:t.m42,z:t.m43,w:t.m44}}transform(m){const t=this,e=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,n=t.m31*m.x+t.m32*m.y+t.m33*m.z+t.m34*m.w,s=t.m41*m.x+t.m42*m.y+t.m43*m.z+t.m44*m.w;return{x:e/s,y:r/s,z:n/s,w:s}}}c.Translate=r,c.Rotate=n,c.RotateAxisAngle=s,c.Scale=a,c.SkewX=i,c.SkewY=o,c.Multiply=l,c.fromArray=m,c.fromMatrix=t,c.fromString=e;export{c as default}; | ||
// DOMMatrix v0.0.14 | thednp © 2021 | MIT-License | ||
function m(m){if(!m.every(m=>!Number.isNaN(m)))throw TypeError(`CSSMatrix: "${m}" must only have numbers.`);const t=new c,e=Array.from(m);if(16===e.length){const[m,r,n,s,i,a,o,l,c,u,f,h,y,M,p,w]=e;t.m11=m,t.a=m,t.m21=i,t.c=i,t.m31=c,t.m41=y,t.e=y,t.m12=r,t.b=r,t.m22=a,t.d=a,t.m32=u,t.m42=M,t.f=M,t.m13=n,t.m23=o,t.m33=f,t.m43=p,t.m14=s,t.m24=l,t.m34=h,t.m44=w}else{if(6!==e.length)throw new TypeError("CSSMatrix: expecting an Array of 6/16 values.");{const[m,r,n,s,i,a]=e;t.m11=m,t.a=m,t.m12=r,t.b=r,t.m21=n,t.c=n,t.m22=s,t.d=s,t.m41=i,t.e=i,t.m42=a,t.f=a}}return t}function t(t){if(![c,DOMMatrix,Object].some(m=>t instanceof m))throw TypeError(`CSSMatrix: "${t}" is not a DOMMatrix / CSSMatrix compatible object.`);return 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])}function e(t){if("string"!=typeof t)throw TypeError(`CSSMatrix: "${t}" is not a string.`);const e=String(t).replace(/\s/g,"");let r=new c;return e.split(")").filter(m=>m).map(m=>{const[t,e]=m.split("(");return{prop:t,components:e.split(",").map(m=>m.includes("rad")?parseFloat(m)*(180/Math.PI):parseFloat(m))}}).forEach(t=>{const{prop:e,components:n}=t,[s,i,a,o]=n,l=[s,i,a],c=[s,i,a,o];if(e.includes("matrix")){const t=n.map(m=>Math.abs(m)<1e-6?0:m);[6,16].includes(t.length)&&(r=r.multiply(m(t)))}else if(["translate","translate3d"].some(m=>e===m)&&s)r=r.translate(s,i||0,a||0);else if("rotate3d"===e&&c.every(m=>!Number.isNaN(+m))&&o)r=r.rotateAxisAngle(s,i,a,o);else if("scale3d"===e&&l.every(m=>!Number.isNaN(+m))&&l.some(m=>1!==m))r=r.scale(s,i,a);else if("rotate"===e&&s)r=r.rotate(0,0,s);else if("scale"!==e||Number.isNaN(s)||1===s){if("skew"===e&&(s||i))r=s?r.skewX(s):r,r=i?r.skewY(i):r;else if(/[XYZ]/.test(e)&&s)if(e.includes("skew"))r=r[e](s);else{const m=e.replace(/[XYZ]/,""),t=e.replace(m,""),n=["X","Y","Z"].indexOf(t),i=[0===n?s:0,1===n?s:0,2===n?s:0];r=r[m](...i)}}else{const m=Number.isNaN(+i)?s:i;r=r.scale(s,m,1)}}),r}function r(m,t,e){const r=new c;return r.m41=m,r.e=m,r.m42=t,r.f=t,r.m43=e,r}function n(m,t,e){const r=new c,n=Math.PI/180,s=m*n,i=t*n,a=e*n,o=Math.cos(s),l=-Math.sin(s),u=Math.cos(i),f=-Math.sin(i),h=Math.cos(a),y=-Math.sin(a),M=u*h,p=-u*y;r.m11=M,r.a=M,r.m12=p,r.b=p,r.m13=f;const w=l*f*h+o*y;r.m21=w,r.c=w;const x=o*h-l*f*y;return r.m22=x,r.d=x,r.m23=-l*u,r.m31=l*y-o*f*h,r.m32=l*h+o*f*y,r.m33=o*u,r}function s(m,t,e,r){const n=new c,s=r*(Math.PI/360),i=Math.sin(s),a=Math.cos(s),o=i*i,l=Math.sqrt(m*m+t*t+e*e);let u=m,f=t,h=e;0===l?(u=0,f=0,h=1):(u/=l,f/=l,h/=l);const y=u*u,M=f*f,p=h*h,w=1-2*(M+p)*o;n.m11=w,n.a=w;const x=2*(u*f*o+h*i*a);n.m12=x,n.b=x,n.m13=2*(u*h*o-f*i*a);const d=2*(f*u*o-h*i*a);n.m21=d,n.c=d;const g=1-2*(p+y)*o;return n.m22=g,n.d=g,n.m23=2*(f*h*o+u*i*a),n.m31=2*(h*u*o+f*i*a),n.m32=2*(h*f*o-u*i*a),n.m33=1-2*(y+M)*o,n}function i(m,t,e){const r=new c;return r.m11=m,r.a=m,r.m22=t,r.d=t,r.m33=e,r}function a(m){const t=new c,e=m*Math.PI/180,r=Math.tan(e);return t.m21=r,t.c=r,t}function o(m){const t=new c,e=m*Math.PI/180,r=Math.tan(e);return t.m12=r,t.b=r,t}function l(t,e){return m([e.m11*t.m11+e.m12*t.m21+e.m13*t.m31+e.m14*t.m41,e.m11*t.m12+e.m12*t.m22+e.m13*t.m32+e.m14*t.m42,e.m11*t.m13+e.m12*t.m23+e.m13*t.m33+e.m14*t.m43,e.m11*t.m14+e.m12*t.m24+e.m13*t.m34+e.m14*t.m44,e.m21*t.m11+e.m22*t.m21+e.m23*t.m31+e.m24*t.m41,e.m21*t.m12+e.m22*t.m22+e.m23*t.m32+e.m24*t.m42,e.m21*t.m13+e.m22*t.m23+e.m23*t.m33+e.m24*t.m43,e.m21*t.m14+e.m22*t.m24+e.m23*t.m34+e.m24*t.m44,e.m31*t.m11+e.m32*t.m21+e.m33*t.m31+e.m34*t.m41,e.m31*t.m12+e.m32*t.m22+e.m33*t.m32+e.m34*t.m42,e.m31*t.m13+e.m32*t.m23+e.m33*t.m33+e.m34*t.m43,e.m31*t.m14+e.m32*t.m24+e.m33*t.m34+e.m34*t.m44,e.m41*t.m11+e.m42*t.m21+e.m43*t.m31+e.m44*t.m41,e.m41*t.m12+e.m42*t.m22+e.m43*t.m32+e.m44*t.m42,e.m41*t.m13+e.m42*t.m23+e.m43*t.m33+e.m44*t.m43,e.m41*t.m14+e.m42*t.m24+e.m43*t.m34+e.m44*t.m44])}class c{constructor(...m){const t=this;if(t.a=1,t.b=0,t.c=0,t.d=1,t.e=0,t.f=0,t.m11=1,t.m12=0,t.m13=0,t.m14=0,t.m21=0,t.m22=1,t.m23=0,t.m24=0,t.m31=0,t.m32=0,t.m33=1,t.m34=0,t.m41=0,t.m42=0,t.m43=0,t.m44=1,m&&m.length){let e=m;return m instanceof Array&&(m[0]instanceof Array&&[16,6].includes(m[0].length)||"string"==typeof m[0]||[c,DOMMatrix].some(t=>m[0]instanceof t))&&([e]=m),t.setMatrixValue(e)}return t}set isIdentity(m){this.isIdentity=m}get isIdentity(){const 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}get is2D(){const m=this;return 0===m.m31&&0===m.m32&&1===m.m33&&0===m.m34&&0===m.m43&&1===m.m44}set is2D(m){this.is2D=m}setMatrixValue(r){return[DOMMatrix,c].some(m=>r instanceof m)?t(r):"string"==typeof r&&r.length&&"none"!==r?e(r):Array.isArray(r)?m(r):this}toString(){const m=this.toArray().join(",");return`${this.is2D?"matrix":"matrix3d"}(${m})`}toArray(){const m=this;let t;return t=m.is2D?[m.a,m.b,m.c,m.d,m.e,m.f]:[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],t.map(m=>Math.abs(m)<1e-6?0:(m*10**6>>0)/10**6)}toJSON(){return JSON.parse(JSON.stringify(this))}multiply(m){return l(this,m)}translate(m,t,e){let n=t,s=e;return null==s&&(s=0),null==n&&(n=0),l(this,r(m,n,s))}scale(m,t,e){let r=t,n=e;return null==r&&(r=m),null==n&&(n=m),l(this,i(m,r,n))}rotate(m,t,e){let r=m,s=t,i=e;return null==s&&(s=0),null==i&&(i=r,r=0),l(this,n(r,s,i))}rotateAxisAngle(m,t,e,r){if([m,t,e,r].some(m=>Number.isNaN(m)))throw new TypeError("CSSMatrix: expecting 4 values");return l(this,s(m,t,e,r))}skewX(m){return l(this,a(m))}skewY(m){return l(this,o(m))}transformPoint(m){let t=r(m.x,m.y,m.z);return t.m44=m.w||1,t=this.multiply(t),{x:t.m41,y:t.m42,z:t.m43,w:t.m44}}transform(m){const t=this,e=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,n=t.m31*m.x+t.m32*m.y+t.m33*m.z+t.m34*m.w,s=t.m41*m.x+t.m42*m.y+t.m43*m.z+t.m44*m.w;return{x:e/s,y:r/s,z:n/s,w:s}}}c.Translate=r,c.Rotate=n,c.RotateAxisAngle=s,c.Scale=i,c.SkewX=a,c.SkewY=o,c.Multiply=l,c.fromArray=m,c.fromMatrix=t,c.fromString=e;export{c as default}; |
/*! | ||
* DOMMatrix v0.0.13 (https://thednp.github.io/DOMMatrix/) | ||
* DOMMatrix v0.0.14 (https://thednp.github.io/DOMMatrix/) | ||
* Copyright 2021 © thednp | ||
@@ -19,11 +19,16 @@ * Licensed under MIT (https://github.com/thednp/DOMMatrix/blob/master/LICENSE) | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an array float values. | ||
* Creates a new mutable `CSSMatrix` object given an array of floating point values. | ||
* | ||
* This static method invalidates arrays that contain non-number elements. | ||
* | ||
* 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 {Number[]} array an `Array` to feed values from. | ||
* @param {number[]} array an `Array` to feed values from. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromArray(array) { | ||
if (!array.every(function (n) { return !Number.isNaN(n); })) { | ||
throw TypeError(("CSSMatrix: \"" + array + "\" must only have numbers.")); | ||
} | ||
var m = new CSSMatrix(); | ||
@@ -106,3 +111,3 @@ var a = Array.from(array); | ||
} else { | ||
throw new TypeError('CSSMatrix: expecting a 6/16 values Array'); | ||
throw new TypeError('CSSMatrix: expecting an Array of 6/16 values.'); | ||
} | ||
@@ -113,9 +118,12 @@ return m; | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an existing matrix or a | ||
* `DOMMatrix` *Object* which provides the values for its properties. | ||
* Creates a new mutable `CSSMatrix` instance given an existing matrix or a | ||
* `DOMMatrix` instance which provides the values for its properties. | ||
* | ||
* @param {CSSMatrix | DOMMatrix} m the source matrix to feed values from. | ||
* @param {CSSMatrix | DOMMatrix | jsonMatrix} m the source matrix to feed values from. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromMatrix(m) { | ||
if (![CSSMatrix, DOMMatrix, Object].some(function (x) { return m instanceof x; })) { | ||
throw TypeError(("CSSMatrix: \"" + m + "\" is not a DOMMatrix / CSSMatrix compatible object.")); | ||
} | ||
return fromArray( | ||
@@ -130,7 +138,10 @@ [m.m11, m.m12, m.m13, m.m14, | ||
/** | ||
* Feed a CSSMatrix object with a valid CSS transform value. | ||
* * matrix(a, b, c, d, e, f) - valid matrix() transform function | ||
* * matrix3d(m11, m12, m13, ...m44) - valid matrix3d() transform function | ||
* * translate(tx, ty) rotateX(alpha) - any valid transform function(s) | ||
* Creates a new mutable `CSSMatrix` instance given any valid CSS transform string. | ||
* | ||
* * `matrix(a, b, c, d, e, f)` - valid matrix() transform function | ||
* * `matrix3d(m11, m12, m13, ...m44)` - valid matrix3d() transform function | ||
* * `translate(tx, ty) rotateX(alpha)` - any valid transform function(s) | ||
* | ||
* @copyright thednp © 2021 | ||
* | ||
* @param {string} source valid CSS transform string syntax. | ||
@@ -140,2 +151,5 @@ * @return {CSSMatrix} the resulted matrix. | ||
function fromString(source) { | ||
if (typeof source !== 'string') { | ||
throw TypeError(("CSSMatrix: \"" + source + "\" is not a string.")); | ||
} | ||
var str = String(source).replace(/\s/g, ''); | ||
@@ -150,16 +164,6 @@ var m = new CSSMatrix(); | ||
.map(function (n) { return (n.includes('rad') ? parseFloat(n) * (180 / Math.PI) : parseFloat(n)); }); | ||
var x = components[0]; | ||
var y = components[1]; | ||
var z = components[2]; | ||
var a = components[3]; | ||
// don't add perspective if is2D | ||
if (prop === 'matrix3d' | ||
|| (prop === 'rotate3d' && [x, y].every(function (n) { return !Number.isNaN(+n) && n !== 0; }) && a) | ||
|| (['rotateX', 'rotateY'].includes(prop) && x) | ||
|| (prop === 'translate3d' && [x, y, z].every(function (n) { return !Number.isNaN(+n); }) && z) | ||
|| (prop === 'scale3d' && [x, y, z].every(function (n) { return !Number.isNaN(+n) && n !== x; })) | ||
) { | ||
is2D = false; | ||
} | ||
components[0]; | ||
components[1]; | ||
components[2]; | ||
components[3]; | ||
return { prop: prop, components: components }; | ||
@@ -230,5 +234,5 @@ }); | ||
* | ||
* @param {Number} x the `x-axis` position. | ||
* @param {Number} y the `y-axis` position. | ||
* @param {Number} z the `z-axis` position. | ||
* @param {number} x the `x-axis` position. | ||
* @param {number} y the `y-axis` position. | ||
* @param {number} z the `z-axis` position. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -251,5 +255,5 @@ */ | ||
* | ||
* @param {Number} rx the `x-axis` rotation. | ||
* @param {Number} ry the `y-axis` rotation. | ||
* @param {Number} rz the `z-axis` rotation. | ||
* @param {number} rx the `x-axis` rotation. | ||
* @param {number} ry the `y-axis` rotation. | ||
* @param {number} rz the `z-axis` rotation. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -306,6 +310,6 @@ */ | ||
* | ||
* @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} alpha the value in degrees of the rotation. | ||
* @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} alpha the value in degrees of the rotation. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -371,5 +375,5 @@ */ | ||
* | ||
* @param {Number} x the `x-axis` scale. | ||
* @param {Number} y the `y-axis` scale. | ||
* @param {Number} z the `z-axis` scale. | ||
* @param {number} x the `x-axis` scale. | ||
* @param {number} y the `y-axis` scale. | ||
* @param {number} z the `z-axis` scale. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -395,3 +399,3 @@ */ | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
* @param {number} angle the angle in degrees. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -414,3 +418,3 @@ */ | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
* @param {number} angle the angle in degrees. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -560,3 +564,3 @@ */ | ||
* | ||
* @param {String | Number[] | CSSMatrix | DOMMatrix} source | ||
* @param {string | number[] | CSSMatrix | DOMMatrix} source | ||
* @return {CSSMatrix} the matrix instance | ||
@@ -588,3 +592,3 @@ */ | ||
* | ||
* @return {String} a string representation of the matrix | ||
* @return {string} a string representation of the matrix | ||
*/ | ||
@@ -604,3 +608,3 @@ CSSMatrix.prototype.toString = function toString () { | ||
* | ||
* @return {Number[]} an *Array* representation of the matrix | ||
* @return {number[]} an *Array* representation of the matrix | ||
*/ | ||
@@ -624,5 +628,24 @@ CSSMatrix.prototype.toArray = function toArray () { | ||
}; | ||
/** | ||
* @typedef {object} jsonMatrix | ||
* @property {number} m11 | ||
* @property {number} m12 | ||
* @property {number} m13 | ||
* @property {number} m14 | ||
* @property {number} m21 | ||
* @property {number} m22 | ||
* @property {number} m23 | ||
* @property {number} m24 | ||
* @property {number} m31 | ||
* @property {number} m32 | ||
* @property {number} m33 | ||
* @property {number} m34 | ||
* @property {number} m41 | ||
* @property {number} m42 | ||
* @property {number} m43 | ||
* @property {number} m44 | ||
*/ | ||
/** | ||
* Returns a JSON representation of the `CSSMatrix` object, a standard *Object* | ||
* Returns a JSON representation of the `CSSMatrix` instance, a standard *Object* | ||
* that includes `{a,b,c,d,e,f}` and `{m11,m12,m13,..m44}` properties and | ||
@@ -634,3 +657,3 @@ * excludes `is2D` & `isIdentity` properties. | ||
* | ||
* @return {Object} an *Object* with all matrix values. | ||
* @return {jsonMatrix} an *Object* with all matrix values. | ||
*/ | ||
@@ -646,3 +669,3 @@ CSSMatrix.prototype.toJSON = function toJSON () { | ||
* | ||
* @param {CSSMatrix | DOMMatrix} m2 CSSMatrix | ||
* @param {CSSMatrix | DOMMatrix | jsonMatrix} m2 CSSMatrix | ||
* @return {CSSMatrix} The resulted matrix. | ||
@@ -774,3 +797,3 @@ */ | ||
* | ||
* Copyright @ thednp | ||
* @copyright thednp © 2021 | ||
* | ||
@@ -777,0 +800,0 @@ * @param {Tuple | DOMPoint} v Tuple or DOMPoint |
@@ -1,2 +0,2 @@ | ||
// DOMMatrix v0.0.13 | 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){var t=new f,e=Array.from(m);if(16===e.length){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],u=e[6],c=e[7],l=e[8],p=e[9],y=e[10],h=e[11],v=e[12],d=e[13],M=e[14],w=e[15];t.m11=r,t.a=r,t.m21=o,t.c=o,t.m31=l,t.m41=v,t.e=v,t.m12=n,t.b=n,t.m22=s,t.d=s,t.m32=p,t.m42=d,t.f=d,t.m13=i,t.m23=u,t.m33=y,t.m43=M,t.m14=a,t.m24=c,t.m34=h,t.m44=w}else{if(6!==e.length)throw new TypeError("CSSMatrix: expecting a 6/16 values Array");var x=e[0],N=e[1],g=e[2],b=e[3],A=e[4],S=e[5];t.m11=x,t.a=x,t.m12=N,t.b=N,t.m21=g,t.c=g,t.m22=b,t.d=b,t.m41=A,t.e=A,t.m42=S,t.f=S}return t}function t(t){return 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])}function e(t){var e=String(t).replace(/\s/g,""),r=new f,n=!0;return e.split(")").filter((function(m){return m})).map((function(m){var t=m.split("("),e=t[0],r=t[1].split(",").map((function(m){return m.includes("rad")?parseFloat(m)*(180/Math.PI):parseFloat(m)})),i=r[0],a=r[1],o=r[2],s=r[3];return("matrix3d"===e||"rotate3d"===e&&[i,a].every((function(m){return!Number.isNaN(+m)&&0!==m}))&&s||["rotateX","rotateY"].includes(e)&&i||"translate3d"===e&&[i,a,o].every((function(m){return!Number.isNaN(+m)}))&&o||"scale3d"===e&&[i,a,o].every((function(m){return!Number.isNaN(+m)&&m!==i})))&&(n=!1),{prop:e,components:r}})).forEach((function(t){var e=t.prop,i=t.components,a=i[0],o=i[1],s=i[2],u=i[3],f=[a,o,s],c=[a,o,s,u];if("perspective"!==e||n)if(e.includes("matrix")){var l=i.map((function(m){return Math.abs(m)<1e-6?0:m}));[6,16].includes(l.length)&&(r=r.multiply(m(l)))}else if(["translate","translate3d"].some((function(m){return e===m}))&&a)r=r.translate(a,o||0,s||0);else if("rotate3d"===e&&c.every((function(m){return!Number.isNaN(+m)}))&&u)r=r.rotateAxisAngle(a,o,s,u);else if("scale3d"===e&&f.every((function(m){return!Number.isNaN(+m)}))&&f.some((function(m){return 1!==m})))r=r.scale(a,o,s);else if("rotate"===e&&a)r=r.rotate(0,0,a);else if("scale"!==e||Number.isNaN(a)||1===a){if("skew"===e&&(a||o))r=a?r.skewX(a):r,r=o?r.skewY(o):r;else if(/[XYZ]/.test(e)&&a)if(e.includes("skew"))r=r[e](a);else{var p=e.replace(/[XYZ]/,""),y=e.replace(p,""),h=["X","Y","Z"].indexOf(y),v=[0===h?a:0,1===h?a:0,2===h?a:0];r=r[p].apply(r,v)}}else{var d=Number.isNaN(+o)?a:o;r=r.scale(a,d,1)}else r.m34=-1/a})),r}function r(m,t,e){var r=new f;return r.m41=m,r.e=m,r.m42=t,r.f=t,r.m43=e,r}function n(m,t,e){var r=new f,n=Math.PI/180,i=m*n,a=t*n,o=e*n,s=Math.cos(i),u=-Math.sin(i),c=Math.cos(a),l=-Math.sin(a),p=Math.cos(o),y=-Math.sin(o),h=c*p,v=-c*y;r.m11=h,r.a=h,r.m12=v,r.b=v,r.m13=l;var d=u*l*p+s*y;r.m21=d,r.c=d;var M=s*p-u*l*y;return r.m22=M,r.d=M,r.m23=-u*c,r.m31=u*y-s*l*p,r.m32=u*p+s*l*y,r.m33=s*c,r}function i(m,t,e,r){var n=new f,i=r*(Math.PI/360),a=Math.sin(i),o=Math.cos(i),s=a*a,u=Math.sqrt(m*m+t*t+e*e),c=m,l=t,p=e;0===u?(c=0,l=0,p=1):(c/=u,l/=u,p/=u);var y=c*c,h=l*l,v=p*p,d=1-2*(h+v)*s;n.m11=d,n.a=d;var M=2*(c*l*s+p*a*o);n.m12=M,n.b=M,n.m13=2*(c*p*s-l*a*o);var w=2*(l*c*s-p*a*o);n.m21=w,n.c=w;var x=1-2*(v+y)*s;return n.m22=x,n.d=x,n.m23=2*(l*p*s+c*a*o),n.m31=2*(p*c*s+l*a*o),n.m32=2*(p*l*s-c*a*o),n.m33=1-2*(y+h)*s,n}function a(m,t,e){var r=new f;return r.m11=m,r.a=m,r.m22=t,r.d=t,r.m33=e,r}function o(m){var t=new f,e=m*Math.PI/180,r=Math.tan(e);return t.m21=r,t.c=r,t}function s(m){var t=new f,e=m*Math.PI/180,r=Math.tan(e);return t.m12=r,t.b=r,t}function u(t,e){return m([e.m11*t.m11+e.m12*t.m21+e.m13*t.m31+e.m14*t.m41,e.m11*t.m12+e.m12*t.m22+e.m13*t.m32+e.m14*t.m42,e.m11*t.m13+e.m12*t.m23+e.m13*t.m33+e.m14*t.m43,e.m11*t.m14+e.m12*t.m24+e.m13*t.m34+e.m14*t.m44,e.m21*t.m11+e.m22*t.m21+e.m23*t.m31+e.m24*t.m41,e.m21*t.m12+e.m22*t.m22+e.m23*t.m32+e.m24*t.m42,e.m21*t.m13+e.m22*t.m23+e.m23*t.m33+e.m24*t.m43,e.m21*t.m14+e.m22*t.m24+e.m23*t.m34+e.m24*t.m44,e.m31*t.m11+e.m32*t.m21+e.m33*t.m31+e.m34*t.m41,e.m31*t.m12+e.m32*t.m22+e.m33*t.m32+e.m34*t.m42,e.m31*t.m13+e.m32*t.m23+e.m33*t.m33+e.m34*t.m43,e.m31*t.m14+e.m32*t.m24+e.m33*t.m34+e.m34*t.m44,e.m41*t.m11+e.m42*t.m21+e.m43*t.m31+e.m44*t.m41,e.m41*t.m12+e.m42*t.m22+e.m43*t.m32+e.m44*t.m42,e.m41*t.m13+e.m42*t.m23+e.m43*t.m33+e.m44*t.m43,e.m41*t.m14+e.m42*t.m24+e.m43*t.m34+e.m44*t.m44])}var f=function m(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var r=this;if(r.a=1,r.b=0,r.c=0,r.d=1,r.e=0,r.f=0,r.m11=1,r.m12=0,r.m13=0,r.m14=0,r.m21=0,r.m22=1,r.m23=0,r.m24=0,r.m31=0,r.m32=0,r.m33=1,r.m34=0,r.m41=0,r.m42=0,r.m43=0,r.m44=1,t&&t.length){var n=t;return t instanceof Array&&(t[0]instanceof Array&&[16,6].includes(t[0].length)||"string"==typeof t[0]||[m,DOMMatrix].some((function(m){return t[0]instanceof m})))&&(n=t[0]),r.setMatrixValue(n)}return r},c={isIdentity:{configurable:!0},is2D:{configurable:!0}};return c.isIdentity.set=function(m){this.isIdentity=m},c.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},c.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},c.is2D.set=function(m){this.is2D=m},f.prototype.setMatrixValue=function(r){return[DOMMatrix,f].some((function(m){return r instanceof m}))?t(r):"string"==typeof r&&r.length&&"none"!==r?e(r):Array.isArray(r)?m(r):this},f.prototype.toString=function(){var m=this.toArray().join(",");return(this.is2D?"matrix":"matrix3d")+"("+m+")"},f.prototype.toArray=function(){var m=this,t=Math.pow(10,6);return(m.is2D?[m.a,m.b,m.c,m.d,m.e,m.f]:[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]).map((function(m){return Math.abs(m)<1e-6?0:(m*t>>0)/t}))},f.prototype.toJSON=function(){return JSON.parse(JSON.stringify(this))},f.prototype.multiply=function(m){return u(this,m)},f.prototype.translate=function(m,t,e){var n=t,i=e;return null==i&&(i=0),null==n&&(n=0),u(this,r(m,n,i))},f.prototype.scale=function(m,t,e){var r=t,n=e;return null==r&&(r=m),null==n&&(n=m),u(this,a(m,r,n))},f.prototype.rotate=function(m,t,e){var r=m,i=t,a=e;return null==i&&(i=0),null==a&&(a=r,r=0),u(this,n(r,i,a))},f.prototype.rotateAxisAngle=function(m,t,e,r){if([m,t,e,r].some((function(m){return Number.isNaN(m)})))throw new TypeError("CSSMatrix: expecting 4 values");return u(this,i(m,t,e,r))},f.prototype.skewX=function(m){return u(this,o(m))},f.prototype.skewY=function(m){return u(this,s(m))},f.prototype.transformPoint=function(m){var t=r(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}},f.prototype.transform=function(m){var t=this,e=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,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:e/i,y:r/i,z:n/i,w:i}},Object.defineProperties(f.prototype,c),f.Translate=r,f.Rotate=n,f.RotateAxisAngle=i,f.Scale=a,f.SkewX=o,f.SkewY=s,f.Multiply=u,f.fromArray=m,f.fromMatrix=t,f.fromString=e,f})); | ||
// DOMMatrix v0.0.14 | 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){if(!m.every((function(m){return!Number.isNaN(m)})))throw TypeError('CSSMatrix: "'+m+'" must only have numbers.');var t=new f,r=Array.from(m);if(16===r.length){var e=r[0],n=r[1],i=r[2],a=r[3],o=r[4],s=r[5],u=r[6],c=r[7],l=r[8],p=r[9],y=r[10],h=r[11],v=r[12],M=r[13],d=r[14],x=r[15];t.m11=e,t.a=e,t.m21=o,t.c=o,t.m31=l,t.m41=v,t.e=v,t.m12=n,t.b=n,t.m22=s,t.d=s,t.m32=p,t.m42=M,t.f=M,t.m13=i,t.m23=u,t.m33=y,t.m43=d,t.m14=a,t.m24=c,t.m34=h,t.m44=x}else{if(6!==r.length)throw new TypeError("CSSMatrix: expecting an Array of 6/16 values.");var w=r[0],g=r[1],b=r[2],S=r[3],N=r[4],A=r[5];t.m11=w,t.a=w,t.m12=g,t.b=g,t.m21=b,t.c=b,t.m22=S,t.d=S,t.m41=N,t.e=N,t.m42=A,t.f=A}return t}function t(t){if(![f,DOMMatrix,Object].some((function(m){return t instanceof m})))throw TypeError('CSSMatrix: "'+t+'" is not a DOMMatrix / CSSMatrix compatible object.');return 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])}function r(t){if("string"!=typeof t)throw TypeError('CSSMatrix: "'+t+'" is not a string.');var r=String(t).replace(/\s/g,""),e=new f;return r.split(")").filter((function(m){return m})).map((function(m){var t=m.split("("),r=t[0],e=t[1].split(",").map((function(m){return m.includes("rad")?parseFloat(m)*(180/Math.PI):parseFloat(m)}));return e[0],e[1],e[2],e[3],{prop:r,components:e}})).forEach((function(t){var r=t.prop,n=t.components,i=n[0],a=n[1],o=n[2],s=n[3],u=[i,a,o],f=[i,a,o,s];if(r.includes("matrix")){var c=n.map((function(m){return Math.abs(m)<1e-6?0:m}));[6,16].includes(c.length)&&(e=e.multiply(m(c)))}else if(["translate","translate3d"].some((function(m){return r===m}))&&i)e=e.translate(i,a||0,o||0);else if("rotate3d"===r&&f.every((function(m){return!Number.isNaN(+m)}))&&s)e=e.rotateAxisAngle(i,a,o,s);else if("scale3d"===r&&u.every((function(m){return!Number.isNaN(+m)}))&&u.some((function(m){return 1!==m})))e=e.scale(i,a,o);else if("rotate"===r&&i)e=e.rotate(0,0,i);else if("scale"!==r||Number.isNaN(i)||1===i){if("skew"===r&&(i||a))e=i?e.skewX(i):e,e=a?e.skewY(a):e;else if(/[XYZ]/.test(r)&&i)if(r.includes("skew"))e=e[r](i);else{var l=r.replace(/[XYZ]/,""),p=r.replace(l,""),y=["X","Y","Z"].indexOf(p),h=[0===y?i:0,1===y?i:0,2===y?i:0];e=e[l].apply(e,h)}}else{var v=Number.isNaN(+a)?i:a;e=e.scale(i,v,1)}})),e}function e(m,t,r){var e=new f;return e.m41=m,e.e=m,e.m42=t,e.f=t,e.m43=r,e}function n(m,t,r){var e=new f,n=Math.PI/180,i=m*n,a=t*n,o=r*n,s=Math.cos(i),u=-Math.sin(i),c=Math.cos(a),l=-Math.sin(a),p=Math.cos(o),y=-Math.sin(o),h=c*p,v=-c*y;e.m11=h,e.a=h,e.m12=v,e.b=v,e.m13=l;var M=u*l*p+s*y;e.m21=M,e.c=M;var d=s*p-u*l*y;return e.m22=d,e.d=d,e.m23=-u*c,e.m31=u*y-s*l*p,e.m32=u*p+s*l*y,e.m33=s*c,e}function i(m,t,r,e){var n=new f,i=e*(Math.PI/360),a=Math.sin(i),o=Math.cos(i),s=a*a,u=Math.sqrt(m*m+t*t+r*r),c=m,l=t,p=r;0===u?(c=0,l=0,p=1):(c/=u,l/=u,p/=u);var y=c*c,h=l*l,v=p*p,M=1-2*(h+v)*s;n.m11=M,n.a=M;var d=2*(c*l*s+p*a*o);n.m12=d,n.b=d,n.m13=2*(c*p*s-l*a*o);var x=2*(l*c*s-p*a*o);n.m21=x,n.c=x;var w=1-2*(v+y)*s;return n.m22=w,n.d=w,n.m23=2*(l*p*s+c*a*o),n.m31=2*(p*c*s+l*a*o),n.m32=2*(p*l*s-c*a*o),n.m33=1-2*(y+h)*s,n}function a(m,t,r){var e=new f;return e.m11=m,e.a=m,e.m22=t,e.d=t,e.m33=r,e}function o(m){var t=new f,r=m*Math.PI/180,e=Math.tan(r);return t.m21=e,t.c=e,t}function s(m){var t=new f,r=m*Math.PI/180,e=Math.tan(r);return t.m12=e,t.b=e,t}function u(t,r){return m([r.m11*t.m11+r.m12*t.m21+r.m13*t.m31+r.m14*t.m41,r.m11*t.m12+r.m12*t.m22+r.m13*t.m32+r.m14*t.m42,r.m11*t.m13+r.m12*t.m23+r.m13*t.m33+r.m14*t.m43,r.m11*t.m14+r.m12*t.m24+r.m13*t.m34+r.m14*t.m44,r.m21*t.m11+r.m22*t.m21+r.m23*t.m31+r.m24*t.m41,r.m21*t.m12+r.m22*t.m22+r.m23*t.m32+r.m24*t.m42,r.m21*t.m13+r.m22*t.m23+r.m23*t.m33+r.m24*t.m43,r.m21*t.m14+r.m22*t.m24+r.m23*t.m34+r.m24*t.m44,r.m31*t.m11+r.m32*t.m21+r.m33*t.m31+r.m34*t.m41,r.m31*t.m12+r.m32*t.m22+r.m33*t.m32+r.m34*t.m42,r.m31*t.m13+r.m32*t.m23+r.m33*t.m33+r.m34*t.m43,r.m31*t.m14+r.m32*t.m24+r.m33*t.m34+r.m34*t.m44,r.m41*t.m11+r.m42*t.m21+r.m43*t.m31+r.m44*t.m41,r.m41*t.m12+r.m42*t.m22+r.m43*t.m32+r.m44*t.m42,r.m41*t.m13+r.m42*t.m23+r.m43*t.m33+r.m44*t.m43,r.m41*t.m14+r.m42*t.m24+r.m43*t.m34+r.m44*t.m44])}var f=function m(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var e=this;if(e.a=1,e.b=0,e.c=0,e.d=1,e.e=0,e.f=0,e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=0,e.m42=0,e.m43=0,e.m44=1,t&&t.length){var n=t;return t instanceof Array&&(t[0]instanceof Array&&[16,6].includes(t[0].length)||"string"==typeof t[0]||[m,DOMMatrix].some((function(m){return t[0]instanceof m})))&&(n=t[0]),e.setMatrixValue(n)}return e},c={isIdentity:{configurable:!0},is2D:{configurable:!0}};return c.isIdentity.set=function(m){this.isIdentity=m},c.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},c.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},c.is2D.set=function(m){this.is2D=m},f.prototype.setMatrixValue=function(e){return[DOMMatrix,f].some((function(m){return e instanceof m}))?t(e):"string"==typeof e&&e.length&&"none"!==e?r(e):Array.isArray(e)?m(e):this},f.prototype.toString=function(){var m=this.toArray().join(",");return(this.is2D?"matrix":"matrix3d")+"("+m+")"},f.prototype.toArray=function(){var m=this,t=Math.pow(10,6);return(m.is2D?[m.a,m.b,m.c,m.d,m.e,m.f]:[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]).map((function(m){return Math.abs(m)<1e-6?0:(m*t>>0)/t}))},f.prototype.toJSON=function(){return JSON.parse(JSON.stringify(this))},f.prototype.multiply=function(m){return u(this,m)},f.prototype.translate=function(m,t,r){var n=t,i=r;return null==i&&(i=0),null==n&&(n=0),u(this,e(m,n,i))},f.prototype.scale=function(m,t,r){var e=t,n=r;return null==e&&(e=m),null==n&&(n=m),u(this,a(m,e,n))},f.prototype.rotate=function(m,t,r){var e=m,i=t,a=r;return null==i&&(i=0),null==a&&(a=e,e=0),u(this,n(e,i,a))},f.prototype.rotateAxisAngle=function(m,t,r,e){if([m,t,r,e].some((function(m){return Number.isNaN(m)})))throw new TypeError("CSSMatrix: expecting 4 values");return u(this,i(m,t,r,e))},f.prototype.skewX=function(m){return u(this,o(m))},f.prototype.skewY=function(m){return u(this,s(m))},f.prototype.transformPoint=function(m){var t=e(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}},f.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(f.prototype,c),f.Translate=e,f.Rotate=n,f.RotateAxisAngle=i,f.Scale=a,f.SkewX=o,f.SkewY=s,f.Multiply=u,f.fromArray=m,f.fromMatrix=t,f.fromString=r,f})); |
{ | ||
"name": "dommatrix", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "ES6+ shim for DOMMatrix", | ||
@@ -5,0 +5,0 @@ "main": "dist/dommatrix.min.js", |
@@ -8,11 +8,16 @@ // DOMMatrix Static methods | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an array float values. | ||
* Creates a new mutable `CSSMatrix` object given an array of floating point values. | ||
* | ||
* This static method invalidates arrays that contain non-number elements. | ||
* | ||
* 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 {Number[]} array an `Array` to feed values from. | ||
* @param {number[]} array an `Array` to feed values from. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromArray(array) { | ||
if (!array.every((n) => !Number.isNaN(n))) { | ||
throw TypeError(`CSSMatrix: "${array}" must only have numbers.`); | ||
} | ||
const m = new CSSMatrix(); | ||
@@ -78,3 +83,3 @@ const a = Array.from(array); | ||
} else { | ||
throw new TypeError('CSSMatrix: expecting a 6/16 values Array'); | ||
throw new TypeError('CSSMatrix: expecting an Array of 6/16 values.'); | ||
} | ||
@@ -85,9 +90,12 @@ return m; | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an existing matrix or a | ||
* `DOMMatrix` *Object* which provides the values for its properties. | ||
* Creates a new mutable `CSSMatrix` instance given an existing matrix or a | ||
* `DOMMatrix` instance which provides the values for its properties. | ||
* | ||
* @param {CSSMatrix | DOMMatrix} m the source matrix to feed values from. | ||
* @param {CSSMatrix | DOMMatrix | jsonMatrix} m the source matrix to feed values from. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromMatrix(m) { | ||
if (![CSSMatrix, DOMMatrix, Object].some((x) => m instanceof x)) { | ||
throw TypeError(`CSSMatrix: "${m}" is not a DOMMatrix / CSSMatrix compatible object.`); | ||
} | ||
return fromArray( | ||
@@ -102,7 +110,10 @@ [m.m11, m.m12, m.m13, m.m14, | ||
/** | ||
* Feed a CSSMatrix object with a valid CSS transform value. | ||
* * matrix(a, b, c, d, e, f) - valid matrix() transform function | ||
* * matrix3d(m11, m12, m13, ...m44) - valid matrix3d() transform function | ||
* * translate(tx, ty) rotateX(alpha) - any valid transform function(s) | ||
* Creates a new mutable `CSSMatrix` instance given any valid CSS transform string. | ||
* | ||
* * `matrix(a, b, c, d, e, f)` - valid matrix() transform function | ||
* * `matrix3d(m11, m12, m13, ...m44)` - valid matrix3d() transform function | ||
* * `translate(tx, ty) rotateX(alpha)` - any valid transform function(s) | ||
* | ||
* @copyright thednp © 2021 | ||
* | ||
* @param {string} source valid CSS transform string syntax. | ||
@@ -112,2 +123,5 @@ * @return {CSSMatrix} the resulted matrix. | ||
function fromString(source) { | ||
if (typeof source !== 'string') { | ||
throw TypeError(`CSSMatrix: "${source}" is not a string.`); | ||
} | ||
const str = String(source).replace(/\s/g, ''); | ||
@@ -123,3 +137,3 @@ let m = new CSSMatrix(); | ||
// don't add perspective if is2D | ||
if (prop === 'matrix3d' | ||
if (!is2D && (prop === 'matrix3d' // only modify is2D once | ||
|| (prop === 'rotate3d' && [x, y].every((n) => !Number.isNaN(+n) && n !== 0) && a) | ||
@@ -129,3 +143,3 @@ || (['rotateX', 'rotateY'].includes(prop) && x) | ||
|| (prop === 'scale3d' && [x, y, z].every((n) => !Number.isNaN(+n) && n !== x)) | ||
) { | ||
)) { | ||
is2D = false; | ||
@@ -194,5 +208,5 @@ } | ||
* | ||
* @param {Number} x the `x-axis` position. | ||
* @param {Number} y the `y-axis` position. | ||
* @param {Number} z the `z-axis` position. | ||
* @param {number} x the `x-axis` position. | ||
* @param {number} y the `y-axis` position. | ||
* @param {number} z the `z-axis` position. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -215,5 +229,5 @@ */ | ||
* | ||
* @param {Number} rx the `x-axis` rotation. | ||
* @param {Number} ry the `y-axis` rotation. | ||
* @param {Number} rz the `z-axis` rotation. | ||
* @param {number} rx the `x-axis` rotation. | ||
* @param {number} ry the `y-axis` rotation. | ||
* @param {number} rz the `z-axis` rotation. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -270,6 +284,6 @@ */ | ||
* | ||
* @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} alpha the value in degrees of the rotation. | ||
* @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} alpha the value in degrees of the rotation. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -335,5 +349,5 @@ */ | ||
* | ||
* @param {Number} x the `x-axis` scale. | ||
* @param {Number} y the `y-axis` scale. | ||
* @param {Number} z the `z-axis` scale. | ||
* @param {number} x the `x-axis` scale. | ||
* @param {number} y the `y-axis` scale. | ||
* @param {number} z the `z-axis` scale. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -359,3 +373,3 @@ */ | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
* @param {number} angle the angle in degrees. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -378,3 +392,3 @@ */ | ||
* | ||
* @param {Number} angle the angle in degrees. | ||
* @param {number} angle the angle in degrees. | ||
* @return {CSSMatrix} the resulted matrix. | ||
@@ -527,3 +541,3 @@ */ | ||
* | ||
* @param {String | Number[] | CSSMatrix | DOMMatrix} source | ||
* @param {string | number[] | CSSMatrix | DOMMatrix} source | ||
* @return {CSSMatrix} the matrix instance | ||
@@ -555,3 +569,3 @@ */ | ||
* | ||
* @return {String} a string representation of the matrix | ||
* @return {string} a string representation of the matrix | ||
*/ | ||
@@ -571,3 +585,3 @@ toString() { | ||
* | ||
* @return {Number[]} an *Array* representation of the matrix | ||
* @return {number[]} an *Array* representation of the matrix | ||
*/ | ||
@@ -591,5 +605,24 @@ toArray() { | ||
} | ||
/** | ||
* @typedef {object} jsonMatrix | ||
* @property {number} m11 | ||
* @property {number} m12 | ||
* @property {number} m13 | ||
* @property {number} m14 | ||
* @property {number} m21 | ||
* @property {number} m22 | ||
* @property {number} m23 | ||
* @property {number} m24 | ||
* @property {number} m31 | ||
* @property {number} m32 | ||
* @property {number} m33 | ||
* @property {number} m34 | ||
* @property {number} m41 | ||
* @property {number} m42 | ||
* @property {number} m43 | ||
* @property {number} m44 | ||
*/ | ||
/** | ||
* Returns a JSON representation of the `CSSMatrix` object, a standard *Object* | ||
* Returns a JSON representation of the `CSSMatrix` instance, a standard *Object* | ||
* that includes `{a,b,c,d,e,f}` and `{m11,m12,m13,..m44}` properties and | ||
@@ -601,3 +634,3 @@ * excludes `is2D` & `isIdentity` properties. | ||
* | ||
* @return {Object} an *Object* with all matrix values. | ||
* @return {jsonMatrix} an *Object* with all matrix values. | ||
*/ | ||
@@ -613,3 +646,3 @@ toJSON() { | ||
* | ||
* @param {CSSMatrix | DOMMatrix} m2 CSSMatrix | ||
* @param {CSSMatrix | DOMMatrix | jsonMatrix} m2 CSSMatrix | ||
* @return {CSSMatrix} The resulted matrix. | ||
@@ -741,3 +774,3 @@ */ | ||
* | ||
* Copyright @ thednp | ||
* @copyright thednp © 2021 | ||
* | ||
@@ -744,0 +777,0 @@ * @param {Tuple | DOMPoint} v Tuple or DOMPoint |
@@ -1,2 +0,484 @@ | ||
export default CSSMatrix; | ||
import CSSMatrix from "./DOMMatrix"; | ||
declare module "DOMMatrix" { | ||
export default CSSMatrix; | ||
/** | ||
* Creates and returns a new `DOMMatrix` compatible *Object* | ||
* with equivalent instance methods. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix | ||
* https://github.com/thednp/DOMMatrix/ | ||
*/ | ||
class CSSMatrix { | ||
/** | ||
* @constructor | ||
* @param {any} args accepts all parameter configurations: | ||
* | ||
* * valid CSS transform string, | ||
* * CSSMatrix/DOMMatrix instance, | ||
* * a 6/16 elements *Array*. | ||
*/ | ||
constructor(...args: any); | ||
a: number; | ||
b: number; | ||
c: number; | ||
d: number; | ||
e: number; | ||
f: number; | ||
m11: number; | ||
m12: number; | ||
m13: number; | ||
m14: number; | ||
m21: number; | ||
m22: number; | ||
m23: number; | ||
m24: number; | ||
m31: number; | ||
m32: number; | ||
m33: number; | ||
m34: number; | ||
m41: number; | ||
m42: number; | ||
m43: number; | ||
m44: number; | ||
/** | ||
* Sets a new `Boolean` flag value for `this.isIdentity` matrix property. | ||
* | ||
* @param {Boolean} value sets a new flag for this property | ||
*/ | ||
set isIdentity(arg: boolean); | ||
/** | ||
* 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). | ||
* | ||
* @return {Boolean} the current property value | ||
*/ | ||
get isIdentity(): boolean; | ||
/** | ||
* Sets a new `Boolean` flag value for `this.is2D` matrix property. | ||
* | ||
* @param {Boolean} value sets a new flag for this property | ||
*/ | ||
set is2D(arg: boolean); | ||
/** | ||
* A `Boolean` flag whose value is `true` if the matrix was initialized as a 2D matrix | ||
* and `false` if the matrix is 3D. | ||
* | ||
* @return {Boolean} the current property value | ||
*/ | ||
get is2D(): boolean; | ||
/** | ||
* The `setMatrixValue` method replaces the existing matrix with one computed | ||
* in the browser. EG: `matrix(1,0.25,-0.25,1,0,0)` | ||
* | ||
* The method accepts any *Array* values, the result of | ||
* `DOMMatrix` instance method `toFloat64Array()` / `toFloat32Array()` calls | ||
* or `CSSMatrix` instance method `toArray()`. | ||
* | ||
* This method expects valid *matrix()* / *matrix3d()* string values, as well | ||
* as other transform functions like *translateX(10px)*. | ||
* | ||
* @param {string | number[] | CSSMatrix | DOMMatrix} source | ||
* @return {CSSMatrix} the matrix instance | ||
*/ | ||
setMatrixValue(source: string | number[] | CSSMatrix | DOMMatrix): CSSMatrix; | ||
/** | ||
* Creates and returns a string representation of the matrix in `CSS` matrix syntax, | ||
* using the appropriate `CSS` matrix notation. | ||
* | ||
* matrix3d *matrix3d(m11, m12, m13, m14, m21, ...)* | ||
* matrix *matrix(a, b, c, d, e, f)* | ||
* | ||
* @return {string} a string representation of the matrix | ||
*/ | ||
toString(): string; | ||
/** | ||
* Returns an *Array* containing all 16 elements which comprise the matrix. | ||
* The method can return either the elements. | ||
* | ||
* Other methods make use of this method to feed their output values from this matrix. | ||
* | ||
* @return {number[]} an *Array* representation of the matrix | ||
*/ | ||
toArray(): number[]; | ||
/** | ||
* @typedef {object} jsonMatrix | ||
* @property {number} m11 | ||
* @property {number} m12 | ||
* @property {number} m13 | ||
* @property {number} m14 | ||
* @property {number} m21 | ||
* @property {number} m22 | ||
* @property {number} m23 | ||
* @property {number} m24 | ||
* @property {number} m31 | ||
* @property {number} m32 | ||
* @property {number} m33 | ||
* @property {number} m34 | ||
* @property {number} m41 | ||
* @property {number} m42 | ||
* @property {number} m43 | ||
* @property {number} m44 | ||
*/ | ||
/** | ||
* Returns a JSON representation of the `CSSMatrix` instance, a standard *Object* | ||
* that includes `{a,b,c,d,e,f}` and `{m11,m12,m13,..m44}` properties and | ||
* excludes `is2D` & `isIdentity` properties. | ||
* | ||
* The result can also be used as a second parameter for the `fromMatrix` static method | ||
* to load values into a matrix instance. | ||
* | ||
* @return {jsonMatrix} an *Object* with all matrix values. | ||
*/ | ||
toJSON(): { | ||
m11: number; | ||
m12: number; | ||
m13: number; | ||
m14: number; | ||
m21: number; | ||
m22: number; | ||
m23: number; | ||
m24: number; | ||
m31: number; | ||
m32: number; | ||
m33: number; | ||
m34: number; | ||
m41: number; | ||
m42: number; | ||
m43: number; | ||
m44: number; | ||
}; | ||
/** | ||
* 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 | DOMMatrix | jsonMatrix} m2 CSSMatrix | ||
* @return {CSSMatrix} The resulted matrix. | ||
*/ | ||
multiply(m2: DOMMatrix | CSSMatrix | { | ||
m11: number; | ||
m12: number; | ||
m13: number; | ||
m14: number; | ||
m21: number; | ||
m22: number; | ||
m23: number; | ||
m24: number; | ||
m31: number; | ||
m32: number; | ||
m33: number; | ||
m34: number; | ||
m41: number; | ||
m42: number; | ||
m43: number; | ||
m44: number; | ||
}): CSSMatrix; | ||
/** | ||
* 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 resulted matrix | ||
*/ | ||
translate(x: number, y: number, z: number): CSSMatrix; | ||
/** | ||
* 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 resulted matrix | ||
*/ | ||
scale(x: number, y: number, z: number): CSSMatrix; | ||
/** | ||
* 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, or Z if Y and Z are null. | ||
* @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 resulted matrix | ||
*/ | ||
rotate(rx: number, ry: number, rz: number): CSSMatrix; | ||
/** | ||
* 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 resulted matrix | ||
*/ | ||
rotateAxisAngle(x: number, y: number, z: number, angle: number): CSSMatrix; | ||
/** | ||
* Specifies a skew transformation along the `x-axis` by the given angle. | ||
* This matrix is not modified. | ||
* | ||
* @param {number} angle The angle amount in degrees to skew. | ||
* @return {CSSMatrix} The resulted matrix | ||
*/ | ||
skewX(angle: number): CSSMatrix; | ||
/** | ||
* Specifies a skew transformation along the `y-axis` by the given angle. | ||
* This matrix is not modified. | ||
* | ||
* @param {number} angle The angle amount in degrees to skew. | ||
* @return {CSSMatrix} The resulted matrix | ||
*/ | ||
skewY(angle: number): CSSMatrix; | ||
/** | ||
* @typedef {Object} Tuple | ||
* @property {number} x the `x-axis` component | ||
* @property {number} y the `y-axis` component | ||
* @property {number} z the `z-axis` component | ||
* @property {number} w the `w` component | ||
*/ | ||
/** | ||
* Transforms a specified point using the matrix, returning a new | ||
* Tuple *Object* comprising of the transformed point. | ||
* Neither the matrix nor the original point are altered. | ||
* | ||
* The method is equivalent with `transformPoint()` method | ||
* of the `DOMMatrix` constructor. | ||
* | ||
* @copyright thednp © 2021 | ||
* | ||
* @param {Tuple | DOMPoint} v Tuple or DOMPoint | ||
* @return {Tuple} the resulting Tuple | ||
*/ | ||
transformPoint(v: DOMPoint | { | ||
/** | ||
* the `x-axis` component | ||
*/ | ||
x: number; | ||
/** | ||
* the `y-axis` component | ||
*/ | ||
y: number; | ||
/** | ||
* the `z-axis` component | ||
*/ | ||
z: number; | ||
/** | ||
* the `w` component | ||
*/ | ||
w: number; | ||
}): { | ||
/** | ||
* the `x-axis` component | ||
*/ | ||
x: number; | ||
/** | ||
* the `y-axis` component | ||
*/ | ||
y: number; | ||
/** | ||
* the `z-axis` component | ||
*/ | ||
z: number; | ||
/** | ||
* the `w` component | ||
*/ | ||
w: number; | ||
}; | ||
/** | ||
* Transforms a specified vector using the matrix, returning a new | ||
* {x,y,z,w} Tuple *Object* comprising the transformed vector. | ||
* Neither the matrix nor the original vector are altered. | ||
* | ||
* @param {Tuple} t Tuple with `{x,y,z,w}` components | ||
* @return {Tuple} the resulting Tuple | ||
*/ | ||
transform(t: { | ||
/** | ||
* the `x-axis` component | ||
*/ | ||
x: number; | ||
/** | ||
* the `y-axis` component | ||
*/ | ||
y: number; | ||
/** | ||
* the `z-axis` component | ||
*/ | ||
z: number; | ||
/** | ||
* the `w` component | ||
*/ | ||
w: number; | ||
}): { | ||
/** | ||
* the `x-axis` component | ||
*/ | ||
x: number; | ||
/** | ||
* the `y-axis` component | ||
*/ | ||
y: number; | ||
/** | ||
* the `z-axis` component | ||
*/ | ||
z: number; | ||
/** | ||
* the `w` component | ||
*/ | ||
w: number; | ||
}; | ||
} | ||
namespace CSSMatrix { | ||
export { Translate }; | ||
export { Rotate }; | ||
export { RotateAxisAngle }; | ||
export { Scale }; | ||
export { SkewX }; | ||
export { SkewY }; | ||
export { Multiply }; | ||
export { fromArray }; | ||
export { fromMatrix }; | ||
export { fromString }; | ||
} | ||
/** | ||
* 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. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function Translate(x: number, y: number, z: number): CSSMatrix; | ||
/** | ||
* 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. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function Rotate(rx: number, ry: number, rz: number): CSSMatrix; | ||
/** | ||
* 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} alpha the value in degrees of the rotation. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function RotateAxisAngle(x: number, y: number, z: number, alpha: number): CSSMatrix; | ||
/** | ||
* 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. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function Scale(x: number, y: number, z: number): CSSMatrix; | ||
/** | ||
* 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. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function SkewX(angle: number): CSSMatrix; | ||
/** | ||
* 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. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function SkewY(angle: number): CSSMatrix; | ||
/** | ||
* 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. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function Multiply(m1: CSSMatrix, m2: CSSMatrix): CSSMatrix; | ||
/** | ||
* Creates a new mutable `CSSMatrix` object given an array of floating point values. | ||
* | ||
* This static method invalidates arrays that contain non-number elements. | ||
* | ||
* 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 {number[]} array an `Array` to feed values from. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromArray(array: number[]): CSSMatrix; | ||
/** | ||
* Creates a new mutable `CSSMatrix` instance given an existing matrix or a | ||
* `DOMMatrix` instance which provides the values for its properties. | ||
* | ||
* @param {CSSMatrix | DOMMatrix | jsonMatrix} m the source matrix to feed values from. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromMatrix(m: DOMMatrix | CSSMatrix | { | ||
m11: number; | ||
m12: number; | ||
m13: number; | ||
m14: number; | ||
m21: number; | ||
m22: number; | ||
m23: number; | ||
m24: number; | ||
m31: number; | ||
m32: number; | ||
m33: number; | ||
m34: number; | ||
m41: number; | ||
m42: number; | ||
m43: number; | ||
m44: number; | ||
}): CSSMatrix; | ||
/** | ||
* Creates a new mutable `CSSMatrix` instance given any valid CSS transform string. | ||
* | ||
* * `matrix(a, b, c, d, e, f)` - valid matrix() transform function | ||
* * `matrix3d(m11, m12, m13, ...m44)` - valid matrix3d() transform function | ||
* * `translate(tx, ty) rotateX(alpha)` - any valid transform function(s) | ||
* | ||
* @copyright thednp © 2021 | ||
* | ||
* @param {string} source valid CSS transform string syntax. | ||
* @return {CSSMatrix} the resulted matrix. | ||
*/ | ||
function fromString(source: string): CSSMatrix; | ||
} | ||
declare module "index" { | ||
export default CSSMatrix; | ||
import CSSMatrix from "DOMMatrix"; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114975
2733
10