@biolibs/bionet-scene 0.1.0 → 0.3.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/README.md CHANGED
@@ -22,6 +22,34 @@ Press a freezer to look into it, a box to take it out, a tube to pick it. The li
22
22
 
23
23
  three.js needs a canvas, so in Next.js load it in the browser only: `dynamic(() => import("@biolibs/bionet-scene").then((m) => m.LabExplorer), { ssr: false })`.
24
24
 
25
+ ## A real lab
26
+
27
+ ```tsx
28
+ import { useLab } from "@biolibs/bionet-react";
29
+ import { LabView } from "@biolibs/bionet-scene";
30
+
31
+ const lab = useLab()?.lab;
32
+ lab && <LabView lab={lab} name={lab.name ?? "Lab"} />
33
+ ```
34
+
35
+ `LabView` draws a lab from its own record: the places its members added and where they put each
36
+ tube. Until the lab has a place it says there is nothing to draw yet.
37
+
38
+ ## Arranging the lab
39
+
40
+ ```tsx
41
+ import { LabView } from "@biolibs/bionet-scene";
42
+
43
+ <LabView lab={lab} name="The Wren Lab" onStand={(place, standing) => act("standPlace", { place, standing })} />
44
+ ```
45
+
46
+ Given `onStand`, the view gains an Arrange switch. In it, drag what stands in a room to move it,
47
+ press it to turn it a quarter or set its size, and with nothing picked set the size of the room.
48
+ Every move is handed to `onStand` and the room is redrawn from what the lab then says. Places
49
+ standing in each other, or through a wall, turn the attention colour and are named in words.
50
+
51
+ `LabBuilder` is the same thing on its own, taking a `Layout`.
52
+
25
53
  ## What to draw is decided before anything is drawn
26
54
 
