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.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,kBAAkB,QAAe,gBAC5C,KAAK,IACH,YAAY,QAAQ,OAAO,OAC3B,YAAY,SAAS,OAAO,OAC7B;;;;;;;;;AAUH,MAAa,oBAAoB,QAAe,gBAC9C,KAAK,IACH,YAAY,QAAQ,OAAO,OAC3B,YAAY,SAAS,OAAO,OAC7B"}