strata-react 2.1.1 → 2.1.3

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/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { i as typeSteps, n as KeyText, r as cn, t as Tooltip } from "./tooltip-BosfsWYh.js";
2
2
  import { a as Textarea, c as useSearchParam, d as createFormat, f as format, i as NativeSelect, l as MISSING, n as Field, o as useFieldControl, p as toDate, r as Input, s as controlHeight, t as ChoiceGroup, u as NBSP } from "./field-DBCsFIng.js";
3
- import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as RowAction, t as Button } from "./button-CYXjU-fs.js";
3
+ import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as RowAction, t as Button } from "./button-CjnotDTb.js";
4
4
  import { t as followAim } from "./follow-CXQsL86O.js";
5
5
  import { n as useViewPointers, r as useWheelZoom, t as useSettledStatus } from "./viewer-input-3Qa-o35k.js";
6
- import { A as StrataQueryProvider, C as toast, D as LoadError, E as EmptyState, F as useLoad, I as usePoll, L as overlaySurface, M as fetchJson, N as staleOf, O as Skeleton, P as toLoad, S as StrataToastRegion, T as DataView$1, _ as clampViewport, a as useMicrophone, b as viewportTransform, d as zoomToBox, f as FIT, g as boxViewport, h as actualPixelsScale, i as explainMicrophoneError, j as createQueryClient, k as StaleNotice, l as readingOrder, m as MIN_SCALE, n as MicrophoneError, o as Thumbnail, p as MAX_SCALE, r as browserMicrophone, s as ThumbnailSkeleton, t as MicrophoneContext, u as regionStyle, v as frameBoxToShares, w as toastTimeout, x as zoomAt, y as regionShares } from "./microphone-76skMt6i.js";
7
- import { a as useAsyncAction, c as KeysLegend, d as useHotkeys, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as keyName } from "./value-controls-5u7sD_wG.js";
6
+ import { A as StrataQueryProvider, C as toast, D as LoadError, E as EmptyState, F as useLoad, I as usePoll, L as overlaySurface, M as fetchJson, N as staleOf, O as Skeleton, P as toLoad, S as StrataToastRegion, T as DataView$1, _ as clampViewport, a as useMicrophone, b as viewportTransform, d as zoomToBox, f as FIT, g as boxViewport, h as actualPixelsScale, i as explainMicrophoneError, j as createQueryClient, k as StaleNotice, l as readingOrder, m as MIN_SCALE, n as MicrophoneError, o as Thumbnail, p as MAX_SCALE, r as browserMicrophone, s as ThumbnailSkeleton, t as MicrophoneContext, u as regionStyle, v as frameBoxToShares, w as toastTimeout, x as zoomAt, y as regionShares } from "./microphone-D3sbBVka.js";
7
+ import { a as useAsyncAction, c as KeysLegend, d as useHotkeys, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as keyName } from "./value-controls-ColD28Pp.js";
8
8
  import { n as useSharedCursor, r as geo, t as CursorScope } from "./cursor-Cwyvgwsw.js";
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-1oOSMj_D.js";
@@ -17,8 +17,53 @@ import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/r
17
17
  import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
18
18
  import { UNSAFE_PortalProvider, VisuallyHidden, mergeProps, useDrag, useDrop, useFocusRing, useMove, useSlider, useSliderThumb, useUNSAFE_PortalContext } from "react-aria";
19
19
  import { LayoutInfo, Rect, Size, useSliderState } from "react-stately";
20
+ import { createPortal } from "react-dom";
20
21
  import pixelmatch from "pixelmatch";
21
22
 
