Reintent

@reintent/lib/gesture

A gesture, read as a value of a choice.

A choice says which drag reaches it (about.gesture: the view's path it answers to, and the field of its possibilities' data the drag moves). Where the drag lets go is a point (moved from where the current possibility is, scaled by depth) or a number along an axis; the possibilities within reach of it are the readings:

snap   a possibility is there (within its tolerance): a person's decision (Reduce)
value  none is, and the choice has a possibility whose value is any point of a fixed type
       (`gesture.value`, an open tail): the new coordinate is a value of that type, a person's
       decision too; C changes, the program does not
free   none is, and K has no such possibility: a new variant, which only a new program has
       (an edit of the program, `@reintent/lib/program-edit`, offered and accepted)
noop   nothing to read

While the drag is on, the in-between is the view's own state (preview); only letting go is an event.

Interfaces

Gesture

Defined in: packages/lib/src/gesture.ts

Which drag reaches a choice, and what it moves.

Properties

PropertyTypeDescription
axis?objectA number along the view's x: x0 is 0, x1 is max (default 1).
axis.max?number-
axis.x0number-
axis.x1number-
depth?readonly [number, number, number, number]For a point: the scale at two depths, [y0, s0, y1, s1] (things further back are smaller).
fieldstringThe field of the possibilities' data the drag sets (at, open).
pathstringThe view's path it answers to: this path, or one under it (man, man.hat, man[bedside]).
value?stringThe tag of the possibility whose value is any point (the open tail of a fixed value type): a drop near no possibility is a value of it, decided, not a new variant.

Type Aliases

Dragged

type Dragged = 
  | {
  at: Pt;
  scale?: number;
}
  | {
  value: number;
};

Defined in: packages/lib/src/gesture.ts

Where a drag leaves a choice's field: a point (and its scale, by depth), or a number.


Landing

type Landing = 
  | {
  outcome: "noop";
}
  | {
  outcome: "snap";
  reach: Reach;
}
  | {
  id: Id;
  key: string;
  outcome: "value";
  value: {
     kind: string;
     value: Record<string, unknown>;
  };
}
  | {
  id: Id;
  key: string;
  outcome: "free";
  value: Record<string, unknown>;
};

Defined in: packages/lib/src/gesture.ts

What letting go of a drag means: a possibility within reach (snap, a decision), a value no possibility holds (free, for a reprogramming to add to K), or nothing to read (noop).


Pt

type Pt = readonly [number, number];

Defined in: packages/lib/src/gesture.ts

A point in the view's units.


Reach

type Reach = object;

Defined in: packages/lib/src/gesture.ts

A possibility within (or out of) reach of a drag.

Properties

PropertyTypeDescription
dnumberDistance in units of the tolerance: ≤ 1 is within reach.
idIdThe choice.
keystringThe choice's key (man#stand).
kindstringThe possibility's tag.

Variables

DOCK

const DOCK: 70 = 70;

Defined in: packages/lib/src/gesture.ts

How close (view units) a drop must be to a possibility's point to be it.


SNAP

const SNAP: 0.1 = 0.1;

Defined in: packages/lib/src/gesture.ts

How close a number must be to a possibility's to be it.

Functions

dataOf()

function dataOf(read, dragged): Record<string, unknown> | undefined;

Defined in: packages/lib/src/gesture.ts

The data a dragged value gives a possibility: its field (and the scale a point has there).

Parameters

ParameterType
readChoiceRead
draggedDragged

Returns

Record<string, unknown> | undefined


dragValue()

function dragValue(
   read, 
   from, 
   to
): Dragged | null;

Defined in: packages/lib/src/gesture.ts

Where a drag from from to to leaves a choice's field: on an axis, the number at to; for a point, the current possibility's point moved by the drag, with its scale at that depth. A choice with no gesture: null.

Parameters

ParameterType
readChoiceRead
fromPt
toPt

Returns

Dragged | null


drop()

function drop(
   read, 
   from, 
   to
): Landing;

Defined in: packages/lib/src/gesture.ts

