@jcsoftdev/ui 0.7.1 → 0.9.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +4 -0
  3. package/dist/atoms/elapsed-time/elapsed-time.d.ts +29 -0
  4. package/dist/atoms/elapsed-time/elapsed-time.js +65 -0
  5. package/dist/atoms/elapsed-time/index.d.ts +2 -0
  6. package/dist/atoms/elapsed-time/index.js +9 -0
  7. package/dist/atoms/elapsed-time/model.d.ts +17 -0
  8. package/dist/atoms/elapsed-time/model.js +37 -0
  9. package/dist/atoms/elapsed-time/ticker.d.ts +5 -0
  10. package/dist/atoms/elapsed-time/ticker.js +37 -0
  11. package/dist/atoms/index.d.ts +2 -0
  12. package/dist/atoms/index.js +2 -0
  13. package/dist/atoms/table-glyph/index.d.ts +2 -0
  14. package/dist/atoms/table-glyph/index.js +14 -0
  15. package/dist/atoms/table-glyph/layout.d.ts +38 -0
  16. package/dist/atoms/table-glyph/layout.js +152 -0
  17. package/dist/atoms/table-glyph/table-glyph.d.ts +32 -0
  18. package/dist/atoms/table-glyph/table-glyph.js +131 -0
  19. package/dist/containers/floor-plan/edit-model.d.ts +33 -0
  20. package/dist/containers/floor-plan/edit-model.js +82 -0
  21. package/dist/containers/floor-plan/floor-plan.d.ts +83 -0
  22. package/dist/containers/floor-plan/floor-plan.js +278 -0
  23. package/dist/containers/floor-plan/index.d.ts +3 -0
  24. package/dist/containers/floor-plan/index.js +21 -0
  25. package/dist/containers/floor-plan/model.d.ts +36 -0
  26. package/dist/containers/floor-plan/model.js +52 -0
  27. package/dist/containers/floor-plan/use-floor-plan-edit.d.ts +26 -0
  28. package/dist/containers/floor-plan/use-floor-plan-edit.js +97 -0
  29. package/dist/containers/index.d.ts +2 -0
  30. package/dist/containers/index.js +2 -0
  31. package/dist/containers/order-ticket/index.d.ts +2 -0
  32. package/dist/containers/order-ticket/index.js +16 -0
  33. package/dist/containers/order-ticket/model.d.ts +18 -0
  34. package/dist/containers/order-ticket/model.js +36 -0
  35. package/dist/containers/order-ticket/order-ticket.d.ts +34 -0
  36. package/dist/containers/order-ticket/order-ticket.js +390 -0
  37. package/dist/glass/crystal-map.d.ts +3 -1
  38. package/dist/glass/crystal-map.js +13 -2
  39. package/dist/i18n/strings.d.ts +104 -0
  40. package/dist/i18n/strings.js +62 -0
  41. package/dist/icons/alarm-clock.d.ts +2 -0
  42. package/dist/icons/alarm-clock.js +15 -0
  43. package/dist/icons/hourglass.d.ts +2 -0
  44. package/dist/icons/hourglass.js +13 -0
  45. package/dist/icons/index.d.ts +2 -0
  46. package/dist/icons/index.js +4 -0
  47. package/icons/svg/alarm-clock.svg +8 -0
  48. package/icons/svg/hourglass.svg +6 -0
  49. package/package.json +2 -2
  50. package/src/atoms/elapsed-time/elapsed-time.tsx +101 -0
  51. package/src/atoms/elapsed-time/index.ts +6 -0
  52. package/src/atoms/elapsed-time/model.ts +54 -0
  53. package/src/atoms/elapsed-time/ticker.ts +39 -0
  54. package/src/atoms/index.ts +2 -0
  55. package/src/atoms/table-glyph/index.ts +14 -0
  56. package/src/atoms/table-glyph/layout.ts +187 -0
  57. package/src/atoms/table-glyph/table-glyph.tsx +161 -0
  58. package/src/containers/floor-plan/edit-model.ts +115 -0
  59. package/src/containers/floor-plan/floor-plan.tsx +393 -0
  60. package/src/containers/floor-plan/index.ts +20 -0
  61. package/src/containers/floor-plan/model.ts +81 -0
  62. package/src/containers/floor-plan/use-floor-plan-edit.ts +135 -0
  63. package/src/containers/index.ts +2 -0
  64. package/src/containers/order-ticket/index.ts +15 -0
  65. package/src/containers/order-ticket/model.ts +55 -0
  66. package/src/containers/order-ticket/order-ticket.tsx +463 -0
  67. package/src/glass/crystal-map.ts +21 -3
  68. package/src/i18n/strings.ts +104 -0
  69. package/src/icons/alarm-clock.tsx +16 -0
  70. package/src/icons/hourglass.tsx +14 -0
  71. package/src/icons/index.ts +2 -0
