{
  "version": 3,
  "sources": ["../../../src/lib/overlays/SnapIndicatorOverlayUtil.ts"],
  "sourcesContent": ["import {\n\tGapsSnapIndicator,\n\tOverlayUtil,\n\tPointsSnapIndicator,\n\tSnapIndicator,\n\tTLOverlay,\n\trangeIntersection,\n} from '@tldraw/editor'\n\n/** @public */\nexport interface TLSnapIndicatorOverlay extends TLOverlay {\n\tprops: {\n\t\tline: SnapIndicator\n\t}\n}\n\n/**\n * Overlay util for snap alignment indicators (point snap lines and gap indicators).\n *\n * @public\n */\nexport class SnapIndicatorOverlayUtil extends OverlayUtil<TLSnapIndicatorOverlay> {\n\tstatic override type = 'snap_indicator'\n\toverride options = { zIndex: 500, lineWidth: 1 }\n\n\toverride isActive(): boolean {\n\t\treturn this.editor.snaps.getIndicators().length > 0\n\t}\n\n\toverride getOverlays(): TLSnapIndicatorOverlay[] {\n\t\treturn this.editor.snaps.getIndicators().map((line) => ({\n\t\t\tid: `snap:${line.id}`,\n\t\t\ttype: 'snap_indicator',\n\t\t\tprops: { line },\n\t\t}))\n\t}\n\n\toverride render(ctx: CanvasRenderingContext2D, overlays: TLSnapIndicatorOverlay[]): void {\n\t\tconst zoom = this.editor.getZoomLevel()\n\t\tconst snapColor = this.editor.getCurrentTheme().colors[this.editor.getColorMode()].snap\n\n\t\tfor (const overlay of overlays) {\n\t\t\tconst { line } = overlay.props\n\t\t\tif (line.type === 'points') {\n\t\t\t\tthis._renderPoints(ctx, line, zoom, snapColor)\n\t\t\t} else if (line.type === 'gaps') {\n\t\t\t\tthis._renderGaps(ctx, line, zoom, snapColor)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _renderPoints(\n\t\tctx: CanvasRenderingContext2D,\n\t\tindicator: PointsSnapIndicator,\n\t\tzoom: number,\n\t\tcolor: string\n\t): void {\n\t\tconst { points } = indicator\n\t\tif (points.length === 0) return\n\n\t\tconst l = 2.5 / zoom\n\n\t\tlet minX = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet minY = Infinity\n\t\tlet maxY = -Infinity\n\t\tfor (const point of points) {\n\t\t\tif (point.x < minX) minX = point.x\n\t\t\tif (point.x > maxX) maxX = point.x\n\t\t\tif (point.y < minY) minY = point.y\n\t\t\tif (point.y > maxY) maxY = point.y\n\t\t}\n\n\t\tlet useNWtoSEdirection = false\n\t\tfor (const point of points) {\n\t\t\tif (point.x === minX && point.y === minY) {\n\t\t\t\tuseNWtoSEdirection = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tlet firstX: number, firstY: number, secondX: number, secondY: number\n\t\tif (useNWtoSEdirection) {\n\t\t\tfirstX = minX\n\t\t\tfirstY = minY\n\t\t\tsecondX = maxX\n\t\t\tsecondY = maxY\n\t\t} else {\n\t\t\tfirstX = minX\n\t\t\tfirstY = maxY\n\t\t\tsecondX = maxX\n\t\t\tsecondY = minY\n\t\t}\n\n\t\tctx.strokeStyle = color\n\t\tctx.lineWidth = this.options.lineWidth / zoom\n\n\t\t// Main snap line\n\t\tctx.beginPath()\n\t\tctx.moveTo(firstX, firstY)\n\t\tctx.lineTo(secondX, secondY)\n\t\tctx.stroke()\n\n\t\t// Batch-draw crosses for all points in a single stroke\n\t\tctx.beginPath()\n\t\tfor (const p of points) {\n\t\t\tctx.moveTo(p.x - l, p.y - l)\n\t\t\tctx.lineTo(p.x + l, p.y + l)\n\t\t\tctx.moveTo(p.x - l, p.y + l)\n\t\t\tctx.lineTo(p.x + l, p.y - l)\n\t\t}\n\t\tctx.stroke()\n\t}\n\n\tprivate _renderGaps(\n\t\tctx: CanvasRenderingContext2D,\n\t\tindicator: GapsSnapIndicator,\n\t\tzoom: number,\n\t\tcolor: string\n\t): void {\n\t\tconst { gaps, direction } = indicator\n\t\tif (gaps.length === 0) return\n\n\t\tconst l = 3.5 / zoom\n\t\tconst tickLength = 2 * l\n\t\tconst horizontal = direction === 'horizontal'\n\n\t\tlet edgeIntersection: number[] = [-Infinity, +Infinity]\n\t\tlet nextEdgeIntersection: number[] | null = null\n\n\t\tfor (const gap of gaps) {\n\t\t\tnextEdgeIntersection = rangeIntersection(\n\t\t\t\tedgeIntersection[0],\n\t\t\t\tedgeIntersection[1],\n\t\t\t\thorizontal ? gap.startEdge[0].y : gap.startEdge[0].x,\n\t\t\t\thorizontal ? gap.startEdge[1].y : gap.startEdge[1].x\n\t\t\t)\n\t\t\tif (nextEdgeIntersection) {\n\t\t\t\tedgeIntersection = nextEdgeIntersection\n\t\t\t} else {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tnextEdgeIntersection = rangeIntersection(\n\t\t\t\tedgeIntersection[0],\n\t\t\t\tedgeIntersection[1],\n\t\t\t\thorizontal ? gap.endEdge[0].y : gap.endEdge[0].x,\n\t\t\t\thorizontal ? gap.endEdge[1].y : gap.endEdge[1].x\n\t\t\t)\n\t\t\tif (nextEdgeIntersection) {\n\t\t\t\tedgeIntersection = nextEdgeIntersection\n\t\t\t} else {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\tconst midPoint = (edgeIntersection[0] + edgeIntersection[1]) / 2\n\n\t\tctx.strokeStyle = color\n\t\tctx.lineWidth = this.options.lineWidth / zoom\n\n\t\t// Batch all gap ticks/lines into a single path, then stroke once\n\t\tctx.beginPath()\n\t\tfor (const { startEdge, endEdge } of gaps) {\n\t\t\tif (horizontal) {\n\t\t\t\t// Start edge tick\n\t\t\t\tctx.moveTo(startEdge[0].x, midPoint - tickLength)\n\t\t\t\tctx.lineTo(startEdge[1].x, midPoint + tickLength)\n\t\t\t\t// End edge tick\n\t\t\t\tctx.moveTo(endEdge[0].x, midPoint - tickLength)\n\t\t\t\tctx.lineTo(endEdge[1].x, midPoint + tickLength)\n\t\t\t\t// Joining line\n\t\t\t\tctx.moveTo(startEdge[0].x, midPoint)\n\t\t\t\tctx.lineTo(endEdge[0].x, midPoint)\n\t\t\t\t// Center tick\n\t\t\t\tconst cx = (startEdge[0].x + endEdge[0].x) / 2\n\t\t\t\tctx.moveTo(cx, midPoint - l)\n\t\t\t\tctx.lineTo(cx, midPoint + l)\n\t\t\t} else {\n\t\t\t\t// Start edge tick\n\t\t\t\tctx.moveTo(midPoint - tickLength, startEdge[0].y)\n\t\t\t\tctx.lineTo(midPoint + tickLength, startEdge[1].y)\n\t\t\t\t// End edge tick\n\t\t\t\tctx.moveTo(midPoint - tickLength, endEdge[0].y)\n\t\t\t\tctx.lineTo(midPoint + tickLength, endEdge[1].y)\n\t\t\t\t// Joining line\n\t\t\t\tctx.moveTo(midPoint, startEdge[0].y)\n\t\t\t\tctx.lineTo(midPoint, endEdge[0].y)\n\t\t\t\t// Center tick\n\t\t\t\tconst cy = (startEdge[0].y + endEdge[0].y) / 2\n\t\t\t\tctx.moveTo(midPoint - l, cy)\n\t\t\t\tctx.lineTo(midPoint + l, cy)\n\t\t\t}\n\t\t}\n\t\tctx.stroke()\n\t}\n}\n"],
  "mappings": "AAAA;AAAA,EAEC;AAAA,EAIA;AAAA,OACM;AAcA,MAAM,iCAAiC,YAAoC;AAAA,EACjF,OAAgB,OAAO;AAAA,EACd,UAAU,EAAE,QAAQ,KAAK,WAAW,EAAE;AAAA,EAEtC,WAAoB;AAC5B,WAAO,KAAK,OAAO,MAAM,cAAc,EAAE,SAAS;AAAA,EACnD;AAAA,EAES,cAAwC;AAChD,WAAO,KAAK,OAAO,MAAM,cAAc,EAAE,IAAI,CAAC,UAAU;AAAA,MACvD,IAAI,QAAQ,KAAK,EAAE;AAAA,MACnB,MAAM;AAAA,MACN,OAAO,EAAE,KAAK;AAAA,IACf,EAAE;AAAA,EACH;AAAA,EAES,OAAO,KAA+B,UAA0C;AACxF,UAAM,OAAO,KAAK,OAAO,aAAa;AACtC,UAAM,YAAY,KAAK,OAAO,gBAAgB,EAAE,OAAO,KAAK,OAAO,aAAa,CAAC,EAAE;AAEnF,eAAW,WAAW,UAAU;AAC/B,YAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,UAAI,KAAK,SAAS,UAAU;AAC3B,aAAK,cAAc,KAAK,MAAM,MAAM,SAAS;AAA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