glasslikeui 1.9.1 → 1.10.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.
Files changed (128) hide show
  1. package/README.md +887 -26
  2. package/dist/actions/adaptiveTone.d.ts +50 -0
  3. package/dist/actions/adaptiveTone.js +569 -0
  4. package/dist/actions/alertLogic.d.ts +67 -0
  5. package/dist/actions/alertLogic.js +123 -0
  6. package/dist/actions/anchorPlacement.d.ts +92 -0
  7. package/dist/actions/anchorPlacement.js +137 -0
  8. package/dist/actions/dragSnap.d.ts +1 -1
  9. package/dist/actions/dragSnapMath.d.ts +70 -0
  10. package/dist/actions/dragSnapMath.js +115 -0
  11. package/dist/actions/glassToneLogic.d.ts +182 -0
  12. package/dist/actions/glassToneLogic.js +513 -0
  13. package/dist/actions/heightTransition.d.ts +32 -0
  14. package/dist/actions/heightTransition.js +64 -0
  15. package/dist/actions/index.d.ts +1 -0
  16. package/dist/actions/index.js +1 -0
  17. package/dist/actions/inertSiblings.js +20 -4
  18. package/dist/actions/menuLogic.d.ts +40 -0
  19. package/dist/actions/menuLogic.js +68 -0
  20. package/dist/actions/modalDialog.d.ts +19 -0
  21. package/dist/actions/modalDialog.js +48 -0
  22. package/dist/actions/popoverLogic.d.ts +25 -0
  23. package/dist/actions/popoverLogic.js +48 -0
  24. package/dist/actions/rovingIndex.d.ts +30 -0
  25. package/dist/actions/rovingIndex.js +49 -0
  26. package/dist/actions/scrollRunTracker.d.ts +36 -0
  27. package/dist/actions/scrollRunTracker.js +77 -0
  28. package/dist/actions/scrollUnder.d.ts +21 -0
  29. package/dist/actions/scrollUnder.js +29 -0
  30. package/dist/actions/segmentedLogic.d.ts +38 -0
  31. package/dist/actions/segmentedLogic.js +59 -0
  32. package/dist/actions/sheetLogic.d.ts +25 -7
  33. package/dist/actions/sheetLogic.js +43 -10
  34. package/dist/actions/sliderLogic.d.ts +29 -0
  35. package/dist/actions/sliderLogic.js +53 -0
  36. package/dist/actions/swipeActions.d.ts +46 -2
  37. package/dist/actions/swipeActions.js +267 -46
  38. package/dist/actions/tabBarMinimize.d.ts +31 -0
  39. package/dist/actions/tabBarMinimize.js +38 -0
  40. package/dist/actions/tabViewLogic.d.ts +47 -0
  41. package/dist/actions/tabViewLogic.js +71 -0
  42. package/dist/actions/toggleKnobLogic.d.ts +57 -0
  43. package/dist/actions/toggleKnobLogic.js +66 -0
  44. package/dist/actions/toolbarFocus.d.ts +44 -0
  45. package/dist/actions/toolbarFocus.js +228 -0
  46. package/dist/actions/topLayer.d.ts +12 -0
  47. package/dist/actions/topLayer.js +18 -0
  48. package/dist/components/dialog/ActionSheet.svelte +457 -0
  49. package/dist/components/dialog/ActionSheet.svelte.d.ts +25 -0
  50. package/dist/components/dialog/Alert.svelte +337 -0
  51. package/dist/components/dialog/Alert.svelte.d.ts +28 -0
  52. package/dist/components/dialog/index.d.ts +6 -0
  53. package/dist/components/dialog/index.js +6 -0
  54. package/dist/components/glass/Glass.svelte +49 -17
  55. package/dist/components/glass/Glass.svelte.d.ts +8 -0
  56. package/dist/components/glass/GlassSection.svelte +9 -1
  57. package/dist/components/glass/LensFilters.svelte +4 -2
  58. package/dist/components/glass/Popover.svelte +379 -0
  59. package/dist/components/glass/Popover.svelte.d.ts +30 -0
  60. package/dist/components/glass/Sheet.svelte +450 -105
  61. package/dist/components/glass/Sheet.svelte.d.ts +55 -7
  62. package/dist/components/glass/index.d.ts +3 -0
  63. package/dist/components/glass/index.js +1 -0
  64. package/dist/components/index.d.ts +2 -0
  65. package/dist/components/index.js +4 -0
  66. package/dist/components/interactive/Badge.svelte +97 -6
  67. package/dist/components/interactive/Badge.svelte.d.ts +13 -2
  68. package/dist/components/interactive/Button.svelte +159 -20
  69. package/dist/components/interactive/Button.svelte.d.ts +14 -1
  70. package/dist/components/interactive/IconButton.svelte +214 -4
  71. package/dist/components/interactive/IconButton.svelte.d.ts +2 -1
  72. package/dist/components/interactive/ProgressView.svelte +306 -0
  73. package/dist/components/interactive/ProgressView.svelte.d.ts +25 -0
  74. package/dist/components/interactive/Segment.d.ts +14 -0
  75. package/dist/components/interactive/Segment.js +1 -0
  76. package/dist/components/interactive/SegmentedControl.svelte +399 -0
  77. package/dist/components/interactive/SegmentedControl.svelte.d.ts +17 -0
  78. package/dist/components/interactive/Slider.svelte +299 -0
  79. package/dist/components/interactive/Slider.svelte.d.ts +23 -0
  80. package/dist/components/interactive/TabView.svelte +573 -41
  81. package/dist/components/interactive/TabView.svelte.d.ts +25 -0
  82. package/dist/components/interactive/Toggle.svelte +287 -16
  83. package/dist/components/interactive/Toggle.svelte.d.ts +12 -0
  84. package/dist/components/interactive/index.d.ts +4 -0
  85. package/dist/components/interactive/index.js +3 -0
  86. package/dist/components/list/List.svelte +41 -17
  87. package/dist/components/list/List.svelte.d.ts +1 -0
  88. package/dist/components/list/ListRow.svelte +208 -47
  89. package/dist/components/list/ListRow.svelte.d.ts +16 -1
  90. package/dist/components/menu/Menu.svelte +51 -27
  91. package/dist/components/menu/Menu.svelte.d.ts +5 -0
  92. package/dist/components/menu/MenuItem.svelte +82 -25
  93. package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
  94. package/dist/components/menu/MenuSection.svelte +95 -0
  95. package/dist/components/menu/MenuSection.svelte.d.ts +18 -0
  96. package/dist/components/menu/MenuSubmenu.svelte +196 -0
  97. package/dist/components/menu/MenuSubmenu.svelte.d.ts +11 -0
  98. package/dist/components/menu/index.d.ts +4 -1
  99. package/dist/components/menu/index.js +3 -1
  100. package/dist/components/navigation/NavigationBar.svelte +97 -15
  101. package/dist/components/navigation/NavigationBar.svelte.d.ts +6 -0
  102. package/dist/components/toolbar/Toolbar.svelte +43 -0
  103. package/dist/components/toolbar/Toolbar.svelte.d.ts +13 -0
  104. package/dist/components/toolbar/ToolbarItemGroup.svelte +45 -0
  105. package/dist/components/toolbar/ToolbarItemGroup.svelte.d.ts +14 -0
  106. package/dist/components/toolbar/ToolbarSpacer.svelte +36 -0
  107. package/dist/components/toolbar/ToolbarSpacer.svelte.d.ts +12 -0
  108. package/dist/components/toolbar/index.d.ts +7 -0
  109. package/dist/components/toolbar/index.js +7 -0
  110. package/dist/components/typography/Text.svelte +9 -1
  111. package/dist/constants/alertAction.d.ts +19 -0
  112. package/dist/constants/alertAction.js +1 -0
  113. package/dist/constants/badge.d.ts +32 -0
  114. package/dist/constants/badge.js +47 -0
  115. package/dist/constants/buttons.d.ts +45 -0
  116. package/dist/constants/buttons.js +52 -0
  117. package/dist/constants/colors.d.ts +9 -4
  118. package/dist/constants/colors.js +9 -4
  119. package/dist/constants/index.d.ts +3 -0
  120. package/dist/constants/index.js +3 -0
  121. package/dist/constants/progress.d.ts +56 -0
  122. package/dist/constants/progress.js +75 -0
  123. package/dist/constants/variants.d.ts +6 -2
  124. package/dist/constants/variants.js +2 -2
  125. package/dist/styles/glasslikeui.css +128 -1
  126. package/dist/styles/lens.css +21 -19
  127. package/dist/styles/squircle.css +17 -7
  128. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ /** A label longer than this does not fit beside another, so the buttons stack. */
