@tbib-image-viewer/react 0.1.0 → 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.css +127 -3
- package/dist/index.css.map +1 -1
- package/dist/index.js +160 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +168 -26
- 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) => {
|
|
@@ -1275,15 +1308,16 @@ var ImageViewer = ({
|
|
|
1275
1308
|
"img",
|
|
1276
1309
|
{
|
|
1277
1310
|
ref: imgRef,
|
|
1278
|
-
src,
|
|
1311
|
+
src: effectiveSrc,
|
|
1279
1312
|
alt,
|
|
1280
|
-
className: "tbib-iv-image"
|
|
1313
|
+
className: `tbib-iv-image ${imageStatus === "loaded" ? "tbib-iv-image-loaded" : "tbib-iv-image-loading"}`,
|
|
1281
1314
|
onLoad: handleImageLoad,
|
|
1282
|
-
|
|
1315
|
+
onError: handleImageError,
|
|
1283
1316
|
draggable: false
|
|
1284
|
-
}
|
|
1317
|
+
},
|
|
1318
|
+
`${src}-${reloadKey}`
|
|
1285
1319
|
),
|
|
1286
|
-
enableAnnotations && /* @__PURE__ */ jsx5(
|
|
1320
|
+
enableAnnotations && imageStatus === "loaded" && /* @__PURE__ */ jsx5(
|
|
1287
1321
|
AnnotationCanvas,
|
|
1288
1322
|
{
|
|
1289
1323
|
width: imgSize.width,
|
|
@@ -1299,7 +1333,43 @@ var ImageViewer = ({
|
|
|
1299
1333
|
]
|
|
1300
1334
|
}
|
|
1301
1335
|
),
|
|
1302
|
-
|
|
1336
|
+
imageStatus === "loading" && /* @__PURE__ */ jsxs4("div", { className: "tbib-iv-status-overlay", children: [
|
|
1337
|
+
/* @__PURE__ */ jsx5("div", { className: "tbib-iv-spinner", children: /* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faSpinner2, spin: true, className: "tbib-iv-spinner-icon" }) }),
|
|
1338
|
+
/* @__PURE__ */ jsx5("span", { className: "tbib-iv-status-text", children: "Chargement de l'illustration..." })
|
|
1339
|
+
] }),
|
|
1340
|
+
imageStatus === "error" && /* @__PURE__ */ jsxs4("div", { className: "tbib-iv-status-overlay tbib-iv-error-card", children: [
|
|
1341
|
+
/* @__PURE__ */ jsx5("div", { className: "tbib-iv-error-icon", children: /* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faExclamationTriangle }) }),
|
|
1342
|
+
/* @__PURE__ */ jsx5("h3", { className: "tbib-iv-error-title", children: "Impossible de charger l'image" }),
|
|
1343
|
+
/* @__PURE__ */ jsx5("p", { className: "tbib-iv-error-desc", children: "Le fichier est temporairement inaccessible ou une erreur r\xE9seau est survenue." }),
|
|
1344
|
+
/* @__PURE__ */ jsxs4("div", { className: "tbib-iv-error-actions", children: [
|
|
1345
|
+
/* @__PURE__ */ jsxs4(
|
|
1346
|
+
"button",
|
|
1347
|
+
{
|
|
1348
|
+
type: "button",
|
|
1349
|
+
className: "tbib-iv-btn tbib-iv-btn-primary tbib-iv-retry-btn",
|
|
1350
|
+
onClick: handleReload,
|
|
1351
|
+
children: [
|
|
1352
|
+
/* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faRotateRight2 }),
|
|
1353
|
+
/* @__PURE__ */ jsx5("span", { children: "R\xE9essayer" })
|
|
1354
|
+
]
|
|
1355
|
+
}
|
|
1356
|
+
),
|
|
1357
|
+
src && /* @__PURE__ */ jsxs4(
|
|
1358
|
+
"a",
|
|
1359
|
+
{
|
|
1360
|
+
href: src,
|
|
1361
|
+
target: "_blank",
|
|
1362
|
+
rel: "noopener noreferrer",
|
|
1363
|
+
className: "tbib-iv-btn tbib-iv-open-btn",
|
|
1364
|
+
children: [
|
|
1365
|
+
/* @__PURE__ */ jsx5(FontAwesomeIcon3, { icon: faExternalLinkAlt }),
|
|
1366
|
+
/* @__PURE__ */ jsx5("span", { children: "Lien direct" })
|
|
1367
|
+
]
|
|
1368
|
+
}
|
|
1369
|
+
)
|
|
1370
|
+
] })
|
|
1371
|
+
] }),
|
|
1372
|
+
enableLaser && activeTool === "laser" && imageStatus === "loaded" && /* @__PURE__ */ jsx5(LaserCursorLayer, { color, secondaryColor: color, enabled: activeTool === "laser" })
|
|
1303
1373
|
]
|
|
1304
1374
|
}
|
|
1305
1375
|
),
|
|
@@ -1310,9 +1380,16 @@ var ImageViewer = ({
|
|
|
1310
1380
|
};
|
|
1311
1381
|
|
|
1312
1382
|
// 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 {
|
|
1383
|
+
import { useState as useState5, useRef as useRef7, useEffect as useEffect4, useCallback as useCallback5, useMemo as useMemo3 } from "react";
|
|
1384
|
+
import { FontAwesomeIcon as FontAwesomeIcon4 } from "@fortawesome/react-fontawesome";
|
|
1385
|
+
import {
|
|
1386
|
+
faChevronLeft,
|
|
1387
|
+
faChevronRight,
|
|
1388
|
+
faSpinner as faSpinner3,
|
|
1389
|
+
faRotateRight as faRotateRight3
|
|
1390
|
+
} from "@fortawesome/free-solid-svg-icons";
|
|
1391
|
+
import { faExclamationTriangle as faExclamationTriangle2 } from "@fortawesome/free-solid-svg-icons/faExclamationTriangle";
|
|
1392
|
+
import { faExternalLinkAlt as faExternalLinkAlt2 } from "@fortawesome/free-solid-svg-icons/faExternalLinkAlt";
|
|
1316
1393
|
import {
|
|
1317
1394
|
AnnotationStore as AnnotationStore2,
|
|
1318
1395
|
downloadAnnotatedImage as downloadAnnotatedImage2,
|
|
@@ -1426,7 +1503,41 @@ var ImageGalleryLightbox = ({
|
|
|
1426
1503
|
}, [currentIndex, resetTransform]);
|
|
1427
1504
|
const imgRef = useRef7(null);
|
|
1428
1505
|
const [imgSize, setImgSize] = useState5({ width: 800, height: 600 });
|
|
1506
|
+
const [imageStatus, setImageStatus] = useState5("loading");
|
|
1507
|
+
const [reloadKey, setReloadKey] = useState5(0);
|
|
1429
1508
|
const containerRef = useRef7(null);
|
|
1509
|
+
const effectiveSrc = useMemo3(() => {
|
|
1510
|
+
if (!currentItem?.src) return "";
|
|
1511
|
+
if (reloadKey === 0) return currentItem.src;
|
|
1512
|
+
const sep = currentItem.src.includes("?") ? "&" : "?";
|
|
1513
|
+
return `${currentItem.src}${sep}_reload=${reloadKey}`;
|
|
1514
|
+
}, [currentItem?.src, reloadKey]);
|
|
1515
|
+
useEffect4(() => {
|
|
1516
|
+
setImageStatus("loading");
|
|
1517
|
+
setReloadKey(0);
|
|
1518
|
+
if (imgRef.current && imgRef.current.complete && imgRef.current.naturalWidth > 0) {
|
|
1519
|
+
setImgSize({
|
|
1520
|
+
width: imgRef.current.naturalWidth,
|
|
1521
|
+
height: imgRef.current.naturalHeight
|
|
1522
|
+
});
|
|
1523
|
+
setImageStatus("loaded");
|
|
1524
|
+
}
|
|
1525
|
+
}, [currentIndex, currentItem?.src]);
|
|
1526
|
+
const handleImageLoad = (e) => {
|
|
1527
|
+
const img = e.currentTarget;
|
|
1528
|
+
setImgSize({
|
|
1529
|
+
width: img.naturalWidth || img.width,
|
|
1530
|
+
height: img.naturalHeight || img.height
|
|
1531
|
+
});
|
|
1532
|
+
setImageStatus("loaded");
|
|
1533
|
+
};
|
|
1534
|
+
const handleImageError = () => {
|
|
1535
|
+
setImageStatus("error");
|
|
1536
|
+
};
|
|
1537
|
+
const handleReload = () => {
|
|
1538
|
+
setImageStatus("loading");
|
|
1539
|
+
setReloadKey((prev) => prev + 1);
|
|
1540
|
+
};
|
|
1430
1541
|
const isDraggingRef = useRef7(false);
|
|
1431
1542
|
const lastMousePosRef = useRef7({ x: 0, y: 0 });
|
|
1432
1543
|
useEffect4(() => {
|
|
@@ -1618,7 +1729,7 @@ var ImageGalleryLightbox = ({
|
|
|
1618
1729
|
onClick: goToPrev,
|
|
1619
1730
|
title: "Previous Image (Arrow Left)",
|
|
1620
1731
|
"aria-label": "Previous image",
|
|
1621
|
-
children: /* @__PURE__ */ jsx7(
|
|
1732
|
+
children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faChevronLeft })
|
|
1622
1733
|
}
|
|
1623
1734
|
),
|
|
1624
1735
|
currentIndex < items.length - 1 && /* @__PURE__ */ jsx7(
|
|
@@ -1629,7 +1740,7 @@ var ImageGalleryLightbox = ({
|
|
|
1629
1740
|
onClick: goToNext,
|
|
1630
1741
|
title: "Next Image (Arrow Right)",
|
|
1631
1742
|
"aria-label": "Next image",
|
|
1632
|
-
children: /* @__PURE__ */ jsx7(
|
|
1743
|
+
children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faChevronRight })
|
|
1633
1744
|
}
|
|
1634
1745
|
),
|
|
1635
1746
|
/* @__PURE__ */ jsxs5(
|
|
@@ -1661,21 +1772,16 @@ var ImageGalleryLightbox = ({
|
|
|
1661
1772
|
"img",
|
|
1662
1773
|
{
|
|
1663
1774
|
ref: imgRef,
|
|
1664
|
-
src:
|
|
1775
|
+
src: effectiveSrc,
|
|
1665
1776
|
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",
|
|
1777
|
+
className: `tbib-iv-image ${imageStatus === "loaded" ? "tbib-iv-image-loaded" : "tbib-iv-image-loading"}`,
|
|
1778
|
+
onLoad: handleImageLoad,
|
|
1779
|
+
onError: handleImageError,
|
|
1675
1780
|
draggable: false
|
|
1676
|
-
}
|
|
1781
|
+
},
|
|
1782
|
+
`${slideId}-${reloadKey}`
|
|
1677
1783
|
),
|
|
1678
|
-
/* @__PURE__ */ jsx7(
|
|
1784
|
+
imageStatus === "loaded" && /* @__PURE__ */ jsx7(
|
|
1679
1785
|
AnnotationCanvas,
|
|
1680
1786
|
{
|
|
1681
1787
|
width: imgSize.width,
|
|
@@ -1691,7 +1797,43 @@ var ImageGalleryLightbox = ({
|
|
|
1691
1797
|
]
|
|
1692
1798
|
}
|
|
1693
1799
|
),
|
|
1694
|
-
|
|
1800
|
+
imageStatus === "loading" && /* @__PURE__ */ jsxs5("div", { className: "tbib-iv-status-overlay", children: [
|
|
1801
|
+
/* @__PURE__ */ jsx7("div", { className: "tbib-iv-spinner", children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faSpinner3, spin: true, className: "tbib-iv-spinner-icon" }) }),
|
|
1802
|
+
/* @__PURE__ */ jsx7("span", { className: "tbib-iv-status-text", children: "Chargement de l'illustration..." })
|
|
1803
|
+
] }),
|
|
1804
|
+
imageStatus === "error" && /* @__PURE__ */ jsxs5("div", { className: "tbib-iv-status-overlay tbib-iv-error-card", children: [
|
|
1805
|
+
/* @__PURE__ */ jsx7("div", { className: "tbib-iv-error-icon", children: /* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faExclamationTriangle2 }) }),
|
|
1806
|
+
/* @__PURE__ */ jsx7("h3", { className: "tbib-iv-error-title", children: "Impossible de charger l'image" }),
|
|
1807
|
+
/* @__PURE__ */ jsx7("p", { className: "tbib-iv-error-desc", children: "Le fichier est temporairement inaccessible ou une erreur r\xE9seau est survenue." }),
|
|
1808
|
+
/* @__PURE__ */ jsxs5("div", { className: "tbib-iv-error-actions", children: [
|
|
1809
|
+
/* @__PURE__ */ jsxs5(
|
|
1810
|
+
"button",
|
|
1811
|
+
{
|
|
1812
|
+
type: "button",
|
|
1813
|
+
className: "tbib-iv-btn tbib-iv-btn-primary tbib-iv-retry-btn",
|
|
1814
|
+
onClick: handleReload,
|
|
1815
|
+
children: [
|
|
1816
|
+
/* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faRotateRight3 }),
|
|
1817
|
+
/* @__PURE__ */ jsx7("span", { children: "R\xE9essayer" })
|
|
1818
|
+
]
|
|
1819
|
+
}
|
|
1820
|
+
),
|
|
1821
|
+
currentItem?.src && /* @__PURE__ */ jsxs5(
|
|
1822
|
+
"a",
|
|
1823
|
+
{
|
|
1824
|
+
href: currentItem.src,
|
|
1825
|
+
target: "_blank",
|
|
1826
|
+
rel: "noopener noreferrer",
|
|
1827
|
+
className: "tbib-iv-btn tbib-iv-open-btn",
|
|
1828
|
+
children: [
|
|
1829
|
+
/* @__PURE__ */ jsx7(FontAwesomeIcon4, { icon: faExternalLinkAlt2 }),
|
|
1830
|
+
/* @__PURE__ */ jsx7("span", { children: "Lien direct" })
|
|
1831
|
+
]
|
|
1832
|
+
}
|
|
1833
|
+
)
|
|
1834
|
+
] })
|
|
1835
|
+
] }),
|
|
1836
|
+
activeTool === "laser" && imageStatus === "loaded" && /* @__PURE__ */ jsx7(LaserCursorLayer, { color, secondaryColor: color, enabled: activeTool === "laser" })
|
|
1695
1837
|
]
|
|
1696
1838
|
}
|
|
1697
1839
|
),
|
|
@@ -1713,7 +1855,7 @@ var ImageGalleryLightbox = ({
|
|
|
1713
1855
|
|
|
1714
1856
|
// src/components/ColorPicker.tsx
|
|
1715
1857
|
import { useState as useState6, useRef as useRef8, useEffect as useEffect5 } from "react";
|
|
1716
|
-
import { FontAwesomeIcon as
|
|
1858
|
+
import { FontAwesomeIcon as FontAwesomeIcon5 } from "@fortawesome/react-fontawesome";
|
|
1717
1859
|
import { faPalette } from "@fortawesome/free-solid-svg-icons";
|
|
1718
1860
|
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1719
1861
|
var PRESET_COLORS2 = [
|
|
@@ -1773,7 +1915,7 @@ var ColorPicker = ({ color, onChange }) => {
|
|
|
1773
1915
|
}
|
|
1774
1916
|
}
|
|
1775
1917
|
),
|
|
1776
|
-
/* @__PURE__ */ jsx8(
|
|
1918
|
+
/* @__PURE__ */ jsx8(FontAwesomeIcon5, { icon: faPalette, style: { fontSize: "12px", opacity: 0.8 } })
|
|
1777
1919
|
]
|
|
1778
1920
|
}
|
|
1779
1921
|
),
|