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