@vvedantb/ui 0.55.0 → 0.57.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.
@@ -8,6 +8,8 @@ import { APP_ICONS } from "../../src/brand/AppIcons.js";
8
8
  import { moveTabsPillXY } from "../../src/ui/tabsSliding.js";
9
9
  import { SIDEBAR_RAIL_APP_ICON_SIZE, railGroupClass, railGroupPillClass, railTileClass, railTileStateClass } from "./app-shell-classes.js";
10
10
  import { SidebarIconTooltip } from "./SidebarIconTooltip.js";
11
+ import { toggleShellPanel } from "./shell-panel-motion.js";
12
+ import { useAppShellPanelDock, useAppShellVariant } from "./shell-variant.js";
11
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
14
  /**
13
15
  * Icon rail column. Width reads `--app-shell-rail-width`; override with `className`. Other props go to the root `<div>`.
@@ -15,9 +17,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
17
  * Legacy (still supported): the `top`, `footer`, `bodyAsChild`, `tabs` and
16
18
  * `*ClassName` props. Compose `Sidebar.Rail`, `.RailHeader`, `.RailBody` and
17
19
  * `.RailFooter` instead.
20
+ *
21
+ * In an `AppShell variant="rail"` each of `top`, the body and `footer` sits on
22
+ * its own `RailGroup` trough, and `showDivider` and `RailDivider` draw nothing.
23
+ * A `bodyAsChild` body is left as it is.
18
24
  */
