jattac.libs.web.zest-file-upload 0.2.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/Errors/FileUploadErrorBoundary.d.ts +16 -0
- package/dist/Hooks/useBrowser.d.ts +3 -0
- package/dist/Hooks/useCamera.d.ts +34 -0
- package/dist/Hooks/useFileValidation.d.ts +6 -0
- package/dist/Types/types.d.ts +82 -0
- package/dist/UI/CameraCapture.d.ts +33 -0
- package/dist/UI/FileUpload.d.ts +4 -0
- package/dist/UI/index.d.ts +3 -0
- package/dist/index.cjs.js +2299 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.esm.js +2276 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,2299 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var md = require('react-icons/md');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
27
|
+
|
|
28
|
+
function styleInject(css, ref) {
|
|
29
|
+
if ( ref === void 0 ) ref = {};
|
|
30
|
+
var insertAt = ref.insertAt;
|
|
31
|
+
|
|
32
|
+
if (typeof document === 'undefined') { return; }
|
|
33
|
+
|
|
34
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
35
|
+
var style = document.createElement('style');
|
|
36
|
+
style.type = 'text/css';
|
|
37
|
+
|
|
38
|
+
if (insertAt === 'top') {
|
|
39
|
+
if (head.firstChild) {
|
|
40
|
+
head.insertBefore(style, head.firstChild);
|
|
41
|
+
} else {
|
|
42
|
+
head.appendChild(style);
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
head.appendChild(style);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (style.styleSheet) {
|
|
49
|
+
style.styleSheet.cssText = css;
|
|
50
|
+
} else {
|
|
51
|
+
style.appendChild(document.createTextNode(css));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var css_248z$1 = ".FileUpload-module_fileUploadContainer__Wy-Up {\n display: flex;\n flex-direction: column;\n margin: 20px 0;\n}\n\n.FileUpload-module_label__nLqx4 {\n margin-bottom: 8px;\n font-size: 16px;\n color: #333;\n}\n\n.FileUpload-module_fileInputContainer__MfXbf {\n display: flex;\n align-items: center;\n cursor: pointer;\n border: 2px dashed;\n border-color: var(--color-primary);\n border-radius: 8px;\n padding: 30px 30px;\n background-color: #fff;\n transition: background-color 0.25s ease, box-shadow 0.25s ease;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);\n}\n\n.FileUpload-module_disabled__FtUd7 {\n cursor: not-allowed;\n opacity: 0.5;\n pointer-events: none;\n}\n\n.FileUpload-module_fileInputContainer__MfXbf:hover {\n background-color: #f7f7f7;\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);\n}\n\n.FileUpload-module_fileInput__ns8S- {\n display: none; /* Keep input hidden */\n}\n\n.FileUpload-module_fileName__h7Ij- {\n flex: 1;\n padding: 12px;\n border: 1px solid transparent; /* Added to maintain focus effect */\n color: #444;\n font-size: 16px;\n font-family: \"Arial\", sans-serif;\n transition: border-color 0.2s ease;\n text-align: center;\n}\n\n.FileUpload-module_visibleElements__JqQ1- {\n display: flex;\n flex-direction: row;\n gap: 10px;\n cursor: \"pointer\";\n border-radius: 5px;\n justify-content: center;\n align-items: center;\n width: 100%;\n}\n\n.FileUpload-module_visibleElements__JqQ1-:hover {\n color: var(--color-primary);\n font-weight: bold;\n}\n\n.FileUpload-module_fileName__h7Ij-:focus {\n outline: none;\n border-color: #2980b9; /* A sharper blue for focus */\n}\n\n.FileUpload-module_fileName__h7Ij-::placeholder {\n color: #999; /* Subtle placeholder color */\n}\n\n/* Progress dialog styles */\n.FileUpload-module_progressDialog__agLef {\n margin-top: 12px;\n width: 100%;\n background-color: #f7f7f7;\n border-radius: 8px;\n padding: 8px;\n}\n\n.FileUpload-module_progressBar__kePxX {\n width: 100%;\n background-color: #ddd;\n border-radius: 4px;\n overflow: hidden;\n}\n\n.FileUpload-module_progressFill__A00Zx {\n height: 10px;\n background-color: #2980b9; /* Blue color for progress fill */\n transition: width 0.25s ease;\n}\n\n/* Status message styling */\n.FileUpload-module_statusMessage__LMpk4 {\n margin-top: 12px;\n font-size: 16px;\n color: #2980b9;\n font-weight: bold;\n text-align: right;\n transition: opacity 0.5s ease, transform 0.5s ease;\n}\n\n/* Success animation for 'complete' status */\n.FileUpload-module_successAnimation__X-AGb {\n animation: FileUpload-module_fadeIn__U5yc7 0.5s ease;\n}\n\n/* Keyframe for fade-in effect */\n@keyframes FileUpload-module_fadeIn__U5yc7 {\n from {\n opacity: 0;\n transform: translateY(10px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n/* Keyframe for error shake effect */\n@keyframes FileUpload-module_shake__xDhrR {\n 0%, 100% { transform: translateX(0); }\n 10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }\n 20%, 40%, 60%, 80% { transform: translateX(5px); }\n}\n\n/* Error animation */\n.FileUpload-module_errorAnimation__DSUBA {\n animation: FileUpload-module_shake__xDhrR 0.5s ease;\n color: #dc3545;\n}\n\n/* Style changes when dragging over the drop area */\n.FileUpload-module_fileInputContainer__MfXbf.FileUpload-module_dragOver__Saj5O {\n background-color: #eaf2f8;\n border-color: #2980b9;\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);\n}\n\n/* ============================================================================\n// MOBILE BUTTONS - Delightful UI with joyous colors & dopamine effects\n// ============================================================================ */\n\n/* Pulse animation for mobile - subtle attention grabber */\n@keyframes FileUpload-module_cameraPulse__RQDx7 {\n 0%, 100% {\n box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.4);\n }\n 50% {\n box-shadow: 0 0 0 8px rgba(139, 92, 246, 0);\n }\n}\n\n/* Mobile buttons container - vertical column - stretches to fill space */\n.FileUpload-module_mobileButtons__stjus {\n display: none;\n flex-direction: column;\n gap: 12px;\n width: 100%;\n min-height: 120px;\n flex: 1;\n justify-content: center;\n}\n\n/* Individual mobile button - stretch to fill available space */\n.FileUpload-module_mobileButton__9LmQC {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n width: 100%;\n flex: 1;\n padding: 16px 20px;\n background: linear-gradient(135deg, #8B5CF6 0%, #7C3AED 100%);\n color: white;\n font-size: 16px;\n font-weight: 600;\n border: none;\n border-radius: 8px;\n cursor: pointer;\n transition: all 0.2s ease;\n}\n\n.FileUpload-module_mobileButton__9LmQC:hover:not(:disabled) {\n background: linear-gradient(135deg, #7C3AED 0%, #6D28D9 100%);\n transform: translateY(-2px);\n box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);\n}\n\n.FileUpload-module_mobileButton__9LmQC:active:not(:disabled) {\n transform: scale(0.95);\n}\n\n.FileUpload-module_mobileButton__9LmQC:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n/* Show mobile buttons on mobile/tablet only, hide desktop text */\n@media (pointer: coarse), (max-width: 1024px) {\n .FileUpload-module_mobileButtons__stjus {\n display: flex;\n animation: FileUpload-module_cameraPulse__RQDx7 2s ease-in-out infinite;\n }\n .FileUpload-module_visibleElements__JqQ1- {\n display: none;\n }\n}\n\n/* ============================================================================\n// PHASE 4: IN-APP CAMERA PREVIEW - Delightful UI with joyous colors\n// ============================================================================ */\n\n/* Camera Preview Container */\n.FileUpload-module_cameraPreview__y5Hpw {\n position: relative;\n width: 100%;\n aspect-ratio: 3 / 4;\n max-height: 400px;\n background: #000;\n border-radius: 12px;\n overflow: hidden;\n margin-top: 12px;\n}\n\n/* Video Element */\n.FileUpload-module_cameraVideo__k8kfy {\n width: 100%;\n height: 100%;\n object-fit: cover;\n}\n\n/* Camera Controls Bar */\n.FileUpload-module_cameraControls__EAT-W {\n position: absolute;\n top: 12px;\n left: 0;\n right: 0;\n display: flex;\n justify-content: space-between;\n padding: 0 16px;\n z-index: 10;\n}\n\n.FileUpload-module_cameraControlBtn__vq5ab {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 42px;\n height: 42px;\n background: rgba(0, 0, 0, 0.5);\n backdrop-filter: blur(8px);\n border: none;\n border-radius: 50%;\n color: white;\n font-size: 20px;\n cursor: pointer;\n transition: all 0.2s ease;\n}\n\n.FileUpload-module_cameraControlBtn__vq5ab:hover {\n background: rgba(0, 0, 0, 0.7);\n transform: scale(1.1);\n}\n\n.FileUpload-module_cameraControlBtn__vq5ab:active {\n transform: scale(0.95);\n}\n\n/* Capture Button */\n.FileUpload-module_captureBtn__7Y0Yi {\n position: absolute;\n bottom: 32px;\n left: 50%;\n transform: translateX(-50%);\n width: 72px;\n height: 72px;\n background: transparent;\n border: 4px solid white;\n border-radius: 50%;\n cursor: pointer;\n transition: all 0.2s ease;\n z-index: 100;\n touch-action: manipulation;\n -webkit-tap-highlight-color: transparent;\n}\n\n.FileUpload-module_captureBtnInner__3fzVL {\n width: 100%;\n height: 100%;\n background: white;\n border-radius: 50%;\n transition: all 0.2s ease;\n}\n\n.FileUpload-module_captureBtn__7Y0Yi:hover .FileUpload-module_captureBtnInner__3fzVL {\n transform: scale(0.9);\n}\n\n.FileUpload-module_captureBtn__7Y0Yi:active .FileUpload-module_captureBtnInner__3fzVL {\n transform: scale(0.8);\n background: #8B5CF6;\n}\n\n/* Captured Preview */\n.FileUpload-module_capturedPreview__8sCVd {\n width: 100%;\n aspect-ratio: 3 / 4;\n max-height: 400px;\n border-radius: 12px;\n overflow: hidden;\n margin-top: 12px;\n background: #000;\n}\n\n.FileUpload-module_capturedImage__0XlUC {\n width: 100%;\n height: 100%;\n object-fit: cover;\n}\n\n/* Captured Actions (Retake / Confirm) */\n.FileUpload-module_capturedActions__7zsfS {\n position: absolute;\n bottom: 24px;\n left: 0;\n right: 0;\n display: flex;\n justify-content: center;\n gap: 24px;\n padding: 0 16px;\n}\n\n.FileUpload-module_retakeBtn__ztglf,\n.FileUpload-module_confirmBtn__RJpS- {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 12px 24px;\n border: none;\n border-radius: 24px;\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s ease;\n}\n\n.FileUpload-module_retakeBtn__ztglf {\n background: rgba(255, 255, 255, 0.2);\n backdrop-filter: blur(8px);\n color: white;\n}\n\n.FileUpload-module_retakeBtn__ztglf:hover {\n background: rgba(255, 255, 255, 0.3);\n}\n\n.FileUpload-module_confirmBtn__RJpS- {\n background: linear-gradient(135deg, #10B981 0%, #059669 100%);\n color: white;\n}\n\n.FileUpload-module_confirmBtn__RJpS-:hover {\n transform: translateY(-2px);\n box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);\n}\n\n/* Camera Error */\n.FileUpload-module_cameraError__DwVo- {\n margin-top: 8px;\n padding: 12px;\n background: #FEF2F2;\n border: 1px solid #FECACA;\n border-radius: 8px;\n color: #DC2626;\n font-size: 14px;\n text-align: center;\n}\n\n/* Screen Flash Animation (capture moment) */\n@keyframes FileUpload-module_screenFlash__xu1rw {\n 0% { opacity: 0; }\n 50% { opacity: 1; background: white; }\n 100% { opacity: 0; }\n}\n\n.FileUpload-module_screenFlash__xu1rw {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: white;\n animation: FileUpload-module_screenFlash__xu1rw 0.3s ease-out;\n pointer-events: none;\n z-index: 200;\n}\n\n.FileUpload-module_errorMessage__AXjcm {\n margin-top: 8px;\n padding: 12px;\n border: 1px solid #dc3545;\n background: #fff5f5;\n border-radius: 8px;\n color: #dc3545;\n font-size: 14px;\n text-align: center;\n}\n\n.FileUpload-module_retryBtn__4lm-y {\n margin-left: 12px;\n padding: 4px 14px;\n background: #dc3545;\n color: #fff;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n font-size: 13px;\n font-weight: 600;\n transition: background 0.2s ease;\n}\n\n.FileUpload-module_retryBtn__4lm-y:hover {\n background: #b02a37;\n}\n\n@keyframes FileUpload-module_loadingPulse__CS4Se {\n 0%, 100% { opacity: 0.6; transform: scale(1); }\n 50% { opacity: 1; transform: scale(1.05); }\n}\n\n.FileUpload-module_cameraLoading__T-SW4 {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n background: #1a1a2e;\n color: #fff;\n font-size: 48px;\n animation: FileUpload-module_loadingPulse__CS4Se 1.5s ease-in-out infinite;\n}\n\n/* Crop container for react-easy-crop */\n.FileUpload-module_cropContainer__J3-11 {\n position: relative;\n width: 100%;\n height: 400px;\n margin-top: 12px;\n border-radius: 12px;\n overflow: hidden;\n background: #000;\n}\n\n/* ============================================================================\n MULTI-FILE QUEUE — Delightful parallel upload UX\n ============================================================================ */\n\n@keyframes FileUpload-module_slideInRow__COE9n {\n from { opacity: 0; transform: translateY(-8px); }\n to { opacity: 1; transform: translateY(0); }\n}\n\n@keyframes FileUpload-module_popCheck__NQqID {\n 0% { transform: scale(0.5); opacity: 0; }\n 70% { transform: scale(1.15); }\n 100% { transform: scale(1); opacity: 1; }\n}\n\n@keyframes FileUpload-module_progressShimmer__jOjnv {\n 0% { transform: translateX(-100%); }\n 100% { transform: translateX(200%); }\n}\n\n@keyframes FileUpload-module_completePulse__IyePh {\n 0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }\n 50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.2); }\n}\n\n/* Drop zone — compact variant when queue already has entries */\n.FileUpload-module_multiDropZoneCompact__9CFq- {\n padding: 14px 30px;\n min-height: 56px;\n}\n\n/* File queue list */\n.FileUpload-module_fileList__NYlEu {\n list-style: none;\n margin: 12px 0 0;\n padding: 0;\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n/* File row: grid layout — meta | badge | actions on row 1, progress on row 2 */\n.FileUpload-module_fileRow__1Fxul {\n display: grid;\n grid-template-columns: 1fr auto auto;\n grid-template-rows: auto auto;\n gap: 6px 12px;\n align-items: center;\n padding: 10px 14px;\n border: 1px solid #e5e7eb;\n border-left: 3px solid #9ca3af;\n border-radius: 8px;\n background: #fff;\n animation: FileUpload-module_slideInRow__COE9n 0.25s ease both;\n transition: border-color 0.2s ease, box-shadow 0.2s ease;\n}\n\n.FileUpload-module_fileRow_pending__pdNXE { border-left-color: #9ca3af; }\n.FileUpload-module_fileRow_uploading__MuNwL { border-left-color: #2980b9; }\n.FileUpload-module_fileRow_complete__zkAqi { border-left-color: #10b981; animation: FileUpload-module_completePulse__IyePh 0.6s ease; }\n.FileUpload-module_fileRow_error__ShiDk { border-left-color: #dc3545; animation: FileUpload-module_shake__xDhrR 0.5s ease; }\n\n/* File name and size */\n.FileUpload-module_fileRowMeta__zufyo {\n grid-column: 1;\n grid-row: 1;\n min-width: 0;\n}\n\n.FileUpload-module_fileRowFilename__4fIwi {\n display: block;\n font-size: 14px;\n font-weight: 500;\n color: #1f2937;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.FileUpload-module_fileRowSize__qTRVw {\n display: block;\n font-size: 12px;\n color: #6b7280;\n margin-top: 1px;\n}\n\n/* Status badge */\n.FileUpload-module_fileRowBadge__o6z-- {\n grid-column: 2;\n grid-row: 1;\n font-size: 11px;\n font-weight: 600;\n padding: 2px 9px;\n border-radius: 999px;\n white-space: nowrap;\n}\n\n.FileUpload-module_badge_pending__xQGJ0 { background: #f3f4f6; color: #6b7280; }\n.FileUpload-module_badge_uploading__8WaRF { background: #dbeafe; color: #1d4ed8; }\n.FileUpload-module_badge_complete__9nfZB { background: #d1fae5; color: #065f46; animation: FileUpload-module_popCheck__NQqID 0.4s ease; }\n.FileUpload-module_badge_error__2vDFn { background: #fee2e2; color: #991b1b; }\n\n/* Per-file progress bar — spans full width below the row header */\n.FileUpload-module_fileRowProgress__nR0ef {\n grid-column: 1 / -1;\n grid-row: 2;\n height: 3px;\n background: #e5e7eb;\n border-radius: 2px;\n overflow: hidden;\n}\n\n.FileUpload-module_fileRowProgressFill__WNeLC {\n height: 100%;\n background: #2980b9;\n border-radius: 2px;\n transition: width 0.25s ease;\n}\n\n.FileUpload-module_fileRowProgressIndeterminate__CThl- {\n height: 100%;\n width: 40%;\n background: linear-gradient(90deg, transparent, #2980b9, transparent);\n animation: FileUpload-module_progressShimmer__jOjnv 1.2s ease-in-out infinite;\n}\n\n/* Action buttons */\n.FileUpload-module_fileRowActions__5gWBm {\n grid-column: 3;\n grid-row: 1;\n display: flex;\n gap: 6px;\n align-items: center;\n}\n\n.FileUpload-module_removeFileBtn__M5al4 {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 26px;\n height: 26px;\n border: none;\n border-radius: 6px;\n background: transparent;\n color: #9ca3af;\n cursor: pointer;\n transition: background 0.15s ease, color 0.15s ease;\n}\n\n.FileUpload-module_removeFileBtn__M5al4:hover {\n background: #fee2e2;\n color: #dc3545;\n}\n\n.FileUpload-module_retryFileBtn__HOpA7 {\n font-size: 11px;\n font-weight: 600;\n padding: 3px 10px;\n border: 1px solid #dc3545;\n border-radius: 4px;\n background: transparent;\n color: #dc3545;\n cursor: pointer;\n transition: background 0.15s ease, color 0.15s ease;\n}\n\n.FileUpload-module_retryFileBtn__HOpA7:hover {\n background: #dc3545;\n color: #fff;\n}\n\n/* Clear all button */\n.FileUpload-module_clearAllBtn__v3oMP {\n margin-top: 8px;\n align-self: flex-end;\n padding: 5px 14px;\n font-size: 12px;\n font-weight: 500;\n color: #6b7280;\n background: transparent;\n border: 1px solid #e5e7eb;\n border-radius: 6px;\n cursor: pointer;\n transition: border-color 0.15s ease, color 0.15s ease;\n}\n\n.FileUpload-module_clearAllBtn__v3oMP:hover {\n border-color: #dc3545;\n color: #dc3545;\n}\n";
|
|
56
|
+
var styles = {"fileUploadContainer":"FileUpload-module_fileUploadContainer__Wy-Up","label":"FileUpload-module_label__nLqx4","fileInputContainer":"FileUpload-module_fileInputContainer__MfXbf","disabled":"FileUpload-module_disabled__FtUd7","fileInput":"FileUpload-module_fileInput__ns8S-","fileName":"FileUpload-module_fileName__h7Ij-","visibleElements":"FileUpload-module_visibleElements__JqQ1-","progressDialog":"FileUpload-module_progressDialog__agLef","progressBar":"FileUpload-module_progressBar__kePxX","progressFill":"FileUpload-module_progressFill__A00Zx","statusMessage":"FileUpload-module_statusMessage__LMpk4","successAnimation":"FileUpload-module_successAnimation__X-AGb","fadeIn":"FileUpload-module_fadeIn__U5yc7","errorAnimation":"FileUpload-module_errorAnimation__DSUBA","shake":"FileUpload-module_shake__xDhrR","dragOver":"FileUpload-module_dragOver__Saj5O","mobileButtons":"FileUpload-module_mobileButtons__stjus","mobileButton":"FileUpload-module_mobileButton__9LmQC","cameraPulse":"FileUpload-module_cameraPulse__RQDx7","cameraPreview":"FileUpload-module_cameraPreview__y5Hpw","cameraVideo":"FileUpload-module_cameraVideo__k8kfy","cameraControls":"FileUpload-module_cameraControls__EAT-W","cameraControlBtn":"FileUpload-module_cameraControlBtn__vq5ab","captureBtn":"FileUpload-module_captureBtn__7Y0Yi","captureBtnInner":"FileUpload-module_captureBtnInner__3fzVL","capturedPreview":"FileUpload-module_capturedPreview__8sCVd","capturedImage":"FileUpload-module_capturedImage__0XlUC","capturedActions":"FileUpload-module_capturedActions__7zsfS","retakeBtn":"FileUpload-module_retakeBtn__ztglf","confirmBtn":"FileUpload-module_confirmBtn__RJpS-","cameraError":"FileUpload-module_cameraError__DwVo-","screenFlash":"FileUpload-module_screenFlash__xu1rw","errorMessage":"FileUpload-module_errorMessage__AXjcm","retryBtn":"FileUpload-module_retryBtn__4lm-y","cameraLoading":"FileUpload-module_cameraLoading__T-SW4","loadingPulse":"FileUpload-module_loadingPulse__CS4Se","cropContainer":"FileUpload-module_cropContainer__J3-11","multiDropZoneCompact":"FileUpload-module_multiDropZoneCompact__9CFq-","fileList":"FileUpload-module_fileList__NYlEu","fileRow":"FileUpload-module_fileRow__1Fxul","slideInRow":"FileUpload-module_slideInRow__COE9n","fileRow_pending":"FileUpload-module_fileRow_pending__pdNXE","fileRow_uploading":"FileUpload-module_fileRow_uploading__MuNwL","fileRow_complete":"FileUpload-module_fileRow_complete__zkAqi","completePulse":"FileUpload-module_completePulse__IyePh","fileRow_error":"FileUpload-module_fileRow_error__ShiDk","fileRowMeta":"FileUpload-module_fileRowMeta__zufyo","fileRowFilename":"FileUpload-module_fileRowFilename__4fIwi","fileRowSize":"FileUpload-module_fileRowSize__qTRVw","fileRowBadge":"FileUpload-module_fileRowBadge__o6z--","badge_pending":"FileUpload-module_badge_pending__xQGJ0","badge_uploading":"FileUpload-module_badge_uploading__8WaRF","badge_complete":"FileUpload-module_badge_complete__9nfZB","popCheck":"FileUpload-module_popCheck__NQqID","badge_error":"FileUpload-module_badge_error__2vDFn","fileRowProgress":"FileUpload-module_fileRowProgress__nR0ef","fileRowProgressFill":"FileUpload-module_fileRowProgressFill__WNeLC","fileRowProgressIndeterminate":"FileUpload-module_fileRowProgressIndeterminate__CThl-","progressShimmer":"FileUpload-module_progressShimmer__jOjnv","fileRowActions":"FileUpload-module_fileRowActions__5gWBm","removeFileBtn":"FileUpload-module_removeFileBtn__M5al4","retryFileBtn":"FileUpload-module_retryFileBtn__HOpA7","clearAllBtn":"FileUpload-module_clearAllBtn__v3oMP"};
|
|
57
|
+
styleInject(css_248z$1);
|
|
58
|
+
|
|
59
|
+
function useBrowser() {
|
|
60
|
+
const [isBrowser, setIsBrowser] = React.useState(false);
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
setIsBrowser(true);
|
|
63
|
+
}, []);
|
|
64
|
+
return { isBrowser };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const isValidFileType = (file, accept) => {
|
|
68
|
+
if (!accept)
|
|
69
|
+
return true;
|
|
70
|
+
const acceptedTypes = accept
|
|
71
|
+
.split(",")
|
|
72
|
+
.map((type) => type.trim().toLowerCase());
|
|
73
|
+
const fileName = file.name.toLowerCase();
|
|
74
|
+
const mimeType = file.type.toLowerCase();
|
|
75
|
+
return acceptedTypes.some((type) => {
|
|
76
|
+
if (type.startsWith(".")) {
|
|
77
|
+
return fileName.endsWith(type);
|
|
78
|
+
}
|
|
79
|
+
else if (type.endsWith("/*")) {
|
|
80
|
+
const baseType = type.split("/")[0];
|
|
81
|
+
return mimeType.startsWith(baseType + "/");
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return mimeType === type;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const useFileValidation = (accept, maxSize) => {
|
|
89
|
+
const validate = React.useCallback((file) => {
|
|
90
|
+
if (!isValidFileType(file, accept)) {
|
|
91
|
+
return { isValid: false, error: "Invalid file type" };
|
|
92
|
+
}
|
|
93
|
+
if (maxSize !== undefined && file.size > maxSize) {
|
|
94
|
+
const sizeMB = Math.ceil(maxSize / (1024 * 1024));
|
|
95
|
+
return {
|
|
96
|
+
isValid: false,
|
|
97
|
+
error: `File exceeds maximum size of ${sizeMB} MB`,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return { isValid: true, error: null };
|
|
101
|
+
}, [accept, maxSize]);
|
|
102
|
+
return { validate };
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const compressImage = async (file, options = {
|
|
106
|
+
maxWidth: 1920,
|
|
107
|
+
maxHeight: 1920,
|
|
108
|
+
quality: 0.85,
|
|
109
|
+
mimeType: "image/jpeg",
|
|
110
|
+
}) => {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
const img = new Image();
|
|
113
|
+
const canvas = document.createElement("canvas");
|
|
114
|
+
const ctx = canvas.getContext("2d");
|
|
115
|
+
if (!ctx) {
|
|
116
|
+
reject(new Error("Could not get canvas context"));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
img.onload = () => {
|
|
120
|
+
let { width, height } = img;
|
|
121
|
+
if (width > options.maxWidth || height > options.maxHeight) {
|
|
122
|
+
const ratio = Math.min(options.maxWidth / width, options.maxHeight / height);
|
|
123
|
+
width = Math.round(width * ratio);
|
|
124
|
+
height = Math.round(height * ratio);
|
|
125
|
+
}
|
|
126
|
+
canvas.width = width;
|
|
127
|
+
canvas.height = height;
|
|
128
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
129
|
+
canvas.toBlob((blob) => {
|
|
130
|
+
URL.revokeObjectURL(img.src);
|
|
131
|
+
if (blob) {
|
|
132
|
+
const compressedFile = new File([blob], file.name, {
|
|
133
|
+
type: options.mimeType,
|
|
134
|
+
lastModified: Date.now(),
|
|
135
|
+
});
|
|
136
|
+
resolve(compressedFile);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
reject(new Error("Compression failed - could not create blob"));
|
|
140
|
+
}
|
|
141
|
+
}, options.mimeType, options.quality);
|
|
142
|
+
};
|
|
143
|
+
img.onerror = () => {
|
|
144
|
+
URL.revokeObjectURL(img.src);
|
|
145
|
+
reject(new Error("Could not load image"));
|
|
146
|
+
};
|
|
147
|
+
img.src = URL.createObjectURL(file);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
function useCamera({ capture, onFileSelect, setStatus, onError, labels, }) {
|
|
151
|
+
const { isBrowser } = useBrowser();
|
|
152
|
+
const [cameraView, setCameraView] = React.useState("none");
|
|
153
|
+
const [stream, setStream] = React.useState(null);
|
|
154
|
+
const [facingMode, setFacingMode] = React.useState(capture || "environment");
|
|
155
|
+
const [flashEnabled, setFlashEnabled] = React.useState(false);
|
|
156
|
+
const [capturedImage, setCapturedImage] = React.useState(null);
|
|
157
|
+
const [cameraError, setCameraError] = React.useState(null);
|
|
158
|
+
const [videoReady, setVideoReady] = React.useState(false);
|
|
159
|
+
const [cameraLoading, setCameraLoading] = React.useState(false);
|
|
160
|
+
const [cropCompleteArea, setCropCompleteArea] = React.useState(null);
|
|
161
|
+
const videoRef = React.useRef(null);
|
|
162
|
+
const canvasRef = React.useRef(null);
|
|
163
|
+
const cameraInputRef = React.useRef(null);
|
|
164
|
+
const capturedBlobRef = React.useRef(null);
|
|
165
|
+
const isCameraSupported = React.useCallback(() => {
|
|
166
|
+
if (!isBrowser)
|
|
167
|
+
return false;
|
|
168
|
+
return !!navigator.mediaDevices && !!navigator.mediaDevices.getUserMedia;
|
|
169
|
+
}, [isBrowser]);
|
|
170
|
+
const stopCamera = React.useCallback(() => {
|
|
171
|
+
if (stream) {
|
|
172
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
173
|
+
setStream(null);
|
|
174
|
+
}
|
|
175
|
+
setVideoReady(false);
|
|
176
|
+
}, [stream]);
|
|
177
|
+
React.useEffect(() => {
|
|
178
|
+
return () => {
|
|
179
|
+
if (stream) {
|
|
180
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}, [stream]);
|
|
184
|
+
React.useEffect(() => {
|
|
185
|
+
if (videoRef.current && stream) {
|
|
186
|
+
videoRef.current.srcObject = stream;
|
|
187
|
+
setVideoReady(false);
|
|
188
|
+
const video = videoRef.current;
|
|
189
|
+
const onLoadedMetadata = () => {
|
|
190
|
+
setVideoReady(true);
|
|
191
|
+
setCameraView("preview");
|
|
192
|
+
};
|
|
193
|
+
video.addEventListener("loadedmetadata", onLoadedMetadata);
|
|
194
|
+
return () => {
|
|
195
|
+
video.removeEventListener("loadedmetadata", onLoadedMetadata);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}, [stream]);
|
|
199
|
+
const handleCameraClick = async (e) => {
|
|
200
|
+
e.stopPropagation();
|
|
201
|
+
if (!isCameraSupported()) {
|
|
202
|
+
cameraInputRef.current?.click();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
setCameraError(null);
|
|
207
|
+
setCameraView("loading");
|
|
208
|
+
setCameraLoading(true);
|
|
209
|
+
const mediaStream = await navigator.mediaDevices.getUserMedia({
|
|
210
|
+
video: {
|
|
211
|
+
facingMode: facingMode,
|
|
212
|
+
width: { ideal: 1920 },
|
|
213
|
+
height: { ideal: 1920 },
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
setStream(mediaStream);
|
|
217
|
+
setCameraLoading(false);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
console.error("Camera error:", err);
|
|
221
|
+
setCameraError(labels.cameraError);
|
|
222
|
+
setCameraLoading(false);
|
|
223
|
+
cameraInputRef.current?.click();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const cancelCamera = () => {
|
|
227
|
+
stopCamera();
|
|
228
|
+
setCameraView("none");
|
|
229
|
+
setCapturedImage(null);
|
|
230
|
+
setCameraLoading(false);
|
|
231
|
+
};
|
|
232
|
+
const toggleCamera = async () => {
|
|
233
|
+
const newFacingMode = facingMode === "environment" ? "user" : "environment";
|
|
234
|
+
setFacingMode(newFacingMode);
|
|
235
|
+
if (stream) {
|
|
236
|
+
stopCamera();
|
|
237
|
+
try {
|
|
238
|
+
const mediaStream = await navigator.mediaDevices.getUserMedia({
|
|
239
|
+
video: { facingMode: newFacingMode },
|
|
240
|
+
});
|
|
241
|
+
setStream(mediaStream);
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
setCameraError("Could not switch camera");
|
|
245
|
+
setCameraView("none");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
const toggleFlash = async () => {
|
|
250
|
+
if (stream) {
|
|
251
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
252
|
+
if (videoTrack && "getCapabilities" in videoTrack) {
|
|
253
|
+
const capabilities = videoTrack.getCapabilities();
|
|
254
|
+
if (capabilities && "torch" in capabilities) {
|
|
255
|
+
try {
|
|
256
|
+
await videoTrack.applyConstraints({
|
|
257
|
+
advanced: [
|
|
258
|
+
{ torch: !flashEnabled },
|
|
259
|
+
],
|
|
260
|
+
});
|
|
261
|
+
setFlashEnabled(!flashEnabled);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
console.error("Torch toggle failed:", err);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const capturePhoto = () => {
|
|
271
|
+
if (!videoRef.current || !canvasRef.current)
|
|
272
|
+
return;
|
|
273
|
+
const video = videoRef.current;
|
|
274
|
+
const canvas = canvasRef.current;
|
|
275
|
+
const width = video.videoWidth || 1920;
|
|
276
|
+
const height = video.videoHeight || 1080;
|
|
277
|
+
canvas.width = width;
|
|
278
|
+
canvas.height = height;
|
|
279
|
+
const ctx = canvas.getContext("2d");
|
|
280
|
+
if (!ctx)
|
|
281
|
+
return;
|
|
282
|
+
if (facingMode === "user") {
|
|
283
|
+
ctx.translate(canvas.width, 0);
|
|
284
|
+
ctx.scale(-1, 1);
|
|
285
|
+
}
|
|
286
|
+
ctx.drawImage(video, 0, 0);
|
|
287
|
+
const imageData = canvas.toDataURL("image/jpeg", 0.9);
|
|
288
|
+
setCapturedImage(imageData);
|
|
289
|
+
canvas.toBlob((blob) => {
|
|
290
|
+
capturedBlobRef.current = blob;
|
|
291
|
+
}, "image/jpeg", 0.9);
|
|
292
|
+
setCameraView("captured");
|
|
293
|
+
stopCamera();
|
|
294
|
+
};
|
|
295
|
+
const retakePhoto = async () => {
|
|
296
|
+
setCapturedImage(null);
|
|
297
|
+
capturedBlobRef.current = null;
|
|
298
|
+
setVideoReady(false);
|
|
299
|
+
setCameraLoading(true);
|
|
300
|
+
try {
|
|
301
|
+
const mediaStream = await navigator.mediaDevices.getUserMedia({
|
|
302
|
+
video: { facingMode },
|
|
303
|
+
});
|
|
304
|
+
setStream(mediaStream);
|
|
305
|
+
setCameraLoading(false);
|
|
306
|
+
}
|
|
307
|
+
catch (err) {
|
|
308
|
+
setCameraError("Could not restart camera");
|
|
309
|
+
setCameraLoading(false);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const confirmPhoto = () => {
|
|
313
|
+
if (!capturedImage)
|
|
314
|
+
return;
|
|
315
|
+
setCameraView("crop");
|
|
316
|
+
};
|
|
317
|
+
const cancelCrop = () => {
|
|
318
|
+
setCameraView("captured");
|
|
319
|
+
setCropCompleteArea(null);
|
|
320
|
+
};
|
|
321
|
+
const applyCrop = async () => {
|
|
322
|
+
if (!capturedImage || !cropCompleteArea)
|
|
323
|
+
return;
|
|
324
|
+
try {
|
|
325
|
+
const img = await new Promise((resolve, reject) => {
|
|
326
|
+
const image = new Image();
|
|
327
|
+
image.onload = () => resolve(image);
|
|
328
|
+
image.onerror = () => reject(new Error("Could not load image for crop"));
|
|
329
|
+
image.src = capturedImage;
|
|
330
|
+
});
|
|
331
|
+
const canvas = document.createElement("canvas");
|
|
332
|
+
const ctx = canvas.getContext("2d");
|
|
333
|
+
if (!ctx)
|
|
334
|
+
throw new Error("Could not get canvas context");
|
|
335
|
+
const { x, y, width, height } = cropCompleteArea;
|
|
336
|
+
canvas.width = width;
|
|
337
|
+
canvas.height = height;
|
|
338
|
+
ctx.drawImage(img, x, y, width, height, 0, 0, width, height);
|
|
339
|
+
const blob = await new Promise((resolve, reject) => {
|
|
340
|
+
canvas.toBlob((b) => {
|
|
341
|
+
if (b)
|
|
342
|
+
resolve(b);
|
|
343
|
+
else
|
|
344
|
+
reject(new Error("Could not create cropped blob"));
|
|
345
|
+
}, "image/jpeg", 0.9);
|
|
346
|
+
});
|
|
347
|
+
const file = new File([blob], `photo_${Date.now()}.jpg`, {
|
|
348
|
+
type: "image/jpeg",
|
|
349
|
+
});
|
|
350
|
+
const compressedFile = await compressImage(file, {
|
|
351
|
+
maxWidth: 1920,
|
|
352
|
+
maxHeight: 1920,
|
|
353
|
+
quality: 0.85,
|
|
354
|
+
mimeType: "image/jpeg",
|
|
355
|
+
});
|
|
356
|
+
setCameraView("none");
|
|
357
|
+
setCapturedImage(null);
|
|
358
|
+
capturedBlobRef.current = null;
|
|
359
|
+
setCropCompleteArea(null);
|
|
360
|
+
setStatus("uploading");
|
|
361
|
+
await onFileSelect(compressedFile);
|
|
362
|
+
setStatus("complete");
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
365
|
+
console.error("Crop processing error:", err);
|
|
366
|
+
setStatus("error");
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
const videoTrack = stream?.getVideoTracks()[0];
|
|
370
|
+
const torchSupported = videoTrack
|
|
371
|
+
? !!videoTrack.getCapabilities?.()?.torch
|
|
372
|
+
: false;
|
|
373
|
+
return {
|
|
374
|
+
stream,
|
|
375
|
+
cameraView,
|
|
376
|
+
facingMode,
|
|
377
|
+
flashEnabled,
|
|
378
|
+
capturedImage,
|
|
379
|
+
cameraError,
|
|
380
|
+
videoReady,
|
|
381
|
+
cameraLoading,
|
|
382
|
+
videoRef,
|
|
383
|
+
canvasRef,
|
|
384
|
+
cameraInputRef,
|
|
385
|
+
torchSupported,
|
|
386
|
+
cropCompleteArea,
|
|
387
|
+
handleCameraClick,
|
|
388
|
+
cancelCamera,
|
|
389
|
+
toggleCamera,
|
|
390
|
+
toggleFlash,
|
|
391
|
+
capturePhoto,
|
|
392
|
+
retakePhoto,
|
|
393
|
+
confirmPhoto,
|
|
394
|
+
cancelCrop,
|
|
395
|
+
applyCrop,
|
|
396
|
+
setCropCompleteArea,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
class FileUploadErrorBoundary extends React.Component {
|
|
401
|
+
constructor(props) {
|
|
402
|
+
super(props);
|
|
403
|
+
this.state = { hasError: false };
|
|
404
|
+
}
|
|
405
|
+
static getDerivedStateFromError() {
|
|
406
|
+
return { hasError: true };
|
|
407
|
+
}
|
|
408
|
+
componentDidCatch(error, errorInfo) {
|
|
409
|
+
console.error("FileUploadErrorBoundary caught an error:", error, errorInfo);
|
|
410
|
+
}
|
|
411
|
+
handleRetry = () => {
|
|
412
|
+
this.setState({ hasError: false });
|
|
413
|
+
};
|
|
414
|
+
render() {
|
|
415
|
+
if (this.state.hasError) {
|
|
416
|
+
return (jsxRuntime.jsxs("div", { style: { padding: "1rem", textAlign: "center" }, children: [jsxRuntime.jsx("p", { children: this.props.fallbackMessage || "Something went wrong" }), jsxRuntime.jsx("button", { type: "button", onClick: this.handleRetry, children: "Try Again" })] }));
|
|
417
|
+
}
|
|
418
|
+
return this.props.children;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const CameraCapture$2 = React.lazy(() => Promise.resolve().then(function () { return CameraCapture$1; }));
|
|
423
|
+
const DEFAULT_LABELS = {
|
|
424
|
+
browseFiles: "Browse Files",
|
|
425
|
+
takePhoto: "Take Photo",
|
|
426
|
+
uploadComplete: "Upload complete!",
|
|
427
|
+
uploadFailed: "Upload failed. Please try again.",
|
|
428
|
+
uploading: "Uploading...",
|
|
429
|
+
noFileSelected: "No file selected. Click or drag file here to upload",
|
|
430
|
+
invalidFileType: "Invalid file type",
|
|
431
|
+
cameraError: "Could not access camera. Please check permissions.",
|
|
432
|
+
retake: "Retake",
|
|
433
|
+
usePhoto: "Use Photo",
|
|
434
|
+
cancel: "Cancel",
|
|
435
|
+
switchCamera: "Switch Camera",
|
|
436
|
+
toggleFlash: "Toggle Flash",
|
|
437
|
+
cropTitle: "Crop Image",
|
|
438
|
+
cropSave: "Save",
|
|
439
|
+
cropCancel: "Back",
|
|
440
|
+
};
|
|
441
|
+
const DEFAULT_MULTI_LABELS = {
|
|
442
|
+
addMoreFiles: "Add more files",
|
|
443
|
+
removeFile: "Remove",
|
|
444
|
+
filesQueued: "files queued",
|
|
445
|
+
clearAll: "Clear all",
|
|
446
|
+
pending: "Pending",
|
|
447
|
+
retryFile: "Retry",
|
|
448
|
+
};
|
|
449
|
+
const DEFAULT_ICONS = {
|
|
450
|
+
camera: jsxRuntime.jsx(md.MdCameraAlt, {}),
|
|
451
|
+
browse: jsxRuntime.jsx(md.MdOutlineFileUpload, {}),
|
|
452
|
+
close: jsxRuntime.jsx(md.MdClose, {}),
|
|
453
|
+
flashOn: jsxRuntime.jsx(md.MdFlashOn, {}),
|
|
454
|
+
flashOff: jsxRuntime.jsx(md.MdFlashOff, {}),
|
|
455
|
+
switchCamera: jsxRuntime.jsx(md.MdCameraswitch, {}),
|
|
456
|
+
retake: jsxRuntime.jsx(md.MdRefresh, {}),
|
|
457
|
+
confirm: jsxRuntime.jsx(md.MdCheck, {}),
|
|
458
|
+
};
|
|
459
|
+
function generateFileId() {
|
|
460
|
+
return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function"
|
|
461
|
+
? crypto.randomUUID()
|
|
462
|
+
: `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
463
|
+
}
|
|
464
|
+
function formatBytes(bytes) {
|
|
465
|
+
if (bytes < 1024)
|
|
466
|
+
return `${bytes} B`;
|
|
467
|
+
if (bytes < 1024 * 1024)
|
|
468
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
469
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
470
|
+
}
|
|
471
|
+
const FileUpload = React.forwardRef(({ disabled, label, onFileSelect, progressPercentage = 0, accept, capture, hideCompletionMessage, onError, maxFileSize, labels: labelsProp, successTimeout = 5000, errorBoundary, icons: iconsProp, multiple = false, onFilesSelect, filesProgress, maxFiles, multiLabels: multiLabelsProp, }, ref) => {
|
|
472
|
+
const labels = { ...DEFAULT_LABELS, ...labelsProp };
|
|
473
|
+
const multiLabels = { ...DEFAULT_MULTI_LABELS, ...multiLabelsProp };
|
|
474
|
+
const icons = { ...DEFAULT_ICONS, ...iconsProp };
|
|
475
|
+
// Single-mode state (unchanged)
|
|
476
|
+
const [selectedFile, setSelectedFile] = React.useState(null);
|
|
477
|
+
const [status, setStatus] = React.useState("idle");
|
|
478
|
+
const [isDragOver, setIsDragOver] = React.useState(false);
|
|
479
|
+
const { isBrowser } = useBrowser();
|
|
480
|
+
const [internalError, setInternalError] = React.useState(null);
|
|
481
|
+
const fileInputRef = React.useRef(null);
|
|
482
|
+
const successTimeoutRef = React.useRef(null);
|
|
483
|
+
const { validate } = useFileValidation(accept || "", maxFileSize);
|
|
484
|
+
// Multi-mode state (declared unconditionally — Rules of Hooks)
|
|
485
|
+
const [fileQueue, setFileQueue] = React.useState([]);
|
|
486
|
+
const [multiDragOver, setMultiDragOver] = React.useState(false);
|
|
487
|
+
// Queue mutators — all use functional update form, safe for concurrent calls
|
|
488
|
+
function markEntry(id, status, error) {
|
|
489
|
+
setFileQueue((prev) => prev.map((e) => e.id === id ? { ...e, status, error: e.error } : e));
|
|
490
|
+
}
|
|
491
|
+
function removeFromQueue(id) {
|
|
492
|
+
setFileQueue((prev) => prev.filter((e) => e.id !== id));
|
|
493
|
+
}
|
|
494
|
+
async function triggerUpload(entries) {
|
|
495
|
+
if (onFilesSelect) {
|
|
496
|
+
entries.forEach((e) => markEntry(e.id, "uploading"));
|
|
497
|
+
try {
|
|
498
|
+
await onFilesSelect(entries.map((e) => e.file));
|
|
499
|
+
entries.forEach((e) => markEntry(e.id, "complete"));
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
entries.forEach((e) => markEntry(e.id, "error"));
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
await Promise.allSettled(entries.map(async (entry) => {
|
|
507
|
+
markEntry(entry.id, "uploading");
|
|
508
|
+
try {
|
|
509
|
+
await onFileSelect(entry.file);
|
|
510
|
+
markEntry(entry.id, "complete");
|
|
511
|
+
}
|
|
512
|
+
catch {
|
|
513
|
+
markEntry(entry.id, "error");
|
|
514
|
+
}
|
|
515
|
+
}));
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function addFilesToQueue(rawFiles) {
|
|
519
|
+
const remaining = maxFiles != null ? maxFiles - fileQueue.length : Infinity;
|
|
520
|
+
const capped = rawFiles.slice(0, remaining);
|
|
521
|
+
const entries = capped.map((file) => {
|
|
522
|
+
const { isValid, error } = validate(file);
|
|
523
|
+
return {
|
|
524
|
+
id: generateFileId(),
|
|
525
|
+
file,
|
|
526
|
+
status: isValid ? "pending" : "error",
|
|
527
|
+
error: isValid ? null : (error || labels.invalidFileType),
|
|
528
|
+
};
|
|
529
|
+
});
|
|
530
|
+
setFileQueue((prev) => [...prev, ...entries]);
|
|
531
|
+
const validEntries = entries.filter((e) => e.status === "pending");
|
|
532
|
+
if (validEntries.length > 0)
|
|
533
|
+
triggerUpload(validEntries);
|
|
534
|
+
}
|
|
535
|
+
function retryEntry(id) {
|
|
536
|
+
const entry = fileQueue.find((e) => e.id === id);
|
|
537
|
+
if (!entry)
|
|
538
|
+
return;
|
|
539
|
+
markEntry(id, "pending");
|
|
540
|
+
triggerUpload([{ ...entry, status: "pending" }]);
|
|
541
|
+
}
|
|
542
|
+
const camera = useCamera({
|
|
543
|
+
capture,
|
|
544
|
+
onFileSelect: multiple
|
|
545
|
+
? async (file) => { if (file)
|
|
546
|
+
addFilesToQueue([file]); }
|
|
547
|
+
: async (file) => {
|
|
548
|
+
setSelectedFile(file);
|
|
549
|
+
await onFileSelect(file);
|
|
550
|
+
},
|
|
551
|
+
setStatus,
|
|
552
|
+
onError,
|
|
553
|
+
labels,
|
|
554
|
+
});
|
|
555
|
+
const handleFileChange = async (event) => {
|
|
556
|
+
if (multiple) {
|
|
557
|
+
const files = Array.from(event.target.files ?? []);
|
|
558
|
+
event.target.value = "";
|
|
559
|
+
addFilesToQueue(files);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const file = event.target.files ? event.target.files[0] : null;
|
|
563
|
+
if (file) {
|
|
564
|
+
const { isValid, error } = validate(file);
|
|
565
|
+
if (!isValid) {
|
|
566
|
+
const msg = error || labels.invalidFileType;
|
|
567
|
+
setInternalError(msg);
|
|
568
|
+
onError?.(msg);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
setInternalError(null);
|
|
573
|
+
setSelectedFile(file);
|
|
574
|
+
setStatus("uploading");
|
|
575
|
+
try {
|
|
576
|
+
await onFileSelect(file);
|
|
577
|
+
setStatus("complete");
|
|
578
|
+
}
|
|
579
|
+
catch {
|
|
580
|
+
setStatus("error");
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
const clearFile = () => {
|
|
584
|
+
setSelectedFile(null);
|
|
585
|
+
onFileSelect(null).catch(() => { });
|
|
586
|
+
setStatus("idle");
|
|
587
|
+
};
|
|
588
|
+
const handleRetry = () => {
|
|
589
|
+
setSelectedFile(null);
|
|
590
|
+
setStatus("idle");
|
|
591
|
+
setInternalError(null);
|
|
592
|
+
};
|
|
593
|
+
React.useImperativeHandle(ref, () => ({
|
|
594
|
+
clearFile,
|
|
595
|
+
clearAll: () => { if (multiple)
|
|
596
|
+
setFileQueue([]); },
|
|
597
|
+
}));
|
|
598
|
+
const handleContainerClick = () => {
|
|
599
|
+
if (!isBrowser)
|
|
600
|
+
return;
|
|
601
|
+
fileInputRef.current?.click();
|
|
602
|
+
};
|
|
603
|
+
const handleBrowseClick = (e) => {
|
|
604
|
+
if (!isBrowser)
|
|
605
|
+
return;
|
|
606
|
+
e.stopPropagation();
|
|
607
|
+
fileInputRef.current?.click();
|
|
608
|
+
};
|
|
609
|
+
React.useEffect(() => {
|
|
610
|
+
if (status === "complete" && successTimeout > 0) {
|
|
611
|
+
successTimeoutRef.current = setTimeout(() => {
|
|
612
|
+
setStatus("idle");
|
|
613
|
+
}, successTimeout);
|
|
614
|
+
}
|
|
615
|
+
return () => {
|
|
616
|
+
if (successTimeoutRef.current) {
|
|
617
|
+
clearTimeout(successTimeoutRef.current);
|
|
618
|
+
successTimeoutRef.current = null;
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
}, [status, successTimeout]);
|
|
622
|
+
const handleDragOver = (event) => {
|
|
623
|
+
event.preventDefault();
|
|
624
|
+
setIsDragOver(true);
|
|
625
|
+
};
|
|
626
|
+
const handleDragLeave = () => {
|
|
627
|
+
setIsDragOver(false);
|
|
628
|
+
};
|
|
629
|
+
const handleDrop = async (event) => {
|
|
630
|
+
event.preventDefault();
|
|
631
|
+
setIsDragOver(false);
|
|
632
|
+
if (multiple) {
|
|
633
|
+
const files = Array.from(event.dataTransfer.files);
|
|
634
|
+
setMultiDragOver(false);
|
|
635
|
+
addFilesToQueue(files);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
const file = event.dataTransfer.files
|
|
639
|
+
? event.dataTransfer.files[0]
|
|
640
|
+
: null;
|
|
641
|
+
if (file) {
|
|
642
|
+
const { isValid, error } = validate(file);
|
|
643
|
+
if (!isValid) {
|
|
644
|
+
const msg = error || labels.invalidFileType;
|
|
645
|
+
setInternalError(msg);
|
|
646
|
+
onError?.(msg);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
setInternalError(null);
|
|
651
|
+
setSelectedFile(file);
|
|
652
|
+
setStatus("uploading");
|
|
653
|
+
try {
|
|
654
|
+
await onFileSelect(file);
|
|
655
|
+
setStatus("complete");
|
|
656
|
+
}
|
|
657
|
+
catch {
|
|
658
|
+
setStatus("error");
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
const getStatusMessage = () => {
|
|
662
|
+
switch (status) {
|
|
663
|
+
case "idle":
|
|
664
|
+
return "";
|
|
665
|
+
case "uploading":
|
|
666
|
+
return labels.uploading;
|
|
667
|
+
case "complete":
|
|
668
|
+
return hideCompletionMessage === true ? "" : labels.uploadComplete;
|
|
669
|
+
case "error":
|
|
670
|
+
return labels.uploadFailed;
|
|
671
|
+
default:
|
|
672
|
+
return "";
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
const cameraOverlay = isBrowser && camera.cameraView !== "none" && (jsxRuntime.jsx(React.Suspense, { fallback: null, children: jsxRuntime.jsx(CameraCapture$2, { cameraView: camera.cameraView, facingMode: camera.facingMode, flashEnabled: camera.flashEnabled, capturedImage: camera.capturedImage, cameraError: camera.cameraError, cameraLoading: camera.cameraLoading, videoRef: camera.videoRef, canvasRef: camera.canvasRef, torchSupported: camera.torchSupported, labels: labels, icons: {
|
|
676
|
+
close: icons.close,
|
|
677
|
+
flashOn: icons.flashOn,
|
|
678
|
+
flashOff: icons.flashOff,
|
|
679
|
+
switchCamera: icons.switchCamera,
|
|
680
|
+
retake: icons.retake,
|
|
681
|
+
confirm: icons.confirm,
|
|
682
|
+
}, onCancel: camera.cancelCamera, onToggleCamera: camera.toggleCamera, onToggleFlash: camera.toggleFlash, onCapture: camera.capturePhoto, onRetake: camera.retakePhoto, onConfirm: camera.confirmPhoto, onCropCancel: camera.cancelCrop, onApplyCrop: camera.applyCrop, onCropComplete: camera.setCropCompleteArea }) }));
|
|
683
|
+
const renderSingleMode = () => (jsxRuntime.jsxs("div", { className: `${disabled ? styles.disabled : ""} ${styles.fileUploadContainer}`, children: [jsxRuntime.jsx("label", { className: styles.label, children: label }), jsxRuntime.jsxs("div", { className: `${styles.fileInputContainer} ${isDragOver ? styles.dragOver : ""}`, onClick: handleContainerClick, onKeyDown: (e) => {
|
|
684
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
685
|
+
e.preventDefault();
|
|
686
|
+
handleContainerClick();
|
|
687
|
+
}
|
|
688
|
+
}, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, tabIndex: 0, role: "button", children: [jsxRuntime.jsx("input", { ref: fileInputRef, type: "file", className: styles.fileInput, onChange: handleFileChange, style: { cursor: "pointer" }, accept: accept }), jsxRuntime.jsx("input", { ref: camera.cameraInputRef, type: "file", accept: "image/*", capture: capture, style: { display: "none" }, onChange: handleFileChange }), jsxRuntime.jsxs("div", { className: styles.mobileButtons, children: [jsxRuntime.jsxs("button", { type: "button", className: styles.mobileButton, onClick: camera.handleCameraClick, disabled: disabled, children: [icons.camera, jsxRuntime.jsx("span", { children: labels.takePhoto })] }), jsxRuntime.jsxs("button", { type: "button", className: styles.mobileButton, onClick: handleBrowseClick, disabled: disabled, children: [icons.browse, jsxRuntime.jsx("span", { children: labels.browseFiles })] })] }), jsxRuntime.jsxs("div", { className: styles.visibleElements, children: [jsxRuntime.jsx(md.MdOutlineFileUpload, {}), jsxRuntime.jsx("div", { children: selectedFile
|
|
689
|
+
? selectedFile.name
|
|
690
|
+
: labels.noFileSelected })] })] }), status === "uploading" && (jsxRuntime.jsxs("div", { className: styles.progressDialog, role: "status", children: [jsxRuntime.jsx("div", { className: styles.progressBar, children: jsxRuntime.jsx("div", { className: styles.progressFill, style: { width: `${progressPercentage}%` } }) }), jsxRuntime.jsx("span", { children: `${labels.uploading} ${progressPercentage.toFixed(2)}%` })] })), status !== "idle" && status !== "uploading" && (jsxRuntime.jsxs("div", { className: `${styles.statusMessage} ${status === "complete"
|
|
691
|
+
? styles.successAnimation
|
|
692
|
+
: status === "error"
|
|
693
|
+
? styles.errorAnimation
|
|
694
|
+
: ""}`, "aria-live": "polite", children: [getStatusMessage(), status === "error" && (jsxRuntime.jsx("button", { type: "button", className: styles.retryBtn, onClick: handleRetry, "aria-label": "Retry upload", children: "Retry" }))] })), cameraOverlay, internalError && (jsxRuntime.jsx("div", { className: styles.errorMessage, role: "alert", children: internalError }))] }));
|
|
695
|
+
const statusLabels = {
|
|
696
|
+
pending: multiLabels.pending,
|
|
697
|
+
uploading: labels.uploading,
|
|
698
|
+
complete: labels.uploadComplete,
|
|
699
|
+
};
|
|
700
|
+
const renderMultiMode = () => (jsxRuntime.jsxs("div", { className: `${disabled ? styles.disabled : ""} ${styles.fileUploadContainer}`, children: [jsxRuntime.jsx("label", { className: styles.label, children: label }), jsxRuntime.jsxs("div", { className: `${styles.fileInputContainer} ${multiDragOver ? styles.dragOver : ""} ${fileQueue.length > 0 ? styles.multiDropZoneCompact : ""}`, onClick: handleContainerClick, onKeyDown: (e) => {
|
|
701
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
702
|
+
e.preventDefault();
|
|
703
|
+
handleContainerClick();
|
|
704
|
+
}
|
|
705
|
+
}, onDragOver: (e) => { e.preventDefault(); setMultiDragOver(true); }, onDragLeave: () => setMultiDragOver(false), onDrop: handleDrop, tabIndex: 0, role: "button", children: [jsxRuntime.jsx("input", { ref: fileInputRef, type: "file", multiple: true, className: styles.fileInput, onChange: handleFileChange, style: { cursor: "pointer" }, accept: accept }), jsxRuntime.jsx("input", { ref: camera.cameraInputRef, type: "file", accept: "image/*", capture: capture, style: { display: "none" }, onChange: handleFileChange }), jsxRuntime.jsxs("div", { className: styles.mobileButtons, children: [jsxRuntime.jsxs("button", { type: "button", className: styles.mobileButton, onClick: camera.handleCameraClick, disabled: disabled, children: [icons.camera, jsxRuntime.jsx("span", { children: labels.takePhoto })] }), jsxRuntime.jsxs("button", { type: "button", className: styles.mobileButton, onClick: handleBrowseClick, disabled: disabled, children: [icons.browse, jsxRuntime.jsx("span", { children: labels.browseFiles })] })] }), jsxRuntime.jsxs("div", { className: styles.visibleElements, children: [jsxRuntime.jsx(md.MdOutlineFileUpload, {}), jsxRuntime.jsx("div", { children: fileQueue.length > 0
|
|
706
|
+
? `${fileQueue.length} ${multiLabels.filesQueued} — drop more or browse`
|
|
707
|
+
: labels.noFileSelected })] })] }), fileQueue.length > 0 && (jsxRuntime.jsx("ul", { className: styles.fileList, "aria-label": "Queued files", children: fileQueue.map((entry, i) => (jsxRuntime.jsxs("li", { className: `${styles.fileRow} ${styles[`fileRow_${entry.status}`]}`, style: { animationDelay: `${i * 40}ms` }, children: [jsxRuntime.jsxs("div", { className: styles.fileRowMeta, children: [jsxRuntime.jsx("span", { className: styles.fileRowFilename, children: entry.file.name }), jsxRuntime.jsx("span", { className: styles.fileRowSize, children: formatBytes(entry.file.size) })] }), jsxRuntime.jsx("span", { className: `${styles.fileRowBadge} ${styles[`badge_${entry.status}`]}`, children: entry.status === "error"
|
|
708
|
+
? (entry.error ?? labels.uploadFailed)
|
|
709
|
+
: statusLabels[entry.status] }), entry.status === "uploading" && (jsxRuntime.jsx("div", { className: styles.fileRowProgress, children: filesProgress?.[entry.id] != null
|
|
710
|
+
? (jsxRuntime.jsx("div", { className: styles.fileRowProgressFill, style: { width: `${filesProgress[entry.id]}%` } }))
|
|
711
|
+
: jsxRuntime.jsx("div", { className: styles.fileRowProgressIndeterminate }) })), jsxRuntime.jsxs("div", { className: styles.fileRowActions, children: [entry.status === "error" && (jsxRuntime.jsx("button", { type: "button", className: styles.retryFileBtn, onClick: () => retryEntry(entry.id), children: multiLabels.retryFile })), entry.status !== "uploading" && (jsxRuntime.jsx("button", { type: "button", className: styles.removeFileBtn, onClick: () => removeFromQueue(entry.id), "aria-label": `${multiLabels.removeFile} ${entry.file.name}`, children: icons.close }))] })] }, entry.id))) })), fileQueue.length > 0 && (jsxRuntime.jsx("button", { type: "button", className: styles.clearAllBtn, onClick: () => setFileQueue([]), children: multiLabels.clearAll })), cameraOverlay, internalError && (jsxRuntime.jsx("div", { className: styles.errorMessage, role: "alert", children: internalError }))] }));
|
|
712
|
+
const content = multiple ? renderMultiMode() : renderSingleMode();
|
|
713
|
+
if (errorBoundary) {
|
|
714
|
+
return jsxRuntime.jsx(FileUploadErrorBoundary, { children: content });
|
|
715
|
+
}
|
|
716
|
+
return content;
|
|
717
|
+
});
|
|
718
|
+
FileUpload.displayName = "FileUpload";
|
|
719
|
+
|
|
720
|
+
/******************************************************************************
|
|
721
|
+
Copyright (c) Microsoft Corporation.
|
|
722
|
+
|
|
723
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
724
|
+
purpose with or without fee is hereby granted.
|
|
725
|
+
|
|
726
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
727
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
728
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
729
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
730
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
731
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
732
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
733
|
+
***************************************************************************** */
|
|
734
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
735
|
+
|
|
736
|
+
var extendStatics = function(d, b) {
|
|
737
|
+
extendStatics = Object.setPrototypeOf ||
|
|
738
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
739
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
740
|
+
return extendStatics(d, b);
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
function __extends(d, b) {
|
|
744
|
+
if (typeof b !== "function" && b !== null)
|
|
745
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
746
|
+
extendStatics(d, b);
|
|
747
|
+
function __() { this.constructor = d; }
|
|
748
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
var __assign = function() {
|
|
752
|
+
__assign = Object.assign || function __assign(t) {
|
|
753
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
754
|
+
s = arguments[i];
|
|
755
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
756
|
+
}
|
|
757
|
+
return t;
|
|
758
|
+
};
|
|
759
|
+
return __assign.apply(this, arguments);
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
763
|
+
var e = new Error(message);
|
|
764
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
function getDefaultExportFromCjs (x) {
|
|
768
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Copyright 2004-present Facebook. All Rights Reserved.
|
|
773
|
+
*
|
|
774
|
+
* @providesModule UserAgent_DEPRECATED
|
|
775
|
+
*/
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Provides entirely client-side User Agent and OS detection. You should prefer
|
|
779
|
+
* the non-deprecated UserAgent module when possible, which exposes our
|
|
780
|
+
* authoritative server-side PHP-based detection to the client.
|
|
781
|
+
*
|
|
782
|
+
* Usage is straightforward:
|
|
783
|
+
*
|
|
784
|
+
* if (UserAgent_DEPRECATED.ie()) {
|
|
785
|
+
* // IE
|
|
786
|
+
* }
|
|
787
|
+
*
|
|
788
|
+
* You can also do version checks:
|
|
789
|
+
*
|
|
790
|
+
* if (UserAgent_DEPRECATED.ie() >= 7) {
|
|
791
|
+
* // IE7 or better
|
|
792
|
+
* }
|
|
793
|
+
*
|
|
794
|
+
* The browser functions will return NaN if the browser does not match, so
|
|
795
|
+
* you can also do version compares the other way:
|
|
796
|
+
*
|
|
797
|
+
* if (UserAgent_DEPRECATED.ie() < 7) {
|
|
798
|
+
* // IE6 or worse
|
|
799
|
+
* }
|
|
800
|
+
*
|
|
801
|
+
* Note that the version is a float and may include a minor version number,
|
|
802
|
+
* so you should always use range operators to perform comparisons, not
|
|
803
|
+
* strict equality.
|
|
804
|
+
*
|
|
805
|
+
* **Note:** You should **strongly** prefer capability detection to browser
|
|
806
|
+
* version detection where it's reasonable:
|
|
807
|
+
*
|
|
808
|
+
* http://www.quirksmode.org/js/support.html
|
|
809
|
+
*
|
|
810
|
+
* Further, we have a large number of mature wrapper functions and classes
|
|
811
|
+
* which abstract away many browser irregularities. Check the documentation,
|
|
812
|
+
* grep for things, or ask on javascript@lists.facebook.com before writing yet
|
|
813
|
+
* another copy of "event || window.event".
|
|
814
|
+
*
|
|
815
|
+
*/
|
|
816
|
+
|
|
817
|
+
var _populated = false;
|
|
818
|
+
|
|
819
|
+
// Browsers
|
|
820
|
+
var _ie, _firefox, _opera, _webkit, _chrome;
|
|
821
|
+
|
|
822
|
+
// Actual IE browser for compatibility mode
|
|
823
|
+
var _ie_real_version;
|
|
824
|
+
|
|
825
|
+
// Platforms
|
|
826
|
+
var _osx, _windows, _linux, _android;
|
|
827
|
+
|
|
828
|
+
// Architectures
|
|
829
|
+
var _win64;
|
|
830
|
+
|
|
831
|
+
// Devices
|
|
832
|
+
var _iphone, _ipad, _native;
|
|
833
|
+
|
|
834
|
+
var _mobile;
|
|
835
|
+
|
|
836
|
+
function _populate() {
|
|
837
|
+
if (_populated) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
_populated = true;
|
|
842
|
+
|
|
843
|
+
// To work around buggy JS libraries that can't handle multi-digit
|
|
844
|
+
// version numbers, Opera 10's user agent string claims it's Opera
|
|
845
|
+
// 9, then later includes a Version/X.Y field:
|
|
846
|
+
//
|
|
847
|
+
// Opera/9.80 (foo) Presto/2.2.15 Version/10.10
|
|
848
|
+
var uas = navigator.userAgent;
|
|
849
|
+
var agent = /(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(uas);
|
|
850
|
+
var os = /(Mac OS X)|(Windows)|(Linux)/.exec(uas);
|
|
851
|
+
|
|
852
|
+
_iphone = /\b(iPhone|iP[ao]d)/.exec(uas);
|
|
853
|
+
_ipad = /\b(iP[ao]d)/.exec(uas);
|
|
854
|
+
_android = /Android/i.exec(uas);
|
|
855
|
+
_native = /FBAN\/\w+;/i.exec(uas);
|
|
856
|
+
_mobile = /Mobile/i.exec(uas);
|
|
857
|
+
|
|
858
|
+
// Note that the IE team blog would have you believe you should be checking
|
|
859
|
+
// for 'Win64; x64'. But MSDN then reveals that you can actually be coming
|
|
860
|
+
// from either x64 or ia64; so ultimately, you should just check for Win64
|
|
861
|
+
// as in indicator of whether you're in 64-bit IE. 32-bit IE on 64-bit
|
|
862
|
+
// Windows will send 'WOW64' instead.
|
|
863
|
+
_win64 = !!(/Win64/.exec(uas));
|
|
864
|
+
|
|
865
|
+
if (agent) {
|
|
866
|
+
_ie = agent[1] ? parseFloat(agent[1]) : (
|
|
867
|
+
agent[5] ? parseFloat(agent[5]) : NaN);
|
|
868
|
+
// IE compatibility mode
|
|
869
|
+
if (_ie && document && document.documentMode) {
|
|
870
|
+
_ie = document.documentMode;
|
|
871
|
+
}
|
|
872
|
+
// grab the "true" ie version from the trident token if available
|
|
873
|
+
var trident = /(?:Trident\/(\d+.\d+))/.exec(uas);
|
|
874
|
+
_ie_real_version = trident ? parseFloat(trident[1]) + 4 : _ie;
|
|
875
|
+
|
|
876
|
+
_firefox = agent[2] ? parseFloat(agent[2]) : NaN;
|
|
877
|
+
_opera = agent[3] ? parseFloat(agent[3]) : NaN;
|
|
878
|
+
_webkit = agent[4] ? parseFloat(agent[4]) : NaN;
|
|
879
|
+
if (_webkit) {
|
|
880
|
+
// We do not add the regexp to the above test, because it will always
|
|
881
|
+
// match 'safari' only since 'AppleWebKit' appears before 'Chrome' in
|
|
882
|
+
// the userAgent string.
|
|
883
|
+
agent = /(?:Chrome\/(\d+\.\d+))/.exec(uas);
|
|
884
|
+
_chrome = agent && agent[1] ? parseFloat(agent[1]) : NaN;
|
|
885
|
+
} else {
|
|
886
|
+
_chrome = NaN;
|
|
887
|
+
}
|
|
888
|
+
} else {
|
|
889
|
+
_ie = _firefox = _opera = _chrome = _webkit = NaN;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
if (os) {
|
|
893
|
+
if (os[1]) {
|
|
894
|
+
// Detect OS X version. If no version number matches, set _osx to true.
|
|
895
|
+
// Version examples: 10, 10_6_1, 10.7
|
|
896
|
+
// Parses version number as a float, taking only first two sets of
|
|
897
|
+
// digits. If only one set of digits is found, returns just the major
|
|
898
|
+
// version number.
|
|
899
|
+
var ver = /(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(uas);
|
|
900
|
+
|
|
901
|
+
_osx = ver ? parseFloat(ver[1].replace('_', '.')) : true;
|
|
902
|
+
} else {
|
|
903
|
+
_osx = false;
|
|
904
|
+
}
|
|
905
|
+
_windows = !!os[2];
|
|
906
|
+
_linux = !!os[3];
|
|
907
|
+
} else {
|
|
908
|
+
_osx = _windows = _linux = false;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
var UserAgent_DEPRECATED$1 = {
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Check if the UA is Internet Explorer.
|
|
916
|
+
*
|
|
917
|
+
*
|
|
918
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
919
|
+
*/
|
|
920
|
+
ie: function() {
|
|
921
|
+
return _populate() || _ie;
|
|
922
|
+
},
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* Check if we're in Internet Explorer compatibility mode.
|
|
926
|
+
*
|
|
927
|
+
* @return bool true if in compatibility mode, false if
|
|
928
|
+
* not compatibility mode or not ie
|
|
929
|
+
*/
|
|
930
|
+
ieCompatibilityMode: function() {
|
|
931
|
+
return _populate() || (_ie_real_version > _ie);
|
|
932
|
+
},
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* Whether the browser is 64-bit IE. Really, this is kind of weak sauce; we
|
|
937
|
+
* only need this because Skype can't handle 64-bit IE yet. We need to remove
|
|
938
|
+
* this when we don't need it -- tracked by #601957.
|
|
939
|
+
*/
|
|
940
|
+
ie64: function() {
|
|
941
|
+
return UserAgent_DEPRECATED$1.ie() && _win64;
|
|
942
|
+
},
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Check if the UA is Firefox.
|
|
946
|
+
*
|
|
947
|
+
*
|
|
948
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
949
|
+
*/
|
|
950
|
+
firefox: function() {
|
|
951
|
+
return _populate() || _firefox;
|
|
952
|
+
},
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* Check if the UA is Opera.
|
|
957
|
+
*
|
|
958
|
+
*
|
|
959
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
960
|
+
*/
|
|
961
|
+
opera: function() {
|
|
962
|
+
return _populate() || _opera;
|
|
963
|
+
},
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* Check if the UA is WebKit.
|
|
968
|
+
*
|
|
969
|
+
*
|
|
970
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
971
|
+
*/
|
|
972
|
+
webkit: function() {
|
|
973
|
+
return _populate() || _webkit;
|
|
974
|
+
},
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* For Push
|
|
978
|
+
* WILL BE REMOVED VERY SOON. Use UserAgent_DEPRECATED.webkit
|
|
979
|
+
*/
|
|
980
|
+
safari: function() {
|
|
981
|
+
return UserAgent_DEPRECATED$1.webkit();
|
|
982
|
+
},
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* Check if the UA is a Chrome browser.
|
|
986
|
+
*
|
|
987
|
+
*
|
|
988
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
989
|
+
*/
|
|
990
|
+
chrome : function() {
|
|
991
|
+
return _populate() || _chrome;
|
|
992
|
+
},
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Check if the user is running Windows.
|
|
997
|
+
*
|
|
998
|
+
* @return bool `true' if the user's OS is Windows.
|
|
999
|
+
*/
|
|
1000
|
+
windows: function() {
|
|
1001
|
+
return _populate() || _windows;
|
|
1002
|
+
},
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Check if the user is running Mac OS X.
|
|
1007
|
+
*
|
|
1008
|
+
* @return float|bool Returns a float if a version number is detected,
|
|
1009
|
+
* otherwise true/false.
|
|
1010
|
+
*/
|
|
1011
|
+
osx: function() {
|
|
1012
|
+
return _populate() || _osx;
|
|
1013
|
+
},
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* Check if the user is running Linux.
|
|
1017
|
+
*
|
|
1018
|
+
* @return bool `true' if the user's OS is some flavor of Linux.
|
|
1019
|
+
*/
|
|
1020
|
+
linux: function() {
|
|
1021
|
+
return _populate() || _linux;
|
|
1022
|
+
},
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Check if the user is running on an iPhone or iPod platform.
|
|
1026
|
+
*
|
|
1027
|
+
* @return bool `true' if the user is running some flavor of the
|
|
1028
|
+
* iPhone OS.
|
|
1029
|
+
*/
|
|
1030
|
+
iphone: function() {
|
|
1031
|
+
return _populate() || _iphone;
|
|
1032
|
+
},
|
|
1033
|
+
|
|
1034
|
+
mobile: function() {
|
|
1035
|
+
return _populate() || (_iphone || _ipad || _android || _mobile);
|
|
1036
|
+
},
|
|
1037
|
+
|
|
1038
|
+
nativeApp: function() {
|
|
1039
|
+
// webviews inside of the native apps
|
|
1040
|
+
return _populate() || _native;
|
|
1041
|
+
},
|
|
1042
|
+
|
|
1043
|
+
android: function() {
|
|
1044
|
+
return _populate() || _android;
|
|
1045
|
+
},
|
|
1046
|
+
|
|
1047
|
+
ipad: function() {
|
|
1048
|
+
return _populate() || _ipad;
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
var UserAgent_DEPRECATED_1 = UserAgent_DEPRECATED$1;
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* Copyright (c) 2015, Facebook, Inc.
|
|
1056
|
+
* All rights reserved.
|
|
1057
|
+
*
|
|
1058
|
+
* This source code is licensed under the BSD-style license found in the
|
|
1059
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
1060
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
1061
|
+
*
|
|
1062
|
+
* @providesModule ExecutionEnvironment
|
|
1063
|
+
*/
|
|
1064
|
+
|
|
1065
|
+
var canUseDOM = !!(
|
|
1066
|
+
typeof window !== 'undefined' &&
|
|
1067
|
+
window.document &&
|
|
1068
|
+
window.document.createElement
|
|
1069
|
+
);
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* Simple, lightweight module assisting with the detection and context of
|
|
1073
|
+
* Worker. Helps avoid circular dependencies and allows code to reason about
|
|
1074
|
+
* whether or not they are in a Worker, even if they never include the main
|
|
1075
|
+
* `ReactWorker` dependency.
|
|
1076
|
+
*/
|
|
1077
|
+
var ExecutionEnvironment$1 = {
|
|
1078
|
+
|
|
1079
|
+
canUseDOM: canUseDOM};
|
|
1080
|
+
|
|
1081
|
+
var ExecutionEnvironment_1 = ExecutionEnvironment$1;
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Copyright 2013-2015, Facebook, Inc.
|
|
1085
|
+
* All rights reserved.
|
|
1086
|
+
*
|
|
1087
|
+
* This source code is licensed under the BSD-style license found in the
|
|
1088
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
1089
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
1090
|
+
*
|
|
1091
|
+
* @providesModule isEventSupported
|
|
1092
|
+
*/
|
|
1093
|
+
|
|
1094
|
+
var ExecutionEnvironment = ExecutionEnvironment_1;
|
|
1095
|
+
|
|
1096
|
+
var useHasFeature;
|
|
1097
|
+
if (ExecutionEnvironment.canUseDOM) {
|
|
1098
|
+
useHasFeature =
|
|
1099
|
+
document.implementation &&
|
|
1100
|
+
document.implementation.hasFeature &&
|
|
1101
|
+
// always returns true in newer browsers as per the standard.
|
|
1102
|
+
// @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
|
|
1103
|
+
document.implementation.hasFeature('', '') !== true;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* Checks if an event is supported in the current execution environment.
|
|
1108
|
+
*
|
|
1109
|
+
* NOTE: This will not work correctly for non-generic events such as `change`,
|
|
1110
|
+
* `reset`, `load`, `error`, and `select`.
|
|
1111
|
+
*
|
|
1112
|
+
* Borrows from Modernizr.
|
|
1113
|
+
*
|
|
1114
|
+
* @param {string} eventNameSuffix Event name, e.g. "click".
|
|
1115
|
+
* @param {?boolean} capture Check if the capture phase is supported.
|
|
1116
|
+
* @return {boolean} True if the event is supported.
|
|
1117
|
+
* @internal
|
|
1118
|
+
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
1119
|
+
*/
|
|
1120
|
+
function isEventSupported$1(eventNameSuffix, capture) {
|
|
1121
|
+
if (!ExecutionEnvironment.canUseDOM ||
|
|
1122
|
+
capture && !('addEventListener' in document)) {
|
|
1123
|
+
return false;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
var eventName = 'on' + eventNameSuffix;
|
|
1127
|
+
var isSupported = eventName in document;
|
|
1128
|
+
|
|
1129
|
+
if (!isSupported) {
|
|
1130
|
+
var element = document.createElement('div');
|
|
1131
|
+
element.setAttribute(eventName, 'return;');
|
|
1132
|
+
isSupported = typeof element[eventName] === 'function';
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') {
|
|
1136
|
+
// This is the only way to test support for the `wheel` event in IE9+.
|
|
1137
|
+
isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
return isSupported;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
var isEventSupported_1 = isEventSupported$1;
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* Copyright (c) 2015, Facebook, Inc.
|
|
1147
|
+
* All rights reserved.
|
|
1148
|
+
*
|
|
1149
|
+
* This source code is licensed under the BSD-style license found in the
|
|
1150
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
1151
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
1152
|
+
*
|
|
1153
|
+
* @providesModule normalizeWheel
|
|
1154
|
+
* @typechecks
|
|
1155
|
+
*/
|
|
1156
|
+
|
|
1157
|
+
var UserAgent_DEPRECATED = UserAgent_DEPRECATED_1;
|
|
1158
|
+
|
|
1159
|
+
var isEventSupported = isEventSupported_1;
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
// Reasonable defaults
|
|
1163
|
+
var PIXEL_STEP = 10;
|
|
1164
|
+
var LINE_HEIGHT = 40;
|
|
1165
|
+
var PAGE_HEIGHT = 800;
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* Mouse wheel (and 2-finger trackpad) support on the web sucks. It is
|
|
1169
|
+
* complicated, thus this doc is long and (hopefully) detailed enough to answer
|
|
1170
|
+
* your questions.
|
|
1171
|
+
*
|
|
1172
|
+
* If you need to react to the mouse wheel in a predictable way, this code is
|
|
1173
|
+
* like your bestest friend. * hugs *
|
|
1174
|
+
*
|
|
1175
|
+
* As of today, there are 4 DOM event types you can listen to:
|
|
1176
|
+
*
|
|
1177
|
+
* 'wheel' -- Chrome(31+), FF(17+), IE(9+)
|
|
1178
|
+
* 'mousewheel' -- Chrome, IE(6+), Opera, Safari
|
|
1179
|
+
* 'MozMousePixelScroll' -- FF(3.5 only!) (2010-2013) -- don't bother!
|
|
1180
|
+
* 'DOMMouseScroll' -- FF(0.9.7+) since 2003
|
|
1181
|
+
*
|
|
1182
|
+
* So what to do? The is the best:
|
|
1183
|
+
*
|
|
1184
|
+
* normalizeWheel.getEventType();
|
|
1185
|
+
*
|
|
1186
|
+
* In your event callback, use this code to get sane interpretation of the
|
|
1187
|
+
* deltas. This code will return an object with properties:
|
|
1188
|
+
*
|
|
1189
|
+
* spinX -- normalized spin speed (use for zoom) - x plane
|
|
1190
|
+
* spinY -- " - y plane
|
|
1191
|
+
* pixelX -- normalized distance (to pixels) - x plane
|
|
1192
|
+
* pixelY -- " - y plane
|
|
1193
|
+
*
|
|
1194
|
+
* Wheel values are provided by the browser assuming you are using the wheel to
|
|
1195
|
+
* scroll a web page by a number of lines or pixels (or pages). Values can vary
|
|
1196
|
+
* significantly on different platforms and browsers, forgetting that you can
|
|
1197
|
+
* scroll at different speeds. Some devices (like trackpads) emit more events
|
|
1198
|
+
* at smaller increments with fine granularity, and some emit massive jumps with
|
|
1199
|
+
* linear speed or acceleration.
|
|
1200
|
+
*
|
|
1201
|
+
* This code does its best to normalize the deltas for you:
|
|
1202
|
+
*
|
|
1203
|
+
* - spin is trying to normalize how far the wheel was spun (or trackpad
|
|
1204
|
+
* dragged). This is super useful for zoom support where you want to
|
|
1205
|
+
* throw away the chunky scroll steps on the PC and make those equal to
|
|
1206
|
+
* the slow and smooth tiny steps on the Mac. Key data: This code tries to
|
|
1207
|
+
* resolve a single slow step on a wheel to 1.
|
|
1208
|
+
*
|
|
1209
|
+
* - pixel is normalizing the desired scroll delta in pixel units. You'll
|
|
1210
|
+
* get the crazy differences between browsers, but at least it'll be in
|
|
1211
|
+
* pixels!
|
|
1212
|
+
*
|
|
1213
|
+
* - positive value indicates scrolling DOWN/RIGHT, negative UP/LEFT. This
|
|
1214
|
+
* should translate to positive value zooming IN, negative zooming OUT.
|
|
1215
|
+
* This matches the newer 'wheel' event.
|
|
1216
|
+
*
|
|
1217
|
+
* Why are there spinX, spinY (or pixels)?
|
|
1218
|
+
*
|
|
1219
|
+
* - spinX is a 2-finger side drag on the trackpad, and a shift + wheel turn
|
|
1220
|
+
* with a mouse. It results in side-scrolling in the browser by default.
|
|
1221
|
+
*
|
|
1222
|
+
* - spinY is what you expect -- it's the classic axis of a mouse wheel.
|
|
1223
|
+
*
|
|
1224
|
+
* - I dropped spinZ/pixelZ. It is supported by the DOM 3 'wheel' event and
|
|
1225
|
+
* probably is by browsers in conjunction with fancy 3D controllers .. but
|
|
1226
|
+
* you know.
|
|
1227
|
+
*
|
|
1228
|
+
* Implementation info:
|
|
1229
|
+
*
|
|
1230
|
+
* Examples of 'wheel' event if you scroll slowly (down) by one step with an
|
|
1231
|
+
* average mouse:
|
|
1232
|
+
*
|
|
1233
|
+
* OS X + Chrome (mouse) - 4 pixel delta (wheelDelta -120)
|
|
1234
|
+
* OS X + Safari (mouse) - N/A pixel delta (wheelDelta -12)
|
|
1235
|
+
* OS X + Firefox (mouse) - 0.1 line delta (wheelDelta N/A)
|
|
1236
|
+
* Win8 + Chrome (mouse) - 100 pixel delta (wheelDelta -120)
|
|
1237
|
+
* Win8 + Firefox (mouse) - 3 line delta (wheelDelta -120)
|
|
1238
|
+
*
|
|
1239
|
+
* On the trackpad:
|
|
1240
|
+
*
|
|
1241
|
+
* OS X + Chrome (trackpad) - 2 pixel delta (wheelDelta -6)
|
|
1242
|
+
* OS X + Firefox (trackpad) - 1 pixel delta (wheelDelta N/A)
|
|
1243
|
+
*
|
|
1244
|
+
* On other/older browsers.. it's more complicated as there can be multiple and
|
|
1245
|
+
* also missing delta values.
|
|
1246
|
+
*
|
|
1247
|
+
* The 'wheel' event is more standard:
|
|
1248
|
+
*
|
|
1249
|
+
* http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents
|
|
1250
|
+
*
|
|
1251
|
+
* The basics is that it includes a unit, deltaMode (pixels, lines, pages), and
|
|
1252
|
+
* deltaX, deltaY and deltaZ. Some browsers provide other values to maintain
|
|
1253
|
+
* backward compatibility with older events. Those other values help us
|
|
1254
|
+
* better normalize spin speed. Example of what the browsers provide:
|
|
1255
|
+
*
|
|
1256
|
+
* | event.wheelDelta | event.detail
|
|
1257
|
+
* ------------------+------------------+--------------
|
|
1258
|
+
* Safari v5/OS X | -120 | 0
|
|
1259
|
+
* Safari v5/Win7 | -120 | 0
|
|
1260
|
+
* Chrome v17/OS X | -120 | 0
|
|
1261
|
+
* Chrome v17/Win7 | -120 | 0
|
|
1262
|
+
* IE9/Win7 | -120 | undefined
|
|
1263
|
+
* Firefox v4/OS X | undefined | 1
|
|
1264
|
+
* Firefox v4/Win7 | undefined | 3
|
|
1265
|
+
*
|
|
1266
|
+
*/
|
|
1267
|
+
function normalizeWheel$2(/*object*/ event) /*object*/ {
|
|
1268
|
+
var sX = 0, sY = 0, // spinX, spinY
|
|
1269
|
+
pX = 0, pY = 0; // pixelX, pixelY
|
|
1270
|
+
|
|
1271
|
+
// Legacy
|
|
1272
|
+
if ('detail' in event) { sY = event.detail; }
|
|
1273
|
+
if ('wheelDelta' in event) { sY = -event.wheelDelta / 120; }
|
|
1274
|
+
if ('wheelDeltaY' in event) { sY = -event.wheelDeltaY / 120; }
|
|
1275
|
+
if ('wheelDeltaX' in event) { sX = -event.wheelDeltaX / 120; }
|
|
1276
|
+
|
|
1277
|
+
// side scrolling on FF with DOMMouseScroll
|
|
1278
|
+
if ( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {
|
|
1279
|
+
sX = sY;
|
|
1280
|
+
sY = 0;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
pX = sX * PIXEL_STEP;
|
|
1284
|
+
pY = sY * PIXEL_STEP;
|
|
1285
|
+
|
|
1286
|
+
if ('deltaY' in event) { pY = event.deltaY; }
|
|
1287
|
+
if ('deltaX' in event) { pX = event.deltaX; }
|
|
1288
|
+
|
|
1289
|
+
if ((pX || pY) && event.deltaMode) {
|
|
1290
|
+
if (event.deltaMode == 1) { // delta in LINE units
|
|
1291
|
+
pX *= LINE_HEIGHT;
|
|
1292
|
+
pY *= LINE_HEIGHT;
|
|
1293
|
+
} else { // delta in PAGE units
|
|
1294
|
+
pX *= PAGE_HEIGHT;
|
|
1295
|
+
pY *= PAGE_HEIGHT;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
// Fall-back if spin cannot be determined
|
|
1300
|
+
if (pX && !sX) { sX = (pX < 1) ? -1 : 1; }
|
|
1301
|
+
if (pY && !sY) { sY = (pY < 1) ? -1 : 1; }
|
|
1302
|
+
|
|
1303
|
+
return { spinX : sX,
|
|
1304
|
+
spinY : sY,
|
|
1305
|
+
pixelX : pX,
|
|
1306
|
+
pixelY : pY };
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
/**
|
|
1311
|
+
* The best combination if you prefer spinX + spinY normalization. It favors
|
|
1312
|
+
* the older DOMMouseScroll for Firefox, as FF does not include wheelDelta with
|
|
1313
|
+
* 'wheel' event, making spin speed determination impossible.
|
|
1314
|
+
*/
|
|
1315
|
+
normalizeWheel$2.getEventType = function() /*string*/ {
|
|
1316
|
+
return (UserAgent_DEPRECATED.firefox())
|
|
1317
|
+
? 'DOMMouseScroll'
|
|
1318
|
+
: (isEventSupported('wheel'))
|
|
1319
|
+
? 'wheel'
|
|
1320
|
+
: 'mousewheel';
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
var normalizeWheel_1 = normalizeWheel$2;
|
|
1324
|
+
|
|
1325
|
+
var normalizeWheel = normalizeWheel_1;
|
|
1326
|
+
|
|
1327
|
+
var normalizeWheel$1 = /*@__PURE__*/getDefaultExportFromCjs(normalizeWheel);
|
|
1328
|
+
|
|
1329
|
+
/**
|
|
1330
|
+
* Compute the dimension of the crop area based on media size,
|
|
1331
|
+
* aspect ratio and optionally rotation
|
|
1332
|
+
*/
|
|
1333
|
+
function getCropSize(mediaWidth, mediaHeight, containerWidth, containerHeight, aspect, rotation) {
|
|
1334
|
+
if (rotation === void 0) {
|
|
1335
|
+
rotation = 0;
|
|
1336
|
+
}
|
|
1337
|
+
var _a = rotateSize(mediaWidth, mediaHeight, rotation),
|
|
1338
|
+
width = _a.width,
|
|
1339
|
+
height = _a.height;
|
|
1340
|
+
var fittingWidth = Math.min(width, containerWidth);
|
|
1341
|
+
var fittingHeight = Math.min(height, containerHeight);
|
|
1342
|
+
if (fittingWidth > fittingHeight * aspect) {
|
|
1343
|
+
return {
|
|
1344
|
+
width: fittingHeight * aspect,
|
|
1345
|
+
height: fittingHeight
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
return {
|
|
1349
|
+
width: fittingWidth,
|
|
1350
|
+
height: fittingWidth / aspect
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Compute media zoom.
|
|
1355
|
+
* We fit the media into the container with "max-width: 100%; max-height: 100%;"
|
|
1356
|
+
*/
|
|
1357
|
+
function getMediaZoom(mediaSize) {
|
|
1358
|
+
// Take the axis with more pixels to improve accuracy
|
|
1359
|
+
return mediaSize.width > mediaSize.height ? mediaSize.width / mediaSize.naturalWidth : mediaSize.height / mediaSize.naturalHeight;
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Ensure a new media position stays in the crop area.
|
|
1363
|
+
*/
|
|
1364
|
+
function restrictPosition(position, mediaSize, cropSize, zoom, rotation) {
|
|
1365
|
+
if (rotation === void 0) {
|
|
1366
|
+
rotation = 0;
|
|
1367
|
+
}
|
|
1368
|
+
var _a = rotateSize(mediaSize.width, mediaSize.height, rotation),
|
|
1369
|
+
width = _a.width,
|
|
1370
|
+
height = _a.height;
|
|
1371
|
+
return {
|
|
1372
|
+
x: restrictPositionCoord(position.x, width, cropSize.width, zoom),
|
|
1373
|
+
y: restrictPositionCoord(position.y, height, cropSize.height, zoom)
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
function restrictPositionCoord(position, mediaSize, cropSize, zoom) {
|
|
1377
|
+
var maxPosition = Math.abs(mediaSize * zoom / 2 - cropSize / 2);
|
|
1378
|
+
return clamp(position, -maxPosition, maxPosition);
|
|
1379
|
+
}
|
|
1380
|
+
function getDistanceBetweenPoints(pointA, pointB) {
|
|
1381
|
+
return Math.sqrt(Math.pow(pointA.y - pointB.y, 2) + Math.pow(pointA.x - pointB.x, 2));
|
|
1382
|
+
}
|
|
1383
|
+
function getRotationBetweenPoints(pointA, pointB) {
|
|
1384
|
+
return Math.atan2(pointB.y - pointA.y, pointB.x - pointA.x) * 180 / Math.PI;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Compute the output cropped area of the media in percentages and pixels.
|
|
1388
|
+
* x/y are the top-left coordinates on the src media
|
|
1389
|
+
*/
|
|
1390
|
+
function computeCroppedArea(crop, mediaSize, cropSize, aspect, zoom, rotation, restrictPosition) {
|
|
1391
|
+
if (rotation === void 0) {
|
|
1392
|
+
rotation = 0;
|
|
1393
|
+
}
|
|
1394
|
+
if (restrictPosition === void 0) {
|
|
1395
|
+
restrictPosition = true;
|
|
1396
|
+
}
|
|
1397
|
+
// if the media is rotated by the user, we cannot limit the position anymore
|
|
1398
|
+
// as it might need to be negative.
|
|
1399
|
+
var limitAreaFn = restrictPosition ? limitArea : noOp;
|
|
1400
|
+
var mediaBBoxSize = rotateSize(mediaSize.width, mediaSize.height, rotation);
|
|
1401
|
+
var mediaNaturalBBoxSize = rotateSize(mediaSize.naturalWidth, mediaSize.naturalHeight, rotation);
|
|
1402
|
+
// calculate the crop area in percentages
|
|
1403
|
+
// in the rotated space
|
|
1404
|
+
var croppedAreaPercentages = {
|
|
1405
|
+
x: limitAreaFn(100, ((mediaBBoxSize.width - cropSize.width / zoom) / 2 - crop.x / zoom) / mediaBBoxSize.width * 100),
|
|
1406
|
+
y: limitAreaFn(100, ((mediaBBoxSize.height - cropSize.height / zoom) / 2 - crop.y / zoom) / mediaBBoxSize.height * 100),
|
|
1407
|
+
width: limitAreaFn(100, cropSize.width / mediaBBoxSize.width * 100 / zoom),
|
|
1408
|
+
height: limitAreaFn(100, cropSize.height / mediaBBoxSize.height * 100 / zoom)
|
|
1409
|
+
};
|
|
1410
|
+
// we compute the pixels size naively
|
|
1411
|
+
var widthInPixels = Math.round(limitAreaFn(mediaNaturalBBoxSize.width, croppedAreaPercentages.width * mediaNaturalBBoxSize.width / 100));
|
|
1412
|
+
var heightInPixels = Math.round(limitAreaFn(mediaNaturalBBoxSize.height, croppedAreaPercentages.height * mediaNaturalBBoxSize.height / 100));
|
|
1413
|
+
var isImgWiderThanHigh = mediaNaturalBBoxSize.width >= mediaNaturalBBoxSize.height * aspect;
|
|
1414
|
+
// then we ensure the width and height exactly match the aspect (to avoid rounding approximations)
|
|
1415
|
+
// if the media is wider than high, when zoom is 0, the crop height will be equals to image height
|
|
1416
|
+
// thus we want to compute the width from the height and aspect for accuracy.
|
|
1417
|
+
// Otherwise, we compute the height from width and aspect.
|
|
1418
|
+
var sizePixels = isImgWiderThanHigh ? {
|
|
1419
|
+
width: Math.round(heightInPixels * aspect),
|
|
1420
|
+
height: heightInPixels
|
|
1421
|
+
} : {
|
|
1422
|
+
width: widthInPixels,
|
|
1423
|
+
height: Math.round(widthInPixels / aspect)
|
|
1424
|
+
};
|
|
1425
|
+
var croppedAreaPixels = __assign(__assign({}, sizePixels), {
|
|
1426
|
+
x: Math.round(limitAreaFn(mediaNaturalBBoxSize.width - sizePixels.width, croppedAreaPercentages.x * mediaNaturalBBoxSize.width / 100)),
|
|
1427
|
+
y: Math.round(limitAreaFn(mediaNaturalBBoxSize.height - sizePixels.height, croppedAreaPercentages.y * mediaNaturalBBoxSize.height / 100))
|
|
1428
|
+
});
|
|
1429
|
+
return {
|
|
1430
|
+
croppedAreaPercentages: croppedAreaPercentages,
|
|
1431
|
+
croppedAreaPixels: croppedAreaPixels
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Ensure the returned value is between 0 and max
|
|
1436
|
+
*/
|
|
1437
|
+
function limitArea(max, value) {
|
|
1438
|
+
return Math.min(max, Math.max(0, value));
|
|
1439
|
+
}
|
|
1440
|
+
function noOp(_max, value) {
|
|
1441
|
+
return value;
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Compute crop and zoom from the croppedAreaPercentages.
|
|
1445
|
+
*/
|
|
1446
|
+
function getInitialCropFromCroppedAreaPercentages(croppedAreaPercentages, mediaSize, rotation, cropSize, minZoom, maxZoom) {
|
|
1447
|
+
var mediaBBoxSize = rotateSize(mediaSize.width, mediaSize.height, rotation);
|
|
1448
|
+
// This is the inverse process of computeCroppedArea
|
|
1449
|
+
var zoom = clamp(cropSize.width / mediaBBoxSize.width * (100 / croppedAreaPercentages.width), minZoom, maxZoom);
|
|
1450
|
+
var crop = {
|
|
1451
|
+
x: zoom * mediaBBoxSize.width / 2 - cropSize.width / 2 - mediaBBoxSize.width * zoom * (croppedAreaPercentages.x / 100),
|
|
1452
|
+
y: zoom * mediaBBoxSize.height / 2 - cropSize.height / 2 - mediaBBoxSize.height * zoom * (croppedAreaPercentages.y / 100)
|
|
1453
|
+
};
|
|
1454
|
+
return {
|
|
1455
|
+
crop: crop,
|
|
1456
|
+
zoom: zoom
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Compute zoom from the croppedAreaPixels
|
|
1461
|
+
*/
|
|
1462
|
+
function getZoomFromCroppedAreaPixels(croppedAreaPixels, mediaSize, cropSize) {
|
|
1463
|
+
var mediaZoom = getMediaZoom(mediaSize);
|
|
1464
|
+
return cropSize.height > cropSize.width ? cropSize.height / (croppedAreaPixels.height * mediaZoom) : cropSize.width / (croppedAreaPixels.width * mediaZoom);
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Compute crop and zoom from the croppedAreaPixels
|
|
1468
|
+
*/
|
|
1469
|
+
function getInitialCropFromCroppedAreaPixels(croppedAreaPixels, mediaSize, rotation, cropSize, minZoom, maxZoom) {
|
|
1470
|
+
if (rotation === void 0) {
|
|
1471
|
+
rotation = 0;
|
|
1472
|
+
}
|
|
1473
|
+
var mediaNaturalBBoxSize = rotateSize(mediaSize.naturalWidth, mediaSize.naturalHeight, rotation);
|
|
1474
|
+
var zoom = clamp(getZoomFromCroppedAreaPixels(croppedAreaPixels, mediaSize, cropSize), minZoom, maxZoom);
|
|
1475
|
+
var cropZoom = cropSize.height > cropSize.width ? cropSize.height / croppedAreaPixels.height : cropSize.width / croppedAreaPixels.width;
|
|
1476
|
+
var crop = {
|
|
1477
|
+
x: ((mediaNaturalBBoxSize.width - croppedAreaPixels.width) / 2 - croppedAreaPixels.x) * cropZoom,
|
|
1478
|
+
y: ((mediaNaturalBBoxSize.height - croppedAreaPixels.height) / 2 - croppedAreaPixels.y) * cropZoom
|
|
1479
|
+
};
|
|
1480
|
+
return {
|
|
1481
|
+
crop: crop,
|
|
1482
|
+
zoom: zoom
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Return the point that is the center of point a and b
|
|
1487
|
+
*/
|
|
1488
|
+
function getCenter(a, b) {
|
|
1489
|
+
return {
|
|
1490
|
+
x: (b.x + a.x) / 2,
|
|
1491
|
+
y: (b.y + a.y) / 2
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
function getRadianAngle(degreeValue) {
|
|
1495
|
+
return degreeValue * Math.PI / 180;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Returns the new bounding area of a rotated rectangle.
|
|
1499
|
+
*/
|
|
1500
|
+
function rotateSize(width, height, rotation) {
|
|
1501
|
+
var rotRad = getRadianAngle(rotation);
|
|
1502
|
+
return {
|
|
1503
|
+
width: Math.abs(Math.cos(rotRad) * width) + Math.abs(Math.sin(rotRad) * height),
|
|
1504
|
+
height: Math.abs(Math.sin(rotRad) * width) + Math.abs(Math.cos(rotRad) * height)
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Clamp value between min and max
|
|
1509
|
+
*/
|
|
1510
|
+
function clamp(value, min, max) {
|
|
1511
|
+
return Math.min(Math.max(value, min), max);
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Combine multiple class names into a single string.
|
|
1515
|
+
*/
|
|
1516
|
+
function classNames() {
|
|
1517
|
+
var args = [];
|
|
1518
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1519
|
+
args[_i] = arguments[_i];
|
|
1520
|
+
}
|
|
1521
|
+
return args.filter(function (value) {
|
|
1522
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
1523
|
+
return true;
|
|
1524
|
+
}
|
|
1525
|
+
return false;
|
|
1526
|
+
}).join(' ').trim();
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
var css_248z = ".reactEasyCrop_Container {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n overflow: hidden;\n user-select: none;\n touch-action: none;\n cursor: move;\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.reactEasyCrop_Image,\n.reactEasyCrop_Video {\n will-change: transform; /* this improves performances and prevent painting issues on iOS Chrome */\n}\n\n.reactEasyCrop_Contain {\n max-width: 100%;\n max-height: 100%;\n margin: auto;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n}\n.reactEasyCrop_Cover_Horizontal {\n width: 100%;\n height: auto;\n}\n.reactEasyCrop_Cover_Vertical {\n width: auto;\n height: 100%;\n}\n\n.reactEasyCrop_CropArea {\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n border: 1px solid rgba(255, 255, 255, 0.5);\n box-sizing: border-box;\n box-shadow: 0 0 0 9999em;\n color: rgba(0, 0, 0, 0.5);\n overflow: hidden;\n}\n\n.reactEasyCrop_CropAreaRound {\n border-radius: 50%;\n}\n\n.reactEasyCrop_CropAreaGrid::before {\n content: ' ';\n box-sizing: border-box;\n position: absolute;\n border: 1px solid rgba(255, 255, 255, 0.5);\n top: 0;\n bottom: 0;\n left: 33.33%;\n right: 33.33%;\n border-top: 0;\n border-bottom: 0;\n}\n\n.reactEasyCrop_CropAreaGrid::after {\n content: ' ';\n box-sizing: border-box;\n position: absolute;\n border: 1px solid rgba(255, 255, 255, 0.5);\n top: 33.33%;\n bottom: 33.33%;\n left: 0;\n right: 0;\n border-left: 0;\n border-right: 0;\n}\n";
|
|
1530
|
+
|
|
1531
|
+
var MIN_ZOOM = 1;
|
|
1532
|
+
var MAX_ZOOM = 3;
|
|
1533
|
+
var KEYBOARD_STEP = 1;
|
|
1534
|
+
var Cropper = /** @class */function (_super) {
|
|
1535
|
+
__extends(Cropper, _super);
|
|
1536
|
+
function Cropper() {
|
|
1537
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1538
|
+
_this.cropperRef = React__namespace.createRef();
|
|
1539
|
+
_this.imageRef = React__namespace.createRef();
|
|
1540
|
+
_this.videoRef = React__namespace.createRef();
|
|
1541
|
+
_this.containerPosition = {
|
|
1542
|
+
x: 0,
|
|
1543
|
+
y: 0
|
|
1544
|
+
};
|
|
1545
|
+
_this.containerRef = null;
|
|
1546
|
+
_this.styleRef = null;
|
|
1547
|
+
_this.containerRect = null;
|
|
1548
|
+
_this.mediaSize = {
|
|
1549
|
+
width: 0,
|
|
1550
|
+
height: 0,
|
|
1551
|
+
naturalWidth: 0,
|
|
1552
|
+
naturalHeight: 0
|
|
1553
|
+
};
|
|
1554
|
+
_this.dragStartPosition = {
|
|
1555
|
+
x: 0,
|
|
1556
|
+
y: 0
|
|
1557
|
+
};
|
|
1558
|
+
_this.dragStartCrop = {
|
|
1559
|
+
x: 0,
|
|
1560
|
+
y: 0
|
|
1561
|
+
};
|
|
1562
|
+
_this.gestureZoomStart = 0;
|
|
1563
|
+
_this.gestureRotationStart = 0;
|
|
1564
|
+
_this.isTouching = false;
|
|
1565
|
+
_this.lastPinchDistance = 0;
|
|
1566
|
+
_this.lastPinchRotation = 0;
|
|
1567
|
+
_this.rafDragTimeout = null;
|
|
1568
|
+
_this.rafPinchTimeout = null;
|
|
1569
|
+
_this.wheelTimer = null;
|
|
1570
|
+
_this.currentDoc = typeof document !== 'undefined' ? document : null;
|
|
1571
|
+
_this.currentWindow = typeof window !== 'undefined' ? window : null;
|
|
1572
|
+
_this.resizeObserver = null;
|
|
1573
|
+
_this.previousCropSize = null;
|
|
1574
|
+
_this.isInitialized = false;
|
|
1575
|
+
_this.state = {
|
|
1576
|
+
cropSize: null,
|
|
1577
|
+
hasWheelJustStarted: false,
|
|
1578
|
+
mediaObjectFit: undefined
|
|
1579
|
+
};
|
|
1580
|
+
_this.initResizeObserver = function () {
|
|
1581
|
+
if (typeof window.ResizeObserver === 'undefined' || !_this.containerRef) {
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
var isFirstResize = true;
|
|
1585
|
+
_this.resizeObserver = new window.ResizeObserver(function (entries) {
|
|
1586
|
+
if (isFirstResize) {
|
|
1587
|
+
isFirstResize = false; // observe() is called on mount, we don't want to trigger a recompute on mount
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
_this.computeSizes();
|
|
1591
|
+
});
|
|
1592
|
+
_this.resizeObserver.observe(_this.containerRef);
|
|
1593
|
+
};
|
|
1594
|
+
// this is to prevent Safari on iOS >= 10 to zoom the page
|
|
1595
|
+
_this.preventZoomSafari = function (e) {
|
|
1596
|
+
return e.preventDefault();
|
|
1597
|
+
};
|
|
1598
|
+
_this.cleanEvents = function () {
|
|
1599
|
+
if (!_this.currentDoc) return;
|
|
1600
|
+
_this.currentDoc.removeEventListener('mousemove', _this.onMouseMove);
|
|
1601
|
+
_this.currentDoc.removeEventListener('mouseup', _this.onDragStopped);
|
|
1602
|
+
_this.currentDoc.removeEventListener('touchmove', _this.onTouchMove);
|
|
1603
|
+
_this.currentDoc.removeEventListener('touchend', _this.onDragStopped);
|
|
1604
|
+
_this.currentDoc.removeEventListener('gesturechange', _this.onGestureChange);
|
|
1605
|
+
_this.currentDoc.removeEventListener('gestureend', _this.onGestureEnd);
|
|
1606
|
+
_this.currentDoc.removeEventListener('scroll', _this.onScroll);
|
|
1607
|
+
};
|
|
1608
|
+
_this.clearScrollEvent = function () {
|
|
1609
|
+
if (_this.containerRef) _this.containerRef.removeEventListener('wheel', _this.onWheel);
|
|
1610
|
+
if (_this.wheelTimer) {
|
|
1611
|
+
clearTimeout(_this.wheelTimer);
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
_this.onMediaLoad = function () {
|
|
1615
|
+
var cropSize = _this.computeSizes();
|
|
1616
|
+
if (cropSize) {
|
|
1617
|
+
_this.previousCropSize = cropSize;
|
|
1618
|
+
_this.emitCropData();
|
|
1619
|
+
_this.setInitialCrop(cropSize);
|
|
1620
|
+
_this.isInitialized = true;
|
|
1621
|
+
}
|
|
1622
|
+
if (_this.props.onMediaLoaded) {
|
|
1623
|
+
_this.props.onMediaLoaded(_this.mediaSize);
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
_this.setInitialCrop = function (cropSize) {
|
|
1627
|
+
if (_this.props.initialCroppedAreaPercentages) {
|
|
1628
|
+
var _a = getInitialCropFromCroppedAreaPercentages(_this.props.initialCroppedAreaPercentages, _this.mediaSize, _this.props.rotation, cropSize, _this.props.minZoom, _this.props.maxZoom),
|
|
1629
|
+
crop = _a.crop,
|
|
1630
|
+
zoom = _a.zoom;
|
|
1631
|
+
_this.props.onCropChange(crop);
|
|
1632
|
+
_this.props.onZoomChange && _this.props.onZoomChange(zoom);
|
|
1633
|
+
} else if (_this.props.initialCroppedAreaPixels) {
|
|
1634
|
+
var _b = getInitialCropFromCroppedAreaPixels(_this.props.initialCroppedAreaPixels, _this.mediaSize, _this.props.rotation, cropSize, _this.props.minZoom, _this.props.maxZoom),
|
|
1635
|
+
crop = _b.crop,
|
|
1636
|
+
zoom = _b.zoom;
|
|
1637
|
+
_this.props.onCropChange(crop);
|
|
1638
|
+
_this.props.onZoomChange && _this.props.onZoomChange(zoom);
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
_this.computeSizes = function () {
|
|
1642
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1643
|
+
var mediaRef = _this.imageRef.current || _this.videoRef.current;
|
|
1644
|
+
if (mediaRef && _this.containerRef) {
|
|
1645
|
+
_this.containerRect = _this.containerRef.getBoundingClientRect();
|
|
1646
|
+
_this.saveContainerPosition();
|
|
1647
|
+
var containerAspect = _this.containerRect.width / _this.containerRect.height;
|
|
1648
|
+
var naturalWidth = ((_a = _this.imageRef.current) === null || _a === void 0 ? void 0 : _a.naturalWidth) || ((_b = _this.videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth) || 0;
|
|
1649
|
+
var naturalHeight = ((_c = _this.imageRef.current) === null || _c === void 0 ? void 0 : _c.naturalHeight) || ((_d = _this.videoRef.current) === null || _d === void 0 ? void 0 : _d.videoHeight) || 0;
|
|
1650
|
+
var isMediaScaledDown = mediaRef.offsetWidth < naturalWidth || mediaRef.offsetHeight < naturalHeight;
|
|
1651
|
+
var mediaAspect = naturalWidth / naturalHeight;
|
|
1652
|
+
// We do not rely on the offsetWidth/offsetHeight if the media is scaled down
|
|
1653
|
+
// as the values they report are rounded. That will result in precision losses
|
|
1654
|
+
// when calculating zoom. We use the fact that the media is positionned relative
|
|
1655
|
+
// to the container. That allows us to use the container's dimensions
|
|
1656
|
+
// and natural aspect ratio of the media to calculate accurate media size.
|
|
1657
|
+
// However, for this to work, the container should not be rotated
|
|
1658
|
+
var renderedMediaSize = void 0;
|
|
1659
|
+
if (isMediaScaledDown) {
|
|
1660
|
+
switch (_this.state.mediaObjectFit) {
|
|
1661
|
+
default:
|
|
1662
|
+
case 'contain':
|
|
1663
|
+
renderedMediaSize = containerAspect > mediaAspect ? {
|
|
1664
|
+
width: _this.containerRect.height * mediaAspect,
|
|
1665
|
+
height: _this.containerRect.height
|
|
1666
|
+
} : {
|
|
1667
|
+
width: _this.containerRect.width,
|
|
1668
|
+
height: _this.containerRect.width / mediaAspect
|
|
1669
|
+
};
|
|
1670
|
+
break;
|
|
1671
|
+
case 'horizontal-cover':
|
|
1672
|
+
renderedMediaSize = {
|
|
1673
|
+
width: _this.containerRect.width,
|
|
1674
|
+
height: _this.containerRect.width / mediaAspect
|
|
1675
|
+
};
|
|
1676
|
+
break;
|
|
1677
|
+
case 'vertical-cover':
|
|
1678
|
+
renderedMediaSize = {
|
|
1679
|
+
width: _this.containerRect.height * mediaAspect,
|
|
1680
|
+
height: _this.containerRect.height
|
|
1681
|
+
};
|
|
1682
|
+
break;
|
|
1683
|
+
}
|
|
1684
|
+
} else {
|
|
1685
|
+
renderedMediaSize = {
|
|
1686
|
+
width: mediaRef.offsetWidth,
|
|
1687
|
+
height: mediaRef.offsetHeight
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
_this.mediaSize = __assign(__assign({}, renderedMediaSize), {
|
|
1691
|
+
naturalWidth: naturalWidth,
|
|
1692
|
+
naturalHeight: naturalHeight
|
|
1693
|
+
});
|
|
1694
|
+
// set media size in the parent
|
|
1695
|
+
if (_this.props.setMediaSize) {
|
|
1696
|
+
_this.props.setMediaSize(_this.mediaSize);
|
|
1697
|
+
}
|
|
1698
|
+
var cropSize = _this.props.cropSize ? _this.props.cropSize : getCropSize(_this.mediaSize.width, _this.mediaSize.height, _this.containerRect.width, _this.containerRect.height, _this.props.aspect, _this.props.rotation);
|
|
1699
|
+
if (((_e = _this.state.cropSize) === null || _e === void 0 ? void 0 : _e.height) !== cropSize.height || ((_f = _this.state.cropSize) === null || _f === void 0 ? void 0 : _f.width) !== cropSize.width) {
|
|
1700
|
+
_this.props.onCropSizeChange && _this.props.onCropSizeChange(cropSize);
|
|
1701
|
+
}
|
|
1702
|
+
_this.setState({
|
|
1703
|
+
cropSize: cropSize
|
|
1704
|
+
}, _this.recomputeCropPosition);
|
|
1705
|
+
// pass crop size to parent
|
|
1706
|
+
if (_this.props.setCropSize) {
|
|
1707
|
+
_this.props.setCropSize(cropSize);
|
|
1708
|
+
}
|
|
1709
|
+
return cropSize;
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
_this.saveContainerPosition = function () {
|
|
1713
|
+
if (_this.containerRef) {
|
|
1714
|
+
var bounds = _this.containerRef.getBoundingClientRect();
|
|
1715
|
+
_this.containerPosition = {
|
|
1716
|
+
x: bounds.left,
|
|
1717
|
+
y: bounds.top
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
_this.onMouseDown = function (e) {
|
|
1722
|
+
if (!_this.currentDoc) return;
|
|
1723
|
+
e.preventDefault();
|
|
1724
|
+
_this.currentDoc.addEventListener('mousemove', _this.onMouseMove);
|
|
1725
|
+
_this.currentDoc.addEventListener('mouseup', _this.onDragStopped);
|
|
1726
|
+
_this.saveContainerPosition();
|
|
1727
|
+
_this.onDragStart(Cropper.getMousePoint(e));
|
|
1728
|
+
};
|
|
1729
|
+
_this.onMouseMove = function (e) {
|
|
1730
|
+
return _this.onDrag(Cropper.getMousePoint(e));
|
|
1731
|
+
};
|
|
1732
|
+
_this.onScroll = function (e) {
|
|
1733
|
+
if (!_this.currentDoc) return;
|
|
1734
|
+
e.preventDefault();
|
|
1735
|
+
_this.saveContainerPosition();
|
|
1736
|
+
};
|
|
1737
|
+
_this.onTouchStart = function (e) {
|
|
1738
|
+
if (!_this.currentDoc) return;
|
|
1739
|
+
_this.isTouching = true;
|
|
1740
|
+
if (_this.props.onTouchRequest && !_this.props.onTouchRequest(e)) {
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
_this.currentDoc.addEventListener('touchmove', _this.onTouchMove, {
|
|
1744
|
+
passive: false
|
|
1745
|
+
}); // iOS 11 now defaults to passive: true
|
|
1746
|
+
_this.currentDoc.addEventListener('touchend', _this.onDragStopped);
|
|
1747
|
+
_this.saveContainerPosition();
|
|
1748
|
+
if (e.touches.length === 2) {
|
|
1749
|
+
_this.onPinchStart(e);
|
|
1750
|
+
} else if (e.touches.length === 1) {
|
|
1751
|
+
_this.onDragStart(Cropper.getTouchPoint(e.touches[0]));
|
|
1752
|
+
}
|
|
1753
|
+
};
|
|
1754
|
+
_this.onTouchMove = function (e) {
|
|
1755
|
+
// Prevent whole page from scrolling on iOS.
|
|
1756
|
+
e.preventDefault();
|
|
1757
|
+
if (e.touches.length === 2) {
|
|
1758
|
+
_this.onPinchMove(e);
|
|
1759
|
+
} else if (e.touches.length === 1) {
|
|
1760
|
+
_this.onDrag(Cropper.getTouchPoint(e.touches[0]));
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
_this.onGestureStart = function (e) {
|
|
1764
|
+
if (!_this.currentDoc) return;
|
|
1765
|
+
e.preventDefault();
|
|
1766
|
+
_this.currentDoc.addEventListener('gesturechange', _this.onGestureChange);
|
|
1767
|
+
_this.currentDoc.addEventListener('gestureend', _this.onGestureEnd);
|
|
1768
|
+
_this.gestureZoomStart = _this.props.zoom;
|
|
1769
|
+
_this.gestureRotationStart = _this.props.rotation;
|
|
1770
|
+
};
|
|
1771
|
+
_this.onGestureChange = function (e) {
|
|
1772
|
+
e.preventDefault();
|
|
1773
|
+
if (_this.isTouching) {
|
|
1774
|
+
// this is to avoid conflict between gesture and touch events
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
var point = Cropper.getMousePoint(e);
|
|
1778
|
+
var newZoom = _this.gestureZoomStart - 1 + e.scale;
|
|
1779
|
+
_this.setNewZoom(newZoom, point, {
|
|
1780
|
+
shouldUpdatePosition: true
|
|
1781
|
+
});
|
|
1782
|
+
if (_this.props.onRotationChange) {
|
|
1783
|
+
var newRotation = _this.gestureRotationStart + e.rotation;
|
|
1784
|
+
_this.props.onRotationChange(newRotation);
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
_this.onGestureEnd = function (e) {
|
|
1788
|
+
_this.cleanEvents();
|
|
1789
|
+
};
|
|
1790
|
+
_this.onDragStart = function (_a) {
|
|
1791
|
+
var _b, _c;
|
|
1792
|
+
var x = _a.x,
|
|
1793
|
+
y = _a.y;
|
|
1794
|
+
_this.dragStartPosition = {
|
|
1795
|
+
x: x,
|
|
1796
|
+
y: y
|
|
1797
|
+
};
|
|
1798
|
+
_this.dragStartCrop = __assign({}, _this.props.crop);
|
|
1799
|
+
(_c = (_b = _this.props).onInteractionStart) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
1800
|
+
};
|
|
1801
|
+
_this.onDrag = function (_a) {
|
|
1802
|
+
var x = _a.x,
|
|
1803
|
+
y = _a.y;
|
|
1804
|
+
if (!_this.currentWindow) return;
|
|
1805
|
+
if (_this.rafDragTimeout) _this.currentWindow.cancelAnimationFrame(_this.rafDragTimeout);
|
|
1806
|
+
_this.rafDragTimeout = _this.currentWindow.requestAnimationFrame(function () {
|
|
1807
|
+
if (!_this.state.cropSize) return;
|
|
1808
|
+
if (x === undefined || y === undefined) return;
|
|
1809
|
+
var offsetX = x - _this.dragStartPosition.x;
|
|
1810
|
+
var offsetY = y - _this.dragStartPosition.y;
|
|
1811
|
+
var requestedPosition = {
|
|
1812
|
+
x: _this.dragStartCrop.x + offsetX,
|
|
1813
|
+
y: _this.dragStartCrop.y + offsetY
|
|
1814
|
+
};
|
|
1815
|
+
var newPosition = _this.props.restrictPosition ? restrictPosition(requestedPosition, _this.mediaSize, _this.state.cropSize, _this.props.zoom, _this.props.rotation) : requestedPosition;
|
|
1816
|
+
_this.props.onCropChange(newPosition);
|
|
1817
|
+
});
|
|
1818
|
+
};
|
|
1819
|
+
_this.onDragStopped = function () {
|
|
1820
|
+
var _a, _b;
|
|
1821
|
+
_this.isTouching = false;
|
|
1822
|
+
_this.cleanEvents();
|
|
1823
|
+
_this.emitCropData();
|
|
1824
|
+
(_b = (_a = _this.props).onInteractionEnd) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1825
|
+
};
|
|
1826
|
+
_this.onWheel = function (e) {
|
|
1827
|
+
if (!_this.currentWindow) return;
|
|
1828
|
+
if (_this.props.onWheelRequest && !_this.props.onWheelRequest(e)) {
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
e.preventDefault();
|
|
1832
|
+
var point = Cropper.getMousePoint(e);
|
|
1833
|
+
var pixelY = normalizeWheel$1(e).pixelY;
|
|
1834
|
+
var newZoom = _this.props.zoom - pixelY * _this.props.zoomSpeed / 200;
|
|
1835
|
+
_this.setNewZoom(newZoom, point, {
|
|
1836
|
+
shouldUpdatePosition: true
|
|
1837
|
+
});
|
|
1838
|
+
if (!_this.state.hasWheelJustStarted) {
|
|
1839
|
+
_this.setState({
|
|
1840
|
+
hasWheelJustStarted: true
|
|
1841
|
+
}, function () {
|
|
1842
|
+
var _a, _b;
|
|
1843
|
+
return (_b = (_a = _this.props).onInteractionStart) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
if (_this.wheelTimer) {
|
|
1847
|
+
clearTimeout(_this.wheelTimer);
|
|
1848
|
+
}
|
|
1849
|
+
_this.wheelTimer = _this.currentWindow.setTimeout(function () {
|
|
1850
|
+
return _this.setState({
|
|
1851
|
+
hasWheelJustStarted: false
|
|
1852
|
+
}, function () {
|
|
1853
|
+
var _a, _b;
|
|
1854
|
+
return (_b = (_a = _this.props).onInteractionEnd) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1855
|
+
});
|
|
1856
|
+
}, 250);
|
|
1857
|
+
};
|
|
1858
|
+
_this.getPointOnContainer = function (_a, containerTopLeft) {
|
|
1859
|
+
var x = _a.x,
|
|
1860
|
+
y = _a.y;
|
|
1861
|
+
if (!_this.containerRect) {
|
|
1862
|
+
throw new Error('The Cropper is not mounted');
|
|
1863
|
+
}
|
|
1864
|
+
return {
|
|
1865
|
+
x: _this.containerRect.width / 2 - (x - containerTopLeft.x),
|
|
1866
|
+
y: _this.containerRect.height / 2 - (y - containerTopLeft.y)
|
|
1867
|
+
};
|
|
1868
|
+
};
|
|
1869
|
+
_this.getPointOnMedia = function (_a) {
|
|
1870
|
+
var x = _a.x,
|
|
1871
|
+
y = _a.y;
|
|
1872
|
+
var _b = _this.props,
|
|
1873
|
+
crop = _b.crop,
|
|
1874
|
+
zoom = _b.zoom;
|
|
1875
|
+
return {
|
|
1876
|
+
x: (x + crop.x) / zoom,
|
|
1877
|
+
y: (y + crop.y) / zoom
|
|
1878
|
+
};
|
|
1879
|
+
};
|
|
1880
|
+
_this.setNewZoom = function (zoom, point, _a) {
|
|
1881
|
+
var _b = _a === void 0 ? {} : _a,
|
|
1882
|
+
_c = _b.shouldUpdatePosition,
|
|
1883
|
+
shouldUpdatePosition = _c === void 0 ? true : _c;
|
|
1884
|
+
if (!_this.state.cropSize || !_this.props.onZoomChange) return;
|
|
1885
|
+
var newZoom = clamp(zoom, _this.props.minZoom, _this.props.maxZoom);
|
|
1886
|
+
if (shouldUpdatePosition) {
|
|
1887
|
+
var zoomPoint = _this.getPointOnContainer(point, _this.containerPosition);
|
|
1888
|
+
var zoomTarget = _this.getPointOnMedia(zoomPoint);
|
|
1889
|
+
var requestedPosition = {
|
|
1890
|
+
x: zoomTarget.x * newZoom - zoomPoint.x,
|
|
1891
|
+
y: zoomTarget.y * newZoom - zoomPoint.y
|
|
1892
|
+
};
|
|
1893
|
+
var newPosition = _this.props.restrictPosition ? restrictPosition(requestedPosition, _this.mediaSize, _this.state.cropSize, newZoom, _this.props.rotation) : requestedPosition;
|
|
1894
|
+
_this.props.onCropChange(newPosition);
|
|
1895
|
+
}
|
|
1896
|
+
_this.props.onZoomChange(newZoom);
|
|
1897
|
+
};
|
|
1898
|
+
_this.getCropData = function () {
|
|
1899
|
+
if (!_this.state.cropSize) {
|
|
1900
|
+
return null;
|
|
1901
|
+
}
|
|
1902
|
+
// this is to ensure the crop is correctly restricted after a zoom back (https://github.com/ValentinH/react-easy-crop/issues/6)
|
|
1903
|
+
var restrictedPosition = _this.props.restrictPosition ? restrictPosition(_this.props.crop, _this.mediaSize, _this.state.cropSize, _this.props.zoom, _this.props.rotation) : _this.props.crop;
|
|
1904
|
+
return computeCroppedArea(restrictedPosition, _this.mediaSize, _this.state.cropSize, _this.getAspect(), _this.props.zoom, _this.props.rotation, _this.props.restrictPosition);
|
|
1905
|
+
};
|
|
1906
|
+
_this.emitCropData = function () {
|
|
1907
|
+
var cropData = _this.getCropData();
|
|
1908
|
+
if (!cropData) return;
|
|
1909
|
+
var croppedAreaPercentages = cropData.croppedAreaPercentages,
|
|
1910
|
+
croppedAreaPixels = cropData.croppedAreaPixels;
|
|
1911
|
+
if (_this.props.onCropComplete) {
|
|
1912
|
+
_this.props.onCropComplete(croppedAreaPercentages, croppedAreaPixels);
|
|
1913
|
+
}
|
|
1914
|
+
if (_this.props.onCropAreaChange) {
|
|
1915
|
+
_this.props.onCropAreaChange(croppedAreaPercentages, croppedAreaPixels);
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
_this.emitCropAreaChange = function () {
|
|
1919
|
+
var cropData = _this.getCropData();
|
|
1920
|
+
if (!cropData) return;
|
|
1921
|
+
var croppedAreaPercentages = cropData.croppedAreaPercentages,
|
|
1922
|
+
croppedAreaPixels = cropData.croppedAreaPixels;
|
|
1923
|
+
if (_this.props.onCropAreaChange) {
|
|
1924
|
+
_this.props.onCropAreaChange(croppedAreaPercentages, croppedAreaPixels);
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
_this.recomputeCropPosition = function () {
|
|
1928
|
+
var _a, _b;
|
|
1929
|
+
if (!_this.state.cropSize) return;
|
|
1930
|
+
var adjustedCrop = _this.props.crop;
|
|
1931
|
+
// Only scale if we're initialized and this is a legitimate resize
|
|
1932
|
+
if (_this.isInitialized && ((_a = _this.previousCropSize) === null || _a === void 0 ? void 0 : _a.width) && ((_b = _this.previousCropSize) === null || _b === void 0 ? void 0 : _b.height)) {
|
|
1933
|
+
var sizeChanged = Math.abs(_this.previousCropSize.width - _this.state.cropSize.width) > 1e-6 || Math.abs(_this.previousCropSize.height - _this.state.cropSize.height) > 1e-6;
|
|
1934
|
+
if (sizeChanged) {
|
|
1935
|
+
var scaleX = _this.state.cropSize.width / _this.previousCropSize.width;
|
|
1936
|
+
var scaleY = _this.state.cropSize.height / _this.previousCropSize.height;
|
|
1937
|
+
adjustedCrop = {
|
|
1938
|
+
x: _this.props.crop.x * scaleX,
|
|
1939
|
+
y: _this.props.crop.y * scaleY
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
var newPosition = _this.props.restrictPosition ? restrictPosition(adjustedCrop, _this.mediaSize, _this.state.cropSize, _this.props.zoom, _this.props.rotation) : adjustedCrop;
|
|
1944
|
+
_this.previousCropSize = _this.state.cropSize;
|
|
1945
|
+
_this.props.onCropChange(newPosition);
|
|
1946
|
+
_this.emitCropData();
|
|
1947
|
+
};
|
|
1948
|
+
_this.onKeyDown = function (event) {
|
|
1949
|
+
var _a, _b;
|
|
1950
|
+
var _c = _this.props,
|
|
1951
|
+
crop = _c.crop,
|
|
1952
|
+
onCropChange = _c.onCropChange,
|
|
1953
|
+
keyboardStep = _c.keyboardStep,
|
|
1954
|
+
zoom = _c.zoom,
|
|
1955
|
+
rotation = _c.rotation;
|
|
1956
|
+
var step = keyboardStep;
|
|
1957
|
+
if (!_this.state.cropSize) return;
|
|
1958
|
+
// if the shift key is pressed, reduce the step to allow finer control
|
|
1959
|
+
if (event.shiftKey) {
|
|
1960
|
+
step *= 0.2;
|
|
1961
|
+
}
|
|
1962
|
+
var newCrop = __assign({}, crop);
|
|
1963
|
+
switch (event.key) {
|
|
1964
|
+
case 'ArrowUp':
|
|
1965
|
+
newCrop.y -= step;
|
|
1966
|
+
event.preventDefault();
|
|
1967
|
+
break;
|
|
1968
|
+
case 'ArrowDown':
|
|
1969
|
+
newCrop.y += step;
|
|
1970
|
+
event.preventDefault();
|
|
1971
|
+
break;
|
|
1972
|
+
case 'ArrowLeft':
|
|
1973
|
+
newCrop.x -= step;
|
|
1974
|
+
event.preventDefault();
|
|
1975
|
+
break;
|
|
1976
|
+
case 'ArrowRight':
|
|
1977
|
+
newCrop.x += step;
|
|
1978
|
+
event.preventDefault();
|
|
1979
|
+
break;
|
|
1980
|
+
default:
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
if (_this.props.restrictPosition) {
|
|
1984
|
+
newCrop = restrictPosition(newCrop, _this.mediaSize, _this.state.cropSize, zoom, rotation);
|
|
1985
|
+
}
|
|
1986
|
+
if (!event.repeat) {
|
|
1987
|
+
(_b = (_a = _this.props).onInteractionStart) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1988
|
+
}
|
|
1989
|
+
onCropChange(newCrop);
|
|
1990
|
+
};
|
|
1991
|
+
_this.onKeyUp = function (event) {
|
|
1992
|
+
var _a, _b;
|
|
1993
|
+
switch (event.key) {
|
|
1994
|
+
case 'ArrowUp':
|
|
1995
|
+
case 'ArrowDown':
|
|
1996
|
+
case 'ArrowLeft':
|
|
1997
|
+
case 'ArrowRight':
|
|
1998
|
+
event.preventDefault();
|
|
1999
|
+
break;
|
|
2000
|
+
default:
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
_this.emitCropData();
|
|
2004
|
+
(_b = (_a = _this.props).onInteractionEnd) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
2005
|
+
};
|
|
2006
|
+
return _this;
|
|
2007
|
+
}
|
|
2008
|
+
Cropper.prototype.componentDidMount = function () {
|
|
2009
|
+
if (!this.currentDoc || !this.currentWindow) return;
|
|
2010
|
+
if (this.containerRef) {
|
|
2011
|
+
if (this.containerRef.ownerDocument) {
|
|
2012
|
+
this.currentDoc = this.containerRef.ownerDocument;
|
|
2013
|
+
}
|
|
2014
|
+
if (this.currentDoc.defaultView) {
|
|
2015
|
+
this.currentWindow = this.currentDoc.defaultView;
|
|
2016
|
+
}
|
|
2017
|
+
this.initResizeObserver();
|
|
2018
|
+
// only add window resize listener if ResizeObserver is not supported. Otherwise, it would be redundant
|
|
2019
|
+
if (typeof window.ResizeObserver === 'undefined') {
|
|
2020
|
+
this.currentWindow.addEventListener('resize', this.computeSizes);
|
|
2021
|
+
}
|
|
2022
|
+
this.props.zoomWithScroll && this.containerRef.addEventListener('wheel', this.onWheel, {
|
|
2023
|
+
passive: false
|
|
2024
|
+
});
|
|
2025
|
+
this.containerRef.addEventListener('gesturestart', this.onGestureStart);
|
|
2026
|
+
}
|
|
2027
|
+
this.currentDoc.addEventListener('scroll', this.onScroll);
|
|
2028
|
+
if (!this.props.disableAutomaticStylesInjection) {
|
|
2029
|
+
this.styleRef = this.currentDoc.createElement('style');
|
|
2030
|
+
this.styleRef.setAttribute('type', 'text/css');
|
|
2031
|
+
if (this.props.nonce) {
|
|
2032
|
+
this.styleRef.setAttribute('nonce', this.props.nonce);
|
|
2033
|
+
}
|
|
2034
|
+
this.styleRef.innerHTML = css_248z;
|
|
2035
|
+
this.currentDoc.head.appendChild(this.styleRef);
|
|
2036
|
+
}
|
|
2037
|
+
// when rendered via SSR, the image can already be loaded and its onLoad callback will never be called
|
|
2038
|
+
if (this.imageRef.current && this.imageRef.current.complete) {
|
|
2039
|
+
this.onMediaLoad();
|
|
2040
|
+
}
|
|
2041
|
+
// set image and video refs in the parent if the callbacks exist
|
|
2042
|
+
if (this.props.setImageRef) {
|
|
2043
|
+
this.props.setImageRef(this.imageRef);
|
|
2044
|
+
}
|
|
2045
|
+
if (this.props.setVideoRef) {
|
|
2046
|
+
this.props.setVideoRef(this.videoRef);
|
|
2047
|
+
}
|
|
2048
|
+
if (this.props.setCropperRef) {
|
|
2049
|
+
this.props.setCropperRef(this.cropperRef);
|
|
2050
|
+
}
|
|
2051
|
+
};
|
|
2052
|
+
Cropper.prototype.componentWillUnmount = function () {
|
|
2053
|
+
var _a, _b;
|
|
2054
|
+
if (!this.currentDoc || !this.currentWindow) return;
|
|
2055
|
+
if (typeof window.ResizeObserver === 'undefined') {
|
|
2056
|
+
this.currentWindow.removeEventListener('resize', this.computeSizes);
|
|
2057
|
+
}
|
|
2058
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
2059
|
+
if (this.containerRef) {
|
|
2060
|
+
this.containerRef.removeEventListener('gesturestart', this.preventZoomSafari);
|
|
2061
|
+
}
|
|
2062
|
+
if (this.styleRef) {
|
|
2063
|
+
(_b = this.styleRef.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(this.styleRef);
|
|
2064
|
+
}
|
|
2065
|
+
this.cleanEvents();
|
|
2066
|
+
this.props.zoomWithScroll && this.clearScrollEvent();
|
|
2067
|
+
};
|
|
2068
|
+
Cropper.prototype.componentDidUpdate = function (prevProps) {
|
|
2069
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2070
|
+
if (prevProps.rotation !== this.props.rotation) {
|
|
2071
|
+
this.computeSizes();
|
|
2072
|
+
this.recomputeCropPosition();
|
|
2073
|
+
} else if (prevProps.aspect !== this.props.aspect) {
|
|
2074
|
+
this.computeSizes();
|
|
2075
|
+
} else if (prevProps.objectFit !== this.props.objectFit) {
|
|
2076
|
+
this.computeSizes();
|
|
2077
|
+
} else if (prevProps.zoom !== this.props.zoom) {
|
|
2078
|
+
this.recomputeCropPosition();
|
|
2079
|
+
} else if (((_a = prevProps.cropSize) === null || _a === void 0 ? void 0 : _a.height) !== ((_b = this.props.cropSize) === null || _b === void 0 ? void 0 : _b.height) || ((_c = prevProps.cropSize) === null || _c === void 0 ? void 0 : _c.width) !== ((_d = this.props.cropSize) === null || _d === void 0 ? void 0 : _d.width)) {
|
|
2080
|
+
this.computeSizes();
|
|
2081
|
+
} else if (((_e = prevProps.crop) === null || _e === void 0 ? void 0 : _e.x) !== ((_f = this.props.crop) === null || _f === void 0 ? void 0 : _f.x) || ((_g = prevProps.crop) === null || _g === void 0 ? void 0 : _g.y) !== ((_h = this.props.crop) === null || _h === void 0 ? void 0 : _h.y)) {
|
|
2082
|
+
this.emitCropAreaChange();
|
|
2083
|
+
}
|
|
2084
|
+
if (prevProps.zoomWithScroll !== this.props.zoomWithScroll && this.containerRef) {
|
|
2085
|
+
this.props.zoomWithScroll ? this.containerRef.addEventListener('wheel', this.onWheel, {
|
|
2086
|
+
passive: false
|
|
2087
|
+
}) : this.clearScrollEvent();
|
|
2088
|
+
}
|
|
2089
|
+
if (prevProps.video !== this.props.video) {
|
|
2090
|
+
(_j = this.videoRef.current) === null || _j === void 0 ? void 0 : _j.load();
|
|
2091
|
+
}
|
|
2092
|
+
var objectFit = this.getObjectFit();
|
|
2093
|
+
if (objectFit !== this.state.mediaObjectFit) {
|
|
2094
|
+
this.setState({
|
|
2095
|
+
mediaObjectFit: objectFit
|
|
2096
|
+
}, this.computeSizes);
|
|
2097
|
+
}
|
|
2098
|
+
};
|
|
2099
|
+
Cropper.prototype.getAspect = function () {
|
|
2100
|
+
var _a = this.props,
|
|
2101
|
+
cropSize = _a.cropSize,
|
|
2102
|
+
aspect = _a.aspect;
|
|
2103
|
+
if (cropSize) {
|
|
2104
|
+
return cropSize.width / cropSize.height;
|
|
2105
|
+
}
|
|
2106
|
+
return aspect;
|
|
2107
|
+
};
|
|
2108
|
+
Cropper.prototype.getObjectFit = function () {
|
|
2109
|
+
var _a, _b, _c, _d;
|
|
2110
|
+
if (this.props.objectFit === 'cover') {
|
|
2111
|
+
var mediaRef = this.imageRef.current || this.videoRef.current;
|
|
2112
|
+
if (mediaRef && this.containerRef) {
|
|
2113
|
+
this.containerRect = this.containerRef.getBoundingClientRect();
|
|
2114
|
+
var containerAspect = this.containerRect.width / this.containerRect.height;
|
|
2115
|
+
var naturalWidth = ((_a = this.imageRef.current) === null || _a === void 0 ? void 0 : _a.naturalWidth) || ((_b = this.videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth) || 0;
|
|
2116
|
+
var naturalHeight = ((_c = this.imageRef.current) === null || _c === void 0 ? void 0 : _c.naturalHeight) || ((_d = this.videoRef.current) === null || _d === void 0 ? void 0 : _d.videoHeight) || 0;
|
|
2117
|
+
var mediaAspect = naturalWidth / naturalHeight;
|
|
2118
|
+
return mediaAspect < containerAspect ? 'horizontal-cover' : 'vertical-cover';
|
|
2119
|
+
}
|
|
2120
|
+
return 'horizontal-cover';
|
|
2121
|
+
}
|
|
2122
|
+
return this.props.objectFit;
|
|
2123
|
+
};
|
|
2124
|
+
Cropper.prototype.onPinchStart = function (e) {
|
|
2125
|
+
var pointA = Cropper.getTouchPoint(e.touches[0]);
|
|
2126
|
+
var pointB = Cropper.getTouchPoint(e.touches[1]);
|
|
2127
|
+
this.lastPinchDistance = getDistanceBetweenPoints(pointA, pointB);
|
|
2128
|
+
this.lastPinchRotation = getRotationBetweenPoints(pointA, pointB);
|
|
2129
|
+
this.onDragStart(getCenter(pointA, pointB));
|
|
2130
|
+
};
|
|
2131
|
+
Cropper.prototype.onPinchMove = function (e) {
|
|
2132
|
+
var _this = this;
|
|
2133
|
+
if (!this.currentDoc || !this.currentWindow) return;
|
|
2134
|
+
var pointA = Cropper.getTouchPoint(e.touches[0]);
|
|
2135
|
+
var pointB = Cropper.getTouchPoint(e.touches[1]);
|
|
2136
|
+
var center = getCenter(pointA, pointB);
|
|
2137
|
+
this.onDrag(center);
|
|
2138
|
+
if (this.rafPinchTimeout) this.currentWindow.cancelAnimationFrame(this.rafPinchTimeout);
|
|
2139
|
+
this.rafPinchTimeout = this.currentWindow.requestAnimationFrame(function () {
|
|
2140
|
+
var distance = getDistanceBetweenPoints(pointA, pointB);
|
|
2141
|
+
var newZoom = _this.props.zoom * (distance / _this.lastPinchDistance);
|
|
2142
|
+
_this.setNewZoom(newZoom, center, {
|
|
2143
|
+
shouldUpdatePosition: false
|
|
2144
|
+
});
|
|
2145
|
+
_this.lastPinchDistance = distance;
|
|
2146
|
+
var rotation = getRotationBetweenPoints(pointA, pointB);
|
|
2147
|
+
var newRotation = _this.props.rotation + (rotation - _this.lastPinchRotation);
|
|
2148
|
+
_this.props.onRotationChange && _this.props.onRotationChange(newRotation);
|
|
2149
|
+
_this.lastPinchRotation = rotation;
|
|
2150
|
+
});
|
|
2151
|
+
};
|
|
2152
|
+
Cropper.prototype.render = function () {
|
|
2153
|
+
var _this = this;
|
|
2154
|
+
var _a;
|
|
2155
|
+
var _b = this.props,
|
|
2156
|
+
image = _b.image,
|
|
2157
|
+
video = _b.video,
|
|
2158
|
+
mediaProps = _b.mediaProps,
|
|
2159
|
+
cropperProps = _b.cropperProps,
|
|
2160
|
+
transform = _b.transform,
|
|
2161
|
+
_c = _b.crop,
|
|
2162
|
+
x = _c.x,
|
|
2163
|
+
y = _c.y,
|
|
2164
|
+
rotation = _b.rotation,
|
|
2165
|
+
zoom = _b.zoom,
|
|
2166
|
+
cropShape = _b.cropShape,
|
|
2167
|
+
showGrid = _b.showGrid,
|
|
2168
|
+
roundCropAreaPixels = _b.roundCropAreaPixels,
|
|
2169
|
+
_d = _b.style,
|
|
2170
|
+
containerStyle = _d.containerStyle,
|
|
2171
|
+
cropAreaStyle = _d.cropAreaStyle,
|
|
2172
|
+
mediaStyle = _d.mediaStyle,
|
|
2173
|
+
_e = _b.classes,
|
|
2174
|
+
containerClassName = _e.containerClassName,
|
|
2175
|
+
cropAreaClassName = _e.cropAreaClassName,
|
|
2176
|
+
mediaClassName = _e.mediaClassName;
|
|
2177
|
+
var objectFit = (_a = this.state.mediaObjectFit) !== null && _a !== void 0 ? _a : this.getObjectFit();
|
|
2178
|
+
return React__namespace.createElement("div", {
|
|
2179
|
+
onMouseDown: this.onMouseDown,
|
|
2180
|
+
onTouchStart: this.onTouchStart,
|
|
2181
|
+
ref: function ref(el) {
|
|
2182
|
+
return _this.containerRef = el;
|
|
2183
|
+
},
|
|
2184
|
+
"data-testid": "container",
|
|
2185
|
+
style: containerStyle,
|
|
2186
|
+
className: classNames('reactEasyCrop_Container', containerClassName)
|
|
2187
|
+
}, image ? React__namespace.createElement("img", __assign({
|
|
2188
|
+
alt: "",
|
|
2189
|
+
className: classNames('reactEasyCrop_Image', objectFit === 'contain' && 'reactEasyCrop_Contain', objectFit === 'horizontal-cover' && 'reactEasyCrop_Cover_Horizontal', objectFit === 'vertical-cover' && 'reactEasyCrop_Cover_Vertical', mediaClassName)
|
|
2190
|
+
}, mediaProps, {
|
|
2191
|
+
src: image,
|
|
2192
|
+
ref: this.imageRef,
|
|
2193
|
+
style: __assign(__assign({}, mediaStyle), {
|
|
2194
|
+
transform: transform || "translate(".concat(x, "px, ").concat(y, "px) rotate(").concat(rotation, "deg) scale(").concat(zoom, ")")
|
|
2195
|
+
}),
|
|
2196
|
+
onLoad: this.onMediaLoad
|
|
2197
|
+
})) : video && React__namespace.createElement("video", __assign({
|
|
2198
|
+
autoPlay: true,
|
|
2199
|
+
playsInline: true,
|
|
2200
|
+
loop: true,
|
|
2201
|
+
muted: true,
|
|
2202
|
+
className: classNames('reactEasyCrop_Video', objectFit === 'contain' && 'reactEasyCrop_Contain', objectFit === 'horizontal-cover' && 'reactEasyCrop_Cover_Horizontal', objectFit === 'vertical-cover' && 'reactEasyCrop_Cover_Vertical', mediaClassName)
|
|
2203
|
+
}, mediaProps, {
|
|
2204
|
+
ref: this.videoRef,
|
|
2205
|
+
onLoadedMetadata: this.onMediaLoad,
|
|
2206
|
+
style: __assign(__assign({}, mediaStyle), {
|
|
2207
|
+
transform: transform || "translate(".concat(x, "px, ").concat(y, "px) rotate(").concat(rotation, "deg) scale(").concat(zoom, ")")
|
|
2208
|
+
}),
|
|
2209
|
+
controls: false
|
|
2210
|
+
}), (Array.isArray(video) ? video : [{
|
|
2211
|
+
src: video
|
|
2212
|
+
}]).map(function (item) {
|
|
2213
|
+
return React__namespace.createElement("source", __assign({
|
|
2214
|
+
key: item.src
|
|
2215
|
+
}, item));
|
|
2216
|
+
})), this.state.cropSize && React__namespace.createElement("div", __assign({
|
|
2217
|
+
ref: this.cropperRef,
|
|
2218
|
+
style: __assign(__assign({}, cropAreaStyle), {
|
|
2219
|
+
width: roundCropAreaPixels ? Math.round(this.state.cropSize.width) : this.state.cropSize.width,
|
|
2220
|
+
height: roundCropAreaPixels ? Math.round(this.state.cropSize.height) : this.state.cropSize.height
|
|
2221
|
+
}),
|
|
2222
|
+
tabIndex: 0,
|
|
2223
|
+
onKeyDown: this.onKeyDown,
|
|
2224
|
+
onKeyUp: this.onKeyUp,
|
|
2225
|
+
"data-testid": "cropper",
|
|
2226
|
+
className: classNames('reactEasyCrop_CropArea', cropShape === 'round' && 'reactEasyCrop_CropAreaRound', showGrid && 'reactEasyCrop_CropAreaGrid', cropAreaClassName)
|
|
2227
|
+
}, cropperProps)));
|
|
2228
|
+
};
|
|
2229
|
+
Cropper.defaultProps = {
|
|
2230
|
+
zoom: 1,
|
|
2231
|
+
rotation: 0,
|
|
2232
|
+
aspect: 4 / 3,
|
|
2233
|
+
maxZoom: MAX_ZOOM,
|
|
2234
|
+
minZoom: MIN_ZOOM,
|
|
2235
|
+
cropShape: 'rect',
|
|
2236
|
+
objectFit: 'contain',
|
|
2237
|
+
showGrid: true,
|
|
2238
|
+
style: {},
|
|
2239
|
+
classes: {},
|
|
2240
|
+
mediaProps: {},
|
|
2241
|
+
cropperProps: {},
|
|
2242
|
+
zoomSpeed: 1,
|
|
2243
|
+
restrictPosition: true,
|
|
2244
|
+
zoomWithScroll: true,
|
|
2245
|
+
keyboardStep: KEYBOARD_STEP
|
|
2246
|
+
};
|
|
2247
|
+
Cropper.getMousePoint = function (e) {
|
|
2248
|
+
return {
|
|
2249
|
+
x: Number(e.clientX),
|
|
2250
|
+
y: Number(e.clientY)
|
|
2251
|
+
};
|
|
2252
|
+
};
|
|
2253
|
+
Cropper.getTouchPoint = function (touch) {
|
|
2254
|
+
return {
|
|
2255
|
+
x: Number(touch.clientX),
|
|
2256
|
+
y: Number(touch.clientY)
|
|
2257
|
+
};
|
|
2258
|
+
};
|
|
2259
|
+
return Cropper;
|
|
2260
|
+
}(React__namespace.Component);
|
|
2261
|
+
|
|
2262
|
+
const CameraCapture = ({ cameraView, facingMode, flashEnabled, capturedImage, cameraError, cameraLoading, videoRef, canvasRef, torchSupported, labels, icons, onCancel, onToggleCamera, onToggleFlash, onCapture, onRetake, onConfirm, onCropCancel, onApplyCrop, onCropComplete, }) => {
|
|
2263
|
+
const [showFlash, setShowFlash] = React.useState(false);
|
|
2264
|
+
const [crop, setCrop] = React.useState({ x: 0, y: 0 });
|
|
2265
|
+
const [zoom] = React.useState(1);
|
|
2266
|
+
const handleCapture = () => {
|
|
2267
|
+
setShowFlash(true);
|
|
2268
|
+
setTimeout(() => setShowFlash(false), 300);
|
|
2269
|
+
onCapture();
|
|
2270
|
+
};
|
|
2271
|
+
const handleCropComplete = React.useCallback((_, croppedAreaPixels) => {
|
|
2272
|
+
onCropComplete({
|
|
2273
|
+
x: croppedAreaPixels.x,
|
|
2274
|
+
y: croppedAreaPixels.y,
|
|
2275
|
+
width: croppedAreaPixels.width,
|
|
2276
|
+
height: croppedAreaPixels.height,
|
|
2277
|
+
});
|
|
2278
|
+
}, [onCropComplete]);
|
|
2279
|
+
if (cameraView === "none")
|
|
2280
|
+
return null;
|
|
2281
|
+
if (cameraView === "crop" && capturedImage) {
|
|
2282
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("label", { className: styles.label, children: labels.cropTitle }), jsxRuntime.jsx("div", { className: styles.cropContainer, children: jsxRuntime.jsx(Cropper, { image: capturedImage, crop: crop, zoom: zoom, aspect: undefined, onCropChange: setCrop, onCropComplete: handleCropComplete }) }), jsxRuntime.jsxs("div", { className: styles.capturedActions, children: [jsxRuntime.jsxs("button", { type: "button", className: styles.retakeBtn, onClick: onCropCancel, children: [icons.close, jsxRuntime.jsx("span", { children: labels.cropCancel })] }), jsxRuntime.jsxs("button", { type: "button", className: styles.confirmBtn, onClick: onApplyCrop, children: [icons.confirm, jsxRuntime.jsx("span", { children: labels.cropSave })] })] }), cameraError && (jsxRuntime.jsx("div", { className: styles.cameraError, children: cameraError }))] }));
|
|
2283
|
+
}
|
|
2284
|
+
if (cameraView === "captured" && capturedImage) {
|
|
2285
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: styles.capturedPreview, children: [jsxRuntime.jsx("img", { src: capturedImage, alt: "Captured", className: styles.capturedImage }), jsxRuntime.jsxs("div", { className: styles.capturedActions, children: [jsxRuntime.jsxs("button", { type: "button", className: styles.retakeBtn, onClick: onRetake, children: [icons.retake, jsxRuntime.jsx("span", { children: labels.retake })] }), jsxRuntime.jsxs("button", { type: "button", className: styles.confirmBtn, onClick: onConfirm, children: [icons.confirm, jsxRuntime.jsx("span", { children: labels.usePhoto })] })] })] }), cameraError && (jsxRuntime.jsx("div", { className: styles.cameraError, children: cameraError }))] }));
|
|
2286
|
+
}
|
|
2287
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: styles.cameraPreview, children: [cameraLoading ? (jsxRuntime.jsxs("div", { className: styles.cameraLoading, children: [jsxRuntime.jsx(md.MdCameraAlt, {}), jsxRuntime.jsx("div", { className: styles.cameraControls, children: jsxRuntime.jsx("button", { type: "button", className: styles.cameraControlBtn, onClick: onCancel, title: labels.cancel, children: icons.close }) })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("video", { ref: videoRef, autoPlay: true, playsInline: true, muted: true, className: styles.cameraVideo, style: {
|
|
2288
|
+
transform: facingMode === "user" ? "scaleX(-1)" : "none",
|
|
2289
|
+
} }), jsxRuntime.jsxs("div", { className: styles.cameraControls, children: [jsxRuntime.jsx("button", { type: "button", className: styles.cameraControlBtn, onClick: onCancel, title: labels.cancel, children: icons.close }), jsxRuntime.jsx("button", { type: "button", className: styles.cameraControlBtn, onClick: onToggleFlash, title: labels.toggleFlash, disabled: !torchSupported, style: { opacity: torchSupported ? 1 : 0.4 }, children: flashEnabled ? icons.flashOn : icons.flashOff }), jsxRuntime.jsx("button", { type: "button", className: styles.cameraControlBtn, onClick: onToggleCamera, title: labels.switchCamera, children: icons.switchCamera })] }), jsxRuntime.jsx("button", { type: "button", className: styles.captureBtn, onClick: handleCapture, children: jsxRuntime.jsx("div", { className: styles.captureBtnInner }) }), showFlash && jsxRuntime.jsx("div", { className: styles.screenFlash })] })), jsxRuntime.jsx("canvas", { ref: canvasRef, style: { display: "none" } })] }), cameraError && (jsxRuntime.jsx("div", { className: styles.cameraError, children: cameraError }))] }));
|
|
2290
|
+
};
|
|
2291
|
+
|
|
2292
|
+
var CameraCapture$1 = /*#__PURE__*/Object.freeze({
|
|
2293
|
+
__proto__: null,
|
|
2294
|
+
default: CameraCapture
|
|
2295
|
+
});
|
|
2296
|
+
|
|
2297
|
+
exports.ZestFileUpload = FileUpload;
|
|
2298
|
+
exports.default = FileUpload;
|
|
2299
|
+
//# sourceMappingURL=index.cjs.js.map
|