strata-react 1.3.24 → 1.3.25

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.
package/dist/scene.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"scene.js","names":[],"sources":["../src/scene/camera.ts","../src/scene/scene-viewport.tsx"],"sourcesContent":["// The camera maths behind `SceneViewport` (issue #370), with no GL and no React, so it is tested on its\n// own and an app can use it to place things in the same space the viewport draws.\n//\n// One camera type covers both ways of looking. **Orbit**: `target` is the point looked at and `distance`\n// the way back from it; the eye is `target - forward * distance`. **Fly**: `distance` is 0, so the eye is\n// `target` and the person moves it. Angles are degrees: `yaw` turns about the vertical axis (positive turns\n// to the right, 0 looks along +z), `pitch` looks up when positive (0 on the horizon). Y is up, as in most\n// scene formats; an app whose world is Z-up (a Quake 2 map) rotates its world, or its `render`, once.\n// Matrices are column-major `Float32Array(16)`, the order WebGL's `uniformMatrix4fv` takes.\n\n/** Where the eye is and what it looks at. */\nexport type OrbitCamera = {\n /** The point looked at (orbit) or the eye itself (fly, `distance` 0). */\n target: readonly [number, number, number];\n /** How far the eye is from `target`. 0 is a fly camera. */\n distance: number;\n /** Degrees; positive turns right. */\n yaw: number;\n /** Degrees; positive looks up. */\n pitch: number;\n};\n\n/** Everything a draw needs, from a camera and a box. */\nexport type SceneFrame = {\n camera: OrbitCamera;\n /** The eye's place. */\n eye: [number, number, number];\n /** Unit vectors: where the camera looks, its right, and its up. */\n forward: [number, number, number];\n right: [number, number, number];\n up: [number, number, number];\n /** World to eye space. */\n view: Float32Array;\n projection: Float32Array;\n /** `projection × view`: one uniform for the usual vertex shader. */\n viewProjection: Float32Array;\n /** The drawing buffer's size in device pixels; `gl.viewport` is already set to it. */\n width: number;\n height: number;\n /** Counts up each time a GL context is made (the first, and each one restored after a loss): when it changes, recreate buffers, textures and programs. */\n context: number;\n /** The scene's time in seconds when the viewport was given a `time` (a `useTimeline` clock's; issue #386), else 0: draw the scene as it is at this moment. */\n time: number;\n};\n\n/** The limits a camera is held to. */\nexport type CameraLimits = { minDistance: number; maxDistance: number; maxPitch: number };\n\nexport const DEFAULT_LIMITS: CameraLimits = { minDistance: 0, maxDistance: Infinity, maxPitch: 89 };\n\nconst rad = (d: number) => (d * Math.PI) / 180;\n\n/** Keeps a camera inside its limits and its yaw in -180 to 180. */\nexport function clampCamera(c: OrbitCamera, limits: Partial<CameraLimits> = {}): OrbitCamera {\n const { minDistance, maxDistance, maxPitch } = { ...DEFAULT_LIMITS, ...limits };\n const yaw = ((((c.yaw + 180) % 360) + 360) % 360) - 180;\n // A fly camera (distance 0 at the start) stays one: only a camera that is orbiting is held off its target.\n const distance = c.distance === 0 && minDistance === 0 ? 0 : Math.min(Math.max(c.distance, minDistance), maxDistance);\n return { target: c.target, distance, yaw, pitch: Math.min(Math.max(c.pitch, -maxPitch), maxPitch) };\n}\n\ntype Vec3 = [number, number, number];\nconst cross = (a: Vec3, b: Vec3): Vec3 => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];\nconst dot = (a: Vec3, b: Vec3) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n\n/** The unit vectors a camera looks along, and to its right and up. */\nexport function basis(c: Pick<OrbitCamera, \"yaw\" | \"pitch\">): { forward: Vec3; right: Vec3; up: Vec3 } {\n // A right-handed world (+x right of a camera that looks along -z, as WebGL's maths assumes): looking\n // along +z with +y up, the right hand is -x, so a positive yaw (a turn to the right) swings the look\n // direction toward -x.\n const y = rad(c.yaw);\n const p = rad(c.pitch);\n const forward: Vec3 = [-Math.cos(p) * Math.sin(y), Math.sin(p), Math.cos(p) * Math.cos(y)];\n const right: Vec3 = [-Math.cos(y), 0, -Math.sin(y)];\n return { forward, right, up: cross(right, forward) };\n}\n\n/** A right-handed perspective projection (OpenGL clip space, depth -1 to 1). `fov` is the vertical field of view in degrees. */\nexport function perspective(fov: number, aspect: number, near: number, far: number): Float32Array {\n const f = 1 / Math.tan(rad(fov) / 2);\n const m = new Float32Array(16);\n m[0] = f / aspect;\n m[5] = f;\n m[10] = (far + near) / (near - far);\n m[11] = -1;\n m[14] = (2 * far * near) / (near - far);\n return m;\n}\n\n/** The view matrix of an eye looking along `forward`. */\nexport function lookAlong(eye: Vec3, forward: Vec3, right: Vec3, up: Vec3): Float32Array {\n const m = new Float32Array(16);\n m[0] = right[0]; m[4] = right[1]; m[8] = right[2]; m[12] = -dot(right, eye);\n m[1] = up[0]; m[5] = up[1]; m[9] = up[2]; m[13] = -dot(up, eye);\n m[2] = -forward[0]; m[6] = -forward[1]; m[10] = -forward[2]; m[14] = dot(forward, eye);\n m[15] = 1;\n return m;\n}\n\n/** `a × b` for column-major matrices. */\nexport function multiply(a: Float32Array, b: Float32Array): Float32Array {\n const out = new Float32Array(16);\n for (let col = 0; col < 4; col++)\n for (let row = 0; row < 4; row++) {\n let sum = 0;\n for (let k = 0; k < 4; k++) sum += a[k * 4 + row]! * b[col * 4 + k]!;\n out[col * 4 + row] = sum;\n }\n return out;\n}\n\n/** The frame for a camera in a drawing buffer of `width` by `height`. */\nexport function frameFor(camera: OrbitCamera, width: number, height: number, { fov = 60, near = 0.1, far = 10_000, context = 0, time = 0 }: { fov?: number; near?: number; far?: number; context?: number; time?: number } = {}): SceneFrame {\n const { forward, right, up } = basis(camera);\n const eye: Vec3 = [camera.target[0] - forward[0] * camera.distance, camera.target[1] - forward[1] * camera.distance, camera.target[2] - forward[2] * camera.distance];\n const view = lookAlong(eye, forward, right, up);\n const projection = perspective(fov, width / Math.max(1, height), near, far);\n return { camera, eye, forward, right, up, view, projection, viewProjection: multiply(projection, view), width, height, context, time };\n}\n\n/** Turns the camera as dragging does: orbit moves the eye round the target; look (fly) turns the head. Pixels in, degrees out at `degreesPerPixel`. */\nexport function turn(c: OrbitCamera, dx: number, dy: number, mode: \"orbit\" | \"fly\", degreesPerPixel = 0.35): OrbitCamera {\n // Orbit: the model follows the pointer, so the eye goes the other way. Fly: the picture follows the pointer.\n const sign = mode === \"orbit\" ? 1 : -1;\n return { ...c, yaw: c.yaw + sign * dx * degreesPerPixel, pitch: c.pitch - sign * dy * degreesPerPixel };\n}\n\n/** Moves the target in the screen's plane by pixels (a pan): the scene follows the pointer. `heightPx` is the box's height and `fov` the vertical field of view, which give the world size of a pixel at the target's distance. */\nexport function pan(c: OrbitCamera, dx: number, dy: number, heightPx: number, fov = 60): OrbitCamera {\n const { right, up } = basis(c);\n const perPixel = (2 * Math.max(c.distance, 0.001) * Math.tan(rad(fov) / 2)) / Math.max(1, heightPx);\n const move = (axis: number) => c.target[axis]! - right[axis]! * dx * perPixel + up[axis]! * dy * perPixel;\n return { ...c, target: [move(0), move(1), move(2)] };\n}\n\n/** Moves along the look direction (`ahead`), to the right (`side`) and up (`rise`), in world units: a fly camera's walk, or an orbit camera's pan by keys. */\nexport function walk(c: OrbitCamera, ahead: number, side: number, rise: number): OrbitCamera {\n const { forward, right } = basis(c);\n const to = (axis: number) => c.target[axis]! + forward[axis]! * ahead + right[axis]! * side + (axis === 1 ? rise : 0);\n return { ...c, target: [to(0), to(1), to(2)] };\n}\n\n/** Moves the eye toward or away from the target by a factor of the distance (orbit zoom). */\nexport function dolly(c: OrbitCamera, factor: number): OrbitCamera {\n return { ...c, distance: c.distance * factor };\n}\n\nconst turnWords = (deg: number, positive: string, negative: string) => (Math.abs(deg) < 1 ? \"\" : `${Math.round(Math.abs(deg))}° ${deg > 0 ? positive : negative}`);\n\n/** The camera in words, for the viewport's name and its status: \"Looking at 0, 2, 0 from 5 away, turned 45° right, 30° above the horizon\". */\nexport function describeCamera(c: OrbitCamera): string {\n const n = (v: number) => String(Math.round(v * 10) / 10);\n const turned = turnWords(c.yaw, \"right\", \"left\");\n const tilted = turnWords(c.pitch, \"up\", \"down\");\n const at = `${n(c.target[0])}, ${n(c.target[1])}, ${n(c.target[2])}`;\n const parts = [turned && `turned ${turned}`, tilted && `looking ${tilted}`].filter(Boolean).join(\", \");\n return c.distance === 0 ? `At ${at}${parts ? `, ${parts}` : \", looking straight ahead\"}` : `Looking at ${at} from ${n(c.distance)} away${parts ? `, ${parts}` : \"\"}`;\n}\n","import * as React from \"react\";\nimport { RotateCcw } from \"lucide-react\";\nimport { VisuallyHidden } from \"react-aria\";\nimport { Button } from \"../components/button\";\nimport { useInView } from \"../lib/in-view\";\nimport { cn } from \"../lib/utils\";\nimport { clampCamera, describeCamera, dolly, frameFor, pan, turn, walk, type CameraLimits, type OrbitCamera, type SceneFrame } from \"./camera\";\n\n// A frame for a 3D scene the app draws itself, that a person orbits, pans and zooms (issue #370, from the\n// Quake 2 explorer, which drew maps and models with its own camera code and controls). `PanoramaViewer`\n// is a WebGL view you look around from *inside*; this is the other kind: the app owns the drawing, Strata\n// owns the frame and the input, and everything Strata owns is what each app otherwise rewrites: pointer\n// capture, wheel zoom, keyboard control, a reset, a resize observer, a lost context, and what a screen\n// reader hears. Its own entry (`strata-react/scene`), like `strata-react/panorama`, so an app without 3D\n// ships none of it. No dependency: the camera maths is in `camera.ts`, and the context is the browser's.\n//\n// - **The app draws.** `render(gl, frame)` is called when the camera, the size or `invalidate()` changes\n// something, never on a timer (unless `continuous`, for a scene that moves by itself). `frame` has the\n// matrices and the eye, and the viewport is already set. A context made again after a loss bumps\n// `frame.context`, so the app knows to recreate what lived on the old one.\n// - **The camera is the app's to hold** (`useOrbitCamera`, or `camera` and `onCameraChange` of its own),\n// so a link, a saved view or a \"focus on this\" button just sets it, and the viewport never animates a\n// change it did not make. The one move it animates is Reset (300 ms ease), and not at all under reduced\n// motion.\n// - **Input.** Orbit by drag; pan by right drag, middle drag or Shift+drag; zoom by Ctrl or Cmd with the\n// wheel (which is also what a trackpad pinch sends) and by a two-finger pinch. A plain wheel scrolls the\n// page, as `ViewportFrame` does, since a 3D view in the middle of a page must not trap it. Keyboard, with\n// the frame focused: arrows orbit (Shift pans), `+` and `-` zoom, `0` resets. Touch is one finger to\n// orbit, two to pinch.\n// - **Fly mode** (`mode=\"fly\"`, for a map walkthrough): the same camera with `distance` 0, so it is the eye.\n// Drag looks (the picture follows the pointer), W A S D and the arrows walk and strafe, Q and E go down and\n// up, Shift is faster; keys held move on every frame, and under reduced motion each press is one step.\n// - **Said in words.** The canvas is an `img` named by `label` and the camera (\"Looking at 0, 2, 0 from 5\n// away, turned 45° right\"), always current, and a polite status says it once the camera has been still a\n// moment, never per frame. A Reset button is always there: a keyboard or touch person has no `0` key\n// to find, and a lost camera needs one visible way home.\n// - **No WebGL, no blank box**: a line says so, and the controls are not drawn.\n// React Aria first: there is no 3D part, so the frame is ours; the Reset button is Strata's `Button`\n// (React Aria's), and the camera maths is plain functions with tests.\n\n/** What a `SceneViewport` hands the app to hold: the camera, and ways to move it that obey the limits. */\nexport type OrbitCameraState = {\n camera: OrbitCamera;\n setCamera: (next: OrbitCamera) => void;\n /** Back to the camera the hook started with (the viewport's Reset button does this, animated). */\n home: OrbitCamera;\n};\n\n/** A camera the app holds: `{ target, distance, yaw, pitch }` to start from, and the limits it is kept inside. Give `camera` and `setCamera` to `SceneViewport`. */\nexport function useOrbitCamera(initial: Partial<OrbitCamera> = {}, limits: Partial<CameraLimits> = {}): OrbitCameraState {\n const home = React.useMemo<OrbitCamera>(\n () => clampCamera({ target: initial.target ?? [0, 0, 0], distance: initial.distance ?? 5, yaw: initial.yaw ?? 0, pitch: initial.pitch ?? 20 }, limits),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n const [camera, set] = React.useState<OrbitCamera>(home);\n const bounds = React.useRef(limits);\n bounds.current = limits;\n const setCamera = React.useCallback((next: OrbitCamera) => set(clampCamera(next, bounds.current)), []);\n return { camera, setCamera, home };\n}\n\nexport type SceneViewportProps = {\n /** Names the view: \"Map e1m1\". The camera in words is added to it. Required. */\n label: string;\n /** The camera, from `useOrbitCamera`. */\n camera: OrbitCamera;\n onCameraChange: (camera: OrbitCamera) => void;\n /** Where Reset goes. Default: the camera the viewport first had. */\n home?: OrbitCamera;\n /** Draws the scene. Called when the camera or size changed, or after `invalidate()`; the viewport is set. */\n render: (gl: WebGL2RenderingContext, frame: SceneFrame) => void;\n /** `\"orbit\"` (default) circles a target; `\"fly\"` is the eye itself, for a walkthrough. */\n mode?: \"orbit\" | \"fly\";\n /** The vertical field of view in degrees. Default 60. */\n fov?: number;\n near?: number;\n far?: number;\n /** Closest and furthest an orbit camera may be, and the highest and lowest look in degrees. Defaults 0, none, 89. */\n limits?: Partial<CameraLimits>;\n /** World units a second of fly walking covers. Default 5. */\n flySpeed?: number;\n /** The scene's time in seconds, from a `useTimeline` clock (issue #386): the scene is drawn again when it changes, with `frame.time` set, so a recorded run or a replay scrubs and plays like a video under `TimelinePlayer`. Default: no time. */\n time?: number;\n /** Redraw every frame while on screen, for a scene that moves by itself. Default false: draw on change. */\n continuous?: boolean;\n /** The shape of the box. Default 16/9. */\n aspect?: number | `${number}/${number}`;\n /** A handle for `invalidate()` (a texture finished loading) and the canvas. */\n handle?: React.Ref<SceneViewportHandle>;\n className?: string;\n};\n\n/** What `handle` gives: ask for a redraw, and the canvas. */\nexport type SceneViewportHandle = { invalidate: () => void; canvas: HTMLCanvasElement | null };\n\nconst STILL_MS = 600;\nconst RESET_MS = 300;\nconst reducedMotion = () => typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n/** A sized, focusable canvas for a 3D scene the app draws: orbit by drag, pan by right drag or Shift, zoom by Ctrl/Cmd+wheel or pinch, keys, a Reset button, a fly mode, a lost context restored, and the camera in words. */\nexport function SceneViewport({ label, camera, onCameraChange, home, render, mode = \"orbit\", fov = 60, near = 0.1, far = 10_000, limits, flySpeed = 5, time = 0, continuous = false, aspect = \"16/9\", handle, className }: SceneViewportProps) {\n const first = React.useRef(camera);\n const target = home ?? first.current;\n const live = React.useRef({ camera, onCameraChange, render, mode, fov, near, far, limits, flySpeed, home: target, time });\n live.current = { camera, onCameraChange, render, mode, fov, near, far, limits, flySpeed, home: target, time };\n const change = React.useCallback((next: OrbitCamera) => {\n live.current.onCameraChange(clampCamera(next, live.current.limits));\n }, []);\n\n const box = React.useRef<HTMLDivElement>(null);\n const canvas = React.useRef<HTMLCanvasElement>(null);\n const [size, setSize] = React.useState({ 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 // Drawing: only when something changed, and only while on screen.\n const { ref: visibleRef, inView } = useInView({ unsupported: true });\n const boxRef = React.useCallback(\n (el: HTMLDivElement | null) => {\n box.current = el;\n visibleRef(el);\n },\n [visibleRef],\n );\n const gl = React.useRef<WebGL2RenderingContext | null>(null);\n const context = React.useRef(0);\n const [unavailable, setUnavailable] = React.useState(false);\n const frameHandle = React.useRef(0);\n const current = React.useRef({ size, inView, continuous });\n current.current = { size, inView, continuous };\n\n const paint = React.useCallback(() => {\n frameHandle.current = 0;\n const c = canvas.current;\n const ctx = gl.current;\n const { size: s, inView: visible, continuous: again } = current.current;\n if (!c || !ctx || !visible || s.width === 0 || s.height === 0) return;\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 (c.width !== w || c.height !== h) {\n c.width = w;\n c.height = h;\n }\n ctx.viewport(0, 0, w, h);\n const l = live.current;\n l.render(ctx, frameFor(l.camera, w, h, { fov: l.fov, near: l.near, far: l.far, context: context.current, time: l.time }));\n if (again) frameHandle.current = requestAnimationFrame(paint);\n }, []);\n const schedule = React.useCallback(() => {\n if (frameHandle.current === 0) frameHandle.current = requestAnimationFrame(paint);\n }, [paint]);\n React.useImperativeHandle(handle, () => ({ invalidate: schedule, canvas: canvas.current }), [schedule]);\n\n // The context: made once, made again when restored after a loss (the app sees `frame.context` change).\n React.useEffect(() => {\n const c = canvas.current;\n if (!c) return;\n const make = () => {\n gl.current = c.getContext(\"webgl2\") as WebGL2RenderingContext | null;\n setUnavailable(gl.current === null);\n if (gl.current) context.current += 1;\n schedule();\n };\n make();\n const lost = (e: Event) => {\n e.preventDefault();\n gl.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 if (frameHandle.current) cancelAnimationFrame(frameHandle.current);\n frameHandle.current = 0;\n };\n }, [schedule]);\n React.useEffect(() => {\n schedule();\n }, [schedule, camera, size.width, size.height, inView, fov, near, far, continuous, time]);\n\n // Reset: animated unless the person asked for less motion.\n const animation = React.useRef(0);\n const reset = () => {\n cancelAnimationFrame(animation.current);\n const from = live.current.camera;\n const to = live.current.home;\n if (reducedMotion()) return change(to);\n const started = performance.now();\n const step = (now: number) => {\n const t = Math.min(1, (now - started) / RESET_MS);\n const e = 1 - (1 - t) ** 3;\n const mix = (a: number, b: number) => a + (b - a) * e;\n // The short way round in yaw.\n const dyaw = ((((to.yaw - from.yaw + 180) % 360) + 360) % 360) - 180;\n change({\n target: [mix(from.target[0], to.target[0]), mix(from.target[1], to.target[1]), mix(from.target[2], to.target[2])],\n distance: mix(from.distance, to.distance),\n yaw: from.yaw + dyaw * e,\n pitch: mix(from.pitch, to.pitch),\n });\n if (t < 1) animation.current = requestAnimationFrame(step);\n };\n animation.current = requestAnimationFrame(step);\n };\n React.useEffect(() => () => cancelAnimationFrame(animation.current), []);\n\n // Pointer: drag orbits (or looks), a right drag or Shift pans, two pointers pinch.\n const pointers = React.useRef(new Map<number, { x: number; y: number }>());\n const pinch = React.useRef<number | null>(null);\n const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n if (e.target instanceof HTMLButtonElement) return;\n pointers.current.set(e.pointerId, { x: e.clientX, y: e.clientY });\n e.currentTarget.setPointerCapture?.(e.pointerId);\n e.currentTarget.focus({ preventScroll: true });\n cancelAnimationFrame(animation.current);\n if (pointers.current.size === 2) {\n const [a, b] = [...pointers.current.values()];\n pinch.current = Math.hypot(a!.x - b!.x, a!.y - b!.y);\n }\n };\n const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n const last = pointers.current.get(e.pointerId);\n if (!last) return;\n const now = { x: e.clientX, y: e.clientY };\n pointers.current.set(e.pointerId, now);\n const l = live.current;\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 (pinch.current && d > 0 && l.mode === \"orbit\") change(dolly(l.camera, pinch.current / d));\n pinch.current = d;\n return;\n }\n const dx = now.x - last.x;\n const dy = now.y - last.y;\n const panning = e.shiftKey || (e.buttons & 6) !== 0; // Shift, or the right or middle button\n change(panning ? pan(l.camera, dx, dy, size.height, l.fov) : turn(l.camera, dx, dy, l.mode));\n };\n const onPointerUp = (e: React.PointerEvent<HTMLDivElement>) => {\n pointers.current.delete(e.pointerId);\n pinch.current = null;\n };\n\n // The wheel zooms only with Ctrl or Cmd (a trackpad pinch sends Ctrl); a plain wheel scrolls the page.\n // Native, because React's wheel listener is passive and the page's own zoom must be refused.\n React.useEffect(() => {\n const el = box.current;\n if (!el) return;\n const onWheel = (e: WheelEvent) => {\n if (!e.ctrlKey && !e.metaKey) return;\n e.preventDefault();\n const l = live.current;\n if (l.mode === \"orbit\") change(dolly(l.camera, Math.exp(e.deltaY * 0.0015)));\n else change(walk(l.camera, -e.deltaY * 0.01 * l.flySpeed, 0, 0));\n };\n el.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => el.removeEventListener(\"wheel\", onWheel);\n }, [change]);\n\n // Keys. Orbit: arrows turn (Shift pans), + and - zoom, 0 resets. Fly: W A S D and arrows walk, Q and E go\n // down and up, held keys move every frame (one step each press under reduced motion).\n const held = React.useRef(new Set<string>());\n const flyLoop = React.useRef(0);\n const flyKeys = [\"w\", \"a\", \"s\", \"d\", \"q\", \"e\", \"ArrowUp\", \"ArrowDown\", \"ArrowLeft\", \"ArrowRight\"];\n const walkFrom = (keys: Iterable<string>, seconds: number, fast: boolean) => {\n const l = live.current;\n const k = new Set(keys);\n const stride = l.flySpeed * seconds * (fast ? 3 : 1);\n const axis = (plus: string[], minus: string[]) => (plus.some((x) => k.has(x)) ? 1 : 0) - (minus.some((x) => k.has(x)) ? 1 : 0);\n change(walk(l.camera, axis([\"w\", \"ArrowUp\"], [\"s\", \"ArrowDown\"]) * stride, axis([\"d\", \"ArrowRight\"], [\"a\", \"ArrowLeft\"]) * stride, axis([\"e\"], [\"q\"]) * stride));\n };\n const startFly = (shift: boolean) => {\n if (flyLoop.current) return;\n let last = performance.now();\n const tick = (now: number) => {\n walkFrom(held.current, (now - last) / 1000, shift);\n last = now;\n flyLoop.current = held.current.size ? requestAnimationFrame(tick) : 0;\n };\n flyLoop.current = requestAnimationFrame(tick);\n };\n React.useEffect(() => () => cancelAnimationFrame(flyLoop.current), []);\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.ctrlKey || e.metaKey || e.altKey) return;\n const l = live.current;\n const key = e.key.length === 1 ? e.key.toLowerCase() : e.key;\n if (key === \"0\") reset();\n else if (l.mode === \"fly\" && flyKeys.includes(key)) {\n if (reducedMotion()) walkFrom([key], 0.2, e.shiftKey);\n else {\n held.current.add(key);\n startFly(e.shiftKey);\n }\n } else if (key === \"+\" || key === \"=\") change(l.mode === \"orbit\" ? dolly(l.camera, 0.8) : walk(l.camera, l.flySpeed * 0.5, 0, 0));\n else if (key === \"-\" || key === \"_\") change(l.mode === \"orbit\" ? dolly(l.camera, 1.25) : walk(l.camera, -l.flySpeed * 0.5, 0, 0));\n else if (l.mode === \"orbit\" && key.startsWith(\"Arrow\")) {\n const step = e.shiftKey ? 30 : 10; // pixels' worth, so keys and the pointer agree\n const dx = key === \"ArrowRight\" ? step : key === \"ArrowLeft\" ? -step : 0;\n const dy = key === \"ArrowDown\" ? step : key === \"ArrowUp\" ? -step : 0;\n change(e.shiftKey ? pan(l.camera, -dx, -dy, size.height, l.fov) : turn(l.camera, dx, dy, \"orbit\"));\n } else return;\n e.preventDefault();\n };\n const onKeyUp = (e: React.KeyboardEvent) => {\n held.current.delete(e.key.length === 1 ? e.key.toLowerCase() : e.key);\n };\n\n // Said in words, politely once the camera has been still for a moment.\n const words = describeCamera(camera);\n const [said, setSaid] = React.useState(\"\");\n const firstWords = React.useRef(true);\n React.useEffect(() => {\n if (firstWords.current) {\n firstWords.current = false;\n return;\n }\n const t = setTimeout(() => setSaid(words), STILL_MS);\n return () => clearTimeout(t);\n }, [words]);\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 tabIndex={0}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n onBlur={() => held.current.clear()}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n onContextMenu={(e) => e.preventDefault()}\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 ref={canvas} role=\"img\" aria-label={`${label}. ${words}`} className=\"absolute inset-0 size-full\" />\n {!unavailable && (\n <Button size=\"sm\" variant=\"outline\" onPress={reset} className=\"absolute top-2 right-2\">\n <RotateCcw /> Reset view\n </Button>\n )}\n </div>\n {unavailable && <p className=\"type-body-sm text-muted-foreground\">This browser cannot draw the 3D view.</p>}\n <VisuallyHidden>\n <span role=\"status\">{said}</span>\n </VisuallyHidden>\n </div>\n );\n}\n"],"mappings":";;;;;;;AAgDA,IAAa,iBAA+B;CAAE,aAAa;CAAG,aAAa;CAAU,UAAU;AAAG;AAElG,IAAM,OAAO,MAAe,IAAI,KAAK,KAAM;;AAG3C,SAAgB,YAAY,GAAgB,SAAgC,CAAC,GAAgB;CAC3F,MAA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MAAM,SAAS,EAAE;CACzC,MAAM,aAAa,MAAM,OAAO,IAAI;CACpC,MAAM,gBAAgB;EACpB,IAAI,WAAW,SAAS;GACtB,WAAW,UAAU;GACrB;EACF;EACA,MAAM,IAAI,iBAAiB,QAAQ,KAAK,GAAG,QAAQ;EACnD,aAAa,aAAa,CAAC;CAC7B,GAAG,CAAC,KAAK,CAAC;CAEV,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,sBAAsB,SAAS;EAAlD,UAAA;GACE,qBAAC,OAAD;IACE,KAAK;IACL,MAAK;IACL,cAAY;IACZ,UAAU;IACC;IACF;IACT,cAAc,KAAK,QAAQ,MAAM;IAClB;IACA;IACF;IACb,iBAAiB;IACjB,gBAAgB,MAAM,EAAE,eAAe;IACvC,WAAU;IACV,OAAO,EAAE,aAAa,OAAO;IAd/B,UAAA,CAgBE,oBAAC,UAAD;KAAQ,KAAK;KAAQ,MAAK;KAAM,cAAY,GAAG,MAAM,IAAI;KAAS,WAAU;IAA8B,CAAA,GACzG,CAAC,eACA,qBAAC,QAAD;KAAQ,MAAK;KAAK,SAAQ;KAAU,SAAS;KAAO,WAAU;KAA9D,UAAA,CACE,oBAAC,WAAD,CAAY,CAAA,GAAC,aACP;IAEP,CAAA,CAAA;;GACJ,eAAe,oBAAC,KAAD;IAAG,WAAU;IAAqC,UAAA;GAAwC,CAAA;GAC1G,oBAAC,gBAAD,EAAA,UACE,oBAAC,QAAD;IAAM,MAAK;IAAU,UAAA;GAAW,CAAA,EAClB,CAAA;EACb;;AAET"}
1
+ {"version":3,"file":"scene.js","names":[],"sources":["../src/scene/camera.ts","../src/scene/scene-viewport.tsx"],"sourcesContent":["// The camera maths behind `SceneViewport` (issue #370), with no GL and no React, so it is tested on its\n// own and an app can use it to place things in the same space the viewport draws.\n//\n// One camera type covers both ways of looking. **Orbit**: `target` is the point looked at and `distance`\n// the way back from it; the eye is `target - forward * distance`. **Fly**: `distance` is 0, so the eye is\n// `target` and the person moves it. Angles are degrees: `yaw` turns about the vertical axis (positive turns\n// to the right, 0 looks along +z), `pitch` looks up when positive (0 on the horizon). Y is up, as in most\n// scene formats; an app whose world is Z-up (a Quake 2 map) rotates its world, or its `render`, once.\n// Matrices are column-major `Float32Array(16)`, the order WebGL's `uniformMatrix4fv` takes.\n\nimport { followAim } from \"../lib/follow\";\n\n/** Where the eye is and what it looks at. */\nexport type OrbitCamera = {\n /** The point looked at (orbit) or the eye itself (fly, `distance` 0). */\n target: readonly [number, number, number];\n /** How far the eye is from `target`. 0 is a fly camera. */\n distance: number;\n /** Degrees; positive turns right. */\n yaw: number;\n /** Degrees; positive looks up. */\n pitch: number;\n};\n\n/** Everything a draw needs, from a camera and a box. */\nexport type SceneFrame = {\n camera: OrbitCamera;\n /** The eye's place. */\n eye: [number, number, number];\n /** Unit vectors: where the camera looks, its right, and its up. */\n forward: [number, number, number];\n right: [number, number, number];\n up: [number, number, number];\n /** World to eye space. */\n view: Float32Array;\n projection: Float32Array;\n /** `projection × view`: one uniform for the usual vertex shader. */\n viewProjection: Float32Array;\n /** The drawing buffer's size in device pixels; `gl.viewport` is already set to it. */\n width: number;\n height: number;\n /** Counts up each time a GL context is made (the first, and each one restored after a loss): when it changes, recreate buffers, textures and programs. */\n context: number;\n /** The scene's time in seconds when the viewport was given a `time` (a `useTimeline` clock's; issue #386), else 0: draw the scene as it is at this moment. */\n time: number;\n};\n\n/** The limits a camera is held to. */\nexport type CameraLimits = { minDistance: number; maxDistance: number; maxPitch: number };\n\nexport const DEFAULT_LIMITS: CameraLimits = { minDistance: 0, maxDistance: Infinity, maxPitch: 89 };\n\nconst rad = (d: number) => (d * Math.PI) / 180;\n\n/** Keeps a camera inside its limits and its yaw in -180 to 180. */\nexport function clampCamera(c: OrbitCamera, limits: Partial<CameraLimits> = {}): OrbitCamera {\n const { minDistance, maxDistance, maxPitch } = { ...DEFAULT_LIMITS, ...limits };\n const yaw = ((((c.yaw + 180) % 360) + 360) % 360) - 180;\n // A fly camera (distance 0 at the start) stays one: only a camera that is orbiting is held off its target.\n const distance = c.distance === 0 && minDistance === 0 ? 0 : Math.min(Math.max(c.distance, minDistance), maxDistance);\n return { target: c.target, distance, yaw, pitch: Math.min(Math.max(c.pitch, -maxPitch), maxPitch) };\n}\n\ntype Vec3 = [number, number, number];\nconst cross = (a: Vec3, b: Vec3): Vec3 => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];\nconst dot = (a: Vec3, b: Vec3) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n\n/** The unit vectors a camera looks along, and to its right and up. */\nexport function basis(c: Pick<OrbitCamera, \"yaw\" | \"pitch\">): { forward: Vec3; right: Vec3; up: Vec3 } {\n // A right-handed world (+x right of a camera that looks along -z, as WebGL's maths assumes): looking\n // along +z with +y up, the right hand is -x, so a positive yaw (a turn to the right) swings the look\n // direction toward -x.\n const y = rad(c.yaw);\n const p = rad(c.pitch);\n const forward: Vec3 = [-Math.cos(p) * Math.sin(y), Math.sin(p), Math.cos(p) * Math.cos(y)];\n const right: Vec3 = [-Math.cos(y), 0, -Math.sin(y)];\n return { forward, right, up: cross(right, forward) };\n}\n\n/** A right-handed perspective projection (OpenGL clip space, depth -1 to 1). `fov` is the vertical field of view in degrees. */\nexport function perspective(fov: number, aspect: number, near: number, far: number): Float32Array {\n const f = 1 / Math.tan(rad(fov) / 2);\n const m = new Float32Array(16);\n m[0] = f / aspect;\n m[5] = f;\n m[10] = (far + near) / (near - far);\n m[11] = -1;\n m[14] = (2 * far * near) / (near - far);\n return m;\n}\n\n/** The view matrix of an eye looking along `forward`. */\nexport function lookAlong(eye: Vec3, forward: Vec3, right: Vec3, up: Vec3): Float32Array {\n const m = new Float32Array(16);\n m[0] = right[0]; m[4] = right[1]; m[8] = right[2]; m[12] = -dot(right, eye);\n m[1] = up[0]; m[5] = up[1]; m[9] = up[2]; m[13] = -dot(up, eye);\n m[2] = -forward[0]; m[6] = -forward[1]; m[10] = -forward[2]; m[14] = dot(forward, eye);\n m[15] = 1;\n return m;\n}\n\n/** `a × b` for column-major matrices. */\nexport function multiply(a: Float32Array, b: Float32Array): Float32Array {\n const out = new Float32Array(16);\n for (let col = 0; col < 4; col++)\n for (let row = 0; row < 4; row++) {\n let sum = 0;\n for (let k = 0; k < 4; k++) sum += a[k * 4 + row]! * b[col * 4 + k]!;\n out[col * 4 + row] = sum;\n }\n return out;\n}\n\n/** The frame for a camera in a drawing buffer of `width` by `height`. */\nexport function frameFor(camera: OrbitCamera, width: number, height: number, { fov = 60, near = 0.1, far = 10_000, context = 0, time = 0 }: { fov?: number; near?: number; far?: number; context?: number; time?: number } = {}): SceneFrame {\n const { forward, right, up } = basis(camera);\n const eye: Vec3 = [camera.target[0] - forward[0] * camera.distance, camera.target[1] - forward[1] * camera.distance, camera.target[2] - forward[2] * camera.distance];\n const view = lookAlong(eye, forward, right, up);\n const projection = perspective(fov, width / Math.max(1, height), near, far);\n return { camera, eye, forward, right, up, view, projection, viewProjection: multiply(projection, view), width, height, context, time };\n}\n\n/** Turns the camera as dragging does: orbit moves the eye round the target; look (fly) turns the head. Pixels in, degrees out at `degreesPerPixel`. */\nexport function turn(c: OrbitCamera, dx: number, dy: number, mode: \"orbit\" | \"fly\", degreesPerPixel = 0.35): OrbitCamera {\n // Orbit: the model follows the pointer, so the eye goes the other way. Fly: the picture follows the pointer.\n const sign = mode === \"orbit\" ? 1 : -1;\n return { ...c, yaw: c.yaw + sign * dx * degreesPerPixel, pitch: c.pitch - sign * dy * degreesPerPixel };\n}\n\n/** Moves the target in the screen's plane by pixels (a pan): the scene follows the pointer. `heightPx` is the box's height and `fov` the vertical field of view, which give the world size of a pixel at the target's distance. */\nexport function pan(c: OrbitCamera, dx: number, dy: number, heightPx: number, fov = 60): OrbitCamera {\n const { right, up } = basis(c);\n const perPixel = (2 * Math.max(c.distance, 0.001) * Math.tan(rad(fov) / 2)) / Math.max(1, heightPx);\n const move = (axis: number) => c.target[axis]! - right[axis]! * dx * perPixel + up[axis]! * dy * perPixel;\n return { ...c, target: [move(0), move(1), move(2)] };\n}\n\n/** Moves along the look direction (`ahead`), to the right (`side`) and up (`rise`), in world units: a fly camera's walk, or an orbit camera's pan by keys. */\nexport function walk(c: OrbitCamera, ahead: number, side: number, rise: number): OrbitCamera {\n const { forward, right } = basis(c);\n const to = (axis: number) => c.target[axis]! + forward[axis]! * ahead + right[axis]! * side + (axis === 1 ? rise : 0);\n return { ...c, target: [to(0), to(1), to(2)] };\n}\n\n/** Moves the eye toward or away from the target by a factor of the distance (orbit zoom). */\nexport function dolly(c: OrbitCamera, factor: number): OrbitCamera {\n return { ...c, distance: c.distance * factor };\n}\n\nconst turnWords = (deg: number, positive: string, negative: string) => (Math.abs(deg) < 1 ? \"\" : `${Math.round(Math.abs(deg))}° ${deg > 0 ? positive : negative}`);\n\n/** The camera in words, for the viewport's name and its status: \"Looking at 0, 2, 0 from 5 away, turned 45° right, 30° above the horizon\". */\nexport function describeCamera(c: OrbitCamera): string {\n const n = (v: number) => String(Math.round(v * 10) / 10);\n const turned = turnWords(c.yaw, \"right\", \"left\");\n const tilted = turnWords(c.pitch, \"up\", \"down\");\n const at = `${n(c.target[0])}, ${n(c.target[1])}, ${n(c.target[2])}`;\n const parts = [turned && `turned ${turned}`, tilted && `looking ${tilted}`].filter(Boolean).join(\", \");\n return c.distance === 0 ? `At ${at}${parts ? `, ${parts}` : \", looking straight ahead\"}` : `Looking at ${at} from ${n(c.distance)} away${parts ? `, ${parts}` : \"\"}`;\n}\n\n/** A view from inside a sphere as `PanoramaViewer` holds it: the same degrees, positive yaw to the right and positive pitch up. */\nexport type LookView = { yaw: number; pitch: number; fov: number };\n\n/** The fly camera that sees what a `PanoramaViewer` view sees from `eye`: one view model for looking from a point, in a picture or a scene (issue #386). */\nexport function cameraFromView(view: Pick<LookView, \"yaw\" | \"pitch\">, eye: readonly [number, number, number] = [0, 0, 0]): OrbitCamera {\n return { target: eye, distance: 0, yaw: view.yaw, pitch: view.pitch };\n}\n\n/** The panorama view a camera looks along from its eye (an orbit camera looks along its `forward` just the same), with the field of view given. */\nexport function viewFromCamera(camera: Pick<OrbitCamera, \"yaw\" | \"pitch\">, fov: number): LookView {\n return { yaw: camera.yaw, pitch: camera.pitch, fov };\n}\n\n/**\n * A camera that follows a moving point (issue #386, \"through the player's eyes\" in a replay): the eye is at `eye` and looks along the\n * heading the app supplies, plus the person's own `look` on top. With `behind` it is a chase camera instead, that far back along the look.\n */\nexport function followCamera({ eye, heading, pitch = 0, look, behind = 0, maxPitch = 89 }: { eye: readonly [number, number, number]; heading: number; pitch?: number; look?: { yaw?: number; pitch?: number }; behind?: number; maxPitch?: number }): OrbitCamera {\n return { target: eye, distance: Math.max(0, behind), ...followAim({ heading, pitch, look, maxPitch }) };\n}\n","import * as React from \"react\";\nimport { RotateCcw } from \"lucide-react\";\nimport { VisuallyHidden } from \"react-aria\";\nimport { Button } from \"../components/button\";\nimport { useInView } from \"../lib/in-view\";\nimport { useSettledStatus, useViewPointers, useWheelZoom } from \"../lib/viewer-input\";\nimport { cn } from \"../lib/utils\";\nimport { clampCamera, describeCamera, dolly, frameFor, pan, turn, walk, type CameraLimits, type OrbitCamera, type SceneFrame } from \"./camera\";\n\n// A frame for a 3D scene the app draws itself, that a person orbits, pans and zooms (issue #370, from the\n// Quake 2 explorer, which drew maps and models with its own camera code and controls). `PanoramaViewer`\n// is a WebGL view you look around from *inside*; this is the other kind: the app owns the drawing, Strata\n// owns the frame and the input, and everything Strata owns is what each app otherwise rewrites: pointer\n// capture, wheel zoom, keyboard control, a reset, a resize observer, a lost context, and what a screen\n// reader hears. Its own entry (`strata-react/scene`), like `strata-react/panorama`, so an app without 3D\n// ships none of it. No dependency: the camera maths is in `camera.ts`, and the context is the browser's.\n//\n// - **The app draws.** `render(gl, frame)` is called when the camera, the size or `invalidate()` changes\n// something, never on a timer (unless `continuous`, for a scene that moves by itself). `frame` has the\n// matrices and the eye, and the viewport is already set. A context made again after a loss bumps\n// `frame.context`, so the app knows to recreate what lived on the old one.\n// - **The camera is the app's to hold** (`useOrbitCamera`, or `camera` and `onCameraChange` of its own),\n// so a link, a saved view or a \"focus on this\" button just sets it, and the viewport never animates a\n// change it did not make. The one move it animates is Reset (300 ms ease), and not at all under reduced\n// motion.\n// - **Input.** Orbit by drag; pan by right drag, middle drag or Shift+drag; zoom by Ctrl or Cmd with the\n// wheel (which is also what a trackpad pinch sends) and by a two-finger pinch. A plain wheel scrolls the\n// page, as `ViewportFrame` does, since a 3D view in the middle of a page must not trap it. Keyboard, with\n// the frame focused: arrows orbit (Shift pans), `+` and `-` zoom, `0` resets. Touch is one finger to\n// orbit, two to pinch.\n// - **Fly mode** (`mode=\"fly\"`, for a map walkthrough): the same camera with `distance` 0, so it is the eye.\n// Drag looks (the picture follows the pointer), W A S D and the arrows walk and strafe, Q and E go down and\n// up, Shift is faster; keys held move on every frame, and under reduced motion each press is one step.\n// - **Said in words.** The canvas is an `img` named by `label` and the camera (\"Looking at 0, 2, 0 from 5\n// away, turned 45° right\"), always current, and a polite status says it once the camera has been still a\n// moment, never per frame. A Reset button is always there: a keyboard or touch person has no `0` key\n// to find, and a lost camera needs one visible way home.\n// - **No WebGL, no blank box**: a line says so, and the controls are not drawn.\n// React Aria first: there is no 3D part, so the frame is ours; the Reset button is Strata's `Button`\n// (React Aria's), and the camera maths is plain functions with tests.\n\n/** What a `SceneViewport` hands the app to hold: the camera, and ways to move it that obey the limits. */\nexport type OrbitCameraState = {\n camera: OrbitCamera;\n setCamera: (next: OrbitCamera) => void;\n /** Back to the camera the hook started with (the viewport's Reset button does this, animated). */\n home: OrbitCamera;\n};\n\n/** A camera the app holds: `{ target, distance, yaw, pitch }` to start from, and the limits it is kept inside. Give `camera` and `setCamera` to `SceneViewport`. */\nexport function useOrbitCamera(initial: Partial<OrbitCamera> = {}, limits: Partial<CameraLimits> = {}): OrbitCameraState {\n const home = React.useMemo<OrbitCamera>(\n () => clampCamera({ target: initial.target ?? [0, 0, 0], distance: initial.distance ?? 5, yaw: initial.yaw ?? 0, pitch: initial.pitch ?? 20 }, limits),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n const [camera, set] = React.useState<OrbitCamera>(home);\n const bounds = React.useRef(limits);\n bounds.current = limits;\n const setCamera = React.useCallback((next: OrbitCamera) => set(clampCamera(next, bounds.current)), []);\n return { camera, setCamera, home };\n}\n\nexport type SceneViewportProps = {\n /** Names the view: \"Map e1m1\". The camera in words is added to it. Required. */\n label: string;\n /** The camera, from `useOrbitCamera`. */\n camera: OrbitCamera;\n onCameraChange: (camera: OrbitCamera) => void;\n /** Where Reset goes. Default: the camera the viewport first had. */\n home?: OrbitCamera;\n /** Draws the scene. Called when the camera or size changed, or after `invalidate()`; the viewport is set. */\n render: (gl: WebGL2RenderingContext, frame: SceneFrame) => void;\n /** `\"orbit\"` (default) circles a target; `\"fly\"` is the eye itself, for a walkthrough. */\n mode?: \"orbit\" | \"fly\";\n /** The vertical field of view in degrees. Default 60. */\n fov?: number;\n near?: number;\n far?: number;\n /** Closest and furthest an orbit camera may be, and the highest and lowest look in degrees. Defaults 0, none, 89. */\n limits?: Partial<CameraLimits>;\n /** World units a second of fly walking covers. Default 5. */\n flySpeed?: number;\n /** The scene's time in seconds, from a `useTimeline` clock (issue #386): the scene is drawn again when it changes, with `frame.time` set, so a recorded run or a replay scrubs and plays like a video under `TimelinePlayer`. Default: no time. */\n time?: number;\n /** Redraw every frame while on screen, for a scene that moves by itself. Default false: draw on change. */\n continuous?: boolean;\n /** The shape of the box. Default 16/9. */\n aspect?: number | `${number}/${number}`;\n /** A handle for `invalidate()` (a texture finished loading) and the canvas. */\n handle?: React.Ref<SceneViewportHandle>;\n className?: string;\n};\n\n/** What `handle` gives: ask for a redraw, and the canvas. */\nexport type SceneViewportHandle = { invalidate: () => void; canvas: HTMLCanvasElement | null };\n\nconst STILL_MS = 600;\nconst RESET_MS = 300;\nconst reducedMotion = () => typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n/** A sized, focusable canvas for a 3D scene the app draws: orbit by drag, pan by right drag or Shift, zoom by Ctrl/Cmd+wheel or pinch, keys, a Reset button, a fly mode, a lost context restored, and the camera in words. */\nexport function SceneViewport({ label, camera, onCameraChange, home, render, mode = \"orbit\", fov = 60, near = 0.1, far = 10_000, limits, flySpeed = 5, time = 0, continuous = false, aspect = \"16/9\", handle, className }: SceneViewportProps) {\n const first = React.useRef(camera);\n const target = home ?? first.current;\n const live = React.useRef({ camera, onCameraChange, render, mode, fov, near, far, limits, flySpeed, home: target, time });\n live.current = { camera, onCameraChange, render, mode, fov, near, far, limits, flySpeed, home: target, time };\n const change = React.useCallback((next: OrbitCamera) => {\n live.current.onCameraChange(clampCamera(next, live.current.limits));\n }, []);\n\n const box = React.useRef<HTMLDivElement>(null);\n const canvas = React.useRef<HTMLCanvasElement>(null);\n const [size, setSize] = React.useState({ 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 // Drawing: only when something changed, and only while on screen.\n const { ref: visibleRef, inView } = useInView({ unsupported: true });\n const boxRef = React.useCallback(\n (el: HTMLDivElement | null) => {\n box.current = el;\n visibleRef(el);\n },\n [visibleRef],\n );\n const gl = React.useRef<WebGL2RenderingContext | null>(null);\n const context = React.useRef(0);\n const [unavailable, setUnavailable] = React.useState(false);\n const frameHandle = React.useRef(0);\n const current = React.useRef({ size, inView, continuous });\n current.current = { size, inView, continuous };\n\n const paint = React.useCallback(() => {\n frameHandle.current = 0;\n const c = canvas.current;\n const ctx = gl.current;\n const { size: s, inView: visible, continuous: again } = current.current;\n if (!c || !ctx || !visible || s.width === 0 || s.height === 0) return;\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 (c.width !== w || c.height !== h) {\n c.width = w;\n c.height = h;\n }\n ctx.viewport(0, 0, w, h);\n const l = live.current;\n l.render(ctx, frameFor(l.camera, w, h, { fov: l.fov, near: l.near, far: l.far, context: context.current, time: l.time }));\n if (again) frameHandle.current = requestAnimationFrame(paint);\n }, []);\n const schedule = React.useCallback(() => {\n if (frameHandle.current === 0) frameHandle.current = requestAnimationFrame(paint);\n }, [paint]);\n React.useImperativeHandle(handle, () => ({ invalidate: schedule, canvas: canvas.current }), [schedule]);\n\n // The context: made once, made again when restored after a loss (the app sees `frame.context` change).\n React.useEffect(() => {\n const c = canvas.current;\n if (!c) return;\n const make = () => {\n gl.current = c.getContext(\"webgl2\") as WebGL2RenderingContext | null;\n setUnavailable(gl.current === null);\n if (gl.current) context.current += 1;\n schedule();\n };\n make();\n const lost = (e: Event) => {\n e.preventDefault();\n gl.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 if (frameHandle.current) cancelAnimationFrame(frameHandle.current);\n frameHandle.current = 0;\n };\n }, [schedule]);\n React.useEffect(() => {\n schedule();\n }, [schedule, camera, size.width, size.height, inView, fov, near, far, continuous, time]);\n\n // Reset: animated unless the person asked for less motion.\n const animation = React.useRef(0);\n const reset = () => {\n cancelAnimationFrame(animation.current);\n const from = live.current.camera;\n const to = live.current.home;\n if (reducedMotion()) return change(to);\n const started = performance.now();\n const step = (now: number) => {\n const t = Math.min(1, (now - started) / RESET_MS);\n const e = 1 - (1 - t) ** 3;\n const mix = (a: number, b: number) => a + (b - a) * e;\n // The short way round in yaw.\n const dyaw = ((((to.yaw - from.yaw + 180) % 360) + 360) % 360) - 180;\n change({\n target: [mix(from.target[0], to.target[0]), mix(from.target[1], to.target[1]), mix(from.target[2], to.target[2])],\n distance: mix(from.distance, to.distance),\n yaw: from.yaw + dyaw * e,\n pitch: mix(from.pitch, to.pitch),\n });\n if (t < 1) animation.current = requestAnimationFrame(step);\n };\n animation.current = requestAnimationFrame(step);\n };\n React.useEffect(() => () => cancelAnimationFrame(animation.current), []);\n\n // Pointer: drag orbits (or looks), a right drag or Shift pans, two pointers pinch (`useViewPointers`).\n const pointers = useViewPointers({\n threshold: 0,\n ignore: (e) => e.target instanceof HTMLButtonElement,\n onDown: () => cancelAnimationFrame(animation.current),\n onPinch: (ratio) => {\n const l = live.current;\n if (l.mode === \"orbit\") change(dolly(l.camera, ratio));\n },\n onDrag: (dx, dy, e) => {\n const l = live.current;\n const panning = e.shiftKey || (e.buttons & 6) !== 0; // Shift, or the right or middle button\n change(panning ? pan(l.camera, dx, dy, size.height, l.fov) : turn(l.camera, dx, dy, l.mode));\n },\n });\n\n // The wheel zooms only with Ctrl or Cmd (a trackpad pinch sends Ctrl); a plain wheel scrolls the page.\n useWheelZoom(\n box,\n (factor, e) => {\n const l = live.current;\n if (l.mode === \"orbit\") change(dolly(l.camera, factor));\n else change(walk(l.camera, -e.deltaY * 0.01 * l.flySpeed, 0, 0));\n },\n { when: (e) => e.ctrlKey || e.metaKey },\n );\n\n // Keys. Orbit: arrows turn (Shift pans), + and - zoom, 0 resets. Fly: W A S D and arrows walk, Q and E go\n // down and up, held keys move every frame (one step each press under reduced motion).\n const held = React.useRef(new Set<string>());\n const flyLoop = React.useRef(0);\n const flyKeys = [\"w\", \"a\", \"s\", \"d\", \"q\", \"e\", \"ArrowUp\", \"ArrowDown\", \"ArrowLeft\", \"ArrowRight\"];\n const walkFrom = (keys: Iterable<string>, seconds: number, fast: boolean) => {\n const l = live.current;\n const k = new Set(keys);\n const stride = l.flySpeed * seconds * (fast ? 3 : 1);\n const axis = (plus: string[], minus: string[]) => (plus.some((x) => k.has(x)) ? 1 : 0) - (minus.some((x) => k.has(x)) ? 1 : 0);\n change(walk(l.camera, axis([\"w\", \"ArrowUp\"], [\"s\", \"ArrowDown\"]) * stride, axis([\"d\", \"ArrowRight\"], [\"a\", \"ArrowLeft\"]) * stride, axis([\"e\"], [\"q\"]) * stride));\n };\n const startFly = (shift: boolean) => {\n if (flyLoop.current) return;\n let last = performance.now();\n const tick = (now: number) => {\n walkFrom(held.current, (now - last) / 1000, shift);\n last = now;\n flyLoop.current = held.current.size ? requestAnimationFrame(tick) : 0;\n };\n flyLoop.current = requestAnimationFrame(tick);\n };\n React.useEffect(() => () => cancelAnimationFrame(flyLoop.current), []);\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.ctrlKey || e.metaKey || e.altKey) return;\n const l = live.current;\n const key = e.key.length === 1 ? e.key.toLowerCase() : e.key;\n if (key === \"0\") reset();\n else if (l.mode === \"fly\" && flyKeys.includes(key)) {\n if (reducedMotion()) walkFrom([key], 0.2, e.shiftKey);\n else {\n held.current.add(key);\n startFly(e.shiftKey);\n }\n } else if (key === \"+\" || key === \"=\") change(l.mode === \"orbit\" ? dolly(l.camera, 0.8) : walk(l.camera, l.flySpeed * 0.5, 0, 0));\n else if (key === \"-\" || key === \"_\") change(l.mode === \"orbit\" ? dolly(l.camera, 1.25) : walk(l.camera, -l.flySpeed * 0.5, 0, 0));\n else if (l.mode === \"orbit\" && key.startsWith(\"Arrow\")) {\n const step = e.shiftKey ? 30 : 10; // pixels' worth, so keys and the pointer agree\n const dx = key === \"ArrowRight\" ? step : key === \"ArrowLeft\" ? -step : 0;\n const dy = key === \"ArrowDown\" ? step : key === \"ArrowUp\" ? -step : 0;\n change(e.shiftKey ? pan(l.camera, -dx, -dy, size.height, l.fov) : turn(l.camera, dx, dy, \"orbit\"));\n } else return;\n e.preventDefault();\n };\n const onKeyUp = (e: React.KeyboardEvent) => {\n held.current.delete(e.key.length === 1 ? e.key.toLowerCase() : e.key);\n };\n\n // Said in words, politely once the camera has been still for a moment.\n const words = describeCamera(camera);\n const said = useSettledStatus(words, STILL_MS);\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 tabIndex={0}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n onBlur={() => held.current.clear()}\n onPointerDown={pointers.onPointerDown}\n onPointerMove={pointers.onPointerMove}\n onPointerUp={pointers.onPointerUp}\n onPointerCancel={pointers.onPointerCancel}\n onContextMenu={(e) => e.preventDefault()}\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 ref={canvas} role=\"img\" aria-label={`${label}. ${words}`} className=\"absolute inset-0 size-full\" />\n {!unavailable && (\n <Button size=\"sm\" variant=\"outline\" onPress={reset} className=\"absolute top-2 right-2\">\n <RotateCcw /> Reset view\n </Button>\n )}\n </div>\n {unavailable && <p className=\"type-body-sm text-muted-foreground\">This browser cannot draw the 3D view.</p>}\n <VisuallyHidden>\n <span role=\"status\">{said}</span>\n </VisuallyHidden>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAkDA,IAAa,iBAA+B;CAAE,aAAa;CAAG,aAAa;CAAU,UAAU;AAAG;AAElG,IAAM,OAAO,MAAe,IAAI,KAAK,KAAM;;AAG3C,SAAgB,YAAY,GAAgB,SAAgC,CAAC,GAAgB;CAC3F,MAAM,EAAE,aAAa,aAAa,aAAa;EAAE,GAAG;EAAgB,GAAG;CAAO;CAC9E,MAAM,QAAU,EAAE,MAAM,OAAO,MAAO,OAAO,MAAO;CAEpD,MAAM,WAAW,EAAE,aAAa,KAAK,gBAAgB,IAAI,IAAI,KAAK,IAAI,KAAK,IAAI,EAAE,UAAU,WAAW,GAAG,WAAW;CACpH,OAAO;EAAE,QAAQ,EAAE;EAAQ;EAAU;EAAK,OAAO,KAAK,IAAI,KAAK,IAAI,EAAE,OAAO,CAAC,QAAQ,GAAG,QAAQ;CAAE;AACpG;AAGA,IAAM,SAAS,GAAS,MAAkB;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AE,IAAI,YAAY,IAAI,EAAE,GAAG;CACtE;CAGA,MAAM,QAAQ,eAAe,MAAM;CACnC,MAAM,OAAO,iBAAiB,OAAO,QAAQ;CAE7C,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,sBAAsB,SAAS;EAAlD,UAAA;GACE,qBAAC,OAAD;IACE,KAAK;IACL,MAAK;IACL,cAAY;IACZ,UAAU;IACC;IACF;IACT,cAAc,KAAK,QAAQ,MAAM;IACjC,eAAe,SAAS;IACxB,eAAe,SAAS;IACxB,aAAa,SAAS;IACtB,iBAAiB,SAAS;IAC1B,gBAAgB,MAAM,EAAE,eAAe;IACvC,WAAU;IACV,OAAO,EAAE,aAAa,OAAO;IAd/B,UAAA,CAgBE,oBAAC,UAAD;KAAQ,KAAK;KAAQ,MAAK;KAAM,cAAY,GAAG,MAAM,IAAI;KAAS,WAAU;IAA8B,CAAA,GACzG,CAAC,eACA,qBAAC,QAAD;KAAQ,MAAK;KAAK,SAAQ;KAAU,SAAS;KAAO,WAAU;KAA9D,UAAA,CACE,oBAAC,WAAD,CAAY,CAAA,GAAC,aACP;IAEP,CAAA,CAAA;;GACJ,eAAe,oBAAC,KAAD;IAAG,WAAU;IAAqC,UAAA;GAAwC,CAAA;GAC1G,oBAAC,gBAAD,EAAA,UACE,oBAAC,QAAD;IAAM,MAAK;IAAU,UAAA;GAAW,CAAA,EAClB,CAAA;EACb;;AAET"}
@@ -0,0 +1,107 @@
1
+ import * as React from "react";
2
+ // src/lib/viewer-input.ts
3
+ /** The pointer handlers of a viewer: spread them on the focusable box. Handlers are read fresh each event, so they may close over state. */
4
+ function useViewPointers(options) {
5
+ const live = React.useRef(options);
6
+ live.current = options;
7
+ const pointers = React.useRef(/* @__PURE__ */ new Map());
8
+ const gesture = React.useRef(null);
9
+ const spread = () => {
10
+ const [a, b] = [...pointers.current.values()];
11
+ return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : null;
12
+ };
13
+ return React.useMemo(() => {
14
+ const onPointerDown = (e) => {
15
+ if (live.current.ignore?.(e)) return;
16
+ pointers.current.set(e.pointerId, {
17
+ x: e.clientX,
18
+ y: e.clientY
19
+ });
20
+ e.currentTarget.setPointerCapture?.(e.pointerId);
21
+ e.currentTarget.focus({ preventScroll: true });
22
+ live.current.onDown?.(e);
23
+ gesture.current = {
24
+ moved: false,
25
+ pinch: spread(),
26
+ start: {
27
+ x: e.clientX,
28
+ y: e.clientY
29
+ }
30
+ };
31
+ };
32
+ const onPointerMove = (e) => {
33
+ const last = pointers.current.get(e.pointerId);
34
+ const g = gesture.current;
35
+ if (!last || !g) return;
36
+ const now = {
37
+ x: e.clientX,
38
+ y: e.clientY
39
+ };
40
+ pointers.current.set(e.pointerId, now);
41
+ if (pointers.current.size === 2) {
42
+ const d = spread();
43
+ if (g.pinch && d) live.current.onPinch?.(g.pinch / d, e);
44
+ g.pinch = d;
45
+ g.moved = true;
46
+ return;
47
+ }
48
+ const threshold = live.current.threshold ?? 4;
49
+ if (!g.moved && Math.hypot(now.x - g.start.x, now.y - g.start.y) > threshold) g.moved = true;
50
+ if (!g.moved) return;
51
+ live.current.onDrag(now.x - last.x, now.y - last.y, e);
52
+ };
53
+ const end = (e, tap) => {
54
+ const g = gesture.current;
55
+ pointers.current.delete(e.pointerId);
56
+ if (pointers.current.size === 0) {
57
+ gesture.current = null;
58
+ if (tap && g && !g.moved) live.current.onTap?.(e);
59
+ } else if (g) g.pinch = null;
60
+ };
61
+ return {
62
+ onPointerDown,
63
+ onPointerMove,
64
+ onPointerUp: (e) => end(e, true),
65
+ onPointerCancel: (e) => end(e, false)
66
+ };
67
+ }, []);
68
+ }
69
+ /** A wheel that zooms a viewer: `onZoom` gets a factor (above 1 is out). `when` says which wheels count; the rest scroll the page. */
70
+ function useWheelZoom(ref, onZoom, { when, enabled = true } = {}) {
71
+ const live = React.useRef({
72
+ onZoom,
73
+ when
74
+ });
75
+ live.current = {
76
+ onZoom,
77
+ when
78
+ };
79
+ React.useEffect(() => {
80
+ const el = ref.current;
81
+ if (!el || !enabled) return;
82
+ const onWheel = (e) => {
83
+ if (live.current.when && !live.current.when(e)) return;
84
+ e.preventDefault();
85
+ live.current.onZoom(Math.exp(e.deltaY * .0015), e);
86
+ };
87
+ el.addEventListener("wheel", onWheel, { passive: false });
88
+ return () => el.removeEventListener("wheel", onWheel);
89
+ }, [ref, enabled]);
90
+ }
91
+ /** The words for a view, once it has been still for `ms`: "" until then and on first render, so a screen reader hears where it ended up, not every frame. */
92
+ function useSettledStatus(words, ms = 600) {
93
+ const [said, setSaid] = React.useState("");
94
+ const first = React.useRef(true);
95
+ React.useEffect(() => {
96
+ if (first.current) {
97
+ first.current = false;
98
+ return;
99
+ }
100
+ const t = setTimeout(() => setSaid(words), ms);
101
+ return () => clearTimeout(t);
102
+ }, [words, ms]);
103
+ return said;
104
+ }
105
+ export { useViewPointers as n, useWheelZoom as r, useSettledStatus as t };
106
+
107
+ //# sourceMappingURL=viewer-input-CHU0Hx4A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewer-input-CHU0Hx4A.js","names":[],"sources":["../src/lib/viewer-input.ts"],"sourcesContent":["import * as React from \"react\";\n\n// The input every 3D viewer needs, written once (strata-react issue #386, from the quake2ts explorer, whose labs wrote an orbit\n// camera, keys and words by hand beside `PanoramaViewer` and `SceneViewport`, which each had their own copy of the same three\n// things). `PanoramaViewer` (looking from inside a sphere) and `SceneViewport` (round or through a scene) differ in what a drag\n// does to the view, not in how a drag is read, so the reading is here and each viewer keeps its own meaning:\n//\n// - `useViewPointers`: one pointer drags (the viewer says what that turns), two pointers pinch, a press that did not move is a tap.\n// Pointer capture, focusing the viewer on press and the 4 px that tells a click from a drag are decided once.\n// - `useWheelZoom`: a native, non-passive wheel listener (React's is passive, so the page would scroll too), with a test for\n// which wheels count: a panorama zooms on any wheel, a scene only with Ctrl or Cmd, so the page still scrolls past it.\n// - `useSettledStatus`: the polite sentence said once the view has been still for a moment, never per frame, and not on first render.\n//\n// Checked: React Aria's `usePress` reports a press and its start and end with no movement, and `useMove` gives one pointer's\n// deltas with no pinch or capture; a viewer needs both pointers and a tap in one gesture, so this is plain pointer events.\n\ntype Point = { x: number; y: number };\n\nexport type ViewPointerOptions = {\n /** One pointer moved while down: the change since its last event, and the event (for Shift and the buttons). Called once the drag is past `threshold`. */\n onDrag: (dx: number, dy: number, event: React.PointerEvent<HTMLElement>) => void;\n /** Two pointers: the earlier distance over the new one, so more than 1 is fingers coming together. Called with the event. */\n onPinch?: (ratio: number, event: React.PointerEvent<HTMLElement>) => void;\n /** A press that did not drag, or pinch, ended. */\n onTap?: (event: React.PointerEvent<HTMLElement>) => void;\n /** Called first on a press that is taken (a scene cancels its Reset animation here). */\n onDown?: (event: React.PointerEvent<HTMLElement>) => void;\n /** A press to leave alone (a button in the viewer, a secondary mouse button). Default: none. */\n ignore?: (event: React.PointerEvent<HTMLElement>) => boolean;\n /** Pixels a press must move before it is a drag. Default 4; 0 drags at once. */\n threshold?: number;\n};\n\n/** The pointer handlers of a viewer: spread them on the focusable box. Handlers are read fresh each event, so they may close over state. */\nexport function useViewPointers(options: ViewPointerOptions) {\n const live = React.useRef(options);\n live.current = options;\n const pointers = React.useRef(new Map<number, Point>());\n const gesture = React.useRef<{ moved: boolean; pinch: number | null; start: Point } | null>(null);\n const spread = () => {\n const [a, b] = [...pointers.current.values()];\n return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : null;\n };\n return React.useMemo(() => {\n const onPointerDown = (e: React.PointerEvent<HTMLElement>) => {\n if (live.current.ignore?.(e)) return;\n pointers.current.set(e.pointerId, { x: e.clientX, y: e.clientY });\n e.currentTarget.setPointerCapture?.(e.pointerId);\n e.currentTarget.focus({ preventScroll: true });\n live.current.onDown?.(e);\n gesture.current = { moved: false, pinch: spread(), start: { x: e.clientX, y: e.clientY } };\n };\n const onPointerMove = (e: React.PointerEvent<HTMLElement>) => {\n const last = pointers.current.get(e.pointerId);\n const g = gesture.current;\n if (!last || !g) return;\n const now = { x: e.clientX, y: e.clientY };\n pointers.current.set(e.pointerId, now);\n if (pointers.current.size === 2) {\n const d = spread();\n if (g.pinch && d) live.current.onPinch?.(g.pinch / d, e);\n g.pinch = d;\n g.moved = true;\n return;\n }\n const threshold = live.current.threshold ?? 4;\n if (!g.moved && Math.hypot(now.x - g.start.x, now.y - g.start.y) > threshold) g.moved = true;\n if (!g.moved) return;\n live.current.onDrag(now.x - last.x, now.y - last.y, e);\n };\n const end = (e: React.PointerEvent<HTMLElement>, tap: boolean) => {\n const g = gesture.current;\n pointers.current.delete(e.pointerId);\n if (pointers.current.size === 0) {\n gesture.current = null;\n if (tap && g && !g.moved) live.current.onTap?.(e);\n } else if (g) g.pinch = null;\n };\n return {\n onPointerDown,\n onPointerMove,\n onPointerUp: (e: React.PointerEvent<HTMLElement>) => end(e, true),\n // A cancelled pointer (the browser took a touch or pen gesture) leaves the gesture without a tap.\n onPointerCancel: (e: React.PointerEvent<HTMLElement>) => end(e, false),\n };\n }, []);\n}\n\n/** A wheel that zooms a viewer: `onZoom` gets a factor (above 1 is out). `when` says which wheels count; the rest scroll the page. */\nexport function useWheelZoom(ref: React.RefObject<HTMLElement | null>, onZoom: (factor: number, event: WheelEvent) => void, { when, enabled = true }: { when?: (event: WheelEvent) => boolean; enabled?: boolean } = {}) {\n const live = React.useRef({ onZoom, when });\n live.current = { onZoom, when };\n React.useEffect(() => {\n const el = ref.current;\n if (!el || !enabled) return;\n const onWheel = (e: WheelEvent) => {\n if (live.current.when && !live.current.when(e)) return;\n e.preventDefault();\n live.current.onZoom(Math.exp(e.deltaY * 0.0015), e);\n };\n el.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => el.removeEventListener(\"wheel\", onWheel);\n }, [ref, enabled]);\n}\n\n/** The words for a view, once it has been still for `ms`: \"\" until then and on first render, so a screen reader hears where it ended up, not every frame. */\nexport function useSettledStatus(words: string, ms = 600): string {\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;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a,GAAG,oBAAoB,SAAS,OAAO;CACtD,GAAG,CAAC,KAAK,OAAO,CAAC;AACnB;;AAGA,SAAgB,iBAAiB,OAAe,KAAK,KAAa;CAChE,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,EAAE;CACzC,MAAM,QAAQ,MAAM,OAAO,IAAI;CAC/B,MAAM,gBAAgB;EACpB,IAAI,MAAM,SAAS;GACjB,MAAM,UAAU;GAChB;EACF;EACA,MAAM,IAAI,iBAAiB,QAAQ,KAAK,GAAG,EAAE;EAC7C,aAAa,aAAa,CAAC;CAC7B,GAAG,CAAC,OAAO,EAAE,CAAC;CACd,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strata-react",
3
- "version": "1.3.24",
3
+ "version": "1.3.25",
4
4
  "description": "React + Tailwind v4 components that ship structure, behaviour, states and a token contract, and no look: each product brings a theme generated from its own subject.",
5
5
  "repository": {
6
6
  "type": "git",