19
25
  export function SidebarRail(t0) {
20
- const $ = _c(30);
26
+ const $ = _c(38);
21
27
  let bodyClassName;
22
28
  let children;
23
29
  let className;
@@ -71,66 +77,95 @@ export function SidebarRail(t0) {
71
77
  const showDivider = t1 === undefined ? false : t1;
72
78
  const bodyAsChild = t2 === undefined ? false : t2;
73
79
  const tabs = t3 === undefined ? false : t3;
80
+ const rail = useAppShellVariant() === "rail";
74
81
  let t4;
75
- if ($[12] !== top || $[13] !== topClassName) {
76
- t4 = top == null ? null : /*#__PURE__*/_jsx(RailHeader, {
82
+ if ($[12] !== rail) {
83
+ t4 = node => rail ? /*#__PURE__*/_jsx(RailGroup, {
84
+ className: railSlotGroupClass,
85
+ children: node
86
+ }) : node;
87
+ $[12] = rail;
88
+ $[13] = t4;
89
+ } else {
90
+ t4 = $[13];
91
+ }
92
+ const slot = t4;
93
+ const t5 = showDivider && !rail;
94
+ let t6;
95
+ if ($[14] !== slot || $[15] !== top || $[16] !== topClassName) {
96
+ t6 = top == null ? null : /*#__PURE__*/_jsx(RailHeader, {
77
97
  className: topClassName,
78
- children: top
98
+ children: slot(top)
79
99
  });
80
- $[12] = top;
81
- $[13] = topClassName;
82
- $[14] = t4;
100
+ $[14] = slot;
101
+ $[15] = top;
102
+ $[16] = topClassName;
103
+ $[17] = t6;
83
104
  } else {
84
- t4 = $[14];
105
+ t6 = $[17];
85
106
  }
86
- let t5;
87
- if ($[15] !== bodyAsChild || $[16] !== bodyClassName || $[17] !== children || $[18] !== tabs) {
88
- t5 = /*#__PURE__*/_jsx(RailBody, {
107
+ let t7;
108
+ if ($[18] !== bodyAsChild || $[19] !== children || $[20] !== slot) {
109
+ t7 = bodyAsChild ? children : slot(children);
110
+ $[18] = bodyAsChild;
111
+ $[19] = children;
112
+ $[20] = slot;
113
+ $[21] = t7;
114
+ } else {
115
+ t7 = $[21];
116
+ }
117
+ let t8;
118
+ if ($[22] !== bodyAsChild || $[23] !== bodyClassName || $[24] !== t7 || $[25] !== tabs) {
119
+ t8 = /*#__PURE__*/_jsx(RailBody, {
89
120
  asChild: bodyAsChild,
90
121
  tabs: tabs,
91
122
  className: bodyClassName,
92
- children: children
123
+ children: t7
93
124
  });
94
- $[15] = bodyAsChild;
95
- $[16] = bodyClassName;
96
- $[17] = children;
97
- $[18] = tabs;
98
- $[19] = t5;
125
+ $[22] = bodyAsChild;
126
+ $[23] = bodyClassName;
127
+ $[24] = t7;
128
+ $[25] = tabs;
129
+ $[26] = t8;
99
130
  } else {
100
- t5 = $[19];
131
+ t8 = $[26];
101
132
  }
102
- let t6;
103
- if ($[20] !== footer || $[21] !== footerClassName) {
104
- t6 = footer == null ? null : /*#__PURE__*/_jsx(RailFooter, {
133
+ let t9;
134
+ if ($[27] !== footer || $[28] !== footerClassName || $[29] !== slot) {
135
+ t9 = footer == null ? null : /*#__PURE__*/_jsx(RailFooter, {
105
136
  className: footerClassName,
106
- children: footer
137
+ children: slot(footer)
107
138
  });
108
- $[20] = footer;
109
- $[21] = footerClassName;
110
- $[22] = t6;
139
+ $[27] = footer;
140
+ $[28] = footerClassName;
141
+ $[29] = slot;
142
+ $[30] = t9;
111
143
  } else {
112
- t6 = $[22];
144
+ t9 = $[30];
113
145
  }
114
- let t7;
115
- if ($[23] !== className || $[24] !== props || $[25] !== showDivider || $[26] !== t4 || $[27] !== t5 || $[28] !== t6) {
116
- t7 = /*#__PURE__*/_jsxs(Rail, {
146
+ let t10;
147
+ if ($[31] !== className || $[32] !== props || $[33] !== t5 || $[34] !== t6 || $[35] !== t8 || $[36] !== t9) {
148
+ t10 = /*#__PURE__*/_jsxs(Rail, {
117
149
  ...props,
118
- showDivider: showDivider,
150
+ showDivider: t5,
119
151
  className: className,
120
- children: [t4, t5, t6]
152
+ children: [t6, t8, t9]
121
153
  });
122
- $[23] = className;
123
- $[24] = props;
124
- $[25] = showDivider;
125
- $[26] = t4;
126
- $[27] = t5;
127
- $[28] = t6;
128
- $[29] = t7;
154
+ $[31] = className;
155
+ $[32] = props;
156
+ $[33] = t5;
157
+ $[34] = t6;
158
+ $[35] = t8;
159
+ $[36] = t9;
160
+ $[37] = t10;
129
161
  } else {
130
- t7 = $[29];
162
+ t10 = $[37];
131
163
  }
132
- return t7;
164
+ return t10;
133
165
  }
166
+
167
+ /** A slot's trough hides while the slot renders nothing (the pill is then its only child). */
168
+ const railSlotGroupClass = "[&:not(:has(>:not([data-rail-pill])))]:hidden";
134
169
  /** Rail column `<div>`. Width reads `--app-shell-rail-width`. */
135
170
  export function Rail(t0) {
136
171
  const $ = _c(10);
@@ -395,6 +430,7 @@ export function RailGroup(t0) {
395
430
  t2 = /*#__PURE__*/_jsx("span", {
396
431
  ref: pillRef,
397
432
  "aria-hidden": true,
433
+ "data-rail-pill": "",
398
434
  className: railGroupPillClass
399
435
  });
400
436
  $[6] = t2;
@@ -637,12 +673,15 @@ export function RailSeparator(t0) {
637
673
  }
638
674
  return t2;
639
675
  }
640
- /** Legacy name of `Sidebar.RailSeparator`. */
676
+ /** Legacy name of `Sidebar.RailSeparator`. Draws nothing in an `AppShell variant="rail"`: the gap between troughs divides. */
641
677
  export function RailDivider(t0) {
642
678
  const $ = _c(2);
643
679
  const {
644
680
  className
645
681
  } = t0;
682
+ if (useAppShellVariant() === "rail") {
683
+ return null;
684
+ }
646
685
  let t1;
647
686
  if ($[0] !== className) {
648
687
  t1 = /*#__PURE__*/_jsx(RailSeparator, {
@@ -655,39 +694,62 @@ export function RailDivider(t0) {
655
694
  }
656
695
  return t1;
657
696
  }
658
- /** Rail tile that shows or hides the sidebar panel. */
697
+
698
+ /** Spread on the rail tile that the panel docks into, when it is not a `RailCollapseTile`. */
699
+ export const shellDockTileProps = {
700
+ "data-shell-dock-tile": ""
701
+ };
702
+ /**
703
+ * Rail tile that shows or hides the sidebar panel. In an `AppShell
704
+ * variant="rail"` (unless `panelMotion="none"`) the panel shrinks into this
705
+ * tile and grows back out of it (`toggleShellPanel`).
706
+ */
659
707
  export function RailCollapseTile(t0) {
660
- const $ = _c(6);
708
+ const $ = _c(11);
661
709
  const {
662
710
  collapsed,
663
711
  onToggle
664
712
  } = t0;
713
+ const dock = useAppShellPanelDock();
665
714
  const t1 = collapsed ? "Show sidebar" : "Hide sidebar";
666
715
  let t2;
667
- if ($[0] !== collapsed) {
668
- t2 = collapsed ? /*#__PURE__*/_jsx(IconLayoutSidebarLeftExpandFilled, {
716
+ if ($[0] !== collapsed || $[1] !== dock || $[2] !== onToggle) {
717
+ t2 = dock ? () => toggleShellPanel(collapsed, onToggle) : onToggle;
718
+ $[0] = collapsed;
719
+ $[1] = dock;
720
+ $[2] = onToggle;
721
+ $[3] = t2;
722
+ } else {
723
+ t2 = $[3];
724
+ }
725
+ const t3 = dock ? shellDockTileProps : undefined;
726
+ let t4;
727
+ if ($[4] !== collapsed) {
728
+ t4 = collapsed ? /*#__PURE__*/_jsx(IconLayoutSidebarLeftExpandFilled, {
669
729
  className: "size-[22px]"
670
730
  }) : /*#__PURE__*/_jsx(IconLayoutSidebarLeftCollapse, {
671
731
  className: "size-[22px]"
672
732
  });
673
- $[0] = collapsed;
674
- $[1] = t2;
733
+ $[4] = collapsed;
734
+ $[5] = t4;
675
735
  } else {
676
- t2 = $[1];
736
+ t4 = $[5];
677
737
  }
678
- let t3;
679
- if ($[2] !== onToggle || $[3] !== t1 || $[4] !== t2) {
680
- t3 = /*#__PURE__*/_jsx(RailItem, {
738
+ let t5;
739
+ if ($[6] !== t1 || $[7] !== t2 || $[8] !== t3 || $[9] !== t4) {
740
+ t5 = /*#__PURE__*/_jsx(RailItem, {
681
741
  label: t1,
682
- onClick: onToggle,
683
- children: t2
742
+ onClick: t2,
743
+ ...t3,
744
+ children: t4
684
745
  });
685
- $[2] = onToggle;
686
- $[3] = t1;
687
- $[4] = t2;
688
- $[5] = t3;
746
+ $[6] = t1;
747
+ $[7] = t2;
748
+ $[8] = t3;
749
+ $[9] = t4;
750
+ $[10] = t5;
689
751
  } else {
690
- t3 = $[5];
752
+ t5 = $[10];
691
753
  }
692
- return t3;
754
+ return t5;
693
755
  }
@@ -4,10 +4,14 @@ export { PillTabs } from "./PillTabs.js";
4
4
  export { cn } from "./cn.js";
5
5
  export { SessionsHoverCard } from "./SessionsHoverCard.js";
6
6
  export { AppShell } from "./AppShell.js";
7
+ export { useAppShellVariant } from "./shell-variant.js";
8
+ export { popInShellPanelNextFrame, popOutShellPanel, toggleShellPanel } from "./shell-panel-motion.js";
9
+ export { ButtonTrack, buttonTrackClass } from "./ButtonTrack.js";
10
+ export { SidePanelTabs, popOutSidePanel, SIDE_PANEL_RAIL_WIDTH_PX, SIDE_PANEL_RAIL_LABELLED_WIDTH_PX } from "./SidePanelTabs.js";
7
11
  export { AppSidebar } from "./AppSidebar.js";
8
12
  // Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
9
13
  export * from "./Sidebar.js";
10
- export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "./SidebarRail.js";
14
+ export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "./SidebarRail.js";
11
15
  export { SidebarResizeHandle, useAppShellResize } from "./SidebarResize.js";
12
16
  export { SidebarIconTooltip } from "./SidebarIconTooltip.js";
13
17
  export { SidebarPanel } from "./SidebarPanel.js";
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Dock motion of the sidebar panel in an `AppShell variant="rail"`, on hide
3
+ * and show only: the panel shrinks into the rail's collapse tile and grows
4
+ * back out of it. `Sidebar.Panel` marks the panel and `RailCollapseTile` the
5
+ * tile (`shellDockTileProps` for a tile of your own). The main content slides
6
+ * its margin with the aside's width, so it does not jump.
7
+ *
8
+ * Off with `MotionProvider reducedMotion` and `PageMotionProvider disabled`
9
+ * (`dockMotionOff`), and outside the rail variant: the toggle runs at once.
10
+ */
11
+ import { dockPopIn, dockPopOut, slideWith } from "../../src/motion/dock-motion.js";
12
+ function dockPanel() {
13
+ if (typeof document === "undefined") return null;
14
+ return document.querySelector("[data-shell-dock-panel]");
15
+ }
16
+ function dockTile() {
17
+ if (typeof document === "undefined") return null;
18
+ return document.querySelector("[data-shell-dock-tile]");
19
+ }
20
+
21
+ /** The page beside the shell aside: its left margin follows the aside. */
22
+ function slideMainWithAside() {
23
+ const tile = dockTile();
24
+ if (!tile) return;
25
+ const shell = tile.closest("[data-shell-variant]");
26
+ slideWith((shell ?? document).querySelector("main"), tile.closest("aside"), "margin-left");
27
+ }
28
+
29
+ /** Shrink the panel into the collapse tile, then run `hide`. */
30
+ export function popOutShellPanel(hide) {
31
+ dockPopOut(dockPanel(), dockTile(), "left", () => {
32
+ slideMainWithAside();
33
+ hide();
34
+ });
35
+ }
36
+
37
+ /**
38
+ * Call right after the state change that shows the panel. React shows it in
39
+ * this event's commit; the next frame runs before it paints.
40
+ */
41
+ export function popInShellPanelNextFrame() {
42
+ if (typeof requestAnimationFrame !== "function") return;
43
+ slideMainWithAside();
44
+ requestAnimationFrame(() => {
45
+ const shown = dockPanel();
46
+ if (shown) dockPopIn(shown, dockTile(), "left");
47
+ });
48
+ }
49
+
50
+ /**
51
+ * Show or hide the sidebar panel with the dock motion. `collapsed` is the
52
+ * state before the toggle; `toggle` flips it. For a hotkey or a context
53
+ * setter that does not go through `RailCollapseTile`.
54
+ */
55
+ export function toggleShellPanel(collapsed, toggle) {
56
+ if (collapsed) {
57
+ toggle();
58
+ popInShellPanelNextFrame();
59
+ } else {
60
+ popOutShellPanel(toggle);
61
+ }
62
+ }
@@ -0,0 +1,28 @@
1
+ import { createContext, use } from "react";
2
+
3
+ /**
4
+ * Layout of the app shell. `"floating"` (default): the page is a rounded card
5
+ * beside a plain icon rail. `"rail"`: no card; rail tiles sit on troughs with
6
+ * a sliding pill, and there are no divider lines.
7
+ */
8
+
9
+ /** How the sidebar panel hides and shows in the `"rail"` variant. */
10
+
11
+ /**
12
+ * The `variant` input of `AppShell` and `AppShell.Root`, as a union keyed on
13
+ * `variant`. An input that only one variant takes goes on that arm, with
14
+ * `?: never` on the other, so passing it to the wrong variant is a type error.
15
+ */
16
+
17
+ export const AppShellVariantContext = /*#__PURE__*/createContext("floating");
18
+
19
+ /** The `variant` of the nearest `AppShell`; `"floating"` outside one. */
20
+ export function useAppShellVariant() {
21
+ return use(AppShellVariantContext);
22
+ }
23
+ export const AppShellPanelDockContext = /*#__PURE__*/createContext(false);
24
+
25
+ /** True inside an `AppShell variant="rail"` whose `panelMotion` is `"dock"`. */
26
+ export function useAppShellPanelDock() {
27
+ return use(AppShellPanelDockContext);
28
+ }
@@ -31,6 +31,7 @@ export { SendQueueIcon } from "./ui/send-queue-icon.js";
31
31
  export { BulkActionBar } from "./ui/bulk-action-bar.js";
32
32
  export { CopyLinkMenuItem } from "./ui/copy-link-menu-item.js";
33
33
  export { ToggleSearch } from "./ui/toggle-search.js";
34
+ export { DOCK_MOTION_EVENT, DockMotionEvent, dockMotionOff, dockNudge, dockPopIn, dockPopOut, slideNextResize, slideWith } from "./motion/dock-motion.js";
34
35
  export { MotionProvider } from "./motion/motion-provider.js";
35
36
  export { useReducedMotionSetting } from "./motion/reduced-motion.js";
36
37
  export { MarqueeOnHover } from "./ui/marquee-on-hover.js";
@@ -171,10 +172,14 @@ export { SessionsHoverCard } from "../shell/src/SessionsHoverCard.js";
171
172
  // App shell: sidebar and main page layout. Widths come from the
172
173
  // `--app-shell-*` CSS variables that `AppShell` sets.
173
174
  export { AppShell } from "../shell/src/AppShell.js";
175
+ export { useAppShellVariant } from "../shell/src/shell-variant.js";
176
+ export { popInShellPanelNextFrame, popOutShellPanel, toggleShellPanel } from "../shell/src/shell-panel-motion.js";
177
+ export { ButtonTrack, buttonTrackClass } from "../shell/src/ButtonTrack.js";
178
+ export { SidePanelTabs, popOutSidePanel, SIDE_PANEL_RAIL_WIDTH_PX, SIDE_PANEL_RAIL_LABELLED_WIDTH_PX } from "../shell/src/SidePanelTabs.js";
174
179
  export { AppSidebar } from "../shell/src/AppSidebar.js";
175
180
  // Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
176
181
  export * from "../shell/src/Sidebar.js";
177
- export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "../shell/src/SidebarRail.js";
182
+ export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "../shell/src/SidebarRail.js";
178
183
  export { SidebarResizeHandle, useAppShellResize } from "../shell/src/SidebarResize.js";
179
184
  export { SidebarIconTooltip } from "../shell/src/SidebarIconTooltip.js";
180
185
  export { SidebarPanel } from "../shell/src/SidebarPanel.js";
package/dist/src/index.js CHANGED
@@ -27,6 +27,7 @@ export { SendQueueIcon } from "./ui/send-queue-icon.js";
27
27
  export { BulkActionBar } from "./ui/bulk-action-bar.js";
28
28
  export { CopyLinkMenuItem } from "./ui/copy-link-menu-item.js";
29
29
  export { ToggleSearch } from "./ui/toggle-search.js";
30
+ export { DOCK_MOTION_EVENT, DockMotionEvent, dockMotionOff, dockNudge, dockPopIn, dockPopOut, slideNextResize, slideWith } from "./motion/dock-motion.js";
30
31
  export { MotionProvider } from "./motion/motion-provider.js";
31
32
  export { useReducedMotionSetting } from "./motion/reduced-motion.js";
32
33
  export { MarqueeOnHover } from "./ui/marquee-on-hover.js";
@@ -171,10 +172,14 @@ export { SessionsHoverCard } from "../shell/src/SessionsHoverCard.js";
171
172
  // App shell: sidebar and main page layout. Widths come from the
172
173
  // `--app-shell-*` CSS variables that `AppShell` sets.
173
174
  export { AppShell } from "../shell/src/AppShell.js";
175
+ export { useAppShellVariant } from "../shell/src/shell-variant.js";
176
+ export { popInShellPanelNextFrame, popOutShellPanel, toggleShellPanel } from "../shell/src/shell-panel-motion.js";
177
+ export { ButtonTrack, buttonTrackClass } from "../shell/src/ButtonTrack.js";
178
+ export { SidePanelTabs, popOutSidePanel, SIDE_PANEL_RAIL_WIDTH_PX, SIDE_PANEL_RAIL_LABELLED_WIDTH_PX } from "../shell/src/SidePanelTabs.js";
174
179
  export { AppSidebar } from "../shell/src/AppSidebar.js";
175
180
  // Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
176
181
  export * from "../shell/src/Sidebar.js";
177
- export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "../shell/src/SidebarRail.js";
182
+ export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "../shell/src/SidebarRail.js";
178
183
  export { SidebarResizeHandle, useAppShellResize } from "../shell/src/SidebarResize.js";
179
184
  export { SidebarIconTooltip } from "../shell/src/SidebarIconTooltip.js";
180
185
  export { SidebarPanel } from "../shell/src/SidebarPanel.js";
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Dock motion for a panel that docks into a rail tile: it grows out of the
3
+ * tile when shown, shrinks back into it when hidden, and settles when the
4
+ * tile it belongs to changes. The Web Animations API drives it: the motions
5
+ * are one-shot and imperative, and a hide has to finish before the caller
6
+ * removes the panel.
7
+ *
8
+ * Off switch: `MotionProvider reducedMotion` (`prefersReducedMotion()`) and
9
+ * `PageMotionProvider disabled` (`html[data-page-motion="off"]`). With either
10
+ * on, nothing here animates: a show is instant and a hide runs at once.
11
+ */
12
+ import { prefersReducedMotion } from "./reduced-motion.js";
13
+
14
+ /** Which edge of the panel touches the rail. */
15
+
16
+ /** How small the panel gets: close to the tile's size, not a dot. */
17
+ const DOCKED_SCALE = 0.12;
18
+ const POP_IN_MS = 380;
19
+ const POP_OUT_MS = 260;
20
+ const SWITCH_MS = 220;
21
+ /* Out-quint: fast start, long settle. The panel lands rather than stops. */
22
+ const SETTLE_EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
23
+ /* In-cubic: accelerates into the tile, as a minimise does. */
24
+ const DOCK_EASE = "cubic-bezier(0.5, 0, 0.75, 0)";
25
+ const POP_OUT_ID = "dock-pop-out";
26
+ /* How long the docked frame holds after a hide: past the sidebar's 280 ms
27
+ width slide, so the panel never shows at full size while it leaves. */
28
+ const HOLD_MS = 400;
29
+
30
+ /**
31
+ * Fired on the panel as a dock motion starts, and it bubbles. Overlays painted
32
+ * over the panel from elsewhere (an iframe host, say) cannot follow its
33
+ * transform, so they step aside for `ms`.
34
+ */
35
+ export const DOCK_MOTION_EVENT = "dockmotion";
36
+ export class DockMotionEvent extends Event {
37
+ constructor(ms) {
38
+ super(DOCK_MOTION_EVENT, {
39
+ bubbles: true
40
+ });
41
+ this.ms = ms;
42
+ }
43
+ }
44
+
45
+ /** True while dock motion must not run. */
46
+ export function dockMotionOff() {
47
+ if (typeof document === "undefined") return true;
48
+ return document.documentElement.dataset.pageMotion === "off" || prefersReducedMotion();
49
+ }
50
+
51
+ /**
52
+ * Points the panel's transform origin at the tile's centre, on the rail
53
+ * edge. False when either is not on screen, so the caller skips the motion.
54
+ * Measure before animating: a scaled panel reports a scaled rect.
55
+ */
56
+ function aimAt(panel, tile, edge) {
57
+ if (!tile || dockMotionOff() || typeof panel.animate !== "function") return false;
58
+ const p = panel.getBoundingClientRect();
59
+ // Height, not width: a sidebar aside slides its width open from 0.
60
+ if (p.height === 0) return false;
61
+ const t = tile.getBoundingClientRect();
62
+ const x = edge === "left" ? "0%" : "100%";
63
+ panel.style.transformOrigin = `${x} ${Math.round(t.top + t.height / 2 - p.top)}px`;
64
+ return true;
65
+ }
66
+
67
+ /** Drops a finished pop-out's held frame (see `dockPopOut`). */
68
+ function releaseDocked(el) {
69
+ if (!el || typeof el.getAnimations !== "function") return;
70
+ for (const a of el.getAnimations()) if (a.id === POP_OUT_ID) a.cancel();
71
+ }
72
+
73
+ /**
74
+ * Shown: the panel grows out of the tile. `after` (an arrow, a badge) fades in
75
+ * once the panel has nearly landed.
76
+ */
77
+ export function dockPopIn(panel, tile, edge, after) {
78
+ // Always, even when the motion is skipped, or the panel stays invisible.
79
+ releaseDocked(panel);
80
+ releaseDocked(after);
81
+ if (!aimAt(panel, tile, edge)) return;
82
+ panel.dispatchEvent(new DockMotionEvent(POP_IN_MS));
83
+ panel.animate([{
84
+ transform: `scale(${DOCKED_SCALE})`,
85
+ opacity: 0
86
+ }, {
87
+ transform: "scale(1.015)",
88
+ opacity: 1,
89
+ offset: 0.75
90
+ }, {
91
+ transform: "scale(1)",
92
+ opacity: 1
93
+ }], {
94
+ duration: POP_IN_MS,
95
+ easing: SETTLE_EASE
96
+ });
97
+ after?.animate([{
98
+ opacity: 0
99
+ }, {
100
+ opacity: 0,
101
+ offset: 0.6
102
+ }, {
103
+ opacity: 1
104
+ }], {
105
+ duration: POP_IN_MS
106
+ });
107
+ }
108
+
109
+ /** The tile changed with the panel shown: a short settle from the new tile. */
110
+ export function dockNudge(panel, tile, edge) {
111
+ if (!aimAt(panel, tile, edge)) return;
112
+ panel.dispatchEvent(new DockMotionEvent(SWITCH_MS));
113
+ panel.animate([{
114
+ transform: "scale(0.965)",
115
+ opacity: 0.4
116
+ }, {
117
+ transform: "scale(1)",
118
+ opacity: 1
119
+ }], {
120
+ duration: SWITCH_MS,
121
+ easing: SETTLE_EASE
122
+ });
123
+ }
124
+
125
+ /**
126
+ * Hiding: shrink the panel back into the tile, then run `hide`. With no panel
127
+ * or tile on screen, or motion off, it hides at once. A second call while the
128
+ * panel is closing is ignored. `first` (an arrow) fades out early. The docked
129
+ * frame holds for 400 ms (or until the next `dockPopIn`): the caller may still
130
+ * slide the panel away, and it must stay invisible.
131
+ */
132
+ export function dockPopOut(panel, tile, edge, hide, first) {
133
+ if (!panel || !aimAt(panel, tile, edge)) {
134
+ hide();
135
+ return;
136
+ }
137
+ const closing = panel.getAnimations().some(a => a.id === POP_OUT_ID && a.playState === "running");
138
+ if (closing) return;
139
+ panel.dispatchEvent(new DockMotionEvent(POP_OUT_MS + HOLD_MS));
140
+ first?.animate([{
141
+ opacity: 1
142
+ }, {
143
+ opacity: 0
144
+ }], {
145
+ id: POP_OUT_ID,
146
+ duration: POP_OUT_MS / 3,
147
+ fill: "forwards"
148
+ });
149
+ const shrink = panel.animate([{
150
+ transform: "scale(1)",
151
+ opacity: 1
152
+ }, {
153
+ transform: `scale(${DOCKED_SCALE})`,
154
+ opacity: 0
155
+ }], {
156
+ id: POP_OUT_ID,
157
+ duration: POP_OUT_MS,
158
+ easing: DOCK_EASE,
159
+ fill: "forwards"
160
+ });
161
+ shrink.onfinish = () => {
162
+ hide();
163
+ setTimeout(() => {
164
+ releaseDocked(panel);
165
+ releaseDocked(first);
166
+ }, HOLD_MS);
167
+ };
168
+ }
169
+
170
+ /**
171
+ * Lets the panes of a resizable group slide to their next size instead of
172
+ * jumping, so the neighbour pane moves in step with a pop. It sets
173
+ * `data-dock-slide` and the `--dock-slide-dur` / `--dock-slide-ease` variables
174
+ * on `group` for one resize; the package CSS transitions `flex-grow` of its
175
+ * `[data-panel]` children (`react-resizable-panels`). Call it just before the
176
+ * resize. Only for this one toggle: a drag must stay 1:1 with the pointer.
177
+ */
178
+ export function slideNextResize(group, direction) {
179
+ if (!group || dockMotionOff()) return;
180
+ const ms = direction === "open" ? POP_IN_MS : POP_OUT_MS;
181
+ group.style.setProperty("--dock-slide-dur", `${ms}ms`);
182
+ group.style.setProperty("--dock-slide-ease", SETTLE_EASE);
183
+ group.dataset.dockSlide = "";
184
+ window.clearTimeout(Number(group.dataset.dockSlideTimer));
185
+ group.dataset.dockSlideTimer = String(window.setTimeout(() => {
186
+ delete group.dataset.dockSlide;
187
+ }, ms + 50));
188
+ }
189
+
190
+ /**
191
+ * For one layout change, `follower` slides its `property` with the timing of
192
+ * `leader`'s own transition, so a neighbour the leader pushes moves in step
193
+ * instead of jumping (the main content beside a sidebar's sliding width). Call
194
+ * it just before the change. Fires `DOCK_MOTION_EVENT` on the follower, so
195
+ * overlays over it step aside while it moves.
196
+ */
197
+ export function slideWith(follower, leader, property) {
198
+ if (!follower || !leader || dockMotionOff()) return;
199
+ const lead = getComputedStyle(leader);
200
+ const ms = parseFloat(lead.transitionDuration) * 1000;
201
+ if (!(ms > 0)) return;
202
+ follower.style.transition = `${property} ${lead.transitionDuration} ${lead.transitionTimingFunction}`;
203
+ follower.dispatchEvent(new DockMotionEvent(ms));
204
+ window.clearTimeout(Number(follower.dataset.slideWithTimer));
205
+ follower.dataset.slideWithTimer = String(window.setTimeout(() => {
206
+ follower.style.transition = "";
207
+ delete follower.dataset.slideWithTimer;
208
+ }, ms + 50));
209
+ }
@@ -158,10 +158,16 @@
158
158
  html[data-page-motion="off"] .t-modal,
159
159
  html[data-page-motion="off"] .t-modal.is-closing,
160
160
  html[data-page-motion="off"] .t-modal[data-state="closed"],
161
- html[data-page-motion="off"] .t-tabs-pill {
161
+ html[data-page-motion="off"] .t-tabs-pill,
162
+ html[data-page-motion="off"] .t-side-panel-arrow {
162
163
  transition-duration: 0s !important;
163
164
  }
164
165
 
166
+ /* `slideNextResize`: the panes of a resizable group slide for one resize. */
167
+ [data-dock-slide] > [data-panel] {
168
+ transition: flex-grow var(--dock-slide-dur) var(--dock-slide-ease);
169
+ }
170
+
165
171
  html[data-page-motion="off"]::view-transition-group(*),
166
172
  html[data-page-motion="off"]::view-transition-old(*),
167
173
  html[data-page-motion="off"]::view-transition-new(*) {
@@ -69,4 +69,8 @@
69
69
  z-index: 0;
70
70
  pointer-events: none;
71
71
  }
72
+ /* The arrow of `SidePanelTabs.Frame`: slides to the active tab in step with the pill. */
73
+ .t-side-panel-arrow {
74
+ transition: transform var(--tabs-dur) var(--tabs-ease);
75
+ }
72
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/ui",
3
- "version": "0.55.0",
3
+ "version": "0.57.0",
4
4
  "license": "MIT",
5
5
  "description": "Shared React 19 UI for web apps: one main JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, artifact viewers over the @vvedantb/server artifacts core, native tokens), third-party brand logos (also @vvedantb/ui/logos), motion-driven animated SVG icons (@vvedantb/ui/icons/animated), a client entry without @vvedantb/server, convex or Clerk for Chrome extensions, design-token CSS, shared Tailwind v4 CSS, a Tailwind preset and packaged Instrument Sans fonts.",
6
6
  "type": "module",