MCPcopy
hub / github.com/fengyuanchen/cropperjs / getAdjustedSizes

Function getAdjustedSizes

packages/utils/src/functions.ts:332–363  ·  view source on GitHub ↗
(
  data: SizeAdjustmentData | SizeAdjustmentDataWithoutWidth | SizeAdjustmentDataWithoutHeight,
  type: SizeAdjustmentType = SIZE_ADJUSTMENT_TYPE_CONTAIN,
)

Source from the content-addressed store, hash-verified

330 * @returns {object} Returns the result sizes.
331 */
332export 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.

Callers 5

$initSelectionMethod · 0.90
$changeMethod · 0.90
$toCanvasMethod · 0.90
index.spec.tsFile · 0.90
$toCanvasMethod · 0.90

Calls 1

isPositiveNumberFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…