@webority/mobile-ui 0.150.0 → 0.152.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 (68) hide show
  1. package/dist/canvas-kit/kit.js +10 -10
  2. package/dist/canvas-kit/manifest.json +139 -17
  3. package/dist/canvas-kit/release.json +6 -6
  4. package/lib/commonjs/components/AppBar/AppBar.js +1 -1
  5. package/lib/commonjs/components/AsyncBlock/AsyncBlock.js +1 -1
  6. package/lib/commonjs/components/Avatar/Avatar.js +1 -1
  7. package/lib/commonjs/components/Banner/Banner.js +1 -1
  8. package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
  9. package/lib/commonjs/components/Button/Button.js +1 -1
  10. package/lib/commonjs/components/Calendar/calendarStyles.js +1 -1
  11. package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
  12. package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
  13. package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
  14. package/lib/commonjs/components/NonModalBottomSheet/NonModalBottomSheet.js +1 -0
  15. package/lib/commonjs/components/NonModalBottomSheet/index.js +1 -0
  16. package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
  17. package/lib/commonjs/components/OptionSheet/optionAccessors.js +1 -1
  18. package/lib/commonjs/components/Repeater/Repeater.js +1 -1
  19. package/lib/commonjs/components/Toast/Toast.js +1 -1
  20. package/lib/commonjs/components/WheelPicker/Wheel.js +1 -1
  21. package/lib/commonjs/components/WheelPicker/WheelPicker.js +1 -1
  22. package/lib/commonjs/components/index.js +1 -1
  23. package/lib/commonjs/index.js +1 -1
  24. package/lib/commonjs/theme/tokens.generated.js +1 -1
  25. package/lib/module/components/AppBar/AppBar.js +1 -1
  26. package/lib/module/components/AsyncBlock/AsyncBlock.js +1 -1
  27. package/lib/module/components/Avatar/Avatar.js +1 -1
  28. package/lib/module/components/Banner/Banner.js +1 -1
  29. package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
  30. package/lib/module/components/Button/Button.js +1 -1
  31. package/lib/module/components/Calendar/calendarStyles.js +1 -1
  32. package/lib/module/components/DatePicker/DatePicker.js +1 -1
  33. package/lib/module/components/FilePicker/FilePicker.js +1 -1
  34. package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
  35. package/lib/module/components/NonModalBottomSheet/NonModalBottomSheet.js +1 -0
  36. package/lib/module/components/NonModalBottomSheet/index.js +1 -0
  37. package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
  38. package/lib/module/components/OptionSheet/optionAccessors.js +1 -1
  39. package/lib/module/components/Repeater/Repeater.js +1 -1
  40. package/lib/module/components/Toast/Toast.js +1 -1
  41. package/lib/module/components/WheelPicker/Wheel.js +1 -1
  42. package/lib/module/components/WheelPicker/WheelPicker.js +1 -1
  43. package/lib/module/components/index.js +1 -1
  44. package/lib/module/index.js +1 -1
  45. package/lib/module/theme/tokens.generated.js +1 -1
  46. package/lib/typescript/commonjs/components/AsyncBlock/AsyncBlock.d.ts +2 -2
  47. package/lib/typescript/commonjs/components/Avatar/Avatar.d.ts +5 -3
  48. package/lib/typescript/commonjs/components/Button/Button.d.ts +7 -2
  49. package/lib/typescript/commonjs/components/NonModalBottomSheet/NonModalBottomSheet.d.ts +52 -0
  50. package/lib/typescript/commonjs/components/NonModalBottomSheet/index.d.ts +3 -0
  51. package/lib/typescript/commonjs/components/OptionSheet/OptionSheet.d.ts +6 -1
  52. package/lib/typescript/commonjs/components/OptionSheet/optionAccessors.d.ts +1 -0
  53. package/lib/typescript/commonjs/components/WheelPicker/Wheel.d.ts +4 -0
  54. package/lib/typescript/commonjs/components/WheelPicker/WheelPicker.d.ts +2 -0
  55. package/lib/typescript/commonjs/components/index.d.ts +2 -0
  56. package/lib/typescript/commonjs/index.d.ts +1 -1
  57. package/lib/typescript/module/components/AsyncBlock/AsyncBlock.d.ts +2 -2
  58. package/lib/typescript/module/components/Avatar/Avatar.d.ts +5 -3
  59. package/lib/typescript/module/components/Button/Button.d.ts +7 -2
  60. package/lib/typescript/module/components/NonModalBottomSheet/NonModalBottomSheet.d.ts +52 -0
  61. package/lib/typescript/module/components/NonModalBottomSheet/index.d.ts +3 -0
  62. package/lib/typescript/module/components/OptionSheet/OptionSheet.d.ts +6 -1
  63. package/lib/typescript/module/components/OptionSheet/optionAccessors.d.ts +1 -0
  64. package/lib/typescript/module/components/WheelPicker/Wheel.d.ts +4 -0
  65. package/lib/typescript/module/components/WheelPicker/WheelPicker.d.ts +2 -0
  66. package/lib/typescript/module/components/index.d.ts +2 -0
  67. package/lib/typescript/module/index.d.ts +1 -1
  68. package/package.json +7 -7
