{"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 } = 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        target.group?.calcTransformMatrix()\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","width","height","makeBoundingBoxFromPoints","getObjectBounds","size","Point","absolutePositioned","_target$group","clipPathCenter","sendPointToPlane","getRelativeCenterPoint","undefined","group","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;AAAEE,MAAAA,QAAAA;AAAS,KAAC,GAAGD,MAAM,CAAA;IAC3B,IAAI,CAACC,QAAQ,IAAI,CAAC,IAAI,CAACH,mBAAmB,CAACC,OAAO,CAAC,EAAE;AACnD,MAAA,OAAA;AACF,KAAA;AACA;IACA,MAAM;MAAEM,KAAK;AAAEC,MAAAA,MAAAA;KAAQ,GAAGC,yBAAyB,CACjDC,eAAe,CAACR,MAAM,EAAEC,QAAwB,CAClD,CAAC,CAAA;IACD,MAAMQ,IAAI,GAAG,IAAIC,KAAK,CAACL,KAAK,EAAEC,MAAM,CAAC,CAAA;IACrC,IAAIL,QAAQ,CAACU,kBAAkB,EAAE;AAAA,MA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