27
55
  ```ts
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Arranging a room, as plain data.
3
+ *
4
+ * The builder lets somebody drag what stands in a room, turn it and say how big it is. Everything
5
+ * it decides is decided here, with nothing drawn: which places may be moved, what the room looks
6
+ * like with a move not yet made, what has gone wrong, and what the lab has to be told.
7
+ */
8
+ import { type Arranged, type Layout, type Standing } from "@biolibs/bionet-space";
9
+ import { type SceneView } from "./view.js";
10
+ /** A room being arranged. */
11
+ export interface Arranging {
12
+ /** The lab as it would be with the moves not yet made. */
13
+ layout: Layout;
14
+ /** That lab, arranged. */
15
+ arranged: Arranged[];
16
+ /** What to draw. */
17
+ view: SceneView;
18
+ /** The places that may be moved: whatever stands directly in the room. */
19
+ movable: string[];
20
+ /** What has gone wrong, in words, for a person to read. */
21
+ problems: string[];
22
+ }
23
+ /**
24
+ * The rooms of a lab: the places that are in nothing.
25
+ *
26
+ * @param layout - The lab.
27
+ * @returns Them, in the lab's order.
28
+ */
29
+ export declare function roomsOf(layout: Pick<Layout, "places">): {
30
+ id: string;
31
+ name: string;
32
+ }[];
33
+ /**
34
+ * Work out a room as it is being arranged.
35
+ *
36
+ * @param layout - The lab.
37
+ * @param room - The room being arranged.
38
+ * @param draft - Standings tried but not yet said, by place.
39
+ * @param options - `labName` is what to call the lab.
40
+ * @returns What to draw, what may be moved, and what has gone wrong.
41
+ */
42
+ export declare function arranging(layout: Layout, room: string, draft?: ReadonlyMap<string, Standing>, options?: {
43
+ labName?: string;
44
+ }): Arranging;
45
+ /**
46
+ * What the lab has to be told for one place to be stood somewhere.
47
+ *
48
+ * A place nobody has stood anywhere is put where there is room, and that changes when one beside it
49
+ * is stood by hand. So standing one place first pins the others beside it where they are: arranging
50
+ * a room must not make the rest of it shuffle.
51
+ *
52
+ * @param arranged - The lab, arranged, before the move.
53
+ * @param place - The place being stood.
54
+ * @param standing - Where.
55
+ * @returns Every standing to say, the pins first and the move last.
56
+ */
57
+ export declare function toSay(arranged: readonly Arranged[], place: string, standing: Standing): {
58
+ place: string;
59
+ standing: Standing;
60
+ }[];
61
+ //# sourceMappingURL=arranging.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arranging.d.ts","sourceRoot":"","sources":["../src/arranging.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAA8C,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC9H,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtD,6BAA6B;AAC7B,MAAM,WAAW,SAAS;IACxB,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,oBAAoB;IACpB,IAAI,EAAE,SAAS,CAAC;IAChB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,CAEtF;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAa,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,SAAS,CAiBvJ;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,SAAS,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,EAAE,CAO/H"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Arranging a room, as plain data.
3
+ *
4
+ * The builder lets somebody drag what stands in a room, turn it and say how big it is. Everything
5
+ * it decides is decided here, with nothing drawn: which places may be moved, what the room looks
6
+ * like with a move not yet made, what has gone wrong, and what the lab has to be told.
7
+ */
8
+ import { arrange, overlapping, standingOf, sticking } from "@biolibs/bionet-space";
9
+ import { sceneView } from "./view.js";
10
+ /**
11
+ * The rooms of a lab: the places that are in nothing.
12
+ *
13
+ * @param layout - The lab.
14
+ * @returns Them, in the lab's order.
15
+ */
16
+ export function roomsOf(layout) {
17
+ return layout.places.filter((place) => place.parent === null).map((place) => ({ id: place.id, name: place.name }));
18
+ }
19
+ /**
20
+ * Work out a room as it is being arranged.
21
+ *
22
+ * @param layout - The lab.
23
+ * @param room - The room being arranged.
24
+ * @param draft - Standings tried but not yet said, by place.
25
+ * @param options - `labName` is what to call the lab.
26
+ * @returns What to draw, what may be moved, and what has gone wrong.
27
+ */
28
+ export function arranging(layout, room, draft = new Map(), options = {}) {
29
+ const tried = draft.size === 0 ? layout
30
+ : { ...layout, places: layout.places.map((place) => (draft.has(place.id) ? { ...place, standing: draft.get(place.id) } : place)) };
31
+ const arranged = arrange(tried);
32
+ const name = (id) => tried.places.find((place) => place.id === id)?.name ?? "a place";
33
+ const inRoom = (id) => arranged.find((one) => one.place.id === id)?.path[0] === room;
34
+ const pairs = overlapping(arranged).filter(([a]) => inRoom(a));
35
+ const out = sticking(arranged).filter(inRoom);
36
+ const attention = new Set([...pairs.flat(), ...out]);
37
+ return {
38
+ layout: tried,
39
+ arranged,
40
+ view: sceneView(tried, { place: room }, { attention, ...(options.labName === undefined ? {} : { labName: options.labName }) }),
41
+ movable: tried.places.filter((place) => place.parent === room).map((place) => place.id),
42
+ problems: [...pairs.map(([a, b]) => `${name(a)} and ${name(b)} are standing in each other.`),
43
+ ...out.map((id) => `${name(id)} is partly outside ${name(tried.places.find((place) => place.id === id).parent)}.`)],
44
+ };
45
+ }
46
+ /**
47
+ * What the lab has to be told for one place to be stood somewhere.
48
+ *
49
+ * A place nobody has stood anywhere is put where there is room, and that changes when one beside it
50
+ * is stood by hand. So standing one place first pins the others beside it where they are: arranging
51
+ * a room must not make the rest of it shuffle.
52
+ *
53
+ * @param arranged - The lab, arranged, before the move.
54
+ * @param place - The place being stood.
55
+ * @param standing - Where.
56
+ * @returns Every standing to say, the pins first and the move last.
57
+ */
58
+ export function toSay(arranged, place, standing) {
59
+ const moving = arranged.find((one) => one.place.id === place);
60
+ if (moving === undefined)
61
+ return [];
62
+ const pins = arranged
63
+ .filter((one) => one.place.parent === moving.place.parent && one.place.id !== place && one.placed === "by default")
64
+ .map((one) => ({ place: one.place.id, standing: standingOf(arranged, one.place.id) }));
65
+ return [...pins, { place, standing }];
66
+ }
67
+ //# sourceMappingURL=arranging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arranging.js","sourceRoot":"","sources":["../src/arranging.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAA6C,MAAM,uBAAuB,CAAC;AAC9H,OAAO,EAAE,SAAS,EAAkB,MAAM,WAAW,CAAC;AAgBtD;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,MAA8B;IACpD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACrH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,IAAY,EAAE,QAAuC,IAAI,GAAG,EAAE,EAAE,UAAgC,EAAE;IAC1I,MAAM,KAAK,GAAW,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;QAC7C,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,KAA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EAAE,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAE,EAAE,CAAC,CAAC,CAAC;IAC1F,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { type Layout, type Standing } from "@biolibs/bionet-space";
2
+ import { type Theme } from "@biolibs/bionet-theme";
3
+ /**
4
+ * A room to arrange.
5
+ *
6
+ * Drag something to move it across the floor; it settles every 5 cm and stays inside the room. Press
7
+ * it to turn it or change its size. With nothing picked, the room's own size can be set.
8
+ *
9
+ * @param props - `layout` is the lab; `onStand` is told each standing to say, or `null` to let a
10
+ * place stand where there is room again, and should resolve once the lab has been told;
11
+ * `labName` is what to call the lab; `theme` pins a theme; `onDone` adds a way out.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * import { LabBuilder } from "@biolibs/bionet-scene";
16
+ *
17
+ * <LabBuilder layout={layout} onStand={(place, standing) => lab.standPlace({ place, standing })} />
18
+ * ```
19
+ */
20
+ export declare function LabBuilder({ layout, onStand, labName, theme, onDone }: {
21
+ layout: Layout;
22
+ onStand: (place: string, standing: Standing | null) => Promise<unknown> | void;
23
+ labName?: string;
24
+ theme?: Theme;
25
+ onDone?: () => void;
26
+ }): import("react").JSX.Element;
27
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.tsx"],"names":[],"mappings":"AASA,OAAO,EAAuD,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACxH,OAAO,EAAmB,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAIpE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAe,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAC9E,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACtJ,+BAwFA"}
@@ -0,0 +1,89 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Arranging a lab by hand: drag what stands in a room, turn it, say how big it is.
5
+ *
6
+ * It keeps only what is being tried. Where things stand is the lab's to say, so every move is handed
7
+ * to `onStand` and the room is redrawn from what comes back.
8
+ */
9
+ import { useEffect, useMemo, useState } from "react";
10
+ import { UNNAMED_ROOM, quarterTurned, standingAt, standingOf } from "@biolibs/bionet-space";
11
+ import { THEME_ATTRIBUTE } from "@biolibs/bionet-theme";
12
+ import { arranging, roomsOf, toSay } from "./arranging.js";
13
+ import { LabScene, useSystemTheme } from "./scene.js";
14
+ /**
15
+ * A room to arrange.
16
+ *
17
+ * Drag something to move it across the floor; it settles every 5 cm and stays inside the room. Press
18
+ * it to turn it or change its size. With nothing picked, the room's own size can be set.
19
+ *
20
+ * @param props - `layout` is the lab; `onStand` is told each standing to say, or `null` to let a
21
+ * place stand where there is room again, and should resolve once the lab has been told;
22
+ * `labName` is what to call the lab; `theme` pins a theme; `onDone` adds a way out.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * import { LabBuilder } from "@biolibs/bionet-scene";
27
+ *
28
+ * <LabBuilder layout={layout} onStand={(place, standing) => lab.standPlace({ place, standing })} />
29
+ * ```
30
+ */
31
+ export function LabBuilder({ layout, onStand, labName = "Lab", theme, onDone }) {
32
+ const system = useSystemTheme();
33
+ const shown = theme ?? system;
34
+ const rooms = useMemo(() => roomsOf(layout), [layout]);
35
+ const [chosen, setRoom] = useState(null);
36
+ const room = rooms.find((one) => one.id === chosen)?.id ?? rooms[0]?.id ?? null;
37
+ const [picked, setPicked] = useState(null);
38
+ const [draft, setDraft] = useState(new Map());
39
+ const [busy, setBusy] = useState(false);
40
+ // What was tried has either been said or refused by the time the lab changes.
41
+ useEffect(() => { setDraft(new Map()); }, [layout]);
42
+ const now = useMemo(() => (room === null ? null : arranging(layout, room, draft, { labName })), [layout, room, draft, labName]);
43
+ if (room === null || now === null)
44
+ return _jsx("div", { className: "bionet-scene empty", [THEME_ATTRIBUTE]: shown, children: _jsx("p", { children: "Nothing to arrange yet." }) });
45
+ const say = async (place, standing) => {
46
+ setBusy(true);
47
+ try {
48
+ // Pins are worked out from the lab as it is, not as it is being tried.
49
+ const all = standing === null ? [{ place, standing }] : toSay(arranging(layout, room).arranged, place, standing);
50
+ for (const one of all)
51
+ await onStand(one.place, one.standing);
52
+ }
53
+ finally {
54
+ setBusy(false);
55
+ setDraft(new Map());
56
+ }
57
+ };
58
+ const drag = {
59
+ ids: new Set(busy ? [] : now.movable),
60
+ onMove: (id, to) => {
61
+ const standing = standingAt(now.arranged, id, to);
62
+ if (standing !== null)
63
+ setDraft(new Map([[id, standing]]));
64
+ },
65
+ onEnd: (id) => { const standing = draft.get(id); if (standing !== undefined)
66
+ void say(id, standing); },
67
+ };
68
+ const target = picked !== null && now.movable.includes(picked) ? picked : room;
69
+ const standing = standingOf(now.arranged, target);
70
+ const made = target === UNNAMED_ROOM;
71
+ const named = now.layout.places.find((place) => place.id === target)?.name ?? labName;
72
+ const stood = now.arranged.find((one) => one.place.id === target)?.placed === "by hand";
73
+ return (_jsxs("div", { className: "bionet-scene", [THEME_ATTRIBUTE]: shown, children: [_jsx(LabScene, { view: now.view, theme: shown, drag: drag, onFocus: (focus) => {
74
+ if (focus.place !== null && now.movable.includes(focus.place))
75
+ setPicked(focus.place);
76
+ else if (rooms.some((one) => one.id === focus.place)) {
77
+ setRoom(focus.place);
78
+ setPicked(null);
79
+ }
80
+ } }), _jsxs("nav", { className: "crumbs", "aria-label": "Rooms", children: [_jsx("strong", { children: "Arranging" }), rooms.map((one) => (one.id === room ? _jsx("strong", { children: one.name }, one.id)
81
+ : _jsx("button", { type: "button", onClick: () => { setRoom(one.id); setPicked(null); }, children: one.name }, one.id))), onDone !== undefined && _jsx("button", { type: "button", className: "done", onClick: onDone, children: "Done" })] }), _jsx("p", { className: "status", children: "Drag something to move it \u00B7 it settles every 5 cm \u00B7 press it to turn or resize" }), standing !== null && (_jsxs("aside", { className: "arrange", "aria-live": "polite", children: [_jsxs("div", { className: "head", children: [_jsx("strong", { children: named }), target !== room && _jsx("button", { type: "button", className: "plain", onClick: () => setPicked(null), children: "the room" })] }), made ? _jsx("p", { className: "note", children: "This room is made up for the drawing. Add a room among the lab's places to give it a size." }) : (_jsx("form", { onSubmit: (event) => {
82
+ event.preventDefault();
83
+ const data = new FormData(event.currentTarget);
84
+ const size = ["wide", "tall", "deep"].map((side) => Number(data.get(side)));
85
+ if (size.every((side) => Number.isFinite(side) && side > 0))
86
+ void say(target, { ...standing, size });
87
+ }, children: _jsxs("fieldset", { disabled: busy, children: [["wide", "tall", "deep"].map((side, at) => (_jsxs("label", { children: [side, _jsx("input", { name: side, type: "number", min: 0.01, max: 1000, step: 0.01, defaultValue: standing.size[at], required: true })] }, side))), _jsx("span", { className: "unit", children: "m" }), _jsx("button", { type: "submit", children: "Set size" })] }) }, `${target} ${standing.size.join()}`)), !made && (_jsxs("div", { className: "row", children: [target !== room && _jsx("button", { type: "button", disabled: busy, onClick: () => void say(target, quarterTurned(standing)), children: "Turn a quarter" }), stood && _jsx("button", { type: "button", disabled: busy, className: "plain", onClick: () => void say(target, null), children: "stand it where there is room" })] })), now.problems.length > 0 && _jsx("ul", { className: "problems", children: now.problems.map((problem) => _jsx("li", { children: problem }, problem)) })] }))] }));
88
+ }
89
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.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E,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,SAAG,KAA3H,IAAI,CAA+H,CAChJ,CAAC,EACF,eAAM,SAAS,EAAC,MAAM,kBAAS,EAC/B,iBAAQ,IAAI,EAAC,QAAQ,yBAAkB,IAC9B,IAZF,GAAG,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAavC,CACR,EACA,CAAC,IAAI,IAAI,CACR,eAAK,SAAS,EAAC,KAAK,aACjB,MAAM,KAAK,IAAI,IAAI,iBAAQ,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,+BAAyB,EAC1I,KAAK,IAAI,iBAAQ,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAC,OAAO,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,6CAAuC,IAC1I,CACP,EACA,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,aAAI,SAAS,EAAC,UAAU,YAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,uBAAmB,OAAO,IAAjB,OAAO,CAAgB,CAAC,GAAM,IACrH,CACT,IACG,CACP,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type Layout } from "@biolibs/bionet-space";
1
+ import { type Layout, type RecordedLab, type Standing } from "@biolibs/bionet-space";
2
2
  import { type Theme } from "@biolibs/bionet-theme";
