strata-react 1.0.33 → 1.0.35

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.
Files changed (55) hide show
  1. package/README.md +12 -2
  2. package/UPGRADING.md +1 -0
  3. package/dist/components/conversation.d.ts +67 -0
  4. package/dist/components/dialog.d.ts +1 -1
  5. package/dist/components/folder-picker.d.ts +42 -0
  6. package/dist/components/lightbox.d.ts +34 -0
  7. package/dist/components/markable-text.d.ts +56 -0
  8. package/dist/components/media-group.d.ts +25 -0
  9. package/dist/components/media-player.d.ts +80 -2
  10. package/dist/components/region-editor.d.ts +55 -0
  11. package/dist/components/sequence-timeline.d.ts +50 -0
  12. package/dist/components/transcript-view.d.ts +36 -0
  13. package/dist/components/tree.d.ts +41 -0
  14. package/dist/components/waveform.d.ts +66 -0
  15. package/dist/{cursor-DplHNzj3.js → cursor-DDGBPiTJ.js} +2 -200
  16. package/dist/cursor-DDGBPiTJ.js.map +1 -0
  17. package/dist/field-7Z4N5r5g.js +178 -0
  18. package/dist/field-7Z4N5r5g.js.map +1 -0
  19. package/dist/format-B32-PVi2.js +201 -0
  20. package/dist/format-B32-PVi2.js.map +1 -0
  21. package/dist/hls/index.d.ts +19 -0
  22. package/dist/hls.js +84 -0
  23. package/dist/hls.js.map +1 -0
  24. package/dist/index.d.ts +17 -1
  25. package/dist/index.js +3454 -568
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/marks.d.ts +6 -0
  28. package/dist/lib/region.d.ts +46 -0
  29. package/dist/lib/rich-text.d.ts +44 -0
  30. package/dist/lib/sequence.d.ts +34 -0
  31. package/dist/lib/transcript.d.ts +28 -0
  32. package/dist/lib/waveform.d.ts +36 -0
  33. package/dist/map.js +4 -2
  34. package/dist/map.js.map +1 -1
  35. package/dist/panorama/gl.d.ts +16 -0
  36. package/dist/panorama/index.d.ts +2 -0
  37. package/dist/panorama/panorama-viewer.d.ts +56 -0
  38. package/dist/panorama/projection.d.ts +45 -0
  39. package/dist/panorama.js +657 -0
  40. package/dist/panorama.js.map +1 -0
  41. package/dist/{query-DgJMyXTT.js → query-BJcxJLhh.js} +3 -2
  42. package/dist/{query-DgJMyXTT.js.map → query-BJcxJLhh.js.map} +1 -1
  43. package/dist/{run-BqZGKhW9.js → run-DzyLrZlA.js} +23 -5
  44. package/dist/run-DzyLrZlA.js.map +1 -0
  45. package/dist/testing.js +2 -2
  46. package/dist/{theme-BgTOESmN.js → theme-CFNi6WUO.js} +5 -175
  47. package/dist/theme-CFNi6WUO.js.map +1 -0
  48. package/dist/value-controls-D6O9TsM6.js +356 -0
  49. package/dist/value-controls-D6O9TsM6.js.map +1 -0
  50. package/dist/visual-cli.js +1 -1
  51. package/dist/visual.js +1 -1
  52. package/package.json +19 -4
  53. package/dist/cursor-DplHNzj3.js.map +0 -1
  54. package/dist/run-BqZGKhW9.js.map +0 -1
  55. package/dist/theme-BgTOESmN.js.map +0 -1
