@webority/mobile-ui 0.146.2 → 0.148.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas-kit/kit.js +4527 -4326
- package/dist/canvas-kit/manifest.json +8 -1
- package/dist/canvas-kit/release.json +6 -6
- package/lib/commonjs/components/AppBar/AppBar.js +1 -1
- package/lib/commonjs/components/AuthedImage/authedImageCache.js +1 -1
- package/lib/commonjs/components/AuthedImage/imageStore.js +1 -1
- package/lib/commonjs/components/AuthedImage/imageStore.web.js +1 -1
- package/lib/commonjs/components/Avatar/Avatar.js +1 -1
- package/lib/commonjs/components/Badge/Badge.js +1 -1
- package/lib/commonjs/components/Banner/Banner.js +1 -1
- package/lib/commonjs/components/BarChart/BarChart.js +1 -1
- package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/Box/Box.js +1 -1
- package/lib/commonjs/components/Button/Button.js +1 -1
- package/lib/commonjs/components/Calendar/Calendar.js +1 -1
- package/lib/commonjs/components/Carousel/Carousel.js +1 -1
- package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
- package/lib/commonjs/components/Confetti/Confetti.js +1 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
- package/lib/commonjs/components/Drawer/Drawer.js +1 -1
- package/lib/commonjs/components/FieldBase/Chevron.js +1 -1
- package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
- package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
- package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/commonjs/components/FormField/FormField.js +1 -1
- package/lib/commonjs/components/Input/Input.js +1 -1
- package/lib/commonjs/components/ListItem/ListItem.js +1 -1
- package/lib/commonjs/components/LoaderOverlay/LoaderOverlay.js +1 -1
- package/lib/commonjs/components/Markdown/Markdown.js +1 -1
- package/lib/commonjs/components/Menu/MenuSurface.js +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +1 -1
- package/lib/commonjs/components/Modal/Modal.js +1 -1
- package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
- package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
- package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
- package/lib/commonjs/components/Radio/RadioDot.js +1 -1
- package/lib/commonjs/components/Rating/Rating.js +1 -1
- package/lib/commonjs/components/RichTextEditor/RichTextEditor.js +1 -1
- package/lib/commonjs/components/RichTextEditor/markdownActions.js +1 -1
- package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
- package/lib/commonjs/components/SignaturePad/signatureGeometry.js +1 -1
- package/lib/commonjs/components/SignaturePad/writePng.js +1 -1
- package/lib/commonjs/components/SignaturePad/writePng.web.js +1 -1
- package/lib/commonjs/components/Skeleton/SkeletonClock.js +1 -1
- package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
- package/lib/commonjs/components/Slider/valueText.js +1 -1
- package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
- package/lib/commonjs/components/Sparkline/geometry.js +1 -1
- package/lib/commonjs/components/Spinner/Spinner.js +1 -1
- package/lib/commonjs/components/Stepper/Stepper.js +1 -1
- package/lib/commonjs/components/Switch/Switch.js +1 -1
- package/lib/commonjs/components/Tabs/Tabs.js +1 -1
- package/lib/commonjs/components/TagInput/TagInput.js +1 -1
- package/lib/commonjs/components/Text/Text.js +1 -1
- package/lib/commonjs/components/Toast/Toast.js +1 -1
- package/lib/commonjs/components/Toast/ToastProvider.js +1 -1
- package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
- package/lib/commonjs/components/Tour/Tour.js +1 -1
- package/lib/commonjs/components/WheelPicker/Wheel.js +1 -1
- package/lib/commonjs/form/path.js +1 -1
- package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
- package/lib/commonjs/hooks/usePressAnimation.js +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/network/NetworkStatusBanner.js +1 -1
- package/lib/commonjs/theme/Gradient.js +1 -1
- package/lib/commonjs/theme/animatedValue.js +1 -1
- package/lib/commonjs/theme/componentSizes.js +1 -1
- package/lib/commonjs/theme/merge.js +1 -1
- package/lib/commonjs/theme/toneInk.js +1 -1
- package/lib/commonjs/utils/color.js +1 -1
- package/lib/commonjs/utils/nativeDriver.js +1 -0
- package/lib/module/components/AppBar/AppBar.js +1 -1
- package/lib/module/components/AuthedImage/authedImageCache.js +1 -1
- package/lib/module/components/AuthedImage/imageStore.js +1 -1
- package/lib/module/components/AuthedImage/imageStore.web.js +1 -1
- package/lib/module/components/Avatar/Avatar.js +1 -1
- package/lib/module/components/Badge/Badge.js +1 -1
- package/lib/module/components/Banner/Banner.js +1 -1
- package/lib/module/components/BarChart/BarChart.js +1 -1
- package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/module/components/Box/Box.js +1 -1
- package/lib/module/components/Button/Button.js +1 -1
- package/lib/module/components/Calendar/Calendar.js +1 -1
- package/lib/module/components/Carousel/Carousel.js +1 -1
- package/lib/module/components/Checkbox/Checkbox.js +1 -1
- package/lib/module/components/Confetti/Confetti.js +1 -1
- package/lib/module/components/DatePicker/DatePicker.js +1 -1
- package/lib/module/components/Drawer/Drawer.js +1 -1
- package/lib/module/components/FieldBase/Chevron.js +1 -1
- package/lib/module/components/FieldBase/FieldBase.js +1 -1
- package/lib/module/components/FilePicker/FilePicker.js +1 -1
- package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/module/components/FormField/FormField.js +1 -1
- package/lib/module/components/Input/Input.js +1 -1
- package/lib/module/components/ListItem/ListItem.js +1 -1
- package/lib/module/components/LoaderOverlay/LoaderOverlay.js +1 -1
- package/lib/module/components/Markdown/Markdown.js +1 -1
- package/lib/module/components/Menu/MenuSurface.js +1 -1
- package/lib/module/components/MessageList/MessageList.js +1 -1
- package/lib/module/components/Modal/Modal.js +1 -1
- package/lib/module/components/OTPInput/OTPInput.js +1 -1
- package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
- package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
- package/lib/module/components/Radio/RadioDot.js +1 -1
- package/lib/module/components/Rating/Rating.js +1 -1
- package/lib/module/components/RichTextEditor/RichTextEditor.js +1 -1
- package/lib/module/components/RichTextEditor/markdownActions.js +1 -1
- package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
- package/lib/module/components/SignaturePad/signatureGeometry.js +1 -1
- package/lib/module/components/SignaturePad/writePng.js +1 -1
- package/lib/module/components/SignaturePad/writePng.web.js +1 -1
- package/lib/module/components/Skeleton/SkeletonClock.js +1 -1
- package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
- package/lib/module/components/Slider/valueText.js +1 -1
- package/lib/module/components/Sparkline/Sparkline.js +1 -1
- package/lib/module/components/Sparkline/geometry.js +1 -1
- package/lib/module/components/Spinner/Spinner.js +1 -1
- package/lib/module/components/Stepper/Stepper.js +1 -1
- package/lib/module/components/Switch/Switch.js +1 -1
- package/lib/module/components/Tabs/Tabs.js +1 -1
- package/lib/module/components/TagInput/TagInput.js +1 -1
- package/lib/module/components/Text/Text.js +1 -1
- package/lib/module/components/Toast/Toast.js +1 -1
- package/lib/module/components/Toast/ToastProvider.js +1 -1
- package/lib/module/components/Tooltip/Tooltip.js +1 -1
- package/lib/module/components/Tour/Tour.js +1 -1
- package/lib/module/components/WheelPicker/Wheel.js +1 -1
- package/lib/module/form/path.js +1 -1
- package/lib/module/hooks/useDragToDismiss.js +1 -1
- package/lib/module/hooks/usePressAnimation.js +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/network/NetworkStatusBanner.js +1 -1
- package/lib/module/theme/Gradient.js +1 -1
- package/lib/module/theme/animatedValue.js +1 -1
- package/lib/module/theme/componentSizes.js +1 -1
- package/lib/module/theme/merge.js +1 -1
- package/lib/module/theme/toneInk.js +1 -1
- package/lib/module/utils/color.js +1 -1
- package/lib/module/utils/nativeDriver.js +1 -0
- package/lib/typescript/commonjs/canvasKit/index.d.ts +15 -6
- package/lib/typescript/commonjs/components/AmountSlider/AmountSlider.d.ts +3 -2
- package/lib/typescript/commonjs/components/AppBar/AppBar.d.ts +2 -2
- package/lib/typescript/commonjs/components/AuthedImage/imageStore.d.ts +1 -1
- package/lib/typescript/commonjs/components/AuthedImage/imageStore.web.d.ts +1 -1
- package/lib/typescript/commonjs/components/Avatar/Avatar.d.ts +2 -2
- package/lib/typescript/commonjs/components/Badge/Badge.d.ts +2 -2
- package/lib/typescript/commonjs/components/Banner/Banner.d.ts +2 -2
- package/lib/typescript/commonjs/components/BarChart/BarChart.d.ts +2 -2
- package/lib/typescript/commonjs/components/BottomNavigation/BottomNavigation.d.ts +2 -2
- package/lib/typescript/commonjs/components/BottomSheet/BottomSheet.d.ts +2 -3
- package/lib/typescript/commonjs/components/Box/Box.d.ts +4 -4
- package/lib/typescript/commonjs/components/Button/Button.d.ts +3 -2
- package/lib/typescript/commonjs/components/Calendar/Calendar.d.ts +3 -2
- package/lib/typescript/commonjs/components/Calendar/calendarStyles.d.ts +25 -116
- package/lib/typescript/commonjs/components/Card/Card.d.ts +2 -2
- package/lib/typescript/commonjs/components/Checkbox/Checkbox.d.ts +2 -2
- package/lib/typescript/commonjs/components/Chip/Chip.d.ts +2 -2
- package/lib/typescript/commonjs/components/ChoiceGroup/ChoiceGroup.d.ts +2 -2
- package/lib/typescript/commonjs/components/Composer/Composer.d.ts +2 -3
- package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +3 -2
- package/lib/typescript/commonjs/components/DecimalInput/DecimalInput.d.ts +3 -2
- package/lib/typescript/commonjs/components/Divider/Divider.d.ts +3 -2
- package/lib/typescript/commonjs/components/EmptyState/EmptyState.d.ts +2 -2
- package/lib/typescript/commonjs/components/FileViewer/useFileViewerZoom.d.ts +14 -22
- package/lib/typescript/commonjs/components/FilterChipRow/FilterChipRow.d.ts +3 -2
- package/lib/typescript/commonjs/components/FloatingActionButton/FloatingActionButton.d.ts +2 -2
- package/lib/typescript/commonjs/components/FormField/FormField.d.ts +2 -2
- package/lib/typescript/commonjs/components/IconBadge/IconBadge.d.ts +3 -2
- package/lib/typescript/commonjs/components/IconButton/IconButton.d.ts +3 -2
- package/lib/typescript/commonjs/components/InlineSelect/InlineSelect.d.ts +2 -2
- package/lib/typescript/commonjs/components/Input/Input.d.ts +2 -3
- package/lib/typescript/commonjs/components/KeyboardAwareScrollView/KeyboardAwareScrollView.d.ts +1 -1
- package/lib/typescript/commonjs/components/ListItem/ListItem.d.ts +4 -3
- package/lib/typescript/commonjs/components/Markdown/Markdown.d.ts +3 -1
- package/lib/typescript/commonjs/components/Menu/useContextMenu.d.ts +2 -2
- package/lib/typescript/commonjs/components/Modal/Modal.d.ts +3 -3
- package/lib/typescript/commonjs/components/PickerTrigger/PickerTrigger.d.ts +4 -2
- package/lib/typescript/commonjs/components/ProfileCompletion/ProfileCompletion.d.ts +2 -2
- package/lib/typescript/commonjs/components/ProfilePicker/ProfilePicker.d.ts +2 -2
- package/lib/typescript/commonjs/components/ProgressBar/ProgressBar.d.ts +4 -4
- package/lib/typescript/commonjs/components/ProgressRing/ProgressRing.d.ts +2 -2
- package/lib/typescript/commonjs/components/Radio/Radio.d.ts +3 -3
- package/lib/typescript/commonjs/components/Rating/Rating.d.ts +2 -2
- package/lib/typescript/commonjs/components/RichTextEditor/RichTextEditor.d.ts +2 -2
- package/lib/typescript/commonjs/components/ScannerOverlay/ScannerOverlay.d.ts +2 -2
- package/lib/typescript/commonjs/components/Screen/Screen.d.ts +2 -2
- package/lib/typescript/commonjs/components/SearchBar/SearchBar.d.ts +3 -3
- package/lib/typescript/commonjs/components/SegmentedControl/SegmentedControl.d.ts +3 -3
- package/lib/typescript/commonjs/components/Select/Select.d.ts +2 -2
- package/lib/typescript/commonjs/components/SignaturePad/writePng.d.ts +1 -1
- package/lib/typescript/commonjs/components/SignaturePad/writePng.web.d.ts +1 -1
- package/lib/typescript/commonjs/components/SlideToConfirm/SlideToConfirm.d.ts +2 -2
- package/lib/typescript/commonjs/components/Slider/Slider.d.ts +2 -2
- package/lib/typescript/commonjs/components/SliderField/SliderField.d.ts +2 -2
- package/lib/typescript/commonjs/components/Sparkline/Sparkline.d.ts +3 -2
- package/lib/typescript/commonjs/components/Spinner/Spinner.d.ts +2 -2
- package/lib/typescript/commonjs/components/SquircleView/SquircleView.d.ts +3 -2
- package/lib/typescript/commonjs/components/StatTile/StatTile.d.ts +3 -3
- package/lib/typescript/commonjs/components/StatusBadge/StatusBadge.d.ts +2 -2
- package/lib/typescript/commonjs/components/Stepper/Stepper.d.ts +2 -2
- package/lib/typescript/commonjs/components/Switch/Switch.d.ts +3 -3
- package/lib/typescript/commonjs/components/Tabs/Tabs.d.ts +3 -3
- package/lib/typescript/commonjs/components/TagInput/TagInput.d.ts +3 -2
- package/lib/typescript/commonjs/components/Text/Text.d.ts +2 -2
- package/lib/typescript/commonjs/components/Tooltip/RichTooltipBody.d.ts +3 -3
- package/lib/typescript/commonjs/components/Tour/Tour.d.ts +2 -2
- package/lib/typescript/commonjs/hooks/useFieldErrorScroll.d.ts +5 -5
- package/lib/typescript/commonjs/index.d.ts +1 -1
- package/lib/typescript/commonjs/theme/Gradient.d.ts +5 -1
- package/lib/typescript/commonjs/theme/animatedValue.d.ts +1 -1
- package/lib/typescript/commonjs/theme/makeStyles.d.ts +4 -2
- package/lib/typescript/commonjs/utils/nativeDriver.d.ts +2 -0
- package/lib/typescript/module/canvasKit/index.d.ts +15 -6
- package/lib/typescript/module/components/AmountSlider/AmountSlider.d.ts +3 -2
- package/lib/typescript/module/components/AppBar/AppBar.d.ts +2 -2
- package/lib/typescript/module/components/AuthedImage/imageStore.d.ts +1 -1
- package/lib/typescript/module/components/AuthedImage/imageStore.web.d.ts +1 -1
- package/lib/typescript/module/components/Avatar/Avatar.d.ts +2 -2
- package/lib/typescript/module/components/Badge/Badge.d.ts +2 -2
- package/lib/typescript/module/components/Banner/Banner.d.ts +2 -2
- package/lib/typescript/module/components/BarChart/BarChart.d.ts +2 -2
- package/lib/typescript/module/components/BottomNavigation/BottomNavigation.d.ts +2 -2
- package/lib/typescript/module/components/BottomSheet/BottomSheet.d.ts +2 -3
- package/lib/typescript/module/components/Box/Box.d.ts +4 -4
- package/lib/typescript/module/components/Button/Button.d.ts +3 -2
- package/lib/typescript/module/components/Calendar/Calendar.d.ts +3 -2
- package/lib/typescript/module/components/Calendar/calendarStyles.d.ts +25 -116
- package/lib/typescript/module/components/Card/Card.d.ts +2 -2
- package/lib/typescript/module/components/Checkbox/Checkbox.d.ts +2 -2
- package/lib/typescript/module/components/Chip/Chip.d.ts +2 -2
- package/lib/typescript/module/components/ChoiceGroup/ChoiceGroup.d.ts +2 -2
- package/lib/typescript/module/components/Composer/Composer.d.ts +2 -3
- package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +3 -2
- package/lib/typescript/module/components/DecimalInput/DecimalInput.d.ts +3 -2
- package/lib/typescript/module/components/Divider/Divider.d.ts +3 -2
- package/lib/typescript/module/components/EmptyState/EmptyState.d.ts +2 -2
- package/lib/typescript/module/components/FileViewer/useFileViewerZoom.d.ts +14 -22
- package/lib/typescript/module/components/FilterChipRow/FilterChipRow.d.ts +3 -2
- package/lib/typescript/module/components/FloatingActionButton/FloatingActionButton.d.ts +2 -2
- package/lib/typescript/module/components/FormField/FormField.d.ts +2 -2
- package/lib/typescript/module/components/IconBadge/IconBadge.d.ts +3 -2
- package/lib/typescript/module/components/IconButton/IconButton.d.ts +3 -2
- package/lib/typescript/module/components/InlineSelect/InlineSelect.d.ts +2 -2
- package/lib/typescript/module/components/Input/Input.d.ts +2 -3
- package/lib/typescript/module/components/KeyboardAwareScrollView/KeyboardAwareScrollView.d.ts +1 -1
- package/lib/typescript/module/components/ListItem/ListItem.d.ts +4 -3
- package/lib/typescript/module/components/Markdown/Markdown.d.ts +3 -1
- package/lib/typescript/module/components/Menu/useContextMenu.d.ts +2 -2
- package/lib/typescript/module/components/Modal/Modal.d.ts +3 -3
- package/lib/typescript/module/components/PickerTrigger/PickerTrigger.d.ts +4 -2
- package/lib/typescript/module/components/ProfileCompletion/ProfileCompletion.d.ts +2 -2
- package/lib/typescript/module/components/ProfilePicker/ProfilePicker.d.ts +2 -2
- package/lib/typescript/module/components/ProgressBar/ProgressBar.d.ts +4 -4
- package/lib/typescript/module/components/ProgressRing/ProgressRing.d.ts +2 -2
- package/lib/typescript/module/components/Radio/Radio.d.ts +3 -3
- package/lib/typescript/module/components/Rating/Rating.d.ts +2 -2
- package/lib/typescript/module/components/RichTextEditor/RichTextEditor.d.ts +2 -2
- package/lib/typescript/module/components/ScannerOverlay/ScannerOverlay.d.ts +2 -2
- package/lib/typescript/module/components/Screen/Screen.d.ts +2 -2
- package/lib/typescript/module/components/SearchBar/SearchBar.d.ts +3 -3
- package/lib/typescript/module/components/SegmentedControl/SegmentedControl.d.ts +3 -3
- package/lib/typescript/module/components/Select/Select.d.ts +2 -2
- package/lib/typescript/module/components/SignaturePad/writePng.d.ts +1 -1
- package/lib/typescript/module/components/SignaturePad/writePng.web.d.ts +1 -1
- package/lib/typescript/module/components/SlideToConfirm/SlideToConfirm.d.ts +2 -2
- package/lib/typescript/module/components/Slider/Slider.d.ts +2 -2
- package/lib/typescript/module/components/SliderField/SliderField.d.ts +2 -2
- package/lib/typescript/module/components/Sparkline/Sparkline.d.ts +3 -2
- package/lib/typescript/module/components/Spinner/Spinner.d.ts +2 -2
- package/lib/typescript/module/components/SquircleView/SquircleView.d.ts +3 -2
- package/lib/typescript/module/components/StatTile/StatTile.d.ts +3 -3
- package/lib/typescript/module/components/StatusBadge/StatusBadge.d.ts +2 -2
- package/lib/typescript/module/components/Stepper/Stepper.d.ts +2 -2
- package/lib/typescript/module/components/Switch/Switch.d.ts +3 -3
- package/lib/typescript/module/components/Tabs/Tabs.d.ts +3 -3
- package/lib/typescript/module/components/TagInput/TagInput.d.ts +3 -2
- package/lib/typescript/module/components/Text/Text.d.ts +2 -2
- package/lib/typescript/module/components/Tooltip/RichTooltipBody.d.ts +3 -3
- package/lib/typescript/module/components/Tour/Tour.d.ts +2 -2
- package/lib/typescript/module/hooks/useFieldErrorScroll.d.ts +5 -5
- package/lib/typescript/module/index.d.ts +1 -1
- package/lib/typescript/module/theme/Gradient.d.ts +5 -1
- package/lib/typescript/module/theme/animatedValue.d.ts +1 -1
- package/lib/typescript/module/theme/makeStyles.d.ts +4 -2
- package/lib/typescript/module/utils/nativeDriver.d.ts +2 -0
- package/package.json +29 -29
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_STEPPER_LABELS=Object.freeze({step:(e,t,s,i)=>`Step ${e} of ${t}, ${s}, ${i}`,statusComplete:"complete",statusActive:"active",statusUpcoming:"upcoming",progressStep:(e,t)=>`Progress: step ${e} of ${t}`,progressDone:(e,t)=>`Progress: ${e} of ${t} steps done`,captionStep:(e,t,s)=>`Step ${e} of ${t}${s?` · ${s}`:""}`,captionDone:(e,t)=>`${e} of ${t} done`});const CIRCLE_SIZE=24,SEGMENT_HEIGHT=4,PULSE_SIZE=32,PULSE_DURATION=1100,toneColorFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},toneOnColorFor=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];default:return e.colors["on-primary"]}},statusWordFor=(e,t)=>{switch(t){case"complete":return e.statusComplete;case"active":return e.statusActive;default:return e.statusUpcoming}},StepCircle=({index:e,step:t,status:s,toneColor:i,upcomingColor:o,upcomingFillColor:r,textOnColor:l,upcomingTextColor:n,interactive:a,canPress:c,totalSteps:u,onPress:p,pulseEnabled:d,labels:m,circleStyles:h,circleSlotStyle:g})=>{const y="active"===s,b=useTheme(),x=useRef(createAnimatedValue(1)).current,S=useRef(createAnimatedValue(.5)).current;useEffect(()=>{if(!y||!d)return x.setValue(1),void S.setValue(0);const e=Animated.loop(Animated.parallel([Animated.sequence([Animated.timing(x,{toValue:1.4,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:!0}),Animated.timing(x,{toValue:1,duration:0,useNativeDriver:!0})]),Animated.sequence([Animated.timing(S,{toValue:0,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:!0}),Animated.timing(S,{toValue:.5,duration:0,useNativeDriver:!0})])]));return e.start(),()=>e.stop()},[y,x,S,d]);const f="upcoming"===s?r:i,w="upcoming"===s?o:i,v="upcoming"===s?n:l,C="complete"===s,j=m.step(e+1,u,t.label,statusWordFor(m,s)),_=_jsxs(View,{style:h.relative,children:[y&&d?_jsx(Animated.View,{pointerEvents:"none",style:[h.pulse,{width:32,height:32,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:i,opacity:S,transform:[{scale:x}]}]}):null,_jsx(View,{style:[h.circle,{width:24,height:24,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:f,borderColor:w},g],children:t.icon?t.icon:_jsx(Text,C?{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:v}],children:"✓"}:{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:v}],children:e+1})})]});return a?_jsx(Pressable,{onPress:()=>p(e),disabled:!c,accessibilityRole:"button",accessibilityLabel:j,accessibilityState:{selected:y,disabled:!c},"aria-selected":y,"aria-disabled":!c,hitSlop:8,...hitSlopMarker(8),children:_}):_jsx(View,{accessibilityRole:"text",accessibilityLabel:j,accessibilityState:{selected:y},"aria-selected":y,children:_})},buildCircleStyles=()=>StyleSheet.create({relative:{alignItems:"center",justifyContent:"center"},pulse:{position:"absolute"},circle:{borderWidth:2,alignItems:"center",justifyContent:"center"},glyph:{includeFontPadding:!1}}),Stepper=forwardRef((e,t)=>{const{steps:s,activeStep:i,defaultActiveStep:o=0,pressMode:r="none",onStepPress:l,onActiveStepChange:n,variant:a="horizontal",tone:c="primary",formatCaption:u,showCaption:p=!0,loading:d=!1,labels:m,accessibilityLabel:h,style:g,containerStyle:y,circleStyle:b,labelStyle:x,connectorStyle:S,haptic:f,testID:w}=e;assertValidValue("Stepper","variant",e.variant,["horizontal","vertical","segmented"]),assertValidValue("Stepper","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Stepper","pressMode",e.pressMode,["none","back","select"]);const v=useMemo(()=>({...DEFAULT_STEPPER_LABELS,...m}),[m]),C=useTheme(),j=C.settings.components.stepper?.pulseAnimation??!1,_=resolveHaptic(f,"selection"),V=useMemo(()=>buildStyles(C),[C]),k=useMemo(()=>buildCircleStyles(),[]),R=toneColorFor(C,c),A=C.colors.border,E=C.colors.bg,L=C.colors["text-muted"],T=toneOnColorFor(C,c),D=s.length,I="none"!==r,P=void 0!==i,[F,$]=useState(o),M=P?i:F,B=null==M||M<0?null:M,O=s.map((e,t)=>(e=>null===B?"upcoming":e<B?"complete":e===B?"active":"upcoming")(t)),N=O.filter(e=>"upcoming"!==e).length,U=O.filter(e=>"complete"===e).length,canPressStatus=e=>"back"===r?"complete"===e:I,handleStepPress=e=>{if(!canPressStatus(O[e]))return;_&&triggerHaptic(_),l?.(e);const t="select"===r&&e===B?null:e;P||$(t),n?.(t)},H=useRef(createAnimatedValue(N)).current,z=useRef(N);useEffect(()=>{const e=z.current;if(e===N)return;z.current=N;const t=Animated.timing(H,{toValue:N,duration:C.motion.duration.default*Math.abs(N-e),easing:Easing.linear,useNativeDriver:!1});return t.start(),()=>t.stop()},[N,H,C.motion]);const sliceOf=e=>H.interpolate({inputRange:[e,e+1],outputRange:["0%","100%"],extrapolate:"clamp"}),W=D<=1?"0%":H.interpolate({inputRange:[1,D],outputRange:["0%","100%"],extrapolate:"clamp"}),G=null!==B&&B<D?B:null,q=h??(null!==G?v.progressStep(G+1,D):v.progressDone(U,D)),[Z,J]=useState(0),K=D>0&&Z>0?Z/(2*D):0,Q=_jsx(View,{ref:t,style:[V.container,y,g],testID:w,accessibilityRole:"progressbar",accessibilityLabel:q,accessibilityValue:{min:0,max:D,now:N},children:"segmented"===a?(()=>{const e=null!==G?s[G]:void 0,t=p?u?u(G,D,e):null!==G?v.captionStep(G+1,D,e?.label):v.captionDone(U,D):"";return _jsxs(View,{children:[p?_jsx(Text,{variant:"bodySmall",style:[V.sCaption,{marginBottom:C.space.sm},x],numberOfLines:1,children:t}):null,_jsx(View,{style:V.sRow,children:s.map((e,t)=>{const s=O[t],i=v.step(t+1,D,e.label,statusWordFor(v,s)),o=_jsx(View,{testID:w?`${w}-segment-${t}`:void 0,style:[V.sTrack,{backgroundColor:A},S],children:_jsx(Animated.View,{style:[V.sFill,{backgroundColor:R,width:sliceOf(t)}]})});if(I){const r=canPressStatus(s);return _jsx(Pressable,{style:V.sItem,onPress:()=>handleStepPress(t),disabled:!r,accessibilityRole:"button",accessibilityLabel:i,accessibilityState:{selected:"active"===s,disabled:!r},"aria-selected":"active"===s,"aria-disabled":!r,hitSlop:{top:12,bottom:12},...hitSlopMarker({top:12,bottom:12}),children:o},e.key)}return _jsx(View,{style:V.sItem,accessibilityRole:"text",accessibilityLabel:i,accessibilityState:{selected:"active"===s},"aria-selected":"active"===s,children:o},e.key)})})]})})():"vertical"===a?_jsx(View,{style:V.vCol,children:s.map((e,t)=>{const s=O[t],i=t===D-1;return _jsxs(View,{style:V.vRow,children:[_jsxs(View,{style:V.vLeft,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:A,upcomingFillColor:E,onPressColor:R,textOnColor:T,upcomingTextColor:L,interactive:I,canPress:canPressStatus(s),totalSteps:D,onPress:handleStepPress,pulseEnabled:j,labels:v,circleStyles:k,circleSlotStyle:b}),i?null:_jsxs(View,{style:[V.vConnectorContainer,S],children:[_jsx(View,{style:[V.vConnectorTrack,{backgroundColor:A}]}),_jsx(Animated.View,{style:[V.vConnectorFill,{backgroundColor:R,height:sliceOf(t+1)}]})]})]}),_jsxs(View,{style:V.vBody,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[V.vLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "}),e.description?_jsx(Text,{variant:"bodySmall",style:V.vDescription,numberOfLines:3,children:e.description}):null]})]},e.key)})}):_jsxs(View,{style:V.hRow,onLayout:e=>J(e.nativeEvent.layout.width),children:[_jsxs(View,{pointerEvents:"none",style:[V.hConnectorContainer,{left:K,right:K},S],children:[_jsx(View,{style:[V.hConnectorTrack,{backgroundColor:A}]}),_jsx(Animated.View,{style:[V.hConnectorFill,{backgroundColor:R,width:W}]})]}),s.map((e,t)=>{const s=O[t];return _jsxs(View,{style:V.hStepItem,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:A,upcomingFillColor:E,onPressColor:R,textOnColor:T,upcomingTextColor:L,interactive:I,canPress:canPressStatus(s),totalSteps:D,onPress:handleStepPress,pulseEnabled:j,labels:v,circleStyles:k,circleSlotStyle:b}),_jsx(Text,{variant:"caption",style:[V.hLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "})]},e.key)})]})});return d?_jsx(StepperSkeleton,{...e}):Q});Stepper.displayName="Stepper";const StepperSkeleton=({steps:e,variant:t="horizontal",showCaption:s=!0,containerStyle:i,style:o,testID:r})=>{const l=useTheme(),n=useMemo(()=>buildStyles(l),[l]),a=useMemo(()=>buildSkeletonStyles(l),[l]),c=e.length||3;return"segmented"===t?_jsxs(View,{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[s?_jsx(Skeleton,{shape:"text",width:"45%",height:14,style:{marginBottom:l.space.sm}}):null,_jsx(View,{style:n.sRow,children:Array.from({length:c}).map((e,t)=>_jsx(View,{style:n.sItem,children:_jsx(Skeleton,{width:"100%",height:4,radius:"pill"})},`sk-step-${t}`))})]}):_jsx(View,"vertical"===t?{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsx(View,{style:a.vCol,children:Array.from({length:c}).map((e,t)=>{const s=t===c-1;return _jsxs(View,{style:a.vRow,children:[_jsxs(View,{style:[a.vLeft,{width:32}],children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),s?null:_jsx(Skeleton,{width:2,height:36})]}),_jsxs(View,{style:a.vBody,children:[_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:l.space.xs}}),_jsx(Skeleton,{shape:"text",width:"80%",height:12})]})]},`sk-step-${t}`)})})}:{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsxs(View,{style:n.hRow,children:[_jsx(View,{pointerEvents:"none",style:[n.hConnectorContainer,{left:50/c+"%",right:50/c+"%"}],children:_jsx(Skeleton,{width:"100%",height:2,radius:"pill"})}),Array.from({length:c}).map((e,t)=>_jsxs(View,{style:n.hStepItem,children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),_jsx(Skeleton,{shape:"text",width:"80%",height:12,style:{marginTop:l.space.xs}})]},`sk-step-${t}`))]})})};StepperSkeleton.displayName="StepperSkeleton",Stepper.Skeleton=StepperSkeleton;const buildSkeletonStyles=e=>StyleSheet.create({vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center"},vBody:{flex:1,paddingLeft:e.space.md,paddingBottom:e.space.lg}}),buildStyles=e=>StyleSheet.create({container:{width:"100%"},hRow:{flexDirection:"row",alignItems:"flex-start",justifyContent:"space-between",position:"relative"},hConnectorContainer:{position:"absolute",top:11,height:2,flexDirection:"row",alignItems:"center"},hConnectorTrack:{position:"absolute",left:0,right:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hConnectorFill:{position:"absolute",left:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hStepItem:{alignItems:"center",flex:1},hLabel:{marginTop:e.space.xs,textAlign:"center"},vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center",alignSelf:"stretch",width:32},vConnectorContainer:{flex:1,width:2,minHeight:32,position:"relative",alignSelf:"center"},vConnectorTrack:{position:"absolute",top:0,bottom:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vConnectorFill:{position:"absolute",top:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vBody:{flex:1,paddingLeft:e.space.sm,paddingBottom:e.space.md},vLabel:{marginBottom:e.space.xxs},vDescription:{},sCaption:{includeFontPadding:!1},sRow:{flexDirection:"row",columnGap:e.space.xs},sItem:{flex:1},sTrack:{height:4,borderRadius:e.radius.pill,overflow:"hidden"},sFill:{height:4,borderRadius:e.radius.pill}});export{Stepper};export default Stepper;
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_STEPPER_LABELS=Object.freeze({step:(e,t,s,i)=>`Step ${e} of ${t}, ${s}, ${i}`,statusComplete:"complete",statusActive:"active",statusUpcoming:"upcoming",progressStep:(e,t)=>`Progress: step ${e} of ${t}`,progressDone:(e,t)=>`Progress: ${e} of ${t} steps done`,captionStep:(e,t,s)=>`Step ${e} of ${t}${s?` · ${s}`:""}`,captionDone:(e,t)=>`${e} of ${t} done`});const CIRCLE_SIZE=24,SEGMENT_HEIGHT=4,PULSE_SIZE=32,PULSE_DURATION=1100,toneColorFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;case"primary":return e.colors.primary}},toneOnColorFor=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];case"primary":return e.colors["on-primary"]}},statusWordFor=(e,t)=>{switch(t){case"complete":return e.statusComplete;case"active":return e.statusActive;case"upcoming":return e.statusUpcoming}},StepCircle=({index:e,step:t,status:s,toneColor:i,upcomingColor:o,upcomingFillColor:r,textOnColor:l,upcomingTextColor:n,interactive:a,canPress:c,totalSteps:p,onPress:u,pulseEnabled:d,labels:m,circleStyles:h,circleSlotStyle:g})=>{const y="active"===s,b=useTheme(),x=useRef(createAnimatedValue(1)).current,S=useRef(createAnimatedValue(.5)).current;useEffect(()=>{if(!y||!d)return x.setValue(1),void S.setValue(0);const e=Animated.loop(Animated.parallel([Animated.sequence([Animated.timing(x,{toValue:1.4,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:nativeDriver}),Animated.timing(x,{toValue:1,duration:0,useNativeDriver:nativeDriver})]),Animated.sequence([Animated.timing(S,{toValue:0,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:nativeDriver}),Animated.timing(S,{toValue:.5,duration:0,useNativeDriver:nativeDriver})])]));return e.start(),()=>e.stop()},[y,x,S,d]);const v="upcoming"===s?r:i,f="upcoming"===s?o:i,w="upcoming"===s?n:l,C="complete"===s,j=m.step(e+1,p,t.label,statusWordFor(m,s)),_=_jsxs(View,{style:h.relative,children:[y&&d?_jsx(Animated.View,{pointerEvents:"none",style:[h.pulse,{width:32,height:32,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:i,opacity:S,transform:[{scale:x}]}]}):null,_jsx(View,{style:[h.circle,{width:24,height:24,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:v,borderColor:f},g],children:t.icon?t.icon:_jsx(Text,C?{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:w}],children:"✓"}:{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:w}],children:e+1})})]});return a?_jsx(Pressable,{onPress:()=>u(e),disabled:!c,accessibilityRole:"button",accessibilityLabel:j,accessibilityState:{selected:y,disabled:!c},"aria-selected":y,"aria-disabled":!c,hitSlop:8,...hitSlopMarker(8),children:_}):_jsx(View,{accessibilityRole:"text",accessibilityLabel:j,accessibilityState:{selected:y},"aria-selected":y,children:_})},buildCircleStyles=()=>StyleSheet.create({relative:{alignItems:"center",justifyContent:"center"},pulse:{position:"absolute"},circle:{borderWidth:2,alignItems:"center",justifyContent:"center"},glyph:{includeFontPadding:!1}}),Stepper=forwardRef((e,t)=>{const{steps:s,activeStep:i,defaultActiveStep:o=0,pressMode:r="none",onStepPress:l,onActiveStepChange:n,variant:a="horizontal",tone:c="primary",formatCaption:p,showCaption:u=!0,loading:d=!1,labels:m,accessibilityLabel:h,style:g,containerStyle:y,circleStyle:b,labelStyle:x,connectorStyle:S,haptic:v,testID:f}=e;assertValidValue("Stepper","variant",e.variant,["horizontal","vertical","segmented"]),assertValidValue("Stepper","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Stepper","pressMode",e.pressMode,["none","back","select"]);const w=useMemo(()=>({...DEFAULT_STEPPER_LABELS,...m}),[m]),C=useTheme(),j=C.settings.components.stepper?.pulseAnimation??!1,_=resolveHaptic(v,"selection"),V=useMemo(()=>buildStyles(C),[C]),k=useMemo(()=>buildCircleStyles(),[]),R=toneColorFor(C,c),D=C.colors.border,A=C.colors.bg,E=C.colors["text-muted"],L=toneOnColorFor(C,c),T=s.length,I="none"!==r,P=void 0!==i,[F,$]=useState(o),M=P?i:F,B=null==M||M<0?null:M,statusOf=e=>null===B?"upcoming":e<B?"complete":e===B?"active":"upcoming",O=s.map((e,t)=>statusOf(t)),N=O.filter(e=>"upcoming"!==e).length,U=O.filter(e=>"complete"===e).length,canPressStatus=e=>"back"===r?"complete"===e:I,handleStepPress=e=>{if(!canPressStatus(statusOf(e)))return;_&&triggerHaptic(_),l?.(e);const t="select"===r&&e===B?null:e;P||$(t),n?.(t)},H=useRef(createAnimatedValue(N)).current,z=useRef(N);useEffect(()=>{const e=z.current;if(e===N)return;z.current=N;const t=Animated.timing(H,{toValue:N,duration:C.motion.duration.default*Math.abs(N-e),easing:Easing.linear,useNativeDriver:!1});return t.start(),()=>t.stop()},[N,H,C.motion]);const sliceOf=e=>H.interpolate({inputRange:[e,e+1],outputRange:["0%","100%"],extrapolate:"clamp"}),W=T<=1?"0%":H.interpolate({inputRange:[1,T],outputRange:["0%","100%"],extrapolate:"clamp"}),G=null!==B&&B<T?B:null,q=h??(null!==G?w.progressStep(G+1,T):w.progressDone(U,T)),[Z,J]=useState(0),K=T>0&&Z>0?Z/(2*T):0,Q=_jsx(View,{ref:t,style:[V.container,y,g],testID:f,accessibilityRole:"progressbar",accessibilityLabel:q,accessibilityValue:{min:0,max:T,now:N},children:"segmented"===a?(()=>{const e=null!==G?s[G]:void 0,t=u?p?p(G,T,e):null!==G?w.captionStep(G+1,T,e?.label):w.captionDone(U,T):"";return _jsxs(View,{children:[u?_jsx(Text,{variant:"bodySmall",style:[V.sCaption,{marginBottom:C.space.sm},x],numberOfLines:1,children:t}):null,_jsx(View,{style:V.sRow,children:s.map((e,t)=>{const s=statusOf(t),i=w.step(t+1,T,e.label,statusWordFor(w,s)),o=_jsx(View,{testID:f?`${f}-segment-${t}`:void 0,style:[V.sTrack,{backgroundColor:D},S],children:_jsx(Animated.View,{style:[V.sFill,{backgroundColor:R,width:sliceOf(t)}]})});if(I){const r=canPressStatus(s);return _jsx(Pressable,{style:V.sItem,onPress:()=>handleStepPress(t),disabled:!r,accessibilityRole:"button",accessibilityLabel:i,accessibilityState:{selected:"active"===s,disabled:!r},"aria-selected":"active"===s,"aria-disabled":!r,hitSlop:{top:12,bottom:12},...hitSlopMarker({top:12,bottom:12}),children:o},e.key)}return _jsx(View,{style:V.sItem,accessibilityRole:"text",accessibilityLabel:i,accessibilityState:{selected:"active"===s},"aria-selected":"active"===s,children:o},e.key)})})]})})():"vertical"===a?_jsx(View,{style:V.vCol,children:s.map((e,t)=>{const s=statusOf(t),i=t===T-1;return _jsxs(View,{style:V.vRow,children:[_jsxs(View,{style:V.vLeft,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:D,upcomingFillColor:A,onPressColor:R,textOnColor:L,upcomingTextColor:E,interactive:I,canPress:canPressStatus(s),totalSteps:T,onPress:handleStepPress,pulseEnabled:j,labels:w,circleStyles:k,circleSlotStyle:b}),i?null:_jsxs(View,{style:[V.vConnectorContainer,S],children:[_jsx(View,{style:[V.vConnectorTrack,{backgroundColor:D}]}),_jsx(Animated.View,{style:[V.vConnectorFill,{backgroundColor:R,height:sliceOf(t+1)}]})]})]}),_jsxs(View,{style:V.vBody,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[V.vLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "}),e.description?_jsx(Text,{variant:"bodySmall",style:V.vDescription,numberOfLines:3,children:e.description}):null]})]},e.key)})}):_jsxs(View,{style:V.hRow,onLayout:e=>J(e.nativeEvent.layout.width),children:[_jsxs(View,{pointerEvents:"none",style:[V.hConnectorContainer,{left:K,right:K},S],children:[_jsx(View,{style:[V.hConnectorTrack,{backgroundColor:D}]}),_jsx(Animated.View,{style:[V.hConnectorFill,{backgroundColor:R,width:W}]})]}),s.map((e,t)=>{const s=statusOf(t);return _jsxs(View,{style:V.hStepItem,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:D,upcomingFillColor:A,onPressColor:R,textOnColor:L,upcomingTextColor:E,interactive:I,canPress:canPressStatus(s),totalSteps:T,onPress:handleStepPress,pulseEnabled:j,labels:w,circleStyles:k,circleSlotStyle:b}),_jsx(Text,{variant:"caption",style:[V.hLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "})]},e.key)})]})});return d?_jsx(StepperSkeleton,{...e}):Q});Stepper.displayName="Stepper";const StepperSkeleton=({steps:e,variant:t="horizontal",showCaption:s=!0,containerStyle:i,style:o,testID:r})=>{const l=useTheme(),n=useMemo(()=>buildStyles(l),[l]),a=useMemo(()=>buildSkeletonStyles(l),[l]),c=e.length||3;return"segmented"===t?_jsxs(View,{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[s?_jsx(Skeleton,{shape:"text",width:"45%",height:14,style:{marginBottom:l.space.sm}}):null,_jsx(View,{style:n.sRow,children:Array.from({length:c}).map((e,t)=>_jsx(View,{style:n.sItem,children:_jsx(Skeleton,{width:"100%",height:4,radius:"pill"})},`sk-step-${t}`))})]}):_jsx(View,"vertical"===t?{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsx(View,{style:a.vCol,children:Array.from({length:c}).map((e,t)=>{const s=t===c-1;return _jsxs(View,{style:a.vRow,children:[_jsxs(View,{style:[a.vLeft,{width:32}],children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),s?null:_jsx(Skeleton,{width:2,height:36})]}),_jsxs(View,{style:a.vBody,children:[_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:l.space.xs}}),_jsx(Skeleton,{shape:"text",width:"80%",height:12})]})]},`sk-step-${t}`)})})}:{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsxs(View,{style:n.hRow,children:[_jsx(View,{pointerEvents:"none",style:[n.hConnectorContainer,{left:50/c+"%",right:50/c+"%"}],children:_jsx(Skeleton,{width:"100%",height:2,radius:"pill"})}),Array.from({length:c}).map((e,t)=>_jsxs(View,{style:n.hStepItem,children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),_jsx(Skeleton,{shape:"text",width:"80%",height:12,style:{marginTop:l.space.xs}})]},`sk-step-${t}`))]})})};StepperSkeleton.displayName="StepperSkeleton",Stepper.Skeleton=StepperSkeleton;const buildSkeletonStyles=e=>StyleSheet.create({vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center"},vBody:{flex:1,paddingLeft:e.space.md,paddingBottom:e.space.lg}}),buildStyles=e=>StyleSheet.create({container:{width:"100%"},hRow:{flexDirection:"row",alignItems:"flex-start",justifyContent:"space-between",position:"relative"},hConnectorContainer:{position:"absolute",top:11,height:2,flexDirection:"row",alignItems:"center"},hConnectorTrack:{position:"absolute",left:0,right:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hConnectorFill:{position:"absolute",left:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hStepItem:{alignItems:"center",flex:1},hLabel:{marginTop:e.space.xs,textAlign:"center"},vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center",alignSelf:"stretch",width:32},vConnectorContainer:{flex:1,width:2,minHeight:32,position:"relative",alignSelf:"center"},vConnectorTrack:{position:"absolute",top:0,bottom:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vConnectorFill:{position:"absolute",top:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vBody:{flex:1,paddingLeft:e.space.sm,paddingBottom:e.space.md},vLabel:{marginBottom:e.space.xxs},vDescription:{},sCaption:{includeFontPadding:!1},sRow:{flexDirection:"row",columnGap:e.space.xs},sItem:{flex:1},sTrack:{height:4,borderRadius:e.radius.pill,overflow:"hidden"},sFill:{height:4,borderRadius:e.radius.pill}});export{Stepper};export default Stepper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSwitchSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},Switch=forwardRef((e,t)=>{const{value:
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSwitchSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},Switch=forwardRef((e,t)=>{const{value:i,defaultValue:s,onChange:r,disabled:a=!1,size:o="md",tone:n="primary",label:l,description:c,helperText:d,error:u,layout:p="inline",accessibilityLabel:m,haptic:h="selection",bounce:f=!1,style:b,containerStyle:g,trackStyle:y,thumbStyle:w,testID:x,hitSlop:S,...j}=e,v=useTheme(),V=Object.keys(v.components.switch);assertValidValue("Switch","size",e.size,V),assertValidValue("Switch","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Switch","layout",e.layout,["inline","row"]);const[T,C]=useControllableState({value:i,defaultValue:s??!1,onChange:r}),R=V.includes(o)?o:"md",k=useMemo(()=>resolveSwitchSize(v,R),[v,R]),A=v.colors["switch-thumb"],D=useMemo(()=>buildStyles(v),[v]),_="dark"===v.mode?v.colors.neutral:v.colors["surface-disabled"],z=toneColor(v,n),E=S??8,F=useRef(createAnimatedValue(T?1:0)).current;useEffect(()=>{const e=Animated.spring(F,{toValue:T?1:0,damping:v.motion.spring.snappy.damping,stiffness:v.motion.spring.snappy.stiffness,mass:v.motion.spring.snappy.mass,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[T,F,v.motion.spring.snappy]);const H=useRef(createAnimatedValue(T?1:0)).current;useEffect(()=>{const e=Animated.timing(H,{toValue:T?1:0,duration:v.motion.duration.fast,easing:Easing.out(Easing.ease),useNativeDriver:!1});return e.start(),()=>e.stop()},[T,H,v.motion.duration.fast]);const M=k.padding,P=k["track-width"]-k["thumb-size"]-k.padding,I=F.interpolate({inputRange:[0,1],outputRange:[M,P]}),N=H.interpolate({inputRange:[0,1],outputRange:[_,z]}),L=useRef(createAnimatedValue(1)).current,B=useRef(!0);useEffect(()=>{if(!f)return;if(B.current)return void(B.current=!1);const e=Animated.sequence([Animated.spring(L,{toValue:1.15,damping:10,stiffness:220,mass:1,useNativeDriver:nativeDriver}),Animated.spring(L,{toValue:1,damping:14,stiffness:240,mass:1,useNativeDriver:nativeDriver})]);return e.start(),()=>e.stop()},[T,f,L]);const handlePress=e=>{a||(!1!==h&&triggerHaptic(h),C(!T),j.onPressOut?.(e))},O=m??fieldTextAsString(l),q="string"==typeof u?u:void 0,U=hasChoiceDetail({description:c,error:q,helperText:d}),W=hasFieldText(l)||U,X=(!0===u||hasFieldText(u))&&!T&&!a,G="row"===p&&W,J=_jsxs(Animated.View,{style:[D.track,{width:k["track-width"],height:k["track-height"],borderRadius:v.radius.pill,...smoothCorners,backgroundColor:N},y],children:[X?_jsx(View,{pointerEvents:"none",style:[D.errorRing,{borderRadius:v.radius.pill,...smoothCorners,borderWidth:v.size.border,borderColor:v.colors["field-border-error"]}]}):null,_jsx(Animated.View,{style:[D.thumb,v.shadow.card,{backgroundColor:A,width:k["thumb-size"],height:k["thumb-size"],borderRadius:v.radius.pill,...smoothCorners,transform:[{translateX:I},{scale:L}]},w]})]});if(G)return _jsxs(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:T,disabled:a},"aria-checked":T,"aria-disabled":a,testID:x,hitSlop:S,...null==S?{}:hitSlopMarker(S),...j,style:({pressed:e})=>[D.row,D.spreadRow,U?D.rowTop:null,{opacity:a?.55:e?.9:1},g,b],children:[_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:D.spreadText}),J]});const K=_jsx(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:T,disabled:a},"aria-checked":T,"aria-disabled":a,testID:x,hitSlop:E,...hitSlopMarker(E),...j,style:({pressed:e})=>[{opacity:a?.55:e?.9:1},W?null:b],children:J});return W?_jsxs(View,{style:[D.row,U?D.rowTop:null,g,b],children:[K,_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:D.text})]}):g?_jsx(View,{style:g,children:K}):K});Switch.displayName="Switch";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},track:{justifyContent:"center"},thumb:{position:"absolute",top:2},errorRing:{...StyleSheet.absoluteFill},rowTop:{alignItems:"flex-start"},text:{marginLeft:e.space.sm},spreadRow:{minHeight:44,justifyContent:"space-between"},spreadText:{flex:1,marginRight:e.space.md}});export{Switch};export default Switch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveSegmentedControlSize,resolveTabsSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Badge}from"../Badge/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const Tabs=forwardRef((e,t)=>{const{tabs:i,activeKey:a,onChange:
|
|
1
|
+
"use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveSegmentedControlSize,resolveTabsSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Badge}from"../Badge/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const measuredLayout=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`Tabs: tab "${t}" has no measured layout while its progress signal drives the indicator`);return i},Tabs=forwardRef((e,t)=>{const{tabs:i,activeKey:a,onChange:r,variant:s="underline",radius:n,size:o="md",scrollable:l=!1,align:d="left",style:c,tabStyle:u,tabLabelStyle:m,tabIconStyle:p,tabBadgeStyle:b,dividerStyle:g,indicatorStyle:h,progress:f,pages:y,haptic:x,accessibilityLabel:v,testID:S}=e;assertValidValue("Tabs","variant",e.variant,["underline","pills","segmented"]),assertValidValue("Tabs","size",e.size,["sm","md","lg"]),assertValidValue("Tabs","align",e.align,["left","center"]);const w=useTheme(),V=useMemo(()=>buildStyles(w),[w]),j=w.components.tabs,T=useMemo(()=>resolveTabsSize(w,o),[w,o]),_=l?T["scrollable-padding-x"]:T["padding-x"],k=T["padding-y"],R=T.text,z=w.space[j["icon-gap"]],C=T.icon,L=j["underline-height"],E=w.space[j["pill-inset"]],I=j["disabled-opacity"],A=w.space[j["badge-gap"]],F="segmented"===s,M=useMemo(()=>resolveSegmentedControlSize(w,o),[w,o]),H=w.space[j["track-padding"]],D="number"==typeof n?n:n?w.radius[n]:void 0,B=D??w.radius.md,P=void 0===D?w.radius.sm:Math.max(D-H,0),q=D??w.radius.pill,N=D??w.radius.none,$=w.colors["bg-muted"],O=useSquircle(F,B),[W,U]=useState({}),K=useRef(createAnimatedValue(0)).current,X=useRef(createAnimatedValue(0)).current,[G,J]=useState(0),Q=useRef(createAnimatedValue(0)).current,Y=useRef(null),Z=useRef(0),ee=W[a],te=Math.max(0,i.findIndex(e=>e.key===a)),ie=useMemo(()=>y&&G>0?Q.interpolate({inputRange:[0,G],outputRange:[0,1]}):void 0,[y,G,Q])??f,ae=i.every(e=>void 0!==W[e.key]),re=void 0!==ie&&ae&&i.length>1,se=useMemo(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>measuredLayout(W,e.key).x),extrapolate:"clamp"}):null,[re,ie,i,W]),ne=useMemo(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>measuredLayout(W,e.key).width),extrapolate:"clamp"}):null,[re,ie,i,W]),oe=useRef(null);useEffect(()=>{if(!ee)return;if(re)return;const e=null!==oe.current&&oe.current!==a;if(oe.current=a,!e)return K.setValue(ee.x),void X.setValue(ee.width);const t=w.motion.spring.snappy,i=Animated.parallel([Animated.spring(K,{toValue:ee.x,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1}),Animated.spring(X,{toValue:ee.width,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1})]);return i.start(),()=>i.stop()},[ee,a,K,X,w.motion.spring.snappy,re]),useEffect(()=>{y&&0!==G&&Z.current!==te&&(Z.current=te,Y.current?.scrollTo({x:te*G,animated:!0}))},[y,G,te]);const le=y?.length;useEffect(()=>{__DEV__&&void 0!==le&&le!==i.length&&Logger.warn(`[@webority/mobile-ui] Tabs pages has ${le} entries for ${i.length} tabs; each tab needs one page.`)},[le,i.length]);const de=useCallback(e=>t=>{const{x:i,width:a}=t.nativeEvent.layout;U(t=>{const r=t[e];return r&&r.x===i&&r.width===a?t:{...t,[e]:{x:i,width:a}}})},[]),ce=useCallback(e=>{if(e.disabled)return;if(e.key===a)return;const t=resolveHaptic(x,"selection");t&&triggerHaptic(t),r(e.key)},[a,r,x]),ue="pills"===s,me=_jsx(Animated.View,{pointerEvents:"none",style:[F?V.indicatorThumb:ue?V.indicatorPill:V.indicatorUnderline,F?null:ue?{top:E,bottom:E}:{height:L},{width:ne??X,transform:[{translateX:se??K}],backgroundColor:F?w.colors.surface:ue?w.colors["primary-soft"]:w.colors.primary,borderRadius:F?P:ue?q:N,...smoothCorners},h]}),renderTabs=()=>i.map(e=>{const t=e.key===a,i=!0===e.disabled,r=t?w.colors.primary:w.colors["text-subtle"],s=renderSlotIcon(e.icon,{color:r,size:C,focused:t,disabled:i});return _jsxs(Pressable,{onPress:()=>ce(e),onLayout:de(e.key),disabled:i,accessibilityRole:"tab",accessibilityLabel:e.label,accessibilityState:{selected:t,disabled:i},"aria-selected":t,"aria-disabled":i,android_ripple:F?void 0:{color:w.colors["surface-pressed"],borderless:!1},style:({pressed:e})=>[V.tab,l?null:V.tabFlex,F?{paddingHorizontal:M["padding-x"],height:M.height-2*H}:{paddingHorizontal:_,paddingVertical:k},{opacity:i?I:e&&F&&!t?.7:1,backgroundColor:e&&!F?w.colors["surface-pressed"]:"transparent"},u],children:[s?_jsx(View,{style:[V.tabIcon,{marginRight:z},p],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:s}):null,_jsx(Text,{variant:"label",weight:t?"semibold":"medium",color:t?"brand":"tertiary",style:[V.tabLabel,{fontSize:F?M.text:R},m],numberOfLines:1,children:e.label}),void 0!==e.badge&&null!==e.badge?_jsx(Badge,{value:String(e.badge),tone:"primary",fill:"soft",accessible:!1,style:{marginLeft:A},badgeStyle:[V.tabBadge,b]}):null]},e.key)}),pe={flexDirection:"row",alignItems:"stretch",justifyContent:l?"flex-start":"center"===d?"center":"flex-start",position:"relative",overflow:"hidden"},be=_jsxs(_Fragment,F?{children:[me,renderTabs()]}:{children:[renderTabs(),me]}),ge=_jsxs(View,{ref:t,style:[V.container,{borderBottomColor:w.colors["border-subtle"],borderBottomWidth:"underline"===s?StyleSheet.hairlineWidth:0},"underline"===s?g:null,F?{padding:H,borderRadius:B,...smoothCorners,backgroundColor:O.active?"transparent":$}:null,c],onLayout:O.onLayout,accessibilityRole:"tablist",accessibilityLabel:v,testID:S,children:[O.active&&O.size?_jsx(SquircleFill,{width:O.size.width,height:O.size.height,radius:B,fill:$}):null,l?_jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[pe],keyboardShouldPersistTaps:"handled",children:be}):_jsx(View,{style:pe,children:be})]});return y?_jsxs(View,{style:V.root,children:[ge,_jsx(Animated.ScrollView,{ref:Y,horizontal:!0,pagingEnabled:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onLayout:e=>J(Math.round(e.nativeEvent.layout.width)),onScroll:Animated.event([{nativeEvent:{contentOffset:{x:Q}}}],{useNativeDriver:!1}),onMomentumScrollEnd:e=>{if(0===G)return;const t=Math.round(e.nativeEvent.contentOffset.x/G),s=i[t];s?.disabled?Y.current?.scrollTo({x:te*G,animated:!0}):(Z.current=t,s&&s.key!==a&&r(s.key))},style:V.pager,testID:S?`${S}-pages`:void 0,children:i.map((e,t)=>_jsx(View,{style:{width:G},accessibilityElementsHidden:t!==te,importantForAccessibility:t===te?"auto":"no-hide-descendants",children:y[t]},e.key))})]}):ge});Tabs.displayName="Tabs";const buildStyles=e=>StyleSheet.create({root:{flex:1},pager:{flex:1},container:{width:"100%",position:"relative"},tab:{flexDirection:"row",alignItems:"center",justifyContent:"center"},tabFlex:{flex:1},tabIcon:{},tabLabel:{includeFontPadding:!1,flexShrink:1},tabBadge:{minWidth:18,minHeight:0},indicatorUnderline:{position:"absolute",left:0,bottom:0},indicatorPill:{position:"absolute",left:0,zIndex:-1},indicatorThumb:{position:"absolute",left:0,top:0,bottom:0}});export{Tabs};export default Tabs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,useTheme}from"../../theme/index.js";import{mergeRefs,resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Chip}from"../Chip/index.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder}from"../FieldBase/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const TagInput=forwardRef((e,t)=>{const{value:s,defaultValue:l,onChange:r,placeholder:a,label:i,helperText:o,error:n,required:u,disabled:d=!1,size:c="md",variant:p,maxTags:m,unique:x=!0,transform:f,separators:h=[","],haptic:g,onFocus:b,style:j,testID:v}=e;assertValidValue("TagInput","size",e.size,["sm","md","lg"]),assertValidValue("TagInput","variant",e.variant,["outline","filled","underline"]);const y=useTheme(),C=useMemo(()=>buildStyles(y),[y]),[T,S]=useControllableState({value:s,defaultValue:l??[],onChange:r}),[F,V]=useState(""),[w,I]=useState(!1),z=useRef(null),_=useMemo(()=>mergeRefs(z,t),[t]),k=useCallback(()=>{d||z.current?.focus()},[d]),R="number"==typeof m&&T.length>=m,B=!0===n||hasFieldText(n),H=u&&!i&&0===T.length&&0===F.length&&Boolean(a),q=useCallback(e=>{const t=f?f(e.trim()):e.trim();if(!t)return;if(R)return;if(x&&T.some(e=>e.toLowerCase()===t.toLowerCase()))return void V("");S([...T,t]),V("");const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[R,g,S,T,f,x]),L=useCallback(e=>{const t=T.filter((t,s)=>s!==e);S(t);const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[g,S,T]),M=useCallback(e=>{const t=h.find(t=>t.length>0&&e.includes(t));
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,useTheme}from"../../theme/index.js";import{mergeRefs,resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Chip}from"../Chip/index.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder}from"../FieldBase/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const TagInput=forwardRef((e,t)=>{const{value:s,defaultValue:l,onChange:r,placeholder:a,label:i,helperText:o,error:n,required:u,disabled:d=!1,size:c="md",variant:p,maxTags:m,unique:x=!0,transform:f,separators:h=[","],haptic:g,onFocus:b,style:j,testID:v}=e;assertValidValue("TagInput","size",e.size,["sm","md","lg"]),assertValidValue("TagInput","variant",e.variant,["outline","filled","underline"]);const y=useTheme(),C=useMemo(()=>buildStyles(y),[y]),[T,S]=useControllableState({value:s,defaultValue:l??[],onChange:r}),[F,V]=useState(""),[w,I]=useState(!1),z=useRef(null),_=useMemo(()=>mergeRefs(z,t),[t]),k=useCallback(()=>{d||z.current?.focus()},[d]),R="number"==typeof m&&T.length>=m,B=!0===n||hasFieldText(n),H=u&&!i&&0===T.length&&0===F.length&&Boolean(a),q=useCallback(e=>{const t=f?f(e.trim()):e.trim();if(!t)return;if(R)return;if(x&&T.some(e=>e.toLowerCase()===t.toLowerCase()))return void V("");S([...T,t]),V("");const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[R,g,S,T,f,x]),L=useCallback(e=>{const t=T.filter((t,s)=>s!==e);S(t);const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[g,S,T]),M=useCallback(e=>{const t=h.find(t=>t.length>0&&e.includes(t));t?q(e.slice(0,e.indexOf(t))):V(e)},[q,h]),D=useCallback(e=>{d||"Backspace"===e.nativeEvent.key&&""===F&&T.length>0&&L(T.length-1)},[d,F,L,T.length]),P=_jsx(FieldBase,{size:c,variant:p,focused:w,disabled:d,error:B,filled:T.length>0||F.length>0,onPress:k,pressFeedback:!1,style:j,children:_jsxs(View,{style:C.wrap,children:[T.map((e,t)=>_jsx(Chip,{label:e,size:"sm",onRemove:d?void 0:()=>L(t),haptic:g},`${e}-${t}`)),_jsxs(View,{style:C.inputBox,children:[_jsx(TextInput,{ref:_,value:F,onChangeText:M,onKeyPress:D,onSubmitEditing:()=>q(F),onFocus:e=>{I(!0),b?.(e)},onBlur:()=>{I(!1),q(F)},editable:!d&&!R,placeholder:R||H?void 0:a,placeholderTextColor:y.colors["text-subtle"],blurOnSubmit:!1,returnKeyType:"done",accessibilityLabel:i??a,style:[C.input,{color:y.colors["text-body"],fontSize:y.text.base.size}],testID:v?`${v}-input`:void 0}),H?_jsx(RequiredPlaceholder,{text:a??"",color:y.colors["text-subtle"],fontSize:y.text.base.size,weightStyle:fontFor(y,"normal")}):null]})]})});return _jsxs(View,{testID:v,children:[i?_jsx(FieldLabel,{size:c,required:u,children:i}):null,P,_jsx(FieldMessage,{size:c,error:B,text:B?n:o})]})});TagInput.displayName="TagInput";const buildStyles=e=>StyleSheet.create({wrap:{flex:1,flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:e.space.xs,paddingVertical:e.space.xs},inputBox:{flexGrow:1,minWidth:80},input:{...fontFor(e,"normal"),padding:e.space.none}});export default TagInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useMemo}from"react";import{Text as RNText}from"react-native";import{fontFor,useTheme}from"../../theme/index.js";import{TEXT_NAMES}from"../../theme/tokens.generated.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{TextInkContext,useTextInk}from"./textInk.js";import{jsx as _jsx}from"react/jsx-runtime";const VARIANTS={display:{size:"4xl",weight:"bold",line:"display",color:"primary",heading:!0,fontFamily:"display"},h1:{size:"3xl",weight:"bold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h2:{size:"2xl",weight:"semibold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h3:{size:"xl",weight:"semibold",line:"heading",color:"primary",heading:!0},title:{size:"lg",weight:"semibold",line:"body",color:"primary",fontFamily:"display"},body:{size:"base",weight:"normal",line:"body",color:"primary"},bodySmall:{size:"sm",weight:"normal",line:"body",color:"secondary"},caption:{size:"xs",weight:"normal",line:"body",color:"tertiary"},label:{size:"sm",weight:"medium",line:"body",color:"secondary"},overline:{size:"xs",weight:"semibold",line:"body",color:"secondary",uppercase:!0,letterSpacing:"wide"}},TEXT_ROLE_COLOR={textStrong:"text",primary:"text-body",secondary:"text-muted",tertiary:"text-subtle",inverse:"text-inverse",disabled:"text-disabled",link:"link",brand:"primary-text"},SEMANTIC={success:!0,warning:!0,danger:!0,info:!0,neutral:!0},COLOR_NAMES=["primary","secondary","tertiary","inverse","disabled","link","textStrong","brand","success","warning","danger","info","neutral"];export const resolveColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)
|
|
1
|
+
"use strict";import{forwardRef,useMemo}from"react";import{Text as RNText}from"react-native";import{fontFor,useTheme}from"../../theme/index.js";import{TEXT_NAMES}from"../../theme/tokens.generated.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{TextInkContext,useTextInk}from"./textInk.js";import{jsx as _jsx}from"react/jsx-runtime";const VARIANTS={display:{size:"4xl",weight:"bold",line:"display",color:"primary",heading:!0,fontFamily:"display"},h1:{size:"3xl",weight:"bold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h2:{size:"2xl",weight:"semibold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h3:{size:"xl",weight:"semibold",line:"heading",color:"primary",heading:!0},title:{size:"lg",weight:"semibold",line:"body",color:"primary",fontFamily:"display"},body:{size:"base",weight:"normal",line:"body",color:"primary"},bodySmall:{size:"sm",weight:"normal",line:"body",color:"secondary"},caption:{size:"xs",weight:"normal",line:"body",color:"tertiary"},label:{size:"sm",weight:"medium",line:"body",color:"secondary"},overline:{size:"xs",weight:"semibold",line:"body",color:"secondary",uppercase:!0,letterSpacing:"wide"}},TEXT_ROLE_COLOR={textStrong:"text",primary:"text-body",secondary:"text-muted",tertiary:"text-subtle",inverse:"text-inverse",disabled:"text-disabled",link:"link",brand:"primary-text"},SEMANTIC={success:!0,warning:!0,danger:!0,info:!0,neutral:!0},COLOR_NAMES=["primary","secondary","tertiary","inverse","disabled","link","textStrong","brand","success","warning","danger","info","neutral"];export const resolveColor=(e,t)=>{if(Object.hasOwn(TEXT_ROLE_COLOR,t)){const i=TEXT_ROLE_COLOR[t];if(void 0===i)throw new Error(`resolveColor: "${t}" is listed as a text role but has no colour`);return e.colors[i]}return Object.hasOwn(SEMANTIC,t)?e.colors[`${t}-text`]:t};const resolveVariantColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)||Object.hasOwn(SEMANTIC,t)?resolveColor(e,t):e.colors[t],decorationOf=(e,t)=>e&&t?"underline line-through":e?"underline":t?"line-through":void 0,Text=forwardRef((e,t)=>{const{variant:i="body",color:o,weight:r,size:n,align:a,italic:l,underline:s,strikethrough:d,style:c,children:m,...x}=e,g=useTheme(),h=Object.hasOwn(VARIANTS,i),y=g.settings.textVariants,p=!h&&y&&Object.hasOwn(y,i)?y[i]:void 0;h||p||assertValidValue("Text","variant",e.variant,[...Object.keys(VARIANTS),...Object.keys(y??{})]),assertValidValue("Text","color",o,COLOR_NAMES),assertValidValue("Text","size",n,TEXT_NAMES);const u=void 0!==o&&COLOR_NAMES.includes(o)?o:void 0,b=useMemo(()=>{if(p){const e=n??p.size,t=g.text[e].size;return{fontSize:t,lineHeight:p.lineHeight??Math.round(t*g.leading[p.heading?"heading":"body"]),color:void 0!==u?resolveColor(g,u):p.color?resolveVariantColor(g,p.color):resolveColor(g,"primary"),textAlign:a,textTransform:p.uppercase?"uppercase":void 0,letterSpacing:p.letterSpacing?g["letter-spacing"][p.letterSpacing]:void 0,fontStyle:l||p.italic?"italic":void 0,fontVariant:p.fontVariant,textDecorationLine:decorationOf(s,d),...fontFor(g,r??p.weight??"normal",p.fontFamily)}}const e=VARIANTS[h?i:"body"],t=g.text[n??e.size].size;return{fontSize:t,lineHeight:Math.round(t*g.leading[e.line]),color:resolveColor(g,u??e.color),textAlign:a,textTransform:e.uppercase?"uppercase":void 0,letterSpacing:e.letterSpacing?g["letter-spacing"][e.letterSpacing]:void 0,fontStyle:l?"italic":void 0,textDecorationLine:decorationOf(s,d),...fontFor(g,r??e.weight,e.fontFamily)}},[g,p,h,i,u,r,n,a,l,s,d]),f=useTextInk([b,c],g.text.base.size,g.colors["text-body"]),T=h?VARIANTS[i].heading:p?.heading,O="string"==typeof m||"number"==typeof m;return _jsx(RNText,{ref:t,style:[b,c],maxFontSizeMultiplier:g.settings.maxFontSizeMultiplier,accessibilityRole:T?"header":x.accessibilityRole,...x,children:O?m:_jsx(TextInkContext.Provider,{value:f,children:m})})});Text.displayName="Text";export{Text};export default Text;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`});const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`});const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:i,shownAt:n,runtime:a})=>{const s=useTheme(),r=usePresenceMotion(),o=r.duration("fast");assertValidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=a?.labels??DEFAULT_TOAST_LABELS,d=useMemo(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=useMemo(()=>buildStyles(s),[s]),p=useMemo(()=>tintFor(s,l),[s,l]),g=useMemo(()=>inkFor(s,l),[s,l]),v=s.components.toast["icon-circle-size"],h=s.text[s.components.toast["icon-glyph-text"]].size,f=s.components.toast["tint-bar-width"],b=s.settings.components.toast?.defaultDurationMs??3e3,A=s.settings.components.toast?.enableSwipeDismiss??!0,x="top"===c?-120:120,y=useRef(createAnimatedValue(r.reduced?0:x)).current,w=useRef(createAnimatedValue(0)).current,D=useRef(createAnimatedValue(0)).current,S=useRef(!1),T="top"===c?8*t:8*-t,V=Math.max(1-.04*t,.9),M=useRef(createAnimatedValue(T)).current;useEffect(()=>{setNativeValue(M,T)},[T,M]);const _=useMemo(()=>Animated.add(y,M),[y,M]),R=void 0!==e.action,C=e.duration??b,E=C>0&&R&&"web"===Platform.OS?Math.max(C,8e3):C,N=E<=0||R&&!0===a?.screenReaderOn,j=!0===e.countdown&&!N,P=useRef(createAnimatedValue(1)).current,O=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),k=useRef({touch:!1,pan:!1,hover:!1}),L=useRef(()=>{}),I=useRef({id:e.id,totalMs:E,shownAt:n,runtime:a,persistent:N,animateBar:!1});I.current={id:e.id,totalMs:E,shownAt:n,runtime:a,persistent:N,animateBar:j&&!r.reduced};const H=useCallback(()=>{const e=O.current,t=I.current,i=k.current;if(!e.initialised){e.initialised=!0;const i=t.runtime?.readRemaining(t.id),n=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=i??(t.totalMs>0?Math.max(t.totalMs-n,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(P,e.remaining/t.totalMs)}const n=!(t.persistent||S.current||i.touch||i.pan||i.hover);n&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,L.current()},e.remaining),t.animateBar&&Animated.timing(P,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:nativeDriver}).start()):n||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),P.stopAnimation())},[P]),dismiss=()=>{if(S.current)return;S.current=!0,H();const t=[Animated.timing(D,{toValue:0,duration:o,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:nativeDriver})];r.reduced||t.push(Animated.timing(y,{toValue:x,duration:s.motion.duration.fast,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:nativeDriver})),Animated.parallel(t).start(()=>i(e.id))};L.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.spring(y,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{H()},[N,H]),useEffect(()=>()=>{const e=O.current,t=I.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),P.stopAnimation(),e.initialised&&t.totalMs>0&&!S.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[P]);const B=useCallback((e,t)=>{k.current[e]=t,H()},[H]),F=useCallback(()=>B("touch",!0),[B]),z=useCallback(e=>B("touch",(e.nativeEvent.touches?.length??0)>0),[B]),U=useCallback(()=>B("hover",!0),[B]),$=useCallback(()=>B("hover",!1),[B]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>B("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(w,t.dx);const i=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(D,i)},onPanResponderTerminate:()=>{if(B("pan",!1),r.reduced)return setNativeValue(w,0),void Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start();Animated.parallel([Animated.spring(w,{toValue:0,damping:s.motion.spring.snappy.damping,stiffness:s.motion.spring.snappy.stiffness,mass:s.motion.spring.snappy.mass,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]).start()},onPanResponderRelease:(t,n)=>{if(Math.abs(n.dx)>80||Math.abs(n.vx)>.5){const t=n.dx>=0?1:-1;S.current=!0,B("pan",!1);const a=[Animated.timing(D,{toValue:0,duration:o,useNativeDriver:nativeDriver})];r.reduced||a.push(Animated.timing(w,{toValue:500*t,duration:s.motion.duration.fast,useNativeDriver:nativeDriver})),Animated.parallel(a).start(()=>i(e.id))}else B("pan",!1),r.reduced?(setNativeValue(w,0),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start()):Animated.parallel([Animated.spring(w,{toValue:0,useNativeDriver:nativeDriver}),Animated.spring(D,{toValue:1,useNativeDriver:nativeDriver})]).start()}}),[w,D,B,o,r.reduced,s.motion.duration.fast,s.motion.spring.snappy.damping,s.motion.spring.snappy.stiffness,s.motion.spring.snappy.mass,i,e.id]),W={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[K,X]=useState(0),Y=useMemo(()=>P.interpolate({inputRange:[0,1],outputRange:[-K,0]}),[P,K]),q=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&j?`${e.action.label}, ${u.seconds(Math.ceil(E/1e3))}`:e.action?.label;return _jsxs(Animated.View,{...A?G.panHandlers:{},...R?{}:{accessible:!0,...W},..."web"===Platform.OS?{onPointerEnter:U,onPointerLeave:$}:{},onTouchStart:F,onTouchEnd:z,onTouchCancel:z,accessibilityLabel:q,testID:e.testID,style:[m.container,{backgroundColor:s.colors.surface,borderRadius:s.radius.lg,...smoothCorners,padding:s.space.md,...s.shadow.elevated,opacity:D,transform:[{translateY:_},{translateX:w},{scale:V}]},e.style],children:[f>0?_jsx(View,{style:[m.tintBar,{width:f,backgroundColor:p}]}):null,_jsxs(View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[m.iconCircle,{width:v,height:v,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:`${p}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[m.iconGlyph,{color:g,fontSize:h}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:m.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[m.message,e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...W,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?s.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:p},numberOfLines:1,children:e.action.label})}):null]}),j?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>X(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${p}22`}],children:[r.reduced?_jsx(View,{style:[m.countdownFill,{backgroundColor:p}]}):null,!r.reduced&&K>0?_jsx(Animated.View,{style:[m.countdownFill,{backgroundColor:p,transform:[{translateX:Y}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;case"neutral":return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];case"neutral":return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";case"primary":case"neutral":return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Logger}from"@webority/mobile-core";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Platform,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import Toast,{DEFAULT_TOAST_LABELS}from"./Toast.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MAX_VISIBLE=3,UNDO_DEFAULT_DURATION_MS=6e3,UNDO_MIN_DURATION_MS=6e3,ToastContext=createContext(null),ToastHostContext=createContext(null);let nextId=0;const makeId=()=>(nextId+=1,`toast-${Date.now().toString(36)}-${nextId.toString(36)}`),defaultHaptic=e=>{switch(e){case"danger":return"notificationError";case"success":return"notificationSuccess";case"warning":return"notificationWarning";
|
|
1
|
+
"use strict";import{Logger}from"@webority/mobile-core";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Platform,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import Toast,{DEFAULT_TOAST_LABELS}from"./Toast.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MAX_VISIBLE=3,UNDO_DEFAULT_DURATION_MS=6e3,UNDO_MIN_DURATION_MS=6e3,ToastContext=createContext(null),ToastHostContext=createContext(null);let nextId=0;const makeId=()=>(nextId+=1,`toast-${Date.now().toString(36)}-${nextId.toString(36)}`),defaultHaptic=e=>{switch(e){case"danger":return"notificationError";case"success":return"notificationSuccess";case"warning":return"notificationWarning";case"info":case"primary":case"neutral":case void 0:return"selection"}},resolveHaptics=(e,t)=>{if(!1===e)return!1;const o=e?.[t??"neutral"];return void 0===o?defaultHaptic(t):o};let nextHostId=0;const makeHostId=()=>(nextHostId+=1,nextHostId),useScreenReaderEnabled=()=>{const[e,t]=useState(!1);return useEffect(()=>{if("web"===Platform.OS)return;let e=!0;AccessibilityInfo.isScreenReaderEnabled().then(o=>{e&&t(o)});const o=AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,o.remove()}},[]),e};let providerCount=0,activeApi=null;const setActiveApi=e=>{activeApi=e},getActiveApi=()=>activeApi;export const ToastProvider=({children:e,maxVisible:t=3,topOffset:o,bottomOffset:s,defaultDuration:r,haptics:n,labels:a})=>{const i=useMemo(()=>({...DEFAULT_TOAST_LABELS,...a}),[a]),u=useRef({defaultDuration:r,haptics:n,labels:i});u.current={defaultDuration:r,haptics:n,labels:i};const[c,l]=useState([]),[d,m]=useState([]),f=useScreenReaderEnabled(),p=useRef(new Map),h=useRef(new Map);useEffect(()=>{const e=new Set(c.map(e=>e.id));for(const[t,o]of[...p.current])e.has(t)||(p.current.delete(t),o());for(const t of[...h.current.keys()])e.has(t)||h.current.delete(t)},[c]),useEffect(()=>{const e=p.current;return()=>{for(const[t,o]of[...e])e.delete(t),o()}},[]);const x=useMemo(()=>({screenReaderOn:f,labels:i,readRemaining:e=>h.current.get(e),writeRemaining:(e,t)=>{h.current.set(e,t)}}),[f,i]),g=useCallback(e=>{l(t=>t.filter(t=>t.id!==e))},[]),b=useCallback(()=>{l([])},[]),w=useCallback(e=>{const o=makeId(),{defaultDuration:s,haptics:r}=u.current,n={...e,duration:e.duration??s,id:o,shownAt:Date.now()},a=void 0!==e.haptic?e.haptic:resolveHaptics(r,e.tone);return!1!==a&&triggerHaptic(a),announce(e.description?`${e.message}. ${e.description}`:e.message,{polite:"danger"!==e.tone}),l(o=>{const s=[...void 0===e.key?o:o.filter(t=>t.key!==e.key),n];return s.length>t?s.slice(s.length-t):s}),o},[t]),v=useCallback((e,t)=>{const{onUndo:o,onCommit:s,duration:r,...n}=t,a={id:""},i=w({...n,message:e,duration:0===r?0:Math.max(r??6e3,6e3),countdown:!0,action:{label:u.current.labels.undo,onPress:()=>{p.current.delete(a.id),o()}}});return a.id=i,s&&p.current.set(i,s),i},[w]),_=useMemo(()=>({show:w,undo:v,hide:g,hideAll:b}),[w,v,g,b]);useEffect(()=>(providerCount+=1,setActiveApi(_),()=>{providerCount-=1,providerCount<=0&&(providerCount=0,setActiveApi(null))}),[_]);const A=useCallback(e=>{m(t=>[...t,e])},[]),y=useCallback(e=>{m(t=>t.filter(t=>t!==e))},[]),T=d.at(-1)??null,C=useMemo(()=>({register:A,unregister:y,activeHostId:T,queue:c,hide:g,topOffset:o,bottomOffset:s,runtime:x}),[A,y,T,c,g,o,s,x]);return _jsx(ToastContext.Provider,{value:_,children:_jsxs(ToastHostContext.Provider,{value:C,children:[e,null===T?_jsx(ToastLayers,{queue:c,onDismiss:g,topOffset:o,bottomOffset:s,runtime:x}):null]})})};let warnedHost=!1;const warnHostWithoutProvider=()=>{warnedHost||(warnedHost=!0,"undefined"!=typeof __DEV__&&__DEV__&&Logger.warn("[@webority/mobile-ui] Toast: <ToastHost /> rendered outside a <ToastProvider />; it renders nothing. Mount a provider near your app root."))};export const ToastHost=()=>{const e=useContext(ToastHostContext),[t]=useState(makeHostId),o=e?.register,s=e?.unregister;return useEffect(()=>{if(o&&s)return o(t),()=>s(t);warnHostWithoutProvider()},[o,s,t]),e&&e.activeHostId===t?_jsx(ToastLayers,{queue:e.queue,onDismiss:e.hide,topOffset:e.topOffset,bottomOffset:e.bottomOffset,runtime:e.runtime}):null};const ToastLayers=({queue:e,onDismiss:t,topOffset:o,bottomOffset:s,runtime:r})=>{const n=useTheme(),a=useSafeAreaInsets(),i=useMemo(()=>buildStyles(),[]),u=e.filter(e=>"top"===(e.position??"bottom")),c=e.filter(e=>"bottom"===(e.position??"bottom"));return _jsxs(_Fragment,{children:[_jsx(View,{testID:"toast-layer-top",pointerEvents:"box-none",style:[i.layer,i.top,{top:(o??a.top)+n.space.sm,paddingHorizontal:n.space.md}],children:u.map((e,o)=>_jsx(Toast,{toast:e,index:u.length-1-o,shownAt:e.shownAt,runtime:r,onClose:t},e.id))}),_jsx(View,{testID:"toast-layer-bottom",pointerEvents:"box-none",style:[i.layer,i.bottom,{bottom:(s??a.bottom)+n.space.sm,paddingHorizontal:n.space.md}],children:c.map((e,o)=>_jsx(Toast,{toast:e,index:c.length-1-o,shownAt:e.shownAt,runtime:r,onClose:t},e.id))})]})};export const useToast=()=>{const e=useContext(ToastContext);if(!e)throw new Error("useToast must be used within a <ToastProvider>.");return e};let warned=!1;const warnNoProvider=()=>{warned||(warned=!0,"undefined"!=typeof __DEV__&&__DEV__&&Logger.warn("[@webority/mobile-ui] Toast: no <ToastProvider /> mounted; toast() calls are no-ops. Mount a provider near your app root."))},proxy=e=>{const t=getActiveApi();return t?e(t):(warnNoProvider(),"")};export const toast={show:e=>proxy(t=>t.show(e)),undo:(e,t)=>proxy(o=>o.undo(e,t)),success:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"success"})),error:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"danger"})),warning:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"warning"})),info:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"info"})),hideAll:()=>{const e=getActiveApi();e?e.hideAll():warnNoProvider()}};const buildStyles=()=>StyleSheet.create({layer:{position:"absolute",left:0,right:0},top:{alignItems:"stretch"},bottom:{alignItems:"stretch"}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{claimAnchoredSurface}from"../../utils/placement.js";import{FOCUS_DELAY_MS,focusHost}from"../Menu/focusHost.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{RichTooltipBody}from"./RichTooltipBody.js";import{resolveTooltipPosition}from"./tooltipPosition.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_TOOLTIP_LABELS=Object.freeze({close:"Close tooltip",longPressHint:"Long press for more info",fallbackName:"Tooltip"});const PRESS_AUTO_HIDE_MS=4e3,ARROW_HALF_WIDTH=4,ARROW_HEIGHT=6,ARROW_CORNER_PADDING=12,DEFAULT_MAX_WIDTH=240,RICH_MAX_WIDTH=280,MESSAGE_LINE_HEIGHT=18,EXIT_DURATION_MS=150,Tooltip=e=>{const{content:t,children:
|
|
1
|
+
"use strict";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{claimAnchoredSurface}from"../../utils/placement.js";import{FOCUS_DELAY_MS,focusHost}from"../Menu/focusHost.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{RichTooltipBody}from"./RichTooltipBody.js";import{resolveTooltipPosition}from"./tooltipPosition.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_TOOLTIP_LABELS=Object.freeze({close:"Close tooltip",longPressHint:"Long press for more info",fallbackName:"Tooltip"});const PRESS_AUTO_HIDE_MS=4e3,ARROW_HALF_WIDTH=4,ARROW_HEIGHT=6,ARROW_CORNER_PADDING=12,DEFAULT_MAX_WIDTH=240,RICH_MAX_WIDTH=280,MESSAGE_LINE_HEIGHT=18,EXIT_DURATION_MS=150,Tooltip=e=>{const{content:t,children:r,variant:o="plain",title:s,action:n,placement:i="auto",open:a,onOpenChange:l,hideOnContentPress:u=!0,maxWidth:c,showArrow:m=!0,accessibilityLabel:p,style:f,containerStyle:d,arrowStyle:h,messageStyle:g,labels:b,testID:T}=e;assertValidValue("Tooltip","variant",e.variant,["plain","rich"]),assertValidValue("Tooltip","placement",e.placement,["top","bottom","left","right","auto"]),assertValidValue("Tooltip","trigger",e.trigger,["longPress","press","manual"]);const v="rich"===o,S=e.trigger??(v?"press":"longPress"),y=useMemo(()=>({...DEFAULT_TOOLTIP_LABELS,...b}),[b]),R=useTheme(),A=usePresenceMotion(),_=useSafeAreaInsets(),[w,j]=useModalInsets(),x=useMemo(()=>({..._,top:w.top,bottom:w.bottom}),[_,w]),C=useWindowDimensions(),E=useMemo(()=>buildStyles(R),[R]),D=R.space.sm,M=R.space.sm,P=c??(v?280:240),V="press"===S&&!v,L=(R.settings.components.tooltip?.enableScaleAnimation??!1)&&!A.reduced,O="manual"===S||"boolean"==typeof a,[I,H]=useState(!1),W=O?Boolean(a):I,[k,N]=useState(null),[F,B]=useState({width:0,height:0}),U=useRef(null),z=useRef(null),G=useRef(null),X=useRef(null),Y=useRef(null),q=useRef(!1),J=useRef(!1),K=useRef(createAnimatedValue(W||!L?1:.85)).current,Q=useRef(createAnimatedValue(W?1:0)).current,Z=useRef(null),$=useRef(!1),[ee,te]=useState(W),re=useCallback(e=>{O||H(e),l?.(e)},[O,l]),oe=useCallback(()=>{U.current&&U.current.measureInWindow((e,t,r,o)=>{N({x:e,y:t,width:r,height:o})})},[]),se=useCallback(e=>{oe(),re(!0)},[oe,re]),ne=useCallback(()=>{re(!1)},[re]),ie=useRef(ne);ie.current=ne;const ae=useCallback(()=>{if(!q.current)return;q.current=!1;const e=Y.current;Y.current=null,e?e():v&&focusHost(z.current??U.current)},[v]);useEffect(()=>{if(W)return J.current=!0,q.current=!1,claimAnchoredSurface(()=>ie.current());J.current&&(J.current=!1,q.current=!0)},[W]),useEffect(()=>{W&&te(!0)},[W]);const le=useCallback(()=>{Y.current=n?.onPress??null,ne()},[n,ne]);useEffect(()=>{if(!$.current)return $.current=!0,W&&(oe(),V&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))),()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)};let e;if(W){oe();const t=[Animated.timing(Q,{toValue:1,duration:A.duration("fast"),useNativeDriver:nativeDriver})];L?t.push(Animated.spring(K,{toValue:1,damping:R.motion.spring.snappy.damping,stiffness:R.motion.spring.snappy.stiffness,mass:R.motion.spring.snappy.mass,useNativeDriver:nativeDriver})):setNativeValue(K,1),e=Animated.parallel(t),e.start(),V&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))}else{const t=[Animated.timing(Q,{toValue:0,duration:A.reduced?A.duration("fast"):150,easing:Easing.bezier(...R.motion.ease.accelerate),useNativeDriver:nativeDriver})];L&&t.push(Animated.timing(K,{toValue:.85,duration:150,easing:Easing.bezier(...R.motion.ease.accelerate),useNativeDriver:nativeDriver})),e=Animated.parallel(t),e.start(({finished:e})=>{e&&te(!1)}),Z.current&&(clearTimeout(Z.current),Z.current=null)}return()=>{e?.stop(),Z.current&&(clearTimeout(Z.current),Z.current=null)}},[W]);const handleContentLayout=e=>{const{width:t,height:r}=e.nativeEvent.layout;t===F.width&&r===F.height||B({width:t,height:r})},ue=useMemo(()=>resolveTooltipPosition({anchor:k,size:F,placement:i,rich:v,viewport:{width:C.width,height:C.height,insets:x},maxWidth:P,gap:D,padding:M,arrowCornerPadding:12}),[k,F,i,v,C.width,C.height,x,P,D,M]),ce=null!==k&&F.width>0,me=W&&ce;useEffect(()=>{if(!v||!me)return;const e="web"===Platform.OS?X:G,t=setTimeout(()=>focusHost(e.current),FOCUS_DELAY_MS);return()=>clearTimeout(t)},[v,me]),useEffect(()=>{!v&&me&&"ios"===Platform.OS&&"string"==typeof t&&announce(t)},[v,me,t]);const pe=r.props,fe=useMemo(()=>mergeRefs(pe.ref,z),[pe.ref]),de={};"longPress"!==S||pe.contextMenu?"press"===S&&(de.onPress=e=>{pe.onPress?.(e),se(e)}):(de.onLongPress=se,de.accessibilityHint=y.longPressHint),v&&(de.ref=fe);const he=React.cloneElement(r,de),ge=p??("string"==typeof t?t:y.fallbackName),be=useMemo(()=>{if(!m)return null;const e={position:"absolute",width:0,height:0,backgroundColor:"transparent",borderStyle:"solid",borderLeftWidth:4,borderRightWidth:4,borderBottomWidth:6,borderTopWidth:0,borderLeftColor:"transparent",borderRightColor:"transparent",borderTopColor:"transparent",borderBottomColor:v?R.colors.surface:R.colors["surface-inverse"]};return"top"===ue.placement?{...e,bottom:-6,left:ue.arrowOffset-4,transform:[{rotate:"180deg"}]}:"bottom"===ue.placement?{...e,top:-6,left:ue.arrowOffset-4}:"left"===ue.placement?{...e,right:-6,top:ue.arrowOffset-4,transform:[{rotate:"90deg"}]}:{...e,left:-6,top:ue.arrowOffset-4,transform:[{rotate:"-90deg"}]}},[m,ue,R,v]),Te={position:"absolute",top:ue.top,left:ue.left,maxWidth:P,opacity:W&&!ce?0:Q,transform:[{scale:K}]},ve=be?_jsx(View,{style:[be,h],pointerEvents:"none"}):null;return _jsxs(_Fragment,{children:[_jsx(View,{ref:U,collapsable:!1,onLayout:oe,testID:T,children:he}),_jsxs(Modal,{open:ee,onClose:ne,presentation:"fullScreen",bare:!0,backdropOpacity:0,backdropPressClose:u,haptic:!1,labels:{close:y.close},onInsetsChange:j,onDismissed:ae,children:[ee&&v?_jsxs(Animated.View,{onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(RichTooltipBody,{title:s,content:t,action:n,onAction:le,focusRef:G,actionRef:X,messageStyle:g}),ve]}):null,ee&&!v?_jsxs(Animated.View,{accessibilityRole:"web"===Platform.OS?"tooltip":void 0,accessibilityLiveRegion:"polite",accessibilityLabel:ge,onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(View,{style:[E.tooltip,{backgroundColor:R.colors["surface-inverse"],borderRadius:R.radius.md,...smoothCorners,paddingHorizontal:R.space.md,paddingVertical:R.space.sm,...R.shadow.popover,shadowColor:R.shadow.popover.shadowColor}],children:"string"==typeof t?_jsx(Text,{variant:"bodySmall",color:"inverse",style:{lineHeight:18,...StyleSheet.flatten(g)},children:t}):t}),ve]}):null]})]})},buildStyles=e=>StyleSheet.create({tooltip:{overflow:"hidden"}});export{Tooltip};export default Tooltip;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{Button}from"../Button/index.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOUR_LABELS=Object.freeze({back:"Back",next:"Next",skip:"Skip",done:"Done",position:(e,t)=>`Step ${e} of ${t}`});const MAX_CARD_WIDTH=360,HIGHLIGHT_BORDER_WIDTH=2,measureInWindow=e=>new Promise(t=>{const i=e.current;i?i.measureInWindow((e,i,s,
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Button}from"../Button/index.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOUR_LABELS=Object.freeze({back:"Back",next:"Next",skip:"Skip",done:"Done",position:(e,t)=>`Step ${e} of ${t}`});const MAX_CARD_WIDTH=360,HIGHLIGHT_BORDER_WIDTH=2,measureInWindow=e=>new Promise(t=>{const i=e.current;i?i.measureInWindow((e,i,s,r)=>t({x:e,y:i,width:s,height:r})):t(null)}),isOnScreen=(e,t)=>e.width>0&&e.height>0&&e.x<t.width&&e.y<t.height&&e.x+e.width>0&&e.y+e.height>0,Tour=({tourId:e,steps:t,open:i,onClose:s,seenStore:r,labels:n,haptic:o,testID:a})=>{const c=useTheme(),l=usePresenceMotion().duration("fast"),u=useMemo(()=>buildStyles(c),[c]),d=useWindowDimensions(),h=useRef(d);h.current=d;const m=c.space.sm,p=c.space.sm,x=useMemo(()=>({...DEFAULT_TOUR_LABELS,...n}),[n]),[f,g]=useState(null),[w,b]=useState(0),y=useRef(createAnimatedValue(0)).current,j=useRef(t);j.current=t;const v=useRef(x);v.current=x;const S=useRef(s);S.current=s;const T=useRef(r);T.current=r;const _=useCallback(async(e,t)=>{for(let i=e;i>=0&&i<j.current.length;i+=t){const e=j.current[i];if(void 0===e)throw new Error(`Tour: no step at index ${i}, though the loop bound checked it`);const t=await measureInWindow(e.target);if(t&&isOnScreen(t,h.current))return{index:i,rect:t}}return null},[]);useEffect(()=>{if(!i)return void g(null);let t=!1;return(async()=>{const i=T.current;if(i&&await i.isSeen(e))return void(t||S.current("alreadySeen"));const s=await _(0,1);t||(s?(b(s.index),g(s)):S.current("noTargets"))})(),()=>{t=!0}},[i,e,_]),useEffect(()=>{if(!f)return;const e=j.current[f.index];if(void 0===e)throw new Error(`Tour: the current step ${f.index} is missing from the steps list`);const t=v.current.position(f.index+1,j.current.length);AccessibilityInfo.announceForAccessibility([t,e.title,e.description].filter(Boolean).join(". ")),y.setValue(0);const i=Animated.timing(y,{toValue:1,duration:l,useNativeDriver:nativeDriver});return i.start(),()=>i.stop()},[f,y,l]);const k=useCallback(async t=>{g(null),await(T.current?.markSeen(e)),S.current(t)},[e]),D=useCallback(async()=>{if(!f)return;const e=await _(f.index+1,1);e?g(e):await k("finished")},[f,_,k]),C=useCallback(async()=>{if(!f)return;const e=await _(f.index-1,-1);e&&g(e)},[f,_]),M=useCallback(()=>{k("skipped")},[k]),R=f?t[f.index]:void 0,I=!!f&&f.index===t.length-1,A=c.space.xs,E=f?{x:f.rect.x-A,y:f.rect.y-A,width:f.rect.width+2*A,height:f.rect.height+2*A}:null,V=Math.min(d.width-2*p,360),B=E?(()=>{const e=E.x+E.width/2,t=Math.max(p,Math.min(e-V/2,d.width-V-p)),i=E.y,s=d.height-(E.y+E.height);return s>=i?{left:t,top:E.y+E.height+m,maxHeight:Math.max(s-m-p,0)}:{left:t,bottom:d.height-E.y+m,maxHeight:Math.max(i-m-p,0)}})():null,L=c.colors.scrim,W=E?Math.min(R?.radius?c.radius[R.radius]+A:c.radius.md,Math.min(E.width,E.height)/2):0,P=Math.max(d.width,d.height);return _jsx(Modal,{open:null!==f,onClose:M,presentation:"fullScreen",backdropPressClose:!1,backdropStyle:u.transparent,contentStyle:u.transparent,accessibilityLabel:R?.title??R?.description,haptic:o,testID:a,children:E&&B&&R?_jsxs(View,{style:StyleSheet.absoluteFill,children:[_jsx(View,{style:[u.dim,{borderColor:L,borderWidth:P,top:E.y-P,left:E.x-P,width:E.width+2*P,height:E.height+2*P,borderRadius:W+P}]}),_jsx(View,{pointerEvents:"none",style:[u.highlight,{top:E.y,left:E.x,width:E.width,height:E.height,borderRadius:W}]}),_jsxs(Animated.View,{accessibilityLiveRegion:"polite",style:[u.card,B,{width:V,opacity:y}],testID:a?`${a}-card`:void 0,children:[_jsx(Text,{variant:"caption",children:x.position((f?.index??0)+1,t.length)}),R.title?_jsx(Text,{variant:"title",accessibilityRole:"header",children:R.title}):null,_jsx(Text,{variant:"bodySmall",children:R.description}),_jsxs(View,{style:u.actions,children:[_jsx(Button,{label:x.skip,variant:"ghost",size:"sm",haptic:o,onPress:M,testID:a?`${a}-skip`:void 0}),_jsxs(View,{style:u.navigation,children:[f&&f.index>w?_jsx(Button,{label:x.back,variant:"outline",size:"sm",haptic:o,onPress:()=>{C()},testID:a?`${a}-back`:void 0}):null,_jsx(Button,{label:I?x.done:x.next,size:"sm",haptic:o,onPress:()=>{D()},testID:a?`${a}-next`:void 0})]})]})]})]}):null})};Tour.displayName="Tour";const buildStyles=e=>StyleSheet.create({transparent:{backgroundColor:"transparent"},dim:{position:"absolute"},highlight:{position:"absolute",borderWidth:2,borderColor:e.colors.primary,borderRadius:e.radius.md,...smoothCorners},card:{position:"absolute",backgroundColor:e.colors.surface,borderRadius:e.radius.lg,...smoothCorners,padding:e.space.lg,gap:e.space.sm,...e.shadow.popover},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginTop:e.space.xs},navigation:{flexDirection:"row",gap:e.space.sm}});export{Tour};export default Tour;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Fragment,memo,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Platform,Pressable,StyleSheet,TextInput,View}from"react-native";import{createAnimatedValue,setNativeValue}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const WHEEL_VISIBLE_ITEMS=5;export const WHEEL_CENTER_OFFSET=Math.floor(2.5);const HAPTIC_DEBOUNCE_MS=35,WEB_SETTLE_MS=120,SCALE_STOPS=[-2,-1,0,1,2],WheelRow=memo(({label:e,index:t,scrollY:n,itemHeight:a,selected:r,theme:i,reducedMotion:s,onPress:l,editor:c})=>{const{opacity:o,scale:u}=useMemo(()=>{const e=Animated.subtract(Animated.divide(n,a),t);return{opacity:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.3,.6,1,.6,.3],extrapolate:"clamp"}),scale:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.85,.95,1.05,.95,.85],extrapolate:"clamp"})}},[n,a,t]),m=_jsx(Text,{variant:"h3",weight:r?"semibold":"medium",color:r?"primary":"secondary",numberOfLines:1,maxFontSizeMultiplier:1.5,style:{letterSpacing:i["letter-spacing"].normal},children:e});return _jsx(Animated.View,{style:[styles.row,{height:a},s?{opacity:o}:{opacity:o,transform:[{scale:u}]}],accessible:!1,importantForAccessibility:"no",children:c??(l?_jsx(Pressable,{focusable:!1,accessible:!1,onPress:()=>l(t),style:styles.rowPress,children:m}):m)})});export const Wheel=({label:e,items:t,selectedIndex:n,onIndexChange:a,itemHeight:r,width:i,theme:s,haptic:l,disabled:c,reducedMotion:o,typeable:u,testID:m})=>{const d="web"===Platform.OS,[b,y]=useState(null),f=useRef(!1),h=useRef(null),p=useRef(createAnimatedValue(n*r)).current,x=useRef(n*r),g=useRef(n*r),S=useRef(n),v=useRef(0),E=useRef(null),T=useRef(()=>{}),w=t.length-1;useEffect(()=>{S.current=n;const e=n*r;if(g.current===e)return;if(g.current=e,Math.abs(x.current-e)<1)return;x.current=e,d||setNativeValue(p,e);const t=requestAnimationFrame(()=>{h.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[n,r,p,d]),useEffect(()=>{const e=x.current,t=requestAnimationFrame(()=>{h.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[]),useEffect(()=>()=>{E.current&&clearTimeout(E.current)},[]);const M=useCallback((e,r)=>{if(!(e===n||e<0||e>w)){if("accessibility"===r){const e=resolveHaptic(l,"denseTick");e&&triggerHaptic(e)}if("keyboard"!==r){const n=t[e];n&&announce(n.accessibilityLabel??n.label)}a(e)}},[n,w,t,l,a]),A=useCallback(()=>{!c&&u&&(f.current=!0,y(String(t[n]?.value??"")))},[c,u,t,n]),_=useCallback(e=>{if(!f.current)return;f.current=!1,y(null);const n=e.trim();if(!/^\d+$/.test(n))return;const a=Number(n),r=t.findIndex(e=>e.value===a);r>=0&&M(r,"keyboard")},[t,M]);T.current=()=>{E.current=null;const e=Math.max(0,Math.min(w,Math.round(x.current/r))),t=e*r;Math.abs(x.current-t)>=1&&h.current?.scrollTo({y:t,animated:!o}),M(e,"scroll")};const j=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:p}}}],{useNativeDriver:!d,listener:e=>{const t=e.nativeEvent.contentOffset.y;x.current=t;const n=Math.round(t/r);if(n!==S.current&&n>=0&&n<=w){const e=Date.now();if(e-v.current>=35){const t=resolveHaptic(l,"denseTick");t&&triggerHaptic(t),v.current=e}S.current=n}d&&(E.current&&clearTimeout(E.current),E.current=setTimeout(()=>T.current(),120))}}),[p,r,w,l,d]),C=useCallback(e=>{const t=e.nativeEvent.contentOffset.y;M(Math.max(0,Math.min(w,Math.round(t/r))),"scroll")},[M,w,r]),R=useCallback(e=>{if(c)return;const t=e.nativeEvent.actionName;"increment"===t?M(Math.min(w,n+1),"accessibility"):"decrement"===t&&M(Math.max(0,n-1),"accessibility")},[c,M,w,n]),F=useCallback(e=>{c||h.current?.scrollTo({y:e*r,animated:!o})},[c,r,o]),k=useCallback(({item:t,index:a})=>{const i=a===n,l=i&&null!==b;return _jsx(WheelRow,{label:t.label,index:a,scrollY:p,itemHeight:r,selected:i,theme:s,reducedMotion:o,onPress:i&&u?A:d?F:void 0,editor:l?_jsx(TextInput,{autoFocus:!0,selectTextOnFocus:!0,keyboardType:"number-pad",returnKeyType:"done",accessibilityLabel:e,value:b,onChangeText:y,onSubmitEditing:()=>_(b),onBlur:()=>_(b),style:{width:"100%",padding:s.space.none,textAlign:"center",fontSize:s.text.xl.size,color:s.colors["text-body"],fontWeight:s.weight.semibold,letterSpacing:s["letter-spacing"].normal}}):void 0})},[p,r,n,s,o,d,F,u,A,b,_,e]),I=useCallback((e,t)=>`${String(e.value)}-${t}`,[]),L=t[n]?t[n].accessibilityLabel??t[n].label:"",P=d?{focusable:!0,role:"spinbutton","aria-label":e,"aria-valuetext":L,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":w,"aria-disabled":c,onKeyDown:e=>{if(c)return;const t={ArrowDown:Math.min(w,n+1),PageDown:Math.min(w,n+1),ArrowUp:Math.max(0,n-1),PageUp:Math.max(0,n-1),Home:0,End:w}[e.key];void 0!==t&&(e.preventDefault
|
|
1
|
+
"use strict";import{Fragment,memo,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Platform,Pressable,StyleSheet,TextInput,View}from"react-native";import{createAnimatedValue,setNativeValue}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const WHEEL_VISIBLE_ITEMS=5;export const WHEEL_CENTER_OFFSET=Math.floor(2.5);const HAPTIC_DEBOUNCE_MS=35,WEB_SETTLE_MS=120,SCALE_STOPS=[-2,-1,0,1,2],WheelRow=memo(({label:e,index:t,scrollY:n,itemHeight:a,selected:r,theme:i,reducedMotion:s,onPress:l,editor:c})=>{const{opacity:o,scale:u}=useMemo(()=>{const e=Animated.subtract(Animated.divide(n,a),t);return{opacity:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.3,.6,1,.6,.3],extrapolate:"clamp"}),scale:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.85,.95,1.05,.95,.85],extrapolate:"clamp"})}},[n,a,t]),m=_jsx(Text,{variant:"h3",weight:r?"semibold":"medium",color:r?"primary":"secondary",numberOfLines:1,maxFontSizeMultiplier:1.5,style:{letterSpacing:i["letter-spacing"].normal},children:e});return _jsx(Animated.View,{style:[styles.row,{height:a},s?{opacity:o}:{opacity:o,transform:[{scale:u}]}],accessible:!1,importantForAccessibility:"no",children:c??(l?_jsx(Pressable,{focusable:!1,accessible:!1,onPress:()=>l(t),style:styles.rowPress,children:m}):m)})});export const Wheel=({label:e,items:t,selectedIndex:n,onIndexChange:a,itemHeight:r,width:i,theme:s,haptic:l,disabled:c,reducedMotion:o,typeable:u,testID:m})=>{const d="web"===Platform.OS,[b,y]=useState(null),f=useRef(!1),h=useRef(null),p=useRef(createAnimatedValue(n*r)).current,x=useRef(n*r),g=useRef(n*r),S=useRef(n),v=useRef(0),E=useRef(null),T=useRef(()=>{}),w=t.length-1;useEffect(()=>{S.current=n;const e=n*r;if(g.current===e)return;if(g.current=e,Math.abs(x.current-e)<1)return;x.current=e,d||setNativeValue(p,e);const t=requestAnimationFrame(()=>{h.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[n,r,p,d]),useEffect(()=>{const e=x.current,t=requestAnimationFrame(()=>{h.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[]),useEffect(()=>()=>{E.current&&clearTimeout(E.current)},[]);const M=useCallback((e,r)=>{if(!(e===n||e<0||e>w)){if("accessibility"===r){const e=resolveHaptic(l,"denseTick");e&&triggerHaptic(e)}if("keyboard"!==r){const n=t[e];n&&announce(n.accessibilityLabel??n.label)}a(e)}},[n,w,t,l,a]),A=useCallback(()=>{!c&&u&&(f.current=!0,y(String(t[n]?.value??"")))},[c,u,t,n]),_=useCallback(e=>{if(!f.current)return;f.current=!1,y(null);const n=e.trim();if(!/^\d+$/.test(n))return;const a=Number(n),r=t.findIndex(e=>e.value===a);r>=0&&M(r,"keyboard")},[t,M]);T.current=()=>{E.current=null;const e=Math.max(0,Math.min(w,Math.round(x.current/r))),t=e*r;Math.abs(x.current-t)>=1&&h.current?.scrollTo({y:t,animated:!o}),M(e,"scroll")};const j=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:p}}}],{useNativeDriver:!d,listener:e=>{const t=e.nativeEvent.contentOffset.y;x.current=t;const n=Math.round(t/r);if(n!==S.current&&n>=0&&n<=w){const e=Date.now();if(e-v.current>=35){const t=resolveHaptic(l,"denseTick");t&&triggerHaptic(t),v.current=e}S.current=n}d&&(E.current&&clearTimeout(E.current),E.current=setTimeout(()=>T.current(),120))}}),[p,r,w,l,d]),C=useCallback(e=>{const t=e.nativeEvent.contentOffset.y;M(Math.max(0,Math.min(w,Math.round(t/r))),"scroll")},[M,w,r]),R=useCallback(e=>{if(c)return;const t=e.nativeEvent.actionName;"increment"===t?M(Math.min(w,n+1),"accessibility"):"decrement"===t&&M(Math.max(0,n-1),"accessibility")},[c,M,w,n]),F=useCallback(e=>{c||h.current?.scrollTo({y:e*r,animated:!o})},[c,r,o]),k=useCallback(({item:t,index:a})=>{const i=a===n,l=i&&null!==b;return _jsx(WheelRow,{label:t.label,index:a,scrollY:p,itemHeight:r,selected:i,theme:s,reducedMotion:o,onPress:i&&u?A:d?F:void 0,editor:l?_jsx(TextInput,{autoFocus:!0,selectTextOnFocus:!0,keyboardType:"number-pad",returnKeyType:"done",accessibilityLabel:e,value:b,onChangeText:y,onSubmitEditing:()=>_(b),onBlur:()=>_(b),style:{width:"100%",padding:s.space.none,textAlign:"center",fontSize:s.text.xl.size,color:s.colors["text-body"],fontWeight:s.weight.semibold,letterSpacing:s["letter-spacing"].normal}}):void 0})},[p,r,n,s,o,d,F,u,A,b,_,e]),I=useCallback((e,t)=>`${String(e.value)}-${t}`,[]),L=t[n]?t[n].accessibilityLabel??t[n].label:"",P=d?{focusable:!0,role:"spinbutton","aria-label":e,"aria-valuetext":L,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":w,"aria-disabled":c,onKeyDown:e=>{if(c)return;const t={ArrowDown:Math.min(w,n+1),PageDown:Math.min(w,n+1),ArrowUp:Math.max(0,n-1),PageUp:Math.max(0,n-1),Home:0,End:w}[e.nativeEvent.key];void 0!==t&&(e.preventDefault(),M(t,"keyboard"))}}:void 0;return _jsxs(View,{style:[void 0===i?styles.columnFlex:{width:i},{height:5*r},styles.column,c?styles.disabled:null],testID:m,...P,children:[d?null:_jsx(View,{pointerEvents:"none",style:styles.a11yLayer,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:e,accessibilityValue:{text:L},accessibilityState:{disabled:Boolean(c)},"aria-disabled":Boolean(c),accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:R}),_jsx(Animated.ScrollView,{ref:h,showsVerticalScrollIndicator:!1,snapToInterval:r,snapToAlignment:"start",decelerationRate:"fast",bounces:!1,scrollEnabled:!c,nestedScrollEnabled:!0,scrollEventThrottle:16,onScroll:j,onMomentumScrollEnd:C,contentOffset:{x:0,y:n*r},contentContainerStyle:{paddingVertical:r*WHEEL_CENTER_OFFSET},style:[styles.list,{height:5*r}],importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:t.map((e,t)=>_jsx(Fragment,{children:k({item:e,index:t})},I(e,t)))})]})};const styles=StyleSheet.create({column:{overflow:"hidden"},columnFlex:{flex:1},disabled:{opacity:.5},list:{flexGrow:0},row:{alignItems:"center",justifyContent:"center"},rowPress:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",flex:1},a11yLayer:{...StyleSheet.absoluteFill,zIndex:2}});
|
package/lib/module/form/path.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const tokenize=t=>{const
|
|
1
|
+
"use strict";const tokenize=t=>{const r=[],o=/[^.[\]]+/g;for(const e of t.matchAll(o)){const t=e[0];r.push(/^\d+$/.test(t)?Number(t):t)}return r};export const getPath=(t,r)=>{const o=tokenize(r);let e=t;for(const t of o){if(null==e||"object"!=typeof e)return;e=e[t]}return e};export const setPath=(t,r,o)=>{const e=tokenize(r),n=e.pop();if(void 0===n)return t;const s=Array.isArray(t)?[...t]:{...t};let c=s,i=e.shift();for(const t of[...e,n]){if(void 0===i)break;const r=c[i],o=null!=r&&"object"==typeof r?Array.isArray(r)?[...r]:{...r}:"number"==typeof t?[]:{};c[i]=o,c=o,i=t}return c[n]=o,s};export const deletePath=(t,r)=>{const o=tokenize(r),e=o.pop();if(void 0===e)return t;const n=Array.isArray(t)?[...t]:{...t};let s=n;for(const t of o){const r=s[t];if(null==r||"object"!=typeof r)return n;const o=Array.isArray(r)?[...r]:{...r};s[t]=o,s=o}return Array.isArray(s)&&"number"==typeof e?s.splice(e,1):delete s[e],n};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useMemo,useRef}from"react";import{Animated,Easing}from"react-native";import{Gesture}from"react-native-gesture-handler";import{createAnimatedValue,setNativeValue,useTheme}from"../theme/index.js";import{usePresenceMotion}from"./usePresenceMotion.js";export const DRAG_DISMISS_DISTANCE=100;export const DRAG_DISMISS_VELOCITY=.5;export const createDragToDismissController=({drag:e,travel:t,onDismiss:
|
|
1
|
+
"use strict";import{useMemo,useRef}from"react";import{Animated,Easing}from"react-native";import{Gesture}from"react-native-gesture-handler";import{createAnimatedValue,setNativeValue,useTheme}from"../theme/index.js";import{nativeDriver}from"../utils/nativeDriver.js";import{usePresenceMotion}from"./usePresenceMotion.js";export const DRAG_DISMISS_DISTANCE=100;export const DRAG_DISMISS_VELOCITY=.5;export const createDragToDismissController=({drag:e,travel:t,onDismiss:r,opacity:a},i,s)=>{const{snappy:n}=i.spring,springBack=()=>Animated.spring(e,{toValue:0,damping:n.damping,stiffness:n.stiffness,mass:n.mass,useNativeDriver:nativeDriver}).start(),o=!0===s?.reduced?a:void 0,u=s?.duration("default")??i.duration.default;return{move:t=>{setNativeValue(e,Math.max(0,t))},release:(a,s)=>{if(a>100||s>.5){if(o)return void Animated.timing(o,{toValue:0,duration:u,easing:Easing.bezier(...i.ease.accelerate),useNativeDriver:nativeDriver}).start(()=>r());Animated.timing(e,{toValue:"function"==typeof t?t():t,duration:i.duration.fast,easing:Easing.bezier(...i.ease.accelerate),useNativeDriver:nativeDriver}).start(()=>r())}else springBack()},cancel:springBack}};export const useDragToDismiss=e=>{const{drag:t,travel:r,onDismiss:a,contentAtTop:i,scrollGesture:s}=e,{motion:n}=useTheme(),o=usePresenceMotion(),u=useRef(createAnimatedValue(1)).current;return useMemo(()=>{const e=createDragToDismissController({drag:t,travel:r,onDismiss:a,opacity:u},n,o),l=Gesture.Pan().runOnJS(!0).activeOffsetY(6).failOffsetX([-12,12]).onUpdate(t=>e.move(t.translationY)).onEnd(t=>e.release(t.translationY,t.velocityY/1e3)).onFinalize((_e,t)=>{t||e.cancel()});let c=0,m=!1;const v=Gesture.Pan().runOnJS(!0).activeOffsetY(8).failOffsetX([-12,12]).onBegin(()=>{c=0,m=!1}).onUpdate(t=>{if(!m){if(i&&!i())return;m=!0,c=t.translationY}e.move(t.translationY-c)}).onEnd(t=>{m&&e.release(t.translationY-c,t.velocityY/1e3)}).onFinalize((_e,t)=>{!t&&m&&e.cancel()});return s&&v.simultaneousWithExternalGesture(s),{handleGesture:l,sheetGesture:v,opacity:u}},[t,r,a,i,s,n,o,u])};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useMemo,useRef}from"react";import{Easing,Animated as RNAnimated}from"react-native";import{setNativeValue,useTheme}from"../theme/index.js";import{createAnimatedValue}from"../theme/animatedValue.js";import{usePresenceMotion}from"./usePresenceMotion.js";export const PRESS_ANIMATION_PRESETS=["scale","bounce","fade","sink","pulse","dim"];const FADE_TO=.6,DIM_TO=.7,SINK_BY=2,PULSE_TO=1.05,DEFAULT_SCALE_TO={scale:.97,bounce:.92,fade:1,sink:1,pulse:1,dim:1};export const usePressAnimation=({preset:e="scale",scaleTo:a,pressDuration:s,enabled:t=!0}={})=>{const i=useTheme(),
|
|
1
|
+
"use strict";import{useCallback,useMemo,useRef}from"react";import{Easing,Animated as RNAnimated}from"react-native";import{setNativeValue,useTheme}from"../theme/index.js";import{createAnimatedValue}from"../theme/animatedValue.js";import{nativeDriver}from"../utils/nativeDriver.js";import{usePresenceMotion}from"./usePresenceMotion.js";export const PRESS_ANIMATION_PRESETS=["scale","bounce","fade","sink","pulse","dim"];const FADE_TO=.6,DIM_TO=.7,SINK_BY=2,PULSE_TO=1.05,DEFAULT_SCALE_TO={scale:.97,bounce:.92,fade:1,sink:1,pulse:1,dim:1};export const usePressAnimation=({preset:e="scale",scaleTo:a,pressDuration:s,enabled:t=!0}={})=>{const i=useTheme(),r=usePresenceMotion(),n=useRef(createAnimatedValue(1)).current,o=useRef(createAnimatedValue(1)).current,u=useRef(createAnimatedValue(0)).current,c=r.reduced?"dim"===e?"dim":"fade":e,m=a??DEFAULT_SCALE_TO[c],l=s??r.duration("fast"),d=useCallback((e,a,s)=>RNAnimated.timing(e,{toValue:a,duration:l,easing:Easing.bezier(...s),useNativeDriver:nativeDriver}),[l]),p=useCallback((e,a,s)=>RNAnimated.spring(e,{toValue:a,damping:i.motion.spring[s].damping,stiffness:i.motion.spring[s].stiffness,mass:i.motion.spring[s].mass,useNativeDriver:nativeDriver}),[i]),f=useCallback(()=>{if(t)switch(c){case"scale":case"bounce":d(n,m,i.motion.ease["in-out"]).start();break;case"fade":d(o,.6,i.motion.ease["in-out"]).start();break;case"dim":setNativeValue(o,.7);break;case"sink":d(u,2,i.motion.ease["in-out"]).start()}},[t,c,m,n,o,u,i,d]),b=useCallback(()=>{if(t)switch(c){case"scale":p(n,1,"snappy").start();break;case"bounce":p(n,1,"bouncy").start();break;case"fade":d(o,1,i.motion.ease.decelerate).start();break;case"dim":setNativeValue(o,1);break;case"sink":p(u,0,"snappy").start()}},[t,c,n,o,u,i,d,p]),v=useCallback(()=>{t&&"pulse"===c&&RNAnimated.sequence([RNAnimated.timing(n,{toValue:1.05,duration:i.motion.duration.instant,easing:Easing.bezier(...i.motion.ease.accelerate),useNativeDriver:nativeDriver}),p(n,1,"snappy")]).start()},[t,c,n,i,p]),A=useMemo(()=>({transform:[{scale:n},{translateY:u}],opacity:o}),[n,u,o]);return{scale:n,opacity:o,translateY:u,style:A,pressIn:f,pressOut:b,press:v}};
|
package/lib/module/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";export{PHONE_CHROME_INSETS}from"./canvasKit/index.js";export{Accordion,AccordionGroup,ALL_CALLING_CODES,AmountSlider,AnimatePresence,AppBar,AppLockOverlay,AsyncBlock,AuthedImage,Autocomplete,Avatar,AvatarGroup,authedImageCacheStats,Badge,Banner,BarChart,BottomNavigation,BottomSheet,Box,Button,buttonLabelInk,Calendar,Card,Carousel,Checkbox,Chip,ChoiceGroup,Composer,Confetti,ConfirmHost,clearAuthedImageCache,confirm,DatePicker,DateRangePicker,DateSeparator,DEFAULT_CALLING_CODES,DecimalInput,Descriptions,Dialog,Divider,Drawer,defineStatusMap,EmptyState,ErrorBoundary,FilePicker,FileViewer,FilterChipRow,FloatingActionButton,FloatingActionButtonGroup,ForceUpdateDialog,FormField,formatE164,formatFileSize,getAuthedImageCacheLimit,IconBadge,IconButton,ImageGallery,InlineSelect,Input,KeyboardAwareScrollView,KeyboardToolbar,ListItem,ListSection,LoaderOverlay,loader,Markdown,Menu,MessageBubble,MessageList,MODAL_DISMISS_GRACE_MS,Modal,NumberInput,OnboardingPager,OptionSheet,OTPInput,OTPResendRow,PagedListFooter,PermissionPrompt,PhoneNumberInput,PickerTrigger,ProfileCompletion,ProfilePicker,ProgressBar,ProgressRing,Radio,RadioDot,RadioGroup,Rating,Repeater,RichTextEditor,Row,ScannerOverlay,Screen,SearchBar,SectionHeader,SegmentedControl,Select,SignaturePad,Skeleton,SkeletonCircle,SkeletonClockProvider,SkeletonContent,SkeletonList,SkeletonProvider,SkeletonSkip,SkeletonText,Slider,SliderField,SlideToConfirm,SortableList,Spacer,Sparkline,Spinner,SquircleImage,SquircleView,Stack,StatTile,StatusBadge,Stepper,Swipeable,Switch,setAuthedImageCacheLimit,Tabs,TagInput,Text,TextInkContext,Timeline,TimePicker,Toast,ToastHost,ToastProvider,Tooltip,Tour,TypingIndicator,toast,useBottomSheet,useErrorHandler,useRecentSearches,useTextInk,useToast,WheelPicker,withErrorBoundary,ZoomableImage}from"./components/index.js";export{AppIcon}from"./components/AppIcon/index.js";export{HookFormField,useHookFormField}from"./form/index.js";export{useDebounce,useFieldChain,useReducedMotion,useRefreshControl,useScrollDirection}from"./hooks/index.js";export{NetworkStatusBanner}from"./network/index.js";export{KitThemeBridge,lightTheme,makeStyles,radiusOf,ThemeProvider,useTheme,useThemeMode}from"./theme/index.js";export{announce,isHapticsEnabled,setHapticImplementation,setHapticsEnabled,triggerHaptic}from"./utils/index.js";
|
|
1
|
+
"use strict";export{PHONE_CHROME_INSETS}from"./canvasKit/index.js";export{Accordion,AccordionGroup,ALL_CALLING_CODES,AmountSlider,AnimatePresence,AppBar,AppLockOverlay,AsyncBlock,AuthedImage,Autocomplete,Avatar,AvatarGroup,authedImageCacheStats,Badge,Banner,BarChart,BottomNavigation,BottomSheet,Box,Button,buttonLabelInk,Calendar,Card,Carousel,Checkbox,Chip,ChoiceGroup,Composer,Confetti,ConfirmHost,clearAuthedImageCache,confirm,DatePicker,DateRangePicker,DateSeparator,DEFAULT_CALLING_CODES,DecimalInput,Descriptions,Dialog,Divider,Drawer,defineStatusMap,EmptyState,ErrorBoundary,FilePicker,FileViewer,FilterChipRow,FloatingActionButton,FloatingActionButtonGroup,ForceUpdateDialog,FormField,formatE164,formatFileSize,getAuthedImageCacheLimit,IconBadge,IconButton,ImageGallery,InlineSelect,Input,KeyboardAwareScrollView,KeyboardToolbar,ListItem,ListSection,LoaderOverlay,loader,Markdown,Menu,MessageBubble,MessageList,MODAL_DISMISS_GRACE_MS,Modal,NumberInput,OnboardingPager,OptionSheet,OTPInput,OTPResendRow,PagedListFooter,PermissionPrompt,PhoneNumberInput,PickerTrigger,ProfileCompletion,ProfilePicker,ProgressBar,ProgressRing,Radio,RadioDot,RadioGroup,Rating,Repeater,RichTextEditor,Row,ScannerOverlay,Screen,SearchBar,SectionHeader,SegmentedControl,Select,SignaturePad,Skeleton,SkeletonCircle,SkeletonClockProvider,SkeletonContent,SkeletonList,SkeletonProvider,SkeletonSkip,SkeletonText,Slider,SliderField,SlideToConfirm,SortableList,Spacer,Sparkline,Spinner,SquircleImage,SquircleView,Stack,StatTile,StatusBadge,Stepper,Swipeable,Switch,setAuthedImageCacheLimit,Tabs,TagInput,Text,TextInkContext,Timeline,TimePicker,Toast,ToastHost,ToastProvider,Tooltip,Tour,TypingIndicator,toast,useBottomSheet,useErrorHandler,useRecentSearches,useTextInk,useToast,WheelPicker,withErrorBoundary,ZoomableImage}from"./components/index.js";export{AppIcon}from"./components/AppIcon/index.js";export{HookFormField,useHookFormField}from"./form/index.js";export{useDebounce,useFieldChain,useReducedMotion,useRefreshControl,useScrollDirection}from"./hooks/index.js";export{NetworkStatusBanner}from"./network/index.js";export{fontFor,KitThemeBridge,lightTheme,makeStyles,radiusOf,ThemeProvider,useTheme,useThemeMode}from"./theme/index.js";export{announce,isHapticsEnabled,setHapticImplementation,setHapticsEnabled,triggerHaptic}from"./utils/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useNetworkStatus}from"@webority/mobile-core";import{useEffect,useMemo,useRef,useState}from"react";import{Animated,StyleSheet,Text}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../hooks/usePresenceMotion.js";import{fontFor,useTheme}from"../theme/index.js";import{jsx as _jsx}from"react/jsx-runtime";export const NetworkStatusBanner=({message:e="You are offline. Some features may be unavailable.",restoredMessage:t="You are back online.",restoredDuration:o=2e3,position:n="top",style:
|
|
1
|
+
"use strict";import{useNetworkStatus}from"@webority/mobile-core";import{useEffect,useMemo,useRef,useState}from"react";import{Animated,StyleSheet,Text}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../hooks/usePresenceMotion.js";import{fontFor,useTheme}from"../theme/index.js";import{nativeDriver}from"../utils/nativeDriver.js";import{jsx as _jsx}from"react/jsx-runtime";export const NetworkStatusBanner=({message:e="You are offline. Some features may be unavailable.",restoredMessage:t="You are back online.",restoredDuration:o=2e3,position:n="top",style:r,disabled:i=!1,safeArea:s=!0})=>{const a=useTheme(),u=usePresenceMotion(),l=useSafeAreaInsets(),d=s?"top"===n?l.top:l.bottom:0,[c,m]=useState(0),f=c>0?c:56+d,{isConnected:p,isInternetReachable:v}=useNetworkStatus(),b=!(i||p&&!1!==v),[g,h]=useState("hidden"),[S,x]=useState("offline");useEffect(()=>{"hidden"!==g&&x(g)},[g]),useEffect(()=>{h(b?"offline":i?"hidden":e=>"offline"===e?"restored":e)},[b,i]),useEffect(()=>{if("restored"!==g)return;const e=setTimeout(()=>h("hidden"),o);return()=>clearTimeout(e)},[g,o]);const y="hidden"!==g,A="restored"===g||"hidden"===g&&"restored"===S,j=useRef(new Animated.Value(0)).current,w=useRef(new Animated.Value(0)).current,R=u.duration("default");useEffect(()=>{Animated.parallel([Animated.timing(j,{toValue:y?1:0,duration:a.motion.duration.default,useNativeDriver:nativeDriver}),Animated.timing(w,{toValue:y?1:0,duration:R,useNativeDriver:nativeDriver})]).start()},[y,j,w,a.motion.duration.default,R]);const k=useMemo(()=>buildStyles(a),[a]),D=j.interpolate({inputRange:[0,1],outputRange:u.range("top"===n?-f:f,0)});return _jsx(Animated.View,{pointerEvents:y?"auto":"none",accessibilityRole:"alert",accessibilityLiveRegion:y?"polite":"none",onLayout:e=>m(e.nativeEvent.layout.height),style:[k.container,"top"===n?k.top:k.bottom,"top"===n?{paddingTop:a.space.sm+d}:{paddingBottom:a.space.sm+d},{backgroundColor:A?a.colors["online-fill"]:a.colors["offline-fill"],opacity:w,transform:[{translateY:D}]},r],children:_jsx(Text,{style:{color:A?a.colors["on-success"]:a.colors["on-danger"],fontSize:a.text.sm.size,...fontFor(a,"semibold"),textAlign:"center"},numberOfLines:2,children:A?t:e})})};const buildStyles=e=>StyleSheet.create({container:{position:"absolute",left:0,right:0,paddingVertical:e.space.sm,paddingHorizontal:e.space.lg,zIndex:1e3,elevation:8},top:{top:0},bottom:{bottom:0}});export default NetworkStatusBanner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{View}from"react-native";import{jsx as _jsx}from"react/jsx-runtime";const DEFAULT_START={x:.5,y:0},DEFAULT_END={x:.5,y:1},round=t=>Math.round(1e3*t)/1e3;export const gradientAngle=(t=DEFAULT_START,
|
|
1
|
+
"use strict";import{View}from"react-native";import{jsx as _jsx}from"react/jsx-runtime";const DEFAULT_START={x:.5,y:0},DEFAULT_END={x:.5,y:1},round=t=>Math.round(1e3*t)/1e3;export const gradientAngle=(t=DEFAULT_START,r=DEFAULT_END)=>{const e=180*Math.atan2(r.x-t.x,t.y-r.y)/Math.PI;return round((e%360+360)%360)};export const toBackgroundImage=t=>{const r=t.colors.length-1;return{type:"linear-gradient",direction:`${gradientAngle(t.start,t.end)}deg`,colorStops:t.colors.map((e,o)=>{const n=t.locations?.[o]??(0===r?0:o/r);return{color:e,positions:[`${round(100*n)}%`]}})}};export const Gradient=({gradient:t,style:r,children:e})=>_jsx(View,{style:[{experimental_backgroundImage:[toBackgroundImage(t)]},r],children:e});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Animated,Platform}from"react-native";export const createAnimatedValue=(t,e)=>{const
|
|
1
|
+
"use strict";import{Animated,Platform}from"react-native";import{nativeDriver}from"../utils/nativeDriver.js";export const createAnimatedValue=(t,e)=>{const r=new Animated.Value(t,e);return"web"===Platform.OS?r:(r._tracking=null,Object.seal(r))};export const setNativeValue=(t,e)=>{Animated.timing(t,{toValue:e,duration:0,useNativeDriver:nativeDriver}).start()};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{scaleStep}from"./scale.js";import{COMPONENT_KINDS}from"./tokens.generated.js";const SIZE_KEYS=["xs","sm","md","lg","xl"],kindOf=(e,o,t)=>{const s=COMPONENT_KINDS[e][o];if(!s)throw new Error(`components.${e}${t?`.${t}`:""}.${o} has no kind in COMPONENT_KINDS.`);return s},pixelsOf=(e,o,t,s)=>{if("space"===o||"text"===o||"radius"===o)return scaleStep(e,o,String(t),s);if("number"!=typeof t)throw new Error(`${s} is ${JSON.stringify(t)}; it takes a number.`);return t},resolveSize=(e,o,t)=>{const s=e.components[o][t]
|
|
1
|
+
"use strict";import{scaleStep}from"./scale.js";import{COMPONENT_KINDS}from"./tokens.generated.js";const SIZE_KEYS=["xs","sm","md","lg","xl"],kindOf=(e,o,t)=>{const s=COMPONENT_KINDS[e][o];if(!s)throw new Error(`components.${e}${t?`.${t}`:""}.${o} has no kind in COMPONENT_KINDS.`);return s},pixelsOf=(e,o,t,s)=>{if("space"===o||"text"===o||"radius"===o)return scaleStep(e,o,String(t),s);if("number"!=typeof t)throw new Error(`${s} is ${JSON.stringify(t)}; it takes a number.`);return t},resolveSize=(e,o,t)=>{const s=e.components[o][t];if(void 0===s)throw new Error(`components.${o} has no "${t}" size in the theme.`);const r={};for(const i of Object.keys(s))r[i]=pixelsOf(e,kindOf(o,i,t),s[i],`components.${o}.${t}.${i}`);return r};export const resolveButtonSize=(e,o)=>resolveSize(e,"button",o);export const resolveFieldSize=(e,o)=>resolveSize(e,"field",o);export const resolveEmptyStateSize=(e,o)=>resolveSize(e,"empty-state",o);export const resolveListItemSize=(e,o)=>resolveSize(e,"list-item",o);export const resolveBadgeSize=(e,o)=>resolveSize(e,"badge",o);export const resolveChipSize=(e,o)=>resolveSize(e,"chip",o);export const resolveCheckboxSize=(e,o)=>resolveSize(e,"checkbox",o);export const resolveRadioSize=(e,o)=>resolveSize(e,"radio",o);export const resolveSwitchSize=(e,o)=>resolveSize(e,"switch",o);export const resolveOtpInputSize=(e,o)=>resolveSize(e,"otp-input",o);export const resolveSegmentedControlSize=(e,o)=>resolveSize(e,"segmented-control",o);export const resolveTabsSize=(e,o)=>resolveSize(e,"tabs",o);export const resolveSliderSize=(e,o)=>resolveSize(e,"slider",o);export const resolveFloatingActionButtonSize=(e,o)=>resolveSize(e,"floating-action-button",o);export const validateComponentTokens=e=>{for(const o of Object.keys(COMPONENT_KINDS)){const t=e.components[o];for(const s of Object.keys(t))SIZE_KEYS.includes(s)?resolveSize(e,o,s):pixelsOf(e,kindOf(o,s),t[s],`components.${o}.${s}`)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{validateComponentTokens}from"./componentSizes.js";import{COLOR_NAMES,FONT_NAMES,RADIUS_NAMES,WEIGHT_NAMES}from"./tokens.generated.js";import{deriveSolidFill,deriveStateFills,deriveToneInk}from"./toneInk.js";const HINT="Run webority upgrade to rename old names.",BRAND_KEYS=["colors","radius","font"],COLOR_MODES=["light","dark"],FIXED_RADII=["none","pill"],RADIUS_ALLOWED="sm, md, lg, xl",SETTINGS_KEYS=["icons","gradients","textVariants","maxFontSizeMultiplier","components"],COMPONENT_SETTING_KEYS={field:{defaultVariant:!0,requiredMarker:!0},input:{defaultVariant:!0,defaultLabelMode:!0,tintLabelOnFocus:!0,shakeOnError:!0},"search-bar":{defaultVariant:!0},select:{defaultVariant:!0},"otp-input":{shakeOnError:!0},"option-sheet":{selectedMarker:!0},"profile-picker":{defaultTone:!0,defaultVariant:!0,defaultAvatarTone:!0},slider:{thumbPressAnimation:!0},rating:{pulseOnPress:!0},stepper:{pulseAnimation:!0},tooltip:{enableScaleAnimation:!0},toast:{enableSwipeDismiss:!0,defaultDurationMs:!0},button:{defaultVariant:!0,defaultSize:!0,defaultPressAnimation:!0},card:{defaultVariant:!0,defaultPadding:!0,defaultRadius:!0,defaultTitleFont:!0},"section-header":{defaultVariant:!0,defaultFlush:!0},"empty-state":{defaultSize:!0,defaultVariant:!0},screen:{tabBarFloats:!0,headerShadowOnScroll:!0}},isPlainObject=
|
|
1
|
+
"use strict";import{validateComponentTokens}from"./componentSizes.js";import{COLOR_NAMES,FONT_NAMES,RADIUS_NAMES,WEIGHT_NAMES}from"./tokens.generated.js";import{deriveSolidFill,deriveStateFills,deriveToneInk}from"./toneInk.js";const HINT="Run webority upgrade to rename old names.",BRAND_KEYS=["colors","radius","font"],COLOR_MODES=["light","dark"],FIXED_RADII=["none","pill"],RADIUS_ALLOWED="sm, md, lg, xl",SETTINGS_KEYS=["icons","gradients","textVariants","maxFontSizeMultiplier","components"],COMPONENT_SETTING_KEYS={field:{defaultVariant:!0,requiredMarker:!0},input:{defaultVariant:!0,defaultLabelMode:!0,tintLabelOnFocus:!0,shakeOnError:!0},"search-bar":{defaultVariant:!0},select:{defaultVariant:!0},"otp-input":{shakeOnError:!0},"option-sheet":{selectedMarker:!0},"profile-picker":{defaultTone:!0,defaultVariant:!0,defaultAvatarTone:!0},slider:{thumbPressAnimation:!0},rating:{pulseOnPress:!0},stepper:{pulseAnimation:!0},tooltip:{enableScaleAnimation:!0},toast:{enableSwipeDismiss:!0,defaultDurationMs:!0},button:{defaultVariant:!0,defaultSize:!0,defaultPressAnimation:!0},card:{defaultVariant:!0,defaultPadding:!0,defaultRadius:!0,defaultTitleFont:!0},"section-header":{defaultVariant:!0,defaultFlush:!0},"empty-state":{defaultSize:!0,defaultVariant:!0},screen:{tabBarFloats:!0,headerShadowOnScroll:!0}},isPlainObject=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),validateBrand=e=>{if(void 0===e)return;if(!isPlainObject(e))throw new Error(`A brand is an object of colors, radius and font; got ${typeof e}. ${HINT}`);for(const o of Object.keys(e))if(!BRAND_KEYS.includes(o))throw new Error(`A brand sets colors, radius and font only; ${o} is not allowed (allowed: colors, radius, font). ${HINT}`);const o=e.colors;if(void 0!==o&&!isPlainObject(o))throw new Error(`A brand's colors is an object of light and dark; got ${typeof o}. ${HINT}`);for(const e of Object.keys(o??{})){if(!COLOR_MODES.includes(e))throw new Error(`A brand sets colours under light and dark only; ${e} is not allowed (allowed: light, dark). ${HINT}`);const t=o[e];if(void 0===t)throw new Error(`A brand's ${e} colours are missing. ${HINT}`);for(const e of Object.keys(t)){if(!COLOR_NAMES.includes(e))throw new Error(`unknown colour ${e}; allowed: ${COLOR_NAMES.join(", ")}. ${HINT}`);if(void 0!==t[e]&&"string"!=typeof t[e])throw new Error(`colour ${e} must be a string; got ${typeof t[e]}.`)}}const t=e.radius;if(void 0!==t&&!isPlainObject(t))throw new Error(`A brand's radius is an object of radius names; got ${typeof t}. ${HINT}`);for(const e of Object.keys(t??{})){const o=t[e];if(!RADIUS_NAMES.includes(e))throw new Error(`unknown radius ${e}; allowed: ${RADIUS_ALLOWED}. ${HINT}`);if(FIXED_RADII.includes(e))throw new Error(`radius ${e} is fixed by the library; allowed: ${RADIUS_ALLOWED}.`);if("number"!=typeof o||!Number.isFinite(o))throw new Error(`radius ${e} must be a number; got ${typeof o}.`)}const n=e.font;if(void 0!==n&&!isPlainObject(n))throw new Error(`A brand's font is an object of font names; got ${typeof n}. ${HINT}`);for(const e of Object.keys(n??{})){if(!FONT_NAMES.includes(e))throw new Error(`unknown font ${e}; allowed: ${FONT_NAMES.join(", ")}. ${HINT}`);const o=n[e];if(!isPlainObject(o))throw new Error(`font ${e} must be an object of weights; got ${typeof o}. ${HINT}`);for(const t of Object.keys(o)){if(!WEIGHT_NAMES.includes(t))throw new Error(`unknown font weight ${t} in font ${e}; allowed: ${WEIGHT_NAMES.join(", ")}. ${HINT}`);const n=o[t];if("string"!=typeof n||0===n.length)throw new Error(`font ${e} weight ${t} must be a non-empty string.`)}}},validateSettings=e=>{if(void 0===e)return;if(!isPlainObject(e))throw new Error(`Theme settings is an object; got ${typeof e}. ${HINT}`);for(const o of Object.keys(e))if(!SETTINGS_KEYS.includes(o))throw new Error(`Theme settings take ${SETTINGS_KEYS.join(", ")} only; ${o} is not allowed. ${HINT}`);const o=e.components;if(void 0===o)return;if(!isPlainObject(o))throw new Error(`Theme settings components is an object of component names; got ${typeof o}. ${HINT}`);const t=COMPONENT_SETTING_KEYS;for(const e of Object.keys(o)){if(!Object.keys(t).includes(e))throw new Error(`unknown component ${e} in theme settings; allowed: ${Object.keys(COMPONENT_SETTING_KEYS).join(", ")}. ${HINT}`);const n=o[e];if(void 0===n)continue;if(!isPlainObject(n))throw new Error(`theme settings for ${e} is an object; got ${typeof n}. ${HINT}`);const r=t[e];if(void 0===r)throw new Error(`theme settings for ${e} have no allowed keys table. ${HINT}`);for(const o of Object.keys(n))if(!(o in r))throw new Error(`unknown setting ${o} for ${e}; allowed: ${Object.keys(r).join(", ")}. ${HINT}`)}},TONES=["primary","success","warning","danger","info"];export const mergeBrand=(e,o,t)=>{validateBrand(o),validateSettings(t);const n=Object.fromEntries(Object.entries(o?.colors?.[e.mode]??{}).filter(([,e])=>void 0!==e)),r={...e.colors,...n},colorOf=e=>{const o=r[e];if(void 0===o)throw new Error(`The theme has no colour ${e}.`);return o},i={...e.radius,...o?.radius},s={...e.font};for(const t of Object.keys(o?.font??{}))s[t]={...e.font[t],...o?.font?.[t]};const a=[colorOf("bg"),colorOf("bg-subtle"),colorOf("bg-muted")],l={};for(const o of TONES){const t="string"==typeof n[o];let r=colorOf(o);if(t||"string"==typeof n[`on-${o}`]){const e=deriveSolidFill(r,colorOf(`on-${o}`));e!==r&&(l[o]=e,r=e)}if(t&&"string"!=typeof n[`${o}-text`]&&(l[`${o}-text`]=deriveToneInk(r,a,e.mode)),"primary"===o&&(t||void 0!==l.primary)){const o=deriveStateFills(r,colorOf("on-primary"),{fill:e.colors.primary,hover:e.colors["primary-hover"],pressed:e.colors["primary-pressed"]});"string"!=typeof n["primary-hover"]&&(l["primary-hover"]=o.hover),"string"!=typeof n["primary-pressed"]&&(l["primary-pressed"]=o.pressed)}}const d={},f=new Set([...Object.keys(e.settings.components),...Object.keys(t?.components??{})]);for(const o of f)d[o]={...e.settings.components[o],...t?.components?.[o]};const c=t?.maxFontSizeMultiplier??e.settings.maxFontSizeMultiplier,u={icons:{...e.settings.icons,...t?.icons},gradients:{...e.settings.gradients,...t?.gradients},textVariants:{...e.settings.textVariants,...t?.textVariants},components:d,...void 0===c?{}:{maxFontSizeMultiplier:c}},w={...e,colors:{...r,...l},radius:i,font:s,settings:u};return validateComponentTokens(w),w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{blendOf}from"../utils/color.js";const HEX=/^#([0-9a-f]{6})$/i,TARGET=4.55,TINT_OPACITY=.14,STEP=.0025,channelsOf=t=>{const e=Number.parseInt(t.slice(1,7),16);return[e>>16&255,e>>8&255,255&e]},
|
|
1
|
+
"use strict";import{blendOf}from"../utils/color.js";const HEX=/^#([0-9a-f]{6})$/i,TARGET=4.55,TINT_OPACITY=.14,STEP=.0025,channelsOf=t=>{const e=Number.parseInt(t.slice(1,7),16);return[e>>16&255,e>>8&255,255&e]},linearOf=t=>{const e=t/255;return e<=.03928?e/12.92:((e+.055)/1.055)**2.4},luminance=t=>{const[e,n,r]=channelsOf(t);return.2126*linearOf(e)+.7152*linearOf(n)+.0722*linearOf(r)};export const contrastRatio=(t,e)=>{const n=luminance(t),r=luminance(e);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)};const toHsl=t=>{const[e,n,r]=channelsOf(t),s=e/255,o=n/255,a=r/255,l=Math.max(s,o,a),i=Math.min(s,o,a),c=l-i,u=(l+i)/2;if(0===c)return[0,0,u];return[60*(l===s?((o-a)/c+6)%6:l===o?(a-s)/c+2:(s-o)/c+4),u>.5?c/(2-l-i):c/(l+i),u]},fromHsl=([t,e,n])=>{const r=e*Math.min(n,1-n),channel=e=>{const s=(e+t/30)%12,o=n-r*Math.max(-1,Math.min(s-3,9-s,1));return Math.round(255*o).toString(16).padStart(2,"0")};return`#${channel(0)}${channel(8)}${channel(4)}`.toUpperCase()},moveUntil=(t,e,n)=>{const[r,s,o]=toHsl(t);let a=t;for(let t=o+e*STEP;t>=0&&t<=1;t+=e*STEP)if(a=fromHsl([r,s,t]),n(a))return a;return a};export const deriveToneInk=(t,e,n)=>{if(!HEX.test(t))return t;const r=e.filter(t=>HEX.test(t));if(0===r.length)return t;const s=r.flatMap(e=>[e,blendOf(t,.14,e,e)]),reads=t=>s.every(e=>contrastRatio(t,e)>=4.55);return reads(t)?t:moveUntil(t,"dark"===n?1:-1,reads)};export const deriveSolidFill=(t,e)=>{if(!HEX.test(t)||!HEX.test(e))return t;const reads=t=>contrastRatio(t,e)>=4.55;return reads(t)?t:moveUntil(t,luminance(e)>luminance(t)?-1:1,reads)};export const deriveStateFills=(t,e,n)=>{if(![t,e,n.fill,n.hover,n.pressed].every(t=>HEX.test(t)))return{hover:n.hover,pressed:n.pressed};const[r,s,o]=toHsl(t),a=toHsl(n.fill)[2],l=[Math.abs(toHsl(n.hover)[2]-a),Math.abs(toHsl(n.pressed)[2]-a)],i=luminance(e)>luminance(t)?-1:1,c=(t=>l.every(e=>o+t*e>=0&&o+t*e<=1))(i)?i:1===i?-1:1,at=t=>fromHsl([r,s,Math.max(0,Math.min(1,o+c*t))]);return{hover:at(l[0]),pressed:at(l[1])}};
|