( data: SizeAdjustmentData | SizeAdjustmentDataWithoutWidth | SizeAdjustmentDataWithoutHeight, type: SizeAdjustmentType = SIZE_ADJUSTMENT_TYPE_CONTAIN, )
| 330 | * @returns {object} Returns the result sizes. |
| 331 | */ |
| 332 | export function getAdjustedSizes( |
| 333 | data: SizeAdjustmentData | SizeAdjustmentDataWithoutWidth | SizeAdjustmentDataWithoutHeight, |
| 334 | type: SizeAdjustmentType = SIZE_ADJUSTMENT_TYPE_CONTAIN, |
| 335 | ): { |
| 336 | width: number; |
| 337 | height: number; |
| 338 | } { |
| 339 | const { aspectRatio } = data; |
| 340 | let { width, height } = data as SizeAdjustmentData; |
| 341 | const isValidWidth = isPositiveNumber(width); |
| 342 | const isValidHeight = isPositiveNumber(height); |
| 343 | |
| 344 | if (isValidWidth && isValidHeight) { |
| 345 | const adjustedWidth = height * aspectRatio; |
| 346 | |
| 347 | if ((type === SIZE_ADJUSTMENT_TYPE_CONTAIN && adjustedWidth > width) |
| 348 | || (type === SIZE_ADJUSTMENT_TYPE_COVER && adjustedWidth < width)) { |
| 349 | height = width / aspectRatio; |
| 350 | } else { |
| 351 | width = height * aspectRatio; |
| 352 | } |
| 353 | } else if (isValidWidth) { |
| 354 | height = width / aspectRatio; |
| 355 | } else if (isValidHeight) { |
| 356 | width = height * aspectRatio; |
| 357 | } |
| 358 | |
| 359 | return { |
| 360 | width, |
| 361 | height, |
| 362 | }; |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Multiply multiple matrices. |
no test coverage detected
searching dependent graphs…