@mark1russell7/visuals 0.2.1 → 0.2.3
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 +65 -2
- package/build/{extent-CALhBZU-.js → extent-BtiN2C8B.js} +25 -3
- package/build/extent-BtiN2C8B.js.map +1 -0
- package/build/globe.d.ts +7 -2
- package/build/globe.d.ts.map +1 -1
- package/build/globe.js +9 -2
- package/build/globe.js.map +1 -1
- package/build/index.d.ts +20 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -3
- 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/{motion-0tsT6sY4.js → motion-BxV1vOEB.js} +9 -6
- package/build/motion-BxV1vOEB.js.map +1 -0
- package/build/screen-DeOx4_90.js +29 -0
- package/build/screen-DeOx4_90.js.map +1 -0
- package/build/{stage-CtWLSoV-.d.ts → stage-DQga0pc6.d.ts} +3 -5
- package/build/{stage-CtWLSoV-.d.ts.map → stage-DQga0pc6.d.ts.map} +1 -1
- package/build/{theme-CKXd_emk.d.ts → theme-DAt9xM0P.d.ts} +18 -3
- package/build/theme-DAt9xM0P.d.ts.map +1 -0
- package/build/three.d.ts +14 -2
- package/build/three.d.ts.map +1 -0
- package/build/three.js +54 -11
- package/build/three.js.map +1 -1
- package/package.json +9 -2
- package/styles/labels.css +88 -0
- package/build/extent-CALhBZU-.js.map +0 -1
- package/build/motion-0tsT6sY4.js.map +0 -1
- package/build/theme-CKXd_emk.d.ts.map +0 -1
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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GAC3C,KAAK,MAAM,QAAQ,OAAO;IACxB,MAAM,EAAE,OAAO,KAAK;IACpB,MAAM,QAAQ,YAAY,KAAA,KAAa,QAAQ,IAAI,OAAO,QAAQ,IAAI,YAAY,IAAI,MAAM,YAAY,OAAO,MAAM,IAAI,KAAA;IACzH,IAAI,OAAO,MAAM,KAAK,OAAO,KAAK,OAAO,MAAM,KAAK,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"}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as turnAcross, m as placeBetween } from "./extent-BtiN2C8B.js";
|
|
2
2
|
// src/keys.ts
|
|
3
|
-
/** The angle of one step of an arrow key, in radians
|
|
3
|
+
/** 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. */
|
|
4
4
|
const KEY_TURN = Math.PI / 24;
|
|
5
|
+
/** 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. */
|
|
6
|
+
const KEY_PART = .125;
|
|
5
7
|
/** The factor of the height of a camera above the surface for one step of the key `+`. */
|
|
6
8
|
const KEY_ZOOM = .85;
|
|
7
9
|
/**
|
|
8
10
|
* This function gives the action of a key on a stage, or `undefined` for a key with no action.
|
|
9
11
|
*
|
|
10
12
|
* The arrow keys turn the camera around the target. The keys `+` and `-` change the height above the surface.
|
|
11
|
-
* The keys `Home` and `0` show the home view.
|
|
13
|
+
* The keys `Home` and `0` show the home view.
|
|
14
|
+
* Near a ball, a step of an arrow key moves the surface by the part `KEY_PART` of the height of the picture.
|
|
12
15
|
* The result has no limits: the stage puts the place in its limits.
|
|
13
16
|
*/
|
|
14
17
|
function keyAction(key, now, options) {
|
|
15
18
|
const surface = options.surface ?? 0;
|
|
16
|
-
const turn = KEY_TURN *
|
|
19
|
+
const turn = Math.min(KEY_TURN, KEY_PART * turnAcross(now.distance, surface, options.fieldOfView ?? 32));
|
|
17
20
|
const zoom = (factor) => ({
|
|
18
21
|
...now,
|
|
19
22
|
distance: surface + (now.distance - surface) * factor
|
|
@@ -127,6 +130,6 @@ function approach(value, goal, seconds, time, snap = .01) {
|
|
|
127
130
|
const next = value + (goal - value) * (1 - Math.exp(0 - seconds / time));
|
|
128
131
|
return Math.abs(goal - next) < snap ? goal : next;
|
|
129
132
|
}
|
|
130
|
-
export { NO_HIGHLIGHTS as a,
|
|
133
|
+
export { NO_HIGHLIGHTS as a, KEY_PART as c, keyAction as d, CLICK_DISTANCE as i, KEY_TURN as l, easeInOut as n, highlightOf as o, moveAt as r, isClick as s, approach as t, KEY_ZOOM as u };
|
|
131
134
|
|
|
132
|
-
//# sourceMappingURL=motion-
|
|
135
|
+
//# sourceMappingURL=motion-BxV1vOEB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion-BxV1vOEB.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 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 = move.duration > 0 ? Math.min(Math.max((now - move.start) / move.duration, 0), 1) : 1;\n if (part >= 1) return { place: move.to, done: true };\n return { place: placeBetween(move.from, move.to, easeInOut(part), surface), done: false };\n}\n\n/**\n * This function moves a value one step to its goal. Each step goes a constant part of the way that remains.\n *\n * `seconds` is the time of the step, and `time` is the time in which the value goes most of the way, in seconds.\n * A step with no time gives the goal. A value nearer to the goal than `snap` becomes the goal, so the steps have an end.\n */\nexport function approach(value: number, goal: number, seconds: number, time: number, snap: number = 0.01): number {\n if (!(seconds > 0) || !(time > 0)) return goal;\n const next = value + (goal - value) * (1 - Math.exp(0 - seconds / time));\n return Math.abs(goal - next) < snap ? goal : next;\n}\n"],"mappings":";;;AAGA,MAAa,WAAmB,KAAK,KAAK;;AAG1C,MAAa,WAAW;;AAGxB,MAAa,WAAW;;;;;;;;;AAyBxB,SAAgB,UAAU,KAAa,KAAY,SAA4C;CAC7F,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,OAAO,KAAK,IAAI,UAAU,WAAW,WAAW,IAAI,UAAU,SAAS,QAAQ,eAAA,EAA4B,CAAC;CAClH,MAAM,QAAQ,YAA2B;EAAE,GAAG;EAAK,UAAU,WAAW,IAAI,WAAW,WAAW;CAAO;CACzG,QAAQ,KAAR;EACE,KAAK,aACH,OAAO;GAAE,MAAM;GAAS,OAAO;IAAE,GAAG;IAAK,SAAS,IAAI,UAAU;GAAK;EAAE;EACzE,KAAK,cACH,OAAO;GAAE,MAAM;GAAS,OAAO;IAAE,GAAG;IAAK,SAAS,IAAI,UAAU;GAAK;EAAE;EACzE,KAAK,WACH,OAAO;GAAE,MAAM;GAAS,OAAO;IAAE,GAAG;IAAK,OAAO,IAAI,QAAQ;GAAK;EAAE;EACrE,KAAK,aACH,OAAO;GAAE,MAAM;GAAS,OAAO;IAAE,GAAG;IAAK,OAAO,IAAI,QAAQ;GAAK;EAAE;EACrE,KAAK;EACL,KAAK,KACH,OAAO;GAAE,MAAM;GAAS,OAAO,KAAK,QAAQ;EAAE;EAChD,KAAK;EACL,KAAK,KACH,OAAO;GAAE,MAAM;GAAS,OAAO,KAAK,IAAI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e,KAAc;CAChH,IAAI,EAAE,UAAU,MAAM,EAAE,OAAO,IAAI,OAAO;CAC1C,MAAM,OAAO,SAAS,OAAO,UAAU,IAAI,KAAK,IAAI,IAAI,UAAU,IAAI;CACtE,OAAO,KAAK,IAAI,OAAO,IAAI,IAAI,OAAO,OAAO;AAC/C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/screen.ts
|
|
2
|
+
/** This function gives one row of the product of a matrix and a vector of four values. The matrix has 16 numbers, one column after the other. */
|
|
3
|
+
function row(matrix, at, x, y, z, w) {
|
|
4
|
+
return (matrix[at] ?? 0) * x + (matrix[at + 4] ?? 0) * y + (matrix[at + 8] ?? 0) * z + (matrix[at + 12] ?? 0) * w;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This function gives the point of a picture that shows a point of the world, in CSS pixels from the top left corner.
|
|
8
|
+
* It gives `undefined` for a point that is not in front of a camera with perspective.
|
|
9
|
+
*
|
|
10
|
+
* - `view` is the matrix from the world to the camera: `matrixWorldInverse.elements` of a three.js camera.
|
|
11
|
+
* - `projection` is the matrix of the lens of the camera: `projectionMatrix.elements` of a three.js camera.
|
|
12
|
+
* - Each matrix has 16 numbers, one column after the other. This is the sequence of three.js and of WebGL.
|
|
13
|
+
* - A point to the side of the picture gives a position out of the picture. The function does not remove it.
|
|
14
|
+
*/
|
|
15
|
+
function screenPoint(point, view, projection, width, height) {
|
|
16
|
+
const x = row(view, 0, point.x, point.y, point.z, 1);
|
|
17
|
+
const y = row(view, 1, point.x, point.y, point.z, 1);
|
|
18
|
+
const z = row(view, 2, point.x, point.y, point.z, 1);
|
|
19
|
+
const w = row(view, 3, point.x, point.y, point.z, 1);
|
|
20
|
+
const depth = row(projection, 3, x, y, z, w);
|
|
21
|
+
if (!(depth > 0)) return void 0;
|
|
22
|
+
return {
|
|
23
|
+
x: (row(projection, 0, x, y, z, w) / depth + 1) / 2 * width,
|
|
24
|
+
y: (1 - row(projection, 1, x, y, z, w) / depth) / 2 * height
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export { screenPoint as t };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=screen-DeOx4_90.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screen-DeOx4_90.js","names":[],"sources":["../src/screen.ts"],"sourcesContent":["import type { Point, Point3 } from \"@mark1russell7/layout-contract\";\n\n/** This function gives one row of the product of a matrix and a vector of four values. The matrix has 16 numbers, one column after the other. */\nfunction row(matrix: ArrayLike<number>, at: number, x: number, y: number, z: number, w: number): number {\n return (matrix[at] ?? 0) * x + (matrix[at + 4] ?? 0) * y + (matrix[at + 8] ?? 0) * z + (matrix[at + 12] ?? 0) * w;\n}\n\n/**\n * This function gives the point of a picture that shows a point of the world, in CSS pixels from the top left corner.\n * It gives `undefined` for a point that is not in front of a camera with perspective.\n *\n * - `view` is the matrix from the world to the camera: `matrixWorldInverse.elements` of a three.js camera.\n * - `projection` is the matrix of the lens of the camera: `projectionMatrix.elements` of a three.js camera.\n * - Each matrix has 16 numbers, one column after the other. This is the sequence of three.js and of WebGL.\n * - A point to the side of the picture gives a position out of the picture. The function does not remove it.\n */\nexport function screenPoint(point: Point3, view: ArrayLike<number>, projection: ArrayLike<number>, width: number, height: number): Point | undefined {\n const x = row(view, 0, point.x, point.y, point.z, 1);\n const y = row(view, 1, point.x, point.y, point.z, 1);\n const z = row(view, 2, point.x, point.y, point.z, 1);\n const w = row(view, 3, point.x, point.y, point.z, 1);\n const depth = row(projection, 3, x, y, z, w);\n if (!(depth > 0)) return undefined;\n return {\n x: ((row(projection, 0, x, y, z, w) / depth + 1) / 2) * width,\n y: ((1 - row(projection, 1, x, y, z, w) / depth) / 2) * height,\n };\n}\n"],"mappings":";;AAGA,SAAS,IAAI,QAA2B,IAAY,GAAW,GAAW,GAAW,GAAmB;CACtG,QAAQ,OAAO,OAAO,KAAK,KAAK,OAAO,KAAK,MAAM,KAAK,KAAK,OAAO,KAAK,MAAM,KAAK,KAAK,OAAO,KAAK,OAAO,KAAK;AAClH;;;;;;;;;;AAWA,SAAgB,YAAY,OAAe,MAAyB,YAA+B,OAAe,QAAmC;CACnJ,MAAM,IAAI,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC;CACnD,MAAM,IAAI,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC;CACnD,MAAM,IAAI,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC;CACnD,MAAM,IAAI,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC;CACnD,MAAM,QAAQ,IAAI,YAAY,GAAG,GAAG,GAAG,GAAG,CAAC;CAC3C,IAAI,EAAE,QAAQ,IAAI,OAAO,KAAA;CACzB,OAAO;EACL,IAAK,IAAI,YAAY,GAAG,GAAG,GAAG,GAAG,CAAC,IAAI,QAAQ,KAAK,IAAK;EACxD,IAAK,IAAI,IAAI,YAAY,GAAG,GAAG,GAAG,GAAG,CAAC,IAAI,SAAS,IAAK;CAC1D;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as StageView, l as StageExtent, r as Highlight, t as StageTheme, x as Place } from "./theme-DAt9xM0P.js";
|
|
2
2
|
import { Object3D, PerspectiveCamera, Raycaster } from "three";
|
|
3
3
|
/** The record under the pointer: its name, and the value that the content gives for it. */
|
|
4
4
|
interface StagePick<P> {
|
|
@@ -107,8 +107,6 @@ interface Stage<P, T extends StageTheme = StageTheme> {
|
|
|
107
107
|
/** This function removes the canvas and releases the memory of the graphics card. It disposes the content. */
|
|
108
108
|
dispose(): void;
|
|
109
109
|
}
|
|
110
|
-
/** The default vertical angle of the picture, in degrees. */
|
|
111
|
-
declare const FIELD_OF_VIEW = 32;
|
|
112
110
|
/** The default lights: a strong light from above and below, and a light from the front left. */
|
|
113
111
|
declare const STAGE_LIGHTS: StageLights;
|
|
114
112
|
/**
|
|
@@ -122,5 +120,5 @@ declare const STAGE_LIGHTS: StageLights;
|
|
|
122
120
|
* The page then shows a different picture of the same data.
|
|
123
121
|
*/
|
|
124
122
|
declare function createStage<P, T extends StageTheme = StageTheme>(container: HTMLElement, options: StageOptions<P, T>): Stage<P, T> | undefined;
|
|
125
|
-
export {
|
|
126
|
-
//# sourceMappingURL=stage-
|
|
123
|
+
export { StageLights as a, createStage as c, StageFrame as i, Stage as n, StageOptions as o, StageContent as r, StagePick as s, STAGE_LIGHTS as t };
|
|
124
|
+
//# sourceMappingURL=stage-DQga0pc6.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage-
|
|
1
|
+
{"version":3,"file":"stage-DQga0pc6.d.ts","names":[],"sources":["../src/stage/stage.ts"],"mappings":";;;UAYiB,UAAU;;WAEhB;;WAEA,OAAO;;;UAID;WACN,QAAQ;;WAER;;;;;WAKA;;WAEA;;WAEA;;;;;;UAOM,aAAa,GAAG,UAAU,aAAa;;WAE7C,kBAAkB;;WAElB,QAAQ;;EAEjB,IAAI;;EAEJ,KAAK,KAAK,YAAY,UAAU;;EAEhC,MAAM,OAAO,GAAG,YAAY,mBAAmB;;;;;EAK/C,MAAM,OAAO;;EAEb;;;UAIe;;WAEN;;WAEA;;WAEA;aAAiB;aAAoB;aAAoB;;;;UAInD,aAAa,GAAG,UAAU,aAAa;;WAE7C,SAAS,aAAa,GAAG;WACzB,OAAO;;WAEP;;WAEA,OAAO,SAAS,eAAe;;WAE/B;;WAEA,OAAO,SAAS;;WAEhB;;WAEA;aAAmB;aAAmC;;;WAEtD;WACA,SAAS;;WAET,YAAY,MAAM;;WAElB,aAAa,MAAM;;;UAIb,MAAM,GAAG,UAAU,aAAa;;WAEtC,QAAQ;;EAEjB,WAAW,SAAS,aAAa,GAAG;;EAEpC,SAAS,OAAO;;EAEhB,QAAQ,eAAe,WAAW;;EAElC,SAAS;;EAET,UAAU;;EAEV,OAAO;;EAEP;;EAEA;;;cAIW,cAAc;;;;;;;;;;;iBAgCX,YAAY,GAAG,UAAU,aAAa,YAAY,WAAW,aAAa,SAAS,aAAa,GAAG,KAAK,MAAM,GAAG"}
|
|
@@ -67,10 +67,25 @@ declare function clampPlace(place: Place, limits: PlaceLimits): Place;
|
|
|
67
67
|
* This function gives the height of a camera above the surface of a stage, as a part of its distance from the target.
|
|
68
68
|
*
|
|
69
69
|
* `surface` is the radius of the ball around the target that the camera stays out of. A stage with no ball has the value 0.
|
|
70
|
-
* The result is the factor of the
|
|
70
|
+
* The result is the factor of the zoom speed of a camera: near the surface, a camera moves slowly.
|
|
71
71
|
* The result is 0.02 at least, so a camera on the surface can move away.
|
|
72
72
|
*/
|
|
73
73
|
declare function speedAt(distance: number, surface: number): number;
|
|
74
|
+
/** The default vertical angle of the picture of a stage, in degrees. */
|
|
75
|
+
declare const FIELD_OF_VIEW = 32;
|
|
76
|
+
/**
|
|
77
|
+
* This function gives the turn of a camera around a ball that moves the surface by the height of the picture, in radians.
|
|
78
|
+
*
|
|
79
|
+
* `surface` is the radius of the ball around the target. `fieldOfView` is the vertical angle of the picture, in degrees.
|
|
80
|
+
*
|
|
81
|
+
* The result is exact for the surface at the middle of the picture. Thus that surface follows the pointer in a drag.
|
|
82
|
+
* The ball is round, so a long drag moves that surface by a smaller distance than the pointer.
|
|
83
|
+
* Thus the surface does not go before the pointer.
|
|
84
|
+
*
|
|
85
|
+
* The result is `Infinity` for a stage with no ball, because such a stage has no surface that follows the pointer.
|
|
86
|
+
* A turn about the up axis moves a point between the equator and a pole of the ball by a smaller distance.
|
|
87
|
+
*/
|
|
88
|
+
declare function turnAcross(distance: number, surface: number, fieldOfView: number): number;
|
|
74
89
|
/**
|
|
75
90
|
* This function gives the place at a part of the way between two places. `part` goes from 0 to 1.
|
|
76
91
|
*
|
|
@@ -189,5 +204,5 @@ interface StageTheme {
|
|
|
189
204
|
/** The color of the light from below. */
|
|
190
205
|
readonly ground: string;
|
|
191
206
|
}
|
|
192
|
-
export {
|
|
193
|
-
//# sourceMappingURL=theme-
|
|
207
|
+
export { speedAt as A, ViewAngles as C, clampPlace as D, capDistance as E, turnBetween as M, viewAxes as N, fitDistance as O, viewOf as P, PlaceLimits as S, cameraPosition as T, reachOf as _, NO_HIGHLIGHTS as a, FIELD_OF_VIEW as b, FIT_MARGIN as c, StageView as d, ViewFrame as f, nearDepth as g, fitView as h, Highlights as i, turnAcross as j, placeBetween as k, StageExtent as l, capView as m, CLICK_DISTANCE as n, highlightOf as o, ballView as p, Highlight as r, isClick as s, StageTheme as t, StageLimits as u, stageLimits as v, ViewAxes as w, Place as x, surfaceOf as y };
|
|
208
|
+
//# sourceMappingURL=theme-DAt9xM0P.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-DAt9xM0P.d.ts","names":[],"sources":["../src/view.ts","../src/extent.ts","../src/highlight.ts","../src/theme.ts"],"mappings":";;;;;UAMiB;;WAEN;;WAEA;;;UAIM,cAAc;WACpB,QAAQ;WACR;;;UAIM;;WAEN,MAAM;;WAEN,OAAO;;WAEP,IAAI;;;UAIE;;WAEN;;WAEA;;WAEA;;WAEA;;;iBAIK,SAAS,MAAM,aAAa;;;;;;;;iBAwB5B,YAAY,iBAAiB,UAAU,QAAQ,QAAQ,MAAM,YAAY,aAAa;;;;;;;;;iBAsBtF,YAAY,gBAAgB,eAAe,aAAa;;iBAaxD,eAAe,QAAQ,QAAQ,MAAM,YAAY,mBAAmB;;iBAMpE,OAAO,QAAQ,QAAQ,QAAQ,SAAS;WAAwB;;;iBAUhE,YAAY,cAAc;;iBAO1B,WAAW,OAAO,OAAO,QAAQ,cAAc;;;;;;;;iBAgB/C,QAAQ,kBAAkB;;cAM7B;;;;;;;;;;;;;iBAiBG,WAAW,kBAAkB,iBAAiB;;;;;;;iBAe9C,aAAa,MAAM,OAAO,IAAI,OAAO,cAAc,mBAAsB;;UC9KxE;;WAEN,kBAAkB;;WAElB,QAAQ;;;;;WAKR;;WAEA;;WAEA;;;UAIM;WACN,QAAQ;;WAER;;WAEA;;;KAIC,aAAa,OAAO,cAAc;;UAG7B,oBAAoB;WAC1B;WACA;;;cAIE;;iBAGG,UAAU,QAAQ;;;;;iBASlB,QAAQ,QAAQ,YAAY,kBAA8B;;;;;;;iBAa1D,QAAQ,QAAQ,YAAY,eAAe,kBAA8B;;;;;;;iBAczE,SAAS,iBAAiB,UAAU,kBAA8B;;iBA0ClE,QAAQ,QAAQ;;;;;;;iBAYhB,UAAU,QAAQ,aAAa,QAAQ,aAAa;;;;;;;iBAWpD,YAAY,OAAO,WAAW,gBAAgB,aAAa;WAAkB;WAAsB;IAAgB;;KC9IvH;;UAGK;;WAEN;;WAEA;;WAEA,aAAa;;;cAIX,eAAe;;iBAGZ,YAAY,YAAY,YAAY,iBAAiB;;cAMxD;;;;;iBAMG,QAAQ;WAAiB;WAAoB;GAAa;WAAe;WAAoB;GAAa;;;;;UCzBzG;;WAEN;;WAEA"}
|
package/build/three.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
1
|
+
import { a as StageLights, c as createStage, i as StageFrame, n as Stage, o as StageOptions, r as StageContent, s as StagePick, t as STAGE_LIGHTS } from "./stage-DQga0pc6.js";
|
|
2
|
+
import { b as FIELD_OF_VIEW, t as StageTheme } from "./theme-DAt9xM0P.js";
|
|
3
|
+
/**
|
|
4
|
+
* This function makes one content from a list of contents, for a stage that shows them together.
|
|
5
|
+
* An example is a globe with a layer of labels, or a room with its marks.
|
|
6
|
+
*
|
|
7
|
+
* - The first content gives the extent: the views and the limits of the camera come from it.
|
|
8
|
+
* - The last content is on top. A pick asks the last content first, and it stops at the first record.
|
|
9
|
+
* - A record that two contents have is one record: each of them gets its highlight.
|
|
10
|
+
* - The stage disposes the stack, and the stack disposes each content.
|
|
11
|
+
*/
|
|
12
|
+
export declare function stackContents<P, T extends StageTheme = StageTheme>(contents: readonly [StageContent<P, T>, ...StageContent<P, T>[]]): StageContent<P, T>;
|
|
13
|
+
export { FIELD_OF_VIEW, STAGE_LIGHTS, type Stage, type StageContent, type StageFrame, type StageLights, type StageOptions, type StagePick, createStage };
|
|
14
|
+
//# sourceMappingURL=three.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"three.d.ts","names":[],"sources":["../src/stage/stack.ts"],"mappings":";;;;;;;;;;;wBAYgB,cAAc,GAAG,UAAU,aAAa,YAAY,oBAAoB,aAAa,GAAG,OAAO,aAAa,GAAG,QAAQ,aAAa,GAAG"}
|
package/build/three.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as NO_HIGHLIGHTS, o as highlightOf, r as moveAt, s as isClick
|
|
1
|
+
import { a as nearDepth, c as surfaceOf, f as clampPlace, g as turnAcross, h as speedAt, l as FIELD_OF_VIEW, s as stageLimits, u as cameraPosition, y as viewOf } from "./extent-BtiN2C8B.js";
|
|
2
|
+
import { a as NO_HIGHLIGHTS, d as keyAction, o as highlightOf, r as moveAt, s as isClick } from "./motion-BxV1vOEB.js";
|
|
3
3
|
import { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene, Vector2, WebGLRenderer } from "three";
|
|
4
4
|
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
5
5
|
// src/stage/stage.ts
|
|
6
|
-
/** The default vertical angle of the picture, in degrees. */
|
|
7
|
-
const FIELD_OF_VIEW = 32;
|
|
8
6
|
/** The default lights: a strong light from above and below, and a light from the front left. */
|
|
9
7
|
const STAGE_LIGHTS = {
|
|
10
8
|
sky: 2.2,
|
|
@@ -17,7 +15,10 @@ const STAGE_LIGHTS = {
|
|
|
17
15
|
};
|
|
18
16
|
/** The time of the move between two views, in milliseconds. */
|
|
19
17
|
const MOVE_TIME = 380;
|
|
20
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* The largest turn of the camera for a drag across the height of the picture, as a part of a full turn.
|
|
20
|
+
* A camera far from a ball, or with no ball, turns by this part.
|
|
21
|
+
*/
|
|
21
22
|
const TURN_SPEED = .9;
|
|
22
23
|
/** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */
|
|
23
24
|
const SMALLEST_POLAR = 5e-4;
|
|
@@ -119,11 +120,15 @@ function createStage(container, options) {
|
|
|
119
120
|
content.paint(theme, (record) => highlightOf(now, record));
|
|
120
121
|
invalidate();
|
|
121
122
|
};
|
|
122
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* This function sets the turn speed and the zoom speed from the height of the camera above the surface.
|
|
125
|
+
* The surface of a ball at the middle of the picture follows the pointer in a drag.
|
|
126
|
+
*/
|
|
123
127
|
const setSpeed = () => {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
controls.
|
|
128
|
+
const distance = camera.position.distanceTo(controls.target);
|
|
129
|
+
const surface = surfaceOf(content.extent);
|
|
130
|
+
controls.rotateSpeed = Math.min(TURN_SPEED, turnAcross(distance, surface, fieldOfView) / (2 * Math.PI));
|
|
131
|
+
controls.zoomSpeed = speedAt(distance, surface);
|
|
127
132
|
};
|
|
128
133
|
const placeNow = () => {
|
|
129
134
|
const target = {
|
|
@@ -306,7 +311,8 @@ function createStage(container, options) {
|
|
|
306
311
|
const action = keyAction(event.key, placeNow(), {
|
|
307
312
|
home: options.home,
|
|
308
313
|
views: options.keys,
|
|
309
|
-
surface: surfaceOf(content.extent)
|
|
314
|
+
surface: surfaceOf(content.extent),
|
|
315
|
+
fieldOfView
|
|
310
316
|
});
|
|
311
317
|
if (action === void 0) return;
|
|
312
318
|
event.preventDefault();
|
|
@@ -405,6 +411,43 @@ function createStage(container, options) {
|
|
|
405
411
|
}
|
|
406
412
|
};
|
|
407
413
|
}
|
|
408
|
-
|
|
414
|
+
// src/stage/stack.ts
|
|
415
|
+
/**
|
|
416
|
+
* This function makes one content from a list of contents, for a stage that shows them together.
|
|
417
|
+
* An example is a globe with a layer of labels, or a room with its marks.
|
|
418
|
+
*
|
|
419
|
+
* - The first content gives the extent: the views and the limits of the camera come from it.
|
|
420
|
+
* - The last content is on top. A pick asks the last content first, and it stops at the first record.
|
|
421
|
+
* - A record that two contents have is one record: each of them gets its highlight.
|
|
422
|
+
* - The stage disposes the stack, and the stack disposes each content.
|
|
423
|
+
*/
|
|
424
|
+
function stackContents(contents) {
|
|
425
|
+
const [first] = contents;
|
|
426
|
+
return {
|
|
427
|
+
objects: contents.flatMap((content) => content.objects),
|
|
428
|
+
get extent() {
|
|
429
|
+
return first.extent;
|
|
430
|
+
},
|
|
431
|
+
has: (record) => contents.some((content) => content.has(record)),
|
|
432
|
+
pick(ray) {
|
|
433
|
+
for (let at = contents.length - 1; at >= 0; at -= 1) {
|
|
434
|
+
const pick = contents[at]?.pick(ray);
|
|
435
|
+
if (pick !== void 0) return pick;
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
paint(theme, highlight) {
|
|
439
|
+
for (const content of contents) content.paint(theme, highlight);
|
|
440
|
+
},
|
|
441
|
+
step(frame) {
|
|
442
|
+
let active = false;
|
|
443
|
+
for (const content of contents) active = (content.step?.(frame) ?? false) || active;
|
|
444
|
+
return active;
|
|
445
|
+
},
|
|
446
|
+
dispose() {
|
|
447
|
+
for (const content of contents) content.dispose();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
export { FIELD_OF_VIEW, STAGE_LIGHTS, createStage, stackContents };
|
|
409
452
|
|
|
410
453
|
//# sourceMappingURL=three.js.map
|