@tbib-image-viewer/react 0.0.0-stage → 0.1.0

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