fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 4.99 kB
Source Map (JSON)
{"version":3,"file":"ClipPathLayout.mjs","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"],"names":["ClipPathLayout","LayoutStrategy","shouldPerformLayout","context","target","clipPath","shouldLayoutClipPath","calcLayoutResult","objects","group","width","height","makeBoundingBoxFromPoints","getObjectBounds","size","Point","absolutePositioned","clipPathCenter","sendPointToPlane","getRelativeCenterPoint","undefined","calcTransformMatrix","center","transform","calcOwnMatrix","correction","calcBoundingBox","add","subtract","_defineProperty","classRegistry","setClass"],"mappings":";;;;;;;;AASA;AACA;AACA;AACO,MAAMA,cAAc,SAASC,cAAc,CAAC;EAGjDC,mBAAmBA,CAACC,OAA4B,EAAW;AACzD,IAAA,OAAO,CAAC,CAACA,OAAO,CAACC,MAAM,CAACC,QAAQ,IAAI,KAAK,CAACH,mBAAmB,CAACC,OAAO,CAAC,CAAA;AACxE,GAAA;AAEAG,EAAAA,oBAAoBA,GAAG;AACrB,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AAEAC,EAAAA,gBAAgBA,CACdJ,OAA4B,EAC5BK,OAAuB,EACW;IAClC,MAAM;AAAEJ,MAAAA,MAAAA;AAAO,KAAC,GAAGD,OAAO,CAAA;IAC1B,MAAM;MAAEE,QAAQ;AAAEI,MAAAA,KAAAA;AAAM,KAAC,GAAGL,MAAM,CAAA;IAClC,IAAI,CAACC,QAAQ,IAAI,CAAC,IAAI,CAACH,mBAAmB,CAACC,OAAO,CAAC,EAAE;AACnD,MAAA,OAAA;AACF,KAAA;AACA;IACA,MAAM;MAAEO,KAAK;AAAEC,MAAAA,MAAAA;KAAQ,GAAGC,yBAAyB,CACjDC,eAAe,CAACT,MAAM,EAAEC,QAAwB,CAClD,CAAC,CAAA;IACD,MAAMS,IAAI,GAAG,IAAIC,KAAK,CAACL,KAAK,EAAEC,MAAM,CAAC,CAAA;IACrC,IAAIN,QA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