fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 3.64 kB
Source Map (JSON)
{"version":3,"file":"ClipPathLayout.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":";;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,eAAe;CAGjD,oBAAoB,SAAuC;AACzD,SAAO,CAAC,CAAC,QAAQ,OAAO,YAAY,MAAM,oBAAoB,QAAQ;;CAGxE,uBAAuB;AACrB,SAAO;;CAGT,iBACE,SACA,SACkC;EAClC,MAAM,EAAE,WAAW;EACnB,MAAM,EAAE,UAAU,UAAU;AAC5B,MAAI,CAAC,YAAY,CAAC,KAAK,oBAAoB,QAAQ,CACjD;EAGF,MAAM,EAAE,OAAO,WAAW,0BACxB,gBAAgB,QAAQ,SAAyB,CAClD;EACD,MAAM,OAAO,IAAI,MAAM,OAAO,OAAO;AACrC,MAAI,SAAS,mBAOX,QAAO;GACL,QANqB,iBACrB,SAAS,wBAAwB,EACjC,KAAA,GACA,QAAQ,MAAM,qBAAqB,GAAG,KAAA,EACvC;GAGC;GACD;OACI;GAEL,MAAM,iBAAiB,SACpB,wBAAwB,CACxB,UAAU,OAAO,eAAe,EAAE,KAAK;AAC1C,OAAI,KAAK,oBAAoB,QAAQ,EAAE;IAGrC,MAAM,EAAE,SAAS,IAAI,OAAO,EAAE,aAAa,IAAI,OAAO,KACpD,KAAK,gBAAgB,SAAS,QAAQ,IAAI,EAAE;AAC9C,WAAO;KACL,QAAQ,OAAO,IAAI,eAAe;KAClC,YAAY,WAAW,SAAS,eAAe;KAC/C;KACD;SAED,QAAO;IACL,QAAQ,OAAO,wBAAwB,CAAC,IAAI,eAAe;IAC3D;IACD;;;;gCAtDS,QAAO,YAAY;AA4DrC,cAAc,SAAS,eAAe"}