@bfrs/agentic-components 0.9.1 → 0.9.2

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.
@@ -0,0 +1,265 @@
1
+ import { jsxs as $, jsx as v } from "react/jsx-runtime";
2
+ import { forwardRef as be, useRef as p, useCallback as me, useState as U, useEffect as q, useLayoutEffect as pe } from "react";
3
+ import g from "@emotion/styled";
4
+ import { Text as ge } from "../../primitives/Text/Text.js";
5
+ const ye = 40, he = 52, K = 16, ve = {
6
+ card: "hsl(var(--bfrs-color-surface-card))",
7
+ tinted: "var(--bfrs-dcl-color-primary-light)"
8
+ }, M = "1px solid hsl(var(--bfrs-color-border-strong))", Se = /* @__PURE__ */ g("div", {
9
+ label: "AgenticSidePanel-slot"
10
+ })({
11
+ position: "relative",
12
+ display: "flex",
13
+ flexShrink: 0,
14
+ height: "100%"
15
+ }), xe = /* @__PURE__ */ g("aside", {
16
+ label: "AgenticSidePanel-panel"
17
+ })({
18
+ display: "flex",
19
+ flexDirection: "column",
20
+ height: "100%",
21
+ outline: "none"
22
+ }), Pe = /* @__PURE__ */ g("div", {
23
+ label: "AgenticSidePanel-header"
24
+ })({
25
+ display: "flex",
26
+ flexShrink: 0,
27
+ alignItems: "center",
28
+ paddingLeft: ".875rem",
29
+ paddingRight: ".5rem",
30
+ borderBottom: M,
31
+ backgroundColor: "hsl(var(--bfrs-color-surface-card))"
32
+ }), Re = /* @__PURE__ */ g("div", {
33
+ label: "AgenticSidePanel-rail"
34
+ })({
35
+ display: "flex",
36
+ flexDirection: "column",
37
+ alignItems: "center",
38
+ flexShrink: 0,
39
+ height: "100%",
40
+ paddingTop: 12,
41
+ borderRight: M,
42
+ zIndex: 5
43
+ }), ke = /* @__PURE__ */ g("button", {
44
+ label: "AgenticSidePanel-railButton"
45
+ })({
46
+ flex: 1,
47
+ display: "flex",
48
+ alignItems: "center",
49
+ justifyContent: "center",
50
+ width: "100%",
51
+ padding: 0,
52
+ border: 0,
53
+ background: "none",
54
+ cursor: "pointer",
55
+ "&:focus-visible": {
56
+ outline: "2px solid hsl(var(--bfrs-color-primary))",
57
+ outlineOffset: -2
58
+ }
59
+ }), we = /* @__PURE__ */ g("div", {
60
+ label: "AgenticSidePanel-scrim"
61
+ })({
62
+ position: "absolute",
63
+ top: 0,
64
+ bottom: 0,
65
+ backgroundColor: "hsl(var(--bfrs-color-surface-app) / 0.6)"
66
+ }), Ae = /* @__PURE__ */ g("div", {
67
+ label: "AgenticSidePanel-resizeHandle"
68
+ })({
69
+ position: "absolute",
70
+ top: 0,
71
+ right: 0,
72
+ zIndex: 20,
73
+ display: "flex",
74
+ alignItems: "center",
75
+ justifyContent: "center",
76
+ width: 8,
77
+ height: "100%",
78
+ cursor: "col-resize",
79
+ touchAction: "none",
80
+ outline: "none",
81
+ "&:hover, &:focus-visible, &[data-dragging]": {
82
+ backgroundColor: "hsl(var(--bfrs-color-primary) / 0.08)"
83
+ },
84
+ "&::after": {
85
+ content: '""',
86
+ width: 2,
87
+ height: 40,
88
+ borderRadius: 3,
89
+ backgroundColor: "var(--bfrs-dcl-color-neutral-stroke-2)"
90
+ }
91
+ }), C = typeof window < "u" ? pe : q, ze = (S, s, b) => Math.min(b, Math.max(s, S)), Ie = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
92
+ function Ee(S, s) {
93
+ const [b, r] = U({ left: 0, areaWidth: 0 });
94
+ return C(() => {
95
+ const l = S.current, o = l == null ? void 0 : l.parentElement;
96
+ if (!s || !l || !o) return;
97
+ const a = () => {
98
+ const u = o.getBoundingClientRect(), x = l.getBoundingClientRect().left - u.left;
99
+ r((y) => y.left === x && y.areaWidth === u.width ? y : { left: x, areaWidth: u.width });
100
+ };
101
+ if (a(), typeof window > "u" || typeof window.ResizeObserver > "u") return;
102
+ const c = new window.ResizeObserver(a);
103
+ return c.observe(o), c.observe(l), () => c.disconnect();
104
+ }, [s, S]), b;
105
+ }
106
+ const Oe = be(function({
107
+ label: s,
108
+ presentation: b = "docked",
109
+ open: r,
110
+ onOpenChange: l,
111
+ width: o,
112
+ minWidth: a = 0,
113
+ maxWidth: c = Number.POSITIVE_INFINITY,
114
+ onWidthChange: u,
115
+ railLabel: x,
116
+ expandLabel: y,
117
+ railWidth: A = ye,
118
+ header: O,
119
+ headerHeight: V = he,
120
+ keepMounted: Y = !1,
121
+ surface: _ = "card",
122
+ zIndex: G,
123
+ inert: J,
124
+ children: Q,
125
+ style: W,
126
+ onKeyDown: I,
127
+ ...Z
128
+ }, P) {
129
+ const i = b !== "docked", R = b === "fullscreen", F = p(null), k = p(null), E = p(null), m = Ee(F, i && r), H = ve[_], D = !!x && !R, ee = me(
130
+ (e) => {
131
+ k.current = e, typeof P == "function" ? P(e) : P && (P.current = e);
132
+ },
133
+ [P]
134
+ );
135
+ C(() => {
136
+ const e = k.current;
137
+ e && (J ? e.setAttribute("inert", "") : e.removeAttribute("inert"));
138
+ });
139
+ const d = i && r, N = p(null), B = p(!1), T = p(!1);
140
+ C(() => {
141
+ var t;
142
+ const e = T.current;
143
+ if (T.current = d, d && !e) {
144
+ const n = document.activeElement;
145
+ E.current = n instanceof HTMLElement && n !== document.body ? n : null, (t = k.current) == null || t.focus({ preventScroll: !0 });
146
+ } else if (!d && e) {
147
+ const n = k.current, h = document.activeElement, z = !h || h === document.body || !!(n != null && n.contains(h)), f = B.current ? N.current : E.current;
148
+ B.current = !1, E.current = null, z && (f != null && f.isConnected) && f.focus({ preventScroll: !0 });
149
+ }
150
+ }, [d]);
151
+ const te = (e) => {
152
+ if (I == null || I(e), !d || e.defaultPrevented || e.nativeEvent.defaultPrevented) return;
153
+ if (e.key === "Escape") {
154
+ e.preventDefault(), l(!1);
155
+ return;
156
+ }
157
+ if (e.key !== "Tab") return;
158
+ const t = k.current;
159
+ if (!t) return;
160
+ const n = Array.from(t.querySelectorAll(Ie)).filter((fe) => fe.getClientRects().length > 0);
161
+ if (n.length === 0) {
162
+ e.preventDefault();
163
+ return;
164
+ }
165
+ const h = n[0], z = n[n.length - 1], f = document.activeElement;
166
+ e.shiftKey && (f === h || f === t) ? (e.preventDefault(), z.focus()) : !e.shiftKey && f === z && (e.preventDefault(), h.focus());
167
+ }, ne = !i && r && !!u, [re, L] = U(!1), w = p(null), j = (e) => u == null ? void 0 : u(ze(Math.round(e), a, c)), oe = (e) => {
168
+ var t, n;
169
+ e.button === 0 && (e.preventDefault(), (n = (t = e.currentTarget).setPointerCapture) == null || n.call(t, e.pointerId), w.current = { startX: e.clientX, startWidth: o }, L(!0), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none");
170
+ }, ie = (e) => {
171
+ const t = w.current;
172
+ t && j(t.startWidth + e.clientX - t.startX);
173
+ }, X = () => {
174
+ w.current && (w.current = null, L(!1), document.body.style.cursor = "", document.body.style.userSelect = "");
175
+ };
176
+ q(
177
+ () => () => {
178
+ w.current && (document.body.style.cursor = "", document.body.style.userSelect = "");
179
+ },
180
+ []
181
+ );
182
+ const le = (e) => {
183
+ const t = e.key === "ArrowLeft" ? o - K : e.key === "ArrowRight" ? o + K : e.key === "Home" && Number.isFinite(a) ? a : e.key === "End" && Number.isFinite(c) ? c : null;
184
+ t !== null && (e.preventDefault(), j(t));
185
+ }, se = r || Y, ae = i ? R ? m.areaWidth || "100%" : m.areaWidth ? Math.max(0, Math.min(o, m.areaWidth - m.left)) : o : "100%", ce = i ? D ? A : 0 : r ? o : D ? A : 0, ue = !i && r ? a : void 0, de = D && !r && /* @__PURE__ */ v(Re, { style: { width: A, minWidth: A, background: H }, children: /* @__PURE__ */ v(
186
+ ke,
187
+ {
188
+ ref: N,
189
+ type: "button",
190
+ "aria-label": y ?? `Open ${s}`,
191
+ title: y ?? `Open ${s}`,
192
+ onClick: () => {
193
+ B.current = i, l(!0);
194
+ },
195
+ children: /* @__PURE__ */ v(
196
+ ge,
197
+ {
198
+ as: "span",
199
+ variant: "body-xs",
200
+ tone: "secondary",
201
+ style: { fontSize: "10px", letterSpacing: "2px", writingMode: "vertical-rl", transform: "rotate(180deg)" },
202
+ children: x
203
+ }
204
+ )
205
+ }
206
+ ) });
207
+ return /* @__PURE__ */ $(
208
+ Se,
209
+ {
210
+ ref: F,
211
+ "data-presentation": b,
212
+ "data-state": r ? "open" : "closed",
213
+ style: { width: ce, minWidth: ue, zIndex: d ? G : void 0 },
214
+ children: [
215
+ de,
216
+ d && !R && /* @__PURE__ */ v(we, { "aria-hidden": "true", style: { left: -m.left, width: m.areaWidth || "100vw" }, onClick: () => l(!1) }),
217
+ se && /* @__PURE__ */ $(
218
+ xe,
219
+ {
220
+ ...Z,
221
+ ref: ee,
222
+ "aria-label": s,
223
+ role: i ? "dialog" : "complementary",
224
+ "aria-modal": d ? !0 : void 0,
225
+ tabIndex: i ? -1 : void 0,
226
+ onKeyDown: te,
227
+ style: {
228
+ background: H,
229
+ borderRight: R ? "none" : M,
230
+ ...i ? { position: "absolute", top: 0, bottom: 0, left: R ? -m.left : 0, width: ae, height: "auto" } : { position: "relative", width: "100%" },
231
+ ...r ? null : { display: "none" },
232
+ ...W
233
+ },
234
+ children: [
235
+ i && O && /* @__PURE__ */ v(Pe, { style: { height: V }, children: O }),
236
+ Q,
237
+ ne && /* @__PURE__ */ v(
238
+ Ae,
239
+ {
240
+ role: "separator",
241
+ "aria-orientation": "vertical",
242
+ "aria-label": `Resize ${s.toLowerCase()}`,
243
+ "aria-valuenow": o,
244
+ "aria-valuemin": Number.isFinite(a) ? a : void 0,
245
+ "aria-valuemax": Number.isFinite(c) ? c : void 0,
246
+ tabIndex: 0,
247
+ "data-dragging": re ? "" : void 0,
248
+ onPointerDown: oe,
249
+ onPointerMove: ie,
250
+ onPointerUp: X,
251
+ onPointerCancel: X,
252
+ onKeyDown: le
253
+ }
254
+ )
255
+ ]
256
+ }
257
+ )
258
+ ]
259
+ }
260
+ );
261
+ });
262
+ export {
263
+ Oe as SidePanel
264
+ };
265
+ //# sourceMappingURL=SidePanel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SidePanel.js","sources":["../../../../../src/components/ui/patterns/SidePanel/SidePanel.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n type HTMLAttributes,\n type KeyboardEvent as ReactKeyboardEvent,\n type PointerEvent as ReactPointerEvent,\n type ReactNode,\n type RefObject\n} from \"react\";\nimport styled from \"@emotion/styled\";\nimport { Text } from \"../../primitives/Text\";\n\n/**\n * How the panel sits next to the page.\n *\n * - `docked`: beside the page, taking its own width (desktop).\n * - `overlay`: over the page, from where the panel would sit, with a scrim over\n * the rest (tablet). The page keeps its full width.\n * - `fullscreen`: over the whole of the area it sits in (phone).\n */\nexport type SidePanelPresentation = \"docked\" | \"overlay\" | \"fullscreen\";\n\nexport type SidePanelProps = Omit<HTMLAttributes<HTMLElement>, \"children\" | \"title\"> & {\n /** Accessible name of the panel, e.g. \"Chat\". */\n label: string;\n presentation?: SidePanelPresentation;\n open: boolean;\n /**\n * Called with `true` from the collapsed rail, and with `false` when an\n * overlaid panel is dismissed (scrim, Escape). Closing a docked panel is the\n * host's own control.\n */\n onOpenChange: (open: boolean) => void;\n /** Width in px. Docked: the panel's width. Overlaid: its width when there is room. */\n width: number;\n minWidth?: number;\n maxWidth?: number;\n /** Makes a docked panel resizable (pointer and keyboard), reporting the new width. */\n onWidthChange?: (width: number) => void;\n /**\n * Show a collapsed rail with this vertical label while the panel is closed\n * (docked and overlay). Overlaid, the rail's place is kept while open so the\n * page does not move. Not shown fullscreen.\n */\n railLabel?: string;\n /** Accessible name of the rail's button. Defaults to `Open <label>`. */\n expandLabel?: string;\n railWidth?: number;\n /** Shown at the top of an overlaid panel, at the workspace header's height. */\n header?: ReactNode;\n headerHeight?: number;\n /** Keep the content mounted (hidden) while closed, e.g. to keep a draft. */\n keepMounted?: boolean;\n /** Panel and rail background. `tinted` is the conversation surface. */\n surface?: \"card\" | \"tinted\";\n /** Stacking order of an overlaid panel and its scrim. */\n zIndex?: number;\n /** Make the panel non-interactive, e.g. while something else is open over it. */\n inert?: boolean;\n children: ReactNode;\n};\n\nconst defaultRailWidth = 40;\nconst defaultHeaderHeight = 52;\nconst keyboardStep = 16;\n\nconst surfaces = {\n card: \"hsl(var(--bfrs-color-surface-card))\",\n tinted: \"var(--bfrs-dcl-color-primary-light)\"\n} as const;\n\nconst rule = \"1px solid hsl(var(--bfrs-color-border-strong))\";\n\nconst SidePanelSlot = /*#__PURE__*/ styled(\"div\", {\n label: \"AgenticSidePanel-slot\"\n})({\n position: \"relative\",\n display: \"flex\",\n flexShrink: 0,\n height: \"100%\"\n});\n\nconst SidePanelSurface = /*#__PURE__*/ styled(\"aside\", {\n label: \"AgenticSidePanel-panel\"\n})({\n display: \"flex\",\n flexDirection: \"column\",\n height: \"100%\",\n outline: \"none\"\n});\n\nconst SidePanelHeader = /*#__PURE__*/ styled(\"div\", {\n label: \"AgenticSidePanel-header\"\n})({\n display: \"flex\",\n flexShrink: 0,\n alignItems: \"center\",\n paddingLeft: \".875rem\",\n paddingRight: \".5rem\",\n borderBottom: rule,\n backgroundColor: \"hsl(var(--bfrs-color-surface-card))\"\n});\n\nconst SidePanelRail = /*#__PURE__*/ styled(\"div\", {\n label: \"AgenticSidePanel-rail\"\n})({\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n flexShrink: 0,\n height: \"100%\",\n paddingTop: 12,\n borderRight: rule,\n zIndex: 5\n});\n\nconst SidePanelRailButton = /*#__PURE__*/ styled(\"button\", {\n label: \"AgenticSidePanel-railButton\"\n})({\n flex: 1,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n width: \"100%\",\n padding: 0,\n border: 0,\n background: \"none\",\n cursor: \"pointer\",\n \"&:focus-visible\": {\n outline: \"2px solid hsl(var(--bfrs-color-primary))\",\n outlineOffset: -2\n }\n});\n\nconst SidePanelScrim = /*#__PURE__*/ styled(\"div\", {\n label: \"AgenticSidePanel-scrim\"\n})({\n position: \"absolute\",\n top: 0,\n bottom: 0,\n backgroundColor: \"hsl(var(--bfrs-color-surface-app) / 0.6)\"\n});\n\nconst SidePanelResizeHandle = /*#__PURE__*/ styled(\"div\", {\n label: \"AgenticSidePanel-resizeHandle\"\n})({\n position: \"absolute\",\n top: 0,\n right: 0,\n zIndex: 20,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n width: 8,\n height: \"100%\",\n cursor: \"col-resize\",\n touchAction: \"none\",\n outline: \"none\",\n \"&:hover, &:focus-visible, &[data-dragging]\": {\n backgroundColor: \"hsl(var(--bfrs-color-primary) / 0.08)\"\n },\n \"&::after\": {\n content: '\"\"',\n width: 2,\n height: 40,\n borderRadius: 3,\n backgroundColor: \"var(--bfrs-dcl-color-neutral-stroke-2)\"\n }\n});\n\nconst useIsomorphicLayoutEffect = typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nconst FOCUSABLE =\n 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/** Where the slot sits in the area it belongs to, for an overlaid panel. */\nfunction useAnchor(slotRef: RefObject<HTMLDivElement | null>, active: boolean) {\n const [anchor, setAnchor] = useState({ left: 0, areaWidth: 0 });\n useIsomorphicLayoutEffect(() => {\n const slot = slotRef.current;\n const area = slot?.parentElement;\n if (!active || !slot || !area) return;\n const measure = () => {\n const areaRect = area.getBoundingClientRect();\n const left = slot.getBoundingClientRect().left - areaRect.left;\n setAnchor((prev) => (prev.left === left && prev.areaWidth === areaRect.width ? prev : { left, areaWidth: areaRect.width }));\n };\n measure();\n if (typeof window === \"undefined\" || typeof window.ResizeObserver === \"undefined\") return;\n const observer = new window.ResizeObserver(measure);\n observer.observe(area);\n observer.observe(slot);\n return () => observer.disconnect();\n }, [active, slotRef]);\n return anchor;\n}\n\n\n/**\n * A side panel that sits beside the page on a wide screen and over it on a\n * narrow one: the host picks the `presentation`, the panel handles the rest —\n * its collapsed rail, resizing, and, overlaid, its geometry, scrim, Escape and\n * focus. Rest props (`data-*`, `aria-*`, `className`, `style`) go on the panel.\n */\nexport const SidePanel = forwardRef<HTMLElement, SidePanelProps>(function SidePanel(\n {\n label,\n presentation = \"docked\",\n open,\n onOpenChange,\n width,\n minWidth = 0,\n maxWidth = Number.POSITIVE_INFINITY,\n onWidthChange,\n railLabel,\n expandLabel,\n railWidth = defaultRailWidth,\n header,\n headerHeight = defaultHeaderHeight,\n keepMounted = false,\n surface = \"card\",\n zIndex,\n inert,\n children,\n style,\n onKeyDown,\n ...rest\n },\n forwardedRef\n) {\n const overlaid = presentation !== \"docked\";\n const fullscreen = presentation === \"fullscreen\";\n const slotRef = useRef<HTMLDivElement>(null);\n const panelRef = useRef<HTMLElement | null>(null);\n const returnFocusRef = useRef<HTMLElement | null>(null);\n const anchor = useAnchor(slotRef, overlaid && open);\n const background = surfaces[surface];\n const showRail = Boolean(railLabel) && !fullscreen;\n\n const setPanelRef = useCallback(\n (node: HTMLElement | null) => {\n panelRef.current = node;\n if (typeof forwardedRef === \"function\") forwardedRef(node);\n else if (forwardedRef) forwardedRef.current = node;\n },\n [forwardedRef]\n );\n\n // `inert` is set as an attribute so it works whatever React version renders it.\n useIsomorphicLayoutEffect(() => {\n const node = panelRef.current;\n if (!node) return;\n if (inert) node.setAttribute(\"inert\", \"\");\n else node.removeAttribute(\"inert\");\n });\n\n // Overlaid: focus moves into the panel as it opens and back to where it came\n // from as it closes. The panel itself takes focus, so a phone keyboard does\n // not pop up for the first field. Opened from the rail, focus goes back to the\n // rail (a new element by then: the rail is not drawn while the panel is open).\n const overlayOpen = overlaid && open;\n const railButtonRef = useRef<HTMLButtonElement>(null);\n const openedFromRailRef = useRef(false);\n const wasOverlayOpenRef = useRef(false);\n useIsomorphicLayoutEffect(() => {\n const wasOpen = wasOverlayOpenRef.current;\n wasOverlayOpenRef.current = overlayOpen;\n if (overlayOpen && !wasOpen) {\n const active = document.activeElement;\n returnFocusRef.current = active instanceof HTMLElement && active !== document.body ? active : null;\n panelRef.current?.focus({ preventScroll: true });\n } else if (!overlayOpen && wasOpen) {\n const panel = panelRef.current;\n const active = document.activeElement;\n const focusLeftWithPanel = !active || active === document.body || Boolean(panel?.contains(active));\n const back = openedFromRailRef.current ? railButtonRef.current : returnFocusRef.current;\n openedFromRailRef.current = false;\n returnFocusRef.current = null;\n if (focusLeftWithPanel && back?.isConnected) back.focus({ preventScroll: true });\n }\n }, [overlayOpen]);\n\n const handleKeyDown = (event: ReactKeyboardEvent<HTMLElement>) => {\n onKeyDown?.(event);\n if (!overlayOpen || event.defaultPrevented || event.nativeEvent.defaultPrevented) return;\n if (event.key === \"Escape\") {\n // A menu or popover inside the panel closes first (it prevents the default).\n event.preventDefault();\n onOpenChange(false);\n return;\n }\n if (event.key !== \"Tab\") return;\n const panel = panelRef.current;\n if (!panel) return;\n const focusables = Array.from(panel.querySelectorAll<HTMLElement>(FOCUSABLE)).filter((el) => el.getClientRects().length > 0);\n if (focusables.length === 0) {\n event.preventDefault();\n return;\n }\n const first = focusables[0];\n const last = focusables[focusables.length - 1];\n const current = document.activeElement;\n if (event.shiftKey && (current === first || current === panel)) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && current === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n // ── Resizing (docked) ──\n const resizable = !overlaid && open && Boolean(onWidthChange);\n const [dragging, setDragging] = useState(false);\n const dragRef = useRef<{ startX: number; startWidth: number } | null>(null);\n const commitWidth = (next: number) => onWidthChange?.(clamp(Math.round(next), minWidth, maxWidth));\n\n const onResizePointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (event.button !== 0) return;\n event.preventDefault();\n event.currentTarget.setPointerCapture?.(event.pointerId);\n dragRef.current = { startX: event.clientX, startWidth: width };\n setDragging(true);\n document.body.style.cursor = \"col-resize\";\n document.body.style.userSelect = \"none\";\n };\n const onResizePointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {\n const drag = dragRef.current;\n if (drag) commitWidth(drag.startWidth + event.clientX - drag.startX);\n };\n const endResize = () => {\n if (!dragRef.current) return;\n dragRef.current = null;\n setDragging(false);\n document.body.style.cursor = \"\";\n document.body.style.userSelect = \"\";\n };\n useEffect(\n () => () => {\n if (!dragRef.current) return;\n document.body.style.cursor = \"\";\n document.body.style.userSelect = \"\";\n },\n []\n );\n const onResizeKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {\n const next =\n event.key === \"ArrowLeft\" ? width - keyboardStep\n : event.key === \"ArrowRight\" ? width + keyboardStep\n : event.key === \"Home\" && Number.isFinite(minWidth) ? minWidth\n : event.key === \"End\" && Number.isFinite(maxWidth) ? maxWidth\n : null;\n if (next === null) return;\n event.preventDefault();\n commitWidth(next);\n };\n\n // ── Layout ──\n const mounted = open || keepMounted;\n const panelWidth = overlaid\n ? fullscreen\n ? anchor.areaWidth || \"100%\"\n : anchor.areaWidth\n ? Math.max(0, Math.min(width, anchor.areaWidth - anchor.left))\n : width\n : \"100%\";\n const slotWidth = overlaid ? (showRail ? railWidth : 0) : open ? width : showRail ? railWidth : 0;\n const slotMinWidth = !overlaid && open ? minWidth : undefined;\n\n // Closed: the rail. Open and overlaid, its place stays empty under the panel.\n const rail = showRail && !open && (\n <SidePanelRail style={{ width: railWidth, minWidth: railWidth, background }}>\n <SidePanelRailButton\n ref={railButtonRef}\n type=\"button\"\n aria-label={expandLabel ?? `Open ${label}`}\n title={expandLabel ?? `Open ${label}`}\n onClick={() => {\n openedFromRailRef.current = overlaid;\n onOpenChange(true);\n }}\n >\n <Text\n as=\"span\"\n variant=\"body-xs\"\n tone=\"secondary\"\n style={{ fontSize: \"10px\", letterSpacing: \"2px\", writingMode: \"vertical-rl\", transform: \"rotate(180deg)\" }}\n >\n {railLabel}\n </Text>\n </SidePanelRailButton>\n </SidePanelRail>\n );\n\n return (\n <SidePanelSlot\n ref={slotRef}\n data-presentation={presentation}\n data-state={open ? \"open\" : \"closed\"}\n style={{ width: slotWidth, minWidth: slotMinWidth, zIndex: overlayOpen ? zIndex : undefined }}\n >\n {rail}\n {overlayOpen && !fullscreen && (\n <SidePanelScrim aria-hidden=\"true\" style={{ left: -anchor.left, width: anchor.areaWidth || \"100vw\" }} onClick={() => onOpenChange(false)} />\n )}\n {mounted && (\n <SidePanelSurface\n {...rest}\n ref={setPanelRef}\n aria-label={label}\n role={overlaid ? \"dialog\" : \"complementary\"}\n aria-modal={overlayOpen ? true : undefined}\n tabIndex={overlaid ? -1 : undefined}\n onKeyDown={handleKeyDown}\n style={{\n background,\n borderRight: fullscreen ? \"none\" : rule,\n ...(overlaid\n ? { position: \"absolute\", top: 0, bottom: 0, left: fullscreen ? -anchor.left : 0, width: panelWidth, height: \"auto\" }\n : { position: \"relative\", width: \"100%\" }),\n ...(open ? null : { display: \"none\" }),\n ...style\n }}\n >\n {overlaid && header && <SidePanelHeader style={{ height: headerHeight }}>{header}</SidePanelHeader>}\n {children}\n {resizable && (\n <SidePanelResizeHandle\n role=\"separator\"\n aria-orientation=\"vertical\"\n aria-label={`Resize ${label.toLowerCase()}`}\n aria-valuenow={width}\n aria-valuemin={Number.isFinite(minWidth) ? minWidth : undefined}\n aria-valuemax={Number.isFinite(maxWidth) ? maxWidth : undefined}\n tabIndex={0}\n data-dragging={dragging ? \"\" : undefined}\n onPointerDown={onResizePointerDown}\n onPointerMove={onResizePointerMove}\n onPointerUp={endResize}\n onPointerCancel={endResize}\n onKeyDown={onResizeKeyDown}\n />\n )}\n </SidePanelSurface>\n )}\n </SidePanelSlot>\n );\n});\n"],"names":["defaultRailWidth","defaultHeaderHeight","keyboardStep","surfaces","rule","SidePanelSlot","SidePanelSurface","SidePanelHeader","SidePanelRail","SidePanelRailButton","SidePanelScrim","SidePanelResizeHandle","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","clamp","value","min","max","FOCUSABLE","useAnchor","slotRef","active","anchor","setAnchor","useState","slot","area","measure","areaRect","left","prev","observer","SidePanel","forwardRef","label","presentation","open","onOpenChange","width","minWidth","maxWidth","onWidthChange","railLabel","expandLabel","railWidth","header","headerHeight","keepMounted","surface","zIndex","inert","children","style","onKeyDown","rest","forwardedRef","overlaid","fullscreen","useRef","panelRef","returnFocusRef","background","showRail","setPanelRef","useCallback","node","overlayOpen","railButtonRef","openedFromRailRef","wasOverlayOpenRef","wasOpen","_a","panel","focusLeftWithPanel","back","handleKeyDown","event","focusables","el","first","last","current","resizable","dragging","setDragging","dragRef","commitWidth","next","onResizePointerDown","_b","onResizePointerMove","drag","endResize","onResizeKeyDown","mounted","panelWidth","slotWidth","slotMinWidth","rail","jsx","Text","jsxs"],"mappings":";;;;AAkEA,MAAMA,KAAmB,IACnBC,KAAsB,IACtBC,IAAe,IAEfC,KAAW;AAAA,EACf,MAAM;AAAA,EACN,QAAQ;AACV,GAEMC,IAAO,kDAEPC,uBAAqC,OAAO;AAAA,EAChD,OAAO;AACT,CAAC,EAAE;AAAA,EACD,UAAU;AAAA,EACV,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,QAAQ;AACV,CAAC,GAEKC,uBAAwC,SAAS;AAAA,EACrD,OAAO;AACT,CAAC,EAAE;AAAA,EACD,SAAS;AAAA,EACT,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,SAAS;AACX,CAAC,GAEKC,uBAAuC,OAAO;AAAA,EAClD,OAAO;AACT,CAAC,EAAE;AAAA,EACD,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,cAAc;AAAA,EACd,cAAcH;AAAA,EACd,iBAAiB;AACnB,CAAC,GAEKI,uBAAqC,OAAO;AAAA,EAChD,OAAO;AACT,CAAC,EAAE;AAAA,EACD,SAAS;AAAA,EACT,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,aAAaJ;AAAA,EACb,QAAQ;AACV,CAAC,GAEKK,uBAA2C,UAAU;AAAA,EACzD,O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