{"version":3,"file":"transform.mjs","sources":["../../../../src/projection/styles/transform.ts"],"sourcesContent":["import type { Delta, Point } from \"motion-utils\"\nimport type { ResolvedValues } from \"../../node/types\"\nimport { angleTransforms } from \"../utils/has-transform\"\n\nexport function buildProjectionTransform(\n    delta: Delta,\n    treeScale: Point,\n    latestTransform?: ResolvedValues\n): string {\n    let transform = \"\"\n\n    /**\n     * The translations we use to calculate are always relative to the viewport coordinate space.\n     * But when we apply scales, we also scale the coordinate space of an element and its children.\n     * For instance if we have a treeScale (the culmination of all parent scales) of 0.5 and we need\n     * to move an element 100 pixels, we actually need to move it 200 in within that scaled space.\n     */\n    const xTranslate = delta.x.translate / treeScale.x\n    const yTranslate = delta.y.translate / treeScale.y\n    const zTranslate = latestTransform?.z || 0\n    if (xTranslate || yTranslate || zTranslate) {\n        transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `\n    }\n\n    let angles = \"\"\n    if (latestTransform) {\n        const { transformPerspective } = latestTransform\n        if (transformPerspective)\n            transform = `perspective(${transformPerspective}px) ${transform}`\n\n        for (let i = 0; i < angleTransforms.length; i++) {\n            const key = angleTransforms[i]\n            const value = latestTransform[key]\n            if (value) angles += `${key}(${value}deg) `\n            // Additive `rotate()` so user `rotate` isn't clobbered.\n            if (!i && latestTransform.pathRotation)\n                angles += `rotate(${latestTransform.pathRotation}deg) `\n        }\n    }\n\n    if (angles) {\n        /**\n         * Apply scale correction for the tree transform.\n         * This will apply scale to the screen-orientated axes.\n         */\n        if (treeScale.x !== 1 || treeScale.y !== 1) {\n            transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `\n        }\n\n        transform += angles\n\n        /**\n         * Apply scale to match the size of the element to the size we want it.\n         * This will apply scale to the element-orientated axes.\n         */\n        const elementScaleX = delta.x.scale * treeScale.x\n        const elementScaleY = delta.y.scale * treeScale.y\n        if (elementScaleX !== 1 || elementScaleY !== 1) {\n            transform += `scale(${elementScaleX}, ${elementScaleY})`\n        }\n    } else if (delta.x.scale !== 1 || delta.y.scale !== 1) {\n        /**\n         * With no rotation or skew between them, the tree scale correction\n         * (1 / treeScale) and the element scale (delta.scale * treeScale)\n         * combine into a single scale. A shorter transform is quicker for\n         * the browser to parse, which matters when it's set every frame.\n         */\n        transform += `scale(${delta.x.scale}, ${delta.y.scale})`\n    } else if (!transform && (treeScale.x !== 1 || treeScale.y !== 1)) {\n        /**\n         * Inside a scaled tree the transform must never be \"none\", even when\n         * this element's own delta is the identity: scale correction for\n         * borderRadius and boxShadow is skipped for \"none\", and the element\n         * would gain and lose its stacking context as the delta snaps.\n         */\n        transform = \"scale(1, 1)\"\n    }\n\n    return transform || \"none\"\n}\n"],"names":[],"mappings":";;SAIgB,wBAAwB,CACpC,KAAY,EACZ,SAAgB,EAChB,eAAgC,EAAA;IAEhC,IAAI,SAAS,GAAG,EAAE;AAElB;;;;;AAKG;IACH,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAClD,IAAA,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC;AAC1C,IAAA,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU,EAAE;QACxC,SAAS,GAAG,eAAe,UAAU,CAAA,IAAA,EAAO,UAAU,CAAA,IAAA,EAAO,UAAU,MAAM;IACjF;IAEA,IAAI,MAAM,GAAG,EAAE;IACf,IAAI,eAAe,EAAE;AACjB,QAAA,MAAM,EAAE,oBAAoB,EAAE,GAAG,eAAe;AAChD,QAAA,IAAI,oBAAoB;AACpB,YAAA,SAAS,GAAG,CAAA,YAAA,EAAe,oBAAoB,CAAA,IAAA,EAAO,SAAS,EAAE;AAErE,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC7C,YAAA,MAAM,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