strata-react 1.3.16 → 1.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microphone-B5ITwm4G.js","names":["Button","_Fragment","ToastQueue","ToastRegion","AriaToast","ToastContent","Button","AriaButton","_Fragment"],"sources":["../src/lib/overlay.ts","../src/query/poll.ts","../src/query/index.tsx","../src/components/data-view.tsx","../src/components/toast.tsx","../src/lib/viewport.ts","../src/lib/boxes.ts","../src/components/thumbnail.tsx","../src/lib/microphone.ts"],"sourcesContent":["// The look every floating surface shares (Dialog, Popover, and later Menu and Toast): the popover\n// role pair, an overlay radius, one hairline and the one shadow that exists for what floats\n// (components.md §3.11). One string, so a menu and a popover cannot drift apart.\nexport const overlaySurface =\n \"rounded-overlay border border-border bg-popover text-popover-foreground shadow-overlay enter-overlay\";\n","import * as React from \"react\";\nimport type { UseQueryResult } from \"@tanstack/react-query\";\n\n// Pausing a polled read (strata-react issue #344, from the status page in jburnhams/homepage). A\n// screen that re-reads every few seconds needs the same three parts every time: whether it is\n// paused, a button that says so, and when the readings were taken. A person reading a table while\n// it re-sorts under them needs the pause (ux-research `patterns.md` on live data: the person, not\n// the poll, decides when the view moves); a page whose readings may be minutes old needs the time.\n// Written by hand it was a `useState`, a button with `aria-pressed`, `refetchInterval: paused ?\n// false : ms` and an \"updated 12:00\" line, in every live screen.\n//\n// - `usePoll({ every })` holds the state and is passed to `useLoad({ poll })`, which polls at its\n// interval while it is not paused, notes when each read arrived, and reads once at once when the\n// poll is resumed (what was on screen is as old as the pause).\n// - `PauseButton` (components/pause-button.tsx) takes the same object, with its words fixed.\n// - One `Poll` may serve several reads: the page pauses together. The time is the latest read's. A read\n// with its own pace takes `poll.with({ every })`: same pause and time, other interval (#349).\n// - `useJob` keeps its own interval: a job is polled only while it runs, which is not the person's\n// to pause.\n\n/** The state of a polled read: its interval, whether the person paused it and when it last read. Made by `usePoll`. */\nexport type Poll = {\n /** Milliseconds between reads while not paused. */\n every: number;\n paused: boolean;\n /** Pause or resume. Resuming reads at once. */\n toggle: () => void;\n /** When the last read arrived, or `null` before the first. */\n updatedAt: Date | null;\n /** Used by `useLoad`: records the time of the read that just arrived (TanStack's `dataUpdatedAt`; 0 is none). */\n note: (dataUpdatedAt: number) => void;\n /** The same poll at another pace: a read that must be slower (or faster) than the page's keeps the shared pause, resume and \"updated\" time (`useLoad({ poll: poll.with({ every: 60_000 }) })`). */\n with: (override: { every: number }) => Poll;\n};\n\n/** The pause state and last-read time of a polled screen: pass it to `useLoad({ poll })` and to `PauseButton`. */\nexport function usePoll({ every, paused: initiallyPaused = false }: { every: number; paused?: boolean }): Poll {\n const [paused, setPaused] = React.useState(initiallyPaused);\n const [at, setAt] = React.useState(0);\n const toggle = React.useCallback(() => setPaused((p) => !p), []);\n const note = React.useCallback((dataUpdatedAt: number) => setAt((previous) => Math.max(previous, dataUpdatedAt)), []);\n return React.useMemo(() => {\n const poll: Poll = { every, paused, toggle, updatedAt: at ? new Date(at) : null, note, with: (override) => ({ ...poll, every: override.every, with: (again) => poll.with(again) }) };\n return poll;\n }, [every, paused, toggle, at, note]);\n}\n\n/** Wires a query to its `Poll`: the time of each read, and one read when the poll is resumed. */\nexport function usePollBinding(poll: Poll | undefined, query: Pick<UseQueryResult, \"dataUpdatedAt\" | \"refetch\">) {\n const note = poll?.note;\n React.useEffect(() => {\n if (note && query.dataUpdatedAt) note(query.dataUpdatedAt);\n }, [note, query.dataUpdatedAt]);\n const paused = poll?.paused;\n const wasPaused = React.useRef(paused);\n React.useEffect(() => {\n if (wasPaused.current && paused === false) void query.refetch();\n wasPaused.current = paused;\n // `refetch` is stable per query; only the pause changing should read.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [paused]);\n}\n","import * as React from \"react\";\nimport {\n QueryClient,\n QueryClientProvider,\n useQuery,\n type QueryKey,\n type UseQueryOptions,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport type { Load, Stale } from \"../components/data-view\";\nimport { usePollBinding, type Poll } from \"./poll\";\nimport { HttpError, describeHttpError, errorPayload, readErrorBody, type DescribeError, type ErrorBody } from \"../lib/errors\";\n\nexport { HttpError, describeHttpError, errorPayload, readErrorBody, type DescribeError, type ErrorBody };\n\n// Data loading, the Strata way: TanStack Query fetches and caches, and every view of the result\n// goes through DataView, which takes a Load<T>. `toLoad` is the one bridge between them, so a\n// screen never re-derives loading/error/ready from a query's flags and never forgets one.\n//\n// Opinions in createQueryClient: one retry (a second failure is real and the person should see\n// it with a \"Try again\"), 30 s stale time (dashboards are read many times a minute but change\n// over minutes), and no refetch on window focus (a table that reorders itself while someone reads\n// it is worse than one that is 30 s old). Override per query when the data says otherwise.\n\n/** A QueryClient with Strata's defaults: one retry, 30 s stale time, no refetch on window focus. */\nexport function createQueryClient(overrides?: ConstructorParameters<typeof QueryClient>[0]) {\n return new QueryClient({\n ...overrides,\n defaultOptions: {\n ...overrides?.defaultOptions,\n queries: { retry: 1, staleTime: 30_000, refetchOnWindowFocus: false, ...overrides?.defaultOptions?.queries },\n },\n });\n}\n\n/** Provides a query client (Strata's defaults unless one is passed) to the app. */\nexport function StrataQueryProvider({ client, children }: { client?: QueryClient; children: React.ReactNode }) {\n const [fallback] = React.useState(() => client ?? createQueryClient());\n return <QueryClientProvider client={client ?? fallback}>{children}</QueryClientProvider>;\n}\n\n/**\n * Turns a TanStack query result into the `Load<T>` that `DataView` takes; errors are described for a person by `describe`.\n * A refetch that fails after data arrived stays `ready`, with `stale` saying why and when the data was read.\n */\nexport function toLoad<T>(query: UseQueryResult<T>, describe: DescribeError = describeHttpError): Load<T> {\n if (query.status === \"success\") return { status: \"ready\", data: query.data };\n // TanStack keeps the last good data when a refetch fails and sets status \"error\" (isRefetchError).\n // That is old data, not no data: keep it on screen and say how old it is.\n if (query.status === \"error\" && query.data !== undefined) return { status: \"ready\", data: query.data, stale: staleOf(query, describe) };\n if (query.status === \"error\") return { status: \"error\", message: describe(query.error), retry: () => void query.refetch() };\n return { status: \"loading\" };\n}\n\n/** The `Stale` of a query whose refetch failed after a good read. Shared by `toLoad` and `useInfiniteLoad`. */\nexport function staleOf(\n query: { error: unknown; dataUpdatedAt: number; isFetching: boolean; refetch: () => unknown },\n describe: DescribeError = describeHttpError,\n): Stale {\n return { message: describe(query.error), readAt: new Date(query.dataUpdatedAt), retry: () => void query.refetch(), retrying: query.isFetching };\n}\n\n/** `useQuery`, returned as a `Load<T>` for `DataView`. With `poll` (from `usePoll`) it reads again every `poll.every` ms until the person pauses it. */\nexport function useLoad<T, K extends QueryKey = QueryKey>(\n options: UseQueryOptions<T, Error, T, K> & {\n describeError?: DescribeError;\n /** Read again on this poll's interval unless it is paused; see `usePoll` and `PauseButton`. Replaces `refetchInterval`. */\n poll?: Poll;\n },\n): Load<T> {\n const { describeError, poll, ...rest } = options;\n const query = useQuery(poll ? { ...rest, refetchInterval: poll.paused ? false : poll.every } : rest);\n usePollBinding(poll, query);\n return toLoad(query, describeError);\n}\n\n/** What `fetchJson` takes as `fetch`'s init, plus `json`. */\nexport type FetchJsonInit = RequestInit & {\n /**\n * A value sent as the JSON body: `Content-Type: application/json` is set unless the caller gave one, and the method is `POST` unless given.\n * Replaces `body`; an app never builds the `RequestInit` for a write by hand.\n */\n json?: unknown;\n};\n\n/** Options for `fetchJson` beyond `fetch`'s own. */\nexport type FetchJsonOptions = {\n /** Finds the server's reason and per-field messages in an error body. Default `readErrorBody` (FastAPI's `detail`, `message`, `error`). */\n readError?: (body: unknown) => ErrorBody;\n};\n\n/**\n * fetch() that throws an HttpError on a non-2xx response and parses JSON: the queryFn default, and the usual commit for a write.\n * `init.json` sends a JSON body without building the headers. A 204 or empty body resolves to undefined. An error response's body is read onto the HttpError (`body`, `reason`, `fieldErrors`).\n */\nexport async function fetchJson<T>(input: string | URL, init?: FetchJsonInit, { readError = readErrorBody }: FetchJsonOptions = {}): Promise<T> {\n const { json, ...rest } = init ?? {};\n // Headers, tuple arrays and plain objects are all valid HeadersInit; normalise before adding the\n // default so a caller's Authorization (or their own Accept) is never dropped.\n const headers = new Headers(rest.headers);\n if (!headers.has(\"Accept\")) headers.set(\"Accept\", \"application/json\");\n if (json !== undefined) {\n if (!headers.has(\"Content-Type\")) headers.set(\"Content-Type\", \"application/json\");\n rest.body = JSON.stringify(json);\n rest.method ??= \"POST\";\n }\n const res = await fetch(input, { ...rest, headers });\n if (!res.ok) {\n // The body is read as text and parsed only when it parses: a proxy's HTML 502 page or an empty\n // body must still throw the HttpError, never a JSON SyntaxError in its place.\n const raw = await res.text().catch(() => \"\");\n let body: unknown = raw || undefined;\n try {\n if (raw) body = JSON.parse(raw);\n } catch {\n // Not JSON: keep the text.\n }\n throw new HttpError(res.status, res.statusText, String(input), body, readError(body));\n }\n // Writes (DELETE, a PUT that returns nothing) answer 204 or an empty body; that is success, not a\n // JSON parse error.\n const text = res.status === 204 ? \"\" : await res.text();\n return (text ? JSON.parse(text) : undefined) as T;\n}\n\nexport { usePoll, type Poll } from \"./poll\";\nexport { createApi, type Api, type ApiOptions } from \"./api\";\nexport { createTypedApi, type TypedApi } from \"./typed-api\";\nexport { useInfiniteLoad, apiPage, type ApiPage, type InfiniteLoad, type InfiniteLoadOptions, type More } from \"./infinite\";\nexport { useJob, isTaskRunning, type Job, type JobOptions } from \"./job\";\nexport { useWorkflowRun, isWorkflowRunning, type WorkflowRunLike, type WorkflowRunOptions } from \"./workflow\";\n","import * as React from \"react\";\nimport { CircleAlert, History, RotateCcw } from \"lucide-react\";\nimport { Button } from \"./button\";\nimport { format } from \"../lib/format\";\nimport { cn } from \"../lib/utils\";\n\n// Every view of remote data goes through DataView, and DataView will not type-check without a\n// skeleton and an empty state. Generated UI renders the happy path; this makes the other three\n// states part of the component's signature rather than a review comment.\n//\n// A failed refresh is not a failed read (strata-react issue #26). Once data has arrived, a later\n// refetch that fails (a poll while the server restarts, a Try again on a flaky link) leaves the\n// data on screen with `stale` set: a polite notice above it says what happened, when the data\n// shown was read, and offers Try again. Swapping a whole dashboard for an error panel throws away\n// readings the person was using, and a silent failure lets them act on old numbers as if live, so\n// the data stays and its age is said in words. Only a read that never produced data is an error.\n//\n// The failed read's look is replaceable (strata-react issue #50): an app with a second look (the\n// Tubes viewer, with its own tokens and pill buttons) passes `error`, a render function given the\n// message and the retry, and keeps the state machine (loading, error, ready, stale, empty) rather\n// than copying DataView to change one panel. Whatever it draws sits inside a `role=\"alert\"` box,\n// so the failure is still announced; the default is `LoadError`, exported for reuse.\n\n/** Data still shown after a refresh failed: why the refresh failed, when the data was read, and the Try again. */\nexport type Stale = {\n /** Why the refresh failed, for a person: the sentence an error panel would have shown. */\n message: string;\n /** When the data on screen was read. */\n readAt: Date;\n /** Fetch again. */\n retry: () => void;\n /** A fetch is on its way (a Try again or the next poll). */\n retrying?: boolean;\n};\n\n/** The state of one remote read, for `DataView`: loading, failed with no data, or ready (and `stale` when a later refresh failed). */\nexport type Load<T> =\n | { status: \"loading\" }\n | { status: \"error\"; message: string; retry: () => void }\n | { status: \"ready\"; data: T; stale?: Stale };\n\n/** What a failed read hands to an `error` renderer: the sentence for a person, and the Try again. */\nexport type LoadFailure = { message: string; retry: () => void };\n\n/** The default failed-read panel: the reason on the danger tint, with Try again. Its parent carries `role=\"alert\"`. */\nexport function LoadError({ message, retry, className }: LoadFailure & { className?: string }) {\n return (\n <div className={cn(\"flex flex-wrap items-start gap-3 rounded-surface bg-danger-subtle p-4 text-danger\", className)}>\n <CircleAlert aria-hidden className=\"mt-0.5 size-5 shrink-0\" />\n <p className=\"min-w-0 flex-1 type-body\">{message}</p>\n <Button size=\"sm\" onClick={retry}>\n <RotateCcw aria-hidden />\n Try again\n </Button>\n </div>\n );\n}\n\nconst defaultError = (failure: LoadFailure) => <LoadError {...failure} />;\n\n/** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)`, under a `StaleNotice` when a refresh failed. The skeleton and empty state are required. */\nexport function DataView<T>({\n state,\n isEmpty,\n skeleton,\n empty,\n children,\n staleNotice = (stale) => <StaleNotice stale={stale} />,\n error = defaultError,\n className,\n}: {\n state: Load<T>;\n /** When the loaded data counts as empty. For arrays, `(rows) => rows.length === 0`. */\n isEmpty: (data: T) => boolean;\n /** Mirrors the final layout, so nothing jumps when data arrives. Not a centred spinner. */\n skeleton: React.ReactNode;\n /** What goes here and how to add it. An `EmptyState`, not an illustration. */\n empty: React.ReactNode;\n children: (data: T) => React.ReactNode;\n /** Shown above the data when a refresh failed. Defaults to a `StaleNotice`; pass one with the product's words for what is old (\"Readings from 13:50\"). */\n staleNotice?: (stale: Stale) => React.ReactNode;\n /** Draws a read that failed with no data, given the message and the retry. Defaults to `LoadError`. Rendered inside a `role=\"alert\"` box. */\n error?: (failure: LoadFailure) => React.ReactNode;\n className?: string;\n}) {\n return (\n <div className={cn(\"min-w-0\", className)} aria-busy={state.status === \"loading\" || undefined}>\n {state.status === \"loading\" && skeleton}\n {state.status === \"error\" && <div role=\"alert\">{error({ message: state.message, retry: state.retry })}</div>}\n {state.status === \"ready\" && (\n <>\n {state.stale && staleNotice(state.stale)}\n {isEmpty(state.data) ? empty : children(state.data)}\n </>\n )}\n </div>\n );\n}\n\n/** When `readAt` was, for a person: the clock time today, else the weekday and time. */\nfunction readTime(readAt: Date, now = new Date()) {\n return readAt.toDateString() === now.toDateString() ? format.clock.format(readAt) : format.shortDay.format(readAt);\n}\n\n/** The notice over data whose refresh failed: what happened, how old the data shown is, and Try again. A polite status, not an alert: nothing was lost. */\nexport function StaleNotice({\n stale,\n shown,\n className,\n}: {\n stale: Stale;\n /** What is old, in the product's words, given when it was read (\"13:50\", or \"Sat 13:50\" before today). Defaults to \"Showing data from 13:50.\" */\n shown?: (when: string) => React.ReactNode;\n className?: string;\n}) {\n return (\n <div role=\"status\" className={cn(\"mb-4 flex flex-wrap items-start gap-3 rounded-surface bg-warning-subtle p-3 text-warning\", className)}>\n <History aria-hidden className=\"mt-0.5 size-4 shrink-0\" />\n <p className=\"min-w-0 flex-1 type-body-sm\">\n {stale.message} {shown ? shown(readTime(stale.readAt)) : `Showing data from ${readTime(stale.readAt)}.`}\n </p>\n <Button size=\"sm\" onClick={stale.retry} disabled={stale.retrying}>\n <RotateCcw aria-hidden />\n {stale.retrying ? \"Trying again…\" : \"Try again\"}\n </Button>\n </div>\n );\n}\n\n// An empty state teaches the next action. No illustration slot exists, on purpose.\n/** An empty state that teaches the next action: a title, a sentence and an action. No illustration slot, on purpose. */\nexport function EmptyState({ title, children, action }: { title: string; children?: React.ReactNode; action?: React.ReactNode }) {\n return (\n <div className=\"grid justify-items-start gap-2 border-y border-border py-6\">\n <p className=\"type-heading\">{title}</p>\n {children && <p className=\"max-w-prose type-body text-muted-foreground\">{children}</p>}\n {action && <div className=\"mt-2\">{action}</div>}\n </div>\n );\n}\n\n/** A placeholder block for a loading layout. Size it with layout classes so it mirrors the final content. */\nexport function Skeleton({ className }: { className?: string }) {\n return <div aria-hidden className={cn(\"rounded-control bg-muted motion-safe:animate-pulse\", className)} />;\n}\n","import * as React from \"react\";\nimport { UNSTABLE_Toast as AriaToast, UNSTABLE_ToastContent as ToastContent, UNSTABLE_ToastQueue as ToastQueue, UNSTABLE_ToastRegion as ToastRegion, Button as AriaButton, Text } from \"react-aria-components\";\nimport { CircleCheck, Info, TriangleAlert, X } from \"lucide-react\";\nimport { Button } from \"./button\";\nimport { cn } from \"../lib/utils\";\nimport { overlaySurface } from \"../lib/overlay\";\nimport { isDev } from \"../lib/dev\";\n\n// A toast confirms background work that finished (\"Export finished\", \"3 pieces synced\"). It is a\n// polite live region; it never carries an error a person must act on, which goes inline as an\n// `Alert` with its recovery (components.md §3.13, patterns.md §7), so there is no danger tone:\n// the type refuses it. `warning` is for a fact worth a glance (\"Kiln 2 is 40 min behind\").\n//\n// Rules the component owns so an app does not have to:\n// - One region, once, at the app root (`ToastRegion`), on the `layer-bar` layer: bottom end of the\n// window on a wide screen, the top on a phone, so it does not sit on the undo bar or cover the\n// focused control. It is a labelled landmark the keyboard reaches with F6 (React Aria).\n// - It stays long enough to read: 5 s plus 40 ms a character, up to 15 s, at least 8 s with an\n// action. The timer pauses while the pointer or focus is on it. There is always a dismiss control.\n// - At most one action, a button (\"Open file\"); content is words, not a form.\n// - Announcements are React Aria's: the toast's text is read when it appears and not again.\n// - The queue is module-level, so `toast.show()` works from a mutation's `onSuccess` outside any\n// component; `toast.clear()` empties it for a test. React Aria marks its toast API unstable; it\n// is used only here, behind this small surface, so a change upstream stays in this file.\n// - One region at a time, enforced (issue #230): the first mounted owns the queue and a second one draws nothing and\n// says so in development, naming the fix. Two regions on one queue show every toast twice, which looks like a bug in\n// the toast and (in a test) fails `findByText` with \"Found multiple elements\"; the usual cause is a route tree that\n// draws the region in its root layout while a test helper draws one too (`renderRoutes(..., { toasts: false })`),\n// or an app with a region in a layout and another in a page. Ownership is held by a mounted-order list, not by the\n// queue, so unmounting the owner hands it to the next region.\n// Toasts are rare and brief, so they get the overlay entrance and nothing else (character.md §3).\n\n/** What a toast says. */\nexport type ToastContentProps = {\n /** What finished, past tense, in the product's words: \"Export finished\". */\n title: string;\n /** One more sentence: what and where (\"run.mp4, 2:31 at 1080p, in your Downloads folder.\"). */\n description?: string;\n /** `info` by default. There is no danger tone: an error the person must act on is an `Alert`. */\n tone?: \"info\" | \"success\" | \"warning\";\n /** One action beside the words. */\n action?: { label: string; onPress: () => void };\n /** Milliseconds before it goes. Defaults to enough to read the words. */\n timeout?: number;\n};\n\nconst queue = new ToastQueue<ToastContentProps>({ maxVisibleToasts: 3 });\n\n/** Milliseconds a toast stays: 5 s plus 40 ms a character, to at most 15 s, and at least 8 s with an action. */\nexport function toastTimeout(content: Pick<ToastContentProps, \"title\" | \"description\" | \"action\" | \"timeout\">): number {\n if (content.timeout !== undefined) return content.timeout;\n const chars = content.title.length + (content.description?.length ?? 0) + (content.action?.label.length ?? 0);\n return Math.max(content.action ? 8000 : 0, Math.min(15000, 5000 + 40 * chars));\n}\n\n/** The toast queue: `toast.show({ title })` from anywhere; `toast.close(key)`; `toast.clear()`. */\nexport const toast = {\n /** Shows a toast and returns its key. */\n show(content: ToastContentProps): string {\n // Nothing appears without a region, and nothing says so: in development the first such call does (issue #249).\n if (mounted.length === 0 && !warnedNoRegion && isDev()) {\n warnedNoRegion = true;\n console.warn(\"strata-react: toast.show() was called but no StrataToastRegion is mounted, so nothing will appear. Render <StrataToastRegion /> once at the app root.\");\n }\n return queue.add(content, { timeout: toastTimeout(content) });\n },\n close(key: string) {\n queue.close(key);\n },\n clear() {\n queue.clear();\n },\n};\n\nconst marks = { info: { icon: Info, color: \"text-info\" }, success: { icon: CircleCheck, color: \"text-success\" }, warning: { icon: TriangleAlert, color: \"text-warning\" } } as const;\n\n/** Props for `ToastRegion`. */\nexport type StrataToastRegionProps = {\n /** Names the landmark. Default \"Notifications\". */\n label?: string;\n className?: string;\n};\n\n// The regions mounted now, oldest first: the first draws, the rest stay empty.\nconst mounted: string[] = [];\nlet warnedNoRegion = false;\n/** For tests: forget that the missing-region warning was given. */\nexport function resetToastWarnings() {\n warnedNoRegion = false;\n}\nconst watchers = new Set<() => void>();\nconst changed = () => watchers.forEach((w) => w());\nconst watch = (w: () => void) => {\n watchers.add(w);\n return () => void watchers.delete(w);\n};\n\n/** True while this region is the one that draws. The server and the first client render say yes, so hydration matches. */\nfunction useOwnsQueue(): boolean {\n const id = React.useId();\n React.useLayoutEffect(() => {\n mounted.push(id);\n changed();\n return () => {\n mounted.splice(mounted.indexOf(id), 1);\n changed();\n };\n }, [id]);\n const owns = React.useSyncExternalStore(watch, () => mounted[0] === id, () => true);\n const [warned, setWarned] = React.useState(false);\n React.useEffect(() => {\n if (owns || warned || mounted.indexOf(id) < 1) return;\n setWarned(true);\n if (isDev()) {\n console.warn(\"strata-react: a StrataToastRegion is already mounted, so this one draws nothing. Render it once at the app root; in a test of a route tree that draws its own, pass `toasts: false` to renderRoutes.\");\n }\n }, [owns, warned, id]);\n return owns;\n}\n\n/** The one place toasts appear. Render it once at the app root; a second one mounted at the same time draws nothing and warns in development. A labelled landmark (F6), polite, above panes and the undo bar. */\nexport function StrataToastRegion({ label = \"Notifications\", className }: StrataToastRegionProps) {\n const owns = useOwnsQueue();\n if (!owns) return null;\n return (\n <ToastRegion\n queue={queue}\n aria-label={label}\n className={cn(\"layer-bar fixed inset-x-4 top-4 grid justify-items-end gap-2 outline-none sm:inset-x-auto sm:top-auto sm:right-4 sm:bottom-4\", className)}\n >\n {({ toast: t }) => (\n <AriaToast\n toast={t}\n className={cn(\"flex w-full max-w-sm items-start gap-3 p-3 outline-none focus-visible:outline-2 focus-visible:outline-ring\", overlaySurface)}\n >\n {(() => {\n const { icon: Icon, color } = marks[t.content.tone ?? \"info\"];\n return <Icon aria-hidden className={cn(\"mt-0.5 size-4 shrink-0\", color)} />;\n })()}\n <ToastContent className=\"grid min-w-0 flex-1 gap-0.5\">\n <Text slot=\"title\" className=\"type-label\">\n {t.content.title}\n </Text>\n {t.content.description && <Text slot=\"description\" className=\"type-body-sm text-muted-foreground\">{t.content.description}</Text>}\n </ToastContent>\n {t.content.action && (\n <Button size=\"sm\" onPress={() => { t.content.action?.onPress(); queue.close(t.key); }}>\n {t.content.action.label}\n </Button>\n )}\n <AriaButton slot=\"close\" aria-label=\"Dismiss\" className=\"grid size-6 shrink-0 cursor-pointer place-items-center rounded-control text-muted-foreground transition-state hover:bg-muted hover:text-foreground\">\n <X aria-hidden className=\"size-4\" />\n </AriaButton>\n </AriaToast>\n )}\n </ToastRegion>\n );\n}\n","// The arithmetic of a shared zoom and pan, kept apart from the DOM so it is unit tested without a\n// layout engine (jsdom has none). Used by `ViewportFrame` and so by every comparison view.\n//\n// Scale is relative to \"fit\" (1 = the whole picture inside its frame). The offset is in pixels from\n// the frame's centre, and the picture's transform origin is that centre, so zooming about a point\n// is one line of algebra and a fit picture is always centred.\n\n/** Zoom and pan of a picture inside its frame. `scale` 1 is the picture fitted; `x` and `y` are pixels from the centre. */\nexport type Viewport = { scale: number; x: number; y: number };\n\n/** The picture fitted in its frame, not panned. */\nexport const FIT: Viewport = { scale: 1, x: 0, y: 0 };\n\n/** The least zoom: the whole picture fitted. */\nexport const MIN_SCALE = 1;\n/** The most zoom, 32 times the fit. */\nexport const MAX_SCALE = 32;\n\n/** Keeps the picture from being dragged out of its frame: at most half the extra width or height past each edge. */\nexport function clampViewport(v: Viewport, frame: { width: number; height: number }): Viewport {\n const scale = Math.min(MAX_SCALE, Math.max(MIN_SCALE, v.scale));\n if (scale === MIN_SCALE) return FIT;\n const mx = ((scale - 1) * frame.width) / 2;\n const my = ((scale - 1) * frame.height) / 2;\n return { scale, x: Math.min(mx, Math.max(-mx, v.x)), y: Math.min(my, Math.max(-my, v.y)) };\n}\n\n/** A new scale with the point under `at` (pixels from the frame's centre) staying under it. */\nexport function zoomAt(v: Viewport, nextScale: number, at: { x: number; y: number }, frame: { width: number; height: number }): Viewport {\n const scale = Math.min(MAX_SCALE, Math.max(MIN_SCALE, nextScale));\n const k = scale / v.scale;\n return clampViewport({ scale, x: at.x - k * (at.x - v.x), y: at.y - k * (at.y - v.y) }, frame);\n}\n\n/** The scale at which the picture's own pixels are drawn one to one: its natural width over the width it is fitted at. */\nexport function actualPixelsScale(naturalWidth: number, fittedWidth: number): number {\n if (!naturalWidth || !fittedWidth) return 1;\n return Math.min(MAX_SCALE, Math.max(MIN_SCALE, naturalWidth / fittedWidth));\n}\n\n/** The CSS transform for a viewport. */\nexport function viewportTransform(v: Viewport): string {\n return `translate(${v.x}px, ${v.y}px) scale(${v.scale})`;\n}\n\n/** A box in a picture, as shares (0 to 1) of its width and height from the top left: `[x, y, width, height]`. */\nexport type ShareBox = readonly [number, number, number, number];\n\n/** A named box in the source's coordinates: `of` is the reference size in pixels, and without it the box is already shares. */\nexport type Region = { id: string; label: string; box: readonly [number, number, number, number]; of?: readonly [number, number] };\n\n/** A region as shares of the frame, so it lands on the same part of every candidate whatever its pixel size. */\nexport function regionShares(region: Region): ShareBox {\n const [x, y, w, h] = region.box;\n if (!region.of) return [x, y, w, h];\n const [ow, oh] = region.of;\n return [x / ow, y / oh, w / ow, h / oh];\n}\n\n/** The viewport that fills the frame with a box (as much of it as fits, centred): the scale that fits the box, the offset that puts its centre at the frame's centre. */\nexport function boxViewport(box: ShareBox, frame: { width: number; height: number }): Viewport {\n const [x, y, w, h] = box;\n const scale = Math.min(MAX_SCALE, Math.max(MIN_SCALE, Math.min(1 / Math.max(w, 1e-6), 1 / Math.max(h, 1e-6))));\n return clampViewport({ scale, x: -scale * (x + w / 2 - 0.5) * frame.width, y: -scale * (y + h / 2 - 0.5) * frame.height }, frame);\n}\n\n/** A rectangle drawn on the frame (pixels from its top left) as shares of the picture under the viewport now. */\nexport function frameBoxToShares(rect: { x0: number; y0: number; x1: number; y1: number }, v: Viewport, frame: { width: number; height: number }): ShareBox {\n const toShare = (p: number, offset: number, size: number) => (size ? (p - size / 2 - offset) / v.scale / size + 0.5 : 0);\n const clamp = (n: number) => Math.min(1, Math.max(0, n));\n const xa = clamp(toShare(Math.min(rect.x0, rect.x1), v.x, frame.width));\n const xb = clamp(toShare(Math.max(rect.x0, rect.x1), v.x, frame.width));\n const ya = clamp(toShare(Math.min(rect.y0, rect.y1), v.y, frame.height));\n const yb = clamp(toShare(Math.max(rect.y0, rect.y1), v.y, frame.height));\n return [xa, ya, xb - xa, yb - ya];\n}\n","// The geometry behind `BoxOverlay` (issue #237): boxes in a picture's own pixel units, the order a\n// person reads them in, and the viewport that zooms to one. No DOM, so the rules are tested without\n// a pointer. `Rect` is the same rectangle `RegionEditor` edits (`lib/region.ts`).\nimport { boxViewport, type ShareBox, type Viewport } from \"./viewport\";\nimport type { Rect } from \"./region\";\n\n/** A box on a picture, in the picture's own pixels. `label` names it for assistive technology and the list beside it. */\nexport type PictureBox = Rect & { id: string; label: string; tone?: BoxTone };\n\n/** The status role a box is drawn in. `neutral` is the foreground. Outline only, so the type underneath stays readable. */\nexport type BoxTone = \"neutral\" | \"info\" | \"success\" | \"warning\" | \"danger\";\n\n/**\n * The boxes in reading order: top to bottom in rows, left to right within a row. A box joins the\n * row above when its centre falls inside that row's first box vertically, so lines of text that\n * wobble a few pixels still read in order and two columns read row by row, not column by column.\n * Returns ids, so a caller keeps its own objects.\n */\nexport function readingOrder(boxes: readonly Rect[] & readonly { id: string }[]): string[] {\n const byTop = [...boxes].sort((a, b) => a.y + a.h / 2 - (b.y + b.h / 2) || a.x - b.x);\n const rows: (typeof byTop)[] = [];\n for (const box of byTop) {\n const row = rows[rows.length - 1];\n const centre = box.y + box.h / 2;\n if (row && centre >= row[0].y && centre <= row[0].y + row[0].h) row.push(box);\n else rows.push([box]);\n }\n return rows.flatMap((row) => row.sort((a, b) => a.x - b.x).map((b) => b.id));\n}\n\n/**\n * The viewport that fills a frame with one box of the picture. The picture sits in the frame the way\n * `object-fit: contain` puts it (a frame of another shape leaves bars), which is also how\n * `BoxOverlay` draws it, so the same numbers agree. `margin` is the share of the box added on every\n * side so the box is not touching the frame (default 0.25).\n */\nexport function zoomToBox(box: Rect, of: { w: number; h: number }, frame: { width: number; height: number }, margin = 0.25): Viewport {\n const s = Math.min(frame.width / of.w, frame.height / of.h);\n const ox = (frame.width - of.w * s) / 2;\n const oy = (frame.height - of.h * s) / 2;\n const mx = box.w * margin;\n const my = box.h * margin;\n const shares: ShareBox = [(ox + (box.x - mx) * s) / frame.width, (oy + (box.y - my) * s) / frame.height, ((box.w + 2 * mx) * s) / frame.width, ((box.h + 2 * my) * s) / frame.height];\n return boxViewport(shares, frame);\n}\n\n/** One box of a picture to show on its own, as `Thumbnail`'s `region` takes it: the picture's size, the box in its pixels, and `pad`, how many times the box's size the crop is (default 1.6, a face with its hair and chin). */\nexport type PictureRegion = { of: { w: number; h: number }; box: Rect; pad?: number };\n\n/**\n * Where the whole picture goes so that one box of it fills a frame of `aspect` (width over height), as\n * percentages of the frame: the crop is the box grown `pad` times about its centre, then widened or\n * heightened to the frame's shape, so the box is never squashed and stays in the middle. A crop that\n * runs past the picture's edge shows the frame's own ground there, as a face at the edge of a photo\n * is shown by a server crop that pads. No canvas and no second request: the browser draws the one\n * picture, which a list of faces from the same photo shares from its cache.\n */\nexport function regionStyle({ of, box, pad = 1.6 }: PictureRegion, aspect: number): { left: string; top: string; width: string; height: string } {\n let cw = Math.max(box.w * pad, 1);\n let ch = Math.max(box.h * pad, 1);\n if (cw / ch < aspect) cw = ch * aspect;\n else ch = cw / aspect;\n const x0 = box.x + box.w / 2 - cw / 2;\n const y0 = box.y + box.h / 2 - ch / 2;\n const pct = (n: number) => `${+(n * 100).toFixed(4) || 0}%`; // `|| 0`: never \"-0%\"\n return { left: pct(-x0 / cw), top: pct(-y0 / ch), width: pct(of.w / cw), height: pct(of.h / ch) };\n}\n","import * as React from \"react\";\nimport { ImageOff } from \"lucide-react\";\nimport { Skeleton } from \"./data-view\";\nimport { useInView } from \"../lib/in-view\";\nimport { cn } from \"../lib/utils\";\nimport { regionStyle, type PictureRegion } from \"../lib/boxes\";\n\n// A photo or crop from an API, in a list, a table cell or a grid (strata-react issue #33, from\n// the Bright Horizons review app, where some crops 404 because the file is missing on disk). A\n// plain <img> gets three things wrong there, and each is a state generated UI leaves out:\n//\n// - it has no size until it loads, so the rows below jump as each one arrives. The box here has\n// its aspect ratio before anything is fetched, and the image is cropped (`cover`) or fitted\n// (`contain`) into it, so nothing moves.\n// - while it loads it is a blank, and on a slow connection a blank reads as \"no photo\". Here it\n// is a `Skeleton`, the same placeholder DataView's loading layouts are made of.\n// - when it fails it is the browser's broken-image icon and the alt text crammed into the box.\n// Here it says what happened in the product's words: `missing` is required (\"Photo not\n// found\"), for the same reason DataView requires `empty`. A record with no photo at all\n// (`src={null}`) shows the same words without a request.\n//\n// `alt` is required too; pass \"\" only when the name beside the thumbnail already says everything\n// it shows. The missing state is an `img` named \"<alt>: <missing>\", so a screen reader hears\n// which photo is gone. Thumbnails come in dozens, so the request waits until the box is near the\n// screen (`useInView`, the hook InfiniteList's sentinel uses, with the same scroll region and a\n// root margin), and once asked for it is not unloaded. `eager` is for the first few on screen.\n// There is no fade-in: a list of thumbnails is seen many times a day (ux-character.md, character\n// by frequency), so the photo simply replaces its skeleton.\n//\n// Two more uses from the Tubes viewer (strata-react issue #51), which drew plain <img>s and lost\n// all of the above:\n//\n// - `children` are drawn above the image in the same positioned box: a video's running time in\n// one corner, \"Saved\" in another. They keep their place while the image loads, fails or is\n// missing, because the box, not the image, holds them. Position them yourself (`absolute\n// bottom-1 right-1`); they are not part of the image's name.\n// - `fallback` replaces the icon and words with the product's own drawing, such as a channel's\n// first letter on a disc for an avatar with no picture. The missing state is still one `img`,\n// named `alt` (with `missing` after it, when given, as \"Night Sky: No picture\"), so a person\n// using a screen reader hears whose picture it is either way. A round avatar is `aspect={1}`\n// with `className=\"rounded-pill\"`. With `alt=\"\"` and no `missing` words (a decorative avatar beside a\n// name that already says it) there is nothing to name, so the missing state is not an image role at all\n// (strata-react issue #209: an `img` named \"\" is flagged by axe, and the `<img alt=\"\">` it replaces is\n// presentational).\n//\n// What a third party's pictures need from the app (issue #209, from Tubes), which made it draw its own\n// `<img>` and lose everything above:\n//\n// - `src` may be a list, tried in order: the next one when a request fails or is rejected, the missing\n// state after the last (`maxres`, then `hq`).\n// - `onLoad(img)` sees each loaded image and may return `false` to reject it: a host that answers a\n// missing item with a 200 and a small grey placeholder is recognised by its `naturalWidth`, and the\n// next source is tried as if it had failed.\n// - `onMissing()` is called once when the thumbnail ends in its missing state after asking for\n// something (not for `src={null}`), so an app can record that the item behind it has gone.\n\n// One box of a bigger picture (strata-models' face store, where every app shows faces cut from photos):\n// `region` draws the whole picture placed so that the box fills the thumbnail, so an app shows a face,\n// or an OCR line, from the photo it already has, with the loading, missing and lazy rules above,\n// without a crop endpoint. A server crop (a smaller file) is still better for a grid of hundreds from\n// different photos; `region` is for a few faces of one photo, or before the server has cut one.\n\n// A picture the page has already loaded is shown at once when a `Thumbnail` for it mounts again (issue\n// #352, from strata-reels): a `FilmStrip` that re-fits after the window changes size, a list that\n// re-sorts or a row that remounts used to start every thumbnail as a skeleton that waited to be near the\n// screen, although the browser had the picture in its cache and a request would cost nothing. The\n// request key and the source index that loaded are remembered for the life of the page (bounded, oldest\n// forgotten first), and a new `Thumbnail` for the same request asks at once, at the source that loaded.\n// It is not trusted to be loaded: the image element says so (it is `complete` with a size when it\n// mounts from the cache, so there is no skeleton frame; otherwise its load event does), so a picture\n// that has left the cache or must be fetched again (`no-store`) keeps its skeleton while it comes, and\n// one that now fails goes through the usual missing path.\nconst loadedBefore = new Map<string, number>();\nconst LOADED_LIMIT = 2000;\n\nfunction remember(key: string, index: number) {\n loadedBefore.delete(key);\n loadedBefore.set(key, index);\n if (loadedBefore.size > LOADED_LIMIT) loadedBefore.delete(loadedBefore.keys().next().value!);\n}\n\n/** Forgets which pictures `Thumbnail` has loaded, so a test that checks the loading state starts from nothing. `renderWithStrata` and `renderRoutes` call it. */\nexport function forgetLoadedThumbnails() {\n loadedBefore.clear();\n}\n\n/** A width-over-height ratio: a number (`1.5`) or a fraction (`\"4/3\"`). */\nexport type AspectRatio = number | `${number}/${number}`;\n\n/** The thumbnail's props. Either `missing` (the words shown when there is no image) or a `fallback` drawing is required. */\nexport type ThumbnailProps = {\n /** The image URL, or a list of them tried in order (the next one when a request fails or `onLoad` rejects it). `null` or an empty list when the record has no photo: the `missing` words show without a request. */\n src: string | readonly string[] | null;\n /** What the photo shows (\"Celadon bowl, front\"). `\"\"` only when the text beside it already says it. */\n alt: string;\n /** Width over height. The box has this shape before the image loads. Default `1`. */\n aspect?: AspectRatio;\n /** `cover` crops to fill the box (default); `contain` fits the whole image in it. */\n fit?: \"cover\" | \"contain\";\n srcSet?: string;\n sizes?: string;\n /** Load at once rather than when near the screen: for the first few above the fold. */\n eager?: boolean;\n /** How far outside the scroll region the request starts (IntersectionObserver `rootMargin`). */\n rootMargin?: string;\n /** Layout at the call site: a width (`w-24`, `w-full`), or `rounded-pill` for an avatar. The height follows from `aspect`. */\n className?: string;\n /** Sees each image that loaded, with the index of its source. Return `false` to reject it (a host's grey placeholder answered with a 200): the next source is tried, or the missing state shows. */\n onLoad?: (image: HTMLImageElement, index: number) => boolean | void;\n /** Called once when the thumbnail ends in its missing state after a request failed or was rejected, never for a record with no source. */\n onMissing?: () => void;\n /** Show one box of the picture, filling the thumbnail (a face from a photo): the picture's size, the box in its pixels and `pad`, how many times the box the crop is (default 1.6). `fit` does not apply. */\n region?: PictureRegion;\n /** Overlays drawn above the image in the same box (a running time, a \"Saved\" badge), in place whether the image has loaded, failed or is missing. */\n children?: React.ReactNode;\n} & (\n | {\n /** What to show when there is no photo or it cannot be loaded, in the product's words: \"Photo not found\". */\n missing: string;\n /** Drawn instead of the icon and `missing` words when there is no image: a letter on a disc for an avatar. */\n fallback?: React.ReactNode;\n }\n | {\n /** Added to the missing state's name after `alt` (\"Night Sky: No picture\"), when given. */\n missing?: string;\n /** Drawn when there is no image or it cannot be loaded: a letter on a disc for an avatar. */\n fallback: React.ReactNode;\n }\n);\n\ntype Phase = \"loading\" | \"loaded\" | \"missing\";\ntype Outcome = { key: string; index: number; done: \"loaded\" | \"missing\" | null };\n\nconst ratioNumber = (aspect: AspectRatio) => {\n if (typeof aspect === \"number\") return aspect;\n const [w, h] = aspect.split(\"/\").map(Number);\n return w! / h!;\n};\n\nconst ratio = (aspect: AspectRatio) => (typeof aspect === \"number\" ? String(aspect) : aspect.replace(\"/\", \" / \"));\n\n/** A box of fixed aspect ratio for a remote image: a skeleton until it loads, the `missing` words (or a `fallback`) if it cannot, a request only when it nears the screen, and `children` overlaid in its corners. `alt` and `missing` or `fallback` are required. */\nexport function Thumbnail({\n src,\n alt,\n missing,\n aspect = 1,\n fit = \"cover\",\n srcSet,\n sizes,\n eager = false,\n rootMargin = \"200px\",\n className,\n fallback,\n onLoad,\n onMissing,\n region,\n children,\n}: ThumbnailProps) {\n // The outcome is kept with the request it belongs to (the sources and `srcSet`, since the browser may\n // have loaded a candidate from either), so a new request starts loading again without an effect\n // to reset it, and a late event from the old image cannot mark the new one. `index` is the source being tried.\n const sources = React.useMemo(() => (src === null ? [] : typeof src === \"string\" ? (src ? [src] : []) : src.filter(Boolean)), [src]);\n const key = sources.length ? `${sources.join(\"\\n\")} ${srcSet ?? \"\"}` : null;\n const [outcome, setOutcome] = React.useState<Outcome | null>(null);\n const before = key === null ? undefined : loadedBefore.get(key);\n const mine = key !== null && outcome?.key === key ? outcome : null;\n // A remembered request starts at the source that loaded, but stays \"loading\" until this image says it has.\n const index = mine?.index ?? before ?? 0;\n const phase: Phase = key === null ? \"missing\" : mine?.done ?? \"loading\";\n const current = sources[index];\n const near = useInView({ active: !eager && sources.length > 0, rootMargin, once: true, unsupported: true });\n const requested = eager || near.inView || before !== undefined;\n // The next source, or the end of the list.\n const fail = () => setOutcome(index + 1 < sources.length ? { key: key!, index: index + 1, done: null } : { key: key!, index, done: \"missing\" });\n // An app that records what is gone is told once per request that ended without a picture.\n const told = React.useRef<string | null>(null);\n const tell = React.useRef(onMissing);\n tell.current = onMissing;\n React.useEffect(() => {\n // Any state but \"missing\" ends the last telling, so the same request failing again later is told again.\n if (phase !== \"missing\") told.current = null;\n else if (key !== null && told.current !== key) {\n told.current = key;\n tell.current?.();\n }\n }, [key, phase]);\n\n const name = [alt, missing].filter(Boolean).join(\": \");\n return (\n <div\n ref={near.ref}\n className={cn(\"relative overflow-hidden rounded-control bg-muted\", className)}\n style={{ aspectRatio: ratio(aspect) }}\n aria-busy={phase === \"loading\" || undefined}\n >\n {phase === \"loading\" && <Skeleton className=\"absolute inset-0\" />}\n {key !== null && phase !== \"missing\" && requested && (\n <img\n key={`${key}#${index}`}\n ref={(el) => {\n // From the cache the image is complete as it mounts: loaded now, with no skeleton frame (the load event also follows, and agrees).\n if (el && phase === \"loading\" && before !== undefined && el.complete && el.naturalWidth > 0) setOutcome({ key: key!, index, done: \"loaded\" });\n }}\n src={current}\n // The candidates are the first source's: a fallback would otherwise be replaced by the set that just failed.\n srcSet={index === 0 ? srcSet : undefined}\n sizes={sizes}\n alt={alt}\n decoding=\"async\"\n onLoad={(e) => (onLoad?.(e.currentTarget, index) === false ? fail() : (remember(key!, index), setOutcome({ key: key!, index, done: \"loaded\" })))}\n onError={fail}\n style={region ? regionStyle(region, ratioNumber(aspect)) : undefined}\n className={cn(\n \"absolute\",\n region ? \"max-w-none\" : [\"inset-0 size-full\", fit === \"cover\" ? \"object-cover\" : \"object-contain\"],\n phase === \"loading\" && \"opacity-0\",\n )}\n />\n )}\n {phase === \"missing\" && (\n <div\n {...(name ? { role: \"img\", \"aria-label\": name } : { \"aria-hidden\": true })}\n className={cn(\n \"absolute inset-0 grid\",\n fallback === undefined && \"content-center justify-items-center gap-0.5 p-1 text-center text-muted-foreground\",\n )}\n >\n {fallback === undefined ? (\n <>\n <ImageOff aria-hidden className=\"size-4 shrink-0\" />\n <span className=\"type-caption text-balance\">{missing}</span>\n </>\n ) : (\n <div aria-hidden className=\"grid size-full min-h-0 min-w-0\">\n {fallback}\n </div>\n )}\n </div>\n )}\n {children}\n </div>\n );\n}\n\n/** The loading shape of a `Thumbnail`, for a `DataView` skeleton: the same box and aspect ratio, so nothing moves when the list arrives. */\nexport function ThumbnailSkeleton({ aspect = 1, className }: { aspect?: AspectRatio; className?: string }) {\n return (\n <div aria-hidden className={cn(\"relative overflow-hidden rounded-control bg-muted\", className)} style={{ aspectRatio: ratio(aspect) }}>\n <Skeleton className=\"absolute inset-0\" />\n </div>\n );\n}\n","import * as React from \"react\";\n\n// The microphone as raw samples, for an app that records speech (strata-voice's studio). What an app would\n// otherwise write each time:\n// - MediaRecorder only writes compressed audio, so the samples come through an AudioWorklet (loaded from a\n// Blob URL, so the app ships no worklet file) that posts 2048 frames at a time (~43 ms at 48 kHz): about\n// 23 messages a second instead of one per 128-frame render quantum.\n// - Echo cancellation, noise suppression and automatic gain are off: each reshapes a voice, and a take is\n// meant to be the voice as it was. The worklet feeds a silent gain into the output, because a worklet\n// nothing pulls does not run.\n// - getUserMedia exists only on a secure page (https:// or http://localhost), and its refusals are\n// DOMExceptions by name; `explainMicrophoneError` turns both into a sentence a person can act on.\n// - The device is behind `MicrophoneContext`, so a screen takes it from `useMicrophone()` and a test or\n// story gives it `fakeMicrophone()` (strata-react/testing) instead: hardware is the one true external.\n// Not a React Aria part: there is none for capture, and nothing here is a control.\n// `browserMicrophone` is covered by the stories in Chromium only: jsdom has no audio graph.\n\n/** A microphone that is open and sending samples. */\nexport type MicrophoneStream = {\n sampleRate: number;\n /** What the browser calls the device (\"USB Audio Device\"), or null when it says nothing. */\n device: string | null;\n /** Stops the device (the browser's recording light goes out). */\n close: () => void;\n};\n\n/** Something that can be opened to send mono samples (-1 to 1) a chunk at a time. */\nexport type Microphone = {\n open: (onSamples: (chunk: Float32Array) => void) => Promise<MicrophoneStream>;\n};\n\n/** A microphone that would not open, with a sentence a person can act on. */\nexport class MicrophoneError extends Error {}\n\n/** The sentence for what getUserMedia threw. */\nexport function explainMicrophoneError(e: unknown): MicrophoneError {\n const name = e instanceof DOMException ? e.name : \"\";\n if (name === \"NotAllowedError\")\n return new MicrophoneError(\"The browser was not allowed to use the microphone. Allow it from the address bar, then try again.\");\n if (name === \"NotFoundError\") return new MicrophoneError(\"No microphone was found. Plug one in, then try again.\");\n if (name === \"NotReadableError\") return new MicrophoneError(\"The microphone is in use by another program. Close it, then try again.\");\n // DOMException is checked apart from Error: it is an Error in browsers but not in every runtime (jsdom).\n const said = e instanceof DOMException || e instanceof Error ? e.message : String(e);\n return new MicrophoneError(`The microphone could not be opened (${said}).`);\n}\n\nconst WORKLET = `\nclass StrataTap extends AudioWorkletProcessor {\n constructor() { super(); this.buf = new Float32Array(2048); this.n = 0 }\n process(inputs) {\n const ch = inputs[0] && inputs[0][0]\n if (ch) for (let i = 0; i < ch.length; i++) {\n this.buf[this.n++] = ch[i]\n if (this.n === this.buf.length) { this.port.postMessage(this.buf.slice()); this.n = 0 }\n }\n return true\n }\n}\nregisterProcessor('strata-tap', StrataTap)\n`;\n\n/** The browser's own microphone, with its processing off. */\nexport const browserMicrophone: Microphone = {\n async open(onSamples) {\n if (typeof navigator === \"undefined\" || !navigator.mediaDevices?.getUserMedia)\n throw new MicrophoneError(\"The microphone needs a secure page: open the app at http://localhost or over https.\");\n let media: MediaStream;\n try {\n media = await navigator.mediaDevices.getUserMedia({\n audio: { channelCount: 1, echoCancellation: false, noiseSuppression: false, autoGainControl: false },\n });\n } catch (e) {\n throw explainMicrophoneError(e);\n }\n let context: AudioContext | undefined;\n const close = () => {\n for (const t of media.getTracks()) t.stop();\n void context?.close();\n };\n // Once the device is open, any failure building the graph closes it again: the caller gets no stream to\n // close, and the browser's recording light would otherwise stay on.\n try {\n context = new AudioContext();\n const url = URL.createObjectURL(new Blob([WORKLET], { type: \"text/javascript\" }));\n try {\n await context.audioWorklet.addModule(url);\n } finally {\n URL.revokeObjectURL(url);\n }\n const tap = new AudioWorkletNode(context, \"strata-tap\");\n tap.port.onmessage = (event: MessageEvent<Float32Array>) => onSamples(event.data);\n const mute = context.createGain();\n mute.gain.value = 0;\n context.createMediaStreamSource(media).connect(tap).connect(mute).connect(context.destination);\n return { sampleRate: context.sampleRate, device: media.getAudioTracks()[0]?.label || null, close };\n } catch (e) {\n close();\n throw explainMicrophoneError(e);\n }\n },\n};\n\n/** The microphone screens record from: the browser's, unless a provider gives another (a fake in tests and stories). */\nexport const MicrophoneContext = React.createContext<Microphone>(browserMicrophone);\n\n/** The microphone from the nearest `MicrophoneContext`. */\nexport const useMicrophone = (): Microphone => React.useContext(MicrophoneContext);\n"],"mappings":";;;;;;;;AAGA,IAAa,iBACX;;;ACgCF,SAAgB,QAAQ,EAAE,OAAO,QAAQ,kBAAkB,SAAoD;CAC7G,MAAM,CAAC,QAAQ,aAAa,MAAM,SAAS,eAAe;CAC1D,MAAM,CAAC,IAAI,SAAS,MAAM,SAAS,CAAC;CACpC,MAAM,SAAS,MAAM,kBAAkB,WAAW,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;CAC/D,MAAM,OAAO,MAAM,aAAa,kBAA0B,OAAO,aAAa,KAAK,IAAI,UAAU,aAAa,CA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,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,QAAQ,WAAW;EAC7F,OAAO;GAAE,YAAY,QAAQ;GAAY,QAAQ,MAAM,eAAe,CAAC,CAAC,EAAE,EAAE,SAAS;GAAM;EAAM;CACnG,SAAS,GAAG;EACV,MAAM;EACN,MAAM,uBAAuB,CAAC;CAChC;AACF,EACF;;AAGA,IAAa,oBAAoB,MAAM,cAA0B,iBAAiB;;AAGlF,IAAa,sBAAkC,MAAM,WAAW,iBAAiB"}
package/dist/panorama.js CHANGED
@@ -1,5 +1,6 @@
1
- import { d as useInView, r as Slider } from "./value-controls-WRXbtUp6.js";
2
- import { d as cn } from "./field-jfhLD5XX.js";
1
+ import { f as useInView } from "./errors-jep2voNI.js";
2
+ import { g as cn } from "./field-t4Hoer0d.js";
3
+ import { r as Slider } from "./value-controls-DB5l5Qe2.js";
3
4
  import * as React from "react";
