diff --git a/packages/image-shrink/src/utils/render/fallback.ts b/packages/image-shrink/src/utils/render/fallback.ts index f553e49e..a5d37550 100644 --- a/packages/image-shrink/src/utils/render/fallback.ts +++ b/packages/image-shrink/src/utils/render/fallback.ts @@ -1,6 +1,14 @@ import { testCanvasSize } from '../canvas/testCanvasSize' import { canvasResize } from '../canvas/canvasResize' +type TFallback = { + img: HTMLImageElement + sourceW: number + targetW: number + targetH: number + step: number +} + /** * Goes from target to source by step, the last incomplete step is dropped. * Always returns at least one step - target. Source step is not included. @@ -9,12 +17,12 @@ import { canvasResize } from '../canvas/canvasResize' * Example with step = 0.71, source = 2000, target = 400 400 (target) <- 563 <- * 793 <- 1117 <- 1574 (dropped) <- [2000 (source)] */ -const calcShrinkSteps = function ( - sourceW: number, - targetW: number, - targetH: number, - step: number -) { +const calcShrinkSteps = function ({ + sourceW, + targetW, + targetH, + step +}: Omit) { const steps: Array<[number, number]> = [] let sW: number = targetW let sH: number = targetH @@ -47,14 +55,8 @@ export const fallback = ({ targetW, targetH, step -}: { - img: HTMLImageElement - sourceW: number - targetW: number - targetH: number - step: number -}): Promise => { - const steps = calcShrinkSteps(sourceW, targetW, targetH, step) +}: TFallback): Promise => { + const steps = calcShrinkSteps({ sourceW, targetW, targetH, step }) return steps.reduce( (chain, [w, h]) => { diff --git a/packages/image-shrink/src/utils/render/native.ts b/packages/image-shrink/src/utils/render/native.ts index 6a7d2dc3..d6c1d4e1 100644 --- a/packages/image-shrink/src/utils/render/native.ts +++ b/packages/image-shrink/src/utils/render/native.ts @@ -1,5 +1,11 @@ import { canvasResize } from '../canvas/canvasResize' +type TNative = { + img: HTMLImageElement + targetW: number + targetH: number +} + /** * Native high-quality canvas resampling * @@ -7,12 +13,5 @@ import { canvasResize } from '../canvas/canvasResize' * https://caniuse.com/mdn-api_canvasrenderingcontext2d_imagesmoothingenabled * Target dimensions expected to be supported by browser. */ -export const native = ({ - img, - targetW, - targetH -}: { - img: HTMLImageElement - targetW: number - targetH: number -}) => canvasResize(img, targetW, targetH) +export const native = ({ img, targetW, targetH }: TNative) => + canvasResize(img, targetW, targetH)