{
  "version": 3,
  "sources": ["../../../src/lib/overlays/ShapeHandleOverlayUtil.ts"],
  "sourcesContent": ["import {\n\tCircle2d,\n\tGeometry2d,\n\tMat,\n\tOverlayUtil,\n\tSIDES,\n\tTLCursorType,\n\tTLHandle,\n\tTLOverlay,\n\tTLShapeId,\n\tVec,\n} from '@tldraw/editor'\n\n/** @public */\nexport interface TLShapeHandleOverlay extends TLOverlay {\n\tprops: {\n\t\tshapeId: TLShapeId\n\t\thandle: TLHandle\n\t}\n}\n\n/**\n * Overlay util for shape handles (arrow endpoints, line vertices, etc.).\n *\n * @public\n */\nexport class ShapeHandleOverlayUtil extends OverlayUtil<TLShapeHandleOverlay> {\n\tstatic override type = 'shape_handle'\n\toverride options = { zIndex: 200, lineWidth: 1.5 }\n\n\toverride isActive(): boolean {\n\t\tconst editor = this.editor\n\t\tif (editor.getIsReadonly() || editor.getInstanceState().isChangingStyle) return false\n\n\t\tconst onlySelectedShape = editor.getOnlySelectedShape()\n\t\tif (!onlySelectedShape) return false\n\n\t\tconst handles = editor.getShapeHandles(onlySelectedShape)\n\t\tif (!handles) return false\n\n\t\tif (editor.isInAny('select.idle', 'select.pointing_handle', 'select.pointing_shape')) {\n\t\t\treturn true\n\t\t}\n\n\t\tif (editor.isIn('select.editing_shape')) {\n\t\t\treturn editor.isShapeOfType(onlySelectedShape, 'note')\n\t\t}\n\n\t\treturn false\n\t}\n\n\toverride getOverlays(): TLShapeHandleOverlay[] {\n\t\tconst editor = this.editor\n\t\tconst onlySelectedShape = editor.getOnlySelectedShape()\n\t\tif (!onlySelectedShape) return []\n\n\t\tconst handles = editor.getShapeHandles(onlySelectedShape)\n\t\tif (!handles) return []\n\n\t\tif (editor.isShapeHidden(onlySelectedShape)) return []\n\n\t\tconst zoom = editor.getZoomLevel()\n\t\tconst isCoarse = editor.getInstanceState().isCoarsePointer\n\t\tconst minDist =\n\t\t\t((isCoarse ? editor.options.coarseHandleRadius : editor.options.handleRadius) / zoom) * 2\n\n\t\tconst vertexHandles = handles.filter((handle) => handle.type === 'vertex')\n\t\tconst vertexHandlesForHitTest: TLHandle[] = []\n\t\tconst otherHandlesForHitTest: TLHandle[] = []\n\n\t\t// Vertex handles come first so they win hit-testing against overlapping\n\t\t// virtual/create handles (e.g., a line's midpoint create handle that\n\t\t// coincides with its endpoint vertices when a segment is very short).\n\t\t// `render` iterates this array in reverse so the painted order puts\n\t\t// vertex handles on top visually, matching the main branch's paint\n\t\t// order where vertex handles were sorted last.\n\t\tfor (const handle of handles) {\n\t\t\tif (\n\t\t\t\thandle.type === 'virtual' &&\n\t\t\t\tvertexHandles.some((vertexHandle) => Vec.Dist(handle, vertexHandle) < minDist)\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (handle.type === 'vertex') {\n\t\t\t\tvertexHandlesForHitTest.push(handle)\n\t\t\t} else {\n\t\t\t\totherHandlesForHitTest.push(handle)\n\t\t\t}\n\t\t}\n\n\t\treturn vertexHandlesForHitTest.concat(otherHandlesForHitTest).map((handle) => ({\n\t\t\tid: `handle:${onlySelectedShape.id}:${handle.id}`,\n\t\t\ttype: 'shape_handle',\n\t\t\tprops: {\n\t\t\t\tshapeId: onlySelectedShape.id,\n\t\t\t\thandle,\n\t\t\t},\n\t\t}))\n\t}\n\n\toverride getGeometry(overlay: TLShapeHandleOverlay): Geometry2d | null {\n\t\tconst editor = this.editor\n\t\tconst { shapeId, handle } = overlay.props\n\t\tconst transform = editor.getShapePageTransform(shapeId)\n\t\tif (!transform) return null\n\n\t\tconst zoom = editor.getZoomLevel()\n\t\tconst isCoarse = editor.getInstanceState().isCoarsePointer\n\t\tconst radius =\n\t\t\t(isCoarse ? editor.options.coarseHandleRadius : editor.options.handleRadius) / zoom\n\n\t\t// Transform handle position to page space\n\t\tconst pagePoint = Mat.applyToPoint(transform, { x: handle.x, y: handle.y })\n\n\t\treturn new Circle2d({\n\t\t\tx: pagePoint.x - radius,\n\t\t\ty: pagePoint.y - radius,\n\t\t\tradius,\n\t\t\tisFilled: true,\n\t\t})\n\t}\n\n\toverride getCursor(_overlay: TLShapeHandleOverlay): TLCursorType | undefined {\n\t\treturn 'grab' as TLCursorType\n\t}\n\n\toverride render(ctx: CanvasRenderingContext2D, overlays: TLShapeHandleOverlay[]): void {\n\t\tif (overlays.length === 0) return\n\n\t\tconst editor = this.editor\n\t\tconst shapeId = overlays[0].props.shapeId\n\t\tconst transform = editor.getShapePageTransform(shapeId)\n\t\tif (!transform) return\n\n\t\tconst zoom = editor.getZoomLevel()\n\t\tconst isCoarse = editor.getInstanceState().isCoarsePointer\n\t\tconst themeColors = editor.getCurrentTheme().colors[editor.getColorMode()]\n\t\tconst fgColor = themeColors.selectedContrast\n\t\tconst strokeColor = themeColors.selectionStroke\n\t\tconst bgFill = themeColors.selectionFill\n\t\tconst hoveredOverlayId = editor.overlays.getHoveredOverlayId()\n\t\tconst bgRadius =\n\t\t\t(isCoarse ? editor.options.coarseHandleRadius : editor.options.handleRadius) / zoom\n\n\t\tctx.save()\n\t\tctx.transform(transform.a, transform.b, transform.c, transform.d, transform.e, transform.f)\n\n\t\tctx.strokeStyle = strokeColor\n\t\tctx.lineWidth = this.options.lineWidth / zoom\n\n\t\t// Iterate in reverse: vertex handles come first in the array (for hit-\n\t\t// test priority) but should paint last so they visually sit on top of\n\t\t// overlapping virtual/create handles.\n\t\tfor (let i = overlays.length - 1; i >= 0; i--) {\n\t\t\tconst overlay = overlays[i]\n\t\t\tconst { handle } = overlay.props\n\t\t\tconst isHovered = overlay.id === hoveredOverlayId\n\n\t\t\t// 'create' handles are invisible on fine pointers and revealed on\n\t\t\t// hover (matches the old .tl-handle__create opacity rules).\n\t\t\tif (handle.type === 'create' && !isCoarse && !isHovered) continue\n\n\t\t\t// Hover halo \u2014 matches the old .tl-handle__bg:hover fill rule.\n\t\t\tif (isHovered) {\n\t\t\t\tctx.fillStyle = bgFill\n\t\t\t\tctx.beginPath()\n\t\t\t\tctx.arc(handle.x, handle.y, bgRadius, 0, Math.PI * 2)\n\t\t\t\tctx.fill()\n\t\t\t}\n\n\t\t\tif (handle.type === 'clone') {\n\t\t\t\t// Note clone handles render as a side-facing half circle.\n\t\t\t\tconst fr = 3 / zoom\n\t\t\t\tconst sideIndex = SIDES.indexOf(handle.id as (typeof SIDES)[number])\n\t\t\t\tconst rotation = (-Math.PI / 2) * (1 - sideIndex)\n\n\t\t\t\tctx.save()\n\t\t\t\tctx.translate(handle.x, handle.y)\n\t\t\t\tctx.rotate(rotation)\n\t\t\t\tctx.fillStyle = strokeColor\n\t\t\t\tctx.beginPath()\n\t\t\t\tctx.moveTo(0, -fr)\n\t\t\t\tctx.arc(0, 0, fr, -Math.PI / 2, Math.PI / 2)\n\t\t\t\tctx.closePath()\n\t\t\t\tctx.fill()\n\t\t\t\tctx.restore()\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Match the old DefaultHandle sizing: create handles on coarse\n\t\t\t// pointers are slightly smaller (3px) since they're always visible;\n\t\t\t// on fine pointers they render at 4px when revealed by hover so\n\t\t\t// they match the vertex handles. Clamp the zoom divisor at 0.25 so\n\t\t\t// the visible circle stops growing past 25% zoom and visually\n\t\t\t// shrinks as the user zooms further out \u2014 the hit-area halo above\n\t\t\t// still tracks the full zoom so handles remain grabbable.\n\t\t\tconst fr = (handle.type === 'create' && isCoarse ? 3 : 4) / Math.max(zoom, 0.25)\n\n\t\t\tctx.fillStyle = fgColor\n\t\t\tctx.beginPath()\n\t\t\tctx.arc(handle.x, handle.y, fr, 0, Math.PI * 2)\n\t\t\tctx.fill()\n\t\t\tctx.stroke()\n\t\t}\n\n\t\tctx.restore()\n\t}\n}\n"],
  "mappings": "AAAA;AAAA,EACC;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAKA;AAAA,OACM;AAeA,MAAM,+BAA+B,YAAkC;AAAA,EAC7E,OAAgB,OAAO;AAAA,EACd,UAAU,EAAE,QAAQ,KAAK,WAAW,IAAI;AAAA,EAExC,WAAoB;AAC5B,UAAM,SAAS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