@@ -1 +1 @@
1
- "use strict";import React,{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,LayoutAnimation,Platform,Pressable,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{renderSlotIcon}from"../AppIcon/index.js";import{Badge}from"../Badge/index.js";import{Text}from"../Text/index.js";import{useScreenReaderEnabled}from"./useScreenReaderEnabled.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BOTTOM_NAVIGATION_LABELS=Object.freeze({switchesTo:e=>`Switches to ${e}`,unread:e=>`${e} unread`,newUpdates:"new updates"});const DEFAULT_ICON_SIZE=18,DEFAULT_LABEL_MAX_FONT_SCALE=1.2,ICON_WRAP_AIR=4,PILL_AIR=8,DEFAULT_PILL_MAX_WIDTH=64,TILE_MAX_WIDTH=96,DEFAULT_UNDERLINE_HEIGHT=3,DEFAULT_BUBBLE_SIZE=48,DEFAULT_BUBBLE_LIFT=14,DEFAULT_CENTER_SIZE=48,DEFAULT_CENTER_ICON_SIZE=24,CENTER_KEY="__center_action__",EXPANDED_FLEX=1.5,SOLID_INACTIVE_OPACITY=.7,TILE_INSET=2,badgeVariantOf=e=>null==e||!1===e?null:!0===e||"·"===e?"dot":"number"==typeof e?e>0?"standard":null:e.length>0?"standard":null,badgeAccessibilitySuffix=(e,t)=>null==e||!1===e?"":"number"==typeof e?e>0?`, ${t.unread(e)}`:"":!0===e||"·"===e?`, ${t.newUpdates}`:"string"==typeof e&&e.length>0?`, ${e}`:"",BottomNavigation=forwardRef((e,t)=>{const{tabs:i,centerAction:n,activeTab:o,onChange:a,haptic:r="selection",showLabels:s=!0,variant:l="pill",indicatorPosition:d="bottom",radius:c,indicatorRadius:u="auto",elevation:p,iconSize:m,marginHorizontal:h,marginVertical:g,paddingHorizontal:b,paddingVertical:f,border:x,minimizeOnScroll:y=!1,scrollDirection:_="idle",accessory:S,style:v,indicatorStyle:w,labelStyle:A,labelMaxFontScale:E,labels:I,testID:R}=e;assertValidValue("BottomNavigation","variant",e.variant,["pill","underline","floating","bubble","expand","solid","tile"]),assertValidValue("BottomNavigation","indicatorPosition",e.indicatorPosition,["top","bottom"]);const T=useMemo(()=>I?{...DEFAULT_BOTTOM_NAVIGATION_LABELS,...I}:DEFAULT_BOTTOM_NAVIGATION_LABELS,[I]),V=useTheme(),j=useSafeAreaInsets(),L=useMemo(()=>buildStyles(V),[V]),B=m??18,D=B+4+8,C=V.space.lg,M=V.space.lg,k=V.radius.xl,N=useReducedMotion(),P=useScreenReaderEnabled(y),[z,F]=React.useState(null);useEffect(()=>{null!==z&&z!==_&&F(null)},[z,_]);const H=y&&!P&&"down"===_&&null===z,[O,W]=React.useState(H);useEffect(()=>{O!==H&&(N||"web"===Platform.OS||LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut),W(H))},[O,H,N]);const U="function"==typeof S?S({minimized:O}):S,$=null!=U&&!1!==U,X=O&&$,[G,Z]=React.useState(0),Y=$&&!X?G+V.space.xs:0,K="tile"===l,q="floating"===l||K,J="bubble"===l,Q="expand"===l,ee="solid"===l,te="pill"===l||q||ee,ie=Math.max(0,i.findIndex(e=>e.key===o)),[ne,oe]=React.useState(0),[ae,re]=React.useState(0),se=n?Math.ceil(i.length/2):i.length,le=i.length+(n?1:0),[de,ce]=React.useState({width:0,height:0}),ue=n?.size??48,pe=void 0!==n?.gap,me=Math.max(0,n?.gap??0),he=pe?(de.width||ue)+2*me:0,ge=pe?i.length>0?Math.max(0,ne-he)/i.length:0:le>0?ne/le:0,be=pe?he:ge,fe=useRef(createAnimatedValue(ie)).current,xe=useRef({}),ye=useRef({});i.forEach(e=>{xe.current[e.key]||(xe.current[e.key]=new Animated.Value(1)),ye.current[e.key]||(ye.current[e.key]=createAnimatedValue(e.key===o?1:0))});const Se=ge>0?K?Math.min(ge-4,96):Math.min(ge-C,64):0,ve=ge>0?(ge-Se)/2:0,we=ge>0?(ge-48)/2:0,hasLabel=e=>s&&!O&&!1!==e.showLabel&&e.label.trim().length>0,Ae=i[ie],Ee=Ae&&!hasLabel(Ae)&&ae>0?ae/2:V.space.xs+(B+4)/2,Ie=Ee-14-24,Re=Math.max(0,ae-4),Te=K?2:Ee-D/2,Ve=useRef(ie);useEffect(()=>{if(Ve.current===ie)return;Ve.current=ie;const e=Animated.spring(fe,{toValue:ie,tension:120,friction:14,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[ie,fe]);const je=Math.max(1,i.length-1),Le=useMemo(()=>{const e=[],t=[];for(let i=0;i<=je;i++)e.push(i),t.push(i<se?i*ge:i*ge+be);return fe.interpolate({inputRange:e,outputRange:t})},[fe,je,se,ge,be]),Be=i.map(e=>e.key).join(" "),De=J||Q;useEffect(()=>{const e=Be.split(" ").flatMap(e=>{const t=e===o?1:0,i=ye.current[e];return i?De?[Animated.spring(i,{toValue:t,tension:140,friction:13,useNativeDriver:!1})]:(i.setValue(t),[]):[]});if(0===e.length)return;const t=Animated.parallel(e);return t.start(),()=>t.stop()},[o,Be,De]);const popIcon=e=>{Animated.sequence([Animated.timing(e,{toValue:1.15,duration:120,useNativeDriver:nativeDriver}),Animated.spring(e,{toValue:1,tension:200,friction:8,useNativeDriver:nativeDriver})]).start()},Ce=useRef(new Animated.Value(1)).current,{colors:Me}=V,ke=ee?Me.primary:Me.surface,Ne=ee?Me["on-primary"]:Me.primary,Pe=ee?Me["on-primary"]:K?Me["text-body"]:Me["text-subtle"],ze=ee?Me["on-primary"]:Me["primary-soft"],Fe=ee?Me.primary:J?Me["on-primary"]:Ne,He=h??M,Oe=g??(q?M:0),We=Oe>0,Ue=f??V.space.sm,$e=b??(q?V.space.sm:V.space.xs),Xe=We?Ue:Math.max(Ue,j.bottom),Ge=We?Math.max(Oe,j.bottom>0?j.bottom+V.space.sm:0):0,Ze="pill"===c,Ye=q?ae+Y+2*Ue+2*StyleSheet.hairlineWidth:ae+Y+Ue+Xe,Ke=Ze?ae>0?Ye/2:V.radius.pill:c??(K?V.radius.pill:q?k:V.radius.none),qe=void 0!==c,activeBgRadius=(e,t)=>"number"==typeof u?Math.max(0,Math.min(u,e/2)):"auto"===u&&qe?Math.min(Ke,e/2):t,Je="underline"===l?Math.max($e,Ze&&0===ae?0:Ke):$e,Qe=p??"none",et="none"===Qe?void 0:V.shadow[Qe],tt=void 0===et?null:supportsBoxShadow()?{boxShadow:toBoxShadow(et)}:et,it=x?StyleSheet.hairlineWidth:0,nt=ee?Me.primary:Me.border,ot=n?.lift??0,at=Ue+it+Y,rt=n&&ae>0?Math.max(0,(de.height||ue)/2+ot-ae/2-at):0,st=n?_jsx(View,{style:[L.centerCell,pe?{flex:0,marginHorizontal:me}:null],pointerEvents:"box-none",children:_jsxs(Pressable,{onPress:()=>{if(!n)return;const e=n.haptic??r;!1!==e&&triggerHaptic(e),popIcon(Ce),n.onPress()},onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;ce(e=>e.width===t&&e.height===i?e:{width:t,height:i})},accessibilityRole:"button",accessibilityLabel:n.label,hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[L.centerPressable,{top:-ot},e?{opacity:.85}:null],testID:n.testID??(R?`${R}-center`:void 0),children:[n.content?_jsx(Animated.View,{style:{transform:[{scale:Ce}]},children:n.content}):_jsx(View,{style:[L.centerCircle,{width:ue,height:ue,borderRadius:V.radius.pill,...smoothCorners,backgroundColor:n.color??Me.primary}],children:_jsx(Animated.View,{style:{transform:[{scale:Ce}]},children:renderSlotIcon(n.icon??"add",{color:n.iconColor??Me["on-primary"],size:n.iconSize??24,disabled:!1})})}),(lt=n,s&&!O&&lt.label.trim().length>0?_jsx(Text,{variant:"caption",numberOfLines:1,maxFontSizeMultiplier:E??V.settings.maxFontSizeMultiplier??1.2,style:[L.label,{color:Pe,opacity:ee?.7:1},A],children:n.label}):null)]})},CENTER_KEY):null;var lt;const dt=$?_jsx(View,{style:X?L.accessoryInline:L.accessoryStacked,onLayout:e=>Z(e.nativeEvent.layout.height),testID:R?`${R}-accessory`:void 0,children:U}):null,ct=_jsxs(View,{style:X?[L.tabRow,L.tabRowInline]:L.tabRow,onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;oe(t),re(i)},children:[te&&Se>0&&(!K||Re>0)?_jsx(Animated.View,{pointerEvents:"none",style:[L.pill,{width:Se,height:K?Re:D,left:ve,top:Te,backgroundColor:ze,borderRadius:K?activeBgRadius(Re,Re/2):activeBgRadius(D,V.radius.pill),...smoothCorners,transform:[{translateX:Le}]},w]}):null,J&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[L.bubble,V.shadow.elevated,{width:48,height:48,borderRadius:V.radius.pill,...smoothCorners,left:we,top:Ie,backgroundColor:Me.primary,borderColor:Me.surface,transform:[{translateX:Le}]},w]}):null,(ut=i.map(e=>{const t=e.key===o,i=t?Ne:Pe,n=t?Fe:Pe,s="string"==typeof e.icon?{name:e.icon,variant:"bold"}:e.icon,l=t?e.activeIcon??s:e.icon,d=xe.current[e.key],c=ye.current[e.key];if(void 0===d||void 0===c)throw new Error(`BottomNavigation has no animation values for tab "${e.key}".`);const u=badgeVariantOf(e.badge??null),p=badgeAccessibilitySuffix(e.badge??null,T),m=ee&&!t?.7:1,h=J&&t||ee?Me.primary:Me.surface,g=hasLabel(e),b=g&&(!Q||t),f=_jsxs(Animated.View,{style:[L.iconWrap,{width:B+4,height:B+4,opacity:m,transform:[{scale:d}]}],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(l,{color:n,size:B,focused:t,disabled:!1})}),u?_jsx(Badge,{variant:u,value:"standard"!==u||"number"!=typeof e.badge&&"string"!=typeof e.badge?void 0:e.badge,tone:"danger",accessible:!1,style:"dot"===u?L.badgeDotPosition:L.badgePillPosition,badgeStyle:["dot"===u?L.badgeDot:L.badgePill,{borderColor:h}],textStyle:L.badgeText}):null]}),x=J?_jsx(Animated.View,{style:{top:c.interpolate({inputRange:[0,1],outputRange:[0,-14]})},children:f}):f,y=b?_jsx(Animated.Text,{numberOfLines:1,maxFontSizeMultiplier:E??V.settings.maxFontSizeMultiplier??1.2,style:[L.label,Q?L.labelInline:null,{color:i,opacity:Q?c:m,fontWeight:t?V.weight.semibold:V.weight.normal},A],children:e.label}):null,S=_jsx(Pressable,{onPress:()=>(e=>{O&&F(_),e.key!==o&&!1!==r&&triggerHaptic(r);const t=xe.current[e.key];t&&popIcon(t),a(e.key)})(e),accessibilityRole:"tab",accessibilityState:{selected:t},"aria-selected":t,accessibilityLabel:`${e.label}${p}`,accessibilityHint:T.switchesTo(e.label),hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[L.tab,K?L.tabTile:null,e?{opacity:.85}:null],testID:R?`${R}-tab-${e.key}`:void 0,children:Q?_jsxs(View,{style:[L.expandPill,{height:D,paddingHorizontal:t&&g?V.space.md:Math.max(0,(D-(B+4))/2)}],children:[_jsx(View,{pointerEvents:"none",style:[L.expandFill,{borderRadius:activeBgRadius(D,D/2),...smoothCorners,backgroundColor:t?Me["primary-soft"]:"transparent"},t?w:null]}),x,y]}):_jsxs(_Fragment,{children:[x,y]})},e.key);return Q?_jsx(Animated.View,{style:{flex:c.interpolate({inputRange:[0,1],outputRange:[1,g?1.5:1]})},children:S},e.key):S}),st?[...ut.slice(0,se),st,...ut.slice(se)]:ut),"underline"===l&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[L.underline,"top"===d?L.underlineTop:L.underlineBottom,"top"===d?{top:-Ue-Y}:{bottom:-Ue},{width:ge,height:3,backgroundColor:Me.primary,transform:[{translateX:Le}]},w]}):null]});var ut;return _jsx(View,{ref:t,testID:R,accessibilityRole:"tablist",style:[L.outer,{paddingHorizontal:He,paddingTop:Math.max(Oe,rt),paddingBottom:Ge},v],children:_jsxs(View,{style:[q?L.floatingBar:L.dockedBar,X?L.barInline:null,tt,{backgroundColor:ke,borderColor:nt,borderRadius:Ke,...smoothCorners},q?{borderWidth:it,paddingHorizontal:$e,paddingVertical:Ue}:{borderTopWidth:it,borderBottomWidth:it,borderLeftWidth:it,borderRightWidth:it,paddingHorizontal:Je,paddingTop:Ue,paddingBottom:Xe}],children:[dt,ct]})})});BottomNavigation.displayName="BottomNavigation";const buildStyles=e=>StyleSheet.create({outer:{backgroundColor:"transparent"},dockedBar:{paddingHorizontal:e.space.xs},floatingBar:{paddingVertical:e.space.sm,paddingHorizontal:e.space.sm},tabRow:{flexDirection:"row",alignItems:"stretch",position:"relative"},tabRowInline:{flex:1},barInline:{flexDirection:"row",alignItems:"center"},accessoryStacked:{marginBottom:e.space.xs},accessoryInline:{flexShrink:0,marginRight:e.space.xs},tab:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center",paddingVertical:e.space.xs,gap:e.space.xs},tabTile:{paddingVertical:e.space.sm,gap:e.space.xxs},centerCell:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center"},centerPressable:{alignItems:"center",maxWidth:"100%",gap:e.space.xs},centerCircle:{alignItems:"center",justifyContent:"center"},iconWrap:{alignItems:"center",justifyContent:"center",position:"relative"},label:{fontSize:e.text.xs.size,lineHeight:e.text.xs.size*e.leading.heading,textAlign:"center",includeFontPadding:!1},labelInline:{fontSize:e.text.sm.size,lineHeight:e.text.sm.size*e.leading.heading,flexShrink:1,includeFontPadding:!1},expandPill:{flexDirection:"row",alignItems:"center",justifyContent:"center",gap:e.space.xs},expandFill:{position:"absolute",top:0,right:0,bottom:0,left:0,overflow:"hidden"},pill:{position:"absolute",left:0},bubble:{position:"absolute",left:0,borderWidth:3},underline:{position:"absolute",left:0,height:3},underlineBottom:{borderTopLeftRadius:e.radius.none,borderTopRightRadius:e.radius.none,...smoothCorners},underlineTop:{borderBottomLeftRadius:e.radius.none,borderBottomRightRadius:e.radius.none,...smoothCorners},badgePillPosition:{position:"absolute",top:-4,right:-8},badgePill:{minWidth:18,height:18,paddingHorizontal:e.space.xs,paddingVertical:e.space.xxs,borderWidth:1.5},badgeDotPosition:{position:"absolute",top:-2,right:-2},badgeDot:{width:10,height:10,borderRadius:e.radius.pill,borderWidth:1.5},badgeText:{lineHeight:13}});export{BottomNavigation};export default BottomNavigation;
1
+ "use strict";import React,{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,LayoutAnimation,Platform,Pressable,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{supportsBoxShadow,toBoxShadow}from"../../utils/shadows.js";import{renderSlotIcon}from"../AppIcon/index.js";import{Badge}from"../Badge/index.js";import{Text}from"../Text/index.js";import{useScreenReaderEnabled}from"./useScreenReaderEnabled.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BOTTOM_NAVIGATION_LABELS=Object.freeze({switchesTo:e=>`Switches to ${e}`,unread:e=>`${e} unread`,newUpdates:"new updates"});const DEFAULT_ICON_SIZE=18,DEFAULT_LABEL_MAX_FONT_SCALE=1.2,ICON_WRAP_AIR=4,PILL_AIR=8,DEFAULT_PILL_MAX_WIDTH=64,TILE_MAX_WIDTH=96,DEFAULT_UNDERLINE_HEIGHT=3,DEFAULT_BUBBLE_SIZE=48,DEFAULT_BUBBLE_LIFT=14,DEFAULT_CENTER_SIZE=48,DEFAULT_CENTER_ICON_SIZE=24,CENTER_KEY="__center_action__",EXPANDED_FLEX=1.5,SOLID_INACTIVE_OPACITY=.7,TILE_INSET=2,badgeVariantOf=e=>null==e||!1===e?null:!0===e||"·"===e?"dot":"number"==typeof e?e>0?"standard":null:e.length>0?"standard":null,badgeAccessibilitySuffix=(e,t)=>null==e||!1===e?"":"number"==typeof e?e>0?`, ${t.unread(e)}`:"":!0===e||"·"===e?`, ${t.newUpdates}`:"string"==typeof e&&e.length>0?`, ${e}`:"",BottomNavigation=forwardRef((e,t)=>{const{tabs:i,centerAction:n,activeTab:o,onChange:a,haptic:r="selection",showLabels:s=!0,variant:l="pill",indicatorPosition:d="bottom",radius:c,indicatorRadius:u="auto",elevation:p,iconSize:m,marginHorizontal:h,marginVertical:g,paddingHorizontal:b,paddingVertical:f,border:x,minimizeOnScroll:y=!1,scrollDirection:_="idle",accessory:S,style:v,indicatorStyle:w,labelStyle:A,labelMaxFontScale:E,labels:I,testID:R}=e;assertValidValue("BottomNavigation","variant",e.variant,["pill","underline","floating","bubble","expand","solid","tile"]),assertValidValue("BottomNavigation","indicatorPosition",e.indicatorPosition,["top","bottom"]);const T=useMemo(()=>I?{...DEFAULT_BOTTOM_NAVIGATION_LABELS,...I}:DEFAULT_BOTTOM_NAVIGATION_LABELS,[I]),V=useTheme(),j=useSafeAreaInsets(),L=useMemo(()=>buildStyles(V),[V]),B=m??18,D=B+4+8,M=V.space.lg,C=V.space.lg,k=V.radius.xl,N=useReducedMotion(),P=useScreenReaderEnabled(y),[z,F]=React.useState(null);useEffect(()=>{null!==z&&z!==_&&F(null)},[z,_]);const H=y&&!P&&"down"===_&&null===z,[O,W]=React.useState(H);useEffect(()=>{O!==H&&(N||"web"===Platform.OS||LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut),W(H))},[O,H,N]);const U="function"==typeof S?S({minimized:O}):S,$=null!=U&&!1!==U,X=O&&$,[G,Z]=React.useState(0),Y=$&&!X?G+V.space.xs:0,K="tile"===l,q="floating"===l||K,J="bubble"===l,Q="expand"===l,ee="solid"===l,te="pill"===l||q||ee,ie=Math.max(0,i.findIndex(e=>e.key===o)),[ne,oe]=React.useState(0),[ae,re]=React.useState(0),se=n?Math.ceil(i.length/2):i.length,le=i.length+(n?1:0),[de,ce]=React.useState({width:0,height:0}),ue=n?.size??48,pe=void 0!==n?.gap,me=Math.max(0,n?.gap??0),he=pe?(de.width||ue)+2*me:0,ge=pe?i.length>0?Math.max(0,ne-he)/i.length:0:le>0?ne/le:0,be=pe?he:ge,fe=useRef(createAnimatedValue(ie)).current,xe=useRef({}),ye=useRef({});i.forEach(e=>{xe.current[e.key]||(xe.current[e.key]=new Animated.Value(1)),ye.current[e.key]||(ye.current[e.key]=createAnimatedValue(e.key===o?1:0))});const Se=ge>0?K?Math.min(ge-4,96):Math.min(ge-M,64):0,ve=ge>0?(ge-Se)/2:0,we=ge>0?(ge-48)/2:0,hasLabel=e=>s&&!O&&!1!==e.showLabel&&e.label.trim().length>0,Ae=i[ie],Ee=Ae&&!hasLabel(Ae)&&ae>0?ae/2:V.space.xs+(B+4)/2,Ie=Ee-14-24,Re=Math.max(0,ae-4),Te=K?2:Ee-D/2,Ve=useRef(ie);useEffect(()=>{if(Ve.current===ie)return;Ve.current=ie;const e=Animated.spring(fe,{toValue:ie,tension:120,friction:14,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[ie,fe]);const je=Math.max(1,i.length-1),Le=useMemo(()=>{const e=[],t=[];for(let i=0;i<=je;i++)e.push(i),t.push(i<se?i*ge:i*ge+be);return fe.interpolate({inputRange:e,outputRange:t})},[fe,je,se,ge,be]),Be=i.map(e=>e.key).join(" "),De=J||Q;useEffect(()=>{const e=Be.split(" ").flatMap(e=>{const t=e===o?1:0,i=ye.current[e];return i?De?[Animated.spring(i,{toValue:t,tension:140,friction:13,useNativeDriver:!1})]:(i.setValue(t),[]):[]});if(0===e.length)return;const t=Animated.parallel(e);return t.start(),()=>t.stop()},[o,Be,De]);const popIcon=e=>{Animated.sequence([Animated.timing(e,{toValue:1.15,duration:120,useNativeDriver:nativeDriver}),Animated.spring(e,{toValue:1,tension:200,friction:8,useNativeDriver:nativeDriver})]).start()},Me=useRef(new Animated.Value(1)).current,{colors:Ce}=V,ke=ee?Ce.primary:Ce.surface,Ne=ee?Ce["on-primary"]:Ce.primary,Pe=ee?Ce["on-primary"]:K?Ce["text-body"]:Ce["text-subtle"],ze=ee?Ce["on-primary"]:Ce["primary-soft"],Fe=ee?Ce.primary:J?Ce["on-primary"]:Ne,He=h??C,Oe=g??(q?C:0),We=Oe>0,Ue=f??V.space.sm,$e=b??(q?V.space.sm:V.space.xs),Xe=We?Ue:Math.max(Ue,j.bottom),Ge=We?Math.max(Oe,j.bottom>0?j.bottom+V.space.sm:0):0,Ze="pill"===c,Ye=q?ae+Y+2*Ue+2*StyleSheet.hairlineWidth:ae+Y+Ue+Xe,Ke=Ze?ae>0?Ye/2:V.radius.pill:c??(K?V.radius.pill:q?k:V.radius.none),qe=void 0!==c,activeBgRadius=(e,t)=>"number"==typeof u?Math.max(0,Math.min(u,e/2)):"auto"===u&&qe?Math.min(Ke,e/2):t,Je="underline"===l?Math.max($e,Ze&&0===ae?0:Ke):$e,Qe=p??"none",et="none"===Qe?void 0:V.shadow[Qe],tt=void 0===et?null:supportsBoxShadow()?{boxShadow:toBoxShadow(et)}:et,it=x?StyleSheet.hairlineWidth:0,nt=ee?Ce.primary:Ce.border,ot=n?.lift??0,at=Ue+it+Y,rt=n&&ae>0?Math.max(0,(de.height||ue)/2+ot-ae/2-at):0,st=n?_jsx(View,{style:[L.centerCell,pe?{flex:0,marginHorizontal:me}:null],pointerEvents:"box-none",children:_jsxs(Pressable,{onPress:()=>{if(!n)return;const e=n.haptic??r;!1!==e&&triggerHaptic(e),popIcon(Me),n.onPress()},onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;ce(e=>e.width===t&&e.height===i?e:{width:t,height:i})},accessibilityRole:"button",accessibilityLabel:n.label,hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[L.centerPressable,{top:-ot},e?{opacity:.85}:null],testID:n.testID??(R?`${R}-center`:void 0),children:[n.content?_jsx(Animated.View,{style:{transform:[{scale:Me}]},children:n.content}):_jsx(View,{style:[L.centerCircle,{width:ue,height:ue,borderRadius:V.radius.pill,...smoothCorners,backgroundColor:n.color??Ce.primary}],children:_jsx(Animated.View,{style:{transform:[{scale:Me}]},children:renderSlotIcon(n.icon??"add",{color:n.iconColor??Ce["on-primary"],size:n.iconSize??24,disabled:!1})})}),(lt=n,s&&!O&&lt.label.trim().length>0?_jsx(Text,{variant:"caption",numberOfLines:1,maxFontSizeMultiplier:E??V.settings.maxFontSizeMultiplier??1.2,style:[L.label,{color:Pe,opacity:ee?.7:1},A],children:n.label}):null)]})},CENTER_KEY):null;var lt;const dt=$?_jsx(View,{style:X?L.accessoryInline:L.accessoryStacked,onLayout:e=>Z(e.nativeEvent.layout.height),testID:R?`${R}-accessory`:void 0,children:U}):null,ct=_jsxs(View,{style:X?[L.tabRow,L.tabRowInline]:L.tabRow,onLayout:e=>{const{width:t,height:i}=e.nativeEvent.layout;oe(t),re(i)},children:[te&&Se>0&&(!K||Re>0)?_jsx(Animated.View,{pointerEvents:"none",style:[L.pill,{width:Se,height:K?Re:D,left:ve,top:Te,backgroundColor:ze,borderRadius:K?activeBgRadius(Re,Re/2):activeBgRadius(D,V.radius.pill),...smoothCorners,transform:[{translateX:Le}]},w]}):null,J&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[L.bubble,V.shadow.elevated,{width:48,height:48,borderRadius:V.radius.pill,...smoothCorners,left:we,top:Ie,backgroundColor:Ce.primary,borderColor:Ce.surface,transform:[{translateX:Le}]},w]}):null,(ut=i.map(e=>{const t=e.key===o,i=t?Ne:Pe,n=t?Fe:Pe,s="string"==typeof e.icon?{name:e.icon,variant:"bold"}:e.icon,l=t?e.activeIcon??s:e.icon,d=xe.current[e.key],c=ye.current[e.key];if(void 0===d||void 0===c)throw new Error(`BottomNavigation has no animation values for tab "${e.key}".`);const u=badgeVariantOf(e.badge??null),p=badgeAccessibilitySuffix(e.badge??null,T),m=ee&&!t?.7:1,h=J&&t||ee?Ce.primary:Ce.surface,g=hasLabel(e),b=g&&(!Q||t),f=_jsxs(Animated.View,{style:[L.iconWrap,{width:B+4,height:B+4,opacity:m,transform:[{scale:d}]}],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(l,{color:n,size:B,focused:t,disabled:!1})}),u?_jsx(Badge,{variant:u,value:"standard"!==u||"number"!=typeof e.badge&&"string"!=typeof e.badge?void 0:e.badge,tone:"danger",accessible:!1,style:"dot"===u?L.badgeDotPosition:L.badgePillPosition,badgeStyle:["dot"===u?L.badgeDot:L.badgePill,{borderColor:h}],textStyle:L.badgeText}):null]}),x=J?_jsx(Animated.View,{style:{top:c.interpolate({inputRange:[0,1],outputRange:[0,-14]})},children:f}):f,y=b?_jsx(Animated.Text,{numberOfLines:1,maxFontSizeMultiplier:E??V.settings.maxFontSizeMultiplier??1.2,style:[L.label,Q?L.labelInline:null,{color:i,opacity:Q?c:m,fontWeight:t?V.weight.semibold:V.weight.normal},A],children:e.label}):null,S=_jsx(Pressable,{onPress:()=>(e=>{O&&F(_),e.key!==o&&!1!==r&&triggerHaptic(r);const t=xe.current[e.key];t&&popIcon(t),a(e.key)})(e),accessibilityRole:"tab",accessibilityState:{selected:t},"aria-selected":t,accessibilityLabel:`${e.label}${p}`,accessibilityHint:T.switchesTo(e.label),hitSlop:{top:6,bottom:6,left:6,right:6},...hitSlopMarker({top:6,bottom:6,left:6,right:6}),style:({pressed:e})=>[L.tab,K?L.tabTile:null,e?{opacity:.85}:null],testID:R?`${R}-tab-${e.key}`:void 0,children:Q?_jsxs(View,{style:[L.expandPill,{height:D,paddingHorizontal:t&&g?V.space.md:Math.max(0,(D-(B+4))/2)}],children:[_jsx(View,{pointerEvents:"none",style:[L.expandFill,{borderRadius:activeBgRadius(D,D/2),...smoothCorners,backgroundColor:t?Ce["primary-soft"]:"transparent"},t?w:null]}),x,y]}):_jsxs(_Fragment,{children:[x,y]})},e.key);return Q?_jsx(Animated.View,{style:{flex:c.interpolate({inputRange:[0,1],outputRange:[1,g?1.5:1]})},children:S},e.key):S}),st?[...ut.slice(0,se),st,...ut.slice(se)]:ut),"underline"===l&&ge>0?_jsx(Animated.View,{pointerEvents:"none",style:[L.underline,"top"===d?L.underlineTop:L.underlineBottom,"top"===d?{top:-Ue-Y}:{bottom:-Ue},{width:ge,height:3,backgroundColor:Ce.primary,transform:[{translateX:Le}]},w]}):null]});var ut;return _jsx(View,{ref:t,testID:R,accessibilityRole:"tablist",style:[L.outer,{paddingHorizontal:He,paddingTop:Math.max(Oe,rt),paddingBottom:Ge},v],children:_jsxs(View,{style:[q?L.floatingBar:L.dockedBar,X?L.barInline:null,tt,{backgroundColor:ke,borderColor:nt,borderRadius:Ke,...smoothCorners},q?{borderWidth:it,paddingHorizontal:$e,paddingVertical:Ue}:{borderTopWidth:it,borderBottomWidth:it,borderLeftWidth:it,borderRightWidth:it,paddingHorizontal:Je,paddingTop:Ue,paddingBottom:Xe}],children:[dt,ct]})})});BottomNavigation.displayName="BottomNavigation";const buildStyles=e=>StyleSheet.create({outer:{backgroundColor:"transparent"},dockedBar:{paddingHorizontal:e.space.xs},floatingBar:{paddingVertical:e.space.sm,paddingHorizontal:e.space.sm},tabRow:{flexDirection:"row",alignItems:"stretch",position:"relative"},tabRowInline:{flex:1},barInline:{flexDirection:"row",alignItems:"center"},accessoryStacked:{marginBottom:e.space.xs},accessoryInline:{flexShrink:0,marginRight:e.space.xs},tab:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center",paddingVertical:e.space.xs,gap:e.space.xs},tabTile:{paddingVertical:e.space.sm,gap:e.space.xxs},centerCell:{flex:1,minHeight:44,alignItems:"center",justifyContent:"center"},centerPressable:{alignItems:"center",maxWidth:"100%",gap:e.space.xs},centerCircle:{alignItems:"center",justifyContent:"center"},iconWrap:{alignItems:"center",justifyContent:"center",position:"relative"},label:{fontSize:e.text.xs.size,lineHeight:e.text.xs.size*e.leading.heading,textAlign:"center",includeFontPadding:!1},labelInline:{fontSize:e.text.sm.size,lineHeight:e.text.sm.size*e.leading.heading,flexShrink:1,includeFontPadding:!1},expandPill:{flexDirection:"row",alignItems:"center",justifyContent:"center",gap:e.space.xs},expandFill:{position:"absolute",top:0,right:0,bottom:0,left:0,overflow:"hidden"},pill:{position:"absolute",left:0},bubble:{position:"absolute",left:0,borderWidth:3},underline:{position:"absolute",left:0,height:3},underlineBottom:{borderTopLeftRadius:e.radius.none,borderTopRightRadius:e.radius.none,...smoothCorners},underlineTop:{borderBottomLeftRadius:e.radius.none,borderBottomRightRadius:e.radius.none,...smoothCorners},badgePillPosition:{position:"absolute",top:-4,right:-8},badgePill:{minWidth:18,height:18,paddingHorizontal:e.space.xs,paddingVertical:e.space.xxs,borderWidth:1.5},badgeDotPosition:{position:"absolute",top:-2,right:-2},badgeDot:{width:10,height:10,borderRadius:e.radius.pill,borderWidth:1.5},badgeText:{lineHeight:Math.round(e.text.xs.size*e.leading.heading)}});export{BottomNavigation};export default BottomNavigation;
@@ -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{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
+ "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:v,testID:I,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 w=useTheme(),F=w.settings.components.button,L=r??F?.defaultVariant??"solid",V=i??F?.defaultSize??"md",A=useMemo(()=>({...DEFAULT_BUTTON_LABELS,...T}),[T]),[R,O]=useState(!1),P=useRef(!1),z=n||R,B=!l&&!z,E={...v,disabled:!B,busy:z},D="link"===L,H=y??F?.defaultPressAnimation??(!D&&"scale"),W=usePressAnimation({preset:H||"scale",enabled:!1!==H&&B}),N=useFlickGuard(),M=useMemo(()=>buildStyles(w),[w]),U=useMemo(()=>resolveButtonSize(w,V),[w,V]),q=useMemo(()=>toneFor(w,s),[w,s]),G=useMemo(()=>variantFor(w,L,q,l),[w,L,q,l]),K=useMemo(()=>!m||l||"solid"!==L?null:"string"==typeof m?w.settings.gradients[m]??null:m,[m,l,L,w.settings.gradients]),X=StyleSheet.flatten(f)?.borderRadius,Y=D?0:"number"==typeof X?X:p?w.radius.pill:U.radius,J=useSquircle(!K&&"link"!==L,Y,j),Q=useRef(createAnimatedValue(0)).current,[Z,$]=useState(0),[ee,te]=useState(null),oe=D?e=>$(e.nativeEvent.layout.width):void 0,settlePending=()=>{P.current=!1,O(!1)},re=C??o,se="outline"===L||"ghost"===L,ie=!se&&!D,ne={color:G.textColor,size:U.icon,disabled:l},le=b&&!D&&Boolean(d),ae=w.space.xs,de=U["min-height"]-2*ae-2*G.borderWidth,ce={color:G.badgeInk,size:U["badge-icon"],disabled:l},ue=z?_jsx(Spinner,{variant:"circular",size:"sm",color:le?G.badgeInk:G.textColor,accessibilityLabel:A.loading}):d?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(d,le?ce:ne,u)}):null,be=_jsxs(View,{style:M.contentRow,children:[le?_jsx(View,{testID:"button-icon-badge",style:[M.iconLeft,M.iconBadge,{width:de,height:de,borderRadius:de/2,backgroundColor:G.badgeFill}],children:ue}):ue?_jsx(View,{style:M.iconLeft,children:ue}):null,_jsxs(View,{onLayout:oe,children:[_jsx(Text,{variant:"label",weight:"semibold",numberOfLines:1,style:[M.label,{color:G.textColor,fontSize:U.text,lineHeight:Math.round(U.text*w.leading.body)},x],children:o}),D?_jsx(Animated.View,{pointerEvents:"none",testID:"button-link-underline",style:[M.linkUnderline,{backgroundColor:G.textColor,transform:[{translateX:Q.interpolate({inputRange:[0,1],outputRange:[-Z/2,0]})},{scaleX:Q.interpolate({inputRange:[0,1],outputRange:[0,1]})}]}]}):null]}),c?_jsx(View,{style:M.iconRight,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(c,ne,u)}):null]}),ge=D?null===ee?LINK_HIT_SLOP:Math.max(LINK_HIT_SLOP,touchSlopFor(ee)):touchSlopFor(U["min-height"]),pe={top:ge,bottom:ge,left:D?LINK_HIT_SLOP:0,right:D?LINK_HIT_SLOP:0};return _jsx(Animated.View,{style:[W.style,a?M.fullWidth:null,h],children:_jsx(Pressable,{ref:t,onPress:e=>{if(!B||P.current||N.isFlick(e))return;W.press();const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t);const o=S?.(e);return o instanceof Promise?(P.current=!0,O(!0),o.then(settlePending,e=>{throw settlePending(),e})):void 0},onPressIn:e=>{N.onPressIn(e),W.pressIn(),D&&B&&(Q.stopAnimation(),Q.setValue(0),Animated.timing(Q,{toValue:1,duration:w.motion.duration.slower,easing:Easing.bezier(...w.motion.ease.decelerate),useNativeDriver:nativeDriver}).start())},onPressOut:()=>{W.pressOut()},disabled:!B,hitSlop:pe,...hitSlopMarker(pe),accessibilityRole:"button",accessibilityLabel:re,accessibilityHint:_,accessibilityState:E,...ariaFromState(E),testID:I,onLayout:e=>{J.onLayout(e),D&&te(e.nativeEvent.layout.height)},style:({pressed:e})=>[M.base,{paddingHorizontal:D?0:U["padding-x"],paddingVertical:D?0:le?ae:U["padding-y"],paddingLeft:le?ae:void 0,minHeight:D?void 0:U["min-height"],borderRadius:Y,...smoothCorners,backgroundColor:K||J.active?"transparent":G.backgroundColor,borderWidth:G.borderWidth,borderColor:J.active?"transparent":G.borderColor,opacity:z?.55:1,overflow:J.active||D?"visible":"hidden"},e&&se&&!J.active?{backgroundColor:w.colors["surface-pressed"]}:null,a?M.fullWidth:null,f],...k,"aria-disabled":!B,"aria-busy":z,children:({pressed:e})=>_jsxs(_Fragment,{children:[J.active&&J.size?_jsx(SquircleFill,{width:J.size.width,height:J.size.height,radius:Y,fill:e&&se?w.colors["surface-pressed"]:G.backgroundColor,stroke:G.borderColor,strokeWidth:G.borderWidth}):null,K?_jsx(Gradient,{gradient:K,style:[StyleSheet.absoluteFill,{borderRadius:Y,...smoothCorners}]}):null,e&&ie?J.active&&J.size?_jsx(SquircleFill,{width:J.size.width,height:J.size.height,radius:Y,fill:G.pressedTint,testID:"button-pressed"}):_jsx(View,{pointerEvents:"none",style:[M.pressedOverlay,{borderRadius:Y,backgroundColor:G.pressedTint,...smoothCorners}],testID:"button-pressed"}):null,be]})})})});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:e.size.border},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{StyleSheet}from"react-native";import{fontFor}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";export const MIN_CELL_SIZE=44;export const NAV_BUTTON_SIZE=36;const DOT_SIZE=5;export const buildCalendarStyles=e=>StyleSheet.create({root:{alignSelf:"stretch"},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"]},navBtnDisabled:{opacity:.4},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],...fontFor(e,"semibold")},headerLabelWrap:{flex:1,alignItems:"center"},headerLabel:{fontSize:e.text.base.size,color:e.colors["text-body"],...fontFor(e,"semibold")},weekdayRow:{flexDirection:"row",justifyContent:"center",marginBottom:e.space.xs},weekdayCell:{alignItems:"center",paddingVertical:e.space.xs},weekdayText:{fontSize:e.text.xs.size,color:e.colors["text-subtle"],letterSpacing:e["letter-spacing"].wide,...fontFor(e,"medium")},gridRow:{flexDirection:"row",justifyContent:"center"},dayCell:{alignItems:"center",justifyContent:"center",padding:e.space.none},barLeft:{position:"absolute",left:0,right:"50%",top:"5%",bottom:"5%"},barRight:{position:"absolute",left:"50%",right:0,top:"5%",bottom:"5%"},rangeFill:{backgroundColor:e.colors["primary-soft"]},dayInner:{width:"90%",height:"90%",alignItems:"center",justifyContent:"center",borderRadius:e.radius.pill,...smoothCorners},dayEdge:{backgroundColor:e.colors.primary},dayMid:{borderRadius:e.radius.none},dayText:{fontSize:e.text.sm.size,...fontFor(e,"medium")},dots:{position:"absolute",bottom:e.space.xs,flexDirection:"row",gap:e.space.xxs},dot:{width:5,height:5,borderRadius:e.radius.pill,...smoothCorners}});
1
+ "use strict";import{StyleSheet}from"react-native";import{fontFor}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";export const MIN_CELL_SIZE=44;export const NAV_BUTTON_SIZE=36;const DOT_SIZE=5;export const buildCalendarStyles=e=>StyleSheet.create({root:{alignSelf:"stretch"},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"]},navBtnDisabled:{opacity:.4},navText:{fontSize:e.text["2xl"].size,lineHeight:Math.round(e.text["2xl"].size*e.leading.heading),color:e.colors["text-body"],...fontFor(e,"semibold")},headerLabelWrap:{flex:1,alignItems:"center"},headerLabel:{fontSize:e.text.base.size,color:e.colors["text-body"],...fontFor(e,"semibold")},weekdayRow:{flexDirection:"row",justifyContent:"center",marginBottom:e.space.xs},weekdayCell:{alignItems:"center",paddingVertical:e.space.xs},weekdayText:{fontSize:e.text.xs.size,color:e.colors["text-subtle"],letterSpacing:e["letter-spacing"].wide,...fontFor(e,"medium")},gridRow:{flexDirection:"row",justifyContent:"center"},dayCell:{alignItems:"center",justifyContent:"center",padding:e.space.none},barLeft:{position:"absolute",left:0,right:"50%",top:"5%",bottom:"5%"},barRight:{position:"absolute",left:"50%",right:0,top:"5%",bottom:"5%"},rangeFill:{backgroundColor:e.colors["primary-soft"]},dayInner:{width:"90%",height:"90%",alignItems:"center",justifyContent:"center",borderRadius:e.radius.pill,...smoothCorners},dayEdge:{backgroundColor:e.colors.primary},dayMid:{borderRadius:e.radius.none},dayText:{fontSize:e.text.sm.size,...fontFor(e,"medium")},dots:{position:"absolute",bottom:e.space.xs,flexDirection:"row",gap:e.space.xxs},dot:{width:5,height:5,borderRadius:e.radius.pill,...smoothCorners}});
@@ -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{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=void 0!==e.open?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
+ "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=void 0!==e.open?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:Math.round(e.text["2xl"].size*e.leading.heading),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,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
+ "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 i=r>=10||0===s?Math.round(r):Math.round(10*r)/10,o=t[s];if(void 0===o)throw new Error("formatFileSize has no unit label for this size.");return`${i} ${o}`};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:i,sources:o,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(_),[_]),z=useMemo(()=>({...DEFAULT_FILE_PICKER_LABELS,...b}),[b]),k=_.radius.md,I=_.colors.primary,[R,V]=useControllableState({value:r,defaultValue:s??[],onChange:i}),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(z.errorTooMany(l)),s=s.slice(0,e))}const i=[];for(const e of s){if("number"==typeof n&&"number"==typeof e.bytes&&e.bytes>1024*n*1024){r.push(z.errorTooLarge(e.name,n));continue}if(!matchesAccept(e.type,a)){r.push(z.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):i.push(e)}if(W(r),0===i.length)return;if(!d){L([...M.current,...i]);const[e]=r;B(e??null);const t=resolveHaptic(f,"selection");return t&&triggerHaptic(t),void y?.(i)}const o=i.map(e=>({...e,status:"processing"}));L([...M.current,...o]);const u=[];for(const e of o)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,z,W,L,y,f]),U=useCallback(e=>{if(p||A)return;const[t]=o,r=e?o.find(t=>t.key===e):1===o.length?t:void 0;r?D(r):o.length>1&&$(!0)},[p,A,o,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?z.trigger:z.attached(R.length),q=F??`${z.attachments}. ${N}`,statusText=e=>{switch(e.status){case"processing":return z.processing;case"uploading":return z.uploading(Math.round(100*(e.progress??0)));case"done":return z.uploaded;case"error":return e.error??z.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:z.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:z.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:k,...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:k,...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:z.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:k,...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?z.trigger:z.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:z.addMore,style:({pressed:e})=>[P.tile,P.addTile,{width:84,height:84,borderRadius:k,...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:z.sheetTitle,options:o,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:Math.round(e.text.sm.size*e.leading.heading),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 React,{useCallback,useMemo,useRef,useState}from"react";import{Dimensions,Image,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,usePinchGesture,useTapGesture}from"react-native-gesture-handler";import Animated,{runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{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{Carousel}from"../Carousel/index.js";import{Modal}from"../Modal/Modal.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_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"};const MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:l=!0,enableLightbox:i=!0,enablePinchZoom:s=!0,onIndexChange:o,haptic:n,loading:r=!1,accessibilityLabel:u,containerStyle:c,testID:m,labels:h})=>{const d=useTheme(),g=useMemo(()=>buildStyles(d),[d]),p=useMemo(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...h}),[h]),[b,S]=useState(clamp(t,0,Math.max(0,e.length-1))),[v,x]=useState(!1),y=useCallback(e=>{S(e),o?.(e)},[o]),I=useCallback(()=>{if(!i)return;const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!0)},[i,n]),w=useCallback(()=>{const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!1)},[n]),C=useCallback((t,a)=>{const l=t.alt??p.imageOf(a+1,e.length);return _jsx(Pressable,{onPress:I,accessibilityRole:"image",accessibilityLabel:l,accessibilityHint:i?p.openFullscreen:void 0,style:g.imageWrap,children:_jsx(Image,{source:t.source,style:g.image,resizeMode:"cover"})})},[i,e.length,I,g,p]),_=useCallback(e=>_jsx(Image,{source:e.source,style:g.thumbnailImage,resizeMode:"cover"}),[g]),f=_jsxs(View,{style:[g.container,c],testID:m,accessibilityLabel:u??p.gallery,children:[_jsxs(View,{style:g.carouselWrap,accessibilityElementsHidden:v,importantForAccessibility:v?"no-hide-descendants":"auto",children:[_jsx(Carousel,{data:e,defaultIndex:t,onIndexChange:y,renderItem:C,showPagination:!1,showThumbnails:a,renderThumbnail:_,haptic:n}),l&&e.length>0?_jsx(View,{style:g.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:d.colors["on-scrim"]},accessibilityLabel:p.imageOf(b+1,e.length),children:`${b+1} / ${e.length}`})}):null]}),i?_jsx(Lightbox,{open:v,images:e,initialIndex:b,enablePinchZoom:s,showCounter:l,onClose:w,onIndexChange:y,haptic:n,labels:p}):null]});return r?_jsx(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:l,containerStyle:c,testID:m}):f};ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:l,testID:i})=>{const s=useTheme(),o=Math.min(e?.length||4,6);return _jsxs(View,{style:[{width:"100%"},l],testID:i,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[_jsxs(View,{style:{position:"relative"},children:[_jsx(Skeleton,{width:"100%",height:280,radius:"lg"}),a?_jsx(View,{style:{position:"absolute",top:12,right:12},children:_jsx(Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.md},children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},`sk-thumb-${t}`))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:l,showCounter:i,onClose:s,onIndexChange:o,haptic:n,labels:r})=>{const u=useTheme(),c=useMemo(()=>buildLightboxStyles(u),[u]),m=useRef(null),[h,d]=useState(a),g=useCallback(e=>{if(e!==h){const t=resolveHaptic(n,"selection");t&&triggerHaptic(t),d(e),o(e)}},[h,o,n]),p=useCallback((e,a)=>_jsx(ZoomableImage,{image:e,index:a,total:t.length,active:a===h,enabled:l,maxScale:4,minScale:1,doubleTapScale:2,haptic:n,imageLabel:r.imageOf}),[h,l,t.length,n,r]),b=t[h]?.caption;return _jsx(Modal,{open:e,onClose:s,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:_jsxs(View,{style:c.backdrop,children:[_jsx(Carousel,{ref:m,data:t,defaultIndex:a,onIndexChange:g,renderItem:p,showPagination:!1,haptic:n}),i&&t.length>0?_jsx(View,{style:c.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:u.colors["on-scrim"]},accessibilityLabel:r.imageOf(h+1,t.length),children:`${h+1} / ${t.length}`})}):null,_jsx(Pressable,{onPress:s,accessibilityRole:"button",accessibilityLabel:r.closeGallery,style:c.closeButton,hitSlop:12,...hitSlopMarker(12),children:(u.settings.icons.close??defaultIcons.close)({size:24,color:u.colors["on-scrim"]})}),b?_jsx(Animated.View,{style:c.captionWrap,accessibilityElementsHidden:!1,children:_jsx(Text,{variant:"body",align:"center",numberOfLines:3,style:c.captionText,children:b})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:l,enabled:i,maxScale:s,minScale:o,doubleTapScale:n,haptic:r,imageLabel:u})=>{const c=Dimensions.get("window"),m=useSharedValue(1),h=useSharedValue(1),d=useSharedValue(0),g=useSharedValue(0),p=useSharedValue(0),b=useSharedValue(0),S=useCallback(()=>{m.value=withSpring(1,SPRING_CONFIG),h.value=1,d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),p.value=0,b.value=0},[m,h,d,g,p,b]);React.useEffect(()=>{l||(m.value=withTiming(1,{duration:150}),d.value=withTiming(0,{duration:150}),g.value=withTiming(0,{duration:150}),h.value=1,p.value=0,b.value=0)},[l,m,d,g,h,p,b]);const v=useCallback(()=>{!1!==r&&triggerHaptic("impactLight")},[r]),x=useMemo(()=>({enabled:i,onActivate:()=>{"worklet";h.value=m.value},onUpdate:e=>{"worklet";const t=h.value*e.scale;m.value=t<o?o+.3*(t-o):t>s?s+.2*(t-s):t},onDeactivate:()=>{"worklet";return m.value<o?(m.value=withSpring(o,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=o,p.value=0,void(b.value=0)):m.value>s?(m.value=withSpring(s,SPRING_CONFIG),void(h.value=s)):void(h.value=m.value)}}),[i,m,h,d,g,p,b,o,s]),y=usePinchGesture(x),I=useMemo(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";p.value=d.value,b.value=g.value},onUpdate:e=>{"worklet";m.value<=1||(d.value=p.value+e.translationX,g.value=b.value+e.translationY)},onDeactivate:()=>{"worklet";p.value=d.value,b.value=g.value}}),[m,d,g,p,b]),w=usePanGesture(I),C=useMemo(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";runOnJS(v)(),m.value>1?(m.value=withSpring(1,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=1,p.value=0,b.value=0):(m.value=withSpring(n,SPRING_CONFIG),h.value=n)}}),[m,h,d,g,p,b,v,n]),_=useTapGesture(C),f=useCompetingGestures(y,w,_),G=useAnimatedStyle(()=>({transform:[{translateX:d.value},{translateY:g.value},{scale:m.value}]}),[d,g,m]);React.useEffect(()=>{l||S()},[l,S]);const j=e.alt??u(t+1,a);return _jsx(GestureDetector,{gesture:f,children:_jsx(Animated.View,{style:[lightboxImageStyles.container,{width:c.width}],children:_jsx(Animated.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,G],accessibilityLabel:j,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,...smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"],lineHeight:21}}),lightboxImageStyles=StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});export{ImageGallery};export default ImageGallery;
1
+ "use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Dimensions,Image,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,usePinchGesture,useTapGesture}from"react-native-gesture-handler";import Animated,{runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{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{Carousel}from"../Carousel/index.js";import{Modal}from"../Modal/Modal.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_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"};const MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:l=!0,enableLightbox:i=!0,enablePinchZoom:s=!0,onIndexChange:o,haptic:n,loading:r=!1,accessibilityLabel:u,containerStyle:c,testID:m,labels:h})=>{const d=useTheme(),g=useMemo(()=>buildStyles(d),[d]),p=useMemo(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...h}),[h]),[b,S]=useState(clamp(t,0,Math.max(0,e.length-1))),[v,x]=useState(!1),y=useCallback(e=>{S(e),o?.(e)},[o]),I=useCallback(()=>{if(!i)return;const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!0)},[i,n]),w=useCallback(()=>{const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!1)},[n]),C=useCallback((t,a)=>{const l=t.alt??p.imageOf(a+1,e.length);return _jsx(Pressable,{onPress:I,accessibilityRole:"image",accessibilityLabel:l,accessibilityHint:i?p.openFullscreen:void 0,style:g.imageWrap,children:_jsx(Image,{source:t.source,style:g.image,resizeMode:"cover"})})},[i,e.length,I,g,p]),_=useCallback(e=>_jsx(Image,{source:e.source,style:g.thumbnailImage,resizeMode:"cover"}),[g]),f=_jsxs(View,{style:[g.container,c],testID:m,accessibilityLabel:u??p.gallery,children:[_jsxs(View,{style:g.carouselWrap,accessibilityElementsHidden:v,importantForAccessibility:v?"no-hide-descendants":"auto",children:[_jsx(Carousel,{data:e,defaultIndex:t,onIndexChange:y,renderItem:C,showPagination:!1,showThumbnails:a,renderThumbnail:_,haptic:n}),l&&e.length>0?_jsx(View,{style:g.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:d.colors["on-scrim"]},accessibilityLabel:p.imageOf(b+1,e.length),children:`${b+1} / ${e.length}`})}):null]}),i?_jsx(Lightbox,{open:v,images:e,initialIndex:b,enablePinchZoom:s,showCounter:l,onClose:w,onIndexChange:y,haptic:n,labels:p}):null]});return r?_jsx(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:l,containerStyle:c,testID:m}):f};ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:l,testID:i})=>{const s=useTheme(),o=Math.min(e?.length||4,6);return _jsxs(View,{style:[{width:"100%"},l],testID:i,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[_jsxs(View,{style:{position:"relative"},children:[_jsx(Skeleton,{width:"100%",height:280,radius:"lg"}),a?_jsx(View,{style:{position:"absolute",top:12,right:12},children:_jsx(Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.md},children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},`sk-thumb-${t}`))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:l,showCounter:i,onClose:s,onIndexChange:o,haptic:n,labels:r})=>{const u=useTheme(),c=useMemo(()=>buildLightboxStyles(u),[u]),m=useRef(null),[h,d]=useState(a),g=useCallback(e=>{if(e!==h){const t=resolveHaptic(n,"selection");t&&triggerHaptic(t),d(e),o(e)}},[h,o,n]),p=useCallback((e,a)=>_jsx(ZoomableImage,{image:e,index:a,total:t.length,active:a===h,enabled:l,maxScale:4,minScale:1,doubleTapScale:2,haptic:n,imageLabel:r.imageOf}),[h,l,t.length,n,r]),b=t[h]?.caption;return _jsx(Modal,{open:e,onClose:s,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:_jsxs(View,{style:c.backdrop,children:[_jsx(Carousel,{ref:m,data:t,defaultIndex:a,onIndexChange:g,renderItem:p,showPagination:!1,haptic:n}),i&&t.length>0?_jsx(View,{style:c.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:u.colors["on-scrim"]},accessibilityLabel:r.imageOf(h+1,t.length),children:`${h+1} / ${t.length}`})}):null,_jsx(Pressable,{onPress:s,accessibilityRole:"button",accessibilityLabel:r.closeGallery,style:c.closeButton,hitSlop:12,...hitSlopMarker(12),children:(u.settings.icons.close??defaultIcons.close)({size:24,color:u.colors["on-scrim"]})}),b?_jsx(Animated.View,{style:c.captionWrap,accessibilityElementsHidden:!1,children:_jsx(Text,{variant:"body",align:"center",numberOfLines:3,style:c.captionText,children:b})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:l,enabled:i,maxScale:s,minScale:o,doubleTapScale:n,haptic:r,imageLabel:u})=>{const c=Dimensions.get("window"),m=useSharedValue(1),h=useSharedValue(1),d=useSharedValue(0),g=useSharedValue(0),p=useSharedValue(0),b=useSharedValue(0),S=useCallback(()=>{m.value=withSpring(1,SPRING_CONFIG),h.value=1,d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),p.value=0,b.value=0},[m,h,d,g,p,b]);React.useEffect(()=>{l||(m.value=withTiming(1,{duration:150}),d.value=withTiming(0,{duration:150}),g.value=withTiming(0,{duration:150}),h.value=1,p.value=0,b.value=0)},[l,m,d,g,h,p,b]);const v=useCallback(()=>{!1!==r&&triggerHaptic("impactLight")},[r]),x=useMemo(()=>({enabled:i,onActivate:()=>{"worklet";h.value=m.value},onUpdate:e=>{"worklet";const t=h.value*e.scale;m.value=t<o?o+.3*(t-o):t>s?s+.2*(t-s):t},onDeactivate:()=>{"worklet";return m.value<o?(m.value=withSpring(o,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=o,p.value=0,void(b.value=0)):m.value>s?(m.value=withSpring(s,SPRING_CONFIG),void(h.value=s)):void(h.value=m.value)}}),[i,m,h,d,g,p,b,o,s]),y=usePinchGesture(x),I=useMemo(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";p.value=d.value,b.value=g.value},onUpdate:e=>{"worklet";m.value<=1||(d.value=p.value+e.translationX,g.value=b.value+e.translationY)},onDeactivate:()=>{"worklet";p.value=d.value,b.value=g.value}}),[m,d,g,p,b]),w=usePanGesture(I),C=useMemo(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";runOnJS(v)(),m.value>1?(m.value=withSpring(1,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=1,p.value=0,b.value=0):(m.value=withSpring(n,SPRING_CONFIG),h.value=n)}}),[m,h,d,g,p,b,v,n]),_=useTapGesture(C),f=useCompetingGestures(y,w,_),G=useAnimatedStyle(()=>({transform:[{translateX:d.value},{translateY:g.value},{scale:m.value}]}),[d,g,m]);React.useEffect(()=>{l||S()},[l,S]);const j=e.alt??u(t+1,a);return _jsx(GestureDetector,{gesture:f,children:_jsx(Animated.View,{style:[lightboxImageStyles.container,{width:c.width}],children:_jsx(Animated.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,G],accessibilityLabel:j,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,...smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"]}}),lightboxImageStyles=StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});export{ImageGallery};export default ImageGallery;
@@ -0,0 +1 @@
1
+ "use strict";import{useCallback,useEffect,useEffectEvent,useMemo,useRef,useState}from"react";import{Dimensions,ScrollView,StyleSheet,View}from"react-native";import{GestureDetector,usePanGesture}from"react-native-gesture-handler";import Animated,{Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=Object.freeze({dragHandle:"Drag handle"});const ERROR_PREFIX="[@webority/mobile-ui] NonModalBottomSheet: ",SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,OVERSHOOT_TO_CLOSE=80,PERCENT_PATTERN=/^(\d+(?:\.\d+)?|\.\d+)%$/,parsePercent=e=>{if("string"!=typeof e)return;const t=PERCENT_PATTERN.exec(e);if(!t)return;const n=Number(t[1]);return n>0&&n<=100?n:void 0},isValidSnapPoint=e=>"number"==typeof e?Number.isFinite(e)&&e>0:void 0!==parsePercent(e),validateProps=(e,t)=>{if(0===e.length)throw new Error(`${ERROR_PREFIX}snapPoints needs at least one snap point.`);for(const t of e)if(!isValidSnapPoint(t))throw new Error(`${ERROR_PREFIX}snap point ${String(t)} is not a positive number or a percentage up to 100%.`);if(null!=t&&(!Number.isInteger(t)||t<0||t>=e.length))throw new Error(`${ERROR_PREFIX}snapIndex ${t} is outside the snap points.`)},resolveNonModalSnapPoints=(e,t)=>e.map(e=>"number"==typeof e?e:parseFloat(e)/100*t).sort((e,t)=>e-t),topAt=(e,t,n)=>{const o=e[n];if(void 0===o)throw new Error(`${ERROR_PREFIX}snap index ${n} has no snap point.`);return Math.max(0,t-o)},NonModalBottomSheet=e=>{const{open:t,onClose:n,snapPoints:o,snapIndex:s,onSnapChange:r,enablePanDownToClose:i=!0,scrollable:a=!1,title:l,header:c,footer:u,labels:d,handleIndicatorStyle:h,containerStyle:m,children:p,accessibilityLabel:f,testID:E}=e;validateProps(o,s);const S=useMemo(()=>({...DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS,...d}),[d]),v=useTheme(),b=usePresenceMotion(),g=b.reduced,R=useMemo(()=>buildStyles(v),[v]),[_,w]=useState(()=>Dimensions.get("window").height),x=useCallback(e=>{const t=e.nativeEvent.layout.height;t>0&&w(t)},[]),y=useMemo(()=>resolveNonModalSnapPoints(o,_),[o,_]),O=y[y.length-1]??0,T=_,C=Math.max(0,_-O),N=useCallback(e=>topAt(y,_,e),[y,_]),[P,M]=useState(!1),[I,A]=useState(-1),j=useRef(-1),D=useRef(n);D.current=n;const V=useRef(r);V.current=r;const L=useSharedValue(T),k=useSharedValue(T),F=useCallback(()=>{j.current<0&&M(!1)},[]),$=useCallback(()=>{if(j.current=-1,A(-1),g)return L.value=T,void F();L.value=withTiming(T,{duration:b.duration("fast"),easing:Easing.bezier(...v.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(F)()})},[T,b,g,v.motion.ease.accelerate,L,F]),B=useCallback(e=>{const t=N(e);L.value=g?t:withSpring(t,SPRING_CONFIG)},[g,N,L]),G=useCallback((e,t)=>{e!==j.current&&(j.current=e,A(e),B(e),t&&V.current?.(e))},[B]),H=useEffectEvent(e=>{if(!e)return void(j.current>=0&&$());const t=s??0;M(!0);const n=N(t);g?L.value=n:(L.value=T,L.value=withSpring(n,SPRING_CONFIG)),j.current=t,A(t)});useEffect(()=>{H(t)},[t]);const J=useEffectEvent(e=>{t&&P&&e!==j.current&&G(e,!1)});useEffect(()=>{null!=s&&J(s)},[s]);const U=useEffectEvent(e=>{const t=j.current;t>=0&&(L.value=topAt(y,e,t))});useEffect(()=>{U(_)},[_]);const X=useCallback(e=>{if(e<0)return triggerHaptic("selection"),$(),void D.current();e!==j.current?G(e,!0):B(e)},[G,B,$]),Y=useCallback(e=>{const t=j.current;t<0||G(Math.min(Math.max(t+e,0),y.length-1),!0)},[G,y.length]),z=useMemo(()=>y.map(e=>_-e),[y,_]),q=useMemo(()=>{const e=z,t=C,n=i;return{testID:E?`${E}-pan-gesture`:"non-modal-bottom-sheet-pan-gesture",activeOffsetY:[-10,10],onActivate:()=>{"worklet";k.value=L.value},onUpdate:e=>{"worklet";const n=k.value+e.translationY;L.value=n<t?t+.25*(n-t):n},onDeactivate:t=>{"worklet";const o=L.value,s=e[0];if(void 0===s)return;if(t.velocityY>1e3)return void runOnJS(X)(n?-1:0);if(n&&o-s>80)return void runOnJS(X)(-1);let r=0,i=1/0,a=0;for(const t of e){const e=Math.abs(o-t);e<i&&(i=e,r=a),a++}runOnJS(X)(r)}}},[k,i,X,C,z,E,L]),K=usePanGesture(q),Q=useAnimatedStyle(()=>({top:L.value<C?C:L.value}),[C]),W=useAnimatedStyle(()=>{const e=L.value<C?C:L.value,t=_-e;return{height:t<0?0:t>O?O:t}},[_,O,C]);return P?_jsx(View,{collapsable:!1,style:StyleSheet.absoluteFill,pointerEvents:"box-none",onLayout:x,testID:E,children:_jsx(Animated.View,{accessibilityLabel:f,testID:E?`${E}-sheet`:void 0,style:[R.sheet,{height:O,backgroundColor:v.colors.surface,borderTopLeftRadius:v.radius.xl,borderTopRightRadius:v.radius.xl,...smoothCorners,...v.shadow.modal},m,Q],children:_jsxs(Animated.View,{style:[R.body,W],children:[_jsx(GestureDetector,{gesture:K,children:_jsx(View,{style:R.handleRow,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:S.dragHandle,accessibilityHint:"Swipe up or down to change the height of the sheet",accessibilityValue:{text:`Snap point ${I+1} of ${y.length}`},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName?Y(1):"decrement"===e.nativeEvent.actionName&&Y(-1)},testID:E?`${E}-handle`:void 0,children:_jsx(View,{style:[R.handle,{backgroundColor:v.colors.border},h]})})}),null!=l?_jsx(Text,{variant:"title",accessibilityRole:"header",children:l}):null,c,a?_jsx(ScrollView,{style:R.scrollContent,children:p}):_jsx(View,{style:R.content,children:p}),u]})})}):null};NonModalBottomSheet.displayName="NonModalBottomSheet";const buildStyles=e=>StyleSheet.create({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},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1}});export{NonModalBottomSheet};export default NonModalBottomSheet;
@@ -0,0 +1 @@
1
+ "use strict";export{DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS,default,NonModalBottomSheet}from"./NonModalBottomSheet.js";
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{selectOptionDescription,selectOptionDisabled,selectOptionIcon,selectOptionLabel,selectOptionValue}from"./optionAccessors.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18;export const DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`});const hostStyle=StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,value:b,onChange:g,multi:x=!1,searchable:y=!1,searchSelectionColor:f,accessibilityLabel:S,optionStyle:T,selectedOptionStyle:j,optionTextStyle:w,selectedOptionTextStyle:C,testID:_}=e,k=c??selectOptionLabel,L=d??selectOptionValue,I=p??selectOptionDescription,O=u??selectOptionDisabled,R=h??selectOptionIcon,V=useTheme(),D=useSafeAreaInsets(),v=useMemo(()=>buildStyles(V),[V]),[P,H]=useState(""),M=Dimensions.get("window").height,B=Math.round(.7*M),A=useRef(createAnimatedValue(0)).current,{handleGesture:E,opacity:F}=useDragToDismiss({drag:A,travel:B,onDismiss:t}),z=useNativeGesture(),W=useKeyboardState(e=>e.height),N=Math.max(0,Math.round(W)),G=Math.max(D.top,StatusBar.currentHeight??0)+V.space.sm,U=N>0,$=U?Math.max(0,Math.min(B,M-N-G)):B,J=useMemo(()=>{const e=y?P.trim().toLowerCase():"",matches=t=>0===e.length||k(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:o})}}),t},[y,P,s,i,k,I]),K=useCallback(()=>{t()},[t]),Y=useRef(null),Z=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of J.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of J.entries()){if(o<t||"option"!==s.kind)continue;const i=k(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,J,i,k]),Q=n&&Z.size>0&&0===P.trim().length,X=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Z.has("#")?["#"]:[]],[Z]),q=useCallback(e=>{const t=Z.get(e);void 0!==t&&Y.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Z]),ee=useRef(null),te=useCallback(()=>{null!==ee.current&&(clearTimeout(ee.current),ee.current=null)},[]),oe=useCallback(e=>{Y.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),te(),ee.current=setTimeout(()=>{ee.current=null,Y.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[te]);useEffect(()=>te,[te]);return _jsx(GestureHandlerRootView,{style:v.gestureRoot,children:_jsxs(Animated.View,{testID:_,accessibilityViewIsModal:!0,accessibilityLabel:S??o??a.fallbackName,style:[v.sheet,{maxHeight:$,marginBottom:N,paddingBottom:U?V.space.lg:D.bottom+V.space.lg,backgroundColor:V.colors.surface,borderTopLeftRadius:V.radius.xl,borderTopRightRadius:V.radius.xl,...smoothCorners,opacity:F,transform:[{translateY:A}],...V.shadow.modal}],children:[_jsx(GestureDetector,{gesture:E,children:_jsxs(View,{children:[_jsx(View,{style:v.sheetHandleRow,children:_jsx(View,{style:[v.sheetHandle,{backgroundColor:V.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[v.sheetTitle,{paddingHorizontal:V.space.lg,marginBottom:V.space.sm}],children:o}):null]})}),y?_jsx(View,{style:[v.searchWrap,{marginHorizontal:V.space.lg,marginBottom:V.space.sm}],children:_jsxs(View,{style:[v.searchBox,{backgroundColor:V.colors["bg-subtle"],borderColor:V.colors.border,borderRadius:V.radius.md,...smoothCorners,paddingHorizontal:V.space.md,gap:V.space.sm}],children:[(V.settings.icons.search??defaultIcons.search)({size:18,color:V.colors["text-subtle"]}),_jsx(TextInput,{value:P,onChangeText:H,placeholder:a.searchPlaceholder,placeholderTextColor:V.colors["text-subtle"],selectionColor:f??V.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[v.searchInput,{color:V.colors["text-body"],fontSize:V.text.base.size,paddingVertical:V.space.sm}]}),P.length>0?_jsx(Pressable,{onPress:()=>H(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(V.settings.icons.close??defaultIcons.close)({size:18,color:V.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[v.listWrap,Q?v.listRow:null],children:[_jsx(GestureDetector,{gesture:z,children:_jsx(FlatList,{ref:Y,data:J,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(L(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[v.sectionHeader,{paddingHorizontal:V.space.lg,paddingTop:V.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:v.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=k(o),i=L(o),n=I(o),a=R(o),c=(d=i,Array.isArray(b)?b.some(e=>String(e)===String(d)):null!=b&&String(b)===String(d));var d;const p=O(o),u=m?.(o)??!1;return _jsxs(Pressable,{onPress:()=>g(i,o),disabled:p,android_ripple:{color:V.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[v.optionRow,{backgroundColor:c?V.colors["surface-selected"]:e?V.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:V.space.lg,paddingVertical:V.space.md},T,c?j:null],children:[l?_jsx(View,{style:v.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[a?_jsx(View,{style:v.optionIcon,children:a}):null,_jsxs(View,{style:v.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[v.optionLabel,w,c?C:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:v.optionDescription,children:n}):null]})]}),x?_jsx(View,{style:[v.checkbox,{borderColor:c?V.colors.primary:V.colors.border,backgroundColor:c?V.colors.primary:"transparent"}],children:c?_jsx(View,{style:v.checkboxTick}):null}):c?"icon"===V.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:v.singleSelectedIcon,children:(V.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:V.colors.primary})}):_jsx(View,{style:[v.singleSelectedDot,{backgroundColor:V.colors.primary}]}):null]})},onScrollToIndexFailed:oe,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!Q,style:Q?v.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:V.space.xl},children:a.empty})})}),Q?_jsx(View,{style:[v.rail,{paddingRight:V.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:X.map(e=>{const t=Z.has(e);return _jsx(Pressable,{onPress:()=>q(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:a.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:v.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[v.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),x?_jsx(View,{style:[v.sheetFooter,{borderTopColor:V.colors["border-subtle"],paddingHorizontal:V.space.lg,paddingVertical:V.space.md}],children:_jsx(Pressable,{onPress:K,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[v.doneButton,{backgroundColor:e?V.colors["primary-pressed"]:V.colors.primary,borderRadius:V.radius.md,...smoothCorners,paddingVertical:V.space.sm,paddingHorizontal:V.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:V.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMemo(()=>({...DEFAULT_OPTION_SHEET_LABELS,...i}),[i]),c=useRef(o);c.current=o;const d=useRef(!1);return useEffect(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:a.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??a.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:a})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:14},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{selectOptionAction,selectOptionDescription,selectOptionDisabled,selectOptionIcon,selectOptionLabel,selectOptionValue}from"./optionAccessors.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18;export const DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`});const hostStyle=StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,getOptionAction:g,value:b,onChange:x,multi:y=!1,searchable:f=!1,searchSelectionColor:S,accessibilityLabel:T,optionStyle:j,selectedOptionStyle:w,optionTextStyle:C,selectedOptionTextStyle:_,testID:k}=e,L=c??selectOptionLabel,O=d??selectOptionValue,I=p??selectOptionDescription,R=u??selectOptionDisabled,V=h??selectOptionIcon,D=g??selectOptionAction,v=useTheme(),P=useSafeAreaInsets(),H=useMemo(()=>buildStyles(v),[v]),[M,A]=useState(""),B=Dimensions.get("window").height,z=Math.round(.7*B),E=useRef(createAnimatedValue(0)).current,{handleGesture:F,opacity:W}=useDragToDismiss({drag:E,travel:z,onDismiss:t}),N=useNativeGesture(),G=useKeyboardState(e=>e.height),U=Math.max(0,Math.round(G)),$=Math.max(P.top,StatusBar.currentHeight??0)+v.space.sm,J=U>0,K=J?Math.max(0,Math.min(z,B-U-$)):z,Y=useMemo(()=>{const e=f?M.trim().toLowerCase():"",matches=t=>0===e.length||L(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:o})}}),t},[f,M,s,i,L,I]),Z=useCallback(()=>{t()},[t]),Q=useRef(null),X=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of Y.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of Y.entries()){if(o<t||"option"!==s.kind)continue;const i=L(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,Y,i,L]),q=n&&X.size>0&&0===M.trim().length,ee=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...X.has("#")?["#"]:[]],[X]),te=useCallback(e=>{const t=X.get(e);void 0!==t&&Q.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[X]),oe=useRef(null),se=useCallback(()=>{null!==oe.current&&(clearTimeout(oe.current),oe.current=null)},[]),ie=useCallback(e=>{Q.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),se(),oe.current=setTimeout(()=>{oe.current=null,Q.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[se]);useEffect(()=>se,[se]);return _jsx(GestureHandlerRootView,{style:H.gestureRoot,children:_jsxs(Animated.View,{testID:k,accessibilityViewIsModal:!0,accessibilityLabel:T??o??a.fallbackName,style:[H.sheet,{maxHeight:K,marginBottom:U,paddingBottom:J?v.space.lg:P.bottom+v.space.lg,backgroundColor:v.colors.surface,borderTopLeftRadius:v.radius.xl,borderTopRightRadius:v.radius.xl,...smoothCorners,opacity:W,transform:[{translateY:E}],...v.shadow.modal}],children:[_jsx(GestureDetector,{gesture:F,children:_jsxs(View,{children:[_jsx(View,{style:H.sheetHandleRow,children:_jsx(View,{style:[H.sheetHandle,{backgroundColor:v.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[H.sheetTitle,{paddingHorizontal:v.space.lg,marginBottom:v.space.sm}],children:o}):null]})}),f?_jsx(View,{style:[H.searchWrap,{marginHorizontal:v.space.lg,marginBottom:v.space.sm}],children:_jsxs(View,{style:[H.searchBox,{backgroundColor:v.colors["bg-subtle"],borderColor:v.colors.border,borderRadius:v.radius.md,...smoothCorners,paddingHorizontal:v.space.md,gap:v.space.sm}],children:[(v.settings.icons.search??defaultIcons.search)({size:18,color:v.colors["text-subtle"]}),_jsx(TextInput,{value:M,onChangeText:A,placeholder:a.searchPlaceholder,placeholderTextColor:v.colors["text-subtle"],selectionColor:S??v.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[H.searchInput,{color:v.colors["text-body"],fontSize:v.text.base.size,paddingVertical:v.space.sm}]}),M.length>0?_jsx(Pressable,{onPress:()=>A(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(v.settings.icons.close??defaultIcons.close)({size:18,color:v.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[H.listWrap,q?H.listRow:null],children:[_jsx(GestureDetector,{gesture:N,children:_jsx(FlatList,{ref:Q,data:Y,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(O(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[H.sectionHeader,{paddingHorizontal:v.space.lg,paddingTop:v.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:H.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=L(o),i=O(o),n=I(o),a=V(o),c=(d=i,Array.isArray(b)?b.some(e=>String(e)===String(d)):null!=b&&String(b)===String(d));var d;const p=R(o),u=m?.(o)??!1,h=D(o);return _jsxs(Pressable,{onPress:()=>{if(h)return h(),void Z();x(i,o)},disabled:p,android_ripple:{color:v.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[H.optionRow,{backgroundColor:c?v.colors["surface-selected"]:e?v.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:v.space.lg,paddingVertical:v.space.md},j,c?w:null],children:[l?_jsx(View,{style:H.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[a?_jsx(View,{style:H.optionIcon,children:a}):null,_jsxs(View,{style:H.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[H.optionLabel,C,c?_:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:H.optionDescription,children:n}):null]})]}),y?_jsx(View,{style:[H.checkbox,{borderColor:c?v.colors.primary:v.colors.border,backgroundColor:c?v.colors.primary:"transparent"}],children:c?_jsx(View,{style:H.checkboxTick}):null}):c?"icon"===v.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:H.singleSelectedIcon,children:(v.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:v.colors.primary})}):_jsx(View,{style:[H.singleSelectedDot,{backgroundColor:v.colors.primary}]}):null]})},onScrollToIndexFailed:ie,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!q,style:q?H.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:v.space.xl},children:a.empty})})}),q?_jsx(View,{style:[H.rail,{paddingRight:v.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:ee.map(e=>{const t=X.has(e);return _jsx(Pressable,{onPress:()=>te(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:a.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:H.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[H.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),y?_jsx(View,{style:[H.sheetFooter,{borderTopColor:v.colors["border-subtle"],paddingHorizontal:v.space.lg,paddingVertical:v.space.md}],children:_jsx(Pressable,{onPress:Z,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[H.doneButton,{backgroundColor:e?v.colors["primary-pressed"]:v.colors.primary,borderRadius:v.radius.md,...smoothCorners,paddingVertical:v.space.sm,paddingHorizontal:v.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:v.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMemo(()=>({...DEFAULT_OPTION_SHEET_LABELS,...i}),[i]),c=useRef(o);c.current=o;const d=useRef(!1);return useEffect(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:a.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??a.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:a})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:Math.round(e.text.xs.size*e.leading.heading)},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
@@ -1 +1 @@
1
- "use strict";import{isValidElement}from"react";import{isRecord}from"../../utils/guards.js";const isReactNode=e=>null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e||Array.isArray(e)||isValidElement(e);export const selectOptionLabel=e=>isRecord(e)&&"string"==typeof e.label?e.label:"";export const selectOptionValue=e=>{if(isRecord(e)&&("string"==typeof e.value||"number"==typeof e.value))return e.value;throw new Error("Option has no string or number value; pass getOptionValue.")};export const selectOptionDescription=e=>isRecord(e)&&"string"==typeof e.description?e.description:void 0;export const selectOptionDisabled=e=>isRecord(e)&&!0===e.disabled;export const selectOptionIcon=e=>isRecord(e)&&isReactNode(e.icon)?e.icon:void 0;
1
+ "use strict";import{isValidElement}from"react";import{isRecord}from"../../utils/guards.js";const isReactNode=e=>null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e||Array.isArray(e)||isValidElement(e);export const selectOptionLabel=e=>isRecord(e)&&"string"==typeof e.label?e.label:"";export const selectOptionValue=e=>{if(isRecord(e)&&("string"==typeof e.value||"number"==typeof e.value))return e.value;throw new Error("Option has no string or number value; pass getOptionValue.")};export const selectOptionDescription=e=>isRecord(e)&&"string"==typeof e.description?e.description:void 0;export const selectOptionDisabled=e=>isRecord(e)&&!0===e.disabled;export const selectOptionIcon=e=>isRecord(e)&&isReactNode(e.icon)?e.icon:void 0;const isAction=e=>"function"==typeof e;export const selectOptionAction=e=>isRecord(e)&&isAction(e.onPress)?e.onPress:void 0;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useMemo,useRef}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{IconButton}from"../IconButton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";let rowIdCounter=0;const nextRowId=()=>(rowIdCounter+=1,`row-${rowIdCounter}`);export const DEFAULT_REPEATER_LABELS=Object.freeze({add:"Add another",empty:"",row:null,removeRow:e=>`Remove ${e}`,fallbackRow:e=>`row ${e+1}`});export const Repeater=({value:e,onChange:t,createRow:r,renderRow:o,labels:n,renderRowHeader:s,onRemove:i,minRows:a=0,maxRows:l,removable:c=!0,disabled:m=!1,haptic:u,style:p,testID:d})=>{const x=useTheme(),w=useMemo(()=>({...DEFAULT_REPEATER_LABELS,...n}),[n]),h=useRef([]);if(h.current.length<e.length)for(;h.current.length<e.length;)h.current.push(nextRowId());else h.current.length>e.length&&(h.current.length=e.length);const f="number"==typeof l&&e.length>=l,g=c&&e.length>a,R=useCallback(e=>{const t=resolveHaptic(u,e);t&&triggerHaptic(t)},[u]),j=useCallback(()=>{m||f||(t([...e,r()]),R("impactLight"))},[f,r,m,R,t,e]),v=useCallback((r,o)=>{t(e.map((e,t)=>t===r?o:e))},[t,e]),b=useCallback(r=>{if(m||!g)return;const o=e[r];if(void 0===o)throw new Error(`Repeater: no row at index ${r} to remove.`);h.current=h.current.filter((e,t)=>t!==r),i?.(r,o),t(e.filter((e,t)=>t!==r)),R("notificationWarning")},[g,m,R,t,i,e]);return _jsxs(View,{style:[{gap:x.space.md},p],testID:d,children:[0===e.length&&w.empty.length>0?_jsx(Text,{variant:"bodySmall",color:"tertiary",children:w.empty}):null,e.map((e,t)=>{const r={item:e,index:t,update:e=>v(t,e),remove:()=>b(t),canRemove:g};return _jsxs(View,{style:{gap:x.space.xs},children:[s?s(r):w.row||g&&!m?_jsxs(View,{style:styles.rowHeader,children:[w.row?_jsx(Text,{variant:"overline",color:"tertiary",children:w.row(t)}):_jsx(View,{}),g&&!m?_jsx(IconButton,{icon:({color:e,size:t})=>_jsx(AppIcon,{name:"x",size:t,color:e}),onPress:()=>b(t),accessibilityLabel:w.removeRow(w.row?w.row(t):w.fallbackRow(t)),size:"sm",tone:"danger",variant:"ghost",haptic:u,testID:d?`${d}-remove-${t}`:void 0}):null]}):null,o(r)]},h.current[t])}),f||m?null:_jsx(Button,{label:w.add,onPress:j,variant:"outline",size:"sm",haptic:u,testID:d?`${d}-add`:void 0})]})};const styles=StyleSheet.create({rowHeader:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",minHeight:24}});export default Repeater;
1
+ "use strict";import{useCallback,useMemo,useRef}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{IconButton}from"../IconButton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";let rowIdCounter=0;const nextRowId=()=>(rowIdCounter+=1,`row-${rowIdCounter}`);export const DEFAULT_REPEATER_LABELS=Object.freeze({add:"Add another",empty:"",row:null,removeRow:e=>`Remove ${e}`,fallbackRow:e=>`row ${e+1}`});export const Repeater=({value:e,onChange:t,createRow:r,renderRow:o,labels:n,renderRowHeader:s,onRemove:i,minRows:a=0,maxRows:l,removable:c=!0,disabled:m=!1,haptic:u,style:p,testID:d})=>{const x=useTheme(),w=useMemo(()=>({...DEFAULT_REPEATER_LABELS,...n}),[n]),h=useRef([]);if(h.current.length<e.length)for(;h.current.length<e.length;)h.current.push(nextRowId());else h.current.length>e.length&&(h.current.length=e.length);const f="number"==typeof l&&e.length>=l,g=c&&e.length>a,R=useCallback(e=>{const t=resolveHaptic(u,e);t&&triggerHaptic(t)},[u]),j=useCallback(()=>{m||f||(t([...e,r()]),R("impactLight"))},[f,r,m,R,t,e]),v=useCallback((r,o)=>{t(e.map((e,t)=>t===r?o:e))},[t,e]),b=useCallback(r=>{if(m||!g)return;const o=e[r];if(void 0===o)throw new Error(`Repeater: no row at index ${r} to remove.`);h.current=h.current.filter((e,t)=>t!==r),i?.(r,o),t(e.filter((e,t)=>t!==r)),R("notificationWarning")},[g,m,R,t,i,e]);return _jsxs(View,{style:[{gap:x.space.md},p],testID:d,children:[0===e.length&&w.empty.length>0?_jsx(Text,{variant:"bodySmall",color:"tertiary",children:w.empty}):null,e.map((e,t)=>{const r={item:e,index:t,update:e=>v(t,e),remove:()=>b(t),canRemove:g};return _jsxs(View,{style:{gap:x.space.xs},children:[s?s(r):w.row||g&&!m?_jsxs(View,{style:styles.rowHeader,children:[w.row?_jsx(Text,{variant:"overline",color:"tertiary",children:w.row(t)}):_jsx(View,{}),g&&!m?_jsx(IconButton,{icon:({color:e,size:t})=>_jsx(AppIcon,{name:"x",size:t,color:e}),onPress:()=>b(t),accessibilityLabel:w.removeRow(w.row?w.row(t):w.fallbackRow(t)),size:"sm",tone:"danger",variant:"ghost",haptic:!1,testID:d?`${d}-remove-${t}`:void 0}):null]}):null,o(r)]},h.current[t])}),f||m?null:_jsx(Button,{label:w.add,onPress:j,variant:"outline",size:"sm",haptic:!1,testID:d?`${d}-add`:void 0})]})};const styles=StyleSheet.create({rowHeader:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",minHeight:24}});export default Repeater;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`});const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:i,shownAt:n,runtime:a})=>{const s=useTheme(),r=usePresenceMotion(),o=r.duration("fast");assertValidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=a?.labels??DEFAULT_TOAST_LABELS,d=useMemo(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=useMemo(()=>buildStyles(s),[s]),p=useMemo(()=>tintFor(s,l),[s,l]),g=useMemo(()=>inkFor(s,l),[s,l]),v=s.components.toast["icon-circle-size"],h=s.text[s.components.toast["icon-glyph-text"]].size,f=s.components.toast["tint-bar-width"],b=s.settings.components.toast?.defaultDurationMs??3e3,A=s.settings.components.toast?.enableSwipeDismiss??!0,x="top"===c?-120:120,y=useRef(createAnimatedValue(r.reduced?0:x)).current,w=useRef(createAnimatedValue(0)).current,D=useRef(createAnimatedValue(0)).current,S=useRef(!1),T="top"===c?8*t:8*-t,V=Math.max(1-.04*t,.9),M=useRef(createAnimatedValue(T)).current;useEffect(()=>{setNativeValue(M,T)},[T,M]);const _=useMemo(()=>Animated.add(y,M),[y,M]),R=void 0!==e.action,C=e.duration??b,E=C>0&&R&&"web"===Platform.OS?Math.max(C,8e3):C,N=E<=0||R&&!0===a?.screenReaderOn,j=!0===e.countdown&&!N,P=useRef(createAnimatedValue(1)).current,O=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),k=useRef({touch:!1,pan:!1,hover:!1}),L=useRef(()=>{}),I=useRef({id:e.id,totalMs:E,shownAt:n,runtime:a,persistent:N,animateBar:!1});I.current={id:e.id,totalMs:E,shownAt:n,runtime:a,persistent:N,animateBar:j&&!r.reduced};const H=useCallback(()=>{const e=O.current,t=I.current,i=k.current;if(!e.initialised){e.initialised=!0;const i=t.runtime?.readRemaining(t.id),n=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=i??(t.totalMs>0?Math.max(t.totalMs-n,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(P,e.remaining/t.totalMs)}const n=!(t.persistent||S.current||i.touch||i.pan||i.hover);n&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,L.current()},e.remaining),t.animateBar&&Animated.timing(P,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:nativeDriver}).start()):n||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),P.stopAnimation())},[P]),dismiss=()=>{if(S.current)return;S.current=!0,H();const t=[Animated.timing(D,{toValue:0,duration:o,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:nativeDriver})];r.reduced||t.push(Animated.timing(y,{toValue:x,duration:s.motion.duration.fast,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:nativeDriver})),Animated.parallel(t).start(()=>i(e.id))};L.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.spring(y,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{H()},[N,H]),useEffect(()=>()=>{const e=O.current,t=I.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),P.stopAnimation(),e.initialised&&t.totalMs>0&&!S.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[P]);const B=useCallback((e,t)=>{k.current[e]=t,H()},[H]),F=useCallback(()=>B("touch",!0),[B]),z=useCallback(e=>B("touch",(e.nativeEvent.touches?.length??0)>0),[B]),U=useCallback(()=>B("hover",!0),[B]),$=useCallback(()=>B("hover",!1),[B]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>B("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(w,t.dx);const i=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(D,i)},onPanResponderTerminate:()=>{if(B("pan",!1),r.reduced)return setNativeValue(w,0),void Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start();Animated.parallel([Animated.spring(w,{toValue:0,damping:s.motion.spring.snappy.damping,stiffness:s.motion.spring.snappy.stiffness,mass:s.motion.spring.snappy.mass,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]).start()},onPanResponderRelease:(t,n)=>{if(Math.abs(n.dx)>80||Math.abs(n.vx)>.5){const t=n.dx>=0?1:-1;S.current=!0,B("pan",!1);const a=[Animated.timing(D,{toValue:0,duration:o,useNativeDriver:nativeDriver})];r.reduced||a.push(Animated.timing(w,{toValue:500*t,duration:s.motion.duration.fast,useNativeDriver:nativeDriver})),Animated.parallel(a).start(()=>i(e.id))}else B("pan",!1),r.reduced?(setNativeValue(w,0),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start()):Animated.parallel([Animated.spring(w,{toValue:0,useNativeDriver:nativeDriver}),Animated.spring(D,{toValue:1,useNativeDriver:nativeDriver})]).start()}}),[w,D,B,o,r.reduced,s.motion.duration.fast,s.motion.spring.snappy.damping,s.motion.spring.snappy.stiffness,s.motion.spring.snappy.mass,i,e.id]),W={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[K,X]=useState(0),Y=useMemo(()=>P.interpolate({inputRange:[0,1],outputRange:[-K,0]}),[P,K]),q=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&j?`${e.action.label}, ${u.seconds(Math.ceil(E/1e3))}`:e.action?.label;return _jsxs(Animated.View,{...A?G.panHandlers:{},...R?{}:{accessible:!0,...W},..."web"===Platform.OS?{onPointerEnter:U,onPointerLeave:$}:{},onTouchStart:F,onTouchEnd:z,onTouchCancel:z,accessibilityLabel:q,testID:e.testID,style:[m.container,{backgroundColor:s.colors.surface,borderRadius:s.radius.lg,...smoothCorners,padding:s.space.md,...s.shadow.elevated,opacity:D,transform:[{translateY:_},{translateX:w},{scale:V}]},e.style],children:[f>0?_jsx(View,{style:[m.tintBar,{width:f,backgroundColor:p}]}):null,_jsxs(View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[m.iconCircle,{width:v,height:v,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:`${p}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[m.iconGlyph,{color:g,fontSize:h}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:m.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[m.message,e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...W,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?s.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:p},numberOfLines:1,children:e.action.label})}):null]}),j?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>X(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${p}22`}],children:[r.reduced?_jsx(View,{style:[m.countdownFill,{backgroundColor:p}]}):null,!r.reduced&&K>0?_jsx(Animated.View,{style:[m.countdownFill,{backgroundColor:p,transform:[{translateX:Y}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;case"neutral":return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];case"neutral":return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";case"primary":case"neutral":return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`});const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:i,shownAt:n,runtime:a})=>{const s=useTheme(),r=usePresenceMotion(),o=r.duration("fast");assertValidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=a?.labels??DEFAULT_TOAST_LABELS,d=useMemo(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=useMemo(()=>buildStyles(s),[s]),p=useMemo(()=>tintFor(s,l),[s,l]),g=useMemo(()=>inkFor(s,l),[s,l]),h=s.components.toast["icon-circle-size"],v=s.text[s.components.toast["icon-glyph-text"]].size,f=s.components.toast["tint-bar-width"],b=s.settings.components.toast?.defaultDurationMs??3e3,x=s.settings.components.toast?.enableSwipeDismiss??!0,A="top"===c?-120:120,y=useRef(createAnimatedValue(r.reduced?0:A)).current,w=useRef(createAnimatedValue(0)).current,D=useRef(createAnimatedValue(0)).current,S=useRef(!1),T="top"===c?8*t:8*-t,V=Math.max(1-.04*t,.9),M=useRef(createAnimatedValue(T)).current;useEffect(()=>{setNativeValue(M,T)},[T,M]);const _=useMemo(()=>Animated.add(y,M),[y,M]),R=void 0!==e.action,C=e.duration??b,E=C>0&&R&&"web"===Platform.OS?Math.max(C,8e3):C,N=E<=0||R&&!0===a?.screenReaderOn,j=!0===e.countdown&&!N,P=useRef(createAnimatedValue(1)).current,O=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),k=useRef({touch:!1,pan:!1,hover:!1}),L=useRef(()=>{}),I=useRef({id:e.id,totalMs:E,shownAt:n,runtime:a,persistent:N,animateBar:!1});I.current={id:e.id,totalMs:E,shownAt:n,runtime:a,persistent:N,animateBar:j&&!r.reduced};const B=useCallback(()=>{const e=O.current,t=I.current,i=k.current;if(!e.initialised){e.initialised=!0;const i=t.runtime?.readRemaining(t.id),n=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=i??(t.totalMs>0?Math.max(t.totalMs-n,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(P,e.remaining/t.totalMs)}const n=!(t.persistent||S.current||i.touch||i.pan||i.hover);n&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,L.current()},e.remaining),t.animateBar&&Animated.timing(P,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:nativeDriver}).start()):n||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),P.stopAnimation())},[P]),dismiss=()=>{if(S.current)return;S.current=!0,B();const t=[Animated.timing(D,{toValue:0,duration:o,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:nativeDriver})];r.reduced||t.push(Animated.timing(y,{toValue:A,duration:s.motion.duration.fast,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:nativeDriver})),Animated.parallel(t).start(()=>i(e.id))};L.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.spring(y,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{B()},[N,B]),useEffect(()=>()=>{const e=O.current,t=I.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),P.stopAnimation(),e.initialised&&t.totalMs>0&&!S.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[P]);const H=useCallback((e,t)=>{k.current[e]=t,B()},[B]),F=useCallback(()=>H("touch",!0),[H]),z=useCallback(e=>H("touch",(e.nativeEvent.touches?.length??0)>0),[H]),U=useCallback(()=>H("hover",!0),[H]),$=useCallback(()=>H("hover",!1),[H]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>H("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(w,t.dx);const i=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(D,i)},onPanResponderTerminate:()=>{if(H("pan",!1),r.reduced)return setNativeValue(w,0),void Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start();Animated.parallel([Animated.spring(w,{toValue:0,damping:s.motion.spring.snappy.damping,stiffness:s.motion.spring.snappy.stiffness,mass:s.motion.spring.snappy.mass,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]).start()},onPanResponderRelease:(t,n)=>{if(Math.abs(n.dx)>80||Math.abs(n.vx)>.5){const t=n.dx>=0?1:-1;S.current=!0,H("pan",!1);const a=[Animated.timing(D,{toValue:0,duration:o,useNativeDriver:nativeDriver})];r.reduced||a.push(Animated.timing(w,{toValue:500*t,duration:s.motion.duration.fast,useNativeDriver:nativeDriver})),Animated.parallel(a).start(()=>i(e.id))}else H("pan",!1),r.reduced?(setNativeValue(w,0),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start()):Animated.parallel([Animated.spring(w,{toValue:0,useNativeDriver:nativeDriver}),Animated.spring(D,{toValue:1,useNativeDriver:nativeDriver})]).start()}}),[w,D,H,o,r.reduced,s.motion.duration.fast,s.motion.spring.snappy.damping,s.motion.spring.snappy.stiffness,s.motion.spring.snappy.mass,i,e.id]),W={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[K,X]=useState(0),Y=useMemo(()=>P.interpolate({inputRange:[0,1],outputRange:[-K,0]}),[P,K]),q=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&j?`${e.action.label}, ${u.seconds(Math.ceil(E/1e3))}`:e.action?.label;return _jsxs(Animated.View,{...x?G.panHandlers:{},...R?{}:{accessible:!0,...W},..."web"===Platform.OS?{onPointerEnter:U,onPointerLeave:$}:{},onTouchStart:F,onTouchEnd:z,onTouchCancel:z,accessibilityLabel:q,testID:e.testID,style:[m.container,{backgroundColor:s.colors.surface,borderRadius:s.radius.lg,...smoothCorners,padding:s.space.md,...s.shadow.elevated,opacity:D,transform:[{translateY:_},{translateX:w},{scale:V}]},e.style],children:[f>0?_jsx(View,{style:[m.tintBar,{width:f,backgroundColor:p}]}):null,_jsxs(View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[m.iconCircle,{width:h,height:h,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:`${p}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[m.iconGlyph,{color:g,fontSize:v}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:m.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...W,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?s.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:p},numberOfLines:1,children:e.action.label})}):null]}),j?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>X(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${p}22`}],children:[r.reduced?_jsx(View,{style:[m.countdownFill,{backgroundColor:p}]}):null,!r.reduced&&K>0?_jsx(Animated.View,{style:[m.countdownFill,{backgroundColor:p,transform:[{translateX:Y}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;case"neutral":return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];case"neutral":return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";case"primary":case"neutral":return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:Math.round(e.text[e.components.toast["icon-glyph-text"]].size*e.leading.heading)},textBlock:{flex:1,paddingRight:e.space.sm},description:{marginTop:e.space.xxs},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
@@ -1 +1 @@
1
- "use strict";import{Fragment,memo,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Platform,Pressable,StyleSheet,TextInput,View}from"react-native";import{createAnimatedValue,setNativeValue}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const WHEEL_VISIBLE_ITEMS=5;export const WHEEL_CENTER_OFFSET=Math.floor(2.5);const HAPTIC_DEBOUNCE_MS=35,WEB_SETTLE_MS=120,SCALE_STOPS=[-2,-1,0,1,2],WheelRow=memo(({label:e,index:t,scrollY:n,itemHeight:r,selected:a,theme:i,reducedMotion:s,onPress:l,editor:c})=>{const{opacity:o,scale:u}=useMemo(()=>{const e=Animated.subtract(Animated.divide(n,r),t);return{opacity:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.3,.6,1,.6,.3],extrapolate:"clamp"}),scale:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.85,.95,1.05,.95,.85],extrapolate:"clamp"})}},[n,r,t]),m=_jsx(Text,{variant:"h3",weight:a?"semibold":"medium",color:a?"primary":"secondary",numberOfLines:1,maxFontSizeMultiplier:1.5,style:{letterSpacing:i["letter-spacing"].normal},children:e});return _jsx(Animated.View,{style:[styles.row,{height:r},s?{opacity:o}:{opacity:o,transform:[{scale:u}]}],accessible:!1,importantForAccessibility:"no",children:c??(l?_jsx(Pressable,{focusable:!1,accessible:!1,onPress:()=>l(t),style:styles.rowPress,children:m}):m)})});export const Wheel=({label:e,items:t,selectedIndex:n,onIndexChange:r,itemHeight:a,width:i,theme:s,haptic:l,disabled:c,reducedMotion:o,typeable:u,testID:m})=>{const d="web"===Platform.OS,[b,f]=useState(null),y=useRef(!1),h=useRef(null),p=useRef(createAnimatedValue(n*a)).current,x=useRef(n*a),v=useRef(n*a),g=useRef(n),S=useRef(0),E=useRef(null),T=useRef(()=>{}),w=t.length-1;useEffect(()=>{g.current=n;const e=n*a;if(v.current===e)return;if(v.current=e,Math.abs(x.current-e)<1)return;x.current=e,d||setNativeValue(p,e);const t=requestAnimationFrame(()=>{h.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[n,a,p,d]),useEffect(()=>{const e=x.current,t=requestAnimationFrame(()=>{h.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[]),useEffect(()=>()=>{E.current&&clearTimeout(E.current)},[]);const M=useCallback((e,a)=>{if(!(e===n||e<0||e>w)){if("accessibility"===a){const e=resolveHaptic(l,"denseTick");e&&triggerHaptic(e)}if("keyboard"!==a){const n=t[e];n&&announce(n.accessibilityLabel??n.label)}r(e)}},[n,w,t,l,r]),A=useCallback(()=>{!c&&u&&(y.current=!0,f(String(t[n]?.value??"")))},[c,u,t,n]),_=useCallback(e=>{if(!y.current)return;y.current=!1,f(null);const n=e.trim();if(!/^\d+$/.test(n))return;const r=Number(n),a=t.findIndex(e=>e.value===r);a>=0&&M(a,"keyboard")},[t,M]);T.current=()=>{E.current=null;const e=Math.max(0,Math.min(w,Math.round(x.current/a))),t=e*a;Math.abs(x.current-t)>=1&&h.current?.scrollTo({y:t,animated:!o}),M(e,"scroll")};const j=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:p}}}],{useNativeDriver:nativeDriver,listener:e=>{const t=e.nativeEvent.contentOffset.y;x.current=t;const n=Math.round(t/a);if(n!==g.current&&n>=0&&n<=w){const e=Date.now();if(e-S.current>=35){const t=resolveHaptic(l,"denseTick");t&&triggerHaptic(t),S.current=e}g.current=n}d&&(E.current&&clearTimeout(E.current),E.current=setTimeout(()=>T.current(),120))}}),[p,a,w,l,d]),C=useCallback(e=>{const t=e.nativeEvent.contentOffset.y;M(Math.max(0,Math.min(w,Math.round(t/a))),"scroll")},[M,w,a]),R=useCallback(e=>{if(c)return;const t=e.nativeEvent.actionName;"increment"===t?M(Math.min(w,n+1),"accessibility"):"decrement"===t&&M(Math.max(0,n-1),"accessibility")},[c,M,w,n]),F=useCallback(e=>{c||h.current?.scrollTo({y:e*a,animated:!o})},[c,a,o]),k=useCallback(({item:t,index:r})=>{const i=r===n,l=i&&null!==b;return _jsx(WheelRow,{label:t.label,index:r,scrollY:p,itemHeight:a,selected:i,theme:s,reducedMotion:o,onPress:i&&u?A:d?F:void 0,editor:l?_jsx(TextInput,{autoFocus:!0,selectTextOnFocus:!0,keyboardType:"number-pad",returnKeyType:"done",accessibilityLabel:e,value:b,onChangeText:f,onSubmitEditing:()=>_(b),onBlur:()=>_(b),style:{width:"100%",padding:s.space.none,textAlign:"center",fontSize:s.text.xl.size,color:s.colors["text-body"],fontWeight:s.weight.semibold,letterSpacing:s["letter-spacing"].normal}}):void 0})},[p,a,n,s,o,d,F,u,A,b,_,e]),I=useCallback((e,t)=>`${String(e.value)}-${t}`,[]),L=t[n]?t[n].accessibilityLabel??t[n].label:"",P=d?{focusable:!0,role:"spinbutton","aria-label":e,"aria-valuetext":L,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":w,"aria-disabled":c,onKeyDown:e=>{if(c)return;const t={ArrowDown:Math.min(w,n+1),PageDown:Math.min(w,n+1),ArrowUp:Math.max(0,n-1),PageUp:Math.max(0,n-1),Home:0,End:w}[e.nativeEvent.key];void 0!==t&&(e.preventDefault(),M(t,"keyboard"))}}:void 0;return _jsxs(View,{style:[void 0===i?styles.columnFlex:{width:i},{height:5*a},styles.column,c?styles.disabled:null],testID:m,...P,children:[d?null:_jsx(View,{pointerEvents:"none",style:styles.a11yLayer,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:e,accessibilityValue:{text:L},accessibilityState:{disabled:Boolean(c)},"aria-disabled":Boolean(c),accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:R}),_jsx(Animated.ScrollView,{ref:h,showsVerticalScrollIndicator:!1,snapToInterval:a,snapToAlignment:"start",decelerationRate:"fast",bounces:!1,scrollEnabled:!c,nestedScrollEnabled:!0,scrollEventThrottle:16,onScroll:j,onMomentumScrollEnd:C,contentOffset:{x:0,y:n*a},contentContainerStyle:{paddingVertical:a*WHEEL_CENTER_OFFSET},style:[styles.list,{height:5*a}],importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:t.map((e,t)=>_jsx(Fragment,{children:k({item:e,index:t})},I(e,t)))})]})};const styles=StyleSheet.create({column:{overflow:"hidden"},columnFlex:{flex:1},disabled:{opacity:.5},list:{flexGrow:0},row:{alignItems:"center",justifyContent:"center"},rowPress:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",flex:1},a11yLayer:{...StyleSheet.absoluteFill,zIndex:2}});
1
+ "use strict";import{Fragment,memo,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Platform,Pressable,StyleSheet,TextInput,View}from"react-native";import{createAnimatedValue,setNativeValue}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const WHEEL_VISIBLE_ITEMS=5;export const WHEEL_CENTER_OFFSET=Math.floor(2.5);const HAPTIC_DEBOUNCE_MS=35,WEB_SETTLE_MS=120,SCALE_STOPS=[-2,-1,0,1,2],WheelRow=memo(({label:e,index:t,scrollY:n,itemHeight:r,selected:i,theme:a,reducedMotion:s,onPress:l,hidden:c})=>{const{opacity:o,scale:u}=useMemo(()=>{const e=Animated.subtract(Animated.divide(n,r),t);return{opacity:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.3,.6,1,.6,.3],extrapolate:"clamp"}),scale:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.85,.95,1.05,.95,.85],extrapolate:"clamp"})}},[n,r,t]),d=_jsx(Text,{variant:"h3",weight:i?"semibold":"medium",color:i?"primary":"secondary",numberOfLines:1,maxFontSizeMultiplier:1.5,style:{letterSpacing:a["letter-spacing"].normal},children:e});return _jsx(Animated.View,{style:[styles.row,{height:r},s?{opacity:o}:{opacity:o,transform:[{scale:u}]},c?styles.rowHidden:null],accessible:!1,importantForAccessibility:"no",children:l?_jsx(Pressable,{focusable:!1,accessible:!1,onPress:()=>l(t),style:styles.rowPress,children:d}):d})});export const Wheel=({label:e,items:t,selectedIndex:n,onIndexChange:r,itemHeight:i,width:a,theme:s,haptic:l,disabled:c,reducedMotion:o,typeable:u,typeAction:d,typeEditor:m,testID:y})=>{const b="web"===Platform.OS,[f,p]=useState(null),h=useRef(!1),x=useRef(null),v=useRef(null),E=useRef(!1),g=useRef(createAnimatedValue(n*i)).current,S=useRef(n*i),T=useRef(n*i),w=useRef(n),A=useRef(0),M=useRef(null),_=useRef(()=>{}),j=t.length-1;useEffect(()=>{w.current=n;const e=n*i;if(T.current===e)return;if(T.current=e,Math.abs(S.current-e)<1)return;S.current=e,b||setNativeValue(g,e);const t=requestAnimationFrame(()=>{x.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[n,i,g,b]),useEffect(()=>{const e=S.current,t=requestAnimationFrame(()=>{x.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[]),useEffect(()=>()=>{M.current&&clearTimeout(M.current)},[]);const C=useCallback((e,i)=>{if(!(e===n||e<0||e>j)){if("accessibility"===i){const e=resolveHaptic(l,"denseTick");e&&triggerHaptic(e)}if("keyboard"!==i){const n=t[e];n&&announce(n.accessibilityLabel??n.label)}r(e)}},[n,j,t,l,r]),R=useCallback(()=>{!c&&u&&(h.current=!0,p(String(t[n]?.value??"")))},[c,u,t,n]),F=useCallback(e=>{if(!h.current)return;h.current=!1,p(null);const n=e.trim();if(!/^\d+$/.test(n))return;const r=Number(n),i=t.findIndex(e=>e.value===r);i>=0&&C(i,"keyboard")},[t,C]);useEffect(()=>{if(null!==f||!E.current)return;E.current=!1;const e=v.current;e&&"web"!==Platform.OS&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},[f]),_.current=()=>{M.current=null;const e=Math.max(0,Math.min(j,Math.round(S.current/i))),t=e*i;Math.abs(S.current-t)>=1&&x.current?.scrollTo({y:t,animated:!o}),C(e,"scroll")};const I=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:g}}}],{useNativeDriver:nativeDriver,listener:e=>{const t=e.nativeEvent.contentOffset.y;S.current=t;const n=Math.round(t/i);if(n!==w.current&&n>=0&&n<=j){const e=Date.now();if(e-A.current>=35){const t=resolveHaptic(l,"denseTick");t&&triggerHaptic(t),A.current=e}w.current=n}b&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>_.current(),120))}}),[g,i,j,l,b]),k=useCallback(e=>{const t=e.nativeEvent.contentOffset.y;C(Math.max(0,Math.min(j,Math.round(t/i))),"scroll")},[C,j,i]),H=useCallback(t=>{if(c)return;const r=t.nativeEvent.actionName;"increment"===r?C(Math.min(j,n+1),"accessibility"):"decrement"===r?C(Math.max(0,n-1),"accessibility"):"type"===r&&(E.current=!0,R(),announce(`${e}. ${m??"Type a number"}`))},[c,C,j,n,R,e,m]),L=useMemo(()=>[{name:"increment"},{name:"decrement"},...u&&!c?[{name:"type",label:d??"Type a value"}]:[]],[u,c,d]),P=useCallback(e=>{c||x.current?.scrollTo({y:e*i,animated:!o})},[c,i,o]),O=useCallback(({item:e,index:t})=>{const r=t===n;return _jsx(WheelRow,{label:e.label,index:t,scrollY:g,itemHeight:i,selected:r,theme:s,reducedMotion:o,onPress:r&&u?R:b?P:void 0,hidden:r&&null!==f})},[g,i,n,s,o,b,P,u,R,f]),V=useCallback((e,t)=>`${String(e.value)}-${t}`,[]),D=t[n]?t[n].accessibilityLabel??t[n].label:"",N=b?{focusable:!0,role:"spinbutton","aria-label":e,"aria-valuetext":D,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":j,"aria-disabled":c,onKeyDown:e=>{if(c)return;const t={ArrowDown:Math.min(j,n+1),PageDown:Math.min(j,n+1),ArrowUp:Math.max(0,n-1),PageUp:Math.max(0,n-1),Home:0,End:j}[e.nativeEvent.key];void 0!==t&&(e.preventDefault(),C(t,"keyboard"))}}:void 0;return _jsxs(View,{style:[void 0===a?styles.columnFlex:{width:a},{height:5*i},styles.column,c?styles.disabled:null],testID:y,...N,children:[b?null:_jsx(View,{pointerEvents:"none",style:styles.a11yLayer,ref:v,accessible:null===f,importantForAccessibility:null===f?"yes":"no-hide-descendants",accessibilityRole:"adjustable",accessibilityLabel:e,accessibilityValue:{text:D},accessibilityState:{disabled:Boolean(c)},"aria-disabled":Boolean(c),accessibilityActions:L,onAccessibilityAction:H}),_jsx(Animated.ScrollView,{ref:x,showsVerticalScrollIndicator:!1,snapToInterval:i,snapToAlignment:"start",decelerationRate:"fast",bounces:!1,scrollEnabled:!c,nestedScrollEnabled:!0,scrollEventThrottle:16,onScroll:I,onMomentumScrollEnd:k,contentOffset:{x:0,y:n*i},contentContainerStyle:{paddingVertical:i*WHEEL_CENTER_OFFSET},style:[styles.list,{height:5*i}],importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:t.map((e,t)=>_jsx(Fragment,{children:O({item:e,index:t})},V(e,t)))}),null!==f?_jsx(View,{style:[styles.editorBand,{top:i*WHEEL_CENTER_OFFSET,height:i,backgroundColor:s.colors.surface}],children:_jsx(TextInput,{autoFocus:!0,selectTextOnFocus:!0,keyboardType:"number-pad",returnKeyType:"done",accessibilityLabel:e,value:f,onChangeText:p,onSubmitEditing:()=>F(f),onBlur:()=>F(f),style:{width:"100%",padding:s.space.none,textAlign:"center",fontSize:s.text.xl.size,color:s.colors["text-body"],fontWeight:s.weight.semibold,letterSpacing:s["letter-spacing"].normal}})}):null]})};const styles=StyleSheet.create({column:{overflow:"hidden"},columnFlex:{flex:1},disabled:{opacity:.5},list:{flexGrow:0},row:{alignItems:"center",justifyContent:"center"},rowHidden:{opacity:0},editorBand:{position:"absolute",left:0,right:0,justifyContent:"center",zIndex:3},rowPress:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",flex:1},a11yLayer:{...StyleSheet.absoluteFill,zIndex:2}});