@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 readWhile 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
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
| Property | Type | Description |
|---|---|---|
d | number | Distance in units of the tolerance: ≤ 1 is within reach. |
id | Id | The choice. |
key | string | The choice's key (man#stand). |
kind | string | The 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
| Parameter | Type |
|---|---|
read | ChoiceRead |
dragged | Dragged |
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
| Parameter | Type |
|---|---|
read | ChoiceRead |
from | Pt |
to | Pt |
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
| Parameter | Type |
|---|---|
read | ChoiceRead |
from | Pt |
to | Pt |
Returns
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
| Parameter | Type |
|---|---|
reads | readonly ChoiceRead[] |
path | string |
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')); // → nullland()
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
Returns
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
| Parameter | Type |
|---|---|
read | ChoiceRead & object |
dragged | Dragged |
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
| Parameter | Type |
|---|---|
read | ChoiceRead |
dragged | Dragged |
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
| Parameter | Type |
|---|---|
depth | readonly [number, number, number, number] | undefined |
y | number |
Returns
number | undefined
Last updated on
Edit on GitHub