An open-source, self-hosted system for apps built with web technologies.
Move desktop animations to GSAP
zohayrslileh377c1d8f88f7
diff --git a/source/client/view/appearance/motion.ts b/source/client/view/appearance/motion.tsnew file mode 100644index 0000000..0b49c2e--- /dev/null+++ b/source/client/view/appearance/motion.ts@@ -0,0 +1,39 @@+import { type Easing } from "@phreshos/core"+import gsap from "gsap"+import { CustomEase } from "gsap/CustomEase"++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": [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>()++/** 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++ const easing = CustomEase.create(`phresh-${registered.size}`, key)++ registered.set(key, easing)++ return easing+}++export function motionDuration(milliseconds: number) {++ return milliseconds / 1_000+}++export default gsapdiff --git a/source/client/view/appearance/surface-presence.ts b/source/client/view/appearance/surface-presence.tsindex a319dd0..cb13ef0 100644--- a/source/client/view/appearance/surface-presence.ts+++ b/source/client/view/appearance/surface-presence.ts@@ -1,4 +1,4 @@-import gsap from "gsap"+import gsap from "./motion"const entered = { scale: 1, y: 0 }diff --git a/source/client/view/desktop/window-manager/snap-preview.tsx b/source/client/view/desktop/window-manager/snap-preview.tsxnew file mode 100644index 0000000..2d7f1dd--- /dev/null+++ b/source/client/view/desktop/window-manager/snap-preview.tsx@@ -0,0 +1,98 @@+import { type CSSProperties, useLayoutEffect, useRef, useState } from "react"+import gsap, { motionEase } from "../../appearance/motion"+import { resolveWindowGeometry, resolveWindowValue, windowPaintInsets, type WindowSurfaceSize } from "./window-geometry"+import { type Position, type Size } from "@phreshos/core"++/** 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 [rendered, setRendered] = useState(shown)++ useLayoutEffect(function () {++ const preview = element.current+ const parent = preview?.offsetParent++ 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 })+ setRendered(shown)++ return+ }++ 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: 0.18,+ ease: motionEase([0.33, 1, 0.68, 1]),+ overwrite: "auto",+ onComplete: () => setRendered(shown)+ })++ return () => { animation.kill() }++ }, [shown.position.x, shown.position.y, shown.size.width, shown.size.height, visible, reducedMotion])++ return <div+ ref={element}+ className="pointer-events-none absolute"+ style={{+ 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+ }}+ >+ <div+ data-snap-preview-frame+ className="absolute border border-white/50 bg-white/25 shadow-snap-preview backdrop-blur-sm"+ style={bare ? { inset: 0 } : { ...windowPaintInsets(shown.position, shown.size, paintSurfaceSize), borderRadius: radius }}+ />+ </div>+}++export interface SnapTarget {+ position: Position+ size: Size+}++interface SnapPreviewProps {+ shown: SnapTarget+ visible: boolean+ bare: boolean+ paintSurfaceSize: WindowSurfaceSize+ radius: number+ reducedMotion: boolean+ zIndex: CSSProperties["zIndex"]+}diff --git a/source/client/view/desktop/window-manager/window-geometry.ts b/source/client/view/desktop/window-manager/window-geometry.tsindex c752a80..69eae74 100644--- a/source/client/view/desktop/window-manager/window-geometry.ts+++ b/source/client/view/desktop/window-manager/window-geometry.ts@@ -50,6 +50,17 @@ export function wholeWindowGeometry(position: Position, size: Size) {return equal(position.x, 0, 0) && equal(position.y, 0, 0) && equal(size.width, 1, 0) && equal(size.height, 1, 0)}+/** Resolves one declarative Window geometry inside a measured surface. */+export function resolveWindowGeometry(position: Position, size: Size, surface: WindowSurfaceSize): WindowRegion {++ return {+ x: pixels(position.x, surface.width),+ y: pixels(position.y, surface.height),+ width: pixels(size.width, surface.width),+ height: pixels(size.height, surface.height)+ }+}+/*** The window's box is its geometry; an ordinary painted frame is inset only* on edges that do not touch that box's containing surface. Snap previews usediff --git a/source/client/view/desktop/window-manager/window-header.tsx b/source/client/view/desktop/window-manager/window-header.tsxindex 3de3201..d03094d 100644--- a/source/client/view/desktop/window-manager/window-header.tsx+++ b/source/client/view/desktop/window-manager/window-header.tsx@@ -1,8 +1,48 @@-import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode } from "react"+import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useLayoutEffect, useRef, useState } from "react"+import gsap, { 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: 0.2, 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 <headeronPointerDown={onGrab}@@ -17,19 +57,27 @@ export default function WindowHeader({ title, icon, active, whole, reducedMotion<img+ ref={iconElement}+src={icon}alt=""draggable={false}- className={`size-4 rounded-sm object-contain ${reducedMotion ? "" : "transition-opacity duration-200"} ${active ? "opacity-100" : "opacity-60"}`}+ className="size-4 rounded-sm object-contain"++ style={{ opacity: renderedActive ? 1 : 0.6 }}/>{/* Focus is said on the chrome and nowhere else. Content staysequally legible when another window owns the keyboard. */}- <span className={`truncate text-window-title font-medium text-shadow-chrome ${reducedMotion ? "" : "transition-colors duration-200"} ${active ? "text-slate-800" : "text-slate-500"}`}>{title}</span>+ <span+ ref={titleElement}+ className="truncate text-window-title font-medium text-shadow-chrome"+ style={{ color: renderedActive ? "#1e293b" : "#64748b" }}+ >{title}</span></div>@@ -67,22 +115,60 @@ 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 reaction = danger+ 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++ ? { borderColor: "rgba(253, 164, 175, 0.7)", backgroundColor: "#f43f5e", color: "#ffffff", scale: 1 }++ : { borderColor: "rgba(255, 255, 255, 0.7)", backgroundColor: "rgba(255, 255, 255, 0.65)", color: "#0f172a", scale: 1 }++ const pressed = { ...hover, backgroundColor: danger ? "#e11d48" : "rgba(255, 255, 255, 0.8)", scale: 0.95 }++ function react(values: typeof base) {++ const button = element.current- ? "hover:border-rose-300/70 hover:bg-rose-500 hover:text-white active:bg-rose-600"+ if (!button) return- : "hover:border-white/70 hover:bg-white/65 hover:text-slate-900 active:bg-white/80"+ gsap.killTweensOf(button)++ if (reducedMotion) gsap.set(button, values)++ else gsap.to(button, { ...values, duration: 0.1, ease: motionEase("ease-out"), overwrite: "auto" })+ }return <button+ {...props}++ ref={element}+aria-label={label}+ onPointerEnter={() => {++ hovering.current = true+ react(hover)+ }}++ onPointerLeave={() => {++ hovering.current = false+ react(base)+ }}+onPointerDown={event => {event.stopPropagation()if (event.button !== 0) return+ react(pressed)+if (focusOnPointerDown) event.currentTarget.focus({ preventScroll: true })// Minimise and close act without focusing their window. Preventing@@ -92,6 +178,20 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMotionClick?.()}}+ 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()@@ -99,9 +199,7 @@ function Control({ label, danger = false, focusOnPointerDown = true, reducedMotiif (event.detail === 0) onClick?.()}}- className={`grid size-6 place-items-center rounded-md border border-transparent bg-white/15 text-slate-600 outline-none shadow-sm disabled:pointer-events-none disabled:opacity-40 focus-visible:relative focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-sky-500 ${reducedMotion ? "" : "transition-colors duration-100 active:scale-95"} ${reaction}`}-- {...props}+ className="grid size-6 place-items-center rounded-md border border-transparent bg-white/15 text-slate-600 outline-none shadow-sm disabled:pointer-events-none disabled:opacity-40 focus-visible:relative focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-sky-500">diff --git a/source/client/view/desktop/window-manager/window-surface.tsx b/source/client/view/desktop/window-manager/window-surface.tsxindex 6efd8a7..3008f9f 100644--- a/source/client/view/desktop/window-manager/window-surface.tsx+++ b/source/client/view/desktop/window-manager/window-surface.tsx@@ -1,13 +1,12 @@import { useReducedMotion } from "@libs/react-motion"-import { isScaleLevel, scale, type Easing, type SurfaceSettings } from "@phreshos/core"+import { isScaleLevel, scale, type SurfaceSettings } from "@phreshos/core"import { Surface, useTheme } from "@phreshos/react-ui"import { useLayoutEffect, useRef, useState } from "react"import { type LocalSurfaceState } from "../client-host/local-window"+import gsap, { motionDuration, motionEase } from "../../appearance/motion"const systemDuration = 240-const systemEasing = "ease-out"-/** Projects one representation-local target and animates explicit replacements. */export default function WindowSurface({ state, onComplete }: WindowSurfaceProps) {@@ -48,42 +47,34 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)firstRender.current = false- setRendered(settings)-- surface.style.opacity = String(target.opacity)-- surface.style.borderRadius = target.borderRadius-const transaction = requestedAnimation?.transactionconst duration = transaction?.duration ?? systemDuration- if (!transaction || !changed) return+ gsap.killTweensOf(surface)- if (reducedMotion || duration === 0) {+ if (!transaction || !changed || reducedMotion || duration === 0) {- onComplete(revision!)+ gsap.set(surface, target)+ setRendered(settings)++ if (transaction && changed) onComplete(revision!)return}- const animation = surface.animate([from, target], {-- duration,+ const animation = gsap.fromTo(surface, from, {+ ...target,+ duration: motionDuration(duration),+ ease: motionEase(transaction.easing),+ overwrite: "auto",+ onComplete: function () {- easing: easing(transaction.easing),-- fill: "both"+ setRendered(settings)+ onComplete(revision!)+ }})- animation.finished.then(function () {-- animation.cancel()-- onComplete(revision!)-- }, () => undefined)-return function () {const shown = getComputedStyle(surface)@@ -92,7 +83,7 @@ export default function WindowSurface({ state, onComplete }: WindowSurfaceProps)surface.style.borderRadius = shown.borderRadius- animation.cancel()+ animation.kill()}}, [reducedMotion, requestedAnimation?.revision, settings, themeRadius])@@ -126,13 +117,6 @@ function values(settings: SurfaceSettings, themeRadius: number) {}}-function easing(value: Easing | undefined) {-- if (typeof value === "string") return value-- return value ? `cubic-bezier(${value.join(", ")})` : systemEasing-}-interface WindowSurfaceProps {state: LocalSurfaceStatediff --git a/source/client/view/desktop/window-manager/window.tsx b/source/client/view/desktop/window-manager/window.tsxindex 95d30fd..a37c5f2 100644--- a/source/client/view/desktop/window-manager/window.tsx+++ b/source/client/view/desktop/window-manager/window.tsx@@ -2,33 +2,32 @@ import { ComponentProps, PointerEvent as ReactPointerEvent, ReactNode, useLayoutimport { useReducedMotion } from "@libs/react-motion"import { enterSurface, prepareSurfaceEntrance, restSurface } from "../../appearance/surface-presence"import { Surface, useTheme } from "@phreshos/react-ui"-import { absoluteWindowGeometry, resolveWindowValue, wholeWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "./window-geometry"-import { numericScale, type Position, type Size } from "@phreshos/core"+import { absoluteWindowGeometry, resolveWindowGeometry, resolveWindowValue, wholeWindowGeometry, windowPaintInsets, type WindowRegion, type WindowSurfaceSize } from "./window-geometry"+import { numericScale, type Position, type Size, type WindowGeometry } from "@phreshos/core"import WindowHeader from "./window-header"import WindowSurface from "./window-surface"import { type LocalAnimation, type LocalSurfaceState } from "../client-host/local-window"import { type LocalGeometryReader } from "./local-windows"-import gsap from "gsap"+import gsap, { motionDuration, motionEase } from "../../appearance/motion"+import SnapPreview, { type SnapTarget } from "./snap-preview"/*** A window: a pure function of the record it is given. Every render- * declares the whole geometry from props — a float as left/top pixels,- * a tile as its relative form — and CSS transitions animate whatever- * changes between renders. There is no imperative geometry writer, no- * birth snapshot, no mode to reconcile: a refreshed page renders the- * truth it was born with because rendering the truth is all this- * component does.+ * declares the whole target geometry from props — a float as left/top+ * 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.** A gesture is state, not a side channel: while one runs, the render* derives from the gesture's rectangle instead of the record — movement- * rides a transform above the grabbed origin, transitions pause — and+ * rides a transform above the grabbed origin, interpolation pauses — and* release reports the outcome (onMove or onResize with resting pixels —* a resize carrying an origin only when the edge dragged moved one —* onSnap with the shares a zone names) and drops the gesture in the same* batch the record updates, so nothing jumps.*- * GSAP keeps exactly one duty: presence — the scale and drift of entering,- * minimising and closing on the painted surface, never the frame.+ * 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* sheet. The close control requests — the window leaves only when the truth@@ -46,10 +45,6 @@ const edges: { edge: WindowEdge, className: string }[] = [{ edge: "se", className: "bottom-0 right-0 size-4 cursor-nwse-resize" }]-const settle = ["left", "top", "width", "height", "transform"].map(property => `${property} 0.3s cubic-bezier(0.65, 0, 0.35, 1)`).join(", ")--const morphing = ["left", "top", "width", "height"].map(property => `${property} 0.22s cubic-bezier(0.33, 1, 0.68, 1)`).join(", ")-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)@@ -68,6 +63,14 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,const [gesture, setGesture] = useState<Gesture | null>(null)+ const [renderedGeometry, setRenderedGeometry] = useState<WindowGeometry>({ position, size })++ const [renderedActive, setRenderedActive] = useState(active)++ const morphStart = useRef<WindowRegion | null>(null)++ const morphRevision = useRef(0)+useLayoutEffect(function () {if (!onLocalRepresentation) return@@ -98,15 +101,140 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,useLayoutEffect(function () {- if (!geometryAnimation) return+ const element = frame.current++ const parent = element?.offsetParent++ if (!element || !parent || gesture) return++ if (sameGeometry(renderedGeometry, { position, size })) {++ if (geometryAnimation) onLocalAnimationComplete?.("geometry", geometryAnimation.revision)++ return+ }++ const parentBounds = parent.getBoundingClientRect()+ const shown = element.getBoundingClientRect()+ const current = {+ x: shown.left - parentBounds.left,+ y: shown.top - parentBounds.top,+ width: shown.width,+ height: shown.height+ }+ const target = resolveWindowGeometry(position, size, parentBounds)+ const transaction = geometryAnimation?.transaction+ const duration = transaction?.duration ?? 300++ gsap.killTweensOf(element)++ const complete = function () {++ setRenderedGeometry({ position, size })++ if (geometryAnimation) onLocalAnimationComplete?.("geometry", geometryAnimation.revision)+ }++ 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" })+ complete()++ return+ }++ const animation = gsap.fromTo(element, {+ left: current.x,+ top: current.y,+ width: current.width,+ height: current.height,+ transform: "none"+ }, {+ left: target.x,+ top: target.y,+ width: target.width,+ height: target.height,+ transform: "none",+ duration: motionDuration(duration),+ ease: transaction ? motionEase(transaction.easing) : motionEase([0.65, 0, 0.35, 1]),+ overwrite: "auto",+ onComplete: complete+ })++ 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,+ width: held.width,+ height: held.height,+ transform: "none"+ })+ }++ }, [position.x, position.y, size.width, size.height, geometryAnimation?.revision, reducedMotion, bare, gesture !== null])++ useLayoutEffect(function () {++ const element = frame.current+ const from = morphStart.current++ 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+ }, {+ left: gesture.origin.x,+ top: gesture.origin.y,+ width: gesture.current.width,+ height: gesture.current.height,+ duration: 0.22,+ ease: motionEase([0.33, 1, 0.68, 1]),+ overwrite: "auto"+ })++ return () => { animation.kill() }++ }, [gesture?.morph, reducedMotion])++ useLayoutEffect(function () {++ const element = surfaceElement.current++ if (!element || renderedActive === active) return- const duration = reducedMotion ? 0 : geometryAnimation.transaction.duration ?? 300+ const property = active ? "--shadow-window-active" : "--shadow-window-inactive"+ const target = getComputedStyle(element).getPropertyValue(property).trim() || "none"- const completed = globalThis.setTimeout(() => onLocalAnimationComplete?.("geometry", geometryAnimation.revision), duration)+ gsap.killTweensOf(element, "boxShadow")- return () => globalThis.clearTimeout(completed)+ if (reducedMotion) {- }, [geometryAnimation?.revision, reducedMotion])+ gsap.set(element, { boxShadow: target })+ setRenderedActive(active)++ return+ }++ const animation = gsap.to(element, {+ boxShadow: target,+ duration: 0.2,+ ease: motionEase("ease-out"),+ overwrite: "auto",+ onComplete: () => setRenderedActive(active)+ })++ return () => { animation.kill() }++ }, [active, reducedMotion, renderedActive])const closureCompleted = useRef(false)@@ -128,23 +256,6 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,// this is the interface recognising a size it offered to set.const whole = wholeWindowGeometry(position, size)- // The render that lands a plain commit suppresses transitions for one- // frame: the record now equals what the gesture showed, and the- // decomposition swap (origin+transform to left alone) must not be- // interpolated — two properties animating opposite ways cancel only- // in exact math, and the browser's residue reads as drift.- const [landed, setLanded] = useState(false)-- useLayoutEffect(function () {-- if (!landed) return-- const settle = requestAnimationFrame(() => setLanded(false))-- return () => cancelAnimationFrame(settle)-- }, [landed])-// Presence: a newly created window enters, while a window inherited// when its desktop mounts is already here and renders at rest. A full// page refresh remounts elements, not processes, and must not make all@@ -309,6 +420,17 @@ 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" })++ setRenderedGeometry({+ position: { x: origin.x, y: origin.y },+ size: { width: origin.width, height: origin.height }+ })++ if (geometryAnimation) onLocalAnimationComplete?.("geometry", geometryAnimation.revision)+// Pulling a shared window out of its placement belongs to the// header alone. An edge is not a hand asking to float — it is a// hand asking for a different size, and a window keeps whatever@@ -317,7 +439,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,let moved = false- let morph = false+ let morph: number | null = nulllet zone: Snap | null = null@@ -408,13 +530,15 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,// stays live: a brief morph phase transitions the body,// never the transform — and it must survive the moves// that arrive while it plays.- morph = !reducedMotion+ morphStart.current = { ...current }- if (morph) setTimeout(() => {+ morph = reducedMotion ? null : ++morphRevision.current- morph = false+ if (morph !== null) setTimeout(() => {- setGesture(active => active && { ...active, morph: false })+ morph = null++ setGesture(active => active && { ...active, morph: null })}, 220)@@ -496,9 +620,18 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,// share with the pixels it happened to resolve to.else onResize?.(current.width, current.height, current.x === origin.x && current.y === origin.y ? null : { x: current.x, y: current.y })- if (!reducedMotion) setLanded(true)}+ if (moved && motion.type === "pointerup") {++ setRenderedGeometry({+ position: { x: current.x, y: current.y },+ size: { width: current.width, height: current.height }+ })+ }++ else if (motion.type === "pointercancel") setRenderedGeometry({ position, size })+setGesture(null)}@@ -508,42 +641,33 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,handle.addEventListener("pointercancel", release)- setGesture({ origin, current, zone, shown, morph: false })+ setGesture({ origin, current, zone, shown, morph: null })}// ------------------------------------------------------------ render// The geometry, declared whole every render: the gesture's rectangle// while one runs — movement as a transform above the grabbed origin,- // transitions paused — otherwise the record's own form.+ // otherwise the last settled representation. GSAP moves that stable+ // representation to each new authoritative target.const geometry = gesture- ? { left: gesture.origin.x, top: gesture.origin.y, width: gesture.current.width, height: gesture.current.height, transform: `translate(${gesture.current.x - gesture.origin.x}px, ${gesture.current.y - gesture.origin.y}px)`, transition: gesture.morph && !reducedMotion ? morphing : "none" }+ ? { left: gesture.origin.x, top: gesture.origin.y, width: gesture.current.width, height: gesture.current.height, transform: `translate(${gesture.current.x - gesture.origin.x}px, ${gesture.current.y - gesture.origin.y}px)` }: {- left: resolveWindowValue(position.x),+ left: resolveWindowValue(renderedGeometry.position.x),- top: resolveWindowValue(position.y),+ top: resolveWindowValue(renderedGeometry.position.y),- width: resolveWindowValue(size.width),+ width: resolveWindowValue(renderedGeometry.size.width),- height: resolveWindowValue(size.height),+ height: resolveWindowValue(renderedGeometry.size.height),- transform: "none",-- // Bare, geometry does not travel. A window the system- // paints nothing on is one whose motion is not the- // system's either: asked to be somewhere, it is there,- // rather than gliding over half a second nobody asked for.- transition: geometryAnimation && !reducedMotion-- ? explicitGeometryTransition(geometryAnimation)-- : bare || landed || reducedMotion ? "none" : settle+ transform: "none"}- const surface = active+ const surface = renderedActive? "shadow-window-active"@@ -554,17 +678,15 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,return <>{/* The snap preview and its result resolve the same edge contacts. */}- {gesture?.shown && <div-- className="pointer-events-none absolute"-- style={{ left: resolveWindowValue(gesture.shown.position.x), top: resolveWindowValue(gesture.shown.position.y), width: resolveWindowValue(gesture.shown.size.width), height: resolveWindowValue(gesture.shown.size.height), opacity: gesture.zone ? 1 : 0, transition: reducedMotion ? "none" : "opacity 0.15s, left 0.18s, top 0.18s, width 0.18s, height 0.18s", zIndex: style?.zIndex }}-- >-- <div data-snap-preview-frame className="absolute border border-white/50 bg-white/25 shadow-snap-preview backdrop-blur-sm" style={bare ? { inset: 0 } : { ...windowPaintInsets(gesture.shown.position, gesture.shown.size, paintSurfaceSize), borderRadius: outerRadius }} />-- </div>}+ {gesture?.shown && <SnapPreview+ shown={gesture.shown}+ visible={gesture.zone !== null}+ bare={bare}+ paintSurfaceSize={paintSurfaceSize}+ radius={outerRadius}+ reducedMotion={reducedMotion}+ zIndex={style?.zIndex}+ />}<div@@ -602,7 +724,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,Bare, there is no difference: the frame fills the box, sothe window is exactly as large as it asked to be and itsboundaries are the ones its own content draws. */}- <div data-window-container ref={surfaceElement} style={bare ? { inset: 0 } : { ...paintedInsets, borderRadius: outerRadius, color: theme.foreground }} className={`absolute isolate grid ${bare ? "grid-rows-1" : `overflow-hidden grid-rows-[auto_minmax(0,1fr)] ${reducedMotion ? "" : "transition-shadow duration-200"} ${surface}`}`}>+ <div data-window-container ref={surfaceElement} style={bare ? { inset: 0 } : { ...paintedInsets, borderRadius: outerRadius, color: theme.foreground }} className={`absolute isolate grid ${bare ? "grid-rows-1" : `overflow-hidden grid-rows-[auto_minmax(0,1fr)] ${surface}`}`}>{/* Material is paint, not the interaction container. Keepingit as a sibling behind the window contents prevents plain@@ -676,12 +798,7 @@ export default function ({ title, icon, children, onClose, onClosed, onMinimize,type WindowEdge = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw"-interface Snap {-- position: Position-- size: Size-}+type Snap = SnapTargetinterface WindowProps extends Omit<ComponentProps<"div">, "title"> {@@ -764,16 +881,21 @@ interface Gesture {shown: Snap | null- morph: boolean+ morph: number | null}-function explicitGeometryTransition(animation: LocalAnimation) {+function sameGeometry(left: WindowGeometry, right: WindowGeometry) {- const duration = animation.transaction.duration ?? 300-- const easing = animation.transaction.easing+ return left.position.x === right.position.x+ && left.position.y === right.position.y+ && left.size.width === right.size.width+ && left.size.height === right.size.height+}- const curve = Array.isArray(easing) ? `cubic-bezier(${easing.join(", ")})` : easing ?? "ease-out"+function sameRegion(left: WindowRegion, right: WindowRegion) {- return ["left", "top", "width", "height"].map(property => `${property} ${duration}ms ${curve}`).join(", ")+ return Math.abs(left.x - right.x) <= 0.5+ && Math.abs(left.y - right.y) <= 0.5+ && Math.abs(left.width - right.width) <= 0.5+ && Math.abs(left.height - right.height) <= 0.5}