11import type { AgentDeviceRuntime , CommandContext } from '../../../runtime-contract.ts' ;
22import type { GestureIntent , GestureSemanticInput } from '../../../contracts/gesture-plan-types.ts' ;
33import { buildGesturePlan } from '../../../contracts/gesture-plan.ts' ;
4- import type { NormalizedGestureInput } from '../../../contracts/gesture-normalization.ts' ;
5- import { buildSwipePresetGesturePlan } from '../../../contracts/scroll-gesture.ts' ;
64import type { Point , Rect } from '../../../kernel/snapshot.ts' ;
75import { AppError } from '../../../kernel/errors.ts' ;
86import { successText } from '../../../utils/success-text.ts' ;
@@ -16,7 +14,7 @@ import { assertSupportedInteractionSurface, captureInteractionSnapshot } from '.
1614import { resolveVisibleSnapshotViewport } from './viewport.ts' ;
1715
1816export type GestureCommandOptions = CommandContext & {
19- gesture : NormalizedGestureInput ;
17+ gesture : GestureSemanticInput ;
2018} ;
2119
2220export type GestureCommandResult = {
@@ -36,8 +34,7 @@ export const gestureCommand: RuntimeCommand<GestureCommandOptions, GestureComman
3634 }
3735 await assertSupportedInteractionSurface ( runtime , options , options . gesture . intent ) ;
3836 const viewport = await captureGestureViewport ( runtime , options ) ;
39- const gesture = resolvePresetGesture ( options . gesture , viewport ) ;
40- const plan = buildGesturePlan ( gesture , viewport , runtime . backend . platform ) ;
37+ const plan = buildGesturePlan ( options . gesture , viewport , runtime . backend . platform ) ;
4138 const backendResult = await runtime . backend . performGesture (
4239 toBackendContext ( runtime , options ) ,
4340 plan ,
@@ -46,13 +43,13 @@ export const gestureCommand: RuntimeCommand<GestureCommandOptions, GestureComman
4643 const from = centroidAt ( plan . pointers , 0 ) ;
4744 const to = centroidAt ( plan . pointers , - 1 ) ;
4845 return {
49- kind : gesture . intent ,
46+ kind : plan . intent ,
5047 durationMs : plan . durationMs ,
5148 pointerCount : plan . topology === 'single' ? 1 : 2 ,
5249 from,
5350 to,
5451 ...( formattedBackendResult ? { backendResult : formattedBackendResult } : { } ) ,
55- ...successText ( gestureMessage ( gesture ) ) ,
52+ ...successText ( gestureMessage ( options . gesture , from , to ) ) ,
5653 } ;
5754} ;
5855
@@ -68,23 +65,6 @@ async function captureGestureViewport(
6865 return resolveVisibleSnapshotViewport ( capture . snapshot . nodes , 'gesture' ) ;
6966}
7067
71- function resolvePresetGesture ( input : NormalizedGestureInput , viewport : Rect ) : GestureSemanticInput {
72- if ( ! ( 'preset' in input ) ) return input ;
73- const relative = buildSwipePresetGesturePlan ( input . preset , {
74- referenceWidth : viewport . width ,
75- referenceHeight : viewport . height ,
76- } ) ;
77- const from = { x : viewport . x + relative . x1 , y : viewport . y + relative . y1 } ;
78- const to = { x : viewport . x + relative . x2 , y : viewport . y + relative . y2 } ;
79- if ( input . intent === 'fling' ) return { intent : 'fling' , from, to } ;
80- return {
81- intent : 'pan' ,
82- origin : from ,
83- delta : { x : to . x - from . x , y : to . y - from . y } ,
84- durationMs : input . durationMs ,
85- } ;
86- }
87-
8868function centroidAt (
8969 pointers : readonly { samples : readonly { point : Point } [ ] } [ ] ,
9070 index : 0 | - 1 ,
@@ -102,10 +82,13 @@ function centroidAt(
10282 } ;
10383}
10484
105- function gestureMessage ( input : GestureSemanticInput ) : string {
85+ function gestureMessage ( input : GestureSemanticInput , from : Point , to : Point ) : string {
10686 switch ( input . intent ) {
107- case 'pan' :
108- return `Panned (${ input . origin . x } , ${ input . origin . y } ) by (${ input . delta . x } , ${ input . delta . y } )` ;
87+ case 'pan' : {
88+ const origin = 'preset' in input ? from : input . origin ;
89+ const delta = 'preset' in input ? { x : to . x - from . x , y : to . y - from . y } : input . delta ;
90+ return `Panned (${ origin . x } , ${ origin . y } ) by (${ delta . x } , ${ delta . y } )` ;
91+ }
10992 case 'fling' :
11093 return 'direction' in input ? `Flung ${ input . direction } ` : 'Flung' ;
11194 case 'pinch' :
0 commit comments