Last active
May 12, 2021 18:01
-
-
Save dvdrtrgn/e93390c8ad49c67b7d7178af89a984d8 to your computer and use it in GitHub Desktop.
Take css transform gibberish; output sanity (to be continued)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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