MCPcopy
hub / github.com/greensock/GSAP / _parseTransform

Function _parseTransform

src/CSSPlugin.js:597–759  ·  view source on GitHub ↗
(target, uncache)

Source from the content-addressed store, hash-verified

595 target.setAttribute("data-svg-origin", xOrigin + " " + yOrigin);
596 },
597 _parseTransform = (target, uncache) => {
598 let cache = target._gsap || new GSCache(target);
599 if ("x" in cache && !uncache && !cache.uncache) {
600 return cache;
601 }
602 let style = target.style,
603 invertedScaleX = cache.scaleX < 0,
604 px = "px",
605 deg = "deg",
606 cs = getComputedStyle(target),
607 origin = _getComputedProperty(target, _transformOriginProp) || "0",
608 x, y, z, scaleX, scaleY, rotation, rotationX, rotationY, skewX, skewY, perspective, xOrigin, yOrigin,
609 matrix, angle, cos, sin, a, b, c, d, a12, a22, t1, t2, t3, a13, a23, a33, a42, a43, a32;
610 x = y = z = rotation = rotationX = rotationY = skewX = skewY = perspective = 0;
611 scaleX = scaleY = 1;
612 cache.svg = !!(target.getCTM && _isSVG(target));
613
614 if (cs.translate) { // accommodate independent transforms by combining them into normal ones.
615 if (cs.translate !== "none" || cs.scale !== "none" || cs.rotate !== "none") {
616 style[_transformProp] = (cs.translate !== "none" ? "translate3d(" + (cs.translate + " 0 0").split(" ").slice(0, 3).join(", ") + ") " : "") + (cs.rotate !== "none" ? "rotate(" + cs.rotate + ") " : "") + (cs.scale !== "none" ? "scale(" + cs.scale.split(" ").join(",") + ") " : "") + (cs[_transformProp] !== "none" ? cs[_transformProp] : "");
617 }
618 style.scale = style.rotate = style.translate = "none";
619 }
620
621 matrix = _getMatrix(target, cache.svg);
622 if (cache.svg) {
623 if (cache.uncache) { // if cache.uncache is true (and maybe if origin is 0,0), we need to set element.style.transformOrigin = (cache.xOrigin - bbox.x) + "px " + (cache.yOrigin - bbox.y) + "px". Previously we let the data-svg-origin stay instead, but when introducing revert(), it complicated things.
624 t2 = target.getBBox();
625 origin = (cache.xOrigin - t2.x) + "px " + (cache.yOrigin - t2.y) + "px";
626 t1 = "";
627 } else {
628 t1 = !uncache && target.getAttribute("data-svg-origin"); // Remember, to work around browser inconsistencies we always force SVG elements' transformOrigin to 0,0 and offset the translation accordingly.
629 }
630 _applySVGOrigin(target, t1 || origin, !!t1 || cache.originIsAbsolute, cache.smooth !== false, matrix);
631 }
632 xOrigin = cache.xOrigin || 0;
633 yOrigin = cache.yOrigin || 0;
634 if (matrix !== _identity2DMatrix) {
635 a = matrix[0]; //a11
636 b = matrix[1]; //a21
637 c = matrix[2]; //a31
638 d = matrix[3]; //a41
639 x = a12 = matrix[4];
640 y = a22 = matrix[5];
641
642 //2D matrix
643 if (matrix.length === 6) {
644 scaleX = Math.sqrt(a * a + b * b);
645 scaleY = Math.sqrt(d * d + c * c);
646 rotation = (a || b) ? _atan2(b, a) * _RAD2DEG : 0; //note: if scaleX is 0, we cannot accurately measure rotation. Same for skewX with a scaleY of 0. Therefore, we default to the previously recorded value (or zero if that doesn't exist).
647 skewX = (c || d) ? _atan2(c, d) * _RAD2DEG + rotation : 0;
648 skewX && (scaleY *= Math.abs(Math.cos(skewX * _DEG2RAD)));
649 if (cache.svg) {
650 x -= xOrigin - (xOrigin * a + yOrigin * c);
651 y -= yOrigin - (xOrigin * b + yOrigin * d);
652 }
653
654 //3D matrix

Callers 4

_getFunction · 0.70
_renderClearPropsFunction · 0.70
_addRawTransformPTsFunction · 0.70
initFunction · 0.70

Calls 8

_roundFunction · 0.90
_getComputedPropertyFunction · 0.70
_isSVGFunction · 0.70
_getMatrixFunction · 0.70
_applySVGOriginFunction · 0.70
_isNullTransformFunction · 0.70
_firstTwoOnlyFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…