@mark1russell7/visuals 0.3.2 → 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 +81 -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/{mark-AZ5AuAIJ.js → mark-D9bjgO-y.js} +46 -3
- package/build/mark-D9bjgO-y.js.map +1 -0
- package/build/{mark-D8AdQYAS.d.ts → mark-ubn709Qw.d.ts} +11 -3
- package/build/{mark-D8AdQYAS.d.ts.map → mark-ubn709Qw.d.ts.map} +1 -1
- package/build/markers.d.ts +1 -1
- package/build/markers.js +1 -1
- package/build/marks.d.ts +2 -2
- package/build/marks.js +2 -2
- 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/build/mark-AZ5AuAIJ.js.map +0 -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
|
|
|
@@ -398,6 +399,16 @@ shapeRing("triangle").length; // => 3: the corners of the sign, counter-clockwis
|
|
|
398
399
|
- A meter has no place. A page draws it in a panel, and a 3D view ignores it.
|
|
399
400
|
- A meter with no limit has no `limit`. A page shows only its value and its unit.
|
|
400
401
|
- Each point of a list of marks is in one space. The producer tells the unit and the axes of that space.
|
|
402
|
+
- `transformMarks` gives the marks in a different space. It moves each point, and it turns each direction.
|
|
403
|
+
|
|
404
|
+
```ts
|
|
405
|
+
import { transformMarks } from "@mark1russell7/visuals/marks";
|
|
406
|
+
|
|
407
|
+
// The marks of a room have the z axis up. A stage has the y axis up: a turn of a quarter about the x axis.
|
|
408
|
+
const onStage = transformMarks(marks, { position: { x: 0, y: 0, z: 0 }, rotation: { x: -Math.SQRT1_2, y: 0, z: 0, w: Math.SQRT1_2 } });
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
A transform is a `Transform3` of `@mark1russell7/layout-contract`. It has no scale, so each length of a mark stays.
|
|
401
412
|
|
|
402
413
|
`checkMarks` gives the faults of a list, each with a code, the index of its mark and the part with the fault. It examines the values that the types do not hold:
|
|
403
414
|
|
|
@@ -458,6 +469,74 @@ stage?.refresh();
|
|
|
458
469
|
- A record with a highlight gets a larger sign, and a line of the color `accent` around it.
|
|
459
470
|
- `signReach` gives the radius of a sign with its line. Give it to the field `clear` of a label.
|
|
460
471
|
- The pick of a field gives the mark. `fieldValue` reads the value of a cell.
|
|
472
|
+
- The content draws the marks in the space of the stage. `transformMarks` moves the marks of a different space into it.
|
|
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.
|
|
461
540
|
|
|
462
541
|
## The camera maths
|
|
463
542
|
|
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;AAC3D;;AAGA,SAAgB,QAAQ,MAAmB,IAAY,IAAyB;CAC9E,OAAO;EAAE,GAAG,KAAK,IAAI;EAAI,GAAG,KAAK,IAAI;EAAI,GAAG,KAAK;CAAE;AACrD;;;;;AAMA,SAAgB,SAAS,MAAmB,IAAW,QAAg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,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";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addPoints3, cross3, scalePoint3 } from "@mark1russell7/layout-contract";
|
|
1
|
+
import { addPoints3, cross3, rotatePoint3, scalePoint3, transformPoint3 } from "@mark1russell7/layout-contract";
|
|
2
2
|
// src/marks/levels.ts
|
|
3
3
|
/** These are the levels of a mark, from the lowest to the highest. */
|
|
4
4
|
const LEVELS = [
|
|
@@ -93,6 +93,49 @@ function fieldValue(field, column, row) {
|
|
|
93
93
|
if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;
|
|
94
94
|
return field.values[row * field.columns + column] ?? null;
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
/** This function gives a frame after a transform. The point gets the transform, and the direction gets only its rotation. */
|
|
97
|
+
function transformFrame(frame, transform) {
|
|
98
|
+
return {
|
|
99
|
+
at: transformPoint3(transform, frame.at),
|
|
100
|
+
out: rotatePoint3(transform.rotation, frame.out)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* This function gives the marks in a different space. Each point gets the transform, and each direction gets only its rotation.
|
|
105
|
+
* An example is the marks of a room with the z axis up, for a stage with the y axis up.
|
|
106
|
+
*
|
|
107
|
+
* A transform has no scale, so each length stays: the size of a point, the width of a run and the cell of a field.
|
|
108
|
+
* A meter has no place, so it stays. Each other part of a mark stays, and the function changes no mark of the list.
|
|
109
|
+
*/
|
|
110
|
+
function transformMarks(marks, transform) {
|
|
111
|
+
return marks.map((mark) => {
|
|
112
|
+
if (mark.type === "point") return {
|
|
113
|
+
...mark,
|
|
114
|
+
frame: transformFrame(mark.frame, transform)
|
|
115
|
+
};
|
|
116
|
+
if (mark.type === "run") return {
|
|
117
|
+
...mark,
|
|
118
|
+
path: mark.path.map((frame) => transformFrame(frame, transform))
|
|
119
|
+
};
|
|
120
|
+
if (mark.type === "link") return {
|
|
121
|
+
...mark,
|
|
122
|
+
from: {
|
|
123
|
+
...mark.from,
|
|
124
|
+
at: transformPoint3(transform, mark.from.at)
|
|
125
|
+
},
|
|
126
|
+
to: {
|
|
127
|
+
...mark.to,
|
|
128
|
+
at: transformPoint3(transform, mark.to.at)
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
if (mark.type === "field") return {
|
|
132
|
+
...mark,
|
|
133
|
+
frame: transformFrame(mark.frame, transform),
|
|
134
|
+
across: rotatePoint3(transform.rotation, mark.across)
|
|
135
|
+
};
|
|
136
|
+
return mark;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
export { transformMarks as a, SHAPE_OUTLINES as c, shapeRing as d, fieldValue as i, levelRank as l, fieldCellCenter as n, LEVELS as o, fieldRowStep as r, LEVEL_SHAPES as s, MARK_TYPES as t, levelShape as u };
|
|
97
140
|
|
|
98
|
-
//# sourceMappingURL=mark-
|
|
141
|
+
//# sourceMappingURL=mark-D9bjgO-y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mark-D9bjgO-y.js","names":[],"sources":["../src/marks/levels.ts","../src/marks/mark.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\n\n/** These are the levels of a mark, from the lowest to the highest. */\nexport const LEVELS: readonly [\"unknown\", \"ok\", \"near\", \"over\"] = [\"unknown\", \"ok\", \"near\", \"over\"];\n\n/**\n * A level of a mark, in the scale of limits. `ok` is below a limit, `near` is near it and `over` is above it.\n * A mark with no known value has `unknown`. The producer of a mark calculates the level, because each topic has its own limits.\n */\nexport type Level = (typeof LEVELS)[number];\n\n/**\n * This function gives the rank of a level: 0 for `unknown` and 3 for `over`.\n * A viewer draws the marks in the sequence of their ranks, so the worst level is always in view.\n */\nexport function levelRank(level: Level): number {\n return LEVELS.indexOf(level);\n}\n\n/** These are the shapes of the sign of a level. */\nexport const LEVEL_SHAPES: readonly [\"ring\", \"disc\", \"triangle\", \"square\"] = [\"ring\", \"disc\", \"triangle\", \"square\"];\n\n/** A shape of the sign of a level. A person who does not see a color reads the level from the shape. */\nexport type LevelShape = (typeof LEVEL_SHAPES)[number];\n\n/**\n * This function gives the shape of the sign of a level: a disc for `ok`, a triangle for `near` and a square for `over`.\n * The level `unknown` has a ring, and so has a record with no level.\n */\nexport function levelShape(level: Level | undefined): LevelShape {\n return level === \"ok\" ? \"disc\" : level === \"near\" ? \"triangle\" : level === \"over\" ? \"square\" : \"ring\";\n}\n\n/** The outline of the sign of a shape, as a regular polygon. A circle is a polygon with 40 sides. */\nexport interface ShapeOutline {\n /** The radius of the circle through the corners, for a disc with the radius 1. */\n readonly radius: number;\n /** The number of the sides. */\n readonly sides: number;\n /** The angle of the first corner, in radians, counter-clockwise from the x axis. */\n readonly start: number;\n /** The radius of the hole of the sign, for a disc with the radius 1. A sign with no hole has 0. */\n readonly hole: number;\n}\n\n/**\n * The outline of the sign of each shape. Each viewer draws the signs from these values, so each viewer shows the same signs.\n * A triangle and a square with the radius of the disc look small, so they are larger.\n */\nexport const SHAPE_OUTLINES: Readonly<Record<LevelShape, ShapeOutline>> = {\n ring: { radius: 1, sides: 40, start: 0, hole: 0.52 },\n disc: { radius: 1, sides: 40, start: 0, hole: 0 },\n triangle: { radius: 1.3, sides: 3, start: Math.PI / 2, hole: 0 },\n square: { radius: 1.25, sides: 4, start: Math.PI / 4, hole: 0 },\n};\n\n/**\n * This function gives the corners of the outline of a sign, counter-clockwise, with the y axis up.\n * The center of the sign is the origin, and `radius` is the radius of a disc.\n */\nexport function shapeRing(shape: LevelShape, radius: number = 1): Ring {\n const outline = SHAPE_OUTLINES[shape];\n return Array.from({ length: outline.sides }, (_, index): readonly [number, number] => {\n const angle = outline.start + (index * 2 * Math.PI) / outline.sides;\n return [radius * outline.radius * Math.cos(angle), radius * outline.radius * Math.sin(angle)];\n });\n}\n","import { addPoints3, cross3, rotatePoint3, scalePoint3, transformPoint3, type Point3, type Transform3 } from \"@mark1russell7/layout-contract\";\nimport type { Level } from \"./levels.ts\";\n\n/** A point of a surface, and the direction out of the surface. */\nexport interface Frame {\n /** The point. */\n readonly at: Point3;\n /** The unit vector out of the surface at the point. */\n readonly out: Point3;\n}\n\n/** These are the types of a mark. */\nexport const MARK_TYPES: readonly [\"point\", \"run\", \"link\", \"field\", \"meter\"] = [\"point\", \"run\", \"link\", \"field\", \"meter\"];\n\n/** A type of a mark. */\nexport type MarkType = (typeof MARK_TYPES)[number];\n\n/**\n * The parts that each mark has. A mark has no shape and no color.\n * A viewer gets the shape from the level, and the color from the level and its theme. Thus a mark does not use color alone.\n */\nexport interface MarkBase {\n /** The name of the record of the mark. The pointer and the selection of a viewer use this name. */\n readonly record: string;\n /** A word of the producer for the legend and the filter, for example `outlet`. */\n readonly kind: string;\n /** The level of the mark. The producer calculates it. */\n readonly level: Level;\n /** One line of text: the name of the mark for a person and for a screen reader. */\n readonly label: string;\n}\n\n/** A mark at one point of a surface, for example an outlet, a tap or a lamp. */\nexport interface PointMark extends MarkBase {\n readonly type: \"point\";\n /** The point, and the direction out of its surface. */\n readonly frame: Frame;\n /** The width of the sign, in the unit of the space. A mark with no size gets the default size of the viewer. */\n readonly size?: number | undefined;\n}\n\n/** A mark along a path on surfaces, for example a cable, a pipe or a duct. */\nexport interface RunMark extends MarkBase {\n readonly type: \"run\";\n /** The points of the path, in sequence. Each point has its own direction, so a run can go across surfaces. A path has 2 or more points. */\n readonly path: readonly Frame[];\n /** The width of the run, in the unit of the space. */\n readonly width: number;\n}\n\n/** One end of a link. */\nexport interface LinkEnd {\n /** The name of the record at this end. A viewer shows the link when the record of one end is selected or under the pointer. */\n readonly record: string;\n /** The point of this end. */\n readonly at: Point3;\n}\n\n/** A mark between two records, for example a power line from an outlet to a computer. */\nexport interface LinkMark extends MarkBase {\n readonly type: \"link\";\n readonly from: LinkEnd;\n readonly to: LinkEnd;\n}\n\n/** The scale of the values of a field. The theme of a viewer gives the colors from `min` to `max`. */\nexport interface FieldScale {\n /** The value of the first color. It is less than `max`. */\n readonly min: number;\n /** The value of the last color. */\n readonly max: number;\n /** The text of the unit of the values, for example `lx`. */\n readonly unit: string;\n}\n\n/** A grid of values on a plane, for example the light on a floor or the heat of a wall. */\nexport interface FieldMark extends MarkBase {\n readonly type: \"field\";\n /** The corner of the first cell, and the direction out of the plane. */\n readonly frame: Frame;\n /** The unit vector of a column step, in the plane. The step of a row is the cross product of `frame.out` and `across`. */\n readonly across: Point3;\n /** The length of a side of a cell, in the unit of the space. */\n readonly cell: number;\n /** The number of the columns. */\n readonly columns: number;\n /** The number of the rows. */\n readonly rows: number;\n /**\n * The values, row by row. The value of the column `c` and the row `r` has the index `r * columns + c`.\n * A cell with no value has `null`, because JSON has no NaN.\n */\n readonly values: readonly (number | null)[];\n readonly scale: FieldScale;\n}\n\n/**\n * A value against a limit, for example the load of a circuit. A meter has no place.\n * A page draws it in a panel, and a 3D view ignores it.\n */\nexport interface MeterMark extends MarkBase {\n readonly type: \"meter\";\n readonly value: number;\n /**\n * The limit of the value. A meter with no limit has no `limit`, for example a circuit with a known load and no known breaker.\n * A page shows only the value and the unit of that meter. A limit of 0 is a real limit, so it is not a sign for no limit.\n */\n readonly limit?: number | undefined;\n /** The text of the unit of the value and of the limit, for example `W`. */\n readonly unit: string;\n}\n\n/**\n * A record that a viewer draws. A mark is plain data with no topic, so it goes through JSON with no change.\n * Each point of a list of marks is in one space. The producer tells the unit and the axes of that space.\n */\nexport type Mark = PointMark | RunMark | LinkMark | FieldMark | MeterMark;\n\n/** This function gives the unit vector of a row step of a field: the cross product of `frame.out` and `across`. */\nexport function fieldRowStep(field: FieldMark): Point3 {\n return cross3(field.frame.out, field.across);\n}\n\n/** This function gives the center of a cell of a field. The first cell has the column 0 and the row 0. */\nexport function fieldCellCenter(field: FieldMark, column: number, row: number): Point3 {\n const across = scalePoint3(field.across, (column + 0.5) * field.cell);\n const down = scalePoint3(fieldRowStep(field), (row + 0.5) * field.cell);\n return addPoints3(field.frame.at, addPoints3(across, down));\n}\n\n/** This function gives the value of a cell of a field. A cell with no value gives `null`, and so does a cell that is not in the grid. */\nexport function fieldValue(field: FieldMark, column: number, row: number): number | null {\n if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;\n return field.values[row * field.columns + column] ?? null;\n}\n\n/** This function gives a frame after a transform. The point gets the transform, and the direction gets only its rotation. */\nfunction transformFrame(frame: Frame, transform: Transform3): Frame {\n return { at: transformPoint3(transform, frame.at), out: rotatePoint3(transform.rotation, frame.out) };\n}\n\n/**\n * This function gives the marks in a different space. Each point gets the transform, and each direction gets only its rotation.\n * An example is the marks of a room with the z axis up, for a stage with the y axis up.\n *\n * A transform has no scale, so each length stays: the size of a point, the width of a run and the cell of a field.\n * A meter has no place, so it stays. Each other part of a mark stays, and the function changes no mark of the list.\n */\nexport function transformMarks(marks: readonly Mark[], transform: Transform3): readonly Mark[] {\n return marks.map((mark): Mark => {\n if (mark.type === \"point\") return { ...mark, frame: transformFrame(mark.frame, transform) };\n if (mark.type === \"run\") return { ...mark, path: mark.path.map((frame) => transformFrame(frame, transform)) };\n if (mark.type === \"link\") {\n return { ...mark, from: { ...mark.from, at: transformPoint3(transform, mark.from.at) }, to: { ...mark.to, at: transformPoint3(transform, mark.to.at) } };\n }\n if (mark.type === \"field\") return { ...mark, frame: transformFrame(mark.frame, transform), across: rotatePoint3(transform.rotation, mark.across) };\n return mark;\n });\n}\n"],"mappings":";;;AAGA,MAAa,SAAqD;CAAC;CAAW;CAAM;CAAQ;AAAM;;;;;AAYlG,SAAgB,UAAU,OAAsB;CAC9C,OAAO,OAAO,QAAQ,KAAK;AAC7B;;AAGA,MAAa,eAAgE;CAAC;CAAQ;CAAQ;CAAY;AAAQ;;;;;AASlH,SAAgB,WAAW,OAAsC;CAC/D,OAAO,UAAU,OAAO,SAAS,UAAU,SAAS,aAAa,UAAU,SAAS,WAAW;AACjG;;;;;AAkBA,MAAa,iBAA6D;CACxE,MAAM;EAAE,QAAQ;EAAG,OAAO;EAAI,OAAO;EAAG,MAAM;CAAK;CACnD,MAAM;EAAE,QAAQ;EAAG,OAAO;EAAI,OAAO;EAAG,MAAM;CAAE;CAChD,UAAU;EAAE,QAAQ;EAAK,OAAO;EAAG,OAAO,KAAK,KAAK;EAAG,MAAM;CAAE;CAC/D,QAAQ;EAAE,QAAQ;EAAM,OAAO;EAAG,OAAO,KAAK,KAAK;EAAG,MAAM;CAAE;AAChE;;;;;AAMA,SAAgB,UAAU,OAAmB,SAAiB,GAAS;CACrE,M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O;GAAE,GAAG;GAAM,MAAM,KAAK,KAAK,KAAK,UAAU,eAAe,OAAO,SAAS,CAAC;EAAE;EAC5G,IAAI,KAAK,SAAS,QAChB,OAAO;GAAE,GAAG;GAAM,MAAM;IAAE,GAAG,KAAK;IAAM,IAAI,gBAAgB,WAAW,KAAK,KAAK,EAAE;GAAE;GAAG,IAAI;IAAE,GAAG,KAAK;IAAI,IAAI,gBAAgB,WAAW,KAAK,GAAG,EAAE;GAAE;EAAE;EAEzJ,IAAI,KAAK,SAAS,SAAS,OAAO;GAAE,GAAG;GAAM,OAAO,eAAe,KAAK,OAAO,SAAS;GAAG,QAAQ,aAAa,UAAU,UAAU,KAAK,MAAM;EAAE;EACjJ,OAAO;CACT,CAAC;AACH"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Point3, Ring } from "@mark1russell7/layout-contract";
|
|
1
|
+
import { Point3, Ring, Transform3 } from "@mark1russell7/layout-contract";
|
|
2
2
|
/** These are the levels of a mark, from the lowest to the highest. */
|
|
3
3
|
declare const LEVELS: readonly ["unknown", "ok", "near", "over"];
|
|
4
4
|
/**
|
|
@@ -150,5 +150,13 @@ declare function fieldRowStep(field: FieldMark): Point3;
|
|
|
150
150
|
declare function fieldCellCenter(field: FieldMark, column: number, row: number): Point3;
|
|
151
151
|
/** This function gives the value of a cell of a field. A cell with no value gives `null`, and so does a cell that is not in the grid. */
|
|
152
152
|
declare function fieldValue(field: FieldMark, column: number, row: number): number | null;
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
/**
|
|
154
|
+
* This function gives the marks in a different space. Each point gets the transform, and each direction gets only its rotation.
|
|
155
|
+
* An example is the marks of a room with the z axis up, for a stage with the y axis up.
|
|
156
|
+
*
|
|
157
|
+
* A transform has no scale, so each length stays: the size of a point, the width of a run and the cell of a field.
|
|
158
|
+
* A meter has no place, so it stays. Each other part of a mark stays, and the function changes no mark of the list.
|
|
159
|
+
*/
|
|
160
|
+
declare function transformMarks(marks: readonly Mark[], transform: Transform3): readonly Mark[];
|
|
161
|
+
export { levelRank as C, ShapeOutline as S, shapeRing as T, LEVELS as _, LinkMark as a, LevelShape as b, MarkBase as c, PointMark as d, RunMark as f, transformMarks as g, fieldValue as h, LinkEnd as i, MarkType as l, fieldRowStep as m, FieldScale as n, MARK_TYPES as o, fieldCellCenter as p, Frame as r, Mark as s, FieldMark as t, MeterMark as u, LEVEL_SHAPES as v, levelShape as w, SHAPE_OUTLINES as x, Level as y };
|
|
162
|
+
//# sourceMappingURL=mark-ubn709Qw.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mark-
|
|
1
|
+
{"version":3,"file":"mark-ubn709Qw.d.ts","names":[],"sources":["../src/marks/levels.ts","../src/marks/mark.ts"],"mappings":";;cAGa;;;;;KAMD,gBAAgB;;;;;iBAMZ,UAAU,OAAO;;cAKpB;;KAGD,qBAAqB;;;;;iBAMjB,WAAW,OAAO,oBAAoB;;UAKrC;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;cAOE,gBAAgB,SAAS,OAAO,YAAY;;;;;iBAWzC,UAAU,OAAO,YAAY,kBAAqB;;UCxDjD;;WAEN,IAAI;;WAEJ,KAAK;;;cAIH;;KAGD,mBAAmB;;;;;UAMd;;WAEN;;WAEA;;WAEA,OAAO;;WAEP;;;UAIM,kBAAkB;WACxB;;WAEA,OAAO;;WAEP;;;UAIM,gBAAgB;WACtB;;WAEA,eAAe;;WAEf;;;UAIM;;WAEN;;WAEA,IAAI;;;UAIE,iBAAiB;WACvB;WACA,MAAM;WACN,IAAI;;;UAIE;;WAEN;;WAEA;;WAEA;;;UAIM,kBAAkB;WACxB;;WAEA,OAAO;;WAEP,QAAQ;;WAER;;WAEA;;WAEA;;;;;WAKA;WACA,OAAO;;;;;;UAOD,kBAAkB;WACxB;WACA;;;;;WAKA;;WAEA;;;;;;KAOC,OAAO,YAAY,UAAU,WAAW,YAAY;;iBAGhD,aAAa,OAAO,YAAY;;iBAKhC,gBAAgB,OAAO,WAAW,gBAAgB,cAAc;;iBAOhE,WAAW,OAAO,WAAW,gBAAgB;;;;;;;;iBAiB7C,eAAe,gBAAgB,QAAQ,WAAW,sBAAsB"}
|
package/build/markers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as Mark,
|
|
1
|
+
import { s as Mark, y as Level } from "./mark-ubn709Qw.js";
|
|
2
2
|
import { r as StageContent } from "./stage-DmFfah2e.js";
|
|
3
3
|
import { t as StageTheme } from "./theme-3EGbXXoP.js";
|
|
4
4
|
/** The colors of the marks of a stage. Each color is a CSS hex color, for example `#22364a`. */
|
package/build/markers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as SHAPE_OUTLINES, i as fieldValue, r as fieldRowStep, u as levelShape } from "./mark-D9bjgO-y.js";
|
|
2
2
|
import "./view-BB_EQx3I.js";
|
|
3
3
|
import { BufferAttribute, BufferGeometry, Color, DataTexture, DoubleSide, InstancedBufferAttribute, InstancedBufferGeometry, Mesh, MeshBasicMaterial, NearestFilter, Plane, RGBAFormat, SRGBColorSpace, ShaderMaterial, UnsignedByteType, Vector3 } from "three";
|
|
4
4
|
// src/markers/content.ts
|
package/build/marks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as levelRank, S as ShapeOutline, T as shapeRing, _ as LEVELS, a as LinkMark, b as LevelShape, c as MarkBase, d as PointMark, f as RunMark, g as transformMarks, h as fieldValue, i as LinkEnd, l as MarkType, m as fieldRowStep, n as FieldScale, o as MARK_TYPES, p as fieldCellCenter, r as Frame, s as Mark, t as FieldMark, u as MeterMark, v as LEVEL_SHAPES, w as levelShape, x as SHAPE_OUTLINES, y as Level } from "./mark-ubn709Qw.js";
|
|
2
2
|
/**
|
|
3
3
|
* These are the codes of the faults of a mark:
|
|
4
4
|
* - `type`: the type of the mark is not known. A list from a later version of a producer can have a new type.
|
|
@@ -41,5 +41,5 @@ export declare const DIRECTION_TOLERANCE = 1e-6;
|
|
|
41
41
|
* It does not examine the form of a mark: read a list from JSON through a schema first.
|
|
42
42
|
*/
|
|
43
43
|
export declare function checkMarks(marks: readonly Mark[]): readonly MarkFault[];
|
|
44
|
-
export { type FieldMark, type FieldScale, type Frame, LEVELS, LEVEL_SHAPES, type Level, type LevelShape, type LinkEnd, type LinkMark, MARK_TYPES, type Mark, type MarkBase, type MarkFault, type MarkFaultCode, type MarkType, type MeterMark, type PointMark, type RunMark, SHAPE_OUTLINES, type ShapeOutline, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing };
|
|
44
|
+
export { type FieldMark, type FieldScale, type Frame, LEVELS, LEVEL_SHAPES, type Level, type LevelShape, type LinkEnd, type LinkMark, MARK_TYPES, type Mark, type MarkBase, type MarkFault, type MarkFaultCode, type MarkType, type MeterMark, type PointMark, type RunMark, SHAPE_OUTLINES, type ShapeOutline, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing, transformMarks };
|
|
45
45
|
//# sourceMappingURL=marks.d.ts.map
|
package/build/marks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as transformMarks, c as SHAPE_OUTLINES, d as shapeRing, i as fieldValue, l as levelRank, n as fieldCellCenter, o as LEVELS, r as fieldRowStep, s as LEVEL_SHAPES, t as MARK_TYPES, u as levelShape } from "./mark-D9bjgO-y.js";
|
|
2
2
|
import { dot3, length3 } from "@mark1russell7/layout-contract";
|
|
3
3
|
// src/marks/check.ts
|
|
4
4
|
/**
|
|
@@ -133,6 +133,6 @@ function checkMarks(marks) {
|
|
|
133
133
|
});
|
|
134
134
|
return faults;
|
|
135
135
|
}
|
|
136
|
-
export { DIRECTION_TOLERANCE, LEVELS, LEVEL_SHAPES, MARK_FAULT_CODES, MARK_TYPES, SHAPE_OUTLINES, checkMarks, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing };
|
|
136
|
+
export { DIRECTION_TOLERANCE, LEVELS, LEVEL_SHAPES, MARK_FAULT_CODES, MARK_TYPES, SHAPE_OUTLINES, checkMarks, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing, transformMarks };
|
|
137
137
|
|
|
138
138
|
//# sourceMappingURL=marks.js.map
|
|
@@ -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,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HLIGHTS, 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": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mark-AZ5AuAIJ.js","names":[],"sources":["../src/marks/levels.ts","../src/marks/mark.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\n\n/** These are the levels of a mark, from the lowest to the highest. */\nexport const LEVELS: readonly [\"unknown\", \"ok\", \"near\", \"over\"] = [\"unknown\", \"ok\", \"near\", \"over\"];\n\n/**\n * A level of a mark, in the scale of limits. `ok` is below a limit, `near` is near it and `over` is above it.\n * A mark with no known value has `unknown`. The producer of a mark calculates the level, because each topic has its own limits.\n */\nexport type Level = (typeof LEVELS)[number];\n\n/**\n * This function gives the rank of a level: 0 for `unknown` and 3 for `over`.\n * A viewer draws the marks in the sequence of their ranks, so the worst level is always in view.\n */\nexport function levelRank(level: Level): number {\n return LEVELS.indexOf(level);\n}\n\n/** These are the shapes of the sign of a level. */\nexport const LEVEL_SHAPES: readonly [\"ring\", \"disc\", \"triangle\", \"square\"] = [\"ring\", \"disc\", \"triangle\", \"square\"];\n\n/** A shape of the sign of a level. A person who does not see a color reads the level from the shape. */\nexport type LevelShape = (typeof LEVEL_SHAPES)[number];\n\n/**\n * This function gives the shape of the sign of a level: a disc for `ok`, a triangle for `near` and a square for `over`.\n * The level `unknown` has a ring, and so has a record with no level.\n */\nexport function levelShape(level: Level | undefined): LevelShape {\n return level === \"ok\" ? \"disc\" : level === \"near\" ? \"triangle\" : level === \"over\" ? \"square\" : \"ring\";\n}\n\n/** The outline of the sign of a shape, as a regular polygon. A circle is a polygon with 40 sides. */\nexport interface ShapeOutline {\n /** The radius of the circle through the corners, for a disc with the radius 1. */\n readonly radius: number;\n /** The number of the sides. */\n readonly sides: number;\n /** The angle of the first corner, in radians, counter-clockwise from the x axis. */\n readonly start: number;\n /** The radius of the hole of the sign, for a disc with the radius 1. A sign with no hole has 0. */\n readonly hole: number;\n}\n\n/**\n * The outline of the sign of each shape. Each viewer draws the signs from these values, so each viewer shows the same signs.\n * A triangle and a square with the radius of the disc look small, so they are larger.\n */\nexport const SHAPE_OUTLINES: Readonly<Record<LevelShape, ShapeOutline>> = {\n ring: { radius: 1, sides: 40, start: 0, hole: 0.52 },\n disc: { radius: 1, sides: 40, start: 0, hole: 0 },\n triangle: { radius: 1.3, sides: 3, start: Math.PI / 2, hole: 0 },\n square: { radius: 1.25, sides: 4, start: Math.PI / 4, hole: 0 },\n};\n\n/**\n * This function gives the corners of the outline of a sign, counter-clockwise, with the y axis up.\n * The center of the sign is the origin, and `radius` is the radius of a disc.\n */\nexport function shapeRing(shape: LevelShape, radius: number = 1): Ring {\n const outline = SHAPE_OUTLINES[shape];\n return Array.from({ length: outline.sides }, (_, index): readonly [number, number] => {\n const angle = outline.start + (index * 2 * Math.PI) / outline.sides;\n return [radius * outline.radius * Math.cos(angle), radius * outline.radius * Math.sin(angle)];\n });\n}\n","import { addPoints3, cross3, scalePoint3, type Point3 } from \"@mark1russell7/layout-contract\";\nimport type { Level } from \"./levels.ts\";\n\n/** A point of a surface, and the direction out of the surface. */\nexport interface Frame {\n /** The point. */\n readonly at: Point3;\n /** The unit vector out of the surface at the point. */\n readonly out: Point3;\n}\n\n/** These are the types of a mark. */\nexport const MARK_TYPES: readonly [\"point\", \"run\", \"link\", \"field\", \"meter\"] = [\"point\", \"run\", \"link\", \"field\", \"meter\"];\n\n/** A type of a mark. */\nexport type MarkType = (typeof MARK_TYPES)[number];\n\n/**\n * The parts that each mark has. A mark has no shape and no color.\n * A viewer gets the shape from the level, and the color from the level and its theme. Thus a mark does not use color alone.\n */\nexport interface MarkBase {\n /** The name of the record of the mark. The pointer and the selection of a viewer use this name. */\n readonly record: string;\n /** A word of the producer for the legend and the filter, for example `outlet`. */\n readonly kind: string;\n /** The level of the mark. The producer calculates it. */\n readonly level: Level;\n /** One line of text: the name of the mark for a person and for a screen reader. */\n readonly label: string;\n}\n\n/** A mark at one point of a surface, for example an outlet, a tap or a lamp. */\nexport interface PointMark extends MarkBase {\n readonly type: \"point\";\n /** The point, and the direction out of its surface. */\n readonly frame: Frame;\n /** The width of the sign, in the unit of the space. A mark with no size gets the default size of the viewer. */\n readonly size?: number | undefined;\n}\n\n/** A mark along a path on surfaces, for example a cable, a pipe or a duct. */\nexport interface RunMark extends MarkBase {\n readonly type: \"run\";\n /** The points of the path, in sequence. Each point has its own direction, so a run can go across surfaces. A path has 2 or more points. */\n readonly path: readonly Frame[];\n /** The width of the run, in the unit of the space. */\n readonly width: number;\n}\n\n/** One end of a link. */\nexport interface LinkEnd {\n /** The name of the record at this end. A viewer shows the link when the record of one end is selected or under the pointer. */\n readonly record: string;\n /** The point of this end. */\n readonly at: Point3;\n}\n\n/** A mark between two records, for example a power line from an outlet to a computer. */\nexport interface LinkMark extends MarkBase {\n readonly type: \"link\";\n readonly from: LinkEnd;\n readonly to: LinkEnd;\n}\n\n/** The scale of the values of a field. The theme of a viewer gives the colors from `min` to `max`. */\nexport interface FieldScale {\n /** The value of the first color. It is less than `max`. */\n readonly min: number;\n /** The value of the last color. */\n readonly max: number;\n /** The text of the unit of the values, for example `lx`. */\n readonly unit: string;\n}\n\n/** A grid of values on a plane, for example the light on a floor or the heat of a wall. */\nexport interface FieldMark extends MarkBase {\n readonly type: \"field\";\n /** The corner of the first cell, and the direction out of the plane. */\n readonly frame: Frame;\n /** The unit vector of a column step, in the plane. The step of a row is the cross product of `frame.out` and `across`. */\n readonly across: Point3;\n /** The length of a side of a cell, in the unit of the space. */\n readonly cell: number;\n /** The number of the columns. */\n readonly columns: number;\n /** The number of the rows. */\n readonly rows: number;\n /**\n * The values, row by row. The value of the column `c` and the row `r` has the index `r * columns + c`.\n * A cell with no value has `null`, because JSON has no NaN.\n */\n readonly values: readonly (number | null)[];\n readonly scale: FieldScale;\n}\n\n/**\n * A value against a limit, for example the load of a circuit. A meter has no place.\n * A page draws it in a panel, and a 3D view ignores it.\n */\nexport interface MeterMark extends MarkBase {\n readonly type: \"meter\";\n readonly value: number;\n /**\n * The limit of the value. A meter with no limit has no `limit`, for example a circuit with a known load and no known breaker.\n * A page shows only the value and the unit of that meter. A limit of 0 is a real limit, so it is not a sign for no limit.\n */\n readonly limit?: number | undefined;\n /** The text of the unit of the value and of the limit, for example `W`. */\n readonly unit: string;\n}\n\n/**\n * A record that a viewer draws. A mark is plain data with no topic, so it goes through JSON with no change.\n * Each point of a list of marks is in one space. The producer tells the unit and the axes of that space.\n */\nexport type Mark = PointMark | RunMark | LinkMark | FieldMark | MeterMark;\n\n/** This function gives the unit vector of a row step of a field: the cross product of `frame.out` and `across`. */\nexport function fieldRowStep(field: FieldMark): Point3 {\n return cross3(field.frame.out, field.across);\n}\n\n/** This function gives the center of a cell of a field. The first cell has the column 0 and the row 0. */\nexport function fieldCellCenter(field: FieldMark, column: number, row: number): Point3 {\n const across = scalePoint3(field.across, (column + 0.5) * field.cell);\n const down = scalePoint3(fieldRowStep(field), (row + 0.5) * field.cell);\n return addPoints3(field.frame.at, addPoints3(across, down));\n}\n\n/** This function gives the value of a cell of a field. A cell with no value gives `null`, and so does a cell that is not in the grid. */\nexport function fieldValue(field: FieldMark, column: number, row: number): number | null {\n if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;\n return field.values[row * field.columns + column] ?? null;\n}\n"],"mappings":";;;AAGA,MAAa,SAAqD;CAAC;CAAW;CAAM;CAAQ;AAAM;;;;;AAYlG,SAAgB,UAAU,OAAsB;CAC9C,OAAO,OAAO,QAAQ,KAAK;AAC7B;;AAGA,MAAa,eAAgE;CAAC;CAAQ;CAAQ;CAAY;AAAQ;;;;;AASlH,SAAgB,WAAW,OAAsC;CAC/D,OAAO,UAAU,OAAO,SAAS,UAAU,SAAS,aAAa,UAAU,SAAS,WAAW;AACjG;;;;;AAkBA,MAAa,iBAA6D;CACxE,MAAM;EAAE,QAAQ;EAAG,OAAO;EAAI,OAAO;EAAG,MAAM;CAAK;CACnD,MAAM;EAAE,QAAQ;EAAG,OAAO;EAAI,OAAO;EAAG,MAAM;CAAE;CAChD,UAAU;EAAE,QAAQ;EAAK,OAAO;EAAG,OAAO,KAAK,KAAK;EAAG,MAAM;CAAE;CAC/D,QAAQ;EAAE,QAAQ;EAAM,OAAO;EAAG,OAAO,KAAK,KAAK;EAAG,MAAM;CAAE;AAChE;;;;;AAMA,SAAgB,UAAU,OAAmB,SAAiB,GAAS;CACrE,MAAM,UAAU,eAAe;CAC/B,OAAO,MAAM,KAAK,EAAE,QAAQ,QAAQ,MAAM,IAAI,GAAG,UAAqC;EACpF,MAAM,QAAQ,QAAQ,QAAS,QAAQ,IAAI,KAAK,KAAM,QAAQ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