strata-react 1.3.23 → 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 CHANGED
@@ -1,5 +1,7 @@
1
1
  import { o as useInView, t as Button } from "./button-KGJI6jQr.js";
2
+ import { n as useViewPointers, r as useWheelZoom, t as useSettledStatus } from "./viewer-input-CHU0Hx4A.js";
2
3
  import { r as cn } from "./tooltip-DhqrDtyu.js";
4
+ import { t as followAim } from "./follow-BTPs49FP.js";
3
5
  import * as React from "react";
4
6
  import { RotateCcw } from "lucide-react";
5
7
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -92,7 +94,7 @@ function multiply(a, b) {
92
94
  return out;
93
95
  }
94
96
  /** The frame for a camera in a drawing buffer of `width` by `height`. */
95
- function frameFor(camera, width, height, { fov = 60, near = .1, far = 1e4, context = 0 } = {}) {
97
+ function frameFor(camera, width, height, { fov = 60, near = .1, far = 1e4, context = 0, time = 0 } = {}) {
96
98
  const { forward, right, up } = basis(camera);
97
99
  const eye = [
98
100
  camera.target[0] - forward[0] * camera.distance,
@@ -112,7 +114,8 @@ function frameFor(camera, width, height, { fov = 60, near = .1, far = 1e4, conte
112
114
  viewProjection: multiply(projection, view),
113
115
  width,
114
116
  height,
115
- context
117
+ context,
118
+ time
116
119
  };
117
120
  }
118
121
  /** Turns the camera as dragging does: orbit moves the eye round the target; look (fly) turns the head. Pixels in, degrees out at `degreesPerPixel`. */
@@ -168,6 +171,43 @@ function describeCamera(c) {
168
171
  const parts = [turned && `turned ${turned}`, tilted && `looking ${tilted}`].filter(Boolean).join(", ");
169
172
  return c.distance === 0 ? `At ${at}${parts ? `, ${parts}` : ", looking straight ahead"}` : `Looking at ${at} from ${n(c.distance)} away${parts ? `, ${parts}` : ""}`;
170
173
  }
174
+ /** 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). */
175
+ function cameraFromView(view, eye = [
176
+ 0,
177
+ 0,
178
+ 0
179
+ ]) {
180
+ return {
181
+ target: eye,
182
+ distance: 0,
183
+ yaw: view.yaw,
184
+ pitch: view.pitch
185
+ };
186
+ }
187
+ /** 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. */
188
+ function viewFromCamera(camera, fov) {
189
+ return {
190
+ yaw: camera.yaw,
191
+ pitch: camera.pitch,
192
+ fov
193
+ };
194
+ }
195
+ /**
196
+ * 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
197
+ * 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.
198
+ */
199
+ function followCamera({ eye, heading, pitch = 0, look, behind = 0, maxPitch = 89 }) {
200
+ return {
201
+ target: eye,
202
+ distance: Math.max(0, behind),
203
+ ...followAim({
204
+ heading,
205
+ pitch,
206
+ look,
207
+ maxPitch
208
+ })
209
+ };
210
+ }
171
211
  // src/scene/scene-viewport.tsx
172
212
  /** 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`. */
173
213
  function useOrbitCamera(initial = {}, limits = {}) {
@@ -194,7 +234,7 @@ var STILL_MS = 600;
194
234
  var RESET_MS = 300;
195
235
  var reducedMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
196
236
  /** 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. */
197
- function SceneViewport({ label, camera, onCameraChange, home, render, mode = "orbit", fov = 60, near = .1, far = 1e4, limits, flySpeed = 5, continuous = false, aspect = "16/9", handle, className }) {
237
+ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "orbit", fov = 60, near = .1, far = 1e4, limits, flySpeed = 5, time = 0, continuous = false, aspect = "16/9", handle, className }) {
198
238
  const first = React.useRef(camera);
199
239
  const target = home ?? first.current;
200
240
  const live = React.useRef({
@@ -207,7 +247,8 @@ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "or
207
247
  far,
208
248
  limits,
209
249
  flySpeed,
210
- home: target
250
+ home: target,
251
+ time
211
252
  });
212
253
  live.current = {
213
254
  camera,
@@ -219,7 +260,8 @@ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "or
219
260
  far,
220
261
  limits,
221
262
  flySpeed,
222
- home: target
263
+ home: target,
264
+ time
223
265
  };
224
266
  const change = React.useCallback((next) => {
225
267
  live.current.onCameraChange(clampCamera(next, live.current.limits));
@@ -284,7 +326,8 @@ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "or
284
326
  fov: l.fov,
285
327
  near: l.near,
286
328
  far: l.far,
287
- context: context.current
329
+ context: context.current,
330
+ time: l.time
288
331
  }));
289
332
  if (again) frameHandle.current = requestAnimationFrame(paint);
290
333
  }, []);
@@ -329,7 +372,8 @@ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "or
329
372
  fov,
330
373
  near,
331
374
  far,
332
- continuous
375
+ continuous,
376
+ time
333
377
  ]);