4
5
  import { jsx, jsxs } from "react/jsx-runtime";
5
6
  import { VisuallyHidden } from "react-aria";
@@ -1 +1 @@
1
- {"version":3,"file":"panorama.js","names":[],"sources":["../src/panorama/gl.ts","../src/panorama/projection.ts","../src/panorama/panorama-viewer.tsx"],"sourcesContent":["import type { PanoramaView } from \"./projection\";\n\n// The WebGL2 side of `PanoramaViewer` (strata-react issue #178): one full-screen triangle, and a\n// fragment shader that does for every pixel what `project`/`unproject` do for one (projection.ts holds\n// the same formulas, and tests hold the two to each other): build the ray through the pixel from the\n// view's yaw, pitch and field of view, turn it into longitude and latitude, and read the equirectangular\n// texture there. The texture repeats across the seam (longitude) and clamps at the poles. No mipmaps:\n// the longitude wraps with an `atan`, whose jump at the seam would make a mipmapped lookup draw a line\n// one pixel wide down it; plain linear filtering draws none.\n//\n// Cost, as documented for apps: one texture upload per *drawn video frame* (`texImage2D` of the\n// `<video>`), none for a still picture (uploaded once), and a draw only when the view, the size or the\n// picture changed, never on a timer.\n\nconst VERTEX = `#version 300 es\nin vec2 aPos;\nout vec2 vNdc;\nvoid main() { vNdc = aPos; gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst FRAGMENT = `#version 300 es\nprecision highp float;\nin vec2 vNdc;\nout vec4 outColor;\nuniform sampler2D uPicture;\nuniform float uYaw;\nuniform float uPitch;\nuniform float uTanHalf;\nuniform float uAspect;\nconst float PI = 3.14159265358979;\nvoid main() {\n vec3 forward = vec3(cos(uPitch) * sin(uYaw), sin(uPitch), cos(uPitch) * cos(uYaw));\n vec3 right = vec3(cos(uYaw), 0.0, -sin(uYaw));\n vec3 up = vec3(-sin(uPitch) * sin(uYaw), cos(uPitch), -sin(uPitch) * cos(uYaw));\n vec3 ray = normalize(forward + vNdc.x * uTanHalf * right + vNdc.y * (uTanHalf / uAspect) * up);\n float lon = atan(ray.x, ray.z);\n float lat = asin(clamp(ray.y, -1.0, 1.0));\n outColor = texture(uPicture, vec2(lon / (2.0 * PI) + 0.5, 0.5 - lat / PI));\n}`;\n\n/** Anything WebGL can take as a texture: a decoded image or a playing video. */\nexport type PanoramaPicture = HTMLImageElement | HTMLVideoElement | ImageBitmap | HTMLCanvasElement;\n\n/** What draws the window. */\nexport type PanoramaRenderer = {\n /** Sends the picture to the GPU. Call when the picture is a new one (an image) or a new frame (a video). */\n upload: (picture: PanoramaPicture) => void;\n /** Draws the view into a canvas of `width` by `height` device pixels. */\n draw: (view: PanoramaView, width: number, height: number) => void;\n /** How many times `upload` has sent a picture (a video frame, an image), for the documented cost and for tests. */\n uploads: () => number;\n /** Frees the GPU objects. */\n dispose: () => void;\n};\n\n/** Makes a renderer on `canvas`, or null where WebGL2 is not available (the viewer then shows the flat picture). */\nexport function createRenderer(canvas: HTMLCanvasElement): PanoramaRenderer | null {\n const gl = canvas.getContext(\"webgl2\", { antialias: false, preserveDrawingBuffer: false, alpha: false }) as WebGL2RenderingContext | null;\n if (!gl) return null;\n const compile = (type: number, source: string) => {\n const shader = gl.createShader(type)!;\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const log = gl.getShaderInfoLog(shader);\n gl.deleteShader(shader);\n throw new Error(`Panorama shader: ${log}`);\n }\n return shader;\n };\n let program: WebGLProgram;\n try {\n program = gl.createProgram()!;\n gl.attachShader(program, compile(gl.VERTEX_SHADER, VERTEX));\n gl.attachShader(program, compile(gl.FRAGMENT_SHADER, FRAGMENT));\n gl.linkProgram(program);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) throw new Error(`Panorama program: ${gl.getProgramInfoLog(program)}`);\n } catch {\n return null;\n }\n gl.useProgram(program);\n const buffer = gl.createBuffer();\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n // One triangle that covers the screen.\n gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n const position = gl.getAttribLocation(program, \"aPos\");\n gl.enableVertexAttribArray(position);\n gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);\n const texture = gl.createTexture();\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n const uniforms = {\n yaw: gl.getUniformLocation(program, \"uYaw\"),\n pitch: gl.getUniformLocation(program, \"uPitch\"),\n tanHalf: gl.getUniformLocation(program, \"uTanHalf\"),\n aspect: gl.getUniformLocation(program, \"uAspect\"),\n picture: gl.getUniformLocation(program, \"uPicture\"),\n };\n gl.uniform1i(uniforms.picture, 0);\n let uploaded = 0;\n let has = false;\n\n return {\n upload(picture) {\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, picture);\n uploaded++;\n has = true;\n },\n draw(view, width, height) {\n if (canvas.width !== width || canvas.height !== height) {\n canvas.width = width;\n canvas.height = height;\n }\n gl.viewport(0, 0, width, height);\n if (!has) {\n gl.clearColor(0, 0, 0, 1);\n gl.clear(gl.COLOR_BUFFER_BIT);\n return;\n }\n const rad = Math.PI / 180;\n gl.uniform1f(uniforms.yaw, view.yaw * rad);\n gl.uniform1f(uniforms.pitch, view.pitch * rad);\n gl.uniform1f(uniforms.tanHalf, Math.tan((view.fov * rad) / 2));\n gl.uniform1f(uniforms.aspect, width / height);\n gl.drawArrays(gl.TRIANGLES, 0, 3);\n },\n uploads: () => uploaded,\n dispose() {\n gl.deleteTexture(texture);\n gl.deleteBuffer(buffer);\n gl.deleteProgram(program);\n },\n };\n}\n","// The geometry of `PanoramaViewer` (strata-react issue #178), with no DOM and no GL so every case\n// is tested on its own and the GL shader is held to the same numbers. A 360 picture is\n// *equirectangular*: longitude across, latitude down. The viewer shows a *rectilinear* window into the\n// sphere, as a camera does: straight lines stay straight, and the width of what is seen is the\n// horizontal field of view `fov`.\n//\n// Angles are degrees, because that is what an app and a person talk in. `yaw` is the heading: 0 is the\n// middle of the picture, positive to the right, wrapped to (-180, 180]. `pitch` is the elevation:\n// 0 is the horizon, positive up, limited to +-90 (the apps' own `maxPitch` is kept below that). A\n// direction in the world is a unit vector `(cos p sin y, sin p, cos p cos y)`; the camera's forward,\n// right and up are built from the view's yaw and pitch (no roll: upright footage). A point is drawn\n// where its direction crosses the image plane, `fpx = (width / 2) / tan(fov / 2)` pixels from the camera.\n\n/** Where the window looks and how wide it sees, degrees. */\nexport type PanoramaView = { yaw: number; pitch: number; fov: number };\n\n/** The size of the picture box in CSS pixels. */\nexport type PanoramaSize = { width: number; height: number };\n\n/** A place in the box. `inside` says it is within the box; a point behind the camera has none (`project` returns null). */\nexport type PanoramaPoint = { x: number; y: number; inside: boolean };\n\nconst RAD = Math.PI / 180;\nconst DEG = 180 / Math.PI;\n\n/** Wraps a heading to (-180, 180]. */\nexport function wrapYaw(yaw: number): number {\n const w = ((((yaw + 180) % 360) + 360) % 360) - 180;\n return w === -180 ? 180 : w;\n}\n\n/** The smallest signed turn from heading `from` to heading `to`, in (-180, 180]. Use it for a difference of headings, never `to - from`. */\nexport const yawDelta = (from: number, to: number) => wrapYaw(to - from);\n\n/** Keeps a view inside its limits: heading wrapped, pitch within +-`maxPitch`, field of view within `minFov` to `maxFov`. */\nexport function clampView(view: PanoramaView, { maxPitch = 85, minFov = 20, maxFov = 120 }: { maxPitch?: number; minFov?: number; maxFov?: number } = {}): PanoramaView {\n return { yaw: wrapYaw(view.yaw), pitch: Math.min(Math.max(view.pitch, -maxPitch), maxPitch), fov: Math.min(Math.max(view.fov, minFov), maxFov) };\n}\n\nconst focal = (view: PanoramaView, size: PanoramaSize) => size.width / 2 / Math.tan((view.fov * RAD) / 2);\n\nfunction basis(view: PanoramaView) {\n const y = view.yaw * RAD;\n const p = view.pitch * RAD;\n const forward = [Math.cos(p) * Math.sin(y), Math.sin(p), Math.cos(p) * Math.cos(y)] as const;\n const right = [Math.cos(y), 0, -Math.sin(y)] as const;\n const up = [-Math.sin(p) * Math.sin(y), Math.cos(p), -Math.sin(p) * Math.cos(y)] as const;\n return { forward, right, up };\n}\nconst dot = (a: readonly number[], b: readonly number[]) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n\n/** Where the direction (`yaw`, `pitch`) is drawn in the box for `view`, or null when it is behind the camera. */\nexport function project(view: PanoramaView, size: PanoramaSize, yaw: number, pitch: number): PanoramaPoint | null {\n const { forward, right, up } = basis(view);\n const p = pitch * RAD;\n const y = yaw * RAD;\n const d = [Math.cos(p) * Math.sin(y), Math.sin(p), Math.cos(p) * Math.cos(y)] as const;\n const z = dot(d, forward);\n if (z <= 1e-9) return null;\n const f = focal(view, size);\n const x = size.width / 2 + (f * dot(d, right)) / z;\n const yy = size.height / 2 - (f * dot(d, up)) / z;\n return { x, y: yy, inside: x >= 0 && x <= size.width && yy >= 0 && yy <= size.height };\n}\n\n/** The direction under a point of the box for `view`: the inverse of `project`. */\nexport function unproject(view: PanoramaView, size: PanoramaSize, x: number, y: number): { yaw: number; pitch: number } {\n const { forward, right, up } = basis(view);\n const f = focal(view, size);\n const a = (x - size.width / 2) / f;\n const b = -(y - size.height / 2) / f;\n const v = [forward[0] + a * right[0] + b * up[0], forward[1] + a * right[1] + b * up[1], forward[2] + a * right[2] + b * up[2]] as const;\n const length = Math.hypot(v[0], v[1], v[2]);\n return { yaw: wrapYaw(Math.atan2(v[0], v[2]) * DEG), pitch: Math.asin(Math.min(Math.max(v[1] / length, -1), 1)) * DEG };\n}\n\n/** Pixels to degrees at the middle of the box: how far a drag of `px` turns the view. */\nexport const degreesPerPixel = (view: PanoramaView, size: PanoramaSize) => (Math.atan(1 / focal(view, size)) * DEG);\n\n/** The flat picture's own mapping, for the fallback with no WebGL: longitude and latitude are straight across and down, the visible rectangle is `fov` wide and as tall as the box's shape makes it. */\nexport function projectFlat(view: PanoramaView, size: PanoramaSize, yaw: number, pitch: number): PanoramaPoint {\n const perPixel = view.fov / size.width;\n const x = size.width / 2 + yawDelta(view.yaw, yaw) / perPixel;\n const y = size.height / 2 - (pitch - view.pitch) / perPixel;\n return { x, y, inside: x >= 0 && x <= size.width && y >= 0 && y <= size.height };\n}\n\n/** The inverse of `projectFlat`. */\nexport function unprojectFlat(view: PanoramaView, size: PanoramaSize, x: number, y: number): { yaw: number; pitch: number } {\n const perPixel = view.fov / size.width;\n return { yaw: wrapYaw(view.yaw + (x - size.width / 2) * perPixel), pitch: Math.min(Math.max(view.pitch - (y - size.height / 2) * perPixel, -90), 90) };\n}\n\n/** The direction in words: \"Looking 40° right, 5° up\", \"Looking straight ahead\". Whole degrees; nothing is said for less than half a degree. */\nexport function describeView(view: Pick<PanoramaView, \"yaw\" | \"pitch\">): string {\n const yaw = Math.round(wrapYaw(view.yaw));\n const pitch = Math.round(view.pitch);\n const side = yaw === 0 ? \"\" : yaw === 180 ? \"directly behind\" : `${Math.abs(yaw)}° ${yaw > 0 ? \"right\" : \"left\"}`;\n const tilt = pitch === 0 ? \"\" : `${Math.abs(pitch)}° ${pitch > 0 ? \"up\" : \"down\"}`;\n const parts = [side, tilt].filter(Boolean);\n return parts.length === 0 ? \"Looking straight ahead\" : `Looking ${parts.join(\", \")}`;\n}\n","import * as React from \"react\";\nimport { VisuallyHidden } from \"react-aria\";\nimport { useInView } from \"../lib/in-view\";\nimport { cn } from \"../lib/utils\";\nimport { Slider } from \"../components/value-controls\";\nimport { createRenderer, type PanoramaPicture, type PanoramaRenderer } from \"./gl\";\nimport { clampView, degreesPerPixel, describeView, project, projectFlat, unproject, unprojectFlat, type PanoramaPoint, type PanoramaSize, type PanoramaView } from \"./projection\";\n\n// A 360 picture or video as a window you pan and zoom (strata-react issue #178, from strata-360, which\n// drew equirectangular footage with a hand-written WebGL2 shader and its own pointer, transport and\n// frame stepping). This is its own entry (`strata-react/panorama`) so an app that never shows 360 ships\n// no GL code. Nothing else in the package is as far from React Aria's world, so the choices:\n//\n// - **The picture is a canvas, the controls are keys and pointers on a group.** React Aria has no 360\n// view, so the viewer is ours; what it can give, it gives: the field-of-view slider is Strata's\n// `Slider` (React Aria's), and the pointer handling is plain pointer events (React Aria's `usePress`\n// is for a press, not a drag that turns a sphere; checked in its props: it reports a press and its\n// start and end, with no movement).\n// - **It does not own the video.** `video` is a ref to an element the app owns (`useMediaElement`,\n// `Transport`, `SeekBar` and `transportShortcuts` drive it as they drive any video, frame stepping\n// included). The viewer reads each new frame (`requestVideoFrameCallback`, else the element's events\n// and a frame loop while it plays) and uploads it: one texture upload per drawn frame, none for a\n// still picture, and no drawing at all while the viewer is off screen.\n// - **The view is controlled from outside** (`view`/`onViewChange`: yaw, pitch and field of view, in\n// degrees; `defaultView` to let it hold its own). It never animates: a view set from outside is\n// drawn at once, so an app's aim modes (follow a heading, a person, a point) are the app's own\n// function of time, and its pan on top is just another view.\n// - **From the keyboard and by touch, as well as the mouse**: arrow keys pan (Shift for more), `+` and\n// `-` zoom, `0` goes home; a drag pans (the picture follows the pointer), a wheel and a pinch zoom,\n// and a click that did not drag is `onPick` with the direction under it. A field-of-view slider is\n// an option. `maxPitch` stops the view short of the poles, where \"up\" stops meaning anything.\n// - **An overlay in the picture's coordinates**: `overlay` gets `project(yaw, pitch)` (the place in the\n// box, or null behind the camera), `unproject(x, y)` (the direction under a place) and the view, so\n// an app draws markers, aim dots and frame outlines in DOM, where they are text and buttons and take\n// focus. The same maths (projection.ts, with no GL) drives the shader.\n// - **Said in words.** The canvas is an image named by `label` and where it looks (\"Looking 40° right,\n// 5° up\"), always current; a polite status says it once the view has been still for a moment, never\n// per frame.\n// - **No WebGL2, no blank box**: the flat picture is drawn instead, cropped to the same window with the\n// same controls, and a line says so. `project` and `unproject` follow the flat drawing there, so\n// overlay markers still sit on what they mark.\n//\n// A GL context that is lost (a GPU reset, a tab in the background on a phone) is restored without the\n// app doing anything: the picture is sent again and the view redrawn.\n\nexport type PanoramaPictureSource = { image: string; video?: never } | { video: React.RefObject<HTMLVideoElement | null>; image?: never };\n\n/** What an overlay is given. */\nexport type PanoramaOverlayApi = {\n view: PanoramaView;\n size: PanoramaSize;\n /** Where the direction is in the box, or null behind the camera. */\n project: (yaw: number, pitch: number) => PanoramaPoint | null;\n /** The direction under a place in the box. */\n unproject: (x: number, y: number) => { yaw: number; pitch: number };\n /** The flat picture is being drawn (no WebGL2). */\n flat: boolean;\n};\n\nexport type PanoramaViewerProps = PanoramaPictureSource & {\n /** Names the viewer: \"360 view of the kitchen\". Required; the current direction is added to it. */\n label: string;\n /** The view, when the app holds it. */\n view?: PanoramaView;\n /** The view the viewer starts with, when it holds its own. Default straight ahead at 90°. */\n defaultView?: PanoramaView;\n /** The view changed (a drag, a key, a wheel, the slider). Not called for a view the app set. */\n onViewChange?: (view: PanoramaView) => void;\n /** A click that did not drag: the direction under it. */\n onPick?: (direction: { yaw: number; pitch: number }) => void;\n /** Highest and lowest look, degrees from the horizon. Default 85. */\n maxPitch?: number;\n /** Narrowest and widest field of view, degrees. Default 20 and 120. */\n minFov?: number;\n maxFov?: number;\n /** Zoom with the wheel. Default true. */\n wheelZoom?: boolean;\n /** Show a field-of-view slider under the picture. */\n fovSlider?: boolean;\n /** Markers and outlines drawn over the picture in its own coordinates. */\n overlay?: (api: PanoramaOverlayApi) => React.ReactNode;\n /** `\"flat\"` draws the flat picture even where WebGL2 is available (a low-power mode, or to see what a browser without it shows). Default `\"auto\"`. */\n mode?: \"auto\" | \"flat\";\n /** The shape of the box. Default 16/9. */\n aspect?: number | `${number}/${number}`;\n className?: string;\n};\n\nconst HOME: PanoramaView = { yaw: 0, pitch: 0, fov: 90 };\nconst STILL_MS = 600;\n\n/** A 360 picture or video as a window you pan and zoom, controlled from outside, with an overlay in the picture's coordinates. */\nexport function PanoramaViewer({ label, image, video, view: controlled, defaultView = HOME, onViewChange, onPick, maxPitch = 85, minFov = 20, maxFov = 120, wheelZoom = true, fovSlider = false, overlay, mode = \"auto\", aspect = \"16/9\", className }: PanoramaViewerProps) {\n const limits = React.useMemo(() => ({ maxPitch, minFov, maxFov }), [maxPitch, minFov, maxFov]);\n const [own, setOwn] = React.useState(() => clampView(defaultView, limits));\n const view = React.useMemo(() => clampView(controlled ?? own, limits), [controlled, own, limits]);\n const live = React.useRef({ view, controlled: controlled !== undefined, onViewChange, onPick, limits });\n live.current = { view, controlled: controlled !== undefined, onViewChange, onPick, limits };\n const change = React.useCallback((next: PanoramaView) => {\n const l = live.current;\n const clamped = clampView(next, l.limits);\n if (!l.controlled) setOwn(clamped);\n l.onViewChange?.(clamped);\n }, []);\n\n // The box, and the canvas in it.\n const box = React.useRef<HTMLDivElement>(null);\n const canvas = React.useRef<HTMLCanvasElement>(null);\n const [size, setSize] = React.useState<PanoramaSize>({ width: 0, height: 0 });\n React.useLayoutEffect(() => {\n const el = box.current;\n if (!el) return;\n const read = () => {\n const r = el.getBoundingClientRect();\n setSize((s) => (s.width === r.width && s.height === r.height ? s : { width: r.width, height: r.height }));\n };\n read();\n if (typeof ResizeObserver === \"undefined\") return;\n const ro = new ResizeObserver(read);\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n // The picture: a still is loaded once; a video is the app's element.\n const [still, setStill] = React.useState<HTMLImageElement | null>(null);\n React.useEffect(() => {\n if (image === undefined) {\n setStill(null);\n return;\n }\n const img = new Image();\n img.crossOrigin = \"anonymous\";\n let cancelled = false;\n img.onload = () => !cancelled && setStill(img);\n img.src = image;\n return () => {\n cancelled = true;\n img.onload = null;\n };\n }, [image]);\n\n // Drawing: only when something changed, and only while on screen.\n const { ref: visibleRef, inView } = useInView({ unsupported: true });\n // One stable callback: an inline one is called with null and the element on every render, and `useInView` would watch it come and go.\n const boxRef = React.useCallback(\n (el: HTMLDivElement | null) => {\n box.current = el;\n visibleRef(el);\n },\n [visibleRef],\n );\n const renderer = React.useRef<PanoramaRenderer | null>(null);\n const [flat, setFlat] = React.useState(false);\n const frame = React.useRef(0);\n const dirtyPicture = React.useRef(true);\n const current = React.useRef({ size, inView, flat });\n current.current = { size, inView, flat };\n\n const pictureNow = React.useCallback((): PanoramaPicture | null => {\n const v = video?.current;\n if (v) return v.readyState >= 2 && v.videoWidth > 0 ? v : null;\n return still;\n }, [video, still]);\n\n const paint = React.useCallback(() => {\n frame.current = 0;\n const c = canvas.current;\n const { size: s, inView: visible } = current.current;\n if (!c || !visible || s.width === 0 || s.height === 0) return;\n const picture = pictureNow();\n const dpr = Math.min(typeof devicePixelRatio === \"number\" ? devicePixelRatio : 1, 2);\n const w = Math.max(1, Math.round(s.width * dpr));\n const h = Math.max(1, Math.round(s.height * dpr));\n if (current.current.flat) {\n const ctx = c.getContext(\"2d\");\n if (!ctx) return;\n if (c.width !== w || c.height !== h) {\n c.width = w;\n c.height = h;\n }\n ctx.fillStyle = \"#000\";\n ctx.fillRect(0, 0, w, h);\n if (!picture) return;\n const sw = (picture as HTMLImageElement).naturalWidth || (picture as HTMLVideoElement).videoWidth || c.width;\n const sh = (picture as HTMLImageElement).naturalHeight || (picture as HTMLVideoElement).videoHeight || c.height;\n const v = live.current.view;\n const wide = (v.fov / 360) * sw;\n const tall = ((v.fov * (s.height / s.width)) / 180) * sh;\n const left = ((v.yaw - v.fov / 2 + 180) / 360) * sw;\n const top = ((90 - v.pitch) / 180) * sh - tall / 2;\n // Across the seam the window is two pieces of the picture side by side.\n for (const shift of [-sw, 0, sw]) {\n const a = Math.max(left + shift, 0);\n const b = Math.min(left + shift + wide, sw);\n if (b > a) ctx.drawImage(picture as CanvasImageSource, a, Math.max(top, 0), b - a, Math.min(tall, sh), ((a - (left + shift)) / wide) * w, 0, ((b - a) / wide) * w, h);\n }\n return;\n }\n const r = renderer.current;\n if (!r) return;\n if (picture && dirtyPicture.current) {\n r.upload(picture);\n dirtyPicture.current = false;\n }\n r.draw(live.current.view, w, h);\n }, [pictureNow]);\n const schedule = React.useCallback(() => {\n if (frame.current === 0) frame.current = requestAnimationFrame(paint);\n }, [paint]);\n\n // The renderer: made once, restored if the context is lost, and the flat picture if there is none.\n React.useEffect(() => {\n const c = canvas.current;\n if (!c) return;\n const make = () => {\n renderer.current?.dispose();\n renderer.current = mode === \"flat\" ? null : createRenderer(c);\n setFlat(renderer.current === null);\n dirtyPicture.current = true;\n schedule();\n };\n make();\n const lost = (e: Event) => {\n e.preventDefault();\n renderer.current = null;\n };\n c.addEventListener(\"webglcontextlost\", lost);\n c.addEventListener(\"webglcontextrestored\", make);\n return () => {\n c.removeEventListener(\"webglcontextlost\", lost);\n c.removeEventListener(\"webglcontextrestored\", make);\n renderer.current?.dispose();\n renderer.current = null;\n if (frame.current) cancelAnimationFrame(frame.current);\n frame.current = 0;\n };\n }, [schedule, mode]);\n\n // A new still, a new size, a new view, or coming into view: draw.\n React.useEffect(() => {\n dirtyPicture.current = true;\n }, [still]);\n React.useEffect(() => {\n schedule();\n }, [schedule, view.yaw, view.pitch, view.fov, size.width, size.height, still, inView, flat]);\n\n // A video: each new frame is one upload and one draw.\n React.useEffect(() => {\n const v = video?.current;\n if (!v || !inView) return;\n let stopped = false;\n let handle = 0;\n const onFrame = () => {\n if (stopped) return;\n dirtyPicture.current = true;\n schedule();\n handle = v.requestVideoFrameCallback(onFrame);\n };\n if (typeof v.requestVideoFrameCallback === \"function\") {\n handle = v.requestVideoFrameCallback(onFrame);\n return () => {\n stopped = true;\n v.cancelVideoFrameCallback?.(handle);\n };\n }\n // No frame callback: the element's own events, and a frame loop while it plays.\n const touch = () => {\n dirtyPicture.current = true;\n schedule();\n };\n const events = [\"loadeddata\", \"seeked\", \"timeupdate\", \"play\", \"pause\"] as const;\n for (const e of events) v.addEventListener(e, touch);\n let loop = 0;\n const tick = () => {\n if (!v.paused) touch();\n loop = requestAnimationFrame(tick);\n };\n loop = requestAnimationFrame(tick);\n return () => {\n for (const e of events) v.removeEventListener(e, touch);\n cancelAnimationFrame(loop);\n };\n }, [video, inView, schedule]);\n\n // Pointer: drag turns the view with the pointer, two pointers pinch, a click that did not drag picks.\n const pointers = React.useRef(new Map<number, { x: number; y: number }>());\n const gesture = React.useRef<{ moved: boolean; pinch: number | null; start: { x: number; y: number } } | null>(null);\n const hostRect = () => box.current!.getBoundingClientRect();\n const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n if (e.button !== 0 && e.pointerType === \"mouse\") return;\n pointers.current.set(e.pointerId, { x: e.clientX, y: e.clientY });\n e.currentTarget.setPointerCapture?.(e.pointerId);\n const [first, second] = [...pointers.current.values()];\n const distance = second ? Math.hypot(first.x - second.x, first.y - second.y) : null;\n gesture.current = { moved: false, pinch: distance, start: { x: e.clientX, y: e.clientY } };\n e.currentTarget.focus({ preventScroll: true });\n };\n const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n const last = pointers.current.get(e.pointerId);\n if (!last || !gesture.current) return;\n const now = { x: e.clientX, y: e.clientY };\n pointers.current.set(e.pointerId, now);\n const v = live.current.view;\n const s = { width: hostRect().width, height: hostRect().height };\n if (pointers.current.size === 2) {\n const [a, b] = [...pointers.current.values()];\n const d = Math.hypot(a.x - b.x, a.y - b.y);\n if (gesture.current.pinch && d > 0) change({ ...v, fov: v.fov * (gesture.current.pinch / d) });\n gesture.current.pinch = d;\n gesture.current.moved = true;\n return;\n }\n if (Math.hypot(now.x - gesture.current.start.x, now.y - gesture.current.start.y) > 4) gesture.current.moved = true;\n if (!gesture.current.moved) return;\n // The picture follows the pointer: dragging right turns the view left.\n const per = degreesPerPixel(v, s);\n change({ ...v, yaw: v.yaw - (now.x - last.x) * per, pitch: v.pitch + (now.y - last.y) * per });\n };\n const onPointerUp = (e: React.PointerEvent<HTMLDivElement>) => {\n const g = gesture.current;\n pointers.current.delete(e.pointerId);\n if (pointers.current.size === 0) {\n gesture.current = null;\n if (g && !g.moved && live.current.onPick) {\n const r = hostRect();\n const s = { width: r.width, height: r.height };\n const x = e.clientX - r.left;\n const y = e.clientY - r.top;\n live.current.onPick(current.current.flat ? unprojectFlat(live.current.view, s, x, y) : unproject(live.current.view, s, x, y));\n }\n } else if (g) g.pinch = null;\n };\n\n // The wheel zooms; native, because React's wheel listener is passive and the page must not scroll too.\n React.useEffect(() => {\n const el = box.current;\n if (!el || !wheelZoom) return;\n const onWheel = (e: WheelEvent) => {\n e.preventDefault();\n const v = live.current.view;\n change({ ...v, fov: v.fov * Math.exp(e.deltaY * 0.0015) });\n };\n el.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => el.removeEventListener(\"wheel\", onWheel);\n }, [wheelZoom, change]);\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n const v = live.current.view;\n const turn = (v.fov / 12) * (e.shiftKey ? 3 : 1);\n if (e.key === \"ArrowLeft\") change({ ...v, yaw: v.yaw - turn });\n else if (e.key === \"ArrowRight\") change({ ...v, yaw: v.yaw + turn });\n else if (e.key === \"ArrowUp\") change({ ...v, pitch: v.pitch + turn });\n else if (e.key === \"ArrowDown\") change({ ...v, pitch: v.pitch - turn });\n else if (e.key === \"+\" || e.key === \"=\") change({ ...v, fov: v.fov * 0.8 });\n else if (e.key === \"-\" || e.key === \"_\") change({ ...v, fov: v.fov * 1.25 });\n else if (e.key === \"0\") change(defaultView);\n else return;\n e.preventDefault();\n };\n\n // Said in words: always on the picture; politely once the view has been still for a moment.\n const direction = describeView(view);\n const [said, setSaid] = React.useState(\"\");\n const first = React.useRef(true);\n React.useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n const t = setTimeout(() => setSaid(`${direction}, field of view ${Math.round(view.fov)}°`), STILL_MS);\n return () => clearTimeout(t);\n }, [direction, view.fov]);\n\n const api: PanoramaOverlayApi = {\n view,\n size,\n flat,\n project: (yaw, pitch) => (flat ? projectFlat(view, size, yaw, pitch) : project(view, size, yaw, pitch)),\n unproject: (x, y) => (flat ? unprojectFlat(view, size, x, y) : unproject(view, size, x, y)),\n };\n const slider = fovSlider ? <Slider aria-label=\"Field of view\" value={Math.round(view.fov)} onChange={(fov) => change({ ...view, fov })} min={minFov} max={maxFov} step={1} unit=\"degree\" /> : null;\n\n return (\n <div className={cn(\"grid min-w-0 gap-2\", className)}>\n <div\n ref={boxRef}\n role=\"group\"\n aria-label={label}\n aria-describedby={undefined}\n tabIndex={0}\n onKeyDown={onKeyDown}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n className=\"relative w-full cursor-grab touch-none overflow-hidden rounded-surface bg-surface-sunken select-none active:cursor-grabbing\"\n style={{ aspectRatio: aspect }}\n >\n <canvas key={mode === \"flat\" ? \"2d\" : \"gl\"} ref={canvas} role=\"img\" aria-label={`${label}. ${direction}, field of view ${Math.round(view.fov)}°`} className=\"absolute inset-0 size-full\" />\n {overlay && size.width > 0 && <div className=\"pointer-events-none absolute inset-0\">{overlay(api)}</div>}\n </div>\n {flat && <p className=\"type-body-sm text-muted-foreground\">This browser cannot draw the 360 view, so the flat picture is shown. The controls work the same.</p>}\n {slider}\n <VisuallyHidden>\n <span role=\"status\">{said}</span>\n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,GAAG;EAAG,WAAW,QAAQ,OAAO;GAAE,GAAG;GAAM;EAAI,CAAC;EAAG,KAAK;EAAQ,KAAK;EAAQ,MAAM;EAAG,MAAK;CAAU,CAAA,IAAI;CAE9L,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,sBAAsB,SAAS;EAAlD,UAAA;GACE,qBAAC,OAAD;IACE,KAAK;IACL,MAAK;IACL,cAAY;IACZ,oBAAkB,KAAA;IAClB,UAAU;IACC;IACI;IACA;IACF;IACb,iBAAiB;IACjB,WAAU;IACV,OAAO,EAAE,aAAa,OAAO;IAZ/B,UAAA,CAcE,oBAAC,UAAD;KAA4C,KAAK;KAAQ,MAAK;KAAM,cAAY,GAAG,MAAM,IAAI,UAAU,kBAAkB,KAAK,MAAM,KAAK,GAAG,EAAE;KAAI,WAAU;IAA8B,GAA7K,SAAS,SAAS,OAAO,IAAoJ,GACzL,WAAW,KAAK,QAAQ,KAAK,oBAAC,OAAD;KAAK,WAAU;KAAwC,UAAA,QAAQ,GAAG;IAAO,CAAA,CACpG;;GACJ,QAAQ,oBAAC,KAAD;IAAG,WAAU;IAAqC,UAAA;GAAmG,CAAA;GAC7J;GACD,oBAAC,gBAAD,EAAA,UACE,oBAAC,QAAD;IAAM,MAAK;IAAU,UAAA;GAAW,CAAA,EAClB,CAAA;EACb;;AAET"}
1
+ {"version":3,"file":"panorama.js","names":[],"sources":["../src/panorama/gl.ts","../src/panorama/projection.ts","../src/panorama/panorama-viewer.tsx"],"sourcesContent":["import type { PanoramaView } from \"./projection\";\n\n// The WebGL2 side of `PanoramaViewer` (strata-react issue #178): one full-screen triangle, and a\n// fragment shader that does for every pixel what `project`/`unproject` do for one (projection.ts holds\n// the same formulas, and tests hold the two to each other): build the ray through the pixel from the\n// view's yaw, pitch and field of view, turn it into longitude and latitude, and read the equirectangular\n// texture there. The texture repeats across the seam (longitude) and clamps at the poles. No mipmaps:\n// the longitude wraps with an `atan`, whose jump at the seam would make a mipmapped lookup draw a line\n// one pixel wide down it; plain linear filtering draws none.\n//\n// Cost, as documented for apps: one texture upload per *drawn video frame* (`texImage2D` of the\n// `<video>`), none for a still picture (uploaded once), and a draw only when the view, the size or the\n// picture changed, never on a timer.\n\nconst VERTEX = `#version 300 es\nin vec2 aPos;\nout vec2 vNdc;\nvoid main() { vNdc = aPos; gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst FRAGMENT = `#version 300 es\nprecision highp float;\nin vec2 vNdc;\nout vec4 outColor;\nuniform sampler2D uPicture;\nuniform float uYaw;\nuniform float uPitch;\nuniform float uTanHalf;\nuniform float uAspect;\nconst float PI = 3.14159265358979;\nvoid main() {\n vec3 forward = vec3(cos(uPitch) * sin(uYaw), sin(uPitch), cos(uPitch) * cos(uYaw));\n vec3 right = vec3(cos(uYaw), 0.0, -sin(uYaw));\n vec3 up = vec3(-sin(uPitch) * sin(uYaw), cos(uPitch), -sin(uPitch) * cos(uYaw));\n vec3 ray = normalize(forward + vNdc.x * uTanHalf * right + vNdc.y * (uTanHalf / uAspect) * up);\n float lon = atan(ray.x, ray.z);\n float lat = asin(clamp(ray.y, -1.0, 1.0));\n outColor = texture(uPicture, vec2(lon / (2.0 * PI) + 0.5, 0.5 - lat / PI));\n}`;\n\n/** Anything WebGL can take as a texture: a decoded image or a playing video. */\nexport type PanoramaPicture = HTMLImageElement | HTMLVideoElement | ImageBitmap | HTMLCanvasElement;\n\n/** What draws the window. */\nexport type PanoramaRenderer = {\n /** Sends the picture to the GPU. Call when the picture is a new one (an image) or a new frame (a video). */\n upload: (picture: PanoramaPicture) => void;\n /** Draws the view into a canvas of `width` by `height` device pixels. */\n draw: (view: PanoramaView, width: number, height: number) => void;\n /** How many times `upload` has sent a picture (a video frame, an image), for the documented cost and for tests. */\n uploads: () => number;\n /** Frees the GPU objects. */\n dispose: () => void;\n};\n\n/** Makes a renderer on `canvas`, or null where WebGL2 is not available (the viewer then shows the flat picture). */\nexport function createRenderer(canvas: HTMLCanvasElement): PanoramaRenderer | null {\n const gl = canvas.getContext(\"webgl2\", { antialias: false, preserveDrawingBuffer: false, alpha: false }) as WebGL2RenderingContext | null;\n if (!gl) return null;\n const compile = (type: number, source: string) => {\n const shader = gl.createShader(type)!;\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const log = gl.getShaderInfoLog(shader);\n gl.deleteShader(shader);\n throw new Error(`Panorama shader: ${log}`);\n }\n return shader;\n };\n let program: WebGLProgram;\n try {\n program = gl.createProgram()!;\n gl.attachShader(program, compile(gl.VERTEX_SHADER, VERTEX));\n gl.attachShader(program, compile(gl.FRAGMENT_SHADER, FRAGMENT));\n gl.linkProgram(program);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) throw new Error(`Panorama program: ${gl.getProgramInfoLog(program)}`);\n } catch {\n return null;\n }\n gl.useProgram(program);\n const buffer = gl.createBuffer();\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n // One triangle that covers the screen.\n gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n const position = gl.getAttribLocation(program, \"aPos\");\n gl.enableVertexAttribArray(position);\n gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);\n const texture = gl.createTexture();\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n const uniforms = {\n yaw: gl.getUniformLocation(program, \"uYaw\"),\n pitch: gl.getUniformLocation(program, \"uPitch\"),\n tanHalf: gl.getUniformLocation(program, \"uTanHalf\"),\n aspect: gl.getUniformLocation(program, \"uAspect\"),\n picture: gl.getUniformLocation(program, \"uPicture\"),\n };\n gl.uniform1i(uniforms.picture, 0);\n let uploaded = 0;\n let has = false;\n\n return {\n upload(picture) {\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, picture);\n uploaded++;\n has = true;\n },\n draw(view, width, height) {\n if (canvas.width !== width || canvas.height !== height) {\n canvas.width = width;\n canvas.height = height;\n }\n gl.viewport(0, 0, width, height);\n if (!has) {\n gl.clearColor(0, 0, 0, 1);\n gl.clear(gl.COLOR_BUFFER_BIT);\n return;\n }\n const rad = Math.PI / 180;\n gl.uniform1f(uniforms.yaw, view.yaw * rad);\n gl.uniform1f(uniforms.pitch, view.pitch * rad);\n gl.uniform1f(uniforms.tanHalf, Math.tan((view.fov * rad) / 2));\n gl.uniform1f(uniforms.aspect, width / height);\n gl.drawArrays(gl.TRIANGLES, 0, 3);\n },\n uploads: () => uploaded,\n dispose() {\n gl.deleteTexture(texture);\n gl.deleteBuffer(buffer);\n gl.deleteProgram(program);\n },\n };\n}\n","// The geometry of `PanoramaViewer` (strata-react issue #178), with no DOM and no GL so every case\n// is tested on its own and the GL shader is held to the same numbers. A 360 picture is\n// *equirectangular*: longitude across, latitude down. The viewer shows a *rectilinear* window into the\n// sphere, as a camera does: straight lines stay straight, and the width of what is seen is the\n// horizontal field of view `fov`.\n//\n// Angles are degrees, because that is what an app and a person talk in. `yaw` is the heading: 0 is the\n// middle of the picture, positive to the right, wrapped to (-180, 180]. `pitch` is the elevation:\n// 0 is the horizon, positive up, limited to +-90 (the apps' own `maxPitch` is kept below that). A\n// direction in the world is a unit vector `(cos p sin y, sin p, cos p cos y)`; the camera's forward,\n// right and up are built from the view's yaw and pitch (no roll: upright footage). A point is drawn\n// where its direction crosses the image plane, `fpx = (width / 2) / tan(fov / 2)` pixels from the camera.\n\n/** Where the window looks and how wide it sees, degrees. */\nexport type PanoramaView = { yaw: number; pitch: number; fov: number };\n\n/** The size of the picture box in CSS pixels. */\nexport type PanoramaSize = { width: number; height: number };\n\n/** A place in the box. `inside` says it is within the box; a point behind the camera has none (`project` returns null). */\nexport type PanoramaPoint = { x: number; y: number; inside: boolean };\n\nconst RAD = Math.PI / 180;\nconst DEG = 180 / Math.PI;\n\n/** Wraps a heading to (-180, 180]. */\nexport function wrapYaw(yaw: number): number {\n const w = ((((yaw + 180) % 360) + 360) % 360) - 180;\n return w === -180 ? 180 : w;\n}\n\n/** The smallest signed turn from heading `from` to heading `to`, in (-180, 180]. Use it for a difference of headings, never `to - from`. */\nexport const yawDelta = (from: number, to: number) => wrapYaw(to - from);\n\n/** Keeps a view inside its limits: heading wrapped, pitch within +-`maxPitch`, field of view within `minFov` to `maxFov`. */\nexport function clampView(view: PanoramaView, { maxPitch = 85, minFov = 20, maxFov = 120 }: { maxPitch?: number; minFov?: number; maxFov?: number } = {}): PanoramaView {\n return { yaw: wrapYaw(view.yaw), pitch: Math.min(Math.max(view.pitch, -maxPitch), maxPitch), fov: Math.min(Math.max(view.fov, minFov), maxFov) };\n}\n\nconst focal = (view: PanoramaView, size: PanoramaSize) => size.width / 2 / Math.tan((view.fov * RAD) / 2);\n\nfunction basis(view: PanoramaView) {\n const y = view.yaw * RAD;\n const p = view.pitch * RAD;\n const forward = [Math.cos(p) * Math.sin(y), Math.sin(p), Math.cos(p) * Math.cos(y)] as const;\n const right = [Math.cos(y), 0, -Math.sin(y)] as const;\n const up = [-Math.sin(p) * Math.sin(y), Math.cos(p), -Math.sin(p) * Math.cos(y)] as const;\n return { forward, right, up };\n}\nconst dot = (a: readonly number[], b: readonly number[]) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n\n/** Where the direction (`yaw`, `pitch`) is drawn in the box for `view`, or null when it is behind the camera. */\nexport function project(view: PanoramaView, size: PanoramaSize, yaw: number, pitch: number): PanoramaPoint | null {\n const { forward, right, up } = basis(view);\n const p = pitch * RAD;\n const y = yaw * RAD;\n const d = [Math.cos(p) * Math.sin(y), Math.sin(p), Math.cos(p) * Math.cos(y)] as const;\n const z = dot(d, forward);\n if (z <= 1e-9) return null;\n const f = focal(view, size);\n const x = size.width / 2 + (f * dot(d, right)) / z;\n const yy = size.height / 2 - (f * dot(d, up)) / z;\n return { x, y: yy, inside: x >= 0 && x <= size.width && yy >= 0 && yy <= size.height };\n}\n\n/** The direction under a point of the box for `view`: the inverse of `project`. */\nexport function unproject(view: PanoramaView, size: PanoramaSize, x: number, y: number): { yaw: number; pitch: number } {\n const { forward, right, up } = basis(view);\n const f = focal(view, size);\n const a = (x - size.width / 2) / f;\n const b = -(y - size.height / 2) / f;\n const v = [forward[0] + a * right[0] + b * up[0], forward[1] + a * right[1] + b * up[1], forward[2] + a * right[2] + b * up[2]] as const;\n const length = Math.hypot(v[0], v[1], v[2]);\n return { yaw: wrapYaw(Math.atan2(v[0], v[2]) * DEG), pitch: Math.asin(Math.min(Math.max(v[1] / length, -1), 1)) * DEG };\n}\n\n/** Pixels to degrees at the middle of the box: how far a drag of `px` turns the view. */\nexport const degreesPerPixel = (view: PanoramaView, size: PanoramaSize) => (Math.atan(1 / focal(view, size)) * DEG);\n\n/** The flat picture's own mapping, for the fallback with no WebGL: longitude and latitude are straight across and down, the visible rectangle is `fov` wide and as tall as the box's shape makes it. */\nexport function projectFlat(view: PanoramaView, size: PanoramaSize, yaw: number, pitch: number): PanoramaPoint {\n const perPixel = view.fov / size.width;\n const x = size.width / 2 + yawDelta(view.yaw, yaw) / perPixel;\n const y = size.height / 2 - (pitch - view.pitch) / perPixel;\n return { x, y, inside: x >= 0 && x <= size.width && y >= 0 && y <= size.height };\n}\n\n/** The inverse of `projectFlat`. */\nexport function unprojectFlat(view: PanoramaView, size: PanoramaSize, x: number, y: number): { yaw: number; pitch: number } {\n const perPixel = view.fov / size.width;\n return { yaw: wrapYaw(view.yaw + (x - size.width / 2) * perPixel), pitch: Math.min(Math.max(view.pitch - (y - size.height / 2) * perPixel, -90), 90) };\n}\n\n/** The direction in words: \"Looking 40° right, 5° up\", \"Looking straight ahead\". Whole degrees; nothing is said for less than half a degree. */\nexport function describeView(view: Pick<PanoramaView, \"yaw\" | \"pitch\">): string {\n const yaw = Math.round(wrapYaw(view.yaw));\n const pitch = Math.round(view.pitch);\n const side = yaw === 0 ? \"\" : yaw === 180 ? \"directly behind\" : `${Math.abs(yaw)}° ${yaw > 0 ? \"right\" : \"left\"}`;\n const tilt = pitch === 0 ? \"\" : `${Math.abs(pitch)}° ${pitch > 0 ? \"up\" : \"down\"}`;\n const parts = [side, tilt].filter(Boolean);\n return parts.length === 0 ? \"Looking straight ahead\" : `Looking ${parts.join(\", \")}`;\n}\n","import * as React from \"react\";\nimport { VisuallyHidden } from \"react-aria\";\nimport { useInView } from \"../lib/in-view\";\nimport { cn } from \"../lib/utils\";\nimport { Slider } from \"../components/value-controls\";\nimport { createRenderer, type PanoramaPicture, type PanoramaRenderer } from \"./gl\";\nimport { clampView, degreesPerPixel, describeView, project, projectFlat, unproject, unprojectFlat, type PanoramaPoint, type PanoramaSize, type PanoramaView } from \"./projection\";\n\n// A 360 picture or video as a window you pan and zoom (strata-react issue #178, from strata-360, which\n// drew equirectangular footage with a hand-written WebGL2 shader and its own pointer, transport and\n// frame stepping). This is its own entry (`strata-react/panorama`) so an app that never shows 360 ships\n// no GL code. Nothing else in the package is as far from React Aria's world, so the choices:\n//\n// - **The picture is a canvas, the controls are keys and pointers on a group.** React Aria has no 360\n// view, so the viewer is ours; what it can give, it gives: the field-of-view slider is Strata's\n// `Slider` (React Aria's), and the pointer handling is plain pointer events (React Aria's `usePress`\n// is for a press, not a drag that turns a sphere; checked in its props: it reports a press and its\n// start and end, with no movement).\n// - **It does not own the video.** `video` is a ref to an element the app owns (`useMediaElement`,\n// `Transport`, `SeekBar` and `transportShortcuts` drive it as they drive any video, frame stepping\n// included). The viewer reads each new frame (`requestVideoFrameCallback`, else the element's events\n// and a frame loop while it plays) and uploads it: one texture upload per drawn frame, none for a\n// still picture, and no drawing at all while the viewer is off screen.\n// - **The view is controlled from outside** (`view`/`onViewChange`: yaw, pitch and field of view, in\n// degrees; `defaultView` to let it hold its own). It never animates: a view set from outside is\n// drawn at once, so an app's aim modes (follow a heading, a person, a point) are the app's own\n// function of time, and its pan on top is just another view.\n// - **From the keyboard and by touch, as well as the mouse**: arrow keys pan (Shift for more), `+` and\n// `-` zoom, `0` goes home; a drag pans (the picture follows the pointer), a wheel and a pinch zoom,\n// and a click that did not drag is `onPick` with the direction under it. A field-of-view slider is\n// an option. `maxPitch` stops the view short of the poles, where \"up\" stops meaning anything.\n// - **An overlay in the picture's coordinates**: `overlay` gets `project(yaw, pitch)` (the place in the\n// box, or null behind the camera), `unproject(x, y)` (the direction under a place) and the view, so\n// an app draws markers, aim dots and frame outlines in DOM, where they are text and buttons and take\n// focus. The same maths (projection.ts, with no GL) drives the shader.\n// - **Said in words.** The canvas is an image named by `label` and where it looks (\"Looking 40° right,\n// 5° up\"), always current; a polite status says it once the view has been still for a moment, never\n// per frame.\n// - **No WebGL2, no blank box**: the flat picture is drawn instead, cropped to the same window with the\n// same controls, and a line says so. `project` and `unproject` follow the flat drawing there, so\n// overlay markers still sit on what they mark.\n//\n// A GL context that is lost (a GPU reset, a tab in the background on a phone) is restored without the\n// app doing anything: the picture is sent again and the view redrawn.\n\nexport type PanoramaPictureSource = { image: string; video?: never } | { video: React.RefObject<HTMLVideoElement | null>; image?: never };\n\n/** What an overlay is given. */\nexport type PanoramaOverlayApi = {\n view: PanoramaView;\n size: PanoramaSize;\n /** Where the direction is in the box, or null behind the camera. */\n project: (yaw: number, pitch: number) => PanoramaPoint | null;\n /** The direction under a place in the box. */\n unproject: (x: number, y: number) => { yaw: number; pitch: number };\n /** The flat picture is being drawn (no WebGL2). */\n flat: boolean;\n};\n\nexport type PanoramaViewerProps = PanoramaPictureSource & {\n /** Names the viewer: \"360 view of the kitchen\". Required; the current direction is added to it. */\n label: string;\n /** The view, when the app holds it. */\n view?: PanoramaView;\n /** The view the viewer starts with, when it holds its own. Default straight ahead at 90°. */\n defaultView?: PanoramaView;\n /** The view changed (a drag, a key, a wheel, the slider). Not called for a view the app set. */\n onViewChange?: (view: PanoramaView) => void;\n /** A click that did not drag: the direction under it. */\n onPick?: (direction: { yaw: number; pitch: number }) => void;\n /** Highest and lowest look, degrees from the horizon. Default 85. */\n maxPitch?: number;\n /** Narrowest and widest field of view, degrees. Default 20 and 120. */\n minFov?: number;\n maxFov?: number;\n /** Zoom with the wheel. Default true. */\n wheelZoom?: boolean;\n /** Show a field-of-view slider under the picture. */\n fovSlider?: boolean;\n /** Markers and outlines drawn over the picture in its own coordinates. */\n overlay?: (api: PanoramaOverlayApi) => React.ReactNode;\n /** `\"flat\"` draws the flat picture even where WebGL2 is available (a low-power mode, or to see what a browser without it shows). Default `\"auto\"`. */\n mode?: \"auto\" | \"flat\";\n /** The shape of the box. Default 16/9. */\n aspect?: number | `${number}/${number}`;\n className?: string;\n};\n\nconst HOME: PanoramaView = { yaw: 0, pitch: 0, fov: 90 };\nconst STILL_MS = 600;\n\n/** A 360 picture or video as a window you pan and zoom, controlled from outside, with an overlay in the picture's coordinates. */\nexport function PanoramaViewer({ label, image, video, view: controlled, defaultView = HOME, onViewChange, onPick, maxPitch = 85, minFov = 20, maxFov = 120, wheelZoom = true, fovSlider = false, overlay, mode = \"auto\", aspect = \"16/9\", className }: PanoramaViewerProps) {\n const limits = React.useMemo(() => ({ maxPitch, minFov, maxFov }), [maxPitch, minFov, maxFov]);\n const [own, setOwn] = React.useState(() => clampView(defaultView, limits));\n const view = React.useMemo(() => clampView(controlled ?? own, limits), [controlled, own, limits]);\n const live = React.useRef({ view, controlled: controlled !== undefined, onViewChange, onPick, limits });\n live.current = { view, controlled: controlled !== undefined, onViewChange, onPick, limits };\n const change = React.useCallback((next: PanoramaView) => {\n const l = live.current;\n const clamped = clampView(next, l.limits);\n if (!l.controlled) setOwn(clamped);\n l.onViewChange?.(clamped);\n }, []);\n\n // The box, and the canvas in it.\n const box = React.useRef<HTMLDivElement>(null);\n const canvas = React.useRef<HTMLCanvasElement>(null);\n const [size, setSize] = React.useState<PanoramaSize>({ width: 0, height: 0 });\n React.useLayoutEffect(() => {\n const el = box.current;\n if (!el) return;\n const read = () => {\n const r = el.getBoundingClientRect();\n setSize((s) => (s.width === r.width && s.height === r.height ? s : { width: r.width, height: r.height }));\n };\n read();\n if (typeof ResizeObserver === \"undefined\") return;\n const ro = new ResizeObserver(read);\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n // The picture: a still is loaded once; a video is the app's element.\n const [still, setStill] = React.useState<HTMLImageElement | null>(null);\n React.useEffect(() => {\n if (image === undefined) {\n setStill(null);\n return;\n }\n const img = new Image();\n img.crossOrigin = \"anonymous\";\n let cancelled = false;\n img.onload = () => !cancelled && setStill(img);\n img.src = image;\n return () => {\n cancelled = true;\n img.onload = null;\n };\n }, [image]);\n\n // Drawing: only when something changed, and only while on screen.\n const { ref: visibleRef, inView } = useInView({ unsupported: true });\n // One stable callback: an inline one is called with null and the element on every render, and `useInView` would watch it come and go.\n const boxRef = React.useCallback(\n (el: HTMLDivElement | null) => {\n box.current = el;\n visibleRef(el);\n },\n [visibleRef],\n );\n const renderer = React.useRef<PanoramaRenderer | null>(null);\n const [flat, setFlat] = React.useState(false);\n const frame = React.useRef(0);\n const dirtyPicture = React.useRef(true);\n const current = React.useRef({ size, inView, flat });\n current.current = { size, inView, flat };\n\n const pictureNow = React.useCallback((): PanoramaPicture | null => {\n const v = video?.current;\n if (v) return v.readyState >= 2 && v.videoWidth > 0 ? v : null;\n return still;\n }, [video, still]);\n\n const paint = React.useCallback(() => {\n frame.current = 0;\n const c = canvas.current;\n const { size: s, inView: visible } = current.current;\n if (!c || !visible || s.width === 0 || s.height === 0) return;\n const picture = pictureNow();\n const dpr = Math.min(typeof devicePixelRatio === \"number\" ? devicePixelRatio : 1, 2);\n const w = Math.max(1, Math.round(s.width * dpr));\n const h = Math.max(1, Math.round(s.height * dpr));\n if (current.current.flat) {\n const ctx = c.getContext(\"2d\");\n if (!ctx) return;\n if (c.width !== w || c.height !== h) {\n c.width = w;\n c.height = h;\n }\n ctx.fillStyle = \"#000\";\n ctx.fillRect(0, 0, w, h);\n if (!picture) return;\n const sw = (picture as HTMLImageElement).naturalWidth || (picture as HTMLVideoElement).videoWidth || c.width;\n const sh = (picture as HTMLImageElement).naturalHeight || (picture as HTMLVideoElement).videoHeight || c.height;\n const v = live.current.view;\n const wide = (v.fov / 360) * sw;\n const tall = ((v.fov * (s.height / s.width)) / 180) * sh;\n const left = ((v.yaw - v.fov / 2 + 180) / 360) * sw;\n const top = ((90 - v.pitch) / 180) * sh - tall / 2;\n // Across the seam the window is two pieces of the picture side by side.\n for (const shift of [-sw, 0, sw]) {\n const a = Math.max(left + shift, 0);\n const b = Math.min(left + shift + wide, sw);\n if (b > a) ctx.drawImage(picture as CanvasImageSource, a, Math.max(top, 0), b - a, Math.min(tall, sh), ((a - (left + shift)) / wide) * w, 0, ((b - a) / wide) * w, h);\n }\n return;\n }\n const r = renderer.current;\n if (!r) return;\n if (picture && dirtyPicture.current) {\n r.upload(picture);\n dirtyPicture.current = false;\n }\n r.draw(live.current.view, w, h);\n }, [pictureNow]);\n const schedule = React.useCallback(() => {\n if (frame.current === 0) frame.current = requestAnimationFrame(paint);\n }, [paint]);\n\n // The renderer: made once, restored if the context is lost, and the flat picture if there is none.\n React.useEffect(() => {\n const c = canvas.current;\n if (!c) return;\n const make = () => {\n renderer.current?.dispose();\n renderer.current = mode === \"flat\" ? null : createRenderer(c);\n setFlat(renderer.current === null);\n dirtyPicture.current = true;\n schedule();\n };\n make();\n const lost = (e: Event) => {\n e.preventDefault();\n renderer.current = null;\n };\n c.addEventListener(\"webglcontextlost\", lost);\n c.addEventListener(\"webglcontextrestored\", make);\n return () => {\n c.removeEventListener(\"webglcontextlost\", lost);\n c.removeEventListener(\"webglcontextrestored\", make);\n renderer.current?.dispose();\n renderer.current = null;\n if (frame.current) cancelAnimationFrame(frame.current);\n frame.current = 0;\n };\n }, [schedule, mode]);\n\n // A new still, a new size, a new view, or coming into view: draw.\n React.useEffect(() => {\n dirtyPicture.current = true;\n }, [still]);\n React.useEffect(() => {\n schedule();\n }, [schedule, view.yaw, view.pitch, view.fov, size.width, size.height, still, inView, flat]);\n\n // A video: each new frame is one upload and one draw.\n React.useEffect(() => {\n const v = video?.current;\n if (!v || !inView) return;\n let stopped = false;\n let handle = 0;\n const onFrame = () => {\n if (stopped) return;\n dirtyPicture.current = true;\n schedule();\n handle = v.requestVideoFrameCallback(onFrame);\n };\n if (typeof v.requestVideoFrameCallback === \"function\") {\n handle = v.requestVideoFrameCallback(onFrame);\n return () => {\n stopped = true;\n v.cancelVideoFrameCallback?.(handle);\n };\n }\n // No frame callback: the element's own events, and a frame loop while it plays.\n const touch = () => {\n dirtyPicture.current = true;\n schedule();\n };\n const events = [\"loadeddata\", \"seeked\", \"timeupdate\", \"play\", \"pause\"] as const;\n for (const e of events) v.addEventListener(e, touch);\n let loop = 0;\n const tick = () => {\n if (!v.paused) touch();\n loop = requestAnimationFrame(tick);\n };\n loop = requestAnimationFrame(tick);\n return () => {\n for (const e of events) v.removeEventListener(e, touch);\n cancelAnimationFrame(loop);\n };\n }, [video, inView, schedule]);\n\n // Pointer: drag turns the view with the pointer, two pointers pinch, a click that did not drag picks.\n const pointers = React.useRef(new Map<number, { x: number; y: number }>());\n const gesture = React.useRef<{ moved: boolean; pinch: number | null; start: { x: number; y: number } } | null>(null);\n const hostRect = () => box.current!.getBoundingClientRect();\n const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n if (e.button !== 0 && e.pointerType === \"mouse\") return;\n pointers.current.set(e.pointerId, { x: e.clientX, y: e.clientY });\n e.currentTarget.setPointerCapture?.(e.pointerId);\n const [first, second] = [...pointers.current.values()];\n const distance = second ? Math.hypot(first.x - second.x, first.y - second.y) : null;\n gesture.current = { moved: false, pinch: distance, start: { x: e.clientX, y: e.clientY } };\n e.currentTarget.focus({ preventScroll: true });\n };\n const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n const last = pointers.current.get(e.pointerId);\n if (!last || !gesture.current) return;\n const now = { x: e.clientX, y: e.clientY };\n pointers.current.set(e.pointerId, now);\n const v = live.current.view;\n const s = { width: hostRect().width, height: hostRect().height };\n if (pointers.current.size === 2) {\n const [a, b] = [...pointers.current.values()];\n const d = Math.hypot(a.x - b.x, a.y - b.y);\n if (gesture.current.pinch && d > 0) change({ ...v, fov: v.fov * (gesture.current.pinch / d) });\n gesture.current.pinch = d;\n gesture.current.moved = true;\n return;\n }\n if (Math.hypot(now.x - gesture.current.start.x, now.y - gesture.current.start.y) > 4) gesture.current.moved = true;\n if (!gesture.current.moved) return;\n // The picture follows the pointer: dragging right turns the view left.\n const per = degreesPerPixel(v, s);\n change({ ...v, yaw: v.yaw - (now.x - last.x) * per, pitch: v.pitch + (now.y - last.y) * per });\n };\n const onPointerUp = (e: React.PointerEvent<HTMLDivElement>) => {\n const g = gesture.current;\n pointers.current.delete(e.pointerId);\n if (pointers.current.size === 0) {\n gesture.current = null;\n if (g && !g.moved && live.current.onPick) {\n const r = hostRect();\n const s = { width: r.width, height: r.height };\n const x = e.clientX - r.left;\n const y = e.clientY - r.top;\n live.current.onPick(current.current.flat ? unprojectFlat(live.current.view, s, x, y) : unproject(live.current.view, s, x, y));\n }\n } else if (g) g.pinch = null;\n };\n\n // The wheel zooms; native, because React's wheel listener is passive and the page must not scroll too.\n React.useEffect(() => {\n const el = box.current;\n if (!el || !wheelZoom) return;\n const onWheel = (e: WheelEvent) => {\n e.preventDefault();\n const v = live.current.view;\n change({ ...v, fov: v.fov * Math.exp(e.deltaY * 0.0015) });\n };\n el.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => el.removeEventListener(\"wheel\", onWheel);\n }, [wheelZoom, change]);\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n const v = live.current.view;\n const turn = (v.fov / 12) * (e.shiftKey ? 3 : 1);\n if (e.key === \"ArrowLeft\") change({ ...v, yaw: v.yaw - turn });\n else if (e.key === \"ArrowRight\") change({ ...v, yaw: v.yaw + turn });\n else if (e.key === \"ArrowUp\") change({ ...v, pitch: v.pitch + turn });\n else if (e.key === \"ArrowDown\") change({ ...v, pitch: v.pitch - turn });\n else if (e.key === \"+\" || e.key === \"=\") change({ ...v, fov: v.fov * 0.8 });\n else if (e.key === \"-\" || e.key === \"_\") change({ ...v, fov: v.fov * 1.25 });\n else if (e.key === \"0\") change(defaultView);\n else return;\n e.preventDefault();\n };\n\n // Said in words: always on the picture; politely once the view has been still for a moment.\n const direction = describeView(view);\n const [said, setSaid] = React.useState(\"\");\n const first = React.useRef(true);\n React.useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n const t = setTimeout(() => setSaid(`${direction}, field of view ${Math.round(view.fov)}°`), STILL_MS);\n return () => clearTimeout(t);\n }, [direction, view.fov]);\n\n const api: PanoramaOverlayApi = {\n view,\n size,\n flat,\n project: (yaw, pitch) => (flat ? projectFlat(view, size, yaw, pitch) : project(view, size, yaw, pitch)),\n unproject: (x, y) => (flat ? unprojectFlat(view, size, x, y) : unproject(view, size, x, y)),\n };\n const slider = fovSlider ? <Slider aria-label=\"Field of view\" value={Math.round(view.fov)} onChange={(fov) => change({ ...view, fov })} min={minFov} max={maxFov} step={1} unit=\"degree\" /> : null;\n\n return (\n <div className={cn(\"grid min-w-0 gap-2\", className)}>\n <div\n ref={boxRef}\n role=\"group\"\n aria-label={label}\n aria-describedby={undefined}\n tabIndex={0}\n onKeyDown={onKeyDown}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n className=\"relative w-full cursor-grab touch-none overflow-hidden rounded-surface bg-surface-sunken select-none active:cursor-grabbing\"\n style={{ aspectRatio: aspect }}\n >\n <canvas key={mode === \"flat\" ? \"2d\" : \"gl\"} ref={canvas} role=\"img\" aria-label={`${label}. ${direction}, field of view ${Math.round(view.fov)}°`} className=\"absolute inset-0 size-full\" />\n {overlay && size.width > 0 && <div className=\"pointer-events-none absolute inset-0\">{overlay(api)}</div>}\n </div>\n {flat && <p className=\"type-body-sm text-muted-foreground\">This browser cannot draw the 360 view, so the flat picture is shown. The controls work the same.</p>}\n {slider}\n <VisuallyHidden>\n <span role=\"status\">{said}</span>\n </VisuallyHidden>\n </div>\n );\n}\n"],"mappings":";;;;;;;AAcA,IAAM,SAAS;;;;AAKf,IAAM,WAAW;;;;;;;;;;;;;;;;;;;;AAoCjB,SAAgB,eAAe,QAAoD;CACjF,MAAM,KAAK,OAAO,WAAW,UAAU;EAAE,WAAW;EAAO,uBAAuB;EAAO,OAAO;CAAM,CAAC;CACvG,IAAI,CAAC,IAAI,OAAO;CAChB,MAAM,WAAW,MAAc,WAAmB;EAChD,MAAM,SAAS,GAAG,aAAa,IAAI;EACnC,GAAG,aAAa,QAAQ,MAAM;EAC9B,GAAG,cAAc,MAAM;EACvB,IAAI,CAAC,GAAG,mBAAmB,QAAQ,GAAG,cAAc,GAAG;GACrD,MAAM,MAAM,GAAG,iBAAiB,MAAM;GACtC,GAAG,aAAa,MAAM;GACtB,MAAM,IAAI,MAAM,oBAAoB,KAAK;EAC3C;EACA,OAAO;CACT;CACA,IAAI;CACJ,IAAI;EACF,UAAU,GAAG,cAAc;EAC3B,GAAG,aAAa,SAAS,QAAQ,GAAG,eAAe,MAAM,CAAC;EAC1D,GAAG,aAAa,SAAS,QAAQ,GAAG,iBAAiB,QAAQ,CAAC;EAC9D,GAAG,YAAY,OAAO;EACtB,IAAI,CAAC,GAAG,oBAAoB,SAAS,GAAG,WAAW,GAAG,MAAM,IAAI,MAAM,qBAAqB,GAAG,kBAAkB,OAAO,GAAG;CAC5H,QAAQ;EACN,OAAO;CACT;CACA,GAAG,WAAW,OAAO;CACrB,MAAM,SAAS,GAAG,aAAa;CAC/B,GAAG,WAAW,GAAG,cAAc,MAAM;CAErC,GAAG,WAAW,GAAG,cAAc,IAAI,aAAa;EAAC;EAAI;EAAI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AM,KAAK,KAAK;EACrG,YAAY,GAAG,MAAO,OAAO,cAAc,MAAM,MAAM,GAAG,CAAC,IAAI,UAAU,MAAM,MAAM,GAAG,CAAC;CAC3F;CACA,MAAM,SAAS,YAAY,oBAAC,QAAD;EAAQ,cAAW;EAAgB,OAAO,KAAK,MAAM,KAAK,GAAG;EAAG,WAAW,QAAQ,OAAO;GAAE,GAAG;GAAM;EAAI,CAAC;EAAG,KAAK;EAAQ,KAAK;EAAQ,MAAM;EAAG,MAAK;CAAU,CAAA,IAAI;CAE9L,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,sBAAsB,SAAS;EAAlD,UAAA;GACE,qBAAC,OAAD;IACE,KAAK;IACL,MAAK;IACL,cAAY;IACZ,oBAAkB,KAAA;IAClB,UAAU;IACC;IACI;IACA;IACF;IACb,iBAAiB;IACjB,WAAU;IACV,OAAO,EAAE,aAAa,OAAO;IAZ/B,UAAA,CAcE,oBAAC,UAAD;KAA4C,KAAK;KAAQ,MAAK;KAAM,cAAY,GAAG,MAAM,IAAI,UAAU,kBAAkB,KAAK,MAAM,KAAK,GAAG,EAAE;KAAI,WAAU;IAA8B,GAA7K,SAAS,SAAS,OAAO,IAAoJ,GACzL,WAAW,KAAK,QAAQ,KAAK,oBAAC,OAAD;KAAK,WAAU;KAAwC,UAAA,QAAQ,GAAG;IAAO,CAAA,CACpG;;GACJ,QAAQ,oBAAC,KAAD;IAAG,WAAU;IAAqC,UAAA;GAAmG,CAAA;GAC7J;GACD,oBAAC,gBAAD,EAAA,UACE,oBAAC,QAAD;IAAM,MAAK;IAAU,UAAA;GAAW,CAAA,EAClB,CAAA;EACb;;AAET"}
package/dist/testing.js CHANGED
@@ -1,5 +1,5 @@
1
- import { l as StrataQueryProvider, n as MicrophoneError, o as StrataToastRegion, s as toast, t as MicrophoneContext, u as createQueryClient } from "./microphone-CZy0bNEx.js";
2
- import { o as ThemeProvider } from "./theme-CFBAYaiu.js";
1
+ import { A as StrataQueryProvider, C as toast, S as StrataToastRegion, c as forgetLoadedThumbnails, j as createQueryClient, n as MicrophoneError, t as MicrophoneContext } from "./microphone-B5ITwm4G.js";
2
+ import { o as ThemeProvider } from "./theme-DXacprlw.js";
3
3
  import * as React from "react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  import { MemoryRouter, RouterProvider, createMemoryRouter } from "react-router";
@@ -470,6 +470,7 @@ function StrataProviders({ client, colorScheme, toasts, microphone, base, childr
470
470
  /** Testing Library's `render` inside `StrataQueryProvider` and a `MemoryRouter` at `route`. */
471
471
  function renderWithStrata(ui, { route = "/", client = createTestQueryClient(), colorScheme = "light", toasts = true, microphone, base, ...options } = {}) {
472
472
  toast.clear();
473
+ forgetLoadedThumbnails();
473
474
  const baseElement = installBase(base);
474
475
  const Wrapper = ({ children }) => /* @__PURE__ */ jsx(StrataProviders, {
475
476
  client,
@@ -493,6 +494,7 @@ function renderWithStrata(ui, { route = "/", client = createTestQueryClient(), c
493
494
  /** Testing Library's `render` of an app's route tree in a memory data router at `route`, with Strata's providers. */
494
495
  function renderRoutes(routes, { route, basename, client = createTestQueryClient(), colorScheme = "light", toasts = true, microphone, base, ...options } = {}) {
495
496
  toast.clear();
497
+ forgetLoadedThumbnails();
496
498
  const baseElement = installBase(base);
497
499
  const router = createMemoryRouter(routes, {
498
500
  initialEntries: [route ?? basename ?? "/"],