A drag let go: snapped to a possibility within reach, a value of the choice's open possibility (gesture.value), or a free value no possibility of K holds. A snap is a person's decision (intent.decide(landing.reach.id, landing.reach.kind)), and so is a value (intent.decide(landing.id, landing.value)): a new coordinate within a fixed type changes C. A free one is a new variant: the program changes (an edit of the program, offered and accepted).

Parameters

ParameterType
readChoiceRead
fromPt
toPt

Returns

Landing

Example

import { createIntent, entity, host, useChoose } from '@reintent/core';
import { drop } from '@reintent/lib/gesture';
import { vocab } from '@reintent/lib/vocab';

const Place = vocab({
  bedside: { words: ['bedside'], at: [236, 872] },
  window: { words: ['window'], at: [118, 708] },
});
const man = entity('man', {
  stand: Place.decl({ default: 'bedside', gesture: { path: 'man', field: 'at' } }),
});
const Man = man(() => host('man', { stand: useChoose(man.stand) }));
const intent = createIntent({ program: <Man /> });
const [stand] = intent.realize().reads;

// Dragged from his feet most of the way to the window: it is the window, a decision.
const near = drop(stand, [236, 872], [130, 720]);
if (near.outcome === 'snap') intent.decide(near.reach.id, near.reach.kind);
console.log(intent.realize().reads[0].value); // → { kind: 'window', at: [ 118, 708 ] }

// Let go in the middle of the room: no place is there, the point is a new variant of K.
const free = drop(stand, [236, 872], [200, 780]);
console.log(free.outcome === 'free' && free.value); // → { at: [ 200, 780 ] }

gestureFor()

function gestureFor(
   reads, 
   path, 
   focus?
): 
  | {
  gesture: Gesture;
  read: ChoiceRead;
}
  | null;

Defined in: packages/lib/src/gesture.ts

The choice a drag on path reaches: the first read whose gesture answers to it (its path, or one under it), the thing in focus first.

Parameters

ParameterType
readsreadonly ChoiceRead[]
pathstring
focus?string

Returns

| { gesture: Gesture; read: ChoiceRead; } | null

Example

import { createIntent, entity, host, useChoose } from '@reintent/core';
import { gestureFor } from '@reintent/lib/gesture';
import { vocab } from '@reintent/lib/vocab';

const Place = vocab({
  bedside: { words: ['bedside'], at: [236, 872] },
  window: { words: ['window'], at: [118, 708] },
});
// Dragging him (or his hat) moves where he stands.
const man = entity('man', {
  stand: Place.decl({
    default: 'bedside',
    gesture: { path: 'man', field: 'at' },
    view: ['man'],
  }),
});
const Man = man(() => host('man', { stand: useChoose(man.stand) }));

const { reads } = createIntent({ program: <Man /> }).realize();
console.log(gestureFor(reads, 'man.hat')?.read.key); // → 'man#stand'
console.log(gestureFor(reads, 'wardrobe')); // → null

land()

function land(reaches, free): Landing;

Defined in: packages/lib/src/gesture.ts

What letting go means: the nearest possibility within reach, else what free says, else nothing.

Parameters

ParameterType
reachesreadonly Reach[]
free() => Landing | null

Returns

Landing


preview()

function preview<V>(read, dragged): V;

Defined in: packages/lib/src/gesture.ts

What the view shows while a drag is on (the in-between is the view's own state; nothing is written): the current possibility's value with the dragged field in it.

Type Parameters

Type Parameter
V

Parameters

ParameterType
readChoiceRead & object
draggedDragged

Returns

V


reaches()

function reaches(read, dragged): Reach[];

Defined in: packages/lib/src/gesture.ts

How far each possibility of a choice is from where a drag left it, nearest first.

Parameters

ParameterType
readChoiceRead
draggedDragged

Returns

Reach[]


scaleAt()

function scaleAt(depth, y): number | undefined;

Defined in: packages/lib/src/gesture.ts

The scale a point has at depth y, between the gesture's two (a little past either end at most).

Parameters

ParameterType
depthreadonly [number, number, number, number] | undefined
ynumber

Returns

number | undefined

Last updated on

Edit on GitHub