{
  "version": 3,
  "sources": ["../../../../../../../src/lib/tools/SelectTool/childStates/Crop/children/TranslatingCrop.ts"],
  "sourcesContent": ["import {\n\tShapeWithCrop,\n\tStateNode,\n\tTLKeyboardEventInfo,\n\tTLPointerEventInfo,\n\tbind,\n} from '@tldraw/editor'\nimport { GestureShapeChangeTracker } from '../../../GestureShapeChangeTracker'\nimport { getTranslateCroppedImageChange } from './crop_helpers'\n\ntype Snapshot = ReturnType<TranslatingCrop['createSnapshot']>\n\nexport class TranslatingCrop extends StateNode {\n\tstatic override id = 'translating_crop'\n\n\tinfo = {} as TLPointerEventInfo & {\n\t\ttarget: 'shape'\n\t\tisCreating?: boolean\n\t\tonInteractionEnd?: string\n\t}\n\n\tmarkId = ''\n\n\tprivate snapshot = {} as any as Snapshot\n\n\tprivate changeTracker = new GestureShapeChangeTracker(this.editor)\n\n\toverride onEnter(\n\t\tinfo: TLPointerEventInfo & {\n\t\t\ttarget: 'shape'\n\t\t\tisCreating?: boolean\n\t\t\tonInteractionEnd?: string\n\t\t}\n\t) {\n\t\tthis.info = info\n\t\tthis.snapshot = this.createSnapshot()\n\n\t\tthis.markId = this.editor.markHistoryStoppingPoint('translating_crop')\n\t\tthis.editor.setCursor({ type: 'move', rotation: 0 })\n\n\t\t// Watch for changes made to the cropping shape from outside this interaction.\n\t\tthis.changeTracker.start(this.snapshot.shape ? [this.snapshot.shape.id] : [])\n\n\t\tthis.updateShapes()\n\t}\n\n\toverride onExit() {\n\t\tthis.changeTracker.stop()\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.updateShapes()\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onComplete() {\n\t\tthis.complete()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onKeyDown(info: TLKeyboardEventInfo) {\n\t\tswitch (info.key) {\n\t\t\tcase 'Alt':\n\t\t\tcase 'Shift': {\n\t\t\t\tthis.updateShapes()\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyUp(info: TLKeyboardEventInfo) {\n\t\tswitch (info.key) {\n\t\t\tcase 'Enter': {\n\t\t\t\tthis.complete()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcase 'Alt':\n\t\t\tcase 'Shift': {\n\t\t\t\tthis.updateShapes()\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected complete() {\n\t\tthis.updateShapes()\n\t\tthis.editor.setCurrentTool('select.crop.idle', this.info)\n\t}\n\n\tprivate cancel() {\n\t\tthis.editor.bailToMark(this.markId)\n\t\tthis.changeTracker.clear()\n\t\tthis.editor.setCurrentTool('select.crop.idle', this.info)\n\t}\n\n\tprivate createSnapshot(originPagePoint = this.editor.inputs.getOriginPagePoint()) {\n\t\tconst shape = this.editor.getOnlySelectedShape() as ShapeWithCrop\n\t\t// The page point the gesture is measured from. Normally the drag origin,\n\t\t// but reset to the current pointer when the snapshot is re-anchored after\n\t\t// an external change, so the delta resolves to 0 there and doesn't jump.\n\t\treturn { shape, originPagePoint }\n\t}\n\n\tprotected updateShapes() {\n\t\tthis.changeTracker.ignoreChanges(this.updateShapesIgnoringExternalChanges)\n\t}\n\n\t@bind\n\tprivate updateShapesIgnoringExternalChanges() {\n\t\t// Otherwise the stale crop snapshot would overwrite an external change.\n\t\tif (this.changeTracker.getAndClearChanged()) {\n\t\t\tthis.snapshot = this.createSnapshot(this.editor.inputs.getCurrentPagePoint())\n\t\t\tthis.changeTracker.setTrackedShapeIds(this.snapshot.shape ? [this.snapshot.shape.id] : [])\n\t\t}\n\n\t\tconst shape = this.snapshot.shape as ShapeWithCrop\n\n\t\tif (!shape) return\n\n\t\tconst currentPagePoint = this.editor.inputs.getCurrentPagePoint()\n\t\tconst delta = currentPagePoint.clone().sub(this.snapshot.originPagePoint)\n\t\tconst partial = getTranslateCroppedImageChange(this.editor, shape, delta)\n\n\t\tif (partial) {\n\t\t\tthis.editor.updateShapes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