@webority/mobile-ui 0.146.1 → 0.147.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.
Files changed (126) hide show
  1. package/dist/canvas-kit/kit.js +4344 -4214
  2. package/dist/canvas-kit/manifest.json +1 -1
  3. package/dist/canvas-kit/release.json +5 -5
  4. package/lib/commonjs/components/AuthedImage/authedImageCache.js +1 -1
  5. package/lib/commonjs/components/Avatar/Avatar.js +1 -1
  6. package/lib/commonjs/components/Badge/Badge.js +1 -1
  7. package/lib/commonjs/components/Banner/Banner.js +1 -1
  8. package/lib/commonjs/components/BarChart/BarChart.js +1 -1
  9. package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
  10. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  11. package/lib/commonjs/components/Button/Button.js +1 -1
  12. package/lib/commonjs/components/Calendar/Calendar.js +1 -1
  13. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  14. package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
  15. package/lib/commonjs/components/Confetti/Confetti.js +1 -1
  16. package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
  17. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  18. package/lib/commonjs/components/FieldBase/Chevron.js +1 -1
  19. package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
  20. package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
  21. package/lib/commonjs/components/FormField/FormField.js +1 -1
  22. package/lib/commonjs/components/Input/Input.js +1 -1
  23. package/lib/commonjs/components/LoaderOverlay/LoaderOverlay.js +1 -1
  24. package/lib/commonjs/components/Menu/MenuSurface.js +1 -1
  25. package/lib/commonjs/components/MessageList/MessageList.js +1 -1
  26. package/lib/commonjs/components/Modal/Modal.js +1 -1
  27. package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
  28. package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
  29. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  30. package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
  31. package/lib/commonjs/components/Radio/RadioDot.js +1 -1
  32. package/lib/commonjs/components/Rating/Rating.js +1 -1
  33. package/lib/commonjs/components/RichTextEditor/markdownActions.js +1 -1
  34. package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
  35. package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
  36. package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
  37. package/lib/commonjs/components/SignaturePad/signatureGeometry.js +1 -1
  38. package/lib/commonjs/components/Skeleton/SkeletonClock.js +1 -1
  39. package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
  40. package/lib/commonjs/components/Slider/valueText.js +1 -1
  41. package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
  42. package/lib/commonjs/components/Sparkline/geometry.js +1 -1
  43. package/lib/commonjs/components/Spinner/Spinner.js +1 -1
  44. package/lib/commonjs/components/Stepper/Stepper.js +1 -1
  45. package/lib/commonjs/components/Switch/Switch.js +1 -1
  46. package/lib/commonjs/components/Tabs/Tabs.js +1 -1
  47. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  48. package/lib/commonjs/components/Text/Text.js +1 -1
  49. package/lib/commonjs/components/Toast/Toast.js +1 -1
  50. package/lib/commonjs/components/Toast/ToastProvider.js +1 -1
  51. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  52. package/lib/commonjs/components/Tour/Tour.js +1 -1
  53. package/lib/commonjs/form/path.js +1 -1
  54. package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
  55. package/lib/commonjs/hooks/usePressAnimation.js +1 -1
  56. package/lib/commonjs/network/NetworkStatusBanner.js +1 -1
  57. package/lib/commonjs/theme/animatedValue.js +1 -1
  58. package/lib/commonjs/theme/componentSizes.js +1 -1
  59. package/lib/commonjs/theme/merge.js +1 -1
  60. package/lib/commonjs/theme/toneInk.js +1 -1
  61. package/lib/commonjs/utils/color.js +1 -1
  62. package/lib/commonjs/utils/nativeDriver.js +1 -0
  63. package/lib/module/components/AuthedImage/authedImageCache.js +1 -1
  64. package/lib/module/components/Avatar/Avatar.js +1 -1
  65. package/lib/module/components/Badge/Badge.js +1 -1
  66. package/lib/module/components/Banner/Banner.js +1 -1
  67. package/lib/module/components/BarChart/BarChart.js +1 -1
  68. package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
  69. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  70. package/lib/module/components/Button/Button.js +1 -1
  71. package/lib/module/components/Calendar/Calendar.js +1 -1
  72. package/lib/module/components/Carousel/Carousel.js +1 -1
  73. package/lib/module/components/Checkbox/Checkbox.js +1 -1
  74. package/lib/module/components/Confetti/Confetti.js +1 -1
  75. package/lib/module/components/DatePicker/DatePicker.js +1 -1
  76. package/lib/module/components/Drawer/Drawer.js +1 -1
  77. package/lib/module/components/FieldBase/Chevron.js +1 -1
  78. package/lib/module/components/FilePicker/FilePicker.js +1 -1
  79. package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
  80. package/lib/module/components/FormField/FormField.js +1 -1
  81. package/lib/module/components/Input/Input.js +1 -1
  82. package/lib/module/components/LoaderOverlay/LoaderOverlay.js +1 -1
  83. package/lib/module/components/Menu/MenuSurface.js +1 -1
  84. package/lib/module/components/MessageList/MessageList.js +1 -1
  85. package/lib/module/components/Modal/Modal.js +1 -1
  86. package/lib/module/components/OTPInput/OTPInput.js +1 -1
  87. package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
  88. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  89. package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
  90. package/lib/module/components/Radio/RadioDot.js +1 -1
  91. package/lib/module/components/Rating/Rating.js +1 -1
  92. package/lib/module/components/RichTextEditor/markdownActions.js +1 -1
  93. package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
  94. package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
  95. package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
  96. package/lib/module/components/SignaturePad/signatureGeometry.js +1 -1
  97. package/lib/module/components/Skeleton/SkeletonClock.js +1 -1
  98. package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
  99. package/lib/module/components/Slider/valueText.js +1 -1
  100. package/lib/module/components/Sparkline/Sparkline.js +1 -1
  101. package/lib/module/components/Sparkline/geometry.js +1 -1
  102. package/lib/module/components/Spinner/Spinner.js +1 -1
  103. package/lib/module/components/Stepper/Stepper.js +1 -1
  104. package/lib/module/components/Switch/Switch.js +1 -1
  105. package/lib/module/components/Tabs/Tabs.js +1 -1
  106. package/lib/module/components/TagInput/TagInput.js +1 -1
  107. package/lib/module/components/Text/Text.js +1 -1
  108. package/lib/module/components/Toast/Toast.js +1 -1
  109. package/lib/module/components/Toast/ToastProvider.js +1 -1
  110. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  111. package/lib/module/components/Tour/Tour.js +1 -1
  112. package/lib/module/form/path.js +1 -1
  113. package/lib/module/hooks/useDragToDismiss.js +1 -1
  114. package/lib/module/hooks/usePressAnimation.js +1 -1
  115. package/lib/module/network/NetworkStatusBanner.js +1 -1
  116. package/lib/module/theme/animatedValue.js +1 -1
  117. package/lib/module/theme/componentSizes.js +1 -1
  118. package/lib/module/theme/merge.js +1 -1
  119. package/lib/module/theme/toneInk.js +1 -1
  120. package/lib/module/utils/color.js +1 -1
  121. package/lib/module/utils/nativeDriver.js +1 -0
  122. package/lib/typescript/commonjs/theme/animatedValue.d.ts +1 -1
  123. package/lib/typescript/commonjs/utils/nativeDriver.d.ts +2 -0
  124. package/lib/typescript/module/theme/animatedValue.d.ts +1 -1
  125. package/lib/typescript/module/utils/nativeDriver.d.ts +2 -0
  126. package/package.json +7 -7