334
378
  const animation = React.useRef(0);
335
379
  const reset = () => {
@@ -358,60 +402,25 @@ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "or
358
402
  animation.current = requestAnimationFrame(step);
359
403
  };
360
404
  React.useEffect(() => () => cancelAnimationFrame(animation.current), []);
361
- const pointers = React.useRef(/* @__PURE__ */ new Map());
362
- const pinch = React.useRef(null);
363
- const onPointerDown = (e) => {
364
- if (e.target instanceof HTMLButtonElement) return;
365
- pointers.current.set(e.pointerId, {
366
- x: e.clientX,
367
- y: e.clientY
368
- });
369
- e.currentTarget.setPointerCapture?.(e.pointerId);
370
- e.currentTarget.focus({ preventScroll: true });
371
- cancelAnimationFrame(animation.current);
372
- if (pointers.current.size === 2) {
373
- const [a, b] = [...pointers.current.values()];
374
- pinch.current = Math.hypot(a.x - b.x, a.y - b.y);
405
+ const pointers = useViewPointers({
406
+ threshold: 0,
407
+ ignore: (e) => e.target instanceof HTMLButtonElement,
408
+ onDown: () => cancelAnimationFrame(animation.current),
409
+ onPinch: (ratio) => {
410
+ const l = live.current;
411
+ if (l.mode === "orbit") change(dolly(l.camera, ratio));
412
+ },
413
+ onDrag: (dx, dy, e) => {
414
+ const l = live.current;
415
+ const panning = e.shiftKey || (e.buttons & 6) !== 0;
416
+ change(panning ? pan(l.camera, dx, dy, size.height, l.fov) : turn(l.camera, dx, dy, l.mode));
375
417
  }
376
- };
377
- const onPointerMove = (e) => {
378
- const last = pointers.current.get(e.pointerId);
379
- if (!last) return;
380
- const now = {
381
- x: e.clientX,
382
- y: e.clientY
383
- };
384
- pointers.current.set(e.pointerId, now);
418
+ });
419
+ useWheelZoom(box, (factor, e) => {
385
420
  const l = live.current;
386
- if (pointers.current.size === 2) {
387
- const [a, b] = [...pointers.current.values()];
388
- const d = Math.hypot(a.x - b.x, a.y - b.y);
389
- if (pinch.current && d > 0 && l.mode === "orbit") change(dolly(l.camera, pinch.current / d));
390
- pinch.current = d;
391
- return;
392
- }
393
- const dx = now.x - last.x;
394
- const dy = now.y - last.y;
395
- const panning = e.shiftKey || (e.buttons & 6) !== 0;
396
- change(panning ? pan(l.camera, dx, dy, size.height, l.fov) : turn(l.camera, dx, dy, l.mode));
397
- };
398
- const onPointerUp = (e) => {
399
- pointers.current.delete(e.pointerId);
400
- pinch.current = null;
401
- };
402
- React.useEffect(() => {
403
- const el = box.current;
404
- if (!el) return;
405
- const onWheel = (e) => {
406
- if (!e.ctrlKey && !e.metaKey) return;
407
- e.preventDefault();
408
- const l = live.current;
409
- if (l.mode === "orbit") change(dolly(l.camera, Math.exp(e.deltaY * .0015)));
410
- else change(walk(l.camera, -e.deltaY * .01 * l.flySpeed, 0, 0));
411
- };
412
- el.addEventListener("wheel", onWheel, { passive: false });
413
- return () => el.removeEventListener("wheel", onWheel);
414
- }, [change]);
421
+ if (l.mode === "orbit") change(dolly(l.camera, factor));
422
+ else change(walk(l.camera, -e.deltaY * .01 * l.flySpeed, 0, 0));
423
+ }, { when: (e) => e.ctrlKey || e.metaKey });
415
424
  const held = React.useRef(/* @__PURE__ */ new Set());
416
425
  const flyLoop = React.useRef(0);
417
426
  const flyKeys = [
@@ -469,16 +478,7 @@ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "or
469
478
  held.current.delete(e.key.length === 1 ? e.key.toLowerCase() : e.key);
470
479
  };
471
480
  const words = describeCamera(camera);
472
- const [said, setSaid] = React.useState("");
473
- const firstWords = React.useRef(true);
474
- React.useEffect(() => {
475
- if (firstWords.current) {
476
- firstWords.current = false;
477
- return;
478
- }
479
- const t = setTimeout(() => setSaid(words), STILL_MS);
480
- return () => clearTimeout(t);
481
- }, [words]);
481
+ const said = useSettledStatus(words, STILL_MS);
482
482
  return /* @__PURE__ */ jsxs("div", {
483
483
  className: cn("grid min-w-0 gap-2", className),
484
484
  children: [
@@ -490,10 +490,10 @@ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "or
490
490
  onKeyDown,
491
491
  onKeyUp,
492
492
  onBlur: () => held.current.clear(),
493
- onPointerDown,
494
- onPointerMove,
495
- onPointerUp,
496
- onPointerCancel: onPointerUp,
493
+ onPointerDown: pointers.onPointerDown,
494
+ onPointerMove: pointers.onPointerMove,
495
+ onPointerUp: pointers.onPointerUp,
496
+ onPointerCancel: pointers.onPointerCancel,
497
497
  onContextMenu: (e) => e.preventDefault(),
498
498
  className: "relative w-full cursor-grab touch-none overflow-hidden rounded-surface bg-surface-sunken select-none active:cursor-grabbing",
499
499
  style: { aspectRatio: aspect },
@@ -521,6 +521,6 @@ function SceneViewport({ label, camera, onCameraChange, home, render, mode = "or
521
521
  ]
522
522
  });
523
523
  }
524
- export { DEFAULT_LIMITS, SceneViewport, basis, clampCamera, describeCamera, dolly, frameFor, lookAlong, multiply, pan, perspective, turn, useOrbitCamera, walk };
524
+ export { DEFAULT_LIMITS, SceneViewport, basis, cameraFromView, clampCamera, describeCamera, dolly, followCamera, frameFor, lookAlong, multiply, pan, perspective, turn, useOrbitCamera, viewFromCamera, walk };
525
525
 
526
526
  //# sourceMappingURL=scene.js.map
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};\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 }: { fov?: number; near?: number; far?: number; context?: 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 };\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 /** 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, 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 });\n live.current = { camera, onCameraChange, render, mode, fov, near, far, limits, flySpeed, home: target };\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 }));\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]);\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":";;;;;;;AA8CA,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,OA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L,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;CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;CAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;CAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;AAAE;AAC1H,IAAM,OAAO,GAAS,MAAY,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;;AAGvE,SAAgB,MAAM,GAAiF;CAIrG,MAAM,IAAI,IAAI,EAAE,GAAG;CACnB,MAAM,IAAI,IAAI,EAAE,KA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AAiB,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"}
@@ -151,7 +151,9 @@
151
151
  @utility type-label { font-size: var(--type-label-size, 0.875rem); line-height: var(--type-label-leading, 1.25rem); font-weight: var(--type-label-weight, 500); }
152
152
  @utility type-body-sm { font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-leading, 1.25rem); font-weight: var(--type-body-sm-weight, 400); }
153
153
  @utility type-body { font-size: var(--type-body-size, 1rem); line-height: var(--type-body-leading, 1.5rem); font-weight: var(--type-body-weight, 400); }
154
- @utility type-heading { font-size: var(--type-heading-size, 1.125rem); line-height: var(--type-heading-leading, 1.5rem); font-weight: var(--type-heading-weight, 600); }
154
+ /* `type-heading` reads `--type-heading-font` (default: inherit) the way `type-figure` reads `--figure-font`, so a look with display headings
155
+ sets one variable and not a `.type-heading` rule (issue #383). `--figure-ink`, `--surface-image` and the `data-part` attributes are in the base layer below. */
156
+ @utility type-heading { font-family: var(--type-heading-font, inherit); font-size: var(--type-heading-size, 1.125rem); line-height: var(--type-heading-leading, 1.5rem); font-weight: var(--type-heading-weight, 600); }
155
157
  @utility type-title {
156
158
  font-family: var(--font-display);
157
159
  font-size: var(--type-title-size, 1.75rem);
@@ -259,6 +261,12 @@
259
261
  line-height: 1.5rem;
260
262
  -webkit-font-smoothing: antialiased;
261
263
  }
