@webority/mobile-ui 0.146.2 → 0.147.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/canvas-kit/kit.js +4344 -4214
  2. package/dist/canvas-kit/manifest.json +1 -1
  3. package/dist/canvas-kit/release.json +5 -5
  4. package/lib/commonjs/components/AuthedImage/authedImageCache.js +1 -1
  5. package/lib/commonjs/components/Avatar/Avatar.js +1 -1
  6. package/lib/commonjs/components/Badge/Badge.js +1 -1
  7. package/lib/commonjs/components/Banner/Banner.js +1 -1
  8. package/lib/commonjs/components/BarChart/BarChart.js +1 -1
  9. package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
  10. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  11. package/lib/commonjs/components/Button/Button.js +1 -1
  12. package/lib/commonjs/components/Calendar/Calendar.js +1 -1
  13. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  14. package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
  15. package/lib/commonjs/components/Confetti/Confetti.js +1 -1
  16. package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
  17. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  18. package/lib/commonjs/components/FieldBase/Chevron.js +1 -1
  19. package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
  20. package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
  21. package/lib/commonjs/components/FormField/FormField.js +1 -1
  22. package/lib/commonjs/components/Input/Input.js +1 -1
  23. package/lib/commonjs/components/LoaderOverlay/LoaderOverlay.js +1 -1
  24. package/lib/commonjs/components/Menu/MenuSurface.js +1 -1
  25. package/lib/commonjs/components/MessageList/MessageList.js +1 -1
  26. package/lib/commonjs/components/Modal/Modal.js +1 -1
  27. package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
  28. package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
  29. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  30. package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
  31. package/lib/commonjs/components/Radio/RadioDot.js +1 -1
  32. package/lib/commonjs/components/Rating/Rating.js +1 -1
  33. package/lib/commonjs/components/RichTextEditor/markdownActions.js +1 -1
  34. package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
  35. package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
  36. package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
  37. package/lib/commonjs/components/SignaturePad/signatureGeometry.js +1 -1
  38. package/lib/commonjs/components/Skeleton/SkeletonClock.js +1 -1
  39. package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
  40. package/lib/commonjs/components/Slider/valueText.js +1 -1
  41. package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
  42. package/lib/commonjs/components/Sparkline/geometry.js +1 -1
  43. package/lib/commonjs/components/Spinner/Spinner.js +1 -1
  44. package/lib/commonjs/components/Stepper/Stepper.js +1 -1
  45. package/lib/commonjs/components/Switch/Switch.js +1 -1
  46. package/lib/commonjs/components/Tabs/Tabs.js +1 -1
  47. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  48. package/lib/commonjs/components/Text/Text.js +1 -1
  49. package/lib/commonjs/components/Toast/Toast.js +1 -1
  50. package/lib/commonjs/components/Toast/ToastProvider.js +1 -1
  51. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  52. package/lib/commonjs/components/Tour/Tour.js +1 -1
  53. package/lib/commonjs/form/path.js +1 -1
  54. package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
  55. package/lib/commonjs/hooks/usePressAnimation.js +1 -1
  56. package/lib/commonjs/network/NetworkStatusBanner.js +1 -1
  57. package/lib/commonjs/theme/animatedValue.js +1 -1
  58. package/lib/commonjs/theme/componentSizes.js +1 -1
  59. package/lib/commonjs/theme/merge.js +1 -1
  60. package/lib/commonjs/theme/toneInk.js +1 -1
  61. package/lib/commonjs/utils/color.js +1 -1
  62. package/lib/commonjs/utils/nativeDriver.js +1 -0
  63. package/lib/module/components/AuthedImage/authedImageCache.js +1 -1
  64. package/lib/module/components/Avatar/Avatar.js +1 -1
  65. package/lib/module/components/Badge/Badge.js +1 -1
  66. package/lib/module/components/Banner/Banner.js +1 -1
  67. package/lib/module/components/BarChart/BarChart.js +1 -1
  68. package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
  69. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  70. package/lib/module/components/Button/Button.js +1 -1
  71. package/lib/module/components/Calendar/Calendar.js +1 -1
  72. package/lib/module/components/Carousel/Carousel.js +1 -1
  73. package/lib/module/components/Checkbox/Checkbox.js +1 -1
  74. package/lib/module/components/Confetti/Confetti.js +1 -1
  75. package/lib/module/components/DatePicker/DatePicker.js +1 -1
  76. package/lib/module/components/Drawer/Drawer.js +1 -1
  77. package/lib/module/components/FieldBase/Chevron.js +1 -1
  78. package/lib/module/components/FilePicker/FilePicker.js +1 -1
  79. package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
  80. package/lib/module/components/FormField/FormField.js +1 -1
  81. package/lib/module/components/Input/Input.js +1 -1
  82. package/lib/module/components/LoaderOverlay/LoaderOverlay.js +1 -1
  83. package/lib/module/components/Menu/MenuSurface.js +1 -1
  84. package/lib/module/components/MessageList/MessageList.js +1 -1
  85. package/lib/module/components/Modal/Modal.js +1 -1
  86. package/lib/module/components/OTPInput/OTPInput.js +1 -1
  87. package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
  88. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  89. package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
  90. package/lib/module/components/Radio/RadioDot.js +1 -1
  91. package/lib/module/components/Rating/Rating.js +1 -1
  92. package/lib/module/components/RichTextEditor/markdownActions.js +1 -1
  93. package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
  94. package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
  95. package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
  96. package/lib/module/components/SignaturePad/signatureGeometry.js +1 -1
  97. package/lib/module/components/Skeleton/SkeletonClock.js +1 -1
  98. package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
  99. package/lib/module/components/Slider/valueText.js +1 -1
  100. package/lib/module/components/Sparkline/Sparkline.js +1 -1
  101. package/lib/module/components/Sparkline/geometry.js +1 -1
  102. package/lib/module/components/Spinner/Spinner.js +1 -1
  103. package/lib/module/components/Stepper/Stepper.js +1 -1
  104. package/lib/module/components/Switch/Switch.js +1 -1
  105. package/lib/module/components/Tabs/Tabs.js +1 -1
  106. package/lib/module/components/TagInput/TagInput.js +1 -1
  107. package/lib/module/components/Text/Text.js +1 -1
  108. package/lib/module/components/Toast/Toast.js +1 -1
  109. package/lib/module/components/Toast/ToastProvider.js +1 -1
  110. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  111. package/lib/module/components/Tour/Tour.js +1 -1
  112. package/lib/module/form/path.js +1 -1
  113. package/lib/module/hooks/useDragToDismiss.js +1 -1
  114. package/lib/module/hooks/usePressAnimation.js +1 -1
  115. package/lib/module/network/NetworkStatusBanner.js +1 -1
  116. package/lib/module/theme/animatedValue.js +1 -1
  117. package/lib/module/theme/componentSizes.js +1 -1
  118. package/lib/module/theme/merge.js +1 -1
  119. package/lib/module/theme/toneInk.js +1 -1
  120. package/lib/module/utils/color.js +1 -1
  121. package/lib/module/utils/nativeDriver.js +1 -0
  122. package/lib/typescript/commonjs/theme/animatedValue.d.ts +1 -1
  123. package/lib/typescript/commonjs/utils/nativeDriver.d.ts +2 -0
  124. package/lib/typescript/module/theme/animatedValue.d.ts +1 -1
  125. package/lib/typescript/module/utils/nativeDriver.d.ts +2 -0
  126. package/package.json +7 -7
