@tbib-image-viewer/react 0.0.0-stage → 0.1.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.
package/dist/index.mjs ADDED
@@ -0,0 +1,2061 @@
1
+ // src/components/ImageViewer.tsx
2
+ import { useState as useState4, useRef as useRef5, useEffect as useEffect3, useCallback as useCallback3, useMemo as useMemo2 } from "react";
3
+ import { FontAwesomeIcon as FontAwesomeIcon3 } from "@fortawesome/react-fontawesome";
4
+ import {
5
+ faSpinner as faSpinner2,
6
+ faRotateRight as faRotateRight2
7
+ } from "@fortawesome/free-solid-svg-icons";
8
+ import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons/faExclamationTriangle";
9
+ import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons/faExternalLinkAlt";
10
+ import {
11
+ AnnotationStore,
12
+ downloadAnnotatedImage,
13
+ isPointNearStroke as isPointNearStroke2
14
+ } from "@tbib-image-viewer/core";
15
+
16
+ // src/components/ImageToolbar.tsx
17
+ import { FontAwesomeIcon as FontAwesomeIcon2 } from "@fortawesome/react-fontawesome";
18
+ import {
19
+ faHand,
20
+ faPen,
21
+ faHighlighter,
22
+ faCrosshairs,
23
+ faEraser,
24
+ faRotateLeft,
25
+ faRotateRight,
26
+ faTrashCan,
27
+ faMagnifyingGlassPlus,
28
+ faMagnifyingGlassMinus,
29
+ faExpand,
30
+ faRotate,
31
+ faXmark,
32
+ faExpandAlt,
33
+ faCompressAlt,
34
+ faEyeDropper
35
+ } from "@fortawesome/free-solid-svg-icons";
36
+
37
+ // src/components/DownloadMenu.tsx
38
+ import { useState, useRef, useEffect } from "react";
39
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
40
+ import {
41
+ faDownload,
42
+ faImage,
43
+ faPaintBrush,
44
+ faSpinner,
45
+ faChevronDown
46
+ } from "@fortawesome/free-solid-svg-icons";
47
+ import { jsx, jsxs } from "react/jsx-runtime";
48
+ var DownloadMenu = ({
49
+ onDownloadAnnotated,
50
+ onDownloadClean,
51
+ onExportJson
52
+ }) => {
53
+ const [isOpen, setIsOpen] = useState(false);
54
+ const [isExporting, setIsExporting] = useState(false);
55
+ const containerRef = useRef(null);
56
+ useEffect(() => {
57
+ const handleOutsideClick = (e) => {
58
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
59
+ setIsOpen(false);
60
+ }
61
+ };
62
+ if (isOpen) {
63
+ document.addEventListener("mousedown", handleOutsideClick);
64
+ }
65
+ return () => {
66
+ document.removeEventListener("mousedown", handleOutsideClick);
67
+ };
68
+ }, [isOpen]);
69
+ const handleAnnotated = async () => {
70
+ if (isExporting) return;
71
+ setIsExporting(true);
72
+ try {
73
+ await onDownloadAnnotated();
74
+ } finally {
75
+ setIsExporting(false);
76
+ setIsOpen(false);
77
+ }
78
+ };
79
+ const handleClean = async () => {
80
+ if (isExporting) return;
81
+ setIsExporting(true);
82
+ try {
83
+ await onDownloadClean();
84
+ } finally {
85
+ setIsExporting(false);
86
+ setIsOpen(false);
87
+ }
88
+ };
89
+ return /* @__PURE__ */ jsxs(
90
+ "div",
91
+ {
92
+ ref: containerRef,
93
+ style: {
94
+ position: "relative",
95
+ display: "inline-flex",
96
+ alignItems: "center"
97
+ },
98
+ children: [
99
+ /* @__PURE__ */ jsx(
100
+ "button",
101
+ {
102
+ type: "button",
103
+ className: "tbib-iv-btn",
104
+ title: "Download Annotated Image (1-Click PNG)",
105
+ "aria-label": "Download Image",
106
+ disabled: isExporting,
107
+ onClick: handleAnnotated,
108
+ style: {
109
+ borderTopRightRadius: 0,
110
+ borderBottomRightRadius: 0,
111
+ paddingRight: "6px"
112
+ },
113
+ children: /* @__PURE__ */ jsx(
114
+ FontAwesomeIcon,
115
+ {
116
+ icon: isExporting ? faSpinner : faDownload,
117
+ className: isExporting ? "fa-spin" : "",
118
+ style: { fontSize: "14px" }
119
+ }
120
+ )
121
+ }
122
+ ),
123
+ /* @__PURE__ */ jsx(
124
+ "button",
125
+ {
126
+ type: "button",
127
+ className: "tbib-iv-btn",
128
+ title: "More Download Options",
129
+ "aria-label": "More Download Options",
130
+ disabled: isExporting,
131
+ onClick: () => setIsOpen((prev) => !prev),
132
+ style: {
133
+ borderTopLeftRadius: 0,
134
+ borderBottomLeftRadius: 0,
135
+ paddingLeft: "4px",
136
+ paddingRight: "6px",
137
+ minWidth: "20px",
138
+ borderLeft: "1px solid var(--tbib-iv-border)"
139
+ },
140
+ children: /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: faChevronDown, style: { fontSize: "10px", opacity: 0.8 } })
141
+ }
142
+ ),
143
+ isOpen && /* @__PURE__ */ jsxs(
144
+ "div",
145
+ {
146
+ className: "tbib-iv-popover",
147
+ style: {
148
+ flexDirection: "column",
149
+ minWidth: "210px",
150
+ right: 0,
151
+ left: "auto",
152
+ zIndex: 100
153
+ },
154
+ children: [
155
+ /* @__PURE__ */ jsxs(
156
+ "button",
157
+ {
158
+ type: "button",
159
+ className: "tbib-iv-btn",
160
+ style: {
161
+ width: "100%",
162
+ justifyContent: "flex-start",
163
+ gap: "10px",
164
+ padding: "8px 10px",
165
+ fontSize: "12px"
166
+ },
167
+ onClick: handleAnnotated,
168
+ children: [
169
+ /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: faPaintBrush, style: { fontSize: "13px", color: "var(--tbib-iv-accent)" } }),
170
+ /* @__PURE__ */ jsx("span", { children: "Annotated Image (PNG)" })
171
+ ]
172
+ }
173
+ ),
174
+ /* @__PURE__ */ jsxs(
175
+ "button",
176
+ {
177
+ type: "button",
178
+ className: "tbib-iv-btn",
179
+ style: {
180
+ width: "100%",
181
+ justifyContent: "flex-start",
182
+ gap: "10px",
183
+ padding: "8px 10px",
184
+ fontSize: "12px"
185
+ },
186
+ onClick: handleClean,
187
+ children: [
188
+ /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: faImage, style: { fontSize: "13px" } }),
189
+ /* @__PURE__ */ jsx("span", { children: "Clean Image (Original)" })
190
+ ]
191
+ }
192
+ )
193
+ ]
194
+ }
195
+ )
196
+ ]
197
+ }
198
+ );
199
+ };
200
+
201
+ // src/components/ImageToolbar.tsx
202
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
203
+ var PRESET_COLORS = [
204
+ "#ef4444",
205
+ // Red
206
+ "#f97316",
207
+ // Orange
208
+ "#eab308",
209
+ // Yellow
210
+ "#10b981",
211
+ // Green
212
+ "#06b6d4",
213
+ // Cyan
214
+ "#8b5cf6",
215
+ // Purple
216
+ "#ffffff",
217
+ // White
218
+ "#0f172a"
219
+ // Black
220
+ ];
221
+ var THICKNESS_OPTIONS = [
222
+ { label: "Fine", value: 2 },
223
+ { label: "Medium", value: 4 },
224
+ { label: "Bold", value: 7 },
225
+ { label: "Heavy", value: 12 }
226
+ ];
227
+ var ImageToolbar = ({
228
+ activeTool,
229
+ onToolChange,
230
+ color,
231
+ onColorChange,
232
+ strokeWidth,
233
+ onStrokeWidthChange,
234
+ canUndo,
235
+ canRedo,
236
+ onUndo,
237
+ onRedo,
238
+ onClear,
239
+ zoomScale,
240
+ onZoomIn,
241
+ onZoomOut,
242
+ onZoomReset,
243
+ onRotate,
244
+ onDownloadAnnotated,
245
+ onDownloadClean,
246
+ onExportJson,
247
+ onClose,
248
+ isFullscreen,
249
+ onToggleFullscreen,
250
+ currentIndex,
251
+ totalImages
252
+ }) => {
253
+ const showSubtoolbar = activeTool === "pen" || activeTool === "highlighter" || activeTool === "laser";
254
+ return /* @__PURE__ */ jsxs2("div", { className: "tbib-iv-toolbar-wrapper", children: [
255
+ /* @__PURE__ */ jsxs2("header", { className: "tbib-iv-toolbar", role: "toolbar", "aria-label": "Image tools", children: [
256
+ currentIndex !== void 0 && totalImages !== void 0 && totalImages > 1 && /* @__PURE__ */ jsxs2(Fragment, { children: [
257
+ /* @__PURE__ */ jsxs2("span", { className: "tbib-iv-tabular", title: "Current Image", children: [
258
+ currentIndex + 1,
259
+ " / ",
260
+ totalImages
261
+ ] }),
262
+ /* @__PURE__ */ jsx2("div", { className: "tbib-iv-divider" })
263
+ ] }),
264
+ /* @__PURE__ */ jsx2(
265
+ "button",
266
+ {
267
+ type: "button",
268
+ className: `tbib-iv-btn ${activeTool === "hand" ? "tbib-iv-btn-active" : ""}`,
269
+ onClick: () => onToolChange("hand"),
270
+ title: "Pan & Move (1-finger / drag)",
271
+ "aria-label": "Hand Pan Tool",
272
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faHand })
273
+ }
274
+ ),
275
+ /* @__PURE__ */ jsx2(
276
+ "button",
277
+ {
278
+ type: "button",
279
+ className: `tbib-iv-btn ${activeTool === "pen" ? "tbib-iv-btn-active" : ""}`,
280
+ onClick: () => onToolChange("pen"),
281
+ title: "Draw Pen",
282
+ "aria-label": "Pen Tool",
283
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faPen })
284
+ }
285
+ ),
286
+ /* @__PURE__ */ jsx2(
287
+ "button",
288
+ {
289
+ type: "button",
290
+ className: `tbib-iv-btn ${activeTool === "highlighter" ? "tbib-iv-btn-active" : ""}`,
291
+ onClick: () => onToolChange("highlighter"),
292
+ title: "Highlighter (Semi-transparent)",
293
+ "aria-label": "Highlighter Tool",
294
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faHighlighter })
295
+ }
296
+ ),
297
+ /* @__PURE__ */ jsx2(
298
+ "button",
299
+ {
300
+ type: "button",
301
+ className: `tbib-iv-btn ${activeTool === "laser" ? "tbib-iv-btn-active" : ""}`,
302
+ onClick: () => onToolChange("laser"),
303
+ title: "Laser Pointer (Glowing WebGL trail)",
304
+ "aria-label": "Laser Pointer",
305
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faCrosshairs })
306
+ }
307
+ ),
308
+ /* @__PURE__ */ jsx2(
309
+ "button",
310
+ {
311
+ type: "button",
312
+ className: `tbib-iv-btn ${activeTool === "eraser" ? "tbib-iv-btn-active" : ""}`,
313
+ onClick: () => onToolChange("eraser"),
314
+ title: "Eraser (Erase strokes on tap)",
315
+ "aria-label": "Eraser Tool",
316
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faEraser })
317
+ }
318
+ ),
319
+ /* @__PURE__ */ jsx2("div", { className: "tbib-iv-divider" }),
320
+ /* @__PURE__ */ jsx2(
321
+ "button",
322
+ {
323
+ type: "button",
324
+ className: "tbib-iv-btn",
325
+ disabled: !canUndo,
326
+ onClick: onUndo,
327
+ title: "Undo (Ctrl+Z)",
328
+ "aria-label": "Undo",
329
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faRotateLeft })
330
+ }
331
+ ),
332
+ /* @__PURE__ */ jsx2(
333
+ "button",
334
+ {
335
+ type: "button",
336
+ className: "tbib-iv-btn",
337
+ disabled: !canRedo,
338
+ onClick: onRedo,
339
+ title: "Redo (Ctrl+Y)",
340
+ "aria-label": "Redo",
341
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faRotateRight })
342
+ }
343
+ ),
344
+ /* @__PURE__ */ jsx2(
345
+ "button",
346
+ {
347
+ type: "button",
348
+ className: "tbib-iv-btn",
349
+ onClick: onClear,
350
+ title: "Clear Slide Annotations",
351
+ "aria-label": "Clear All",
352
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faTrashCan })
353
+ }
354
+ ),
355
+ /* @__PURE__ */ jsx2("div", { className: "tbib-iv-divider" }),
356
+ /* @__PURE__ */ jsx2(
357
+ "button",
358
+ {
359
+ type: "button",
360
+ className: "tbib-iv-btn",
361
+ onClick: onZoomOut,
362
+ title: "Zoom Out (-)",
363
+ "aria-label": "Zoom Out",
364
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faMagnifyingGlassMinus })
365
+ }
366
+ ),
367
+ /* @__PURE__ */ jsxs2("span", { className: "tbib-iv-tabular", title: "Current Zoom Scale", children: [
368
+ Math.round(zoomScale * 100),
369
+ "%"
370
+ ] }),
371
+ /* @__PURE__ */ jsx2(
372
+ "button",
373
+ {
374
+ type: "button",
375
+ className: "tbib-iv-btn",
376
+ onClick: onZoomIn,
377
+ title: "Zoom In (+)",
378
+ "aria-label": "Zoom In",
379
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faMagnifyingGlassPlus })
380
+ }
381
+ ),
382
+ /* @__PURE__ */ jsx2(
383
+ "button",
384
+ {
385
+ type: "button",
386
+ className: "tbib-iv-btn",
387
+ onClick: onZoomReset,
388
+ title: "Reset Fit to Screen (0)",
389
+ "aria-label": "Reset Zoom",
390
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faExpand })
391
+ }
392
+ ),
393
+ /* @__PURE__ */ jsx2(
394
+ "button",
395
+ {
396
+ type: "button",
397
+ className: "tbib-iv-btn",
398
+ onClick: onRotate,
399
+ title: "Rotate 90\xB0 Clockwise",
400
+ "aria-label": "Rotate Image",
401
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faRotate })
402
+ }
403
+ ),
404
+ /* @__PURE__ */ jsx2("div", { className: "tbib-iv-divider" }),
405
+ /* @__PURE__ */ jsx2(
406
+ DownloadMenu,
407
+ {
408
+ onDownloadAnnotated,
409
+ onDownloadClean,
410
+ onExportJson
411
+ }
412
+ ),
413
+ onToggleFullscreen && /* @__PURE__ */ jsx2(
414
+ "button",
415
+ {
416
+ type: "button",
417
+ className: "tbib-iv-btn",
418
+ onClick: onToggleFullscreen,
419
+ title: isFullscreen ? "Exit Fullscreen" : "Enter Fullscreen",
420
+ "aria-label": "Toggle Fullscreen",
421
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: isFullscreen ? faCompressAlt : faExpandAlt })
422
+ }
423
+ ),
424
+ onClose && /* @__PURE__ */ jsxs2(Fragment, { children: [
425
+ /* @__PURE__ */ jsx2("div", { className: "tbib-iv-divider" }),
426
+ /* @__PURE__ */ jsx2(
427
+ "button",
428
+ {
429
+ type: "button",
430
+ className: "tbib-iv-btn",
431
+ onClick: onClose,
432
+ title: "Close Viewer (Esc)",
433
+ "aria-label": "Close",
434
+ style: { color: "#ef4444" },
435
+ children: /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faXmark, style: { fontSize: "16px" } })
436
+ }
437
+ )
438
+ ] })
439
+ ] }),
440
+ showSubtoolbar && /* @__PURE__ */ jsxs2("div", { className: "tbib-iv-subtoolbar", role: "region", "aria-label": "Tool customization", children: [
441
+ activeTool !== "laser" && /* @__PURE__ */ jsx2("div", { className: "tbib-iv-thickness-group", children: THICKNESS_OPTIONS.map((opt) => /* @__PURE__ */ jsxs2(
442
+ "button",
443
+ {
444
+ type: "button",
445
+ className: `tbib-iv-thickness-btn ${strokeWidth === opt.value ? "tbib-iv-thickness-active" : ""}`,
446
+ onClick: () => onStrokeWidthChange(opt.value),
447
+ title: `${opt.label} stroke (${opt.value}px)`,
448
+ children: [
449
+ /* @__PURE__ */ jsx2(
450
+ "span",
451
+ {
452
+ style: {
453
+ display: "inline-block",
454
+ width: `${Math.min(opt.value * 1.5, 12)}px`,
455
+ height: `${Math.min(opt.value * 1.5, 12)}px`,
456
+ borderRadius: "50%",
457
+ backgroundColor: "currentColor"
458
+ }
459
+ }
460
+ ),
461
+ /* @__PURE__ */ jsx2("span", { children: opt.label })
462
+ ]
463
+ },
464
+ opt.value
465
+ )) }),
466
+ activeTool === "laser" && /* @__PURE__ */ jsx2("span", { style: { fontSize: "11px", color: "var(--tbib-iv-text-muted)", fontStyle: "italic", paddingRight: "4px" }, children: "Laser Beam Color:" }),
467
+ /* @__PURE__ */ jsx2("div", { className: "tbib-iv-divider", style: { height: "16px", margin: "0 2px" } }),
468
+ /* @__PURE__ */ jsxs2("div", { style: { display: "inline-flex", alignItems: "center", gap: "6px" }, children: [
469
+ PRESET_COLORS.map((c) => {
470
+ const isSelected = color.toLowerCase() === c.toLowerCase();
471
+ return /* @__PURE__ */ jsx2(
472
+ "button",
473
+ {
474
+ type: "button",
475
+ className: `tbib-iv-swatch-btn ${isSelected ? "tbib-iv-swatch-active" : ""}`,
476
+ style: { backgroundColor: c },
477
+ onClick: () => onColorChange(c),
478
+ title: `Select color: ${c}`,
479
+ "aria-label": `Color ${c}`
480
+ },
481
+ c
482
+ );
483
+ }),
484
+ /* @__PURE__ */ jsxs2("label", { className: "tbib-iv-custom-color-btn", title: "Custom Color Picker", children: [
485
+ /* @__PURE__ */ jsx2(FontAwesomeIcon2, { icon: faEyeDropper, style: { fontSize: "10px", opacity: 0.8 } }),
486
+ /* @__PURE__ */ jsx2(
487
+ "input",
488
+ {
489
+ type: "color",
490
+ value: color,
491
+ onChange: (e) => onColorChange(e.target.value),
492
+ className: "tbib-iv-custom-color-input",
493
+ "aria-label": "Custom color picker"
494
+ }
495
+ )
496
+ ] })
497
+ ] })
498
+ ] })
499
+ ] });
500
+ };
501
+
502
+ // src/components/AnnotationCanvas.tsx
503
+ import { useRef as useRef2, useState as useState2, useCallback, useMemo } from "react";
504
+ import {
505
+ pointsToSvgPath,
506
+ hexToRgba
507
+ } from "@tbib-image-viewer/core";
508
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
509
+ var AnnotationCanvas = ({
510
+ width,
511
+ height,
512
+ strokes,
513
+ activeTool,
514
+ color,
515
+ strokeWidth,
516
+ onStrokeComplete,
517
+ onEraseStroke
518
+ }) => {
519
+ const [currentPoints, setCurrentPoints] = useState2(null);
520
+ const isDrawingRef = useRef2(false);
521
+ const svgRef = useRef2(null);
522
+ const isDrawableTool = activeTool === "pen" || activeTool === "highlighter";
523
+ const isEraser = activeTool === "eraser";
524
+ const getNormalizedPoint = useCallback(
525
+ (e) => {
526
+ const svg = svgRef.current;
527
+ if (!svg || width <= 0 || height <= 0) return null;
528
+ const rect = svg.getBoundingClientRect();
529
+ const x = (e.clientX - rect.left) / rect.width;
530
+ const y = (e.clientY - rect.top) / rect.height;
531
+ return {
532
+ x: Math.max(0, Math.min(1, x)),
533
+ y: Math.max(0, Math.min(1, y)),
534
+ pressure: e.pressure || 0.5
535
+ };
536
+ },
537
+ [width, height]
538
+ );
539
+ const handlePointerDown = (e) => {
540
+ if (!isDrawableTool && !isEraser) return;
541
+ e.stopPropagation();
542
+ e.target.setPointerCapture?.(e.pointerId);
543
+ const pt = getNormalizedPoint(e);
544
+ if (!pt) return;
545
+ if (isEraser) {
546
+ onEraseStroke(pt);
547
+ isDrawingRef.current = true;
548
+ return;
549
+ }
550
+ if (isDrawableTool) {
551
+ isDrawingRef.current = true;
552
+ setCurrentPoints([pt]);
553
+ }
554
+ };
555
+ const handlePointerMove = (e) => {
556
+ if (!isDrawingRef.current) return;
557
+ e.stopPropagation();
558
+ const pt = getNormalizedPoint(e);
559
+ if (!pt) return;
560
+ if (isEraser) {
561
+ onEraseStroke(pt);
562
+ return;
563
+ }
564
+ if (isDrawableTool) {
565
+ setCurrentPoints((prev) => prev ? [...prev, pt] : [pt]);
566
+ }
567
+ };
568
+ const handlePointerUp = (e) => {
569
+ if (!isDrawingRef.current) return;
570
+ e.stopPropagation();
571
+ isDrawingRef.current = false;
572
+ if (isDrawableTool && currentPoints && currentPoints.length > 0) {
573
+ const isHighlighter = activeTool === "highlighter";
574
+ const newStroke = {
575
+ id: `stroke-${Date.now()}-${Math.random().toString(36).substring(2, 7)}`,
576
+ tool: isHighlighter ? "highlighter" : "pen",
577
+ color,
578
+ width: isHighlighter ? strokeWidth * 2.5 : strokeWidth,
579
+ opacity: isHighlighter ? 0.35 : 1,
580
+ points: currentPoints,
581
+ createdAt: Date.now()
582
+ };
583
+ onStrokeComplete(newStroke);
584
+ setCurrentPoints(null);
585
+ }
586
+ };
587
+ const currentPathD = useMemo(() => {
588
+ if (!currentPoints || currentPoints.length === 0) return "";
589
+ return pointsToSvgPath(currentPoints, width, height);
590
+ }, [currentPoints, width, height]);
591
+ const pointerEventsStyle = isDrawableTool || isEraser ? "auto" : "none";
592
+ return /* @__PURE__ */ jsxs3(
593
+ "svg",
594
+ {
595
+ ref: svgRef,
596
+ className: "tbib-iv-annotation-svg",
597
+ viewBox: `0 0 ${width} ${height}`,
598
+ style: {
599
+ width: "100%",
600
+ height: "100%",
601
+ pointerEvents: pointerEventsStyle,
602
+ touchAction: "none",
603
+ cursor: isEraser ? "crosshair" : isDrawableTool ? "crosshair" : "default"
604
+ },
605
+ onPointerDown: handlePointerDown,
606
+ onPointerMove: handlePointerMove,
607
+ onPointerUp: handlePointerUp,
608
+ onPointerCancel: handlePointerUp,
609
+ children: [
610
+ /* @__PURE__ */ jsx3("defs", { children: /* @__PURE__ */ jsx3("filter", { id: "highlighter-blend", children: /* @__PURE__ */ jsx3("feBlend", { mode: "multiply" }) }) }),
611
+ strokes.map((stroke) => {
612
+ const d = pointsToSvgPath(stroke.points, width, height);
613
+ const isHighlighter = stroke.tool === "highlighter";
614
+ return /* @__PURE__ */ jsx3(
615
+ "path",
616
+ {
617
+ d,
618
+ fill: "none",
619
+ stroke: isHighlighter ? hexToRgba(stroke.color, stroke.opacity || 0.35) : stroke.color,
620
+ strokeWidth: stroke.width,
621
+ strokeLinecap: "round",
622
+ strokeLinejoin: "round",
623
+ style: {
624
+ mixBlendMode: isHighlighter ? "multiply" : "normal",
625
+ pointerEvents: "none"
626
+ }
627
+ },
628
+ stroke.id
629
+ );
630
+ }),
631
+ currentPathD && /* @__PURE__ */ jsx3(
632
+ "path",
633
+ {
634
+ d: currentPathD,
635
+ fill: "none",
636
+ stroke: activeTool === "highlighter" ? hexToRgba(color, 0.35) : color,
637
+ strokeWidth: activeTool === "highlighter" ? strokeWidth * 2.5 : strokeWidth,
638
+ strokeLinecap: "round",
639
+ strokeLinejoin: "round",
640
+ style: {
641
+ mixBlendMode: activeTool === "highlighter" ? "multiply" : "normal",
642
+ pointerEvents: "none"
643
+ }
644
+ }
645
+ )
646
+ ]
647
+ }
648
+ );
649
+ };
650
+
651
+ // src/components/LaserCursorLayer.tsx
652
+ import { useEffect as useEffect2, useRef as useRef3 } from "react";
653
+ import { Mesh, Program, Renderer, Triangle } from "ogl";
654
+ import { jsx as jsx4 } from "react/jsx-runtime";
655
+ var MAX_POINTS = 64;
656
+ var VERTEX_SHADER = `
657
+ attribute vec2 position;
658
+ attribute vec2 uv;
659
+ varying vec2 vUv;
660
+
661
+ void main() {
662
+ vUv = uv;
663
+ gl_Position = vec4(position, 0.0, 1.0);
664
+ }
665
+ `;
666
+ var FRAGMENT_SHADER = `
667
+ precision highp float;
668
+
669
+ #define MAX_POINTS 64
670
+
671
+ uniform vec2 uResolution;
672
+ uniform vec2 uPoints[MAX_POINTS];
673
+ uniform float uPointCount;
674
+ uniform vec3 uColor;
675
+ uniform vec3 uSecondaryColor;
676
+ uniform float uTrailWidth;
677
+ uniform float uTaper;
678
+ uniform float uGlowIntensity;
679
+ uniform float uGlowSpread;
680
+ uniform float uHotspot;
681
+ uniform float uBrightness;
682
+ uniform float uOpacity;
683
+ uniform float uPulseSpeed;
684
+ uniform float uNoiseStrength;
685
+ uniform float uTime;
686
+ uniform float uFade;
687
+
688
+ varying vec2 vUv;
689
+
690
+ float sRGB(float x) {
691
+ if (x <= 0.00031308) return 12.92 * x;
692
+ return 1.055 * pow(x, 1.0 / 2.4) - 0.055;
693
+ }
694
+
695
+ float hash(vec2 p) {
696
+ return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
697
+ }
698
+
699
+ float filmGrain(vec2 p, float time) {
700
+ float frame = time * 18.0;
701
+ float frameIndex = mod(floor(frame), 256.0);
702
+ float nextFrameIndex = mod(frameIndex + 1.0, 256.0);
703
+ float blend = fract(frame);
704
+ blend = blend * blend * (3.0 - 2.0 * blend);
705
+ vec2 pixel = floor(p);
706
+ float current = hash(pixel + vec2(frameIndex * 17.0, frameIndex * 31.0));
707
+ float next = hash(pixel + vec2(nextFrameIndex * 17.0, nextFrameIndex * 31.0));
708
+ return mix(current, next, blend) * 2.0 - 1.0;
709
+ }
710
+
711
+ void main() {
712
+ vec2 pixel = vUv * uResolution;
713
+ float denominator = max(uPointCount - 1.0, 1.0);
714
+ float strongest = 0.0;
715
+ float strongestCore = 0.0;
716
+ float colorWeight = 0.0;
717
+ vec3 colorSum = vec3(0.0);
718
+
719
+ for (int i = 0; i < MAX_POINTS - 1; i++) {
720
+ float index = float(i);
721
+ vec2 start = uPoints[i];
722
+ vec2 end = uPoints[i + 1];
723
+ vec2 toPixel = pixel - start;
724
+ vec2 segment = end - start;
725
+ float along = clamp(dot(toPixel, segment) / max(dot(segment, segment), 0.0001), 0.0, 1.0);
726
+ float progress = clamp((index + along) / denominator, 0.0, 1.0);
727
+ float life = pow(max(1.0 - progress, 0.0), mix(0.55, 1.25, uTaper));
728
+ float width = uTrailWidth * mix(1.0, 0.25, pow(progress, mix(0.55, 1.6, uTaper)));
729
+ float distanceToTrail = length(toPixel - segment * along);
730
+ float falloff = max(width * (0.8 + uGlowSpread * 1.4), 0.5);
731
+ float beam = min(1.0, (falloff * falloff) / (distanceToTrail * distanceToTrail + falloff * falloff));
732
+ float core = exp(-pow(distanceToTrail / max(width, 0.5), 2.0) * 2.5);
733
+ float pulseAmount = min(abs(uPulseSpeed), 1.0);
734
+ float pulse = 1.0 + sin(uTime * uPulseSpeed * 3.0 - progress * 11.0) * 0.16 * pulseAmount;
735
+ float intensity = (core + beam * uGlowIntensity * 0.55) * life * pulse;
736
+ vec3 segmentColor = mix(uColor, uSecondaryColor, progress);
737
+
738
+ strongest = max(strongest, intensity);
739
+ strongestCore = max(strongestCore, core * life);
740
+ colorSum += segmentColor * intensity;
741
+ colorWeight += intensity;
742
+ }
743
+
744
+ float grain = filmGrain(pixel, uTime);
745
+ float noiseAmount = (1.0 - exp(-uNoiseStrength * 2.2)) * 0.4;
746
+ float alpha = clamp(strongest * uOpacity * uFade, 0.0, 1.0);
747
+ if (alpha < 0.0005) discard;
748
+
749
+ vec3 color = colorSum / max(colorWeight, 0.0001);
750
+ color = mix(color, vec3(1.0), smoothstep(0.25, 0.95, strongestCore) * uHotspot);
751
+ float luminance = sRGB(clamp(strongest * uBrightness, 0.0, 1.0));
752
+ luminance *= 1.0 + grain * noiseAmount;
753
+ vec3 additiveColor = color * luminance;
754
+ float normalAlpha = clamp(strongest * uBrightness * uOpacity * uFade, 0.0, 1.0);
755
+ vec3 normalColor = mix(color, vec3(1.0), smoothstep(0.45, 1.0, strongestCore) * uHotspot * 0.35);
756
+ gl_FragColor = vec4(mix(additiveColor, normalColor, 1.0), mix(alpha, normalAlpha, 1.0));
757
+ }
758
+ `;
759
+ function hexToRgb(hex) {
760
+ let value = (hex || "").replace("#", "").trim();
761
+ if (value.length === 3) {
762
+ value = value.split("").map((c) => c + c).join("");
763
+ }
764
+ const parsed = Number.parseInt(value || "ff0000", 16);
765
+ return [
766
+ (parsed >> 16 & 255) / 255,
767
+ (parsed >> 8 & 255) / 255,
768
+ (parsed & 255) / 255
769
+ ];
770
+ }
771
+ var LaserCursorLayer = ({
772
+ color = "#ef4444",
773
+ secondaryColor = "#ef4444",
774
+ trailLength = 29,
775
+ trailWidth = 8,
776
+ trailTaper = 0.22,
777
+ followSpeed = 1.5,
778
+ glowIntensity = 1.9,
779
+ glowSpread = 0.1,
780
+ hotspot = 0.5,
781
+ brightness = 1.25,
782
+ opacity = 1,
783
+ pulseSpeed = 0.8,
784
+ noiseStrength = 0.035,
785
+ idleFade = true,
786
+ idleTimeout = 700,
787
+ fadeDuration = 1500,
788
+ enabled = true,
789
+ className = "",
790
+ style,
791
+ ...rest
792
+ }) => {
793
+ const containerRef = useRef3(null);
794
+ const canvasRef = useRef3(null);
795
+ useEffect2(() => {
796
+ const container = containerRef.current;
797
+ const canvas = canvasRef.current;
798
+ if (!container || !canvas || !enabled) return;
799
+ let renderer = null;
800
+ try {
801
+ renderer = new Renderer({
802
+ canvas,
803
+ alpha: true,
804
+ dpr: Math.min(window.devicePixelRatio || 1, 1.5)
805
+ });
806
+ } catch {
807
+ return;
808
+ }
809
+ const gl = renderer.gl;
810
+ gl.clearColor(0, 0, 0, 0);
811
+ const pointData = Array(MAX_POINTS * 2).fill(0);
812
+ const points = Array.from({ length: MAX_POINTS }, () => ({ x: 0, y: 0 }));
813
+ const target = { x: 0, y: 0 };
814
+ const head = { x: 0, y: 0 };
815
+ let program;
816
+ let mesh;
817
+ try {
818
+ program = new Program(gl, {
819
+ vertex: VERTEX_SHADER,
820
+ fragment: FRAGMENT_SHADER,
821
+ uniforms: {
822
+ uResolution: { value: [1, 1] },
823
+ uPoints: { value: pointData },
824
+ uPointCount: { value: trailLength },
825
+ uColor: { value: hexToRgb(color) },
826
+ uSecondaryColor: { value: hexToRgb(secondaryColor) },
827
+ uTrailWidth: { value: trailWidth },
828
+ uTaper: { value: trailTaper },
829
+ uGlowIntensity: { value: glowIntensity },
830
+ uGlowSpread: { value: glowSpread },
831
+ uHotspot: { value: hotspot },
832
+ uBrightness: { value: brightness },
833
+ uOpacity: { value: opacity },
834
+ uPulseSpeed: { value: pulseSpeed },
835
+ uNoiseStrength: { value: noiseStrength },
836
+ uTime: { value: 0 },
837
+ uFade: { value: 0 }
838
+ },
839
+ transparent: true,
840
+ depthTest: false,
841
+ depthWrite: false
842
+ });
843
+ mesh = new Mesh(gl, { geometry: new Triangle(gl), program });
844
+ } catch {
845
+ return;
846
+ }
847
+ let width = 0;
848
+ let height = 0;
849
+ let isHovered = false;
850
+ let lastMoveTime = 0;
851
+ let animationId;
852
+ const resize = () => {
853
+ const rect = container.getBoundingClientRect();
854
+ const newWidth = Math.floor(rect.width);
855
+ const newHeight = Math.floor(rect.height);
856
+ if (newWidth <= 0 || newHeight <= 0) return;
857
+ if (newWidth === width && newHeight === height) return;
858
+ width = newWidth;
859
+ height = newHeight;
860
+ renderer?.setSize(width, height);
861
+ program.uniforms.uResolution.value = [width, height];
862
+ };
863
+ resize();
864
+ const resizeObserver = new ResizeObserver(resize);
865
+ resizeObserver.observe(container);
866
+ const onPointerMove = (e) => {
867
+ const rect = container.getBoundingClientRect();
868
+ target.x = e.clientX - rect.left;
869
+ target.y = rect.height - (e.clientY - rect.top);
870
+ lastMoveTime = performance.now();
871
+ isHovered = true;
872
+ };
873
+ const onPointerLeave = () => {
874
+ isHovered = false;
875
+ };
876
+ container.addEventListener("pointermove", onPointerMove);
877
+ container.addEventListener("pointerleave", onPointerLeave);
878
+ let lastTime = performance.now();
879
+ const render = (now) => {
880
+ animationId = requestAnimationFrame(render);
881
+ const dt = Math.min((now - lastTime) / 1e3, 0.1);
882
+ lastTime = now;
883
+ const speed = followSpeed * 20;
884
+ head.x += (target.x - head.x) * Math.min(dt * speed, 1);
885
+ head.y += (target.y - head.y) * Math.min(dt * speed, 1);
886
+ for (let i = MAX_POINTS - 1; i > 0; i--) {
887
+ points[i].x = points[i - 1].x;
888
+ points[i].y = points[i - 1].y;
889
+ }
890
+ points[0].x = head.x;
891
+ points[0].y = head.y;
892
+ for (let i = 0; i < MAX_POINTS; i++) {
893
+ pointData[i * 2] = points[i].x;
894
+ pointData[i * 2 + 1] = points[i].y;
895
+ }
896
+ program.uniforms.uTime.value = now * 1e-3;
897
+ let fade = 1;
898
+ if (idleFade) {
899
+ const idleTime = now - lastMoveTime;
900
+ if (!isHovered || idleTime > idleTimeout) {
901
+ const fadeProgress = Math.min(Math.max((idleTime - idleTimeout) / fadeDuration, 0), 1);
902
+ fade = 1 - fadeProgress;
903
+ }
904
+ }
905
+ program.uniforms.uFade.value = fade;
906
+ if (fade > 1e-3) {
907
+ renderer?.render({ scene: mesh });
908
+ } else {
909
+ gl.clear(gl.COLOR_BUFFER_BIT);
910
+ }
911
+ };
912
+ animationId = requestAnimationFrame(render);
913
+ return () => {
914
+ cancelAnimationFrame(animationId);
915
+ resizeObserver.disconnect();
916
+ container.removeEventListener("pointermove", onPointerMove);
917
+ container.removeEventListener("pointerleave", onPointerLeave);
918
+ };
919
+ }, [
920
+ color,
921
+ secondaryColor,
922
+ trailLength,
923
+ trailWidth,
924
+ trailTaper,
925
+ followSpeed,
926
+ glowIntensity,
927
+ glowSpread,
928
+ hotspot,
929
+ brightness,
930
+ opacity,
931
+ pulseSpeed,
932
+ noiseStrength,
933
+ idleFade,
934
+ idleTimeout,
935
+ fadeDuration,
936
+ enabled
937
+ ]);
938
+ return /* @__PURE__ */ jsx4(
939
+ "div",
940
+ {
941
+ ref: containerRef,
942
+ className: `tbib-iv-laser-layer ${className}`,
943
+ style: {
944
+ position: "absolute",
945
+ top: 0,
946
+ left: 0,
947
+ width: "100%",
948
+ height: "100%",
949
+ pointerEvents: "auto",
950
+ touchAction: "none",
951
+ cursor: "crosshair",
952
+ zIndex: 30,
953
+ overflow: "hidden",
954
+ ...style
955
+ },
956
+ ...rest,
957
+ children: /* @__PURE__ */ jsx4(
958
+ "canvas",
959
+ {
960
+ ref: canvasRef,
961
+ className: "tbib-iv-laser-canvas",
962
+ style: {
963
+ position: "absolute",
964
+ top: 0,
965
+ left: 0,
966
+ width: "100%",
967
+ height: "100%",
968
+ display: "block",
969
+ pointerEvents: "none"
970
+ }
971
+ }
972
+ )
973
+ }
974
+ );
975
+ };
976
+
977
+ // src/hooks/useImageTransform.ts
978
+ import { useState as useState3, useCallback as useCallback2, useRef as useRef4 } from "react";
979
+ import { clampScale, DEFAULT_TRANSFORM } from "@tbib-image-viewer/core";
980
+ function useImageTransform() {
981
+ const [transform, setTransform] = useState3(DEFAULT_TRANSFORM);
982
+ const pinchStartDistRef = useRef4(null);
983
+ const pinchStartScaleRef = useRef4(1);
984
+ const zoomIn = useCallback2(() => {
985
+ setTransform((prev) => ({
986
+ ...prev,
987
+ scale: clampScale(prev.scale * 1.25)
988
+ }));
989
+ }, []);
990
+ const zoomOut = useCallback2(() => {
991
+ setTransform((prev) => ({
992
+ ...prev,
993
+ scale: clampScale(prev.scale / 1.25)
994
+ }));
995
+ }, []);
996
+ const resetTransform = useCallback2(() => {
997
+ setTransform(DEFAULT_TRANSFORM);
998
+ }, []);
999
+ const rotateClockwise = useCallback2(() => {
1000
+ setTransform((prev) => ({
1001
+ ...prev,
1002
+ rotate: (prev.rotate + 90) % 360
1003
+ }));
1004
+ }, []);
1005
+ const panBy = useCallback2((dx, dy) => {
1006
+ setTransform((prev) => ({
1007
+ ...prev,
1008
+ translateX: prev.translateX + dx,
1009
+ translateY: prev.translateY + dy
1010
+ }));
1011
+ }, []);
1012
+ const handleWheel = useCallback2((e) => {
1013
+ e.preventDefault();
1014
+ const factor = e.deltaY < 0 ? 1.15 : 1 / 1.15;
1015
+ setTransform((prev) => ({
1016
+ ...prev,
1017
+ scale: clampScale(prev.scale * factor)
1018
+ }));
1019
+ }, []);
1020
+ const handleTouchStart = useCallback2((e) => {
1021
+ if (e.touches.length === 2) {
1022
+ const t1 = e.touches[0];
1023
+ const t2 = e.touches[1];
1024
+ const dist = Math.hypot(t1.clientX - t2.clientX, t1.clientY - t2.clientY);
1025
+ pinchStartDistRef.current = dist;
1026
+ pinchStartScaleRef.current = transform.scale;
1027
+ }
1028
+ }, [transform.scale]);
1029
+ const handleTouchMove = useCallback2((e) => {
1030
+ if (e.touches.length === 2 && pinchStartDistRef.current !== null) {
1031
+ const t1 = e.touches[0];
1032
+ const t2 = e.touches[1];
1033
+ const dist = Math.hypot(t1.clientX - t2.clientX, t1.clientY - t2.clientY);
1034
+ const ratio = dist / pinchStartDistRef.current;
1035
+ setTransform((prev) => ({
1036
+ ...prev,
1037
+ scale: clampScale(pinchStartScaleRef.current * ratio)
1038
+ }));
1039
+ }
1040
+ }, []);
1041
+ const handleTouchEnd = useCallback2(() => {
1042
+ pinchStartDistRef.current = null;
1043
+ }, []);
1044
+ return {
1045
+ transform,
1046
+ setTransform,
1047
+ zoomIn,
1048
+ zoomOut,
1049
+ resetTransform,
1050
+ rotateClockwise,
1051
+ panBy,
1052
+ handleWheel,
1053
+ handleTouchStart,
1054
+ handleTouchMove,
1055
+ handleTouchEnd
1056
+ };
1057
+ }
1058
+
1059
+ // src/components/ImageViewer.tsx
1060
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1061
+ var ImageViewer = ({
1062
+ src,
1063
+ alt = "Medical illustration",
1064
+ className = "",
1065
+ style,
1066
+ theme = "dark",
1067
+ initialTool = "hand",
1068
+ initialColor = "#ef4444",
1069
+ initialStrokeWidth = 4,
1070
+ showToolbar = true,
1071
+ enableAnnotations = true,
1072
+ enableLaser = true,
1073
+ slideId,
1074
+ initialAnnotations,
1075
+ onAnnotationsChange,
1076
+ children
1077
+ }) => {
1078
+ const effectiveSlideId = useMemo2(() => slideId || src, [slideId, src]);
1079
+ const [activeTool, setActiveTool] = useState4(initialTool);
1080
+ const [color, setColor] = useState4(initialColor);
1081
+ const [strokeWidth, setStrokeWidth] = useState4(initialStrokeWidth);
1082
+ const storeRef = useRef5(
1083
+ new AnnotationStore(
1084
+ initialAnnotations ? [{ slideId: effectiveSlideId, strokes: initialAnnotations }] : void 0
1085
+ )
1086
+ );
1087
+ const [strokes, setStrokes] = useState4(
1088
+ () => storeRef.current.getStrokes(effectiveSlideId)
1089
+ );
1090
+ const [canUndo, setCanUndo] = useState4(false);
1091
+ const [canRedo, setCanRedo] = useState4(false);
1092
+ const containerRef = useRef5(null);
1093
+ const imgRef = useRef5(null);
1094
+ const [imgSize, setImgSize] = useState4({ width: 800, height: 600 });
1095
+ const [imageStatus, setImageStatus] = useState4("loading");
1096
+ const [reloadKey, setReloadKey] = useState4(0);
1097
+ const effectiveSrc = useMemo2(() => {
1098
+ if (!src) return "";
1099
+ if (reloadKey === 0) return src;
1100
+ const sep = src.includes("?") ? "&" : "?";
1101
+ return `${src}${sep}_reload=${reloadKey}`;
1102
+ }, [src, reloadKey]);
1103
+ useEffect3(() => {
1104
+ setImageStatus("loading");
1105
+ if (imgRef.current && imgRef.current.complete && imgRef.current.naturalWidth > 0) {
1106
+ setImgSize({
1107
+ width: imgRef.current.naturalWidth,
1108
+ height: imgRef.current.naturalHeight
1109
+ });
1110
+ setImageStatus("loaded");
1111
+ }
1112
+ }, [src, reloadKey]);
1113
+ const {
1114
+ transform,
1115
+ zoomIn,
1116
+ zoomOut,
1117
+ resetTransform,
1118
+ rotateClockwise,
1119
+ panBy,
1120
+ handleWheel,
1121
+ handleTouchStart,
1122
+ handleTouchMove,
1123
+ handleTouchEnd
1124
+ } = useImageTransform();
1125
+ const isDraggingRef = useRef5(false);
1126
+ const lastMousePosRef = useRef5({ x: 0, y: 0 });
1127
+ useEffect3(() => {
1128
+ const store = storeRef.current;
1129
+ const unsubscribe = store.subscribe((id, updated) => {
1130
+ if (id === effectiveSlideId) {
1131
+ setStrokes(updated);
1132
+ setCanUndo(store.canUndo(effectiveSlideId));
1133
+ setCanRedo(store.canRedo(effectiveSlideId));
1134
+ onAnnotationsChange?.(updated);
1135
+ }
1136
+ });
1137
+ setStrokes(store.getStrokes(effectiveSlideId));
1138
+ setCanUndo(store.canUndo(effectiveSlideId));
1139
+ setCanRedo(store.canRedo(effectiveSlideId));
1140
+ return unsubscribe;
1141
+ }, [effectiveSlideId, onAnnotationsChange]);
1142
+ const handleImageLoad = (e) => {
1143
+ const img = e.currentTarget;
1144
+ setImgSize({
1145
+ width: img.naturalWidth || img.width,
1146
+ height: img.naturalHeight || img.height
1147
+ });
1148
+ setImageStatus("loaded");
1149
+ };
1150
+ const handleImageError = () => {
1151
+ setImageStatus("error");
1152
+ };
1153
+ const handleReload = () => {
1154
+ setImageStatus("loading");
1155
+ setReloadKey((prev) => prev + 1);
1156
+ };
1157
+ const handleStrokeComplete = useCallback3(
1158
+ (newStroke) => {
1159
+ storeRef.current.addStroke(effectiveSlideId, newStroke);
1160
+ },
1161
+ [effectiveSlideId]
1162
+ );
1163
+ const handleEraseStroke = useCallback3(
1164
+ (point) => {
1165
+ storeRef.current.removeStrokesNear(
1166
+ effectiveSlideId,
1167
+ point,
1168
+ 0.03,
1169
+ // 3% hit radius in normalized coordinates
1170
+ isPointNearStroke2
1171
+ );
1172
+ },
1173
+ [effectiveSlideId]
1174
+ );
1175
+ const handleUndo = useCallback3(() => {
1176
+ storeRef.current.undo(effectiveSlideId);
1177
+ }, [effectiveSlideId]);
1178
+ const handleRedo = useCallback3(() => {
1179
+ storeRef.current.redo(effectiveSlideId);
1180
+ }, [effectiveSlideId]);
1181
+ const handleClear = useCallback3(() => {
1182
+ storeRef.current.clear(effectiveSlideId);
1183
+ }, [effectiveSlideId]);
1184
+ const handleStagePointerDown = (e) => {
1185
+ if (activeTool !== "hand") return;
1186
+ isDraggingRef.current = true;
1187
+ lastMousePosRef.current = { x: e.clientX, y: e.clientY };
1188
+ e.target.setPointerCapture?.(e.pointerId);
1189
+ };
1190
+ const handleStagePointerMove = (e) => {
1191
+ if (!isDraggingRef.current || activeTool !== "hand") return;
1192
+ const dx = e.clientX - lastMousePosRef.current.x;
1193
+ const dy = e.clientY - lastMousePosRef.current.y;
1194
+ lastMousePosRef.current = { x: e.clientX, y: e.clientY };
1195
+ panBy(dx, dy);
1196
+ };
1197
+ const handleStagePointerUp = (e) => {
1198
+ isDraggingRef.current = false;
1199
+ };
1200
+ useEffect3(() => {
1201
+ const handleKeyDown = (e) => {
1202
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z") {
1203
+ e.preventDefault();
1204
+ if (e.shiftKey) {
1205
+ handleRedo();
1206
+ } else {
1207
+ handleUndo();
1208
+ }
1209
+ } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "y") {
1210
+ e.preventDefault();
1211
+ handleRedo();
1212
+ } else if (e.key === "+" || e.key === "=") {
1213
+ zoomIn();
1214
+ } else if (e.key === "-") {
1215
+ zoomOut();
1216
+ } else if (e.key === "0") {
1217
+ resetTransform();
1218
+ }
1219
+ };
1220
+ window.addEventListener("keydown", handleKeyDown);
1221
+ return () => window.removeEventListener("keydown", handleKeyDown);
1222
+ }, [handleUndo, handleRedo, zoomIn, zoomOut, resetTransform]);
1223
+ const handleDownloadAnnotated = async () => {
1224
+ if (!imgRef.current) return;
1225
+ await downloadAnnotatedImage(imgRef.current, strokes, {
1226
+ format: "image/png",
1227
+ includeAnnotations: true,
1228
+ fileName: `tbib-annotated-${Date.now()}.png`
1229
+ });
1230
+ };
1231
+ const handleDownloadClean = async () => {
1232
+ if (!imgRef.current) return;
1233
+ await downloadAnnotatedImage(imgRef.current, [], {
1234
+ format: "image/png",
1235
+ includeAnnotations: false,
1236
+ fileName: `tbib-clean-${Date.now()}.png`
1237
+ });
1238
+ };
1239
+ const handleExportJson = () => {
1240
+ const data = storeRef.current.exportJSON();
1241
+ const blob = new Blob([JSON.stringify(data, null, 2)], {
1242
+ type: "application/json"
1243
+ });
1244
+ const url = URL.createObjectURL(blob);
1245
+ const link = document.createElement("a");
1246
+ link.href = url;
1247
+ link.download = `tbib-annotations-${Date.now()}.json`;
1248
+ link.click();
1249
+ setTimeout(() => URL.revokeObjectURL(url), 1e3);
1250
+ };
1251
+ return /* @__PURE__ */ jsxs4(
1252
+ "div",
1253
+ {
1254
+ ref: containerRef,
1255
+ className: `tbib-iv-container ${theme === "light" ? "tbib-iv-light" : ""} ${className}`,
1256
+ style,
1257
+ children: [
1258
+ showToolbar && /* @__PURE__ */ jsx5(
1259
+ ImageToolbar,
1260
+ {
1261
+ activeTool,
1262
+ onToolChange: setActiveTool,
1263
+ color,
1264
+ onColorChange: setColor,
1265
+ strokeWidth,
1266
+ onStrokeWidthChange: setStrokeWidth,
1267
+ canUndo,
1268
+ canRedo,
1269
+ onUndo: handleUndo,
1270
+ onRedo: handleRedo,
1271
+ onClear: handleClear,
1272
+ zoomScale: transform.scale,
1273
+ onZoomIn: zoomIn,
1274
+ onZoomOut: zoomOut,
1275
+ onZoomReset: resetTransform,
1276
+ onRotate: rotateClockwise,
1277
+ onDownloadAnnotated: handleDownloadAnnotated,
1278
+ onDownloadClean: handleDownloadClean,
1279
+ onExportJson: handleExportJson
1280
+ }
1281
+ ),
1282
+ /* @__PURE__ */ jsxs4(
1283
+ "div",
1284
+ {
1285
+ className: "tbib-iv-stage",
1286
+ onWheel: handleWheel,
1287
+ onTouchStart: handleTouchStart,
1288
+ onTouchMove: handleTouchMove,
1289
+ onTouchEnd: handleTouchEnd,
1290
+ onPointerDown: handleStagePointerDown,
1291
+ onPointerMove: handleStagePointerMove,
1292
+ onPointerUp: handleStagePointerUp,
1293
+ onPointerCancel: handleStagePointerUp,
1294
+ style: {
1295
+ cursor: activeTool === "hand" ? isDraggingRef.current ? "grabbing" : "grab" : "default"
1296
+ },
1297
+ children: [
1298
+ /* @__PURE__ */ jsxs4(
1299
+ "div",
1300
+ {
1301
+ className: "tbib-iv-stage-inner",
1302
+ style: {
1303
+ transform: `translate3d(${transform.translateX}px, ${transform.translateY}px, 0) scale(${transform.scale}) rotate(${transform.rotate}deg)`,
1304
+ transition: isDraggingRef.current ? "none" : "transform 0.05s ease-out"
1305
+ },
1306
+ children: [
1307
+ /* @__PURE__ */ jsx5(
1308
+ "img",
1309
+ {
1310
+ ref: imgRef,
1311
+ src: effectiveSrc,
1312
+ alt,
1313
+ className: `tbib-iv-image ${imageStatus === "loaded" ? "tbib-iv-image-loaded" : "tbib-iv-image-loading"}`,
1314
+ onLoad: handleImageLoad,
1315
+ onError: handleImageError,
1316
+ draggable: false
1317
+ },
1318
+ `${src}-${reloadKey}`
1319
+ ),
1320
+ enableAnnotations && imageStatus === "loaded" && /* @__PURE__ */ jsx5(
1321
+ AnnotationCanvas,
1322
+ {
1323
+ width: imgSize.width,
1324
+ height: imgSize.height,
1325
+ strokes,
1326
+ activeTool,
1327
+ color,
1328
+ strokeWidth,
1329
+ onStrokeComplete: handleStrokeComplete,
1330
+ onEraseStroke: handleEraseStroke
1331
+ }
1332
+ )
1333
+ ]
1334
+ }
1335
+ ),
1336
+ imageStatus === "loading" && /* @__PURE__ */ jsxs4("div", { className: "tbib-iv-status-overlay", children: [
1337
+ /* @__PURE__ */ jsx5("div", { className: "tbib-iv-spinner", children: /* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faSpinner2, spin: true, className: "tbib-iv-spinner-icon" }) }),
1338
+ /* @__PURE__ */ jsx5("span", { className: "tbib-iv-status-text", children: "Chargement de l'illustration..." })
1339
+ ] }),
1340
+ imageStatus === "error" && /* @__PURE__ */ jsxs4("div", { className: "tbib-iv-status-overlay tbib-iv-error-card", children: [
1341
+ /* @__PURE__ */ jsx5("div", { className: "tbib-iv-error-icon", children: /* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faExclamationTriangle }) }),
1342
+ /* @__PURE__ */ jsx5("h3", { className: "tbib-iv-error-title", children: "Impossible de charger l'image" }),
1343
+ /* @__PURE__ */ jsx5("p", { className: "tbib-iv-error-desc", children: "Le fichier est temporairement inaccessible ou une erreur r\xE9seau est survenue." }),
1344
+ /* @__PURE__ */ jsxs4("div", { className: "tbib-iv-error-actions", children: [
1345
+ /* @__PURE__ */ jsxs4(
1346
+ "button",
1347
+ {
1348
+ type: "button",
1349
+ className: "tbib-iv-btn tbib-iv-btn-primary tbib-iv-retry-btn",
1350
+ onClick: handleReload,
1351
+ children: [
1352
+ /* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faRotateRight2 }),
1353
+ /* @__PURE__ */ jsx5("span", { children: "R\xE9essayer" })
1354
+ ]
1355
+ }
1356
+ ),
1357
+ src && /* @__PURE__ */ jsxs4(
1358
+ "a",
1359
+ {
1360
+ href: src,
1361
+ target: "_blank",
1362
+ rel: "noopener noreferrer",
1363
+ className: "tbib-iv-btn tbib-iv-open-btn",
1364
+ children: [
1365
+ /* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faExternalLinkAlt }),
1366
+ /* @__PURE__ */ jsx5("span", { children: "Lien direct" })
1367
+ ]
1368
+ }
1369
+ )
1370
+ ] })
1371
+ ] }),
1372
+ enableLaser && activeTool === "laser" && imageStatus === "loaded" && /* @__PURE__ */ jsx5(LaserCursorLayer, { color, secondaryColor: color, enabled: activeTool === "laser" })
1373
+ ]
1374
+ }
1375
+ ),
1376
+ children
1377
+ ]
1378
+ }
1379
+ );
1380
+ };
1381
+
1382
+ // src/components/ImageGalleryLightbox.tsx
1383
+ import { useState as useState5, useRef as useRef7, useEffect as useEffect4, useCallback as useCallback5, useMemo as useMemo3 } from "react";
1384
+ import { FontAwesomeIcon as FontAwesomeIcon4 } from "@fortawesome/react-fontawesome";
1385
+ import {
1386
+ faChevronLeft,
1387
+ faChevronRight,
1388
+ faSpinner as faSpinner3,
1389
+ faRotateRight as faRotateRight3
1390
+ } from "@fortawesome/free-solid-svg-icons";
1391
+ import { faExclamationTriangle as faExclamationTriangle2 } from "@fortawesome/free-solid-svg-icons/faExclamationTriangle";
1392
+ import { faExternalLinkAlt as faExternalLinkAlt2 } from "@fortawesome/free-solid-svg-icons/faExternalLinkAlt";
1393
+ import {
1394
+ AnnotationStore as AnnotationStore2,
1395
+ downloadAnnotatedImage as downloadAnnotatedImage2,
1396
+ isPointNearStroke as isPointNearStroke3
1397
+ } from "@tbib-image-viewer/core";
1398
+
1399
+ // src/components/ThumbnailStrip.tsx
1400
+ import { jsx as jsx6 } from "react/jsx-runtime";
1401
+ var ThumbnailStrip = ({
1402
+ items,
1403
+ activeIndex,
1404
+ onSelect
1405
+ }) => {
1406
+ if (items.length <= 1) return null;
1407
+ return /* @__PURE__ */ jsx6("div", { className: "tbib-iv-thumbnail-strip", children: items.map((item, idx) => /* @__PURE__ */ jsx6(
1408
+ "button",
1409
+ {
1410
+ type: "button",
1411
+ className: `tbib-iv-thumbnail-item ${idx === activeIndex ? "tbib-iv-thumbnail-item-active" : ""}`,
1412
+ onClick: () => onSelect(idx),
1413
+ title: item.title || `Image ${idx + 1}`,
1414
+ children: /* @__PURE__ */ jsx6(
1415
+ "img",
1416
+ {
1417
+ src: item.thumbnailSrc || item.src,
1418
+ alt: item.alt || `Thumb ${idx + 1}`,
1419
+ className: "tbib-iv-thumbnail-img",
1420
+ loading: "lazy"
1421
+ }
1422
+ )
1423
+ },
1424
+ item.id || idx
1425
+ )) });
1426
+ };
1427
+
1428
+ // src/hooks/useSwipeGesture.ts
1429
+ import { useRef as useRef6, useCallback as useCallback4 } from "react";
1430
+ function useSwipeGesture({ onSwipeLeft, onSwipeRight, enabled = true }) {
1431
+ const touchStartXRef = useRef6(null);
1432
+ const touchStartYRef = useRef6(null);
1433
+ const onTouchStart = useCallback4((e) => {
1434
+ if (!enabled || e.touches.length !== 1) return;
1435
+ touchStartXRef.current = e.touches[0].clientX;
1436
+ touchStartYRef.current = e.touches[0].clientY;
1437
+ }, [enabled]);
1438
+ const onTouchEnd = useCallback4((e) => {
1439
+ if (!enabled || touchStartXRef.current === null || touchStartYRef.current === null) return;
1440
+ const touchEndX = e.changedTouches[0].clientX;
1441
+ const touchEndY = e.changedTouches[0].clientY;
1442
+ const dx = touchEndX - touchStartXRef.current;
1443
+ const dy = touchEndY - touchStartYRef.current;
1444
+ if (Math.abs(dx) > Math.abs(dy) * 1.5 && Math.abs(dx) > 50) {
1445
+ if (dx < 0) {
1446
+ onSwipeLeft();
1447
+ } else {
1448
+ onSwipeRight();
1449
+ }
1450
+ }
1451
+ touchStartXRef.current = null;
1452
+ touchStartYRef.current = null;
1453
+ }, [enabled, onSwipeLeft, onSwipeRight]);
1454
+ return {
1455
+ onTouchStart,
1456
+ onTouchEnd
1457
+ };
1458
+ }
1459
+
1460
+ // src/components/ImageGalleryLightbox.tsx
1461
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1462
+ var ImageGalleryLightbox = ({
1463
+ items,
1464
+ activeIndex = 0,
1465
+ isOpen,
1466
+ onClose,
1467
+ onIndexChange,
1468
+ theme = "dark",
1469
+ initialTool = "hand",
1470
+ initialColor = "#ef4444",
1471
+ showThumbnails = true,
1472
+ initialAnnotations,
1473
+ onAnnotationsChange
1474
+ }) => {
1475
+ const [currentIndex, setCurrentIndex] = useState5(activeIndex);
1476
+ const [activeTool, setActiveTool] = useState5(initialTool);
1477
+ const [color, setColor] = useState5(initialColor);
1478
+ const [strokeWidth, setStrokeWidth] = useState5(4);
1479
+ const [isFullscreen, setIsFullscreen] = useState5(false);
1480
+ useEffect4(() => {
1481
+ setCurrentIndex(activeIndex);
1482
+ }, [activeIndex]);
1483
+ const currentItem = items[currentIndex] || items[0];
1484
+ const slideId = currentItem?.id || currentItem?.src || `slide-${currentIndex}`;
1485
+ const storeRef = useRef7(new AnnotationStore2(initialAnnotations));
1486
+ const [strokes, setStrokes] = useState5([]);
1487
+ const [canUndo, setCanUndo] = useState5(false);
1488
+ const [canRedo, setCanRedo] = useState5(false);
1489
+ const {
1490
+ transform,
1491
+ zoomIn,
1492
+ zoomOut,
1493
+ resetTransform,
1494
+ rotateClockwise,
1495
+ panBy,
1496
+ handleWheel,
1497
+ handleTouchStart,
1498
+ handleTouchMove,
1499
+ handleTouchEnd
1500
+ } = useImageTransform();
1501
+ useEffect4(() => {
1502
+ resetTransform();
1503
+ }, [currentIndex, resetTransform]);
1504
+ const imgRef = useRef7(null);
1505
+ const [imgSize, setImgSize] = useState5({ width: 800, height: 600 });
1506
+ const [imageStatus, setImageStatus] = useState5("loading");
1507
+ const [reloadKey, setReloadKey] = useState5(0);
1508
+ const containerRef = useRef7(null);
1509
+ const effectiveSrc = useMemo3(() => {
1510
+ if (!currentItem?.src) return "";
1511
+ if (reloadKey === 0) return currentItem.src;
1512
+ const sep = currentItem.src.includes("?") ? "&" : "?";
1513
+ return `${currentItem.src}${sep}_reload=${reloadKey}`;
1514
+ }, [currentItem?.src, reloadKey]);
1515
+ useEffect4(() => {
1516
+ setImageStatus("loading");
1517
+ setReloadKey(0);
1518
+ if (imgRef.current && imgRef.current.complete && imgRef.current.naturalWidth > 0) {
1519
+ setImgSize({
1520
+ width: imgRef.current.naturalWidth,
1521
+ height: imgRef.current.naturalHeight
1522
+ });
1523
+ setImageStatus("loaded");
1524
+ }
1525
+ }, [currentIndex, currentItem?.src]);
1526
+ const handleImageLoad = (e) => {
1527
+ const img = e.currentTarget;
1528
+ setImgSize({
1529
+ width: img.naturalWidth || img.width,
1530
+ height: img.naturalHeight || img.height
1531
+ });
1532
+ setImageStatus("loaded");
1533
+ };
1534
+ const handleImageError = () => {
1535
+ setImageStatus("error");
1536
+ };
1537
+ const handleReload = () => {
1538
+ setImageStatus("loading");
1539
+ setReloadKey((prev) => prev + 1);
1540
+ };
1541
+ const isDraggingRef = useRef7(false);
1542
+ const lastMousePosRef = useRef7({ x: 0, y: 0 });
1543
+ useEffect4(() => {
1544
+ const store = storeRef.current;
1545
+ const updateStrokes = () => {
1546
+ const s = store.getStrokes(slideId);
1547
+ setStrokes(s);
1548
+ setCanUndo(store.canUndo(slideId));
1549
+ setCanRedo(store.canRedo(slideId));
1550
+ onAnnotationsChange?.(slideId, s);
1551
+ };
1552
+ updateStrokes();
1553
+ const unsubscribe = store.subscribe((id) => {
1554
+ if (id === slideId) {
1555
+ updateStrokes();
1556
+ }
1557
+ });
1558
+ return unsubscribe;
1559
+ }, [slideId, onAnnotationsChange]);
1560
+ const goToNext = useCallback5(() => {
1561
+ if (currentIndex < items.length - 1) {
1562
+ const nextIdx = currentIndex + 1;
1563
+ setCurrentIndex(nextIdx);
1564
+ onIndexChange?.(nextIdx);
1565
+ }
1566
+ }, [currentIndex, items.length, onIndexChange]);
1567
+ const goToPrev = useCallback5(() => {
1568
+ if (currentIndex > 0) {
1569
+ const prevIdx = currentIndex - 1;
1570
+ setCurrentIndex(prevIdx);
1571
+ onIndexChange?.(prevIdx);
1572
+ }
1573
+ }, [currentIndex, onIndexChange]);
1574
+ const { onTouchStart: onSwipeTouchStart, onTouchEnd: onSwipeTouchEnd } = useSwipeGesture({
1575
+ onSwipeLeft: goToNext,
1576
+ onSwipeRight: goToPrev,
1577
+ enabled: activeTool === "hand"
1578
+ });
1579
+ const combinedTouchStart = (e) => {
1580
+ handleTouchStart(e);
1581
+ onSwipeTouchStart(e);
1582
+ };
1583
+ const combinedTouchEnd = (e) => {
1584
+ handleTouchEnd();
1585
+ onSwipeTouchEnd(e);
1586
+ };
1587
+ useEffect4(() => {
1588
+ if (!isOpen) return;
1589
+ const handleKeyDown = (e) => {
1590
+ if (e.key === "Escape") {
1591
+ onClose();
1592
+ } else if (e.key === "ArrowRight") {
1593
+ goToNext();
1594
+ } else if (e.key === "ArrowLeft") {
1595
+ goToPrev();
1596
+ } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z") {
1597
+ e.preventDefault();
1598
+ if (e.shiftKey) {
1599
+ storeRef.current.redo(slideId);
1600
+ } else {
1601
+ storeRef.current.undo(slideId);
1602
+ }
1603
+ } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "y") {
1604
+ e.preventDefault();
1605
+ storeRef.current.redo(slideId);
1606
+ } else if (e.key === "+" || e.key === "=") {
1607
+ zoomIn();
1608
+ } else if (e.key === "-") {
1609
+ zoomOut();
1610
+ } else if (e.key === "0") {
1611
+ resetTransform();
1612
+ }
1613
+ };
1614
+ window.addEventListener("keydown", handleKeyDown);
1615
+ return () => window.removeEventListener("keydown", handleKeyDown);
1616
+ }, [isOpen, onClose, goToNext, goToPrev, slideId, zoomIn, zoomOut, resetTransform]);
1617
+ const handleStagePointerDown = (e) => {
1618
+ if (activeTool !== "hand") return;
1619
+ isDraggingRef.current = true;
1620
+ lastMousePosRef.current = { x: e.clientX, y: e.clientY };
1621
+ e.target.setPointerCapture?.(e.pointerId);
1622
+ };
1623
+ const handleStagePointerMove = (e) => {
1624
+ if (!isDraggingRef.current || activeTool !== "hand") return;
1625
+ const dx = e.clientX - lastMousePosRef.current.x;
1626
+ const dy = e.clientY - lastMousePosRef.current.y;
1627
+ lastMousePosRef.current = { x: e.clientX, y: e.clientY };
1628
+ panBy(dx, dy);
1629
+ };
1630
+ const handleStagePointerUp = () => {
1631
+ isDraggingRef.current = false;
1632
+ };
1633
+ const handleStrokeComplete = useCallback5(
1634
+ (stroke) => {
1635
+ storeRef.current.addStroke(slideId, stroke);
1636
+ },
1637
+ [slideId]
1638
+ );
1639
+ const handleEraseStroke = useCallback5(
1640
+ (pt) => {
1641
+ storeRef.current.removeStrokesNear(slideId, pt, 0.03, isPointNearStroke3);
1642
+ },
1643
+ [slideId]
1644
+ );
1645
+ const handleUndo = useCallback5(() => storeRef.current.undo(slideId), [slideId]);
1646
+ const handleRedo = useCallback5(() => storeRef.current.redo(slideId), [slideId]);
1647
+ const handleClear = useCallback5(() => storeRef.current.clear(slideId), [slideId]);
1648
+ const toggleFullscreen = () => {
1649
+ if (!document.fullscreenElement) {
1650
+ containerRef.current?.requestFullscreen?.();
1651
+ setIsFullscreen(true);
1652
+ } else {
1653
+ document.exitFullscreen?.();
1654
+ setIsFullscreen(false);
1655
+ }
1656
+ };
1657
+ const handleDownloadAnnotated = async () => {
1658
+ if (!imgRef.current) return;
1659
+ await downloadAnnotatedImage2(imgRef.current, strokes, {
1660
+ format: "image/png",
1661
+ includeAnnotations: true,
1662
+ fileName: `tbib-gallery-${currentIndex + 1}-annotated.png`
1663
+ });
1664
+ };
1665
+ const handleDownloadClean = async () => {
1666
+ if (!imgRef.current) return;
1667
+ await downloadAnnotatedImage2(imgRef.current, [], {
1668
+ format: "image/png",
1669
+ includeAnnotations: false,
1670
+ fileName: `tbib-gallery-${currentIndex + 1}-clean.png`
1671
+ });
1672
+ };
1673
+ const handleExportJson = () => {
1674
+ const data = storeRef.current.exportJSON();
1675
+ const blob = new Blob([JSON.stringify(data, null, 2)], {
1676
+ type: "application/json"
1677
+ });
1678
+ const url = URL.createObjectURL(blob);
1679
+ const link = document.createElement("a");
1680
+ link.href = url;
1681
+ link.download = `tbib-gallery-annotations.json`;
1682
+ link.click();
1683
+ setTimeout(() => URL.revokeObjectURL(url), 1e3);
1684
+ };
1685
+ if (!isOpen || !currentItem) return null;
1686
+ return /* @__PURE__ */ jsxs5(
1687
+ "div",
1688
+ {
1689
+ ref: containerRef,
1690
+ className: `tbib-iv-lightbox-overlay ${theme === "light" ? "tbib-iv-light" : ""}`,
1691
+ role: "dialog",
1692
+ "aria-modal": "true",
1693
+ "aria-label": "Image Lightbox Gallery",
1694
+ children: [
1695
+ /* @__PURE__ */ jsx7(
1696
+ ImageToolbar,
1697
+ {
1698
+ activeTool,
1699
+ onToolChange: setActiveTool,
1700
+ color,
1701
+ onColorChange: setColor,
1702
+ strokeWidth,
1703
+ onStrokeWidthChange: setStrokeWidth,
1704
+ canUndo,
1705
+ canRedo,
1706
+ onUndo: handleUndo,
1707
+ onRedo: handleRedo,
1708
+ onClear: handleClear,
1709
+ zoomScale: transform.scale,
1710
+ onZoomIn: zoomIn,
1711
+ onZoomOut: zoomOut,
1712
+ onZoomReset: resetTransform,
1713
+ onRotate: rotateClockwise,
1714
+ onDownloadAnnotated: handleDownloadAnnotated,
1715
+ onDownloadClean: handleDownloadClean,
1716
+ onExportJson: handleExportJson,
1717
+ onClose,
1718
+ isFullscreen,
1719
+ onToggleFullscreen: toggleFullscreen,
1720
+ currentIndex,
1721
+ totalImages: items.length
1722
+ }
1723
+ ),
1724
+ currentIndex > 0 && /* @__PURE__ */ jsx7(
1725
+ "button",
1726
+ {
1727
+ type: "button",
1728
+ className: "tbib-iv-nav-prev",
1729
+ onClick: goToPrev,
1730
+ title: "Previous Image (Arrow Left)",
1731
+ "aria-label": "Previous image",
1732
+ children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faChevronLeft })
1733
+ }
1734
+ ),
1735
+ currentIndex < items.length - 1 && /* @__PURE__ */ jsx7(
1736
+ "button",
1737
+ {
1738
+ type: "button",
1739
+ className: "tbib-iv-nav-next",
1740
+ onClick: goToNext,
1741
+ title: "Next Image (Arrow Right)",
1742
+ "aria-label": "Next image",
1743
+ children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faChevronRight })
1744
+ }
1745
+ ),
1746
+ /* @__PURE__ */ jsxs5(
1747
+ "div",
1748
+ {
1749
+ className: "tbib-iv-stage",
1750
+ onWheel: handleWheel,
1751
+ onTouchStart: combinedTouchStart,
1752
+ onTouchMove: handleTouchMove,
1753
+ onTouchEnd: combinedTouchEnd,
1754
+ onPointerDown: handleStagePointerDown,
1755
+ onPointerMove: handleStagePointerMove,
1756
+ onPointerUp: handleStagePointerUp,
1757
+ onPointerCancel: handleStagePointerUp,
1758
+ style: {
1759
+ cursor: activeTool === "hand" ? isDraggingRef.current ? "grabbing" : "grab" : "default"
1760
+ },
1761
+ children: [
1762
+ /* @__PURE__ */ jsxs5(
1763
+ "div",
1764
+ {
1765
+ className: "tbib-iv-stage-inner",
1766
+ style: {
1767
+ transform: `translate3d(${transform.translateX}px, ${transform.translateY}px, 0) scale(${transform.scale}) rotate(${transform.rotate}deg)`,
1768
+ transition: isDraggingRef.current ? "none" : "transform 0.05s ease-out"
1769
+ },
1770
+ children: [
1771
+ /* @__PURE__ */ jsx7(
1772
+ "img",
1773
+ {
1774
+ ref: imgRef,
1775
+ src: effectiveSrc,
1776
+ alt: currentItem.alt || currentItem.title || `Gallery slide ${currentIndex + 1}`,
1777
+ className: `tbib-iv-image ${imageStatus === "loaded" ? "tbib-iv-image-loaded" : "tbib-iv-image-loading"}`,
1778
+ onLoad: handleImageLoad,
1779
+ onError: handleImageError,
1780
+ draggable: false
1781
+ },
1782
+ `${slideId}-${reloadKey}`
1783
+ ),
1784
+ imageStatus === "loaded" && /* @__PURE__ */ jsx7(
1785
+ AnnotationCanvas,
1786
+ {
1787
+ width: imgSize.width,
1788
+ height: imgSize.height,
1789
+ strokes,
1790
+ activeTool,
1791
+ color,
1792
+ strokeWidth,
1793
+ onStrokeComplete: handleStrokeComplete,
1794
+ onEraseStroke: handleEraseStroke
1795
+ }
1796
+ )
1797
+ ]
1798
+ }
1799
+ ),
1800
+ imageStatus === "loading" && /* @__PURE__ */ jsxs5("div", { className: "tbib-iv-status-overlay", children: [
1801
+ /* @__PURE__ */ jsx7("div", { className: "tbib-iv-spinner", children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faSpinner3, spin: true, className: "tbib-iv-spinner-icon" }) }),
1802
+ /* @__PURE__ */ jsx7("span", { className: "tbib-iv-status-text", children: "Chargement de l'illustration..." })
1803
+ ] }),
1804
+ imageStatus === "error" && /* @__PURE__ */ jsxs5("div", { className: "tbib-iv-status-overlay tbib-iv-error-card", children: [
1805
+ /* @__PURE__ */ jsx7("div", { className: "tbib-iv-error-icon", children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faExclamationTriangle2 }) }),
1806
+ /* @__PURE__ */ jsx7("h3", { className: "tbib-iv-error-title", children: "Impossible de charger l'image" }),
1807
+ /* @__PURE__ */ jsx7("p", { className: "tbib-iv-error-desc", children: "Le fichier est temporairement inaccessible ou une erreur r\xE9seau est survenue." }),
1808
+ /* @__PURE__ */ jsxs5("div", { className: "tbib-iv-error-actions", children: [
1809
+ /* @__PURE__ */ jsxs5(
1810
+ "button",
1811
+ {
1812
+ type: "button",
1813
+ className: "tbib-iv-btn tbib-iv-btn-primary tbib-iv-retry-btn",
1814
+ onClick: handleReload,
1815
+ children: [
1816
+ /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faRotateRight3 }),
1817
+ /* @__PURE__ */ jsx7("span", { children: "R\xE9essayer" })
1818
+ ]
1819
+ }
1820
+ ),
1821
+ currentItem?.src && /* @__PURE__ */ jsxs5(
1822
+ "a",
1823
+ {
1824
+ href: currentItem.src,
1825
+ target: "_blank",
1826
+ rel: "noopener noreferrer",
1827
+ className: "tbib-iv-btn tbib-iv-open-btn",
1828
+ children: [
1829
+ /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faExternalLinkAlt2 }),
1830
+ /* @__PURE__ */ jsx7("span", { children: "Lien direct" })
1831
+ ]
1832
+ }
1833
+ )
1834
+ ] })
1835
+ ] }),
1836
+ activeTool === "laser" && imageStatus === "loaded" && /* @__PURE__ */ jsx7(LaserCursorLayer, { color, secondaryColor: color, enabled: activeTool === "laser" })
1837
+ ]
1838
+ }
1839
+ ),
1840
+ showThumbnails && /* @__PURE__ */ jsx7(
1841
+ ThumbnailStrip,
1842
+ {
1843
+ items,
1844
+ activeIndex: currentIndex,
1845
+ onSelect: (idx) => {
1846
+ setCurrentIndex(idx);
1847
+ onIndexChange?.(idx);
1848
+ }
1849
+ }
1850
+ )
1851
+ ]
1852
+ }
1853
+ );
1854
+ };
1855
+
1856
+ // src/components/ColorPicker.tsx
1857
+ import { useState as useState6, useRef as useRef8, useEffect as useEffect5 } from "react";
1858
+ import { FontAwesomeIcon as FontAwesomeIcon5 } from "@fortawesome/react-fontawesome";
1859
+ import { faPalette } from "@fortawesome/free-solid-svg-icons";
1860
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1861
+ var PRESET_COLORS2 = [
1862
+ "#ef4444",
1863
+ // Red (Danger / Anatomy landmark)
1864
+ "#f59e0b",
1865
+ // Amber / Orange
1866
+ "#eab308",
1867
+ // Yellow (Highlighter classic)
1868
+ "#10b981",
1869
+ // Emerald / Green
1870
+ "#06b6d4",
1871
+ // Cyan
1872
+ "#8b5cf6",
1873
+ // Purple / Violet
1874
+ "#ffffff",
1875
+ // White
1876
+ "#0f172a"
1877
+ // Slate / Black
1878
+ ];
1879
+ var ColorPicker = ({ color, onChange }) => {
1880
+ const [isOpen, setIsOpen] = useState6(false);
1881
+ const containerRef = useRef8(null);
1882
+ useEffect5(() => {
1883
+ const handleOutsideClick = (e) => {
1884
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
1885
+ setIsOpen(false);
1886
+ }
1887
+ };
1888
+ if (isOpen) {
1889
+ document.addEventListener("mousedown", handleOutsideClick);
1890
+ }
1891
+ return () => {
1892
+ document.removeEventListener("mousedown", handleOutsideClick);
1893
+ };
1894
+ }, [isOpen]);
1895
+ return /* @__PURE__ */ jsxs6("div", { ref: containerRef, style: { position: "relative", display: "inline-block" }, children: [
1896
+ /* @__PURE__ */ jsxs6(
1897
+ "button",
1898
+ {
1899
+ type: "button",
1900
+ className: "tbib-iv-btn",
1901
+ title: "Annotation Color",
1902
+ onClick: () => setIsOpen((prev) => !prev),
1903
+ children: [
1904
+ /* @__PURE__ */ jsx8(
1905
+ "span",
1906
+ {
1907
+ style: {
1908
+ display: "inline-block",
1909
+ width: "16px",
1910
+ height: "16px",
1911
+ borderRadius: "50%",
1912
+ backgroundColor: color,
1913
+ border: "1px solid rgba(255,255,255,0.4)",
1914
+ marginRight: "4px"
1915
+ }
1916
+ }
1917
+ ),
1918
+ /* @__PURE__ */ jsx8(FontAwesomeIcon5, { icon: faPalette, style: { fontSize: "12px", opacity: 0.8 } })
1919
+ ]
1920
+ }
1921
+ ),
1922
+ isOpen && /* @__PURE__ */ jsx8("div", { className: "tbib-iv-popover", children: PRESET_COLORS2.map((c) => /* @__PURE__ */ jsx8(
1923
+ "button",
1924
+ {
1925
+ type: "button",
1926
+ className: `tbib-iv-color-swatch ${c.toLowerCase() === color.toLowerCase() ? "tbib-iv-color-swatch-active" : ""}`,
1927
+ style: { backgroundColor: c },
1928
+ onClick: () => {
1929
+ onChange(c);
1930
+ setIsOpen(false);
1931
+ },
1932
+ title: c
1933
+ },
1934
+ c
1935
+ )) })
1936
+ ] });
1937
+ };
1938
+
1939
+ // src/components/StrokeWidthPicker.tsx
1940
+ import { useState as useState7, useRef as useRef9, useEffect as useEffect6 } from "react";
1941
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1942
+ var WIDTH_OPTIONS = [
1943
+ { label: "Fine (2px)", value: 2, iconSize: "6px" },
1944
+ { label: "Medium (4px)", value: 4, iconSize: "10px" },
1945
+ { label: "Bold (8px)", value: 8, iconSize: "14px" },
1946
+ { label: "Heavy (14px)", value: 14, iconSize: "18px" }
1947
+ ];
1948
+ var StrokeWidthPicker = ({
1949
+ strokeWidth,
1950
+ onChange
1951
+ }) => {
1952
+ const [isOpen, setIsOpen] = useState7(false);
1953
+ const containerRef = useRef9(null);
1954
+ useEffect6(() => {
1955
+ const handleOutsideClick = (e) => {
1956
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
1957
+ setIsOpen(false);
1958
+ }
1959
+ };
1960
+ if (isOpen) {
1961
+ document.addEventListener("mousedown", handleOutsideClick);
1962
+ }
1963
+ return () => {
1964
+ document.removeEventListener("mousedown", handleOutsideClick);
1965
+ };
1966
+ }, [isOpen]);
1967
+ const currentOption = WIDTH_OPTIONS.find((o) => o.value === strokeWidth) || WIDTH_OPTIONS[1];
1968
+ return /* @__PURE__ */ jsxs7("div", { ref: containerRef, style: { position: "relative", display: "inline-block" }, children: [
1969
+ /* @__PURE__ */ jsx9(
1970
+ "button",
1971
+ {
1972
+ type: "button",
1973
+ className: "tbib-iv-btn",
1974
+ title: "Stroke Thickness",
1975
+ onClick: () => setIsOpen((prev) => !prev),
1976
+ children: /* @__PURE__ */ jsx9(
1977
+ "span",
1978
+ {
1979
+ style: {
1980
+ display: "inline-flex",
1981
+ alignItems: "center",
1982
+ justifyContent: "center",
1983
+ width: "16px",
1984
+ height: "16px"
1985
+ },
1986
+ children: /* @__PURE__ */ jsx9(
1987
+ "span",
1988
+ {
1989
+ style: {
1990
+ width: currentOption.iconSize,
1991
+ height: currentOption.iconSize,
1992
+ borderRadius: "50%",
1993
+ backgroundColor: "currentColor"
1994
+ }
1995
+ }
1996
+ )
1997
+ }
1998
+ )
1999
+ }
2000
+ ),
2001
+ isOpen && /* @__PURE__ */ jsx9(
2002
+ "div",
2003
+ {
2004
+ className: "tbib-iv-popover",
2005
+ style: {
2006
+ flexDirection: "column",
2007
+ minWidth: "120px",
2008
+ padding: "4px"
2009
+ },
2010
+ children: WIDTH_OPTIONS.map((opt) => /* @__PURE__ */ jsxs7(
2011
+ "button",
2012
+ {
2013
+ type: "button",
2014
+ className: `tbib-iv-btn ${opt.value === strokeWidth ? "tbib-iv-btn-active" : ""}`,
2015
+ style: {
2016
+ width: "100%",
2017
+ justifyContent: "flex-start",
2018
+ gap: "8px",
2019
+ padding: "6px 10px",
2020
+ fontSize: "12px"
2021
+ },
2022
+ onClick: () => {
2023
+ onChange(opt.value);
2024
+ setIsOpen(false);
2025
+ },
2026
+ children: [
2027
+ /* @__PURE__ */ jsx9(
2028
+ "span",
2029
+ {
2030
+ style: {
2031
+ display: "inline-block",
2032
+ width: opt.iconSize,
2033
+ height: opt.iconSize,
2034
+ borderRadius: "50%",
2035
+ backgroundColor: "currentColor"
2036
+ }
2037
+ }
2038
+ ),
2039
+ /* @__PURE__ */ jsx9("span", { children: opt.label })
2040
+ ]
2041
+ },
2042
+ opt.value
2043
+ ))
2044
+ }
2045
+ )
2046
+ ] });
2047
+ };
2048
+ export {
2049
+ AnnotationCanvas,
2050
+ ColorPicker,
2051
+ DownloadMenu,
2052
+ ImageGalleryLightbox,
2053
+ ImageToolbar,
2054
+ ImageViewer,
2055
+ LaserCursorLayer,
2056
+ StrokeWidthPicker,
2057
+ ThumbnailStrip,
2058
+ useImageTransform,
2059
+ useSwipeGesture
2060
+ };
2061
+ //# sourceMappingURL=index.mjs.map