diff --git a/apps/web/src/components/composer.tsx b/apps/web/src/components/composer.tsx index a9327420..aea2567c 100644 --- a/apps/web/src/components/composer.tsx +++ b/apps/web/src/components/composer.tsx @@ -1,4 +1,4 @@ -import { ArrowUp, X, type LucideIcon } from "lucide-react"; +import { ArrowUp } from "lucide-react"; import type { ReactNode, Ref } from "react"; import { cn } from "@/lib/utils"; @@ -101,34 +101,6 @@ export function Composer({ ); } -export function ComposerHeader({ - title, - icon: Icon, - onClose, -}: { - readonly title: string; - readonly icon: LucideIcon; - readonly onClose?: () => void; -}) { - return ( -
- - {title} - {onClose !== undefined && ( - - )} -
- ); -} - export function ComposerSubmit({ label, disabled, diff --git a/apps/web/src/components/loader.tsx b/apps/web/src/components/loader.tsx new file mode 100644 index 00000000..8d0e4480 --- /dev/null +++ b/apps/web/src/components/loader.tsx @@ -0,0 +1,28 @@ +const pixels = [ + [0, 0], + [6, 0], + [12, 0], + [12, 6], + [12, 12], + [6, 12], + [0, 12], + [0, 6], +] as const; + +export function PixelLoader() { + return ( + + {pixels.map(([x, y], index) => ( + + ))} + + ); +} diff --git a/apps/web/src/components/logo.tsx b/apps/web/src/components/logo.tsx new file mode 100644 index 00000000..2370e6fc --- /dev/null +++ b/apps/web/src/components/logo.tsx @@ -0,0 +1,17 @@ +import { cn } from "@/lib/utils"; + +/** The pixel C and square dot from the site's brand/logo.svg. */ +export function Logo({ className }: { readonly className?: string }) { + return ( + + + + + ); +} diff --git a/apps/web/src/components/ui/sidebar.tsx b/apps/web/src/components/ui/sidebar.tsx index 82423cb7..aa9a9140 100644 --- a/apps/web/src/components/ui/sidebar.tsx +++ b/apps/web/src/components/ui/sidebar.tsx @@ -7,6 +7,7 @@ import { PanelLeftIcon } from "lucide-react"; import { Slot } from "radix-ui"; import { useIsMobile } from "@/hooks/use-mobile"; +import { useScrollFade } from "@/hooks/use-scroll-fade"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Separator } from "@/components/ui/separator"; @@ -437,12 +438,15 @@ function SidebarSeparator({ className, ...props }: React.ComponentProps) { + const viewport = React.useRef(null); + useScrollFade(viewport); return (
) { - return ( - - - - ); -} - -export { Switch }; diff --git a/apps/web/src/hooks/use-scroll-fade.ts b/apps/web/src/hooks/use-scroll-fade.ts new file mode 100644 index 00000000..641d77a7 --- /dev/null +++ b/apps/web/src/hooks/use-scroll-fade.ts @@ -0,0 +1,32 @@ +import { useLayoutEffect, type RefObject } from "react"; + +export function useScrollFade(viewport: RefObject) { + useLayoutEffect(() => { + const element = viewport.current; + if (element === null) return; + const update = () => { + element.style.setProperty("--scroll-top", element.scrollTop > 1 ? "transparent" : "black"); + element.style.setProperty( + "--scroll-bottom", + element.scrollTop + element.clientHeight < element.scrollHeight - 1 ? "transparent" : "black", + ); + }; + const resize = new ResizeObserver(update); + const observe = () => { + resize.disconnect(); + resize.observe(element); + for (const child of element.children) resize.observe(child); + update(); + }; + const mutations = new MutationObserver(observe); + // Direct children only: their ResizeObserver entries already catch anything nested growing. + mutations.observe(element, { childList: true }); + element.addEventListener("scroll", update, { passive: true }); + observe(); + return () => { + resize.disconnect(); + mutations.disconnect(); + element.removeEventListener("scroll", update); + }; + }, [viewport]); +} diff --git a/apps/web/src/kernel/servers.ts b/apps/web/src/kernel/servers.ts index cd34bd5f..1b006102 100644 --- a/apps/web/src/kernel/servers.ts +++ b/apps/web/src/kernel/servers.ts @@ -15,7 +15,7 @@ export interface Problem { } /** The default server's problem from its status; undefined while the app can work with it. */ -export function problemOf(status: ServerStatus): Problem | undefined { +function problemOf(status: ServerStatus): Problem | undefined { const { cli, server } = status; // An already running, compatible server is usable even without a local CLI. if (server._tag === "Running") return undefined; diff --git a/apps/web/src/landing/landing.tsx b/apps/web/src/landing/landing.tsx index cb7a1411..bd4c756a 100644 --- a/apps/web/src/landing/landing.tsx +++ b/apps/web/src/landing/landing.tsx @@ -7,6 +7,7 @@ import { NoticeSlot } from "@/components/banner"; import { Composer, ComposerSubmit } from "@/components/composer"; import { makeHost } from "../kernel/host"; import { sessionAddress } from "../widgets/session/address"; +import { handoffs } from "../widgets/session/handoff"; import { Json, type Place as Where, topics } from "../widgets/session/schema"; import { useOpenElsewhere } from "../wm/open"; import { ModelPicker, ThinkingPicker, useChoice, useModelsNotice } from "@/components/model"; @@ -50,13 +51,14 @@ export function Landing() { const where: Where = { _tag: "Folder", path: place.path }; setPending(true); setError(undefined); + const prompt = { id: crypto.randomUUID(), text: query.trim(), createdAt: Date.now() }; const created = await bus .request({ topic: topics.create, payload: encodeCreate({ place: where, - messageId: crypto.randomUUID(), - text: query.trim(), + messageId: prompt.id, + text: prompt.text, ...(model === undefined ? {} : { model }), ...(thinking === undefined ? {} : { thinkingLevel: thinking }), }), @@ -68,6 +70,7 @@ export function Landing() { setError(created?.message ?? "The CodeWork server is not reachable."); return; } + handoffs.set(created.sessionId, prompt); refreshProjects(); await openElsewhere(sessionAddress(created.sessionId), placeLabel(place), "replace"); }; diff --git a/apps/web/src/landing/sidebar.tsx b/apps/web/src/landing/sidebar.tsx index babb287c..2b339c6e 100644 --- a/apps/web/src/landing/sidebar.tsx +++ b/apps/web/src/landing/sidebar.tsx @@ -3,7 +3,8 @@ import { PlusSignIcon, Search01Icon, Settings02Icon, SquarePenIcon } from "@huge import { HugeiconsIcon } from "@hugeicons/react"; import { Link, useNavigate, useParams } from "@tanstack/react-router"; import { AsyncResult } from "effect/reactivity"; -import { type MouseEvent, useMemo, useState } from "react"; +import type { Project } from "@codeworksh/contract"; +import { type MouseEvent, memo, useCallback, useLayoutEffect, useMemo, useRef, useState } from "react"; import { Sidebar, @@ -15,7 +16,7 @@ import { } from "@/components/ui/sidebar"; import { isMac, openMode } from "@codeworksh/widget/view"; import { sessionAddress } from "../widgets/session/address"; -import { projectsAtom } from "../widgets/session/projects"; +import { projectsAtom, workingAtom } from "../widgets/session/projects"; import { focusedAtom } from "../wm/chrome"; import { deskAtom } from "../wm/instances"; import { useOpenElsewhere } from "../wm/open"; @@ -27,6 +28,7 @@ import { problemAtom } from "../kernel/servers"; import { Empty, EmptyAction } from "./empty"; import { useAddProject } from "../shell/palette"; import { placeAtom } from "./place"; +import { PixelLoader } from "@/components/loader"; /** * Recent sessions across every project, newest first, beside every page. With none yet it invites @@ -35,6 +37,7 @@ import { placeAtom } from "./place"; export function SessionsSidebar() { const result = useAtomValue(projectsAtom); const problem = useAtomValue(problemAtom); + const working = useAtomValue(workingAtom); const [query, setQuery] = useState(""); const openElsewhere = useOpenElsewhere(); const [place, setPlace] = useAtom(placeAtom); @@ -56,11 +59,16 @@ export function SessionsSidebar() { }; // Primary and middle clicks open; a right click is left to the context menu. Shift, like a // browser's new window, asks for a workspace of its own. - const open = (session: { id: string; project: { name: string } }, event: MouseEvent) => { + // Read through a ref, so rows keep one handler and skip re-rendering when the desk changes. + const opener = useRef(openElsewhere); + useLayoutEffect(() => { + opener.current = openElsewhere; + }); + const open = useCallback((session: Listed, event: MouseEvent) => { if (event.button > 1) return; const placement = event.shiftKey ? "workspace" : openMode(event); - void openElsewhere(sessionAddress(session.id), session.project.name, placement); - }; + void opener.current(sessionAddress(session.id), session.project.name, placement); + }, []); const needle = query.trim().toLowerCase(); const sessions = useMemo( @@ -141,43 +149,13 @@ export function SessionsSidebar() { ) : (
    {sessions.map((session) => ( -
  • - -
  • + ))}
)} @@ -195,3 +173,63 @@ export function SessionsSidebar() { ); } + +type Listed = Project["sessions"][number] & { readonly project: Project }; + +/** Off-screen rows skip layout and paint until scrolled near; memoized so a loader or focus change repaints one row. */ +const SessionRow = memo(function SessionRow({ + session, + current, + working, + onOpen, +}: { + readonly session: Listed; + readonly current: boolean; + readonly working: boolean; + readonly onOpen: (session: Listed, event: MouseEvent) => void; +}) { + return ( +
  • + +
  • + ); +}); diff --git a/apps/web/src/routes/__root.tsx b/apps/web/src/routes/__root.tsx index 7cef6381..5fd0e417 100644 --- a/apps/web/src/routes/__root.tsx +++ b/apps/web/src/routes/__root.tsx @@ -8,9 +8,11 @@ import { NavigationControls } from "../shell/titlebar"; import { Palette } from "../shell/palette"; import { Toasts } from "../shell/toasts"; import { Splash } from "../splash"; +import { useWorkingFeed } from "../widgets/session/projects"; // The sessions sidebar wraps every page but settings, which has its own; its open state carries over. function Root() { + useWorkingFeed(); const inSettings = useLocation({ select: (location) => location.pathname.startsWith("/settings") }); return ( (null); - const content = useRef(null); - useEffect(() => { - const element = viewport.current; - const body = content.current; - if (element === null || body === null) return; - const update = () => { - element.style.setProperty("--scroll-top", element.scrollTop > 1 ? "transparent" : "black"); - element.style.setProperty( - "--scroll-bottom", - element.scrollTop + element.clientHeight < element.scrollHeight - 1 ? "transparent" : "black", - ); - }; - const observer = new ResizeObserver(update); - observer.observe(element); - observer.observe(body); - element.addEventListener("scroll", update, { passive: true }); - update(); - return () => { - observer.disconnect(); - element.removeEventListener("scroll", update); - }; - }, []); + useScrollFade(viewport); return ( -
    -
    +
    +
    diff --git a/apps/web/src/settings/sections.ts b/apps/web/src/settings/sections.ts index c945bdac..300fa238 100644 --- a/apps/web/src/settings/sections.ts +++ b/apps/web/src/settings/sections.ts @@ -10,7 +10,7 @@ export interface SettingsSection { readonly keywords: readonly string[]; } -export const sections: readonly SettingsSection[] = [ +const sections: readonly SettingsSection[] = [ { to: "/settings/workspaces", label: "Workspaces", diff --git a/apps/web/src/settings/servers/local.tsx b/apps/web/src/settings/servers/local.tsx index 68937b05..58c62d79 100644 --- a/apps/web/src/settings/servers/local.tsx +++ b/apps/web/src/settings/servers/local.tsx @@ -26,7 +26,7 @@ const updateAtom = Server.mutation("servers.update"); const removeAtom = Server.mutation("servers.remove"); const setDefaultAtom = Server.mutation("servers.setDefault"); -export const INSTALL = "curl -fsSL https://codework.sh/install | sh"; +const INSTALL = "curl -fsSL https://codework.sh/install | sh"; type Tone = "success" | "warning" | "danger" | "info" | "muted"; @@ -347,7 +347,7 @@ function ServerActions({ status, onError }: { status: ServerStatus; onError: (me ); } -export const Card = ({ children }: { children: ReactNode }) => ( +const Card = ({ children }: { children: ReactNode }) => (
    {children}
    ); @@ -450,7 +450,7 @@ function ServerLine({ status }: { status: ServerStatus }) { return "Not running. Once started, it keeps running in the background after the app quits."; } -export function CopyCommand({ command }: { command: string }) { +function CopyCommand({ command }: { command: string }) { const [copied, setCopied] = useState(false); return ( diff --git a/apps/web/src/shell/clones.ts b/apps/web/src/shell/clones.ts index 147f024a..dba25a9c 100644 --- a/apps/web/src/shell/clones.ts +++ b/apps/web/src/shell/clones.ts @@ -10,7 +10,7 @@ import { Server } from "../kernel/rpc"; import { placeAtom } from "../landing/place"; /** Every clone the server tracks, as one list: the current one first, then each change. */ -export const clonesAtom = Server.runtime +const clonesAtom = Server.runtime .atom( Stream.unwrap(Server.use((client) => Effect.succeed(client("host.clones", undefined)))).pipe( // A dropped stream is a reconnect; the next list is whole again. diff --git a/apps/web/src/shell/switcher.tsx b/apps/web/src/shell/switcher.tsx index b9b68971..6bc9dbfe 100644 --- a/apps/web/src/shell/switcher.tsx +++ b/apps/web/src/shell/switcher.tsx @@ -4,7 +4,10 @@ import { AppWindow, X } from "lucide-react"; import { useEffect, useRef } from "react"; import { isMac } from "@codeworksh/widget/view"; +import { PixelLoader } from "@/components/loader"; import { registry } from "../widgets"; +import { threadRef } from "../widgets/session/address"; +import { workingAtom } from "../widgets/session/projects"; import { chromeAtom, chromeOf, focusedAtom, tabOwnerAtom } from "../wm/chrome"; import { deskAtom, deskKey } from "../wm/instances"; import { @@ -32,6 +35,7 @@ export function Switcher({ workspaces, active }: SwitcherProps) { const chrome = useAtomValue(chromeAtom); const focusedOn = useAtomValue(focusedAtom); const owners = useAtomValue(tabOwnerAtom); + const working = useAtomValue(workingAtom); const navigate = useNavigate(); const remove = useAtomSet(deleteWorkspace, { mode: "promise" }); // No confirm, like a browser tab; closing the one on screen moves to a neighbour first. @@ -103,6 +107,11 @@ export function Switcher({ workspaces, active }: SwitcherProps) { {workspaces.map((workspace, index) => { const current = workspace.id === active?.id; const tab = showing(workspace); + const busy = instances.some( + (instance) => + (instance.tags & workspaceTag(workspace)) !== 0 && + working.has(threadRef(instance.address)?.sessionId ?? ""), + ); return (
    - + {busy ? : } {tab} diff --git a/apps/web/src/shell/titlebar.tsx b/apps/web/src/shell/titlebar.tsx index 1c8cef2f..fed02604 100644 --- a/apps/web/src/shell/titlebar.tsx +++ b/apps/web/src/shell/titlebar.tsx @@ -9,10 +9,10 @@ import { Switcher } from "./switcher"; // The window has no native title bar on macOS; a title bar is its drag region and leaves room for the // inset traffic lights. -export const insetTitleBar = window.desktopBridge?.platform === "darwin"; +const insetTitleBar = window.desktopBridge?.platform === "darwin"; /** A square title-bar button; it opts out of the window's drag region so it can be clicked. */ -export const chromeButton = +const chromeButton = "grid size-7 shrink-0 place-items-center rounded-md text-ink-muted press [-webkit-app-region:no-drag] hover:bg-selection-subtle hover:text-ink disabled:opacity-40 disabled:hover:bg-transparent"; /** Window-level navigation remains available on Home, workspaces, and settings. */ diff --git a/apps/web/src/style.css b/apps/web/src/style.css index 02a73893..97b4c84c 100644 --- a/apps/web/src/style.css +++ b/apps/web/src/style.css @@ -282,10 +282,9 @@ --transcript-top: transparent; } -/* After a send, the live turn fills the transcript viewport so the prompt sits - at the top, then follows the reply when it outgrows the viewport. */ -.transcript-turn-anchor { - min-height: var(--transcript-viewport, 0px); +/* A sent prompt waits, unseen, for its anchor before it rises into it. */ +.transcript-turn[data-prompt-pending] { + opacity: 0; } /* While a sent prompt rises into place, the rest of its turn waits for it. */ @@ -506,6 +505,28 @@ } } +@media (prefers-reduced-motion: no-preference) { + .pixel-loader-cell { + animation: pixel-loader 960ms steps(1, end) infinite; + } +} + +@keyframes pixel-loader { + 0% { + opacity: 1; + } + 12.5% { + opacity: 0.65; + } + 25% { + opacity: 0.4; + } + 37.5%, + 100% { + opacity: 0.2; + } +} + @keyframes zen-spin { to { transform: rotate(360deg); @@ -552,8 +573,8 @@ color: color-mix(in srgb, var(--cw-ink) 80%, transparent); } -/* Only soften edges that have more settings content beyond them. */ -.settings-scroll { +/* Only soften edges that have more scrollable content beyond them. */ +.scroll-fade { mask-image: linear-gradient( to bottom, var(--scroll-top, black), diff --git a/apps/web/src/widgets/session/backend.ts b/apps/web/src/widgets/session/backend.ts index cadf7b82..1031313d 100644 --- a/apps/web/src/widgets/session/backend.ts +++ b/apps/web/src/widgets/session/backend.ts @@ -141,6 +141,7 @@ const encodeCreated = Schema.encodeEffect(Json.Created); const encodeWindow = Schema.encodeEffect(Json.Window); const encodeUpdate = Schema.encodeEffect(Json.Update); const encodeSnapshot = Schema.encodeEffect(Json.Snapshot); +const encodeActivity = Schema.encodeEffect(Json.Activity); const decodeSnapshot = Schema.decodeUnknownEffect(Json.Snapshot); /** @@ -276,6 +277,37 @@ export const session = defineBackend({ const publishEach = (event: { readonly sessionId: string; readonly threadId: string }, update: Update) => Effect.forEach(keysFor(event), (key) => publishLive(key, update), { discard: true }); + // Every session's work, followed or not, so the sidebar and tabs show it without a view open: + // threads mid-run, and sessions whose prompt this app sent before their run starts. + const runs = new Set(); + const waking = new Set(); + let shown = ""; + const working = () => [...new Set([...waking, ...[...runs].map((run) => run.split("/")[0]!)])].sort(); + const publishActivity = Effect.suspend(() => { + const list = working(); + const key = list.join("\n"); + if (key === shown) return Effect.void; + shown = key; + return encodeActivity({ working: list }).pipe( + Effect.orDie, + Effect.flatMap((payload) => bus.publish({ topic: topics.working, payload, ephemeral: true })), + Effect.asVoid, + ); + }); + const track = (event: { readonly sessionId: string; readonly threadId: string }, running: boolean) => + Effect.suspend(() => { + waking.delete(event.sessionId); + const run = `${event.sessionId}/${event.threadId}`; + if (running) runs.add(run); + else runs.delete(run); + return publishActivity; + }); + const wake = (sessionId: string) => + Effect.suspend(() => { + waking.add(sessionId); + return publishActivity; + }); + /** Folds what CodeWork only says live: deltas into their drafts, and whether the agent works. */ const observe = (envelope: EventEnvelope): Effect.Effect => { switch (envelope.type) { @@ -317,8 +349,10 @@ export const session = defineBackend({ // in the session's log records it: this is the only place the reason shows. case "session.execution.failed": { const failed = Option.getOrUndefined(decodeFailed(envelope.data)); - if (failed === undefined || keysFor(failed).length === 0) return Effect.void; - return publishEach(failed, { _tag: "Running", running: false }).pipe( + if (failed === undefined) return Effect.void; + if (keysFor(failed).length === 0) return track(failed, false); + return track(failed, false).pipe( + Effect.andThen(publishEach(failed, { _tag: "Running", running: false })), Effect.andThen( publishEach(failed, { _tag: "Failed", @@ -332,11 +366,13 @@ export const session = defineBackend({ case "session.execution.succeeded": case "session.execution.interrupted": { const event = Option.getOrUndefined(decodeOfThread(envelope.data)); - if (event === undefined || keysFor(event).length === 0) return Effect.void; - return publishEach(event, { - _tag: "Running", - running: envelope.type === "session.execution.started", - }); + if (event === undefined) return Effect.void; + const running = envelope.type === "session.execution.started"; + return track(event, running).pipe( + Effect.andThen( + keysFor(event).length === 0 ? Effect.void : publishEach(event, { _tag: "Running", running }), + ), + ); } default: return Effect.void; @@ -530,13 +566,21 @@ export const session = defineBackend({ { ephemeral: true }, ); + // A sent prompt wakes its thread, so its session reads as working before the run starts. const prompt = ({ messageId, text, delivery, ...ref }: Prompt) => codework("thread.prompt", { ...addressed(ref), text, id: messageId, ...(delivery === undefined ? {} : { delivery }), - }); + }).pipe(Effect.tap(() => wake(ref.sessionId))); + + yield* handle( + topics.activity, + Schema.Struct({}), + () => encodeActivity({ working: working() }).pipe(Effect.orDie), + { ephemeral: true }, + ); yield* handle(topics.prompt, Prompt, (input) => prompt(input).pipe( diff --git a/apps/web/src/widgets/session/follow.ts b/apps/web/src/widgets/session/follow.ts new file mode 100644 index 00000000..5f7c20c1 --- /dev/null +++ b/apps/web/src/widgets/session/follow.ts @@ -0,0 +1,347 @@ +import type { AnchoredEndSpaceConfig, LegendListRef, MaintainScrollAtEndOptions } from "@legendapp/list/react"; +import { useCallback, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react"; + +/** The anchored prompt's distance from the top of the viewport. */ +const ANCHOR_OFFSET = 20; +/** How far from the end still counts as at it. */ +const END_BAND = 40; + +const END = { + animated: false, + on: { dataChange: true, footerLayout: false, itemLayout: true, layout: true }, +} as const satisfies MaintainScrollAtEndOptions; +const END_SMOOTH = { ...END, animated: true } as const satisfies MaintainScrollAtEndOptions; + +const CANCEL = Object.freeze({}); + +const PROMPT_RISE_MS = 560; +const PROMPT_REVEAL_MS = 320; +const PROMPT_FADE_MS = 480; +const PROMPT_RISE_FROM = 0.3; + +const isAtEnd = (el: HTMLElement) => el.scrollHeight - el.scrollTop - el.clientHeight <= END_BAND; + +/** Whether the transcript keeps the live end in view. `atEnd` only matters once released. */ +type Follow = { readonly mode: "following" } | { readonly mode: "released"; readonly atEnd: boolean }; +type FollowEvent = "navigated" | "followEnd" | "reachedEnd" | "leftEnd"; + +const FOLLOWING: Follow = { mode: "following" }; + +function transition(state: Follow, event: FollowEvent): Follow { + switch (event) { + case "navigated": + return state.mode === "released" ? state : { mode: "released", atEnd: true }; + case "followEnd": + return FOLLOWING; + case "reachedEnd": + // Navigating away while still at the end stays released until the list reports leaving and + // returning, so a scroll key at the end cannot re-arm. + return state.mode === "released" && !state.atEnd ? FOLLOWING : state; + case "leftEnd": + // While following, the list leaves the end band for a frame on every streamed chunk before + // the follow scroll catches up. + return state.mode === "released" && state.atEnd ? { mode: "released", atEnd: false } : state; + } +} + +/** The follow mode, read by scroll listeners at event time and by render through useSyncExternalStore. */ +function followStore() { + let follow = FOLLOWING; + const listeners = new Set<() => void>(); + return { + subscribe: (listener: () => void) => { + listeners.add(listener); + return () => void listeners.delete(listener); + }, + read: () => follow, + dispatch: (event: FollowEvent) => { + const before = follow; + follow = transition(before, event); + if (follow !== before) for (const listener of listeners) listener(); + return { before, after: follow }; + }, + }; +} + +/** One reader attempt to move the transcript. */ +type Navigation = + | { readonly source: "wheel" | "key"; readonly up: boolean } + | { readonly source: "pointer"; readonly onScrollbar: boolean } + | { readonly source: "touch" | "scroll" }; + +/** + * Whether a navigation can carry the view away from the live end. Downward input counts only outside + * the end band: streaming growth leaves it for a frame, and a gesture then must not release follow. + */ +function releases(navigation: Navigation, el: HTMLElement) { + const scrollsUp = el.scrollTop > 0; + switch (navigation.source) { + case "wheel": + return navigation.up && scrollsUp; + case "key": + return navigation.up ? scrollsUp : !isAtEnd(el); + case "pointer": + return navigation.onScrollbar ? scrollsUp : !isAtEnd(el); + case "touch": + return !isAtEnd(el); + case "scroll": + return true; + } +} + +/** Whether a wheel at `target` scrolls the transcript itself rather than a scroller nested in it. */ +function scrollsTranscript(target: EventTarget | null, el: HTMLElement, deltaY: number) { + if (!(target instanceof Element) || !el.contains(target) || deltaY === 0) return false; + for (let node: Element | null = target; node !== null && node !== el; node = node.parentElement) { + const style = getComputedStyle(node); + if (style.overflowY !== "auto" && style.overflowY !== "scroll") continue; + const canScroll = deltaY < 0 ? node.scrollTop > 0 : node.scrollTop < node.scrollHeight - node.clientHeight; + if (canScroll || style.overscrollBehaviorY === "contain" || style.overscrollBehaviorY === "none") return false; + } + return true; +} + +const UP_KEYS = new Set(["PageUp", "Home", "ArrowUp"]); +const DOWN_KEYS = new Set(["PageDown", "End", "ArrowDown", " "]); + +/** Turns the scroller's input listeners into one navigation signal, for as long as it is mounted. */ +function attachViewport(el: HTMLElement, navigate: (navigation: Navigation) => void) { + let holds = 0; + const wheel = (event: WheelEvent) => { + if (!event.ctrlKey && scrollsTranscript(event.target, el, event.deltaY)) + navigate({ source: "wheel", up: event.deltaY < 0 }); + }; + const touch = () => navigate({ source: "touch" }); + // Scrollbar drags are the only pointerdowns whose target is the scroller itself rather than a row. + const pointer = (event: PointerEvent) => navigate({ source: "pointer", onScrollbar: event.target === el }); + const key = (event: KeyboardEvent) => { + if (event.target !== el || event.altKey || event.ctrlKey || event.metaKey) return; + const up = UP_KEYS.has(event.key) || (event.key === " " && event.shiftKey); + if (up || DOWN_KEYS.has(event.key)) navigate({ source: "key", up }); + }; + // Scrolls no listener above hears still count when they move up and away from the end. + let baseline = { top: el.scrollTop, height: el.scrollHeight }; + const scroll = () => { + const next = { top: el.scrollTop, height: el.scrollHeight }; + if (holds > 0 || next.height < baseline.height || next.top > baseline.top) { + baseline = next; + } else if (next.top < baseline.top - 1) { + baseline = next; + if (!isAtEnd(el)) navigate({ source: "scroll" }); + } else { + // A slow scroll can move under a pixel per event; let those moves add up. + baseline = { top: baseline.top, height: next.height }; + } + }; + el.addEventListener("scroll", scroll, { passive: true }); + el.addEventListener("wheel", wheel, { passive: true }); + el.addEventListener("touchmove", touch, { passive: true }); + el.addEventListener("pointerdown", pointer, { passive: true }); + el.addEventListener("keydown", key); + return { + el, + /** Marks our own scrolling so the upward scroll it causes is not read as the reader's. */ + hold: () => { + holds += 1; + let released = false; + return () => { + if (released) return; + released = true; + holds -= 1; + }; + }, + dispose: () => { + el.removeEventListener("scroll", scroll); + el.removeEventListener("wheel", wheel); + el.removeEventListener("touchmove", touch); + el.removeEventListener("pointerdown", pointer); + el.removeEventListener("keydown", key); + }, + }; +} + +/** Fades a freshly sent prompt in while sliding it from the upper viewport into its top anchor. */ +function riseIntoAnchor(scroller: HTMLElement | undefined, promptId: string) { + if (scroller === undefined) return undefined; + const row = scroller.querySelector(`[data-prompt-anchor="${CSS.escape(promptId)}"]`); + if (row === null || typeof row.animate !== "function") return undefined; + if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return undefined; + const view = scroller.getBoundingClientRect(); + const dy = view.top + view.height * PROMPT_RISE_FROM - row.getBoundingClientRect().top; + if (dy <= 1) return undefined; + const animation = row.animate([{ transform: `translateY(${dy}px)` }, { transform: "translateY(0)" }], { + duration: PROMPT_RISE_MS, + easing: "cubic-bezier(0.22, 1, 0.36, 1)", + }); + const fade = row.animate([{ opacity: 0 }, { opacity: 1 }], { duration: PROMPT_FADE_MS, easing: "ease-out" }); + const turn = row.closest(".transcript-turn"); + let revealTimer: ReturnType | undefined; + turn?.setAttribute("data-prompt-rise", "rising"); + animation.onfinish = () => { + turn?.setAttribute("data-prompt-rise", "revealing"); + revealTimer = setTimeout(() => turn?.removeAttribute("data-prompt-rise"), PROMPT_REVEAL_MS); + }; + return () => { + animation.cancel(); + fade.cancel(); + clearTimeout(revealTimer); + turn?.removeAttribute("data-prompt-rise"); + }; +} + +/** + * Keeps the transcript following its live end and lets the reader scroll away: scrolling up + * detaches it, scrolling back to the end re-attaches. A new prompt is anchored to the top of the + * viewport (anchored end space) until its reply reaches the composer; the end follows it from there. + */ +export function useFollow({ + lastUserId, + anchored, + rise, + running, + inset, + anchorIndex, +}: { + readonly lastUserId: string | undefined; + /** On mount: whether the latest prompt opens anchored. */ + readonly anchored: boolean; + /** On mount: whether the latest prompt rises into its anchor. */ + readonly rise: boolean; + readonly running: boolean; + /** The composer overlay's height. */ + readonly inset: number; + /** Where a prompt's turn sits in the list, or -1. */ + readonly anchorIndex: (promptId: string) => number; +}) { + const list = useRef(null); + const viewport = useRef>(undefined); + const [store] = useState(followStore); + const following = useSyncExternalStore(store.subscribe, store.read).mode === "following"; + const [settled, setSettled] = useState(false); + const [anchor, setAnchor] = useState(() => (anchored ? (lastUserId ?? null) : null)); + // A prompt that rises stays hidden until its anchor is in place. + const [rising, setRising] = useState(() => (rise ? lastUserId : undefined)); + const [seenUserId, setSeenUserId] = useState(lastUserId); + if (seenUserId !== lastUserId) { + setSeenUserId(lastUserId); + if (lastUserId !== undefined) { + setAnchor(lastUserId); + setRising(lastUserId); + } + } + // A new prompt follows its reply, wherever the reader was. + useLayoutEffect(() => { + if (lastUserId !== undefined) store.dispatch("followEnd"); + }, [store, lastUserId]); + + const anchorSize = useRef(undefined); + const positioned = useRef(null); + const cancelRise = useRef<() => void>(undefined); + useEffect(() => () => cancelRise.current?.(), []); + + const toEnd = () => requestAnimationFrame(() => void list.current?.scrollToEnd({ animated: false })); + const releaseAnchor = () => { + anchorSize.current = undefined; + setAnchor(null); + toEnd(); + }; + const landed = (promptId: string) => { + if (rising !== promptId) return; + cancelRise.current?.(); + cancelRise.current = riseIntoAnchor(viewport.current?.el, promptId); + setRising(undefined); + }; + + const index = anchor === null ? -1 : anchorIndex(anchor); + const anchoredEndSpace: AnchoredEndSpaceConfig | undefined = + anchor === null || index === -1 + ? undefined + : { + anchorIndex: index, + anchorOffset: ANCHOR_OFFSET, + onReady: ({ anchorIndex: ready, size }) => { + anchorSize.current = size; + if (ready === undefined || positioned.current === anchor) return; + positioned.current = anchor; + // Its reply already reaches the composer: the end follows it instead. + if (following && size <= inset) { + releaseAnchor(); + requestAnimationFrame(() => landed(anchor)); + return; + } + const release = viewport.current?.hold() ?? (() => {}); + void list.current + ?.scrollToIndex({ index: ready, viewPosition: 0, viewOffset: ANCHOR_OFFSET, animated: false }) + .then(() => { + release(); + landed(anchor); + }); + }, + onSizeChanged: (size) => { + anchorSize.current = size; + if (positioned.current === anchor && store.read().mode === "following" && size <= inset) + releaseAnchor(); + }, + }; + + const navigate = useCallback( + (navigation: Navigation) => { + const el = viewport.current?.el; + if (el === undefined || !releases(navigation, el)) return; + if (store.dispatch("navigated").before.mode !== "following") return; + // A new imperative scroll cancels the list's queued ones; a missing item cancels without moving. + void list.current?.scrollToItem({ item: CANCEL, animated: false }); + // A smooth scroll already under way keeps running in the browser; writing its position halts it. + const top = el.scrollTop; + el.scrollTop = top; + }, + [store], + ); + const ref = useCallback( + (instance: LegendListRef | null) => { + list.current = instance; + if (instance === null) return; + const attached = attachViewport(instance.getScrollableNode(), navigate); + viewport.current = attached; + return () => { + attached.dispose(); + if (viewport.current === attached) viewport.current = undefined; + list.current = null; + }; + }, + [navigate], + ); + + const onScroll = () => { + const el = viewport.current?.el; + if (el === undefined) return; + const { before, after } = store.dispatch(isAtEnd(el) ? "reachedEnd" : "leftEnd"); + // Back at the end of a reply that outgrew its anchor: follow the end again. + if ( + after !== before && + after.mode === "following" && + anchorSize.current !== undefined && + anchorSize.current <= inset + ) + releaseAnchor(); + }; + + // The list doesn't follow its footer, so a taller composer would cover the last rows. + const followedInset = useRef(inset); + useLayoutEffect(() => { + const grew = inset > followedInset.current; + followedInset.current = inset; + if (grew && anchoredEndSpace === undefined && store.read().mode === "following") toEnd(); + }); + + const smooth = running && settled && !window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; + return { + ref, + onScroll, + onLoad: () => setSettled(true), + anchoredEndSpace, + maintainScrollAtEnd: anchoredEndSpace !== undefined || !following ? false : smooth ? END_SMOOTH : END, + /** The prompt hidden until it rises into its anchor. */ + pending: anchor !== null && rising === anchor ? rising : undefined, + }; +} diff --git a/apps/web/src/widgets/session/handoff.ts b/apps/web/src/widgets/session/handoff.ts new file mode 100644 index 00000000..16fb25ea --- /dev/null +++ b/apps/web/src/widgets/session/handoff.ts @@ -0,0 +1,8 @@ +/** A prompt the start page sent with a new session, as the session's view first shows it. */ +export type Handoff = { readonly id: string; readonly text: string; readonly createdAt: number }; + +/** + * Kept until the session's view opens, which then shows it as sent: the backend queues a first + * prompt before the conversation takes it in, which would otherwise flash a steer row. + */ +export const handoffs = new Map(); diff --git a/apps/web/src/widgets/session/projects.ts b/apps/web/src/widgets/session/projects.ts index 8b4df37f..fb0c55e3 100644 --- a/apps/web/src/widgets/session/projects.ts +++ b/apps/web/src/widgets/session/projects.ts @@ -1,12 +1,43 @@ -import { useAtomValue } from "@effect/atom-react"; +import { RegistryContext, useAtomSet, useAtomValue } from "@effect/atom-react"; +import { Option, Schema } from "effect"; import { AsyncResult, Atom } from "effect/reactivity"; +import { useContext, useEffect, useMemo } from "react"; +import { makeHost } from "../../kernel/host"; import { Server } from "../../kernel/rpc"; import { codeworkKey } from "../../kernel/servers"; +import { Json, topics } from "./schema"; + +const decodeActivity = Schema.decodeUnknownOption(Json.Activity); /** Every project with its sessions, as the sidebar lists them; refresh it once a new session exists. */ export const projectsAtom = Server.query("projects.list", undefined, { reactivityKeys: codeworkKey }); +/** The sessions the agent works on, followed or not, as the Session backend sees runs start and end. */ +export const workingAtom = Atom.make>(new Set()).pipe(Atom.keepAlive); + +/** Keeps {@link workingAtom} current; mounted once, at the app's root. */ +export function useWorkingFeed() { + const registry = useContext(RegistryContext); + const bus = useMemo(() => makeHost({ registry, package: "codework", instanceId: "activity" }).bus, [registry]); + const setWorking = useAtomSet(workingAtom); + useEffect(() => { + // A live change beats the answer to the first read, which may have been taken before it. + let live = false; + const apply = (payload: unknown) => + Option.map(decodeActivity(payload), ({ working }) => setWorking(new Set(working))); + const stop = bus.subscribe({ topics: [topics.working] }, (item) => { + if ("_tag" in item) return; + live = true; + apply(item.payload); + }); + bus.request({ topic: topics.activity, payload: {} }) + .then((reply) => live || apply(reply.payload)) + .catch(() => undefined); + return stop; + }, [bus, setWorking]); +} + const listedAtom = Atom.family((id: string) => Atom.make((get) => { const result = get(projectsAtom); diff --git a/apps/web/src/widgets/session/schema.ts b/apps/web/src/widgets/session/schema.ts index e4241d75..201348ec 100644 --- a/apps/web/src/widgets/session/schema.ts +++ b/apps/web/src/widgets/session/schema.ts @@ -32,6 +32,10 @@ export const topics = { change: "codework/session.change", /** Requests: a window of a followed thread's conversation, newest first back from `before`. */ page: "codework/session.page", + /** Requests: the sessions the agent works on now; answered with `Activity`. */ + activity: "codework/session.activity", + /** `Activity` again whenever a session starts or stops working; sent live only. */ + working: "codework/session.working", /** Updates to one thread's conversation, by its {@link threadKey}. */ thread: (key: string) => `codework/session/${key}`, }; @@ -161,6 +165,9 @@ export const Window = Schema.Union([ ]); export type Window = typeof Window.Type; +/** The sessions the agent works on: a run is going, or a prompt this app sent is about to start one. */ +const Activity = Schema.Struct({ working: Schema.Array(Schema.String) }); + /** Published on a session's topic as its conversation changes. */ export const Update = Schema.Union([ Schema.TaggedStruct("Info", { info: Info }), @@ -195,4 +202,5 @@ export const Json = { Reply: Schema.toCodecJson(Reply), Snapshot: Schema.toCodecJson(Snapshot), Update: Schema.toCodecJson(Update), + Activity: Schema.toCodecJson(Activity), }; diff --git a/apps/web/src/widgets/session/view.tsx b/apps/web/src/widgets/session/view.tsx index 46ae28ff..8815494e 100644 --- a/apps/web/src/widgets/session/view.tsx +++ b/apps/web/src/widgets/session/view.tsx @@ -3,18 +3,21 @@ import { type HistoryEntry, Part, type QueuedPrompt, type ToolCall } from "@code import { useBus, useEvents, useFrame, type WidgetProps } from "@codeworksh/widget/view"; import { Option, Schema } from "effect"; import { Atom } from "effect/reactivity"; +import { LegendList, type LegendListRenderItemProps } from "@legendapp/list/react"; import { ChevronRight, CircleDashed, X } from "lucide-react"; import { createContext, memo, use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; -import brand from "../../assets/codework.png"; +import { Logo } from "@/components/logo"; import { ComposerNotice, type Notice } from "@/components/banner"; import { Monogram } from "@/components/monogram"; import { useModelName, useModelsNotice } from "@/components/model"; import { threadRef } from "./address"; import { SessionComposer } from "./composer"; +import { useFollow } from "./follow"; import { Markdown } from "./markdown"; import { Message } from "./message"; import { Queue } from "./queue"; +import { type Handoff, handoffs } from "./handoff"; import { projectsAtom, useListedSession } from "./projects"; import { type Info, Json, type ThreadRef, threadKey, topics, type Update } from "./schema"; @@ -61,6 +64,11 @@ type State = type Ready = Extract; +const isRunning = (state: Ready) => { + const last = state.messages.at(-1); + return state.running ?? (last?.role === "assistant" && last.state === "draft"); +}; + /* * The threads opened lately, as last shown: switching back to one renders it on the first frame * while it catches up, instead of an empty frame until its first page loads. @@ -313,31 +321,39 @@ function useConversation(thread: ThreadRef) { }); const oldest = state.status === "ready" && state.more ? state.messages[0]?.id : undefined; - const loadOlder = useCallback( - (beforePrepend: () => void) => { - if (oldest === undefined || paging.current) return; - paging.current = true; - void page(oldest) - .then((window) => { - if (window?._tag !== "Window") return; - beforePrepend(); - setState((current) => { - if (current.status !== "ready") return current; - const known = new Set(current.messages.map((message) => message.id)); - const older = window.messages.filter((message) => !known.has(message.id)); - return { ...current, messages: [...older, ...current.messages], more: window.more }; - }); - }) - .finally(() => { - paging.current = false; + const loadOlder = useCallback(() => { + if (oldest === undefined || paging.current) return; + paging.current = true; + void page(oldest) + .then((window) => { + if (window?._tag !== "Window") return; + setState((current) => { + if (current.status !== "ready") return current; + const known = new Set(current.messages.map((message) => message.id)); + const older = window.messages.filter((message) => !known.has(message.id)); + return { ...current, messages: [...older, ...current.messages], more: window.more }; }); - }, - [oldest, page], - ); + }) + .finally(() => { + paging.current = false; + }); + }, [oldest, page]); return { state, loadOlder, message: store.message }; } +/** A sent prompt as the conversation shows it until the backend echoes it. */ +const standIn = (thread: ThreadRef, prompt: Handoff): HistoryEntry => ({ + id: prompt.id, + threadId: thread.threadId ?? thread.sessionId, + seq: Number.MAX_SAFE_INTEGER, + role: "user", + state: "committed", + createdAt: prompt.createdAt, + updatedAt: prompt.createdAt, + parts: [{ type: "text", text: prompt.text }], +}); + function Conversation({ thread, instanceId, @@ -353,7 +369,12 @@ function Conversation({ const slow = useSlow(loaded.status === "loading"); // Prompts sent while idle, shown before the backend echoes them: it queues a prompt before the // conversation takes it in, which would otherwise flash a queue row. Each leaves once echoed. - const [sent, setSent] = useState([]); + // The start page's first prompt arrives the same way, handed over with the new session. + const [sent, setSent] = useState(() => { + const handoff = thread.threadId === undefined ? handoffs.get(thread.sessionId) : undefined; + return handoff === undefined ? [] : [standIn(thread, handoff)]; + }); + useEffect(() => void handoffs.delete(thread.sessionId), [thread.sessionId]); if (loaded.status === "ready" && sent.length > 0) { const echoed = new Set(loaded.messages.map((message) => message.id)); if (sent.some((message) => echoed.has(message.id))) setSent(sent.filter((message) => !echoed.has(message.id))); @@ -372,6 +393,8 @@ function Conversation({ const ids = new Set(sent.map((message) => message.id)); return { ...loaded, + // A prompt not yet taken in is about to wake the agent: busy until the server says otherwise. + running: loaded.running ?? true, messages: [...loaded.messages, ...sent], queued: loaded.queued.some((prompt) => ids.has(prompt.id)) ? loaded.queued.filter((prompt) => !ids.has(prompt.id)) @@ -379,20 +402,7 @@ function Conversation({ }; }, [loaded, sent]); const sending = useCallback( - (prompt: { readonly id: string; readonly text: string; readonly createdAt: number }) => - setSent((current) => [ - ...current, - { - id: prompt.id, - threadId: thread.threadId ?? thread.sessionId, - seq: Number.MAX_SAFE_INTEGER, - role: "user", - state: "committed", - createdAt: prompt.createdAt, - updatedAt: prompt.createdAt, - parts: [{ type: "text", text: prompt.text }], - }, - ]), + (prompt: Handoff) => setSent((current) => [...current, standIn(thread, prompt)]), [thread], ); const unsent = useCallback((id: string) => setSent((current) => current.filter((message) => message.id !== id)), []); @@ -441,18 +451,19 @@ function Conversation({ const surface = useRef(null); const composer = useRef(null); - // Before paint, so the first frame is laid out with both heights. + const [inset, setInset] = useState(0); + // Before paint, so the first frame is laid out with the composer's height. useLayoutEffect(() => { const root = surface.current; const element = composer.current; if (root === null || element === null) return; const sync = () => { - root.style.setProperty("--transcript-height", `${root.getBoundingClientRect().height}px`); - root.style.setProperty("--composer-height", `${element.getBoundingClientRect().height}px`); + const height = element.getBoundingClientRect().height; + root.style.setProperty("--composer-height", `${height}px`); + setInset(Math.ceil(height)); }; sync(); const observer = new ResizeObserver(sync); - observer.observe(root); observer.observe(element); return () => observer.disconnect(); }, [state.status]); @@ -463,8 +474,7 @@ function Conversation({ const view = stand ?? state; if (view.status === "loading") return ; if (view.status === "failed") return

    {view.message}

    ; - const last = view.messages.at(-1); - const running = view.running ?? (last?.role === "assistant" && last.state === "draft"); + const running = isRunning(view); return (
    @@ -473,6 +483,7 @@ function Conversation({ state={view} running={running} loadOlder={loadOlder} + inset={inset} />
    turn.user?.id ?? turn.replies[0]?.id ?? "empty"; -const PROMPT_JUST_SENT_MS = 1500; -const PROMPT_RISE_MS = 560; -const PROMPT_REVEAL_MS = 320; -const PROMPT_FADE_MS = 480; -const PROMPT_RISE_FROM = 0.3; - -/** - * Keeps the live turn's min-height equal to the visible transcript height above the composer, so - * pinning to the bottom places the latest user prompt at the very top of the viewport. - */ -function syncTranscriptViewport(el: HTMLElement | null) { - if (el === null || el.clientHeight <= 0) return; - const inner = el.querySelector("[data-transcript-content]"); - const style = inner !== null ? getComputedStyle(inner) : null; - const pad = - style !== null ? (Number.parseFloat(style.paddingBottom) || 0) + (Number.parseFloat(style.paddingTop) || 0) : 0; - el.style.setProperty("--transcript-viewport", `${Math.max(0, el.clientHeight - pad)}px`); +// LegendList averages sizes by type; length buckets prevent inflated estimates and nested-update loops. +function turnType(turn: Turn) { + const length = + (turn.user === undefined ? 0 : textOf(turn.user).length) + + turn.replies.reduce((sum, reply) => sum + textOf(reply).length, 0); + return `turn:${Math.max(0, Math.floor(Math.log2(length / 1000)))}`; } -/** Fades a freshly sent prompt in while sliding it from the upper viewport into its top anchor. */ -function riseIntoAnchor(scroller: HTMLElement | null, promptId: string) { - if (scroller === null) return undefined; - const row = scroller.querySelector(`[data-prompt-anchor="${CSS.escape(promptId)}"]`); - if (row === null || typeof row.animate !== "function") return undefined; - if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return undefined; - const view = scroller.getBoundingClientRect(); - const dy = view.top + view.height * PROMPT_RISE_FROM - row.getBoundingClientRect().top; - if (dy <= 1) return undefined; - const animation = row.animate([{ transform: `translateY(${dy}px)` }, { transform: "translateY(0)" }], { - duration: PROMPT_RISE_MS, - easing: "cubic-bezier(0.22, 1, 0.36, 1)", - }); - const fade = row.animate([{ opacity: 0 }, { opacity: 1 }], { - duration: PROMPT_FADE_MS, - easing: "ease-out", - }); - const turn = row.closest(".transcript-turn"); - let revealTimer: ReturnType | undefined; - turn?.setAttribute("data-prompt-rise", "rising"); - animation.onfinish = () => { - turn?.setAttribute("data-prompt-rise", "revealing"); - revealTimer = setTimeout(() => turn?.removeAttribute("data-prompt-rise"), PROMPT_REVEAL_MS); - }; - return () => { - animation.cancel(); - fade.cancel(); - clearTimeout(revealTimer); - turn?.removeAttribute("data-prompt-rise"); - }; -} +const PROMPT_JUST_SENT_MS = 1500; +const PROMPT_RECENT_MS = 5000; + +const TRANSCRIPT_HEADER =
    ; +const MAINTAIN_VISIBLE_CONTENT_POSITION = { data: true, size: true }; /** * The conversation as a list of turns. Sending a prompt anchors the new turn to the top of the - * viewport (`.transcript-turn-anchor`) so older turns scroll above the screen unless the reader - * scrolls up. + * viewport, so older turns scroll above the screen unless the reader scrolls up. */ function Transcript({ state, running, loadOlder, + inset, }: { readonly state: Ready; readonly running: boolean; - readonly loadOlder: (beforePrepend: () => void) => void; + readonly loadOlder: () => void; + /** The composer overlay's height. */ + readonly inset: number; }) { - const scroller = useRef(null); - const stickToBottom = useRef(true); - const lastScrollTop = useRef(0); - const touchY = useRef(undefined); - const prependHeight = useRef(null); const [scrolled, setScrolled] = useState(false); const modelName = useModelName(state.info.hostDir, state.info.model); - const turns = useMemo(() => turnsOf(state.messages), [state.messages]); + const turns = useTurns(state.messages); const lastUser = turns.at(-1)?.user; - const lastUserId = lastUser?.id; - const [anchorTurn, setAnchorTurn] = useState( - () => running || (lastUser !== undefined && Date.now() - lastUser.createdAt < 5000), - ); - const seenUserId = useRef(lastUserId); - if (lastUserId !== seenUserId.current) { - seenUserId.current = lastUserId; - if (lastUserId !== undefined && !anchorTurn) setAnchorTurn(true); - } - - const pinToBottom = useCallback((el: HTMLElement | null) => { - if (el === null) return; - el.scrollTop = el.scrollHeight; - lastScrollTop.current = el.scrollTop; - setScrolled(el.scrollTop > 1); - }, []); - - useLayoutEffect(() => { - stickToBottom.current = true; - const el = scroller.current; - syncTranscriptViewport(el); - pinToBottom(el); - }, [lastUserId, anchorTurn, pinToBottom]); - - const introducedPrompt = useRef<{ id: string | undefined; cancel: (() => void) | undefined }>(undefined); - useLayoutEffect(() => { - const previous = introducedPrompt.current; - if (previous !== undefined && previous.id === lastUserId) return; - const mounting = previous === undefined; - previous?.cancel?.(); - const current: { id: string | undefined; cancel: (() => void) | undefined } = { - id: lastUserId, - cancel: undefined, - }; - introducedPrompt.current = current; - if (lastUserId === undefined || !anchorTurn) return; - if ( - mounting && - !( - running && - turns.length === 1 && - lastUser !== undefined && - Date.now() - lastUser.createdAt < PROMPT_JUST_SENT_MS - ) - ) - return; - current.cancel = riseIntoAnchor(scroller.current, lastUserId); - }, [lastUserId, anchorTurn, running, turns.length, lastUser]); - - const firstTurnKey = turns[0] !== undefined ? turnKey(turns[0]) : undefined; - const seenFirstTurnKey = useRef(firstTurnKey); - useLayoutEffect(() => { - const el = scroller.current; - if (el === null) return; - if (seenFirstTurnKey.current !== firstTurnKey && prependHeight.current !== null) { - const delta = el.scrollHeight - prependHeight.current; - prependHeight.current = null; - seenFirstTurnKey.current = firstTurnKey; - if (delta > 0) { - el.scrollTop += delta; - lastScrollTop.current = el.scrollTop; - } - return; - } - seenFirstTurnKey.current = firstTurnKey; - prependHeight.current = null; - // Growth is pinned by the resize observer below, once per layout rather than once per update. - }, [turns, firstTurnKey]); - - useLayoutEffect(() => { - const el = scroller.current; - const inner = el?.firstElementChild; - if (el === null || inner === null || inner === undefined) return; - // Runs after layout and before paint. The viewport is measured again only when the scroller - // itself resizes; content growing only needs pinning. - const observer = new ResizeObserver((entries) => { - if (!el.isConnected) return; - if (entries.some((entry) => entry.target === el)) syncTranscriptViewport(el); - if (stickToBottom.current) pinToBottom(el); - }); - observer.observe(el); - observer.observe(inner); - syncTranscriptViewport(el); - if (stickToBottom.current) pinToBottom(el); - return () => observer.disconnect(); - }, [pinToBottom, turns.length]); + const sentAgo = lastUser === undefined ? Infinity : Date.now() - lastUser.createdAt; + const follow = useFollow({ + lastUserId: lastUser?.id, + anchored: running || sentAgo < PROMPT_RECENT_MS, + // The start page's first prompt, handed over with the new session. + rise: running && turns.length === 1 && sentAgo < PROMPT_JUST_SENT_MS, + running, + inset, + anchorIndex: (promptId) => turns.findLastIndex((turn) => turn.user?.id === promptId), + }); + const { pending } = follow; + const extraData = useMemo(() => ({ running, modelName, pending }), [running, modelName, pending]); if (turns.length === 0) return ( @@ -706,67 +603,44 @@ function Transcript({

    Send a message to start the conversation.

    ); + const renderItem = ({ item, index }: LegendListRenderItemProps) => ( + + ); return ( -
    { - if (event.target !== event.currentTarget) return; - if (["ArrowUp", "PageUp", "Home"].includes(event.key) || (event.key === " " && event.shiftKey)) { - stickToBottom.current = false; - } - }} - onTouchStart={(event) => { - touchY.current = event.touches[0]?.clientY; - }} - onTouchMove={(event) => { - const next = event.touches[0]?.clientY; - if (next !== undefined && touchY.current !== undefined && next > touchY.current) { - stickToBottom.current = false; - } - touchY.current = next; - }} - onWheel={(event) => { - if (event.deltaY < 0) stickToBottom.current = false; - }} + + ref={follow.ref} + data={turns} + extraData={extraData} + keyExtractor={turnKey} + getItemType={turnType} + renderItem={renderItem} + estimatedItemSize={90} + recycleItems={false} + initialScrollAtEnd + onLoad={follow.onLoad} + {...(follow.anchoredEndSpace === undefined ? {} : { anchoredEndSpace: follow.anchoredEndSpace })} + contentInsetEndAdjustment={follow.anchoredEndSpace === undefined ? 0 : inset} + maintainScrollAtEnd={follow.maintainScrollAtEnd} + maintainScrollAtEndThreshold={1} + maintainVisibleContentPosition={MAINTAIN_VISIBLE_CONTENT_POSITION} + onStartReached={state.more ? loadOlder : undefined} onScroll={(event) => { - const el = event.currentTarget; - const nearBottom = el.scrollHeight - el.clientHeight - el.scrollTop <= 16; - if (el.scrollTop < lastScrollTop.current - 1 && !nearBottom) { - stickToBottom.current = false; - } else if (nearBottom && el.scrollTop > lastScrollTop.current) { - stickToBottom.current = true; - } - lastScrollTop.current = el.scrollTop; - setScrolled(el.scrollTop > 1); - if (state.more && el.scrollTop < 120 && prependHeight.current === null) { - // Capture just before insertion: streamed updates may arrive while the page loads. - loadOlder(() => { - prependHeight.current = el.scrollHeight; - }); - } + follow.onScroll(); + setScrolled(event.nativeEvent.contentOffset.y > 1); }} - className={`session-transcript min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-y-contain [overflow-anchor:none] ${scrolled ? "session-transcript-scrolled" : ""}`} - > -
    - {turns.map((item, index) => { - const last = index === turns.length - 1; - return ( - - ); - })} -
    -
    + tabIndex={0} + aria-label="Conversation" + className={`session-transcript min-h-0 flex-1 overflow-x-hidden overscroll-y-contain [overflow-anchor:none] ${scrolled ? "session-transcript-scrolled" : ""}`} + ListHeaderComponent={TRANSCRIPT_HEADER} + ListFooterComponent={ +
    + } + /> ); } @@ -776,7 +650,13 @@ interface Turn { readonly replies: readonly HistoryEntry[]; } -function turnsOf(entries: readonly HistoryEntry[]): Turn[] { +// Messages are the same objects unless they changed, so an unchanged turn keeps its object too. +const sameMessages = (a: Turn, b: Turn) => + a.user === b.user && + a.replies.length === b.replies.length && + a.replies.every((reply, index) => reply === b.replies[index]); + +function turnsOf(entries: readonly HistoryEntry[], previous: readonly Turn[]): Turn[] { const turns: { user: HistoryEntry | undefined; replies: HistoryEntry[] }[] = []; for (const entry of entries) { const current = turns.at(-1); @@ -785,30 +665,32 @@ function turnsOf(entries: readonly HistoryEntry[]): Turn[] { if (entry.role === "user") turn.user = entry; else turn.replies.push(entry); } + const known = new Map(previous.map((turn) => [turnKey(turn), turn])); + return turns.map((turn) => { + const old = known.get(turnKey(turn)); + return old !== undefined && sameMessages(old, turn) ? old : turn; + }); +} + +/** Turns rebuilt on every structural update, keeping the objects of those that didn't change. */ +function useTurns(messages: readonly HistoryEntry[]) { + const [state, setState] = useState(() => ({ messages, turns: turnsOf(messages, []) })); + if (state.messages === messages) return state.turns; + const turns = turnsOf(messages, state.turns); + setState({ messages, turns }); return turns; } -// Turns are rebuilt on every structural update, but their messages are the same objects unless they changed. -const sameTurn = ( - a: { - readonly turn: Turn; - readonly active: boolean; - readonly anchored: boolean; - readonly modelName: string | undefined; - }, - b: { - readonly turn: Turn; - readonly active: boolean; - readonly anchored: boolean; - readonly modelName: string | undefined; - }, -) => - a.active === b.active && - a.anchored === b.anchored && - a.modelName === b.modelName && - a.turn.user === b.turn.user && - a.turn.replies.length === b.turn.replies.length && - a.turn.replies.every((reply, index) => reply === b.turn.replies[index]); +interface TurnProps { + readonly turn: Turn; + readonly active: boolean; + /** Hidden until its prompt rises into its anchor. */ + readonly pending: boolean; + readonly modelName: string | undefined; +} + +const sameTurn = (a: TurnProps, b: TurnProps) => + a.turn === b.turn && a.active === b.active && a.pending === b.pending && a.modelName === b.modelName; /** * What the work log can show: a tool call, readable thinking, or a note between calls. Thinking a @@ -823,17 +705,7 @@ const isWork = (part: Part) => * The answer is the last reply's text; everything before it (thinking, tool calls, notes between * calls) is the work that led there, folded under one line. */ -const TurnView = memo(function TurnView({ - turn, - active, - anchored, - modelName, -}: { - readonly turn: Turn; - readonly active: boolean; - readonly anchored: boolean; - readonly modelName: string | undefined; -}) { +const TurnView = memo(function TurnView({ turn, active, pending, modelName }: TurnProps) { const last = turn.replies.at(-1); const answer = last?.parts.some((part) => part.type === "text") === true; const work = turn.replies.flatMap((reply) => @@ -853,7 +725,8 @@ const TurnView = memo(function TurnView({ return (
    {turn.user !== undefined && } {(work.length > 0 || working || answer || interrupted || failed) && ( @@ -1107,10 +980,12 @@ function WorkLog({ ) : ( <> - {expandable && ( { + * - true enables both behaviors; false disables both. + */ + maintainVisibleContentPosition?: boolean | MaintainVisibleContentPositionConfig; ++ /** ++ * T3 patch: the scroll offset a change in item or list size should leave, read in the same pass ++ * that repositions the items so the adjustment commits with them. `undefined` keeps the default. ++ */ ++ sizeChangeAnchor?: () => number | undefined; + /** + * Keeps an item visually anchored to the start by adding trailing space when the content below it underflows. + */ +diff --git a/keyboard.d.ts b/keyboard.d.ts +index 367945cdfa8a8c260b7a127657a75c016c9ab46f..0ac7bf8b8e9c386058b2374199e58fe8c92d39b3 100644 +--- a/keyboard.d.ts ++++ b/keyboard.d.ts +@@ -279,7 +279,7 @@ type KeyboardChatComposerInsetListRef = { + type KeyboardChatComposerRef = { + current: Pick | null; + }; +-declare function useKeyboardChatComposerInset(listRef: KeyboardChatComposerInsetListRef, composerRef: KeyboardChatComposerRef, initialHeight?: number): { ++declare function useKeyboardChatComposerInset(listRef: KeyboardChatComposerInsetListRef, composerRef: KeyboardChatComposerRef, initialHeight?: number, heightAdjustment?: number, animationDuration?: number): { + contentInsetEndAdjustment: SharedValue; + onComposerLayout: (event: LayoutChangeEvent) => void; + }; +@@ -288,8 +288,10 @@ declare function useKeyboardScrollToEnd({ freeze: freezeProp, listRef }: UseKeyb + scrollMessageToEnd: ({ animated, closeKeyboard }: ScrollMessageToEndOptions) => Promise; + }; + declare const KeyboardAwareLegendList: (props: Omit, "anchoredEndSpace" | "contentInsetEndAdjustment" | "renderScrollComponent"> & KeyboardChatScrollViewPropsUnique & { ++ adjustedInsetCompensation?: number; + anchoredEndSpace?: AnchoredEndSpaceConfig; + contentInsetEndAdjustment?: SharedValue; ++ contentInsetEndStaticAdjustment?: number; + keyboardOffset?: number; + } & React.RefAttributes) => React.ReactElement | null; + +diff --git a/keyboard.js b/keyboard.js +index 6645bcbb1f77c36c432035eaf8b2d6d924fc8bda..321c4c305129dd3ce3f06127c47d51720a73fb83 100644 +--- a/keyboard.js ++++ b/keyboard.js +@@ -33,19 +33,22 @@ if (typeof __DEV__ !== "undefined" && __DEV__ && !reactNativeKeyboardController. + "[legend-list] KeyboardAwareLegendList requires a recent react-native-keyboard-controller with KeyboardChatScrollView. Please upgrade react-native-keyboard-controller to at least 1.21.7." + ); + } +-function useKeyboardChatComposerInset(listRef, composerRef, initialHeight = 0) { ++function useKeyboardChatComposerInset(listRef, composerRef, initialHeight = 0, heightAdjustment = 0, animationDuration = 0) { + const contentInsetEndAdjustment = reactNativeReanimated.useSharedValue(initialHeight); + const lastHeightRef = React.useRef(void 0); + const reportHeight = React.useCallback( +- (height) => { ++ (rawHeight) => { ++ const height = Math.max(0, rawHeight + heightAdjustment); + var _a; + if (Number.isFinite(height) && height !== lastHeightRef.current) { ++ const shouldAnimate = lastHeightRef.current !== void 0 && animationDuration > 0; + lastHeightRef.current = height; +- contentInsetEndAdjustment.value = height; +- (_a = listRef.current) == null ? void 0 : _a.reportContentInset({ bottom: height }); ++ contentInsetEndAdjustment.value = shouldAnimate ? reactNativeReanimated.withTiming(height, { ++ duration: animationDuration ++ }) : height; + } + }, +- [contentInsetEndAdjustment, listRef] ++ [animationDuration, contentInsetEndAdjustment, heightAdjustment, listRef] + ); + React.useLayoutEffect(() => { + var _a; +@@ -84,9 +87,11 @@ function useKeyboardScrollToEnd({ freeze: freezeProp, listRef }) { + } + var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2(props, forwardedRef) { + const { ++ adjustedInsetCompensation, + anchoredEndSpace, + applyWorkaroundForContentInsetHitTestBug, + contentInsetEndAdjustment, ++ contentInsetEndStaticAdjustment, + freeze, + keyboardLiftBehavior, + keyboardOffset, +@@ -94,6 +99,7 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + } = props; + const refLegendList = React.useRef(null); + const combinedRef = useCombinedRef(forwardedRef, refLegendList); ++ const adjustedStartInsetCompensation = props.contentInsetStartAdjustment; + const blankSpace = reactNativeReanimated.useSharedValue(0); + React.useEffect(() => { + if (!anchoredEndSpace) { +@@ -108,11 +114,15 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + ...anchoredEndSpace, + onSizeChanged: (size) => { + var _a; +- blankSpace.value = size; ++ // The anchored blank is sized against the ADJUSTED viewport, but the ++ // scroll component writes it as a raw contentInset that UIKit tops up ++ // with the safe-area bottom — write it net of that or the end rest ++ // (and the anchored message) sinks one safe-area under the header. ++ blankSpace.value = size > 0 ? Math.max(0, size - (adjustedInsetCompensation || 0)) : 0; + (_a = anchoredEndSpace.onSizeChanged) == null ? void 0 : _a.call(anchoredEndSpace, size); + } + }; +- }, [anchoredEndSpace, blankSpace]); ++ }, [adjustedInsetCompensation, anchoredEndSpace, blankSpace]); + const onContentInsetChange = React.useCallback((insets) => { + var _a; + (_a = refLegendList.current) == null ? void 0 : _a.reportContentInset(insets); +@@ -123,6 +133,8 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + reactNativeKeyboardController.KeyboardChatScrollView, + { + ...scrollProps, ++ adjustedInsetCompensation, ++ adjustedStartInsetCompensation, + applyWorkaroundForContentInsetHitTestBug, + blankSpace, + extraContentPadding: contentInsetEndAdjustment, +@@ -134,6 +146,8 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + ); + }, + [ ++ adjustedInsetCompensation, ++ adjustedStartInsetCompensation, + applyWorkaroundForContentInsetHitTestBug, + blankSpace, + contentInsetEndAdjustment, +@@ -149,6 +163,7 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + { + anchoredEndSpace: anchoredEndSpaceWithBlankSpace, + anchoredEndSpaceOwnerInternal: "scroll", ++ contentInsetEndAdjustment: contentInsetEndStaticAdjustment, + ref: combinedRef, + renderScrollComponent: memoList, + ...rest +diff --git a/keyboard.mjs b/keyboard.mjs +index 87b38b9607c2eba6b407c2acfd520633bdb0e7c2..111eb242ba9d9ade1cb912550f7df85cf4f361ee 100644 +--- a/keyboard.mjs ++++ b/keyboard.mjs +@@ -1,7 +1,7 @@ + import * as React from 'react'; + import { useRef, useEffect, useMemo, useCallback, useLayoutEffect } from 'react'; + import { KeyboardChatScrollView, KeyboardController } from 'react-native-keyboard-controller'; +-import { useSharedValue } from 'react-native-reanimated'; ++import { useSharedValue, withTiming } from 'react-native-reanimated'; + import { internal } from '@legendapp/list/react-native'; + import { AnimatedLegendList } from '@legendapp/list/reanimated'; + +@@ -12,19 +12,22 @@ if (typeof __DEV__ !== "undefined" && __DEV__ && !KeyboardChatScrollView) { + "[legend-list] KeyboardAwareLegendList requires a recent react-native-keyboard-controller with KeyboardChatScrollView. Please upgrade react-native-keyboard-controller to at least 1.21.7." + ); + } +-function useKeyboardChatComposerInset(listRef, composerRef, initialHeight = 0) { ++function useKeyboardChatComposerInset(listRef, composerRef, initialHeight = 0, heightAdjustment = 0, animationDuration = 0) { + const contentInsetEndAdjustment = useSharedValue(initialHeight); + const lastHeightRef = useRef(void 0); + const reportHeight = useCallback( +- (height) => { ++ (rawHeight) => { ++ const height = Math.max(0, rawHeight + heightAdjustment); + var _a; + if (Number.isFinite(height) && height !== lastHeightRef.current) { ++ const shouldAnimate = lastHeightRef.current !== void 0 && animationDuration > 0; + lastHeightRef.current = height; +- contentInsetEndAdjustment.value = height; +- (_a = listRef.current) == null ? void 0 : _a.reportContentInset({ bottom: height }); ++ contentInsetEndAdjustment.value = shouldAnimate ? withTiming(height, { ++ duration: animationDuration ++ }) : height; + } + }, +- [contentInsetEndAdjustment, listRef] ++ [animationDuration, contentInsetEndAdjustment, heightAdjustment, listRef] + ); + useLayoutEffect(() => { + var _a; +@@ -63,9 +66,11 @@ function useKeyboardScrollToEnd({ freeze: freezeProp, listRef }) { + } + var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2(props, forwardedRef) { + const { ++ adjustedInsetCompensation, + anchoredEndSpace, + applyWorkaroundForContentInsetHitTestBug, + contentInsetEndAdjustment, ++ contentInsetEndStaticAdjustment, + freeze, + keyboardLiftBehavior, + keyboardOffset, +@@ -73,6 +78,7 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + } = props; + const refLegendList = useRef(null); + const combinedRef = useCombinedRef(forwardedRef, refLegendList); ++ const adjustedStartInsetCompensation = props.contentInsetStartAdjustment; + const blankSpace = useSharedValue(0); + useEffect(() => { + if (!anchoredEndSpace) { +@@ -87,11 +93,15 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + ...anchoredEndSpace, + onSizeChanged: (size) => { + var _a; +- blankSpace.value = size; ++ // The anchored blank is sized against the ADJUSTED viewport, but the ++ // scroll component writes it as a raw contentInset that UIKit tops up ++ // with the safe-area bottom — write it net of that or the end rest ++ // (and the anchored message) sinks one safe-area under the header. ++ blankSpace.value = size > 0 ? Math.max(0, size - (adjustedInsetCompensation || 0)) : 0; + (_a = anchoredEndSpace.onSizeChanged) == null ? void 0 : _a.call(anchoredEndSpace, size); + } + }; +- }, [anchoredEndSpace, blankSpace]); ++ }, [adjustedInsetCompensation, anchoredEndSpace, blankSpace]); + const onContentInsetChange = useCallback((insets) => { + var _a; + (_a = refLegendList.current) == null ? void 0 : _a.reportContentInset(insets); +@@ -102,6 +112,8 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + KeyboardChatScrollView, + { + ...scrollProps, ++ adjustedInsetCompensation, ++ adjustedStartInsetCompensation, + applyWorkaroundForContentInsetHitTestBug, + blankSpace, + extraContentPadding: contentInsetEndAdjustment, +@@ -113,6 +125,8 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + ); + }, + [ ++ adjustedInsetCompensation, ++ adjustedStartInsetCompensation, + applyWorkaroundForContentInsetHitTestBug, + blankSpace, + contentInsetEndAdjustment, +@@ -128,6 +142,7 @@ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2( + { + anchoredEndSpace: anchoredEndSpaceWithBlankSpace, + anchoredEndSpaceOwnerInternal: "scroll", ++ contentInsetEndAdjustment: contentInsetEndStaticAdjustment, + ref: combinedRef, + renderScrollComponent: memoList, + ...rest +diff --git a/react-native.d.ts b/react-native.d.ts +index ce1fe00001c9e5aee6c6ea8bb2d4757d4586d002..ca6e596aa53327a097a388ffd545a4c6191f24e6 100644 +--- a/react-native.d.ts ++++ b/react-native.d.ts +@@ -284,6 +284,11 @@ interface LegendListSpecificProps { + * - true enables both behaviors; false disables both. + */ + maintainVisibleContentPosition?: boolean | MaintainVisibleContentPositionConfig; ++ /** ++ * T3 patch: the scroll offset a change in item or list size should leave, read in the same pass ++ * that repositions the items so the adjustment commits with them. `undefined` keeps the default. ++ */ ++ sizeChangeAnchor?: () => number | undefined; + /** + * Keeps an item visually anchored to the start by adding trailing space when the content below it underflows. + */ +@@ -293,6 +298,12 @@ interface LegendListSpecificProps { + * The adjustment is also rendered as real content padding so the browser scroll range includes it. + */ + contentInsetEndAdjustment?: number; ++ /** ++ * Width/height of a leading content inset applied natively outside the list's knowledge ++ * (e.g. iOS contentInsetAdjustmentBehavior="automatic" under a transparent header). ++ * Programmatic scrolls clamp to -adjustment instead of 0 so content can rest below the header. ++ */ ++ contentInsetStartAdjustment?: number; + /** + * Number of columns to render items in. + * @default 1 +diff --git a/react-native.js b/react-native.js +index b3c5a306b293f797a8b338adfca3060c0f6db22b..d7f59b63cd4982dfc9c347732caa77e0974864df 100644 +--- a/react-native.js ++++ b/react-native.js +@@ -717,6 +717,15 @@ function hasActiveInitialScroll(state) { + return !!(state == null ? void 0 : state.initialScroll) && !state.didFinishInitialScroll; + } + ++// Size-only changes may not emit a scroll event to refresh the edge signal. ++function getIsAtEnd(ctx, contentSize = getContentSize(ctx)) { ++ const { queuedInitialLayout, scroll, scrollLength } = ctx.state; ++ if (!(contentSize > 0 && queuedInitialLayout)) { ++ return peek$(ctx, "isAtEnd"); ++ } ++ return contentSize < scrollLength || contentSize - scroll - scrollLength - getContentInsetEnd(ctx) <= EDGE_POSITION_EPSILON; ++} ++ + // src/utils/checkAtBottom.ts + function checkAtBottom(ctx, allowedEdge, allowGateCreatedInCurrentCheck) { + var _a3; +@@ -737,7 +746,7 @@ function checkAtBottom(ctx, allowedEdge, allowGateCreatedInCurrentCheck) { + const insetEnd = getContentInsetEnd(ctx); + const distanceFromEnd = contentSize - scroll - scrollLength - insetEnd; + const isContentLess = contentSize < scrollLength; +- set$(ctx, "isAtEnd", isContentLess || distanceFromEnd <= EDGE_POSITION_EPSILON); ++ set$(ctx, "isAtEnd", getIsAtEnd(ctx, contentSize)); + set$(ctx, "isNearEnd", isContentLess || distanceFromEnd <= onEndReachedThreshold * scrollLength); + set$( + ctx, +@@ -954,7 +963,16 @@ function setInitialRenderState(ctx, { + if (didInitialScroll) { + state.didFinishInitialScroll = true; + } +- const isReadyToRender = Boolean(state.didContainersLayout && state.didFinishInitialScroll); ++ // Native contentOffset can seed an end target without dispatchInitialScroll. ++ // Both overflow completion paths must wait for the native end landing. ++ // Underflow needs no scroll: preserve UIKit's untouched resting position. ++ if (state.didContainersLayout && state.didFinishInitialScroll && state.initialScroll && state.initialScroll.viewPosition === 1 && state.initialScroll.index === state.props.data.length - 1 && state.props.data.length > 0) { ++ const insetStartAdjustment = getContentInsetStartAdjustment(ctx); ++ if (insetStartAdjustment > 0 && getContentSize(ctx) > state.scrollLength - insetStartAdjustment + 1) { ++ startInsetEndSettleWatchdog(ctx); ++ } ++ } ++ const isReadyToRender = Boolean(state.didContainersLayout && state.didFinishInitialScroll && !state.insetEndRevealHold); + if (isReadyToRender && !peek$(ctx, "readyToRender")) { + set$(ctx, "readyToRender", true); + setAdaptiveRender(ctx, "normal", "ready"); +@@ -1090,7 +1108,7 @@ function getRawContentLength(ctx) { + function getAlignItemsAtEndPadding(ctx) { + const { state } = ctx; + const shouldPad = !!state.props.alignItemsAtEndPaddingEnabled && !state.props.horizontal && state.props.data.length > 0 && state.scrollLength > 0; +- return shouldPad ? Math.max(0, state.scrollLength - getRawContentLength(ctx) - getContentInsetEnd(ctx)) : 0; ++ return shouldPad ? Math.max(0, state.scrollLength - getContentInsetStartAdjustment(ctx) - getRawContentLength(ctx) - getContentInsetEnd(ctx)) : 0; + } + function updateContentMetricsState(ctx) { + const previousPadding = peek$(ctx, "alignItemsAtEndPadding") || 0; +@@ -1115,6 +1133,10 @@ function addTotalSize(ctx, key, add, notifyTotalSize = true) { + totalSize += add; + } + if (prevTotalSize !== totalSize) { ++ const now = Date.now(); ++ const isContinuingContentSizeAnimation = state.contentSizeAnimationActiveEpoch !== void 0; ++ state.contentSizeAnimationEpoch = (state.contentSizeAnimationEpoch || 0) + 1; ++ state.contentSizeAnimationEligible = !!state.props.sizeComponentInternal && state.didContainersLayout && (isContinuingContentSizeAnimation || !state.props.maintainScrollAtEnd && !state.isUserDragging && !state.isMomentumScrolling && now - (state.lastMVCPAdjustTime || 0) >= 300); + if (!IsNewArchitecture && state.initialScroll && totalSize < prevTotalSize) { + state.pendingTotalSize = totalSize; + } else { +@@ -1304,18 +1326,23 @@ function calculateOffsetWithOffsetPosition(ctx, offsetParam, params) { + } + + // src/core/clampScrollOffset.ts ++function getContentInsetStartAdjustment(ctx) { ++ const adjustment = ctx.state.props.contentInsetStartAdjustment; ++ return typeof adjustment === "number" && Number.isFinite(adjustment) ? Math.max(0, adjustment) : 0; ++} + function clampScrollOffset(ctx, offset, scrollTarget) { + const state = ctx.state; + const contentSize = getContentSize(ctx); ++ const minOffset = -getContentInsetStartAdjustment(ctx); + let clampedOffset = offset; + if (Number.isFinite(contentSize) && Number.isFinite(state.scrollLength) && (Platform.OS !== "android" || state.lastLayout)) { +- const baseMaxOffset = Math.max(0, contentSize - state.scrollLength); ++ const baseMaxOffset = Math.max(minOffset, contentSize - state.scrollLength); + const viewOffset = scrollTarget == null ? void 0 : scrollTarget.viewOffset; + const extraEndOffset = typeof viewOffset === "number" && viewOffset < 0 ? -viewOffset : 0; + const maxOffset = baseMaxOffset + extraEndOffset; + clampedOffset = Math.min(offset, maxOffset); + } +- clampedOffset = Math.max(0, clampedOffset); ++ clampedOffset = Math.max(minOffset, clampedOffset); + return clampedOffset; + } + +@@ -1451,10 +1478,10 @@ function checkFinishedScrollFrame(ctx) { + finishScrollTo(ctx); + } + } +-function scrollToFallbackOffset(ctx, offset) { ++function scrollToFallbackOffset(ctx, offset, animated) { + var _a3; + (_a3 = ctx.state.refScroller.current) == null ? void 0 : _a3.scrollTo({ +- animated: false, ++ animated: !!animated, + x: ctx.state.props.horizontal ? offset : 0, + y: ctx.state.props.horizontal ? 0 : offset + }); +@@ -1503,7 +1530,10 @@ function checkFinishedScrollFallback(ctx) { + ); + scheduleFallbackCheck(SILENT_INITIAL_SCROLL_RETRY_DELAY_MS); + } else if (shouldRetryUnalignedEndScroll) { +- scrollToFallbackOffset(ctx, completionState.clampedTargetOffset); ++ const isActivelyAnimatingToEnd = !!isStillScrollingTo.animated && Date.now() - state.scrollTime < 100; ++ if (!isActivelyAnimatingToEnd) { ++ scrollToFallbackOffset(ctx, completionState.clampedTargetOffset, !!isStillScrollingTo.animated); ++ } + scheduleFallbackCheck(100); + } else if (shouldFinishZeroTarget || shouldFinishAfterObservedScroll || canFinishInitialScrollWithoutNativeProgress || canFinishAfterSilentNativeDispatch || numChecks > maxChecks) { + finishScrollTo(ctx); +@@ -1560,15 +1590,33 @@ function doMaintainScrollAtEnd(ctx) { + } = state; + const isWithinMaintainScrollAtEndThreshold = peek$(ctx, "isWithinMaintainScrollAtEndThreshold"); + const shouldMaintainScrollAtEnd = !!(isWithinMaintainScrollAtEndThreshold && maintainScrollAtEnd && didContainersLayout); ++ if (state.contentSizeAnimationActiveEpoch !== void 0) { ++ state.pendingMaintainScrollAtEnd = false; ++ return false; ++ } + if (pendingNativeMVCPAdjust) { + state.pendingMaintainScrollAtEnd = shouldMaintainScrollAtEnd; + return false; + } ++ // T3 patch: a caller anchor already placed this pass's offset; a later scroll would move it. ++ if (state.props.sizeChangeAnchor && !state.mvcpDataChanged && state.props.sizeChangeAnchor() !== void 0) { ++ state.pendingMaintainScrollAtEnd = false; ++ return shouldMaintainScrollAtEnd; ++ } + if (shouldMaintainScrollAtEnd) { + state.pendingMaintainScrollAtEnd = false; ++ const maintainAnchoredEndSpace = state.props.anchoredEndSpace; ++ const maintainAnchorIndex = maintainAnchoredEndSpace == null ? void 0 : maintainAnchoredEndSpace.anchorIndex; ++ if (maintainAnchorIndex !== void 0 && maintainAnchorIndex >= 0 && maintainAnchorIndex < state.props.data.length && !areKnownOrFixedItemSizesAvailable(ctx, maintainAnchorIndex, state.props.data.length - 1)) { ++ return false; ++ } + const contentSize = getContentSize(ctx); ++ const maintainInsetStartAdjustment = getContentInsetStartAdjustment(ctx); + if (contentSize < state.scrollLength) { +- state.scroll = 0; ++ state.scroll = -maintainInsetStartAdjustment; ++ if (maintainInsetStartAdjustment > 0) { ++ return true; ++ } + } + if (!state.maintainingScrollAtEnd) { + const pendingState = maintainScrollAtEnd.animated ? "pending-animated" : "pending-instant"; +@@ -1591,9 +1639,18 @@ function doMaintainScrollAtEnd(ctx) { + y: 0 + }); + } else { +- scroller == null ? void 0 : scroller.scrollToEnd({ +- animated: maintainScrollAtEnd.animated +- }); ++ const insetStartAdjustment = getContentInsetStartAdjustment(ctx); ++ if (insetStartAdjustment > 0) { ++ scroller == null ? void 0 : scroller.scrollTo({ ++ animated: maintainScrollAtEnd.animated, ++ x: 0, ++ y: Math.max(-insetStartAdjustment, getContentSize(ctx) - state.scrollLength) ++ }); ++ } else { ++ scroller == null ? void 0 : scroller.scrollToEnd({ ++ animated: maintainScrollAtEnd.animated ++ }); ++ } + } + setTimeout( + () => { +@@ -1624,6 +1681,10 @@ function doMaintainScrollAtEnd(ctx) { + function requestAdjust(ctx, positionDiff, dataChanged) { + const state = ctx.state; + if (Math.abs(positionDiff) > 0.1) { ++ // Timestamp for ReanimatedPositionView: repositions caused by an MVCP ++ // size adjustment are already compensated by a contentOffset shift, so ++ // animating them would make rows visibly lurch and slide back. ++ state.lastMVCPAdjustTime = Date.now(); + const needsScrollWorkaround = Platform.OS === "android" && !IsNewArchitecture && dataChanged && state.scroll <= positionDiff; + const doit = () => { + if (needsScrollWorkaround) { +@@ -1728,7 +1789,9 @@ function getPredictedNativeClamp(state, unresolvedAmount, totalSize) { + if (Math.abs(unresolvedAmount) <= MVCP_POSITION_EPSILON) { + return 0; + } +- const maxScroll = Math.max(0, totalSize - state.scrollLength); ++ const insetStartAdjustment = state.props.contentInsetStartAdjustment; ++ const minScroll = typeof insetStartAdjustment === "number" && Number.isFinite(insetStartAdjustment) ? -Math.max(0, insetStartAdjustment) : 0; ++ const maxScroll = Math.max(minScroll, totalSize - state.scrollLength); + const clampDelta = maxScroll - state.scroll; + if (unresolvedAmount < 0) { + return Math.max(unresolvedAmount, Math.min(0, clampDelta)); +@@ -1790,7 +1853,7 @@ function resolvePendingNativeMVCPAdjust(ctx, newScroll) { + settlePendingNativeMVCPAdjust(ctx, remainingAfterManual, nativeDelta); + return true; + } +- const expectedNativeClampScroll = Math.max(0, getContentSize(ctx) - state.scrollLength); ++ const expectedNativeClampScroll = Math.max(-getContentInsetStartAdjustment(ctx), getContentSize(ctx) - state.scrollLength); + const distanceToClamp = Math.abs(newScroll - expectedNativeClampScroll); + const isAtExpectedNativeClamp = distanceToClamp <= NATIVE_END_CLAMP_EPSILON; + if (isAtExpectedNativeClamp) { +@@ -1811,7 +1874,35 @@ function resolvePendingNativeMVCPAdjust(ctx, newScroll) { + } + return false; + } ++// T3 patch: a caller anchor decides where a size change leaves the scroll position. It is read in ++// the same pass that repositions the items, so the adjustment commits with the new positions. + function prepareMVCP(ctx, dataChanged) { ++ // T3 patch: a data change skips the caller anchor, so end maintenance must still run after it. ++ ctx.state.mvcpDataChanged = !!dataChanged; ++ const sizeChangeAnchor = dataChanged ? void 0 : ctx.state.props.sizeChangeAnchor; ++ const restore = prepareDefaultMVCP(ctx, dataChanged); ++ if (!sizeChangeAnchor || ctx.state.scrollingTo !== void 0) { ++ return restore; ++ } ++ return () => { ++ const target = sizeChangeAnchor(); ++ if (target === void 0) { ++ restore == null ? void 0 : restore(); ++ return; ++ } ++ // Content that shrinks under an offset past its new end pulls the native offset back to ++ // that end by itself; only the rest of the way to the target is adjusted. ++ const endOffset = clampScrollOffset(ctx, Number.POSITIVE_INFINITY); ++ if (ctx.state.scroll > endOffset) { ++ ctx.state.scroll = endOffset; ++ } ++ const positionDiff = clampScrollOffset(ctx, target) - ctx.state.scroll; ++ if (Math.abs(positionDiff) > MVCP_POSITION_EPSILON) { ++ requestAdjust(ctx, positionDiff, false); ++ } ++ }; ++} ++function prepareDefaultMVCP(ctx, dataChanged) { + const state = ctx.state; + const { idsInView, positions, props } = state; + const { +@@ -1923,7 +2014,7 @@ function prepareMVCP(ctx, dataChanged) { + if (diff > 0) { + diff = Math.max(0, totalSize - state.scroll - state.scrollLength); + } else { +- const maxScroll = Math.max(0, totalSize - state.scrollLength); ++ const maxScroll = Math.max(-getContentInsetStartAdjustment(ctx), totalSize - state.scrollLength); + state.scroll = maxScroll; + state.scrollPending = maxScroll; + diff = 0; +@@ -2320,8 +2411,121 @@ function scrollToIndex(ctx, { + } + + // src/core/initialScroll.ts ++var INSET_END_SETTLE_WATCHDOG_FRAMES = 150; ++var INSET_END_SETTLE_WATCHDOG_STABLE_FRAMES = 20; ++var INSET_END_REVEAL_STABLE_FRAMES = 3; ++var INSET_END_REVEAL_MAX_HOLD_FRAMES = 40; ++function startInsetEndSettleWatchdog(ctx) { ++ const state = ctx.state; ++ if (state.insetEndSettleWatchdogStarted || state.didLoad) { ++ return; ++ } ++ state.insetEndSettleWatchdogStarted = true; ++ state.insetEndSettleWatchdogActive = true; ++ // Hold the readyToRender opacity gate until the end landing is stable, so ++ // the estimated-to-measured settle chase happens before first VISIBLE ++ // paint instead of in front of the user. Capped so slow measurement can ++ // never hide content for long. ++ state.insetEndRevealHold = true; ++ let frames = 0; ++ let settledFrames = 0; ++ let revealStableFrames = 0; ++ let previousEndOffset; ++ const releaseRevealHold = () => { ++ if (state.insetEndRevealHold) { ++ state.insetEndRevealHold = false; ++ setInitialRenderState(ctx, {}); ++ } ++ }; ++ // Revealing flips adaptive rendering to "normal", which re-renders rows and ++ // can move the end target one more time — do that upgrade while still ++ // hidden (phase 1), then require stability again before revealing (phase 2) ++ // so the first visible frame is the settled one. ++ let revealPhase = 1; ++ const onRevealStability = () => { ++ var _a3; ++ if (!state.insetEndRevealHold) { ++ return; ++ } ++ if (revealPhase === 1) { ++ revealPhase = 2; ++ revealStableFrames = 0; ++ setAdaptiveRender(ctx, "normal"); ++ (_a3 = state.triggerCalculateItemsInView) == null ? void 0 : _a3.call(state); ++ return; ++ } ++ releaseRevealHold(); ++ }; ++ const tick = () => { ++ // The user owns the scroll from their first drag — a re-pin here would ++ // pin the list under their finger. ++ if (frames++ >= INSET_END_SETTLE_WATCHDOG_FRAMES || settledFrames >= INSET_END_SETTLE_WATCHDOG_STABLE_FRAMES || state.didUserDrag || !ctx.state || ctx.state !== state) { ++ state.insetEndSettleWatchdogActive = false; ++ releaseRevealHold(); ++ return; ++ } ++ if (frames >= INSET_END_REVEAL_MAX_HOLD_FRAMES) { ++ releaseRevealHold(); ++ } ++ const insetStartAdjustment = getContentInsetStartAdjustment(ctx); ++ const contentSize = getContentSize(ctx); ++ const scrollLength = state.scrollLength; ++ const endOffset = Math.max(-insetStartAdjustment, contentSize - scrollLength); ++ // state.scroll is optimistic: non-animated scrollTo writes it before UIKit ++ // moves. Only a native scroll event proves that the requested offset landed. ++ const nativeOffset = state.lastNativeScroll; ++ const hasNativeOffset = typeof nativeOffset === "number" && Number.isFinite(nativeOffset); ++ const distance = hasNativeOffset ? endOffset - nativeOffset : Infinity; ++ const isIdle = !state.scrollingTo && !state.maintainingScrollAtEnd; ++ const hasViewport = insetStartAdjustment > 0 && scrollLength > 0 && Number.isFinite(contentSize); ++ const isStable = hasViewport && isIdle && Math.abs(distance) <= 2 && previousEndOffset !== void 0 && Math.abs(endOffset - previousEndOffset) <= 1; ++ previousEndOffset = endOffset; ++ if (isStable) { ++ settledFrames++; ++ revealStableFrames++; ++ if (revealStableFrames >= INSET_END_REVEAL_STABLE_FRAMES) { ++ onRevealStability(); ++ } ++ } else { ++ settledFrames = 0; ++ revealStableFrames = 0; ++ // Keep the existing near-end correction limit. In-flight scrolls and ++ // unknown native offsets wait; neither counts as a settled frame. ++ if (hasViewport && isIdle && Math.abs(distance) > 2 && Math.abs(distance) <= scrollLength * 0.5) { ++ const scroller = state.refScroller.current; ++ if (scroller) { ++ scroller.scrollTo({ animated: false, x: 0, y: endOffset }); ++ } ++ } ++ } ++ requestAnimationFrame(tick); ++ }; ++ requestAnimationFrame(tick); ++} + function dispatchInitialScroll(ctx, params) { + const { forceScroll, resolvedOffset, target, waitForCompletionFrame } = params; ++ const insetStartAdjustment = getContentInsetStartAdjustment(ctx); ++ if (insetStartAdjustment > 0 && ctx.state.props.data.length > 0) { ++ if (ctx.state.scrollLength <= 0) { ++ // The scroll length is unknown, so the resolved target is meaningless; ++ // the initial-scroll machinery re-advances after layout. ++ return; ++ } ++ if (resolvedOffset <= -insetStartAdjustment + 1 && !ctx.state.didDispatchInsetInitialScroll) { ++ // Content underflows the viewport and nothing has scrolled yet: the ++ // untouched native rest position (UIKit's adjustedContentInset) IS the ++ // end position. Dispatching a negative scroll here would race UIKit's ++ // inset application during screen attach, so just finish the session. ++ finishInitialScroll(ctx, { ++ resolvedOffset ++ }); ++ return; ++ } ++ ctx.state.didDispatchInsetInitialScroll = true; ++ if (target.viewPosition === 1) { ++ startInsetEndSettleWatchdog(ctx); ++ } ++ } + const requestedIndex = target.index; + const index = requestedIndex !== void 0 ? clampScrollIndex(requestedIndex, ctx.state.props.data.length) : void 0; + const itemSize = getItemSizeAtIndex(ctx, index); +@@ -2747,7 +2951,9 @@ function clearFinishedBootstrapInitialScrollTargetIfMovedAway(ctx) { + return; + } + if (didFinishedInitialScrollMoveAwayFromTarget(ctx, initialScroll)) { +- const shouldKeepEndTargetAlive = isRetargetableBottomAlignedInitialScrollTarget(initialScroll) && peek$(ctx, "isAtEnd"); ++ const endTargetDistanceFromEnd = getContentSize(ctx) - state.scroll - state.scrollLength - getContentInsetEnd(ctx); ++ const isNearEndForInsetList = getContentInsetStartAdjustment(ctx) > 0 && Number.isFinite(endTargetDistanceFromEnd) && endTargetDistanceFromEnd <= state.scrollLength * 0.5; ++ const shouldKeepEndTargetAlive = isRetargetableBottomAlignedInitialScrollTarget(initialScroll) && (peek$(ctx, "isAtEnd") || !state.didUserDrag && isNearEndForInsetList); + if (!shouldKeepEndTargetAlive) { + if (shouldPreserveInitialScrollForFooterLayout(initialScroll)) { + clearPendingInitialScrollFooterLayout(ctx, { +@@ -4672,7 +4878,8 @@ function maybeUpdateAnchoredEndSpace(ctx) { + contentBelowAnchor = Math.max(0, contentBelowAnchor - ctx.scrollAxisGap); + contentBelowAnchor += (ctx.values.get("footerSize") || 0) + getStylePaddingEnd(state.props); + isReady = !hasUnknownTailSize; +- nextSize = hasUnknownTailSize ? previousSize || 0 : Math.max(0, state.scrollLength - contentBelowAnchor - anchorOffset); ++ const knownSizeBound = Math.max(0, state.scrollLength - contentBelowAnchor - anchorOffset); ++ nextSize = hasUnknownTailSize ? Math.min(previousSize || 0, knownSizeBound) : knownSizeBound; + } else if (anchorIndex >= 0) { + isReady = false; + } +@@ -4692,6 +4899,12 @@ function maybeUpdateAnchoredEndSpace(ctx) { + updateScroll(ctx, state.scroll, true, { markHasScrolled: false }); + } + (_b = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onReady) == null ? void 0 : _b.call(anchoredEndSpace, { anchorIndex: nextAnchorIndex, anchorKey: nextAnchorKey, size: nextSize }); ++ } else if (!isReady && didSizeChange && nextSize < (previousSize || 0)) { ++ set$(ctx, "anchoredEndSpaceSize", nextSize); ++ (_a3 = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onSizeChanged) == null ? void 0 : _a3.call(anchoredEndSpace, nextSize); ++ if (anchoredEndSpace == null ? void 0 : anchoredEndSpace.includeInEndInset) { ++ updateScroll(ctx, state.scroll, true, { markHasScrolled: false }); ++ } + } + return nextSize; + } +@@ -5715,8 +5928,11 @@ var ContainersLayer = typedMemo(function ContainersLayer2({ + horizontal + }) { + const ctx = useStateContext(); ++ const SizeComponent = ctx.state.props.sizeComponentInternal; + const columnWrapperStyle = ctx.columnWrapperStyle; +- const animSize = useValue$("totalSize"); ++ // T3 patch: on the new architecture an animated value commits on its own, ahead of the item ++ // positions and their scroll compensation; a rendered size commits with them. ++ const animSize = IsNewArchitecture ? useArr$(["totalSize"])[0] || 0 : useValue$("totalSize"); + const [readyToRender, numColumns, otherAxisSize = 0] = useArr$(["readyToRender", "numColumns", "otherAxisSize"]); + const isVisible = useFreshDataTransitionVisibility(!!readyToRender, freshDataTransitionEpoch); + const style = horizontal ? { +@@ -5725,6 +5941,13 @@ var ContainersLayer = typedMemo(function ContainersLayer2({ + opacity: isVisible ? 1 : 0, + width: animSize + } : { height: animSize, minWidth: otherAxisSize, opacity: isVisible ? 1 : 0 }; ++ if (SizeComponent) { ++ if (horizontal) { ++ delete style.width; ++ } else { ++ delete style.height; ++ } ++ } + if (columnWrapperStyle) { + const { columnGap, rowGap, gap } = columnWrapperStyle; + const gapX = columnGap || gap || 0; +@@ -5745,7 +5968,8 @@ var ContainersLayer = typedMemo(function ContainersLayer2({ + } + } + } +- return /* @__PURE__ */ React2__namespace.createElement(ReactNative.Animated.View, { pointerEvents: isVisible ? void 0 : "none", style }, /* @__PURE__ */ React2__namespace.createElement(ContainerLayoutCoordinator, null, children)); ++ const content = /* @__PURE__ */ React2__namespace.createElement(ContainerLayoutCoordinator, null, children); ++ return SizeComponent ? /* @__PURE__ */ React2__namespace.createElement(SizeComponent, { horizontal, pointerEvents: isVisible ? void 0 : "none", signalName: "totalSize", style }, content) : /* @__PURE__ */ React2__namespace.createElement(ReactNative.Animated.View, { pointerEvents: isVisible ? void 0 : "none", style }, content); + }); + var Containers = typedMemo(function Containers2({ + freshDataTransitionEpoch, +@@ -5896,7 +6120,12 @@ var StyleSheet = ReactNative.StyleSheet; + + // src/components/ListComponent.tsx + var AlignItemsAtEndSpacer = typedMemo(function AlignItemsAtEndSpacer2({ horizontal }) { ++ const ctx = useStateContext(); + const [alignItemsAtEndPadding = 0] = useArr$(["alignItemsAtEndPadding"]); ++ const SizeComponent = ctx.state.props.sizeComponentInternal; ++ if (SizeComponent) { ++ return /* @__PURE__ */ React2__namespace.createElement(SizeComponent, { horizontal, signalName: "alignItemsAtEndPadding", style: { flexShrink: 0 } }); ++ } + if (alignItemsAtEndPadding <= 0) { + return null; + } +@@ -5929,8 +6158,12 @@ var ListComponent = typedMemo(function ListComponent2({ + refScrollView, + renderScrollComponent, + onLayoutFooter, ++ onInternalMomentumScrollBegin, + onInternalScrollBeginDrag, ++ onInternalScrollEndDrag, + onInternalScrollEnd, ++ onMomentumScrollBegin, ++ onScrollEndDrag, + scrollAdjustHandler, + snapToIndices, + stickyHeaderConfig, +@@ -6001,7 +6234,17 @@ var ListComponent = typedMemo(function ListComponent2({ + SnapOrScroll, + { + ...rest, +- ...Platform.OS === "web" ? ScrollComponent === ListComponentScrollView ? { onInternalScrollEnd, useWindowScroll } : {} : { onScrollBeginDrag: onInternalScrollBeginDrag }, ++ ...Platform.OS === "web" ? ScrollComponent === ListComponentScrollView ? { onInternalScrollEnd, useWindowScroll } : {} : { ++ onMomentumScrollBegin: (event) => { ++ onInternalMomentumScrollBegin == null ? void 0 : onInternalMomentumScrollBegin(event); ++ onMomentumScrollBegin == null ? void 0 : onMomentumScrollBegin(event); ++ }, ++ onScrollBeginDrag: onInternalScrollBeginDrag, ++ onScrollEndDrag: (event) => { ++ onInternalScrollEndDrag == null ? void 0 : onInternalScrollEndDrag(event); ++ onScrollEndDrag == null ? void 0 : onScrollEndDrag(event); ++ } ++ }, + contentContainerStyle: [ + horizontal ? { height: "100%" } : {}, + contentContainerStyle, +@@ -6010,7 +6253,10 @@ var ListComponent = typedMemo(function ListComponent2({ + ], + contentOffset: initialContentOffset !== void 0 ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0, + horizontal, +- maintainVisibleContentPosition: maintainVisibleContentPosition.size || maintainVisibleContentPosition.data ? { minIndexForVisible: 0 } : void 0, ++ // Keep iOS anchored to ScrollAdjust even when JS position restoration is ++ // disabled. Re-enabling native MVCP mid-drag can compare its stale anchor ++ // with the 1e7 sentinel and scroll the entire list out of view. ++ maintainVisibleContentPosition: Platform.OS === "ios" || maintainVisibleContentPosition.size || maintainVisibleContentPosition.data ? { minIndexForVisible: 0 } : void 0, + onLayout, + onScroll: onScroll2, + ref: refScrollView, +@@ -6267,7 +6513,8 @@ function handleLayout(ctx, layoutParam, setCanRender) { + if (scrollLength > 0) { + doInitialAllocateContainers(ctx); + } +- if (needsCalculate) { ++ // T3 patch: a shorter list keeps a caller anchor too, such as the end. ++ if (needsCalculate || state.props.sizeChangeAnchor) { + calculateItemsInView(ctx, { doMVCP: true }); + } + if (didChange || otherAxisSize !== prevOtherAxisSize) { +@@ -6751,7 +6998,7 @@ function createImperativeHandle(ctx, scheduleImperativeScrollCommit) { + endBuffered: state.endBuffered, + getAverageItemSizes: () => getAverageItemSizes(state), + indexByKey: (key) => state.indexByKey.get(key), +- isAtEnd: peek$(ctx, "isAtEnd"), ++ isAtEnd: getIsAtEnd(ctx), + isAtStart: peek$(ctx, "isAtStart"), + isEndReached: state.isEndReached, + isNearEnd: peek$(ctx, "isNearEnd"), +@@ -7075,6 +7322,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + dataVersion, + drawDistance = 250, + contentInsetEndAdjustment, ++ contentInsetStartAdjustment, + estimatedItemSize = 100, + estimatedListSize, + extraData, +@@ -7096,6 +7344,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + maintainScrollAtEnd = false, + maintainScrollAtEndThreshold = 0.1, + maintainVisibleContentPosition: maintainVisibleContentPositionProp, ++ sizeChangeAnchor, + numColumns: numColumnsProp = 1, + overrideItemLayout, + onEndReached, +@@ -7132,10 +7381,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + const animatedPropsInternal = props.animatedPropsInternal; + const anchoredEndSpaceOwner = (_a3 = props.anchoredEndSpaceOwnerInternal) != null ? _a3 : "list"; + const positionComponentInternal = props.positionComponentInternal; ++ const sizeComponentInternal = props.sizeComponentInternal; + const stickyPositionComponentInternal = props.stickyPositionComponentInternal; + const { + anchoredEndSpaceOwnerInternal: _anchoredEndSpaceOwnerInternal, + positionComponentInternal: _positionComponentInternal, ++ sizeComponentInternal: _sizeComponentInternal, + stickyPositionComponentInternal: _stickyPositionComponentInternal, + ...restProps + } = rest; +@@ -7200,7 +7451,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + const combinedRef = useCombinedRef(refScroller, refScrollView); + const keyExtractor = keyExtractorProp != null ? keyExtractorProp : ((_item, index) => index.toString()); + const stickyHeaderIndices = stickyHeaderIndicesProp; +- const contentInsetEndAdjustmentResolved = Platform.OS === "web" ? contentInsetEndAdjustment : void 0; ++ const contentInsetEndAdjustmentResolved = contentInsetEndAdjustment; + const previousContentInsetEndAdjustmentRef = React2.useRef(contentInsetEndAdjustmentResolved); + const alwaysRenderIndices = React2.useMemo(() => { + const indices = getAlwaysRenderIndices(alwaysRender, dataProp, keyExtractor, anchoredEndSpace == null ? void 0 : anchoredEndSpace.anchorIndex); +@@ -7341,6 +7592,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + contentContainerAlignItems: contentContainerStyle.alignItems, + contentInset, + contentInsetEndAdjustment: contentInsetEndAdjustmentResolved, ++ contentInsetStartAdjustment, + data: dataProp, + dataKey, + dataVersion, +@@ -7354,6 +7606,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + maintainScrollAtEnd: maintainScrollAtEndConfig, + maintainScrollAtEndThreshold, + maintainVisibleContentPosition: maintainVisibleContentPositionConfig, ++ sizeChangeAnchor, + numColumns: numColumnsProp, + onEndReached, + onEndReachedThreshold, +@@ -7372,6 +7625,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + renderItem, + rtl, + snapToIndices, ++ sizeComponentInternal, + stickyHeaderIndicesArr: stickyHeaderIndices != null ? stickyHeaderIndices : [], + stickyHeaderIndicesSet: React2.useMemo(() => new Set(stickyHeaderIndices != null ? stickyHeaderIndices : []), [stickyHeaderIndices == null ? void 0 : stickyHeaderIndices.join(",")]), + stickyPositionComponentInternal, +@@ -7423,6 +7677,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + return void 0; + } + const resolvedOffset = (_a4 = initialScroll.contentOffset) != null ? _a4 : resolveInitialScrollOffset(ctx, initialScroll); ++ if (getContentInsetStartAdjustment(ctx) > 0) { ++ // With a native leading inset (transparent header + automatic insets), ++ // any mount-time contentOffset races UIKit's adjustedContentInset ++ // application. The gated initial-scroll dispatch positions the list once ++ // real sizes are known instead. ++ return void 0; ++ } + return usesBootstrapInitialScroll && ((_b2 = state.initialScrollSession) == null ? void 0 : _b2.kind) === "bootstrap" && Platform.OS === "web" ? void 0 : resolvedOffset; + }, [usesBootstrapInitialScroll]); + React2.useLayoutEffect(() => { +@@ -7547,6 +7808,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + [ + dataKey, + dataVersion, ++ contentInsetStartAdjustment, + memoizedLastItemKeys.join(","), + numColumnsProp, + nextScrollAxisGap, +@@ -7643,6 +7905,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + () => ({ + getRenderedItem: (key) => getRenderedItem(ctx, key), + onMomentumScrollEnd: (event) => { ++ state.isMomentumScrolling = false; + checkFinishedScrollFallback(ctx); + if (state.props.onMomentumScrollEnd) { + state.props.onMomentumScrollEnd(event); +@@ -7651,6 +7914,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + onScroll: (event) => onScroll(ctx, event), + onScrollBeginDrag: (event) => { + var _a4, _b2; ++ ctx.state.didUserDrag = true; ++ ctx.state.isUserDragging = true; + prepareReachedEdgeForNextUserScroll(ctx); + (_b2 = (_a4 = state.props).onScrollBeginDrag) == null ? void 0 : _b2.call(_a4, event); + }, +@@ -7676,11 +7941,18 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + ListFooterComponent, + ListFooterComponentStyle, + ListHeaderComponent, ++ onInternalMomentumScrollBegin: () => { ++ ctx.state.isMomentumScrolling = true; ++ }, + onInternalScrollBeginDrag: fns.onScrollBeginDrag, ++ onInternalScrollEndDrag: () => { ++ ctx.state.isUserDragging = false; ++ }, + onInternalScrollEnd: fns.onScrollEnd, + onLayout, + onLayoutFooter, + onMomentumScrollEnd: fns.onMomentumScrollEnd, ++ onScrollBeginDrag: fns.onScrollBeginDrag, + onScroll: onScrollHandler, + recycleItems, + refreshControl: refreshControlElement ? stylePaddingTopState > 0 ? React2__namespace.cloneElement(refreshControlElement, { +diff --git a/react-native.mjs b/react-native.mjs +index 40e87cda8c9bc79a889e5542f29af429a24b24d4..c2ca39bab6ea1ebaaed25190a01e8cf2e395ece9 100644 +--- a/react-native.mjs ++++ b/react-native.mjs +@@ -696,6 +696,15 @@ function hasActiveInitialScroll(state) { + return !!(state == null ? void 0 : state.initialScroll) && !state.didFinishInitialScroll; + } + ++// Size-only changes may not emit a scroll event to refresh the edge signal. ++function getIsAtEnd(ctx, contentSize = getContentSize(ctx)) { ++ const { queuedInitialLayout, scroll, scrollLength } = ctx.state; ++ if (!(contentSize > 0 && queuedInitialLayout)) { ++ return peek$(ctx, "isAtEnd"); ++ } ++ return contentSize < scrollLength || contentSize - scroll - scrollLength - getContentInsetEnd(ctx) <= EDGE_POSITION_EPSILON; ++} ++ + // src/utils/checkAtBottom.ts + function checkAtBottom(ctx, allowedEdge, allowGateCreatedInCurrentCheck) { + var _a3; +@@ -716,7 +725,7 @@ function checkAtBottom(ctx, allowedEdge, allowGateCreatedInCurrentCheck) { + const insetEnd = getContentInsetEnd(ctx); + const distanceFromEnd = contentSize - scroll - scrollLength - insetEnd; + const isContentLess = contentSize < scrollLength; +- set$(ctx, "isAtEnd", isContentLess || distanceFromEnd <= EDGE_POSITION_EPSILON); ++ set$(ctx, "isAtEnd", getIsAtEnd(ctx, contentSize)); + set$(ctx, "isNearEnd", isContentLess || distanceFromEnd <= onEndReachedThreshold * scrollLength); + set$( + ctx, +@@ -933,7 +942,16 @@ function setInitialRenderState(ctx, { + if (didInitialScroll) { + state.didFinishInitialScroll = true; + } +- const isReadyToRender = Boolean(state.didContainersLayout && state.didFinishInitialScroll); ++ // Native contentOffset can seed an end target without dispatchInitialScroll. ++ // Both overflow completion paths must wait for the native end landing. ++ // Underflow needs no scroll: preserve UIKit's untouched resting position. ++ if (state.didContainersLayout && state.didFinishInitialScroll && state.initialScroll && state.initialScroll.viewPosition === 1 && state.initialScroll.index === state.props.data.length - 1 && state.props.data.length > 0) { ++ const insetStartAdjustment = getContentInsetStartAdjustment(ctx); ++ if (insetStartAdjustment > 0 && getContentSize(ctx) > state.scrollLength - insetStartAdjustment + 1) { ++ startInsetEndSettleWatchdog(ctx); ++ } ++ } ++ const isReadyToRender = Boolean(state.didContainersLayout && state.didFinishInitialScroll && !state.insetEndRevealHold); + if (isReadyToRender && !peek$(ctx, "readyToRender")) { + set$(ctx, "readyToRender", true); + setAdaptiveRender(ctx, "normal", "ready"); +@@ -1069,7 +1087,7 @@ function getRawContentLength(ctx) { + function getAlignItemsAtEndPadding(ctx) { + const { state } = ctx; + const shouldPad = !!state.props.alignItemsAtEndPaddingEnabled && !state.props.horizontal && state.props.data.length > 0 && state.scrollLength > 0; +- return shouldPad ? Math.max(0, state.scrollLength - getRawContentLength(ctx) - getContentInsetEnd(ctx)) : 0; ++ return shouldPad ? Math.max(0, state.scrollLength - getContentInsetStartAdjustment(ctx) - getRawContentLength(ctx) - getContentInsetEnd(ctx)) : 0; + } + function updateContentMetricsState(ctx) { + const previousPadding = peek$(ctx, "alignItemsAtEndPadding") || 0; +@@ -1094,6 +1112,10 @@ function addTotalSize(ctx, key, add, notifyTotalSize = true) { + totalSize += add; + } + if (prevTotalSize !== totalSize) { ++ const now = Date.now(); ++ const isContinuingContentSizeAnimation = state.contentSizeAnimationActiveEpoch !== void 0; ++ state.contentSizeAnimationEpoch = (state.contentSizeAnimationEpoch || 0) + 1; ++ state.contentSizeAnimationEligible = !!state.props.sizeComponentInternal && state.didContainersLayout && (isContinuingContentSizeAnimation || !state.props.maintainScrollAtEnd && !state.isUserDragging && !state.isMomentumScrolling && now - (state.lastMVCPAdjustTime || 0) >= 300); + if (!IsNewArchitecture && state.initialScroll && totalSize < prevTotalSize) { + state.pendingTotalSize = totalSize; + } else { +@@ -1283,18 +1305,23 @@ function calculateOffsetWithOffsetPosition(ctx, offsetParam, params) { + } + + // src/core/clampScrollOffset.ts ++function getContentInsetStartAdjustment(ctx) { ++ const adjustment = ctx.state.props.contentInsetStartAdjustment; ++ return typeof adjustment === "number" && Number.isFinite(adjustment) ? Math.max(0, adjustment) : 0; ++} + function clampScrollOffset(ctx, offset, scrollTarget) { + const state = ctx.state; + const contentSize = getContentSize(ctx); ++ const minOffset = -getContentInsetStartAdjustment(ctx); + let clampedOffset = offset; + if (Number.isFinite(contentSize) && Number.isFinite(state.scrollLength) && (Platform.OS !== "android" || state.lastLayout)) { +- const baseMaxOffset = Math.max(0, contentSize - state.scrollLength); ++ const baseMaxOffset = Math.max(minOffset, contentSize - state.scrollLength); + const viewOffset = scrollTarget == null ? void 0 : scrollTarget.viewOffset; + const extraEndOffset = typeof viewOffset === "number" && viewOffset < 0 ? -viewOffset : 0; + const maxOffset = baseMaxOffset + extraEndOffset; + clampedOffset = Math.min(offset, maxOffset); + } +- clampedOffset = Math.max(0, clampedOffset); ++ clampedOffset = Math.max(minOffset, clampedOffset); + return clampedOffset; + } + +@@ -1430,10 +1457,10 @@ function checkFinishedScrollFrame(ctx) { + finishScrollTo(ctx); + } + } +-function scrollToFallbackOffset(ctx, offset) { ++function scrollToFallbackOffset(ctx, offset, animated) { + var _a3; + (_a3 = ctx.state.refScroller.current) == null ? void 0 : _a3.scrollTo({ +- animated: false, ++ animated: !!animated, + x: ctx.state.props.horizontal ? offset : 0, + y: ctx.state.props.horizontal ? 0 : offset + }); +@@ -1482,7 +1509,10 @@ function checkFinishedScrollFallback(ctx) { + ); + scheduleFallbackCheck(SILENT_INITIAL_SCROLL_RETRY_DELAY_MS); + } else if (shouldRetryUnalignedEndScroll) { +- scrollToFallbackOffset(ctx, completionState.clampedTargetOffset); ++ const isActivelyAnimatingToEnd = !!isStillScrollingTo.animated && Date.now() - state.scrollTime < 100; ++ if (!isActivelyAnimatingToEnd) { ++ scrollToFallbackOffset(ctx, completionState.clampedTargetOffset, !!isStillScrollingTo.animated); ++ } + scheduleFallbackCheck(100); + } else if (shouldFinishZeroTarget || shouldFinishAfterObservedScroll || canFinishInitialScrollWithoutNativeProgress || canFinishAfterSilentNativeDispatch || numChecks > maxChecks) { + finishScrollTo(ctx); +@@ -1539,15 +1569,33 @@ function doMaintainScrollAtEnd(ctx) { + } = state; + const isWithinMaintainScrollAtEndThreshold = peek$(ctx, "isWithinMaintainScrollAtEndThreshold"); + const shouldMaintainScrollAtEnd = !!(isWithinMaintainScrollAtEndThreshold && maintainScrollAtEnd && didContainersLayout); ++ if (state.contentSizeAnimationActiveEpoch !== void 0) { ++ state.pendingMaintainScrollAtEnd = false; ++ return false; ++ } + if (pendingNativeMVCPAdjust) { + state.pendingMaintainScrollAtEnd = shouldMaintainScrollAtEnd; + return false; + } ++ // T3 patch: a caller anchor already placed this pass's offset; a later scroll would move it. ++ if (state.props.sizeChangeAnchor && !state.mvcpDataChanged && state.props.sizeChangeAnchor() !== void 0) { ++ state.pendingMaintainScrollAtEnd = false; ++ return shouldMaintainScrollAtEnd; ++ } + if (shouldMaintainScrollAtEnd) { + state.pendingMaintainScrollAtEnd = false; ++ const maintainAnchoredEndSpace = state.props.anchoredEndSpace; ++ const maintainAnchorIndex = maintainAnchoredEndSpace == null ? void 0 : maintainAnchoredEndSpace.anchorIndex; ++ if (maintainAnchorIndex !== void 0 && maintainAnchorIndex >= 0 && maintainAnchorIndex < state.props.data.length && !areKnownOrFixedItemSizesAvailable(ctx, maintainAnchorIndex, state.props.data.length - 1)) { ++ return false; ++ } + const contentSize = getContentSize(ctx); ++ const maintainInsetStartAdjustment = getContentInsetStartAdjustment(ctx); + if (contentSize < state.scrollLength) { +- state.scroll = 0; ++ state.scroll = -maintainInsetStartAdjustment; ++ if (maintainInsetStartAdjustment > 0) { ++ return true; ++ } + } + if (!state.maintainingScrollAtEnd) { + const pendingState = maintainScrollAtEnd.animated ? "pending-animated" : "pending-instant"; +@@ -1570,9 +1618,18 @@ function doMaintainScrollAtEnd(ctx) { + y: 0 + }); + } else { +- scroller == null ? void 0 : scroller.scrollToEnd({ +- animated: maintainScrollAtEnd.animated +- }); ++ const insetStartAdjustment = getContentInsetStartAdjustment(ctx); ++ if (insetStartAdjustment > 0) { ++ scroller == null ? void 0 : scroller.scrollTo({ ++ animated: maintainScrollAtEnd.animated, ++ x: 0, ++ y: Math.max(-insetStartAdjustment, getContentSize(ctx) - state.scrollLength) ++ }); ++ } else { ++ scroller == null ? void 0 : scroller.scrollToEnd({ ++ animated: maintainScrollAtEnd.animated ++ }); ++ } + } + setTimeout( + () => { +@@ -1603,6 +1660,10 @@ function doMaintainScrollAtEnd(ctx) { + function requestAdjust(ctx, positionDiff, dataChanged) { + const state = ctx.state; + if (Math.abs(positionDiff) > 0.1) { ++ // Timestamp for ReanimatedPositionView: repositions caused by an MVCP ++ // size adjustment are already compensated by a contentOffset shift, so ++ // animating them would make rows visibly lurch and slide back. ++ state.lastMVCPAdjustTime = Date.now(); + const needsScrollWorkaround = Platform.OS === "android" && !IsNewArchitecture && dataChanged && state.scroll <= positionDiff; + const doit = () => { + if (needsScrollWorkaround) { +@@ -1707,7 +1768,9 @@ function getPredictedNativeClamp(state, unresolvedAmount, totalSize) { + if (Math.abs(unresolvedAmount) <= MVCP_POSITION_EPSILON) { + return 0; + } +- const maxScroll = Math.max(0, totalSize - state.scrollLength); ++ const insetStartAdjustment = state.props.contentInsetStartAdjustment; ++ const minScroll = typeof insetStartAdjustment === "number" && Number.isFinite(insetStartAdjustment) ? -Math.max(0, insetStartAdjustment) : 0; ++ const maxScroll = Math.max(minScroll, totalSize - state.scrollLength); + const clampDelta = maxScroll - state.scroll; + if (unresolvedAmount < 0) { + return Math.max(unresolvedAmount, Math.min(0, clampDelta)); +@@ -1769,7 +1832,7 @@ function resolvePendingNativeMVCPAdjust(ctx, newScroll) { + settlePendingNativeMVCPAdjust(ctx, remainingAfterManual, nativeDelta); + return true; + } +- const expectedNativeClampScroll = Math.max(0, getContentSize(ctx) - state.scrollLength); ++ const expectedNativeClampScroll = Math.max(-getContentInsetStartAdjustment(ctx), getContentSize(ctx) - state.scrollLength); + const distanceToClamp = Math.abs(newScroll - expectedNativeClampScroll); + const isAtExpectedNativeClamp = distanceToClamp <= NATIVE_END_CLAMP_EPSILON; + if (isAtExpectedNativeClamp) { +@@ -1790,7 +1853,35 @@ function resolvePendingNativeMVCPAdjust(ctx, newScroll) { + } + return false; + } ++// T3 patch: a caller anchor decides where a size change leaves the scroll position. It is read in ++// the same pass that repositions the items, so the adjustment commits with the new positions. + function prepareMVCP(ctx, dataChanged) { ++ // T3 patch: a data change skips the caller anchor, so end maintenance must still run after it. ++ ctx.state.mvcpDataChanged = !!dataChanged; ++ const sizeChangeAnchor = dataChanged ? void 0 : ctx.state.props.sizeChangeAnchor; ++ const restore = prepareDefaultMVCP(ctx, dataChanged); ++ if (!sizeChangeAnchor || ctx.state.scrollingTo !== void 0) { ++ return restore; ++ } ++ return () => { ++ const target = sizeChangeAnchor(); ++ if (target === void 0) { ++ restore == null ? void 0 : restore(); ++ return; ++ } ++ // Content that shrinks under an offset past its new end pulls the native offset back to ++ // that end by itself; only the rest of the way to the target is adjusted. ++ const endOffset = clampScrollOffset(ctx, Number.POSITIVE_INFINITY); ++ if (ctx.state.scroll > endOffset) { ++ ctx.state.scroll = endOffset; ++ } ++ const positionDiff = clampScrollOffset(ctx, target) - ctx.state.scroll; ++ if (Math.abs(positionDiff) > MVCP_POSITION_EPSILON) { ++ requestAdjust(ctx, positionDiff, false); ++ } ++ }; ++} ++function prepareDefaultMVCP(ctx, dataChanged) { + const state = ctx.state; + const { idsInView, positions, props } = state; + const { +@@ -1902,7 +1993,7 @@ function prepareMVCP(ctx, dataChanged) { + if (diff > 0) { + diff = Math.max(0, totalSize - state.scroll - state.scrollLength); + } else { +- const maxScroll = Math.max(0, totalSize - state.scrollLength); ++ const maxScroll = Math.max(-getContentInsetStartAdjustment(ctx), totalSize - state.scrollLength); + state.scroll = maxScroll; + state.scrollPending = maxScroll; + diff = 0; +@@ -2299,8 +2390,121 @@ function scrollToIndex(ctx, { + } + + // src/core/initialScroll.ts ++var INSET_END_SETTLE_WATCHDOG_FRAMES = 150; ++var INSET_END_SETTLE_WATCHDOG_STABLE_FRAMES = 20; ++var INSET_END_REVEAL_STABLE_FRAMES = 3; ++var INSET_END_REVEAL_MAX_HOLD_FRAMES = 40; ++function startInsetEndSettleWatchdog(ctx) { ++ const state = ctx.state; ++ if (state.insetEndSettleWatchdogStarted || state.didLoad) { ++ return; ++ } ++ state.insetEndSettleWatchdogStarted = true; ++ state.insetEndSettleWatchdogActive = true; ++ // Hold the readyToRender opacity gate until the end landing is stable, so ++ // the estimated-to-measured settle chase happens before first VISIBLE ++ // paint instead of in front of the user. Capped so slow measurement can ++ // never hide content for long. ++ state.insetEndRevealHold = true; ++ let frames = 0; ++ let settledFrames = 0; ++ let revealStableFrames = 0; ++ let previousEndOffset; ++ const releaseRevealHold = () => { ++ if (state.insetEndRevealHold) { ++ state.insetEndRevealHold = false; ++ setInitialRenderState(ctx, {}); ++ } ++ }; ++ // Revealing flips adaptive rendering to "normal", which re-renders rows and ++ // can move the end target one more time — do that upgrade while still ++ // hidden (phase 1), then require stability again before revealing (phase 2) ++ // so the first visible frame is the settled one. ++ let revealPhase = 1; ++ const onRevealStability = () => { ++ var _a3; ++ if (!state.insetEndRevealHold) { ++ return; ++ } ++ if (revealPhase === 1) { ++ revealPhase = 2; ++ revealStableFrames = 0; ++ setAdaptiveRender(ctx, "normal"); ++ (_a3 = state.triggerCalculateItemsInView) == null ? void 0 : _a3.call(state); ++ return; ++ } ++ releaseRevealHold(); ++ }; ++ const tick = () => { ++ // The user owns the scroll from their first drag — a re-pin here would ++ // pin the list under their finger. ++ if (frames++ >= INSET_END_SETTLE_WATCHDOG_FRAMES || settledFrames >= INSET_END_SETTLE_WATCHDOG_STABLE_FRAMES || state.didUserDrag || !ctx.state || ctx.state !== state) { ++ state.insetEndSettleWatchdogActive = false; ++ releaseRevealHold(); ++ return; ++ } ++ if (frames >= INSET_END_REVEAL_MAX_HOLD_FRAMES) { ++ releaseRevealHold(); ++ } ++ const insetStartAdjustment = getContentInsetStartAdjustment(ctx); ++ const contentSize = getContentSize(ctx); ++ const scrollLength = state.scrollLength; ++ const endOffset = Math.max(-insetStartAdjustment, contentSize - scrollLength); ++ // state.scroll is optimistic: non-animated scrollTo writes it before UIKit ++ // moves. Only a native scroll event proves that the requested offset landed. ++ const nativeOffset = state.lastNativeScroll; ++ const hasNativeOffset = typeof nativeOffset === "number" && Number.isFinite(nativeOffset); ++ const distance = hasNativeOffset ? endOffset - nativeOffset : Infinity; ++ const isIdle = !state.scrollingTo && !state.maintainingScrollAtEnd; ++ const hasViewport = insetStartAdjustment > 0 && scrollLength > 0 && Number.isFinite(contentSize); ++ const isStable = hasViewport && isIdle && Math.abs(distance) <= 2 && previousEndOffset !== void 0 && Math.abs(endOffset - previousEndOffset) <= 1; ++ previousEndOffset = endOffset; ++ if (isStable) { ++ settledFrames++; ++ revealStableFrames++; ++ if (revealStableFrames >= INSET_END_REVEAL_STABLE_FRAMES) { ++ onRevealStability(); ++ } ++ } else { ++ settledFrames = 0; ++ revealStableFrames = 0; ++ // Keep the existing near-end correction limit. In-flight scrolls and ++ // unknown native offsets wait; neither counts as a settled frame. ++ if (hasViewport && isIdle && Math.abs(distance) > 2 && Math.abs(distance) <= scrollLength * 0.5) { ++ const scroller = state.refScroller.current; ++ if (scroller) { ++ scroller.scrollTo({ animated: false, x: 0, y: endOffset }); ++ } ++ } ++ } ++ requestAnimationFrame(tick); ++ }; ++ requestAnimationFrame(tick); ++} + function dispatchInitialScroll(ctx, params) { + const { forceScroll, resolvedOffset, target, waitForCompletionFrame } = params; ++ const insetStartAdjustment = getContentInsetStartAdjustment(ctx); ++ if (insetStartAdjustment > 0 && ctx.state.props.data.length > 0) { ++ if (ctx.state.scrollLength <= 0) { ++ // The scroll length is unknown, so the resolved target is meaningless; ++ // the initial-scroll machinery re-advances after layout. ++ return; ++ } ++ if (resolvedOffset <= -insetStartAdjustment + 1 && !ctx.state.didDispatchInsetInitialScroll) { ++ // Content underflows the viewport and nothing has scrolled yet: the ++ // untouched native rest position (UIKit's adjustedContentInset) IS the ++ // end position. Dispatching a negative scroll here would race UIKit's ++ // inset application during screen attach, so just finish the session. ++ finishInitialScroll(ctx, { ++ resolvedOffset ++ }); ++ return; ++ } ++ ctx.state.didDispatchInsetInitialScroll = true; ++ if (target.viewPosition === 1) { ++ startInsetEndSettleWatchdog(ctx); ++ } ++ } + const requestedIndex = target.index; + const index = requestedIndex !== void 0 ? clampScrollIndex(requestedIndex, ctx.state.props.data.length) : void 0; + const itemSize = getItemSizeAtIndex(ctx, index); +@@ -2726,7 +2930,9 @@ function clearFinishedBootstrapInitialScrollTargetIfMovedAway(ctx) { + return; + } + if (didFinishedInitialScrollMoveAwayFromTarget(ctx, initialScroll)) { +- const shouldKeepEndTargetAlive = isRetargetableBottomAlignedInitialScrollTarget(initialScroll) && peek$(ctx, "isAtEnd"); ++ const endTargetDistanceFromEnd = getContentSize(ctx) - state.scroll - state.scrollLength - getContentInsetEnd(ctx); ++ const isNearEndForInsetList = getContentInsetStartAdjustment(ctx) > 0 && Number.isFinite(endTargetDistanceFromEnd) && endTargetDistanceFromEnd <= state.scrollLength * 0.5; ++ const shouldKeepEndTargetAlive = isRetargetableBottomAlignedInitialScrollTarget(initialScroll) && (peek$(ctx, "isAtEnd") || !state.didUserDrag && isNearEndForInsetList); + if (!shouldKeepEndTargetAlive) { + if (shouldPreserveInitialScrollForFooterLayout(initialScroll)) { + clearPendingInitialScrollFooterLayout(ctx, { +@@ -4651,7 +4857,8 @@ function maybeUpdateAnchoredEndSpace(ctx) { + contentBelowAnchor = Math.max(0, contentBelowAnchor - ctx.scrollAxisGap); + contentBelowAnchor += (ctx.values.get("footerSize") || 0) + getStylePaddingEnd(state.props); + isReady = !hasUnknownTailSize; +- nextSize = hasUnknownTailSize ? previousSize || 0 : Math.max(0, state.scrollLength - contentBelowAnchor - anchorOffset); ++ const knownSizeBound = Math.max(0, state.scrollLength - contentBelowAnchor - anchorOffset); ++ nextSize = hasUnknownTailSize ? Math.min(previousSize || 0, knownSizeBound) : knownSizeBound; + } else if (anchorIndex >= 0) { + isReady = false; + } +@@ -4671,6 +4878,12 @@ function maybeUpdateAnchoredEndSpace(ctx) { + updateScroll(ctx, state.scroll, true, { markHasScrolled: false }); + } + (_b = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onReady) == null ? void 0 : _b.call(anchoredEndSpace, { anchorIndex: nextAnchorIndex, anchorKey: nextAnchorKey, size: nextSize }); ++ } else if (!isReady && didSizeChange && nextSize < (previousSize || 0)) { ++ set$(ctx, "anchoredEndSpaceSize", nextSize); ++ (_a3 = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onSizeChanged) == null ? void 0 : _a3.call(anchoredEndSpace, nextSize); ++ if (anchoredEndSpace == null ? void 0 : anchoredEndSpace.includeInEndInset) { ++ updateScroll(ctx, state.scroll, true, { markHasScrolled: false }); ++ } + } + return nextSize; + } +@@ -5694,8 +5907,11 @@ var ContainersLayer = typedMemo(function ContainersLayer2({ + horizontal + }) { + const ctx = useStateContext(); ++ const SizeComponent = ctx.state.props.sizeComponentInternal; + const columnWrapperStyle = ctx.columnWrapperStyle; +- const animSize = useValue$("totalSize"); ++ // T3 patch: on the new architecture an animated value commits on its own, ahead of the item ++ // positions and their scroll compensation; a rendered size commits with them. ++ const animSize = IsNewArchitecture ? useArr$(["totalSize"])[0] || 0 : useValue$("totalSize"); + const [readyToRender, numColumns, otherAxisSize = 0] = useArr$(["readyToRender", "numColumns", "otherAxisSize"]); + const isVisible = useFreshDataTransitionVisibility(!!readyToRender, freshDataTransitionEpoch); + const style = horizontal ? { +@@ -5704,6 +5920,13 @@ var ContainersLayer = typedMemo(function ContainersLayer2({ + opacity: isVisible ? 1 : 0, + width: animSize + } : { height: animSize, minWidth: otherAxisSize, opacity: isVisible ? 1 : 0 }; ++ if (SizeComponent) { ++ if (horizontal) { ++ delete style.width; ++ } else { ++ delete style.height; ++ } ++ } + if (columnWrapperStyle) { + const { columnGap, rowGap, gap } = columnWrapperStyle; + const gapX = columnGap || gap || 0; +@@ -5724,7 +5947,8 @@ var ContainersLayer = typedMemo(function ContainersLayer2({ + } + } + } +- return /* @__PURE__ */ React2.createElement(Animated.View, { pointerEvents: isVisible ? void 0 : "none", style }, /* @__PURE__ */ React2.createElement(ContainerLayoutCoordinator, null, children)); ++ const content = /* @__PURE__ */ React2.createElement(ContainerLayoutCoordinator, null, children); ++ return SizeComponent ? /* @__PURE__ */ React2.createElement(SizeComponent, { horizontal, pointerEvents: isVisible ? void 0 : "none", signalName: "totalSize", style }, content) : /* @__PURE__ */ React2.createElement(Animated.View, { pointerEvents: isVisible ? void 0 : "none", style }, content); + }); + var Containers = typedMemo(function Containers2({ + freshDataTransitionEpoch, +@@ -5875,7 +6099,12 @@ var StyleSheet = StyleSheet$1; + + // src/components/ListComponent.tsx + var AlignItemsAtEndSpacer = typedMemo(function AlignItemsAtEndSpacer2({ horizontal }) { ++ const ctx = useStateContext(); + const [alignItemsAtEndPadding = 0] = useArr$(["alignItemsAtEndPadding"]); ++ const SizeComponent = ctx.state.props.sizeComponentInternal; ++ if (SizeComponent) { ++ return /* @__PURE__ */ React2.createElement(SizeComponent, { horizontal, signalName: "alignItemsAtEndPadding", style: { flexShrink: 0 } }); ++ } + if (alignItemsAtEndPadding <= 0) { + return null; + } +@@ -5908,8 +6137,12 @@ var ListComponent = typedMemo(function ListComponent2({ + refScrollView, + renderScrollComponent, + onLayoutFooter, ++ onInternalMomentumScrollBegin, + onInternalScrollBeginDrag, ++ onInternalScrollEndDrag, + onInternalScrollEnd, ++ onMomentumScrollBegin, ++ onScrollEndDrag, + scrollAdjustHandler, + snapToIndices, + stickyHeaderConfig, +@@ -5980,7 +6213,17 @@ var ListComponent = typedMemo(function ListComponent2({ + SnapOrScroll, + { + ...rest, +- ...Platform.OS === "web" ? ScrollComponent === ListComponentScrollView ? { onInternalScrollEnd, useWindowScroll } : {} : { onScrollBeginDrag: onInternalScrollBeginDrag }, ++ ...Platform.OS === "web" ? ScrollComponent === ListComponentScrollView ? { onInternalScrollEnd, useWindowScroll } : {} : { ++ onMomentumScrollBegin: (event) => { ++ onInternalMomentumScrollBegin == null ? void 0 : onInternalMomentumScrollBegin(event); ++ onMomentumScrollBegin == null ? void 0 : onMomentumScrollBegin(event); ++ }, ++ onScrollBeginDrag: onInternalScrollBeginDrag, ++ onScrollEndDrag: (event) => { ++ onInternalScrollEndDrag == null ? void 0 : onInternalScrollEndDrag(event); ++ onScrollEndDrag == null ? void 0 : onScrollEndDrag(event); ++ } ++ }, + contentContainerStyle: [ + horizontal ? { height: "100%" } : {}, + contentContainerStyle, +@@ -5989,7 +6232,10 @@ var ListComponent = typedMemo(function ListComponent2({ + ], + contentOffset: initialContentOffset !== void 0 ? horizontal ? { x: initialContentOffset, y: 0 } : { x: 0, y: initialContentOffset } : void 0, + horizontal, +- maintainVisibleContentPosition: maintainVisibleContentPosition.size || maintainVisibleContentPosition.data ? { minIndexForVisible: 0 } : void 0, ++ // Keep iOS anchored to ScrollAdjust even when JS position restoration is ++ // disabled. Re-enabling native MVCP mid-drag can compare its stale anchor ++ // with the 1e7 sentinel and scroll the entire list out of view. ++ maintainVisibleContentPosition: Platform.OS === "ios" || maintainVisibleContentPosition.size || maintainVisibleContentPosition.data ? { minIndexForVisible: 0 } : void 0, + onLayout, + onScroll: onScroll2, + ref: refScrollView, +@@ -6246,7 +6492,8 @@ function handleLayout(ctx, layoutParam, setCanRender) { + if (scrollLength > 0) { + doInitialAllocateContainers(ctx); + } +- if (needsCalculate) { ++ // T3 patch: a shorter list keeps a caller anchor too, such as the end. ++ if (needsCalculate || state.props.sizeChangeAnchor) { + calculateItemsInView(ctx, { doMVCP: true }); + } + if (didChange || otherAxisSize !== prevOtherAxisSize) { +@@ -6730,7 +6977,7 @@ function createImperativeHandle(ctx, scheduleImperativeScrollCommit) { + endBuffered: state.endBuffered, + getAverageItemSizes: () => getAverageItemSizes(state), + indexByKey: (key) => state.indexByKey.get(key), +- isAtEnd: peek$(ctx, "isAtEnd"), ++ isAtEnd: getIsAtEnd(ctx), + isAtStart: peek$(ctx, "isAtStart"), + isEndReached: state.isEndReached, + isNearEnd: peek$(ctx, "isNearEnd"), +@@ -7054,6 +7301,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + dataVersion, + drawDistance = 250, + contentInsetEndAdjustment, ++ contentInsetStartAdjustment, + estimatedItemSize = 100, + estimatedListSize, + extraData, +@@ -7075,6 +7323,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + maintainScrollAtEnd = false, + maintainScrollAtEndThreshold = 0.1, + maintainVisibleContentPosition: maintainVisibleContentPositionProp, ++ sizeChangeAnchor, + numColumns: numColumnsProp = 1, + overrideItemLayout, + onEndReached, +@@ -7111,10 +7360,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + const animatedPropsInternal = props.animatedPropsInternal; + const anchoredEndSpaceOwner = (_a3 = props.anchoredEndSpaceOwnerInternal) != null ? _a3 : "list"; + const positionComponentInternal = props.positionComponentInternal; ++ const sizeComponentInternal = props.sizeComponentInternal; + const stickyPositionComponentInternal = props.stickyPositionComponentInternal; + const { + anchoredEndSpaceOwnerInternal: _anchoredEndSpaceOwnerInternal, + positionComponentInternal: _positionComponentInternal, ++ sizeComponentInternal: _sizeComponentInternal, + stickyPositionComponentInternal: _stickyPositionComponentInternal, + ...restProps + } = rest; +@@ -7179,7 +7430,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + const combinedRef = useCombinedRef(refScroller, refScrollView); + const keyExtractor = keyExtractorProp != null ? keyExtractorProp : ((_item, index) => index.toString()); + const stickyHeaderIndices = stickyHeaderIndicesProp; +- const contentInsetEndAdjustmentResolved = Platform.OS === "web" ? contentInsetEndAdjustment : void 0; ++ const contentInsetEndAdjustmentResolved = contentInsetEndAdjustment; + const previousContentInsetEndAdjustmentRef = useRef(contentInsetEndAdjustmentResolved); + const alwaysRenderIndices = useMemo(() => { + const indices = getAlwaysRenderIndices(alwaysRender, dataProp, keyExtractor, anchoredEndSpace == null ? void 0 : anchoredEndSpace.anchorIndex); +@@ -7320,6 +7571,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + contentContainerAlignItems: contentContainerStyle.alignItems, + contentInset, + contentInsetEndAdjustment: contentInsetEndAdjustmentResolved, ++ contentInsetStartAdjustment, + data: dataProp, + dataKey, + dataVersion, +@@ -7333,6 +7585,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + maintainScrollAtEnd: maintainScrollAtEndConfig, + maintainScrollAtEndThreshold, + maintainVisibleContentPosition: maintainVisibleContentPositionConfig, ++ sizeChangeAnchor, + numColumns: numColumnsProp, + onEndReached, + onEndReachedThreshold, +@@ -7351,6 +7604,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + renderItem, + rtl, + snapToIndices, ++ sizeComponentInternal, + stickyHeaderIndicesArr: stickyHeaderIndices != null ? stickyHeaderIndices : [], + stickyHeaderIndicesSet: useMemo(() => new Set(stickyHeaderIndices != null ? stickyHeaderIndices : []), [stickyHeaderIndices == null ? void 0 : stickyHeaderIndices.join(",")]), + stickyPositionComponentInternal, +@@ -7402,6 +7656,13 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + return void 0; + } + const resolvedOffset = (_a4 = initialScroll.contentOffset) != null ? _a4 : resolveInitialScrollOffset(ctx, initialScroll); ++ if (getContentInsetStartAdjustment(ctx) > 0) { ++ // With a native leading inset (transparent header + automatic insets), ++ // any mount-time contentOffset races UIKit's adjustedContentInset ++ // application. The gated initial-scroll dispatch positions the list once ++ // real sizes are known instead. ++ return void 0; ++ } + return usesBootstrapInitialScroll && ((_b2 = state.initialScrollSession) == null ? void 0 : _b2.kind) === "bootstrap" && Platform.OS === "web" ? void 0 : resolvedOffset; + }, [usesBootstrapInitialScroll]); + useLayoutEffect(() => { +@@ -7526,6 +7787,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + [ + dataKey, + dataVersion, ++ contentInsetStartAdjustment, + memoizedLastItemKeys.join(","), + numColumnsProp, + nextScrollAxisGap, +@@ -7622,6 +7884,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + () => ({ + getRenderedItem: (key) => getRenderedItem(ctx, key), + onMomentumScrollEnd: (event) => { ++ state.isMomentumScrolling = false; + checkFinishedScrollFallback(ctx); + if (state.props.onMomentumScrollEnd) { + state.props.onMomentumScrollEnd(event); +@@ -7630,6 +7893,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + onScroll: (event) => onScroll(ctx, event), + onScrollBeginDrag: (event) => { + var _a4, _b2; ++ ctx.state.didUserDrag = true; ++ ctx.state.isUserDragging = true; + prepareReachedEdgeForNextUserScroll(ctx); + (_b2 = (_a4 = state.props).onScrollBeginDrag) == null ? void 0 : _b2.call(_a4, event); + }, +@@ -7655,11 +7920,18 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded + ListFooterComponent, + ListFooterComponentStyle, + ListHeaderComponent, ++ onInternalMomentumScrollBegin: () => { ++ ctx.state.isMomentumScrolling = true; ++ }, + onInternalScrollBeginDrag: fns.onScrollBeginDrag, ++ onInternalScrollEndDrag: () => { ++ ctx.state.isUserDragging = false; ++ }, + onInternalScrollEnd: fns.onScrollEnd, + onLayout, + onLayoutFooter, + onMomentumScrollEnd: fns.onMomentumScrollEnd, ++ onScrollBeginDrag: fns.onScrollBeginDrag, + onScroll: onScrollHandler, + recycleItems, + refreshControl: refreshControlElement ? stylePaddingTopState > 0 ? React2.cloneElement(refreshControlElement, { +diff --git a/react-native.web.js b/react-native.web.js +index 914d2dafaafa001c9ab6791a0a0581659295e333..8b88b09d1269acef77c6ce0f8aaa1049d4fa26e9 100644 +--- a/react-native.web.js ++++ b/react-native.web.js +@@ -5651,6 +5651,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) { + }); + + // src/utils/reordering.ts ++// Element.moveBefore keeps the moved subtree's state and does not count as an ++// insertion, so CSS @starting-style transitions and iframes inside a row do not ++// restart when the list reorders its containers. insertBefore is the fallback. ++function moveChildBefore(container, element, reference) { ++ if (typeof container.moveBefore === "function") { ++ container.moveBefore(element, reference); ++ } else if (reference) { ++ container.insertBefore(element, reference); ++ } else { ++ container.appendChild(element); ++ } ++} + function sortDOMElements(container, indexByElement) { + const elements = Array.from(container.children); + if (elements.length <= 1) return elements; +@@ -5690,9 +5702,9 @@ function sortDOMElements(container, indexByElement) { + } + } + if (nextStableElement) { +- container.insertBefore(element, nextStableElement); ++ moveChildBefore(container, element, nextStableElement); + } else { +- container.appendChild(element); ++ moveChildBefore(container, element, null); + } + } + } +diff --git a/react-native.web.mjs b/react-native.web.mjs +index 95465f2ab89ce41a10553f58af83618f7310e83c..d7cbe1cb43449cc29822b2646deabbddd67f1e7d 100644 +--- a/react-native.web.mjs ++++ b/react-native.web.mjs +@@ -5630,6 +5630,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) { + }); + + // src/utils/reordering.ts ++// Element.moveBefore keeps the moved subtree's state and does not count as an ++// insertion, so CSS @starting-style transitions and iframes inside a row do not ++// restart when the list reorders its containers. insertBefore is the fallback. ++function moveChildBefore(container, element, reference) { ++ if (typeof container.moveBefore === "function") { ++ container.moveBefore(element, reference); ++ } else if (reference) { ++ container.insertBefore(element, reference); ++ } else { ++ container.appendChild(element); ++ } ++} + function sortDOMElements(container, indexByElement) { + const elements = Array.from(container.children); + if (elements.length <= 1) return elements; +@@ -5669,9 +5681,9 @@ function sortDOMElements(container, indexByElement) { + } + } + if (nextStableElement) { +- container.insertBefore(element, nextStableElement); ++ moveChildBefore(container, element, nextStableElement); + } else { +- container.appendChild(element); ++ moveChildBefore(container, element, null); + } + } + } +diff --git a/react.js b/react.js +index 914d2dafaafa001c9ab6791a0a0581659295e333..8c320b0dfb3ea60ef145274b37b1297b7dee26dc 100644 +--- a/react.js ++++ b/react.js +@@ -1908,6 +1908,10 @@ function updateScroll(ctx, newScroll, forceUpdate, options) { + state.scrollTime = currentTime; + const scrollDelta = Math.abs(newScroll - prevScroll); + const isUserScrollEvent = !!(options == null ? void 0 : options.fromNativeScrollEvent) && scrollDelta > 0.1 && !adjustChanged && scrollingTo === void 0 && !state.pendingNativeMVCPAdjust; ++ if (isUserScrollEvent) { ++ state.userScrollPrevTime = state.userScrollTime; ++ state.userScrollTime = currentTime; ++ } + const allowedEdge = isUserScrollEvent ? beginReachedEdgeUserScroll(ctx, newScroll - prevScroll) : void 0; + const didResolvePendingNativeMVCPAdjust = resolvePendingNativeMVCPAdjust(ctx, newScroll); + const scrollLength = state.scrollLength; +@@ -3257,6 +3261,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) { + const itemKey = (_a3 = state.idCache[itemIndex]) != null ? _a3 : getId(state, itemIndex); + const updateLayout = (_b = options == null ? void 0 : options.updateLayout) != null ? _b : true; + let didChangePosition = false; ++ let didChangeIndex = false; + let didRefreshData = false; + if (updateLayout) { + const positionValue = positions[itemIndex]; +@@ -3286,6 +3291,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) { + const prevIndex = peek$(ctx, `containerItemIndex${containerIndex}`); + if (prevIndex !== itemIndex) { + set$(ctx, `containerItemIndex${containerIndex}`, itemIndex); ++ didChangeIndex = true; + } + const prevData = peek$(ctx, `containerItemData${containerIndex}`); + const updateData = () => { +@@ -3324,7 +3330,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) { + } + } + } +- return { didChangePosition, didRefreshData }; ++ return { didChangeIndex, didChangePosition, didRefreshData }; + } + + // src/core/prepareColumnStartState.ts +@@ -3542,7 +3548,11 @@ function updateItemPositions(ctx, dataChanged, { + } + if (shouldOptimize && breakAt === void 0 && !scrollingTo && !dataChanged && currentRowTop > maxVisibleArea) { + const itemsPerRow = hasColumns ? numColumns : 1; +- breakAt = i + itemsPerRow + 10; ++ // alwaysRender rows stay mounted outside the visible window, so keep their ++ // positions current instead of leaving them where they were last laid out. ++ const pinnedIndices = state.props.alwaysRenderIndicesArr; ++ const lastPinnedIndex = pinnedIndices && pinnedIndices.length > 0 ? pinnedIndices[pinnedIndices.length - 1] : -1; ++ breakAt = Math.max(i + itemsPerRow + 10, lastPinnedIndex); + } + const id = (_e = idCache[i]) != null ? _e : getId(state, i); + let span = 1; +@@ -4243,6 +4253,7 @@ function calculateItemsInView(ctx, params = {}) { + } + let totalSize = getContentSize(ctx); + let changedContainerIds; ++ let didChangeContainerOrder = false; + const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "alignItemsAtEndPadding") + peek$(ctx, "headerSize"); + const numColumns = peek$(ctx, "numColumns"); + const speed = (_b = params.scrollVelocity) != null ? _b : getScrollVelocity(state); +@@ -4545,6 +4556,9 @@ function calculateItemsInView(ctx, params = {}) { + const containerIndex = allocation.containerIndex; + const id = (_o = idCache[i]) != null ? _o : getId(state, i); + const oldKey = peek$(ctx, `containerItemKey${containerIndex}`); ++ if (oldKey !== id || peek$(ctx, `containerItemIndex${containerIndex}`) !== i) { ++ didChangeContainerOrder = true; ++ } + if (oldKey && oldKey !== id) { + containerItemKeys.delete(oldKey); + } +@@ -4629,10 +4643,12 @@ function calculateItemsInView(ctx, params = {}) { + } else { + const itemIndex = indexByKey.get(itemKey); + if (itemIndex !== void 0) { +- didChangePositions = syncMountedContainer(ctx, i, itemIndex, { ++ const synced = syncMountedContainer(ctx, i, itemIndex, { + scrollAdjustPending, + updateLayout: true +- }).didChangePosition || didChangePositions; ++ }); ++ didChangePositions = synced.didChangePosition || didChangePositions; ++ didChangeContainerOrder = synced.didChangeIndex || didChangeContainerOrder; + } + } + } +@@ -4642,6 +4658,9 @@ function calculateItemsInView(ctx, params = {}) { + if (didChangePositions) { + set$(ctx, "lastPositionUpdate", Date.now()); + } ++ if (didChangeContainerOrder) { ++ set$(ctx, "containerOrderUpdate", (peek$(ctx, "containerOrderUpdate") || 0) + 1); ++ } + if (suppressInitialScrollSideEffects) { + evaluateBootstrapInitialScroll(ctx); + return; +@@ -4702,7 +4721,8 @@ function maybeUpdateAnchoredEndSpace(ctx) { + contentBelowAnchor = Math.max(0, contentBelowAnchor - ctx.scrollAxisGap); + contentBelowAnchor += (ctx.values.get("footerSize") || 0) + getStylePaddingEnd(state.props); + isReady = !hasUnknownTailSize; +- nextSize = hasUnknownTailSize ? previousSize || 0 : Math.max(0, state.scrollLength - contentBelowAnchor - anchorOffset); ++ const knownSizeBound = Math.max(0, state.scrollLength - contentBelowAnchor - anchorOffset); ++ nextSize = hasUnknownTailSize ? Math.min(previousSize || 0, knownSizeBound) : knownSizeBound; + } else if (anchorIndex >= 0) { + isReady = false; + } +@@ -4722,6 +4742,12 @@ function maybeUpdateAnchoredEndSpace(ctx) { + updateScroll(ctx, state.scroll, true, { markHasScrolled: false }); + } + (_b = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onReady) == null ? void 0 : _b.call(anchoredEndSpace, { anchorIndex: nextAnchorIndex, anchorKey: nextAnchorKey, size: nextSize }); ++ } else if (!isReady && didSizeChange && nextSize < (previousSize || 0)) { ++ set$(ctx, "anchoredEndSpaceSize", nextSize); ++ (_a3 = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onSizeChanged) == null ? void 0 : _a3.call(anchoredEndSpace, nextSize); ++ if (anchoredEndSpace == null ? void 0 : anchoredEndSpace.includeInEndInset) { ++ updateScroll(ctx, state.scroll, true, { markHasScrolled: false }); ++ } + } + return nextSize; + } +@@ -4956,7 +4982,8 @@ function measureContainersInLayoutEffect(ctx, targetContainerIds = null) { + const itemKey = peek$(ctx, `containerItemKey${containerId}`); + const element = viewRef == null ? void 0 : viewRef.current; + if (itemKey !== void 0 && element) { +- const rect = element.getBoundingClientRect(); ++ // Unlike getBoundingClientRect, offset sizes ignore ancestor transforms (e.g. a popup's zoom-in), like ResizeObserver. ++ const rect = { height: element.offsetHeight, width: element.offsetWidth }; + setContainerLayoutBaseline(element, rect); + measurements.push({ + containerId, +@@ -4978,12 +5005,26 @@ var ContainerLayoutCoordinator = typedMemo(function ContainerLayoutCoordinatorCo + }) { + const ctx = useStateContext(); + const [containerLayoutEpoch] = useArr$(["containerLayoutEpoch"]); ++ const layoutPasses = React3__namespace.useRef(0); + React3__namespace.useLayoutEffect(() => { +- { +- const targetContainerIds = getContainerLayoutEffectScope(ctx); +- if (targetContainerIds !== void 0) { +- measureContainersInLayoutEffect(ctx, targetContainerIds); +- } ++ const targetContainerIds = getContainerLayoutEffectScope(ctx); ++ if (targetContainerIds === void 0) return; ++ if (layoutPasses.current === 0) { ++ queueMicrotask(() => { layoutPasses.current = 0; }); ++ } ++ // Correcting large estimates can mount one row per commit. Bound the ++ // synchronous chain below React's nested-update limit, then keep measuring ++ // the latest pending rows on the next frame. Idle lists schedule no work. ++ if (layoutPasses.current++ < 8) { ++ measureContainersInLayoutEffect(ctx, targetContainerIds); ++ } else { ++ ctx.pendingContainerIds = targetContainerIds; ++ ctx.state.scheduledWork.frame(() => { ++ const pendingIds = getContainerLayoutEffectScope(ctx); ++ if (pendingIds !== void 0) { ++ measureContainersInLayoutEffect(ctx, pendingIds); ++ } ++ }, "containerLayout"); + } + }, [ctx, containerLayoutEpoch]); + return children; +@@ -5651,6 +5692,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) { + }); + + // src/utils/reordering.ts ++// Element.moveBefore keeps the moved subtree's state and does not count as an ++// insertion, so CSS @starting-style transitions and iframes inside a row do not ++// restart when the list reorders its containers. insertBefore is the fallback. ++function moveChildBefore(container, element, reference) { ++ if (typeof container.moveBefore === "function") { ++ container.moveBefore(element, reference); ++ } else if (reference) { ++ container.insertBefore(element, reference); ++ } else { ++ container.appendChild(element); ++ } ++} + function sortDOMElements(container, indexByElement) { + const elements = Array.from(container.children); + if (elements.length <= 1) return elements; +@@ -5690,9 +5743,9 @@ function sortDOMElements(container, indexByElement) { + } + } + if (nextStableElement) { +- container.insertBefore(element, nextStableElement); ++ moveChildBefore(container, element, nextStableElement); + } else { +- container.appendChild(element); ++ moveChildBefore(container, element, null); + } + } + } +@@ -5734,37 +5787,55 @@ function findLIS(arr) { + } + + // src/hooks/useDOMOrder.ts ++var DOM_ORDER_SETTLE_MS = 150; ++function isUserScrolling(state) { ++ const { userScrollPrevTime, userScrollTime } = state; ++ return userScrollTime !== void 0 && userScrollPrevTime !== void 0 && userScrollTime - userScrollPrevTime < DOM_ORDER_SETTLE_MS && Date.now() - userScrollTime < DOM_ORDER_SETTLE_MS; ++} + function useDOMOrder(ref) { + const ctx = useStateContext(); +- const debounceRef = React3.useRef(void 0); +- React3.useEffect(() => { +- const unsubscribe = listen$(ctx, "lastPositionUpdate", () => { +- if (debounceRef.current !== void 0) { +- clearTimeout(debounceRef.current); +- } +- debounceRef.current = setTimeout(() => { +- const parent = ref.current; +- if (parent) { +- const indexByElement = /* @__PURE__ */ new Map(); +- for (const [containerId, viewRef] of ctx.viewRefs) { +- const element = viewRef.current; +- const index = peek$(ctx, `containerItemIndex${containerId}`); +- if (element && index !== void 0) { +- indexByElement.set(element, index); +- } +- } +- sortDOMElements(parent, indexByElement); ++ const [containerOrderUpdate] = useArr$(["containerOrderUpdate"]); ++ const settleRef = React3.useRef(void 0); ++ React3.useLayoutEffect(() => { ++ const sort = () => { ++ settleRef.current = void 0; ++ const parent = ref.current; ++ if (!parent) { ++ return; ++ } ++ const indexByElement = /* @__PURE__ */ new Map(); ++ for (const [containerId, viewRef] of ctx.viewRefs) { ++ const element = viewRef.current; ++ const index = peek$(ctx, `containerItemIndex${containerId}`); ++ if (element && index !== void 0) { ++ indexByElement.set(element, index); + } +- debounceRef.current = void 0; +- }, 500); +- }); +- return () => { +- unsubscribe(); +- if (debounceRef.current !== void 0) { +- clearTimeout(debounceRef.current); + } ++ sortDOMElements(parent, indexByElement); + }; +- }, [ctx]); ++ if (settleRef.current !== void 0) { ++ clearTimeout(settleRef.current); ++ } ++ // Before paint: NVDA's browse mode keeps the first DOM order it reads. Each move ++ // lays its row out again, so during a continuous scroll, sort once it settles. ++ if (!isUserScrolling(ctx.state)) { ++ sort(); ++ return; ++ } ++ const settle = () => { ++ if (isUserScrolling(ctx.state)) { ++ settleRef.current = setTimeout(settle, DOM_ORDER_SETTLE_MS); ++ } else { ++ sort(); ++ } ++ }; ++ settleRef.current = setTimeout(settle, DOM_ORDER_SETTLE_MS); ++ }, [ctx, containerOrderUpdate]); ++ React3.useEffect(() => () => { ++ if (settleRef.current !== void 0) { ++ clearTimeout(settleRef.current); ++ } ++ }, []); + } + function useFreshDataTransitionVisibility(readyToRender, transitionEpoch) { + const [completedTransitionEpoch, setCompletedTransitionEpoch] = React3.useState(transitionEpoch); +@@ -6446,8 +6517,8 @@ function ScrollAdjust() { + window.getComputedStyle(contentNode)[axis.paddingEndProp] + ); + const temporaryPaddingEnd = `${(currentPaddingEnd || 0) + pad}px`; +- temporaryPaddingRef.current = { baseline: baselinePaddingEnd, value: temporaryPaddingEnd }; + contentNode.style[axis.paddingEndProp] = temporaryPaddingEnd; ++ temporaryPaddingRef.current = { baseline: baselinePaddingEnd, value: contentNode.style[axis.paddingEndProp] }; + void contentNode.offsetHeight; + scrollBy(); + if (resetPaddingRafRef.current !== void 0) { +diff --git a/react.mjs b/react.mjs +index 95465f2ab89ce41a10553f58af83618f7310e83c..252a9d5b23e271c089d30c357a78dff754f1c899 100644 +--- a/react.mjs ++++ b/react.mjs +@@ -1887,6 +1887,10 @@ function updateScroll(ctx, newScroll, forceUpdate, options) { + state.scrollTime = currentTime; + const scrollDelta = Math.abs(newScroll - prevScroll); + const isUserScrollEvent = !!(options == null ? void 0 : options.fromNativeScrollEvent) && scrollDelta > 0.1 && !adjustChanged && scrollingTo === void 0 && !state.pendingNativeMVCPAdjust; ++ if (isUserScrollEvent) { ++ state.userScrollPrevTime = state.userScrollTime; ++ state.userScrollTime = currentTime; ++ } + const allowedEdge = isUserScrollEvent ? beginReachedEdgeUserScroll(ctx, newScroll - prevScroll) : void 0; + const didResolvePendingNativeMVCPAdjust = resolvePendingNativeMVCPAdjust(ctx, newScroll); + const scrollLength = state.scrollLength; +@@ -3236,6 +3240,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) { + const itemKey = (_a3 = state.idCache[itemIndex]) != null ? _a3 : getId(state, itemIndex); + const updateLayout = (_b = options == null ? void 0 : options.updateLayout) != null ? _b : true; + let didChangePosition = false; ++ let didChangeIndex = false; + let didRefreshData = false; + if (updateLayout) { + const positionValue = positions[itemIndex]; +@@ -3265,6 +3270,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) { + const prevIndex = peek$(ctx, `containerItemIndex${containerIndex}`); + if (prevIndex !== itemIndex) { + set$(ctx, `containerItemIndex${containerIndex}`, itemIndex); ++ didChangeIndex = true; + } + const prevData = peek$(ctx, `containerItemData${containerIndex}`); + const updateData = () => { +@@ -3303,7 +3309,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) { + } + } + } +- return { didChangePosition, didRefreshData }; ++ return { didChangeIndex, didChangePosition, didRefreshData }; + } + + // src/core/prepareColumnStartState.ts +@@ -3521,7 +3527,11 @@ function updateItemPositions(ctx, dataChanged, { + } + if (shouldOptimize && breakAt === void 0 && !scrollingTo && !dataChanged && currentRowTop > maxVisibleArea) { + const itemsPerRow = hasColumns ? numColumns : 1; +- breakAt = i + itemsPerRow + 10; ++ // alwaysRender rows stay mounted outside the visible window, so keep their ++ // positions current instead of leaving them where they were last laid out. ++ const pinnedIndices = state.props.alwaysRenderIndicesArr; ++ const lastPinnedIndex = pinnedIndices && pinnedIndices.length > 0 ? pinnedIndices[pinnedIndices.length - 1] : -1; ++ breakAt = Math.max(i + itemsPerRow + 10, lastPinnedIndex); + } + const id = (_e = idCache[i]) != null ? _e : getId(state, i); + let span = 1; +@@ -4222,6 +4232,7 @@ function calculateItemsInView(ctx, params = {}) { + } + let totalSize = getContentSize(ctx); + let changedContainerIds; ++ let didChangeContainerOrder = false; + const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "alignItemsAtEndPadding") + peek$(ctx, "headerSize"); + const numColumns = peek$(ctx, "numColumns"); + const speed = (_b = params.scrollVelocity) != null ? _b : getScrollVelocity(state); +@@ -4524,6 +4535,9 @@ function calculateItemsInView(ctx, params = {}) { + const containerIndex = allocation.containerIndex; + const id = (_o = idCache[i]) != null ? _o : getId(state, i); + const oldKey = peek$(ctx, `containerItemKey${containerIndex}`); ++ if (oldKey !== id || peek$(ctx, `containerItemIndex${containerIndex}`) !== i) { ++ didChangeContainerOrder = true; ++ } + if (oldKey && oldKey !== id) { + containerItemKeys.delete(oldKey); + } +@@ -4608,10 +4622,12 @@ function calculateItemsInView(ctx, params = {}) { + } else { + const itemIndex = indexByKey.get(itemKey); + if (itemIndex !== void 0) { +- didChangePositions = syncMountedContainer(ctx, i, itemIndex, { ++ const synced = syncMountedContainer(ctx, i, itemIndex, { + scrollAdjustPending, + updateLayout: true +- }).didChangePosition || didChangePositions; ++ }); ++ didChangePositions = synced.didChangePosition || didChangePositions; ++ didChangeContainerOrder = synced.didChangeIndex || didChangeContainerOrder; + } + } + } +@@ -4621,6 +4637,9 @@ function calculateItemsInView(ctx, params = {}) { + if (didChangePositions) { + set$(ctx, "lastPositionUpdate", Date.now()); + } ++ if (didChangeContainerOrder) { ++ set$(ctx, "containerOrderUpdate", (peek$(ctx, "containerOrderUpdate") || 0) + 1); ++ } + if (suppressInitialScrollSideEffects) { + evaluateBootstrapInitialScroll(ctx); + return; +@@ -4681,7 +4700,8 @@ function maybeUpdateAnchoredEndSpace(ctx) { + contentBelowAnchor = Math.max(0, contentBelowAnchor - ctx.scrollAxisGap); + contentBelowAnchor += (ctx.values.get("footerSize") || 0) + getStylePaddingEnd(state.props); + isReady = !hasUnknownTailSize; +- nextSize = hasUnknownTailSize ? previousSize || 0 : Math.max(0, state.scrollLength - contentBelowAnchor - anchorOffset); ++ const knownSizeBound = Math.max(0, state.scrollLength - contentBelowAnchor - anchorOffset); ++ nextSize = hasUnknownTailSize ? Math.min(previousSize || 0, knownSizeBound) : knownSizeBound; + } else if (anchorIndex >= 0) { + isReady = false; + } +@@ -4701,6 +4721,12 @@ function maybeUpdateAnchoredEndSpace(ctx) { + updateScroll(ctx, state.scroll, true, { markHasScrolled: false }); + } + (_b = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onReady) == null ? void 0 : _b.call(anchoredEndSpace, { anchorIndex: nextAnchorIndex, anchorKey: nextAnchorKey, size: nextSize }); ++ } else if (!isReady && didSizeChange && nextSize < (previousSize || 0)) { ++ set$(ctx, "anchoredEndSpaceSize", nextSize); ++ (_a3 = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onSizeChanged) == null ? void 0 : _a3.call(anchoredEndSpace, nextSize); ++ if (anchoredEndSpace == null ? void 0 : anchoredEndSpace.includeInEndInset) { ++ updateScroll(ctx, state.scroll, true, { markHasScrolled: false }); ++ } + } + return nextSize; + } +@@ -4935,7 +4961,8 @@ function measureContainersInLayoutEffect(ctx, targetContainerIds = null) { + const itemKey = peek$(ctx, `containerItemKey${containerId}`); + const element = viewRef == null ? void 0 : viewRef.current; + if (itemKey !== void 0 && element) { +- const rect = element.getBoundingClientRect(); ++ // Unlike getBoundingClientRect, offset sizes ignore ancestor transforms (e.g. a popup's zoom-in), like ResizeObserver. ++ const rect = { height: element.offsetHeight, width: element.offsetWidth }; + setContainerLayoutBaseline(element, rect); + measurements.push({ + containerId, +@@ -4957,12 +4984,26 @@ var ContainerLayoutCoordinator = typedMemo(function ContainerLayoutCoordinatorCo + }) { + const ctx = useStateContext(); + const [containerLayoutEpoch] = useArr$(["containerLayoutEpoch"]); ++ const layoutPasses = React3.useRef(0); + React3.useLayoutEffect(() => { +- { +- const targetContainerIds = getContainerLayoutEffectScope(ctx); +- if (targetContainerIds !== void 0) { +- measureContainersInLayoutEffect(ctx, targetContainerIds); +- } ++ const targetContainerIds = getContainerLayoutEffectScope(ctx); ++ if (targetContainerIds === void 0) return; ++ if (layoutPasses.current === 0) { ++ queueMicrotask(() => { layoutPasses.current = 0; }); ++ } ++ // Correcting large estimates can mount one row per commit. Bound the ++ // synchronous chain below React's nested-update limit, then keep measuring ++ // the latest pending rows on the next frame. Idle lists schedule no work. ++ if (layoutPasses.current++ < 8) { ++ measureContainersInLayoutEffect(ctx, targetContainerIds); ++ } else { ++ ctx.pendingContainerIds = targetContainerIds; ++ ctx.state.scheduledWork.frame(() => { ++ const pendingIds = getContainerLayoutEffectScope(ctx); ++ if (pendingIds !== void 0) { ++ measureContainersInLayoutEffect(ctx, pendingIds); ++ } ++ }, "containerLayout"); + } + }, [ctx, containerLayoutEpoch]); + return children; +@@ -5630,6 +5671,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) { + }); + + // src/utils/reordering.ts ++// Element.moveBefore keeps the moved subtree's state and does not count as an ++// insertion, so CSS @starting-style transitions and iframes inside a row do not ++// restart when the list reorders its containers. insertBefore is the fallback. ++function moveChildBefore(container, element, reference) { ++ if (typeof container.moveBefore === "function") { ++ container.moveBefore(element, reference); ++ } else if (reference) { ++ container.insertBefore(element, reference); ++ } else { ++ container.appendChild(element); ++ } ++} + function sortDOMElements(container, indexByElement) { + const elements = Array.from(container.children); + if (elements.length <= 1) return elements; +@@ -5669,9 +5722,9 @@ function sortDOMElements(container, indexByElement) { + } + } + if (nextStableElement) { +- container.insertBefore(element, nextStableElement); ++ moveChildBefore(container, element, nextStableElement); + } else { +- container.appendChild(element); ++ moveChildBefore(container, element, null); + } + } + } +@@ -5713,37 +5766,55 @@ function findLIS(arr) { + } + + // src/hooks/useDOMOrder.ts ++var DOM_ORDER_SETTLE_MS = 150; ++function isUserScrolling(state) { ++ const { userScrollPrevTime, userScrollTime } = state; ++ return userScrollTime !== void 0 && userScrollPrevTime !== void 0 && userScrollTime - userScrollPrevTime < DOM_ORDER_SETTLE_MS && Date.now() - userScrollTime < DOM_ORDER_SETTLE_MS; ++} + function useDOMOrder(ref) { + const ctx = useStateContext(); +- const debounceRef = useRef(void 0); +- useEffect(() => { +- const unsubscribe = listen$(ctx, "lastPositionUpdate", () => { +- if (debounceRef.current !== void 0) { +- clearTimeout(debounceRef.current); +- } +- debounceRef.current = setTimeout(() => { +- const parent = ref.current; +- if (parent) { +- const indexByElement = /* @__PURE__ */ new Map(); +- for (const [containerId, viewRef] of ctx.viewRefs) { +- const element = viewRef.current; +- const index = peek$(ctx, `containerItemIndex${containerId}`); +- if (element && index !== void 0) { +- indexByElement.set(element, index); +- } +- } +- sortDOMElements(parent, indexByElement); ++ const [containerOrderUpdate] = useArr$(["containerOrderUpdate"]); ++ const settleRef = useRef(void 0); ++ useLayoutEffect(() => { ++ const sort = () => { ++ settleRef.current = void 0; ++ const parent = ref.current; ++ if (!parent) { ++ return; ++ } ++ const indexByElement = /* @__PURE__ */ new Map(); ++ for (const [containerId, viewRef] of ctx.viewRefs) { ++ const element = viewRef.current; ++ const index = peek$(ctx, `containerItemIndex${containerId}`); ++ if (element && index !== void 0) { ++ indexByElement.set(element, index); + } +- debounceRef.current = void 0; +- }, 500); +- }); +- return () => { +- unsubscribe(); +- if (debounceRef.current !== void 0) { +- clearTimeout(debounceRef.current); + } ++ sortDOMElements(parent, indexByElement); + }; +- }, [ctx]); ++ if (settleRef.current !== void 0) { ++ clearTimeout(settleRef.current); ++ } ++ // Before paint: NVDA's browse mode keeps the first DOM order it reads. Each move ++ // lays its row out again, so during a continuous scroll, sort once it settles. ++ if (!isUserScrolling(ctx.state)) { ++ sort(); ++ return; ++ } ++ const settle = () => { ++ if (isUserScrolling(ctx.state)) { ++ settleRef.current = setTimeout(settle, DOM_ORDER_SETTLE_MS); ++ } else { ++ sort(); ++ } ++ }; ++ settleRef.current = setTimeout(settle, DOM_ORDER_SETTLE_MS); ++ }, [ctx, containerOrderUpdate]); ++ useEffect(() => () => { ++ if (settleRef.current !== void 0) { ++ clearTimeout(settleRef.current); ++ } ++ }, []); + } + function useFreshDataTransitionVisibility(readyToRender, transitionEpoch) { + const [completedTransitionEpoch, setCompletedTransitionEpoch] = useState(transitionEpoch); +@@ -6425,8 +6496,8 @@ function ScrollAdjust() { + window.getComputedStyle(contentNode)[axis.paddingEndProp] + ); + const temporaryPaddingEnd = `${(currentPaddingEnd || 0) + pad}px`; +- temporaryPaddingRef.current = { baseline: baselinePaddingEnd, value: temporaryPaddingEnd }; + contentNode.style[axis.paddingEndProp] = temporaryPaddingEnd; ++ temporaryPaddingRef.current = { baseline: baselinePaddingEnd, value: contentNode.style[axis.paddingEndProp] }; + void contentNode.offsetHeight; + scrollBy(); + if (resetPaddingRafRef.current !== void 0) { +diff --git a/reanimated.d.ts b/reanimated.d.ts +index e5043320700b12f34f4c0babbc341f85ca8135c1..e8cbd461325a2e2e9ffd61de26a85ae4d108555c 100644 +--- a/reanimated.d.ts ++++ b/reanimated.d.ts +@@ -285,6 +285,11 @@ interface LegendListSpecificProps { + * - true enables both behaviors; false disables both. + */ + maintainVisibleContentPosition?: boolean | MaintainVisibleContentPositionConfig; ++ /** ++ * T3 patch: the scroll offset a change in item or list size should leave, read in the same pass ++ * that repositions the items so the adjustment commits with them. `undefined` keeps the default. ++ */ ++ sizeChangeAnchor?: () => number | undefined; + /** + * Keeps an item visually anchored to the start by adding trailing space when the content below it underflows. + */ +@@ -294,6 +299,12 @@ interface LegendListSpecificProps { + * The adjustment is also rendered as real content padding so the browser scroll range includes it. + */ + contentInsetEndAdjustment?: number; ++ /** ++ * Width/height of a leading content inset applied natively outside the list's knowledge ++ * (e.g. iOS contentInsetAdjustmentBehavior="automatic" under a transparent header). ++ * Programmatic scrolls clamp to -adjustment instead of 0 so content can rest below the header. ++ */ ++ contentInsetStartAdjustment?: number; + /** + * Number of columns to render items in. + * @default 1 +diff --git a/reanimated.js b/reanimated.js +index f1265fad74189591b5aae86cf2e3a31f9c0fdb02..fc03be2190c046f743ffde45ed189ee7868d0cec 100644 +--- a/reanimated.js ++++ b/reanimated.js +@@ -115,8 +115,10 @@ var ReanimatedPositionView = typedMemo(function ReanimatedPositionViewComponent( + const { id, horizontal, style, refView, children, recycleItems, layoutTransition, ...rest } = props; + const [positionValue = POSITION_OUT_OF_VIEW] = useArr$([`containerPosition${id}`]); + const prevItemKeyRef = React__namespace.useRef(void 0); ++ const previousPositionRef = React__namespace.useRef(positionValue); ++ const lastContentSizeEpochRef = React__namespace.useRef(ctx.state.contentSizeAnimationEpoch || 0); + let shouldSkipTransitionForRecycleReuse = false; +- if (recycleItems && layoutTransition) { ++ if (layoutTransition) { + const itemKeySignal = `containerItemKey${id}`; + const itemKey = peek$(ctx, itemKeySignal); + shouldSkipTransitionForRecycleReuse = itemKey !== void 0 && prevItemKeyRef.current !== void 0 && prevItemKeyRef.current !== itemKey; +@@ -130,10 +132,29 @@ var ReanimatedPositionView = typedMemo(function ReanimatedPositionViewComponent( + () => [style, horizontal ? { left: positionValue } : { top: positionValue }], + [horizontal, positionValue, style] + ); ++ // Two kinds of repositions must not animate: (1) MVCP size adjustments, ++ // which are compensated by an equal contentOffset shift so the row should ++ // not visibly move — animating turns the invisible correction into a ++ // lurch-and-settle; (2) any reposition while the user is actively ++ // scrolling, where rows shifting under the finger reads as jank. The ++ // transition exists to smooth at-rest shifts (streaming text, work-log ++ // folds), so gate it to at-rest moments. ++ const now = Date.now(); ++ const contentSizeEpoch = ctx.state.contentSizeAnimationEpoch || 0; ++ const didPositionChange = positionValue !== previousPositionRef.current; ++ const isRawSizeReposition = didPositionChange && contentSizeEpoch !== lastContentSizeEpochRef.current && ctx.state.contentSizeAnimationEligible && !!layoutTransition && typeof layoutTransition.getAnimationAndConfig === "function"; ++ React__namespace.useLayoutEffect(() => { ++ if (didPositionChange) { ++ previousPositionRef.current = positionValue; ++ lastContentSizeEpochRef.current = contentSizeEpoch; ++ } ++ }, [contentSizeEpoch, didPositionChange, positionValue]); ++ const isRecentNativeReposition = now - (ctx.state.lastNativeScrollTime || 0) < 300; ++ const shouldSkipLayoutTransition = now - (ctx.state.lastMVCPAdjustTime || 0) < 300 || ctx.state.isUserDragging || ctx.state.isMomentumScrolling || isRecentNativeReposition && !isRawSizeReposition; + return /* @__PURE__ */ React__namespace.createElement( + Reanimated__default.default.View, + { +- layout: shouldSkipTransitionForRecycleReuse ? void 0 : layoutTransition, ++ layout: shouldSkipTransitionForRecycleReuse || shouldSkipLayoutTransition ? void 0 : layoutTransition, + ref: refView, + style: viewStyle, + ...rest +@@ -141,6 +162,95 @@ var ReanimatedPositionView = typedMemo(function ReanimatedPositionViewComponent( + children + ); + }); ++var ReanimatedSizeView = typedMemo(function ReanimatedSizeViewComponent(props) { ++ const ctx = useStateContext(); ++ const { horizontal, signalName, style, children, ...rest } = props; ++ const [logicalSize = 0] = useArr$(signalName === "totalSize" ? [signalName] : [signalName, "totalSize"]); ++ const baseSize = Reanimated.useSharedValue(logicalSize); ++ const animatedDelta = Reanimated.useSharedValue(0); ++ const previousLogicalSizeRef = React__namespace.useRef(logicalSize); ++ const previousEpochRef = React__namespace.useRef(ctx.state.contentSizeAnimationEpoch || 0); ++ const animationRunRef = React__namespace.useRef(0); ++ const isAnimatingRef = React__namespace.useRef(false); ++ const transition = props.layoutTransition; ++ const canAnimate = !!transition && typeof transition.getAnimationAndConfig === "function"; ++ const renderEpoch = ctx.state.contentSizeAnimationEpoch || 0; ++ // Keep the animated size attached after transitions finish. Reanimated ++ // retains removed animated props, so switching to a static size leaves ++ // native scroll bounds stuck while logical measurements keep changing. ++ const animatedStyle = Reanimated.useAnimatedStyle(() => { ++ const size = Math.max(0, baseSize.value + animatedDelta.value); ++ return horizontal ? { width: size } : { height: size }; ++ }, [horizontal]); ++ const completeAnimation = React__namespace.useCallback((run, epoch) => { ++ if (animationRunRef.current !== run) { ++ return; ++ } ++ isAnimatingRef.current = false; ++ const state = ctx.state; ++ if (state.contentSizeAnimationActiveEpoch !== epoch) { ++ return; ++ } ++ state.contentSizeAnimationActiveSignals.delete(signalName); ++ if (state.contentSizeAnimationActiveSignals.size === 0) { ++ state.contentSizeAnimationActiveEpoch = void 0; ++ state.contentSizeAnimationEligible = false; ++ } ++ }, [ctx.state, signalName]); ++ React__namespace.useLayoutEffect(() => { ++ const state = ctx.state; ++ const epoch = state.contentSizeAnimationEpoch || 0; ++ const previousLogicalSize = previousLogicalSizeRef.current; ++ const delta = logicalSize - previousLogicalSize; ++ const isNewEpoch = epoch !== previousEpochRef.current; ++ // Retarget measurements received mid-animation, even in the same epoch. ++ // Updating only the base keeps the old delta and can shrink scroll bounds. ++ const shouldAnimate = canAnimate && (isAnimatingRef.current || isNewEpoch && state.contentSizeAnimationEligible); ++ previousLogicalSizeRef.current = logicalSize; ++ previousEpochRef.current = epoch; ++ if (!delta) { ++ return; ++ } ++ if (!shouldAnimate) { ++ baseSize.value = logicalSize; ++ if (signalName === "totalSize" && isNewEpoch && state.contentSizeAnimationEligible && !canAnimate) { ++ state.contentSizeAnimationEligible = false; ++ } ++ return; ++ } ++ const [animation, config] = transition.getAnimationAndConfig(); ++ const delayFunction = typeof transition.getDelayFunction === "function" ? transition.getDelayFunction() : (_, value) => value; ++ const delay = typeof transition.getDelay === "function" ? transition.getDelay() : 0; ++ if (typeof animation !== "function" || typeof delayFunction !== "function") { ++ baseSize.value = logicalSize; ++ if (signalName === "totalSize") { ++ state.contentSizeAnimationEligible = false; ++ } ++ return; ++ } ++ if (state.contentSizeAnimationActiveEpoch !== epoch) { ++ state.contentSizeAnimationActiveEpoch = epoch; ++ state.contentSizeAnimationActiveSignals = /* @__PURE__ */ new Set(); ++ } ++ state.contentSizeAnimationActiveSignals.add(signalName); ++ const wasAnimating = isAnimatingRef.current; ++ isAnimatingRef.current = true; ++ const run = ++animationRunRef.current; ++ Reanimated.runOnUI((absoluteSize, previousSize, continuesAnimation, animationRun, animationEpoch) => { ++ "worklet"; ++ const currentVisualSize = continuesAnimation ? baseSize.value + animatedDelta.value : previousSize; ++ baseSize.value = absoluteSize; ++ animatedDelta.value = currentVisualSize - absoluteSize; ++ animatedDelta.value = delayFunction(delay, animation(0, config, (finished) => { ++ "worklet"; ++ if (finished) { ++ Reanimated.runOnJS(completeAnimation)(animationRun, animationEpoch); ++ } ++ })); ++ })(logicalSize, previousLogicalSize, wasAnimating, run, epoch); ++ }, [baseSize, animatedDelta, canAnimate, completeAnimation, ctx.state, logicalSize, renderEpoch, signalName, transition]); ++ return /* @__PURE__ */ React__namespace.createElement(Reanimated__default.default.View, { ...rest, style: [style, animatedStyle] }, children); ++}); + function setSharedValueValue(sharedValue, value) { + if (!sharedValue) { + return; +@@ -245,10 +355,19 @@ var LegendListForwardedRef = typedMemo( + ); + }; + }, [hasItemLayoutAnimation, recycleItems]); ++ const sizeComponentInternal = React__namespace.useMemo(() => { ++ if (!hasItemLayoutAnimation) { ++ return void 0; ++ } ++ return function SizeComponent(sizeProps) { ++ return /* @__PURE__ */ React__namespace.createElement(ReanimatedSizeView, { ...sizeProps, layoutTransition: itemLayoutAnimationRef.current }); ++ }; ++ }, [hasItemLayoutAnimation]); + const legendListProps = { + ...rest, + positionComponentInternal, + recycleItems, ++ sizeComponentInternal, + ...{ + renderScrollComponent: renderReanimatedScrollComponent, + ...IsNewArchitecture ? { stickyPositionComponentInternal } : {} +diff --git a/reanimated.mjs b/reanimated.mjs +index 29a00d5dc084fd408a0e0a0a4d64e856d0ed1525..6ab929250c8924e2d9919ee09a4f774238fbb90a 100644 +--- a/reanimated.mjs ++++ b/reanimated.mjs +@@ -1,7 +1,7 @@ + import * as React from 'react'; + import { useCallback } from 'react'; + import { View } from 'react-native'; +-import Reanimated, { useAnimatedRef, useAnimatedStyle, useSharedValue, useScrollViewOffset } from 'react-native-reanimated'; ++import Reanimated, { runOnJS, runOnUI, useAnimatedRef, useAnimatedStyle, useSharedValue, useScrollViewOffset } from 'react-native-reanimated'; + import { internal, LegendList } from '@legendapp/list/react-native'; + + // src/integrations/reanimated.tsx +@@ -91,8 +91,10 @@ var ReanimatedPositionView = typedMemo(function ReanimatedPositionViewComponent( + const { id, horizontal, style, refView, children, recycleItems, layoutTransition, ...rest } = props; + const [positionValue = POSITION_OUT_OF_VIEW] = useArr$([`containerPosition${id}`]); + const prevItemKeyRef = React.useRef(void 0); ++ const previousPositionRef = React.useRef(positionValue); ++ const lastContentSizeEpochRef = React.useRef(ctx.state.contentSizeAnimationEpoch || 0); + let shouldSkipTransitionForRecycleReuse = false; +- if (recycleItems && layoutTransition) { ++ if (layoutTransition) { + const itemKeySignal = `containerItemKey${id}`; + const itemKey = peek$(ctx, itemKeySignal); + shouldSkipTransitionForRecycleReuse = itemKey !== void 0 && prevItemKeyRef.current !== void 0 && prevItemKeyRef.current !== itemKey; +@@ -106,10 +108,29 @@ var ReanimatedPositionView = typedMemo(function ReanimatedPositionViewComponent( + () => [style, horizontal ? { left: positionValue } : { top: positionValue }], + [horizontal, positionValue, style] + ); ++ // Two kinds of repositions must not animate: (1) MVCP size adjustments, ++ // which are compensated by an equal contentOffset shift so the row should ++ // not visibly move — animating turns the invisible correction into a ++ // lurch-and-settle; (2) any reposition while the user is actively ++ // scrolling, where rows shifting under the finger reads as jank. The ++ // transition exists to smooth at-rest shifts (streaming text, work-log ++ // folds), so gate it to at-rest moments. ++ const now = Date.now(); ++ const contentSizeEpoch = ctx.state.contentSizeAnimationEpoch || 0; ++ const didPositionChange = positionValue !== previousPositionRef.current; ++ const isRawSizeReposition = didPositionChange && contentSizeEpoch !== lastContentSizeEpochRef.current && ctx.state.contentSizeAnimationEligible && !!layoutTransition && typeof layoutTransition.getAnimationAndConfig === "function"; ++ React.useLayoutEffect(() => { ++ if (didPositionChange) { ++ previousPositionRef.current = positionValue; ++ lastContentSizeEpochRef.current = contentSizeEpoch; ++ } ++ }, [contentSizeEpoch, didPositionChange, positionValue]); ++ const isRecentNativeReposition = now - (ctx.state.lastNativeScrollTime || 0) < 300; ++ const shouldSkipLayoutTransition = now - (ctx.state.lastMVCPAdjustTime || 0) < 300 || ctx.state.isUserDragging || ctx.state.isMomentumScrolling || isRecentNativeReposition && !isRawSizeReposition; + return /* @__PURE__ */ React.createElement( + Reanimated.View, + { +- layout: shouldSkipTransitionForRecycleReuse ? void 0 : layoutTransition, ++ layout: shouldSkipTransitionForRecycleReuse || shouldSkipLayoutTransition ? void 0 : layoutTransition, + ref: refView, + style: viewStyle, + ...rest +@@ -117,6 +138,95 @@ var ReanimatedPositionView = typedMemo(function ReanimatedPositionViewComponent( + children + ); + }); ++var ReanimatedSizeView = typedMemo(function ReanimatedSizeViewComponent(props) { ++ const ctx = useStateContext(); ++ const { horizontal, signalName, style, children, ...rest } = props; ++ const [logicalSize = 0] = useArr$(signalName === "totalSize" ? [signalName] : [signalName, "totalSize"]); ++ const baseSize = useSharedValue(logicalSize); ++ const animatedDelta = useSharedValue(0); ++ const previousLogicalSizeRef = React.useRef(logicalSize); ++ const previousEpochRef = React.useRef(ctx.state.contentSizeAnimationEpoch || 0); ++ const animationRunRef = React.useRef(0); ++ const isAnimatingRef = React.useRef(false); ++ const transition = props.layoutTransition; ++ const canAnimate = !!transition && typeof transition.getAnimationAndConfig === "function"; ++ const renderEpoch = ctx.state.contentSizeAnimationEpoch || 0; ++ // Keep the animated size attached after transitions finish. Reanimated ++ // retains removed animated props, so switching to a static size leaves ++ // native scroll bounds stuck while logical measurements keep changing. ++ const animatedStyle = useAnimatedStyle(() => { ++ const size = Math.max(0, baseSize.value + animatedDelta.value); ++ return horizontal ? { width: size } : { height: size }; ++ }, [horizontal]); ++ const completeAnimation = useCallback((run, epoch) => { ++ if (animationRunRef.current !== run) { ++ return; ++ } ++ isAnimatingRef.current = false; ++ const state = ctx.state; ++ if (state.contentSizeAnimationActiveEpoch !== epoch) { ++ return; ++ } ++ state.contentSizeAnimationActiveSignals.delete(signalName); ++ if (state.contentSizeAnimationActiveSignals.size === 0) { ++ state.contentSizeAnimationActiveEpoch = void 0; ++ state.contentSizeAnimationEligible = false; ++ } ++ }, [ctx.state, signalName]); ++ React.useLayoutEffect(() => { ++ const state = ctx.state; ++ const epoch = state.contentSizeAnimationEpoch || 0; ++ const previousLogicalSize = previousLogicalSizeRef.current; ++ const delta = logicalSize - previousLogicalSize; ++ const isNewEpoch = epoch !== previousEpochRef.current; ++ // Retarget measurements received mid-animation, even in the same epoch. ++ // Updating only the base keeps the old delta and can shrink scroll bounds. ++ const shouldAnimate = canAnimate && (isAnimatingRef.current || isNewEpoch && state.contentSizeAnimationEligible); ++ previousLogicalSizeRef.current = logicalSize; ++ previousEpochRef.current = epoch; ++ if (!delta) { ++ return; ++ } ++ if (!shouldAnimate) { ++ baseSize.value = logicalSize; ++ if (signalName === "totalSize" && isNewEpoch && state.contentSizeAnimationEligible && !canAnimate) { ++ state.contentSizeAnimationEligible = false; ++ } ++ return; ++ } ++ const [animation, config] = transition.getAnimationAndConfig(); ++ const delayFunction = typeof transition.getDelayFunction === "function" ? transition.getDelayFunction() : (_, value) => value; ++ const delay = typeof transition.getDelay === "function" ? transition.getDelay() : 0; ++ if (typeof animation !== "function" || typeof delayFunction !== "function") { ++ baseSize.value = logicalSize; ++ if (signalName === "totalSize") { ++ state.contentSizeAnimationEligible = false; ++ } ++ return; ++ } ++ if (state.contentSizeAnimationActiveEpoch !== epoch) { ++ state.contentSizeAnimationActiveEpoch = epoch; ++ state.contentSizeAnimationActiveSignals = /* @__PURE__ */ new Set(); ++ } ++ state.contentSizeAnimationActiveSignals.add(signalName); ++ const wasAnimating = isAnimatingRef.current; ++ isAnimatingRef.current = true; ++ const run = ++animationRunRef.current; ++ runOnUI((absoluteSize, previousSize, continuesAnimation, animationRun, animationEpoch) => { ++ "worklet"; ++ const currentVisualSize = continuesAnimation ? baseSize.value + animatedDelta.value : previousSize; ++ baseSize.value = absoluteSize; ++ animatedDelta.value = currentVisualSize - absoluteSize; ++ animatedDelta.value = delayFunction(delay, animation(0, config, (finished) => { ++ "worklet"; ++ if (finished) { ++ runOnJS(completeAnimation)(animationRun, animationEpoch); ++ } ++ })); ++ })(logicalSize, previousLogicalSize, wasAnimating, run, epoch); ++ }, [baseSize, animatedDelta, canAnimate, completeAnimation, ctx.state, logicalSize, renderEpoch, signalName, transition]); ++ return /* @__PURE__ */ React.createElement(Reanimated.View, { ...rest, style: [style, animatedStyle] }, children); ++}); + function setSharedValueValue(sharedValue, value) { + if (!sharedValue) { + return; +@@ -221,10 +331,19 @@ var LegendListForwardedRef = typedMemo( + ); + }; + }, [hasItemLayoutAnimation, recycleItems]); ++ const sizeComponentInternal = React.useMemo(() => { ++ if (!hasItemLayoutAnimation) { ++ return void 0; ++ } ++ return function SizeComponent(sizeProps) { ++ return /* @__PURE__ */ React.createElement(ReanimatedSizeView, { ...sizeProps, layoutTransition: itemLayoutAnimationRef.current }); ++ }; ++ }, [hasItemLayoutAnimation]); + const legendListProps = { + ...rest, + positionComponentInternal, + recycleItems, ++ sizeComponentInternal, + ...{ + renderScrollComponent: renderReanimatedScrollComponent, + ...IsNewArchitecture ? { stickyPositionComponentInternal } : {} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 71019619..dfc473c7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -183,6 +183,9 @@ catalogs: overrides: run: 2.1.8 +patchedDependencies: + '@legendapp/list@3.3.5': 6cbdacd8c380d9a5afb9f73d4198dc2cc44be6ef28a955b1183c781469307896 + importers: .: @@ -211,6 +214,9 @@ importers: eslint-plugin-better-tailwindcss: specifier: 4.10.0 version: 4.10.0(oxlint@1.81.0(oxlint-tsgolint@7.0.2001)(vite-plus@0.3.1(@opentelemetry/api@1.9.1)(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(typescript@7.0.2)(yaml@2.9.1)))(tailwindcss@4.3.3)(typescript@7.0.2) + knip: + specifier: 6.34.0 + version: 6.34.0 typescript: specifier: 'catalog:' version: 7.0.2 @@ -302,7 +308,7 @@ importers: version: 1.1.10(react@19.3.1) '@legendapp/list': specifier: 3.3.5 - version: 3.3.5(react-dom@19.3.1(react@19.3.1))(react@19.3.1) + version: 3.3.5(patch_hash=6cbdacd8c380d9a5afb9f73d4198dc2cc44be6ef28a955b1183c781469307896)(react-dom@19.3.1(react@19.3.1))(react@19.3.1) '@pierre/trees': specifier: 1.0.0-beta.6 version: 1.0.0-beta.6(@shikijs/themes@4.5.0)(react-dom@19.3.1(react@19.3.1))(react@19.3.1)(shiki@4.4.3) @@ -1711,12 +1717,18 @@ packages: '@emnapi/core@1.11.1': resolution: {integrity: sha512-RSvbQmHzdKzNsLYa/wHrbc3KN4sYLKAdPZxqiM2HATqv/SBk2/ENSHpvXGaLOMcsAyz0poEGqkmmKYG3OWiJEQ==} + '@emnapi/core@1.11.2': + resolution: {integrity: sha512-TC8MkTuZUtcTSiFeuC0ksCh9QIJ5+F21MvZ4Wn4ORfYaFJ/0dsiudv5tVkejgwZlwQ39jL9WWDe2lz8x0WglOA==} + '@emnapi/core@1.11.3': resolution: {integrity: sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg==} '@emnapi/runtime@1.11.1': resolution: {integrity: sha512-vgj7R3y3Wgx24IQaGPA/R6YFXLHVMOZ0uVEyIQPaWs+rd1AzfEMXlAC22FYwO1XkKR6NPsq7mUandH8oIRdZFw==} + '@emnapi/runtime@1.11.2': + resolution: {integrity: sha512-kyOl3X0DuTiT1h2ft8r2fYO8JYtU9a9Xis/zBSiGArNaagCOWx90N1k2wxp18czFDH+OgcWGb5ZP/XMt3dcyPA==} + '@emnapi/runtime@1.11.3': resolution: {integrity: sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==} @@ -2655,48 +2667,97 @@ packages: '@oslojs/encoding@1.1.0': resolution: {integrity: sha512-70wQhgYmndg4GCPxPPxPGevRKqTIJ2Nh4OkiMWmDAVYsTQ+Ta7Sq+rPevXyXGdzr30/qZBnyOalCszoMxlyldQ==} + '@oxc-parser/binding-android-arm-eabi@0.147.0': + resolution: {integrity: sha512-fOtoGvIoirkvxQVw9J1WJPxz571XPgLsPf9uhRD+PJteUnvrJHMDmK9pw2yZEGGyismtRoEsp+JcXUdF/JDMDw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [android] + '@oxc-parser/binding-android-arm-eabi@0.148.0': resolution: {integrity: sha512-pHASv9g5pASxb7akHERZNSkrEqPhFaUix98o7d9hbTpolnnFWl7UiRrcMhCsV1+iVO4/cJwKsbKRJTFNs2tdBQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm] os: [android] + '@oxc-parser/binding-android-arm64@0.147.0': + resolution: {integrity: sha512-emjQHOYJaomo4ykaXQ1EItunr/I94Nk01oqBmU4dSkKSTupIDx6OysVDf2e8Eytm77rb+4ZxzgElyWP7rcEX7A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [android] + '@oxc-parser/binding-android-arm64@0.148.0': resolution: {integrity: sha512-sg/6Ez0KdAygsu0POELux9wN1Po2CP93WY8eNl4DBKIGprsd4QSHBXOb471Pu9i2OCD5sLkISSb2agZEhVn2Zw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [android] + '@oxc-parser/binding-darwin-arm64@0.147.0': + resolution: {integrity: sha512-kXvBPJL7RmDPJ2mze/vXPPVQimCDtFr9OFLjf7dyhV5Dx64cgcXh9KKrA1sMWvCObvJll9CZZUO0FBlFwD0l6A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [darwin] + '@oxc-parser/binding-darwin-arm64@0.148.0': resolution: {integrity: sha512-yiSJmzGUvCUaJT8X3j40gVcX+ckuHQMuiOtF8DvzTs5+JtB/7XuHFPp4M+vv5u+HlBtDUd4Ks5pyHpWz8mfnkg==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [darwin] + '@oxc-parser/binding-darwin-x64@0.147.0': + resolution: {integrity: sha512-mgFF8pLU6R64LbT27lSrtVRspVC/3IcZ0qyIikzmi78Y3Ik2OPnlAHHI0UEBRcC3qmNgtjaef7zkFt7/uPxIcw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [darwin] + '@oxc-parser/binding-darwin-x64@0.148.0': resolution: {integrity: sha512-6ZeklaamrMy4H2JmhvcJg6iip59tYILtuLaILxyAHT3l5FDxnI5ihVievAft5ZmAbqtlWHErOi1OpJK8gy1wcA==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [darwin] + '@oxc-parser/binding-freebsd-x64@0.147.0': + resolution: {integrity: sha512-v38aiF11qufOTBcCAKL4skgQf0zJ4NEvRlivq7B5kHrlyvjCLjvNrMtNWDTz1SDUL6/xVsJRmLDxv2e+Cp4oWw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [freebsd] + '@oxc-parser/binding-freebsd-x64@0.148.0': resolution: {integrity: sha512-vFsPx+a/qFECPnz/H8nC6x6MDvnWscLTCo/5muojEF54ERUq1kdgbvnWo95YnkhjF9sTIcG/uDxQBh1gffaufQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [freebsd] + '@oxc-parser/binding-linux-arm-gnueabihf@0.147.0': + resolution: {integrity: sha512-AeIiBbwUaP0H1+4/qGW9l5qHecS/+XA5iMuieVcGb1T+tyc2dVGspFW13BWk/XrLsiGP/CiDJTJqAPLLCzZHkw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [linux] + '@oxc-parser/binding-linux-arm-gnueabihf@0.148.0': resolution: {integrity: sha512-eOr3M+6iGbbxNL4PSS0VtsyQ2eOUxSBh00BqO22SbolDimPSYsBuLr/LCrZBkiqW2BoabhR6V4R8jrRAay7hjg==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm] os: [linux] + '@oxc-parser/binding-linux-arm-musleabihf@0.147.0': + resolution: {integrity: sha512-/41MKPW4RgPY4DJco0NCF0RYX3IMZaVlRNMNzvhaxRavc7tN3Txm+qllZbh0aMRs0VHdgUlbI8TcAOiTai4TKg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [linux] + '@oxc-parser/binding-linux-arm-musleabihf@0.148.0': resolution: {integrity: sha512-58ZKDw0mQRbCNfrd2IDyV4o8T7enzGERJn41BH2tjrZVGyiKiFzcfDicuB7Zcpb/1xIOrObovr8Dja6lZi8dLw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm] os: [linux] + '@oxc-parser/binding-linux-arm64-gnu@0.147.0': + resolution: {integrity: sha512-bmpw/RPhVXgZbtb3xBDuwW5s8+LvZYdqcDSX/sP2ltL77aTio3DP/B5ZTwwgoJ6Mr9vJs4RrmgEKW9XkLNUU1g==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [glibc] + '@oxc-parser/binding-linux-arm64-gnu@0.148.0': resolution: {integrity: sha512-Fnu95O4eZ5i++GPvIzBEZ8y4ddTLR+D9paYa8JRaRk6ZK7nHQiWP5xtrhcPQsXqgat1d7sU/d5rbbI0p1FTHSQ==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2704,6 +2765,13 @@ packages: os: [linux] libc: [glibc] + '@oxc-parser/binding-linux-arm64-musl@0.147.0': + resolution: {integrity: sha512-gd7VX/FDVOw6mjQcu45iIcp4QkgybgJwh3a0OFG2NxmPCj628mQWD96QGu1kK8+mZF9qK4b/gIEyC63vQoB7+Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [musl] + '@oxc-parser/binding-linux-arm64-musl@0.148.0': resolution: {integrity: sha512-3CQy/BMdx7N7H3qrcPxUL+a2CwUZodUcf6oq8iJuNZ9C6Ol1aq3mcWzsgySJ7CHFLvpX21ZDPp1r1X0QLbu/AQ==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2711,6 +2779,13 @@ packages: os: [linux] libc: [musl] + '@oxc-parser/binding-linux-ppc64-gnu@0.147.0': + resolution: {integrity: sha512-HnAzcfki7dSUNHf510Q2NmbJlz8Ys7rn8l9l588Pkx0tYe1BHLZnmELIgqizJ4WPhHGSwN8Ce+B/menVxS3odA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [ppc64] + os: [linux] + libc: [glibc] + '@oxc-parser/binding-linux-ppc64-gnu@0.148.0': resolution: {integrity: sha512-9LkaYvfiF8hMOw900csAvkf1oxE8XlmMeGowu5BcastSSwV8mKvKRMNU7HsV+ycyj1dQD8pX5qgOw8ja6SJacg==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2718,6 +2793,13 @@ packages: os: [linux] libc: [glibc] + '@oxc-parser/binding-linux-riscv64-gnu@0.147.0': + resolution: {integrity: sha512-qlkOL6wT44U+fT5s/+sR6Shx0OdwvQF83JyIPZUxG/ovqZF5/7atOtjH+JPZ5/7ATQLbFBBSmghcy/+2NVB/ew==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [riscv64] + os: [linux] + libc: [glibc] + '@oxc-parser/binding-linux-riscv64-gnu@0.148.0': resolution: {integrity: sha512-2GBiM9h26dR4WJfhoMvnFMnFLf7m/kYs4UMqjvrOfQG4BV1nuTJDH22Zc2MQr3INZF7nSKYQ6xlhD3hQ7A6gug==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2725,6 +2807,13 @@ packages: os: [linux] libc: [glibc] + '@oxc-parser/binding-linux-riscv64-musl@0.147.0': + resolution: {integrity: sha512-DlefD7L7sMXs/3hIBH23Egk0phj8kG0SA81dVGOQ3S1ekjOlmTLH2E+F2Thwfh1slKx6aH+lNc5fQYAw0GU7/g==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [riscv64] + os: [linux] + libc: [musl] + '@oxc-parser/binding-linux-riscv64-musl@0.148.0': resolution: {integrity: sha512-uPqZexvKJmEgq4mAu36qe2xTfXZE7oyik1R7KtZ5tl8qKlq1U1fIqTFRUEBZqRGvforoTrGIpatRzcoPKO66RA==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2732,6 +2821,13 @@ packages: os: [linux] libc: [musl] + '@oxc-parser/binding-linux-s390x-gnu@0.147.0': + resolution: {integrity: sha512-Xqpagk/031IvZ4svrk2FF01YEqM/iN3MJV3SVZadKg/CsGlDCGoREqKHXYnoV5+8SfGe/m6RM1szXFLusTu/Uw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [s390x] + os: [linux] + libc: [glibc] + '@oxc-parser/binding-linux-s390x-gnu@0.148.0': resolution: {integrity: sha512-9oUHvnTbp7ZraFsTC8PN6XhdhPSSxZumYvixWl7Smi353gEULvK6yV0sXNVrdFMHQeaDKFCi8TgDhNK7/A+Y+Q==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2739,6 +2835,13 @@ packages: os: [linux] libc: [glibc] + '@oxc-parser/binding-linux-x64-gnu@0.147.0': + resolution: {integrity: sha512-QioQOeUbI4ATUr0S2z88uA3Cds2R3Mm5Ge7U8XNYtlTb2GJF3rWlcj70z0AJhhOlbdm0YgVjqPBldUNbFylDIg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [glibc] + '@oxc-parser/binding-linux-x64-gnu@0.148.0': resolution: {integrity: sha512-2qhDSJwKzbSZzF7lDqqk8sr/yXsmwr3PeUa4/nazIF+zFAYz1gVPEfC34GQtGxzJUUmklaYAL63368LEfrMeyw==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2746,6 +2849,13 @@ packages: os: [linux] libc: [glibc] + '@oxc-parser/binding-linux-x64-musl@0.147.0': + resolution: {integrity: sha512-NXy1tv/OdC+pPTwf9RiCZWPK53V/Xq/2cjSnjOSyKopajdaDqMIkgtDY+jXZemp2e8px5FeWfY2L2LwhKZQovg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [musl] + '@oxc-parser/binding-linux-x64-musl@0.148.0': resolution: {integrity: sha512-qQoPDZUFV0bh9xA09XydmkjMBpgc1ukJuhMvzQ9QeVmFaHTS9W5TE5CoLmSl3QQyUP9OuHO3x/WPZTIIZPWR3Q==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2753,24 +2863,48 @@ packages: os: [linux] libc: [musl] + '@oxc-parser/binding-openharmony-arm64@0.147.0': + resolution: {integrity: sha512-GpGWZ6oKz4bjCWW9Mz5pCaGPyk2Aaze6zEoaslIQqpSLtpx5pXj/ap5gUNb5Jn2LIbqWyjkGLX9yv3NMuNcBVQ==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [openharmony] + '@oxc-parser/binding-openharmony-arm64@0.148.0': resolution: {integrity: sha512-1UGbaQWEXUCLqAmaR5kwRDjx/R4S5LQKZkM9CHmaHkuKhriOF32aRLfS0jCRNE2yGQJLMEA1z9UucbBVqjXnDw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [openharmony] + '@oxc-parser/binding-win32-arm64-msvc@0.147.0': + resolution: {integrity: sha512-a8mlt7CC8z7LUdCfaxhff4kCd+vSjE+NEFL0cxA8ukfuSnvAto/pWTjytW4BuVLnQGcCVdHJwcRKOfs++H+tjw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [win32] + '@oxc-parser/binding-win32-arm64-msvc@0.148.0': resolution: {integrity: sha512-pWKdzRDNG2+NK4h/V6U/CYERcfYD6u28h5IB/VJVsrZaD3muvE58tUj22lieL5vLZ+XFi1GPv9YXckZbJZ9BLA==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [win32] + '@oxc-parser/binding-win32-ia32-msvc@0.147.0': + resolution: {integrity: sha512-M5ViVDBcFLnl2632AuuWuP35zEL5oikK1jTx8r3+902VEDeSNHxFZAB6RZyfZ7MU6Oi5QTOG8MmMkIeHsudSaw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [ia32] + os: [win32] + '@oxc-parser/binding-win32-ia32-msvc@0.148.0': resolution: {integrity: sha512-i3p4x+mvwtjcE1J5HM6V7ggsbXiznExN/4MkNyOy3dfXrVV3bnkSfmZxvo6/84qCVX4ShkpNE1SKt9biIF31GQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [ia32] os: [win32] + '@oxc-parser/binding-win32-x64-msvc@0.147.0': + resolution: {integrity: sha512-DUaE13OwnUSlHpLZNcC/nuT10ivlWqc5EZgsfgXuAmWYw0r3nDxGeLD1zlGwYwIgVk1/ZMAxoXpV+05stvbHaA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [win32] + '@oxc-parser/binding-win32-x64-msvc@0.148.0': resolution: {integrity: sha512-Ye6vB7VQulghWYkYkECOBYFRVEizz4XyRTUAv+t8BuyurhKU7uD0P9eowL+mKG5Mf8MSYx+DI3Cm8SKZvYG7bQ==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2784,6 +2918,9 @@ packages: '@oxc-project/types@0.146.0': resolution: {integrity: sha512-XC0QsnnhVe7sLIWmYmdPw7x5P0h4W8vUU3Nv1ySgWXtvCz8NizoAEpGXA0sOYoJQV2Rl13LgURAHQ5cI5ILCSA==} + '@oxc-project/types@0.147.0': + resolution: {integrity: sha512-IJ3s6ltHLp45S0bh7phkX+gJO7A1Wuz2EaqpAhb8WjqDwbzMiWKHhyyT42tskaWjEYXtHtVCPpnBJVT9+dcRLg==} + '@oxc-project/types@0.148.0': resolution: {integrity: sha512-Nm4s/jB+4FpFsPhWGEC4h7rzksesmtnMXomo6rCMcg/b8zLQuOziRgkCS1fxDCXOlJB/6Q8oABOZ/OP6RIPj9A==} @@ -2793,6 +2930,109 @@ packages: '@oxc-project/types@0.154.0': resolution: {integrity: sha512-KYOUGQFlLWR+s4QMV2Q9ko38TZm7EdO87Qm7rvZLqk/webse/cDjtyxKhg/47l0byCbs/k46LT8qc4PKjAikzA==} + '@oxc-resolver/binding-android-arm-eabi@11.24.2': + resolution: {integrity: sha512-y09e0L0SRI2OA2tUIrjBgoV3eH5hvUKXNkJqXmNo5V2WxIjyC7I7aJfRLMEVpA8yi95f90gFDvO0VMgrDw+vwA==} + cpu: [arm] + os: [android] + + '@oxc-resolver/binding-android-arm64@11.24.2': + resolution: {integrity: sha512-cl4icWaZFnLdg8m6qtnh5rBMuGbxc/ptStFHLeCNwr+2cZjkjNwQu/jYRS0CHlnPecOJMpuS5M6/BH+0J/YkEg==} + cpu: [arm64] + os: [android] + + '@oxc-resolver/binding-darwin-arm64@11.24.2': + resolution: {integrity: sha512-At29QEMF6HajbQvgY8K6OXnHD1x9rad74xBEfmCB6ZqCGsdq75aK7tOYcTbOanMy8qdIBrfL3SMr3p/lfSlb9w==} + cpu: [arm64] + os: [darwin] + + '@oxc-resolver/binding-darwin-x64@11.24.2': + resolution: {integrity: sha512-A5Kqr1EUj4oIL5CF4WRssq/o5P0Y11cwoFouMRmQ7YnC/A8V93nv1nb7aSU8HwcgmXropjLNkVTl4MN87cu28Q==} + cpu: [x64] + os: [darwin] + + '@oxc-resolver/binding-freebsd-x64@11.24.2': + resolution: {integrity: sha512-R5xkRBRRz7ceH/P5Jrc6G7FmdUdgpLYyESFAUDVTNQ9K0sGPxcp4ljiwEwEqsvNcQ4sYbMRrWcHHBCu7ksAJVw==} + cpu: [x64] + os: [freebsd] + + '@oxc-resolver/binding-linux-arm-gnueabihf@11.24.2': + resolution: {integrity: sha512-k/RuYL4L/R58IBn3wT5ma3Wh4k62bp1eYCFRWCmMsasUOqL+H6sW0VGFadEzKWXFFlz+2uIMoeMk9ySSZJHgbg==} + cpu: [arm] + os: [linux] + + '@oxc-resolver/binding-linux-arm-musleabihf@11.24.2': + resolution: {integrity: sha512-bnHAak3ujYfH5pKk4NieFNbvYvernfoQDgwLddbZ3OtMYrem87/qjlA+u+aKG0oZcqSLGCful/6/CEA+aeAgaA==} + cpu: [arm] + os: [linux] + + '@oxc-resolver/binding-linux-arm64-gnu@11.24.2': + resolution: {integrity: sha512-vDT3KHgzYp47gmtNOqL2VNhCyl5Zv643eyxm//A68J8DeUGXrvD1pZFiaT4jSfe+RInfnn1R2yVHye4enx6RnA==} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@oxc-resolver/binding-linux-arm64-musl@11.24.2': + resolution: {integrity: sha512-+kMlQvbzfyEYtu5FcjE4p+ttBLpKW4d/AsAsuE69BxV6V4twZJeIQZFfD8gh/wqglY0MkPSezWXQH0jBV13MUw==} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@oxc-resolver/binding-linux-ppc64-gnu@11.24.2': + resolution: {integrity: sha512-shjfMhmZ3gq9fv/w7bi3PnZlgOPG+2QAOFf0BJF0EgBSIGZ6PMLN2zbGEblTUYB/NKVDRyYhE2ff3dJ1QqNPkA==} + cpu: [ppc64] + os: [linux] + libc: [glibc] + + '@oxc-resolver/binding-linux-riscv64-gnu@11.24.2': + resolution: {integrity: sha512-zGelwFR5oRo+b69k8Lrzun86DyUHzfKN6cnjbR9l7Z7NIRznOE/2ZvPa1IUKqAL2PzAXOdwkfVqNvO1H2RlpAw==} + cpu: [riscv64] + os: [linux] + libc: [glibc] + + '@oxc-resolver/binding-linux-riscv64-musl@11.24.2': + resolution: {integrity: sha512-qxZ1SWCXJY0eyhAlP6Lmo9F2Nrtx7EkYj9oCgL8apDPCwXwCEDA2U697bbT81JIc2IrVjxO4KX6WU2N+oN9Z4w==} + cpu: [riscv64] + os: [linux] + libc: [musl] + + '@oxc-resolver/binding-linux-s390x-gnu@11.24.2': + resolution: {integrity: sha512-sGCecF3cx2DFlH4t/z7ApnOnXqN48p5p5mlHDEnHTAukQa2P+qMVE4CwyWE9W+q/m3QJ7kKfGrIjax31f44oFQ==} + cpu: [s390x] + os: [linux] + libc: [glibc] + + '@oxc-resolver/binding-linux-x64-gnu@11.24.2': + resolution: {integrity: sha512-k/VlMMcSzMlahb3/fENM4rTlsJ0s3fFROA0KXPBmKggqmTSaE383sl8F3KCOXPLmVsYfW6hCitMhXCEtNeZxxg==} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@oxc-resolver/binding-linux-x64-musl@11.24.2': + resolution: {integrity: sha512-8hbnZyNi97b/8wapYaIF9+t9GmZKBW2vunaOc3h9HGJptH7b7XpvZqOTBSm/MpTjr7H497BlgOaSfLUdhmy2bw==} + cpu: [x64] + os: [linux] + libc: [musl] + + '@oxc-resolver/binding-openharmony-arm64@11.24.2': + resolution: {integrity: sha512-MvyGik3a6pVgZ0t/kWlbmFxFLmXQJwgLsY2eYFHLpy0wGwRbfzeIGgDwQ3kXqE30z+kSXennRkCrT7TUvkptNg==} + cpu: [arm64] + os: [openharmony] + + '@oxc-resolver/binding-wasm32-wasi@11.24.2': + resolution: {integrity: sha512-vHcssMPwO08RTvj/c0iOBz90attxyG3wQJ0dTcyEQK43LRpcdLWZlV5feBhv6Isn6ahbQIzHbCgfa81+RiML0Q==} + engines: {node: '>=14.0.0'} + cpu: [wasm32] + + '@oxc-resolver/binding-win32-arm64-msvc@11.24.2': + resolution: {integrity: sha512-uokJqro2iBqkFvJdKQLP7d8/BUmFwESQFVmIJUQKj1Xn1a/LysJoe1vmeECLF5b3jsV8CAL5sEMJXX6SdK9Nhg==} + cpu: [arm64] + os: [win32] + + '@oxc-resolver/binding-win32-x64-msvc@11.24.2': + resolution: {integrity: sha512-UqGPmo56KDfLlfXFAFIrNflHT8tFxWGEivWg3Zeyp4Uy2NlKN1FGPr6/BxcLGG3+kZ6Wp14g5Uj+n71boqZfiw==} + cpu: [x64] + os: [win32] + '@oxfmt/binding-android-arm-eabi@0.66.0': resolution: {integrity: sha512-2Me9eoptv6ERdEuI2P8AOlYdHHraXebJaM6SC0kc2Dfb+mLrep2db+fedBPKaYn673h/vBgvP4tkOdAbaudX6w==} engines: {node: ^20.19.0 || >=22.12.0} @@ -6145,6 +6385,9 @@ packages: fastq@1.20.3: resolution: {integrity: sha512-XKv5nnLs6nLF71NgiKJLIZFLkPyIEuOselLG7ujZnGrRfQK8HpvY+WqKhAJUAdLomwVHErVS4LfxFlPq0/FTAw==} + fd-package-json@2.0.0: + resolution: {integrity: sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ==} + fdir@6.5.0: resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==} engines: {node: '>=12.0.0'} @@ -6203,6 +6446,11 @@ packages: resolution: {integrity: sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==} engines: {node: '>= 6'} + formatly@0.7.1: + resolution: {integrity: sha512-ESuCEJE0SGgabl9q+zABI8LhJDmF+8nhpuqDzuM48HfJ9QTD5o6PqFJDFZY7w6f8xsh5lixuj5nJsQNvYOWvKQ==} + engines: {node: '>=18.3.0'} + hasBin: true + formdata-polyfill@4.0.10: resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} engines: {node: '>=12.20.0'} @@ -6391,6 +6639,9 @@ packages: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} + get-tsconfig@4.14.3: + resolution: {integrity: sha512-++QEw4DIY7WGoukz+/+A/8dGYPT9l9yIadnmSgZ8Rjr3YVSVDipQSO9CdnJo9ePqFqUUqh+wk9uIaoiAwsiPkA==} + get-tsconfig@5.0.0-beta.6: resolution: {integrity: sha512-X6fBC0pmImC70gvX2zm56go9hx0MyoGVdG0tUCkg/D+Xnh5TJsOZ7iDbOdI3PvmtrDxnu1YdDufpK2QJX1Meqw==} engines: {node: '>=20.20.0'} @@ -6803,6 +7054,11 @@ packages: resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==} engines: {node: '>=6'} + knip@6.34.0: + resolution: {integrity: sha512-bbHIrnGspYwe4EBPjjx+lvkUor0F2qfKQc5BPzPI4SOAImYA+k2ueVpIcF7d/W1LEVT7XoJUPt6zELeGZhXBgA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + lazy-val@1.0.5: resolution: {integrity: sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q==} @@ -7514,10 +7770,17 @@ packages: resolution: {integrity: sha512-wrAwOeXp1RRMFfQY8Sy7VaGVmPocaLwSFOYCGKSyo8qmJ+/yaafCl5BCA1IQZWqFSRBrKDYFeR9d/VyQzfH/jg==} engines: {node: '>= 6.0'} + oxc-parser@0.147.0: + resolution: {integrity: sha512-5xaug6t7GfV3BO5Iv+xHW1rmQkDEQ3BEu3L8g3InsvWO5i8CYGc4tCZ2X985QcwWNycFJam+aOns6Nr2XAThTA==} + engines: {node: ^20.19.0 || >=22.12.0} + oxc-parser@0.148.0: resolution: {integrity: sha512-syxUKHeUll89RIABQADcI7sikYrwyssvA6gj4phSSIPezKVM8yMaLAiLLSc7fmzVvrwybfFGFbW5zme9sX87rg==} engines: {node: ^20.19.0 || >=22.12.0} + oxc-resolver@11.24.2: + resolution: {integrity: sha512-FY91FiDBj7ls5MsFS9jN3tjz2o0/zsdSsymlakySaBwVJZorHhkWyICLZMKxlu1R9vYo+sd3z1jwb4J8x7bNDw==} + oxfmt@0.66.0: resolution: {integrity: sha512-FfvqR8RFtV6JJpRrpkfqyVCQ7HDvZ/VriWFx7veftCgL1B5ZO9qNr+1rvPieycMQnNfVG0PWyJQiy7p0hq1I5w==} engines: {node: ^20.19.0 || >=22.12.0} @@ -8313,6 +8576,10 @@ packages: resolution: {integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==} engines: {node: '>=0.10.0'} + strip-json-comments@5.0.3: + resolution: {integrity: sha512-1tB5mhVo7U+ETBKNf92xT4hrQa3pm0MZ0PQvuDnWgAAGHDsfp4lPSpiS6psrSiet87wyGPh9ft6wmhOMQ0hDiw==} + engines: {node: '>=14.16'} + strnum@2.5.1: resolution: {integrity: sha512-UM4nTLWzQiDBseVxUGxN0wJzIk0UU89Qi7pKXz9qISo+lhviJikTuikBsK/oFRlpvYHvSdz0TVoLyQ+sEpYwxA==} @@ -8518,6 +8785,10 @@ packages: ultrahtml@1.7.0: resolution: {integrity: sha512-2xRd0VHoAQE4M+vF/DvFFB7pUV0ZxTW1TLi7lHQWnF/Sb5TPeEUV/l+hxcNnGO00ZXGnR0voCMmYRKQf+rvJ2g==} + unbash@4.0.12: + resolution: {integrity: sha512-PnKvRX+Fbxl/usVlTr/31tXIOVAH+8OdC9qaxUQcvurwEnoc3Vk/ipi2Ce8IjMxzK9byfSGdsUBjqqJGc1o5lw==} + engines: {node: '>=14'} + unconfig-core@7.5.0: resolution: {integrity: sha512-Su3FauozOGP44ZmKdHy2oE6LPjk51M/TRRjHv2HNCWiDvfvCoxC2lno6jevMA91MYAdCdwP05QnWdWpSbncX/w==} @@ -10380,6 +10651,12 @@ snapshots: tslib: 2.8.1 optional: true + '@emnapi/core@1.11.2': + dependencies: + '@emnapi/wasi-threads': 1.2.2 + tslib: 2.8.1 + optional: true + '@emnapi/core@1.11.3': dependencies: '@emnapi/wasi-threads': 1.2.3 @@ -10390,6 +10667,11 @@ snapshots: tslib: 2.8.1 optional: true + '@emnapi/runtime@1.11.2': + dependencies: + tslib: 2.8.1 + optional: true + '@emnapi/runtime@1.11.3': dependencies: tslib: 2.8.1 @@ -10683,7 +10965,7 @@ snapshots: '@js-sdsl/ordered-map@4.4.2': {} - '@legendapp/list@3.3.5(react-dom@19.3.1(react@19.3.1))(react@19.3.1)': + '@legendapp/list@3.3.5(patch_hash=6cbdacd8c380d9a5afb9f73d4198dc2cc44be6ef28a955b1183c781469307896)(react-dom@19.3.1(react@19.3.1))(react@19.3.1)': dependencies: react: 19.3.1 use-sync-external-store: 1.7.0(react@19.3.1) @@ -10845,6 +11127,13 @@ snapshots: '@tybys/wasm-util': 0.10.4 optional: true + '@napi-rs/wasm-runtime@1.2.5(@emnapi/core@1.11.2)(@emnapi/runtime@1.11.2)': + dependencies: + '@emnapi/core': 1.11.2 + '@emnapi/runtime': 1.11.2 + '@tybys/wasm-util': 0.10.4 + optional: true + '@napi-rs/wasm-runtime@1.2.5(@emnapi/core@1.11.3)(@emnapi/runtime@1.11.3)': dependencies: '@emnapi/core': 1.11.3 @@ -11356,60 +11645,117 @@ snapshots: '@oslojs/encoding@1.1.0': {} + '@oxc-parser/binding-android-arm-eabi@0.147.0': + optional: true + '@oxc-parser/binding-android-arm-eabi@0.148.0': optional: true + '@oxc-parser/binding-android-arm64@0.147.0': + optional: true + '@oxc-parser/binding-android-arm64@0.148.0': optional: true + '@oxc-parser/binding-darwin-arm64@0.147.0': + optional: true + '@oxc-parser/binding-darwin-arm64@0.148.0': optional: true + '@oxc-parser/binding-darwin-x64@0.147.0': + optional: true + '@oxc-parser/binding-darwin-x64@0.148.0': optional: true + '@oxc-parser/binding-freebsd-x64@0.147.0': + optional: true + '@oxc-parser/binding-freebsd-x64@0.148.0': optional: true + '@oxc-parser/binding-linux-arm-gnueabihf@0.147.0': + optional: true + '@oxc-parser/binding-linux-arm-gnueabihf@0.148.0': optional: true + '@oxc-parser/binding-linux-arm-musleabihf@0.147.0': + optional: true + '@oxc-parser/binding-linux-arm-musleabihf@0.148.0': optional: true + '@oxc-parser/binding-linux-arm64-gnu@0.147.0': + optional: true + '@oxc-parser/binding-linux-arm64-gnu@0.148.0': optional: true + '@oxc-parser/binding-linux-arm64-musl@0.147.0': + optional: true + '@oxc-parser/binding-linux-arm64-musl@0.148.0': optional: true + '@oxc-parser/binding-linux-ppc64-gnu@0.147.0': + optional: true + '@oxc-parser/binding-linux-ppc64-gnu@0.148.0': optional: true + '@oxc-parser/binding-linux-riscv64-gnu@0.147.0': + optional: true + '@oxc-parser/binding-linux-riscv64-gnu@0.148.0': optional: true + '@oxc-parser/binding-linux-riscv64-musl@0.147.0': + optional: true + '@oxc-parser/binding-linux-riscv64-musl@0.148.0': optional: true + '@oxc-parser/binding-linux-s390x-gnu@0.147.0': + optional: true + '@oxc-parser/binding-linux-s390x-gnu@0.148.0': optional: true + '@oxc-parser/binding-linux-x64-gnu@0.147.0': + optional: true + '@oxc-parser/binding-linux-x64-gnu@0.148.0': optional: true + '@oxc-parser/binding-linux-x64-musl@0.147.0': + optional: true + '@oxc-parser/binding-linux-x64-musl@0.148.0': optional: true + '@oxc-parser/binding-openharmony-arm64@0.147.0': + optional: true + '@oxc-parser/binding-openharmony-arm64@0.148.0': optional: true + '@oxc-parser/binding-win32-arm64-msvc@0.147.0': + optional: true + '@oxc-parser/binding-win32-arm64-msvc@0.148.0': optional: true + '@oxc-parser/binding-win32-ia32-msvc@0.147.0': + optional: true + '@oxc-parser/binding-win32-ia32-msvc@0.148.0': optional: true + '@oxc-parser/binding-win32-x64-msvc@0.147.0': + optional: true + '@oxc-parser/binding-win32-x64-msvc@0.148.0': optional: true @@ -11417,12 +11763,75 @@ snapshots: '@oxc-project/types@0.146.0': {} + '@oxc-project/types@0.147.0': {} + '@oxc-project/types@0.148.0': {} '@oxc-project/types@0.153.0': {} '@oxc-project/types@0.154.0': {} + '@oxc-resolver/binding-android-arm-eabi@11.24.2': + optional: true + + '@oxc-resolver/binding-android-arm64@11.24.2': + optional: true + + '@oxc-resolver/binding-darwin-arm64@11.24.2': + optional: true + + '@oxc-resolver/binding-darwin-x64@11.24.2': + optional: true + + '@oxc-resolver/binding-freebsd-x64@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-arm-gnueabihf@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-arm-musleabihf@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-arm64-gnu@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-arm64-musl@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-ppc64-gnu@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-riscv64-gnu@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-riscv64-musl@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-s390x-gnu@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-x64-gnu@11.24.2': + optional: true + + '@oxc-resolver/binding-linux-x64-musl@11.24.2': + optional: true + + '@oxc-resolver/binding-openharmony-arm64@11.24.2': + optional: true + + '@oxc-resolver/binding-wasm32-wasi@11.24.2': + dependencies: + '@emnapi/core': 1.11.2 + '@emnapi/runtime': 1.11.2 + '@napi-rs/wasm-runtime': 1.2.5(@emnapi/core@1.11.2)(@emnapi/runtime@1.11.2) + optional: true + + '@oxc-resolver/binding-win32-arm64-msvc@11.24.2': + optional: true + + '@oxc-resolver/binding-win32-x64-msvc@11.24.2': + optional: true + '@oxfmt/binding-android-arm-eabi@0.66.0': optional: true @@ -14587,6 +14996,10 @@ snapshots: dependencies: reusify: 1.1.0 + fd-package-json@2.0.0: + dependencies: + walk-up-path: 4.0.0 + fdir@6.5.0(picomatch@4.0.7): optionalDependencies: picomatch: 4.0.7 @@ -14644,6 +15057,11 @@ snapshots: hasown: 2.0.4 mime-types: 2.1.35 + formatly@0.7.1: + dependencies: + fd-package-json: 2.0.0 + package-manager-detector: 1.9.0 + formdata-polyfill@4.0.10: dependencies: fetch-blob: 3.2.0 @@ -14831,6 +15249,10 @@ snapshots: get-stream@6.0.1: {} + get-tsconfig@4.14.3: + dependencies: + resolve-pkg-maps: 1.0.0 + get-tsconfig@5.0.0-beta.6: dependencies: resolve-pkg-maps: 1.0.0 @@ -15344,6 +15766,22 @@ snapshots: kleur@4.1.5: {} + knip@6.34.0: + dependencies: + fdir: 6.5.0(picomatch@4.0.7) + formatly: 0.7.1 + get-tsconfig: 4.14.3 + jiti: 2.7.0 + oxc-parser: 0.147.0 + oxc-resolver: 11.24.2 + picomatch: 4.0.7 + smol-toml: 1.9.1 + strip-json-comments: 5.0.3 + tinyglobby: 0.2.17 + unbash: 4.0.12 + yaml: 2.9.1 + zod: 4.6.5 + lazy-val@1.0.5: {} libsodium-wrappers@0.8.4: @@ -16281,6 +16719,30 @@ snapshots: os-paths@4.4.0: {} + oxc-parser@0.147.0: + dependencies: + '@oxc-project/types': 0.147.0 + optionalDependencies: + '@oxc-parser/binding-android-arm-eabi': 0.147.0 + '@oxc-parser/binding-android-arm64': 0.147.0 + '@oxc-parser/binding-darwin-arm64': 0.147.0 + '@oxc-parser/binding-darwin-x64': 0.147.0 + '@oxc-parser/binding-freebsd-x64': 0.147.0 + '@oxc-parser/binding-linux-arm-gnueabihf': 0.147.0 + '@oxc-parser/binding-linux-arm-musleabihf': 0.147.0 + '@oxc-parser/binding-linux-arm64-gnu': 0.147.0 + '@oxc-parser/binding-linux-arm64-musl': 0.147.0 + '@oxc-parser/binding-linux-ppc64-gnu': 0.147.0 + '@oxc-parser/binding-linux-riscv64-gnu': 0.147.0 + '@oxc-parser/binding-linux-riscv64-musl': 0.147.0 + '@oxc-parser/binding-linux-s390x-gnu': 0.147.0 + '@oxc-parser/binding-linux-x64-gnu': 0.147.0 + '@oxc-parser/binding-linux-x64-musl': 0.147.0 + '@oxc-parser/binding-openharmony-arm64': 0.147.0 + '@oxc-parser/binding-win32-arm64-msvc': 0.147.0 + '@oxc-parser/binding-win32-ia32-msvc': 0.147.0 + '@oxc-parser/binding-win32-x64-msvc': 0.147.0 + oxc-parser@0.148.0: dependencies: '@oxc-project/types': 0.148.0 @@ -16306,6 +16768,28 @@ snapshots: '@oxc-parser/binding-win32-x64-msvc': 0.148.0 optional: true + oxc-resolver@11.24.2: + optionalDependencies: + '@oxc-resolver/binding-android-arm-eabi': 11.24.2 + '@oxc-resolver/binding-android-arm64': 11.24.2 + '@oxc-resolver/binding-darwin-arm64': 11.24.2 + '@oxc-resolver/binding-darwin-x64': 11.24.2 + '@oxc-resolver/binding-freebsd-x64': 11.24.2 + '@oxc-resolver/binding-linux-arm-gnueabihf': 11.24.2 + '@oxc-resolver/binding-linux-arm-musleabihf': 11.24.2 + '@oxc-resolver/binding-linux-arm64-gnu': 11.24.2 + '@oxc-resolver/binding-linux-arm64-musl': 11.24.2 + '@oxc-resolver/binding-linux-ppc64-gnu': 11.24.2 + '@oxc-resolver/binding-linux-riscv64-gnu': 11.24.2 + '@oxc-resolver/binding-linux-riscv64-musl': 11.24.2 + '@oxc-resolver/binding-linux-s390x-gnu': 11.24.2 + '@oxc-resolver/binding-linux-x64-gnu': 11.24.2 + '@oxc-resolver/binding-linux-x64-musl': 11.24.2 + '@oxc-resolver/binding-openharmony-arm64': 11.24.2 + '@oxc-resolver/binding-wasm32-wasi': 11.24.2 + '@oxc-resolver/binding-win32-arm64-msvc': 11.24.2 + '@oxc-resolver/binding-win32-x64-msvc': 11.24.2 + oxfmt@0.66.0(vite-plus@0.3.1(@opentelemetry/api@1.9.1)(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(typescript@7.0.2)(yaml@2.9.1)): dependencies: tinypool: 2.1.0 @@ -17359,6 +17843,8 @@ snapshots: strip-json-comments@2.0.1: optional: true + strip-json-comments@5.0.3: {} + strnum@2.5.1: dependencies: anynum: 1.0.1 @@ -17593,6 +18079,8 @@ snapshots: ultrahtml@1.7.0: {} + unbash@4.0.12: {} + unconfig-core@7.5.0: dependencies: '@quansync/fs': 1.1.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 4fae1c24..6a38a29e 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -33,6 +33,9 @@ allowBuilds: # electron-builder's Windows installer; the desktop app builds no Windows targets. electron-winstaller: false +patchedDependencies: + "@legendapp/list@3.3.5": patches/@legendapp__list@3.3.5.patch + # just-bash pins `run` exactly; the harness uses a newer one, and the binary unpacks one copy. overrides: run: 2.1.8 diff --git a/vite.config.ts b/vite.config.ts index 7f7a68b2..2d7941cd 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -118,6 +118,8 @@ export default defineConfig({ command: [ "vp check packages scripts .github infra", "vp run --filter './packages/*' --concurrency-limit 2 typecheck", + // Dead files, dependencies and exports, in the workspaces kept clean so far. + "vp run knip:check", ], dependsOn: ["@codeworksh/aikit#build"], cache: false,