3
3
  import { type Neighbour } from "./scene.js";
4
4
  import { type Focus } from "./view.js";
@@ -30,4 +30,30 @@ export declare function LabExplorer({ layout, labName, neighbours, theme, focus:
30
30
  focus?: Focus;
31
31
  onNeighbour?: (id: string) => void;
32
32
  }): import("react").JSX.Element;
33
+ /**
34
+ * A lab's own record of itself, drawn.
35
+ *
36
+ * It takes the lab as plain data — what `@biolibs/bionet-client` gives a window fits as it is — so
37
+ * it can be put in a desktop window or on a web page alike. Until the lab has said where anything
38
+ * is kept there is nothing to draw, and it says so.
39
+ *
40
+ * @param props - `lab` is the lab's places, items and parts; `name` is what to call it; `theme` pins
41
+ * a theme; `neighbours` are other labs to draw beside it; `onStand`, if given, adds a way to
42
+ * arrange the lab by hand, and is told each standing to say.
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * import { LabView } from "@biolibs/bionet-scene";
47
+ *
48
+ * // `lab` is the lab as a window is given it: the `lab` of a client's snapshot fits as it is.
49
+ * <LabView lab={lab} name={lab.name ?? "Lab"} />
50
+ * ```
51
+ */
52
+ export declare function LabView({ lab, name, theme, neighbours, onStand }: {
53
+ lab: RecordedLab;
54
+ name?: string;
55
+ theme?: Theme;
56
+ neighbours?: readonly Neighbour[];
57
+ onStand?: (place: string, standing: Standing | null) => Promise<unknown> | void;
58
+ }): import("react").JSX.Element;
33
59
  //# sourceMappingURL=explorer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../src/explorer.tsx"],"names":[],"mappings":"AASA,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAmB,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAsB,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,OAAe,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE;IACrG,MAAM,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AAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAClF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CACjF,+BAkBA"}
