@7365admin1/layer-common 4.22.0 → 4.22.1-staging.352

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/components/AccessCardAddForm.vue +5 -4
  3. package/components/AccessCardAssignToUnitForm.vue +3 -2
  4. package/components/AccessCardPreviewDialog.vue +4 -3
  5. package/components/Dialog/UpdateMoreAction.vue +11 -1
  6. package/components/DocumentForm.vue +407 -112
  7. package/components/DocumentManagement.vue +213 -12
  8. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  9. package/components/EntryPassInformation.vue +119 -24
  10. package/components/Facility/BookingSetup.vue +63 -0
  11. package/components/HidAccessLogDashboard.vue +29 -5
  12. package/components/HidAccessPermissions.vue +424 -0
  13. package/components/HidIntercomManagement.vue +148 -14
  14. package/components/HidProfileQrCode.vue +323 -0
  15. package/components/HidReaderManagement.vue +26 -0
  16. package/components/HidReaderUserRoster.vue +32 -2
  17. package/components/HidUserEnrollment.vue +833 -152
  18. package/components/InvitationClientForm.vue +19 -1
  19. package/components/Robot/Fleet.vue +709 -0
  20. package/components/Robot/Form.vue +256 -0
  21. package/components/Robot/Map3D.vue +421 -0
  22. package/components/Robot/Plans.vue +63 -0
  23. package/components/Robot/SpotClean.vue +174 -0
  24. package/components/VisitorManagement.vue +267 -5
  25. package/composables/useAccessManagement.ts +5 -0
  26. package/composables/useDocument.ts +7 -0
  27. package/composables/useFacility.ts +11 -0
  28. package/composables/useHidAmico.ts +117 -0
  29. package/composables/useHidNavigation.ts +25 -1
  30. package/composables/usePeople.ts +19 -0
  31. package/composables/useRobots.ts +236 -0
  32. package/composables/useSiteCategory.ts +45 -0
  33. package/composables/useSiteEntryPassSettings.ts +26 -0
  34. package/composables/useWebUsb.ts +14 -11
  35. package/package.json +2 -2
  36. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  37. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  38. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  39. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  40. package/types/document.d.ts +14 -0
  41. package/types/facility.d.ts +4 -0
  42. package/types/people.d.ts +28 -1
  43. package/utils/building-map.ts +398 -0
  44. package/utils/hid-permission-assignments.ts +190 -0
  45. package/utils/occupancy-role.ts +109 -0
  46. package/utils/robot-display.ts +212 -0
