UNPKG

fabric

Version:

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

1 lines 3.63 kB
{"version":3,"file":"utils.mjs","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"],"names":["getObjectBounds","destinationGroup","object","strokeUniform","strokeWidth","width","height","group","currentGroup","t","calcPlaneChangeMatrix","calcTransformMatrix","objectCenter","getRelativeCenterPoint","transform","accountForStroke","strokeUniformVector","sendVectorToPlane","Point","undefined","ZERO","scalingStrokeWidth","sizeVector","sizeAfterTransform","multiplyTransformMatrixArray","calcOwnMatrix","add","scalarDivide","subtract"],"mappings":";;;;;AAUA;AACA;AACA;AACA;AACA;MACaA,eAAe,GAAGA,CAC7BC,gBAAuB,EACvBC,MAAoB,KACR;EACZ,MAAM;IACJC,aAAa;IACbC,WAAW;IACXC,KAAK;IACLC,MAAM;AACNC,IAAAA,KAAK,EAAEC,YAAAA;AACT,GAAC,GAAGN,MAAM,CAAA;EACV,MAAMO,CAAC,GACLD,YAAY,IAAIA,YAAY,KAAKP,gBAAgB,GAC7CS,qBAAqB,CACnBF,YAAY,CAACG,mBAAmB,EAAE,EAClCV,gBAAgB,CAACU,mBAAmB,EACtC,CAAC,GACD,IAAI,CAAA;AACV,EAAA,MAAMC,YAAY,GAAGH,CAAC,GAClBP,MAAM,CAACW,sBAAsB,EAAE,CAACC,SAAS,CAACL,CAAC,CAAC,GAC5CP,MAAM,CAACW,sBAAsB,EAAE,CAAA;EACnC,MAAME,gBAAgB,GAAG,CAACb,MAAM,CAAC,kCAAkC,CAAC,EAAE,CAAA;EACtE,MAAMc,mBAAmB,GACvBb,aAAa,IAAIY,gBAAgB,GAC7BE,iBAAiB,CACf,IAAIC,KAAK,CAACd,WAAW,EAAEA,WAAW,CAAC,EACnCe,SAAS,EACTlB,gBAAgB,CAACU,mBAAmB,EACtC,CAAC,GACDS,IAAI,CAAA;EACV,MAAMC,kBAAkB,GACtB,CAAClB,aAAa,IAAIY,gBAAgB,GAAGX,WAAW,GAAG,CAAC,CAAA;AACtD,EAAA,MAAMkB,UAAU,GAAGC,kBAAkB,CACnClB,KAAK,GAAGgB,kBAAkB,EAC1Bf,MAAM,GAAGe,kBAAkB,EAC3BG,4BAA4B,CAAC,CAACf,CAAC,EAAEP,MAAM,CAACuB,aAAa,EAAE,CAAC,EAAE,IAAI,CAChE,CAAC,CACEC,GAAG,CAACV,mBAAmB,CAAC,CACxBW,YAAY,CAAC,CAAC,CAAC,CAAA;AAClB,EAAA,OAAO,CAACf,YAAY,CAACgB,QAAQ,CAACN,UAAU,CAAC,EAAEV,YAAY,CAACc,GAAG,CAACJ,UAAU,CAAC,CAAC,CAAA;AAC1E;;;;"}