264
+ /* Hooks for a second look (issue #383), all inert by default. `--figure-ink` colours `type-figure` where the figure sets no
265
+ colour of its own (this layer is below the utilities, so a `text-*` class wins). `--surface-image` is a texture for the ground
266
+ (the body) and the surface parts that draw their own panel; themes read `data-part` (pane, pane-header, pane-title,
267
+ workspace-bar, inspector, inspector-header, inspector-section, link-card) and not markup or class names. */
268
+ .type-figure { color: var(--figure-ink, inherit); }
269
+ body, [data-part="pane"], [data-part="link-card"], [data-part="inspector"] { background-image: var(--surface-image, none); }
262
270
  /* One focus treatment for everything focusable, so no component can forget it. */
263
271
  :focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
264
272
  /* Except where a script moved focus to a heading to announce a result (Done): the heading is not
package/dist/strata.css CHANGED
@@ -146,7 +146,9 @@
146
146
  @utility type-label { font-size: var(--type-label-size, 0.875rem); line-height: var(--type-label-leading, 1.25rem); font-weight: var(--type-label-weight, 500); }
147
147
  @utility type-body-sm { font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-leading, 1.25rem); font-weight: var(--type-body-sm-weight, 400); }
148
148
  @utility type-body { font-size: var(--type-body-size, 1rem); line-height: var(--type-body-leading, 1.5rem); font-weight: var(--type-body-weight, 400); }
149
- @utility type-heading { font-size: var(--type-heading-size, 1.125rem); line-height: var(--type-heading-leading, 1.5rem); font-weight: var(--type-heading-weight, 600); }
149
+ /* `type-heading` reads `--type-heading-font` (default: inherit) the way `type-figure` reads `--figure-font`, so a look with display headings
150
+ sets one variable and not a `.type-heading` rule (issue #383). `--figure-ink`, `--surface-image` and the `data-part` attributes are in the base layer below. */
151
+ @utility type-heading { font-family: var(--type-heading-font, inherit); font-size: var(--type-heading-size, 1.125rem); line-height: var(--type-heading-leading, 1.5rem); font-weight: var(--type-heading-weight, 600); }
150
152
  @utility type-title {
151
153
  font-family: var(--font-display);
152
154
  font-size: var(--type-title-size, 1.75rem);
@@ -254,6 +256,12 @@
254
256
  line-height: 1.5rem;
255
257
  -webkit-font-smoothing: antialiased;
256
258
  }