@@ -0,0 +1,256 @@
1
+ <template>
2
+ <v-card width="100%">
3
+ <v-toolbar density="comfortable" class="pl-4 py-2">
4
+ <span class="font-weight-medium text-h6">
5
+ {{ editing ? `Edit ${robot?.name ?? "robot"}` : `Add ${typeLabel} robot` }}
6
+ </span>
7
+ </v-toolbar>
8
+
9
+ <v-card-text class="pa-0" style="max-height: 70vh; overflow-y: auto">
10
+ <v-form ref="form" @submit.prevent="submit">
11
+ <v-row no-gutters class="px-6 pt-4">
12
+ <v-col cols="12" class="mb-2">
13
+ <p v-if="editing" class="text-body-2 text-medium-emphasis">
14
+ Rename the robot or set its serial. To change its brand or its app
15
+ key and token, remove the robot and add it again.
16
+ </p>
17
+ <p v-else class="text-body-2 text-medium-emphasis">
18
+ The app key and token come from your robot supplier. They are used
19
+ to talk to the robot and are never shown again once saved.
20
+ </p>
21
+ </v-col>
22
+
23
+ <v-col cols="12">
24
+ <InputLabel class="font-weight-bold" title="Name" required />
25
+ <v-text-field
26
+ v-model="name"
27
+ density="comfortable"
28
+ placeholder="e.g. Cleaner 02"
29
+ :rules="[requiredRule]"
30
+ :disabled="saving"
31
+ />
32
+ </v-col>
33
+
34
+ <v-col v-if="!editing" cols="12">
35
+ <InputLabel class="font-weight-bold" title="Brand" required />
36
+ <AppSelect
37
+ v-model="brand"
38
+ :items="brands"
39
+ item-title="label"
40
+ item-value="brand"
41
+ density="comfortable"
42
+ :loading="loadingBrands"
43
+ :rules="[requiredRule]"
44
+ :disabled="saving"
45
+ />
46
+ <p class="text-caption text-medium-emphasis mt-n3 mb-2">
47
+ {{ brandHint }}
48
+ </p>
49
+ </v-col>
50
+
51
+ <v-col v-if="!editing" cols="12">
52
+ <InputLabel class="font-weight-bold" title="App key" required />
53
+ <v-text-field
54
+ v-model="appKey"
55
+ density="comfortable"
56
+ autocomplete="off"
57
+ :rules="[requiredRule]"
58
+ :disabled="saving"
59
+ />
60
+ </v-col>
61
+
62
+ <v-col v-if="!editing" cols="12">
63
+ <InputLabel class="font-weight-bold" title="App token" required />
64
+ <!--
65
+ Masked like a password because that is what it is: this token signs
66
+ every command sent to the estate's robots. It is never returned by
67
+ any read, so it cannot be recovered from the screen later either.
68
+ -->
69
+ <v-text-field
70
+ v-model="appToken"
71
+ density="comfortable"
72
+ autocomplete="off"
73
+ :type="reveal ? 'text' : 'password'"
74
+ :append-inner-icon="reveal ? 'mdi-eye-off-outline' : 'mdi-eye-outline'"
75
+ :rules="[requiredRule]"
76
+ :disabled="saving"
77
+ @click:append-inner="reveal = !reveal"
78
+ />
79
+ </v-col>
80
+
81
+ <v-col cols="12">
82
+ <InputLabel class="font-weight-bold" title="Serial number" />
83
+ <v-text-field
84
+ v-model="robotSn"
85
+ density="comfortable"
86
+ placeholder="Optional — found automatically if left blank"
87
+ :disabled="saving"
88
+ />
89
+ <p class="text-caption text-medium-emphasis mt-n3 mb-2">
90
+ Leave this blank unless the same key covers more than one robot.
91
+ </p>
92
+ </v-col>
93
+
94
+ <v-col cols="12" v-if="error">
95
+ <v-alert type="error" variant="tonal" class="mb-3" :text="error" />
96
+ </v-col>
97
+ </v-row>
98
+ </v-form>
99
+ </v-card-text>
100
+
101
+ <v-toolbar density="compact">
102
+ <v-row no-gutters>
103
+ <v-col cols="6">
104
+ <v-btn
105
+ tile block variant="flat" size="48"
106
+ class="text-none" color="#EFEFEF"
107
+ :disabled="saving"
108
+ @click="$emit('cancel')"
109
+ >
110
+ Close
111
+ </v-btn>
112
+ </v-col>
113
+ <v-col cols="6">
114
+ <v-btn
115
+ tile block variant="flat" size="48"
116
+ class="text-none" color="primary"
117
+ :loading="saving"
118
+ @click="submit"
119
+ >
120
+ {{ editing ? "Save" : "Add robot" }}
121
+ </v-btn>
122
+ </v-col>
123
+ </v-row>
124
+ </v-toolbar>
125
+ </v-card>
126
+ </template>
127
+
128
+ <script lang="ts" setup>
129
+ /**
130
+ * Register a robot against a site.
131
+ *
132
+ * The credential pair travels up once and is never returned by any read, so
133
+ * there is deliberately no edit-credentials path here: a wrong key is fixed by
134
+ * removing the robot and adding it again, which is honest about the fact that
135
+ * the old value is gone.
136
+ *
137
+ * The serial is optional because the supplier's Add-Robot flow has never asked
138
+ * for one. When it is blank the server finds it from the robot cloud — and
139
+ * refuses rather than guessing if the key covers more than one machine, which is
140
+ * exactly when the person filling this in should type it themselves.
141
+ */
142
+ import { robotErrorMessage } from "../../utils/robot-display";
143
+
144
+ const props = withDefaults(
145
+ defineProps<{
146
+ organization: string;
147
+ site: string;
148
+ type?: "cleaning" | "security";
149
+ /** When given, the form edits this robot instead of adding one. */
150
+ robot?: Record<string, any> | null;
151
+ }>(),
152
+ { type: "cleaning", robot: null },
153
+ );
154
+
155
+ const emit = defineEmits<{ cancel: []; created: []; saved: [] }>();
156
+
157
+ const { createRobot, updateRobot, getRobotBrands } = useRobots();
158
+ const editing = computed(() => !!props.robot?._id);
159
+ const { requiredRule } = useUtils();
160
+
161
+ const form = ref();
162
+ const name = ref(props.robot?.name ?? "");
163
+ const brand = ref("");
164
+ const brands = ref<Array<Record<string, any>>>([]);
165
+ const loadingBrands = ref(false);
166
+ const appKey = ref("");
167
+ const appToken = ref("");
168
+ const robotSn = ref(props.robot?.robotSn ?? "");
169
+ const reveal = ref(false);
170
+ const saving = ref(false);
171
+ const error = ref("");
172
+
173
+ const typeLabel = computed(() => (props.type === "security" ? "security" : "cleaning"));
174
+
175
+ /**
176
+ * What each brand's protocol will actually allow, in plain words.
177
+ *
178
+ * The tier comes from Open-RMF's published categories, so this is not a Seven365
179
+ * opinion - and somebody choosing a brand should know before they commit that
180
+ * one of them cannot be paused or told where to go.
181
+ */
182
+ const TIER_HINT: Record<string, string> = {
183
+ "full-control": "Full control — position, battery, navigation, pause and resume.",
184
+ "traffic-light": "Position, battery, and pause/resume. No navigation to a point.",
185
+ "read-only": "Position only. This brand cannot be given jobs through its API.",
186
+ "no-interface":
187
+ "Limited: the published API does not yet report battery or progress. Cleaning and return-to-dock work.",
188
+ };
189
+
190
+ const brandHint = computed(() => {
191
+ const chosen = brands.value.find((b) => b.brand === brand.value);
192
+ return chosen ? TIER_HINT[chosen.tier] ?? "" : "Which robot this is. Ask your supplier if unsure.";
193
+ });
194
+
195
+ async function loadBrands() {
196
+ loadingBrands.value = true;
197
+ try {
198
+ const res = await getRobotBrands();
199
+ brands.value = (res?.items ?? []).map((b: any) => ({
200
+ ...b,
201
+ label: b.displayName ?? b.brand,
202
+ }));
203
+ // Only preselect when there is no choice to make. Guessing a brand is how a
204
+ // robot ends up being sent commands in a protocol it does not speak.
205
+ if (brands.value.length === 1) brand.value = brands.value[0].brand;
206
+ } catch {
207
+ brands.value = [];
208
+ } finally {
209
+ loadingBrands.value = false;
210
+ }
211
+ }
212
+
213
+ onMounted(() => {
214
+ if (!editing.value) loadBrands();
215
+ });
216
+
217
+ async function submit() {
218
+ const { valid } = await form.value?.validate?.() ?? { valid: false };
219
+ if (!valid) return;
220
+
221
+ saving.value = true;
222
+ error.value = "";
223
+ if (editing.value) {
224
+ try {
225
+ await updateRobot(props.robot!._id, {
226
+ name: name.value.trim(),
227
+ robotSn: robotSn.value.trim(),
228
+ });
229
+ emit("saved");
230
+ } catch (e) {
231
+ error.value = robotErrorMessage(e, "Could not save the robot.");
232
+ } finally {
233
+ saving.value = false;
234
+ }
235
+ return;
236
+ }
237
+ try {
238
+ await createRobot({
239
+ name: name.value.trim(),
240
+ brand: brand.value,
241
+ appKey: appKey.value.trim(),
242
+ appToken: appToken.value.trim(),
243
+ type: props.type,
244
+ // Sent only when the person typed one; an empty string would otherwise be
245
+ // stored and stop the server ever discovering the real serial.
246
+ ...(robotSn.value.trim() ? { robotSn: robotSn.value.trim() } : {}),
247
+ metadata: { orgId: props.organization, siteId: props.site },
248
+ });
249
+ emit("created");
250
+ } catch (e) {
251
+ error.value = robotErrorMessage(e, "Could not add the robot.");
252
+ } finally {
253
+ saving.value = false;
254
+ }
255
+ }
256
+ </script>
@@ -0,0 +1,421 @@
1
+ <template>
2
+ <AppCard class="pa-0">
3
+ <CardToolbar>
4
+ <template #left>
5
+ <AppSelect
6
+ v-model="selectedFloor"
7
+ :items="floorOptions"
8
+ item-title="title"
9
+ item-value="value"
10
+ label="Level"
11
+ density="compact"
12
+ hide-details
13
+ style="max-width: 180px"
14
+ :disabled="loading || !floorOptions.length"
15
+ />
16
+ <span v-if="wallCount" class="text-caption text-medium-emphasis ml-4">
17
+ {{ wallCount }} walls found
18
+ </span>
19
+ </template>
20
+ <template #right>
21
+ <AppButton
22
+ variant="icon"
23
+ icon="mdi-rotate-left"
24
+ aria-label="Rotate left"
25
+ :disabled="loading"
26
+ @click="rotate(-1)"
27
+ />
28
+ <AppButton
29
+ variant="icon"
30
+ icon="mdi-rotate-right"
31
+ aria-label="Rotate right"
32
+ :disabled="loading"
33
+ @click="rotate(1)"
34
+ />
35
+ <AppButton
36
+ variant="icon"
37
+ :icon="tilted ? 'mdi-cube-outline' : 'mdi-floor-plan'"
38
+ :aria-label="tilted ? 'Show as a flat plan' : 'Show in 3D'"
39
+ :disabled="loading"
40
+ @click="toggleTilt"
41
+ />
42
+ </template>
43
+ </CardToolbar>
44
+
45
+ <div ref="stage" class="robot-map3d">
46
+ <canvas ref="canvasEl" class="robot-map3d__canvas" />
47
+
48
+ <div v-if="loading" class="robot-map3d__overlay">
49
+ <v-progress-circular indeterminate size="28" />
50
+ <p class="text-body-2 mt-3 mb-0">Building the layout…</p>
51
+ </div>
52
+
53
+ <!--
54
+ A failure is named rather than left as an empty canvas. An empty canvas
55
+ and a failed load look identical, and they need opposite actions from
56
+ the person looking at the screen.
57
+ -->
58
+ <div v-else-if="error" class="robot-map3d__overlay">
59
+ <v-icon size="36" class="mb-2">mdi-map-marker-off-outline</v-icon>
60
+ <p class="text-body-2 mb-3">{{ error }}</p>
61
+ <AppButton size="small" variant="outlined" @click="load">Try again</AppButton>
62
+ </div>
63
+
64
+ <div v-else-if="!wallCount" class="robot-map3d__overlay">
65
+ <v-icon size="36" class="mb-2">mdi-floor-plan</v-icon>
66
+ <p class="text-body-2 mb-0">
67
+ No walls could be found in this floor plan.
68
+ </p>
69
+ </div>
70
+ </div>
71
+ </AppCard>
72
+ </template>
73
+
74
+ <script lang="ts" setup>
75
+ /**
76
+ * The building, in 3D, generated from the robot's own floor plan.
77
+ *
78
+ * Nobody draws walls. The robot's map image is a SLAM occupancy grid — walls
79
+ * are already dark pixels — so it is fetched into a canvas, thresholded, traced
80
+ * into wall segments and extruded. Open-RMF does the same thing from an
81
+ * annotated plan; this skips the annotation because the robot has surveyed the
82
+ * building already.
83
+ *
84
+ * ## Why the image is fetched every time
85
+ *
86
+ * The vendor signs its map URLs for about an hour. A URL kept in a record is a
87
+ * URL that stops working, so it is asked for at the moment of display — the
88
+ * same trap the Virtual Patrol camera addresses hit.
89
+ *
90
+ * ## Why there is no 3D engine
91
+ *
92
+ * The scene is extruded boxes on flat floors. A parallel projection and a
93
+ * back-to-front draw order render that correctly, and `layer-common` is
94
+ * consumed by eleven web apps — an engine is a large thing to put in all of
95
+ * them for a shape this simple.
96
+ *
97
+ * ponytail: painter's algorithm, fixed camera, flat shading by face angle. No
98
+ * lighting model, no textures, no orbit. Swap Three.js in behind `levelSolids`
99
+ * and `projectPoint` if those ever matter; the geometry does not change.
100
+ */
101
+ import {
102
+ depthOf,
103
+ fitView,
104
+ gridFromImageData,
105
+ levelSolids,
106
+ projectPoint,
107
+ stackedElevations,
108
+ wallCorners,
109
+ wallsFromOccupancyGrid,
110
+ type TView,
111
+ type TWallSolid,
112
+ } from "../../utils/building-map";
113
+ import { robotErrorMessage } from "../../utils/robot-display";
114
+
115
+ const props = defineProps<{
116
+ /** The robot whose maps describe this building. */
117
+ robotId: string;
118
+ /** Drawn on the plan when its position and floor are both known. */
119
+ robotState?: Record<string, any> | null;
120
+ }>();
121
+
122
+ const { getRobotMaps, getRobotMapImages } = useRobots();
123
+
124
+ const stage = ref<HTMLElement | null>(null);
125
+ const canvasEl = ref<HTMLCanvasElement | null>(null);
126
+
127
+ const maps = ref<Array<Record<string, any>>>([]);
128
+ const selectedFloor = ref<number | null>(null);
129
+ const solids = ref<TWallSolid[]>([]);
130
+ const imageHeight = ref(0);
131
+ const loading = ref(true);
132
+ const error = ref("");
133
+ const rotation = ref(Math.PI / 5);
134
+ const tilted = ref(true);
135
+
136
+ const wallCount = computed(() => solids.value.length);
137
+
138
+ /**
139
+ * "All levels" stacks every floor the robot has mapped, one storey apart.
140
+ * A sentinel rather than null, because null already means "nothing chosen".
141
+ */
142
+ const ALL_LEVELS = -1_000_000;
143
+
144
+ const floorOptions = computed(() => {
145
+ const floors = maps.value
146
+ .map((m) => ({ title: m.mapName?.trim() || `Floor ${m.floorNo}`, value: m.floorNo }))
147
+ .sort((a, b) => a.value - b.value);
148
+ return floors.length > 1
149
+ ? [...floors, { title: "All levels (stacked)", value: ALL_LEVELS }]
150
+ : floors;
151
+ });
152
+
153
+ const stacked = computed(() => selectedFloor.value === ALL_LEVELS);
154
+
155
+ /** Each floor's height in the stack; a single floor sits at zero. */
156
+ const elevations = computed(() => stackedElevations(maps.value.map((m) => Number(m.floorNo))));
157
+
158
+ /* ------------------------------------------------------------------ load */
159
+
160
+ async function load() {
161
+ loading.value = true;
162
+ error.value = "";
163
+ try {
164
+ if (!maps.value.length) {
165
+ const res = await getRobotMaps(props.robotId);
166
+ maps.value = res?.items ?? [];
167
+ if (!maps.value.length) {
168
+ error.value = "This robot has no floor maps yet.";
169
+ return;
170
+ }
171
+ selectedFloor.value = floorOptions.value[0]?.value ?? null;
172
+ }
173
+ await buildLevel();
174
+ } catch (e) {
175
+ error.value = robotErrorMessage(e, "Could not load this building's floor plan.");
176
+ } finally {
177
+ loading.value = false;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Fetch the selected floor's plan - or every floor's, stacked - trace the
183
+ * walls and extrude them. Stacking uses only what the robot's maps already
184
+ * return (floor number, plan image, scale, origin); floors sit one storey
185
+ * apart because the maps carry no height.
186
+ */
187
+ async function buildLevel() {
188
+ solids.value = [];
189
+ const chosen = stacked.value
190
+ ? [...maps.value].sort((a, b) => a.floorNo - b.floorNo)
191
+ : maps.value.filter((m) => m.floorNo === selectedFloor.value);
192
+
193
+ if (!chosen.length || chosen.some((m) => !m.backgroundFileKey)) {
194
+ error.value = "This floor has no plan image.";
195
+ return;
196
+ }
197
+
198
+ const keys = chosen.map((m) => m.backgroundFileKey);
199
+ const files = await getRobotMapImages(props.robotId, keys);
200
+
201
+ const built: TWallSolid[] = [];
202
+ for (const map of chosen) {
203
+ const url = files?.items?.find((f: any) => f.fileKey === map.backgroundFileKey)?.url;
204
+ if (!url) {
205
+ error.value = "The floor plan image could not be fetched.";
206
+ return;
207
+ }
208
+ const level = await traceLevel(map, url, stacked.value ? elevations.value.get(Number(map.floorNo)) ?? 0 : 0);
209
+ if (!level) return;
210
+ built.push(...level);
211
+ }
212
+
213
+ solids.value = built;
214
+ draw();
215
+ }
216
+
217
+ /** One floor plan image to extruded wall boxes, at a given height. */
218
+ async function traceLevel(
219
+ map: Record<string, any>,
220
+ url: string,
221
+ elevationM: number,
222
+ ): Promise<TWallSolid[] | null> {
223
+ const image = await loadImage(url);
224
+ imageHeight.value = image.height;
225
+
226
+ const work = document.createElement("canvas");
227
+ work.width = image.width;
228
+ work.height = image.height;
229
+ const wctx = work.getContext("2d", { willReadFrequently: true });
230
+ if (!wctx) {
231
+ error.value = "This browser could not read the floor plan image.";
232
+ return null;
233
+ }
234
+ wctx.drawImage(image, 0, 0);
235
+
236
+ const { data } = wctx.getImageData(0, 0, image.width, image.height);
237
+ const grid = gridFromImageData(data, image.width, image.height);
238
+ const { vertices, walls } = wallsFromOccupancyGrid(grid, { minRunPx: 6 });
239
+
240
+ return levelSolids(
241
+ {
242
+ name: map.mapName ?? `L${map.floorNo}`,
243
+ elevationM,
244
+ scaleMPerPx: Number(map.resolution) || 0.05,
245
+ originXM: Number(map.originX) || 0,
246
+ originYM: Number(map.originY) || 0,
247
+ vertices,
248
+ walls,
249
+ },
250
+ image.height,
251
+ );
252
+ }
253
+
254
+ /**
255
+ * `crossOrigin` is set because the pixels are read back, and a canvas tainted
256
+ * by a cross-origin image throws on `getImageData` — which would look like a
257
+ * broken floor plan rather than a CORS rule.
258
+ */
259
+ function loadImage(url: string): Promise<HTMLImageElement> {
260
+ return new Promise((resolve, reject) => {
261
+ const img = new Image();
262
+ img.crossOrigin = "anonymous";
263
+ img.onload = () => resolve(img);
264
+ img.onerror = () => reject(new Error("The floor plan image could not be loaded."));
265
+ img.src = url;
266
+ });
267
+ }
268
+
269
+ /* ------------------------------------------------------------------ draw */
270
+
271
+ function draw() {
272
+ const canvas = canvasEl.value;
273
+ const host = stage.value;
274
+ if (!canvas || !host) return;
275
+
276
+ const dpr = Math.min(window.devicePixelRatio || 1, 2);
277
+ const width = host.clientWidth;
278
+ const height = host.clientHeight;
279
+ canvas.width = width * dpr;
280
+ canvas.height = height * dpr;
281
+ canvas.style.width = `${width}px`;
282
+ canvas.style.height = `${height}px`;
283
+
284
+ const ctx = canvas.getContext("2d");
285
+ if (!ctx) return;
286
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
287
+ ctx.clearRect(0, 0, width, height);
288
+
289
+ const view: TView = fitView(solids.value, { width, height }, {
290
+ rotation: rotation.value,
291
+ tilt: tilted.value ? 0.95 : 0,
292
+ });
293
+
294
+ // Painter's algorithm: with no depth buffer, draw order IS the depth test.
295
+ // Lower storeys first when stacked - seen from above, a floor hides the one
296
+ // beneath it, never the other way round.
297
+ const ordered = [...solids.value].sort(
298
+ (a, b) => a.centre.z - b.centre.z || depthOf(a.centre, view) - depthOf(b.centre, view),
299
+ );
300
+
301
+ for (const solid of ordered) drawBox(ctx, solid, view);
302
+ drawRobot(ctx, view);
303
+ }
304
+
305
+ /** The three visible faces of a box: top, and two sides. */
306
+ function drawBox(ctx: CanvasRenderingContext2D, solid: TWallSolid, view: TView) {
307
+ const c = wallCorners(solid).map((p) => projectPoint(p.x, p.y, p.z, view));
308
+ // wallCorners emits the bottom four then the top four, in the same order.
309
+ const faces: Array<{ idx: number[]; shade: number }> = [
310
+ { idx: [4, 5, 6, 7], shade: 1 }, // top, lit
311
+ { idx: [0, 1, 5, 4], shade: 0.78 },
312
+ { idx: [1, 2, 6, 5], shade: 0.62 },
313
+ { idx: [2, 3, 7, 6], shade: 0.78 },
314
+ { idx: [3, 0, 4, 7], shade: 0.62 },
315
+ ];
316
+
317
+ for (const face of faces) {
318
+ ctx.beginPath();
319
+ face.idx.forEach((i, n) => (n === 0 ? ctx.moveTo(c[i].x, c[i].y) : ctx.lineTo(c[i].x, c[i].y)));
320
+ ctx.closePath();
321
+ const v = Math.round(150 * face.shade + 60);
322
+ ctx.fillStyle = `rgb(${v},${v + 4},${v + 8})`;
323
+ ctx.fill();
324
+ ctx.strokeStyle = "rgba(20,28,38,0.22)";
325
+ ctx.lineWidth = 0.6;
326
+ ctx.stroke();
327
+ }
328
+ }
329
+
330
+ /**
331
+ * The robot, only when its position AND its floor are both known.
332
+ *
333
+ * The vendor's tracking stream carries no floor, so drawing it on whichever
334
+ * level happens to be selected would put it on a storey nobody confirmed — and
335
+ * a robot shown in the wrong place is worse than one not shown.
336
+ */
337
+ function drawRobot(ctx: CanvasRenderingContext2D, view: TView) {
338
+ const state = props.robotState;
339
+ const pos = state?.position;
340
+ if (!pos || state?.floorKnown !== true) return;
341
+ if (!stacked.value && state.floorNo !== selectedFloor.value) return;
342
+
343
+ // Stacked, the robot stands on its own storey.
344
+ const z = stacked.value ? elevations.value.get(Number(state.floorNo)) ?? 0 : 0;
345
+ const base = projectPoint(pos.x, pos.y, z, view);
346
+ const top = projectPoint(pos.x, pos.y, z + 0.9, view);
347
+
348
+ ctx.beginPath();
349
+ ctx.moveTo(base.x, base.y);
350
+ ctx.lineTo(top.x, top.y);
351
+ ctx.strokeStyle = "#FF5A1F";
352
+ ctx.lineWidth = 2;
353
+ ctx.stroke();
354
+
355
+ ctx.beginPath();
356
+ ctx.arc(top.x, top.y, 6, 0, Math.PI * 2);
357
+ ctx.fillStyle = "#FF5A1F";
358
+ ctx.fill();
359
+ }
360
+
361
+ /* --------------------------------------------------------------- controls */
362
+
363
+ function rotate(direction: number) {
364
+ rotation.value += (direction * Math.PI) / 12;
365
+ draw();
366
+ }
367
+
368
+ function toggleTilt() {
369
+ tilted.value = !tilted.value;
370
+ draw();
371
+ }
372
+
373
+ watch(selectedFloor, async () => {
374
+ if (!maps.value.length) return;
375
+ loading.value = true;
376
+ error.value = "";
377
+ try {
378
+ await buildLevel();
379
+ } catch (e) {
380
+ error.value = robotErrorMessage(e, "Could not load this floor.");
381
+ } finally {
382
+ loading.value = false;
383
+ }
384
+ });
385
+
386
+ watch(() => props.robotState, draw, { deep: true });
387
+
388
+ let onResize: (() => void) | undefined;
389
+ onMounted(() => {
390
+ load();
391
+ onResize = () => draw();
392
+ window.addEventListener("resize", onResize);
393
+ });
394
+ onBeforeUnmount(() => {
395
+ if (onResize) window.removeEventListener("resize", onResize);
396
+ });
397
+ </script>
398
+
399
+ <style scoped>
400
+ .robot-map3d {
401
+ position: relative;
402
+ width: 100%;
403
+ height: 460px;
404
+ background: linear-gradient(180deg, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.06));
405
+ }
406
+ .robot-map3d__canvas {
407
+ display: block;
408
+ width: 100%;
409
+ height: 100%;
410
+ }
411
+ .robot-map3d__overlay {
412
+ position: absolute;
413
+ inset: 0;
414
+ display: flex;
415
+ flex-direction: column;
416
+ align-items: center;
417
+ justify-content: center;
418
+ text-align: center;
419
+ padding: 24px;
420
+ }
421
+ </style>