@jcsoftdev/ui 0.7.1 → 0.8.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/CHANGELOG.md +32 -0
- package/README.md +3 -0
- package/dist/atoms/elapsed-time/elapsed-time.d.ts +29 -0
- package/dist/atoms/elapsed-time/elapsed-time.js +65 -0
- package/dist/atoms/elapsed-time/index.d.ts +2 -0
- package/dist/atoms/elapsed-time/index.js +9 -0
- package/dist/atoms/elapsed-time/model.d.ts +17 -0
- package/dist/atoms/elapsed-time/model.js +37 -0
- package/dist/atoms/elapsed-time/ticker.d.ts +5 -0
- package/dist/atoms/elapsed-time/ticker.js +37 -0
- package/dist/atoms/index.d.ts +2 -0
- package/dist/atoms/index.js +2 -0
- package/dist/atoms/table-glyph/index.d.ts +2 -0
- package/dist/atoms/table-glyph/index.js +14 -0
- package/dist/atoms/table-glyph/layout.d.ts +38 -0
- package/dist/atoms/table-glyph/layout.js +152 -0
- package/dist/atoms/table-glyph/table-glyph.d.ts +32 -0
- package/dist/atoms/table-glyph/table-glyph.js +131 -0
- package/dist/containers/floor-plan/edit-model.d.ts +33 -0
- package/dist/containers/floor-plan/edit-model.js +82 -0
- package/dist/containers/floor-plan/floor-plan.d.ts +83 -0
- package/dist/containers/floor-plan/floor-plan.js +278 -0
- package/dist/containers/floor-plan/index.d.ts +3 -0
- package/dist/containers/floor-plan/index.js +21 -0
- package/dist/containers/floor-plan/model.d.ts +36 -0
- package/dist/containers/floor-plan/model.js +52 -0
- package/dist/containers/floor-plan/use-floor-plan-edit.d.ts +26 -0
- package/dist/containers/floor-plan/use-floor-plan-edit.js +97 -0
- package/dist/containers/index.d.ts +1 -0
- package/dist/containers/index.js +1 -0
- package/dist/i18n/strings.d.ts +44 -0
- package/dist/i18n/strings.js +22 -0
- package/package.json +2 -2
- package/src/atoms/elapsed-time/elapsed-time.tsx +101 -0
- package/src/atoms/elapsed-time/index.ts +6 -0
- package/src/atoms/elapsed-time/model.ts +54 -0
- package/src/atoms/elapsed-time/ticker.ts +39 -0
- package/src/atoms/index.ts +2 -0
- package/src/atoms/table-glyph/index.ts +14 -0
- package/src/atoms/table-glyph/layout.ts +187 -0
- package/src/atoms/table-glyph/table-glyph.tsx +161 -0
- package/src/containers/floor-plan/edit-model.ts +115 -0
- package/src/containers/floor-plan/floor-plan.tsx +393 -0
- package/src/containers/floor-plan/index.ts +20 -0
- package/src/containers/floor-plan/model.ts +81 -0
- package/src/containers/floor-plan/use-floor-plan-edit.ts +135 -0
- package/src/containers/index.ts +1 -0
- package/src/i18n/strings.ts +44 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.0 (2026-11-04)
|
|
4
|
+
|
|
5
|
+
### Floor plan
|
|
6
|
+
|
|
7
|
+
A salon plan for table-service apps: a live timer, a table glyph and a plan that shows the tables and
|
|
8
|
+
lets an operator rearrange them.
|
|
9
|
+
|
|
10
|
+
#### Added
|
|
11
|
+
|
|
12
|
+
- **`ElapsedTime`** (`atoms`): a live `<time>` on one shared 1 s ticker. `since`, `serverOffsetMs`
|
|
13
|
+
(corrects a skewed device clock), `format`, `warnAt` and `dangerAt` (tone thresholds),
|
|
14
|
+
`countdownTo` (counts down to a target, then reports the overrun). No `aria-live`, so a screen
|
|
15
|
+
reader is not interrupted every second.
|
|
16
|
+
- **`TableGlyph`** (`atoms`): an SVG table with its chairs placed from `shape` (`round`, `square`,
|
|
17
|
+
`rect`, `bar`) and `seats`; `occupied`, `size` and `pattern`. Exports `glyphLayout`.
|
|
18
|
+
- **`FloorPlan`** (`containers`), read-only: a salon plan on a grid-unit canvas. Items are roving-focus
|
|
19
|
+
buttons with a seat count, landmarks, group outlines (`groupId`, two or more items) and `late` and
|
|
20
|
+
`selected` rings. Labels sit inside the table body when they fit and below it otherwise.
|
|
21
|
+
- **`FloorPlan`, editable**: pass `onChange(items, landmarks)` to drag, resize and rotate items and
|
|
22
|
+
landmarks. The plan stays controlled by `items` and `landmarks`. Keyboard: Alt with arrows moves,
|
|
23
|
+
Alt and Shift with arrows resizes, R rotates. Exports the pure helpers `moveBox`, `resizeBox`,
|
|
24
|
+
`rotateBox`, `snapTo`, `editKey`.
|
|
25
|
+
- **11 UI strings** (en, es): `elapsedMinutesOne`, `elapsedMinutes`, `minutesShort`, `countdownLeft`,
|
|
26
|
+
`countdownOver`, `seats`, `seatsOne`, `late`, `floorPlan`, `rotate`, `floorPlanEditHint`.
|
|
27
|
+
|
|
28
|
+
#### Changed
|
|
29
|
+
|
|
30
|
+
- **Size budgets raised** for `ui/atoms` (23000 to 26000 B gzip) and `ui/containers` (117500 to 124000
|
|
31
|
+
B), the entries that hold the new components, and by 200 to 600 B for `ui/auth`, `ui/auth/statement`,
|
|
32
|
+
`ui/brand`, `ui/calendar`, `ui/forms`, `ui/i18n`, `ui/motion`, `ui/navigation`, `ui/overlays`,
|
|
33
|
+
`ui/shell` and `ui/states`, which bundle the larger string table.
|
|
34
|
+
|
|
3
35
|
## 0.7.1 (2026-11-03)
|
|
4
36
|
|
|
5
37
|
### Phone bottom bar counts
|
package/README.md
CHANGED
|
@@ -189,6 +189,9 @@ https://ui.jcsoftdev.com/docs/blocks/
|
|
|
189
189
|
| `Spinner`, `Kbd` | `atoms` | Loading ring (`size`, `label`, `label={false}` for decorative) and a styled `<kbd>`. |
|
|
190
190
|
| `IconButton` | `atoms` | Square `Button` with a required `label` (`aria-label`), `variant`, `size`, `loading`. |
|
|
191
191
|
| `DueChip` | `atoms` | Due-date chip: overdue, soon (`soonDays`) and ok states with a glyph and sr-only suffix; time-zone safe. |
|
|
192
|
+
| `ElapsedTime` | `atoms` | Live `<time>` timer on one shared 1 s ticker: `since`, `serverOffsetMs`, `format`, `warnAt`, `dangerAt`, `countdownTo`; no `aria-live`. |
|
|
193
|
+
| `TableGlyph` | `atoms` | SVG table with chairs placed from `shape` (`round`, `square`, `rect`, `bar`) and `seats`; `occupied`, `size`, `pattern`. |
|
|
194
|
+
| `FloorPlan` | `containers` | Read-only salon plan on a grid-unit canvas: items as roving-focus buttons, landmarks, group outlines, `late`/`selected` rings. |
|
|
192
195
|
| `Seal` | `atoms` | Stamp mark: `title`, `icon`, `tone`, optional named `label`. |
|
|
193
196
|
| `Tooltip` | `overlays` | Hover and focus tip: `content`, `shortcut`, `side`, `openDelay`, `closeDelay`; `role="tooltip"`. |
|
|
194
197
|
| `AlertDialog` | `overlays` | `role="alertdialog"` with cancel and confirm, `tone="danger"`, async `onConfirm` with a pending state. |
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
|
+
export type ElapsedTimePart = "root" | "text";
|
|
4
|
+
export interface ElapsedTimeProps extends Omit<ComponentPropsWithoutRef<"time">, "children"> {
|
|
5
|
+
/** Moment the timer counts from. */
|
|
6
|
+
since: Date | string;
|
|
7
|
+
/** Server clock minus the client clock in ms, so a skewed device still shows the server's elapsed time. */
|
|
8
|
+
serverOffsetMs?: number;
|
|
9
|
+
/**
|
|
10
|
+
* `mm:ss` (default) shows a ticking clock; `minutes` shows whole minutes. With reduced motion
|
|
11
|
+
* requested, `mm:ss` is shown as whole minutes so the digits stop ticking.
|
|
12
|
+
*/
|
|
13
|
+
format?: "mm:ss" | "minutes";
|
|
14
|
+
/** Minutes from which the text turns warning (counting up), or down to which it does (countdown). */
|
|
15
|
+
warnAt?: number;
|
|
16
|
+
/** Minutes from which the text turns danger (counting up), or down to which it does (countdown). A countdown past its target is always danger. */
|
|
17
|
+
dangerAt?: number;
|
|
18
|
+
/** Turns the timer into a countdown to this moment; `since` is then only the fallback reference. */
|
|
19
|
+
countdownTo?: Date | string;
|
|
20
|
+
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
21
|
+
classNames?: ClassNames<ElapsedTimePart>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A live timer in tabular numerals. Every instance shares one ticker (a single timer, aligned to
|
|
25
|
+
* the second, running only while something is mounted). It renders `<time>` with an ISO duration
|
|
26
|
+
* in `dateTime`, exposes plain text such as "12 minutes" to assistive tech and is never an
|
|
27
|
+
* `aria-live` region, so it does not interrupt anyone.
|
|
28
|
+
*/
|
|
29
|
+
export declare function ElapsedTime({ since, serverOffsetMs, format, warnAt, dangerAt, countdownTo, className, classNames, ...props }: ElapsedTimeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useSyncExternalStore } from "react";
|
|
4
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
5
|
+
import { cn } from "../../utils/cn.js";
|
|
6
|
+
import { usePrefersReducedMotion } from "../../utils/reduced-motion.js";
|
|
7
|
+
import { formatClock, isoDuration, readElapsed, toneFor } from "./model.js";
|
|
8
|
+
import { getTickerSnapshot, subscribeTicker } from "./ticker.js";
|
|
9
|
+
const toneClasses = {
|
|
10
|
+
neutral: "text-ink-2",
|
|
11
|
+
warning: "font-bold text-warning",
|
|
12
|
+
danger: "font-bold text-danger"
|
|
13
|
+
};
|
|
14
|
+
function fill(template, key, value) {
|
|
15
|
+
return template.replace(`{${key}}`, value);
|
|
16
|
+
}
|
|
17
|
+
function ElapsedTime({
|
|
18
|
+
since,
|
|
19
|
+
serverOffsetMs,
|
|
20
|
+
format = "mm:ss",
|
|
21
|
+
warnAt,
|
|
22
|
+
dangerAt,
|
|
23
|
+
countdownTo,
|
|
24
|
+
className,
|
|
25
|
+
classNames,
|
|
26
|
+
...props
|
|
27
|
+
}) {
|
|
28
|
+
const strings = useUiStrings();
|
|
29
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
30
|
+
const now = useSyncExternalStore(subscribeTicker, getTickerSnapshot, getTickerSnapshot);
|
|
31
|
+
const countdown = countdownTo !== void 0;
|
|
32
|
+
const reading = readElapsed({ since, now, serverOffsetMs, countdownTo });
|
|
33
|
+
const tone = toneFor(reading, countdown, warnAt, dangerAt);
|
|
34
|
+
const minutes = Math.floor(reading.seconds / 60);
|
|
35
|
+
const asClock = format === "mm:ss" && !reducedMotion;
|
|
36
|
+
const visible = asClock ? formatClock(reading.seconds) : fill(strings.minutesShort, "count", String(minutes));
|
|
37
|
+
const spoken = fill(
|
|
38
|
+
minutes === 1 ? strings.elapsedMinutesOne : strings.elapsedMinutes,
|
|
39
|
+
"count",
|
|
40
|
+
String(minutes)
|
|
41
|
+
);
|
|
42
|
+
const announced = countdown ? fill(reading.over ? strings.countdownOver : strings.countdownLeft, "time", spoken) : spoken;
|
|
43
|
+
return /* @__PURE__ */ jsxs(
|
|
44
|
+
"time",
|
|
45
|
+
{
|
|
46
|
+
dateTime: isoDuration(reading.seconds),
|
|
47
|
+
"data-tone": tone === "neutral" ? void 0 : tone,
|
|
48
|
+
"data-countdown": countdown ? "" : void 0,
|
|
49
|
+
className: cn(
|
|
50
|
+
"inline-block text-data tabular-nums transition-colors motion-reduce:transition-none",
|
|
51
|
+
toneClasses[tone],
|
|
52
|
+
classNames?.root,
|
|
53
|
+
className
|
|
54
|
+
),
|
|
55
|
+
...props,
|
|
56
|
+
children: [
|
|
57
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", suppressHydrationWarning: true, className: classNames?.text, children: visible }),
|
|
58
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", suppressHydrationWarning: true, children: announced })
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
ElapsedTime
|
|
65
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ElapsedTone = "neutral" | "warning" | "danger";
|
|
2
|
+
export interface ElapsedReading {
|
|
3
|
+
/** Whole seconds away from the reference: elapsed since it, or remaining until the target. */
|
|
4
|
+
seconds: number;
|
|
5
|
+
/** True once a countdown passed its target. */
|
|
6
|
+
over: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function toMs(value: Date | string | number): number;
|
|
9
|
+
export declare function readElapsed(options: {
|
|
10
|
+
since: Date | string;
|
|
11
|
+
now: number;
|
|
12
|
+
serverOffsetMs?: number | undefined;
|
|
13
|
+
countdownTo?: Date | string | undefined;
|
|
14
|
+
}): ElapsedReading;
|
|
15
|
+
export declare function toneFor(reading: ElapsedReading, countdown: boolean, warnAt?: number, dangerAt?: number): ElapsedTone;
|
|
16
|
+
export declare function formatClock(seconds: number): string;
|
|
17
|
+
export declare function isoDuration(seconds: number): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function toMs(value) {
|
|
2
|
+
return value instanceof Date ? value.getTime() : new Date(value).getTime();
|
|
3
|
+
}
|
|
4
|
+
function readElapsed(options) {
|
|
5
|
+
const { since, now, serverOffsetMs = 0, countdownTo } = options;
|
|
6
|
+
const clock = now + serverOffsetMs;
|
|
7
|
+
if (countdownTo !== void 0) {
|
|
8
|
+
const diff = Math.floor((toMs(countdownTo) - clock) / 1e3);
|
|
9
|
+
return { seconds: Math.abs(diff), over: diff < 0 };
|
|
10
|
+
}
|
|
11
|
+
return { seconds: Math.max(0, Math.floor((clock - toMs(since)) / 1e3)), over: false };
|
|
12
|
+
}
|
|
13
|
+
function toneFor(reading, countdown, warnAt, dangerAt) {
|
|
14
|
+
const minutes = reading.seconds / 60;
|
|
15
|
+
if (countdown) {
|
|
16
|
+
if (reading.over || dangerAt !== void 0 && minutes <= dangerAt) return "danger";
|
|
17
|
+
if (warnAt !== void 0 && minutes <= warnAt) return "warning";
|
|
18
|
+
return "neutral";
|
|
19
|
+
}
|
|
20
|
+
if (dangerAt !== void 0 && minutes >= dangerAt) return "danger";
|
|
21
|
+
if (warnAt !== void 0 && minutes >= warnAt) return "warning";
|
|
22
|
+
return "neutral";
|
|
23
|
+
}
|
|
24
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
25
|
+
function formatClock(seconds) {
|
|
26
|
+
return `${pad(Math.floor(seconds / 60))}:${pad(seconds % 60)}`;
|
|
27
|
+
}
|
|
28
|
+
function isoDuration(seconds) {
|
|
29
|
+
return `PT${Math.floor(seconds / 60)}M${seconds % 60}S`;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
formatClock,
|
|
33
|
+
isoDuration,
|
|
34
|
+
readElapsed,
|
|
35
|
+
toMs,
|
|
36
|
+
toneFor
|
|
37
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Subscribes to the one-second ticker every `ElapsedTime` shares; the timer runs only while someone listens. */
|
|
2
|
+
export declare function subscribeTicker(listener: () => void): () => void;
|
|
3
|
+
/** Wall clock floored to the second, stable between ticks so it is a valid external-store snapshot. */
|
|
4
|
+
export declare function getTickerSnapshot(): number;
|
|
5
|
+
export declare function tickerListenerCount(): number;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
2
|
+
let timer;
|
|
3
|
+
function stamp() {
|
|
4
|
+
return Math.floor(Date.now() / 1e3) * 1e3;
|
|
5
|
+
}
|
|
6
|
+
function schedule() {
|
|
7
|
+
timer = setTimeout(
|
|
8
|
+
() => {
|
|
9
|
+
for (const listener of [...listeners]) listener();
|
|
10
|
+
if (listeners.size > 0) schedule();
|
|
11
|
+
else timer = void 0;
|
|
12
|
+
},
|
|
13
|
+
1e3 - Date.now() % 1e3 + 5
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function subscribeTicker(listener) {
|
|
17
|
+
listeners.add(listener);
|
|
18
|
+
if (timer === void 0) schedule();
|
|
19
|
+
return () => {
|
|
20
|
+
listeners.delete(listener);
|
|
21
|
+
if (listeners.size === 0 && timer !== void 0) {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
timer = void 0;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function getTickerSnapshot() {
|
|
28
|
+
return stamp();
|
|
29
|
+
}
|
|
30
|
+
function tickerListenerCount() {
|
|
31
|
+
return listeners.size;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
getTickerSnapshot,
|
|
35
|
+
subscribeTicker,
|
|
36
|
+
tickerListenerCount
|
|
37
|
+
};
|
package/dist/atoms/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./checkbox/index.js";
|
|
|
6
6
|
export * from "./chip/index.js";
|
|
7
7
|
export * from "./divider/index.js";
|
|
8
8
|
export * from "./due-chip/index.js";
|
|
9
|
+
export * from "./elapsed-time/index.js";
|
|
9
10
|
export * from "./icon/index.js";
|
|
10
11
|
export * from "./icon-button/index.js";
|
|
11
12
|
export * from "./kbd/index.js";
|
|
@@ -19,4 +20,5 @@ export * from "./spinner/index.js";
|
|
|
19
20
|
export * from "./status-dot/index.js";
|
|
20
21
|
export * from "./status-pill/index.js";
|
|
21
22
|
export * from "./switch/index.js";
|
|
23
|
+
export * from "./table-glyph/index.js";
|
|
22
24
|
export * from "./trend-chip/index.js";
|
package/dist/atoms/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./checkbox/index.js";
|
|
|
6
6
|
export * from "./chip/index.js";
|
|
7
7
|
export * from "./divider/index.js";
|
|
8
8
|
export * from "./due-chip/index.js";
|
|
9
|
+
export * from "./elapsed-time/index.js";
|
|
9
10
|
export * from "./icon/index.js";
|
|
10
11
|
export * from "./icon-button/index.js";
|
|
11
12
|
export * from "./kbd/index.js";
|
|
@@ -19,4 +20,5 @@ export * from "./spinner/index.js";
|
|
|
19
20
|
export * from "./status-dot/index.js";
|
|
20
21
|
export * from "./status-pill/index.js";
|
|
21
22
|
export * from "./switch/index.js";
|
|
23
|
+
export * from "./table-glyph/index.js";
|
|
22
24
|
export * from "./trend-chip/index.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type TableShape = "round" | "square" | "rect" | "bar";
|
|
2
|
+
export interface Chair {
|
|
3
|
+
cx: number;
|
|
4
|
+
cy: number;
|
|
5
|
+
rotate: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
circle: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface GlyphLayout {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
body: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
round: boolean;
|
|
19
|
+
};
|
|
20
|
+
chairs: Chair[];
|
|
21
|
+
}
|
|
22
|
+
export declare const UNIT = 100;
|
|
23
|
+
export declare const CHAIR_DEPTH = 18;
|
|
24
|
+
export declare const CHAIR_WIDTH = 26;
|
|
25
|
+
export declare const CHAIR_GAP = 6;
|
|
26
|
+
type Side = "top" | "bottom" | "left" | "right";
|
|
27
|
+
/** Chairs per side of a square table: one per side up to four seats, then spread evenly with the remainder going top, bottom, left, right. */
|
|
28
|
+
export declare function squareSideCounts(seats: number): Record<Side, number>;
|
|
29
|
+
/** Chairs of a rect table: one at each end, the rest split between the two long sides (top gets the odd one). */
|
|
30
|
+
export declare function rectSideCounts(seats: number): Record<Side, number>;
|
|
31
|
+
/**
|
|
32
|
+
* Geometry of a table glyph in a `width` x `height` box (100 units per grid cell). Round tables
|
|
33
|
+
* space chairs radially; square ones put a chair per side up to four, then spread; rect tables
|
|
34
|
+
* seat one at each end and split the rest along the long sides; bars line stools up in a row.
|
|
35
|
+
* Rect and bar follow the longer axis of the box.
|
|
36
|
+
*/
|
|
37
|
+
export declare function glyphLayout(shape: TableShape, seats: number, width: number, height: number): GlyphLayout;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const UNIT = 100;
|
|
2
|
+
const CHAIR_DEPTH = 18;
|
|
3
|
+
const CHAIR_WIDTH = 26;
|
|
4
|
+
const CHAIR_GAP = 6;
|
|
5
|
+
const INSET = CHAIR_DEPTH + CHAIR_GAP;
|
|
6
|
+
function spread(count, length) {
|
|
7
|
+
return Array.from({ length: count }, (_, i) => (i + 0.5) / count * length);
|
|
8
|
+
}
|
|
9
|
+
function chairWidthFor(count, length) {
|
|
10
|
+
if (count === 0) return CHAIR_WIDTH;
|
|
11
|
+
return Math.max(6, Math.min(CHAIR_WIDTH, length / count - CHAIR_GAP));
|
|
12
|
+
}
|
|
13
|
+
function sideChair(side, along, w, h, size) {
|
|
14
|
+
const horizontal = side === "top" || side === "bottom";
|
|
15
|
+
const half = CHAIR_DEPTH / 2;
|
|
16
|
+
const cx = horizontal ? along : side === "left" ? half : w - half;
|
|
17
|
+
const cy = horizontal ? side === "top" ? half : h - half : along;
|
|
18
|
+
return {
|
|
19
|
+
cx,
|
|
20
|
+
cy,
|
|
21
|
+
rotate: horizontal ? 0 : 90,
|
|
22
|
+
width: size,
|
|
23
|
+
height: CHAIR_DEPTH,
|
|
24
|
+
circle: false
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function squareSideCounts(seats) {
|
|
28
|
+
const order = ["top", "bottom", "left", "right"];
|
|
29
|
+
const counts = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
30
|
+
const base = Math.floor(seats / 4);
|
|
31
|
+
const extra = seats % 4;
|
|
32
|
+
order.forEach((side, i) => {
|
|
33
|
+
counts[side] = base + (i < extra ? 1 : 0);
|
|
34
|
+
});
|
|
35
|
+
return counts;
|
|
36
|
+
}
|
|
37
|
+
function rectSideCounts(seats) {
|
|
38
|
+
const ends = Math.min(seats, 2);
|
|
39
|
+
const rest = seats - ends;
|
|
40
|
+
return {
|
|
41
|
+
left: ends >= 1 ? 1 : 0,
|
|
42
|
+
right: ends >= 2 ? 1 : 0,
|
|
43
|
+
top: Math.ceil(rest / 2),
|
|
44
|
+
bottom: Math.floor(rest / 2)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function sidedChairs(counts, w, h) {
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const side of ["top", "bottom", "left", "right"]) {
|
|
50
|
+
const horizontal = side === "top" || side === "bottom";
|
|
51
|
+
const length = horizontal ? w - 2 * INSET : h - 2 * INSET;
|
|
52
|
+
const offset = INSET;
|
|
53
|
+
const size = chairWidthFor(counts[side], length);
|
|
54
|
+
for (const along of spread(counts[side], length)) {
|
|
55
|
+
out.push(sideChair(side, offset + along, w, h, size));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
function roundLayout(seats, w, h) {
|
|
61
|
+
const cx = w / 2;
|
|
62
|
+
const cy = h / 2;
|
|
63
|
+
const radius = Math.max(8, Math.min(w, h) / 2 - INSET);
|
|
64
|
+
const orbit = radius + CHAIR_GAP + CHAIR_DEPTH / 2;
|
|
65
|
+
const size = chairWidthFor(seats, 2 * Math.PI * orbit);
|
|
66
|
+
const chairs = Array.from({ length: seats }, (_, i) => {
|
|
67
|
+
const angle = -Math.PI / 2 + i * 2 * Math.PI / seats;
|
|
68
|
+
return {
|
|
69
|
+
cx: cx + orbit * Math.cos(angle),
|
|
70
|
+
cy: cy + orbit * Math.sin(angle),
|
|
71
|
+
rotate: angle * 180 / Math.PI + 90,
|
|
72
|
+
width: size,
|
|
73
|
+
height: CHAIR_DEPTH,
|
|
74
|
+
circle: false
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
width: w,
|
|
79
|
+
height: h,
|
|
80
|
+
body: { x: cx - radius, y: cy - radius, width: 2 * radius, height: 2 * radius, round: true },
|
|
81
|
+
chairs
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function barLayout(seats, w, h) {
|
|
85
|
+
const counterHeight = Math.max(14, h * 0.4);
|
|
86
|
+
const stool = Math.min(
|
|
87
|
+
CHAIR_WIDTH * 0.8,
|
|
88
|
+
h - counterHeight - CHAIR_GAP,
|
|
89
|
+
w / Math.max(seats, 1) - 4
|
|
90
|
+
);
|
|
91
|
+
const diameter = Math.max(6, stool);
|
|
92
|
+
const chairs = spread(seats, w - 2 * CHAIR_GAP).map((x) => ({
|
|
93
|
+
cx: CHAIR_GAP + x,
|
|
94
|
+
cy: counterHeight + CHAIR_GAP + diameter / 2,
|
|
95
|
+
rotate: 0,
|
|
96
|
+
width: diameter,
|
|
97
|
+
height: diameter,
|
|
98
|
+
circle: true
|
|
99
|
+
}));
|
|
100
|
+
return {
|
|
101
|
+
width: w,
|
|
102
|
+
height: h,
|
|
103
|
+
body: { x: 0, y: 0, width: w, height: counterHeight, round: false },
|
|
104
|
+
chairs
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function transpose(layout) {
|
|
108
|
+
return {
|
|
109
|
+
width: layout.height,
|
|
110
|
+
height: layout.width,
|
|
111
|
+
body: {
|
|
112
|
+
x: layout.body.y,
|
|
113
|
+
y: layout.body.x,
|
|
114
|
+
width: layout.body.height,
|
|
115
|
+
height: layout.body.width,
|
|
116
|
+
round: layout.body.round
|
|
117
|
+
},
|
|
118
|
+
chairs: layout.chairs.map((c) => ({
|
|
119
|
+
...c,
|
|
120
|
+
cx: c.cy,
|
|
121
|
+
cy: c.cx,
|
|
122
|
+
rotate: c.circle ? 0 : c.rotate === 0 ? 90 : 0
|
|
123
|
+
}))
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function framed(counts, w, h) {
|
|
127
|
+
return {
|
|
128
|
+
width: w,
|
|
129
|
+
height: h,
|
|
130
|
+
body: { x: INSET, y: INSET, width: w - 2 * INSET, height: h - 2 * INSET, round: false },
|
|
131
|
+
chairs: sidedChairs(counts, w, h)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function glyphLayout(shape, seats, width, height) {
|
|
135
|
+
const count = Math.max(0, Math.floor(seats));
|
|
136
|
+
if (shape === "round") return roundLayout(count, width, height);
|
|
137
|
+
if (shape === "square") return framed(squareSideCounts(count), width, height);
|
|
138
|
+
const vertical = height > width;
|
|
139
|
+
const w = vertical ? height : width;
|
|
140
|
+
const h = vertical ? width : height;
|
|
141
|
+
const layout = shape === "rect" ? framed(rectSideCounts(count), w, h) : barLayout(count, w, h);
|
|
142
|
+
return vertical ? transpose(layout) : layout;
|
|
143
|
+
}
|
|
144
|
+
export {
|
|
145
|
+
CHAIR_DEPTH,
|
|
146
|
+
CHAIR_GAP,
|
|
147
|
+
CHAIR_WIDTH,
|
|
148
|
+
UNIT,
|
|
149
|
+
glyphLayout,
|
|
150
|
+
rectSideCounts,
|
|
151
|
+
squareSideCounts
|
|
152
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
|
+
import { type TableShape } from "./layout.js";
|
|
4
|
+
export type TableGlyphSize = "sm" | "md" | "lg" | "fill";
|
|
5
|
+
export type TableGlyphPattern = "dashed" | "solid" | "soft" | "strong";
|
|
6
|
+
export type TableGlyphPart = "root" | "body" | "chair";
|
|
7
|
+
export interface TableGlyphProps extends Omit<ComponentPropsWithoutRef<"svg">, "children"> {
|
|
8
|
+
shape: TableShape;
|
|
9
|
+
/** Chairs drawn around the table. */
|
|
10
|
+
seats: number;
|
|
11
|
+
/** How many chairs are filled, in drawing order. Clamped to `seats`. */
|
|
12
|
+
occupied?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Height of a one-unit box from the control-height tokens, so it follows density; wider shapes
|
|
15
|
+
* grow from it. `fill` takes the size of the parent instead.
|
|
16
|
+
*/
|
|
17
|
+
size?: TableGlyphSize;
|
|
18
|
+
/** Box in grid units (1 unit is one square cell). Defaults to 1x1, rect 2x1 and bar 3x1. */
|
|
19
|
+
width?: number;
|
|
20
|
+
height?: number;
|
|
21
|
+
/** Table surface: `dashed` outline, `solid` outline on the surface, `soft` or `strong` tint. Defaults to `solid`. */
|
|
22
|
+
pattern?: TableGlyphPattern;
|
|
23
|
+
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
24
|
+
classNames?: ClassNames<TableGlyphPart>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* An SVG table with its chairs placed from `seats` and `shape`: radial for round, one per side
|
|
28
|
+
* (then spread) for square, ends plus long sides for rect, a row of stools for bar. It draws with
|
|
29
|
+
* `currentColor` and the surface token, so it follows the text colour and the theme. Decorative
|
|
30
|
+
* (`aria-hidden`) unless an `aria-label` is given.
|
|
31
|
+
*/
|
|
32
|
+
export declare function TableGlyph({ shape, seats, occupied, size, width, height, pattern, className, classNames, "aria-label": ariaLabel, ...props }: TableGlyphProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { glyphLayout, UNIT } from "./layout.js";
|
|
4
|
+
const sizeClasses = {
|
|
5
|
+
sm: "h-control w-auto",
|
|
6
|
+
md: "h-control-lg w-auto",
|
|
7
|
+
lg: "h-[calc(var(--control-height-lg)*1.5)] w-auto",
|
|
8
|
+
fill: "size-full"
|
|
9
|
+
};
|
|
10
|
+
const patternClasses = {
|
|
11
|
+
dashed: "fill-transparent",
|
|
12
|
+
solid: "fill-surface",
|
|
13
|
+
soft: "fill-current/10",
|
|
14
|
+
strong: "fill-current/35"
|
|
15
|
+
};
|
|
16
|
+
const defaultBox = {
|
|
17
|
+
round: [1, 1],
|
|
18
|
+
square: [1, 1],
|
|
19
|
+
rect: [2, 1],
|
|
20
|
+
bar: [3, 1]
|
|
21
|
+
};
|
|
22
|
+
const STROKE = 1.5;
|
|
23
|
+
function TableGlyph({
|
|
24
|
+
shape,
|
|
25
|
+
seats,
|
|
26
|
+
occupied = 0,
|
|
27
|
+
size = "md",
|
|
28
|
+
width,
|
|
29
|
+
height,
|
|
30
|
+
pattern = "solid",
|
|
31
|
+
className,
|
|
32
|
+
classNames,
|
|
33
|
+
"aria-label": ariaLabel,
|
|
34
|
+
...props
|
|
35
|
+
}) {
|
|
36
|
+
const [defaultW, defaultH] = defaultBox[shape];
|
|
37
|
+
const w = (width ?? defaultW) * UNIT;
|
|
38
|
+
const h = (height ?? defaultH) * UNIT;
|
|
39
|
+
const layout = glyphLayout(shape, seats, w, h);
|
|
40
|
+
const filled = Math.max(0, Math.min(Math.floor(occupied), layout.chairs.length));
|
|
41
|
+
const { body } = layout;
|
|
42
|
+
const labelled = ariaLabel !== void 0;
|
|
43
|
+
return /* @__PURE__ */ jsxs(
|
|
44
|
+
"svg",
|
|
45
|
+
{
|
|
46
|
+
viewBox: `0 0 ${w} ${h}`,
|
|
47
|
+
role: labelled ? "img" : void 0,
|
|
48
|
+
"aria-label": ariaLabel,
|
|
49
|
+
"aria-hidden": labelled ? void 0 : true,
|
|
50
|
+
focusable: "false",
|
|
51
|
+
"data-shape": shape,
|
|
52
|
+
"data-seats": layout.chairs.length,
|
|
53
|
+
"data-occupied": filled,
|
|
54
|
+
"data-pattern": pattern,
|
|
55
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
56
|
+
className: cn("shrink-0 text-ink-2", sizeClasses[size], classNames?.root, className),
|
|
57
|
+
...props,
|
|
58
|
+
children: [
|
|
59
|
+
body.round ? /* @__PURE__ */ jsx(
|
|
60
|
+
"circle",
|
|
61
|
+
{
|
|
62
|
+
cx: body.x + body.width / 2,
|
|
63
|
+
cy: body.y + body.height / 2,
|
|
64
|
+
r: body.width / 2,
|
|
65
|
+
"data-part": "body",
|
|
66
|
+
className: cn("stroke-current", patternClasses[pattern], classNames?.body),
|
|
67
|
+
strokeWidth: STROKE,
|
|
68
|
+
strokeDasharray: pattern === "dashed" ? "5 4" : void 0,
|
|
69
|
+
vectorEffect: "non-scaling-stroke"
|
|
70
|
+
}
|
|
71
|
+
) : /* @__PURE__ */ jsx(
|
|
72
|
+
"rect",
|
|
73
|
+
{
|
|
74
|
+
x: body.x,
|
|
75
|
+
y: body.y,
|
|
76
|
+
width: body.width,
|
|
77
|
+
height: body.height,
|
|
78
|
+
rx: 6,
|
|
79
|
+
"data-part": "body",
|
|
80
|
+
className: cn("stroke-current", patternClasses[pattern], classNames?.body),
|
|
81
|
+
strokeWidth: STROKE,
|
|
82
|
+
strokeDasharray: pattern === "dashed" ? "5 4" : void 0,
|
|
83
|
+
vectorEffect: "non-scaling-stroke"
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
layout.chairs.map((chair, index) => {
|
|
87
|
+
const taken = index < filled;
|
|
88
|
+
const chairClass = cn(
|
|
89
|
+
"stroke-current",
|
|
90
|
+
taken ? "fill-current" : "fill-surface",
|
|
91
|
+
classNames?.chair
|
|
92
|
+
);
|
|
93
|
+
const key = `${chair.cx.toFixed(2)}-${chair.cy.toFixed(2)}`;
|
|
94
|
+
return chair.circle ? /* @__PURE__ */ jsx(
|
|
95
|
+
"circle",
|
|
96
|
+
{
|
|
97
|
+
cx: chair.cx,
|
|
98
|
+
cy: chair.cy,
|
|
99
|
+
r: chair.width / 2,
|
|
100
|
+
"data-part": "chair",
|
|
101
|
+
"data-occupied": taken ? "" : void 0,
|
|
102
|
+
className: chairClass,
|
|
103
|
+
strokeWidth: STROKE,
|
|
104
|
+
vectorEffect: "non-scaling-stroke"
|
|
105
|
+
},
|
|
106
|
+
key
|
|
107
|
+
) : /* @__PURE__ */ jsx(
|
|
108
|
+
"rect",
|
|
109
|
+
{
|
|
110
|
+
x: chair.cx - chair.width / 2,
|
|
111
|
+
y: chair.cy - chair.height / 2,
|
|
112
|
+
width: chair.width,
|
|
113
|
+
height: chair.height,
|
|
114
|
+
rx: 5,
|
|
115
|
+
transform: `rotate(${chair.rotate.toFixed(2)} ${chair.cx.toFixed(2)} ${chair.cy.toFixed(2)})`,
|
|
116
|
+
"data-part": "chair",
|
|
117
|
+
"data-occupied": taken ? "" : void 0,
|
|
118
|
+
className: chairClass,
|
|
119
|
+
strokeWidth: STROKE,
|
|
120
|
+
vectorEffect: "non-scaling-stroke"
|
|
121
|
+
},
|
|
122
|
+
key
|
|
123
|
+
);
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
TableGlyph
|
|
131
|
+
};
|