diff --git a/packages/app/src/shell/panel-motion.ts b/packages/app/src/shell/panel-motion.ts
index ff26ce949e5..da3df6cd66d 100644
--- a/packages/app/src/shell/panel-motion.ts
+++ b/packages/app/src/shell/panel-motion.ts
@@ -46,6 +46,8 @@ export function createPanelMotion(input: {
/** A change shows the new state without motion, e.g. switching to another session's layout. */
identity?: Accessor
onClosed?: () => void
+ /** Reads layout in the frame loop's read phase, before each frame of a flight paints. */
+ measure?: () => void
}) {
const [present, setPresent] = createSignal(input.open())
// Percent closed, so the spring's rest threshold stays well under a pixel.
@@ -118,7 +120,7 @@ export function createPanelMotion(input: {
motion.set(target)
fly(true)
// Writes only; anything reading layout this frame does so in the loop's read phase, before this runs.
- stop ??= frameLoop.add((dt) => {
+ const step = (dt: number) => {
motion.step(dt)
paint()
@@ -127,7 +129,8 @@ export function createPanelMotion(input: {
settle()
return false
- })
+ }
+ stop ??= input.measure ? frameLoop.addMeasured(input.measure, step) : frameLoop.add(step)
},
),
)
diff --git a/packages/app/src/shell/shell.tsx b/packages/app/src/shell/shell.tsx
index 871cb01ebbf..5628933fe8b 100644
--- a/packages/app/src/shell/shell.tsx
+++ b/packages/app/src/shell/shell.tsx
@@ -13,7 +13,7 @@ import { ExtensionServerCover } from "@/runtime/extension/server-shell"
import { ExtensionSlot } from "@/runtime/extension/render"
import { useCommand } from "@/shell/commands/command"
import { useLanguage } from "@/runtime/i18n/language"
-import { CollapsedSidebarToggle, paintCollapsedSlots } from "@/shell/sidebar-toggle"
+import { CollapsedSidebarToggle, measureSidebarToggles, paintCollapsedSlots } from "@/shell/sidebar-toggle"
import { createPanelMotion, guardClosingFocus, replayPanelToggle } from "@/shell/panel-motion"
import { windowDragEnabled } from "@/session/header/drag-area"
@@ -46,8 +46,12 @@ export default function Layout(props: ParentProps) {
const aside = state.tabsAside
if (aside) aside.style.width = `${state.tabsWidth * (1 - closed)}px`
+
+ // Dims the contents, background included, as they leave and fade them in as they arrive.
+ if (state.tabsMount) state.tabsMount.style.opacity = closed === 0 ? "" : `${1 - closed}`
paintCollapsedSlots(closed)
},
+ measure: () => measureSidebarToggles(state.tabsWidth),
})
replayPanelToggle({ id: "sidebar", label: "Toggle the left sidebar", toggle: toggleSidebar })
@@ -124,7 +128,7 @@ export default function Layout(props: ParentProps) {
>
setState("tabsMount", element)}
- class="absolute inset-y-0 end-0 contain-strict flex min-h-0 flex-col bg-v2-background-bg-deep pe-0.5 ps-2.5 pb-[var(--shell-bottom-inset,8px)] pt-[var(--shell-top-inset,8px)]"
+ class="absolute inset-y-0 end-0 contain-strict will-change-[opacity] flex min-h-0 flex-col bg-v2-background-bg-deep pe-0.5 ps-2.5 pb-[var(--shell-bottom-inset,8px)] pt-[var(--shell-top-inset,8px)]"
style={{
width: `${state.tabsWidth}px`,
"padding-bottom": "max(10px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)))",
@@ -165,8 +169,8 @@ export default function Layout(props: ParentProps) {
{props.children}
-
+
diff --git a/packages/app/src/shell/sidebar-toggle.tsx b/packages/app/src/shell/sidebar-toggle.tsx
index 37d6fa15b9e..8a0bd50ccdd 100644
--- a/packages/app/src/shell/sidebar-toggle.tsx
+++ b/packages/app/src/shell/sidebar-toggle.tsx
@@ -33,9 +33,9 @@ const slotWidth = 32
const contentStart = 18
/**
- * `handoff` makes this one of the two vertical-tabs toggles, each shown only on its side of the motion: "out" rides
- * the sidebar's header and fades as it passes the collapsed slot, then the "in" toggle fades up. Each keeps its own
- * icon, so neither flips mid-flight.
+ * `handoff` makes this one of the two vertical-tabs toggles that read as one icon: "out" sits in the sidebar's header
+ * and shows only while the sidebar rests open; "in" shows otherwise, travelling from the header's spot to the
+ * collapsed one on the sidebar's spring as its glyph turns from the open one to the closed one.
*/
export function SidebarToggle(props: { handoff?: "out" | "in" }) {
const command = useCommand()
@@ -43,7 +43,28 @@ export function SidebarToggle(props: { handoff?: "out" | "in" }) {
const settings = useSettings()
const keybind = () => command.keybindParts("sidebar.toggle")
const side = props.handoff
- const ref = side && collapsedRef((button, closed) => (button.style.opacity = `${handoff(side, closed)}`))
+ let full: SVGSVGElement | undefined
+ let outline: SVGSVGElement | undefined
+ const ref =
+ side === "out"
+ ? collapsedRef((button, closed) => {
+ travel.header = button
+ button.style.opacity = closed === 0 ? "" : "0"
+ })
+ : side === "in"
+ ? collapsedRef((button, closed) => {
+ travel.toggle = button
+ const moving = closed > 0 && closed < 1
+ travel.dx = moving ? travel.x * (1 - closed) : 0
+ travel.dy = moving ? travel.y * (1 - closed) : 0
+ button.style.opacity = closed === 0 ? "0" : ""
+ button.style.transform = moving ? `translate3d(${travel.dx}px, ${travel.dy}px, 0)` : ""
+
+ if (full) full.style.opacity = `${1 - closed}`
+
+ if (outline) outline.style.opacity = `${closed}`
+ })
+ : undefined
return (
+ side === "in" ? (
+
+
+
+
+ ) : (
+
+ )
}
/>
@@ -105,7 +133,7 @@ function useCollapsedSlot() {
const slotClass = "flex shrink-0 justify-end overflow-hidden"
// How far closed the left sidebar is, from 0 to 1. The shell paints it on every frame of the sidebar's motion; the
-// collapsed toggle and the space headers keep for it grow with it, so header contents travel with the sidebar's edge.
+// space headers keep for the collapsed toggle grows with it, so header contents travel with the sidebar's edge.
const collapsed = { closed: 0, slots: new Set<() => void>() }
export function paintCollapsedSlots(closed: number) {
@@ -113,6 +141,28 @@ export function paintCollapsedSlots(closed: number) {
collapsed.slots.forEach((paint) => paint())
}
+// The two vertical-tabs toggles, how far the header one rests from the collapsed one (x, y), and the offset the
+// collapsed one is drawn at now (dx, dy).
+const travel: { header?: HTMLElement; toggle?: HTMLElement; x: number; y: number; dx: number; dy: number } = {
+ x: 0,
+ y: 0,
+ dx: 0,
+ dy: 0,
+}
+
+/**
+ * Measures, in the frame loop's read phase of the sidebar's motion, how far the header toggle rests from the collapsed
+ * one. The header toggle rides the sidebar's edge, `width × closed` from where it rests open.
+ */
+export function measureSidebarToggles(width: number) {
+ if (!travel.header?.isConnected || !travel.toggle?.isConnected) return
+ const header = travel.header.getBoundingClientRect()
+ const toggle = travel.toggle.getBoundingClientRect()
+ const direction = document.documentElement.dir === "rtl" ? -1 : 1
+ travel.x = header.left + direction * width * collapsed.closed - (toggle.left - travel.dx)
+ travel.y = header.top - (toggle.top - travel.dy)
+}
+
/** A ref whose element `paint` styles from how far closed the sidebar is, now and on every frame of its motion. */
function collapsedRef(paint: (element: HTMLElement, closed: number) => void) {
let target: HTMLElement | undefined
@@ -136,25 +186,16 @@ function slotRef(width: () => number) {
return collapsedRef((slot, closed) => (slot.style.width = `${width() * closed}px`))
}
-// The collapsed toggle rides the content's edge, so the two never meet: the sliding one fades out as it passes the
-// collapsed slot, then the collapsed one fades up, and only one shows at a time.
-function handoff(side: "out" | "in", closed: number) {
- if (side === "out") return 1 - Math.min(1, Math.max(0, (closed - 0.55) / 0.2))
-
- return Math.min(1, Math.max(0, (closed - 0.75) / 0.25))
-}
-
-// Floats over the top of every screen, centered on the session header's 48px row. Appears at the content's start edge
-// when the sidebar closes.
+// Floats over the top of every screen, centered on the session header's 48px row, where the content starts once the
+// sidebar has closed. It sits outside the sidebar and the content, so neither clips it as it travels.
export function CollapsedSidebarToggle() {
const slot = useCollapsedSlot()
- const ref = slotRef(slot.width)
return (