* Detect which mechanism should be used to apply a move to this element. * - framer-motion: element is motion.* with animate prop that ALREADY contains x or y * (only if the animate prop already controls position — don't inject position into * opacity-only or scale-only animations) * - trans
(nodePath: any, axis: "x" | "y")
| 1001 | * without destroying existing values |
| 1002 | */ |
| 1003 | function detectMoveMechanism(nodePath: any, axis: "x" | "y"): MoveMechanism { |
| 1004 | const node = nodePath.node; |
| 1005 | const tagName = getJSXTagName(node); |
| 1006 | const attrs = node.openingElement?.attributes ?? []; |
| 1007 | |
| 1008 | // Check for framer-motion: tag starts with "motion." and animate prop has x/y |
| 1009 | if (tagName?.startsWith("motion.")) { |
| 1010 | const animateProp = attrs.find( |
| 1011 | (a: any) => a.type === "JSXAttribute" && a.name?.name === "animate" |
| 1012 | ); |
| 1013 | if (animateProp?.value?.type === "JSXExpressionContainer") { |
| 1014 | const expr = animateProp.value.expression; |
| 1015 | if (expr.type === "ObjectExpression") { |
| 1016 | const propName = axis === "x" ? "x" : "y"; |
| 1017 | const hasAxisProp = expr.properties.some( |
| 1018 | (p: any) => p.type === "ObjectProperty" && p.key?.name === propName |
| 1019 | ); |
| 1020 | if (hasAxisProp) return "framer-motion"; |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | return "translate-class"; |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * Apply move to a framer-motion element by modifying the animate prop's existing x/y value. |
no test coverage detected