{"version":3,"file":"ClipPathLayout.min.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","super","shouldLayoutClipPath","calcLayoutResult","objects","this","width","height","makeBoundingBoxFromPoints","getObjectBounds","size","Point","absolutePositioned","_target$group","center","sendPointToPlane","getRelativeCenterPoint","undefined","group","calcTransformMatrix","clipPathCenter","transform","calcOwnMatrix","correction","calcBoundingBox","add","subtract","_defineProperty","classRegistry","setClass"],"mappings":"0cAYO,MAAMA,UAAuBC,EAGlCC,mBAAAA,CAAoBC,GAClB,QAASA,EAAQC,OAAOC,UAAYC,MAAMJ,oBAAoBC,EAChE,CAEAI,oBAAAA,GACE,OAAO,CACT,CAEAC,gBAAAA,CACEL,EACAM,GAEA,MAAML,OAAEA,GAAWD,GACbE,SAAEA,GAAaD,EACrB,IAAKC,IAAaK,KAAKR,oBAAoBC,GACzC,OAGF,MAAMQ,MAAEA,EAAKC,OAAEA,GAAWC,EACxBC,EAAgBV,EAAQC,IAEpBU,EAAO,IAAIC,EAAML,EAAOC,GAC9B,GAAIP,EAASY,mBAAoB,CAAA,IAAAC,EAO/B,MAAO,CACLC,OANqBC,EACrBf,EAASgB,8BACTC,EACYJ,QADHA,EACTd,EAAOmB,aAAPL,IAAYA,OAAZA,EAAAA,EAAcM,uBAIdT,OAEJ,CAAO,CAEL,MAAMU,EAAiBpB,EACpBgB,yBACAK,UAAUtB,EAAOuB,iBAAiB,GACrC,GAAIjB,KAAKR,oBAAoBC,GAAU,CAGrC,MAAMgB,OAAEA,EAAS,IAAIH,EAAOY,WAAEA,EAAa,IAAIZ,GAC7CN,KAAKmB,gBAAgBpB,EAASN,IAAY,CAAA,EAC5C,MAAO,CACLgB,OAAQA,EAAOW,IAAIL,GACnBG,WAAYA,EAAWG,SAASN,GAChCV,OAEJ,CACE,MAAO,CACLI,OAAQf,EAAOiB,yBAAyBS,IAAIL,GAC5CV,OAGN,CACF,EACDiB,EA3DYhC,EAAc,OACF,aA4DzBiC,EAAcC,SAASlC"}