{
  "version": 3,
  "sources": ["../../../../../src/lib/tools/HandTool/childStates/OneFingerZooming.ts"],
  "sourcesContent": ["import { StateNode, TLPointerEventInfo, Vec, clamp, last } from '@tldraw/editor'\n\nexport class OneFingerZooming extends StateNode {\n\tstatic override id = 'one_finger_zooming'\n\n\tprivate anchorScreenPoint = new Vec()\n\tprivate initialCamera = new Vec()\n\tprivate initialZoom = 1\n\tprivate originScreenY = 0\n\n\toverride onEnter(_info: TLPointerEventInfo) {\n\t\tconst camera = this.editor.getCamera()\n\t\tthis.initialCamera = Vec.From(camera)\n\t\tthis.initialZoom = camera.z\n\t\tthis.anchorScreenPoint = this.editor.inputs.getOriginScreenPoint().clone()\n\t\tthis.originScreenY = this.editor.inputs.getCurrentScreenPoint().y\n\t\tthis.editor.setCursor({ type: 'grab', rotation: 0 })\n\t}\n\n\toverride onPointerMove(_info: TLPointerEventInfo) {\n\t\tthis.editor.menus.clearOpenMenus()\n\n\t\tconst currentScreenY = this.editor.inputs.getCurrentScreenPoint().y\n\n\t\t// Dragging up = zoom out, dragging down = zoom in (same as google maps default)\n\t\t// we won't respect the user's zoom direction preference because it only applies\n\t\t// to mouse input\n\t\tconst dy = (this.originScreenY - currentScreenY) * -1\n\n\t\t// ~200px of drag \u2248 2x zoom change.\n\t\tconst zoomFactor = Math.pow(2, dy / 200)\n\t\tconst newZoom = this.clampZoom(this.initialZoom * zoomFactor)\n\n\t\tconst { x: cx, y: cy } = this.initialCamera\n\t\tconst { x: sx, y: sy } = this.anchorScreenPoint\n\t\tthis.editor.setCamera(\n\t\t\tnew Vec(\n\t\t\t\tcx + sx / newZoom - sx / this.initialZoom,\n\t\t\t\tcy + sy / newZoom - sy / this.initialZoom,\n\t\t\t\tnewZoom\n\t\t\t),\n\t\t\t{ immediate: true }\n\t\t)\n\t}\n\n\toverride onPointerUp(_info: TLPointerEventInfo) {\n\t\tthis.complete()\n\t}\n\n\toverride onCancel() {\n\t\tthis.parent.transition('idle')\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate complete() {\n\t\tconst pointerVelocity = this.editor.inputs.getPointerVelocity()\n\t\tconst velocityAtPointerUp = Math.min(pointerVelocity.len(), 2)\n\n\t\tif (velocityAtPointerUp > 0.1) {\n\t\t\t// Use velocity y-sign for momentum direction (positive y = moving down = zoom in)\n\t\t\tthis.editor.slideCamera({\n\t\t\t\tspeed: velocityAtPointerUp,\n\t\t\t\tdirection: { x: 0, y: 0, z: Math.sign(pointerVelocity.y) * 0.01 },\n\t\t\t})\n\t\t}\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate clampZoom(zoom: number): number {\n\t\tconst { zoomSteps } = this.editor.getCameraOptions()\n\t\tconst baseZoom = this.editor.getBaseZoom()\n\t\tconst zoomMin = zoomSteps[0] * baseZoom\n\t\tconst zoomMax = last(zoomSteps)! * baseZoom\n\t\treturn clamp(zoom, zoomMin, zoomMax)\n\t}\n}\n"],
  "mappings": "AAAA,SAAS,WAA+B,KAAK,OAAO,YAAY;AAEzD,MAAM,yBAAyB,UAAU;AAAA,EAC/C,OAAgB,KAAK;AAAA,EAEb,oBAAoB,IAAI,IAAI;AAAA,EAC5B,gBAAgB,IAAI,IAAI;AAAA,EACxB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAEf,QAAQ,OAA2B;AAC3C,UAAM,SAAS,KAAK,OAAO,UAAU;AACrC,SAAK,gBAAgB,IAAI,KAAK,MAAM;AACpC,SAAK,cAAc,OAAO;AAC1B,SAAK,oBAAoB,KAAK,OAAO,OAAO,qBAAqB,EAAE,MAAM;AACzE,SAAK,gBAAgB,KAAK,OAAO,OAAO,sBAAsB,EAAE;AAChE,SAAK,OAAO,UAAU,EAAE,MAAM,QAAQ,UAAU,EAAE,CAAC;AAAA,EACpD;AAAA,EAES,cAAc,OAA2B;AACjD,SAAK,OAAO,MAAM,eAAe;AAEjC,UAAM,iBAAiB,KAAK,OAAO,OAAO,sBAAsB,EAAE;AAKlE,UAAM,MAAM,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