{
  "version": 3,
  "sources": ["../../../../../../src/lib/shapes/arrow/elbow/routes/ElbowArrowWorkingInfo.ts"],
  "sourcesContent": ["import { Box, Vec, VecLike } from '@tldraw/editor'\nimport {\n\tElbowArrowBoxEdges,\n\tElbowArrowEdge,\n\tElbowArrowInfoWithoutRoute,\n\tElbowArrowOptions,\n} from '../definitions'\n\n/**\n * A transform that can be applied when working on elbow arrows. This only models flipping x/y or\n * transposing x/y (for 90 degree rotations).\n */\nexport interface ElbowArrowTransform {\n\treadonly x: 1 | -1\n\treadonly y: 1 | -1\n\treadonly transpose: boolean\n}\n\nfunction flipEdgeCrossInPlace(edge: ElbowArrowEdge | null) {\n\tif (!edge) return\n\tconst tmp = edge.cross.min\n\tedge.cross.min = -edge.cross.max\n\tedge.cross.max = -tmp\n\tedge.crossTarget = -edge.crossTarget\n}\n\nfunction flipEdgeValueInPlace(edge: ElbowArrowEdge | null) {\n\tif (!edge) return\n\tedge.value = -edge.value\n\tedge.expanded = edge.expanded === null ? null : -edge.expanded\n}\n\nexport const ElbowArrowTransform = {\n\tIdentity: { x: 1, y: 1, transpose: false } as const,\n\tRotate90: { x: -1, y: 1, transpose: true } as const,\n\tRotate180: { x: -1, y: -1, transpose: false } as const,\n\tRotate270: { x: 1, y: -1, transpose: true } as const,\n\tFlipX: { x: -1, y: 1, transpose: false } as const,\n\tFlipY: { x: 1, y: -1, transpose: false } as const,\n}\n\nfunction invertElbowArrowTransform(transform: ElbowArrowTransform): ElbowArrowTransform {\n\tif (transform.transpose) {\n\t\treturn {\n\t\t\tx: transform.y,\n\t\t\ty: transform.x,\n\t\t\ttranspose: true,\n\t\t}\n\t}\n\n\treturn transform\n}\n\nexport function transformElbowArrowTransform(a: ElbowArrowTransform, b: ElbowArrowTransform) {\n\t// apply b to a:\n\tconst next = { ...a }\n\n\tif (b.transpose) {\n\t\tswap(next, 'x', 'y')\n\t\tnext.transpose = !next.transpose\n\t}\n\n\tif (b.x === -1) {\n\t\tnext.x = -next.x as 1 | -1\n\t}\n\tif (b.y === -1) {\n\t\tnext.y = -next.y as 1 | -1\n\t}\n\n\treturn next\n}\n\nfunction swap<const A extends string, const B extends string>(\n\tobject: { [key in A | B]: any },\n\ta: A,\n\tb: B\n) {\n\tconst temp = object[a]\n\tobject[a] = object[b]\n\tobject[b] = temp\n}\n\nfunction transformVecInPlace(transform: ElbowArrowTransform, point: VecLike) {\n\tpoint.x = transform.x * point.x\n\tpoint.y = transform.y * point.y\n\n\tif (transform.transpose) {\n\t\tswap(point, 'x', 'y')\n\t}\n}\n\nfunction transformBoxInPlace(transform: ElbowArrowTransform, box: Box) {\n\tif (transform.x === -1) {\n\t\tbox.x = -(box.x + box.width)\n\t}\n\tif (transform.y === -1) {\n\t\tbox.y = -(box.y + box.height)\n\t}\n\tif (transform.transpose) {\n\t\tswap(box, 'x', 'y')\n\t\tswap(box, 'width', 'height')\n\t}\n}\n\nfunction transformEdgesInPlace(transform: ElbowArrowTransform, edges: ElbowArrowBoxEdges) {\n\tif (transform.x === -1) {\n\t\tswap(edges, 'left', 'right')\n\t\tflipEdgeCrossInPlace(edges.top)\n\t\tflipEdgeCrossInPlace(edges.bottom)\n\t\tflipEdgeValueInPlace(edges.left)\n\t\tflipEdgeValueInPlace(edges.right)\n\t}\n\tif (transform.y === -1) {\n\t\tswap(edges, 'top', 'bottom')\n\t\tflipEdgeCrossInPlace(edges.left)\n\t\tflipEdgeCrossInPlace(edges.right)\n\t\tflipEdgeValueInPlace(edges.top)\n\t\tflipEdgeValueInPlace(edges.bottom)\n\t}\n\tif (transform.transpose) {\n\t\tswap(edges, 'left', 'top')\n\t\tswap(edges, 'right', 'bottom')\n\t}\n}\n\nexport function debugElbowArrowTransform(transform: ElbowArrowTransform) {\n\tswitch (\n\t\t`${transform.transpose ? 't' : ''}${transform.x === -1 ? 'x' : ''}${transform.y === -1 ? 'y' : ''}`\n\t) {\n\t\tcase '':\n\t\t\treturn 'Identity'\n\t\tcase 't':\n\t\t\treturn 'Transpose'\n\t\tcase 'x':\n\t\t\treturn 'FlipX'\n\t\tcase 'y':\n\t\t\treturn 'FlipY'\n\t\tcase 'tx':\n\t\t\treturn 'Rotate90'\n\t\tcase 'ty':\n\t\t\treturn 'Rotate270'\n\t\tcase 'xy':\n\t\t\treturn 'Rotate180'\n\t\tcase 'txy':\n\t\t\treturn 'spooky (transpose + flip both)'\n\t\tdefault:\n\t\t\tthrow new Error('Unknown transform')\n\t}\n}\n\nexport interface ElbowArrowWorkingBox {\n\toriginal: Box\n\texpanded: Box\n\tedges: ElbowArrowBoxEdges\n\tisPoint: boolean\n}\n\nexport class ElbowArrowWorkingInfo {\n\toptions: ElbowArrowOptions\n\tA: ElbowArrowWorkingBox\n\tB: ElbowArrowWorkingBox\n\tcommon: {\n\t\toriginal: Box\n\t\texpanded: Box\n\t}\n\tgapX: number\n\tgapY: number\n\tmidX: number | null\n\tmidY: number | null\n\tbias: Vec\n\n\tconstructor(info: ElbowArrowInfoWithoutRoute) {\n\t\tthis.options = info.options\n\t\tthis.A = info.A\n\t\tthis.B = info.B\n\t\tthis.common = info.common\n\t\tthis.midX = info.midX\n\t\tthis.midY = info.midY\n\t\tthis.gapX = info.gapX\n\t\tthis.gapY = info.gapY\n\t\t// prefer down/right when routing arrows\n\t\tthis.bias = new Vec(1, 1)\n\t}\n\n\ttransform: ElbowArrowTransform = ElbowArrowTransform.Identity\n\tinverse: ElbowArrowTransform = ElbowArrowTransform.Identity\n\n\tapply(transform: ElbowArrowTransform) {\n\t\tthis.transform = transformElbowArrowTransform(transform, this.transform)\n\t\tthis.inverse = invertElbowArrowTransform(this.transform)\n\n\t\ttransformBoxInPlace(transform, this.A.original)\n\t\ttransformBoxInPlace(transform, this.B.original)\n\t\ttransformBoxInPlace(transform, this.common.original)\n\n\t\ttransformBoxInPlace(transform, this.A.expanded)\n\t\ttransformBoxInPlace(transform, this.B.expanded)\n\t\ttransformBoxInPlace(transform, this.common.expanded)\n\n\t\ttransformEdgesInPlace(transform, this.A.edges)\n\t\ttransformEdgesInPlace(transform, this.B.edges)\n\n\t\ttransformVecInPlace(transform, this.bias)\n\n\t\tif (transform.x === -1) {\n\t\t\tthis.gapX = -this.gapX\n\t\t\tthis.midX = this.midX === null ? null : -this.midX\n\t\t}\n\t\tif (transform.y === -1) {\n\t\t\tthis.gapY = -this.gapY\n\t\t\tthis.midY = this.midY === null ? null : -this.midY\n\t\t}\n\n\t\tif (transform.transpose) {\n\t\t\tlet temp = this.midX\n\t\t\tthis.midX = this.midY\n\t\t\tthis.midY = temp\n\t\t\ttemp = this.gapX\n\t\t\tthis.gapX = this.gapY\n\t\t\tthis.gapY = temp\n\t\t}\n\t}\n\n\treset() {\n\t\tthis.apply(this.inverse)\n\t}\n\n\tvec(x: number, y: number) {\n\t\tconst point = new Vec(x, y)\n\t\ttransformVecInPlace(this.inverse, point)\n\t\treturn point\n\t}\n}\n"],
  "mappings": "AAAA,SAAc,WAAoB;AAkBlC,SAAS,qBAAqB,MAA6B;AAC1D,MAAI,CAAC,KAAM;AACX,QAAM,MAAM,KAAK,MAAM;AACvB,OAAK,MAAM,MAAM,CAAC,KAAK,MAAM;AAC7B,OAAK,MAAM,MAAM,CAAC;AAClB,OAAK,cAAc,CAAC,KAAK;AAC1B;AAEA,SAAS,qBAAqB,MAA6B;AAC1D,MAAI,CAAC,KAAM;AACX,OAAK,QAAQ,CAAC,KAAK;AACnB,OAAK,WAAW,KAAK,aAAa,OAAO,OAAO,CAAC,KAAK;AACvD;AAEO,MAAM,sBAAsB;AAAA,EAClC,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,WAAW,MAAM;AAAA,EACzC,UAAU,EAAE,GAAG,IAAI,GAAG,GAAG,WAAW,KAAK;AAAA,EACzC,WAAW,EAAE,GAAG,IAAI,GAAG,IAAI,WAAW,MAAM;AAAA,EAC5C,WAAW,EAAE,GAAG,GAAG,GAAG,IAAI,WAAW,KAAK;AAAA,EAC1C,OAAO,EAAE,GAAG,IAAI,GAAG,GAAG,WAAW,MAAM;AAAA,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