Primitives / foldkit-primitives/dom

PointerPosition

const · packages/primitives/src/dom/pointer-position.ts:119

const PointerPosition: Mount.MountDefinitionWithArgs<
  'PointerPosition',
  { focus: Schema.optionalKey<Schema.String> },
  | {
      readonly _tag: 'PointerPressed'
      readonly point: {
        readonly x: number
        readonly y: number
        readonly pressure: number
      }
      readonly pointerType: string
      readonly width: number
      readonly height: number
    }
  | {
      readonly _tag: 'PointerMoved'
      readonly point: {
        readonly x: number
        readonly y: number
        readonly pressure: number
      }
      readonly points: readonly {
        readonly x: number
        readonly y: number
        readonly pressure: number
      }[]
      readonly width: number
      readonly height: number
    }
  | { readonly _tag: 'PointerReleased'; readonly completed: boolean }
>

Where one pointer is inside an element, as a Mount, for a surface the pointer draws on or points into (a color area, a dial, a signature pad): a primary press, each move until the release, and the release, each with the place in the element's padding box and the box's size. The box is measured at each event, so an element that moved or resized is followed. Coordinates are raw, left to right and top down whatever the direction: what a place means (a share, an angle, a reading direction) is the parent's.

The pointer is captured from press to release, so a drag that leaves the element is still heard, and the moves and the release are listened to only meanwhile. A press keeps the browser's own focus and text selection away, and a second pointer while one is down is ignored.

In the guides