23
+ // src/lib/countdown.ts
24
+ /**
25
+ * Counts down `seconds` whole seconds while `running`, then calls `onDone` once: the seconds left (never below 1), or
26
+ * null when not counting (not running, or 0 seconds: the caller waits for a tap instead). Running false and true again
27
+ * starts again from `seconds`, and so does a new `run` while it counts (a new look begun before the last one showed).
28
+ */
29
+ function useCountdown(running, seconds, onDone, run) {
30
+ const counting = running && seconds > 0;
31
+ const [left, setLeft] = React.useState(seconds);
32
+ const [was, setWas] = React.useState({
33
+ counting: false,
34
+ run
35
+ });
36
+ if (counting !== was.counting || counting && run !== was.run) {
37
+ setWas({
38
+ counting,
39
+ run
40
+ });
41
+ if (counting) setLeft(seconds);
42
+ }
43
+ const latest = React.useRef(onDone);
44
+ React.useEffect(() => {
45
+ latest.current = onDone;
46
+ });
47
+ React.useEffect(() => {
48
+ if (!counting) return;
49
+ let n = seconds;
50
+ const t = setInterval(() => {
51
+ n -= 1;
52
+ setLeft(n);
53
+ if (n <= 0) {
54
+ clearInterval(t);
55
+ latest.current();
56
+ }
57
+ }, 1e3);
58
+ return () => clearInterval(t);
59
+ }, [
60
+ counting,
61
+ seconds,
62
+ run
63
+ ]);
64
+ return counting ? Math.max(left, 1) : null;
65
+ }
66
+
22
67
  // src/lib/chords.ts
23
68
  /** The platform this page runs on, read from the browser (`mac` for macOS and iOS). Server and test default: `other`. */
24
69
  function detectPlatform() {
@@ -12698,17 +12743,22 @@ const pieceSide = 96;
12698
12743
  const placedSide = 72;
12699
12744
  const placedPicture = { "--type-picture-size": "2.5rem" };
12700
12745
  const placeSide = 160;
12701
- /** Pictures put into places with two taps (pick up, put down) for an answer that is an arrangement: give a number, order, match, sort. The app owns where each piece is and checks it; the board only moves what the learner asks. */
12702
- function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState = () => "open", marks, locked = false, stretch = false, beckon = false, beckonMs = 1600, className }) {
12746
+ /** Pictures put into places for an answer that is an arrangement (give a number, order, match, sort): two taps (pick up, put down), one tap when there is one place, or a drag. The app owns where each piece is and checks it; the board only moves what the learner asks, and keeps every piece's slot so nothing shifts. */
12747
+ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState = () => "open", marks, locked = false, stretch = false, beckon = false, beckonMs = 1600, check, limit, className }) {
12703
12748
  const fill = stretch ? "auto-fit" : "auto-fill";
12704
12749
  const [heldKey, setHeld] = React.useState(null);
12705
12750
  const [follow, setFollow] = React.useState(null);
12751
+ const [drag, setDrag] = React.useState(null);
12706
12752
  const buttons = React.useRef(/* @__PURE__ */ new Map());
12753
+ const zones = React.useRef(/* @__PURE__ */ new Map());
12754
+ const dragged = React.useRef(false);
12755
+ const stopDrag = React.useRef(null);
12707
12756
  const placeKeys = new Set(places.map(placeKey));
12708
12757
  const where = (p) => {
12709
12758
  const at = placement[pieceKey(p)];
12710
12759
  return at !== void 0 && placeKeys.has(at) ? at : null;
12711
12760
  };
12761
+ const only = places.length === 1 ? places[0] : void 0;
12712
12762
  const held = locked ? void 0 : pieces.find((p) => pieceKey(p) === heldKey);
12713
12763
  const heldAt = held === void 0 ? null : where(held);
12714
12764
  const lit = useBeckon(beckon && !locked && held === void 0, pieces.filter((p) => where(p) === null).map(pieceKey), beckonMs);
@@ -12717,90 +12767,364 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
12717
12767
  buttons.current.get(follow)?.focus();
12718
12768
  setFollow(null);
12719
12769
  }, [follow]);
