react-zoom-pan-pinch 4.0.0 → 4.0.1

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 (82) hide show
  1. package/package.json +3 -2
  2. package/src/stories/assets/big-image.jpeg +0 -0
  3. package/src/stories/assets/map.jpg +0 -0
  4. package/src/stories/assets/medium-image.jpg +0 -0
  5. package/src/stories/assets/pin.svg +0 -1
  6. package/src/stories/assets/small-image.jpg +0 -0
  7. package/src/stories/assets/svg-example.svg +0 -14
  8. package/src/stories/docs/DocTable.tsx +0 -59
  9. package/src/stories/docs/HandlerCards.tsx +0 -102
  10. package/src/stories/docs/Introduction.stories.mdx +0 -135
  11. package/src/stories/docs/PropTable.tsx +0 -116
  12. package/src/stories/docs/docs.module.css +0 -370
  13. package/src/stories/docs/handlers.stories.mdx +0 -7
  14. package/src/stories/docs/handlers.tsx +0 -111
  15. package/src/stories/docs/props.stories.mdx +0 -11
  16. package/src/stories/docs/props.tsx +0 -571
  17. package/src/stories/examples/axis-lock/axis-lock.stories.mdx +0 -35
  18. package/src/stories/examples/axis-lock/example.tsx +0 -114
  19. package/src/stories/examples/bounds/bounds.data.tsx +0 -191
  20. package/src/stories/examples/bounds/bounds.stories.mdx +0 -99
  21. package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +0 -206
  22. package/src/stories/examples/cinema/cinema-data.tsx +0 -578
  23. package/src/stories/examples/cinema/cinema.stories.mdx +0 -30
  24. package/src/stories/examples/cinema/example.tsx +0 -378
  25. package/src/stories/examples/cinema/image.png +0 -0
  26. package/src/stories/examples/content/content.stories.mdx +0 -172
  27. package/src/stories/examples/content/mixed-content.data.tsx +0 -624
  28. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -34
  29. package/src/stories/examples/content-rerendering/example.tsx +0 -631
  30. package/src/stories/examples/controls/controls.stories.mdx +0 -120
  31. package/src/stories/examples/image/example.tsx +0 -149
  32. package/src/stories/examples/image/image.stories.mdx +0 -46
  33. package/src/stories/examples/image-annotations/example.tsx +0 -1442
  34. package/src/stories/examples/image-annotations/image-annotations.stories.mdx +0 -39
  35. package/src/stories/examples/image-responsive/example.tsx +0 -152
  36. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -51
  37. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -107
  38. package/src/stories/examples/initial-transform/example.tsx +0 -233
  39. package/src/stories/examples/initial-transform/initial-transform.stories.mdx +0 -37
  40. package/src/stories/examples/keep-scale/example.tsx +0 -882
  41. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -30
  42. package/src/stories/examples/keep-scale/map.stories.mdx +0 -28
  43. package/src/stories/examples/medical-viewer/chest-xray.tsx +0 -246
  44. package/src/stories/examples/medical-viewer/example.tsx +0 -690
  45. package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +0 -49
  46. package/src/stories/examples/mini-map/example.tsx +0 -122
  47. package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -26
  48. package/src/stories/examples/miro/example.tsx +0 -1573
  49. package/src/stories/examples/miro/miro.stories.mdx +0 -31
  50. package/src/stories/examples/padding/example.tsx +0 -147
  51. package/src/stories/examples/padding/padding.stories.mdx +0 -35
  52. package/src/stories/examples/product-card/example.tsx +0 -594
  53. package/src/stories/examples/product-card/product-card.stories.mdx +0 -29
  54. package/src/stories/examples/stadium/example.tsx +0 -1040
  55. package/src/stories/examples/stadium/stadium-data.ts +0 -224
  56. package/src/stories/examples/stadium/stadium.stories.mdx +0 -32
  57. package/src/stories/examples/stress/example.tsx +0 -59
  58. package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
  59. package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
  60. package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -95
  61. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
  62. package/src/stories/examples/text-selection/example.tsx +0 -221
  63. package/src/stories/examples/text-selection/text-selection.stories.mdx +0 -31
  64. package/src/stories/examples/velocity/example.tsx +0 -908
  65. package/src/stories/examples/velocity/velocity.stories.mdx +0 -35
  66. package/src/stories/examples/virtualize/example.tsx +0 -239
  67. package/src/stories/examples/virtualize/virtualize.stories.mdx +0 -84
  68. package/src/stories/examples/zoom-to-element/example.tsx +0 -219
  69. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -31
  70. package/src/stories/hooks/use-controls.stories.mdx +0 -86
  71. package/src/stories/hooks/use-transform-component.stories.mdx +0 -108
  72. package/src/stories/hooks/use-transform-context.stories.mdx +0 -92
  73. package/src/stories/hooks/use-transform-effect.stories.mdx +0 -114
  74. package/src/stories/hooks/use-transform-init.stories.mdx +0 -105
  75. package/src/stories/types/args.types.ts +0 -192
  76. package/src/stories/utils/args.utils.ts +0 -35
  77. package/src/stories/utils/bounds-overlay.tsx +0 -168
  78. package/src/stories/utils/code.utils.tsx +0 -22
  79. package/src/stories/utils/controls.utils.tsx +0 -347
  80. package/src/stories/utils/index.ts +0 -5
  81. package/src/stories/utils/styles.module.css +0 -223
  82. package/src/stories/utils/viewer.styles.ts +0 -34
@@ -1,908 +0,0 @@
1
- import React, { useCallback, useEffect, useRef, useState } from "react";
2
-
3
- import { TransformWrapper, TransformComponent } from "../../../components";
4
- import { Controls, normalizeArgs, viewerChrome } from "../../utils";
5
- import type { ReactZoomPanPinchRef } from "../../../models/context.model";
6
-
7
- const font = 'Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
8
-
9
- const CANVAS_W = 4200;
10
- const CANVAS_H = 2800;
11
-
12
- /* ── Procedural starfield ──────────────────────────────────── */
13
-
14
- function hash(i: number) {
15
- let n = i;
16
- // eslint-disable-next-line no-bitwise
17
- n = ((n >> 16) ^ n) * 0x45d9f3b;
18
- // eslint-disable-next-line no-bitwise
19
- n = ((n >> 16) ^ n) * 0x45d9f3b;
20
- // eslint-disable-next-line no-bitwise
21
- return ((n >> 16) ^ n) >>> 0;
22
- }
23
-
24
- interface Star {
25
- x: number;
26
- y: number;
27
- r: number;
28
- o: number;
29
- }
30
-
31
- const STARS: Star[] = Array.from({ length: 320 }, (_, i) => {
32
- const h = hash(i + 7);
33
- return {
34
- x: h % CANVAS_W,
35
- y: hash(i * 3 + 11) % CANVAS_H,
36
- r: 0.6 + (h % 30) / 20,
37
- o: 0.15 + (h % 60) / 100,
38
- };
39
- });
40
-
41
- interface Nebula {
42
- x: number;
43
- y: number;
44
- rx: number;
45
- ry: number;
46
- hue: number;
47
- sat: number;
48
- opacity: number;
49
- }
50
-
51
- const NEBULAE: Nebula[] = [
52
- { x: 700, y: 500, rx: 420, ry: 280, hue: 270, sat: 65, opacity: 0.18 },
53
- { x: 2100, y: 1400, rx: 500, ry: 320, hue: 340, sat: 60, opacity: 0.16 },
54
- { x: 3200, y: 700, rx: 360, ry: 440, hue: 190, sat: 55, opacity: 0.2 },
55
- { x: 1400, y: 2100, rx: 380, ry: 240, hue: 30, sat: 50, opacity: 0.14 },
56
- { x: 3500, y: 2200, rx: 340, ry: 280, hue: 210, sat: 58, opacity: 0.17 },
57
- { x: 500, y: 1800, rx: 280, ry: 320, hue: 150, sat: 45, opacity: 0.12 },
58
- ];
59
-
60
- interface CelestialObject {
61
- x: number;
62
- y: number;
63
- name: string;
64
- sub: string;
65
- hue: number;
66
- size: number;
67
- }
68
-
69
- const OBJECTS: CelestialObject[] = [
70
- {
71
- x: 700,
72
- y: 500,
73
- name: "Orion Nebula",
74
- sub: "M42 · Emission nebula",
75
- hue: 270,
76
- size: 14,
77
- },
78
- {
79
- x: 2100,
80
- y: 1400,
81
- name: "Carina Cluster",
82
- sub: "NGC 3372 · Star cluster",
83
- hue: 340,
84
- size: 16,
85
- },
86
- {
87
- x: 3200,
88
- y: 700,
89
- name: "Eagle Nebula",
90
- sub: "M16 · Pillars of Creation",
91
- hue: 190,
92
- size: 12,
93
- },
94
- {
95
- x: 1400,
96
- y: 2100,
97
- name: "Flame Nebula",
98
- sub: "NGC 2024 · H II region",
99
- hue: 30,
100
- size: 10,
101
- },
102
- {
103
- x: 3500,
104
- y: 2200,
105
- name: "Helix Nebula",
106
- sub: "NGC 7293 · Planetary",
107
- hue: 210,
108
- size: 13,
109
- },
110
- {
111
- x: 500,
112
- y: 1800,
113
- name: "Rosette Nebula",
114
- sub: "NGC 2237 · Emission",
115
- hue: 150,
116
- size: 11,
117
- },
118
- ];
119
-
120
- /* Constellation lines */
121
- const CONSTELLATIONS: [number, number, number, number][] = [
122
- [640, 460, 820, 380],
123
- [820, 380, 960, 520],
124
- [960, 520, 1050, 430],
125
- [2050, 1350, 2200, 1280],
126
- [2200, 1280, 2300, 1400],
127
- [3140, 650, 3300, 580],
128
- [3300, 580, 3380, 720],
129
- [3380, 720, 3280, 800],
130
- [1350, 2060, 1500, 1980],
131
- [1500, 1980, 1480, 2160],
132
- ];
133
-
134
- /* ── Planet (CSS sphere) ───────────────────────────────────── */
135
-
136
- function Planet(props: {
137
- x: number;
138
- y: number;
139
- size: number;
140
- hue: number;
141
- name: string;
142
- rings: boolean;
143
- }) {
144
- const { x, y, size, hue, name, rings } = props;
145
- return (
146
- <div style={{ position: "absolute", left: x - size, top: y - size }}>
147
- <div
148
- style={{
149
- width: size * 2,
150
- height: size * 2,
151
- borderRadius: "50%",
152
- background: `radial-gradient(
153
- circle at 35% 30%,
154
- hsl(${hue}, 55%, 72%) 0%,
155
- hsl(${hue}, 50%, 48%) 40%,
156
- hsl(${hue}, 45%, 22%) 80%,
157
- hsl(${hue}, 40%, 10%) 100%
158
- )`,
159
- boxShadow: `
160
- 0 0 ${size}px hsla(${hue}, 60%, 50%, 0.35),
161
- 0 0 ${size * 3}px hsla(${hue}, 60%, 40%, 0.15)
162
- `,
163
- position: "relative",
164
- }}
165
- >
166
- {rings && (
167
- <div
168
- style={{
169
- position: "absolute",
170
- left: -size * 0.7,
171
- top: "50%",
172
- width: size * 3.4,
173
- height: size * 0.7,
174
- marginTop: -size * 0.15,
175
- borderRadius: "50%",
176
- border: `2px solid hsla(${hue}, 40%, 60%, 0.3)`,
177
- background: `linear-gradient(
178
- 180deg,
179
- transparent 40%,
180
- hsla(${hue}, 35%, 55%, 0.08) 50%,
181
- transparent 60%
182
- )`,
183
- transform: "rotateX(70deg)",
184
- }}
185
- />
186
- )}
187
- </div>
188
- <div
189
- style={{
190
- textAlign: "center",
191
- marginTop: 10,
192
- fontSize: 11,
193
- fontWeight: 600,
194
- color: `hsla(${hue}, 50%, 80%, 0.7)`,
195
- letterSpacing: "0.05em",
196
- textTransform: "uppercase",
197
- fontFamily: font,
198
- }}
199
- >
200
- {name}
201
- </div>
202
- </div>
203
- );
204
- }
205
-
206
- /* ── Space canvas ──────────────────────────────────────────── */
207
-
208
- const SpaceCanvas = React.memo(function SpaceCanvas() {
209
- return (
210
- <div
211
- style={{
212
- position: "relative",
213
- width: CANVAS_W,
214
- height: CANVAS_H,
215
- background:
216
- "radial-gradient(ellipse 80% 60% at 40% 35%, #0c1229 0%, #060a18 50%, #020510 100%)",
217
- overflow: "hidden",
218
- }}
219
- >
220
- {/* Nebulae */}
221
- {NEBULAE.map((n) => (
222
- <div
223
- key={`nebula-${n.x}-${n.y}`}
224
- style={{
225
- position: "absolute",
226
- left: n.x - n.rx,
227
- top: n.y - n.ry,
228
- width: n.rx * 2,
229
- height: n.ry * 2,
230
- borderRadius: "50%",
231
- background: `radial-gradient(
232
- ellipse at center,
233
- hsla(${n.hue}, ${n.sat}%, 55%, ${n.opacity}) 0%,
234
- hsla(${n.hue}, ${n.sat}%, 40%, ${n.opacity * 0.5}) 35%,
235
- hsla(${n.hue}, ${n.sat}%, 30%, ${n.opacity * 0.15}) 65%,
236
- transparent 100%
237
- )`,
238
- filter: "blur(8px)",
239
- pointerEvents: "none",
240
- }}
241
- />
242
- ))}
243
-
244
- {/* Stars SVG */}
245
- <svg
246
- width={CANVAS_W}
247
- height={CANVAS_H}
248
- style={{ position: "absolute", inset: 0, pointerEvents: "none" }}
249
- aria-hidden
250
- >
251
- {STARS.map((s) => (
252
- <circle
253
- key={`star-${s.x}-${s.y}`}
254
- cx={s.x}
255
- cy={s.y}
256
- r={s.r}
257
- fill={`rgba(220, 230, 255, ${s.o})`}
258
- />
259
- ))}
260
-
261
- {/* Constellation lines + vertex stars */}
262
- {CONSTELLATIONS.map(([x1, y1, x2, y2]) => (
263
- <g key={`${x1}-${y1}-${x2}-${y2}`}>
264
- <line
265
- x1={x1}
266
- y1={y1}
267
- x2={x2}
268
- y2={y2}
269
- stroke="rgba(148, 163, 184, 0.18)"
270
- strokeWidth={0.8}
271
- strokeDasharray="4 6"
272
- />
273
- <circle cx={x1} cy={y1} r={2} fill="rgba(200, 215, 240, 0.35)" />
274
- <circle cx={x2} cy={y2} r={2} fill="rgba(200, 215, 240, 0.35)" />
275
- </g>
276
- ))}
277
- </svg>
278
-
279
- {/* Planets */}
280
- <Planet
281
- x={1700}
282
- y={800}
283
- size={48}
284
- hue={25}
285
- name="Kepler-442b"
286
- rings={false}
287
- />
288
- <Planet
289
- x={2900}
290
- y={1800}
291
- size={64}
292
- hue={220}
293
- name="Neptune Prime"
294
- rings
295
- />
296
- <Planet
297
- x={900}
298
- y={1300}
299
- size={32}
300
- hue={0}
301
- name="Proxima c"
302
- rings={false}
303
- />
304
-
305
- {/* Celestial object labels */}
306
- {OBJECTS.map((obj) => (
307
- <div
308
- key={obj.name}
309
- style={{ position: "absolute", left: obj.x + 20, top: obj.y - 12 }}
310
- >
311
- <div
312
- style={{
313
- display: "flex",
314
- alignItems: "center",
315
- gap: 8,
316
- marginBottom: 2,
317
- }}
318
- >
319
- <div
320
- style={{
321
- width: obj.size,
322
- height: obj.size,
323
- borderRadius: "50%",
324
- background: `radial-gradient(
325
- circle at 40% 35%,
326
- hsla(${obj.hue}, 80%, 80%, 0.9),
327
- hsla(${obj.hue}, 70%, 50%, 0.7)
328
- )`,
329
- boxShadow: `0 0 ${obj.size}px hsla(${obj.hue}, 60%, 60%, 0.4)`,
330
- flexShrink: 0,
331
- }}
332
- />
333
- <span
334
- style={{
335
- fontSize: 14,
336
- fontWeight: 700,
337
- color: "rgba(226, 232, 240, 0.9)",
338
- letterSpacing: "-0.01em",
339
- fontFamily: font,
340
- whiteSpace: "nowrap",
341
- }}
342
- >
343
- {obj.name}
344
- </span>
345
- </div>
346
- <span
347
- style={{
348
- fontSize: 11,
349
- color: "rgba(148, 163, 184, 0.6)",
350
- fontFamily: font,
351
- marginLeft: obj.size + 8,
352
- }}
353
- >
354
- {obj.sub}
355
- </span>
356
- </div>
357
- ))}
358
-
359
- {/* Center title */}
360
- <div
361
- style={{
362
- position: "absolute",
363
- left: "50%",
364
- top: "50%",
365
- transform: "translate(-50%, -50%)",
366
- textAlign: "center",
367
- pointerEvents: "none",
368
- }}
369
- >
370
- <div
371
- style={{
372
- fontSize: 72,
373
- fontWeight: 900,
374
- letterSpacing: "0.2em",
375
- fontFamily: font,
376
- userSelect: "none",
377
- color: "transparent",
378
- background:
379
- "linear-gradient(180deg, rgba(148, 163, 184, 0.18) 0%, rgba(100, 116, 139, 0.08) 100%)",
380
- WebkitBackgroundClip: "text",
381
- WebkitTextFillColor: "transparent",
382
- textShadow: "0 0 60px rgba(56, 189, 248, 0.06)",
383
- }}
384
- >
385
- EXPLORE
386
- </div>
387
- <div
388
- style={{
389
- fontSize: 12,
390
- fontWeight: 500,
391
- letterSpacing: "0.25em",
392
- color: "rgba(148, 163, 184, 0.18)",
393
- textTransform: "uppercase",
394
- marginTop: 4,
395
- }}
396
- >
397
- Deep space explorer
398
- </div>
399
- </div>
400
- </div>
401
- );
402
- });
403
-
404
- /* ── Velocity gauge (DOM-driven, no re-renders) ──────────── */
405
-
406
- function VelocityGauge() {
407
- const barRef = useRef<HTMLDivElement>(null);
408
- const labelRef = useRef<HTMLSpanElement>(null);
409
- const dotRef = useRef<HTMLDivElement>(null);
410
- const lastRef = useRef({ x: 0, y: 0, t: 0 });
411
- const speedRef = useRef(0);
412
- const rafRef = useRef(0);
413
-
414
- const updateDOM = useCallback((v: number) => {
415
- const pct = Math.min(v / 12, 1) * 100;
416
- if (barRef.current) {
417
- barRef.current.style.width = `${pct}%`;
418
- barRef.current.style.opacity = pct > 0 ? "1" : "0.3";
419
- }
420
- if (labelRef.current) {
421
- labelRef.current.textContent = `${Math.round(v * 10) / 10}`;
422
- }
423
- if (dotRef.current) {
424
- dotRef.current.style.boxShadow =
425
- v > 2
426
- ? "0 0 8px rgba(56, 189, 248, 0.6)"
427
- : "0 0 4px rgba(56, 189, 248, 0.2)";
428
- dotRef.current.style.background =
429
- v > 2 ? "rgba(56, 189, 248, 0.9)" : "rgba(56, 189, 248, 0.4)";
430
- }
431
- }, []);
432
-
433
- const decay = useCallback(() => {
434
- speedRef.current *= 0.92;
435
- if (speedRef.current < 0.5) speedRef.current = 0;
436
- updateDOM(speedRef.current);
437
- if (speedRef.current > 0) {
438
- rafRef.current = requestAnimationFrame(decay);
439
- }
440
- }, [updateDOM]);
441
-
442
- useEffect(() => {
443
- return () => cancelAnimationFrame(rafRef.current);
444
- }, []);
445
-
446
- const onTransform = useCallback(
447
- (
448
- _ref: ReactZoomPanPinchRef,
449
- st: { positionX: number; positionY: number },
450
- ) => {
451
- const now = performance.now();
452
- const dt = now - lastRef.current.t;
453
- if (dt > 0 && lastRef.current.t > 0) {
454
- const dx = st.positionX - lastRef.current.x;
455
- const dy = st.positionY - lastRef.current.y;
456
- speedRef.current =
457
- (Math.sqrt(dx * dx + dy * dy) / Math.max(dt, 1)) * 16;
458
- }
459
- lastRef.current = { x: st.positionX, y: st.positionY, t: now };
460
- cancelAnimationFrame(rafRef.current);
461
- updateDOM(speedRef.current);
462
- rafRef.current = requestAnimationFrame(decay);
463
- },
464
- [decay, updateDOM],
465
- );
466
-
467
- return { onTransform, barRef, labelRef, dotRef };
468
- }
469
-
470
- /* ── Toggle pill ───────────────────────────────────────────── */
471
-
472
- function TogglePill(props: { on: boolean; onToggle: (v: boolean) => void }) {
473
- const { on, onToggle } = props;
474
-
475
- return (
476
- <div
477
- style={{
478
- display: "inline-flex",
479
- borderRadius: 12,
480
- background: "rgba(15, 23, 42, 0.85)",
481
- border: "1px solid rgba(255,255,255,0.12)",
482
- backdropFilter: "blur(12px)",
483
- padding: 4,
484
- gap: 2,
485
- fontFamily: font,
486
- }}
487
- >
488
- <button
489
- type="button"
490
- onClick={() => onToggle(true)}
491
- style={{
492
- padding: "8px 18px",
493
- borderRadius: 9,
494
- border: "none",
495
- fontSize: 13,
496
- fontWeight: 700,
497
- fontFamily: font,
498
- cursor: "pointer",
499
- transition: "all 0.2s ease",
500
- background: on
501
- ? "linear-gradient(135deg, rgba(16, 185, 129, 0.35), rgba(52, 211, 153, 0.2))"
502
- : "transparent",
503
- color: on ? "#6ee7b7" : "rgba(203, 213, 225, 0.7)",
504
- boxShadow: on
505
- ? "0 0 0 1px rgba(52, 211, 153, 0.4) inset, 0 2px 8px rgba(16, 185, 129, 0.2)"
506
- : "none",
507
- display: "flex",
508
- alignItems: "center",
509
- gap: 7,
510
- }}
511
- >
512
- <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
513
- <path
514
- d="M2 7C2 7 4 3.5 7 3.5S12 7 12 7"
515
- stroke="currentColor"
516
- strokeWidth="1.5"
517
- strokeLinecap="round"
518
- />
519
- <path
520
- d="M3 9.5C4 10.5 5.5 11 7 11S10 10.5 11 9.5"
521
- stroke="currentColor"
522
- strokeWidth="1.2"
523
- strokeLinecap="round"
524
- opacity="0.5"
525
- />
526
- </svg>
527
- Momentum
528
- </button>
529
- <button
530
- type="button"
531
- onClick={() => onToggle(false)}
532
- style={{
533
- padding: "8px 18px",
534
- borderRadius: 9,
535
- border: "none",
536
- fontSize: 13,
537
- fontWeight: 700,
538
- fontFamily: font,
539
- cursor: "pointer",
540
- transition: "all 0.2s ease",
541
- background: !on
542
- ? "linear-gradient(135deg, rgba(239, 68, 68, 0.3), rgba(248, 113, 113, 0.18))"
543
- : "transparent",
544
- color: !on ? "#fca5a5" : "rgba(203, 213, 225, 0.7)",
545
- boxShadow: !on
546
- ? "0 0 0 1px rgba(248, 113, 113, 0.4) inset, 0 2px 8px rgba(239, 68, 68, 0.15)"
547
- : "none",
548
- display: "flex",
549
- alignItems: "center",
550
- gap: 7,
551
- }}
552
- >
553
- <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
554
- <rect
555
- x="3"
556
- y="3"
557
- width="8"
558
- height="8"
559
- rx="2"
560
- stroke="currentColor"
561
- strokeWidth="1.5"
562
- />
563
- <path
564
- d="M6 6L8 8M8 6L6 8"
565
- stroke="currentColor"
566
- strokeWidth="1.3"
567
- strokeLinecap="round"
568
- />
569
- </svg>
570
- Locked
571
- </button>
572
- </div>
573
- );
574
- }
575
-
576
- /* ── Sensitivity slider ────────────────────────────────────── */
577
-
578
- function ParamSlider(props: {
579
- label: string;
580
- value: number;
581
- min: number;
582
- max: number;
583
- step: number;
584
- onChange: (v: number) => void;
585
- display: (v: number) => string;
586
- }) {
587
- const { label, value, min, max, step, onChange, display } = props;
588
- const inputId = `param-slider-${label.toLowerCase().replace(/\s+/g, "-")}`;
589
- return (
590
- <label
591
- htmlFor={inputId}
592
- style={{
593
- display: "flex",
594
- alignItems: "center",
595
- gap: 10,
596
- fontSize: 12,
597
- fontWeight: 700,
598
- color: "rgba(226, 232, 240, 0.85)",
599
- fontFamily: font,
600
- cursor: "default",
601
- }}
602
- >
603
- {label}
604
- <input
605
- id={inputId}
606
- type="range"
607
- min={min}
608
- max={max}
609
- step={step}
610
- value={value}
611
- onChange={(e) => onChange(Number(e.target.value))}
612
- style={{
613
- width: 100,
614
- accentColor: "#38bdf8",
615
- cursor: "pointer",
616
- }}
617
- />
618
- <span
619
- style={{
620
- fontSize: 11,
621
- color: "#e2e8f0",
622
- fontVariantNumeric: "tabular-nums",
623
- fontWeight: 600,
624
- minWidth: 32,
625
- }}
626
- >
627
- {display(value)}
628
- </span>
629
- </label>
630
- );
631
- }
632
-
633
- /* ── Main ──────────────────────────────────────────────────── */
634
-
635
- const viewer: React.CSSProperties = {
636
- ...viewerChrome,
637
- width: "100%",
638
- height: "clamp(480px, calc(100vh - 320px), 720px)",
639
- };
640
-
641
- export const Example: React.FC<Record<string, unknown>> = (args) => {
642
- const normalized = normalizeArgs(args);
643
- const [inertiaOn, setInertiaOn] = useState(true);
644
- const [sensitivity, setSensitivity] = useState(1);
645
- const [friction, setFriction] = useState(0.93);
646
-
647
- const velocityAnimation = {
648
- ...(normalized.velocityAnimation ?? {}),
649
- disabled: !inertiaOn,
650
- sensitivityMouse: sensitivity,
651
- inertia: friction,
652
- };
653
-
654
- const gauge = VelocityGauge();
655
-
656
- return (
657
- <div style={{ fontFamily: font, maxWidth: 960 }}>
658
- {/* ── Top control strip ────────────────────────────── */}
659
- <div
660
- style={{
661
- display: "flex",
662
- flexWrap: "wrap",
663
- gap: 14,
664
- marginBottom: 14,
665
- alignItems: "center",
666
- }}
667
- >
668
- <TogglePill on={inertiaOn} onToggle={setInertiaOn} />
669
-
670
- <div
671
- style={{
672
- display: "flex",
673
- flexWrap: "wrap",
674
- gap: 16,
675
- alignItems: "center",
676
- padding: "8px 16px",
677
- borderRadius: 12,
678
- background: "rgba(15, 23, 42, 0.85)",
679
- border: "1px solid rgba(255,255,255,0.12)",
680
- }}
681
- >
682
- <ParamSlider
683
- label="Sensitivity"
684
- value={sensitivity}
685
- min={0.2}
686
- max={3}
687
- step={0.1}
688
- onChange={setSensitivity}
689
- display={(v) => `${v.toFixed(1)}×`}
690
- />
691
- <ParamSlider
692
- label="Friction"
693
- value={friction}
694
- min={0.8}
695
- max={0.99}
696
- step={0.01}
697
- onChange={setFriction}
698
- display={(v) => `${(v * 100).toFixed(0)}%`}
699
- />
700
- </div>
701
- </div>
702
-
703
- {/* ── Viewer ───────────────────────────────────────── */}
704
- <div style={{ position: "relative" }}>
705
- <TransformWrapper
706
- {...normalized}
707
- centerOnInit
708
- limitToBounds={false}
709
- velocityAnimation={velocityAnimation}
710
- doubleClick={{ ...normalized.doubleClick, disabled: true }}
711
- onTransform={gauge.onTransform}
712
- >
713
- {(utils) => (
714
- <div style={{ position: "relative" }}>
715
- <Controls {...utils} />
716
-
717
- {/* Velocity HUD */}
718
- <div
719
- style={{
720
- position: "absolute",
721
- bottom: 14,
722
- right: 14,
723
- zIndex: 4,
724
- display: "flex",
725
- alignItems: "center",
726
- gap: 8,
727
- padding: "7px 14px",
728
- borderRadius: 10,
729
- background: "rgba(2, 6, 23, 0.75)",
730
- border: "1px solid rgba(255,255,255,0.08)",
731
- backdropFilter: "blur(8px)",
732
- fontFamily: font,
733
- fontSize: 12,
734
- fontWeight: 600,
735
- color: "rgba(148, 163, 184, 0.8)",
736
- fontVariantNumeric: "tabular-nums",
737
- }}
738
- >
739
- <div
740
- ref={gauge.dotRef}
741
- style={{
742
- width: 8,
743
- height: 8,
744
- borderRadius: "50%",
745
- background: "rgba(56, 189, 248, 0.4)",
746
- transition: "background 0.15s, box-shadow 0.15s",
747
- flexShrink: 0,
748
- }}
749
- />
750
- <span style={{ color: "rgba(226, 232, 240, 0.65)" }}>vel</span>
751
- <span
752
- ref={gauge.labelRef}
753
- style={{
754
- color: "rgba(226, 232, 240, 0.9)",
755
- minWidth: 24,
756
- textAlign: "right",
757
- }}
758
- >
759
- 0
760
- </span>
761
- <div
762
- style={{
763
- width: 60,
764
- height: 4,
765
- borderRadius: 2,
766
- background: "rgba(255,255,255,0.06)",
767
- overflow: "hidden",
768
- }}
769
- >
770
- <div
771
- ref={gauge.barRef}
772
- style={{
773
- height: "100%",
774
- width: "0%",
775
- borderRadius: 2,
776
- background:
777
- "linear-gradient(90deg, rgba(56, 189, 248, 0.7), rgba(139, 92, 246, 0.7))",
778
- transition: "width 0.08s linear",
779
- }}
780
- />
781
- </div>
782
- </div>
783
-
784
- <TransformComponent
785
- wrapperStyle={viewer}
786
- contentStyle={{ width: CANVAS_W, height: CANVAS_H }}
787
- >
788
- <SpaceCanvas />
789
- </TransformComponent>
790
- </div>
791
- )}
792
- </TransformWrapper>
793
-
794
- {/* Instruction overlay */}
795
- <div
796
- style={{
797
- position: "absolute",
798
- bottom: 56,
799
- left: "50%",
800
- transform: "translateX(-50%)",
801
- padding: "8px 20px",
802
- borderRadius: 999,
803
- background: "rgba(2, 6, 23, 0.7)",
804
- border: "1px solid rgba(255,255,255,0.06)",
805
- backdropFilter: "blur(8px)",
806
- fontSize: 12,
807
- fontWeight: 500,
808
- color: "rgba(148, 163, 184, 0.7)",
809
- fontFamily: font,
810
- pointerEvents: "none",
811
- whiteSpace: "nowrap",
812
- zIndex: 3,
813
- }}
814
- >
815
- Drag quickly and{" "}
816
- <strong style={{ color: "rgba(226, 232, 240, 0.85)" }}>
817
- release
818
- </strong>{" "}
819
- to feel the momentum
820
- </div>
821
- </div>
822
-
823
- {/* ── API reference ────────────────────────────────── */}
824
- <div
825
- style={{
826
- marginTop: 16,
827
- padding: "16px 20px",
828
- borderRadius: 14,
829
- background: "rgba(15, 23, 42, 0.7)",
830
- border: "1px solid rgba(56, 189, 248, 0.15)",
831
- fontFamily: font,
832
- display: "flex",
833
- alignItems: "flex-start",
834
- gap: 14,
835
- }}
836
- >
837
- <span
838
- style={{
839
- flexShrink: 0,
840
- width: 28,
841
- height: 28,
842
- borderRadius: 8,
843
- background: "linear-gradient(135deg, #0ea5e9, #6366f1)",
844
- display: "flex",
845
- alignItems: "center",
846
- justifyContent: "center",
847
- fontSize: 13,
848
- fontWeight: 800,
849
- color: "#fff",
850
- marginTop: 2,
851
- }}
852
- >
853
- v
854
- </span>
855
- <div
856
- style={{
857
- display: "flex",
858
- flexDirection: "column",
859
- gap: 10,
860
- fontSize: 13,
861
- lineHeight: 1.55,
862
- color: "#94a3b8",
863
- }}
864
- >
865
- {[
866
- {
867
- prop: "velocityAnimation.disabled",
868
- desc: "Enable or disable post-release momentum",
869
- accent: "#a78bfa",
870
- },
871
- {
872
- prop: "sensitivityMouse",
873
- desc: "How much initial velocity is captured from gesture speed",
874
- accent: "#38bdf8",
875
- },
876
- {
877
- prop: "inertia",
878
- desc: "Decay coefficient — higher values produce a longer, smoother glide",
879
- accent: "#38bdf8",
880
- },
881
- ].map((item) => (
882
- <div
883
- key={item.prop}
884
- style={{ display: "flex", alignItems: "baseline", gap: 8 }}
885
- >
886
- <code
887
- style={{
888
- flexShrink: 0,
889
- padding: "2px 8px",
890
- borderRadius: 5,
891
- background: `${item.accent}15`,
892
- border: `1px solid ${item.accent}30`,
893
- fontSize: 11,
894
- fontWeight: 600,
895
- fontFamily: "'SF Mono', ui-monospace, monospace",
896
- color: item.accent,
897
- }}
898
- >
899
- {item.prop}
900
- </code>
901
- <span style={{ color: "#cbd5e1" }}>{item.desc}</span>
902
- </div>
903
- ))}
904
- </div>
905
- </div>
906
- </div>
907
- );
908
- };