@@ -1 +1 @@
1
- "use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Dimensions,Keyboard,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{ACTIONS_LAYOUTS,OverlayActions}from"../Dialog/OverlayActions.js";import{Modal}from"../Modal/Modal.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"});const DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=e=>{const{snapPoints:t=DEFAULT_SNAP_POINTS,open:o,onClose:s,snapIndex:n,onSnapChange:r,onAnimate:a,onAfterClose:l,enablePanDownToClose:i=!0,enableBackdropPress:u=!0,onBeforeClose:c,title:d,labels:h,scrollable:m=!1,scrollRef:f,onScroll:S,onContentSizeChange:b,onScrollLayout:p,scrollEventThrottle:y,keyboardBehavior:v="shift",inline:g=!1,presentation:w="sheet",animateMount:C=!0,handleIndicatorStyle:x,containerStyle:_,header:M,actions:E,actionsLayout:O="auto",footer:T,headerStyle:k,footerStyle:R,children:A,accessibilityLabel:I,accessibilityViewIsModal:j,testID:V}=e;assertValidValue("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),assertValidValue("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),assertValidValue("BottomSheet","actionsLayout",e.actionsLayout,ACTIONS_LAYOUTS);const D=useMemo(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,...h}),[h]),B=null!=M||null!=d,L=null!=E&&E.length>0,P=null!=T||L,N=g?"inline":"modal",H=useTheme(),G=usePresenceMotion(),F=useSafeAreaInsets(),[U,J]=useState(()=>Dimensions.get("window").height),[z,Y]=useState(()=>Dimensions.get("window").width),K=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&J(e=>e===t?e:t),o>0&&Y(e=>e===o?e:o)},[]),$=useWindowDimensions(),W="dialog"===w||"auto"===w&&Math.min($.width,$.height)>=600,X=Math.min(560,z-2*H.space.xl),[q,Q]=useModalInsets(),Z="modal"===N?q.top:F.top,ee="modal"===N?q.bottom:F.bottom,te=t.includes("content"),[oe,se]=useMeasuredHeight(),[ne,re]=useMeasuredHeight(),[ae,le,ie]=useMeasuredHeight(),[ue,ce]=useMeasuredHeight(),de=W?H.space.md:oe,he=te?Math.min(de+(B?ne:0)+ae+(P?ue:0)+ee,U-Z):0,me=useCallback((e,t)=>{te&&ie(t),b?.(e,t)},[te,b,ie]),fe=useMemo(()=>resolveSnapPoints(t,U,he),[t,U,he]),Se=U,be=fe[fe.length-1]??0,pe=useSharedValue(Se),ye=useSharedValue(Se),ve=useSharedValue(1),ge=useSharedValue(-1),[we,Ce]=useState(-1),xe=useRef(!1),[Me,Ee]=useState(!1),[Oe,Te]=useState(!1),ke=useRef(!1),Re=useRef(l);Re.current=l;const[Ae,Ie]=useState(!1),je=useRef(!C&&o),Ve=useRef(-1),De=useRef(!1);De.current="modal"===N?Oe:Ae;const Be=useRef(c);Be.current=c;const Le=useRef(s);Le.current=s;const Pe=useRef(!1),Ne=useRef(!0),He=useRef([]),Ge=useCallback(e=>{const t=He.current;He.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,Ge(!1)}),[Ge]);const Fe=useCallback(e=>{if(e<0||e>=fe.length)return Se;const t=fe[e];return W?(U-t)/2:U-t},[fe,U,Se,W]),Ue=useCallback(e=>{Ve.current=e;we!==e&&(Ce(e),ge.value=e,e>=0&&r?.(e))},[we,ge,r]),Je=useCallback(()=>{xe.current=!1,ge.value<0&&(ke.current=!0,"modal"===N?(Ee(!1),"ios"!==Platform.OS&&Te(!1)):Ie(!1))},[N,ge]),ze=useCallback(()=>{ke.current&&Te(!1)},[]);useEffect(()=>{("modal"===N?!Oe:!Ae)&&ke.current&&(ke.current=!1,Re.current?.(),Ge(!0))},[N,Oe,Ae,Ge]);const Ye=useCallback((e,t,o)=>{xe.current=!0,a?.(t,o),pe.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(Je)()})},[a,pe,Je]),Ke=useCallback(e=>{const t="number"==typeof e?clamp(e,0,fe.length-1):we>=0?we:0,o=ge.value,s=Fe(t);return ke.current=!1,Ge(!1),"modal"===N?(Te(!0),Ee(!0)):Ie(!0),o<0&&je.current?(pe.value=s,ve.value=1,Ue(t),void a?.(o,t)):o<0&&G.reduced?(pe.value=s,ve.value=0,ve.value=withTiming(1,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Ue(t),void a?.(o,t)):(o<0&&(pe.value=Se,ve.value=1),Ue(t),void Ye(s,o,t))},[Ye,Se,we,ge,N,a,G,ve,fe.length,Ue,Ge,H.motion.ease.decelerate,pe,Fe]),$e=useCallback(()=>new Promise(e=>{if(Ve.current<0)return void(De.current?He.current.push(e):e(!0));He.current.push(e),je.current=!1;const t=ge.value;Ue(-1),xe.current=!0,a?.(t,-1);const o=G.reduced?ve:pe,s=G.reduced?0:Se;o.value=withTiming(s,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(Je)()})}),[Se,ge,Je,a,G,ve,Ue,pe,H.motion.ease.accelerate]),We=useCallback((e,t,o)=>{const s=Be.current;if(!s)return void e();if(Pe.current)return void t?.();const n=s();"boolean"!=typeof n?(Pe.current=!0,o?.(),n.then(o=>{Pe.current=!1,o&&Ne.current&&Ve.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(n?e:t)?.()},[]),Xe=useCallback(()=>new Promise(e=>{Ve.current<0?e(!0):We(()=>{Le.current(),$e(),e(!0)},()=>e(!1))}),[$e,We]),qe=useCallback(()=>{Le.current()},[]),Qe=useCallback(()=>{u&&Xe()},[u,Xe]),Ze=useRef(null);useEffect(()=>{const e=Ze.current!==o;Ze.current=o,e?o?Ke(n??0):$e():o&&"number"==typeof n&&n!==ge.value&&Ke(n)},[o,n]);const et=useRef({hostHeight:U,contentSnap:he});useEffect(()=>{const e=et.current;if(e.hostHeight===U&&e.contentSnap===he)return;if(et.current={hostHeight:U,contentSnap:he},e.hostHeight===U&&ge.value<0)return;const t=Fe(ge.value);pe.value=je.current?t:withSpring(t,SPRING_CONFIG)},[U,he]);const tt=U-be,ot=useMemo(()=>fe.map(e=>U-e),[fe,U]),st=useCallback(()=>{const e=Ve.current;e<0||Ye(Fe(e),e,e)},[Ye,Fe]),nt=useCallback((e,t)=>{const o=ge.value;-1!==e?(Ue(e),Ye(t,o,e)):We(()=>{Keyboard.dismiss(),triggerHaptic("selection"),Le.current(),$e()},st,st)},[Ye,$e,ge,We,Ue,st]),rt=useMemo(()=>Gesture.Native().withTestId(V?`${V}-content-gesture`:"bottom-sheet-content-gesture"),[V]),at=useMemo(()=>{const e=ot,t=Se,o=tt,s=i;return Gesture.Pan().withTestId(V?`${V}-pan-gesture`:"bottom-sheet-pan-gesture").activeOffsetY([-10,10]).failOffsetX([-15,15]).onStart(()=>{"worklet";ye.value=pe.value}).onUpdate(e=>{"worklet";const t=ye.value+e.translationY;pe.value=t<o?o+.25*(t-o):t}).onEnd(o=>{"worklet";const n=pe.value;if(o.velocityY>1e3)return s?void runOnJS(nt)(-1,t):void runOnJS(nt)(0,e[0]);let r=0,a=Math.abs(n-e[0]);for(let t=1;t<e.length;t++){const o=Math.abs(n-e[t]);o<a&&(a=o,r=t)}const l=e[0];s&&n-l>80?runOnJS(nt)(-1,t):runOnJS(nt)(r,e[r])})},[Se,ye,i,nt,tt,ot,V,pe]),{height:lt}=useReanimatedKeyboardAnimation(),it="shift"===v,ut=useDerivedValue(()=>it?lt.value:0,[it,lt]),ct=fe[we>=0?we:0]??be,dt=H.space.md,ht=useAnimatedStyle(()=>{if(W){const e=ut.value,t=U+e-ct-dt,o=e<0&&pe.value>t?t:pe.value;return{top:o<Z?Z:o,opacity:ve.value}}const e=pe.value+ut.value,t=ut.value<0?Z:tt;return{top:e<t?t:e,opacity:ve.value}},[W,ut,U,ct,dt,pe,Z,ve,tt]),mt=useAnimatedStyle(()=>{const e=ut.value;if(W){const t=U+e-ct-dt,o=e<0&&pe.value>t?t:pe.value,s=U+e-dt-(o<Z?Z:o);return{height:s<0?0:s>ct?ct:s}}const t=e<0?Z:tt,o=pe.value+e,s=U+e-(o<t?t:o);return{height:s<0?0:s>be?be:s}},[ut,W,U,ct,dt,pe,Z,tt,be]),ft=we>=0,St=useMemo(()=>buildStyles(H),[H]),bt=useCallback(()=>{u&&We(()=>{triggerHaptic("selection"),Le.current(),$e()})},[u,$e,We]),pt=useMemo(()=>Gesture.Tap().withTestId(V?`${V}-backdrop-gesture`:"bottom-sheet-backdrop-gesture").maxDuration(250).onEnd((_e,e)=>{"worklet";e&&runOnJS(bt)()}),[bt,V]),yt=useMemo(()=>({snapIndex:we,snapPoints:fe,close:qe,requestClose:Xe}),[we,fe,qe,Xe]);if("inline"===N&&!Ae)return null;if("modal"===N&&!Oe)return null;const vt=_jsxs(View,{collapsable:!1,style:["modal"===N?St.backdropModal:St.backdropInline,{backgroundColor:"modal"===N?transparentOf(H.colors.scrim):H.colors.scrim}],onLayout:K,testID:V,accessibilityViewIsModal:j??ft,children:[_jsx(GestureDetector,{gesture:pt,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:D.close})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:I,accessibilityViewIsModal:j??ft,accessibilityActions:[{name:"escape",label:D.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[St.sheet,{height:be,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,...smoothCorners,...H.shadow.modal},W?{height:ct,left:(z-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,_,ht],children:_jsxs(SheetBody,{style:[St.body,mt],keyboardOffset:ut,children:[W?_jsx(View,{style:{height:H.space.md}}):_jsx(GestureDetector,{gesture:at,children:_jsx(View,{style:St.handleRow,onLayout:te?se:void 0,accessible:!0,accessibilityLabel:D.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:V?`${V}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[St.handle,{backgroundColor:H.colors.border},x]})})}),B&&_jsxs(View,{style:[St.header,k],onLayout:te?re:void 0,children:[null!=d?_jsx(Text,{variant:"title",accessibilityRole:"header",children:d}):null,M]}),m?_jsx(GestureDetector,{gesture:rt,children:_jsx(ScrollView,{ref:f,style:St.scrollContent,onScroll:S,onContentSizeChange:me,onLayout:p,scrollEventThrottle:y,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:A})}):_jsx(View,{style:te?[St.content,{overflow:"visible"}]:St.content,children:te?_jsx(View,{onLayout:le,children:A}):A}),P&&_jsxs(View,{style:[St.footer,R],onLayout:te?ce:void 0,children:[L?_jsx(View,{style:St.actions,children:_jsx(OverlayActions,{actions:E??[],layout:O})}):null,T]})]})})]}),gt=_jsx(BottomSheetContext.Provider,{value:yt,children:vt});return"modal"===N?_jsx(Modal,{open:Me,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===Platform.OS?ze:void 0,children:"android"===Platform.OS?_jsx(GestureHandlerRootView,{style:St.modalRoot,children:gt}):gt}):gt},SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}},[s,t]);return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},header:{},actions:{padding:e.space.lg},footer:{},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
1
+ "use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Dimensions,Keyboard,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{ACTIONS_LAYOUTS,OverlayActions}from"../Dialog/OverlayActions.js";import{Modal}from"../Modal/Modal.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"});const DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=e=>{const{snapPoints:t=DEFAULT_SNAP_POINTS,open:o,onClose:s,snapIndex:n,onSnapChange:r,onAnimate:a,onAfterClose:i,enablePanDownToClose:l=!0,enableBackdropPress:u=!0,onBeforeClose:c,title:d,labels:h,scrollable:m=!1,scrollRef:f,onScroll:S,onContentSizeChange:b,onScrollLayout:p,scrollEventThrottle:v,keyboardBehavior:y="shift",inline:g=!1,presentation:w="sheet",animateMount:C=!0,handleIndicatorStyle:x,containerStyle:_,header:E,actions:M,actionsLayout:O="auto",footer:T,headerStyle:k,footerStyle:R,children:A,accessibilityLabel:I,accessibilityViewIsModal:j,testID:V}=e;assertValidValue("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),assertValidValue("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),assertValidValue("BottomSheet","actionsLayout",e.actionsLayout,ACTIONS_LAYOUTS);const D=useMemo(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,...h}),[h]),B=null!=E||null!=d,L=null!=M&&M.length>0,P=null!=T||L,N=g?"inline":"modal",H=useTheme(),G=usePresenceMotion(),F=useSafeAreaInsets(),[U,J]=useState(()=>Dimensions.get("window").height),[z,Y]=useState(()=>Dimensions.get("window").width),K=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&J(e=>e===t?e:t),o>0&&Y(e=>e===o?e:o)},[]),$=useWindowDimensions(),W="dialog"===w||"auto"===w&&Math.min($.width,$.height)>=600,X=Math.min(560,z-2*H.space.xl),[q,Q]=useModalInsets(),Z="modal"===N?q.top:F.top,ee="modal"===N?q.bottom:F.bottom,te=t.includes("content"),[oe,se]=useMeasuredHeight(),[ne,re]=useMeasuredHeight(),[ae,ie,le]=useMeasuredHeight(),[ue,ce]=useMeasuredHeight(),de=W?H.space.md:oe,he=te?Math.min(de+(B?ne:0)+ae+(P?ue:0)+ee,U-Z):0,me=useCallback((e,t)=>{te&&le(t),b?.(e,t)},[te,b,le]),fe=useMemo(()=>resolveSnapPoints(t,U,he),[t,U,he]),Se=U,be=fe[fe.length-1]??0,pe=useSharedValue(Se),ve=useSharedValue(Se),ye=useSharedValue(1),ge=useSharedValue(-1),[we,Ce]=useState(-1),xe=useRef(!1),[Ee,Me]=useState(!1),[Oe,Te]=useState(!1),ke=useRef(!1),Re=useRef(i);Re.current=i;const[Ae,Ie]=useState(!1),je=useRef(!C&&o),Ve=useRef(-1),De=useRef(!1);De.current="modal"===N?Oe:Ae;const Be=useRef(c);Be.current=c;const Le=useRef(s);Le.current=s;const Pe=useRef(!1),Ne=useRef(!0),He=useRef([]),Ge=useCallback(e=>{const t=He.current;He.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,Ge(!1)}),[Ge]);const Fe=useCallback(e=>{if(e<0||e>=fe.length)return Se;const t=fe[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return W?(U-t)/2:U-t},[fe,U,Se,W]),Ue=useCallback(e=>{Ve.current=e;we!==e&&(Ce(e),ge.value=e,e>=0&&r?.(e))},[we,ge,r]),Je=useCallback(()=>{xe.current=!1,ge.value<0&&(ke.current=!0,"modal"===N?(Me(!1),"ios"!==Platform.OS&&Te(!1)):Ie(!1))},[N,ge]),ze=useCallback(()=>{ke.current&&Te(!1)},[]);useEffect(()=>{("modal"===N?!Oe:!Ae)&&ke.current&&(ke.current=!1,Re.current?.(),Ge(!0))},[N,Oe,Ae,Ge]);const Ye=useCallback((e,t,o)=>{xe.current=!0,a?.(t,o),pe.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(Je)()})},[a,pe,Je]),Ke=useCallback(e=>{const t="number"==typeof e?clamp(e,0,fe.length-1):we>=0?we:0,o=ge.value,s=Fe(t);return ke.current=!1,Ge(!1),"modal"===N?(Te(!0),Me(!0)):Ie(!0),o<0&&je.current?(pe.value=s,ye.value=1,Ue(t),void a?.(o,t)):o<0&&G.reduced?(pe.value=s,ye.value=0,ye.value=withTiming(1,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Ue(t),void a?.(o,t)):(o<0&&(pe.value=Se,ye.value=1),Ue(t),void Ye(s,o,t))},[Ye,Se,we,ge,N,a,G,ye,fe.length,Ue,Ge,H.motion.ease.decelerate,pe,Fe]),$e=useCallback(()=>new Promise(e=>{if(Ve.current<0)return void(De.current?He.current.push(e):e(!0));He.current.push(e),je.current=!1;const t=ge.value;Ue(-1),xe.current=!0,a?.(t,-1);const o=G.reduced?ye:pe,s=G.reduced?0:Se;o.value=withTiming(s,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(Je)()})}),[Se,ge,Je,a,G,ye,Ue,pe,H.motion.ease.accelerate]),We=useCallback((e,t,o)=>{const s=Be.current;if(!s)return void e();if(Pe.current)return void t?.();const n=s();"boolean"!=typeof n?(Pe.current=!0,o?.(),n.then(o=>{Pe.current=!1,o&&Ne.current&&Ve.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(n?e:t)?.()},[]),Xe=useCallback(()=>new Promise(e=>{Ve.current<0?e(!0):We(()=>{Le.current(),$e(),e(!0)},()=>e(!1))}),[$e,We]),qe=useCallback(()=>{Le.current()},[]),Qe=useCallback(()=>{u&&Xe()},[u,Xe]),Ze=useRef(null);useEffect(()=>{const e=Ze.current!==o;Ze.current=o,e?o?Ke(n??0):$e():o&&"number"==typeof n&&n!==ge.value&&Ke(n)},[o,n]);const et=useRef({hostHeight:U,contentSnap:he});useEffect(()=>{const e=et.current;if(e.hostHeight===U&&e.contentSnap===he)return;if(et.current={hostHeight:U,contentSnap:he},e.hostHeight===U&&ge.value<0)return;const t=Fe(ge.value);pe.value=je.current?t:withSpring(t,SPRING_CONFIG)},[U,he]);const tt=U-be,ot=useMemo(()=>fe.map(e=>U-e),[fe,U]),st=useCallback(()=>{const e=Ve.current;e<0||Ye(Fe(e),e,e)},[Ye,Fe]),nt=useCallback((e,t)=>{const o=ge.value;-1!==e?(Ue(e),Ye(t,o,e)):We(()=>{Keyboard.dismiss(),triggerHaptic("selection"),Le.current(),$e()},st,st)},[Ye,$e,ge,We,Ue,st]),rt=useMemo(()=>Gesture.Native().withTestId(V?`${V}-content-gesture`:"bottom-sheet-content-gesture"),[V]),at=useMemo(()=>{const e=ot,t=Se,o=tt,s=l;return Gesture.Pan().withTestId(V?`${V}-pan-gesture`:"bottom-sheet-pan-gesture").activeOffsetY([-10,10]).failOffsetX([-15,15]).onStart(()=>{"worklet";ve.value=pe.value}).onUpdate(e=>{"worklet";const t=ve.value+e.translationY;pe.value=t<o?o+.25*(t-o):t}).onEnd(o=>{"worklet";const n=pe.value,r=o.velocityY,[a]=e;if(void 0===a)return void runOnJS(nt)(-1,t);if(r>1e3)return s?void runOnJS(nt)(-1,t):void runOnJS(nt)(0,a);let i=0,l=a,u=1/0,c=0;for(const t of e){const e=Math.abs(n-t);e<u&&(u=e,l=t,i=c),c++}s&&n-a>80?runOnJS(nt)(-1,t):runOnJS(nt)(i,l)})},[Se,ve,l,nt,tt,ot,V,pe]),{height:it}=useReanimatedKeyboardAnimation(),lt="shift"===y,ut=useDerivedValue(()=>lt?it.value:0,[lt,it]),ct=fe[we>=0?we:0]??be,dt=H.space.md,ht=useAnimatedStyle(()=>{if(W){const e=ut.value,t=U+e-ct-dt,o=e<0&&pe.value>t?t:pe.value;return{top:o<Z?Z:o,opacity:ye.value}}const e=pe.value+ut.value,t=ut.value<0?Z:tt;return{top:e<t?t:e,opacity:ye.value}},[W,ut,U,ct,dt,pe,Z,ye,tt]),mt=useAnimatedStyle(()=>{const e=ut.value;if(W){const t=U+e-ct-dt,o=e<0&&pe.value>t?t:pe.value,s=U+e-dt-(o<Z?Z:o);return{height:s<0?0:s>ct?ct:s}}const t=e<0?Z:tt,o=pe.value+e,s=U+e-(o<t?t:o);return{height:s<0?0:s>be?be:s}},[ut,W,U,ct,dt,pe,Z,tt,be]),ft=we>=0,St=useMemo(()=>buildStyles(H),[H]),bt=useCallback(()=>{u&&We(()=>{triggerHaptic("selection"),Le.current(),$e()})},[u,$e,We]),pt=useMemo(()=>Gesture.Tap().withTestId(V?`${V}-backdrop-gesture`:"bottom-sheet-backdrop-gesture").maxDuration(250).onEnd((_e,e)=>{"worklet";e&&runOnJS(bt)()}),[bt,V]),vt=useMemo(()=>({snapIndex:we,snapPoints:fe,close:qe,requestClose:Xe}),[we,fe,qe,Xe]);if("inline"===N&&!Ae)return null;if("modal"===N&&!Oe)return null;const yt=_jsxs(View,{collapsable:!1,style:["modal"===N?St.backdropModal:St.backdropInline,{backgroundColor:"modal"===N?transparentOf(H.colors.scrim):H.colors.scrim}],onLayout:K,testID:V,accessibilityViewIsModal:j??ft,children:[_jsx(GestureDetector,{gesture:pt,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:D.close})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:I,accessibilityViewIsModal:j??ft,accessibilityActions:[{name:"escape",label:D.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[St.sheet,{height:be,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,...smoothCorners,...H.shadow.modal},W?{height:ct,left:(z-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,_,ht],children:_jsxs(SheetBody,{style:[St.body,mt],keyboardOffset:ut,children:[W?_jsx(View,{style:{height:H.space.md}}):_jsx(GestureDetector,{gesture:at,children:_jsx(View,{style:St.handleRow,onLayout:te?se:void 0,accessible:!0,accessibilityLabel:D.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:V?`${V}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[St.handle,{backgroundColor:H.colors.border},x]})})}),B&&_jsxs(View,{style:[St.header,k],onLayout:te?re:void 0,children:[null!=d?_jsx(Text,{variant:"title",accessibilityRole:"header",children:d}):null,E]}),m?_jsx(GestureDetector,{gesture:rt,children:_jsx(ScrollView,{ref:f,style:St.scrollContent,onScroll:S,onContentSizeChange:me,onLayout:p,scrollEventThrottle:v,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:A})}):_jsx(View,{style:te?[St.content,{overflow:"visible"}]:St.content,children:te?_jsx(View,{onLayout:ie,children:A}):A}),P&&_jsxs(View,{style:[St.footer,R],onLayout:te?ce:void 0,children:[L?_jsx(View,{style:St.actions,children:_jsx(OverlayActions,{actions:M??[],layout:O})}):null,T]})]})})]}),gt=_jsx(BottomSheetContext.Provider,{value:vt,children:yt});return"modal"===N?_jsx(Modal,{open:Ee,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===Platform.OS?ze:void 0,children:"android"===Platform.OS?_jsx(GestureHandlerRootView,{style:St.modalRoot,children:gt}):gt}):gt},SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}},[s,t]);return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},header:{},actions:{padding:e.space.lg},footer:{},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{Gradient,resolveButtonSize,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT,tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/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";export const DEFAULT_BUTTON_LABELS=Object.freeze({loading:"Loading"});const Button=forwardRef((e,t)=>{const{label:o,variant:r,tone:s="primary",size:i,loading:n=!1,disabled:l=!1,fullWidth:a=!1,leftIcon:d,rightIcon:c,iconVariant:u,leftIconBadge:b=!1,haptic:g,rounded:p=!1,gradient:m,style:f,containerStyle:h,textStyle:x,pressAnimation:y,onPress:S,accessibilityLabel:C,accessibilityHint:_,accessibilityState:I,testID:T,onLayout:j,labels:k,...v}=e;assertValidValue("Button","variant",e.variant,["solid","soft","outline","ghost","link","glass"]),assertValidValue("Button","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Button","size",e.size,["xs","sm","md","lg","xl"]);const F=useTheme(),w=F.settings.components.button,L=r??w?.defaultVariant??"solid",V=i??w?.defaultSize??"md",A=useMemo(()=>({...DEFAULT_BUTTON_LABELS,...k}),[k]),O=!l&&!n,R={...I,disabled:!O,busy:n},B="link"===L,E=y??w?.defaultPressAnimation??(!B&&"scale"),P=usePressAnimation({preset:E||"scale",enabled:!1!==E&&O}),z=useFlickGuard(),H=useMemo(()=>buildStyles(F),[F]),W=useMemo(()=>resolveButtonSize(F,V),[F,V]),D=useMemo(()=>toneFor(F,s),[F,s]),N=useMemo(()=>variantFor(F,L,D,l),[F,L,D,l]),M=useMemo(()=>!m||l||"solid"!==L?null:"string"==typeof m?F.settings.gradients[m]??null:m,[m,l,L,F.settings.gradients]),U=StyleSheet.flatten(f)?.borderRadius,q=B?0:"number"==typeof U?U:p?F.radius.pill:W.radius,G=useSquircle(!M&&"link"!==L,q,j),K=useRef(createAnimatedValue(0)).current,[X,Y]=useState(0),[J,Q]=useState(null),Z=B?e=>Y(e.nativeEvent.layout.width):void 0,$=C??o,ee="outline"===L||"ghost"===L,te=!ee&&!B,oe={color:N.textColor,size:W.icon,disabled:l},re=b&&!B&&Boolean(d),se=F.space.xs,ie=W["min-height"]-2*se-2*N.borderWidth,ne={color:N.badgeInk,size:W["badge-icon"],disabled:l},le=n?_jsx(Spinner,{variant:"circular",size:"sm",color:re?N.badgeInk:N.textColor,accessibilityLabel:A.loading}):d?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(d,re?ne:oe,u)}):null,ae=_jsxs(View,{style:H.contentRow,children:[re?_jsx(View,{testID:"button-icon-badge",style:[H.iconLeft,H.iconBadge,{width:ie,height:ie,borderRadius:ie/2,backgroundColor:N.badgeFill}],children:le}):le?_jsx(View,{style:H.iconLeft,children:le}):null,_jsxs(View,{onLayout:Z,children:[_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,style:[H.label,{color:N.textColor,fontSize:W.text,lineHeight:Math.round(W.text*F.leading.body)},x],children:o}),B?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[H.linkUnderline,{backgroundColor:N.textColor,transform:[{translateX:K.interpolate({inputRange:[0,1],outputRange:[-X/2,0]})},{scaleX:K.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}),c?_jsx(View,{style:H.iconRight,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(c,oe,u)}):null]}),de=B?null===J?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(J)):touchSlopFor(W["min-height"]),ce={top:de,bottom:de,left:B?LINK_HIT_SLOP:0,right:B?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[P.style,a?H.fullWidth:null,h],children:_jsx(Pressable,{ref:t,onPress:e=>{if(!O||z.isFlick(e))return;P.press();const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t),S?.(e)},onPressIn:e=>{z.onPressIn(e),P.pressIn(),B&&O&&(K.stopAnimation(),K.setValue(0),Animated.timing(K,{toValue:1,duration:F.motion.duration.slower,easing:Easing.bezier(...F.motion.ease.decelerate),useNativeDriver:!0}).start())},onPressOut:()=>{P.pressOut()},disabled:!O,hitSlop:ce,...hitSlopMarker(ce),accessibilityRole:"button",accessibilityLabel:$,accessibilityHint:_,accessibilityState:R,...ariaFromState(R),testID:T,onLayout:e=>{G.onLayout(e),B&&Q(e.nativeEvent.layout.height)},style:({pressed:e})=>[H.base,{paddingHorizontal:B?0:W["padding-x"],paddingVertical:B?0:re?se:W["padding-y"],paddingLeft:re?se:void 0,minHeight:B?void 0:W["min-height"],borderRadius:q,...smoothCorners,backgroundColor:M||G.active?"transparent":N.backgroundColor,borderWidth:N.borderWidth,borderColor:G.active?"transparent":N.borderColor,opacity:n?.55:1,overflow:G.active||B?"visible":"hidden"},e&&ee&&!G.active?{backgroundColor:F.colors["surface-pressed"]}:null,a?H.fullWidth:null,f],...v,"aria-disabled":!O,"aria-busy":n,children:({pressed:e})=>_jsxs(_Fragment,{children:[G.active&&G.size?_jsx(SquircleFill,{width:G.size.width,height:G.size.height,radius:q,fill:e&&ee?F.colors["surface-pressed"]:N.backgroundColor,stroke:N.borderColor,strokeWidth:N.borderWidth}):null,M?_jsx(Gradient,{gradient:M,style:[StyleSheet.absoluteFill,{borderRadius:q,...smoothCorners}]}):null,e&&te?G.active&&G.size?_jsx(SquircleFill,{width:G.size.width,height:G.size.height,radius:q,fill:N.pressedTint,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[H.pressedOverlay,{borderRadius:q,backgroundColor:N.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,ae]})})})});Button.displayName="Button";const SOFT_FILL_OPACITY=.14,toneFor=(e,t)=>{switch(t){case"primary":return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors["primary-text"],soft:tintOf(e.colors.primary,.14,e.colors["primary-soft"])};case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"],soft:tintOf(e.colors.success,.14,e.colors["bg-subtle"])};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"],soft:tintOf(e.colors.warning,.14,e.colors["bg-subtle"])};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"],soft:tintOf(e.colors.danger,.14,e.colors["bg-subtle"])};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"],soft:tintOf(e.colors.info,.14,e.colors["bg-subtle"])};default:return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"],soft:e.colors["bg-subtle"]}}},BUTTON_BORDER_WIDTH=1,MIN_TOUCH_TARGET=44,LINK_HIT_SLOP=8,touchSlopFor=e=>Math.max(0,Math.ceil((44-e)/2)),variantFor=(e,t,o,r)=>{const s=r?e.colors["text-disabled"]:o.fg,i={badgeFill:e.colors["surface-disabled"],badgeInk:e.colors["text-disabled"]},n=r?i:{badgeFill:o.on,badgeInk:o.base},l=r?i:{badgeFill:o.base,badgeInk:o.on};switch(t){case"solid":return{backgroundColor:r?e.colors["surface-disabled"]:o.base,borderColor:"transparent",borderWidth:1,textColor:r?e.colors["text-disabled"]:o.on,pressedTint:e.colors["surface-pressed"],...n};case"soft":return{backgroundColor:r?e.colors["surface-disabled"]:o.soft,borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"outline":return{backgroundColor:"transparent",borderColor:r?e.colors.border:o.outline,borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"ghost":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"link":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:0,textColor:r?e.colors["text-disabled"]:e.colors.link,pressedTint:e.colors["surface-pressed"],...l};case"glass":return{backgroundColor:e.colors["glass-fill"],borderColor:e.colors["glass-border"],borderWidth:1,textColor:r?e.colors["text-disabled"]:e.colors["on-glass"],pressedTint:ACCENT_PRESSED_TINT,badgeFill:e.colors["glass-badge"],badgeInk:r?e.colors["text-disabled"]:o.base};default:return{backgroundColor:o.base,borderColor:"transparent",borderWidth:1,textColor:o.on,pressedTint:e.colors["surface-pressed"],...n}}};export function buttonLabelInk(e,t){return variantFor(t,e.variant??"solid",toneFor(t,e.tone??"primary"),e.disabled??!1).textColor}const buildStyles=e=>StyleSheet.create({pressedOverlay:{position:"absolute",top:0,right:0,bottom:0,left:0},base:{alignItems:"center",justifyContent:"center",flexDirection:"row",overflow:"hidden"},contentRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},label:{textAlign:"center",includeFontPadding:!1,textAlignVertical:"center"},linkUnderline:{height:1.5,marginTop:1},iconLeft:{marginRight:e.space.sm},iconBadge:{alignItems:"center",justifyContent:"center"},iconRight:{marginLeft:e.space.sm},fullWidth:{alignSelf:"stretch"}});export{Button};export default Button;
1
+ "use strict";import{forwardRef,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useFlickGuard}from"../../hooks/useFlickGuard.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{Gradient,resolveButtonSize,useTheme}from"../../theme/index.js";import{createAnimatedValue}from"../../theme/animatedValue.js";import{ariaFromState}from"../../utils/ariaState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT,tintOf}from"../../utils/color.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{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/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";export const DEFAULT_BUTTON_LABELS=Object.freeze({loading:"Loading"});const Button=forwardRef((e,t)=>{const{label:o,variant:r,tone:s="primary",size:i,loading:n=!1,disabled:l=!1,fullWidth:a=!1,leftIcon:d,rightIcon:c,iconVariant:u,leftIconBadge:b=!1,haptic:g,rounded:p=!1,gradient:m,style:f,containerStyle:h,textStyle:x,pressAnimation:y,onPress:S,accessibilityLabel:C,accessibilityHint:_,accessibilityState:I,testID:v,onLayout:j,labels:T,...k}=e;assertValidValue("Button","variant",e.variant,["solid","soft","outline","ghost","link","glass"]),assertValidValue("Button","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Button","size",e.size,["xs","sm","md","lg","xl"]);const F=useTheme(),w=F.settings.components.button,L=r??w?.defaultVariant??"solid",V=i??w?.defaultSize??"md",A=useMemo(()=>({...DEFAULT_BUTTON_LABELS,...T}),[T]),O=!l&&!n,R={...I,disabled:!O,busy:n},B="link"===L,E=y??w?.defaultPressAnimation??(!B&&"scale"),P=usePressAnimation({preset:E||"scale",enabled:!1!==E&&O}),z=useFlickGuard(),D=useMemo(()=>buildStyles(F),[F]),H=useMemo(()=>resolveButtonSize(F,V),[F,V]),W=useMemo(()=>toneFor(F,s),[F,s]),N=useMemo(()=>variantFor(F,L,W,l),[F,L,W,l]),M=useMemo(()=>!m||l||"solid"!==L?null:"string"==typeof m?F.settings.gradients[m]??null:m,[m,l,L,F.settings.gradients]),U=StyleSheet.flatten(f)?.borderRadius,q=B?0:"number"==typeof U?U:p?F.radius.pill:H.radius,G=useSquircle(!M&&"link"!==L,q,j),K=useRef(createAnimatedValue(0)).current,[X,Y]=useState(0),[J,Q]=useState(null),Z=B?e=>Y(e.nativeEvent.layout.width):void 0,$=C??o,ee="outline"===L||"ghost"===L,te=!ee&&!B,oe={color:N.textColor,size:H.icon,disabled:l},re=b&&!B&&Boolean(d),se=F.space.xs,ie=H["min-height"]-2*se-2*N.borderWidth,ne={color:N.badgeInk,size:H["badge-icon"],disabled:l},le=n?_jsx(Spinner,{variant:"circular",size:"sm",color:re?N.badgeInk:N.textColor,accessibilityLabel:A.loading}):d?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(d,re?ne:oe,u)}):null,ae=_jsxs(View,{style:D.contentRow,children:[re?_jsx(View,{testID:"button-icon-badge",style:[D.iconLeft,D.iconBadge,{width:ie,height:ie,borderRadius:ie/2,backgroundColor:N.badgeFill}],children:le}):le?_jsx(View,{style:D.iconLeft,children:le}):null,_jsxs(View,{onLayout:Z,children:[_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,style:[D.label,{color:N.textColor,fontSize:H.text,lineHeight:Math.round(H.text*F.leading.body)},x],children:o}),B?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[D.linkUnderline,{backgroundColor:N.textColor,transform:[{translateX:K.interpolate({inputRange:[0,1],outputRange:[-X/2,0]})},{scaleX:K.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}),c?_jsx(View,{style:D.iconRight,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(c,oe,u)}):null]}),de=B?null===J?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(J)):touchSlopFor(H["min-height"]),ce={top:de,bottom:de,left:B?LINK_HIT_SLOP:0,right:B?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[P.style,a?D.fullWidth:null,h],children:_jsx(Pressable,{ref:t,onPress:e=>{if(!O||z.isFlick(e))return;P.press();const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t),S?.(e)},onPressIn:e=>{z.onPressIn(e),P.pressIn(),B&&O&&(K.stopAnimation(),K.setValue(0),Animated.timing(K,{toValue:1,duration:F.motion.duration.slower,easing:Easing.bezier(...F.motion.ease.decelerate),useNativeDriver:nativeDriver}).start())},onPressOut:()=>{P.pressOut()},disabled:!O,hitSlop:ce,...hitSlopMarker(ce),accessibilityRole:"button",accessibilityLabel:$,accessibilityHint:_,accessibilityState:R,...ariaFromState(R),testID:v,onLayout:e=>{G.onLayout(e),B&&Q(e.nativeEvent.layout.height)},style:({pressed:e})=>[D.base,{paddingHorizontal:B?0:H["padding-x"],paddingVertical:B?0:re?se:H["padding-y"],paddingLeft:re?se:void 0,minHeight:B?void 0:H["min-height"],borderRadius:q,...smoothCorners,backgroundColor:M||G.active?"transparent":N.backgroundColor,borderWidth:N.borderWidth,borderColor:G.active?"transparent":N.borderColor,opacity:n?.55:1,overflow:G.active||B?"visible":"hidden"},e&&ee&&!G.active?{backgroundColor:F.colors["surface-pressed"]}:null,a?D.fullWidth:null,f],...k,"aria-disabled":!O,"aria-busy":n,children:({pressed:e})=>_jsxs(_Fragment,{children:[G.active&&G.size?_jsx(SquircleFill,{width:G.size.width,height:G.size.height,radius:q,fill:e&&ee?F.colors["surface-pressed"]:N.backgroundColor,stroke:N.borderColor,strokeWidth:N.borderWidth}):null,M?_jsx(Gradient,{gradient:M,style:[StyleSheet.absoluteFill,{borderRadius:q,...smoothCorners}]}):null,e&&te?G.active&&G.size?_jsx(SquircleFill,{width:G.size.width,height:G.size.height,radius:q,fill:N.pressedTint,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[D.pressedOverlay,{borderRadius:q,backgroundColor:N.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,ae]})})})});Button.displayName="Button";const SOFT_FILL_OPACITY=.14,toneFor=(e,t)=>{switch(t){case"primary":return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors["primary-text"],soft:tintOf(e.colors.primary,.14,e.colors["primary-soft"])};case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"],soft:tintOf(e.colors.success,.14,e.colors["bg-subtle"])};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"],soft:tintOf(e.colors.warning,.14,e.colors["bg-subtle"])};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"],soft:tintOf(e.colors.danger,.14,e.colors["bg-subtle"])};case"info":return{base:e.colors.info,outline:e.colors.info,on:e.colors["on-info"],fg:e.colors["info-text"],soft:tintOf(e.colors.info,.14,e.colors["bg-subtle"])};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"],soft:e.colors["bg-subtle"]}}},BUTTON_BORDER_WIDTH=1,MIN_TOUCH_TARGET=44,LINK_HIT_SLOP=8,touchSlopFor=e=>Math.max(0,Math.ceil((44-e)/2)),variantFor=(e,t,o,r)=>{const s=r?e.colors["text-disabled"]:o.fg,i={badgeFill:e.colors["surface-disabled"],badgeInk:e.colors["text-disabled"]},n=r?i:{badgeFill:o.on,badgeInk:o.base},l=r?i:{badgeFill:o.base,badgeInk:o.on};switch(t){case"solid":return{backgroundColor:r?e.colors["surface-disabled"]:o.base,borderColor:"transparent",borderWidth:1,textColor:r?e.colors["text-disabled"]:o.on,pressedTint:e.colors["surface-pressed"],...n};case"soft":return{backgroundColor:r?e.colors["surface-disabled"]:o.soft,borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"outline":return{backgroundColor:"transparent",borderColor:r?e.colors.border:o.outline,borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"ghost":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:1,textColor:s,pressedTint:e.colors["surface-pressed"],...l};case"link":return{backgroundColor:"transparent",borderColor:"transparent",borderWidth:0,textColor:r?e.colors["text-disabled"]:e.colors.link,pressedTint:e.colors["surface-pressed"],...l};case"glass":return{backgroundColor:e.colors["glass-fill"],borderColor:e.colors["glass-border"],borderWidth:1,textColor:r?e.colors["text-disabled"]:e.colors["on-glass"],pressedTint:ACCENT_PRESSED_TINT,badgeFill:e.colors["glass-badge"],badgeInk:r?e.colors["text-disabled"]:o.base};default:return{backgroundColor:o.base,borderColor:"transparent",borderWidth:1,textColor:o.on,pressedTint:e.colors["surface-pressed"],...n}}};export function buttonLabelInk(e,t){return variantFor(t,e.variant??"solid",toneFor(t,e.tone??"primary"),e.disabled??!1).textColor}const buildStyles=e=>StyleSheet.create({pressedOverlay:{position:"absolute",top:0,right:0,bottom:0,left:0},base:{alignItems:"center",justifyContent:"center",flexDirection:"row",overflow:"hidden"},contentRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},label:{textAlign:"center",includeFontPadding:!1,textAlignVertical:"center"},linkUnderline:{height:1.5,marginTop:1},iconLeft:{marginRight:e.space.sm},iconBadge:{alignItems:"center",justifyContent:"center"},iconRight:{marginLeft:e.space.sm},fullWidth:{alignSelf:"stretch"}});export{Button};export default Button;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useLayoutEffect,useMemo,useRef}from"react";import{AccessibilityInfo,Animated,Easing,Pressable,View}from"react-native";import{useControllableState,usePresenceMotion}from"../../hooks/index.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Text}from"../Text/index.js";import{CalendarDay}from"./CalendarDay.js";import{addMonths,buildMonthMatrix,GRID_CELLS,startOfDay,startOfMonth,toIso,weekdayLabels}from"./calendarDates.js";import{buildCalendarStyles,MIN_CELL_SIZE,NAV_BUTTON_SIZE}from"./calendarStyles.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CALENDAR_LABELS=Object.freeze({previousMonth:"Previous month",nextMonth:"Next month",marked:"Marked"});const MAX_DOTS=3,DAY_TEXT_MAX_SCALE=1.5,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"primary":return e.colors.primary;default:return e.colors["text-muted"]}},Calendar=forwardRef((e,t)=>{const{selectionMode:a="single",value:s,onChange:i,month:n,onMonthChange:r,minDate:l,maxDate:o,disabledDates:d,weekStartsOn:u=0,locale:c="en-IN",marks:m,cellSize:h,haptic:y,accessibilityLabel:f,onTitlePress:p,labels:g,style:b,headerLabelStyle:M,navButtonStyle:x,testID:_}=e;assertValidValue("Calendar","selectionMode",e.selectionMode,["single","range"]);const S=useMemo(()=>({...DEFAULT_CALENDAR_LABELS,...g}),[g]),v=S.marked,D=useTheme(),L=usePresenceMotion(),T=useMemo(()=>buildCalendarStyles(D),[D]),[w,C]=useControllableState({value:n?startOfMonth(n):void 0,defaultValue:startOfMonth(s?.start??new Date),onChange:r}),A=12*w.getFullYear()+w.getMonth(),j=s?.start?startOfDay(s.start):null,E="range"===a&&s?.end?startOfDay(s.end):null,k=j?.getTime()??null,V=E?.getTime()??null,I=toIso(new Date),R=l?startOfDay(l).getTime():null,N=o?startOfDay(o).getTime():null,O=useMemo(()=>new Set((d??[]).map(e=>toIso(e))),[d]),P=useCallback(e=>null!==R&&e.getTime()<R||null!==N&&e.getTime()>N||O.has(toIso(e)),[R,N,O]),F=useMemo(()=>{const e=new Map;for(const t of m??[]){const a=t.date;let s=e.get(a);s||(s={dots:[],spoken:[]},e.set(a,s)),s.dots.length<3&&s.dots.push({key:`${t.tone}-${s.dots.length}`,color:toneColor(D,t.tone)}),s.spoken.push(t.label??v)}return e},[m,D,v]),B=useMemo(()=>buildMonthMatrix(new Date(Math.floor(A/12),A%12,1),u),[A,u]),z=useMemo(()=>weekdayLabels(c,u),[c,u]),H=useMemo(()=>new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}),[c]),Z=useMemo(()=>new Intl.DateTimeFormat(c,{weekday:"short",day:"numeric",month:"long"}),[c]),$=H.format(w),X=null===R||startOfMonth(new Date(R)).getTime()<w.getTime(),U=null===N||startOfMonth(new Date(N)).getTime()>w.getTime(),q=useRef(createAnimatedValue(0)).current,G=useRef(createAnimatedValue(1)).current,Y=useRef(null);useEffect(()=>()=>Y.current?.stop(),[]);const W=useCallback(e=>{!1!==y&&triggerHaptic("impactLight");const t=D.motion.duration.fast,a=D.motion.duration.fast,[s]=L.range(32*-e,0),[i]=L.range(32*e,0),n=L.reduced?L.duration("fast"):t,r=L.reduced?L.duration("fast"):a;Y.current?.stop(),Y.current=Animated.sequence([Animated.parallel([Animated.timing(q,{toValue:s,duration:t,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(G,{toValue:0,duration:n,useNativeDriver:!0})]),Animated.timing(q,{toValue:i,duration:0,useNativeDriver:!0}),Animated.parallel([Animated.timing(q,{toValue:0,duration:a,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(G,{toValue:1,duration:r,useNativeDriver:!0})])]),Y.current.start();const l=addMonths(w,e);C(l),AccessibilityInfo.announceForAccessibility(H.format(l))},[y,w,G,H,q,L,C,D]),J=useCallback(()=>W(-1),[W]),K=useCallback(()=>W(1),[W]),pressDay=e=>{if(P(e.date))return;const t=resolveHaptic(y,"selection");t&&triggerHaptic(t);const s=e.date;"single"===a||!j||E||s.getTime()<j.getTime()?i({start:s}):i({start:j,end:s}),e.inMonth||C(startOfMonth(s))},Q=useRef(pressDay);useLayoutEffect(()=>{Q.current=pressDay});const ee=useCallback(e=>Q.current(e),[]),te=void 0===h?void 0:Math.max(h,MIN_CELL_SIZE),ae=useMemo(()=>void 0===te?{flex:1}:{width:te},[te]),se=useMemo(()=>void 0===te?{flex:1,aspectRatio:1,minHeight:MIN_CELL_SIZE}:{width:te,height:te},[te]),ie=Math.max(D.space.sm,(MIN_CELL_SIZE-NAV_BUTTON_SIZE)/2),ne=Math.min(D.settings.maxFontSizeMultiplier??1.5,1.5),re=[];for(let e=0;e<GRID_CELLS;e+=7)re.push(B.slice(e,e+7));const le=_jsx(Text,{variant:"title",accessibilityRole:"header",accessibilityLabel:f?`${f}, ${$}`:void 0,style:T.headerLabel,children:$});return _jsxs(View,{ref:t,style:[T.root,b],testID:_,children:[_jsxs(View,{style:T.headerRow,children:[_jsx(Pressable,{onPress:J,disabled:!X,style:({pressed:e})=>[T.navBtn,e&&T.navBtnPressed,!X&&T.navBtnDisabled,x],accessibilityRole:"button",accessibilityLabel:S.previousMonth,accessibilityState:{disabled:!X},"aria-disabled":!X,hitSlop:ie,...hitSlopMarker(ie),children:_jsx(Text,{variant:"title",style:T.navText,maxFontSizeMultiplier:ne,children:"‹"})}),_jsx(Animated.View,{style:[T.headerLabelWrap,{opacity:G,transform:[{translateX:q}]},M],children:p?_jsx(Pressable,{onPress:p,accessibilityRole:"button",accessibilityLabel:f?`${f}, ${$}`:$,hitSlop:ie,...hitSlopMarker(ie),children:le}):le}),_jsx(Pressable,{onPress:K,disabled:!U,style:({pressed:e})=>[T.navBtn,e&&T.navBtnPressed,!U&&T.navBtnDisabled,x],accessibilityRole:"button",accessibilityLabel:S.nextMonth,accessibilityState:{disabled:!U},"aria-disabled":!U,hitSlop:ie,...hitSlopMarker(ie),children:_jsx(Text,{variant:"title",style:T.navText,maxFontSizeMultiplier:ne,children:"›"})})]}),_jsx(View,{style:T.weekdayRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:z.map(({weekday:e,label:t})=>_jsx(View,{style:[T.weekdayCell,ae],children:_jsx(Text,{variant:"caption",style:T.weekdayText,maxFontSizeMultiplier:ne,children:t})},e))}),_jsx(Animated.View,{style:{opacity:G,transform:[{translateX:q}]},children:re.map(e=>_jsx(View,{style:T.gridRow,children:e.map(e=>{const t=e.date.getTime(),s=null!==k&&t===k,i=null!==V&&t===V,n=null!==k&&null!==V&&t>=k&&t<=V,r=n&&!s&&!i,l=e.iso===I,o=F.get(e.iso),d=[Z.format(e.date),...o?.spoken??[]];return l&&d.push("today"),"range"===a&&(s&&i?d.push("start and end of your range"):s?d.push("start of your range"):i?d.push("end of your range"):r&&d.push("in your range")),_jsx(CalendarDay,{cell:e,accessibilityLabel:d.join(", "),disabled:P(e.date),edge:s||i,mid:r,barLeft:n&&(i||r)&&!(s&&i),barRight:n&&(s||r)&&!(s&&i),today:l,dots:o?.dots,cellStyle:se,styles:T,maxFontSizeMultiplier:ne,onPressDay:ee},e.iso)})},e[0].iso))})]})});Calendar.displayName="Calendar";export{Calendar};export default Calendar;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useLayoutEffect,useMemo,useRef}from"react";import{AccessibilityInfo,Animated,Easing,Pressable,View}from"react-native";import{useControllableState,usePresenceMotion}from"../../hooks/index.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{CalendarDay}from"./CalendarDay.js";import{addMonths,buildMonthMatrix,GRID_CELLS,startOfDay,startOfMonth,toIso,weekdayLabels}from"./calendarDates.js";import{buildCalendarStyles,MIN_CELL_SIZE,NAV_BUTTON_SIZE}from"./calendarStyles.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_CALENDAR_LABELS=Object.freeze({previousMonth:"Previous month",nextMonth:"Next month",marked:"Marked"});const MAX_DOTS=3,DAY_TEXT_MAX_SCALE=1.5,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"primary":return e.colors.primary;case"neutral":return e.colors["text-muted"]}},Calendar=forwardRef((e,t)=>{const{selectionMode:a="single",value:s,onChange:i,month:r,onMonthChange:n,minDate:l,maxDate:o,disabledDates:d,weekStartsOn:u=0,locale:c="en-IN",marks:m,cellSize:h,haptic:p,accessibilityLabel:y,onTitlePress:f,labels:g,style:b,headerLabelStyle:M,navButtonStyle:x,testID:v}=e;assertValidValue("Calendar","selectionMode",e.selectionMode,["single","range"]);const D=useMemo(()=>({...DEFAULT_CALENDAR_LABELS,...g}),[g]),_=D.marked,S=useTheme(),L=usePresenceMotion(),T=useMemo(()=>buildCalendarStyles(S),[S]),[w,C]=useControllableState({value:r?startOfMonth(r):void 0,defaultValue:startOfMonth(s?.start??new Date),onChange:n}),j=12*w.getFullYear()+w.getMonth(),A=s?.start?startOfDay(s.start):null,E="range"===a&&s?.end?startOfDay(s.end):null,k=A?.getTime()??null,V=E?.getTime()??null,I=toIso(new Date),R=l?startOfDay(l).getTime():null,N=o?startOfDay(o).getTime():null,O=useMemo(()=>new Set((d??[]).map(e=>toIso(e))),[d]),P=useCallback(e=>null!==R&&e.getTime()<R||null!==N&&e.getTime()>N||O.has(toIso(e)),[R,N,O]),F=useMemo(()=>{const e=new Map;for(const t of m??[]){const a=t.date;let s=e.get(a);s||(s={dots:[],spoken:[]},e.set(a,s)),s.dots.length<3&&s.dots.push({key:`${t.tone}-${s.dots.length}`,color:toneColor(S,t.tone)}),s.spoken.push(t.label??_)}return e},[m,S,_]),B=useMemo(()=>buildMonthMatrix(new Date(Math.floor(j/12),j%12,1),u),[j,u]),z=useMemo(()=>weekdayLabels(c,u),[c,u]),H=useMemo(()=>new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}),[c]),Z=useMemo(()=>new Intl.DateTimeFormat(c,{weekday:"short",day:"numeric",month:"long"}),[c]),$=H.format(w),X=null===R||startOfMonth(new Date(R)).getTime()<w.getTime(),U=null===N||startOfMonth(new Date(N)).getTime()>w.getTime(),q=useRef(createAnimatedValue(0)).current,G=useRef(createAnimatedValue(1)).current,Y=useRef(null);useEffect(()=>()=>Y.current?.stop(),[]);const W=useCallback(e=>{!1!==p&&triggerHaptic("impactLight");const t=S.motion.duration.fast,a=S.motion.duration.fast,[s]=L.range(32*-e,0),[i]=L.range(32*e,0),r=L.reduced?L.duration("fast"):t,n=L.reduced?L.duration("fast"):a;Y.current?.stop(),Y.current=Animated.sequence([Animated.parallel([Animated.timing(q,{toValue:s,duration:t,easing:Easing.out(Easing.quad),useNativeDriver:nativeDriver}),Animated.timing(G,{toValue:0,duration:r,useNativeDriver:nativeDriver})]),Animated.timing(q,{toValue:i,duration:0,useNativeDriver:nativeDriver}),Animated.parallel([Animated.timing(q,{toValue:0,duration:a,easing:Easing.out(Easing.cubic),useNativeDriver:nativeDriver}),Animated.timing(G,{toValue:1,duration:n,useNativeDriver:nativeDriver})])]),Y.current.start();const l=addMonths(w,e);C(l),AccessibilityInfo.announceForAccessibility(H.format(l))},[p,w,G,H,q,L,C,S]),J=useCallback(()=>W(-1),[W]),K=useCallback(()=>W(1),[W]),pressDay=e=>{if(P(e.date))return;const t=resolveHaptic(p,"selection");t&&triggerHaptic(t);const s=e.date;"single"===a||!A||E||s.getTime()<A.getTime()?i({start:s}):i({start:A,end:s}),e.inMonth||C(startOfMonth(s))},Q=useRef(pressDay);useLayoutEffect(()=>{Q.current=pressDay});const ee=useCallback(e=>Q.current(e),[]),te=void 0===h?void 0:Math.max(h,MIN_CELL_SIZE),ae=useMemo(()=>void 0===te?{flex:1}:{width:te},[te]),se=useMemo(()=>void 0===te?{flex:1,aspectRatio:1,minHeight:MIN_CELL_SIZE}:{width:te,height:te},[te]),ie=Math.max(S.space.sm,(MIN_CELL_SIZE-NAV_BUTTON_SIZE)/2),re=Math.min(S.settings.maxFontSizeMultiplier??1.5,1.5),ne=[];for(let e=0;e<GRID_CELLS;e+=7)ne.push(B.slice(e,e+7));const le=_jsx(Text,{variant:"title",accessibilityRole:"header",accessibilityLabel:y?`${y}, ${$}`:void 0,style:T.headerLabel,children:$});return _jsxs(View,{ref:t,style:[T.root,b],testID:v,children:[_jsxs(View,{style:T.headerRow,children:[_jsx(Pressable,{onPress:J,disabled:!X,style:({pressed:e})=>[T.navBtn,e&&T.navBtnPressed,!X&&T.navBtnDisabled,x],accessibilityRole:"button",accessibilityLabel:D.previousMonth,accessibilityState:{disabled:!X},"aria-disabled":!X,hitSlop:ie,...hitSlopMarker(ie),children:_jsx(Text,{variant:"title",style:T.navText,maxFontSizeMultiplier:re,children:"‹"})}),_jsx(Animated.View,{style:[T.headerLabelWrap,{opacity:G,transform:[{translateX:q}]},M],children:f?_jsx(Pressable,{onPress:f,accessibilityRole:"button",accessibilityLabel:y?`${y}, ${$}`:$,hitSlop:ie,...hitSlopMarker(ie),children:le}):le}),_jsx(Pressable,{onPress:K,disabled:!U,style:({pressed:e})=>[T.navBtn,e&&T.navBtnPressed,!U&&T.navBtnDisabled,x],accessibilityRole:"button",accessibilityLabel:D.nextMonth,accessibilityState:{disabled:!U},"aria-disabled":!U,hitSlop:ie,...hitSlopMarker(ie),children:_jsx(Text,{variant:"title",style:T.navText,maxFontSizeMultiplier:re,children:"›"})})]}),_jsx(View,{style:T.weekdayRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:z.map(({weekday:e,label:t})=>_jsx(View,{style:[T.weekdayCell,ae],children:_jsx(Text,{variant:"caption",style:T.weekdayText,maxFontSizeMultiplier:re,children:t})},e))}),_jsx(Animated.View,{style:{opacity:G,transform:[{translateX:q}]},children:ne.map(e=>_jsx(View,{style:T.gridRow,children:e.map(e=>{const t=e.date.getTime(),s=null!==k&&t===k,i=null!==V&&t===V,r=null!==k&&null!==V&&t>=k&&t<=V,n=r&&!s&&!i,l=e.iso===I,o=F.get(e.iso),d=[Z.format(e.date),...o?.spoken??[]];return l&&d.push("today"),"range"===a&&(s&&i?d.push("start and end of your range"):s?d.push("start of your range"):i?d.push("end of your range"):n&&d.push("in your range")),_jsx(CalendarDay,{cell:e,accessibilityLabel:d.join(", "),disabled:P(e.date),edge:s||i,mid:n,barLeft:r&&(i||n)&&!(s&&i),barRight:r&&(s||n)&&!(s&&i),today:l,dots:o?.dots,cellStyle:se,styles:T,maxFontSizeMultiplier:re,onPressDay:ee},e.iso)})},e.map(e=>e.iso).join(",")))})]})});Calendar.displayName="Calendar";export{Calendar};export default Calendar;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,AppState,Dimensions,FlatList,Image,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,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{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_CAROUSEL_LABELS=Object.freeze({carousel:"Carousel",slideOf:(e,t)=>`Slide ${e} of ${t}`,goToSlide:e=>`Go to slide ${e}`});const CarouselInner=forwardRef((e,t)=>{const{data:n,renderItem:r,keyExtractor:s,index:a,defaultIndex:i=0,onIndexChange:l,onScrollOffsetChange:o,autoPlay:c=!1,autoPlayInterval:u=4e3,loop:d=!1,showPagination:m=!0,paginationStyle:h="dots",itemWidth:g="screen",spacing:b=0,containerStyle:p,accessibilityLabel:f,testID:x,showThumbnails:y=!1,haptic:S,renderThumbnail:w,loading:C=!1,labels:T}=e;assertValidValue("Carousel","paginationStyle",e.paginationStyle,["dots","bars","numbers"]);const v=useMemo(()=>({...DEFAULT_CAROUSEL_LABELS,...T}),[T]),j=useTheme(),I="number"==typeof a,k=d||c,[_,A]=useState(()=>Dimensions.get("window").width),E="screen"===g?_:g,R=E+b,V=useRef(null),L=useRef(createAnimatedValue(0)).current,O=clamp(I?a:i,0,Math.max(0,n.length-1)),[H,D]=useState(O),M=useRef(null),P=useRef(null),z=useRef(!1),N=useRef(H);N.current=H;const W=useCallback(e=>{const t=clamp(e,0,Math.max(0,n.length-1));D(e=>e===t?e:(l?.(t),t))},[n.length,l]),F=useCallback((e,t=!0)=>{if(0===n.length)return;const r=clamp(e,0,n.length-1);V.current?.scrollToOffset({offset:r*R,animated:t}),W(r)},[n.length,R,W]),$=useCallback(()=>{if(0===n.length)return;const e=N.current+1;e>=n.length?k&&F(0,!1):F(e,!0)},[n.length,k,F]),U=useCallback(()=>{if(0===n.length)return;const e=N.current-1;e<0?k&&F(n.length-1,!1):F(e,!0)},[n.length,k,F]);useImperativeHandle(t,()=>({scrollTo:F,next:$,prev:U}),[F,$,U]),useEffect(()=>{I&&a!==H&&F(a,!0)},[a]);const B=useCallback(()=>{M.current&&(clearInterval(M.current),M.current=null)},[]),G=useCallback(()=>{!c||n.length<=1||(B(),M.current=setInterval(()=>{if(z.current)return;const e=N.current+1;e>=n.length?F(0,!1):F(e,!0)},u))},[c,u,n.length,F,B]);useEffect(()=>(G(),()=>{B(),P.current&&clearTimeout(P.current)}),[G,B]),useEffect(()=>{const e=AppState.addEventListener("change",e=>{"active"!==e?(B(),P.current&&(clearTimeout(P.current),P.current=null)):G()});return()=>e.remove()},[G,B]);const K=m&&n.length>1&&"numbers"!==h||void 0!==o,X=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{x:L}}}],{useNativeDriver:!1,listener:o?e=>o(e.nativeEvent.contentOffset.x):void 0}),[L,o]),q=useCallback(e=>{if(R<=0)return;const t=e.nativeEvent.contentOffset.x,n=Math.round(t/R);W(n)},[R,W]),J=useCallback(()=>{z.current=!0,B(),P.current&&(clearTimeout(P.current),P.current=null)},[B]),Q=useCallback(()=>{z.current=!1,c&&(P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{G()},1e3))},[c,G]),Y=useCallback(e=>{switch(e.nativeEvent.actionName){case"increment":$();break;case"decrement":U()}},[$,U]),Z=useMemo(()=>buildStyles(j),[j]),ee=useCallback(({item:e,index:t})=>_jsx(View,{style:{width:E,marginRight:t===n.length-1?0:b},accessibilityElementsHidden:t!==H,importantForAccessibility:t===H?"yes":"no-hide-descendants",children:r(e,t)}),[r,E,b,n.length,H]),te=useCallback((e,t)=>String(t),[]),ne=useCallback((e,t)=>({length:R,offset:R*t,index:t}),[R]);return C?_jsx(CarouselSkeleton,{...e,containerWidth:_}):_jsxs(View,{style:[Z.container,p],onLayout:e=>A(e.nativeEvent.layout.width),accessibilityRole:"adjustable",accessibilityLabel:f??v.carousel,accessibilityValue:{min:0,max:Math.max(0,n.length-1),now:H,text:v.slideOf(H+1,n.length)},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Y,testID:x,children:[_jsx(FlatList,{ref:V,data:n,keyExtractor:s??te,renderItem:ee,horizontal:!0,pagingEnabled:"screen"===g&&0===b,snapToInterval:R,snapToAlignment:"start",decelerationRate:"fast",showsHorizontalScrollIndicator:!1,onScroll:K?X:void 0,scrollEventThrottle:K?16:void 0,onMomentumScrollEnd:q,onScrollBeginDrag:J,onScrollEndDrag:Q,getItemLayout:ne,initialScrollIndex:O,bounces:!1}),m&&n.length>1?_jsx(Pagination,{count:n.length,currentIndex:H,scrollX:L,slideStride:R,variant:h,theme:j,labels:v}):null,y&&n.length>0?_jsx(ThumbnailStrip,{data:n,currentIndex:H,renderThumbnail:w,labels:v,onSelect:e=>{const t=resolveHaptic(S,"selection");t&&triggerHaptic(t),F(e,!0)},theme:j}):null]})});CarouselInner.displayName="Carousel";const CarouselSkeleton=({itemWidth:e="screen",showPagination:t=!0,paginationStyle:n="dots",containerStyle:r,containerWidth:s})=>{const a=useTheme(),i="screen"===e?s||320:e;return _jsxs(View,{style:[carouselSkeletonStyles.container,r],children:[_jsx(Skeleton,{width:i,height:160,radius:"md"}),t?_jsx(View,{style:[carouselSkeletonStyles.paginationRow,{marginTop:a.space.md}],children:SKELETON_PAGINATION_DOTS.map(e=>_jsx(Skeleton,"numbers"===n?{width:24,height:16,radius:"sm",style:{marginHorizontal:a.space.xs}}:"bars"===n?{width:20,height:4,radius:"pill",style:{marginHorizontal:a.space.xxs}}:{shape:"circle",width:8,height:8,style:{marginHorizontal:a.space.xs}},e))}):null]})};CarouselSkeleton.displayName="CarouselSkeleton";const SKELETON_PAGINATION_DOTS=["first","second","third"],carouselSkeletonStyles=StyleSheet.create({container:{alignItems:"center"},paginationRow:{flexDirection:"row",justifyContent:"center"}}),Carousel=CarouselInner;Carousel.Skeleton=CarouselSkeleton;const Pagination=({count:e,currentIndex:t,scrollX:n,slideStride:r,variant:s,theme:a,labels:i})=>{const l=useMemo(()=>buildPaginationStyles(a),[a]);if("numbers"===s)return _jsx(View,{style:l.numbersWrap,children:_jsx(Text,{variant:"bodySmall",weight:"medium",color:"secondary",style:l.numbersText,accessibilityLabel:i.slideOf(t+1,e),children:`${t+1} / ${e}`})});const o=Array.from({length:e},(e,t)=>t),c="bars"===s,u=c?24:6,d=c?36:16,m=c?3:6;return _jsx(View,{style:l.dotRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o.map(e=>{const s=[(e-1)*r,e*r,(e+1)*r],i=n.interpolate({inputRange:s,outputRange:[u,d,u],extrapolate:"clamp"}),l=n.interpolate({inputRange:s,outputRange:[.5,1,.5],extrapolate:"clamp"});return _jsx(Animated.View,{style:[{width:i,height:m,marginHorizontal:a.space.xs,borderRadius:a.radius.pill,...smoothCorners,backgroundColor:e===t?a.colors.primary:a.colors.border,opacity:l}]},e)})})},ThumbnailStrip=({data:e,currentIndex:t,renderThumbnail:n,onSelect:r,theme:s,labels:a})=>{const i=useMemo(()=>buildThumbStyles(s),[s]);return _jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:i.row,accessibilityRole:"tablist",children:e.map((e,l)=>_jsx(ThumbnailItem,{item:e,index:l,isActive:l===t,renderThumbnail:n,onPress:()=>r(l),theme:s,styles:i,labels:a},l))})},ThumbnailItem=({item:e,index:t,isActive:n,renderThumbnail:r,onPress:s,theme:a,styles:i,labels:l})=>{const o=useRef(createAnimatedValue(n?1.1:1)).current;useEffect(()=>{const e=Animated.spring(o,{toValue:n?1.1:1,useNativeDriver:!0,friction:6,tension:80});return e.start(),()=>e.stop()},[n,o]);const c=useMemo(()=>r?r(e,t):e&&"object"==typeof e&&"uri"in e&&"string"==typeof e.uri?_jsx(Image,{source:{uri:e.uri},style:i.image,resizeMode:"cover"}):_jsx(View,{style:[i.placeholder,{backgroundColor:a.colors["bg-subtle"]}],children:_jsx(Text,{variant:"caption",weight:"semibold",color:"secondary",children:t+1})}),[e,t,r,a,i]);return _jsx(Pressable,{onPress:s,accessibilityRole:"tab",accessibilityState:{selected:n},"aria-selected":n,accessibilityLabel:l.goToSlide(t+1),children:_jsx(Animated.View,{style:[i.thumb,{borderColor:n?a.colors.primary:"transparent",transform:[{scale:o}]}],children:c})})},buildThumbStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",paddingHorizontal:e.space.sm,paddingVertical:e.space.sm},thumb:{width:40,height:40,marginHorizontal:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,overflow:"hidden"},image:{width:"100%",height:"100%"},placeholder:{flex:1,alignItems:"center",justifyContent:"center"}}),clamp=(e,t,n)=>Math.min(Math.max(e,t),n),buildStyles=e=>StyleSheet.create({container:{width:"100%"}}),buildPaginationStyles=e=>StyleSheet.create({dotRow:{flexDirection:"row",alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersWrap:{alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersText:{textAlign:"center"}});export{Carousel};export default Carousel;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,AppState,Dimensions,FlatList,Image,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,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{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_CAROUSEL_LABELS=Object.freeze({carousel:"Carousel",slideOf:(e,t)=>`Slide ${e} of ${t}`,goToSlide:e=>`Go to slide ${e}`});const CarouselInner=forwardRef((e,t)=>{const{data:n,renderItem:r,keyExtractor:i,index:s,defaultIndex:a=0,onIndexChange:l,onScrollOffsetChange:o,autoPlay:c=!1,autoPlayInterval:u=4e3,loop:d=!1,showPagination:m=!0,paginationStyle:h="dots",itemWidth:g="screen",spacing:b=0,containerStyle:p,accessibilityLabel:f,testID:x,showThumbnails:y=!1,haptic:S,renderThumbnail:v,loading:w=!1,labels:C}=e;assertValidValue("Carousel","paginationStyle",e.paginationStyle,["dots","bars","numbers"]);const T=useMemo(()=>({...DEFAULT_CAROUSEL_LABELS,...C}),[C]),j=useTheme(),I="number"==typeof s,k=d||c,[_,A]=useState(()=>Dimensions.get("window").width),E="screen"===g?_:g,R=E+b,V=useRef(null),L=useRef(createAnimatedValue(0)).current,D=clamp(I?s:a,0,Math.max(0,n.length-1)),[O,H]=useState(D),M=useRef(null),P=useRef(null),z=useRef(!1),N=useRef(O);N.current=O;const W=useCallback(e=>{const t=clamp(e,0,Math.max(0,n.length-1));H(e=>e===t?e:(l?.(t),t))},[n.length,l]),F=useCallback((e,t=!0)=>{if(0===n.length)return;const r=clamp(e,0,n.length-1);V.current?.scrollToOffset({offset:r*R,animated:t}),W(r)},[n.length,R,W]),$=useCallback(()=>{if(0===n.length)return;const e=N.current+1;e>=n.length?k&&F(0,!1):F(e,!0)},[n.length,k,F]),U=useCallback(()=>{if(0===n.length)return;const e=N.current-1;e<0?k&&F(n.length-1,!1):F(e,!0)},[n.length,k,F]);useImperativeHandle(t,()=>({scrollTo:F,next:$,prev:U}),[F,$,U]),useEffect(()=>{I&&s!==O&&F(s,!0)},[s]);const B=useCallback(()=>{M.current&&(clearInterval(M.current),M.current=null)},[]),G=useCallback(()=>{!c||n.length<=1||(B(),M.current=setInterval(()=>{if(z.current)return;const e=N.current+1;e>=n.length?F(0,!1):F(e,!0)},u))},[c,u,n.length,F,B]);useEffect(()=>(G(),()=>{B(),P.current&&clearTimeout(P.current)}),[G,B]),useEffect(()=>{const e=AppState.addEventListener("change",e=>{"active"!==e?(B(),P.current&&(clearTimeout(P.current),P.current=null)):G()});return()=>e.remove()},[G,B]);const K=m&&n.length>1&&"numbers"!==h||void 0!==o,X=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{x:L}}}],{useNativeDriver:!1,listener:o?e=>o(e.nativeEvent.contentOffset.x):void 0}),[L,o]),q=useCallback(e=>{if(R<=0)return;const t=e.nativeEvent.contentOffset.x,n=Math.round(t/R);W(n)},[R,W]),J=useCallback(()=>{z.current=!0,B(),P.current&&(clearTimeout(P.current),P.current=null)},[B]),Q=useCallback(()=>{z.current=!1,c&&(P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{G()},1e3))},[c,G]),Y=useCallback(e=>{switch(e.nativeEvent.actionName){case"increment":$();break;case"decrement":U()}},[$,U]),Z=useMemo(()=>buildStyles(j),[j]),ee=useCallback(({item:e,index:t})=>_jsx(View,{style:{width:E,marginRight:t===n.length-1?0:b},accessibilityElementsHidden:t!==O,importantForAccessibility:t===O?"yes":"no-hide-descendants",children:r(e,t)}),[r,E,b,n.length,O]),te=useCallback((e,t)=>String(t),[]),ne=useCallback((e,t)=>({length:R,offset:R*t,index:t}),[R]);return w?_jsx(CarouselSkeleton,{...e,containerWidth:_}):_jsxs(View,{style:[Z.container,p],onLayout:e=>A(e.nativeEvent.layout.width),accessibilityRole:"adjustable",accessibilityLabel:f??T.carousel,accessibilityValue:{min:0,max:Math.max(0,n.length-1),now:O,text:T.slideOf(O+1,n.length)},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Y,testID:x,children:[_jsx(FlatList,{ref:V,data:n,keyExtractor:i??te,renderItem:ee,horizontal:!0,pagingEnabled:"screen"===g&&0===b,snapToInterval:R,snapToAlignment:"start",decelerationRate:"fast",showsHorizontalScrollIndicator:!1,onScroll:K?X:void 0,scrollEventThrottle:K?16:void 0,onMomentumScrollEnd:q,onScrollBeginDrag:J,onScrollEndDrag:Q,getItemLayout:ne,initialScrollIndex:D,bounces:!1}),m&&n.length>1?_jsx(Pagination,{count:n.length,currentIndex:O,scrollX:L,slideStride:R,variant:h,theme:j,labels:T}):null,y&&n.length>0?_jsx(ThumbnailStrip,{data:n,currentIndex:O,renderThumbnail:v,labels:T,onSelect:e=>{const t=resolveHaptic(S,"selection");t&&triggerHaptic(t),F(e,!0)},theme:j}):null]})});CarouselInner.displayName="Carousel";const CarouselSkeleton=({itemWidth:e="screen",showPagination:t=!0,paginationStyle:n="dots",containerStyle:r,containerWidth:i})=>{const s=useTheme(),a="screen"===e?i||320:e;return _jsxs(View,{style:[carouselSkeletonStyles.container,r],children:[_jsx(Skeleton,{width:a,height:160,radius:"md"}),t?_jsx(View,{style:[carouselSkeletonStyles.paginationRow,{marginTop:s.space.md}],children:SKELETON_PAGINATION_DOTS.map(e=>_jsx(Skeleton,"numbers"===n?{width:24,height:16,radius:"sm",style:{marginHorizontal:s.space.xs}}:"bars"===n?{width:20,height:4,radius:"pill",style:{marginHorizontal:s.space.xxs}}:{shape:"circle",width:8,height:8,style:{marginHorizontal:s.space.xs}},e))}):null]})};CarouselSkeleton.displayName="CarouselSkeleton";const SKELETON_PAGINATION_DOTS=["first","second","third"],carouselSkeletonStyles=StyleSheet.create({container:{alignItems:"center"},paginationRow:{flexDirection:"row",justifyContent:"center"}}),Carousel=CarouselInner;Carousel.Skeleton=CarouselSkeleton;const Pagination=({count:e,currentIndex:t,scrollX:n,slideStride:r,variant:i,theme:s,labels:a})=>{const l=useMemo(()=>buildPaginationStyles(s),[s]);if("numbers"===i)return _jsx(View,{style:l.numbersWrap,children:_jsx(Text,{variant:"bodySmall",weight:"medium",color:"secondary",style:l.numbersText,accessibilityLabel:a.slideOf(t+1,e),children:`${t+1} / ${e}`})});const o=Array.from({length:e},(e,t)=>t),c="bars"===i,u=c?24:6,d=c?36:16,m=c?3:6;return _jsx(View,{style:l.dotRow,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o.map(e=>{const i=[(e-1)*r,e*r,(e+1)*r],a=n.interpolate({inputRange:i,outputRange:[u,d,u],extrapolate:"clamp"}),l=n.interpolate({inputRange:i,outputRange:[.5,1,.5],extrapolate:"clamp"});return _jsx(Animated.View,{style:[{width:a,height:m,marginHorizontal:s.space.xs,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:e===t?s.colors.primary:s.colors.border,opacity:l}]},e)})})},ThumbnailStrip=({data:e,currentIndex:t,renderThumbnail:n,onSelect:r,theme:i,labels:s})=>{const a=useMemo(()=>buildThumbStyles(i),[i]);return _jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:a.row,accessibilityRole:"tablist",children:e.map((e,l)=>_jsx(ThumbnailItem,{item:e,index:l,isActive:l===t,renderThumbnail:n,onPress:()=>r(l),theme:i,styles:a,labels:s},l))})},ThumbnailItem=({item:e,index:t,isActive:n,renderThumbnail:r,onPress:i,theme:s,styles:a,labels:l})=>{const o=useRef(createAnimatedValue(n?1.1:1)).current;useEffect(()=>{const e=Animated.spring(o,{toValue:n?1.1:1,useNativeDriver:nativeDriver,friction:6,tension:80});return e.start(),()=>e.stop()},[n,o]);const c=useMemo(()=>r?r(e,t):e&&"object"==typeof e&&"uri"in e&&"string"==typeof e.uri?_jsx(Image,{source:{uri:e.uri},style:a.image,resizeMode:"cover"}):_jsx(View,{style:[a.placeholder,{backgroundColor:s.colors["bg-subtle"]}],children:_jsx(Text,{variant:"caption",weight:"semibold",color:"secondary",children:t+1})}),[e,t,r,s,a]);return _jsx(Pressable,{onPress:i,accessibilityRole:"tab",accessibilityState:{selected:n},"aria-selected":n,accessibilityLabel:l.goToSlide(t+1),children:_jsx(Animated.View,{style:[a.thumb,{borderColor:n?s.colors.primary:"transparent",transform:[{scale:o}]}],children:c})})},buildThumbStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center",paddingHorizontal:e.space.sm,paddingVertical:e.space.sm},thumb:{width:40,height:40,marginHorizontal:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,overflow:"hidden"},image:{width:"100%",height:"100%"},placeholder:{flex:1,alignItems:"center",justifyContent:"center"}}),clamp=(e,t,n)=>Math.min(Math.max(e,t),n),buildStyles=e=>StyleSheet.create({container:{width:"100%"}}),buildPaginationStyles=e=>StyleSheet.create({dotRow:{flexDirection:"row",alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersWrap:{alignItems:"center",justifyContent:"center",paddingVertical:e.space.md},numbersText:{textAlign:"center"}});export{Carousel};export default Carousel;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveCheckboxSize,spaceOf,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{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 CHECKBOX_SHAPES=["circle"],toneColor=(e,r)=>{switch(r){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}},toneOnColor=(e,r)=>{switch(r){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"]}},Checkbox=forwardRef((e,r)=>{const{checked:t,defaultChecked:s,onChange:o,indeterminate:i=!1,disabled:a=!1,label:l,helperText:n,description:c,error:d,help:h,size:u="md",tone:p="primary",shape:m,accessibilityLabel:x,haptic:f,style:b,boxStyle:g,indeterminateBarStyle:y,containerStyle:C,labelStyle:S,testID:w,hitSlop:k,...j}=e,[V,T]=useControllableState({value:t,defaultValue:s??!1,onChange:o}),v=useTheme(),_=useMemo(()=>buildStyles(v),[v]),{"box-size":R}=useMemo(()=>resolveCheckboxSize(v,u),[v,u]),A=v.size.border,H=spaceOf(v,v.components.checkbox["label-gap"]),M=toneColor(v,p),D=k??6;assertValidValue("Checkbox","shape",m,CHECKBOX_SHAPES),assertValidValue("Checkbox","size",e.size,["sm","md","lg"]),assertValidValue("Checkbox","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const P="circle"===m,z="string"==typeof d?d:void 0,B={description:c,helperText:n,error:z},F=V||i,I=useRef(createAnimatedValue(F?1:0)).current;useEffect(()=>{const e=Animated.spring(I,{toValue:F?1:0,damping:v.motion.spring.snappy.damping,stiffness:v.motion.spring.snappy.stiffness,mass:v.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[F,I,v.motion.spring.snappy]);const L=I.interpolate({inputRange:[0,1],outputRange:[0,1]}),O=x??fieldTextAsString(l),E=!0===d||hasFieldText(d),W=F?M:a?v.colors.border:E?v.colors["field-border-error"]:v.colors.border,K=F?M:a?v.colors["surface-disabled"]:"transparent",N=a&&!F?v.colors["text-disabled"]:toneOnColor(v,p),X=Math.round(.72*R),U=Math.round(.55*R),q=Math.max(2,Math.round(.12*R)),G=_jsxs(Pressable,{ref:r,onPress:e=>{if(a)return;const r=resolveHaptic(f,"selection");r&&triggerHaptic(r),T(!V),j.onPressOut?.(e)},disabled:a,accessibilityRole:"checkbox",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(n??c),accessibilityState:{checked:i?"mixed":V,disabled:a},"aria-checked":i?"mixed":V,"aria-disabled":a,testID:w,hitSlop:D,...hitSlopMarker(D),...j,style:({pressed:e})=>[_.row,hasChoiceDetail(B)?_.rowTop:null,hasFieldText(h)?_.rowShrink:null,{opacity:a?.55:e?.85:1},C,b],children:[_jsx(View,{style:[_.box,{width:R,height:R,borderWidth:A,borderRadius:P?R/2:v.radius.sm,...P?{}:smoothCorners,borderColor:W,backgroundColor:K},g],children:_jsx(Animated.View,{style:[_.glyphWrap,{opacity:I,transform:[{scale:L}]}],children:i?_jsx(View,{style:[{width:U,height:q,borderRadius:v.radius.pill,...smoothCorners,backgroundColor:N},y]}):_jsx(Svg,{width:X,height:X,viewBox:"0 0 24 24",children:_jsx(Path,{d:"M5 12.5l4.5 4.5L19 7.5",stroke:N,strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}),_jsx(ChoiceText,{label:l,helperText:n,description:c,error:z,disabled:a,style:{marginLeft:H},labelStyle:S})]});return hasFieldText(h)?_jsxs(View,{style:[_.helpRow,hasChoiceDetail(B)?_.rowTop:null],children:[G,_jsx(View,{style:[_.help,{marginLeft:v.space.xs}],children:h})]}):G});Checkbox.displayName="Checkbox";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"},rowShrink:{flexShrink:1},helpRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},box:{alignItems:"center",justifyContent:"center"},glyphWrap:{alignItems:"center",justifyContent:"center"}});export{Checkbox};export default Checkbox;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveCheckboxSize,spaceOf,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{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 CHECKBOX_SHAPES=["circle"],toneColor=(e,r)=>{switch(r){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}},toneOnColor=(e,r)=>{switch(r){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"]}},Checkbox=forwardRef((e,r)=>{const{checked:t,defaultChecked:s,onChange:o,indeterminate:i=!1,disabled:a=!1,label:l,helperText:n,description:c,error:d,help:h,size:u="md",tone:p="primary",shape:m,accessibilityLabel:f,haptic:x,style:b,boxStyle:g,indeterminateBarStyle:y,containerStyle:C,labelStyle:S,testID:w,hitSlop:k,...j}=e,[v,V]=useControllableState({value:t,defaultValue:s??!1,onChange:o}),T=useTheme(),_=useMemo(()=>buildStyles(T),[T]),{"box-size":D}=useMemo(()=>resolveCheckboxSize(T,u),[T,u]),R=T.size.border,A=spaceOf(T,T.components.checkbox["label-gap"]),H=toneColor(T,p),M=k??6;assertValidValue("Checkbox","shape",m,CHECKBOX_SHAPES),assertValidValue("Checkbox","size",e.size,["sm","md","lg"]),assertValidValue("Checkbox","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const P="circle"===m,z="string"==typeof d?d:void 0,B={description:c,helperText:n,error:z},F=v||i,I=useRef(createAnimatedValue(F?1:0)).current;useEffect(()=>{const e=Animated.spring(I,{toValue:F?1:0,damping:T.motion.spring.snappy.damping,stiffness:T.motion.spring.snappy.stiffness,mass:T.motion.spring.snappy.mass,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[F,I,T.motion.spring.snappy]);const L=I.interpolate({inputRange:[0,1],outputRange:[0,1]}),O=f??fieldTextAsString(l),E=!0===d||hasFieldText(d),W=F?H:a?T.colors.border:E?T.colors["field-border-error"]:T.colors.border,K=F?H:a?T.colors["surface-disabled"]:"transparent",N=a&&!F?T.colors["text-disabled"]:toneOnColor(T,p),X=Math.round(.72*D),U=Math.round(.55*D),q=Math.max(2,Math.round(.12*D)),G=_jsxs(Pressable,{ref:r,onPress:e=>{if(a)return;const r=resolveHaptic(x,"selection");r&&triggerHaptic(r),V(!v),j.onPressOut?.(e)},disabled:a,accessibilityRole:"checkbox",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(n??c),accessibilityState:{checked:i?"mixed":v,disabled:a},"aria-checked":i?"mixed":v,"aria-disabled":a,testID:w,hitSlop:M,...hitSlopMarker(M),...j,style:({pressed:e})=>[_.row,hasChoiceDetail(B)?_.rowTop:null,hasFieldText(h)?_.rowShrink:null,{opacity:a?.55:e?.85:1},C,b],children:[_jsx(View,{style:[_.box,{width:D,height:D,borderWidth:R,borderRadius:P?D/2:T.radius.sm,...P?{}:smoothCorners,borderColor:W,backgroundColor:K},g],children:_jsx(Animated.View,{style:[_.glyphWrap,{opacity:I,transform:[{scale:L}]}],children:i?_jsx(View,{style:[{width:U,height:q,borderRadius:T.radius.pill,...smoothCorners,backgroundColor:N},y]}):_jsx(Svg,{width:X,height:X,viewBox:"0 0 24 24",children:_jsx(Path,{d:"M5 12.5l4.5 4.5L19 7.5",stroke:N,strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}),_jsx(ChoiceText,{label:l,helperText:n,description:c,error:z,disabled:a,style:{marginLeft:A},labelStyle:S})]});return hasFieldText(h)?_jsxs(View,{style:[_.helpRow,hasChoiceDetail(B)?_.rowTop:null],children:[G,_jsx(View,{style:[_.help,{marginLeft:T.space.xs}],children:h})]}):G});Checkbox.displayName="Checkbox";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"},rowShrink:{flexShrink:1},helpRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},box:{alignItems:"center",justifyContent:"center"},glyphWrap:{alignItems:"center",justifyContent:"center"}});export{Checkbox};export default Checkbox;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useState}from"react";import{StyleSheet,useWindowDimensions,View}from"react-native";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withRepeat,withTiming}from"react-native-reanimated";import Svg,{Path,Polygon}from"react-native-svg";import{useReducedMotion}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx}from"react/jsx-runtime";const TAU=2*Math.PI,DEG=Math.PI/180,SPEED_FACTOR={slow:1.6,normal:1,fast:.6};export const DEFAULT_PHYSICS={velocity:1,drag:1,fallSpeed:1,spread:0};const PRESET_SHAPES={pop:["strip","strip","strip","square","circle","triangle","star","streamer"],rain:["strip","strip","strip","circle","square"],fireworks:["circle","circle","star","star","triangle","strip"]},rand=(e,a)=>e+Math.random()*(a-e),pick=e=>e[Math.floor(Math.random()*e.length)]??e[0],commonPiece=(e,a)=>({color:e.colors[a%e.colors.length]??e.colors[0],size:e.baseSize*rand(.6,1.4),shape:pick(e.shapes),rotations:rand(1,5),rotateDir:Math.random()<.5?1:-1,flutterFreq:rand(2,5)}),popPiece=(e,a)=>{const r=e.physics.spread>0?e.physics.spread/2:100,t=(-90+rand(-r,r))*DEG,s=rand(1.8,4.2)*e.physics.velocity;return{...commonPiece(e,a),x0Frac:e.originXFrac,y0Frac:e.originYFrac,vxFrac:Math.cos(t)*s*.7,vyFrac:Math.sin(t)*s,drag:rand(5.5,7.5)*e.physics.drag,terminalFrac:rand(.22,.44)*e.physics.fallSpeed,delay:rand(0,.05),swayAmp:rand(4,16),swayFreq:rand(1,3)}},rainPiece=(e,a)=>({...commonPiece(e,a),x0Frac:Math.random(),y0Frac:-.05,vxFrac:rand(-.12,.12)*e.physics.velocity,vyFrac:rand(.05,.25)*e.physics.velocity,drag:rand(2.5,4)*e.physics.drag,terminalFrac:rand(.95,1.35)*e.physics.fallSpeed,delay:rand(0,.35),swayAmp:rand(10,30),swayFreq:rand(1,3)}),FIREWORK_BURSTS=4,buildFireworks=(e,a)=>{const r=Math.max(1,Math.round(e/4)),t=a.physics.spread>0?a.physics.spread/2:180,s=[];for(let i=0;i<4&&s.length<e;i+=1){const o=rand(.18,.82),n=rand(.18,.52),c=i/4*.5+rand(0,.06);for(let i=0;i<r&&s.length<e;i+=1){const e=rand(-t,t)*DEG,r=rand(1.4,3.4)*a.physics.velocity;s.push({...commonPiece(a,s.length),x0Frac:o,y0Frac:n,vxFrac:Math.cos(e)*r*.7,vyFrac:Math.sin(e)*r,drag:rand(6.5,8.5)*a.physics.drag,terminalFrac:rand(.18,.38)*a.physics.fallSpeed,delay:c,swayAmp:rand(3,12),swayFreq:rand(1,3)})}}return s};export const buildPieces=(e,a,r)=>{if("fireworks"===a)return buildFireworks(e,r);const t="rain"===a?rainPiece:popPiece;return Array.from({length:e},(e,a)=>t(r,a))};const SHAPE_BOX={strip:{w:1,h:.45},square:{w:1,h:1},circle:{w:1,h:1},triangle:{w:1,h:1},star:{w:1.2,h:1.2},streamer:{w:3,h:1.2}},TRIANGLE_POINTS="50,4 96,96 4,96",STAR_POINTS="50,2 61,36 97,36 68,58 79,94 50,72 21,94 32,58 3,36 39,36",STREAMER_PATH="M2,50 C20,6 44,94 62,50 S92,6 98,50",ShapeBody=({shape:e,color:a})=>"triangle"===e||"star"===e?_jsx(Svg,{width:"100%",height:"100%",viewBox:"0 0 100 100",children:_jsx(Polygon,{points:"star"===e?STAR_POINTS:TRIANGLE_POINTS,fill:a})}):"streamer"===e?_jsx(Svg,{width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",children:_jsx(Path,{d:STREAMER_PATH,stroke:a,strokeWidth:22,strokeLinecap:"round",fill:"none"})}):null,ConfettiPiece=({piece:e,progress:a,width:r,height:t,fadeOut:s})=>{const i=useAnimatedStyle(()=>{const i=1-e.delay,o=i<=0?0:Math.min(1,Math.max(0,(a.value-e.delay)/i)),n=(1-Math.exp(-e.drag*o))/e.drag,c=e.x0Frac*r+e.vxFrac*r*n,l=e.y0Frac*t+e.terminalFrac*t*o+(e.vyFrac-e.terminalFrac)*t*n,h=Math.sin(o*e.swayFreq*TAU)*e.swayAmp,d=e.rotateDir*e.rotations*360*o,p=.35+.65*Math.abs(Math.cos(o*e.flutterFreq*TAU));return{opacity:s?Math.max(0,1-Math.max(0,o-.75)/.25):1,transform:[{translateX:c+h},{translateY:l},{rotate:`${d}deg`},{scaleY:p}]}},[e,a,r,t,s]),o=SHAPE_BOX[e.shape],n="triangle"===e.shape||"star"===e.shape||"streamer"===e.shape;return _jsx(Animated.View,{style:[{position:"absolute",width:e.size*o.w,height:e.size*o.h,borderRadius:"circle"===e.shape?e.size*o.h/2:1,backgroundColor:n?"transparent":e.color},i],children:_jsx(ShapeBody,{shape:e.shape,color:e.color})})},Confetti=forwardRef(({count:e=80,colors:a,preset:r="pop",shapes:t,speed:s="normal",physics:i,origin:o,duration:n=2800,fadeOut:c=!0,autoStart:l=!1,recycle:h=!1,size:d=10,onComplete:p,style:u,testID:m},y)=>{assertValidValue("Confetti","preset",r,["pop","rain","fireworks"]),assertValidValue("Confetti","speed",s,["slow","normal","fast"]);for(const e of t??[])assertValidValue("Confetti","shapes",e,["strip","square","circle","triangle","star","streamer"]);const g=useTheme(),f=useReducedMotion(),S=useWindowDimensions(),[w,F]=useState({width:S.width,height:S.height}),[x,P]=useState(!1),[A,v]=useState([]),E=useMemo(()=>a??[g.colors.primary,g.colors.neutral,g.colors.success,g.colors.warning,g.colors.danger,g.colors.info],[a,g.colors]),M=useSharedValue(0),T=n*SPEED_FACTOR[s],_=useCallback(()=>{P(!1),p?.()},[p]),R=useCallback(()=>{if(f)return void p?.();cancelAnimation(M),M.value=0,v(buildPieces(e,r,{colors:E,baseSize:d,originXFrac:o?o.x/Math.max(1,w.width):.5,originYFrac:o?o.y/Math.max(1,w.height):.5,physics:{...DEFAULT_PHYSICS,...i},shapes:t??PRESET_SHAPES[r]})),P(!0);const a=withTiming(1,{duration:T,easing:Easing.linear},e=>{"worklet";e&&!h&&runOnJS(_)()});M.value=h?withRepeat(a,-1,!1):a},[f,M,T,h,_,p,e,E,r,t,i,d,o,w.width,w.height]),C=useCallback(()=>{cancelAnimation(M),P(!1)},[M]);useImperativeHandle(y,()=>({start:R,stop:C}),[R,C]),useEffect(()=>(l&&R(),()=>cancelAnimation(M)),[]);const k=useCallback(e=>{const{width:a,height:r}=e.nativeEvent.layout;a>0&&r>0&&F({width:a,height:r})},[]);return _jsx(View,{style:[StyleSheet.absoluteFill,u],pointerEvents:"none",onLayout:k,testID:m,children:x?A.map((e,a)=>_jsx(ConfettiPiece,{piece:e,progress:M,width:w.width,height:w.height,fadeOut:c},a)):null})});Confetti.displayName="Confetti";export{Confetti};export default Confetti;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useState}from"react";import{StyleSheet,useWindowDimensions,View}from"react-native";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withRepeat,withTiming}from"react-native-reanimated";import Svg,{Path,Polygon}from"react-native-svg";import{useReducedMotion}from"../../hooks/index.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx}from"react/jsx-runtime";const TAU=2*Math.PI,DEG=Math.PI/180,SPEED_FACTOR={slow:1.6,normal:1,fast:.6};export const DEFAULT_PHYSICS={velocity:1,drag:1,fallSpeed:1,spread:0};const PRESET_SHAPES={pop:["strip","strip","strip","square","circle","triangle","star","streamer"],rain:["strip","strip","strip","circle","square"],fireworks:["circle","circle","star","star","triangle","strip"]},rand=(e,a)=>e+Math.random()*(a-e),itemAt=(e,a,r)=>{const t=e[a];if(void 0===t)throw new Error(`Confetti needs at least one ${r}`);return t},pick=e=>itemAt(e,Math.floor(Math.random()*e.length),"shape"),commonPiece=(e,a)=>({color:itemAt(e.colors,a%e.colors.length,"colour"),size:e.baseSize*rand(.6,1.4),shape:pick(e.shapes),rotations:rand(1,5),rotateDir:Math.random()<.5?1:-1,flutterFreq:rand(2,5)}),popPiece=(e,a)=>{const r=e.physics.spread>0?e.physics.spread/2:100,t=(-90+rand(-r,r))*DEG,s=rand(1.8,4.2)*e.physics.velocity;return{...commonPiece(e,a),x0Frac:e.originXFrac,y0Frac:e.originYFrac,vxFrac:Math.cos(t)*s*.7,vyFrac:Math.sin(t)*s,drag:rand(5.5,7.5)*e.physics.drag,terminalFrac:rand(.22,.44)*e.physics.fallSpeed,delay:rand(0,.05),swayAmp:rand(4,16),swayFreq:rand(1,3)}},rainPiece=(e,a)=>({...commonPiece(e,a),x0Frac:Math.random(),y0Frac:-.05,vxFrac:rand(-.12,.12)*e.physics.velocity,vyFrac:rand(.05,.25)*e.physics.velocity,drag:rand(2.5,4)*e.physics.drag,terminalFrac:rand(.95,1.35)*e.physics.fallSpeed,delay:rand(0,.35),swayAmp:rand(10,30),swayFreq:rand(1,3)}),FIREWORK_BURSTS=4,buildFireworks=(e,a)=>{const r=Math.max(1,Math.round(e/4)),t=a.physics.spread>0?a.physics.spread/2:180,s=[];for(let i=0;i<4&&s.length<e;i+=1){const o=rand(.18,.82),n=rand(.18,.52),c=i/4*.5+rand(0,.06);for(let i=0;i<r&&s.length<e;i+=1){const e=rand(-t,t)*DEG,r=rand(1.4,3.4)*a.physics.velocity;s.push({...commonPiece(a,s.length),x0Frac:o,y0Frac:n,vxFrac:Math.cos(e)*r*.7,vyFrac:Math.sin(e)*r,drag:rand(6.5,8.5)*a.physics.drag,terminalFrac:rand(.18,.38)*a.physics.fallSpeed,delay:c,swayAmp:rand(3,12),swayFreq:rand(1,3)})}}return s};export const buildPieces=(e,a,r)=>{if("fireworks"===a)return buildFireworks(e,r);const t="rain"===a?rainPiece:popPiece;return Array.from({length:e},(e,a)=>t(r,a))};const SHAPE_BOX={strip:{w:1,h:.45},square:{w:1,h:1},circle:{w:1,h:1},triangle:{w:1,h:1},star:{w:1.2,h:1.2},streamer:{w:3,h:1.2}},TRIANGLE_POINTS="50,4 96,96 4,96",STAR_POINTS="50,2 61,36 97,36 68,58 79,94 50,72 21,94 32,58 3,36 39,36",STREAMER_PATH="M2,50 C20,6 44,94 62,50 S92,6 98,50",ShapeBody=({shape:e,color:a})=>"triangle"===e||"star"===e?_jsx(Svg,{width:"100%",height:"100%",viewBox:"0 0 100 100",children:_jsx(Polygon,{points:"star"===e?STAR_POINTS:TRIANGLE_POINTS,fill:a})}):"streamer"===e?_jsx(Svg,{width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",children:_jsx(Path,{d:STREAMER_PATH,stroke:a,strokeWidth:22,strokeLinecap:"round",fill:"none"})}):null,ConfettiPiece=({piece:e,progress:a,width:r,height:t,fadeOut:s})=>{const i=useAnimatedStyle(()=>{const i=1-e.delay,o=i<=0?0:Math.min(1,Math.max(0,(a.value-e.delay)/i)),n=(1-Math.exp(-e.drag*o))/e.drag,c=e.x0Frac*r+e.vxFrac*r*n,l=e.y0Frac*t+e.terminalFrac*t*o+(e.vyFrac-e.terminalFrac)*t*n,h=Math.sin(o*e.swayFreq*TAU)*e.swayAmp,d=e.rotateDir*e.rotations*360*o,p=.35+.65*Math.abs(Math.cos(o*e.flutterFreq*TAU));return{opacity:s?Math.max(0,1-Math.max(0,o-.75)/.25):1,transform:[{translateX:c+h},{translateY:l},{rotate:`${d}deg`},{scaleY:p}]}},[e,a,r,t,s]),o=SHAPE_BOX[e.shape],n="triangle"===e.shape||"star"===e.shape||"streamer"===e.shape;return _jsx(Animated.View,{style:[{position:"absolute",width:e.size*o.w,height:e.size*o.h,borderRadius:"circle"===e.shape?e.size*o.h/2:1,backgroundColor:n?"transparent":e.color},i],children:_jsx(ShapeBody,{shape:e.shape,color:e.color})})},Confetti=forwardRef(({count:e=80,colors:a,preset:r="pop",shapes:t,speed:s="normal",physics:i,origin:o,duration:n=2800,fadeOut:c=!0,autoStart:l=!1,recycle:h=!1,size:d=10,onComplete:p,style:u,testID:m},y)=>{assertValidValue("Confetti","preset",r,["pop","rain","fireworks"]),assertValidValue("Confetti","speed",s,["slow","normal","fast"]);for(const e of t??[])assertValidValue("Confetti","shapes",e,["strip","square","circle","triangle","star","streamer"]);const f=useTheme(),g=useReducedMotion(),w=useWindowDimensions(),[S,F]=useState({width:w.width,height:w.height}),[A,x]=useState(!1),[P,v]=useState([]),E=useMemo(()=>a??[f.colors.primary,f.colors.neutral,f.colors.success,f.colors.warning,f.colors.danger,f.colors.info],[a,f.colors]),M=useSharedValue(0),T=n*SPEED_FACTOR[s],_=useCallback(()=>{x(!1),p?.()},[p]),C=useCallback(()=>{if(g)return void p?.();cancelAnimation(M),M.value=0,v(buildPieces(e,r,{colors:E,baseSize:d,originXFrac:o?o.x/Math.max(1,S.width):.5,originYFrac:o?o.y/Math.max(1,S.height):.5,physics:{...DEFAULT_PHYSICS,...i},shapes:t??PRESET_SHAPES[r]})),x(!0);const a=withTiming(1,{duration:T,easing:Easing.linear},e=>{"worklet";e&&!h&&runOnJS(_)()});M.value=h?withRepeat(a,-1,!1):a},[g,M,T,h,_,p,e,E,r,t,i,d,o,S.width,S.height]),R=useCallback(()=>{cancelAnimation(M),x(!1)},[M]);useImperativeHandle(y,()=>({start:C,stop:R}),[C,R]),useEffect(()=>(l&&C(),()=>cancelAnimation(M)),[]);const k=useCallback(e=>{const{width:a,height:r}=e.nativeEvent.layout;a>0&&r>0&&F({width:a,height:r})},[]);return _jsx(View,{style:[StyleSheet.absoluteFill,u],pointerEvents:"none",onLayout:k,testID:m,children:A?P.map((e,a)=>_jsx(ConfettiPiece,{piece:e,progress:M,width:S.width,height:S.height,fadeOut:c},a)):null})});Confetti.displayName="Confetti";export{Confetti};export default Confetti;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Calendar}from"../Calendar/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const NAV_BUTTON_SIZE=36;export const DEFAULT_DATE_PICKER_LABELS=Object.freeze({title:"Select Date",confirm:"Confirm",cancel:"Cancel",dismiss:"Dismiss",previousMonth:"Previous month",nextMonth:"Next month",previousYears:"Previous years",nextYears:"Next years",previousDecades:"Previous decades",nextDecades:"Next decades",switchToYears:"switch to year selection",switchToDecades:"switch to decade selection",year:e=>`Year ${e}`,decade:(e,t)=>`Decade ${e} to ${t}`});const GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:s,minDate:r,maxDate:i,disabledDates:o,inline:l=!1,locale:n="en-IN",weekStartsOn:c=0,title:d,labels:u,style:g,containerStyle:m,headerLabelStyle:h,navButtonStyle:y,footerButtonStyle:b,haptic:p,testID:x,label:f,help:D,placeholder:v,helperText:w,error:C,required:j,disabled:S,size:_,variant:T,clearable:M,onClear:R,leftIcon:P,trailing:k,triggerStyle:A,valueStyle:I,labelStyle:V,messageStyle:L,accessibilityLabel:B,triggerLabels:E,formatValue:F}=e,Y=l?"inline":"modal",z=useMemo(()=>u?{...DEFAULT_DATE_PICKER_LABELS,...u}:DEFAULT_DATE_PICKER_LABELS,[u]),H=void 0!==e.open,[$,N]=useState(!1),O=H?e.open:$,W=H?x:x?`${x}-calendar`:void 0,G=useTheme(),U=usePresenceMotion(),[q,K]=useModalInsets(),Z=useMemo(()=>buildStyles(G),[G]),[X,J]=useState(()=>startOfDay(new Date));useEffect(()=>{O&&J(startOfDay(new Date))},[O]);const Q=t?startOfDay(t):X,[ee,te]=useState(Q),[ae,se]=useState(t?startOfDay(t):null),[re,ie]=useState("days"),oe=useRef(createAnimatedValue(0)).current,le=useRef(0),ne=useRef(createAnimatedValue(1)).current,ce=useRef(createAnimatedValue(1)).current,de=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(t){const e=startOfDay(t);se(e),te(e)}else se(null)},[t]);const ue=useMemo(()=>r?startOfDay(r):null,[r]),ge=useMemo(()=>i?startOfDay(i):null,[i]),me=useMemo(()=>buildYearCells(ee.getFullYear()),[ee]),he=useMemo(()=>buildDecadeCells(ee.getFullYear()),[ee]),ye=useMemo(()=>{if("years"===re){return`${me[0]} - ${me[me.length-1]}`}return`${he[0]} - ${he[he.length-1]+9}`},[he,re,me]),be=useCallback(e=>!!(ue&&e<ue.getFullYear())||!!(ge&&e>ge.getFullYear()),[ue,ge]),pe=useCallback(e=>!!(ue&&e+10-1<ue.getFullYear())||!!(ge&&e>ge.getFullYear()),[ue,ge]),xe=useCallback(()=>{!1!==p&&triggerHaptic("impactLight"),te("years"===re?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))},[re,p]),fe=useCallback(()=>{!1!==p&&triggerHaptic("impactLight"),te("years"===re?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))},[re,p]),De=useCallback(()=>{const[e]=U.range(.9,1),t=U.reduced?U.duration("default"):G.motion.duration.default;setNativeValue(ne,0),setNativeValue(ce,e),Animated.parallel([Animated.timing(ne,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ce,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0})]).start()},[ne,ce,U,G.motion.duration.default]),ve=useCallback(()=>{const e=resolveHaptic(p,"selection");if(e&&triggerHaptic(e),!U.reduced){const e=80,t=100;Animated.sequence([Animated.timing(de,{toValue:.96,duration:e,useNativeDriver:!0}),Animated.timing(de,{toValue:1,duration:t,useNativeDriver:!0})]).start()}ie(e=>"days"===e?"years":"years"===e?"decades":"years"),De()},[De,de,p,U.reduced]),we=useCallback(e=>{const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),te(t=>new Date(e,t.getMonth(),1)),ie("days"),De()},[De,p]),Ce=useCallback(e=>{const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),te(t=>new Date(e+4,t.getMonth(),1)),ie("years"),De()},[De,p]),je=useCallback(e=>{se(e.start)},[]),Se=useCallback(()=>{H||N(!1),s?.()},[H,s]),{handleGesture:Te,opacity:Me}=useDragToDismiss({drag:oe,travel:()=>le.current||320,onDismiss:Se});useEffect(()=>{O&&"modal"===Y&&(setNativeValue(oe,0),setNativeValue(Me,1))},[O,Y,oe,Me]);const Re=useCallback(()=>{!1!==p&&triggerHaptic("selection"),Se()},[Se,p]),Pe=useCallback(()=>{ae&&(!1!==p&&triggerHaptic("notificationSuccess"),a?.(ae),Se())},[Se,a,ae,p]),ke=_jsx(View,{style:Z.titleRow,children:_jsx(Text,{style:Z.title,variant:"title",accessibilityRole:"header",children:d??z.title})}),Ae=_jsxs(View,{style:[Z.card,m,g],accessibilityRole:"modal"===Y?void 0:"none",accessible:!1,testID:W,children:["modal"===Y?_jsx(GestureDetector,{gesture:Te,children:_jsxs(View,{style:Z.grabArea,children:[_jsx(View,{style:Z.handle}),ke]})}):ke,"days"!==re?_jsxs(View,{style:Z.headerRow,children:[_jsx(Pressable,{onPress:xe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"years"===re?z.previousYears:z.previousDecades,hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:Z.navText,variant:"title",children:"‹"})}),_jsx(Pressable,{onPress:ve,style:[Z.headerLabelWrap,h],accessibilityRole:"button",accessibilityLabel:`${ye}, ${"years"===re?z.switchToDecades:z.switchToYears}`,hitSlop:8,...hitSlopMarker(8),children:_jsxs(Animated.View,{style:[Z.headerLabelInner,{transform:[{scale:de}]}],children:[_jsx(Animated.Text,{style:[Z.headerLabel,{transform:[{translateX:0}]}],accessibilityLiveRegion:"polite",children:ye}),_jsx(View,{style:Z.headerCaret,children:(G.settings.icons.chevronDown??defaultIcons.chevronDown)({size:G.text.sm.size,color:G.colors["text-muted"]})})]})}),_jsx(Pressable,{onPress:fe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"years"===re?z.nextYears:z.nextDecades,hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:Z.navText,variant:"title",children:"›"})})]}):null,"days"===re?_jsx(Calendar,{selectionMode:"single",value:ae?{start:ae}:null,onChange:je,month:ee,onMonthChange:te,minDate:r,maxDate:i,disabledDates:o,weekStartsOn:c,locale:n,haptic:p,headerLabelStyle:h,navButtonStyle:y,onTitlePress:ve,labels:{previousMonth:z.previousMonth,nextMonth:z.nextMonth},testID:W?`${W}-grid`:void 0}):_jsx(Animated.View,"years"===re?{style:[Z.yearGrid,{opacity:ne,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>me.slice(4*t,4*t+4)).map(e=>_jsx(View,{style:Z.gridRow,children:e.map(e=>{const t=be(e),a=!!ae&&ae.getFullYear()===e,s=X.getFullYear()===e,r=a?G.colors.primary:"transparent",i=s&&!a?G.colors.primary:"transparent",o=a?G.colors["on-primary"]:t?G.colors["text-disabled"]:G.colors["text-body"],l=t?.3:1;return _jsx(Pressable,{disabled:t,onPress:()=>we(e),accessibilityRole:"button",accessibilityLabel:z.year(e),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:Z.yearCell,children:_jsx(View,{style:[Z.yearInner,{backgroundColor:r,borderColor:i,borderWidth:s&&!a?1.5:0,opacity:l}],children:_jsx(Text,{style:[Z.yearText,{color:o}],variant:"body",children:e})})},`year-${e}`)})},`yr-${e[0]}`))}:{style:[Z.yearGrid,{opacity:ne,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>he.slice(4*t,4*t+4)).map(e=>_jsx(View,{style:Z.gridRow,children:e.map(e=>{const t=e+10-1,a=pe(e),s=!!ae&&decadeStartFor(ae.getFullYear())===e,r=decadeStartFor(X.getFullYear())===e,i=s?G.colors.primary:"transparent",o=r&&!s?G.colors.primary:"transparent",l=s?G.colors["on-primary"]:a?G.colors["text-disabled"]:G.colors["text-body"],n=a?.3:1;return _jsx(Pressable,{disabled:a,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:z.decade(e,t),accessibilityState:{selected:s,disabled:a},"aria-selected":s,"aria-disabled":a,style:Z.yearCell,children:_jsxs(View,{style:[Z.yearInner,{backgroundColor:i,borderColor:o,borderWidth:r&&!s?1.5:0,opacity:n}],children:[_jsx(Text,{style:[Z.yearText,{color:l}],variant:"body",children:`${e}s`}),_jsx(Text,{variant:"caption",style:[Z.decadeRangeText,{color:s?G.colors["on-primary"]:G.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${e[0]}`))}),_jsxs(View,{style:Z.footer,children:[_jsx(Pressable,{onPress:Re,style:({pressed:e})=>[Z.footerBtn,Z.footerCancel,e&&Z.footerBtnPressed,b],accessibilityRole:"button",accessibilityLabel:z.cancel,children:_jsx(Text,{style:[Z.footerBtnText,{color:G.colors["text-muted"]}],variant:"label",weight:"semibold",children:z.cancel})}),_jsx(Pressable,{onPress:Pe,disabled:!ae,style:({pressed:e})=>[Z.footerBtn,Z.footerConfirm,{backgroundColor:G.colors.primary,opacity:ae?1:.5},e&&{backgroundColor:G.colors["primary-hover"]},b],accessibilityRole:"button",accessibilityLabel:z.confirm,accessibilityState:{disabled:!ae},"aria-disabled":!ae,children:_jsx(Text,{style:[Z.footerBtnText,{color:G.colors["on-primary"]}],variant:"label",weight:"semibold",children:z.confirm})})]})]}),Ie=t?(F??(e=>e.toLocaleDateString()))(t):void 0,Ve=!H,Le={label:f,help:D,placeholder:v,helperText:w,error:C,required:j,disabled:S,size:_,variant:T,clearable:M,onClear:R,leftIcon:P,trailing:k,triggerStyle:A,valueStyle:I,labelStyle:V,messageStyle:L,accessibilityLabel:B,labels:E};if("inline"===Y)return O||Ve?Ve?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...Le,value:Ie,onPress:()=>N(!0),testID:x}),O?Ae:null]}):Ae:null;const Be=_jsx(Modal,{open:O,onClose:Se,presentation:"bottom",bare:!0,haptic:!1,labels:{close:z.dismiss},onInsetsChange:K,children:_jsx(GestureHandlerRootView,{style:Z.gestureRoot,children:_jsx(Animated.View,{style:[Z.sheetWrap,{paddingBottom:Math.max(q.bottom,G.space.lg),opacity:Me,transform:[{translateY:oe}]}],onLayout:e=>{le.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Ae})})});return Ve?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...Le,value:Ie,onPress:()=>N(!0),testID:x}),Be]}):Be},buildStyles=e=>{const t=e.shadow.popover;return StyleSheet.create({gestureRoot:{width:"100%"},sheetWrap:{paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,...smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,lineHeight:Math.round(e.text.lg.size*e.leading.body),fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},gridRow:{flexDirection:"row"},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,...smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,lineHeight:Math.round(e.text.base.size*e.leading.body),fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,lineHeight:Math.round(e.text.xs.size*e.leading.body),fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,lineHeight:Math.round(e.text.sm.size*e.leading.body),fontWeight:e.weight.semibold}})};export{DatePicker};export default DatePicker;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Calendar}from"../Calendar/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const NAV_BUTTON_SIZE=36;export const DEFAULT_DATE_PICKER_LABELS=Object.freeze({title:"Select Date",confirm:"Confirm",cancel:"Cancel",dismiss:"Dismiss",previousMonth:"Previous month",nextMonth:"Next month",previousYears:"Previous years",nextYears:"Next years",previousDecades:"Previous decades",nextDecades:"Next decades",switchToYears:"switch to year selection",switchToDecades:"switch to decade selection",year:e=>`Year ${e}`,decade:(e,t)=>`Decade ${e} to ${t}`});const GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:s,maxDate:i,disabledDates:o,inline:l=!1,locale:n="en-IN",weekStartsOn:c=0,title:d,labels:u,style:g,containerStyle:m,headerLabelStyle:h,navButtonStyle:y,footerButtonStyle:b,haptic:p,testID:x,label:f,help:v,placeholder:D,helperText:w,error:C,required:j,disabled:S,size:_,variant:T,clearable:M,onClear:R,leftIcon:P,trailing:k,triggerStyle:A,valueStyle:I,labelStyle:V,messageStyle:L,accessibilityLabel:F,triggerLabels:B,formatValue:E}=e,Y=l?"inline":"modal",z=useMemo(()=>u?{...DEFAULT_DATE_PICKER_LABELS,...u}:DEFAULT_DATE_PICKER_LABELS,[u]),H=void 0!==e.open,[$,N]=useState(!1),O=H?e.open:$,W=H?x:x?`${x}-calendar`:void 0,G=useTheme(),U=usePresenceMotion(),[q,K]=useModalInsets(),Z=useMemo(()=>buildStyles(G),[G]),[X,J]=useState(()=>startOfDay(new Date));useEffect(()=>{O&&J(startOfDay(new Date))},[O]);const Q=t?startOfDay(t):X,[ee,te]=useState(Q),[ae,re]=useState(t?startOfDay(t):null),[se,ie]=useState("days"),oe=useRef(createAnimatedValue(0)).current,le=useRef(0),ne=useRef(createAnimatedValue(1)).current,ce=useRef(createAnimatedValue(1)).current,de=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(t){const e=startOfDay(t);re(e),te(e)}else re(null)},[t]);const ue=useMemo(()=>s?startOfDay(s):null,[s]),ge=useMemo(()=>i?startOfDay(i):null,[i]),me=useMemo(()=>buildYearCells(ee.getFullYear()),[ee]),he=useMemo(()=>buildDecadeCells(ee.getFullYear()),[ee]),ye=useMemo(()=>{const e=ee.getFullYear();if("years"===se)return`${e-4} - ${e+7}`;const t=decadeStartFor(e)-40;return`${t} - ${t+110+9}`},[ee,se]),be=useCallback(e=>!!(ue&&e<ue.getFullYear())||!!(ge&&e>ge.getFullYear()),[ue,ge]),pe=useCallback(e=>!!(ue&&e+10-1<ue.getFullYear())||!!(ge&&e>ge.getFullYear()),[ue,ge]),xe=useCallback(()=>{!1!==p&&triggerHaptic("impactLight"),te("years"===se?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))},[se,p]),fe=useCallback(()=>{!1!==p&&triggerHaptic("impactLight"),te("years"===se?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))},[se,p]),ve=useCallback(()=>{const[e]=U.range(.9,1),t=U.reduced?U.duration("default"):G.motion.duration.default;setNativeValue(ne,0),setNativeValue(ce,e),Animated.parallel([Animated.timing(ne,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:nativeDriver}),Animated.timing(ce,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:nativeDriver})]).start()},[ne,ce,U,G.motion.duration.default]),De=useCallback(()=>{const e=resolveHaptic(p,"selection");if(e&&triggerHaptic(e),!U.reduced){const e=80,t=100;Animated.sequence([Animated.timing(de,{toValue:.96,duration:e,useNativeDriver:nativeDriver}),Animated.timing(de,{toValue:1,duration:t,useNativeDriver:nativeDriver})]).start()}ie(e=>"days"===e?"years":"years"===e?"decades":"years"),ve()},[ve,de,p,U.reduced]),we=useCallback(e=>{const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),te(t=>new Date(e,t.getMonth(),1)),ie("days"),ve()},[ve,p]),Ce=useCallback(e=>{const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),te(t=>new Date(e+4,t.getMonth(),1)),ie("years"),ve()},[ve,p]),je=useCallback(e=>{re(e.start)},[]),Se=useCallback(()=>{H||N(!1),r?.()},[H,r]),{handleGesture:Te,opacity:Me}=useDragToDismiss({drag:oe,travel:()=>le.current||320,onDismiss:Se});useEffect(()=>{O&&"modal"===Y&&(setNativeValue(oe,0),setNativeValue(Me,1))},[O,Y,oe,Me]);const Re=useCallback(()=>{!1!==p&&triggerHaptic("selection"),Se()},[Se,p]),Pe=useCallback(()=>{ae&&(!1!==p&&triggerHaptic("notificationSuccess"),a?.(ae),Se())},[Se,a,ae,p]),ke=_jsx(View,{style:Z.titleRow,children:_jsx(Text,{style:Z.title,variant:"title",accessibilityRole:"header",children:d??z.title})}),Ae=_jsxs(View,{style:[Z.card,m,g],accessibilityRole:"modal"===Y?void 0:"none",accessible:!1,testID:W,children:["modal"===Y?_jsx(GestureDetector,{gesture:Te,children:_jsxs(View,{style:Z.grabArea,children:[_jsx(View,{style:Z.handle}),ke]})}):ke,"days"!==se?_jsxs(View,{style:Z.headerRow,children:[_jsx(Pressable,{onPress:xe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"years"===se?z.previousYears:z.previousDecades,hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:Z.navText,variant:"title",children:"‹"})}),_jsx(Pressable,{onPress:De,style:[Z.headerLabelWrap,h],accessibilityRole:"button",accessibilityLabel:`${ye}, ${"years"===se?z.switchToDecades:z.switchToYears}`,hitSlop:8,...hitSlopMarker(8),children:_jsxs(Animated.View,{style:[Z.headerLabelInner,{transform:[{scale:de}]}],children:[_jsx(Animated.Text,{style:[Z.headerLabel,{transform:[{translateX:0}]}],accessibilityLiveRegion:"polite",children:ye}),_jsx(View,{style:Z.headerCaret,children:(G.settings.icons.chevronDown??defaultIcons.chevronDown)({size:G.text.sm.size,color:G.colors["text-muted"]})})]})}),_jsx(Pressable,{onPress:fe,style:({pressed:e})=>[Z.navBtn,e&&Z.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"years"===se?z.nextYears:z.nextDecades,hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:Z.navText,variant:"title",children:"›"})})]}):null,"days"===se?_jsx(Calendar,{selectionMode:"single",value:ae?{start:ae}:null,onChange:je,month:ee,onMonthChange:te,minDate:s,maxDate:i,disabledDates:o,weekStartsOn:c,locale:n,haptic:p,headerLabelStyle:h,navButtonStyle:y,onTitlePress:De,labels:{previousMonth:z.previousMonth,nextMonth:z.nextMonth},testID:W?`${W}-grid`:void 0}):_jsx(Animated.View,"years"===se?{style:[Z.yearGrid,{opacity:ne,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>me.slice(4*t,4*t+4)).map(e=>_jsx(View,{style:Z.gridRow,children:e.map(e=>{const t=be(e),a=!!ae&&ae.getFullYear()===e,r=X.getFullYear()===e,s=a?G.colors.primary:"transparent",i=r&&!a?G.colors.primary:"transparent",o=a?G.colors["on-primary"]:t?G.colors["text-disabled"]:G.colors["text-body"],l=t?.3:1;return _jsx(Pressable,{disabled:t,onPress:()=>we(e),accessibilityRole:"button",accessibilityLabel:z.year(e),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:Z.yearCell,children:_jsx(View,{style:[Z.yearInner,{backgroundColor:s,borderColor:i,borderWidth:r&&!a?1.5:0,opacity:l}],children:_jsx(Text,{style:[Z.yearText,{color:o}],variant:"body",children:e})})},`year-${e}`)})},`yr-${e.join("-")}`))}:{style:[Z.yearGrid,{opacity:ne,transform:[{scale:ce}]}],children:Array.from({length:3},(e,t)=>he.slice(4*t,4*t+4)).map(e=>_jsx(View,{style:Z.gridRow,children:e.map(e=>{const t=e+10-1,a=pe(e),r=!!ae&&decadeStartFor(ae.getFullYear())===e,s=decadeStartFor(X.getFullYear())===e,i=r?G.colors.primary:"transparent",o=s&&!r?G.colors.primary:"transparent",l=r?G.colors["on-primary"]:a?G.colors["text-disabled"]:G.colors["text-body"],n=a?.3:1;return _jsx(Pressable,{disabled:a,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:z.decade(e,t),accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:Z.yearCell,children:_jsxs(View,{style:[Z.yearInner,{backgroundColor:i,borderColor:o,borderWidth:s&&!r?1.5:0,opacity:n}],children:[_jsx(Text,{style:[Z.yearText,{color:l}],variant:"body",children:`${e}s`}),_jsx(Text,{variant:"caption",style:[Z.decadeRangeText,{color:r?G.colors["on-primary"]:G.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${e.join("-")}`))}),_jsxs(View,{style:Z.footer,children:[_jsx(Pressable,{onPress:Re,style:({pressed:e})=>[Z.footerBtn,Z.footerCancel,e&&Z.footerBtnPressed,b],accessibilityRole:"button",accessibilityLabel:z.cancel,children:_jsx(Text,{style:[Z.footerBtnText,{color:G.colors["text-muted"]}],variant:"label",weight:"semibold",children:z.cancel})}),_jsx(Pressable,{onPress:Pe,disabled:!ae,style:({pressed:e})=>[Z.footerBtn,Z.footerConfirm,{backgroundColor:G.colors.primary,opacity:ae?1:.5},e&&{backgroundColor:G.colors["primary-hover"]},b],accessibilityRole:"button",accessibilityLabel:z.confirm,accessibilityState:{disabled:!ae},"aria-disabled":!ae,children:_jsx(Text,{style:[Z.footerBtnText,{color:G.colors["on-primary"]}],variant:"label",weight:"semibold",children:z.confirm})})]})]}),Ie=t?(E??(e=>e.toLocaleDateString()))(t):void 0,Ve=!H,Le={label:f,help:v,placeholder:D,helperText:w,error:C,required:j,disabled:S,size:_,variant:T,clearable:M,onClear:R,leftIcon:P,trailing:k,triggerStyle:A,valueStyle:I,labelStyle:V,messageStyle:L,accessibilityLabel:F,labels:B};if("inline"===Y)return O||Ve?Ve?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...Le,value:Ie,onPress:()=>N(!0),testID:x}),O?Ae:null]}):Ae:null;const Fe=_jsx(Modal,{open:O,onClose:Se,presentation:"bottom",bare:!0,haptic:!1,labels:{close:z.dismiss},onInsetsChange:K,children:_jsx(GestureHandlerRootView,{style:Z.gestureRoot,children:_jsx(Animated.View,{style:[Z.sheetWrap,{paddingBottom:Math.max(q.bottom,G.space.lg),opacity:Me,transform:[{translateY:oe}]}],onLayout:e=>{le.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Ae})})});return Ve?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{...Le,value:Ie,onPress:()=>N(!0),testID:x}),Fe]}):Fe},buildStyles=e=>{const t=e.shadow.popover;return StyleSheet.create({gestureRoot:{width:"100%"},sheetWrap:{paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,...smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,lineHeight:Math.round(e.text.lg.size*e.leading.body),fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},gridRow:{flexDirection:"row"},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,...smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,lineHeight:Math.round(e.text.base.size*e.leading.body),fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,lineHeight:Math.round(e.text.xs.size*e.leading.body),fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,lineHeight:Math.round(e.text.sm.size*e.leading.body),fontWeight:e.weight.semibold}})};export{DatePicker};export default DatePicker;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{Extrapolation,interpolate,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DRAWER_LABELS={close:"Close drawer",drawer:"Drawer"};const DEFAULT_CLOSE_VELOCITY_THRESHOLD=1e3,DEFAULT_DRAG_ACTIVATION_OFFSET=10,Drawer=forwardRef((e,t)=>{const{open:a,defaultOpen:r=!1,onOpenChange:i,side:o="left",width:s,enableSwipe:n=!0,enableBackdropPress:l=!0,backdropOpacity:u=.5,haptic:c,containerStyle:d,children:p,accessibilityLabel:h,labels:m,testID:f}=e,g=useTheme();assertValidValue("Drawer","side",e.side,["left","right","top","bottom"]);const b=useMemo(()=>({...DEFAULT_DRAWER_LABELS,...m}),[m]),S=usePresenceMotion(),v=S.reduced,E=S.duration("default"),w=S.duration("fast"),y=useSafeAreaInsets(),M="boolean"==typeof a,[_,D]=useState(()=>Dimensions.get("window"));useEffect(()=>{const e=Dimensions.addEventListener("change",({window:e})=>D(e));return()=>e.remove()},[]);const C="left"===o||"right"===o,O=useMemo(()=>resolveSize(s,C,_),[s,C,_]),R=useMemo(()=>{switch(o){case"left":case"top":return-O;case"right":case"bottom":return O}},[o,O]),T=useSharedValue(r?0:R),x=useSharedValue(r?0:R),k=useSharedValue(r?1:0),[A,L]=useState(r),V=useSharedValue(r);useEffect(()=>{A||v||(T.value=R,x.value=R)},[R,A,T,x,v]);const j=g.motion.spring.snappy,I=useCallback(()=>{if(v)return T.value=0,void(k.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION}));k.value=1,T.value=withSpring(0,j)},[T,k,j,v,E]),N=useCallback(()=>{v?k.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(T.value=R)}):T.value=withSpring(R,j)},[T,k,R,j,v,w]),P=useCallback(e=>{L(t=>t===e?t:(i?.(e),e)),V.value=e},[i,V]),F=useCallback(()=>{P(!0),I()},[P,I]),U=useCallback(()=>{P(!1),N()},[P,N]),H=useCallback(()=>{A?U():F()},[A,F,U]);useImperativeHandle(t,()=>({open:F,close:U,toggle:H}),[F,U,H]),useEffect(()=>{M&&a!==A&&(a?F():U())},[a]);const B=useMemo(()=>{const e=R,t=o,a=n;let r=Gesture.Pan();return r=C?r.activeOffsetX([-10,10]).failOffsetY([-15,15]):r.activeOffsetY([-10,10]).failOffsetX([-15,15]),r.onStart(()=>{"worklet";a&&(x.value=T.value)}).onUpdate(t=>{"worklet";if(!a)return;const r=C?t.translationX:t.translationY,i=x.value+r,o=Math.min(0,e),s=Math.max(0,e);T.value=i<o?o+.25*(i-o):i>s?s+.25*(i-s):i}).onEnd(r=>{"worklet";if(!a)return;const i=C?r.velocityX:r.velocityY,o=T.value;let s=!1;s="left"===t||"top"===t?i<-1e3:i>1e3;const n=Math.abs(e),l=Math.abs(o)/n;s||l>.5?(runOnJS(P)(!1),v?k.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},t=>{"worklet";t&&(T.value=e)}):T.value=withSpring(e,j)):(runOnJS(P)(!0),v?(T.value=0,k.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION})):T.value=withSpring(0,j))})},[R,x,n,C,T,k,P,o,j,v,E,w]),Y=useAnimatedStyle(()=>C?{opacity:k.value,transform:[{translateX:T.value}]}:{opacity:k.value,transform:[{translateY:T.value}]},[C,T,k]),G=useAnimatedStyle(()=>({opacity:interpolate(T.value,[R,0],[0,u],Extrapolation.CLAMP)*k.value,pointerEvents:Math.abs(T.value-R)<.5?"none":"auto"}),[T,R,u,k]),X=useMemo(()=>buildStyles(g),[g]),J=useCallback(()=>{if(!l)return;const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),U()},[l,U,c]),z=useMemo(()=>{switch(o){case"left":return{position:"absolute",top:0,bottom:0,left:0,width:O,paddingTop:y.top,paddingBottom:y.bottom,paddingLeft:y.left};case"right":return{position:"absolute",top:0,bottom:0,right:0,width:O,paddingTop:y.top,paddingBottom:y.bottom,paddingRight:y.right};case"top":return{position:"absolute",top:0,left:0,right:0,height:O,paddingTop:y.top,paddingLeft:y.left,paddingRight:y.right};case"bottom":return{position:"absolute",bottom:0,left:0,right:0,height:O,paddingBottom:y.bottom,paddingLeft:y.left,paddingRight:y.right}}},[o,O,y]),W=useRef(r);return A&&(W.current=!0),W.current?_jsxs(View,{style:StyleSheet.absoluteFill,pointerEvents:"box-none",testID:f,accessibilityViewIsModal:A,children:[_jsx(Animated.View,{style:[X.backdrop,{backgroundColor:g.colors.scrim},G],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:J,accessibilityRole:"button",accessibilityLabel:b.close,disabled:!l||!A})}),_jsx(GestureDetector,{gesture:B,children:_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:h??b.drawer,style:[z,{backgroundColor:g.colors.surface,...g.shadow.modal},d,Y],children:_jsx(View,{style:X.content,children:p})})})]}):null});Drawer.displayName="Drawer";const resolveSize=(e,t,a)=>{if("number"==typeof e)return e;if("string"==typeof e){const r=parseFloat(e);if(Number.isNaN(r))return t?280:Math.round(.4*a.height);return r/100*(t?a.width:a.height)}return t?280:Math.round(.4*a.height)},buildStyles=e=>StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},content:{flex:1}});export{Drawer};export default Drawer;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{Extrapolation,interpolate,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DRAWER_LABELS={close:"Close drawer",drawer:"Drawer"};const DEFAULT_CLOSE_VELOCITY_THRESHOLD=1e3,DEFAULT_DRAG_ACTIVATION_OFFSET=10,Drawer=forwardRef((e,t)=>{const{open:a,defaultOpen:o=!1,onOpenChange:r,side:i="left",width:s,enableSwipe:l=!0,enableBackdropPress:n=!0,backdropOpacity:u=.5,haptic:c,containerStyle:d,children:p,accessibilityLabel:f,labels:h,testID:m}=e,g=useTheme();assertValidValue("Drawer","side",e.side,["left","right","top","bottom"]);const b=useMemo(()=>({...DEFAULT_DRAWER_LABELS,...h}),[h]),S=usePresenceMotion(),v=S.reduced,E=S.duration("default"),w=S.duration("fast"),y=useSafeAreaInsets(),O="boolean"==typeof a,[M,_]=useState(()=>Dimensions.get("window"));useEffect(()=>{const e=Dimensions.addEventListener("change",({window:e})=>_(e));return()=>e.remove()},[]);const D="left"===i||"right"===i,C=useMemo(()=>resolveSize(s,D,M),[s,D,M]),R=useMemo(()=>closedOffsetOf(i,C),[i,C]),T=useSharedValue(o?0:R),x=useSharedValue(o?0:R),L=useSharedValue(o?1:0),[k,A]=useState(o),V=useSharedValue(o);useEffect(()=>{k||v||(T.value=R,x.value=R)},[R,k,T,x,v]);const j=g.motion.spring.snappy,I=useCallback(()=>{if(v)return T.value=0,void(L.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION}));L.value=1,T.value=withSpring(0,j)},[T,L,j,v,E]),N=useCallback(()=>{v?L.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(T.value=R)}):T.value=withSpring(R,j)},[T,L,R,j,v,w]),P=useCallback(e=>{A(t=>t===e?t:(r?.(e),e)),V.value=e},[r,V]),F=useCallback(()=>{P(!0),I()},[P,I]),U=useCallback(()=>{P(!1),N()},[P,N]),H=useCallback(()=>{k?U():F()},[k,F,U]);useImperativeHandle(t,()=>({open:F,close:U,toggle:H}),[F,U,H]),useEffect(()=>{O&&a!==k&&(a?F():U())},[a]);const B=useMemo(()=>{const e=R,t=i,a=l;let o=Gesture.Pan();return o=D?o.activeOffsetX([-10,10]).failOffsetY([-15,15]):o.activeOffsetY([-10,10]).failOffsetX([-15,15]),o.onStart(()=>{"worklet";a&&(x.value=T.value)}).onUpdate(t=>{"worklet";if(!a)return;const o=D?t.translationX:t.translationY,r=x.value+o,i=Math.min(0,e),s=Math.max(0,e);T.value=r<i?i+.25*(r-i):r>s?s+.25*(r-s):r}).onEnd(o=>{"worklet";if(!a)return;const r=D?o.velocityX:o.velocityY,i=T.value;let s=!1;s="left"===t||"top"===t?r<-1e3:r>1e3;const l=Math.abs(e),n=Math.abs(i)/l;s||n>.5?(runOnJS(P)(!1),v?L.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},t=>{"worklet";t&&(T.value=e)}):T.value=withSpring(e,j)):(runOnJS(P)(!0),v?(T.value=0,L.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION})):T.value=withSpring(0,j))})},[R,x,l,D,T,L,P,i,j,v,E,w]),Y=useAnimatedStyle(()=>D?{opacity:L.value,transform:[{translateX:T.value}]}:{opacity:L.value,transform:[{translateY:T.value}]},[D,T,L]),G=useAnimatedStyle(()=>({opacity:interpolate(T.value,[R,0],[0,u],Extrapolation.CLAMP)*L.value,pointerEvents:Math.abs(T.value-R)<.5?"none":"auto"}),[T,R,u,L]),X=useMemo(()=>buildStyles(g),[g]),J=useCallback(()=>{if(!n)return;const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),U()},[n,U,c]),z=useMemo(()=>sideLayoutOf(i,C,y),[i,C,y]),W=useRef(o);return k&&(W.current=!0),W.current?_jsxs(View,{style:StyleSheet.absoluteFill,pointerEvents:"box-none",testID:m,accessibilityViewIsModal:k,children:[_jsx(Animated.View,{style:[X.backdrop,{backgroundColor:g.colors.scrim},G],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:J,accessibilityRole:"button",accessibilityLabel:b.close,disabled:!n||!k})}),_jsx(GestureDetector,{gesture:B,children:_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:f??b.drawer,style:[z,{backgroundColor:g.colors.surface,...g.shadow.modal},d,Y],children:_jsx(View,{style:X.content,children:p})})})]}):null});Drawer.displayName="Drawer";const closedOffsetOf=(e,t)=>{switch(e){case"left":case"top":return-t;case"right":case"bottom":return t}},sideLayoutOf=(e,t,a)=>{switch(e){case"left":return{position:"absolute",top:0,bottom:0,left:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingLeft:a.left};case"right":return{position:"absolute",top:0,bottom:0,right:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingRight:a.right};case"top":return{position:"absolute",top:0,left:0,right:0,height:t,paddingTop:a.top,paddingLeft:a.left,paddingRight:a.right};case"bottom":return{position:"absolute",bottom:0,left:0,right:0,height:t,paddingBottom:a.bottom,paddingLeft:a.left,paddingRight:a.right}}},resolveSize=(e,t,a)=>{if("number"==typeof e)return e;if("string"==typeof e){const o=parseFloat(e);if(Number.isNaN(o))return t?280:Math.round(.4*a.height);return o/100*(t?a.width:a.height)}return t?280:Math.round(.4*a.height)},buildStyles=e=>StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},content:{flex:1}});export{Drawer};export default Drawer;
@@ -1 +1 @@
1
- "use strict";import{useEffect,useRef}from"react";import{Animated,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{jsx as _jsx}from"react/jsx-runtime";export const Chevron=({color:e,size:t,open:n,style:o})=>{const r=useTheme(),i=useRef(createAnimatedValue(n?1:0)).current;useEffect(()=>{if(void 0===n)return;const e=Animated.timing(i,{toValue:n?1:0,duration:r.motion.duration.fast,useNativeDriver:!0});return e.start(),()=>e.stop()},[n,i,r.motion.duration.fast]);const s=(r.settings.icons.chevronDown??defaultIcons.chevronDown)({size:t,color:e}),a={width:t,height:t,alignItems:"center",justifyContent:"center"};if(void 0===n)return _jsx(View,{style:[a,o],children:s});const u=i.interpolate({inputRange:[0,1],outputRange:["0deg","180deg"]});return _jsx(Animated.View,{style:[a,{transform:[{rotate:u}]},o],children:s})};export default Chevron;
1
+ "use strict";import{useEffect,useRef}from"react";import{Animated,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{jsx as _jsx}from"react/jsx-runtime";export const Chevron=({color:e,size:t,open:r,style:n})=>{const o=useTheme(),i=useRef(createAnimatedValue(r?1:0)).current;useEffect(()=>{if(void 0===r)return;const e=Animated.timing(i,{toValue:r?1:0,duration:o.motion.duration.fast,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[r,i,o.motion.duration.fast]);const s=(o.settings.icons.chevronDown??defaultIcons.chevronDown)({size:t,color:e}),a={width:t,height:t,alignItems:"center",justifyContent:"center"};if(void 0===r)return _jsx(View,{style:[a,n],children:s});const u=i.interpolate({inputRange:[0,1],outputRange:["0deg","180deg"]});return _jsx(Animated.View,{style:[a,{transform:[{rotate:u}]},n],children:s})};export default Chevron;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useImperativeHandle,useMemo,useRef,useState}from"react";import{Image,Pressable,ScrollView,StyleSheet,Text,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,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{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{hasFieldText}from"../FieldBase/index.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";let fileIdSeq=0;const nextFileId=()=>"wfp-"+ ++fileIdSeq;export const DEFAULT_FILE_PICKER_LABELS={trigger:"Attach file",addMore:"Add more",sheetTitle:"Add from",removeFile:e=>`Remove ${e}`,retry:"Retry upload",attachments:"Attachments",attached:e=>`${e} file${1===e?"":"s"} attached`,processing:"Processing…",uploading:e=>`Uploading ${e}%`,uploaded:"Uploaded",failed:"Failed",errorTooMany:e=>`You can attach up to ${e} files.`,errorTooLarge:(e,t)=>`${e} is larger than ${t} MB.`,errorWrongType:e=>`${e} is not an accepted file type.`};export const formatFileSize=e=>{if(void 0===e||e<=0)return"";const t=["B","KB","MB","GB"];let r=e,s=0;for(;r>=1024&&s<t.length-1;)r/=1024,s+=1;return`${r>=10||0===s?Math.round(r):Math.round(10*r)/10} ${t[s]}`};export const matchesAccept=(e,t)=>!t||0===t.length||!!e&&t.some(t=>"*/*"===t||"*"===t||(t.endsWith("/*")?e.startsWith(t.slice(0,t.length-1)):e===t));const isImage=e=>!0===e.type?.startsWith("image/")||!e.type&&/\.(png|jpe?g|gif|webp|heic)$/i.test(e.name),imageSourceOf=e=>e.thumbnailUrl??(isImage(e)?e.uri??e.url:void 0),extensionOf=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"FILE":e.slice(t+1).toUpperCase().slice(0,4)},FilePicker=forwardRef((e,t)=>{assertValidValue("FilePicker","variant",e.variant,["card","list"]);const{files:r,defaultFiles:s,onChange:o,sources:i,maxFiles:l,maxSizeMB:n,accept:a,validate:c,process:d,variant:u="card",renderFile:g,renderTrigger:h,disabled:p=!1,helperText:m,error:x,labels:b,haptic:f,onPick:y,onRemove:T,onError:j,onFilePress:S,onRetry:C,style:w,accessibilityLabel:F,testID:_}=e,v=useTheme(),P=useMemo(()=>buildStyles(v),[v]),k=useMemo(()=>({...DEFAULT_FILE_PICKER_LABELS,...b}),[b]),z=v.radius.md,I=v.colors.primary,[R,V]=useControllableState({value:r,defaultValue:s??[],onChange:o}),M=useRef(R);M.current=R;const L=useCallback(e=>{M.current=e,V(e)},[V]),[O,B]=useState(null),[H,$]=useState(!1),E=x??O??void 0,A="number"==typeof l&&R.length>=l,W=useCallback((e,t)=>{0!==e.length&&(B(e[0]),e.forEach(e=>{j?.(e,t)}),!1!==f&&triggerHaptic("notificationError"))},[j,f]),D=useCallback(async e=>{let t;try{t=await e.pick()}catch(e){return void W([e instanceof Error?e.message:String(e)])}if(!t||0===t.length)return;const r=[];let s=t.map(e=>({id:nextFileId(),name:e.name??e.uri.split("/").pop()??"file",uri:e.uri,type:e.type,bytes:e.size,meta:e.meta,status:"idle"}));if("number"==typeof l){const e=Math.max(0,l-M.current.length);s.length>e&&(r.push(k.errorTooMany(l)),s=s.slice(0,e))}const o=[];for(const e of s){if("number"==typeof n&&"number"==typeof e.bytes&&e.bytes>1024*n*1024){r.push(k.errorTooLarge(e.name,n));continue}if(!matchesAccept(e.type,a)){r.push(k.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):o.push(e)}if(W(r),0===o.length)return;if(!d){L([...M.current,...o]),B(r.length>0?r[0]:null);const e=resolveHaptic(f,"selection");return e&&triggerHaptic(e),void y?.(o)}const i=o.map(e=>({...e,status:"processing"}));L([...M.current,...i]);const u=[];for(const e of i)try{const t=await d({...e,status:"idle"}),r={...t,id:e.id,status:t.status??"idle"};L(M.current.map(t=>t.id===e.id?r:t)),u.push(r)}catch(t){L(M.current.filter(t=>t.id!==e.id)),W([t instanceof Error?t.message:String(t)],e)}if(u.length>0){0===r.length&&B(null);const e=resolveHaptic(f,"selection");e&&triggerHaptic(e),y?.(u)}},[l,n,a,c,d,k,W,L,y,f]),U=useCallback(e=>{if(p||A)return;const t=e?i.find(t=>t.key===e):1===i.length?i[0]:void 0;t?D(t):i.length>1&&$(!0)},[p,A,i,D]),G=useCallback(e=>{if(p)return;L(M.current.filter(t=>t.id!==e.id)),B(null);const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),T?.(e)},[p,L,T,f]),K=useCallback(()=>{L([]),B(null)},[L]);useImperativeHandle(t,()=>({open:U,clear:K}),[U,K]);const N=0===R.length?k.trigger:k.attached(R.length),q=F??`${k.attachments}. ${N}`,statusText=e=>{switch(e.status){case"processing":return k.processing;case"uploading":return k.uploading(Math.round(100*(e.progress??0)));case"done":return k.uploaded;case"error":return e.error??k.failed;default:return""}},fileA11yLabel=e=>[e.name,formatFileSize(e.bytes),statusText(e)].filter(Boolean).join(", "),Y=v.settings.icons.attachment??defaultIcons.attachment,renderStatusOverlay=e=>{if("processing"===e.status)return _jsx(View,{style:[P.tileOverlay,{backgroundColor:v.colors.scrim}],children:_jsx(Spinner,{size:"sm"})});if("uploading"===e.status){const t=Math.round(100*(e.progress??0));return _jsxs(View,{style:[P.tileOverlay,{backgroundColor:v.colors.scrim}],children:[_jsx(Text,{style:[P.tileOverlayText,{color:v.colors["on-scrim"]}],children:`${t}%`}),_jsx(View,{style:[P.tileProgressTrack,{backgroundColor:v.colors.border}],children:_jsx(View,{style:[P.tileProgressFill,{width:`${t}%`,backgroundColor:v.colors.primary}]})})]})}return"done"===e.status?_jsx(View,{style:[P.doneBadge,{backgroundColor:v.colors.success}],children:_jsx(Text,{style:[P.doneBadgeText,{color:v.colors["on-success"]}],children:"✓"})}):null},renderThumbnail=e=>{const t=imageSourceOf(e);return t?_jsx(Image,{source:{uri:t},style:P.thumbnailImage}):_jsx(View,{style:[P.extensionTile,{backgroundColor:v.colors["bg-subtle"]}],children:_jsx(Text,{style:[P.extensionText,{color:v.colors["text-muted"],...fontFor(v,"semibold")}],children:extensionOf(e.name)})})},removeButton=e=>_jsx(Pressable,{onPress:()=>G(e),disabled:p,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:k.removeFile(e.name),style:[P.removeButton,{backgroundColor:v.colors.scrim}],children:_jsx(Text,{style:[P.removeButtonText,{color:v.colors["on-scrim"]}],children:"×"})}),retryButton=e=>C&&"error"===e.status?_jsx(Pressable,{onPress:()=>C(e),disabled:p,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:k.retry,children:_jsx(Text,{style:[P.retryText,{color:v.colors.primary}],children:"↻"})}):null,renderOneFile=(e,t)=>{const r={file:e,index:t,disabled:p,remove:()=>G(e),retry:C?()=>C(e):void 0},s=g?g(r):"card"===u?(e=>{const{file:t}=e;return _jsxs(View,{style:[P.tile,{width:84,height:84,borderRadius:z,...smoothCorners,borderColor:"error"===t.status?v.colors.danger:v.colors.border}],children:[renderThumbnail(t),renderStatusOverlay(t),"error"===t.status?_jsx(View,{style:[P.tileOverlay,{backgroundColor:v.colors.scrim}],children:retryButton(t)}):null,removeButton(t)]})})(r):(e=>{const{file:t}=e,r=statusText(t);return _jsxs(View,{style:[P.listRow,{borderRadius:z,...smoothCorners,borderColor:"error"===t.status?v.colors.danger:v.colors.border,backgroundColor:v.colors.bg}],children:[_jsxs(View,{style:[P.listThumb,{borderRadius:v.radius.sm,...smoothCorners}],children:[renderThumbnail(t),"processing"===t.status?_jsx(View,{style:[P.tileOverlay,{backgroundColor:v.colors.scrim}],children:_jsx(Spinner,{size:"sm"})}):null]}),_jsxs(View,{style:P.listTextWrap,children:[_jsx(Text,{numberOfLines:1,ellipsizeMode:"middle",style:[P.listName,{color:v.colors["text-body"],fontSize:v.text.sm.size,...fontFor(v,"medium")}],children:t.name}),_jsx(Text,{numberOfLines:1,style:[P.listSubtitle,{color:"error"===t.status?v.colors["danger-text"]:v.colors["text-subtle"],fontSize:v.text.xs.size}],children:[formatFileSize(t.bytes),r].filter(Boolean).join(" · ")}),"uploading"===t.status?_jsx(View,{style:[P.listProgressTrack,{backgroundColor:v.colors.border}],children:_jsx(View,{style:[P.listProgressFill,{width:`${Math.round(100*(t.progress??0))}%`,backgroundColor:v.colors.primary}]})}):null]}),retryButton(t),_jsx(Pressable,{onPress:()=>G(t),disabled:p,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:k.removeFile(t.name),children:_jsx(Text,{style:[P.listRemoveText,{color:v.colors["text-subtle"]}],children:"×"})})]})})(r);return _jsx(Pressable,{onPress:S?()=>S(e):void 0,disabled:p||!S,accessibilityLabel:fileA11yLabel(e),children:s},e.id)},J={open:U,disabled:p||A,fileCount:R.length,atCapacity:A},dashedTrigger=e=>_jsxs(Pressable,{onPress:()=>U(),disabled:p||A,accessibilityRole:"button",accessibilityState:{disabled:p||A},"aria-disabled":p||A,style:({pressed:t})=>[P.trigger,e?P.triggerCompact:null,{borderRadius:z,...smoothCorners,borderColor:I,backgroundColor:t?v.colors["surface-pressed"]:v.colors.bg,opacity:p||A?.55:1}],children:[_jsxs(View,{style:P.triggerRow,children:[Y?Y({size:16,color:v.colors.primary}):null,_jsx(Text,{style:[P.triggerText,{color:v.colors.primary,fontSize:v.text.sm.size,...fontFor(v,"medium")}],children:0===R.length?k.trigger:k.addMore})]}),!e&&m?_jsx(Text,{style:[P.helperText,{color:v.colors["text-subtle"],fontSize:v.text.xs.size}],children:m}):null]}),Q=_jsx(Pressable,{onPress:()=>U(),disabled:p||A,accessibilityRole:"button",accessibilityLabel:k.addMore,style:({pressed:e})=>[P.tile,P.addTile,{width:84,height:84,borderRadius:z,...smoothCorners,borderColor:I,backgroundColor:e?v.colors["surface-pressed"]:"transparent",opacity:p||A?.55:1}],children:_jsx(Text,{style:[P.addTileText,{color:v.colors.primary}],children:"+"})});return _jsxs(View,{style:[P.container,w],testID:_,accessibilityLabel:q,children:["card"===u?0===R.length?h?h(J):dashedTrigger(!1):_jsxs(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[P.strip,{columnGap:v.space.sm}],children:[R.map(renderOneFile),h?h(J):A||p?null:Q]}):_jsxs(View,{style:{rowGap:v.space.sm},children:[h?h(J):A?null:dashedTrigger(R.length>0),R.map(renderOneFile)]}),hasFieldText(E)?_jsx(Text,{accessibilityLiveRegion:"polite",style:[P.errorText,{color:v.colors["danger-text"],fontSize:v.text.xs.size,marginTop:v.space.xxs}],children:E}):null,_jsx(OptionSheet,{open:H,onClose:()=>$(!1),title:k.sheetTitle,options:i,getOptionLabel:e=>e.label,getOptionValue:e=>e.key,getOptionDescription:e=>e.description,getOptionIcon:e=>e.icon,onChange:(e,t)=>{$(!1),D(t)}})]})});FilePicker.displayName="FilePicker";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},trigger:{borderWidth:1,borderStyle:"dashed",alignItems:"center",minHeight:48,paddingVertical:e.space.md,paddingHorizontal:e.space.lg},triggerCompact:{minHeight:40,paddingVertical:e.space.sm},triggerRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},triggerText:{includeFontPadding:!1},helperText:{includeFontPadding:!1,marginTop:e.space.xs,textAlign:"center"},strip:{paddingVertical:e.space.xxs},tile:{borderWidth:1,overflow:"hidden"},addTile:{borderStyle:"dashed",alignItems:"center",justifyContent:"center"},addTileText:{fontSize:e.text["3xl"].size,includeFontPadding:!1},thumbnailImage:{width:"100%",height:"100%",resizeMode:"cover"},extensionTile:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"},extensionText:{fontSize:e.text.sm.size,letterSpacing:1,includeFontPadding:!1},tileOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},tileOverlayText:{fontSize:e.text.sm.size,includeFontPadding:!1,marginBottom:e.space.xs},tileProgressTrack:{position:"absolute",left:8,right:8,bottom:8,height:3,borderRadius:e.radius.pill,...smoothCorners,overflow:"hidden"},tileProgressFill:{height:"100%",borderRadius:e.radius.pill,...smoothCorners},doneBadge:{position:"absolute",right:4,bottom:4,width:18,height:18,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},doneBadgeText:{fontSize:e.text.xs.size,includeFontPadding:!1},removeButton:{position:"absolute",top:4,right:4,width:20,height:20,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},removeButtonText:{fontSize:e.text.sm.size,lineHeight:15,includeFontPadding:!1},retryText:{fontSize:e.text.xl.size,includeFontPadding:!1},listRow:{flexDirection:"row",alignItems:"center",borderWidth:1,padding:e.space.sm,columnGap:e.space.sm},listThumb:{width:40,height:40,overflow:"hidden"},listTextWrap:{flex:1},listName:{includeFontPadding:!1},listSubtitle:{includeFontPadding:!1,marginTop:e.space.xxs},listProgressTrack:{height:3,borderRadius:e.radius.pill,...smoothCorners,overflow:"hidden",marginTop:e.space.xs},listProgressFill:{height:"100%",borderRadius:e.radius.pill,...smoothCorners},listRemoveText:{fontSize:e.text["2xl"].size,includeFontPadding:!1,paddingHorizontal:e.space.xs},errorText:{includeFontPadding:!1}});export{FilePicker};export default FilePicker;
1
+ "use strict";import{forwardRef,useCallback,useImperativeHandle,useMemo,useRef,useState}from"react";import{Image,Pressable,ScrollView,StyleSheet,Text,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,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{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{hasFieldText}from"../FieldBase/index.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";let fileIdSeq=0;const nextFileId=()=>"wfp-"+ ++fileIdSeq;export const DEFAULT_FILE_PICKER_LABELS={trigger:"Attach file",addMore:"Add more",sheetTitle:"Add from",removeFile:e=>`Remove ${e}`,retry:"Retry upload",attachments:"Attachments",attached:e=>`${e} file${1===e?"":"s"} attached`,processing:"Processing…",uploading:e=>`Uploading ${e}%`,uploaded:"Uploaded",failed:"Failed",errorTooMany:e=>`You can attach up to ${e} files.`,errorTooLarge:(e,t)=>`${e} is larger than ${t} MB.`,errorWrongType:e=>`${e} is not an accepted file type.`};export const formatFileSize=e=>{if(void 0===e||e<=0)return"";const t=["B","KB","MB","GB"];let r=e,s=0;for(;r>=1024&&s<t.length-1;)r/=1024,s+=1;const o=r>=10||0===s?Math.round(r):Math.round(10*r)/10,i=t[s];if(void 0===i)throw new Error("formatFileSize has no unit label for this size.");return`${o} ${i}`};export const matchesAccept=(e,t)=>!t||0===t.length||!!e&&t.some(t=>"*/*"===t||"*"===t||(t.endsWith("/*")?e.startsWith(t.slice(0,t.length-1)):e===t));const isImage=e=>!0===e.type?.startsWith("image/")||!e.type&&/\.(png|jpe?g|gif|webp|heic)$/i.test(e.name),imageSourceOf=e=>e.thumbnailUrl??(isImage(e)?e.uri??e.url:void 0),extensionOf=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"FILE":e.slice(t+1).toUpperCase().slice(0,4)},FilePicker=forwardRef((e,t)=>{assertValidValue("FilePicker","variant",e.variant,["card","list"]);const{files:r,defaultFiles:s,onChange:o,sources:i,maxFiles:l,maxSizeMB:n,accept:a,validate:c,process:d,variant:u="card",renderFile:h,renderTrigger:g,disabled:p=!1,helperText:m,error:x,labels:b,haptic:f,onPick:y,onRemove:T,onError:S,onFilePress:j,onRetry:C,style:w,accessibilityLabel:F,testID:v}=e,_=useTheme(),P=useMemo(()=>buildStyles(_),[_]),k=useMemo(()=>({...DEFAULT_FILE_PICKER_LABELS,...b}),[b]),z=_.radius.md,I=_.colors.primary,[R,V]=useControllableState({value:r,defaultValue:s??[],onChange:o}),M=useRef(R);M.current=R;const L=useCallback(e=>{M.current=e,V(e)},[V]),[O,B]=useState(null),[H,$]=useState(!1),E=x??O??void 0,A="number"==typeof l&&R.length>=l,W=useCallback((e,t)=>{const[r]=e;void 0!==r&&(B(r),e.forEach(e=>{S?.(e,t)}),!1!==f&&triggerHaptic("notificationError"))},[S,f]),D=useCallback(async e=>{let t;try{t=await e.pick()}catch(e){return void W([e instanceof Error?e.message:String(e)])}if(!t||0===t.length)return;const r=[];let s=t.map(e=>({id:nextFileId(),name:e.name??e.uri.split("/").pop()??"file",uri:e.uri,type:e.type,bytes:e.size,meta:e.meta,status:"idle"}));if("number"==typeof l){const e=Math.max(0,l-M.current.length);s.length>e&&(r.push(k.errorTooMany(l)),s=s.slice(0,e))}const o=[];for(const e of s){if("number"==typeof n&&"number"==typeof e.bytes&&e.bytes>1024*n*1024){r.push(k.errorTooLarge(e.name,n));continue}if(!matchesAccept(e.type,a)){r.push(k.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):o.push(e)}if(W(r),0===o.length)return;if(!d){L([...M.current,...o]);const[e]=r;B(e??null);const t=resolveHaptic(f,"selection");return t&&triggerHaptic(t),void y?.(o)}const i=o.map(e=>({...e,status:"processing"}));L([...M.current,...i]);const u=[];for(const e of i)try{const t=await d({...e,status:"idle"}),r={...t,id:e.id,status:t.status??"idle"};L(M.current.map(t=>t.id===e.id?r:t)),u.push(r)}catch(t){L(M.current.filter(t=>t.id!==e.id)),W([t instanceof Error?t.message:String(t)],e)}if(u.length>0){0===r.length&&B(null);const e=resolveHaptic(f,"selection");e&&triggerHaptic(e),y?.(u)}},[l,n,a,c,d,k,W,L,y,f]),U=useCallback(e=>{if(p||A)return;const[t]=i,r=e?i.find(t=>t.key===e):1===i.length?t:void 0;r?D(r):i.length>1&&$(!0)},[p,A,i,D]),G=useCallback(e=>{if(p)return;L(M.current.filter(t=>t.id!==e.id)),B(null);const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),T?.(e)},[p,L,T,f]),K=useCallback(()=>{L([]),B(null)},[L]);useImperativeHandle(t,()=>({open:U,clear:K}),[U,K]);const N=0===R.length?k.trigger:k.attached(R.length),q=F??`${k.attachments}. ${N}`,statusText=e=>{switch(e.status){case"processing":return k.processing;case"uploading":return k.uploading(Math.round(100*(e.progress??0)));case"done":return k.uploaded;case"error":return e.error??k.failed;case"idle":case void 0:return""}},fileA11yLabel=e=>[e.name,formatFileSize(e.bytes),statusText(e)].filter(Boolean).join(", "),Y=_.settings.icons.attachment??defaultIcons.attachment,renderStatusOverlay=e=>{if("processing"===e.status)return _jsx(View,{style:[P.tileOverlay,{backgroundColor:_.colors.scrim}],children:_jsx(Spinner,{size:"sm"})});if("uploading"===e.status){const t=Math.round(100*(e.progress??0));return _jsxs(View,{style:[P.tileOverlay,{backgroundColor:_.colors.scrim}],children:[_jsx(Text,{style:[P.tileOverlayText,{color:_.colors["on-scrim"]}],children:`${t}%`}),_jsx(View,{style:[P.tileProgressTrack,{backgroundColor:_.colors.border}],children:_jsx(View,{style:[P.tileProgressFill,{width:`${t}%`,backgroundColor:_.colors.primary}]})})]})}return"done"===e.status?_jsx(View,{style:[P.doneBadge,{backgroundColor:_.colors.success}],children:_jsx(Text,{style:[P.doneBadgeText,{color:_.colors["on-success"]}],children:"✓"})}):null},renderThumbnail=e=>{const t=imageSourceOf(e);return t?_jsx(Image,{source:{uri:t},style:P.thumbnailImage}):_jsx(View,{style:[P.extensionTile,{backgroundColor:_.colors["bg-subtle"]}],children:_jsx(Text,{style:[P.extensionText,{color:_.colors["text-muted"],...fontFor(_,"semibold")}],children:extensionOf(e.name)})})},removeButton=e=>_jsx(Pressable,{onPress:()=>G(e),disabled:p,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:k.removeFile(e.name),style:[P.removeButton,{backgroundColor:_.colors.scrim}],children:_jsx(Text,{style:[P.removeButtonText,{color:_.colors["on-scrim"]}],children:"×"})}),retryButton=e=>C&&"error"===e.status?_jsx(Pressable,{onPress:()=>C(e),disabled:p,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:k.retry,children:_jsx(Text,{style:[P.retryText,{color:_.colors.primary}],children:"↻"})}):null,renderOneFile=(e,t)=>{const r={file:e,index:t,disabled:p,remove:()=>G(e),retry:C?()=>C(e):void 0},s=h?h(r):"card"===u?(e=>{const{file:t}=e;return _jsxs(View,{style:[P.tile,{width:84,height:84,borderRadius:z,...smoothCorners,borderColor:"error"===t.status?_.colors.danger:_.colors.border}],children:[renderThumbnail(t),renderStatusOverlay(t),"error"===t.status?_jsx(View,{style:[P.tileOverlay,{backgroundColor:_.colors.scrim}],children:retryButton(t)}):null,removeButton(t)]})})(r):(e=>{const{file:t}=e,r=statusText(t);return _jsxs(View,{style:[P.listRow,{borderRadius:z,...smoothCorners,borderColor:"error"===t.status?_.colors.danger:_.colors.border,backgroundColor:_.colors.bg}],children:[_jsxs(View,{style:[P.listThumb,{borderRadius:_.radius.sm,...smoothCorners}],children:[renderThumbnail(t),"processing"===t.status?_jsx(View,{style:[P.tileOverlay,{backgroundColor:_.colors.scrim}],children:_jsx(Spinner,{size:"sm"})}):null]}),_jsxs(View,{style:P.listTextWrap,children:[_jsx(Text,{numberOfLines:1,ellipsizeMode:"middle",style:[P.listName,{color:_.colors["text-body"],fontSize:_.text.sm.size,...fontFor(_,"medium")}],children:t.name}),_jsx(Text,{numberOfLines:1,style:[P.listSubtitle,{color:"error"===t.status?_.colors["danger-text"]:_.colors["text-subtle"],fontSize:_.text.xs.size}],children:[formatFileSize(t.bytes),r].filter(Boolean).join(" · ")}),"uploading"===t.status?_jsx(View,{style:[P.listProgressTrack,{backgroundColor:_.colors.border}],children:_jsx(View,{style:[P.listProgressFill,{width:`${Math.round(100*(t.progress??0))}%`,backgroundColor:_.colors.primary}]})}):null]}),retryButton(t),_jsx(Pressable,{onPress:()=>G(t),disabled:p,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:k.removeFile(t.name),children:_jsx(Text,{style:[P.listRemoveText,{color:_.colors["text-subtle"]}],children:"×"})})]})})(r);return _jsx(Pressable,{onPress:j?()=>j(e):void 0,disabled:p||!j,accessibilityLabel:fileA11yLabel(e),children:s},e.id)},J={open:U,disabled:p||A,fileCount:R.length,atCapacity:A},dashedTrigger=e=>_jsxs(Pressable,{onPress:()=>U(),disabled:p||A,accessibilityRole:"button",accessibilityState:{disabled:p||A},"aria-disabled":p||A,style:({pressed:t})=>[P.trigger,e?P.triggerCompact:null,{borderRadius:z,...smoothCorners,borderColor:I,backgroundColor:t?_.colors["surface-pressed"]:_.colors.bg,opacity:p||A?.55:1}],children:[_jsxs(View,{style:P.triggerRow,children:[Y?Y({size:16,color:_.colors.primary}):null,_jsx(Text,{style:[P.triggerText,{color:_.colors.primary,fontSize:_.text.sm.size,...fontFor(_,"medium")}],children:0===R.length?k.trigger:k.addMore})]}),!e&&m?_jsx(Text,{style:[P.helperText,{color:_.colors["text-subtle"],fontSize:_.text.xs.size}],children:m}):null]}),Q=_jsx(Pressable,{onPress:()=>U(),disabled:p||A,accessibilityRole:"button",accessibilityLabel:k.addMore,style:({pressed:e})=>[P.tile,P.addTile,{width:84,height:84,borderRadius:z,...smoothCorners,borderColor:I,backgroundColor:e?_.colors["surface-pressed"]:"transparent",opacity:p||A?.55:1}],children:_jsx(Text,{style:[P.addTileText,{color:_.colors.primary}],children:"+"})});return _jsxs(View,{style:[P.container,w],testID:v,accessibilityLabel:q,children:["card"===u?0===R.length?g?g(J):dashedTrigger(!1):_jsxs(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[P.strip,{columnGap:_.space.sm}],children:[R.map(renderOneFile),g?g(J):A||p?null:Q]}):_jsxs(View,{style:{rowGap:_.space.sm},children:[g?g(J):A?null:dashedTrigger(R.length>0),R.map(renderOneFile)]}),hasFieldText(E)?_jsx(Text,{accessibilityLiveRegion:"polite",style:[P.errorText,{color:_.colors["danger-text"],fontSize:_.text.xs.size,marginTop:_.space.xxs}],children:E}):null,_jsx(OptionSheet,{open:H,onClose:()=>$(!1),title:k.sheetTitle,options:i,getOptionLabel:e=>e.label,getOptionValue:e=>e.key,getOptionDescription:e=>e.description,getOptionIcon:e=>e.icon,onChange:(e,t)=>{$(!1),D(t)}})]})});FilePicker.displayName="FilePicker";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},trigger:{borderWidth:1,borderStyle:"dashed",alignItems:"center",minHeight:48,paddingVertical:e.space.md,paddingHorizontal:e.space.lg},triggerCompact:{minHeight:40,paddingVertical:e.space.sm},triggerRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},triggerText:{includeFontPadding:!1},helperText:{includeFontPadding:!1,marginTop:e.space.xs,textAlign:"center"},strip:{paddingVertical:e.space.xxs},tile:{borderWidth:1,overflow:"hidden"},addTile:{borderStyle:"dashed",alignItems:"center",justifyContent:"center"},addTileText:{fontSize:e.text["3xl"].size,includeFontPadding:!1},thumbnailImage:{width:"100%",height:"100%",resizeMode:"cover"},extensionTile:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"},extensionText:{fontSize:e.text.sm.size,letterSpacing:1,includeFontPadding:!1},tileOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},tileOverlayText:{fontSize:e.text.sm.size,includeFontPadding:!1,marginBottom:e.space.xs},tileProgressTrack:{position:"absolute",left:8,right:8,bottom:8,height:3,borderRadius:e.radius.pill,...smoothCorners,overflow:"hidden"},tileProgressFill:{height:"100%",borderRadius:e.radius.pill,...smoothCorners},doneBadge:{position:"absolute",right:4,bottom:4,width:18,height:18,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},doneBadgeText:{fontSize:e.text.xs.size,includeFontPadding:!1},removeButton:{position:"absolute",top:4,right:4,width:20,height:20,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},removeButtonText:{fontSize:e.text.sm.size,lineHeight:15,includeFontPadding:!1},retryText:{fontSize:e.text.xl.size,includeFontPadding:!1},listRow:{flexDirection:"row",alignItems:"center",borderWidth:1,padding:e.space.sm,columnGap:e.space.sm},listThumb:{width:40,height:40,overflow:"hidden"},listTextWrap:{flex:1},listName:{includeFontPadding:!1},listSubtitle:{includeFontPadding:!1,marginTop:e.space.xxs},listProgressTrack:{height:3,borderRadius:e.radius.pill,...smoothCorners,overflow:"hidden",marginTop:e.space.xs},listProgressFill:{height:"100%",borderRadius:e.radius.pill,...smoothCorners},listRemoveText:{fontSize:e.text["2xl"].size,includeFontPadding:!1,paddingHorizontal:e.space.xs},errorText:{includeFontPadding:!1}});export{FilePicker};export default FilePicker;
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import Reanimated,{cancelAnimation,Easing as ReanimatedEasing,useAnimatedStyle,useSharedValue,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{createAnimatedValue,resolveFloatingActionButtonSize,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const FAB_SIZES=["sm","md","lg"],FAB_TONES=["primary","success","warning","danger","info","neutral"],FAB_POSITIONS=["bottomRight","bottomLeft","bottomCenter"],toneBackground=(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["bg-muted"];default:return e.colors.primary}},pressedTintFor=(e,t)=>"neutral"===t?e.colors["surface-pressed"]:ACCENT_PRESSED_TINT,toneForeground=(e,t)=>{if("neutral"===t)return e.colors["text-body"];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"];default:return e.colors["on-primary"]}},FloatingActionButton=forwardRef((e,t)=>{const{icon:o,onPress:n,label:s,collapsed:i=!1,size:r="md",tone:a="primary",position:l,bottomOffset:c,disabled:u=!1,loading:d=!1,hideOnScroll:m=!1,isScrolling:p=!1,accessibilityLabel:b,accessibilityHint:g,haptic:f,style:h,containerStyle:y,labelStyle:A,testID:S}=e;assertValidValue("FloatingActionButton","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButton","tone",e.tone,FAB_TONES),assertValidValue("FloatingActionButton","position",e.position,FAB_POSITIONS);const x=!u&&!d,_=useTheme(),w=useSafeAreaInsets(),v=useMemo(()=>resolveFloatingActionButtonSize(_,r),[_,r]),E=useMemo(()=>buildStyles(_),[_]),{scale:R,opacity:I,pressIn:F,pressOut:C}=usePressAnimation({enabled:x}),V=usePresenceMotion(),j=_.space[_.components["floating-action-button"]["edge-offset"]],T=_.space[_.components["floating-action-button"]["bottom-offset"]],B=useRef(createAnimatedValue(1)).current,P=V.duration("default");useEffect(()=>{if(!m)return void setNativeValue(B,1);const e=Animated.timing(B,{toValue:p?0:1,duration:P,easing:Easing.bezier(..._.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[m,p,B,P,_.motion.ease["in-out"]]);const k=v.diameter+(c??T)+w.bottom+j,O=B.interpolate({inputRange:[0,1],outputRange:V.range(k,0)}),L=useMemo(()=>Animated.multiply(B,I),[B,I]),N="string"==typeof s&&s.length>0,D=N&&i,z=V.reduced,M=_.space.sm,G=v["label-padding-x"],H=_.motion.duration.fast,$=_.motion.ease["in-out"],U=useSharedValue(D?1:0),[W,Y]=useState(null);useEffect(()=>{const e=D?1:0;return U.value=z?e:withTiming(e,{duration:H,easing:ReanimatedEasing.bezier(...$)}),()=>cancelAnimation(U)},[D,z,U,H,$]);const Z=useCallback(e=>{const t=Math.ceil(e);Y(e=>e===t?e:t)},[]),q=useAnimatedStyle(()=>({paddingHorizontal:G*(1-U.value)}),[G,U]),Q=useAnimatedStyle(()=>{const e=Math.max(0,1-2*U.value);return null===W?U.value>=1?{opacity:e,width:0}:{opacity:e}:{opacity:e,width:(W+M)*(1-U.value)}},[U,W,M]),X=u?_.colors["surface-disabled"]:toneBackground(_,a),J=u?_.colors["text-disabled"]:toneForeground(_,a),K=d?_jsx(Spinner,{variant:"circular",size:"lg"===r?"md":"sm",color:J}):renderSlotIcon(o,{color:J,size:v.icon,disabled:u}),ee=useMemo(()=>{if(!l)return null;const e=(c??T)+w.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:j};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center"};default:return{position:"absolute",bottom:e,right:j}}},[l,c,w.bottom,T,j]);return _jsx(Animated.View,{style:[ee,{transform:[{translateY:O},{scale:R}],opacity:L},y,h],pointerEvents:m&&p?"none":"auto",children:_jsx(Pressable,{ref:t,onPress:e=>{if(!x)return;const t=resolveHaptic(f,"impactLight");t&&triggerHaptic(t),n()},onPressIn:F,onPressOut:C,disabled:!x,accessibilityRole:"button",accessibilityLabel:b,accessibilityHint:g,accessibilityState:{disabled:!x,busy:d},"aria-disabled":!x,"aria-busy":d,testID:S,style:[E.base,N?{height:v.diameter,minWidth:v.diameter,borderRadius:v.diameter/2,...smoothCorners}:{width:v.diameter,height:v.diameter,borderRadius:v.diameter/2,...smoothCorners},_.shadow.popover,{backgroundColor:X,opacity:u||d?.55:1}],children:({pressed:e})=>_jsxs(_Fragment,{children:[e&&x?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:pressedTintFor(_,a),borderRadius:v.diameter/2,...smoothCorners}]}):null,N?_jsxs(Reanimated.View,{style:[E.extendedRow,q],children:[K,_jsx(Reanimated.View,{style:[E.labelClip,Q],children:_jsx(Text,{onLayout:e=>Z(e.nativeEvent.layout.width),style:[E.label,{color:J,fontSize:v.text,fontWeight:_.weight.semibold,marginLeft:M},A],numberOfLines:1,children:s})})]}):K]})})})});FloatingActionButton.displayName="FloatingActionButton";const buildStyles=e=>StyleSheet.create({base:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},extendedRow:{flexDirection:"row",alignItems:"center"},labelClip:{flexDirection:"row",overflow:"hidden"},label:{includeFontPadding:!1,flexShrink:0}}),FAB_GROUP_MIN_ACTIONS=2,FAB_GROUP_MAX_ACTIONS=6,FAB_GROUP_RANGE="2 to 6",describeActionProblem=e=>e.length<2?`was given ${e.length} action(s); a menu holds 2 to 6.`:e.length>6?`was given ${e.length} actions; a menu holds 2 to 6, so only the first 6 are drawn.`:e.some(e=>"string"!=typeof e.label||""===e.label.trim())?"has an action without a visible `label`; every menu action needs one.":"";export const DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS={quickActions:"Quick actions",expanded:(e,t)=>`${e}, expanded, ${t} ${1===t?"action":"actions"}`,collapsed:e=>`${e}, collapsed`};const FloatingActionButtonGroup=e=>{const{primaryIcon:t,primaryActiveIcon:o,actions:n,expanded:s,defaultExpanded:i=!1,onExpandedChange:r,labels:a,position:l="bottomRight",bottomOffset:c,size:u="md",accessibilityLabel:d,haptic:m,hideOnScroll:p=!1,isScrolling:b=!1,containerStyle:g,secondaryActionStyle:f,labelPillStyle:h,labelStyle:y,testID:A}=e;assertValidValue("FloatingActionButtonGroup","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButtonGroup","position",e.position,FAB_POSITIONS);const S=useMemo(()=>({...DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS,...a}),[a]),x=d??S.quickActions,_=useTheme(),w=useSafeAreaInsets(),v=useMemo(()=>resolveFloatingActionButtonSize(_,u),[_,u]),E=useMemo(()=>buildGroupStyles(_),[_]),R=usePresenceMotion(),I=R.duration("default"),F=_.space[_.components["floating-action-button"]["edge-offset"]],C=_.space[_.components["floating-action-button"]["bottom-offset"]],V=_.space[_.components["floating-action-button"]["secondary-gap"]],j=_.components["floating-action-button"]["stagger-ms"],T=useMemo(()=>n.slice(0,6),[n]),B=T.length,P=useMemo(()=>T.map((e,t)=>({action:e,index:t})).reverse(),[T]);n.forEach(e=>{assertValidValue("FloatingActionButtonGroup","actions[].tone",e.tone,FAB_TONES)});const k=__DEV__?describeActionProblem(n):"";useEffect(()=>{__DEV__&&k&&Logger.warn(`[@webority/mobile-ui] FloatingActionButtonGroup ${k}`)},[k]);const O="boolean"==typeof s,[L,N]=useState(i),D=O?s:L,z=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!p)return void setNativeValue(z,1);const e=Animated.timing(z,{toValue:b?0:1,duration:I,easing:Easing.bezier(..._.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[p,b,z,I,_.motion.ease["in-out"]]);const M=p&&b;useEffect(()=>{M&&D&&(O||N(!1),r?.(!1))},[M,D,O,r]);const G=v.diameter+(c??C)+w.bottom+F,H=z.interpolate({inputRange:[0,1],outputRange:R.range(G,0)}),$=z,U=useRef(createAnimatedValue(D?1:0)).current,W=useRef([]),[Y,Z]=useState(0);useEffect(()=>{const e=W.current;if(e.length!==B){if(e.length<B){const t=e.slice();for(let o=e.length;o<B;o+=1)t.push(new Animated.Value(D?1:0));W.current=t}else W.current=e.slice(0,B);Z(e=>e+1)}},[B]),useEffect(()=>{const e=Animated.timing(U,{toValue:D?1:0,duration:I,easing:Easing.bezier(..._.motion.ease["in-out"]),useNativeDriver:!0});e.start();const t=W.current.map(e=>Animated.timing(e,{toValue:D?1:0,duration:I,easing:Easing.bezier(..._.motion.ease["in-out"]),useNativeDriver:!0})),o=D?t:[...t].reverse(),n=Animated.stagger(j,o);return n.start(),()=>{e.stop(),n.stop()}},[D,U,I,_.motion.ease["in-out"],B,Y,j]);const q=useCallback(e=>{const t=resolveHaptic(m,"impactLight");t&&triggerHaptic(t),O||N(e),r?.(e)},[O,r,m]),Q=useRef(null),X=useRef(D),J=useRef(!1);useEffect(()=>{if(X.current===D)return;X.current=D;const e=J.current;if(J.current=!1,M||e)return;const t=Q.current;t&&("web"===Platform.OS?t.focus?.():AccessibilityInfo.sendAccessibilityEvent(t,"focus")),announce(D?S.expanded(x,B):S.collapsed(x))},[D,M,x,B,S]);const K=useCallback(()=>{q(!D)},[D,q]),ee=useCallback(e=>{!1!==m&&triggerHaptic("selection"),J.current=!0,e.onPress(),O||N(!1),r?.(!1)},[O,r,m]),te=useCallback(()=>{D&&q(!1)},[D,q]);useEffect(()=>{if(!D)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(q(!1),!0));return()=>e.remove()},[D,q]),useEffect(()=>{if(!D||"web"!==Platform.OS)return;const onKeyDown=e=>{"Escape"===e.key&&q(!1)};return window.addEventListener("keydown",onKeyDown),()=>window.removeEventListener("keydown",onKeyDown)},[D,q]);const oe=useMemo(()=>{const e=(c??C)+w.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:F,alignItems:"flex-start"};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center",alignItems:"center"};default:return{position:"absolute",bottom:e,right:F,alignItems:"flex-end"}}},[l,c,w.bottom,C,F]),slotOffset=e=>-(v.diameter+V)*(e+1),ne=useMemo(()=>{switch(l){case"bottomLeft":return{left:0,right:0,justifyContent:"flex-start"};case"bottomCenter":return{left:0,right:0,justifyContent:"center"};default:return{left:0,right:0,justifyContent:"flex-end"}}},[l]),se=.78*v.diameter,ie=useMemo(()=>{const e=se+_.space.sm;switch(l){case"bottomLeft":return{left:e,alignItems:"flex-start"};case"bottomCenter":return{right:v.diameter/2+se/2+_.space.sm,alignItems:"flex-end"};default:return{right:e,alignItems:"flex-end"}}},[l,se,v.diameter,_.space.sm]),re=U.interpolate({inputRange:[0,1],outputRange:[0,.4]}),ae=U.interpolate(R.reduced?{inputRange:[0,.5,.5001,1],outputRange:["0deg","0deg","45deg","45deg"]}:{inputRange:[0,1],outputRange:["0deg","45deg"]});return _jsxs(_Fragment,{children:[D?_jsx(Animated.View,{pointerEvents:D?"auto":"none",style:[StyleSheet.absoluteFill,{backgroundColor:_.colors.scrim,opacity:re}],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:te,accessibilityElementsHidden:!0,importantForAccessibility:"no",testID:A?`${A}-backdrop`:void 0})}):null,_jsxs(Animated.View,{pointerEvents:M?"none":"box-none",style:[oe,{transform:[{translateY:H}],opacity:$},g],accessibilityRole:"menu",testID:A,children:[P.map(({action:e,index:t})=>{const o=W.current[t];if(!o)return null;const n=o.interpolate({inputRange:[0,1],outputRange:R.range(0,slotOffset(t))}),s=o.interpolate({inputRange:[0,1],outputRange:R.range(.6,1)}),i=toneBackground(_,e.tone??"primary"),r=toneForeground(_,e.tone??"primary"),a=e.label?_jsx(View,{pointerEvents:"none",style:[E.labelSlot,ie],testID:A?`${A}-label-${e.key}`:void 0,children:_jsx(View,{style:[E.labelPill,_.shadow.card,{backgroundColor:_.colors.surface,paddingHorizontal:_.space.sm,paddingVertical:_.space.xs,borderRadius:_.radius.sm,...smoothCorners},h],children:_jsx(Text,{style:[{color:_.colors["text-body"],fontSize:_.text.sm.size,fontWeight:_.weight.medium},y],numberOfLines:1,children:e.label})})}):null;return _jsxs(Animated.View,{pointerEvents:D?"auto":"none",accessibilityElementsHidden:!D,importantForAccessibility:D?"auto":"no-hide-descendants","aria-hidden":!D,style:[E.secondaryRow,ne,{position:"absolute",bottom:0,opacity:o,transform:[{translateY:n},{scale:s}]}],children:[_jsx(Pressable,{onPress:()=>ee(e),focusable:D,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel,style:[E.fabBase,_.shadow.elevated,{width:se,height:se,borderRadius:se/2,...smoothCorners,backgroundColor:i},f],testID:A?`${A}-action-${e.key}`:void 0,children:({pressed:t})=>_jsxs(_Fragment,{children:[t?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:pressedTintFor(_,e.tone??"primary"),borderRadius:se/2,...smoothCorners}]}):null,renderSlotIcon(e.icon,{color:r,size:v.icon,disabled:!1})]})}),a]},e.key)}),_jsx(Pressable,{ref:Q,onPress:K,accessibilityRole:"button",accessibilityLabel:x,accessibilityState:{expanded:D},"aria-expanded":D,style:[E.fabBase,_.shadow.popover,{width:v.diameter,height:v.diameter,borderRadius:v.diameter/2,...smoothCorners,backgroundColor:_.colors.primary}],testID:A?`${A}-primary`:void 0,children:({pressed:e})=>_jsxs(_Fragment,{children:[e?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:ACCENT_PRESSED_TINT,borderRadius:v.diameter/2,...smoothCorners}]}):null,_jsx(Animated.View,{style:o?void 0:{transform:[{rotate:ae}]},children:renderSlotIcon(D&&o?o:t,{color:_.colors["on-primary"],size:v.icon,disabled:!1})})]})})]})]})},buildGroupStyles=e=>StyleSheet.create({fabBase:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},secondaryRow:{flexDirection:"row",alignItems:"center"},labelSlot:{position:"absolute",top:0,bottom:0,justifyContent:"center"},labelPill:{alignSelf:"auto"}});export{FloatingActionButton,FloatingActionButtonGroup};export default FloatingActionButton;
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import Reanimated,{cancelAnimation,Easing as ReanimatedEasing,useAnimatedStyle,useSharedValue,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{createAnimatedValue,resolveFloatingActionButtonSize,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const FAB_SIZES=["sm","md","lg"],FAB_TONES=["primary","success","warning","danger","info","neutral"],FAB_POSITIONS=["bottomRight","bottomLeft","bottomCenter"],toneBackground=(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["bg-muted"];default:return e.colors.primary}},pressedTintFor=(e,t)=>"neutral"===t?e.colors["surface-pressed"]:ACCENT_PRESSED_TINT,toneForeground=(e,t)=>{if("neutral"===t)return e.colors["text-body"];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"];default:return e.colors["on-primary"]}},FloatingActionButton=forwardRef((e,t)=>{const{icon:o,onPress:n,label:i,collapsed:s=!1,size:r="md",tone:a="primary",position:l,bottomOffset:c,disabled:u=!1,loading:d=!1,hideOnScroll:m=!1,isScrolling:p=!1,accessibilityLabel:b,accessibilityHint:f,haptic:g,style:h,containerStyle:y,labelStyle:A,testID:S}=e;assertValidValue("FloatingActionButton","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButton","tone",e.tone,FAB_TONES),assertValidValue("FloatingActionButton","position",e.position,FAB_POSITIONS);const v=!u&&!d,x=useTheme(),_=useSafeAreaInsets(),w=useMemo(()=>resolveFloatingActionButtonSize(x,r),[x,r]),E=useMemo(()=>buildStyles(x),[x]),{scale:R,opacity:I,pressIn:F,pressOut:C}=usePressAnimation({enabled:v}),V=usePresenceMotion(),j=x.space[x.components["floating-action-button"]["edge-offset"]],T=x.space[x.components["floating-action-button"]["bottom-offset"]],B=useRef(createAnimatedValue(1)).current,P=V.duration("default");useEffect(()=>{if(!m)return void setNativeValue(B,1);const e=Animated.timing(B,{toValue:p?0:1,duration:P,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[m,p,B,P,x.motion.ease["in-out"]]);const k=w.diameter+(c??T)+_.bottom+j,D=B.interpolate({inputRange:[0,1],outputRange:V.range(k,0)}),O=useMemo(()=>Animated.multiply(B,I),[B,I]),L="string"==typeof i&&i.length>0,N=L&&s,z=V.reduced,M=x.space.sm,G=w["label-padding-x"],H=x.motion.duration.fast,$=x.motion.ease["in-out"],U=useSharedValue(N?1:0),[W,Y]=useState(null);useEffect(()=>{const e=N?1:0;return U.value=z?e:withTiming(e,{duration:H,easing:ReanimatedEasing.bezier(...$)}),()=>cancelAnimation(U)},[N,z,U,H,$]);const Z=useCallback(e=>{const t=Math.ceil(e);Y(e=>e===t?e:t)},[]),q=useAnimatedStyle(()=>({paddingHorizontal:G*(1-U.value)}),[G,U]),Q=useAnimatedStyle(()=>{const e=Math.max(0,1-2*U.value);return null===W?U.value>=1?{opacity:e,width:0}:{opacity:e}:{opacity:e,width:(W+M)*(1-U.value)}},[U,W,M]),X=u?x.colors["surface-disabled"]:toneBackground(x,a),J=u?x.colors["text-disabled"]:toneForeground(x,a),K=d?_jsx(Spinner,{variant:"circular",size:"lg"===r?"md":"sm",color:J}):renderSlotIcon(o,{color:J,size:w.icon,disabled:u}),ee=useMemo(()=>{if(!l)return null;const e=(c??T)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:j};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center"};default:return{position:"absolute",bottom:e,right:j}}},[l,c,_.bottom,T,j]);return _jsx(Animated.View,{style:[ee,{transform:[{translateY:D},{scale:R}],opacity:O},y,h],pointerEvents:m&&p?"none":"auto",children:_jsx(Pressable,{ref:t,onPress:e=>{if(!v)return;const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t),n()},onPressIn:F,onPressOut:C,disabled:!v,accessibilityRole:"button",accessibilityLabel:b,accessibilityHint:f,accessibilityState:{disabled:!v,busy:d},"aria-disabled":!v,"aria-busy":d,testID:S,style:[E.base,L?{height:w.diameter,minWidth:w.diameter,borderRadius:w.diameter/2,...smoothCorners}:{width:w.diameter,height:w.diameter,borderRadius:w.diameter/2,...smoothCorners},x.shadow.popover,{backgroundColor:X,opacity:u||d?.55:1}],children:({pressed:e})=>_jsxs(_Fragment,{children:[e&&v?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:pressedTintFor(x,a),borderRadius:w.diameter/2,...smoothCorners}]}):null,L?_jsxs(Reanimated.View,{style:[E.extendedRow,q],children:[K,_jsx(Reanimated.View,{style:[E.labelClip,Q],children:_jsx(Text,{onLayout:e=>Z(e.nativeEvent.layout.width),style:[E.label,{color:J,fontSize:w.text,fontWeight:x.weight.semibold,marginLeft:M},A],numberOfLines:1,children:i})})]}):K]})})})});FloatingActionButton.displayName="FloatingActionButton";const buildStyles=e=>StyleSheet.create({base:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},extendedRow:{flexDirection:"row",alignItems:"center"},labelClip:{flexDirection:"row",overflow:"hidden"},label:{includeFontPadding:!1,flexShrink:0}}),FAB_GROUP_MIN_ACTIONS=2,FAB_GROUP_MAX_ACTIONS=6,FAB_GROUP_RANGE="2 to 6",describeActionProblem=e=>e.length<2?`was given ${e.length} action(s); a menu holds 2 to 6.`:e.length>6?`was given ${e.length} actions; a menu holds 2 to 6, so only the first 6 are drawn.`:e.some(e=>"string"!=typeof e.label||""===e.label.trim())?"has an action without a visible `label`; every menu action needs one.":"";export const DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS={quickActions:"Quick actions",expanded:(e,t)=>`${e}, expanded, ${t} ${1===t?"action":"actions"}`,collapsed:e=>`${e}, collapsed`};const FloatingActionButtonGroup=e=>{const{primaryIcon:t,primaryActiveIcon:o,actions:n,expanded:i,defaultExpanded:s=!1,onExpandedChange:r,labels:a,position:l="bottomRight",bottomOffset:c,size:u="md",accessibilityLabel:d,haptic:m,hideOnScroll:p=!1,isScrolling:b=!1,containerStyle:f,secondaryActionStyle:g,labelPillStyle:h,labelStyle:y,testID:A}=e;assertValidValue("FloatingActionButtonGroup","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButtonGroup","position",e.position,FAB_POSITIONS);const S=useMemo(()=>({...DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS,...a}),[a]),v=d??S.quickActions,x=useTheme(),_=useSafeAreaInsets(),w=useMemo(()=>resolveFloatingActionButtonSize(x,u),[x,u]),E=useMemo(()=>buildGroupStyles(x),[x]),R=usePresenceMotion(),I=R.duration("default"),F=x.space[x.components["floating-action-button"]["edge-offset"]],C=x.space[x.components["floating-action-button"]["bottom-offset"]],V=x.space[x.components["floating-action-button"]["secondary-gap"]],j=x.components["floating-action-button"]["stagger-ms"],T=useMemo(()=>n.slice(0,6),[n]),B=T.length,P=useMemo(()=>T.map((e,t)=>({action:e,index:t})).reverse(),[T]);n.forEach(e=>{assertValidValue("FloatingActionButtonGroup","actions[].tone",e.tone,FAB_TONES)});const k=__DEV__?describeActionProblem(n):"";useEffect(()=>{__DEV__&&k&&Logger.warn(`[@webority/mobile-ui] FloatingActionButtonGroup ${k}`)},[k]);const D="boolean"==typeof i,[O,L]=useState(s),N=D?i:O,z=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!p)return void setNativeValue(z,1);const e=Animated.timing(z,{toValue:b?0:1,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[p,b,z,I,x.motion.ease["in-out"]]);const M=p&&b;useEffect(()=>{M&&N&&(D||L(!1),r?.(!1))},[M,N,D,r]);const G=w.diameter+(c??C)+_.bottom+F,H=z.interpolate({inputRange:[0,1],outputRange:R.range(G,0)}),$=z,U=useRef(createAnimatedValue(N?1:0)).current,W=useRef([]),[Y,Z]=useState(0);useEffect(()=>{const e=W.current;if(e.length!==B){if(e.length<B){const t=e.slice();for(let o=e.length;o<B;o+=1)t.push(new Animated.Value(N?1:0));W.current=t}else W.current=e.slice(0,B);Z(e=>e+1)}},[B]),useEffect(()=>{const e=Animated.timing(U,{toValue:N?1:0,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});e.start();const t=W.current.map(e=>Animated.timing(e,{toValue:N?1:0,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver})),o=N?t:[...t].reverse(),n=Animated.stagger(j,o);return n.start(),()=>{e.stop(),n.stop()}},[N,U,I,x.motion.ease["in-out"],B,Y,j]);const q=useCallback(e=>{const t=resolveHaptic(m,"impactLight");t&&triggerHaptic(t),D||L(e),r?.(e)},[D,r,m]),Q=useRef(null),X=useRef(N),J=useRef(!1);useEffect(()=>{if(X.current===N)return;X.current=N;const e=J.current;if(J.current=!1,M||e)return;const t=Q.current;t&&("web"===Platform.OS?t.focus?.():AccessibilityInfo.sendAccessibilityEvent(t,"focus")),announce(N?S.expanded(v,B):S.collapsed(v))},[N,M,v,B,S]);const K=useCallback(()=>{q(!N)},[N,q]),ee=useCallback(e=>{!1!==m&&triggerHaptic("selection"),J.current=!0,e.onPress(),D||L(!1),r?.(!1)},[D,r,m]),te=useCallback(()=>{N&&q(!1)},[N,q]);useEffect(()=>{if(!N)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(q(!1),!0));return()=>e.remove()},[N,q]),useEffect(()=>{if(!N||"web"!==Platform.OS)return;const onKeyDown=e=>{"Escape"===e.key&&q(!1)};return window.addEventListener("keydown",onKeyDown),()=>window.removeEventListener("keydown",onKeyDown)},[N,q]);const oe=useMemo(()=>{const e=(c??C)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:F,alignItems:"flex-start"};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center",alignItems:"center"};default:return{position:"absolute",bottom:e,right:F,alignItems:"flex-end"}}},[l,c,_.bottom,C,F]),slotOffset=e=>-(w.diameter+V)*(e+1),ne=useMemo(()=>{switch(l){case"bottomLeft":return{left:0,right:0,justifyContent:"flex-start"};case"bottomCenter":return{left:0,right:0,justifyContent:"center"};default:return{left:0,right:0,justifyContent:"flex-end"}}},[l]),ie=.78*w.diameter,se=useMemo(()=>{const e=ie+x.space.sm;switch(l){case"bottomLeft":return{left:e,alignItems:"flex-start"};case"bottomCenter":return{right:w.diameter/2+ie/2+x.space.sm,alignItems:"flex-end"};default:return{right:e,alignItems:"flex-end"}}},[l,ie,w.diameter,x.space.sm]),re=U.interpolate({inputRange:[0,1],outputRange:[0,.4]}),ae=U.interpolate(R.reduced?{inputRange:[0,.5,.5001,1],outputRange:["0deg","0deg","45deg","45deg"]}:{inputRange:[0,1],outputRange:["0deg","45deg"]});return _jsxs(_Fragment,{children:[N?_jsx(Animated.View,{pointerEvents:N?"auto":"none",style:[StyleSheet.absoluteFill,{backgroundColor:x.colors.scrim,opacity:re}],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:te,accessibilityElementsHidden:!0,importantForAccessibility:"no",testID:A?`${A}-backdrop`:void 0})}):null,_jsxs(Animated.View,{pointerEvents:M?"none":"box-none",style:[oe,{transform:[{translateY:H}],opacity:$},f],accessibilityRole:"menu",testID:A,children:[P.map(({action:e,index:t})=>{const o=W.current[t];if(!o)return null;const n=o.interpolate({inputRange:[0,1],outputRange:R.range(0,slotOffset(t))}),i=o.interpolate({inputRange:[0,1],outputRange:R.range(.6,1)}),s=toneBackground(x,e.tone??"primary"),r=toneForeground(x,e.tone??"primary"),a=e.label?_jsx(View,{pointerEvents:"none",style:[E.labelSlot,se],testID:A?`${A}-label-${e.key}`:void 0,children:_jsx(View,{style:[E.labelPill,x.shadow.card,{backgroundColor:x.colors.surface,paddingHorizontal:x.space.sm,paddingVertical:x.space.xs,borderRadius:x.radius.sm,...smoothCorners},h],children:_jsx(Text,{style:[{color:x.colors["text-body"],fontSize:x.text.sm.size,fontWeight:x.weight.medium},y],numberOfLines:1,children:e.label})})}):null;return _jsxs(Animated.View,{pointerEvents:N?"auto":"none",accessibilityElementsHidden:!N,importantForAccessibility:N?"auto":"no-hide-descendants","aria-hidden":!N,style:[E.secondaryRow,ne,{position:"absolute",bottom:0,opacity:o,transform:[{translateY:n},{scale:i}]}],children:[_jsx(Pressable,{onPress:()=>ee(e),focusable:N,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel,style:[E.fabBase,x.shadow.elevated,{width:ie,height:ie,borderRadius:ie/2,...smoothCorners,backgroundColor:s},g],testID:A?`${A}-action-${e.key}`:void 0,children:({pressed:t})=>_jsxs(_Fragment,{children:[t?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:pressedTintFor(x,e.tone??"primary"),borderRadius:ie/2,...smoothCorners}]}):null,renderSlotIcon(e.icon,{color:r,size:w.icon,disabled:!1})]})}),a]},e.key)}),_jsx(Pressable,{ref:Q,onPress:K,accessibilityRole:"button",accessibilityLabel:v,accessibilityState:{expanded:N},"aria-expanded":N,style:[E.fabBase,x.shadow.popover,{width:w.diameter,height:w.diameter,borderRadius:w.diameter/2,...smoothCorners,backgroundColor:x.colors.primary}],testID:A?`${A}-primary`:void 0,children:({pressed:e})=>_jsxs(_Fragment,{children:[e?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:ACCENT_PRESSED_TINT,borderRadius:w.diameter/2,...smoothCorners}]}):null,_jsx(Animated.View,{style:o?void 0:{transform:[{rotate:ae}]},children:renderSlotIcon(N&&o?o:t,{color:x.colors["on-primary"],size:w.icon,disabled:!1})})]})})]})]})},buildGroupStyles=e=>StyleSheet.create({fabBase:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},secondaryRow:{flexDirection:"row",alignItems:"center"},labelSlot:{position:"absolute",top:0,bottom:0,justifyContent:"center"},labelPill:{alignSelf:"auto"}});export{FloatingActionButton,FloatingActionButtonGroup};export default FloatingActionButton;
@@ -1 +1 @@
1
- "use strict";import React,{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,StyleSheet,Text,View}from"react-native";import{useFieldErrorAnchor}from"../../hooks/useFieldErrorScroll.js";import{createAnimatedValue,fontFor,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{fieldTextAsString,hasFieldText,RequiredMark}from"../FieldBase/index.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_FORM_FIELD_LABELS={labelWithError:(e,t)=>`${e}, error: ${t}`};const FormField=forwardRef((e,t)=>{assertValidValue("FormField","layout",e.layout,["stacked","inline"]);const{label:l,help:i,helperText:r,error:s,required:n=!1,children:o,layout:a="stacked",helperLines:d,labelStyle:x,helperStyle:c,errorStyle:u,containerStyle:m,inputContainerStyle:h,accessibilityLabel:f,labels:p,testID:F}=e,T=useFieldErrorAnchor(hasFieldText(s),t),S=useTheme(),b=useMemo(()=>buildStyles(S),[S]),y=useMemo(()=>({...DEFAULT_FORM_FIELD_LABELS,...p}),[p]),k=fieldTextAsString(s),I=useRef(createAnimatedValue(s?1:0)).current;useEffect(()=>{const e=Animated.timing(I,{toValue:s?1:0,duration:S.motion.duration.fast,useNativeDriver:!0});return e.start(),()=>e.stop()},[s,I,S.motion.duration.fast]);const j=useMemo(()=>{if(f)return f;const e=fieldTextAsString(l);return e?k?y.labelWithError(e,k):e:void 0},[f,l,k,y]),_=useTextInk(x,S.text.sm.size,S.colors["text-muted"]),E=useTextInk(c,S.text.sm.size,S.colors["text-subtle"]),L=useTextInk(u,S.text.sm.size,S.colors["danger-text"]),V=hasFieldText(l),v=_jsxs(Text,{style:[b.label,"inline"!==a||hasFieldText(i)?null:b.labelInline,hasFieldText(i)?b.labelShrink:null,x],children:[_jsx(TextInkContext.Provider,{value:_,children:l}),n?_jsx(RequiredMark,{}):null]}),w=V?hasFieldText(i)?_jsxs(View,{style:[b.labelRow,"inline"===a?b.labelInline:null],children:[v,_jsx(View,{style:[b.help,{marginLeft:S.space.xs}],children:i})]}):v:null,A="inline"===a?b.inputInline:b.inputStacked,R=hasFieldText(s),g=!R&&hasFieldText(r),D=n&&!V&&React.isValidElement(o)?React.cloneElement(o,{required:!0}):o;return _jsxs(View,{ref:T,style:["inline"===a?b.rootInline:b.rootStacked,m],accessibilityLabel:j,accessibilityHint:k||void 0,testID:F,children:[w,_jsx(View,{style:[A,h],children:D}),g?_jsx(Text,{style:[b.helper,c],numberOfLines:d||void 0,children:_jsx(TextInkContext.Provider,{value:E,children:r})}):null,R?_jsx(Animated.Text,{style:[b.error,{opacity:I},u],numberOfLines:d||void 0,accessibilityLiveRegion:"polite",children:_jsx(TextInkContext.Provider,{value:L,children:s})}):null]})});FormField.displayName="FormField";const buildStyles=e=>StyleSheet.create({rootStacked:{flexDirection:"column",gap:e.space.xs},rootInline:{flexDirection:"row",alignItems:"center",flexWrap:"wrap",gap:e.space.xs},label:{fontSize:e.text.sm.size,...fontFor(e,"medium"),color:e.colors["text-muted"]},labelShrink:{flexShrink:1},labelRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},labelInline:{width:"35%"},inputStacked:{width:"100%"},inputInline:{flex:1,minWidth:0},helper:{fontSize:e.text.sm.size,color:e.colors["text-subtle"]},error:{fontSize:e.text.sm.size,color:e.colors["danger-text"]}});export{FormField};export default FormField;
1
+ "use strict";import React,{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,StyleSheet,Text,View}from"react-native";import{useFieldErrorAnchor}from"../../hooks/useFieldErrorScroll.js";import{createAnimatedValue,fontFor,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{fieldTextAsString,hasFieldText,RequiredMark}from"../FieldBase/index.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_FORM_FIELD_LABELS={labelWithError:(e,t)=>`${e}, error: ${t}`};const FormField=forwardRef((e,t)=>{assertValidValue("FormField","layout",e.layout,["stacked","inline"]);const{label:i,help:r,helperText:l,error:s,required:n=!1,children:o,layout:a="stacked",helperLines:d,labelStyle:x,helperStyle:c,errorStyle:u,containerStyle:m,inputContainerStyle:h,accessibilityLabel:f,labels:p,testID:F}=e,T=useFieldErrorAnchor(hasFieldText(s),t),S=useTheme(),b=useMemo(()=>buildStyles(S),[S]),y=useMemo(()=>({...DEFAULT_FORM_FIELD_LABELS,...p}),[p]),j=fieldTextAsString(s),k=useRef(createAnimatedValue(s?1:0)).current;useEffect(()=>{const e=Animated.timing(k,{toValue:s?1:0,duration:S.motion.duration.fast,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[s,k,S.motion.duration.fast]);const I=useMemo(()=>{if(f)return f;const e=fieldTextAsString(i);return e?j?y.labelWithError(e,j):e:void 0},[f,i,j,y]),v=useTextInk(x,S.text.sm.size,S.colors["text-muted"]),_=useTextInk(c,S.text.sm.size,S.colors["text-subtle"]),E=useTextInk(u,S.text.sm.size,S.colors["danger-text"]),L=hasFieldText(i),V=_jsxs(Text,{style:[b.label,"inline"!==a||hasFieldText(r)?null:b.labelInline,hasFieldText(r)?b.labelShrink:null,x],children:[_jsx(TextInkContext.Provider,{value:v,children:i}),n?_jsx(RequiredMark,{}):null]}),w=L?hasFieldText(r)?_jsxs(View,{style:[b.labelRow,"inline"===a?b.labelInline:null],children:[V,_jsx(View,{style:[b.help,{marginLeft:S.space.xs}],children:r})]}):V:null,A="inline"===a?b.inputInline:b.inputStacked,R=hasFieldText(s),D=!R&&hasFieldText(l),g=n&&!L&&React.isValidElement(o)?React.cloneElement(o,{required:!0}):o;return _jsxs(View,{ref:T,style:["inline"===a?b.rootInline:b.rootStacked,m],accessibilityLabel:I,accessibilityHint:j||void 0,testID:F,children:[w,_jsx(View,{style:[A,h],children:g}),D?_jsx(Text,{style:[b.helper,c],numberOfLines:d||void 0,children:_jsx(TextInkContext.Provider,{value:_,children:l})}):null,R?_jsx(Animated.Text,{style:[b.error,{opacity:k},u],numberOfLines:d||void 0,accessibilityLiveRegion:"polite",children:_jsx(TextInkContext.Provider,{value:E,children:s})}):null]})});FormField.displayName="FormField";const buildStyles=e=>StyleSheet.create({rootStacked:{flexDirection:"column",gap:e.space.xs},rootInline:{flexDirection:"row",alignItems:"center",flexWrap:"wrap",gap:e.space.xs},label:{fontSize:e.text.sm.size,...fontFor(e,"medium"),color:e.colors["text-muted"]},labelShrink:{flexShrink:1},labelRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},labelInline:{width:"35%"},inputStacked:{width:"100%"},inputInline:{flex:1,minWidth:0},helper:{fontSize:e.text.sm.size,color:e.colors["text-subtle"]},error:{fontSize:e.text.sm.size,color:e.colors["danger-text"]}});export{FormField};export default FormField;