@webority/mobile-ui 0.144.1 → 0.145.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 (174) hide show
  1. package/dist/canvas-kit/kit.js +4429 -3708
  2. package/dist/canvas-kit/manifest.json +1 -1
  3. package/dist/canvas-kit/release.json +5 -5
  4. package/lib/commonjs/components/Accordion/Accordion.js +1 -1
  5. package/lib/commonjs/components/AmountSlider/AmountSlider.js +1 -1
  6. package/lib/commonjs/components/AnimatePresence/AnimatePresence.js +1 -1
  7. package/lib/commonjs/components/AppBar/AppBar.js +1 -1
  8. package/lib/commonjs/components/AppIcon/AppIcon.js +1 -1
  9. package/lib/commonjs/components/AsyncBlock/AsyncBlock.js +1 -1
  10. package/lib/commonjs/components/AuthedImage/AuthedImage.js +1 -1
  11. package/lib/commonjs/components/Autocomplete/Autocomplete.js +1 -1
  12. package/lib/commonjs/components/Avatar/Avatar.js +1 -1
  13. package/lib/commonjs/components/Badge/Badge.js +1 -1
  14. package/lib/commonjs/components/Banner/Banner.js +1 -1
  15. package/lib/commonjs/components/BarChart/BarChart.js +1 -1
  16. package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
  17. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  18. package/lib/commonjs/components/Button/Button.js +1 -1
  19. package/lib/commonjs/components/Calendar/Calendar.js +1 -1
  20. package/lib/commonjs/components/Card/Card.js +1 -1
  21. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  22. package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
  23. package/lib/commonjs/components/Chip/Chip.js +1 -1
  24. package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
  25. package/lib/commonjs/components/Confetti/Confetti.js +1 -1
  26. package/lib/commonjs/components/Descriptions/Descriptions.js +1 -1
  27. package/lib/commonjs/components/Dialog/Dialog.js +1 -1
  28. package/lib/commonjs/components/Dialog/OverlayActions.js +1 -1
  29. package/lib/commonjs/components/Divider/Divider.js +1 -1
  30. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  31. package/lib/commonjs/components/EmptyState/EmptyState.js +1 -1
  32. package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
  33. package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
  34. package/lib/commonjs/components/FileViewer/FileViewer.js +1 -1
  35. package/lib/commonjs/components/FilterChipRow/FilterChipRow.js +1 -1
  36. package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
  37. package/lib/commonjs/components/FormField/FormField.js +1 -1
  38. package/lib/commonjs/components/IconBadge/IconBadge.js +1 -1
  39. package/lib/commonjs/components/IconButton/IconButton.js +1 -1
  40. package/lib/commonjs/components/InlineSelect/InlineSelect.js +1 -1
  41. package/lib/commonjs/components/Input/Input.js +1 -1
  42. package/lib/commonjs/components/ListItem/ListItem.js +1 -1
  43. package/lib/commonjs/components/ListSection/ListSection.js +1 -1
  44. package/lib/commonjs/components/Menu/Menu.js +1 -1
  45. package/lib/commonjs/components/Menu/useContextMenu.js +1 -1
  46. package/lib/commonjs/components/MessageBubble/MessageBubble.js +1 -1
  47. package/lib/commonjs/components/Modal/Modal.js +1 -1
  48. package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
  49. package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
  50. package/lib/commonjs/components/PermissionPrompt/PermissionPrompt.js +1 -1
  51. package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
  52. package/lib/commonjs/components/PickerTrigger/PickerTrigger.js +1 -1
  53. package/lib/commonjs/components/ProfileCompletion/ProfileCompletion.js +1 -1
  54. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  55. package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
  56. package/lib/commonjs/components/ProgressRing/ProgressRing.js +1 -1
  57. package/lib/commonjs/components/Radio/Radio.js +1 -1
  58. package/lib/commonjs/components/Rating/Rating.js +1 -1
  59. package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
  60. package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
  61. package/lib/commonjs/components/SectionHeader/SectionHeader.js +1 -1
  62. package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
  63. package/lib/commonjs/components/Select/Select.js +1 -1
  64. package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
  65. package/lib/commonjs/components/Skeleton/Skeleton.js +1 -1
  66. package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
  67. package/lib/commonjs/components/SlideToConfirm/SlideToConfirm.js +1 -1
  68. package/lib/commonjs/components/Slider/Slider.js +1 -1
  69. package/lib/commonjs/components/SliderField/SliderField.js +1 -1
  70. package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
  71. package/lib/commonjs/components/Spinner/Spinner.js +1 -1
  72. package/lib/commonjs/components/StatTile/StatTile.js +1 -1
  73. package/lib/commonjs/components/StatusBadge/StatusBadge.js +1 -1
  74. package/lib/commonjs/components/Stepper/Stepper.js +1 -1
  75. package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
  76. package/lib/commonjs/components/Switch/Switch.js +1 -1
  77. package/lib/commonjs/components/Tabs/Tabs.js +1 -1
  78. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  79. package/lib/commonjs/components/Text/Text.js +1 -1
  80. package/lib/commonjs/components/TimePicker/TimePicker.js +1 -1
  81. package/lib/commonjs/components/Timeline/Timeline.js +1 -1
  82. package/lib/commonjs/components/Toast/Toast.js +1 -1
  83. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  84. package/lib/commonjs/components/WheelPicker/WheelPicker.js +1 -1
  85. package/lib/commonjs/utils/assertValidValue.js +1 -0
  86. package/lib/module/components/Accordion/Accordion.js +1 -1
  87. package/lib/module/components/AmountSlider/AmountSlider.js +1 -1
  88. package/lib/module/components/AnimatePresence/AnimatePresence.js +1 -1
  89. package/lib/module/components/AppBar/AppBar.js +1 -1
  90. package/lib/module/components/AppIcon/AppIcon.js +1 -1
  91. package/lib/module/components/AsyncBlock/AsyncBlock.js +1 -1
  92. package/lib/module/components/AuthedImage/AuthedImage.js +1 -1
  93. package/lib/module/components/Autocomplete/Autocomplete.js +1 -1
  94. package/lib/module/components/Avatar/Avatar.js +1 -1
  95. package/lib/module/components/Badge/Badge.js +1 -1
  96. package/lib/module/components/Banner/Banner.js +1 -1
  97. package/lib/module/components/BarChart/BarChart.js +1 -1
  98. package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
  99. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  100. package/lib/module/components/Button/Button.js +1 -1
  101. package/lib/module/components/Calendar/Calendar.js +1 -1
  102. package/lib/module/components/Card/Card.js +1 -1
  103. package/lib/module/components/Carousel/Carousel.js +1 -1
  104. package/lib/module/components/Checkbox/Checkbox.js +1 -1
  105. package/lib/module/components/Chip/Chip.js +1 -1
  106. package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
  107. package/lib/module/components/Confetti/Confetti.js +1 -1
  108. package/lib/module/components/Descriptions/Descriptions.js +1 -1
  109. package/lib/module/components/Dialog/Dialog.js +1 -1
  110. package/lib/module/components/Dialog/OverlayActions.js +1 -1
  111. package/lib/module/components/Divider/Divider.js +1 -1
  112. package/lib/module/components/Drawer/Drawer.js +1 -1
  113. package/lib/module/components/EmptyState/EmptyState.js +1 -1
  114. package/lib/module/components/FieldBase/FieldBase.js +1 -1
  115. package/lib/module/components/FilePicker/FilePicker.js +1 -1
  116. package/lib/module/components/FileViewer/FileViewer.js +1 -1
  117. package/lib/module/components/FilterChipRow/FilterChipRow.js +1 -1
  118. package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
  119. package/lib/module/components/FormField/FormField.js +1 -1
  120. package/lib/module/components/IconBadge/IconBadge.js +1 -1
  121. package/lib/module/components/IconButton/IconButton.js +1 -1
  122. package/lib/module/components/InlineSelect/InlineSelect.js +1 -1
  123. package/lib/module/components/Input/Input.js +1 -1
  124. package/lib/module/components/ListItem/ListItem.js +1 -1
  125. package/lib/module/components/ListSection/ListSection.js +1 -1
  126. package/lib/module/components/Menu/Menu.js +1 -1
  127. package/lib/module/components/Menu/useContextMenu.js +1 -1
  128. package/lib/module/components/MessageBubble/MessageBubble.js +1 -1
  129. package/lib/module/components/Modal/Modal.js +1 -1
  130. package/lib/module/components/NumberInput/NumberInput.js +1 -1
  131. package/lib/module/components/OTPInput/OTPInput.js +1 -1
  132. package/lib/module/components/PermissionPrompt/PermissionPrompt.js +1 -1
  133. package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
  134. package/lib/module/components/PickerTrigger/PickerTrigger.js +1 -1
  135. package/lib/module/components/ProfileCompletion/ProfileCompletion.js +1 -1
  136. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  137. package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
  138. package/lib/module/components/ProgressRing/ProgressRing.js +1 -1
  139. package/lib/module/components/Radio/Radio.js +1 -1
  140. package/lib/module/components/Rating/Rating.js +1 -1
  141. package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
  142. package/lib/module/components/SearchBar/SearchBar.js +1 -1
  143. package/lib/module/components/SectionHeader/SectionHeader.js +1 -1
  144. package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
  145. package/lib/module/components/Select/Select.js +1 -1
  146. package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
  147. package/lib/module/components/Skeleton/Skeleton.js +1 -1
  148. package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
  149. package/lib/module/components/SlideToConfirm/SlideToConfirm.js +1 -1
  150. package/lib/module/components/Slider/Slider.js +1 -1
  151. package/lib/module/components/SliderField/SliderField.js +1 -1
  152. package/lib/module/components/Sparkline/Sparkline.js +1 -1
  153. package/lib/module/components/Spinner/Spinner.js +1 -1
  154. package/lib/module/components/StatTile/StatTile.js +1 -1
  155. package/lib/module/components/StatusBadge/StatusBadge.js +1 -1
  156. package/lib/module/components/Stepper/Stepper.js +1 -1
  157. package/lib/module/components/Swipeable/Swipeable.js +1 -1
  158. package/lib/module/components/Switch/Switch.js +1 -1
  159. package/lib/module/components/Tabs/Tabs.js +1 -1
  160. package/lib/module/components/TagInput/TagInput.js +1 -1
  161. package/lib/module/components/Text/Text.js +1 -1
  162. package/lib/module/components/TimePicker/TimePicker.js +1 -1
  163. package/lib/module/components/Timeline/Timeline.js +1 -1
  164. package/lib/module/components/Toast/Toast.js +1 -1
  165. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  166. package/lib/module/components/WheelPicker/WheelPicker.js +1 -1
  167. package/lib/module/utils/assertValidValue.js +1 -0
  168. package/lib/typescript/commonjs/utils/assertValidValue.d.ts +10 -0
  169. package/lib/typescript/module/utils/assertValidValue.d.ts +10 -0
  170. package/package.json +7 -7
  171. package/lib/commonjs/utils/warnInvalidValue.js +0 -1
  172. package/lib/module/utils/warnInvalidValue.js +0 -1
  173. package/lib/typescript/commonjs/utils/warnInvalidValue.d.ts +0 -10
  174. package/lib/typescript/module/utils/warnInvalidValue.d.ts +0 -10
