@portnet/ui 6.0.1 → 6.0.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 +737 -0
- package/dist/esm/index.js +90 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/v2/__tests__/AppMain.test.js +130 -0
- package/dist/esm/v2/__tests__/AppMain.test.js.map +1 -0
- package/dist/esm/v2/__tests__/ChartFigure.test.js +180 -0
- package/dist/esm/v2/__tests__/ChartFigure.test.js.map +1 -0
- package/dist/esm/v2/__tests__/DataGridRowActionsPropagation.test.js +150 -0
- package/dist/esm/v2/__tests__/DataGridRowActionsPropagation.test.js.map +1 -0
- package/dist/esm/v2/__tests__/DrawerTactileTargets.test.js +93 -0
- package/dist/esm/v2/__tests__/DrawerTactileTargets.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FieldError.test.js +71 -39
- package/dist/esm/v2/__tests__/FieldError.test.js.map +1 -1
- package/dist/esm/v2/__tests__/FieldNaming.test.js +160 -0
- package/dist/esm/v2/__tests__/FieldNaming.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FieldWidth.test.js +146 -0
- package/dist/esm/v2/__tests__/FieldWidth.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FileCard.test.js +18 -18
- package/dist/esm/v2/__tests__/FileCard.test.js.map +1 -1
- package/dist/esm/v2/__tests__/FormikCheckbox.test.js +173 -0
- package/dist/esm/v2/__tests__/FormikCheckbox.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FormikDateTimePicker.test.js +236 -0
- package/dist/esm/v2/__tests__/FormikDateTimePicker.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FormikDisplayWidth.test.js +101 -0
- package/dist/esm/v2/__tests__/FormikDisplayWidth.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FormikRadioGroup.test.js +299 -0
- package/dist/esm/v2/__tests__/FormikRadioGroup.test.js.map +1 -0
- package/dist/esm/v2/__tests__/MobileRowCard.test.js +44 -43
- package/dist/esm/v2/__tests__/MobileRowCard.test.js.map +1 -1
- package/dist/esm/v2/__tests__/PreviewDrawer.test.js +165 -0
- package/dist/esm/v2/__tests__/PreviewDrawer.test.js.map +1 -0
- package/dist/esm/v2/__tests__/ReferentielFieldContainer.test.js +156 -0
- package/dist/esm/v2/__tests__/ReferentielFieldContainer.test.js.map +1 -0
- package/dist/esm/v2/__tests__/SectionErrorBoundary.test.js +37 -52
- package/dist/esm/v2/__tests__/SectionErrorBoundary.test.js.map +1 -1
- package/dist/esm/v2/__tests__/apiError.test.js +50 -69
- package/dist/esm/v2/__tests__/apiError.test.js.map +1 -1
- package/dist/esm/v2/__tests__/banned-patterns.test.js +41 -122
- package/dist/esm/v2/__tests__/banned-patterns.test.js.map +1 -1
- package/dist/esm/v2/__tests__/chart-palette.test.js +204 -0
- package/dist/esm/v2/__tests__/chart-palette.test.js.map +1 -0
- package/dist/esm/v2/__tests__/contrast-palette.test.js +42 -74
- package/dist/esm/v2/__tests__/contrast-palette.test.js.map +1 -1
- package/dist/esm/v2/__tests__/cssVariables.test.js +44 -51
- package/dist/esm/v2/__tests__/cssVariables.test.js.map +1 -1
- package/dist/esm/v2/__tests__/fileValidation.test.js +134 -0
- package/dist/esm/v2/__tests__/fileValidation.test.js.map +1 -0
- package/dist/esm/v2/__tests__/filterCriteria.test.js +321 -0
- package/dist/esm/v2/__tests__/filterCriteria.test.js.map +1 -0
- package/dist/esm/v2/__tests__/fmtDate.test.js +68 -0
- package/dist/esm/v2/__tests__/fmtDate.test.js.map +1 -0
- package/dist/esm/v2/__tests__/gap-leakage-refonte.test.js +218 -0
- package/dist/esm/v2/__tests__/gap-leakage-refonte.test.js.map +1 -0
- package/dist/esm/v2/__tests__/labels-merge.test.js +17 -22
- package/dist/esm/v2/__tests__/labels-merge.test.js.map +1 -1
- package/dist/esm/v2/__tests__/locale-fallback.test.js +35 -40
- package/dist/esm/v2/__tests__/locale-fallback.test.js.map +1 -1
- package/dist/esm/v2/__tests__/reviveSavedCriteria.test.js +143 -0
- package/dist/esm/v2/__tests__/reviveSavedCriteria.test.js.map +1 -0
- package/dist/esm/v2/__tests__/rowActions.test.js +182 -0
- package/dist/esm/v2/__tests__/rowActions.test.js.map +1 -0
- package/dist/esm/v2/__tests__/useFocusOnRouteChange.test.js +155 -0
- package/dist/esm/v2/__tests__/useFocusOnRouteChange.test.js.map +1 -0
- package/dist/esm/v2/__tests__/useFocusTrap.test.js +266 -402
- package/dist/esm/v2/__tests__/useFocusTrap.test.js.map +1 -1
- package/dist/esm/v2/__tests__/usePrefersReducedMotion.test.js +120 -0
- package/dist/esm/v2/__tests__/usePrefersReducedMotion.test.js.map +1 -0
- package/dist/esm/v2/components/Accordion.js +48 -70
- package/dist/esm/v2/components/Accordion.js.map +1 -1
- package/dist/esm/v2/components/ActionStrip.js +31 -43
- package/dist/esm/v2/components/ActionStrip.js.map +1 -1
- package/dist/esm/v2/components/Banner.js +25 -22
- package/dist/esm/v2/components/Banner.js.map +1 -1
- package/dist/esm/v2/components/Busy.js +14 -19
- package/dist/esm/v2/components/Busy.js.map +1 -1
- package/dist/esm/v2/components/Button.js +34 -45
- package/dist/esm/v2/components/Button.js.map +1 -1
- package/dist/esm/v2/components/CategoryTag.js +44 -27
- package/dist/esm/v2/components/CategoryTag.js.map +1 -1
- package/dist/esm/v2/components/Checkbox.js +32 -38
- package/dist/esm/v2/components/Checkbox.js.map +1 -1
- package/dist/esm/v2/components/Chip.js +23 -36
- package/dist/esm/v2/components/Chip.js.map +1 -1
- package/dist/esm/v2/components/Combobox.js +112 -136
- package/dist/esm/v2/components/Combobox.js.map +1 -1
- package/dist/esm/v2/components/CommandPalette.js +113 -198
- package/dist/esm/v2/components/CommandPalette.js.map +1 -1
- package/dist/esm/v2/components/ConfirmDialog.js +36 -45
- package/dist/esm/v2/components/ConfirmDialog.js.map +1 -1
- package/dist/esm/v2/components/DatePicker.js +78 -81
- package/dist/esm/v2/components/DatePicker.js.map +1 -1
- package/dist/esm/v2/components/DateRangePicker.js +63 -74
- package/dist/esm/v2/components/DateRangePicker.js.map +1 -1
- package/dist/esm/v2/components/DateTimePicker.js +118 -90
- package/dist/esm/v2/components/DateTimePicker.js.map +1 -1
- package/dist/esm/v2/components/Drawer.js +71 -65
- package/dist/esm/v2/components/Drawer.js.map +1 -1
- package/dist/esm/v2/components/Dropzone.js +130 -177
- package/dist/esm/v2/components/Dropzone.js.map +1 -1
- package/dist/esm/v2/components/EmptyState.js +9 -9
- package/dist/esm/v2/components/EmptyState.js.map +1 -1
- package/dist/esm/v2/components/FavoriteToggle.js +24 -33
- package/dist/esm/v2/components/FavoriteToggle.js.map +1 -1
- package/dist/esm/v2/components/Field.js +210 -52
- package/dist/esm/v2/components/Field.js.map +1 -1
- package/dist/esm/v2/components/FieldError.js +9 -13
- package/dist/esm/v2/components/FieldError.js.map +1 -1
- package/dist/esm/v2/components/FieldHelp.js +28 -49
- package/dist/esm/v2/components/FieldHelp.js.map +1 -1
- package/dist/esm/v2/components/FileCard.js +14 -19
- package/dist/esm/v2/components/FileCard.js.map +1 -1
- package/dist/esm/v2/components/FilterTab.js +22 -31
- package/dist/esm/v2/components/FilterTab.js.map +1 -1
- package/dist/esm/v2/components/ForbiddenPage.js +28 -8
- package/dist/esm/v2/components/ForbiddenPage.js.map +1 -1
- package/dist/esm/v2/components/FormGrid.js +48 -54
- package/dist/esm/v2/components/FormGrid.js.map +1 -1
- package/dist/esm/v2/components/FormikDisplay.js +98 -24
- package/dist/esm/v2/components/FormikDisplay.js.map +1 -1
- package/dist/esm/v2/components/Input.js +75 -34
- package/dist/esm/v2/components/Input.js.map +1 -1
- package/dist/esm/v2/components/KPICard.js +42 -51
- package/dist/esm/v2/components/KPICard.js.map +1 -1
- package/dist/esm/v2/components/KPIStrip.js +9 -15
- package/dist/esm/v2/components/KPIStrip.js.map +1 -1
- package/dist/esm/v2/components/KV.js +16 -23
- package/dist/esm/v2/components/KV.js.map +1 -1
- package/dist/esm/v2/components/KVGrid.js +15 -23
- package/dist/esm/v2/components/KVGrid.js.map +1 -1
- package/dist/esm/v2/components/Layout.js +81 -117
- package/dist/esm/v2/components/Layout.js.map +1 -1
- package/dist/esm/v2/components/MobileRowCard.js +64 -75
- package/dist/esm/v2/components/MobileRowCard.js.map +1 -1
- package/dist/esm/v2/components/Modal.js +44 -53
- package/dist/esm/v2/components/Modal.js.map +1 -1
- package/dist/esm/v2/components/NetworkErrorPage.js +28 -11
- package/dist/esm/v2/components/NetworkErrorPage.js.map +1 -1
- package/dist/esm/v2/components/NotFoundPage.js +28 -9
- package/dist/esm/v2/components/NotFoundPage.js.map +1 -1
- package/dist/esm/v2/components/NumberInput.js +77 -107
- package/dist/esm/v2/components/NumberInput.js.map +1 -1
- package/dist/esm/v2/components/OverflowMenu.js +24 -42
- package/dist/esm/v2/components/OverflowMenu.js.map +1 -1
- package/dist/esm/v2/components/PdfViewer.js +24 -33
- package/dist/esm/v2/components/PdfViewer.js.map +1 -1
- package/dist/esm/v2/components/ProgressBar.js +28 -36
- package/dist/esm/v2/components/ProgressBar.js.map +1 -1
- package/dist/esm/v2/components/Radio.js +49 -57
- package/dist/esm/v2/components/Radio.js.map +1 -1
- package/dist/esm/v2/components/SectionErrorBoundary.js +84 -130
- package/dist/esm/v2/components/SectionErrorBoundary.js.map +1 -1
- package/dist/esm/v2/components/SectionHeader.js +24 -31
- package/dist/esm/v2/components/SectionHeader.js.map +1 -1
- package/dist/esm/v2/components/Segmented.js +59 -84
- package/dist/esm/v2/components/Segmented.js.map +1 -1
- package/dist/esm/v2/components/Select.js +100 -138
- package/dist/esm/v2/components/Select.js.map +1 -1
- package/dist/esm/v2/components/ServerErrorPage.js +27 -10
- package/dist/esm/v2/components/ServerErrorPage.js.map +1 -1
- package/dist/esm/v2/components/Skeleton.js +81 -96
- package/dist/esm/v2/components/Skeleton.js.map +1 -1
- package/dist/esm/v2/components/SkipLink.js +6 -7
- package/dist/esm/v2/components/SkipLink.js.map +1 -1
- package/dist/esm/v2/components/Spinner.js +13 -22
- package/dist/esm/v2/components/Spinner.js.map +1 -1
- package/dist/esm/v2/components/Status.js +14 -25
- package/dist/esm/v2/components/Status.js.map +1 -1
- package/dist/esm/v2/components/Stepper.js +68 -71
- package/dist/esm/v2/components/Stepper.js.map +1 -1
- package/dist/esm/v2/components/Surface.js +25 -44
- package/dist/esm/v2/components/Surface.js.map +1 -1
- package/dist/esm/v2/components/Switch.js +21 -29
- package/dist/esm/v2/components/Switch.js.map +1 -1
- package/dist/esm/v2/components/TabPanel.js +84 -0
- package/dist/esm/v2/components/TabPanel.js.map +1 -0
- package/dist/esm/v2/components/Tabs.js +43 -19
- package/dist/esm/v2/components/Tabs.js.map +1 -1
- package/dist/esm/v2/components/TelInput.js +75 -108
- package/dist/esm/v2/components/TelInput.js.map +1 -1
- package/dist/esm/v2/components/Textarea.js +21 -30
- package/dist/esm/v2/components/Textarea.js.map +1 -1
- package/dist/esm/v2/components/TimePicker.js +59 -69
- package/dist/esm/v2/components/TimePicker.js.map +1 -1
- package/dist/esm/v2/components/Toast.js +109 -163
- package/dist/esm/v2/components/Toast.js.map +1 -1
- package/dist/esm/v2/components/Tooltip.js +18 -31
- package/dist/esm/v2/components/Tooltip.js.map +1 -1
- package/dist/esm/v2/components/_ErrorPageBody.js +6 -5
- package/dist/esm/v2/components/_ErrorPageBody.js.map +1 -1
- package/dist/esm/v2/components/_pickerShared.js +2 -2
- package/dist/esm/v2/components/_pickerShared.js.map +1 -1
- package/dist/esm/v2/components/index.js +64 -0
- package/dist/esm/v2/components/index.js.map +1 -1
- package/dist/esm/v2/hooks/index.js +62 -0
- package/dist/esm/v2/hooks/index.js.map +1 -1
- package/dist/esm/v2/hooks/useAppliedFilters.js +112 -0
- package/dist/esm/v2/hooks/useAppliedFilters.js.map +1 -0
- package/dist/esm/v2/hooks/useDebouncedCallback.js +82 -0
- package/dist/esm/v2/hooks/useDebouncedCallback.js.map +1 -0
- package/dist/esm/v2/hooks/useDelayedFlag.js +5 -19
- package/dist/esm/v2/hooks/useDelayedFlag.js.map +1 -1
- package/dist/esm/v2/hooks/useDensity.js +13 -17
- package/dist/esm/v2/hooks/useDensity.js.map +1 -1
- package/dist/esm/v2/hooks/useFocusFirstError.js +25 -33
- package/dist/esm/v2/hooks/useFocusFirstError.js.map +1 -1
- package/dist/esm/v2/hooks/useFocusOnRouteChange.js +81 -0
- package/dist/esm/v2/hooks/useFocusOnRouteChange.js.map +1 -0
- package/dist/esm/v2/hooks/useFocusTrap.js +19 -23
- package/dist/esm/v2/hooks/useFocusTrap.js.map +1 -1
- package/dist/esm/v2/hooks/useFormAutoSave.js +38 -53
- package/dist/esm/v2/hooks/useFormAutoSave.js.map +1 -1
- package/dist/esm/v2/hooks/useFormCompletionProgress.js +32 -51
- package/dist/esm/v2/hooks/useFormCompletionProgress.js.map +1 -1
- package/dist/esm/v2/hooks/useKeyboardShortcuts.js +125 -0
- package/dist/esm/v2/hooks/useKeyboardShortcuts.js.map +1 -0
- package/dist/esm/v2/hooks/usePrefersReducedMotion.js +99 -0
- package/dist/esm/v2/hooks/usePrefersReducedMotion.js.map +1 -0
- package/dist/esm/v2/hooks/useResolvedDensity.js +2 -10
- package/dist/esm/v2/hooks/useResolvedDensity.js.map +1 -1
- package/dist/esm/v2/hooks/useSortedRows.js +3 -5
- package/dist/esm/v2/hooks/useSortedRows.js.map +1 -1
- package/dist/esm/v2/hooks/useTabLoading.js +6 -21
- package/dist/esm/v2/hooks/useTabLoading.js.map +1 -1
- package/dist/esm/v2/index.js +14 -4
- package/dist/esm/v2/index.js.map +1 -1
- package/dist/esm/v2/modalContext.js +2 -2
- package/dist/esm/v2/modalContext.js.map +1 -1
- package/dist/esm/v2/models/favorite.js.map +1 -1
- package/dist/esm/v2/models/personalization.js.map +1 -1
- package/dist/esm/v2/models/referentiel.js.map +1 -1
- package/dist/esm/v2/models/savedFilter.js.map +1 -1
- package/dist/esm/v2/patterns/ActionBar.js +115 -159
- package/dist/esm/v2/patterns/ActionBar.js.map +1 -1
- package/dist/esm/v2/patterns/AppMain.js +108 -0
- package/dist/esm/v2/patterns/AppMain.js.map +1 -0
- package/dist/esm/v2/patterns/BulkActionBar.js +31 -34
- package/dist/esm/v2/patterns/BulkActionBar.js.map +1 -1
- package/dist/esm/v2/patterns/ChartFigure.js +151 -0
- package/dist/esm/v2/patterns/ChartFigure.js.map +1 -0
- package/dist/esm/v2/patterns/CollapsibleDataGrid.js +111 -152
- package/dist/esm/v2/patterns/CollapsibleDataGrid.js.map +1 -1
- package/dist/esm/v2/patterns/ColumnsToggle.js +43 -77
- package/dist/esm/v2/patterns/ColumnsToggle.js.map +1 -1
- package/dist/esm/v2/patterns/DataGrid.js +221 -255
- package/dist/esm/v2/patterns/DataGrid.js.map +1 -1
- package/dist/esm/v2/patterns/DataGridSettingsMenu.js +76 -94
- package/dist/esm/v2/patterns/DataGridSettingsMenu.js.map +1 -1
- package/dist/esm/v2/patterns/DataGridToolbar.js +85 -89
- package/dist/esm/v2/patterns/DataGridToolbar.js.map +1 -1
- package/dist/esm/v2/patterns/DataGridVirtualized.js +141 -182
- package/dist/esm/v2/patterns/DataGridVirtualized.js.map +1 -1
- package/dist/esm/v2/patterns/DeleteResourceConfirmDialog.js +26 -30
- package/dist/esm/v2/patterns/DeleteResourceConfirmDialog.js.map +1 -1
- package/dist/esm/v2/patterns/DetailSplit.js +108 -0
- package/dist/esm/v2/patterns/DetailSplit.js.map +1 -0
- package/dist/esm/v2/patterns/FavoriteColumn.js +26 -75
- package/dist/esm/v2/patterns/FavoriteColumn.js.map +1 -1
- package/dist/esm/v2/patterns/FavoritesFilter.js +30 -39
- package/dist/esm/v2/patterns/FavoritesFilter.js.map +1 -1
- package/dist/esm/v2/patterns/FilterTabBar.js +112 -0
- package/dist/esm/v2/patterns/FilterTabBar.js.map +1 -0
- package/dist/esm/v2/patterns/FormErrorSummary.js +12 -13
- package/dist/esm/v2/patterns/FormErrorSummary.js.map +1 -1
- package/dist/esm/v2/patterns/FormPageShell.js +43 -41
- package/dist/esm/v2/patterns/FormPageShell.js.map +1 -1
- package/dist/esm/v2/patterns/FormSection.js +30 -38
- package/dist/esm/v2/patterns/FormSection.js.map +1 -1
- package/dist/esm/v2/patterns/FormikCheckbox.js +130 -0
- package/dist/esm/v2/patterns/FormikCheckbox.js.map +1 -0
- package/dist/esm/v2/patterns/FormikCheckboxGroup.js +56 -60
- package/dist/esm/v2/patterns/FormikCheckboxGroup.js.map +1 -1
- package/dist/esm/v2/patterns/FormikCombobox.js +51 -66
- package/dist/esm/v2/patterns/FormikCombobox.js.map +1 -1
- package/dist/esm/v2/patterns/FormikDatePicker.js +51 -99
- package/dist/esm/v2/patterns/FormikDatePicker.js.map +1 -1
- package/dist/esm/v2/patterns/FormikDateTimePicker.js +136 -0
- package/dist/esm/v2/patterns/FormikDateTimePicker.js.map +1 -0
- package/dist/esm/v2/patterns/FormikErrorFocus.js +22 -23
- package/dist/esm/v2/patterns/FormikErrorFocus.js.map +1 -1
- package/dist/esm/v2/patterns/FormikErrorSummary.js +89 -0
- package/dist/esm/v2/patterns/FormikErrorSummary.js.map +1 -0
- package/dist/esm/v2/patterns/FormikFile.js +94 -78
- package/dist/esm/v2/patterns/FormikFile.js.map +1 -1
- package/dist/esm/v2/patterns/FormikInput.js +40 -50
- package/dist/esm/v2/patterns/FormikInput.js.map +1 -1
- package/dist/esm/v2/patterns/FormikRadioGroup.js +129 -0
- package/dist/esm/v2/patterns/FormikRadioGroup.js.map +1 -0
- package/dist/esm/v2/patterns/FormikReferentielField.js +49 -59
- package/dist/esm/v2/patterns/FormikReferentielField.js.map +1 -1
- package/dist/esm/v2/patterns/FormikSelect.js +64 -84
- package/dist/esm/v2/patterns/FormikSelect.js.map +1 -1
- package/dist/esm/v2/patterns/FormikTextarea.js +30 -43
- package/dist/esm/v2/patterns/FormikTextarea.js.map +1 -1
- package/dist/esm/v2/patterns/KeyboardShortcutsHelp.js +64 -65
- package/dist/esm/v2/patterns/KeyboardShortcutsHelp.js.map +1 -1
- package/dist/esm/v2/patterns/NetworkErrorBanner.js +6 -7
- package/dist/esm/v2/patterns/NetworkErrorBanner.js.map +1 -1
- package/dist/esm/v2/patterns/PageContent.js +10 -14
- package/dist/esm/v2/patterns/PageContent.js.map +1 -1
- package/dist/esm/v2/patterns/PreviewDrawer.js +153 -0
- package/dist/esm/v2/patterns/PreviewDrawer.js.map +1 -0
- package/dist/esm/v2/patterns/ReferentielField.js +327 -312
- package/dist/esm/v2/patterns/ReferentielField.js.map +1 -1
- package/dist/esm/v2/patterns/RowFavoriteToggle.js +127 -0
- package/dist/esm/v2/patterns/RowFavoriteToggle.js.map +1 -0
- package/dist/esm/v2/patterns/SaveFilterDialog.js +38 -66
- package/dist/esm/v2/patterns/SaveFilterDialog.js.map +1 -1
- package/dist/esm/v2/patterns/SavedFiltersMenu.js +62 -81
- package/dist/esm/v2/patterns/SavedFiltersMenu.js.map +1 -1
- package/dist/esm/v2/patterns/SkeletonPageShell.js +106 -129
- package/dist/esm/v2/patterns/SkeletonPageShell.js.map +1 -1
- package/dist/esm/v2/patterns/SortableHeader.js +22 -45
- package/dist/esm/v2/patterns/SortableHeader.js.map +1 -1
- package/dist/esm/v2/patterns/Tour.js +94 -120
- package/dist/esm/v2/patterns/Tour.js.map +1 -1
- package/dist/esm/v2/patterns/_dataGridShared.js +107 -128
- package/dist/esm/v2/patterns/_dataGridShared.js.map +1 -1
- package/dist/esm/v2/patterns/_pickerSerialisation.js +72 -0
- package/dist/esm/v2/patterns/_pickerSerialisation.js.map +1 -0
- package/dist/esm/v2/patterns/_sort.js +17 -33
- package/dist/esm/v2/patterns/_sort.js.map +1 -1
- package/dist/esm/v2/patterns/_useColumnReorder.js +122 -160
- package/dist/esm/v2/patterns/_useColumnReorder.js.map +1 -1
- package/dist/esm/v2/patterns/_useColumnResize.js +78 -96
- package/dist/esm/v2/patterns/_useColumnResize.js.map +1 -1
- package/dist/esm/v2/patterns/filterCriteria.js +102 -0
- package/dist/esm/v2/patterns/filterCriteria.js.map +1 -0
- package/dist/esm/v2/patterns/index.js +235 -0
- package/dist/esm/v2/patterns/index.js.map +1 -1
- package/dist/esm/v2/patterns/rowActions.js +223 -0
- package/dist/esm/v2/patterns/rowActions.js.map +1 -0
- package/dist/esm/v2/personalization/PersonalizationProvider.js +50 -47
- package/dist/esm/v2/personalization/PersonalizationProvider.js.map +1 -1
- package/dist/esm/v2/personalization/adapters/_storageKey.js +5 -5
- package/dist/esm/v2/personalization/adapters/_storageKey.js.map +1 -1
- package/dist/esm/v2/personalization/adapters/createLocalStorageAdapter.js +22 -23
- package/dist/esm/v2/personalization/adapters/createLocalStorageAdapter.js.map +1 -1
- package/dist/esm/v2/personalization/adapters/createMemoryAdapter.js +13 -13
- package/dist/esm/v2/personalization/adapters/createMemoryAdapter.js.map +1 -1
- package/dist/esm/v2/personalization/capabilities/favorites.js +36 -60
- package/dist/esm/v2/personalization/capabilities/favorites.js.map +1 -1
- package/dist/esm/v2/personalization/capabilities/favoritesView.js +22 -34
- package/dist/esm/v2/personalization/capabilities/favoritesView.js.map +1 -1
- package/dist/esm/v2/personalization/capabilities/gridPreferences.js +203 -0
- package/dist/esm/v2/personalization/capabilities/gridPreferences.js.map +1 -0
- package/dist/esm/v2/personalization/capabilities/index.js +5 -0
- package/dist/esm/v2/personalization/capabilities/index.js.map +1 -1
- package/dist/esm/v2/personalization/capabilities/reviveSavedCriteria.js +119 -0
- package/dist/esm/v2/personalization/capabilities/reviveSavedCriteria.js.map +1 -0
- package/dist/esm/v2/personalization/capabilities/savedFilters.js +90 -98
- package/dist/esm/v2/personalization/capabilities/savedFilters.js.map +1 -1
- package/dist/esm/v2/personalization/createPersonalizationStore.js +78 -181
- package/dist/esm/v2/personalization/createPersonalizationStore.js.map +1 -1
- package/dist/esm/v2/personalization/index.js +35 -0
- package/dist/esm/v2/personalization/index.js.map +1 -1
- package/dist/esm/v2/personalization/personalizationContext.js +9 -9
- package/dist/esm/v2/personalization/personalizationContext.js.map +1 -1
- package/dist/esm/v2/personalization/schema.js +8 -9
- package/dist/esm/v2/personalization/schema.js.map +1 -1
- package/dist/esm/v2/referentiel/ReferentielProvider.js +27 -42
- package/dist/esm/v2/referentiel/ReferentielProvider.js.map +1 -1
- package/dist/esm/v2/referentiel/types.js +2 -0
- package/dist/esm/v2/referentiel/types.js.map +1 -0
- package/dist/esm/v2/referentiel/useReferentielClient.js +10 -11
- package/dist/esm/v2/referentiel/useReferentielClient.js.map +1 -1
- package/dist/esm/v2/referentiel/useReferentielOptions.js +60 -117
- package/dist/esm/v2/referentiel/useReferentielOptions.js.map +1 -1
- package/dist/esm/v2/referentiel/useReferentielSearch.js +37 -91
- package/dist/esm/v2/referentiel/useReferentielSearch.js.map +1 -1
- package/dist/esm/v2/theme/_brand.js +8 -24
- package/dist/esm/v2/theme/_brand.js.map +1 -1
- package/dist/esm/v2/theme/_brandSecondary.js +8 -24
- package/dist/esm/v2/theme/_brandSecondary.js.map +1 -1
- package/dist/esm/v2/theme/createPortnetTheme.js +51 -61
- package/dist/esm/v2/theme/createPortnetTheme.js.map +1 -1
- package/dist/esm/v2/theme/cssVariables.js +62 -69
- package/dist/esm/v2/theme/cssVariables.js.map +1 -1
- package/dist/esm/v2/theme/index.js +5 -5
- package/dist/esm/v2/theme/index.js.map +1 -1
- package/dist/esm/v2/tokens/breakpoints.js +14 -14
- package/dist/esm/v2/tokens/breakpoints.js.map +1 -1
- package/dist/esm/v2/tokens/chart.js +261 -0
- package/dist/esm/v2/tokens/chart.js.map +1 -0
- package/dist/esm/v2/tokens/colors.js +22 -22
- package/dist/esm/v2/tokens/colors.js.map +1 -1
- package/dist/esm/v2/tokens/density.js +62 -7
- package/dist/esm/v2/tokens/density.js.map +1 -1
- package/dist/esm/v2/tokens/index.js +49 -34
- package/dist/esm/v2/tokens/index.js.map +1 -1
- package/dist/esm/v2/tokens/motion.js +12 -20
- package/dist/esm/v2/tokens/motion.js.map +1 -1
- package/dist/esm/v2/tokens/radius.js +1 -1
- package/dist/esm/v2/tokens/radius.js.map +1 -1
- package/dist/esm/v2/tokens/shadows.js +6 -6
- package/dist/esm/v2/tokens/shadows.js.map +1 -1
- package/dist/esm/v2/tokens/spacing.js +2 -2
- package/dist/esm/v2/tokens/spacing.js.map +1 -1
- package/dist/esm/v2/tokens/state.js +1 -1
- package/dist/esm/v2/tokens/state.js.map +1 -1
- package/dist/esm/v2/tokens/statusPalette.js +17 -21
- package/dist/esm/v2/tokens/statusPalette.js.map +1 -1
- package/dist/esm/v2/tokens/tokens.json +6 -1
- package/dist/esm/v2/tokens/typography.js +13 -13
- package/dist/esm/v2/tokens/typography.js.map +1 -1
- package/dist/esm/v2/tokens/zIndex.js +1 -1
- package/dist/esm/v2/tokens/zIndex.js.map +1 -1
- package/dist/esm/v2/types/datagrid.js.map +1 -1
- package/dist/esm/v2/utils/apiError.js +16 -37
- package/dist/esm/v2/utils/apiError.js.map +1 -1
- package/dist/esm/v2/utils/contrast.js +31 -32
- package/dist/esm/v2/utils/contrast.js.map +1 -1
- package/dist/esm/v2/utils/cx.js +5 -25
- package/dist/esm/v2/utils/cx.js.map +1 -1
- package/dist/esm/v2/utils/fileDownload.js +23 -26
- package/dist/esm/v2/utils/fileDownload.js.map +1 -1
- package/dist/esm/v2/utils/fileValidation.js +209 -0
- package/dist/esm/v2/utils/fileValidation.js.map +1 -0
- package/dist/esm/v2/utils/fmtDate.js +111 -0
- package/dist/esm/v2/utils/fmtDate.js.map +1 -0
- package/dist/esm/v2/utils/fmtMoney.js +8 -10
- package/dist/esm/v2/utils/fmtMoney.js.map +1 -1
- package/dist/esm/v2/utils/formikErrors.js +78 -0
- package/dist/esm/v2/utils/formikErrors.js.map +1 -0
- package/dist/esm/v2/utils/index.js +35 -2
- package/dist/esm/v2/utils/index.js.map +1 -1
- package/dist/esm/v2/utils/mergeLabels.js +7 -12
- package/dist/esm/v2/utils/mergeLabels.js.map +1 -1
- package/dist/esm/v2/utils/networkStatus.js +12 -12
- package/dist/esm/v2/utils/networkStatus.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -47
- package/dist/index.js.map +1 -1
- package/dist/v2/__tests__/AppMain.test.js +133 -0
- package/dist/v2/__tests__/AppMain.test.js.map +1 -0
- package/dist/v2/__tests__/ChartFigure.test.js +183 -0
- package/dist/v2/__tests__/ChartFigure.test.js.map +1 -0
- package/dist/v2/__tests__/DataGridRowActionsPropagation.test.js +153 -0
- package/dist/v2/__tests__/DataGridRowActionsPropagation.test.js.map +1 -0
- package/dist/v2/__tests__/DrawerTactileTargets.test.js +94 -0
- package/dist/v2/__tests__/DrawerTactileTargets.test.js.map +1 -0
- package/dist/v2/__tests__/FieldError.test.js +98 -69
- package/dist/v2/__tests__/FieldError.test.js.map +1 -1
- package/dist/v2/__tests__/FieldNaming.test.js +161 -0
- package/dist/v2/__tests__/FieldNaming.test.js.map +1 -0
- package/dist/v2/__tests__/FieldWidth.test.js +148 -0
- package/dist/v2/__tests__/FieldWidth.test.js.map +1 -0
- package/dist/v2/__tests__/FileCard.test.js +45 -48
- package/dist/v2/__tests__/FileCard.test.js.map +1 -1
- package/dist/v2/__tests__/FormikCheckbox.test.js +175 -0
- package/dist/v2/__tests__/FormikCheckbox.test.js.map +1 -0
- package/dist/v2/__tests__/FormikDateTimePicker.test.js +237 -0
- package/dist/v2/__tests__/FormikDateTimePicker.test.js.map +1 -0
- package/dist/v2/__tests__/FormikDisplayWidth.test.js +102 -0
- package/dist/v2/__tests__/FormikDisplayWidth.test.js.map +1 -0
- package/dist/v2/__tests__/FormikRadioGroup.test.js +300 -0
- package/dist/v2/__tests__/FormikRadioGroup.test.js.map +1 -0
- package/dist/v2/__tests__/MobileRowCard.test.js +100 -102
- package/dist/v2/__tests__/MobileRowCard.test.js.map +1 -1
- package/dist/v2/__tests__/PreviewDrawer.test.js +169 -0
- package/dist/v2/__tests__/PreviewDrawer.test.js.map +1 -0
- package/dist/v2/__tests__/ReferentielFieldContainer.test.js +159 -0
- package/dist/v2/__tests__/ReferentielFieldContainer.test.js.map +1 -0
- package/dist/v2/__tests__/SectionErrorBoundary.test.js +53 -68
- package/dist/v2/__tests__/SectionErrorBoundary.test.js.map +1 -1
- package/dist/v2/__tests__/apiError.test.js +50 -69
- package/dist/v2/__tests__/apiError.test.js.map +1 -1
- package/dist/v2/__tests__/banned-patterns.test.js +42 -123
- package/dist/v2/__tests__/banned-patterns.test.js.map +1 -1
- package/dist/v2/__tests__/chart-palette.test.js +205 -0
- package/dist/v2/__tests__/chart-palette.test.js.map +1 -0
- package/dist/v2/__tests__/contrast-palette.test.js +42 -74
- package/dist/v2/__tests__/contrast-palette.test.js.map +1 -1
- package/dist/v2/__tests__/cssVariables.test.js +44 -51
- package/dist/v2/__tests__/cssVariables.test.js.map +1 -1
- package/dist/v2/__tests__/fileValidation.test.js +136 -0
- package/dist/v2/__tests__/fileValidation.test.js.map +1 -0
- package/dist/v2/__tests__/filterCriteria.test.js +324 -0
- package/dist/v2/__tests__/filterCriteria.test.js.map +1 -0
- package/dist/v2/__tests__/fmtDate.test.js +69 -0
- package/dist/v2/__tests__/fmtDate.test.js.map +1 -0
- package/dist/v2/__tests__/gap-leakage-refonte.test.js +221 -0
- package/dist/v2/__tests__/gap-leakage-refonte.test.js.map +1 -0
- package/dist/v2/__tests__/labels-merge.test.js +38 -46
- package/dist/v2/__tests__/labels-merge.test.js.map +1 -1
- package/dist/v2/__tests__/locale-fallback.test.js +47 -52
- package/dist/v2/__tests__/locale-fallback.test.js.map +1 -1
- package/dist/v2/__tests__/reviveSavedCriteria.test.js +144 -0
- package/dist/v2/__tests__/reviveSavedCriteria.test.js.map +1 -0
- package/dist/v2/__tests__/rowActions.test.js +186 -0
- package/dist/v2/__tests__/rowActions.test.js.map +1 -0
- package/dist/v2/__tests__/useFocusOnRouteChange.test.js +156 -0
- package/dist/v2/__tests__/useFocusOnRouteChange.test.js.map +1 -0
- package/dist/v2/__tests__/useFocusTrap.test.js +270 -407
- package/dist/v2/__tests__/useFocusTrap.test.js.map +1 -1
- package/dist/v2/__tests__/usePrefersReducedMotion.test.js +123 -0
- package/dist/v2/__tests__/usePrefersReducedMotion.test.js.map +1 -0
- package/dist/v2/components/Accordion.js +60 -82
- package/dist/v2/components/Accordion.js.map +1 -1
- package/dist/v2/components/ActionStrip.js +40 -52
- package/dist/v2/components/ActionStrip.js.map +1 -1
- package/dist/v2/components/Banner.js +42 -41
- package/dist/v2/components/Banner.js.map +1 -1
- package/dist/v2/components/Busy.js +22 -27
- package/dist/v2/components/Busy.js.map +1 -1
- package/dist/v2/components/Button.js +39 -50
- package/dist/v2/components/Button.js.map +1 -1
- package/dist/v2/components/CategoryTag.d.ts.map +1 -1
- package/dist/v2/components/CategoryTag.js +49 -32
- package/dist/v2/components/CategoryTag.js.map +1 -1
- package/dist/v2/components/Checkbox.js +39 -45
- package/dist/v2/components/Checkbox.js.map +1 -1
- package/dist/v2/components/Chip.js +29 -42
- package/dist/v2/components/Chip.js.map +1 -1
- package/dist/v2/components/Combobox.js +122 -144
- package/dist/v2/components/Combobox.js.map +1 -1
- package/dist/v2/components/CommandPalette.js +138 -225
- package/dist/v2/components/CommandPalette.js.map +1 -1
- package/dist/v2/components/ConfirmDialog.js +46 -56
- package/dist/v2/components/ConfirmDialog.js.map +1 -1
- package/dist/v2/components/DatePicker.js +81 -86
- package/dist/v2/components/DatePicker.js.map +1 -1
- package/dist/v2/components/DateRangePicker.js +77 -87
- package/dist/v2/components/DateRangePicker.js.map +1 -1
- package/dist/v2/components/DateTimePicker.d.ts.map +1 -1
- package/dist/v2/components/DateTimePicker.js +121 -95
- package/dist/v2/components/DateTimePicker.js.map +1 -1
- package/dist/v2/components/Drawer.d.ts.map +1 -1
- package/dist/v2/components/Drawer.js +93 -88
- package/dist/v2/components/Drawer.js.map +1 -1
- package/dist/v2/components/Dropzone.js +150 -196
- package/dist/v2/components/Dropzone.js.map +1 -1
- package/dist/v2/components/EmptyState.js +18 -20
- package/dist/v2/components/EmptyState.js.map +1 -1
- package/dist/v2/components/FavoriteToggle.js +28 -39
- package/dist/v2/components/FavoriteToggle.js.map +1 -1
- package/dist/v2/components/Field.d.ts +121 -5
- package/dist/v2/components/Field.d.ts.map +1 -1
- package/dist/v2/components/Field.js +221 -62
- package/dist/v2/components/Field.js.map +1 -1
- package/dist/v2/components/FieldError.js +18 -21
- package/dist/v2/components/FieldError.js.map +1 -1
- package/dist/v2/components/FieldHelp.js +40 -60
- package/dist/v2/components/FieldHelp.js.map +1 -1
- package/dist/v2/components/FileCard.js +27 -31
- package/dist/v2/components/FileCard.js.map +1 -1
- package/dist/v2/components/FilterTab.js +30 -38
- package/dist/v2/components/FilterTab.js.map +1 -1
- package/dist/v2/components/ForbiddenPage.d.ts +25 -1
- package/dist/v2/components/ForbiddenPage.d.ts.map +1 -1
- package/dist/v2/components/ForbiddenPage.js +37 -17
- package/dist/v2/components/ForbiddenPage.js.map +1 -1
- package/dist/v2/components/FormGrid.js +53 -59
- package/dist/v2/components/FormGrid.js.map +1 -1
- package/dist/v2/components/FormikDisplay.d.ts +50 -1
- package/dist/v2/components/FormikDisplay.d.ts.map +1 -1
- package/dist/v2/components/FormikDisplay.js +108 -33
- package/dist/v2/components/FormikDisplay.js.map +1 -1
- package/dist/v2/components/Input.d.ts +40 -0
- package/dist/v2/components/Input.d.ts.map +1 -1
- package/dist/v2/components/Input.js +81 -41
- package/dist/v2/components/Input.js.map +1 -1
- package/dist/v2/components/KPICard.js +57 -67
- package/dist/v2/components/KPICard.js.map +1 -1
- package/dist/v2/components/KPIStrip.js +16 -22
- package/dist/v2/components/KPIStrip.js.map +1 -1
- package/dist/v2/components/KV.js +25 -31
- package/dist/v2/components/KV.js.map +1 -1
- package/dist/v2/components/KVGrid.js +19 -26
- package/dist/v2/components/KVGrid.js.map +1 -1
- package/dist/v2/components/Layout.js +91 -120
- package/dist/v2/components/Layout.js.map +1 -1
- package/dist/v2/components/MobileRowCard.js +79 -91
- package/dist/v2/components/MobileRowCard.js.map +1 -1
- package/dist/v2/components/Modal.js +61 -69
- package/dist/v2/components/Modal.js.map +1 -1
- package/dist/v2/components/NetworkErrorPage.d.ts +19 -1
- package/dist/v2/components/NetworkErrorPage.d.ts.map +1 -1
- package/dist/v2/components/NetworkErrorPage.js +38 -21
- package/dist/v2/components/NetworkErrorPage.js.map +1 -1
- package/dist/v2/components/NotFoundPage.d.ts +17 -1
- package/dist/v2/components/NotFoundPage.d.ts.map +1 -1
- package/dist/v2/components/NotFoundPage.js +37 -18
- package/dist/v2/components/NotFoundPage.js.map +1 -1
- package/dist/v2/components/NumberInput.js +88 -118
- package/dist/v2/components/NumberInput.js.map +1 -1
- package/dist/v2/components/OverflowMenu.js +38 -56
- package/dist/v2/components/OverflowMenu.js.map +1 -1
- package/dist/v2/components/PdfViewer.js +34 -45
- package/dist/v2/components/PdfViewer.js.map +1 -1
- package/dist/v2/components/ProgressBar.js +42 -49
- package/dist/v2/components/ProgressBar.js.map +1 -1
- package/dist/v2/components/Radio.js +59 -67
- package/dist/v2/components/Radio.js.map +1 -1
- package/dist/v2/components/SectionErrorBoundary.js +90 -135
- package/dist/v2/components/SectionErrorBoundary.js.map +1 -1
- package/dist/v2/components/SectionHeader.js +34 -41
- package/dist/v2/components/SectionHeader.js.map +1 -1
- package/dist/v2/components/Segmented.js +69 -93
- package/dist/v2/components/Segmented.js.map +1 -1
- package/dist/v2/components/Select.d.ts +26 -2
- package/dist/v2/components/Select.d.ts.map +1 -1
- package/dist/v2/components/Select.js +120 -155
- package/dist/v2/components/Select.js.map +1 -1
- package/dist/v2/components/ServerErrorPage.d.ts +27 -1
- package/dist/v2/components/ServerErrorPage.d.ts.map +1 -1
- package/dist/v2/components/ServerErrorPage.js +37 -20
- package/dist/v2/components/ServerErrorPage.js.map +1 -1
- package/dist/v2/components/Skeleton.js +86 -100
- package/dist/v2/components/Skeleton.js.map +1 -1
- package/dist/v2/components/SkipLink.js +9 -12
- package/dist/v2/components/SkipLink.js.map +1 -1
- package/dist/v2/components/Spinner.js +16 -25
- package/dist/v2/components/Spinner.js.map +1 -1
- package/dist/v2/components/Status.js +18 -29
- package/dist/v2/components/Status.js.map +1 -1
- package/dist/v2/components/Stepper.js +80 -82
- package/dist/v2/components/Stepper.js.map +1 -1
- package/dist/v2/components/Surface.js +34 -49
- package/dist/v2/components/Surface.js.map +1 -1
- package/dist/v2/components/Switch.js +29 -37
- package/dist/v2/components/Switch.js.map +1 -1
- package/dist/v2/components/TabPanel.d.ts +17 -0
- package/dist/v2/components/TabPanel.d.ts.map +1 -0
- package/dist/v2/components/TabPanel.js +90 -0
- package/dist/v2/components/TabPanel.js.map +1 -0
- package/dist/v2/components/Tabs.d.ts +25 -0
- package/dist/v2/components/Tabs.d.ts.map +1 -1
- package/dist/v2/components/Tabs.js +53 -29
- package/dist/v2/components/Tabs.js.map +1 -1
- package/dist/v2/components/TelInput.js +80 -115
- package/dist/v2/components/TelInput.js.map +1 -1
- package/dist/v2/components/Textarea.js +26 -35
- package/dist/v2/components/Textarea.js.map +1 -1
- package/dist/v2/components/TimePicker.js +62 -74
- package/dist/v2/components/TimePicker.js.map +1 -1
- package/dist/v2/components/Toast.js +119 -174
- package/dist/v2/components/Toast.js.map +1 -1
- package/dist/v2/components/Tooltip.js +23 -38
- package/dist/v2/components/Tooltip.js.map +1 -1
- package/dist/v2/components/_ErrorPageBody.js +15 -16
- package/dist/v2/components/_ErrorPageBody.js.map +1 -1
- package/dist/v2/components/_pickerShared.js +5 -5
- package/dist/v2/components/_pickerShared.js.map +1 -1
- package/dist/v2/components/index.d.ts +67 -1
- package/dist/v2/components/index.d.ts.map +1 -1
- package/dist/v2/components/index.js +153 -136
- package/dist/v2/components/index.js.map +1 -1
- package/dist/v2/hooks/index.d.ts +65 -0
- package/dist/v2/hooks/index.d.ts.map +1 -1
- package/dist/v2/hooks/index.js +63 -24
- package/dist/v2/hooks/index.js.map +1 -1
- package/dist/v2/hooks/useAppliedFilters.d.ts +102 -0
- package/dist/v2/hooks/useAppliedFilters.d.ts.map +1 -0
- package/dist/v2/hooks/useAppliedFilters.js +117 -0
- package/dist/v2/hooks/useAppliedFilters.js.map +1 -0
- package/dist/v2/hooks/useDebouncedCallback.d.ts +64 -0
- package/dist/v2/hooks/useDebouncedCallback.d.ts.map +1 -0
- package/dist/v2/hooks/useDebouncedCallback.js +87 -0
- package/dist/v2/hooks/useDebouncedCallback.js.map +1 -0
- package/dist/v2/hooks/useDelayedFlag.js +6 -20
- package/dist/v2/hooks/useDelayedFlag.js.map +1 -1
- package/dist/v2/hooks/useDensity.d.ts.map +1 -1
- package/dist/v2/hooks/useDensity.js +14 -18
- package/dist/v2/hooks/useDensity.js.map +1 -1
- package/dist/v2/hooks/useFocusFirstError.js +26 -34
- package/dist/v2/hooks/useFocusFirstError.js.map +1 -1
- package/dist/v2/hooks/useFocusOnRouteChange.d.ts +65 -0
- package/dist/v2/hooks/useFocusOnRouteChange.d.ts.map +1 -0
- package/dist/v2/hooks/useFocusOnRouteChange.js +88 -0
- package/dist/v2/hooks/useFocusOnRouteChange.js.map +1 -0
- package/dist/v2/hooks/useFocusTrap.js +20 -24
- package/dist/v2/hooks/useFocusTrap.js.map +1 -1
- package/dist/v2/hooks/useFormAutoSave.d.ts +4 -4
- package/dist/v2/hooks/useFormAutoSave.d.ts.map +1 -1
- package/dist/v2/hooks/useFormAutoSave.js +39 -54
- package/dist/v2/hooks/useFormAutoSave.js.map +1 -1
- package/dist/v2/hooks/useFormCompletionProgress.d.ts +1 -1
- package/dist/v2/hooks/useFormCompletionProgress.d.ts.map +1 -1
- package/dist/v2/hooks/useFormCompletionProgress.js +33 -52
- package/dist/v2/hooks/useFormCompletionProgress.js.map +1 -1
- package/dist/v2/hooks/useKeyboardShortcuts.d.ts +25 -0
- package/dist/v2/hooks/useKeyboardShortcuts.d.ts.map +1 -0
- package/dist/v2/hooks/useKeyboardShortcuts.js +132 -0
- package/dist/v2/hooks/useKeyboardShortcuts.js.map +1 -0
- package/dist/v2/hooks/usePrefersReducedMotion.d.ts +56 -0
- package/dist/v2/hooks/usePrefersReducedMotion.d.ts.map +1 -0
- package/dist/v2/hooks/usePrefersReducedMotion.js +105 -0
- package/dist/v2/hooks/usePrefersReducedMotion.js.map +1 -0
- package/dist/v2/hooks/useResolvedDensity.js +5 -13
- package/dist/v2/hooks/useResolvedDensity.js.map +1 -1
- package/dist/v2/hooks/useSortedRows.js +4 -6
- package/dist/v2/hooks/useSortedRows.js.map +1 -1
- package/dist/v2/hooks/useTabLoading.js +7 -22
- package/dist/v2/hooks/useTabLoading.js.map +1 -1
- package/dist/v2/index.d.ts.map +1 -1
- package/dist/v2/index.js +143 -145
- package/dist/v2/index.js.map +1 -1
- package/dist/v2/modalContext.js +2 -2
- package/dist/v2/modalContext.js.map +1 -1
- package/dist/v2/models/favorite.d.ts +8 -9
- package/dist/v2/models/favorite.d.ts.map +1 -1
- package/dist/v2/models/favorite.js.map +1 -1
- package/dist/v2/models/index.js +4 -4
- package/dist/v2/models/index.js.map +1 -1
- package/dist/v2/models/personalization.d.ts +44 -48
- package/dist/v2/models/personalization.d.ts.map +1 -1
- package/dist/v2/models/personalization.js.map +1 -1
- package/dist/v2/models/referentiel.d.ts +32 -50
- package/dist/v2/models/referentiel.d.ts.map +1 -1
- package/dist/v2/models/referentiel.js.map +1 -1
- package/dist/v2/models/savedFilter.d.ts +8 -17
- package/dist/v2/models/savedFilter.d.ts.map +1 -1
- package/dist/v2/models/savedFilter.js.map +1 -1
- package/dist/v2/patterns/ActionBar.js +152 -187
- package/dist/v2/patterns/ActionBar.js.map +1 -1
- package/dist/v2/patterns/AppMain.d.ts +109 -0
- package/dist/v2/patterns/AppMain.d.ts.map +1 -0
- package/dist/v2/patterns/AppMain.js +115 -0
- package/dist/v2/patterns/AppMain.js.map +1 -0
- package/dist/v2/patterns/BulkActionBar.js +40 -42
- package/dist/v2/patterns/BulkActionBar.js.map +1 -1
- package/dist/v2/patterns/ChartFigure.d.ts +124 -0
- package/dist/v2/patterns/ChartFigure.d.ts.map +1 -0
- package/dist/v2/patterns/ChartFigure.js +159 -0
- package/dist/v2/patterns/ChartFigure.js.map +1 -0
- package/dist/v2/patterns/CollapsibleDataGrid.js +138 -174
- package/dist/v2/patterns/CollapsibleDataGrid.js.map +1 -1
- package/dist/v2/patterns/ColumnsToggle.js +60 -94
- package/dist/v2/patterns/ColumnsToggle.js.map +1 -1
- package/dist/v2/patterns/DataGrid.d.ts.map +1 -1
- package/dist/v2/patterns/DataGrid.js +262 -297
- package/dist/v2/patterns/DataGrid.js.map +1 -1
- package/dist/v2/patterns/DataGridSettingsMenu.d.ts +12 -0
- package/dist/v2/patterns/DataGridSettingsMenu.d.ts.map +1 -1
- package/dist/v2/patterns/DataGridSettingsMenu.js +104 -121
- package/dist/v2/patterns/DataGridSettingsMenu.js.map +1 -1
- package/dist/v2/patterns/DataGridToolbar.js +103 -106
- package/dist/v2/patterns/DataGridToolbar.js.map +1 -1
- package/dist/v2/patterns/DataGridVirtualized.js +179 -217
- package/dist/v2/patterns/DataGridVirtualized.js.map +1 -1
- package/dist/v2/patterns/DeleteResourceConfirmDialog.js +32 -35
- package/dist/v2/patterns/DeleteResourceConfirmDialog.js.map +1 -1
- package/dist/v2/patterns/DetailSplit.d.ts +87 -0
- package/dist/v2/patterns/DetailSplit.d.ts.map +1 -0
- package/dist/v2/patterns/DetailSplit.js +116 -0
- package/dist/v2/patterns/DetailSplit.js.map +1 -0
- package/dist/v2/patterns/FavoriteColumn.d.ts +9 -9
- package/dist/v2/patterns/FavoriteColumn.d.ts.map +1 -1
- package/dist/v2/patterns/FavoriteColumn.js +32 -80
- package/dist/v2/patterns/FavoriteColumn.js.map +1 -1
- package/dist/v2/patterns/FavoritesFilter.js +36 -44
- package/dist/v2/patterns/FavoritesFilter.js.map +1 -1
- package/dist/v2/patterns/FilterTabBar.d.ts +28 -0
- package/dist/v2/patterns/FilterTabBar.d.ts.map +1 -0
- package/dist/v2/patterns/FilterTabBar.js +120 -0
- package/dist/v2/patterns/FilterTabBar.js.map +1 -0
- package/dist/v2/patterns/FormErrorSummary.js +20 -23
- package/dist/v2/patterns/FormErrorSummary.js.map +1 -1
- package/dist/v2/patterns/FormPageShell.js +53 -50
- package/dist/v2/patterns/FormPageShell.js.map +1 -1
- package/dist/v2/patterns/FormSection.d.ts +8 -3
- package/dist/v2/patterns/FormSection.d.ts.map +1 -1
- package/dist/v2/patterns/FormSection.js +44 -51
- package/dist/v2/patterns/FormSection.js.map +1 -1
- package/dist/v2/patterns/FormikCheckbox.d.ts +77 -0
- package/dist/v2/patterns/FormikCheckbox.d.ts.map +1 -0
- package/dist/v2/patterns/FormikCheckbox.js +138 -0
- package/dist/v2/patterns/FormikCheckbox.js.map +1 -0
- package/dist/v2/patterns/FormikCheckboxGroup.d.ts +17 -1
- package/dist/v2/patterns/FormikCheckboxGroup.d.ts.map +1 -1
- package/dist/v2/patterns/FormikCheckboxGroup.js +62 -65
- package/dist/v2/patterns/FormikCheckboxGroup.js.map +1 -1
- package/dist/v2/patterns/FormikCombobox.d.ts +7 -1
- package/dist/v2/patterns/FormikCombobox.d.ts.map +1 -1
- package/dist/v2/patterns/FormikCombobox.js +55 -69
- package/dist/v2/patterns/FormikCombobox.js.map +1 -1
- package/dist/v2/patterns/FormikDatePicker.d.ts +13 -1
- package/dist/v2/patterns/FormikDatePicker.d.ts.map +1 -1
- package/dist/v2/patterns/FormikDatePicker.js +59 -106
- package/dist/v2/patterns/FormikDatePicker.js.map +1 -1
- package/dist/v2/patterns/FormikDateTimePicker.d.ts +111 -0
- package/dist/v2/patterns/FormikDateTimePicker.d.ts.map +1 -0
- package/dist/v2/patterns/FormikDateTimePicker.js +144 -0
- package/dist/v2/patterns/FormikDateTimePicker.js.map +1 -0
- package/dist/v2/patterns/FormikErrorFocus.js +25 -26
- package/dist/v2/patterns/FormikErrorFocus.js.map +1 -1
- package/dist/v2/patterns/FormikErrorSummary.d.ts +74 -0
- package/dist/v2/patterns/FormikErrorSummary.d.ts.map +1 -0
- package/dist/v2/patterns/FormikErrorSummary.js +97 -0
- package/dist/v2/patterns/FormikErrorSummary.js.map +1 -0
- package/dist/v2/patterns/FormikFile.d.ts +14 -1
- package/dist/v2/patterns/FormikFile.d.ts.map +1 -1
- package/dist/v2/patterns/FormikFile.js +99 -83
- package/dist/v2/patterns/FormikFile.js.map +1 -1
- package/dist/v2/patterns/FormikInput.d.ts +11 -1
- package/dist/v2/patterns/FormikInput.d.ts.map +1 -1
- package/dist/v2/patterns/FormikInput.js +45 -55
- package/dist/v2/patterns/FormikInput.js.map +1 -1
- package/dist/v2/patterns/FormikRadioGroup.d.ts +80 -0
- package/dist/v2/patterns/FormikRadioGroup.d.ts.map +1 -0
- package/dist/v2/patterns/FormikRadioGroup.js +137 -0
- package/dist/v2/patterns/FormikRadioGroup.js.map +1 -0
- package/dist/v2/patterns/FormikReferentielField.d.ts +12 -1
- package/dist/v2/patterns/FormikReferentielField.d.ts.map +1 -1
- package/dist/v2/patterns/FormikReferentielField.js +54 -64
- package/dist/v2/patterns/FormikReferentielField.js.map +1 -1
- package/dist/v2/patterns/FormikSelect.d.ts +9 -1
- package/dist/v2/patterns/FormikSelect.d.ts.map +1 -1
- package/dist/v2/patterns/FormikSelect.js +70 -89
- package/dist/v2/patterns/FormikSelect.js.map +1 -1
- package/dist/v2/patterns/FormikTextarea.d.ts +9 -1
- package/dist/v2/patterns/FormikTextarea.d.ts.map +1 -1
- package/dist/v2/patterns/FormikTextarea.js +35 -48
- package/dist/v2/patterns/FormikTextarea.js.map +1 -1
- package/dist/v2/patterns/KeyboardShortcutsHelp.d.ts +14 -1
- package/dist/v2/patterns/KeyboardShortcutsHelp.d.ts.map +1 -1
- package/dist/v2/patterns/KeyboardShortcutsHelp.js +71 -74
- package/dist/v2/patterns/KeyboardShortcutsHelp.js.map +1 -1
- package/dist/v2/patterns/NetworkErrorBanner.js +13 -16
- package/dist/v2/patterns/NetworkErrorBanner.js.map +1 -1
- package/dist/v2/patterns/PageContent.js +17 -20
- package/dist/v2/patterns/PageContent.js.map +1 -1
- package/dist/v2/patterns/PreviewDrawer.d.ts +49 -0
- package/dist/v2/patterns/PreviewDrawer.d.ts.map +1 -0
- package/dist/v2/patterns/PreviewDrawer.js +159 -0
- package/dist/v2/patterns/PreviewDrawer.js.map +1 -0
- package/dist/v2/patterns/ReferentielField.d.ts +86 -2
- package/dist/v2/patterns/ReferentielField.d.ts.map +1 -1
- package/dist/v2/patterns/ReferentielField.js +347 -327
- package/dist/v2/patterns/ReferentielField.js.map +1 -1
- package/dist/v2/patterns/RowFavoriteToggle.d.ts +98 -0
- package/dist/v2/patterns/RowFavoriteToggle.d.ts.map +1 -0
- package/dist/v2/patterns/RowFavoriteToggle.js +135 -0
- package/dist/v2/patterns/RowFavoriteToggle.js.map +1 -0
- package/dist/v2/patterns/SaveFilterDialog.js +50 -77
- package/dist/v2/patterns/SaveFilterDialog.js.map +1 -1
- package/dist/v2/patterns/SavedFiltersMenu.js +89 -107
- package/dist/v2/patterns/SavedFiltersMenu.js.map +1 -1
- package/dist/v2/patterns/SkeletonPageShell.js +122 -143
- package/dist/v2/patterns/SkeletonPageShell.js.map +1 -1
- package/dist/v2/patterns/SortableHeader.js +35 -57
- package/dist/v2/patterns/SortableHeader.js.map +1 -1
- package/dist/v2/patterns/Tour.js +121 -142
- package/dist/v2/patterns/Tour.js.map +1 -1
- package/dist/v2/patterns/_dataGridShared.d.ts.map +1 -1
- package/dist/v2/patterns/_dataGridShared.js +131 -147
- package/dist/v2/patterns/_dataGridShared.js.map +1 -1
- package/dist/v2/patterns/_pickerSerialisation.d.ts +44 -0
- package/dist/v2/patterns/_pickerSerialisation.d.ts.map +1 -0
- package/dist/v2/patterns/_pickerSerialisation.js +80 -0
- package/dist/v2/patterns/_pickerSerialisation.js.map +1 -0
- package/dist/v2/patterns/_sort.js +17 -33
- package/dist/v2/patterns/_sort.js.map +1 -1
- package/dist/v2/patterns/_useColumnReorder.js +124 -163
- package/dist/v2/patterns/_useColumnReorder.js.map +1 -1
- package/dist/v2/patterns/_useColumnResize.js +80 -99
- package/dist/v2/patterns/_useColumnResize.js.map +1 -1
- package/dist/v2/patterns/filterCriteria.d.ts +78 -0
- package/dist/v2/patterns/filterCriteria.d.ts.map +1 -0
- package/dist/v2/patterns/filterCriteria.js +110 -0
- package/dist/v2/patterns/filterCriteria.js.map +1 -0
- package/dist/v2/patterns/index.d.ts +247 -0
- package/dist/v2/patterns/index.d.ts.map +1 -1
- package/dist/v2/patterns/index.js +182 -70
- package/dist/v2/patterns/index.js.map +1 -1
- package/dist/v2/patterns/rowActions.d.ts +150 -0
- package/dist/v2/patterns/rowActions.d.ts.map +1 -0
- package/dist/v2/patterns/rowActions.js +232 -0
- package/dist/v2/patterns/rowActions.js.map +1 -0
- package/dist/v2/personalization/PersonalizationProvider.d.ts.map +1 -1
- package/dist/v2/personalization/PersonalizationProvider.js +57 -53
- package/dist/v2/personalization/PersonalizationProvider.js.map +1 -1
- package/dist/v2/personalization/adapters/_storageKey.js +5 -5
- package/dist/v2/personalization/adapters/_storageKey.js.map +1 -1
- package/dist/v2/personalization/adapters/createLocalStorageAdapter.js +25 -24
- package/dist/v2/personalization/adapters/createLocalStorageAdapter.js.map +1 -1
- package/dist/v2/personalization/adapters/createMemoryAdapter.js +14 -14
- package/dist/v2/personalization/adapters/createMemoryAdapter.js.map +1 -1
- package/dist/v2/personalization/adapters/index.js +5 -5
- package/dist/v2/personalization/adapters/index.js.map +1 -1
- package/dist/v2/personalization/capabilities/favorites.js +39 -62
- package/dist/v2/personalization/capabilities/favorites.js.map +1 -1
- package/dist/v2/personalization/capabilities/favoritesView.js +25 -37
- package/dist/v2/personalization/capabilities/favoritesView.js.map +1 -1
- package/dist/v2/personalization/capabilities/gridPreferences.d.ts +100 -0
- package/dist/v2/personalization/capabilities/gridPreferences.d.ts.map +1 -0
- package/dist/v2/personalization/capabilities/gridPreferences.js +210 -0
- package/dist/v2/personalization/capabilities/gridPreferences.js.map +1 -0
- package/dist/v2/personalization/capabilities/index.d.ts +6 -0
- package/dist/v2/personalization/capabilities/index.d.ts.map +1 -1
- package/dist/v2/personalization/capabilities/index.js +23 -10
- package/dist/v2/personalization/capabilities/index.js.map +1 -1
- package/dist/v2/personalization/capabilities/reviveSavedCriteria.d.ts +88 -0
- package/dist/v2/personalization/capabilities/reviveSavedCriteria.d.ts.map +1 -0
- package/dist/v2/personalization/capabilities/reviveSavedCriteria.js +126 -0
- package/dist/v2/personalization/capabilities/reviveSavedCriteria.js.map +1 -0
- package/dist/v2/personalization/capabilities/savedFilters.js +93 -100
- package/dist/v2/personalization/capabilities/savedFilters.js.map +1 -1
- package/dist/v2/personalization/createPersonalizationStore.d.ts.map +1 -1
- package/dist/v2/personalization/createPersonalizationStore.js +81 -182
- package/dist/v2/personalization/createPersonalizationStore.js.map +1 -1
- package/dist/v2/personalization/index.d.ts +34 -0
- package/dist/v2/personalization/index.d.ts.map +1 -1
- package/dist/v2/personalization/index.js +41 -21
- package/dist/v2/personalization/index.js.map +1 -1
- package/dist/v2/personalization/personalizationContext.js +10 -12
- package/dist/v2/personalization/personalizationContext.js.map +1 -1
- package/dist/v2/personalization/schema.js +8 -9
- package/dist/v2/personalization/schema.js.map +1 -1
- package/dist/v2/referentiel/ReferentielProvider.js +31 -45
- package/dist/v2/referentiel/ReferentielProvider.js.map +1 -1
- package/dist/v2/referentiel/index.js +11 -13
- package/dist/v2/referentiel/index.js.map +1 -1
- package/dist/v2/referentiel/types.d.ts +105 -0
- package/dist/v2/referentiel/types.d.ts.map +1 -0
- package/dist/v2/referentiel/types.js +6 -0
- package/dist/v2/referentiel/types.js.map +1 -0
- package/dist/v2/referentiel/useReferentielClient.js +13 -16
- package/dist/v2/referentiel/useReferentielClient.js.map +1 -1
- package/dist/v2/referentiel/useReferentielOptions.d.ts +7 -17
- package/dist/v2/referentiel/useReferentielOptions.d.ts.map +1 -1
- package/dist/v2/referentiel/useReferentielOptions.js +63 -120
- package/dist/v2/referentiel/useReferentielOptions.js.map +1 -1
- package/dist/v2/referentiel/useReferentielSearch.d.ts +7 -48
- package/dist/v2/referentiel/useReferentielSearch.d.ts.map +1 -1
- package/dist/v2/referentiel/useReferentielSearch.js +40 -95
- package/dist/v2/referentiel/useReferentielSearch.js.map +1 -1
- package/dist/v2/theme/_brand.js +12 -26
- package/dist/v2/theme/_brand.js.map +1 -1
- package/dist/v2/theme/_brandSecondary.js +12 -26
- package/dist/v2/theme/_brandSecondary.js.map +1 -1
- package/dist/v2/theme/createPortnetTheme.js +41 -49
- package/dist/v2/theme/createPortnetTheme.js.map +1 -1
- package/dist/v2/theme/cssVariables.d.ts +3 -3
- package/dist/v2/theme/cssVariables.d.ts.map +1 -1
- package/dist/v2/theme/cssVariables.js +65 -70
- package/dist/v2/theme/cssVariables.js.map +1 -1
- package/dist/v2/theme/index.js +10 -10
- package/dist/v2/theme/index.js.map +1 -1
- package/dist/v2/tokens/breakpoints.js +16 -16
- package/dist/v2/tokens/breakpoints.js.map +1 -1
- package/dist/v2/tokens/chart.d.ts +103 -0
- package/dist/v2/tokens/chart.d.ts.map +1 -0
- package/dist/v2/tokens/chart.js +270 -0
- package/dist/v2/tokens/chart.js.map +1 -0
- package/dist/v2/tokens/colors.js +24 -24
- package/dist/v2/tokens/colors.js.map +1 -1
- package/dist/v2/tokens/density.d.ts +104 -0
- package/dist/v2/tokens/density.d.ts.map +1 -1
- package/dist/v2/tokens/density.js +67 -12
- package/dist/v2/tokens/density.js.map +1 -1
- package/dist/v2/tokens/index.d.ts +50 -1
- package/dist/v2/tokens/index.d.ts.map +1 -1
- package/dist/v2/tokens/index.js +116 -68
- package/dist/v2/tokens/index.js.map +1 -1
- package/dist/v2/tokens/motion.js +16 -22
- package/dist/v2/tokens/motion.js.map +1 -1
- package/dist/v2/tokens/radius.js +3 -3
- package/dist/v2/tokens/radius.js.map +1 -1
- package/dist/v2/tokens/shadows.js +8 -8
- package/dist/v2/tokens/shadows.js.map +1 -1
- package/dist/v2/tokens/spacing.js +4 -4
- package/dist/v2/tokens/spacing.js.map +1 -1
- package/dist/v2/tokens/state.js +3 -3
- package/dist/v2/tokens/state.js.map +1 -1
- package/dist/v2/tokens/statusPalette.js +21 -23
- package/dist/v2/tokens/statusPalette.js.map +1 -1
- package/dist/v2/tokens/tokens.json +6 -1
- package/dist/v2/tokens/typography.js +15 -15
- package/dist/v2/tokens/typography.js.map +1 -1
- package/dist/v2/tokens/zIndex.js +3 -3
- package/dist/v2/tokens/zIndex.js.map +1 -1
- package/dist/v2/types/datagrid.d.ts +9 -1
- package/dist/v2/types/datagrid.d.ts.map +1 -1
- package/dist/v2/types/datagrid.js.map +1 -1
- package/dist/v2/types/index.js +2 -2
- package/dist/v2/types/index.js.map +1 -1
- package/dist/v2/utils/apiError.js +16 -37
- package/dist/v2/utils/apiError.js.map +1 -1
- package/dist/v2/utils/contrast.js +31 -32
- package/dist/v2/utils/contrast.js.map +1 -1
- package/dist/v2/utils/cx.js +7 -27
- package/dist/v2/utils/cx.js.map +1 -1
- package/dist/v2/utils/fileDownload.js +25 -28
- package/dist/v2/utils/fileDownload.js.map +1 -1
- package/dist/v2/utils/fileValidation.d.ts +116 -0
- package/dist/v2/utils/fileValidation.d.ts.map +1 -0
- package/dist/v2/utils/fileValidation.js +220 -0
- package/dist/v2/utils/fileValidation.js.map +1 -0
- package/dist/v2/utils/fmtDate.d.ts +103 -0
- package/dist/v2/utils/fmtDate.d.ts.map +1 -0
- package/dist/v2/utils/fmtDate.js +119 -0
- package/dist/v2/utils/fmtDate.js.map +1 -0
- package/dist/v2/utils/fmtMoney.d.ts +3 -3
- package/dist/v2/utils/fmtMoney.d.ts.map +1 -1
- package/dist/v2/utils/fmtMoney.js +9 -11
- package/dist/v2/utils/fmtMoney.js.map +1 -1
- package/dist/v2/utils/formikErrors.d.ts +67 -0
- package/dist/v2/utils/formikErrors.d.ts.map +1 -0
- package/dist/v2/utils/formikErrors.js +85 -0
- package/dist/v2/utils/formikErrors.js.map +1 -0
- package/dist/v2/utils/index.d.ts +5 -0
- package/dist/v2/utils/index.d.ts.map +1 -1
- package/dist/v2/utils/index.js +67 -18
- package/dist/v2/utils/index.js.map +1 -1
- package/dist/v2/utils/mergeLabels.js +9 -14
- package/dist/v2/utils/mergeLabels.js.map +1 -1
- package/dist/v2/utils/networkStatus.js +14 -14
- package/dist/v2/utils/networkStatus.js.map +1 -1
- package/package.json +26 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiError.js","names":["DEFAULT_API_ERROR_MESSAGE","exports","readPath","source","path","current","_iterator","_createForOfIteratorHelper","_step","s","n","done","key","value","_typeof","undefined","Reflect","get","err","e","f","asNonEmptyString","length","TRANSPORT_MESSAGE_PATTERNS","isTransportMessage","some","pattern","test","trim","asUserFacingMessage","text","getApiErrorMessage","error","_ref","_ref2","_ref3","_asNonEmptyString","fallback","arguments","getApiErrorDetail","getApiErrorStatus","bodyStatus","status"],"sources":["../../../src/lib/v2/utils/apiError.ts"],"sourcesContent":["/**\r\n * apiError — narrow an `unknown` rejection into something displayable.\r\n *\r\n * ─────────────────────────────────────────────────────────────────────────────\r\n * WHY THIS BELONGS IN THE LIBRARY (capability gap G-04)\r\n *\r\n * The Platform TypeScript Guidelines mandate `useUnknownInCatchVariables`, so\r\n * `catch (e)` binds `unknown` in EVERY saga of EVERY consuming module. The same\r\n * guidelines forbid `any` and unsafe assertions. Between those two rules sits a\r\n * narrowing helper that the library did not provide — so each module wrote its\r\n * own, and the observed outcome was that they wrote it the forbidden way:\r\n *\r\n * (error as { response?: { data?: { message?: unknown } } }).response\r\n *\r\n * i.e. an unchecked assertion on an `unknown`, used to work around a flag the\r\n * platform imposes. Two modules audited (`procuration-portnet-fe`,\r\n * `procuration-fe`) had independently reached for exactly that construct.\r\n * A mandated strict-mode flag with no sanctioned escape hatch produces\r\n * unsanctioned ones.\r\n *\r\n * Implementation notes\r\n * --------------------\r\n * `readPath` walks nested objects using the `in` operator, which narrows without\r\n * an assertion, and `Reflect.get`, which returns the value as `unknown` rather\r\n * than widening anything to `any`. No assertion appears anywhere in this file.\r\n *\r\n * Deliberately DUCK-TYPED rather than built on `axios.isAxiosError`. Three\r\n * reasons: this library must not take a hard axios dependency for a string\r\n * helper; a plain object shaped like an axios error (a hand-rolled reject, a\r\n * test double, a non-axios transport) still resolves correctly; and the check\r\n * stays valid across axios majors.\r\n * ─────────────────────────────────────────────────────────────────────────────\r\n *\r\n * getApiErrorMessage(err) → backend message, or the default\r\n * getApiErrorMessage(err, \"Échec de l'envoi.\") → custom fallback\r\n * getApiErrorStatus(err) → 404 | undefined\r\n *\r\n * Envelope keys read, in order: `data.body`, `data.message`, `data.error`.\r\n * Three keys because three PORTNET back-ends chose differently; see the\r\n * resolution-order note on `getApiErrorMessage` before adding a fourth.\r\n */\r\n\r\n/**\r\n * Default user-facing fallback. French per Charter §09 (voice, vouvoiement) and\r\n * §09.3 (no raw technical detail — never \"Erreur 422 Unprocessable Entity\").\r\n * Override per call site when a screen can say something more useful.\r\n */\r\nexport const DEFAULT_API_ERROR_MESSAGE =\r\n \"Une erreur est survenue. Veuillez réessayer.\";\r\n\r\n/**\r\n * Walk `path` through nested non-null objects, returning the value at the end,\r\n * or `undefined` if any hop is missing. Assertion-free.\r\n */\r\nconst readPath = (source: unknown, path: readonly string[]): unknown => {\r\n let current: unknown = source;\r\n\r\n for (const key of path) {\r\n if (typeof current !== \"object\" || current === null || !(key in current)) {\r\n return undefined;\r\n }\r\n current = Reflect.get(current, key);\r\n }\r\n\r\n return current;\r\n};\r\n\r\nconst asNonEmptyString = (value: unknown): string | undefined =>\r\n typeof value === \"string\" && value.length > 0 ? value : undefined;\r\n\r\n/**\r\n * Transport-layer phrasings that must NEVER reach a user — capability gap G-07.\r\n *\r\n * ──────────────────────────────────────────────────────────────────────\r\n * THE DEFECT THIS FIXES\r\n *\r\n * `getApiErrorMessage` resolved `error.message` BEFORE its fallback. An\r\n * `AxiosError` always has `.message`, so on any server error carrying no\r\n * `response.data.message` — a 500 with an empty body, a gateway error, a\r\n * timeout — step 3 won and the user was shown:\r\n *\r\n * \"Request failed with status code 500\"\r\n *\r\n * English, technical, and precisely the shape Charter §09.3 names as forbidden\r\n * (\"✗ « Erreur 422 — Unprocessable Entity »\"). Worse, it made every consuming\r\n * module's carefully-written French fallback effectively UNREACHABLE — the\r\n * argument was accepted and then almost never used. Found during the\r\n * `procuration-portnet-fe` Area 10 audit, where 12 call sites pass a considered\r\n * fallback that could essentially never render.\r\n *\r\n * WHY A DENY-LIST AND NOT SIMPLY DROPPING STEP 3\r\n *\r\n * Step 3 also carries LEGITIMATE messages: any `throw new Error(\"Ce titre ne\r\n * peut pas être supprimé car il est en cours de validation.\")` in module code\r\n * arrives through exactly the same path. Removing the hop would trade a leak of\r\n * technical strings for the loss of real business messages across the whole\r\n * platform — a worse outcome. So the hop stays and only transport phrasings are\r\n * suppressed.\r\n *\r\n * The list is deliberately CONSERVATIVE: anything not recognised passes through,\r\n * on the assumption a human wrote it. A false negative shows one ugly string; a\r\n * false positive silently replaces a real business message with a generic\r\n * fallback, which is the more damaging error.\r\n *\r\n * Sourced from axios's own message construction (`settle`, `AxiosError` codes\r\n * ECONNABORTED / ETIMEDOUT / ERR_NETWORK / ERR_CANCELED) plus the Node socket\r\n * phrasing that surfaces through SSR and test doubles.\r\n * ──────────────────────────────────────────────────────────────────────\r\n */\r\nconst TRANSPORT_MESSAGE_PATTERNS: readonly RegExp[] = [\r\n /^request failed with status code \\d+$/i,\r\n /^network error$/i,\r\n /^timeout of \\d+ms exceeded$/i,\r\n /^timeout exceeded$/i,\r\n /^request aborted$/i,\r\n /^canceled$/i,\r\n /^unsupported protocol/i,\r\n /^maximum content size exceeded$/i,\r\n /^socket hang up$/i,\r\n /* ── errno codes and axios error codes ── CASE-SENSITIVE, DELIBERATELY ─────\r\n *\r\n * These two are the only patterns here NOT marked `/i`, and the asymmetry is\r\n * load-bearing. errno constants are uppercase by universal convention\r\n * (`ETIMEDOUT`, `ECONNREFUSED`, `ENOTFOUND`, `EPIPE`), so an uppercase-only\r\n * match identifies them precisely. Matching case-insensitively would make\r\n * `/^e[a-z]+$/i` swallow ordinary French words beginning with \"e\" — \"erreur\",\r\n * \"expiré\", \"échec\" — turning a real business message into a generic fallback,\r\n * which is the more damaging failure this list is tuned against.\r\n *\r\n * ⚠ An earlier version of the first pattern was `/^ec[a-z]+$/i`, which matched\r\n * `ECONNREFUSED` (it begins \"EC\") but silently MISSED `ETIMEDOUT` (\"ET\"),\r\n * despite the comment claiming otherwise. The unit test caught it. Do not\r\n * narrow the prefix again: the family is \"E + uppercase word\", not \"EC...\".\r\n *\r\n * Residual, accepted: an all-caps single word like \"ERREUR\" is treated as an\r\n * errno code. A module should not be throwing all-caps single-word messages at\r\n * users, and replacing one with a proper French fallback is an improvement. */\r\n /^E[A-Z]{3,}$/, // errno: ETIMEDOUT, ECONNREFUSED, ECONNRESET, ENOTFOUND, EPIPE\r\n /^ERR_[A-Z_]+$/, // axios: ERR_NETWORK, ERR_CANCELED, ERR_BAD_RESPONSE\r\n];\r\n\r\n/** Is this string an axios/transport artefact rather than something for a user? */\r\nconst isTransportMessage = (value: string): boolean =>\r\n TRANSPORT_MESSAGE_PATTERNS.some((pattern) => pattern.test(value.trim()));\r\n\r\n/**\r\n * `error.message`, but only when it is fit to show a user.\r\n *\r\n * Suppresses transport phrasings (G-07) so the caller's French fallback is\r\n * reached instead. Module-thrown `Error` messages pass through untouched.\r\n */\r\nconst asUserFacingMessage = (value: unknown): string | undefined => {\r\n const text = asNonEmptyString(value);\r\n if (text === undefined) return undefined;\r\n return isTransportMessage(text) ? undefined : text;\r\n};\r\n\r\n/**\r\n * Best available human-readable message for a rejection of unknown shape.\r\n *\r\n * Resolution order, first match wins:\r\n * 1. the rejection itself, when it is a non-empty string;\r\n * 2. `error.response.data.body` — the SAME envelope's third key;\r\n * 3. `error.response.data.message` — the backend's own message;\r\n * 4. `error.response.data.error` — the SAME envelope's alternate key;\r\n * 5. `error.message` — **only when it is not a transport artefact** (G-07);\r\n * 6. `fallback`.\r\n *\r\n * Step 4 closes capability gap G-08. Several PORTNET back-ends populate\r\n * `data.error` rather than `data.message` (addpe-fe declares BOTH on its\r\n * `ApiErrorBody` and read both at seven call sites), so a helper that stopped at\r\n * `data.message` skipped a real business message and fell through to the generic\r\n * fallback — which made it non-substitutable for the module-local extractors it\r\n * exists to replace. Strictly additive: what step 4 now catches previously\r\n * reached step 5 or 6.\r\n *\r\n * Step 2 closes G-08bis — the same defect, a third key. `caution-ui`'s axios\r\n * interceptor reads `error.response.data.body ?? error.response.data.message`,\r\n * so on that back-end a helper stopping at `message` again skipped a real\r\n * business message. Without step 2 the helper was non-substitutable there and\r\n * the module would have had to keep its own assertion-based extractor.\r\n *\r\n * WHY STEP 2 SITS BEFORE `message` AND NOT AFTER `error`.\r\n * `caution-ui` uses `??`, which is direct evidence that a single response can\r\n * carry both keys and that `body` is the one that back-end means. Appending\r\n * `body` at the end of the envelope hops would therefore have SILENTLY FLIPPED\r\n * which message its users see. Placing it first preserves that precedence, and\r\n * is provably a no-op for every module that does not populate `body`: `readPath`\r\n * returns `undefined` and resolution falls straight through to `message`.\r\n *\r\n * The one case this perturbs is a back-end that populates BOTH `body` and\r\n * `message` while intending `message` to win. No such module exists in the\r\n * portfolio — addpe-fe's `ApiErrorBody` declares `message` and `error`, not\r\n * `body` — and a module in that position should say so here rather than have the\r\n * order guessed for it.\r\n *\r\n * Step 5 is filtered: `\"Request failed with status code 500\"`, `\"Network Error\"`,\r\n * timeouts and errno codes are SUPPRESSED so the caller's own French copy is\r\n * used instead (Charter §09.3 — no raw technical detail). A message a module\r\n * threw deliberately still passes through. Use `getApiErrorDetail` when you want\r\n * the unfiltered string for a log.\r\n *\r\n * Never throws and never returns an empty string, so it is safe to render\r\n * directly into a toast or a `Banner`.\r\n *\r\n * @param error The caught value. `unknown` by design.\r\n * @param fallback Message when nothing usable is found.\r\n */\r\nexport function getApiErrorMessage(\r\n error: unknown,\r\n fallback: string = DEFAULT_API_ERROR_MESSAGE\r\n): string {\r\n if (typeof error === \"string\" && error.length > 0) return error;\r\n\r\n return (\r\n asNonEmptyString(readPath(error, [\"response\", \"data\", \"body\"])) ??\r\n asNonEmptyString(readPath(error, [\"response\", \"data\", \"message\"])) ??\r\n asNonEmptyString(readPath(error, [\"response\", \"data\", \"error\"])) ??\r\n asUserFacingMessage(readPath(error, [\"message\"])) ??\r\n fallback\r\n );\r\n}\r\n\r\n/**\r\n * Unfiltered technical detail for LOGGING — never for display.\r\n *\r\n * `getApiErrorMessage` deliberately suppresses transport phrasings (G-07), which\r\n * is right for a toast and wrong for a console or an APM breadcrumb, where\r\n * `\"Request failed with status code 502\"` is exactly what an operator needs. This\r\n * is the escape hatch: it returns the raw `error.message` when there is one,\r\n * whatever its shape.\r\n *\r\n * Pair them:\r\n *\r\n * toast(getApiErrorMessage(err, \"Échec de l'envoi.\"), \"error\");\r\n * console.error(\"[submit]\", getApiErrorStatus(err), getApiErrorDetail(err));\r\n */\r\nexport function getApiErrorDetail(error: unknown): string | undefined {\r\n if (typeof error === \"string\" && error.length > 0) return error;\r\n return asNonEmptyString(readPath(error, [\"message\"]));\r\n}\r\n\r\n/**\r\n * HTTP status carried by a rejection, when there is one.\r\n *\r\n * Resolution order, first numeric match wins:\r\n * 1. `error.response.data.status` — a BODY-level status;\r\n * 2. `error.response.status` — the transport status.\r\n *\r\n * Returns `undefined` for a network drop, a timeout, or any non-HTTP rejection —\r\n * which is the signal callers use to distinguish \"the server answered with an\r\n * error\" from \"there was no answer at all\" (Charter R-4.3: a status-less failure\r\n * is a network banner, not a toast).\r\n *\r\n * Step 1 closes G-08ter, the status-side counterpart of the envelope-key gaps\r\n * G-08 / G-08bis. Several PORTNET back-ends put the meaningful status in the\r\n * BODY: caution-ui's axios interceptor reads\r\n * `error.response.data.status ?? error.response.status` and routes on the\r\n * result (404 -> not-found page, 500 -> server-error page, 401 -> re-login), and\r\n * its RESPONSE interceptor does the same for success handling. A helper reading\r\n * only the transport status was therefore not substitutable there — the module\r\n * had to keep a hand-written `HttpErrorLike` interface and assert onto it, which\r\n * is exactly the anti-pattern G-04 exists to end. Closing the message side\r\n * (G-08bis) without the status side would have left that assertion in place for\r\n * the sake of one field.\r\n *\r\n * Body-first ordering mirrors the module's own `??` and is provably a no-op for\r\n * every back-end that does not populate `data.status`: `readPath` returns\r\n * `undefined` and resolution falls through to the transport status.\r\n *\r\n * BOTH hops are numeric-guarded, which is a deliberate tightening over the\r\n * module code being replaced. That code did `String(status)` on whatever it\r\n * found, so a body carrying `status: \"ERROR\"` produced a `String` switch miss\r\n * and fell to the default toast branch; here a non-numeric `data.status` is\r\n * ignored and the real transport status is used instead. That is the more useful\r\n * answer, and it keeps the return type honest — the signature promises a number.\r\n */\r\nexport function getApiErrorStatus(error: unknown): number | undefined {\r\n const bodyStatus = readPath(error, [\"response\", \"data\", \"status\"]);\r\n if (typeof bodyStatus === \"number\") return bodyStatus;\r\n\r\n const status = readPath(error, [\"response\", \"status\"]);\r\n return typeof status === \"number\" ? status : undefined;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,IAAMA,yBAAyB,GAAAC,OAAA,CAAAD,yBAAA,GACpC,8CAA8C;;AAEhD;AACA;AACA;AACA;AACA,IAAME,QAAQ,GAAG,SAAXA,QAAQA,CAAIC,MAAe,EAAEC,IAAuB,EAAc;EACtE,IAAIC,OAAgB,GAAGF,MAAM;EAAC,IAAAG,SAAA,GAAAC,0BAAA,CAEZH,IAAI;IAAAI,KAAA;EAAA;IAAtB,KAAAF,SAAA,CAAAG,CAAA,MAAAD,KAAA,GAAAF,SAAA,CAAAI,CAAA,IAAAC,IAAA,GAAwB;MAAA,IAAbC,GAAG,GAAAJ,KAAA,CAAAK,KAAA;MACZ,IAAIC,OAAA,CAAOT,OAAO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ChEL,mBAAmB,CAAC3B,QAAQ,CAAC8B,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,cAAAC,IAAA,cAAAA,IAAA,GACjDI,QAAQ;AAEZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,iBAAiBA,CAACP,KAAc,EAAsB;EACpE,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACV,MAAM,GAAG,CAAC,EAAE,OAAOU,KAAK;EAC/D,OAAOX,gBAAgB,CAACnB,QAAQ,CAAC8B,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AACvD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASQ,iBAAiBA,CAACR,KAAc,EAAsB;EACpE,IAAMS,UAAU,GAAGvC,QAAQ,CAAC8B,KAAK,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;EAClE,IAAI,OAAOS,UAAU,KAAK,QAAQ,EAAE,OAAOA,UAAU;EAErD,IAAMC,MAAM,GAAGxC,QAAQ,CAAC8B,KAAK,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;EACtD,OAAO,OAAOU,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAG3B,SAAS;AACxD","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"apiError.js","names":["DEFAULT_API_ERROR_MESSAGE","exports","readPath","source","path","current","key","undefined","Reflect","get","asNonEmptyString","value","length","TRANSPORT_MESSAGE_PATTERNS","isTransportMessage","some","pattern","test","trim","asUserFacingMessage","text","getApiErrorMessage","error","fallback","getApiErrorDetail","getApiErrorStatus","bodyStatus","status"],"sources":["../../../src/lib/v2/utils/apiError.ts"],"sourcesContent":["/**\r\n * apiError — narrow an `unknown` rejection into something displayable.\r\n *\r\n * ─────────────────────────────────────────────────────────────────────────────\r\n * WHY THIS BELONGS IN THE LIBRARY (capability gap G-04)\r\n *\r\n * The Platform TypeScript Guidelines mandate `useUnknownInCatchVariables`, so\r\n * `catch (e)` binds `unknown` in EVERY saga of EVERY consuming module. The same\r\n * guidelines forbid `any` and unsafe assertions. Between those two rules sits a\r\n * narrowing helper that the library did not provide — so each module wrote its\r\n * own, and the observed outcome was that they wrote it the forbidden way:\r\n *\r\n * (error as { response?: { data?: { message?: unknown } } }).response\r\n *\r\n * i.e. an unchecked assertion on an `unknown`, used to work around a flag the\r\n * platform imposes. Two modules audited (`procuration-portnet-fe`,\r\n * `procuration-fe`) had independently reached for exactly that construct.\r\n * A mandated strict-mode flag with no sanctioned escape hatch produces\r\n * unsanctioned ones.\r\n *\r\n * Implementation notes\r\n * --------------------\r\n * `readPath` walks nested objects using the `in` operator, which narrows without\r\n * an assertion, and `Reflect.get`, which returns the value as `unknown` rather\r\n * than widening anything to `any`. No assertion appears anywhere in this file.\r\n *\r\n * Deliberately DUCK-TYPED rather than built on `axios.isAxiosError`. Three\r\n * reasons: this library must not take a hard axios dependency for a string\r\n * helper; a plain object shaped like an axios error (a hand-rolled reject, a\r\n * test double, a non-axios transport) still resolves correctly; and the check\r\n * stays valid across axios majors.\r\n * ─────────────────────────────────────────────────────────────────────────────\r\n *\r\n * getApiErrorMessage(err) → backend message, or the default\r\n * getApiErrorMessage(err, \"Échec de l'envoi.\") → custom fallback\r\n * getApiErrorStatus(err) → 404 | undefined\r\n *\r\n * Envelope keys read, in order: `data.body`, `data.message`, `data.error`.\r\n * Three keys because three PORTNET back-ends chose differently; see the\r\n * resolution-order note on `getApiErrorMessage` before adding a fourth.\r\n */\r\n\r\n/**\r\n * Default user-facing fallback. French per Charter §09 (voice, vouvoiement) and\r\n * §09.3 (no raw technical detail — never \"Erreur 422 Unprocessable Entity\").\r\n * Override per call site when a screen can say something more useful.\r\n */\r\nexport const DEFAULT_API_ERROR_MESSAGE =\r\n \"Une erreur est survenue. Veuillez réessayer.\";\r\n\r\n/**\r\n * Walk `path` through nested non-null objects, returning the value at the end,\r\n * or `undefined` if any hop is missing. Assertion-free.\r\n */\r\nconst readPath = (source: unknown, path: readonly string[]): unknown => {\r\n let current: unknown = source;\r\n\r\n for (const key of path) {\r\n if (typeof current !== \"object\" || current === null || !(key in current)) {\r\n return undefined;\r\n }\r\n current = Reflect.get(current, key);\r\n }\r\n\r\n return current;\r\n};\r\n\r\nconst asNonEmptyString = (value: unknown): string | undefined =>\r\n typeof value === \"string\" && value.length > 0 ? value : undefined;\r\n\r\n/**\r\n * Transport-layer phrasings that must NEVER reach a user — capability gap G-07.\r\n *\r\n * ──────────────────────────────────────────────────────────────────────\r\n * THE DEFECT THIS FIXES\r\n *\r\n * `getApiErrorMessage` resolved `error.message` BEFORE its fallback. An\r\n * `AxiosError` always has `.message`, so on any server error carrying no\r\n * `response.data.message` — a 500 with an empty body, a gateway error, a\r\n * timeout — step 3 won and the user was shown:\r\n *\r\n * \"Request failed with status code 500\"\r\n *\r\n * English, technical, and precisely the shape Charter §09.3 names as forbidden\r\n * (\"✗ « Erreur 422 — Unprocessable Entity »\"). Worse, it made every consuming\r\n * module's carefully-written French fallback effectively UNREACHABLE — the\r\n * argument was accepted and then almost never used. Found during the\r\n * `procuration-portnet-fe` Area 10 audit, where 12 call sites pass a considered\r\n * fallback that could essentially never render.\r\n *\r\n * WHY A DENY-LIST AND NOT SIMPLY DROPPING STEP 3\r\n *\r\n * Step 3 also carries LEGITIMATE messages: any `throw new Error(\"Ce titre ne\r\n * peut pas être supprimé car il est en cours de validation.\")` in module code\r\n * arrives through exactly the same path. Removing the hop would trade a leak of\r\n * technical strings for the loss of real business messages across the whole\r\n * platform — a worse outcome. So the hop stays and only transport phrasings are\r\n * suppressed.\r\n *\r\n * The list is deliberately CONSERVATIVE: anything not recognised passes through,\r\n * on the assumption a human wrote it. A false negative shows one ugly string; a\r\n * false positive silently replaces a real business message with a generic\r\n * fallback, which is the more damaging error.\r\n *\r\n * Sourced from axios's own message construction (`settle`, `AxiosError` codes\r\n * ECONNABORTED / ETIMEDOUT / ERR_NETWORK / ERR_CANCELED) plus the Node socket\r\n * phrasing that surfaces through SSR and test doubles.\r\n * ──────────────────────────────────────────────────────────────────────\r\n */\r\nconst TRANSPORT_MESSAGE_PATTERNS: readonly RegExp[] = [\r\n /^request failed with status code \\d+$/i,\r\n /^network error$/i,\r\n /^timeout of \\d+ms exceeded$/i,\r\n /^timeout exceeded$/i,\r\n /^request aborted$/i,\r\n /^canceled$/i,\r\n /^unsupported protocol/i,\r\n /^maximum content size exceeded$/i,\r\n /^socket hang up$/i,\r\n /* ── errno codes and axios error codes ── CASE-SENSITIVE, DELIBERATELY ─────\r\n *\r\n * These two are the only patterns here NOT marked `/i`, and the asymmetry is\r\n * load-bearing. errno constants are uppercase by universal convention\r\n * (`ETIMEDOUT`, `ECONNREFUSED`, `ENOTFOUND`, `EPIPE`), so an uppercase-only\r\n * match identifies them precisely. Matching case-insensitively would make\r\n * `/^e[a-z]+$/i` swallow ordinary French words beginning with \"e\" — \"erreur\",\r\n * \"expiré\", \"échec\" — turning a real business message into a generic fallback,\r\n * which is the more damaging failure this list is tuned against.\r\n *\r\n * ⚠ An earlier version of the first pattern was `/^ec[a-z]+$/i`, which matched\r\n * `ECONNREFUSED` (it begins \"EC\") but silently MISSED `ETIMEDOUT` (\"ET\"),\r\n * despite the comment claiming otherwise. The unit test caught it. Do not\r\n * narrow the prefix again: the family is \"E + uppercase word\", not \"EC...\".\r\n *\r\n * Residual, accepted: an all-caps single word like \"ERREUR\" is treated as an\r\n * errno code. A module should not be throwing all-caps single-word messages at\r\n * users, and replacing one with a proper French fallback is an improvement. */\r\n /^E[A-Z]{3,}$/, // errno: ETIMEDOUT, ECONNREFUSED, ECONNRESET, ENOTFOUND, EPIPE\r\n /^ERR_[A-Z_]+$/, // axios: ERR_NETWORK, ERR_CANCELED, ERR_BAD_RESPONSE\r\n];\r\n\r\n/** Is this string an axios/transport artefact rather than something for a user? */\r\nconst isTransportMessage = (value: string): boolean =>\r\n TRANSPORT_MESSAGE_PATTERNS.some((pattern) => pattern.test(value.trim()));\r\n\r\n/**\r\n * `error.message`, but only when it is fit to show a user.\r\n *\r\n * Suppresses transport phrasings (G-07) so the caller's French fallback is\r\n * reached instead. Module-thrown `Error` messages pass through untouched.\r\n */\r\nconst asUserFacingMessage = (value: unknown): string | undefined => {\r\n const text = asNonEmptyString(value);\r\n if (text === undefined) return undefined;\r\n return isTransportMessage(text) ? undefined : text;\r\n};\r\n\r\n/**\r\n * Best available human-readable message for a rejection of unknown shape.\r\n *\r\n * Resolution order, first match wins:\r\n * 1. the rejection itself, when it is a non-empty string;\r\n * 2. `error.response.data.body` — the SAME envelope's third key;\r\n * 3. `error.response.data.message` — the backend's own message;\r\n * 4. `error.response.data.error` — the SAME envelope's alternate key;\r\n * 5. `error.message` — **only when it is not a transport artefact** (G-07);\r\n * 6. `fallback`.\r\n *\r\n * Step 4 closes capability gap G-08. Several PORTNET back-ends populate\r\n * `data.error` rather than `data.message` (addpe-fe declares BOTH on its\r\n * `ApiErrorBody` and read both at seven call sites), so a helper that stopped at\r\n * `data.message` skipped a real business message and fell through to the generic\r\n * fallback — which made it non-substitutable for the module-local extractors it\r\n * exists to replace. Strictly additive: what step 4 now catches previously\r\n * reached step 5 or 6.\r\n *\r\n * Step 2 closes G-08bis — the same defect, a third key. `caution-ui`'s axios\r\n * interceptor reads `error.response.data.body ?? error.response.data.message`,\r\n * so on that back-end a helper stopping at `message` again skipped a real\r\n * business message. Without step 2 the helper was non-substitutable there and\r\n * the module would have had to keep its own assertion-based extractor.\r\n *\r\n * WHY STEP 2 SITS BEFORE `message` AND NOT AFTER `error`.\r\n * `caution-ui` uses `??`, which is direct evidence that a single response can\r\n * carry both keys and that `body` is the one that back-end means. Appending\r\n * `body` at the end of the envelope hops would therefore have SILENTLY FLIPPED\r\n * which message its users see. Placing it first preserves that precedence, and\r\n * is provably a no-op for every module that does not populate `body`: `readPath`\r\n * returns `undefined` and resolution falls straight through to `message`.\r\n *\r\n * The one case this perturbs is a back-end that populates BOTH `body` and\r\n * `message` while intending `message` to win. No such module exists in the\r\n * portfolio — addpe-fe's `ApiErrorBody` declares `message` and `error`, not\r\n * `body` — and a module in that position should say so here rather than have the\r\n * order guessed for it.\r\n *\r\n * Step 5 is filtered: `\"Request failed with status code 500\"`, `\"Network Error\"`,\r\n * timeouts and errno codes are SUPPRESSED so the caller's own French copy is\r\n * used instead (Charter §09.3 — no raw technical detail). A message a module\r\n * threw deliberately still passes through. Use `getApiErrorDetail` when you want\r\n * the unfiltered string for a log.\r\n *\r\n * Never throws and never returns an empty string, so it is safe to render\r\n * directly into a toast or a `Banner`.\r\n *\r\n * @param error The caught value. `unknown` by design.\r\n * @param fallback Message when nothing usable is found.\r\n */\r\nexport function getApiErrorMessage(\r\n error: unknown,\r\n fallback: string = DEFAULT_API_ERROR_MESSAGE\r\n): string {\r\n if (typeof error === \"string\" && error.length > 0) return error;\r\n\r\n return (\r\n asNonEmptyString(readPath(error, [\"response\", \"data\", \"body\"])) ??\r\n asNonEmptyString(readPath(error, [\"response\", \"data\", \"message\"])) ??\r\n asNonEmptyString(readPath(error, [\"response\", \"data\", \"error\"])) ??\r\n asUserFacingMessage(readPath(error, [\"message\"])) ??\r\n fallback\r\n );\r\n}\r\n\r\n/**\r\n * Unfiltered technical detail for LOGGING — never for display.\r\n *\r\n * `getApiErrorMessage` deliberately suppresses transport phrasings (G-07), which\r\n * is right for a toast and wrong for a console or an APM breadcrumb, where\r\n * `\"Request failed with status code 502\"` is exactly what an operator needs. This\r\n * is the escape hatch: it returns the raw `error.message` when there is one,\r\n * whatever its shape.\r\n *\r\n * Pair them:\r\n *\r\n * toast(getApiErrorMessage(err, \"Échec de l'envoi.\"), \"error\");\r\n * console.error(\"[submit]\", getApiErrorStatus(err), getApiErrorDetail(err));\r\n */\r\nexport function getApiErrorDetail(error: unknown): string | undefined {\r\n if (typeof error === \"string\" && error.length > 0) return error;\r\n return asNonEmptyString(readPath(error, [\"message\"]));\r\n}\r\n\r\n/**\r\n * HTTP status carried by a rejection, when there is one.\r\n *\r\n * Resolution order, first numeric match wins:\r\n * 1. `error.response.data.status` — a BODY-level status;\r\n * 2. `error.response.status` — the transport status.\r\n *\r\n * Returns `undefined` for a network drop, a timeout, or any non-HTTP rejection —\r\n * which is the signal callers use to distinguish \"the server answered with an\r\n * error\" from \"there was no answer at all\" (Charter R-4.3: a status-less failure\r\n * is a network banner, not a toast).\r\n *\r\n * Step 1 closes G-08ter, the status-side counterpart of the envelope-key gaps\r\n * G-08 / G-08bis. Several PORTNET back-ends put the meaningful status in the\r\n * BODY: caution-ui's axios interceptor reads\r\n * `error.response.data.status ?? error.response.status` and routes on the\r\n * result (404 -> not-found page, 500 -> server-error page, 401 -> re-login), and\r\n * its RESPONSE interceptor does the same for success handling. A helper reading\r\n * only the transport status was therefore not substitutable there — the module\r\n * had to keep a hand-written `HttpErrorLike` interface and assert onto it, which\r\n * is exactly the anti-pattern G-04 exists to end. Closing the message side\r\n * (G-08bis) without the status side would have left that assertion in place for\r\n * the sake of one field.\r\n *\r\n * Body-first ordering mirrors the module's own `??` and is provably a no-op for\r\n * every back-end that does not populate `data.status`: `readPath` returns\r\n * `undefined` and resolution falls through to the transport status.\r\n *\r\n * BOTH hops are numeric-guarded, which is a deliberate tightening over the\r\n * module code being replaced. That code did `String(status)` on whatever it\r\n * found, so a body carrying `status: \"ERROR\"` produced a `String` switch miss\r\n * and fell to the default toast branch; here a non-numeric `data.status` is\r\n * ignored and the real transport status is used instead. That is the more useful\r\n * answer, and it keeps the return type honest — the signature promises a number.\r\n */\r\nexport function getApiErrorStatus(error: unknown): number | undefined {\r\n const bodyStatus = readPath(error, [\"response\", \"data\", \"status\"]);\r\n if (typeof bodyStatus === \"number\") return bodyStatus;\r\n\r\n const status = readPath(error, [\"response\", \"status\"]);\r\n return typeof status === \"number\" ? status : undefined;\r\n}\r\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,MAAMA,yBAAyB,GAAAC,OAAA,CAAAD,yBAAA,GACpC,8CAA8C;;AAEhD;AACA;AACA;AACA;AACA,MAAME,QAAQ,GAAGA,CAACC,MAAe,EAAEC,IAAuB,KAAc;EACtE,IAAIC,OAAgB,GAAGF,MAAM;EAE7B,KAAK,MAAMG,GAAG,IAAIF,IAAI,EAAE;IACtB,IAAI,OAAOC,OAAO,KAAK,QAAQ,IAAIA,OAAO,KAAK,IAAI,IAAI,EAAEC,GAAG,IAAID,OAAO,CAAC,EAAE;MACxE,OAAOE,SAAS;IAClB;IACAF,OAAO,GAAGG,OAAO,CAACC,GAAG,CAACJ,OAAO,EAAEC,GAAG,CAAC;EACrC;EAEA,OAAOD,OAAO;AAChB,CAAC;AAED,MAAMK,gBAAgB,GAAIC,KAAc,IACtC,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACC,MAAM,GAAG,CAAC,GAAGD,KAAK,GAAGJ,SAAS;;AAEnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,0BAA6C,GAAG,CACpD,wCAAwC,EACxC,kBAAkB,EAClB,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,wBAAwB,EACxB,kCAAkC,EAClC,mBAAmB;AACnB;AACF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M,EAAE,OAAO,CAAC,CAAC,CAAC,IAChEH,mBAAmB,CAACjB,QAAQ,CAACoB,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,IACjDC,QAAQ;AAEZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,iBAAiBA,CAACF,KAAc,EAAsB;EACpE,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACV,MAAM,GAAG,CAAC,EAAE,OAAOU,KAAK;EAC/D,OAAOZ,gBAAgB,CAACR,QAAQ,CAACoB,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AACvD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,iBAAiBA,CAACH,KAAc,EAAsB;EACpE,MAAMI,UAAU,GAAGxB,QAAQ,CAACoB,KAAK,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;EAClE,IAAI,OAAOI,UAAU,KAAK,QAAQ,EAAE,OAAOA,UAAU;EAErD,MAAMC,MAAM,GAAGzB,QAAQ,CAACoB,KAAK,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;EACtD,OAAO,OAAOK,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAGpB,SAAS;AACxD","ignoreList":[]}
|
|
@@ -8,7 +8,6 @@ exports.contrastRatio = contrastRatio;
|
|
|
8
8
|
exports.parseColor = parseColor;
|
|
9
9
|
exports.passesContrast = passesContrast;
|
|
10
10
|
exports.relativeLuminance = relativeLuminance;
|
|
11
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
12
11
|
/**
|
|
13
12
|
* WCAG 2.1 contrast utilities — Portnet UI v2
|
|
14
13
|
*
|
|
@@ -27,13 +26,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
27
26
|
/* ── WCAG AA thresholds (exported for caller readability) ──────── */
|
|
28
27
|
|
|
29
28
|
/** Normal text contrast ratio threshold (AA). */
|
|
30
|
-
|
|
29
|
+
const WCAG_AA_NORMAL = exports.WCAG_AA_NORMAL = 4.5;
|
|
31
30
|
|
|
32
31
|
/** Large text (≥ 18pt or ≥ 14pt bold) contrast ratio threshold (AA). */
|
|
33
|
-
|
|
32
|
+
const WCAG_AA_LARGE = exports.WCAG_AA_LARGE = 3.0;
|
|
34
33
|
|
|
35
34
|
/** UI components & graphical objects contrast ratio threshold (AA 1.4.11). */
|
|
36
|
-
|
|
35
|
+
const WCAG_AA_UI_NON_TEXT = exports.WCAG_AA_UI_NON_TEXT = 3.0;
|
|
37
36
|
|
|
38
37
|
/* ── Color parsing ───────────────────────── */
|
|
39
38
|
|
|
@@ -55,11 +54,11 @@ var WCAG_AA_UI_NON_TEXT = exports.WCAG_AA_UI_NON_TEXT = 3.0;
|
|
|
55
54
|
*/
|
|
56
55
|
function parseColor(input) {
|
|
57
56
|
if (typeof input !== "string") return null;
|
|
58
|
-
|
|
57
|
+
const s = input.trim();
|
|
59
58
|
|
|
60
59
|
// Hex (3, 6, or 8 digits; alpha dropped if present)
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const hexMatch = s.match(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/);
|
|
61
|
+
const hex = hexMatch?.[1];
|
|
63
62
|
if (hex) {
|
|
64
63
|
if (hex.length === 3) {
|
|
65
64
|
return {
|
|
@@ -77,17 +76,16 @@ function parseColor(input) {
|
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
// rgb() / rgba() — alpha dropped
|
|
80
|
-
|
|
79
|
+
const rgbMatch = s.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})/);
|
|
81
80
|
if (rgbMatch) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var b = parseInt((_rgbMatch$3 = rgbMatch[3]) !== null && _rgbMatch$3 !== void 0 ? _rgbMatch$3 : "", 10);
|
|
81
|
+
const r = parseInt(rgbMatch[1] ?? "", 10);
|
|
82
|
+
const g = parseInt(rgbMatch[2] ?? "", 10);
|
|
83
|
+
const b = parseInt(rgbMatch[3] ?? "", 10);
|
|
86
84
|
if (Number.isFinite(r) && r >= 0 && r <= 255 && Number.isFinite(g) && g >= 0 && g <= 255 && Number.isFinite(b) && b >= 0 && b <= 255) {
|
|
87
85
|
return {
|
|
88
|
-
r
|
|
89
|
-
g
|
|
90
|
-
b
|
|
86
|
+
r,
|
|
87
|
+
g,
|
|
88
|
+
b
|
|
91
89
|
};
|
|
92
90
|
}
|
|
93
91
|
}
|
|
@@ -98,7 +96,7 @@ function parseColor(input) {
|
|
|
98
96
|
|
|
99
97
|
/** sRGB channel → linear-light conversion per WCAG 2.1. */
|
|
100
98
|
function srgbChannelToLinear(c) {
|
|
101
|
-
|
|
99
|
+
const cs = c / 255;
|
|
102
100
|
return cs <= 0.03928 ? cs / 12.92 : Math.pow((cs + 0.055) / 1.055, 2.4);
|
|
103
101
|
}
|
|
104
102
|
|
|
@@ -108,14 +106,16 @@ function srgbChannelToLinear(c) {
|
|
|
108
106
|
* Returns a number in 0..1, or null if input is invalid.
|
|
109
107
|
*/
|
|
110
108
|
function relativeLuminance(rgb) {
|
|
111
|
-
if (!rgb ||
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
if (!rgb || typeof rgb !== "object") return null;
|
|
110
|
+
const {
|
|
111
|
+
r,
|
|
112
|
+
g,
|
|
113
|
+
b
|
|
114
|
+
} = rgb;
|
|
115
115
|
if (!Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b)) return null;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
const R = srgbChannelToLinear(r);
|
|
117
|
+
const G = srgbChannelToLinear(g);
|
|
118
|
+
const B = srgbChannelToLinear(b);
|
|
119
119
|
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -127,13 +127,13 @@ function relativeLuminance(rgb) {
|
|
|
127
127
|
* [1.0, 21.0], or null if either input is unparseable.
|
|
128
128
|
*/
|
|
129
129
|
function contrastRatio(c1, c2) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
const rgb1 = typeof c1 === "string" ? parseColor(c1) : c1;
|
|
131
|
+
const rgb2 = typeof c2 === "string" ? parseColor(c2) : c2;
|
|
132
|
+
const L1 = relativeLuminance(rgb1);
|
|
133
|
+
const L2 = relativeLuminance(rgb2);
|
|
134
134
|
if (L1 == null || L2 == null) return null;
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
const lighter = Math.max(L1, L2);
|
|
136
|
+
const darker = Math.min(L1, L2);
|
|
137
137
|
return (lighter + 0.05) / (darker + 0.05);
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -146,10 +146,9 @@ function contrastRatio(c1, c2) {
|
|
|
146
146
|
* `level` accepts "normal" | "large" | "ui". Unknown levels default
|
|
147
147
|
* to the strictest threshold.
|
|
148
148
|
*/
|
|
149
|
-
function passesContrast(ratio) {
|
|
150
|
-
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "normal";
|
|
149
|
+
function passesContrast(ratio, level = "normal") {
|
|
151
150
|
if (ratio == null || !Number.isFinite(ratio)) return false;
|
|
152
|
-
|
|
151
|
+
let threshold;
|
|
153
152
|
switch (level) {
|
|
154
153
|
case "large":
|
|
155
154
|
threshold = WCAG_AA_LARGE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contrast.js","names":["WCAG_AA_NORMAL","exports","WCAG_AA_LARGE","WCAG_AA_UI_NON_TEXT","parseColor","input","s","trim","hexMatch","match","hex","length","r","parseInt","charAt","g","b","slice","rgbMatch","_rgbMatch$","_rgbMatch$2","_rgbMatch$3","Number","isFinite","srgbChannelToLinear","c","cs","Math","pow","relativeLuminance","rgb","_typeof","R","G","B","contrastRatio","c1","c2","rgb1","rgb2","L1","L2","lighter","max","darker","min","passesContrast","ratio","level","arguments","undefined","threshold"],"sources":["../../../src/lib/v2/utils/contrast.ts"],"sourcesContent":["/**\r\n * WCAG 2.1 contrast utilities — Portnet UI v2\r\n *\r\n * Reference: https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio\r\n *\r\n * Pure functions, framework-agnostic, no deps. Reusable by any\r\n * host module that needs to validate a runtime brand override\r\n * against WCAG 1.4.3 AA (typical scenario: a host-shell event\r\n * injects a tenant brand and the consumer wants to dev-warn when\r\n * the resulting accent/foreground pair drops below 4.5:1).\r\n *\r\n * Also used by the dark-mode work (F29) to audit dual-mode token\r\n * pairs and by Storybook contrast stories.\r\n */\r\n\r\n/* ── WCAG AA thresholds (exported for caller readability) ──────── */\r\n\r\n/** Normal text contrast ratio threshold (AA). */\r\nexport const WCAG_AA_NORMAL = 4.5;\r\n\r\n/** Large text (≥ 18pt or ≥ 14pt bold) contrast ratio threshold (AA). */\r\nexport const WCAG_AA_LARGE = 3.0;\r\n\r\n/** UI components & graphical objects contrast ratio threshold (AA 1.4.11). */\r\nexport const WCAG_AA_UI_NON_TEXT = 3.0;\r\n\r\n/* ── Color parsing ───────────────────────── */\r\n\r\ntype RGB = { r: number; g: number; b: number };\r\n\r\n/**\r\n * Parse a CSS color string into an { r, g, b } object with 0..255\r\n * channels. Returns null for unparseable input.\r\n *\r\n * Supported formats:\r\n * - \"#RGB\" (3-digit hex shorthand)\r\n * - \"#RRGGBB\" (6-digit hex)\r\n * - \"#RRGGBBAA\" (8-digit hex; alpha channel is dropped)\r\n * - \"rgb(r, g, b)\"\r\n * - \"rgba(r, g, b, a)\" (alpha dropped)\r\n *\r\n * HSL / HWB / LAB / named-colors are NOT supported — the v2 token\r\n * surface and observed host-shell brand payloads are always hex\r\n * or rgb(). A wider parser can be swapped in later without\r\n * changing the public API of this function.\r\n */\r\nexport function parseColor(input: unknown): RGB | null {\r\n if (typeof input !== \"string\") return null;\r\n const s = input.trim();\r\n\r\n // Hex (3, 6, or 8 digits; alpha dropped if present)\r\n const hexMatch = s.match(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/);\r\n const hex = hexMatch?.[1];\r\n if (hex) {\r\n if (hex.length === 3) {\r\n return {\r\n r: parseInt(hex.charAt(0) + hex.charAt(0), 16),\r\n g: parseInt(hex.charAt(1) + hex.charAt(1), 16),\r\n b: parseInt(hex.charAt(2) + hex.charAt(2), 16),\r\n };\r\n }\r\n // 6 or 8 digit — first 6 chars are RGB\r\n return {\r\n r: parseInt(hex.slice(0, 2), 16),\r\n g: parseInt(hex.slice(2, 4), 16),\r\n b: parseInt(hex.slice(4, 6), 16),\r\n };\r\n }\r\n\r\n // rgb() / rgba() — alpha dropped\r\n const rgbMatch = s.match(\r\n /^rgba?\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})/\r\n );\r\n if (rgbMatch) {\r\n const r = parseInt(rgbMatch[1] ?? \"\", 10);\r\n const g = parseInt(rgbMatch[2] ?? \"\", 10);\r\n const b = parseInt(rgbMatch[3] ?? \"\", 10);\r\n if (\r\n Number.isFinite(r) && r >= 0 && r <= 255 &&\r\n Number.isFinite(g) && g >= 0 && g <= 255 &&\r\n Number.isFinite(b) && b >= 0 && b <= 255\r\n ) {\r\n return { r, g, b };\r\n }\r\n }\r\n\r\n return null;\r\n}\r\n\r\n/* ── Luminance & ratio ───────────────────── */\r\n\r\n/** sRGB channel → linear-light conversion per WCAG 2.1. */\r\nfunction srgbChannelToLinear(c: number): number {\r\n const cs = c / 255;\r\n return cs <= 0.03928 ? cs / 12.92 : Math.pow((cs + 0.055) / 1.055, 2.4);\r\n}\r\n\r\n/**\r\n * Compute relative luminance of an sRGB color per WCAG 2.1.\r\n * Accepts an { r, g, b } object (channels in 0..255).\r\n * Returns a number in 0..1, or null if input is invalid.\r\n */\r\nexport function relativeLuminance(rgb: RGB | null | undefined): number | null {\r\n if (!rgb || typeof rgb !== \"object\") return null;\r\n const { r, g, b } = rgb;\r\n if (\r\n !Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b)\r\n ) return null;\r\n const R = srgbChannelToLinear(r);\r\n const G = srgbChannelToLinear(g);\r\n const B = srgbChannelToLinear(b);\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B;\r\n}\r\n\r\n/**\r\n * WCAG contrast ratio between two colors.\r\n *\r\n * Accepts either CSS color strings (parsed via parseColor) or\r\n * already-parsed { r, g, b } objects. Returns a number in\r\n * [1.0, 21.0], or null if either input is unparseable.\r\n */\r\nexport function contrastRatio(\r\n c1: string | RGB,\r\n c2: string | RGB\r\n): number | null {\r\n const rgb1 = typeof c1 === \"string\" ? parseColor(c1) : c1;\r\n const rgb2 = typeof c2 === \"string\" ? parseColor(c2) : c2;\r\n const L1 = relativeLuminance(rgb1);\r\n const L2 = relativeLuminance(rgb2);\r\n if (L1 == null || L2 == null) return null;\r\n const lighter = Math.max(L1, L2);\r\n const darker = Math.min(L1, L2);\r\n return (lighter + 0.05) / (darker + 0.05);\r\n}\r\n\r\n/**\r\n * Verdict helper — `passesContrast(ratio, \"normal\")` returns true\r\n * if the ratio meets the requested WCAG AA threshold. Returns\r\n * false on null ratios so callers can treat unparseable inputs as\r\n * failures.\r\n *\r\n * `level` accepts \"normal\" | \"large\" | \"ui\". Unknown levels default\r\n * to the strictest threshold.\r\n */\r\nexport function passesContrast(\r\n ratio: number | null | undefined,\r\n level: \"normal\" | \"large\" | \"ui\" = \"normal\"\r\n): boolean {\r\n if (ratio == null || !Number.isFinite(ratio)) return false;\r\n let threshold: number;\r\n switch (level) {\r\n case \"large\":\r\n threshold = WCAG_AA_LARGE;\r\n break;\r\n case \"ui\":\r\n threshold = WCAG_AA_UI_NON_TEXT;\r\n break;\r\n case \"normal\":\r\n default:\r\n threshold = WCAG_AA_NORMAL;\r\n break;\r\n }\r\n return ratio >= threshold;\r\n}\r\n"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACO,IAAMA,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,GAAG;;AAEjC;AACO,IAAME,aAAa,GAAAD,OAAA,CAAAC,aAAA,GAAG,GAAG;;AAEhC;AACO,IAAMC,mBAAmB,GAAAF,OAAA,CAAAE,mBAAA,GAAG,GAAG;;AAEtC;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAACC,KAAc,EAAc;EACrD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE,OAAO,IAAI;EAC1C,IAAMC,CAAC,GAAGD,KAAK,CAACE,IAAI,CAAC,CAAC;;EAEtB;EACA,IAAMC,QAAQ,GAAGF,CAAC,CAACG,KAAK,CAAC,mDAAmD,CAAC;EAC7E,IAAMC,GAAG,GAAGF,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAG,CAAC,CAAC;EACzB,IAAIE,GAAG,EAAE;IACP,IAAIA,GAAG,CAACC,MAAM,KAAK,CAAC,EAAE;MACpB,OAAO;QACLC,CAAC,EAAEC,QAAQ,CAACH,GAAG,CAACI,MAAM,CAAC,CAAC,CAAC,GAAGJ,GAAG,CAACI,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAC9CC,CAAC,EAAEF,QAAQ,CAACH,GAAG,CAACI,MAAM,CAAC,CAAC,CAAC,GAAGJ,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|
+
{"version":3,"file":"contrast.js","names":["WCAG_AA_NORMAL","exports","WCAG_AA_LARGE","WCAG_AA_UI_NON_TEXT","parseColor","input","s","trim","hexMatch","match","hex","length","r","parseInt","charAt","g","b","slice","rgbMatch","Number","isFinite","srgbChannelToLinear","c","cs","Math","pow","relativeLuminance","rgb","R","G","B","contrastRatio","c1","c2","rgb1","rgb2","L1","L2","lighter","max","darker","min","passesContrast","ratio","level","threshold"],"sources":["../../../src/lib/v2/utils/contrast.ts"],"sourcesContent":["/**\r\n * WCAG 2.1 contrast utilities — Portnet UI v2\r\n *\r\n * Reference: https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio\r\n *\r\n * Pure functions, framework-agnostic, no deps. Reusable by any\r\n * host module that needs to validate a runtime brand override\r\n * against WCAG 1.4.3 AA (typical scenario: a host-shell event\r\n * injects a tenant brand and the consumer wants to dev-warn when\r\n * the resulting accent/foreground pair drops below 4.5:1).\r\n *\r\n * Also used by the dark-mode work (F29) to audit dual-mode token\r\n * pairs and by Storybook contrast stories.\r\n */\r\n\r\n/* ── WCAG AA thresholds (exported for caller readability) ──────── */\r\n\r\n/** Normal text contrast ratio threshold (AA). */\r\nexport const WCAG_AA_NORMAL = 4.5;\r\n\r\n/** Large text (≥ 18pt or ≥ 14pt bold) contrast ratio threshold (AA). */\r\nexport const WCAG_AA_LARGE = 3.0;\r\n\r\n/** UI components & graphical objects contrast ratio threshold (AA 1.4.11). */\r\nexport const WCAG_AA_UI_NON_TEXT = 3.0;\r\n\r\n/* ── Color parsing ───────────────────────── */\r\n\r\ntype RGB = { r: number; g: number; b: number };\r\n\r\n/**\r\n * Parse a CSS color string into an { r, g, b } object with 0..255\r\n * channels. Returns null for unparseable input.\r\n *\r\n * Supported formats:\r\n * - \"#RGB\" (3-digit hex shorthand)\r\n * - \"#RRGGBB\" (6-digit hex)\r\n * - \"#RRGGBBAA\" (8-digit hex; alpha channel is dropped)\r\n * - \"rgb(r, g, b)\"\r\n * - \"rgba(r, g, b, a)\" (alpha dropped)\r\n *\r\n * HSL / HWB / LAB / named-colors are NOT supported — the v2 token\r\n * surface and observed host-shell brand payloads are always hex\r\n * or rgb(). A wider parser can be swapped in later without\r\n * changing the public API of this function.\r\n */\r\nexport function parseColor(input: unknown): RGB | null {\r\n if (typeof input !== \"string\") return null;\r\n const s = input.trim();\r\n\r\n // Hex (3, 6, or 8 digits; alpha dropped if present)\r\n const hexMatch = s.match(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/);\r\n const hex = hexMatch?.[1];\r\n if (hex) {\r\n if (hex.length === 3) {\r\n return {\r\n r: parseInt(hex.charAt(0) + hex.charAt(0), 16),\r\n g: parseInt(hex.charAt(1) + hex.charAt(1), 16),\r\n b: parseInt(hex.charAt(2) + hex.charAt(2), 16),\r\n };\r\n }\r\n // 6 or 8 digit — first 6 chars are RGB\r\n return {\r\n r: parseInt(hex.slice(0, 2), 16),\r\n g: parseInt(hex.slice(2, 4), 16),\r\n b: parseInt(hex.slice(4, 6), 16),\r\n };\r\n }\r\n\r\n // rgb() / rgba() — alpha dropped\r\n const rgbMatch = s.match(\r\n /^rgba?\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})/\r\n );\r\n if (rgbMatch) {\r\n const r = parseInt(rgbMatch[1] ?? \"\", 10);\r\n const g = parseInt(rgbMatch[2] ?? \"\", 10);\r\n const b = parseInt(rgbMatch[3] ?? \"\", 10);\r\n if (\r\n Number.isFinite(r) && r >= 0 && r <= 255 &&\r\n Number.isFinite(g) && g >= 0 && g <= 255 &&\r\n Number.isFinite(b) && b >= 0 && b <= 255\r\n ) {\r\n return { r, g, b };\r\n }\r\n }\r\n\r\n return null;\r\n}\r\n\r\n/* ── Luminance & ratio ───────────────────── */\r\n\r\n/** sRGB channel → linear-light conversion per WCAG 2.1. */\r\nfunction srgbChannelToLinear(c: number): number {\r\n const cs = c / 255;\r\n return cs <= 0.03928 ? cs / 12.92 : Math.pow((cs + 0.055) / 1.055, 2.4);\r\n}\r\n\r\n/**\r\n * Compute relative luminance of an sRGB color per WCAG 2.1.\r\n * Accepts an { r, g, b } object (channels in 0..255).\r\n * Returns a number in 0..1, or null if input is invalid.\r\n */\r\nexport function relativeLuminance(rgb: RGB | null | undefined): number | null {\r\n if (!rgb || typeof rgb !== \"object\") return null;\r\n const { r, g, b } = rgb;\r\n if (\r\n !Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b)\r\n ) return null;\r\n const R = srgbChannelToLinear(r);\r\n const G = srgbChannelToLinear(g);\r\n const B = srgbChannelToLinear(b);\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B;\r\n}\r\n\r\n/**\r\n * WCAG contrast ratio between two colors.\r\n *\r\n * Accepts either CSS color strings (parsed via parseColor) or\r\n * already-parsed { r, g, b } objects. Returns a number in\r\n * [1.0, 21.0], or null if either input is unparseable.\r\n */\r\nexport function contrastRatio(\r\n c1: string | RGB,\r\n c2: string | RGB\r\n): number | null {\r\n const rgb1 = typeof c1 === \"string\" ? parseColor(c1) : c1;\r\n const rgb2 = typeof c2 === \"string\" ? parseColor(c2) : c2;\r\n const L1 = relativeLuminance(rgb1);\r\n const L2 = relativeLuminance(rgb2);\r\n if (L1 == null || L2 == null) return null;\r\n const lighter = Math.max(L1, L2);\r\n const darker = Math.min(L1, L2);\r\n return (lighter + 0.05) / (darker + 0.05);\r\n}\r\n\r\n/**\r\n * Verdict helper — `passesContrast(ratio, \"normal\")` returns true\r\n * if the ratio meets the requested WCAG AA threshold. Returns\r\n * false on null ratios so callers can treat unparseable inputs as\r\n * failures.\r\n *\r\n * `level` accepts \"normal\" | \"large\" | \"ui\". Unknown levels default\r\n * to the strictest threshold.\r\n */\r\nexport function passesContrast(\r\n ratio: number | null | undefined,\r\n level: \"normal\" | \"large\" | \"ui\" = \"normal\"\r\n): boolean {\r\n if (ratio == null || !Number.isFinite(ratio)) return false;\r\n let threshold: number;\r\n switch (level) {\r\n case \"large\":\r\n threshold = WCAG_AA_LARGE;\r\n break;\r\n case \"ui\":\r\n threshold = WCAG_AA_UI_NON_TEXT;\r\n break;\r\n case \"normal\":\r\n default:\r\n threshold = WCAG_AA_NORMAL;\r\n break;\r\n }\r\n return ratio >= threshold;\r\n}\r\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACO,MAAMA,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,GAAG;;AAEjC;AACO,MAAME,aAAa,GAAAD,OAAA,CAAAC,aAAA,GAAG,GAAG;;AAEhC;AACO,MAAMC,mBAAmB,GAAAF,OAAA,CAAAE,mBAAA,GAAG,GAAG;;AAEtC;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAACC,KAAc,EAAc;EACrD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE,OAAO,IAAI;EAC1C,MAAMC,CAAC,GAAGD,KAAK,CAACE,IAAI,CAAC,CAAC;;EAEtB;EACA,MAAMC,QAAQ,GAAGF,CAAC,CAACG,KAAK,CAAC,mDAAmD,CAAC;EAC7E,MAAMC,GAAG,GAAGF,QAAQ,GAAG,CAAC,CAAC;EACzB,IAAIE,GAAG,EAAE;IACP,IAAIA,GAAG,CAACC,MAAM,KAAK,CAAC,EAAE;MACpB,OAAO;QACLC,CAAC,EAAEC,QAAQ,CAACH,GAAG,CAACI,MAAM,CAAC,CAAC,CAAC,GAAGJ,GAAG,CAACI,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAC9CC,CAAC,EAAEF,QAAQ,CAACH,GAAG,CAACI,MAAM,CAAC,CAAC,CAAC,GAAGJ,GAAG,CAACI,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAC9CE,CAAC,EAAEH,QAAQ,CAACH,GAAG,CAACI,MAAM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EAClC,IAAIC,EAAE,IAAI,IAAI,IAAIC,EAAE,IAAI,IAAI,EAAE,OAAO,IAAI;EACzC,MAAMC,OAAO,GAAGd,IAAI,CAACe,GAAG,CAACH,EAAE,EAAEC,EAAE,CAAC;EAChC,MAAMG,MAAM,GAAIhB,IAAI,CAACiB,GAAG,CAACL,EAAE,EAAEC,EAAE,CAAC;EAChC,OAAO,CAACC,OAAO,GAAG,IAAI,KAAKE,MAAM,GAAG,IAAI,CAAC;AAC3C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,cAAcA,CAC5BC,KAAgC,EAChCC,KAAgC,GAAG,QAAQ,EAClC;EACT,IAAID,KAAK,IAAI,IAAI,IAAI,CAACxB,MAAM,CAACC,QAAQ,CAACuB,KAAK,CAAC,EAAE,OAAO,KAAK;EAC1D,IAAIE,SAAiB;EACrB,QAAQD,KAAK;IACX,KAAK,OAAO;MACVC,SAAS,GAAG3C,aAAa;MACzB;IACF,KAAK,IAAI;MACP2C,SAAS,GAAG1C,mBAAmB;MAC/B;IACF,KAAK,QAAQ;IACb;MACE0C,SAAS,GAAG7C,cAAc;MAC1B;EACJ;EACA,OAAO2C,KAAK,IAAIE,SAAS;AAC3B","ignoreList":[]}
|
package/dist/v2/utils/cx.js
CHANGED
|
@@ -4,42 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.cx = cx;
|
|
7
|
-
exports
|
|
8
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
13
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
14
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
17
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
18
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
7
|
+
exports.default = void 0;
|
|
19
8
|
/**
|
|
20
9
|
* cx — minimal classnames composer
|
|
21
10
|
*
|
|
22
11
|
* cx("a", cond && "b", { "c": isC }) → "a b c"
|
|
23
12
|
*/
|
|
24
13
|
|
|
25
|
-
function cx() {
|
|
26
|
-
|
|
27
|
-
for (
|
|
28
|
-
args[_key] = arguments[_key];
|
|
29
|
-
}
|
|
30
|
-
for (var _i = 0, _args = args; _i < _args.length; _i++) {
|
|
31
|
-
var a = _args[_i];
|
|
14
|
+
function cx(...args) {
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const a of args) {
|
|
32
17
|
if (!a) continue;
|
|
33
|
-
if (typeof a === "string" || typeof a === "number") out.push(String(a));else if (Array.isArray(a)) out.push(cx
|
|
34
|
-
for (
|
|
35
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
|
36
|
-
k = _Object$entries$_i[0],
|
|
37
|
-
v = _Object$entries$_i[1];
|
|
38
|
-
if (v) out.push(k);
|
|
39
|
-
}
|
|
18
|
+
if (typeof a === "string" || typeof a === "number") out.push(String(a));else if (Array.isArray(a)) out.push(cx(...a));else if (typeof a === "object") {
|
|
19
|
+
for (const [k, v] of Object.entries(a)) if (v) out.push(k);
|
|
40
20
|
}
|
|
41
21
|
}
|
|
42
22
|
return out.join(" ");
|
|
43
23
|
}
|
|
44
|
-
var _default = exports
|
|
24
|
+
var _default = exports.default = cx;
|
|
45
25
|
//# sourceMappingURL=cx.js.map
|
package/dist/v2/utils/cx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cx.js","names":["cx","
|
|
1
|
+
{"version":3,"file":"cx.js","names":["cx","args","out","a","push","String","Array","isArray","k","v","Object","entries","join","_default","exports","default"],"sources":["../../../src/lib/v2/utils/cx.ts"],"sourcesContent":["/**\r\n * cx — minimal classnames composer\r\n *\r\n * cx(\"a\", cond && \"b\", { \"c\": isC }) → \"a b c\"\r\n */\r\ntype ClassValue =\r\n | string\r\n | number\r\n | null\r\n | undefined\r\n | boolean\r\n | ClassValue[]\r\n | Record<string, unknown>;\r\n\r\nexport function cx(...args: ClassValue[]): string {\r\n const out: string[] = [];\r\n for (const a of args) {\r\n if (!a) continue;\r\n if (typeof a === \"string\" || typeof a === \"number\") out.push(String(a));\r\n else if (Array.isArray(a)) out.push(cx(...a));\r\n else if (typeof a === \"object\") {\r\n for (const [k, v] of Object.entries(a)) if (v) out.push(k);\r\n }\r\n }\r\n return out.join(\" \");\r\n}\r\n\r\nexport default cx;\r\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAUO,SAASA,EAAEA,CAAC,GAAGC,IAAkB,EAAU;EAChD,MAAMC,GAAa,GAAG,EAAE;EACxB,KAAK,MAAMC,CAAC,IAAIF,IAAI,EAAE;IACpB,IAAI,CAACE,CAAC,EAAE;IACR,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAED,GAAG,CAACE,IAAI,CAACC,MAAM,CAACF,CAAC,CAAC,CAAC,CAAC,KACnE,IAAIG,KAAK,CAACC,OAAO,CAACJ,CAAC,CAAC,EAAED,GAAG,CAACE,IAAI,CAACJ,EAAE,CAAC,GAAGG,CAAC,CAAC,CAAC,CAAC,KACzC,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;MAC9B,KAAK,MAAM,CAACK,CAAC,EAAEC,CAAC,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACR,CAAC,CAAC,EAAE,IAAIM,CAAC,EAAEP,GAAG,CAACE,IAAI,CAACI,CAAC,CAAC;IAC5D;EACF;EACA,OAAON,GAAG,CAACU,IAAI,CAAC,GAAG,CAAC;AACtB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcf,EAAE","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
exports.downloadBase64File = downloadBase64File;
|
|
8
8
|
exports.downloadBlobFile = downloadBlobFile;
|
|
9
9
|
exports.getMimeType = getMimeType;
|
|
@@ -37,7 +37,7 @@ exports.openBase64FileInTab = openBase64FileInTab;
|
|
|
37
37
|
* browser download the file rather than attempt to render it — the safe
|
|
38
38
|
* default for an unknown payload.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
const MIME_TYPES = Object.freeze({
|
|
41
41
|
// Documents
|
|
42
42
|
pdf: "application/pdf",
|
|
43
43
|
doc: "application/msword",
|
|
@@ -66,8 +66,7 @@ var MIME_TYPES = Object.freeze({
|
|
|
66
66
|
* @returns The mapped MIME type, or "application/octet-stream".
|
|
67
67
|
*/
|
|
68
68
|
function getMimeType(extension) {
|
|
69
|
-
|
|
70
|
-
return (_MIME_TYPES$extension = MIME_TYPES[extension.toLowerCase()]) !== null && _MIME_TYPES$extension !== void 0 ? _MIME_TYPES$extension : "application/octet-stream";
|
|
69
|
+
return MIME_TYPES[extension.toLowerCase()] ?? "application/octet-stream";
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
/**
|
|
@@ -91,15 +90,15 @@ function downloadBase64File(base64Data, fileName, extension) {
|
|
|
91
90
|
if (typeof document === "undefined" || typeof atob === "undefined") {
|
|
92
91
|
return false;
|
|
93
92
|
}
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
let url = null;
|
|
94
|
+
let link = null;
|
|
96
95
|
try {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
for (
|
|
96
|
+
const binary = atob(base64Data);
|
|
97
|
+
const bytes = new Uint8Array(binary.length);
|
|
98
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
100
99
|
bytes[i] = binary.charCodeAt(i);
|
|
101
100
|
}
|
|
102
|
-
|
|
101
|
+
const blob = new Blob([bytes], {
|
|
103
102
|
type: getMimeType(extension)
|
|
104
103
|
});
|
|
105
104
|
url = URL.createObjectURL(blob);
|
|
@@ -130,7 +129,7 @@ function downloadBase64File(base64Data, fileName, extension) {
|
|
|
130
129
|
* revoking early shows the user a blank tab, while being late costs one
|
|
131
130
|
* short-lived blob.
|
|
132
131
|
*/
|
|
133
|
-
|
|
132
|
+
const PREVIEW_REVOKE_DELAY_MS = 60_000;
|
|
134
133
|
|
|
135
134
|
/**
|
|
136
135
|
* Decode a base64 payload and open it in a new tab for preview.
|
|
@@ -160,22 +159,20 @@ function openBase64FileInTab(base64Data, extension) {
|
|
|
160
159
|
if (typeof window === "undefined" || typeof atob === "undefined") {
|
|
161
160
|
return false;
|
|
162
161
|
}
|
|
163
|
-
|
|
162
|
+
let url = null;
|
|
164
163
|
try {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
for (
|
|
164
|
+
const binary = atob(base64Data);
|
|
165
|
+
const bytes = new Uint8Array(binary.length);
|
|
166
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
168
167
|
bytes[i] = binary.charCodeAt(i);
|
|
169
168
|
}
|
|
170
|
-
|
|
169
|
+
const blob = new Blob([bytes], {
|
|
171
170
|
type: getMimeType(extension)
|
|
172
171
|
});
|
|
173
172
|
url = URL.createObjectURL(blob);
|
|
174
173
|
window.open(url, "_blank", "noopener,noreferrer");
|
|
175
|
-
|
|
176
|
-
window.setTimeout(
|
|
177
|
-
return URL.revokeObjectURL(revokeTarget);
|
|
178
|
-
}, PREVIEW_REVOKE_DELAY_MS);
|
|
174
|
+
const revokeTarget = url;
|
|
175
|
+
window.setTimeout(() => URL.revokeObjectURL(revokeTarget), PREVIEW_REVOKE_DELAY_MS);
|
|
179
176
|
return true;
|
|
180
177
|
} catch (error) {
|
|
181
178
|
// Revoke straight away here: nothing consumed the URL on this path.
|
|
@@ -207,8 +204,8 @@ function downloadBlobFile(blob, fileName) {
|
|
|
207
204
|
if (typeof document === "undefined" || typeof URL === "undefined") {
|
|
208
205
|
return false;
|
|
209
206
|
}
|
|
210
|
-
|
|
211
|
-
|
|
207
|
+
let url = null;
|
|
208
|
+
let link = null;
|
|
212
209
|
try {
|
|
213
210
|
url = URL.createObjectURL(blob);
|
|
214
211
|
link = document.createElement("a");
|
|
@@ -226,11 +223,11 @@ function downloadBlobFile(blob, fileName) {
|
|
|
226
223
|
if (url) URL.revokeObjectURL(url);
|
|
227
224
|
}
|
|
228
225
|
}
|
|
229
|
-
|
|
230
|
-
getMimeType
|
|
231
|
-
downloadBase64File
|
|
232
|
-
openBase64FileInTab
|
|
233
|
-
downloadBlobFile
|
|
226
|
+
const fileDownloadApi = {
|
|
227
|
+
getMimeType,
|
|
228
|
+
downloadBase64File,
|
|
229
|
+
openBase64FileInTab,
|
|
230
|
+
downloadBlobFile
|
|
234
231
|
};
|
|
235
|
-
var _default = exports
|
|
232
|
+
var _default = exports.default = fileDownloadApi;
|
|
236
233
|
//# sourceMappingURL=fileDownload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDownload.js","names":["MIME_TYPES","Object","freeze","pdf","doc","docx","xls","xlsx","csv","txt","png","jpg","jpeg","gif","bmp","webp","svg","ico","tiff","tif","getMimeType","extension","_MIME_TYPES$extension","toLowerCase","downloadBase64File","base64Data","fileName","document","atob","url","link","binary","bytes","Uint8Array","length","i","charCodeAt","blob","Blob","type","URL","createObjectURL","createElement","href","download","body","appendChild","click","error","console","parentNode","removeChild","revokeObjectURL","PREVIEW_REVOKE_DELAY_MS","openBase64FileInTab","window","open","revokeTarget","setTimeout","downloadBlobFile","fileDownloadApi","_default","exports"],"sources":["../../../src/lib/v2/utils/fileDownload.ts"],"sourcesContent":["/**\r\n * File download utilities — Portnet UI v2\r\n *\r\n * Turns a base64 payload from the API into a browser download. Every GU\r\n * module that lets a user retrieve an attached document needs this, and\r\n * before this file each one carried its own copy of the same\r\n * atob → Uint8Array → Blob → anchor sequence plus its own MIME map.\r\n *\r\n * DEPENDENCY-FREE ON PURPOSE. Multi-file (zip) bundling is deliberately NOT\r\n * here: it needs a zip library, and making that a hard dependency of the\r\n * design system would put it in every module's bundle against the\r\n * R-8.2 budget (180 KB gz initial JS) for a capability only\r\n * document-heavy modules use. If it is promoted later it belongs behind an\r\n * OPTIONAL peer dependency, the way PdfViewer sits behind pdfjs-dist and\r\n * @react-pdf-viewer/* in peerDependenciesMeta.\r\n *\r\n * Charter ref: §09.3 — the caller owns the user-facing message; these\r\n * return a boolean rather than throwing so a failure surfaces as copy\r\n * (R-4.4) instead of an unhandled rejection.\r\n */\r\n\r\n/**\r\n * Extension → MIME type for the formats the platform accepts as\r\n * attachments.\r\n *\r\n * Anything unmapped resolves to application/octet-stream, which makes the\r\n * browser download the file rather than attempt to render it — the safe\r\n * default for an unknown payload.\r\n */\r\nconst MIME_TYPES: Readonly<Record<string, string>> = Object.freeze({\r\n // Documents\r\n pdf: \"application/pdf\",\r\n doc: \"application/msword\",\r\n docx: \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\r\n xls: \"application/vnd.ms-excel\",\r\n xlsx: \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\r\n csv: \"text/csv\",\r\n txt: \"text/plain\",\r\n\r\n // Images\r\n png: \"image/png\",\r\n jpg: \"image/jpeg\",\r\n jpeg: \"image/jpeg\",\r\n gif: \"image/gif\",\r\n bmp: \"image/bmp\",\r\n webp: \"image/webp\",\r\n svg: \"image/svg+xml\",\r\n ico: \"image/x-icon\",\r\n tiff: \"image/tiff\",\r\n tif: \"image/tiff\",\r\n});\r\n\r\n/**\r\n * Resolve the MIME type for a file extension.\r\n *\r\n * @param extension - Extension WITHOUT a leading dot. Case-insensitive.\r\n * @returns The mapped MIME type, or \"application/octet-stream\".\r\n */\r\nexport function getMimeType(extension: string): string {\r\n return MIME_TYPES[extension.toLowerCase()] ?? \"application/octet-stream\";\r\n}\r\n\r\n/**\r\n * Decode a base64 payload and hand it to the browser as a download.\r\n *\r\n * @param base64Data - Base64 WITHOUT a `data:` prefix, as the getFile /\r\n * downloadFile endpoints return it.\r\n * @param fileName - Filename offered to the user. The extension is NOT\r\n * appended automatically; pass it already suffixed if\r\n * you want one.\r\n * @param extension - Used only to resolve the Blob's MIME type.\r\n * @returns true on success; false if decoding failed or there is no DOM.\r\n *\r\n * @example\r\n * const ok = downloadBase64File(body.content, body.fileName, body.extension);\r\n * if (!ok) toast(\"Le téléchargement a échoué. Veuillez réessayer.\", \"error\");\r\n */\r\nexport function downloadBase64File(\r\n base64Data: string,\r\n fileName: string,\r\n extension: string,\r\n): boolean {\r\n // Guarded rather than assumed: this runs in jsdom under test and could be\r\n // reached during SSR. The host modules' copies of this threw in both.\r\n if (typeof document === \"undefined\" || typeof atob === \"undefined\") {\r\n return false;\r\n }\r\n\r\n let url: string | null = null;\r\n let link: HTMLAnchorElement | null = null;\r\n\r\n try {\r\n const binary = atob(base64Data);\r\n const bytes = new Uint8Array(binary.length);\r\n for (let i = 0; i < binary.length; i += 1) {\r\n bytes[i] = binary.charCodeAt(i);\r\n }\r\n\r\n const blob = new Blob([bytes], { type: getMimeType(extension) });\r\n\r\n url = URL.createObjectURL(blob);\r\n link = document.createElement(\"a\");\r\n link.href = url;\r\n link.download = fileName;\r\n document.body.appendChild(link);\r\n link.click();\r\n return true;\r\n } catch (error) {\r\n // eslint-disable-next-line no-console\r\n console.error(\"[@portnet/ui] downloadBase64File failed:\", error);\r\n return false;\r\n } finally {\r\n // finally, not the happy path: the host copies leaked both the anchor\r\n // and the object URL whenever click() or appendChild threw.\r\n if (link && link.parentNode) link.parentNode.removeChild(link);\r\n if (url) URL.revokeObjectURL(url);\r\n }\r\n}\r\n\r\n/**\r\n * Delay before revoking a preview's object URL.\r\n *\r\n * It CANNOT be revoked synchronously: the newly opened tab still has to fetch\r\n * the blob. There is no portable \"that tab finished loading\" signal for a blob\r\n * URL, so a timeout is the only cross-browser option. Deliberately generous:\r\n * revoking early shows the user a blank tab, while being late costs one\r\n * short-lived blob.\r\n */\r\nconst PREVIEW_REVOKE_DELAY_MS = 60_000;\r\n\r\n/**\r\n * Decode a base64 payload and open it in a new tab for preview.\r\n *\r\n * Companion to downloadBase64File: every document-bearing GU module offers a\r\n * « Visualiser » action next to « Télécharger », and each carried its own copy of\r\n * this atob -> Uint8Array -> Blob -> window.open sequence. NONE of those copies\r\n * revoked the object URL, so every preview leaked a blob for the lifetime of the\r\n * page.\r\n *\r\n * RETURN VALUE — read this before relying on it. `window.open` returns null BY\r\n * SPECIFICATION when \"noopener\" is set, so a blocked popup is indistinguishable\r\n * from a successful one. `true` therefore means \"decoded and the open call was\r\n * issued without throwing\" — NOT \"the tab is on screen\". Do not use it to claim\r\n * success to the user; use `false` to report a genuine failure (bad payload, no\r\n * DOM). Dropping \"noopener\" would make blocked-popup detection possible but\r\n * would hand the opened tab a window.opener reference — not a trade worth making\r\n * for a diagnostic.\r\n *\r\n * @param base64Data - Base64 WITHOUT a `data:` prefix.\r\n * @param extension - Resolves the Blob MIME type. Required for inline\r\n * rendering: with the wrong type the browser downloads the\r\n * file instead of displaying it.\r\n * @returns false if there is no DOM or the payload could not be decoded.\r\n */\r\nexport function openBase64FileInTab(base64Data: string, extension: string): boolean {\r\n if (typeof window === \"undefined\" || typeof atob === \"undefined\") {\r\n return false;\r\n }\r\n let url: string | null = null;\r\n try {\r\n const binary = atob(base64Data);\r\n const bytes = new Uint8Array(binary.length);\r\n for (let i = 0; i < binary.length; i += 1) {\r\n bytes[i] = binary.charCodeAt(i);\r\n }\r\n const blob = new Blob([bytes], { type: getMimeType(extension) });\r\n url = URL.createObjectURL(blob);\r\n window.open(url, \"_blank\", \"noopener,noreferrer\");\r\n const revokeTarget = url;\r\n window.setTimeout(() => URL.revokeObjectURL(revokeTarget), PREVIEW_REVOKE_DELAY_MS);\r\n return true;\r\n } catch (error) {\r\n // Revoke straight away here: nothing consumed the URL on this path.\r\n if (url) URL.revokeObjectURL(url);\r\n // eslint-disable-next-line no-console\r\n console.error(\"[@portnet/ui] openBase64FileInTab failed:\", error);\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * Hand an already-materialised Blob to the browser as a download.\r\n *\r\n * Companion to downloadBase64File for endpoints that return a binary body\r\n * directly (axios `responseType: \"blob\"`) instead of base64 — Excel exports,\r\n * server-generated PDFs. Host modules built the anchor by hand for this too,\r\n * and every copy found so far never revoked the object URL.\r\n *\r\n * Revoked synchronously in `finally`, unlike openBase64FileInTab: a download is\r\n * snapshotted by the browser at click() time, so nothing needs the URL\r\n * afterwards — only a preview in another tab does.\r\n *\r\n * @param blob - The payload. Its own `type` is used as-is; no MIME lookup,\r\n * the server already declared it.\r\n * @param fileName - Filename offered to the user, extension included.\r\n * @returns true on success; false if there is no DOM.\r\n */\r\nexport function downloadBlobFile(blob: Blob, fileName: string): boolean {\r\n if (typeof document === \"undefined\" || typeof URL === \"undefined\") {\r\n return false;\r\n }\r\n let url: string | null = null;\r\n let link: HTMLAnchorElement | null = null;\r\n try {\r\n url = URL.createObjectURL(blob);\r\n link = document.createElement(\"a\");\r\n link.href = url;\r\n link.download = fileName;\r\n document.body.appendChild(link);\r\n link.click();\r\n return true;\r\n } catch (error) {\r\n // eslint-disable-next-line no-console\r\n console.error(\"[@portnet/ui] downloadBlobFile failed:\", error);\r\n return false;\r\n } finally {\r\n if (link && link.parentNode) link.parentNode.removeChild(link);\r\n if (url) URL.revokeObjectURL(url);\r\n }\r\n}\r\n\r\nconst fileDownloadApi = {\r\n getMimeType,\r\n downloadBase64File,\r\n openBase64FileInTab,\r\n downloadBlobFile,\r\n};\r\nexport default fileDownloadApi;\r\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,UAA4C,GAAGC,MAAM,CAACC,MAAM,CAAC;EACjE;EACAC,GAAG,EAAE,iBAAiB;EACtBC,GAAG,EAAE,oBAAoB;EACzBC,IAAI,EAAE,yEAAyE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AC;IAC/BP,IAAI,GAAGH,QAAQ,CAACe,aAAa,CAAC,GAAG,CAAC;IAClCZ,IAAI,CAACa,IAAI,GAAGd,GAAG;IACfC,IAAI,CAACc,QAAQ,GAAGlB,QAAQ;IACxBC,QAAQ,CAACkB,IAAI,CAACC,WAAW,CAAChB,IAAI,CAAC;IAC/BA,IAAI,CAACiB,KAAK,CAAC,CAAC;IACZ,OAAO,IAAI;EACb,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd;IACAC,OAAO,CAACD,KAAK,CAAC,wCAAwC,EAAEA,KAAK,CAAC;IAC9D,OAAO,KAAK;EACd,CAAC,SAAS;IACR,IAAIlB,IAAI,IAAIA,IAAI,CAACoB,UAAU,EAAEpB,IAAI,CAACoB,UAAU,CAACC,WAAW,CAACrB,IAAI,CAAC;IAC9D,IAAID,GAAG,EAAEW,GAAG,CAACY,eAAe,CAACvB,GAAG,CAAC;EACnC;AACF;AAEA,IAAM+B,eAAe,GAAG;EACtBxC,WAAW,EAAXA,WAAW;EACXI,kBAAkB,EAAlBA,kBAAkB;EAClB8B,mBAAmB,EAAnBA,mBAAmB;EACnBK,gBAAgB,EAAhBA;AACF,CAAC;AAAC,IAAAE,QAAA,GAAAC,OAAA,cACaF,eAAe","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fileDownload.js","names":["MIME_TYPES","Object","freeze","pdf","doc","docx","xls","xlsx","csv","txt","png","jpg","jpeg","gif","bmp","webp","svg","ico","tiff","tif","getMimeType","extension","toLowerCase","downloadBase64File","base64Data","fileName","document","atob","url","link","binary","bytes","Uint8Array","length","i","charCodeAt","blob","Blob","type","URL","createObjectURL","createElement","href","download","body","appendChild","click","error","console","parentNode","removeChild","revokeObjectURL","PREVIEW_REVOKE_DELAY_MS","openBase64FileInTab","window","open","revokeTarget","setTimeout","downloadBlobFile","fileDownloadApi","_default","exports","default"],"sources":["../../../src/lib/v2/utils/fileDownload.ts"],"sourcesContent":["/**\r\n * File download utilities — Portnet UI v2\r\n *\r\n * Turns a base64 payload from the API into a browser download. Every GU\r\n * module that lets a user retrieve an attached document needs this, and\r\n * before this file each one carried its own copy of the same\r\n * atob → Uint8Array → Blob → anchor sequence plus its own MIME map.\r\n *\r\n * DEPENDENCY-FREE ON PURPOSE. Multi-file (zip) bundling is deliberately NOT\r\n * here: it needs a zip library, and making that a hard dependency of the\r\n * design system would put it in every module's bundle against the\r\n * R-8.2 budget (180 KB gz initial JS) for a capability only\r\n * document-heavy modules use. If it is promoted later it belongs behind an\r\n * OPTIONAL peer dependency, the way PdfViewer sits behind pdfjs-dist and\r\n * @react-pdf-viewer/* in peerDependenciesMeta.\r\n *\r\n * Charter ref: §09.3 — the caller owns the user-facing message; these\r\n * return a boolean rather than throwing so a failure surfaces as copy\r\n * (R-4.4) instead of an unhandled rejection.\r\n */\r\n\r\n/**\r\n * Extension → MIME type for the formats the platform accepts as\r\n * attachments.\r\n *\r\n * Anything unmapped resolves to application/octet-stream, which makes the\r\n * browser download the file rather than attempt to render it — the safe\r\n * default for an unknown payload.\r\n */\r\nconst MIME_TYPES: Readonly<Record<string, string>> = Object.freeze({\r\n // Documents\r\n pdf: \"application/pdf\",\r\n doc: \"application/msword\",\r\n docx: \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\r\n xls: \"application/vnd.ms-excel\",\r\n xlsx: \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\r\n csv: \"text/csv\",\r\n txt: \"text/plain\",\r\n\r\n // Images\r\n png: \"image/png\",\r\n jpg: \"image/jpeg\",\r\n jpeg: \"image/jpeg\",\r\n gif: \"image/gif\",\r\n bmp: \"image/bmp\",\r\n webp: \"image/webp\",\r\n svg: \"image/svg+xml\",\r\n ico: \"image/x-icon\",\r\n tiff: \"image/tiff\",\r\n tif: \"image/tiff\",\r\n});\r\n\r\n/**\r\n * Resolve the MIME type for a file extension.\r\n *\r\n * @param extension - Extension WITHOUT a leading dot. Case-insensitive.\r\n * @returns The mapped MIME type, or \"application/octet-stream\".\r\n */\r\nexport function getMimeType(extension: string): string {\r\n return MIME_TYPES[extension.toLowerCase()] ?? \"application/octet-stream\";\r\n}\r\n\r\n/**\r\n * Decode a base64 payload and hand it to the browser as a download.\r\n *\r\n * @param base64Data - Base64 WITHOUT a `data:` prefix, as the getFile /\r\n * downloadFile endpoints return it.\r\n * @param fileName - Filename offered to the user. The extension is NOT\r\n * appended automatically; pass it already suffixed if\r\n * you want one.\r\n * @param extension - Used only to resolve the Blob's MIME type.\r\n * @returns true on success; false if decoding failed or there is no DOM.\r\n *\r\n * @example\r\n * const ok = downloadBase64File(body.content, body.fileName, body.extension);\r\n * if (!ok) toast(\"Le téléchargement a échoué. Veuillez réessayer.\", \"error\");\r\n */\r\nexport function downloadBase64File(\r\n base64Data: string,\r\n fileName: string,\r\n extension: string,\r\n): boolean {\r\n // Guarded rather than assumed: this runs in jsdom under test and could be\r\n // reached during SSR. The host modules' copies of this threw in both.\r\n if (typeof document === \"undefined\" || typeof atob === \"undefined\") {\r\n return false;\r\n }\r\n\r\n let url: string | null = null;\r\n let link: HTMLAnchorElement | null = null;\r\n\r\n try {\r\n const binary = atob(base64Data);\r\n const bytes = new Uint8Array(binary.length);\r\n for (let i = 0; i < binary.length; i += 1) {\r\n bytes[i] = binary.charCodeAt(i);\r\n }\r\n\r\n const blob = new Blob([bytes], { type: getMimeType(extension) });\r\n\r\n url = URL.createObjectURL(blob);\r\n link = document.createElement(\"a\");\r\n link.href = url;\r\n link.download = fileName;\r\n document.body.appendChild(link);\r\n link.click();\r\n return true;\r\n } catch (error) {\r\n // eslint-disable-next-line no-console\r\n console.error(\"[@portnet/ui] downloadBase64File failed:\", error);\r\n return false;\r\n } finally {\r\n // finally, not the happy path: the host copies leaked both the anchor\r\n // and the object URL whenever click() or appendChild threw.\r\n if (link && link.parentNode) link.parentNode.removeChild(link);\r\n if (url) URL.revokeObjectURL(url);\r\n }\r\n}\r\n\r\n/**\r\n * Delay before revoking a preview's object URL.\r\n *\r\n * It CANNOT be revoked synchronously: the newly opened tab still has to fetch\r\n * the blob. There is no portable \"that tab finished loading\" signal for a blob\r\n * URL, so a timeout is the only cross-browser option. Deliberately generous:\r\n * revoking early shows the user a blank tab, while being late costs one\r\n * short-lived blob.\r\n */\r\nconst PREVIEW_REVOKE_DELAY_MS = 60_000;\r\n\r\n/**\r\n * Decode a base64 payload and open it in a new tab for preview.\r\n *\r\n * Companion to downloadBase64File: every document-bearing GU module offers a\r\n * « Visualiser » action next to « Télécharger », and each carried its own copy of\r\n * this atob -> Uint8Array -> Blob -> window.open sequence. NONE of those copies\r\n * revoked the object URL, so every preview leaked a blob for the lifetime of the\r\n * page.\r\n *\r\n * RETURN VALUE — read this before relying on it. `window.open` returns null BY\r\n * SPECIFICATION when \"noopener\" is set, so a blocked popup is indistinguishable\r\n * from a successful one. `true` therefore means \"decoded and the open call was\r\n * issued without throwing\" — NOT \"the tab is on screen\". Do not use it to claim\r\n * success to the user; use `false` to report a genuine failure (bad payload, no\r\n * DOM). Dropping \"noopener\" would make blocked-popup detection possible but\r\n * would hand the opened tab a window.opener reference — not a trade worth making\r\n * for a diagnostic.\r\n *\r\n * @param base64Data - Base64 WITHOUT a `data:` prefix.\r\n * @param extension - Resolves the Blob MIME type. Required for inline\r\n * rendering: with the wrong type the browser downloads the\r\n * file instead of displaying it.\r\n * @returns false if there is no DOM or the payload could not be decoded.\r\n */\r\nexport function openBase64FileInTab(base64Data: string, extension: string): boolean {\r\n if (typeof window === \"undefined\" || typeof atob === \"undefined\") {\r\n return false;\r\n }\r\n let url: string | null = null;\r\n try {\r\n const binary = atob(base64Data);\r\n const bytes = new Uint8Array(binary.length);\r\n for (let i = 0; i < binary.length; i += 1) {\r\n bytes[i] = binary.charCodeAt(i);\r\n }\r\n const blob = new Blob([bytes], { type: getMimeType(extension) });\r\n url = URL.createObjectURL(blob);\r\n window.open(url, \"_blank\", \"noopener,noreferrer\");\r\n const revokeTarget = url;\r\n window.setTimeout(() => URL.revokeObjectURL(revokeTarget), PREVIEW_REVOKE_DELAY_MS);\r\n return true;\r\n } catch (error) {\r\n // Revoke straight away here: nothing consumed the URL on this path.\r\n if (url) URL.revokeObjectURL(url);\r\n // eslint-disable-next-line no-console\r\n console.error(\"[@portnet/ui] openBase64FileInTab failed:\", error);\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * Hand an already-materialised Blob to the browser as a download.\r\n *\r\n * Companion to downloadBase64File for endpoints that return a binary body\r\n * directly (axios `responseType: \"blob\"`) instead of base64 — Excel exports,\r\n * server-generated PDFs. Host modules built the anchor by hand for this too,\r\n * and every copy found so far never revoked the object URL.\r\n *\r\n * Revoked synchronously in `finally`, unlike openBase64FileInTab: a download is\r\n * snapshotted by the browser at click() time, so nothing needs the URL\r\n * afterwards — only a preview in another tab does.\r\n *\r\n * @param blob - The payload. Its own `type` is used as-is; no MIME lookup,\r\n * the server already declared it.\r\n * @param fileName - Filename offered to the user, extension included.\r\n * @returns true on success; false if there is no DOM.\r\n */\r\nexport function downloadBlobFile(blob: Blob, fileName: string): boolean {\r\n if (typeof document === \"undefined\" || typeof URL === \"undefined\") {\r\n return false;\r\n }\r\n let url: string | null = null;\r\n let link: HTMLAnchorElement | null = null;\r\n try {\r\n url = URL.createObjectURL(blob);\r\n link = document.createElement(\"a\");\r\n link.href = url;\r\n link.download = fileName;\r\n document.body.appendChild(link);\r\n link.click();\r\n return true;\r\n } catch (error) {\r\n // eslint-disable-next-line no-console\r\n console.error(\"[@portnet/ui] downloadBlobFile failed:\", error);\r\n return false;\r\n } finally {\r\n if (link && link.parentNode) link.parentNode.removeChild(link);\r\n if (url) URL.revokeObjectURL(url);\r\n }\r\n}\r\n\r\nconst fileDownloadApi = {\r\n getMimeType,\r\n downloadBase64File,\r\n openBase64FileInTab,\r\n downloadBlobFile,\r\n};\r\nexport default fileDownloadApi;\r\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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