@mark1russell7/visuals 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,193 @@
1
+ import { Point3 } from "@mark1russell7/layout-contract";
2
+ /**
3
+ * The direction of a view: where the camera is, as seen from the point that it looks at.
4
+ * The space of a stage has the y axis up.
5
+ */
6
+ interface ViewAngles {
7
+ /** The angle from the up axis to the camera, in radians. At 0, the camera looks down from above. */
8
+ readonly polar: number;
9
+ /** The angle around the up axis, in radians. At 0, the camera is on the positive z side of the point. */
10
+ readonly azimuth: number;
11
+ }
12
+ /** A place of a camera: the point that it looks at, the angles of its view and its distance from the point. */
13
+ interface Place extends ViewAngles {
14
+ readonly target: Point3;
15
+ readonly distance: number;
16
+ }
17
+ /** The three axes of a camera, as unit vectors in the space of the stage. */
18
+ interface ViewAxes {
19
+ /** The vector from the point that the camera looks at to the camera. */
20
+ readonly back: Point3;
21
+ /** The vector to the right side of the picture. */
22
+ readonly right: Point3;
23
+ /** The vector to the top of the picture. */
24
+ readonly up: Point3;
25
+ }
26
+ /** The limits of the place of a camera. */
27
+ interface PlaceLimits {
28
+ /** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */
29
+ readonly minPolar: number;
30
+ /** The largest polar angle. */
31
+ readonly maxPolar: number;
32
+ /** The smallest distance from the target. */
33
+ readonly minDistance: number;
34
+ /** The largest distance from the target. */
35
+ readonly maxDistance: number;
36
+ }
37
+ /** This function gives the axes of the camera of a view. At a polar angle of 0, the top of the picture is the negative z axis. */
38
+ declare function viewAxes(view: ViewAngles): ViewAxes;
39
+ /**
40
+ * This function gives the smallest distance from `target` at which a camera shows each point.
41
+ *
42
+ * The camera looks at `target` along the direction of `view`. `fov` is the vertical angle of the picture in degrees,
43
+ * and `aspect` is the width of the picture divided by its height.
44
+ * The function gives 0 for no points, and for an angle or an aspect that makes no picture.
45
+ */
46
+ declare function fitDistance(points: readonly Point3[], target: Point3, view: ViewAngles, fov: number, aspect: number): number;
47
+ /**
48
+ * This function gives the smallest distance from the center of a ball at which a camera shows a cap of the ball.
49
+ *
50
+ * The camera looks at the center of the ball, and the center of the cap is on the line to the camera.
51
+ * `radius` is the radius of the ball. `angle` is the angle of the cap at the center of the ball, in radians, from 0 to π / 2.
52
+ * `fov` is the vertical angle of the picture in degrees, and `aspect` is the width of the picture divided by its height.
53
+ * The function gives 0 for an angle or an aspect that makes no picture.
54
+ */
55
+ declare function capDistance(radius: number, angle: number, fov: number, aspect: number): number;
56
+ /** This function gives the position of a camera at a distance from `target`, in the direction of `view`. */
57
+ declare function cameraPosition(target: Point3, view: ViewAngles, distance: number): Point3;
58
+ /** This function gives the angles of the view from `target` to a camera, and the distance between them. A camera at the target gives the angles 0. */
59
+ declare function viewOf(camera: Point3, target: Point3): ViewAngles & {
60
+ readonly distance: number;
61
+ };
62
+ /** This function gives the angle between two azimuths along the shortest way, from −π to π. */
63
+ declare function turnBetween(from: number, to: number): number;
64
+ /** This function gives a place in its limits. The target and the azimuth stay as they are. */
65
+ declare function clampPlace(place: Place, limits: PlaceLimits): Place;
66
+ /**
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
+ *
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 turn speed and the zoom speed of a camera: near the surface, a camera moves slowly.
71
+ * The result is 0.02 at least, so a camera on the surface can move away.
72
+ */
73
+ declare function speedAt(distance: number, surface: number): number;
74
+ /**
75
+ * This function gives the place at a part of the way between two places. `part` goes from 0 to 1.
76
+ *
77
+ * The azimuth goes along the shortest way. The height above the surface changes by an equal factor for each equal step,
78
+ * so a zoom has one speed in the picture. `surface` is the radius of the ball around the target, or 0 for no ball.
79
+ */
80
+ declare function placeBetween(from: Place, to: Place, part: number, surface?: number): Place;
81
+ /** The space that the content of a stage fills. A view and the limits of the camera come from it. */
82
+ interface StageExtent {
83
+ /** The points that a view of all the content shows, for example each corner of each solid. */
84
+ readonly corners: readonly Point3[];
85
+ /** The point that the camera looks at. */
86
+ readonly center: Point3;
87
+ /**
88
+ * The radius of the ball around the center that the camera stays out of, for example the radius of a globe.
89
+ * The default is 0: the content has no ball.
90
+ */
91
+ readonly surface?: number | undefined;
92
+ /** The smallest distance of the camera from the center. The default comes from the views of the stage. */
93
+ readonly minDistance?: number | undefined;
94
+ /** The largest distance of the camera from the center. The default comes from the views of the stage. */
95
+ readonly maxDistance?: number | undefined;
96
+ }
97
+ /** The picture that a view is for: the content, and the angle and the shape of the picture. */
98
+ interface ViewFrame {
99
+ readonly extent: StageExtent;
100
+ /** The vertical angle of the picture, in degrees. */
101
+ readonly fieldOfView: number;
102
+ /** The width of the picture divided by its height. */
103
+ readonly aspect: number;
104
+ }
105
+ /** A view of a stage: a function that gives the place of the camera for a picture. A new size of the picture gives a new place. */
106
+ type StageView = (frame: ViewFrame) => Place;
107
+ /** The limits of the camera of a stage: the limits of its place, and the nearest and the farthest depth that it draws. */
108
+ interface StageLimits extends PlaceLimits {
109
+ readonly near: number;
110
+ readonly far: number;
111
+ }
112
+ /** The space around the content in a view that shows all of it, as a factor of the distance. */
113
+ declare const FIT_MARGIN = 1.06;
114
+ /** This function gives the radius of the ball around the center of an extent, or 0 for no ball. */
115
+ declare function surfaceOf(extent: StageExtent): number;
116
+ /**
117
+ * This function makes a view that shows each corner of the content from one direction.
118
+ * `margin` is the space around the content, as a factor of the distance. An extent with no corners gives the distance 1.
119
+ */
120
+ declare function fitView(angles: ViewAngles, margin?: number): StageView;
121
+ /**
122
+ * This function makes a view of a part of the ball of the content: a cap around the point of the ball below the camera.
123
+ *
124
+ * `angles` is the direction from the center of the ball to the camera. `angle` is the angle of the cap at the center of the ball, in radians.
125
+ * `margin` is the space around the cap, as a factor of the height above the ball. An extent with no ball gives the distance 1.
126
+ */
127
+ declare function capView(angles: ViewAngles, angle: number, margin?: number): StageView;
128
+ /**
129
+ * This function makes a view of points on the ball of the content. The camera is above the middle of the points, and the picture shows each point.
130
+ *
131
+ * The middle is the center of the box of the points. `margin` is the space around the points, as a factor of the height above the ball.
132
+ * A list with no points gives a view of all of the ball from the front. Points with their middle at the center of the ball give the same view.
133
+ */
134
+ declare function ballView(points: readonly Point3[], margin?: number): StageView;
135
+ /** This function gives the radius of the ball around the center of an extent that holds the ball of the extent and each corner. */
136
+ declare function reachOf(extent: StageExtent): number;
137
+ /**
138
+ * This function gives the nearest depth that a camera draws, from the distance of the camera to the center of the content.
139
+ *
140
+ * A camera far from the content gets a large value. The depths of the content then have more steps, so two surfaces that are near stay apart.
141
+ * The result is not less than the nearest depth of the limits, and it is in front of all the content.
142
+ */
143
+ declare function nearDepth(limits: StageLimits, extent: StageExtent, distance: number): number;
144
+ /**
145
+ * This function gives the limits of the camera of a stage for a picture.
146
+ *
147
+ * The largest distance of the views is the base. The camera goes out to 3 times this distance, and in to 3 % of the height of that view.
148
+ * The extent can give each distance. The nearest depth is small against the height of the nearest camera, and the farthest depth is behind all the content.
149
+ */
150
+ declare function stageLimits(frame: ViewFrame, views: readonly StageView[], polar: {
151
+ readonly min: number;
152
+ readonly max: number;
153
+ }): StageLimits;
154
+ /** The mark of a record. 0 is no mark. 1 is a record under the pointer or in the marked list. 2 is the selected record. */
155
+ type Mark = 0 | 1 | 2;
156
+ /** The records of a stage that have a mark. Each record has a name. */
157
+ interface Marks {
158
+ /** The name of the record under the pointer. */
159
+ readonly hovered: string | undefined;
160
+ /** The name of the selected record. */
161
+ readonly selected: string | undefined;
162
+ /** The names of the records that the page marks. */
163
+ readonly marked: ReadonlySet<string>;
164
+ }
165
+ /** The marks of a stage with no pointer on it and no selected record. */
166
+ declare const NO_MARKS: Marks;
167
+ /** This function gives the mark of a record. The selected record has the highest mark. */
168
+ declare function markOf(marks: Marks, record: string): Mark;
169
+ /** A pointer that moves this distance or less between down and up makes a click, in CSS pixels. */
170
+ declare const CLICK_DISTANCE = 4;
171
+ /**
172
+ * This function tells if a pointer that went down and up made a click. A pointer that moved more than `limit` made a drag.
173
+ * The positions and the limit are in CSS pixels.
174
+ */
175
+ declare function isClick(down: {
176
+ readonly x: number;
177
+ readonly y: number;
178
+ }, up: {
179
+ readonly x: number;
180
+ readonly y: number;
181
+ }, limit?: number): boolean;
182
+ /**
183
+ * The colors that each stage uses. Each color is a CSS hex color, for example `#22364a`.
184
+ * A stage has no background: the page shows behind the content. The theme of a content adds its own colors.
185
+ */
186
+ interface StageTheme {
187
+ /** The color of the light from above. */
188
+ readonly sky: string;
189
+ /** The color of the light from below. */
190
+ readonly ground: string;
191
+ }
192
+ export { turnBetween as A, ViewAxes as C, fitDistance as D, clampPlace as E, viewOf as M, placeBetween as O, ViewAngles as S, capDistance as T, reachOf as _, NO_MARKS as a, Place as b, FIT_MARGIN as c, StageView as d, ViewFrame as f, nearDepth as g, fitView as h, Marks as i, viewAxes as j, speedAt as k, StageExtent as l, capView as m, CLICK_DISTANCE as n, isClick as o, ballView as p, Mark as r, markOf as s, StageTheme as t, StageLimits as u, stageLimits as v, cameraPosition as w, PlaceLimits as x, surfaceOf as y };
193
+ //# sourceMappingURL=theme-CJ2SAcHX.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-CJ2SAcHX.d.ts","names":[],"sources":["../src/view.ts","../src/extent.ts","../src/marks.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;;;;;;;iBAW1B,aAAa,MAAM,OAAO,IAAI,OAAO,cAAc,mBAAsB;;UCnJxE;;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,QAAQ;;;cAIN,UAAU;;iBAGP,OAAO,OAAO,OAAO,iBAAiB;;cAMzC;;;;;iBAMG,QAAQ;WAAiB;WAAoB;GAAa;WAAe;WAAoB;GAAa;;;;;UCzBzG;;WAEN;;WAEA"}
@@ -0,0 +1,2 @@
1
+ import { a as StageFrame, c as StagePick, i as StageContent, l as createStage, n as STAGE_LIGHTS, o as StageLights, r as Stage, s as StageOptions, t as FIELD_OF_VIEW } from "./stage-C9NHD-6Q.js";
2
+ export { FIELD_OF_VIEW, STAGE_LIGHTS, type Stage, type StageContent, type StageFrame, type StageLights, type StageOptions, type StagePick, createStage };
package/build/three.js ADDED
@@ -0,0 +1,410 @@
1
+ import { _ as viewOf, a as nearDepth, c as surfaceOf, d as clampPlace, l as cameraPosition, m as speedAt, s as stageLimits } from "./extent-CALhBZU-.js";
2
+ import { a as NO_MARKS, o as isClick, r as moveAt, s as markOf, u as keyAction } from "./motion-BwDDtx3D.js";
3
+ import { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene, Vector2, WebGLRenderer } from "three";
4
+ import { OrbitControls } from "three/addons/controls/OrbitControls.js";
5
+ // src/stage/stage.ts
6
+ /** The default vertical angle of the picture, in degrees. */
7
+ const FIELD_OF_VIEW = 32;
8
+ /** The default lights: a strong light from above and below, and a light from the front left. */
9
+ const STAGE_LIGHTS = {
10
+ sky: 2.2,
11
+ sun: 1.5,
12
+ from: {
13
+ x: -10,
14
+ y: 24,
15
+ z: 15
16
+ }
17
+ };
18
+ /** The time of the move between two views, in milliseconds. */
19
+ const MOVE_TIME = 380;
20
+ /** The turn of the camera for a drag across the height of the picture, as a part of a full turn, far from the surface. */
21
+ const TURN_SPEED = .9;
22
+ /** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */
23
+ const SMALLEST_POLAR = 5e-4;
24
+ /** The default largest polar angle: the camera stays above the plane of the target. */
25
+ const LARGEST_POLAR = Math.PI / 2 - .05;
26
+ /** This function tells if the person asks for less motion. */
27
+ function lessMotion() {
28
+ return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
29
+ }
30
+ /**
31
+ * This function makes a stage in a container of a page. The stage fills the container, so give the container a size.
32
+ *
33
+ * A person turns the content with a drag, and moves nearer with the wheel after a click in the picture.
34
+ * A click selects the record under the pointer. With the keyboard, the arrow keys turn the content, `+` and `-` change the distance,
35
+ * and `Home` shows the first view. The stage makes a picture only after a change.
36
+ *
37
+ * The function gives `undefined` when the browser has no WebGL 2. It does not throw, and it writes no error to the console.
38
+ * The page then shows a different picture of the same data.
39
+ */
40
+ function createStage(container, options) {
41
+ const canvas = container.ownerDocument.createElement("canvas");
42
+ const context = canvas.getContext("webgl2", {
43
+ alpha: true,
44
+ antialias: true,
45
+ depth: true,
46
+ stencil: false,
47
+ premultipliedAlpha: true,
48
+ powerPreference: "default"
49
+ });
50
+ if (context === null) return void 0;
51
+ let renderer;
52
+ try {
53
+ renderer = new WebGLRenderer({
54
+ canvas,
55
+ context,
56
+ alpha: true,
57
+ antialias: true
58
+ });
59
+ } catch {
60
+ return;
61
+ }
62
+ renderer.setClearColor(0, 0);
63
+ canvas.style.display = "block";
64
+ canvas.style.width = "100%";
65
+ canvas.style.height = "100%";
66
+ canvas.style.cursor = "grab";
67
+ canvas.style.touchAction = "none";
68
+ canvas.tabIndex = 0;
69
+ canvas.setAttribute("role", "application");
70
+ canvas.setAttribute("aria-label", options.label);
71
+ container.append(canvas);
72
+ const fieldOfView = options.fieldOfView ?? 32;
73
+ const polar = {
74
+ min: options.polar?.min ?? SMALLEST_POLAR,
75
+ max: options.polar?.max ?? LARGEST_POLAR
76
+ };
77
+ const lights = options.lights ?? STAGE_LIGHTS;
78
+ const world = new Scene();
79
+ const sky = new HemisphereLight("#ffffff", "#ffffff", lights.sky);
80
+ const sun = new DirectionalLight("#ffffff", lights.sun);
81
+ sun.position.set(lights.from.x, lights.from.y, lights.from.z);
82
+ world.add(sky, sun);
83
+ const camera = new PerspectiveCamera(fieldOfView, 1, .05, 1e3);
84
+ let content = options.content;
85
+ let theme = options.theme;
86
+ for (const object of content.objects) world.add(object);
87
+ let marks = NO_MARKS;
88
+ let view = options.home;
89
+ let move;
90
+ /** This value is true after a person moved the view. Then a new size of the container does not move the camera. */
91
+ let moved = false;
92
+ /** This value is true until the content had a step with no time. */
93
+ let settle = true;
94
+ /** The height of the picture, in CSS pixels. */
95
+ let height = 1;
96
+ let frame = 0;
97
+ let lastTime = 0;
98
+ let disposed = false;
99
+ const invalidate = () => {
100
+ if (frame === 0 && !disposed) frame = requestAnimationFrame(tick);
101
+ };
102
+ const controls = new OrbitControls(camera, canvas);
103
+ controls.enableDamping = !lessMotion();
104
+ controls.dampingFactor = .14;
105
+ controls.minPolarAngle = polar.min;
106
+ controls.maxPolarAngle = polar.max;
107
+ controls.rotateSpeed = TURN_SPEED;
108
+ controls.screenSpacePanning = true;
109
+ controls.enablePan = options.pan ?? true;
110
+ controls.enableZoom = false;
111
+ const viewFrame = () => ({
112
+ extent: content.extent,
113
+ fieldOfView,
114
+ aspect: camera.aspect
115
+ });
116
+ let limits = stageLimits(viewFrame(), Object.values(options.views), polar);
117
+ const paint = () => {
118
+ const now = marks;
119
+ content.paint(theme, (record) => markOf(now, record));
120
+ invalidate();
121
+ };
122
+ /** This function sets the turn speed and the zoom speed from the height of the camera above the surface. */
123
+ const setSpeed = () => {
124
+ const speed = speedAt(camera.position.distanceTo(controls.target), surfaceOf(content.extent));
125
+ controls.rotateSpeed = TURN_SPEED * speed;
126
+ controls.zoomSpeed = speed;
127
+ };
128
+ const placeNow = () => {
129
+ const target = {
130
+ x: controls.target.x,
131
+ y: controls.target.y,
132
+ z: controls.target.z
133
+ };
134
+ return {
135
+ target,
136
+ ...viewOf(camera.position, target)
137
+ };
138
+ };
139
+ const put = (to) => {
140
+ const next = clampPlace(to, limits);
141
+ const eye = cameraPosition(next.target, next, next.distance);
142
+ controls.target.set(next.target.x, next.target.y, next.target.z);
143
+ camera.position.set(eye.x, eye.y, eye.z);
144
+ camera.lookAt(controls.target);
145
+ setSpeed();
146
+ };
147
+ /** This function gives the view function of a view, or `undefined` for a name that the options do not have. */
148
+ const viewFunction = (of) => typeof of === "string" ? options.views[of] : of;
149
+ /**
150
+ * This function sets the nearest depth that the camera draws, from the distance of the camera to the content.
151
+ * A camera far from the content then has small steps of depth at the content, so a layer near a surface stays above it.
152
+ */
153
+ const setDepth = () => {
154
+ const { center } = content.extent;
155
+ const distance = Math.hypot(camera.position.x - center.x, camera.position.y - center.y, camera.position.z - center.z);
156
+ const near = nearDepth(limits, content.extent, distance);
157
+ if (near === camera.near && limits.far === camera.far) return;
158
+ camera.near = near;
159
+ camera.far = limits.far;
160
+ camera.updateProjectionMatrix();
161
+ };
162
+ /** This function sets the limits of the camera from the content and the shape of the picture. */
163
+ const setLimits = () => {
164
+ limits = stageLimits(viewFrame(), Object.values(options.views), polar);
165
+ controls.minDistance = limits.minDistance;
166
+ controls.maxDistance = limits.maxDistance;
167
+ setDepth();
168
+ };
169
+ /**
170
+ * This function stops the turn that continues after a drag. The camera stays where it is.
171
+ * Without it, the camera continues to turn after a move to a view, and the view is not exact.
172
+ */
173
+ const stopDrift = () => {
174
+ if (!controls.enableDamping) return;
175
+ const now = placeNow();
176
+ controls.enableDamping = false;
177
+ controls.update();
178
+ controls.enableDamping = true;
179
+ put(now);
180
+ };
181
+ const goTo = (next, animate) => {
182
+ const found = viewFunction(next);
183
+ if (found === void 0) return;
184
+ view = next;
185
+ moved = false;
186
+ stopDrift();
187
+ const to = found(viewFrame());
188
+ if (animate && !lessMotion()) move = {
189
+ from: placeNow(),
190
+ to,
191
+ start: performance.now(),
192
+ duration: MOVE_TIME
193
+ };
194
+ else {
195
+ move = void 0;
196
+ put(to);
197
+ }
198
+ invalidate();
199
+ };
200
+ /** This function sets the size of the picture from the size of the container. It gives false for a container with no size. */
201
+ const setSize = () => {
202
+ const width = container.clientWidth;
203
+ const tall = container.clientHeight;
204
+ if (width === 0 || tall === 0) return false;
205
+ height = tall;
206
+ renderer.setPixelRatio(Math.min(globalThis.devicePixelRatio, 2));
207
+ renderer.setSize(width, tall, false);
208
+ camera.aspect = width / tall;
209
+ camera.updateProjectionMatrix();
210
+ return true;
211
+ };
212
+ /** This function moves the camera one step of a move between two views. It gives true while the move continues. */
213
+ const stepMove = (now) => {
214
+ if (move === void 0) return false;
215
+ const step = moveAt(move, now, surfaceOf(content.extent));
216
+ put(step.place);
217
+ if (step.done) move = void 0;
218
+ return true;
219
+ };
220
+ function tick(now) {
221
+ frame = 0;
222
+ if (disposed) return;
223
+ const seconds = lastTime === 0 ? 1 / 60 : Math.min((now - lastTime) / 1e3, .1);
224
+ let active = stepMove(now);
225
+ setSpeed();
226
+ active = controls.update() || active;
227
+ setDepth();
228
+ const stepped = content.step?.({
229
+ camera,
230
+ seconds,
231
+ settle: settle || lessMotion(),
232
+ height,
233
+ fieldOfView
234
+ }) ?? false;
235
+ settle = false;
236
+ renderer.render(world, camera);
237
+ active = stepped || active;
238
+ lastTime = active ? now : 0;
239
+ if (active) invalidate();
240
+ }
241
+ const raycaster = new Raycaster();
242
+ const pointer = new Vector2();
243
+ /** This function gives the record under a pointer. */
244
+ const pickAt = (event) => {
245
+ const box = canvas.getBoundingClientRect();
246
+ if (box.width === 0 || box.height === 0) return void 0;
247
+ pointer.set((event.clientX - box.left) / box.width * 2 - 1, 1 - (event.clientY - box.top) / box.height * 2);
248
+ raycaster.setFromCamera(pointer, camera);
249
+ return content.pick(raycaster);
250
+ };
251
+ const setHover = (pick) => {
252
+ const record = pick?.record;
253
+ if (record === marks.hovered) return;
254
+ marks = {
255
+ ...marks,
256
+ hovered: record
257
+ };
258
+ canvas.style.cursor = record === void 0 ? "grab" : "pointer";
259
+ paint();
260
+ options.onHover?.(pick?.value);
261
+ };
262
+ const listeners = new AbortController();
263
+ const signal = listeners.signal;
264
+ let down;
265
+ const setInUse = (inUse) => {
266
+ controls.enableZoom = inUse;
267
+ };
268
+ canvas.addEventListener("pointerdown", (event) => {
269
+ setInUse(true);
270
+ canvas.focus({ preventScroll: true });
271
+ down = {
272
+ id: event.pointerId,
273
+ x: event.clientX,
274
+ y: event.clientY
275
+ };
276
+ }, { signal });
277
+ canvas.addEventListener("pointermove", (event) => {
278
+ if (event.buttons === 0 && event.pointerType !== "touch") setHover(pickAt(event));
279
+ }, { signal });
280
+ canvas.addEventListener("pointerup", (event) => {
281
+ const start = down;
282
+ down = void 0;
283
+ if (start === void 0 || start.id !== event.pointerId) return;
284
+ if (!isClick(start, {
285
+ x: event.clientX,
286
+ y: event.clientY
287
+ })) return;
288
+ const pick = pickAt(event);
289
+ marks = {
290
+ ...marks,
291
+ selected: pick?.record
292
+ };
293
+ paint();
294
+ options.onSelect?.(pick?.value);
295
+ }, { signal });
296
+ canvas.addEventListener("pointercancel", () => {
297
+ down = void 0;
298
+ }, { signal });
299
+ canvas.addEventListener("pointerleave", (event) => {
300
+ setHover(void 0);
301
+ if (event.pointerType === "mouse") setInUse(false);
302
+ }, { signal });
303
+ canvas.addEventListener("blur", () => setInUse(false), { signal });
304
+ canvas.addEventListener("keydown", (event) => {
305
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
306
+ const action = keyAction(event.key, placeNow(), {
307
+ home: options.home,
308
+ views: options.keys,
309
+ surface: surfaceOf(content.extent)
310
+ });
311
+ if (action === void 0) return;
312
+ event.preventDefault();
313
+ setInUse(true);
314
+ if (action.type === "view") {
315
+ goTo(action.view, true);
316
+ return;
317
+ }
318
+ moved = true;
319
+ move = void 0;
320
+ stopDrift();
321
+ put(action.place);
322
+ invalidate();
323
+ }, { signal });
324
+ canvas.addEventListener("webglcontextlost", (event) => event.preventDefault(), { signal });
325
+ canvas.addEventListener("webglcontextrestored", invalidate, { signal });
326
+ controls.addEventListener("start", () => {
327
+ moved = true;
328
+ move = void 0;
329
+ canvas.style.cursor = "grabbing";
330
+ invalidate();
331
+ });
332
+ controls.addEventListener("end", () => {
333
+ canvas.style.cursor = marks.hovered === void 0 ? "grab" : "pointer";
334
+ });
335
+ controls.addEventListener("change", invalidate);
336
+ const applyTheme = () => {
337
+ sky.color.set(theme.sky);
338
+ sky.groundColor.set(theme.ground);
339
+ paint();
340
+ };
341
+ const observer = new ResizeObserver(() => {
342
+ if (disposed || !setSize()) return;
343
+ setLimits();
344
+ if (!moved) goTo(view, false);
345
+ invalidate();
346
+ });
347
+ setSize();
348
+ setLimits();
349
+ goTo(options.home, false);
350
+ applyTheme();
351
+ observer.observe(container);
352
+ return {
353
+ canvas,
354
+ setContent(next) {
355
+ if (disposed || next === content) return;
356
+ for (const object of content.objects) world.remove(object);
357
+ content.dispose();
358
+ content = next;
359
+ for (const object of content.objects) world.add(object);
360
+ const selected = marks.selected !== void 0 && content.has(marks.selected) ? marks.selected : void 0;
361
+ marks = {
362
+ ...marks,
363
+ hovered: void 0,
364
+ selected
365
+ };
366
+ settle = true;
367
+ setLimits();
368
+ if (!moved) goTo(view, false);
369
+ paint();
370
+ },
371
+ setTheme(next) {
372
+ theme = next;
373
+ applyTheme();
374
+ },
375
+ setView(next, animate = true) {
376
+ goTo(next, animate);
377
+ },
378
+ place: placeNow,
379
+ highlight(records) {
380
+ marks = {
381
+ ...marks,
382
+ marked: new Set(records)
383
+ };
384
+ paint();
385
+ },
386
+ select(record) {
387
+ marks = {
388
+ ...marks,
389
+ selected: record
390
+ };
391
+ paint();
392
+ },
393
+ refresh: paint,
394
+ dispose() {
395
+ if (disposed) return;
396
+ disposed = true;
397
+ cancelAnimationFrame(frame);
398
+ observer.disconnect();
399
+ listeners.abort();
400
+ controls.dispose();
401
+ for (const object of content.objects) world.remove(object);
402
+ content.dispose();
403
+ renderer.dispose();
404
+ canvas.remove();
405
+ }
406
+ };
407
+ }
408
+ export { FIELD_OF_VIEW, STAGE_LIGHTS, createStage };
409
+
410
+ //# sourceMappingURL=three.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"three.js","names":["World"],"sources":["../src/stage/stage.ts"],"sourcesContent":["import { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene as World, Vector2, WebGLRenderer, type Object3D } from \"three\";\nimport { OrbitControls } from \"three/addons/controls/OrbitControls.js\";\nimport { nearDepth, stageLimits, surfaceOf, type StageExtent, type StageLimits, type StageView, type ViewFrame } from \"../extent.ts\";\nimport { keyAction } from \"../keys.ts\";\nimport { isClick, markOf, NO_MARKS, type Mark, type Marks } from \"../marks.ts\";\nimport { moveAt, type Move } from \"../motion.ts\";\nimport type { StageTheme } from \"../theme.ts\";\nimport { cameraPosition, clampPlace, speedAt, viewOf, type Place } from \"../view.ts\";\n\n/** The record under the pointer: its name, and the value that the content gives for it. */\nexport interface StagePick<P> {\n /** The name of the record. The marks of the stage use this name. */\n readonly record: string;\n /** The value of the record for the page, for example its kind and its source. */\n readonly value: P;\n}\n\n/** One picture of a stage, for the step of its content. */\nexport interface StageFrame {\n readonly camera: PerspectiveCamera;\n /** The time since the last picture, in seconds. */\n readonly seconds: number;\n /**\n * This value is true for the first picture of a content, and for a person who asks for less motion.\n * Each change then has no time: the content sets each value to its goal immediately.\n */\n readonly settle: boolean;\n /** The height of the picture, in CSS pixels. */\n readonly height: number;\n /** The vertical angle of the picture, in degrees. */\n readonly fieldOfView: number;\n}\n\n/**\n * The content of a stage: the three.js objects of one scene, and what the stage asks of them.\n * `P` is the type of the value of a pick, and `T` is the type of the theme.\n */\nexport interface StageContent<P, T extends StageTheme = StageTheme> {\n /** The three.js objects of the content. The stage adds them to its world, and removes them. */\n readonly objects: readonly Object3D[];\n /** The space that the content fills. */\n readonly extent: StageExtent;\n /** This function tells if the content has a record with a name. */\n has(record: string): boolean;\n /** This function gives the record that a ray from the camera finds first, or `undefined` for no record. */\n pick(ray: Raycaster): StagePick<P> | undefined;\n /** This function gives each part its colors, from the theme and the mark of its record. */\n paint(theme: T, mark: (record: string) => Mark): void;\n /**\n * This function changes the parts that depend on the camera or on the time, before each picture.\n * It gives true while a part continues to change. The stage then makes the next picture.\n */\n step?(frame: StageFrame): boolean;\n /** This function releases the memory of the graphics card that the content uses. */\n dispose(): void;\n}\n\n/** The lights of a stage. A content with materials that use no light ignores them. */\nexport interface StageLights {\n /** The strength of the light from above and below. */\n readonly sky: number;\n /** The strength of the light from one direction. */\n readonly sun: number;\n /** The position that the light from one direction comes from. */\n readonly from: { readonly x: number; readonly y: number; readonly z: number };\n}\n\n/** The options of a stage. */\nexport interface StageOptions<P, T extends StageTheme = StageTheme> {\n /** The first content. The stage disposes each content that it gets. */\n readonly content: StageContent<P, T>;\n readonly theme: T;\n /** The name of the picture for a screen reader. */\n readonly label: string;\n /** The views of the stage, each with a name. */\n readonly views: Readonly<Record<string, StageView>>;\n /** The name of the first view. The keys `Home` and `0` show it. */\n readonly home: string;\n /** The name of the view of a key, for example `{ t: \"top\" }`. A letter has no case. */\n readonly keys?: Readonly<Record<string, string>> | undefined;\n /** The vertical angle of the picture, in degrees. A small angle gives the look of a drawing. The default is 32. */\n readonly fieldOfView?: number | undefined;\n /** The smallest and the largest polar angle of the camera, in radians. The default keeps the camera above the plane of the target. */\n readonly polar?: { readonly min?: number | undefined; readonly max?: number | undefined } | undefined;\n /** This value is true if a person can move the target with a drag of the second button. The default is true. */\n readonly pan?: boolean | undefined;\n readonly lights?: StageLights | undefined;\n /** The stage starts this function when the pointer goes to a different record, or to no record. */\n readonly onHover?: ((pick: P | undefined) => void) | undefined;\n /** The stage starts this function when a person selects a record with the pointer, or selects no record. */\n readonly onSelect?: ((pick: P | undefined) => void) | undefined;\n}\n\n/** A stage in a page: one canvas with a camera that a person moves, and one content. */\nexport interface Stage<P, T extends StageTheme = StageTheme> {\n /** The canvas of the stage. It is in the container. */\n readonly canvas: HTMLCanvasElement;\n /** This function shows a different content, and disposes the old content. The view stays if a person moved it. */\n setContent(content: StageContent<P, T>): void;\n /** This function changes the colors. */\n setTheme(theme: T): void;\n /** This function moves the camera to a view: a name of the options, or a view function. `animate` has the default true. */\n setView(view: string | StageView, animate?: boolean): void;\n /** This function gives the place of the camera. */\n place(): Place;\n /** This function marks records by their names, as the pointer does. An empty list removes the marks. */\n highlight(records: readonly string[]): void;\n /** This function selects one record by its name, or no record. It does not start `onSelect`. */\n select(record: string | undefined): void;\n /** This function paints the content again and makes a new picture. Use it after a change of the content. */\n refresh(): void;\n /** This function removes the canvas and releases the memory of the graphics card. It disposes the content. */\n dispose(): void;\n}\n\n/** The default vertical angle of the picture, in degrees. */\nexport const FIELD_OF_VIEW = 32;\n\n/** The default lights: a strong light from above and below, and a light from the front left. */\nexport const STAGE_LIGHTS: StageLights = { sky: 2.2, sun: 1.5, from: { x: -10, y: 24, z: 15 } };\n\n/** The time of the move between two views, in milliseconds. */\nconst MOVE_TIME = 380;\n\n/** The turn of the camera for a drag across the height of the picture, as a part of a full turn, far from the surface. */\nconst TURN_SPEED = 0.9;\n\n/** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */\nconst SMALLEST_POLAR = 0.0005;\n\n/** The default largest polar angle: the camera stays above the plane of the target. */\nconst LARGEST_POLAR = Math.PI / 2 - 0.05;\n\n/** This function tells if the person asks for less motion. */\nfunction lessMotion(): boolean {\n return typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\n/**\n * This function makes a stage in a container of a page. The stage fills the container, so give the container a size.\n *\n * A person turns the content with a drag, and moves nearer with the wheel after a click in the picture.\n * A click selects the record under the pointer. With the keyboard, the arrow keys turn the content, `+` and `-` change the distance,\n * and `Home` shows the first view. The stage makes a picture only after a change.\n *\n * The function gives `undefined` when the browser has no WebGL 2. It does not throw, and it writes no error to the console.\n * The page then shows a different picture of the same data.\n */\nexport function createStage<P, T extends StageTheme = StageTheme>(container: HTMLElement, options: StageOptions<P, T>): Stage<P, T> | undefined {\n const canvas = container.ownerDocument.createElement(\"canvas\");\n const context = canvas.getContext(\"webgl2\", { alpha: true, antialias: true, depth: true, stencil: false, premultipliedAlpha: true, powerPreference: \"default\" });\n if (context === null) return undefined;\n let renderer: WebGLRenderer;\n try {\n renderer = new WebGLRenderer({ canvas, context, alpha: true, antialias: true });\n } catch {\n return undefined;\n }\n renderer.setClearColor(0x000000, 0);\n\n canvas.style.display = \"block\";\n canvas.style.width = \"100%\";\n canvas.style.height = \"100%\";\n canvas.style.cursor = \"grab\";\n canvas.style.touchAction = \"none\";\n canvas.tabIndex = 0;\n canvas.setAttribute(\"role\", \"application\");\n canvas.setAttribute(\"aria-label\", options.label);\n container.append(canvas);\n\n const fieldOfView = options.fieldOfView ?? FIELD_OF_VIEW;\n const polar = { min: options.polar?.min ?? SMALLEST_POLAR, max: options.polar?.max ?? LARGEST_POLAR };\n const lights = options.lights ?? STAGE_LIGHTS;\n const world = new World();\n const sky = new HemisphereLight(\"#ffffff\", \"#ffffff\", lights.sky);\n const sun = new DirectionalLight(\"#ffffff\", lights.sun);\n sun.position.set(lights.from.x, lights.from.y, lights.from.z);\n world.add(sky, sun);\n const camera = new PerspectiveCamera(fieldOfView, 1, 0.05, 1000);\n\n let content = options.content;\n let theme = options.theme;\n for (const object of content.objects) world.add(object);\n\n let marks: Marks = NO_MARKS;\n let view: string | StageView = options.home;\n let move: Move | undefined;\n /** This value is true after a person moved the view. Then a new size of the container does not move the camera. */\n let moved = false;\n /** This value is true until the content had a step with no time. */\n let settle = true;\n /** The height of the picture, in CSS pixels. */\n let height = 1;\n let frame = 0;\n let lastTime = 0;\n let disposed = false;\n\n const invalidate = (): void => {\n if (frame === 0 && !disposed) frame = requestAnimationFrame(tick);\n };\n\n const controls = new OrbitControls(camera, canvas);\n controls.enableDamping = !lessMotion();\n controls.dampingFactor = 0.14;\n controls.minPolarAngle = polar.min;\n controls.maxPolarAngle = polar.max;\n controls.rotateSpeed = TURN_SPEED;\n controls.screenSpacePanning = true;\n controls.enablePan = options.pan ?? true;\n // The wheel moves the page until a person uses the picture. Thus the picture does not stop a person who reads down the page.\n controls.enableZoom = false;\n\n const viewFrame = (): ViewFrame => ({ extent: content.extent, fieldOfView, aspect: camera.aspect });\n let limits: StageLimits = stageLimits(viewFrame(), Object.values(options.views), polar);\n\n const paint = (): void => {\n const now = marks;\n content.paint(theme, (record) => markOf(now, record));\n invalidate();\n };\n\n /** This function sets the turn speed and the zoom speed from the height of the camera above the surface. */\n const setSpeed = (): void => {\n const speed = speedAt(camera.position.distanceTo(controls.target), surfaceOf(content.extent));\n controls.rotateSpeed = TURN_SPEED * speed;\n controls.zoomSpeed = speed;\n };\n const placeNow = (): Place => {\n const target = { x: controls.target.x, y: controls.target.y, z: controls.target.z };\n return { target, ...viewOf(camera.position, target) };\n };\n const put = (to: Place): void => {\n const next = clampPlace(to, limits);\n const eye = cameraPosition(next.target, next, next.distance);\n controls.target.set(next.target.x, next.target.y, next.target.z);\n camera.position.set(eye.x, eye.y, eye.z);\n camera.lookAt(controls.target);\n setSpeed();\n };\n /** This function gives the view function of a view, or `undefined` for a name that the options do not have. */\n const viewFunction = (of: string | StageView): StageView | undefined => (typeof of === \"string\" ? options.views[of] : of);\n\n /**\n * This function sets the nearest depth that the camera draws, from the distance of the camera to the content.\n * A camera far from the content then has small steps of depth at the content, so a layer near a surface stays above it.\n */\n const setDepth = (): void => {\n const { center } = content.extent;\n const distance = Math.hypot(camera.position.x - center.x, camera.position.y - center.y, camera.position.z - center.z);\n const near = nearDepth(limits, content.extent, distance);\n if (near === camera.near && limits.far === camera.far) return;\n camera.near = near;\n camera.far = limits.far;\n camera.updateProjectionMatrix();\n };\n /** This function sets the limits of the camera from the content and the shape of the picture. */\n const setLimits = (): void => {\n limits = stageLimits(viewFrame(), Object.values(options.views), polar);\n controls.minDistance = limits.minDistance;\n controls.maxDistance = limits.maxDistance;\n setDepth();\n };\n /**\n * This function stops the turn that continues after a drag. The camera stays where it is.\n * Without it, the camera continues to turn after a move to a view, and the view is not exact.\n */\n const stopDrift = (): void => {\n if (!controls.enableDamping) return;\n const now = placeNow();\n // With no damping, an update of the controls uses all of the turn that remains. The camera then goes back.\n controls.enableDamping = false;\n controls.update();\n controls.enableDamping = true;\n put(now);\n };\n const goTo = (next: string | StageView, animate: boolean): void => {\n const found = viewFunction(next);\n if (found === undefined) return;\n view = next;\n moved = false;\n stopDrift();\n const to = found(viewFrame());\n if (animate && !lessMotion()) {\n move = { from: placeNow(), to, start: performance.now(), duration: MOVE_TIME };\n } else {\n move = undefined;\n put(to);\n }\n invalidate();\n };\n\n /** This function sets the size of the picture from the size of the container. It gives false for a container with no size. */\n const setSize = (): boolean => {\n const width = container.clientWidth;\n const tall = container.clientHeight;\n if (width === 0 || tall === 0) return false;\n height = tall;\n renderer.setPixelRatio(Math.min(globalThis.devicePixelRatio, 2));\n renderer.setSize(width, tall, false);\n camera.aspect = width / tall;\n camera.updateProjectionMatrix();\n return true;\n };\n\n /** This function moves the camera one step of a move between two views. It gives true while the move continues. */\n const stepMove = (now: number): boolean => {\n if (move === undefined) return false;\n const step = moveAt(move, now, surfaceOf(content.extent));\n put(step.place);\n if (step.done) move = undefined;\n return true;\n };\n\n function tick(now: number): void {\n frame = 0;\n if (disposed) return;\n const seconds = lastTime === 0 ? 1 / 60 : Math.min((now - lastTime) / 1000, 0.1);\n let active = stepMove(now);\n setSpeed();\n active = controls.update() || active;\n setDepth();\n const stepped = content.step?.({ camera, seconds, settle: settle || lessMotion(), height, fieldOfView }) ?? false;\n settle = false;\n renderer.render(world, camera);\n active = stepped || active;\n lastTime = active ? now : 0;\n if (active) invalidate();\n }\n\n const raycaster = new Raycaster();\n const pointer = new Vector2();\n /** This function gives the record under a pointer. */\n const pickAt = (event: PointerEvent): StagePick<P> | undefined => {\n const box = canvas.getBoundingClientRect();\n if (box.width === 0 || box.height === 0) return undefined;\n pointer.set(((event.clientX - box.left) / box.width) * 2 - 1, 1 - ((event.clientY - box.top) / box.height) * 2);\n raycaster.setFromCamera(pointer, camera);\n return content.pick(raycaster);\n };\n\n const setHover = (pick: StagePick<P> | undefined): void => {\n const record = pick?.record;\n if (record === marks.hovered) return;\n marks = { ...marks, hovered: record };\n canvas.style.cursor = record === undefined ? \"grab\" : \"pointer\";\n paint();\n options.onHover?.(pick?.value);\n };\n\n const listeners = new AbortController();\n const signal = listeners.signal;\n let down: { readonly id: number; readonly x: number; readonly y: number } | undefined;\n const setInUse = (inUse: boolean): void => {\n controls.enableZoom = inUse;\n };\n canvas.addEventListener(\n \"pointerdown\",\n (event) => {\n setInUse(true);\n canvas.focus({ preventScroll: true });\n down = { id: event.pointerId, x: event.clientX, y: event.clientY };\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointermove\",\n (event) => {\n if (event.buttons === 0 && event.pointerType !== \"touch\") setHover(pickAt(event));\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerup\",\n (event) => {\n const start = down;\n down = undefined;\n if (start === undefined || start.id !== event.pointerId) return;\n if (!isClick(start, { x: event.clientX, y: event.clientY })) return;\n const pick = pickAt(event);\n marks = { ...marks, selected: pick?.record };\n paint();\n options.onSelect?.(pick?.value);\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointercancel\",\n () => {\n down = undefined;\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerleave\",\n (event) => {\n setHover(undefined);\n if (event.pointerType === \"mouse\") setInUse(false);\n },\n { signal },\n );\n canvas.addEventListener(\"blur\", () => setInUse(false), { signal });\n canvas.addEventListener(\n \"keydown\",\n (event) => {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const action = keyAction(event.key, placeNow(), { home: options.home, views: options.keys, surface: surfaceOf(content.extent) });\n if (action === undefined) return;\n event.preventDefault();\n setInUse(true);\n if (action.type === \"view\") {\n goTo(action.view, true);\n return;\n }\n moved = true;\n move = undefined;\n stopDrift();\n put(action.place);\n invalidate();\n },\n { signal },\n );\n canvas.addEventListener(\"webglcontextlost\", (event) => event.preventDefault(), { signal });\n canvas.addEventListener(\"webglcontextrestored\", invalidate, { signal });\n\n controls.addEventListener(\"start\", () => {\n moved = true;\n move = undefined;\n canvas.style.cursor = \"grabbing\";\n invalidate();\n });\n controls.addEventListener(\"end\", () => {\n canvas.style.cursor = marks.hovered === undefined ? \"grab\" : \"pointer\";\n });\n controls.addEventListener(\"change\", invalidate);\n\n const applyTheme = (): void => {\n sky.color.set(theme.sky);\n sky.groundColor.set(theme.ground);\n paint();\n };\n\n const observer = new ResizeObserver(() => {\n if (disposed || !setSize()) return;\n setLimits();\n if (!moved) goTo(view, false);\n invalidate();\n });\n\n setSize();\n setLimits();\n goTo(options.home, false);\n applyTheme();\n observer.observe(container);\n\n return {\n canvas,\n setContent(next: StageContent<P, T>): void {\n if (disposed || next === content) return;\n for (const object of content.objects) world.remove(object);\n content.dispose();\n content = next;\n for (const object of content.objects) world.add(object);\n const selected = marks.selected !== undefined && content.has(marks.selected) ? marks.selected : undefined;\n marks = { ...marks, hovered: undefined, selected };\n settle = true;\n setLimits();\n if (!moved) goTo(view, false);\n paint();\n },\n setTheme(next: T): void {\n theme = next;\n applyTheme();\n },\n setView(next: string | StageView, animate: boolean = true): void {\n goTo(next, animate);\n },\n place: placeNow,\n highlight(records: readonly string[]): void {\n marks = { ...marks, marked: new Set(records) };\n paint();\n },\n select(record: string | undefined): void {\n marks = { ...marks, selected: record };\n paint();\n },\n refresh: paint,\n dispose(): void {\n if (disposed) return;\n disposed = true;\n cancelAnimationFrame(frame);\n observer.disconnect();\n listeners.abort();\n controls.dispose();\n for (const object of content.objects) world.remove(object);\n content.dispose();\n renderer.dispose();\n canvas.remove();\n },\n };\n}\n"],"mappings":";;;;;;AAoHA,MAAa,gBAAgB;;AAG7B,MAAa,eAA4B;CAAE,KAAK;CAAK,KAAK;CAAK,MAAM;EAAE,GAAG;EAAK,GAAG;EAAI,GAAG;CAAG;AAAE;;AAG9F,MAAM,YAAY;;AAGlB,MAAM,aAAa;;AAGnB,MAAM,iBAAiB;;AAGvB,MAAM,gBAAgB,KAAK,KAAK,IAAI;;AAGpC,SAAS,aAAsB;CAC7B,OAAO,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;AAC5F;;;;;;;;;;;AAYA,SAAgB,YAAkD,WAAwB,SAAsD;CAC9I,MAAM,SAAS,UAAU,cAAc,cAAc,QAAQ;CAC7D,MAAM,UAAU,OAAO,WAAW,UAAU;EAAE,OAAO;EAAM,WAAW;EAAM,OAAO;EAAM,SAAS;EAAO,oBAAoB;EAAM,iBAAiB;CAAU,CAAC;CAC/J,IAAI,YAAY,MAAM,OAAO,KAAA;CAC7B,IAAI;CACJ,IAAI;EACF,WAAW,IAAI,cAAc;GAAE;GAAQ;GAAS,OAAO;GAAM,WAAW;EAAK,CAAC;CAChF,QAAQ;EACN;CACF;CACA,SAAS,cAAc,GAAU,CAAC;CAElC,OAAO,MAAM,UAAU;CACvB,OAAO,MAAM,QAAQ;CACrB,OAAO,MAAM,SAAS;CACtB,OAAO,MAAM,SAAS;CACtB,OAAO,MAAM,cAAc;CAC3B,OAAO,WAAW;CAClB,OAAO,aAAa,QAAQ,aAAa;CACzC,OAAO,aAAa,cAAc,QAAQ,KAAK;CAC/C,UAAU,OAAO,MAAM;CAEvB,MAAM,cAAc,QAAQ,eAAA;CAC5B,MAAM,QAAQ;EAAE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