Primitives / foldkit-primitives/dom

Swipe

const · packages/primitives/src/dom/swipe.ts:86

const Swipe: Mount.MountDefinitionWithArgs<
  'Swipe',
  { measure: Schema.optional<Schema.String> },
  | {
      readonly _tag: 'SwipeStarted'
      readonly pointerId: number
      readonly pointerType: string
      readonly width: number
      readonly height: number
    }
  | {
      readonly _tag: 'Swiped'
      readonly pointerId: number
      readonly deltaX: number
      readonly deltaY: number
    }
  | {
      readonly _tag: 'SwipeEnded'
      readonly pointerId: number
      readonly deltaX: number
      readonly deltaY: number
      readonly velocityX: number
      readonly velocityY: number
      readonly completed: boolean
    }
>

Move with the speed of its release, for a gesture that a flick ends (a sheet dragged to dismiss, a card swiped away): a primary-button pointer down captures the pointer, each move reports the delta from where it started, and up reports the last delta with the velocity over the last SWIPE_WINDOW milliseconds, by the events' own time stamps. Cancel or lost capture ends it incomplete. The start reports the size of what is moved, so a distance can be read as a share of it. What a delta or a speed means is the parent's update. Capture is released with the Mount.