{"version":3,"file":"rematrix.es.mjs","sources":["../../../../node_modules/rematrix/dist/rematrix.es.js"],"sourcesContent":["/*! @license Rematrix v0.2.2\n\n\tCopyright 2018 Fisssion LLC.\n\n\tPermission is hereby granted, free of charge, to any person obtaining a copy\n\tof this software and associated documentation files (the \"Software\"), to deal\n\tin the Software without restriction, including without limitation the rights\n\tto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\tcopies of the Software, and to permit persons to whom the Software is\n\tfurnished to do so, subject to the following conditions:\n\n\tThe above copyright notice and this permission notice shall be included in\n\tall copies or substantial portions of the Software.\n\n\tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\tIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\tAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\tLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\tOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n\tTHE SOFTWARE.\n*/\n/**\n * @module Rematrix\n */\n\n/**\n * Transformation matrices in the browser come in two flavors:\n *\n *  - `matrix` using 6 values (short)\n *  - `matrix3d` using 16 values (long)\n *\n * This utility follows this [conversion guide](https://goo.gl/EJlUQ1)\n * to expand short form matrices to their equivalent long form.\n *\n * @param  {array} source - Accepts both short and long form matrices.\n * @return {array}\n */\nfunction format(source) {\n\tif (source.constructor !== Array) {\n\t\tthrow new TypeError('Expected array.')\n\t}\n\tif (source.length === 16) {\n\t\treturn source\n\t}\n\tif (source.length === 6) {\n\t\tvar matrix = identity();\n\t\tmatrix[0] = source[0];\n\t\tmatrix[1] = source[1];\n\t\tmatrix[4] = source[2];\n\t\tmatrix[5] = source[3];\n\t\tmatrix[12] = source[4];\n\t\tmatrix[13] = source[5];\n\t\treturn matrix\n\t}\n\tthrow new RangeError('Expected array with either 6 or 16 values.')\n}\n\n/**\n * Returns a matrix representing no transformation. The product of any matrix\n * multiplied by the identity matrix will be the original matrix.\n *\n * > **Tip:** Similar to how `5 * 1 === 5`, where `1` is the identity.\n *\n * @return {array}\n */\nfunction identity() {\n\tvar matrix = [];\n\tfor (var i = 0; i < 16; i++) {\n\t\ti % 5 == 0 ? matrix.push(1) : matrix.push(0);\n\t}\n\treturn matrix\n}\n\n/**\n * Returns a matrix describing the inverse transformation of the source\n * matrix. The product of any matrix multiplied by its inverse will be the\n * identity matrix.\n *\n * > **Tip:** Similar to how `5 * (1/5) === 1`, where `1/5` is the inverse.\n *\n * @param  {array} source - Accepts both short and long form matrices.\n * @return {array}\n */\nfunction inverse(source) {\n\tvar m = format(source);\n\n\tvar s0 = m[0] * m[5] - m[4] * m[1];\n\tvar s1 = m[0] * m[6] - m[4] * m[2];\n\tvar s2 = m[0] * m[7] - m[4] * m[3];\n\tvar s3 = m[1] * m[6] - m[5] * m[2];\n\tvar s4 = m[1] * m[7] - m[5] * m[3];\n\tvar s5 = m[2] * m[7] - m[6] * m[3];\n\n\tvar c5 = m[10] * m[15] - m[14] * m[11];\n\tvar c4 = m[9] * m[15] - m[13] * m[11];\n\tvar c3 = m[9] * m[14] - m[13] * m[10];\n\tvar c2 = m[8] * m[15] - m[12] * m[11];\n\tvar c1 = m[8] * m[14] - m[12] * m[10];\n\tvar c0 = m[8] * m[13] - m[12] * m[9];\n\n\tvar determinant = 1 / (s0 * c5 - s1 * c4 + s2 * c3 + s3 * c2 - s4 * c1 + s5 * c0);\n\n\tif (isNaN(determinant) || determinant === Infinity) {\n\t\tthrow new Error('Inverse determinant attempted to divide by zero.')\n\t}\n\n\treturn [\n\t\t(m[5] * c5 - m[6] * c4 + m[7] * c3) * determinant,\n\t\t(-m[1] * c5 + m[2] * c4 - m[3] * c3) * determinant,\n\t\t(m[13] * s5 - m[14] * s4 + m[15] * s3) * determinant,\n\t\t(-m[9] * s5 + m[10] * s4 - m[11] * s3) * determinant,\n\n\t\t(-m[4] * c5 + m[6] * c2 - m[7] * c1) * determinant,\n\t\t(m[0] * c5 - m[2] * c2 + m[3] * c1) * determinant,\n\t\t(-m[12] * s5 + m[14] * s2 - m[15] * s1) * determinant,\n\t\t(m[8] * s5 - m[10] * s2 + m[11] * s1) * determinant,\n\n\t\t(m[4] * c4 - m[5] * c2 + m[7] * c0) * determinant,\n\t\t(-m[0] * c4 + m[1] * c2 - m[3] * c0) * determinant,\n\t\t(m[12] * s4 - m[13] * s2 + m[15] * s0) * determinant,\n\t\t(-m[8] * s4 + m[9] * s2 - m[11] * s0) * determinant,\n\n\t\t(-m[4] * c3 + m[5] * c1 - m[6] * c0) * determinant,\n\t\t(m[0] * c3 - m[1] * c1 + m[2] * c0) * determinant,\n\t\t(-m[12] * s3 + m[13] * s1 - m[14] * s0) * determinant,\n\t\t(m[8] * s3 - m[9] * s1 + m[10] * s0) * determinant\n\t]\n}\n\n/**\n * Returns a 4x4 matrix describing the combined transformations\n * of both arguments.\n *\n * > **Note:** Order is very important. For example, rotating 45°\n * along the Z-axis, followed by translating 500 pixels along the\n * Y-axis... is not the same as translating 500 pixels along the\n * Y-axis, followed by rotating 45° along on the Z-axis.\n *\n * @param  {array} m - Accepts both short and long form matrices.\n * @param  {array} x - Accepts both short and long form matrices.\n * @return {array}\n */\nfunction multiply(m, x) {\n\tvar fm = format(m);\n\tvar fx = format(x);\n\tvar product = [];\n\n\tfor (var i = 0; i < 4; i++) {\n\t\tvar row = [fm[i], fm[i + 4], fm[i + 8], fm[i + 12]];\n\t\tfor (var j = 0; j < 4; j++) {\n\t\t\tvar k = j * 4;\n\t\t\tvar col = [fx[k], fx[k + 1], fx[k + 2], fx[k + 3]];\n\t\t\tvar result =\n\t\t\t\trow[0] * col[0] + row[1] * col[1] + row[2] * col[2] + row[3] * col[3];\n\n\t\t\tproduct[i + k] = result;\n\t\t}\n\t}\n\n\treturn product\n}\n\n/**\n * Attempts to return a 4x4 matrix describing the CSS transform\n * matrix passed in, but will return the identity matrix as a\n * fallback.\n *\n * **Tip:** In virtually all cases, this method is used to convert\n * a CSS matrix (retrieved as a `string` from computed styles) to\n * its equivalent array format.\n *\n * @param  {string} source - String containing a valid CSS `matrix` or `matrix3d` property.\n * @return {array}\n */\nfunction parse(source) {\n\tif (typeof source === 'string') {\n\t\tvar match = source.match(/matrix(3d)?\\(([^)]+)\\)/);\n\t\tif (match) {\n\t\t\tvar raw = match[2].split(', ').map(parseFloat);\n\t\t\treturn format(raw)\n\t\t}\n\t}\n\treturn identity()\n}\n\n/**\n * Returns a 4x4 matrix describing Z-axis rotation.\n *\n * @param  {number} angle - Measured in degrees.\n * @return {array}\n */\nfunction rotate(angle) {\n\treturn rotateZ(angle)\n}\n\n/**\n * Returns a 4x4 matrix describing X-axis rotation.\n *\n * @param  {number} angle - Measured in degrees.\n * @return {array}\n */\nfunction rotateX(angle) {\n\tvar theta = Math.PI / 180 * angle;\n\tvar matrix = identity();\n\n\tmatrix[5] = matrix[10] = Math.cos(theta);\n\tmatrix[6] = matrix[9] = Math.sin(theta);\n\tmatrix[9] *= -1;\n\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing Y-axis rotation.\n *\n * @param  {number} angle - Measured in degrees.\n * @return {array}\n */\nfunction rotateY(angle) {\n\tvar theta = Math.PI / 180 * angle;\n\tvar matrix = identity();\n\n\tmatrix[0] = matrix[10] = Math.cos(theta);\n\tmatrix[2] = matrix[8] = Math.sin(theta);\n\tmatrix[2] *= -1;\n\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing Z-axis rotation.\n *\n * @param  {number} angle - Measured in degrees.\n * @return {array}\n */\nfunction rotateZ(angle) {\n\tvar theta = Math.PI / 180 * angle;\n\tvar matrix = identity();\n\n\tmatrix[0] = matrix[5] = Math.cos(theta);\n\tmatrix[1] = matrix[4] = Math.sin(theta);\n\tmatrix[4] *= -1;\n\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing 2D scaling. The first argument\n * is used for both X and Y-axis scaling, unless an optional\n * second argument is provided to explicitly define Y-axis scaling.\n *\n * @param  {number} scalar    - Decimal multiplier.\n * @param  {number} [scalarY] - Decimal multiplier.\n * @return {array}\n */\nfunction scale(scalar, scalarY) {\n\tvar matrix = identity();\n\n\tmatrix[0] = scalar;\n\tmatrix[5] = typeof scalarY === 'number' ? scalarY : scalar;\n\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing X-axis scaling.\n *\n * @param  {number} scalar - Decimal multiplier.\n * @return {array}\n */\nfunction scaleX(scalar) {\n\tvar matrix = identity();\n\tmatrix[0] = scalar;\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing Y-axis scaling.\n *\n * @param  {number} scalar - Decimal multiplier.\n * @return {array}\n */\nfunction scaleY(scalar) {\n\tvar matrix = identity();\n\tmatrix[5] = scalar;\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing Z-axis scaling.\n *\n * @param  {number} scalar - Decimal multiplier.\n * @return {array}\n */\nfunction scaleZ(scalar) {\n\tvar matrix = identity();\n\tmatrix[10] = scalar;\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing shear. The first argument\n * defines X-axis shearing, and an optional second argument\n * defines Y-axis shearing.\n *\n * @param  {number} angleX   - Measured in degrees.\n * @param  {number} [angleY] - Measured in degrees.\n * @return {array}\n */\nfunction skew(angleX, angleY) {\n\tvar thetaX = Math.PI / 180 * angleX;\n\tvar matrix = identity();\n\n\tmatrix[4] = Math.tan(thetaX);\n\n\tif (angleY) {\n\t\tvar thetaY = Math.PI / 180 * angleY;\n\t\tmatrix[1] = Math.tan(thetaY);\n\t}\n\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing X-axis shear.\n *\n * @param  {number} angle - Measured in degrees.\n * @return {array}\n */\nfunction skewX(angle) {\n\tvar theta = Math.PI / 180 * angle;\n\tvar matrix = identity();\n\n\tmatrix[4] = Math.tan(theta);\n\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing Y-axis shear.\n *\n * @param  {number} angle - Measured in degrees\n * @return {array}\n */\nfunction skewY(angle) {\n\tvar theta = Math.PI / 180 * angle;\n\tvar matrix = identity();\n\n\tmatrix[1] = Math.tan(theta);\n\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing 2D translation. The first\n * argument defines X-axis translation, and an optional second\n * argument defines Y-axis translation.\n *\n * @param  {number} distanceX   - Measured in pixels.\n * @param  {number} [distanceY] - Measured in pixels.\n * @return {array}\n */\nfunction translate(distanceX, distanceY) {\n\tvar matrix = identity();\n\tmatrix[12] = distanceX;\n\n\tif (distanceY) {\n\t\tmatrix[13] = distanceY;\n\t}\n\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing X-axis translation.\n *\n * @param  {number} distance - Measured in pixels.\n * @return {array}\n */\nfunction translateX(distance) {\n\tvar matrix = identity();\n\tmatrix[12] = distance;\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing Y-axis translation.\n *\n * @param  {number} distance - Measured in pixels.\n * @return {array}\n */\nfunction translateY(distance) {\n\tvar matrix = identity();\n\tmatrix[13] = distance;\n\treturn matrix\n}\n\n/**\n * Returns a 4x4 matrix describing Z-axis translation.\n *\n * @param  {number} distance - Measured in pixels.\n * @return {array}\n */\nfunction translateZ(distance) {\n\tvar matrix = identity();\n\tmatrix[14] = distance;\n\treturn matrix\n}\n\nexport { format, identity, inverse, multiply, parse, rotate, rotateX, rotateY, rotateZ, scale, scaleX, scaleY, scaleZ, skew, skewX, skewY, translate, translateX, translateY, translateZ };\n"],"names":["format","source","constructor","Array","TypeError","length","matrix","identity","RangeError","i","push","multiply","m","x","fm","fx","product","row","j","k","col","result","parse","match","split","map","parseFloat","scaleX","scalar","scaleY","translateX","distance","translateY"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsCA,SAASA,OAAOC,GACf,GAAIA,EAAO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