package/dist/explorer.js CHANGED
@@ -7,8 +7,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
7
  * comes from `sceneView`, so what is on screen is always the lab it was given.
8
8
  */
9
9
  import { useMemo, useState } from "react";
10
- import { search } from "@biolibs/bionet-space";
10
+ import { layoutFrom, search } from "@biolibs/bionet-space";
11
11
  import { THEME_ATTRIBUTE } from "@biolibs/bionet-theme";
12
+ import { LabBuilder } from "./builder.js";
12
13
  import { LabScene, useSystemTheme } from "./scene.js";
13
14
  import { focusOn, sceneView } from "./view.js";
14
15
  /**
@@ -49,4 +50,34 @@ export function LabExplorer({ layout, labName = "Lab", neighbours, theme, focus:
49
50
  setFocus(focusOn(layout, first.item) ?? focus);
50
51
  }, children: [_jsx("input", { value: words, onChange: (event) => setWords(event.target.value), placeholder: "Find a part", "aria-label": "Find a part", spellCheck: false }), words.trim() !== "" && _jsx("span", { className: "count", children: found.length === 0 ? "none" : `${found.length} found` })] }), _jsxs("p", { className: "status", children: [view.holding.toLocaleString("en-US"), " ", view.holding === 1 ? "tube" : "tubes", " in ", where.name, view.level !== "box" && _jsx("span", { className: "hint", children: " \u00B7 press something to look into it" })] }), picked !== undefined && (_jsxs("aside", { className: "picked", "aria-live": "polite", children: [_jsx("strong", { children: picked.name }), _jsx("span", { children: picked.amount }), _jsxs("span", { children: ["position ", picked.position, " \u00B7 ", where.name] })] }))] }));
51
52
  }
53
+ /**
54
+ * A lab's own record of itself, drawn.
55
+ *
56
+ * It takes the lab as plain data — what `@biolibs/bionet-client` gives a window fits as it is — so
57
+ * it can be put in a desktop window or on a web page alike. Until the lab has said where anything
58
+ * is kept there is nothing to draw, and it says so.
59
+ *
60
+ * @param props - `lab` is the lab's places, items and parts; `name` is what to call it; `theme` pins
61
+ * a theme; `neighbours` are other labs to draw beside it; `onStand`, if given, adds a way to
62
+ * arrange the lab by hand, and is told each standing to say.
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * import { LabView } from "@biolibs/bionet-scene";
67
+ *
68
+ * // `lab` is the lab as a window is given it: the `lab` of a client's snapshot fits as it is.
69
+ * <LabView lab={lab} name={lab.name ?? "Lab"} />
70
+ * ```
71
+ */
72
+ export function LabView({ lab, name = "Lab", theme, neighbours, onStand }) {
73
+ const layout = useMemo(() => layoutFrom(lab, { room: name }), [lab.places, lab.items, lab.parts, name]);
74
+ const [arranging, setArranging] = useState(false);
75
+ if (layout.places.length === 0) {
76
+ return (_jsx("div", { className: "bionet-scene empty", ...(theme === undefined ? {} : { [THEME_ATTRIBUTE]: theme }), children: _jsx("p", { children: "Nothing to draw yet. Add a place \u2014 a freezer, then the boxes in it \u2014 and it appears here." }) }));
77
+ }
78
+ const pinned = theme === undefined ? {} : { theme };
79
+ if (arranging && onStand !== undefined)
80
+ return _jsx(LabBuilder, { layout: layout, labName: name, onStand: onStand, onDone: () => setArranging(false), ...pinned });
81
+ return (_jsxs("div", { className: "bionet-view", children: [_jsx(LabExplorer, { layout: layout, labName: name, ...pinned, ...(neighbours === undefined ? {} : { neighbours }) }), onStand !== undefined && _jsx("button", { type: "button", className: "bionet-arrange", onClick: () => setArranging(true), children: "Arrange" })] }));
82
+ }
52
83
  //# sourceMappingURL=explorer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"explorer.js","sourceRoot":"","sources":["../src/explorer.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAe,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAc,MAAM,u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AAO,KAAK,SAAS,IAAI,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,gBAAgB,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,wBAAkB,IAC1H,CACP,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  *
