Skip to content

An open-source, self-hosted system for apps built with web technologies.

Replace desktop GSAP with Motion

zohayrslilehb0ef7485dcc4
diff --git a/bun.lock b/bun.lock
index 487bf6f..5b4a8fd 100644
--- a/bun.lock
+++ b/bun.lock
@@ -13,9 +13,9 @@
"@react-aria/utils": "^3.34.1",
"cfonts": "^3.3.1",
"get-port": "^7.2.0",
- "gsap": "^3.15.0",
"hono": "^4.13.2",
"keyv": "^5.6.0",
+ "motion": "^13.1.1",
"node-rsa": "^2.0.0",
"react": "^19.2.8",
"react-aria": "^3.51.0",
@@ -381,6 +381,8 @@
"fdir": ["[email protected]", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="],
+ "framer-motion": ["[email protected]", "", { "dependencies": { "motion-dom": "^13.1.1", "motion-utils": "^13.0.0", "tslib": "^2.4.0" }, "peerDependencies": { "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" }, "optionalPeers": ["react", "react-dom"] }, "sha512-B/xn2TPS4f61cEBLFjiYlQFnBZUW1YVj/LM+C+N4OP8Rs95VLEI2ot/RlfBg111la/EiyECFaJJi/A3FWA8MUA=="],
+
"fsevents": ["[email protected]", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="],
"function-bind": ["[email protected]", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="],
@@ -391,8 +393,6 @@
"graceful-fs": ["[email protected]", "", {}, "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="],
- "gsap": ["[email protected]", "", {}, "sha512-dMW4CWBTUK1AEEDeZc1g4xpPGIrSf9fJF960qbTZmN/QwZIWY5wgliS6JWl9/25fpTGJrMRtSjGtOmPnfjZB+A=="],
-
"has-flag": ["[email protected]", "", {}, "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="],
"hasown": ["[email protected]", "", { "dependencies": { "function-bind": "^1.1.2" } }, "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A=="],
@@ -451,6 +451,12 @@
"magic-string": ["[email protected]", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="],
+ "motion": ["[email protected]", "", { "dependencies": { "framer-motion": "^13.1.1", "tslib": "^2.4.0" }, "peerDependencies": { "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" }, "optionalPeers": ["react", "react-dom"] }, "sha512-WNZoK6xiF+kkTqkZ5K7FDDh6A8BG4i5Hc7KXtW8gtTxkpJFds+hIOrDaQGKjQj/AE/i4hJqAaUHEqp/Qo02y6Q=="],
+
+ "motion-dom": ["[email protected]", "", { "dependencies": { "motion-utils": "^13.0.0" } }, "sha512-XSf8VYWSB6G/0IY3rWVbyLcxWXtAVHkN1PQE2agTaCv3u8RGvbwu56TyyR/MNzBqqNavEBTZzErcxI1TxBrjcA=="],
+
+ "motion-utils": ["[email protected]", "", {}, "sha512-7DnN7TmbLcYXcG4RVadXIihWlyuM9afoUww8Y5Agg431kGKiuL2/OMyP4mJ5wLz+pvN3t5ySClLOaVXJ+wekRQ=="],
+
"ms": ["[email protected]", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
"nanoid": ["[email protected]", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w=="],
diff --git a/package.json b/package.json
index c838ab6..20d106d 100644
--- a/package.json
+++ b/package.json
@@ -43,9 +43,9 @@
"@react-aria/utils": "^3.34.1",
"cfonts": "^3.3.1",
"get-port": "^7.2.0",
- "gsap": "^3.15.0",
"hono": "^4.13.2",
"keyv": "^5.6.0",
+ "motion": "^13.1.1",
"node-rsa": "^2.0.0",
"react": "^19.2.8",
"react-aria": "^3.51.0",
diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsx
index 7b829f9..3050145 100644
--- a/source/client/view/appearance/appearance.tsx
+++ b/source/client/view/appearance/appearance.tsx
@@ -1,6 +1,6 @@
import DesktopPreferencesProvider, { useDesktopPreferences } from "./desktop-preferences"
import { standardAppearance } from "@phreshos/core"
-import ReducedMotion from "@libs/react-motion"
+import { MotionConfig } from "motion/react"
import { PropsWithChildren } from "react"
import "./appearance.css"
@@ -17,7 +17,7 @@ function AppearanceRoot({ children }: PropsWithChildren) {
const { preferences } = useDesktopPreferences()
const background = standardAppearance.background[preferences.theme]
- return <ReducedMotion reduced={!preferences.animations}>
+ return <MotionConfig reducedMotion={preferences.animations ? "never" : "always"}>
<div className="relative isolate grid h-dvh overflow-hidden font-roboto" style={{ backgroundColor: background }}>
@@ -25,5 +25,5 @@ function AppearanceRoot({ children }: PropsWithChildren) {
</div>
- </ReducedMotion>
+ </MotionConfig>
}
diff --git a/source/client/view/appearance/motion.ts b/source/client/view/appearance/motion.ts
index 5261408..dfc92af 100644
--- a/source/client/view/appearance/motion.ts
+++ b/source/client/view/appearance/motion.ts
@@ -1,19 +1,14 @@
-import { type Easing } from "@phreshos/core"
-import gsap from "gsap"
-import { CustomEase } from "gsap/CustomEase"
+import { type Easing as SystemEasing } from "@phreshos/core"
+import { type Easing } from "motion"
-gsap.registerPlugin(CustomEase)
-
-const curves: Record<Exclude<Easing, readonly number[]>, readonly [number, number, number, number]> = {
- linear: [0, 0, 1, 1],
+const curves: Record<Exclude<SystemEasing, readonly number[]>, Easing> = {
+ linear: "linear",
ease: [0.25, 0.1, 0.25, 1],
- "ease-in": [0.42, 0, 1, 1],
- "ease-out": [0, 0, 0.58, 1],
- "ease-in-out": [0.42, 0, 0.58, 1]
+ "ease-in": "easeIn",
+ "ease-out": "easeOut",
+ "ease-in-out": "easeInOut"
}
-const registered = new Map<string, gsap.EaseFunction>()
-
/** Shared interaction timings in the same millisecond unit as public transactions. */
export const motionDurations = Object.freeze({
control: 100,
@@ -27,26 +22,15 @@ export const motionDurations = Object.freeze({
geometry: 300
})
-/** Preserves public CSS timing curves while GSAP owns their interpolation. */
-export function motionEase(value: Easing | undefined, fallback: Easing = "ease-out") {
+/** Converts a public CSS timing curve into Motion's equivalent easing. */
+export function motionEase(value: SystemEasing | undefined, fallback: SystemEasing = "ease-out"): Easing {
const selected = value ?? fallback
- const points = typeof selected === "string" ? curves[selected] : selected
- const key = points.join(",")
- const existing = registered.get(key)
-
- if (existing) return existing
- const easing = CustomEase.create(`phresh-${registered.size}`, key)
-
- registered.set(key, easing)
-
- return easing
+ return typeof selected === "string" ? curves[selected] : selected
}
export function motionDuration(milliseconds: number) {
return milliseconds / 1_000
}
-
-export default gsap
diff --git a/source/client/view/appearance/surface-presence.ts b/source/client/view/appearance/surface-presence.ts
index 505875b..4b3b7f2 100644
--- a/source/client/view/appearance/surface-presence.ts
+++ b/source/client/view/appearance/surface-presence.ts
@@ -1,17 +1,19 @@
-import gsap, { motionDuration, motionDurations } from "./motion"
+import { animate, type AnimationPlaybackControlsWithThen } from "motion"
+import { motionDuration, motionDurations, motionEase } from "./motion"
const entered = { scale: 1, y: 0 }
const entering = { scale: 0.96, y: 8 }
+const animations = new WeakMap<HTMLElement, AnimationPlaybackControlsWithThen>()
+
/** Establish the first frame before a surface becomes visible. */
export function prepareSurfaceEntrance(surface: HTMLElement | null, reducedMotion: boolean) {
if (!surface) return
- gsap.killTweensOf(surface)
-
- gsap.set(surface, reducedMotion ? entered : entering)
+ stop(surface)
+ set(surface, reducedMotion ? entered : entering)
}
/** Give every system surface the same entrance motion. */
@@ -19,21 +21,23 @@ export function enterSurface(surface: HTMLElement | null, reducedMotion: boolean
if (!surface) return null
- gsap.killTweensOf(surface)
+ stop(surface)
if (reducedMotion) {
- gsap.set(surface, entered)
+ set(surface, entered)
return null
}
- return gsap.to(surface, {
- ...entered,
+ const animation = animate(surface, entered, {
duration: motionDuration(motionDurations.presence),
- ease: "power3.out",
- overwrite: "auto"
+ ease: motionEase([0.33, 1, 0.68, 1])
})
+
+ animations.set(surface, animation)
+
+ return animation
}
/** Stop presence motion and leave the surface ready for its next entrance. */
@@ -41,7 +45,15 @@ export function restSurface(surface: HTMLElement | null) {
if (!surface) return
- gsap.killTweensOf(surface)
+ stop(surface)
+ set(surface, entered)
+}
+
+function stop(surface: HTMLElement) {
+ animations.get(surface)?.stop()
+ animations.delete(surface)
+}
- gsap.set(surface, entered)
+function set(surface: HTMLElement, target: typeof entered) {
+ surface.style.transform = target.scale === 1 && target.y === 0 ? "" : `translateY(${target.y}px) scale(${target.scale})`
}
diff --git a/source/client/view/structure/authentication/credentials-form.tsx b/source/client/view/structure/authentication/credentials-form.tsx
index d7dbf64..a687618 100644
--- a/source/client/view/structure/authentication/credentials-form.tsx
+++ b/source/client/view/structure/authentication/credentials-form.tsx
@@ -28,7 +28,7 @@ export default function CredentialsForm({ title, description, submitLabel, passw
return () => {
- entrance?.kill()
+ entrance?.stop()
restSurface(surface.current)
}
diff --git a/source/client/view/structure/desktop/windows/snap-preview.tsx b/source/client/view/structure/desktop/windows/snap-preview.tsx
index 3ebd894..3eeac61 100644
--- a/source/client/view/structure/desktop/windows/snap-preview.tsx
+++ b/source/client/view/structure/desktop/windows/snap-preview.tsx
@@ -1,11 +1,12 @@
import { type CSSProperties, useLayoutEffect, useRef, useState } from "react"
-import gsap, { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"
+import { animate } from "motion"
+import { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"
import { resolveWindowGeometry, resolveWindowValue, windowPaintInsets, type WindowSurfaceSize } from "../../../components/window-manager/window-geometry"
import { windowPaintInset } from "../geometry"
import { type Position, type Size } from "@phreshos/core"
import { Surface } from "@phreshos/react-ui"
-/** GSAP-owned preview of the placement currently offered by a drag. */
+/** Animated preview of the placement currently offered by a drag. */
export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, radius, reducedMotion, zIndex }: SnapPreviewProps) {
const element = useRef<HTMLDivElement>(null)
@@ -20,47 +21,32 @@ export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, ra
if (!preview || !parent) return
const parentBounds = parent.getBoundingClientRect()
- const shownBounds = preview.getBoundingClientRect()
- const current = {
- x: shownBounds.left - parentBounds.left,
- y: shownBounds.top - parentBounds.top,
- width: shownBounds.width,
- height: shownBounds.height
- }
const target = resolveWindowGeometry(shown.position, shown.size, parentBounds)
const fromOpacity = firstRender.current ? 0 : Number(getComputedStyle(preview).opacity)
firstRender.current = false
- gsap.killTweensOf(preview)
-
if (reducedMotion) {
- gsap.set(preview, { left: target.x, top: target.y, width: target.width, height: target.height, opacity: visible ? 1 : 0 })
+ setPreview(preview, target, visible ? 1 : 0)
setRendered(shown)
return
}
- const animation = gsap.fromTo(preview, {
- left: current.x,
- top: current.y,
- width: current.width,
- height: current.height,
- opacity: fromOpacity
- }, {
+ const animation = animate(preview, {
left: target.x,
top: target.y,
width: target.width,
height: target.height,
- opacity: visible ? 1 : 0,
+ opacity: [fromOpacity, visible ? 1 : 0]
+ }, {
duration: motionDuration(motionDurations.snap),
ease: motionEase([0.33, 1, 0.68, 1]),
- overwrite: "auto",
onComplete: () => setRendered(shown)
})
- return () => { animation.kill() }
+ return () => { animation.stop() }
}, [shown.position.x, shown.position.y, shown.size.width, shown.size.height, visible, reducedMotion])
@@ -85,6 +71,14 @@ export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, ra
</div>
}
+function setPreview(element: HTMLElement, region: ReturnType<typeof resolveWindowGeometry>, opacity: number) {
+ element.style.left = `${region.x}px`
+ element.style.top = `${region.y}px`
+ element.style.width = `${region.width}px`
+ element.style.height = `${region.height}px`
+ element.style.opacity = String(opacity)
+}
+
export interface SnapTarget {
position: Position
size: Size
diff --git a/source/client/view/structure/desktop/windows/window-header.tsx b/source/client/view/structure/desktop/windows/window-header.tsx
index cd0438b..30a8bbd 100644
--- a/source/client/view/structure/desktop/windows/window-header.tsx
+++ b/source/client/view/structure/desktop/windows/window-header.tsx
@@ -1,51 +1,14 @@
-import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useLayoutEffect, useRef, useState } from "react"
-import gsap, { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"
+import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode } from "react"
+import { motion } from "motion/react"
+import { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"
/** The visible chrome above an ordinary window's content. */
export default function WindowHeader({ title, icon, active, whole, reducedMotion, stopping, onGrab, onMinimize, onMaximize, onClose }: WindowHeaderProps) {
- const iconElement = useRef<HTMLImageElement>(null)
- const titleElement = useRef<HTMLSpanElement>(null)
- const [renderedActive, setRenderedActive] = useState(active)
-
- useLayoutEffect(function () {
-
- const icon = iconElement.current
- const title = titleElement.current
-
- if (!icon || !title || renderedActive === active) return
-
- const target = {
- opacity: active ? 1 : 0.6,
- color: active ? "#1e293b" : "#64748b"
- }
-
- gsap.killTweensOf([icon, title])
-
- if (reducedMotion) {
-
- gsap.set(icon, { opacity: target.opacity })
- gsap.set(title, { color: target.color })
- setRenderedActive(active)
-
- return
- }
-
- const timeline = gsap.timeline({
- defaults: {
- duration: motionDuration(motionDurations.feedback),
- ease: motionEase("ease-out"),
- overwrite: "auto"
- },
- onComplete: () => setRenderedActive(active)
- })
-
- timeline.to(icon, { opacity: target.opacity }, 0)
- timeline.to(title, { color: target.color }, 0)
-
- return () => { timeline.kill() }
-
- }, [active, reducedMotion, renderedActive])
+ const feedback = {
+ duration: reducedMotion ? 0 : motionDuration(motionDurations.feedback),
+ ease: motionEase("ease-out")
+ }
return <header
@@ -59,9 +22,7 @@ export default function WindowHeader({ title, icon, active, whole, reducedMotion
<div className="grid min-w-0 grid-cols-[auto_minmax(0,1fr)] items-center gap-3">
- <img
-
- ref={iconElement}
+ <motion.img
src={icon}
@@ -71,17 +32,22 @@ export default function WindowHeader({ title, icon, active, whole, reducedMotion
className="size-4 rounded-sm object-contain"
- style={{ opacity: renderedActive ? 1 : 0.6 }}
+ initial={false}
+
+ animate={{ opacity: active ? 1 : 0.6 }}
+
+ transition={feedback}
/>
{/* Focus is said on the chrome and nowhere else. Content stays
equally legible when another window owns the keyboard. */}
- <span
- ref={titleElement}
+ <motion.span
className="truncate text-window-title font-medium"
- style={{ color: renderedActive ? "#1e293b" : "#64748b" }}
- >{title}</span>
+ initial={false}
+ animate={{ color: active ? "#1e293b" : "#64748b" }}
+ transition={feedback}
+ >{title}</motion.span>
</div>
@@ -119,9 +85,6 @@ export default function WindowHeader({ title, icon, active, whole, reducedMotion
// assistive technology still use the button's native click activation.
function Control({ label, danger = false, focusOnPointerDown = true, reducedMotion, children, onClick, ...props }: ControlProps) {
- const element = useRef<HTMLButtonElement>(null)
- const hovering = useRef(false)
-
const base = { borderColor: "transparent", backgroundColor: "rgba(255, 255, 255, 0.15)", color: "#475569", scale: 1 }
const hover = danger
@@ -132,42 +95,23 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMoti
const pressed = { ...hover, backgroundColor: danger ? "#e11d48" : "rgba(255, 255, 255, 0.8)", scale: 0.95 }
- function react(values: typeof base) {
-
- const button = element.current
-
- if (!button) return
-
- gsap.killTweensOf(button)
-
- if (reducedMotion) gsap.set(button, values)
-
- else gsap.to(button, {
- ...values,
- duration: motionDuration(motionDurations.control),
- ease: motionEase("ease-out"),
- overwrite: "auto"
- })
- }
-
- return <button
+ return <motion.button
{...props}
- ref={element}
-
aria-label={label}
- onPointerEnter={() => {
+ initial={false}
- hovering.current = true
- react(hover)
- }}
+ animate={base}
- onPointerLeave={() => {
+ whileHover={hover}
- hovering.current = false
- react(base)
+ whileTap={pressed}
+
+ transition={{
+ duration: reducedMotion ? 0 : motionDuration(motionDurations.control),
+ ease: motionEase("ease-out")
}}
onPointerDown={event => {
@@ -176,8 +120,6 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMoti
if (event.button !== 0) return
- react(pressed)
-
if (focusOnPointerDown) event.currentTarget.focus({ preventScroll: true })
// Minimise and close act without focusing their window. Preventing
@@ -187,20 +129,6 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMoti
onClick?.()
}}
- onPointerUp={() => react(hovering.current ? hover : base)}
-
- onPointerCancel={() => react(hovering.current ? hover : base)}
-
- onKeyDown={event => {
-
- if (event.key === "Enter" || event.key === " ") react(pressed)
- }}
-
- onKeyUp={event => {
-
- if (event.key === "Enter" || event.key === " ") react(hovering.current ? hover : base)
- }}
-
onClick={event => {
event.stopPropagation()
@@ -218,7 +146,7 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMoti
</svg>
- </button>
+ </motion.button>
}
interface WindowHeaderProps {
@@ -244,10 +172,12 @@ interface WindowHeaderProps {
onClose?: () => void
}
-interface ControlProps extends Omit<ComponentProps<"button">, "onClick"> {
+interface ControlProps extends Omit<ComponentProps<typeof motion.button>, "children" | "onClick"> {
label: string
+ children: ReactNode
+
danger?: boolean
focusOnPointerDown?: boolean
diff --git a/source/client/view/structure/desktop/windows/window-surface.tsx b/source/client/view/structure/desktop/windows/window-surface.tsx
index 74b538c..9152e02 100644
--- a/source/client/view/structure/desktop/windows/window-surface.tsx
+++ b/source/client/view/structure/desktop/windows/window-surface.tsx
@@ -1,8 +1,9 @@
import { useReducedMotion } from "@libs/react-motion"
import { Surface } from "@phreshos/react-ui"
import { useLayoutEffect, useRef } from "react"
+import { animate } from "motion"
import { type LocalSurfaceState } from "../../../components/desktop-host/local-window"
-import gsap, { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"
+import { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"
const paintSelector = "[data-surface-backdrop], [data-surface-border], [data-surface-material]"
@@ -27,7 +28,7 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)
if (!surface) return
- const layers = [...surface.querySelectorAll(paintSelector)]
+ const layers = [...surface.querySelectorAll<HTMLElement>(paintSelector)]
for (const layer of layers) {
@@ -36,8 +37,6 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)
const revision = transition?.revision ?? null
- const changed = revision !== null
-
const initial = firstRender.current
firstRender.current = false
@@ -46,33 +45,34 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)
const duration = transaction?.duration ?? motionDurations.presence
- gsap.killTweensOf(layers)
-
- if (!transaction || !changed || reducedMotion || duration === 0) {
+ if (!transaction || revision === null || reducedMotion || duration === 0) {
- for (const layer of layers) gsap.set(layer, { opacity: visible ? visibleOpacity.current.get(layer) : 0 })
+ for (const layer of layers) layer.style.opacity = String(visible ? visibleOpacity.current.get(layer) : 0)
- if (transaction && changed) onComplete(revision!)
+ if (transaction && revision !== null) onComplete(revision)
return
}
- const animation = gsap.timeline({
- onComplete: () => onComplete(revision!)
- })
-
- for (const layer of layers) animation.fromTo(layer, {
- opacity: initial && visible ? 0 : Number(getComputedStyle(layer).opacity)
+ const animations = layers.map(layer => animate(layer, {
+ opacity: [
+ initial && visible ? 0 : Number(getComputedStyle(layer).opacity),
+ visible ? visibleOpacity.current.get(layer) ?? 1 : 0
+ ]
}, {
- opacity: visible ? visibleOpacity.current.get(layer) : 0,
duration: motionDuration(duration),
- ease: motionEase(transaction.easing),
- overwrite: "auto"
- }, 0)
+ ease: motionEase(transaction.easing)
+ }))
- return function () {
+ let active = true
+
+ void Promise.all(animations).then(() => {
+ if (active) onComplete(revision)
+ })
- animation.kill()
+ return function () {
+ active = false
+ for (const animation of animations) animation.stop()
}
}, [reducedMotion, transition?.revision, visible])
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index cf70ccf..b6bd93a 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -8,14 +8,15 @@ import WindowHeader from "./window-header"
import WindowSurface from "./window-surface"
import { type LocalAnimation, type LocalSurfaceState } from "../../../components/desktop-host/local-window"
import { type LocalGeometryReader } from "../../../components/window-manager/local-windows"
-import gsap, { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"
+import { animate, type AnimationPlaybackControlsWithThen } from "motion"
+import { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"
import SnapPreview, { type SnapTarget } from "./snap-preview"
import { windowPaintInset } from "../geometry"
/**
* A window: a pure function of the record it is given. Every render
* declares the whole target geometry from props — a float as left/top
- * pixels, a tile as its relative form. GSAP interpolates only the local
+ * pixels, a tile as its relative form. Motion interpolates only the local
* representation between targets; the record remains the truth and a
* refreshed page renders that truth directly.
*
@@ -27,7 +28,7 @@ import { windowPaintInset } from "../geometry"
* onSnap with the shares a zone names) and drops the gesture in the same
* batch the record updates, so nothing jumps.
*
- * GSAP owns every structural interpolation: frame geometry, local Surface
+ * Motion owns every structural interpolation: frame geometry, local Surface
* replacement, and the scale and drift of presence. It never owns state.
*
* The chrome uses the shared system material and content sits on an inset
@@ -52,6 +53,10 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
const surfaceElement = useRef<HTMLDivElement>(null)
+ const geometryMotion = useRef<AnimationPlaybackControlsWithThen | null>(null)
+
+ const entranceMotion = useRef<AnimationPlaybackControlsWithThen | null>(null)
+
const reducedMotion = useReducedMotion()
const appearance = useAppearance()
@@ -129,7 +134,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
const transaction = geometryAnimation?.transaction
const duration = transaction?.duration ?? motionDurations.geometry
- gsap.killTweensOf(element)
+ geometryMotion.current?.stop()
const complete = function () {
@@ -140,7 +145,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
if (bare || reducedMotion || duration === 0 || sameRegion(current, target)) {
- gsap.set(element, { left: target.x, top: target.y, width: target.width, height: target.height, transform: "none" })
+ setRegion(element, target)
complete()
return
@@ -149,48 +154,39 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
// Lay out the authoritative target once, then animate only the visual
// difference. Reflowing an iframe-sized box on every animation frame
// causes the small hitch this transition is meant to hide.
- gsap.set(element, {
- left: target.x,
- top: target.y,
- width: target.width,
- height: target.height,
- transformOrigin: "0 0"
- })
-
- const animation = gsap.fromTo(element, {
- x: current.x - target.x,
- y: current.y - target.y,
- scaleX: current.width / target.width,
- scaleY: current.height / target.height
+ setRegion(element, target)
+ element.style.transformOrigin = "0 0"
+
+ const animation = animate(element, {
+ x: [current.x - target.x, 0],
+ y: [current.y - target.y, 0],
+ scaleX: [current.width / target.width, 1],
+ scaleY: [current.height / target.height, 1]
}, {
- x: 0,
- y: 0,
- scaleX: 1,
- scaleY: 1,
duration: motionDuration(duration),
ease: transaction ? motionEase(transaction.easing) : motionEase([0.33, 1, 0.68, 1]),
- force3D: true,
- overwrite: "auto",
onComplete: function () {
-
- gsap.set(element, { transform: "none", transformOrigin: "" })
+ element.style.transform = "none"
+ element.style.transformOrigin = ""
+ geometryMotion.current = null
complete()
}
})
+ geometryMotion.current = animation
+
return function () {
const held = element.getBoundingClientRect()
const bounds = parent.getBoundingClientRect()
- animation.kill()
-
- gsap.set(element, {
- left: held.left - bounds.left,
- top: held.top - bounds.top,
+ animation.stop()
+ if (geometryMotion.current === animation) geometryMotion.current = null
+ setRegion(element, {
+ x: held.left - bounds.left,
+ y: held.top - bounds.top,
width: held.width,
- height: held.height,
- transform: "none"
+ height: held.height
})
}
@@ -203,22 +199,17 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
if (!element || !from || gesture?.morph == null || reducedMotion) return
- const animation = gsap.fromTo(element, {
- left: from.x,
- top: from.y,
- width: from.width,
- height: from.height
+ const animation = animate(element, {
+ left: [from.x, gesture.origin.x],
+ top: [from.y, gesture.origin.y],
+ width: [from.width, gesture.current.width],
+ height: [from.height, gesture.current.height]
}, {
- left: gesture.origin.x,
- top: gesture.origin.y,
- width: gesture.current.width,
- height: gesture.current.height,
duration: motionDuration(motionDurations.morph),
- ease: motionEase([0.33, 1, 0.68, 1]),
- overwrite: "auto"
+ ease: motionEase([0.33, 1, 0.68, 1])
})
- return () => { animation.kill() }
+ return () => { animation.stop() }
}, [gesture?.morph, reducedMotion])
@@ -231,25 +222,21 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
const property = active ? "--shadow-window-active" : "--shadow-window-inactive"
const target = getComputedStyle(element).getPropertyValue(property).trim() || "none"
- gsap.killTweensOf(element, "boxShadow")
-
if (reducedMotion) {
- gsap.set(element, { boxShadow: target })
+ element.style.boxShadow = target
setRenderedActive(active)
return
}
- const animation = gsap.to(element, {
- boxShadow: target,
+ const animation = animate(element, { boxShadow: target }, {
duration: motionDuration(motionDurations.feedback),
ease: motionEase("ease-out"),
- overwrite: "auto",
onComplete: () => setRenderedActive(active)
})
- return () => { animation.kill() }
+ return () => { animation.stop() }
}, [active, reducedMotion, renderedActive])
@@ -290,7 +277,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
if (minimized) {
- gsap.set(surfaceElement.current, { scale: reducedMotion ? 1 : 0.86, y: reducedMotion ? 0 : 28, visibility: "hidden" })
+ setSurface(surfaceElement.current, reducedMotion ? 1 : 0.86, reducedMotion ? 0 : 28, "hidden")
return
}
@@ -299,18 +286,23 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
restSurface(surfaceElement.current)
- gsap.set(surfaceElement.current, { visibility: "visible" })
+ setVisibility(surfaceElement.current, "visible")
return
}
prepareSurfaceEntrance(surfaceElement.current, reducedMotion)
- gsap.set(surfaceElement.current, { visibility: "visible" })
+ setVisibility(surfaceElement.current, "visible")
const animation = enterSurface(surfaceElement.current, reducedMotion)
- return () => { animation?.kill() }
+ entranceMotion.current = animation
+
+ return () => {
+ animation?.stop()
+ if (entranceMotion.current === animation) entranceMotion.current = null
+ }
// Presence at birth reads the mount's own values once.
}, [])
@@ -326,14 +318,15 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
// restore will animate from if the preference has been relaxed.
if (!reducedMotion) {
- if (minimized) gsap.set(surfaceElement.current, { scale: 0.86, y: 28, visibility: "hidden" })
+ if (minimized) setSurface(surfaceElement.current, 0.86, 28, "hidden")
return
}
- gsap.killTweensOf(surfaceElement.current)
+ entranceMotion.current?.stop()
+ entranceMotion.current = null
- gsap.set(surfaceElement.current, { scale: 1, y: 0, visibility: minimized || closing ? "hidden" : "visible" })
+ setSurface(surfaceElement.current, 1, 0, minimized || closing ? "hidden" : "visible")
if (closing) {
@@ -368,7 +361,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
// would be motion toward nowhere.
if (bare || reducedMotion) {
- gsap.set(surfaceElement.current, { scale: 1, y: 0, visibility: minimized ? "hidden" : "visible" })
+ setSurface(surfaceElement.current, 1, 0, minimized ? "hidden" : "visible")
return
}
@@ -376,17 +369,17 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
// Presence is scale and drift, never opacity, so the material and its
// content remain visually stable throughout the movement. Going away
// is a departure toward the taskbar; hiding happens only at the end.
- if (!minimized) gsap.set(surfaceElement.current, { visibility: "visible" })
+ if (!minimized) setVisibility(surfaceElement.current, "visible")
const animation = minimized
- ? gsap.to(surfaceElement.current, { scale: 0.86, y: 28, duration: motionDuration(motionDurations.minimize), ease: "power3.in", overwrite: "auto", onComplete: () => gsap.set(surfaceElement.current, { visibility: "hidden" }) })
+ ? animate(surfaceElement.current, { scale: 0.86, y: 28 }, { duration: motionDuration(motionDurations.minimize), ease: motionEase("ease-in"), onComplete: () => setVisibility(surfaceElement.current, "hidden") })
- : gsap.to(surfaceElement.current, { scale: 1, y: 0, duration: motionDuration(motionDurations.restore), ease: "power3.out", overwrite: "auto" })
+ : animate(surfaceElement.current, { scale: 1, y: 0 }, { duration: motionDuration(motionDurations.restore), ease: motionEase("ease-out") })
- return () => { animation.kill() }
+ return () => { animation.stop() }
- }, [minimized])
+ }, [minimized, bare, reducedMotion])
// Closing is a handshake: the exit plays, onClosed reports the
// element may be unmounted.
@@ -406,18 +399,15 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
return
}
- const animation = gsap.to(surfaceElement.current, {
- scale: 0.86,
- y: 12,
+ const animation = animate(surfaceElement.current, { scale: 0.86, y: 12 }, {
duration: motionDuration(motionDurations.close),
- ease: "power2.in",
- overwrite: "auto",
+ ease: motionEase("ease-in"),
onComplete: completeClosure
})
- return () => { animation.kill() }
+ return () => { animation.stop() }
- }, [closing])
+ }, [closing, bare, reducedMotion])
function grab(event: ReactPointerEvent<HTMLElement>, edge: WindowEdge | null) {
@@ -444,9 +434,9 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
let current: WindowRegion = { ...origin }
- gsap.killTweensOf(frame.current)
-
- gsap.set(frame.current, { left: origin.x, top: origin.y, width: origin.width, height: origin.height, transform: "none" })
+ geometryMotion.current?.stop()
+ geometryMotion.current = null
+ setRegion(frame.current, origin)
setRenderedGeometry({
position: { x: origin.x, y: origin.y },
@@ -672,7 +662,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,
// The geometry, declared whole every render: the gesture's rectangle
// while one runs — movement as a transform above the grabbed origin,
- // otherwise the last settled representation. GSAP moves that stable
+ // otherwise the last settled representation. Motion moves that stable
// representation to each new authoritative target.
const geometry = gesture
@@ -906,6 +896,25 @@ interface Gesture {
morph: number | null
}
+function setRegion(element: HTMLElement, region: WindowRegion) {
+ element.style.left = `${region.x}px`
+ element.style.top = `${region.y}px`
+ element.style.width = `${region.width}px`
+ element.style.height = `${region.height}px`
+ element.style.transform = "none"
+ element.style.transformOrigin = ""
+}
+
+function setSurface(element: HTMLElement | null, scale: number, y: number, visibility: "hidden" | "visible") {
+ if (!element) return
+ element.style.transform = scale === 1 && y === 0 ? "" : `translateY(${y}px) scale(${scale})`
+ element.style.visibility = visibility
+}
+
+function setVisibility(element: HTMLElement | null, visibility: "hidden" | "visible") {
+ if (element) element.style.visibility = visibility
+}
+
function sameGeometry(left: WindowGeometry, right: WindowGeometry) {
return left.position.x === right.position.x
diff --git a/source/libs/react-motion.ts b/source/libs/react-motion.ts
new file mode 100644
index 0000000..d2cffb3
--- /dev/null
+++ b/source/libs/react-motion.ts
@@ -0,0 +1,6 @@
+import { useReducedMotionConfig } from "motion/react"
+
+/** Returns the effective Motion policy selected at the desktop root. */
+export function useReducedMotion() {
+ return useReducedMotionConfig() ?? false
+}
diff --git a/source/libs/react-motion.tsx b/source/libs/react-motion.tsx
deleted file mode 100644
index cc9d897..0000000
--- a/source/libs/react-motion.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import { ReactNode, createContext, useContext, useSyncExternalStore } from "react"
-
-const ReducedMotionContext = createContext(false)
-
-const media = "(prefers-reduced-motion: reduce)"
-
-let preference: MediaQueryList | null = null
-
-/** Provides the operating-system motion preference with an optional override. */
-export default function ReducedMotion({ children, reduced }: ReducedMotionProps) {
-
- const preferred = useSyncExternalStore(subscribe, snapshot, () => false)
-
- return <ReducedMotionContext.Provider value={reduced ?? preferred}>{children}</ReducedMotionContext.Provider>
-}
-
-export function useReducedMotion() {
-
- return useContext(ReducedMotionContext)
-}
-
-function subscribe(change: () => void) {
-
- const query = motionPreference()
-
- query?.addEventListener("change", change)
-
- return () => query?.removeEventListener("change", change)
-}
-
-function snapshot() {
-
- return motionPreference()?.matches ?? false
-}
-
-function motionPreference() {
-
- if (typeof window === "undefined" || !window.matchMedia) return null
-
- preference ??= window.matchMedia(media)
-
- return preference
-}
-
-interface ReducedMotionProps {
-
- children: ReactNode
-
- /** A deterministic environment may override the operating-system preference. */
- reduced?: boolean
-}