UNPKG

fabric

Version:

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

1 lines 1.27 kB
{"version":3,"file":"boundingBoxFromPoints.min.mjs","names":[],"sources":["../../../../src/util/misc/boundingBoxFromPoints.ts"],"sourcesContent":["import type { XY } from '../../Point';\nimport type { TBBox } from '../../typedefs';\n\n/**\n * Calculates bounding box (left, top, width, height) from given `points`\n * @param {XY[]} points\n * @return {Object} Object with left, top, width, height properties\n */\nexport const makeBoundingBoxFromPoints = (points: XY[]): TBBox => {\n let left = 0,\n top = 0,\n width = 0,\n height = 0;\n\n for (let i = 0, len = points.length; i < len; i++) {\n const { x, y } = points[i];\n if (x > width || !i) width = x;\n if (x < left || !i) left = x;\n if (y > height || !i) height = y;\n if (y < top || !i) top = y;\n }\n\n return {\n left,\n top,\n width: width - left,\n height: height - top,\n };\n};\n"],"mappings":"AAQA,MAAa,EAA6B,GAAA,CACxC,IAAI,EAAO,EACT,EAAM,EACN,EAAQ,EACR,EAAS,EAEX,IAAK,IAAI,EAAI,EAAG,EAAM,EAAO,OAAQ,EAAI,EAAK,IAAK,CACjD,GAAA,CAAM,EAAE,EAAA,EAAG,GAAM,EAAO,IACpB,EAAI,GAAA,CAAU,KAAG,EAAQ,IACzB,EAAI,GAAA,CAAS,KAAG,EAAO,IACvB,EAAI,GAAA,CAAW,KAAG,EAAS,IAC3B,EAAI,GAAA,CAAQ,KAAG,EAAM,GAG3B,MAAO,CACL,KAAA,EACA,IAAA,EACA,MAAO,EAAQ,EACf,OAAQ,EAAS,EAAA,EAAA,OAAA,KAAA"}