strata-react 2.1.8 → 2.1.10

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
@@ -4,7 +4,7 @@ import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as
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
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-Db5o3SHZ.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-D5zpPQuJ.js";
7
+ import { a as AsyncButton, c as ToolbarSeparator, d as keyName, f as useHotkeys, i as Slider, l as KeysLegend, n as NumberField, o as useAsyncAction, r as RangeSlider, s as Toolbar, t as ColorField, u as isTypingTarget } from "./value-controls-i1aGyO_3.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-5Mb1ydlA.js";
@@ -3486,6 +3486,59 @@ function ScheduleTable({ caption, rows, now, className }) {
3486
3486
  });
3487
3487
  }
3488
3488
 
3489
+ // src/components/concealed.tsx
3490
+ /** Content covered until a person chooses to see it: the reason in words, a named Show / Hide button, and the picture itself supplied by the app (blurred by the server while covered), so nothing is hidden by CSS alone. */
3491
+ function Concealed({ concealed, reason, label, revealed, onRevealedChange, children, className }) {
3492
+ if (!concealed) return /* @__PURE__ */ jsx(Fragment, { children });
3493
+ const Icon = revealed ? EyeOff : Eye;
3494
+ return /* @__PURE__ */ jsxs("div", {
3495
+ className: cn("relative", className),
3496
+ "data-concealed": revealed ? "revealed" : "covered",
3497
+ children: [children, /* @__PURE__ */ jsxs("div", {
3498
+ className: "absolute inset-x-0 bottom-0 flex items-center justify-between gap-2 bg-background/85 px-2 py-1",
3499
+ children: [/* @__PURE__ */ jsx("span", {
3500
+ className: "min-w-0 truncate type-caption text-foreground",
3501
+ children: reason
3502
+ }), /* @__PURE__ */ jsx(IconButton, {
3503
+ icon: Icon,
3504
+ size: "sm",
3505
+ label: `${revealed ? "Hide" : "Show"} ${label}`,
3506
+ onPress: () => onRevealedChange(!revealed)
3507
+ })]
3508
+ })]
3509
+ });
3510
+ }
3511
+ /** Which covered items a person has chosen to see on this screen, and a show-all switch; for this visit only, never stored. */
3512
+ function useRevealed() {
3513
+ const [ids, setIds] = React.useState(/* @__PURE__ */ new Set());
3514
+ const [all, setAllState] = React.useState(false);
3515
+ const isRevealed = React.useCallback((id) => all || ids.has(id), [all, ids]);
3516
+ const set = React.useCallback((id, revealed) => {
3517
+ setIds((prev) => {
3518
+ const next = new Set(prev);
3519
+ if (revealed) next.add(id);
3520
+ else next.delete(id);
3521
+ return next;
3522
+ });
3523
+ if (!revealed) setAllState(false);
3524
+ }, []);
3525
+ const setAll = React.useCallback((on) => {
3526
+ setAllState(on);
3527
+ if (!on) setIds(/* @__PURE__ */ new Set());
3528
+ }, []);
3529
+ return React.useMemo(() => ({
3530
+ isRevealed,
3531
+ set,
3532
+ all,
3533
+ setAll
3534
+ }), [
3535
+ isRevealed,
3536
+ set,
3537
+ all,
3538
+ setAll
3539
+ ]);
3540
+ }
3541
+
3489
3542
  // src/components/film-strip.tsx
3490
3543
  const GAP$1 = 4;
3491
3544
  /** `n` of `items` spread evenly from the first to the last (all of them when there are no more than `n`). */
@@ -12828,7 +12881,7 @@ function nextBeckon(open, last) {
12828
12881
  const others = open.length > 1 ? open.filter((k) => k !== last) : open;
12829
12882
  return others[Math.floor(Math.random() * others.length)] ?? null;
12830
12883
  }
12831
- const SEP$1 = "\0";
12884
+ const SEP$2 = "\0";
12832
12885
  const REDUCE = "(prefers-reduced-motion: reduce)";
12833
12886
  const reduceQuery = () => typeof matchMedia === "function" ? matchMedia(REDUCE) : null;
