UNPKG

fabric

Version:

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

1 lines 1.36 kB
{"version":3,"file":"boundingBoxFromPoints.min.mjs","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"],"names":["makeBoundingBoxFromPoints","points","left","top","width","height","i","len","length","x","y"],"mappings":"AAQaA,MAAAA,EAA6BC,IACxC,IAAIC,EAAO,EACTC,EAAM,EACNC,EAAQ,EACRC,EAAS,EAEX,IAAK,IAAIC,EAAI,EAAGC,EAAMN,EAAOO,OAAQF,EAAIC,EAAKD,IAAK,CACjD,MAAMG,EAAEA,EAACC,EAAEA,GAAMT,EAAOK,IACpBG,EAAIL,IAAUE,KAAGF,EAAQK,IACzBA,EAAIP,IAASI,KAAGJ,EAAOO,IACvBC,EAAIL,IAAWC,KAAGD,EAASK,IAC3BA,EAAIP,IAAQG,KAAGH,EAAMO,EAC3B,CAEA,MAAO,CACLR,OACAC,MACAC,MAAOA,EAAQF,EACfG,OAAQA,EAASF,EAClB"}