fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 3.68 kB
Source Map (JSON)
{"version":3,"file":"ClipPathLayout.min.mjs","names":[],"sources":["../../../../src/LayoutManager/LayoutStrategies/ClipPathLayout.ts"],"sourcesContent":["import { Point } from '../../Point';\nimport type { FabricObject } from '../../shapes/Object/FabricObject';\nimport { makeBoundingBoxFromPoints } from '../../util/misc/boundingBoxFromPoints';\nimport { sendPointToPlane } from '../../util/misc/planeChange';\nimport type { LayoutStrategyResult, StrictLayoutContext } from '../types';\nimport { LayoutStrategy } from './LayoutStrategy';\nimport { getObjectBounds } from './utils';\nimport { classRegistry } from '../../ClassRegistry';\n\n/**\n * Layout will adjust the bounding box to match the clip path bounding box.\n */\nexport class ClipPathLayout extends LayoutStrategy {\n static readonly type = 'clip-path';\n\n shouldPerformLayout(context: StrictLayoutContext): boolean {\n return !!context.target.clipPath && super.shouldPerformLayout(context);\n }\n\n shouldLayoutClipPath() {\n return false;\n }\n\n calcLayoutResult(\n context: StrictLayoutContext,\n objects: FabricObject[],\n ): LayoutStrategyResult | undefined {\n const { target } = context;\n const { clipPath, group } = target;\n if (!clipPath || !this.shouldPerformLayout(context)) {\n return;\n }\n // TODO: remove stroke calculation from this case\n const { width, height } = makeBoundingBoxFromPoints(\n getObjectBounds(target, clipPath as FabricObject),\n );\n const size = new Point(width, height);\n if (clipPath.absolutePositioned) {\n // we want the center point to exist in group's containing plane\n const clipPathCenter = sendPointToPlane(\n clipPath.getRelativeCenterPoint(),\n undefined,\n group ? group.calcTransformMatrix() : undefined,\n );\n return {\n center: clipPathCenter,\n size,\n };\n } else {\n // we want the center point to exist in group's containing plane, so we send it upwards\n const clipPathCenter = clipPath\n .getRelativeCenterPoint()\n .transform(target.calcOwnMatrix(), true);\n if (this.shouldPerformLayout(context)) {\n // the clip path is positioned relative to the group's center which is affected by the bbox\n // so we first calculate the bbox\n const { center = new Point(), correction = new Point() } =\n this.calcBoundingBox(objects, context) || {};\n return {\n center: center.add(clipPathCenter),\n correction: correction.subtract(clipPathCenter),\n size,\n };\n } else {\n return {\n center: target.getRelativeCenterPoint().add(clipPathCenter),\n size,\n };\n }\n }\n }\n}\n\nclassRegistry.setClass(ClipPathLayout);\n"],"mappings":"seAYA,IAAa,EAAb,cAAoC,CAAA,CAGlC,oBAAoB,EAAA,CAClB,MAAA,CAAA,CAAS,EAAQ,OAAO,UAAY,MAAM,oBAAoB,EAAA,CAGhE,sBAAA,CACE,MAAA,CAAO,EAGT,iBACE,EACA,EAAA,CAEA,GAAA,CAAM,OAAE,GAAW,EAAA,CACb,SAAE,EAAA,MAAU,GAAU,EAC5B,GAAA,CAAK,GAAA,CAAa,KAAK,oBAAoB,EAAA,CACzC,OAGF,GAAA,CAAM,MAAE,EAAA,OAAO,GAAW,EACxB,EAAgB,EAAQ,EAAA,CAAA,CAEpB,EAAO,IAAI,EAAM,EAAO,EAAA,CAC9B,GAAI,EAAS,mBAOX,MAAO,CACL,OANqB,EACrB,EAAS,wBAAA,CAAA,IACT,GACA,EAAQ,EAAM,qBAAA,CAAA,IAAwB,GAAA,CAItC,KAAA,EAAA,CAEG,CAEL,IAAM,EAAiB,EACpB,wBAAA,CACA,UAAU,EAAO,eAAA,CAAA,CAAiB,EAAA,CACrC,GAAI,KAAK,oBAAoB,EAAA,CAAU,CAGrC,GAAA,CAAM,OAAE,EAAS,IAAI,EAAO,WAAE,EAAa,IAAI,GAC7C,KAAK,gBAAgB,EAAS,EAAA,EAAY,EAAA,CAC5C,MAAO,CACL,OAAQ,EAAO,IAAI,EAAA,CACnB,WAAY,EAAW,SAAS,EAAA,CAChC,KAAA,EAAA,CAGF,MAAO,CACL,OAAQ,EAAO,wBAAA,CAAyB,IAAI,EAAA,CAC5C,KAAA,EAAA,IAAA,EAAA,EArDQ,OAAO,YAAA,CA4DzB,EAAc,SAAS,EAAA,CAAA,OAAA,KAAA"}