@biolibs/bionet-scene 0.0.0-stage → 0.2.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 +54 -2
- package/dist/explorer.d.ts +57 -0
- package/dist/explorer.d.ts.map +1 -0
- package/dist/explorer.js +77 -0
- package/dist/explorer.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/scene.d.ts +49 -0
- package/dist/scene.d.ts.map +1 -0
- package/dist/scene.js +239 -0
- package/dist/scene.js.map +1 -0
- package/dist/view.d.ts +132 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +161 -0
- package/dist/view.js.map +1 -0
- package/package.json +57 -4
- package/scene.css +43 -0
- package/src/explorer.tsx +112 -0
- package/src/index.ts +17 -0
- package/src/scene.tsx +337 -0
- package/src/view.ts +251 -0
package/dist/view.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to draw, worked out as plain data.
|
|
3
|
+
*
|
|
4
|
+
* A scene of a lab is the same lab seen from different distances: the whole room, one freezer, one
|
|
5
|
+
* box, one tube. What changes with distance is what is worth drawing and how strongly. That is
|
|
6
|
+
* decided here, by a function from the lab and what is being looked at to a list of things to draw,
|
|
7
|
+
* and nothing in this file knows how to draw anything.
|
|
8
|
+
*
|
|
9
|
+
* Keeping it apart is what makes the scene checkable. Whether a search match lights up its box, or
|
|
10
|
+
* a tube needing a count is flagged, is a question about data and is tested as one. The part that
|
|
11
|
+
* turns the list into lines and cylinders is left with nothing to decide.
|
|
12
|
+
*
|
|
13
|
+
* Colours are given as meanings from `@biolibs/bionet-theme`, never as colours: `yours` for the
|
|
14
|
+
* lab's own structure, `held` for a box or tube with something in it, `found` for a search match,
|
|
15
|
+
* `attention` for something that needs a person. The scene looks the colour up for whichever theme
|
|
16
|
+
* is showing.
|
|
17
|
+
*/
|
|
18
|
+
import { type Layout, type Level, type Pose } from "@biolibs/bionet-space";
|
|
19
|
+
import type { Meaning } from "@biolibs/bionet-theme";
|
|
20
|
+
/** What is being looked at: a place, or the whole lab, and perhaps one item in it. */
|
|
21
|
+
export interface Focus {
|
|
22
|
+
/** The place, or `null` for the whole lab. */
|
|
23
|
+
place: string | null;
|
|
24
|
+
/** One item singled out, if any. */
|
|
25
|
+
item?: string | null;
|
|
26
|
+
}
|
|
27
|
+
/** One place to draw, as a box. */
|
|
28
|
+
export interface DrawnPlace {
|
|
29
|
+
id: string;
|
|
30
|
+
kind: string;
|
|
31
|
+
name: string;
|
|
32
|
+
/** The centre of the box, in metres. */
|
|
33
|
+
center: [number, number, number];
|
|
34
|
+
/** How wide, tall and deep it is. */
|
|
35
|
+
size: [number, number, number];
|
|
36
|
+
/** What its colour means. */
|
|
37
|
+
tone: Meaning;
|
|
38
|
+
/** How strongly to draw its edges, from 0 to 1. */
|
|
39
|
+
strength: number;
|
|
40
|
+
/** How solid its faces are, from 0 (edges only) to 1. */
|
|
41
|
+
fill: number;
|
|
42
|
+
/** Whether pressing it should look at it. */
|
|
43
|
+
focusable: boolean;
|
|
44
|
+
/** Whether to write its name beside it. */
|
|
45
|
+
labelled: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** One tube to draw, standing in its position. */
|
|
48
|
+
export interface DrawnTube {
|
|
49
|
+
item: string;
|
|
50
|
+
/** The box it is in. */
|
|
51
|
+
place: string;
|
|
52
|
+
/** The centre of the tube. */
|
|
53
|
+
center: [number, number, number];
|
|
54
|
+
radius: number;
|
|
55
|
+
height: number;
|
|
56
|
+
tone: Meaning;
|
|
57
|
+
/** Whether it is the one singled out. */
|
|
58
|
+
selected: boolean;
|
|
59
|
+
/** What the part is called. */
|
|
60
|
+
name: string;
|
|
61
|
+
/** How much there is, with its unit. */
|
|
62
|
+
amount: string;
|
|
63
|
+
/** Its position, as a lid names it, like `C4`. */
|
|
64
|
+
position: string;
|
|
65
|
+
}
|
|
66
|
+
/** One empty position to draw. */
|
|
67
|
+
export interface DrawnSlot {
|
|
68
|
+
center: [number, number, number];
|
|
69
|
+
radius: number;
|
|
70
|
+
}
|
|
71
|
+
/** One step of the way from the whole lab to what is being looked at. */
|
|
72
|
+
export interface Crumb {
|
|
73
|
+
/** The place, or `null` for the whole lab. */
|
|
74
|
+
id: string | null;
|
|
75
|
+
name: string;
|
|
76
|
+
}
|
|
77
|
+
/** Everything to draw for one look at a lab. */
|
|
78
|
+
export interface SceneView {
|
|
79
|
+
/** Every place worth drawing. */
|
|
80
|
+
places: DrawnPlace[];
|
|
81
|
+
/** The tubes of the box being looked at. */
|
|
82
|
+
tubes: DrawnTube[];
|
|
83
|
+
/** The empty positions of that box. */
|
|
84
|
+
empty: DrawnSlot[];
|
|
85
|
+
/** Where the camera should stand. */
|
|
86
|
+
pose: Pose;
|
|
87
|
+
/** The way here, from the whole lab. */
|
|
88
|
+
crumbs: Crumb[];
|
|
89
|
+
/** How close this look is. */
|
|
90
|
+
level: Level;
|
|
91
|
+
/** How many items are in what is being looked at, however deep. */
|
|
92
|
+
holding: number;
|
|
93
|
+
}
|
|
94
|
+
/** What `sceneView` can be told beyond the lab and the focus. */
|
|
95
|
+
export interface ViewOptions {
|
|
96
|
+
/** Items a search has matched. Their boxes and tubes are drawn as found. */
|
|
97
|
+
matches?: ReadonlySet<string>;
|
|
98
|
+
/** What to call the whole lab in the crumbs. */
|
|
99
|
+
labName?: string;
|
|
100
|
+
/** The camera's vertical field of view, in degrees. */
|
|
101
|
+
fov?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Work out what to draw.
|
|
105
|
+
*
|
|
106
|
+
* @param layout - The lab: its places and what is stored in them.
|
|
107
|
+
* @param focus - What is being looked at.
|
|
108
|
+
* @param options - Search matches, the lab's name, the camera's field of view.
|
|
109
|
+
* @returns Everything to draw, and where to draw it from.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { exampleLab } from "@biolibs/bionet-space";
|
|
114
|
+
* import { sceneView } from "@biolibs/bionet-scene";
|
|
115
|
+
*
|
|
116
|
+
* const lab = exampleLab();
|
|
117
|
+
* sceneView(lab, { place: null }).tubes.length; // 0: from across the room, no tube is worth drawing
|
|
118
|
+
* sceneView(lab, { place: "fridge-s1-1" }).level; // "box"
|
|
119
|
+
* sceneView(lab, { place: "fridge-s1-1" }).crumbs.map((c) => c.name);
|
|
120
|
+
* // [ "Lab", "Main lab", "4 °C fridge", "Shelf 1", "Box F1-1" ]
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function sceneView(layout: Layout, focus: Focus, options?: ViewOptions): SceneView;
|
|
124
|
+
/**
|
|
125
|
+
* Where to look to see one item: its box, with the item singled out.
|
|
126
|
+
*
|
|
127
|
+
* @param layout - The lab.
|
|
128
|
+
* @param item - The item's ID.
|
|
129
|
+
* @returns The focus that shows it, or `null` if there is no such item.
|
|
130
|
+
*/
|
|
131
|
+
export declare function focusOn(layout: Pick<Layout, "stored">, item: string): Focus | null;
|
|
132
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAA2F,KAAK,MAAM,EAAE,KAAK,KAAK,EAChH,KAAK,IAAI,EAA0B,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,sFAAsF;AACtF,MAAM,WAAW,KAAK;IACpB,8CAA8C;IAC9C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,mCAAmC;AACnC,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,M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AE,UAAU,EAAE,CAAC;IACrB,4CAA4C;IAC5C,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,uCAAuC;IACvC,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,qCAAqC;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,wCAAwC;IACxC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,8BAA8B;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,iEAAiE;AACjE,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAKD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,WAAgB,GAAG,SAAS,CAwG5F;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAGlF"}
|
package/dist/view.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to draw, worked out as plain data.
|
|
3
|
+
*
|
|
4
|
+
* A scene of a lab is the same lab seen from different distances: the whole room, one freezer, one
|
|
5
|
+
* box, one tube. What changes with distance is what is worth drawing and how strongly. That is
|
|
6
|
+
* decided here, by a function from the lab and what is being looked at to a list of things to draw,
|
|
7
|
+
* and nothing in this file knows how to draw anything.
|
|
8
|
+
*
|
|
9
|
+
* Keeping it apart is what makes the scene checkable. Whether a search match lights up its box, or
|
|
10
|
+
* a tube needing a count is flagged, is a question about data and is tested as one. The part that
|
|
11
|
+
* turns the list into lines and cylinders is left with nothing to decide.
|
|
12
|
+
*
|
|
13
|
+
* Colours are given as meanings from `@biolibs/bionet-theme`, never as colours: `yours` for the
|
|
14
|
+
* lab's own structure, `held` for a box or tube with something in it, `found` for a search match,
|
|
15
|
+
* `attention` for something that needs a person. The scene looks the colour up for whichever theme
|
|
16
|
+
* is showing.
|
|
17
|
+
*/
|
|
18
|
+
import { arrange, firstFreeSlot, levelOf, poseFor, slotCenter, slotName, slotSize } from "@biolibs/bionet-space";
|
|
19
|
+
/** A tube's height, in metres. */
|
|
20
|
+
const TUBE_HEIGHT = 0.04;
|
|
21
|
+
/**
|
|
22
|
+
* Work out what to draw.
|
|
23
|
+
*
|
|
24
|
+
* @param layout - The lab: its places and what is stored in them.
|
|
25
|
+
* @param focus - What is being looked at.
|
|
26
|
+
* @param options - Search matches, the lab's name, the camera's field of view.
|
|
27
|
+
* @returns Everything to draw, and where to draw it from.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { exampleLab } from "@biolibs/bionet-space";
|
|
32
|
+
* import { sceneView } from "@biolibs/bionet-scene";
|
|
33
|
+
*
|
|
34
|
+
* const lab = exampleLab();
|
|
35
|
+
* sceneView(lab, { place: null }).tubes.length; // 0: from across the room, no tube is worth drawing
|
|
36
|
+
* sceneView(lab, { place: "fridge-s1-1" }).level; // "box"
|
|
37
|
+
* sceneView(lab, { place: "fridge-s1-1" }).crumbs.map((c) => c.name);
|
|
38
|
+
* // [ "Lab", "Main lab", "4 °C fridge", "Shelf 1", "Box F1-1" ]
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function sceneView(layout, focus, options = {}) {
|
|
42
|
+
const arranged = arrange(layout);
|
|
43
|
+
const by = new Map(arranged.map((one) => [one.place.id, one]));
|
|
44
|
+
const focused = focus.place === null ? null : by.get(focus.place) ?? null;
|
|
45
|
+
const level = levelOf(focused);
|
|
46
|
+
const matches = options.matches ?? new Set();
|
|
47
|
+
// What each place holds, itself and everything inside it.
|
|
48
|
+
const direct = new Map();
|
|
49
|
+
for (const one of layout.stored)
|
|
50
|
+
direct.set(one.place, [...(direct.get(one.place) ?? []), one]);
|
|
51
|
+
const within = new Map();
|
|
52
|
+
for (const one of arranged) {
|
|
53
|
+
for (const item of direct.get(one.place.id) ?? []) {
|
|
54
|
+
for (const id of one.path)
|
|
55
|
+
within.set(id, [...(within.get(id) ?? []), item]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Whether a place is what is looked at, something it is inside, or something inside it. */
|
|
59
|
+
const near = (one) => focused === null || focused.path.includes(one.place.id) || one.path.includes(focused.place.id);
|
|
60
|
+
/** The thing standing in a room that a place belongs to: its freezer, its bench. */
|
|
61
|
+
const unitOf = (one) => one.path[1];
|
|
62
|
+
const focusedUnit = focused === null ? undefined : unitOf(focused);
|
|
63
|
+
const places = [];
|
|
64
|
+
for (const one of arranged) {
|
|
65
|
+
const { place } = one;
|
|
66
|
+
const held = within.get(place.id) ?? [];
|
|
67
|
+
const base = { id: place.id, kind: place.kind, name: place.name, center: one.center, size: one.size };
|
|
68
|
+
const depth = one.path.length;
|
|
69
|
+
const isFocus = focused !== null && place.id === focused.place.id;
|
|
70
|
+
const childOfFocus = focused !== null && place.parent === focused.place.id;
|
|
71
|
+
if (focused !== null && focused.place.grid !== undefined && !isFocus) {
|
|
72
|
+
// A box is looked into as if it had been taken out: what it was standing in is left as a faint
|
|
73
|
+
// outline to say where it came from, and nothing else is drawn, since all of it would be in the way.
|
|
74
|
+
if (focused.path.includes(place.id))
|
|
75
|
+
places.push({ ...base, tone: depth === 1 ? "dim" : "yours", strength: 0.1, fill: 0, focusable: false, labelled: false });
|
|
76
|
+
}
|
|
77
|
+
else if (depth === 1) {
|
|
78
|
+
// A room is the frame everything else stands in, and is drawn quietly.
|
|
79
|
+
places.push({ ...base, tone: "dim", strength: level === "lab" || level === "room" ? 0.55 : 0.28, fill: 0,
|
|
80
|
+
focusable: level === "lab", labelled: level === "lab" });
|
|
81
|
+
}
|
|
82
|
+
else if (depth === 2 || place.kind === "instrument") {
|
|
83
|
+
// What stands in a room, and what stands on a bench.
|
|
84
|
+
const close = near(one) || (place.kind === "instrument" && focusedUnit === unitOf(one));
|
|
85
|
+
places.push({ ...base, tone: "yours", strength: close ? (place.kind === "bench" ? 0.6 : 1) : 0.25, fill: close ? 0.035 : 0,
|
|
86
|
+
focusable: true, labelled: isFocus || childOfFocus || level === "lab" || level === "room" });
|
|
87
|
+
}
|
|
88
|
+
else if (place.grid !== undefined) {
|
|
89
|
+
// A box. From across the room it is a small slab that says whether anything is in it.
|
|
90
|
+
const inUnit = focusedUnit !== undefined && unitOf(one) === focusedUnit;
|
|
91
|
+
const found = held.some((item) => matches.has(item.item));
|
|
92
|
+
const tone = found ? "found" : held.some((item) => item.needsRecount === true) ? "attention" : held.length > 0 ? "held" : "dim";
|
|
93
|
+
places.push({ ...base, tone, strength: found || isFocus ? 1 : inUnit ? (near(one) ? 0.85 : 0.5) : 0.3,
|
|
94
|
+
fill: held.length === 0 ? 0 : isFocus ? 0.05 : 0.14, focusable: inUnit, labelled: isFocus || childOfFocus });
|
|
95
|
+
}
|
|
96
|
+
else if (focusedUnit !== undefined && unitOf(one) === focusedUnit) {
|
|
97
|
+
// A shelf or a rack, drawn only once its freezer is being looked into.
|
|
98
|
+
places.push({ ...base, tone: "yours", strength: near(one) ? 0.55 : 0.25, fill: 0, focusable: true, labelled: isFocus || childOfFocus });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// The tubes and empty positions of the box being looked at.
|
|
102
|
+
const tubes = [];
|
|
103
|
+
const empty = [];
|
|
104
|
+
if (focused !== null && focused.place.grid !== undefined) {
|
|
105
|
+
const side = slotSize(focused);
|
|
106
|
+
const height = Math.min(TUBE_HEIGHT, focused.size[1] * 0.8);
|
|
107
|
+
const taken = [];
|
|
108
|
+
const items = direct.get(focused.place.id) ?? [];
|
|
109
|
+
// An item with no position of its own is stood in the first free one, so it can still be seen.
|
|
110
|
+
const placed = items.filter((item) => item.slot !== undefined && item.slot !== null && slotCenter(focused, item.slot) !== null);
|
|
111
|
+
for (const item of placed)
|
|
112
|
+
taken.push(item.slot);
|
|
113
|
+
const stand = (item, slot) => {
|
|
114
|
+
const at = slotCenter(focused, slot);
|
|
115
|
+
tubes.push({
|
|
116
|
+
item: item.item, place: focused.place.id, center: [at[0], at[1] + height / 2, at[2]], radius: side * 0.36, height,
|
|
117
|
+
tone: matches.has(item.item) ? "found" : item.needsRecount === true ? "attention" : "held",
|
|
118
|
+
selected: focus.item === item.item, name: item.name,
|
|
119
|
+
amount: `${item.amount}${item.unit === null ? "" : ` ${item.unit}`}`, position: slotName(slot),
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
for (const item of placed)
|
|
123
|
+
stand(item, item.slot);
|
|
124
|
+
for (const item of items.filter((one) => !placed.includes(one))) {
|
|
125
|
+
const free = firstFreeSlot(focused.place, taken);
|
|
126
|
+
if (free === null)
|
|
127
|
+
break;
|
|
128
|
+
taken.push(free);
|
|
129
|
+
stand(item, free);
|
|
130
|
+
}
|
|
131
|
+
const used = new Set(taken.map((slot) => `${slot.row},${slot.column}`));
|
|
132
|
+
for (let row = 0; row < focused.place.grid.rows; row++) {
|
|
133
|
+
for (let column = 0; column < focused.place.grid.columns; column++) {
|
|
134
|
+
if (used.has(`${row},${column}`))
|
|
135
|
+
continue;
|
|
136
|
+
empty.push({ center: slotCenter(focused, { row, column }), radius: side * 0.3 });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
places,
|
|
142
|
+
tubes,
|
|
143
|
+
empty,
|
|
144
|
+
pose: poseFor(arranged, focused === null ? null : focused.place.id, options.fov ?? 45),
|
|
145
|
+
crumbs: [{ id: null, name: options.labName ?? "Lab" }, ...(focused?.path ?? []).map((id) => ({ id, name: by.get(id).place.name }))],
|
|
146
|
+
level,
|
|
147
|
+
holding: focused === null ? layout.stored.length : (within.get(focused.place.id) ?? []).length,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Where to look to see one item: its box, with the item singled out.
|
|
152
|
+
*
|
|
153
|
+
* @param layout - The lab.
|
|
154
|
+
* @param item - The item's ID.
|
|
155
|
+
* @returns The focus that shows it, or `null` if there is no such item.
|
|
156
|
+
*/
|
|
157
|
+
export function focusOn(layout, item) {
|
|
158
|
+
const found = layout.stored.find((one) => one.item === item);
|
|
159
|
+
return found === undefined ? null : { place: found.place, item };
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=view.js.map
|
package/dist/view.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EACrC,MAAM,uBAAuB,CAAC;AA6F1E,kCAAkC;AAClC,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,KAAY,EAAE,UAAuB,EAAE;IAC/E,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,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C,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM;KAC/F,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,MAA8B,EAAE,IAAY;IAClE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAC7D,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
|
+
"bugs": {
|
|
3
|
+
"url": "https://github.com/matthewlovestocode/biolibs/issues"
|
|
4
|
+
},
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@biolibs/bionet-space": "^0.2.0",
|
|
7
|
+
"@biolibs/bionet-theme": "^0.1.0"
|
|
8
|
+
},
|
|
9
|
+
"description": "A lab in three dimensions: rooms, freezers, boxes and tubes drawn as edges in the Bionet theme, with a camera that moves from the whole lab down to one position in a box",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./scene.css": "./scene.css"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src",
|
|
23
|
+
"scene.css"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://github.com/matthewlovestocode/biolibs/tree/main/packages/bionet-scene#readme",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"bionet",
|
|
28
|
+
"three",
|
|
29
|
+
"react-three-fiber",
|
|
30
|
+
"3d",
|
|
31
|
+
"lab",
|
|
32
|
+
"freezer",
|
|
33
|
+
"biology"
|
|
34
|
+
],
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"main": "dist/index.js",
|
|
2
37
|
"name": "@biolibs/bionet-scene",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@react-three/drei": ">=10",
|
|
40
|
+
"@react-three/fiber": ">=9",
|
|
41
|
+
"@react-three/postprocessing": ">=3",
|
|
42
|
+
"react": ">=19",
|
|
43
|
+
"three": ">=0.170"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/matthewlovestocode/biolibs.git",
|
|
51
|
+
"directory": "packages/bionet-scene"
|
|
52
|
+
},
|
|
53
|
+
"sideEffects": [
|
|
54
|
+
"*.css"
|
|
55
|
+
],
|
|
56
|
+
"type": "module",
|
|
57
|
+
"types": "dist/index.d.ts",
|
|
58
|
+
"version": "0.2.0"
|
|
59
|
+
}
|
package/scene.css
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* The frame around the scene and what is written over it. Every rule is inside .bionet-scene, and
|
|
2
|
+
every colour is one of the theme's variables. */
|
|
3
|
+
.bionet-scene { position: relative; width: 100%; height: 100%; min-height: 26rem; overflow: hidden; background: var(--bionet-ground);
|
|
4
|
+
color: var(--bionet-ink); font: 13px/1.45 "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
|
|
5
|
+
.bionet-scene * { box-sizing: border-box }
|
|
6
|
+
.bionet-scene .stage { position: absolute; inset: 0 }
|
|
7
|
+
.bionet-scene .pins { position: absolute; inset: 0; overflow: hidden; pointer-events: none }
|
|
8
|
+
.bionet-scene .pin { position: absolute; left: 0; top: 0; visibility: hidden; will-change: transform }
|
|
9
|
+
.bionet-scene .crumbs { position: absolute; top: .8rem; left: .9rem; display: flex; flex-wrap: wrap; align-items: center; gap: .1rem;
|
|
10
|
+
padding: .3rem .55rem; border: 1px solid var(--bionet-rule); border-radius: 8px;
|
|
11
|
+
background: color-mix(in srgb, var(--bionet-surface) 82%, transparent); backdrop-filter: blur(6px); max-width: calc(100% - 15rem) }
|
|
12
|
+
.bionet-scene .crumbs button { font: inherit; color: var(--bionet-dim); background: none; border: 0; padding: .1rem .2rem; cursor: pointer; border-radius: 4px }
|
|
13
|
+
.bionet-scene .crumbs button:hover { color: var(--bionet-yours) }
|
|
14
|
+
.bionet-scene .crumbs strong { font-weight: 600; padding: .1rem .2rem }
|
|
15
|
+
.bionet-scene .crumbs .sep { color: var(--bionet-dim); padding: 0 .1rem }
|
|
16
|
+
.bionet-scene .search { position: absolute; top: .8rem; right: .9rem; display: flex; align-items: center; gap: .5rem }
|
|
17
|
+
.bionet-scene .search input { font: inherit; width: 11.5rem; color: var(--bionet-ink); padding: .38rem .6rem; border: 1px solid var(--bionet-rule);
|
|
18
|
+
border-radius: 8px; background: color-mix(in srgb, var(--bionet-surface) 82%, transparent); backdrop-filter: blur(6px) }
|
|
19
|
+
.bionet-scene .search input:focus-visible, .bionet-scene .crumbs button:focus-visible { outline: 2px solid var(--bionet-yours); outline-offset: 1px }
|
|
20
|
+
.bionet-scene .search .count { color: var(--bionet-found); font-variant-numeric: tabular-nums; white-space: nowrap }
|
|
21
|
+
.bionet-scene .status { position: absolute; left: .9rem; bottom: .7rem; margin: 0; color: var(--bionet-dim); font-variant-numeric: tabular-nums }
|
|
22
|
+
.bionet-scene .status .hint { opacity: .8 }
|
|
23
|
+
.bionet-scene .picked { position: absolute; right: .9rem; bottom: .8rem; display: grid; gap: .1rem; min-width: 12rem; padding: .6rem .8rem;
|
|
24
|
+
border: 1px solid var(--bionet-rule); border-left: 3px solid var(--bionet-held); border-radius: 8px;
|
|
25
|
+
background: color-mix(in srgb, var(--bionet-surface) 90%, transparent); backdrop-filter: blur(6px) }
|
|
26
|
+
.bionet-scene .picked strong { font-size: 1.05em } .bionet-scene .picked span { color: var(--bionet-dim) }
|
|
27
|
+
.bionet-scene .tag { display: inline-block; text-transform: none; font-weight: 400; transform: translateY(-.9em); white-space: nowrap; font-size: 11px; letter-spacing: .02em;
|
|
28
|
+
padding: .08rem .4rem; border-radius: 999px; border: 1px solid currentColor; color: var(--bionet-dim);
|
|
29
|
+
background: color-mix(in srgb, var(--bionet-ground) 78%, transparent) }
|
|
30
|
+
.bionet-scene .tag small { display: block; font-size: 10px; opacity: .8; text-align: center }
|
|
31
|
+
.bionet-scene .tag.tone-yours { color: var(--bionet-yours) } .bionet-scene .tag.tone-theirs { color: var(--bionet-theirs); border-radius: 8px }
|
|
32
|
+
.bionet-scene .tag.tone-held { color: var(--bionet-held) } .bionet-scene .tag.tone-found { color: var(--bionet-found) }
|
|
33
|
+
.bionet-scene .tag.tone-attention { color: var(--bionet-attention) } .bionet-scene .tag.tone-ink { color: var(--bionet-ink) }
|
|
34
|
+
.bionet-scene .tag.raised { transform: translateY(-1.6em); font-weight: 600; background: var(--bionet-surface) }
|
|
35
|
+
/* Narrow: the way back takes the whole top, and the search moves to the bottom. */
|
|
36
|
+
@media (max-width: 640px) {
|
|
37
|
+
.bionet-scene .crumbs { max-width: calc(100% - 1.8rem) }
|
|
38
|
+
.bionet-scene .search { top: auto; bottom: 2.3rem; left: .9rem; right: .9rem }
|
|
39
|
+
.bionet-scene .search input { flex: 1; width: auto; min-width: 0 }
|
|
40
|
+
.bionet-scene .picked { bottom: 4.9rem }
|
|
41
|
+
}
|
|
42
|
+
.bionet-scene.empty { display: grid; place-items: center; padding: 2rem; text-align: center; color: var(--bionet-dim) }
|
|
43
|
+
.bionet-scene.empty p { max-width: 26rem; margin: 0 }
|
package/src/explorer.tsx
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A lab to walk around: the scene, with the way back, a search, and what was picked.
|
|
5
|
+
*
|
|
6
|
+
* It is given a lab and keeps only what is being looked at and what was typed. Everything drawn
|
|
7
|
+
* comes from `sceneView`, so what is on screen is always the lab it was given.
|
|
8
|
+
*/
|
|
9
|
+
import { useMemo, useState } from "react";
|
|
10
|
+
import { layoutFrom, search, type Layout, type RecordedLab } from "@biolibs/bionet-space";
|
|
11
|
+
import { THEME_ATTRIBUTE, type Theme } from "@biolibs/bionet-theme";
|
|
12
|
+
import { LabScene, useSystemTheme, type Neighbour } from "./scene.js";
|
|
13
|
+
import { focusOn, sceneView, type Focus } from "./view.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A lab in three dimensions, with the controls to move around it.
|
|
17
|
+
*
|
|
18
|
+
* Press a freezer to look into it, a box to open it, a tube to pick it. The line at the top is the
|
|
19
|
+
* way back. Typing a part's name lights up every box that holds one, and Return goes to the first.
|
|
20
|
+
*
|
|
21
|
+
* @param props - `layout` is the lab; `labName` is what to call it; `neighbours` are other labs to
|
|
22
|
+
* draw beside it; `theme` pins a theme, which otherwise follows the system; `focus` is where to
|
|
23
|
+
* start; `onNeighbour` is told when another lab is pressed.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import "@biolibs/bionet-theme/theme.css";
|
|
28
|
+
* import "@biolibs/bionet-scene/scene.css";
|
|
29
|
+
* import { exampleLab } from "@biolibs/bionet-space";
|
|
30
|
+
* import { LabExplorer } from "@biolibs/bionet-scene";
|
|
31
|
+
*
|
|
32
|
+
* <LabExplorer layout={exampleLab()} labName="The Wren Lab" />
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function LabExplorer({ layout, labName = "Lab", neighbours, theme, focus: start, onNeighbour }: {
|
|
36
|
+
layout: Layout; labName?: string; neighbours?: readonly Neighbour[]; theme?: Theme; focus?: Focus; onNeighbour?: (id: string) => void;
|
|
37
|
+
}) {
|
|
38
|
+
const system = useSystemTheme();
|
|
39
|
+
const shown = theme ?? system;
|
|
40
|
+
const [focus, setFocus] = useState<Focus>(start ?? { place: null });
|
|
41
|
+
const [words, setWords] = useState("");
|
|
42
|
+
const found = useMemo(() => search(layout, words), [layout, words]);
|
|
43
|
+
const matches = useMemo(() => new Set(found.map((one) => one.item)), [found]);
|
|
44
|
+
const view = useMemo(() => sceneView(layout, focus, { matches, labName }), [layout, focus, matches, labName]);
|
|
45
|
+
const picked = view.tubes.find((tube) => tube.selected);
|
|
46
|
+
const where = view.crumbs.at(-1)!;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className="bionet-scene" {...{ [THEME_ATTRIBUTE]: shown }}>
|
|
50
|
+
<LabScene view={view} theme={shown} onFocus={setFocus} {...(neighbours === undefined ? {} : { neighbours })}
|
|
51
|
+
{...(onNeighbour === undefined ? {} : { onNeighbour })} />
|
|
52
|
+
<nav className="crumbs" aria-label="Where you are">
|
|
53
|
+
{view.crumbs.map((crumb, at) => (
|
|
54
|
+
<span key={crumb.id ?? "lab"}>
|
|
55
|
+
{at > 0 && <span className="sep" aria-hidden="true">›</span>}
|
|
56
|
+
{at === view.crumbs.length - 1 ? <strong>{crumb.name}</strong>
|
|
57
|
+
: <button type="button" onClick={() => setFocus({ place: crumb.id })}>{crumb.name}</button>}
|
|
58
|
+
</span>
|
|
59
|
+
))}
|
|
60
|
+
</nav>
|
|
61
|
+
<form className="search" role="search" onSubmit={(event) => {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
const first = found[0];
|
|
64
|
+
if (first !== undefined) setFocus(focusOn(layout, first.item) ?? focus);
|
|
65
|
+
}}>
|
|
66
|
+
<input value={words} onChange={(event) => setWords(event.target.value)} placeholder="Find a part" aria-label="Find a part" spellCheck={false} />
|
|
67
|
+
{words.trim() !== "" && <span className="count">{found.length === 0 ? "none" : `${found.length} found`}</span>}
|
|
68
|
+
</form>
|
|
69
|
+
<p className="status">
|
|
70
|
+
{view.holding.toLocaleString("en-US")} {view.holding === 1 ? "tube" : "tubes"} in {where.name}
|
|
71
|
+
{view.level !== "box" && <span className="hint"> · press something to look into it</span>}
|
|
72
|
+
</p>
|
|
73
|
+
{picked !== undefined && (
|
|
74
|
+
<aside className="picked" aria-live="polite">
|
|
75
|
+
<strong>{picked.name}</strong>
|
|
76
|
+
<span>{picked.amount}</span>
|
|
77
|
+
<span>position {picked.position} · {where.name}</span>
|
|
78
|
+
</aside>
|
|
79
|
+
)}
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A lab's own record of itself, drawn.
|
|
86
|
+
*
|
|
87
|
+
* It takes the lab as plain data — what `@biolibs/bionet-client` gives a window fits as it is — so
|
|
88
|
+
* it can be put in a desktop window or on a web page alike. Until the lab has said where anything
|
|
89
|
+
* is kept there is nothing to draw, and it says so.
|
|
90
|
+
*
|
|
91
|
+
* @param props - `lab` is the lab's places, items and parts; `name` is what to call it; `theme` pins
|
|
92
|
+
* a theme; `neighbours` are other labs to draw beside it.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* import { LabView } from "@biolibs/bionet-scene";
|
|
97
|
+
*
|
|
98
|
+
* // `lab` is the lab as a window is given it: the `lab` of a client's snapshot fits as it is.
|
|
99
|
+
* <LabView lab={lab} name={lab.name ?? "Lab"} />
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function LabView({ lab, name = "Lab", theme, neighbours }: { lab: RecordedLab; name?: string; theme?: Theme; neighbours?: readonly Neighbour[] }) {
|
|
103
|
+
const layout = useMemo(() => layoutFrom(lab, { room: name }), [lab.places, lab.items, lab.parts, name]);
|
|
104
|
+
if (layout.places.length === 0) {
|
|
105
|
+
return (
|
|
106
|
+
<div className="bionet-scene empty" {...(theme === undefined ? {} : { [THEME_ATTRIBUTE]: theme })}>
|
|
107
|
+
<p>Nothing to draw yet. Add a place — a freezer, then the boxes in it — and it appears here.</p>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return <LabExplorer layout={layout} labName={name} {...(theme === undefined ? {} : { theme })} {...(neighbours === undefined ? {} : { neighbours })} />;
|
|
112
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* `@biolibs/bionet-scene`: a lab in three dimensions.
|
|
4
|
+
*
|
|
5
|
+
* The same lab is drawn from four distances — the whole lab, one freezer, one box, one tube — and
|
|
6
|
+
* pressing something moves to the next. It is drawn as edges in the Bionet theme: glowing on black,
|
|
7
|
+
* or plainly on a pale ground.
|
|
8
|
+
*
|
|
9
|
+
* - `view.ts` — what to draw at each distance, as plain data, with nothing drawn
|
|
10
|
+
* - `scene.tsx` — that list, drawn with three.js
|
|
11
|
+
* - `explorer.tsx` — the scene with the way back, a search, and what was picked
|
|
12
|
+
*
|
|
13
|
+
* Import `@biolibs/bionet-theme/theme.css` and `@biolibs/bionet-scene/scene.css` once.
|
|
14
|
+
*/
|
|
15
|
+
export * from "./view.js";
|
|
16
|
+
export * from "./scene.js";
|
|
17
|
+
export * from "./explorer.js";
|