UNPKG

fabric

Version:

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

1 lines 1.47 kB
{"version":3,"file":"findScaleTo.min.mjs","names":[],"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"],"mappings":"AAUA,MAAa,GAAkB,EAAe,IAC5C,KAAK,IACH,EAAY,MAAQ,EAAO,MAC3B,EAAY,OAAS,EAAO,OAAA,CAWnB,GAAoB,EAAe,IAC9C,KAAK,IACH,EAAY,MAAQ,EAAO,MAC3B,EAAY,OAAS,EAAO,OAAA,CAAA,OAAA,KAAA,iBAAA,KAAA"}