@@ -0,0 +1,115 @@
1
+ import type { Box } from "./model.js";
2
+
3
+ export type ResizeHandle = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw";
4
+
5
+ export interface EditBounds {
6
+ /** Canvas size in grid units. */
7
+ width: number;
8
+ height: number;
9
+ /** Grid step positions and sizes snap to. */
10
+ snap: number;
11
+ /** Smallest width or height. */
12
+ minSize: number;
13
+ }
14
+
15
+ export function snapTo(value: number, step: number): number {
16
+ if (step <= 0) return value;
17
+ return Math.round(value / step) * step;
18
+ }
19
+
20
+ const clean = (value: number) => Math.round(value * 1e6) / 1e6;
21
+
22
+ function contain(box: Box, bounds: EditBounds): Box {
23
+ const width = Math.min(Math.max(box.width, bounds.minSize), bounds.width);
24
+ const height = Math.min(Math.max(box.height, bounds.minSize), bounds.height);
25
+ return {
26
+ x: clean(Math.min(Math.max(box.x, 0), bounds.width - width)),
27
+ y: clean(Math.min(Math.max(box.y, 0), bounds.height - height)),
28
+ width: clean(width),
29
+ height: clean(height),
30
+ };
31
+ }
32
+
33
+ /** Moves a box by a delta in grid units, snapped to the grid and kept inside the canvas. */
34
+ export function moveBox(box: Box, dx: number, dy: number, bounds: EditBounds): Box {
35
+ return contain(
36
+ { ...box, x: snapTo(box.x + dx, bounds.snap), y: snapTo(box.y + dy, bounds.snap) },
37
+ bounds,
38
+ );
39
+ }
40
+
41
+ /** Resizes a box from one handle by a delta in grid units; the opposite edges stay put. */
42
+ export function resizeBox(
43
+ box: Box,
44
+ handle: ResizeHandle,
45
+ dx: number,
46
+ dy: number,
47
+ bounds: EditBounds,
48
+ ): Box {
49
+ let left = box.x;
50
+ let top = box.y;
51
+ let right = box.x + box.width;
52
+ let bottom = box.y + box.height;
53
+ const clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max);
54
+ if (handle.includes("w")) left = clamp(snapTo(left + dx, bounds.snap), 0, right - bounds.minSize);
55
+ if (handle.includes("e")) {
56
+ right = clamp(snapTo(right + dx, bounds.snap), left + bounds.minSize, bounds.width);
57
+ }
58
+ if (handle.includes("n")) top = clamp(snapTo(top + dy, bounds.snap), 0, bottom - bounds.minSize);
59
+ if (handle.includes("s")) {
60
+ bottom = clamp(snapTo(bottom + dy, bounds.snap), top + bounds.minSize, bounds.height);
61
+ }
62
+ return contain({ x: left, y: top, width: right - left, height: bottom - top }, bounds);
63
+ }
64
+
65
+ /** Turns a box a quarter by swapping its width and height around its centre, snapped and kept inside the canvas. */
66
+ export function rotateBox(box: Box, bounds: EditBounds): Box {
67
+ const centerX = box.x + box.width / 2;
68
+ const centerY = box.y + box.height / 2;
69
+ return moveBox(
70
+ {
71
+ x: centerX - box.height / 2,
72
+ y: centerY - box.width / 2,
73
+ width: box.height,
74
+ height: box.width,
75
+ },
76
+ 0,
77
+ 0,
78
+ bounds,
79
+ );
80
+ }
81
+
82
+ const ARROWS: Record<string, readonly [number, number]> = {
83
+ ArrowLeft: [-1, 0],
84
+ ArrowRight: [1, 0],
85
+ ArrowUp: [0, -1],
86
+ ArrowDown: [0, 1],
87
+ };
88
+
89
+ export type EditKeyResult = { box: Box } | undefined;
90
+
91
+ /**
92
+ * Keyboard edit of a box: Alt with an arrow nudges by one grid step, Alt and Shift with an arrow
93
+ * grows or shrinks the bottom-right corner, `r` turns it a quarter. Anything else is not an edit.
94
+ */
95
+ export function editKey(
96
+ box: Box,
97
+ event: { key: string; altKey: boolean; shiftKey: boolean; ctrlKey?: boolean; metaKey?: boolean },
98
+ bounds: EditBounds,
99
+ ): EditKeyResult {
100
+ if (event.ctrlKey || event.metaKey) return undefined;
101
+ if (!event.altKey && !event.shiftKey && event.key.toLowerCase() === "r") {
102
+ return { box: rotateBox(box, bounds) };
103
+ }
104
+ const arrow = ARROWS[event.key];
105
+ if (!arrow || !event.altKey) return undefined;
106
+ const dx = arrow[0] * bounds.snap;
107
+ const dy = arrow[1] * bounds.snap;
108
+ return {
109
+ box: event.shiftKey ? resizeBox(box, "se", dx, dy, bounds) : moveBox(box, dx, dy, bounds),
110
+ };
111
+ }
112
+
113
+ export function sameBox(a: Box, b: Box): boolean {
114
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
115
+ }
@@ -0,0 +1,393 @@
1
+ "use client";
2
+
3
+ import { type CSSProperties, type ReactNode, useId, useRef } from "react";
4
+ import type { TableShape } from "../../atoms/table-glyph/layout.js";
5
+ import { TableGlyph, type TableGlyphPattern } from "../../atoms/table-glyph/table-glyph.js";
6
+ import { useUiStrings } from "../../i18n/index.js";
7
+ import { RotateCcw } from "../../icons/index.js";
8
+ import type { ClassNames } from "../../utils/class-names.js";
9
+ import { cn } from "../../utils/cn.js";
10
+ import { useComposedRefs } from "../../utils/compose.js";
11
+ import { useRovingFocus } from "../../utils/roving-focus.js";
12
+ import { customToneStyle, isCustomTone } from "../../utils/tone.js";
13
+ import { useContainerWidth } from "../../utils/use-container-width.js";
14
+ import type { ResizeHandle } from "./edit-model.js";
15
+ import { DEFAULT_PX_PER_UNIT, groupOutlines, labelPlacement, percentBox } from "./model.js";
16
+ import { useFloorPlanEdit } from "./use-floor-plan-edit.js";
17
+
18
+ export type FloorPlanBuiltinTone = "neutral" | "accent" | "success" | "warning" | "danger" | "info";
19
+
20
+ /** A built-in tone, or the name of a tone declared in `tonePalettes`. */
21
+ export type FloorPlanTone = FloorPlanBuiltinTone | (string & {});
22
+
23
+ export type FloorPlanRing = "none" | "late" | "selected";
24
+
25
+ export interface FloorPlanItem {
26
+ id: string;
27
+ /** Position and size in grid units. */
28
+ x: number;
29
+ y: number;
30
+ width: number;
31
+ height: number;
32
+ shape: TableShape;
33
+ seats: number;
34
+ /** Chairs drawn as taken. */
35
+ occupied?: number | undefined;
36
+ /** Table name; always visible, inside the table or under it on small shapes. */
37
+ label: string;
38
+ /** Text of the state. Pair it with `statusIcon`: the state is never carried by colour alone. */
39
+ statusLabel?: string | undefined;
40
+ /** Decorative glyph shown before `statusLabel`. */
41
+ statusIcon?: ReactNode;
42
+ /** Colour of the table and the status glyph. Defaults to `neutral`. */
43
+ tone?: FloorPlanTone | undefined;
44
+ /** Table surface; see `TableGlyph`. Defaults to `solid`. */
45
+ pattern?: TableGlyphPattern | undefined;
46
+ /** A uniform ring around the whole item: `late` (danger) or `selected` (accent). `selectedId` wins over it. */
47
+ ring?: FloorPlanRing | undefined;
48
+ /** Items sharing a `groupId` (merged tables) get one outline around the group. */
49
+ groupId?: string | undefined;
50
+ }
51
+
52
+ export interface FloorPlanLandmark {
53
+ id: string;
54
+ /** What it is (`wall`, `door`, `bar`, `stairs`, `restroom`...); exposed as `data-kind`. */
55
+ kind: string;
56
+ label: string;
57
+ x: number;
58
+ y: number;
59
+ width: number;
60
+ height: number;
61
+ }
62
+
63
+ export type FloorPlanPart =
64
+ | "root"
65
+ | "canvas"
66
+ | "item"
67
+ | "glyph"
68
+ | "label"
69
+ | "status"
70
+ | "landmark"
71
+ | "group"
72
+ | "handle"
73
+ | "rotate";
74
+
75
+ export interface FloorPlanProps {
76
+ /** Canvas size in grid units. The canvas fills its container and keeps this aspect ratio. */
77
+ width: number;
78
+ height: number;
79
+ items: readonly FloorPlanItem[];
80
+ landmarks?: readonly FloorPlanLandmark[];
81
+ /** Controlled selection; the item gets the selected ring and `aria-pressed`. */
82
+ selectedId?: string | null;
83
+ /** Called with the id of the item or landmark that was picked, by click, keyboard or the start of a drag. */
84
+ onSelect?: (id: string) => void;
85
+ /**
86
+ * Lets people rearrange the plan: drag an item or landmark to move it, drag a corner handle of
87
+ * the selected one to resize, press the rotate button or `r` to turn it a quarter, Alt with an
88
+ * arrow to nudge and Alt and Shift with an arrow to resize. Edits snap to `snap`, stay inside the
89
+ * canvas and are reported through `onChange`; the plan stays controlled by `items` and `landmarks`.
90
+ * Edited boxes are not checked against each other, so overlaps are possible.
91
+ */
92
+ editable?: boolean;
93
+ /** Receives the full lists with the edited box applied; called once per drop and once per key press. */
94
+ onChange?: (items: FloorPlanItem[], landmarks: FloorPlanLandmark[]) => void;
95
+ /** Grid step in units that positions and sizes snap to while editing. Defaults to 1. */
96
+ snap?: number;
97
+ /** Smallest width or height in units while editing. Defaults to 1. */
98
+ minSize?: number;
99
+ /** Accessible name of the plan. Defaults to the localized "Floor plan". */
100
+ "aria-label"?: string;
101
+ className?: string;
102
+ /** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
103
+ classNames?: ClassNames<FloorPlanPart>;
104
+ }
105
+
106
+ const toneClasses: Record<FloorPlanBuiltinTone, string> = {
107
+ neutral: "text-ink-2",
108
+ accent: "text-accent",
109
+ success: "text-success",
110
+ warning: "text-warning",
111
+ danger: "text-danger",
112
+ info: "text-info",
113
+ };
114
+
115
+ const builtinTones = new Set<string>(Object.keys(toneClasses));
116
+
117
+ const ringClasses: Record<FloorPlanRing, string> = {
118
+ none: "",
119
+ late: "ring-2 ring-danger",
120
+ selected: "ring-2 ring-accent",
121
+ };
122
+
123
+ const HANDLES: readonly ResizeHandle[] = ["nw", "ne", "sw", "se"];
124
+
125
+ const handleClasses: Partial<Record<ResizeHandle, string>> = {
126
+ nw: "-top-1.5 -left-1.5 cursor-nwse-resize",
127
+ ne: "-top-1.5 -right-1.5 cursor-nesw-resize",
128
+ sw: "-bottom-1.5 -left-1.5 cursor-nesw-resize",
129
+ se: "-right-1.5 -bottom-1.5 cursor-nwse-resize",
130
+ };
131
+
132
+ const hatch =
133
+ "bg-[repeating-linear-gradient(135deg,var(--line-strong)_0_1px,transparent_1px_7px)] border border-line-strong";
134
+
135
+ function format(template: string, count: number): string {
136
+ return template.replace("{count}", String(count));
137
+ }
138
+
139
+ /**
140
+ * A salon plan on a logical-unit canvas, read-only unless `editable`. The canvas fills its container and keeps the
141
+ * `width` x `height` aspect ratio, and every item is placed in percentages of it, so hit areas
142
+ * always match what is drawn. Items are buttons in array order with roving arrow-key focus. A
143
+ * state shows as an icon plus text (never colour alone), `late` and `selected` as one ring around
144
+ * the whole item, and the label moves under the shape when the table is too small to hold it.
145
+ */
146
+ export function FloorPlan({
147
+ width,
148
+ height,
149
+ items,
150
+ landmarks = [],
151
+ selectedId,
152
+ onSelect,
153
+ editable = false,
154
+ onChange,
155
+ snap = 1,
156
+ minSize = 1,
157
+ "aria-label": ariaLabel,
158
+ className,
159
+ classNames,
160
+ }: FloorPlanProps) {
161
+ const strings = useUiStrings();
162
+ const canvasRef = useRef<HTMLDivElement>(null);
163
+ const measured = useContainerWidth(canvasRef);
164
+ const pxPerUnit = measured === null ? DEFAULT_PX_PER_UNIT : measured / width;
165
+ const { rootProps, getItemProps } = useRovingFocus({ activeId: selectedId ?? null });
166
+ const rootRef = useComposedRefs(canvasRef, rootProps.ref);
167
+ const selectable = onSelect !== undefined || selectedId !== undefined;
168
+ const hintId = useId();
169
+ const edit = useFloorPlanEdit({
170
+ enabled: editable,
171
+ items,
172
+ landmarks,
173
+ bounds: { width, height, snap, minSize },
174
+ canvasRef,
175
+ onChange,
176
+ onSelect,
177
+ });
178
+ const shownItems = items.map(edit.view);
179
+ const shownLandmarks = landmarks.map(edit.view);
180
+ const outlines = groupOutlines(shownItems);
181
+ const selectedBox = editable
182
+ ? [...shownItems, ...shownLandmarks].find((entry) => entry.id === selectedId)
183
+ : undefined;
184
+ const selectedSource = selectedBox
185
+ ? [...items, ...landmarks].find((entry) => entry.id === selectedBox.id)
186
+ : undefined;
187
+
188
+ return (
189
+ <div className={cn("@container/floor w-full", classNames?.root, className)}>
190
+ {/* biome-ignore lint/a11y/useSemanticElements: the canvas is a positioned div; a fieldset cannot be laid out as a canvas */}
191
+ <div
192
+ {...rootProps}
193
+ ref={rootRef}
194
+ role="group"
195
+ aria-label={ariaLabel ?? strings.floorPlan}
196
+ style={{
197
+ aspectRatio: `${width} / ${height}`,
198
+ ...(editable
199
+ ? {
200
+ backgroundImage: "radial-gradient(circle, var(--line-strong) 1px, transparent 1px)",
201
+ backgroundSize: `${100 / width}% ${100 / height}%`,
202
+ }
203
+ : null),
204
+ }}
205
+ data-editable={editable ? "" : undefined}
206
+ className={cn(
207
+ "relative w-full rounded-card border border-line bg-surface-sunken focus-visible:focus-ring",
208
+ classNames?.canvas,
209
+ )}
210
+ >
211
+ {editable ? (
212
+ <p id={hintId} className="sr-only">
213
+ {strings.floorPlanEditHint}
214
+ </p>
215
+ ) : null}
216
+ {shownLandmarks.map((landmark) => {
217
+ const common = {
218
+ "data-kind": landmark.kind,
219
+ style: percentBox(landmark, width, height),
220
+ className: cn(
221
+ "absolute flex items-center justify-center overflow-hidden rounded-control p-0.5 text-center text-ink-2 text-meta",
222
+ hatch,
223
+ classNames?.landmark,
224
+ ),
225
+ };
226
+ const label = (
227
+ <span className="max-w-full truncate rounded-chip bg-surface px-1">
228
+ {landmark.label}
229
+ </span>
230
+ );
231
+ if (!editable) {
232
+ return (
233
+ <div key={landmark.id} {...common}>
234
+ {label}
235
+ </div>
236
+ );
237
+ }
238
+ const selected = selectedId === landmark.id;
239
+ return (
240
+ <button
241
+ key={landmark.id}
242
+ type="button"
243
+ data-landmark={landmark.id}
244
+ aria-pressed={selectable ? selected : undefined}
245
+ aria-describedby={hintId}
246
+ {...common}
247
+ className={cn(
248
+ common.className,
249
+ "cursor-grab touch-none focus-visible:focus-ring active:cursor-grabbing",
250
+ selected && "ring-2 ring-accent",
251
+ )}
252
+ {...getItemProps(landmark.id, { onKeyDown: edit.onKeyDown(landmark) })}
253
+ {...edit.dragProps(landmark, "move")}
254
+ onClick={() => onSelect?.(landmark.id)}
255
+ >
256
+ <span className="sr-only">{landmark.label}</span>
257
+ <span aria-hidden="true" className="contents">
258
+ {label}
259
+ </span>
260
+ </button>
261
+ );
262
+ })}
263
+ {outlines.map((outline) => (
264
+ <div
265
+ key={outline.groupId}
266
+ aria-hidden="true"
267
+ data-group={outline.groupId}
268
+ style={percentBox(outline, width, height)}
269
+ className={cn(
270
+ "pointer-events-none absolute rounded-card border border-ink-3 border-dashed",
271
+ classNames?.group,
272
+ )}
273
+ />
274
+ ))}
275
+ {shownItems.map((item) => {
276
+ const selected = selectedId === item.id || item.ring === "selected";
277
+ const ring: FloorPlanRing = selected ? "selected" : (item.ring ?? "none");
278
+ const tone = item.tone ?? "neutral";
279
+ const placement = labelPlacement(item, pxPerUnit);
280
+ const hasStatus = item.statusLabel !== undefined || item.statusIcon !== undefined;
281
+ const style: CSSProperties | undefined = customToneStyle(
282
+ tone,
283
+ builtinTones,
284
+ percentBox(item, width, height),
285
+ );
286
+ return (
287
+ <button
288
+ key={item.id}
289
+ type="button"
290
+ data-item={item.id}
291
+ data-shape={item.shape}
292
+ data-tone={tone === "neutral" ? undefined : tone}
293
+ data-ring={ring === "none" ? undefined : ring}
294
+ data-label={placement}
295
+ data-selected={selected ? "" : undefined}
296
+ aria-pressed={selectable ? selected : undefined}
297
+ style={style}
298
+ aria-describedby={editable ? hintId : undefined}
299
+ {...getItemProps(item.id, { onKeyDown: edit.onKeyDown(item) })}
300
+ {...(editable ? edit.dragProps(item, "move") : null)}
301
+ onClick={() => onSelect?.(item.id)}
302
+ className={cn(
303
+ "absolute block rounded-control p-0 text-ink focus-visible:focus-ring",
304
+ editable && "cursor-grab touch-none active:cursor-grabbing",
305
+ isCustomTone(tone, builtinTones)
306
+ ? "text-(--tone-c)"
307
+ : (toneClasses[tone as FloorPlanBuiltinTone] ?? toneClasses.neutral),
308
+ ringClasses[ring],
309
+ classNames?.item,
310
+ )}
311
+ >
312
+ <TableGlyph
313
+ shape={item.shape}
314
+ seats={item.seats}
315
+ occupied={item.occupied ?? 0}
316
+ width={item.width}
317
+ height={item.height}
318
+ pattern={item.pattern}
319
+ size="fill"
320
+ className={cn(
321
+ "pointer-events-none absolute inset-0 text-current",
322
+ classNames?.glyph,
323
+ )}
324
+ />
325
+ <span
326
+ className={cn(
327
+ "pointer-events-none flex flex-col items-center text-center",
328
+ placement === "inside"
329
+ ? "absolute inset-0 justify-center"
330
+ : "absolute inset-x-0 top-full pt-0.5",
331
+ classNames?.label,
332
+ )}
333
+ >
334
+ <span className="whitespace-nowrap font-bold text-ink text-meta">{item.label}</span>
335
+ {hasStatus ? (
336
+ <span
337
+ className={cn(
338
+ "inline-flex items-center gap-0.5 whitespace-nowrap text-ink-2 text-count",
339
+ classNames?.status,
340
+ )}
341
+ >
342
+ {item.statusIcon ? (
343
+ <span aria-hidden="true" className="inline-flex shrink-0 text-current">
344
+ {item.statusIcon}
345
+ </span>
346
+ ) : null}
347
+ {item.statusLabel}
348
+ </span>
349
+ ) : null}
350
+ </span>
351
+ <span className="sr-only">
352
+ {format(item.seats === 1 ? strings.seatsOne : strings.seats, item.seats)}
353
+ {item.ring === "late" ? `, ${strings.late}` : ""}
354
+ </span>
355
+ </button>
356
+ );
357
+ })}
358
+ {selectedBox && selectedSource ? (
359
+ <div
360
+ data-edit-overlay={selectedBox.id}
361
+ style={percentBox(selectedBox, width, height)}
362
+ className="pointer-events-none absolute"
363
+ >
364
+ {HANDLES.map((handle) => (
365
+ <span
366
+ key={handle}
367
+ aria-hidden="true"
368
+ data-handle={handle}
369
+ {...edit.dragProps(selectedSource, handle)}
370
+ className={cn(
371
+ "pointer-events-auto absolute size-2.5 touch-none rounded-chip border border-accent bg-surface before:absolute before:-inset-1.5 before:content-['']",
372
+ handleClasses[handle],
373
+ classNames?.handle,
374
+ )}
375
+ />
376
+ ))}
377
+ <button
378
+ type="button"
379
+ aria-label={strings.rotate}
380
+ onClick={() => edit.rotate(selectedSource)}
381
+ className={cn(
382
+ "pointer-events-auto absolute right-0 bottom-full mb-1 inline-flex size-control-sm items-center justify-center rounded-control border border-line bg-surface text-ink-2 hover:bg-surface-2 focus-visible:focus-ring [&_svg]:size-4",
383
+ classNames?.rotate,
384
+ )}
385
+ >
386
+ <RotateCcw aria-hidden="true" />
387
+ </button>
388
+ </div>
389
+ ) : null}
390
+ </div>
391
+ </div>
392
+ );
393
+ }
@@ -0,0 +1,20 @@
1
+ export {
2
+ type EditBounds,
3
+ editKey,
4
+ moveBox,
5
+ type ResizeHandle,
6
+ resizeBox,
7
+ rotateBox,
8
+ snapTo,
9
+ } from "./edit-model.js";
10
+ export {
11
+ FloorPlan,
12
+ type FloorPlanBuiltinTone,
13
+ type FloorPlanItem,
14
+ type FloorPlanLandmark,
15
+ type FloorPlanPart,
16
+ type FloorPlanProps,
17
+ type FloorPlanRing,
18
+ type FloorPlanTone,
19
+ } from "./floor-plan.js";
20
+ export { type GroupOutline, groupOutlines, type LabelPlacement, labelPlacement } from "./model.js";
@@ -0,0 +1,81 @@
1
+ import type { TableShape } from "../../atoms/table-glyph/layout.js";
2
+
3
+ export interface Box {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ }
9
+
10
+ export interface FloorPlanBox extends Box {
11
+ id: string;
12
+ }
13
+
14
+ export type LabelPlacement = "inside" | "below";
15
+
16
+ export const DEFAULT_PX_PER_UNIT = 32;
17
+ const CHAIR_BAND = 0.24;
18
+ const MIN_INSIDE_WIDTH = 44;
19
+ const MIN_INSIDE_HEIGHT = 30;
20
+
21
+ /**
22
+ * Whether an item's label fits inside the table body. The usable area is the box minus the chair
23
+ * band (and a round body only offers its inscribed square), measured in pixels from the canvas
24
+ * scale; anything smaller puts the label under the shape.
25
+ */
26
+ export function labelPlacement(
27
+ item: { width: number; height: number; shape: TableShape },
28
+ pxPerUnit: number = DEFAULT_PX_PER_UNIT,
29
+ ): LabelPlacement {
30
+ if (item.shape === "bar") return "below";
31
+ const usable = (units: number) => units * pxPerUnit * (1 - 2 * CHAIR_BAND);
32
+ const round = item.shape === "round" ? Math.SQRT1_2 : 1;
33
+ const fits =
34
+ usable(item.width) * round >= MIN_INSIDE_WIDTH &&
35
+ usable(item.height) * round >= MIN_INSIDE_HEIGHT;
36
+ return fits ? "inside" : "below";
37
+ }
38
+
39
+ export function percentBox(box: Box, width: number, height: number) {
40
+ return {
41
+ left: `${(box.x / width) * 100}%`,
42
+ top: `${(box.y / height) * 100}%`,
43
+ width: `${(box.width / width) * 100}%`,
44
+ height: `${(box.height / height) * 100}%`,
45
+ };
46
+ }
47
+
48
+ export interface GroupOutline extends Box {
49
+ groupId: string;
50
+ }
51
+
52
+ export const GROUP_PADDING = 0.2;
53
+
54
+ /** One outline per `groupId` shared by at least two items: their union box plus a small padding. */
55
+ export function groupOutlines(
56
+ items: ReadonlyArray<Box & { groupId?: string | undefined }>,
57
+ ): GroupOutline[] {
58
+ const groups = new Map<string, Box[]>();
59
+ for (const item of items) {
60
+ if (item.groupId === undefined) continue;
61
+ const list = groups.get(item.groupId) ?? [];
62
+ list.push(item);
63
+ groups.set(item.groupId, list);
64
+ }
65
+ const outlines: GroupOutline[] = [];
66
+ for (const [groupId, members] of groups) {
67
+ if (members.length < 2) continue;
68
+ const left = Math.min(...members.map((m) => m.x));
69
+ const top = Math.min(...members.map((m) => m.y));
70
+ const right = Math.max(...members.map((m) => m.x + m.width));
71
+ const bottom = Math.max(...members.map((m) => m.y + m.height));
72
+ outlines.push({
73
+ groupId,
74
+ x: left - GROUP_PADDING,
75
+ y: top - GROUP_PADDING,
76
+ width: right - left + 2 * GROUP_PADDING,
77
+ height: bottom - top + 2 * GROUP_PADDING,
78
+ });
79
+ }
80
+ return outlines;
81
+ }