@astryxdesign/lab 0.2.0-canary.fc53ff7 → 0.2.0-canary.fce8b64

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.
Files changed (97) hide show
  1. package/dist/BottomSheet/BottomSheet.d.ts +41 -35
  2. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  3. package/dist/BottomSheet/BottomSheet.js +222 -75
  4. package/dist/BottomSheet/snapOffsets.d.ts +54 -0
  5. package/dist/BottomSheet/snapOffsets.d.ts.map +1 -0
  6. package/dist/BottomSheet/snapOffsets.js +101 -0
  7. package/dist/BottomSheet/useSheetGestures.d.ts +55 -12
  8. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
  9. package/dist/BottomSheet/useSheetGestures.js +383 -40
  10. package/dist/Chart/index.d.ts +1 -1
  11. package/dist/Chart/index.d.ts.map +1 -1
  12. package/dist/Chart/index.js +1 -1
  13. package/dist/RichTextEditor/RichTextEditor.d.ts +6 -0
  14. package/dist/RichTextEditor/RichTextEditor.d.ts.map +1 -1
  15. package/dist/RichTextEditor/RichTextEditor.js +7 -7
  16. package/dist/RichTextEditor/RichTextEditorAutoLinkPlugin.d.ts +85 -0
  17. package/dist/RichTextEditor/RichTextEditorAutoLinkPlugin.d.ts.map +1 -0
  18. package/dist/RichTextEditor/RichTextEditorAutoLinkPlugin.js +95 -0
  19. package/dist/RichTextEditor/RichTextEditorToolbar.d.ts +126 -0
  20. package/dist/RichTextEditor/RichTextEditorToolbar.d.ts.map +1 -0
  21. package/dist/RichTextEditor/RichTextEditorToolbar.js +633 -0
  22. package/dist/RichTextEditor/RichTextView.d.ts.map +1 -1
  23. package/dist/RichTextEditor/RichTextView.js +48 -2
  24. package/dist/RichTextEditor/editorNodes.d.ts +8 -0
  25. package/dist/RichTextEditor/editorNodes.d.ts.map +1 -0
  26. package/dist/RichTextEditor/editorNodes.js +23 -0
  27. package/dist/RichTextEditor/index.d.ts +7 -0
  28. package/dist/RichTextEditor/index.d.ts.map +1 -1
  29. package/dist/RichTextEditor/index.js +5 -1
  30. package/dist/RichTextEditor/linkUtils.d.ts +22 -0
  31. package/dist/RichTextEditor/linkUtils.d.ts.map +1 -0
  32. package/dist/RichTextEditor/linkUtils.js +91 -0
  33. package/dist/RichTextEditor/markdownSerializers.d.ts +40 -0
  34. package/dist/RichTextEditor/markdownSerializers.d.ts.map +1 -0
  35. package/dist/RichTextEditor/markdownSerializers.js +85 -0
  36. package/dist/Stepper/Step.d.ts +1 -1
  37. package/dist/Stepper/Step.js +1 -1
  38. package/dist/Stepper/Stepper.d.ts +1 -1
  39. package/dist/Stepper/Stepper.js +1 -1
  40. package/dist/index.d.ts +1 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +2 -2
  43. package/dist/lab.css +15 -8
  44. package/package.json +19 -3
  45. package/src/BottomSheet/BottomSheet.doc.mjs +13 -13
  46. package/src/BottomSheet/BottomSheet.test.tsx +81 -4
  47. package/src/BottomSheet/BottomSheet.tsx +333 -97
  48. package/src/BottomSheet/snapOffsets.test.ts +146 -0
  49. package/src/BottomSheet/snapOffsets.ts +126 -0
  50. package/src/BottomSheet/useSheetGestures.doc.mjs +7 -6
  51. package/src/BottomSheet/useSheetGestures.test.ts +315 -65
  52. package/src/BottomSheet/useSheetGestures.ts +515 -55
  53. package/src/Chart/ChartArea.doc.mjs +1 -1
  54. package/src/Chart/ChartBar.doc.mjs +1 -1
  55. package/src/Chart/ChartCandlestick.doc.mjs +1 -1
  56. package/src/Chart/ChartDot.doc.mjs +1 -1
  57. package/src/Chart/ChartDotGL.doc.mjs +1 -1
  58. package/src/Chart/ChartDotGLInteractive.doc.mjs +1 -1
  59. package/src/Chart/ChartHeatmapGL.doc.mjs +1 -1
  60. package/src/Chart/ChartLine.doc.mjs +1 -1
  61. package/src/Chart/ChartStreamGL.doc.mjs +1 -1
  62. package/src/Chart/index.ts +0 -1
  63. package/src/Chat/ChatEmojiPicker.doc.mjs +1 -1
  64. package/src/Chat/ChatReactionBar.doc.mjs +1 -1
  65. package/src/Chat/ChatTypingIndicator.doc.mjs +1 -1
  66. package/src/Chat/ChatUnreadDivider.doc.mjs +1 -1
  67. package/src/ChatReasoning/ChatReasoning.doc.mjs +1 -1
  68. package/src/CircularProgress/CircularProgress.doc.mjs +3 -3
  69. package/src/CodeEditor/CodeEditor.doc.mjs +1 -1
  70. package/src/Drawer/Drawer.doc.mjs +3 -3
  71. package/src/InfoTip/InfoTip.doc.mjs +3 -3
  72. package/src/LogStream/LogStream.doc.mjs +1 -1
  73. package/src/Radial/RadialChart.doc.mjs +1 -1
  74. package/src/RichTextEditor/RichTextEditor.doc.mjs +27 -2
  75. package/src/RichTextEditor/RichTextEditor.test.tsx +622 -21
  76. package/src/RichTextEditor/RichTextEditor.tsx +13 -16
  77. package/src/RichTextEditor/RichTextEditorAutoLinkPlugin.tsx +116 -0
  78. package/src/RichTextEditor/RichTextEditorToolbar.tsx +789 -0
  79. package/src/RichTextEditor/RichTextView.tsx +44 -1
  80. package/src/RichTextEditor/editorNodes.ts +34 -0
  81. package/src/RichTextEditor/index.ts +26 -0
  82. package/src/RichTextEditor/linkUtils.ts +93 -0
  83. package/src/RichTextEditor/markdownSerializers.ts +105 -0
  84. package/src/SVGIcon/SVGIcon.doc.mjs +1 -1
  85. package/src/Sankey/SankeyChart.doc.mjs +1 -1
  86. package/src/Schedule/Schedule.doc.mjs +1 -1
  87. package/src/Stat/Stat.doc.mjs +3 -3
  88. package/src/Stepper/Step.doc.mjs +1 -1
  89. package/src/Stepper/Step.tsx +1 -1
  90. package/src/Stepper/Stepper.doc.mjs +3 -3
  91. package/src/Stepper/Stepper.tsx +1 -1
  92. package/src/ThreeD/3DBar.doc.mjs +1 -1
  93. package/src/ThreeD/3DChart.doc.mjs +1 -1
  94. package/src/ThreeD/3DScatter.doc.mjs +1 -1
  95. package/src/ThreeD/3DScatterGL.doc.mjs +1 -1
  96. package/src/ThreeD/3DSurface.doc.mjs +1 -1
  97. package/src/index.ts +15 -1