@@ -1 +1 @@
1
- "use strict";import{Children,isValidElement}from"react";import{makeStyles}from"../../theme/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Card}from"../Card/index.js";import{Divider}from"../Divider/index.js";import{SectionHeader}from"../SectionHeader/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const useStyles=makeStyles(e=>({label:{marginTop:e.space.xl,marginBottom:e.space.sm},footer:{marginTop:e.space.sm,paddingHorizontal:e.space.md}}));export const ListSection=e=>{const{title:t,action:i,footer:r,variant:a="outline",testID:n,children:s}=e;warnInvalidValue("ListSection","variant",e.variant,["elevated","outline","filled","flat"]);const o=useStyles(),l=Children.toArray(s).filter(isValidElement).flatMap((e,t)=>0===t?[e]:[_jsx(Divider,{},`divider-${e.key}`),e]);return _jsxs(_Fragment,{children:[t?_jsx(SectionHeader,{variant:"caps",action:i,style:o.label,children:t}):null,_jsx(Card,{variant:a,padding:"none",testID:n,children:l}),r?_jsx(Text,{variant:"caption",color:"secondary",style:o.footer,children:r}):null]})};export default ListSection;
1
+ "use strict";import{Children,isValidElement}from"react";import{makeStyles}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Card}from"../Card/index.js";import{Divider}from"../Divider/index.js";import{SectionHeader}from"../SectionHeader/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const useStyles=makeStyles(e=>({label:{marginTop:e.space.xl,marginBottom:e.space.sm},footer:{marginTop:e.space.sm,paddingHorizontal:e.space.md}}));export const ListSection=e=>{const{title:t,action:i,footer:r,variant:a="outline",testID:s,children:n}=e;assertValidValue("ListSection","variant",e.variant,["elevated","outline","filled","flat"]);const o=useStyles(),l=Children.toArray(n).filter(isValidElement).flatMap((e,t)=>0===t?[e]:[_jsx(Divider,{},`divider-${e.key}`),e]);return _jsxs(_Fragment,{children:[t?_jsx(SectionHeader,{variant:"caps",action:i,style:o.label,children:t}):null,_jsx(Card,{variant:a,padding:"none",testID:s,children:l}),r?_jsx(Text,{variant:"caption",color:"secondary",style:o.footer,children:r}):null]})};export default ListSection;
@@ -1 +1 @@
1
- "use strict";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{MenuSurface}from"./MenuSurface.js";import{DEFAULT_MENU_LABELS}from"./menuModel.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const Menu=e=>{const{items:t,trigger:a,title:s,topActions:n,placement:l="bottom",presentation:o="auto",unavailable:r="disable",open:u,onOpenChange:i,haptic:c,accessibilityLabel:m,labels:p,testID:f}=e;warnInvalidValue("Menu","placement",e.placement,["top","bottom","auto"]),warnInvalidValue("Menu","presentation",e.presentation,["auto","popover","sheet"]),warnInvalidValue("Menu","unavailable",e.unavailable,["disable","hide"]);const b=useMemo(()=>({...DEFAULT_MENU_LABELS,...p}),[p]),[d,M]=useControllableState({value:u,defaultValue:!1,onChange:i}),[h,j]=useState(null),[v,x]=useState(d),g=useRef(null),S=useRef(null);useEffect(()=>{d?(x(!0),g.current?.measureInWindow((e,t,a,s)=>{j({x:e,y:t,width:a,height:s})})):j(null)},[d]);const _=useCallback(()=>M(!1),[M]),w=useCallback(()=>S.current??g.current,[]),C=a.props,E=C.ref,I={ref:useMemo(()=>mergeRefs(E,S),[E]),"aria-expanded":d,onPress:e=>{C.onPress?.(e),M(!0)}};return _jsxs(_Fragment,{children:[_jsx(View,{ref:g,collapsable:!1,testID:f,children:React.cloneElement(a,I)}),v?_jsx(MenuSurface,{open:d,anchor:h,items:t,title:s,topActions:n,placement:l,presentation:o,unavailable:r,onClose:_,restoreFocusTo:w,haptic:c,accessibilityLabel:m,labels:b,testID:f}):null]})};export{Menu};export default Menu;
1
+ "use strict";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{MenuSurface}from"./MenuSurface.js";import{DEFAULT_MENU_LABELS}from"./menuModel.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const Menu=e=>{const{items:t,trigger:a,title:s,topActions:l,placement:o="bottom",presentation:r="auto",unavailable:n="disable",open:u,onOpenChange:i,haptic:c,accessibilityLabel:m,labels:p,testID:f}=e;assertValidValue("Menu","placement",e.placement,["top","bottom","auto"]),assertValidValue("Menu","presentation",e.presentation,["auto","popover","sheet"]),assertValidValue("Menu","unavailable",e.unavailable,["disable","hide"]);const b=useMemo(()=>({...DEFAULT_MENU_LABELS,...p}),[p]),[d,M]=useControllableState({value:u,defaultValue:!1,onChange:i}),[h,j]=useState(null),[V,x]=useState(d),g=useRef(null),S=useRef(null);useEffect(()=>{d?(x(!0),g.current?.measureInWindow((e,t,a,s)=>{j({x:e,y:t,width:a,height:s})})):j(null)},[d]);const _=useCallback(()=>M(!1),[M]),C=useCallback(()=>S.current??g.current,[]),E=a.props,L=E.ref,R={ref:useMemo(()=>mergeRefs(L,S),[L]),"aria-expanded":d,onPress:e=>{E.onPress?.(e),M(!0)}};return _jsxs(_Fragment,{children:[_jsx(View,{ref:g,collapsable:!1,testID:f,children:React.cloneElement(a,R)}),V?_jsx(MenuSurface,{open:d,anchor:h,items:t,title:s,topActions:l,placement:o,presentation:r,unavailable:n,onClose:_,restoreFocusTo:C,haptic:c,accessibilityLabel:m,labels:b,testID:f}):null]})};export{Menu};export default Menu;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{MenuSurface}from"./MenuSurface.js";import{DEFAULT_MENU_LABELS,menuActions,visibleGroups,visibleTopActions}from"./menuModel.js";import{webOnly}from"./webOnly.js";import{jsx as _jsx}from"react/jsx-runtime";export const useContextMenu=(e,t={})=>{const n=useRef(null),[s,i]=useState(!1),[o,a]=useState(!1),[l,r]=useState(null);warnInvalidValue("ContextMenu","unavailable",e?.unavailable,["hide","disable"]),warnInvalidValue("ContextMenu","presentation",e?.presentation,["auto","popover","sheet"]),warnInvalidValue("ContextMenu","placement",e?.placement,["top","bottom","auto"]);const c=e?.unavailable??"hide",u=e?.items,p=e?.topActions,m=useMemo(()=>u?visibleGroups(u,c):[],[u,c]),b=useMemo(()=>visibleTopActions(p,c),[p,c]),v=useMemo(()=>menuActions(m,b),[m,b]),f=m.length>0||b.length>0,d=useRef(e);d.current=e;const h=useRef(t);h.current=t;const A=useRef(v);A.current=v;const M=useCallback(e=>{e&&a(!0),i(e),d.current?.onOpenChange?.(e)},[]);useEffect(()=>{!f&&s&&M(!1)},[f,s,M]);const C=useCallback(()=>{n.current?.measureInWindow((e,t,n,s)=>{r({x:e,y:t,width:n,height:s}),M(!0)})},[M]),w=useCallback(()=>{const e=resolveHaptic(h.current.haptic,"longPress");e&&triggerHaptic(e),C()},[C]),x=useCallback(e=>{const t=A.current.find(t=>t.name===e.nativeEvent.actionName);if(!t)return void h.current.onAccessibilityAction?.(e);const n=resolveHaptic(h.current.haptic,"selection");n&&triggerHaptic(n),t.item.onPress?.()},[]),g=t.accessibilityActions,y=useMemo(()=>[...g??[],...v.map(e=>({name:e.name,label:e.label}))],[g,v]),S=useMemo(()=>f?{onLongPress:w,accessibilityActions:y,onAccessibilityAction:x,...webOnly({onContextMenu:e=>{e.preventDefault?.(),C()}})}:{},[f,w,y,x,C]),j=useCallback(()=>M(!1),[M]),E=useCallback(()=>n.current,[]);return{enabled:f,hostRef:n,hostProps:S,renderSurface:n=>e&&f&&o?_jsx(MenuSurface,{open:s,anchor:l,items:e.items,title:e.title,topActions:e.topActions,placement:e.placement??"bottom",presentation:e.presentation??"auto",unavailable:c,context:!0,preview:!1===e.preview?void 0:e.preview??n,onClose:j,restoreFocusTo:E,haptic:t.haptic,accessibilityLabel:e.accessibilityLabel,labels:{...DEFAULT_MENU_LABELS,...e.labels},testID:t.testID?`${t.testID}-context`:void 0}):null}};
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{MenuSurface}from"./MenuSurface.js";import{DEFAULT_MENU_LABELS,menuActions,visibleGroups,visibleTopActions}from"./menuModel.js";import{webOnly}from"./webOnly.js";import{jsx as _jsx}from"react/jsx-runtime";export const useContextMenu=(e,t={})=>{const s=useRef(null),[n,i]=useState(!1),[o,a]=useState(!1),[l,r]=useState(null);assertValidValue("ContextMenu","unavailable",e?.unavailable,["hide","disable"]),assertValidValue("ContextMenu","presentation",e?.presentation,["auto","popover","sheet"]),assertValidValue("ContextMenu","placement",e?.placement,["top","bottom","auto"]);const c=e?.unavailable??"hide",u=e?.items,p=e?.topActions,m=useMemo(()=>u?visibleGroups(u,c):[],[u,c]),b=useMemo(()=>visibleTopActions(p,c),[p,c]),f=useMemo(()=>menuActions(m,b),[m,b]),v=m.length>0||b.length>0,d=useRef(e);d.current=e;const h=useRef(t);h.current=t;const A=useRef(f);A.current=f;const M=useCallback(e=>{e&&a(!0),i(e),d.current?.onOpenChange?.(e)},[]);useEffect(()=>{!v&&n&&M(!1)},[v,n,M]);const C=useCallback(()=>{s.current?.measureInWindow((e,t,s,n)=>{r({x:e,y:t,width:s,height:n}),M(!0)})},[M]),x=useCallback(()=>{const e=resolveHaptic(h.current.haptic,"longPress");e&&triggerHaptic(e),C()},[C]),g=useCallback(e=>{const t=A.current.find(t=>t.name===e.nativeEvent.actionName);if(!t)return void h.current.onAccessibilityAction?.(e);const s=resolveHaptic(h.current.haptic,"selection");s&&triggerHaptic(s),t.item.onPress?.()},[]),y=t.accessibilityActions,S=useMemo(()=>[...y??[],...f.map(e=>({name:e.name,label:e.label}))],[y,f]),V=useMemo(()=>v?{onLongPress:x,accessibilityActions:S,onAccessibilityAction:g,...webOnly({onContextMenu:e=>{e.preventDefault?.(),C()}})}:{},[v,x,S,g,C]),j=useCallback(()=>M(!1),[M]),E=useCallback(()=>s.current,[]);return{enabled:v,hostRef:s,hostProps:V,renderSurface:s=>e&&v&&o?_jsx(MenuSurface,{open:n,anchor:l,items:e.items,title:e.title,topActions:e.topActions,placement:e.placement??"bottom",presentation:e.presentation??"auto",unavailable:c,context:!0,preview:!1===e.preview?void 0:e.preview??s,onClose:j,restoreFocusTo:E,haptic:t.haptic,accessibilityLabel:e.accessibilityLabel,labels:{...DEFAULT_MENU_LABELS,...e.labels},testID:t.testID?`${t.testID}-context`:void 0}):null}};
@@ -1 +1 @@
1
- "use strict";import{markdownToPlainText}from"@webority/markdown-core";import{formatTime}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{Markdown}from"../Markdown/index.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MESSAGE_BUBBLE_LABELS=Object.freeze({you:"You",sending:"Sending",sent:"Sent",delivered:"Delivered",read:"Read",failed:"Not sent",retry:"Try again",copy:"Copy",replyTo:e=>e?`Reply to ${e}`:"Reply"});const MAX_WIDTH="85%",STATUS_ICON=14,statusIcon=e=>{switch(e){case"sending":return"clock";case"sent":return"check";case"failed":return"alert-circle";default:return"check-check"}},statusColour=(e,s)=>{switch(s){case"read":return e.colors["info-text"];case"failed":return e.colors["danger-text"];default:return e.colors["text-subtle"]}};export const MessageBubble=({side:e,text:s,children:t,markdown:o,groupPosition:r="single",author:n,time:i,status:a,replyTo:l,streaming:c=!1,error:u,onRetry:d,actions:m,onCopy:b,onLongPress:p,footer:x,labels:y,haptic:f,style:h,testID:g})=>{warnInvalidValue("MessageBubble","side",e,["mine","theirs"]),warnInvalidValue("MessageBubble","groupPosition",r,["single","first","middle","last"]),warnInvalidValue("MessageBubble","status",a,["sending","sent","delivered","read","failed"]);const T=useTheme(),j=useMemo(()=>buildStyles(T),[T]),L=y?{...DEFAULT_MESSAGE_BUBBLE_LABELS,...y}:DEFAULT_MESSAGE_BUBBLE_LABELS,_="mine"===e,B=!u&&(o??"theirs"===e),P="single"===r||"first"===r,S="single"===r||"last"===r,M=null==i?"":formatTime(i),v=("failed"===a||Boolean(u))&&Boolean(d),w=_?L.you:n??"",I=useMemo(()=>{const e=[];return b&&!m?.some(e=>"copy"===e.name)&&e.push({name:"copy",label:L.copy,onPress:()=>b(s)}),m&&e.push(...m),l?.onPress&&e.push({name:"openReply",label:L.replyTo(l.author),onPress:l.onPress}),v&&d&&e.push({name:"retry",label:L.retry,onPress:d}),e},[m,b,s,l,v,d,L]),E=(m?.length??0)>0||Boolean(b),A=useMemo(()=>E?{items:I.map(({name:e,label:s,onPress:t})=>({key:e,label:s,onPress:t}))}:void 0,[E,I]),k=useContextMenu(A,{haptic:f,testID:g}),C=k.hostProps.onLongPress,R=!t||(m?.length??0)>0,D=a&&_?L[a]:"",$=useMemo(()=>B&&null==t?markdownToPlainText(s):s,[B,t,s]),V=[w,M,$,l?`${L.replyTo(l.author)}: ${l.text}`:"",D].filter(Boolean).join(", "),U=useRef(c);useEffect(()=>{U.current&&!c&&!u&&s&&announce(w?`${w}, ${$}`:$),U.current=c},[c,u,s,$,w]);const z=useRef(u);useEffect(()=>{u&&u!==z.current&&announce(u,{polite:!1}),z.current=u},[u]);const H=useCallback(e=>{C?.(e),p?.()},[C,p]),F=useCallback(e=>{I.find(s=>s.name===e.nativeEvent.actionName)?.onPress()},[I]),O=T.radius.xl,G=T.radius.sm,N=_?{borderTopRightRadius:P?O:G,borderBottomRightRadius:S?O:G}:{borderTopLeftRadius:P?O:G,borderBottomLeftRadius:S?O:G},W=t??(B?_jsx(Markdown,{children:s}):_jsx(Text,{variant:"body",children:s})),q=l?_jsxs(Pressable,{onPress:l.onPress,disabled:!l.onPress,accessibilityRole:l.onPress?"button":void 0,accessibilityLabel:`${L.replyTo(l.author)}: ${l.text}`,style:j.quote,children:[l.author?_jsx(Text,{variant:"caption",weight:"semibold",color:"link",numberOfLines:1,children:l.author}):null,_jsx(Text,{variant:"bodySmall",color:"secondary",numberOfLines:2,children:l.text})]}):null,X=[j.bubble,_?j.mine:j.theirs,N],Y=R?{accessible:!0,accessibilityLabel:V,accessibilityState:{busy:c},"aria-busy":c,accessibilityActions:I.map(({name:e,label:s})=>({name:e,label:s})),onAccessibilityAction:F}:{accessible:!1},J=E?_jsxs(Pressable,{ref:k.hostRef,...k.hostProps,onLongPress:H,delayLongPress:350,style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[q,W]}):_jsxs(View,{style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[q,W]}),K=S&&(""!==M||_&&a);return _jsxs(View,{style:[j.root,_?j.rootMine:j.rootTheirs,{marginTop:P?T.space.sm:T.space.xxs},h],accessibilityState:{busy:c},"aria-busy":c,testID:g,children:[!_&&P&&n?_jsx(Text,{variant:"caption",color:"secondary",style:j.author,numberOfLines:1,importantForAccessibility:R?"no-hide-descendants":"auto",accessibilityElementsHidden:R,children:n}):null,J,k.renderSurface(),K?_jsxs(View,{style:[j.meta,_?j.metaMine:null],importantForAccessibility:R?"no-hide-descendants":"auto",accessibilityElementsHidden:R,children:[M?_jsx(Text,{variant:"caption",color:"tertiary",children:M}):null,_&&a?_jsx(AppIcon,{name:statusIcon(a),size:14,color:statusColour(T,a),accessibilityLabel:L[a],testID:g?`${g}-status-${a}`:void 0}):null]}):null,u?_jsx(Text,{variant:"bodySmall",color:"danger",style:_?j.endText:null,children:u}):null,v?_jsx(Button,{label:L.retry,variant:"link",size:"sm",leftIcon:"refresh-cw",onPress:d,testID:g?`${g}-retry`:void 0}):null,x]})};const buildStyles=e=>StyleSheet.create({root:{maxWidth:"85%",gap:e.space.xs},rootMine:{alignSelf:"flex-end",alignItems:"flex-end"},rootTheirs:{alignSelf:"flex-start",alignItems:"flex-start"},author:{paddingHorizontal:e.space.md},bubble:{borderRadius:e.radius.xl,...smoothCorners,paddingHorizontal:e.space.md,paddingVertical:e.space.sm,gap:e.space.xs},mine:{backgroundColor:e.colors["primary-soft"]},theirs:{backgroundColor:e.colors["bg-subtle"]},quote:{borderLeftWidth:3,borderLeftColor:e.colors.primary,paddingLeft:e.space.sm,paddingVertical:e.space.xs},meta:{flexDirection:"row",alignItems:"center",gap:e.space.xs,paddingHorizontal:e.space.xs},metaMine:{justifyContent:"flex-end"},endText:{textAlign:"right"}});export default MessageBubble;
1
+ "use strict";import{markdownToPlainText}from"@webority/markdown-core";import{formatTime}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{Markdown}from"../Markdown/index.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MESSAGE_BUBBLE_LABELS=Object.freeze({you:"You",sending:"Sending",sent:"Sent",delivered:"Delivered",read:"Read",failed:"Not sent",retry:"Try again",copy:"Copy",replyTo:e=>e?`Reply to ${e}`:"Reply"});const MAX_WIDTH="85%",STATUS_ICON=14,statusIcon=e=>{switch(e){case"sending":return"clock";case"sent":return"check";case"failed":return"alert-circle";default:return"check-check"}},statusColour=(e,s)=>{switch(s){case"read":return e.colors["info-text"];case"failed":return e.colors["danger-text"];default:return e.colors["text-subtle"]}};export const MessageBubble=({side:e,text:s,children:t,markdown:o,groupPosition:r="single",author:n,time:i,status:a,replyTo:l,streaming:c=!1,error:u,onRetry:d,actions:m,onCopy:b,onLongPress:p,footer:x,labels:y,haptic:f,style:h,testID:g})=>{assertValidValue("MessageBubble","side",e,["mine","theirs"]),assertValidValue("MessageBubble","groupPosition",r,["single","first","middle","last"]),assertValidValue("MessageBubble","status",a,["sending","sent","delivered","read","failed"]);const T=useTheme(),j=useMemo(()=>buildStyles(T),[T]),L=y?{...DEFAULT_MESSAGE_BUBBLE_LABELS,...y}:DEFAULT_MESSAGE_BUBBLE_LABELS,_="mine"===e,B=!u&&(o??"theirs"===e),P="single"===r||"first"===r,S="single"===r||"last"===r,M=null==i?"":formatTime(i),E=("failed"===a||Boolean(u))&&Boolean(d),A=_?L.you:n??"",k=useMemo(()=>{const e=[];return b&&!m?.some(e=>"copy"===e.name)&&e.push({name:"copy",label:L.copy,onPress:()=>b(s)}),m&&e.push(...m),l?.onPress&&e.push({name:"openReply",label:L.replyTo(l.author),onPress:l.onPress}),E&&d&&e.push({name:"retry",label:L.retry,onPress:d}),e},[m,b,s,l,E,d,L]),v=(m?.length??0)>0||Boolean(b),w=useMemo(()=>v?{items:k.map(({name:e,label:s,onPress:t})=>({key:e,label:s,onPress:t}))}:void 0,[v,k]),I=useContextMenu(w,{haptic:f,testID:g}),C=I.hostProps.onLongPress,R=!t||(m?.length??0)>0,V=a&&_?L[a]:"",D=useMemo(()=>B&&null==t?markdownToPlainText(s):s,[B,t,s]),$=[A,M,D,l?`${L.replyTo(l.author)}: ${l.text}`:"",V].filter(Boolean).join(", "),U=useRef(c);useEffect(()=>{U.current&&!c&&!u&&s&&announce(A?`${A}, ${D}`:D),U.current=c},[c,u,s,D,A]);const z=useRef(u);useEffect(()=>{u&&u!==z.current&&announce(u,{polite:!1}),z.current=u},[u]);const H=useCallback(e=>{C?.(e),p?.()},[C,p]),F=useCallback(e=>{k.find(s=>s.name===e.nativeEvent.actionName)?.onPress()},[k]),O=T.radius.xl,G=T.radius.sm,N=_?{borderTopRightRadius:P?O:G,borderBottomRightRadius:S?O:G}:{borderTopLeftRadius:P?O:G,borderBottomLeftRadius:S?O:G},W=t??(B?_jsx(Markdown,{children:s}):_jsx(Text,{variant:"body",children:s})),q=l?_jsxs(Pressable,{onPress:l.onPress,disabled:!l.onPress,accessibilityRole:l.onPress?"button":void 0,accessibilityLabel:`${L.replyTo(l.author)}: ${l.text}`,style:j.quote,children:[l.author?_jsx(Text,{variant:"caption",weight:"semibold",color:"link",numberOfLines:1,children:l.author}):null,_jsx(Text,{variant:"bodySmall",color:"secondary",numberOfLines:2,children:l.text})]}):null,X=[j.bubble,_?j.mine:j.theirs,N],Y=R?{accessible:!0,accessibilityLabel:$,accessibilityState:{busy:c},"aria-busy":c,accessibilityActions:k.map(({name:e,label:s})=>({name:e,label:s})),onAccessibilityAction:F}:{accessible:!1},J=v?_jsxs(Pressable,{ref:I.hostRef,...I.hostProps,onLongPress:H,delayLongPress:350,style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[q,W]}):_jsxs(View,{style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[q,W]}),K=S&&(""!==M||_&&a);return _jsxs(View,{style:[j.root,_?j.rootMine:j.rootTheirs,{marginTop:P?T.space.sm:T.space.xxs},h],accessibilityState:{busy:c},"aria-busy":c,testID:g,children:[!_&&P&&n?_jsx(Text,{variant:"caption",color:"secondary",style:j.author,numberOfLines:1,importantForAccessibility:R?"no-hide-descendants":"auto",accessibilityElementsHidden:R,children:n}):null,J,I.renderSurface(),K?_jsxs(View,{style:[j.meta,_?j.metaMine:null],importantForAccessibility:R?"no-hide-descendants":"auto",accessibilityElementsHidden:R,children:[M?_jsx(Text,{variant:"caption",color:"tertiary",children:M}):null,_&&a?_jsx(AppIcon,{name:statusIcon(a),size:14,color:statusColour(T,a),accessibilityLabel:L[a],testID:g?`${g}-status-${a}`:void 0}):null]}):null,u?_jsx(Text,{variant:"bodySmall",color:"danger",style:_?j.endText:null,children:u}):null,E?_jsx(Button,{label:L.retry,variant:"link",size:"sm",leftIcon:"refresh-cw",onPress:d,testID:g?`${g}-retry`:void 0}):null,x]})};const buildStyles=e=>StyleSheet.create({root:{maxWidth:"85%",gap:e.space.xs},rootMine:{alignSelf:"flex-end",alignItems:"flex-end"},rootTheirs:{alignSelf:"flex-start",alignItems:"flex-start"},author:{paddingHorizontal:e.space.md},bubble:{borderRadius:e.radius.xl,...smoothCorners,paddingHorizontal:e.space.md,paddingVertical:e.space.sm,gap:e.space.xs},mine:{backgroundColor:e.colors["primary-soft"]},theirs:{backgroundColor:e.colors["bg-subtle"]},quote:{borderLeftWidth:3,borderLeftColor:e.colors.primary,paddingLeft:e.space.sm,paddingVertical:e.space.xs},meta:{flexDirection:"row",alignItems:"center",gap:e.space.xs,paddingHorizontal:e.space.xs},metaMine:{justifyContent:"flex-end"},endText:{textAlign:"right"}});export default MessageBubble;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Dimensions,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MODAL_LABELS=Object.freeze({close:"Close modal"});const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9,Modal=forwardRef((e,t)=>{warnInvalidValue("Modal","presentation",e.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:s="centered",backdropOpacity:n,backdropPressClose:i=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:S,placement:A="auto",align:y="center",testID:v,bare:x=!1,onInsetsChange:M}=e,w=useTheme(),C=useMemo(()=>({...DEFAULT_MODAL_LABELS,...b}),[b]),R=usePresenceMotion(),[V,j]=useModalInsets();useEffect(()=>{M?.(V)},[V,M]);const{width:E,height:T}=useWindowDimensions(),[D,_]=useState({width:0,height:0}),L=a??R.duration("default"),I=Dimensions.get("window").height,N=useRef(!l&&o),H=N.current,P=useRef(createAnimatedValue(H?1:.9)).current,k=useRef(createAnimatedValue(H?1:0)).current,O=useRef(createAnimatedValue(H?0:I)).current,z=useRef(createAnimatedValue(H?1:0)).current,W=useRef(null),q=useRef(!1),[F,B]=useState(o),U=useMemo(()=>buildStyles(w),[w]),K=useMemo(()=>{if("anchored"!==s||void 0===S)return null;const e={width:E,height:T,insets:{top:V.top,bottom:V.bottom,left:0,right:0}},t=computePlacement(S,D,e,A,{align:y});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(S,e))}},[s,S,D,A,y,E,T,V.top,V.bottom]),G=useMemo(()=>{const e=w.colors.scrim;return"number"!=typeof n?"anchored"===s?transparentOf(e):e:withAlpha(e,n)??e},[w.colors.scrim,n,s]),Y=useMemo(()=>z.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[z,G]);useEffect(()=>{o&&(Keyboard.dismiss(),B(!0))},[o]),useEffect(()=>{const e=[];if(o&&F&&N.current)N.current=!1;else if(o&&F){const t=Animated.timing(z,{toValue:1,duration:R.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),R.reduced||"anchored"===s){k.setValue(0),O.setValue(0),P.setValue(1);const t=Animated.timing(k,{toValue:1,duration:L,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===s){k.setValue(1);const t=Animated.spring(O,{toValue:0,damping:w.motion.spring.gentle.damping,stiffness:w.motion.spring.gentle.stiffness,mass:w.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(P,{toValue:1,damping:w.motion.spring.gentle.damping,stiffness:w.motion.spring.gentle.stiffness,mass:w.motion.spring.gentle.mass,useNativeDriver:!0}),Animated.timing(k,{toValue:1,duration:L,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(F){const t=R.duration("fast"),o=Easing.bezier(...w.motion.ease.accelerate),r=Animated.timing(k,{toValue:0,duration:t,easing:o,useNativeDriver:!0}),n=R.reduced||"anchored"===s?r:"bottom"===s?Animated.timing(O,{toValue:I,duration:t,easing:o,useNativeDriver:!0}):Animated.parallel([Animated.timing(P,{toValue:.9,duration:t,easing:o,useNativeDriver:!0}),r]),i=Animated.parallel([n,Animated.timing(z,{toValue:0,duration:R.duration("default"),useNativeDriver:!1})]);i.start(({finished:e})=>{e&&(O.setValue(I),B(!1))}),e.push(i)}return()=>e.forEach(e=>{e.stop()})},[o,F,s,L,P,k,z,O,I,w.motion.spring.gentle.damping,w.motion.spring.gentle.stiffness,w.motion.spring.gentle.mass,R,w.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{W.current&&AccessibilityInfo.sendAccessibilityEvent(W.current,"focus")},150),q.current=!0):q.current&&(q.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},L))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,L,f]);const J=useRef(h);J.current=h;const Q=useRef(!1);useEffect(()=>{if(o)return void(Q.current=!0);if(!Q.current)return;Q.current=!1;const e=setTimeout(()=>J.current?.(),300);return()=>clearTimeout(e)},[o]);const X=useCallback(()=>{if(!i)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[i,r,g]),Z=useCallback(()=>{u&&r()},[u,r]),$=useSquircle(!x&&"bottom"!==s&&"fullScreen"!==s&&"anchored"!==s,w.radius.xl),ee=useCallback(e=>{$.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;_(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[$.onLayout]),te=useMemo(()=>x?"bottom"===s?U.bottomContent:"fullScreen"===s?U.fullScreenContent:U.bareCentredContent:"anchored"===s?[U.anchoredContent,{left:K?.x,top:K?.y,maxHeight:K?.maxHeight,backgroundColor:w.colors.surface,borderRadius:w.radius.lg,...smoothCorners},w.shadow.modal]:"fullScreen"===s?[U.fullScreenContent,{backgroundColor:w.colors.surface}]:"bottom"===s?[U.bottomContent,{backgroundColor:w.colors.surface,borderTopLeftRadius:w.radius.xl,borderTopRightRadius:w.radius.xl,...smoothCorners,paddingTop:w.space.lg,paddingHorizontal:w.space.lg,paddingBottom:w.space.lg+V.bottom},w.shadow.modal]:[U.centeredContent,{backgroundColor:w.colors.surface,borderRadius:$.active&&$.size?squircleHostRadius($.size.width,$.size.height,w.radius.xl):w.radius.xl,...smoothCorners,padding:w.space.xl},w.shadow.modal],[s,w,U,V.bottom,$.active,$.size,K,x]),oe=useMemo(()=>"anchored"===s?U.anchoredWrapper:"bottom"===s?U.bottomWrapper:"fullScreen"===s?U.fullScreenWrapper:U.centeredWrapper,[s,U]),re=useMemo(()=>"bottom"===s?{opacity:k,transform:[{translateY:O}]}:"fullScreen"===s||"anchored"===s?{opacity:k}:{opacity:k,transform:[{scale:P}]},[s,P,k,O]);if("anchored"===s&&void 0===S)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(x&&"anchored"===s)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return _jsx(RNModal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:v,children:_jsx(View,{ref:e=>{W.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:U.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:j,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,oe,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:X,accessibilityRole:i?"button":void 0,accessibilityLabel:i?C.close:void 0,accessible:!!i&&void 0,importantForAccessibility:i?void 0:"no",disabled:!i}),_jsxs(Animated.View,{style:[te,re,D.height>0||"anchored"!==s?null:U.unmeasured,m],onLayout:ee,pointerEvents:x&&"fullScreen"===s?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[$.active&&$.size?_jsx(SquircleFill,{width:$.size.width,height:$.size.height,radius:w.radius.xl,fill:w.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});export{Modal};export default Modal;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Dimensions,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MODAL_LABELS=Object.freeze({close:"Close modal"});const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9,Modal=forwardRef((e,t)=>{assertValidValue("Modal","presentation",e.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:s="centered",backdropOpacity:n,backdropPressClose:i=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:S,placement:A="auto",align:y="center",testID:x,bare:M=!1,onInsetsChange:v}=e,C=useTheme(),w=useMemo(()=>({...DEFAULT_MODAL_LABELS,...b}),[b]),R=usePresenceMotion(),[V,j]=useModalInsets();useEffect(()=>{v?.(V)},[V,v]);const{width:E,height:T}=useWindowDimensions(),[D,_]=useState({width:0,height:0}),L=a??R.duration("default"),N=Dimensions.get("window").height,H=useRef(!l&&o),I=H.current,P=useRef(createAnimatedValue(I?1:.9)).current,k=useRef(createAnimatedValue(I?1:0)).current,O=useRef(createAnimatedValue(I?0:N)).current,z=useRef(createAnimatedValue(I?1:0)).current,W=useRef(null),q=useRef(!1),[F,B]=useState(o),U=useMemo(()=>buildStyles(C),[C]),K=useMemo(()=>{if("anchored"!==s||void 0===S)return null;const e={width:E,height:T,insets:{top:V.top,bottom:V.bottom,left:0,right:0}},t=computePlacement(S,D,e,A,{align:y});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(S,e))}},[s,S,D,A,y,E,T,V.top,V.bottom]),G=useMemo(()=>{const e=C.colors.scrim;return"number"!=typeof n?"anchored"===s?transparentOf(e):e:withAlpha(e,n)??e},[C.colors.scrim,n,s]),Y=useMemo(()=>z.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[z,G]);useEffect(()=>{o&&(Keyboard.dismiss(),B(!0))},[o]),useEffect(()=>{const e=[];if(o&&F&&H.current)H.current=!1;else if(o&&F){const t=Animated.timing(z,{toValue:1,duration:R.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),R.reduced||"anchored"===s){k.setValue(0),O.setValue(0),P.setValue(1);const t=Animated.timing(k,{toValue:1,duration:L,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===s){k.setValue(1);const t=Animated.spring(O,{toValue:0,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(P,{toValue:1,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:!0}),Animated.timing(k,{toValue:1,duration:L,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(F){const t=R.duration("fast"),o=Easing.bezier(...C.motion.ease.accelerate),r=Animated.timing(k,{toValue:0,duration:t,easing:o,useNativeDriver:!0}),n=R.reduced||"anchored"===s?r:"bottom"===s?Animated.timing(O,{toValue:N,duration:t,easing:o,useNativeDriver:!0}):Animated.parallel([Animated.timing(P,{toValue:.9,duration:t,easing:o,useNativeDriver:!0}),r]),i=Animated.parallel([n,Animated.timing(z,{toValue:0,duration:R.duration("default"),useNativeDriver:!1})]);i.start(({finished:e})=>{e&&(O.setValue(N),B(!1))}),e.push(i)}return()=>e.forEach(e=>{e.stop()})},[o,F,s,L,P,k,z,O,N,C.motion.spring.gentle.damping,C.motion.spring.gentle.stiffness,C.motion.spring.gentle.mass,R,C.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{W.current&&AccessibilityInfo.sendAccessibilityEvent(W.current,"focus")},150),q.current=!0):q.current&&(q.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},L))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,L,f]);const J=useRef(h);J.current=h;const Q=useRef(!1);useEffect(()=>{if(o)return void(Q.current=!0);if(!Q.current)return;Q.current=!1;const e=setTimeout(()=>J.current?.(),300);return()=>clearTimeout(e)},[o]);const X=useCallback(()=>{if(!i)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[i,r,g]),Z=useCallback(()=>{u&&r()},[u,r]),$=useSquircle(!M&&"bottom"!==s&&"fullScreen"!==s&&"anchored"!==s,C.radius.xl),ee=useCallback(e=>{$.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;_(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[$.onLayout]),te=useMemo(()=>M?"bottom"===s?U.bottomContent:"fullScreen"===s?U.fullScreenContent:U.bareCentredContent:"anchored"===s?[U.anchoredContent,{left:K?.x,top:K?.y,maxHeight:K?.maxHeight,backgroundColor:C.colors.surface,borderRadius:C.radius.lg,...smoothCorners},C.shadow.modal]:"fullScreen"===s?[U.fullScreenContent,{backgroundColor:C.colors.surface}]:"bottom"===s?[U.bottomContent,{backgroundColor:C.colors.surface,borderTopLeftRadius:C.radius.xl,borderTopRightRadius:C.radius.xl,...smoothCorners,paddingTop:C.space.lg,paddingHorizontal:C.space.lg,paddingBottom:C.space.lg+V.bottom},C.shadow.modal]:[U.centeredContent,{backgroundColor:C.colors.surface,borderRadius:$.active&&$.size?squircleHostRadius($.size.width,$.size.height,C.radius.xl):C.radius.xl,...smoothCorners,padding:C.space.xl},C.shadow.modal],[s,C,U,V.bottom,$.active,$.size,K,M]),oe=useMemo(()=>"anchored"===s?U.anchoredWrapper:"bottom"===s?U.bottomWrapper:"fullScreen"===s?U.fullScreenWrapper:U.centeredWrapper,[s,U]),re=useMemo(()=>"bottom"===s?{opacity:k,transform:[{translateY:O}]}:"fullScreen"===s||"anchored"===s?{opacity:k}:{opacity:k,transform:[{scale:P}]},[s,P,k,O]);if("anchored"===s&&void 0===S)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(M&&"anchored"===s)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return _jsx(RNModal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:x,children:_jsx(View,{ref:e=>{W.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:U.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:j,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,oe,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:X,accessibilityRole:i?"button":void 0,accessibilityLabel:i?w.close:void 0,accessible:!!i&&void 0,importantForAccessibility:i?void 0:"no",disabled:!i}),_jsxs(Animated.View,{style:[te,re,D.height>0||"anchored"!==s?null:U.unmeasured,m],onLayout:ee,pointerEvents:M&&"fullScreen"===s?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[$.active&&$.size?_jsx(SquircleFill,{width:$.size.width,height:$.size.height,radius:C.radius.xl,fill:C.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});export{Modal};export default Modal;
@@ -1 +1 @@
1
- "use strict";import React,{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"];export const DEFAULT_NUMBER_INPUT_LABELS=Object.freeze({decrease:"Decrease",increase:"Increase",input:"Number input"});const DEFAULT_LONG_PRESS_DELAY=500,DEFAULT_LONG_PRESS_INTERVAL=80,roundToPrecision=(e,t)=>{if(!Number.isFinite(e))return 0;if(t<=0)return Math.round(e);const i=10**t;return Math.round(e*i)/i},clamp=(e,t,i)=>e<t?t:e>i?i:e,formatValue=(e,t,i)=>Number.isFinite(e)?t&&i>0?e.toFixed(i):String(Math.trunc(e)):"",sanitizeTyped=(e,t)=>{if(!e)return"";let i=e.replace(/[^0-9.-]/g,"");if(i=i.replace(/(?!^)-/g,""),t){const e=i.indexOf(".");-1!==e&&(i=i.slice(0,e+1)+i.slice(e+1).replace(/\./g,""))}else i=i.replace(/\./g,"");return i},NumberInput=forwardRef((e,t)=>{const{value:i,defaultValue:l,onChange:s,min:r=Number.NEGATIVE_INFINITY,max:n=Number.POSITIVE_INFINITY,step:a=1,allowDecimal:o=!1,precision:c=0,label:u,help:d,helperText:b,error:m,disabled:p=!1,size:f="md",variant:x="inline",unit:h,haptic:y,labels:S,accessibilityLabel:I,style:T,containerStyle:N,inputStyle:g,buttonStyle:_,unitStyle:F,labelStyle:j,textInputProps:v,testID:E}=e;warnInvalidValue("NumberInput","size",e.size,NUMBER_INPUT_SIZES),warnInvalidValue("NumberInput","variant",e.variant,NUMBER_INPUT_VARIANTS);const R=useMemo(()=>({...DEFAULT_NUMBER_INPUT_LABELS,...S}),[S]),[C,w]=useControllableState({value:i,defaultValue:l??e.min??0,onChange:s}),L=useTheme(),P=resolveFieldSize(L,f),V=resolveFieldTextStyle(L,{disabled:p}),z=useMemo(()=>buildStyles(L),[L]),A=useRef(null),[U,k]=useState(formatValue(C,o,c)),[B,M]=useState(!1),[D,H]=useState(!1),O=useCallback(()=>{p||A.current?.focus()},[p]),G=useRef(null),W=useRef(null),Y=useCallback(()=>{null!==G.current&&(clearTimeout(G.current),G.current=null),null!==W.current&&(clearInterval(W.current),W.current=null)},[]);useEffect(()=>Y,[Y]),useEffect(()=>{B||k(formatValue(C,o,c))},[C,o,c,B]);const Z=C<=r,$=C>=n,q=!p,J=useCallback(e=>{const t=roundToPrecision(e,o?c:0),i=clamp(t,r,n);i!==C&&w(i)},[o,n,r,w,c,C]),K=useCallback(()=>{if(!q||Z)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),J(C-a)},[Z,q,y,J,a,C]),Q=useCallback(()=>{if(!q||$)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),J(C+a)},[$,q,y,J,a,C]);React.useImperativeHandle(t,()=>({focus:()=>A.current?.focus(),blur:()=>A.current?.blur(),clear:()=>{k(""),Number.isFinite(r)&&r>0?w(r):w(0<r?r:0>n?n:0)}}),[n,r,w]);const X=useCallback(e=>{q&&(Y(),G.current=setTimeout(()=>{W.current=setInterval(()=>{"inc"===e?Q():K()},80)},500))},[Y,K,Q,q]),ee=useCallback(e=>{const t=sanitizeTyped(e,o);k(t);const i=Number(t);""!==t&&"-"!==t&&"."!==t&&Number.isFinite(i)&&i>=r&&i<=n&&i!==C&&w(roundToPrecision(i,o?c:0))},[o,n,r,w,c,C]),te=useCallback(()=>{M(!1),H(!1);const e=Number(U);if(""===U||!Number.isFinite(e))return void k(formatValue(C,o,c));const t=roundToPrecision(e,o?c:0),i=clamp(t,r,n);i!==C&&w(i),k(formatValue(i,o,c))},[o,U,n,r,w,c,C]),ie=useCallback(()=>{M(!0),H(!0)},[]),le=Z||p?L.colors["text-disabled"]:L.colors["text-body"],se=$||p?L.colors["text-disabled"]:L.colors["text-body"],re=P.icon+8,renderStepper=(e,t,i,l,s,r)=>_jsx(Pressable,{onPress:t,onLongPress:()=>X(e),onPressOut:Y,delayLongPress:500,disabled:i,accessibilityRole:"button",accessibilityLabel:l,accessibilityState:{disabled:i},"aria-disabled":i,style:({pressed:e})=>[{width:re,height:re,alignItems:"center",justifyContent:"center",borderRadius:L.radius.pill,...smoothCorners},e&&!i?{backgroundColor:L.colors["surface-pressed"]}:null,_],testID:`${E??"numberinput"}-${"inc"===e?"plus":"minus"}`,children:_jsx(Text,{variant:"body",weight:"semibold",style:{fontSize:P.icon,color:s,fontWeight:L.weight.semibold,lineHeight:P.icon+2},children:r})}),ne=I??fieldTextAsString(u)??R.input,ae=!0===m||hasFieldText(m),oe=_jsx(FieldBase,{size:f,disabled:p,error:ae,filled:!0,focused:D,onPress:O,pressFeedback:!1,leading:renderStepper("dec",K,Z||p,R.decrease,le,"−"),trailing:renderStepper("inc",Q,$||p,R.increase,se,"+"),children:_jsxs(View,{style:z.inputRow,children:[_jsx(TextInput,{ref:A,value:U,onChangeText:ee,onFocus:ie,onBlur:te,editable:!p,keyboardType:o?"decimal-pad":"number-pad",selectTextOnFocus:!0,accessibilityRole:"adjustable",accessibilityLabel:ne,accessibilityValue:{now:Number.isFinite(C)?C:0},accessibilityState:{disabled:p},"aria-disabled":p,accessibilityActions:[{name:"increment",label:R.increase},{name:"decrement",label:R.decrease}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName&&Q(),"decrement"===e.nativeEvent.actionName&&K()},style:[z.input,{fontSize:P.text,color:V.color,...V.weightStyle},g],...v}),h?_jsx(Text,{variant:"bodySmall",style:[z.unit,{fontSize:P.text,color:V.placeholderColor},F],children:h}):null]})}),ce=hasFieldText(u)?_jsx(FieldLabel,{size:f,help:d,style:j,children:u}):null,ue=_jsx(FieldMessage,{size:f,error:ae,text:ae?m:b});return _jsxs(View,"horizontal"===x?{style:[z.horizontalContainer,N,T],testID:E,accessibilityState:{disabled:p},"aria-disabled":p,children:[_jsx(View,{style:z.horizontalLabelWrap,children:ce}),_jsxs(View,{children:[oe,ue]})]}:{style:[N,T],testID:E,accessibilityState:{disabled:p},"aria-disabled":p,children:[ce,oe,ue]})});NumberInput.displayName="NumberInput";const buildStyles=e=>StyleSheet.create({inputRow:{flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center"},input:{flex:1,textAlign:"center",padding:e.space.none,margin:e.space.none,includeFontPadding:!1},unit:{marginLeft:e.space.xs},label:{marginBottom:e.space.xs},helper:{marginTop:e.space.xs},horizontalContainer:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},horizontalLabelWrap:{flexShrink:1,paddingRight:e.space.md}});export{NumberInput};export default NumberInput;
1
+ "use strict";import React,{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{resolveFieldSize,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{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"];export const DEFAULT_NUMBER_INPUT_LABELS=Object.freeze({decrease:"Decrease",increase:"Increase",input:"Number input"});const DEFAULT_LONG_PRESS_DELAY=500,DEFAULT_LONG_PRESS_INTERVAL=80,roundToPrecision=(e,t)=>{if(!Number.isFinite(e))return 0;if(t<=0)return Math.round(e);const i=10**t;return Math.round(e*i)/i},clamp=(e,t,i)=>e<t?t:e>i?i:e,formatValue=(e,t,i)=>Number.isFinite(e)?t&&i>0?e.toFixed(i):String(Math.trunc(e)):"",sanitizeTyped=(e,t)=>{if(!e)return"";let i=e.replace(/[^0-9.-]/g,"");if(i=i.replace(/(?!^)-/g,""),t){const e=i.indexOf(".");-1!==e&&(i=i.slice(0,e+1)+i.slice(e+1).replace(/\./g,""))}else i=i.replace(/\./g,"");return i},NumberInput=forwardRef((e,t)=>{const{value:i,defaultValue:s,onChange:l,min:r=Number.NEGATIVE_INFINITY,max:a=Number.POSITIVE_INFINITY,step:n=1,allowDecimal:o=!1,precision:c=0,label:u,help:d,helperText:b,error:m,disabled:p=!1,size:f="md",variant:x="inline",unit:h,haptic:y,labels:S,accessibilityLabel:T,style:N,containerStyle:g,inputStyle:I,buttonStyle:_,unitStyle:F,labelStyle:j,textInputProps:E,testID:V}=e;assertValidValue("NumberInput","size",e.size,NUMBER_INPUT_SIZES),assertValidValue("NumberInput","variant",e.variant,NUMBER_INPUT_VARIANTS);const R=useMemo(()=>({...DEFAULT_NUMBER_INPUT_LABELS,...S}),[S]),[v,C]=useControllableState({value:i,defaultValue:s??e.min??0,onChange:l}),L=useTheme(),P=resolveFieldSize(L,f),z=resolveFieldTextStyle(L,{disabled:p}),A=useMemo(()=>buildStyles(L),[L]),w=useRef(null),[U,k]=useState(formatValue(v,o,c)),[B,M]=useState(!1),[D,H]=useState(!1),O=useCallback(()=>{p||w.current?.focus()},[p]),G=useRef(null),W=useRef(null),Y=useCallback(()=>{null!==G.current&&(clearTimeout(G.current),G.current=null),null!==W.current&&(clearInterval(W.current),W.current=null)},[]);useEffect(()=>Y,[Y]),useEffect(()=>{B||k(formatValue(v,o,c))},[v,o,c,B]);const Z=v<=r,$=v>=a,q=!p,J=useCallback(e=>{const t=roundToPrecision(e,o?c:0),i=clamp(t,r,a);i!==v&&C(i)},[o,a,r,C,c,v]),K=useCallback(()=>{if(!q||Z)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),J(v-n)},[Z,q,y,J,n,v]),Q=useCallback(()=>{if(!q||$)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),J(v+n)},[$,q,y,J,n,v]);React.useImperativeHandle(t,()=>({focus:()=>w.current?.focus(),blur:()=>w.current?.blur(),clear:()=>{k(""),Number.isFinite(r)&&r>0?C(r):C(0<r?r:0>a?a:0)}}),[a,r,C]);const X=useCallback(e=>{q&&(Y(),G.current=setTimeout(()=>{W.current=setInterval(()=>{"inc"===e?Q():K()},80)},500))},[Y,K,Q,q]),ee=useCallback(e=>{const t=sanitizeTyped(e,o);k(t);const i=Number(t);""!==t&&"-"!==t&&"."!==t&&Number.isFinite(i)&&i>=r&&i<=a&&i!==v&&C(roundToPrecision(i,o?c:0))},[o,a,r,C,c,v]),te=useCallback(()=>{M(!1),H(!1);const e=Number(U);if(""===U||!Number.isFinite(e))return void k(formatValue(v,o,c));const t=roundToPrecision(e,o?c:0),i=clamp(t,r,a);i!==v&&C(i),k(formatValue(i,o,c))},[o,U,a,r,C,c,v]),ie=useCallback(()=>{M(!0),H(!0)},[]),se=Z||p?L.colors["text-disabled"]:L.colors["text-body"],le=$||p?L.colors["text-disabled"]:L.colors["text-body"],re=P.icon+8,renderStepper=(e,t,i,s,l,r)=>_jsx(Pressable,{onPress:t,onLongPress:()=>X(e),onPressOut:Y,delayLongPress:500,disabled:i,accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{disabled:i},"aria-disabled":i,style:({pressed:e})=>[{width:re,height:re,alignItems:"center",justifyContent:"center",borderRadius:L.radius.pill,...smoothCorners},e&&!i?{backgroundColor:L.colors["surface-pressed"]}:null,_],testID:`${V??"numberinput"}-${"inc"===e?"plus":"minus"}`,children:_jsx(Text,{variant:"body",weight:"semibold",style:{fontSize:P.icon,color:l,fontWeight:L.weight.semibold,lineHeight:P.icon+2},children:r})}),ae=T??fieldTextAsString(u)??R.input,ne=!0===m||hasFieldText(m),oe=_jsx(FieldBase,{size:f,disabled:p,error:ne,filled:!0,focused:D,onPress:O,pressFeedback:!1,leading:renderStepper("dec",K,Z||p,R.decrease,se,"−"),trailing:renderStepper("inc",Q,$||p,R.increase,le,"+"),children:_jsxs(View,{style:A.inputRow,children:[_jsx(TextInput,{ref:w,value:U,onChangeText:ee,onFocus:ie,onBlur:te,editable:!p,keyboardType:o?"decimal-pad":"number-pad",selectTextOnFocus:!0,accessibilityRole:"adjustable",accessibilityLabel:ae,accessibilityValue:{now:Number.isFinite(v)?v:0},accessibilityState:{disabled:p},"aria-disabled":p,accessibilityActions:[{name:"increment",label:R.increase},{name:"decrement",label:R.decrease}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName&&Q(),"decrement"===e.nativeEvent.actionName&&K()},style:[A.input,{fontSize:P.text,color:z.color,...z.weightStyle},I],...E}),h?_jsx(Text,{variant:"bodySmall",style:[A.unit,{fontSize:P.text,color:z.placeholderColor},F],children:h}):null]})}),ce=hasFieldText(u)?_jsx(FieldLabel,{size:f,help:d,style:j,children:u}):null,ue=_jsx(FieldMessage,{size:f,error:ne,text:ne?m:b});return _jsxs(View,"horizontal"===x?{style:[A.horizontalContainer,g,N],testID:V,accessibilityState:{disabled:p},"aria-disabled":p,children:[_jsx(View,{style:A.horizontalLabelWrap,children:ce}),_jsxs(View,{children:[oe,ue]})]}:{style:[g,N],testID:V,accessibilityState:{disabled:p},"aria-disabled":p,children:[ce,oe,ue]})});NumberInput.displayName="NumberInput";const buildStyles=e=>StyleSheet.create({inputRow:{flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center"},input:{flex:1,textAlign:"center",padding:e.space.none,margin:e.space.none,includeFontPadding:!1},unit:{marginLeft:e.space.xs},label:{marginBottom:e.space.xs},helper:{marginTop:e.space.xs},horizontalContainer:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},horizontalLabelWrap:{flexShrink:1,paddingRight:e.space.md}});export{NumberInput};export default NumberInput;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_OTP_INPUT_LABELS=Object.freeze({field:e=>`Enter ${e}-digit code`});const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:i,onChange:s,onComplete:r,length:a=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,labels:g,onFocus:h,accessibilityLabel:b,style:y,cellStyle:x,textStyle:T,testID:v}=e;warnInvalidValue("OTPInput","size",e.size,["sm","md","lg"]),warnInvalidValue("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const j=g?{...DEFAULT_OTP_INPUT_LABELS,...g}:DEFAULT_OTP_INPUT_LABELS,[I,C]=useControllableState({value:n,defaultValue:i??"",onChange:s}),E=useTheme(),V=useMemo(()=>buildStyles(E),[E]),w=resolveOtpInputSize(E,m),S=E.components["otp-input"][m].radius,A=useRef([]),[k,_]=useState(-1),[F,O]=useState(0),P=useRef(null),z=useRef(createAnimatedValue(0)).current,M=useRef(new Map),R=useMemo(()=>{const e=M.current,t=[];for(let n=0;n<a;n+=1){let i=e.get(n);i||(i=new Animated.Value(0),e.set(n,i)),t.push(i)}for(const t of Array.from(e.keys()))t>=a&&e.delete(t);return t},[a]),D=useRef(-1),L=E.settings.components["otp-input"]?.shakeOnError??!1,N=useReducedMotion(),B=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===P.current||!B||P.current||(f&&triggerHaptic("notificationError"),L&&!N&&(setNativeValue(z,0),e=Animated.sequence([Animated.timing(z,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:-1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:0,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0})]),e.start())),P.current=B,()=>e?.stop()},[B,z,L,f,N,E.motion.duration.instant]),useEffect(()=>{const e=D.current;if(D.current=k,e===k)return;if(-1===e&&-1===k)return;const t=[];return R.forEach((n,i)=>{const s=i===k?1:0;if(i!==k&&i!==e)return;const r=Animated.timing(n,{toValue:s,duration:E.motion.duration.fast,easing:Easing.bezier(...E.motion.ease["in-out"]),useNativeDriver:!0});r.start(),t.push(r)}),()=>t.forEach(e=>{e.stop()})},[k,R,E]);const H=useCallback(e=>{const t=A.current[e];t&&t.focus()},[]);useImperativeHandle(t,()=>({focus:()=>H(0),blur:()=>{const e=A.current[k>=0?k:0];e?.blur()},clear:()=>{C(""),H(0)}}),[H,k,C]),useEffect(()=>{if(l&&!c){const e=setTimeout(()=>H(0),u);return()=>clearTimeout(e)}},[l,u,c,H]);const U=useMemo(()=>{const e=new Array(a).fill("");for(let t=0;t<Math.min(I.length,a);t+=1)e[t]=I[t]??"";return e},[I,a]),W=useCallback(e=>{const t=e.slice(0,a);t!==I&&(C(t),t.length===a&&r&&r(t))},[a,C,r,I]),$=useCallback((e,t)=>{const n=t.replace(/\u200B/g,""),i=sanitizeChar(n,o);if(!i){const t=U.slice(),n=(t[e]??"").length>0;if(t[e]="",W(t.join("").slice(0,a)),!n&&e>0){const t=U.slice();t[e-1]="",W(t.join("")),H(e-1)}return}const s=U[e]??"",r=s&&i.length>a&&i.startsWith(s)?i.slice(s.length):i;if(r.length>=a){const t=r.slice(0,a),n=I.length;return W(t),t.length!==n&&f&&triggerHaptic(f),void A.current[e]?.blur()}const l=U.slice();let u=e;for(let e=0;e<i.length&&u<a;e+=1)l[u]=i[e]??"",u+=1;const c=l.join("").slice(0,a),d=I.length;W(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,a-1);u>=a?A.current[e]?.blur():H(m)},[U,H,o,a,f,W,I]),q=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(U[e]??"").length){if(e>0){const t=U.slice();t[e-1]="",W(t.join("")),H(e-1)}}else{const t=U.slice();t[e]="",W(t.join(""))}},[U,H,W]),G=useCallback((e,t)=>{_(e),h?.(t)},[h]),K=useCallback(()=>{_(-1)},[]),X=useCallback(()=>{if(c)return;const e=U.indexOf("");H(-1===e?a-1:e)},[U,c,H,a]),J=useCallback(e=>{O(e.nativeEvent.layout.width)},[]),Q=b??j.field(a),Y=F>0?Math.max(24,Math.min(w.cell,Math.floor((F-w.gap*(a-1))/a))):w.cell,Z=z.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return _jsxs(View,{style:y,onLayout:J,accessible:!0,accessibilityRole:"none",accessibilityLabel:Q,accessibilityValue:{text:n},accessibilityState:{disabled:c},"aria-disabled":c,testID:v,children:[_jsx(Pressable,{onPress:X,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[V.row,{columnGap:w.gap,transform:[{translateX:Z}]}],children:U.map((e,t)=>{const n=k===t,i=e.length>0,s=B?E.colors["danger-border"]:E.colors["focus-ring"],r=R[t];if(!r)return null;const l=p&&i?"●":e;return _jsxs(View,{style:V.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:Y,height:Y,radius:S,borderWidth:1.5,focused:n,error:B,filled:i,disabled:c,paddingHorizontal:E.space.none,paddingVertical:E.space.none,gap:E.space.none,style:x,children:[_jsx(TextInput,{ref:e=>{A.current[t]=e},value:(p&&i?"":e)||"​",onChangeText:e=>$(t,e),onKeyPress:e=>q(t,e),onFocus:e=>G(t,e),onBlur:K,keyboardType:o,editable:!c,selectTextOnFocus:!0,caretHidden:i,maxLength:a+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[V.input,{fontSize:w.text,color:E.colors["text-body"],...fontFor(E,"semibold")},T]}),p&&i?_jsx(View,{pointerEvents:"none",style:V.maskOverlay,children:_jsx(Text,{variant:"body",weight:"semibold",style:[{fontSize:w.text},T],children:l})}):null]}),_jsx(Animated.View,{style:[V.underline,{backgroundColor:s,opacity:r}]})]},`otp-cell-${t}`)})})}),_jsx(FieldMessage,{size:m,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,...smoothCorners}});export{OTPInput};export default OTPInput;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_OTP_INPUT_LABELS=Object.freeze({field:e=>`Enter ${e}-digit code`});const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:s,onChange:i,onComplete:r,length:a=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,labels:g,onFocus:h,accessibilityLabel:b,style:y,cellStyle:x,textStyle:T,testID:j}=e;assertValidValue("OTPInput","size",e.size,["sm","md","lg"]),assertValidValue("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const v=g?{...DEFAULT_OTP_INPUT_LABELS,...g}:DEFAULT_OTP_INPUT_LABELS,[V,C]=useControllableState({value:n,defaultValue:s??"",onChange:i}),E=useTheme(),S=useMemo(()=>buildStyles(E),[E]),A=resolveOtpInputSize(E,m),k=E.components["otp-input"][m].radius,I=useRef([]),[_,F]=useState(-1),[w,O]=useState(0),P=useRef(null),z=useRef(createAnimatedValue(0)).current,M=useRef(new Map),R=useMemo(()=>{const e=M.current,t=[];for(let n=0;n<a;n+=1){let s=e.get(n);s||(s=new Animated.Value(0),e.set(n,s)),t.push(s)}for(const t of Array.from(e.keys()))t>=a&&e.delete(t);return t},[a]),D=useRef(-1),L=E.settings.components["otp-input"]?.shakeOnError??!1,N=useReducedMotion(),B=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===P.current||!B||P.current||(f&&triggerHaptic("notificationError"),L&&!N&&(setNativeValue(z,0),e=Animated.sequence([Animated.timing(z,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:-1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:0,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0})]),e.start())),P.current=B,()=>e?.stop()},[B,z,L,f,N,E.motion.duration.instant]),useEffect(()=>{const e=D.current;if(D.current=_,e===_)return;if(-1===e&&-1===_)return;const t=[];return R.forEach((n,s)=>{const i=s===_?1:0;if(s!==_&&s!==e)return;const r=Animated.timing(n,{toValue:i,duration:E.motion.duration.fast,easing:Easing.bezier(...E.motion.ease["in-out"]),useNativeDriver:!0});r.start(),t.push(r)}),()=>t.forEach(e=>{e.stop()})},[_,R,E]);const H=useCallback(e=>{const t=I.current[e];t&&t.focus()},[]);useImperativeHandle(t,()=>({focus:()=>H(0),blur:()=>{const e=I.current[_>=0?_:0];e?.blur()},clear:()=>{C(""),H(0)}}),[H,_,C]),useEffect(()=>{if(l&&!c){const e=setTimeout(()=>H(0),u);return()=>clearTimeout(e)}},[l,u,c,H]);const U=useMemo(()=>{const e=new Array(a).fill("");for(let t=0;t<Math.min(V.length,a);t+=1)e[t]=V[t]??"";return e},[V,a]),W=useCallback(e=>{const t=e.slice(0,a);t!==V&&(C(t),t.length===a&&r&&r(t))},[a,C,r,V]),$=useCallback((e,t)=>{const n=t.replace(/\u200B/g,""),s=sanitizeChar(n,o);if(!s){const t=U.slice(),n=(t[e]??"").length>0;if(t[e]="",W(t.join("").slice(0,a)),!n&&e>0){const t=U.slice();t[e-1]="",W(t.join("")),H(e-1)}return}const i=U[e]??"",r=i&&s.length>a&&s.startsWith(i)?s.slice(i.length):s;if(r.length>=a){const t=r.slice(0,a),n=V.length;return W(t),t.length!==n&&f&&triggerHaptic(f),void I.current[e]?.blur()}const l=U.slice();let u=e;for(let e=0;e<s.length&&u<a;e+=1)l[u]=s[e]??"",u+=1;const c=l.join("").slice(0,a),d=V.length;W(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,a-1);u>=a?I.current[e]?.blur():H(m)},[U,H,o,a,f,W,V]),q=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(U[e]??"").length){if(e>0){const t=U.slice();t[e-1]="",W(t.join("")),H(e-1)}}else{const t=U.slice();t[e]="",W(t.join(""))}},[U,H,W]),G=useCallback((e,t)=>{F(e),h?.(t)},[h]),K=useCallback(()=>{F(-1)},[]),X=useCallback(()=>{if(c)return;const e=U.indexOf("");H(-1===e?a-1:e)},[U,c,H,a]),J=useCallback(e=>{O(e.nativeEvent.layout.width)},[]),Q=b??v.field(a),Y=w>0?Math.max(24,Math.min(A.cell,Math.floor((w-A.gap*(a-1))/a))):A.cell,Z=z.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return _jsxs(View,{style:y,onLayout:J,accessible:!0,accessibilityRole:"none",accessibilityLabel:Q,accessibilityValue:{text:n},accessibilityState:{disabled:c},"aria-disabled":c,testID:j,children:[_jsx(Pressable,{onPress:X,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[S.row,{columnGap:A.gap,transform:[{translateX:Z}]}],children:U.map((e,t)=>{const n=_===t,s=e.length>0,i=B?E.colors["danger-border"]:E.colors["focus-ring"],r=R[t];if(!r)return null;const l=p&&s?"●":e;return _jsxs(View,{style:S.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:Y,height:Y,radius:k,borderWidth:1.5,focused:n,error:B,filled:s,disabled:c,paddingHorizontal:E.space.none,paddingVertical:E.space.none,gap:E.space.none,style:x,children:[_jsx(TextInput,{ref:e=>{I.current[t]=e},value:(p&&s?"":e)||"​",onChangeText:e=>$(t,e),onKeyPress:e=>q(t,e),onFocus:e=>G(t,e),onBlur:K,keyboardType:o,editable:!c,selectTextOnFocus:!0,caretHidden:s,maxLength:a+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[S.input,{fontSize:A.text,color:E.colors["text-body"],...fontFor(E,"semibold")},T]}),p&&s?_jsx(View,{pointerEvents:"none",style:S.maskOverlay,children:_jsx(Text,{variant:"body",weight:"semibold",style:[{fontSize:A.text},T],children:l})}):null]}),_jsx(Animated.View,{style:[S.underline,{backgroundColor:i,opacity:r}]})]},`otp-cell-${t}`)})})}),_jsx(FieldMessage,{size:m,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,...smoothCorners}});export{OTPInput};export default OTPInput;
@@ -1 +1 @@
1
- "use strict";import{useEffect,useMemo,useRef}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Button}from"../Button/index.js";import{IconBadge}from"../IconBadge/index.js";import{Text}from"../Text/index.js";import{usePermissionPrompt}from"./usePermissionPrompt.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PERMISSION_PROMPT_LABELS=Object.freeze({proceed:"Continue",cancel:"Cancel",openSettings:"Open Settings",access:Object.freeze({camera:"Camera access",microphone:"Microphone access",photos:"Photo access",photosAdd:"Photo access",mediaLibrary:"Media library access",location:"Location access",locationAlways:"Location access",contacts:"Contacts access",calendar:"Calendar access",reminders:"Reminders access",notifications:"Notification access",bluetooth:"Bluetooth access",storage:"Storage access"}),notAvailable:e=>`${e} is not available on this device.`,offWithSettings:e=>`${e} is off for this app. You can turn it on in Settings.`,off:e=>`${e} is off, so this cannot be used right now.`});const unavailableMessage=(e,s,t,n)=>{const a=n.access[e];return"unavailable"===s?n.notAvailable(a):t?n.offWithSettings(a):n.off(a)};export const PermissionPrompt=e=>{const{kind:s,title:t,reason:n,icon:a,onResult:i,fallback:o,haptic:c="selection",labels:l,style:r,testID:u}=e;warnInvalidValue("PermissionPrompt","kind",s,Object.keys(DEFAULT_PERMISSION_PROMPT_LABELS.access));const m=l?{...DEFAULT_PERMISSION_PROMPT_LABELS,...l}:DEFAULT_PERMISSION_PROMPT_LABELS,p=useTheme(),d=useMemo(()=>buildStyles(p),[p]),h=usePermissionPrompt(s,{onResult:i}),f=unavailableMessage(s,h.status,h.showSettings,m),g=useRef(!1);if(useEffect(()=>{"explain"!==h.view?("unavailable"===h.view&&g.current&&announce(f),g.current=!1):g.current=!0},[h.view,f]),"explain"!==h.view&&"unavailable"!==h.view)return _jsx(View,{style:r,testID:u});const x="explain"===h.view;return _jsxs(View,{style:[d.root,r],testID:u,children:[_jsxs(View,{style:d.header,children:[a?_jsx(IconBadge,{icon:a,size:"lg",tone:x?"primary":"neutral"}):null,_jsx(Text,{variant:"h3",align:"center",children:t}),_jsx(Text,{variant:"body",color:"secondary",align:"center",children:x?n:f})]}),_jsxs(View,x?{style:d.actions,children:[_jsx(Button,{haptic:c,label:m.proceed,size:"lg",fullWidth:!0,loading:h.requesting,onPress:()=>{h.request()}}),h.cancellable?_jsx(Button,{haptic:c,label:m.cancel,size:"lg",fullWidth:!0,variant:"ghost",tone:"neutral",disabled:h.requesting,onPress:h.cancel}):null]}:{style:d.actions,children:[o?_jsx(Button,{haptic:c,label:o.label,size:"lg",fullWidth:!0,onPress:o.onPress}):null,h.showSettings?_jsx(View,{style:d.link,children:_jsx(Button,{haptic:c,label:m.openSettings,variant:"link",onPress:()=>{h.openSettings()}})}):null]})]})};const buildStyles=e=>StyleSheet.create({root:{gap:e.space.lg,paddingVertical:e.space.lg},header:{alignItems:"center",gap:e.space.sm},actions:{gap:e.space.sm},link:{alignItems:"center",paddingVertical:e.space.sm}});export default PermissionPrompt;
1
+ "use strict";import{useEffect,useMemo,useRef}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Button}from"../Button/index.js";import{IconBadge}from"../IconBadge/index.js";import{Text}from"../Text/index.js";import{usePermissionPrompt}from"./usePermissionPrompt.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PERMISSION_PROMPT_LABELS=Object.freeze({proceed:"Continue",cancel:"Cancel",openSettings:"Open Settings",access:Object.freeze({camera:"Camera access",microphone:"Microphone access",photos:"Photo access",photosAdd:"Photo access",mediaLibrary:"Media library access",location:"Location access",locationAlways:"Location access",contacts:"Contacts access",calendar:"Calendar access",reminders:"Reminders access",notifications:"Notification access",bluetooth:"Bluetooth access",storage:"Storage access"}),notAvailable:e=>`${e} is not available on this device.`,offWithSettings:e=>`${e} is off for this app. You can turn it on in Settings.`,off:e=>`${e} is off, so this cannot be used right now.`});const unavailableMessage=(e,s,t,n)=>{const a=n.access[e];return"unavailable"===s?n.notAvailable(a):t?n.offWithSettings(a):n.off(a)};export const PermissionPrompt=e=>{const{kind:s,title:t,reason:n,icon:a,onResult:i,fallback:o,haptic:c="selection",labels:l,style:r,testID:u}=e;assertValidValue("PermissionPrompt","kind",s,Object.keys(DEFAULT_PERMISSION_PROMPT_LABELS.access));const m=l?{...DEFAULT_PERMISSION_PROMPT_LABELS,...l}:DEFAULT_PERMISSION_PROMPT_LABELS,p=useTheme(),d=useMemo(()=>buildStyles(p),[p]),h=usePermissionPrompt(s,{onResult:i}),f=unavailableMessage(s,h.status,h.showSettings,m),g=useRef(!1);if(useEffect(()=>{"explain"!==h.view?("unavailable"===h.view&&g.current&&announce(f),g.current=!1):g.current=!0},[h.view,f]),"explain"!==h.view&&"unavailable"!==h.view)return _jsx(View,{style:r,testID:u});const x="explain"===h.view;return _jsxs(View,{style:[d.root,r],testID:u,children:[_jsxs(View,{style:d.header,children:[a?_jsx(IconBadge,{icon:a,size:"lg",tone:x?"primary":"neutral"}):null,_jsx(Text,{variant:"h3",align:"center",children:t}),_jsx(Text,{variant:"body",color:"secondary",align:"center",children:x?n:f})]}),_jsxs(View,x?{style:d.actions,children:[_jsx(Button,{haptic:c,label:m.proceed,size:"lg",fullWidth:!0,loading:h.requesting,onPress:()=>{h.request()}}),h.cancellable?_jsx(Button,{haptic:c,label:m.cancel,size:"lg",fullWidth:!0,variant:"ghost",tone:"neutral",disabled:h.requesting,onPress:h.cancel}):null]}:{style:d.actions,children:[o?_jsx(Button,{haptic:c,label:o.label,size:"lg",fullWidth:!0,onPress:o.onPress}):null,h.showSettings?_jsx(View,{style:d.link,children:_jsx(Button,{haptic:c,label:m.openSettings,variant:"link",onPress:()=>{h.openSettings()}})}):null]})]})};const buildStyles=e=>StyleSheet.create({root:{gap:e.space.lg,paddingVertical:e.space.lg},header:{alignItems:"center",gap:e.space.sm},actions:{gap:e.space.sm},link:{alignItems:"center",paddingVertical:e.space.sm}});export default PermissionPrompt;
@@ -1 +1 @@
1
- "use strict";import{countryFlagEmoji,formatPhoneAsTyped,getFormatterConfig,getPhoneCountries,isSupportedCountry,isValidNationalNumber,maxNationalNumberLength,splitPhoneNumber}from"@webority/mobile-core";import{PHONE_COUNTRY_NAMES}from"@webority/mobile-core/phone/countries";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PHONE_NUMBER_INPUT_LABELS=Object.freeze({placeholder:"Phone number",popular:"Popular",allCountries:"All countries",countrySheetTitle:"Country code",countrySearchPlaceholder:"Search…",invalid:"Enter a valid number",invalidMobile:"Enter a valid mobile number",countryButton:e=>`Country code, currently +${e}`});export const DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}];export const ALL_CALLING_CODES=getPhoneCountries().map(e=>({iso:e.iso,code:e.callingCode,label:PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label));const digitsOnly=e=>e.replace(/[^0-9]/g,"");export const formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;export const parseE164=(e,t,o)=>{const n=e.replace(/[^0-9]/g,"");if(!n)return null;const i=splitPhoneNumber(`+${n}`);let l=i?.callingCode,a=i?.nationalNumber??"";if(!l){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(l=e.find(e=>n.startsWith(e)),!l)return null;a=n.slice(l.length)}const r=t.filter(e=>e.code===l),s=r.find(e=>e.iso===o)?.iso??r.find(e=>e.iso===i?.country)?.iso??i?.country??r[0]?.iso??"";return{callingCode:l,nationalNumber:a,iso:s}};const planOf=e=>isSupportedCountry(e)?e:null;export const PhoneNumberInput=forwardRef((e,t)=>{const{value:o,defaultValue:n,onChange:i,e164:l,onChangeE164:a,returnKeyType:r,submitBehavior:s,onSubmitEditing:u,blurOnSubmit:d,onComplete:c,onValidityChange:p,countries:m=ALL_CALLING_CODES,popularCountries:b,hiddenCountries:f,showFlag:h=!0,renderFlag:g,renderCountry:N,showAlphabetIndex:y,defaultCountry:C,validation:x="any",maxLength:v,formatAsYouType:S=!0,countryLocked:I=!1,label:E,labelMode:T="top",labelStyle:F,placeholder:L,helperText:P,error:_,invalidMessage:j,required:O,disabled:A=!1,size:M="md",variant:w,radius:V,labels:B,haptic:U,accessibilityLabel:k,countryAccessibilityLabel:z,onFocus:D,onBlur:R,style:H,testID:$}=e;warnInvalidValue("PhoneNumberInput","size",e.size,["sm","md","lg"]),warnInvalidValue("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),warnInvalidValue("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),warnInvalidValue("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const W=useTheme(),q=useMemo(()=>buildStyles(W),[W]),G=useRef(null),Y=useMemo(()=>B?{...DEFAULT_PHONE_NUMBER_INPUT_LABELS,...B}:DEFAULT_PHONE_NUMBER_INPUT_LABELS,[B]),K=L??Y.placeholder,Z=useMemo(()=>/-([A-Za-z]{2})(?:-|$)/.exec(getFormatterConfig().locale)?.[1]?.toUpperCase(),[]),J=useMemo(()=>f?.length?m.filter(e=>!f.includes(e.iso)):m,[m,f]),Q=useMemo(()=>{if(!b?.length)return;const e=b.map(e=>J.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:Y.popular,options:e},{title:Y.allCountries,options:J}]:void 0},[b,Y.popular,Y.allCountries,J]),X=useCallback((e,t,o)=>{if(!e)return null;if(g)return g(e);if(!h)return null;const n=countryFlagEmoji(e.iso);return n?_jsx(Text,{variant:"body",style:[q.flag,{fontSize:t}],testID:o,children:n}):null},[g,h,q.flag]),ee=useCallback(e=>{const t=planOf(e),o=t?maxNationalNumberLength(t,!1===x?"any":x):Number.POSITIVE_INFINITY;return v?Math.min(o,v):o},[v,x]),te=useCallback((e,t)=>e.slice(0,ee(t)),[ee]),oe=useCallback((e,t)=>{const o=planOf(t)??void 0,n=splitPhoneNumber(e,o);if(!n)return null;const i=n.country??t,l=m.find(e=>e.iso===i);return{callingCode:l?.code??n.callingCode,nationalNumber:te(n.nationalNumber,i),iso:l?.iso??i}},[m,te]),ne=useMemo(()=>{const e=J.find(e=>e.iso===(C??Z))??J[0]??m[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof n?oe(n,t.iso)??t:n??t},[m,J,C,Z,n,oe]),ie=useCallback(e=>{if(!1===x)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?isValidNationalNumber(e.nationalNumber,t,x):e.nationalNumber.length>0},[x]),[le,ae]=useState(ne.iso),re=useMemo(()=>{if(void 0===l)return;const e=l?parseE164(l,m,le):null;if(e)return{...e,nationalNumber:te(e.nationalNumber,e.iso)};const t=m.find(e=>e.iso===le);return{callingCode:t?.code??ne.callingCode,nationalNumber:"",iso:le}},[l,m,le,ne.callingCode,te]),se=useCallback(e=>{ae(e.iso),i?.(e),a?.(e.nationalNumber?formatE164(e):"",{country:m.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:ie(e)})},[i,a,m,ie]),[ue,de]=useControllableState({value:o??re,defaultValue:ne,onChange:se}),[ce,pe]=useState(!1),me=useCallback(()=>{A||G.current?.focus()},[A]),[be,fe]=useState(!1),[he,ge]=useState(!1),[Ne,ye]=useState(!1),Ce=useRef(!1);useEffect(()=>{Ne||(Ce.current=!1)},[Ne]);const xe=resolveFieldSize(W,M),ve=resolveFieldTextStyle(W,{disabled:A}),Se=w??W.settings.components.field?.defaultVariant??"outline",Ie="underline"===Se,Ee=W.space.md,[Te,Fe]=useState(0),Le=Te+Ee+1+Ee,Pe=ue.nationalNumber.length>0,je=O&&!E&&!Pe&&K.length>0,Oe=ce||Pe,Ae=Boolean(E)&&"float"===T&&Te>0,Me=useFloatingLabel({label:E,enabled:Ae,floated:Oe,required:O,variant:Se,sizeTokens:xe,leadingOffset:Le,paddingLeft:Ie?W.space.none:xe["padding-x"],color:W.colors["field-label"],style:F}),we=useMemo(()=>m.find(e=>e.iso===ue.iso),[m,ue.iso]),Ve=planOf(ue.iso),Be=S&&Ve?formatPhoneAsTyped(ue.nationalNumber,Ve):ue.nationalNumber,Ue=ee(ue.iso),ke=0===ue.nationalNumber.length||be||!Number.isFinite(Ue)?void 0:Be.length+Math.max(0,Ue-ue.nationalNumber.length),ze=ie(ue);useEffect(()=>{Pe||ge(!1)},[Pe]);const De=Ve?maxNationalNumberLength(Ve,!1===x?"any":x):Number.POSITIVE_INFINITY,Re=ue.nationalNumber.length>=De,He=!1!==x&&!1!==j&&Pe&&!ze&&(he||Re),$e="mobile"===x?Y.invalidMobile:Y.invalid,We=hasFieldText(_)?_:He?j||$e:void 0,qe=!0===_||hasFieldText(We),Ge=useRef(ze),Ye=useRef(ue);Ye.current=ue,useEffect(()=>{Ge.current!==ze&&(Ge.current=ze,p?.(ze),ze&&c?.(formatE164(Ye.current)))},[ze,c,p]);const Ke=useCallback(e=>{if(e.includes("+")){const t=oe(e,ue.iso);if(t&&!I&&J.some(e=>e.iso===t.iso))return void de(t);if(t&&t.iso===ue.iso)return void de(t)}de({...ue,nationalNumber:te(digitsOnly(e),ue.iso)})},[J,I,ue,oe,te,de]),Ze=useCallback(e=>{de({callingCode:e.code,iso:e.iso,nationalNumber:te(ue.nationalNumber,e.iso)}),ye(!1);const t=resolveHaptic(U,"selection");t&&triggerHaptic(t)},[ue,U,te,de]);useImperativeHandle(t,()=>({focus:()=>G.current?.focus(),blur:()=>G.current?.blur(),clear:()=>de({...Ye.current,nationalNumber:""}),isFocused:()=>G.current?.isFocused()??!1,getValue:()=>Ye.current,getE164:()=>formatE164(Ye.current),getFormatted:()=>{const e=Ye.current,t=planOf(e.iso);return t?formatPhoneAsTyped(e.nationalNumber,t):e.nationalNumber},isValid:()=>ie(Ye.current),getCountry:()=>m.find(e=>e.iso===Ye.current.iso)}),[m,ie,de]);const Je=A||I,Qe=_jsx(FieldBase,{size:M,variant:Se,radius:V,topNotch:Me.topNotch,focused:ce,disabled:A,error:qe,filled:Pe,onPress:me,pressFeedback:!1,leadingDivider:!0,paddingLeft:Ie?W.space.none:void 0,leading:_jsxs(Pressable,{onPress:()=>{Je||(Ce.current=!0,ye(!0))},disabled:Je,accessibilityRole:"button",accessibilityLabel:z??Y.countryButton(ue.callingCode),accessibilityState:{disabled:Je},"aria-disabled":Je,hitSlop:6,...hitSlopMarker(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Fe(e=>e===t?e:t)},style:q.codeTrigger,testID:$?`${$}-code`:void 0,children:[X(we,xe.text,$?`${$}-flag`:void 0),_jsx(Text,{variant:"body",style:[q.codeText,{color:ve.color,fontSize:xe.text}],children:`+${ue.callingCode}`}),I?null:_jsx(Chevron,{color:A?W.colors["field-icon-disabled"]:W.colors["field-icon"],size:xe.icon,open:Ne})]}),children:_jsxs(View,{style:q.inputWrap,children:[_jsx(TextInput,{ref:G,value:Be,maxLength:ke,onChangeText:Ke,returnKeyType:r,submitBehavior:s,onSubmitEditing:u,blurOnSubmit:d,onSelectionChange:e=>{const{start:t,end:o}=e.nativeEvent.selection;fe(t!==o)},onFocus:()=>{pe(!0),D?.()},onBlur:()=>{pe(!1),Pe&&!Ce.current&&ge(!0),R?.()},editable:!A,placeholder:Ae&&!Oe||je?void 0:K,placeholderTextColor:ve.placeholderColor,accessibilityLabel:k??E??K,selectionColor:W.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[q.input,{color:ve.color,fontSize:xe.text,...ve.weightStyle,paddingLeft:Ie?W.space.none:void 0}],testID:$?`${$}-input`:void 0}),je?_jsx(RequiredPlaceholder,{text:K,color:ve.placeholderColor,fontSize:xe.text,weightStyle:ve.weightStyle}):null]})});return _jsxs(View,{style:H,testID:$,children:[E&&"top"===T?_jsx(FieldLabel,{size:M,required:O,children:E}):null,_jsxs(View,{style:q.fieldWrapper,children:[Qe,Me.node]}),_jsx(FieldMessage,{size:M,error:qe,text:qe?We:P}),_jsx(OptionSheet,{open:Ne,haptic:U,onClose:()=>ye(!1),title:Y.countrySheetTitle,options:J,sections:Q,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>X(e,W.text.lg.size),renderOption:N?({option:e,selected:t})=>N(e,{selected:t}):void 0,value:we?.iso,onChange:(e,t)=>Ze(t),searchable:J.length>8,labels:{searchPlaceholder:Y.countrySearchPlaceholder},alphabetIndex:y??J.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...fontFor(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});export default PhoneNumberInput;
1
+ "use strict";import{countryFlagEmoji,formatPhoneAsTyped,getFormatterConfig,getPhoneCountries,isSupportedCountry,isValidNationalNumber,maxNationalNumberLength,splitPhoneNumber}from"@webority/mobile-core";import{PHONE_COUNTRY_NAMES}from"@webority/mobile-core/phone/countries";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PHONE_NUMBER_INPUT_LABELS=Object.freeze({placeholder:"Phone number",popular:"Popular",allCountries:"All countries",countrySheetTitle:"Country code",countrySearchPlaceholder:"Search…",invalid:"Enter a valid number",invalidMobile:"Enter a valid mobile number",countryButton:e=>`Country code, currently +${e}`});export const DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}];export const ALL_CALLING_CODES=getPhoneCountries().map(e=>({iso:e.iso,code:e.callingCode,label:PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label));const digitsOnly=e=>e.replace(/[^0-9]/g,"");export const formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;export const parseE164=(e,t,o)=>{const i=e.replace(/[^0-9]/g,"");if(!i)return null;const l=splitPhoneNumber(`+${i}`);let n=l?.callingCode,a=l?.nationalNumber??"";if(!n){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(n=e.find(e=>i.startsWith(e)),!n)return null;a=i.slice(n.length)}const r=t.filter(e=>e.code===n),s=r.find(e=>e.iso===o)?.iso??r.find(e=>e.iso===l?.country)?.iso??l?.country??r[0]?.iso??"";return{callingCode:n,nationalNumber:a,iso:s}};const planOf=e=>isSupportedCountry(e)?e:null;export const PhoneNumberInput=forwardRef((e,t)=>{const{value:o,defaultValue:i,onChange:l,e164:n,onChangeE164:a,returnKeyType:r,submitBehavior:s,onSubmitEditing:u,blurOnSubmit:d,onComplete:c,onValidityChange:p,countries:m=ALL_CALLING_CODES,popularCountries:b,hiddenCountries:f,showFlag:h=!0,renderFlag:g,renderCountry:N,showAlphabetIndex:y,defaultCountry:C,validation:x="any",maxLength:S,formatAsYouType:v=!0,countryLocked:E=!1,label:T,labelMode:F="top",labelStyle:L,placeholder:P,helperText:I,error:_,invalidMessage:j,required:O,disabled:A=!1,size:V="md",variant:M,radius:w,labels:B,haptic:U,accessibilityLabel:k,countryAccessibilityLabel:z,onFocus:D,onBlur:R,style:H,testID:$}=e;assertValidValue("PhoneNumberInput","size",e.size,["sm","md","lg"]),assertValidValue("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),assertValidValue("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),assertValidValue("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const W=useTheme(),q=useMemo(()=>buildStyles(W),[W]),G=useRef(null),Y=useMemo(()=>B?{...DEFAULT_PHONE_NUMBER_INPUT_LABELS,...B}:DEFAULT_PHONE_NUMBER_INPUT_LABELS,[B]),K=P??Y.placeholder,Z=useMemo(()=>/-([A-Za-z]{2})(?:-|$)/.exec(getFormatterConfig().locale)?.[1]?.toUpperCase(),[]),J=useMemo(()=>f?.length?m.filter(e=>!f.includes(e.iso)):m,[m,f]),Q=useMemo(()=>{if(!b?.length)return;const e=b.map(e=>J.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:Y.popular,options:e},{title:Y.allCountries,options:J}]:void 0},[b,Y.popular,Y.allCountries,J]),X=useCallback((e,t,o)=>{if(!e)return null;if(g)return g(e);if(!h)return null;const i=countryFlagEmoji(e.iso);return i?_jsx(Text,{variant:"body",style:[q.flag,{fontSize:t}],testID:o,children:i}):null},[g,h,q.flag]),ee=useCallback(e=>{const t=planOf(e),o=t?maxNationalNumberLength(t,!1===x?"any":x):Number.POSITIVE_INFINITY;return S?Math.min(o,S):o},[S,x]),te=useCallback((e,t)=>e.slice(0,ee(t)),[ee]),oe=useCallback((e,t)=>{const o=planOf(t)??void 0,i=splitPhoneNumber(e,o);if(!i)return null;const l=i.country??t,n=m.find(e=>e.iso===l);return{callingCode:n?.code??i.callingCode,nationalNumber:te(i.nationalNumber,l),iso:n?.iso??l}},[m,te]),ie=useMemo(()=>{const e=J.find(e=>e.iso===(C??Z))??J[0]??m[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof i?oe(i,t.iso)??t:i??t},[m,J,C,Z,i,oe]),le=useCallback(e=>{if(!1===x)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?isValidNationalNumber(e.nationalNumber,t,x):e.nationalNumber.length>0},[x]),[ne,ae]=useState(ie.iso),re=useMemo(()=>{if(void 0===n)return;const e=n?parseE164(n,m,ne):null;if(e)return{...e,nationalNumber:te(e.nationalNumber,e.iso)};const t=m.find(e=>e.iso===ne);return{callingCode:t?.code??ie.callingCode,nationalNumber:"",iso:ne}},[n,m,ne,ie.callingCode,te]),se=useCallback(e=>{ae(e.iso),l?.(e),a?.(e.nationalNumber?formatE164(e):"",{country:m.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:le(e)})},[l,a,m,le]),[ue,de]=useControllableState({value:o??re,defaultValue:ie,onChange:se}),[ce,pe]=useState(!1),me=useCallback(()=>{A||G.current?.focus()},[A]),[be,fe]=useState(!1),[he,ge]=useState(!1),[Ne,ye]=useState(!1),Ce=useRef(!1);useEffect(()=>{Ne||(Ce.current=!1)},[Ne]);const xe=resolveFieldSize(W,V),Se=resolveFieldTextStyle(W,{disabled:A}),ve=M??W.settings.components.field?.defaultVariant??"outline",Ee="underline"===ve,Te=W.space.md,[Fe,Le]=useState(0),Pe=Fe+Te+1+Te,Ie=ue.nationalNumber.length>0,je=O&&!T&&!Ie&&K.length>0,Oe=ce||Ie,Ae=Boolean(T)&&"float"===F&&Fe>0,Ve=useFloatingLabel({label:T,enabled:Ae,floated:Oe,required:O,variant:ve,sizeTokens:xe,leadingOffset:Pe,paddingLeft:Ee?W.space.none:xe["padding-x"],color:W.colors["field-label"],style:L}),Me=useMemo(()=>m.find(e=>e.iso===ue.iso),[m,ue.iso]),we=planOf(ue.iso),Be=v&&we?formatPhoneAsTyped(ue.nationalNumber,we):ue.nationalNumber,Ue=ee(ue.iso),ke=0===ue.nationalNumber.length||be||!Number.isFinite(Ue)?void 0:Be.length+Math.max(0,Ue-ue.nationalNumber.length),ze=le(ue);useEffect(()=>{Ie||ge(!1)},[Ie]);const De=we?maxNationalNumberLength(we,!1===x?"any":x):Number.POSITIVE_INFINITY,Re=ue.nationalNumber.length>=De,He=!1!==x&&!1!==j&&Ie&&!ze&&(he||Re),$e="mobile"===x?Y.invalidMobile:Y.invalid,We=hasFieldText(_)?_:He?j||$e:void 0,qe=!0===_||hasFieldText(We),Ge=useRef(ze),Ye=useRef(ue);Ye.current=ue,useEffect(()=>{Ge.current!==ze&&(Ge.current=ze,p?.(ze),ze&&c?.(formatE164(Ye.current)))},[ze,c,p]);const Ke=useCallback(e=>{if(e.includes("+")){const t=oe(e,ue.iso);if(t&&!E&&J.some(e=>e.iso===t.iso))return void de(t);if(t&&t.iso===ue.iso)return void de(t)}de({...ue,nationalNumber:te(digitsOnly(e),ue.iso)})},[J,E,ue,oe,te,de]),Ze=useCallback(e=>{de({callingCode:e.code,iso:e.iso,nationalNumber:te(ue.nationalNumber,e.iso)}),ye(!1);const t=resolveHaptic(U,"selection");t&&triggerHaptic(t)},[ue,U,te,de]);useImperativeHandle(t,()=>({focus:()=>G.current?.focus(),blur:()=>G.current?.blur(),clear:()=>de({...Ye.current,nationalNumber:""}),isFocused:()=>G.current?.isFocused()??!1,getValue:()=>Ye.current,getE164:()=>formatE164(Ye.current),getFormatted:()=>{const e=Ye.current,t=planOf(e.iso);return t?formatPhoneAsTyped(e.nationalNumber,t):e.nationalNumber},isValid:()=>le(Ye.current),getCountry:()=>m.find(e=>e.iso===Ye.current.iso)}),[m,le,de]);const Je=A||E,Qe=_jsx(FieldBase,{size:V,variant:ve,radius:w,topNotch:Ve.topNotch,focused:ce,disabled:A,error:qe,filled:Ie,onPress:me,pressFeedback:!1,leadingDivider:!0,paddingLeft:Ee?W.space.none:void 0,leading:_jsxs(Pressable,{onPress:()=>{Je||(Ce.current=!0,ye(!0))},disabled:Je,accessibilityRole:"button",accessibilityLabel:z??Y.countryButton(ue.callingCode),accessibilityState:{disabled:Je},"aria-disabled":Je,hitSlop:6,...hitSlopMarker(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Le(e=>e===t?e:t)},style:q.codeTrigger,testID:$?`${$}-code`:void 0,children:[X(Me,xe.text,$?`${$}-flag`:void 0),_jsx(Text,{variant:"body",style:[q.codeText,{color:Se.color,fontSize:xe.text}],children:`+${ue.callingCode}`}),E?null:_jsx(Chevron,{color:A?W.colors["field-icon-disabled"]:W.colors["field-icon"],size:xe.icon,open:Ne})]}),children:_jsxs(View,{style:q.inputWrap,children:[_jsx(TextInput,{ref:G,value:Be,maxLength:ke,onChangeText:Ke,returnKeyType:r,submitBehavior:s,onSubmitEditing:u,blurOnSubmit:d,onSelectionChange:e=>{const{start:t,end:o}=e.nativeEvent.selection;fe(t!==o)},onFocus:()=>{pe(!0),D?.()},onBlur:()=>{pe(!1),Ie&&!Ce.current&&ge(!0),R?.()},editable:!A,placeholder:Ae&&!Oe||je?void 0:K,placeholderTextColor:Se.placeholderColor,accessibilityLabel:k??T??K,selectionColor:W.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[q.input,{color:Se.color,fontSize:xe.text,...Se.weightStyle,paddingLeft:Ee?W.space.none:void 0}],testID:$?`${$}-input`:void 0}),je?_jsx(RequiredPlaceholder,{text:K,color:Se.placeholderColor,fontSize:xe.text,weightStyle:Se.weightStyle}):null]})});return _jsxs(View,{style:H,testID:$,children:[T&&"top"===F?_jsx(FieldLabel,{size:V,required:O,children:T}):null,_jsxs(View,{style:q.fieldWrapper,children:[Qe,Ve.node]}),_jsx(FieldMessage,{size:V,error:qe,text:qe?We:I}),_jsx(OptionSheet,{open:Ne,haptic:U,onClose:()=>ye(!1),title:Y.countrySheetTitle,options:J,sections:Q,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>X(e,W.text.lg.size),renderOption:N?({option:e,selected:t})=>N(e,{selected:t}):void 0,value:Me?.iso,onChange:(e,t)=>Ze(t),searchable:J.length>8,labels:{searchPlaceholder:Y.countrySearchPlaceholder},alphabetIndex:y??J.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...fontFor(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});export default PhoneNumberInput;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,RequiredMark,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PICKER_TRIGGER_LABELS=Object.freeze({placeholder:"Select…",selection:"Selection",noSelection:"No selection",clear:"Clear"});const PickerTrigger=forwardRef((e,l)=>{warnInvalidValue("PickerTrigger","size",e.size,["sm","md","lg"]),warnInvalidValue("PickerTrigger","variant",e.variant,["outline","filled","underline"]);const{value:i,placeholder:r,label:t,help:s,helperText:o,error:a,required:n=!1,onPress:d,clearable:c=!1,onClear:x,leftIcon:u,trailing:g,disabled:m=!1,size:b="md",variant:y,style:T,triggerStyle:h,valueStyle:S,labelStyle:f,messageStyle:v,accessibilityLabel:p,labels:F,testID:j}=e,_=F?{...DEFAULT_PICKER_TRIGGER_LABELS,...F}:DEFAULT_PICKER_TRIGGER_LABELS,R=useTheme(),P=useMemo(()=>buildStyles(R),[R]),L=resolveFieldSize(R,b),w=resolveFieldTextStyle(R,{disabled:m}),I="string"==typeof i&&i.length>0,z=!0===a||hasFieldText(a),E=hasFieldText(t),k=I?i:r??_.placeholder,C=I?w.color:w.placeholderColor,A=I?`${fieldTextAsString(t)??_.selection}: ${i}`:r??_.noSelection,B=p??A,V={disabled:m},D=void 0===g,G=c&&I&&!m;return _jsxs(View,{style:[P.root,T],testID:j,children:[E?_jsx(FieldLabel,{size:b,required:n,help:s,style:f,children:t}):null,_jsx(FieldBase,{size:b,variant:y,disabled:m,error:z,filled:I,onPress:d,leading:u,trailing:G||D||null!==g?_jsxs(View,{style:P.trailingRow,children:[G?_jsx(Text,{variant:"body",onPress:()=>{m||x?.()},accessibilityRole:"button",accessibilityLabel:_.clear,style:{fontSize:L.icon,color:R.colors["text-muted"],paddingHorizontal:R.space.xs},children:"×"}):null,void 0!==g?g:D?_jsx(Chevron,{size:L.icon,color:m?R.colors["text-disabled"]:R.colors["text-subtle"]}):null]}):null,accessibilityLabel:B,accessibilityState:V,accessibilityRole:"button",style:h,children:_jsxs(Text,{variant:"body",numberOfLines:1,style:[P.valueText,{color:C,fontSize:L.text,...w.weightStyle},S],children:[k,I||!n||E?null:_jsx(RequiredMark,{})]})}),_jsx(FieldMessage,{size:b,error:z,text:z?a:o,style:v})]})});PickerTrigger.displayName="PickerTrigger";const buildStyles=e=>StyleSheet.create({root:{width:"100%"},label:{includeFontPadding:!1},valueText:{flex:1,includeFontPadding:!1},message:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center"}});export{PickerTrigger};export default PickerTrigger;
1
+ "use strict";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,RequiredMark,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PICKER_TRIGGER_LABELS=Object.freeze({placeholder:"Select…",selection:"Selection",noSelection:"No selection",clear:"Clear"});const PickerTrigger=forwardRef((e,l)=>{assertValidValue("PickerTrigger","size",e.size,["sm","md","lg"]),assertValidValue("PickerTrigger","variant",e.variant,["outline","filled","underline"]);const{value:i,placeholder:t,label:r,help:s,helperText:o,error:a,required:n=!1,onPress:d,clearable:c=!1,onClear:x,leftIcon:u,trailing:g,disabled:m=!1,size:b="md",variant:y,style:T,triggerStyle:h,valueStyle:S,labelStyle:f,messageStyle:p,accessibilityLabel:F,labels:j,testID:v}=e,_=j?{...DEFAULT_PICKER_TRIGGER_LABELS,...j}:DEFAULT_PICKER_TRIGGER_LABELS,R=useTheme(),P=useMemo(()=>buildStyles(R),[R]),L=resolveFieldSize(R,b),z=resolveFieldTextStyle(R,{disabled:m}),E="string"==typeof i&&i.length>0,V=!0===a||hasFieldText(a),w=hasFieldText(r),I=E?i:t??_.placeholder,k=E?z.color:z.placeholderColor,C=E?`${fieldTextAsString(r)??_.selection}: ${i}`:t??_.noSelection,A=F??C,B={disabled:m},D=void 0===g,G=c&&E&&!m;return _jsxs(View,{style:[P.root,T],testID:v,children:[w?_jsx(FieldLabel,{size:b,required:n,help:s,style:f,children:r}):null,_jsx(FieldBase,{size:b,variant:y,disabled:m,error:V,filled:E,onPress:d,leading:u,trailing:G||D||null!==g?_jsxs(View,{style:P.trailingRow,children:[G?_jsx(Text,{variant:"body",onPress:()=>{m||x?.()},accessibilityRole:"button",accessibilityLabel:_.clear,style:{fontSize:L.icon,color:R.colors["text-muted"],paddingHorizontal:R.space.xs},children:"×"}):null,void 0!==g?g:D?_jsx(Chevron,{size:L.icon,color:m?R.colors["text-disabled"]:R.colors["text-subtle"]}):null]}):null,accessibilityLabel:A,accessibilityState:B,accessibilityRole:"button",style:h,children:_jsxs(Text,{variant:"body",numberOfLines:1,style:[P.valueText,{color:k,fontSize:L.text,...z.weightStyle},S],children:[I,E||!n||w?null:_jsx(RequiredMark,{})]})}),_jsx(FieldMessage,{size:b,error:V,text:V?a:o,style:p})]})});PickerTrigger.displayName="PickerTrigger";const buildStyles=e=>StyleSheet.create({root:{width:"100%"},label:{includeFontPadding:!1},valueText:{flex:1,includeFontPadding:!1},message:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center"}});export{PickerTrigger};export default PickerTrigger;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Avatar}from"../Avatar/index.js";import{IconBadge}from"../IconBadge/index.js";import{ProgressRing}from"../ProgressRing/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PROFILE_COMPLETION_LABELS=Object.freeze({summary:(e,r)=>`${e}, profile ${r}% complete`,avatar:e=>`${e}'s avatar`});const AVATAR_PX={sm:32,md:48,lg:64,xl:80},toneColor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["text-muted"];default:return e.colors.primary}},DEFAULT_RING_WIDTH=3,DEFAULT_RING_GAP=1,ProfileCompletion=forwardRef((e,r)=>{const{progress:t,title:o,subtitle:i,description:s,source:a,ImageComponent:n,size:l="md",avatarTone:c="neutral",avatarBackgroundColor:m,avatarColor:d,ringWidth:u,ringGap:p=DEFAULT_RING_GAP,ringVariant:g="banded",tone:x,ringColor:f,animated:y=!0,showCompleteBadge:b=!0,trailing:_,labels:h,accessibilityLabel:I,style:j,titleStyle:w,subtitleStyle:v,descriptionStyle:A,testID:C}=e;warnInvalidValue("ProfileCompletion","size",e.size,["sm","md","lg","xl"]),warnInvalidValue("ProfileCompletion","ringVariant",e.ringVariant,["banded","single"]),warnInvalidValue("ProfileCompletion","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const P=useTheme(),T=useMemo(()=>buildStyles(P),[P]),L=useMemo(()=>({...DEFAULT_PROFILE_COMPLETION_LABELS,...h}),[h]),V=u??3,R=AVATAR_PX[l]+2*(p+V),S=Math.min(100,Math.max(0,Number.isNaN(t)?0:t)),D=Math.round(S),E=I??L.summary(o,D),M=C??"profile-completion",G=b&&S>=100,N=Math.max(16,Math.round(.3*R)),O=R/2*(1+Math.SQRT1_2)-V/2,B=f??("banded"===g&&null==x?P.colors.success:toneColor(P,x??"primary"));return _jsxs(View,{ref:r,style:[T.root,j],testID:C,children:[_jsxs(View,{style:T.summary,accessible:!0,accessibilityRole:"summary",accessibilityLabel:E,accessibilityValue:{min:0,max:100,now:D},testID:`${M}-summary`,children:[_jsxs(View,{style:{width:R,height:R},children:[_jsx(ProgressRing,{progress:S/100,size:R,strokeWidth:V,tone:x??"primary",ringColor:f,colorByProgress:"banded"===g&&null==x&&null==f,animated:y,testID:`${M}-ring`,children:_jsx(Avatar,{name:o,source:a,ImageComponent:n,size:l,tone:c,backgroundColor:m,color:d,accessibilityLabel:L.avatar(o)})}),G?_jsx(IconBadge,{dimension:N,fill:"surface",icon:_jsx(AppIcon,{name:"verify",variant:"bold",size:N-2,color:B}),pointerEvents:"none",style:[T.badge,{left:O-N/2,top:O-N/2}],testID:`${M}-complete-badge`}):null]}),_jsxs(View,{style:T.body,children:[_jsx(Text,{variant:"h3",numberOfLines:2,style:w,children:o}),i?_jsx(Text,{variant:"label",color:"tertiary",numberOfLines:1,style:[T.subtitle,v],children:i}):null,s?_jsx(Text,{variant:"body",color:"secondary",style:A,children:s}):null]})]}),null!=_?_jsx(View,{style:T.trailing,children:_}):null]})});ProfileCompletion.displayName="ProfileCompletion";const buildStyles=e=>StyleSheet.create({root:{flexDirection:"row",alignItems:"center",columnGap:e.space.md},summary:{flex:1,flexDirection:"row",alignItems:"center",columnGap:e.space.md},body:{flex:1,rowGap:e.space.xxs},badge:{position:"absolute"},subtitle:{textTransform:"uppercase",letterSpacing:e["letter-spacing"].wide},trailing:{alignSelf:"flex-start"}});export{ProfileCompletion};export default ProfileCompletion;
1
+ "use strict";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Avatar}from"../Avatar/index.js";import{IconBadge}from"../IconBadge/index.js";import{ProgressRing}from"../ProgressRing/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PROFILE_COMPLETION_LABELS=Object.freeze({summary:(e,r)=>`${e}, profile ${r}% complete`,avatar:e=>`${e}'s avatar`});const AVATAR_PX={sm:32,md:48,lg:64,xl:80},toneColor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["text-muted"];default:return e.colors.primary}},DEFAULT_RING_WIDTH=3,DEFAULT_RING_GAP=1,ProfileCompletion=forwardRef((e,r)=>{const{progress:t,title:s,subtitle:o,description:i,source:a,ImageComponent:l,size:n="md",avatarTone:c="neutral",avatarBackgroundColor:m,avatarColor:d,ringWidth:u,ringGap:p=DEFAULT_RING_GAP,ringVariant:g="banded",tone:x,ringColor:f,animated:y=!0,showCompleteBadge:b=!0,trailing:_,labels:h,accessibilityLabel:j,style:I,titleStyle:V,subtitleStyle:A,descriptionStyle:C,testID:P}=e;assertValidValue("ProfileCompletion","size",e.size,["sm","md","lg","xl"]),assertValidValue("ProfileCompletion","ringVariant",e.ringVariant,["banded","single"]),assertValidValue("ProfileCompletion","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const T=useTheme(),w=useMemo(()=>buildStyles(T),[T]),L=useMemo(()=>({...DEFAULT_PROFILE_COMPLETION_LABELS,...h}),[h]),v=u??3,R=AVATAR_PX[n]+2*(p+v),S=Math.min(100,Math.max(0,Number.isNaN(t)?0:t)),D=Math.round(S),E=j??L.summary(s,D),M=P??"profile-completion",G=b&&S>=100,N=Math.max(16,Math.round(.3*R)),O=R/2*(1+Math.SQRT1_2)-v/2,B=f??("banded"===g&&null==x?T.colors.success:toneColor(T,x??"primary"));return _jsxs(View,{ref:r,style:[w.root,I],testID:P,children:[_jsxs(View,{style:w.summary,accessible:!0,accessibilityRole:"summary",accessibilityLabel:E,accessibilityValue:{min:0,max:100,now:D},testID:`${M}-summary`,children:[_jsxs(View,{style:{width:R,height:R},children:[_jsx(ProgressRing,{progress:S/100,size:R,strokeWidth:v,tone:x??"primary",ringColor:f,colorByProgress:"banded"===g&&null==x&&null==f,animated:y,testID:`${M}-ring`,children:_jsx(Avatar,{name:s,source:a,ImageComponent:l,size:n,tone:c,backgroundColor:m,color:d,accessibilityLabel:L.avatar(s)})}),G?_jsx(IconBadge,{dimension:N,fill:"surface",icon:_jsx(AppIcon,{name:"verify",variant:"bold",size:N-2,color:B}),pointerEvents:"none",style:[w.badge,{left:O-N/2,top:O-N/2}],testID:`${M}-complete-badge`}):null]}),_jsxs(View,{style:w.body,children:[_jsx(Text,{variant:"h3",numberOfLines:2,style:V,children:s}),o?_jsx(Text,{variant:"label",color:"tertiary",numberOfLines:1,style:[w.subtitle,A],children:o}):null,i?_jsx(Text,{variant:"body",color:"secondary",style:C,children:i}):null]})]}),null!=_?_jsx(View,{style:w.trailing,children:_}):null]})});ProfileCompletion.displayName="ProfileCompletion";const buildStyles=e=>StyleSheet.create({root:{flexDirection:"row",alignItems:"center",columnGap:e.space.md},summary:{flex:1,flexDirection:"row",alignItems:"center",columnGap:e.space.md},body:{flex:1,rowGap:e.space.xxs},badge:{position:"absolute"},subtitle:{textTransform:"uppercase",letterSpacing:e["letter-spacing"].wide},trailing:{alignSelf:"flex-start"}});export{ProfileCompletion};export default ProfileCompletion;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Avatar}from"../Avatar/index.js";import{FieldLabel,FieldMessage,fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{matchesAccept}from"../FilePicker/FilePicker.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Spinner}from"../Spinner/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PROFILE_PICKER_LABELS=Object.freeze({pick:"Change profile photo",remove:"Remove photo",sheetTitle:"Change photo",errorTooLarge:e=>`The photo is larger than ${e} MB.`,errorWrongType:"That file is not a supported image."});const DEFAULT_ACCEPT=["image/*"],SHEET_ICON_SIZE=20,SOFT_FILL_OPACITY=.14,SIZE_PX={sm:72,md:120,lg:160},clamp=(e,r,o)=>Math.min(o,Math.max(r,e)),toneFor=(e,r)=>{switch(r){case"success":return{base:e.colors.success,on:e.colors["on-success"]};case"warning":return{base:e.colors.warning,on:e.colors["on-warning"]};case"danger":return{base:e.colors.danger,on:e.colors["on-danger"]};case"info":return{base:e.colors.info,on:e.colors["on-info"]};case"neutral":return{base:e.colors["text-muted"],on:e.colors["on-neutral-strong"]};default:return{base:e.colors.primary,on:e.colors["on-primary"]}}},badgeLookFor=(e,r,o)=>{const t=toneFor(e,r),i=t.base,s=e.colors.bg,n="neutral"===r;let l;switch(o){case"soft":l={fill:n?e.colors["bg-muted"]:blendOf(i,.14,s,e.colors["bg-subtle"]),ring:s,icon:i};break;case"outline":l={fill:s,ring:n?e.colors.border:i,icon:i};break;default:l={fill:i,ring:s,icon:t.on}}return l},resolveRadius=(e,r)=>"circle"===e?r/2:"rounded"===e?Math.max(6,Math.round(.22*r)):0,REMOVE_VALUE="__profile-picker-remove__",ProfilePicker=forwardRef((e,r)=>{const{value:o,name:t,sources:i,onPick:s,onRemove:n,loading:l=!1,disabled:a=!1,accept:c=DEFAULT_ACCEPT,maxSizeMB:d,size:u="md",shape:m="circle",badgeIcon:p="camera",tone:g,variant:h,avatarTone:f,avatarBackgroundColor:b,avatarColor:y,label:x,required:v=!1,helperText:k,error:C,layout:I="stacked",title:_,subtitle:j,ImageComponent:P,labels:S,haptic:T,onError:w,accessibilityLabel:E,style:F,testID:A}=e;warnInvalidValue("ProfilePicker","size",e.size,["sm","md","lg"]),warnInvalidValue("ProfilePicker","shape",e.shape,["circle","rounded","square"]),warnInvalidValue("ProfilePicker","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("ProfilePicker","variant",e.variant,["solid","soft","outline"]),warnInvalidValue("ProfilePicker","layout",e.layout,["stacked","inline","profile"]);const L=useTheme(),R=L.settings.components["profile-picker"],V=g??R?.defaultTone??"primary",M=h??R?.defaultVariant??"solid",O=useMemo(()=>badgeLookFor(L,V,M),[L,V,M]),D=f??R?.defaultAvatarTone,H=useMemo(()=>({...DEFAULT_PROFILE_PICKER_LABELS,...S}),[S]),[z,B]=useState(null),[U,$]=useState(null),[q,W]=useState(!1),[Z,G]=useState(o);o!==Z&&(G(o),B(null));const K=l||a,N=z??o??null,X=useMemo(()=>N?{uri:N}:void 0,[N]),Q=C??U??void 0,Y=!K&&(null!==z||Boolean(o)&&Boolean(n)),J=i.length>0||Y,ee=SIZE_PX[u],re=resolveRadius(m,ee),oe=re*(1-Math.SQRT1_2),te=clamp(Math.round(.28*ee),24,44),ie=oe-te/2,se=Math.max(0,-ie),ne=useCallback(e=>{$(e),w?.(e),!1!==T&&triggerHaptic("notificationError")},[w,T]),le=useCallback(async e=>{let r;try{r=await e.pick()}catch(e){return void ne(e instanceof Error?e.message:String(e))}const o=r?.[0];if(!o)return;if("number"==typeof d&&"number"==typeof o.size&&o.size>1024*d*1024)return void ne(H.errorTooLarge(d));if(o.type&&!matchesAccept(o.type,c))return void ne(H.errorWrongType);$(null),B(o.uri);const t=resolveHaptic(T,"selection");t&&triggerHaptic(t),s?.(o)},[d,c,H,T,s,ne]),ae=useCallback(()=>{K||(ue.current=null,1!==i.length||Y?(i.length>0||Y)&&W(!0):le(i[0]))},[K,i,Y,le]),ce=useCallback(()=>{B(null),$(null);const e=resolveHaptic(T,"selection");e&&triggerHaptic(e),n?.()},[T,n]),de=useMemo(()=>{const e=i.map(e=>({kind:"source",source:e}));return Y&&e.push({kind:"remove"}),e},[i,Y]),ue=useRef(null),me=useCallback(e=>{ue.current||(W(!1),"remove"===e.kind?ce():ue.current=e.source)},[ce]),pe=useRef(le);pe.current=le;const ge=useCallback(()=>{const e=ue.current;ue.current=null,e&&pe.current(e)},[]),he=A??"profile-picker",fe=E??(J?H.pick:t),be=_jsx(View,{style:{width:ee,height:ee,marginBottom:se,marginRight:se},children:_jsxs(Pressable,{onPress:ae,disabled:K||!J,accessibilityRole:J?"button":"image",accessibilityLabel:fe,accessibilityHint:fieldTextAsString(Q),accessibilityState:J?{disabled:K,busy:l}:{busy:l},"aria-disabled":J?K:void 0,"aria-busy":l,testID:`${he}-button`,style:({pressed:e})=>[{width:ee,height:ee,borderRadius:re,...smoothCorners},{opacity:a?.55:e?.85:1}],children:[_jsx(View,{importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,pointerEvents:"none",children:_jsx(Avatar,{dimension:ee,shape:m,name:t||void 0,source:X,ImageComponent:P,tone:D,backgroundColor:b,color:y,placeholderIcon:"user"})}),l?_jsx(View,{style:[styles.fill,styles.overlay,{borderRadius:re,...smoothCorners,backgroundColor:L.colors.scrim}],testID:`${he}-loading`,children:_jsx(Spinner,{size:ee>=100?"md":"sm",color:L.colors["on-primary"]})}):null,!a&&J?_jsx(View,{pointerEvents:"none",testID:`${he}-badge`,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,style:[styles.badge,{width:te,height:te,borderRadius:L.radius.pill,...smoothCorners,right:ie,bottom:ie,backgroundColor:O.fill,borderColor:O.ring}],children:renderSlotIcon(p,{color:O.icon,size:Math.round(.55*te),disabled:!1})}):null]})}),ye="stacked"!==I?_jsxs(View,{style:[styles.meta,"profile"===I?styles.metaCentred:null],children:[_?_jsx(Text,{variant:"body",weight:"semibold",style:[styles.title,"profile"===I?styles.textCentred:null],children:_}):null,j?_jsx(Text,{variant:"bodySmall",color:"secondary",style:[styles.subtitle,"profile"===I?styles.textCentred:null,{marginTop:L.space.xxs}],children:j}):null,_jsx(FieldMessage,{text:Q??k,error:hasFieldText(Q)})]}):_jsx(FieldMessage,{text:Q??k,error:hasFieldText(Q)});return _jsxs(View,{ref:r,style:F,testID:A,children:[x?_jsx(FieldLabel,{required:v,children:x}):null,_jsxs(View,{style:"inline"===I?[styles.row,{columnGap:L.space.md}]:["profile"===I?styles.columnCentred:styles.column,{rowGap:L.space.xs}],children:[be,ye]}),_jsx(OptionSheet,{open:q,haptic:T,onClose:()=>W(!1),onAfterClose:ge,title:H.sheetTitle,options:de,getOptionLabel:e=>"remove"===e.kind?H.remove:e.source.label,getOptionValue:e=>"remove"===e.kind?REMOVE_VALUE:e.source.key,destructiveOf:e=>"remove"===e.kind,getOptionDescription:e=>"remove"===e.kind?void 0:e.source.description,getOptionIcon:e=>"remove"===e.kind?_jsx(AppIcon,{name:"trash",size:20,color:L.colors["danger-text"]}):e.source.icon,onChange:(e,r)=>me(r)})]})});ProfilePicker.displayName="ProfilePicker";const styles=StyleSheet.create({fill:{alignItems:"center",justifyContent:"center",overflow:"hidden"},overlay:{...StyleSheet.absoluteFill},badge:{position:"absolute",alignItems:"center",justifyContent:"center",borderWidth:2},row:{flexDirection:"row",alignItems:"center"},column:{alignItems:"flex-start"},columnCentred:{alignItems:"center"},meta:{flexShrink:1},metaCentred:{alignItems:"center"},title:{includeFontPadding:!1},subtitle:{includeFontPadding:!1},textCentred:{textAlign:"center"}});export{ProfilePicker};export default ProfilePicker;
1
+ "use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Avatar}from"../Avatar/index.js";import{FieldLabel,FieldMessage,fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{matchesAccept}from"../FilePicker/FilePicker.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Spinner}from"../Spinner/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PROFILE_PICKER_LABELS=Object.freeze({pick:"Change profile photo",remove:"Remove photo",sheetTitle:"Change photo",errorTooLarge:e=>`The photo is larger than ${e} MB.`,errorWrongType:"That file is not a supported image."});const DEFAULT_ACCEPT=["image/*"],SHEET_ICON_SIZE=20,SOFT_FILL_OPACITY=.14,SIZE_PX={sm:72,md:120,lg:160},clamp=(e,r,t)=>Math.min(t,Math.max(r,e)),toneFor=(e,r)=>{switch(r){case"success":return{base:e.colors.success,on:e.colors["on-success"]};case"warning":return{base:e.colors.warning,on:e.colors["on-warning"]};case"danger":return{base:e.colors.danger,on:e.colors["on-danger"]};case"info":return{base:e.colors.info,on:e.colors["on-info"]};case"neutral":return{base:e.colors["text-muted"],on:e.colors["on-neutral-strong"]};default:return{base:e.colors.primary,on:e.colors["on-primary"]}}},badgeLookFor=(e,r,t)=>{const o=toneFor(e,r),s=o.base,i=e.colors.bg,l="neutral"===r;let n;switch(t){case"soft":n={fill:l?e.colors["bg-muted"]:blendOf(s,.14,i,e.colors["bg-subtle"]),ring:i,icon:s};break;case"outline":n={fill:i,ring:l?e.colors.border:s,icon:s};break;default:n={fill:s,ring:i,icon:o.on}}return n},resolveRadius=(e,r)=>"circle"===e?r/2:"rounded"===e?Math.max(6,Math.round(.22*r)):0,REMOVE_VALUE="__profile-picker-remove__",ProfilePicker=forwardRef((e,r)=>{const{value:t,name:o,sources:s,onPick:i,onRemove:l,loading:n=!1,disabled:a=!1,accept:c=DEFAULT_ACCEPT,maxSizeMB:d,size:u="md",shape:m="circle",badgeIcon:p="camera",tone:g,variant:h,avatarTone:f,avatarBackgroundColor:b,avatarColor:y,label:x,required:k=!1,helperText:v,error:C,layout:_="stacked",title:j,subtitle:P,ImageComponent:S,labels:T,haptic:I,onError:E,accessibilityLabel:F,style:V,testID:A}=e;assertValidValue("ProfilePicker","size",e.size,["sm","md","lg"]),assertValidValue("ProfilePicker","shape",e.shape,["circle","rounded","square"]),assertValidValue("ProfilePicker","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("ProfilePicker","variant",e.variant,["solid","soft","outline"]),assertValidValue("ProfilePicker","layout",e.layout,["stacked","inline","profile"]);const w=useTheme(),L=w.settings.components["profile-picker"],R=g??L?.defaultTone??"primary",M=h??L?.defaultVariant??"solid",O=useMemo(()=>badgeLookFor(w,R,M),[w,R,M]),D=f??L?.defaultAvatarTone,H=useMemo(()=>({...DEFAULT_PROFILE_PICKER_LABELS,...T}),[T]),[z,B]=useState(null),[U,$]=useState(null),[q,W]=useState(!1),[Z,G]=useState(t);t!==Z&&(G(t),B(null));const K=n||a,N=z??t??null,X=useMemo(()=>N?{uri:N}:void 0,[N]),Q=C??U??void 0,Y=!K&&(null!==z||Boolean(t)&&Boolean(l)),J=s.length>0||Y,ee=SIZE_PX[u],re=resolveRadius(m,ee),te=re*(1-Math.SQRT1_2),oe=clamp(Math.round(.28*ee),24,44),se=te-oe/2,ie=Math.max(0,-se),le=useCallback(e=>{$(e),E?.(e),!1!==I&&triggerHaptic("notificationError")},[E,I]),ne=useCallback(async e=>{let r;try{r=await e.pick()}catch(e){return void le(e instanceof Error?e.message:String(e))}const t=r?.[0];if(!t)return;if("number"==typeof d&&"number"==typeof t.size&&t.size>1024*d*1024)return void le(H.errorTooLarge(d));if(t.type&&!matchesAccept(t.type,c))return void le(H.errorWrongType);$(null),B(t.uri);const o=resolveHaptic(I,"selection");o&&triggerHaptic(o),i?.(t)},[d,c,H,I,i,le]),ae=useCallback(()=>{K||(ue.current=null,1!==s.length||Y?(s.length>0||Y)&&W(!0):ne(s[0]))},[K,s,Y,ne]),ce=useCallback(()=>{B(null),$(null);const e=resolveHaptic(I,"selection");e&&triggerHaptic(e),l?.()},[I,l]),de=useMemo(()=>{const e=s.map(e=>({kind:"source",source:e}));return Y&&e.push({kind:"remove"}),e},[s,Y]),ue=useRef(null),me=useCallback(e=>{ue.current||(W(!1),"remove"===e.kind?ce():ue.current=e.source)},[ce]),pe=useRef(ne);pe.current=ne;const ge=useCallback(()=>{const e=ue.current;ue.current=null,e&&pe.current(e)},[]),he=A??"profile-picker",fe=F??(J?H.pick:o),be=_jsx(View,{style:{width:ee,height:ee,marginBottom:ie,marginRight:ie},children:_jsxs(Pressable,{onPress:ae,disabled:K||!J,accessibilityRole:J?"button":"image",accessibilityLabel:fe,accessibilityHint:fieldTextAsString(Q),accessibilityState:J?{disabled:K,busy:n}:{busy:n},"aria-disabled":J?K:void 0,"aria-busy":n,testID:`${he}-button`,style:({pressed:e})=>[{width:ee,height:ee,borderRadius:re,...smoothCorners},{opacity:a?.55:e?.85:1}],children:[_jsx(View,{importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,pointerEvents:"none",children:_jsx(Avatar,{dimension:ee,shape:m,name:o||void 0,source:X,ImageComponent:S,tone:D,backgroundColor:b,color:y,placeholderIcon:"user"})}),n?_jsx(View,{style:[styles.fill,styles.overlay,{borderRadius:re,...smoothCorners,backgroundColor:w.colors.scrim}],testID:`${he}-loading`,children:_jsx(Spinner,{size:ee>=100?"md":"sm",color:w.colors["on-primary"]})}):null,!a&&J?_jsx(View,{pointerEvents:"none",testID:`${he}-badge`,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,style:[styles.badge,{width:oe,height:oe,borderRadius:w.radius.pill,...smoothCorners,right:se,bottom:se,backgroundColor:O.fill,borderColor:O.ring}],children:renderSlotIcon(p,{color:O.icon,size:Math.round(.55*oe),disabled:!1})}):null]})}),ye="stacked"!==_?_jsxs(View,{style:[styles.meta,"profile"===_?styles.metaCentred:null],children:[j?_jsx(Text,{variant:"body",weight:"semibold",style:[styles.title,"profile"===_?styles.textCentred:null],children:j}):null,P?_jsx(Text,{variant:"bodySmall",color:"secondary",style:[styles.subtitle,"profile"===_?styles.textCentred:null,{marginTop:w.space.xxs}],children:P}):null,_jsx(FieldMessage,{text:Q??v,error:hasFieldText(Q)})]}):_jsx(FieldMessage,{text:Q??v,error:hasFieldText(Q)});return _jsxs(View,{ref:r,style:V,testID:A,children:[x?_jsx(FieldLabel,{required:k,children:x}):null,_jsxs(View,{style:"inline"===_?[styles.row,{columnGap:w.space.md}]:["profile"===_?styles.columnCentred:styles.column,{rowGap:w.space.xs}],children:[be,ye]}),_jsx(OptionSheet,{open:q,haptic:I,onClose:()=>W(!1),onAfterClose:ge,title:H.sheetTitle,options:de,getOptionLabel:e=>"remove"===e.kind?H.remove:e.source.label,getOptionValue:e=>"remove"===e.kind?REMOVE_VALUE:e.source.key,destructiveOf:e=>"remove"===e.kind,getOptionDescription:e=>"remove"===e.kind?void 0:e.source.description,getOptionIcon:e=>"remove"===e.kind?_jsx(AppIcon,{name:"trash",size:20,color:w.colors["danger-text"]}):e.source.icon,onChange:(e,r)=>me(r)})]})});ProfilePicker.displayName="ProfilePicker";const styles=StyleSheet.create({fill:{alignItems:"center",justifyContent:"center",overflow:"hidden"},overlay:{...StyleSheet.absoluteFill},badge:{position:"absolute",alignItems:"center",justifyContent:"center",borderWidth:2},row:{flexDirection:"row",alignItems:"center"},column:{alignItems:"flex-start"},columnCentred:{alignItems:"center"},meta:{flexShrink:1},metaCentred:{alignItems:"center"},title:{includeFontPadding:!1},subtitle:{includeFontPadding:!1},textCentred:{textAlign:"center"}});export{ProfilePicker};export default ProfilePicker;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,Gradient,setNativeValue,useTheme}from"../../theme/index.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PROGRESS_BAR_LABELS=Object.freeze({loading:"Loading"});const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},DETERMINATE_ANIMATION_DURATION=400,INDETERMINATE_LOOP_DURATION=1500,INDETERMINATE_WIDTH="30%",GLOW_LOCATIONS=[0,.35,.5,.65,1],glowOf=e=>{const t=tintOf(e,0,"transparent"),r=tintOf(e,.6,e);return{colors:[t,r,e,r,t],locations:GLOW_LOCATIONS,start:{x:0,y:.5},end:{x:1,y:.5}}},clampProgress=e=>"number"!=typeof e||Number.isNaN(e)||e<0?0:e>1?1:e,ProgressBar=forwardRef((e,t)=>{const r=useTheme(),s=useReducedMotion(),{progress:a,label:o,showPercent:i=!1,valueLabel:n,indeterminate:l,height:u=6,radius:c,tone:d="primary",trackColor:m,barColor:g,gradient:p,segments:f,animated:y=!0,style:h,containerStyle:b,barStyle:w,accessibilityLabel:x,labels:R,testID:A}=e;warnInvalidValue("ProgressBar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const _=useMemo(()=>({...DEFAULT_PROGRESS_BAR_LABELS,...R}),[R]),j=l??"number"!=typeof a,E=clampProgress(a),v=useRef(createAnimatedValue(E)).current,V=useRef(createAnimatedValue(0)).current,S=useRef(createAnimatedValue(0)).current,T=useRef(0),N=useMemo(()=>buildStyles(r),[r]),O=c??r.radius.pill,I=m??r.colors["surface-disabled"],L=g??toneColor(r,d),B=useMemo(()=>p?"string"==typeof p?r.settings.gradients[p]??null:p:null,[p,r.settings.gradients]),C=useMemo(()=>glowOf(L),[L]),D=Array.isArray(f)&&f.length>0;useEffect(()=>{j||(y?Animated.timing(v,{toValue:E,duration:400,easing:Easing.bezier(...r.motion.ease["in-out"]),useNativeDriver:!1}).start():v.setValue(E))},[y,E,v,j,r]),useEffect(()=>{if(!j)return;setNativeValue(V,0);const e=Animated.loop(Animated.timing(V,{toValue:1,duration:1500,easing:Easing.inOut(Easing.ease),useNativeDriver:!0}));return e.start(),()=>{e.stop()}},[j,V]);const M=v.interpolate({inputRange:[0,1],outputRange:["0%","100%"]}),P=V.interpolate({inputRange:[0,1],outputRange:[-1,1]}),k=V.interpolate({inputRange:[0,.5,1],outputRange:[.4,1,.4]}),G=i&&!j&&!D,F=null!=o||G||null!=n,U=_jsx(View,{ref:t,accessibilityRole:"progressbar",accessibilityLabel:x??("string"==typeof o?o:void 0),accessibilityValue:j?{text:_.loading}:{min:0,max:100,now:Math.round(100*E)},testID:A,onLayout:e=>{const t=e.nativeEvent.layout.width;T.current=t,setNativeValue(S,t)},style:[N.track,{height:u,borderRadius:O,...smoothCorners,backgroundColor:I},b,h],children:D?_jsx(View,{style:[N.segments,{height:u}],children:(f??[]).map((e,t)=>_jsx(View,{style:{width:100*clampProgress(e.value)+"%",height:u,backgroundColor:e.color??toneColor(r,e.tone??"primary")}},t))}):_jsx(Animated.View,j?{style:[N.indeterminateBar,{height:u,width:s?"100%":"30%",opacity:s?k:1,transform:s?[]:[{translateX:Animated.multiply(P,S)}]},w],children:_jsx(Gradient,{gradient:C,style:StyleSheet.absoluteFill})}:{style:[N.determinateBar,{height:u,borderRadius:O,...smoothCorners,backgroundColor:B?"transparent":L,width:M,overflow:B?"hidden":void 0},w],children:B?_jsx(Gradient,{gradient:B,style:StyleSheet.absoluteFill}):null})});return F?_jsxs(View,{style:N.wrapper,children:[_jsxs(View,{style:[N.labelRow,{marginBottom:r.space.xs}],children:["string"==typeof o||"number"==typeof o?_jsx(Text,{variant:"label",color:"primary",style:N.label,children:o}):_jsx(View,{style:N.label,children:o}),null!=n?"string"==typeof n||"number"==typeof n?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:n}):n:G?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:`${Math.round(100*E)}%`}):null]}),U]}):U});ProgressBar.displayName="ProgressBar";const buildStyles=e=>StyleSheet.create({wrapper:{width:"100%"},labelRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},label:{flexShrink:1},track:{width:"100%",overflow:"hidden"},determinateBar:{position:"absolute",left:0,top:0},indeterminateBar:{position:"absolute",left:0,top:0},segments:{flexDirection:"row",width:"100%"}});export{ProgressBar};export default ProgressBar;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,Gradient,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.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_PROGRESS_BAR_LABELS=Object.freeze({loading:"Loading"});const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},DETERMINATE_ANIMATION_DURATION=400,INDETERMINATE_LOOP_DURATION=1500,INDETERMINATE_WIDTH="30%",GLOW_LOCATIONS=[0,.35,.5,.65,1],glowOf=e=>{const t=tintOf(e,0,"transparent"),r=tintOf(e,.6,e);return{colors:[t,r,e,r,t],locations:GLOW_LOCATIONS,start:{x:0,y:.5},end:{x:1,y:.5}}},clampProgress=e=>"number"!=typeof e||Number.isNaN(e)||e<0?0:e>1?1:e,ProgressBar=forwardRef((e,t)=>{const r=useTheme(),s=useReducedMotion(),{progress:a,label:o,showPercent:i=!1,valueLabel:n,indeterminate:l,height:u=6,radius:c,tone:d="primary",trackColor:m,barColor:g,gradient:p,segments:f,animated:y=!0,style:h,containerStyle:b,barStyle:x,accessibilityLabel:w,labels:R,testID:A}=e;assertValidValue("ProgressBar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const _=useMemo(()=>({...DEFAULT_PROGRESS_BAR_LABELS,...R}),[R]),j=l??"number"!=typeof a,V=clampProgress(a),E=useRef(createAnimatedValue(V)).current,S=useRef(createAnimatedValue(0)).current,T=useRef(createAnimatedValue(0)).current,N=useRef(0),O=useMemo(()=>buildStyles(r),[r]),v=c??r.radius.pill,L=m??r.colors["surface-disabled"],B=g??toneColor(r,d),I=useMemo(()=>p?"string"==typeof p?r.settings.gradients[p]??null:p:null,[p,r.settings.gradients]),C=useMemo(()=>glowOf(B),[B]),D=Array.isArray(f)&&f.length>0;useEffect(()=>{j||(y?Animated.timing(E,{toValue:V,duration:400,easing:Easing.bezier(...r.motion.ease["in-out"]),useNativeDriver:!1}).start():E.setValue(V))},[y,V,E,j,r]),useEffect(()=>{if(!j)return;setNativeValue(S,0);const e=Animated.loop(Animated.timing(S,{toValue:1,duration:1500,easing:Easing.inOut(Easing.ease),useNativeDriver:!0}));return e.start(),()=>{e.stop()}},[j,S]);const M=E.interpolate({inputRange:[0,1],outputRange:["0%","100%"]}),P=S.interpolate({inputRange:[0,1],outputRange:[-1,1]}),k=S.interpolate({inputRange:[0,.5,1],outputRange:[.4,1,.4]}),G=i&&!j&&!D,F=null!=o||G||null!=n,U=_jsx(View,{ref:t,accessibilityRole:"progressbar",accessibilityLabel:w??("string"==typeof o?o:void 0),accessibilityValue:j?{text:_.loading}:{min:0,max:100,now:Math.round(100*V)},testID:A,onLayout:e=>{const t=e.nativeEvent.layout.width;N.current=t,setNativeValue(T,t)},style:[O.track,{height:u,borderRadius:v,...smoothCorners,backgroundColor:L},b,h],children:D?_jsx(View,{style:[O.segments,{height:u}],children:(f??[]).map((e,t)=>_jsx(View,{style:{width:100*clampProgress(e.value)+"%",height:u,backgroundColor:e.color??toneColor(r,e.tone??"primary")}},t))}):_jsx(Animated.View,j?{style:[O.indeterminateBar,{height:u,width:s?"100%":"30%",opacity:s?k:1,transform:s?[]:[{translateX:Animated.multiply(P,T)}]},x],children:_jsx(Gradient,{gradient:C,style:StyleSheet.absoluteFill})}:{style:[O.determinateBar,{height:u,borderRadius:v,...smoothCorners,backgroundColor:I?"transparent":B,width:M,overflow:I?"hidden":void 0},x],children:I?_jsx(Gradient,{gradient:I,style:StyleSheet.absoluteFill}):null})});return F?_jsxs(View,{style:O.wrapper,children:[_jsxs(View,{style:[O.labelRow,{marginBottom:r.space.xs}],children:["string"==typeof o||"number"==typeof o?_jsx(Text,{variant:"label",color:"primary",style:O.label,children:o}):_jsx(View,{style:O.label,children:o}),null!=n?"string"==typeof n||"number"==typeof n?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:n}):n:G?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:`${Math.round(100*V)}%`}):null]}),U]}):U});ProgressBar.displayName="ProgressBar";const buildStyles=e=>StyleSheet.create({wrapper:{width:"100%"},labelRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},label:{flexShrink:1},track:{width:"100%",overflow:"hidden"},determinateBar:{position:"absolute",left:0,top:0},indeterminateBar:{position:"absolute",left:0,top:0},segments:{flexDirection:"row",width:"100%"}});export{ProgressBar};export default ProgressBar;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import Svg,{Circle}from"react-native-svg";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const AnimatedCircle=Animated.createAnimatedComponent(Circle),toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["text-muted"];default:return e.colors.primary}},clampProgress=e=>"number"!=typeof e||Number.isNaN(e)?0:Math.min(1,Math.max(0,e)),DEFAULT_STROKE_WIDTH=4,DEFAULT_DURATION=600,DEFAULT_COLOR_STOPS=[1/3,2/3],STOP_EDGE=1e-4,ProgressRing=forwardRef((e,t)=>{const{progress:r,size:s=48,strokeWidth:o,tone:n="primary",trackColor:i,ringColor:a,colorByProgress:c=!1,animated:l=!0,rounded:u=!0,children:m,accessibilityLabel:d,style:g,testID:f}=e;warnInvalidValue("ProgressRing","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const p=useTheme(),h=useReducedMotion(),y=clampProgress(r),R=o??4,x=i??p.colors["surface-disabled"],[w,b]=DEFAULT_COLOR_STOPS,j=Math.max(0,(s-R)/2),_=2*Math.PI*j,v=useRef(createAnimatedValue(y)).current;useEffect(()=>{if(!l||h)return void v.setValue(y);const e=Animated.timing(v,{toValue:y,duration:600,easing:Easing.bezier(...p.motion.ease["in-out"]),useNativeDriver:!1});return e.start(),()=>e.stop()},[l,y,v,h,p.motion.ease["in-out"]]);const C=v.interpolate({inputRange:[0,1],outputRange:[_,0]}),S=v.interpolate({inputRange:[0,.001,1],outputRange:[0,1,1]}),A=useMemo(()=>v.interpolate({inputRange:[0,w-1e-4,w,b-1e-4,b,1],outputRange:[p.colors.danger,p.colors.danger,p.colors.warning,p.colors.warning,p.colors.success,p.colors.success]}),[v,p.colors.danger,p.colors.warning,p.colors.success]),D=a??(c?A:toneColor(p,n)),P=useMemo(()=>buildStyles(),[]),E=s/2;return _jsxs(View,{ref:t,accessible:null==m,accessibilityRole:"progressbar",accessibilityLabel:d,accessibilityValue:{min:0,max:100,now:Math.round(100*y)},testID:f,style:[P.root,{width:s,height:s},g],children:[_jsxs(Svg,{width:s,height:s,viewBox:`0 0 ${s} ${s}`,children:[_jsx(Circle,{cx:E,cy:E,r:j,stroke:x,strokeWidth:R,fill:"none"}),_jsx(AnimatedCircle,{cx:E,cy:E,r:j,stroke:D,strokeWidth:R,strokeLinecap:u?"round":"butt",strokeDasharray:`${_} ${_}`,strokeDashoffset:C,strokeOpacity:S,fill:"none",transform:`rotate(-90 ${E} ${E})`,testID:f?`${f}-fill`:void 0})]}),null!=m?_jsx(View,{style:P.content,pointerEvents:"box-none",children:m}):null]})});ProgressRing.displayName="ProgressRing";const buildStyles=()=>StyleSheet.create({root:{alignItems:"center",justifyContent:"center"},content:{position:"absolute",top:0,right:0,bottom:0,left:0,alignItems:"center",justifyContent:"center"}});export{ProgressRing};export default ProgressRing;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import Svg,{Circle}from"react-native-svg";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const AnimatedCircle=Animated.createAnimatedComponent(Circle),toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["text-muted"];default:return e.colors.primary}},clampProgress=e=>"number"!=typeof e||Number.isNaN(e)?0:Math.min(1,Math.max(0,e)),DEFAULT_STROKE_WIDTH=4,DEFAULT_DURATION=600,DEFAULT_COLOR_STOPS=[1/3,2/3],STOP_EDGE=1e-4,ProgressRing=forwardRef((e,t)=>{const{progress:r,size:s=48,strokeWidth:o,tone:n="primary",trackColor:i,ringColor:a,colorByProgress:c=!1,animated:l=!0,rounded:u=!0,children:m,accessibilityLabel:d,style:g,testID:f}=e;assertValidValue("ProgressRing","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const p=useTheme(),h=useReducedMotion(),y=clampProgress(r),R=o??4,x=i??p.colors["surface-disabled"],[b,w]=DEFAULT_COLOR_STOPS,j=Math.max(0,(s-R)/2),_=2*Math.PI*j,C=useRef(createAnimatedValue(y)).current;useEffect(()=>{if(!l||h)return void C.setValue(y);const e=Animated.timing(C,{toValue:y,duration:600,easing:Easing.bezier(...p.motion.ease["in-out"]),useNativeDriver:!1});return e.start(),()=>e.stop()},[l,y,C,h,p.motion.ease["in-out"]]);const S=C.interpolate({inputRange:[0,1],outputRange:[_,0]}),V=C.interpolate({inputRange:[0,.001,1],outputRange:[0,1,1]}),A=useMemo(()=>C.interpolate({inputRange:[0,b-1e-4,b,w-1e-4,w,1],outputRange:[p.colors.danger,p.colors.danger,p.colors.warning,p.colors.warning,p.colors.success,p.colors.success]}),[C,p.colors.danger,p.colors.warning,p.colors.success]),D=a??(c?A:toneColor(p,n)),P=useMemo(()=>buildStyles(),[]),E=s/2;return _jsxs(View,{ref:t,accessible:null==m,accessibilityRole:"progressbar",accessibilityLabel:d,accessibilityValue:{min:0,max:100,now:Math.round(100*y)},testID:f,style:[P.root,{width:s,height:s},g],children:[_jsxs(Svg,{width:s,height:s,viewBox:`0 0 ${s} ${s}`,children:[_jsx(Circle,{cx:E,cy:E,r:j,stroke:x,strokeWidth:R,fill:"none"}),_jsx(AnimatedCircle,{cx:E,cy:E,r:j,stroke:D,strokeWidth:R,strokeLinecap:u?"round":"butt",strokeDasharray:`${_} ${_}`,strokeDashoffset:S,strokeOpacity:V,fill:"none",transform:`rotate(-90 ${E} ${E})`,testID:f?`${f}-fill`:void 0})]}),null!=m?_jsx(View,{style:P.content,pointerEvents:"box-none",children:m}):null]})});ProgressRing.displayName="ProgressRing";const buildStyles=()=>StyleSheet.create({root:{alignItems:"center",justifyContent:"center"},content:{position:"absolute",top:0,right:0,bottom:0,left:0,alignItems:"center",justifyContent:"center"}});export{ProgressRing};export default ProgressRing;
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{createContext,forwardRef,useContext,useMemo}from"react";import{Pressable,StyleSheet}from"react-native";import{spaceOf,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"./RadioDot.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const RadioGroupContext=createContext(null);export const useRadioGroup=()=>useContext(RadioGroupContext);const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},Radio=forwardRef((e,t)=>{const{value:r,selected:o,onChange:i,disabled:s=!1,label:a,helperText:l,description:n,error:c,size:d="md",tone:p="primary",accessibilityLabel:u,haptic:m,style:h,containerStyle:x,circleStyle:f,dotStyle:b,labelStyle:y,testID:g,hitSlop:S,...w}=e;warnInvalidValue("Radio","size",e.size,["sm","md","lg"]),warnInvalidValue("Radio","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const R=useTheme(),C=useMemo(()=>buildStyles(R),[R]),j=useRadioGroup();__DEV__&&void 0===r&&Logger.warn("[@webority/mobile-ui] Radio was rendered without a `value`. Selection compares against it, so the group cannot track which option is chosen.");const T=j?j.selectedValue===r:!!o,v=j&&j.disabled||s,D=toneColor(R,p),_=spaceOf(R,R.components.radio["label-gap"]),I=S??6,H=u??fieldTextAsString(a),V="string"==typeof c?c:void 0,k={description:n,helperText:l,error:V},L=!0===j?.error||!0===c||hasFieldText(c);return _jsxs(Pressable,{ref:t,onPress:e=>{if(v)return;const t=resolveHaptic(m,"selection");t&&triggerHaptic(t),j?j.onChange(r):i?.(r)},disabled:v,accessibilityRole:"radio",accessibilityLabel:H,accessibilityHint:w.accessibilityHint??fieldTextAsString(l??n),accessibilityState:{checked:T,disabled:v},"aria-checked":T,"aria-disabled":v,testID:g,hitSlop:I,...hitSlopMarker(I),...w,style:({pressed:e})=>[C.row,hasChoiceDetail(k)?C.rowTop:null,{opacity:v?.55:e?.85:1},x,h],children:[_jsx(RadioDot,{selected:T,color:D,disabled:v&&!T,size:d,style:[!L||T||v?null:{borderColor:R.colors["field-border-error"]},f],dotStyle:b}),_jsx(ChoiceText,{label:a,helperText:l,description:n,error:V,disabled:v,style:{marginLeft:_},labelStyle:y})]})});Radio.displayName="Radio";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"}});export{Radio};export default Radio;
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{createContext,forwardRef,useContext,useMemo}from"react";import{Pressable,StyleSheet}from"react-native";import{spaceOf,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"./RadioDot.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const RadioGroupContext=createContext(null);export const useRadioGroup=()=>useContext(RadioGroupContext);const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},Radio=forwardRef((e,t)=>{const{value:r,selected:o,onChange:i,disabled:s=!1,label:a,helperText:l,description:c,error:n,size:d="md",tone:p="primary",accessibilityLabel:u,haptic:m,style:h,containerStyle:x,circleStyle:f,dotStyle:b,labelStyle:y,testID:g,hitSlop:S,...R}=e;assertValidValue("Radio","size",e.size,["sm","md","lg"]),assertValidValue("Radio","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const w=useTheme(),C=useMemo(()=>buildStyles(w),[w]),j=useRadioGroup();__DEV__&&void 0===r&&Logger.warn("[@webority/mobile-ui] Radio was rendered without a `value`. Selection compares against it, so the group cannot track which option is chosen.");const T=j?j.selectedValue===r:!!o,V=j&&j.disabled||s,D=toneColor(w,p),_=spaceOf(w,w.components.radio["label-gap"]),v=S??6,H=u??fieldTextAsString(a),k="string"==typeof n?n:void 0,L={description:c,helperText:l,error:k},z=!0===j?.error||!0===n||hasFieldText(n);return _jsxs(Pressable,{ref:t,onPress:e=>{if(V)return;const t=resolveHaptic(m,"selection");t&&triggerHaptic(t),j?j.onChange(r):i?.(r)},disabled:V,accessibilityRole:"radio",accessibilityLabel:H,accessibilityHint:R.accessibilityHint??fieldTextAsString(l??c),accessibilityState:{checked:T,disabled:V},"aria-checked":T,"aria-disabled":V,testID:g,hitSlop:v,...hitSlopMarker(v),...R,style:({pressed:e})=>[C.row,hasChoiceDetail(L)?C.rowTop:null,{opacity:V?.55:e?.85:1},x,h],children:[_jsx(RadioDot,{selected:T,color:D,disabled:V&&!T,size:d,style:[!z||T||V?null:{borderColor:w.colors["field-border-error"]},f],dotStyle:b}),_jsx(ChoiceText,{label:a,helperText:l,description:c,error:k,disabled:V,style:{marginLeft:_},labelStyle:y})]})});Radio.displayName="Radio";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"}});export{Radio};export default Radio;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const RATING_SIZES=["sm","md","lg"],RATING_TONES=["primary","success","warning","danger","info","neutral"];export const DEFAULT_RATING_LABELS=Object.freeze({value:(e,t)=>`${e} of ${t} stars`});const sizePxMap={sm:16,md:24,lg:32},resolveSize=e=>sizePxMap[e],PULSE_SCALE=1.2,toneColorFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},clampToStep=(e,t,s)=>{const i=Math.max(0,Math.min(t,e)),n=Math.round(i/s)*s;return Number(n.toFixed(2))},Star=({index:e,filled:t,size:s,filledColor:i,emptyColor:n,scale:a})=>{const r=Math.max(0,Math.min(1,t-e));return _jsxs(Animated.View,{style:[starStyles.starWrap,{width:s,height:s,transform:[{scale:a}]}],children:[_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:n,fontSize:s,lineHeight:s}],accessible:!1,children:"☆"}),r>0?_jsx(View,{pointerEvents:"none",style:[starStyles.fillClip,{width:s*r,height:s}],children:_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:i,fontSize:s,lineHeight:s}],accessible:!1,children:"★"})}):null]})},Rating=forwardRef((e,t)=>{const{value:s,onChange:i,max:n=5,allowHalf:a=!0,readonly:r=!1,size:l="md",tone:o="warning",label:c,loading:m=!1,haptic:u,labels:d,accessibilityLabel:p,style:y,containerStyle:g,starContainerStyle:f,testID:h}=e;warnInvalidValue("Rating","size",e.size,RATING_SIZES),warnInvalidValue("Rating","tone",e.tone,RATING_TONES);const x=useMemo(()=>({...DEFAULT_RATING_LABELS,...d}),[d]),S=useTheme(),b=useMemo(()=>buildStyles(S),[S]),v=!r&&"function"==typeof i,w=a?.5:1,j=resolveSize(l),R=toneColorFor(S,o),_=S.colors.border,A=useRef(j),k=useCallback(e=>{A.current=e.nativeEvent.layout.width},[]),T=useRef(new Map),C=useMemo(()=>{const e=T.current,t=[];for(let s=0;s<n;s+=1){let i=e.get(s);i||(i=new Animated.Value(1),e.set(s,i)),t.push(i)}for(const t of Array.from(e.keys()))t>=n&&e.delete(t);return t},[n]),E=S.settings.components.rating?.pulseOnPress??!1,I=useCallback(e=>{const t=C[e];t&&Animated.sequence([Animated.timing(t,{toValue:1.2,duration:S.motion.duration.fast,easing:Easing.bezier(...S.motion.ease["in-out"]),useNativeDriver:!0}),Animated.spring(t,{toValue:1,damping:S.motion.spring.bouncy.damping,stiffness:S.motion.spring.bouncy.stiffness,mass:S.motion.spring.bouncy.mass,useNativeDriver:!0})]).start()},[S.motion,C]),M=useCallback((e,t)=>{if(!v||!i)return;const s=clampToStep(e,n,w),a=resolveHaptic(u,"selection");a&&triggerHaptic(a),E&&"number"==typeof t&&I(t),i(s)},[v,i,n,w,I,u,E]),V=useCallback(e=>t=>{if(!v)return;const s=A.current||j,i=t.nativeEvent.locationX??s;let n;n=a&&i<s/2?e+.5:e+1,M(n,e)},[v,j,a,M]),z=useCallback(e=>{v&&("increment"===e.nativeEvent.actionName?M(s+w):"decrement"===e.nativeEvent.actionName&&M(s-w))},[v,s,w,M]),N=x.value(s,n),L=p??c??N,P=[];for(let e=0;e<n;e+=1){const t=C[e];if(!t)continue;const i=_jsx(Star,{index:e,filled:s,size:j,filledColor:R,emptyColor:_,scale:t},e);P.push(v?_jsx(Pressable,{onPress:V(e),onLayout:0===e?k:void 0,hitSlop:4,...hitSlopMarker(4),accessible:!1,style:b.starPress,children:i},e):_jsx(View,{onLayout:0===e?k:void 0,style:b.starPress,children:i},e))}const D=_jsxs(View,{style:[b.wrapper,g,y],ref:t,testID:h,children:[c?_jsx(Text,{variant:"bodySmall",color:"secondary",style:b.label,children:c}):null,_jsx(View,{style:[b.row,f],accessible:!0,accessibilityRole:v?"adjustable":"text",accessibilityLabel:L,accessibilityValue:v?{min:0,max:n,now:s,text:N}:void 0,accessibilityActions:v?[{name:"increment"},{name:"decrement"}]:void 0,onAccessibilityAction:v?z:void 0,children:P})]});return m?_jsx(RatingSkeleton,{...e}):D});Rating.displayName="Rating";const RatingSkeleton=({max:e=5,size:t="md",label:s,containerStyle:i,starContainerStyle:n,style:a})=>{const r=useTheme(),l=resolveSize(t),o=Math.max(1,e);return _jsxs(View,{style:[{alignItems:"flex-start"},i,a],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==s?_jsx(Skeleton,{shape:"text",width:80,height:14,style:{marginBottom:r.space.xs}}):null,_jsx(View,{style:[{flexDirection:"row"},n],children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:l,height:l,radius:Math.round(.25*l),style:t<o-1?{marginRight:r.space.xs}:void 0},`sk-star-${t}`))})]})};RatingSkeleton.displayName="RatingSkeleton",Rating.Skeleton=RatingSkeleton;const starStyles=StyleSheet.create({starWrap:{position:"relative",alignItems:"flex-start",justifyContent:"center"},glyph:{textAlign:"left",includeFontPadding:!1},fillClip:{position:"absolute",top:0,left:0,overflow:"hidden"}}),buildStyles=e=>StyleSheet.create({wrapper:{flexDirection:"column"},row:{flexDirection:"row",alignItems:"center"},starPress:{marginRight:e.space.xs},label:{marginBottom:e.space.xs}});export{Rating};export default Rating;
1
+ "use strict";import{forwardRef,useCallback,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const RATING_SIZES=["sm","md","lg"],RATING_TONES=["primary","success","warning","danger","info","neutral"];export const DEFAULT_RATING_LABELS=Object.freeze({value:(e,t)=>`${e} of ${t} stars`});const sizePxMap={sm:16,md:24,lg:32},resolveSize=e=>sizePxMap[e],PULSE_SCALE=1.2,toneColorFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},clampToStep=(e,t,s)=>{const i=Math.max(0,Math.min(t,e)),a=Math.round(i/s)*s;return Number(a.toFixed(2))},Star=({index:e,filled:t,size:s,filledColor:i,emptyColor:a,scale:n})=>{const r=Math.max(0,Math.min(1,t-e));return _jsxs(Animated.View,{style:[starStyles.starWrap,{width:s,height:s,transform:[{scale:n}]}],children:[_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:a,fontSize:s,lineHeight:s}],accessible:!1,children:"☆"}),r>0?_jsx(View,{pointerEvents:"none",style:[starStyles.fillClip,{width:s*r,height:s}],children:_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:i,fontSize:s,lineHeight:s}],accessible:!1,children:"★"})}):null]})},Rating=forwardRef((e,t)=>{const{value:s,onChange:i,max:a=5,allowHalf:n=!0,readonly:r=!1,size:l="md",tone:o="warning",label:c,loading:m=!1,haptic:u,labels:d,accessibilityLabel:p,style:y,containerStyle:g,starContainerStyle:f,testID:h}=e;assertValidValue("Rating","size",e.size,RATING_SIZES),assertValidValue("Rating","tone",e.tone,RATING_TONES);const x=useMemo(()=>({...DEFAULT_RATING_LABELS,...d}),[d]),S=useTheme(),b=useMemo(()=>buildStyles(S),[S]),v=!r&&"function"==typeof i,w=n?.5:1,j=resolveSize(l),R=toneColorFor(S,o),_=S.colors.border,A=useRef(j),k=useCallback(e=>{A.current=e.nativeEvent.layout.width},[]),T=useRef(new Map),V=useMemo(()=>{const e=T.current,t=[];for(let s=0;s<a;s+=1){let i=e.get(s);i||(i=new Animated.Value(1),e.set(s,i)),t.push(i)}for(const t of Array.from(e.keys()))t>=a&&e.delete(t);return t},[a]),C=S.settings.components.rating?.pulseOnPress??!1,E=useCallback(e=>{const t=V[e];t&&Animated.sequence([Animated.timing(t,{toValue:1.2,duration:S.motion.duration.fast,easing:Easing.bezier(...S.motion.ease["in-out"]),useNativeDriver:!0}),Animated.spring(t,{toValue:1,damping:S.motion.spring.bouncy.damping,stiffness:S.motion.spring.bouncy.stiffness,mass:S.motion.spring.bouncy.mass,useNativeDriver:!0})]).start()},[S.motion,V]),M=useCallback((e,t)=>{if(!v||!i)return;const s=clampToStep(e,a,w),n=resolveHaptic(u,"selection");n&&triggerHaptic(n),C&&"number"==typeof t&&E(t),i(s)},[v,i,a,w,E,u,C]),z=useCallback(e=>t=>{if(!v)return;const s=A.current||j,i=t.nativeEvent.locationX??s;let a;a=n&&i<s/2?e+.5:e+1,M(a,e)},[v,j,n,M]),N=useCallback(e=>{v&&("increment"===e.nativeEvent.actionName?M(s+w):"decrement"===e.nativeEvent.actionName&&M(s-w))},[v,s,w,M]),I=x.value(s,a),L=p??c??I,P=[];for(let e=0;e<a;e+=1){const t=V[e];if(!t)continue;const i=_jsx(Star,{index:e,filled:s,size:j,filledColor:R,emptyColor:_,scale:t},e);P.push(v?_jsx(Pressable,{onPress:z(e),onLayout:0===e?k:void 0,hitSlop:4,...hitSlopMarker(4),accessible:!1,style:b.starPress,children:i},e):_jsx(View,{onLayout:0===e?k:void 0,style:b.starPress,children:i},e))}const D=_jsxs(View,{style:[b.wrapper,g,y],ref:t,testID:h,children:[c?_jsx(Text,{variant:"bodySmall",color:"secondary",style:b.label,children:c}):null,_jsx(View,{style:[b.row,f],accessible:!0,accessibilityRole:v?"adjustable":"text",accessibilityLabel:L,accessibilityValue:v?{min:0,max:a,now:s,text:I}:void 0,accessibilityActions:v?[{name:"increment"},{name:"decrement"}]:void 0,onAccessibilityAction:v?N:void 0,children:P})]});return m?_jsx(RatingSkeleton,{...e}):D});Rating.displayName="Rating";const RatingSkeleton=({max:e=5,size:t="md",label:s,containerStyle:i,starContainerStyle:a,style:n})=>{const r=useTheme(),l=resolveSize(t),o=Math.max(1,e);return _jsxs(View,{style:[{alignItems:"flex-start"},i,n],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==s?_jsx(Skeleton,{shape:"text",width:80,height:14,style:{marginBottom:r.space.xs}}):null,_jsx(View,{style:[{flexDirection:"row"},a],children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:l,height:l,radius:Math.round(.25*l),style:t<o-1?{marginRight:r.space.xs}:void 0},`sk-star-${t}`))})]})};RatingSkeleton.displayName="RatingSkeleton",Rating.Skeleton=RatingSkeleton;const starStyles=StyleSheet.create({starWrap:{position:"relative",alignItems:"flex-start",justifyContent:"center"},glyph:{textAlign:"left",includeFontPadding:!1},fillClip:{position:"absolute",top:0,left:0,overflow:"hidden"}}),buildStyles=e=>StyleSheet.create({wrapper:{flexDirection:"column"},row:{flexDirection:"row",alignItems:"center"},starPress:{marginRight:e.space.xs},label:{marginBottom:e.space.xs}});export{Rating};export default Rating;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,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{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{EmptyState}from"../EmptyState/index.js";import{IconButton}from"../IconButton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MIN_FRAME=240,DEFAULT_FRAME=260,MARK_LENGTH=32,MARK_THICKNESS=4,BREATHE_SCALE=1.03,SNAP_SCALE=1.08,T=4,CORNERS=[{key:"tl",style:{top:0,left:0,borderTopWidth:4,borderLeftWidth:4}},{key:"tr",style:{top:0,right:0,borderTopWidth:4,borderRightWidth:4}},{key:"bl",style:{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4}},{key:"br",style:{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4}}];export const DEFAULT_SCANNER_OVERLAY_LABELS=Object.freeze({hint:"Point the camera at the code",found:"Code found",invalid:"This code cannot be used. Try another.",torchOn:"Turn torch on",torchOff:"Turn torch off",manualEntry:"Enter code instead",gallery:"Upload from gallery",noPermissionTitle:"Camera access is off",noPermissionMessage:"Allow camera access to scan a code.",permissionAction:"Allow camera access",noCameraTitle:"No camera found",noCameraMessage:"This device has no camera available. You can still add the code another way."});const ScannerOverlay=forwardRef((e,t)=>{warnInvalidValue("ScannerOverlay","state",e.state,["scanning","found","invalid","noPermission","noCamera"]);const{children:o,state:n="scanning",helperText:i,labels:s,torch:a=!1,onTorchChange:r,onManualEntry:l,onGallery:c,onPermissionAction:d,frameSize:m=DEFAULT_FRAME,haptic:u,style:h,testID:f}=e,p=useTheme(),g=useSafeAreaInsets(),y=useReducedMotion(),x=useMemo(()=>buildStyles(p),[p]),b=useMemo(()=>({...DEFAULT_SCANNER_OVERLAY_LABELS,...s}),[s]),j=i??b.hint,[v,S]=useState({width:0,height:0}),[w,A]=useState(0),E="scanning"===n||"found"===n||"invalid"===n,_=useRef(createAnimatedValue(1)).current,V=p.motion.duration.slower,C=p.motion.duration.default;useEffect(()=>{if(_.setValue(1),y)return;let e;return"scanning"===n&&V>0?e=Animated.loop(Animated.sequence([Animated.timing(_,{toValue:1.03,duration:2*V,useNativeDriver:!0}),Animated.timing(_,{toValue:1,duration:2*V,useNativeDriver:!0})])):"found"===n&&C>0&&(_.setValue(1.08),e=Animated.timing(_,{toValue:1,duration:C,useNativeDriver:!0})),e?.start(),()=>e?.stop()},[n,y,V,C,_]);const R=useRef(n);useEffect(()=>{R.current!==n&&(R.current=n,!1!==u&&("found"===n?triggerHaptic("notificationSuccess"):"invalid"===n&&triggerHaptic("notificationError")))},[n,u]);const{found:M,invalid:I}=b,{noPermissionTitle:L,noPermissionMessage:P}=b,{noCameraTitle:k,noCameraMessage:N}=b;useEffect(()=>{switch(n){case"scanning":announce(j);break;case"found":announce(M);break;case"invalid":announce(I,{polite:!1});break;case"noPermission":announce(`${L}. ${P}`);break;case"noCamera":announce(`${k}. ${N}`)}},[n,j,M,I,L,P,k,N]);const O=Math.max(240,Math.min(m,v.width-2*p.space.xl)),F=(v.width-O)/2,B=Math.max(p.space.md,(v.height-w-O)/2),D=v.width>0&&v.height>0,H={borderColor:"found"===n?p.colors.success:"invalid"===n?p.colors.danger:p.colors["on-scrim"],width:32,height:32},z="found"===n||"invalid"===n?_jsx(View,{style:[x.pill,{backgroundColor:"found"===n?p.colors.success:p.colors.danger}],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:"found"===n?p.colors["on-success"]:p.colors["on-danger"]},children:"found"===n?M:I})}):_jsx(Text,{variant:"bodySmall",align:"center",style:{color:p.colors["on-scrim"]},children:j}),W=E&&null!=r,U=E?"glass":"outline";return _jsxs(View,{ref:t,testID:f,onLayout:e=>{const{width:t,height:o}=e.nativeEvent.layout;S(e=>e.width===t&&e.height===o?e:{width:t,height:o})},style:[x.root,!E&&{backgroundColor:p.colors.bg},h],children:[E?_jsx(View,{style:StyleSheet.absoluteFill,children:o}):null,E&&D?_jsx(_Fragment,{children:_jsxs(View,{pointerEvents:"none",style:StyleSheet.absoluteFill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:[_jsx(View,{style:[x.scrim,{left:0,right:0,top:0,height:B}]}),_jsx(View,{style:[x.scrim,{left:0,right:0,top:B+O,bottom:0}]}),_jsx(View,{style:[x.scrim,{left:0,width:F,top:B,height:O}]}),_jsx(View,{style:[x.scrim,{left:F+O,right:0,top:B,height:O}]}),_jsx(Animated.View,{style:{position:"absolute",left:F,top:B,width:O,height:O,transform:[{scale:_}]},children:CORNERS.map(e=>_jsx(View,{style:[x.mark,H,e.style]},e.key))})]})}):null,E?null:_jsx(View,{style:x.panel,children:_jsx(EmptyState,{fill:!0,icon:_jsx(AppIcon,{name:"noPermission"===n?"camera":"camera-slash",size:48,color:p.colors["text-subtle"]}),title:"noPermission"===n?L:k,description:"noPermission"===n?P:N,action:"noPermission"===n&&d?{label:b.permissionAction,onPress:d}:void 0})}),_jsxs(View,{pointerEvents:"box-none",onLayout:e=>{const{height:t}=e.nativeEvent.layout;A(e=>e===t?e:t)},style:[x.bar,{paddingBottom:Math.max(g.bottom,p.space.md)}],children:[E&&D?_jsx(View,{pointerEvents:"none",style:x.message,children:z}):null,_jsxs(View,{style:x.actions,children:[W?_jsx(IconButton,{icon:a?"flash":"flash-slash",variant:"glass",size:"lg",active:a,haptic:u,accessibilityLabel:a?b.torchOff:b.torchOn,onPress:()=>r?.(!a)}):null,c?_jsx(Button,{label:b.gallery,leftIcon:"gallery",variant:U,tone:"neutral",size:"lg",haptic:u,onPress:c}):null,l?_jsx(Button,{label:b.manualEntry,leftIcon:"keyboard",variant:U,tone:"neutral",size:"lg",haptic:u,onPress:l}):null]})]})]})});ScannerOverlay.displayName="ScannerOverlay";const buildStyles=e=>StyleSheet.create({root:{flex:1,overflow:"hidden"},scrim:{position:"absolute",backgroundColor:e.colors.scrim},mark:{position:"absolute"},message:{alignItems:"center",paddingHorizontal:e.space.xl},pill:{paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners},panel:{...StyleSheet.absoluteFill,justifyContent:"center"},bar:{position:"absolute",left:0,right:0,bottom:0,flexDirection:"column",alignItems:"center",justifyContent:"center",gap:e.space.sm,paddingHorizontal:e.space.md},actions:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"center",gap:e.space.sm}});export{ScannerOverlay};export default ScannerOverlay;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,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{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{EmptyState}from"../EmptyState/index.js";import{IconButton}from"../IconButton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MIN_FRAME=240,DEFAULT_FRAME=260,MARK_LENGTH=32,MARK_THICKNESS=4,BREATHE_SCALE=1.03,SNAP_SCALE=1.08,T=4,CORNERS=[{key:"tl",style:{top:0,left:0,borderTopWidth:4,borderLeftWidth:4}},{key:"tr",style:{top:0,right:0,borderTopWidth:4,borderRightWidth:4}},{key:"bl",style:{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4}},{key:"br",style:{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4}}];export const DEFAULT_SCANNER_OVERLAY_LABELS=Object.freeze({hint:"Point the camera at the code",found:"Code found",invalid:"This code cannot be used. Try another.",torchOn:"Turn torch on",torchOff:"Turn torch off",manualEntry:"Enter code instead",gallery:"Upload from gallery",noPermissionTitle:"Camera access is off",noPermissionMessage:"Allow camera access to scan a code.",permissionAction:"Allow camera access",noCameraTitle:"No camera found",noCameraMessage:"This device has no camera available. You can still add the code another way."});const ScannerOverlay=forwardRef((e,t)=>{assertValidValue("ScannerOverlay","state",e.state,["scanning","found","invalid","noPermission","noCamera"]);const{children:o,state:n="scanning",helperText:i,labels:s,torch:a=!1,onTorchChange:r,onManualEntry:l,onGallery:c,onPermissionAction:d,frameSize:m=DEFAULT_FRAME,haptic:u,style:h,testID:f}=e,p=useTheme(),g=useSafeAreaInsets(),y=useReducedMotion(),x=useMemo(()=>buildStyles(p),[p]),b=useMemo(()=>({...DEFAULT_SCANNER_OVERLAY_LABELS,...s}),[s]),j=i??b.hint,[S,v]=useState({width:0,height:0}),[A,E]=useState(0),_="scanning"===n||"found"===n||"invalid"===n,w=useRef(createAnimatedValue(1)).current,V=p.motion.duration.slower,C=p.motion.duration.default;useEffect(()=>{if(w.setValue(1),y)return;let e;return"scanning"===n&&V>0?e=Animated.loop(Animated.sequence([Animated.timing(w,{toValue:1.03,duration:2*V,useNativeDriver:!0}),Animated.timing(w,{toValue:1,duration:2*V,useNativeDriver:!0})])):"found"===n&&C>0&&(w.setValue(1.08),e=Animated.timing(w,{toValue:1,duration:C,useNativeDriver:!0})),e?.start(),()=>e?.stop()},[n,y,V,C,w]);const R=useRef(n);useEffect(()=>{R.current!==n&&(R.current=n,!1!==u&&("found"===n?triggerHaptic("notificationSuccess"):"invalid"===n&&triggerHaptic("notificationError")))},[n,u]);const{found:M,invalid:L}=b,{noPermissionTitle:I,noPermissionMessage:P}=b,{noCameraTitle:k,noCameraMessage:N}=b;useEffect(()=>{switch(n){case"scanning":announce(j);break;case"found":announce(M);break;case"invalid":announce(L,{polite:!1});break;case"noPermission":announce(`${I}. ${P}`);break;case"noCamera":announce(`${k}. ${N}`)}},[n,j,M,L,I,P,k,N]);const O=Math.max(240,Math.min(m,S.width-2*p.space.xl)),F=(S.width-O)/2,B=Math.max(p.space.md,(S.height-A-O)/2),D=S.width>0&&S.height>0,H={borderColor:"found"===n?p.colors.success:"invalid"===n?p.colors.danger:p.colors["on-scrim"],width:32,height:32},z="found"===n||"invalid"===n?_jsx(View,{style:[x.pill,{backgroundColor:"found"===n?p.colors.success:p.colors.danger}],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:"found"===n?p.colors["on-success"]:p.colors["on-danger"]},children:"found"===n?M:L})}):_jsx(Text,{variant:"bodySmall",align:"center",style:{color:p.colors["on-scrim"]},children:j}),W=_&&null!=r,U=_?"glass":"outline";return _jsxs(View,{ref:t,testID:f,onLayout:e=>{const{width:t,height:o}=e.nativeEvent.layout;v(e=>e.width===t&&e.height===o?e:{width:t,height:o})},style:[x.root,!_&&{backgroundColor:p.colors.bg},h],children:[_?_jsx(View,{style:StyleSheet.absoluteFill,children:o}):null,_&&D?_jsx(_Fragment,{children:_jsxs(View,{pointerEvents:"none",style:StyleSheet.absoluteFill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:[_jsx(View,{style:[x.scrim,{left:0,right:0,top:0,height:B}]}),_jsx(View,{style:[x.scrim,{left:0,right:0,top:B+O,bottom:0}]}),_jsx(View,{style:[x.scrim,{left:0,width:F,top:B,height:O}]}),_jsx(View,{style:[x.scrim,{left:F+O,right:0,top:B,height:O}]}),_jsx(Animated.View,{style:{position:"absolute",left:F,top:B,width:O,height:O,transform:[{scale:w}]},children:CORNERS.map(e=>_jsx(View,{style:[x.mark,H,e.style]},e.key))})]})}):null,_?null:_jsx(View,{style:x.panel,children:_jsx(EmptyState,{fill:!0,icon:_jsx(AppIcon,{name:"noPermission"===n?"camera":"camera-slash",size:48,color:p.colors["text-subtle"]}),title:"noPermission"===n?I:k,description:"noPermission"===n?P:N,action:"noPermission"===n&&d?{label:b.permissionAction,onPress:d}:void 0})}),_jsxs(View,{pointerEvents:"box-none",onLayout:e=>{const{height:t}=e.nativeEvent.layout;E(e=>e===t?e:t)},style:[x.bar,{paddingBottom:Math.max(g.bottom,p.space.md)}],children:[_&&D?_jsx(View,{pointerEvents:"none",style:x.message,children:z}):null,_jsxs(View,{style:x.actions,children:[W?_jsx(IconButton,{icon:a?"flash":"flash-slash",variant:"glass",size:"lg",active:a,haptic:u,accessibilityLabel:a?b.torchOff:b.torchOn,onPress:()=>r?.(!a)}):null,c?_jsx(Button,{label:b.gallery,leftIcon:"gallery",variant:U,tone:"neutral",size:"lg",haptic:u,onPress:c}):null,l?_jsx(Button,{label:b.manualEntry,leftIcon:"keyboard",variant:U,tone:"neutral",size:"lg",haptic:u,onPress:l}):null]})]})]})});ScannerOverlay.displayName="ScannerOverlay";const buildStyles=e=>StyleSheet.create({root:{flex:1,overflow:"hidden"},scrim:{position:"absolute",backgroundColor:e.colors.scrim},mark:{position:"absolute"},message:{alignItems:"center",paddingHorizontal:e.space.xl},pill:{paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners},panel:{...StyleSheet.absoluteFill,justifyContent:"center"},bar:{position:"absolute",left:0,right:0,bottom:0,flexDirection:"column",alignItems:"center",justifyContent:"center",gap:e.space.sm,paddingHorizontal:e.space.md},actions:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"center",gap:e.space.sm}});export{ScannerOverlay};export default ScannerOverlay;