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