@mark1russell7/visuals 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -2
- package/build/graph.d.ts +228 -0
- package/build/graph.d.ts.map +1 -0
- package/build/graph.js +369 -0
- package/build/graph.js.map +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/{motion-BvRKIWAC.js → motion-DViuJNyh.js} +10 -3
- package/build/{motion-BvRKIWAC.js.map → motion-DViuJNyh.js.map} +1 -1
- package/build/three.js +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
3D stages for data. A stage is one canvas of three.js with a camera that a person moves. The content of the stage is your data.
|
|
4
4
|
|
|
5
|
-
The package has
|
|
5
|
+
The package has eight entries and two style sheets:
|
|
6
6
|
|
|
7
7
|
- The entry `.` has the camera maths and the model of a replay. It needs no browser, and it does not need `three`.
|
|
8
8
|
- The entry `/marks` has the marks that a viewer draws, as plain data. It needs no browser, and it does not need `three`.
|
|
@@ -13,6 +13,7 @@ The package has seven entries and two style sheets:
|
|
|
13
13
|
- The file `/scrubber.css` is the style sheet of the scrubber.
|
|
14
14
|
- The entry `/labels` has the labels of a stage: a short text next to a point, as an element of the page. It needs a browser.
|
|
15
15
|
- The file `/labels.css` is the style sheet of the labels.
|
|
16
|
+
- The entry `/graph` has the camera of a flat picture, for example a graph of boxes and edges. It does not need `three`.
|
|
16
17
|
|
|
17
18
|
## Install
|
|
18
19
|
|
|
@@ -20,7 +21,7 @@ The package has seven entries and two style sheets:
|
|
|
20
21
|
npm install @mark1russell7/visuals three
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
A package that uses only the entries `.`, `/marks` and `/
|
|
24
|
+
A package that uses only the entries `.`, `/marks`, `/scrubber` and `/graph` does not install `three`.
|
|
24
25
|
|
|
25
26
|
## A stage
|
|
26
27
|
|
|
@@ -470,6 +471,73 @@ stage?.refresh();
|
|
|
470
471
|
- The pick of a field gives the mark. `fieldValue` reads the value of a cell.
|
|
471
472
|
- The content draws the marks in the space of the stage. `transformMarks` moves the marks of a different space into it.
|
|
472
473
|
|
|
474
|
+
## A flat picture
|
|
475
|
+
|
|
476
|
+
The entry `/graph` is for a flat picture that a person moves and zooms, for example a graph of boxes and edges.
|
|
477
|
+
This version has the maths of its camera, its pointers and its keys. Each function is pure, so a test in Node.js uses it.
|
|
478
|
+
|
|
479
|
+
```ts
|
|
480
|
+
import { fitRect, freeArea, toPicture, viewBetween, zoomView } from "@mark1russell7/visuals/graph";
|
|
481
|
+
|
|
482
|
+
// A panel of the page covers 300 pixels at the right of a picture of 1000 by 600 pixels.
|
|
483
|
+
const area = freeArea({ width: 1000, height: 600 }, { right: 300 }); // => { x: 0, y: 0, w: 700, h: 600 }
|
|
484
|
+
const all = fitRect({ x: 0, y: 0, w: 1304, h: 400 }, area); // => { x: 24, y: 200, k: 0.5 }
|
|
485
|
+
|
|
486
|
+
// A zoom at the middle of the free area: the point of the picture there stays there.
|
|
487
|
+
const near = zoomView(all, { x: 350, y: 300 }, 2); // => { x: -302, y: 100, k: 1 }
|
|
488
|
+
toPicture(near, { x: 350, y: 300 }); // => { x: 652, y: 200 }
|
|
489
|
+
viewBetween(all, near, 0.5).k; // => 0.707: a half of the way is a half of the factor of the zoom
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
A view has the zoom `k` and the screen position of the origin of the picture. A point `p` shows at `p * k + (x, y)`.
|
|
493
|
+
|
|
494
|
+
| Function | What it gives |
|
|
495
|
+
| --- | --- |
|
|
496
|
+
| `toPicture`, `toScreen`, `rectToScreen` | The point of the picture at a screen point, and the screen position of a point or a rectangle. |
|
|
497
|
+
| `viewAt`, `panView`, `zoomView` | The view that shows a point at a screen point, the view after a move, and the view after a zoom at a screen point. |
|
|
498
|
+
| `wheelFactor` | The factor of the zoom for one event of a wheel, also for a pinch on a touch pad. |
|
|
499
|
+
| `pinchView` | The view after the two pointers of a pinch move. Each pointer keeps its point of the picture. |
|
|
500
|
+
| `freeArea` | The part of a picture that the page does not cover. A camera shows a selection there. |
|
|
501
|
+
| `fitRect` | The view that shows a rectangle in an area, as large as the area permits. |
|
|
502
|
+
| `frameRects` | The view for the first rectangle of a list that the area shows at a least zoom or more. |
|
|
503
|
+
| `showsRect` | True when a view shows all of a rectangle in an area. |
|
|
504
|
+
| `revealRects` | The view that shows a selection. It is the view of the camera when the selection is in view, so the camera stays. |
|
|
505
|
+
| `viewBetween`, `pictureMoveAt` | A view on the way between two views, and the view at a time of a move. |
|
|
506
|
+
| `pointerDown`, `pointerMove`, `pointerUp`, `pointerCancel` | The pointers that are down on a picture, the view after a pointer moved, and the answer if a pointer made a click. |
|
|
507
|
+
| `pictureKeyAction` | The action of a key: a move of the camera, or a view by its name. |
|
|
508
|
+
|
|
509
|
+
The pointers of a picture are a value. Each event of a pointer gives the next value:
|
|
510
|
+
|
|
511
|
+
```ts
|
|
512
|
+
import { NO_POINTERS, UNIT_VIEW, pointerDown, pointerMove, pointerUp, toPicture } from "@mark1russell7/visuals/graph";
|
|
513
|
+
|
|
514
|
+
let pointers = NO_POINTERS;
|
|
515
|
+
let view = UNIT_VIEW;
|
|
516
|
+
const at = (event: PointerEvent) => ({ x: event.offsetX, y: event.offsetY });
|
|
517
|
+
|
|
518
|
+
canvas.addEventListener("pointerdown", (event) => {
|
|
519
|
+
pointers = pointerDown(pointers, event.pointerId, at(event));
|
|
520
|
+
});
|
|
521
|
+
canvas.addEventListener("pointermove", (event) => {
|
|
522
|
+
// One pointer moves the picture. Two pointers make a pinch.
|
|
523
|
+
({ pointers, view } = pointerMove(pointers, event.pointerId, at(event), view));
|
|
524
|
+
});
|
|
525
|
+
canvas.addEventListener("pointerup", (event) => {
|
|
526
|
+
const up = pointerUp(pointers, event.pointerId, at(event));
|
|
527
|
+
pointers = up.pointers;
|
|
528
|
+
if (up.click) select(toPicture(view, at(event)));
|
|
529
|
+
});
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
- One pointer moves the picture, and the point of the picture below the pointer stays there. Two pointers make a pinch.
|
|
533
|
+
- A click is one pointer that goes up near its start. A drag and a pinch make no click.
|
|
534
|
+
- A finger moves more than a mouse. Give `TOUCH_CLICK_DISTANCE` to `pointerUp` for an event with the pointer type `touch`.
|
|
535
|
+
- An arrow key moves the camera. The keys `+` and `-` zoom at the middle of the free area, and `Home` shows the home view.
|
|
536
|
+
- A move between two views is a zoom at one screen point. Each point of the picture moves along a straight line, in one direction.
|
|
537
|
+
- The zoom of a move changes by an equal factor for each equal step, so it has one speed in the picture.
|
|
538
|
+
- `frameRects` gets the bounds of groups of boxes, the largest group first. It takes the first group that a person can read.
|
|
539
|
+
- The zoom stays in `ZOOM_LIMITS`. Each function with a zoom takes different limits as a parameter.
|
|
540
|
+
|
|
473
541
|
## The camera maths
|
|
474
542
|
|
|
475
543
|
The entry `.` has pure functions. A page with no WebGL 2 and a test in Node.js use the same functions as the stage.
|
package/build/graph.d.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Point, Rect } from "@mark1russell7/layout-contract";
|
|
2
|
+
/**
|
|
3
|
+
* The camera of a flat picture: a zoom and the position of the origin.
|
|
4
|
+
* A point `p` of the picture shows at the screen point `p * k + (x, y)`. Each screen length is in CSS pixels.
|
|
5
|
+
*/
|
|
6
|
+
interface PictureView {
|
|
7
|
+
/** The screen position of the origin of the picture, from the left edge. */
|
|
8
|
+
readonly x: number;
|
|
9
|
+
/** The screen position of the origin of the picture, from the top edge. */
|
|
10
|
+
readonly y: number;
|
|
11
|
+
/** The zoom: the screen length of one unit of the picture. */
|
|
12
|
+
readonly k: number;
|
|
13
|
+
}
|
|
14
|
+
/** The limits of the zoom of a camera. */
|
|
15
|
+
interface ZoomLimits {
|
|
16
|
+
readonly min: number;
|
|
17
|
+
readonly max: number;
|
|
18
|
+
}
|
|
19
|
+
/** The default limits of the zoom. */
|
|
20
|
+
export declare const ZOOM_LIMITS: ZoomLimits;
|
|
21
|
+
/** The view that shows each point of the picture at its own position. */
|
|
22
|
+
export declare const UNIT_VIEW: PictureView;
|
|
23
|
+
/** This function gives a zoom in its limits. A zoom that is not a number gives the smallest zoom. */
|
|
24
|
+
export declare function clampZoom(k: number, limits?: ZoomLimits): number;
|
|
25
|
+
/** This function gives the point of the picture that shows at a screen point. */
|
|
26
|
+
export declare function toPicture(view: PictureView, screen: Point): Point;
|
|
27
|
+
/** This function gives the screen point that shows a point of the picture. */
|
|
28
|
+
export declare function toScreen(view: PictureView, point: Point): Point;
|
|
29
|
+
/** This function gives the screen rectangle that shows a rectangle of the picture. */
|
|
30
|
+
export declare function rectToScreen(view: PictureView, rect: Rect): Rect;
|
|
31
|
+
/** This function gives the view with the zoom `k` that shows the point `point` of the picture at the screen point `at`. */
|
|
32
|
+
export declare function viewAt(point: Point, at: Point, k: number): PictureView;
|
|
33
|
+
/** This function gives the view after a move of the picture by a screen distance. */
|
|
34
|
+
export declare function panView(view: PictureView, dx: number, dy: number): PictureView;
|
|
35
|
+
/**
|
|
36
|
+
* This function gives the view after a zoom by `factor`. The zoom stays in its limits.
|
|
37
|
+
* The screen point `at` shows the same point of the picture before and after the zoom.
|
|
38
|
+
*/
|
|
39
|
+
export declare function zoomView(view: PictureView, at: Point, factor: number, limits?: ZoomLimits): PictureView;
|
|
40
|
+
/** The positions of the two pointers of a pinch, in CSS pixels. */
|
|
41
|
+
type PointerPair = readonly [Point, Point];
|
|
42
|
+
/**
|
|
43
|
+
* This function gives the view after the two pointers of a pinch move from `before` to `after`.
|
|
44
|
+
*
|
|
45
|
+
* The zoom changes by the ratio of the two distances between the pointers.
|
|
46
|
+
* The point of the picture at the middle of the pointers stays at their middle.
|
|
47
|
+
* Thus each pointer keeps its point of the picture, if the pointers do not turn and the zoom is in its limits.
|
|
48
|
+
*/
|
|
49
|
+
export declare function pinchView(view: PictureView, before: PointerPair, after: PointerPair, limits?: ZoomLimits): PictureView;
|
|
50
|
+
/** The speed of the zoom of a wheel: the change of the natural logarithm of the zoom for one CSS pixel of the wheel. */
|
|
51
|
+
export declare const WHEEL_SPEED = .0015;
|
|
52
|
+
/** The height of one line of a wheel that gives its turn in lines, in CSS pixels. */
|
|
53
|
+
export declare const WHEEL_LINE = 16;
|
|
54
|
+
/** The factor of the speed of the wheel for a pinch on a touch pad. A browser gives such a pinch as a wheel with the key `Control`. */
|
|
55
|
+
export declare const WHEEL_PINCH = 10;
|
|
56
|
+
/**
|
|
57
|
+
* This function gives the factor of the zoom for one event of a wheel. A turn away from the person makes the picture larger.
|
|
58
|
+
*
|
|
59
|
+
* `deltaY` and `deltaMode` are the fields of the event. A mode of 1 has its turn in lines.
|
|
60
|
+
* `pinch` is the field `ctrlKey` of the event: a pinch on a touch pad has small turns, so its speed is higher.
|
|
61
|
+
*/
|
|
62
|
+
export declare function wheelFactor(deltaY: number, deltaMode?: number, pinch?: boolean): number;
|
|
63
|
+
/** The parts of a picture that a page covers, from each edge, in CSS pixels. */
|
|
64
|
+
interface Insets {
|
|
65
|
+
readonly top: number;
|
|
66
|
+
readonly right: number;
|
|
67
|
+
readonly bottom: number;
|
|
68
|
+
readonly left: number;
|
|
69
|
+
}
|
|
70
|
+
/** The smallest width and height of a free area, in CSS pixels. */
|
|
71
|
+
export declare const SMALLEST_AREA = 80;
|
|
72
|
+
/**
|
|
73
|
+
* This function gives the free area of a picture: the screen rectangle that the page does not cover.
|
|
74
|
+
* A camera shows a selection in this area, so a panel of the page does not hide it.
|
|
75
|
+
* The width and the height of the area are `SMALLEST_AREA` at least.
|
|
76
|
+
*/
|
|
77
|
+
export declare function freeArea(size: {
|
|
78
|
+
readonly width: number;
|
|
79
|
+
readonly height: number;
|
|
80
|
+
}, insets?: Partial<Insets>): Rect;
|
|
81
|
+
/** The default distance between a rectangle that a camera shows and each edge of the area, in CSS pixels. */
|
|
82
|
+
export declare const FIT_PADDING = 24;
|
|
83
|
+
/** The options of `fitRect`. */
|
|
84
|
+
interface FitOptions {
|
|
85
|
+
/** The distance between the rectangle and each edge of the area, in CSS pixels. The default is `FIT_PADDING`. */
|
|
86
|
+
readonly padding?: number | undefined;
|
|
87
|
+
/** The largest zoom of the result. The default is the largest zoom of the limits. */
|
|
88
|
+
readonly most?: number | undefined;
|
|
89
|
+
/** The limits of the zoom. The default is `ZOOM_LIMITS`. */
|
|
90
|
+
readonly limits?: ZoomLimits | undefined;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* This function gives the view that shows a rectangle of the picture in an area of the screen, as large as the area permits.
|
|
94
|
+
* The middle of the rectangle is at the middle of the area. A rectangle with no size gets the largest zoom.
|
|
95
|
+
*/
|
|
96
|
+
export declare function fitRect(rect: Rect, area: Rect, options?: FitOptions): PictureView;
|
|
97
|
+
/** The options of `frameRects`. */
|
|
98
|
+
interface FrameOptions extends FitOptions {
|
|
99
|
+
/** The smallest zoom at which a person reads the content of a rectangle. */
|
|
100
|
+
readonly least: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* This function gives the view for the first rectangle of a list that an area of the screen shows at the zoom `least` or more.
|
|
104
|
+
*
|
|
105
|
+
* Give the bounds of the largest group of boxes first, then the bounds of smaller groups.
|
|
106
|
+
* If no rectangle is small enough, the result has the zoom `least` and the middle of the last rectangle at the middle of the area.
|
|
107
|
+
* An empty list gives `undefined`.
|
|
108
|
+
*/
|
|
109
|
+
export declare function frameRects(rects: readonly Rect[], area: Rect, options: FrameOptions): PictureView | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* This function tells if a view shows all of a rectangle of the picture in an area of the screen.
|
|
112
|
+
* `margin` is the smallest distance between the rectangle and each edge of the area, in CSS pixels.
|
|
113
|
+
*/
|
|
114
|
+
export declare function showsRect(view: PictureView, rect: Rect, area: Rect, margin?: number): boolean;
|
|
115
|
+
/** The options of `revealRects`. */
|
|
116
|
+
interface RevealOptions extends FrameOptions {
|
|
117
|
+
/** The smallest distance between a rectangle in view and each edge of the area, in CSS pixels. The default is 0. */
|
|
118
|
+
readonly margin?: number | undefined;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* This function gives the view that shows a selection, and it keeps the view `view` when the selection is in view.
|
|
122
|
+
*
|
|
123
|
+
* The rectangles are the bounds of the groups of the selection, as for `frameRects`, the largest group first.
|
|
124
|
+
* The selection is in view when `view` has the zoom `least` or more, and shows all of the rectangle that `frameRects` selects.
|
|
125
|
+
* The result is then `view` itself, so a camera does not move for a click on a box that a person reads.
|
|
126
|
+
* In each other case, the result is the view of `frameRects`. An empty list gives `view`.
|
|
127
|
+
*/
|
|
128
|
+
export declare function revealRects(view: PictureView, rects: readonly Rect[], area: Rect, options: RevealOptions): PictureView;
|
|
129
|
+
/**
|
|
130
|
+
* This function gives the view at a part of the way between two views. `part` goes from 0 to 1.
|
|
131
|
+
*
|
|
132
|
+
* The zoom changes by an equal factor for each equal step, so a zoom has one speed in the picture.
|
|
133
|
+
* The way is a zoom at one screen point: the point of the picture that the two views show there stays there.
|
|
134
|
+
* Thus each point of the picture moves along a straight line of the screen, in one direction.
|
|
135
|
+
* Two views with one zoom give a straight move at one speed.
|
|
136
|
+
*/
|
|
137
|
+
export declare function viewBetween(from: PictureView, to: PictureView, part: number): PictureView;
|
|
138
|
+
/** A move of the camera of a flat picture from one view to a different view. */
|
|
139
|
+
interface PictureMove {
|
|
140
|
+
readonly from: PictureView;
|
|
141
|
+
readonly to: PictureView;
|
|
142
|
+
/** The time of the start of the move, in milliseconds. */
|
|
143
|
+
readonly start: number;
|
|
144
|
+
/** The time that the move takes, in milliseconds. */
|
|
145
|
+
readonly duration: number;
|
|
146
|
+
}
|
|
147
|
+
/** The view of a camera at one time of a move. */
|
|
148
|
+
interface PictureMoveStep {
|
|
149
|
+
readonly view: PictureView;
|
|
150
|
+
/** This value is true at the end of the move, and after it. */
|
|
151
|
+
readonly done: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* This function gives the view of a camera at the time `now` of a move, in milliseconds.
|
|
155
|
+
* The move has a slow start and a slow end. A move with no duration is at its end immediately.
|
|
156
|
+
*/
|
|
157
|
+
export declare function pictureMoveAt(move: PictureMove, now: number): PictureMoveStep;
|
|
158
|
+
/** What a key does on a flat picture: it moves the camera to a view, or it shows a view by its name. */
|
|
159
|
+
type PictureKeyAction = {
|
|
160
|
+
readonly type: "move";
|
|
161
|
+
readonly to: PictureView;
|
|
162
|
+
} | {
|
|
163
|
+
readonly type: "view";
|
|
164
|
+
readonly view: string;
|
|
165
|
+
};
|
|
166
|
+
/** The keys of a flat picture. */
|
|
167
|
+
interface PictureKeyOptions {
|
|
168
|
+
/** The name of the view of the keys `Home` and `0`. */
|
|
169
|
+
readonly home: string;
|
|
170
|
+
/** The name of the view of each other key, for example `{ f: "focus" }`. A letter has no case. */
|
|
171
|
+
readonly views?: Readonly<Record<string, string>> | undefined;
|
|
172
|
+
/** The limits of the zoom. The default is `ZOOM_LIMITS`. */
|
|
173
|
+
readonly limits?: ZoomLimits | undefined;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* This function gives the action of a key on a flat picture, or `undefined` for a key with no action.
|
|
177
|
+
*
|
|
178
|
+
* `area` is the part of the screen that shows the picture. `freeArea` gives it.
|
|
179
|
+
* An arrow key moves the camera by the part `KEY_PART` of the smaller side of the area.
|
|
180
|
+
* The keys `+` and `-` zoom at the middle of the area, by the factor of one step of a key on a 3D stage.
|
|
181
|
+
* The keys `Home` and `0` show the home view.
|
|
182
|
+
*/
|
|
183
|
+
export declare function pictureKeyAction(key: string, now: PictureView, area: Rect, options: PictureKeyOptions): PictureKeyAction | undefined;
|
|
184
|
+
/** The pointers that are down on a picture: a mouse button, a pen or each finger of a hand. */
|
|
185
|
+
interface Pointers {
|
|
186
|
+
/** The screen position of each pointer that is down, by the id of the pointer. */
|
|
187
|
+
readonly at: ReadonlyMap<number, Point>;
|
|
188
|
+
/** The position where the first pointer went down. */
|
|
189
|
+
readonly start: Point | undefined;
|
|
190
|
+
/** This value is true after a second pointer went down. The pointers then make no click. */
|
|
191
|
+
readonly many: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** The pointers of a picture that no pointer is down on. */
|
|
194
|
+
export declare const NO_POINTERS: Pointers;
|
|
195
|
+
/** A finger moves more than a mouse between down and up. This is the distance of a click for a finger, in CSS pixels. */
|
|
196
|
+
export declare const TOUCH_CLICK_DISTANCE = 10;
|
|
197
|
+
/** This function gives the pointers after a pointer went down. The first pointer starts a possible click. */
|
|
198
|
+
export declare function pointerDown(pointers: Pointers, id: number, at: Point): Pointers;
|
|
199
|
+
/** The result of `pointerMove`: the pointers and the view after the move. */
|
|
200
|
+
interface PointerMoveResult {
|
|
201
|
+
readonly pointers: Pointers;
|
|
202
|
+
readonly view: PictureView;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* This function gives the pointers and the view after a pointer moved.
|
|
206
|
+
*
|
|
207
|
+
* One pointer moves the picture, so the point of the picture below the pointer stays there.
|
|
208
|
+
* Two pointers make a pinch: `pinchView` gives the view. Three pointers or more do not change the view.
|
|
209
|
+
* A pointer that is not down changes nothing.
|
|
210
|
+
*/
|
|
211
|
+
export declare function pointerMove(pointers: Pointers, id: number, at: Point, view: PictureView, limits?: ZoomLimits): PointerMoveResult;
|
|
212
|
+
/** The result of `pointerUp`: the pointers that stay down, and the answer if the pointer made a click. */
|
|
213
|
+
interface PointerUpResult {
|
|
214
|
+
readonly pointers: Pointers;
|
|
215
|
+
/** This value is true when one pointer went down and up at almost the same position. */
|
|
216
|
+
readonly click: boolean;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* This function gives the pointers after a pointer went up, and tells if the pointer made a click.
|
|
220
|
+
*
|
|
221
|
+
* A click is one pointer that went up not more than `limit` from its start, with no second pointer between.
|
|
222
|
+
* The default of `limit` is `CLICK_DISTANCE`. Use `TOUCH_CLICK_DISTANCE` for a finger.
|
|
223
|
+
*/
|
|
224
|
+
export declare function pointerUp(pointers: Pointers, id: number, at: Point, limit?: number): PointerUpResult;
|
|
225
|
+
/** This function gives the pointers after the browser stopped a pointer, for example for a gesture of the system. It makes no click. */
|
|
226
|
+
export declare function pointerCancel(pointers: Pointers, id: number): Pointers;
|
|
227
|
+
export type { FitOptions, FrameOptions, Insets, PictureKeyAction, PictureKeyOptions, PictureMove, PictureMoveStep, PictureView, PointerMoveResult, PointerPair, PointerUpResult, Pointers, RevealOptions, ZoomLimits };
|
|
228
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","names":[],"sources":["../src/graph/camera.ts","../src/graph/keys.ts","../src/graph/pointers.ts"],"mappings":";;;;;UAOiB;;WAEN;;WAEA;;WAEA;;;UAIM;WACN;WACA;;;qBAIE,aAAa;;qBAGb,WAAW;;wBAGR,UAAU,WAAW,SAAQ;;wBAK7B,UAAU,MAAM,aAAa,QAAQ,QAAQ;;wBAK7C,SAAS,MAAM,aAAa,OAAO,QAAQ;;wBAK3C,aAAa,MAAM,aAAa,MAAM,OAAO;;wBAK7C,OAAO,OAAO,OAAO,IAAI,OAAO,YAAY;;wBAK5C,QAAQ,MAAM,aAAa,YAAY,aAAa;;;;;wBAQpD,SAAS,MAAM,aAAa,IAAI,OAAO,gBAAgB,SAAQ,aAA2B;;KAO9F,wBAAwB,OAAO;;;;;;;;wBAS3B,UAAU,MAAM,aAAa,QAAQ,aAAa,OAAO,aAAa,SAAQ,aAA2B;;qBAW5G;;qBAGA;;qBAGA;;;;;;;wBAQG,YAAY,gBAAgB,oBAAuB;;UAMlD;WACN;WACA;WACA;WACA;;;qBAIE;;;;;;wBAOG,SAAS;WAAiB;WAAwB;GAAkB,SAAQ,QAAQ,UAAe;;qBAYtG;;UAGI;;WAEN;;WAEA;;WAEA,SAAS;;;;;;wBAYJ,QAAQ,MAAM,MAAM,MAAM,MAAM,UAAS,aAAkB;;UAU1D,qBAAqB;;WAE3B;;;;;;;;;wBAUK,WAAW,gBAAgB,QAAQ,MAAM,MAAM,SAAS,eAAe;;;;;wBAcvE,UAAU,MAAM,aAAa,MAAM,MAAM,MAAM,MAAM;;UAMpD,sBAAsB;;WAE5B;;;;;;;;;;wBAWK,YAAY,MAAM,aAAa,gBAAgB,QAAQ,MAAM,MAAM,SAAS,gBAAgB;;;;;;;;;wBAiB5F,YAAY,MAAM,aAAa,IAAI,aAAa,eAAe;;UAW9D;WACN,MAAM;WACN,IAAI;;WAEJ;;WAEA;;;UAIM;WACN,MAAM;;WAEN;;;;;;wBAOK,cAAc,MAAM,aAAa,cAAc;;KC/PnD;WAA8B;WAAuB,IAAI;;WAA2B;WAAuB;;;UAGtG;;WAEN;;WAEA,QAAQ,SAAS;;WAEjB,SAAS;;;;;;;;;;wBAWJ,iBAAiB,aAAa,KAAK,aAAa,MAAM,MAAM,SAAS,oBAAoB;;UCpBxF;;WAEN,IAAI,oBAAoB;;WAExB,OAAO;;WAEP;;;qBAIE,aAAa;;qBAGb;;wBAGG,YAAY,UAAU,UAAU,YAAY,IAAI,QAAQ;;UAQvD;WACN,UAAU;WACV,MAAM;;;;;;;;;wBAUD,YAAY,UAAU,UAAU,YAAY,IAAI,OAAO,MAAM,aAAa,SAAQ,aAA2B;;UAa5G;WACN,UAAU;;WAEV;;;;;;;;wBASK,UAAU,UAAU,UAAU,YAAY,IAAI,OAAO,iBAAiC;;wBAStF,cAAc,UAAU,UAAU,aAAa"}
|
package/build/graph.js
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { c as isClick, d as KEY_ZOOM, i as partAt, l as KEY_PART, n as easeInOut } from "./motion-DViuJNyh.js";
|
|
2
|
+
// src/graph/camera.ts
|
|
3
|
+
/** The default limits of the zoom. */
|
|
4
|
+
const ZOOM_LIMITS = {
|
|
5
|
+
min: .05,
|
|
6
|
+
max: 8
|
|
7
|
+
};
|
|
8
|
+
/** The view that shows each point of the picture at its own position. */
|
|
9
|
+
const UNIT_VIEW = {
|
|
10
|
+
x: 0,
|
|
11
|
+
y: 0,
|
|
12
|
+
k: 1
|
|
13
|
+
};
|
|
14
|
+
/** This function gives a zoom in its limits. A zoom that is not a number gives the smallest zoom. */
|
|
15
|
+
function clampZoom(k, limits = ZOOM_LIMITS) {
|
|
16
|
+
return k >= limits.min ? Math.min(k, limits.max) : limits.min;
|
|
17
|
+
}
|
|
18
|
+
/** This function gives the point of the picture that shows at a screen point. */
|
|
19
|
+
function toPicture(view, screen) {
|
|
20
|
+
return {
|
|
21
|
+
x: (screen.x - view.x) / view.k,
|
|
22
|
+
y: (screen.y - view.y) / view.k
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** This function gives the screen point that shows a point of the picture. */
|
|
26
|
+
function toScreen(view, point) {
|
|
27
|
+
return {
|
|
28
|
+
x: point.x * view.k + view.x,
|
|
29
|
+
y: point.y * view.k + view.y
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** This function gives the screen rectangle that shows a rectangle of the picture. */
|
|
33
|
+
function rectToScreen(view, rect) {
|
|
34
|
+
return {
|
|
35
|
+
x: rect.x * view.k + view.x,
|
|
36
|
+
y: rect.y * view.k + view.y,
|
|
37
|
+
w: rect.w * view.k,
|
|
38
|
+
h: rect.h * view.k
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** This function gives the view with the zoom `k` that shows the point `point` of the picture at the screen point `at`. */
|
|
42
|
+
function viewAt(point, at, k) {
|
|
43
|
+
return {
|
|
44
|
+
x: at.x - point.x * k,
|
|
45
|
+
y: at.y - point.y * k,
|
|
46
|
+
k
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** This function gives the view after a move of the picture by a screen distance. */
|
|
50
|
+
function panView(view, dx, dy) {
|
|
51
|
+
return {
|
|
52
|
+
x: view.x + dx,
|
|
53
|
+
y: view.y + dy,
|
|
54
|
+
k: view.k
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* This function gives the view after a zoom by `factor`. The zoom stays in its limits.
|
|
59
|
+
* The screen point `at` shows the same point of the picture before and after the zoom.
|
|
60
|
+
*/
|
|
61
|
+
function zoomView(view, at, factor, limits = ZOOM_LIMITS) {
|
|
62
|
+
const k = clampZoom(view.k * factor, limits);
|
|
63
|
+
const ratio = k / view.k;
|
|
64
|
+
return {
|
|
65
|
+
x: at.x - (at.x - view.x) * ratio,
|
|
66
|
+
y: at.y - (at.y - view.y) * ratio,
|
|
67
|
+
k
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* This function gives the view after the two pointers of a pinch move from `before` to `after`.
|
|
72
|
+
*
|
|
73
|
+
* The zoom changes by the ratio of the two distances between the pointers.
|
|
74
|
+
* The point of the picture at the middle of the pointers stays at their middle.
|
|
75
|
+
* Thus each pointer keeps its point of the picture, if the pointers do not turn and the zoom is in its limits.
|
|
76
|
+
*/
|
|
77
|
+
function pinchView(view, before, after, limits = ZOOM_LIMITS) {
|
|
78
|
+
const from = {
|
|
79
|
+
x: (before[0].x + before[1].x) / 2,
|
|
80
|
+
y: (before[0].y + before[1].y) / 2
|
|
81
|
+
};
|
|
82
|
+
const to = {
|
|
83
|
+
x: (after[0].x + after[1].x) / 2,
|
|
84
|
+
y: (after[0].y + after[1].y) / 2
|
|
85
|
+
};
|
|
86
|
+
const was = Math.hypot(before[0].x - before[1].x, before[0].y - before[1].y);
|
|
87
|
+
const is = Math.hypot(after[0].x - after[1].x, after[0].y - after[1].y);
|
|
88
|
+
const factor = was > 0 && is > 0 ? is / was : 1;
|
|
89
|
+
return zoomView(panView(view, to.x - from.x, to.y - from.y), to, factor, limits);
|
|
90
|
+
}
|
|
91
|
+
/** The speed of the zoom of a wheel: the change of the natural logarithm of the zoom for one CSS pixel of the wheel. */
|
|
92
|
+
const WHEEL_SPEED = .0015;
|
|
93
|
+
/** The height of one line of a wheel that gives its turn in lines, in CSS pixels. */
|
|
94
|
+
const WHEEL_LINE = 16;
|
|
95
|
+
/** The factor of the speed of the wheel for a pinch on a touch pad. A browser gives such a pinch as a wheel with the key `Control`. */
|
|
96
|
+
const WHEEL_PINCH = 10;
|
|
97
|
+
/**
|
|
98
|
+
* This function gives the factor of the zoom for one event of a wheel. A turn away from the person makes the picture larger.
|
|
99
|
+
*
|
|
100
|
+
* `deltaY` and `deltaMode` are the fields of the event. A mode of 1 has its turn in lines.
|
|
101
|
+
* `pinch` is the field `ctrlKey` of the event: a pinch on a touch pad has small turns, so its speed is higher.
|
|
102
|
+
*/
|
|
103
|
+
function wheelFactor(deltaY, deltaMode = 0, pinch = false) {
|
|
104
|
+
const pixels = deltaMode === 1 ? deltaY * 16 : deltaY;
|
|
105
|
+
return Math.exp(0 - pixels * WHEEL_SPEED * (pinch ? 10 : 1));
|
|
106
|
+
}
|
|
107
|
+
/** The smallest width and height of a free area, in CSS pixels. */
|
|
108
|
+
const SMALLEST_AREA = 80;
|
|
109
|
+
/**
|
|
110
|
+
* This function gives the free area of a picture: the screen rectangle that the page does not cover.
|
|
111
|
+
* A camera shows a selection in this area, so a panel of the page does not hide it.
|
|
112
|
+
* The width and the height of the area are `SMALLEST_AREA` at least.
|
|
113
|
+
*/
|
|
114
|
+
function freeArea(size, insets = {}) {
|
|
115
|
+
const left = insets.left ?? 0;
|
|
116
|
+
const top = insets.top ?? 0;
|
|
117
|
+
return {
|
|
118
|
+
x: left,
|
|
119
|
+
y: top,
|
|
120
|
+
w: Math.max(80, size.width - left - (insets.right ?? 0)),
|
|
121
|
+
h: Math.max(80, size.height - top - (insets.bottom ?? 0))
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** The default distance between a rectangle that a camera shows and each edge of the area, in CSS pixels. */
|
|
125
|
+
const FIT_PADDING = 24;
|
|
126
|
+
/** This function gives the middle of a rectangle. */
|
|
127
|
+
function middleOf(rect) {
|
|
128
|
+
return {
|
|
129
|
+
x: rect.x + rect.w / 2,
|
|
130
|
+
y: rect.y + rect.h / 2
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* This function gives the view that shows a rectangle of the picture in an area of the screen, as large as the area permits.
|
|
135
|
+
* The middle of the rectangle is at the middle of the area. A rectangle with no size gets the largest zoom.
|
|
136
|
+
*/
|
|
137
|
+
function fitRect(rect, area, options = {}) {
|
|
138
|
+
const limits = options.limits ?? ZOOM_LIMITS;
|
|
139
|
+
const padding = options.padding ?? 24;
|
|
140
|
+
const width = Math.max(area.w - 2 * padding, 1);
|
|
141
|
+
const height = Math.max(area.h - 2 * padding, 1);
|
|
142
|
+
const k = clampZoom(Math.min(options.most ?? limits.max, width / Math.max(rect.w, 0), height / Math.max(rect.h, 0)), limits);
|
|
143
|
+
return viewAt(middleOf(rect), middleOf(area), k);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* This function gives the view for the first rectangle of a list that an area of the screen shows at the zoom `least` or more.
|
|
147
|
+
*
|
|
148
|
+
* Give the bounds of the largest group of boxes first, then the bounds of smaller groups.
|
|
149
|
+
* If no rectangle is small enough, the result has the zoom `least` and the middle of the last rectangle at the middle of the area.
|
|
150
|
+
* An empty list gives `undefined`.
|
|
151
|
+
*/
|
|
152
|
+
function frameRects(rects, area, options) {
|
|
153
|
+
for (const rect of rects) {
|
|
154
|
+
const view = fitRect(rect, area, options);
|
|
155
|
+
if (view.k >= options.least) return view;
|
|
156
|
+
}
|
|
157
|
+
const last = rects.at(-1);
|
|
158
|
+
if (last === void 0) return void 0;
|
|
159
|
+
return viewAt(middleOf(last), middleOf(area), clampZoom(options.least, options.limits));
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* This function tells if a view shows all of a rectangle of the picture in an area of the screen.
|
|
163
|
+
* `margin` is the smallest distance between the rectangle and each edge of the area, in CSS pixels.
|
|
164
|
+
*/
|
|
165
|
+
function showsRect(view, rect, area, margin = 0) {
|
|
166
|
+
const shown = rectToScreen(view, rect);
|
|
167
|
+
return shown.x >= area.x + margin && shown.y >= area.y + margin && shown.x + shown.w <= area.x + area.w - margin && shown.y + shown.h <= area.y + area.h - margin;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* This function gives the view that shows a selection, and it keeps the view `view` when the selection is in view.
|
|
171
|
+
*
|
|
172
|
+
* The rectangles are the bounds of the groups of the selection, as for `frameRects`, the largest group first.
|
|
173
|
+
* The selection is in view when `view` has the zoom `least` or more, and shows all of the rectangle that `frameRects` selects.
|
|
174
|
+
* The result is then `view` itself, so a camera does not move for a click on a box that a person reads.
|
|
175
|
+
* In each other case, the result is the view of `frameRects`. An empty list gives `view`.
|
|
176
|
+
*/
|
|
177
|
+
function revealRects(view, rects, area, options) {
|
|
178
|
+
for (const rect of rects) {
|
|
179
|
+
const framed = fitRect(rect, area, options);
|
|
180
|
+
if (framed.k < options.least) continue;
|
|
181
|
+
return view.k >= options.least && showsRect(view, rect, area, options.margin ?? 0) ? view : framed;
|
|
182
|
+
}
|
|
183
|
+
return frameRects(rects.slice(-1), area, options) ?? view;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* This function gives the view at a part of the way between two views. `part` goes from 0 to 1.
|
|
187
|
+
*
|
|
188
|
+
* The zoom changes by an equal factor for each equal step, so a zoom has one speed in the picture.
|
|
189
|
+
* The way is a zoom at one screen point: the point of the picture that the two views show there stays there.
|
|
190
|
+
* Thus each point of the picture moves along a straight line of the screen, in one direction.
|
|
191
|
+
* Two views with one zoom give a straight move at one speed.
|
|
192
|
+
*/
|
|
193
|
+
function viewBetween(from, to, part) {
|
|
194
|
+
if (!(part > 0)) return from;
|
|
195
|
+
if (part >= 1) return to;
|
|
196
|
+
const log = Math.log(to.k / from.k);
|
|
197
|
+
if (!Number.isFinite(log)) return to;
|
|
198
|
+
const share = log === 0 ? part : Math.expm1(log * part) / Math.expm1(log);
|
|
199
|
+
return {
|
|
200
|
+
x: from.x + (to.x - from.x) * share,
|
|
201
|
+
y: from.y + (to.y - from.y) * share,
|
|
202
|
+
k: from.k * Math.exp(log * part)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* This function gives the view of a camera at the time `now` of a move, in milliseconds.
|
|
207
|
+
* The move has a slow start and a slow end. A move with no duration is at its end immediately.
|
|
208
|
+
*/
|
|
209
|
+
function pictureMoveAt(move, now) {
|
|
210
|
+
const part = partAt(move.start, move.duration, now);
|
|
211
|
+
if (part >= 1) return {
|
|
212
|
+
view: move.to,
|
|
213
|
+
done: true
|
|
214
|
+
};
|
|
215
|
+
return {
|
|
216
|
+
view: viewBetween(move.from, move.to, easeInOut(part)),
|
|
217
|
+
done: false
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// src/graph/keys.ts
|
|
221
|
+
/**
|
|
222
|
+
* This function gives the action of a key on a flat picture, or `undefined` for a key with no action.
|
|
223
|
+
*
|
|
224
|
+
* `area` is the part of the screen that shows the picture. `freeArea` gives it.
|
|
225
|
+
* An arrow key moves the camera by the part `KEY_PART` of the smaller side of the area.
|
|
226
|
+
* The keys `+` and `-` zoom at the middle of the area, by the factor of one step of a key on a 3D stage.
|
|
227
|
+
* The keys `Home` and `0` show the home view.
|
|
228
|
+
*/
|
|
229
|
+
function pictureKeyAction(key, now, area, options) {
|
|
230
|
+
const step = Math.min(area.w, area.h) * KEY_PART;
|
|
231
|
+
const middle = {
|
|
232
|
+
x: area.x + area.w / 2,
|
|
233
|
+
y: area.y + area.h / 2
|
|
234
|
+
};
|
|
235
|
+
switch (key) {
|
|
236
|
+
case "ArrowLeft": return {
|
|
237
|
+
type: "move",
|
|
238
|
+
to: panView(now, step, 0)
|
|
239
|
+
};
|
|
240
|
+
case "ArrowRight": return {
|
|
241
|
+
type: "move",
|
|
242
|
+
to: panView(now, 0 - step, 0)
|
|
243
|
+
};
|
|
244
|
+
case "ArrowUp": return {
|
|
245
|
+
type: "move",
|
|
246
|
+
to: panView(now, 0, step)
|
|
247
|
+
};
|
|
248
|
+
case "ArrowDown": return {
|
|
249
|
+
type: "move",
|
|
250
|
+
to: panView(now, 0, 0 - step)
|
|
251
|
+
};
|
|
252
|
+
case "+":
|
|
253
|
+
case "=": return {
|
|
254
|
+
type: "move",
|
|
255
|
+
to: zoomView(now, middle, 1 / KEY_ZOOM, options.limits)
|
|
256
|
+
};
|
|
257
|
+
case "-":
|
|
258
|
+
case "_": return {
|
|
259
|
+
type: "move",
|
|
260
|
+
to: zoomView(now, middle, KEY_ZOOM, options.limits)
|
|
261
|
+
};
|
|
262
|
+
case "Home":
|
|
263
|
+
case "0": return {
|
|
264
|
+
type: "view",
|
|
265
|
+
view: options.home
|
|
266
|
+
};
|
|
267
|
+
default: {
|
|
268
|
+
const view = key.length === 1 ? options.views?.[key.toLowerCase()] : void 0;
|
|
269
|
+
return view === void 0 ? void 0 : {
|
|
270
|
+
type: "view",
|
|
271
|
+
view
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// src/graph/pointers.ts
|
|
277
|
+
/** The pointers of a picture that no pointer is down on. */
|
|
278
|
+
const NO_POINTERS = {
|
|
279
|
+
at: /* @__PURE__ */ new Map(),
|
|
280
|
+
start: void 0,
|
|
281
|
+
many: false
|
|
282
|
+
};
|
|
283
|
+
/** A finger moves more than a mouse between down and up. This is the distance of a click for a finger, in CSS pixels. */
|
|
284
|
+
const TOUCH_CLICK_DISTANCE = 10;
|
|
285
|
+
/** This function gives the pointers after a pointer went down. The first pointer starts a possible click. */
|
|
286
|
+
function pointerDown(pointers, id, at) {
|
|
287
|
+
const next = new Map(pointers.at).set(id, at);
|
|
288
|
+
return next.size === 1 ? {
|
|
289
|
+
at: next,
|
|
290
|
+
start: at,
|
|
291
|
+
many: false
|
|
292
|
+
} : {
|
|
293
|
+
at: next,
|
|
294
|
+
start: pointers.start,
|
|
295
|
+
many: true
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* This function gives the pointers and the view after a pointer moved.
|
|
300
|
+
*
|
|
301
|
+
* One pointer moves the picture, so the point of the picture below the pointer stays there.
|
|
302
|
+
* Two pointers make a pinch: `pinchView` gives the view. Three pointers or more do not change the view.
|
|
303
|
+
* A pointer that is not down changes nothing.
|
|
304
|
+
*/
|
|
305
|
+
function pointerMove(pointers, id, at, view, limits = ZOOM_LIMITS) {
|
|
306
|
+
const old = pointers.at.get(id);
|
|
307
|
+
if (old === void 0) return {
|
|
308
|
+
pointers,
|
|
309
|
+
view
|
|
310
|
+
};
|
|
311
|
+
const next = {
|
|
312
|
+
...pointers,
|
|
313
|
+
at: new Map(pointers.at).set(id, at)
|
|
314
|
+
};
|
|
315
|
+
if (pointers.at.size === 1) return {
|
|
316
|
+
pointers: next,
|
|
317
|
+
view: panView(view, at.x - old.x, at.y - old.y)
|
|
318
|
+
};
|
|
319
|
+
if (pointers.at.size > 2) return {
|
|
320
|
+
pointers: next,
|
|
321
|
+
view
|
|
322
|
+
};
|
|
323
|
+
for (const [key, other] of pointers.at) if (key !== id) return {
|
|
324
|
+
pointers: next,
|
|
325
|
+
view: pinchView(view, [old, other], [at, other], limits)
|
|
326
|
+
};
|
|
327
|
+
return {
|
|
328
|
+
pointers: next,
|
|
329
|
+
view
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* This function gives the pointers after a pointer went up, and tells if the pointer made a click.
|
|
334
|
+
*
|
|
335
|
+
* A click is one pointer that went up not more than `limit` from its start, with no second pointer between.
|
|
336
|
+
* The default of `limit` is `CLICK_DISTANCE`. Use `TOUCH_CLICK_DISTANCE` for a finger.
|
|
337
|
+
*/
|
|
338
|
+
function pointerUp(pointers, id, at, limit = 4) {
|
|
339
|
+
if (!pointers.at.has(id)) return {
|
|
340
|
+
pointers,
|
|
341
|
+
click: false
|
|
342
|
+
};
|
|
343
|
+
const rest = new Map(pointers.at);
|
|
344
|
+
rest.delete(id);
|
|
345
|
+
if (rest.size > 0) return {
|
|
346
|
+
pointers: {
|
|
347
|
+
...pointers,
|
|
348
|
+
at: rest
|
|
349
|
+
},
|
|
350
|
+
click: false
|
|
351
|
+
};
|
|
352
|
+
return {
|
|
353
|
+
pointers: NO_POINTERS,
|
|
354
|
+
click: !pointers.many && pointers.start !== void 0 && isClick(pointers.start, at, limit)
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
/** This function gives the pointers after the browser stopped a pointer, for example for a gesture of the system. It makes no click. */
|
|
358
|
+
function pointerCancel(pointers, id) {
|
|
359
|
+
if (!pointers.at.has(id)) return pointers;
|
|
360
|
+
const rest = new Map(pointers.at);
|
|
361
|
+
rest.delete(id);
|
|
362
|
+
return rest.size > 0 ? {
|
|
363
|
+
...pointers,
|
|
364
|
+
at: rest
|
|
365
|
+
} : NO_POINTERS;
|
|
366
|
+
}
|
|
367
|
+
export { FIT_PADDING, NO_POINTERS, SMALLEST_AREA, TOUCH_CLICK_DISTANCE, UNIT_VIEW, WHEEL_LINE, WHEEL_PINCH, WHEEL_SPEED, ZOOM_LIMITS, clampZoom, fitRect, frameRects, freeArea, panView, pictureKeyAction, pictureMoveAt, pinchView, pointerCancel, pointerDown, pointerMove, pointerUp, rectToScreen, revealRects, showsRect, toPicture, toScreen, viewAt, viewBetween, wheelFactor, zoomView };
|
|
368
|
+
|
|
369
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","names":[],"sources":["../src/graph/camera.ts","../src/graph/keys.ts","../src/graph/pointers.ts"],"sourcesContent":["import type { Point, Rect } from \"@mark1russell7/layout-contract\";\nimport { easeInOut, partAt } from \"../motion.ts\";\n\n/**\n * The camera of a flat picture: a zoom and the position of the origin.\n * A point `p` of the picture shows at the screen point `p * k + (x, y)`. Each screen length is in CSS pixels.\n */\nexport interface PictureView {\n /** The screen position of the origin of the picture, from the left edge. */\n readonly x: number;\n /** The screen position of the origin of the picture, from the top edge. */\n readonly y: number;\n /** The zoom: the screen length of one unit of the picture. */\n readonly k: number;\n}\n\n/** The limits of the zoom of a camera. */\nexport interface ZoomLimits {\n readonly min: number;\n readonly max: number;\n}\n\n/** The default limits of the zoom. */\nexport const ZOOM_LIMITS: ZoomLimits = { min: 0.05, max: 8 };\n\n/** The view that shows each point of the picture at its own position. */\nexport const UNIT_VIEW: PictureView = { x: 0, y: 0, k: 1 };\n\n/** This function gives a zoom in its limits. A zoom that is not a number gives the smallest zoom. */\nexport function clampZoom(k: number, limits: ZoomLimits = ZOOM_LIMITS): number {\n return k >= limits.min ? Math.min(k, limits.max) : limits.min;\n}\n\n/** This function gives the point of the picture that shows at a screen point. */\nexport function toPicture(view: PictureView, screen: Point): Point {\n return { x: (screen.x - view.x) / view.k, y: (screen.y - view.y) / view.k };\n}\n\n/** This function gives the screen point that shows a point of the picture. */\nexport function toScreen(view: PictureView, point: Point): Point {\n return { x: point.x * view.k + view.x, y: point.y * view.k + view.y };\n}\n\n/** This function gives the screen rectangle that shows a rectangle of the picture. */\nexport function rectToScreen(view: PictureView, rect: Rect): Rect {\n return { x: rect.x * view.k + view.x, y: rect.y * view.k + view.y, w: rect.w * view.k, h: rect.h * view.k };\n}\n\n/** This function gives the view with the zoom `k` that shows the point `point` of the picture at the screen point `at`. */\nexport function viewAt(point: Point, at: Point, k: number): PictureView {\n return { x: at.x - point.x * k, y: at.y - point.y * k, k };\n}\n\n/** This function gives the view after a move of the picture by a screen distance. */\nexport function panView(view: PictureView, dx: number, dy: number): PictureView {\n return { x: view.x + dx, y: view.y + dy, k: view.k };\n}\n\n/**\n * This function gives the view after a zoom by `factor`. The zoom stays in its limits.\n * The screen point `at` shows the same point of the picture before and after the zoom.\n */\nexport function zoomView(view: PictureView, at: Point, factor: number, limits: ZoomLimits = ZOOM_LIMITS): PictureView {\n const k = clampZoom(view.k * factor, limits);\n const ratio = k / view.k;\n return { x: at.x - (at.x - view.x) * ratio, y: at.y - (at.y - view.y) * ratio, k };\n}\n\n/** The positions of the two pointers of a pinch, in CSS pixels. */\nexport type PointerPair = readonly [Point, Point];\n\n/**\n * This function gives the view after the two pointers of a pinch move from `before` to `after`.\n *\n * The zoom changes by the ratio of the two distances between the pointers.\n * The point of the picture at the middle of the pointers stays at their middle.\n * Thus each pointer keeps its point of the picture, if the pointers do not turn and the zoom is in its limits.\n */\nexport function pinchView(view: PictureView, before: PointerPair, after: PointerPair, limits: ZoomLimits = ZOOM_LIMITS): PictureView {\n const from = { x: (before[0].x + before[1].x) / 2, y: (before[0].y + before[1].y) / 2 };\n const to = { x: (after[0].x + after[1].x) / 2, y: (after[0].y + after[1].y) / 2 };\n const was = Math.hypot(before[0].x - before[1].x, before[0].y - before[1].y);\n const is = Math.hypot(after[0].x - after[1].x, after[0].y - after[1].y);\n // Two pointers at one position give no ratio. The picture then only moves.\n const factor = was > 0 && is > 0 ? is / was : 1;\n return zoomView(panView(view, to.x - from.x, to.y - from.y), to, factor, limits);\n}\n\n/** The speed of the zoom of a wheel: the change of the natural logarithm of the zoom for one CSS pixel of the wheel. */\nexport const WHEEL_SPEED = 0.0015;\n\n/** The height of one line of a wheel that gives its turn in lines, in CSS pixels. */\nexport const WHEEL_LINE = 16;\n\n/** The factor of the speed of the wheel for a pinch on a touch pad. A browser gives such a pinch as a wheel with the key `Control`. */\nexport const WHEEL_PINCH = 10;\n\n/**\n * This function gives the factor of the zoom for one event of a wheel. A turn away from the person makes the picture larger.\n *\n * `deltaY` and `deltaMode` are the fields of the event. A mode of 1 has its turn in lines.\n * `pinch` is the field `ctrlKey` of the event: a pinch on a touch pad has small turns, so its speed is higher.\n */\nexport function wheelFactor(deltaY: number, deltaMode: number = 0, pinch: boolean = false): number {\n const pixels = deltaMode === 1 ? deltaY * WHEEL_LINE : deltaY;\n return Math.exp(0 - pixels * WHEEL_SPEED * (pinch ? WHEEL_PINCH : 1));\n}\n\n/** The parts of a picture that a page covers, from each edge, in CSS pixels. */\nexport interface Insets {\n readonly top: number;\n readonly right: number;\n readonly bottom: number;\n readonly left: number;\n}\n\n/** The smallest width and height of a free area, in CSS pixels. */\nexport const SMALLEST_AREA = 80;\n\n/**\n * This function gives the free area of a picture: the screen rectangle that the page does not cover.\n * A camera shows a selection in this area, so a panel of the page does not hide it.\n * The width and the height of the area are `SMALLEST_AREA` at least.\n */\nexport function freeArea(size: { readonly width: number; readonly height: number }, insets: Partial<Insets> = {}): Rect {\n const left = insets.left ?? 0;\n const top = insets.top ?? 0;\n return {\n x: left,\n y: top,\n w: Math.max(SMALLEST_AREA, size.width - left - (insets.right ?? 0)),\n h: Math.max(SMALLEST_AREA, size.height - top - (insets.bottom ?? 0)),\n };\n}\n\n/** The default distance between a rectangle that a camera shows and each edge of the area, in CSS pixels. */\nexport const FIT_PADDING = 24;\n\n/** The options of `fitRect`. */\nexport interface FitOptions {\n /** The distance between the rectangle and each edge of the area, in CSS pixels. The default is `FIT_PADDING`. */\n readonly padding?: number | undefined;\n /** The largest zoom of the result. The default is the largest zoom of the limits. */\n readonly most?: number | undefined;\n /** The limits of the zoom. The default is `ZOOM_LIMITS`. */\n readonly limits?: ZoomLimits | undefined;\n}\n\n/** This function gives the middle of a rectangle. */\nfunction middleOf(rect: Rect): Point {\n return { x: rect.x + rect.w / 2, y: rect.y + rect.h / 2 };\n}\n\n/**\n * This function gives the view that shows a rectangle of the picture in an area of the screen, as large as the area permits.\n * The middle of the rectangle is at the middle of the area. A rectangle with no size gets the largest zoom.\n */\nexport function fitRect(rect: Rect, area: Rect, options: FitOptions = {}): PictureView {\n const limits = options.limits ?? ZOOM_LIMITS;\n const padding = options.padding ?? FIT_PADDING;\n const width = Math.max(area.w - 2 * padding, 1);\n const height = Math.max(area.h - 2 * padding, 1);\n const k = clampZoom(Math.min(options.most ?? limits.max, width / Math.max(rect.w, 0), height / Math.max(rect.h, 0)), limits);\n return viewAt(middleOf(rect), middleOf(area), k);\n}\n\n/** The options of `frameRects`. */\nexport interface FrameOptions extends FitOptions {\n /** The smallest zoom at which a person reads the content of a rectangle. */\n readonly least: number;\n}\n\n/**\n * This function gives the view for the first rectangle of a list that an area of the screen shows at the zoom `least` or more.\n *\n * Give the bounds of the largest group of boxes first, then the bounds of smaller groups.\n * If no rectangle is small enough, the result has the zoom `least` and the middle of the last rectangle at the middle of the area.\n * An empty list gives `undefined`.\n */\nexport function frameRects(rects: readonly Rect[], area: Rect, options: FrameOptions): PictureView | undefined {\n for (const rect of rects) {\n const view = fitRect(rect, area, options);\n if (view.k >= options.least) return view;\n }\n const last = rects.at(-1);\n if (last === undefined) return undefined;\n return viewAt(middleOf(last), middleOf(area), clampZoom(options.least, options.limits));\n}\n\n/**\n * This function tells if a view shows all of a rectangle of the picture in an area of the screen.\n * `margin` is the smallest distance between the rectangle and each edge of the area, in CSS pixels.\n */\nexport function showsRect(view: PictureView, rect: Rect, area: Rect, margin: number = 0): boolean {\n const shown = rectToScreen(view, rect);\n return shown.x >= area.x + margin && shown.y >= area.y + margin && shown.x + shown.w <= area.x + area.w - margin && shown.y + shown.h <= area.y + area.h - margin;\n}\n\n/** The options of `revealRects`. */\nexport interface RevealOptions extends FrameOptions {\n /** The smallest distance between a rectangle in view and each edge of the area, in CSS pixels. The default is 0. */\n readonly margin?: number | undefined;\n}\n\n/**\n * This function gives the view that shows a selection, and it keeps the view `view` when the selection is in view.\n *\n * The rectangles are the bounds of the groups of the selection, as for `frameRects`, the largest group first.\n * The selection is in view when `view` has the zoom `least` or more, and shows all of the rectangle that `frameRects` selects.\n * The result is then `view` itself, so a camera does not move for a click on a box that a person reads.\n * In each other case, the result is the view of `frameRects`. An empty list gives `view`.\n */\nexport function revealRects(view: PictureView, rects: readonly Rect[], area: Rect, options: RevealOptions): PictureView {\n for (const rect of rects) {\n const framed = fitRect(rect, area, options);\n if (framed.k < options.least) continue;\n return view.k >= options.least && showsRect(view, rect, area, options.margin ?? 0) ? view : framed;\n }\n return frameRects(rects.slice(-1), area, options) ?? view;\n}\n\n/**\n * This function gives the view at a part of the way between two views. `part` goes from 0 to 1.\n *\n * The zoom changes by an equal factor for each equal step, so a zoom has one speed in the picture.\n * The way is a zoom at one screen point: the point of the picture that the two views show there stays there.\n * Thus each point of the picture moves along a straight line of the screen, in one direction.\n * Two views with one zoom give a straight move at one speed.\n */\nexport function viewBetween(from: PictureView, to: PictureView, part: number): PictureView {\n if (!(part > 0)) return from;\n if (part >= 1) return to;\n const log = Math.log(to.k / from.k);\n if (!Number.isFinite(log)) return to;\n // The origin moves in proportion to the change of the zoom. The function expm1 keeps the precision for two zooms that are almost equal.\n const share = log === 0 ? part : Math.expm1(log * part) / Math.expm1(log);\n return { x: from.x + (to.x - from.x) * share, y: from.y + (to.y - from.y) * share, k: from.k * Math.exp(log * part) };\n}\n\n/** A move of the camera of a flat picture from one view to a different view. */\nexport interface PictureMove {\n readonly from: PictureView;\n readonly to: PictureView;\n /** The time of the start of the move, in milliseconds. */\n readonly start: number;\n /** The time that the move takes, in milliseconds. */\n readonly duration: number;\n}\n\n/** The view of a camera at one time of a move. */\nexport interface PictureMoveStep {\n readonly view: PictureView;\n /** This value is true at the end of the move, and after it. */\n readonly done: boolean;\n}\n\n/**\n * This function gives the view of a camera at the time `now` of a move, in milliseconds.\n * The move has a slow start and a slow end. A move with no duration is at its end immediately.\n */\nexport function pictureMoveAt(move: PictureMove, now: number): PictureMoveStep {\n const part = partAt(move.start, move.duration, now);\n if (part >= 1) return { view: move.to, done: true };\n return { view: viewBetween(move.from, move.to, easeInOut(part)), done: false };\n}\n","import type { Rect } from \"@mark1russell7/layout-contract\";\nimport { KEY_PART, KEY_ZOOM } from \"../keys.ts\";\nimport { panView, zoomView, type PictureView, type ZoomLimits } from \"./camera.ts\";\n\n/** What a key does on a flat picture: it moves the camera to a view, or it shows a view by its name. */\nexport type PictureKeyAction = { readonly type: \"move\"; readonly to: PictureView } | { readonly type: \"view\"; readonly view: string };\n\n/** The keys of a flat picture. */\nexport interface PictureKeyOptions {\n /** The name of the view of the keys `Home` and `0`. */\n readonly home: string;\n /** The name of the view of each other key, for example `{ f: \"focus\" }`. A letter has no case. */\n readonly views?: Readonly<Record<string, string>> | undefined;\n /** The limits of the zoom. The default is `ZOOM_LIMITS`. */\n readonly limits?: ZoomLimits | undefined;\n}\n\n/**\n * This function gives the action of a key on a flat picture, or `undefined` for a key with no action.\n *\n * `area` is the part of the screen that shows the picture. `freeArea` gives it.\n * An arrow key moves the camera by the part `KEY_PART` of the smaller side of the area.\n * The keys `+` and `-` zoom at the middle of the area, by the factor of one step of a key on a 3D stage.\n * The keys `Home` and `0` show the home view.\n */\nexport function pictureKeyAction(key: string, now: PictureView, area: Rect, options: PictureKeyOptions): PictureKeyAction | undefined {\n const step = Math.min(area.w, area.h) * KEY_PART;\n const middle = { x: area.x + area.w / 2, y: area.y + area.h / 2 };\n switch (key) {\n // The camera moves in the direction of the arrow, so the picture moves in the opposite direction.\n case \"ArrowLeft\":\n return { type: \"move\", to: panView(now, step, 0) };\n case \"ArrowRight\":\n return { type: \"move\", to: panView(now, 0 - step, 0) };\n case \"ArrowUp\":\n return { type: \"move\", to: panView(now, 0, step) };\n case \"ArrowDown\":\n return { type: \"move\", to: panView(now, 0, 0 - step) };\n case \"+\":\n case \"=\":\n return { type: \"move\", to: zoomView(now, middle, 1 / KEY_ZOOM, options.limits) };\n case \"-\":\n case \"_\":\n return { type: \"move\", to: zoomView(now, middle, KEY_ZOOM, options.limits) };\n case \"Home\":\n case \"0\":\n return { type: \"view\", view: options.home };\n default: {\n const view = key.length === 1 ? options.views?.[key.toLowerCase()] : undefined;\n return view === undefined ? undefined : { type: \"view\", view };\n }\n }\n}\n","import type { Point } from \"@mark1russell7/layout-contract\";\nimport { CLICK_DISTANCE, isClick } from \"../highlight.ts\";\nimport { panView, pinchView, ZOOM_LIMITS, type PictureView, type ZoomLimits } from \"./camera.ts\";\n\n/** The pointers that are down on a picture: a mouse button, a pen or each finger of a hand. */\nexport interface Pointers {\n /** The screen position of each pointer that is down, by the id of the pointer. */\n readonly at: ReadonlyMap<number, Point>;\n /** The position where the first pointer went down. */\n readonly start: Point | undefined;\n /** This value is true after a second pointer went down. The pointers then make no click. */\n readonly many: boolean;\n}\n\n/** The pointers of a picture that no pointer is down on. */\nexport const NO_POINTERS: Pointers = { at: new Map(), start: undefined, many: false };\n\n/** A finger moves more than a mouse between down and up. This is the distance of a click for a finger, in CSS pixels. */\nexport const TOUCH_CLICK_DISTANCE = 10;\n\n/** This function gives the pointers after a pointer went down. The first pointer starts a possible click. */\nexport function pointerDown(pointers: Pointers, id: number, at: Point): Pointers {\n const next = new Map(pointers.at).set(id, at);\n // A pointer that went up outside of the page can go down again with no up between.\n const first = next.size === 1;\n return first ? { at: next, start: at, many: false } : { at: next, start: pointers.start, many: true };\n}\n\n/** The result of `pointerMove`: the pointers and the view after the move. */\nexport interface PointerMoveResult {\n readonly pointers: Pointers;\n readonly view: PictureView;\n}\n\n/**\n * This function gives the pointers and the view after a pointer moved.\n *\n * One pointer moves the picture, so the point of the picture below the pointer stays there.\n * Two pointers make a pinch: `pinchView` gives the view. Three pointers or more do not change the view.\n * A pointer that is not down changes nothing.\n */\nexport function pointerMove(pointers: Pointers, id: number, at: Point, view: PictureView, limits: ZoomLimits = ZOOM_LIMITS): PointerMoveResult {\n const old = pointers.at.get(id);\n if (old === undefined) return { pointers, view };\n const next: Pointers = { ...pointers, at: new Map(pointers.at).set(id, at) };\n if (pointers.at.size === 1) return { pointers: next, view: panView(view, at.x - old.x, at.y - old.y) };\n if (pointers.at.size > 2) return { pointers: next, view };\n for (const [key, other] of pointers.at) {\n if (key !== id) return { pointers: next, view: pinchView(view, [old, other], [at, other], limits) };\n }\n return { pointers: next, view };\n}\n\n/** The result of `pointerUp`: the pointers that stay down, and the answer if the pointer made a click. */\nexport interface PointerUpResult {\n readonly pointers: Pointers;\n /** This value is true when one pointer went down and up at almost the same position. */\n readonly click: boolean;\n}\n\n/**\n * This function gives the pointers after a pointer went up, and tells if the pointer made a click.\n *\n * A click is one pointer that went up not more than `limit` from its start, with no second pointer between.\n * The default of `limit` is `CLICK_DISTANCE`. Use `TOUCH_CLICK_DISTANCE` for a finger.\n */\nexport function pointerUp(pointers: Pointers, id: number, at: Point, limit: number = CLICK_DISTANCE): PointerUpResult {\n if (!pointers.at.has(id)) return { pointers, click: false };\n const rest = new Map(pointers.at);\n rest.delete(id);\n if (rest.size > 0) return { pointers: { ...pointers, at: rest }, click: false };\n return { pointers: NO_POINTERS, click: !pointers.many && pointers.start !== undefined && isClick(pointers.start, at, limit) };\n}\n\n/** This function gives the pointers after the browser stopped a pointer, for example for a gesture of the system. It makes no click. */\nexport function pointerCancel(pointers: Pointers, id: number): Pointers {\n if (!pointers.at.has(id)) return pointers;\n const rest = new Map(pointers.at);\n rest.delete(id);\n return rest.size > 0 ? { ...pointers, at: rest } : NO_POINTERS;\n}\n"],"mappings":";;;AAuBA,MAAa,cAA0B;CAAE,KAAK;CAAM,KAAK;AAAE;;AAG3D,MAAa,YAAyB;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;;AAGzD,SAAgB,UAAU,GAAW,SAAqB,aAAqB;CAC7E,OAAO,KAAK,OAAO,MAAM,KAAK,IAAI,GAAG,OAAO,GAAG,IAAI,OAAO;AAC5D;;AAGA,SAAgB,UAAU,MAAmB,QAAsB;CACjE,OAAO;EAAE,IAAI,OAAO,IAAI,KAAK,KAAK,KAAK;EAAG,IAAI,OAAO,IAAI,KAAK,KAAK,KAAK;CAAE;AAC5E;;AAGA,SAAgB,SAAS,MAAmB,OAAqB;CAC/D,OAAO;EAAE,GAAG,MAAM,IAAI,KAAK,IAAI,KAAK;EAAG,GAAG,MAAM,IAAI,KAAK,IAAI,KAAK;CAAE;AACtE;;AAGA,SAAgB,aAAa,MAAmB,MAAkB;CAChE,OAAO;EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,KAAK;EAAG,GAAG,KAAK,IAAI,KAAK,IAAI,KAAK;EAAG,GAAG,KAAK,IAAI,KAAK;EAAG,GAAG,KAAK,IAAI,KAAK;CAAE;AAC5G;;AAGA,SAAgB,OAAO,OAAc,IAAW,GAAwB;CACtE,OAAO;EAAE,GAAG,GAAG,IAAI,MAAM,IAAI;EAAG,GAAG,GAAG,IAAI,MAAM,IAAI;EAAG;CAAE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AA,GAAiD;CACpH,IAAI,CAAC,SAAS,GAAG,IAAI,EAAE,GAAG,OAAO;EAAE;EAAU,OAAO;CAAM;CAC1D,MAAM,OAAO,IAAI,IAAI,SAAS,EAAE;CAChC,KAAK,OAAO,EAAE;CACd,IAAI,KAAK,OAAO,GAAG,OAAO;EAAE,UAAU;GAAE,GAAG;GAAU,IAAI;EAAK;EAAG,OAAO;CAAM;CAC9E,OAAO;EAAE,UAAU;EAAa,OAAO,CAAC,SAAS,QAAQ,SAAS,UAAU,KAAA,KAAa,QAAQ,SAAS,OAAO,IAAI,KAAK;CAAE;AAC9H;;AAGA,SAAgB,cAAc,UAAoB,IAAsB;CACtE,IAAI,CAAC,SAAS,GAAG,IAAI,EAAE,GAAG,OAAO;CACjC,MAAM,OAAO,IAAI,IAAI,SAAS,EAAE;CAChC,KAAK,OAAO,EAAE;CACd,OAAO,KAAK,OAAO,IAAI;EAAE,GAAG;EAAU,IAAI;CAAK,IAAI;AACrD"}
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/keys.ts","../src/motion.ts","../src/screen.ts","../src/support.ts"],"mappings":";;;;qBAGa;;qBAGA;;qBAGA;;KAGD;WAAuB;WAAwB,OAAO;;WAAqB;WAAuB;;;UAG7F;;WAEN;;WAEA,QAAQ,SAAS;;WAEjB;;WAEA;;;;;;;;;;wBAWK,UAAU,aAAa,KAAK,OAAO,SAAS,aAAa;;UC/BxD;WACN,MAAM;WACN,IAAI;;WAEJ;;WAEA;;;UAIM;WACN,OAAO;;WAEP;;;;;;wBAOK,UAAU;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/keys.ts","../src/motion.ts","../src/screen.ts","../src/support.ts"],"mappings":";;;;qBAGa;;qBAGA;;qBAGA;;KAGD;WAAuB;WAAwB,OAAO;;WAAqB;WAAuB;;;UAG7F;;WAEN;;WAEA,QAAQ,SAAS;;WAEjB;;WAEA;;;;;;;;;;wBAWK,UAAU,aAAa,KAAK,OAAO,SAAS,aAAa;;UC/BxD;WACN,MAAM;WACN,IAAI;;WAEJ;;WAEA;;;UAIM;WACN,OAAO;;WAEP;;;;;;wBAOK,UAAU;;;;;wBAiBV,OAAO,MAAM,MAAM,aAAa,mBAAsB;;;;;;;wBAYtD,SAAS,eAAe,cAAc,iBAAiB,cAAc;;;;;;;;;;wBCpCrE,YAAY,OAAO,QAAQ,MAAM,mBAAmB,YAAY,mBAAmB,eAAe,iBAAiB;;;;;;;;;;wBCPnH,eAAe,OAAM"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as nearDepth, c as surfaceOf, i as fitView, n as ballView, o as reachOf, r as capView, s as stageLimits, t as FIT_MARGIN } from "./extent-D2SsHJnP.js";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as CLICK_DISTANCE, c as isClick, d as KEY_ZOOM, f as keyAction, l as KEY_PART, n as easeInOut, o as NO_HIGHLIGHTS, r as moveAt, s as highlightOf, t as approach, u as KEY_TURN } from "./motion-DViuJNyh.js";
|
|
3
3
|
import { _ as replaySpan, a as changeAfter, b as spanPart, c as changeTimes, d as replayKey, f as replayNextSpeed, g as replaySeek, h as replayPlay, i as REPLAY_STEP, l as isLive, m as replayPause, n as REPLAY_PAGE, o as changeBefore, p as replayOf, r as REPLAY_SPEEDS, s as changeIndex, t as REPLAY_DURATION, u as replayAdvance, v as replayToggle, x as spanTime, y as spanOfTimes } from "./replay-YdWMyFko.js";
|
|
4
4
|
import { t as screenPoint } from "./screen-DeOx4_90.js";
|
|
5
5
|
import { a as fitDistance, c as turnAcross, d as viewOf, i as clampPlace, l as turnBetween, n as cameraPosition, o as placeBetween, r as capDistance, s as speedAt, t as FIELD_OF_VIEW, u as viewAxes } from "./view-BB_EQx3I.js";
|
|
@@ -105,11 +105,18 @@ function easeInOut(part) {
|
|
|
105
105
|
return clamped < .5 ? 4 * clamped * clamped * clamped : 1 - (-2 * clamped + 2) ** 3 / 2;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
+
* This function gives the part of a move that is complete at the time `now`, from 0 to 1.
|
|
109
|
+
* `start` is the time of the start of the move, and `duration` is the time that it takes. A move with no duration is complete.
|
|
110
|
+
*/
|
|
111
|
+
function partAt(start, duration, now) {
|
|
112
|
+
return duration > 0 ? Math.min(Math.max((now - start) / duration, 0), 1) : 1;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
108
115
|
* This function gives the place of a camera at the time `now` of a move, in milliseconds.
|
|
109
116
|
* A move with no duration is at its end immediately. `surface` is the radius of the ball around the target, or 0 for no ball.
|
|
110
117
|
*/
|
|
111
118
|
function moveAt(move, now, surface = 0) {
|
|
112
|
-
const part =
|
|
119
|
+
const part = partAt(move.start, move.duration, now);
|
|
113
120
|
if (part >= 1) return {
|
|
114
121
|
place: move.to,
|
|
115
122
|
done: true
|
|
@@ -130,6 +137,6 @@ function approach(value, goal, seconds, time, snap = .01) {
|
|
|
130
137
|
const next = value + (goal - value) * (1 - Math.exp(0 - seconds / time));
|
|
131
138
|
return Math.abs(goal - next) < snap ? goal : next;
|
|
132
139
|
}
|
|
133
|
-
export {
|
|
140
|
+
export { CLICK_DISTANCE as a, isClick as c, KEY_ZOOM as d, keyAction as f, partAt as i, KEY_PART as l, easeInOut as n, NO_HIGHLIGHTS as o, moveAt as r, highlightOf as s, approach as t, KEY_TURN as u };
|
|
134
141
|
|
|
135
|
-
//# sourceMappingURL=motion-
|
|
142
|
+
//# sourceMappingURL=motion-DViuJNyh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motion-
|
|
1
|
+
{"version":3,"file":"motion-DViuJNyh.js","names":[],"sources":["../src/keys.ts","../src/highlight.ts","../src/motion.ts"],"sourcesContent":["import { FIELD_OF_VIEW, turnAcross, type Place } from \"./view.ts\";\n\n/** The largest angle of one step of an arrow key, in radians. A camera far from a ball, or with no ball, turns by this angle. */\nexport const KEY_TURN: number = Math.PI / 24;\n\n/** The part of the height of the picture by which one step of an arrow key moves the surface of a ball, near the ball. */\nexport const KEY_PART = 0.125;\n\n/** The factor of the height of a camera above the surface for one step of the key `+`. */\nexport const KEY_ZOOM = 0.85;\n\n/** What a key does on a stage: it moves the camera to a place, or it shows a view. */\nexport type KeyAction = { readonly type: \"place\"; readonly place: Place } | { readonly type: \"view\"; readonly view: string };\n\n/** The keys of a stage. */\nexport interface KeyOptions {\n /** The name of the view of the keys `Home` and `0`. */\n readonly home: string;\n /** The name of the view of each other key, for example `{ t: \"top\" }`. A letter has no case. */\n readonly views?: Readonly<Record<string, string>> | undefined;\n /** The radius of the ball around the target that the camera stays out of, or 0 for no ball. */\n readonly surface?: number | undefined;\n /** The vertical angle of the picture, in degrees. The default is `FIELD_OF_VIEW`. */\n readonly fieldOfView?: number | undefined;\n}\n\n/**\n * This function gives the action of a key on a stage, or `undefined` for a key with no action.\n *\n * The arrow keys turn the camera around the target. The keys `+` and `-` change the height above the surface.\n * The keys `Home` and `0` show the home view.\n * Near a ball, a step of an arrow key moves the surface by the part `KEY_PART` of the height of the picture.\n * The result has no limits: the stage puts the place in its limits.\n */\nexport function keyAction(key: string, now: Place, options: KeyOptions): KeyAction | undefined {\n const surface = options.surface ?? 0;\n const turn = Math.min(KEY_TURN, KEY_PART * turnAcross(now.distance, surface, options.fieldOfView ?? FIELD_OF_VIEW));\n const zoom = (factor: number): Place => ({ ...now, distance: surface + (now.distance - surface) * factor });\n switch (key) {\n case \"ArrowLeft\":\n return { type: \"place\", place: { ...now, azimuth: now.azimuth - turn } };\n case \"ArrowRight\":\n return { type: \"place\", place: { ...now, azimuth: now.azimuth + turn } };\n case \"ArrowUp\":\n return { type: \"place\", place: { ...now, polar: now.polar - turn } };\n case \"ArrowDown\":\n return { type: \"place\", place: { ...now, polar: now.polar + turn } };\n case \"+\":\n case \"=\":\n return { type: \"place\", place: zoom(KEY_ZOOM) };\n case \"-\":\n case \"_\":\n return { type: \"place\", place: zoom(1 / KEY_ZOOM) };\n case \"Home\":\n case \"0\":\n return { type: \"view\", view: options.home };\n default: {\n const view = key.length === 1 ? options.views?.[key.toLowerCase()] : undefined;\n return view === undefined ? undefined : { type: \"view\", view };\n }\n }\n}\n","/** The highlight of a record. 0 is no highlight. 1 is a record under the pointer or in the highlighted list. 2 is the selected record. */\nexport type Highlight = 0 | 1 | 2;\n\n/** The records of a stage that have a highlight. Each record has a name. */\nexport interface Highlights {\n /** The name of the record under the pointer. */\n readonly hovered: string | undefined;\n /** The name of the selected record. */\n readonly selected: string | undefined;\n /** The names of the records that the page highlights. */\n readonly highlighted: ReadonlySet<string>;\n}\n\n/** The highlights of a stage with no pointer on it and no selected record. */\nexport const NO_HIGHLIGHTS: Highlights = { hovered: undefined, selected: undefined, highlighted: new Set() };\n\n/** This function gives the highlight of a record. The selected record has the highest highlight. */\nexport function highlightOf(highlights: Highlights, record: string): Highlight {\n if (record === highlights.selected) return 2;\n return record === highlights.hovered || highlights.highlighted.has(record) ? 1 : 0;\n}\n\n/** A pointer that moves this distance or less between down and up makes a click, in CSS pixels. */\nexport const CLICK_DISTANCE = 4;\n\n/**\n * This function tells if a pointer that went down and up made a click. A pointer that moved more than `limit` made a drag.\n * The positions and the limit are in CSS pixels.\n */\nexport function isClick(down: { readonly x: number; readonly y: number }, up: { readonly x: number; readonly y: number }, limit: number = CLICK_DISTANCE): boolean {\n return Math.hypot(up.x - down.x, up.y - down.y) <= limit;\n}\n","import { placeBetween, type Place } from \"./view.ts\";\n\n/** A move of a camera from one place to a different place. */\nexport interface Move {\n readonly from: Place;\n readonly to: Place;\n /** The time of the start of the move, in milliseconds. */\n readonly start: number;\n /** The time that the move takes, in milliseconds. */\n readonly duration: number;\n}\n\n/** The place of a camera at one time of a move. */\nexport interface MoveStep {\n readonly place: Place;\n /** This value is true at the end of the move, and after it. */\n readonly done: boolean;\n}\n\n/**\n * This function gives a part of a move with a slow start and a slow end. `part` goes from 0 to 1.\n * The result goes from 0 to 1, and it is 0.5 at the middle.\n */\nexport function easeInOut(part: number): number {\n const clamped = Math.min(Math.max(part, 0), 1);\n return clamped < 0.5 ? 4 * clamped * clamped * clamped : 1 - (-2 * clamped + 2) ** 3 / 2;\n}\n\n/**\n * This function gives the part of a move that is complete at the time `now`, from 0 to 1.\n * `start` is the time of the start of the move, and `duration` is the time that it takes. A move with no duration is complete.\n */\nexport function partAt(start: number, duration: number, now: number): number {\n return duration > 0 ? Math.min(Math.max((now - start) / duration, 0), 1) : 1;\n}\n\n/**\n * This function gives the place of a camera at the time `now` of a move, in milliseconds.\n * A move with no duration is at its end immediately. `surface` is the radius of the ball around the target, or 0 for no ball.\n */\nexport function moveAt(move: Move, now: number, surface: number = 0): MoveStep {\n const part = partAt(move.start, move.duration, now);\n if (part >= 1) return { place: move.to, done: true };\n return { place: placeBetween(move.from, move.to, easeInOut(part), surface), done: false };\n}\n\n/**\n * This function moves a value one step to its goal. Each step goes a constant part of the way that remains.\n *\n * `seconds` is the time of the step, and `time` is the time in which the value goes most of the way, in seconds.\n * A step with no time gives the goal. A value nearer to the goal than `snap` becomes the goal, so the steps have an end.\n */\nexport function approach(value: number, goal: number, seconds: number, time: number, snap: number = 0.01): number {\n if (!(seconds > 0) || !(time > 0)) return goal;\n const next = value + (goal - value) * (1 - Math.exp(0 - seconds / time));\n return Math.abs(goal - next) < snap ? goal : next;\n}\n"],"mappings":";;;AAGA,MAAa,WAAmB,KAAK,KAAK;;AAG1C,MAAa,WAAW;;AAGxB,MAAa,WAAW;;;;;;;;;AAyBxB,SAAgB,UAAU,KAAa,KAAY,SAA4C;CAC7F,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,OAAO,KAAK,IAAI,UAAU,WAAW,WAAW,IAAI,UAAU,SAAS,QAAQ,eAAA,EAA4B,CAAC;CAClH,MAAM,QAAQ,YAA2B;EAAE,GAAG;EAAK,UAAU,WAAW,IAAI,WAAW,WAAW;CAAO;CACzG,QAAQ,KAAR;EACE,KAAK,aACH,OAAO;GAAE,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AAM,CAAC,GAAG,CAAC;CAC7C,OAAO,UAAU,KAAM,IAAI,UAAU,UAAU,UAAU,KAAK,KAAK,UAAU,MAAM,IAAI;AACzF;;;;;AAMA,SAAgB,OAAO,OAAe,UAAkB,KAAqB;CAC3E,OAAO,WAAW,IAAI,KAAK,IAAI,KAAK,KAAK,MAAM,SAAS,UAAU,CAAC,GAAG,CAAC,IAAI;AAC7E;;;;;AAMA,SAAgB,OAAO,MAAY,KAAa,UAAkB,GAAa;CAC7E,MAAM,OAAO,OAAO,KAAK,OAAO,KAAK,UAAU,GAAG;CAClD,IAAI,QAAQ,GAAG,OAAO;EAAE,OAAO,KAAK;EAAI,MAAM;CAAK;CACnD,OAAO;EAAE,OAAO,aAAa,KAAK,MAAM,KAAK,IAAI,UAAU,IAAI,GAAG,OAAO;EAAG,MAAM;CAAM;AAC1F;;;;;;;AAQA,SAAgB,SAAS,OAAe,MAAc,SAAiB,MAAc,OAAe,KAAc;CAChH,IAAI,EAAE,UAAU,MAAM,EAAE,OAAO,IAAI,OAAO;CAC1C,MAAM,OAAO,SAAS,OAAO,UAAU,IAAI,KAAK,IAAI,IAAI,UAAU,IAAI;CACtE,OAAO,KAAK,IAAI,OAAO,IAAI,IAAI,OAAO,OAAO;AAC/C"}
|
package/build/three.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as nearDepth, c as surfaceOf, s as stageLimits } from "./extent-D2SsHJnP.js";
|
|
2
|
-
import {
|
|
2
|
+
import { c as isClick, f as keyAction, o as NO_HIGHLIGHTS, r as moveAt, s as highlightOf } from "./motion-DViuJNyh.js";
|
|
3
3
|
import { c as turnAcross, d as viewOf, i as clampPlace, n as cameraPosition, s as speedAt, t as FIELD_OF_VIEW } from "./view-BB_EQx3I.js";
|
|
4
4
|
import { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene, Vector2, WebGLRenderer } from "three";
|
|
5
5
|
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/visuals",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.4",
|
|
5
5
|
"description": "3D stages for data on three.js: a camera that a person moves, views by name, picking, highlights and themes, a globe of the Earth, and the shared marks of the viewers as data.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -68,6 +68,11 @@
|
|
|
68
68
|
"default": "./build/labels.js"
|
|
69
69
|
},
|
|
70
70
|
"./labels.css": "./styles/labels.css",
|
|
71
|
+
"./graph": {
|
|
72
|
+
"types": "./build/graph.d.ts",
|
|
73
|
+
"import": "./build/graph.js",
|
|
74
|
+
"default": "./build/graph.js"
|
|
75
|
+
},
|
|
71
76
|
"./package.json": "./package.json"
|
|
72
77
|
},
|
|
73
78
|
"files": [
|