An open-source, self-hosted system for apps built with web technologies.
Restore GSAP desktop motion
zohayrslilehafad95c1fd4b
diff --git a/bun.lock b/bun.lockindex b95b560..5cf9271 100644--- a/bun.lock+++ b/bun.lock@@ -10,9 +10,9 @@"@msgpack/msgpack": "^3.1.3","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-dom": "^19.2.8",@@ -356,8 +356,6 @@"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=="],@@ -368,6 +366,8 @@"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=="],@@ -424,12 +424,6 @@"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.jsonindex 1f6cbf2..8e8a9d7 100644--- a/package.json+++ b/package.json@@ -40,9 +40,9 @@"@msgpack/msgpack": "^3.1.3","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-dom": "^19.2.8",diff --git a/source/client/view/appearance/appearance.tsx b/source/client/view/appearance/appearance.tsxindex 3050145..7b829f9 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 { MotionConfig } from "motion/react"+import ReducedMotion from "@libs/react-motion"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 <MotionConfig reducedMotion={preferences.animations ? "never" : "always"}>+ return <ReducedMotion reduced={!preferences.animations}><div className="relative isolate grid h-dvh overflow-hidden font-roboto" style={{ backgroundColor: background }}>@@ -25,5 +25,5 @@ function AppearanceRoot({ children }: PropsWithChildren) {</div>- </MotionConfig>+ </ReducedMotion>}diff --git a/source/client/view/appearance/motion.ts b/source/client/view/appearance/motion.tsindex 21d5adf..c0df95c 100644--- a/source/client/view/appearance/motion.ts+++ b/source/client/view/appearance/motion.ts@@ -1,36 +1,51 @@-import { type Easing as SystemEasing } from "@phreshos/core"-import { type Easing } from "motion"+import { type Easing } from "@phreshos/core"+import gsap from "gsap"+import { CustomEase } from "gsap/CustomEase"-const curves: Record<Exclude<SystemEasing, readonly number[]>, Easing> = {- linear: "linear",+gsap.registerPlugin(CustomEase)++const curves: Record<Exclude<Easing, readonly number[]>, readonly [number, number, number, number]> = {+ linear: [0, 0, 1, 1],ease: [0.25, 0.1, 0.25, 1],- "ease-in": "easeIn",- "ease-out": "easeOut",- "ease-in-out": "easeInOut"+ "ease-in": [0.42, 0, 1, 1],+ "ease-out": [0, 0, 0.58, 1],+ "ease-in-out": [0.42, 0, 0.58, 1]}+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,minimize: 110,- dismiss: 140,close: 160,snap: 180,- presence: 180,feedback: 200,morph: 220,+ presence: 240,restore: 240,geometry: 300})-/** Converts a public CSS timing curve into Motion's equivalent easing. */-export function motionEase(value: SystemEasing | undefined, fallback: SystemEasing = "ease-out"): Easing {+/** Preserves public CSS timing curves while GSAP owns their interpolation. */+export function motionEase(value: Easing | undefined, fallback: Easing = "ease-out") {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- return typeof selected === "string" ? curves[selected] : selected+ const easing = CustomEase.create(`phresh-${registered.size}`, key)++ registered.set(key, easing)++ return easing}+export default gsap+export function motionDuration(milliseconds: number) {return milliseconds / 1_000diff --git a/source/client/view/appearance/surface-presence.ts b/source/client/view/appearance/surface-presence.tsindex 3d33bf5..505875b 100644--- a/source/client/view/appearance/surface-presence.ts+++ b/source/client/view/appearance/surface-presence.ts@@ -1,21 +1,17 @@-import { animate, motionValue, styleEffect, type AnimationPlaybackControlsWithThen, type MotionValue, type ValueAnimationTransition } from "motion"-import { motionDuration, motionDurations, motionEase } from "./motion"+import gsap, { motionDuration, motionDurations } from "./motion"-const entered = "translateY(0px) scale(1)"+const entered = { scale: 1, y: 0 }-const entering = "translateY(8px) scale(0.96)"--const resting = "none"--const motions = new WeakMap<HTMLElement, SurfaceMotion>()+const entering = { scale: 0.96, y: 8 }/** Establish the first frame before a surface becomes visible. */export function prepareSurfaceEntrance(surface: HTMLElement | null, reducedMotion: boolean) {if (!surface) return- stop(surface)- set(surface, reducedMotion ? resting : entering)+ gsap.killTweensOf(surface)++ gsap.set(surface, reducedMotion ? entered : entering)}/** Give every system surface the same entrance motion. */@@ -23,37 +19,20 @@ export function enterSurface(surface: HTMLElement | null, reducedMotion: booleanif (!surface) return null- stop(surface)+ gsap.killTweensOf(surface)if (reducedMotion) {- set(surface, resting)+ gsap.set(surface, entered)return null}- return animateSurfaceTransform(surface, 1, 0, {+ return gsap.to(surface, {+ ...entered,duration: motionDuration(motionDurations.presence),- ease: motionEase([0.33, 1, 0.68, 1])- })-}--/** Let a dismissible surface leave before its host removes it from paint. */-export function exitSurface(surface: HTMLElement | null, reducedMotion: boolean) {-- if (!surface) return null-- if (reducedMotion) {-- restSurface(surface)-- return null- }-- return animateSurfaceTransform(surface, 0.96, 8, {- duration: motionDuration(motionDurations.dismiss),- ease: motionEase("ease-in"),- onComplete: () => restSurface(surface)+ ease: "power3.out",+ overwrite: "auto"})}@@ -62,82 +41,7 @@ export function restSurface(surface: HTMLElement | null) {if (!surface) return- stop(surface)- set(surface, resting)-}--/** Set a surface pose through the same transform owner used by its motion. */-export function setSurfaceTransform(surface: HTMLElement | null, scale: number, y: number) {-- if (!surface) return-- stop(surface)- set(surface, surfaceTransform(scale, y))-}--/** Move a surface without creating a second transform owner on its element. */-export function animateSurfaceTransform(surface: HTMLElement | null, scale: number, y: number, options: ValueAnimationTransition<string>) {-- if (!surface) return null-- stop(surface)-- const values = motion(surface)- const target = surfaceTransform(scale, y)- const { onComplete, ...transition } = options-- // `none` and a composed transform look identical at rest but are not- // compatible complex values. Keep the identity representation while a- // transition runs, then normalize it back to `none` when it settles.- if (values.transform.get() === resting) values.transform.jump(entered)-- const animation = animate(values.transform, target === resting ? entered : target, {- ...transition,- onComplete: function () {- values.transform.set(target)- values.animation = null- onComplete?.()- }- })-- values.animation = animation-- return animation-}--function stop(surface: HTMLElement) {- const values = motions.get(surface)- values?.animation?.stop()- if (values) values.animation = null-}--function set(surface: HTMLElement, target: string) {- const values = motion(surface)- values.transform.jump(target)-}--function motion(surface: HTMLElement) {- const existing = motions.get(surface)-- if (existing) return existing-- const transform = motionValue(resting)- const values: SurfaceMotion = {- transform,- animation: null- }-- styleEffect(surface, { transform })- motions.set(surface, values)-- return values-}--function surfaceTransform(scale: number, y: number) {- return scale === 1 && y === 0 ? resting : `translateY(${y}px) scale(${scale})`-}+ gsap.killTweensOf(surface)-interface SurfaceMotion {- transform: MotionValue<string>- animation: AnimationPlaybackControlsWithThen | null+ gsap.set(surface, entered)}diff --git a/source/client/view/structure/authentication/credentials-form.tsx b/source/client/view/structure/authentication/credentials-form.tsxindex a687618..d7dbf64 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, passwreturn () => {- entrance?.stop()+ entrance?.kill()restSurface(surface.current)}diff --git a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsxindex c0d36a0..fc00b1c 100644--- a/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx+++ b/source/client/view/structure/desktop/taskbar/launcher/launcher.tsx@@ -1,6 +1,5 @@import { ComponentProps, ReactNode, useCallback, useEffect, useId, useRef, useState } from "react"-import { enterSurface, exitSurface, prepareSurfaceEntrance } from "../../../../appearance/surface-presence"-import { motionDurations } from "../../../../appearance/motion"+import { enterSurface, prepareSurfaceEntrance, restSurface } from "../../../../appearance/surface-presence"import { useReducedMotion } from "@libs/react-motion"import { useAppearance, useResolveTheme, useScale } from "@phreshos/react-ui"import TaskbarSurface, { taskbarSurfaceClassName } from "../taskbar-surface"@@ -87,21 +86,13 @@ export default function ({ label, trigger, children, className, style, ...propstabIndex={-1}- style={{- ...style,- borderRadius: radius,- transitionBehavior: "allow-discrete",- transitionDuration: reducedMotion ? "0s" : `${motionDurations.dismiss}ms`,- transitionProperty: "display, overlay"- }}+ style={{ ...style, borderRadius: radius }}className={`${taskbarSurfaceClassName} hidden open:block ${className ?? ""}`}onBeforeToggle={event => {if (event.newState === "open") prepareSurfaceEntrance(event.currentTarget, reducedMotion)-- else exitSurface(event.currentTarget, reducedMotion)}}onToggle={event => {@@ -119,6 +110,8 @@ export default function ({ label, trigger, children, className, style, ...propsfocusTarget.focus()}+ else restSurface(event.currentTarget)+}}>diff --git a/source/client/view/structure/desktop/windows/snap-preview.tsx b/source/client/view/structure/desktop/windows/snap-preview.tsxindex 013f118..3ebd894 100644--- a/source/client/view/structure/desktop/windows/snap-preview.tsx+++ b/source/client/view/structure/desktop/windows/snap-preview.tsx@@ -1,17 +1,16 @@-import { type CSSProperties, useLayoutEffect, useRef } from "react"-import { animate } from "motion"-import { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"+import { type CSSProperties, useLayoutEffect, useRef, useState } from "react"+import gsap, { 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"-/** Animated preview of the placement currently offered by a drag. */+/** GSAP-owned 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)const firstRender = useRef(true)- const initial = useRef(shown)+ const [rendered, setRendered] = useState(shown)useLayoutEffect(function () {@@ -21,37 +20,47 @@ export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, raif (!preview || !parent) returnconst parentBounds = parent.getBoundingClientRect()- const currentBounds = preview.getBoundingClientRect()+ const shownBounds = preview.getBoundingClientRect()const current = {- x: currentBounds.left - parentBounds.left,- y: currentBounds.top - parentBounds.top,- width: currentBounds.width,- height: currentBounds.height+ 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) {- setPreview(preview, target, visible ? 1 : 0)+ gsap.set(preview, { left: target.x, top: target.y, width: target.width, height: target.height, opacity: visible ? 1 : 0 })+ setRendered(shown)return}- const animation = animate(preview, {- left: [current.x, target.x],- top: [current.y, target.y],- width: [current.width, target.width],- height: [current.height, target.height],- opacity: [fromOpacity, visible ? 1 : 0]+ const animation = gsap.fromTo(preview, {+ left: current.x,+ top: current.y,+ width: current.width,+ height: current.height,+ opacity: fromOpacity}, {+ left: target.x,+ top: target.y,+ width: target.width,+ height: target.height,+ opacity: visible ? 1 : 0,duration: motionDuration(motionDurations.snap),- ease: motionEase([0.33, 1, 0.68, 1])+ ease: motionEase([0.33, 1, 0.68, 1]),+ overwrite: "auto",+ onComplete: () => setRendered(shown)})- return () => { animation.stop() }+ return () => { animation.kill() }}, [shown.position.x, shown.position.y, shown.size.width, shown.size.height, visible, reducedMotion])@@ -59,11 +68,11 @@ export default function SnapPreview({ shown, visible, bare, paintSurfaceSize, raref={element}className="pointer-events-none absolute"style={{- left: resolveWindowValue(initial.current.position.x),- top: resolveWindowValue(initial.current.position.y),- width: resolveWindowValue(initial.current.size.width),- height: resolveWindowValue(initial.current.size.height),- opacity: 0,+ left: resolveWindowValue(rendered.position.x),+ top: resolveWindowValue(rendered.position.y),+ width: resolveWindowValue(rendered.size.width),+ height: resolveWindowValue(rendered.size.height),+ opacity: visible ? 1 : 0,zIndex}}>@@ -76,14 +85,6 @@ 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: Positionsize: Sizediff --git a/source/client/view/structure/desktop/windows/window-header.tsx b/source/client/view/structure/desktop/windows/window-header.tsxindex 30a8bbd..b19c9d4 100644--- a/source/client/view/structure/desktop/windows/window-header.tsx+++ b/source/client/view/structure/desktop/windows/window-header.tsx@@ -1,14 +1,59 @@-import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode } from "react"-import { motion } from "motion/react"-import { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"+import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useLayoutEffect, useRef, useState } from "react"+import gsap, { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"++const control = {+ base: { borderColor: "transparent", backgroundColor: "rgba(255, 255, 255, 0.15)", color: "#475569", scale: 1 },+ hover: { borderColor: "rgba(255, 255, 255, 0.7)", backgroundColor: "rgba(255, 255, 255, 0.65)", color: "#0f172a", scale: 1 },+ danger: { borderColor: "rgba(253, 164, 175, 0.7)", backgroundColor: "#f43f5e", color: "#ffffff", scale: 1 }+}++const focus = {+ active: { opacity: 1, color: "#1e293b" },+ inactive: { opacity: 0.6, color: "#64748b" }+}/** 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 feedback = {- duration: reducedMotion ? 0 : motionDuration(motionDurations.feedback),- ease: motionEase("ease-out")- }+ 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 = active ? focus.active : focus.inactive++ 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])return <header@@ -22,7 +67,9 @@ 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">- <motion.img+ <img++ ref={iconElement}src={icon}@@ -32,22 +79,17 @@ export default function WindowHeader({ title, icon, active, whole, reducedMotionclassName="size-4 rounded-sm object-contain"- initial={false}-- animate={{ opacity: active ? 1 : 0.6 }}-- transition={feedback}+ style={{ opacity: renderedActive ? 1 : 0.6 }}/>{/* Focus is said on the chrome and nowhere else. Content staysequally legible when another window owns the keyboard. */}- <motion.span+ <span+ ref={titleElement}className="truncate text-window-title font-medium"- initial={false}- animate={{ color: active ? "#1e293b" : "#64748b" }}- transition={feedback}- >{title}</motion.span>+ style={{ color: renderedActive ? "#1e293b" : "#64748b" }}+ >{title}</span></div>@@ -85,33 +127,53 @@ 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 base = { borderColor: "transparent", backgroundColor: "rgba(255, 255, 255, 0.15)", color: "#475569", scale: 1 }+ const element = useRef<HTMLButtonElement>(null)+ const hovering = useRef(false)- const hover = danger+ const hover = danger ? control.danger : control.hover- ? { borderColor: "rgba(253, 164, 175, 0.7)", backgroundColor: "#f43f5e", color: "#ffffff", scale: 1 }+ const pressed = {+ ...hover,+ backgroundColor: danger ? "#e11d48" : "rgba(255, 255, 255, 0.8)",+ scale: 0.95+ }++ function react(values: typeof control.base) {++ const button = element.current++ if (!button) return++ gsap.killTweensOf(button)- : { borderColor: "rgba(255, 255, 255, 0.7)", backgroundColor: "rgba(255, 255, 255, 0.65)", color: "#0f172a", scale: 1 }+ if (reducedMotion) gsap.set(button, values)- const pressed = { ...hover, backgroundColor: danger ? "#e11d48" : "rgba(255, 255, 255, 0.8)", scale: 0.95 }+ else gsap.to(button, {+ ...values,+ duration: motionDuration(motionDurations.control),+ ease: motionEase("ease-out"),+ overwrite: "auto"+ })+ }- return <motion.button+ return <button{...props}- aria-label={label}+ ref={element}- initial={false}+ aria-label={label}- animate={base}+ onPointerEnter={() => {- whileHover={hover}+ hovering.current = true+ react(hover)+ }}- whileTap={pressed}+ onPointerLeave={() => {- transition={{- duration: reducedMotion ? 0 : motionDuration(motionDurations.control),- ease: motionEase("ease-out")+ hovering.current = false+ react(control.base)}}onPointerDown={event => {@@ -120,6 +182,8 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMotiif (event.button !== 0) return+ react(pressed)+if (focusOnPointerDown) event.currentTarget.focus({ preventScroll: true })// Minimise and close act without focusing their window. Preventing@@ -129,6 +193,20 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMotionClick?.()}}+ onPointerUp={() => react(hovering.current ? hover : control.base)}++ onPointerCancel={() => react(hovering.current ? hover : control.base)}++ onKeyDown={event => {++ if (event.key === "Enter" || event.key === " ") react(pressed)+ }}++ onKeyUp={event => {++ if (event.key === "Enter" || event.key === " ") react(hovering.current ? hover : control.base)+ }}+onClick={event => {event.stopPropagation()@@ -146,7 +224,7 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMoti</svg>- </motion.button>+ </button>}interface WindowHeaderProps {@@ -172,12 +250,10 @@ interface WindowHeaderProps {onClose?: () => void}-interface ControlProps extends Omit<ComponentProps<typeof motion.button>, "children" | "onClick"> {+interface ControlProps extends Omit<ComponentProps<"button">, "onClick"> {label: string- children: ReactNode-danger?: booleanfocusOnPointerDown?: booleandiff --git a/source/client/view/structure/desktop/windows/window-surface.tsx b/source/client/view/structure/desktop/windows/window-surface.tsxindex 9152e02..74b538c 100644--- a/source/client/view/structure/desktop/windows/window-surface.tsx+++ b/source/client/view/structure/desktop/windows/window-surface.tsx@@ -1,9 +1,8 @@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 { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"+import gsap, { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"const paintSelector = "[data-surface-backdrop], [data-surface-border], [data-surface-material]"@@ -28,7 +27,7 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)if (!surface) return- const layers = [...surface.querySelectorAll<HTMLElement>(paintSelector)]+ const layers = [...surface.querySelectorAll(paintSelector)]for (const layer of layers) {@@ -37,6 +36,8 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)const revision = transition?.revision ?? null+ const changed = revision !== null+const initial = firstRender.currentfirstRender.current = false@@ -45,34 +46,33 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)const duration = transaction?.duration ?? motionDurations.presence- if (!transaction || revision === null || reducedMotion || duration === 0) {+ gsap.killTweensOf(layers)++ if (!transaction || !changed || reducedMotion || duration === 0) {- for (const layer of layers) layer.style.opacity = String(visible ? visibleOpacity.current.get(layer) : 0)+ for (const layer of layers) gsap.set(layer, { opacity: visible ? visibleOpacity.current.get(layer) : 0 })- if (transaction && revision !== null) onComplete(revision)+ if (transaction && changed) onComplete(revision!)return}- const animations = layers.map(layer => animate(layer, {- opacity: [- initial && visible ? 0 : Number(getComputedStyle(layer).opacity),- visible ? visibleOpacity.current.get(layer) ?? 1 : 0- ]+ const animation = gsap.timeline({+ onComplete: () => onComplete(revision!)+ })++ for (const layer of layers) animation.fromTo(layer, {+ opacity: initial && visible ? 0 : Number(getComputedStyle(layer).opacity)}, {+ opacity: visible ? visibleOpacity.current.get(layer) : 0,duration: motionDuration(duration),- ease: motionEase(transaction.easing)- }))-- let active = true-- void Promise.all(animations).then(() => {- if (active) onComplete(revision)- })+ ease: motionEase(transaction.easing),+ overwrite: "auto"+ }, 0)return function () {- active = false- for (const animation of animations) animation.stop()++ animation.kill()}}, [reducedMotion, transition?.revision, visible])diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsxindex 55bd54a..e6ef653 100644--- a/source/client/view/structure/desktop/windows/window.tsx+++ b/source/client/view/structure/desktop/windows/window.tsx@@ -1,6 +1,6 @@import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useLayoutEffect, useRef, useState } from "react"import { useReducedMotion } from "@libs/react-motion"-import { animateSurfaceTransform, enterSurface, prepareSurfaceEntrance, restSurface, setSurfaceTransform } from "../../../appearance/surface-presence"+import { enterSurface, prepareSurfaceEntrance, restSurface } from "../../../appearance/surface-presence"import { Surface, useAppearance, useResolveTheme, useScale } from "@phreshos/react-ui"import { absoluteWindowGeometry, resolveWindowGeometry, resolveWindowValue, wholeWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "../../../components/window-manager/window-geometry"import { type Position, type Size, type WindowGeometry } from "@phreshos/core"@@ -8,15 +8,14 @@ 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 { animate, type AnimationPlaybackControlsWithThen } from "motion"-import { motionDuration, motionDurations, motionEase } from "../../../appearance/motion"+import gsap, { 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. Motion interpolates only the local+ * pixels, a tile as its relative form. GSAP interpolates only the local* representation between targets; the record remains the truth and a* refreshed page renders that truth directly.*@@ -28,7 +27,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.*- * Motion owns every structural interpolation: frame geometry, local Surface+ * GSAP 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@@ -47,16 +46,18 @@ const edges: { edge: WindowEdge, className: string }[] = [{ edge: "se", className: "bottom-0 right-0 size-4 cursor-nwse-resize" }]+const surfacePose = {+ resting: { scale: 1, y: 0 },+ minimized: { scale: 0.86, y: 28 },+ closing: { scale: 0.86, y: 12 }+}+export default function ({ title, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onLocalAnimationComplete, onLocalRepresentation, onFocusCapture, active = false, bare = false, closing = false, stopping = false, minimized = false, animateEntrance = true, position = { x: 0, y: 0 }, size = { width: 520, height: 340 }, localSurface, geometryAnimation, paintSurfaceSize = { width: 0, height: 0 }, minWidth = 260, minHeight = 160, className, style, ...props }: WindowProps) {const frame = useRef<HTMLDivElement>(null)const surfaceElement = useRef<HTMLDivElement>(null)- const geometryMotion = useRef<AnimationPlaybackControlsWithThen | null>(null)-- const entranceMotion = useRef<AnimationPlaybackControlsWithThen | null>(null)-const reducedMotion = useReducedMotion()const appearance = useAppearance()@@ -134,7 +135,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,const transaction = geometryAnimation?.transactionconst duration = transaction?.duration ?? motionDurations.geometry- geometryMotion.current?.stop()+ gsap.killTweensOf(element)const complete = function () {@@ -145,7 +146,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,if (bare || reducedMotion || duration === 0 || sameRegion(current, target)) {- setRegion(element, target)+ gsap.set(element, { left: target.x, top: target.y, width: target.width, height: target.height, transform: "none" })complete()return@@ -154,48 +155,48 @@ 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.- setRegion(element, target)- element.style.transformOrigin = "0 0"-- // Motion resolves independent transform values after this layout- // effect. Seed and animate the composed transform itself so laying- // out the target can never expose it before the inverse is installed.- const inverse = windowTransform(- current.x - target.x,- current.y - target.y,- current.width / target.width,- current.height / target.height- )-- element.style.transform = inverse-- const animation = animate(element, {- transform: [inverse, windowTransform(0, 0, 1, 1)]+ 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}, {+ 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 () {- element.style.transform = "none"- element.style.transformOrigin = ""- geometryMotion.current = null++ gsap.set(element, { transform: "none", transformOrigin: "" })complete()}})- geometryMotion.current = animation-return function () {const held = element.getBoundingClientRect()const bounds = parent.getBoundingClientRect()- animation.stop()- if (geometryMotion.current === animation) geometryMotion.current = null- setRegion(element, {- x: held.left - bounds.left,- y: held.top - bounds.top,+ animation.kill()++ gsap.set(element, {+ left: held.left - bounds.left,+ top: held.top - bounds.top,width: held.width,- height: held.height+ height: held.height,+ transform: "none"})}@@ -208,17 +209,22 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,if (!element || !from || gesture?.morph == null || reducedMotion) return- 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]+ const animation = gsap.fromTo(element, {+ left: from.x,+ top: from.y,+ width: from.width,+ height: from.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])+ ease: motionEase([0.33, 1, 0.68, 1]),+ overwrite: "auto"})- return () => { animation.stop() }+ return () => { animation.kill() }}, [gesture?.morph, reducedMotion])@@ -231,21 +237,25 @@ 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) {- element.style.boxShadow = target+ gsap.set(element, { boxShadow: target })setRenderedActive(active)return}- const animation = animate(element, { boxShadow: target }, {+ const animation = gsap.to(element, {+ boxShadow: target,duration: motionDuration(motionDurations.feedback),ease: motionEase("ease-out"),+ overwrite: "auto",onComplete: () => setRenderedActive(active)})- return () => { animation.stop() }+ return () => { animation.kill() }}, [active, reducedMotion, renderedActive])@@ -286,7 +296,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,if (minimized) {- setSurface(surfaceElement.current, reducedMotion ? 1 : 0.86, reducedMotion ? 0 : 28, "hidden")+ gsap.set(surfaceElement.current, { scale: reducedMotion ? 1 : 0.86, y: reducedMotion ? 0 : 28, visibility: "hidden" })return}@@ -295,23 +305,18 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,restSurface(surfaceElement.current)- setVisibility(surfaceElement.current, "visible")+ gsap.set(surfaceElement.current, { visibility: "visible" })return}prepareSurfaceEntrance(surfaceElement.current, reducedMotion)- setVisibility(surfaceElement.current, "visible")+ gsap.set(surfaceElement.current, { visibility: "visible" })const animation = enterSurface(surfaceElement.current, reducedMotion)- entranceMotion.current = animation-- return () => {- animation?.stop()- if (entranceMotion.current === animation) entranceMotion.current = null- }+ return () => { animation?.kill() }// Presence at birth reads the mount's own values once.}, [])@@ -327,15 +332,14 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,// restore will animate from if the preference has been relaxed.if (!reducedMotion) {- if (minimized) setSurface(surfaceElement.current, 0.86, 28, "hidden")+ if (minimized) gsap.set(surfaceElement.current, { ...surfacePose.minimized, visibility: "hidden" })return}- entranceMotion.current?.stop()- entranceMotion.current = null+ gsap.killTweensOf(surfaceElement.current)- setSurface(surfaceElement.current, 1, 0, minimized || closing ? "hidden" : "visible")+ gsap.set(surfaceElement.current, { ...surfacePose.resting, visibility: minimized || closing ? "hidden" : "visible" })if (closing) {@@ -370,7 +374,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,// would be motion toward nowhere.if (bare || reducedMotion) {- setSurface(surfaceElement.current, 1, 0, minimized ? "hidden" : "visible")+ gsap.set(surfaceElement.current, { ...surfacePose.resting, visibility: minimized ? "hidden" : "visible" })return}@@ -378,17 +382,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) setVisibility(surfaceElement.current, "visible")+ if (!minimized) gsap.set(surfaceElement.current, { visibility: "visible" })const animation = minimized- ? animateSurfaceTransform(surfaceElement.current, 0.86, 28, { duration: motionDuration(motionDurations.minimize), ease: motionEase("ease-in"), onComplete: () => setVisibility(surfaceElement.current, "hidden") })+ ? gsap.to(surfaceElement.current, { ...surfacePose.minimized, duration: motionDuration(motionDurations.minimize), ease: "power3.in", overwrite: "auto", onComplete: () => gsap.set(surfaceElement.current, { visibility: "hidden" }) })- : animateSurfaceTransform(surfaceElement.current, 1, 0, { duration: motionDuration(motionDurations.restore), ease: motionEase("ease-out") })+ : gsap.to(surfaceElement.current, { ...surfacePose.resting, duration: motionDuration(motionDurations.restore), ease: "power3.out", overwrite: "auto" })- return () => { animation?.stop() }+ return () => { animation.kill() }- }, [minimized, bare, reducedMotion])+ }, [minimized])// Closing is a handshake: the exit plays, onClosed reports the// element may be unmounted.@@ -408,15 +412,17 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,return}- const animation = animateSurfaceTransform(surfaceElement.current, 0.86, 12, {+ const animation = gsap.to(surfaceElement.current, {+ ...surfacePose.closing,duration: motionDuration(motionDurations.close),- ease: motionEase("ease-in"),+ ease: "power2.in",+ overwrite: "auto",onComplete: completeClosure})- return () => { animation?.stop() }+ return () => { animation.kill() }- }, [closing, bare, reducedMotion])+ }, [closing])function grab(event: ReactPointerEvent<HTMLElement>, edge: WindowEdge | null) {@@ -443,9 +449,9 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,let current: WindowRegion = { ...origin }- geometryMotion.current?.stop()- geometryMotion.current = null- setRegion(frame.current, origin)+ gsap.killTweensOf(frame.current)++ gsap.set(frame.current, { left: origin.x, top: origin.y, width: origin.width, height: origin.height, transform: "none" })setRenderedGeometry({position: { x: origin.x, y: origin.y },@@ -671,7 +677,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. Motion moves that stable+ // otherwise the last settled representation. GSAP moves that stable// representation to each new authoritative target.const geometry = gesture@@ -905,29 +911,6 @@ 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 windowTransform(x: number, y: number, scaleX: number, scaleY: number) {- return `translate(${x}px, ${y}px) scale(${scaleX}, ${scaleY})`-}--function setSurface(element: HTMLElement | null, scale: number, y: number, visibility: "hidden" | "visible") {- if (!element) return- setSurfaceTransform(element, scale, y)- 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.xdiff --git a/source/libs/react-motion.ts b/source/libs/react-motion.tsdeleted file mode 100644index d2cffb3..0000000--- a/source/libs/react-motion.ts+++ /dev/null@@ -1,6 +0,0 @@-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.tsxnew file mode 100644index 0000000..cc9d897--- /dev/null+++ b/source/libs/react-motion.tsx@@ -0,0 +1,51 @@+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+}