(token: string, available: number)
| 204 | // `available` is the "slack" (box dimension - content dimension). |
| 205 | // fallow-ignore-next-line complexity |
| 206 | function resolveToken(token: string, available: number): number { |
| 207 | if (token === "left" || token === "top") return 0; |
| 208 | if (token === "right" || token === "bottom") return available; |
| 209 | if (token === "center") return available / 2; |
| 210 | if (token.endsWith("%")) { |
| 211 | const pct = parseFloat(token) / 100; |
| 212 | return isNaN(pct) ? available / 2 : pct * available; |
| 213 | } |
| 214 | if (token.endsWith("px")) { |
| 215 | const px = parseFloat(token); |
| 216 | return isNaN(px) ? available / 2 : px; |
| 217 | } |
| 218 | // Bare number — treat as px |
| 219 | const n = parseFloat(token); |
| 220 | return isNaN(n) ? available / 2 : n; |
| 221 | } |
| 222 | |
| 223 | const availX = box.width - content.width; |
| 224 | const availY = box.height - content.height; |
no outgoing calls
no test coverage detected