259
+ /* Hooks for a second look (issue #383), all inert by default. `--figure-ink` colours `type-figure` where the figure sets no
260
+ colour of its own (this layer is below the utilities, so a `text-*` class wins). `--surface-image` is a texture for the ground
261
+ (the body) and the surface parts that draw their own panel; themes read `data-part` (pane, pane-header, pane-title,
262
+ workspace-bar, inspector, inspector-header, inspector-section, link-card) and not markup or class names. */
263
+ .type-figure { color: var(--figure-ink, inherit); }
264
+ body, [data-part="pane"], [data-part="link-card"], [data-part="inspector"] { background-image: var(--surface-image, none); }
257
265
  /* One focus treatment for everything focusable, so no component can forget it. */
258
266
  :focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
259
267
  /* Except where a script moved focus to a heading to announce a result (Done): the heading is not
@@ -142,7 +142,9 @@
142
142
  @utility type-label { font-size: var(--type-label-size, 0.875rem); line-height: var(--type-label-leading, 1.25rem); font-weight: var(--type-label-weight, 500); }
143
143
  @utility type-body-sm { font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-leading, 1.25rem); font-weight: var(--type-body-sm-weight, 400); }
144
144
  @utility type-body { font-size: var(--type-body-size, 1rem); line-height: var(--type-body-leading, 1.5rem); font-weight: var(--type-body-weight, 400); }
145
- @utility type-heading { font-size: var(--type-heading-size, 1.125rem); line-height: var(--type-heading-leading, 1.5rem); font-weight: var(--type-heading-weight, 600); }
145
+ /* `type-heading` reads `--type-heading-font` (default: inherit) the way `type-figure` reads `--figure-font`, so a look with display headings
146
+ sets one variable and not a `.type-heading` rule (issue #383). `--figure-ink`, `--surface-image` and the `data-part` attributes are in the base layer below. */
147
+ @utility type-heading { font-family: var(--type-heading-font, inherit); font-size: var(--type-heading-size, 1.125rem); line-height: var(--type-heading-leading, 1.5rem); font-weight: var(--type-heading-weight, 600); }
146
148
  @utility type-title {
147
149
  font-family: var(--font-display);
148
150
  font-size: var(--type-title-size, 1.75rem);
@@ -250,6 +252,12 @@
250
252
  line-height: 1.5rem;
251
253
  -webkit-font-smoothing: antialiased;
252
254
  }