@@ -1 +1 @@
1
- "use strict";import{formatDateTime}from"@webority/mobile-core";import{forwardRef,memo,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Modal,PixelRatio,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import Svg,{Path,Rect,Text as SvgText}from"react-native-svg";import{lightTheme,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Button}from"../Button/index.js";import{Input}from"../Input/index.js";import{Text}from"../Text/index.js";import{BASELINE_RATIO,buildSignatureSvg,distanceBetween,FALLBACK_WIDTH,pointOf,strokePath,typedFontSize}from"./signatureGeometry.js";import{writePng}from"./writePng";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SIGNATURE_PAD_LABELS=Object.freeze({pad:"Signature pad",padHint:"Draw with one finger. To sign without drawing, use the type your name action.",caption:"Sign above the line. To start with an up or down stroke, rest your finger a moment first.",typedCaption:"Your typed name is used as your signature.",undo:"Undo",clear:"Clear",typeInstead:"Type your name instead",drawInstead:"Draw instead",typedLabel:"Type your name",typedPlaceholder:"Your full name",empty:"Not signed",signed:"Signed",typingAnnouncement:"Signing by typing your name. Your typed name is used as your signature. Choose Draw instead to sign with your finger.",drawingAnnouncement:"Signing by drawing. Use one finger on the pad.",clearedAnnouncement:"Signature cleared",undoneAnnouncement:"Last stroke removed",emptyError:"Add a signature first.",expand:"Expand",done:"Done",close:"Close"});const STROKE_WIDTH=2.5,SIDEWAYS_TO_DRAW=6,UPRIGHT_TO_SCROLL=8,REST_TO_DRAW_MS=200,MIN_POINT_GAP=.8,DEFAULT_HEIGHT=180,EXPANDED_CHROME=200,DEFAULT_NAME_LENGTH=100,MAX_EXPORT_SCALE=3,MIN_TARGET=44,BASELINE_OPACITY=.3,DISABLED_OPACITY=.5,TARGET_STYLE={minHeight:44},defaultScriptFont=()=>Platform.select({ios:"Snell Roundhand",default:"cursive"}),cssFontStack=e=>"cursive"===e?"cursive":`'${e}', cursive`,useScreenReader=()=>{const[e,t]=useState(!1);return useEffect(()=>{let e=!0;AccessibilityInfo.isScreenReaderEnabled().then(n=>{e&&t(n)});const n=AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,n.remove()}},[]),e},StrokePath=memo(({points:e,color:t})=>_jsx(Path,{d:strokePath(e),stroke:t,strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}));StrokePath.displayName="SignaturePadStroke";const Marks=({mode:e,strokes:t,name:n,color:a,fontFamily:r,width:o,height:i})=>"draw"===e?_jsx(_Fragment,{children:t.map(e=>_jsx(StrokePath,{points:e.points,color:a},e.id))}):n?_jsx(SvgText,{x:o/2,y:i*BASELINE_RATIO,fontSize:typedFontSize(o,n),fontFamily:r,textAnchor:"middle",fill:a,children:n}):null,SignaturePadSurface=forwardRef((e,t)=>{const{expandable:n,initialStrokes:a,onChange:r,initialTypedName:o="",onTypedNameChange:i,defaultMode:s="draw",onModeChange:l,onEmptyChange:d,allowTyped:c=!0,signedBy:u,signedAt:p,height:m=DEFAULT_HEIGHT,maxNameLength:h=DEFAULT_NAME_LENGTH,inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x="selection",disabled:T=!1,style:b,testID:w}=e;assertValidValue("SignaturePad","defaultMode",e.defaultMode,["draw","type"]);const _=useTheme(),E=void 0===g&&void 0===y,A=E?_.colors["text-body"]:g??lightTheme.colors["text-body"],C=E?_.colors.surface:y??lightTheme.colors.surface,R=E?lightTheme.colors["text-body"]:A,v=E?lightTheme.colors.surface:C,I=R!==A||v!==C,j=f??defaultScriptFont(),P=useMemo(()=>({...DEFAULT_SIGNATURE_PAD_LABELS,...S}),[S]),D=useScreenReader(),L=useRef(null),k=useRef(null),[F,M]=useState(0),[G,N]=useState(()=>(a??[]).map((e,t)=>({id:t+1,points:[...e]}))),B=useRef(G),O=useRef(G.length),H=useRef(null),V=useRef(null),[Y,$]=useState(c?s:"draw"),[z,U]=useState(o),[W,K]=useState(null),X=useRef(!1),{height:q}=useWindowDimensions(),[J,Q]=useState(!1),[Z,ee]=useState([]),te=useRef({onChange:r,onTypedNameChange:i,onModeChange:l,onEmptyChange:d});useEffect(()=>{te.current={onChange:r,onTypedNameChange:i,onModeChange:l,onEmptyChange:d}});const ne="draw"===Y&&!T,ae="draw"===Y?0===G.length:0===z.trim().length,re=useRef(null);useEffect(()=>{re.current!==ae&&(re.current=ae,te.current.onEmptyChange?.(ae))},[ae]);const oe=useCallback(e=>{B.current=e,N(e)},[]),ie=useCallback(()=>{K(Date.now()),te.current.onChange?.(B.current.map(e=>e.points))},[]),se=useMemo(()=>{const pan=e=>Gesture.Pan().enabled(ne).runOnJS(!0).onBegin(e=>{H.current=pointOf(e.x,e.y)}).onStart(t=>{V.current=e,O.current+=1;const n=pointOf(t.x,t.y);oe([...B.current,{id:O.current,points:[H.current??n,n]}])}).onUpdate(t=>{if(V.current!==e)return;const n=B.current[B.current.length-1],a=pointOf(t.x,t.y);distanceBetween(n.points[n.points.length-1],a)<.8||oe([...B.current.slice(0,-1),{...n,points:[...n.points,a]}])}).onFinalize(()=>{V.current===e&&(V.current=null,ie())}),e=pan("sideways").activeOffsetX([-6,6]).failOffsetY([-8,8]),t=pan("rested").activateAfterLongPress(200);return Gesture.Race(e,t)},[ne,oe,ie]),le=useCallback(e=>{$(e),te.current.onModeChange?.(e),announce("type"===e?P.typingAnnouncement:P.drawingAnnouncement)},[P.typingAnnouncement,P.drawingAnnouncement]);useEffect(()=>{D&&c&&!X.current&&"draw"===Y&&0===B.current.length&&le("type")},[D,c,Y,le]);const de=useCallback(()=>{X.current=!0,le("draw"===Y?"type":"draw")},[Y,le]),ce=useCallback(e=>{U(e),K(Date.now()),te.current.onTypedNameChange?.(e)},[]),ue=useCallback(()=>{"type"===Y?ce(""):(oe([]),ie()),announce(P.clearedAnnouncement)},[Y,ce,oe,ie,P.clearedAnnouncement]),pe=useCallback(()=>{"draw"===Y&&0!==B.current.length&&(oe(B.current.slice(0,-1)),ie(),announce(P.undoneAnnouncement))},[Y,oe,ie,P.undoneAnnouncement]),me=useCallback(()=>{ee(B.current.map(e=>e.points)),Q(!0)},[]),he=useCallback(()=>{Q(!1)},[]),ge=useCallback(()=>{oe(Z.map(e=>(O.current+=1,{id:O.current,points:[...e]}))),ie(),Q(!1)},[Z,oe,ie]),ye=F||FALLBACK_WIDTH;useImperativeHandle(t,()=>({toFile:()=>new Promise((e,t)=>{if(ae)return void t(new Error(P.emptyError));const n=I?k.current:L.current;if(!n)return void t(new Error("The signature pad is not on screen."));const a=Math.min(3,Math.max(1,PixelRatio.get()));n.toDataURL(n=>{try{e(writePng(n))}catch(e){t(e)}},{width:ye*a,height:m*a})}),toSvg:()=>buildSignatureSvg({width:ye,height:m,mode:Y,strokes:G.map(e=>e.points),typedName:z,ink:R,paper:v,strokeWidth:2.5,fontFamily:cssFontStack(j)}),clear:ue,undo:pe,isEmpty:()=>ae}),[ae,P.emptyError,ye,m,Y,G,z,I,R,v,j,ue,pe]);const fe=useMemo(()=>[{name:"undo",label:P.undo},{name:"clear",label:P.clear},...c?[{name:"toggleMode",label:"draw"===Y?P.typeInstead:P.drawInstead}]:[]],[P.undo,P.clear,P.typeInstead,P.drawInstead,c,Y]),Se=useCallback(e=>{if(T)return;const{actionName:t}=e.nativeEvent;"undo"===t?pe():"clear"===t?ue():"toggleMode"===t&&c&&de()},[T,pe,ue,de,c]),xe=useCallback(e=>{M(e.nativeEvent.layout.width)},[]),Te=useMemo(()=>StyleSheet.create({root:{gap:_.space.sm},pad:{height:m,borderWidth:_.size.border,borderColor:_.colors.border,borderRadius:_.radius.md,...smoothCorners,overflow:"hidden",backgroundColor:C,opacity:T?.5:1},baseline:{position:"absolute",left:_.space.md,right:_.space.md,top:m*BASELINE_RATIO,height:StyleSheet.hairlineWidth,backgroundColor:A,opacity:.3},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:_.space.xs},trailing:{flexDirection:"row",alignItems:"center",gap:_.space.xs},expandedRoot:{flex:1,padding:_.space.md,gap:_.space.sm,backgroundColor:_.colors.bg},expandedBar:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"}}),[_,m,C,A,T]),be=z.trim(),we=p??W,Ee=u&&!ae?`Signed by ${u}${we?`, ${formatDateTime(we)}`:""}`:null,Ae="type"===Y&&be?`${P.pad}. ${be}`:P.pad;return _jsxs(View,{style:[Te.root,b],testID:w,children:[_jsx(GestureDetector,{gesture:se,children:_jsxs(View,{style:Te.pad,onLayout:xe,accessible:!0,accessibilityRole:"image",accessibilityLabel:Ae,accessibilityHint:"draw"===Y?P.padHint:void 0,accessibilityValue:{text:ae?P.empty:P.signed},accessibilityState:{disabled:T},"aria-disabled":T,accessibilityActions:fe,onAccessibilityAction:Se,children:[I?_jsxs(Svg,{ref:k,style:StyleSheet.absoluteFill,width:"100%",height:m,children:[_jsx(Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:v}),_jsx(Marks,{mode:Y,strokes:G,name:be,color:R,fontFamily:j,width:ye,height:m})]}):null,_jsxs(Svg,{ref:L,width:"100%",height:m,children:[_jsx(Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:C}),_jsx(Marks,{mode:Y,strokes:G,name:be,color:A,fontFamily:j,width:ye,height:m})]}),_jsx(View,{pointerEvents:"none",style:Te.baseline})]})}),"type"===Y?_jsx(Input,{label:P.typedLabel,placeholder:P.typedPlaceholder,value:z,onChangeText:ce,maxLength:h,disabled:T,autoComplete:"name",textContentType:"name",autoCapitalize:"words",autoCorrect:!1,returnKeyType:"done",testID:w?`${w}-name`:void 0}):null,_jsx(Text,{variant:"caption",color:"tertiary",children:"draw"===Y?P.caption:P.typedCaption}),_jsxs(View,{style:Te.actions,children:[c?_jsx(Button,{label:"draw"===Y?P.typeInstead:P.drawInstead,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:de,testID:w?`${w}-mode`:void 0}):_jsx(View,{}),"draw"===Y?_jsxs(View,{style:Te.trailing,children:[G.length>0?_jsxs(_Fragment,{children:[_jsx(Button,{label:P.undo,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:pe,testID:w?`${w}-undo`:void 0}),_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:ue,testID:w?`${w}-clear`:void 0})]}):null,n?_jsx(Button,{label:P.expand,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:me,testID:w?`${w}-expand`:void 0}):null]}):null,"type"===Y&&be?_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:ue,testID:w?`${w}-clear`:void 0}):null]}),Ee?_jsx(Text,{variant:"caption",color:"secondary",children:Ee}):null,n?_jsx(Modal,{visible:J,animationType:"slide",presentationStyle:"fullScreen",onRequestClose:he,children:_jsxs(ExpandedRoot,{style:Te.expandedRoot,children:[_jsxs(View,{style:Te.expandedBar,children:[_jsx(Button,{label:P.close,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:he,testID:w?`${w}-close`:void 0}),_jsx(Button,{label:P.done,variant:"solid",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:ge,testID:w?`${w}-done`:void 0})]}),J?_jsx(SignaturePadSurface,{expandable:!1,defaultMode:"draw",allowTyped:!1,initialStrokes:Z,onChange:ee,height:Math.max(DEFAULT_HEIGHT,q-200),inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x,testID:w?`${w}-expanded`:void 0}):null]})}):null]})});SignaturePadSurface.displayName="SignaturePadSurface";const ExpandedRoot="android"===Platform.OS?GestureHandlerRootView:View,SignaturePad=forwardRef((e,t)=>_jsx(SignaturePadSurface,{...e,expandable:!0,ref:t}));SignaturePad.displayName="SignaturePad";export{SignaturePad};export default SignaturePad;
1
+ "use strict";import{formatDateTime}from"@webority/mobile-core";import{forwardRef,memo,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Modal,PixelRatio,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import Svg,{Path,Rect,Text as SvgText}from"react-native-svg";import{lightTheme,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Button}from"../Button/index.js";import{Input}from"../Input/index.js";import{Text}from"../Text/index.js";import{BASELINE_RATIO,buildSignatureSvg,distanceBetween,FALLBACK_WIDTH,pointOf,strokePath,typedFontSize}from"./signatureGeometry.js";import{writePng}from"./writePng";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SIGNATURE_PAD_LABELS=Object.freeze({pad:"Signature pad",padHint:"Draw with one finger. To sign without drawing, use the type your name action.",caption:"Sign above the line. To start with an up or down stroke, rest your finger a moment first.",typedCaption:"Your typed name is used as your signature.",undo:"Undo",clear:"Clear",typeInstead:"Type your name instead",drawInstead:"Draw instead",typedLabel:"Type your name",typedPlaceholder:"Your full name",empty:"Not signed",signed:"Signed",typingAnnouncement:"Signing by typing your name. Your typed name is used as your signature. Choose Draw instead to sign with your finger.",drawingAnnouncement:"Signing by drawing. Use one finger on the pad.",clearedAnnouncement:"Signature cleared",undoneAnnouncement:"Last stroke removed",emptyError:"Add a signature first.",expand:"Expand",done:"Done",close:"Close"});const STROKE_WIDTH=2.5,SIDEWAYS_TO_DRAW=6,UPRIGHT_TO_SCROLL=8,REST_TO_DRAW_MS=200,MIN_POINT_GAP=.8,DEFAULT_HEIGHT=180,EXPANDED_CHROME=200,DEFAULT_NAME_LENGTH=100,MAX_EXPORT_SCALE=3,MIN_TARGET=44,BASELINE_OPACITY=.3,DISABLED_OPACITY=.5,TARGET_STYLE={minHeight:44},defaultScriptFont=()=>Platform.select({ios:"Snell Roundhand",default:"cursive"}),cssFontStack=e=>"cursive"===e?"cursive":`'${e}', cursive`,useScreenReader=()=>{const[e,t]=useState(!1);return useEffect(()=>{let e=!0;AccessibilityInfo.isScreenReaderEnabled().then(n=>{e&&t(n)});const n=AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,n.remove()}},[]),e},StrokePath=memo(({points:e,color:t})=>_jsx(Path,{d:strokePath(e),stroke:t,strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}));StrokePath.displayName="SignaturePadStroke";const Marks=({mode:e,strokes:t,name:n,color:a,fontFamily:r,width:o,height:i})=>"draw"===e?_jsx(_Fragment,{children:t.map(e=>_jsx(StrokePath,{points:e.points,color:a},e.id))}):n?_jsx(SvgText,{x:o/2,y:i*BASELINE_RATIO,fontSize:typedFontSize(o,n),fontFamily:r,textAnchor:"middle",fill:a,children:n}):null,SignaturePadSurface=forwardRef((e,t)=>{const{expandable:n,initialStrokes:a,onChange:r,initialTypedName:o="",onTypedNameChange:i,defaultMode:s="draw",onModeChange:l,onEmptyChange:d,allowTyped:c=!0,signedBy:u,signedAt:p,height:m=DEFAULT_HEIGHT,maxNameLength:h=DEFAULT_NAME_LENGTH,inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x="selection",disabled:T=!1,style:w,testID:b}=e;assertValidValue("SignaturePad","defaultMode",e.defaultMode,["draw","type"]);const _=useTheme(),E=void 0===g&&void 0===y,A=E?_.colors["text-body"]:g??lightTheme.colors["text-body"],C=E?_.colors.surface:y??lightTheme.colors.surface,v=E?lightTheme.colors["text-body"]:A,R=E?lightTheme.colors.surface:C,I=v!==A||R!==C,j=f??defaultScriptFont(),P=useMemo(()=>({...DEFAULT_SIGNATURE_PAD_LABELS,...S}),[S]),D=useScreenReader(),k=useRef(null),L=useRef(null),[F,M]=useState(0),[G,N]=useState(()=>(a??[]).map((e,t)=>({id:t+1,points:[...e]}))),B=useRef(G),O=useRef(G.length),H=useRef(null),V=useRef(null),[Y,$]=useState(c?s:"draw"),[z,U]=useState(o),[W,K]=useState(null),X=useRef(!1),{height:q}=useWindowDimensions(),[J,Q]=useState(!1),[Z,ee]=useState([]),te=useRef({onChange:r,onTypedNameChange:i,onModeChange:l,onEmptyChange:d});useEffect(()=>{te.current={onChange:r,onTypedNameChange:i,onModeChange:l,onEmptyChange:d}});const ne="draw"===Y&&!T,ae="draw"===Y?0===G.length:0===z.trim().length,re=useRef(null);useEffect(()=>{re.current!==ae&&(re.current=ae,te.current.onEmptyChange?.(ae))},[ae]);const oe=useCallback(e=>{B.current=e,N(e)},[]),ie=useCallback(()=>{K(Date.now()),te.current.onChange?.(B.current.map(e=>e.points))},[]),se=useMemo(()=>{const pan=e=>Gesture.Pan().enabled(ne).runOnJS(!0).onBegin(e=>{H.current=pointOf(e.x,e.y)}).onStart(t=>{V.current=e,O.current+=1;const n=pointOf(t.x,t.y);oe([...B.current,{id:O.current,points:[H.current??n,n]}])}).onUpdate(t=>{if(V.current!==e)return;const n=B.current[B.current.length-1];if(void 0===n)throw new Error("The stroke being drawn is missing.");const a=pointOf(t.x,t.y),r=n.points[n.points.length-1];if(void 0===r)throw new Error("A drawn stroke has no points.");distanceBetween(r,a)<.8||oe([...B.current.slice(0,-1),{...n,points:[...n.points,a]}])}).onFinalize(()=>{V.current===e&&(V.current=null,ie())}),e=pan("sideways").activeOffsetX([-6,6]).failOffsetY([-8,8]),t=pan("rested").activateAfterLongPress(200);return Gesture.Race(e,t)},[ne,oe,ie]),le=useCallback(e=>{$(e),te.current.onModeChange?.(e),announce("type"===e?P.typingAnnouncement:P.drawingAnnouncement)},[P.typingAnnouncement,P.drawingAnnouncement]);useEffect(()=>{D&&c&&!X.current&&"draw"===Y&&0===B.current.length&&le("type")},[D,c,Y,le]);const de=useCallback(()=>{X.current=!0,le("draw"===Y?"type":"draw")},[Y,le]),ce=useCallback(e=>{U(e),K(Date.now()),te.current.onTypedNameChange?.(e)},[]),ue=useCallback(()=>{"type"===Y?ce(""):(oe([]),ie()),announce(P.clearedAnnouncement)},[Y,ce,oe,ie,P.clearedAnnouncement]),pe=useCallback(()=>{"draw"===Y&&0!==B.current.length&&(oe(B.current.slice(0,-1)),ie(),announce(P.undoneAnnouncement))},[Y,oe,ie,P.undoneAnnouncement]),me=useCallback(()=>{ee(B.current.map(e=>e.points)),Q(!0)},[]),he=useCallback(()=>{Q(!1)},[]),ge=useCallback(()=>{oe(Z.map(e=>(O.current+=1,{id:O.current,points:[...e]}))),ie(),Q(!1)},[Z,oe,ie]),ye=F||FALLBACK_WIDTH;useImperativeHandle(t,()=>({toFile:()=>new Promise((e,t)=>{if(ae)return void t(new Error(P.emptyError));const n=I?L.current:k.current;if(!n)return void t(new Error("The signature pad is not on screen."));const a=Math.min(3,Math.max(1,PixelRatio.get()));n.toDataURL(n=>{try{e(writePng(n))}catch(e){t(e)}},{width:ye*a,height:m*a})}),toSvg:()=>buildSignatureSvg({width:ye,height:m,mode:Y,strokes:G.map(e=>e.points),typedName:z,ink:v,paper:R,strokeWidth:2.5,fontFamily:cssFontStack(j)}),clear:ue,undo:pe,isEmpty:()=>ae}),[ae,P.emptyError,ye,m,Y,G,z,I,v,R,j,ue,pe]);const fe=useMemo(()=>[{name:"undo",label:P.undo},{name:"clear",label:P.clear},...c?[{name:"toggleMode",label:"draw"===Y?P.typeInstead:P.drawInstead}]:[]],[P.undo,P.clear,P.typeInstead,P.drawInstead,c,Y]),Se=useCallback(e=>{if(T)return;const{actionName:t}=e.nativeEvent;"undo"===t?pe():"clear"===t?ue():"toggleMode"===t&&c&&de()},[T,pe,ue,de,c]),xe=useCallback(e=>{M(e.nativeEvent.layout.width)},[]),Te=useMemo(()=>StyleSheet.create({root:{gap:_.space.sm},pad:{height:m,borderWidth:_.size.border,borderColor:_.colors.border,borderRadius:_.radius.md,...smoothCorners,overflow:"hidden",backgroundColor:C,opacity:T?.5:1},baseline:{position:"absolute",left:_.space.md,right:_.space.md,top:m*BASELINE_RATIO,height:StyleSheet.hairlineWidth,backgroundColor:A,opacity:.3},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:_.space.xs},trailing:{flexDirection:"row",alignItems:"center",gap:_.space.xs},expandedRoot:{flex:1,padding:_.space.md,gap:_.space.sm,backgroundColor:_.colors.bg},expandedBar:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"}}),[_,m,C,A,T]),we=z.trim(),be=p??W,Ee=u&&!ae?`Signed by ${u}${be?`, ${formatDateTime(be)}`:""}`:null,Ae="type"===Y&&we?`${P.pad}. ${we}`:P.pad;return _jsxs(View,{style:[Te.root,w],testID:b,children:[_jsx(GestureDetector,{gesture:se,children:_jsxs(View,{style:Te.pad,onLayout:xe,accessible:!0,accessibilityRole:"image",accessibilityLabel:Ae,accessibilityHint:"draw"===Y?P.padHint:void 0,accessibilityValue:{text:ae?P.empty:P.signed},accessibilityState:{disabled:T},"aria-disabled":T,accessibilityActions:fe,onAccessibilityAction:Se,children:[I?_jsxs(Svg,{ref:L,style:StyleSheet.absoluteFill,width:"100%",height:m,children:[_jsx(Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:R}),_jsx(Marks,{mode:Y,strokes:G,name:we,color:v,fontFamily:j,width:ye,height:m})]}):null,_jsxs(Svg,{ref:k,width:"100%",height:m,children:[_jsx(Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:C}),_jsx(Marks,{mode:Y,strokes:G,name:we,color:A,fontFamily:j,width:ye,height:m})]}),_jsx(View,{pointerEvents:"none",style:Te.baseline})]})}),"type"===Y?_jsx(Input,{label:P.typedLabel,placeholder:P.typedPlaceholder,value:z,onChangeText:ce,maxLength:h,disabled:T,autoComplete:"name",textContentType:"name",autoCapitalize:"words",autoCorrect:!1,returnKeyType:"done",testID:b?`${b}-name`:void 0}):null,_jsx(Text,{variant:"caption",color:"tertiary",children:"draw"===Y?P.caption:P.typedCaption}),_jsxs(View,{style:Te.actions,children:[c?_jsx(Button,{label:"draw"===Y?P.typeInstead:P.drawInstead,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:de,testID:b?`${b}-mode`:void 0}):_jsx(View,{}),"draw"===Y?_jsxs(View,{style:Te.trailing,children:[G.length>0?_jsxs(_Fragment,{children:[_jsx(Button,{label:P.undo,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:pe,testID:b?`${b}-undo`:void 0}),_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:ue,testID:b?`${b}-clear`:void 0})]}):null,n?_jsx(Button,{label:P.expand,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:me,testID:b?`${b}-expand`:void 0}):null]}):null,"type"===Y&&we?_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:ue,testID:b?`${b}-clear`:void 0}):null]}),Ee?_jsx(Text,{variant:"caption",color:"secondary",children:Ee}):null,n?_jsx(Modal,{visible:J,animationType:"slide",presentationStyle:"fullScreen",onRequestClose:he,children:_jsxs(ExpandedRoot,{style:Te.expandedRoot,children:[_jsxs(View,{style:Te.expandedBar,children:[_jsx(Button,{label:P.close,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:he,testID:b?`${b}-close`:void 0}),_jsx(Button,{label:P.done,variant:"solid",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:ge,testID:b?`${b}-done`:void 0})]}),J?_jsx(SignaturePadSurface,{expandable:!1,defaultMode:"draw",allowTyped:!1,initialStrokes:Z,onChange:ee,height:Math.max(DEFAULT_HEIGHT,q-200),inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x,testID:b?`${b}-expanded`:void 0}):null]})}):null]})});SignaturePadSurface.displayName="SignaturePadSurface";const ExpandedRoot="android"===Platform.OS?GestureHandlerRootView:View,SignaturePad=forwardRef((e,t)=>_jsx(SignaturePadSurface,{...e,expandable:!0,ref:t}));SignaturePad.displayName="SignaturePad";export{SignaturePad};export default SignaturePad;
@@ -1 +1 @@
1
- "use strict";export const FALLBACK_WIDTH=320;const MIN_FONT_SIZE=18,MAX_FONT_SIZE=56,SCRIPT_ADVANCE=.5,TYPED_WIDTH_SHARE=.88;export const BASELINE_RATIO=.7;const oneDecimal=t=>Math.round(10*t)/10;export const pointOf=(t,e)=>[oneDecimal(t),oneDecimal(e)];export const distanceBetween=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]);const format=t=>t.toFixed(1);export const strokePath=t=>{if(0===t.length)return"";const[e,...o]=t,r=[`M${format(e[0])} ${format(e[1])}`];if(0===o.length)return r.push(`L${format(e[0])} ${format(e[1])}`),r.join(" ");if(1===o.length)return r.push(`L${format(o[0][0])} ${format(o[0][1])}`),r.join(" ");for(let t=0;t<o.length-1;t+=1){const e=o[t],n=o[t+1],a=(e[0]+n[0])/2,s=(e[1]+n[1])/2;r.push(`Q${format(e[0])} ${format(e[1])} ${format(a)} ${format(s)}`)}const n=o[o.length-1];return r.push(`L${format(n[0])} ${format(n[1])}`),r.join(" ")};export const typedFontSize=(t,e)=>{const o=Math.max(1,e.length),r=Math.floor(.88*t/(.5*o));return Math.min(56,Math.max(18,r))};export const escapeXml=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;");export const buildSignatureSvg=t=>{const{width:e,height:o,mode:r,strokes:n,typedName:a,ink:s,paper:i,strokeWidth:p,fontFamily:c}=t,h=Math.round(e),l=Math.round(o),m=[`<rect x="0" y="0" width="${h}" height="${l}" fill="${escapeXml(i)}"/>`];if("type"===r){const t=a.trim();t&&m.push(`<text x="${h/2}" y="${format(.7*l)}" text-anchor="middle" font-family="${escapeXml(c)}" font-size="${typedFontSize(h,t)}" fill="${escapeXml(s)}">${escapeXml(t)}</text>`)}else for(const t of n)m.push(`<path d="${strokePath(t)}" fill="none" stroke="${escapeXml(s)}" stroke-width="${p}" stroke-linecap="round" stroke-linejoin="round"/>`);return`<svg xmlns="http://www.w3.org/2000/svg" width="${h}" height="${l}" viewBox="0 0 ${h} ${l}">${m.join("")}</svg>`};
1
+ "use strict";export const FALLBACK_WIDTH=320;const MIN_FONT_SIZE=18,MAX_FONT_SIZE=56,SCRIPT_ADVANCE=.5,TYPED_WIDTH_SHARE=.88;export const BASELINE_RATIO=.7;const oneDecimal=t=>Math.round(10*t)/10;export const pointOf=(t,o)=>[oneDecimal(t),oneDecimal(o)];export const distanceBetween=(t,o)=>Math.hypot(t[0]-o[0],t[1]-o[1]);const format=t=>t.toFixed(1);export const strokePath=t=>{const[o,e,...r]=t;if(void 0===o)return"";const n=[`M${format(o[0])} ${format(o[1])}`];if(void 0===e)return n.push(`L${format(o[0])} ${format(o[1])}`),n.join(" ");if(0===r.length)return n.push(`L${format(e[0])} ${format(e[1])}`),n.join(" ");let a=e;for(const t of r){const o=(a[0]+t[0])/2,e=(a[1]+t[1])/2;n.push(`Q${format(a[0])} ${format(a[1])} ${format(o)} ${format(e)}`),a=t}return n.push(`L${format(a[0])} ${format(a[1])}`),n.join(" ")};export const typedFontSize=(t,o)=>{const e=Math.max(1,o.length),r=Math.floor(.88*t/(.5*e));return Math.min(56,Math.max(18,r))};export const escapeXml=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;");export const buildSignatureSvg=t=>{const{width:o,height:e,mode:r,strokes:n,typedName:a,ink:s,paper:i,strokeWidth:c,fontFamily:p}=t,m=Math.round(o),h=Math.round(e),l=[`<rect x="0" y="0" width="${m}" height="${h}" fill="${escapeXml(i)}"/>`];if("type"===r){const t=a.trim();t&&l.push(`<text x="${m/2}" y="${format(.7*h)}" text-anchor="middle" font-family="${escapeXml(p)}" font-size="${typedFontSize(m,t)}" fill="${escapeXml(s)}">${escapeXml(t)}</text>`)}else for(const t of n)l.push(`<path d="${strokePath(t)}" fill="none" stroke="${escapeXml(s)}" stroke-width="${c}" stroke-linecap="round" stroke-linejoin="round"/>`);return`<svg xmlns="http://www.w3.org/2000/svg" width="${m}" height="${h}" viewBox="0 0 ${m} ${h}">${l.join("")}</svg>`};
@@ -1 +1 @@
1
- "use strict";import{createContext,useContext,useEffect,useMemo,useRef}from"react";import{Animated,Easing}from"react-native";import{createAnimatedValue}from"../../theme/index.js";import{jsx as _jsx}from"react/jsx-runtime";const SHIMMER_DURATION={slow:1800,normal:1200,fast:800},PULSE_DURATION=1e3,SkeletonClockContext=createContext(null);export const SkeletonClockProvider=({speed:e,enabled:t,variant:n,children:a})=>{const o=useRef(createAnimatedValue(0)).current,r=useRef(createAnimatedValue(0)).current;useEffect(()=>{if(!t)return o.setValue(0),void r.setValue(.5);const n=Animated.loop(Animated.timing(o,{toValue:1,duration:SHIMMER_DURATION[e],easing:Easing.linear,useNativeDriver:!0})),a=Animated.loop(Animated.sequence([Animated.timing(r,{toValue:1,duration:500,easing:Easing.inOut(Easing.ease),useNativeDriver:!0}),Animated.timing(r,{toValue:0,duration:500,easing:Easing.inOut(Easing.ease),useNativeDriver:!0})]));return n.start(),a.start(),()=>{n.stop(),a.stop()}},[e,t,o,r]);const i=useMemo(()=>({shimmer:o,pulse:r,enabled:t}),[o,r,t]);return _jsx(SkeletonClockContext.Provider,{value:i,children:a})};SkeletonClockProvider.displayName="SkeletonClockProvider";export const useSkeletonClock=()=>{const e=useContext(SkeletonClockContext);return e||fallbackClock};const fallbackClock={shimmer:createAnimatedValue(0),pulse:createAnimatedValue(.5),enabled:!1};
1
+ "use strict";import{createContext,useContext,useEffect,useMemo,useRef}from"react";import{Animated,Easing}from"react-native";import{createAnimatedValue}from"../../theme/index.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{jsx as _jsx}from"react/jsx-runtime";const SHIMMER_DURATION={slow:1800,normal:1200,fast:800},PULSE_DURATION=1e3,SkeletonClockContext=createContext(null);export const SkeletonClockProvider=({speed:e,enabled:t,variant:n,children:a})=>{const r=useRef(createAnimatedValue(0)).current,i=useRef(createAnimatedValue(0)).current;useEffect(()=>{if(!t)return r.setValue(0),void i.setValue(.5);const n=Animated.loop(Animated.timing(r,{toValue:1,duration:SHIMMER_DURATION[e],easing:Easing.linear,useNativeDriver:nativeDriver})),a=Animated.loop(Animated.sequence([Animated.timing(i,{toValue:1,duration:500,easing:Easing.inOut(Easing.ease),useNativeDriver:nativeDriver}),Animated.timing(i,{toValue:0,duration:500,easing:Easing.inOut(Easing.ease),useNativeDriver:nativeDriver})]));return n.start(),a.start(),()=>{n.stop(),a.stop()}},[e,t,r,i]);const o=useMemo(()=>({shimmer:r,pulse:i,enabled:t}),[r,i,t]);return _jsx(SkeletonClockContext.Provider,{value:o,children:a})};SkeletonClockProvider.displayName="SkeletonClockProvider";export const useSkeletonClock=()=>{const e=useContext(SkeletonClockContext);return e||fallbackClock};const fallbackClock={shimmer:createAnimatedValue(0),pulse:createAnimatedValue(.5),enabled:!1};
@@ -1 +1 @@
1
- "use strict";import React,{Children,cloneElement,isValidElement,useEffect,useMemo,useRef}from"react";import{Animated,Image,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Text as LibraryText}from"../Text/index.js";import{DEFAULT_SKELETON_LABELS,Skeleton}from"./Skeleton.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{SkeletonSkip}from"./SkeletonSkip.js";import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";const DEFAULT_REVEAL_FADE_MS=300,flattenStyle=e=>{if(!e)return{};return StyleSheet.flatten(e)??{}},resolveWidth=(e,t)=>"number"==typeof e?e:"string"!=typeof e||"auto"!==e&&"100%"!==e&&!/^\d+(\.\d+)?%$/.test(e)?t:e,resolveRadius=(e,t)=>"number"==typeof e?e:t,skeletonizeNode=(e,t,i,r,n="r")=>{if(null==t||"boolean"==typeof t)return null;if("string"==typeof t||"number"==typeof t)return _jsx(Skeleton,{shape:"text",width:"60%",height:14,variant:i,colors:r},`${n}-text`);if(Array.isArray(t))return Children.map(t,(t,s)=>skeletonizeNode(e,t,i,r,`${n}-${s}`));if(!isValidElement(t))return null;const s=t,o=s.props??{},l=s.type;if(l===SkeletonSkip)return cloneElement(s,{key:`${n}-skip`});if("function"==typeof l||"object"==typeof l){const e=l.Skeleton;if(e){return _jsx(e,{...o},`${n}-self`)}}if(l===Image){const e=flattenStyle(o.style),t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:120,l=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:l,variant:i,colors:r,style:{margin:"number"==typeof e.margin?e.margin:void 0}},`${n}-img`)}if(l===Text||l===LibraryText){const t=flattenStyle(o.style),s="number"==typeof t.fontSize?t.fontSize:e.text.base.size,l=resolveWidth(t.width,"85%");return _jsx(Skeleton,{shape:"text",width:l,height:Math.round(1.15*s),variant:i,colors:r,style:{marginVertical:e.space.xxs}},`${n}-txt`)}if(null!=o.children)return cloneElement(s,{key:`${n}-w`},skeletonizeNode(e,o.children,i,r,`${n}-c`));if(l===View){const e=flattenStyle(o.style);if(null!=e.width||null!=e.height){const t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:20,o=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:o,variant:i,colors:r},`${n}-vw`)}}return cloneElement(s,{key:`${n}-leaf`})},SkeletonContent=e=>{const{loading:t,children:i,placeholder:r,variant:n,count:s=1,colors:o,labels:l,fadeDuration:a,style:u,testID:c}=e;assertValidValue("SkeletonContent","variant",e.variant,["shimmer","pulse","none"]);const d=useTheme(),m=useMemo(()=>({...DEFAULT_SKELETON_LABELS,...l}),[l]),f=useSkeletonDefaults(),h=usePresenceMotion(),y=a??f.fadeDuration??(h.reduced?h.duration("default"):300),p=useRef(t),S=useRef(createAnimatedValue(t?0:1)).current;if(useEffect(()=>{let e;return p.current&&!t?(S.setValue(0),e=Animated.timing(S,{toValue:1,duration:y,useNativeDriver:!0}),e.start()):!p.current&&t&&S.setValue(1),p.current=t,()=>e?.stop()},[t,S,y]),!t)return y<=0?_jsx(_Fragment,{children:i}):_jsx(Animated.View,{style:[u,{opacity:S}],testID:c,children:i});if(void 0!==r){const e=s>1?Array.from({length:s},(e,t)=>_jsx(React.Fragment,{children:r},`sk-ph-${t}`)):r;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:m.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:e})}const b=s>1?Array.from({length:s},(e,t)=>_jsx(React.Fragment,{children:i},`sk-rep-${t}`)):i;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:m.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:skeletonizeNode(d,b,n,o)})};SkeletonContent.displayName="SkeletonContent";export{SkeletonContent};export default SkeletonContent;
1
+ "use strict";import React,{Children,cloneElement,isValidElement,useEffect,useMemo,useRef}from"react";import{Animated,Image,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text as LibraryText}from"../Text/index.js";import{DEFAULT_SKELETON_LABELS,Skeleton}from"./Skeleton.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{SkeletonSkip}from"./SkeletonSkip.js";import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";const DEFAULT_REVEAL_FADE_MS=300,flattenStyle=e=>{if(!e)return{};return StyleSheet.flatten(e)??{}},resolveWidth=(e,t)=>"number"==typeof e?e:"string"!=typeof e||"auto"!==e&&"100%"!==e&&!/^\d+(\.\d+)?%$/.test(e)?t:e,resolveRadius=(e,t)=>"number"==typeof e?e:t,skeletonizeNode=(e,t,i,r,n="r")=>{if(null==t||"boolean"==typeof t)return null;if("string"==typeof t||"number"==typeof t)return _jsx(Skeleton,{shape:"text",width:"60%",height:14,variant:i,colors:r},`${n}-text`);if(Array.isArray(t))return Children.map(t,(t,s)=>skeletonizeNode(e,t,i,r,`${n}-${s}`));if(!isValidElement(t))return null;const s=t,o=s.props??{},l=s.type;if(l===SkeletonSkip)return cloneElement(s,{key:`${n}-skip`});if("function"==typeof l||"object"==typeof l){const e=l.Skeleton;if(e){return _jsx(e,{...o},`${n}-self`)}}if(l===Image){const e=flattenStyle(o.style),t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:120,l=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:l,variant:i,colors:r,style:{margin:"number"==typeof e.margin?e.margin:void 0}},`${n}-img`)}if(l===Text||l===LibraryText){const t=flattenStyle(o.style),s="number"==typeof t.fontSize?t.fontSize:e.text.base.size,l=resolveWidth(t.width,"85%");return _jsx(Skeleton,{shape:"text",width:l,height:Math.round(1.15*s),variant:i,colors:r,style:{marginVertical:e.space.xxs}},`${n}-txt`)}if(null!=o.children)return cloneElement(s,{key:`${n}-w`},skeletonizeNode(e,o.children,i,r,`${n}-c`));if(l===View){const e=flattenStyle(o.style);if(null!=e.width||null!=e.height){const t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:20,o=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:o,variant:i,colors:r},`${n}-vw`)}}return cloneElement(s,{key:`${n}-leaf`})},SkeletonContent=e=>{const{loading:t,children:i,placeholder:r,variant:n,count:s=1,colors:o,labels:l,fadeDuration:a,style:u,testID:c}=e;assertValidValue("SkeletonContent","variant",e.variant,["shimmer","pulse","none"]);const d=useTheme(),m=useMemo(()=>({...DEFAULT_SKELETON_LABELS,...l}),[l]),f=useSkeletonDefaults(),h=usePresenceMotion(),y=a??f.fadeDuration??(h.reduced?h.duration("default"):300),p=useRef(t),S=useRef(createAnimatedValue(t?0:1)).current;if(useEffect(()=>{let e;return p.current&&!t?(S.setValue(0),e=Animated.timing(S,{toValue:1,duration:y,useNativeDriver:nativeDriver}),e.start()):!p.current&&t&&S.setValue(1),p.current=t,()=>e?.stop()},[t,S,y]),!t)return y<=0?_jsx(_Fragment,{children:i}):_jsx(Animated.View,{style:[u,{opacity:S}],testID:c,children:i});if(void 0!==r){const e=s>1?Array.from({length:s},(e,t)=>_jsx(React.Fragment,{children:r},`sk-ph-${t}`)):r;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:m.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:e})}const b=s>1?Array.from({length:s},(e,t)=>_jsx(React.Fragment,{children:i},`sk-rep-${t}`)):i;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:m.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:skeletonizeNode(d,b,n,o)})};SkeletonContent.displayName="SkeletonContent";export{SkeletonContent};export default SkeletonContent;
@@ -1 +1 @@
1
- "use strict";import{memo,useEffect,useRef,useState}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const sliderToneInk=(t,e)=>{switch(e){case"success":return t.colors["on-success"];case"warning":return t.colors["on-warning"];case"danger":return t.colors["on-danger"];case"info":return t.colors["on-info"];case"neutral":return t.colors["on-neutral"];default:return t.colors["on-primary"]}};export const clampValue=(t,e,n)=>Math.min(Math.max(t,e),n);export const snapValue=(t,e,n,r)=>{if(r<=0)return clampValue(t,e,n);const o=String(r).split(".")[1]?.length??0,s=Math.round((t-e)/r)*r+e;return clampValue(o>0?Number(s.toFixed(o)):s,e,n)};export const parseTyped=t=>{const e=t.replace(/[^\d.-]/g,"");if(""===e||"."===e||"-"===e)return null;const n=Number.parseFloat(e);return Number.isFinite(n)?n:null};const easeOutCubic=t=>1-(1-t)**3,roundTo=(t,e)=>{const n=10**e;return Math.round(t*n)/n};export const CountingText=memo(({value:t,format:e,decimals:n=2,duration:r,jumpKey:o="",style:s,testID:l})=>{const[a,i]=useState(t),u=useRef(t),c=useRef(o);return useEffect(()=>{const e=c.current!==o;c.current=o;const n=u.current;if(e||r<=0||n===t)return u.current=t,void i(t);const s=Date.now();let l=0;const tick=()=>{const e=Math.min(1,(Date.now()-s)/r),o=n+(t-n)*easeOutCubic(e);u.current=o,i(o),e<1&&(l=requestAnimationFrame(tick))};return l=requestAnimationFrame(tick),()=>cancelAnimationFrame(l)},[t,o,r]),_jsx(Text,{variant:"caption",weight:"semibold",style:s,testID:l,children:e(roundTo(a,n))})});CountingText.displayName="CountingText";export const useValueDraft=({value:t,min:e,max:n,step:r,format:o,parse:s=parseTyped,onChange:l})=>{const[a,i]=useState(null);return{text:a??o(t),editing:null!==a,onFocus:()=>i(o(t)),onChangeText:t=>{i(t);const r=s(t);null!==r&&l(clampValue(r,e,n))},onBlur:()=>{if(null===a)return;const o=s(a);i(null);const u=snapValue(o??e,e,n,r);u!==t&&l(u)}}};const ROLL_TRAVEL_RATIO=1.2,RollingSlot=memo(({text:t,direction:e,duration:n,style:r,testID:o})=>{const[s,l]=useState(null),a=useRef(t),i=useRef(new Animated.Value(1)).current,u=1.2*(StyleSheet.flatten(r)?.fontSize??14);useEffect(()=>{if(a.current===t)return;const e=a.current;if(a.current=t,n<=0)return void l(null);l(e),i.setValue(0);const r=Animated.timing(i,{toValue:1,duration:n,easing:Easing.out(Easing.cubic),useNativeDriver:!0});return r.start(({finished:t})=>{t&&l(null)}),()=>r.stop()},[t,n,i]);const c="up"===e?-1:1,m=null===s?null:{opacity:i,transform:[{translateY:i.interpolate({inputRange:[0,1],outputRange:[-c*u,0]})}]},p={opacity:i.interpolate({inputRange:[0,1],outputRange:[1,0]}),transform:[{translateY:i.interpolate({inputRange:[0,1],outputRange:[0,c*u]})}]};return _jsxs(View,{style:rollStyles.slot,children:[_jsx(Animated.Text,{style:[r,m],testID:o,children:t}),null!==s?_jsx(Animated.Text,{style:[r,rollStyles.leaving,p],testID:o?`${o}-leaving`:void 0,children:s}):null]})});RollingSlot.displayName="RollingSlot";export const RollingText=memo(({text:t,direction:e="up",duration:n,perCharacter:r=!0,style:o,testID:s})=>{const l=useRef(t),a=r?Math.max(t.length,l.current.length):1;return useEffect(()=>{l.current=t},[t]),_jsx(View,{style:rollStyles.row,testID:s,children:r?Array.from({length:a},(r,l)=>_jsx(RollingSlot,{text:t[l]??"",direction:e,duration:n,style:o,testID:s?`${s}-char`:void 0},l)):_jsx(RollingSlot,{text:t,direction:e,duration:n,style:o,testID:s?`${s}-char`:void 0})})});RollingText.displayName="RollingText";const rollStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"baseline"},slot:{overflow:"hidden"},leaving:{position:"absolute",left:0,top:0}});
1
+ "use strict";import{memo,useEffect,useRef,useState}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const sliderToneInk=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];case"primary":return e.colors["on-primary"]}};export const clampValue=(e,t,n)=>Math.min(Math.max(e,t),n);export const snapValue=(e,t,n,r)=>{if(r<=0)return clampValue(e,t,n);const o=String(r).split(".")[1]?.length??0,s=Math.round((e-t)/r)*r+t;return clampValue(o>0?Number(s.toFixed(o)):s,t,n)};export const parseTyped=e=>{const t=e.replace(/[^\d.-]/g,"");if(""===t||"."===t||"-"===t)return null;const n=Number.parseFloat(t);return Number.isFinite(n)?n:null};const easeOutCubic=e=>1-(1-e)**3,roundTo=(e,t)=>{const n=10**t;return Math.round(e*n)/n};export const CountingText=memo(({value:e,format:t,decimals:n=2,duration:r,jumpKey:o="",style:s,testID:l})=>{const[a,i]=useState(e),u=useRef(e),c=useRef(o);return useEffect(()=>{const t=c.current!==o;c.current=o;const n=u.current;if(t||r<=0||n===e)return u.current=e,void i(e);const s=Date.now();let l=0;const tick=()=>{const t=Math.min(1,(Date.now()-s)/r),o=n+(e-n)*easeOutCubic(t);u.current=o,i(o),t<1&&(l=requestAnimationFrame(tick))};return l=requestAnimationFrame(tick),()=>cancelAnimationFrame(l)},[e,o,r]),_jsx(Text,{variant:"caption",weight:"semibold",style:s,testID:l,children:t(roundTo(a,n))})});CountingText.displayName="CountingText";export const useValueDraft=({value:e,min:t,max:n,step:r,format:o,parse:s=parseTyped,onChange:l})=>{const[a,i]=useState(null);return{text:a??o(e),editing:null!==a,onFocus:()=>i(o(e)),onChangeText:e=>{i(e);const r=s(e);null!==r&&l(clampValue(r,t,n))},onBlur:()=>{if(null===a)return;const o=s(a);i(null);const u=snapValue(o??t,t,n,r);u!==e&&l(u)}}};const ROLL_TRAVEL_RATIO=1.2,RollingSlot=memo(({text:e,direction:t,duration:n,style:r,testID:o})=>{const[s,l]=useState(null),a=useRef(e),i=useRef(new Animated.Value(1)).current,u=1.2*(StyleSheet.flatten(r)?.fontSize??14);useEffect(()=>{if(a.current===e)return;const t=a.current;if(a.current=e,n<=0)return void l(null);l(t),i.setValue(0);const r=Animated.timing(i,{toValue:1,duration:n,easing:Easing.out(Easing.cubic),useNativeDriver:nativeDriver});return r.start(({finished:e})=>{e&&l(null)}),()=>r.stop()},[e,n,i]);const c="up"===t?-1:1,m=null===s?null:{opacity:i,transform:[{translateY:i.interpolate({inputRange:[0,1],outputRange:[-c*u,0]})}]},p={opacity:i.interpolate({inputRange:[0,1],outputRange:[1,0]}),transform:[{translateY:i.interpolate({inputRange:[0,1],outputRange:[0,c*u]})}]};return _jsxs(View,{style:rollStyles.slot,children:[_jsx(Animated.Text,{style:[r,m],testID:o,children:e}),null!==s?_jsx(Animated.Text,{style:[r,rollStyles.leaving,p],testID:o?`${o}-leaving`:void 0,children:s}):null]})});RollingSlot.displayName="RollingSlot";export const RollingText=memo(({text:e,direction:t="up",duration:n,perCharacter:r=!0,style:o,testID:s})=>{const l=useRef(e),a=r?Math.max(e.length,l.current.length):1;return useEffect(()=>{l.current=e},[e]),_jsx(View,{style:rollStyles.row,testID:s,children:r?Array.from({length:a},(r,l)=>_jsx(RollingSlot,{text:e[l]??"",direction:t,duration:n,style:o,testID:s?`${s}-char`:void 0},l)):_jsx(RollingSlot,{text:e,direction:t,duration:n,style:o,testID:s?`${s}-char`:void 0})})});RollingText.displayName="RollingText";const rollStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"baseline"},slot:{overflow:"hidden"},leaving:{position:"absolute",left:0,top:0}});
@@ -1 +1 @@
1
- "use strict";import{formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import Svg,{Circle,Path}from"react-native-svg";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{finiteValues,sparklineGeometry}from"./geometry.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SPARKLINE_LABELS=Object.freeze({noData:"no data",range:(e,t,r,a)=>`from ${e} to ${t}, low ${r}, high ${a}`});const DOT_RADIUS=3,lineColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],defaultFormat=e=>formatNumber(e),Sparkline=forwardRef((e,t)=>{const{data:r,tone:a="primary",color:i,fill:o=!1,highlightLast:s=!0,height:l=32,width:n,strokeWidth:m=2,label:c,formatLabel:u=defaultFormat,accessibilityLabel:h,labels:d,style:f,testID:p}=e;assertValidValue("Sparkline","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const y=useMemo(()=>({...DEFAULT_SPARKLINE_LABELS,...d}),[d]),x=useTheme(),[S,g]=useState(0),b=n??S,k=useCallback(e=>{if(void 0===n){const t=Math.round(e.nativeEvent.layout.width);g(e=>e===t?e:t)}},[n]),$=Math.max(3,m/2)+1,j=useMemo(()=>sparklineGeometry(r,b,l,$),[r,b,l,$]),L=i??lineColor(x,a),v=useMemo(()=>{if(void 0!==h)return h;const e=finiteValues(r),t=c?`${c}, `:"";if(0===e.length)return`${t}${y.noData}`;if(1===e.length)return`${t}${u(e[0])}`;const a=u(e[0]),i=u(e[e.length-1]),o=u(Math.min(...e)),s=u(Math.max(...e));return`${t}${y.range(a,i,o,s)}`},[h,r,u,c,y]);return _jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:v,testID:p,onLayout:k,style:[styles.root,void 0===n?styles.stretch:{width:n},{height:l},f],children:""===j.line?null:_jsxs(Svg,{width:b,height:l,viewBox:`0 0 ${b} ${l}`,children:[o?_jsx(Path,{d:j.area,fill:L,fillOpacity:.14,stroke:"none"}):null,_jsx(Path,{d:j.line,fill:"none",stroke:L,strokeWidth:m,strokeLinecap:"round",strokeLinejoin:"round",testID:p?`${p}-line`:void 0}),s&&j.last?_jsx(Circle,{cx:j.last.x,cy:j.last.y,r:3,fill:L,testID:p?`${p}-dot`:void 0}):null]})})});Sparkline.displayName="Sparkline";const styles=StyleSheet.create({root:{overflow:"hidden"},stretch:{alignSelf:"stretch"}});export{Sparkline};export default Sparkline;
1
+ "use strict";import{formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import Svg,{Circle,Path}from"react-native-svg";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{finiteValues,sparklineGeometry}from"./geometry.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SPARKLINE_LABELS=Object.freeze({noData:"no data",range:(e,t,r,o)=>`from ${e} to ${t}, low ${r}, high ${o}`});const DOT_RADIUS=3,lineColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],defaultFormat=e=>formatNumber(e),Sparkline=forwardRef((e,t)=>{const{data:r,tone:o="primary",color:i,fill:a=!1,highlightLast:s=!0,height:l=32,width:n,strokeWidth:m=2,label:c,formatLabel:u=defaultFormat,accessibilityLabel:h,labels:d,style:f,testID:p}=e;assertValidValue("Sparkline","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const y=useMemo(()=>({...DEFAULT_SPARKLINE_LABELS,...d}),[d]),x=useTheme(),[S,g]=useState(0),v=n??S,k=useCallback(e=>{if(void 0===n){const t=Math.round(e.nativeEvent.layout.width);g(e=>e===t?e:t)}},[n]),w=Math.max(3,m/2)+1,b=useMemo(()=>sparklineGeometry(r,v,l,w),[r,v,l,w]),$=i??lineColor(x,o),j=useMemo(()=>{if(void 0!==h)return h;const e=finiteValues(r),t=c?`${c}, `:"",[o]=e;if(void 0===o)return`${t}${y.noData}`;if(1===e.length)return`${t}${u(o)}`;const i=e[e.length-1];if(void 0===i)throw new Error("A sparkline with two or more finite values has a last value.");const a=u(o),s=u(i),l=u(Math.min(...e)),n=u(Math.max(...e));return`${t}${y.range(a,s,l,n)}`},[h,r,u,c,y]);return _jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:j,testID:p,onLayout:k,style:[styles.root,void 0===n?styles.stretch:{width:n},{height:l},f],children:""===b.line?null:_jsxs(Svg,{width:v,height:l,viewBox:`0 0 ${v} ${l}`,children:[a?_jsx(Path,{d:b.area,fill:$,fillOpacity:.14,stroke:"none"}):null,_jsx(Path,{d:b.line,fill:"none",stroke:$,strokeWidth:m,strokeLinecap:"round",strokeLinejoin:"round",testID:p?`${p}-line`:void 0}),s&&b.last?_jsx(Circle,{cx:b.last.x,cy:b.last.y,r:3,fill:$,testID:p?`${p}-dot`:void 0}):null]})})});Sparkline.displayName="Sparkline";const styles=StyleSheet.create({root:{overflow:"hidden"},stretch:{alignSelf:"stretch"}});export{Sparkline};export default Sparkline;
@@ -1 +1 @@
1
- "use strict";const finite=n=>n.filter(n=>Number.isFinite(n)),round=n=>(Math.round(100*n)/100).toString();export const sparklineGeometry=(n,t,e,r)=>{const i=finite(n);if(0===i.length||t<=0||e<=0)return{line:"",area:"",last:null};const a=Math.min(...i),o=Math.max(...i),u=Math.max(0,t-2*r),l=Math.max(0,e-2*r),s=o-a,h=i.map((n,a)=>({x:1===i.length?t/2:r+a*u/(i.length-1),y:0===s?e/2:r+(o-n)/s*l})),x=h.map((n,t)=>`${0===t?"M":"L"}${round(n.x)} ${round(n.y)}`).join(" "),d=h[0],m=h[h.length-1];return{line:x,area:`${x} L${round(m.x)} ${round(e)} L${round(d.x)} ${round(e)} Z`,last:m}};export const finiteValues=finite;
1
+ "use strict";const finite=t=>t.filter(t=>Number.isFinite(t)),round=t=>(Math.round(100*t)/100).toString();export const sparklineGeometry=(t,n,r,e)=>{const i=finite(t);if(0===i.length||n<=0||r<=0)return{line:"",area:"",last:null};const o=Math.min(...i),a=Math.max(...i),s=Math.max(0,n-2*e),l=Math.max(0,r-2*e),u=a-o,h=i.map((t,o)=>({x:1===i.length?n/2:e+o*s/(i.length-1),y:0===u?r/2:e+(a-t)/u*l})),d=h.map((t,n)=>`${0===n?"M":"L"}${round(t.x)} ${round(t.y)}`).join(" "),x=h[0],m=h[h.length-1];if(void 0===x||void 0===m)throw new Error("A sparkline with values has points to draw.");return{line:d,area:`${d} L${round(m.x)} ${round(r)} L${round(x.x)} ${round(r)} Z`,last:m}};export const finiteValues=finite;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{ActivityIndicator,Animated,Easing,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{squircleHostRadius}from"../../utils/squircle.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SPINNER_LABELS=Object.freeze({loading:"Loading"});const sizeMap={sm:20,md:32,lg:48},CONTAINER_RATIO=1.5,DOT_NAMES=["first","second","third"],DOT_STAGGER_MS=150,DOT_CYCLE_MS=600,DOT_GROW_SCALE=1.4,DOT_PULSE_MIN_OPACITY=.4,Dot=({size:e,color:t,delay:i,duration:n,reduced:s})=>{const r=useTheme(),o=useRef(createAnimatedValue(0)).current;useEffect(()=>{const e=Animated.loop(Animated.sequence([Animated.delay(i),Animated.timing(o,{toValue:1,duration:n/2,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(o,{toValue:0,duration:n/2,easing:Easing.in(Easing.quad),useNativeDriver:!0})]));return e.start(),()=>{e.stop()}},[o,i,n]);const a=useMemo(()=>({grow:o.interpolate({inputRange:[0,1],outputRange:[1,1.4]}),fade:o.interpolate({inputRange:[0,1],outputRange:[.4,1]})}),[o]);return _jsx(Animated.View,{style:{width:e,height:e,borderRadius:r.radius.pill,...smoothCorners,backgroundColor:t,...s?{opacity:a.fade}:{transform:[{scale:a.grow}]}}})},Spinner=forwardRef((e,t)=>{const{size:i="md",color:n,message:s,overlay:r=!1,backdropColor:o,variant:a="circular",accessibilityLabel:l,labels:c,style:u,testID:d}=e;assertValidValue("Spinner","size",e.size,["sm","md","lg"]),assertValidValue("Spinner","variant",e.variant,["circular","dots","contained"]);const m=useMemo(()=>({...DEFAULT_SPINNER_LABELS,...c}),[c]),g="contained"===a,f=r&&!g,p=useTheme(),h=usePresenceMotion(),y=h.duration("default"),b=useRef(createAnimatedValue(0)).current;useEffect(()=>{Animated.timing(b,{toValue:1,duration:y,easing:Easing.bezier(...p.motion.ease["in-out"]),useNativeDriver:!0}).start()},[b,p,y]);const S=useMemo(()=>buildStyles(p),[p]),j=sizeMap[i],x=n??p.colors.primary,_=o??p.colors.scrim,A=useMemo(()=>{if("contained"===a){const e=Math.round(1.5*j);return _jsx(View,{style:[S.container,{width:e,height:e,borderRadius:p.radius.pill,backgroundColor:blendOf(x,.14,p.colors.surface,p.colors["bg-subtle"])}],children:_jsx(ActivityIndicator,{color:x,size:"sm"===i?"small":"large",style:{width:j,height:j}})})}if("dots"===a){const e=Math.max(6,Math.round(j/4));return _jsx(View,{style:[S.dotsRow,{gap:Math.round(e/2)}],children:DOT_NAMES.map((t,i)=>_jsx(Dot,{size:e,color:x,delay:150*i,duration:600,reduced:h.reduced},t))})}return _jsx(ActivityIndicator,{color:x,size:"sm"===i?"small":"large",style:{width:j,height:j}})},[a,i,j,x,S.dotsRow,S.container,h.reduced,p.radius.pill,p.colors.surface,p.colors["bg-subtle"]]),C=l??s??m.loading,R=useRef(C);R.current=C,useEffect(()=>{g&&announce(R.current)},[g]);const v=useSquircle(f,p.radius.lg),E=v.active&&v.size?{borderRadius:squircleHostRadius(v.size.width,v.size.height,p.radius.lg)}:null;let w=S.inlineContent;f?w=S.overlayContent:g&&(w=S.containedContent);const z=_jsxs(Animated.View,{ref:t,accessible:!0,accessibilityRole:"progressbar",accessibilityLiveRegion:g?"none":"polite",accessibilityLabel:C,accessibilityState:{busy:!0},"aria-busy":!0,testID:d,onLayout:v.onLayout,style:[w,E,{opacity:b}],children:[v.active&&v.size?_jsx(SquircleFill,{width:v.size.width,height:v.size.height,radius:p.radius.lg,fill:p.colors.surface}):null,A,s?_jsx(Text,{variant:"body",weight:"medium",style:[S.message,{marginTop:p.space.md}],numberOfLines:2,children:s}):null]});return _jsx(View,f?{pointerEvents:"auto",style:[S.overlay,{backgroundColor:_},u],children:z}:{style:[g?S.containedFill:S.inline,u],children:z})});Spinner.displayName="Spinner";const buildStyles=e=>StyleSheet.create({inline:{alignItems:"center",justifyContent:"center"},inlineContent:{alignItems:"center",justifyContent:"center"},containedFill:{flex:1,alignSelf:"stretch",alignItems:"center",justifyContent:"center",minHeight:Math.round(1.5*sizeMap.lg)+2*e.space.xl},containedContent:{alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},container:{alignItems:"center",justifyContent:"center"},overlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center",zIndex:1e3},overlayContent:{alignItems:"center",justifyContent:"center",backgroundColor:e.colors.surface,borderRadius:e.radius.lg,...smoothCorners,paddingHorizontal:e.space.xl,paddingVertical:e.space.xl,minWidth:140,...e.shadow.popover},dotsRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},message:{textAlign:"center"}});export{Spinner};export default Spinner;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{ActivityIndicator,Animated,Easing,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{squircleHostRadius}from"../../utils/squircle.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SPINNER_LABELS=Object.freeze({loading:"Loading"});const sizeMap={sm:20,md:32,lg:48},CONTAINER_RATIO=1.5,DOT_NAMES=["first","second","third"],DOT_STAGGER_MS=150,DOT_CYCLE_MS=600,DOT_GROW_SCALE=1.4,DOT_PULSE_MIN_OPACITY=.4,Dot=({size:e,color:t,delay:i,duration:r,reduced:n})=>{const s=useTheme(),o=useRef(createAnimatedValue(0)).current;useEffect(()=>{const e=Animated.loop(Animated.sequence([Animated.delay(i),Animated.timing(o,{toValue:1,duration:r/2,easing:Easing.out(Easing.quad),useNativeDriver:nativeDriver}),Animated.timing(o,{toValue:0,duration:r/2,easing:Easing.in(Easing.quad),useNativeDriver:nativeDriver})]));return e.start(),()=>{e.stop()}},[o,i,r]);const a=useMemo(()=>({grow:o.interpolate({inputRange:[0,1],outputRange:[1,1.4]}),fade:o.interpolate({inputRange:[0,1],outputRange:[.4,1]})}),[o]);return _jsx(Animated.View,{style:{width:e,height:e,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:t,...n?{opacity:a.fade}:{transform:[{scale:a.grow}]}}})},Spinner=forwardRef((e,t)=>{const{size:i="md",color:r,message:n,overlay:s=!1,backdropColor:o,variant:a="circular",accessibilityLabel:l,labels:c,style:u,testID:d}=e;assertValidValue("Spinner","size",e.size,["sm","md","lg"]),assertValidValue("Spinner","variant",e.variant,["circular","dots","contained"]);const m=useMemo(()=>({...DEFAULT_SPINNER_LABELS,...c}),[c]),g="contained"===a,f=s&&!g,p=useTheme(),h=usePresenceMotion(),y=h.duration("default"),b=useRef(createAnimatedValue(0)).current;useEffect(()=>{Animated.timing(b,{toValue:1,duration:y,easing:Easing.bezier(...p.motion.ease["in-out"]),useNativeDriver:nativeDriver}).start()},[b,p,y]);const j=useMemo(()=>buildStyles(p),[p]),v=sizeMap[i],S=r??p.colors.primary,x=o??p.colors.scrim,_=useMemo(()=>{if("contained"===a){const e=Math.round(1.5*v);return _jsx(View,{style:[j.container,{width:e,height:e,borderRadius:p.radius.pill,backgroundColor:blendOf(S,.14,p.colors.surface,p.colors["bg-subtle"])}],children:_jsx(ActivityIndicator,{color:S,size:"sm"===i?"small":"large",style:{width:v,height:v}})})}if("dots"===a){const e=Math.max(6,Math.round(v/4));return _jsx(View,{style:[j.dotsRow,{gap:Math.round(e/2)}],children:DOT_NAMES.map((t,i)=>_jsx(Dot,{size:e,color:S,delay:150*i,duration:600,reduced:h.reduced},t))})}return _jsx(ActivityIndicator,{color:S,size:"sm"===i?"small":"large",style:{width:v,height:v}})},[a,i,v,S,j.dotsRow,j.container,h.reduced,p.radius.pill,p.colors.surface,p.colors["bg-subtle"]]),A=l??n??m.loading,C=useRef(A);C.current=A,useEffect(()=>{g&&announce(C.current)},[g]);const R=useSquircle(f,p.radius.lg),E=R.active&&R.size?{borderRadius:squircleHostRadius(R.size.width,R.size.height,p.radius.lg)}:null;let w=j.inlineContent;f?w=j.overlayContent:g&&(w=j.containedContent);const z=_jsxs(Animated.View,{ref:t,accessible:!0,accessibilityRole:"progressbar",accessibilityLiveRegion:g?"none":"polite",accessibilityLabel:A,accessibilityState:{busy:!0},"aria-busy":!0,testID:d,onLayout:R.onLayout,style:[w,E,{opacity:b}],children:[R.active&&R.size?_jsx(SquircleFill,{width:R.size.width,height:R.size.height,radius:p.radius.lg,fill:p.colors.surface}):null,_,n?_jsx(Text,{variant:"body",weight:"medium",style:[j.message,{marginTop:p.space.md}],numberOfLines:2,children:n}):null]});return _jsx(View,f?{pointerEvents:"auto",style:[j.overlay,{backgroundColor:x},u],children:z}:{style:[g?j.containedFill:j.inline,u],children:z})});Spinner.displayName="Spinner";const buildStyles=e=>StyleSheet.create({inline:{alignItems:"center",justifyContent:"center"},inlineContent:{alignItems:"center",justifyContent:"center"},containedFill:{flex:1,alignSelf:"stretch",alignItems:"center",justifyContent:"center",minHeight:Math.round(1.5*sizeMap.lg)+2*e.space.xl},containedContent:{alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},container:{alignItems:"center",justifyContent:"center"},overlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center",zIndex:1e3},overlayContent:{alignItems:"center",justifyContent:"center",backgroundColor:e.colors.surface,borderRadius:e.radius.lg,...smoothCorners,paddingHorizontal:e.space.xl,paddingVertical:e.space.xl,minWidth:140,...e.shadow.popover},dotsRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},message:{textAlign:"center"}});export{Spinner};export default Spinner;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_STEPPER_LABELS=Object.freeze({step:(e,t,s,i)=>`Step ${e} of ${t}, ${s}, ${i}`,statusComplete:"complete",statusActive:"active",statusUpcoming:"upcoming",progressStep:(e,t)=>`Progress: step ${e} of ${t}`,progressDone:(e,t)=>`Progress: ${e} of ${t} steps done`,captionStep:(e,t,s)=>`Step ${e} of ${t}${s?` · ${s}`:""}`,captionDone:(e,t)=>`${e} of ${t} done`});const CIRCLE_SIZE=24,SEGMENT_HEIGHT=4,PULSE_SIZE=32,PULSE_DURATION=1100,toneColorFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},toneOnColorFor=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];default:return e.colors["on-primary"]}},statusWordFor=(e,t)=>{switch(t){case"complete":return e.statusComplete;case"active":return e.statusActive;default:return e.statusUpcoming}},StepCircle=({index:e,step:t,status:s,toneColor:i,upcomingColor:o,upcomingFillColor:r,textOnColor:l,upcomingTextColor:n,interactive:a,canPress:c,totalSteps:u,onPress:p,pulseEnabled:d,labels:m,circleStyles:h,circleSlotStyle:g})=>{const y="active"===s,b=useTheme(),x=useRef(createAnimatedValue(1)).current,S=useRef(createAnimatedValue(.5)).current;useEffect(()=>{if(!y||!d)return x.setValue(1),void S.setValue(0);const e=Animated.loop(Animated.parallel([Animated.sequence([Animated.timing(x,{toValue:1.4,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:!0}),Animated.timing(x,{toValue:1,duration:0,useNativeDriver:!0})]),Animated.sequence([Animated.timing(S,{toValue:0,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:!0}),Animated.timing(S,{toValue:.5,duration:0,useNativeDriver:!0})])]));return e.start(),()=>e.stop()},[y,x,S,d]);const f="upcoming"===s?r:i,w="upcoming"===s?o:i,v="upcoming"===s?n:l,C="complete"===s,j=m.step(e+1,u,t.label,statusWordFor(m,s)),_=_jsxs(View,{style:h.relative,children:[y&&d?_jsx(Animated.View,{pointerEvents:"none",style:[h.pulse,{width:32,height:32,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:i,opacity:S,transform:[{scale:x}]}]}):null,_jsx(View,{style:[h.circle,{width:24,height:24,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:f,borderColor:w},g],children:t.icon?t.icon:_jsx(Text,C?{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:v}],children:"✓"}:{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:v}],children:e+1})})]});return a?_jsx(Pressable,{onPress:()=>p(e),disabled:!c,accessibilityRole:"button",accessibilityLabel:j,accessibilityState:{selected:y,disabled:!c},"aria-selected":y,"aria-disabled":!c,hitSlop:8,...hitSlopMarker(8),children:_}):_jsx(View,{accessibilityRole:"text",accessibilityLabel:j,accessibilityState:{selected:y},"aria-selected":y,children:_})},buildCircleStyles=()=>StyleSheet.create({relative:{alignItems:"center",justifyContent:"center"},pulse:{position:"absolute"},circle:{borderWidth:2,alignItems:"center",justifyContent:"center"},glyph:{includeFontPadding:!1}}),Stepper=forwardRef((e,t)=>{const{steps:s,activeStep:i,defaultActiveStep:o=0,pressMode:r="none",onStepPress:l,onActiveStepChange:n,variant:a="horizontal",tone:c="primary",formatCaption:u,showCaption:p=!0,loading:d=!1,labels:m,accessibilityLabel:h,style:g,containerStyle:y,circleStyle:b,labelStyle:x,connectorStyle:S,haptic:f,testID:w}=e;assertValidValue("Stepper","variant",e.variant,["horizontal","vertical","segmented"]),assertValidValue("Stepper","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Stepper","pressMode",e.pressMode,["none","back","select"]);const v=useMemo(()=>({...DEFAULT_STEPPER_LABELS,...m}),[m]),C=useTheme(),j=C.settings.components.stepper?.pulseAnimation??!1,_=resolveHaptic(f,"selection"),V=useMemo(()=>buildStyles(C),[C]),k=useMemo(()=>buildCircleStyles(),[]),R=toneColorFor(C,c),A=C.colors.border,E=C.colors.bg,L=C.colors["text-muted"],T=toneOnColorFor(C,c),D=s.length,I="none"!==r,P=void 0!==i,[F,$]=useState(o),M=P?i:F,B=null==M||M<0?null:M,O=s.map((e,t)=>(e=>null===B?"upcoming":e<B?"complete":e===B?"active":"upcoming")(t)),N=O.filter(e=>"upcoming"!==e).length,U=O.filter(e=>"complete"===e).length,canPressStatus=e=>"back"===r?"complete"===e:I,handleStepPress=e=>{if(!canPressStatus(O[e]))return;_&&triggerHaptic(_),l?.(e);const t="select"===r&&e===B?null:e;P||$(t),n?.(t)},H=useRef(createAnimatedValue(N)).current,z=useRef(N);useEffect(()=>{const e=z.current;if(e===N)return;z.current=N;const t=Animated.timing(H,{toValue:N,duration:C.motion.duration.default*Math.abs(N-e),easing:Easing.linear,useNativeDriver:!1});return t.start(),()=>t.stop()},[N,H,C.motion]);const sliceOf=e=>H.interpolate({inputRange:[e,e+1],outputRange:["0%","100%"],extrapolate:"clamp"}),W=D<=1?"0%":H.interpolate({inputRange:[1,D],outputRange:["0%","100%"],extrapolate:"clamp"}),G=null!==B&&B<D?B:null,q=h??(null!==G?v.progressStep(G+1,D):v.progressDone(U,D)),[Z,J]=useState(0),K=D>0&&Z>0?Z/(2*D):0,Q=_jsx(View,{ref:t,style:[V.container,y,g],testID:w,accessibilityRole:"progressbar",accessibilityLabel:q,accessibilityValue:{min:0,max:D,now:N},children:"segmented"===a?(()=>{const e=null!==G?s[G]:void 0,t=p?u?u(G,D,e):null!==G?v.captionStep(G+1,D,e?.label):v.captionDone(U,D):"";return _jsxs(View,{children:[p?_jsx(Text,{variant:"bodySmall",style:[V.sCaption,{marginBottom:C.space.sm},x],numberOfLines:1,children:t}):null,_jsx(View,{style:V.sRow,children:s.map((e,t)=>{const s=O[t],i=v.step(t+1,D,e.label,statusWordFor(v,s)),o=_jsx(View,{testID:w?`${w}-segment-${t}`:void 0,style:[V.sTrack,{backgroundColor:A},S],children:_jsx(Animated.View,{style:[V.sFill,{backgroundColor:R,width:sliceOf(t)}]})});if(I){const r=canPressStatus(s);return _jsx(Pressable,{style:V.sItem,onPress:()=>handleStepPress(t),disabled:!r,accessibilityRole:"button",accessibilityLabel:i,accessibilityState:{selected:"active"===s,disabled:!r},"aria-selected":"active"===s,"aria-disabled":!r,hitSlop:{top:12,bottom:12},...hitSlopMarker({top:12,bottom:12}),children:o},e.key)}return _jsx(View,{style:V.sItem,accessibilityRole:"text",accessibilityLabel:i,accessibilityState:{selected:"active"===s},"aria-selected":"active"===s,children:o},e.key)})})]})})():"vertical"===a?_jsx(View,{style:V.vCol,children:s.map((e,t)=>{const s=O[t],i=t===D-1;return _jsxs(View,{style:V.vRow,children:[_jsxs(View,{style:V.vLeft,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:A,upcomingFillColor:E,onPressColor:R,textOnColor:T,upcomingTextColor:L,interactive:I,canPress:canPressStatus(s),totalSteps:D,onPress:handleStepPress,pulseEnabled:j,labels:v,circleStyles:k,circleSlotStyle:b}),i?null:_jsxs(View,{style:[V.vConnectorContainer,S],children:[_jsx(View,{style:[V.vConnectorTrack,{backgroundColor:A}]}),_jsx(Animated.View,{style:[V.vConnectorFill,{backgroundColor:R,height:sliceOf(t+1)}]})]})]}),_jsxs(View,{style:V.vBody,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[V.vLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "}),e.description?_jsx(Text,{variant:"bodySmall",style:V.vDescription,numberOfLines:3,children:e.description}):null]})]},e.key)})}):_jsxs(View,{style:V.hRow,onLayout:e=>J(e.nativeEvent.layout.width),children:[_jsxs(View,{pointerEvents:"none",style:[V.hConnectorContainer,{left:K,right:K},S],children:[_jsx(View,{style:[V.hConnectorTrack,{backgroundColor:A}]}),_jsx(Animated.View,{style:[V.hConnectorFill,{backgroundColor:R,width:W}]})]}),s.map((e,t)=>{const s=O[t];return _jsxs(View,{style:V.hStepItem,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:A,upcomingFillColor:E,onPressColor:R,textOnColor:T,upcomingTextColor:L,interactive:I,canPress:canPressStatus(s),totalSteps:D,onPress:handleStepPress,pulseEnabled:j,labels:v,circleStyles:k,circleSlotStyle:b}),_jsx(Text,{variant:"caption",style:[V.hLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "})]},e.key)})]})});return d?_jsx(StepperSkeleton,{...e}):Q});Stepper.displayName="Stepper";const StepperSkeleton=({steps:e,variant:t="horizontal",showCaption:s=!0,containerStyle:i,style:o,testID:r})=>{const l=useTheme(),n=useMemo(()=>buildStyles(l),[l]),a=useMemo(()=>buildSkeletonStyles(l),[l]),c=e.length||3;return"segmented"===t?_jsxs(View,{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[s?_jsx(Skeleton,{shape:"text",width:"45%",height:14,style:{marginBottom:l.space.sm}}):null,_jsx(View,{style:n.sRow,children:Array.from({length:c}).map((e,t)=>_jsx(View,{style:n.sItem,children:_jsx(Skeleton,{width:"100%",height:4,radius:"pill"})},`sk-step-${t}`))})]}):_jsx(View,"vertical"===t?{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsx(View,{style:a.vCol,children:Array.from({length:c}).map((e,t)=>{const s=t===c-1;return _jsxs(View,{style:a.vRow,children:[_jsxs(View,{style:[a.vLeft,{width:32}],children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),s?null:_jsx(Skeleton,{width:2,height:36})]}),_jsxs(View,{style:a.vBody,children:[_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:l.space.xs}}),_jsx(Skeleton,{shape:"text",width:"80%",height:12})]})]},`sk-step-${t}`)})})}:{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsxs(View,{style:n.hRow,children:[_jsx(View,{pointerEvents:"none",style:[n.hConnectorContainer,{left:50/c+"%",right:50/c+"%"}],children:_jsx(Skeleton,{width:"100%",height:2,radius:"pill"})}),Array.from({length:c}).map((e,t)=>_jsxs(View,{style:n.hStepItem,children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),_jsx(Skeleton,{shape:"text",width:"80%",height:12,style:{marginTop:l.space.xs}})]},`sk-step-${t}`))]})})};StepperSkeleton.displayName="StepperSkeleton",Stepper.Skeleton=StepperSkeleton;const buildSkeletonStyles=e=>StyleSheet.create({vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center"},vBody:{flex:1,paddingLeft:e.space.md,paddingBottom:e.space.lg}}),buildStyles=e=>StyleSheet.create({container:{width:"100%"},hRow:{flexDirection:"row",alignItems:"flex-start",justifyContent:"space-between",position:"relative"},hConnectorContainer:{position:"absolute",top:11,height:2,flexDirection:"row",alignItems:"center"},hConnectorTrack:{position:"absolute",left:0,right:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hConnectorFill:{position:"absolute",left:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hStepItem:{alignItems:"center",flex:1},hLabel:{marginTop:e.space.xs,textAlign:"center"},vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center",alignSelf:"stretch",width:32},vConnectorContainer:{flex:1,width:2,minHeight:32,position:"relative",alignSelf:"center"},vConnectorTrack:{position:"absolute",top:0,bottom:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vConnectorFill:{position:"absolute",top:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vBody:{flex:1,paddingLeft:e.space.sm,paddingBottom:e.space.md},vLabel:{marginBottom:e.space.xxs},vDescription:{},sCaption:{includeFontPadding:!1},sRow:{flexDirection:"row",columnGap:e.space.xs},sItem:{flex:1},sTrack:{height:4,borderRadius:e.radius.pill,overflow:"hidden"},sFill:{height:4,borderRadius:e.radius.pill}});export{Stepper};export default Stepper;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_STEPPER_LABELS=Object.freeze({step:(e,t,s,i)=>`Step ${e} of ${t}, ${s}, ${i}`,statusComplete:"complete",statusActive:"active",statusUpcoming:"upcoming",progressStep:(e,t)=>`Progress: step ${e} of ${t}`,progressDone:(e,t)=>`Progress: ${e} of ${t} steps done`,captionStep:(e,t,s)=>`Step ${e} of ${t}${s?` · ${s}`:""}`,captionDone:(e,t)=>`${e} of ${t} done`});const CIRCLE_SIZE=24,SEGMENT_HEIGHT=4,PULSE_SIZE=32,PULSE_DURATION=1100,toneColorFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;case"primary":return e.colors.primary}},toneOnColorFor=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];case"primary":return e.colors["on-primary"]}},statusWordFor=(e,t)=>{switch(t){case"complete":return e.statusComplete;case"active":return e.statusActive;case"upcoming":return e.statusUpcoming}},StepCircle=({index:e,step:t,status:s,toneColor:i,upcomingColor:o,upcomingFillColor:r,textOnColor:l,upcomingTextColor:n,interactive:a,canPress:c,totalSteps:p,onPress:u,pulseEnabled:d,labels:m,circleStyles:h,circleSlotStyle:g})=>{const y="active"===s,b=useTheme(),x=useRef(createAnimatedValue(1)).current,S=useRef(createAnimatedValue(.5)).current;useEffect(()=>{if(!y||!d)return x.setValue(1),void S.setValue(0);const e=Animated.loop(Animated.parallel([Animated.sequence([Animated.timing(x,{toValue:1.4,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:nativeDriver}),Animated.timing(x,{toValue:1,duration:0,useNativeDriver:nativeDriver})]),Animated.sequence([Animated.timing(S,{toValue:0,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:nativeDriver}),Animated.timing(S,{toValue:.5,duration:0,useNativeDriver:nativeDriver})])]));return e.start(),()=>e.stop()},[y,x,S,d]);const v="upcoming"===s?r:i,f="upcoming"===s?o:i,w="upcoming"===s?n:l,C="complete"===s,j=m.step(e+1,p,t.label,statusWordFor(m,s)),_=_jsxs(View,{style:h.relative,children:[y&&d?_jsx(Animated.View,{pointerEvents:"none",style:[h.pulse,{width:32,height:32,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:i,opacity:S,transform:[{scale:x}]}]}):null,_jsx(View,{style:[h.circle,{width:24,height:24,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:v,borderColor:f},g],children:t.icon?t.icon:_jsx(Text,C?{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:w}],children:"✓"}:{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:w}],children:e+1})})]});return a?_jsx(Pressable,{onPress:()=>u(e),disabled:!c,accessibilityRole:"button",accessibilityLabel:j,accessibilityState:{selected:y,disabled:!c},"aria-selected":y,"aria-disabled":!c,hitSlop:8,...hitSlopMarker(8),children:_}):_jsx(View,{accessibilityRole:"text",accessibilityLabel:j,accessibilityState:{selected:y},"aria-selected":y,children:_})},buildCircleStyles=()=>StyleSheet.create({relative:{alignItems:"center",justifyContent:"center"},pulse:{position:"absolute"},circle:{borderWidth:2,alignItems:"center",justifyContent:"center"},glyph:{includeFontPadding:!1}}),Stepper=forwardRef((e,t)=>{const{steps:s,activeStep:i,defaultActiveStep:o=0,pressMode:r="none",onStepPress:l,onActiveStepChange:n,variant:a="horizontal",tone:c="primary",formatCaption:p,showCaption:u=!0,loading:d=!1,labels:m,accessibilityLabel:h,style:g,containerStyle:y,circleStyle:b,labelStyle:x,connectorStyle:S,haptic:v,testID:f}=e;assertValidValue("Stepper","variant",e.variant,["horizontal","vertical","segmented"]),assertValidValue("Stepper","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Stepper","pressMode",e.pressMode,["none","back","select"]);const w=useMemo(()=>({...DEFAULT_STEPPER_LABELS,...m}),[m]),C=useTheme(),j=C.settings.components.stepper?.pulseAnimation??!1,_=resolveHaptic(v,"selection"),V=useMemo(()=>buildStyles(C),[C]),k=useMemo(()=>buildCircleStyles(),[]),R=toneColorFor(C,c),D=C.colors.border,A=C.colors.bg,E=C.colors["text-muted"],L=toneOnColorFor(C,c),T=s.length,I="none"!==r,P=void 0!==i,[F,$]=useState(o),M=P?i:F,B=null==M||M<0?null:M,statusOf=e=>null===B?"upcoming":e<B?"complete":e===B?"active":"upcoming",O=s.map((e,t)=>statusOf(t)),N=O.filter(e=>"upcoming"!==e).length,U=O.filter(e=>"complete"===e).length,canPressStatus=e=>"back"===r?"complete"===e:I,handleStepPress=e=>{if(!canPressStatus(statusOf(e)))return;_&&triggerHaptic(_),l?.(e);const t="select"===r&&e===B?null:e;P||$(t),n?.(t)},H=useRef(createAnimatedValue(N)).current,z=useRef(N);useEffect(()=>{const e=z.current;if(e===N)return;z.current=N;const t=Animated.timing(H,{toValue:N,duration:C.motion.duration.default*Math.abs(N-e),easing:Easing.linear,useNativeDriver:!1});return t.start(),()=>t.stop()},[N,H,C.motion]);const sliceOf=e=>H.interpolate({inputRange:[e,e+1],outputRange:["0%","100%"],extrapolate:"clamp"}),W=T<=1?"0%":H.interpolate({inputRange:[1,T],outputRange:["0%","100%"],extrapolate:"clamp"}),G=null!==B&&B<T?B:null,q=h??(null!==G?w.progressStep(G+1,T):w.progressDone(U,T)),[Z,J]=useState(0),K=T>0&&Z>0?Z/(2*T):0,Q=_jsx(View,{ref:t,style:[V.container,y,g],testID:f,accessibilityRole:"progressbar",accessibilityLabel:q,accessibilityValue:{min:0,max:T,now:N},children:"segmented"===a?(()=>{const e=null!==G?s[G]:void 0,t=u?p?p(G,T,e):null!==G?w.captionStep(G+1,T,e?.label):w.captionDone(U,T):"";return _jsxs(View,{children:[u?_jsx(Text,{variant:"bodySmall",style:[V.sCaption,{marginBottom:C.space.sm},x],numberOfLines:1,children:t}):null,_jsx(View,{style:V.sRow,children:s.map((e,t)=>{const s=statusOf(t),i=w.step(t+1,T,e.label,statusWordFor(w,s)),o=_jsx(View,{testID:f?`${f}-segment-${t}`:void 0,style:[V.sTrack,{backgroundColor:D},S],children:_jsx(Animated.View,{style:[V.sFill,{backgroundColor:R,width:sliceOf(t)}]})});if(I){const r=canPressStatus(s);return _jsx(Pressable,{style:V.sItem,onPress:()=>handleStepPress(t),disabled:!r,accessibilityRole:"button",accessibilityLabel:i,accessibilityState:{selected:"active"===s,disabled:!r},"aria-selected":"active"===s,"aria-disabled":!r,hitSlop:{top:12,bottom:12},...hitSlopMarker({top:12,bottom:12}),children:o},e.key)}return _jsx(View,{style:V.sItem,accessibilityRole:"text",accessibilityLabel:i,accessibilityState:{selected:"active"===s},"aria-selected":"active"===s,children:o},e.key)})})]})})():"vertical"===a?_jsx(View,{style:V.vCol,children:s.map((e,t)=>{const s=statusOf(t),i=t===T-1;return _jsxs(View,{style:V.vRow,children:[_jsxs(View,{style:V.vLeft,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:D,upcomingFillColor:A,onPressColor:R,textOnColor:L,upcomingTextColor:E,interactive:I,canPress:canPressStatus(s),totalSteps:T,onPress:handleStepPress,pulseEnabled:j,labels:w,circleStyles:k,circleSlotStyle:b}),i?null:_jsxs(View,{style:[V.vConnectorContainer,S],children:[_jsx(View,{style:[V.vConnectorTrack,{backgroundColor:D}]}),_jsx(Animated.View,{style:[V.vConnectorFill,{backgroundColor:R,height:sliceOf(t+1)}]})]})]}),_jsxs(View,{style:V.vBody,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[V.vLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "}),e.description?_jsx(Text,{variant:"bodySmall",style:V.vDescription,numberOfLines:3,children:e.description}):null]})]},e.key)})}):_jsxs(View,{style:V.hRow,onLayout:e=>J(e.nativeEvent.layout.width),children:[_jsxs(View,{pointerEvents:"none",style:[V.hConnectorContainer,{left:K,right:K},S],children:[_jsx(View,{style:[V.hConnectorTrack,{backgroundColor:D}]}),_jsx(Animated.View,{style:[V.hConnectorFill,{backgroundColor:R,width:W}]})]}),s.map((e,t)=>{const s=statusOf(t);return _jsxs(View,{style:V.hStepItem,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:D,upcomingFillColor:A,onPressColor:R,textOnColor:L,upcomingTextColor:E,interactive:I,canPress:canPressStatus(s),totalSteps:T,onPress:handleStepPress,pulseEnabled:j,labels:w,circleStyles:k,circleSlotStyle:b}),_jsx(Text,{variant:"caption",style:[V.hLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "})]},e.key)})]})});return d?_jsx(StepperSkeleton,{...e}):Q});Stepper.displayName="Stepper";const StepperSkeleton=({steps:e,variant:t="horizontal",showCaption:s=!0,containerStyle:i,style:o,testID:r})=>{const l=useTheme(),n=useMemo(()=>buildStyles(l),[l]),a=useMemo(()=>buildSkeletonStyles(l),[l]),c=e.length||3;return"segmented"===t?_jsxs(View,{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[s?_jsx(Skeleton,{shape:"text",width:"45%",height:14,style:{marginBottom:l.space.sm}}):null,_jsx(View,{style:n.sRow,children:Array.from({length:c}).map((e,t)=>_jsx(View,{style:n.sItem,children:_jsx(Skeleton,{width:"100%",height:4,radius:"pill"})},`sk-step-${t}`))})]}):_jsx(View,"vertical"===t?{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsx(View,{style:a.vCol,children:Array.from({length:c}).map((e,t)=>{const s=t===c-1;return _jsxs(View,{style:a.vRow,children:[_jsxs(View,{style:[a.vLeft,{width:32}],children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),s?null:_jsx(Skeleton,{width:2,height:36})]}),_jsxs(View,{style:a.vBody,children:[_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:l.space.xs}}),_jsx(Skeleton,{shape:"text",width:"80%",height:12})]})]},`sk-step-${t}`)})})}:{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsxs(View,{style:n.hRow,children:[_jsx(View,{pointerEvents:"none",style:[n.hConnectorContainer,{left:50/c+"%",right:50/c+"%"}],children:_jsx(Skeleton,{width:"100%",height:2,radius:"pill"})}),Array.from({length:c}).map((e,t)=>_jsxs(View,{style:n.hStepItem,children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),_jsx(Skeleton,{shape:"text",width:"80%",height:12,style:{marginTop:l.space.xs}})]},`sk-step-${t}`))]})})};StepperSkeleton.displayName="StepperSkeleton",Stepper.Skeleton=StepperSkeleton;const buildSkeletonStyles=e=>StyleSheet.create({vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center"},vBody:{flex:1,paddingLeft:e.space.md,paddingBottom:e.space.lg}}),buildStyles=e=>StyleSheet.create({container:{width:"100%"},hRow:{flexDirection:"row",alignItems:"flex-start",justifyContent:"space-between",position:"relative"},hConnectorContainer:{position:"absolute",top:11,height:2,flexDirection:"row",alignItems:"center"},hConnectorTrack:{position:"absolute",left:0,right:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hConnectorFill:{position:"absolute",left:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hStepItem:{alignItems:"center",flex:1},hLabel:{marginTop:e.space.xs,textAlign:"center"},vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center",alignSelf:"stretch",width:32},vConnectorContainer:{flex:1,width:2,minHeight:32,position:"relative",alignSelf:"center"},vConnectorTrack:{position:"absolute",top:0,bottom:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vConnectorFill:{position:"absolute",top:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vBody:{flex:1,paddingLeft:e.space.sm,paddingBottom:e.space.md},vLabel:{marginBottom:e.space.xxs},vDescription:{},sCaption:{includeFontPadding:!1},sRow:{flexDirection:"row",columnGap:e.space.xs},sItem:{flex:1},sTrack:{height:4,borderRadius:e.radius.pill,overflow:"hidden"},sFill:{height:4,borderRadius:e.radius.pill}});export{Stepper};export default Stepper;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSwitchSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},Switch=forwardRef((e,t)=>{const{value:s,defaultValue:i,onChange:r,disabled:a=!1,size:o="md",tone:n="primary",label:l,description:c,helperText:d,error:u,layout:p="inline",accessibilityLabel:m,haptic:h="selection",bounce:f=!1,style:b,containerStyle:g,trackStyle:y,thumbStyle:w,testID:x,hitSlop:S,...V}=e,j=useTheme(),T=Object.keys(j.components.switch);assertValidValue("Switch","size",e.size,T),assertValidValue("Switch","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Switch","layout",e.layout,["inline","row"]);const[C,R]=useControllableState({value:s,defaultValue:i??!1,onChange:r}),k=T.includes(o)?o:"md",v=useMemo(()=>resolveSwitchSize(j,k),[j,k]),A=j.colors["switch-thumb"],_=useMemo(()=>buildStyles(j),[j]),D="dark"===j.mode?j.colors.neutral:j.colors["surface-disabled"],z=toneColor(j,n),E=S??8,F=useRef(createAnimatedValue(C?1:0)).current;useEffect(()=>{const e=Animated.spring(F,{toValue:C?1:0,damping:j.motion.spring.snappy.damping,stiffness:j.motion.spring.snappy.stiffness,mass:j.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[C,F,j.motion.spring.snappy]);const H=useRef(createAnimatedValue(C?1:0)).current;useEffect(()=>{const e=Animated.timing(H,{toValue:C?1:0,duration:j.motion.duration.fast,easing:Easing.out(Easing.ease),useNativeDriver:!1});return e.start(),()=>e.stop()},[C,H,j.motion.duration.fast]);const M=v.padding,P=v["track-width"]-v["thumb-size"]-v.padding,I=F.interpolate({inputRange:[0,1],outputRange:[M,P]}),N=H.interpolate({inputRange:[0,1],outputRange:[D,z]}),L=useRef(createAnimatedValue(1)).current,B=useRef(!0);useEffect(()=>{if(!f)return;if(B.current)return void(B.current=!1);const e=Animated.sequence([Animated.spring(L,{toValue:1.15,damping:10,stiffness:220,mass:1,useNativeDriver:!0}),Animated.spring(L,{toValue:1,damping:14,stiffness:240,mass:1,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[C,f,L]);const handlePress=e=>{a||(!1!==h&&triggerHaptic(h),R(!C),V.onPressOut?.(e))},O=m??fieldTextAsString(l),q="string"==typeof u?u:void 0,U=hasChoiceDetail({description:c,error:q,helperText:d}),W=hasFieldText(l)||U,X=(!0===u||hasFieldText(u))&&!C&&!a,G="row"===p&&W,J=_jsxs(Animated.View,{style:[_.track,{width:v["track-width"],height:v["track-height"],borderRadius:j.radius.pill,...smoothCorners,backgroundColor:N},y],children:[X?_jsx(View,{pointerEvents:"none",style:[_.errorRing,{borderRadius:j.radius.pill,...smoothCorners,borderWidth:j.size.border,borderColor:j.colors["field-border-error"]}]}):null,_jsx(Animated.View,{style:[_.thumb,j.shadow.card,{backgroundColor:A,width:v["thumb-size"],height:v["thumb-size"],borderRadius:j.radius.pill,...smoothCorners,transform:[{translateX:I},{scale:L}]},w]})]});if(G)return _jsxs(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:V.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:C,disabled:a},"aria-checked":C,"aria-disabled":a,testID:x,hitSlop:S,...null==S?{}:hitSlopMarker(S),...V,style:({pressed:e})=>[_.row,_.spreadRow,U?_.rowTop:null,{opacity:a?.55:e?.9:1},g,b],children:[_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:_.spreadText}),J]});const K=_jsx(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:V.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:C,disabled:a},"aria-checked":C,"aria-disabled":a,testID:x,hitSlop:E,...hitSlopMarker(E),...V,style:({pressed:e})=>[{opacity:a?.55:e?.9:1},W?null:b],children:J});return W?_jsxs(View,{style:[_.row,U?_.rowTop:null,g,b],children:[K,_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:_.text})]}):g?_jsx(View,{style:g,children:K}):K});Switch.displayName="Switch";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},track:{justifyContent:"center"},thumb:{position:"absolute",top:2},errorRing:{...StyleSheet.absoluteFill},rowTop:{alignItems:"flex-start"},text:{marginLeft:e.space.sm},spreadRow:{minHeight:44,justifyContent:"space-between"},spreadText:{flex:1,marginRight:e.space.md}});export{Switch};export default Switch;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSwitchSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},Switch=forwardRef((e,t)=>{const{value:i,defaultValue:s,onChange:r,disabled:a=!1,size:o="md",tone:n="primary",label:l,description:c,helperText:d,error:u,layout:p="inline",accessibilityLabel:m,haptic:h="selection",bounce:f=!1,style:b,containerStyle:g,trackStyle:y,thumbStyle:w,testID:x,hitSlop:S,...j}=e,v=useTheme(),V=Object.keys(v.components.switch);assertValidValue("Switch","size",e.size,V),assertValidValue("Switch","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Switch","layout",e.layout,["inline","row"]);const[T,C]=useControllableState({value:i,defaultValue:s??!1,onChange:r}),R=V.includes(o)?o:"md",k=useMemo(()=>resolveSwitchSize(v,R),[v,R]),A=v.colors["switch-thumb"],D=useMemo(()=>buildStyles(v),[v]),_="dark"===v.mode?v.colors.neutral:v.colors["surface-disabled"],z=toneColor(v,n),E=S??8,F=useRef(createAnimatedValue(T?1:0)).current;useEffect(()=>{const e=Animated.spring(F,{toValue:T?1:0,damping:v.motion.spring.snappy.damping,stiffness:v.motion.spring.snappy.stiffness,mass:v.motion.spring.snappy.mass,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[T,F,v.motion.spring.snappy]);const H=useRef(createAnimatedValue(T?1:0)).current;useEffect(()=>{const e=Animated.timing(H,{toValue:T?1:0,duration:v.motion.duration.fast,easing:Easing.out(Easing.ease),useNativeDriver:!1});return e.start(),()=>e.stop()},[T,H,v.motion.duration.fast]);const M=k.padding,P=k["track-width"]-k["thumb-size"]-k.padding,I=F.interpolate({inputRange:[0,1],outputRange:[M,P]}),N=H.interpolate({inputRange:[0,1],outputRange:[_,z]}),L=useRef(createAnimatedValue(1)).current,B=useRef(!0);useEffect(()=>{if(!f)return;if(B.current)return void(B.current=!1);const e=Animated.sequence([Animated.spring(L,{toValue:1.15,damping:10,stiffness:220,mass:1,useNativeDriver:nativeDriver}),Animated.spring(L,{toValue:1,damping:14,stiffness:240,mass:1,useNativeDriver:nativeDriver})]);return e.start(),()=>e.stop()},[T,f,L]);const handlePress=e=>{a||(!1!==h&&triggerHaptic(h),C(!T),j.onPressOut?.(e))},O=m??fieldTextAsString(l),q="string"==typeof u?u:void 0,U=hasChoiceDetail({description:c,error:q,helperText:d}),W=hasFieldText(l)||U,X=(!0===u||hasFieldText(u))&&!T&&!a,G="row"===p&&W,J=_jsxs(Animated.View,{style:[D.track,{width:k["track-width"],height:k["track-height"],borderRadius:v.radius.pill,...smoothCorners,backgroundColor:N},y],children:[X?_jsx(View,{pointerEvents:"none",style:[D.errorRing,{borderRadius:v.radius.pill,...smoothCorners,borderWidth:v.size.border,borderColor:v.colors["field-border-error"]}]}):null,_jsx(Animated.View,{style:[D.thumb,v.shadow.card,{backgroundColor:A,width:k["thumb-size"],height:k["thumb-size"],borderRadius:v.radius.pill,...smoothCorners,transform:[{translateX:I},{scale:L}]},w]})]});if(G)return _jsxs(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:T,disabled:a},"aria-checked":T,"aria-disabled":a,testID:x,hitSlop:S,...null==S?{}:hitSlopMarker(S),...j,style:({pressed:e})=>[D.row,D.spreadRow,U?D.rowTop:null,{opacity:a?.55:e?.9:1},g,b],children:[_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:D.spreadText}),J]});const K=_jsx(Pressable,{ref:t,onPress:handlePress,disabled:a,accessibilityRole:"switch",accessibilityLabel:O,accessibilityHint:j.accessibilityHint??fieldTextAsString(c),accessibilityState:{checked:T,disabled:a},"aria-checked":T,"aria-disabled":a,testID:x,hitSlop:E,...hitSlopMarker(E),...j,style:({pressed:e})=>[{opacity:a?.55:e?.9:1},W?null:b],children:J});return W?_jsxs(View,{style:[D.row,U?D.rowTop:null,g,b],children:[K,_jsx(ChoiceText,{label:l,description:c,helperText:d,error:q,disabled:a,style:D.text})]}):g?_jsx(View,{style:g,children:K}):K});Switch.displayName="Switch";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},track:{justifyContent:"center"},thumb:{position:"absolute",top:2},errorRing:{...StyleSheet.absoluteFill},rowTop:{alignItems:"flex-start"},text:{marginLeft:e.space.sm},spreadRow:{minHeight:44,justifyContent:"space-between"},spreadText:{flex:1,marginRight:e.space.md}});export{Switch};export default Switch;
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveSegmentedControlSize,resolveTabsSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Badge}from"../Badge/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const Tabs=forwardRef((e,t)=>{const{tabs:i,activeKey:a,onChange:s,variant:r="underline",radius:n,size:l="md",scrollable:o=!1,align:d="left",style:c,tabStyle:u,tabLabelStyle:m,tabIconStyle:p,tabBadgeStyle:b,dividerStyle:g,indicatorStyle:f,progress:h,pages:y,haptic:x,accessibilityLabel:v,testID:S}=e;assertValidValue("Tabs","variant",e.variant,["underline","pills","segmented"]),assertValidValue("Tabs","size",e.size,["sm","md","lg"]),assertValidValue("Tabs","align",e.align,["left","center"]);const w=useTheme(),V=useMemo(()=>buildStyles(w),[w]),j=w.components.tabs,T=useMemo(()=>resolveTabsSize(w,l),[w,l]),_=o?T["scrollable-padding-x"]:T["padding-x"],k=T["padding-y"],R=T.text,z=w.space[j["icon-gap"]],C=T.icon,I=j["underline-height"],E=w.space[j["pill-inset"]],A=j["disabled-opacity"],L=w.space[j["badge-gap"]],F="segmented"===r,M=useMemo(()=>resolveSegmentedControlSize(w,l),[w,l]),H=w.space[j["track-padding"]],D="number"==typeof n?n:n?w.radius[n]:void 0,B=D??w.radius.md,P=void 0===D?w.radius.sm:Math.max(D-H,0),q=D??w.radius.pill,N=D??w.radius.none,O=w.colors["bg-muted"],W=useSquircle(F,B),[$,U]=useState({}),K=useRef(createAnimatedValue(0)).current,X=useRef(createAnimatedValue(0)).current,[G,J]=useState(0),Q=useRef(createAnimatedValue(0)).current,Y=useRef(null),Z=useRef(0),ee=$[a],te=Math.max(0,i.findIndex(e=>e.key===a)),ie=useMemo(()=>y&&G>0?Q.interpolate({inputRange:[0,G],outputRange:[0,1]}):void 0,[y,G,Q])??h,ae=i.every(e=>void 0!==$[e.key]),se=void 0!==ie&&ae&&i.length>1,re=useMemo(()=>se&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>$[e.key].x),extrapolate:"clamp"}):null,[se,ie,i,$]),ne=useMemo(()=>se&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>$[e.key].width),extrapolate:"clamp"}):null,[se,ie,i,$]),le=useRef(null);useEffect(()=>{if(!ee)return;if(se)return;const e=null!==le.current&&le.current!==a;if(le.current=a,!e)return K.setValue(ee.x),void X.setValue(ee.width);const t=w.motion.spring.snappy,i=Animated.parallel([Animated.spring(K,{toValue:ee.x,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1}),Animated.spring(X,{toValue:ee.width,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1})]);return i.start(),()=>i.stop()},[ee,a,K,X,w.motion.spring.snappy,se]),useEffect(()=>{y&&0!==G&&Z.current!==te&&(Z.current=te,Y.current?.scrollTo({x:te*G,animated:!0}))},[y,G,te]);const oe=y?.length;useEffect(()=>{__DEV__&&void 0!==oe&&oe!==i.length&&Logger.warn(`[@webority/mobile-ui] Tabs pages has ${oe} entries for ${i.length} tabs; each tab needs one page.`)},[oe,i.length]);const de=useCallback(e=>t=>{const{x:i,width:a}=t.nativeEvent.layout;U(t=>{const s=t[e];return s&&s.x===i&&s.width===a?t:{...t,[e]:{x:i,width:a}}})},[]),ce=useCallback(e=>{if(e.disabled)return;if(e.key===a)return;const t=resolveHaptic(x,"selection");t&&triggerHaptic(t),s(e.key)},[a,s,x]),ue="pills"===r,me=_jsx(Animated.View,{pointerEvents:"none",style:[F?V.indicatorThumb:ue?V.indicatorPill:V.indicatorUnderline,F?null:ue?{top:E,bottom:E}:{height:I},{width:ne??X,transform:[{translateX:re??K}],backgroundColor:F?w.colors.surface:ue?w.colors["primary-soft"]:w.colors.primary,borderRadius:F?P:ue?q:N,...smoothCorners},f]}),renderTabs=()=>i.map(e=>{const t=e.key===a,i=!0===e.disabled,s=t?w.colors.primary:w.colors["text-subtle"],r=renderSlotIcon(e.icon,{color:s,size:C,focused:t,disabled:i});return _jsxs(Pressable,{onPress:()=>ce(e),onLayout:de(e.key),disabled:i,accessibilityRole:"tab",accessibilityLabel:e.label,accessibilityState:{selected:t,disabled:i},"aria-selected":t,"aria-disabled":i,android_ripple:F?void 0:{color:w.colors["surface-pressed"],borderless:!1},style:({pressed:e})=>[V.tab,o?null:V.tabFlex,F?{paddingHorizontal:M["padding-x"],height:M.height-2*H}:{paddingHorizontal:_,paddingVertical:k},{opacity:i?A:e&&F&&!t?.7:1,backgroundColor:e&&!F?w.colors["surface-pressed"]:"transparent"},u],children:[r?_jsx(View,{style:[V.tabIcon,{marginRight:z},p],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:r}):null,_jsx(Text,{variant:"label",weight:t?"semibold":"medium",color:t?"brand":"tertiary",style:[V.tabLabel,{fontSize:F?M.text:R},m],numberOfLines:1,children:e.label}),void 0!==e.badge&&null!==e.badge?_jsx(Badge,{value:String(e.badge),tone:"primary",fill:"soft",accessible:!1,style:{marginLeft:L},badgeStyle:[V.tabBadge,b]}):null]},e.key)}),pe={flexDirection:"row",alignItems:"stretch",justifyContent:o?"flex-start":"center"===d?"center":"flex-start",position:"relative",overflow:"hidden"},be=_jsxs(_Fragment,F?{children:[me,renderTabs()]}:{children:[renderTabs(),me]}),ge=_jsxs(View,{ref:t,style:[V.container,{borderBottomColor:w.colors["border-subtle"],borderBottomWidth:"underline"===r?StyleSheet.hairlineWidth:0},"underline"===r?g:null,F?{padding:H,borderRadius:B,...smoothCorners,backgroundColor:W.active?"transparent":O}:null,c],onLayout:W.onLayout,accessibilityRole:"tablist",accessibilityLabel:v,testID:S,children:[W.active&&W.size?_jsx(SquircleFill,{width:W.size.width,height:W.size.height,radius:B,fill:O}):null,o?_jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[pe],keyboardShouldPersistTaps:"handled",children:be}):_jsx(View,{style:pe,children:be})]});return y?_jsxs(View,{style:V.root,children:[ge,_jsx(Animated.ScrollView,{ref:Y,horizontal:!0,pagingEnabled:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onLayout:e=>J(Math.round(e.nativeEvent.layout.width)),onScroll:Animated.event([{nativeEvent:{contentOffset:{x:Q}}}],{useNativeDriver:!1}),onMomentumScrollEnd:e=>{if(0===G)return;const t=Math.round(e.nativeEvent.contentOffset.x/G),r=i[t];r?.disabled?Y.current?.scrollTo({x:te*G,animated:!0}):(Z.current=t,r&&r.key!==a&&s(r.key))},style:V.pager,testID:S?`${S}-pages`:void 0,children:i.map((e,t)=>_jsx(View,{style:{width:G},accessibilityElementsHidden:t!==te,importantForAccessibility:t===te?"auto":"no-hide-descendants",children:y[t]},e.key))})]}):ge});Tabs.displayName="Tabs";const buildStyles=e=>StyleSheet.create({root:{flex:1},pager:{flex:1},container:{width:"100%",position:"relative"},tab:{flexDirection:"row",alignItems:"center",justifyContent:"center"},tabFlex:{flex:1},tabIcon:{},tabLabel:{includeFontPadding:!1,flexShrink:1},tabBadge:{minWidth:18,minHeight:0},indicatorUnderline:{position:"absolute",left:0,bottom:0},indicatorPill:{position:"absolute",left:0,zIndex:-1},indicatorThumb:{position:"absolute",left:0,top:0,bottom:0}});export{Tabs};export default Tabs;
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,ScrollView,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveSegmentedControlSize,resolveTabsSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Badge}from"../Badge/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const measuredLayout=(e,t)=>{const i=e[t];if(void 0===i)throw new Error(`Tabs: tab "${t}" has no measured layout while its progress signal drives the indicator`);return i},Tabs=forwardRef((e,t)=>{const{tabs:i,activeKey:a,onChange:r,variant:s="underline",radius:n,size:o="md",scrollable:l=!1,align:d="left",style:c,tabStyle:u,tabLabelStyle:m,tabIconStyle:p,tabBadgeStyle:b,dividerStyle:g,indicatorStyle:h,progress:f,pages:y,haptic:x,accessibilityLabel:v,testID:S}=e;assertValidValue("Tabs","variant",e.variant,["underline","pills","segmented"]),assertValidValue("Tabs","size",e.size,["sm","md","lg"]),assertValidValue("Tabs","align",e.align,["left","center"]);const w=useTheme(),V=useMemo(()=>buildStyles(w),[w]),j=w.components.tabs,T=useMemo(()=>resolveTabsSize(w,o),[w,o]),_=l?T["scrollable-padding-x"]:T["padding-x"],k=T["padding-y"],R=T.text,z=w.space[j["icon-gap"]],C=T.icon,L=j["underline-height"],E=w.space[j["pill-inset"]],I=j["disabled-opacity"],A=w.space[j["badge-gap"]],F="segmented"===s,M=useMemo(()=>resolveSegmentedControlSize(w,o),[w,o]),H=w.space[j["track-padding"]],D="number"==typeof n?n:n?w.radius[n]:void 0,B=D??w.radius.md,P=void 0===D?w.radius.sm:Math.max(D-H,0),q=D??w.radius.pill,N=D??w.radius.none,$=w.colors["bg-muted"],O=useSquircle(F,B),[W,U]=useState({}),K=useRef(createAnimatedValue(0)).current,X=useRef(createAnimatedValue(0)).current,[G,J]=useState(0),Q=useRef(createAnimatedValue(0)).current,Y=useRef(null),Z=useRef(0),ee=W[a],te=Math.max(0,i.findIndex(e=>e.key===a)),ie=useMemo(()=>y&&G>0?Q.interpolate({inputRange:[0,G],outputRange:[0,1]}):void 0,[y,G,Q])??f,ae=i.every(e=>void 0!==W[e.key]),re=void 0!==ie&&ae&&i.length>1,se=useMemo(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>measuredLayout(W,e.key).x),extrapolate:"clamp"}):null,[re,ie,i,W]),ne=useMemo(()=>re&&ie?ie.interpolate({inputRange:i.map((e,t)=>t),outputRange:i.map(e=>measuredLayout(W,e.key).width),extrapolate:"clamp"}):null,[re,ie,i,W]),oe=useRef(null);useEffect(()=>{if(!ee)return;if(re)return;const e=null!==oe.current&&oe.current!==a;if(oe.current=a,!e)return K.setValue(ee.x),void X.setValue(ee.width);const t=w.motion.spring.snappy,i=Animated.parallel([Animated.spring(K,{toValue:ee.x,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1}),Animated.spring(X,{toValue:ee.width,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!1})]);return i.start(),()=>i.stop()},[ee,a,K,X,w.motion.spring.snappy,re]),useEffect(()=>{y&&0!==G&&Z.current!==te&&(Z.current=te,Y.current?.scrollTo({x:te*G,animated:!0}))},[y,G,te]);const le=y?.length;useEffect(()=>{__DEV__&&void 0!==le&&le!==i.length&&Logger.warn(`[@webority/mobile-ui] Tabs pages has ${le} entries for ${i.length} tabs; each tab needs one page.`)},[le,i.length]);const de=useCallback(e=>t=>{const{x:i,width:a}=t.nativeEvent.layout;U(t=>{const r=t[e];return r&&r.x===i&&r.width===a?t:{...t,[e]:{x:i,width:a}}})},[]),ce=useCallback(e=>{if(e.disabled)return;if(e.key===a)return;const t=resolveHaptic(x,"selection");t&&triggerHaptic(t),r(e.key)},[a,r,x]),ue="pills"===s,me=_jsx(Animated.View,{pointerEvents:"none",style:[F?V.indicatorThumb:ue?V.indicatorPill:V.indicatorUnderline,F?null:ue?{top:E,bottom:E}:{height:L},{width:ne??X,transform:[{translateX:se??K}],backgroundColor:F?w.colors.surface:ue?w.colors["primary-soft"]:w.colors.primary,borderRadius:F?P:ue?q:N,...smoothCorners},h]}),renderTabs=()=>i.map(e=>{const t=e.key===a,i=!0===e.disabled,r=t?w.colors.primary:w.colors["text-subtle"],s=renderSlotIcon(e.icon,{color:r,size:C,focused:t,disabled:i});return _jsxs(Pressable,{onPress:()=>ce(e),onLayout:de(e.key),disabled:i,accessibilityRole:"tab",accessibilityLabel:e.label,accessibilityState:{selected:t,disabled:i},"aria-selected":t,"aria-disabled":i,android_ripple:F?void 0:{color:w.colors["surface-pressed"],borderless:!1},style:({pressed:e})=>[V.tab,l?null:V.tabFlex,F?{paddingHorizontal:M["padding-x"],height:M.height-2*H}:{paddingHorizontal:_,paddingVertical:k},{opacity:i?I:e&&F&&!t?.7:1,backgroundColor:e&&!F?w.colors["surface-pressed"]:"transparent"},u],children:[s?_jsx(View,{style:[V.tabIcon,{marginRight:z},p],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:s}):null,_jsx(Text,{variant:"label",weight:t?"semibold":"medium",color:t?"brand":"tertiary",style:[V.tabLabel,{fontSize:F?M.text:R},m],numberOfLines:1,children:e.label}),void 0!==e.badge&&null!==e.badge?_jsx(Badge,{value:String(e.badge),tone:"primary",fill:"soft",accessible:!1,style:{marginLeft:A},badgeStyle:[V.tabBadge,b]}):null]},e.key)}),pe={flexDirection:"row",alignItems:"stretch",justifyContent:l?"flex-start":"center"===d?"center":"flex-start",position:"relative",overflow:"hidden"},be=_jsxs(_Fragment,F?{children:[me,renderTabs()]}:{children:[renderTabs(),me]}),ge=_jsxs(View,{ref:t,style:[V.container,{borderBottomColor:w.colors["border-subtle"],borderBottomWidth:"underline"===s?StyleSheet.hairlineWidth:0},"underline"===s?g:null,F?{padding:H,borderRadius:B,...smoothCorners,backgroundColor:O.active?"transparent":$}:null,c],onLayout:O.onLayout,accessibilityRole:"tablist",accessibilityLabel:v,testID:S,children:[O.active&&O.size?_jsx(SquircleFill,{width:O.size.width,height:O.size.height,radius:B,fill:$}):null,l?_jsx(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[pe],keyboardShouldPersistTaps:"handled",children:be}):_jsx(View,{style:pe,children:be})]});return y?_jsxs(View,{style:V.root,children:[ge,_jsx(Animated.ScrollView,{ref:Y,horizontal:!0,pagingEnabled:!0,showsHorizontalScrollIndicator:!1,scrollEventThrottle:16,onLayout:e=>J(Math.round(e.nativeEvent.layout.width)),onScroll:Animated.event([{nativeEvent:{contentOffset:{x:Q}}}],{useNativeDriver:!1}),onMomentumScrollEnd:e=>{if(0===G)return;const t=Math.round(e.nativeEvent.contentOffset.x/G),s=i[t];s?.disabled?Y.current?.scrollTo({x:te*G,animated:!0}):(Z.current=t,s&&s.key!==a&&r(s.key))},style:V.pager,testID:S?`${S}-pages`:void 0,children:i.map((e,t)=>_jsx(View,{style:{width:G},accessibilityElementsHidden:t!==te,importantForAccessibility:t===te?"auto":"no-hide-descendants",children:y[t]},e.key))})]}):ge});Tabs.displayName="Tabs";const buildStyles=e=>StyleSheet.create({root:{flex:1},pager:{flex:1},container:{width:"100%",position:"relative"},tab:{flexDirection:"row",alignItems:"center",justifyContent:"center"},tabFlex:{flex:1},tabIcon:{},tabLabel:{includeFontPadding:!1,flexShrink:1},tabBadge:{minWidth:18,minHeight:0},indicatorUnderline:{position:"absolute",left:0,bottom:0},indicatorPill:{position:"absolute",left:0,zIndex:-1},indicatorThumb:{position:"absolute",left:0,top:0,bottom:0}});export{Tabs};export default Tabs;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,useTheme}from"../../theme/index.js";import{mergeRefs,resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Chip}from"../Chip/index.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder}from"../FieldBase/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const TagInput=forwardRef((e,t)=>{const{value:s,defaultValue:l,onChange:r,placeholder:a,label:i,helperText:o,error:n,required:u,disabled:d=!1,size:c="md",variant:p,maxTags:m,unique:x=!0,transform:f,separators:h=[","],haptic:g,onFocus:b,style:j,testID:v}=e;assertValidValue("TagInput","size",e.size,["sm","md","lg"]),assertValidValue("TagInput","variant",e.variant,["outline","filled","underline"]);const y=useTheme(),C=useMemo(()=>buildStyles(y),[y]),[T,S]=useControllableState({value:s,defaultValue:l??[],onChange:r}),[F,V]=useState(""),[w,I]=useState(!1),z=useRef(null),_=useMemo(()=>mergeRefs(z,t),[t]),k=useCallback(()=>{d||z.current?.focus()},[d]),R="number"==typeof m&&T.length>=m,B=!0===n||hasFieldText(n),H=u&&!i&&0===T.length&&0===F.length&&Boolean(a),q=useCallback(e=>{const t=f?f(e.trim()):e.trim();if(!t)return;if(R)return;if(x&&T.some(e=>e.toLowerCase()===t.toLowerCase()))return void V("");S([...T,t]),V("");const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[R,g,S,T,f,x]),L=useCallback(e=>{const t=T.filter((t,s)=>s!==e);S(t);const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[g,S,T]),M=useCallback(e=>{const t=h.find(t=>t.length>0&&e.includes(t));if(t){const[s]=e.split(t);return void q(s)}V(e)},[q,h]),D=useCallback(e=>{d||"Backspace"===e.nativeEvent.key&&""===F&&T.length>0&&L(T.length-1)},[d,F,L,T.length]),P=_jsx(FieldBase,{size:c,variant:p,focused:w,disabled:d,error:B,filled:T.length>0||F.length>0,onPress:k,pressFeedback:!1,style:j,children:_jsxs(View,{style:C.wrap,children:[T.map((e,t)=>_jsx(Chip,{label:e,size:"sm",onRemove:d?void 0:()=>L(t),haptic:g},`${e}-${t}`)),_jsxs(View,{style:C.inputBox,children:[_jsx(TextInput,{ref:_,value:F,onChangeText:M,onKeyPress:D,onSubmitEditing:()=>q(F),onFocus:e=>{I(!0),b?.(e)},onBlur:()=>{I(!1),q(F)},editable:!d&&!R,placeholder:R||H?void 0:a,placeholderTextColor:y.colors["text-subtle"],blurOnSubmit:!1,returnKeyType:"done",accessibilityLabel:i??a,style:[C.input,{color:y.colors["text-body"],fontSize:y.text.base.size}],testID:v?`${v}-input`:void 0}),H?_jsx(RequiredPlaceholder,{text:a??"",color:y.colors["text-subtle"],fontSize:y.text.base.size,weightStyle:fontFor(y,"normal")}):null]})]})});return _jsxs(View,{testID:v,children:[i?_jsx(FieldLabel,{size:c,required:u,children:i}):null,P,_jsx(FieldMessage,{size:c,error:B,text:B?n:o})]})});TagInput.displayName="TagInput";const buildStyles=e=>StyleSheet.create({wrap:{flex:1,flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:e.space.xs,paddingVertical:e.space.xs},inputBox:{flexGrow:1,minWidth:80},input:{...fontFor(e,"normal"),padding:e.space.none}});export default TagInput;
1
+ "use strict";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,useTheme}from"../../theme/index.js";import{mergeRefs,resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Chip}from"../Chip/index.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder}from"../FieldBase/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const TagInput=forwardRef((e,t)=>{const{value:s,defaultValue:l,onChange:r,placeholder:a,label:i,helperText:o,error:n,required:u,disabled:d=!1,size:c="md",variant:p,maxTags:m,unique:x=!0,transform:f,separators:h=[","],haptic:g,onFocus:b,style:j,testID:v}=e;assertValidValue("TagInput","size",e.size,["sm","md","lg"]),assertValidValue("TagInput","variant",e.variant,["outline","filled","underline"]);const y=useTheme(),C=useMemo(()=>buildStyles(y),[y]),[T,S]=useControllableState({value:s,defaultValue:l??[],onChange:r}),[F,V]=useState(""),[w,I]=useState(!1),z=useRef(null),_=useMemo(()=>mergeRefs(z,t),[t]),k=useCallback(()=>{d||z.current?.focus()},[d]),R="number"==typeof m&&T.length>=m,B=!0===n||hasFieldText(n),H=u&&!i&&0===T.length&&0===F.length&&Boolean(a),q=useCallback(e=>{const t=f?f(e.trim()):e.trim();if(!t)return;if(R)return;if(x&&T.some(e=>e.toLowerCase()===t.toLowerCase()))return void V("");S([...T,t]),V("");const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[R,g,S,T,f,x]),L=useCallback(e=>{const t=T.filter((t,s)=>s!==e);S(t);const s=resolveHaptic(g,"selection");s&&triggerHaptic(s)},[g,S,T]),M=useCallback(e=>{const t=h.find(t=>t.length>0&&e.includes(t));t?q(e.slice(0,e.indexOf(t))):V(e)},[q,h]),D=useCallback(e=>{d||"Backspace"===e.nativeEvent.key&&""===F&&T.length>0&&L(T.length-1)},[d,F,L,T.length]),P=_jsx(FieldBase,{size:c,variant:p,focused:w,disabled:d,error:B,filled:T.length>0||F.length>0,onPress:k,pressFeedback:!1,style:j,children:_jsxs(View,{style:C.wrap,children:[T.map((e,t)=>_jsx(Chip,{label:e,size:"sm",onRemove:d?void 0:()=>L(t),haptic:g},`${e}-${t}`)),_jsxs(View,{style:C.inputBox,children:[_jsx(TextInput,{ref:_,value:F,onChangeText:M,onKeyPress:D,onSubmitEditing:()=>q(F),onFocus:e=>{I(!0),b?.(e)},onBlur:()=>{I(!1),q(F)},editable:!d&&!R,placeholder:R||H?void 0:a,placeholderTextColor:y.colors["text-subtle"],blurOnSubmit:!1,returnKeyType:"done",accessibilityLabel:i??a,style:[C.input,{color:y.colors["text-body"],fontSize:y.text.base.size}],testID:v?`${v}-input`:void 0}),H?_jsx(RequiredPlaceholder,{text:a??"",color:y.colors["text-subtle"],fontSize:y.text.base.size,weightStyle:fontFor(y,"normal")}):null]})]})});return _jsxs(View,{testID:v,children:[i?_jsx(FieldLabel,{size:c,required:u,children:i}):null,P,_jsx(FieldMessage,{size:c,error:B,text:B?n:o})]})});TagInput.displayName="TagInput";const buildStyles=e=>StyleSheet.create({wrap:{flex:1,flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:e.space.xs,paddingVertical:e.space.xs},inputBox:{flexGrow:1,minWidth:80},input:{...fontFor(e,"normal"),padding:e.space.none}});export default TagInput;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useMemo}from"react";import{Text as RNText}from"react-native";import{fontFor,useTheme}from"../../theme/index.js";import{TEXT_NAMES}from"../../theme/tokens.generated.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{TextInkContext,useTextInk}from"./textInk.js";import{jsx as _jsx}from"react/jsx-runtime";const VARIANTS={display:{size:"4xl",weight:"bold",line:"display",color:"primary",heading:!0,fontFamily:"display"},h1:{size:"3xl",weight:"bold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h2:{size:"2xl",weight:"semibold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h3:{size:"xl",weight:"semibold",line:"heading",color:"primary",heading:!0},title:{size:"lg",weight:"semibold",line:"body",color:"primary",fontFamily:"display"},body:{size:"base",weight:"normal",line:"body",color:"primary"},bodySmall:{size:"sm",weight:"normal",line:"body",color:"secondary"},caption:{size:"xs",weight:"normal",line:"body",color:"tertiary"},label:{size:"sm",weight:"medium",line:"body",color:"secondary"},overline:{size:"xs",weight:"semibold",line:"body",color:"secondary",uppercase:!0,letterSpacing:"wide"}},TEXT_ROLE_COLOR={textStrong:"text",primary:"text-body",secondary:"text-muted",tertiary:"text-subtle",inverse:"text-inverse",disabled:"text-disabled",link:"link",brand:"primary-text"},SEMANTIC={success:!0,warning:!0,danger:!0,info:!0,neutral:!0},COLOR_NAMES=["primary","secondary","tertiary","inverse","disabled","link","textStrong","brand","success","warning","danger","info","neutral"];export const resolveColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)?e.colors[TEXT_ROLE_COLOR[t]]:Object.hasOwn(SEMANTIC,t)?e.colors[`${t}-text`]:t;const resolveVariantColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)||Object.hasOwn(SEMANTIC,t)?resolveColor(e,t):e.colors[t],decorationOf=(e,t)=>e&&t?"underline line-through":e?"underline":t?"line-through":void 0,Text=forwardRef((e,t)=>{const{variant:i="body",color:o,weight:r,size:n,align:a,italic:l,underline:s,strikethrough:d,style:c,children:m,...x}=e,g=useTheme(),y=Object.hasOwn(VARIANTS,i),h=g.settings.textVariants,p=!y&&h&&Object.hasOwn(h,i)?h[i]:void 0;y||p||assertValidValue("Text","variant",e.variant,[...Object.keys(VARIANTS),...Object.keys(h??{})]),assertValidValue("Text","color",o,COLOR_NAMES),assertValidValue("Text","size",n,TEXT_NAMES);const u=void 0!==o&&COLOR_NAMES.includes(o)?o:void 0,b=useMemo(()=>{if(p){const e=n??p.size,t=g.text[e].size;return{fontSize:t,lineHeight:p.lineHeight??Math.round(t*g.leading[p.heading?"heading":"body"]),color:void 0!==u?resolveColor(g,u):p.color?resolveVariantColor(g,p.color):resolveColor(g,"primary"),textAlign:a,textTransform:p.uppercase?"uppercase":void 0,letterSpacing:p.letterSpacing?g["letter-spacing"][p.letterSpacing]:void 0,fontStyle:l||p.italic?"italic":void 0,fontVariant:p.fontVariant,textDecorationLine:decorationOf(s,d),...fontFor(g,r??p.weight??"normal",p.fontFamily)}}const e=VARIANTS[y?i:"body"],t=g.text[n??e.size].size;return{fontSize:t,lineHeight:Math.round(t*g.leading[e.line]),color:resolveColor(g,u??e.color),textAlign:a,textTransform:e.uppercase?"uppercase":void 0,letterSpacing:e.letterSpacing?g["letter-spacing"][e.letterSpacing]:void 0,fontStyle:l?"italic":void 0,textDecorationLine:decorationOf(s,d),...fontFor(g,r??e.weight,e.fontFamily)}},[g,p,y,i,u,r,n,a,l,s,d]),T=useTextInk([b,c],g.text.base.size,g.colors["text-body"]),f=y?VARIANTS[i].heading:p?.heading,O="string"==typeof m||"number"==typeof m;return _jsx(RNText,{ref:t,style:[b,c],maxFontSizeMultiplier:g.settings.maxFontSizeMultiplier,accessibilityRole:f?"header":x.accessibilityRole,...x,children:O?m:_jsx(TextInkContext.Provider,{value:T,children:m})})});Text.displayName="Text";export{Text};export default Text;
1
+ "use strict";import{forwardRef,useMemo}from"react";import{Text as RNText}from"react-native";import{fontFor,useTheme}from"../../theme/index.js";import{TEXT_NAMES}from"../../theme/tokens.generated.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{TextInkContext,useTextInk}from"./textInk.js";import{jsx as _jsx}from"react/jsx-runtime";const VARIANTS={display:{size:"4xl",weight:"bold",line:"display",color:"primary",heading:!0,fontFamily:"display"},h1:{size:"3xl",weight:"bold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h2:{size:"2xl",weight:"semibold",line:"heading",color:"primary",heading:!0,fontFamily:"display"},h3:{size:"xl",weight:"semibold",line:"heading",color:"primary",heading:!0},title:{size:"lg",weight:"semibold",line:"body",color:"primary",fontFamily:"display"},body:{size:"base",weight:"normal",line:"body",color:"primary"},bodySmall:{size:"sm",weight:"normal",line:"body",color:"secondary"},caption:{size:"xs",weight:"normal",line:"body",color:"tertiary"},label:{size:"sm",weight:"medium",line:"body",color:"secondary"},overline:{size:"xs",weight:"semibold",line:"body",color:"secondary",uppercase:!0,letterSpacing:"wide"}},TEXT_ROLE_COLOR={textStrong:"text",primary:"text-body",secondary:"text-muted",tertiary:"text-subtle",inverse:"text-inverse",disabled:"text-disabled",link:"link",brand:"primary-text"},SEMANTIC={success:!0,warning:!0,danger:!0,info:!0,neutral:!0},COLOR_NAMES=["primary","secondary","tertiary","inverse","disabled","link","textStrong","brand","success","warning","danger","info","neutral"];export const resolveColor=(e,t)=>{if(Object.hasOwn(TEXT_ROLE_COLOR,t)){const i=TEXT_ROLE_COLOR[t];if(void 0===i)throw new Error(`resolveColor: "${t}" is listed as a text role but has no colour`);return e.colors[i]}return Object.hasOwn(SEMANTIC,t)?e.colors[`${t}-text`]:t};const resolveVariantColor=(e,t)=>Object.hasOwn(TEXT_ROLE_COLOR,t)||Object.hasOwn(SEMANTIC,t)?resolveColor(e,t):e.colors[t],decorationOf=(e,t)=>e&&t?"underline line-through":e?"underline":t?"line-through":void 0,Text=forwardRef((e,t)=>{const{variant:i="body",color:o,weight:r,size:n,align:a,italic:l,underline:s,strikethrough:d,style:c,children:m,...x}=e,g=useTheme(),h=Object.hasOwn(VARIANTS,i),y=g.settings.textVariants,p=!h&&y&&Object.hasOwn(y,i)?y[i]:void 0;h||p||assertValidValue("Text","variant",e.variant,[...Object.keys(VARIANTS),...Object.keys(y??{})]),assertValidValue("Text","color",o,COLOR_NAMES),assertValidValue("Text","size",n,TEXT_NAMES);const u=void 0!==o&&COLOR_NAMES.includes(o)?o:void 0,b=useMemo(()=>{if(p){const e=n??p.size,t=g.text[e].size;return{fontSize:t,lineHeight:p.lineHeight??Math.round(t*g.leading[p.heading?"heading":"body"]),color:void 0!==u?resolveColor(g,u):p.color?resolveVariantColor(g,p.color):resolveColor(g,"primary"),textAlign:a,textTransform:p.uppercase?"uppercase":void 0,letterSpacing:p.letterSpacing?g["letter-spacing"][p.letterSpacing]:void 0,fontStyle:l||p.italic?"italic":void 0,fontVariant:p.fontVariant,textDecorationLine:decorationOf(s,d),...fontFor(g,r??p.weight??"normal",p.fontFamily)}}const e=VARIANTS[h?i:"body"],t=g.text[n??e.size].size;return{fontSize:t,lineHeight:Math.round(t*g.leading[e.line]),color:resolveColor(g,u??e.color),textAlign:a,textTransform:e.uppercase?"uppercase":void 0,letterSpacing:e.letterSpacing?g["letter-spacing"][e.letterSpacing]:void 0,fontStyle:l?"italic":void 0,textDecorationLine:decorationOf(s,d),...fontFor(g,r??e.weight,e.fontFamily)}},[g,p,h,i,u,r,n,a,l,s,d]),f=useTextInk([b,c],g.text.base.size,g.colors["text-body"]),T=h?VARIANTS[i].heading:p?.heading,O="string"==typeof m||"number"==typeof m;return _jsx(RNText,{ref:t,style:[b,c],maxFontSizeMultiplier:g.settings.maxFontSizeMultiplier,accessibilityRole:T?"header":x.accessibilityRole,...x,children:O?m:_jsx(TextInkContext.Provider,{value:f,children:m})})});Text.displayName="Text";export{Text};export default Text;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`});const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:n,shownAt:i,runtime:s})=>{const a=useTheme(),r=usePresenceMotion(),o=r.duration("fast");assertValidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=s?.labels??DEFAULT_TOAST_LABELS,d=useMemo(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=useMemo(()=>buildStyles(a),[a]),p=useMemo(()=>tintFor(a,l),[a,l]),g=useMemo(()=>inkFor(a,l),[a,l]),h=a.components.toast["icon-circle-size"],f=a.text[a.components.toast["icon-glyph-text"]].size,b=a.components.toast["tint-bar-width"],v=a.settings.components.toast?.defaultDurationMs??3e3,A=a.settings.components.toast?.enableSwipeDismiss??!0,x="top"===c?-120:120,y=useRef(createAnimatedValue(r.reduced?0:x)).current,w=useRef(createAnimatedValue(0)).current,S=useRef(createAnimatedValue(0)).current,T=useRef(!1),V="top"===c?8*t:8*-t,M=Math.max(1-.04*t,.9),_=useRef(createAnimatedValue(V)).current;useEffect(()=>{setNativeValue(_,V)},[V,_]);const D=useMemo(()=>Animated.add(y,_),[y,_]),R=void 0!==e.action,C=e.duration??v,E=C>0&&R&&"web"===Platform.OS?Math.max(C,8e3):C,N=E<=0||R&&!0===s?.screenReaderOn,j=!0===e.countdown&&!N,P=useRef(createAnimatedValue(1)).current,O=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),k=useRef({touch:!1,pan:!1,hover:!1}),L=useRef(()=>{}),I=useRef({id:e.id,totalMs:E,shownAt:i,runtime:s,persistent:N,animateBar:!1});I.current={id:e.id,totalMs:E,shownAt:i,runtime:s,persistent:N,animateBar:j&&!r.reduced};const H=useCallback(()=>{const e=O.current,t=I.current,n=k.current;if(!e.initialised){e.initialised=!0;const n=t.runtime?.readRemaining(t.id),i=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=n??(t.totalMs>0?Math.max(t.totalMs-i,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(P,e.remaining/t.totalMs)}const i=!(t.persistent||T.current||n.touch||n.pan||n.hover);i&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,L.current()},e.remaining),t.animateBar&&Animated.timing(P,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:!0}).start()):i||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),P.stopAnimation())},[P]),dismiss=()=>{if(T.current)return;T.current=!0,H();const t=[Animated.timing(S,{toValue:0,duration:o,easing:Easing.bezier(...a.motion.ease.accelerate),useNativeDriver:!0})];r.reduced||t.push(Animated.timing(y,{toValue:x,duration:a.motion.duration.fast,easing:Easing.bezier(...a.motion.ease.accelerate),useNativeDriver:!0})),Animated.parallel(t).start(()=>n(e.id))};L.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}):Animated.parallel([Animated.spring(y,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{H()},[N,H]),useEffect(()=>()=>{const e=O.current,t=I.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),P.stopAnimation(),e.initialised&&t.totalMs>0&&!T.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[P]);const B=useCallback((e,t)=>{k.current[e]=t,H()},[H]),F=useCallback(()=>B("touch",!0),[B]),z=useCallback(e=>B("touch",(e.nativeEvent.touches?.length??0)>0),[B]),U=useCallback(()=>B("hover",!0),[B]),$=useCallback(()=>B("hover",!1),[B]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>B("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(w,t.dx);const n=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(S,n)},onPanResponderTerminate:()=>{if(B("pan",!1),r.reduced)return setNativeValue(w,0),void Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start();Animated.parallel([Animated.spring(w,{toValue:0,damping:a.motion.spring.snappy.damping,stiffness:a.motion.spring.snappy.stiffness,mass:a.motion.spring.snappy.mass,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,i)=>{if(Math.abs(i.dx)>80||Math.abs(i.vx)>.5){const t=i.dx>=0?1:-1;T.current=!0,B("pan",!1);const s=[Animated.timing(S,{toValue:0,duration:o,useNativeDriver:!0})];r.reduced||s.push(Animated.timing(w,{toValue:500*t,duration:a.motion.duration.fast,useNativeDriver:!0})),Animated.parallel(s).start(()=>n(e.id))}else B("pan",!1),r.reduced?(setNativeValue(w,0),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start()):Animated.parallel([Animated.spring(w,{toValue:0,useNativeDriver:!0}),Animated.spring(S,{toValue:1,useNativeDriver:!0})]).start()}}),[w,S,B,o,r.reduced,a.motion.duration.fast,a.motion.spring.snappy.damping,a.motion.spring.snappy.stiffness,a.motion.spring.snappy.mass,n,e.id]),W={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[K,X]=useState(0),Y=useMemo(()=>P.interpolate({inputRange:[0,1],outputRange:[-K,0]}),[P,K]),q=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&j?`${e.action.label}, ${u.seconds(Math.ceil(E/1e3))}`:e.action?.label;return _jsxs(Animated.View,{...A?G.panHandlers:{},...R?{}:{accessible:!0,...W},..."web"===Platform.OS?{onPointerEnter:U,onPointerLeave:$}:{},onTouchStart:F,onTouchEnd:z,onTouchCancel:z,accessibilityLabel:q,testID:e.testID,style:[m.container,{backgroundColor:a.colors.surface,borderRadius:a.radius.lg,...smoothCorners,padding:a.space.md,...a.shadow.elevated,opacity:S,transform:[{translateY:D},{translateX:w},{scale:M}]},e.style],children:[b>0?_jsx(View,{style:[m.tintBar,{width:b,backgroundColor:p}]}):null,_jsxs(View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[m.iconCircle,{width:h,height:h,borderRadius:a.radius.pill,...smoothCorners,backgroundColor:`${p}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[m.iconGlyph,{color:g,fontSize:f}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:m.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[m.message,e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...W,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?a.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:p},numberOfLines:1,children:e.action.label})}):null]}),j?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>X(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${p}22`}],children:[r.reduced?_jsx(View,{style:[m.countdownFill,{backgroundColor:p}]}):null,!r.reduced&&K>0?_jsx(Animated.View,{style:[m.countdownFill,{backgroundColor:p,transform:[{translateX:Y}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOAST_LABELS=Object.freeze({dismiss:"Dismiss",undo:"Undo",seconds:e=>`${e} seconds`});const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:i,shownAt:n,runtime:a})=>{const s=useTheme(),r=usePresenceMotion(),o=r.duration("fast");assertValidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=a?.labels??DEFAULT_TOAST_LABELS,d=useMemo(()=>[{name:"dismiss",label:u.dismiss}],[u]),m=useMemo(()=>buildStyles(s),[s]),p=useMemo(()=>tintFor(s,l),[s,l]),g=useMemo(()=>inkFor(s,l),[s,l]),v=s.components.toast["icon-circle-size"],h=s.text[s.components.toast["icon-glyph-text"]].size,f=s.components.toast["tint-bar-width"],b=s.settings.components.toast?.defaultDurationMs??3e3,A=s.settings.components.toast?.enableSwipeDismiss??!0,x="top"===c?-120:120,y=useRef(createAnimatedValue(r.reduced?0:x)).current,w=useRef(createAnimatedValue(0)).current,D=useRef(createAnimatedValue(0)).current,S=useRef(!1),T="top"===c?8*t:8*-t,V=Math.max(1-.04*t,.9),M=useRef(createAnimatedValue(T)).current;useEffect(()=>{setNativeValue(M,T)},[T,M]);const _=useMemo(()=>Animated.add(y,M),[y,M]),R=void 0!==e.action,C=e.duration??b,E=C>0&&R&&"web"===Platform.OS?Math.max(C,8e3):C,N=E<=0||R&&!0===a?.screenReaderOn,j=!0===e.countdown&&!N,P=useRef(createAnimatedValue(1)).current,O=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),k=useRef({touch:!1,pan:!1,hover:!1}),L=useRef(()=>{}),I=useRef({id:e.id,totalMs:E,shownAt:n,runtime:a,persistent:N,animateBar:!1});I.current={id:e.id,totalMs:E,shownAt:n,runtime:a,persistent:N,animateBar:j&&!r.reduced};const H=useCallback(()=>{const e=O.current,t=I.current,i=k.current;if(!e.initialised){e.initialised=!0;const i=t.runtime?.readRemaining(t.id),n=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=i??(t.totalMs>0?Math.max(t.totalMs-n,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(P,e.remaining/t.totalMs)}const n=!(t.persistent||S.current||i.touch||i.pan||i.hover);n&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,L.current()},e.remaining),t.animateBar&&Animated.timing(P,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:nativeDriver}).start()):n||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),P.stopAnimation())},[P]),dismiss=()=>{if(S.current)return;S.current=!0,H();const t=[Animated.timing(D,{toValue:0,duration:o,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:nativeDriver})];r.reduced||t.push(Animated.timing(y,{toValue:x,duration:s.motion.duration.fast,easing:Easing.bezier(...s.motion.ease.accelerate),useNativeDriver:nativeDriver})),Animated.parallel(t).start(()=>i(e.id))};L.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.spring(y,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{H()},[N,H]),useEffect(()=>()=>{const e=O.current,t=I.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),P.stopAnimation(),e.initialised&&t.totalMs>0&&!S.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[P]);const B=useCallback((e,t)=>{k.current[e]=t,H()},[H]),F=useCallback(()=>B("touch",!0),[B]),z=useCallback(e=>B("touch",(e.nativeEvent.touches?.length??0)>0),[B]),U=useCallback(()=>B("hover",!0),[B]),$=useCallback(()=>B("hover",!1),[B]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>B("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(w,t.dx);const i=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(D,i)},onPanResponderTerminate:()=>{if(B("pan",!1),r.reduced)return setNativeValue(w,0),void Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start();Animated.parallel([Animated.spring(w,{toValue:0,damping:s.motion.spring.snappy.damping,stiffness:s.motion.spring.snappy.stiffness,mass:s.motion.spring.snappy.mass,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]).start()},onPanResponderRelease:(t,n)=>{if(Math.abs(n.dx)>80||Math.abs(n.vx)>.5){const t=n.dx>=0?1:-1;S.current=!0,B("pan",!1);const a=[Animated.timing(D,{toValue:0,duration:o,useNativeDriver:nativeDriver})];r.reduced||a.push(Animated.timing(w,{toValue:500*t,duration:s.motion.duration.fast,useNativeDriver:nativeDriver})),Animated.parallel(a).start(()=>i(e.id))}else B("pan",!1),r.reduced?(setNativeValue(w,0),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start()):Animated.parallel([Animated.spring(w,{toValue:0,useNativeDriver:nativeDriver}),Animated.spring(D,{toValue:1,useNativeDriver:nativeDriver})]).start()}}),[w,D,B,o,r.reduced,s.motion.duration.fast,s.motion.spring.snappy.damping,s.motion.spring.snappy.stiffness,s.motion.spring.snappy.mass,i,e.id]),W={accessibilityActions:d,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[K,X]=useState(0),Y=useMemo(()=>P.interpolate({inputRange:[0,1],outputRange:[-K,0]}),[P,K]),q=e.description?`${e.message}. ${e.description}`:e.message,J=e.action&&j?`${e.action.label}, ${u.seconds(Math.ceil(E/1e3))}`:e.action?.label;return _jsxs(Animated.View,{...A?G.panHandlers:{},...R?{}:{accessible:!0,...W},..."web"===Platform.OS?{onPointerEnter:U,onPointerLeave:$}:{},onTouchStart:F,onTouchEnd:z,onTouchCancel:z,accessibilityLabel:q,testID:e.testID,style:[m.container,{backgroundColor:s.colors.surface,borderRadius:s.radius.lg,...smoothCorners,padding:s.space.md,...s.shadow.elevated,opacity:D,transform:[{translateY:_},{translateX:w},{scale:V}]},e.style],children:[f>0?_jsx(View,{style:[m.tintBar,{width:f,backgroundColor:p}]}):null,_jsxs(View,{style:m.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[m.iconCircle,{width:v,height:v,borderRadius:s.radius.pill,...smoothCorners,backgroundColor:`${p}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[m.iconGlyph,{color:g,fontSize:h}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:m.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[m.message,e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:m.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:J,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...W,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[m.actionBtn,{backgroundColor:t?s.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:p},numberOfLines:1,children:e.action.label})}):null]}),j?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>X(e.nativeEvent.layout.width),testID:"toast-countdown",style:[m.countdownTrack,{backgroundColor:`${p}22`}],children:[r.reduced?_jsx(View,{style:[m.countdownFill,{backgroundColor:p}]}):null,!r.reduced&&K>0?_jsx(Animated.View,{style:[m.countdownFill,{backgroundColor:p,transform:[{translateX:Y}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;case"neutral":return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];case"neutral":return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";case"primary":case"neutral":return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Platform,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import Toast,{DEFAULT_TOAST_LABELS}from"./Toast.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MAX_VISIBLE=3,UNDO_DEFAULT_DURATION_MS=6e3,UNDO_MIN_DURATION_MS=6e3,ToastContext=createContext(null),ToastHostContext=createContext(null);let nextId=0;const makeId=()=>(nextId+=1,`toast-${Date.now().toString(36)}-${nextId.toString(36)}`),defaultHaptic=e=>{switch(e){case"danger":return"notificationError";case"success":return"notificationSuccess";case"warning":return"notificationWarning";default:return"selection"}},resolveHaptics=(e,t)=>{if(!1===e)return!1;const o=e?.[t??"neutral"];return void 0===o?defaultHaptic(t):o};let nextHostId=0;const makeHostId=()=>(nextHostId+=1,nextHostId),useScreenReaderEnabled=()=>{const[e,t]=useState(!1);return useEffect(()=>{if("web"===Platform.OS)return;let e=!0;AccessibilityInfo.isScreenReaderEnabled().then(o=>{e&&t(o)});const o=AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,o.remove()}},[]),e};let providerCount=0,activeApi=null;const setActiveApi=e=>{activeApi=e},getActiveApi=()=>activeApi;export const ToastProvider=({children:e,maxVisible:t=3,topOffset:o,bottomOffset:s,defaultDuration:r,haptics:n,labels:a})=>{const i=useMemo(()=>({...DEFAULT_TOAST_LABELS,...a}),[a]),u=useRef({defaultDuration:r,haptics:n,labels:i});u.current={defaultDuration:r,haptics:n,labels:i};const[c,l]=useState([]),[d,f]=useState([]),m=useScreenReaderEnabled(),p=useRef(new Map),h=useRef(new Map);useEffect(()=>{const e=new Set(c.map(e=>e.id));for(const[t,o]of[...p.current])e.has(t)||(p.current.delete(t),o());for(const t of[...h.current.keys()])e.has(t)||h.current.delete(t)},[c]),useEffect(()=>{const e=p.current;return()=>{for(const[t,o]of[...e])e.delete(t),o()}},[]);const g=useMemo(()=>({screenReaderOn:m,labels:i,readRemaining:e=>h.current.get(e),writeRemaining:(e,t)=>{h.current.set(e,t)}}),[m,i]),x=useCallback(e=>{l(t=>t.filter(t=>t.id!==e))},[]),b=useCallback(()=>{l([])},[]),w=useCallback(e=>{const o=makeId(),{defaultDuration:s,haptics:r}=u.current,n={...e,duration:e.duration??s,id:o,shownAt:Date.now()},a=void 0!==e.haptic?e.haptic:resolveHaptics(r,e.tone);return!1!==a&&triggerHaptic(a),announce(e.description?`${e.message}. ${e.description}`:e.message,{polite:"danger"!==e.tone}),l(o=>{const s=[...void 0===e.key?o:o.filter(t=>t.key!==e.key),n];return s.length>t?s.slice(s.length-t):s}),o},[t]),v=useCallback((e,t)=>{const{onUndo:o,onCommit:s,duration:r,...n}=t,a={id:""},i=w({...n,message:e,duration:0===r?0:Math.max(r??6e3,6e3),countdown:!0,action:{label:u.current.labels.undo,onPress:()=>{p.current.delete(a.id),o()}}});return a.id=i,s&&p.current.set(i,s),i},[w]),_=useMemo(()=>({show:w,undo:v,hide:x,hideAll:b}),[w,v,x,b]);useEffect(()=>(providerCount+=1,setActiveApi(_),()=>{providerCount-=1,providerCount<=0&&(providerCount=0,setActiveApi(null))}),[_]);const A=useCallback(e=>{f(t=>[...t,e])},[]),y=useCallback(e=>{f(t=>t.filter(t=>t!==e))},[]),T=d.length>0?d[d.length-1]:null,C=useMemo(()=>({register:A,unregister:y,activeHostId:T,queue:c,hide:x,topOffset:o,bottomOffset:s,runtime:g}),[A,y,T,c,x,o,s,g]);return _jsx(ToastContext.Provider,{value:_,children:_jsxs(ToastHostContext.Provider,{value:C,children:[e,null===T?_jsx(ToastLayers,{queue:c,onDismiss:x,topOffset:o,bottomOffset:s,runtime:g}):null]})})};let warnedHost=!1;const warnHostWithoutProvider=()=>{warnedHost||(warnedHost=!0,"undefined"!=typeof __DEV__&&__DEV__&&Logger.warn("[@webority/mobile-ui] Toast: <ToastHost /> rendered outside a <ToastProvider />; it renders nothing. Mount a provider near your app root."))};export const ToastHost=()=>{const e=useContext(ToastHostContext),[t]=useState(makeHostId),o=e?.register,s=e?.unregister;return useEffect(()=>{if(o&&s)return o(t),()=>s(t);warnHostWithoutProvider()},[o,s,t]),e&&e.activeHostId===t?_jsx(ToastLayers,{queue:e.queue,onDismiss:e.hide,topOffset:e.topOffset,bottomOffset:e.bottomOffset,runtime:e.runtime}):null};const ToastLayers=({queue:e,onDismiss:t,topOffset:o,bottomOffset:s,runtime:r})=>{const n=useTheme(),a=useSafeAreaInsets(),i=useMemo(()=>buildStyles(),[]),u=e.filter(e=>"top"===(e.position??"bottom")),c=e.filter(e=>"bottom"===(e.position??"bottom"));return _jsxs(_Fragment,{children:[_jsx(View,{testID:"toast-layer-top",pointerEvents:"box-none",style:[i.layer,i.top,{top:(o??a.top)+n.space.sm,paddingHorizontal:n.space.md}],children:u.map((e,o)=>_jsx(Toast,{toast:e,index:u.length-1-o,shownAt:e.shownAt,runtime:r,onClose:t},e.id))}),_jsx(View,{testID:"toast-layer-bottom",pointerEvents:"box-none",style:[i.layer,i.bottom,{bottom:(s??a.bottom)+n.space.sm,paddingHorizontal:n.space.md}],children:c.map((e,o)=>_jsx(Toast,{toast:e,index:c.length-1-o,shownAt:e.shownAt,runtime:r,onClose:t},e.id))})]})};export const useToast=()=>{const e=useContext(ToastContext);if(!e)throw new Error("useToast must be used within a <ToastProvider>.");return e};let warned=!1;const warnNoProvider=()=>{warned||(warned=!0,"undefined"!=typeof __DEV__&&__DEV__&&Logger.warn("[@webority/mobile-ui] Toast: no <ToastProvider /> mounted; toast() calls are no-ops. Mount a provider near your app root."))},proxy=e=>{const t=getActiveApi();return t?e(t):(warnNoProvider(),"")};export const toast={show:e=>proxy(t=>t.show(e)),undo:(e,t)=>proxy(o=>o.undo(e,t)),success:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"success"})),error:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"danger"})),warning:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"warning"})),info:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"info"})),hideAll:()=>{const e=getActiveApi();e?e.hideAll():warnNoProvider()}};const buildStyles=()=>StyleSheet.create({layer:{position:"absolute",left:0,right:0},top:{alignItems:"stretch"},bottom:{alignItems:"stretch"}});
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Platform,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import Toast,{DEFAULT_TOAST_LABELS}from"./Toast.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MAX_VISIBLE=3,UNDO_DEFAULT_DURATION_MS=6e3,UNDO_MIN_DURATION_MS=6e3,ToastContext=createContext(null),ToastHostContext=createContext(null);let nextId=0;const makeId=()=>(nextId+=1,`toast-${Date.now().toString(36)}-${nextId.toString(36)}`),defaultHaptic=e=>{switch(e){case"danger":return"notificationError";case"success":return"notificationSuccess";case"warning":return"notificationWarning";case"info":case"primary":case"neutral":case void 0:return"selection"}},resolveHaptics=(e,t)=>{if(!1===e)return!1;const o=e?.[t??"neutral"];return void 0===o?defaultHaptic(t):o};let nextHostId=0;const makeHostId=()=>(nextHostId+=1,nextHostId),useScreenReaderEnabled=()=>{const[e,t]=useState(!1);return useEffect(()=>{if("web"===Platform.OS)return;let e=!0;AccessibilityInfo.isScreenReaderEnabled().then(o=>{e&&t(o)});const o=AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,o.remove()}},[]),e};let providerCount=0,activeApi=null;const setActiveApi=e=>{activeApi=e},getActiveApi=()=>activeApi;export const ToastProvider=({children:e,maxVisible:t=3,topOffset:o,bottomOffset:s,defaultDuration:r,haptics:n,labels:a})=>{const i=useMemo(()=>({...DEFAULT_TOAST_LABELS,...a}),[a]),u=useRef({defaultDuration:r,haptics:n,labels:i});u.current={defaultDuration:r,haptics:n,labels:i};const[c,l]=useState([]),[d,m]=useState([]),f=useScreenReaderEnabled(),p=useRef(new Map),h=useRef(new Map);useEffect(()=>{const e=new Set(c.map(e=>e.id));for(const[t,o]of[...p.current])e.has(t)||(p.current.delete(t),o());for(const t of[...h.current.keys()])e.has(t)||h.current.delete(t)},[c]),useEffect(()=>{const e=p.current;return()=>{for(const[t,o]of[...e])e.delete(t),o()}},[]);const x=useMemo(()=>({screenReaderOn:f,labels:i,readRemaining:e=>h.current.get(e),writeRemaining:(e,t)=>{h.current.set(e,t)}}),[f,i]),g=useCallback(e=>{l(t=>t.filter(t=>t.id!==e))},[]),b=useCallback(()=>{l([])},[]),w=useCallback(e=>{const o=makeId(),{defaultDuration:s,haptics:r}=u.current,n={...e,duration:e.duration??s,id:o,shownAt:Date.now()},a=void 0!==e.haptic?e.haptic:resolveHaptics(r,e.tone);return!1!==a&&triggerHaptic(a),announce(e.description?`${e.message}. ${e.description}`:e.message,{polite:"danger"!==e.tone}),l(o=>{const s=[...void 0===e.key?o:o.filter(t=>t.key!==e.key),n];return s.length>t?s.slice(s.length-t):s}),o},[t]),v=useCallback((e,t)=>{const{onUndo:o,onCommit:s,duration:r,...n}=t,a={id:""},i=w({...n,message:e,duration:0===r?0:Math.max(r??6e3,6e3),countdown:!0,action:{label:u.current.labels.undo,onPress:()=>{p.current.delete(a.id),o()}}});return a.id=i,s&&p.current.set(i,s),i},[w]),_=useMemo(()=>({show:w,undo:v,hide:g,hideAll:b}),[w,v,g,b]);useEffect(()=>(providerCount+=1,setActiveApi(_),()=>{providerCount-=1,providerCount<=0&&(providerCount=0,setActiveApi(null))}),[_]);const A=useCallback(e=>{m(t=>[...t,e])},[]),y=useCallback(e=>{m(t=>t.filter(t=>t!==e))},[]),T=d.at(-1)??null,C=useMemo(()=>({register:A,unregister:y,activeHostId:T,queue:c,hide:g,topOffset:o,bottomOffset:s,runtime:x}),[A,y,T,c,g,o,s,x]);return _jsx(ToastContext.Provider,{value:_,children:_jsxs(ToastHostContext.Provider,{value:C,children:[e,null===T?_jsx(ToastLayers,{queue:c,onDismiss:g,topOffset:o,bottomOffset:s,runtime:x}):null]})})};let warnedHost=!1;const warnHostWithoutProvider=()=>{warnedHost||(warnedHost=!0,"undefined"!=typeof __DEV__&&__DEV__&&Logger.warn("[@webority/mobile-ui] Toast: <ToastHost /> rendered outside a <ToastProvider />; it renders nothing. Mount a provider near your app root."))};export const ToastHost=()=>{const e=useContext(ToastHostContext),[t]=useState(makeHostId),o=e?.register,s=e?.unregister;return useEffect(()=>{if(o&&s)return o(t),()=>s(t);warnHostWithoutProvider()},[o,s,t]),e&&e.activeHostId===t?_jsx(ToastLayers,{queue:e.queue,onDismiss:e.hide,topOffset:e.topOffset,bottomOffset:e.bottomOffset,runtime:e.runtime}):null};const ToastLayers=({queue:e,onDismiss:t,topOffset:o,bottomOffset:s,runtime:r})=>{const n=useTheme(),a=useSafeAreaInsets(),i=useMemo(()=>buildStyles(),[]),u=e.filter(e=>"top"===(e.position??"bottom")),c=e.filter(e=>"bottom"===(e.position??"bottom"));return _jsxs(_Fragment,{children:[_jsx(View,{testID:"toast-layer-top",pointerEvents:"box-none",style:[i.layer,i.top,{top:(o??a.top)+n.space.sm,paddingHorizontal:n.space.md}],children:u.map((e,o)=>_jsx(Toast,{toast:e,index:u.length-1-o,shownAt:e.shownAt,runtime:r,onClose:t},e.id))}),_jsx(View,{testID:"toast-layer-bottom",pointerEvents:"box-none",style:[i.layer,i.bottom,{bottom:(s??a.bottom)+n.space.sm,paddingHorizontal:n.space.md}],children:c.map((e,o)=>_jsx(Toast,{toast:e,index:c.length-1-o,shownAt:e.shownAt,runtime:r,onClose:t},e.id))})]})};export const useToast=()=>{const e=useContext(ToastContext);if(!e)throw new Error("useToast must be used within a <ToastProvider>.");return e};let warned=!1;const warnNoProvider=()=>{warned||(warned=!0,"undefined"!=typeof __DEV__&&__DEV__&&Logger.warn("[@webority/mobile-ui] Toast: no <ToastProvider /> mounted; toast() calls are no-ops. Mount a provider near your app root."))},proxy=e=>{const t=getActiveApi();return t?e(t):(warnNoProvider(),"")};export const toast={show:e=>proxy(t=>t.show(e)),undo:(e,t)=>proxy(o=>o.undo(e,t)),success:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"success"})),error:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"danger"})),warning:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"warning"})),info:(e,t)=>proxy(o=>o.show({...t,message:e,tone:"info"})),hideAll:()=>{const e=getActiveApi();e?e.hideAll():warnNoProvider()}};const buildStyles=()=>StyleSheet.create({layer:{position:"absolute",left:0,right:0},top:{alignItems:"stretch"},bottom:{alignItems:"stretch"}});
@@ -1 +1 @@
1
- "use strict";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{claimAnchoredSurface}from"../../utils/placement.js";import{FOCUS_DELAY_MS,focusHost}from"../Menu/focusHost.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{RichTooltipBody}from"./RichTooltipBody.js";import{resolveTooltipPosition}from"./tooltipPosition.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_TOOLTIP_LABELS=Object.freeze({close:"Close tooltip",longPressHint:"Long press for more info",fallbackName:"Tooltip"});const PRESS_AUTO_HIDE_MS=4e3,ARROW_HALF_WIDTH=4,ARROW_HEIGHT=6,ARROW_CORNER_PADDING=12,DEFAULT_MAX_WIDTH=240,RICH_MAX_WIDTH=280,MESSAGE_LINE_HEIGHT=18,EXIT_DURATION_MS=150,Tooltip=e=>{const{content:t,children:o,variant:r="plain",title:s,action:n,placement:i="auto",open:a,onOpenChange:l,hideOnContentPress:u=!0,maxWidth:c,showArrow:m=!0,accessibilityLabel:p,style:f,containerStyle:d,arrowStyle:h,messageStyle:g,labels:b,testID:T}=e;assertValidValue("Tooltip","variant",e.variant,["plain","rich"]),assertValidValue("Tooltip","placement",e.placement,["top","bottom","left","right","auto"]),assertValidValue("Tooltip","trigger",e.trigger,["longPress","press","manual"]);const S="rich"===r,y=e.trigger??(S?"press":"longPress"),R=useMemo(()=>({...DEFAULT_TOOLTIP_LABELS,...b}),[b]),A=useTheme(),_=usePresenceMotion(),w=useSafeAreaInsets(),[v,x]=useModalInsets(),j=useMemo(()=>({...w,top:v.top,bottom:v.bottom}),[w,v]),C=useWindowDimensions(),E=useMemo(()=>buildStyles(A),[A]),M=A.space.sm,P=A.space.sm,V=c??(S?280:240),L="press"===y&&!S,O=(A.settings.components.tooltip?.enableScaleAnimation??!1)&&!_.reduced,D="manual"===y||"boolean"==typeof a,[I,H]=useState(!1),W=D?Boolean(a):I,[k,N]=useState(null),[F,B]=useState({width:0,height:0}),U=useRef(null),z=useRef(null),G=useRef(null),X=useRef(null),Y=useRef(null),q=useRef(!1),J=useRef(!1),K=useRef(createAnimatedValue(W||!O?1:.85)).current,Q=useRef(createAnimatedValue(W?1:0)).current,Z=useRef(null),$=useRef(!1),[ee,te]=useState(W),oe=useCallback(e=>{D||H(e),l?.(e)},[D,l]),re=useCallback(()=>{U.current&&U.current.measureInWindow((e,t,o,r)=>{N({x:e,y:t,width:o,height:r})})},[]),se=useCallback(e=>{re(),oe(!0)},[re,oe]),ne=useCallback(()=>{oe(!1)},[oe]),ie=useRef(ne);ie.current=ne;const ae=useCallback(()=>{if(!q.current)return;q.current=!1;const e=Y.current;Y.current=null,e?e():S&&focusHost(z.current??U.current)},[S]);useEffect(()=>{if(W)return J.current=!0,q.current=!1,claimAnchoredSurface(()=>ie.current());J.current&&(J.current=!1,q.current=!0)},[W]),useEffect(()=>{W&&te(!0)},[W]);const le=useCallback(()=>{Y.current=n?.onPress??null,ne()},[n,ne]);useEffect(()=>{if(!$.current)return $.current=!0,W&&(re(),L&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))),()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)};let e;if(W){re();const t=[Animated.timing(Q,{toValue:1,duration:_.duration("fast"),useNativeDriver:!0})];O?t.push(Animated.spring(K,{toValue:1,damping:A.motion.spring.snappy.damping,stiffness:A.motion.spring.snappy.stiffness,mass:A.motion.spring.snappy.mass,useNativeDriver:!0})):setNativeValue(K,1),e=Animated.parallel(t),e.start(),L&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))}else{const t=[Animated.timing(Q,{toValue:0,duration:_.reduced?_.duration("fast"):150,easing:Easing.bezier(...A.motion.ease.accelerate),useNativeDriver:!0})];O&&t.push(Animated.timing(K,{toValue:.85,duration:150,easing:Easing.bezier(...A.motion.ease.accelerate),useNativeDriver:!0})),e=Animated.parallel(t),e.start(({finished:e})=>{e&&te(!1)}),Z.current&&(clearTimeout(Z.current),Z.current=null)}return()=>{e?.stop(),Z.current&&(clearTimeout(Z.current),Z.current=null)}},[W]);const handleContentLayout=e=>{const{width:t,height:o}=e.nativeEvent.layout;t===F.width&&o===F.height||B({width:t,height:o})},ue=useMemo(()=>resolveTooltipPosition({anchor:k,size:F,placement:i,rich:S,viewport:{width:C.width,height:C.height,insets:j},maxWidth:V,gap:M,padding:P,arrowCornerPadding:12}),[k,F,i,S,C.width,C.height,j,V,M,P]),ce=null!==k&&F.width>0,me=W&&ce;useEffect(()=>{if(!S||!me)return;const e="web"===Platform.OS?X:G,t=setTimeout(()=>focusHost(e.current),FOCUS_DELAY_MS);return()=>clearTimeout(t)},[S,me]),useEffect(()=>{!S&&me&&"ios"===Platform.OS&&"string"==typeof t&&announce(t)},[S,me,t]);const pe=o.props,fe=useMemo(()=>mergeRefs(pe.ref,z),[pe.ref]),de={};"longPress"!==y||pe.contextMenu?"press"===y&&(de.onPress=e=>{pe.onPress?.(e),se(e)}):(de.onLongPress=se,de.accessibilityHint=R.longPressHint),S&&(de.ref=fe);const he=React.cloneElement(o,de),ge=p??("string"==typeof t?t:R.fallbackName),be=useMemo(()=>{if(!m)return null;const e={position:"absolute",width:0,height:0,backgroundColor:"transparent",borderStyle:"solid",borderLeftWidth:4,borderRightWidth:4,borderBottomWidth:6,borderTopWidth:0,borderLeftColor:"transparent",borderRightColor:"transparent",borderTopColor:"transparent",borderBottomColor:S?A.colors.surface:A.colors["surface-inverse"]};return"top"===ue.placement?{...e,bottom:-6,left:ue.arrowOffset-4,transform:[{rotate:"180deg"}]}:"bottom"===ue.placement?{...e,top:-6,left:ue.arrowOffset-4}:"left"===ue.placement?{...e,right:-6,top:ue.arrowOffset-4,transform:[{rotate:"90deg"}]}:{...e,left:-6,top:ue.arrowOffset-4,transform:[{rotate:"-90deg"}]}},[m,ue,A,S]),Te={position:"absolute",top:ue.top,left:ue.left,maxWidth:V,opacity:W&&!ce?0:Q,transform:[{scale:K}]},Se=be?_jsx(View,{style:[be,h],pointerEvents:"none"}):null;return _jsxs(_Fragment,{children:[_jsx(View,{ref:U,collapsable:!1,onLayout:re,testID:T,children:he}),_jsxs(Modal,{open:ee,onClose:ne,presentation:"fullScreen",bare:!0,backdropOpacity:0,backdropPressClose:u,haptic:!1,labels:{close:R.close},onInsetsChange:x,onDismissed:ae,children:[ee&&S?_jsxs(Animated.View,{onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(RichTooltipBody,{title:s,content:t,action:n,onAction:le,focusRef:G,actionRef:X,messageStyle:g}),Se]}):null,ee&&!S?_jsxs(Animated.View,{accessibilityRole:"web"===Platform.OS?"tooltip":void 0,accessibilityLiveRegion:"polite",accessibilityLabel:ge,onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(View,{style:[E.tooltip,{backgroundColor:A.colors["surface-inverse"],borderRadius:A.radius.md,...smoothCorners,paddingHorizontal:A.space.md,paddingVertical:A.space.sm,...A.shadow.popover,shadowColor:A.shadow.popover.shadowColor}],children:"string"==typeof t?_jsx(Text,{variant:"bodySmall",color:"inverse",style:{lineHeight:18,...StyleSheet.flatten(g)},children:t}):t}),Se]}):null]})]})},buildStyles=e=>StyleSheet.create({tooltip:{overflow:"hidden"}});export{Tooltip};export default Tooltip;
1
+ "use strict";import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{claimAnchoredSurface}from"../../utils/placement.js";import{FOCUS_DELAY_MS,focusHost}from"../Menu/focusHost.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{RichTooltipBody}from"./RichTooltipBody.js";import{resolveTooltipPosition}from"./tooltipPosition.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_TOOLTIP_LABELS=Object.freeze({close:"Close tooltip",longPressHint:"Long press for more info",fallbackName:"Tooltip"});const PRESS_AUTO_HIDE_MS=4e3,ARROW_HALF_WIDTH=4,ARROW_HEIGHT=6,ARROW_CORNER_PADDING=12,DEFAULT_MAX_WIDTH=240,RICH_MAX_WIDTH=280,MESSAGE_LINE_HEIGHT=18,EXIT_DURATION_MS=150,Tooltip=e=>{const{content:t,children:r,variant:o="plain",title:s,action:n,placement:i="auto",open:a,onOpenChange:l,hideOnContentPress:u=!0,maxWidth:c,showArrow:m=!0,accessibilityLabel:p,style:f,containerStyle:d,arrowStyle:h,messageStyle:g,labels:b,testID:T}=e;assertValidValue("Tooltip","variant",e.variant,["plain","rich"]),assertValidValue("Tooltip","placement",e.placement,["top","bottom","left","right","auto"]),assertValidValue("Tooltip","trigger",e.trigger,["longPress","press","manual"]);const v="rich"===o,S=e.trigger??(v?"press":"longPress"),y=useMemo(()=>({...DEFAULT_TOOLTIP_LABELS,...b}),[b]),R=useTheme(),A=usePresenceMotion(),_=useSafeAreaInsets(),[w,j]=useModalInsets(),x=useMemo(()=>({..._,top:w.top,bottom:w.bottom}),[_,w]),C=useWindowDimensions(),E=useMemo(()=>buildStyles(R),[R]),D=R.space.sm,M=R.space.sm,P=c??(v?280:240),V="press"===S&&!v,L=(R.settings.components.tooltip?.enableScaleAnimation??!1)&&!A.reduced,O="manual"===S||"boolean"==typeof a,[I,H]=useState(!1),W=O?Boolean(a):I,[k,N]=useState(null),[F,B]=useState({width:0,height:0}),U=useRef(null),z=useRef(null),G=useRef(null),X=useRef(null),Y=useRef(null),q=useRef(!1),J=useRef(!1),K=useRef(createAnimatedValue(W||!L?1:.85)).current,Q=useRef(createAnimatedValue(W?1:0)).current,Z=useRef(null),$=useRef(!1),[ee,te]=useState(W),re=useCallback(e=>{O||H(e),l?.(e)},[O,l]),oe=useCallback(()=>{U.current&&U.current.measureInWindow((e,t,r,o)=>{N({x:e,y:t,width:r,height:o})})},[]),se=useCallback(e=>{oe(),re(!0)},[oe,re]),ne=useCallback(()=>{re(!1)},[re]),ie=useRef(ne);ie.current=ne;const ae=useCallback(()=>{if(!q.current)return;q.current=!1;const e=Y.current;Y.current=null,e?e():v&&focusHost(z.current??U.current)},[v]);useEffect(()=>{if(W)return J.current=!0,q.current=!1,claimAnchoredSurface(()=>ie.current());J.current&&(J.current=!1,q.current=!0)},[W]),useEffect(()=>{W&&te(!0)},[W]);const le=useCallback(()=>{Y.current=n?.onPress??null,ne()},[n,ne]);useEffect(()=>{if(!$.current)return $.current=!0,W&&(oe(),V&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))),()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)};let e;if(W){oe();const t=[Animated.timing(Q,{toValue:1,duration:A.duration("fast"),useNativeDriver:nativeDriver})];L?t.push(Animated.spring(K,{toValue:1,damping:R.motion.spring.snappy.damping,stiffness:R.motion.spring.snappy.stiffness,mass:R.motion.spring.snappy.mass,useNativeDriver:nativeDriver})):setNativeValue(K,1),e=Animated.parallel(t),e.start(),V&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ne()},4e3))}else{const t=[Animated.timing(Q,{toValue:0,duration:A.reduced?A.duration("fast"):150,easing:Easing.bezier(...R.motion.ease.accelerate),useNativeDriver:nativeDriver})];L&&t.push(Animated.timing(K,{toValue:.85,duration:150,easing:Easing.bezier(...R.motion.ease.accelerate),useNativeDriver:nativeDriver})),e=Animated.parallel(t),e.start(({finished:e})=>{e&&te(!1)}),Z.current&&(clearTimeout(Z.current),Z.current=null)}return()=>{e?.stop(),Z.current&&(clearTimeout(Z.current),Z.current=null)}},[W]);const handleContentLayout=e=>{const{width:t,height:r}=e.nativeEvent.layout;t===F.width&&r===F.height||B({width:t,height:r})},ue=useMemo(()=>resolveTooltipPosition({anchor:k,size:F,placement:i,rich:v,viewport:{width:C.width,height:C.height,insets:x},maxWidth:P,gap:D,padding:M,arrowCornerPadding:12}),[k,F,i,v,C.width,C.height,x,P,D,M]),ce=null!==k&&F.width>0,me=W&&ce;useEffect(()=>{if(!v||!me)return;const e="web"===Platform.OS?X:G,t=setTimeout(()=>focusHost(e.current),FOCUS_DELAY_MS);return()=>clearTimeout(t)},[v,me]),useEffect(()=>{!v&&me&&"ios"===Platform.OS&&"string"==typeof t&&announce(t)},[v,me,t]);const pe=r.props,fe=useMemo(()=>mergeRefs(pe.ref,z),[pe.ref]),de={};"longPress"!==S||pe.contextMenu?"press"===S&&(de.onPress=e=>{pe.onPress?.(e),se(e)}):(de.onLongPress=se,de.accessibilityHint=y.longPressHint),v&&(de.ref=fe);const he=React.cloneElement(r,de),ge=p??("string"==typeof t?t:y.fallbackName),be=useMemo(()=>{if(!m)return null;const e={position:"absolute",width:0,height:0,backgroundColor:"transparent",borderStyle:"solid",borderLeftWidth:4,borderRightWidth:4,borderBottomWidth:6,borderTopWidth:0,borderLeftColor:"transparent",borderRightColor:"transparent",borderTopColor:"transparent",borderBottomColor:v?R.colors.surface:R.colors["surface-inverse"]};return"top"===ue.placement?{...e,bottom:-6,left:ue.arrowOffset-4,transform:[{rotate:"180deg"}]}:"bottom"===ue.placement?{...e,top:-6,left:ue.arrowOffset-4}:"left"===ue.placement?{...e,right:-6,top:ue.arrowOffset-4,transform:[{rotate:"90deg"}]}:{...e,left:-6,top:ue.arrowOffset-4,transform:[{rotate:"-90deg"}]}},[m,ue,R,v]),Te={position:"absolute",top:ue.top,left:ue.left,maxWidth:P,opacity:W&&!ce?0:Q,transform:[{scale:K}]},ve=be?_jsx(View,{style:[be,h],pointerEvents:"none"}):null;return _jsxs(_Fragment,{children:[_jsx(View,{ref:U,collapsable:!1,onLayout:oe,testID:T,children:he}),_jsxs(Modal,{open:ee,onClose:ne,presentation:"fullScreen",bare:!0,backdropOpacity:0,backdropPressClose:u,haptic:!1,labels:{close:y.close},onInsetsChange:j,onDismissed:ae,children:[ee&&v?_jsxs(Animated.View,{onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(RichTooltipBody,{title:s,content:t,action:n,onAction:le,focusRef:G,actionRef:X,messageStyle:g}),ve]}):null,ee&&!v?_jsxs(Animated.View,{accessibilityRole:"web"===Platform.OS?"tooltip":void 0,accessibilityLiveRegion:"polite",accessibilityLabel:ge,onLayout:handleContentLayout,style:[Te,d,f],children:[_jsx(View,{style:[E.tooltip,{backgroundColor:R.colors["surface-inverse"],borderRadius:R.radius.md,...smoothCorners,paddingHorizontal:R.space.md,paddingVertical:R.space.sm,...R.shadow.popover,shadowColor:R.shadow.popover.shadowColor}],children:"string"==typeof t?_jsx(Text,{variant:"bodySmall",color:"inverse",style:{lineHeight:18,...StyleSheet.flatten(g)},children:t}):t}),ve]}):null]})]})},buildStyles=e=>StyleSheet.create({tooltip:{overflow:"hidden"}});export{Tooltip};export default Tooltip;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{Button}from"../Button/index.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOUR_LABELS=Object.freeze({back:"Back",next:"Next",skip:"Skip",done:"Done",position:(e,t)=>`Step ${e} of ${t}`});const MAX_CARD_WIDTH=360,HIGHLIGHT_BORDER_WIDTH=2,measureInWindow=e=>new Promise(t=>{const i=e.current;i?i.measureInWindow((e,i,s,n)=>t({x:e,y:i,width:s,height:n})):t(null)}),isOnScreen=(e,t)=>e.width>0&&e.height>0&&e.x<t.width&&e.y<t.height&&e.x+e.width>0&&e.y+e.height>0,Tour=({tourId:e,steps:t,open:i,onClose:s,seenStore:n,labels:r,haptic:o,testID:a})=>{const c=useTheme(),l=usePresenceMotion().duration("fast"),u=useMemo(()=>buildStyles(c),[c]),d=useWindowDimensions(),h=useRef(d);h.current=d;const m=c.space.sm,p=c.space.sm,x=useMemo(()=>({...DEFAULT_TOUR_LABELS,...r}),[r]),[f,b]=useState(null),[g,y]=useState(0),w=useRef(createAnimatedValue(0)).current,j=useRef(t);j.current=t;const S=useRef(x);S.current=x;const _=useRef(s);_.current=s;const k=useRef(n);k.current=n;const T=useCallback(async(e,t)=>{for(let i=e;i>=0&&i<j.current.length;i+=t){const e=await measureInWindow(j.current[i].target);if(e&&isOnScreen(e,h.current))return{index:i,rect:e}}return null},[]);useEffect(()=>{if(!i)return void b(null);let t=!1;return(async()=>{const i=k.current;if(i&&await i.isSeen(e))return void(t||_.current("alreadySeen"));const s=await T(0,1);t||(s?(y(s.index),b(s)):_.current("noTargets"))})(),()=>{t=!0}},[i,e,T]),useEffect(()=>{if(!f)return;const e=j.current[f.index],t=S.current.position(f.index+1,j.current.length);AccessibilityInfo.announceForAccessibility([t,e.title,e.description].filter(Boolean).join(". ")),w.setValue(0);const i=Animated.timing(w,{toValue:1,duration:l,useNativeDriver:!0});return i.start(),()=>i.stop()},[f,w,l]);const v=useCallback(async t=>{b(null),await(k.current?.markSeen(e)),_.current(t)},[e]),C=useCallback(async()=>{if(!f)return;const e=await T(f.index+1,1);e?b(e):await v("finished")},[f,T,v]),D=useCallback(async()=>{if(!f)return;const e=await T(f.index-1,-1);e&&b(e)},[f,T]),M=useCallback(()=>{v("skipped")},[v]),R=f?t[f.index]:void 0,I=!!f&&f.index===t.length-1,A=c.space.xs,V=f?{x:f.rect.x-A,y:f.rect.y-A,width:f.rect.width+2*A,height:f.rect.height+2*A}:null,B=Math.min(d.width-2*p,360),E=V?(()=>{const e=V.x+V.width/2,t=Math.max(p,Math.min(e-B/2,d.width-B-p)),i=V.y,s=d.height-(V.y+V.height);return s>=i?{left:t,top:V.y+V.height+m,maxHeight:Math.max(s-m-p,0)}:{left:t,bottom:d.height-V.y+m,maxHeight:Math.max(i-m-p,0)}})():null,L=c.colors.scrim,W=V?Math.min(R?.radius?c.radius[R.radius]+A:c.radius.md,Math.min(V.width,V.height)/2):0,P=Math.max(d.width,d.height);return _jsx(Modal,{open:null!==f,onClose:M,presentation:"fullScreen",backdropPressClose:!1,backdropStyle:u.transparent,contentStyle:u.transparent,accessibilityLabel:R?.title??R?.description,haptic:o,testID:a,children:V&&E&&R?_jsxs(View,{style:StyleSheet.absoluteFill,children:[_jsx(View,{style:[u.dim,{borderColor:L,borderWidth:P,top:V.y-P,left:V.x-P,width:V.width+2*P,height:V.height+2*P,borderRadius:W+P}]}),_jsx(View,{pointerEvents:"none",style:[u.highlight,{top:V.y,left:V.x,width:V.width,height:V.height,borderRadius:W}]}),_jsxs(Animated.View,{accessibilityLiveRegion:"polite",style:[u.card,E,{width:B,opacity:w}],testID:a?`${a}-card`:void 0,children:[_jsx(Text,{variant:"caption",children:x.position((f?.index??0)+1,t.length)}),R.title?_jsx(Text,{variant:"title",accessibilityRole:"header",children:R.title}):null,_jsx(Text,{variant:"bodySmall",children:R.description}),_jsxs(View,{style:u.actions,children:[_jsx(Button,{label:x.skip,variant:"ghost",size:"sm",haptic:o,onPress:M,testID:a?`${a}-skip`:void 0}),_jsxs(View,{style:u.navigation,children:[f&&f.index>g?_jsx(Button,{label:x.back,variant:"outline",size:"sm",haptic:o,onPress:()=>{D()},testID:a?`${a}-back`:void 0}):null,_jsx(Button,{label:I?x.done:x.next,size:"sm",haptic:o,onPress:()=>{C()},testID:a?`${a}-next`:void 0})]})]})]})]}):null})};Tour.displayName="Tour";const buildStyles=e=>StyleSheet.create({transparent:{backgroundColor:"transparent"},dim:{position:"absolute"},highlight:{position:"absolute",borderWidth:2,borderColor:e.colors.primary,borderRadius:e.radius.md,...smoothCorners},card:{position:"absolute",backgroundColor:e.colors.surface,borderRadius:e.radius.lg,...smoothCorners,padding:e.space.lg,gap:e.space.sm,...e.shadow.popover},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginTop:e.space.xs},navigation:{flexDirection:"row",gap:e.space.sm}});export{Tour};export default Tour;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Button}from"../Button/index.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TOUR_LABELS=Object.freeze({back:"Back",next:"Next",skip:"Skip",done:"Done",position:(e,t)=>`Step ${e} of ${t}`});const MAX_CARD_WIDTH=360,HIGHLIGHT_BORDER_WIDTH=2,measureInWindow=e=>new Promise(t=>{const i=e.current;i?i.measureInWindow((e,i,s,r)=>t({x:e,y:i,width:s,height:r})):t(null)}),isOnScreen=(e,t)=>e.width>0&&e.height>0&&e.x<t.width&&e.y<t.height&&e.x+e.width>0&&e.y+e.height>0,Tour=({tourId:e,steps:t,open:i,onClose:s,seenStore:r,labels:n,haptic:o,testID:a})=>{const c=useTheme(),l=usePresenceMotion().duration("fast"),u=useMemo(()=>buildStyles(c),[c]),d=useWindowDimensions(),h=useRef(d);h.current=d;const m=c.space.sm,p=c.space.sm,x=useMemo(()=>({...DEFAULT_TOUR_LABELS,...n}),[n]),[f,g]=useState(null),[w,b]=useState(0),y=useRef(createAnimatedValue(0)).current,j=useRef(t);j.current=t;const v=useRef(x);v.current=x;const S=useRef(s);S.current=s;const T=useRef(r);T.current=r;const _=useCallback(async(e,t)=>{for(let i=e;i>=0&&i<j.current.length;i+=t){const e=j.current[i];if(void 0===e)throw new Error(`Tour: no step at index ${i}, though the loop bound checked it`);const t=await measureInWindow(e.target);if(t&&isOnScreen(t,h.current))return{index:i,rect:t}}return null},[]);useEffect(()=>{if(!i)return void g(null);let t=!1;return(async()=>{const i=T.current;if(i&&await i.isSeen(e))return void(t||S.current("alreadySeen"));const s=await _(0,1);t||(s?(b(s.index),g(s)):S.current("noTargets"))})(),()=>{t=!0}},[i,e,_]),useEffect(()=>{if(!f)return;const e=j.current[f.index];if(void 0===e)throw new Error(`Tour: the current step ${f.index} is missing from the steps list`);const t=v.current.position(f.index+1,j.current.length);AccessibilityInfo.announceForAccessibility([t,e.title,e.description].filter(Boolean).join(". ")),y.setValue(0);const i=Animated.timing(y,{toValue:1,duration:l,useNativeDriver:nativeDriver});return i.start(),()=>i.stop()},[f,y,l]);const k=useCallback(async t=>{g(null),await(T.current?.markSeen(e)),S.current(t)},[e]),D=useCallback(async()=>{if(!f)return;const e=await _(f.index+1,1);e?g(e):await k("finished")},[f,_,k]),C=useCallback(async()=>{if(!f)return;const e=await _(f.index-1,-1);e&&g(e)},[f,_]),M=useCallback(()=>{k("skipped")},[k]),R=f?t[f.index]:void 0,I=!!f&&f.index===t.length-1,A=c.space.xs,E=f?{x:f.rect.x-A,y:f.rect.y-A,width:f.rect.width+2*A,height:f.rect.height+2*A}:null,V=Math.min(d.width-2*p,360),B=E?(()=>{const e=E.x+E.width/2,t=Math.max(p,Math.min(e-V/2,d.width-V-p)),i=E.y,s=d.height-(E.y+E.height);return s>=i?{left:t,top:E.y+E.height+m,maxHeight:Math.max(s-m-p,0)}:{left:t,bottom:d.height-E.y+m,maxHeight:Math.max(i-m-p,0)}})():null,L=c.colors.scrim,W=E?Math.min(R?.radius?c.radius[R.radius]+A:c.radius.md,Math.min(E.width,E.height)/2):0,P=Math.max(d.width,d.height);return _jsx(Modal,{open:null!==f,onClose:M,presentation:"fullScreen",backdropPressClose:!1,backdropStyle:u.transparent,contentStyle:u.transparent,accessibilityLabel:R?.title??R?.description,haptic:o,testID:a,children:E&&B&&R?_jsxs(View,{style:StyleSheet.absoluteFill,children:[_jsx(View,{style:[u.dim,{borderColor:L,borderWidth:P,top:E.y-P,left:E.x-P,width:E.width+2*P,height:E.height+2*P,borderRadius:W+P}]}),_jsx(View,{pointerEvents:"none",style:[u.highlight,{top:E.y,left:E.x,width:E.width,height:E.height,borderRadius:W}]}),_jsxs(Animated.View,{accessibilityLiveRegion:"polite",style:[u.card,B,{width:V,opacity:y}],testID:a?`${a}-card`:void 0,children:[_jsx(Text,{variant:"caption",children:x.position((f?.index??0)+1,t.length)}),R.title?_jsx(Text,{variant:"title",accessibilityRole:"header",children:R.title}):null,_jsx(Text,{variant:"bodySmall",children:R.description}),_jsxs(View,{style:u.actions,children:[_jsx(Button,{label:x.skip,variant:"ghost",size:"sm",haptic:o,onPress:M,testID:a?`${a}-skip`:void 0}),_jsxs(View,{style:u.navigation,children:[f&&f.index>w?_jsx(Button,{label:x.back,variant:"outline",size:"sm",haptic:o,onPress:()=>{C()},testID:a?`${a}-back`:void 0}):null,_jsx(Button,{label:I?x.done:x.next,size:"sm",haptic:o,onPress:()=>{D()},testID:a?`${a}-next`:void 0})]})]})]})]}):null})};Tour.displayName="Tour";const buildStyles=e=>StyleSheet.create({transparent:{backgroundColor:"transparent"},dim:{position:"absolute"},highlight:{position:"absolute",borderWidth:2,borderColor:e.colors.primary,borderRadius:e.radius.md,...smoothCorners},card:{position:"absolute",backgroundColor:e.colors.surface,borderRadius:e.radius.lg,...smoothCorners,padding:e.space.lg,gap:e.space.sm,...e.shadow.popover},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginTop:e.space.xs},navigation:{flexDirection:"row",gap:e.space.sm}});export{Tour};export default Tour;