react-zoom-pan-pinch 3.7.0 → 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.
- package/dist/index.cjs.js +785 -310
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +117 -23
- package/dist/index.esm.js +781 -302
- package/dist/index.esm.js.map +1 -1
- package/package.json +73 -62
- package/src/components/index.ts +5 -0
- package/src/components/keep-scale/keep-scale.tsx +28 -0
- package/src/components/mini-map/mini-map.tsx +292 -0
- package/src/components/mini-map/use-resize.hook.ts +74 -0
- package/src/components/transform-component/transform-component.module.css +43 -0
- package/src/components/transform-component/transform-component.tsx +96 -0
- package/src/components/transform-wrapper/transform-wrapper.tsx +39 -0
- package/src/components/virtualize/virtualize.tsx +133 -0
- package/src/components/virtualize/virtualize.utils.ts +104 -0
- package/src/constants/state.constants.ts +99 -0
- package/src/core/animations/animations.constants.ts +78 -0
- package/src/core/animations/animations.utils.ts +115 -0
- package/src/core/bounds/bounds.types.ts +8 -0
- package/src/core/bounds/bounds.utils.ts +226 -0
- package/src/core/double-click/double-click.logic.ts +127 -0
- package/src/core/handlers/handlers.logic.ts +122 -0
- package/src/core/handlers/handlers.utils.ts +243 -0
- package/src/core/instance.core.ts +704 -0
- package/src/core/pan/panning.logic.ts +122 -0
- package/src/core/pan/panning.utils.ts +216 -0
- package/src/core/pan/velocity.logic.ts +187 -0
- package/src/core/pan/velocity.utils.ts +83 -0
- package/src/core/pinch/pinch.logic.ts +139 -0
- package/src/core/pinch/pinch.utils.ts +95 -0
- package/src/core/wheel/wheel.logic.ts +161 -0
- package/src/core/wheel/wheel.utils.ts +157 -0
- package/src/core/zoom/zoom.logic.ts +71 -0
- package/src/core/zoom/zoom.utils.ts +62 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/use-controls.tsx +9 -0
- package/src/hooks/use-transform-component.tsx +30 -0
- package/src/hooks/use-transform-context.tsx +13 -0
- package/src/hooks/use-transform-effect.tsx +22 -0
- package/src/hooks/use-transform-init.tsx +28 -0
- package/src/hooks/use-zoom-pan-pinch.tsx +48 -0
- package/src/index.ts +6 -0
- package/src/models/calculations.model.ts +34 -0
- package/src/models/context.model.ts +218 -0
- package/src/models/helpers.model.ts +15 -0
- package/src/models/index.ts +3 -0
- package/src/react-app-env.d.ts +1 -0
- package/src/stories/assets/big-image.jpeg +0 -0
- package/src/stories/assets/map.jpg +0 -0
- package/src/stories/assets/medium-image.jpg +0 -0
- package/src/stories/assets/pin.svg +1 -0
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +14 -0
- package/src/stories/docs/DocTable.tsx +59 -0
- package/src/stories/docs/HandlerCards.tsx +102 -0
- package/src/stories/docs/Introduction.stories.mdx +135 -0
- package/src/stories/docs/PropTable.tsx +116 -0
- package/src/stories/docs/docs.module.css +370 -0
- package/src/stories/docs/handlers.stories.mdx +7 -0
- package/src/stories/docs/handlers.tsx +111 -0
- package/src/stories/docs/props.stories.mdx +11 -0
- package/src/stories/docs/props.tsx +571 -0
- package/src/stories/examples/axis-lock/axis-lock.stories.mdx +35 -0
- package/src/stories/examples/axis-lock/example.tsx +114 -0
- package/src/stories/examples/bounds/bounds.data.tsx +191 -0
- package/src/stories/examples/bounds/bounds.stories.mdx +99 -0
- package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +206 -0
- package/src/stories/examples/cinema/cinema-data.tsx +578 -0
- package/src/stories/examples/cinema/cinema.stories.mdx +30 -0
- package/src/stories/examples/cinema/example.tsx +378 -0
- package/src/stories/examples/cinema/image.png +0 -0
- package/src/stories/examples/content/content.stories.mdx +172 -0
- package/src/stories/examples/content/mixed-content.data.tsx +624 -0
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +34 -0
- package/src/stories/examples/content-rerendering/example.tsx +631 -0
- package/src/stories/examples/controls/controls.stories.mdx +120 -0
- package/src/stories/examples/image/example.tsx +149 -0
- package/src/stories/examples/image/image.stories.mdx +46 -0
- package/src/stories/examples/image-annotations/example.tsx +1442 -0
- package/src/stories/examples/image-annotations/image-annotations.stories.mdx +39 -0
- package/src/stories/examples/image-responsive/example.tsx +152 -0
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +51 -0
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +107 -0
- package/src/stories/examples/initial-transform/example.tsx +233 -0
- package/src/stories/examples/initial-transform/initial-transform.stories.mdx +37 -0
- package/src/stories/examples/keep-scale/example.tsx +882 -0
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +30 -0
- package/src/stories/examples/keep-scale/map.stories.mdx +28 -0
- package/src/stories/examples/medical-viewer/chest-xray.tsx +246 -0
- package/src/stories/examples/medical-viewer/example.tsx +690 -0
- package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +49 -0
- package/src/stories/examples/mini-map/example.tsx +122 -0
- package/src/stories/examples/mini-map/mini-map.stories.mdx +26 -0
- package/src/stories/examples/miro/example.tsx +1573 -0
- package/src/stories/examples/miro/miro.stories.mdx +31 -0
- package/src/stories/examples/padding/example.tsx +147 -0
- package/src/stories/examples/padding/padding.stories.mdx +35 -0
- package/src/stories/examples/product-card/example.tsx +594 -0
- package/src/stories/examples/product-card/product-card.stories.mdx +29 -0
- package/src/stories/examples/stadium/example.tsx +1040 -0
- package/src/stories/examples/stadium/stadium-data.ts +224 -0
- package/src/stories/examples/stadium/stadium.stories.mdx +32 -0
- package/src/stories/examples/stress/example.tsx +59 -0
- package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
- package/src/stories/examples/svg-zoom-to-element/example.tsx +95 -0
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
- package/src/stories/examples/text-selection/example.tsx +221 -0
- package/src/stories/examples/text-selection/text-selection.stories.mdx +31 -0
- package/src/stories/examples/velocity/example.tsx +908 -0
- package/src/stories/examples/velocity/velocity.stories.mdx +35 -0
- package/src/stories/examples/virtualize/example.tsx +239 -0
- package/src/stories/examples/virtualize/virtualize.stories.mdx +84 -0
- package/src/stories/examples/zoom-to-element/example.tsx +219 -0
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +31 -0
- package/src/stories/hooks/use-controls.stories.mdx +86 -0
- package/src/stories/hooks/use-transform-component.stories.mdx +108 -0
- package/src/stories/hooks/use-transform-context.stories.mdx +92 -0
- package/src/stories/hooks/use-transform-effect.stories.mdx +114 -0
- package/src/stories/hooks/use-transform-init.stories.mdx +105 -0
- package/src/stories/types/args.types.ts +192 -0
- package/src/stories/utils/args.utils.ts +35 -0
- package/src/stories/utils/bounds-overlay.tsx +168 -0
- package/src/stories/utils/code.utils.tsx +22 -0
- package/src/stories/utils/controls.utils.tsx +347 -0
- package/src/stories/utils/index.ts +5 -0
- package/src/stories/utils/styles.module.css +223 -0
- package/src/stories/utils/viewer.styles.ts +34 -0
- package/src/styles.css +8 -0
- package/src/typings.d.ts +21 -0
- package/src/utils/calculations.utils.ts +16 -0
- package/src/utils/callback.utils.ts +11 -0
- package/src/utils/context.utils.ts +49 -0
- package/src/utils/event.utils.ts +38 -0
- package/src/utils/helpers.utils.ts +22 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/ref.utils.ts +32 -0
- package/src/utils/state.utils.ts +77 -0
- package/src/utils/styles.utils.ts +49 -0
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
import React, { useCallback, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
4
|
+
import { useTransformComponent } from "../../../hooks";
|
|
5
|
+
import { Controls, normalizeArgs } from "../../utils";
|
|
6
|
+
import { ChestXray, XRAY_W, XRAY_H } from "./chest-xray";
|
|
7
|
+
|
|
8
|
+
const font =
|
|
9
|
+
'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
|
|
10
|
+
const mono = '"SF Mono", ui-monospace, "Cascadia Code", monospace';
|
|
11
|
+
|
|
12
|
+
type WindowPreset = {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
brightness: number;
|
|
16
|
+
contrast: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const PRESETS: WindowPreset[] = [
|
|
20
|
+
{ id: "default", label: "Default", brightness: 1, contrast: 1 },
|
|
21
|
+
{ id: "lung", label: "Lung", brightness: 1.3, contrast: 1.6 },
|
|
22
|
+
{ id: "bone", label: "Bone", brightness: 0.85, contrast: 2.0 },
|
|
23
|
+
{ id: "soft", label: "Soft tissue", brightness: 1.15, contrast: 0.85 },
|
|
24
|
+
{ id: "mediastinum", label: "Mediastinum", brightness: 0.9, contrast: 1.35 },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
interface Finding {
|
|
28
|
+
id: string;
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
label: string;
|
|
32
|
+
detail: string;
|
|
33
|
+
severity: "normal" | "mild" | "significant";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const FINDINGS: Finding[] = [
|
|
37
|
+
{
|
|
38
|
+
id: "f1",
|
|
39
|
+
x: 320,
|
|
40
|
+
y: 580,
|
|
41
|
+
label: "Cardiomediastinal",
|
|
42
|
+
detail: "Heart size within normal limits. No mediastinal widening.",
|
|
43
|
+
severity: "normal",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "f2",
|
|
47
|
+
x: 680,
|
|
48
|
+
y: 450,
|
|
49
|
+
label: "Left hilum",
|
|
50
|
+
detail: "Mildly prominent left hilum — consider lymphadenopathy.",
|
|
51
|
+
severity: "mild",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "f3",
|
|
55
|
+
x: 250,
|
|
56
|
+
y: 720,
|
|
57
|
+
label: "Right base",
|
|
58
|
+
detail: "Subtle opacity at right costophrenic angle — small effusion?",
|
|
59
|
+
severity: "significant",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "f4",
|
|
63
|
+
x: 512,
|
|
64
|
+
y: 300,
|
|
65
|
+
label: "Trachea",
|
|
66
|
+
detail: "Midline trachea. No deviation.",
|
|
67
|
+
severity: "normal",
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const SEV_COLORS: Record<Finding["severity"], string> = {
|
|
72
|
+
normal: "#22c55e",
|
|
73
|
+
mild: "#f59e0b",
|
|
74
|
+
significant: "#ef4444",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/* ── Toolbar primitives ─────────────────────────────────────── */
|
|
78
|
+
|
|
79
|
+
function ToolbarGroup({
|
|
80
|
+
label,
|
|
81
|
+
children,
|
|
82
|
+
}: {
|
|
83
|
+
label: string;
|
|
84
|
+
children: React.ReactNode;
|
|
85
|
+
}) {
|
|
86
|
+
return (
|
|
87
|
+
<div style={{ display: "flex", alignItems: "center", gap: 4 }}>
|
|
88
|
+
<span
|
|
89
|
+
style={{
|
|
90
|
+
fontSize: 10,
|
|
91
|
+
fontWeight: 700,
|
|
92
|
+
letterSpacing: "0.08em",
|
|
93
|
+
textTransform: "uppercase",
|
|
94
|
+
color: "#444",
|
|
95
|
+
marginRight: 4,
|
|
96
|
+
whiteSpace: "nowrap",
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
{label}
|
|
100
|
+
</span>
|
|
101
|
+
{children}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function ToolbarButton({
|
|
107
|
+
label,
|
|
108
|
+
active,
|
|
109
|
+
onClick,
|
|
110
|
+
accent,
|
|
111
|
+
}: {
|
|
112
|
+
label: string;
|
|
113
|
+
active: boolean;
|
|
114
|
+
onClick: () => void;
|
|
115
|
+
accent: string;
|
|
116
|
+
}) {
|
|
117
|
+
return (
|
|
118
|
+
<button
|
|
119
|
+
type="button"
|
|
120
|
+
onClick={onClick}
|
|
121
|
+
style={{
|
|
122
|
+
fontFamily: "inherit",
|
|
123
|
+
fontSize: 11,
|
|
124
|
+
fontWeight: 600,
|
|
125
|
+
padding: "5px 10px",
|
|
126
|
+
borderRadius: 6,
|
|
127
|
+
border: active ? `1px solid ${accent}55` : "1px solid #222",
|
|
128
|
+
background: active ? `${accent}18` : "transparent",
|
|
129
|
+
color: active ? accent : "#666",
|
|
130
|
+
cursor: "pointer",
|
|
131
|
+
whiteSpace: "nowrap",
|
|
132
|
+
}}
|
|
133
|
+
>
|
|
134
|
+
{label}
|
|
135
|
+
</button>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function ToolbarDivider() {
|
|
140
|
+
return (
|
|
141
|
+
<span
|
|
142
|
+
style={{
|
|
143
|
+
width: 1,
|
|
144
|
+
height: 20,
|
|
145
|
+
background: "#222",
|
|
146
|
+
margin: "0 6px",
|
|
147
|
+
flexShrink: 0,
|
|
148
|
+
}}
|
|
149
|
+
/>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* ── DICOM corner overlays ──────────────────────────────────── */
|
|
154
|
+
|
|
155
|
+
const overlayBase: React.CSSProperties = {
|
|
156
|
+
position: "absolute",
|
|
157
|
+
zIndex: 10,
|
|
158
|
+
fontFamily: mono,
|
|
159
|
+
fontSize: 11,
|
|
160
|
+
lineHeight: 1.6,
|
|
161
|
+
color: "#888",
|
|
162
|
+
pointerEvents: "none",
|
|
163
|
+
userSelect: "none",
|
|
164
|
+
textShadow: "0 1px 4px rgba(0,0,0,0.9)",
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
function DicomOverlayTL() {
|
|
168
|
+
return (
|
|
169
|
+
<div style={{ ...overlayBase, top: 16, left: 16 }}>
|
|
170
|
+
<div style={{ color: "#aaa", fontWeight: 700, marginBottom: 2 }}>
|
|
171
|
+
SMITH, JOHN A
|
|
172
|
+
</div>
|
|
173
|
+
<div>DOB: 15-Mar-1978 · M</div>
|
|
174
|
+
<div>MRN: 00847291</div>
|
|
175
|
+
<div style={{ marginTop: 6, fontSize: 10, color: "#555" }}>
|
|
176
|
+
Lumen Regional Medical Center
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function DicomOverlayTR({
|
|
183
|
+
preset,
|
|
184
|
+
inverted,
|
|
185
|
+
}: {
|
|
186
|
+
preset: WindowPreset;
|
|
187
|
+
inverted: boolean;
|
|
188
|
+
}) {
|
|
189
|
+
return (
|
|
190
|
+
<div style={{ ...overlayBase, top: 16, right: 16, textAlign: "right" }}>
|
|
191
|
+
<div>CR · PA Chest</div>
|
|
192
|
+
<div>2024-12-08 14:32</div>
|
|
193
|
+
<div style={{ marginTop: 6 }}>
|
|
194
|
+
W: {(preset.contrast * 400).toFixed(0)} L:{" "}
|
|
195
|
+
{(preset.brightness * 40).toFixed(0)}
|
|
196
|
+
</div>
|
|
197
|
+
{inverted && <div style={{ color: "#60a5fa" }}>INVERTED</div>}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function DicomOverlayBL() {
|
|
203
|
+
return (
|
|
204
|
+
<div style={{ ...overlayBase, bottom: 50, left: 16 }}>
|
|
205
|
+
<div>Series: 1 · Image: 1/1</div>
|
|
206
|
+
<div>
|
|
207
|
+
Matrix: {XRAY_W} × {XRAY_H}
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* ── Finding marker on image ────────────────────────────────── */
|
|
214
|
+
|
|
215
|
+
function FindingMarker({
|
|
216
|
+
finding: f,
|
|
217
|
+
active,
|
|
218
|
+
onToggle,
|
|
219
|
+
}: {
|
|
220
|
+
finding: Finding;
|
|
221
|
+
active: boolean;
|
|
222
|
+
onToggle: () => void;
|
|
223
|
+
}) {
|
|
224
|
+
const color = SEV_COLORS[f.severity];
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<>
|
|
228
|
+
<button
|
|
229
|
+
type="button"
|
|
230
|
+
id={`finding-${f.id}`}
|
|
231
|
+
aria-label={f.label}
|
|
232
|
+
onClick={(e) => {
|
|
233
|
+
e.stopPropagation();
|
|
234
|
+
onToggle();
|
|
235
|
+
}}
|
|
236
|
+
style={{
|
|
237
|
+
position: "absolute",
|
|
238
|
+
left: f.x,
|
|
239
|
+
top: f.y,
|
|
240
|
+
width: 24,
|
|
241
|
+
height: 24,
|
|
242
|
+
marginLeft: -12,
|
|
243
|
+
marginTop: -12,
|
|
244
|
+
borderRadius: "50%",
|
|
245
|
+
border: `2px solid ${color}`,
|
|
246
|
+
background: active ? `${color}35` : "transparent",
|
|
247
|
+
cursor: "pointer",
|
|
248
|
+
boxShadow: active
|
|
249
|
+
? `0 0 0 6px ${color}22, 0 0 16px ${color}44`
|
|
250
|
+
: `0 0 12px ${color}33`,
|
|
251
|
+
transition: "box-shadow 0.2s ease, background 0.2s ease",
|
|
252
|
+
zIndex: active ? 8 : 5,
|
|
253
|
+
padding: 0,
|
|
254
|
+
}}
|
|
255
|
+
/>
|
|
256
|
+
|
|
257
|
+
{active && (
|
|
258
|
+
<div
|
|
259
|
+
style={{
|
|
260
|
+
position: "absolute",
|
|
261
|
+
left: f.x + 20,
|
|
262
|
+
top: f.y - 16,
|
|
263
|
+
zIndex: 20,
|
|
264
|
+
minWidth: 220,
|
|
265
|
+
maxWidth: 300,
|
|
266
|
+
padding: "10px 14px",
|
|
267
|
+
borderRadius: 10,
|
|
268
|
+
background: "rgba(10, 10, 10, 0.94)",
|
|
269
|
+
border: `1px solid ${color}55`,
|
|
270
|
+
boxShadow: `0 12px 36px rgba(0,0,0,0.6), 0 0 0 1px ${color}22`,
|
|
271
|
+
fontFamily: font,
|
|
272
|
+
pointerEvents: "auto",
|
|
273
|
+
}}
|
|
274
|
+
>
|
|
275
|
+
<div
|
|
276
|
+
style={{
|
|
277
|
+
display: "flex",
|
|
278
|
+
alignItems: "center",
|
|
279
|
+
gap: 8,
|
|
280
|
+
marginBottom: 8,
|
|
281
|
+
}}
|
|
282
|
+
>
|
|
283
|
+
<span
|
|
284
|
+
style={{
|
|
285
|
+
width: 8,
|
|
286
|
+
height: 8,
|
|
287
|
+
borderRadius: "50%",
|
|
288
|
+
background: color,
|
|
289
|
+
boxShadow: `0 0 8px ${color}`,
|
|
290
|
+
flexShrink: 0,
|
|
291
|
+
}}
|
|
292
|
+
/>
|
|
293
|
+
<span
|
|
294
|
+
style={{
|
|
295
|
+
fontSize: 12,
|
|
296
|
+
fontWeight: 700,
|
|
297
|
+
color: "#e2e8f0",
|
|
298
|
+
}}
|
|
299
|
+
>
|
|
300
|
+
{f.label}
|
|
301
|
+
</span>
|
|
302
|
+
<span
|
|
303
|
+
style={{
|
|
304
|
+
marginLeft: "auto",
|
|
305
|
+
fontSize: 10,
|
|
306
|
+
fontWeight: 600,
|
|
307
|
+
textTransform: "uppercase",
|
|
308
|
+
letterSpacing: "0.06em",
|
|
309
|
+
color,
|
|
310
|
+
}}
|
|
311
|
+
>
|
|
312
|
+
{f.severity}
|
|
313
|
+
</span>
|
|
314
|
+
</div>
|
|
315
|
+
<p
|
|
316
|
+
style={{
|
|
317
|
+
margin: 0,
|
|
318
|
+
fontSize: 12,
|
|
319
|
+
lineHeight: 1.55,
|
|
320
|
+
color: "#94a3b8",
|
|
321
|
+
}}
|
|
322
|
+
>
|
|
323
|
+
{f.detail}
|
|
324
|
+
</p>
|
|
325
|
+
</div>
|
|
326
|
+
)}
|
|
327
|
+
</>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/* ── Finding chip in bottom panel ───────────────────────────── */
|
|
332
|
+
|
|
333
|
+
function FindingChip({
|
|
334
|
+
finding: f,
|
|
335
|
+
active,
|
|
336
|
+
onToggle,
|
|
337
|
+
}: {
|
|
338
|
+
finding: Finding;
|
|
339
|
+
active: boolean;
|
|
340
|
+
onToggle: () => void;
|
|
341
|
+
}) {
|
|
342
|
+
const color = SEV_COLORS[f.severity];
|
|
343
|
+
return (
|
|
344
|
+
<button
|
|
345
|
+
type="button"
|
|
346
|
+
onClick={onToggle}
|
|
347
|
+
style={{
|
|
348
|
+
display: "inline-flex",
|
|
349
|
+
alignItems: "center",
|
|
350
|
+
gap: 8,
|
|
351
|
+
padding: "8px 14px",
|
|
352
|
+
borderRadius: 10,
|
|
353
|
+
border: active ? `1px solid ${color}66` : "1px solid #1f1f1f",
|
|
354
|
+
background: active ? `${color}14` : "#111",
|
|
355
|
+
cursor: "pointer",
|
|
356
|
+
fontFamily: "inherit",
|
|
357
|
+
}}
|
|
358
|
+
>
|
|
359
|
+
<span
|
|
360
|
+
style={{
|
|
361
|
+
width: 7,
|
|
362
|
+
height: 7,
|
|
363
|
+
borderRadius: "50%",
|
|
364
|
+
background: color,
|
|
365
|
+
boxShadow: active ? `0 0 8px ${color}` : "none",
|
|
366
|
+
flexShrink: 0,
|
|
367
|
+
}}
|
|
368
|
+
/>
|
|
369
|
+
<span style={{ fontSize: 12, fontWeight: 600, color: "#ccc" }}>
|
|
370
|
+
{f.label}
|
|
371
|
+
</span>
|
|
372
|
+
</button>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* ── Ruler overlay ──────────────────────────────────────────── */
|
|
377
|
+
|
|
378
|
+
function RulerOverlay() {
|
|
379
|
+
const tickCount = Math.floor(XRAY_H / 100);
|
|
380
|
+
|
|
381
|
+
return (
|
|
382
|
+
<div
|
|
383
|
+
style={{
|
|
384
|
+
position: "absolute",
|
|
385
|
+
left: 6,
|
|
386
|
+
top: 0,
|
|
387
|
+
width: 32,
|
|
388
|
+
height: XRAY_H,
|
|
389
|
+
pointerEvents: "none",
|
|
390
|
+
zIndex: 6,
|
|
391
|
+
}}
|
|
392
|
+
>
|
|
393
|
+
<div
|
|
394
|
+
style={{
|
|
395
|
+
position: "absolute",
|
|
396
|
+
left: 14,
|
|
397
|
+
top: 0,
|
|
398
|
+
width: 1,
|
|
399
|
+
height: "100%",
|
|
400
|
+
background: "rgba(52, 211, 153, 0.45)",
|
|
401
|
+
}}
|
|
402
|
+
/>
|
|
403
|
+
{Array.from({ length: tickCount + 1 }, (_, i) => {
|
|
404
|
+
const y = i * 100;
|
|
405
|
+
const major = i % 5 === 0;
|
|
406
|
+
return (
|
|
407
|
+
<React.Fragment key={i}>
|
|
408
|
+
<div
|
|
409
|
+
style={{
|
|
410
|
+
position: "absolute",
|
|
411
|
+
left: major ? 6 : 10,
|
|
412
|
+
top: y,
|
|
413
|
+
width: major ? 18 : 10,
|
|
414
|
+
height: 1,
|
|
415
|
+
background: major
|
|
416
|
+
? "rgba(52, 211, 153, 0.7)"
|
|
417
|
+
: "rgba(52, 211, 153, 0.35)",
|
|
418
|
+
}}
|
|
419
|
+
/>
|
|
420
|
+
{major && (
|
|
421
|
+
<span
|
|
422
|
+
style={{
|
|
423
|
+
position: "absolute",
|
|
424
|
+
left: 28,
|
|
425
|
+
top: y - 5,
|
|
426
|
+
fontSize: 9,
|
|
427
|
+
fontFamily: mono,
|
|
428
|
+
fontWeight: 600,
|
|
429
|
+
color: "rgba(52, 211, 153, 0.65)",
|
|
430
|
+
}}
|
|
431
|
+
>
|
|
432
|
+
{i}
|
|
433
|
+
</span>
|
|
434
|
+
)}
|
|
435
|
+
</React.Fragment>
|
|
436
|
+
);
|
|
437
|
+
})}
|
|
438
|
+
|
|
439
|
+
{/* Horizontal ruler at top */}
|
|
440
|
+
<div
|
|
441
|
+
style={{
|
|
442
|
+
position: "absolute",
|
|
443
|
+
left: 0,
|
|
444
|
+
top: 0,
|
|
445
|
+
width: XRAY_W,
|
|
446
|
+
height: 20,
|
|
447
|
+
}}
|
|
448
|
+
>
|
|
449
|
+
<div
|
|
450
|
+
style={{
|
|
451
|
+
position: "absolute",
|
|
452
|
+
left: 0,
|
|
453
|
+
top: 14,
|
|
454
|
+
width: XRAY_W,
|
|
455
|
+
height: 1,
|
|
456
|
+
background: "rgba(52, 211, 153, 0.3)",
|
|
457
|
+
}}
|
|
458
|
+
/>
|
|
459
|
+
{Array.from({ length: Math.floor(XRAY_W / 100) + 1 }, (_, i) => {
|
|
460
|
+
const x = i * 100;
|
|
461
|
+
const major = i % 5 === 0;
|
|
462
|
+
return (
|
|
463
|
+
<React.Fragment key={`h-${i}`}>
|
|
464
|
+
<div
|
|
465
|
+
style={{
|
|
466
|
+
position: "absolute",
|
|
467
|
+
left: x,
|
|
468
|
+
top: major ? 6 : 10,
|
|
469
|
+
width: 1,
|
|
470
|
+
height: major ? 14 : 6,
|
|
471
|
+
background: major
|
|
472
|
+
? "rgba(52, 211, 153, 0.6)"
|
|
473
|
+
: "rgba(52, 211, 153, 0.3)",
|
|
474
|
+
}}
|
|
475
|
+
/>
|
|
476
|
+
</React.Fragment>
|
|
477
|
+
);
|
|
478
|
+
})}
|
|
479
|
+
</div>
|
|
480
|
+
</div>
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/* ── Scale badge ────────────────────────────────────────────── */
|
|
485
|
+
|
|
486
|
+
function ScaleBadge() {
|
|
487
|
+
return useTransformComponent(({ state }) => (
|
|
488
|
+
<div
|
|
489
|
+
style={{
|
|
490
|
+
position: "absolute",
|
|
491
|
+
bottom: 16,
|
|
492
|
+
right: 16,
|
|
493
|
+
zIndex: 10,
|
|
494
|
+
padding: "4px 10px",
|
|
495
|
+
borderRadius: 6,
|
|
496
|
+
background: "rgba(0, 0, 0, 0.7)",
|
|
497
|
+
border: "1px solid rgba(255,255,255,0.1)",
|
|
498
|
+
color: "#aaa",
|
|
499
|
+
fontSize: 11,
|
|
500
|
+
fontWeight: 600,
|
|
501
|
+
fontFamily: mono,
|
|
502
|
+
pointerEvents: "none",
|
|
503
|
+
userSelect: "none",
|
|
504
|
+
}}
|
|
505
|
+
>
|
|
506
|
+
{(state.scale * 100).toFixed(0)}%
|
|
507
|
+
</div>
|
|
508
|
+
));
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/* ── Main component ─────────────────────────────────────────── */
|
|
512
|
+
|
|
513
|
+
export const Example: React.FC<Record<string, unknown>> = (args) => {
|
|
514
|
+
const normalized = normalizeArgs(args);
|
|
515
|
+
const [activePreset, setActivePreset] = useState<string>("default");
|
|
516
|
+
const [inverted, setInverted] = useState(false);
|
|
517
|
+
const [showFindings, setShowFindings] = useState(true);
|
|
518
|
+
const [showRuler, setShowRuler] = useState(false);
|
|
519
|
+
const [activeFinding, setActiveFinding] = useState<string | null>(null);
|
|
520
|
+
|
|
521
|
+
const preset = PRESETS.find((p) => p.id === activePreset)!;
|
|
522
|
+
|
|
523
|
+
const imageFilter = [
|
|
524
|
+
`brightness(${preset.brightness})`,
|
|
525
|
+
`contrast(${preset.contrast})`,
|
|
526
|
+
inverted ? "invert(1)" : "",
|
|
527
|
+
]
|
|
528
|
+
.filter(Boolean)
|
|
529
|
+
.join(" ");
|
|
530
|
+
|
|
531
|
+
const toggleFinding = useCallback((id: string) => {
|
|
532
|
+
setActiveFinding((prev) => (prev === id ? null : id));
|
|
533
|
+
}, []);
|
|
534
|
+
|
|
535
|
+
return (
|
|
536
|
+
<div
|
|
537
|
+
style={{
|
|
538
|
+
fontFamily: font,
|
|
539
|
+
background: "#000",
|
|
540
|
+
borderRadius: 14,
|
|
541
|
+
overflow: "hidden",
|
|
542
|
+
boxSizing: "border-box",
|
|
543
|
+
}}
|
|
544
|
+
>
|
|
545
|
+
{/* Toolbar */}
|
|
546
|
+
<div
|
|
547
|
+
style={{
|
|
548
|
+
display: "flex",
|
|
549
|
+
flexWrap: "wrap",
|
|
550
|
+
gap: 6,
|
|
551
|
+
padding: "10px 16px",
|
|
552
|
+
borderBottom: "1px solid #1a1a1a",
|
|
553
|
+
background: "#0a0a0a",
|
|
554
|
+
alignItems: "center",
|
|
555
|
+
}}
|
|
556
|
+
>
|
|
557
|
+
{/* Presets */}
|
|
558
|
+
<ToolbarGroup label="Window">
|
|
559
|
+
{PRESETS.map((p) => (
|
|
560
|
+
<ToolbarButton
|
|
561
|
+
key={p.id}
|
|
562
|
+
label={p.label}
|
|
563
|
+
active={activePreset === p.id}
|
|
564
|
+
onClick={() => setActivePreset(p.id)}
|
|
565
|
+
accent="#e2e8f0"
|
|
566
|
+
/>
|
|
567
|
+
))}
|
|
568
|
+
</ToolbarGroup>
|
|
569
|
+
|
|
570
|
+
<ToolbarDivider />
|
|
571
|
+
|
|
572
|
+
<ToolbarGroup label="Display">
|
|
573
|
+
<ToolbarButton
|
|
574
|
+
label="Invert"
|
|
575
|
+
active={inverted}
|
|
576
|
+
onClick={() => setInverted((v) => !v)}
|
|
577
|
+
accent="#60a5fa"
|
|
578
|
+
/>
|
|
579
|
+
<ToolbarButton
|
|
580
|
+
label="Findings"
|
|
581
|
+
active={showFindings}
|
|
582
|
+
onClick={() => {
|
|
583
|
+
setShowFindings((v) => !v);
|
|
584
|
+
if (showFindings) setActiveFinding(null);
|
|
585
|
+
}}
|
|
586
|
+
accent="#a78bfa"
|
|
587
|
+
/>
|
|
588
|
+
<ToolbarButton
|
|
589
|
+
label="Ruler"
|
|
590
|
+
active={showRuler}
|
|
591
|
+
onClick={() => setShowRuler((v) => !v)}
|
|
592
|
+
accent="#34d399"
|
|
593
|
+
/>
|
|
594
|
+
</ToolbarGroup>
|
|
595
|
+
</div>
|
|
596
|
+
|
|
597
|
+
<div style={{ position: "relative" }}>
|
|
598
|
+
{/* DICOM corner overlays */}
|
|
599
|
+
<DicomOverlayTL />
|
|
600
|
+
<DicomOverlayTR preset={preset} inverted={inverted} />
|
|
601
|
+
<DicomOverlayBL />
|
|
602
|
+
|
|
603
|
+
<TransformWrapper
|
|
604
|
+
{...normalized}
|
|
605
|
+
centerOnInit
|
|
606
|
+
centerZoomedOut
|
|
607
|
+
minScale={0.25}
|
|
608
|
+
maxScale={10}
|
|
609
|
+
doubleClick={{ step: 1.8 }}
|
|
610
|
+
>
|
|
611
|
+
{(utils) => (
|
|
612
|
+
<>
|
|
613
|
+
<Controls {...utils} position="bottom-right" />
|
|
614
|
+
<ScaleBadge />
|
|
615
|
+
<TransformComponent
|
|
616
|
+
wrapperStyle={{
|
|
617
|
+
width: "100%",
|
|
618
|
+
height: "min(640px, 72vh)",
|
|
619
|
+
minHeight: 420,
|
|
620
|
+
background: "#000",
|
|
621
|
+
}}
|
|
622
|
+
contentStyle={{
|
|
623
|
+
width: XRAY_W,
|
|
624
|
+
height: XRAY_H,
|
|
625
|
+
}}
|
|
626
|
+
>
|
|
627
|
+
<div style={{ position: "relative" }}>
|
|
628
|
+
<div
|
|
629
|
+
style={{
|
|
630
|
+
filter: imageFilter,
|
|
631
|
+
transition: "filter 0.25s ease",
|
|
632
|
+
}}
|
|
633
|
+
>
|
|
634
|
+
<ChestXray />
|
|
635
|
+
</div>
|
|
636
|
+
|
|
637
|
+
{showRuler && <RulerOverlay />}
|
|
638
|
+
|
|
639
|
+
{showFindings &&
|
|
640
|
+
FINDINGS.map((f) => (
|
|
641
|
+
<FindingMarker
|
|
642
|
+
key={f.id}
|
|
643
|
+
finding={f}
|
|
644
|
+
active={activeFinding === f.id}
|
|
645
|
+
onToggle={() => toggleFinding(f.id)}
|
|
646
|
+
/>
|
|
647
|
+
))}
|
|
648
|
+
</div>
|
|
649
|
+
</TransformComponent>
|
|
650
|
+
</>
|
|
651
|
+
)}
|
|
652
|
+
</TransformWrapper>
|
|
653
|
+
</div>
|
|
654
|
+
|
|
655
|
+
{/* Findings panel */}
|
|
656
|
+
{showFindings && (
|
|
657
|
+
<div
|
|
658
|
+
style={{
|
|
659
|
+
borderTop: "1px solid #1a1a1a",
|
|
660
|
+
background: "#0a0a0a",
|
|
661
|
+
padding: "12px 16px",
|
|
662
|
+
}}
|
|
663
|
+
>
|
|
664
|
+
<div
|
|
665
|
+
style={{
|
|
666
|
+
fontSize: 10,
|
|
667
|
+
fontWeight: 700,
|
|
668
|
+
letterSpacing: "0.12em",
|
|
669
|
+
textTransform: "uppercase",
|
|
670
|
+
color: "#555",
|
|
671
|
+
marginBottom: 10,
|
|
672
|
+
}}
|
|
673
|
+
>
|
|
674
|
+
Findings ({FINDINGS.length})
|
|
675
|
+
</div>
|
|
676
|
+
<div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
|
|
677
|
+
{FINDINGS.map((f) => (
|
|
678
|
+
<FindingChip
|
|
679
|
+
key={f.id}
|
|
680
|
+
finding={f}
|
|
681
|
+
active={activeFinding === f.id}
|
|
682
|
+
onToggle={() => toggleFinding(f.id)}
|
|
683
|
+
/>
|
|
684
|
+
))}
|
|
685
|
+
</div>
|
|
686
|
+
</div>
|
|
687
|
+
)}
|
|
688
|
+
</div>
|
|
689
|
+
);
|
|
690
|
+
};
|