11
+ export var LONG_ACTION_LABEL = 14;
12
+ /** The index of the first cancel action, or -1. */
13
+ function cancelIndex(actions) {
14
+ return actions.findIndex(function (action) { return action.role === 'cancel'; });
15
+ }
16
+ /**
17
+ * Lays out an alert's buttons as iOS 26 does. One or two short buttons sit in
18
+ * a row with the cancel button leading. Three or more, or a label too long to
19
+ * share the row, stack, with the cancel button last.
20
+ */
21
+ export function alertLayout(actions) {
22
+ var cancel = cancelIndex(actions);
23
+ var rest = actions.map(function (_, i) { return i; }).filter(function (i) { return i !== cancel; });
24
+ var fits = actions.every(function (action) { return action.label.length <= LONG_ACTION_LABEL; });
25
+ if (actions.length <= 2 && fits) {
26
+ return { axis: 'horizontal', order: cancel < 0 ? rest : __spreadArray([cancel], rest, true) };
27
+ }
28
+ return { axis: 'vertical', order: cancel < 0 ? rest : __spreadArray(__spreadArray([], rest, true), [cancel], false) };
29
+ }
30
+ /**
31
+ * The action Escape runs, or null. It is the cancel action. A one button alert
32
+ * with no cancel, such as an OK alert, runs that button, since it only
33
+ * acknowledges. Otherwise Escape does nothing: the choice has to be made. A
34
+ * disabled action never runs.
35
+ */
36
+ export function escapeActionIndex(actions) {
37
+ var cancel = cancelIndex(actions);
38
+ var index = cancel >= 0 ? cancel : actions.length === 1 ? 0 : -1;
39
+ if (index < 0 || actions[index].disabled)
40
+ return null;
41
+ return index;
42
+ }
43
+ /**
44
+ * The action that takes focus when the dialog opens, or null to focus the
45
+ * dialog itself. The WAI-ARIA alertdialog pattern asks for the least
46
+ * destructive choice: the cancel action, else the first that is not
47
+ * destructive, else the first that is enabled. With `cancelHidden` (an
48
+ * anchored action sheet, whose Cancel is kept for assistive technology but
49
+ * not drawn) the choice is the first visible action that is not destructive.
50
+ * When there is none (the usual "Delete Photo, Cancel" sheet) the answer is
51
+ * null, so the dialog itself takes focus: one Return never runs a destructive
52
+ * action, the sheet opens looking as iOS draws it, and Tab still reaches the
53
+ * hidden Cancel, which shows itself on focus.
54
+ */
55
+ export function initialFocusIndex(actions, cancelHidden) {
56
+ var _a, _b;
57
+ if (cancelHidden === void 0) { cancelHidden = false; }
58
+ var enabled = actions.map(function (action, i) { return ({ action: action, i: i }); }).filter(function (_a) {
59
+ var action = _a.action;
60
+ return !action.disabled;
61
+ });
62
+ var pick = cancelHidden
63
+ ? enabled.find(function (_a) {
64
+ var action = _a.action;
65
+ return action.role !== 'cancel' && action.role !== 'destructive';
66
+ })
67
+ : ((_b = (_a = enabled.find(function (_a) {
68
+ var action = _a.action;
69
+ return action.role === 'cancel';
70
+ })) !== null && _a !== void 0 ? _a : enabled.find(function (_a) {
71
+ var action = _a.action;
72
+ return action.role !== 'destructive';
73
+ })) !== null && _b !== void 0 ? _b : enabled[0]);
74
+ return pick ? pick.i : null;
75
+ }
76
+ /** The action Return runs from the alert's text field: the first enabled preferred one, or null. */
77
+ export function submitActionIndex(actions) {
78
+ var index = actions.findIndex(function (action) { return action.preferred && !action.disabled; });
79
+ return index < 0 ? null : index;
80
+ }
81
+ /** Splits an action sheet's actions into the main group and the cancel action, drawn apart on iOS. */
82
+ export function actionSheetGroups(actions) {
83
+ var cancel = cancelIndex(actions);
84
+ return {
85
+ main: actions.map(function (_, i) { return i; }).filter(function (i) { return i !== cancel; }),
86
+ cancel: cancel < 0 ? null : cancel
87
+ };
88
+ }
89
+ /**
90
+ * What is wrong with a list of actions, as messages for a console warning. An
91
+ * empty list is fine for an Alert, which falls back to an OK button.
92
+ */
93
+ export function alertActionProblems(actions) {
94
+ var problems = [];
95
+ if (actions.filter(function (action) { return action.role === 'cancel'; }).length > 1) {
96
+ problems.push('more than one action has role "cancel"; only the first is treated as cancel');
97
+ }
98
+ if (actions.some(function (action) { return action.label.trim() === ''; })) {
99
+ problems.push('an action has an empty label, so its button has no accessible name');
100
+ }
101
+ return problems;
102
+ }
103
+ /** Writes each problem with the actions to the console, once per call, naming the component. */
104
+ export function warnAlertActions(component, actions) {
105
+ for (var _i = 0, _a = alertActionProblems(actions); _i < _a.length; _i++) {
106
+ var problem = _a[_i];
107
+ console.warn("[glasslikeui] ".concat(component, ": ").concat(problem, "."));
108
+ }
109
+ }
110
+ /** The button an Alert shows when it is given no actions, as SwiftUI's alert does. */
111
+ export var DEFAULT_ALERT_ACTIONS = Object.freeze([{ label: 'OK' }]);
112
+ /**
113
+ * What Escape or a tap outside does to an action sheet. With a cancel action
114
+ * it runs that action, or nothing while it is disabled. With none the sheet
115
+ * just closes ('close'): unlike an alert, an action sheet can always be put
116
+ * away without choosing.
117
+ */
118
+ export function actionSheetDismissal(actions) {
119
+ var cancel = cancelIndex(actions);
120
+ if (cancel < 0)
121
+ return 'close';
122
+ return actions[cancel].disabled ? null : cancel;
123
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Where a panel that grows out of a control goes, and how it grows. Popover and
3
+ * Menu use these, so the decisions are plain functions that mutation testing
4
+ * reaches (Stryker cannot instrument .svelte files). Internal.
5
+ */
6
+ /** A box in viewport pixels, as getBoundingClientRect reports it. */
7
+ export interface AnchorRect {
8
+ top: number;
9
+ left: number;
10
+ width: number;
11
+ height: number;
12
+ }
13
+ /** A width and a height in pixels. */
14
+ export interface PanelSize {
15
+ width: number;
16
+ height: number;
17
+ }
18
+ /** Which edge of the panel lines up with the matching edge of the anchor. */
19
+ export type AnchorAlignment = 'start' | 'center' | 'end';
20
+ /** The side of the anchor the panel sits on. */
21
+ export type AnchorSide = 'top' | 'bottom';
22
+ /** Below this viewport width the layout is compact (an iPhone in portrait), so a popover becomes a sheet. */
23
+ export declare const COMPACT_WIDTH = 600;
24
+ /** Space between the anchor and the panel. */
25
+ export declare const ANCHOR_GAP = 8;
26
+ /** The closest the panel comes to a viewport edge. */
27
+ export declare const VIEWPORT_MARGIN = 8;
28
+ /** True when the viewport is too narrow for an anchored popover, as in a compact size class. */
29
+ export declare function isCompactWidth(viewportWidth: number): boolean;
30
+ /** Where an anchored panel goes, and the point inside it that it grows from. */
31
+ export interface AnchorPlacement {
32
+ top: number;
33
+ left: number;
34
+ side: AnchorSide;
35
+ /** The anchor's centre, from the panel's top left, kept inside the panel. */
36
+ originX: number;
37
+ originY: number;
38
+ }
39
+ /**
40
+ * Places a panel next to its anchor. It goes below the anchor when it fits
41
+ * there, else above when it fits there, else on the side with more room. The
42
+ * horizontal edge follows `align` (logical, so swapped under right to left
43
+ * text), then the panel is kept `VIEWPORT_MARGIN` inside the viewport.
44
+ */
45
+ export declare function placeAnchored(anchor: AnchorRect, panel: PanelSize, viewport: PanelSize, align?: AnchorAlignment, rtl?: boolean, lockedSide?: AnchorSide | undefined): AnchorPlacement;
46
+ /** The transform that lays a panel exactly over its anchor, the first frame of the grow. */
47
+ export interface MorphStart {
48
+ translateX: number;
49
+ translateY: number;
50
+ scaleX: number;
51
+ scaleY: number;
52
+ }
53
+ /** The smallest scale used, so a zero sized anchor never collapses the panel to nothing. */
54
+ export declare const MIN_MORPH_SCALE = 0.01;
55
+ /**
56
+ * The start of a grow from the anchor's glass: with `transform-origin: 0 0`,
57
+ * this transform shrinks the panel onto the anchor's box. Animating from it to
58
+ * no transform makes the panel grow out of the control, as menus and popovers
59
+ * do on iOS 26.
60
+ */
61
+ export declare function morphStart(anchor: AnchorRect, panel: AnchorRect): MorphStart;
62
+ /** The CSS transform for a MorphStart. */
63
+ export declare function morphTransform(start: MorphStart): string;
64
+ /** How long the grow from the anchor runs, matching --transition-spring. */
65
+ export declare const GROW_DURATION_MS = 400;
66
+ /** The easing of the grow, matching --transition-spring. */
67
+ export declare const GROW_EASING = "cubic-bezier(0.32, 0.72, 0, 1)";
68
+ /**
69
+ * Grows a panel out of its anchor with the Web Animations API. Under reduced
70
+ * motion it fades in instead, with no change of size or place. Returns the
71
+ * animation, or null where the browser has no `animate`.
72
+ */
73
+ export declare function playGrow(panel: HTMLElement, anchor: Element, reducedMotion: boolean): Animation | null;
74
+ /**
75
+ * The side of the anchor for a panel that can reveal a part beside it (the
76
+ * anchored ActionSheet's Cancel). The panel and the revealed part, with the
77
+ * gap between them, are sized together, so the part has room on the far side
78
+ * from the anchor whenever the viewport allows: below when that fits, else
79
+ * above when that fits. When neither side fits both, the side is the one
80
+ * `placeAnchored` would choose for the panel alone, and the part then takes
81
+ * the near side (see revealOffset).
82
+ */
83
+ export declare function revealSide(anchor: AnchorRect, panel: PanelSize, revealHeight: number, viewport: PanelSize): AnchorSide;
84
+ /**
85
+ * Where a part revealed beside an anchored panel goes, as an offset from the
86
+ * panel's top: the anchored ActionSheet's Cancel, which shows on keyboard
87
+ * focus. It is drawn over the page, never in the panel's flow, so the
88
+ * panel's rows never move. It goes on the panel's far side from the anchor
89
+ * when it fits there, else on the near side, and is then kept inside the
90
+ * viewport (over the panel only when neither side has room).
91
+ */
92
+ export declare function revealOffset(side: AnchorSide, panelTop: number, panelHeight: number, revealHeight: number, viewportHeight: number): number;
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Where a panel that grows out of a control goes, and how it grows. Popover and
3
+ * Menu use these, so the decisions are plain functions that mutation testing
4
+ * reaches (Stryker cannot instrument .svelte files). Internal.
5
+ */
6
+ /** Below this viewport width the layout is compact (an iPhone in portrait), so a popover becomes a sheet. */
7
+ export var COMPACT_WIDTH = 600;
8
+ /** Space between the anchor and the panel. */
9
+ export var ANCHOR_GAP = 8;
10
+ /** The closest the panel comes to a viewport edge. */
11
+ export var VIEWPORT_MARGIN = 8;
12
+ /** True when the viewport is too narrow for an anchored popover, as in a compact size class. */
13
+ export function isCompactWidth(viewportWidth) {
14
+ return viewportWidth < COMPACT_WIDTH;
15
+ }
16
+ function clamp(value, min, max) {
17
+ // When the panel is wider than the room, the start edge wins.
18
+ return Math.max(min, Math.min(value, max));
19
+ }
20
+ /**
21
+ * Places a panel next to its anchor. It goes below the anchor when it fits
22
+ * there, else above when it fits there, else on the side with more room. The
23
+ * horizontal edge follows `align` (logical, so swapped under right to left
24
+ * text), then the panel is kept `VIEWPORT_MARGIN` inside the viewport.
25
+ */
26
+ export function placeAnchored(anchor, panel, viewport, align, rtl, lockedSide) {
27
+ if (align === void 0) { align = 'start'; }
28
+ if (rtl === void 0) { rtl = false; }
29
+ var below = viewport.height - (anchor.top + anchor.height) - ANCHOR_GAP - VIEWPORT_MARGIN;
30
+ var above = anchor.top - ANCHOR_GAP - VIEWPORT_MARGIN;
31
+ // Below when it fits there. Otherwise the roomier side, which is above
32
+ // whenever the panel fits above, and below on a tie.
33
+ // A `lockedSide` keeps the side chosen earlier, so the panel never flips while it is open.
34
+ var side = lockedSide !== null && lockedSide !== void 0 ? lockedSide : (panel.height <= below || below >= above ? 'bottom' : 'top');
35
+ var rawTop = side === 'bottom'
36
+ ? anchor.top + anchor.height + ANCHOR_GAP
37
+ : anchor.top - ANCHOR_GAP - panel.height;
38
+ var top = clamp(rawTop, VIEWPORT_MARGIN, viewport.height - VIEWPORT_MARGIN - panel.height);
39
+ var physical = rtl ? (align === 'start' ? 'end' : align === 'end' ? 'start' : align) : align;
40
+ var rawLeft;
41
+ if (physical === 'start')
42
+ rawLeft = anchor.left;
43
+ else if (physical === 'end')
44
+ rawLeft = anchor.left + anchor.width - panel.width;
45
+ else
46
+ rawLeft = anchor.left + (anchor.width - panel.width) / 2;
47
+ var left = clamp(rawLeft, VIEWPORT_MARGIN, viewport.width - VIEWPORT_MARGIN - panel.width);
48
+ return {
49
+ top: top,
50
+ left: left,
51
+ side: side,
52
+ originX: clamp(anchor.left + anchor.width / 2 - left, 0, panel.width),
53
+ originY: clamp(anchor.top + anchor.height / 2 - top, 0, panel.height)
54
+ };
55
+ }
56
+ /** The smallest scale used, so a zero sized anchor never collapses the panel to nothing. */
57
+ export var MIN_MORPH_SCALE = 0.01;
58
+ /**
59
+ * The start of a grow from the anchor's glass: with `transform-origin: 0 0`,
60
+ * this transform shrinks the panel onto the anchor's box. Animating from it to
61
+ * no transform makes the panel grow out of the control, as menus and popovers
62
+ * do on iOS 26.
63
+ */
64
+ export function morphStart(anchor, panel) {
65
+ var scale = function (part, whole) {
66
+ return whole > 0 ? Math.max(MIN_MORPH_SCALE, part / whole) : 1;
67
+ };
68
+ return {
69
+ translateX: anchor.left - panel.left,
70
+ translateY: anchor.top - panel.top,
71
+ scaleX: scale(anchor.width, panel.width),
72
+ scaleY: scale(anchor.height, panel.height)
73
+ };
74
+ }
75
+ /** The CSS transform for a MorphStart. */
76
+ export function morphTransform(start) {
77
+ return "translate(".concat(start.translateX, "px, ").concat(start.translateY, "px) scale(").concat(start.scaleX, ", ").concat(start.scaleY, ")");
78
+ }
79
+ /** How long the grow from the anchor runs, matching --transition-spring. */
80
+ export var GROW_DURATION_MS = 400;
81
+ /** The easing of the grow, matching --transition-spring. */
82
+ export var GROW_EASING = 'cubic-bezier(0.32, 0.72, 0, 1)';
83
+ /**
84
+ * Grows a panel out of its anchor with the Web Animations API. Under reduced
85
+ * motion it fades in instead, with no change of size or place. Returns the
86
+ * animation, or null where the browser has no `animate`.
87
+ */
88
+ export function playGrow(panel, anchor, reducedMotion) {
89
+ if (typeof panel.animate !== 'function')
90
+ return null;
91
+ if (reducedMotion) {
92
+ return panel.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 150, easing: 'linear' });
93
+ }
94
+ var start = morphStart(anchor.getBoundingClientRect(), panel.getBoundingClientRect());
95
+ return panel.animate([
96
+ { transformOrigin: '0 0', transform: morphTransform(start), opacity: 0 },
97
+ { opacity: 1, offset: 0.5 },
98
+ { transformOrigin: '0 0', transform: 'none', opacity: 1 }
99
+ ], { duration: GROW_DURATION_MS, easing: GROW_EASING });
100
+ }
101
+ /**
102
+ * The side of the anchor for a panel that can reveal a part beside it (the
103
+ * anchored ActionSheet's Cancel). The panel and the revealed part, with the
104
+ * gap between them, are sized together, so the part has room on the far side
105
+ * from the anchor whenever the viewport allows: below when that fits, else
106
+ * above when that fits. When neither side fits both, the side is the one
107
+ * `placeAnchored` would choose for the panel alone, and the part then takes
108
+ * the near side (see revealOffset).
109
+ */
110
+ export function revealSide(anchor, panel, revealHeight, viewport) {
111
+ var needed = panel.height + ANCHOR_GAP + revealHeight;
112
+ var below = viewport.height - (anchor.top + anchor.height) - ANCHOR_GAP - VIEWPORT_MARGIN;
113
+ var above = anchor.top - ANCHOR_GAP - VIEWPORT_MARGIN;
114
+ if (needed <= below)
115
+ return 'bottom';
116
+ if (needed <= above)
117
+ return 'top';
118
+ return placeAnchored(anchor, panel, viewport).side;
119
+ }
120
+ /**
121
+ * Where a part revealed beside an anchored panel goes, as an offset from the
122
+ * panel's top: the anchored ActionSheet's Cancel, which shows on keyboard
123
+ * focus. It is drawn over the page, never in the panel's flow, so the
124
+ * panel's rows never move. It goes on the panel's far side from the anchor
125
+ * when it fits there, else on the near side, and is then kept inside the
126
+ * viewport (over the panel only when neither side has room).
127
+ */
128
+ export function revealOffset(side, panelTop, panelHeight, revealHeight, viewportHeight) {
129
+ var above = -(ANCHOR_GAP + revealHeight);
130
+ var below = panelHeight + ANCHOR_GAP;
131
+ var fits = function (offset) {
132
+ return panelTop + offset >= VIEWPORT_MARGIN && panelTop + offset + revealHeight <= viewportHeight - VIEWPORT_MARGIN;
133
+ };
134
+ var _a = side === 'top' ? [above, below] : [below, above], far = _a[0], near = _a[1];
135
+ var offset = fits(far) ? far : fits(near) ? near : far;
136
+ return clamp(panelTop + offset, VIEWPORT_MARGIN, viewportHeight - VIEWPORT_MARGIN - revealHeight) - panelTop;
137
+ }
@@ -51,4 +51,4 @@ export declare function dragSnap(node: HTMLElement, initialOptions: DragSnapOpti
51
51
  destroy(): void;
52
52
  };
