UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

1 lines 1.79 kB
{"version":3,"file":"findScaleTo.mjs","sources":["../../../../src/util/misc/findScaleTo.ts"],"sourcesContent":["import type { TSize } from '../../typedefs';\n\n/**\n * Finds the scale for the object source to fit inside the object destination,\n * keeping aspect ratio intact.\n * respect the total allowed area for the cache.\n * @param {TSize} source natural unscaled size of the object\n * @param {TSize} destination natural unscaled size of the object\n * @return {Number} scale factor to apply to source to fit into destination\n */\nexport const findScaleToFit = (source: TSize, destination: TSize) =>\n Math.min(\n destination.width / source.width,\n destination.height / source.height,\n );\n\n/**\n * Finds the scale for the object source to cover entirely the object destination,\n * keeping aspect ratio intact.\n * respect the total allowed area for the cache.\n * @param {TSize} source natural unscaled size of the object\n * @param {TSize} destination natural unscaled size of the object\n * @return {Number} scale factor to apply to source to cover destination\n */\nexport const findScaleToCover = (source: TSize, destination: TSize) =>\n Math.max(\n destination.width / source.width,\n destination.height / source.height,\n );\n"],"names":["findScaleToFit","source","destination","Math","min","width","height","findScaleToCover","max"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc,GAAGA,CAACC,MAAa,EAAEC,WAAkB,KAC9DC,IAAI,CAACC,GAAG,CACNF,WAAW,CAACG,KAAK,GAAGJ,MAAM,CAACI,KAAK,EAChCH,WAAW,CAACI,MAAM,GAAGL,MAAM,CAACK,MAC9B,EAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,gBAAgB,GAAGA,CAACN,MAAa,EAAEC,WAAkB,KAChEC,IAAI,CAACK,GAAG,CACNN,WAAW,CAACG,KAAK,GAAGJ,MAAM,CAACI,KAAK,EAChCH,WAAW,CAACI,MAAM,GAAGL,MAAM,CAACK,MAC9B;;;;"}