@mark1russell7/visuals 0.2.0 → 0.2.2
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 +147 -3
- package/build/globe.d.ts +5 -0
- package/build/globe.d.ts.map +1 -1
- package/build/globe.js +8 -1
- package/build/globe.js.map +1 -1
- package/build/index.d.ts +13 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -1
- package/build/labels.d.ts +115 -0
- package/build/labels.d.ts.map +1 -0
- package/build/labels.js +251 -0
- package/build/labels.js.map +1 -0
- package/build/replay-DvGYPe7T.d.ts +95 -0
- package/build/replay-DvGYPe7T.d.ts.map +1 -0
- package/build/replay-YdWMyFko.js +172 -0
- package/build/replay-YdWMyFko.js.map +1 -0
- package/build/screen-DeOx4_90.js +29 -0
- package/build/screen-DeOx4_90.js.map +1 -0
- package/build/scrubber.d.ts +93 -0
- package/build/scrubber.d.ts.map +1 -0
- package/build/scrubber.js +265 -0
- package/build/scrubber.js.map +1 -0
- package/build/three.d.ts +13 -1
- package/build/three.d.ts.map +1 -0
- package/build/three.js +38 -1
- package/build/three.js.map +1 -1
- package/package.json +20 -4
- package/styles/labels.css +88 -0
- package/styles/scrubber.css +289 -0
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { A as turnBetween, C as ViewAxes, D as fitDistance, E as clampPlace, M as viewOf, O as placeBetween, S as ViewAngles, T as capDistance, _ as reachOf, a as NO_HIGHLIGHTS, b as Place, c as FIT_MARGIN, d as StageView, f as ViewFrame, g as nearDepth, h as fitView, i as Highlights, j as viewAxes, k as speedAt, l as StageExtent, m as capView, n as CLICK_DISTANCE, o as highlightOf, p as ballView, r as Highlight, s as isClick, t as StageTheme, u as StageLimits, v as stageLimits, w as cameraPosition, x as PlaceLimits, y as surfaceOf } from "./theme-CKXd_emk.js";
|
|
2
|
+
import { C as spanPart, S as spanOfTimes, _ as replayPause, a as REPLAY_STEP, b as replaySpan, c as changeAfter, d as changeTimes, f as isLive, g as replayOf, h as replayNextSpeed, i as REPLAY_SPEEDS, l as changeBefore, m as replayKey, n as REPLAY_DURATION, o as Replay, p as replayAdvance, r as REPLAY_PAGE, s as TimeSpan, t as Lifetime, u as changeIndex, v as replayPlay, w as spanTime, x as replayToggle, y as replaySeek } from "./replay-DvGYPe7T.js";
|
|
3
|
+
import { Point, Point3 } from "@mark1russell7/layout-contract";
|
|
2
4
|
/** The angle of one step of an arrow key, in radians, for a camera far from the surface. */
|
|
3
5
|
export declare const KEY_TURN: number;
|
|
4
6
|
/** The factor of the height of a camera above the surface for one step of the key `+`. */
|
|
@@ -60,5 +62,15 @@ export declare function moveAt(move: Move, now: number, surface?: number): MoveS
|
|
|
60
62
|
* 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.
|
|
61
63
|
*/
|
|
62
64
|
export declare function approach(value: number, goal: number, seconds: number, time: number, snap?: number): number;
|
|
63
|
-
|
|
65
|
+
/**
|
|
66
|
+
* This function gives the point of a picture that shows a point of the world, in CSS pixels from the top left corner.
|
|
67
|
+
* It gives `undefined` for a point that is not in front of a camera with perspective.
|
|
68
|
+
*
|
|
69
|
+
* - `view` is the matrix from the world to the camera: `matrixWorldInverse.elements` of a three.js camera.
|
|
70
|
+
* - `projection` is the matrix of the lens of the camera: `projectionMatrix.elements` of a three.js camera.
|
|
71
|
+
* - Each matrix has 16 numbers, one column after the other. This is the sequence of three.js and of WebGL.
|
|
72
|
+
* - A point to the side of the picture gives a position out of the picture. The function does not remove it.
|
|
73
|
+
*/
|
|
74
|
+
export declare function screenPoint(point: Point3, view: ArrayLike<number>, projection: ArrayLike<number>, width: number, height: number): Point | undefined;
|
|
75
|
+
export { CLICK_DISTANCE, FIT_MARGIN, type Highlight, type Highlights, type KeyAction, type KeyOptions, type Lifetime, type Move, type MoveStep, NO_HIGHLIGHTS, type Place, type PlaceLimits, REPLAY_DURATION, REPLAY_PAGE, REPLAY_SPEEDS, REPLAY_STEP, type Replay, type StageExtent, type StageLimits, type StageTheme, type StageView, type TimeSpan, type ViewAngles, type ViewAxes, type ViewFrame, ballView, cameraPosition, capDistance, capView, changeAfter, changeBefore, changeIndex, changeTimes, clampPlace, fitDistance, fitView, highlightOf, isClick, isLive, nearDepth, placeBetween, reachOf, replayAdvance, replayKey, replayNextSpeed, replayOf, replayPause, replayPlay, replaySeek, replaySpan, replayToggle, spanOfTimes, spanPart, spanTime, speedAt, stageLimits, surfaceOf, turnBetween, viewAxes, viewOf };
|
|
64
76
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/keys.ts","../src/motion.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/keys.ts","../src/motion.ts","../src/screen.ts"],"mappings":";;;;qBAGa;;qBAGA;;KAGD;WAAuB;WAAwB,OAAO;;WAAqB;WAAuB;;;UAG7F;;WAEN;;WAEA,QAAQ,SAAS;;WAEjB;;;;;;;;;wBAUK,UAAU,aAAa,KAAK,OAAO,SAAS,aAAa;;UCzBxD;WACN,MAAM;WACN,IAAI;;WAEJ;;WAEA;;;UAIM;WACN,OAAO;;WAEP;;;;;;wBAOK,UAAU;;;;;wBASV,OAAO,MAAM,MAAM,aAAa,mBAAsB;;;;;;;wBAYtD,SAAS,eAAe,cAAc,iBAAiB,cAAc;;;;;;;;;;wBC5BrE,YAAY,OAAO,QAAQ,MAAM,mBAAmB,YAAY,mBAAmB,eAAe,iBAAiB"}
|
package/build/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { _ as viewOf, a as nearDepth, c as surfaceOf, d as clampPlace, f as fitDistance, g as viewAxes, h as turnBetween, i as fitView, l as cameraPosition, m as speedAt, n as ballView, o as reachOf, p as placeBetween, r as capView, s as stageLimits, t as FIT_MARGIN, u as capDistance } from "./extent-CALhBZU-.js";
|
|
2
2
|
import { a as NO_HIGHLIGHTS, c as KEY_TURN, i as CLICK_DISTANCE, l as KEY_ZOOM, n as easeInOut, o as highlightOf, r as moveAt, s as isClick, t as approach, u as keyAction } from "./motion-0tsT6sY4.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
|
+
import { t as screenPoint } from "./screen-DeOx4_90.js";
|
|
5
|
+
export { CLICK_DISTANCE, FIT_MARGIN, KEY_TURN, KEY_ZOOM, NO_HIGHLIGHTS, REPLAY_DURATION, REPLAY_PAGE, REPLAY_SPEEDS, REPLAY_STEP, approach, ballView, cameraPosition, capDistance, capView, changeAfter, changeBefore, changeIndex, changeTimes, clampPlace, easeInOut, fitDistance, fitView, highlightOf, isClick, isLive, keyAction, moveAt, nearDepth, placeBetween, reachOf, replayAdvance, replayKey, replayNextSpeed, replayOf, replayPause, replayPlay, replaySeek, replaySpan, replayToggle, screenPoint, spanOfTimes, spanPart, spanTime, speedAt, stageLimits, surfaceOf, turnBetween, viewAxes, viewOf };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { i as StageContent } from "./stage-CtWLSoV-.js";
|
|
2
|
+
import { Point3, Rect } from "@mark1russell7/layout-contract";
|
|
3
|
+
/**
|
|
4
|
+
* The side of an anchor that the text of a label is on.
|
|
5
|
+
* `center` puts the middle of the text on the anchor. Use it for the name of an area.
|
|
6
|
+
*/
|
|
7
|
+
type LabelSide = "right" | "left" | "above" | "below" | "center";
|
|
8
|
+
/** The default sides of a label, in the sequence in which `placeLabels` tries them. */
|
|
9
|
+
export declare const LABEL_SIDES: readonly LabelSide[];
|
|
10
|
+
/** The default distance between the mark of an anchor and the text of its label, in CSS pixels. */
|
|
11
|
+
export declare const LABEL_GAP = 4;
|
|
12
|
+
/**
|
|
13
|
+
* One label for `placeLabels`: its anchor in a picture, and the size of its text.
|
|
14
|
+
* Each length is in CSS pixels. A position is from the top left corner of the picture.
|
|
15
|
+
*/
|
|
16
|
+
interface LabelAnchor {
|
|
17
|
+
/** The position of the anchor: the point of the picture that the label names. */
|
|
18
|
+
readonly x: number;
|
|
19
|
+
readonly y: number;
|
|
20
|
+
/** The width of the text. */
|
|
21
|
+
readonly width: number;
|
|
22
|
+
/** The height of the text. */
|
|
23
|
+
readonly height: number;
|
|
24
|
+
/**
|
|
25
|
+
* The radius of the mark at the anchor, for example a half of the width of a dot. The default is 0: the anchor has no mark.
|
|
26
|
+
* No text is on the square around a mark.
|
|
27
|
+
*/
|
|
28
|
+
readonly clear?: number | undefined;
|
|
29
|
+
/** The sides that the text can have, in the sequence of the tries. The default is `LABEL_SIDES`. */
|
|
30
|
+
readonly sides?: readonly LabelSide[] | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The picture that the labels are in. Each length is in CSS pixels. */
|
|
33
|
+
interface LabelFrame {
|
|
34
|
+
readonly width: number;
|
|
35
|
+
readonly height: number;
|
|
36
|
+
/** The distance between a mark and the text of its label. The default is `LABEL_GAP`. */
|
|
37
|
+
readonly gap?: number | undefined;
|
|
38
|
+
/** The smallest distance between a text and an edge of the picture. The default is 0. */
|
|
39
|
+
readonly edge?: number | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The place of the text of a label: its side, and its rectangle in the picture. */
|
|
42
|
+
interface LabelPlace {
|
|
43
|
+
readonly side: LabelSide;
|
|
44
|
+
readonly box: Rect;
|
|
45
|
+
}
|
|
46
|
+
/** This function gives the rectangle of the text of a label on one side of its anchor. `gap` is the distance between the mark and the text. */
|
|
47
|
+
export declare function labelBox(label: LabelAnchor, side: LabelSide, gap?: number): Rect;
|
|
48
|
+
/**
|
|
49
|
+
* This function gives each label a place for its text, or `undefined` for a label that the picture does not show.
|
|
50
|
+
* The result has one value for each label, in the sequence of the labels.
|
|
51
|
+
*
|
|
52
|
+
* - The first label has the first choice. Thus give the labels from the most important to the least important.
|
|
53
|
+
* - A label tries its sides in sequence. It takes the first side on which its text is in the picture and on no other text and on no mark.
|
|
54
|
+
* - A label with no free side is not in the picture. A label that comes later does not move a label that has a place.
|
|
55
|
+
* - A label with an anchor out of the picture, or with a text of no size, is not in the picture. Its mark continues to keep the texts away.
|
|
56
|
+
*
|
|
57
|
+
* The function compares each label with each other label. It is for some hundreds of labels.
|
|
58
|
+
*/
|
|
59
|
+
export declare function placeLabels(labels: readonly LabelAnchor[], frame: LabelFrame): (LabelPlace | undefined)[];
|
|
60
|
+
/** A label of a stage: a short text next to a point of the world. */
|
|
61
|
+
interface StageLabel {
|
|
62
|
+
/** The name of the record that the label names. The label gets the highlight of this record. */
|
|
63
|
+
readonly record: string;
|
|
64
|
+
/** The point of the world that the label names. */
|
|
65
|
+
readonly at: Point3;
|
|
66
|
+
readonly text: string;
|
|
67
|
+
/** The kind of the label. The element of the label has it in `data-kind`, so a style sheet gives each kind a look. */
|
|
68
|
+
readonly kind?: string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* The importance of the label. When two texts cannot be in the picture together, the label with the higher rank stays.
|
|
71
|
+
* The default is 0. A label of a highlighted record is before each other label.
|
|
72
|
+
*/
|
|
73
|
+
readonly rank?: number | undefined;
|
|
74
|
+
/** The radius of the mark at the point, in CSS pixels, for example a half of the width of a dot. The default is 0. */
|
|
75
|
+
readonly clear?: number | undefined;
|
|
76
|
+
/** The sides that the text can have, in the sequence of the tries. The default is `LABEL_SIDES`. Use `["center"]` for the name of an area. */
|
|
77
|
+
readonly sides?: readonly LabelSide[] | undefined;
|
|
78
|
+
}
|
|
79
|
+
/** The options of a layer of labels. */
|
|
80
|
+
interface LabelsOptions {
|
|
81
|
+
readonly labels: readonly StageLabel[];
|
|
82
|
+
/**
|
|
83
|
+
* This function tells if the camera sees a point of the world from its position.
|
|
84
|
+
* For a globe, use `inSight`: a point on the far side of the Earth then has no label. The default shows each point.
|
|
85
|
+
*/
|
|
86
|
+
readonly visible?: ((at: Point3, eye: Point3) => boolean) | undefined;
|
|
87
|
+
/** The distance between a mark and the text of its label, in CSS pixels. The default is `LABEL_GAP`. */
|
|
88
|
+
readonly gap?: number | undefined;
|
|
89
|
+
/** The smallest distance between a text and an edge of the picture, in CSS pixels. The default is 0. */
|
|
90
|
+
readonly edge?: number | undefined;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A layer of labels: a content of a stage with no three.js object. Use `stackContents` to show it with the content that it names.
|
|
94
|
+
* The layer has no pick: the pointer goes through each text to the picture.
|
|
95
|
+
*/
|
|
96
|
+
interface LabelsContent extends StageContent<never> {
|
|
97
|
+
/** The element of the layer. It is in the container. */
|
|
98
|
+
readonly element: HTMLElement;
|
|
99
|
+
/** This function shows the labels that a test accepts, and it removes the other labels from the picture. */
|
|
100
|
+
show(test: (label: StageLabel) => boolean): void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* This function makes a layer of labels in a container of a page. The style sheet `@mark1russell7/visuals/labels.css` draws it.
|
|
104
|
+
*
|
|
105
|
+
* - Use the container of the stage, and give it `position: relative`. The layer then fills the picture, above the canvas.
|
|
106
|
+
* - Each label is an HTML element, so its text is sharp at each size and it uses the font of the page.
|
|
107
|
+
* - Before each picture, the layer puts each text next to its point. `placeLabels` keeps each text off each other text and off each mark.
|
|
108
|
+
* - The places are a function of the picture: after a move of the camera, each label tries its sides from the first side.
|
|
109
|
+
* - While the picture does not move, a label keeps its side. So a highlight or a change of `show` moves no other text.
|
|
110
|
+
* - The layer writes no inline style attribute. It sets each position through the CSS object model, so a strict content security policy permits it.
|
|
111
|
+
* - A screen reader ignores the layer. Give the names of the records in the page, for example in a list.
|
|
112
|
+
*/
|
|
113
|
+
export declare function createLabels(container: HTMLElement, options: LabelsOptions): LabelsContent;
|
|
114
|
+
export type { LabelAnchor, LabelFrame, LabelPlace, LabelSide, LabelsContent, LabelsOptions, StageLabel };
|
|
115
|
+
//# sourceMappingURL=labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.d.ts","names":[],"sources":["../src/labels/place.ts","../src/labels/layer.ts"],"mappings":";;;;;;KAMY;;qBAGC,sBAAsB;;qBAGtB;;;;;UAMI;;WAEN;WACA;;WAEA;;WAEA;;;;;WAKA;;WAEA,iBAAiB;;;UAIX;WACN;WACA;;WAEA;;WAEA;;;UAIM;WACN,MAAM;WACN,KAAK;;;wBAIA,SAAS,OAAO,aAAa,MAAM,WAAW,eAA0B;;;;;;;;;;;;wBA+BxE,YAAY,iBAAiB,eAAe,OAAO,cAAc;;UC3EhE;;WAEN;;WAEA,IAAI;WACJ;;WAEA;;;;;WAKA;;WAEA;;WAEA,iBAAiB;;;UAIX;WACN,iBAAiB;;;;;WAKjB,YAAY,IAAI,QAAQ,KAAK;;WAE7B;;WAEA;;;;;;UAOM,sBAAsB;;WAE5B,SAAS;;EAElB,KAAK,OAAO,OAAO;;;;;;;;;;;;;wBA4CL,aAAa,WAAW,aAAa,SAAS,gBAAgB"}
|
package/build/labels.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { t as screenPoint } from "./screen-DeOx4_90.js";
|
|
2
|
+
import { overlapOf } from "@mark1russell7/layout-contract";
|
|
3
|
+
// src/labels/place.ts
|
|
4
|
+
/** The default sides of a label, in the sequence in which `placeLabels` tries them. */
|
|
5
|
+
const LABEL_SIDES = [
|
|
6
|
+
"right",
|
|
7
|
+
"left",
|
|
8
|
+
"above",
|
|
9
|
+
"below"
|
|
10
|
+
];
|
|
11
|
+
/** The default distance between the mark of an anchor and the text of its label, in CSS pixels. */
|
|
12
|
+
const LABEL_GAP = 4;
|
|
13
|
+
/** This function gives the rectangle of the text of a label on one side of its anchor. `gap` is the distance between the mark and the text. */
|
|
14
|
+
function labelBox(label, side, gap = 4) {
|
|
15
|
+
const { width: w, height: h } = label;
|
|
16
|
+
const reach = (label.clear ?? 0) + gap;
|
|
17
|
+
return {
|
|
18
|
+
x: side === "right" ? label.x + reach : side === "left" ? label.x - reach - w : label.x - w / 2,
|
|
19
|
+
y: side === "below" ? label.y + reach : side === "above" ? label.y - reach - h : label.y - h / 2,
|
|
20
|
+
w,
|
|
21
|
+
h
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** This function tells if the insides of two rectangles overlap. Two rectangles with a common edge do not overlap. */
|
|
25
|
+
function overlaps(a, b) {
|
|
26
|
+
const overlap = overlapOf(a, b);
|
|
27
|
+
return overlap.x > 0 && overlap.y > 0;
|
|
28
|
+
}
|
|
29
|
+
/** This function gives the square around the mark of an anchor, or `undefined` for an anchor with no mark. */
|
|
30
|
+
function markOf(label) {
|
|
31
|
+
const clear = label.clear ?? 0;
|
|
32
|
+
return clear > 0 ? {
|
|
33
|
+
x: label.x - clear,
|
|
34
|
+
y: label.y - clear,
|
|
35
|
+
w: 2 * clear,
|
|
36
|
+
h: 2 * clear
|
|
37
|
+
} : void 0;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* This function gives each label a place for its text, or `undefined` for a label that the picture does not show.
|
|
41
|
+
* The result has one value for each label, in the sequence of the labels.
|
|
42
|
+
*
|
|
43
|
+
* - The first label has the first choice. Thus give the labels from the most important to the least important.
|
|
44
|
+
* - A label tries its sides in sequence. It takes the first side on which its text is in the picture and on no other text and on no mark.
|
|
45
|
+
* - A label with no free side is not in the picture. A label that comes later does not move a label that has a place.
|
|
46
|
+
* - A label with an anchor out of the picture, or with a text of no size, is not in the picture. Its mark continues to keep the texts away.
|
|
47
|
+
*
|
|
48
|
+
* The function compares each label with each other label. It is for some hundreds of labels.
|
|
49
|
+
*/
|
|
50
|
+
function placeLabels(labels, frame) {
|
|
51
|
+
const gap = frame.gap ?? 4;
|
|
52
|
+
const edge = frame.edge ?? 0;
|
|
53
|
+
const marks = labels.map(markOf);
|
|
54
|
+
const texts = [];
|
|
55
|
+
return labels.map((label, index) => {
|
|
56
|
+
if (!(label.width > 0 && label.height > 0)) return void 0;
|
|
57
|
+
if (!(label.x >= 0 && label.x <= frame.width && label.y >= 0 && label.y <= frame.height)) return void 0;
|
|
58
|
+
for (const side of label.sides ?? LABEL_SIDES) {
|
|
59
|
+
const box = labelBox(label, side, gap);
|
|
60
|
+
if (!(box.x >= edge && box.y >= edge && box.x + box.w <= frame.width - edge && box.y + box.h <= frame.height - edge)) continue;
|
|
61
|
+
if (texts.some((text) => overlaps(box, text))) continue;
|
|
62
|
+
if (marks.some((mark, other) => mark !== void 0 && other !== index && overlaps(box, mark))) continue;
|
|
63
|
+
texts.push(box);
|
|
64
|
+
return {
|
|
65
|
+
side,
|
|
66
|
+
box
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// src/labels/layer.ts
|
|
72
|
+
/** This function gives the space that labels fill: each point, around the middle of the points. */
|
|
73
|
+
function extentOf(labels) {
|
|
74
|
+
const count = Math.max(labels.length, 1);
|
|
75
|
+
const sum = labels.reduce((to, label) => ({
|
|
76
|
+
x: to.x + label.at.x,
|
|
77
|
+
y: to.y + label.at.y,
|
|
78
|
+
z: to.z + label.at.z
|
|
79
|
+
}), {
|
|
80
|
+
x: 0,
|
|
81
|
+
y: 0,
|
|
82
|
+
z: 0
|
|
83
|
+
});
|
|
84
|
+
const center = {
|
|
85
|
+
x: sum.x / count,
|
|
86
|
+
y: sum.y / count,
|
|
87
|
+
z: sum.z / count
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
center,
|
|
91
|
+
corners: labels.length === 0 ? [center] : labels.map((label) => label.at)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* This function makes a layer of labels in a container of a page. The style sheet `@mark1russell7/visuals/labels.css` draws it.
|
|
96
|
+
*
|
|
97
|
+
* - Use the container of the stage, and give it `position: relative`. The layer then fills the picture, above the canvas.
|
|
98
|
+
* - Each label is an HTML element, so its text is sharp at each size and it uses the font of the page.
|
|
99
|
+
* - Before each picture, the layer puts each text next to its point. `placeLabels` keeps each text off each other text and off each mark.
|
|
100
|
+
* - The places are a function of the picture: after a move of the camera, each label tries its sides from the first side.
|
|
101
|
+
* - While the picture does not move, a label keeps its side. So a highlight or a change of `show` moves no other text.
|
|
102
|
+
* - The layer writes no inline style attribute. It sets each position through the CSS object model, so a strict content security policy permits it.
|
|
103
|
+
* - A screen reader ignores the layer. Give the names of the records in the page, for example in a list.
|
|
104
|
+
*/
|
|
105
|
+
function createLabels(container, options) {
|
|
106
|
+
const page = container.ownerDocument;
|
|
107
|
+
const visible = options.visible;
|
|
108
|
+
const records = new Set(options.labels.map((label) => label.record));
|
|
109
|
+
let width = 0;
|
|
110
|
+
let height = 0;
|
|
111
|
+
const element = page.createElement("div");
|
|
112
|
+
element.className = "visuals-labels";
|
|
113
|
+
element.setAttribute("aria-hidden", "true");
|
|
114
|
+
const parts = options.labels.map((label, index) => {
|
|
115
|
+
const text = page.createElement("span");
|
|
116
|
+
text.className = "visuals-label visuals-label-off";
|
|
117
|
+
if (label.kind !== void 0) text.dataset["kind"] = label.kind;
|
|
118
|
+
text.textContent = label.text;
|
|
119
|
+
element.append(text);
|
|
120
|
+
return {
|
|
121
|
+
label,
|
|
122
|
+
index,
|
|
123
|
+
element: text,
|
|
124
|
+
width: 0,
|
|
125
|
+
height: 0,
|
|
126
|
+
shown: true,
|
|
127
|
+
highlight: 0,
|
|
128
|
+
point: void 0,
|
|
129
|
+
side: void 0,
|
|
130
|
+
on: false,
|
|
131
|
+
left: NaN,
|
|
132
|
+
top: NaN
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
const partOf = new Map(parts.map((part) => [part.element, part]));
|
|
136
|
+
/** This function puts one text at its place, or removes it from the picture. It changes the page only for a new value. */
|
|
137
|
+
const put = (part, place) => {
|
|
138
|
+
if (place === void 0) {
|
|
139
|
+
if (part.on) part.element.classList.add("visuals-label-off");
|
|
140
|
+
part.on = false;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const left = Math.round(place.box.x);
|
|
144
|
+
const top = Math.round(place.box.y);
|
|
145
|
+
if (left !== part.left || top !== part.top) {
|
|
146
|
+
part.left = left;
|
|
147
|
+
part.top = top;
|
|
148
|
+
part.element.style.transform = `translate(${String(left)}px, ${String(top)}px)`;
|
|
149
|
+
}
|
|
150
|
+
if (place.side !== part.side) {
|
|
151
|
+
part.side = place.side;
|
|
152
|
+
part.element.dataset["side"] = place.side;
|
|
153
|
+
}
|
|
154
|
+
if (!part.on) part.element.classList.remove("visuals-label-off");
|
|
155
|
+
part.on = true;
|
|
156
|
+
};
|
|
157
|
+
/** This function gives the sides of a label, with its last side first. */
|
|
158
|
+
const sidesOf = (part) => {
|
|
159
|
+
const sides = part.label.sides ?? LABEL_SIDES;
|
|
160
|
+
const last = part.side;
|
|
161
|
+
return last === void 0 || sides[0] === last || !sides.includes(last) ? sides : [last, ...sides.filter((side) => side !== last)];
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* This function gives each text its place from the anchors of the last picture.
|
|
165
|
+
* `fresh` is true after a move of the picture: each label then tries its sides from the first side.
|
|
166
|
+
*/
|
|
167
|
+
const layout = (fresh) => {
|
|
168
|
+
const live = parts.filter((part) => part.shown && part.point !== void 0);
|
|
169
|
+
live.sort((a, b) => b.highlight - a.highlight || (b.label.rank ?? 0) - (a.label.rank ?? 0) || a.index - b.index);
|
|
170
|
+
const places = placeLabels(live.map((part) => ({
|
|
171
|
+
x: part.point?.x ?? 0,
|
|
172
|
+
y: part.point?.y ?? 0,
|
|
173
|
+
width: part.width,
|
|
174
|
+
height: part.height,
|
|
175
|
+
clear: part.label.clear,
|
|
176
|
+
sides: fresh ? part.label.sides : sidesOf(part)
|
|
177
|
+
})), {
|
|
178
|
+
width,
|
|
179
|
+
height,
|
|
180
|
+
gap: options.gap,
|
|
181
|
+
edge: options.edge
|
|
182
|
+
});
|
|
183
|
+
const placed = /* @__PURE__ */ new Set();
|
|
184
|
+
live.forEach((part, at) => {
|
|
185
|
+
placed.add(part);
|
|
186
|
+
put(part, places[at]);
|
|
187
|
+
});
|
|
188
|
+
for (const part of parts) if (!placed.has(part)) put(part, void 0);
|
|
189
|
+
};
|
|
190
|
+
const observer = new ResizeObserver((entries) => {
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
const part = partOf.get(entry.target);
|
|
193
|
+
const size = entry.borderBoxSize[0];
|
|
194
|
+
if (part === void 0 || size === void 0) continue;
|
|
195
|
+
part.width = size.inlineSize;
|
|
196
|
+
part.height = size.blockSize;
|
|
197
|
+
}
|
|
198
|
+
layout(false);
|
|
199
|
+
});
|
|
200
|
+
for (const part of parts) observer.observe(part.element);
|
|
201
|
+
container.append(element);
|
|
202
|
+
return {
|
|
203
|
+
element,
|
|
204
|
+
objects: [],
|
|
205
|
+
extent: extentOf(options.labels),
|
|
206
|
+
has: (record) => records.has(record),
|
|
207
|
+
pick: () => void 0,
|
|
208
|
+
paint(_theme, highlight) {
|
|
209
|
+
let changed = false;
|
|
210
|
+
for (const part of parts) {
|
|
211
|
+
const next = highlight(part.label.record);
|
|
212
|
+
if (next === part.highlight) continue;
|
|
213
|
+
part.highlight = next;
|
|
214
|
+
part.element.classList.toggle("visuals-label-hovered", next === 1);
|
|
215
|
+
part.element.classList.toggle("visuals-label-selected", next === 2);
|
|
216
|
+
changed = true;
|
|
217
|
+
}
|
|
218
|
+
if (changed) layout(false);
|
|
219
|
+
},
|
|
220
|
+
step(frame) {
|
|
221
|
+
const { camera } = frame;
|
|
222
|
+
camera.updateMatrixWorld();
|
|
223
|
+
const nextHeight = frame.height;
|
|
224
|
+
const nextWidth = frame.height * camera.aspect;
|
|
225
|
+
let moved = nextWidth !== width || nextHeight !== height;
|
|
226
|
+
width = nextWidth;
|
|
227
|
+
height = nextHeight;
|
|
228
|
+
const view = camera.matrixWorldInverse.elements;
|
|
229
|
+
const projection = camera.projectionMatrix.elements;
|
|
230
|
+
for (const part of parts) {
|
|
231
|
+
const { at } = part.label;
|
|
232
|
+
const point = visible === void 0 || visible(at, camera.position) ? screenPoint(at, view, projection, width, height) : void 0;
|
|
233
|
+
if (point?.x !== part.point?.x || point?.y !== part.point?.y) moved = true;
|
|
234
|
+
part.point = point;
|
|
235
|
+
}
|
|
236
|
+
layout(moved);
|
|
237
|
+
return false;
|
|
238
|
+
},
|
|
239
|
+
show(test) {
|
|
240
|
+
for (const part of parts) part.shown = test(part.label);
|
|
241
|
+
layout(false);
|
|
242
|
+
},
|
|
243
|
+
dispose() {
|
|
244
|
+
observer.disconnect();
|
|
245
|
+
element.remove();
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
export { LABEL_GAP, LABEL_SIDES, createLabels, labelBox, placeLabels };
|
|
250
|
+
|
|
251
|
+
//# sourceMappingURL=labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.js","names":[],"sources":["../src/labels/place.ts","../src/labels/layer.ts"],"sourcesContent":["import { overlapOf, type Rect } from \"@mark1russell7/layout-contract\";\n\n/**\n * The side of an anchor that the text of a label is on.\n * `center` puts the middle of the text on the anchor. Use it for the name of an area.\n */\nexport type LabelSide = \"right\" | \"left\" | \"above\" | \"below\" | \"center\";\n\n/** The default sides of a label, in the sequence in which `placeLabels` tries them. */\nexport const LABEL_SIDES: readonly LabelSide[] = [\"right\", \"left\", \"above\", \"below\"];\n\n/** The default distance between the mark of an anchor and the text of its label, in CSS pixels. */\nexport const LABEL_GAP = 4;\n\n/**\n * One label for `placeLabels`: its anchor in a picture, and the size of its text.\n * Each length is in CSS pixels. A position is from the top left corner of the picture.\n */\nexport interface LabelAnchor {\n /** The position of the anchor: the point of the picture that the label names. */\n readonly x: number;\n readonly y: number;\n /** The width of the text. */\n readonly width: number;\n /** The height of the text. */\n readonly height: number;\n /**\n * The radius of the mark at the anchor, for example a half of the width of a dot. The default is 0: the anchor has no mark.\n * No text is on the square around a mark.\n */\n readonly clear?: number | undefined;\n /** The sides that the text can have, in the sequence of the tries. The default is `LABEL_SIDES`. */\n readonly sides?: readonly LabelSide[] | undefined;\n}\n\n/** The picture that the labels are in. Each length is in CSS pixels. */\nexport interface LabelFrame {\n readonly width: number;\n readonly height: number;\n /** The distance between a mark and the text of its label. The default is `LABEL_GAP`. */\n readonly gap?: number | undefined;\n /** The smallest distance between a text and an edge of the picture. The default is 0. */\n readonly edge?: number | undefined;\n}\n\n/** The place of the text of a label: its side, and its rectangle in the picture. */\nexport interface LabelPlace {\n readonly side: LabelSide;\n readonly box: Rect;\n}\n\n/** This function gives the rectangle of the text of a label on one side of its anchor. `gap` is the distance between the mark and the text. */\nexport function labelBox(label: LabelAnchor, side: LabelSide, gap: number = LABEL_GAP): Rect {\n const { width: w, height: h } = label;\n const reach = (label.clear ?? 0) + gap;\n const x = side === \"right\" ? label.x + reach : side === \"left\" ? label.x - reach - w : label.x - w / 2;\n const y = side === \"below\" ? label.y + reach : side === \"above\" ? label.y - reach - h : label.y - h / 2;\n return { x, y, w, h };\n}\n\n/** This function tells if the insides of two rectangles overlap. Two rectangles with a common edge do not overlap. */\nfunction overlaps(a: Rect, b: Rect): boolean {\n const overlap = overlapOf(a, b);\n return overlap.x > 0 && overlap.y > 0;\n}\n\n/** This function gives the square around the mark of an anchor, or `undefined` for an anchor with no mark. */\nfunction markOf(label: LabelAnchor): Rect | undefined {\n const clear = label.clear ?? 0;\n return clear > 0 ? { x: label.x - clear, y: label.y - clear, w: 2 * clear, h: 2 * clear } : undefined;\n}\n\n/**\n * This function gives each label a place for its text, or `undefined` for a label that the picture does not show.\n * The result has one value for each label, in the sequence of the labels.\n *\n * - The first label has the first choice. Thus give the labels from the most important to the least important.\n * - A label tries its sides in sequence. It takes the first side on which its text is in the picture and on no other text and on no mark.\n * - A label with no free side is not in the picture. A label that comes later does not move a label that has a place.\n * - A label with an anchor out of the picture, or with a text of no size, is not in the picture. Its mark continues to keep the texts away.\n *\n * The function compares each label with each other label. It is for some hundreds of labels.\n */\nexport function placeLabels(labels: readonly LabelAnchor[], frame: LabelFrame): (LabelPlace | undefined)[] {\n const gap = frame.gap ?? LABEL_GAP;\n const edge = frame.edge ?? 0;\n const marks = labels.map(markOf);\n const texts: Rect[] = [];\n return labels.map((label, index) => {\n if (!(label.width > 0 && label.height > 0)) return undefined;\n if (!(label.x >= 0 && label.x <= frame.width && label.y >= 0 && label.y <= frame.height)) return undefined;\n for (const side of label.sides ?? LABEL_SIDES) {\n const box = labelBox(label, side, gap);\n if (!(box.x >= edge && box.y >= edge && box.x + box.w <= frame.width - edge && box.y + box.h <= frame.height - edge)) continue;\n if (texts.some((text) => overlaps(box, text))) continue;\n if (marks.some((mark, other) => mark !== undefined && other !== index && overlaps(box, mark))) continue;\n texts.push(box);\n return { side, box };\n }\n return undefined;\n });\n}\n","import type { Point, Point3 } from \"@mark1russell7/layout-contract\";\nimport type { StageExtent } from \"../extent.ts\";\nimport type { Highlight } from \"../highlight.ts\";\nimport { screenPoint } from \"../screen.ts\";\nimport type { StageContent, StageFrame } from \"../stage/stage.ts\";\nimport { LABEL_SIDES, placeLabels, type LabelAnchor, type LabelPlace, type LabelSide } from \"./place.ts\";\n\n/** A label of a stage: a short text next to a point of the world. */\nexport interface StageLabel {\n /** The name of the record that the label names. The label gets the highlight of this record. */\n readonly record: string;\n /** The point of the world that the label names. */\n readonly at: Point3;\n readonly text: string;\n /** The kind of the label. The element of the label has it in `data-kind`, so a style sheet gives each kind a look. */\n readonly kind?: string | undefined;\n /**\n * The importance of the label. When two texts cannot be in the picture together, the label with the higher rank stays.\n * The default is 0. A label of a highlighted record is before each other label.\n */\n readonly rank?: number | undefined;\n /** The radius of the mark at the point, in CSS pixels, for example a half of the width of a dot. The default is 0. */\n readonly clear?: number | undefined;\n /** The sides that the text can have, in the sequence of the tries. The default is `LABEL_SIDES`. Use `[\"center\"]` for the name of an area. */\n readonly sides?: readonly LabelSide[] | undefined;\n}\n\n/** The options of a layer of labels. */\nexport interface LabelsOptions {\n readonly labels: readonly StageLabel[];\n /**\n * This function tells if the camera sees a point of the world from its position.\n * For a globe, use `inSight`: a point on the far side of the Earth then has no label. The default shows each point.\n */\n readonly visible?: ((at: Point3, eye: Point3) => boolean) | undefined;\n /** The distance between a mark and the text of its label, in CSS pixels. The default is `LABEL_GAP`. */\n readonly gap?: number | undefined;\n /** The smallest distance between a text and an edge of the picture, in CSS pixels. The default is 0. */\n readonly edge?: number | undefined;\n}\n\n/**\n * A layer of labels: a content of a stage with no three.js object. Use `stackContents` to show it with the content that it names.\n * The layer has no pick: the pointer goes through each text to the picture.\n */\nexport interface LabelsContent extends StageContent<never> {\n /** The element of the layer. It is in the container. */\n readonly element: HTMLElement;\n /** This function shows the labels that a test accepts, and it removes the other labels from the picture. */\n show(test: (label: StageLabel) => boolean): void;\n}\n\n/** One label with its element and its state in the picture. */\ninterface Part {\n readonly label: StageLabel;\n readonly index: number;\n readonly element: HTMLElement;\n /** The size of the text, in CSS pixels. It is 0 until the browser gives the size. */\n width: number;\n height: number;\n /** This value is false for a label that `show` removed. */\n shown: boolean;\n highlight: Highlight;\n /** The anchor in the picture, or `undefined` for a point that the camera does not see. */\n point: Point | undefined;\n /** The last side of the text. While the picture does not move, the label tries it first, so a highlight moves no text. */\n side: LabelSide | undefined;\n /** This value is true while the text is in the picture. */\n on: boolean;\n /** The position of the text in the picture, in whole CSS pixels. */\n left: number;\n top: number;\n}\n\n/** This function gives the space that labels fill: each point, around the middle of the points. */\nfunction extentOf(labels: readonly StageLabel[]): StageExtent {\n const count = Math.max(labels.length, 1);\n const sum = labels.reduce((to, label) => ({ x: to.x + label.at.x, y: to.y + label.at.y, z: to.z + label.at.z }), { x: 0, y: 0, z: 0 });\n const center = { x: sum.x / count, y: sum.y / count, z: sum.z / count };\n return { center, corners: labels.length === 0 ? [center] : labels.map((label) => label.at) };\n}\n\n/**\n * This function makes a layer of labels in a container of a page. The style sheet `@mark1russell7/visuals/labels.css` draws it.\n *\n * - Use the container of the stage, and give it `position: relative`. The layer then fills the picture, above the canvas.\n * - Each label is an HTML element, so its text is sharp at each size and it uses the font of the page.\n * - Before each picture, the layer puts each text next to its point. `placeLabels` keeps each text off each other text and off each mark.\n * - The places are a function of the picture: after a move of the camera, each label tries its sides from the first side.\n * - While the picture does not move, a label keeps its side. So a highlight or a change of `show` moves no other text.\n * - The layer writes no inline style attribute. It sets each position through the CSS object model, so a strict content security policy permits it.\n * - A screen reader ignores the layer. Give the names of the records in the page, for example in a list.\n */\nexport function createLabels(container: HTMLElement, options: LabelsOptions): LabelsContent {\n const page = container.ownerDocument;\n const visible = options.visible;\n const records = new Set(options.labels.map((label) => label.record));\n let width = 0;\n let height = 0;\n\n const element = page.createElement(\"div\");\n element.className = \"visuals-labels\";\n element.setAttribute(\"aria-hidden\", \"true\");\n const parts: Part[] = options.labels.map((label, index) => {\n const text = page.createElement(\"span\");\n text.className = \"visuals-label visuals-label-off\";\n if (label.kind !== undefined) text.dataset[\"kind\"] = label.kind;\n text.textContent = label.text;\n element.append(text);\n return { label, index, element: text, width: 0, height: 0, shown: true, highlight: 0, point: undefined, side: undefined, on: false, left: Number.NaN, top: Number.NaN };\n });\n const partOf = new Map<Element, Part>(parts.map((part) => [part.element, part]));\n\n /** This function puts one text at its place, or removes it from the picture. It changes the page only for a new value. */\n const put = (part: Part, place: LabelPlace | undefined): void => {\n if (place === undefined) {\n if (part.on) part.element.classList.add(\"visuals-label-off\");\n part.on = false;\n return;\n }\n const left = Math.round(place.box.x);\n const top = Math.round(place.box.y);\n if (left !== part.left || top !== part.top) {\n part.left = left;\n part.top = top;\n part.element.style.transform = `translate(${String(left)}px, ${String(top)}px)`;\n }\n if (place.side !== part.side) {\n part.side = place.side;\n part.element.dataset[\"side\"] = place.side;\n }\n if (!part.on) part.element.classList.remove(\"visuals-label-off\");\n part.on = true;\n };\n\n /** This function gives the sides of a label, with its last side first. */\n const sidesOf = (part: Part): readonly LabelSide[] => {\n const sides = part.label.sides ?? LABEL_SIDES;\n const last = part.side;\n return last === undefined || sides[0] === last || !sides.includes(last) ? sides : [last, ...sides.filter((side) => side !== last)];\n };\n\n /**\n * This function gives each text its place from the anchors of the last picture.\n * `fresh` is true after a move of the picture: each label then tries its sides from the first side.\n */\n const layout = (fresh: boolean): void => {\n const live = parts.filter((part) => part.shown && part.point !== undefined);\n // A highlighted record is first, then the higher rank, then the sequence of the labels.\n live.sort((a, b) => b.highlight - a.highlight || (b.label.rank ?? 0) - (a.label.rank ?? 0) || a.index - b.index);\n const anchors: LabelAnchor[] = live.map((part) => ({\n x: part.point?.x ?? 0,\n y: part.point?.y ?? 0,\n width: part.width,\n height: part.height,\n clear: part.label.clear,\n sides: fresh ? part.label.sides : sidesOf(part),\n }));\n const places = placeLabels(anchors, { width, height, gap: options.gap, edge: options.edge });\n const placed = new Set<Part>();\n live.forEach((part, at) => {\n placed.add(part);\n put(part, places[at]);\n });\n for (const part of parts) if (!placed.has(part)) put(part, undefined);\n };\n\n // The browser gives the size of each text one time at the start, and again after a change of the font or of the zoom.\n const observer = new ResizeObserver((entries) => {\n for (const entry of entries) {\n const part = partOf.get(entry.target);\n const size = entry.borderBoxSize[0];\n if (part === undefined || size === undefined) continue;\n part.width = size.inlineSize;\n part.height = size.blockSize;\n }\n layout(false);\n });\n for (const part of parts) observer.observe(part.element);\n container.append(element);\n\n return {\n element,\n objects: [],\n extent: extentOf(options.labels),\n has: (record) => records.has(record),\n pick: () => undefined,\n paint(_theme, highlight): void {\n let changed = false;\n for (const part of parts) {\n const next = highlight(part.label.record);\n if (next === part.highlight) continue;\n part.highlight = next;\n part.element.classList.toggle(\"visuals-label-hovered\", next === 1);\n part.element.classList.toggle(\"visuals-label-selected\", next === 2);\n changed = true;\n }\n if (changed) layout(false);\n },\n step(frame: StageFrame): boolean {\n const { camera } = frame;\n // The stage moves the camera before the step, and three.js sets the matrices of the camera only when it makes the picture.\n camera.updateMatrixWorld();\n const nextHeight = frame.height;\n const nextWidth = frame.height * camera.aspect;\n let moved = nextWidth !== width || nextHeight !== height;\n width = nextWidth;\n height = nextHeight;\n const view = camera.matrixWorldInverse.elements;\n const projection = camera.projectionMatrix.elements;\n for (const part of parts) {\n const { at } = part.label;\n const point = visible === undefined || visible(at, camera.position) ? screenPoint(at, view, projection, width, height) : undefined;\n if (point?.x !== part.point?.x || point?.y !== part.point?.y) moved = true;\n part.point = point;\n }\n layout(moved);\n return false;\n },\n show(test): void {\n for (const part of parts) part.shown = test(part.label);\n layout(false);\n },\n dispose(): void {\n observer.disconnect();\n element.remove();\n },\n };\n}\n"],"mappings":";;;;AASA,MAAa,cAAoC;CAAC;CAAS;CAAQ;CAAS;AAAO;;AAGnF,MAAa,YAAY;;AAwCzB,SAAgB,SAAS,OAAoB,MAAiB,MAAA,GAA+B;CAC3F,MAAM,EAAE,OAAO,GAAG,QAAQ,MAAM;CAChC,MAAM,SAAS,MAAM,SAAS,KAAK;CAGnC,OAAO;EAAE,GAFC,SAAS,UAAU,MAAM,IAAI,QAAQ,SAAS,SAAS,MAAM,IAAI,QAAQ,IAAI,MAAM,IAAI,IAAI;EAEzF,GADF,SAAS,UAAU,MAAM,IAAI,QAAQ,SAAS,UAAU,MAAM,IAAI,QAAQ,IAAI,MAAM,IAAI,IAAI;EACvF;EAAG;CAAE;AACtB;;AAGA,SAAS,SAAS,GAAS,GAAkB;CAC3C,MAAM,UAAU,UAAU,GAAG,CAAC;CAC9B,OAAO,QAAQ,IAAI,KAAK,QAAQ,IAAI;AACtC;;AAGA,SAAS,OAAO,OAAsC;CACpD,MAAM,QAAQ,MAAM,SAAS;CAC7B,OAAO,QAAQ,IAAI;EAAE,GAAG,MAAM,IAAI;EAAO,GAAG,MAAM,IAAI;EAAO,GAAG,IAAI;EAAO,GAAG,IAAI;CAAM,IAAI,KAAA;AAC9F;;;;;;;;;;;;AAaA,SAAgB,YAAY,QAAgC,OAA+C;CACzG,MAAM,MAAM,MAAM,OAAA;CAClB,MAAM,OAA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AAK,OAAO,GAAG,QAAQ;IACtE,KAAK,QAAQ;GACf;GACA,OAAO,KAAK;GACZ,OAAO;EACT;EACA,KAAK,MAAY;GACf,KAAK,MAAM,QAAQ,OAAO,KAAK,QAAQ,KAAK,KAAK,KAAK;GACtD,OAAO,KAAK;EACd;EACA,UAAgB;GACd,SAAS,WAAW;GACpB,QAAQ,OAAO;EACjB;CACF;AACF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A range of time, with its two ends. Each time of this file is a number in one unit that the page chooses, for example milliseconds.
|
|
3
|
+
* A range is also a lifetime that has an end.
|
|
4
|
+
*/
|
|
5
|
+
interface TimeSpan {
|
|
6
|
+
readonly from: number;
|
|
7
|
+
/** The end of the range. It is not before `from`. */
|
|
8
|
+
readonly to: number;
|
|
9
|
+
}
|
|
10
|
+
/** The time in which a part of a content is in the picture. */
|
|
11
|
+
interface Lifetime {
|
|
12
|
+
/** The first time of the part. */
|
|
13
|
+
readonly from: number;
|
|
14
|
+
/** The first time after the part. A part with no `to` has no end. */
|
|
15
|
+
readonly to?: number | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** This function tells if a part is in the picture at a time. A part is in the picture at `from`, and it is not in the picture at `to`. */
|
|
18
|
+
declare function isLive(life: Lifetime, at: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* This function gives the times at which a picture changes: each start and each end of a lifetime.
|
|
21
|
+
* The result has each time once, from the first time to the last time. A time that is not finite is not in the result.
|
|
22
|
+
*/
|
|
23
|
+
declare function changeTimes(lives: Iterable<Lifetime>): readonly number[];
|
|
24
|
+
/** This function gives the range from the first change to the last change of a sorted list of times. A list with no time gives `undefined`. */
|
|
25
|
+
declare function spanOfTimes(times: readonly number[]): TimeSpan | undefined;
|
|
26
|
+
/** This function gives the first time after `at` in a sorted list of times, or `undefined` when no time is after it. */
|
|
27
|
+
declare function changeAfter(times: readonly number[], at: number): number | undefined;
|
|
28
|
+
/** This function gives the last time before `at` in a sorted list of times, or `undefined` when no time is before it. */
|
|
29
|
+
declare function changeBefore(times: readonly number[], at: number): number | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* This function gives the count of the times of a sorted list that are not after `at`.
|
|
32
|
+
* The picture of two times with the same count is the same picture, so a page draws again only after a new count.
|
|
33
|
+
*/
|
|
34
|
+
declare function changeIndex(times: readonly number[], at: number): number;
|
|
35
|
+
/** This function gives the place of a time in a range, from 0 at the start to 1 at the end. A range with no length gives 0. */
|
|
36
|
+
declare function spanPart(span: TimeSpan, at: number): number;
|
|
37
|
+
/** This function gives the time at a place of a range. `part` goes from 0 at the start to 1 at the end. */
|
|
38
|
+
declare function spanTime(span: TimeSpan, part: number): number;
|
|
39
|
+
/** The state of a replay: a control shows the picture of one time of a range, and it can go through the range. */
|
|
40
|
+
interface Replay {
|
|
41
|
+
readonly span: TimeSpan;
|
|
42
|
+
/** The time of the picture. It is in the range. */
|
|
43
|
+
readonly at: number;
|
|
44
|
+
/** This value is true while the time goes forward. */
|
|
45
|
+
readonly playing: boolean;
|
|
46
|
+
/** The speed, as a factor. A replay with the speed 1 goes through the range in the duration that `replayAdvance` gets. */
|
|
47
|
+
readonly speed: number;
|
|
48
|
+
}
|
|
49
|
+
/** The time in which a replay with the speed 1 goes through its range, in milliseconds. */
|
|
50
|
+
declare const REPLAY_DURATION = 2e4;
|
|
51
|
+
/** The speeds of a replay that a control offers, from the slowest to the fastest. */
|
|
52
|
+
declare const REPLAY_SPEEDS: readonly number[];
|
|
53
|
+
/** The part of a range that the keys `PageUp` and `PageDown` go. */
|
|
54
|
+
declare const REPLAY_PAGE = .1;
|
|
55
|
+
/** The part of a range that an arrow key goes when the replay has no times of change. */
|
|
56
|
+
declare const REPLAY_STEP = .01;
|
|
57
|
+
/**
|
|
58
|
+
* This function gives a replay that does not go. With no time, the picture is at the end of the range.
|
|
59
|
+
* The end of a range is the present for a content that shows live data.
|
|
60
|
+
*/
|
|
61
|
+
declare function replayOf(span: TimeSpan, at?: number): Replay;
|
|
62
|
+
/** This function puts the picture of a replay at a time. A time out of the range becomes the nearest end of the range. */
|
|
63
|
+
declare function replaySeek(replay: Replay, at: number): Replay;
|
|
64
|
+
/** This function starts a replay. A replay at the end of its range starts again from the start of the range. */
|
|
65
|
+
declare function replayPlay(replay: Replay): Replay;
|
|
66
|
+
/** This function stops a replay at its time. */
|
|
67
|
+
declare function replayPause(replay: Replay): Replay;
|
|
68
|
+
/** This function starts a replay that does not go, and it stops a replay that goes. */
|
|
69
|
+
declare function replayToggle(replay: Replay): Replay;
|
|
70
|
+
/**
|
|
71
|
+
* This function moves a replay that goes by a time of the clock. `elapsed` and `duration` are in milliseconds.
|
|
72
|
+
* The replay stops at the end of its range. A replay that does not go stays the same value.
|
|
73
|
+
*/
|
|
74
|
+
declare function replayAdvance(replay: Replay, elapsed: number, duration?: number): Replay;
|
|
75
|
+
/**
|
|
76
|
+
* This function gives a replay with the next speed of a list. After the last speed comes the first speed.
|
|
77
|
+
* A speed that is not in the list gets the first speed that is higher, or the first speed of the list.
|
|
78
|
+
*/
|
|
79
|
+
declare function replayNextSpeed(replay: Replay, speeds?: readonly number[]): Replay;
|
|
80
|
+
/**
|
|
81
|
+
* This function gives a replay a new range, for example after new data. A replay at the end of the old range stays at the end.
|
|
82
|
+
* Thus a picture of the present stays the picture of the present. A different time stays the same, in the new range.
|
|
83
|
+
*/
|
|
84
|
+
declare function replaySpan(replay: Replay, span: TimeSpan): Replay;
|
|
85
|
+
/**
|
|
86
|
+
* This function gives the replay after a key of a slider, or `undefined` for a key with no action.
|
|
87
|
+
*
|
|
88
|
+
* The keys `ArrowRight` and `ArrowUp` go to the next change of `times`, and `ArrowLeft` and `ArrowDown` go to the change before.
|
|
89
|
+
* The keys `PageUp` and `PageDown` go a tenth of the range. The keys `Home` and `End` go to the ends.
|
|
90
|
+
* Each of these keys stops a replay that goes, because the person sets the time.
|
|
91
|
+
* The key Space starts a replay that does not go, and it stops a replay that goes.
|
|
92
|
+
*/
|
|
93
|
+
declare function replayKey(key: string, replay: Replay, times?: readonly number[]): Replay | undefined;
|
|
94
|
+
export { spanPart as C, spanOfTimes as S, replayPause as _, REPLAY_STEP as a, replaySpan as b, changeAfter as c, changeTimes as d, isLive as f, replayOf as g, replayNextSpeed as h, REPLAY_SPEEDS as i, changeBefore as l, replayKey as m, REPLAY_DURATION as n, Replay as o, replayAdvance as p, REPLAY_PAGE as r, TimeSpan as s, Lifetime as t, changeIndex as u, replayPlay as v, spanTime as w, replayToggle as x, replaySeek as y };
|
|
95
|
+
//# sourceMappingURL=replay-DvGYPe7T.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-DvGYPe7T.d.ts","names":[],"sources":["../src/replay.ts"],"mappings":";;;;UAIiB;WACN;;WAEA;;;UAIM;;WAEN;;WAEA;;;iBAIK,OAAO,MAAM,UAAU;;;;;iBAQvB,YAAY,OAAO,SAAS;;iBAU5B,YAAY,2BAA2B;;iBAOvC,YAAY,0BAA0B;;iBAKtC,aAAa,0BAA0B;;;;;iBAQvC,YAAY,0BAA0B;;iBAKtC,SAAS,MAAM,UAAU;;iBAMzB,SAAS,MAAM,UAAU;;UAKxB;WACN,MAAM;;WAEN;;WAEA;;WAEA;;;cAIE;;cAGA;;cAGA;;cAGA;;;;;iBAMG,SAAS,MAAM,UAAU,cAAuB;;iBAKhD,WAAW,QAAQ,QAAQ,aAAa;;iBAMxC,WAAW,QAAQ,SAAS;;iBAM5B,YAAY,QAAQ,SAAS;;iBAK7B,aAAa,QAAQ,SAAS;;;;;iBAQ9B,cAAc,QAAQ,QAAQ,iBAAiB,oBAAqC;;;;;iBAWpF,gBAAgB,QAAQ,QAAQ,6BAA4C;;;;;iBAS5E,WAAW,QAAQ,QAAQ,MAAM,WAAW;;;;;;;;;iBAc5C,UAAU,aAAa,QAAQ,QAAQ,4BAAgC"}
|