@saar-ai/web-widget 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -524,6 +524,7 @@ var defaultWidgetMessages = {
524
524
  dock_cards: "{count} picks — see",
525
525
  dock_voice_failed: "Couldn’t start the call — type instead",
526
526
  dock_show_transcript: "Show what was said",
527
+ dock_show_conversation: "Show conversation",
527
528
  dock_earbuds: "Earbuds in — talk freely",
528
529
  handoff_event: "Handed to a human teammate",
529
530
  escalated_banner: "A human teammate will pick this up shortly.",
@@ -840,11 +841,14 @@ var WIDGET_THEME_TOKENS = [
840
841
  "--wgt-accent",
841
842
  "--wgt-surface",
842
843
  "--wgt-surface-2",
844
+ "--wgt-surface-glass",
845
+ "--wgt-surface-glass-blurred",
843
846
  "--wgt-text",
844
847
  "--wgt-text-muted",
845
848
  "--wgt-border",
846
849
  "--wgt-ring",
847
850
  "--wgt-radius",
851
+ "--wgt-row-radius",
848
852
  "--wgt-sheet-radius",
849
853
  "--wgt-card-radius",
850
854
  "--wgt-font",
@@ -895,6 +899,60 @@ var MUTED_ALPHA = .62;
895
899
  var BORDER_ALPHA = .12;
896
900
  /** §9.2: `color-mix(in oklch, surface 94%, text)`, computed rather than emitted. */
897
901
  var SURFACE_2_MIX = .06;
902
+ /**
903
+ * §3.3 (revised 2026-09-11) — the sheet is translucent, at one of TWO alphas.
904
+ *
905
+ * The sheet overlays the merchant's page and has to read as something the
906
+ * concierge raised over it rather than as a second page pasted on top. How
907
+ * much of the page can show through before it stops being texture and starts
908
+ * being competing content depends entirely on whether a blur is standing
909
+ * between the two, so there are two tokens rather than one:
910
+ *
911
+ * - `--wgt-surface-glass` (97 %) is the DEFAULT, and the one the sheet uses
912
+ * unless something else is established. No blur is helping it, so it faces
913
+ * the merchant's page at full detail. Photographed against a product grid,
914
+ * 92 % left the card titles and prices plainly READABLE through the
915
+ * greeting and the chips; 95 % and 96 % still did; 97 % is the first step
916
+ * where the backdrop stops competing with the text and stays a tint.
917
+ * - `--wgt-surface-glass-blurred` (92 %) is for the one case where a
918
+ * `backdrop-filter` is behind the surface — `pointer: fine`, and only
919
+ * where the browser actually supports the filter (§3.3). A 16 px blur
920
+ * destroys exactly the high-frequency detail that made 92 % illegible, so
921
+ * the extra five per cent buys depth at no cost to the reading surface.
922
+ *
923
+ * The default being the SAFE one is deliberate: every way the blur can fail
924
+ * to apply — an unsupported browser, a stripped declaration, a coarse
925
+ * pointer, a future refactor that moves the rule — lands on the alpha that is
926
+ * legible without it. The pairing is asserted in `concierge-css.test.ts`
927
+ * against the COMPILED bundle, because a `backdrop-filter` that survives the
928
+ * source and not the minifier is exactly how this shipped wrong once.
929
+ *
930
+ * Tokens rather than an `opacity` on the element, because `opacity` on the
931
+ * sheet would fade its contents — the shopper's own words, the prices — and
932
+ * because §7.1 rule 1 wants nothing on that box that a transition could later
933
+ * be attached to. The BUBBLES inside stay opaque (`--wgt-surface-2`) either
934
+ * way: the reading surface is solid and it is the sheet's margins that show
935
+ * the page.
936
+ *
937
+ * The ROW is deliberately not glass at all. It is a control surface: the
938
+ * caption is a field somebody types into and the four slots have to stay
939
+ * legible over whatever the merchant's page happens to be scrolled to.
940
+ */
941
+ var SURFACE_GLASS_ALPHA = .97;
942
+ /** §3.3 — the alpha that is only safe with a blur behind it. See above. */
943
+ var SURFACE_GLASS_BLURRED_ALPHA = .92;
944
+ /**
945
+ * §2 (revised 2026-09-11) — the row and the pill are ALWAYS a full pill.
946
+ *
947
+ * A constant rather than a derivation, and emitted as a token rather than
948
+ * hard-coded in the two stylesheets, for the reason every other length here
949
+ * is: the dock is drawn twice and the two renderers must not each carry their
950
+ * own 9999. `type.radius` keeps shaping the sheet (`--wgt-sheet-radius`), the
951
+ * cards (`--wgt-card-radius`) and the buttons (`--wgt-radius`) — it stopped
952
+ * shaping the row on 2026-09-11, because a 48 px bar with 12 px corners
953
+ * reads as a dialog that lost its title bar, and the row is not a dialog.
954
+ */
955
+ var ROW_RADIUS_CSS = "9999px";
898
956
  /** §9.3's floor for derived text on the surface. */
899
957
  var TEXT_CONTRAST_MIN = 4.5;
900
958
  /** §11's floor for the focus ring against the surface it is drawn on. */
@@ -1037,11 +1095,14 @@ function deriveVars(color, type, surfaceHex) {
1037
1095
  "--wgt-accent": accent,
1038
1096
  "--wgt-surface": surface,
1039
1097
  "--wgt-surface-2": mixToward(surface, text, SURFACE_2_MIX),
1098
+ "--wgt-surface-glass": withAlpha(surface, SURFACE_GLASS_ALPHA),
1099
+ "--wgt-surface-glass-blurred": withAlpha(surface, SURFACE_GLASS_BLURRED_ALPHA),
1040
1100
  "--wgt-text": text,
1041
1101
  "--wgt-text-muted": withAlpha(text, MUTED_ALPHA),
1042
1102
  "--wgt-border": withAlpha(text, BORDER_ALPHA),
1043
1103
  "--wgt-ring": deriveRing(primary, surface),
1044
1104
  "--wgt-radius": `${radiusPx}px`,
1105
+ "--wgt-row-radius": ROW_RADIUS_CSS,
1045
1106
  "--wgt-sheet-radius": `${Math.min(radiusPx, 20)}px`,
1046
1107
  "--wgt-card-radius": `${Math.min(radiusPx, 12)}px`,
1047
1108
  "--wgt-font": lookup({
@@ -1147,8 +1208,18 @@ var DESKTOP_GUTTER = 16;
1147
1208
  var BOTTOM_FLOOR = 10;
1148
1209
  /** Desktop bottom inset (§3.1). */
1149
1210
  var DESKTOP_BOTTOM = 16;
1150
- /** Gap between the sheet's floor and the row above it (§3.3). */
1151
- var SHEET_GAP = 8;
1211
+ /**
1212
+ * Gap between the sheet's floor and the row above it (§3.3).
1213
+ *
1214
+ * ZERO since 2026-09-11. The 8 px gap read as two unrelated boxes stacked on
1215
+ * a merchant's page rather than as one surface the concierge grew, which is
1216
+ * what §3.3's "a bottom sheet whose floor is the row" was always describing.
1217
+ * The constant stays rather than being deleted: it is the number the sheet's
1218
+ * `bottom` is written from, both renderers have to agree about it, and a
1219
+ * reader who finds `bottom: var(--wgt-row-h)` in the stylesheet needs
1220
+ * somewhere that says why there is nothing added to it.
1221
+ */
1222
+ var SHEET_GAP = 0;
1152
1223
  /** The one breakpoint. Below it the dock is full-width and thumb-anchored. */
1153
1224
  var DESKTOP_BREAKPOINT = 768;
1154
1225
  /**
@@ -1199,6 +1270,88 @@ var SHEET_TOP_CLEARANCE = 24;
1199
1270
  * storage key is two ways for one preference to be lost.
1200
1271
  */
1201
1272
  var DOCK_MINIMISED_STORAGE_KEY = "wgt_dock_minimised";
1273
+ /**
1274
+ * §9.1's `layout.draggable` — where a shopper's own horizontal position is
1275
+ * remembered, per visitor and per origin.
1276
+ *
1277
+ * Beside {@link DOCK_MINIMISED_STORAGE_KEY} and for the same reason: the core
1278
+ * dock reads it BEFORE first paint (so a returning shopper never watches the
1279
+ * dock slide across the page to where they left it) and the React dock writes
1280
+ * it when a drag settles. Two copies of a storage key is two ways for one
1281
+ * preference to be lost.
1282
+ */
1283
+ var DOCK_ALIGN_STORAGE_KEY = "wgt_dock_align";
1284
+ /**
1285
+ * Under this many pixels of travel, a press-and-release is a TAP (§9.1).
1286
+ *
1287
+ * Six rather than the sheet drag's four: the sheet's handle does nothing but
1288
+ * drag, so a hair-trigger costs nothing, while the pill and the mark are the
1289
+ * dock's two most-pressed controls and a mouse that travels three pixels
1290
+ * between press and release is a click in every other piece of software the
1291
+ * shopper uses. Below it the gesture never became a drag at all — no
1292
+ * alignment is written and the press's own click is left to run.
1293
+ */
1294
+ var DRAG_TAP_SLOP_PX = 6;
1295
+ /**
1296
+ * Where a released drag lands (§9.1): the third of the viewport the dock's
1297
+ * CENTRE finished in.
1298
+ *
1299
+ * Thirds rather than nearest-edge, because `center` is one of the three
1300
+ * answers and an edge-distance rule can never return it. Pure, and shared by
1301
+ * both renderers — the pill's drag is `cdn/dock-dom.ts`'s and the row's is
1302
+ * `dock/dock-drag.ts`'s, and a dock that snapped differently depending on
1303
+ * which one the shopper grabbed would be a bug nobody could describe.
1304
+ *
1305
+ * A degenerate viewport (0 wide, or a `NaN` centre from a `pointercancel`
1306
+ * that carried no coordinates) resolves to `center`: the tenant's own default,
1307
+ * and the only answer that cannot put the dock off the edge of the screen.
1308
+ */
1309
+ function snapAlign(centreX, viewportWidth) {
1310
+ if (!(viewportWidth > 0)) return "center";
1311
+ if (centreX < viewportWidth / 3) return "left";
1312
+ if (centreX > viewportWidth * 2 / 3) return "right";
1313
+ return "center";
1314
+ }
1315
+ /**
1316
+ * `localStorage`, wrapped once for the whole dock.
1317
+ *
1318
+ * Both preferences the dock remembers (§5.4's minimise, §9.1's alignment) are
1319
+ * read by `cdn/dock-dom.ts` before first paint and written by the React dock,
1320
+ * so four near-identical `try`/`catch` blocks were four copies of the same
1321
+ * three lines in an artefact every visitor to every merchant page downloads.
1322
+ *
1323
+ * The `try` is the load-bearing part and is not optional: `localStorage`
1324
+ * THROWS on access — not on use — in a third-party frame with storage access
1325
+ * blocked, in Safari's private mode past its quota, and behind a merchant's
1326
+ * own cookie wall. A dock that took the storefront's script down over a
1327
+ * remembered position is worse than a dock that forgets one.
1328
+ */
1329
+ function readStored(win, key) {
1330
+ try {
1331
+ return win.localStorage?.getItem(key) ?? void 0;
1332
+ } catch {
1333
+ return;
1334
+ }
1335
+ }
1336
+ function writeStored(win, key, value) {
1337
+ try {
1338
+ win.localStorage?.setItem(key, value);
1339
+ } catch {}
1340
+ }
1341
+ /**
1342
+ * The shopper's remembered alignment, or `undefined` where there is none.
1343
+ *
1344
+ * Anything that is not one of §9.1's three values is `undefined` rather than
1345
+ * a default: the key is on the MERCHANT's origin, shared with whatever else
1346
+ * their page stores, and a value we did not write is not a preference.
1347
+ */
1348
+ function readStoredAlign(win) {
1349
+ const raw = readStored(win, DOCK_ALIGN_STORAGE_KEY);
1350
+ return raw === "left" || raw === "center" || raw === "right" ? raw : void 0;
1351
+ }
1352
+ function persistAlign(win, align) {
1353
+ writeStored(win, DOCK_ALIGN_STORAGE_KEY, align);
1354
+ }
1202
1355
  /** §5.6 — how long a proactive nudge holds the row open before it recedes. */
1203
1356
  var PROACTIVE_NUDGE_MS = 8e3;
1204
1357
  /**
@@ -1365,6 +1518,104 @@ function useCrossFade(line, swapKey, durationMs) {
1365
1518
  }, [outgoing, durationMs]);
1366
1519
  return outgoing;
1367
1520
  }
1521
+ /**
1522
+ * "The browser is not painting this document."
1523
+ *
1524
+ * An absent `document` (SSR, a worker) is NOT hidden: the caller is asking
1525
+ * whether to skip an animation, and there is no animation to skip. Tolerant
1526
+ * of a partial `document` stub, which is what an embedded webview can hand a
1527
+ * widget that has no say in where it is loaded.
1528
+ */
1529
+ function isDocumentHidden(doc) {
1530
+ return (doc ?? (typeof document === "undefined" ? null : document))?.visibilityState === "hidden";
1531
+ }
1532
+ /**
1533
+ * Guarantees that one transition's end state lands, whether or not the
1534
+ * browser ever fires `transitionend` for it.
1535
+ *
1536
+ * @returns a handle whose `finish()`/`cancel()` are both idempotent. Callers
1537
+ * that can be superseded (a swap interrupting a swap) `cancel()` the previous
1538
+ * handle before opening a new one; callers that unmount `cancel()` in their
1539
+ * effect cleanup.
1540
+ */
1541
+ function finaliseTransition(options) {
1542
+ const { el, durationMs, endState, onFinalise } = options;
1543
+ const doc = options.doc ?? el.ownerDocument ?? null;
1544
+ const win = doc?.defaultView ?? null;
1545
+ let settled = false;
1546
+ let timer = null;
1547
+ /** Undoes the inline override written by `applyEndState`; null when none is outstanding. */
1548
+ let release = null;
1549
+ const onTransitionEnd = (event) => {
1550
+ if (event.target === el) finish();
1551
+ };
1552
+ const onVisibilityChange = () => finish();
1553
+ const detach = () => {
1554
+ if (timer !== null) clearTimeout(timer);
1555
+ timer = null;
1556
+ el.removeEventListener("transitionend", onTransitionEnd);
1557
+ doc?.removeEventListener?.("visibilitychange", onVisibilityChange);
1558
+ };
1559
+ /**
1560
+ * Write the end state, behind a `transition: none` that outlives this task.
1561
+ *
1562
+ * The override has to survive at least one frame to cancel a transition the
1563
+ * engine has already started — set and cleared inside one task it is not
1564
+ * observed at all, and the frozen transition keeps running. `requestAnimationFrame`
1565
+ * is the right clock for "one frame from now" and it is also the right one
1566
+ * for a hidden tab: a frame requested while hidden is not dropped, it runs
1567
+ * when the document is painted again, which is exactly when the element
1568
+ * needs to be handed back to the cascade.
1569
+ */
1570
+ const applyEndState = () => {
1571
+ const previousTransition = el.style.transition;
1572
+ el.style.transition = "none";
1573
+ if (endState) for (const property of Object.keys(endState)) el.style.setProperty(property, endState[property]);
1574
+ let released = false;
1575
+ release = () => {
1576
+ if (released) return;
1577
+ released = true;
1578
+ release = null;
1579
+ el.style.transition = previousTransition;
1580
+ if (!endState) return;
1581
+ for (const property of Object.keys(endState)) el.style.removeProperty(property);
1582
+ };
1583
+ const scheduled = release;
1584
+ if (typeof win?.requestAnimationFrame === "function") {
1585
+ win.requestAnimationFrame(() => scheduled());
1586
+ return;
1587
+ }
1588
+ setTimeout(() => scheduled(), 0);
1589
+ };
1590
+ function finish() {
1591
+ if (settled) return;
1592
+ settled = true;
1593
+ detach();
1594
+ applyEndState();
1595
+ onFinalise?.();
1596
+ }
1597
+ function cancel() {
1598
+ release?.();
1599
+ if (settled) return;
1600
+ settled = true;
1601
+ detach();
1602
+ }
1603
+ const handle = {
1604
+ finish,
1605
+ cancel,
1606
+ get settled() {
1607
+ return settled;
1608
+ }
1609
+ };
1610
+ if (options.immediate === true || durationMs <= 0 || isDocumentHidden(doc)) {
1611
+ finish();
1612
+ return handle;
1613
+ }
1614
+ el.addEventListener("transitionend", onTransitionEnd);
1615
+ doc?.addEventListener?.("visibilitychange", onVisibilityChange);
1616
+ timer = setTimeout(finish, durationMs + 100);
1617
+ return handle;
1618
+ }
1368
1619
  var SWAP_EASING = "cubic-bezier(0.2, 0, 0, 1)";
1369
1620
  /** §7.2 — the waveform's per-frame smoothing. */
1370
1621
  var LEVEL_LERP = .25;
@@ -1404,6 +1655,41 @@ function matchesReducedMotion() {
1404
1655
  return safeMatchMedia()?.matches === true;
1405
1656
  }
1406
1657
  /**
1658
+ * §7.1 rule 12 — `document.visibilityState`, as a subscription.
1659
+ *
1660
+ * A one-shot read at mount would be the wrong answer for the whole of the
1661
+ * rest of the visit, and the visit is where this matters: the shopper taps
1662
+ * the pill and then locks the phone. Both edges are reported, because both
1663
+ * change what the dock is allowed to do — hidden means "apply the end state,
1664
+ * animate nothing", visible means "a stalled transition, if there is one, has
1665
+ * to be finalised now".
1666
+ */
1667
+ function useDocumentHidden() {
1668
+ const [hidden, setHidden] = useState(() => isDocumentHidden());
1669
+ useEffect(() => {
1670
+ if (typeof document === "undefined") return;
1671
+ const onChange = () => setHidden(isDocumentHidden());
1672
+ onChange();
1673
+ document.addEventListener("visibilitychange", onChange);
1674
+ return () => document.removeEventListener("visibilitychange", onChange);
1675
+ }, []);
1676
+ return hidden;
1677
+ }
1678
+ /**
1679
+ * "Motion is off." §7.1 rule 10 and rule 12 in ONE read, because a surface
1680
+ * that has to remember two of them will eventually remember one.
1681
+ *
1682
+ * `prefers-reduced-motion` is a preference and a hidden tab is a fact, but
1683
+ * they ask the dock for the same thing: skip the animation, apply the end
1684
+ * state now. Every duration in {@link useDockDurations} collapses to 0, the
1685
+ * FLIP does not start, and the caption swaps in place.
1686
+ */
1687
+ function useMotionOff() {
1688
+ const reduced = usePrefersReducedMotion();
1689
+ const hidden = useDocumentHidden();
1690
+ return reduced || hidden;
1691
+ }
1692
+ /**
1407
1693
  * §7.1 rule 5 — a per-frame custom-property writer.
1408
1694
  *
1409
1695
  * Returns `set(name, value)`. Calls COALESCE: whatever the last value for a
@@ -1466,33 +1752,55 @@ function useCssVars(ref) {
1466
1752
  * the timer left the listener attached and `will-change` set on a node that
1467
1753
  * no longer renders, so the layer survived the component and the closure
1468
1754
  * survived with it.
1755
+ *
1756
+ * ## Why the promotion is not the only thing this arms (§7.1 rule 12)
1757
+ *
1758
+ * The `transitionend` this waits for never arrives in a hidden tab, and a
1759
+ * sheet whose reveal was interrupted by a lock screen is not merely a layer
1760
+ * left promoted — it is a `visibility: hidden` box that the shopper cannot
1761
+ * see or reach. `arm(endState)` therefore hands the whole finalisation to
1762
+ * `motion-gate.ts`: the fallback timer, the `visibilitychange` edge, and the
1763
+ * explicit end state the surface passes in. Armed while the tab is already
1764
+ * hidden (or with a zeroed duration), it promotes nothing at all and applies
1765
+ * that end state synchronously — there is no animation to give a layer to.
1469
1766
  */
1470
1767
  function useTransientWillChange(ref, properties = "transform, opacity", ms = 240) {
1471
- const timer = useRef(null);
1472
- /** Undoes whatever arming is currently live — null when nothing is armed. */
1473
- const disarm = useRef(null);
1768
+ /** The finalisation currently in flight — null when nothing is armed. */
1769
+ const pending = useRef(null);
1770
+ /**
1771
+ * The element the promotion was written on, held separately from `ref`.
1772
+ *
1773
+ * Unmount is the third way out and it used to be the leaky one. React may
1774
+ * have detached `ref` by the time this effect's cleanup runs, and a
1775
+ * `will-change` left on a detached node keeps its layer alive for as long
1776
+ * as anything still points at the node — which is precisely what rule 4
1777
+ * forbids.
1778
+ */
1779
+ const armed = useRef(null);
1474
1780
  useEffect(() => () => {
1475
- disarm.current?.();
1476
- if (timer.current !== null) clearTimeout(timer.current);
1477
- timer.current = null;
1781
+ pending.current?.cancel();
1782
+ pending.current = null;
1783
+ if (armed.current) armed.current.style.willChange = "";
1784
+ armed.current = null;
1478
1785
  }, []);
1479
- return useCallback(() => {
1786
+ return useCallback((endState) => {
1480
1787
  const el = ref.current;
1481
1788
  if (!el) return;
1482
- disarm.current?.();
1483
- el.style.willChange = properties;
1484
- const clear = (event) => {
1485
- if (event && event.target !== el) return;
1486
- el.style.willChange = "";
1487
- el.removeEventListener("transitionend", clear);
1488
- if (timer.current !== null) clearTimeout(timer.current);
1489
- timer.current = null;
1490
- disarm.current = null;
1491
- };
1492
- disarm.current = () => clear();
1493
- el.addEventListener("transitionend", clear);
1494
- if (timer.current !== null) clearTimeout(timer.current);
1495
- timer.current = setTimeout(clear, ms + 60);
1789
+ pending.current?.cancel();
1790
+ pending.current = null;
1791
+ if (ms > 0 && !isDocumentHidden(el.ownerDocument)) {
1792
+ el.style.willChange = properties;
1793
+ armed.current = el;
1794
+ }
1795
+ pending.current = finaliseTransition({
1796
+ el,
1797
+ durationMs: ms,
1798
+ endState,
1799
+ onFinalise: () => {
1800
+ el.style.willChange = "";
1801
+ armed.current = null;
1802
+ }
1803
+ });
1496
1804
  }, [
1497
1805
  ref,
1498
1806
  properties,
@@ -1530,6 +1838,63 @@ function lerp(current, target, factor = LEVEL_LERP) {
1530
1838
  return current + (target - current) * factor;
1531
1839
  }
1532
1840
  /**
1841
+ * §7.2's two forms at rest, as the inline properties a §7.1 rule 12
1842
+ * finalisation writes.
1843
+ *
1844
+ * These MIRROR `.wgt-row[data-form='pill']` and `.wgt-pill[data-form='row']`
1845
+ * in `styles/concierge.css` — the cascade is still what draws the dock, and
1846
+ * this table is only ever written for the one frame in which a stalled
1847
+ * transition is being cancelled. `dock-motion.test.ts` reads the stylesheet
1848
+ * and asserts the two agree, because a divergence here is invisible until a
1849
+ * shopper locks their phone mid-swap and comes back to a dock in the wrong
1850
+ * shape.
1851
+ */
1852
+ var FORM_END_STATE = {
1853
+ /** Either form, showing. The base rule for both boxes. */
1854
+ shown: {
1855
+ visibility: "visible",
1856
+ opacity: "1",
1857
+ transform: "none"
1858
+ },
1859
+ /** `.wgt-pill[data-form='row']`. */
1860
+ pillHidden: {
1861
+ visibility: "hidden",
1862
+ opacity: "0",
1863
+ transform: "scale(0.92)"
1864
+ },
1865
+ /** `.wgt-row[data-form='pill']`. */
1866
+ rowHidden: {
1867
+ visibility: "hidden",
1868
+ opacity: "0",
1869
+ transform: "scale(0.98)"
1870
+ }
1871
+ };
1872
+ /**
1873
+ * §3.3's sheet at each end of its reveal, as the inline properties a §7.1
1874
+ * rule 12 finalisation writes.
1875
+ *
1876
+ * Mirrors `.wgt-sheet` and `.wgt-sheet[data-snap='closed']` in
1877
+ * `styles/concierge.css`, and `dock-motion.test.ts` asserts they agree. The
1878
+ * open state keeps `transform` expressed through `--wgt-sheet-y` rather than
1879
+ * as a resolved `translateY(0px)`: the drag writes that custom property once
1880
+ * per frame (§7.1 rule 5), and a finaliser that resolved it would pin the
1881
+ * sheet to wherever the last gesture left it.
1882
+ */
1883
+ var SHEET_END_STATE = {
1884
+ open: {
1885
+ visibility: "visible",
1886
+ opacity: "1",
1887
+ "clip-path": "inset(0 0 0 0)",
1888
+ transform: "translateY(var(--wgt-sheet-y, 0px))"
1889
+ },
1890
+ closed: {
1891
+ visibility: "hidden",
1892
+ opacity: "0",
1893
+ "clip-path": "inset(100% 0 0 0)",
1894
+ transform: "translateY(8px)"
1895
+ }
1896
+ };
1897
+ /**
1533
1898
  * The pill ↔ row swap (§7.2), driven by whichever box is showing.
1534
1899
  *
1535
1900
  * Both boxes exist at all times — the swap is a VISIBILITY change, never a
@@ -1538,42 +1903,114 @@ function lerp(current, target, factor = LEVEL_LERP) {
1538
1903
  * the change puts the incoming one back where the outgoing one was and
1539
1904
  * releases it. One layout read, one style write, no host reflow.
1540
1905
  *
1541
- * Under reduced motion it does nothing at all: §7.1 rule 10, and the state is
1542
- * always also in text (the live region), so nothing is lost.
1906
+ * Under reduced motion, or in a hidden tab, it does nothing at all but write
1907
+ * both end states: §7.1 rules 10 and 12, and the state is always also in text
1908
+ * (the live region), so nothing is lost. `motionOff` is the caller's single
1909
+ * read of both (see {@link useMotionOff}).
1910
+ *
1911
+ * ## The FLIP is not the only thing being finalised here
1912
+ *
1913
+ * The WAAPI animation below is the cross-fade's TRAVEL. The cross-fade
1914
+ * itself — `opacity`, `transform`, and the `visibility` that takes the
1915
+ * outgoing form out of the tab order — is a CSS transition on both elements,
1916
+ * driven by `data-form`, and it is the one that froze on production: a hidden
1917
+ * tab left `.wgt-row` at `opacity: 0.6`, `visibility: hidden` with the pill
1918
+ * hidden too, so there was nothing on screen to tap. Each form therefore gets
1919
+ * its own finaliser, with its own end state, on every swap.
1543
1920
  */
1544
- function useFormFlip(pillRef, rowRef, form, reducedMotion, durationMs = 240) {
1921
+ function useFormFlip(pillRef, rowRef, form, motionOff, durationMs = 240) {
1545
1922
  const previous = useRef(form);
1923
+ /**
1924
+ * The swap currently being finalised, held across effect runs rather than
1925
+ * torn down by each one.
1926
+ *
1927
+ * This hook's dependencies change on the very `visibilitychange` that
1928
+ * finalises the swap — `useMotionOff` is subscribed to that event and every
1929
+ * duration in {@link useDockDurations} collapses with it — so an effect
1930
+ * cleanup that cancelled the finalisers would take the end state back off
1931
+ * in the SAME TASK it was written in. The one-frame `transition: none` is
1932
+ * the whole mechanism (it is what cancels a transition the engine has
1933
+ * frozen), and an override set and cleared inside one task is never
1934
+ * observed at all. So: a NEW swap supersedes the old one, a dependency
1935
+ * change with no swap behind it finalises rather than discards, and only an
1936
+ * unmount cancels.
1937
+ */
1938
+ const inFlight = useRef([]);
1939
+ const running = useRef(void 0);
1940
+ useEffect(() => () => {
1941
+ running.current?.cancel();
1942
+ running.current = void 0;
1943
+ for (const finaliser of inFlight.current) finaliser.cancel();
1944
+ inFlight.current = [];
1945
+ }, []);
1546
1946
  useEffect(() => {
1547
1947
  const was = previous.current;
1548
1948
  previous.current = form;
1549
- if (was === form || reducedMotion || durationMs <= 0) return;
1550
- const outgoing = was === "pill" ? pillRef.current : rowRef.current;
1551
- const incoming = form === "pill" ? pillRef.current : rowRef.current;
1552
- if (!outgoing || !incoming || typeof incoming.getBoundingClientRect !== "function") return;
1553
- const transform = flipTransform(outgoing.getBoundingClientRect(), incoming.getBoundingClientRect());
1554
- if (transform === "none") return;
1555
- const animation = incoming.animate?.([{
1556
- transform,
1557
- opacity: .6
1558
- }, {
1559
- transform: "none",
1560
- opacity: 1
1561
- }], {
1562
- duration: durationMs,
1563
- easing: SWAP_EASING,
1564
- fill: "none"
1565
- });
1566
- return () => animation?.cancel();
1949
+ if (was === form) {
1950
+ if (motionOff || durationMs <= 0) for (const finaliser of inFlight.current) finaliser.finish();
1951
+ return;
1952
+ }
1953
+ running.current?.cancel();
1954
+ running.current = void 0;
1955
+ for (const finaliser of inFlight.current) finaliser.cancel();
1956
+ inFlight.current = [];
1957
+ const pill = pillRef.current;
1958
+ const row = rowRef.current;
1959
+ const outgoing = was === "pill" ? pill : row;
1960
+ const incoming = form === "pill" ? pill : row;
1961
+ const immediate = motionOff || durationMs <= 0 || isDocumentHidden((pill ?? row)?.ownerDocument);
1962
+ let animation;
1963
+ const finishAnimation = () => {
1964
+ try {
1965
+ animation?.finish();
1966
+ } catch {}
1967
+ };
1968
+ const finalisers = [];
1969
+ if (pill) finalisers.push(finaliseTransition({
1970
+ el: pill,
1971
+ durationMs,
1972
+ immediate,
1973
+ onFinalise: finishAnimation,
1974
+ endState: form === "pill" ? FORM_END_STATE.shown : FORM_END_STATE.pillHidden
1975
+ }));
1976
+ if (row) finalisers.push(finaliseTransition({
1977
+ el: row,
1978
+ durationMs,
1979
+ immediate,
1980
+ onFinalise: finishAnimation,
1981
+ endState: form === "row" ? FORM_END_STATE.shown : FORM_END_STATE.rowHidden
1982
+ }));
1983
+ if (!immediate && outgoing && incoming && typeof incoming.getBoundingClientRect === "function") {
1984
+ const transform = flipTransform(outgoing.getBoundingClientRect(), incoming.getBoundingClientRect());
1985
+ if (transform !== "none") animation = incoming.animate?.([{
1986
+ transform,
1987
+ opacity: .6
1988
+ }, {
1989
+ transform: "none",
1990
+ opacity: 1
1991
+ }], {
1992
+ duration: durationMs,
1993
+ easing: SWAP_EASING,
1994
+ fill: "none"
1995
+ });
1996
+ }
1997
+ inFlight.current = finalisers;
1998
+ running.current = animation;
1567
1999
  }, [
1568
2000
  form,
1569
- reducedMotion,
2001
+ motionOff,
1570
2002
  pillRef,
1571
2003
  rowRef,
1572
2004
  durationMs
1573
2005
  ]);
1574
2006
  }
1575
- function useDockDurations(reducedMotion) {
1576
- return useMemo(() => reducedMotion ? {
2007
+ /**
2008
+ * @param motionOff §7.1 rule 10 (`prefers-reduced-motion`) OR rule 12 (the
2009
+ * tab is hidden and the browser will not advance a transition in it). See
2010
+ * {@link useMotionOff}, which is how every caller reads both at once.
2011
+ */
2012
+ function useDockDurations(motionOff) {
2013
+ return useMemo(() => motionOff ? {
1577
2014
  swap: 0,
1578
2015
  recede: 0,
1579
2016
  sheetOpen: 0,
@@ -1591,7 +2028,200 @@ function useDockDurations(reducedMotion) {
1591
2028
  caption: 160,
1592
2029
  border: 160,
1593
2030
  control: 120
1594
- }, [reducedMotion]);
2031
+ }, [motionOff]);
2032
+ }
2033
+ //#endregion
2034
+ //#region src/dock/dock-drag.ts
2035
+ /** The one custom property a drag writes (§7.1 rule 5). */
2036
+ var DRAG_VAR = "--wgt-drag-x";
2037
+ function useDockDrag(containerRef, { enabled, published, win, durationMs, pillRef }) {
2038
+ const [stored, setStored] = useState(void 0);
2039
+ const align = (enabled ? stored : void 0) ?? published;
2040
+ /**
2041
+ * The stored alignment is read AFTER MOUNT, in a layout effect, and never
2042
+ * in a `useState` initialiser.
2043
+ *
2044
+ * The initialiser was gated on `enabled`, and `enabled` is false on the
2045
+ * HYDRATION render of every server-rendered host: `useViewport`'s
2046
+ * `useSyncExternalStore` server snapshots are hard-coded `false` (§1 rule 8
2047
+ * — a hydration mismatch on those booleans throws the dock's whole subtree
2048
+ * away), so `isDesktop` and `finePointer` are both false on the render the
2049
+ * initialiser runs in. Nothing re-read it afterwards, so the marketing
2050
+ * preview, the console preview and every npm consumer pinned the shopper's
2051
+ * remembered position `undefined` for the life of the mount — while still
2052
+ * happily WRITING to the same key on every drop. The same hole swallowed
2053
+ * the CDN path whenever the window started under 768 px and was widened
2054
+ * mid-session.
2055
+ *
2056
+ * A LAYOUT effect rather than an ordinary one, because `cdn/dock-dom.ts`
2057
+ * applies this value before its first paint (see that file's `storedAlign`)
2058
+ * and §4.2 gives the handover one frame to disagree in: read after the
2059
+ * paint, the React dock would start at the tenant's alignment and slide to
2060
+ * the shopper's in front of them. `flipFrom` is null on this path, so the
2061
+ * adoption commits the anchor with no settle animation, which is what an
2062
+ * alignment that was never dragged should look like.
2063
+ *
2064
+ * `enabled` still gates the READ as well as the gesture. A tenant who
2065
+ * turned dragging off may have turned it off BECAUSE of where a shopper
2066
+ * could put it, and a remembered position that outlives the setting which
2067
+ * allowed it is a setting that does not work.
2068
+ */
2069
+ useLayoutEffect(() => {
2070
+ if (!enabled || !win) return;
2071
+ const remembered = readStoredAlign(win);
2072
+ if (remembered !== void 0) setStored(remembered);
2073
+ }, [enabled, win]);
2074
+ const drag = useRef(null);
2075
+ const movedLast = useRef(false);
2076
+ /** Where the container's left edge was at the instant of release — rule 4's FLIP. */
2077
+ const flipFrom = useRef(null);
2078
+ /** Where the PILL's left edge was at the same instant — rule 4's other half. */
2079
+ const pillFlipFrom = useRef(null);
2080
+ const write = useCallback((value) => containerRef.current?.style.setProperty(DRAG_VAR, value), [containerRef]);
2081
+ /**
2082
+ * Rule 4, in the commit that moved the anchor.
2083
+ *
2084
+ * `useLayoutEffect` rather than an effect: this runs BEFORE the browser
2085
+ * paints the new anchor, so the shopper never sees the frame where the dock
2086
+ * has jumped. One frame later the transform is animated away, and the
2087
+ * `data-settling` attribute is what turns the transition on — the container
2088
+ * cannot simply carry one, because `--wgt-kb` rides on the same `transform`
2089
+ * and §7.2 gives the keyboard offset "continuous, no easing".
2090
+ */
2091
+ useLayoutEffect(() => {
2092
+ const el = containerRef.current;
2093
+ const from = flipFrom.current;
2094
+ const pillFrom = pillFlipFrom.current;
2095
+ flipFrom.current = null;
2096
+ pillFlipFrom.current = null;
2097
+ if (!el || from === null) return;
2098
+ const applied = Number.parseFloat(el.style.getPropertyValue("--wgt-drag-x")) || 0;
2099
+ const dx = from - (el.getBoundingClientRect().left - applied);
2100
+ const pill = pillRef?.current ?? null;
2101
+ const pillDx = pill && pillFrom !== null ? pillFrom - (pill.getBoundingClientRect().left - applied + dx) : 0;
2102
+ if (pill && Math.abs(pillDx) >= .5 && durationMs > 0) pill.animate?.([{ transform: `translateX(${pillDx}px)` }, { transform: "none" }], {
2103
+ duration: durationMs,
2104
+ easing: SWAP_EASING,
2105
+ fill: "none"
2106
+ });
2107
+ if (dx === 0 || durationMs === 0) {
2108
+ write("0px");
2109
+ return;
2110
+ }
2111
+ write(`${dx}px`);
2112
+ el.setAttribute("data-settling", "true");
2113
+ const raf = typeof requestAnimationFrame === "function" ? requestAnimationFrame(() => write("0px")) : (write("0px"), 0);
2114
+ const timer = setTimeout(() => {
2115
+ el.removeAttribute("data-settling");
2116
+ write("0px");
2117
+ }, durationMs + 100);
2118
+ return () => {
2119
+ if (raf) cancelAnimationFrame(raf);
2120
+ clearTimeout(timer);
2121
+ el.removeAttribute("data-settling");
2122
+ };
2123
+ }, [
2124
+ align,
2125
+ containerRef,
2126
+ durationMs,
2127
+ pillRef,
2128
+ write
2129
+ ]);
2130
+ const settle = useCallback((endX) => {
2131
+ const state = drag.current;
2132
+ drag.current = null;
2133
+ const el = containerRef.current;
2134
+ if (!state || !el || !win) return;
2135
+ el.removeAttribute("data-dragging");
2136
+ movedLast.current = state.moved;
2137
+ if (!state.moved) {
2138
+ write("0px");
2139
+ return;
2140
+ }
2141
+ const rect = el.getBoundingClientRect();
2142
+ const next = snapAlign(rect.left + rect.width / 2, win.innerWidth || 0);
2143
+ flipFrom.current = rect.left;
2144
+ pillFlipFrom.current = pillRef?.current?.getBoundingClientRect().left ?? null;
2145
+ persistAlign(win, next);
2146
+ setStored(next);
2147
+ if (next === align) {
2148
+ flipFrom.current = null;
2149
+ pillFlipFrom.current = null;
2150
+ write("0px");
2151
+ }
2152
+ }, [
2153
+ align,
2154
+ containerRef,
2155
+ pillRef,
2156
+ win,
2157
+ write
2158
+ ]);
2159
+ /**
2160
+ * The three listeners the press in flight has armed, so an UNMOUNT can take
2161
+ * them off.
2162
+ *
2163
+ * `onEnd` disarms them itself on `pointerup`/`pointercancel`, which is every
2164
+ * way a gesture ends — but not every way this hook ends. A dock unmounted
2165
+ * mid-drag (the host swaps routes, the merchant's SPA tears the mount point
2166
+ * down, a test unmounts between cases) left three listeners on the WINDOW
2167
+ * closed over a detached container, for the life of the page.
2168
+ */
2169
+ const armed = useRef(null);
2170
+ useEffect(() => () => {
2171
+ armed.current?.();
2172
+ armed.current = null;
2173
+ }, []);
2174
+ const onPointerDown = useCallback((event) => {
2175
+ const el = containerRef.current;
2176
+ if (!el || !win || event.button > 0 || drag.current !== null) return;
2177
+ movedLast.current = false;
2178
+ drag.current = {
2179
+ startX: event.clientX,
2180
+ lastX: event.clientX,
2181
+ moved: false
2182
+ };
2183
+ const onMove = (native) => {
2184
+ const state = drag.current;
2185
+ const x = native.clientX;
2186
+ if (!state || !Number.isFinite(x)) return;
2187
+ state.lastX = x;
2188
+ const dx = x - state.startX;
2189
+ if (Math.abs(dx) >= 6) {
2190
+ state.moved = true;
2191
+ el.setAttribute("data-dragging", "true");
2192
+ }
2193
+ if (state.moved) write(`${dx}px`);
2194
+ };
2195
+ const disarm = () => {
2196
+ armed.current = null;
2197
+ win.removeEventListener("pointermove", onMove);
2198
+ win.removeEventListener("pointerup", onEnd);
2199
+ win.removeEventListener("pointercancel", onEnd);
2200
+ };
2201
+ const onEnd = (native) => {
2202
+ disarm();
2203
+ settle(native.clientX ?? NaN);
2204
+ };
2205
+ armed.current?.();
2206
+ win.addEventListener("pointermove", onMove, { passive: true });
2207
+ win.addEventListener("pointerup", onEnd, { passive: true });
2208
+ win.addEventListener("pointercancel", onEnd, { passive: true });
2209
+ armed.current = disarm;
2210
+ }, [
2211
+ containerRef,
2212
+ settle,
2213
+ win,
2214
+ write
2215
+ ]);
2216
+ return {
2217
+ align,
2218
+ consumeClick: useCallback(() => {
2219
+ if (!movedLast.current) return false;
2220
+ movedLast.current = false;
2221
+ return true;
2222
+ }, []),
2223
+ handleProps: enabled ? { onPointerDown } : {}
2224
+ };
1595
2225
  }
1596
2226
  //#endregion
1597
2227
  //#region src/dock/dock-row.tsx
@@ -1665,7 +2295,7 @@ function DockActivitySlot({ activity }) {
1665
2295
  }, i)) : activity === "progress" ? /* @__PURE__ */ jsx("span", { className: "wgt-progress" }) : null
1666
2296
  });
1667
2297
  }
1668
- function DockRow({ view, identity, form, messages, captionLine, captionSwapKey, captionTestId, draft, onDraftChange, onSubmit, placeholder, composerDisabled, onControl, onMicDown, onMicUp, interruptLabelled, micOpen, micDisabled, micUnavailableReason, attachBusy, rowRef, inputRef, captionDurationMs, markStateLabel, onMarkPress }) {
2298
+ function DockRow({ view, identity, form, messages, captionLine, captionSwapKey, captionTestId, draft, onDraftChange, onSubmit, placeholder, composerDisabled, onControl, onMicDown, onMicUp, interruptLabelled, micOpen, micDisabled, micUnavailableReason, attachBusy, rowRef, inputRef, captionDurationMs, markStateLabel, onMarkPress, sheetOpen, draggable, dragHandleProps }) {
1669
2299
  const msg = (key, vars) => formatMessage(messages[key] ?? defaultWidgetMessages[key], vars);
1670
2300
  /**
1671
2301
  * §5.1 — tap anywhere on the row during `speaking` is an interrupt. A press
@@ -1684,6 +2314,8 @@ function DockRow({ view, identity, form, messages, captionLine, captionSwapKey,
1684
2314
  "data-state": view.state,
1685
2315
  "data-border": view.border,
1686
2316
  "data-form": form,
2317
+ "data-sheet": sheetOpen ? "open" : "closed",
2318
+ "data-draggable": draggable ? "true" : void 0,
1687
2319
  "data-testid": "widget-dock-row",
1688
2320
  onClick: onRowClick,
1689
2321
  children: [
@@ -1692,6 +2324,7 @@ function DockRow({ view, identity, form, messages, captionLine, captionSwapKey,
1692
2324
  className: "wgt-mark",
1693
2325
  "data-dock-slot": "mark",
1694
2326
  "aria-label": markStateLabel,
2327
+ ...draggable ? dragHandleProps : {},
1695
2328
  onClick: onMarkPress,
1696
2329
  children: /* @__PURE__ */ jsx(DockMarkFace, {
1697
2330
  identity,
@@ -1945,7 +2578,7 @@ function ClipGlyph() {
1945
2578
  }
1946
2579
  //#endregion
1947
2580
  //#region src/dock/dock-pill.tsx
1948
- function DockPill({ identity, mark, label, line, expandLabel, form, onPress, pillRef }) {
2581
+ function DockPill({ identity, mark, label, line, expandLabel, form, onPress, draggable, dragHandleProps, pillRef }) {
1949
2582
  const text = line !== void 0 && line !== "" ? line : label;
1950
2583
  return /* @__PURE__ */ jsxs("button", {
1951
2584
  ref: pillRef,
@@ -1955,7 +2588,9 @@ function DockPill({ identity, mark, label, line, expandLabel, form, onPress, pil
1955
2588
  "data-concierge-open": "",
1956
2589
  "data-form": form,
1957
2590
  "data-testid": "widget-dock-pill",
2591
+ "data-draggable": draggable ? "true" : void 0,
1958
2592
  "aria-label": `${label} — ${expandLabel}`,
2593
+ ...draggable ? dragHandleProps : {},
1959
2594
  onClick: onPress,
1960
2595
  children: [/* @__PURE__ */ jsx(DockMarkFace, {
1961
2596
  identity,
@@ -1973,7 +2608,7 @@ function DockPill({ identity, mark, label, line, expandLabel, form, onPress, pil
1973
2608
  var EXPAND_DRAG_PX = 40;
1974
2609
  /** Below this, the pointer never left the tap — a thumb resting, not a drag. */
1975
2610
  var DRAG_SLOP_PX = 4;
1976
- function DockSheet({ snap, onSnapChange, label, peekOnly, header, children, onDismiss, followKey, sheetRef, durationMs, dragHandleLabel }) {
2611
+ function DockSheet({ snap, onSnapChange, label, peekOnly, header, children, onDismiss, followKey, historyRevealed = false, sheetRef, durationMs, dragHandleLabel }) {
1977
2612
  const localRef = useRef(null);
1978
2613
  const ref = sheetRef ?? localRef;
1979
2614
  const bodyRef = useRef(null);
@@ -2003,6 +2638,11 @@ function DockSheet({ snap, onSnapChange, label, peekOnly, header, children, onDi
2003
2638
  * precisely when a reader who has scrolled away must be left alone.
2004
2639
  */
2005
2640
  const rowCount = useRef(-1);
2641
+ /**
2642
+ * Whether the last follow ran on the WHOLE transcript — see
2643
+ * {@link DockSheetProps.historyRevealed}.
2644
+ */
2645
+ const revealed = useRef(historyRevealed);
2006
2646
  const onScroll = useCallback(() => {
2007
2647
  const el = bodyRef.current;
2008
2648
  if (!el) return;
@@ -2012,16 +2652,18 @@ function DockSheet({ snap, onSnapChange, label, peekOnly, header, children, onDi
2012
2652
  const el = bodyRef.current;
2013
2653
  if (!el || snap === "closed") return;
2014
2654
  const anchorCount = el.querySelectorAll("[data-dock-follow]").length;
2015
- const grew = anchorCount > rowCount.current && rowCount.current >= 0;
2655
+ const justRevealed = historyRevealed && !revealed.current;
2656
+ revealed.current = historyRevealed;
2657
+ const grew = anchorCount !== rowCount.current && rowCount.current >= 0;
2016
2658
  rowCount.current = anchorCount;
2017
- if (grew) following.current = true;
2659
+ if (grew || justRevealed) following.current = true;
2018
2660
  if (!following.current) return;
2019
2661
  const settle = () => {
2020
2662
  const anchors = el.querySelectorAll("[data-dock-follow]");
2021
2663
  const newest = anchors[anchors.length - 1];
2022
2664
  const end = Math.max(0, el.scrollHeight - el.clientHeight);
2023
2665
  const before = el.scrollTop;
2024
- el.scrollTop = newest === void 0 ? end : Math.max(0, Math.min(end, el.scrollTop + (newest.getBoundingClientRect().top - el.getBoundingClientRect().top)));
2666
+ el.scrollTop = newest === void 0 || justRevealed ? end : Math.max(0, Math.min(end, el.scrollTop + (newest.getBoundingClientRect().top - el.getBoundingClientRect().top)));
2025
2667
  return Math.abs(el.scrollTop - before);
2026
2668
  };
2027
2669
  settle();
@@ -2032,14 +2674,22 @@ function DockSheet({ snap, onSnapChange, label, peekOnly, header, children, onDi
2032
2674
  if (settle() > .5 && passes < 4) raf = requestAnimationFrame(again);
2033
2675
  });
2034
2676
  return () => cancelAnimationFrame(raf);
2035
- }, [followKey, snap]);
2677
+ }, [
2678
+ followKey,
2679
+ snap,
2680
+ historyRevealed
2681
+ ]);
2682
+ const lastSnap = useRef(snap);
2036
2683
  const firstSnap = useRef(true);
2037
2684
  useEffect(() => {
2038
2685
  if (firstSnap.current) {
2039
2686
  firstSnap.current = false;
2687
+ lastSnap.current = snap;
2040
2688
  return;
2041
2689
  }
2042
- armWillChange();
2690
+ if (lastSnap.current === snap) return;
2691
+ lastSnap.current = snap;
2692
+ armWillChange(snap === "closed" ? SHEET_END_STATE.closed : SHEET_END_STATE.open);
2043
2693
  }, [snap, armWillChange]);
2044
2694
  /**
2045
2695
  * A drag that can never END.
@@ -2837,6 +3487,43 @@ function deriveView(input) {
2837
3487
  }
2838
3488
  }
2839
3489
  }
3490
+ /**
3491
+ * §3.4 (revised 2026-09-11) — where the LATEST EXCHANGE begins.
3492
+ *
3493
+ * An exchange is the shopper's line and the reply to it. The latest one
3494
+ * therefore starts at the LAST caller turn and runs to the end, so a reply
3495
+ * that arrived as three turns (a filler, the answer, the cards) stays whole.
3496
+ *
3497
+ * Two cases are not that shape and both are real:
3498
+ *
3499
+ * - the shopper has not spoken yet. The concierge opens with a greeting of
3500
+ * its own, and a proactive nudge can add a second line before anybody has
3501
+ * typed; the latest exchange is then the LAST agent turn alone, because
3502
+ * two unanswered agent lines are two things said, not one exchange.
3503
+ * - a `speaker: 'event'` row — §3.4's handoff marker. It is something that
3504
+ * happened TO an exchange rather than a turn in one, so it never starts a
3505
+ * new one and never ends the search for the caller line above it.
3506
+ */
3507
+ function latestExchangeStart(speakers) {
3508
+ for (let i = speakers.length - 1; i >= 0; i--) if (speakers[i] === "caller") return i;
3509
+ return Math.max(0, speakers.length - 1);
3510
+ }
3511
+ /**
3512
+ * How many exchanges the transcript holds — the number "Show conversation"
3513
+ * is offered on (§3.4: the control exists only when there is more than one).
3514
+ *
3515
+ * A caller line opens an exchange; anything said BEFORE the first one (the
3516
+ * greeting, a proactive nudge) is an exchange of its own, because it is
3517
+ * something the shopper can scroll back to and would otherwise be counted as
3518
+ * nothing at all — leaving a dock that shows a greeting, then an answer, and
3519
+ * claims there is nothing more to see.
3520
+ */
3521
+ function exchangeCount(speakers) {
3522
+ if (speakers.length === 0) return 0;
3523
+ const opened = speakers.findIndex((s) => s === "caller");
3524
+ if (opened === -1) return speakers.length;
3525
+ return speakers.filter((s) => s === "caller").length + (opened === 0 ? 0 : 1);
3526
+ }
2840
3527
  //#endregion
2841
3528
  //#region src/dock/dock.tsx
2842
3529
  var DEFAULT_COLOR = {
@@ -2855,16 +3542,33 @@ var DEFAULT_LAYOUT = {
2855
3542
  };
2856
3543
  var INTERRUPT_SEEN_STORAGE_KEY = "wgt_dock_interrupt_seen";
2857
3544
  function Dock(props) {
2858
- const { identity, color = DEFAULT_COLOR, type = DEFAULT_TYPE, layout = DEFAULT_LAYOUT, copy = {}, direction = "ltr", locale = "en", messages = defaultWidgetMessages, voice, escalated = false, offline = false, status, notice, statusKind, operatorLine, reconnecting = false, roomDropped = false, partialTranscript, preamble, clause, channel = "text", shelf, transcript, sheetExtra, followKey, revealSheet = false, showPrice = true, cardImageAspect = DEFAULT_CARD_ASPECT, bottomOffset = "auto", curationHref, productHref, navigate, draft, onDraftChange, onSubmit, composerDisabled = false, onAttach, attachSlot, attachBusy, proactive, pageKey, onEndCall, skinStyle, skin, preview = false, announcement, attribution, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady } = props;
3545
+ const { identity, color = DEFAULT_COLOR, type = DEFAULT_TYPE, layout = DEFAULT_LAYOUT, copy = {}, direction = "ltr", locale = "en", messages = defaultWidgetMessages, voice, escalated = false, offline = false, status, notice, statusKind, operatorLine, reconnecting = false, roomDropped = false, partialTranscript, preamble, clause, channel = "text", shelf, transcript, latestExchange, exchangeCount, sheetExtra, followKey, revealSheet = false, showPrice = true, cardImageAspect = DEFAULT_CARD_ASPECT, bottomOffset = "auto", curationHref, productHref, navigate, draft, onDraftChange, onSubmit, composerDisabled = false, onAttach, attachSlot, attachBusy, proactive, pageKey, onEndCall, skinStyle, skin, preview = false, announcement, attribution, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady } = props;
2859
3546
  const scopeId = useId().replace(/[^a-zA-Z0-9_-]/g, "");
2860
3547
  const rootRef = useRef(null);
2861
3548
  const rowRef = useRef(null);
2862
3549
  const pillRef = useRef(null);
2863
3550
  const inputRef = useRef(null);
2864
3551
  const setVar = useCssVars(rootRef);
2865
- const reducedMotion = usePrefersReducedMotion();
2866
- const durations = useDockDurations(reducedMotion);
2867
- const { isDesktop, shortViewport } = useViewport(rootRef);
3552
+ const motionOff = useMotionOff();
3553
+ const durations = useDockDurations(motionOff);
3554
+ const { isDesktop, shortViewport, finePointer, win } = useViewport(rootRef);
3555
+ /**
3556
+ * §9.1's `layout.draggable` — desktop only, a real pointer only, and the
3557
+ * tenant's own switch on top.
3558
+ *
3559
+ * Defaulted `true` rather than required, because the config field is
3560
+ * younger than this component: a host still passing a `layout` without it
3561
+ * (the marketing preview, a Next.js embed pinned to an older config) gets
3562
+ * §9.1's default rather than a dock that refuses to move.
3563
+ */
3564
+ const draggable = isDesktop && finePointer && layout.draggable !== false;
3565
+ const dragging = useDockDrag(rootRef, {
3566
+ enabled: draggable,
3567
+ published: layout.desktopAlign,
3568
+ win,
3569
+ durationMs: durations.swap,
3570
+ pillRef
3571
+ });
2868
3572
  const msg = useCallback((key, vars) => formatMessage(messages[key] ?? defaultWidgetMessages[key], vars), [messages]);
2869
3573
  const name = identity.name?.trim() || "Concierge";
2870
3574
  const [form, setForm] = useState(() => layout.minimised === "never" ? "row" : initialMinimised ?? layout.minimised === "startMinimised" ? "pill" : "row");
@@ -2887,6 +3591,16 @@ function Dock(props) {
2887
3591
  const [sheetEverOpened, setSheetEverOpened] = useState(false);
2888
3592
  const [ducked, setDucked] = useState(false);
2889
3593
  const [showTranscript, setShowTranscript] = useState(false);
3594
+ /**
3595
+ * §3.4 — the shopper asked for the whole conversation, so the sheet holds
3596
+ * the transcript rather than the latest exchange.
3597
+ *
3598
+ * Reset when the sheet CLOSES (see `dismissSheet`) rather than kept for the
3599
+ * session: the sheet's job at `peek` is to show the concierge's answer, and
3600
+ * a shopper who opened the history once should not find every later reply
3601
+ * buried under it.
3602
+ */
3603
+ const [showConversation, setShowConversation] = useState(false);
2890
3604
  const [nudge, setNudge] = useState(void 0);
2891
3605
  const [interruptsSeen, setInterruptsSeen] = useState(readInterruptsSeen);
2892
3606
  const [engaged, setEngaged] = useState(() => initialFocus !== null && initialFocus !== void 0);
@@ -3440,11 +4154,11 @@ function Dock(props) {
3440
4154
  useEffect(() => {
3441
4155
  recedeRef.current?.setForm(form);
3442
4156
  }, [form]);
3443
- useFormFlip(pillRef, rowRef, form, reducedMotion, durations.swap);
4157
+ useFormFlip(pillRef, rowRef, form, motionOff, durations.swap);
3444
4158
  const levelRef = voice?.levelRef;
3445
4159
  const waveform = view.activity === "waveform";
3446
4160
  useEffect(() => {
3447
- if (!waveform || reducedMotion || typeof requestAnimationFrame !== "function") return;
4161
+ if (!waveform || motionOff || typeof requestAnimationFrame !== "function") return;
3448
4162
  let frame = 0;
3449
4163
  const smoothed = [
3450
4164
  .15,
@@ -3465,7 +4179,7 @@ function Dock(props) {
3465
4179
  return () => cancelAnimationFrame(raf);
3466
4180
  }, [
3467
4181
  waveform,
3468
- reducedMotion,
4182
+ motionOff,
3469
4183
  setVar,
3470
4184
  levelRef
3471
4185
  ]);
@@ -3599,10 +4313,14 @@ function Dock(props) {
3599
4313
  setSheet("closed");
3600
4314
  inputRef.current?.focus();
3601
4315
  }, []);
4316
+ useEffect(() => {
4317
+ if (sheet === "closed") setShowConversation(false);
4318
+ }, [sheet]);
4319
+ const align = dragging.align;
3602
4320
  const rootStyle = useMemo(() => {
3603
4321
  const style = { ...geometryVars(isDesktop, layout) };
3604
4322
  style["--wgt-row-margin"] = isDesktop ? "0px" : `10px`;
3605
- const anchor = pillAnchor(direction, isDesktop, layout.desktopAlign);
4323
+ const anchor = pillAnchor(direction, isDesktop, align);
3606
4324
  style["--wgt-pill-left"] = anchor.side === "left" ? `${anchor.inset}px` : "auto";
3607
4325
  style["--wgt-pill-right"] = anchor.side === "right" ? `${anchor.inset}px` : "auto";
3608
4326
  style["--wgt-sheet-peek"] = `260px`;
@@ -3619,8 +4337,8 @@ function Dock(props) {
3619
4337
  } else {
3620
4338
  const width = rowWidthLen(true, layout.desktopWidth);
3621
4339
  style.width = width;
3622
- if (layout.desktopAlign === "left") style.left = `16px`;
3623
- else if (layout.desktopAlign === "right") style.right = `16px`;
4340
+ if (align === "left") style.left = `16px`;
4341
+ else if (align === "right") style.right = `16px`;
3624
4342
  else {
3625
4343
  style.left = "50%";
3626
4344
  style.marginLeft = `calc(${width} / -2)`;
@@ -3633,6 +4351,7 @@ function Dock(props) {
3633
4351
  }, [
3634
4352
  isDesktop,
3635
4353
  layout,
4354
+ align,
3636
4355
  durations,
3637
4356
  direction,
3638
4357
  skinStyle,
@@ -3685,6 +4404,16 @@ function Dock(props) {
3685
4404
  const greeting = copy.greeting?.trim();
3686
4405
  const typedPlaceholder = copy.placeholder?.trim() || msg("type_placeholder");
3687
4406
  const placeholder = greeting !== void 0 && greeting !== "" && !hasContent && !sheetEverOpened && view.state === "dormant" ? greeting : typedPlaceholder;
4407
+ /**
4408
+ * §3.4 — is this the one-answer view?
4409
+ *
4410
+ * A TEXT session, a host that supplied the latest view at all, the shopper
4411
+ * has not asked for the history, and the sheet is not already expanded —
4412
+ * because a sheet dragged open by its handle is a shopper asking for room,
4413
+ * and answering that with one exchange and a lot of white space is worse
4414
+ * than answering it with the conversation.
4415
+ */
4416
+ const showLatestOnly = channel === "text" && latestExchange !== void 0 && !showConversation && sheet !== "expanded";
3688
4417
  const sheetHeader = /* @__PURE__ */ jsxs(Fragment, { children: [
3689
4418
  onEndCall !== void 0 && view.callActive ? /* @__PURE__ */ jsx("button", {
3690
4419
  type: "button",
@@ -3700,15 +4429,29 @@ function Dock(props) {
3700
4429
  onClick: () => setShowTranscript(true),
3701
4430
  children: msg("dock_show_transcript")
3702
4431
  }) : null,
4432
+ showLatestOnly && (exchangeCount ?? 0) > 1 ? /* @__PURE__ */ jsx("button", {
4433
+ type: "button",
4434
+ className: "wgt-sheet-action",
4435
+ "data-testid": "widget-dock-show-conversation",
4436
+ onClick: (event) => {
4437
+ const handle = event.currentTarget.closest(".wgt-sheet")?.querySelector(".wgt-sheet-handle");
4438
+ setShowConversation(true);
4439
+ if (!shortViewport) setSheet("expanded");
4440
+ handle?.focus();
4441
+ },
4442
+ children: msg("dock_show_conversation")
4443
+ }) : null,
3703
4444
  layout.minimised !== "never" ? /* @__PURE__ */ jsx("button", {
3704
4445
  type: "button",
3705
4446
  className: "wgt-sheet-action",
3706
4447
  "data-testid": "widget-dock-minimise",
4448
+ "aria-label": msg("minimize"),
4449
+ title: msg("minimize"),
3707
4450
  onClick: () => {
3708
4451
  setSheet("closed");
3709
4452
  setFormPersisting("pill");
3710
4453
  },
3711
- children: msg("minimize")
4454
+ children: /* @__PURE__ */ jsx(ChevronDownGlyph, {})
3712
4455
  }) : null
3713
4456
  ] });
3714
4457
  return /* @__PURE__ */ jsxs("div", {
@@ -3717,6 +4460,8 @@ function Dock(props) {
3717
4460
  "data-concierge-dock": "",
3718
4461
  "data-wgt-scope": scopeId,
3719
4462
  "data-viewport": isDesktop ? "desktop" : "mobile",
4463
+ "data-align": align,
4464
+ "data-draggable": draggable ? "true" : void 0,
3720
4465
  "data-state": view.state,
3721
4466
  ...skin !== void 0 ? { "data-skin": skin } : {},
3722
4467
  role: "region",
@@ -3746,6 +4491,7 @@ function Dock(props) {
3746
4491
  header: sheetHeader,
3747
4492
  onDismiss: dismissSheet,
3748
4493
  ...followKey !== void 0 ? { followKey } : {},
4494
+ historyRevealed: latestExchange !== void 0 && !showLatestOnly,
3749
4495
  durationMs: sheet === "closed" ? durations.sheetClose : durations.sheetOpen,
3750
4496
  dragHandleLabel: msg("conversation"),
3751
4497
  children: [
@@ -3758,7 +4504,7 @@ function Dock(props) {
3758
4504
  ...productHref ? { productHref } : {},
3759
4505
  ...navigate ? { navigate } : {}
3760
4506
  }) : null,
3761
- channel === "text" || showTranscript ? transcript : null,
4507
+ channel === "text" || showTranscript ? showLatestOnly ? latestExchange : transcript : null,
3762
4508
  sheetExtra,
3763
4509
  attribution !== void 0 ? /* @__PURE__ */ jsx("a", {
3764
4510
  className: "wgt-shelf-more",
@@ -3778,9 +4524,12 @@ function Dock(props) {
3778
4524
  expandLabel: msg("open"),
3779
4525
  form,
3780
4526
  onPress: () => {
4527
+ if (dragging.consumeClick()) return;
3781
4528
  setEngaged(true);
3782
4529
  setFormPersisting("row");
3783
4530
  },
4531
+ draggable,
4532
+ dragHandleProps: dragging.handleProps,
3784
4533
  pillRef
3785
4534
  }),
3786
4535
  /* @__PURE__ */ jsx(DockRow, {
@@ -3812,14 +4561,41 @@ function Dock(props) {
3812
4561
  captionDurationMs: durations.caption,
3813
4562
  markStateLabel: msg(view.border === "primary" ? "state_listening" : "state_idle", { product: name }),
3814
4563
  onMarkPress: () => {
4564
+ if (dragging.consumeClick()) return;
3815
4565
  setEngaged(true);
3816
4566
  setSheet((current) => current === "closed" ? "peek" : "closed");
3817
- }
4567
+ },
4568
+ sheetOpen: sheet !== "closed",
4569
+ draggable,
4570
+ dragHandleProps: dragging.handleProps
3818
4571
  }),
3819
4572
  attachSlot
3820
4573
  ]
3821
4574
  });
3822
4575
  }
4576
+ /**
4577
+ * §5.4's minimise glyph — a chevron pointing at the row the sheet collapses
4578
+ * onto.
4579
+ *
4580
+ * Inline SVG at 18 px on `currentColor`, exactly like `dock-row.tsx`'s five:
4581
+ * a webfont is a network request on a merchant's page for one shape, and an
4582
+ * `aria-hidden` glyph inside a button that already carries its accessible
4583
+ * name is never read out.
4584
+ */
4585
+ function ChevronDownGlyph() {
4586
+ return /* @__PURE__ */ jsx("svg", {
4587
+ width: 18,
4588
+ height: 18,
4589
+ viewBox: "0 0 24 24",
4590
+ "aria-hidden": "true",
4591
+ fill: "none",
4592
+ stroke: "currentColor",
4593
+ strokeWidth: 1.8,
4594
+ strokeLinecap: "round",
4595
+ strokeLinejoin: "round",
4596
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
4597
+ });
4598
+ }
3823
4599
  /** Turns §5.1's caption spec into the string this locale renders. */
3824
4600
  function resolveCaption(view, msg) {
3825
4601
  if (view.caption.kind === "field") return void 0;
@@ -3937,7 +4713,15 @@ function useViewport(rootRef) {
3937
4713
  const subscribe = useCallback((onChange) => win === null ? () => void 0 : subscribeToViewport(win, onChange), [win]);
3938
4714
  return {
3939
4715
  isDesktop: useSyncExternalStore(subscribe, () => win !== null && win.innerWidth >= 768, () => false),
3940
- shortViewport: useSyncExternalStore(subscribe, () => win !== null && win.innerHeight < 500, () => false)
4716
+ shortViewport: useSyncExternalStore(subscribe, () => win !== null && win.innerHeight < 500, () => false),
4717
+ finePointer: useSyncExternalStore(subscribe, () => {
4718
+ try {
4719
+ return win?.matchMedia?.("(pointer: fine)").matches === true;
4720
+ } catch {
4721
+ return false;
4722
+ }
4723
+ }, () => false),
4724
+ win
3941
4725
  };
3942
4726
  }
3943
4727
  //#endregion
@@ -5153,6 +5937,103 @@ function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle",
5153
5937
  onStart: onToggleMic,
5154
5938
  onToggleMute: onToggleMic
5155
5939
  };
5940
+ /**
5941
+ * §3.4 — the transcript, rendered from whichever slice of the turns it is
5942
+ * given.
5943
+ *
5944
+ * A local function rather than a component, and deliberately: it closes
5945
+ * over the dozen things a turn is drawn from (the messages, the locale, the
5946
+ * card handlers, `escalated`, `sending`) and lifting those into props would
5947
+ * be a component with fifteen of them and no second caller. The two slices
5948
+ * it is called with are §3.4's two views.
5949
+ */
5950
+ const renderLog = (shown, view = "all", offset = 0) => /* @__PURE__ */ jsxs("div", {
5951
+ role: "log",
5952
+ "aria-live": "polite",
5953
+ "aria-relevant": "additions text",
5954
+ className: "flex flex-col gap-1",
5955
+ children: [
5956
+ shown.length === 0 ? /* @__PURE__ */ jsx("p", {
5957
+ className: "py-8 text-center text-sm text-[var(--widget-foreground-muted)]",
5958
+ children: messages.empty
5959
+ }) : shown.map((turn, i) => turn.speaker === "event" ? /* @__PURE__ */ jsx(TranscriptEvent, {
5960
+ event: turn.event,
5961
+ messages,
5962
+ awaitingReply: !shown.slice(i + 1).some((t) => t.speaker === "agent" && t.text.trim() !== "")
5963
+ }, `event-${offset + i}`) : /* @__PURE__ */ jsxs("div", {
5964
+ "data-dock-follow": "",
5965
+ className: turn.speaker === "caller" ? "wgt-turn-row flex flex-col items-end" : "wgt-turn-row flex flex-col items-start",
5966
+ children: [
5967
+ turn.text !== "" || turn.speaker === "agent" && turn.final === false ? /* @__PURE__ */ jsx("div", {
5968
+ dir: textDirectionFor(turn.locale),
5969
+ lang: turn.locale,
5970
+ "data-testid": turn.speaker === "caller" ? "widget-turn-caller" : turn.filler === true ? "widget-turn-agent-filler" : "widget-turn-agent",
5971
+ className: `max-w-[85%] px-3.5 py-2 text-[14px] leading-[1.55] shadow-sm ${turn.speaker === "caller" ? "from-brand-plum to-brand-plum/90 text-[var(--widget-accent-foreground)] rounded-2xl rounded-ee-md bg-gradient-to-br" : turn.filler === true ? "rounded-2xl rounded-es-md border border-dashed border-[var(--widget-foreground-muted)]/50 bg-transparent text-[var(--widget-foreground-muted)] shadow-none" : AGENT_BUBBLE_CLASS}`,
5972
+ children: turn.speaker === "agent" && turn.text === "" && turn.final === false ? /* @__PURE__ */ jsx(TypingDots, { label: messages.typing }) : turn.speaker === "agent" && turn.filler === true ? /* @__PURE__ */ jsxs("span", {
5973
+ className: "flex items-center gap-2 italic",
5974
+ children: [/* @__PURE__ */ jsx("span", { children: turn.text }), /* @__PURE__ */ jsx(TypingDots, { label: messages.typing })]
5975
+ }) : turn.speaker === "agent" ? /* @__PURE__ */ jsx(WidgetMarkdown, { text: turn.text }) : /* @__PURE__ */ jsx("span", {
5976
+ className: `whitespace-pre-wrap ${turn.final === false ? "italic opacity-70" : ""}`,
5977
+ children: turn.text
5978
+ })
5979
+ }) : null,
5980
+ turn.attachments && turn.attachments.length > 0 ? /* @__PURE__ */ jsx("div", {
5981
+ className: "w-full max-w-[85%]",
5982
+ children: /* @__PURE__ */ jsx(WidgetAttachmentList, {
5983
+ attachments: turn.attachments,
5984
+ messages
5985
+ })
5986
+ }) : null,
5987
+ turn.cards && turn.cards.items.length > 0 ? /* @__PURE__ */ jsx("div", {
5988
+ className: "w-full",
5989
+ children: /* @__PURE__ */ jsx(WidgetCardList, {
5990
+ cards: turn.cards,
5991
+ onAddToCart,
5992
+ curationHref,
5993
+ productHref,
5994
+ navigate,
5995
+ locale,
5996
+ messages,
5997
+ roomy: false,
5998
+ ...dock?.showPrice !== void 0 ? { showPrice: dock.showPrice } : {},
5999
+ ...dock?.cardImageAspect !== void 0 ? { imageAspect: dock.cardImageAspect } : {}
6000
+ })
6001
+ }) : null,
6002
+ turn.delivery !== void 0 ? /* @__PURE__ */ jsx(TurnDeliveryStatus, {
6003
+ delivery: turn.delivery,
6004
+ messages
6005
+ }) : null
6006
+ ]
6007
+ }, `${turn.speaker}-${offset + i}`)),
6008
+ humanTyping ? /* @__PURE__ */ jsx("div", {
6009
+ "data-testid": "widget-human-typing",
6010
+ "data-dock-follow": "",
6011
+ className: "wgt-turn-row flex flex-col items-start",
6012
+ children: /* @__PURE__ */ jsx("div", {
6013
+ className: `px-3.5 py-2 text-[14px] leading-[1.55] shadow-sm ${AGENT_BUBBLE_CLASS}`,
6014
+ children: /* @__PURE__ */ jsx(TypingDots, { label: messages.typing })
6015
+ })
6016
+ }) : null,
6017
+ !escalated && turns.every((turn) => turn.speaker !== "caller") ? /* @__PURE__ */ jsx("ul", {
6018
+ "aria-label": messages.suggestions_label,
6019
+ "data-testid": "widget-suggestions",
6020
+ className: "flex flex-wrap gap-2 pt-1",
6021
+ children: SUGGESTION_KEYS.map((key) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
6022
+ type: "button",
6023
+ "data-testid": "widget-suggestion",
6024
+ disabled: sending,
6025
+ onClick: () => void sendSuggestion(messages[key]),
6026
+ className: "cursor-pointer rounded-full bg-[var(--widget-chip)] px-3 py-1.5 text-xs font-medium text-[var(--widget-foreground)] ring-1 ring-black/10 transition-colors hover:bg-[var(--widget-accent)] hover:text-[var(--widget-accent-foreground)] disabled:cursor-default disabled:opacity-50 focus-visible:ring-2 focus-visible:ring-[var(--widget-accent-ring)] focus-visible:outline-none",
6027
+ children: messages[key]
6028
+ }) }, key))
6029
+ }) : null
6030
+ ]
6031
+ }, `log-${view}`);
6032
+ /**
6033
+ * The turns' SPEAKERS, which is all §3.4's split looks at
6034
+ * (`dock-state.ts`'s `latestExchangeStart` / `exchangeCount`).
6035
+ */
6036
+ const speakers = turns.map((turn) => turn.speaker);
5156
6037
  return /* @__PURE__ */ jsx(Dock, {
5157
6038
  identity: {
5158
6039
  name: "",
@@ -5210,88 +6091,9 @@ function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle",
5210
6091
  className: `text-xs ${attaching.failed ? "text-destructive" : "text-[var(--widget-foreground-muted)]"}`,
5211
6092
  children: attaching.failed ? formatMessage(messages.attach_error, { filename: attaching.filename }) : formatMessage(messages.attach_uploading, { filename: attaching.filename })
5212
6093
  }) : null] }),
5213
- transcript: /* @__PURE__ */ jsxs("div", {
5214
- role: "log",
5215
- "aria-live": "polite",
5216
- "aria-relevant": "additions text",
5217
- className: "flex flex-col gap-1",
5218
- children: [
5219
- turns.length === 0 ? /* @__PURE__ */ jsx("p", {
5220
- className: "py-8 text-center text-sm text-[var(--widget-foreground-muted)]",
5221
- children: messages.empty
5222
- }) : turns.map((turn, i) => turn.speaker === "event" ? /* @__PURE__ */ jsx(TranscriptEvent, {
5223
- event: turn.event,
5224
- messages,
5225
- awaitingReply: !turns.slice(i + 1).some((t) => t.speaker === "agent" && t.text.trim() !== "")
5226
- }, `event-${i}`) : /* @__PURE__ */ jsxs("div", {
5227
- "data-dock-follow": "",
5228
- className: turn.speaker === "caller" ? "wgt-turn-row flex flex-col items-end" : "wgt-turn-row flex flex-col items-start",
5229
- children: [
5230
- turn.text !== "" || turn.speaker === "agent" && turn.final === false ? /* @__PURE__ */ jsx("div", {
5231
- dir: textDirectionFor(turn.locale),
5232
- lang: turn.locale,
5233
- "data-testid": turn.speaker === "caller" ? "widget-turn-caller" : turn.filler === true ? "widget-turn-agent-filler" : "widget-turn-agent",
5234
- className: `max-w-[85%] px-3.5 py-2 text-[14px] leading-[1.55] shadow-sm ${turn.speaker === "caller" ? "from-brand-plum to-brand-plum/90 text-[var(--widget-accent-foreground)] rounded-2xl rounded-ee-md bg-gradient-to-br" : turn.filler === true ? "rounded-2xl rounded-es-md border border-dashed border-[var(--widget-foreground-muted)]/50 bg-transparent text-[var(--widget-foreground-muted)] shadow-none" : AGENT_BUBBLE_CLASS}`,
5235
- children: turn.speaker === "agent" && turn.text === "" && turn.final === false ? /* @__PURE__ */ jsx(TypingDots, { label: messages.typing }) : turn.speaker === "agent" && turn.filler === true ? /* @__PURE__ */ jsxs("span", {
5236
- className: "flex items-center gap-2 italic",
5237
- children: [/* @__PURE__ */ jsx("span", { children: turn.text }), /* @__PURE__ */ jsx(TypingDots, { label: messages.typing })]
5238
- }) : turn.speaker === "agent" ? /* @__PURE__ */ jsx(WidgetMarkdown, { text: turn.text }) : /* @__PURE__ */ jsx("span", {
5239
- className: `whitespace-pre-wrap ${turn.final === false ? "italic opacity-70" : ""}`,
5240
- children: turn.text
5241
- })
5242
- }) : null,
5243
- turn.attachments && turn.attachments.length > 0 ? /* @__PURE__ */ jsx("div", {
5244
- className: "w-full max-w-[85%]",
5245
- children: /* @__PURE__ */ jsx(WidgetAttachmentList, {
5246
- attachments: turn.attachments,
5247
- messages
5248
- })
5249
- }) : null,
5250
- turn.cards && turn.cards.items.length > 0 ? /* @__PURE__ */ jsx("div", {
5251
- className: "w-full",
5252
- children: /* @__PURE__ */ jsx(WidgetCardList, {
5253
- cards: turn.cards,
5254
- onAddToCart,
5255
- curationHref,
5256
- productHref,
5257
- navigate,
5258
- locale,
5259
- messages,
5260
- roomy: false,
5261
- ...dock?.showPrice !== void 0 ? { showPrice: dock.showPrice } : {},
5262
- ...dock?.cardImageAspect !== void 0 ? { imageAspect: dock.cardImageAspect } : {}
5263
- })
5264
- }) : null,
5265
- turn.delivery !== void 0 ? /* @__PURE__ */ jsx(TurnDeliveryStatus, {
5266
- delivery: turn.delivery,
5267
- messages
5268
- }) : null
5269
- ]
5270
- }, `${turn.speaker}-${i}`)),
5271
- humanTyping ? /* @__PURE__ */ jsx("div", {
5272
- "data-testid": "widget-human-typing",
5273
- "data-dock-follow": "",
5274
- className: "wgt-turn-row flex flex-col items-start",
5275
- children: /* @__PURE__ */ jsx("div", {
5276
- className: `px-3.5 py-2 text-[14px] leading-[1.55] shadow-sm ${AGENT_BUBBLE_CLASS}`,
5277
- children: /* @__PURE__ */ jsx(TypingDots, { label: messages.typing })
5278
- })
5279
- }) : null,
5280
- !escalated && turns.every((turn) => turn.speaker !== "caller") ? /* @__PURE__ */ jsx("ul", {
5281
- "aria-label": messages.suggestions_label,
5282
- "data-testid": "widget-suggestions",
5283
- className: "flex flex-wrap gap-2 pt-1",
5284
- children: SUGGESTION_KEYS.map((key) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
5285
- type: "button",
5286
- "data-testid": "widget-suggestion",
5287
- disabled: sending,
5288
- onClick: () => void sendSuggestion(messages[key]),
5289
- className: "cursor-pointer rounded-full bg-[var(--widget-chip)] px-3 py-1.5 text-xs font-medium text-[var(--widget-foreground)] ring-1 ring-black/10 transition-colors hover:bg-[var(--widget-accent)] hover:text-[var(--widget-accent-foreground)] disabled:cursor-default disabled:opacity-50 focus-visible:ring-2 focus-visible:ring-[var(--widget-accent-ring)] focus-visible:outline-none",
5290
- children: messages[key]
5291
- }) }, key))
5292
- }) : null
5293
- ]
5294
- })
6094
+ transcript: renderLog(turns),
6095
+ latestExchange: renderLog(turns.slice(latestExchangeStart(speakers)), "latest", latestExchangeStart(speakers)),
6096
+ exchangeCount: exchangeCount(speakers)
5295
6097
  });
5296
6098
  }
5297
6099
  new Set([
@@ -9634,4 +10436,4 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, col
9634
10436
  });
9635
10437
  }
9636
10438
  //#endregion
9637
- export { SHEET_PEEK_MAX as $, Dock as A, srgbToLinear as At, DESKTOP_GUTTER as B, IDLE_SNAPSHOT as C, oklabToLinearRgb as Ct, SessionLog as D, parseHex as Dt, SESSION_EVENTS as E, oklchToOklab as Et, ACTIVITY_W as F, widgetMessagesFromCopy as Ft, PILL_H as G, DOCK_MINIMISED_STORAGE_KEY as H, BOTTOM_FLOOR as I, RADII as J, PILL_MARK as K, CONTROL as L, deriveDockState as M, defaultWidgetMessages as Mt, idleDockInput as N, formatMessage as Nt, formatMs as O, relativeLuminance as Ot, formatMoney as P, resolveWidgetMessages as Pt, SHEET_GAP as Q, DESKTOP_BOTTOM as R, parseBlocks as S, oklabToHex as St, SseFrameParser as T, oklchToHex as Tt, MARK as U, DESKTOP_WIDTHS as V, MOBILE_MARGIN as W, SHEET_EXPANDED_DESKTOP_MAX as X, ROW_H as Y, SHEET_EXPANDED_VH as Z, readsAsCheckoutIntent as _, hexToOklab as _t, mergeAddedCartLine as a, pillAnchor as at, WidgetCardList as b, linearToSrgb as bt, toChatCart as c, CARD_RADIUS_MAX_PX as ct, useVoiceSession as d, WIDGET_THEME_TOKENS as dt, SHEET_TOP_CLEARANCE as et, useChatSession as f, deriveTheme as ft, readsAsCartViewIntent as g, formatHex as gt, basketIntentFromTurns as h, contrastRatio as ht, deriveCallPhase as i, geometryVars as it, DOCK_STATES as j, withAlpha as jt, latencyBetween as k, rotateHue as kt, ROOM_EVENTS as l, SHEET_RADIUS_MAX_PX as lt, VoiceWidget as m, themeToInlineStyle as mt, MAX_REPORTED_CART_LINES as n, Z_INDEX as nt, resolveAddToCartHandler as o, rowWidthLen as ot, detectPage as p, themeToCss as pt, PROACTIVE_NUDGE_MS as q, cartLinesFromSnapshot as r, bottomLen as rt, resolveCheckoutUrl as s, sheetMaxHeightLen as st, ConciergeWidget as t, SHORT_VIEWPORT as tt, createWidgetVoiceTokenFetcher as u, SYSTEM_FONT_STACK as ut, textDirectionFor as v, hexToOklch as vt, botStateFor as w, oklabToOklch as wt, WidgetMarkdown as x, mixToward as xt, WidgetCartSummary as y, linearRgbToOklab as yt, DESKTOP_BREAKPOINT as z };
10439
+ export { ROW_H as $, Dock as A, mixToward as At, DESKTOP_BOTTOM as B, withAlpha as Bt, IDLE_SNAPSHOT as C, themeToInlineStyle as Ct, SessionLog as D, hexToOklch as Dt, SESSION_EVENTS as E, hexToOklab as Et, latestExchangeStart as F, oklchToOklab as Ft, DOCK_MINIMISED_STORAGE_KEY as G, DESKTOP_GUTTER as H, formatMessage as Ht, formatMoney as I, parseHex as It, MOBILE_MARGIN as J, DRAG_TAP_SLOP_PX as K, ACTIVITY_W as L, relativeLuminance as Lt, deriveDockState as M, oklabToLinearRgb as Mt, exchangeCount as N, oklabToOklch as Nt, formatMs as O, linearRgbToOklab as Ot, idleDockInput as P, oklchToHex as Pt, RADII as Q, BOTTOM_FLOOR as R, rotateHue as Rt, parseBlocks as S, themeToCss as St, SseFrameParser as T, formatHex as Tt, DESKTOP_WIDTHS as U, resolveWidgetMessages as Ut, DESKTOP_BREAKPOINT as V, defaultWidgetMessages as Vt, DOCK_ALIGN_STORAGE_KEY as W, widgetMessagesFromCopy as Wt, PILL_MARK as X, PILL_H as Y, PROACTIVE_NUDGE_MS as Z, readsAsCheckoutIntent as _, CARD_RADIUS_MAX_PX as _t, mergeAddedCartLine as a, SHORT_VIEWPORT as at, WidgetCardList as b, WIDGET_THEME_TOKENS as bt, toChatCart as c, geometryVars as ct, useVoiceSession as d, readStored as dt, SHEET_EXPANDED_DESKTOP_MAX as et, useChatSession as f, readStoredAlign as ft, readsAsCartViewIntent as g, writeStored as gt, basketIntentFromTurns as h, snapAlign as ht, deriveCallPhase as i, SHEET_TOP_CLEARANCE as it, DOCK_STATES as j, oklabToHex as jt, latencyBetween as k, linearToSrgb as kt, ROOM_EVENTS as l, persistAlign as lt, VoiceWidget as m, sheetMaxHeightLen as mt, MAX_REPORTED_CART_LINES as n, SHEET_GAP as nt, resolveAddToCartHandler as o, Z_INDEX as ot, detectPage as p, rowWidthLen as pt, MARK as q, cartLinesFromSnapshot as r, SHEET_PEEK_MAX as rt, resolveCheckoutUrl as s, bottomLen as st, ConciergeWidget as t, SHEET_EXPANDED_VH as tt, createWidgetVoiceTokenFetcher as u, pillAnchor as ut, textDirectionFor as v, SHEET_RADIUS_MAX_PX as vt, botStateFor as w, contrastRatio as wt, WidgetMarkdown as x, deriveTheme as xt, WidgetCartSummary as y, SYSTEM_FONT_STACK as yt, CONTROL as z, srgbToLinear as zt };