@@ -1,20 +1,21 @@
1
1
  /**
2
2
  * @file BottomSheet.tsx
3
- * @input Uses React, StyleX, theme tokens, Drawer, useSheetGestures, themeProps
3
+ * @input Uses React, StyleX, theme tokens, core hooks (useScrollLock), utils, useSheetGestures
4
4
  * @output Exports BottomSheet component and BottomSheetProps
5
5
  * @position Lab implementation; consumed by index.ts, tested by BottomSheet.test.tsx, demonstrated in Storybook
6
6
  *
7
- * A mobile touch surface that rises from the bottom edge with a grab handle
8
- * and swipe-to-dismiss. Built ON TOP OF the lab Drawer's native `<dialog>`
9
- * engine (`side="bottom"`) rather than forking it — Drawer owns
10
- * showModal/show, the open/close slide animation, focus trap + restore,
11
- * scroll lock, the Escape/scrim contract, and the LIFO overlay registry.
12
- * BottomSheet layers the grab handle and the drag-to-dismiss gesture on top,
13
- * inside the dialog.
7
+ * A mobile touch surface that rises from the bottom edge: grab handle, snap
8
+ * points, and swipe-to-dismiss. It owns a native modal `<dialog>` directly and
9
+ * composes core primitives (`useScrollLock`, `<dialog>.showModal()` for the
10
+ * top layer + focus trap, a `::backdrop` scrim) rather than delegating to a
11
+ * heavier overlay component — so it controls its own sizing and can render a
12
+ * full-height transparent shell with the visible sheet bottom-anchored inside.
13
+ * That shell is what lets the sheet translate freely (including a little past
14
+ * fully-open) without clipping against a fixed dialog edge.
14
15
  *
15
- * The gesture translate is applied to an inner sheet wrapper, not the
16
- * `<dialog>` itself, so Drawer owns the open/close slide and the drag
17
- * translates within it without the two transforms fighting.
16
+ * The drag/snap/dismiss machinery lives in `useSheetGestures`; the offset
17
+ * geometry lives in the pure, tested `snapOffsets` module. Both are internal
18
+ * to BottomSheet and not exported from the lab entry point.
18
19
  *
19
20
  * SYNC: When modified, update these files to stay in sync:
20
21
  * - /packages/lab/src/BottomSheet/BottomSheet.doc.mjs (props table, features, usage)
@@ -25,15 +26,16 @@
25
26
  import { type ReactNode } from 'react';
26
27
  import type { BaseProps } from '@astryxdesign/core';
27
28
  /**
28
- * Height budget for each named size. `medium`/`tall` track the viewport so
29
- * the sheet scales with the device; `short` is a fixed peek height. `auto`
30
- * is handled separately (fits content, capped at the `tall` budget).
29
+ * Height budget for each named size, as a fraction of the viewport:
30
+ * - `hug` — fits its content, never taller than 92%.
31
+ * - `capped` — a scrolling mid-height panel (62%).
32
+ * - `tall` — a pinned near-full panel (92%); use when content streams in so
33
+ * the sheet doesn't resize under the user.
31
34
  */