@@ -0,0 +1,657 @@
1
+ import { i as useInView, r as Slider } from "./value-controls-D6O9TsM6.js";
2
+ import { c as cn } from "./field-7Z4N5r5g.js";
3
+ import * as React from "react";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { VisuallyHidden } from "react-aria";
6
+ // src/panorama/gl.ts
7
+ var VERTEX = `#version 300 es
8
+ in vec2 aPos;
9
+ out vec2 vNdc;
10
+ void main() { vNdc = aPos; gl_Position = vec4(aPos, 0.0, 1.0); }`;
11
+ var FRAGMENT = `#version 300 es
12
+ precision highp float;
13
+ in vec2 vNdc;
14
+ out vec4 outColor;
15
+ uniform sampler2D uPicture;
16
+ uniform float uYaw;
17
+ uniform float uPitch;
18
+ uniform float uTanHalf;
19
+ uniform float uAspect;
20
+ const float PI = 3.14159265358979;
21
+ void main() {
22
+ vec3 forward = vec3(cos(uPitch) * sin(uYaw), sin(uPitch), cos(uPitch) * cos(uYaw));
23
+ vec3 right = vec3(cos(uYaw), 0.0, -sin(uYaw));
24
+ vec3 up = vec3(-sin(uPitch) * sin(uYaw), cos(uPitch), -sin(uPitch) * cos(uYaw));
25
+ vec3 ray = normalize(forward + vNdc.x * uTanHalf * right + vNdc.y * (uTanHalf / uAspect) * up);
26
+ float lon = atan(ray.x, ray.z);
27
+ float lat = asin(clamp(ray.y, -1.0, 1.0));
28
+ outColor = texture(uPicture, vec2(lon / (2.0 * PI) + 0.5, 0.5 - lat / PI));
29
+ }`;
30
+ /** Makes a renderer on `canvas`, or null where WebGL2 is not available (the viewer then shows the flat picture). */
31
+ function createRenderer(canvas) {
32
+ const gl = canvas.getContext("webgl2", {
33
+ antialias: false,
34
+ preserveDrawingBuffer: false,
35
+ alpha: false
36
+ });
37
+ if (!gl) return null;
38
+ const compile = (type, source) => {
39
+ const shader = gl.createShader(type);
40
+ gl.shaderSource(shader, source);
41
+ gl.compileShader(shader);
42
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
43
+ const log = gl.getShaderInfoLog(shader);
44
+ gl.deleteShader(shader);
45
+ throw new Error(`Panorama shader: ${log}`);
46
+ }
47
+ return shader;
48
+ };
49
+ let program;
50
+ try {
51
+ program = gl.createProgram();
52
+ gl.attachShader(program, compile(gl.VERTEX_SHADER, VERTEX));
53
+ gl.attachShader(program, compile(gl.FRAGMENT_SHADER, FRAGMENT));
54
+ gl.linkProgram(program);
55
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) throw new Error(`Panorama program: ${gl.getProgramInfoLog(program)}`);
56
+ } catch {
57
+ return null;
58
+ }
59
+ gl.useProgram(program);
60
+ const buffer = gl.createBuffer();
61
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
62
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
63
+ -1,
64
+ -1,
65
+ 3,
66
+ -1,
67
+ -1,
68
+ 3
69
+ ]), gl.STATIC_DRAW);
70
+ const position = gl.getAttribLocation(program, "aPos");
71
+ gl.enableVertexAttribArray(position);
72
+ gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
73
+ const texture = gl.createTexture();
74
+ gl.bindTexture(gl.TEXTURE_2D, texture);
75
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
76
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
77
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
78
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
79
+ const uniforms = {
80
+ yaw: gl.getUniformLocation(program, "uYaw"),
81
+ pitch: gl.getUniformLocation(program, "uPitch"),
82
+ tanHalf: gl.getUniformLocation(program, "uTanHalf"),
83
+ aspect: gl.getUniformLocation(program, "uAspect"),
84
+ picture: gl.getUniformLocation(program, "uPicture")
85
+ };
86
+ gl.uniform1i(uniforms.picture, 0);
87
+ let uploaded = 0;
88
+ let has = false;
89
+ return {
90
+ upload(picture) {
91
+ gl.bindTexture(gl.TEXTURE_2D, texture);
92
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, picture);
93
+ uploaded++;
94
+ has = true;
95
+ },
96
+ draw(view, width, height) {
97
+ if (canvas.width !== width || canvas.height !== height) {
98
+ canvas.width = width;
99
+ canvas.height = height;
100
+ }
101
+ gl.viewport(0, 0, width, height);
102
+ if (!has) {
103
+ gl.clearColor(0, 0, 0, 1);
104
+ gl.clear(gl.COLOR_BUFFER_BIT);
105
+ return;
106
+ }
107
+ const rad = Math.PI / 180;
108
+ gl.uniform1f(uniforms.yaw, view.yaw * rad);
109
+ gl.uniform1f(uniforms.pitch, view.pitch * rad);
110
+ gl.uniform1f(uniforms.tanHalf, Math.tan(view.fov * rad / 2));
111
+ gl.uniform1f(uniforms.aspect, width / height);
112
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
113
+ },
114
+ uploads: () => uploaded,
115
+ dispose() {
116
+ gl.deleteTexture(texture);
117
+ gl.deleteBuffer(buffer);
118
+ gl.deleteProgram(program);
119
+ }
120
+ };
121
+ }
122
+ // src/panorama/projection.ts
123
+ var RAD = Math.PI / 180;
124
+ var DEG = 180 / Math.PI;
125
+ /** Wraps a heading to (-180, 180]. */
126
+ function wrapYaw(yaw) {
127
+ const w = ((yaw + 180) % 360 + 360) % 360 - 180;
128
+ return w === -180 ? 180 : w;
129
+ }
130
+ /** The smallest signed turn from heading `from` to heading `to`, in (-180, 180]. Use it for a difference of headings, never `to - from`. */
131
+ var yawDelta = (from, to) => wrapYaw(to - from);
132
+ /** Keeps a view inside its limits: heading wrapped, pitch within +-`maxPitch`, field of view within `minFov` to `maxFov`. */
133
+ function clampView(view, { maxPitch = 85, minFov = 20, maxFov = 120 } = {}) {
134
+ return {
135
+ yaw: wrapYaw(view.yaw),
136
+ pitch: Math.min(Math.max(view.pitch, -maxPitch), maxPitch),
137
+ fov: Math.min(Math.max(view.fov, minFov), maxFov)
138
+ };
139
+ }
140
+ var focal = (view, size) => size.width / 2 / Math.tan(view.fov * RAD / 2);
141
+ function basis(view) {
142
+ const y = view.yaw * RAD;
143
+ const p = view.pitch * RAD;
144
+ return {
145
+ forward: [
146
+ Math.cos(p) * Math.sin(y),
147
+ Math.sin(p),
148
+ Math.cos(p) * Math.cos(y)
149
+ ],
150
+ right: [
151
+ Math.cos(y),
152
+ 0,
153
+ -Math.sin(y)
154
+ ],
155
+ up: [
156
+ -Math.sin(p) * Math.sin(y),
157
+ Math.cos(p),
158
+ -Math.sin(p) * Math.cos(y)
159
+ ]
160
+ };
161
+ }
162
+ var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
163
+ /** Where the direction (`yaw`, `pitch`) is drawn in the box for `view`, or null when it is behind the camera. */
164
+ function project(view, size, yaw, pitch) {
165
+ const { forward, right, up } = basis(view);
166
+ const p = pitch * RAD;
167
+ const y = yaw * RAD;
168
+ const d = [
169
+ Math.cos(p) * Math.sin(y),
170
+ Math.sin(p),
171
+ Math.cos(p) * Math.cos(y)
172
+ ];
173
+ const z = dot(d, forward);
174
+ if (z <= 1e-9) return null;
175
+ const f = focal(view, size);
176
+ const x = size.width / 2 + f * dot(d, right) / z;
177
+ const yy = size.height / 2 - f * dot(d, up) / z;
178
+ return {
179
+ x,
180
+ y: yy,
181
+ inside: x >= 0 && x <= size.width && yy >= 0 && yy <= size.height
182
+ };
183
+ }
184
+ /** The direction under a point of the box for `view`: the inverse of `project`. */
185
+ function unproject(view, size, x, y) {
186
+ const { forward, right, up } = basis(view);
187
+ const f = focal(view, size);
188
+ const a = (x - size.width / 2) / f;
189
+ const b = -(y - size.height / 2) / f;
190
+ const v = [
191
+ forward[0] + a * right[0] + b * up[0],
192
+ forward[1] + a * right[1] + b * up[1],
193
+ forward[2] + a * right[2] + b * up[2]
194
+ ];
195
+ const length = Math.hypot(v[0], v[1], v[2]);
196
+ return {
197
+ yaw: wrapYaw(Math.atan2(v[0], v[2]) * DEG),
198
+ pitch: Math.asin(Math.min(Math.max(v[1] / length, -1), 1)) * DEG
199
+ };
200
+ }
201
+ /** Pixels to degrees at the middle of the box: how far a drag of `px` turns the view. */
202
+ var degreesPerPixel = (view, size) => Math.atan(1 / focal(view, size)) * DEG;
203
+ /** The flat picture's own mapping, for the fallback with no WebGL: longitude and latitude are straight across and down, the visible rectangle is `fov` wide and as tall as the box's shape makes it. */
204
+ function projectFlat(view, size, yaw, pitch) {
205
+ const perPixel = view.fov / size.width;
206
+ const x = size.width / 2 + yawDelta(view.yaw, yaw) / perPixel;
207
+ const y = size.height / 2 - (pitch - view.pitch) / perPixel;
208
+ return {
209
+ x,
210
+ y,
211
+ inside: x >= 0 && x <= size.width && y >= 0 && y <= size.height
212
+ };
213
+ }
214
+ /** The inverse of `projectFlat`. */
215
+ function unprojectFlat(view, size, x, y) {
216
+ const perPixel = view.fov / size.width;
217
+ return {
218
+ yaw: wrapYaw(view.yaw + (x - size.width / 2) * perPixel),
219
+ pitch: Math.min(Math.max(view.pitch - (y - size.height / 2) * perPixel, -90), 90)
220
+ };
221
+ }
222
+ /** The direction in words: "Looking 40° right, 5° up", "Looking straight ahead". Whole degrees; nothing is said for less than half a degree. */
223
+ function describeView(view) {
224
+ const yaw = Math.round(wrapYaw(view.yaw));
225
+ const pitch = Math.round(view.pitch);
226
+ const parts = [yaw === 0 ? "" : yaw === 180 ? "directly behind" : `${Math.abs(yaw)}° ${yaw > 0 ? "right" : "left"}`, pitch === 0 ? "" : `${Math.abs(pitch)}° ${pitch > 0 ? "up" : "down"}`].filter(Boolean);
227
+ return parts.length === 0 ? "Looking straight ahead" : `Looking ${parts.join(", ")}`;
228
+ }
229
+ // src/panorama/panorama-viewer.tsx
230
+ var HOME = {
231
+ yaw: 0,
232
+ pitch: 0,
233
+ fov: 90
234
+ };
235
+ var STILL_MS = 600;
236
+ /** A 360 picture or video as a window you pan and zoom, controlled from outside, with an overlay in the picture's coordinates. */
237
+ function PanoramaViewer({ label, image, video, view: controlled, defaultView = HOME, onViewChange, onPick, maxPitch = 85, minFov = 20, maxFov = 120, wheelZoom = true, fovSlider = false, overlay, mode = "auto", aspect = "16/9", className }) {
238
+ const limits = React.useMemo(() => ({
239
+ maxPitch,
240
+ minFov,
241
+ maxFov
242
+ }), [
243
+ maxPitch,
244
+ minFov,
245
+ maxFov
246
+ ]);
247
+ const [own, setOwn] = React.useState(() => clampView(defaultView, limits));
248
+ const view = React.useMemo(() => clampView(controlled ?? own, limits), [
249
+ controlled,
250
+ own,
251
+ limits
252
+ ]);
253
+ const live = React.useRef({
254
+ view,
255
+ controlled: controlled !== void 0,
256
+ onViewChange,
257
+ onPick,
258
+ limits
259
+ });
260
+ live.current = {
261
+ view,
262
+ controlled: controlled !== void 0,
263
+ onViewChange,
264
+ onPick,
265
+ limits
266
+ };
267
+ const change = React.useCallback((next) => {
268
+ const l = live.current;
269
+ const clamped = clampView(next, l.limits);
270
+ if (!l.controlled) setOwn(clamped);
271
+ l.onViewChange?.(clamped);
272
+ }, []);
273
+ const box = React.useRef(null);
274
+ const canvas = React.useRef(null);
275
+ const [size, setSize] = React.useState({
276
+ width: 0,
277
+ height: 0
278
+ });
279
+ React.useLayoutEffect(() => {
280
+ const el = box.current;
281
+ if (!el) return;
282
+ const read = () => {
283
+ const r = el.getBoundingClientRect();
284
+ setSize((s) => s.width === r.width && s.height === r.height ? s : {
285
+ width: r.width,
286
+ height: r.height
287
+ });
288
+ };
289
+ read();
290
+ if (typeof ResizeObserver === "undefined") return;
291
+ const ro = new ResizeObserver(read);
292
+ ro.observe(el);
293
+ return () => ro.disconnect();
294
+ }, []);
295
+ const [still, setStill] = React.useState(null);
296
+ React.useEffect(() => {
297
+ if (image === void 0) {
298
+ setStill(null);
299
+ return;
300
+ }
301
+ const img = new Image();
302
+ img.crossOrigin = "anonymous";
303
+ let cancelled = false;
304
+ img.onload = () => !cancelled && setStill(img);
305
+ img.src = image;
306
+ return () => {
307
+ cancelled = true;
308
+ img.onload = null;
309
+ };
310
+ }, [image]);
311
+ const { ref: visibleRef, inView } = useInView({ unsupported: true });
312
+ const boxRef = React.useCallback((el) => {
313
+ box.current = el;
314
+ visibleRef(el);
315
+ }, [visibleRef]);
316
+ const renderer = React.useRef(null);
317
+ const [flat, setFlat] = React.useState(false);
318
+ const frame = React.useRef(0);
319
+ const dirtyPicture = React.useRef(true);
320
+ const current = React.useRef({
321
+ size,
322
+ inView,
323
+ flat
324
+ });
325
+ current.current = {
326
+ size,
327
+ inView,
328
+ flat
329
+ };
330
+ const pictureNow = React.useCallback(() => {
331
+ const v = video?.current;
332
+ if (v) return v.readyState >= 2 && v.videoWidth > 0 ? v : null;
333
+ return still;
334
+ }, [video, still]);
335
+ const paint = React.useCallback(() => {
336
+ frame.current = 0;
337
+ const c = canvas.current;
338
+ const { size: s, inView: visible } = current.current;
339
+ if (!c || !visible || s.width === 0 || s.height === 0) return;
340
+ const picture = pictureNow();
341
+ const dpr = Math.min(typeof devicePixelRatio === "number" ? devicePixelRatio : 1, 2);
342
+ const w = Math.max(1, Math.round(s.width * dpr));
343
+ const h = Math.max(1, Math.round(s.height * dpr));
344
+ if (current.current.flat) {
345
+ const ctx = c.getContext("2d");
346
+ if (!ctx) return;
347
+ if (c.width !== w || c.height !== h) {
348
+ c.width = w;
349
+ c.height = h;
350
+ }
351
+ ctx.fillStyle = "#000";
352
+ ctx.fillRect(0, 0, w, h);
353
+ if (!picture) return;
354
+ const sw = picture.naturalWidth || picture.videoWidth || c.width;
355
+ const sh = picture.naturalHeight || picture.videoHeight || c.height;
356
+ const v = live.current.view;
357
+ const wide = v.fov / 360 * sw;
358
+ const tall = v.fov * (s.height / s.width) / 180 * sh;
359
+ const left = (v.yaw - v.fov / 2 + 180) / 360 * sw;
360
+ const top = (90 - v.pitch) / 180 * sh - tall / 2;
361
+ for (const shift of [
362
+ -sw,
363
+ 0,
364
+ sw
365
+ ]) {
366
+ const a = Math.max(left + shift, 0);
367
+ const b = Math.min(left + shift + wide, sw);
368
+ if (b > a) ctx.drawImage(picture, a, Math.max(top, 0), b - a, Math.min(tall, sh), (a - (left + shift)) / wide * w, 0, (b - a) / wide * w, h);
369
+ }
370
+ return;
371
+ }
372
+ const r = renderer.current;
373
+ if (!r) return;
374
+ if (picture && dirtyPicture.current) {
375
+ r.upload(picture);
376
+ dirtyPicture.current = false;
377
+ }
378
+ r.draw(live.current.view, w, h);
379
+ }, [pictureNow]);
380
+ const schedule = React.useCallback(() => {
381
+ if (frame.current === 0) frame.current = requestAnimationFrame(paint);
382
+ }, [paint]);
383
+ React.useEffect(() => {
384
+ const c = canvas.current;
385
+ if (!c) return;
386
+ const make = () => {
387
+ renderer.current?.dispose();
388
+ renderer.current = mode === "flat" ? null : createRenderer(c);
389
+ setFlat(renderer.current === null);
390
+ dirtyPicture.current = true;
391
+ schedule();
392
+ };
393
+ make();
394
+ const lost = (e) => {
395
+ e.preventDefault();
396
+ renderer.current = null;
397
+ };
398
+ c.addEventListener("webglcontextlost", lost);
399
+ c.addEventListener("webglcontextrestored", make);
400
+ return () => {
401
+ c.removeEventListener("webglcontextlost", lost);
402
+ c.removeEventListener("webglcontextrestored", make);
403
+ renderer.current?.dispose();
404
+ renderer.current = null;
405
+ if (frame.current) cancelAnimationFrame(frame.current);
406
+ frame.current = 0;
407
+ };
408
+ }, [schedule, mode]);
409
+ React.useEffect(() => {
410
+ dirtyPicture.current = true;
411
+ }, [still]);
412
+ React.useEffect(() => {
413
+ schedule();
414
+ }, [
415
+ schedule,
416
+ view.yaw,
417
+ view.pitch,
418
+ view.fov,
419
+ size.width,
420
+ size.height,
421
+ still,
422
+ inView,
423
+ flat
424
+ ]);
425
+ React.useEffect(() => {
426
+ const v = video?.current;
427
+ if (!v || !inView) return;
428
+ let stopped = false;
429
+ let handle = 0;
430
+ const onFrame = () => {
431
+ if (stopped) return;
432
+ dirtyPicture.current = true;
433
+ schedule();
434
+ handle = v.requestVideoFrameCallback(onFrame);
435
+ };
436
+ if (typeof v.requestVideoFrameCallback === "function") {
437
+ handle = v.requestVideoFrameCallback(onFrame);
438
+ return () => {
439
+ stopped = true;
440
+ v.cancelVideoFrameCallback?.(handle);
441
+ };
442
+ }
443
+ const touch = () => {
444
+ dirtyPicture.current = true;
445
+ schedule();
446
+ };
447
+ const events = [
448
+ "loadeddata",
449
+ "seeked",
450
+ "timeupdate",
451
+ "play",
452
+ "pause"
453
+ ];
454
+ for (const e of events) v.addEventListener(e, touch);
455
+ let loop = 0;
456
+ const tick = () => {
457
+ if (!v.paused) touch();
458
+ loop = requestAnimationFrame(tick);
459
+ };
460
+ loop = requestAnimationFrame(tick);
461
+ return () => {
462
+ for (const e of events) v.removeEventListener(e, touch);
463
+ cancelAnimationFrame(loop);
464
+ };
465
+ }, [
466
+ video,
467
+ inView,
468
+ schedule
469
+ ]);
470
+ const pointers = React.useRef(/* @__PURE__ */ new Map());
471
+ const gesture = React.useRef(null);
472
+ const hostRect = () => box.current.getBoundingClientRect();
473
+ const onPointerDown = (e) => {
474
+ if (e.button !== 0 && e.pointerType === "mouse") return;
475
+ pointers.current.set(e.pointerId, {
476
+ x: e.clientX,
477
+ y: e.clientY
478
+ });
479
+ e.currentTarget.setPointerCapture?.(e.pointerId);
480
+ const [first, second] = [...pointers.current.values()];
481
+ const distance = second ? Math.hypot(first.x - second.x, first.y - second.y) : null;
482
+ gesture.current = {
483
+ moved: false,
484
+ pinch: distance,
485
+ start: {
486
+ x: e.clientX,
487
+ y: e.clientY
488
+ }
489
+ };
490
+ e.currentTarget.focus({ preventScroll: true });
491
+ };
492
+ const onPointerMove = (e) => {
493
+ const last = pointers.current.get(e.pointerId);
494
+ if (!last || !gesture.current) return;
495
+ const now = {
496
+ x: e.clientX,
497
+ y: e.clientY
498
+ };
499
+ pointers.current.set(e.pointerId, now);
500
+ const v = live.current.view;
501
+ const s = {
502
+ width: hostRect().width,
503
+ height: hostRect().height
504
+ };
505
+ if (pointers.current.size === 2) {
506
+ const [a, b] = [...pointers.current.values()];
507
+ const d = Math.hypot(a.x - b.x, a.y - b.y);
508
+ if (gesture.current.pinch && d > 0) change({
509
+ ...v,
510
+ fov: v.fov * (gesture.current.pinch / d)
511
+ });
512
+ gesture.current.pinch = d;
513
+ gesture.current.moved = true;
514
+ return;
515
+ }
516
+ if (Math.hypot(now.x - gesture.current.start.x, now.y - gesture.current.start.y) > 4) gesture.current.moved = true;
517
+ if (!gesture.current.moved) return;
518
+ const per = degreesPerPixel(v, s);
519
+ change({
520
+ ...v,
521
+ yaw: v.yaw - (now.x - last.x) * per,
522
+ pitch: v.pitch + (now.y - last.y) * per
523
+ });
524
+ };
525
+ const onPointerUp = (e) => {
526
+ const g = gesture.current;
527
+ pointers.current.delete(e.pointerId);
528
+ if (pointers.current.size === 0) {
529
+ gesture.current = null;
530
+ if (g && !g.moved && live.current.onPick) {
531
+ const r = hostRect();
532
+ const s = {
533
+ width: r.width,
534
+ height: r.height
535
+ };
536
+ const x = e.clientX - r.left;
537
+ const y = e.clientY - r.top;
538
+ live.current.onPick(current.current.flat ? unprojectFlat(live.current.view, s, x, y) : unproject(live.current.view, s, x, y));
539
+ }
540
+ } else if (g) g.pinch = null;
541
+ };
542
+ React.useEffect(() => {
543
+ const el = box.current;
544
+ if (!el || !wheelZoom) return;
545
+ const onWheel = (e) => {
546
+ e.preventDefault();
547
+ const v = live.current.view;
548
+ change({
549
+ ...v,
550
+ fov: v.fov * Math.exp(e.deltaY * .0015)
551
+ });
552
+ };
553
+ el.addEventListener("wheel", onWheel, { passive: false });
554
+ return () => el.removeEventListener("wheel", onWheel);
555
+ }, [wheelZoom, change]);
556
+ const onKeyDown = (e) => {
557
+ const v = live.current.view;
558
+ const turn = v.fov / 12 * (e.shiftKey ? 3 : 1);
559
+ if (e.key === "ArrowLeft") change({
560
+ ...v,
561
+ yaw: v.yaw - turn
562
+ });
563
+ else if (e.key === "ArrowRight") change({
564
+ ...v,
565
+ yaw: v.yaw + turn
566
+ });
567
+ else if (e.key === "ArrowUp") change({
568
+ ...v,
569
+ pitch: v.pitch + turn
570
+ });
571
+ else if (e.key === "ArrowDown") change({
572
+ ...v,
573
+ pitch: v.pitch - turn
574
+ });
575
+ else if (e.key === "+" || e.key === "=") change({
576
+ ...v,
577
+ fov: v.fov * .8
578
+ });
579
+ else if (e.key === "-" || e.key === "_") change({
580
+ ...v,
581
+ fov: v.fov * 1.25
582
+ });
583
+ else if (e.key === "0") change(defaultView);
584
+ else return;
585
+ e.preventDefault();
586
+ };
587
+ const direction = describeView(view);
588
+ const [said, setSaid] = React.useState("");
589
+ const first = React.useRef(true);
590
+ React.useEffect(() => {
591
+ if (first.current) {
592
+ first.current = false;
593
+ return;
594
+ }
595
+ const t = setTimeout(() => setSaid(`${direction}, field of view ${Math.round(view.fov)}°`), STILL_MS);
596
+ return () => clearTimeout(t);
597
+ }, [direction, view.fov]);
598
+ const api = {
599
+ view,
600
+ size,
601
+ flat,
602
+ project: (yaw, pitch) => flat ? projectFlat(view, size, yaw, pitch) : project(view, size, yaw, pitch),
603
+ unproject: (x, y) => flat ? unprojectFlat(view, size, x, y) : unproject(view, size, x, y)
604
+ };
605
+ const slider = fovSlider ? /* @__PURE__ */ jsx(Slider, {
606
+ "aria-label": "Field of view",
607
+ value: Math.round(view.fov),
608
+ onChange: (fov) => change({
609
+ ...view,
610
+ fov
611
+ }),
612
+ min: minFov,
613
+ max: maxFov,
614
+ step: 1,
615
+ unit: "degree"
616
+ }) : null;
617
+ return /* @__PURE__ */ jsxs("div", {
618
+ className: cn("grid min-w-0 gap-2", className),
619
+ children: [
620
+ /* @__PURE__ */ jsxs("div", {
621
+ ref: boxRef,
622
+ role: "group",
623
+ "aria-label": label,
624
+ "aria-describedby": void 0,
625
+ tabIndex: 0,
626
+ onKeyDown,
627
+ onPointerDown,
628
+ onPointerMove,
629
+ onPointerUp,
630
+ onPointerCancel: onPointerUp,
631
+ className: "relative w-full cursor-grab touch-none overflow-hidden rounded-surface bg-surface-sunken select-none active:cursor-grabbing",
632
+ style: { aspectRatio: aspect },
633
+ children: [/* @__PURE__ */ jsx("canvas", {
634
+ ref: canvas,
635
+ role: "img",
636
+ "aria-label": `${label}. ${direction}, field of view ${Math.round(view.fov)}°`,
637
+ className: "absolute inset-0 size-full"
638
+ }, mode === "flat" ? "2d" : "gl"), overlay && size.width > 0 && /* @__PURE__ */ jsx("div", {
639
+ className: "pointer-events-none absolute inset-0",
640
+ children: overlay(api)
641
+ })]
642
+ }),
643
+ flat && /* @__PURE__ */ jsx("p", {
644
+ className: "type-body-sm text-muted-foreground",
645
+ children: "This browser cannot draw the 360 view, so the flat picture is shown. The controls work the same."
646
+ }),
647
+ slider,
648
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("span", {
649
+ role: "status",
650
+ children: said
651
+ }) })
652
+ ]
653
+ });
654
+ }
655
+ export { PanoramaViewer, clampView, degreesPerPixel, describeView, project, projectFlat, unproject, unprojectFlat, wrapYaw, yawDelta };
656
+
657
+ //# sourceMappingURL=panorama.js.map