9
9
  * - `view.ts` — what to draw at each distance, as plain data, with nothing drawn
10
10
  * - `scene.tsx` — that list, drawn with three.js
11
+ * - `arranging.ts` — a room being arranged by hand, as plain data
12
+ * - `builder.tsx` — dragging, turning and resizing what stands in a room
11
13
  * - `explorer.tsx` — the scene with the way back, a search, and what was picked
12
14
  *
13
15
  * Import `@biolibs/bionet-theme/theme.css` and `@biolibs/bionet-scene/scene.css` once.
@@ -15,4 +17,6 @@
15
17
  export * from "./view.js";
16
18
  export * from "./scene.js";
17
19
  export * from "./explorer.js";
20
+ export * from "./arranging.js";
21
+ export * from "./builder.js";
18
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -8,6 +8,8 @@
8
8
  *
9
9
  * - `view.ts` — what to draw at each distance, as plain data, with nothing drawn
10
10
  * - `scene.tsx` — that list, drawn with three.js
11
+ * - `arranging.ts` — a room being arranged by hand, as plain data
12
+ * - `builder.tsx` — dragging, turning and resizing what stands in a room
11
13
  * - `explorer.tsx` — the scene with the way back, a search, and what was picked
12
14
  *
13
15
  * Import `@biolibs/bionet-theme/theme.css` and `@biolibs/bionet-scene/scene.css` once.