32
35
  declare const HEIGHT_BUDGETS: {
33
- readonly short: "240px";
34
- readonly medium: "50dvh";
35
- readonly tall: "90dvh";
36
- readonly auto: "90dvh";
36
+ readonly hug: "92dvh";
37
+ readonly capped: "62dvh";
38
+ readonly tall: "92dvh";
37
39
  };
38
40
  export type BottomSheetHeight = keyof typeof HEIGHT_BUDGETS;
39
41
  export interface BottomSheetProps extends BaseProps<HTMLDialogElement> {
@@ -42,8 +44,8 @@ export interface BottomSheetProps extends BaseProps<HTMLDialogElement> {
42
44
  /** Whether the sheet is open. Fully controlled — pair with `onOpenChange`. */
43
45
  isOpen: boolean;
44
46
  /**
45
- * Called when the sheet opens or closes. The boolean is the requested
46
- * next state (`false` on Escape, scrim click, or a swipe past the dismiss
47
+ * Called when the sheet opens or closes. The boolean is the requested next
48
+ * state (`false` on Escape, scrim click, or a swipe past the dismiss
47
49
  * threshold). The caller owns the open state.
48
50
  */
49
51
  onOpenChange: (isOpen: boolean) => void;
@@ -55,26 +57,30 @@ export interface BottomSheetProps extends BaseProps<HTMLDialogElement> {
55
57
  /** Sheet content, rendered below the grab handle in a scrollable area. */
56
58
  children: ReactNode;
57
59
  /**
58
- * How tall the sheet is:
59
- * - `'short'` — a fixed peek height
60
- * - `'medium'` — half the viewport
61
- * - `'tall'` — nearly the full viewport
62
- * - `'auto'` — fits its content, capped at the `'tall'` budget
60
+ * How tall the sheet is. A named budget, or any explicit height:
61
+ * - `'hug'` — fits its content, never taller than 92% of the viewport.
62
+ * - `'capped'` — a scrolling mid-height panel (~62%).
63
+ * - `'tall'` — a pinned near-full panel (~92%); use when content streams in
64
+ * so the sheet doesn't resize under the user.
65
+ * - a `number` (px) or CSS length string (e.g. `'70dvh'`, `480`) for a
66
+ * custom budget.
63
67
  *
64
- * On viewports shorter than the budget the sheet fills the available
65
- * height.
66
- * @default 'medium'
68
+ * The user can still drag between snap points regardless of the starting
69
+ * height. On viewports shorter than the budget the sheet fills the
70
+ * available height.
71
+ * @default 'capped'
67
72
  */
68
- height?: BottomSheetHeight;
73
+ height?: BottomSheetHeight | number | string;
69
74
  /** Test ID for the root element. */
70
75
  'data-testid'?: string;
71
76
  }
72
77
  /**
73
- * A mobile touch sheet that rises from the bottom edge, with a grab handle
74
- * and swipe-to-dismiss. Built on the lab Drawer's `<dialog>` engine
75
- * (`side="bottom"`): Drawer owns the open/close slide, focus trap + restore,
76
- * scroll lock, and the Escape/scrim contract, while BottomSheet layers the
77
- * grab handle and drag-to-dismiss on top.
78
+ * A mobile touch sheet that rises from the bottom edge, with a grab handle,
79
+ * drag-to-resize snap points, and swipe-to-dismiss. It owns a native modal
80
+ * `<dialog>` (top layer, focus trap, `::backdrop` scrim) and locks body scroll
81
+ * while open; a slow drag settles to the nearest snap point, a flick down
82
+ * dismisses, and Escape closes — so the swipe always has a keyboard
83
+ * equivalent.
78
84
  *
79
85
  * @example
80
86
  * ```
@@ -87,7 +93,7 @@ export interface BottomSheetProps extends BaseProps<HTMLDialogElement> {
87
93
  * </BottomSheet>
88
94
  * ```
89
95
  */
90
- export declare function BottomSheet({ isOpen, onOpenChange, label, children, height, xstyle, ...props }: BottomSheetProps): import("react").JSX.Element;
96
+ export declare function BottomSheet({ ref, isOpen, onOpenChange, label, children, height, xstyle, ...props }: BottomSheetProps): import("react").JSX.Element;
91
97
  export declare namespace BottomSheet {
92
98
  var displayName: string;
93
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheet.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAUlD;;;;GAIG;AACH,QAAA,MAAM,cAAc;;;;;CAKV,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,cAAc,CAAC;AAoE5D,MAAM,WAAW,gBAAiB,SAAQ,SAAS,CAAC,iBAAiB,CAAC;IACpE,wDAAwD;IACxD,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAEnC,8EAA8E;IAC9E,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAExC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd,0EAA0E;IAC1E,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B,oCAAoC;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,MAAiB,EACjB,MAAM,EACN,GAAG,KAAK,EACT,EAAE,gBAAgB,+BAoClB;yBA5Ce,WAAW"}
1
+ {"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/BottomSheet.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAiC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAErE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAqBlD;;;;;;GAMG;AACH,QAAA,MAAM,cAAc;;;;CAIV,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,cAAc,CAAC;AAyJ5D,MAAM,WAAW,gBAAiB,SAAQ,SAAS,CAAC,iBAAiB,CAAC;IACpE,wDAAwD;IACxD,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAEnC,8EAA8E;IAC9E,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAExC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd,0EAA0E;IAC1E,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;IAE7C,oCAAoC;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,EAC1B,GAAG,EACH,MAAM,EACN,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,MAAiB,EACjB,MAAM,EACN,GAAG,KAAK,EACT,EAAE,gBAAgB,+BAyKlB;yBAlLe,WAAW"}
@@ -4,21 +4,22 @@
4
4
 
5
5
  /**
6
6
  * @file BottomSheet.tsx
7
- * @input Uses React, StyleX, theme tokens, Drawer, useSheetGestures, themeProps
7
+ * @input Uses React, StyleX, theme tokens, core hooks (useScrollLock), utils, useSheetGestures
8
8
  * @output Exports BottomSheet component and BottomSheetProps
9
9
  * @position Lab implementation; consumed by index.ts, tested by BottomSheet.test.tsx, demonstrated in Storybook
10
10
  *
11
- * A mobile touch surface that rises from the bottom edge with a grab handle
12
- * and swipe-to-dismiss. Built ON TOP OF the lab Drawer's native `<dialog>`
13
- * engine (`side="bottom"`) rather than forking it — Drawer owns
14
- * showModal/show, the open/close slide animation, focus trap + restore,
15
- * scroll lock, the Escape/scrim contract, and the LIFO overlay registry.
16
- * BottomSheet layers the grab handle and the drag-to-dismiss gesture on top,
17
- * inside the dialog.
11
+ * A mobile touch surface that rises from the bottom edge: grab handle, snap
12
+ * points, and swipe-to-dismiss. It owns a native modal `<dialog>` directly and
13
+ * composes core primitives (`useScrollLock`, `<dialog>.showModal()` for the
14
+ * top layer + focus trap, a `::backdrop` scrim) rather than delegating to a
15
+ * heavier overlay component — so it controls its own sizing and can render a
16
+ * full-height transparent shell with the visible sheet bottom-anchored inside.
17
+ * That shell is what lets the sheet translate freely (including a little past
18
+ * fully-open) without clipping against a fixed dialog edge.
18
19
  *
19
- * The gesture translate is applied to an inner sheet wrapper, not the
20
- * `<dialog>` itself, so Drawer owns the open/close slide and the drag
21
- * translates within it without the two transforms fighting.
20
+ * The drag/snap/dismiss machinery lives in `useSheetGestures`; the offset
21
+ * geometry lives in the pure, tested `snapOffsets` module. Both are internal
22
+ * to BottomSheet and not exported from the lab entry point.
22
23
  *
23
24
  * SYNC: When modified, update these files to stay in sync:
24
25
  * - /packages/lab/src/BottomSheet/BottomSheet.doc.mjs (props table, features, usage)
@@ -26,64 +27,100 @@
26
27
  * - /packages/lab/src/BottomSheet/index.ts (exports if types change)
27
28
  * - /apps/storybook/stories/BottomSheet.stories.tsx (examples and visual coverage)
28
29
  */
30
+ import { useCallback, useEffect, useRef } from 'react';
29
31
  import * as stylex from '@stylexjs/stylex';
30
32
  import '@astryxdesign/core/theme/tokens.stylex';
31
- import { colorVars, radiusVars, spacingVars } from '@astryxdesign/core/theme/tokens.stylex';
32
- import { mergeProps, themeProps } from '@astryxdesign/core/utils';
33
- import { Drawer } from "../Drawer/index.js";
33
+ import { colorVars, durationVars, easeVars, radiusVars, shadowVars, sizeVars, spacingVars } from '@astryxdesign/core/theme/tokens.stylex';
34
+ import { useDevWarning, useScrollLock } from '@astryxdesign/core/hooks';
35
+ import { mergeProps, mergeRefs, themeProps } from '@astryxdesign/core/utils';
34
36
  import { useSheetGestures } from "./useSheetGestures.js";
35
37
 
38
+ // Detent fractions of the viewport, ascending (peek / mid / full). Detents
39
+ // that land within DETENT_DEDUP_PX of each other (e.g. a hug height next to a
40
+ // snap) are de-duped in the gesture hook, and any taller than the sheet are
41
+ // dropped, so a full set is safe to offer. The shortest is a glance "peek";
42
+ // the scrim hides as the sheet collapses onto it (see onScrimOpacity).
43
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
44
+ const SNAP_FRACTIONS = [0.14, 0.5, 0.92];
45
+
36
46
  /**
37
- * Height budget for each named size. `medium`/`tall` track the viewport so
38
- * the sheet scales with the device; `short` is a fixed peek height. `auto`
39
- * is handled separately (fits content, capped at the `tall` budget).
47
+ * Height budget for each named size, as a fraction of the viewport:
48
+ * - `hug` — fits its content, never taller than 92%.
49
+ * - `capped` — a scrolling mid-height panel (62%).
50
+ * - `tall` — a pinned near-full panel (92%); use when content streams in so
51
+ * the sheet doesn't resize under the user.
40
52
  */
41
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
42
53
  const HEIGHT_BUDGETS = {
43
- short: '240px',
44
- medium: '50dvh',
45
- tall: '90dvh',
46
- auto: '90dvh'
54
+ hug: '92dvh',
55
+ // upper bound only; the sheet hugs its content beneath it
56
+ capped: '62dvh',
57
+ tall: '92dvh'
47
58
  };
48
- // Sheets on wide touch devices (tablets) shouldn't stretch edge to edge;
49
- // cap and center them. Matches the `sm` layout breakpoint. On phones the
50
- // viewport is narrower than this, so the sheet stays full-width.
51
- const MAX_SHEET_WIDTH = 640;
59
+ // px the sheet extends below its budget as reserved padding, revealed by an
60
+ // upward overdrag rather than showing a gap.
61
+ // SYNC: must match OVERSCROLL_MAX in useSheetGestures.ts (the drag cap).
62
+ const OVERSCROLL_PADDING = 48;
63
+
64
+ /**
65
+ * Default snap detents in px, resolved against the *visual* viewport (like iOS
66
+ * detents), so a mid rest point is ~half the screen regardless of the sheet's
67
+ * own height budget. Read lazily at drag start (no persistent listener) so it
68
+ * reflects the live viewport after a rotation or the virtual keyboard opening.
69
+ * SSR-safe: returns `[]` off the client.
70
+ */
71
+ function defaultSnapHeights() {
72
+ if (typeof window === 'undefined') {
73
+ return [];
74
+ }
75
+ const vh = window.visualViewport?.height ?? window.innerHeight;
76
+ return SNAP_FRACTIONS.map(f => f * vh);
77
+ }
52
78
  const styles = {
53
79
  sheet: {
80
+ kfzvcC: "x67bb7w",
81
+ kB7OPa: "x9f619",
54
82
  k1xSpc: "x78zum5",
55
83
  kXwgrk: "xdt5ytf",
56
84
  kAzted: "x2lwn1j",
57
- kZKoxP: "x5yr21d",
58
85
  kzqmXN: "xh8yej3",
59
86
  ks0D6T: "x11gisft",
60
- kUOVxO: "xvueqy4",
61
87
  kWkggS: "x10xzikg",
62
- krdFHd: "x183tx6i",
63
- kfmiAY: "x663v1",
88
+ krdFHd: "x81l70g",
89
+ kfmiAY: "x7hs6f1",
90
+ kGVxlE: "x1kcpxr7",
91
+ kI3sdo: "x1a2a7pz",
64
92
  kVQacm: "xb3r6kr",
65
- kGO01o: "x1a148e8",
93
+ kGO01o: "x1wkw6tp",
94
+ k1K539: "x1if0o47",
95
+ k3aq6I: "xnn1q72 xhbqy3z",
96
+ k1ekBW: "x11xpdln",
97
+ kIyJzY: "x80gvsz",
98
+ kAMwcw: "xlr8y92",
66
99
  k6sLGO: "x1so62im",
100
+ k6CgDc: "xzg1mie",
101
+ $$css: true
102
+ },
103
+ sheetClosing: {
104
+ k3aq6I: "x1weeur4",
67
105
  $$css: true
68
106
  },
69
- dialogSurface: {
70
- kWkggS: "xjbqb8w",
71
- kGVxlE: "x1gnnqk1",
72
- kEafiO: "x972fbf",
107
+ budget: {
108
+ kZKoxP: "x1tpcejd",
73
109
  $$css: true
74
110
  },
75
- autoHeight: {
111
+ hugHeight: {
76
112
  kZKoxP: "xg7h5cd",
77
- kskxy: "x1ismmbu",
113
+ kskxy: "x14bu9tk",
78
114
  $$css: true
79
115
  }
80
116
  };
81
117
  /**
82
- * A mobile touch sheet that rises from the bottom edge, with a grab handle
83
- * and swipe-to-dismiss. Built on the lab Drawer's `<dialog>` engine
84
- * (`side="bottom"`): Drawer owns the open/close slide, focus trap + restore,
85
- * scroll lock, and the Escape/scrim contract, while BottomSheet layers the
86
- * grab handle and drag-to-dismiss on top.
118
+ * A mobile touch sheet that rises from the bottom edge, with a grab handle,
119
+ * drag-to-resize snap points, and swipe-to-dismiss. It owns a native modal
120
+ * `<dialog>` (top layer, focus trap, `::backdrop` scrim) and locks body scroll
121
+ * while open; a slow drag settles to the nearest snap point, a flick down
122
+ * dismisses, and Escape closes — so the swipe always has a keyboard
123
+ * equivalent.
87
124
  *
88
125
  * @example
89
126
  * ```
@@ -97,53 +134,163 @@ const styles = {
97
134
  * ```
98
135
  */
99
136
  export function BottomSheet({
137
+ ref,
100
138
  isOpen,
101
139
  onOpenChange,
102
140
  label,
103
141
  children,
104
- height = 'medium',
142
+ height = 'capped',
105
143
  xstyle,
106
144
  ...props
107
145
  }) {
108
- const close = () => onOpenChange(false);
146
+ const dialogRef = useRef(null);
147
+ const triggerRef = useRef(null);
148
+ const sheetNodeRef = useRef(null);
149
+ const close = useCallback(() => onOpenChange(false), [onOpenChange]);
150
+
151
+ // Set imperatively (not via state) so a 60fps drag doesn't re-render. The
152
+ // hook reports the scrim opacity for the current detent (hidden at the peek).
153
+ const handleScrimOpacity = useCallback(opacity => {
154
+ dialogRef.current?.style.setProperty('--_sheet-scrim-opacity', String(opacity));
155
+ }, []);
109
156
  const {
110
157
  contentProps,
111
- handleProps
158
+ handleProps,
159
+ bodyProps,
160
+ sheetRef
112
161
  } = useSheetGestures({
113
162
  isOpen,
114
- onDismiss: close
163
+ onDismiss: close,
164
+ snapHeights: defaultSnapHeights,
165
+ onScrimOpacity: handleScrimOpacity
115
166
  });
116
- return /*#__PURE__*/_jsx(Drawer, {
117
- isOpen: isOpen,
118
- onClose: close,
119
- side: "bottom",
120
- size: HEIGHT_BUDGETS[height],
121
- label: label,
122
- hasScrim: true,
123
- hasCloseButton: false,
124
- xstyle: [styles.dialogSurface, height === 'auto' && styles.autoHeight],
167
+
168
+ // showModal() enters the top layer with a focus trap + ::backdrop; on close
169
+ // we animate out (below) then restore focus to the opener.
170
+ useEffect(() => {
171
+ const dialog = dialogRef.current;
172
+ if (!dialog) {
173
+ return;
174
+ }
175
+ if (isOpen) {
176
+ triggerRef.current = document.activeElement;
177
+ dialog.style.setProperty('--_sheet-scrim-opacity', '1');
178
+ if (!dialog.open) {
179
+ dialog.showModal();
180
+ // Override showModal()'s default (first tabbable) to land on the panel,
181
+ // so AT reads from the label — unless a descendant sets data-autofocus.
182
+ const autofocus = dialog.querySelector('[data-autofocus]');
183
+ if (autofocus) {
184
+ autofocus.focus();
185
+ } else {
186
+ sheetNodeRef.current?.focus();
187
+ }
188
+ }
189
+ } else if (dialog.open) {
190
+ // Wait for the slide-out (sheetClosing, applied this render) before
191
+ // close() releases the top layer. Timeout backstops a missing
192
+ // transitionend (reduced motion, hidden tab).
193
+ const sheet = sheetNodeRef.current;
194
+ let done = false;
195
+ const finish = () => {
196
+ if (done) {
197
+ return;
198
+ }
199
+ done = true;
200
+ clearTimeout(timer);
201
+ sheet?.removeEventListener('transitionend', onEnd);
202
+ if (dialog.open) {
203
+ dialog.close();
204
+ }
205
+ triggerRef.current?.focus();
206
+ triggerRef.current = null;
207
+ };
208
+ const onEnd = event => {
209
+ if (event.target === sheet && event.propertyName === 'transform') {
210
+ finish();
211
+ }
212
+ };
213
+ sheet?.addEventListener('transitionend', onEnd);
214
+ // Backstop above --duration-medium (410ms) so transitionend normally
215
+ // fires first; this only covers environments that don't emit it.
216
+ const timer = setTimeout(finish, 450);
217
+ return () => {
218
+ clearTimeout(timer);
219
+ sheet?.removeEventListener('transitionend', onEnd);
220
+ };
221
+ }
222
+ }, [isOpen]);
223
+ useScrollLock(isOpen);
224
+
225
+ // Enforce an accessible name: label is required by types, but a JS caller
226
+ // can still pass an empty string, leaving the sheet unnamed.
227
+ useDevWarning('BottomSheet', 'requires a non-empty `label` for an accessible name; the open sheet ' + 'has no built-in heading to derive one from.', isOpen && !label);
228
+ const handleCancel = useCallback(event => {
229
+ event.preventDefault();
230
+ close();
231
+ }, [close]);
232
+ // Explicit Escape handler in addition to the native `cancel` event, for
233
+ // environments that don't synthesize `cancel`.
234
+ const handleKeyDown = useCallback(event => {
235
+ if (event.key === 'Escape') {
236
+ event.preventDefault();
237
+ close();
238
+ }
239
+ }, [close]);
240
+ const handleClick = useCallback(event => {
241
+ if (event.target === event.currentTarget) {
242
+ close();
243
+ }
244
+ }, [close]);
245
+ const isNamed = typeof height === 'string' && height in HEIGHT_BUDGETS;
246
+ const budget = isNamed ? HEIGHT_BUDGETS[height] : typeof height === 'number' ? `${height}px` : height;
247
+ const isHug = height === 'hug';
248
+ return /*#__PURE__*/_jsx("dialog", {
249
+ ...{
250
+ 0: {
251
+ className: "xixxii4 x10a8y8t x1o6l61p xtdtrs8 x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1s85apg x1a2a7pz xnixb3f x1abwkk1 xni466t xxiuuzi xc0dz0a xft5bk6 x15h3t91 x142juwg x1viac0w"
252
+ },
253
+ 1: {
254
+ className: "xixxii4 x10a8y8t x1o6l61p xtdtrs8 x1x1rfll x7ab17h x1ghz6dp x1717udv xjbqb8w x1rea2x4 x1a2a7pz x1lliihq xnixb3f x1abwkk1 xni466t xxiuuzi xc0dz0a xft5bk6 x15h3t91 x142juwg x1viac0w"
255
+ }
256
+ }[!!isOpen << 0],
257
+ ref: mergeRefs(ref, dialogRef),
258
+ "aria-label": label,
259
+ "aria-modal": "true",
260
+ onCancel: handleCancel,
261
+ onClick: handleClick,
262
+ onKeyDown: handleKeyDown,
125
263
  ...props,
126
- children: /*#__PURE__*/_jsxs("div", {
127
- "data-astryx-sheet": "",
128
- ...mergeProps(themeProps('bottom-sheet'), stylex.props(styles.sheet, xstyle), contentProps.style),
129
- children: [/*#__PURE__*/_jsx("div", {
130
- "data-astryx-sheet-handle": "",
131
- ...{
132
- className: "x2lah0s x78zum5 x6s0dn4 xl56j7k xce4md1 x5ve5x3 x1jm3nie"
133
- },
134
- ...handleProps,
135
- "aria-hidden": "true",
136
- children: /*#__PURE__*/_jsx("div", {
264
+ children: /*#__PURE__*/_jsx("div", {
265
+ ...{
266
+ className: "x10l6tqk x17y0mx6 x1ey2m1c x78zum5 xl56j7k x47corl"
267
+ },
268
+ children: /*#__PURE__*/_jsxs("div", {
269
+ ref: mergeRefs(sheetRef, sheetNodeRef),
270
+ tabIndex: -1,
271
+ ...mergeProps(themeProps('bottom-sheet'), stylex.props(styles.sheet, isHug ? styles.hugHeight : styles.budget, !isOpen && styles.sheetClosing, xstyle), undefined, {
272
+ ['--_sheet-budget']: budget,
273
+ ...contentProps.style
274
+ }),
275
+ children: [/*#__PURE__*/_jsx("div", {
276
+ ...{
277
+ className: "x2lah0s x78zum5 x6s0dn4 xl56j7k x1k15mir x5ve5x3 x1jm3nie"
278
+ },
279
+ ...handleProps,
280
+ "aria-hidden": "true",
281
+ children: /*#__PURE__*/_jsx("div", {
282
+ ...{
283
+ className: "x1m747yf x11c6zpc xjspbzw x1m4xfpy"
284
+ }
285
+ })
286
+ }), /*#__PURE__*/_jsx("div", {
137
287
  ...{
138
- className: "x14qfxbe xqu0tyb xjspbzw x1m4xfpy"
139
- }
140
- })
141
- }), /*#__PURE__*/_jsx("div", {
142
- ...{
143
- className: "x1iyjqo2 x2lwn1j x1odjw0f xish69e"
144
- },
145
- children: children
146
- })]
288
+ className: "x1iyjqo2 x2lwn1j x1odjw0f x8du1vd xx69xxh"
289
+ },
290
+ ...bodyProps,
291
+ children: children
292
+ })]
293
+ })
147
294
  })
148
295
  });
149
296
  }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file snapOffsets.ts
3
+ * @input Pure geometry helpers — no React, no DOM.
4
+ * @output Converts snap points to translateY offsets for the sheet surface.
5
+ * @position Internal to BottomSheet; consumed by useSheetGestures, tested by
6
+ * snapOffsets.test.ts.
7
+ *
8
+ * The sheet is rendered at its full (fully-open) height and *translated down*
9
+ * to express shorter detents — translate is GPU-composited, so this is cheaper
10
+ * than animating layout height. A detent is therefore a translateY offset in
11
+ * px from the fully-open position (0 = fully open, larger = more collapsed).
12
+ * These helpers turn snap points into that offset list; they are pure so the
13
+ * geometry can be unit-tested without a DOM.
14
+ */
15
+ /**
16
+ * Detents whose resting offsets land within this many px of each other are
17
+ * treated as the same stop (the taller one wins). Stops the sheet from having
18
+ * two near-identical rest positions — e.g. when a content-hugging height sits
19
+ * a hair away from a fractional snap point.
20
+ */
21
+ export declare const DETENT_DEDUP_PX = 48;
22
+ /** Resolve snap points given as viewport fractions (0, 1] to px heights. */
23
+ export declare function snapFractionsToHeights(fractions: readonly number[], viewportPx: number): number[];
24
+ /**
25
+ * Given the sheet's full height (px, as rendered fully open) and a set of
26
+ * candidate detent *visible heights* (px), return the resting translateY
27
+ * offsets from fully-open, ascending and de-duplicated.
28
+ *
29
+ * - `0` (fully open) is always the first detent.
30
+ * - Only heights strictly shorter than the sheet become collapsed detents; a
31
+ * height >= the sheet can't be shown by translating down, so it's dropped.
32
+ * - Offsets closer than `dedupPx` collapse to the smaller (taller) offset, so
33
+ * near-identical detents — e.g. a hug height ≈ a snap point — become one stop.
34
+ */
35
+ export declare function computeDetentOffsets(sheetHeight: number, detentHeights: readonly number[], dedupPx?: number): number[];
36
+ /** Nearest value in `offsets` to `value` (offsets must be non-empty). */
37
+ export declare function nearestOffset(value: number, offsets: readonly number[]): number;
38
+ /**
39
+ * Scrim opacity (1 = fully visible, 0 = hidden) for a drag/settle `offset`.
40
+ * The scrim stays full while the sheet is at or above its second-shortest
41
+ * detent, then fades to 0 as it collapses onto the shortest ("peek") detent —
42
+ * a glance state that reveals the content behind — and stays hidden below it.
43
+ * A single-detent sheet has no peek, so it instead fades across the dismiss
44
+ * overshoot toward `dismissOffset`.
45
+ */
46
+ export declare function scrimOpacityForOffset(offset: number, offsets: readonly number[], dismissOffset: number): number;
47
+ /**
48
+ * Settle target for a released drag. Restricts candidates to the drag
49
+ * direction so a committed drag never snaps *back past* where it started
50
+ * (a down-drag settles at/below the start, an up-drag at/above), then picks
51
+ * the nearest remaining detent. `dir`: 1 = dragged down, -1 = up, 0 = neither.
52
+ */
53
+ export declare function resolveSettleOffset(value: number, offsets: readonly number[], dir: number, baseOffset: number): number;
54
+ //# sourceMappingURL=snapOffsets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapOffsets.d.ts","sourceRoot":"","sources":["../../src/BottomSheet/snapOffsets.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,4EAA4E;AAC5E,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,UAAU,EAAE,MAAM,GACjB,MAAM,EAAE,CAEV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,OAAO,GAAE,MAAwB,GAChC,MAAM,EAAE,CAcV;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,CAKR;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,aAAa,EAAE,MAAM,GACpB,MAAM,CAWR;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,MAAM,CAcR"}