53
53
  export { DEFAULT_DETENT_FRACTIONS, DRAG_BLOCKER_SELECTOR, SAMPLE_WINDOW, SHEET_DISMISS_FRACTION, SHEET_TRANSITION, applyRubberBand, chooseNextIndex, clampIndex, computeVelocity, detentAt, detentFractions, isDragStartAllowed, nearestDetentIndex, pushSample, resolveDragFraction, shouldDismiss, sheetYForFraction } from './dragSnapMath';
54
- export type { PointerSample, SheetDetentName } from './dragSnapMath';
54
+ export type { PointerSample, SheetDetent, SheetDetentName, SheetFractionDetent, SheetHeightDetent, SheetLabels } from './dragSnapMath';
@@ -66,3 +66,73 @@ export declare const DEFAULT_DETENT_FRACTIONS: {
66
66
  };
67
67
  export type SheetDetentName = keyof typeof DEFAULT_DETENT_FRACTIONS;
68
68
  export declare function detentFractions(names: readonly SheetDetentName[]): number[];
69
+ /** A custom detent: a share of the viewport height, mirroring SwiftUI's `.fraction`. */
70
+ export interface SheetFractionDetent {
71
+ /** The visible share of the viewport height, from 0 to 1. */
72
+ fraction: number;
73
+ }
74
+ /** A custom detent: a fixed visible height in CSS pixels, mirroring SwiftUI's `.height`. */
75
+ export interface SheetHeightDetent {
76
+ /** The visible height in CSS pixels. Capped at the viewport height. */
77
+ height: number;
78
+ }
79
+ /** A sheet detent: one of the named sizes, a fraction of the viewport, or a height. */
80
+ export type SheetDetent = SheetDetentName | SheetFractionDetent | SheetHeightDetent;
81
+ /**
82
+ * The visible share of the viewport for a detent. A height detent is divided by
83
+ * `viewportHeight`, and is 0 while that is unknown (no window yet).
84
+ */
85
+ export declare function resolveDetentFraction(detent: SheetDetent, viewportHeight: number): number;
86
+ /** The words the sheet's grabber reads out. Pass some or all to `Sheet`'s `labels` to translate them. */
87
+ export interface SheetLabels {
88
+ /** The grabber slider's name. */
89
+ size: string;
90
+ small: string;
91
+ medium: string;
92
+ large: string;
93
+ fullscreen: string;
94
+ /** A height detent, given its whole number of CSS pixels. */
95
+ pixels: (height: number) => string;
96
+ }
97
+ /** The English defaults. */
98
+ export declare const DEFAULT_SHEET_LABELS: Readonly<SheetLabels>;
99
+ /** The defaults with any given labels laid over them. */
100
+ export declare function sheetLabels(overrides?: Partial<SheetLabels>): SheetLabels;
101
+ /** How a detent is read out: its name, a percentage of the screen, or a height in pixels. */
102
+ export declare function detentLabel(detent: SheetDetent, labels?: SheetLabels): string;
103
+ /**
104
+ * Whether a sheet at this fraction counts as full height: at or above the large
105
+ * detent. An inset sheet meets the screen edges there, as on iOS 26.
106
+ */
107
+ export declare function isFullHeightFraction(fraction: number): boolean;
108
+ /** A detent as the sheet uses it: the value the consumer passed and its resolved fraction. */
109
+ export interface DetentLevel<D extends SheetDetent = SheetDetent> {
110
+ detent: D;
111
+ fraction: number;
112
+ }
113
+ /**
114
+ * The detents the sheet moves between: each resolved against the viewport,
115
+ * sorted smallest first, with detents that resolve to the same fraction
116
+ * collapsed into the first one given. So a list passed out of order, a height
117
+ * capped at the viewport next to `fullscreen`, or `{ fraction: 0.5 }` next to
118
+ * `medium` still gives one ordered set of distinct sizes. The sort is stable.
119
+ */
120
+ export declare function normalizeDetents<D extends SheetDetent>(detents: readonly D[], viewportHeight: number): DetentLevel<D>[];
121
+ /**
122
+ * The index in `levels` of a detent: the level with its fraction, which is the
123
+ * detent itself or the one it collapsed into (levels have distinct fractions),
124
+ * else the level nearest in size (the smaller on a tie). 0 for no levels.
125
+ */
126
+ export declare function levelIndexOf(levels: readonly DetentLevel[], detent: SheetDetent, viewportHeight: number): number;
127
+ /** Whether `levels` offers a detent's size: the detent itself, or one it collapsed into. */
128
+ export declare function isDetentOffered(levels: readonly DetentLevel[], detent: SheetDetent, viewportHeight: number): boolean;
129
+ /**
130
+ * The detent a sheet opens at: `initial` when its size is offered, else the
131
+ * smallest level, else `initial` itself when there are no levels.
132
+ */
133
+ export declare function openingDetent<D extends SheetDetent>(levels: readonly DetentLevel<D>[], initial: D, viewportHeight: number): D;
134
+ /**
135
+ * A detent's value as a string: its name, `f:<fraction>` or `h:<height>`. Two
136
+ * detent objects with the same value give the same key.
137
+ */
138
+ export declare function detentKey(detent: SheetDetent): string;
@@ -3,6 +3,17 @@
3
3
  * turns a drag into a fraction, and the release decisions. Internal; dragSnap
