@tbib-image-viewer/react 0.1.0 → 0.1.2
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.css +127 -3
- package/dist/index.css.map +1 -1
- package/dist/index.js +172 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +180 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
// src/components/ImageViewer.tsx
|
|
2
2
|
import { useState as useState4, useRef as useRef5, useEffect as useEffect3, useCallback as useCallback3, useMemo as useMemo2 } from "react";
|
|
3
|
+
import { FontAwesomeIcon as FontAwesomeIcon3 } from "@fortawesome/react-fontawesome";
|
|
4
|
+
import {
|
|
5
|
+
faSpinner as faSpinner2,
|
|
6
|
+
faRotateRight as faRotateRight2
|
|
7
|
+
} from "@fortawesome/free-solid-svg-icons";
|
|
8
|
+
import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons/faExclamationTriangle";
|
|
9
|
+
import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons/faExternalLinkAlt";
|
|
3
10
|
import {
|
|
4
11
|
AnnotationStore,
|
|
5
12
|
downloadAnnotatedImage,
|
|
@@ -1085,6 +1092,24 @@ var ImageViewer = ({
|
|
|
1085
1092
|
const containerRef = useRef5(null);
|
|
1086
1093
|
const imgRef = useRef5(null);
|
|
1087
1094
|
const [imgSize, setImgSize] = useState4({ width: 800, height: 600 });
|
|
1095
|
+
const [imageStatus, setImageStatus] = useState4("loading");
|
|
1096
|
+
const [reloadKey, setReloadKey] = useState4(0);
|
|
1097
|
+
const effectiveSrc = useMemo2(() => {
|
|
1098
|
+
if (!src) return "";
|
|
1099
|
+
if (reloadKey === 0) return src;
|
|
1100
|
+
const sep = src.includes("?") ? "&" : "?";
|
|
1101
|
+
return `${src}${sep}_reload=${reloadKey}`;
|
|
1102
|
+
}, [src, reloadKey]);
|
|
1103
|
+
useEffect3(() => {
|
|
1104
|
+
setImageStatus("loading");
|
|
1105
|
+
if (imgRef.current && imgRef.current.complete && imgRef.current.naturalWidth > 0) {
|
|
1106
|
+
setImgSize({
|
|
1107
|
+
width: imgRef.current.naturalWidth,
|
|
1108
|
+
height: imgRef.current.naturalHeight
|
|
1109
|
+
});
|
|
1110
|
+
setImageStatus("loaded");
|
|
1111
|
+
}
|
|
1112
|
+
}, [src, reloadKey]);
|
|
1088
1113
|
const {
|
|
1089
1114
|
transform,
|
|
1090
1115
|
zoomIn,
|
|
@@ -1120,6 +1145,14 @@ var ImageViewer = ({
|
|
|
1120
1145
|
width: img.naturalWidth || img.width,
|
|
1121
1146
|
height: img.naturalHeight || img.height
|
|
1122
1147
|
});
|
|
1148
|
+
setImageStatus("loaded");
|
|
1149
|
+
};
|
|
1150
|
+
const handleImageError = () => {
|
|
1151
|
+
setImageStatus("error");
|
|
1152
|
+
};
|
|
1153
|
+
const handleReload = () => {
|
|
1154
|
+
setImageStatus("loading");
|
|
1155
|
+
setReloadKey((prev) => prev + 1);
|
|
1123
1156
|
};
|
|
1124
1157
|
const handleStrokeComplete = useCallback3(
|
|
1125
1158
|
(newStroke) => {
|
|
@@ -1188,16 +1221,18 @@ var ImageViewer = ({
|
|
|
1188
1221
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
1189
1222
|
}, [handleUndo, handleRedo, zoomIn, zoomOut, resetTransform]);
|
|
1190
1223
|
const handleDownloadAnnotated = async () => {
|
|
1191
|
-
|
|
1192
|
-
|
|
1224
|
+
const targetSource = effectiveSrc || imgRef.current?.src || "";
|
|
1225
|
+
if (!targetSource) return;
|
|
1226
|
+
await downloadAnnotatedImage(targetSource, strokes, {
|
|
1193
1227
|
format: "image/png",
|
|
1194
1228
|
includeAnnotations: true,
|
|
1195
1229
|
fileName: `tbib-annotated-${Date.now()}.png`
|
|
1196
1230
|
});
|
|
1197
1231
|
};
|
|
1198
1232
|
const handleDownloadClean = async () => {
|
|
1199
|
-
|
|
1200
|
-
|
|
1233
|
+
const targetSource = effectiveSrc || imgRef.current?.src || "";
|
|
1234
|
+
if (!targetSource) return;
|
|
1235
|
+
await downloadAnnotatedImage(targetSource, [], {
|
|
1201
1236
|
format: "image/png",
|
|
1202
1237
|
includeAnnotations: false,
|
|
1203
1238
|
fileName: `tbib-clean-${Date.now()}.png`
|
|
@@ -1275,15 +1310,16 @@ var ImageViewer = ({
|
|
|
1275
1310
|
"img",
|
|
1276
1311
|
{
|
|
1277
1312
|
ref: imgRef,
|
|
1278
|
-
src,
|
|
1313
|
+
src: effectiveSrc,
|
|
1279
1314
|
alt,
|
|
1280
|
-
className: "tbib-iv-image"
|
|
1315
|
+
className: `tbib-iv-image ${imageStatus === "loaded" ? "tbib-iv-image-loaded" : "tbib-iv-image-loading"}`,
|
|
1281
1316
|
onLoad: handleImageLoad,
|
|
1282
|
-
|
|
1317
|
+
onError: handleImageError,
|
|
1283
1318
|
draggable: false
|
|
1284
|
-
}
|
|
1319
|
+
},
|
|
1320
|
+
`${src}-${reloadKey}`
|
|
1285
1321
|
),
|
|
1286
|
-
enableAnnotations && /* @__PURE__ */ jsx5(
|
|
1322
|
+
enableAnnotations && imageStatus === "loaded" && /* @__PURE__ */ jsx5(
|
|
1287
1323
|
AnnotationCanvas,
|
|
1288
1324
|
{
|
|
1289
1325
|
width: imgSize.width,
|
|
@@ -1299,7 +1335,43 @@ var ImageViewer = ({
|
|
|
1299
1335
|
]
|
|
1300
1336
|
}
|
|
1301
1337
|
),
|
|
1302
|
-
|
|
1338
|
+
imageStatus === "loading" && /* @__PURE__ */ jsxs4("div", { className: "tbib-iv-status-overlay", children: [
|
|
1339
|
+
/* @__PURE__ */ jsx5("div", { className: "tbib-iv-spinner", children: /* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faSpinner2, spin: true, className: "tbib-iv-spinner-icon" }) }),
|
|
1340
|
+
/* @__PURE__ */ jsx5("span", { className: "tbib-iv-status-text", children: "Chargement de l'illustration..." })
|
|
1341
|
+
] }),
|
|
1342
|
+
imageStatus === "error" && /* @__PURE__ */ jsxs4("div", { className: "tbib-iv-status-overlay tbib-iv-error-card", children: [
|
|
1343
|
+
/* @__PURE__ */ jsx5("div", { className: "tbib-iv-error-icon", children: /* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faExclamationTriangle }) }),
|
|
1344
|
+
/* @__PURE__ */ jsx5("h3", { className: "tbib-iv-error-title", children: "Impossible de charger l'image" }),
|
|
1345
|
+
/* @__PURE__ */ jsx5("p", { className: "tbib-iv-error-desc", children: "Le fichier est temporairement inaccessible ou une erreur r\xE9seau est survenue." }),
|
|
1346
|
+
/* @__PURE__ */ jsxs4("div", { className: "tbib-iv-error-actions", children: [
|
|
1347
|
+
/* @__PURE__ */ jsxs4(
|
|
1348
|
+
"button",
|
|
1349
|
+
{
|
|
1350
|
+
type: "button",
|
|
1351
|
+
className: "tbib-iv-btn tbib-iv-btn-primary tbib-iv-retry-btn",
|
|
1352
|
+
onClick: handleReload,
|
|
1353
|
+
children: [
|
|
1354
|
+
/* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faRotateRight2 }),
|
|
1355
|
+
/* @__PURE__ */ jsx5("span", { children: "R\xE9essayer" })
|
|
1356
|
+
]
|
|
1357
|
+
}
|
|
1358
|
+
),
|
|
1359
|
+
src && /* @__PURE__ */ jsxs4(
|
|
1360
|
+
"a",
|
|
1361
|
+
{
|
|
1362
|
+
href: src,
|
|
1363
|
+
target: "_blank",
|
|
1364
|
+
rel: "noopener noreferrer",
|
|
1365
|
+
className: "tbib-iv-btn tbib-iv-open-btn",
|
|
1366
|
+
children: [
|
|
1367
|
+
/* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faExternalLinkAlt }),
|
|
1368
|
+
/* @__PURE__ */ jsx5("span", { children: "Lien direct" })
|
|
1369
|
+
]
|
|
1370
|
+
}
|
|
1371
|
+
)
|
|
1372
|
+
] })
|
|
1373
|
+
] }),
|
|
1374
|
+
enableLaser && activeTool === "laser" && imageStatus === "loaded" && /* @__PURE__ */ jsx5(LaserCursorLayer, { color, secondaryColor: color, enabled: activeTool === "laser" })
|
|
1303
1375
|
]
|
|
1304
1376
|
}
|
|
1305
1377
|
),
|
|
@@ -1310,9 +1382,16 @@ var ImageViewer = ({
|
|
|
1310
1382
|
};
|
|
1311
1383
|
|
|
1312
1384
|
// src/components/ImageGalleryLightbox.tsx
|
|
1313
|
-
import { useState as useState5, useRef as useRef7, useEffect as useEffect4, useCallback as useCallback5 } from "react";
|
|
1314
|
-
import { FontAwesomeIcon as
|
|
1315
|
-
import {
|
|
1385
|
+
import { useState as useState5, useRef as useRef7, useEffect as useEffect4, useCallback as useCallback5, useMemo as useMemo3 } from "react";
|
|
1386
|
+
import { FontAwesomeIcon as FontAwesomeIcon4 } from "@fortawesome/react-fontawesome";
|
|
1387
|
+
import {
|
|
1388
|
+
faChevronLeft,
|
|
1389
|
+
faChevronRight,
|
|
1390
|
+
faSpinner as faSpinner3,
|
|
1391
|
+
faRotateRight as faRotateRight3
|
|
1392
|
+
} from "@fortawesome/free-solid-svg-icons";
|
|
1393
|
+
import { faExclamationTriangle as faExclamationTriangle2 } from "@fortawesome/free-solid-svg-icons/faExclamationTriangle";
|
|
1394
|
+
import { faExternalLinkAlt as faExternalLinkAlt2 } from "@fortawesome/free-solid-svg-icons/faExternalLinkAlt";
|
|
1316
1395
|
import {
|
|
1317
1396
|
AnnotationStore as AnnotationStore2,
|
|
1318
1397
|
downloadAnnotatedImage as downloadAnnotatedImage2,
|
|
@@ -1426,7 +1505,41 @@ var ImageGalleryLightbox = ({
|
|
|
1426
1505
|
}, [currentIndex, resetTransform]);
|
|
1427
1506
|
const imgRef = useRef7(null);
|
|
1428
1507
|
const [imgSize, setImgSize] = useState5({ width: 800, height: 600 });
|
|
1508
|
+
const [imageStatus, setImageStatus] = useState5("loading");
|
|
1509
|
+
const [reloadKey, setReloadKey] = useState5(0);
|
|
1429
1510
|
const containerRef = useRef7(null);
|
|
1511
|
+
const effectiveSrc = useMemo3(() => {
|
|
1512
|
+
if (!currentItem?.src) return "";
|
|
1513
|
+
if (reloadKey === 0) return currentItem.src;
|
|
1514
|
+
const sep = currentItem.src.includes("?") ? "&" : "?";
|
|
1515
|
+
return `${currentItem.src}${sep}_reload=${reloadKey}`;
|
|
1516
|
+
}, [currentItem?.src, reloadKey]);
|
|
1517
|
+
useEffect4(() => {
|
|
1518
|
+
setImageStatus("loading");
|
|
1519
|
+
setReloadKey(0);
|
|
1520
|
+
if (imgRef.current && imgRef.current.complete && imgRef.current.naturalWidth > 0) {
|
|
1521
|
+
setImgSize({
|
|
1522
|
+
width: imgRef.current.naturalWidth,
|
|
1523
|
+
height: imgRef.current.naturalHeight
|
|
1524
|
+
});
|
|
1525
|
+
setImageStatus("loaded");
|
|
1526
|
+
}
|
|
1527
|
+
}, [currentIndex, currentItem?.src]);
|
|
1528
|
+
const handleImageLoad = (e) => {
|
|
1529
|
+
const img = e.currentTarget;
|
|
1530
|
+
setImgSize({
|
|
1531
|
+
width: img.naturalWidth || img.width,
|
|
1532
|
+
height: img.naturalHeight || img.height
|
|
1533
|
+
});
|
|
1534
|
+
setImageStatus("loaded");
|
|
1535
|
+
};
|
|
1536
|
+
const handleImageError = () => {
|
|
1537
|
+
setImageStatus("error");
|
|
1538
|
+
};
|
|
1539
|
+
const handleReload = () => {
|
|
1540
|
+
setImageStatus("loading");
|
|
1541
|
+
setReloadKey((prev) => prev + 1);
|
|
1542
|
+
};
|
|
1430
1543
|
const isDraggingRef = useRef7(false);
|
|
1431
1544
|
const lastMousePosRef = useRef7({ x: 0, y: 0 });
|
|
1432
1545
|
useEffect4(() => {
|
|
@@ -1544,16 +1657,18 @@ var ImageGalleryLightbox = ({
|
|
|
1544
1657
|
}
|
|
1545
1658
|
};
|
|
1546
1659
|
const handleDownloadAnnotated = async () => {
|
|
1547
|
-
|
|
1548
|
-
|
|
1660
|
+
const targetSource = effectiveSrc || currentItem?.src || imgRef.current?.src || "";
|
|
1661
|
+
if (!targetSource) return;
|
|
1662
|
+
await downloadAnnotatedImage2(targetSource, strokes, {
|
|
1549
1663
|
format: "image/png",
|
|
1550
1664
|
includeAnnotations: true,
|
|
1551
1665
|
fileName: `tbib-gallery-${currentIndex + 1}-annotated.png`
|
|
1552
1666
|
});
|
|
1553
1667
|
};
|
|
1554
1668
|
const handleDownloadClean = async () => {
|
|
1555
|
-
|
|
1556
|
-
|
|
1669
|
+
const targetSource = effectiveSrc || currentItem?.src || imgRef.current?.src || "";
|
|
1670
|
+
if (!targetSource) return;
|
|
1671
|
+
await downloadAnnotatedImage2(targetSource, [], {
|
|
1557
1672
|
format: "image/png",
|
|
1558
1673
|
includeAnnotations: false,
|
|
1559
1674
|
fileName: `tbib-gallery-${currentIndex + 1}-clean.png`
|
|
@@ -1618,7 +1733,7 @@ var ImageGalleryLightbox = ({
|
|
|
1618
1733
|
onClick: goToPrev,
|
|
1619
1734
|
title: "Previous Image (Arrow Left)",
|
|
1620
1735
|
"aria-label": "Previous image",
|
|
1621
|
-
children: /* @__PURE__ */ jsx7(
|
|
1736
|
+
children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faChevronLeft })
|
|
1622
1737
|
}
|
|
1623
1738
|
),
|
|
1624
1739
|
currentIndex < items.length - 1 && /* @__PURE__ */ jsx7(
|
|
@@ -1629,7 +1744,7 @@ var ImageGalleryLightbox = ({
|
|
|
1629
1744
|
onClick: goToNext,
|
|
1630
1745
|
title: "Next Image (Arrow Right)",
|
|
1631
1746
|
"aria-label": "Next image",
|
|
1632
|
-
children: /* @__PURE__ */ jsx7(
|
|
1747
|
+
children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faChevronRight })
|
|
1633
1748
|
}
|
|
1634
1749
|
),
|
|
1635
1750
|
/* @__PURE__ */ jsxs5(
|
|
@@ -1661,21 +1776,16 @@ var ImageGalleryLightbox = ({
|
|
|
1661
1776
|
"img",
|
|
1662
1777
|
{
|
|
1663
1778
|
ref: imgRef,
|
|
1664
|
-
src:
|
|
1779
|
+
src: effectiveSrc,
|
|
1665
1780
|
alt: currentItem.alt || currentItem.title || `Gallery slide ${currentIndex + 1}`,
|
|
1666
|
-
className: "tbib-iv-image"
|
|
1667
|
-
onLoad:
|
|
1668
|
-
|
|
1669
|
-
setImgSize({
|
|
1670
|
-
width: img.naturalWidth || img.width,
|
|
1671
|
-
height: img.naturalHeight || img.height
|
|
1672
|
-
});
|
|
1673
|
-
},
|
|
1674
|
-
crossOrigin: "anonymous",
|
|
1781
|
+
className: `tbib-iv-image ${imageStatus === "loaded" ? "tbib-iv-image-loaded" : "tbib-iv-image-loading"}`,
|
|
1782
|
+
onLoad: handleImageLoad,
|
|
1783
|
+
onError: handleImageError,
|
|
1675
1784
|
draggable: false
|
|
1676
|
-
}
|
|
1785
|
+
},
|
|
1786
|
+
`${slideId}-${reloadKey}`
|
|
1677
1787
|
),
|
|
1678
|
-
/* @__PURE__ */ jsx7(
|
|
1788
|
+
imageStatus === "loaded" && /* @__PURE__ */ jsx7(
|
|
1679
1789
|
AnnotationCanvas,
|
|
1680
1790
|
{
|
|
1681
1791
|
width: imgSize.width,
|
|
@@ -1691,7 +1801,43 @@ var ImageGalleryLightbox = ({
|
|
|
1691
1801
|
]
|
|
1692
1802
|
}
|
|
1693
1803
|
),
|
|
1694
|
-
|
|
1804
|
+
imageStatus === "loading" && /* @__PURE__ */ jsxs5("div", { className: "tbib-iv-status-overlay", children: [
|
|
1805
|
+
/* @__PURE__ */ jsx7("div", { className: "tbib-iv-spinner", children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faSpinner3, spin: true, className: "tbib-iv-spinner-icon" }) }),
|
|
1806
|
+
/* @__PURE__ */ jsx7("span", { className: "tbib-iv-status-text", children: "Chargement de l'illustration..." })
|
|
1807
|
+
] }),
|
|
1808
|
+
imageStatus === "error" && /* @__PURE__ */ jsxs5("div", { className: "tbib-iv-status-overlay tbib-iv-error-card", children: [
|
|
1809
|
+
/* @__PURE__ */ jsx7("div", { className: "tbib-iv-error-icon", children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faExclamationTriangle2 }) }),
|
|
1810
|
+
/* @__PURE__ */ jsx7("h3", { className: "tbib-iv-error-title", children: "Impossible de charger l'image" }),
|
|
1811
|
+
/* @__PURE__ */ jsx7("p", { className: "tbib-iv-error-desc", children: "Le fichier est temporairement inaccessible ou une erreur r\xE9seau est survenue." }),
|
|
1812
|
+
/* @__PURE__ */ jsxs5("div", { className: "tbib-iv-error-actions", children: [
|
|
1813
|
+
/* @__PURE__ */ jsxs5(
|
|
1814
|
+
"button",
|
|
1815
|
+
{
|
|
1816
|
+
type: "button",
|
|
1817
|
+
className: "tbib-iv-btn tbib-iv-btn-primary tbib-iv-retry-btn",
|
|
1818
|
+
onClick: handleReload,
|
|
1819
|
+
children: [
|
|
1820
|
+
/* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faRotateRight3 }),
|
|
1821
|
+
/* @__PURE__ */ jsx7("span", { children: "R\xE9essayer" })
|
|
1822
|
+
]
|
|
1823
|
+
}
|
|
1824
|
+
),
|
|
1825
|
+
currentItem?.src && /* @__PURE__ */ jsxs5(
|
|
1826
|
+
"a",
|
|
1827
|
+
{
|
|
1828
|
+
href: currentItem.src,
|
|
1829
|
+
target: "_blank",
|
|
1830
|
+
rel: "noopener noreferrer",
|
|
1831
|
+
className: "tbib-iv-btn tbib-iv-open-btn",
|
|
1832
|
+
children: [
|
|
1833
|
+
/* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faExternalLinkAlt2 }),
|
|
1834
|
+
/* @__PURE__ */ jsx7("span", { children: "Lien direct" })
|
|
1835
|
+
]
|
|
1836
|
+
}
|
|
1837
|
+
)
|
|
1838
|
+
] })
|
|
1839
|
+
] }),
|
|
1840
|
+
activeTool === "laser" && imageStatus === "loaded" && /* @__PURE__ */ jsx7(LaserCursorLayer, { color, secondaryColor: color, enabled: activeTool === "laser" })
|
|
1695
1841
|
]
|
|
1696
1842
|
}
|
|
1697
1843
|
),
|
|
@@ -1713,7 +1859,7 @@ var ImageGalleryLightbox = ({
|
|
|
1713
1859
|
|
|
1714
1860
|
// src/components/ColorPicker.tsx
|
|
1715
1861
|
import { useState as useState6, useRef as useRef8, useEffect as useEffect5 } from "react";
|
|
1716
|
-
import { FontAwesomeIcon as
|
|
1862
|
+
import { FontAwesomeIcon as FontAwesomeIcon5 } from "@fortawesome/react-fontawesome";
|
|
1717
1863
|
import { faPalette } from "@fortawesome/free-solid-svg-icons";
|
|
1718
1864
|
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1719
1865
|
var PRESET_COLORS2 = [
|
|
@@ -1773,7 +1919,7 @@ var ColorPicker = ({ color, onChange }) => {
|
|
|
1773
1919
|
}
|
|
1774
1920
|
}
|
|
1775
1921
|
),
|
|
1776
|
-
/* @__PURE__ */ jsx8(
|
|
1922
|
+
/* @__PURE__ */ jsx8(FontAwesomeIcon5, { icon: faPalette, style: { fontSize: "12px", opacity: 0.8 } })
|
|
1777
1923
|
]
|
|
1778
1924
|
}
|
|
1779
1925
|
),
|