(css: string)
| 918 | * flattening their scene rather than failing it. |
| 919 | */ |
| 920 | export function parseTransformMatrix(css: string): number[] | null { |
| 921 | if (!css || css === "none") return null; |
| 922 | |
| 923 | const match2d = css.match( |
| 924 | /^matrix\(\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,)]+)\s*\)$/, |
| 925 | ); |
| 926 | if (match2d) { |
| 927 | const values = match2d.slice(1, 7).map(Number); |
| 928 | if (!values.every(Number.isFinite)) return null; |
| 929 | return values; |
| 930 | } |
| 931 | |
| 932 | const match3d = css.match(/^matrix3d\(\s*([^)]+)\)$/); |
| 933 | if (match3d) { |
| 934 | const raw = match3d[1]; |
| 935 | if (!raw) return null; |
| 936 | const parts = raw.split(",").map((s) => Number(s.trim())); |
| 937 | if (parts.length !== 16 || !parts.every(Number.isFinite)) return null; |
| 938 | // 3D-significance check: a flat 2D transform expressed as matrix3d has |
| 939 | // a3=b3=c1=c2=d1=d2=d3=0, c3=1, d4=1. Any deviation means the composition |
| 940 | // is using real 3D (perspective, rotateX/Y) which the engine path can't |
| 941 | // represent — we project to 2D and the visual will silently drop depth. |
| 942 | // Warn once per process so authors don't get a misleading "looks fine in |
| 943 | // studio, broken in render" experience without any signal. Z translation |
| 944 | // (c4 = parts[14]) is intentionally dropped by the 2D projection below |
| 945 | // and does NOT trigger this warning — that's the GSAP `force3D: true` |
| 946 | // happy path. |
| 947 | warnIfZSignificant(parts); |
| 948 | // Extract column-major 2D affine: m11, m12, m21, m22, m41, m42. |
| 949 | return [ |
| 950 | parts[0] as number, |
| 951 | parts[1] as number, |
| 952 | parts[4] as number, |
| 953 | parts[5] as number, |
| 954 | parts[12] as number, |
| 955 | parts[13] as number, |
| 956 | ]; |
| 957 | } |
| 958 | |
| 959 | return null; |
| 960 | } |
| 961 | |
| 962 | let warnedZSignificant = false; |
| 963 | const Z_EPSILON = 1e-6; |
no test coverage detected