@marinoscar/vault-web 0.0.0-bootstrap → 0.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/agent/headless/agentActivity.d.ts +53 -0
- package/dist/agent/headless/agentActivity.js +58 -0
- package/dist/agent/headless/index.d.ts +2 -0
- package/dist/agent/headless/index.js +3 -0
- package/dist/agent/headless/useAgentActivity.d.ts +9 -0
- package/dist/agent/headless/useAgentActivity.js +30 -0
- package/dist/agent/ui/components/AgentActivityTable.d.ts +25 -0
- package/dist/agent/ui/components/AgentActivityTable.js +114 -0
- package/dist/agent/ui/index.d.ts +3 -0
- package/dist/agent/ui/index.js +4 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.d.ts +7 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.js +70 -0
- package/dist/agent/ui/pages/AgentActivityPage.d.ts +6 -0
- package/dist/agent/ui/pages/AgentActivityPage.js +61 -0
- package/dist/backups/headless/backupContents.d.ts +69 -0
- package/dist/backups/headless/backupContents.js +133 -0
- package/dist/backups/headless/backupPassword.d.ts +34 -0
- package/dist/backups/headless/backupPassword.js +80 -0
- package/dist/backups/headless/backupSchedule.d.ts +56 -0
- package/dist/backups/headless/backupSchedule.js +189 -0
- package/dist/backups/headless/index.d.ts +4 -0
- package/dist/backups/headless/index.js +5 -0
- package/dist/backups/headless/useBackupRunHistory.d.ts +36 -0
- package/dist/backups/headless/useBackupRunHistory.js +83 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.d.ts +20 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.js +65 -0
- package/dist/backups/ui/components/BackupContentsGroup.d.ts +17 -0
- package/dist/backups/ui/components/BackupContentsGroup.js +21 -0
- package/dist/backups/ui/components/BackupPasswordFields.d.ts +18 -0
- package/dist/backups/ui/components/BackupPasswordFields.js +40 -0
- package/dist/backups/ui/components/BackupRunsTable.d.ts +44 -0
- package/dist/backups/ui/components/BackupRunsTable.js +61 -0
- package/dist/backups/ui/components/DataBackup.d.ts +14 -0
- package/dist/backups/ui/components/DataBackup.js +169 -0
- package/dist/backups/ui/components/ScheduledBackups.d.ts +13 -0
- package/dist/backups/ui/components/ScheduledBackups.js +304 -0
- package/dist/backups/ui/index.d.ts +8 -0
- package/dist/backups/ui/index.js +9 -0
- package/dist/backups/ui/pages/BackupSettingsPage.d.ts +8 -0
- package/dist/backups/ui/pages/BackupSettingsPage.js +19 -0
- package/dist/backups/ui/pages/MyBackupsPage.d.ts +8 -0
- package/dist/backups/ui/pages/MyBackupsPage.js +19 -0
- package/dist/brand/BrandLockup.d.ts +14 -0
- package/dist/brand/BrandLockup.js +13 -0
- package/dist/brand/assets/vault-mark.png +0 -0
- package/dist/brand/contrast.d.ts +8 -0
- package/dist/brand/contrast.js +21 -0
- package/dist/brand/index.d.ts +7 -0
- package/dist/brand/index.js +8 -0
- package/dist/brand/mark.d.ts +6 -0
- package/dist/brand/mark.js +7 -0
- package/dist/brand/theme.d.ts +25 -0
- package/dist/brand/theme.js +84 -0
- package/dist/brand/tokens.d.ts +52 -0
- package/dist/brand/tokens.js +54 -0
- package/dist/cards/headless/cardExpiry.d.ts +57 -0
- package/dist/cards/headless/cardExpiry.js +138 -0
- package/dist/cards/headless/cardFormat.d.ts +60 -0
- package/dist/cards/headless/cardFormat.js +135 -0
- package/dist/cards/headless/cardImage.d.ts +293 -0
- package/dist/cards/headless/cardImage.js +518 -0
- package/dist/cards/headless/index.d.ts +6 -0
- package/dist/cards/headless/index.js +7 -0
- package/dist/cards/headless/useCardImport.d.ts +137 -0
- package/dist/cards/headless/useCardImport.js +391 -0
- package/dist/cards/headless/useCardRenewal.d.ts +102 -0
- package/dist/cards/headless/useCardRenewal.js +305 -0
- package/dist/cards/headless/useCards.d.ts +80 -0
- package/dist/cards/headless/useCards.js +114 -0
- package/dist/cards/ui/components/AiEgressNotice.d.ts +13 -0
- package/dist/cards/ui/components/AiEgressNotice.js +18 -0
- package/dist/cards/ui/components/CardCaptureStep.d.ts +59 -0
- package/dist/cards/ui/components/CardCaptureStep.js +96 -0
- package/dist/cards/ui/components/CardCropAdjuster.d.ts +43 -0
- package/dist/cards/ui/components/CardCropAdjuster.js +215 -0
- package/dist/cards/ui/components/CardCropReview.d.ts +51 -0
- package/dist/cards/ui/components/CardCropReview.js +88 -0
- package/dist/cards/ui/components/CardExpiryBadge.d.ts +8 -0
- package/dist/cards/ui/components/CardExpiryBadge.js +43 -0
- package/dist/cards/ui/components/CardFieldDiff.d.ts +37 -0
- package/dist/cards/ui/components/CardFieldDiff.js +66 -0
- package/dist/cards/ui/components/CardFlowStepper.d.ts +24 -0
- package/dist/cards/ui/components/CardFlowStepper.js +23 -0
- package/dist/cards/ui/components/CardReviewForm.d.ts +44 -0
- package/dist/cards/ui/components/CardReviewForm.js +102 -0
- package/dist/cards/ui/components/CardScanModelSection.d.ts +23 -0
- package/dist/cards/ui/components/CardScanModelSection.js +81 -0
- package/dist/cards/ui/components/CardTile.d.ts +40 -0
- package/dist/cards/ui/components/CardTile.js +94 -0
- package/dist/cards/ui/index.d.ts +15 -0
- package/dist/cards/ui/index.js +16 -0
- package/dist/cards/ui/pages/AiSettingsPage.d.ts +12 -0
- package/dist/cards/ui/pages/AiSettingsPage.js +24 -0
- package/dist/cards/ui/pages/CardsPage.d.ts +26 -0
- package/dist/cards/ui/pages/CardsPage.js +160 -0
- package/dist/cards/ui/pages/ImportCardPage.d.ts +24 -0
- package/dist/cards/ui/pages/ImportCardPage.js +343 -0
- package/dist/cards/ui/pages/RenewCardPage.d.ts +35 -0
- package/dist/cards/ui/pages/RenewCardPage.js +350 -0
- package/dist/core/headless/api.d.ts +272 -0
- package/dist/core/headless/api.js +425 -0
- package/dist/core/headless/cardScanAvailability.d.ts +20 -0
- package/dist/core/headless/cardScanAvailability.js +27 -0
- package/dist/core/headless/clipboard.d.ts +60 -0
- package/dist/core/headless/clipboard.js +101 -0
- package/dist/core/headless/http.d.ts +41 -0
- package/dist/core/headless/http.js +50 -0
- package/dist/core/headless/index.d.ts +12 -0
- package/dist/core/headless/index.js +13 -0
- package/dist/core/headless/relativeTime.d.ts +7 -0
- package/dist/core/headless/relativeTime.js +28 -0
- package/dist/core/headless/saveBlob.d.ts +6 -0
- package/dist/core/headless/saveBlob.js +21 -0
- package/dist/core/headless/types.d.ts +441 -0
- package/dist/core/headless/types.js +49 -0
- package/dist/core/headless/useAiStatus.d.ts +41 -0
- package/dist/core/headless/useAiStatus.js +42 -0
- package/dist/core/headless/useCopyToClipboard.d.ts +20 -0
- package/dist/core/headless/useCopyToClipboard.js +52 -0
- package/dist/core/headless/useDashboardResource.d.ts +22 -0
- package/dist/core/headless/useDashboardResource.js +52 -0
- package/dist/core/headless/useSystemSettings.d.ts +17 -0
- package/dist/core/headless/useSystemSettings.js +106 -0
- package/dist/core/headless/useUserSettings.d.ts +13 -0
- package/dist/core/headless/useUserSettings.js +103 -0
- package/dist/core/ui/ErrorBoundary.d.ts +15 -0
- package/dist/core/ui/ErrorBoundary.js +27 -0
- package/dist/core/ui/LoadingSpinner.d.ts +6 -0
- package/dist/core/ui/LoadingSpinner.js +14 -0
- package/dist/core/ui/SettingsPageFrame.d.ts +19 -0
- package/dist/core/ui/SettingsPageFrame.js +12 -0
- package/dist/core/ui/StorageSettingsLink.d.ts +19 -0
- package/dist/core/ui/StorageSettingsLink.js +26 -0
- package/dist/core/ui/index.d.ts +4 -0
- package/dist/core/ui/index.js +5 -0
- package/dist/home/headless/homeLinks.d.ts +24 -0
- package/dist/home/headless/homeLinks.js +24 -0
- package/dist/home/headless/index.d.ts +1 -0
- package/dist/home/headless/index.js +2 -0
- package/dist/home/ui/components/BackupStatusPanel.d.ts +28 -0
- package/dist/home/ui/components/BackupStatusPanel.js +99 -0
- package/dist/home/ui/components/DashboardPanel.d.ts +33 -0
- package/dist/home/ui/components/DashboardPanel.js +21 -0
- package/dist/home/ui/components/ExpiringCardsPanel.d.ts +31 -0
- package/dist/home/ui/components/ExpiringCardsPanel.js +35 -0
- package/dist/home/ui/components/FirstRunPanel.d.ts +7 -0
- package/dist/home/ui/components/FirstRunPanel.js +21 -0
- package/dist/home/ui/components/QuickActions.d.ts +14 -0
- package/dist/home/ui/components/QuickActions.js +40 -0
- package/dist/home/ui/components/RecentSecretsPanel.d.ts +19 -0
- package/dist/home/ui/components/RecentSecretsPanel.js +20 -0
- package/dist/home/ui/components/StatsRow.d.ts +19 -0
- package/dist/home/ui/components/StatsRow.js +46 -0
- package/dist/home/ui/components/WelcomeHeader.d.ts +11 -0
- package/dist/home/ui/components/WelcomeHeader.js +15 -0
- package/dist/home/ui/index.d.ts +9 -0
- package/dist/home/ui/index.js +10 -0
- package/dist/home/ui/pages/HomePage.d.ts +14 -0
- package/dist/home/ui/pages/HomePage.js +121 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/media/headless/index.d.ts +2 -0
- package/dist/media/headless/index.js +3 -0
- package/dist/media/headless/useMediaFiles.d.ts +20 -0
- package/dist/media/headless/useMediaFiles.js +82 -0
- package/dist/media/headless/useMediaFolders.d.ts +22 -0
- package/dist/media/headless/useMediaFolders.js +81 -0
- package/dist/media/ui/components/FolderList.d.ts +19 -0
- package/dist/media/ui/components/FolderList.js +36 -0
- package/dist/media/ui/components/MediaList.d.ts +20 -0
- package/dist/media/ui/components/MediaList.js +55 -0
- package/dist/media/ui/components/MediaPlayer.d.ts +7 -0
- package/dist/media/ui/components/MediaPlayer.js +361 -0
- package/dist/media/ui/index.d.ts +10 -0
- package/dist/media/ui/index.js +11 -0
- package/dist/media/ui/pages/CreateFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/CreateFolderPage.js +39 -0
- package/dist/media/ui/pages/EditFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/EditFolderPage.js +59 -0
- package/dist/media/ui/pages/MediaFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFolderPage.js +68 -0
- package/dist/media/ui/pages/MediaFoldersPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFoldersPage.js +58 -0
- package/dist/media/ui/pages/MediaPlayerPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaPlayerPage.js +76 -0
- package/dist/media/ui/pages/MediaUploadPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaUploadPage.js +88 -0
- package/dist/media/ui/pages/RenameMediaFilePage.d.ts +1 -0
- package/dist/media/ui/pages/RenameMediaFilePage.js +63 -0
- package/dist/navigation/destinations.d.ts +50 -0
- package/dist/navigation/destinations.js +109 -0
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.js +4 -0
- package/dist/secrets/headless/fieldOptionsValidation.d.ts +45 -0
- package/dist/secrets/headless/fieldOptionsValidation.js +79 -0
- package/dist/secrets/headless/index.d.ts +6 -0
- package/dist/secrets/headless/index.js +7 -0
- package/dist/secrets/headless/secretFields.d.ts +86 -0
- package/dist/secrets/headless/secretFields.js +190 -0
- package/dist/secrets/headless/useSecretDetail.d.ts +33 -0
- package/dist/secrets/headless/useSecretDetail.js +87 -0
- package/dist/secrets/headless/useSecretTypes.d.ts +16 -0
- package/dist/secrets/headless/useSecretTypes.js +62 -0
- package/dist/secrets/headless/useSecrets.d.ts +24 -0
- package/dist/secrets/headless/useSecrets.js +59 -0
- package/dist/secrets/headless/useTotpCode.d.ts +24 -0
- package/dist/secrets/headless/useTotpCode.js +116 -0
- package/dist/secrets/ui/components/CardImages.d.ts +31 -0
- package/dist/secrets/ui/components/CardImages.js +208 -0
- package/dist/secrets/ui/components/DynamicSecretFields.d.ts +10 -0
- package/dist/secrets/ui/components/DynamicSecretFields.js +90 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.d.ts +13 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.js +114 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.d.ts +15 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.js +45 -0
- package/dist/secrets/ui/components/SecretAttachments.d.ts +15 -0
- package/dist/secrets/ui/components/SecretAttachments.js +106 -0
- package/dist/secrets/ui/components/SecretForm.d.ts +34 -0
- package/dist/secrets/ui/components/SecretForm.js +83 -0
- package/dist/secrets/ui/components/SecretFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretFormDialog.js +95 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.js +92 -0
- package/dist/secrets/ui/components/SecretTypeIcon.d.ts +8 -0
- package/dist/secrets/ui/components/SecretTypeIcon.js +16 -0
- package/dist/secrets/ui/components/SecretTypesList.d.ts +10 -0
- package/dist/secrets/ui/components/SecretTypesList.js +13 -0
- package/dist/secrets/ui/components/SecretValueField.d.ts +20 -0
- package/dist/secrets/ui/components/SecretValueField.js +52 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.d.ts +22 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.js +131 -0
- package/dist/secrets/ui/components/SecretsTable.d.ts +49 -0
- package/dist/secrets/ui/components/SecretsTable.js +174 -0
- package/dist/secrets/ui/components/TotpCodeCard.d.ts +8 -0
- package/dist/secrets/ui/components/TotpCodeCard.js +34 -0
- package/dist/secrets/ui/index.d.ts +20 -0
- package/dist/secrets/ui/index.js +21 -0
- package/dist/secrets/ui/pages/CreateSecretPage.d.ts +2 -0
- package/dist/secrets/ui/pages/CreateSecretPage.js +25 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.js +62 -0
- package/dist/secrets/ui/pages/EditSecretPage.d.ts +5 -0
- package/dist/secrets/ui/pages/EditSecretPage.js +55 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.js +88 -0
- package/dist/secrets/ui/pages/SecretDetailPage.d.ts +7 -0
- package/dist/secrets/ui/pages/SecretDetailPage.js +182 -0
- package/dist/secrets/ui/pages/SecretTypesPage.d.ts +1 -0
- package/dist/secrets/ui/pages/SecretTypesPage.js +23 -0
- package/dist/secrets/ui/pages/SecretsPage.d.ts +6 -0
- package/dist/secrets/ui/pages/SecretsPage.js +179 -0
- package/dist/settings/ui/components/FeatureFlagsList.d.ts +7 -0
- package/dist/settings/ui/components/FeatureFlagsList.js +46 -0
- package/dist/settings/ui/components/ImageUpload.d.ts +6 -0
- package/dist/settings/ui/components/ImageUpload.js +61 -0
- package/dist/settings/ui/components/ProfileSettings.d.ts +11 -0
- package/dist/settings/ui/components/ProfileSettings.js +55 -0
- package/dist/settings/ui/components/ThemeSettings.d.ts +7 -0
- package/dist/settings/ui/components/ThemeSettings.js +24 -0
- package/dist/settings/ui/components/UISettings.d.ts +9 -0
- package/dist/settings/ui/components/UISettings.js +25 -0
- package/dist/settings/ui/components/UserProfileCard.d.ts +1 -0
- package/dist/settings/ui/components/UserProfileCard.js +39 -0
- package/dist/settings/ui/components/UserSettingsSection.d.ts +23 -0
- package/dist/settings/ui/components/UserSettingsSection.js +29 -0
- package/dist/settings/ui/index.d.ts +10 -0
- package/dist/settings/ui/index.js +11 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.js +11 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.d.ts +9 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.js +41 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.js +11 -0
- package/package.json +146 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { Alert, Box, Button, CircularProgress, Paper, Typography, } from '@mui/material';
|
|
4
|
+
import { PhotoCamera as CameraIcon, PhotoLibraryOutlined as LibraryIcon, Refresh as RetakeIcon, } from '@mui/icons-material';
|
|
5
|
+
import { CARD_ASPECT_RATIO } from '../../headless/cardImage.js';
|
|
6
|
+
const COPY = {
|
|
7
|
+
front: {
|
|
8
|
+
heading: 'Photograph the front of the card',
|
|
9
|
+
help: 'Make sure every corner of the card is in the shot and the text is readable.',
|
|
10
|
+
action: 'Take a photo of the front',
|
|
11
|
+
},
|
|
12
|
+
back: {
|
|
13
|
+
heading: 'Photograph the back of the card (optional)',
|
|
14
|
+
help: 'Make sure every corner of the card is in the shot and the text is readable. Skip it if you would rather not photograph the signature strip.',
|
|
15
|
+
action: 'Take a photo of the back',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* One capture step of the import wizard.
|
|
20
|
+
*
|
|
21
|
+
* Camera-friendly (E10.5): the primary action is a file input with
|
|
22
|
+
* `capture="environment"`, which asks a phone for the rear camera and opens it
|
|
23
|
+
* directly; on a desktop browser the same input degrades to an ordinary file
|
|
24
|
+
* picker, which is why this is a file input rather than a getUserMedia preview.
|
|
25
|
+
* A second, secondary action picks an existing photo from the library (no
|
|
26
|
+
* `capture`), for a card photographed earlier. On a phone both buttons are full
|
|
27
|
+
* width, comfortably above the 44px target size.
|
|
28
|
+
*
|
|
29
|
+
* No cropping happens here: the FULL photo is shown as-is for a use-it-or-
|
|
30
|
+
* retake decision, and the full frame is what the extraction endpoint receives
|
|
31
|
+
* — the AI locates the card and returns its bounding box. Cropping to the card
|
|
32
|
+
* (for the stored attachment) happens after extraction, seeded from that box
|
|
33
|
+
* and adjustable on the review step; the full photo itself is never uploaded
|
|
34
|
+
* to storage.
|
|
35
|
+
*/
|
|
36
|
+
export function CardCaptureStep({ side, photo, onFileSelected, onRetake, onContinue, onSkip, onCancel, isProcessing = false, error = null, heading, helpText, continueLabel, skipLabel = 'Skip the back', }) {
|
|
37
|
+
const cameraRef = useRef(null);
|
|
38
|
+
const libraryRef = useRef(null);
|
|
39
|
+
const copy = COPY[side];
|
|
40
|
+
const handleChange = (event) => {
|
|
41
|
+
const file = event.target.files?.[0];
|
|
42
|
+
// Reset so retaking with the same file name still fires a change event.
|
|
43
|
+
event.target.value = '';
|
|
44
|
+
if (file)
|
|
45
|
+
onFileSelected(file);
|
|
46
|
+
};
|
|
47
|
+
const fullWidthOnPhone = { width: { xs: '100%', sm: 'auto' }, minHeight: 44 };
|
|
48
|
+
return (_jsxs(Paper, { variant: "outlined", sx: { p: { xs: 2, md: 3 } }, children: [_jsx(Typography, { variant: "h6", component: "h2", gutterBottom: true, children: heading ?? copy.heading }), _jsx(Typography, { variant: "body2", sx: {
|
|
49
|
+
color: "text.secondary",
|
|
50
|
+
mb: 2
|
|
51
|
+
}, children: helpText ?? copy.help }), error && (_jsx(Alert, { severity: "error", sx: { mb: 2 }, children: error })), _jsx("input", { ref: cameraRef, type: "file", accept: "image/*", capture: "environment", onChange: handleChange, style: { display: 'none' }, "data-testid": `card-${side}-input`, "aria-label": copy.action }), _jsx("input", { ref: libraryRef, type: "file", accept: "image/*", onChange: handleChange, style: { display: 'none' }, "data-testid": `card-${side}-library-input`, "aria-label": `Choose a photo of the ${side}` }), photo ? (_jsx(Box, { sx: {
|
|
52
|
+
mb: 2,
|
|
53
|
+
mx: { xs: 'auto', sm: 0 },
|
|
54
|
+
borderRadius: 1,
|
|
55
|
+
overflow: 'hidden',
|
|
56
|
+
border: 1,
|
|
57
|
+
borderColor: 'divider',
|
|
58
|
+
maxWidth: 480,
|
|
59
|
+
}, children: _jsx(Box, { component: "img", src: photo.previewUrl, alt: `Photo of the ${side} of the card`, sx: { display: 'block', width: '100%', height: 'auto', maxHeight: 360, objectFit: 'contain' } }) })) : (
|
|
60
|
+
// A card-shaped frame with corner guides: what "every corner in the
|
|
61
|
+
// shot" looks like. Decorative; the buttons below carry the action.
|
|
62
|
+
_jsxs(Box, { "aria-hidden": "true", sx: {
|
|
63
|
+
position: 'relative',
|
|
64
|
+
mb: 2,
|
|
65
|
+
mx: { xs: 'auto', sm: 0 },
|
|
66
|
+
maxWidth: 480,
|
|
67
|
+
aspectRatio: String(CARD_ASPECT_RATIO),
|
|
68
|
+
border: 1,
|
|
69
|
+
borderStyle: 'dashed',
|
|
70
|
+
borderColor: 'divider',
|
|
71
|
+
borderRadius: 2,
|
|
72
|
+
bgcolor: 'action.hover',
|
|
73
|
+
display: 'flex',
|
|
74
|
+
flexDirection: 'column',
|
|
75
|
+
gap: 1,
|
|
76
|
+
alignItems: 'center',
|
|
77
|
+
justifyContent: 'center',
|
|
78
|
+
color: 'text.secondary',
|
|
79
|
+
'& .corner': {
|
|
80
|
+
position: 'absolute',
|
|
81
|
+
width: 28,
|
|
82
|
+
height: 28,
|
|
83
|
+
borderColor: 'primary.main',
|
|
84
|
+
borderStyle: 'solid',
|
|
85
|
+
borderWidth: 0,
|
|
86
|
+
},
|
|
87
|
+
}, children: [_jsx(Box, { className: "corner", sx: { top: 10, left: 10, borderTopWidth: 3, borderLeftWidth: 3, borderTopLeftRadius: 8 } }), _jsx(Box, { className: "corner", sx: { top: 10, right: 10, borderTopWidth: 3, borderRightWidth: 3, borderTopRightRadius: 8 } }), _jsx(Box, { className: "corner", sx: { bottom: 10, left: 10, borderBottomWidth: 3, borderLeftWidth: 3, borderBottomLeftRadius: 8 } }), _jsx(Box, { className: "corner", sx: { bottom: 10, right: 10, borderBottomWidth: 3, borderRightWidth: 3, borderBottomRightRadius: 8 } }), isProcessing ? (_jsx(CircularProgress, { size: 28 })) : (_jsxs(_Fragment, { children: [_jsx(CameraIcon, { sx: { fontSize: 36, color: 'text.disabled' } }), _jsx(Typography, { variant: "body2", children: side === 'front' ? 'Front of the card' : 'Back of the card' })] }))] })), _jsxs(Box, { sx: {
|
|
88
|
+
display: 'flex',
|
|
89
|
+
flexDirection: { xs: 'column', sm: 'row' },
|
|
90
|
+
flexWrap: 'wrap',
|
|
91
|
+
gap: 1,
|
|
92
|
+
}, children: [photo ? (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "contained", onClick: onContinue, disabled: isProcessing, sx: fullWidthOnPhone, children: continueLabel ?? (side === 'front' ? 'Continue' : 'Read the card') }), _jsx(Button, { variant: "outlined", startIcon: _jsx(RetakeIcon, {}), onClick: () => {
|
|
93
|
+
onRetake();
|
|
94
|
+
cameraRef.current?.click();
|
|
95
|
+
}, disabled: isProcessing, sx: fullWidthOnPhone, children: "Retake" })] })) : (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "contained", startIcon: _jsx(CameraIcon, {}), onClick: () => cameraRef.current?.click(), disabled: isProcessing, sx: fullWidthOnPhone, children: copy.action }), _jsx(Button, { variant: "outlined", startIcon: _jsx(LibraryIcon, {}), onClick: () => libraryRef.current?.click(), disabled: isProcessing, sx: fullWidthOnPhone, children: "Choose a photo" })] })), onSkip && (_jsx(Button, { onClick: onSkip, disabled: isProcessing, sx: fullWidthOnPhone, children: skipLabel })), _jsx(Box, { sx: { flexGrow: 1, display: { xs: 'none', sm: 'block' } } }), _jsx(Button, { color: "inherit", onClick: onCancel, disabled: isProcessing, sx: fullWidthOnPhone, children: "Cancel" })] })] }));
|
|
96
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type CardAdjustments, type FractionalCropBox } from '../../headless/cardImage.js';
|
|
2
|
+
interface CardCropAdjusterProps {
|
|
3
|
+
/** The raw capture, exactly as picked. Never uploaded — only drawn locally. */
|
|
4
|
+
file: File;
|
|
5
|
+
side: 'front' | 'back';
|
|
6
|
+
/** Fired with the final adjustments when the user accepts the framing. */
|
|
7
|
+
onConfirm: (adjustments: CardAdjustments) => void;
|
|
8
|
+
/** The user backed out; the caller reopens the picker (or closes the stage). */
|
|
9
|
+
onRetake: () => void;
|
|
10
|
+
/** True while the caller is encoding the confirmed crop. */
|
|
11
|
+
isProcessing?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Seed the knobs from a previously confirmed adjustment, so reopening the
|
|
14
|
+
* adjuster resumes where the user left off. Takes precedence over
|
|
15
|
+
* `initialBox`.
|
|
16
|
+
*/
|
|
17
|
+
initialAdjustments?: CardAdjustments;
|
|
18
|
+
/**
|
|
19
|
+
* Seed the knobs from the AI-returned fractional box, so the adjuster opens
|
|
20
|
+
* showing the crop the box produced rather than the centred auto-fit. Used
|
|
21
|
+
* when the user has not adjusted this side yet.
|
|
22
|
+
*/
|
|
23
|
+
initialBox?: FractionalCropBox;
|
|
24
|
+
/** Label of the confirm button. Defaults to 'Use this photo'. */
|
|
25
|
+
confirmLabel?: string;
|
|
26
|
+
/** Label of the secondary (back-out) button. Defaults to 'Retake'. */
|
|
27
|
+
retakeLabel?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Interactive crop override.
|
|
31
|
+
*
|
|
32
|
+
* The AI locates the card and its box seeds the stored-attachment crop; this
|
|
33
|
+
* stage exists for when that box (or, with AI unavailable, the centred
|
|
34
|
+
* auto-fit) is wrong. The user rotates (90° steps), zooms (1-4x) and drags the
|
|
35
|
+
* picture until the card fills the card-shaped viewport, then confirms. The
|
|
36
|
+
* preview is drawn by the SAME `drawCardCrop` routine that later encodes the
|
|
37
|
+
* stored crop, so what the user approves is what gets kept.
|
|
38
|
+
*
|
|
39
|
+
* The raw file is only ever drawn to a local canvas here; only the confirmed
|
|
40
|
+
* crop, encoded by the caller, is uploaded to storage.
|
|
41
|
+
*/
|
|
42
|
+
export declare function CardCropAdjuster({ file, side, onConfirm, onRetake, isProcessing, initialAdjustments, initialBox, confirmLabel, retakeLabel, }: CardCropAdjusterProps): import("react").JSX.Element;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState, } from 'react';
|
|
3
|
+
import { Alert, Box, Button, CircularProgress, Slider, Stack } from '@mui/material';
|
|
4
|
+
import { Check as ConfirmIcon, Refresh as RetakeIcon, RotateRight as RotateIcon, ZoomIn as ZoomInIcon, ZoomOut as ZoomOutIcon, } from '@mui/icons-material';
|
|
5
|
+
import { CARD_ASPECT_RATIO, CARD_IMAGE_MAX_ZOOM, adjustmentsFromCropBox, clamp, computeAdjustedCropRect, computeMaxPan, drawCardCrop, effectiveSourceSize, normalizeQuarterTurns, } from '../../headless/cardImage.js';
|
|
6
|
+
const INITIAL_ADJUSTMENTS = {
|
|
7
|
+
zoom: 1,
|
|
8
|
+
panX: 0,
|
|
9
|
+
panY: 0,
|
|
10
|
+
quarterTurns: 0,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Preview canvas backing resolution. Wider than the on-screen size (~480 CSS
|
|
14
|
+
* px capped by the layout) so the preview stays sharp on high-DPI phones —
|
|
15
|
+
* which is where this flow mostly runs.
|
|
16
|
+
*/
|
|
17
|
+
const PREVIEW_WIDTH = 960;
|
|
18
|
+
const PREVIEW_HEIGHT = Math.round(PREVIEW_WIDTH / CARD_ASPECT_RATIO);
|
|
19
|
+
/**
|
|
20
|
+
* Interactive crop override.
|
|
21
|
+
*
|
|
22
|
+
* The AI locates the card and its box seeds the stored-attachment crop; this
|
|
23
|
+
* stage exists for when that box (or, with AI unavailable, the centred
|
|
24
|
+
* auto-fit) is wrong. The user rotates (90° steps), zooms (1-4x) and drags the
|
|
25
|
+
* picture until the card fills the card-shaped viewport, then confirms. The
|
|
26
|
+
* preview is drawn by the SAME `drawCardCrop` routine that later encodes the
|
|
27
|
+
* stored crop, so what the user approves is what gets kept.
|
|
28
|
+
*
|
|
29
|
+
* The raw file is only ever drawn to a local canvas here; only the confirmed
|
|
30
|
+
* crop, encoded by the caller, is uploaded to storage.
|
|
31
|
+
*/
|
|
32
|
+
export function CardCropAdjuster({ file, side, onConfirm, onRetake, isProcessing = false, initialAdjustments, initialBox, confirmLabel = 'Use this photo', retakeLabel = 'Retake', }) {
|
|
33
|
+
const canvasRef = useRef(null);
|
|
34
|
+
const [image, setImage] = useState(null);
|
|
35
|
+
const [loadError, setLoadError] = useState(null);
|
|
36
|
+
const [adjust, setAdjust] = useState(INITIAL_ADJUSTMENTS);
|
|
37
|
+
// The seeds are read once per decoded file, inside the decode effect. A ref
|
|
38
|
+
// keeps them out of that effect's dependencies: pages pass fresh object
|
|
39
|
+
// literals every render, and re-running the decode on each would reset the
|
|
40
|
+
// user's in-progress adjustment.
|
|
41
|
+
const seedRef = useRef({ initialAdjustments, initialBox });
|
|
42
|
+
seedRef.current = { initialAdjustments, initialBox };
|
|
43
|
+
/** Resolve the starting knobs for a freshly decoded image. */
|
|
44
|
+
const resolveSeed = (element) => {
|
|
45
|
+
const { initialAdjustments: seedAdjust, initialBox: seedBox } = seedRef.current;
|
|
46
|
+
if (seedAdjust) {
|
|
47
|
+
return {
|
|
48
|
+
zoom: clamp(seedAdjust.zoom ?? 1, 1, CARD_IMAGE_MAX_ZOOM),
|
|
49
|
+
panX: seedAdjust.panX ?? 0,
|
|
50
|
+
panY: seedAdjust.panY ?? 0,
|
|
51
|
+
quarterTurns: normalizeQuarterTurns(seedAdjust.quarterTurns),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (seedBox) {
|
|
55
|
+
try {
|
|
56
|
+
return adjustmentsFromCropBox(element.naturalWidth || element.width, element.naturalHeight || element.height, seedBox);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// A degenerate box seeds nothing; fall through to the auto-fit start.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return INITIAL_ADJUSTMENTS;
|
|
63
|
+
};
|
|
64
|
+
// One active drag at a time; a second touch while dragging is ignored rather
|
|
65
|
+
// than making the pan jump between fingers.
|
|
66
|
+
const dragRef = useRef(null);
|
|
67
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
68
|
+
// Decode the picked file once per file. The object URL is revoked as soon as
|
|
69
|
+
// the decode settles — the decoded element keeps its pixels without it.
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
let cancelled = false;
|
|
72
|
+
setImage(null);
|
|
73
|
+
setLoadError(null);
|
|
74
|
+
setAdjust(INITIAL_ADJUSTMENTS);
|
|
75
|
+
const url = URL.createObjectURL(file);
|
|
76
|
+
const element = new Image();
|
|
77
|
+
element.onload = () => {
|
|
78
|
+
URL.revokeObjectURL(url);
|
|
79
|
+
if (!cancelled) {
|
|
80
|
+
setImage(element);
|
|
81
|
+
setAdjust(resolveSeed(element));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
element.onerror = () => {
|
|
85
|
+
URL.revokeObjectURL(url);
|
|
86
|
+
if (!cancelled)
|
|
87
|
+
setLoadError('That file could not be read as an image.');
|
|
88
|
+
};
|
|
89
|
+
element.src = url;
|
|
90
|
+
return () => {
|
|
91
|
+
cancelled = true;
|
|
92
|
+
};
|
|
93
|
+
}, [file]);
|
|
94
|
+
// Redraw on every knob change, coalesced to one draw per frame: the cleanup
|
|
95
|
+
// cancels a not-yet-painted frame when a newer state lands, which is all the
|
|
96
|
+
// debounce a drag needs.
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const canvas = canvasRef.current;
|
|
99
|
+
if (!canvas || !image)
|
|
100
|
+
return;
|
|
101
|
+
const frame = requestAnimationFrame(() => {
|
|
102
|
+
const context = canvas.getContext('2d');
|
|
103
|
+
if (!context)
|
|
104
|
+
return;
|
|
105
|
+
const sourceWidth = image.naturalWidth || image.width;
|
|
106
|
+
const sourceHeight = image.naturalHeight || image.height;
|
|
107
|
+
const effective = effectiveSourceSize(sourceWidth, sourceHeight, adjust.quarterTurns);
|
|
108
|
+
const crop = computeAdjustedCropRect(effective.width, effective.height, adjust.zoom, adjust.panX, adjust.panY);
|
|
109
|
+
drawCardCrop(context, image, sourceWidth, sourceHeight, { crop, quarterTurns: adjust.quarterTurns }, canvas.width, canvas.height);
|
|
110
|
+
});
|
|
111
|
+
return () => cancelAnimationFrame(frame);
|
|
112
|
+
}, [image, adjust]);
|
|
113
|
+
/** Clamp a pan against the slack available at the given zoom/rotation. */
|
|
114
|
+
const clampPan = useCallback((panX, panY, zoom, quarterTurns) => {
|
|
115
|
+
if (!image)
|
|
116
|
+
return { panX, panY };
|
|
117
|
+
const sourceWidth = image.naturalWidth || image.width;
|
|
118
|
+
const sourceHeight = image.naturalHeight || image.height;
|
|
119
|
+
const effective = effectiveSourceSize(sourceWidth, sourceHeight, quarterTurns);
|
|
120
|
+
const max = computeMaxPan(effective.width, effective.height, zoom);
|
|
121
|
+
return {
|
|
122
|
+
panX: clamp(panX, -max.x, max.x),
|
|
123
|
+
panY: clamp(panY, -max.y, max.y),
|
|
124
|
+
};
|
|
125
|
+
}, [image]);
|
|
126
|
+
const handleRotate = () => {
|
|
127
|
+
// A rotation changes which way the pan axes point; recentering is less
|
|
128
|
+
// surprising than a pan that suddenly moves the picture sideways.
|
|
129
|
+
setAdjust((prev) => ({
|
|
130
|
+
zoom: prev.zoom,
|
|
131
|
+
panX: 0,
|
|
132
|
+
panY: 0,
|
|
133
|
+
quarterTurns: (prev.quarterTurns + 1) % 4,
|
|
134
|
+
}));
|
|
135
|
+
};
|
|
136
|
+
const handleZoom = (value) => {
|
|
137
|
+
setAdjust((prev) => {
|
|
138
|
+
const zoom = clamp(value, 1, CARD_IMAGE_MAX_ZOOM);
|
|
139
|
+
// Zooming out shrinks the available slack; pull the pan back in so the
|
|
140
|
+
// crop never sticks outside the frame.
|
|
141
|
+
const panned = clampPan(prev.panX, prev.panY, zoom, prev.quarterTurns);
|
|
142
|
+
return { ...prev, zoom, ...panned };
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const handlePointerDown = (event) => {
|
|
146
|
+
if (isProcessing || !image || dragRef.current)
|
|
147
|
+
return;
|
|
148
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
149
|
+
dragRef.current = {
|
|
150
|
+
pointerId: event.pointerId,
|
|
151
|
+
lastX: event.clientX,
|
|
152
|
+
lastY: event.clientY,
|
|
153
|
+
};
|
|
154
|
+
setIsDragging(true);
|
|
155
|
+
};
|
|
156
|
+
const handlePointerMove = (event) => {
|
|
157
|
+
const drag = dragRef.current;
|
|
158
|
+
if (!drag || drag.pointerId !== event.pointerId || !image)
|
|
159
|
+
return;
|
|
160
|
+
const deltaX = event.clientX - drag.lastX;
|
|
161
|
+
const deltaY = event.clientY - drag.lastY;
|
|
162
|
+
drag.lastX = event.clientX;
|
|
163
|
+
drag.lastY = event.clientY;
|
|
164
|
+
const viewWidth = event.currentTarget.getBoundingClientRect().width;
|
|
165
|
+
if (viewWidth <= 0)
|
|
166
|
+
return;
|
|
167
|
+
setAdjust((prev) => {
|
|
168
|
+
const sourceWidth = image.naturalWidth || image.width;
|
|
169
|
+
const sourceHeight = image.naturalHeight || image.height;
|
|
170
|
+
const effective = effectiveSourceSize(sourceWidth, sourceHeight, prev.quarterTurns);
|
|
171
|
+
const crop = computeAdjustedCropRect(effective.width, effective.height, prev.zoom, prev.panX, prev.panY);
|
|
172
|
+
// Dragging moves the PICTURE under a fixed viewport, so the crop rect
|
|
173
|
+
// moves the opposite way, scaled from CSS pixels to source pixels.
|
|
174
|
+
const scale = crop.width / viewWidth;
|
|
175
|
+
const panned = clampPan(prev.panX - deltaX * scale, prev.panY - deltaY * scale, prev.zoom, prev.quarterTurns);
|
|
176
|
+
return { ...prev, ...panned };
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
const endDrag = (event) => {
|
|
180
|
+
if (dragRef.current?.pointerId !== event.pointerId)
|
|
181
|
+
return;
|
|
182
|
+
dragRef.current = null;
|
|
183
|
+
setIsDragging(false);
|
|
184
|
+
};
|
|
185
|
+
return (_jsxs(Box, { children: [loadError && (_jsx(Alert, { severity: "error", sx: { mb: 2 }, children: loadError })), _jsxs(Box, { sx: {
|
|
186
|
+
mb: 1.5,
|
|
187
|
+
maxWidth: 480,
|
|
188
|
+
borderRadius: 1,
|
|
189
|
+
overflow: 'hidden',
|
|
190
|
+
border: 1,
|
|
191
|
+
borderColor: 'divider',
|
|
192
|
+
position: 'relative',
|
|
193
|
+
bgcolor: 'action.hover',
|
|
194
|
+
}, children: [_jsx("canvas", { ref: canvasRef, width: PREVIEW_WIDTH, height: PREVIEW_HEIGHT, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: endDrag, onPointerCancel: endDrag, "aria-label": `Adjust the crop of the ${side} photo`, "data-testid": `card-${side}-adjuster`, style: {
|
|
195
|
+
display: 'block',
|
|
196
|
+
width: '100%',
|
|
197
|
+
height: 'auto',
|
|
198
|
+
aspectRatio: String(CARD_ASPECT_RATIO),
|
|
199
|
+
// Without this, a touch drag scrolls the page instead of panning.
|
|
200
|
+
touchAction: 'none',
|
|
201
|
+
cursor: isDragging ? 'grabbing' : 'grab',
|
|
202
|
+
} }), !image && !loadError && (_jsx(Box, { sx: {
|
|
203
|
+
position: 'absolute',
|
|
204
|
+
inset: 0,
|
|
205
|
+
display: 'flex',
|
|
206
|
+
alignItems: 'center',
|
|
207
|
+
justifyContent: 'center',
|
|
208
|
+
}, children: _jsx(CircularProgress, { size: 28 }) }))] }), _jsxs(Box, { sx: { maxWidth: 480 }, children: [_jsx(Box, { sx: { mb: 1.5, typography: 'body2', color: 'text.secondary' }, children: "Zoom and drag until the card fills the frame \u2014 this crop is what gets stored with the card. Rotate if the card is on its side or upside down." }), _jsxs(Stack, { direction: "row", spacing: 2, sx: {
|
|
209
|
+
alignItems: "center",
|
|
210
|
+
mb: 2
|
|
211
|
+
}, children: [_jsx(ZoomOutIcon, { fontSize: "small", color: "action" }), _jsx(Slider, { value: adjust.zoom, min: 1, max: CARD_IMAGE_MAX_ZOOM, step: 0.05, onChange: (_event, value) => {
|
|
212
|
+
if (typeof value === 'number')
|
|
213
|
+
handleZoom(value);
|
|
214
|
+
}, disabled: isProcessing || !image, "aria-label": "Zoom", valueLabelDisplay: "auto", valueLabelFormat: (value) => `${value.toFixed(1)}x` }), _jsx(ZoomInIcon, { fontSize: "small", color: "action" }), _jsx(Button, { startIcon: _jsx(RotateIcon, {}), onClick: handleRotate, disabled: isProcessing || !image, sx: { flexShrink: 0 }, children: "Rotate" })] }), _jsxs(Box, { sx: { display: 'flex', flexWrap: 'wrap', gap: 1 }, children: [_jsx(Button, { variant: "contained", startIcon: isProcessing ? _jsx(CircularProgress, { size: 16, color: "inherit" }) : _jsx(ConfirmIcon, {}), onClick: () => onConfirm(adjust), disabled: isProcessing || !image, children: isProcessing ? 'Cropping…' : confirmLabel }), _jsx(Button, { variant: "outlined", startIcon: _jsx(RetakeIcon, {}), onClick: onRetake, disabled: isProcessing, children: retakeLabel })] })] })] }));
|
|
215
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CardCropBox } from '../../../core/headless/types.js';
|
|
2
|
+
import { type CardAdjustments, type CroppedCardImage } from '../../headless/cardImage.js';
|
|
3
|
+
/**
|
|
4
|
+
* The state of one side's stored-attachment crop, owned by the page.
|
|
5
|
+
*
|
|
6
|
+
* `box` is the AI's location of the card (null when the extraction returned
|
|
7
|
+
* none and the centred auto-fit was used); `adjustments` is the user's manual
|
|
8
|
+
* override, once they have made one. Whichever exists seeds the adjuster, the
|
|
9
|
+
* override taking precedence.
|
|
10
|
+
*/
|
|
11
|
+
export interface CardSideCrop {
|
|
12
|
+
image: CroppedCardImage;
|
|
13
|
+
box: CardCropBox | null;
|
|
14
|
+
adjustments: CardAdjustments | null;
|
|
15
|
+
}
|
|
16
|
+
export interface CardCropReviewSide {
|
|
17
|
+
side: 'front' | 'back';
|
|
18
|
+
/** The raw full capture the crop is rendered from. Never uploaded itself. */
|
|
19
|
+
file: File;
|
|
20
|
+
/** Null when the initial render failed; the adjuster can still create one. */
|
|
21
|
+
crop: CardSideCrop | null;
|
|
22
|
+
}
|
|
23
|
+
interface CardCropReviewProps {
|
|
24
|
+
sides: CardCropReviewSide[];
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Summary mode, for the Review step: small read-only thumbnails of what will
|
|
28
|
+
* be stored and one "Change crop" action (calls `onEdit`, which takes the
|
|
29
|
+
* wizard back to its Crop step). No adjuster opens in this mode.
|
|
30
|
+
*/
|
|
31
|
+
compact?: boolean;
|
|
32
|
+
onEdit?: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* A new crop was confirmed in the adjuster and rendered. The caller replaces
|
|
35
|
+
* its stored image (revoking the old preview URL) and remembers the
|
|
36
|
+
* adjustments so reopening the adjuster resumes from them.
|
|
37
|
+
*/
|
|
38
|
+
onCropChange: (side: 'front' | 'back', image: CroppedCardImage, adjustments: CardAdjustments) => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Review-step gallery of the cropped card photos that will be stored, each
|
|
42
|
+
* with an "Adjust crop" override.
|
|
43
|
+
*
|
|
44
|
+
* The initial crops come from the AI's bounding boxes (or the centred
|
|
45
|
+
* auto-fit fallback); this component reopens {@link CardCropAdjuster} on the
|
|
46
|
+
* raw capture, seeded from that box or from the user's last adjustment, and
|
|
47
|
+
* re-renders the attachment file on confirm — so what is uploaded on save is
|
|
48
|
+
* always exactly what is previewed here.
|
|
49
|
+
*/
|
|
50
|
+
export declare function CardCropReview({ sides, disabled, compact, onEdit, onCropChange, }: CardCropReviewProps): import("react").JSX.Element | null;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Alert, Box, Button, Typography } from '@mui/material';
|
|
4
|
+
import { Crop as CropIcon } from '@mui/icons-material';
|
|
5
|
+
import { CARD_ASPECT_RATIO, cropImageFileToCard, } from '../../headless/cardImage.js';
|
|
6
|
+
import { CardCropAdjuster } from './CardCropAdjuster.js';
|
|
7
|
+
/**
|
|
8
|
+
* Review-step gallery of the cropped card photos that will be stored, each
|
|
9
|
+
* with an "Adjust crop" override.
|
|
10
|
+
*
|
|
11
|
+
* The initial crops come from the AI's bounding boxes (or the centred
|
|
12
|
+
* auto-fit fallback); this component reopens {@link CardCropAdjuster} on the
|
|
13
|
+
* raw capture, seeded from that box or from the user's last adjustment, and
|
|
14
|
+
* re-renders the attachment file on confirm — so what is uploaded on save is
|
|
15
|
+
* always exactly what is previewed here.
|
|
16
|
+
*/
|
|
17
|
+
export function CardCropReview({ sides, disabled = false, compact = false, onEdit, onCropChange, }) {
|
|
18
|
+
const [adjustingSide, setAdjustingSide] = useState(null);
|
|
19
|
+
const [isRendering, setIsRendering] = useState(false);
|
|
20
|
+
const [renderError, setRenderError] = useState(null);
|
|
21
|
+
if (sides.length === 0)
|
|
22
|
+
return null;
|
|
23
|
+
if (compact) {
|
|
24
|
+
return (_jsxs(Box, { sx: {
|
|
25
|
+
mb: 3,
|
|
26
|
+
p: 1.5,
|
|
27
|
+
display: 'flex',
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
gap: 1.5,
|
|
30
|
+
flexWrap: 'wrap',
|
|
31
|
+
borderRadius: 1,
|
|
32
|
+
border: 1,
|
|
33
|
+
borderColor: 'divider',
|
|
34
|
+
bgcolor: 'action.hover',
|
|
35
|
+
}, children: [_jsx(Box, { sx: { display: 'flex', gap: 1 }, children: sides.map((entry) => entry.crop ? (_jsx(Box, { component: "img", src: entry.crop.image.previewUrl, alt: `Cropped ${entry.side} of the card`, sx: {
|
|
36
|
+
display: 'block',
|
|
37
|
+
width: 88,
|
|
38
|
+
aspectRatio: String(CARD_ASPECT_RATIO),
|
|
39
|
+
objectFit: 'cover',
|
|
40
|
+
borderRadius: 1,
|
|
41
|
+
border: 1,
|
|
42
|
+
borderColor: 'divider',
|
|
43
|
+
} }, entry.side)) : null) }), _jsxs(Box, { sx: { flex: '1 1 160px', minWidth: 0 }, children: [_jsx(Typography, { variant: "body2", sx: { fontWeight: 600 }, children: sides.length === 2 ? 'Front and back photos' : `${sides[0].side === 'front' ? 'Front' : 'Back'} photo` }), _jsx(Typography, { variant: "caption", sx: { color: 'text.secondary', display: 'block' }, children: "Only these crops are stored with the card." })] }), onEdit && (_jsx(Button, { size: "small", startIcon: _jsx(CropIcon, {}), onClick: onEdit, disabled: disabled, children: "Change crop" }))] }));
|
|
44
|
+
}
|
|
45
|
+
const adjusting = sides.find((entry) => entry.side === adjustingSide) ?? null;
|
|
46
|
+
const applyAdjustments = async (entry, adjustments) => {
|
|
47
|
+
setIsRendering(true);
|
|
48
|
+
setRenderError(null);
|
|
49
|
+
try {
|
|
50
|
+
const image = await cropImageFileToCard(entry.file, {
|
|
51
|
+
fileName: `card-${entry.side}.jpg`,
|
|
52
|
+
...adjustments,
|
|
53
|
+
});
|
|
54
|
+
onCropChange(entry.side, image, adjustments);
|
|
55
|
+
setAdjustingSide(null);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
setRenderError(err instanceof Error ? err.message : 'That crop could not be applied.');
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
setIsRendering(false);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return (_jsxs(Box, { sx: { mb: 3 }, children: [_jsx(Typography, { variant: "body2", sx: {
|
|
65
|
+
color: "text.secondary",
|
|
66
|
+
mb: 1.5
|
|
67
|
+
}, children: "These crops are what gets saved with the card \u2014 the full photos are never stored. Adjust a crop if the card was not framed right." }), renderError && (_jsx(Alert, { severity: "error", sx: { mb: 2 }, children: renderError })), _jsx(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap' }, children: sides.map((entry) => (_jsxs(Box, { sx: { width: { xs: '100%', sm: 280 } }, children: [_jsx(Typography, { variant: "caption", sx: {
|
|
68
|
+
color: "text.secondary"
|
|
69
|
+
}, children: entry.side === 'front' ? 'Front' : 'Back' }), entry.crop ? (_jsx(Box, { sx: {
|
|
70
|
+
borderRadius: 1,
|
|
71
|
+
overflow: 'hidden',
|
|
72
|
+
border: 1,
|
|
73
|
+
borderColor: 'divider',
|
|
74
|
+
}, children: _jsx(Box, { component: "img", src: entry.crop.image.previewUrl, alt: `Cropped ${entry.side} of the card`, sx: { display: 'block', width: '100%', height: 'auto' } }) })) : (_jsx(Box, { sx: {
|
|
75
|
+
aspectRatio: String(CARD_ASPECT_RATIO),
|
|
76
|
+
border: 1,
|
|
77
|
+
borderStyle: 'dashed',
|
|
78
|
+
borderColor: 'divider',
|
|
79
|
+
borderRadius: 1,
|
|
80
|
+
display: 'flex',
|
|
81
|
+
alignItems: 'center',
|
|
82
|
+
justifyContent: 'center',
|
|
83
|
+
color: 'text.disabled',
|
|
84
|
+
}, children: _jsx(Typography, { variant: "body2", children: "No crop yet" }) })), _jsx(Button, { size: "small", startIcon: _jsx(CropIcon, {}), onClick: () => {
|
|
85
|
+
setRenderError(null);
|
|
86
|
+
setAdjustingSide(entry.side);
|
|
87
|
+
}, disabled: disabled || isRendering, sx: { mt: 0.5 }, children: "Adjust crop" })] }, entry.side))) }), adjusting && (_jsx(Box, { sx: { mt: 2 }, children: _jsx(CardCropAdjuster, { file: adjusting.file, side: adjusting.side, isProcessing: isRendering, initialAdjustments: adjusting.crop?.adjustments ?? undefined, initialBox: adjusting.crop?.box ?? undefined, confirmLabel: "Apply crop", retakeLabel: "Cancel", onConfirm: (adjustments) => void applyAdjustments(adjusting, adjustments), onRetake: () => setAdjustingSide(null) }) }))] }));
|
|
88
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type CardExpiryStatus } from '../../headless/cardExpiry.js';
|
|
2
|
+
interface CardExpiryBadgeProps {
|
|
3
|
+
status: CardExpiryStatus;
|
|
4
|
+
/** `MM/YY`, appended to the accessible label when known. */
|
|
5
|
+
expiryLabel?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function CardExpiryBadge({ status, expiryLabel }: CardExpiryBadgeProps): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Chip, Tooltip } from '@mui/material';
|
|
3
|
+
import { ErrorOutlineOutlined as ExpiredIcon, WarningAmber as ExpiringIcon, CheckCircleOutlineOutlined as ValidIcon, HelpOutlineOutlined as UnknownIcon, } from '@mui/icons-material';
|
|
4
|
+
import { EXPIRING_SOON_DAYS } from '../../headless/cardExpiry.js';
|
|
5
|
+
const PRESENTATION = {
|
|
6
|
+
expired: {
|
|
7
|
+
label: 'Expired',
|
|
8
|
+
icon: _jsx(ExpiredIcon, { fontSize: "small" }),
|
|
9
|
+
color: 'error',
|
|
10
|
+
variant: 'filled',
|
|
11
|
+
tooltip: 'This card has passed its expiry date.',
|
|
12
|
+
},
|
|
13
|
+
expiring_soon: {
|
|
14
|
+
label: 'Expires soon',
|
|
15
|
+
icon: _jsx(ExpiringIcon, { fontSize: "small" }),
|
|
16
|
+
color: 'secondary',
|
|
17
|
+
variant: 'filled',
|
|
18
|
+
tooltip: `This card expires within ${EXPIRING_SOON_DAYS} days.`,
|
|
19
|
+
},
|
|
20
|
+
valid: {
|
|
21
|
+
label: 'Valid',
|
|
22
|
+
icon: _jsx(ValidIcon, { fontSize: "small" }),
|
|
23
|
+
color: 'success',
|
|
24
|
+
variant: 'outlined',
|
|
25
|
+
tooltip: 'This card is valid.',
|
|
26
|
+
},
|
|
27
|
+
unknown: {
|
|
28
|
+
label: 'Unknown expiry',
|
|
29
|
+
icon: _jsx(UnknownIcon, { fontSize: "small" }),
|
|
30
|
+
color: 'default',
|
|
31
|
+
variant: 'outlined',
|
|
32
|
+
tooltip: 'No usable expiry date is stored for this card.',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
export function CardExpiryBadge({ status, expiryLabel }) {
|
|
36
|
+
const presentation = PRESENTATION[status] ?? PRESENTATION.unknown;
|
|
37
|
+
// Screen readers get the date alongside the status, which sighted users read
|
|
38
|
+
// from the adjacent expiry field.
|
|
39
|
+
const accessibleLabel = expiryLabel
|
|
40
|
+
? `${presentation.label}, expiry ${expiryLabel}`
|
|
41
|
+
: presentation.label;
|
|
42
|
+
return (_jsx(Tooltip, { title: presentation.tooltip, children: _jsx(Chip, { icon: presentation.icon, label: presentation.label, color: presentation.color, size: "small", variant: presentation.variant, "aria-label": accessibleLabel, "data-status": status, sx: { fontWeight: 600 } }) }));
|
|
43
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { FieldDefinition } from '../../../core/headless/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Render a value for the comparison line.
|
|
4
|
+
*
|
|
5
|
+
* Sensitive values are reduced to their last few characters. The editable field
|
|
6
|
+
* above this line already has a reveal toggle for the NEW value, so the user can
|
|
7
|
+
* see in full whatever they are about to save; the OLD value has no such toggle
|
|
8
|
+
* and no reason for one — "is this the card ending 4242?" is the entire question
|
|
9
|
+
* the old value has to answer, and printing a full PAN to answer it would put a
|
|
10
|
+
* live card number on screen that nobody asked to see.
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatDiffValue(value: string, sensitive: boolean): string;
|
|
13
|
+
interface CardFieldDiffProps {
|
|
14
|
+
field: FieldDefinition;
|
|
15
|
+
/** The outgoing version's value. */
|
|
16
|
+
current: string;
|
|
17
|
+
/** What is about to be saved. */
|
|
18
|
+
proposed: string;
|
|
19
|
+
changed: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* True for the field that is never carried forward, so the line explains the
|
|
22
|
+
* absence instead of showing a misleading "no current value".
|
|
23
|
+
*/
|
|
24
|
+
notCarriedForward?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One field's before/after, shown beneath its input on the renewal review.
|
|
28
|
+
*
|
|
29
|
+
* This is the step that distinguishes a renewal from an import: the user is not
|
|
30
|
+
* confirming values in a vacuum, they are confirming a CHANGE to a card they
|
|
31
|
+
* already hold, and the thing worth checking is which fields moved. Unchanged
|
|
32
|
+
* fields are stated explicitly rather than hidden — "cardholder stays the same"
|
|
33
|
+
* is information, and a field that silently shows nothing reads as a field that
|
|
34
|
+
* was forgotten.
|
|
35
|
+
*/
|
|
36
|
+
export declare function CardFieldDiff({ field, current, proposed, changed, notCarriedForward, }: CardFieldDiffProps): import("react").JSX.Element;
|
|
37
|
+
export {};
|