12720
- const move = (to) => {
12721
- if (held === void 0) return;
12722
- const key = pieceKey(held);
12770
+ React.useEffect(() => () => stopDrag.current?.(), []);
12771
+ React.useEffect(() => {
12772
+ if (locked) stopDrag.current?.();
12773
+ }, [locked]);
12774
+ const bumped = (key, to) => {
12775
+ const s = places.find((q) => placeKey(q) === to);
12776
+ const max = s === void 0 || limit === void 0 ? Infinity : limit(s);
12777
+ const there = pieces.filter((p) => pieceKey(p) !== key && where(p) === to);
12778
+ return there.length >= max ? there[0] : void 0;
12779
+ };
12780
+ const room = (s) => Math.min(pieces.length, limit === void 0 ? Infinity : limit(s));
12781
+ const send = (key, to) => {
12723
12782
  setHeld(null);
12783
+ const out = to === null ? void 0 : bumped(key, to);
12784
+ if (out !== void 0) onMove(pieceKey(out), null);
12724
12785
  onMove(key, to);
12725
12786
  setFollow(key);
12726
12787
  };
12788
+ const move = (to) => {
12789
+ if (held !== void 0) send(pieceKey(held), to);
12790
+ };
12791
+ const latest = React.useRef({
12792
+ send,
12793
+ placement,
12794
+ placeKeys
12795
+ });
12796
+ latest.current = {
12797
+ send,
12798
+ placement,
12799
+ placeKeys
12800
+ };
12801
+ const hit = (x, y) => {
12802
+ for (const [key, el] of zones.current) {
12803
+ const r = el.getBoundingClientRect();
12804
+ if (x >= r.left && x <= r.right && y >= r.top && y <= r.bottom) return key;
12805
+ }
12806
+ };
12807
+ const press = (key) => (e) => {
12808
+ if (locked || e.button !== 0 || !e.isPrimary) return;
12809
+ stopDrag.current?.();
12810
+ const el = e.currentTarget;
12811
+ const { clientX: x0, clientY: y0, pointerId } = e;
12812
+ let size = null;
12813
+ const moved = (ev) => {
12814
+ if (ev.pointerId !== pointerId) return;
12815
+ if (size === null) {
12816
+ if (Math.hypot(ev.clientX - x0, ev.clientY - y0) < DRAG_START) return;
12817
+ const r = el.getBoundingClientRect();
12818
+ size = {
12819
+ w: r.width,
12820
+ h: r.height
12821
+ };
12822
+ dragged.current = true;
12823
+ setHeld(key);
12824
+ }
12825
+ ev.preventDefault();
12826
+ setDrag({
12827
+ key,
12828
+ x: ev.clientX,
12829
+ y: ev.clientY,
12830
+ ...size,
12831
+ over: hit(ev.clientX, ev.clientY)
12832
+ });
12833
+ };
12834
+ const ended = (ev) => {
12835
+ if (ev.pointerId !== pointerId) return;
12836
+ stop();
12837
+ if (size === null) return;
12838
+ const over = ev.type === "pointerup" ? hit(ev.clientX, ev.clientY) : void 0;
12839
+ const { send, placement, placeKeys } = latest.current;
12840
+ const raw = placement[key];
12841
+ const at = raw !== void 0 && placeKeys.has(raw) ? raw : null;
12842
+ const to = over === PILE ? null : over;
12843
+ if (to !== void 0 && to !== at) send(key, to);
12844
+ else setHeld(null);
12845
+ setTimeout(() => {
12846
+ dragged.current = false;
12847
+ }, 0);
12848
+ };
12849
+ const stop = () => {
12850
+ window.removeEventListener("pointermove", moved);
12851
+ window.removeEventListener("pointerup", ended);
12852
+ window.removeEventListener("pointercancel", ended);
12853
+ stopDrag.current = null;
12854
+ setDrag(null);
12855
+ };
12856
+ window.addEventListener("pointermove", moved);
12857
+ window.addEventListener("pointerup", ended);
12858
+ window.addEventListener("pointercancel", ended);
12859
+ stopDrag.current = () => {
12860
+ stop();
12861
+ dragged.current = false;
12862
+ if (size !== null) setHeld(null);
12863
+ };
12864
+ };
12865
+ const zone = (key) => (el) => {
12866
+ if (el) zones.current.set(key, el);
12867
+ else zones.current.delete(key);
12868
+ };
12869
+ const ref = (key) => (el) => {
12870
+ if (el) buttons.current.set(key, el);
12871
+ else buttons.current.delete(key);
12872
+ };
12873
+ const pieceClass = (key) => cn("@container relative flex aspect-square w-full min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-overlay border-2 border-border bg-card p-1 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", "selected:border-info selected:bg-info-subtle selected:ring-4 selected:ring-info", key === lit?.key && cn(lit.className, "border-primary"));
12874
+ const picture = (p, placed) => /* @__PURE__ */ jsx("span", {
12875
+ "aria-hidden": true,
12876
+ className: "type-picture",
12877
+ style: placed ? {
12878
+ ...placedPicture,
12879
+ ...pictureInTile
12880
+ } : pictureInTile,
12881
+ children: renderPiece(p)
12882
+ });
12727
12883
  const piece = (p, placed) => {
12728
12884
  const key = pieceKey(p);
12729
12885
  const isHeld = held !== void 0 && pieceKey(held) === key;
12730
- return /* @__PURE__ */ jsxs(ToggleButton, {
12731
- ref: (el) => {
12732
- if (el) buttons.current.set(key, el);
12733
- else buttons.current.delete(key);
12886
+ const name = pieceLabel(p);
12887
+ const control = only !== void 0 ? /* @__PURE__ */ jsxs(Button$1, {
12888
+ ref: ref(key),
12889
+ isDisabled: locked,
12890
+ onPress: () => {
12891
+ if (!dragged.current) send(key, placed ? null : placeKey(only));
12734
12892
  },
12893
+ "aria-label": placed ? `Take ${name} out of ${placeLabel(only)}` : `Put ${name} in ${placeLabel(only)}`,
12894
+ "data-beckon": key === lit?.key || void 0,
12895
+ className: cn(pieceClass(key), "group", isHeld && "border-info bg-info-subtle ring-4 ring-info"),
12896
+ children: [picture(p, placed), placed && !locked && /* @__PURE__ */ jsx("span", {
12897
+ "aria-hidden": true,
12898
+ "data-remove": true,
12899
+ className: "absolute inset-0 flex items-center justify-center rounded-overlay bg-background/70 text-foreground opacity-0 transition-state group-hover:opacity-100 group-focus-visible:opacity-100",
12900
+ children: /* @__PURE__ */ jsx(X, {
12901
+ className: "size-3/4",
12902
+ strokeWidth: 3
12903
+ })
12904
+ })]
12905
+ }) : /* @__PURE__ */ jsxs(ToggleButton, {
12906
+ ref: ref(key),
12735
12907
  isSelected: isHeld,
12736
- onChange: (on) => setHeld(on ? key : null),
12908
+ onChange: (on) => {
12909
+ if (!dragged.current) setHeld(on ? key : null);
12910
+ },
12737
12911
  isDisabled: locked,
12738
- "aria-label": isHeld ? `${pieceLabel(p)}, ${marks.held.toLowerCase()}` : pieceLabel(p),
12912
+ "aria-label": isHeld ? `${name}, ${marks.held.toLowerCase()}` : name,
12739
12913
  "data-held": isHeld || void 0,
12740
12914
  "data-beckon": key === lit?.key || void 0,
12741
- className: cn("@container flex aspect-square min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-overlay border-2 border-border bg-card p-1 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", "selected:border-4 selected:border-primary selected:bg-muted", key === lit?.key && cn(lit.className, "border-primary")),
12742
- children: [/* @__PURE__ */ jsx("span", {
12743
- "aria-hidden": true,
12744
- className: "type-picture",
12745
- style: placed ? {
12746
- ...placedPicture,
12747
- ...pictureInTile
12748
- } : pictureInTile,
12749
- children: renderPiece(p)
12750
- }), isHeld && /* @__PURE__ */ jsx(Status, {
12915
+ className: pieceClass(key),
12916
+ children: [picture(p, placed), isHeld && /* @__PURE__ */ jsx(Status, {
12751
12917
  tone: "info",
12752
12918
  className: "max-w-full truncate",
12753
12919
  children: marks.held
12754
12920
  })]
12921
+ });
12922
+ return /* @__PURE__ */ jsx("div", {
12923
+ "data-piece": key,
12924
+ onPointerDownCapture: press(key),
12925
+ onDragStart: (e) => e.preventDefault(),
12926
+ className: cn("grid min-w-0", !locked && "touch-none", drag?.key === key && "opacity-30"),
12927
+ children: control
12755
12928
  }, key);
12756
12929
  };
12757
- const grid = (inside, name, side) => inside.length > 0 && /* @__PURE__ */ jsx("div", {
12758
- role: "group",
12759
- "aria-label": name,
12760
- className: "grid min-w-0 gap-2",
12761
- style: { gridTemplateColumns: `repeat(${side === placedSide ? "auto-fill" : fill}, minmax(min(${side}px, 100%), 1fr))` },
12762
- children: inside.map((p) => piece(p, side === placedSide))
12763
- });
12764
- const pile = pieces.filter((p) => where(p) === null);
12930
+ const columns = (side, fit) => ({ gridTemplateColumns: `repeat(${fit}, minmax(min(${side}px, 100%), 1fr))` });
12931
+ const slot = (p) => {
12932
+ if (where(p) === null) return piece(p, false);
12933
+ const key = pieceKey(p);
12934
+ const isHeld = held !== void 0 && pieceKey(held) === key && only === void 0;
12935
+ const gap = "aspect-square min-w-0 rounded-overlay border-2 border-dashed border-border";
12936
+ return isHeld ? /* @__PURE__ */ jsx(Button$1, {
12937
+ onPress: () => move(null),
12938
+ "aria-label": `Put ${pieceLabel(p)} back`,
12939
+ className: cn(gap, "cursor-pointer border-solid border-info ring-4 ring-info outline-offset-2 transition-state press hover:bg-info-subtle")
12940
+ }, key) : /* @__PURE__ */ jsx("div", {
12941
+ "aria-hidden": true,
12942
+ "data-gap": true,
12943
+ className: gap
12944
+ }, key);
12945
+ };
12946
+ const target = (over) => over && "bg-info-subtle";
12947
+ const swap = (out) => out === void 0 ? "" : ` in place of ${pieceLabel(out)}`;
12765
12948
  return /* @__PURE__ */ jsxs("section", {
12766
12949
  "aria-label": label,
12767
12950
  className: cn("grid min-w-0 gap-6", className),
12951
+ children: [
12952
+ /* @__PURE__ */ jsx("div", {
12953
+ ref: zone(PILE),
12954
+ role: "group",
12955
+ "aria-label": pileLabel,
12956
+ className: cn("grid min-w-0 gap-2 rounded-overlay transition-state", target(drag?.over === PILE && heldAt !== null)),
12957
+ style: columns(pieceSide, fill),
12958
+ children: pieces.map(slot)
12959
+ }),
12960
+ /* @__PURE__ */ jsx("div", {
12961
+ className: "grid min-w-0 gap-4",
12962
+ style: only !== void 0 ? void 0 : columns(placeSide, fill),
12963
+ children: places.map((s) => {
12964
+ const key = placeKey(s);
12965
+ const state = placeState(s);
12966
+ const name = placeLabel(s);
12967
+ const inside = pieces.filter((p) => where(p) === key);
12968
+ const takes = held !== void 0 && heldAt !== key;
12969
+ return /* @__PURE__ */ jsxs("div", {
12970
+ ref: zone(key),
12971
+ "data-place": state,
12972
+ className: cn("grid min-w-0 content-start gap-2 rounded-overlay border-2 border-dashed border-input p-2 transition-state", takes && "border-solid border-info ring-4 ring-info", takes && target(drag?.over === key), state === "right" && "border-solid border-success bg-success-subtle ring-2 ring-success", state === "wrong" && "border-solid border-muted-foreground"),
12973
+ children: [/* @__PURE__ */ jsxs(Button$1, {
12974
+ isDisabled: !takes || only !== void 0,
12975
+ onPress: () => move(key),
12976
+ "aria-label": (takes && held !== void 0 && only === void 0 ? `Put ${pieceLabel(held)} in ${name}` + swap(bumped(pieceKey(held), key)) : name) + (state === "open" ? "" : `, ${marks[state].toLowerCase()}`),
12977
+ className: "flex min-h-30 min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-surface outline-offset-2 transition-state press hover:bg-muted disabled:cursor-default disabled:hover:bg-transparent",
12978
+ children: [/* @__PURE__ */ jsx("span", {
12979
+ "aria-hidden": true,
12980
+ className: renderPlace ? "type-picture" : "type-heading",
12981
+ children: renderPlace ? renderPlace(s) : name
12982
+ }), state !== "open" && /* @__PURE__ */ jsx(Status, {
12983
+ tone: state === "right" ? "success" : "neutral",
12984
+ className: "max-w-full truncate",
12985
+ children: marks[state]
12986
+ })]
12987
+ }), /* @__PURE__ */ jsxs("div", {
12988
+ role: inside.length > 0 ? "group" : void 0,
12989
+ "aria-label": inside.length > 0 ? `In ${name}` : void 0,
12990
+ className: "grid min-w-0 gap-2",
12991
+ style: columns(placedSide, "auto-fill"),
12992
+ children: [inside.map((p) => piece(p, true)), Array.from({ length: Math.max(0, room(s) - inside.length) }, (_, i) => /* @__PURE__ */ jsx("div", {
12993
+ "aria-hidden": true,
12994
+ "data-room": true,
12995
+ className: "aspect-square min-w-0"
12996
+ }, `room${i}`))]
12997
+ })]
12998
+ }, key);
12999
+ })
13000
+ }),
13001
+ check && !locked && /* @__PURE__ */ jsxs(Button, {
13002
+ variant: "default",
13003
+ size: "lg",
13004
+ onClick: check.onCheck,
13005
+ disabled: check.disabled,
13006
+ className: "justify-self-center",
13007
+ children: [
13008
+ /* @__PURE__ */ jsx(Check, {
13009
+ "aria-hidden": true,
13010
+ strokeWidth: 3
13011
+ }),
13012
+ check.label,
13013
+ /* @__PURE__ */ jsx(Check, {
13014
+ "aria-hidden": true,
13015
+ strokeWidth: 3
13016
+ })
13017
+ ]
13018
+ }),
13019
+ drag !== null && createPortal((() => {
13020
+ const p = pieces.find((q) => pieceKey(q) === drag.key);
13021
+ return p === void 0 ? null : /* @__PURE__ */ jsx("div", {
13022
+ "aria-hidden": true,
13023
+ "data-dragging": true,
13024
+ className: "@container pointer-events-none fixed z-50 flex items-center justify-center rounded-overlay border-2 border-info bg-info-subtle p-1 text-card-foreground shadow-overlay ring-4 ring-info",
13025
+ style: {
13026
+ left: drag.x - drag.w / 2,
13027
+ top: drag.y - drag.h / 2,
13028
+ width: drag.w,
13029
+ height: drag.h
13030
+ },
13031
+ children: picture(p, where(p) !== null)
13032
+ });
13033
+ })(), document.body)
13034
+ ]
13035
+ });
13036
+ }
13037
+ /** The pile's key among the drop zones: not a string a place key can be. */
13038
+ const PILE = "\0pile";
13039
+ /** How far a press moves, in px, before it is a drag rather than a tap (a finger wobbles a few). */
13040
+ const DRAG_START = 8;
13041
+
13042
+ // src/components/glimpse.tsx
13043
+ /** Shows its content for `ms` after a 3-2-1, with a bar that empties as the time goes, then hides it, keeping its room; shown again when `again` changes, and `peeks` looks again on a button that goes once used. */
13044
+ function Glimpse({ children, ms, count = 3, again = 0, peeks = 0, peekLabel = "Look again", ready = "Get ready to look.", gone, onLook, className }) {
13045
+ const first = count > 0 ? "counting" : "showing";
13046
+ const [phase, setPhase] = React.useState(first);
13047
+ const [look, setLook] = React.useState({
13048
+ n: 1,
13049
+ why: "first"
13050
+ });
13051
+ const [used, setUsed] = React.useState(0);
13052
+ const start = (why) => {
13053
+ setLook((l) => ({
13054
+ n: l.n + 1,
13055
+ why
13056
+ }));
13057
+ setPhase(first);
13058
+ };
13059
+ const [seenAgain, setSeenAgain] = React.useState(again);
13060
+ if (again !== seenAgain) {
13061
+ setSeenAgain(again);
13062
+ start("again");
13063
+ }
13064
+ const left = useCountdown(phase === "counting", count, () => setPhase("showing"), look.n);
13065
+ const [offered, setOffered] = React.useState(peeks > 0);
13066
+ if (peeks > 0 && !offered) setOffered(true);
13067
+ const latest = React.useRef(onLook);
13068
+ React.useEffect(() => {
13069
+ latest.current = onLook;
13070
+ });
13071
+ React.useEffect(() => {
13072
+ if (phase !== "showing") return;
13073
+ latest.current?.(look);
13074
+ const t = setTimeout(() => setPhase("gone"), ms);
13075
+ return () => clearTimeout(t);
13076
+ }, [
13077
+ phase,
13078
+ look,
13079
+ ms
13080
+ ]);
13081
+ const canPeek = phase === "gone" && used < peeks;
13082
+ const said = phase === "counting" ? ready : phase === "gone" ? gone : "";
13083
+ return /* @__PURE__ */ jsxs("div", {
13084
+ "data-glimpse": phase,
13085
+ className: cn("grid justify-items-center", className),
12768
13086
  children: [/* @__PURE__ */ jsxs("div", {
12769
- className: "grid min-w-0 gap-2",
12770
- children: [grid(pile, pileLabel, pieceSide), heldAt !== null && held !== void 0 && /* @__PURE__ */ jsx(Button$1, {
12771
- onPress: () => move(null),
12772
- className: "min-h-(--control-h) justify-self-start rounded-control border border-input bg-background px-3 type-label transition-state press hover:bg-muted",
12773
- children: `Put ${pieceLabel(held)} back`
13087
+ className: "grid gap-3",
13088
+ children: [/* @__PURE__ */ jsxs("div", {
13089
+ className: "grid place-items-center",
13090
+ children: [
13091
+ /* @__PURE__ */ jsx("div", {
13092
+ className: cn("col-start-1 row-start-1", phase !== "showing" && "invisible"),
13093
+ children
13094
+ }),
13095
+ count > 0 && /* @__PURE__ */ jsx("span", {
13096
+ "aria-hidden": true,
13097
+ "data-countdown": left !== null || void 0,
13098
+ className: cn("col-start-1 row-start-1 type-picture tabular-nums text-muted-foreground", left === null && "invisible"),
13099
+ children: left ?? count
13100
+ }),
13101
+ offered && /* @__PURE__ */ jsx("div", {
13102
+ className: cn("col-start-1 row-start-1", !canPeek && "invisible"),
13103
+ "aria-hidden": !canPeek || void 0,
13104
+ inert: !canPeek || void 0,
13105
+ children: /* @__PURE__ */ jsxs(Button, {
13106
+ size: "lg",
13107
+ onPress: () => {
13108
+ setUsed((u) => u + 1);
13109
+ start("peek");
13110
+ },
13111
+ children: [/* @__PURE__ */ jsx(Eye, { "aria-hidden": true }), peekLabel]
13112
+ })
13113
+ })
13114
+ ]
13115
+ }), /* @__PURE__ */ jsx("div", {
13116
+ "aria-hidden": true,
13117
+ className: cn("h-2 w-full overflow-hidden rounded-pill bg-muted", phase !== "showing" && "invisible"),
13118
+ children: phase === "showing" && /* @__PURE__ */ jsx("div", {
13119
+ "data-time-left": true,
13120
+ className: "drain h-full bg-primary",
13121
+ style: { "--drain-ms": `${ms}ms` }
13122
+ }, look.n)
12774
13123
  })]
12775
- }), /* @__PURE__ */ jsx("div", {
12776
- className: "grid min-w-0 gap-4",
12777
- style: { gridTemplateColumns: `repeat(${fill}, minmax(min(${placeSide}px, 100%), 1fr))` },
12778
- children: places.map((s) => {
12779
- const key = placeKey(s);
12780
- const state = placeState(s);
12781
- const name = placeLabel(s);
12782
- const inside = pieces.filter((p) => where(p) === key);
12783
- const takes = held !== void 0 && heldAt !== key;
12784
- return /* @__PURE__ */ jsxs("div", {
12785
- "data-place": state,
12786
- className: cn("grid min-w-0 content-start gap-2 rounded-overlay border-2 border-dashed border-input p-2 transition-state", takes && "border-solid border-primary", state === "right" && "border-4 border-solid border-success bg-success-subtle", state === "wrong" && "border-solid border-muted-foreground"),
12787
- children: [/* @__PURE__ */ jsxs(Button$1, {
12788
- isDisabled: !takes,
12789
- onPress: () => move(key),
12790
- "aria-label": (takes && held !== void 0 ? `Put ${pieceLabel(held)} in ${name}` : name) + (state === "open" ? "" : `, ${marks[state].toLowerCase()}`),
12791
- className: "flex min-h-30 min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-surface outline-offset-2 transition-state press hover:bg-muted disabled:cursor-default disabled:hover:bg-transparent",
12792
- children: [/* @__PURE__ */ jsx("span", {
12793
- "aria-hidden": true,
12794
- className: renderPlace ? "type-picture" : "type-heading",
12795
- children: renderPlace ? renderPlace(s) : name
12796
- }), state !== "open" && /* @__PURE__ */ jsx(Status, {
12797
- tone: state === "right" ? "success" : "neutral",
12798
- className: "max-w-full truncate",
12799
- children: marks[state]
12800
- })]
12801
- }), grid(inside, `In ${name}`, placedSide)]
12802
- }, key);
12803
- })
13124
+ }), /* @__PURE__ */ jsx("span", {
13125
+ role: "status",
13126
+ className: "sr-only",
13127
+ children: said
12804
13128
  })]
12805
13129
  });
12806
13130
  }
@@ -21541,5 +21865,5 @@ function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose
21541
21865
  });
21542
21866
  }
21543
21867
 
21544
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EditListPlayer, EmptyState, FIT, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, FullscreenFrame, 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, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, 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, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, continues, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, ease, editTimeOf, editTimes, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, followAim, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, inkMatch, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, locateInEdit, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, nextBreak, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, resample, resamplePeaks, resizeRect, rgbaToBlob, rmsDb, safeHref, sayPosition, serialiseSort, settleCut, skipAction, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, 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, useDifference, useEditList, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useInkMatch, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useRebindableShortcuts, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSettledStatus, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
21868
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EditListPlayer, EmptyState, FIT, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, 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, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, 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, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, continues, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, ease, editTimeOf, editTimes, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, followAim, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, inkMatch, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, locateInEdit, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, nextBreak, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, resample, resamplePeaks, resizeRect, rgbaToBlob, rmsDb, safeHref, sayPosition, serialiseSort, settleCut, skipAction, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, 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, useEditList, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useInkMatch, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useRebindableShortcuts, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSettledStatus, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
21545
21869
  //# sourceMappingURL=index.js.map