( width: number, height: number, command: FrameSettingsPathCommand )
| 2 | import { formatFrameDimension } from './formatFrameDimension.js' |
| 3 | |
| 4 | const formatCommand = ( |
| 5 | width: number, |
| 6 | height: number, |
| 7 | command: FrameSettingsPathCommand |
| 8 | ): string => { |
| 9 | if (Array.isArray(command)) { |
| 10 | const [name, ...dimensions] = command |
| 11 | |
| 12 | // One dimension horizontal commands. |
| 13 | if (name === 'H' || name === 'h') { |
| 14 | return `${name} ${formatFrameDimension(width, dimensions[0])}` |
| 15 | } |
| 16 | |
| 17 | // One dimension vertical commands. |
| 18 | if (name === 'V' || name === 'v') { |
| 19 | return `${name} ${formatFrameDimension(height, dimensions[0])}` |
| 20 | } |
| 21 | |
| 22 | // Elliptical Arc Curve commands. |
| 23 | if (name === 'A' || name === 'a') { |
| 24 | const [rx, ry, angle, largeArcFlag, sweepFlag, x, y] = dimensions |
| 25 | const values = [ |
| 26 | formatFrameDimension(width, rx), |
| 27 | formatFrameDimension(height, ry), |
| 28 | angle, |
| 29 | largeArcFlag, |
| 30 | sweepFlag, |
| 31 | formatFrameDimension(width, x), |
| 32 | formatFrameDimension(height, y) |
| 33 | ].join(',') |
| 34 | |
| 35 | return name + ' ' + values |
| 36 | } |
| 37 | |
| 38 | // Multiple (x,y)+ dimensions. |
| 39 | const values = dimensions |
| 40 | .map((dimension, index) => { |
| 41 | const isEven = index % 2 === 0 |
| 42 | const size = isEven ? width : height |
| 43 | return formatFrameDimension(size, dimension) |
| 44 | }) |
| 45 | .join(',') |
| 46 | |
| 47 | return name + ' ' + values |
| 48 | } |
| 49 | |
| 50 | // No dimensions commands. |
| 51 | return command |
| 52 | } |
| 53 | |
| 54 | const formatFramePath = ( |
| 55 | width: number, |
no test coverage detected