UNPKG

fabric

Version:

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

1 lines 1.57 kB
{"version":3,"file":"findScaleTo.min.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":"AAUO,MAAMA,EAAiBA,CAACC,EAAeC,IAC5CC,KAAKC,IACHF,EAAYG,MAAQJ,EAAOI,MAC3BH,EAAYI,OAASL,EAAOK,QAWnBC,EAAmBA,CAACN,EAAeC,IAC9CC,KAAKK,IACHN,EAAYG,MAAQJ,EAAOI,MAC3BH,EAAYI,OAASL,EAAOK"}