4
4
  * re-exports the public names.
5
5
  */
6
+ var __assign = (this && this.__assign) || function () {
7
+ __assign = Object.assign || function(t) {
8
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9
+ s = arguments[i];
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
+ t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return __assign.apply(this, arguments);
16
+ };
6
17
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
7
18
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
8
19
  if (ar || !(i in from)) {
@@ -164,3 +175,107 @@ export var DEFAULT_DETENT_FRACTIONS = {
164
175
  export function detentFractions(names) {
165
176
  return names.map(function (n) { return DEFAULT_DETENT_FRACTIONS[n]; });
166
177
  }
178
+ /** Clamp a fraction into 0..1, treating anything that is not a finite number as 0. */
179
+ function clampFraction(fraction) {
180
+ return Number.isFinite(fraction) ? Math.min(1, Math.max(0, fraction)) : 0;
181
+ }
182
+ /**
183
+ * The visible share of the viewport for a detent. A height detent is divided by
184
+ * `viewportHeight`, and is 0 while that is unknown (no window yet).
185
+ */
186
+ export function resolveDetentFraction(detent, viewportHeight) {
187
+ var _a;
188
+ if (typeof detent === 'string')
189
+ return (_a = DEFAULT_DETENT_FRACTIONS[detent]) !== null && _a !== void 0 ? _a : 0;
190
+ if ('fraction' in detent)
191
+ return clampFraction(detent.fraction);
192
+ // An unknown (0) or invalid viewport height divides to Infinity, NaN or a
193
+ // negative number, all of which clampFraction turns into 0.
194
+ return clampFraction(detent.height / viewportHeight);
195
+ }
196
+ /** The English defaults. */
197
+ export var DEFAULT_SHEET_LABELS = {
198
+ size: 'Sheet size',
199
+ small: 'Small',
200
+ medium: 'Medium',
201
+ large: 'Large',
202
+ fullscreen: 'Full screen',
203
+ pixels: function (height) { return "".concat(height, " pixels"); }
204
+ };
205
+ /** The defaults with any given labels laid over them. */
206
+ export function sheetLabels(overrides) {
207
+ if (overrides === void 0) { overrides = {}; }
208
+ return __assign(__assign({}, DEFAULT_SHEET_LABELS), overrides);
209
+ }
210
+ /** How a detent is read out: its name, a percentage of the screen, or a height in pixels. */
211
+ export function detentLabel(detent, labels) {
212
+ var _a;
213
+ if (labels === void 0) { labels = DEFAULT_SHEET_LABELS; }
214
+ if (typeof detent === 'string')
215
+ return (_a = labels[detent]) !== null && _a !== void 0 ? _a : detent;
216
+ if ('fraction' in detent)
217
+ return "".concat(Math.round(clampFraction(detent.fraction) * 100), "%");
218
+ return labels.pixels(Math.round(detent.height));
219
+ }
220
+ /**
221
+ * Whether a sheet at this fraction counts as full height: at or above the large
222
+ * detent. An inset sheet meets the screen edges there, as on iOS 26.
223
+ */
224
+ export function isFullHeightFraction(fraction) {
225
+ return fraction >= DEFAULT_DETENT_FRACTIONS.large;
226
+ }
227
+ /**
228
+ * The detents the sheet moves between: each resolved against the viewport,
229
+ * sorted smallest first, with detents that resolve to the same fraction
230
+ * collapsed into the first one given. So a list passed out of order, a height
231
+ * capped at the viewport next to `fullscreen`, or `{ fraction: 0.5 }` next to
232
+ * `medium` still gives one ordered set of distinct sizes. The sort is stable.
233
+ */
234
+ export function normalizeDetents(detents, viewportHeight) {
235
+ var _a;
236
+ var sorted = detents
237
+ .map(function (detent) { return ({ detent: detent, fraction: resolveDetentFraction(detent, viewportHeight) }); })
238
+ .sort(function (a, b) { return a.fraction - b.fraction; });
239
+ var levels = [];
240
+ for (var _i = 0, sorted_1 = sorted; _i < sorted_1.length; _i++) {
241
+ var level = sorted_1[_i];
242
+ if (((_a = levels.at(-1)) === null || _a === void 0 ? void 0 : _a.fraction) === level.fraction)
243
+ continue;
244
+ levels.push(level);
245
+ }
246
+ return levels;
247
+ }
248
+ /**
249
+ * The index in `levels` of a detent: the level with its fraction, which is the
250
+ * detent itself or the one it collapsed into (levels have distinct fractions),
251
+ * else the level nearest in size (the smaller on a tie). 0 for no levels.
252
+ */
253
+ export function levelIndexOf(levels, detent, viewportHeight) {
254
+ return nearestDetentIndex(resolveDetentFraction(detent, viewportHeight), levels.map(function (level) { return level.fraction; }));
255
+ }
256
+ /** Whether `levels` offers a detent's size: the detent itself, or one it collapsed into. */
257
+ export function isDetentOffered(levels, detent, viewportHeight) {
258
+ var fraction = resolveDetentFraction(detent, viewportHeight);
259
+ return levels.some(function (level) { return level.fraction === fraction; });
260
+ }
261
+ /**
262
+ * The detent a sheet opens at: `initial` when its size is offered, else the
263
+ * smallest level, else `initial` itself when there are no levels.
264
+ */
265
+ export function openingDetent(levels, initial, viewportHeight) {
266
+ var _a, _b;
267
+ if (isDetentOffered(levels, initial, viewportHeight))
268
+ return initial;
269
+ return (_b = (_a = levels[0]) === null || _a === void 0 ? void 0 : _a.detent) !== null && _b !== void 0 ? _b : initial;
270
+ }
271
+ /**
272
+ * A detent's value as a string: its name, `f:<fraction>` or `h:<height>`. Two
273
+ * detent objects with the same value give the same key.
274
+ */
275
+ export function detentKey(detent) {
276
+ if (typeof detent === 'string')
277
+ return detent;
278
+ if ('fraction' in detent)
279
+ return "f:".concat(detent.fraction);
280
+ return "h:".concat(detent.height);
281
+ }