From 96e7ba78087dbe90112623ce73f9a8bdadea180a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Tue, 22 Sep 2026 15:26:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=8B=96=E5=8A=A8=E9=98=88?= =?UTF-8?q?=E5=80=BC=E6=8A=BD=E6=88=90=E5=85=AC=E5=85=B1=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 previewDragThreshold.ts,导出 DRAG_THRESHOLD_SCREEN_PX 与屏幕坐标阈值判定 passedDragThresholdScreen - useNodeTransformInteraction 删除本地阈值常量,改为复用该模块,左键拖动/缩放行为不变 验证:npx vitest run useNodeTransformInteraction.test.tsx previewWorkspaceZoom.test.tsx(18 passed) --- .../preview/previewDragThreshold.ts | 21 +++++++++++++++++++ .../preview/useNodeTransformInteraction.ts | 11 ++++------ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 apps/ai-game-creator-shell/src/view/ui-editor/components/preview/previewDragThreshold.ts diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/previewDragThreshold.ts b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/previewDragThreshold.ts new file mode 100644 index 000000000..a38a6f469 --- /dev/null +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/previewDragThreshold.ts @@ -0,0 +1,21 @@ +/** 屏幕像素坐标点。 */ +export type ScreenPoint = { + x: number; + y: number; +}; + +/** + * 指针拖动阈值(屏幕像素)。左键拖动/缩放与右键拖拽平移共用同一判据, + * 保证同一张画布上"多小的移动算点击"只有一个答案。 + */ +export const DRAG_THRESHOLD_SCREEN_PX = 2; + +export function passedDragThresholdScreen( + start: ScreenPoint, + current: ScreenPoint, +): boolean { + return ( + Math.hypot(current.x - start.x, current.y - start.y) >= + DRAG_THRESHOLD_SCREEN_PX + ); +} diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/useNodeTransformInteraction.ts b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/useNodeTransformInteraction.ts index 37ad66c0e..b619f6c01 100644 --- a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/useNodeTransformInteraction.ts +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/useNodeTransformInteraction.ts @@ -21,6 +21,7 @@ import { import type { Node as UiNode } from '../../../../features/ui-editor/types/Node'; import type { UITree } from '../../../../features/ui-editor/types/UITree'; import type { UiEditorCanvasProjection } from '../../useUiEditorPage'; +import { passedDragThresholdScreen } from './previewDragThreshold'; type ViewportScale = { scale: number }; type GestureBase = { @@ -47,17 +48,13 @@ type ActiveGesture = ratioAxis: ResizeAxis | null; }); -const DRAG_THRESHOLD_SCREEN_PX = 2; - function passedDragThreshold( gesture: GestureBase, event: ReactPointerEvent, ) { - return ( - Math.hypot( - event.clientX - gesture.startClientX, - event.clientY - gesture.startClientY, - ) >= DRAG_THRESHOLD_SCREEN_PX + return passedDragThresholdScreen( + { x: gesture.startClientX, y: gesture.startClientY }, + { x: event.clientX, y: event.clientY }, ); }