{
  "version": 3,
  "sources": ["../../../../src/lib/shapes/shared/flip.ts"],
  "sourcesContent": ["import { MatModel } from '@tldraw/editor'\n\n/**\n * The flip state shared by shapes that model mirroring with `flipX` / `flipY` props (for example\n * the image and geo shapes).\n *\n * @internal\n */\nexport interface ShapeFlipState {\n\t/** Whether the shape is mirrored horizontally. */\n\tflipX: boolean\n\t/** Whether the shape is mirrored vertically. */\n\tflipY: boolean\n}\n\n/**\n * Compute the new `flipX` / `flipY` state after a resize. An axis is toggled whenever its resize\n * scale goes negative, which happens both when using the flip command (scale of exactly `-1`) and\n * when dragging a resize handle (including a group's handle) past the opposite edge. We can't check\n * for an exact scale of `-1` because a group flip resizes its children by an arbitrary negative\n * scale, not just `-1`.\n *\n * @param initial - The flip state of the shape before the resize.\n * @param info - The resize scale factors for each axis.\n * @returns The flip state to apply to the resized shape.\n * @internal\n */\nexport function getFlipForResize(\n\tinitial: ShapeFlipState,\n\tinfo: { scaleX: number; scaleY: number }\n): ShapeFlipState {\n\treturn {\n\t\tflipX: info.scaleX < 0 !== initial.flipX,\n\t\tflipY: info.scaleY < 0 !== initial.flipY,\n\t}\n}\n\n/**\n * Get an affine matrix that mirrors a `width`\u00D7`height` box around its center according to the given\n * flip state. Flipping the geometry with this matrix reproduces the visual result of `scale(-1)`\n * around the center, without needing negative width/height.\n *\n * @param flip - The flip state to apply.\n * @param width - The width of the box to mirror within.\n * @param height - The height of the box to mirror within.\n * @returns An affine matrix mirroring points within the box.\n * @internal\n */\nexport function getFlipMatrix(flip: ShapeFlipState, width: number, height: number): MatModel {\n\treturn {\n\t\ta: flip.flipX ? -1 : 1,\n\t\tb: 0,\n\t\tc: 0,\n\t\td: flip.flipY ? -1 : 1,\n\t\t// mirroring around the center of the box: x' = width - x, y' = height - y\n\t\te: flip.flipX ? width : 0,\n\t\tf: flip.flipY ? height : 0,\n\t}\n}\n"],
  "mappings": "AA2BO,SAAS,iBACf,SACA,MACiB;AACjB,SAAO;AAAA,IACN,OAAO,KAAK,SAAS,MAAM,QAAQ;AAAA,IACnC,OAAO,KAAK,SAAS,MAAM,QAAQ;AAAA,EACpC;AACD;AAaO,SAAS,cAAc,MAAsB,OAAe,QAA0B;AAC5F,SAAO;AAAA,IACN,GAAG,KAAK,QAAQ,KAAK;AAAA,IACrB,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG,KAAK,QAAQ,KAAK;AAAA;AAAA,IAErB,GAAG,KAAK,QAAQ,QAAQ;AAAA,IACxB,GAAG,KAAK,QAAQ,SAAS;AAAA,EAC1B;AACD;",
  "names": []
}
