strata-react 2.1.13 → 2.1.15
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 +2 -1
- package/dist/index.d.ts +177 -7
- package/dist/index.js +1262 -89
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,8 +9,9 @@ import { n as useSharedCursor, r as geo, t as CursorScope } from "./cursor-Cwyvg
|
|
|
9
9
|
import { a as fieldErrorsOf, i as errorPayload, n as describeActionError, o as readErrorBody, r as describeHttpError, t as HttpError } from "./errors-CmuwcWlb.js";
|
|
10
10
|
import { a as PaletteChoice, c as paletteScript, d as usePalette, f as useSystemColorScheme, i as PALETTE_STORAGE_KEY, l as palettes, n as ColorSchemeChoice, o as ThemeProvider, p as Density, r as DEFAULT_PALETTE, s as colorSchemeScript, t as COLOR_SCHEME_STORAGE_KEY, u as useColorScheme } from "./theme-kCizTI4-.js";
|
|
11
11
|
import * as React from "react";
|
|
12
|
+
import { useRef, useState } from "react";
|
|
12
13
|
import { Autocomplete, Button as Button$1, Cell, Checkbox as Checkbox$1, Collection, Column, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridLayout, GridList, GridListItem, Header, Heading, Input as Input$1, Keyboard, Link, ListBox, ListBoxItem, ListLayout, ListStateContext, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, RouterProvider, Row, SearchField, Select, SelectValue, Separator, Slider as Slider$1, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Table, TableBody, TableHeader, TableLayout, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Tree as Tree$1, TreeItem, TreeItemContent, Virtualizer, useDragAndDrop, useFilter } from "react-aria-components";
|
|
13
|
-
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Brush, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronsUp, CircleAlert, CircleCheck, CircleDashed, Clock, CloudOff, Columns2, Ellipsis, Eraser, Eye, EyeOff, FastForward, FileQuestion, Flag, Folder, FolderOpen, FolderX, GripVertical, Hand, Highlighter, ImageOff, Info, KeyRound, LayoutGrid, List, Loader, LoaderCircle, Lock, Maximize, Maximize2, Minimize, Minus, MousePointer2, Paintbrush, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, PenLine, Pencil, Play, Redo2, Rewind, RotateCcw, RotateCw, Scan, Search, Send, SkipBack, SkipForward, SlidersHorizontal, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
14
|
+
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Brush, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronsUp, CircleAlert, CircleCheck, CircleDashed, Clock as Clock$1, CloudOff, Columns2, Ellipsis, Eraser, Eye, EyeOff, FastForward, FileQuestion, Flag, Folder, FolderOpen, FolderX, GripVertical, Hand, Highlighter, ImageOff, Info, KeyRound, LayoutGrid, List, Loader, LoaderCircle, Lock, Maximize, Maximize2, Minimize, Minus, MousePointer2, Paintbrush, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, PenLine, Pencil, Play, Redo2, Rewind, RotateCcw, RotateCw, Scan, Search, Send, SkipBack, SkipForward, SlidersHorizontal, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
14
15
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
16
|
import { Link as Link$1, NavLink, useHref, useNavigate, useSearchParams } from "react-router";
|
|
16
17
|
import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
@@ -2368,7 +2369,7 @@ const LOOKS$2 = {
|
|
|
2368
2369
|
},
|
|
2369
2370
|
blocked: {
|
|
2370
2371
|
tone: "neutral",
|
|
2371
|
-
icon: Clock
|
|
2372
|
+
icon: Clock$1
|
|
2372
2373
|
}
|
|
2373
2374
|
};
|
|
2374
2375
|
function wordOf(stage, words) {
|
|
@@ -2500,7 +2501,7 @@ function summariseWorkflow(stages, { running = false } = {}) {
|
|
|
2500
2501
|
const SUMMARY_LOOKS = {
|
|
2501
2502
|
running: {
|
|
2502
2503
|
tone: "info",
|
|
2503
|
-
icon: Clock,
|
|
2504
|
+
icon: Clock$1,
|
|
2504
2505
|
word: (w) => w.running
|
|
2505
2506
|
},
|
|
2506
2507
|
failed: {
|
|
@@ -3306,7 +3307,7 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
|
|
|
3306
3307
|
const LOOKS$1 = {
|
|
3307
3308
|
queued: {
|
|
3308
3309
|
tone: "neutral",
|
|
3309
|
-
icon: Clock,
|
|
3310
|
+
icon: Clock$1,
|
|
3310
3311
|
word: "Queued"
|
|
3311
3312
|
},
|
|
3312
3313
|
running: {
|
|
@@ -4434,20 +4435,20 @@ function useKeyOwner(enabled, playing = false) {
|
|
|
4434
4435
|
}
|
|
4435
4436
|
|
|
4436
4437
|
// src/components/media-group.tsx
|
|
4437
|
-
const groups = /* @__PURE__ */ new Map();
|
|
4438
|
+
const groups$1 = /* @__PURE__ */ new Map();
|
|
4438
4439
|
/** Adds an element, or a `useTimeline` clock, to a named group until the returned function is called; whenever one plays, the others pause. */
|
|
4439
4440
|
function joinMediaGroup(name, el) {
|
|
4440
|
-
let members = groups.get(name);
|
|
4441
|
-
if (!members) groups.set(name, members = /* @__PURE__ */ new Set());
|
|
4441
|
+
let members = groups$1.get(name);
|
|
4442
|
+
if (!members) groups$1.set(name, members = /* @__PURE__ */ new Set());
|
|
4442
4443
|
members.add(el);
|
|
4443
4444
|
const onPlay = () => {
|
|
4444
|
-
for (const other of groups.get(name) ?? []) if (other !== el && !other.paused) other.pause();
|
|
4445
|
+
for (const other of groups$1.get(name) ?? []) if (other !== el && !other.paused) other.pause();
|
|
4445
4446
|
};
|
|
4446
4447
|
el.addEventListener("play", onPlay);
|
|
4447
4448
|
return () => {
|
|
4448
4449
|
el.removeEventListener("play", onPlay);
|
|
4449
4450
|
members.delete(el);
|
|
4450
|
-
if (members.size === 0 && groups.get(name) === members) groups.delete(name);
|
|
4451
|
+
if (members.size === 0 && groups$1.get(name) === members) groups$1.delete(name);
|
|
4451
4452
|
};
|
|
4452
4453
|
}
|
|
4453
4454
|
const GroupContext = React.createContext(null);
|
|
@@ -21622,9 +21623,9 @@ const HANDLE_AT = {
|
|
|
21622
21623
|
sw: "left-0 bottom-0 -translate-x-1/2 translate-y-1/2",
|
|
21623
21624
|
w: "left-0 top-1/2 -translate-x-1/2 -translate-y-1/2"
|
|
21624
21625
|
};
|
|
21625
|
-
const round = (n) => format.integer(Math.round(n));
|
|
21626
|
+
const round$1 = (n) => format.integer(Math.round(n));
|
|
21626
21627
|
/** A window said in words. */
|
|
21627
|
-
const describeRegion = (r) => `${r.label}: ${round(r.w)} wide by ${round(r.h)} high, ${round(r.x)} across and ${round(r.y)} down`;
|
|
21628
|
+
const describeRegion = (r) => `${r.label}: ${round$1(r.w)} wide by ${round$1(r.h)} high, ${round$1(r.x)} across and ${round$1(r.y)} down`;
|
|
21628
21629
|
/** Draw and move one or two named windows on a picture, with pointer, keyboard and numbers kept in step; aspect and bounds hold through all three; two windows make a from/to move with a Watch preview. */
|
|
21629
21630
|
function RegionEditor({ label, children, size, regions, onChange, selectedId, onSelectedChange, aspect, min, bounds, step, onDraw, mode = "single", onPreview, duration = 1500, easing = "ease-in-out", fields = true, unit = "px", defaults, angle = 0, onAngleChange, guide, spreadLabels = {
|
|
21630
21631
|
one: "Page",
|
|
@@ -21825,7 +21826,7 @@ function RegionEditor({ label, children, size, regions, onChange, selectedId, on
|
|
|
21825
21826
|
...regions[1],
|
|
21826
21827
|
...moved[1]
|
|
21827
21828
|
}]);
|
|
21828
|
-
setSaid(`Gutter at ${round(gutterOf(moved[0], moved[1]))}: ${spreadLabels.left} ${round(moved[0].w)} wide, ${spreadLabels.right} ${round(moved[1].w)} wide`);
|
|
21829
|
+
setSaid(`Gutter at ${round$1(gutterOf(moved[0], moved[1]))}: ${spreadLabels.left} ${round$1(moved[0].w)} wide, ${spreadLabels.right} ${round$1(moved[1].w)} wide`);
|
|
21829
21830
|
}
|
|
21830
21831
|
};
|
|
21831
21832
|
const split = () => {
|
|
@@ -23637,6 +23638,106 @@ function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose
|
|
|
23637
23638
|
}
|
|
23638
23639
|
|
|
23639
23640
|
// src/components/clock-face.tsx
|
|
23641
|
+
/** Every analogue face, in the order a gallery shows them. */
|
|
23642
|
+
const CLOCK_FACE_STYLES = [
|
|
23643
|
+
"teaching",
|
|
23644
|
+
"railway",
|
|
23645
|
+
"classic",
|
|
23646
|
+
"bauhaus",
|
|
23647
|
+
"aviator",
|
|
23648
|
+
"modern",
|
|
23649
|
+
"minimal"
|
|
23650
|
+
];
|
|
23651
|
+
const PRESETS = {
|
|
23652
|
+
teaching: {
|
|
23653
|
+
numerals: "arabic",
|
|
23654
|
+
numbers: "all",
|
|
23655
|
+
marks: "minutes",
|
|
23656
|
+
hands: "teaching",
|
|
23657
|
+
minuteNumbers: false,
|
|
23658
|
+
rim: "plain",
|
|
23659
|
+
numeralSize: 20,
|
|
23660
|
+
numeralWeight: "font-semibold",
|
|
23661
|
+
pip: false
|
|
23662
|
+
},
|
|
23663
|
+
railway: {
|
|
23664
|
+
numerals: "none",
|
|
23665
|
+
numbers: "all",
|
|
23666
|
+
marks: "bars",
|
|
23667
|
+
hands: "railway",
|
|
23668
|
+
minuteNumbers: false,
|
|
23669
|
+
rim: "bold",
|
|
23670
|
+
numeralSize: 20,
|
|
23671
|
+
numeralWeight: "font-semibold",
|
|
23672
|
+
pip: false
|
|
23673
|
+
},
|
|
23674
|
+
classic: {
|
|
23675
|
+
numerals: "roman",
|
|
23676
|
+
numbers: "all",
|
|
23677
|
+
marks: "track",
|
|
23678
|
+
hands: "breguet",
|
|
23679
|
+
minuteNumbers: false,
|
|
23680
|
+
rim: "double",
|
|
23681
|
+
numeralSize: 15,
|
|
23682
|
+
numeralWeight: "font-normal",
|
|
23683
|
+
pip: false
|
|
23684
|
+
},
|
|
23685
|
+
bauhaus: {
|
|
23686
|
+
numerals: "arabic",
|
|
23687
|
+
numbers: "all",
|
|
23688
|
+
marks: "minutes",
|
|
23689
|
+
hands: "stick",
|
|
23690
|
+
minuteNumbers: false,
|
|
23691
|
+
rim: "thin",
|
|
23692
|
+
numeralSize: 13,
|
|
23693
|
+
numeralWeight: "font-normal",
|
|
23694
|
+
pip: false
|
|
23695
|
+
},
|
|
23696
|
+
aviator: {
|
|
23697
|
+
numerals: "arabic",
|
|
23698
|
+
numbers: "all",
|
|
23699
|
+
marks: "minutes",
|
|
23700
|
+
hands: "sword",
|
|
23701
|
+
minuteNumbers: true,
|
|
23702
|
+
rim: "bold",
|
|
23703
|
+
numeralSize: 21,
|
|
23704
|
+
numeralWeight: "font-bold",
|
|
23705
|
+
pip: true
|
|
23706
|
+
},
|
|
23707
|
+
modern: {
|
|
23708
|
+
numerals: "none",
|
|
23709
|
+
numbers: "all",
|
|
23710
|
+
marks: "dots",
|
|
23711
|
+
hands: "baton",
|
|
23712
|
+
minuteNumbers: false,
|
|
23713
|
+
rim: "none",
|
|
23714
|
+
numeralSize: 20,
|
|
23715
|
+
numeralWeight: "font-semibold",
|
|
23716
|
+
pip: false
|
|
23717
|
+
},
|
|
23718
|
+
minimal: {
|
|
23719
|
+
numerals: "none",
|
|
23720
|
+
numbers: "all",
|
|
23721
|
+
marks: "none",
|
|
23722
|
+
hands: "stick",
|
|
23723
|
+
minuteNumbers: false,
|
|
23724
|
+
rim: "thin",
|
|
23725
|
+
numeralSize: 20,
|
|
23726
|
+
numeralWeight: "font-semibold",
|
|
23727
|
+
pip: false
|
|
23728
|
+
}
|
|
23729
|
+
};
|
|
23730
|
+
/** The parts a face is drawn from, once a preset and the props that override it are put together. */
|
|
23731
|
+
function clockParts(face = "teaching", over = {}) {
|
|
23732
|
+
const p = PRESETS[face];
|
|
23733
|
+
return {
|
|
23734
|
+
numerals: over.numerals ?? p.numerals,
|
|
23735
|
+
numbers: over.numbers ?? p.numbers,
|
|
23736
|
+
marks: over.marks ?? p.marks,
|
|
23737
|
+
hands: over.hands ?? p.hands,
|
|
23738
|
+
minuteNumbers: over.minuteNumbers ?? p.minuteNumbers
|
|
23739
|
+
};
|
|
23740
|
+
}
|
|
23640
23741
|
const WORDS = [
|
|
23641
23742
|
"twelve",
|
|
23642
23743
|
"one",
|
|
@@ -23657,7 +23758,7 @@ const MINUTE_WORDS = {
|
|
|
23657
23758
|
20: "twenty",
|
|
23658
23759
|
25: "twenty-five"
|
|
23659
23760
|
};
|
|
23660
|
-
const NUMBER_WORDS = [
|
|
23761
|
+
const NUMBER_WORDS$1 = [
|
|
23661
23762
|
"",
|
|
23662
23763
|
"one",
|
|
23663
23764
|
"two",
|
|
@@ -23682,114 +23783,1186 @@ const NUMBER_WORDS = [
|
|
|
23682
23783
|
];
|
|
23683
23784
|
/** "one" to "twenty-nine", for the minutes said as a number ("seven minutes past three"). */
|
|
23684
23785
|
function minuteWord(n) {
|
|
23685
|
-
if (n <= 20) return NUMBER_WORDS[n] ?? String(n);
|
|
23686
|
-
return `twenty-${NUMBER_WORDS[n - 20]}`;
|
|
23786
|
+
if (n <= 20) return NUMBER_WORDS$1[n] ?? String(n);
|
|
23787
|
+
return `twenty-${NUMBER_WORDS$1[n - 20]}`;
|
|
23788
|
+
}
|
|
23789
|
+
/** The part of the day a 24-hour time falls in, as `clockWords` says it with `dayPart`. */
|
|
23790
|
+
function dayPart(hours) {
|
|
23791
|
+
const h = (Math.floor(hours) % 24 + 24) % 24;
|
|
23792
|
+
if (h >= 5 && h < 12) return "morning";
|
|
23793
|
+
if (h >= 12 && h < 18) return "afternoon";
|
|
23794
|
+
if (h >= 18 && h < 22) return "evening";
|
|
23795
|
+
return "night";
|
|
23687
23796
|
}
|
|
23688
23797
|
/**
|
|
23689
23798
|
* A time as it is said in UK English on a 12-hour clock: "three o'clock", "half past three", "quarter to four",
|
|
23690
23799
|
* "twenty-five past three", "seven minutes to four". The words a clock round speaks and a `ClockFace` is named by.
|
|
23800
|
+
* With `dayPart`, the hours are read as 0 to 23: "half past three in the afternoon", "twelve o'clock midnight".
|
|
23691
23801
|
*/
|
|
23692
|
-
function clockWords(hours, minutes) {
|
|
23802
|
+
function clockWords(hours, minutes, options = {}) {
|
|
23693
23803
|
const m = (Math.round(minutes) % 60 + 60) % 60;
|
|
23694
23804
|
const hour = (n) => WORDS[(n % 12 + 12) % 12];
|
|
23695
|
-
|
|
23696
|
-
if (m ===
|
|
23697
|
-
|
|
23698
|
-
|
|
23699
|
-
|
|
23700
|
-
|
|
23805
|
+
let said;
|
|
23806
|
+
if (m === 0) said = `${hour(hours)} o’clock`;
|
|
23807
|
+
else if (m === 30) said = `half past ${hour(hours)}`;
|
|
23808
|
+
else {
|
|
23809
|
+
const past = m < 30;
|
|
23810
|
+
const n = past ? m : 60 - m;
|
|
23811
|
+
const amount = n === 15 ? "quarter" : MINUTE_WORDS[n] ?? `${minuteWord(n)} minute${n === 1 ? "" : "s"}`;
|
|
23812
|
+
said = past ? `${amount} past ${hour(hours)}` : `${amount} to ${hour(hours + 1)}`;
|
|
23813
|
+
}
|
|
23814
|
+
if (!options.dayPart) return said;
|
|
23815
|
+
const h = (Math.floor(hours) % 24 + 24) % 24;
|
|
23816
|
+
if (m === 0 && h === 12) return `${said} midday`;
|
|
23817
|
+
if (m === 0 && h === 0) return `${said} midnight`;
|
|
23818
|
+
const part = dayPart(h);
|
|
23819
|
+
return part === "night" ? `${said} at night` : `${said} in the ${part}`;
|
|
23820
|
+
}
|
|
23821
|
+
const ROMAN = [
|
|
23822
|
+
"XII",
|
|
23823
|
+
"I",
|
|
23824
|
+
"II",
|
|
23825
|
+
"III",
|
|
23826
|
+
"IIII",
|
|
23827
|
+
"V",
|
|
23828
|
+
"VI",
|
|
23829
|
+
"VII",
|
|
23830
|
+
"VIII",
|
|
23831
|
+
"IX",
|
|
23832
|
+
"X",
|
|
23833
|
+
"XI"
|
|
23834
|
+
];
|
|
23835
|
+
/** A clock dial's Roman numeral for an hour, 1 to 12 (IIII at four, as dials write it, not IV). */
|
|
23836
|
+
function romanHour(n) {
|
|
23837
|
+
return ROMAN[(n % 12 + 12) % 12];
|
|
23701
23838
|
}
|
|
23702
|
-
const C = 100;
|
|
23839
|
+
const C$1 = 100;
|
|
23703
23840
|
/** A point `r` from the centre at `deg` clockwise from 12. */
|
|
23704
23841
|
function at(deg, r) {
|
|
23705
23842
|
const a = (deg - 90) * Math.PI / 180;
|
|
23706
23843
|
return {
|
|
23707
|
-
x:
|
|
23708
|
-
y:
|
|
23844
|
+
x: 100 + r * Math.cos(a),
|
|
23845
|
+
y: 100 + r * Math.sin(a)
|
|
23709
23846
|
};
|
|
23710
23847
|
}
|
|
23711
|
-
/**
|
|
23712
|
-
function
|
|
23848
|
+
/** The angles the hands point at, clockwise from 12: the hour hand between the numbers as the minutes pass. */
|
|
23849
|
+
function handAngles(hours, minutes, seconds = 0) {
|
|
23713
23850
|
const m = (minutes % 60 + 60) % 60;
|
|
23714
|
-
const
|
|
23715
|
-
|
|
23716
|
-
|
|
23717
|
-
|
|
23718
|
-
|
|
23719
|
-
|
|
23720
|
-
|
|
23721
|
-
|
|
23722
|
-
|
|
23723
|
-
|
|
23724
|
-
|
|
23725
|
-
|
|
23726
|
-
|
|
23727
|
-
|
|
23728
|
-
|
|
23729
|
-
|
|
23730
|
-
|
|
23731
|
-
|
|
23732
|
-
|
|
23851
|
+
const s = (seconds % 60 + 60) % 60;
|
|
23852
|
+
return {
|
|
23853
|
+
hour: (hours % 12 + 12) % 12 * 30 + m / 2,
|
|
23854
|
+
minute: m * 6,
|
|
23855
|
+
second: s * 6
|
|
23856
|
+
};
|
|
23857
|
+
}
|
|
23858
|
+
/** Points along a hand drawn pointing at 12, `from` below the centre to `to` above it, as an SVG polygon. */
|
|
23859
|
+
const poly$1 = (pts) => pts.map(([x, y]) => `${100 + x},${100 - y}`).join(" ");
|
|
23860
|
+
/** One hand drawn pointing at 12 (the group around it turns it): its shape by style, ink by role. */
|
|
23861
|
+
function handShape(style, which) {
|
|
23862
|
+
const hour = which === "hour";
|
|
23863
|
+
switch (style) {
|
|
23864
|
+
case "teaching": return /* @__PURE__ */ jsx("line", {
|
|
23865
|
+
x1: 100,
|
|
23866
|
+
y1: 110,
|
|
23867
|
+
x2: 100,
|
|
23868
|
+
y2: 100 - (hour ? 38 : 58),
|
|
23869
|
+
strokeWidth: hour ? 9 : 5,
|
|
23870
|
+
strokeLinecap: "round",
|
|
23871
|
+
className: hour ? "stroke-foreground" : "stroke-primary"
|
|
23872
|
+
});
|
|
23873
|
+
case "railway": {
|
|
23874
|
+
const [tail, tip, base, end] = hour ? [
|
|
23875
|
+
20,
|
|
23876
|
+
54,
|
|
23877
|
+
6,
|
|
23878
|
+
4.5
|
|
23879
|
+
] : [
|
|
23880
|
+
22,
|
|
23881
|
+
84,
|
|
23882
|
+
4.5,
|
|
23883
|
+
3.25
|
|
23884
|
+
];
|
|
23885
|
+
return /* @__PURE__ */ jsx("polygon", {
|
|
23886
|
+
points: poly$1([
|
|
23887
|
+
[-base, -tail],
|
|
23888
|
+
[base, -tail],
|
|
23889
|
+
[end, tip],
|
|
23890
|
+
[-end, tip]
|
|
23891
|
+
]),
|
|
23892
|
+
className: "fill-foreground"
|
|
23893
|
+
});
|
|
23894
|
+
}
|
|
23895
|
+
case "breguet": {
|
|
23896
|
+
const [len, ring] = hour ? [46, 30] : [74, 52];
|
|
23897
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
23898
|
+
className: "stroke-foreground",
|
|
23899
|
+
children: [
|
|
23900
|
+
/* @__PURE__ */ jsx("line", {
|
|
23901
|
+
x1: 100,
|
|
23902
|
+
y1: 114,
|
|
23903
|
+
x2: 100,
|
|
23904
|
+
y2: 100 - ring + 5,
|
|
23905
|
+
strokeWidth: 2.5,
|
|
23906
|
+
strokeLinecap: "round"
|
|
23907
|
+
}),
|
|
23908
|
+
/* @__PURE__ */ jsx("circle", {
|
|
23909
|
+
cx: 100,
|
|
23910
|
+
cy: 100 - ring,
|
|
23911
|
+
r: 5,
|
|
23912
|
+
strokeWidth: 2.2,
|
|
23913
|
+
className: "fill-card"
|
|
23914
|
+
}),
|
|
23915
|
+
/* @__PURE__ */ jsx("line", {
|
|
23916
|
+
x1: 100,
|
|
23917
|
+
y1: 100 - ring - 5,
|
|
23918
|
+
x2: 100,
|
|
23919
|
+
y2: 100 - len,
|
|
23920
|
+
strokeWidth: hour ? 2.5 : 1.8,
|
|
23921
|
+
strokeLinecap: "round"
|
|
23922
|
+
})
|
|
23923
|
+
]
|
|
23924
|
+
});
|
|
23925
|
+
}
|
|
23926
|
+
case "sword": {
|
|
23927
|
+
const [len, w] = hour ? [46, 6] : [74, 4.5];
|
|
23928
|
+
return /* @__PURE__ */ jsx("polygon", {
|
|
23929
|
+
points: poly$1([
|
|
23930
|
+
[0, -12],
|
|
23931
|
+
[w, len * .3],
|
|
23932
|
+
[0, len],
|
|
23933
|
+
[-w, len * .3]
|
|
23934
|
+
]),
|
|
23935
|
+
className: "fill-foreground"
|
|
23936
|
+
});
|
|
23937
|
+
}
|
|
23938
|
+
case "baton": return /* @__PURE__ */ jsx("line", {
|
|
23939
|
+
x1: 100,
|
|
23940
|
+
y1: 108,
|
|
23941
|
+
x2: 100,
|
|
23942
|
+
y2: 100 - (hour ? 48 : 74),
|
|
23943
|
+
strokeWidth: hour ? 8 : 6,
|
|
23944
|
+
strokeLinecap: "round",
|
|
23945
|
+
className: "stroke-foreground"
|
|
23946
|
+
});
|
|
23947
|
+
case "stick": return /* @__PURE__ */ jsx("line", {
|
|
23948
|
+
x1: 100,
|
|
23949
|
+
y1: 112,
|
|
23950
|
+
x2: 100,
|
|
23951
|
+
y2: 100 - (hour ? 50 : 80),
|
|
23952
|
+
strokeWidth: hour ? 4.5 : 3,
|
|
23953
|
+
strokeLinecap: "butt",
|
|
23954
|
+
className: "stroke-foreground"
|
|
23955
|
+
});
|
|
23956
|
+
}
|
|
23957
|
+
}
|
|
23958
|
+
/** The second hand: the railway clock's red disc, a fine accent line on any other face. */
|
|
23959
|
+
function secondShape(style) {
|
|
23960
|
+
if (style === "railway") return /* @__PURE__ */ jsxs("g", {
|
|
23961
|
+
className: "fill-danger stroke-danger",
|
|
23733
23962
|
children: [
|
|
23963
|
+
/* @__PURE__ */ jsx("line", {
|
|
23964
|
+
x1: 100,
|
|
23965
|
+
y1: 126,
|
|
23966
|
+
x2: 100,
|
|
23967
|
+
y2: 42,
|
|
23968
|
+
strokeWidth: 2.5
|
|
23969
|
+
}),
|
|
23734
23970
|
/* @__PURE__ */ jsx("circle", {
|
|
23735
|
-
cx:
|
|
23736
|
-
cy:
|
|
23737
|
-
r:
|
|
23738
|
-
strokeWidth: 6,
|
|
23739
|
-
className: "fill-card stroke-border"
|
|
23971
|
+
cx: 100,
|
|
23972
|
+
cy: 42,
|
|
23973
|
+
r: 9.5
|
|
23740
23974
|
}),
|
|
23741
|
-
|
|
23975
|
+
/* @__PURE__ */ jsx("circle", {
|
|
23976
|
+
cx: 100,
|
|
23977
|
+
cy: 100,
|
|
23978
|
+
r: 3.5
|
|
23979
|
+
})
|
|
23980
|
+
]
|
|
23981
|
+
});
|
|
23982
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
23983
|
+
className: "fill-accent stroke-accent",
|
|
23984
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
23985
|
+
x1: 100,
|
|
23986
|
+
y1: 118,
|
|
23987
|
+
x2: 100,
|
|
23988
|
+
y2: 16,
|
|
23989
|
+
strokeWidth: 1.4
|
|
23990
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
23991
|
+
cx: 100,
|
|
23992
|
+
cy: 100,
|
|
23993
|
+
r: 3
|
|
23994
|
+
})]
|
|
23995
|
+
});
|
|
23996
|
+
}
|
|
23997
|
+
/** A hand of a `ClockFace` or `SetClock`, turned to its angle: what `data-hand` and `data-angle` mark for tests. */
|
|
23998
|
+
function ClockHand({ which, style, angle }) {
|
|
23999
|
+
return /* @__PURE__ */ jsx("g", {
|
|
24000
|
+
"data-hand": which,
|
|
24001
|
+
"data-angle": angle,
|
|
24002
|
+
transform: `rotate(${angle} ${100} ${100})`,
|
|
24003
|
+
children: which === "second" ? secondShape(style) : handShape(style, which)
|
|
24004
|
+
});
|
|
24005
|
+
}
|
|
24006
|
+
/** The hub over the hands' ends: a cap in the hands' own ink. */
|
|
24007
|
+
function ClockHub({ hands }) {
|
|
24008
|
+
if (hands === "railway") return /* @__PURE__ */ jsx("circle", {
|
|
24009
|
+
cx: 100,
|
|
24010
|
+
cy: 100,
|
|
24011
|
+
r: 4,
|
|
24012
|
+
className: "fill-foreground"
|
|
24013
|
+
});
|
|
24014
|
+
if (hands === "breguet") return /* @__PURE__ */ jsx("circle", {
|
|
24015
|
+
cx: 100,
|
|
24016
|
+
cy: 100,
|
|
24017
|
+
r: 4,
|
|
24018
|
+
strokeWidth: 1.5,
|
|
24019
|
+
className: "fill-card stroke-foreground"
|
|
24020
|
+
});
|
|
24021
|
+
if (hands === "stick" || hands === "sword") return /* @__PURE__ */ jsx("circle", {
|
|
24022
|
+
cx: 100,
|
|
24023
|
+
cy: 100,
|
|
24024
|
+
r: 4.5,
|
|
24025
|
+
className: "fill-foreground"
|
|
24026
|
+
});
|
|
24027
|
+
return /* @__PURE__ */ jsx("circle", {
|
|
24028
|
+
cx: 100,
|
|
24029
|
+
cy: 100,
|
|
24030
|
+
r: 7,
|
|
24031
|
+
className: "fill-foreground"
|
|
24032
|
+
});
|
|
24033
|
+
}
|
|
24034
|
+
/** The rim and the face it holds. */
|
|
24035
|
+
function Rim({ rim }) {
|
|
24036
|
+
switch (rim) {
|
|
24037
|
+
case "plain": return /* @__PURE__ */ jsx("circle", {
|
|
24038
|
+
cx: 100,
|
|
24039
|
+
cy: 100,
|
|
24040
|
+
r: 94,
|
|
24041
|
+
strokeWidth: 6,
|
|
24042
|
+
className: "fill-card stroke-border"
|
|
24043
|
+
});
|
|
24044
|
+
case "bold": return /* @__PURE__ */ jsx("circle", {
|
|
24045
|
+
cx: 100,
|
|
24046
|
+
cy: 100,
|
|
24047
|
+
r: 94,
|
|
24048
|
+
strokeWidth: 6,
|
|
24049
|
+
className: "fill-card stroke-foreground"
|
|
24050
|
+
});
|
|
24051
|
+
case "double": return /* @__PURE__ */ jsxs("g", {
|
|
24052
|
+
className: "stroke-foreground",
|
|
24053
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
24054
|
+
cx: 100,
|
|
24055
|
+
cy: 100,
|
|
24056
|
+
r: 95,
|
|
24057
|
+
strokeWidth: 2.5,
|
|
24058
|
+
className: "fill-card"
|
|
24059
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
24060
|
+
cx: 100,
|
|
24061
|
+
cy: 100,
|
|
24062
|
+
r: 91,
|
|
24063
|
+
strokeWidth: .8,
|
|
24064
|
+
fill: "none"
|
|
24065
|
+
})]
|
|
24066
|
+
});
|
|
24067
|
+
case "thin": return /* @__PURE__ */ jsx("circle", {
|
|
24068
|
+
cx: 100,
|
|
24069
|
+
cy: 100,
|
|
24070
|
+
r: 95,
|
|
24071
|
+
strokeWidth: 1.5,
|
|
24072
|
+
className: "fill-card stroke-foreground"
|
|
24073
|
+
});
|
|
24074
|
+
case "none": return /* @__PURE__ */ jsx("circle", {
|
|
24075
|
+
cx: 100,
|
|
24076
|
+
cy: 100,
|
|
24077
|
+
r: 96,
|
|
24078
|
+
className: "fill-muted"
|
|
24079
|
+
});
|
|
24080
|
+
}
|
|
24081
|
+
}
|
|
24082
|
+
/** The marks round the rim, each tagged `data-mark` with what it marks. */
|
|
24083
|
+
function Marks({ marks }) {
|
|
24084
|
+
if (marks === "none") return null;
|
|
24085
|
+
if (marks === "dots") return /* @__PURE__ */ jsx("g", {
|
|
24086
|
+
className: "fill-foreground",
|
|
24087
|
+
children: Array.from({ length: 12 }, (_, i) => {
|
|
24088
|
+
const p = at(i * 30, 84);
|
|
24089
|
+
return /* @__PURE__ */ jsx("circle", {
|
|
24090
|
+
"data-mark": "hour",
|
|
24091
|
+
cx: p.x,
|
|
24092
|
+
cy: p.y,
|
|
24093
|
+
r: i % 3 === 0 ? 5 : 3.2
|
|
24094
|
+
}, i);
|
|
24095
|
+
})
|
|
24096
|
+
});
|
|
24097
|
+
if (marks === "bars") return /* @__PURE__ */ jsx("g", {
|
|
24098
|
+
className: "fill-foreground",
|
|
24099
|
+
children: Array.from({ length: 60 }, (_, i) => {
|
|
24100
|
+
const hourMark = i % 5 === 0;
|
|
24101
|
+
const [w, from, to] = hourMark ? [
|
|
24102
|
+
7,
|
|
24103
|
+
62,
|
|
24104
|
+
89
|
|
24105
|
+
] : [
|
|
24106
|
+
2.6,
|
|
24107
|
+
81,
|
|
24108
|
+
89
|
|
24109
|
+
];
|
|
24110
|
+
return /* @__PURE__ */ jsx("rect", {
|
|
24111
|
+
"data-mark": hourMark ? "hour" : "minute",
|
|
24112
|
+
x: 100 - w / 2,
|
|
24113
|
+
y: 100 - to,
|
|
24114
|
+
width: w,
|
|
24115
|
+
height: to - from,
|
|
24116
|
+
transform: `rotate(${i * 6} ${100} ${100})`
|
|
24117
|
+
}, i);
|
|
24118
|
+
})
|
|
24119
|
+
});
|
|
24120
|
+
if (marks === "track") return /* @__PURE__ */ jsxs("g", {
|
|
24121
|
+
className: "stroke-foreground",
|
|
24122
|
+
children: [
|
|
24123
|
+
/* @__PURE__ */ jsx("circle", {
|
|
24124
|
+
cx: 100,
|
|
24125
|
+
cy: 100,
|
|
24126
|
+
r: 87,
|
|
24127
|
+
strokeWidth: .8,
|
|
24128
|
+
fill: "none"
|
|
24129
|
+
}),
|
|
24130
|
+
/* @__PURE__ */ jsx("circle", {
|
|
24131
|
+
cx: 100,
|
|
24132
|
+
cy: 100,
|
|
24133
|
+
r: 80,
|
|
24134
|
+
strokeWidth: .8,
|
|
24135
|
+
fill: "none"
|
|
24136
|
+
}),
|
|
24137
|
+
Array.from({ length: 60 }, (_, i) => {
|
|
23742
24138
|
const hourMark = i % 5 === 0;
|
|
23743
|
-
const outer = at(i * 6,
|
|
23744
|
-
const inner = at(i * 6,
|
|
24139
|
+
const outer = at(i * 6, 87);
|
|
24140
|
+
const inner = at(i * 6, 80);
|
|
23745
24141
|
return /* @__PURE__ */ jsx("line", {
|
|
23746
24142
|
"data-mark": hourMark ? "hour" : "minute",
|
|
23747
24143
|
x1: outer.x,
|
|
23748
24144
|
y1: outer.y,
|
|
23749
24145
|
x2: inner.x,
|
|
23750
24146
|
y2: inner.y,
|
|
23751
|
-
strokeWidth: hourMark ?
|
|
23752
|
-
strokeLinecap: "round",
|
|
23753
|
-
className: hourMark ? "stroke-foreground" : "stroke-muted-foreground"
|
|
24147
|
+
strokeWidth: hourMark ? 2.6 : .8
|
|
23754
24148
|
}, i);
|
|
24149
|
+
})
|
|
24150
|
+
]
|
|
24151
|
+
});
|
|
24152
|
+
const every = marks === "minutes";
|
|
24153
|
+
return /* @__PURE__ */ jsx("g", { children: Array.from({ length: every ? 60 : 12 }, (_, k) => every ? k : k * 5).map((i) => {
|
|
24154
|
+
const hourMark = i % 5 === 0;
|
|
24155
|
+
const outer = at(i * 6, 89);
|
|
24156
|
+
const inner = at(i * 6, hourMark ? 82 : 86);
|
|
24157
|
+
return /* @__PURE__ */ jsx("line", {
|
|
24158
|
+
"data-mark": hourMark ? "hour" : "minute",
|
|
24159
|
+
x1: outer.x,
|
|
24160
|
+
y1: outer.y,
|
|
24161
|
+
x2: inner.x,
|
|
24162
|
+
y2: inner.y,
|
|
24163
|
+
strokeWidth: hourMark ? 3.5 : 1.5,
|
|
24164
|
+
strokeLinecap: "round",
|
|
24165
|
+
className: hourMark ? "stroke-foreground" : "stroke-muted-foreground"
|
|
24166
|
+
}, i);
|
|
24167
|
+
}) });
|
|
24168
|
+
}
|
|
24169
|
+
/** The face without its hands: rim, marks, numerals, minute numbers. Shared with `SetClock`. */
|
|
24170
|
+
function ClockDial({ face = "teaching", parts }) {
|
|
24171
|
+
const preset = PRESETS[face];
|
|
24172
|
+
const shown = (n) => parts.numerals !== "none" && (parts.numbers === "all" || parts.numbers === "quarters" && n % 3 === 0) && !(preset.pip && n === 12);
|
|
24173
|
+
const radius = parts.marks === "track" ? 66 : parts.marks === "bars" ? 50 : 70;
|
|
24174
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
24175
|
+
/* @__PURE__ */ jsx(Rim, { rim: preset.rim }),
|
|
24176
|
+
/* @__PURE__ */ jsx(Marks, { marks: parts.marks }),
|
|
24177
|
+
preset.pip && parts.numerals !== "none" && /* @__PURE__ */ jsx("polygon", {
|
|
24178
|
+
"data-mark": "pip",
|
|
24179
|
+
points: `93,21 107,21 ${100},34`,
|
|
24180
|
+
className: "fill-foreground"
|
|
24181
|
+
}),
|
|
24182
|
+
Array.from({ length: 12 }, (_, i) => i + 1).filter(shown).map((n) => {
|
|
24183
|
+
const p = at(n * 30, radius);
|
|
24184
|
+
return /* @__PURE__ */ jsx("text", {
|
|
24185
|
+
x: p.x,
|
|
24186
|
+
y: p.y,
|
|
24187
|
+
textAnchor: "middle",
|
|
24188
|
+
dominantBaseline: "central",
|
|
24189
|
+
fontSize: parts.numerals === "roman" ? Math.min(preset.numeralSize, 15) : preset.numeralSize,
|
|
24190
|
+
className: cn("fill-foreground tabular-nums", preset.numeralWeight),
|
|
24191
|
+
children: parts.numerals === "roman" ? romanHour(n) : n
|
|
24192
|
+
}, n);
|
|
24193
|
+
}),
|
|
24194
|
+
parts.minuteNumbers && Array.from({ length: 12 }, (_, i) => i * 5).map((m) => {
|
|
24195
|
+
const p = at(m * 6, 108);
|
|
24196
|
+
return /* @__PURE__ */ jsx("text", {
|
|
24197
|
+
"data-minute-number": m,
|
|
24198
|
+
x: p.x,
|
|
24199
|
+
y: p.y,
|
|
24200
|
+
textAnchor: "middle",
|
|
24201
|
+
dominantBaseline: "central",
|
|
24202
|
+
fontSize: 12,
|
|
24203
|
+
className: "fill-muted-foreground tabular-nums",
|
|
24204
|
+
children: String(m).padStart(2, "0")
|
|
24205
|
+
}, `m${m}`);
|
|
24206
|
+
})
|
|
24207
|
+
] });
|
|
24208
|
+
}
|
|
24209
|
+
/** The SVG box: wider when minute numbers are written outside the rim, so nothing inside shrinks. */
|
|
24210
|
+
const clockViewBox = (minuteNumbers) => minuteNumbers ? "-22 -22 244 244" : "0 0 200 200";
|
|
24211
|
+
/** An analogue clock showing one time, in a face people know (a classroom clock by default, its hands told apart). */
|
|
24212
|
+
function ClockFace({ hours, minutes, seconds, label, face = "teaching", numbers, numerals, marks, hands, minuteNumbers, minuteMarks, className }) {
|
|
24213
|
+
const preset = PRESETS[face];
|
|
24214
|
+
const parts = clockParts(face, {
|
|
24215
|
+
numbers,
|
|
24216
|
+
numerals,
|
|
24217
|
+
hands,
|
|
24218
|
+
minuteNumbers,
|
|
24219
|
+
marks: marks ?? (minuteMarks === false && preset.marks === "minutes" ? "hours" : void 0)
|
|
24220
|
+
});
|
|
24221
|
+
const angle = handAngles(hours, minutes, seconds);
|
|
24222
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
24223
|
+
viewBox: clockViewBox(parts.minuteNumbers),
|
|
24224
|
+
role: "img",
|
|
24225
|
+
"aria-label": label ?? clockWords(hours, minutes),
|
|
24226
|
+
"data-face": face,
|
|
24227
|
+
className: cn("block aspect-square w-48", className),
|
|
24228
|
+
children: [
|
|
24229
|
+
/* @__PURE__ */ jsx(ClockDial, {
|
|
24230
|
+
face,
|
|
24231
|
+
parts
|
|
23755
24232
|
}),
|
|
23756
|
-
|
|
23757
|
-
|
|
23758
|
-
|
|
23759
|
-
|
|
23760
|
-
y: p.y,
|
|
23761
|
-
textAnchor: "middle",
|
|
23762
|
-
dominantBaseline: "central",
|
|
23763
|
-
fontSize: 20,
|
|
23764
|
-
className: "fill-foreground font-semibold tabular-nums",
|
|
23765
|
-
children: n
|
|
23766
|
-
}, n);
|
|
24233
|
+
/* @__PURE__ */ jsx(ClockHand, {
|
|
24234
|
+
which: "hour",
|
|
24235
|
+
style: parts.hands,
|
|
24236
|
+
angle: angle.hour
|
|
23767
24237
|
}),
|
|
23768
|
-
/* @__PURE__ */ jsx(
|
|
23769
|
-
|
|
23770
|
-
|
|
23771
|
-
|
|
23772
|
-
strokeWidth: 9,
|
|
23773
|
-
strokeLinecap: "round",
|
|
23774
|
-
className: "stroke-foreground"
|
|
24238
|
+
/* @__PURE__ */ jsx(ClockHand, {
|
|
24239
|
+
which: "minute",
|
|
24240
|
+
style: parts.hands,
|
|
24241
|
+
angle: angle.minute
|
|
23775
24242
|
}),
|
|
23776
|
-
/* @__PURE__ */ jsx(
|
|
23777
|
-
|
|
23778
|
-
|
|
23779
|
-
|
|
23780
|
-
strokeWidth: 5,
|
|
23781
|
-
strokeLinecap: "round",
|
|
23782
|
-
className: "stroke-primary"
|
|
24243
|
+
seconds !== void 0 && /* @__PURE__ */ jsx(ClockHand, {
|
|
24244
|
+
which: "second",
|
|
24245
|
+
style: parts.hands,
|
|
24246
|
+
angle: angle.second
|
|
23783
24247
|
}),
|
|
23784
|
-
/* @__PURE__ */ jsx(
|
|
23785
|
-
cx: C,
|
|
23786
|
-
cy: C,
|
|
23787
|
-
r: 7,
|
|
23788
|
-
className: "fill-foreground"
|
|
23789
|
-
})
|
|
24248
|
+
/* @__PURE__ */ jsx(ClockHub, { hands: parts.hands })
|
|
23790
24249
|
]
|
|
23791
24250
|
});
|
|
23792
24251
|
}
|
|
23793
24252
|
|
|
23794
|
-
|
|
24253
|
+
// src/components/digital-clock.tsx
|
|
24254
|
+
/** Every digital face, in the order a gallery shows them. */
|
|
24255
|
+
const DIGITAL_CLOCK_STYLES = [
|
|
24256
|
+
"segments",
|
|
24257
|
+
"flip",
|
|
24258
|
+
"plain"
|
|
24259
|
+
];
|
|
24260
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
24261
|
+
/** The hour a clock shows: 1 to 12 on a 12-hour clock (0 is 12), 0 to 23 on a 24-hour one. */
|
|
24262
|
+
function shownHour(hours, hour12) {
|
|
24263
|
+
const h = (Math.floor(hours) % 24 + 24) % 24;
|
|
24264
|
+
return hour12 ? h % 12 || 12 : h;
|
|
24265
|
+
}
|
|
24266
|
+
/**
|
|
24267
|
+
* A time as a digital clock writes it: "3:45" on a 12-hour clock, "15:45" or "03:45" on a 24-hour one, "3:45 pm"
|
|
24268
|
+
* with `period`, "3:45:09" with `seconds`. Hours are 0 to 23, so 15 is "3:45 pm" and 0 is "12:00 am".
|
|
24269
|
+
*/
|
|
24270
|
+
function digitalTime(hours, minutes, options = {}) {
|
|
24271
|
+
const { hour12 = true, period = false, seconds } = options;
|
|
24272
|
+
const h = shownHour(hours, hour12);
|
|
24273
|
+
const m = (Math.floor(minutes) % 60 + 60) % 60;
|
|
24274
|
+
const time = `${hour12 ? h : two(h)}:${two(m)}${seconds === void 0 ? "" : `:${two((seconds % 60 + 60) % 60)}`}`;
|
|
24275
|
+
if (!hour12 || !period) return time;
|
|
24276
|
+
return `${time} ${(Math.floor(hours) % 24 + 24) % 24 < 12 ? "am" : "pm"}`;
|
|
24277
|
+
}
|
|
24278
|
+
const DIGITS = {
|
|
24279
|
+
"0": "abcdef",
|
|
24280
|
+
"1": "bc",
|
|
24281
|
+
"2": "abged",
|
|
24282
|
+
"3": "abgcd",
|
|
24283
|
+
"4": "fgbc",
|
|
24284
|
+
"5": "afgcd",
|
|
24285
|
+
"6": "afgedc",
|
|
24286
|
+
"7": "abc",
|
|
24287
|
+
"8": "abcdefg",
|
|
24288
|
+
"9": "abcdfg"
|
|
24289
|
+
};
|
|
24290
|
+
const W = 40;
|
|
24291
|
+
const H = 72;
|
|
24292
|
+
const T = 8;
|
|
24293
|
+
/** A segment's hexagon: horizontal at height y from x0 to x1, or vertical at x from y0 to y1. */
|
|
24294
|
+
function segment(id) {
|
|
24295
|
+
const g = 1.5;
|
|
24296
|
+
const horizontal = (y) => {
|
|
24297
|
+
const x0 = 5.5;
|
|
24298
|
+
const x1 = W - T / 2 - g;
|
|
24299
|
+
return `${x0},${y} 9.5,${y - T / 2} ${x1 - T / 2},${y - T / 2} ${x1},${y} ${x1 - T / 2},${y + T / 2} 9.5,${y + T / 2}`;
|
|
24300
|
+
};
|
|
24301
|
+
const vertical = (x, y0, y1) => {
|
|
24302
|
+
const a = y0 + g;
|
|
24303
|
+
const b = y1 - g;
|
|
24304
|
+
return `${x},${a} ${x + T / 2},${a + T / 2} ${x + T / 2},${b - T / 2} ${x},${b} ${x - T / 2},${b - T / 2} ${x - T / 2},${a + T / 2}`;
|
|
24305
|
+
};
|
|
24306
|
+
const mid = H / 2;
|
|
24307
|
+
switch (id) {
|
|
24308
|
+
case "a": return horizontal(T / 2);
|
|
24309
|
+
case "g": return horizontal(mid);
|
|
24310
|
+
case "d": return horizontal(H - T / 2);
|
|
24311
|
+
case "f": return vertical(T / 2, T / 2, mid);
|
|
24312
|
+
case "b": return vertical(W - T / 2, T / 2, mid);
|
|
24313
|
+
case "e": return vertical(T / 2, mid, H - T / 2);
|
|
24314
|
+
default: return vertical(W - T / 2, mid, H - T / 2);
|
|
24315
|
+
}
|
|
24316
|
+
}
|
|
24317
|
+
/** One seven-segment digit at x: every segment drawn, the lit ones in ink and the rest faint, as on a real display. */
|
|
24318
|
+
function SegmentDigit({ digit, x }) {
|
|
24319
|
+
const lit = DIGITS[digit] ?? "";
|
|
24320
|
+
return /* @__PURE__ */ jsx("g", {
|
|
24321
|
+
"data-digit": digit,
|
|
24322
|
+
transform: `translate(${x} 0)`,
|
|
24323
|
+
children: [..."abcdefg"].map((s) => /* @__PURE__ */ jsx("polygon", {
|
|
24324
|
+
points: segment(s),
|
|
24325
|
+
"data-lit": lit.includes(s) || void 0,
|
|
24326
|
+
className: lit.includes(s) ? "fill-foreground" : "fill-muted"
|
|
24327
|
+
}, s))
|
|
24328
|
+
});
|
|
24329
|
+
}
|
|
24330
|
+
const Colon = ({ x, h, r }) => /* @__PURE__ */ jsxs("g", {
|
|
24331
|
+
className: "fill-foreground",
|
|
24332
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
24333
|
+
cx: x,
|
|
24334
|
+
cy: h * .3,
|
|
24335
|
+
r
|
|
24336
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
24337
|
+
cx: x,
|
|
24338
|
+
cy: h * .7,
|
|
24339
|
+
r
|
|
24340
|
+
})]
|
|
24341
|
+
});
|
|
24342
|
+
/** The groups a clock writes, hours first: ["3", "45"] or ["15", "45", "09"]. */
|
|
24343
|
+
function groups(hours, minutes, hour12, seconds) {
|
|
24344
|
+
const h = shownHour(hours, hour12);
|
|
24345
|
+
const out = [hour12 ? String(h) : two(h), two((Math.floor(minutes) % 60 + 60) % 60)];
|
|
24346
|
+
if (seconds !== void 0) out.push(two((seconds % 60 + 60) % 60));
|
|
24347
|
+
return out;
|
|
24348
|
+
}
|
|
24349
|
+
/** A digital clock showing one time: seven segments, flip tiles or plain figures. */
|
|
24350
|
+
function DigitalClock({ hours, minutes, seconds, hour12 = true, period = false, label, face = "segments", className }) {
|
|
24351
|
+
const parts = groups(hours, minutes, hour12, seconds);
|
|
24352
|
+
const pm = (Math.floor(hours) % 24 + 24) % 24 >= 12 ? "pm" : "am";
|
|
24353
|
+
const showPeriod = hour12 && period;
|
|
24354
|
+
const name = label ?? digitalTime(hours, minutes, {
|
|
24355
|
+
hour12,
|
|
24356
|
+
period,
|
|
24357
|
+
seconds
|
|
24358
|
+
});
|
|
24359
|
+
let body;
|
|
24360
|
+
let width;
|
|
24361
|
+
let height;
|
|
24362
|
+
if (face === "segments") {
|
|
24363
|
+
const pad = 12;
|
|
24364
|
+
const step = 50;
|
|
24365
|
+
const colonW = 24;
|
|
24366
|
+
const items = [];
|
|
24367
|
+
let x = pad;
|
|
24368
|
+
parts.forEach((group, gi) => {
|
|
24369
|
+
if (gi > 0) {
|
|
24370
|
+
items.push(/* @__PURE__ */ jsx(Colon, {
|
|
24371
|
+
x: x + colonW / 2 - 5,
|
|
24372
|
+
h: H,
|
|
24373
|
+
r: 5
|
|
24374
|
+
}, `c${gi}`));
|
|
24375
|
+
x += colonW;
|
|
24376
|
+
}
|
|
24377
|
+
[...group.padStart(2, " ")].forEach((ch, ci) => {
|
|
24378
|
+
if (ch !== " ") items.push(/* @__PURE__ */ jsx(SegmentDigit, {
|
|
24379
|
+
digit: ch,
|
|
24380
|
+
x
|
|
24381
|
+
}, `${gi}-${ci}`));
|
|
24382
|
+
x += step;
|
|
24383
|
+
});
|
|
24384
|
+
});
|
|
24385
|
+
const periodW = showPeriod ? 44 : 0;
|
|
24386
|
+
if (showPeriod) items.push(/* @__PURE__ */ jsx("text", {
|
|
24387
|
+
x: x + 4,
|
|
24388
|
+
y: 18,
|
|
24389
|
+
fontSize: 18,
|
|
24390
|
+
className: "fill-foreground font-semibold uppercase",
|
|
24391
|
+
children: pm
|
|
24392
|
+
}, "p"));
|
|
24393
|
+
width = x + periodW + pad - 10;
|
|
24394
|
+
height = 96;
|
|
24395
|
+
body = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("rect", {
|
|
24396
|
+
x: 1,
|
|
24397
|
+
y: 1,
|
|
24398
|
+
width: width - 2,
|
|
24399
|
+
height: height - 2,
|
|
24400
|
+
rx: 12,
|
|
24401
|
+
strokeWidth: 2,
|
|
24402
|
+
className: "fill-card stroke-border"
|
|
24403
|
+
}), /* @__PURE__ */ jsx("g", {
|
|
24404
|
+
transform: `translate(0 ${pad}) skewX(-5)`,
|
|
24405
|
+
children: items
|
|
24406
|
+
})] });
|
|
24407
|
+
} else if (face === "flip") {
|
|
24408
|
+
const tileW = 100;
|
|
24409
|
+
const tileH = 104;
|
|
24410
|
+
width = parts.length * tileW + (parts.length - 1) * 10;
|
|
24411
|
+
height = tileH;
|
|
24412
|
+
body = parts.map((group, gi) => {
|
|
24413
|
+
const x = gi * 110;
|
|
24414
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
24415
|
+
"data-tile": group,
|
|
24416
|
+
children: [
|
|
24417
|
+
/* @__PURE__ */ jsx("rect", {
|
|
24418
|
+
x,
|
|
24419
|
+
y: 0,
|
|
24420
|
+
width: tileW,
|
|
24421
|
+
height: tileH,
|
|
24422
|
+
rx: 12,
|
|
24423
|
+
className: "fill-foreground"
|
|
24424
|
+
}),
|
|
24425
|
+
/* @__PURE__ */ jsx("text", {
|
|
24426
|
+
x: x + tileW / 2,
|
|
24427
|
+
y: 54,
|
|
24428
|
+
textAnchor: "middle",
|
|
24429
|
+
dominantBaseline: "central",
|
|
24430
|
+
fontSize: 70,
|
|
24431
|
+
className: "fill-background font-semibold tabular-nums",
|
|
24432
|
+
children: group
|
|
24433
|
+
}),
|
|
24434
|
+
/* @__PURE__ */ jsx("line", {
|
|
24435
|
+
x1: x,
|
|
24436
|
+
y1: tileH / 2,
|
|
24437
|
+
x2: x + tileW,
|
|
24438
|
+
y2: tileH / 2,
|
|
24439
|
+
strokeWidth: 3,
|
|
24440
|
+
className: "stroke-card"
|
|
24441
|
+
}),
|
|
24442
|
+
gi === 0 && showPeriod && /* @__PURE__ */ jsx("text", {
|
|
24443
|
+
x: x + 9,
|
|
24444
|
+
y: 94,
|
|
24445
|
+
fontSize: 13,
|
|
24446
|
+
className: "fill-background font-semibold uppercase",
|
|
24447
|
+
children: pm
|
|
24448
|
+
})
|
|
24449
|
+
]
|
|
24450
|
+
}, gi);
|
|
24451
|
+
});
|
|
24452
|
+
} else {
|
|
24453
|
+
const chars = parts.join(":");
|
|
24454
|
+
const items = [];
|
|
24455
|
+
let x = 0;
|
|
24456
|
+
for (const [i, ch] of [...chars].entries()) {
|
|
24457
|
+
const w = ch === ":" ? 20 : 40;
|
|
24458
|
+
items.push(/* @__PURE__ */ jsx("text", {
|
|
24459
|
+
x: x + w / 2,
|
|
24460
|
+
y: 44,
|
|
24461
|
+
textAnchor: "middle",
|
|
24462
|
+
dominantBaseline: "central",
|
|
24463
|
+
fontSize: 72,
|
|
24464
|
+
className: "fill-foreground font-semibold tabular-nums",
|
|
24465
|
+
children: ch
|
|
24466
|
+
}, i));
|
|
24467
|
+
x += w;
|
|
24468
|
+
}
|
|
24469
|
+
if (showPeriod) {
|
|
24470
|
+
items.push(/* @__PURE__ */ jsx("text", {
|
|
24471
|
+
x: x + 8,
|
|
24472
|
+
y: 68,
|
|
24473
|
+
fontSize: 26,
|
|
24474
|
+
className: "fill-muted-foreground font-semibold",
|
|
24475
|
+
children: pm
|
|
24476
|
+
}, "p"));
|
|
24477
|
+
x += 48;
|
|
24478
|
+
}
|
|
24479
|
+
width = x;
|
|
24480
|
+
height = 88;
|
|
24481
|
+
body = items;
|
|
24482
|
+
}
|
|
24483
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
24484
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
24485
|
+
role: "img",
|
|
24486
|
+
"aria-label": name,
|
|
24487
|
+
"data-face": face,
|
|
24488
|
+
className: cn("block w-56", className),
|
|
24489
|
+
children: body
|
|
24490
|
+
});
|
|
24491
|
+
}
|
|
24492
|
+
|
|
24493
|
+
// src/components/fraction-shape.tsx
|
|
24494
|
+
/** Every outline, in the order a gallery shows them. */
|
|
24495
|
+
const FRACTION_OUTLINES = [
|
|
24496
|
+
"circle",
|
|
24497
|
+
"square",
|
|
24498
|
+
"rectangle",
|
|
24499
|
+
"triangle"
|
|
24500
|
+
];
|
|
24501
|
+
const R = 92;
|
|
24502
|
+
const C = 100;
|
|
24503
|
+
const RECT = {
|
|
24504
|
+
x: 6,
|
|
24505
|
+
y: 35,
|
|
24506
|
+
w: 188,
|
|
24507
|
+
h: 130
|
|
24508
|
+
};
|
|
24509
|
+
const SQUARE = {
|
|
24510
|
+
x: 8,
|
|
24511
|
+
y: 8,
|
|
24512
|
+
w: 184,
|
|
24513
|
+
h: 184
|
|
24514
|
+
};
|
|
24515
|
+
const TRIANGLE = [
|
|
24516
|
+
[100, 10],
|
|
24517
|
+
[192, 182],
|
|
24518
|
+
[8, 182]
|
|
24519
|
+
];
|
|
24520
|
+
const poly = (points) => `M${points.map(([x, y]) => `${round(x)} ${round(y)}`).join(" L")} Z`;
|
|
24521
|
+
const round = (n) => Math.round(n * 100) / 100;
|
|
24522
|
+
const mid = (a, b) => [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
|
|
24523
|
+
const lerp = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
|
24524
|
+
/** Cut points from 0 to 1: equal, or (unequal) each part one size bigger than the one before. */
|
|
24525
|
+
function stops(parts, unequal) {
|
|
24526
|
+
const sizes = Array.from({ length: parts }, (_, i) => unequal ? i + 1 : 1);
|
|
24527
|
+
const total = sizes.reduce((a, b) => a + b, 0);
|
|
24528
|
+
const out = [0];
|
|
24529
|
+
for (const s of sizes) out.push(out[out.length - 1] + s / total);
|
|
24530
|
+
out[out.length - 1] = 1;
|
|
24531
|
+
return out;
|
|
24532
|
+
}
|
|
24533
|
+
function slices(parts, unequal) {
|
|
24534
|
+
if (parts === 1) return [`M8 ${C} A${R} ${R} 0 1 1 192 ${C} A${R} ${R} 0 1 1 8 ${C} Z`];
|
|
24535
|
+
const at = (t) => [C + R * Math.sin(t * 2 * Math.PI), C - R * Math.cos(t * 2 * Math.PI)];
|
|
24536
|
+
const s = stops(parts, unequal);
|
|
24537
|
+
return s.slice(1).map((end, i) => {
|
|
24538
|
+
const [x0, y0] = at(s[i]);
|
|
24539
|
+
const [x1, y1] = at(end);
|
|
24540
|
+
const large = end - s[i] > .5 ? 1 : 0;
|
|
24541
|
+
return `M${C} ${C} L${round(x0)} ${round(y0)} A${R} ${R} 0 ${large} 1 ${round(x1)} ${round(y1)} Z`;
|
|
24542
|
+
});
|
|
24543
|
+
}
|
|
24544
|
+
function boxParts(box, parts, cut) {
|
|
24545
|
+
const { x, y, w, h } = box;
|
|
24546
|
+
const corners = [
|
|
24547
|
+
[x, y],
|
|
24548
|
+
[x + w, y],
|
|
24549
|
+
[x + w, y + h],
|
|
24550
|
+
[x, y + h]
|
|
24551
|
+
];
|
|
24552
|
+
if (cut === "diagonal" && (parts === 2 || parts === 4)) {
|
|
24553
|
+
if (parts === 2) return [poly([
|
|
24554
|
+
corners[0],
|
|
24555
|
+
corners[1],
|
|
24556
|
+
corners[2]
|
|
24557
|
+
]), poly([
|
|
24558
|
+
corners[0],
|
|
24559
|
+
corners[2],
|
|
24560
|
+
corners[3]
|
|
24561
|
+
])];
|
|
24562
|
+
const centre = [x + w / 2, y + h / 2];
|
|
24563
|
+
return corners.map((p, i) => poly([
|
|
24564
|
+
p,
|
|
24565
|
+
corners[(i + 1) % 4],
|
|
24566
|
+
centre
|
|
24567
|
+
]));
|
|
24568
|
+
}
|
|
24569
|
+
if (cut === "grid" && parts === 4) {
|
|
24570
|
+
const cx = x + w / 2;
|
|
24571
|
+
const cy = y + h / 2;
|
|
24572
|
+
return [
|
|
24573
|
+
poly([
|
|
24574
|
+
[x, y],
|
|
24575
|
+
[cx, y],
|
|
24576
|
+
[cx, cy],
|
|
24577
|
+
[x, cy]
|
|
24578
|
+
]),
|
|
24579
|
+
poly([
|
|
24580
|
+
[cx, y],
|
|
24581
|
+
[x + w, y],
|
|
24582
|
+
[x + w, cy],
|
|
24583
|
+
[cx, cy]
|
|
24584
|
+
]),
|
|
24585
|
+
poly([
|
|
24586
|
+
[cx, cy],
|
|
24587
|
+
[x + w, cy],
|
|
24588
|
+
[x + w, y + h],
|
|
24589
|
+
[cx, y + h]
|
|
24590
|
+
]),
|
|
24591
|
+
poly([
|
|
24592
|
+
[x, cy],
|
|
24593
|
+
[cx, cy],
|
|
24594
|
+
[cx, y + h],
|
|
24595
|
+
[x, y + h]
|
|
24596
|
+
])
|
|
24597
|
+
];
|
|
24598
|
+
}
|
|
24599
|
+
const s = stops(parts, cut === "unequal");
|
|
24600
|
+
return s.slice(1).map((end, i) => cut === "rows" ? poly([
|
|
24601
|
+
[x, y + h * s[i]],
|
|
24602
|
+
[x + w, y + h * s[i]],
|
|
24603
|
+
[x + w, y + h * end],
|
|
24604
|
+
[x, y + h * end]
|
|
24605
|
+
]) : poly([
|
|
24606
|
+
[x + w * s[i], y],
|
|
24607
|
+
[x + w * end, y],
|
|
24608
|
+
[x + w * end, y + h],
|
|
24609
|
+
[x + w * s[i], y + h]
|
|
24610
|
+
]));
|
|
24611
|
+
}
|
|
24612
|
+
function triangleParts(parts, cut) {
|
|
24613
|
+
const [top, right, left] = TRIANGLE;
|
|
24614
|
+
if (parts === 4 && cut !== "unequal" && cut !== "strips") {
|
|
24615
|
+
const a = mid(top, right);
|
|
24616
|
+
const b = mid(right, left);
|
|
24617
|
+
const c = mid(left, top);
|
|
24618
|
+
return [
|
|
24619
|
+
poly([
|
|
24620
|
+
top,
|
|
24621
|
+
a,
|
|
24622
|
+
c
|
|
24623
|
+
]),
|
|
24624
|
+
poly([
|
|
24625
|
+
a,
|
|
24626
|
+
right,
|
|
24627
|
+
b
|
|
24628
|
+
]),
|
|
24629
|
+
poly([
|
|
24630
|
+
c,
|
|
24631
|
+
b,
|
|
24632
|
+
left
|
|
24633
|
+
]),
|
|
24634
|
+
poly([
|
|
24635
|
+
a,
|
|
24636
|
+
b,
|
|
24637
|
+
c
|
|
24638
|
+
])
|
|
24639
|
+
];
|
|
24640
|
+
}
|
|
24641
|
+
const s = stops(parts, cut === "unequal");
|
|
24642
|
+
return s.slice(1).map((end, i) => poly([
|
|
24643
|
+
top,
|
|
24644
|
+
lerp(left, right, s[i]),
|
|
24645
|
+
lerp(left, right, end)
|
|
24646
|
+
]));
|
|
24647
|
+
}
|
|
24648
|
+
/** The parts of a shape as SVG paths in a 200 by 200 view, in the order `shaded` counts them. */
|
|
24649
|
+
function fractionParts(shape, parts, cut = "strips") {
|
|
24650
|
+
if (!Number.isInteger(parts) || parts < 1 || parts > 8) throw new RangeError(`parts must be 1 to 8, not ${parts}`);
|
|
24651
|
+
if (shape === "circle") return slices(parts, cut === "unequal");
|
|
24652
|
+
if (shape === "triangle") return triangleParts(parts, cut);
|
|
24653
|
+
return boxParts(shape === "square" ? SQUARE : RECT, parts, cut);
|
|
24654
|
+
}
|
|
24655
|
+
const NUMBER_WORDS = [
|
|
24656
|
+
"zero",
|
|
24657
|
+
"one",
|
|
24658
|
+
"two",
|
|
24659
|
+
"three",
|
|
24660
|
+
"four",
|
|
24661
|
+
"five",
|
|
24662
|
+
"six",
|
|
24663
|
+
"seven",
|
|
24664
|
+
"eight"
|
|
24665
|
+
];
|
|
24666
|
+
const PART_NAMES = {
|
|
24667
|
+
2: ["half", "halves"],
|
|
24668
|
+
3: ["third", "thirds"],
|
|
24669
|
+
4: ["quarter", "quarters"],
|
|
24670
|
+
5: ["fifth", "fifths"],
|
|
24671
|
+
6: ["sixth", "sixths"],
|
|
24672
|
+
7: ["seventh", "sevenths"],
|
|
24673
|
+
8: ["eighth", "eighths"]
|
|
24674
|
+
};
|
|
24675
|
+
/**
|
|
24676
|
+
* A fraction as it is said: "one half", "three quarters", "two thirds". A whole is "one whole" ("two halves" is still
|
|
24677
|
+
* a whole, so `fractionWords(2, 2)` is "two halves"); 0 is "none".
|
|
24678
|
+
*/
|
|
24679
|
+
function fractionWords(shaded, parts) {
|
|
24680
|
+
if (shaded === 0) return "none";
|
|
24681
|
+
if (parts === 1) return "one whole";
|
|
24682
|
+
const [one, many] = PART_NAMES[parts] ?? [`part of ${parts}`, `parts of ${parts}`];
|
|
24683
|
+
return `${NUMBER_WORDS[shaded] ?? String(shaded)} ${shaded === 1 ? one : many}`;
|
|
24684
|
+
}
|
|
24685
|
+
const OUTLINE_WORDS = {
|
|
24686
|
+
circle: "A circle",
|
|
24687
|
+
square: "A square",
|
|
24688
|
+
rectangle: "A rectangle",
|
|
24689
|
+
triangle: "A triangle"
|
|
24690
|
+
};
|
|
24691
|
+
/** A shape cut into parts, some of them shaded: the picture of a fraction (a half, a quarter, and not a half). */
|
|
24692
|
+
function FractionShape({ shape, parts, shaded, cut = "strips", label, className }) {
|
|
24693
|
+
const paths = fractionParts(shape, parts, cut);
|
|
24694
|
+
const lit = new Set(typeof shaded === "number" ? paths.map((_, i) => i).slice(0, shaded) : shaded);
|
|
24695
|
+
const equal = cut === "unequal" && parts > 1 ? "unequal" : "equal";
|
|
24696
|
+
const said = label ?? `${OUTLINE_WORDS[shape]} cut into ${parts} ${equal} part${parts === 1 ? "" : "s"}, ${lit.size} shaded`;
|
|
24697
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
24698
|
+
viewBox: "0 0 200 200",
|
|
24699
|
+
role: "img",
|
|
24700
|
+
"aria-label": said,
|
|
24701
|
+
className: cn("block aspect-square w-full", className),
|
|
24702
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
24703
|
+
strokeWidth: 3,
|
|
24704
|
+
strokeLinejoin: "round",
|
|
24705
|
+
className: "stroke-foreground",
|
|
24706
|
+
children: paths.map((d, i) => /* @__PURE__ */ jsx("path", {
|
|
24707
|
+
d,
|
|
24708
|
+
"data-shaded": lit.has(i) || void 0,
|
|
24709
|
+
className: lit.has(i) ? "fill-primary" : "fill-card"
|
|
24710
|
+
}, i))
|
|
24711
|
+
})
|
|
24712
|
+
});
|
|
24713
|
+
}
|
|
24714
|
+
|
|
24715
|
+
// src/components/clock.tsx
|
|
24716
|
+
/** Every face `Clock` draws: the analogue faces, then the digital ones. */
|
|
24717
|
+
const CLOCK_STYLES = [...CLOCK_FACE_STYLES, ...DIGITAL_CLOCK_STYLES];
|
|
24718
|
+
/** Whether a face is digital. */
|
|
24719
|
+
const isDigitalStyle = (face) => DIGITAL_CLOCK_STYLES.includes(face);
|
|
24720
|
+
/** One time on a clock, analogue or digital, in a face people know: `face` picks which. */
|
|
24721
|
+
function Clock({ face = "teaching", hour12, period, ...props }) {
|
|
24722
|
+
if (isDigitalStyle(face)) return /* @__PURE__ */ jsx(DigitalClock, {
|
|
24723
|
+
hours: props.hours,
|
|
24724
|
+
minutes: props.minutes,
|
|
24725
|
+
seconds: props.seconds,
|
|
24726
|
+
label: props.label,
|
|
24727
|
+
className: props.className,
|
|
24728
|
+
face,
|
|
24729
|
+
hour12,
|
|
24730
|
+
period
|
|
24731
|
+
});
|
|
24732
|
+
return /* @__PURE__ */ jsx(ClockFace, {
|
|
24733
|
+
...props,
|
|
24734
|
+
face
|
|
24735
|
+
});
|
|
24736
|
+
}
|
|
24737
|
+
|
|
24738
|
+
// src/components/set-clock.tsx
|
|
24739
|
+
const wrap12 = (h) => ((Math.round(h) - 1) % 12 + 12) % 12 + 1;
|
|
24740
|
+
const wrap60 = (m) => (Math.round(m) % 60 + 60) % 60;
|
|
24741
|
+
/** How far apart two angles are, the short way round. */
|
|
24742
|
+
const apart = (a, b) => {
|
|
24743
|
+
const d = Math.abs(((a - b) % 360 + 360) % 360);
|
|
24744
|
+
return Math.min(d, 360 - d);
|
|
24745
|
+
};
|
|
24746
|
+
/** The time with the minute hand moved to `minutes`, the hour carried when the hand passes 12 and `geared`. */
|
|
24747
|
+
function moveMinuteHand(time, minutes, geared = true) {
|
|
24748
|
+
const m = wrap60(minutes);
|
|
24749
|
+
let h = time.hours;
|
|
24750
|
+
if (geared && time.minutes >= 45 && m < 15) h += 1;
|
|
24751
|
+
if (geared && time.minutes < 15 && m >= 45) h -= 1;
|
|
24752
|
+
return {
|
|
24753
|
+
hours: wrap12(h),
|
|
24754
|
+
minutes: m
|
|
24755
|
+
};
|
|
24756
|
+
}
|
|
24757
|
+
/** The time with the minute hand stepped `by` minutes (a key press): through 12 into the next hour when `geared`. */
|
|
24758
|
+
function stepMinuteHand(time, by, geared = true) {
|
|
24759
|
+
if (!geared) return {
|
|
24760
|
+
hours: wrap12(time.hours),
|
|
24761
|
+
minutes: wrap60(time.minutes + by)
|
|
24762
|
+
};
|
|
24763
|
+
const total = time.hours * 60 + time.minutes + by;
|
|
24764
|
+
return {
|
|
24765
|
+
hours: wrap12(Math.floor(total / 60)),
|
|
24766
|
+
minutes: wrap60(total)
|
|
24767
|
+
};
|
|
24768
|
+
}
|
|
24769
|
+
/** The hour whose hand, at these minutes, points nearest `angle` (degrees clockwise from 12). */
|
|
24770
|
+
function hourAt(angle, minutes) {
|
|
24771
|
+
return wrap12(Math.round((angle - minutes / 2) / 30));
|
|
24772
|
+
}
|
|
24773
|
+
/** The minutes the minute hand shows at `angle`, snapped to `step`. */
|
|
24774
|
+
function minutesAt(angle, step = 5) {
|
|
24775
|
+
return wrap60(Math.round(angle / 6 / step) * step);
|
|
24776
|
+
}
|
|
24777
|
+
/** One hand as a slider: focus, keys and the ring that shows keyboard focus at its tip. */
|
|
24778
|
+
function HandSlider({ which, label, time, tip, isDisabled, onStep, onPage, handRef, children }) {
|
|
24779
|
+
const { focusProps, isFocusVisible } = useFocusRing();
|
|
24780
|
+
const { moveProps } = useMove({ onMove: (e) => {
|
|
24781
|
+
if (isDisabled || e.pointerType !== "keyboard") return;
|
|
24782
|
+
onStep(e.deltaX > 0 || e.deltaY < 0 ? 1 : -1);
|
|
24783
|
+
} });
|
|
24784
|
+
const onKeyDown = (e) => {
|
|
24785
|
+
if (isDisabled) return;
|
|
24786
|
+
if (e.key === "PageUp" || e.key === "PageDown") {
|
|
24787
|
+
e.preventDefault();
|
|
24788
|
+
onPage(e.key === "PageUp" ? 1 : -1);
|
|
24789
|
+
}
|
|
24790
|
+
};
|
|
24791
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
24792
|
+
ref: handRef,
|
|
24793
|
+
role: "slider",
|
|
24794
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
24795
|
+
"aria-label": label,
|
|
24796
|
+
"aria-disabled": isDisabled || void 0,
|
|
24797
|
+
"aria-orientation": "horizontal",
|
|
24798
|
+
"aria-valuemin": which === "hour" ? 1 : 0,
|
|
24799
|
+
"aria-valuemax": which === "hour" ? 12 : 59,
|
|
24800
|
+
"aria-valuenow": which === "hour" ? time.hours : time.minutes,
|
|
24801
|
+
"aria-valuetext": clockWords(time.hours, time.minutes),
|
|
24802
|
+
className: "outline-none",
|
|
24803
|
+
...mergeProps(focusProps, isDisabled ? {} : moveProps, { onKeyDown }),
|
|
24804
|
+
children: [children, isFocusVisible && /* @__PURE__ */ jsx("circle", {
|
|
24805
|
+
cx: tip.x,
|
|
24806
|
+
cy: tip.y,
|
|
24807
|
+
r: 11,
|
|
24808
|
+
strokeWidth: 3,
|
|
24809
|
+
fill: "none",
|
|
24810
|
+
className: "stroke-ring"
|
|
24811
|
+
})]
|
|
24812
|
+
});
|
|
24813
|
+
}
|
|
24814
|
+
/** A clock whose hands are dragged, pressed or keyed to a time, geared as a real clock's are. */
|
|
24815
|
+
function SetClock({ value, onChange, step = 5, geared = true, face = "teaching", label = "Set the clock", handLabels = {
|
|
24816
|
+
hour: "Hour hand",
|
|
24817
|
+
minute: "Minute hand"
|
|
24818
|
+
}, isDisabled = false, className, ...over }) {
|
|
24819
|
+
const parts = clockParts(face, over);
|
|
24820
|
+
const time = {
|
|
24821
|
+
hours: wrap12(value.hours),
|
|
24822
|
+
minutes: wrap60(value.minutes)
|
|
24823
|
+
};
|
|
24824
|
+
const angle = handAngles(time.hours, time.minutes);
|
|
24825
|
+
const svgRef = useRef(null);
|
|
24826
|
+
const hourRef = useRef(null);
|
|
24827
|
+
const minuteRef = useRef(null);
|
|
24828
|
+
const [held, setHeld] = useState(null);
|
|
24829
|
+
const live = useRef(time);
|
|
24830
|
+
live.current = time;
|
|
24831
|
+
const point = (e) => {
|
|
24832
|
+
const svg = svgRef.current;
|
|
24833
|
+
if (!svg) return null;
|
|
24834
|
+
const box = svg.getBoundingClientRect();
|
|
24835
|
+
const [x0, , size] = clockViewBox(parts.minuteNumbers).split(" ").map(Number);
|
|
24836
|
+
const scale = size / (box.width || 1);
|
|
24837
|
+
const x = x0 + (e.clientX - box.left) * scale - 100;
|
|
24838
|
+
const y = x0 + (e.clientY - box.top) * scale - 100;
|
|
24839
|
+
return {
|
|
24840
|
+
angle: (Math.atan2(x, -y) * 180 / Math.PI + 360) % 360,
|
|
24841
|
+
radius: Math.hypot(x, y)
|
|
24842
|
+
};
|
|
24843
|
+
};
|
|
24844
|
+
const set = (next) => {
|
|
24845
|
+
if (next.hours !== live.current.hours || next.minutes !== live.current.minutes) {
|
|
24846
|
+
live.current = next;
|
|
24847
|
+
onChange(next);
|
|
24848
|
+
}
|
|
24849
|
+
};
|
|
24850
|
+
const drag = useRef(null);
|
|
24851
|
+
const moveHand = (which, to) => {
|
|
24852
|
+
const now = live.current;
|
|
24853
|
+
if (which === "hour") {
|
|
24854
|
+
set({
|
|
24855
|
+
hours: hourAt(to, now.minutes),
|
|
24856
|
+
minutes: now.minutes
|
|
24857
|
+
});
|
|
24858
|
+
return;
|
|
24859
|
+
}
|
|
24860
|
+
const was = drag.current;
|
|
24861
|
+
if (!was) {
|
|
24862
|
+
const next = moveMinuteHand(now, minutesAt(to, step), geared);
|
|
24863
|
+
const off = ((to / 6 - next.minutes) % 60 + 90) % 60 - 30;
|
|
24864
|
+
drag.current = {
|
|
24865
|
+
angle: to,
|
|
24866
|
+
total: next.hours * 60 + next.minutes + off
|
|
24867
|
+
};
|
|
24868
|
+
set(next);
|
|
24869
|
+
return;
|
|
24870
|
+
}
|
|
24871
|
+
const turned = ((to - was.angle) % 360 + 540) % 360 - 180;
|
|
24872
|
+
const total = was.total + turned / 6;
|
|
24873
|
+
drag.current = {
|
|
24874
|
+
angle: to,
|
|
24875
|
+
total
|
|
24876
|
+
};
|
|
24877
|
+
const snapped = Math.round(total / step) * step;
|
|
24878
|
+
set({
|
|
24879
|
+
hours: geared ? wrap12(Math.floor(snapped / 60)) : now.hours,
|
|
24880
|
+
minutes: wrap60(snapped)
|
|
24881
|
+
});
|
|
24882
|
+
};
|
|
24883
|
+
const onPointerDown = (e) => {
|
|
24884
|
+
if (isDisabled || e.pointerType === "mouse" && e.button !== 0) return;
|
|
24885
|
+
const p = point(e);
|
|
24886
|
+
if (!p) return;
|
|
24887
|
+
const which = apart(p.angle, angle.hour) - (p.radius < 50 ? 25 : 0) < apart(p.angle, angle.minute) ? "hour" : "minute";
|
|
24888
|
+
e.preventDefault();
|
|
24889
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
24890
|
+
drag.current = null;
|
|
24891
|
+
setHeld(which);
|
|
24892
|
+
(which === "hour" ? hourRef : minuteRef).current?.focus({ preventScroll: true });
|
|
24893
|
+
moveHand(which, p.angle);
|
|
24894
|
+
};
|
|
24895
|
+
const onPointerMove = (e) => {
|
|
24896
|
+
if (!held) return;
|
|
24897
|
+
const p = point(e);
|
|
24898
|
+
if (p) moveHand(held, p.angle);
|
|
24899
|
+
};
|
|
24900
|
+
const release = () => {
|
|
24901
|
+
drag.current = null;
|
|
24902
|
+
setHeld(null);
|
|
24903
|
+
};
|
|
24904
|
+
const tip = (which) => at(which === "hour" ? angle.hour : angle.minute, which === "hour" ? 40 : 64);
|
|
24905
|
+
return /* @__PURE__ */ jsx("div", {
|
|
24906
|
+
role: "group",
|
|
24907
|
+
"aria-label": label,
|
|
24908
|
+
"aria-disabled": isDisabled || void 0,
|
|
24909
|
+
className: cn("w-48", className),
|
|
24910
|
+
children: /* @__PURE__ */ jsxs("svg", {
|
|
24911
|
+
ref: svgRef,
|
|
24912
|
+
viewBox: clockViewBox(parts.minuteNumbers),
|
|
24913
|
+
"data-face": face,
|
|
24914
|
+
"data-held": held ?? void 0,
|
|
24915
|
+
className: cn("block aspect-square w-full touch-none select-none", isDisabled ? "" : "cursor-pointer"),
|
|
24916
|
+
onPointerDown,
|
|
24917
|
+
onPointerMove,
|
|
24918
|
+
onPointerUp: release,
|
|
24919
|
+
onPointerCancel: release,
|
|
24920
|
+
children: [
|
|
24921
|
+
/* @__PURE__ */ jsx(ClockDial, {
|
|
24922
|
+
face,
|
|
24923
|
+
parts
|
|
24924
|
+
}),
|
|
24925
|
+
/* @__PURE__ */ jsx(HandSlider, {
|
|
24926
|
+
which: "hour",
|
|
24927
|
+
label: handLabels.hour,
|
|
24928
|
+
time,
|
|
24929
|
+
tip: tip("hour"),
|
|
24930
|
+
isDisabled,
|
|
24931
|
+
handRef: hourRef,
|
|
24932
|
+
onStep: (d) => set({
|
|
24933
|
+
hours: wrap12(time.hours + d),
|
|
24934
|
+
minutes: time.minutes
|
|
24935
|
+
}),
|
|
24936
|
+
onPage: (d) => set({
|
|
24937
|
+
hours: wrap12(time.hours + 3 * d),
|
|
24938
|
+
minutes: time.minutes
|
|
24939
|
+
}),
|
|
24940
|
+
children: /* @__PURE__ */ jsx(ClockHand, {
|
|
24941
|
+
which: "hour",
|
|
24942
|
+
style: parts.hands,
|
|
24943
|
+
angle: angle.hour
|
|
24944
|
+
})
|
|
24945
|
+
}),
|
|
24946
|
+
/* @__PURE__ */ jsx(HandSlider, {
|
|
24947
|
+
which: "minute",
|
|
24948
|
+
label: handLabels.minute,
|
|
24949
|
+
time,
|
|
24950
|
+
tip: tip("minute"),
|
|
24951
|
+
isDisabled,
|
|
24952
|
+
handRef: minuteRef,
|
|
24953
|
+
onStep: (d) => set(stepMinuteHand(time, d * step, geared)),
|
|
24954
|
+
onPage: (d) => set(stepMinuteHand(time, d * 15, geared)),
|
|
24955
|
+
children: /* @__PURE__ */ jsx(ClockHand, {
|
|
24956
|
+
which: "minute",
|
|
24957
|
+
style: parts.hands,
|
|
24958
|
+
angle: angle.minute
|
|
24959
|
+
})
|
|
24960
|
+
}),
|
|
24961
|
+
/* @__PURE__ */ jsx(ClockHub, { hands: parts.hands })
|
|
24962
|
+
]
|
|
24963
|
+
})
|
|
24964
|
+
});
|
|
24965
|
+
}
|
|
24966
|
+
|
|
24967
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BRUSHES, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, CLOCK_FACE_STYLES, CLOCK_STYLES, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, Clock, ClockFace, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Concealed, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DIGITAL_CLOCK_STYLES, DataTable, DataView$1 as DataView, Density, Dialog, DigitalClock, Disclosure, Done, DragSource, DrawingLayer, DrawingToolbar, EditListPlayer, EmptyState, EventLog, FIT, FRACTION_OUTLINES, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, FractionShape, FullscreenFrame, Glimpse, HttpError, INK_COLOURS, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PauseButton, PixelImage, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RangeSlider, RateChoice, ReadAlong, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, SayPicture, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, SetClock, ShortcutEditor, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelinePlayer, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, WorkspaceBar, actualPixelsScale, ancestorsOf, apiPage, appBase, applyOp, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, clockParts, clockWords, cn, colorSchemeScript, commandShortcut, continues, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, currentOf, curvePoints, dayPart, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, digitalTime, diskThresholds, drawRect, drawingToSvg, ease, editTimeOf, editTimes, emptyDrawing, encodeWav, errorPayload, explainMicrophoneError, feedbackMarker, fetchJson, fieldErrorsOf, filterMarkup, findPage, fitPoints, fitRect, followAim, format, formatChord, fractionParts, fractionWords, frameAt, gainToVolume, geo, gridPoints, gutterOf, hitsStroke, hourAt, inkMatch, inputLevelThresholds, invertOp, isDigitalStyle, isDoubtful, isRefusal, isReservedChord, isSpeaking, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, locateInEdit, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, mediaStatRows, minutesAt, moveGutter, moveMinuteHand, movePoints, moveRect, newStrokeId, nextBreak, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, pointsBox, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, replay, resample, resamplePeaks, rescaleDrawing, resizeRect, rgbaToBlob, rmsDb, romanHour, safeHref, sayPosition, serialiseSort, settleCut, simplifyPoints, skipAction, smoothPath, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepMinuteHand, stepOnGrid, stopSpeaking, strokeAt, strokeBox, strokeShape, summariseWorkflow, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useCountdown, useDifference, useDrawing, useEditList, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useInkMatch, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMediaStats, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useReadAloud, useRebindableShortcuts, useRecorder, useReserve, useRevealed, useSayOnShow, useSearchParam, useSelection, useSettledStatus, useSharedCursor, useSpeaking, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, widthsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
|
|
23795
24968
|
//# sourceMappingURL=index.js.map
|