@newtone-dev/ui-react-web 0.64.0 → 0.66.0
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/dist/beside/beside.css +2 -2
- package/dist/nav-list/nav-list.css +10 -0
- package/dist/node-map/beads-gl.d.ts +62 -0
- package/dist/node-map/beads-gl.d.ts.map +1 -0
- package/dist/node-map/beads-gl.js +332 -0
- package/dist/node-map/beads-gl.js.map +1 -0
- package/dist/node-map/node-map-3d.d.ts +7 -1
- package/dist/node-map/node-map-3d.d.ts.map +1 -1
- package/dist/node-map/node-map-3d.js +365 -30
- package/dist/node-map/node-map-3d.js.map +1 -1
- package/dist/node-map/node-map.css +136 -14
- package/dist/node-map/node-map.d.ts +18 -2
- package/dist/node-map/node-map.d.ts.map +1 -1
- package/dist/node-map/node-map.js +6 -3
- package/dist/node-map/node-map.js.map +1 -1
- package/dist/node-map/over.d.ts +18 -2
- package/dist/node-map/over.d.ts.map +1 -1
- package/dist/node-map/over.js +14 -4
- package/dist/node-map/over.js.map +1 -1
- package/dist/node-map/space.d.ts +6 -0
- package/dist/node-map/space.d.ts.map +1 -1
- package/dist/node-map/space.js +22 -8
- package/dist/node-map/space.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useCallback, useEffect, useId, useMemo, useRef, useState, } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { boundsOf, fitted, focalOf, seen, spaceOf } from './space.js';
|
|
4
|
+
import { MapOver, MapTools } from './over.js';
|
|
5
|
+
import { beadsOn, rgbOf } from './beads-gl.js';
|
|
6
|
+
import { boundsOf, FIT, fitted, focalOf, seen, spaceOf, turned, unturned, } from './space.js';
|
|
7
7
|
// A mark's radius, in pixels, at the target's depth.
|
|
8
8
|
const MARK = 4;
|
|
9
9
|
// How many names show at once when nothing is chosen, nearest first; and how many of the chosen one's ties.
|
|
@@ -20,6 +20,8 @@ const FAINTEST = 0.3;
|
|
|
20
20
|
// Nodes are solid beads, so the nearer always hides the farther; depth is fog instead: a veil of the map's ground
|
|
21
21
|
// over each bead, none on the nearest, FOG on the farthest, DIMMED_FOG on what the chosen node does not touch.
|
|
22
22
|
const FOG = 0.65;
|
|
23
|
+
// The spheres' fog is deeper (2026-12-04, Joshua: a stronger distance fog): the farthest nearly gone into the ground.
|
|
24
|
+
const SPHERE_FOG = 0.85;
|
|
23
25
|
const DIMMED_FOG = 0.86;
|
|
24
26
|
// A bead smaller than DETAIL pixels across its radius draws no shadow and no light inside: nobody would see them.
|
|
25
27
|
const DETAIL = 3.5;
|
|
@@ -33,6 +35,67 @@ const CHAR = 6.4;
|
|
|
33
35
|
const LINE = 13;
|
|
34
36
|
// How faint a tie the chosen node does not touch is: fainter than a dimmed node, so the web behind stays back.
|
|
35
37
|
const DIMMED_TIE = 0.06;
|
|
38
|
+
// Where the light comes from as the map first opens: above, on the left, a little in front (view space: y down, z toward
|
|
39
|
+
// the camera). With `light="world"` it is set in the map's space from there, so it stays put while the map turns.
|
|
40
|
+
const LIGHT = (() => {
|
|
41
|
+
const v = { x: -0.45, y: -0.72, z: 0.53 };
|
|
42
|
+
const k = Math.hypot(v.x, v.y, v.z);
|
|
43
|
+
return { x: v.x / k, y: v.y / k, z: v.z / k };
|
|
44
|
+
})();
|
|
45
|
+
// How long a fresh sphere takes to fade back to its own colour, and the rest to come forward again, in ms.
|
|
46
|
+
const FADE = 1500;
|
|
47
|
+
// How deep in the ground what is not fresh sits while others are fresh and nothing is chosen.
|
|
48
|
+
const QUIET = 0.7;
|
|
49
|
+
// Each look's paint, as CSS the browser resolves (so a style's tokens and the dark mode come through), and how opaque.
|
|
50
|
+
const PAINTS = {
|
|
51
|
+
// On the base ground a plain sphere is lifted a little toward the ink, so it still stands off it.
|
|
52
|
+
plain: 'color-mix(in oklab, var(--newtone-role-surface-primary), var(--newtone-role-text-primary) 28%)',
|
|
53
|
+
accent: 'var(--newtone-role-text-accent)',
|
|
54
|
+
fresh: 'var(--newtone-role-text-accent)',
|
|
55
|
+
solid: 'var(--newtone-role-text-primary)',
|
|
56
|
+
warning: 'var(--newtone-role-text-warning)',
|
|
57
|
+
error: 'var(--newtone-role-text-error)',
|
|
58
|
+
support: 'var(--newtone-color-system-support-12, var(--newtone-role-text-secondary))',
|
|
59
|
+
ring: 'color-mix(in oklab, var(--newtone-role-surface-primary), var(--newtone-role-text-accent) 40%)',
|
|
60
|
+
dashed: 'color-mix(in oklab, var(--newtone-role-surface-primary), var(--newtone-role-text-primary) 28%)',
|
|
61
|
+
ground: 'var(--newtone-role-surface-primary)',
|
|
62
|
+
// A tie is a plain line (2026-12-04, Joshua: lines, not tubes), in a colour that stands 3 to 1 off the ground
|
|
63
|
+
// (2026-12-05), as a control's outline must; TIE_CONTRAST keeps the depth fade from undoing it.
|
|
64
|
+
tie: 'var(--newtone-role-divider-primary)',
|
|
65
|
+
};
|
|
66
|
+
// The least contrast a tie keeps against the map's ground, however far back it sits; and how wide it is drawn, in CSS
|
|
67
|
+
// pixels: a hairline, and a little wider while fresh, never 1.5 or more (2026-12-05).
|
|
68
|
+
const TIE_CONTRAST = 3;
|
|
69
|
+
const TIE_WIDTH = 1;
|
|
70
|
+
const FRESH_TIE_WIDTH = 1.4;
|
|
71
|
+
// What a colour weighs to the eye (WCAG relative luminance, from sRGB 0..1), and two colours' contrast.
|
|
72
|
+
const luminance = ([r, g, b]) => {
|
|
73
|
+
const lin = (v) => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
|
|
74
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
75
|
+
};
|
|
76
|
+
export const contrastOf = (a, b) => {
|
|
77
|
+
const [x, y] = [luminance(a), luminance(b)].sort((p, q) => q - p);
|
|
78
|
+
return (x + 0.05) / (y + 0.05);
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The least opacity a line of `color` drawn over `ground` may have and still stand `want` to 1 off it: what the depth
|
|
82
|
+
* fade may go down to. 1 when even the full colour does not reach it.
|
|
83
|
+
*/
|
|
84
|
+
export function floorOf(color, ground, want = TIE_CONTRAST) {
|
|
85
|
+
const at = (a) => contrastOf(color.map((c, i) => c * a + ground[i] * (1 - a)), ground);
|
|
86
|
+
if (at(1) < want)
|
|
87
|
+
return 1;
|
|
88
|
+
let [lo, hi] = [0, 1];
|
|
89
|
+
for (let i = 0; i < 20; i++) {
|
|
90
|
+
const mid = (lo + hi) / 2;
|
|
91
|
+
if (at(mid) >= want)
|
|
92
|
+
hi = mid;
|
|
93
|
+
else
|
|
94
|
+
lo = mid;
|
|
95
|
+
}
|
|
96
|
+
return hi;
|
|
97
|
+
}
|
|
98
|
+
const ALPHA = { dashed: 0.45 };
|
|
36
99
|
const clip = (s, n) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
|
|
37
100
|
const lerp = (a, b, t) => a + (b - a) * t;
|
|
38
101
|
/**
|
|
@@ -42,19 +105,75 @@ const lerp = (a, b, t) => a + (b - a) * t;
|
|
|
42
105
|
* pointed node, its ties, and the nearest `named` nodes, never more than a few at once. Drawn in SVG with the same
|
|
43
106
|
* looks as the flat map; a hidden list of the nodes, in a steady order, is what Tab and assistive tech reach.
|
|
44
107
|
*/
|
|
45
|
-
export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labels, fresh, }) {
|
|
108
|
+
export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labels, fresh, light = 'world', home, }) {
|
|
46
109
|
const svg = useRef(null);
|
|
110
|
+
const root = useRef(null);
|
|
111
|
+
const canvas = useRef(null);
|
|
112
|
+
const probe = useRef(null);
|
|
113
|
+
// The spheres' painter (WebGL2); null until made, and where there is none the SVG beads are drawn instead.
|
|
114
|
+
const beads = useRef(null);
|
|
115
|
+
const [gl, setGl] = useState(false);
|
|
116
|
+
const [, setTier] = useState('');
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const el = canvas.current;
|
|
119
|
+
if (!el)
|
|
120
|
+
return;
|
|
121
|
+
const b = beadsOn(el, setTier);
|
|
122
|
+
beads.current = b;
|
|
123
|
+
setGl(!!b);
|
|
124
|
+
return () => {
|
|
125
|
+
b?.dispose();
|
|
126
|
+
beads.current = null;
|
|
127
|
+
};
|
|
128
|
+
}, []);
|
|
129
|
+
// Each look's colour, read from the tokens, and read again when the mode or the style changes.
|
|
130
|
+
const [paints, setPaints] = useState(null);
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
const read = () => {
|
|
133
|
+
const el = probe.current;
|
|
134
|
+
if (!el)
|
|
135
|
+
return;
|
|
136
|
+
const out = {};
|
|
137
|
+
for (const [k, css] of Object.entries(PAINTS))
|
|
138
|
+
out[k] = rgbOf(css, el);
|
|
139
|
+
setPaints(out);
|
|
140
|
+
};
|
|
141
|
+
read();
|
|
142
|
+
const watch = new MutationObserver(read);
|
|
143
|
+
watch.observe(document.documentElement, { attributes: true });
|
|
144
|
+
watch.observe(document.body, { attributes: true });
|
|
145
|
+
const dark = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;
|
|
146
|
+
dark?.addEventListener('change', read);
|
|
147
|
+
return () => {
|
|
148
|
+
watch.disconnect();
|
|
149
|
+
dark?.removeEventListener('change', read);
|
|
150
|
+
};
|
|
151
|
+
}, []);
|
|
47
152
|
// The beads' shared paints (a satin body per look, the light inside, the shadow), named for this map alone.
|
|
48
153
|
const paint = `newtone-node-map-${useId().replace(/[^a-zA-Z0-9_-]/g, '')}`;
|
|
49
154
|
const isFresh = useMemo(() => new Set(fresh ?? []), [fresh]);
|
|
50
155
|
const space = useMemo(() => spaceOf(nodes, edges), [nodes, edges]);
|
|
51
156
|
const bounds = useMemo(() => boundsOf(space.values()), [space]);
|
|
52
157
|
const [box, setBox] = useState({ w: 0, h: 0 });
|
|
53
|
-
|
|
158
|
+
// The node the map turns round while nothing is chosen (2026-12-05), if the consumer names one: every view that
|
|
159
|
+
// fits the map keeps it in the middle, standing back as far again as it is from the map's own middle.
|
|
160
|
+
const homeAt = home ? space.get(home) : undefined;
|
|
161
|
+
const homeNow = useRef(homeAt);
|
|
162
|
+
homeNow.current = homeAt;
|
|
163
|
+
const around = (c) => {
|
|
164
|
+
const h = homeNow.current;
|
|
165
|
+
if (!h)
|
|
166
|
+
return c;
|
|
167
|
+
const off = Math.hypot(h.x - c.target.x, h.y - c.target.y, h.z - c.target.z);
|
|
168
|
+
return { ...c, target: h, dist: c.dist + off };
|
|
169
|
+
};
|
|
170
|
+
const [cam, setCam] = useState(() => around(fitted(space.values())));
|
|
54
171
|
const camNow = useRef(cam);
|
|
55
172
|
camNow.current = cam;
|
|
56
173
|
// Where the camera is flying to, if anywhere: the frames ease it there.
|
|
57
174
|
const goal = useRef(null);
|
|
175
|
+
// Whether the person is turning or pinching it now: the frames then count toward the tier.
|
|
176
|
+
const interacting = useRef(false);
|
|
58
177
|
const [flying, setFlying] = useState(0);
|
|
59
178
|
const fly = useCallback((to) => {
|
|
60
179
|
goal.current = to;
|
|
@@ -62,9 +181,10 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
62
181
|
}, []);
|
|
63
182
|
// Fitted again only when what is drawn changes, keeping how it is turned.
|
|
64
183
|
useEffect(() => {
|
|
65
|
-
setCam((c) => fitted(space.values(), c));
|
|
184
|
+
setCam((c) => around(fitted(space.values(), c)));
|
|
66
185
|
goal.current = null;
|
|
67
|
-
|
|
186
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
187
|
+
}, [space, home]);
|
|
68
188
|
useEffect(() => {
|
|
69
189
|
const el = svg.current;
|
|
70
190
|
if (!el)
|
|
@@ -92,10 +212,17 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
92
212
|
z: lerp(c.target.z, g.target.z, 0.2),
|
|
93
213
|
};
|
|
94
214
|
const dist = lerp(c.dist, g.dist, 0.2);
|
|
215
|
+
const yaw = g.yaw === undefined ? c.yaw : lerp(c.yaw, g.yaw, 0.2);
|
|
216
|
+
const pitch = g.pitch === undefined ? c.pitch : lerp(c.pitch, g.pitch, 0.2);
|
|
95
217
|
done =
|
|
96
218
|
Math.hypot(t.x - g.target.x, t.y - g.target.y, t.z - g.target.z) <
|
|
97
|
-
bounds.reach * 0.002 &&
|
|
98
|
-
|
|
219
|
+
bounds.reach * 0.002 &&
|
|
220
|
+
Math.abs(dist - g.dist) < bounds.reach * 0.002 &&
|
|
221
|
+
Math.abs(yaw - (g.yaw ?? yaw)) < 0.002 &&
|
|
222
|
+
Math.abs(pitch - (g.pitch ?? pitch)) < 0.002;
|
|
223
|
+
return done
|
|
224
|
+
? { ...c, target: g.target, dist: g.dist, yaw: g.yaw ?? c.yaw, pitch: g.pitch ?? c.pitch }
|
|
225
|
+
: { ...c, target: t, dist, yaw, pitch };
|
|
99
226
|
});
|
|
100
227
|
if (done)
|
|
101
228
|
goal.current = null;
|
|
@@ -105,22 +232,47 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
105
232
|
frame = requestAnimationFrame(step);
|
|
106
233
|
return () => cancelAnimationFrame(frame);
|
|
107
234
|
}, [flying, bounds.reach]);
|
|
108
|
-
// Choosing a node flies to it, a little nearer than it was
|
|
235
|
+
// Choosing a node flies to it, a little nearer than it was. Clearing flies back to the home node, standing at least
|
|
236
|
+
// as far off as the first view (2026-12-05); with no home node it leaves the camera where it is.
|
|
109
237
|
const placeOf = useCallback((id) => space.get(id), [space]);
|
|
238
|
+
const chosenOnce = useRef(false);
|
|
110
239
|
useEffect(() => {
|
|
111
|
-
if (!selected)
|
|
240
|
+
if (!selected) {
|
|
241
|
+
const h = homeNow.current;
|
|
242
|
+
if (!h || !chosenOnce.current)
|
|
243
|
+
return;
|
|
244
|
+
const first = around(fitted(space.values()));
|
|
245
|
+
fly({ target: h, dist: Math.max(camNow.current.dist, first.dist) });
|
|
112
246
|
return;
|
|
247
|
+
}
|
|
113
248
|
const p = placeOf(selected);
|
|
114
249
|
if (!p)
|
|
115
250
|
return;
|
|
251
|
+
chosenOnce.current = true;
|
|
116
252
|
fly({ target: p, dist: Math.min(camNow.current.dist, bounds.reach * 1.4) });
|
|
253
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
254
|
}, [selected, placeOf, bounds.reach, fly]);
|
|
118
255
|
const clampDist = (d) => Math.min(bounds.reach * FARTHEST, Math.max(bounds.reach * CLOSEST, d));
|
|
119
256
|
const flyBy = (by) => {
|
|
120
257
|
goal.current = null;
|
|
121
258
|
setCam((c) => ({ ...c, dist: clampDist(c.dist / by) }));
|
|
122
259
|
};
|
|
123
|
-
const fit = () => fly(fitted(space.values(), cam));
|
|
260
|
+
const fit = () => fly(around(fitted(space.values(), cam)));
|
|
261
|
+
// The double click on the ground (2026-12-04, Joshua): back to the first view, fitted and turned as the map opens;
|
|
262
|
+
// from there, turned half way round, so a second double click shows the back.
|
|
263
|
+
const backHome = () => {
|
|
264
|
+
const first = around(fitted(space.values()));
|
|
265
|
+
const atHome = Math.abs(cam.dist - first.dist) < bounds.reach * 0.02 &&
|
|
266
|
+
Math.hypot(cam.target.x - first.target.x, cam.target.y - first.target.y, cam.target.z - first.target.z) <
|
|
267
|
+
bounds.reach * 0.02 &&
|
|
268
|
+
Math.abs(cam.pitch - first.pitch) < 0.02 &&
|
|
269
|
+
Math.abs(Math.cos(cam.yaw - first.yaw) - 1) < 0.001;
|
|
270
|
+
const turnedRound = Math.abs(Math.cos(cam.yaw - first.yaw) + 1) < 0.001;
|
|
271
|
+
fly({
|
|
272
|
+
...first,
|
|
273
|
+
yaw: atHome || turnedRound ? cam.yaw + Math.PI : first.yaw,
|
|
274
|
+
});
|
|
275
|
+
};
|
|
124
276
|
const wheel = (e) => flyBy(Math.exp(-e.deltaY * 0.002));
|
|
125
277
|
// The wheel flies through the map, not the page round it.
|
|
126
278
|
useEffect(() => {
|
|
@@ -137,6 +289,7 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
137
289
|
const press = (e) => {
|
|
138
290
|
down.current.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
139
291
|
moved.current = false;
|
|
292
|
+
interacting.current = true;
|
|
140
293
|
};
|
|
141
294
|
const drag = (e) => {
|
|
142
295
|
const was = down.current.get(e.pointerId);
|
|
@@ -169,6 +322,8 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
169
322
|
};
|
|
170
323
|
const release = (e) => {
|
|
171
324
|
down.current.delete(e.pointerId);
|
|
325
|
+
if (!down.current.size)
|
|
326
|
+
interacting.current = false;
|
|
172
327
|
};
|
|
173
328
|
// Where each node falls now, farthest first, so the nearer are drawn over them.
|
|
174
329
|
const f = focalOf(box.w, box.h);
|
|
@@ -193,6 +348,9 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
193
348
|
? [at.get(order[order.length - 1].id).depth, at.get(order[0].id).depth]
|
|
194
349
|
: [0, 1];
|
|
195
350
|
const fade = (depth) => farthest - nearest < 1e-6 ? 1 : lerp(1, FAINTEST, (depth - nearest) / (farthest - nearest));
|
|
351
|
+
// A tie fades with depth only as far as it still stands TIE_CONTRAST off the ground (2026-12-05).
|
|
352
|
+
const tieFloor = useMemo(() => (paints ? floorOf(paints.tie, paints.ground) : FAINTEST), [paints]);
|
|
353
|
+
const tieFade = (depth) => Math.max(fade(depth), tieFloor);
|
|
196
354
|
const ties = useMemo(() => {
|
|
197
355
|
const m = new Map();
|
|
198
356
|
for (const e of edges) {
|
|
@@ -205,6 +363,7 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
205
363
|
}
|
|
206
364
|
return m;
|
|
207
365
|
}, [edges]);
|
|
366
|
+
const byId = useMemo(() => new Map(nodes.map((n) => [n.id, n])), [nodes]);
|
|
208
367
|
const lit = (id) => !selected || id === selected || !!ties.get(selected)?.has(id);
|
|
209
368
|
const [pointed, setPointed] = useState(null);
|
|
210
369
|
const focus = pointed ?? selected;
|
|
@@ -266,15 +425,188 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
266
425
|
const o = fade(at.get(id).depth);
|
|
267
426
|
return lit(id) ? o : Math.min(o, 0.18);
|
|
268
427
|
};
|
|
269
|
-
|
|
428
|
+
// The light, in the map's own space: set from where it first comes, so it stays put while the map turns; or, with
|
|
429
|
+
// `light="screen"`, wherever the camera has turned to, so it stays on the screen.
|
|
430
|
+
const fixedLight = useMemo(() => unturned(LIGHT, fitted([])), []);
|
|
431
|
+
const turnKey = light === 'screen' ? `${cam.yaw.toFixed(3)}:${cam.pitch.toFixed(3)}` : '';
|
|
432
|
+
const worldLight = useMemo(() => (light === 'screen' ? unturned(LIGHT, cam) : fixedLight),
|
|
433
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
434
|
+
[light, fixedLight, turnKey]);
|
|
435
|
+
// Which sphere throws its shadow on each: the nearest one on the way to the light. The light is far off, so the
|
|
436
|
+
// answer stays the same however the map turns or flies, and is worked out again only when the layout or the light
|
|
437
|
+
// moves. A sphere's size here is its size at the fitted distance.
|
|
438
|
+
const occluders = useMemo(() => {
|
|
439
|
+
const out = new Map();
|
|
440
|
+
if (!f)
|
|
441
|
+
return out;
|
|
442
|
+
const list = nodes
|
|
443
|
+
.map((n) => ({ id: n.id, p: space.get(n.id), R: (n.r * crowd * bounds.reach * FIT) / f }))
|
|
444
|
+
.filter((x) => !!x.p);
|
|
445
|
+
const L = worldLight;
|
|
446
|
+
for (const a of list) {
|
|
447
|
+
let best = Infinity;
|
|
448
|
+
let by = null;
|
|
449
|
+
for (const b of list) {
|
|
450
|
+
if (b === a)
|
|
451
|
+
continue;
|
|
452
|
+
const dx = b.p.x - a.p.x;
|
|
453
|
+
const dy = b.p.y - a.p.y;
|
|
454
|
+
const dz = b.p.z - a.p.z;
|
|
455
|
+
const t = dx * L.x + dy * L.y + dz * L.z;
|
|
456
|
+
if (t <= 0 || t >= best)
|
|
457
|
+
continue;
|
|
458
|
+
const miss2 = dx * dx + dy * dy + dz * dz - t * t;
|
|
459
|
+
const reach = (a.R + b.R) * 1.1;
|
|
460
|
+
if (miss2 < reach * reach) {
|
|
461
|
+
best = t;
|
|
462
|
+
by = b.id;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (by)
|
|
466
|
+
out.set(a.id, by);
|
|
467
|
+
}
|
|
468
|
+
return out;
|
|
469
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
470
|
+
}, [nodes, space, worldLight, f, crowd, bounds.reach]);
|
|
471
|
+
// What fades: each sphere's share of the fresh colour, and how far the rest has stepped back. Kept between frames
|
|
472
|
+
// and eased toward what is wanted now, so a fresh sphere shows in accent at once and fades back over FADE.
|
|
473
|
+
const ease = useRef({ fresh: new Map(), quiet: 0, last: 0, painted: 0 });
|
|
474
|
+
const paintNow = useRef(() => false);
|
|
475
|
+
paintNow.current = () => {
|
|
476
|
+
const b = beads.current;
|
|
477
|
+
if (!b || !paints || !box.w)
|
|
478
|
+
return false;
|
|
479
|
+
const e = ease.current;
|
|
480
|
+
const now = performance.now();
|
|
481
|
+
const dt = e.last ? Math.min(100, now - e.last) : 16;
|
|
482
|
+
e.last = now;
|
|
483
|
+
const still = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
484
|
+
const by = still ? 1 : dt / FADE;
|
|
485
|
+
let moving = false;
|
|
486
|
+
const toward = (v, to) => {
|
|
487
|
+
if (Math.abs(v - to) <= by)
|
|
488
|
+
return to;
|
|
489
|
+
moving = true;
|
|
490
|
+
return v + Math.sign(to - v) * by;
|
|
491
|
+
};
|
|
492
|
+
for (const n of nodes) {
|
|
493
|
+
const want = isFresh.has(n.id) ? 1 : 0;
|
|
494
|
+
const was = e.fresh.get(n.id);
|
|
495
|
+
e.fresh.set(n.id, was === undefined ? want : toward(was, want));
|
|
496
|
+
}
|
|
497
|
+
for (const edge of edges) {
|
|
498
|
+
const want = isFresh.has(edge.id) ? 1 : 0;
|
|
499
|
+
const was = e.fresh.get(edge.id);
|
|
500
|
+
e.fresh.set(edge.id, was === undefined ? want : toward(was, want));
|
|
501
|
+
}
|
|
502
|
+
e.quiet = toward(e.quiet, isFresh.size && !selected ? QUIET : 0);
|
|
503
|
+
const mixed = (a, c, t) => [lerp(a[0], c[0], t), lerp(a[1], c[1], t), lerp(a[2], c[2], t)];
|
|
504
|
+
const view = (id) => {
|
|
505
|
+
const p = at.get(id);
|
|
506
|
+
const node = byId.get(id);
|
|
507
|
+
const r = node.r * sizeOf(p.s);
|
|
508
|
+
return { p, r, R: (r * p.depth) / Math.max(f, 1) };
|
|
509
|
+
};
|
|
510
|
+
const beadsNow = [];
|
|
511
|
+
let maxR = 0;
|
|
512
|
+
for (const n of order) {
|
|
513
|
+
const { p, r, R } = view(n.id);
|
|
514
|
+
maxR = Math.max(maxR, R);
|
|
515
|
+
const fr = e.fresh.get(n.id) ?? 0;
|
|
516
|
+
const lifted = n.id === selected || n.id === pointed;
|
|
517
|
+
const fog = lifted ? 0 : Math.max(fogOf(n.id) * (SPHERE_FOG / FOG), e.quiet * (1 - fr));
|
|
518
|
+
const occId = occluders.get(n.id);
|
|
519
|
+
const occ = occId && at.has(occId) ? view(occId) : null;
|
|
520
|
+
beadsNow.push({
|
|
521
|
+
x: p.x,
|
|
522
|
+
y: p.y,
|
|
523
|
+
r,
|
|
524
|
+
depth: p.depth,
|
|
525
|
+
vx: p.v.x,
|
|
526
|
+
vy: p.v.y,
|
|
527
|
+
vz: p.v.z,
|
|
528
|
+
R,
|
|
529
|
+
color: mixed(paints[n.look], paints.fresh, fr),
|
|
530
|
+
alpha: lerp(ALPHA[n.look] ?? 1, 1, fr),
|
|
531
|
+
fog,
|
|
532
|
+
occluder: occ ? { vx: occ.p.v.x, vy: occ.p.v.y, vz: occ.p.v.z, R: occ.R } : undefined,
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
const tiesNow = [];
|
|
536
|
+
for (const edge of edges) {
|
|
537
|
+
const a = at.get(edge.from);
|
|
538
|
+
const c = at.get(edge.to);
|
|
539
|
+
if (!a || !c || a.depth <= near || c.depth <= near)
|
|
540
|
+
continue;
|
|
541
|
+
const fr = e.fresh.get(edge.id) ?? 0;
|
|
542
|
+
const on = lit(edge.from) &&
|
|
543
|
+
lit(edge.to) &&
|
|
544
|
+
(!selected || edge.from === selected || edge.to === selected);
|
|
545
|
+
const o = tieFade((a.depth + c.depth) / 2);
|
|
546
|
+
const alpha = on ? o : Math.min(selected ? DIMMED_TIE : 0.18, o);
|
|
547
|
+
tiesNow.push({
|
|
548
|
+
ax: a.x,
|
|
549
|
+
ay: a.y,
|
|
550
|
+
ad: a.depth,
|
|
551
|
+
bx: c.x,
|
|
552
|
+
by: c.y,
|
|
553
|
+
bd: c.depth,
|
|
554
|
+
width: lerp(TIE_WIDTH, FRESH_TIE_WIDTH, fr),
|
|
555
|
+
color: mixed(paints.tie, paints.fresh, fr),
|
|
556
|
+
alpha: alpha * (1 - e.quiet * (1 - fr)),
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
const lightNow = light === 'screen' ? LIGHT : turned(worldLight.x, worldLight.y, worldLight.z, cam);
|
|
560
|
+
b.draw({
|
|
561
|
+
width: box.w,
|
|
562
|
+
height: box.h,
|
|
563
|
+
beads: beadsNow,
|
|
564
|
+
ties: tiesNow,
|
|
565
|
+
light: [lightNow.x, lightNow.y, lightNow.z],
|
|
566
|
+
ground: paints.ground,
|
|
567
|
+
// In focus: the nearest beads (2026-12-05); only what is behind them blurs, more the farther back.
|
|
568
|
+
focus: nearest + maxR * 2,
|
|
569
|
+
span: bounds.reach * 1.2,
|
|
570
|
+
near: nearest - maxR * 2,
|
|
571
|
+
far: farthest + maxR * 2,
|
|
572
|
+
});
|
|
573
|
+
// How long since the last frame while the person turns or flies it: a card that cannot keep up steps down.
|
|
574
|
+
if (interacting.current || goal.current) {
|
|
575
|
+
if (e.painted && now - e.painted < 200)
|
|
576
|
+
b.frame(now - e.painted);
|
|
577
|
+
e.painted = now;
|
|
578
|
+
}
|
|
579
|
+
else
|
|
580
|
+
e.painted = 0;
|
|
581
|
+
return moving;
|
|
582
|
+
};
|
|
583
|
+
// Painted after every change, and every frame while something fades.
|
|
584
|
+
useEffect(() => {
|
|
585
|
+
let frame = 0;
|
|
586
|
+
const run = () => {
|
|
587
|
+
if (paintNow.current())
|
|
588
|
+
frame = requestAnimationFrame(run);
|
|
589
|
+
else
|
|
590
|
+
ease.current.last = 0;
|
|
591
|
+
};
|
|
592
|
+
run();
|
|
593
|
+
return () => cancelAnimationFrame(frame);
|
|
594
|
+
});
|
|
595
|
+
return (_jsxs("div", { ref: root, className: "newtone-node-map", "data-mode": "3d", "data-gl": gl ? '' : undefined, "data-quiet": isFresh.size && !selected ? '' : undefined, children: [_jsx("canvas", { ref: canvas, className: "newtone-node-map-spheres", "aria-hidden": "true" }), _jsxs("svg", { ref: svg, className: "newtone-node-map-canvas", "aria-hidden": "true", style: {
|
|
270
596
|
'--newtone-node-map-sheen-plain': `url(#${paint}-plain)`,
|
|
271
597
|
'--newtone-node-map-sheen-accent': `url(#${paint}-accent)`,
|
|
272
598
|
'--newtone-node-map-sheen-solid': `url(#${paint}-solid)`,
|
|
273
599
|
'--newtone-node-map-sheen-warning': `url(#${paint}-warning)`,
|
|
600
|
+
'--newtone-node-map-sheen-error': `url(#${paint}-error)`,
|
|
601
|
+
'--newtone-node-map-sheen-support': `url(#${paint}-support)`,
|
|
274
602
|
}, onWheel: wheel, onPointerDown: press, onPointerMove: drag, onPointerUp: release, onPointerCancel: release, onClick: () => {
|
|
275
603
|
if (!moved.current)
|
|
276
604
|
onSelect(null);
|
|
277
|
-
},
|
|
605
|
+
}, onDoubleClick: (e) => {
|
|
606
|
+
// A double click on the ground fits the whole map (2026-12-04), as on Slides' plane.
|
|
607
|
+
if (!e.target.closest('.newtone-node-map-node, .newtone-node-map-label'))
|
|
608
|
+
backHome();
|
|
609
|
+
}, children: [_jsxs("defs", { children: [['plain', 'accent', 'solid', 'warning', 'error', 'support'].map((look) => (_jsxs("radialGradient", { id: `${paint}-${look}`, className: "newtone-node-map-sheen", "data-look": look, fx: "0.34", fy: "0.3", children: [_jsx("stop", { offset: "0" }), _jsx("stop", { offset: "0.3" }), _jsx("stop", { offset: "0.72" }), _jsx("stop", { offset: "0.93" }), _jsx("stop", { offset: "1" })] }, look))), ['soft', 'bright'].map((glow) => (_jsxs("radialGradient", { id: `${paint}-bulb-${glow}`, className: "newtone-node-map-glow", "data-glow": glow, cy: "0.56", children: [_jsx("stop", { offset: "0" }), _jsx("stop", { offset: "0.3" }), _jsx("stop", { offset: "1" })] }, glow))), _jsxs("radialGradient", { id: `${paint}-shadow`, className: "newtone-node-map-umbra", children: [_jsx("stop", { offset: "0" }), _jsx("stop", { offset: "0.55" }), _jsx("stop", { offset: "1" })] })] }), box.w && !gl
|
|
278
610
|
? edges.map((edge) => {
|
|
279
611
|
const s = at.get(edge.from);
|
|
280
612
|
const t = at.get(edge.to);
|
|
@@ -285,8 +617,8 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
285
617
|
(!selected || edge.from === selected || edge.to === selected);
|
|
286
618
|
return (_jsx("line", { className: "newtone-node-map-edge", "data-fresh": isFresh.has(edge.id) ? '' : undefined, style: {
|
|
287
619
|
opacity: on
|
|
288
|
-
?
|
|
289
|
-
: Math.min(selected ? DIMMED_TIE : 0.18,
|
|
620
|
+
? tieFade((s.depth + t.depth) / 2)
|
|
621
|
+
: Math.min(selected ? DIMMED_TIE : 0.18, tieFade((s.depth + t.depth) / 2)),
|
|
290
622
|
}, x1: s.x, y1: s.y, x2: t.x, y2: t.y }, edge.id));
|
|
291
623
|
})
|
|
292
624
|
: null, box.w
|
|
@@ -300,18 +632,21 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
300
632
|
e.stopPropagation();
|
|
301
633
|
if (!moved.current)
|
|
302
634
|
onSelect(n.id);
|
|
303
|
-
}, onPointerEnter: () => setPointed(n.id), onPointerLeave: () => setPointed((x) => (x === n.id ? null : x)), children: [
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
635
|
+
}, onPointerEnter: () => setPointed(n.id), onPointerLeave: () => setPointed((x) => (x === n.id ? null : x)), children: [_jsx("circle", { r: r + 8, className: "newtone-node-map-hit" }), gl ? (
|
|
636
|
+
// The sphere is drawn below, on the canvas; here only what is pressed, and the
|
|
637
|
+
// ring of the one chosen or pointed at.
|
|
638
|
+
n.id === selected || n.id === pointed ? (_jsx("circle", { r: r + 3, className: "newtone-node-map-focus", style: { fill: 'none' } })) : null) : (_jsxs(_Fragment, { children: [detailed ? (_jsx("circle", { className: "newtone-node-map-shadow", cx: r * 0.3, cy: r * 0.45, r: r * 1.25, style: {
|
|
639
|
+
fill: `url(#${paint}-shadow)`,
|
|
640
|
+
stroke: 'none',
|
|
641
|
+
opacity: 1 - fog,
|
|
642
|
+
} })) : null, _jsx("circle", { r: r, className: "newtone-node-map-body" }), detailed ? (_jsx("circle", { className: "newtone-node-map-bulb", r: r * 0.62, style: {
|
|
643
|
+
fill: `url(#${paint}-bulb-${bright ? 'bright' : 'soft'})`,
|
|
644
|
+
stroke: 'none',
|
|
645
|
+
} })) : null, _jsx("circle", { className: "newtone-node-map-veil", r: r + 2.5, style: {
|
|
646
|
+
'--newtone-node-map-fog': fog,
|
|
647
|
+
fill: 'var(--newtone-role-surface-primary)',
|
|
648
|
+
stroke: 'none',
|
|
649
|
+
} })] })), n.mark ? (_jsx("circle", { className: "newtone-node-map-mark", r: MARK, cx: r * Math.SQRT1_2, cy: -r * Math.SQRT1_2 })) : null] }, n.id));
|
|
315
650
|
})
|
|
316
651
|
: null, _jsxs("g", { className: "newtone-node-map-labels", children: [focus && box.w
|
|
317
652
|
? edges
|
|
@@ -332,6 +667,6 @@ export function NodeMap3D({ nodes, edges, selected, onSelect, head, legend, labe
|
|
|
332
667
|
onSelect(n.id);
|
|
333
668
|
}, onPointerEnter: () => setPointed(n.id), onPointerLeave: () => setPointed((x) => (x === n.id ? null : x)), children: clip(n.label, n.id === focus ? 60 : 32) }, n.id));
|
|
334
669
|
})
|
|
335
|
-
: null] })] }), _jsx("ul", { className: "newtone-node-map-list", role: "group", "aria-label": labels.map, children: nodes.map((n) => (_jsx("li", { children: _jsx("button", { type: "button", "aria-pressed": n.id === selected, onClick: () => onSelect(n.id), onFocus: () => setPointed(n.id), onBlur: () => setPointed((x) => (x === n.id ? null : x)), children: n.name }) }, n.id))) }), _jsx(MapOver, { head: head, legend: legend
|
|
670
|
+
: null] })] }), _jsx("ul", { className: "newtone-node-map-list", role: "group", "aria-label": labels.map, children: nodes.map((n) => (_jsx("li", { children: _jsx("button", { type: "button", "aria-pressed": n.id === selected, onClick: () => onSelect(n.id), onFocus: () => setPointed(n.id), onBlur: () => setPointed((x) => (x === n.id ? null : x)), children: n.name }) }, n.id))) }), _jsx(MapOver, { head: head, legend: legend, sphere: gl }), _jsx(MapTools, { labels: labels, zoomIn: () => flyBy(1.4), zoomOut: () => flyBy(1 / 1.4), fit: fit }), _jsx("span", { ref: probe, className: "newtone-node-map-probe", "aria-hidden": "true" })] }));
|
|
336
671
|
}
|
|
337
672
|
//# sourceMappingURL=node-map-3d.js.map
|