12834
12887
  function subscribeReduce(change) {
@@ -12845,11 +12898,11 @@ function useReducedMotion() {
12845
12898
  * open tile, lit beat after beat, still pulses each time (Codex on #400). */
12846
12899
  function useBeckon(on, open, ms) {
12847
12900
  const [lit, setLit] = React.useState(null);
12848
- const openKey = open.join(SEP$1);
12901
+ const openKey = open.join(SEP$2);
12849
12902
  const still = useReducedMotion();
12850
12903
  React.useEffect(() => {
12851
12904
  if (!on || still || openKey === "") return;
12852
- const keys = openKey.split(SEP$1);
12905
+ const keys = openKey.split(SEP$2);
12853
12906
  let last = null;
12854
12907
  let beat = 0;
12855
12908
  const t = setInterval(() => {
@@ -12875,9 +12928,26 @@ function useBeckon(on, open, ms) {
12875
12928
  className: lit.beat % 2 ? "beckon" : "beckon-again"
12876
12929
  } : null;
12877
12930
  }
12931
+ const TILE = "min(var(--type-picture-size, 4.5rem), 75cqi)";
12932
+ const WORD$1 = /^\p{L}[\p{L}\p{M}' -]*$/u;
12933
+ const WORD_SHARE = 140;
12934
+ const letters = new Intl.Segmenter(void 0, { granularity: "grapheme" });
12878
12935
  /** A tile's picture: the `type-picture` step, but never more than 75% of the tile it sits in (the tile is a size
12879
- * container), so an app that grows the step on a wide screen does not push a picture out of a small tile. */
12880
- const pictureInTile = { fontSize: "min(var(--type-picture-size, 4.5rem), 75cqi)" };
12936
+ * container), so an app that grows the step on a wide screen does not push a picture out of a small tile. A word of
12937
+ * three letters or more (`content` a string of letters) is made smaller still, so the whole word fits across the tile:
12938
+ * the longer the word, the smaller. */
12939
+ function pictureInTile(content) {
12940
+ if (typeof content !== "string" || !WORD$1.test(content)) return { fontSize: TILE };
12941
+ const n = [...letters.segment(content)].length;
12942
+ return n <= 2 ? { fontSize: TILE } : { fontSize: `min(var(--type-picture-size, 4.5rem), 75cqi, ${Math.round(WORD_SHARE / n * 10) / 10}cqi)` };
12943
+ }
12944
+ const CAPTION = "var(--type-body-size, 1rem)";
12945
+ const CAPTION_SHARE = 160;
12946
+ /** A caption's size in its tile: the body step, or smaller for a long caption so it fits across the tile on one line. */
12947
+ function captionInTile(content) {
12948
+ const n = typeof content === "string" ? [...letters.segment(content)].length : 0;
12949
+ return n <= 8 ? { fontSize: `min(${CAPTION}, 20cqi)` } : { fontSize: `min(${CAPTION}, ${Math.round(CAPTION_SHARE / n * 10) / 10}cqi)` };
12950
+ }
12881
12951
 
12882
12952
  // src/components/choice-grid.tsx
12883
12953
  const minSide = {
@@ -12887,11 +12957,11 @@ const minSide = {
12887
12957
  const closed = (s) => s === "right" || s === "answer" || s === "picked";
12888
12958
  const columns = (size, stretch = false) => ({ gridTemplateColumns: `repeat(${stretch ? "auto-fit" : "auto-fill"}, minmax(min(${minSide[size]}px, 100%), 1fr))` });
12889
12959
  /** A grid of large picture tiles for answering one question with a tap: each tile open, wrong, right, shown as the answer or (no answer key) picked, with its word; answered tiles cannot be pressed again, and the grid closes once the answer shows. */
12890
- function ChoiceGrid({ label, items, itemKey, itemLabel, renderPicture, state, marks, onChoose, size = "md", stretch = false, beckon = false, beckonMs = 1600, className }) {
12960
+ function ChoiceGrid({ label, items, itemKey, itemLabel, renderPicture, state, marks, onChoose, size = "md", stretch = false, beckon = false, beckonMs = 1600, renderCaption, onHover, reading = null, className }) {
12891
12961
  const byKey = new Map(items.map((item) => [itemKey(item), item]));
12892
12962
  const over = items.some((item) => closed(state(item)));
12893
12963
  const disabledKeys = items.filter((item) => over || state(item) !== "open").map(itemKey);
12894
- const lit = useBeckon(beckon && !over, items.filter((item) => state(item) === "open").map(itemKey), beckonMs);
12964
+ const lit = useBeckon(beckon && !over && reading === null, items.filter((item) => state(item) === "open").map(itemKey), beckonMs);
12895
12965
  return /* @__PURE__ */ jsx(GridList, {
12896
12966
  "aria-label": label,
12897
12967
  layout: "grid",
@@ -12913,17 +12983,35 @@ function ChoiceGrid({ label, items, itemKey, itemLabel, renderPicture, state, ma
12913
12983
  "aria-label": mark ? `${itemLabel(item)}, ${mark.toLowerCase()}` : itemLabel(item),
12914
12984
  "data-choice": s,
12915
12985
  "data-beckon": key === lit?.key || void 0,
12916
- 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-2 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", key === lit?.key && cn(lit.className, "border-primary"), (s === "right" || s === "answer") && "border-4 border-success bg-success-subtle disabled:hover:border-success", s === "picked" && "border-4 border-primary bg-surface-sunken disabled:hover:border-primary"),
12917
- children: [/* @__PURE__ */ jsx("span", {
12918
- "aria-hidden": true,
12919
- className: cn("type-picture transition-state", s === "wrong" && "opacity-40"),
12920
- style: pictureInTile,
12921
- children: renderPicture(item)
12922
- }), mark && /* @__PURE__ */ jsx(Status, {
12923
- tone: s === "wrong" || s === "picked" ? "neutral" : "success",
12924
- className: "max-w-full truncate",
12925
- children: mark
12926
- })]
12986
+ "data-reading": key === reading || void 0,
12987
+ onPointerEnter: onHover && ((e) => e.pointerType !== "touch" && onHover(item)),
12988
+ 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-2 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", key === lit?.key && cn(lit.className, "border-primary"), key === reading && "border-primary ring-4 ring-primary", (s === "right" || s === "answer") && "border-4 border-success bg-success-subtle disabled:hover:border-success", s === "picked" && "border-4 border-primary bg-surface-sunken disabled:hover:border-primary"),
12989
+ children: [
12990
+ (() => {
12991
+ const drawn = renderPicture(item);
12992
+ return /* @__PURE__ */ jsx("span", {
12993
+ "aria-hidden": true,
12994
+ className: cn("type-picture transition-state", s === "wrong" && "opacity-40"),
12995
+ style: pictureInTile(drawn),
12996
+ children: drawn
12997
+ });
12998
+ })(),
12999
+ renderCaption && (() => {
13000
+ const caption = renderCaption(item);
13001
+ return /* @__PURE__ */ jsx("span", {
13002
+ "aria-hidden": true,
13003
+ "data-caption": true,
13004
+ className: cn("type-body max-w-full truncate font-medium", s === "wrong" && "opacity-40"),
13005
+ style: captionInTile(caption),
13006
+ children: caption
13007
+ });
13008
+ })(),
13009
+ mark && /* @__PURE__ */ jsx(Status, {
13010
+ tone: s === "wrong" || s === "picked" ? "neutral" : "success",
13011
+ className: "max-w-full truncate",
13012
+ children: mark
13013
+ })
13014
+ ]
12927
13015
  }, key);
12928
13016
  })
12929
13017
  });
@@ -12944,7 +13032,7 @@ const placedSide = 72;
12944
13032
  const placedPicture = { "--type-picture-size": "2.5rem" };
12945
13033
  const placeSide = 160;
12946
13034
  /** 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. */
12947
- 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 }) {
13035
+ 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, renderCaption, onHover, onHoverPlace, reading = null, className }) {
12948
13036
  const fill = stretch ? "auto-fit" : "auto-fill";
12949
13037
  const [heldKey, setHeld] = React.useState(null);
12950
13038
  const [follow, setFollow] = React.useState(null);
@@ -12961,7 +13049,7 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
12961
13049
  const only = places.length === 1 ? places[0] : void 0;
12962
13050
  const held = locked ? void 0 : pieces.find((p) => pieceKey(p) === heldKey);
12963
13051
  const heldAt = held === void 0 ? null : where(held);
12964
- const lit = useBeckon(beckon && !locked && held === void 0, pieces.filter((p) => where(p) === null).map(pieceKey), beckonMs);
13052
+ const lit = useBeckon(beckon && !locked && held === void 0 && reading === null, pieces.filter((p) => where(p) === null).map(pieceKey), beckonMs);
12965
13053
  React.useEffect(() => {
12966
13054
  if (follow === null) return;
12967
13055
  buttons.current.get(follow)?.focus();
@@ -13070,16 +13158,33 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
13070
13158
  if (el) buttons.current.set(key, el);
13071
13159
  else buttons.current.delete(key);
13072
13160
  };
13073
- 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"));
13074
- const picture = (p, placed) => /* @__PURE__ */ jsx("span", {
13075
- "aria-hidden": true,
13076
- className: "type-picture",
13077
- style: placed ? {
13078
- ...placedPicture,
13079
- ...pictureInTile
13080
- } : pictureInTile,
13081
- children: renderPiece(p)
13082
- });
13161
+ 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"), key === reading && "border-primary ring-4 ring-primary");
13162
+ const picture = (p, placed) => {
13163
+ const drawn = renderPiece(p);
13164
+ return /* @__PURE__ */ jsx("span", {
13165
+ "aria-hidden": true,
13166
+ className: "type-picture",
13167
+ style: placed ? {
13168
+ ...placedPicture,
13169
+ ...pictureInTile(drawn)
13170
+ } : pictureInTile(drawn),
13171
+ children: drawn
13172
+ });
13173
+ };
13174
+ const caption = (p) => {
13175
+ if (!renderCaption) return null;
13176
+ const text = renderCaption(p);
13177
+ return /* @__PURE__ */ jsx("span", {
13178
+ "aria-hidden": true,
13179
+ "data-caption": true,
13180
+ className: "type-body max-w-full truncate font-medium",
13181
+ style: captionInTile(text),
13182
+ children: text
13183
+ });
13184
+ };
13185
+ const hover = (say) => (e) => {
13186
+ if (e.pointerType !== "touch") say();
13187
+ };
13083
13188
  const piece = (p, placed) => {
13084
13189
  const key = pieceKey(p);
13085
13190
  const isHeld = held !== void 0 && pieceKey(held) === key;
@@ -13093,15 +13198,19 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
13093
13198
  "aria-label": placed ? `Take ${name} out of ${placeLabel(only)}` : `Put ${name} in ${placeLabel(only)}`,
13094
13199
  "data-beckon": key === lit?.key || void 0,
13095
13200
  className: cn(pieceClass(key), "group", isHeld && "border-info bg-info-subtle ring-4 ring-info"),
13096
- children: [picture(p, placed), placed && !locked && /* @__PURE__ */ jsx("span", {
13097
- "aria-hidden": true,
13098
- "data-remove": true,
13099
- 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",
13100
- children: /* @__PURE__ */ jsx(X, {
13101
- className: "size-3/4",
13102
- strokeWidth: 3
13201
+ children: [
13202
+ picture(p, placed),
13203
+ caption(p),
13204
+ placed && !locked && /* @__PURE__ */ jsx("span", {
13205
+ "aria-hidden": true,
13206
+ "data-remove": true,
13207
+ 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",
13208
+ children: /* @__PURE__ */ jsx(X, {
13209
+ className: "size-3/4",
13210
+ strokeWidth: 3
13211
+ })
13103
13212
  })
13104
- })]
13213
+ ]
13105
13214
  }) : /* @__PURE__ */ jsxs(ToggleButton, {
13106
13215
  ref: ref(key),
13107
13216
  isSelected: isHeld,
@@ -13113,15 +13222,21 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
13113
13222
  "data-held": isHeld || void 0,
13114
13223
  "data-beckon": key === lit?.key || void 0,
13115
13224
  className: pieceClass(key),
13116
- children: [picture(p, placed), isHeld && /* @__PURE__ */ jsx(Status, {
13117
- tone: "info",
13118
- className: "absolute inset-x-1 bottom-1 justify-center truncate",
13119
- children: marks.held
13120
- })]
13225
+ children: [
13226
+ picture(p, placed),
13227
+ caption(p),
13228
+ isHeld && /* @__PURE__ */ jsx(Status, {
13229
+ tone: "info",
13230
+ className: "absolute inset-x-1 bottom-1 justify-center truncate",
13231
+ children: marks.held
13232
+ })
13233
+ ]
13121
13234
  });
13122
13235
  return /* @__PURE__ */ jsx("div", {
13123
13236
  "data-piece": key,
13124
13237
  onPointerDownCapture: press(key),
13238
+ onPointerEnter: onHover && hover(() => onHover(p)),
13239
+ "data-reading": key === reading || void 0,
13125
13240
  onDragStart: (e) => e.preventDefault(),
13126
13241
  className: cn("grid min-w-0 items-start", !locked && "touch-none", drag?.key === key && "opacity-30"),
13127
13242
  children: control
@@ -13169,6 +13284,7 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
13169
13284
  return /* @__PURE__ */ jsxs("div", {
13170
13285
  ref: zone(key),
13171
13286
  "data-place": state,
13287
+ onPointerEnter: onHoverPlace && hover(() => onHoverPlace(s)),
13172
13288
  className: cn("grid min-w-0 content-start items-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"),
13173
13289
  children: [/* @__PURE__ */ jsxs(Button$1, {
13174
13290
  isDisabled: !takes || only !== void 0,
@@ -13222,17 +13338,17 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
13222
13338
  }),
13223
13339
  drag !== null && createPortal((() => {
13224
13340
  const p = pieces.find((q) => pieceKey(q) === drag.key);
13225
- return p === void 0 ? null : /* @__PURE__ */ jsx("div", {
13341
+ return p === void 0 ? null : /* @__PURE__ */ jsxs("div", {
13226
13342
  "aria-hidden": true,
13227
13343
  "data-dragging": true,
13228
- 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",
13344
+ className: "@container pointer-events-none fixed z-50 flex flex-col items-center justify-center gap-1 rounded-overlay border-2 border-info bg-info-subtle p-1 text-card-foreground shadow-overlay ring-4 ring-info",
13229
13345
  style: {
13230
13346
  left: drag.x - drag.w / 2,
13231
13347
  top: drag.y - drag.h / 2,
13232
13348
  width: drag.w,
13233
13349
  height: drag.h
13234
13350
  },
13235
- children: picture(p, where(p) !== null)
13351
+ children: [picture(p, where(p) !== null), caption(p)]
13236
13352
  });
13237
13353
  })(), document.body)
13238
13354
  ]
@@ -15545,6 +15661,107 @@ function useSayOnShow(text, { muted = false } = {}) {
15545
15661
  ]);
15546
15662
  }
15547
15663
 
15664
+ // src/lib/read-aloud.ts
15665
+ const SEP$1 = "\0";
15666
+ /** Reads a grid's tiles aloud once, one at a time, and says which is being read so the grid can light it. */
15667
+ function useReadAloud({ keys, say, gapMs = 300 }) {
15668
+ const [reading, setReading] = React.useState(null);
15669
+ const setKey = keys.join(SEP$1);
15670
+ const run = React.useRef({
15671
+ token: 0,
15672
+ spent: false,
15673
+ timer: void 0
15674
+ });
15675
+ const latest = React.useRef({
15676
+ keys,
15677
+ say,
15678
+ gapMs
15679
+ });
15680
+ latest.current = {
15681
+ keys,
15682
+ say,
15683
+ gapMs
15684
+ };
15685
+ const stop = React.useCallback(() => {
15686
+ const r = run.current;
15687
+ r.token += 1;
15688
+ r.spent = true;
15689
+ clearTimeout(r.timer);
15690
+ setReading(null);
15691
+ }, []);
15692
+ React.useEffect(() => {
15693
+ const r = run.current;
15694
+ r.spent = false;
15695
+ return () => {
15696
+ r.token += 1;
15697
+ clearTimeout(r.timer);
15698
+ setReading(null);
15699
+ };
15700
+ }, [setKey]);
15701
+ return {
15702
+ reading,
15703
+ start: React.useCallback(() => {
15704
+ const r = run.current;
15705
+ if (r.spent) return;
15706
+ r.spent = true;
15707
+ const token = ++r.token;
15708
+ const from = (i) => {
15709
+ if (token !== r.token) return;
15710
+ const key = latest.current.keys[i];
15711
+ if (key === void 0) {
15712
+ setReading(null);
15713
+ return;
15714
+ }
15715
+ setReading(key);
15716
+ let said = false;
15717
+ const done = () => {
15718
+ if (said || token !== r.token) return;
15719
+ said = true;
15720
+ r.timer = setTimeout(() => from(i + 1), latest.current.gapMs);
15721
+ };
15722
+ if (!latest.current.say(key, done)) {
15723
+ r.token += 1;
15724
+ setReading(null);
15725
+ }
15726
+ };
15727
+ from(0);
15728
+ }, []),
15729
+ stop
15730
+ };
15731
+ }
15732
+
15733
+ // src/components/read-along.tsx
15734
+ /** A run of words or numbers read aloud a part at a time, each lit as it is said, with the part the question is about left lit and pulsing. */
15735
+ function ReadAlong({ parts, reading = null, target = null, onPress, label, className }) {
15736
+ const drawn = parts.map((p) => /* @__PURE__ */ jsx("span", {
15737
+ "data-part": p.key,
15738
+ "data-reading": p.key === reading || void 0,
15739
+ "data-target": p.key === target && reading === null || void 0,
15740
+ className: cn("inline-block rounded-control px-2 ring-primary transition-state", p.key === reading && "bg-accent text-accent-foreground ring-4", p.key === target && reading === null && "beckon-loop bg-accent text-accent-foreground ring-4"),
15741
+ children: p.text
15742
+ }, p.key));
15743
+ const row = "flex flex-wrap items-center justify-center gap-x-2 gap-y-1 text-center";
15744
+ return onPress ? /* @__PURE__ */ jsx(Button$1, {
15745
+ "aria-label": label,
15746
+ onPress,
15747
+ className: cn(row, "cursor-pointer rounded-surface transition-state press", className),
15748
+ children: /* @__PURE__ */ jsx("span", {
15749
+ "aria-hidden": true,
15750
+ className: "contents",
15751
+ children: drawn
15752
+ })
15753
+ }) : /* @__PURE__ */ jsx("div", {
15754
+ role: "group",
15755
+ "aria-label": label,
15756
+ className: cn(row, className),
15757
+ children: /* @__PURE__ */ jsx("span", {
15758
+ "aria-hidden": true,
15759
+ className: "contents",
15760
+ children: drawn
15761
+ })
15762
+ });
15763
+ }
15764
+
15548
15765
  // src/components/say-again.tsx
15549
15766
  /** An icon button that says one sentence aloud, from its recordings when given, else with the browser's voice; hidden where neither can be heard or it is muted. */
15550
15767
  function SayAgain({ text, parts, verb = "Say", className, ...options }) {
@@ -23267,5 +23484,5 @@ function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose
23267
23484
  });
23268
23485
  }
23269
23486
 
23270
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BRUSHES, 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, DrawingLayer, DrawingToolbar, 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, SayPicture, 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, applyOp, 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, currentOf, curvePoints, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, drawingToSvg, ease, editTimeOf, editTimes, emptyDrawing, encodeWav, errorPayload, explainMicrophoneError, feedbackMarker, fetchJson, fieldErrorsOf, filterMarkup, findPage, fitPoints, fitRect, followAim, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, hitsStroke, inkMatch, inputLevelThresholds, invertOp, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, locateInEdit, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, mediaStatRows, moveGutter, 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, safeHref, sayPosition, serialiseSort, settleCut, simplifyPoints, skipAction, smoothPath, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, 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, useRebindableShortcuts, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSettledStatus, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, widthsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
23487
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BRUSHES, 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, Concealed, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, DrawingLayer, DrawingToolbar, 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, RangeSlider, RateChoice, ReadAlong, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, SayPicture, 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, applyOp, 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, currentOf, curvePoints, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, drawingToSvg, ease, editTimeOf, editTimes, emptyDrawing, encodeWav, errorPayload, explainMicrophoneError, feedbackMarker, fetchJson, fieldErrorsOf, filterMarkup, findPage, fitPoints, fitRect, followAim, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, hitsStroke, inkMatch, inputLevelThresholds, invertOp, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, locateInEdit, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, mediaStatRows, moveGutter, 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, safeHref, sayPosition, serialiseSort, settleCut, simplifyPoints, skipAction, smoothPath, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, 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, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, widthsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
23271
23488
  //# sourceMappingURL=index.js.map