Skip to content

Instantly share code, notes, and snippets.

@dvdrtrgn
Last active May 12, 2021 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdrtrgn/e93390c8ad49c67b7d7178af89a984d8 to your computer and use it in GitHub Desktop.
Save dvdrtrgn/e93390c8ad49c67b7d7178af89a984d8 to your computer and use it in GitHub Desktop.
Take css transform gibberish; output sanity (to be continued)
/*
DeMatrix
Take css transform gibberish; output sanity.
*/
define([], function () {
function DeMatrix(a, b, c, d, e, f) {
return {
a,
b,
c,
d,
e,
f,
rotation: Math.atan2(c, d) * (180 / Math.PI),
scaleX: undefined,
scaleY: undefined,
translateX: undefined,
translateY: undefined,
};
}
DeMatrix.parse = function (str) {
return this.apply(0, this.read2dCss(str));
};
DeMatrix.read2dCss = function (str) {
str = str.slice(7).slice(0, -1); // strip `matrix(...)`
return (str || '1, 0, 0, 1, 0, 0').split(', ').map(Number);
};
return DeMatrix;
});
/*
DeMatrix
Take css transform gibberish; output sanity.
*/
function DeMatrix(a, b, c, d, e, f) {
return {
a,
b,
c,
d,
e,
f,
rotation: Math.atan2(c, d) * (180 / Math.PI),
scaleX: undefined,
scaleY: undefined,
translateX: undefined,
translateY: undefined,
};
}
DeMatrix.parse = function (str) {
return this.apply(0, this.read2dCss(str));
};
DeMatrix.read2dCss = function (str) {
str = str.slice(7).slice(0, -1); // strip `matrix(...)`
return (str || '1, 0, 0, 1, 0, 0').split(', ').map(Number);
};
export default DeMatrix;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment