react-zoom-pan-pinch 3.6.1 → 4.0.0

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 (139) hide show
  1. package/dist/index.cjs.js +770 -277
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +116 -22
  4. package/dist/index.esm.js +766 -269
  5. package/dist/index.esm.js.map +1 -1
  6. package/package.json +73 -60
  7. package/src/components/index.ts +5 -0
  8. package/src/components/keep-scale/keep-scale.tsx +28 -0
  9. package/src/components/mini-map/mini-map.tsx +292 -0
  10. package/src/components/mini-map/use-resize.hook.ts +74 -0
  11. package/src/components/transform-component/transform-component.module.css +43 -0
  12. package/src/components/transform-component/transform-component.tsx +96 -0
  13. package/src/components/transform-wrapper/transform-wrapper.tsx +39 -0
  14. package/src/components/virtualize/virtualize.tsx +133 -0
  15. package/src/components/virtualize/virtualize.utils.ts +104 -0
  16. package/src/constants/state.constants.ts +99 -0
  17. package/src/core/animations/animations.constants.ts +78 -0
  18. package/src/core/animations/animations.utils.ts +115 -0
  19. package/src/core/bounds/bounds.types.ts +8 -0
  20. package/src/core/bounds/bounds.utils.ts +226 -0
  21. package/src/core/double-click/double-click.logic.ts +127 -0
  22. package/src/core/handlers/handlers.logic.ts +122 -0
  23. package/src/core/handlers/handlers.utils.ts +243 -0
  24. package/src/core/instance.core.ts +704 -0
  25. package/src/core/pan/panning.logic.ts +122 -0
  26. package/src/core/pan/panning.utils.ts +216 -0
  27. package/src/core/pan/velocity.logic.ts +187 -0
  28. package/src/core/pan/velocity.utils.ts +83 -0
  29. package/src/core/pinch/pinch.logic.ts +139 -0
  30. package/src/core/pinch/pinch.utils.ts +95 -0
  31. package/src/core/wheel/wheel.logic.ts +161 -0
  32. package/src/core/wheel/wheel.utils.ts +157 -0
  33. package/src/core/zoom/zoom.logic.ts +71 -0
  34. package/src/core/zoom/zoom.utils.ts +62 -0
  35. package/src/hooks/index.ts +5 -0
  36. package/src/hooks/use-controls.tsx +9 -0
  37. package/src/hooks/use-transform-component.tsx +30 -0
  38. package/src/hooks/use-transform-context.tsx +13 -0
  39. package/src/hooks/use-transform-effect.tsx +22 -0
  40. package/src/hooks/use-transform-init.tsx +28 -0
  41. package/src/hooks/use-zoom-pan-pinch.tsx +48 -0
  42. package/src/index.ts +6 -0
  43. package/src/models/calculations.model.ts +34 -0
  44. package/src/models/context.model.ts +218 -0
  45. package/src/models/helpers.model.ts +15 -0
  46. package/src/models/index.ts +3 -0
  47. package/src/react-app-env.d.ts +1 -0
  48. package/src/stories/assets/big-image.jpeg +0 -0
  49. package/src/stories/assets/map.jpg +0 -0
  50. package/src/stories/assets/medium-image.jpg +0 -0
  51. package/src/stories/assets/pin.svg +1 -0
  52. package/src/stories/assets/small-image.jpg +0 -0
  53. package/src/stories/assets/svg-example.svg +14 -0
  54. package/src/stories/docs/DocTable.tsx +59 -0
  55. package/src/stories/docs/HandlerCards.tsx +102 -0
  56. package/src/stories/docs/Introduction.stories.mdx +135 -0
  57. package/src/stories/docs/PropTable.tsx +116 -0
  58. package/src/stories/docs/docs.module.css +370 -0
  59. package/src/stories/docs/handlers.stories.mdx +7 -0
  60. package/src/stories/docs/handlers.tsx +111 -0
  61. package/src/stories/docs/props.stories.mdx +11 -0
  62. package/src/stories/docs/props.tsx +571 -0
  63. package/src/stories/examples/axis-lock/axis-lock.stories.mdx +35 -0
  64. package/src/stories/examples/axis-lock/example.tsx +114 -0
  65. package/src/stories/examples/bounds/bounds.data.tsx +191 -0
  66. package/src/stories/examples/bounds/bounds.stories.mdx +99 -0
  67. package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +206 -0
  68. package/src/stories/examples/cinema/cinema-data.tsx +578 -0
  69. package/src/stories/examples/cinema/cinema.stories.mdx +30 -0
  70. package/src/stories/examples/cinema/example.tsx +378 -0
  71. package/src/stories/examples/cinema/image.png +0 -0
  72. package/src/stories/examples/content/content.stories.mdx +172 -0
  73. package/src/stories/examples/content/mixed-content.data.tsx +624 -0
  74. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +34 -0
  75. package/src/stories/examples/content-rerendering/example.tsx +631 -0
  76. package/src/stories/examples/controls/controls.stories.mdx +120 -0
  77. package/src/stories/examples/image/example.tsx +149 -0
  78. package/src/stories/examples/image/image.stories.mdx +46 -0
  79. package/src/stories/examples/image-annotations/example.tsx +1442 -0
  80. package/src/stories/examples/image-annotations/image-annotations.stories.mdx +39 -0
  81. package/src/stories/examples/image-responsive/example.tsx +152 -0
  82. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +51 -0
  83. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +107 -0
  84. package/src/stories/examples/initial-transform/example.tsx +233 -0
  85. package/src/stories/examples/initial-transform/initial-transform.stories.mdx +37 -0
  86. package/src/stories/examples/keep-scale/example.tsx +882 -0
  87. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +30 -0
  88. package/src/stories/examples/keep-scale/map.stories.mdx +28 -0
  89. package/src/stories/examples/medical-viewer/chest-xray.tsx +246 -0
  90. package/src/stories/examples/medical-viewer/example.tsx +690 -0
  91. package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +49 -0
  92. package/src/stories/examples/mini-map/example.tsx +122 -0
  93. package/src/stories/examples/mini-map/mini-map.stories.mdx +26 -0
  94. package/src/stories/examples/miro/example.tsx +1573 -0
  95. package/src/stories/examples/miro/miro.stories.mdx +31 -0
  96. package/src/stories/examples/padding/example.tsx +147 -0
  97. package/src/stories/examples/padding/padding.stories.mdx +35 -0
  98. package/src/stories/examples/product-card/example.tsx +594 -0
  99. package/src/stories/examples/product-card/product-card.stories.mdx +29 -0
  100. package/src/stories/examples/stadium/example.tsx +1040 -0
  101. package/src/stories/examples/stadium/stadium-data.ts +224 -0
  102. package/src/stories/examples/stadium/stadium.stories.mdx +32 -0
  103. package/src/stories/examples/stress/example.tsx +59 -0
  104. package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
  105. package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
  106. package/src/stories/examples/svg-zoom-to-element/example.tsx +95 -0
  107. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
  108. package/src/stories/examples/text-selection/example.tsx +221 -0
  109. package/src/stories/examples/text-selection/text-selection.stories.mdx +31 -0
  110. package/src/stories/examples/velocity/example.tsx +908 -0
  111. package/src/stories/examples/velocity/velocity.stories.mdx +35 -0
  112. package/src/stories/examples/virtualize/example.tsx +239 -0
  113. package/src/stories/examples/virtualize/virtualize.stories.mdx +84 -0
  114. package/src/stories/examples/zoom-to-element/example.tsx +219 -0
  115. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +31 -0
  116. package/src/stories/hooks/use-controls.stories.mdx +86 -0
  117. package/src/stories/hooks/use-transform-component.stories.mdx +108 -0
  118. package/src/stories/hooks/use-transform-context.stories.mdx +92 -0
  119. package/src/stories/hooks/use-transform-effect.stories.mdx +114 -0
  120. package/src/stories/hooks/use-transform-init.stories.mdx +105 -0
  121. package/src/stories/types/args.types.ts +192 -0
  122. package/src/stories/utils/args.utils.ts +35 -0
  123. package/src/stories/utils/bounds-overlay.tsx +168 -0
  124. package/src/stories/utils/code.utils.tsx +22 -0
  125. package/src/stories/utils/controls.utils.tsx +347 -0
  126. package/src/stories/utils/index.ts +5 -0
  127. package/src/stories/utils/styles.module.css +223 -0
  128. package/src/stories/utils/viewer.styles.ts +34 -0
  129. package/src/styles.css +8 -0
  130. package/src/typings.d.ts +21 -0
  131. package/src/utils/calculations.utils.ts +16 -0
  132. package/src/utils/callback.utils.ts +11 -0
  133. package/src/utils/context.utils.ts +49 -0
  134. package/src/utils/event.utils.ts +38 -0
  135. package/src/utils/helpers.utils.ts +22 -0
  136. package/src/utils/index.ts +8 -0
  137. package/src/utils/ref.utils.ts +32 -0
  138. package/src/utils/state.utils.ts +77 -0
  139. package/src/utils/styles.utils.ts +49 -0
@@ -0,0 +1,168 @@
1
+ import React, { useCallback } from "react";
2
+
3
+ import { useTransformComponent } from "../../hooks/use-transform-component";
4
+
5
+ const THRESHOLD = 30;
6
+ const FOG_MAX = 60;
7
+ const FOG_COLOR = "10, 10, 18";
8
+
9
+ const GRADIENT_DIR: Record<string, string> = {
10
+ left: "to right",
11
+ right: "to left",
12
+ top: "to bottom",
13
+ bottom: "to top",
14
+ };
15
+
16
+ function FogBar({
17
+ side,
18
+ intensity,
19
+ }: {
20
+ side: "left" | "right" | "top" | "bottom";
21
+ intensity: number;
22
+ }) {
23
+ if (intensity <= 0) return null;
24
+
25
+ const depth = Math.round(FOG_MAX * intensity);
26
+ const isHorizontal = side === "left" || side === "right";
27
+
28
+ const gradientDir = GRADIENT_DIR[side];
29
+
30
+ const style: React.CSSProperties = {
31
+ position: "absolute",
32
+ background: `linear-gradient(${gradientDir}, rgba(${FOG_COLOR}, ${Math.min(0.97, intensity * 0.97)}) 0%, rgba(${FOG_COLOR}, ${Math.min(0.6, intensity * 0.6)}) 50%, rgba(${FOG_COLOR}, 0) 100%)`,
33
+ pointerEvents: "none",
34
+ };
35
+
36
+ if (isHorizontal) {
37
+ Object.assign(style, {
38
+ top: 0,
39
+ bottom: 0,
40
+ [side]: 0,
41
+ width: depth,
42
+ });
43
+ } else {
44
+ Object.assign(style, {
45
+ left: 0,
46
+ right: 0,
47
+ [side]: 0,
48
+ height: depth,
49
+ });
50
+ }
51
+
52
+ return <div style={style} />;
53
+ }
54
+
55
+ function EdgeLabel({
56
+ side,
57
+ intensity,
58
+ }: {
59
+ side: "left" | "right" | "top" | "bottom";
60
+ intensity: number;
61
+ }) {
62
+ if (intensity < 0.3) return null;
63
+
64
+ const opacity = Math.min(1, (intensity - 0.3) / 0.7);
65
+ const isVertical = side === "left" || side === "right";
66
+
67
+ const positionStyle: React.CSSProperties = isVertical
68
+ ? {
69
+ top: "50%",
70
+ [side]: `${12 + (1 - Math.min(1, intensity)) * 20}px`,
71
+ transform: `translateY(-50%) rotate(${side === "left" ? -90 : 90}deg)`,
72
+ }
73
+ : {
74
+ left: "50%",
75
+ [side]: `${12 + (1 - Math.min(1, intensity)) * 20}px`,
76
+ transform: "translateX(-50%)",
77
+ };
78
+
79
+ return (
80
+ <span
81
+ style={{
82
+ position: "absolute",
83
+ color: `rgba(255, 100, 100, ${opacity * 0.8})`,
84
+ fontSize: "13px",
85
+ fontWeight: 700,
86
+ letterSpacing: "4px",
87
+ textTransform: "uppercase",
88
+ fontFamily: "system-ui, -apple-system, sans-serif",
89
+ userSelect: "none",
90
+ pointerEvents: "none",
91
+ transition: "opacity 0.15s ease-out",
92
+ textShadow: `0 0 12px rgba(255, 80, 80, ${opacity * 0.5})`,
93
+ ...positionStyle,
94
+ }}
95
+ >
96
+ Limit
97
+ </span>
98
+ );
99
+ }
100
+
101
+ interface BoundsOverlayProps {
102
+ minX: number;
103
+ maxX: number;
104
+ minY: number;
105
+ maxY: number;
106
+ wrapperWidth: number;
107
+ wrapperHeight: number;
108
+ }
109
+
110
+ export function BoundsOverlay({
111
+ minX,
112
+ maxX,
113
+ minY,
114
+ maxY,
115
+ wrapperWidth,
116
+ wrapperHeight,
117
+ }: BoundsOverlayProps) {
118
+ const computeEdges = useCallback(
119
+ (state: {
120
+ state: { positionX: number; positionY: number; scale: number };
121
+ }) => {
122
+ const { positionX, positionY, scale } = state.state;
123
+
124
+ // Match the library's scaled bounds (see calculateBounds in bounds.utils.ts)
125
+ const sMinX = wrapperWidth * (1 - scale) + minX * scale;
126
+ const sMaxX = maxX * scale;
127
+ const sMinY = wrapperHeight * (1 - scale) + minY * scale;
128
+ const sMaxY = maxY * scale;
129
+
130
+ const rangeX = sMaxX - sMinX || 1;
131
+ const rangeY = sMaxY - sMinY || 1;
132
+ const t = THRESHOLD;
133
+
134
+ return {
135
+ left: Math.max(0, 1 - (sMaxX - positionX) / Math.min(t, rangeX)),
136
+ right: Math.max(0, 1 - (positionX - sMinX) / Math.min(t, rangeX)),
137
+ top: Math.max(0, 1 - (sMaxY - positionY) / Math.min(t, rangeY)),
138
+ bottom: Math.max(0, 1 - (positionY - sMinY) / Math.min(t, rangeY)),
139
+ };
140
+ },
141
+ [minX, maxX, minY, maxY, wrapperWidth, wrapperHeight],
142
+ );
143
+
144
+ const edges = useTransformComponent(computeEdges);
145
+
146
+ return (
147
+ <div
148
+ style={{
149
+ position: "absolute",
150
+ inset: 0,
151
+ pointerEvents: "none",
152
+ overflow: "hidden",
153
+ borderRadius: "10px",
154
+ zIndex: 10,
155
+ }}
156
+ >
157
+ <FogBar side="left" intensity={edges.left} />
158
+ <FogBar side="right" intensity={edges.right} />
159
+ <FogBar side="top" intensity={edges.top} />
160
+ <FogBar side="bottom" intensity={edges.bottom} />
161
+
162
+ <EdgeLabel side="left" intensity={edges.left} />
163
+ <EdgeLabel side="right" intensity={edges.right} />
164
+ <EdgeLabel side="top" intensity={edges.top} />
165
+ <EdgeLabel side="bottom" intensity={edges.bottom} />
166
+ </div>
167
+ );
168
+ }
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+
3
+ type Props = { code: string };
4
+
5
+ export const Code: React.FC<Props> = ({ code }: Props) => (
6
+ <code
7
+ style={{
8
+ display: "inline",
9
+ padding: "2px 7px",
10
+ borderRadius: 5,
11
+ background: "rgba(30, 30, 50, 0.7)",
12
+ border: "1px solid rgba(255,255,255,0.08)",
13
+ fontFamily: "'SF Mono', 'Fira Code', 'Cascadia Code', monospace",
14
+ fontSize: 12,
15
+ color: "#e2e8f0",
16
+ whiteSpace: "pre-wrap",
17
+ wordBreak: "break-word",
18
+ }}
19
+ >
20
+ {code}
21
+ </code>
22
+ );
@@ -0,0 +1,347 @@
1
+ import React from "react";
2
+
3
+ import { ReactZoomPanPinchContentRef } from "../../models/context.model";
4
+
5
+ import styles from "./styles.module.css";
6
+
7
+ /* ── Built-in icons ─────────────────────────────────────────── */
8
+
9
+ const ZoomInIcon = () => (
10
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
11
+ <circle cx="7" cy="7" r="5.5" stroke="currentColor" strokeWidth="1.5" />
12
+ <path
13
+ d="M11 11L14 14"
14
+ stroke="currentColor"
15
+ strokeWidth="1.5"
16
+ strokeLinecap="round"
17
+ />
18
+ <path
19
+ d="M7 5V9M5 7H9"
20
+ stroke="currentColor"
21
+ strokeWidth="1.5"
22
+ strokeLinecap="round"
23
+ />
24
+ </svg>
25
+ );
26
+
27
+ const ZoomOutIcon = () => (
28
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
29
+ <circle cx="7" cy="7" r="5.5" stroke="currentColor" strokeWidth="1.5" />
30
+ <path
31
+ d="M11 11L14 14"
32
+ stroke="currentColor"
33
+ strokeWidth="1.5"
34
+ strokeLinecap="round"
35
+ />
36
+ <path
37
+ d="M5 7H9"
38
+ stroke="currentColor"
39
+ strokeWidth="1.5"
40
+ strokeLinecap="round"
41
+ />
42
+ </svg>
43
+ );
44
+
45
+ const ResetIcon = () => (
46
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
47
+ <path
48
+ d="M2.5 2.5V6H6"
49
+ stroke="currentColor"
50
+ strokeWidth="1.5"
51
+ strokeLinecap="round"
52
+ strokeLinejoin="round"
53
+ />
54
+ <path
55
+ d="M2.87 10A6 6 0 1 0 4.05 4.05L2.5 6"
56
+ stroke="currentColor"
57
+ strokeWidth="1.5"
58
+ strokeLinecap="round"
59
+ strokeLinejoin="round"
60
+ />
61
+ </svg>
62
+ );
63
+
64
+ const CenterIcon = () => (
65
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
66
+ <circle cx="8" cy="8" r="2" stroke="currentColor" strokeWidth="1.5" />
67
+ <path
68
+ d="M8 2V5M8 11V14M2 8H5M11 8H14"
69
+ stroke="currentColor"
70
+ strokeWidth="1.5"
71
+ strokeLinecap="round"
72
+ />
73
+ </svg>
74
+ );
75
+
76
+ /* ── Reusable icons for stories ─────────────────────────────── */
77
+
78
+ /** Crosshair target — zoom-to-element / focus */
79
+ export const TargetIcon = () => (
80
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
81
+ <circle cx="8" cy="8" r="5" stroke="currentColor" strokeWidth="1.5" />
82
+ <circle cx="8" cy="8" r="1.5" fill="currentColor" />
83
+ <path
84
+ d="M8 1.5V4M8 12V14.5M1.5 8H4M12 8H14.5"
85
+ stroke="currentColor"
86
+ strokeWidth="1.2"
87
+ strokeLinecap="round"
88
+ />
89
+ </svg>
90
+ );
91
+
92
+ /** Toggle switch — enable/disable a feature */
93
+ export const ToggleIcon = () => (
94
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
95
+ <rect
96
+ x="1.5"
97
+ y="4.5"
98
+ width="13"
99
+ height="7"
100
+ rx="3.5"
101
+ stroke="currentColor"
102
+ strokeWidth="1.4"
103
+ />
104
+ <circle cx="11" cy="8" r="2.2" fill="currentColor" />
105
+ </svg>
106
+ );
107
+
108
+ /** Lock to vertical axis (arrows up/down) */
109
+ export const LockVerticalIcon = () => (
110
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
111
+ <path
112
+ d="M8 2L8 14"
113
+ stroke="currentColor"
114
+ strokeWidth="1.5"
115
+ strokeLinecap="round"
116
+ />
117
+ <path
118
+ d="M5 4.5L8 2L11 4.5"
119
+ stroke="currentColor"
120
+ strokeWidth="1.4"
121
+ strokeLinecap="round"
122
+ strokeLinejoin="round"
123
+ />
124
+ <path
125
+ d="M5 11.5L8 14L11 11.5"
126
+ stroke="currentColor"
127
+ strokeWidth="1.4"
128
+ strokeLinecap="round"
129
+ strokeLinejoin="round"
130
+ />
131
+ </svg>
132
+ );
133
+
134
+ /** Lock to horizontal axis (arrows left/right) */
135
+ export const LockHorizontalIcon = () => (
136
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
137
+ <path
138
+ d="M2 8L14 8"
139
+ stroke="currentColor"
140
+ strokeWidth="1.5"
141
+ strokeLinecap="round"
142
+ />
143
+ <path
144
+ d="M4.5 5L2 8L4.5 11"
145
+ stroke="currentColor"
146
+ strokeWidth="1.4"
147
+ strokeLinecap="round"
148
+ strokeLinejoin="round"
149
+ />
150
+ <path
151
+ d="M11.5 5L14 8L11.5 11"
152
+ stroke="currentColor"
153
+ strokeWidth="1.4"
154
+ strokeLinecap="round"
155
+ strokeLinejoin="round"
156
+ />
157
+ </svg>
158
+ );
159
+
160
+ /** Free movement (4-direction arrows) */
161
+ export const FreeMovementIcon = () => (
162
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
163
+ <path
164
+ d="M8 2V14M2 8H14"
165
+ stroke="currentColor"
166
+ strokeWidth="1.3"
167
+ strokeLinecap="round"
168
+ />
169
+ <path
170
+ d="M6.5 3.5L8 2L9.5 3.5"
171
+ stroke="currentColor"
172
+ strokeWidth="1.2"
173
+ strokeLinecap="round"
174
+ strokeLinejoin="round"
175
+ />
176
+ <path
177
+ d="M6.5 12.5L8 14L9.5 12.5"
178
+ stroke="currentColor"
179
+ strokeWidth="1.2"
180
+ strokeLinecap="round"
181
+ strokeLinejoin="round"
182
+ />
183
+ <path
184
+ d="M3.5 6.5L2 8L3.5 9.5"
185
+ stroke="currentColor"
186
+ strokeWidth="1.2"
187
+ strokeLinecap="round"
188
+ strokeLinejoin="round"
189
+ />
190
+ <path
191
+ d="M12.5 6.5L14 8L12.5 9.5"
192
+ stroke="currentColor"
193
+ strokeWidth="1.2"
194
+ strokeLinecap="round"
195
+ strokeLinejoin="round"
196
+ />
197
+ </svg>
198
+ );
199
+
200
+ /** X / close / deselect */
201
+ export const CloseIcon = () => (
202
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
203
+ <path
204
+ d="M4 4L12 12M12 4L4 12"
205
+ stroke="currentColor"
206
+ strokeWidth="1.5"
207
+ strokeLinecap="round"
208
+ />
209
+ </svg>
210
+ );
211
+
212
+ /** Numbered target (1, 2, 3…) with a dot in center */
213
+ export const NumberedTargetIcon = ({ n }: { n: number }) => (
214
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
215
+ <circle cx="8" cy="8" r="6" stroke="currentColor" strokeWidth="1.4" />
216
+ <text
217
+ x="8"
218
+ y="8"
219
+ textAnchor="middle"
220
+ dominantBaseline="central"
221
+ fill="currentColor"
222
+ fontSize="8"
223
+ fontWeight="700"
224
+ fontFamily="ui-sans-serif, system-ui, sans-serif"
225
+ >
226
+ {n}
227
+ </text>
228
+ </svg>
229
+ );
230
+
231
+ /* ── Types ──────────────────────────────────────────────────── */
232
+
233
+ export type ControlButton = {
234
+ label: string;
235
+ icon?: React.ReactNode;
236
+ onClick: () => void;
237
+ active?: boolean;
238
+ };
239
+
240
+ type ControlsProps = ReactZoomPanPinchContentRef & {
241
+ extraButtons?: ControlButton[];
242
+ position?:
243
+ | "top-left"
244
+ | "top-center"
245
+ | "top-right"
246
+ | "bottom-left"
247
+ | "bottom-right";
248
+ };
249
+
250
+ const POSITION_CLASS_MAP: Record<string, string> = {
251
+ "top-center": styles.controlsTopCenter,
252
+ "top-right": styles.controlsTopRight,
253
+ "bottom-left": styles.controlsBottomLeft,
254
+ "bottom-right": styles.controlsBottomRight,
255
+ "top-left": styles.controlsTopLeft,
256
+ };
257
+
258
+ /* ── Component ──────────────────────────────────────────────── */
259
+
260
+ export const Controls: React.FC<ControlsProps> = ({
261
+ zoomIn,
262
+ zoomOut,
263
+ resetTransform,
264
+ centerView,
265
+ extraButtons = [],
266
+ position = "top-left",
267
+ }) => {
268
+ const positionClass = POSITION_CLASS_MAP[position] || styles.controlsTopLeft;
269
+
270
+ return (
271
+ <div className={`${styles.controlBar} ${positionClass}`}>
272
+ <div className={styles.controlGroup}>
273
+ <button
274
+ type="button"
275
+ className={styles.controlIcon}
276
+ onClick={() => zoomIn()}
277
+ data-tooltip="Zoom in"
278
+ aria-label="Zoom in"
279
+ >
280
+ <ZoomInIcon />
281
+ </button>
282
+ <button
283
+ type="button"
284
+ className={styles.controlIcon}
285
+ onClick={() => zoomOut()}
286
+ data-tooltip="Zoom out"
287
+ aria-label="Zoom out"
288
+ >
289
+ <ZoomOutIcon />
290
+ </button>
291
+ </div>
292
+
293
+ <span className={styles.controlDivider} />
294
+
295
+ <div className={styles.controlGroup}>
296
+ <button
297
+ type="button"
298
+ className={styles.controlIcon}
299
+ onClick={() => resetTransform()}
300
+ data-tooltip="Reset"
301
+ aria-label="Reset"
302
+ >
303
+ <ResetIcon />
304
+ </button>
305
+ <button
306
+ type="button"
307
+ className={styles.controlIcon}
308
+ onClick={() => centerView()}
309
+ data-tooltip="Center"
310
+ aria-label="Center"
311
+ >
312
+ <CenterIcon />
313
+ </button>
314
+ </div>
315
+
316
+ {extraButtons && extraButtons.length > 0 && (
317
+ <>
318
+ <span className={styles.controlDivider} />
319
+ <div className={styles.controlGroup}>
320
+ {extraButtons.map((btn) => {
321
+ const base = btn.icon ? styles.controlIcon : styles.controlText;
322
+ const cls = btn.active
323
+ ? `${base} ${styles.controlIconActive}`
324
+ : base;
325
+ return (
326
+ <button
327
+ key={btn.label}
328
+ type="button"
329
+ className={cls}
330
+ onClick={btn.onClick}
331
+ data-tooltip={btn.label}
332
+ >
333
+ {btn.icon ?? btn.label}
334
+ </button>
335
+ );
336
+ })}
337
+ </div>
338
+ </>
339
+ )}
340
+ </div>
341
+ );
342
+ };
343
+
344
+ Controls.defaultProps = {
345
+ extraButtons: [],
346
+ position: "top-left",
347
+ };
@@ -0,0 +1,5 @@
1
+ export * from "./args.utils";
2
+ export * from "./bounds-overlay";
3
+ export * from "./code.utils";
4
+ export * from "./controls.utils";
5
+ export * from "./viewer.styles";