255
+ /* Hooks for a second look (issue #383), all inert by default. `--figure-ink` colours `type-figure` where the figure sets no
256
+ colour of its own (this layer is below the utilities, so a `text-*` class wins). `--surface-image` is a texture for the ground
257
+ (the body) and the surface parts that draw their own panel; themes read `data-part` (pane, pane-header, pane-title,
258
+ workspace-bar, inspector, inspector-header, inspector-section, link-card) and not markup or class names. */
259
+ .type-figure { color: var(--figure-ink, inherit); }
260
+ body, [data-part="pane"], [data-part="link-card"], [data-part="inspector"] { background-image: var(--surface-image, none); }
253
261
  /* One focus treatment for everything focusable, so no component can forget it. */
254
262
  :focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
255
263
  /* Except where a script moved focus to a heading to announce a result (Done): the heading is not
@@ -39,11 +39,28 @@ function toShortcuts(input) {
39
39
  }
40
40
  /**
41
41
  * Binds single-key shortcuts on the window (also for a key pressed on a control inside a grid row, whose React Aria hooks stop propagation), ignoring keys typed into fields, chords with Ctrl, Meta
42
- * or Alt, IME composition and (unless `repeat`) held keys. Pass the same list to `KeysLegend`.
42
+ * or Alt, IME composition and (unless `repeat`) held keys. Pass the same list to `KeysLegend`: better, pass it `live`, which is what answers a key
43
+ * right now (nothing while `enabled` is off; with `within`, only the `anywhere` keys until focus is inside the region).
43
44
  */
44
- function useHotkeys(shortcuts, { enabled = true } = {}) {
45
+ function useHotkeys(shortcuts, { enabled = true, within } = {}) {
45
46
  const latest = React.useRef([]);
46
- latest.current = toShortcuts(shortcuts);
47
+ const list = toShortcuts(shortcuts);
48
+ latest.current = list;
49
+ const [inside, setInside] = React.useState(false);
50
+ React.useEffect(() => {
51
+ const region = within?.current;
52
+ if (!region || !enabled) return setInside(false);
53
+ const sync = () => setInside(region.contains(document.activeElement));
54
+ sync();
55
+ const leave = () => queueMicrotask(sync);
56
+ region.addEventListener("focusin", sync);
57
+ region.addEventListener("focusout", leave);
58
+ return () => {
59
+ region.removeEventListener("focusin", sync);
60
+ region.removeEventListener("focusout", leave);
61
+ setInside(false);
62
+ };
63
+ }, [enabled, within]);
47
64
  React.useEffect(() => {
48
65
  if (!enabled) return;
49
66
  const seen = /* @__PURE__ */ new WeakSet();
@@ -52,7 +69,9 @@ function useHotkeys(shortcuts, { enabled = true } = {}) {
52
69
  seen.add(e);
53
70
  if (e.defaultPrevented || e.isComposing || e.ctrlKey || e.metaKey || e.altKey) return;
54
71
  if (isTypingTarget(e.target)) return;
55
- const hit = latest.current.find((s) => !s.disabled && s.keys.includes(e.key));
72
+ const region = within?.current;
73
+ const here = !within || !!region && e.target instanceof Node && region.contains(e.target);
74
+ const hit = latest.current.find((s) => !s.disabled && (here || s.anywhere) && s.keys.includes(e.key));
56
75
  if (!hit || e.repeat && !hit.repeat) return;
57
76
  e.preventDefault();
58
77
  hit.run();
@@ -66,7 +85,8 @@ function useHotkeys(shortcuts, { enabled = true } = {}) {
66
85
  window.removeEventListener("keydown", early, true);
67
86
  window.removeEventListener("keydown", onKeyDown);
68
87
  };
69
- }, [enabled]);
88
+ }, [enabled, within]);
89
+ return { live: enabled ? list.filter((s) => !s.disabled && (!within || inside || s.anywhere)) : [] };
70
90
  }
71
91
  /** How a `KeyboardEvent.key` is drawn in a legend and an editor: arrows as arrows, the rest by name. */
72
92
  var keyName = (key) => KEY_NAMES[key] ?? key;
@@ -722,4 +742,4 @@ function ColorField({ value, onChange, suggestions, against, againstLabel = "the
722
742
  }
723
743
  export { useAsyncAction as a, KeysLegend as c, useHotkeys as d, AsyncButton as i, isTypingTarget as l, NumberField$1 as n, Toolbar$1 as o, Slider$1 as r, ToolbarSeparator as s, ColorField as t, keyName as u };
724
744
 
725
- //# sourceMappingURL=value-controls-Dq2-QpvA.js.map
745
+ //# sourceMappingURL=value-controls-Dm_EYfZW.js.map