tldraw
Version:
A tiny little drawing editor.
8 lines (7 loc) • 3.19 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../../../src/lib/tools/ZoomTool/childStates/ZoomBrushing.ts"],
"sourcesContent": ["import { Box, StateNode, TLPointerEventInfo } from '@tldraw/editor'\n\nexport class ZoomBrushing extends StateNode {\n\tstatic override id = 'zoom_brushing'\n\n\tinfo = {} as TLPointerEventInfo & { onInteractionEnd?: string }\n\n\tzoomBrush = new Box()\n\n\toverride onEnter(info: TLPointerEventInfo & { onInteractionEnd: string }) {\n\t\tthis.info = info\n\t\tthis.update()\n\t}\n\n\toverride onExit() {\n\t\tthis.editor.updateInstanceState({ zoomBrush: null })\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.update()\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\tprivate update() {\n\t\tconst originPagePoint = this.editor.inputs.getOriginPagePoint()\n\t\tconst currentPagePoint = this.editor.inputs.getCurrentPagePoint()\n\n\t\tthis.zoomBrush.setTo(Box.FromPoints([originPagePoint, currentPagePoint]))\n\t\tthis.editor.updateInstanceState({ zoomBrush: this.zoomBrush.toJson() })\n\t}\n\n\tprivate cancel() {\n\t\tthis.parent.transition('idle', this.info)\n\t}\n\n\tprivate complete() {\n\t\tconst { zoomBrush } = this\n\t\tconst threshold = 8 / this.editor.getZoomLevel()\n\t\t// If the selected area is small then treat it as a click\n\t\tif (zoomBrush.width < threshold && zoomBrush.height < threshold) {\n\t\t\tconst point = this.editor.inputs.getCurrentScreenPoint()\n\t\t\tif (this.editor.inputs.getAltKey()) {\n\t\t\t\tthis.editor.zoomOut(point, { animation: { duration: 220 } })\n\t\t\t} else {\n\t\t\t\tthis.editor.zoomIn(point, { animation: { duration: 220 } })\n\t\t\t}\n\t\t} else {\n\t\t\tconst targetZoom = this.editor.inputs.getAltKey() ? this.editor.getZoomLevel() / 2 : undefined\n\t\t\tthis.editor.zoomToBoun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