@koraidv/react 1.7.3 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +35 -4
- package/dist/index.mjs +35 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1814,6 +1814,7 @@ function DocumentCaptureScreen({
|
|
|
1814
1814
|
}) {
|
|
1815
1815
|
const videoRef = (0, import_react5.useRef)(null);
|
|
1816
1816
|
const canvasRef = (0, import_react5.useRef)(null);
|
|
1817
|
+
const guideRef = (0, import_react5.useRef)(null);
|
|
1817
1818
|
const [stream, setStream] = (0, import_react5.useState)(null);
|
|
1818
1819
|
const [isCapturing, setIsCapturing] = (0, import_react5.useState)(false);
|
|
1819
1820
|
const [error, setError] = (0, import_react5.useState)(null);
|
|
@@ -1862,9 +1863,39 @@ function DocumentCaptureScreen({
|
|
|
1862
1863
|
setIsCapturing(false);
|
|
1863
1864
|
return;
|
|
1864
1865
|
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1866
|
+
const guideRect = guideRef.current?.getBoundingClientRect();
|
|
1867
|
+
const videoRect = video.getBoundingClientRect();
|
|
1868
|
+
let cropX = 0;
|
|
1869
|
+
let cropY = 0;
|
|
1870
|
+
let cropW = video.videoWidth;
|
|
1871
|
+
let cropH = video.videoHeight;
|
|
1872
|
+
if (guideRect && videoRect.width > 0 && videoRect.height > 0 && video.videoWidth > 0 && video.videoHeight > 0) {
|
|
1873
|
+
const scale = Math.max(
|
|
1874
|
+
videoRect.width / video.videoWidth,
|
|
1875
|
+
videoRect.height / video.videoHeight
|
|
1876
|
+
);
|
|
1877
|
+
const visibleSourceW = videoRect.width / scale;
|
|
1878
|
+
const visibleSourceH = videoRect.height / scale;
|
|
1879
|
+
const sourceLeftOffset = (video.videoWidth - visibleSourceW) / 2;
|
|
1880
|
+
const sourceTopOffset = (video.videoHeight - visibleSourceH) / 2;
|
|
1881
|
+
const guideOffsetX = guideRect.left - videoRect.left;
|
|
1882
|
+
const guideOffsetY = guideRect.top - videoRect.top;
|
|
1883
|
+
const sx = sourceLeftOffset + guideOffsetX / scale;
|
|
1884
|
+
const sy = sourceTopOffset + guideOffsetY / scale;
|
|
1885
|
+
const sw = guideRect.width / scale;
|
|
1886
|
+
const sh = guideRect.height / scale;
|
|
1887
|
+
cropX = Math.max(0, Math.min(Math.round(sx), video.videoWidth - 1));
|
|
1888
|
+
cropY = Math.max(0, Math.min(Math.round(sy), video.videoHeight - 1));
|
|
1889
|
+
cropW = Math.max(1, Math.min(Math.round(sw), video.videoWidth - cropX));
|
|
1890
|
+
cropH = Math.max(1, Math.min(Math.round(sh), video.videoHeight - cropY));
|
|
1891
|
+
}
|
|
1892
|
+
const TARGET_MIN_WIDTH = 1600;
|
|
1893
|
+
const upscale = cropW < TARGET_MIN_WIDTH ? TARGET_MIN_WIDTH / cropW : 1;
|
|
1894
|
+
const outW = Math.round(cropW * upscale);
|
|
1895
|
+
const outH = Math.round(cropH * upscale);
|
|
1896
|
+
canvas.width = outW;
|
|
1897
|
+
canvas.height = outH;
|
|
1898
|
+
ctx.drawImage(video, cropX, cropY, cropW, cropH, 0, 0, outW, outH);
|
|
1868
1899
|
const dataUrl = canvas.toDataURL("image/jpeg", 0.85);
|
|
1869
1900
|
canvas.toBlob(
|
|
1870
1901
|
(blob) => {
|
|
@@ -1994,7 +2025,7 @@ function DocumentCaptureScreen({
|
|
|
1994
2025
|
] }),
|
|
1995
2026
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: styles.cameraContainer, children: [
|
|
1996
2027
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("video", { ref: videoRef, autoPlay: true, playsInline: true, muted: true, style: styles.cameraVideo }),
|
|
1997
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: styles.documentOverlay, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: styles.documentFrame, children: [
|
|
2028
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: styles.documentOverlay, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { ref: guideRef, style: styles.documentFrame, children: [
|
|
1998
2029
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: { ...styles.corner, top: 0, left: 0 } }),
|
|
1999
2030
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: { ...styles.corner, top: 0, right: 0, transform: "rotate(90deg)" } }),
|
|
2000
2031
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: { ...styles.corner, bottom: 0, right: 0, transform: "rotate(180deg)" } }),
|
package/dist/index.mjs
CHANGED
|
@@ -1765,6 +1765,7 @@ function DocumentCaptureScreen({
|
|
|
1765
1765
|
}) {
|
|
1766
1766
|
const videoRef = useRef(null);
|
|
1767
1767
|
const canvasRef = useRef(null);
|
|
1768
|
+
const guideRef = useRef(null);
|
|
1768
1769
|
const [stream, setStream] = useState3(null);
|
|
1769
1770
|
const [isCapturing, setIsCapturing] = useState3(false);
|
|
1770
1771
|
const [error, setError] = useState3(null);
|
|
@@ -1813,9 +1814,39 @@ function DocumentCaptureScreen({
|
|
|
1813
1814
|
setIsCapturing(false);
|
|
1814
1815
|
return;
|
|
1815
1816
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1817
|
+
const guideRect = guideRef.current?.getBoundingClientRect();
|
|
1818
|
+
const videoRect = video.getBoundingClientRect();
|
|
1819
|
+
let cropX = 0;
|
|
1820
|
+
let cropY = 0;
|
|
1821
|
+
let cropW = video.videoWidth;
|
|
1822
|
+
let cropH = video.videoHeight;
|
|
1823
|
+
if (guideRect && videoRect.width > 0 && videoRect.height > 0 && video.videoWidth > 0 && video.videoHeight > 0) {
|
|
1824
|
+
const scale = Math.max(
|
|
1825
|
+
videoRect.width / video.videoWidth,
|
|
1826
|
+
videoRect.height / video.videoHeight
|
|
1827
|
+
);
|
|
1828
|
+
const visibleSourceW = videoRect.width / scale;
|
|
1829
|
+
const visibleSourceH = videoRect.height / scale;
|
|
1830
|
+
const sourceLeftOffset = (video.videoWidth - visibleSourceW) / 2;
|
|
1831
|
+
const sourceTopOffset = (video.videoHeight - visibleSourceH) / 2;
|
|
1832
|
+
const guideOffsetX = guideRect.left - videoRect.left;
|
|
1833
|
+
const guideOffsetY = guideRect.top - videoRect.top;
|
|
1834
|
+
const sx = sourceLeftOffset + guideOffsetX / scale;
|
|
1835
|
+
const sy = sourceTopOffset + guideOffsetY / scale;
|
|
1836
|
+
const sw = guideRect.width / scale;
|
|
1837
|
+
const sh = guideRect.height / scale;
|
|
1838
|
+
cropX = Math.max(0, Math.min(Math.round(sx), video.videoWidth - 1));
|
|
1839
|
+
cropY = Math.max(0, Math.min(Math.round(sy), video.videoHeight - 1));
|
|
1840
|
+
cropW = Math.max(1, Math.min(Math.round(sw), video.videoWidth - cropX));
|
|
1841
|
+
cropH = Math.max(1, Math.min(Math.round(sh), video.videoHeight - cropY));
|
|
1842
|
+
}
|
|
1843
|
+
const TARGET_MIN_WIDTH = 1600;
|
|
1844
|
+
const upscale = cropW < TARGET_MIN_WIDTH ? TARGET_MIN_WIDTH / cropW : 1;
|
|
1845
|
+
const outW = Math.round(cropW * upscale);
|
|
1846
|
+
const outH = Math.round(cropH * upscale);
|
|
1847
|
+
canvas.width = outW;
|
|
1848
|
+
canvas.height = outH;
|
|
1849
|
+
ctx.drawImage(video, cropX, cropY, cropW, cropH, 0, 0, outW, outH);
|
|
1819
1850
|
const dataUrl = canvas.toDataURL("image/jpeg", 0.85);
|
|
1820
1851
|
canvas.toBlob(
|
|
1821
1852
|
(blob) => {
|
|
@@ -1945,7 +1976,7 @@ function DocumentCaptureScreen({
|
|
|
1945
1976
|
] }),
|
|
1946
1977
|
/* @__PURE__ */ jsxs5("div", { style: styles.cameraContainer, children: [
|
|
1947
1978
|
/* @__PURE__ */ jsx6("video", { ref: videoRef, autoPlay: true, playsInline: true, muted: true, style: styles.cameraVideo }),
|
|
1948
|
-
/* @__PURE__ */ jsx6("div", { style: styles.documentOverlay, children: /* @__PURE__ */ jsxs5("div", { style: styles.documentFrame, children: [
|
|
1979
|
+
/* @__PURE__ */ jsx6("div", { style: styles.documentOverlay, children: /* @__PURE__ */ jsxs5("div", { ref: guideRef, style: styles.documentFrame, children: [
|
|
1949
1980
|
/* @__PURE__ */ jsx6("div", { style: { ...styles.corner, top: 0, left: 0 } }),
|
|
1950
1981
|
/* @__PURE__ */ jsx6("div", { style: { ...styles.corner, top: 0, right: 0, transform: "rotate(90deg)" } }),
|
|
1951
1982
|
/* @__PURE__ */ jsx6("div", { style: { ...styles.corner, bottom: 0, right: 0, transform: "rotate(180deg)" } }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koraidv/react",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"description": "Kora IDV React Components for Identity Verification",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "vitest run"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@koraidv/core": "^1.7.
|
|
24
|
+
"@koraidv/core": "^1.7.5"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "^18.2.0",
|