@@ -15,4 +17,6 @@
15
17
  export * from "./view.js";
16
18
  export * from "./scene.js";
17
19
  export * from "./explorer.js";
20
+ export * from "./arranging.js";
21
+ export * from "./builder.js";
18
22
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
package/dist/scene.d.ts CHANGED
@@ -29,6 +29,15 @@ export declare function paint(tone: Meaning, theme: Theme, strength: number): {
29
29
  * @returns `dark` or `light`, and again whenever the system changes its mind.
30
30
  */
31
31
  export declare function useSystemTheme(): Theme;
32
+ /** Letting places be dragged across the floor they stand on. */
33
+ export interface Dragging {
34
+ /** Which places may be dragged. */
35
+ ids: ReadonlySet<string>;
36
+ /** Called as one is dragged, with where the centre of its base would be: across, and towards the front. */
37
+ onMove: (id: string, to: [number, number]) => void;
38
+ /** Called when it is let go. */
39
+ onEnd: (id: string) => void;
40
+ }
32
41
  /**
33
42
  * A lab, drawn.
34
43
  *
@@ -37,13 +46,14 @@ export declare function useSystemTheme(): Theme;
37
46
  *
38
47
  * @param props - `view` is what to draw; `theme` picks the colours; `onFocus` is told which place or
39
48
  * tube was pressed; `neighbours` are other labs to draw beside this one, and `onNeighbour` is told
40
- * when one is pressed.
49
+ * when one is pressed; `drag` lets some places be dragged across the floor.
41
50
  */
42
- export declare function LabScene({ view, theme, onFocus, neighbours, onNeighbour }: {
51
+ export declare function LabScene({ view, theme, onFocus, neighbours, onNeighbour, drag }: {
43
52
  view: SceneView;
44
53
  theme: Theme;
45
54
  onFocus: (focus: Focus) => void;
46
55
  neighbours?: readonly Neighbour[];
47
56
  onNeighbour?: (id: string) => void;
57
+ drag?: Dragging;
48
58
  }): import("react").JSX.Element;
49
59
  //# sourceMappingURL=scene.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../src/scene.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAAe,KAAK,EACa,MAAM,OAAO,CAAC;AACtD,OAAO,EAAU,KAAK,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,KAAK,EAAoC,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEpF,0CAA0C;AAC1C,MAAM,WAAW,SAAS;IACxB,0DAA0D;IAC1D,EAAE,EAAE,MAAM,CAAC;IACX,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAItG;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,KAAK,CAUtC;AA4MD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,UAAe,EAAE,WAAW,EAAE,EAAE;IAC/E,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,CAAC,KAAK,EAAE,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AO,EAAE,UAAe,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE;IACrF,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACtI,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB,+BAqDA"}
package/dist/scene.js CHANGED
@@ -15,7 +15,7 @@ import { Line, OrbitControls } from "@react-three/drei";
15
15
  import { Canvas, useFrame, useThree } from "@react-three/fiber";
16
16
  import { Bloom, EffectComposer } from "@react-three/postprocessing";
17
17
  import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
18
- import { BoxGeometry, Color, CylinderGeometry, EdgesGeometry, Object3D, QuadraticBezierCurve3, RingGeometry, Vector3 } from "three";
18
+ import { BoxGeometry, Color, CylinderGeometry, EdgesGeometry, Object3D, Plane, QuadraticBezierCurve3, RingGeometry, Vector3 } from "three";
19
19
  import { colour } from "@biolibs/bionet-theme";
20
20
  const BOX = new BoxGeometry(1, 1, 1);
21
21
  const EDGES = new EdgesGeometry(BOX);
@@ -90,11 +90,45 @@ const meantFor = (event, volume) => !dragged(event) && event.intersections.every
90
90
  const other = hit.object.userData.volume;
91
91
  return other === undefined || other >= volume;
92
92
  });
93
- function PlaceBox({ place, theme, onPick }) {
93
+ const FLOOR = new Plane(new Vector3(0, 1, 0), 0);
94
+ function PlaceBox({ place, theme, onPick, drag }) {
95
+ const controls = useThree((state) => state.controls);
96
+ const held = useRef(null);
97
+ const draggable = drag?.ids.has(place.id) === true;
98
+ const onFloor = (event) => {
99
+ // The floor the place stands on, so that it follows the pointer and not the camera's depth.
100
+ FLOOR.constant = -(place.center[1] - place.size[1] / 2);
101
+ return event.ray.intersectPlane(FLOOR, new Vector3());
102
+ };
94
103
  const edge = paint(place.tone, theme, place.strength);
95
104
  const face = colour(place.tone, theme);
96
105
  const volume = place.size[0] * place.size[1] * place.size[2];
97
- return (_jsxs("group", { position: place.center, children: [_jsx("lineSegments", { scale: place.size, geometry: EDGES, children: _jsx("lineBasicMaterial", { color: edge.color, transparent: true, opacity: edge.opacity, toneMapped: false }) }), (place.focusable || place.fill > 0) && (_jsx("mesh", { scale: place.size, geometry: BOX, userData: place.focusable ? { volume } : {}, onClick: place.focusable ? (event) => { if (meantFor(event, volume))
106
+ return (_jsxs("group", { position: place.center, children: [_jsx("lineSegments", { scale: place.size, geometry: EDGES, children: _jsx("lineBasicMaterial", { color: edge.color, transparent: true, opacity: edge.opacity, toneMapped: false }) }), (place.focusable || place.fill > 0) && (_jsx("mesh", { scale: place.size, geometry: BOX, userData: place.focusable ? { volume } : {}, onPointerDown: !draggable ? undefined : (event) => {
107
+ const at = onFloor(event);
108
+ if (at === null || event.button !== 0)
109
+ return;
110
+ event.stopPropagation();
111
+ event.target.setPointerCapture(event.pointerId);
112
+ held.current = { dx: at.x - place.center[0], dz: at.z - place.center[2], moved: false };
113
+ if (controls !== null)
114
+ controls.enabled = false;
115
+ }, onPointerMove: !draggable ? undefined : (event) => {
116
+ const at = held.current === null ? null : onFloor(event);
117
+ if (held.current === null || at === null)
118
+ return;
119
+ held.current.moved = true;
120
+ drag.onMove(place.id, [at.x - held.current.dx, at.z - held.current.dz]);
121
+ }, onPointerUp: !draggable ? undefined : (event) => {
122
+ if (held.current === null)
123
+ return;
124
+ event.target.releasePointerCapture(event.pointerId);
125
+ const moved = held.current.moved;
126
+ held.current = null;
127
+ if (controls !== null)
128
+ controls.enabled = true;
129
+ if (moved)
130
+ drag.onEnd(place.id);
131
+ }, onClick: place.focusable ? (event) => { if (meantFor(event, volume))
98
132
  onPick(place.id); } : undefined, onPointerOver: place.focusable ? (event) => { event.stopPropagation(); document.body.style.cursor = "pointer"; } : undefined, onPointerOut: place.focusable ? () => { document.body.style.cursor = ""; } : undefined, children: _jsx("meshBasicMaterial", { color: face, transparent: true, opacity: theme === "dark" ? place.fill : place.fill * 1.6, depthWrite: false, toneMapped: false }) }))] }));
99
133
  }
100
134
  /**
@@ -175,8 +209,9 @@ function Rig({ view }) {
175
209
  const controls = useThree((state) => state.controls);
176
210
  const left = useRef(0);
177
211
  const first = useRef(true);
178
- const position = useMemo(() => new Vector3(...view.pose.position), [view.pose]);
179
- const target = useMemo(() => new Vector3(...view.pose.target), [view.pose]);
212
+ // Keyed on the numbers, so a view rebuilt with the same pose does not send the camera back.
213
+ const position = useMemo(() => new Vector3(...view.pose.position), [view.pose.position.join()]);
214
+ const target = useMemo(() => new Vector3(...view.pose.target), [view.pose.target.join()]);
180
215
  useEffect(() => { left.current = 1.6; }, [position, target]);
181
216
  useFrame((_, delta) => {
182
217
  if (controls === null || left.current <= 0)
@@ -206,9 +241,9 @@ function Rig({ view }) {
206
241
  *
207
242
  * @param props - `view` is what to draw; `theme` picks the colours; `onFocus` is told which place or
208
243
  * tube was pressed; `neighbours` are other labs to draw beside this one, and `onNeighbour` is told
209
- * when one is pressed.
244
+ * when one is pressed; `drag` lets some places be dragged across the floor.
210
245
  */
211
- export function LabScene({ view, theme, onFocus, neighbours = [], onNeighbour }) {
246
+ export function LabScene({ view, theme, onFocus, neighbours = [], onNeighbour, drag }) {
212
247
  const rooms = view.places.filter((place) => place.kind === "room");
213
248
  const right = Math.max(0, ...rooms.map((room) => room.center[0] + room.size[0] / 2));
214
249
  const middle = rooms.length === 0 ? 0 : rooms.reduce((sum, room) => sum + room.center[2], 0) / rooms.length;
@@ -234,6 +269,6 @@ export function LabScene({ view, theme, onFocus, neighbours = [], onNeighbour })
234
269
  }]),
235
270
  ];
236
271
  const layer = useRef(null);
237
- return (_jsxs("div", { className: "stage", children: [_jsxs(Canvas, { camera: { fov: 45, near: 0.01, far: 400, position: view.pose.position }, dpr: [1, 2], gl: { antialias: true }, children: [_jsx("color", { attach: "background", args: [colour("ground", theme)] }), _jsx("gridHelper", { args: [60, 60, rule.color, rule.color], position: [0, -0.002, 0], children: _jsx("lineBasicMaterial", { attach: "material", color: rule.color, transparent: true, opacity: theme === "dark" ? 0.5 : 0.7, toneMapped: false }) }), view.places.map((place) => _jsx(PlaceBox, { place: place, theme: theme, onPick: (id) => onFocus({ place: id }) }, place.id)), _jsx(EmptySlots, { slots: view.empty, theme: theme }), _jsx(Tubes, { tubes: view.tubes, theme: theme, onPick: (tube) => onFocus({ place: tube.place, item: tube.item }) }), beside.map(({ neighbour, from, to }) => (_jsx(NeighbourLab, { neighbour: neighbour, theme: theme, onPick: onNeighbour, from: from, to: to }, neighbour.id))), _jsx(Follow, { labels: labels, layer: layer }), _jsx(OrbitControls, { makeDefault: true, enableDamping: true, dampingFactor: 0.12, maxPolarAngle: Math.PI / 2 - 0.03, minDistance: 0.08, maxDistance: 60 }), _jsx(Rig, { view: view }), theme === "dark" && (_jsx(EffectComposer, { children: _jsx(Bloom, { mipmapBlur: true, intensity: 0.85, luminanceThreshold: 0.55, luminanceSmoothing: 0.3 }) }))] }), _jsx("div", { className: "labels", ref: layer, children: labels.map((label) => _jsx("div", { className: "label", children: label.content }, label.key)) })] }));
272
+ return (_jsxs("div", { className: "stage", children: [_jsxs(Canvas, { camera: { fov: 45, near: 0.01, far: 400, position: view.pose.position }, dpr: [1, 2], gl: { antialias: true }, children: [_jsx("color", { attach: "background", args: [colour("ground", theme)] }), _jsx("gridHelper", { args: [60, 60, rule.color, rule.color], position: [0, -0.002, 0], children: _jsx("lineBasicMaterial", { attach: "material", color: rule.color, transparent: true, opacity: theme === "dark" ? 0.5 : 0.7, toneMapped: false }) }), view.places.map((place) => _jsx(PlaceBox, { place: place, theme: theme, onPick: (id) => onFocus({ place: id }), drag: drag }, place.id)), _jsx(EmptySlots, { slots: view.empty, theme: theme }), _jsx(Tubes, { tubes: view.tubes, theme: theme, onPick: (tube) => onFocus({ place: tube.place, item: tube.item }) }), beside.map(({ neighbour, from, to }) => (_jsx(NeighbourLab, { neighbour: neighbour, theme: theme, onPick: onNeighbour, from: from, to: to }, neighbour.id))), _jsx(Follow, { labels: labels, layer: layer }), _jsx(OrbitControls, { makeDefault: true, enableDamping: true, dampingFactor: 0.12, maxPolarAngle: Math.PI / 2 - 0.03, minDistance: 0.08, maxDistance: 60 }), _jsx(Rig, { view: view }), theme === "dark" && (_jsx(EffectComposer, { children: _jsx(Bloom, { mipmapBlur: true, intensity: 0.85, luminanceThreshold: 0.55, luminanceSmoothing: 0.3 }) }))] }), _jsx("div", { className: "pins", ref: layer, children: labels.map((label) => _jsx("div", { className: "pin", children: label.content }, label.key)) })] }));
238
273
  }
239
274
  //# sourceMappingURL=scene.js.map