{
  "version": 3,
  "sources": ["../../../src/lib/overlays/ArrowHintOverlayUtil.ts"],
  "sourcesContent": ["import { OverlayUtil, TLOverlay, TLShape, TLShapeId, createComputedCache } from '@tldraw/editor'\nimport type { Editor } from '@tldraw/editor'\nimport { TLIndicatorPath } from '@tldraw/editor'\nimport { getArrowTargetState } from '../shapes/arrow/arrowTargetState'\nimport { DraggingHandle } from '../tools/SelectTool/childStates/DraggingHandle'\nimport { PointingHandle } from '../tools/SelectTool/childStates/PointingHandle'\n\n/** @public */\nexport interface TLArrowHintOverlay extends TLOverlay {\n\tprops: {\n\t\ttargetId: TLShapeId\n\t\thandles: {\n\t\t\ttop: { x: number; y: number; isEnabled: boolean }\n\t\t\tbottom: { x: number; y: number; isEnabled: boolean }\n\t\t\tleft: { x: number; y: number; isEnabled: boolean }\n\t\t\tright: { x: number; y: number; isEnabled: boolean }\n\t\t}\n\t\tanchorX: number\n\t\tanchorY: number\n\t\tsnap: string\n\t\tisExact: boolean\n\t\tisPrecise: boolean\n\t\tarrowKind: string\n\t\tshowEdgeHints: boolean\n\t}\n}\n\nconst indicatorPathCache = createComputedCache(\n\t'arrowHintIndicatorPath',\n\t(editor: Editor, shape: TLShape) => {\n\t\tconst util = editor.getShapeUtil(shape)\n\t\treturn util.getIndicatorPath(shape)\n\t},\n\t{\n\t\tareRecordsEqual(a, b) {\n\t\t\treturn a.props === b.props\n\t\t},\n\t}\n)\n\n/**\n * Overlay util for arrow target hints (target shape indicator + edge snap circles).\n *\n * @public\n */\nexport class ArrowHintOverlayUtil extends OverlayUtil<TLArrowHintOverlay> {\n\tstatic override type = 'arrow_hint'\n\toverride options = {\n\t\tzIndex: 1000,\n\t\tlineWidth: 1.5,\n\t\tedgeRadius: 8,\n\t\tedgePointRadius: 12,\n\t\thandleRadius: 4,\n\t}\n\n\toverride isActive(): boolean {\n\t\tconst editor = this.editor\n\t\tif (editor.isInAny('arrow.idle', 'arrow.pointing')) return true\n\n\t\tif (editor.isIn('select.pointing_handle')) {\n\t\t\tconst node: PointingHandle = editor.getStateDescendant('select.pointing_handle')!\n\t\t\tif (\n\t\t\t\tnode.info.shape.type === 'arrow' &&\n\t\t\t\t(node.info.handle.id === 'start' || node.info.handle.id === 'end')\n\t\t\t) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\tif (editor.isIn('select.dragging_handle')) {\n\t\t\tconst node: DraggingHandle = editor.getStateDescendant('select.dragging_handle')!\n\t\t\tif (\n\t\t\t\tnode.info.shape.type === 'arrow' &&\n\t\t\t\t(node.info.handle.id === 'start' || node.info.handle.id === 'end')\n\t\t\t) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t}\n\n\toverride getOverlays(): TLArrowHintOverlay[] {\n\t\tconst targetInfo = getArrowTargetState(this.editor)\n\t\tif (!targetInfo) return []\n\n\t\tconst { handlesInPageSpace, snap, anchorInPageSpace, arrowKind, isExact, isPrecise } =\n\t\t\ttargetInfo\n\t\tconst showEdgeHints = !isExact && arrowKind === 'elbow'\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tid: 'arrow_hint',\n\t\t\t\ttype: 'arrow_hint',\n\t\t\t\tprops: {\n\t\t\t\t\ttargetId: targetInfo.target.id,\n\t\t\t\t\thandles: {\n\t\t\t\t\t\ttop: {\n\t\t\t\t\t\t\tx: handlesInPageSpace.top.point.x,\n\t\t\t\t\t\t\ty: handlesInPageSpace.top.point.y,\n\t\t\t\t\t\t\tisEnabled: handlesInPageSpace.top.isEnabled,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbottom: {\n\t\t\t\t\t\t\tx: handlesInPageSpace.bottom.point.x,\n\t\t\t\t\t\t\ty: handlesInPageSpace.bottom.point.y,\n\t\t\t\t\t\t\tisEnabled: handlesInPageSpace.bottom.isEnabled,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tleft: {\n\t\t\t\t\t\t\tx: handlesInPageSpace.left.point.x,\n\t\t\t\t\t\t\ty: handlesInPageSpace.left.point.y,\n\t\t\t\t\t\t\tisEnabled: handlesInPageSpace.left.isEnabled,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tright: {\n\t\t\t\t\t\t\tx: handlesInPageSpace.right.point.x,\n\t\t\t\t\t\t\ty: handlesInPageSpace.right.point.y,\n\t\t\t\t\t\t\tisEnabled: handlesInPageSpace.right.isEnabled,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tanchorX: anchorInPageSpace.x,\n\t\t\t\t\tanchorY: anchorInPageSpace.y,\n\t\t\t\t\tsnap,\n\t\t\t\t\tisExact,\n\t\t\t\t\tisPrecise,\n\t\t\t\t\tarrowKind,\n\t\t\t\t\tshowEdgeHints,\n\t\t\t\t},\n\t\t\t},\n\t\t]\n\t}\n\n\toverride render(ctx: CanvasRenderingContext2D, overlays: TLArrowHintOverlay[]): void {\n\t\tconst overlay = overlays[0]\n\t\tif (!overlay) return\n\n\t\tconst editor = this.editor\n\t\tconst zoom = editor.getZoomLevel()\n\t\tconst colors = editor.getCurrentTheme().colors[editor.getColorMode()]\n\t\tconst { targetId, handles, anchorX, anchorY, snap, showEdgeHints } = overlay.props\n\n\t\t// Draw the target shape indicator\n\t\tconst shape = editor.getShape(targetId)\n\t\tif (shape) {\n\t\t\tconst pageTransform = editor.getShapePageTransform(shape)\n\t\t\tconst indicatorPath = indicatorPathCache.get(editor, targetId)\n\t\t\tif (pageTransform && indicatorPath) {\n\t\t\t\tctx.save()\n\t\t\t\tctx.transform(\n\t\t\t\t\tpageTransform.a,\n\t\t\t\t\tpageTransform.b,\n\t\t\t\t\tpageTransform.c,\n\t\t\t\t\tpageTransform.d,\n\t\t\t\t\tpageTransform.e,\n\t\t\t\t\tpageTransform.f\n\t\t\t\t)\n\t\t\t\tctx.strokeStyle = colors.selectionStroke\n\t\t\t\tctx.lineWidth = this.options.lineWidth / zoom\n\t\t\t\tctx.lineCap = 'round'\n\t\t\t\tctx.lineJoin = 'round'\n\t\t\t\tthis._renderIndicatorPath(ctx, indicatorPath)\n\t\t\t\tctx.restore()\n\t\t\t}\n\t\t}\n\n\t\tif (!showEdgeHints) return\n\n\t\t// Draw the anchor snap circle\n\t\tif (snap === 'edge' || snap === 'edge-point') {\n\t\t\tconst snapRadius =\n\t\t\t\t(snap === 'edge-point' ? this.options.edgePointRadius : this.options.edgeRadius) / zoom\n\t\t\tctx.beginPath()\n\t\t\tctx.arc(anchorX, anchorY, snapRadius, 0, Math.PI * 2)\n\t\t\tctx.fillStyle = colors.selectionFill\n\t\t\tctx.fill()\n\t\t}\n\n\t\t// Draw edge handle circles using a single fill+stroke for all handles\n\t\tconst handleRadius = this.options.handleRadius / zoom\n\t\tctx.fillStyle = colors.selectedContrast\n\t\tctx.strokeStyle = colors.selectionStroke\n\t\tctx.lineWidth = this.options.lineWidth / zoom\n\t\tctx.beginPath()\n\t\tfor (const handle of Object.values(handles)) {\n\t\t\tif (!handle.isEnabled) continue\n\t\t\t// Separate subpath for each circle\n\t\t\tctx.moveTo(handle.x + handleRadius, handle.y)\n\t\t\tctx.arc(handle.x, handle.y, handleRadius, 0, Math.PI * 2)\n\t\t}\n\t\tctx.fill()\n\t\tctx.stroke()\n\t}\n\n\t/** @internal */\n\tprivate _renderIndicatorPath(ctx: CanvasRenderingContext2D, indicatorPath: TLIndicatorPath) {\n\t\tif (indicatorPath instanceof Path2D) {\n\t\t\tctx.stroke(indicatorPath)\n\t\t} else {\n\t\t\tconst { path, clipPath, additionalPaths } = indicatorPath\n\n\t\t\tif (clipPath) {\n\t\t\t\tctx.save()\n\t\t\t\tctx.clip(clipPath, 'evenodd')\n\t\t\t\tctx.stroke(path)\n\t\t\t\tctx.restore()\n\t\t\t} else {\n\t\t\t\tctx.stroke(path)\n\t\t\t}\n\n\t\t\tif (additionalPaths) {\n\t\t\t\tfor (const additionalPath of additionalPaths) {\n\t\t\t\t\tctx.stroke(additionalPath)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],
  "mappings": "AAAA,SAAS,aAA4C,2BAA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