fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 2.65 kB
Source Map (JSON)
{"version":3,"file":"utils.min.mjs","names":[],"sources":["../../../../src/LayoutManager/LayoutStrategies/utils.ts"],"sourcesContent":["import { Point, ZERO } from '../../Point';\nimport type { Group } from '../../shapes/Group';\nimport type { FabricObject } from '../../shapes/Object/FabricObject';\nimport { multiplyTransformMatrixArray } from '../../util/misc/matrix';\nimport { sizeAfterTransform } from '../../util/misc/objectTransforms';\nimport {\n calcPlaneChangeMatrix,\n sendVectorToPlane,\n} from '../../util/misc/planeChange';\n\n/**\n * @returns 2 points, the tl and br corners of the non rotated bounding box of an object\n * in the {@link group} plane, taking into account objects that {@link group} is their parent\n * but also belong to the active selection.\n */\nexport const getObjectBounds = (\n destinationGroup: Group,\n object: FabricObject,\n): Point[] => {\n const {\n strokeUniform,\n strokeWidth,\n width,\n height,\n group: currentGroup,\n } = object;\n const t =\n currentGroup && currentGroup !== destinationGroup\n ? calcPlaneChangeMatrix(\n currentGroup.calcTransformMatrix(),\n destinationGroup.calcTransformMatrix(),\n )\n : null;\n const objectCenter = t\n ? object.getRelativeCenterPoint().transform(t)\n : object.getRelativeCenterPoint();\n const accountForStroke = !object['isStrokeAccountedForInDimensions']();\n const strokeUniformVector =\n strokeUniform && accountForStroke\n ? sendVectorToPlane(\n new Point(strokeWidth, strokeWidth),\n undefined,\n destinationGroup.calcTransformMatrix(),\n )\n : ZERO;\n const scalingStrokeWidth =\n !strokeUniform && accountForStroke ? strokeWidth : 0;\n const sizeVector = sizeAfterTransform(\n width + scalingStrokeWidth,\n height + scalingStrokeWidth,\n multiplyTransformMatrixArray([t, object.calcOwnMatrix()], true),\n )\n .add(strokeUniformVector)\n .scalarDivide(2);\n return [objectCenter.subtract(sizeVector), objectCenter.add(sizeVector)];\n};\n"],"mappings":"qTAeA,MAAa,GACX,EACA,IAAA,CAEA,GAAA,CAAM,cACJ,EAAA,YACA,EAAA,MACA,EAAA,OACA,EACA,MAAO,GACL,EACE,EACJ,GAAgB,IAAiB,EAC7B,EACE,EAAa,qBAAA,CACb,EAAiB,qBAAA,CAAA,CAEnB,KACA,EAAe,EACjB,EAAO,wBAAA,CAAyB,UAAU,EAAA,CAC1C,EAAO,wBAAA,CACL,EAAA,CAAoB,EAAO,kCAAA,CAC3B,EACJ,GAAiB,EACb,EACE,IAAI,EAAM,EAAa,EAAA,CAAA,IACvB,GACA,EAAiB,qBAAA,CAAA,CAEnB,EACA,EAAA,CACH,GAAiB,EAAmB,EAAc,EAC/C,EAAa,EACjB,EAAQ,EACR,EAAS,EACT,EAA6B,CAAC,EAAG,EAAO,eAAA,CAAA,CAAA,CAAkB,EAAA,CAAA,CAEzD,IAAI,EAAA,CACJ,aAAa,EAAA,CAChB,MAAO,CAAC,EAAa,SAAS,EAAA,CAAa,EAAa,IAAI,EAAA,CAAA,EAAA,OAAA,KAAA"}