@webority/mobile-ui 0.148.0 → 0.149.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 (46) hide show
  1. package/dist/canvas-kit/kit.js +4580 -4419
  2. package/dist/canvas-kit/manifest.json +1 -1
  3. package/dist/canvas-kit/release.json +5 -5
  4. package/lib/commonjs/components/BarChart/BarChart.js +1 -1
  5. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  6. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  7. package/lib/commonjs/components/FieldBase/useFloatingLabel.js +1 -1
  8. package/lib/commonjs/components/FileViewer/useFileViewerZoom.js +1 -1
  9. package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
  10. package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
  11. package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
  12. package/lib/commonjs/components/SlideToConfirm/SlideToConfirm.js +1 -1
  13. package/lib/commonjs/components/Slider/Slider.js +1 -1
  14. package/lib/commonjs/components/SortableList/SortableList.js +1 -1
  15. package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
  16. package/lib/commonjs/components/WheelPicker/Wheel.js +1 -1
  17. package/lib/commonjs/components/ZoomableImage/ZoomableImage.js +1 -1
  18. package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
  19. package/lib/commonjs/navigation/NavigationScreen.js +1 -1
  20. package/lib/module/components/BarChart/BarChart.js +1 -1
  21. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  22. package/lib/module/components/Drawer/Drawer.js +1 -1
  23. package/lib/module/components/FieldBase/useFloatingLabel.js +1 -1
  24. package/lib/module/components/FileViewer/useFileViewerZoom.js +1 -1
  25. package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
  26. package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
  27. package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
  28. package/lib/module/components/SlideToConfirm/SlideToConfirm.js +1 -1
  29. package/lib/module/components/Slider/Slider.js +1 -1
  30. package/lib/module/components/SortableList/SortableList.js +1 -1
  31. package/lib/module/components/Swipeable/Swipeable.js +1 -1
  32. package/lib/module/components/WheelPicker/Wheel.js +1 -1
  33. package/lib/module/components/ZoomableImage/ZoomableImage.js +1 -1
  34. package/lib/module/hooks/useDragToDismiss.js +1 -1
  35. package/lib/module/navigation/NavigationScreen.js +1 -1
  36. package/lib/typescript/commonjs/components/BottomSheet/BottomSheet.d.ts +1 -1
  37. package/lib/typescript/commonjs/components/Drawer/Drawer.d.ts +1 -1
  38. package/lib/typescript/commonjs/components/FileViewer/useFileViewerZoom.d.ts +3 -3
  39. package/lib/typescript/commonjs/components/Swipeable/Swipeable.d.ts +1 -1
  40. package/lib/typescript/commonjs/hooks/useDragToDismiss.d.ts +5 -5
  41. package/lib/typescript/module/components/BottomSheet/BottomSheet.d.ts +1 -1
  42. package/lib/typescript/module/components/Drawer/Drawer.d.ts +1 -1
  43. package/lib/typescript/module/components/FileViewer/useFileViewerZoom.d.ts +3 -3
  44. package/lib/typescript/module/components/Swipeable/Swipeable.d.ts +1 -1
  45. package/lib/typescript/module/hooks/useDragToDismiss.d.ts +5 -5
  46. package/package.json +9 -9
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_SORTABLE_LIST_LABELS=void 0,exports.SortableList=SortableList,exports.default=void 0,exports.dropIndex=dropIndex,exports.moveItem=moveItem,exports.rowShifts=rowShifts,exports.slotTop=slotTop,exports.topOf=topOf;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_ScrollHost=require("../Screen/ScrollHost.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,l=Object.defineProperty,n={__proto__:null,default:e};if(Object(e)!==e)return n;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,n)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=l&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?l(n,r,a):n[r]=e[r]);return n}const DEFAULT_SORTABLE_LIST_LABELS=exports.DEFAULT_SORTABLE_LIST_LABELS=Object.freeze({moveUp:"Move up",moveDown:"Move down"}),LONG_PRESS_MS=350,EDGE_PX=48,SCROLL_STEP_PX=12,SCROLL_SLACK_PX=1,SPRING_CONFIG={damping:22,stiffness:260,mass:1},ACTION_STEP={moveUp:-1,moveDown:1},noop=e=>{};function moveItem(e,t,a){const r=e.slice();if(t<0||t>=r.length)return r;const[l]=r.splice(t,1);return r.splice(a,0,l),r}function topOf(e,t){"worklet";let a=0;for(let r=0;r<t;r++)a+=e[r]??0;return a}function slotTop(e,t,a){"worklet";let r=0,l=0;for(let n=0;n<e.length&&l<a;n++)n!==t&&(r+=e[n]??0,l++);return r}function dropIndex(e,t,a){"worklet";const r=topOf(e,t)+(e[t]??0)/2+a;let l=0,n=0;for(let a=0;a<e.length;a++){const i=e[a]??0;a!==t&&n+i/2<r&&l++,n+=i}return l}function rowShifts(e,t,a){const r=[];let l=0;for(const t of e)r.push(l),l+=t;const n=e.map(()=>0),i=moveItem(e.map((e,t)=>t),t,a);let o=0;for(const t of i)n[t]=o-(r[t]??0),o+=e[t]??0;return n}const buildStyles=e=>_reactNative.StyleSheet.create({handleRow:{flexDirection:"row",alignItems:"center"},handle:{paddingHorizontal:e.space.sm,paddingVertical:e.space.md,gap:e.space.xxs},bar:{width:e.space.md,height:e.space.xxs,backgroundColor:e.colors["text-muted"]},body:{flex:1}});function SortableRow({rowKey:e,index:t,count:a,shift:r,isActive:l,dragging:n,handle:i,disabled:o,shared:s,callbacks:c,labels:u,children:d}){const v=(0,_index.useTheme)(),_=(0,_react.useMemo)(()=>buildStyles(v),[v]),m=(0,_reactNativeReanimated.useSharedValue)(0);(0,_react.useEffect)(()=>{m.value=n&&!l?(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG):r},[n,l,r,m]),(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(m)},[m]);const S=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateY:l?s.dragY.value:m.value}],zIndex:l?1:0}),[l,s,m]),h=(0,_react.useMemo)(()=>{const{dragIndex:e,dropTo:a,dragY:r,translation:l,absoluteY:n,scrollY:u,scrollStart:d,hostOffset:v,hostStart:_,hostTarget:m,heights:S}=s,{onLift:h,onDrop:f,onSettled:p}=c,R=_reactNativeGestureHandler.Gesture.Pan().enabled(!o).onStart(i=>{"worklet";n.value=i.absoluteY,e.value=t,a.value=t,d.value=u.value,_.value=v.value,m.value=v.value,l.value=0,r.value=0,(0,_reactNativeReanimated.runOnJS)(h)(t)}).onUpdate(a=>{"worklet";e.value===t&&(l.value=a.translationY,n.value=a.absoluteY)}).onFinalize(()=>{"worklet";if(e.value!==t)return;const l=a.value,n=S.value;e.value=-1,r.value=topOf(n,t)+r.value-slotTop(n,t,l),r.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG,e=>{"worklet";e&&(0,_reactNativeReanimated.runOnJS)(p)()}),(0,_reactNativeReanimated.runOnJS)(f)(t,l)});return i?R:R.activateAfterLongPress(350)},[o,i,t,c,s]),f=o?[]:[...t>0?[{name:"moveUp",label:u.moveUp}]:[],...t<a-1?[{name:"moveDown",label:u.moveDown}]:[]];return(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:S,onLayout:t=>c.onHeight(e,t.nativeEvent.layout.height),accessibilityActions:f,onAccessibilityAction:e=>{if(o)return;const r=t+(ACTION_STEP[e.nativeEvent.actionName]??0);r!==t&&r>=0&&r<a&&c.onMove(t,r)},testID:`sortable-row-${e}`,children:i?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_.handleRow,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:h,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_.handle,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.bar}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.bar}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.bar})]})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.body,children:d})]}):(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:h,children:(0,_jsxRuntime.jsx)(_reactNative.View,{children:d})})})}function SortableList(e){const{data:t,keyExtractor:a,renderItem:r,onReorder:l,handle:n=!1,disabled:i=!1,accessibilityLabel:o,labels:s,testID:c}=e,u=(0,_react.useMemo)(()=>({...DEFAULT_SORTABLE_LIST_LABELS,...s}),[s]),d=(0,_react.useMemo)(()=>t.map((e,t)=>({key:a(e,t),item:e})),[t,a]),v=(0,_react.useMemo)(()=>d.map(e=>e.key),[d]),_=(0,_reactNativeReanimated.useAnimatedRef)(),m=(0,_reactNativeReanimated.useSharedValue)(0),S=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),f=(0,_ScrollHost.useScrollHost)(),p=(0,_reactNativeReanimated.useSharedValue)(0),R=null!==f,g=f?.top??p,x=f?.bottom??p,N=f?.offset??p,b=f?.maxOffset??p,L=f?.scrollTo??noop,w=(0,_reactNativeReanimated.useSharedValue)(0),O=(0,_reactNativeReanimated.useSharedValue)(0),y=(0,_reactNativeReanimated.useSharedValue)(0),E=(0,_reactNativeReanimated.useSharedValue)(0),j=(0,_reactNativeReanimated.useSharedValue)(-1),T=(0,_reactNativeReanimated.useSharedValue)(-1),k=(0,_reactNativeReanimated.useSharedValue)(0),A=(0,_reactNativeReanimated.useSharedValue)([]),I=(0,_react.useRef)(new Map),P=(0,_react.useRef)(v),[C,M]=(0,_react.useState)(null),V=(0,_react.useCallback)(()=>{A.value=P.current.map(e=>I.current.get(e)??0)},[A]);(0,_react.useEffect)(()=>{P.current=v,V()},[v,V]),(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(k)},[k]);const D=(0,_react.useCallback)(e=>{M(t=>t?.dragging?{...t,to:e}:t)},[]),G=(0,_reactNativeReanimated.useFrameCallback)(()=>{"worklet";const e=j.value;if(e<0)return;const t=(0,_reactNativeReanimated.measure)(_);if(t){const e=R?Math.max(t.pageY,g.value):t.pageY,a=R?Math.min(t.pageY+t.height,x.value):t.pageY+t.height,r=Math.max(0,h.value-t.height-SCROLL_SLACK_PX);E.value<e+EDGE_PX?m.value>SCROLL_SLACK_PX?(0,_reactNativeReanimated.scrollTo)(_,0,Math.max(0,m.value-SCROLL_STEP_PX),!1):R&&O.value>0&&(O.value=Math.max(0,O.value-SCROLL_STEP_PX),(0,_reactNativeReanimated.runOnJS)(L)(O.value)):E.value>a-EDGE_PX&&(m.value<r?(0,_reactNativeReanimated.scrollTo)(_,0,Math.min(r,m.value+SCROLL_STEP_PX),!1):R&&O.value<b.value&&(O.value=Math.min(b.value,O.value+SCROLL_STEP_PX),(0,_reactNativeReanimated.runOnJS)(L)(O.value)))}k.value=y.value+m.value-S.value+N.value-w.value;const a=dropIndex(A.value,e,k.value);a!==T.value&&(T.value=a,(0,_reactNativeReanimated.runOnJS)(D)(a))},!1),Y=(0,_react.useCallback)(e=>{(0,_index2.triggerHaptic)("longPress"),G.setActive(!0),M({key:v[e]??"",from:e,to:e,dragging:!0})},[G,v]),H=(0,_react.useCallback)((e,t)=>{G.setActive(!1),M(e=>e?{...e,to:t,dragging:!1}:e),t!==e&&l(moveItem(v,e,t))},[G,v,l]),X=(0,_react.useCallback)(()=>{M(e=>e&&!e.dragging?null:e)},[]),q=(0,_react.useCallback)((e,t)=>{l(moveItem(v,e,t))},[v,l]),F=(0,_react.useCallback)((e,t)=>{I.current.set(e,t),V()},[V]),U=(0,_reactNativeReanimated.useAnimatedScrollHandler)({onScroll:e=>{"worklet";m.value=e.contentOffset.y}}),B=(0,_react.useCallback)((e,t)=>{h.value=t},[h]),J=(0,_react.useMemo)(()=>({scrollRef:_,scrollY:m,scrollStart:S,hostOffset:N,hostStart:w,hostTarget:O,translation:y,absoluteY:E,dragIndex:j,dropTo:T,dragY:k,heights:A}),[_,m,S,N,w,O,y,E,j,T,k,A]),z=(0,_react.useMemo)(()=>({onLift:Y,onDrop:H,onSettled:X,onMove:q,onHeight:F}),[Y,H,X,q,F]),K=!0===C?.dragging,W=K&&C?rowShifts(v.map(e=>I.current.get(e)??0),C.from,C.to):null;return(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.ScrollView,{ref:_,onScroll:U,onContentSizeChange:B,scrollEventThrottle:16,scrollEnabled:!K,accessibilityLabel:o,testID:c,children:d.map((e,t)=>{const a=C?.key===e.key;return(0,_jsxRuntime.jsx)(SortableRow,{rowKey:e.key,index:t,count:d.length,shift:W?.[t]??0,isActive:a,dragging:K,handle:n,disabled:i,shared:J,callbacks:z,labels:u,children:r({item:e.item,index:t,isActive:a})},e.key)})})}SortableList.displayName="SortableList";var _default=exports.default=SortableList;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_SORTABLE_LIST_LABELS=void 0,exports.SortableList=SortableList,exports.default=void 0,exports.dropIndex=dropIndex,exports.moveItem=moveItem,exports.rowShifts=rowShifts,exports.slotTop=slotTop,exports.topOf=topOf;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_ScrollHost=require("../Screen/ScrollHost.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,l=Object.defineProperty,n={__proto__:null,default:e};if(Object(e)!==e)return n;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,n)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=l&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?l(n,r,a):n[r]=e[r]);return n}const DEFAULT_SORTABLE_LIST_LABELS=exports.DEFAULT_SORTABLE_LIST_LABELS=Object.freeze({moveUp:"Move up",moveDown:"Move down"}),LONG_PRESS_MS=350,EDGE_PX=48,SCROLL_STEP_PX=12,SCROLL_SLACK_PX=1,SPRING_CONFIG={damping:22,stiffness:260,mass:1},ACTION_STEP={moveUp:-1,moveDown:1},noop=e=>{};function moveItem(e,t,a){const r=e.slice();if(t<0||t>=r.length)return r;const[l]=r.splice(t,1);return r.splice(a,0,l),r}function topOf(e,t){"worklet";let a=0;for(let r=0;r<t;r++)a+=e[r]??0;return a}function slotTop(e,t,a){"worklet";let r=0,l=0;for(let n=0;n<e.length&&l<a;n++)n!==t&&(r+=e[n]??0,l++);return r}function dropIndex(e,t,a){"worklet";const r=topOf(e,t)+(e[t]??0)/2+a;let l=0,n=0;for(let a=0;a<e.length;a++){const i=e[a]??0;a!==t&&n+i/2<r&&l++,n+=i}return l}function rowShifts(e,t,a){const r=[];let l=0;for(const t of e)r.push(l),l+=t;const n=e.map(()=>0),i=moveItem(e.map((e,t)=>t),t,a);let o=0;for(const t of i)n[t]=o-(r[t]??0),o+=e[t]??0;return n}const buildStyles=e=>_reactNative.StyleSheet.create({handleRow:{flexDirection:"row",alignItems:"center"},handle:{paddingHorizontal:e.space.sm,paddingVertical:e.space.md,gap:e.space.xxs},bar:{width:e.space.md,height:e.space.xxs,backgroundColor:e.colors["text-muted"]},body:{flex:1}});function SortableRow({rowKey:e,index:t,count:a,shift:r,isActive:l,dragging:n,handle:i,disabled:o,shared:s,callbacks:c,labels:u,children:d}){const v=(0,_index.useTheme)(),_=(0,_react.useMemo)(()=>buildStyles(v),[v]),m=(0,_reactNativeReanimated.useSharedValue)(0);(0,_react.useEffect)(()=>{m.value=n&&!l?(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG):r},[n,l,r,m]),(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(m)},[m]);const S=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateY:l?s.dragY.value:m.value}],zIndex:l?1:0}),[l,s,m]),h=(0,_react.useMemo)(()=>{const{dragIndex:e,dropTo:a,dragY:r,translation:l,absoluteY:n,scrollY:u,scrollStart:d,hostOffset:v,hostStart:_,hostTarget:m,heights:S}=s,{onLift:h,onDrop:f,onSettled:p}=c;return{enabled:!o,activateAfterLongPress:i?void 0:350,onActivate:i=>{"worklet";n.value=i.absoluteY,e.value=t,a.value=t,d.value=u.value,_.value=v.value,m.value=v.value,l.value=0,r.value=0,(0,_reactNativeReanimated.runOnJS)(h)(t)},onUpdate:a=>{"worklet";e.value===t&&(l.value=a.translationY,n.value=a.absoluteY)},onFinalize:()=>{"worklet";if(e.value!==t)return;const l=a.value,n=S.value;e.value=-1,r.value=topOf(n,t)+r.value-slotTop(n,t,l),r.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG,e=>{"worklet";e&&(0,_reactNativeReanimated.runOnJS)(p)()}),(0,_reactNativeReanimated.runOnJS)(f)(t,l)}}},[o,i,t,c,s]),f=(0,_reactNativeGestureHandler.usePanGesture)(h),p=o?[]:[...t>0?[{name:"moveUp",label:u.moveUp}]:[],...t<a-1?[{name:"moveDown",label:u.moveDown}]:[]];return(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:S,onLayout:t=>c.onHeight(e,t.nativeEvent.layout.height),accessibilityActions:p,onAccessibilityAction:e=>{if(o)return;const r=t+(ACTION_STEP[e.nativeEvent.actionName]??0);r!==t&&r>=0&&r<a&&c.onMove(t,r)},testID:`sortable-row-${e}`,children:i?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_.handleRow,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:f,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_.handle,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.bar}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.bar}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.bar})]})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.body,children:d})]}):(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:f,children:(0,_jsxRuntime.jsx)(_reactNative.View,{children:d})})})}function SortableList(e){const{data:t,keyExtractor:a,renderItem:r,onReorder:l,handle:n=!1,disabled:i=!1,accessibilityLabel:o,labels:s,testID:c}=e,u=(0,_react.useMemo)(()=>({...DEFAULT_SORTABLE_LIST_LABELS,...s}),[s]),d=(0,_react.useMemo)(()=>t.map((e,t)=>({key:a(e,t),item:e})),[t,a]),v=(0,_react.useMemo)(()=>d.map(e=>e.key),[d]),_=(0,_reactNativeReanimated.useAnimatedRef)(),m=(0,_reactNativeReanimated.useSharedValue)(0),S=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),f=(0,_ScrollHost.useScrollHost)(),p=(0,_reactNativeReanimated.useSharedValue)(0),R=null!==f,g=f?.top??p,x=f?.bottom??p,N=f?.offset??p,b=f?.maxOffset??p,L=f?.scrollTo??noop,w=(0,_reactNativeReanimated.useSharedValue)(0),O=(0,_reactNativeReanimated.useSharedValue)(0),y=(0,_reactNativeReanimated.useSharedValue)(0),E=(0,_reactNativeReanimated.useSharedValue)(0),j=(0,_reactNativeReanimated.useSharedValue)(-1),T=(0,_reactNativeReanimated.useSharedValue)(-1),A=(0,_reactNativeReanimated.useSharedValue)(0),k=(0,_reactNativeReanimated.useSharedValue)([]),I=(0,_react.useRef)(new Map),P=(0,_react.useRef)(v),[C,M]=(0,_react.useState)(null),V=(0,_react.useCallback)(()=>{k.value=P.current.map(e=>I.current.get(e)??0)},[k]);(0,_react.useEffect)(()=>{P.current=v,V()},[v,V]),(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(A)},[A]);const D=(0,_react.useCallback)(e=>{M(t=>t?.dragging?{...t,to:e}:t)},[]),G=(0,_reactNativeReanimated.useFrameCallback)(()=>{"worklet";const e=j.value;if(e<0)return;const t=(0,_reactNativeReanimated.measure)(_);if(t){const e=R?Math.max(t.pageY,g.value):t.pageY,a=R?Math.min(t.pageY+t.height,x.value):t.pageY+t.height,r=Math.max(0,h.value-t.height-SCROLL_SLACK_PX);E.value<e+EDGE_PX?m.value>SCROLL_SLACK_PX?(0,_reactNativeReanimated.scrollTo)(_,0,Math.max(0,m.value-SCROLL_STEP_PX),!1):R&&O.value>0&&(O.value=Math.max(0,O.value-SCROLL_STEP_PX),(0,_reactNativeReanimated.runOnJS)(L)(O.value)):E.value>a-EDGE_PX&&(m.value<r?(0,_reactNativeReanimated.scrollTo)(_,0,Math.min(r,m.value+SCROLL_STEP_PX),!1):R&&O.value<b.value&&(O.value=Math.min(b.value,O.value+SCROLL_STEP_PX),(0,_reactNativeReanimated.runOnJS)(L)(O.value)))}A.value=y.value+m.value-S.value+N.value-w.value;const a=dropIndex(k.value,e,A.value);a!==T.value&&(T.value=a,(0,_reactNativeReanimated.runOnJS)(D)(a))},!1),Y=(0,_react.useCallback)(e=>{(0,_index2.triggerHaptic)("longPress"),G.setActive(!0),M({key:v[e]??"",from:e,to:e,dragging:!0})},[G,v]),H=(0,_react.useCallback)((e,t)=>{G.setActive(!1),M(e=>e?{...e,to:t,dragging:!1}:e),t!==e&&l(moveItem(v,e,t))},[G,v,l]),X=(0,_react.useCallback)(()=>{M(e=>e&&!e.dragging?null:e)},[]),q=(0,_react.useCallback)((e,t)=>{l(moveItem(v,e,t))},[v,l]),F=(0,_react.useCallback)((e,t)=>{I.current.set(e,t),V()},[V]),U=(0,_reactNativeReanimated.useAnimatedScrollHandler)({onScroll:e=>{"worklet";m.value=e.contentOffset.y}}),B=(0,_react.useCallback)((e,t)=>{h.value=t},[h]),J=(0,_react.useMemo)(()=>({scrollRef:_,scrollY:m,scrollStart:S,hostOffset:N,hostStart:w,hostTarget:O,translation:y,absoluteY:E,dragIndex:j,dropTo:T,dragY:A,heights:k}),[_,m,S,N,w,O,y,E,j,T,A,k]),z=(0,_react.useMemo)(()=>({onLift:Y,onDrop:H,onSettled:X,onMove:q,onHeight:F}),[Y,H,X,q,F]),K=!0===C?.dragging,W=K&&C?rowShifts(v.map(e=>I.current.get(e)??0),C.from,C.to):null;return(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.ScrollView,{ref:_,onScroll:U,onContentSizeChange:B,scrollEventThrottle:16,scrollEnabled:!K,accessibilityLabel:o,testID:c,children:d.map((e,t)=>{const a=C?.key===e.key;return(0,_jsxRuntime.jsx)(SortableRow,{rowKey:e.key,index:t,count:d.length,shift:W?.[t]??0,isActive:a,dragging:K,handle:n,disabled:i,shared:J,callbacks:z,labels:u,children:r({item:e.item,index:t,isActive:a})},e.key)})})}SortableList.displayName="SortableList";var _default=exports.default=SortableList;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Swipeable=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,n=Object.defineProperty,r={__proto__:null,default:e};if(Object(e)!==e)return r;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,r)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=n&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?n(r,i,a):r[i]=e[i]);return r}const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,ACTION_ICON_SIZE=20,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:a,rightActions:i,threshold:n,fullSwipeThreshold:r,onSwipeOpen:s,onSwipeClose:c,disabled:o=!1,haptic:l,containerStyle:u,contentStyle:d,actionStyle:_,accessibilityLabel:m,testID:h}=e,v=(0,_index.useTheme)(),p=n??80,b=r??200,S=(0,_react.useMemo)(()=>buildStyles(v),[v]),f=(0,_react.useMemo)(()=>buildActionStyles(v),[v]),N=!!a&&a.length>0,R=!!i&&i.length>0,w=_reactNative.Dimensions.get("window").width,x=N?p*(a?.length??0):0,y=R?p*(i?.length??0):0,g=(0,_reactNativeReanimated.useSharedValue)(0),j=(0,_reactNativeReanimated.useSharedValue)(0),I=(0,_react.useRef)(null);(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(g),(0,_reactNativeReanimated.cancelAnimation)(j)},[g,j]);const O=(0,_react.useCallback)(e=>{I.current!==e&&(I.current=e,s?.(e))},[s]),C=(0,_react.useCallback)(()=>{null!==I.current&&(I.current=null,c?.())},[c]),A=(0,_react.useCallback)(e=>{const t="left"===e?a:i,n=t?.[0];n&&(!1!==l&&(0,_index2.triggerHaptic)("notificationSuccess"),n.onPress(),g.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),I.current=null,c?.())},[a,i,g,c,l]),G=(0,_react.useCallback)(()=>{g.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),C()},[g,C]),P=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(l,"selection");t&&(0,_index2.triggerHaptic)(t),e.onPress(),G()},[G,l]),k=(0,_react.useMemo)(()=>{const e=x,t=y,a=b,i=-b,n=w,r=-w,s=p,c=N,l=R;return _reactNativeGestureHandler.Gesture.Pan().enabled(!o).withTestId(h?`${h}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";j.value=g.value}).onUpdate(a=>{"worklet";const i=j.value+a.translationX;g.value=i>0&&!c||i<0&&!l?0:i>e&&c?e+.35*(i-e):i<-t&&l?.35*(i+t)-t:i}).onEnd(()=>{"worklet";const o=g.value;return c&&o>=a?(g.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(A)("left")):l&&o<=i?(g.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(A)("right")):c&&o>=s?(g.value=(0,_reactNativeReanimated.withSpring)(e,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(O)("left")):l&&o<=-s?(g.value=(0,_reactNativeReanimated.withSpring)(-t,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(O)("right")):(g.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(C)())})},[o,j,A,b,N,R,x,C,O,y,w,p,g,h]),V=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:g.value}]}),[g]),T=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:x>0?Math.min(1,Math.max(0,g.value/x)):0}),[x,g]),F=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:y>0?Math.min(1,Math.max(0,-g.value/y)):0}),[y,g]),q=(0,_react.useMemo)(()=>{const e=[];return a?.forEach(t=>{e.push({name:t.key,label:t.label})}),i?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[a,i]),E=(0,_react.useCallback)(e=>{const t=e.nativeEvent.actionName,n=[...a??[],...i??[]].find(e=>e.key===t);n&&(!1!==l&&(0,_index2.triggerHaptic)("selection"),n.onPress())},[a,i,l]);return N||R?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[S.root,u],testID:h,accessibilityLabel:m,accessibilityActions:q,onAccessibilityAction:E,children:[N?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.actionsRow,S.actionsLeft,{width:x},_,T],pointerEvents:"box-none",children:a?.map(e=>(0,_jsxRuntime.jsx)(ActionButton,{action:e,theme:v,actionStyles:f,width:p,onPress:P},e.key))}):null,R?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.actionsRow,S.actionsRight,{width:y},_,F],pointerEvents:"box-none",children:i?.map(e=>(0,_jsxRuntime.jsx)(ActionButton,{action:e,theme:v,actionStyles:f,width:p,onPress:P},e.key))}):null,(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:k,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.content,d,V],children:t})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:u,testID:h,children:t})};exports.Swipeable=Swipeable,Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:a,width:i,onPress:n})=>{(0,_assertValidValue.assertValidValue)("Swipeable","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const r=e.tone??"neutral",s=toneToBg(t,r),c=(0,_slotIcon.renderSlotIcon)(e.icon,{color:toneToOnColor(t,r),size:20,disabled:!1});return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>n(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[a.button,{width:i,backgroundColor:s,paddingHorizontal:t.space.sm}],children:[c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:a.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:c}):null,(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",weight:"semibold",style:[a.label,{color:toneToOnColor(t,r)}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>_reactNative.StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>_reactNative.StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});var _default=exports.default=Swipeable;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Swipeable=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,n=Object.defineProperty,r={__proto__:null,default:e};if(Object(e)!==e)return r;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,r)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=n&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?n(r,i,a):r[i]=e[i]);return r}const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,ACTION_ICON_SIZE=20,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:a,rightActions:i,threshold:n,fullSwipeThreshold:r,onSwipeOpen:s,onSwipeClose:c,disabled:o=!1,haptic:l,containerStyle:u,contentStyle:d,actionStyle:_,accessibilityLabel:m,testID:h}=e,v=(0,_index.useTheme)(),p=n??80,b=r??200,S=(0,_react.useMemo)(()=>buildStyles(v),[v]),f=(0,_react.useMemo)(()=>buildActionStyles(v),[v]),N=!!a&&a.length>0,R=!!i&&i.length>0,w=_reactNative.Dimensions.get("window").width,x=N?p*(a?.length??0):0,y=R?p*(i?.length??0):0,g=(0,_reactNativeReanimated.useSharedValue)(0),j=(0,_reactNativeReanimated.useSharedValue)(0),I=(0,_react.useRef)(null);(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(g),(0,_reactNativeReanimated.cancelAnimation)(j)},[g,j]);const O=(0,_react.useCallback)(e=>{I.current!==e&&(I.current=e,s?.(e))},[s]),A=(0,_react.useCallback)(()=>{null!==I.current&&(I.current=null,c?.())},[c]),C=(0,_react.useCallback)(e=>{const t="left"===e?a:i,n=t?.[0];n&&(!1!==l&&(0,_index2.triggerHaptic)("notificationSuccess"),n.onPress(),g.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),I.current=null,c?.())},[a,i,g,c,l]),G=(0,_react.useCallback)(()=>{g.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),A()},[g,A]),P=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(l,"selection");t&&(0,_index2.triggerHaptic)(t),e.onPress(),G()},[G,l]),k=(0,_react.useMemo)(()=>{const e=x,t=y,a=b,i=-b,n=w,r=-w,s=p,c=N,l=R;return{enabled:!o,testID:h?`${h}-gesture`:"swipeable-gesture",activeOffsetX:[-10,10],failOffsetY:[-15,15],onActivate:()=>{"worklet";j.value=g.value},onUpdate:a=>{"worklet";const i=j.value+a.translationX;g.value=i>0&&!c||i<0&&!l?0:i>e&&c?e+.35*(i-e):i<-t&&l?.35*(i+t)-t:i},onDeactivate:()=>{"worklet";const o=g.value;return c&&o>=a?(g.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(C)("left")):l&&o<=i?(g.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(C)("right")):c&&o>=s?(g.value=(0,_reactNativeReanimated.withSpring)(e,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(O)("left")):l&&o<=-s?(g.value=(0,_reactNativeReanimated.withSpring)(-t,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(O)("right")):(g.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(A)())}}},[o,j,C,b,N,R,x,A,O,y,w,p,g,h]),V=(0,_reactNativeGestureHandler.usePanGesture)(k),F=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:g.value}]}),[g]),T=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:x>0?Math.min(1,Math.max(0,g.value/x)):0}),[x,g]),q=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:y>0?Math.min(1,Math.max(0,-g.value/y)):0}),[y,g]),M=(0,_react.useMemo)(()=>{const e=[];return a?.forEach(t=>{e.push({name:t.key,label:t.label})}),i?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[a,i]),D=(0,_react.useCallback)(e=>{const t=e.nativeEvent.actionName,n=[...a??[],...i??[]].find(e=>e.key===t);n&&(!1!==l&&(0,_index2.triggerHaptic)("selection"),n.onPress())},[a,i,l]);return N||R?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[S.root,u],testID:h,accessibilityLabel:m,accessibilityActions:M,onAccessibilityAction:D,children:[N?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.actionsRow,S.actionsLeft,{width:x},_,T],pointerEvents:"box-none",children:a?.map(e=>(0,_jsxRuntime.jsx)(ActionButton,{action:e,theme:v,actionStyles:f,width:p,onPress:P},e.key))}):null,R?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.actionsRow,S.actionsRight,{width:y},_,q],pointerEvents:"box-none",children:i?.map(e=>(0,_jsxRuntime.jsx)(ActionButton,{action:e,theme:v,actionStyles:f,width:p,onPress:P},e.key))}):null,(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:V,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.content,d,F],children:t})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:u,testID:h,children:t})};exports.Swipeable=Swipeable,Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:a,width:i,onPress:n})=>{(0,_assertValidValue.assertValidValue)("Swipeable","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const r=e.tone??"neutral",s=toneToBg(t,r),c=(0,_slotIcon.renderSlotIcon)(e.icon,{color:toneToOnColor(t,r),size:20,disabled:!1});return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>n(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[a.button,{width:i,backgroundColor:s,paddingHorizontal:t.space.sm}],children:[c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:a.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:c}):null,(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",weight:"semibold",style:[a.label,{color:toneToOnColor(t,r)}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>_reactNative.StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>_reactNative.StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});var _default=exports.default=Swipeable;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Wheel=exports.WHEEL_VISIBLE_ITEMS=exports.WHEEL_CENTER_OFFSET=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_index2=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const WHEEL_VISIBLE_ITEMS=exports.WHEEL_VISIBLE_ITEMS=5,WHEEL_CENTER_OFFSET=exports.WHEEL_CENTER_OFFSET=Math.floor(WHEEL_VISIBLE_ITEMS/2),HAPTIC_DEBOUNCE_MS=35,WEB_SETTLE_MS=120,SCALE_STOPS=[-2,-1,0,1,2],WheelRow=(0,_react.memo)(({label:e,index:t,scrollY:a,itemHeight:n,selected:r,theme:i,reducedMotion:c,onPress:s,editor:l})=>{const{opacity:o,scale:u}=(0,_react.useMemo)(()=>{const e=_reactNative.Animated.subtract(_reactNative.Animated.divide(a,n),t);return{opacity:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.3,.6,1,.6,.3],extrapolate:"clamp"}),scale:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.85,.95,1.05,.95,.85],extrapolate:"clamp"})}},[a,n,t]),d=(0,_jsxRuntime.jsx)(_index2.Text,{variant:"h3",weight:r?"semibold":"medium",color:r?"primary":"secondary",numberOfLines:1,maxFontSizeMultiplier:1.5,style:{letterSpacing:i["letter-spacing"].normal},children:e});return(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[styles.row,{height:n},c?{opacity:o}:{opacity:o,transform:[{scale:u}]}],accessible:!1,importantForAccessibility:"no",children:l??(s?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{focusable:!1,accessible:!1,onPress:()=>s(t),style:styles.rowPress,children:d}):d)})}),Wheel=({label:e,items:t,selectedIndex:a,onIndexChange:n,itemHeight:r,width:i,theme:c,haptic:s,disabled:l,reducedMotion:o,typeable:u,testID:d})=>{const m="web"===_reactNative.Platform.OS,[_,b]=(0,_react.useState)(null),x=(0,_react.useRef)(!1),E=(0,_react.useRef)(null),h=(0,_react.useRef)((0,_index.createAnimatedValue)(a*r)).current,y=(0,_react.useRef)(a*r),p=(0,_react.useRef)(a*r),f=(0,_react.useRef)(a),v=(0,_react.useRef)(0),S=(0,_react.useRef)(null),T=(0,_react.useRef)(()=>{}),g=t.length-1;(0,_react.useEffect)(()=>{f.current=a;const e=a*r;if(p.current===e)return;if(p.current=e,Math.abs(y.current-e)<1)return;y.current=e,m||(0,_index.setNativeValue)(h,e);const t=requestAnimationFrame(()=>{E.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[a,r,h,m]),(0,_react.useEffect)(()=>{const e=y.current,t=requestAnimationFrame(()=>{E.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[]),(0,_react.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);const M=(0,_react.useCallback)((e,r)=>{if(!(e===a||e<0||e>g)){if("accessibility"===r){const e=(0,_hapticUtils.resolveHaptic)(s,"denseTick");e&&(0,_hapticUtils.triggerHaptic)(e)}if("keyboard"!==r){const a=t[e];a&&(0,_announce.announce)(a.accessibilityLabel??a.label)}n(e)}},[a,g,t,s,n]),R=(0,_react.useCallback)(()=>{!l&&u&&(x.current=!0,b(String(t[a]?.value??"")))},[l,u,t,a]),I=(0,_react.useCallback)(e=>{if(!x.current)return;x.current=!1,b(null);const a=e.trim();if(!/^\d+$/.test(a))return;const n=Number(a),r=t.findIndex(e=>e.value===n);r>=0&&M(r,"keyboard")},[t,M]);T.current=()=>{S.current=null;const e=Math.max(0,Math.min(g,Math.round(y.current/r))),t=e*r;Math.abs(y.current-t)>=1&&E.current?.scrollTo({y:t,animated:!o}),M(e,"scroll")};const j=(0,_react.useMemo)(()=>_reactNative.Animated.event([{nativeEvent:{contentOffset:{y:h}}}],{useNativeDriver:!m,listener:e=>{const t=e.nativeEvent.contentOffset.y;y.current=t;const a=Math.round(t/r);if(a!==f.current&&a>=0&&a<=g){const e=Date.now();if(e-v.current>=35){const t=(0,_hapticUtils.resolveHaptic)(s,"denseTick");t&&(0,_hapticUtils.triggerHaptic)(t),v.current=e}f.current=a}m&&(S.current&&clearTimeout(S.current),S.current=setTimeout(()=>T.current(),120))}}),[h,r,g,s,m]),L=(0,_react.useCallback)(e=>{const t=e.nativeEvent.contentOffset.y;M(Math.max(0,Math.min(g,Math.round(t/r))),"scroll")},[M,g,r]),w=(0,_react.useCallback)(e=>{if(l)return;const t=e.nativeEvent.actionName;"increment"===t?M(Math.min(g,a+1),"accessibility"):"decrement"===t&&M(Math.max(0,a-1),"accessibility")},[l,M,g,a]),A=(0,_react.useCallback)(e=>{l||E.current?.scrollTo({y:e*r,animated:!o})},[l,r,o]),C=(0,_react.useCallback)(({item:t,index:n})=>{const i=n===a,s=i&&null!==_;return(0,_jsxRuntime.jsx)(WheelRow,{label:t.label,index:n,scrollY:h,itemHeight:r,selected:i,theme:c,reducedMotion:o,onPress:i&&u?R:m?A:void 0,editor:s?(0,_jsxRuntime.jsx)(_reactNative.TextInput,{autoFocus:!0,selectTextOnFocus:!0,keyboardType:"number-pad",returnKeyType:"done",accessibilityLabel:e,value:_,onChangeText:b,onSubmitEditing:()=>I(_),onBlur:()=>I(_),style:{width:"100%",padding:c.space.none,textAlign:"center",fontSize:c.text.xl.size,color:c.colors["text-body"],fontWeight:c.weight.semibold,letterSpacing:c["letter-spacing"].normal}}):void 0})},[h,r,a,c,o,m,A,u,R,_,I,e]),N=(0,_react.useCallback)((e,t)=>`${String(e.value)}-${t}`,[]),F=t[a]?t[a].accessibilityLabel??t[a].label:"",H=m?{focusable:!0,role:"spinbutton","aria-label":e,"aria-valuetext":F,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":g,"aria-disabled":l,onKeyDown:e=>{if(l)return;const t={ArrowDown:Math.min(g,a+1),PageDown:Math.min(g,a+1),ArrowUp:Math.max(0,a-1),PageUp:Math.max(0,a-1),Home:0,End:g}[e.nativeEvent.key];void 0!==t&&(e.preventDefault(),M(t,"keyboard"))}}:void 0;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[void 0===i?styles.columnFlex:{width:i},{height:r*WHEEL_VISIBLE_ITEMS},styles.column,l?styles.disabled:null],testID:d,...H,children:[m?null:(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:styles.a11yLayer,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:e,accessibilityValue:{text:F},accessibilityState:{disabled:Boolean(l)},"aria-disabled":Boolean(l),accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:w}),(0,_jsxRuntime.jsx)(_reactNative.Animated.ScrollView,{ref:E,showsVerticalScrollIndicator:!1,snapToInterval:r,snapToAlignment:"start",decelerationRate:"fast",bounces:!1,scrollEnabled:!l,nestedScrollEnabled:!0,scrollEventThrottle:16,onScroll:j,onMomentumScrollEnd:L,contentOffset:{x:0,y:a*r},contentContainerStyle:{paddingVertical:r*WHEEL_CENTER_OFFSET},style:[styles.list,{height:r*WHEEL_VISIBLE_ITEMS}],importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:t.map((e,t)=>(0,_jsxRuntime.jsx)(_react.Fragment,{children:C({item:e,index:t})},N(e,t)))})]})};exports.Wheel=Wheel;const styles=_reactNative.StyleSheet.create({column:{overflow:"hidden"},columnFlex:{flex:1},disabled:{opacity:.5},list:{flexGrow:0},row:{alignItems:"center",justifyContent:"center"},rowPress:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",flex:1},a11yLayer:{..._reactNative.StyleSheet.absoluteFill,zIndex:2}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Wheel=exports.WHEEL_VISIBLE_ITEMS=exports.WHEEL_CENTER_OFFSET=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_index2=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const WHEEL_VISIBLE_ITEMS=exports.WHEEL_VISIBLE_ITEMS=5,WHEEL_CENTER_OFFSET=exports.WHEEL_CENTER_OFFSET=Math.floor(WHEEL_VISIBLE_ITEMS/2),HAPTIC_DEBOUNCE_MS=35,WEB_SETTLE_MS=120,SCALE_STOPS=[-2,-1,0,1,2],WheelRow=(0,_react.memo)(({label:e,index:t,scrollY:a,itemHeight:r,selected:n,theme:i,reducedMotion:c,onPress:s,editor:l})=>{const{opacity:o,scale:u}=(0,_react.useMemo)(()=>{const e=_reactNative.Animated.subtract(_reactNative.Animated.divide(a,r),t);return{opacity:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.3,.6,1,.6,.3],extrapolate:"clamp"}),scale:e.interpolate({inputRange:SCALE_STOPS,outputRange:[.85,.95,1.05,.95,.85],extrapolate:"clamp"})}},[a,r,t]),d=(0,_jsxRuntime.jsx)(_index2.Text,{variant:"h3",weight:n?"semibold":"medium",color:n?"primary":"secondary",numberOfLines:1,maxFontSizeMultiplier:1.5,style:{letterSpacing:i["letter-spacing"].normal},children:e});return(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[styles.row,{height:r},c?{opacity:o}:{opacity:o,transform:[{scale:u}]}],accessible:!1,importantForAccessibility:"no",children:l??(s?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{focusable:!1,accessible:!1,onPress:()=>s(t),style:styles.rowPress,children:d}):d)})}),Wheel=({label:e,items:t,selectedIndex:a,onIndexChange:r,itemHeight:n,width:i,theme:c,haptic:s,disabled:l,reducedMotion:o,typeable:u,testID:d})=>{const m="web"===_reactNative.Platform.OS,[_,b]=(0,_react.useState)(null),x=(0,_react.useRef)(!1),E=(0,_react.useRef)(null),h=(0,_react.useRef)((0,_index.createAnimatedValue)(a*n)).current,y=(0,_react.useRef)(a*n),v=(0,_react.useRef)(a*n),p=(0,_react.useRef)(a),f=(0,_react.useRef)(0),S=(0,_react.useRef)(null),T=(0,_react.useRef)(()=>{}),g=t.length-1;(0,_react.useEffect)(()=>{p.current=a;const e=a*n;if(v.current===e)return;if(v.current=e,Math.abs(y.current-e)<1)return;y.current=e,m||(0,_index.setNativeValue)(h,e);const t=requestAnimationFrame(()=>{E.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[a,n,h,m]),(0,_react.useEffect)(()=>{const e=y.current,t=requestAnimationFrame(()=>{E.current?.scrollTo({y:e,animated:!1})});return()=>cancelAnimationFrame(t)},[]),(0,_react.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);const M=(0,_react.useCallback)((e,n)=>{if(!(e===a||e<0||e>g)){if("accessibility"===n){const e=(0,_hapticUtils.resolveHaptic)(s,"denseTick");e&&(0,_hapticUtils.triggerHaptic)(e)}if("keyboard"!==n){const a=t[e];a&&(0,_announce.announce)(a.accessibilityLabel??a.label)}r(e)}},[a,g,t,s,r]),R=(0,_react.useCallback)(()=>{!l&&u&&(x.current=!0,b(String(t[a]?.value??"")))},[l,u,t,a]),I=(0,_react.useCallback)(e=>{if(!x.current)return;x.current=!1,b(null);const a=e.trim();if(!/^\d+$/.test(a))return;const r=Number(a),n=t.findIndex(e=>e.value===r);n>=0&&M(n,"keyboard")},[t,M]);T.current=()=>{S.current=null;const e=Math.max(0,Math.min(g,Math.round(y.current/n))),t=e*n;Math.abs(y.current-t)>=1&&E.current?.scrollTo({y:t,animated:!o}),M(e,"scroll")};const j=(0,_react.useMemo)(()=>_reactNative.Animated.event([{nativeEvent:{contentOffset:{y:h}}}],{useNativeDriver:_nativeDriver.nativeDriver,listener:e=>{const t=e.nativeEvent.contentOffset.y;y.current=t;const a=Math.round(t/n);if(a!==p.current&&a>=0&&a<=g){const e=Date.now();if(e-f.current>=35){const t=(0,_hapticUtils.resolveHaptic)(s,"denseTick");t&&(0,_hapticUtils.triggerHaptic)(t),f.current=e}p.current=a}m&&(S.current&&clearTimeout(S.current),S.current=setTimeout(()=>T.current(),120))}}),[h,n,g,s,m]),L=(0,_react.useCallback)(e=>{const t=e.nativeEvent.contentOffset.y;M(Math.max(0,Math.min(g,Math.round(t/n))),"scroll")},[M,g,n]),w=(0,_react.useCallback)(e=>{if(l)return;const t=e.nativeEvent.actionName;"increment"===t?M(Math.min(g,a+1),"accessibility"):"decrement"===t&&M(Math.max(0,a-1),"accessibility")},[l,M,g,a]),A=(0,_react.useCallback)(e=>{l||E.current?.scrollTo({y:e*n,animated:!o})},[l,n,o]),C=(0,_react.useCallback)(({item:t,index:r})=>{const i=r===a,s=i&&null!==_;return(0,_jsxRuntime.jsx)(WheelRow,{label:t.label,index:r,scrollY:h,itemHeight:n,selected:i,theme:c,reducedMotion:o,onPress:i&&u?R:m?A:void 0,editor:s?(0,_jsxRuntime.jsx)(_reactNative.TextInput,{autoFocus:!0,selectTextOnFocus:!0,keyboardType:"number-pad",returnKeyType:"done",accessibilityLabel:e,value:_,onChangeText:b,onSubmitEditing:()=>I(_),onBlur:()=>I(_),style:{width:"100%",padding:c.space.none,textAlign:"center",fontSize:c.text.xl.size,color:c.colors["text-body"],fontWeight:c.weight.semibold,letterSpacing:c["letter-spacing"].normal}}):void 0})},[h,n,a,c,o,m,A,u,R,_,I,e]),N=(0,_react.useCallback)((e,t)=>`${String(e.value)}-${t}`,[]),F=t[a]?t[a].accessibilityLabel??t[a].label:"",H=m?{focusable:!0,role:"spinbutton","aria-label":e,"aria-valuetext":F,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":g,"aria-disabled":l,onKeyDown:e=>{if(l)return;const t={ArrowDown:Math.min(g,a+1),PageDown:Math.min(g,a+1),ArrowUp:Math.max(0,a-1),PageUp:Math.max(0,a-1),Home:0,End:g}[e.nativeEvent.key];void 0!==t&&(e.preventDefault(),M(t,"keyboard"))}}:void 0;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[void 0===i?styles.columnFlex:{width:i},{height:n*WHEEL_VISIBLE_ITEMS},styles.column,l?styles.disabled:null],testID:d,...H,children:[m?null:(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:styles.a11yLayer,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:e,accessibilityValue:{text:F},accessibilityState:{disabled:Boolean(l)},"aria-disabled":Boolean(l),accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:w}),(0,_jsxRuntime.jsx)(_reactNative.Animated.ScrollView,{ref:E,showsVerticalScrollIndicator:!1,snapToInterval:n,snapToAlignment:"start",decelerationRate:"fast",bounces:!1,scrollEnabled:!l,nestedScrollEnabled:!0,scrollEventThrottle:16,onScroll:j,onMomentumScrollEnd:L,contentOffset:{x:0,y:a*n},contentContainerStyle:{paddingVertical:n*WHEEL_CENTER_OFFSET},style:[styles.list,{height:n*WHEEL_VISIBLE_ITEMS}],importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:t.map((e,t)=>(0,_jsxRuntime.jsx)(_react.Fragment,{children:C({item:e,index:t})},N(e,t)))})]})};exports.Wheel=Wheel;const styles=_reactNative.StyleSheet.create({column:{overflow:"hidden"},columnFlex:{flex:1},disabled:{opacity:.5},list:{flexGrow:0},row:{alignItems:"center",justifyContent:"center"},rowPress:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",flex:1},a11yLayer:{..._reactNative.StyleSheet.absoluteFill,zIndex:2}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ZoomableImage=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../utils/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,a){if(!a&&e&&e.__esModule)return e;var t,r,i=Object.defineProperty,l={__proto__:null,default:e};if(Object(e)!==e)return l;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,l)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((t=i&&Object.getOwnPropertyDescriptor(e,r))&&(t.get||t.set)?i(l,r,t):l[r]=e[r]);return l}const DEFAULT_MAX_SCALE=4,DEFAULT_MIN_SCALE=1,DEFAULT_DOUBLE_TAP_SCALE=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ZoomableImage=({children:e,maxScale:a=4,minScale:t=1,doubleTapScale:r=2,disabled:i=!1,haptic:l,style:n,accessibilityLabel:u,testID:c})=>{const s=(0,_reactNativeReanimated.useSharedValue)(1),v=(0,_reactNativeReanimated.useSharedValue)(1),d=(0,_reactNativeReanimated.useSharedValue)(0),o=(0,_reactNativeReanimated.useSharedValue)(0),_=(0,_reactNativeReanimated.useSharedValue)(0),m=(0,_reactNativeReanimated.useSharedValue)(0),N=(0,_react.useCallback)(()=>{s.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),v.value=1,d.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),o.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),_.value=0,m.value=0},[s,v,d,o,_,m]);(0,_react.useEffect)(()=>{i&&N()},[i,N]);const S=(0,_react.useCallback)(()=>{const e=(0,_index.resolveHaptic)(l,"impactLight");e&&(0,_index.triggerHaptic)(e)},[l]),R=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Pinch().enabled(!i).onStart(()=>{"worklet";v.value=s.value}).onUpdate(e=>{"worklet";const r=v.value*e.scale;s.value=r<t?t+.3*(r-t):r>a?a+.2*(r-a):r}).onEnd(()=>{"worklet";return s.value<t?(s.value=(0,_reactNativeReanimated.withSpring)(t,SPRING_CONFIG),d.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),o.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),v.value=t,_.value=0,void(m.value=0)):s.value>a?(s.value=(0,_reactNativeReanimated.withSpring)(a,SPRING_CONFIG),void(v.value=a)):void(v.value=s.value)}),[i,s,v,d,o,_,m,t,a]),h=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Pan().enabled(!i).minPointers(1).maxPointers(1).onStart(()=>{"worklet";_.value=d.value,m.value=o.value}).onUpdate(e=>{"worklet";s.value<=1||(d.value=_.value+e.translationX,o.value=m.value+e.translationY)}).onEnd(()=>{"worklet";_.value=d.value,m.value=o.value}),[i,s,d,o,_,m]),p=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Tap().enabled(!i).numberOfTaps(2).onEnd(()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(S)(),s.value>1?(s.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),d.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),o.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),v.value=1,_.value=0,m.value=0):(s.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),v.value=r)}),[i,s,v,d,o,_,m,S,r]),I=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Race(R,h,p),[R,h,p]),G=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:d.value},{translateY:o.value},{scale:s.value}]}),[d,o,s]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:I,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[styles.container,n],testID:c,accessibilityLabel:u,accessibilityState:{disabled:i},"aria-disabled":i,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[styles.content,G],children:e})})})};exports.ZoomableImage=ZoomableImage,ZoomableImage.displayName="ZoomableImage";const styles=_reactNative.StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center",overflow:"hidden"},content:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"}});var _default=exports.default=ZoomableImage;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ZoomableImage=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../utils/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,a){if(!a&&e&&e.__esModule)return e;var t,i,r=Object.defineProperty,l={__proto__:null,default:e};if(Object(e)!==e)return l;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,l)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((t=r&&Object.getOwnPropertyDescriptor(e,i))&&(t.get||t.set)?r(l,i,t):l[i]=e[i]);return l}const DEFAULT_MAX_SCALE=4,DEFAULT_MIN_SCALE=1,DEFAULT_DOUBLE_TAP_SCALE=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ZoomableImage=({children:e,maxScale:a=4,minScale:t=1,doubleTapScale:i=2,disabled:r=!1,haptic:l,style:n,accessibilityLabel:u,testID:c})=>{const s=(0,_reactNativeReanimated.useSharedValue)(1),v=(0,_reactNativeReanimated.useSharedValue)(1),d=(0,_reactNativeReanimated.useSharedValue)(0),o=(0,_reactNativeReanimated.useSharedValue)(0),_=(0,_reactNativeReanimated.useSharedValue)(0),m=(0,_reactNativeReanimated.useSharedValue)(0),N=(0,_react.useCallback)(()=>{s.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),v.value=1,d.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),o.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),_.value=0,m.value=0},[s,v,d,o,_,m]);(0,_react.useEffect)(()=>{r&&N()},[r,N]);const R=(0,_react.useCallback)(()=>{const e=(0,_index.resolveHaptic)(l,"impactLight");e&&(0,_index.triggerHaptic)(e)},[l]),S=(0,_react.useMemo)(()=>({enabled:!r,onActivate:()=>{"worklet";v.value=s.value},onUpdate:e=>{"worklet";const i=v.value*e.scale;s.value=i<t?t+.3*(i-t):i>a?a+.2*(i-a):i},onDeactivate:()=>{"worklet";return s.value<t?(s.value=(0,_reactNativeReanimated.withSpring)(t,SPRING_CONFIG),d.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),o.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),v.value=t,_.value=0,void(m.value=0)):s.value>a?(s.value=(0,_reactNativeReanimated.withSpring)(a,SPRING_CONFIG),void(v.value=a)):void(v.value=s.value)}}),[r,s,v,d,o,_,m,t,a]),h=(0,_reactNativeGestureHandler.usePinchGesture)(S),p=(0,_react.useMemo)(()=>({enabled:!r,minPointers:1,maxPointers:1,onActivate:()=>{"worklet";_.value=d.value,m.value=o.value},onUpdate:e=>{"worklet";s.value<=1||(d.value=_.value+e.translationX,o.value=m.value+e.translationY)},onDeactivate:()=>{"worklet";_.value=d.value,m.value=o.value}}),[r,s,d,o,_,m]),I=(0,_reactNativeGestureHandler.usePanGesture)(p),G=(0,_react.useMemo)(()=>({enabled:!r,numberOfTaps:2,onDeactivate:()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(R)(),s.value>1?(s.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),d.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),o.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),v.value=1,_.value=0,m.value=0):(s.value=(0,_reactNativeReanimated.withSpring)(i,SPRING_CONFIG),v.value=i)}}),[r,s,v,d,o,_,m,R,i]),g=(0,_reactNativeGestureHandler.useTapGesture)(G),f=(0,_reactNativeGestureHandler.useCompetingGestures)(h,I,g),b=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:d.value},{translateY:o.value},{scale:s.value}]}),[d,o,s]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:f,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[styles.container,n],testID:c,accessibilityLabel:u,accessibilityState:{disabled:r},"aria-disabled":r,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[styles.content,b],children:e})})})};exports.ZoomableImage=ZoomableImage,ZoomableImage.displayName="ZoomableImage";const styles=_reactNative.StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center",overflow:"hidden"},content:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"}});var _default=exports.default=ZoomableImage;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useDragToDismiss=exports.createDragToDismissController=exports.DRAG_DISMISS_VELOCITY=exports.DRAG_DISMISS_DISTANCE=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_index=require("../theme/index.js"),_nativeDriver=require("../utils/nativeDriver.js"),_usePresenceMotion=require("./usePresenceMotion.js");const DRAG_DISMISS_DISTANCE=exports.DRAG_DISMISS_DISTANCE=100,DRAG_DISMISS_VELOCITY=exports.DRAG_DISMISS_VELOCITY=.5,createDragToDismissController=({drag:e,travel:t,onDismiss:r,opacity:a},i,s)=>{const{snappy:n}=i.spring,springBack=()=>_reactNative.Animated.spring(e,{toValue:0,damping:n.damping,stiffness:n.stiffness,mass:n.mass,useNativeDriver:_nativeDriver.nativeDriver}).start(),o=!0===s?.reduced?a:void 0,u=s?.duration("default")??i.duration.default;return{move:t=>{(0,_index.setNativeValue)(e,Math.max(0,t))},release:(a,s)=>{if(a>DRAG_DISMISS_DISTANCE||s>DRAG_DISMISS_VELOCITY){if(o)return void _reactNative.Animated.timing(o,{toValue:0,duration:u,easing:_reactNative.Easing.bezier(...i.ease.accelerate),useNativeDriver:_nativeDriver.nativeDriver}).start(()=>r());_reactNative.Animated.timing(e,{toValue:"function"==typeof t?t():t,duration:i.duration.fast,easing:_reactNative.Easing.bezier(...i.ease.accelerate),useNativeDriver:_nativeDriver.nativeDriver}).start(()=>r())}else springBack()},cancel:springBack}};exports.createDragToDismissController=createDragToDismissController;const useDragToDismiss=e=>{const{drag:t,travel:r,onDismiss:a,contentAtTop:i,scrollGesture:s}=e,{motion:n}=(0,_index.useTheme)(),o=(0,_usePresenceMotion.usePresenceMotion)(),u=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current;return(0,_react.useMemo)(()=>{const e=createDragToDismissController({drag:t,travel:r,onDismiss:a,opacity:u},n,o),c=_reactNativeGestureHandler.Gesture.Pan().runOnJS(!0).activeOffsetY(6).failOffsetX([-12,12]).onUpdate(t=>e.move(t.translationY)).onEnd(t=>e.release(t.translationY,t.velocityY/1e3)).onFinalize((_e,t)=>{t||e.cancel()});let l=0,D=!1;const v=_reactNativeGestureHandler.Gesture.Pan().runOnJS(!0).activeOffsetY(8).failOffsetX([-12,12]).onBegin(()=>{l=0,D=!1}).onUpdate(t=>{if(!D){if(i&&!i())return;D=!0,l=t.translationY}e.move(t.translationY-l)}).onEnd(t=>{D&&e.release(t.translationY-l,t.velocityY/1e3)}).onFinalize((_e,t)=>{!t&&D&&e.cancel()});return s&&v.simultaneousWithExternalGesture(s),{handleGesture:c,sheetGesture:v,opacity:u}},[t,r,a,i,s,n,o,u])};exports.useDragToDismiss=useDragToDismiss;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useDragToDismiss=exports.createDragToDismissController=exports.DRAG_DISMISS_VELOCITY=exports.DRAG_DISMISS_DISTANCE=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_index=require("../theme/index.js"),_nativeDriver=require("../utils/nativeDriver.js"),_usePresenceMotion=require("./usePresenceMotion.js");const DRAG_DISMISS_DISTANCE=exports.DRAG_DISMISS_DISTANCE=100,DRAG_DISMISS_VELOCITY=exports.DRAG_DISMISS_VELOCITY=.5,createDragToDismissController=({drag:e,travel:t,onDismiss:r,opacity:a},i,s)=>{const{snappy:n}=i.spring,springBack=()=>_reactNative.Animated.spring(e,{toValue:0,damping:n.damping,stiffness:n.stiffness,mass:n.mass,useNativeDriver:_nativeDriver.nativeDriver}).start(),o=!0===s?.reduced?a:void 0,c=s?.duration("default")??i.duration.default;return{move:t=>{(0,_index.setNativeValue)(e,Math.max(0,t))},release:(a,s)=>{if(a>DRAG_DISMISS_DISTANCE||s>DRAG_DISMISS_VELOCITY){if(o)return void _reactNative.Animated.timing(o,{toValue:0,duration:c,easing:_reactNative.Easing.bezier(...i.ease.accelerate),useNativeDriver:_nativeDriver.nativeDriver}).start(()=>r());_reactNative.Animated.timing(e,{toValue:"function"==typeof t?t():t,duration:i.duration.fast,easing:_reactNative.Easing.bezier(...i.ease.accelerate),useNativeDriver:_nativeDriver.nativeDriver}).start(()=>r())}else springBack()},cancel:springBack}};exports.createDragToDismissController=createDragToDismissController;const useDragToDismiss=e=>{const{drag:t,travel:r,onDismiss:a,contentAtTop:i,scrollGesture:s}=e,{motion:n}=(0,_index.useTheme)(),o=(0,_usePresenceMotion.usePresenceMotion)(),c=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,u=(0,_react.useMemo)(()=>createDragToDismissController({drag:t,travel:r,onDismiss:a,opacity:c},n,o),[t,r,a,c,n,o]),l=(0,_react.useMemo)(()=>({runOnJS:!0,activeOffsetY:6,failOffsetX:[-12,12],onUpdate:e=>u.move(e.translationY),onDeactivate:e=>u.release(e.translationY,e.velocityY/1e3),onFinalize:e=>{e.canceled&&u.cancel()}}),[u]),D=(0,_reactNativeGestureHandler.usePanGesture)(l),v=(0,_react.useMemo)(()=>{let e=0,t=!1;return{runOnJS:!0,activeOffsetY:8,failOffsetX:[-12,12],simultaneousWith:s,onBegin:()=>{e=0,t=!1},onUpdate:r=>{if(!t){if(i&&!i())return;t=!0,e=r.translationY}u.move(r.translationY-e)},onDeactivate:r=>{t&&u.release(r.translationY-e,r.velocityY/1e3)},onFinalize:e=>{e.canceled&&t&&u.cancel()}}},[u,i,s]),_=(0,_reactNativeGestureHandler.usePanGesture)(v);return(0,_react.useMemo)(()=>({handleGesture:D,sheetGesture:_,opacity:c}),[D,_,c])};exports.useDragToDismiss=useDragToDismiss;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NavigationScreen=NavigationScreen;var _bottomTabs=require("@react-navigation/bottom-tabs"),_native=require("@react-navigation/native"),_react=require("react"),_index=require("../components/Screen/index.js"),_index2=require("../theme/index.js"),_jsxRuntime=require("react/jsx-runtime");const TAB_EDGES=["top"];function NavigationScreen({kind:e="pushed",appBar:t=!0,onBack:i,...n}){const o=(0,_native.useNavigation)(),r=(0,_react.useContext)(_bottomTabs.BottomTabBarHeightContext),a=!0===(0,_index2.useTheme)().settings.components.screen?.tabBarFloats,s=t?n:{...n,title:void 0,subtitle:void 0,leading:void 0,trailing:void 0,rightActions:void 0};return"tab"===e?(0,_jsxRuntime.jsx)(_index.Screen,{...s,largeTitle:!1,edges:TAB_EDGES,bottomInset:a?r??0:0}):(0,_jsxRuntime.jsx)(_index.Screen,{...s,largeTitle:!1,onBack:"root"!==e&&t?i??o.goBack:void 0})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NavigationScreen=NavigationScreen;var _native=require("@react-navigation/native"),_react=require("react"),_index=require("../components/Screen/index.js"),_index2=require("../theme/index.js"),_jsxRuntime=require("react/jsx-runtime");const TabBarHeightContext=(()=>{try{return require("@react-navigation/bottom-tabs").BottomTabBarHeightContext}catch{return(0,_react.createContext)(void 0)}})(),TAB_EDGES=["top"];function NavigationScreen({kind:e="pushed",appBar:t=!0,onBack:i,...n}){const r=(0,_native.useNavigation)(),a=(0,_react.useContext)(TabBarHeightContext),o=!0===(0,_index2.useTheme)().settings.components.screen?.tabBarFloats,s=t?n:{...n,title:void 0,subtitle:void 0,leading:void 0,trailing:void 0,rightActions:void 0};return"tab"===e?(0,_jsxRuntime.jsx)(_index.Screen,{...s,largeTitle:!1,edges:TAB_EDGES,bottomInset:o?a??0:0}):(0,_jsxRuntime.jsx)(_index.Screen,{...s,largeTitle:!1,onBack:"root"!==e&&t?i??r.goBack:void 0})}
@@ -1 +1 @@
1
- "use strict";import{formatCompactNumber,formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import{useControllableState}from"../../hooks/index.js";import{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{Text}from"../Text/index.js";import{barScale}from"./scale.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BAR_CHART_LABELS=Object.freeze({chart:"Bar chart",noData:"no data",highest:(e,t)=>`Highest: ${e}, ${t}`});const AUTO_VALUES_MAX_BARS=7,MAX_BAR_WIDTH=40,BAR_SHARE=.6,MIN_BAR_HEIGHT=2,VALUE_LABEL_ROOM=20,PLOT_PAD=6,HEADER_MIN_HEIGHT=48,AXIS_LABEL_MIN_WIDTH=44,CHAR_WIDTH=8,SWATCH_SIZE=10,STACK_TONES=["primary","info","success","warning","danger","neutral"],FONT_SCALE_CAP=1.2,toneColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],safe=e=>"number"==typeof e&&Number.isFinite(e)?e:0,entryAt=(e,t)=>{const r=e[t];if(void 0===r)throw new Error(`BarChart has no entry at index ${t}.`);return r},defaultFormatValue=e=>formatNumber(e),defaultFormatTick=e=>formatCompactNumber(e),BarChart=forwardRef((e,t)=>{const{data:r,tone:s="primary",color:a,series:o,height:i=160,label:l,summary:n,formatValue:c=defaultFormatValue,formatTick:u=defaultFormatTick,showValues:m,selection:h,defaultSelection:d=null,onSelect:p,haptic:x,labels:f,style:y,testID:b}=e;assertValidValue("BarChart","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const _=useMemo(()=>({...DEFAULT_BAR_CHART_LABELS,...f}),[f]),g=useTheme(),A=r.length,[S,w]=useState(0),[j,C]=useControllableState({value:h,defaultValue:d,onChange:p}),T=null!==j&&j>=0&&j<A?j:null,M=useRef(T);M.current=T;const R=useRef(-1),v=resolveHaptic(x,"tick"),V=useCallback(()=>{v&&triggerHaptic(v)},[v]),L=m??(A>0&&A<=7),$=void 0!==o&&o.length>0,D=useMemo(()=>$?o.map((e,t)=>e.tone??entryAt(STACK_TONES,t%STACK_TONES.length)):[],[$,o]),E=useMemo(()=>$?o.map(e=>e.key):[],[$,o]),I=useMemo(()=>$?r.map(e=>o.map(t=>safe(e.values?.[t.key]))):null,[r,o,$]),B=useMemo(()=>I?I.map(e=>e.reduce((e,t)=>e+t,0)):r.map(e=>safe(e.value)),[r,I]),k=useMemo(()=>I?I.flatMap(e=>[e.reduce((e,t)=>t>0?e+t:e,0),e.reduce((e,t)=>t<0?e+t:e,0)]):B,[I,B]),H=useMemo(()=>barScale(k),[k]),O=L?20:6,F=L&&H.min<0?20:6,N=Math.max(1,i-O-F),G=useCallback(e=>O+(H.max-e)/(H.max-H.min)*N,[O,H.max,H.min,N]),W=G(0),U=useMemo(()=>H.ticks.map(e=>u(e)),[H.ticks,u]),z=Math.ceil(8*Math.max(...U.map(e=>e.length),1)*1.2)+g.space.xs,P=A>0?S/A:0,X=Math.max(1,Math.ceil(44/Math.max(1,P||44))),K=useCallback(e=>{const t=entryAt(r,e);if(t.accessibilityLabel)return t.accessibilityLabel;if(I&&o){const r=entryAt(I,e);return`${t.label}, ${o.map((e,t)=>`${e.label} ${c(entryAt(r,t))}`).join(", ")}`}return`${t.label}, ${c(entryAt(B,e))}`},[r,c,B,I,o]),J=useMemo(()=>{let e=-1,t=0;for(const[r,s]of B.entries())(-1===e||s>t)&&(e=r,t=s);return e},[B]),Y=n??(J>=0?_.highest(entryAt(r,J).label,c(entryAt(B,J))):""),Z=useRef({fire:V,setSelected:C,count:A,plotWidth:S});Z.current={fire:V,setSelected:C,count:A,plotWidth:S};const q=useMemo(()=>{const indexAt=e=>{const{count:t,plotWidth:r}=Z.current;return 0===t||r<=0||!Number.isFinite(e)?-1:Math.min(t-1,Math.max(0,Math.floor(e/r*t)))},scrubTo=e=>{const t=indexAt(e);t<0||t===R.current||(R.current=t,Z.current.fire(),Z.current.setSelected(t))},e=Gesture.Pan().runOnJS(!0).activeOffsetX([-8,8]).failOffsetY([-12,12]).onStart(e=>{R.current=M.current??-1,scrubTo(e.x)}).onUpdate(e=>scrubTo(e.x)).withTestId(b?`${b}-pan`:"bar-chart-pan"),t=Gesture.Tap().runOnJS(!0).onEnd((e,t)=>{if(!t)return;const r=indexAt(e.x);r<0||(Z.current.fire(),R.current=r,Z.current.setSelected(r===M.current?null:r))}).withTestId(b?`${b}-tap`:"bar-chart-tap");return Gesture.Race(e,t)},[b]),Q=useCallback(e=>{if(0===A)return;const t=M.current,r="increment"===e.nativeEvent.actionName?null===t?0:Math.min(A-1,t+1):null===t?A-1:Math.max(0,t-1);r!==t&&(V(),C(r))},[A,V,C]),ee=useCallback(e=>{const t=Math.round(e.nativeEvent.layout.width);w(e=>e===t?e:t)},[]),te=a??toneColor(g,s),re=g.radius.sm,se=l??_.chart,ae=0===A?`${se}, ${_.noData}`:Y?`${se}, ${Y}`:se,oe=null===T?Y:K(T),ie=Math.min(40,Math.max(4,.6*P)),renderStack=(e,t,r)=>{const s=e.reduce((e,t)=>t>0?e+t:e,0),a=e.reduce((e,t)=>t<0?e+t:e,0);if(0===s&&0===a)return null;const o=G(s),i=[];let l=0,n=0;return e.forEach((e,r)=>{if(0===e)return;const s=e>0?l:n,a=s+e;e>0?l=a:n=a;const c=G(s),u=G(a);i.push(_jsx(View,{testID:b?`${b}-bar-${t}-series-${r}`:void 0,style:{position:"absolute",left:0,right:0,top:Math.min(c,u)-o,height:Math.abs(c-u),backgroundColor:toneColor(g,entryAt(D,r))}},entryAt(E,r)))}),_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-ie)/2,top:o,width:ie,height:Math.max(2,G(a)-o),overflow:"hidden",opacity:r?.4:1,...smoothCorners,...s>0?{borderTopLeftRadius:re,borderTopRightRadius:re}:null,...a<0?{borderBottomLeftRadius:re,borderBottomRightRadius:re}:null},children:i})},le=B.map((e,t)=>{const r=G(e),s=e>=0?r:W,a=0===e?0:Math.max(2,Math.abs(r-W)),o=null!==T&&T!==t;return _jsxs(View,{style:[styles.slot,{height:i}],children:[S>0&&I?renderStack(entryAt(I,t),t,o):null,S>0&&!I&&a>0?_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-ie)/2,top:s,width:ie,height:a,backgroundColor:te,opacity:o?.4:1,...smoothCorners,...e>=0?{borderTopLeftRadius:re,borderTopRightRadius:re}:{borderBottomLeftRadius:re,borderBottomRightRadius:re}}}):null,L&&S>0?_jsx(Text,{variant:"caption",color:"secondary",align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",left:0,right:0,top:e>=0?(I?G(entryAt(k,2*t)):r)-20+2:(I?G(entryAt(k,2*t+1)):r)+2},children:u(e)}):null]},t)});return 0===A?_jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:ae,testID:b,style:[styles.root,y],children:_jsx(Text,{variant:"bodySmall",color:"secondary",children:"No data"})}):_jsxs(View,{ref:t,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:ae,accessibilityValue:{min:0,max:A-1,now:T??0,text:oe},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Q,testID:b,style:[styles.root,y],children:[_jsx(View,{style:[styles.header,{minHeight:48,marginBottom:g.space.sm}],children:null===T?Y?_jsx(Text,{variant:"bodySmall",color:"secondary",children:Y}):null:_jsxs(_Fragment,{children:[_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,children:entryAt(r,T).label}),_jsx(Text,{variant:"h3",numberOfLines:1,testID:b?`${b}-callout`:void 0,children:c(entryAt(B,T))})]})}),_jsxs(View,{style:styles.body,children:[_jsx(View,{style:{width:z,height:i},children:H.ticks.map((e,t)=>_jsx(Text,{variant:"caption",color:"tertiary",align:"right",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",right:g.space.xs,left:0,top:G(e)-8},children:entryAt(U,t)},e))}),_jsxs(View,{style:styles.plotColumn,children:[_jsx(GestureDetector,{gesture:q,children:_jsxs(View,{style:{height:i},onLayout:ee,testID:b?`${b}-plot`:void 0,children:[H.ticks.map(e=>_jsx(View,{pointerEvents:"none",style:{position:"absolute",left:0,right:0,top:G(e)-(0===e?.75:StyleSheet.hairlineWidth),height:0===e?1.5:2*StyleSheet.hairlineWidth,backgroundColor:0===e?g.colors["text-subtle"]:g.colors["border-subtle"]}},e)),_jsx(View,{style:[styles.slots,{height:i}],children:le})]})}),_jsx(View,{style:styles.axis,children:r.map((e,t)=>_jsx(View,{style:styles.axisSlot,children:t%X===0?_jsx(Text,{variant:"caption",color:T===t?"primary":"tertiary",weight:T===t?"semibold":void 0,align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:P>0?{width:P*X}:void 0,children:e.axisLabel??e.label}):null},t))})]})]}),o&&$?_jsx(View,{style:[styles.legend,{marginTop:g.space.sm,columnGap:g.space.md,rowGap:g.space.xs}],children:o.map((e,t)=>_jsxs(View,{style:[styles.legendItem,{columnGap:g.space.xs}],children:[_jsx(View,{style:{width:10,height:10,borderRadius:g.radius.sm,...smoothCorners,backgroundColor:toneColor(g,entryAt(D,t))}}),_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,children:e.label})]},e.key))}):null]})});BarChart.displayName="BarChart";const styles=StyleSheet.create({root:{alignSelf:"stretch"},header:{justifyContent:"center"},body:{flexDirection:"row"},plotColumn:{flex:1},slots:{flexDirection:"row"},slot:{flex:1},axis:{flexDirection:"row"},legend:{flexDirection:"row",flexWrap:"wrap"},legendItem:{flexDirection:"row",alignItems:"center"},axisSlot:{flex:1,alignItems:"center",overflow:"visible"}});export{BarChart};export default BarChart;
1
+ "use strict";import{formatCompactNumber,formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,useTapGesture}from"react-native-gesture-handler";import{useControllableState}from"../../hooks/index.js";import{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{Text}from"../Text/index.js";import{barScale}from"./scale.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const DEFAULT_BAR_CHART_LABELS=Object.freeze({chart:"Bar chart",noData:"no data",highest:(e,t)=>`Highest: ${e}, ${t}`});const AUTO_VALUES_MAX_BARS=7,MAX_BAR_WIDTH=40,BAR_SHARE=.6,MIN_BAR_HEIGHT=2,VALUE_LABEL_ROOM=20,PLOT_PAD=6,HEADER_MIN_HEIGHT=48,AXIS_LABEL_MIN_WIDTH=44,CHAR_WIDTH=8,SWATCH_SIZE=10,STACK_TONES=["primary","info","success","warning","danger","neutral"],FONT_SCALE_CAP=1.2,toneColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],safe=e=>"number"==typeof e&&Number.isFinite(e)?e:0,entryAt=(e,t)=>{const r=e[t];if(void 0===r)throw new Error(`BarChart has no entry at index ${t}.`);return r},defaultFormatValue=e=>formatNumber(e),defaultFormatTick=e=>formatCompactNumber(e),BarChart=forwardRef((e,t)=>{const{data:r,tone:s="primary",color:a,series:o,height:i=160,label:l,summary:n,formatValue:c=defaultFormatValue,formatTick:u=defaultFormatTick,showValues:m,selection:h,defaultSelection:d=null,onSelect:p,haptic:x,labels:f,style:y,testID:b}=e;assertValidValue("BarChart","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const g=useMemo(()=>({...DEFAULT_BAR_CHART_LABELS,...f}),[f]),_=useTheme(),A=r.length,[C,S]=useState(0),[j,w]=useControllableState({value:h,defaultValue:d,onChange:p}),M=null!==j&&j>=0&&j<A?j:null,T=useRef(M);T.current=M;const v=useRef(-1),R=resolveHaptic(x,"tick"),V=useCallback(()=>{R&&triggerHaptic(R)},[R]),L=m??(A>0&&A<=7),D=void 0!==o&&o.length>0,$=useMemo(()=>D?o.map((e,t)=>e.tone??entryAt(STACK_TONES,t%STACK_TONES.length)):[],[D,o]),k=useMemo(()=>D?o.map(e=>e.key):[],[D,o]),I=useMemo(()=>D?r.map(e=>o.map(t=>safe(e.values?.[t.key]))):null,[r,o,D]),B=useMemo(()=>I?I.map(e=>e.reduce((e,t)=>e+t,0)):r.map(e=>safe(e.value)),[r,I]),E=useMemo(()=>I?I.flatMap(e=>[e.reduce((e,t)=>t>0?e+t:e,0),e.reduce((e,t)=>t<0?e+t:e,0)]):B,[I,B]),H=useMemo(()=>barScale(E),[E]),O=L?20:6,F=L&&H.min<0?20:6,N=Math.max(1,i-O-F),G=useCallback(e=>O+(H.max-e)/(H.max-H.min)*N,[O,H.max,H.min,N]),W=G(0),U=useMemo(()=>H.ticks.map(e=>u(e)),[H.ticks,u]),z=Math.ceil(8*Math.max(...U.map(e=>e.length),1)*1.2)+_.space.xs,P=A>0?C/A:0,X=Math.max(1,Math.ceil(44/Math.max(1,P||44))),K=useCallback(e=>{const t=entryAt(r,e);if(t.accessibilityLabel)return t.accessibilityLabel;if(I&&o){const r=entryAt(I,e);return`${t.label}, ${o.map((e,t)=>`${e.label} ${c(entryAt(r,t))}`).join(", ")}`}return`${t.label}, ${c(entryAt(B,e))}`},[r,c,B,I,o]),J=useMemo(()=>{let e=-1,t=0;for(const[r,s]of B.entries())(-1===e||s>t)&&(e=r,t=s);return e},[B]),Y=n??(J>=0?g.highest(entryAt(r,J).label,c(entryAt(B,J))):""),Z=useRef({fire:V,setSelected:w,count:A,plotWidth:C});Z.current={fire:V,setSelected:w,count:A,plotWidth:C};const q=useCallback(e=>{const{count:t,plotWidth:r}=Z.current;return 0===t||r<=0||!Number.isFinite(e)?-1:Math.min(t-1,Math.max(0,Math.floor(e/r*t)))},[]),Q=useCallback(e=>{const t=q(e);t<0||t===v.current||(v.current=t,Z.current.fire(),Z.current.setSelected(t))},[q]),ee=useMemo(()=>({runOnJS:!0,activeOffsetX:[-8,8],failOffsetY:[-12,12],onActivate:e=>{v.current=T.current??-1,Q(e.x)},onUpdate:e=>Q(e.x),testID:b?`${b}-pan`:"bar-chart-pan"}),[Q,b]),te=usePanGesture(ee),re=useMemo(()=>({runOnJS:!0,onDeactivate:e=>{if(e.canceled)return;const t=q(e.x);t<0||(Z.current.fire(),v.current=t,Z.current.setSelected(t===T.current?null:t))},testID:b?`${b}-tap`:"bar-chart-tap"}),[q,b]),se=useTapGesture(re),ae=useCompetingGestures(te,se),oe=useCallback(e=>{if(0===A)return;const t=T.current,r="increment"===e.nativeEvent.actionName?null===t?0:Math.min(A-1,t+1):null===t?A-1:Math.max(0,t-1);r!==t&&(V(),w(r))},[A,V,w]),ie=useCallback(e=>{const t=Math.round(e.nativeEvent.layout.width);S(e=>e===t?e:t)},[]),le=a??toneColor(_,s),ne=_.radius.sm,ce=l??g.chart,ue=0===A?`${ce}, ${g.noData}`:Y?`${ce}, ${Y}`:ce,me=null===M?Y:K(M),he=Math.min(40,Math.max(4,.6*P)),renderStack=(e,t,r)=>{const s=e.reduce((e,t)=>t>0?e+t:e,0),a=e.reduce((e,t)=>t<0?e+t:e,0);if(0===s&&0===a)return null;const o=G(s),i=[];let l=0,n=0;return e.forEach((e,r)=>{if(0===e)return;const s=e>0?l:n,a=s+e;e>0?l=a:n=a;const c=G(s),u=G(a);i.push(_jsx(View,{testID:b?`${b}-bar-${t}-series-${r}`:void 0,style:{position:"absolute",left:0,right:0,top:Math.min(c,u)-o,height:Math.abs(c-u),backgroundColor:toneColor(_,entryAt($,r))}},entryAt(k,r)))}),_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-he)/2,top:o,width:he,height:Math.max(2,G(a)-o),overflow:"hidden",opacity:r?.4:1,...smoothCorners,...s>0?{borderTopLeftRadius:ne,borderTopRightRadius:ne}:null,...a<0?{borderBottomLeftRadius:ne,borderBottomRightRadius:ne}:null},children:i})},de=B.map((e,t)=>{const r=G(e),s=e>=0?r:W,a=0===e?0:Math.max(2,Math.abs(r-W)),o=null!==M&&M!==t;return _jsxs(View,{style:[styles.slot,{height:i}],children:[C>0&&I?renderStack(entryAt(I,t),t,o):null,C>0&&!I&&a>0?_jsx(View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(P-he)/2,top:s,width:he,height:a,backgroundColor:le,opacity:o?.4:1,...smoothCorners,...e>=0?{borderTopLeftRadius:ne,borderTopRightRadius:ne}:{borderBottomLeftRadius:ne,borderBottomRightRadius:ne}}}):null,L&&C>0?_jsx(Text,{variant:"caption",color:"secondary",align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",left:0,right:0,top:e>=0?(I?G(entryAt(E,2*t)):r)-20+2:(I?G(entryAt(E,2*t+1)):r)+2},children:u(e)}):null]},t)});return 0===A?_jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:ue,testID:b,style:[styles.root,y],children:_jsx(Text,{variant:"bodySmall",color:"secondary",children:"No data"})}):_jsxs(View,{ref:t,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:ue,accessibilityValue:{min:0,max:A-1,now:M??0,text:me},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:oe,testID:b,style:[styles.root,y],children:[_jsx(View,{style:[styles.header,{minHeight:48,marginBottom:_.space.sm}],children:null===M?Y?_jsx(Text,{variant:"bodySmall",color:"secondary",children:Y}):null:_jsxs(_Fragment,{children:[_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,children:entryAt(r,M).label}),_jsx(Text,{variant:"h3",numberOfLines:1,testID:b?`${b}-callout`:void 0,children:c(entryAt(B,M))})]})}),_jsxs(View,{style:styles.body,children:[_jsx(View,{style:{width:z,height:i},children:H.ticks.map((e,t)=>_jsx(Text,{variant:"caption",color:"tertiary",align:"right",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",right:_.space.xs,left:0,top:G(e)-8},children:entryAt(U,t)},e))}),_jsxs(View,{style:styles.plotColumn,children:[_jsx(GestureDetector,{gesture:ae,children:_jsxs(View,{style:{height:i},onLayout:ie,testID:b?`${b}-plot`:void 0,children:[H.ticks.map(e=>_jsx(View,{pointerEvents:"none",style:{position:"absolute",left:0,right:0,top:G(e)-(0===e?.75:StyleSheet.hairlineWidth),height:0===e?1.5:2*StyleSheet.hairlineWidth,backgroundColor:0===e?_.colors["text-subtle"]:_.colors["border-subtle"]}},e)),_jsx(View,{style:[styles.slots,{height:i}],children:de})]})}),_jsx(View,{style:styles.axis,children:r.map((e,t)=>_jsx(View,{style:styles.axisSlot,children:t%X===0?_jsx(Text,{variant:"caption",color:M===t?"primary":"tertiary",weight:M===t?"semibold":void 0,align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:P>0?{width:P*X}:void 0,children:e.axisLabel??e.label}):null},t))})]})]}),o&&D?_jsx(View,{style:[styles.legend,{marginTop:_.space.sm,columnGap:_.space.md,rowGap:_.space.xs}],children:o.map((e,t)=>_jsxs(View,{style:[styles.legendItem,{columnGap:_.space.xs}],children:[_jsx(View,{style:{width:10,height:10,borderRadius:_.radius.sm,...smoothCorners,backgroundColor:toneColor(_,entryAt($,t))}}),_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,children:e.label})]},e.key))}):null]})});BarChart.displayName="BarChart";const styles=StyleSheet.create({root:{alignSelf:"stretch"},header:{justifyContent:"center"},body:{flexDirection:"row"},plotColumn:{flex:1},slots:{flexDirection:"row"},slot:{flex:1},axis:{flexDirection:"row"},legend:{flexDirection:"row",flexWrap:"wrap"},legendItem:{flexDirection:"row",alignItems:"center"},axisSlot:{flex:1,alignItems:"center",overflow:"visible"}});export{BarChart};export default BarChart;
@@ -1 +1 @@
1
- "use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Dimensions,Keyboard,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{ACTIONS_LAYOUTS,OverlayActions}from"../Dialog/OverlayActions.js";import{Modal}from"../Modal/Modal.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"});const DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=e=>{const{snapPoints:t=DEFAULT_SNAP_POINTS,open:o,onClose:s,snapIndex:n,onSnapChange:r,onAnimate:a,onAfterClose:i,enablePanDownToClose:l=!0,enableBackdropPress:u=!0,onBeforeClose:c,title:d,labels:h,scrollable:m=!1,scrollRef:f,onScroll:S,onContentSizeChange:b,onScrollLayout:p,scrollEventThrottle:v,keyboardBehavior:y="shift",inline:g=!1,presentation:w="sheet",animateMount:C=!0,handleIndicatorStyle:x,containerStyle:_,header:E,actions:M,actionsLayout:O="auto",footer:T,headerStyle:k,footerStyle:R,children:A,accessibilityLabel:I,accessibilityViewIsModal:j,testID:V}=e;assertValidValue("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),assertValidValue("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),assertValidValue("BottomSheet","actionsLayout",e.actionsLayout,ACTIONS_LAYOUTS);const D=useMemo(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,...h}),[h]),B=null!=E||null!=d,L=null!=M&&M.length>0,P=null!=T||L,N=g?"inline":"modal",H=useTheme(),G=usePresenceMotion(),F=useSafeAreaInsets(),[U,J]=useState(()=>Dimensions.get("window").height),[z,Y]=useState(()=>Dimensions.get("window").width),K=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&J(e=>e===t?e:t),o>0&&Y(e=>e===o?e:o)},[]),$=useWindowDimensions(),W="dialog"===w||"auto"===w&&Math.min($.width,$.height)>=600,X=Math.min(560,z-2*H.space.xl),[q,Q]=useModalInsets(),Z="modal"===N?q.top:F.top,ee="modal"===N?q.bottom:F.bottom,te=t.includes("content"),[oe,se]=useMeasuredHeight(),[ne,re]=useMeasuredHeight(),[ae,ie,le]=useMeasuredHeight(),[ue,ce]=useMeasuredHeight(),de=W?H.space.md:oe,he=te?Math.min(de+(B?ne:0)+ae+(P?ue:0)+ee,U-Z):0,me=useCallback((e,t)=>{te&&le(t),b?.(e,t)},[te,b,le]),fe=useMemo(()=>resolveSnapPoints(t,U,he),[t,U,he]),Se=U,be=fe[fe.length-1]??0,pe=useSharedValue(Se),ve=useSharedValue(Se),ye=useSharedValue(1),ge=useSharedValue(-1),[we,Ce]=useState(-1),xe=useRef(!1),[Ee,Me]=useState(!1),[Oe,Te]=useState(!1),ke=useRef(!1),Re=useRef(i);Re.current=i;const[Ae,Ie]=useState(!1),je=useRef(!C&&o),Ve=useRef(-1),De=useRef(!1);De.current="modal"===N?Oe:Ae;const Be=useRef(c);Be.current=c;const Le=useRef(s);Le.current=s;const Pe=useRef(!1),Ne=useRef(!0),He=useRef([]),Ge=useCallback(e=>{const t=He.current;He.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,Ge(!1)}),[Ge]);const Fe=useCallback(e=>{if(e<0||e>=fe.length)return Se;const t=fe[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return W?(U-t)/2:U-t},[fe,U,Se,W]),Ue=useCallback(e=>{Ve.current=e;we!==e&&(Ce(e),ge.value=e,e>=0&&r?.(e))},[we,ge,r]),Je=useCallback(()=>{xe.current=!1,ge.value<0&&(ke.current=!0,"modal"===N?(Me(!1),"ios"!==Platform.OS&&Te(!1)):Ie(!1))},[N,ge]),ze=useCallback(()=>{ke.current&&Te(!1)},[]);useEffect(()=>{("modal"===N?!Oe:!Ae)&&ke.current&&(ke.current=!1,Re.current?.(),Ge(!0))},[N,Oe,Ae,Ge]);const Ye=useCallback((e,t,o)=>{xe.current=!0,a?.(t,o),pe.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(Je)()})},[a,pe,Je]),Ke=useCallback(e=>{const t="number"==typeof e?clamp(e,0,fe.length-1):we>=0?we:0,o=ge.value,s=Fe(t);return ke.current=!1,Ge(!1),"modal"===N?(Te(!0),Me(!0)):Ie(!0),o<0&&je.current?(pe.value=s,ye.value=1,Ue(t),void a?.(o,t)):o<0&&G.reduced?(pe.value=s,ye.value=0,ye.value=withTiming(1,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Ue(t),void a?.(o,t)):(o<0&&(pe.value=Se,ye.value=1),Ue(t),void Ye(s,o,t))},[Ye,Se,we,ge,N,a,G,ye,fe.length,Ue,Ge,H.motion.ease.decelerate,pe,Fe]),$e=useCallback(()=>new Promise(e=>{if(Ve.current<0)return void(De.current?He.current.push(e):e(!0));He.current.push(e),je.current=!1;const t=ge.value;Ue(-1),xe.current=!0,a?.(t,-1);const o=G.reduced?ye:pe,s=G.reduced?0:Se;o.value=withTiming(s,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(Je)()})}),[Se,ge,Je,a,G,ye,Ue,pe,H.motion.ease.accelerate]),We=useCallback((e,t,o)=>{const s=Be.current;if(!s)return void e();if(Pe.current)return void t?.();const n=s();"boolean"!=typeof n?(Pe.current=!0,o?.(),n.then(o=>{Pe.current=!1,o&&Ne.current&&Ve.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(n?e:t)?.()},[]),Xe=useCallback(()=>new Promise(e=>{Ve.current<0?e(!0):We(()=>{Le.current(),$e(),e(!0)},()=>e(!1))}),[$e,We]),qe=useCallback(()=>{Le.current()},[]),Qe=useCallback(()=>{u&&Xe()},[u,Xe]),Ze=useRef(null);useEffect(()=>{const e=Ze.current!==o;Ze.current=o,e?o?Ke(n??0):$e():o&&"number"==typeof n&&n!==ge.value&&Ke(n)},[o,n]);const et=useRef({hostHeight:U,contentSnap:he});useEffect(()=>{const e=et.current;if(e.hostHeight===U&&e.contentSnap===he)return;if(et.current={hostHeight:U,contentSnap:he},e.hostHeight===U&&ge.value<0)return;const t=Fe(ge.value);pe.value=je.current?t:withSpring(t,SPRING_CONFIG)},[U,he]);const tt=U-be,ot=useMemo(()=>fe.map(e=>U-e),[fe,U]),st=useCallback(()=>{const e=Ve.current;e<0||Ye(Fe(e),e,e)},[Ye,Fe]),nt=useCallback((e,t)=>{const o=ge.value;-1!==e?(Ue(e),Ye(t,o,e)):We(()=>{Keyboard.dismiss(),triggerHaptic("selection"),Le.current(),$e()},st,st)},[Ye,$e,ge,We,Ue,st]),rt=useMemo(()=>Gesture.Native().withTestId(V?`${V}-content-gesture`:"bottom-sheet-content-gesture"),[V]),at=useMemo(()=>{const e=ot,t=Se,o=tt,s=l;return Gesture.Pan().withTestId(V?`${V}-pan-gesture`:"bottom-sheet-pan-gesture").activeOffsetY([-10,10]).failOffsetX([-15,15]).onStart(()=>{"worklet";ve.value=pe.value}).onUpdate(e=>{"worklet";const t=ve.value+e.translationY;pe.value=t<o?o+.25*(t-o):t}).onEnd(o=>{"worklet";const n=pe.value,r=o.velocityY,[a]=e;if(void 0===a)return void runOnJS(nt)(-1,t);if(r>1e3)return s?void runOnJS(nt)(-1,t):void runOnJS(nt)(0,a);let i=0,l=a,u=1/0,c=0;for(const t of e){const e=Math.abs(n-t);e<u&&(u=e,l=t,i=c),c++}s&&n-a>80?runOnJS(nt)(-1,t):runOnJS(nt)(i,l)})},[Se,ve,l,nt,tt,ot,V,pe]),{height:it}=useReanimatedKeyboardAnimation(),lt="shift"===y,ut=useDerivedValue(()=>lt?it.value:0,[lt,it]),ct=fe[we>=0?we:0]??be,dt=H.space.md,ht=useAnimatedStyle(()=>{if(W){const e=ut.value,t=U+e-ct-dt,o=e<0&&pe.value>t?t:pe.value;return{top:o<Z?Z:o,opacity:ye.value}}const e=pe.value+ut.value,t=ut.value<0?Z:tt;return{top:e<t?t:e,opacity:ye.value}},[W,ut,U,ct,dt,pe,Z,ye,tt]),mt=useAnimatedStyle(()=>{const e=ut.value;if(W){const t=U+e-ct-dt,o=e<0&&pe.value>t?t:pe.value,s=U+e-dt-(o<Z?Z:o);return{height:s<0?0:s>ct?ct:s}}const t=e<0?Z:tt,o=pe.value+e,s=U+e-(o<t?t:o);return{height:s<0?0:s>be?be:s}},[ut,W,U,ct,dt,pe,Z,tt,be]),ft=we>=0,St=useMemo(()=>buildStyles(H),[H]),bt=useCallback(()=>{u&&We(()=>{triggerHaptic("selection"),Le.current(),$e()})},[u,$e,We]),pt=useMemo(()=>Gesture.Tap().withTestId(V?`${V}-backdrop-gesture`:"bottom-sheet-backdrop-gesture").maxDuration(250).onEnd((_e,e)=>{"worklet";e&&runOnJS(bt)()}),[bt,V]),vt=useMemo(()=>({snapIndex:we,snapPoints:fe,close:qe,requestClose:Xe}),[we,fe,qe,Xe]);if("inline"===N&&!Ae)return null;if("modal"===N&&!Oe)return null;const yt=_jsxs(View,{collapsable:!1,style:["modal"===N?St.backdropModal:St.backdropInline,{backgroundColor:"modal"===N?transparentOf(H.colors.scrim):H.colors.scrim}],onLayout:K,testID:V,accessibilityViewIsModal:j??ft,children:[_jsx(GestureDetector,{gesture:pt,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:D.close})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:I,accessibilityViewIsModal:j??ft,accessibilityActions:[{name:"escape",label:D.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[St.sheet,{height:be,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,...smoothCorners,...H.shadow.modal},W?{height:ct,left:(z-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,_,ht],children:_jsxs(SheetBody,{style:[St.body,mt],keyboardOffset:ut,children:[W?_jsx(View,{style:{height:H.space.md}}):_jsx(GestureDetector,{gesture:at,children:_jsx(View,{style:St.handleRow,onLayout:te?se:void 0,accessible:!0,accessibilityLabel:D.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:V?`${V}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[St.handle,{backgroundColor:H.colors.border},x]})})}),B&&_jsxs(View,{style:[St.header,k],onLayout:te?re:void 0,children:[null!=d?_jsx(Text,{variant:"title",accessibilityRole:"header",children:d}):null,E]}),m?_jsx(GestureDetector,{gesture:rt,children:_jsx(ScrollView,{ref:f,style:St.scrollContent,onScroll:S,onContentSizeChange:me,onLayout:p,scrollEventThrottle:v,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:A})}):_jsx(View,{style:te?[St.content,{overflow:"visible"}]:St.content,children:te?_jsx(View,{onLayout:ie,children:A}):A}),P&&_jsxs(View,{style:[St.footer,R],onLayout:te?ce:void 0,children:[L?_jsx(View,{style:St.actions,children:_jsx(OverlayActions,{actions:M??[],layout:O})}):null,T]})]})})]}),gt=_jsx(BottomSheetContext.Provider,{value:vt,children:yt});return"modal"===N?_jsx(Modal,{open:Ee,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===Platform.OS?ze:void 0,children:"android"===Platform.OS?_jsx(GestureHandlerRootView,{style:St.modalRoot,children:gt}):gt}):gt},SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}},[s,t]);return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},header:{},actions:{padding:e.space.lg},footer:{},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
1
+ "use strict";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Dimensions,Keyboard,Platform,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture,usePanGesture,useTapGesture}from"react-native-gesture-handler";import{useReanimatedKeyboardAnimation}from"react-native-keyboard-controller";import Animated,{Easing,runOnJS,useAnimatedStyle,useDerivedValue,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{ACTIONS_LAYOUTS,OverlayActions}from"../Dialog/OverlayActions.js";import{Modal}from"../Modal/Modal.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"});const DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=createContext(null);export const useBottomSheet=()=>{const e=useContext(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};const SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,BottomSheet=e=>{const{snapPoints:t=DEFAULT_SNAP_POINTS,open:o,onClose:s,snapIndex:n,onSnapChange:r,onAnimate:a,onAfterClose:i,enablePanDownToClose:l=!0,enableBackdropPress:u=!0,onBeforeClose:c,title:d,labels:h,scrollable:m=!1,scrollRef:f,onScroll:S,onContentSizeChange:p,onScrollLayout:b,scrollEventThrottle:v,keyboardBehavior:y="shift",inline:g=!1,presentation:w="sheet",animateMount:C=!0,handleIndicatorStyle:x,containerStyle:_,header:M,actions:O,actionsLayout:E="auto",footer:k,headerStyle:R,footerStyle:T,children:A,accessibilityLabel:I,accessibilityViewIsModal:j,testID:V}=e;assertValidValue("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),assertValidValue("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),assertValidValue("BottomSheet","actionsLayout",e.actionsLayout,ACTIONS_LAYOUTS);const D=useMemo(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,...h}),[h]),B=null!=M||null!=d,L=null!=O&&O.length>0,P=null!=k||L,N=g?"inline":"modal",H=useTheme(),G=usePresenceMotion(),F=useSafeAreaInsets(),[U,J]=useState(()=>Dimensions.get("window").height),[z,Y]=useState(()=>Dimensions.get("window").width),K=useCallback(e=>{const{height:t,width:o}=e.nativeEvent.layout;t>0&&J(e=>e===t?e:t),o>0&&Y(e=>e===o?e:o)},[]),$=useWindowDimensions(),W="dialog"===w||"auto"===w&&Math.min($.width,$.height)>=600,X=Math.min(560,z-2*H.space.xl),[q,Q]=useModalInsets(),Z="modal"===N?q.top:F.top,ee="modal"===N?q.bottom:F.bottom,te=t.includes("content"),[oe,se]=useMeasuredHeight(),[ne,re]=useMeasuredHeight(),[ae,ie,le]=useMeasuredHeight(),[ue,ce]=useMeasuredHeight(),de=W?H.space.md:oe,he=te?Math.min(de+(B?ne:0)+ae+(P?ue:0)+ee,U-Z):0,me=useCallback((e,t)=>{te&&le(t),p?.(e,t)},[te,p,le]),fe=useMemo(()=>resolveSnapPoints(t,U,he),[t,U,he]),Se=U,pe=fe[fe.length-1]??0,be=useSharedValue(Se),ve=useSharedValue(Se),ye=useSharedValue(1),ge=useSharedValue(-1),[we,Ce]=useState(-1),xe=useRef(!1),[Me,Oe]=useState(!1),[Ee,ke]=useState(!1),Re=useRef(!1),Te=useRef(i);Te.current=i;const[Ae,Ie]=useState(!1),je=useRef(!C&&o),Ve=useRef(-1),De=useRef(!1);De.current="modal"===N?Ee:Ae;const Be=useRef(c);Be.current=c;const Le=useRef(s);Le.current=s;const Pe=useRef(!1),Ne=useRef(!0),He=useRef([]),Ge=useCallback(e=>{const t=He.current;He.current=[];for(const o of t)o(e)},[]);useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,Ge(!1)}),[Ge]);const Fe=useCallback(e=>{if(e<0||e>=fe.length)return Se;const t=fe[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return W?(U-t)/2:U-t},[fe,U,Se,W]),Ue=useCallback(e=>{Ve.current=e;we!==e&&(Ce(e),ge.value=e,e>=0&&r?.(e))},[we,ge,r]),Je=useCallback(()=>{xe.current=!1,ge.value<0&&(Re.current=!0,"modal"===N?(Oe(!1),"ios"!==Platform.OS&&ke(!1)):Ie(!1))},[N,ge]),ze=useCallback(()=>{Re.current&&ke(!1)},[]);useEffect(()=>{("modal"===N?!Ee:!Ae)&&Re.current&&(Re.current=!1,Te.current?.(),Ge(!0))},[N,Ee,Ae,Ge]);const Ye=useCallback((e,t,o)=>{xe.current=!0,a?.(t,o),be.value=withSpring(e,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(Je)()})},[a,be,Je]),Ke=useCallback(e=>{const t="number"==typeof e?clamp(e,0,fe.length-1):we>=0?we:0,o=ge.value,s=Fe(t);return Re.current=!1,Ge(!1),"modal"===N?(ke(!0),Oe(!0)):Ie(!0),o<0&&je.current?(be.value=s,ye.value=1,Ue(t),void a?.(o,t)):o<0&&G.reduced?(be.value=s,ye.value=0,ye.value=withTiming(1,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.decelerate),reduceMotion:PRESENCE_REDUCE_MOTION}),Ue(t),void a?.(o,t)):(o<0&&(be.value=Se,ye.value=1),Ue(t),void Ye(s,o,t))},[Ye,Se,we,ge,N,a,G,ye,fe.length,Ue,Ge,H.motion.ease.decelerate,be,Fe]),$e=useCallback(()=>new Promise(e=>{if(Ve.current<0)return void(De.current?He.current.push(e):e(!0));He.current.push(e),je.current=!1;const t=ge.value;Ue(-1),xe.current=!0,a?.(t,-1);const o=G.reduced?ye:be,s=G.reduced?0:Se;o.value=withTiming(s,{duration:G.duration("fast"),easing:Easing.bezier(...H.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(Je)()})}),[Se,ge,Je,a,G,ye,Ue,be,H.motion.ease.accelerate]),We=useCallback((e,t,o)=>{const s=Be.current;if(!s)return void e();if(Pe.current)return void t?.();const n=s();"boolean"!=typeof n?(Pe.current=!0,o?.(),n.then(o=>{Pe.current=!1,o&&Ne.current&&Ve.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(n?e:t)?.()},[]),Xe=useCallback(()=>new Promise(e=>{Ve.current<0?e(!0):We(()=>{Le.current(),$e(),e(!0)},()=>e(!1))}),[$e,We]),qe=useCallback(()=>{Le.current()},[]),Qe=useCallback(()=>{u&&Xe()},[u,Xe]),Ze=useRef(null);useEffect(()=>{const e=Ze.current!==o;Ze.current=o,e?o?Ke(n??0):$e():o&&"number"==typeof n&&n!==ge.value&&Ke(n)},[o,n]);const et=useRef({hostHeight:U,contentSnap:he});useEffect(()=>{const e=et.current;if(e.hostHeight===U&&e.contentSnap===he)return;if(et.current={hostHeight:U,contentSnap:he},e.hostHeight===U&&ge.value<0)return;const t=Fe(ge.value);be.value=je.current?t:withSpring(t,SPRING_CONFIG)},[U,he]);const tt=U-pe,ot=useMemo(()=>fe.map(e=>U-e),[fe,U]),st=useCallback(()=>{const e=Ve.current;e<0||Ye(Fe(e),e,e)},[Ye,Fe]),nt=useCallback((e,t)=>{const o=ge.value;-1!==e?(Ue(e),Ye(t,o,e)):We(()=>{Keyboard.dismiss(),triggerHaptic("selection"),Le.current(),$e()},st,st)},[Ye,$e,ge,We,Ue,st]),rt=useMemo(()=>({testID:V?`${V}-content-gesture`:"bottom-sheet-content-gesture"}),[V]),at=useNativeGesture(rt),it=useMemo(()=>{const e=ot,t=Se,o=tt,s=l;return{testID:V?`${V}-pan-gesture`:"bottom-sheet-pan-gesture",activeOffsetY:[-10,10],failOffsetX:[-15,15],onActivate:()=>{"worklet";ve.value=be.value},onUpdate:e=>{"worklet";const t=ve.value+e.translationY;be.value=t<o?o+.25*(t-o):t},onDeactivate:o=>{"worklet";const n=be.value,r=o.velocityY,[a]=e;if(void 0===a)return void runOnJS(nt)(-1,t);if(r>1e3)return s?void runOnJS(nt)(-1,t):void runOnJS(nt)(0,a);let i=0,l=a,u=1/0,c=0;for(const t of e){const e=Math.abs(n-t);e<u&&(u=e,l=t,i=c),c++}s&&n-a>80?runOnJS(nt)(-1,t):runOnJS(nt)(i,l)}}},[Se,ve,l,nt,tt,ot,V,be]),lt=usePanGesture(it),{height:ut}=useReanimatedKeyboardAnimation(),ct="shift"===y,dt=useDerivedValue(()=>ct?ut.value:0,[ct,ut]),ht=fe[we>=0?we:0]??pe,mt=H.space.md,ft=useAnimatedStyle(()=>{if(W){const e=dt.value,t=U+e-ht-mt,o=e<0&&be.value>t?t:be.value;return{top:o<Z?Z:o,opacity:ye.value}}const e=be.value+dt.value,t=dt.value<0?Z:tt;return{top:e<t?t:e,opacity:ye.value}},[W,dt,U,ht,mt,be,Z,ye,tt]),St=useAnimatedStyle(()=>{const e=dt.value;if(W){const t=U+e-ht-mt,o=e<0&&be.value>t?t:be.value,s=U+e-mt-(o<Z?Z:o);return{height:s<0?0:s>ht?ht:s}}const t=e<0?Z:tt,o=be.value+e,s=U+e-(o<t?t:o);return{height:s<0?0:s>pe?pe:s}},[dt,W,U,ht,mt,be,Z,tt,pe]),pt=we>=0,bt=useMemo(()=>buildStyles(H),[H]),vt=useCallback(()=>{u&&We(()=>{triggerHaptic("selection"),Le.current(),$e()})},[u,$e,We]),yt=useMemo(()=>({testID:V?`${V}-backdrop-gesture`:"bottom-sheet-backdrop-gesture",maxDuration:250,onDeactivate:e=>{"worklet";e.canceled||runOnJS(vt)()}}),[vt,V]),gt=useTapGesture(yt),wt=useMemo(()=>({snapIndex:we,snapPoints:fe,close:qe,requestClose:Xe}),[we,fe,qe,Xe]);if("inline"===N&&!Ae)return null;if("modal"===N&&!Ee)return null;const Ct=_jsxs(View,{collapsable:!1,style:["modal"===N?bt.backdropModal:bt.backdropInline,{backgroundColor:"modal"===N?transparentOf(H.colors.scrim):H.colors.scrim}],onLayout:K,testID:V,accessibilityViewIsModal:j??pt,children:[_jsx(GestureDetector,{gesture:gt,children:_jsx(Animated.View,{style:StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:D.close})}),_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:I,accessibilityViewIsModal:j??pt,accessibilityActions:[{name:"escape",label:D.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[bt.sheet,{height:pe,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,...smoothCorners,...H.shadow.modal},W?{height:ht,left:(z-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,_,ft],children:_jsxs(SheetBody,{style:[bt.body,St],keyboardOffset:dt,children:[W?_jsx(View,{style:{height:H.space.md}}):_jsx(GestureDetector,{gesture:lt,children:_jsx(View,{style:bt.handleRow,onLayout:te?se:void 0,accessible:!0,accessibilityLabel:D.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:V?`${V}-handle`:"bottom-sheet-handle",children:_jsx(View,{style:[bt.handle,{backgroundColor:H.colors.border},x]})})}),B&&_jsxs(View,{style:[bt.header,R],onLayout:te?re:void 0,children:[null!=d?_jsx(Text,{variant:"title",accessibilityRole:"header",children:d}):null,M]}),m?_jsx(GestureDetector,{gesture:at,children:_jsx(ScrollView,{ref:f,style:bt.scrollContent,onScroll:S,onContentSizeChange:me,onLayout:b,scrollEventThrottle:v,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:A})}):_jsx(View,{style:te?[bt.content,{overflow:"visible"}]:bt.content,children:te?_jsx(View,{onLayout:ie,children:A}):A}),P&&_jsxs(View,{style:[bt.footer,T],onLayout:te?ce:void 0,children:[L?_jsx(View,{style:bt.actions,children:_jsx(OverlayActions,{actions:O??[],layout:E})}):null,k]})]})})]}),xt=_jsx(BottomSheetContext.Provider,{value:wt,children:Ct});return"modal"===N?_jsx(Modal,{open:Me,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===Platform.OS?ze:void 0,children:"android"===Platform.OS?_jsx(GestureHandlerRootView,{style:bt.modalRoot,children:xt}):xt}):xt},SheetBody=({style:e,keyboardOffset:t,children:o})=>{const s=useSafeAreaInsets().bottom,n=useAnimatedStyle(()=>{const e=s+t.value;return{paddingBottom:e>0?e:0}},[s,t]);return _jsx(Animated.View,{style:[e,n],children:o})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=useState(0),o=useCallback(e=>{t(t=>t===e?t:e)},[]);return[e,useCallback(e=>o(e.nativeEvent.layout.height),[o]),o]},resolveSnapPoints=(e,t,o)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return o;const s=parseFloat(e);return Number.isNaN(s)?0:s/100*t})].sort((e,t)=>e-t),clamp=(e,t,o)=>Math.min(Math.max(e,t),o),buildStyles=e=>StyleSheet.create({backdropModal:{flex:1},backdropInline:{...StyleSheet.absoluteFill},sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},header:{},actions:{padding:e.space.lg},footer:{},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});export{BottomSheet};export default BottomSheet;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{Extrapolation,interpolate,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DRAWER_LABELS={close:"Close drawer",drawer:"Drawer"};const DEFAULT_CLOSE_VELOCITY_THRESHOLD=1e3,DEFAULT_DRAG_ACTIVATION_OFFSET=10,Drawer=forwardRef((e,t)=>{const{open:a,defaultOpen:o=!1,onOpenChange:r,side:i="left",width:s,enableSwipe:l=!0,enableBackdropPress:n=!0,backdropOpacity:u=.5,haptic:c,containerStyle:d,children:p,accessibilityLabel:f,labels:h,testID:m}=e,g=useTheme();assertValidValue("Drawer","side",e.side,["left","right","top","bottom"]);const b=useMemo(()=>({...DEFAULT_DRAWER_LABELS,...h}),[h]),S=usePresenceMotion(),v=S.reduced,E=S.duration("default"),w=S.duration("fast"),y=useSafeAreaInsets(),O="boolean"==typeof a,[M,_]=useState(()=>Dimensions.get("window"));useEffect(()=>{const e=Dimensions.addEventListener("change",({window:e})=>_(e));return()=>e.remove()},[]);const D="left"===i||"right"===i,C=useMemo(()=>resolveSize(s,D,M),[s,D,M]),R=useMemo(()=>closedOffsetOf(i,C),[i,C]),T=useSharedValue(o?0:R),x=useSharedValue(o?0:R),L=useSharedValue(o?1:0),[k,A]=useState(o),V=useSharedValue(o);useEffect(()=>{k||v||(T.value=R,x.value=R)},[R,k,T,x,v]);const j=g.motion.spring.snappy,I=useCallback(()=>{if(v)return T.value=0,void(L.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION}));L.value=1,T.value=withSpring(0,j)},[T,L,j,v,E]),N=useCallback(()=>{v?L.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(T.value=R)}):T.value=withSpring(R,j)},[T,L,R,j,v,w]),P=useCallback(e=>{A(t=>t===e?t:(r?.(e),e)),V.value=e},[r,V]),F=useCallback(()=>{P(!0),I()},[P,I]),U=useCallback(()=>{P(!1),N()},[P,N]),H=useCallback(()=>{k?U():F()},[k,F,U]);useImperativeHandle(t,()=>({open:F,close:U,toggle:H}),[F,U,H]),useEffect(()=>{O&&a!==k&&(a?F():U())},[a]);const B=useMemo(()=>{const e=R,t=i,a=l;let o=Gesture.Pan();return o=D?o.activeOffsetX([-10,10]).failOffsetY([-15,15]):o.activeOffsetY([-10,10]).failOffsetX([-15,15]),o.onStart(()=>{"worklet";a&&(x.value=T.value)}).onUpdate(t=>{"worklet";if(!a)return;const o=D?t.translationX:t.translationY,r=x.value+o,i=Math.min(0,e),s=Math.max(0,e);T.value=r<i?i+.25*(r-i):r>s?s+.25*(r-s):r}).onEnd(o=>{"worklet";if(!a)return;const r=D?o.velocityX:o.velocityY,i=T.value;let s=!1;s="left"===t||"top"===t?r<-1e3:r>1e3;const l=Math.abs(e),n=Math.abs(i)/l;s||n>.5?(runOnJS(P)(!1),v?L.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},t=>{"worklet";t&&(T.value=e)}):T.value=withSpring(e,j)):(runOnJS(P)(!0),v?(T.value=0,L.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION})):T.value=withSpring(0,j))})},[R,x,l,D,T,L,P,i,j,v,E,w]),Y=useAnimatedStyle(()=>D?{opacity:L.value,transform:[{translateX:T.value}]}:{opacity:L.value,transform:[{translateY:T.value}]},[D,T,L]),G=useAnimatedStyle(()=>({opacity:interpolate(T.value,[R,0],[0,u],Extrapolation.CLAMP)*L.value,pointerEvents:Math.abs(T.value-R)<.5?"none":"auto"}),[T,R,u,L]),X=useMemo(()=>buildStyles(g),[g]),J=useCallback(()=>{if(!n)return;const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),U()},[n,U,c]),z=useMemo(()=>sideLayoutOf(i,C,y),[i,C,y]),W=useRef(o);return k&&(W.current=!0),W.current?_jsxs(View,{style:StyleSheet.absoluteFill,pointerEvents:"box-none",testID:m,accessibilityViewIsModal:k,children:[_jsx(Animated.View,{style:[X.backdrop,{backgroundColor:g.colors.scrim},G],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:J,accessibilityRole:"button",accessibilityLabel:b.close,disabled:!n||!k})}),_jsx(GestureDetector,{gesture:B,children:_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:f??b.drawer,style:[z,{backgroundColor:g.colors.surface,...g.shadow.modal},d,Y],children:_jsx(View,{style:X.content,children:p})})})]}):null});Drawer.displayName="Drawer";const closedOffsetOf=(e,t)=>{switch(e){case"left":case"top":return-t;case"right":case"bottom":return t}},sideLayoutOf=(e,t,a)=>{switch(e){case"left":return{position:"absolute",top:0,bottom:0,left:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingLeft:a.left};case"right":return{position:"absolute",top:0,bottom:0,right:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingRight:a.right};case"top":return{position:"absolute",top:0,left:0,right:0,height:t,paddingTop:a.top,paddingLeft:a.left,paddingRight:a.right};case"bottom":return{position:"absolute",bottom:0,left:0,right:0,height:t,paddingBottom:a.bottom,paddingLeft:a.left,paddingRight:a.right}}},resolveSize=(e,t,a)=>{if("number"==typeof e)return e;if("string"==typeof e){const o=parseFloat(e);if(Number.isNaN(o))return t?280:Math.round(.4*a.height);return o/100*(t?a.width:a.height)}return t?280:Math.round(.4*a.height)},buildStyles=e=>StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},content:{flex:1}});export{Drawer};export default Drawer;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,usePanGesture}from"react-native-gesture-handler";import Animated,{Extrapolation,interpolate,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_DRAWER_LABELS={close:"Close drawer",drawer:"Drawer"};const DEFAULT_CLOSE_VELOCITY_THRESHOLD=1e3,DEFAULT_DRAG_ACTIVATION_OFFSET=10,Drawer=forwardRef((e,t)=>{const{open:a,defaultOpen:i=!1,onOpenChange:o,side:r="left",width:s,enableSwipe:l=!0,enableBackdropPress:n=!0,backdropOpacity:u=.5,haptic:c,containerStyle:d,children:p,accessibilityLabel:f,labels:h,testID:m}=e,g=useTheme();assertValidValue("Drawer","side",e.side,["left","right","top","bottom"]);const b=useMemo(()=>({...DEFAULT_DRAWER_LABELS,...h}),[h]),v=usePresenceMotion(),S=v.reduced,E=v.duration("default"),w=v.duration("fast"),y=useSafeAreaInsets(),O="boolean"==typeof a,[D,M]=useState(()=>Dimensions.get("window"));useEffect(()=>{const e=Dimensions.addEventListener("change",({window:e})=>M(e));return()=>e.remove()},[]);const _="left"===r||"right"===r,C=useMemo(()=>resolveSize(s,_,D),[s,_,D]),R=useMemo(()=>closedOffsetOf(r,C),[r,C]),T=useSharedValue(i?0:R),x=useSharedValue(i?0:R),A=useSharedValue(i?1:0),[L,k]=useState(i),V=useSharedValue(i);useEffect(()=>{L||S||(T.value=R,x.value=R)},[R,L,T,x,S]);const j=g.motion.spring.snappy,I=useCallback(()=>{if(S)return T.value=0,void(A.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION}));A.value=1,T.value=withSpring(0,j)},[T,A,j,S,E]),N=useCallback(()=>{S?A.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(T.value=R)}):T.value=withSpring(R,j)},[T,A,R,j,S,w]),P=useCallback(e=>{k(t=>t===e?t:(o?.(e),e)),V.value=e},[o,V]),F=useCallback(()=>{P(!0),I()},[P,I]),U=useCallback(()=>{P(!1),N()},[P,N]),H=useCallback(()=>{L?U():F()},[L,F,U]);useImperativeHandle(t,()=>({open:F,close:U,toggle:H}),[F,U,H]),useEffect(()=>{O&&a!==L&&(a?F():U())},[a]);const B=useMemo(()=>{const e=R,t=r,a=l;return{..._?{activeOffsetX:[-10,10],failOffsetY:[-15,15]}:{activeOffsetY:[-10,10],failOffsetX:[-15,15]},onActivate:()=>{"worklet";a&&(x.value=T.value)},onUpdate:t=>{"worklet";if(!a)return;const i=_?t.translationX:t.translationY,o=x.value+i,r=Math.min(0,e),s=Math.max(0,e);T.value=o<r?r+.25*(o-r):o>s?s+.25*(o-s):o},onDeactivate:i=>{"worklet";if(!a)return;const o=_?i.velocityX:i.velocityY,r=T.value;let s=!1;s="left"===t||"top"===t?o<-1e3:o>1e3;const l=Math.abs(e),n=Math.abs(r)/l;s||n>.5?(runOnJS(P)(!1),S?A.value=withTiming(0,{duration:w,reduceMotion:PRESENCE_REDUCE_MOTION},t=>{"worklet";t&&(T.value=e)}):T.value=withSpring(e,j)):(runOnJS(P)(!0),S?(T.value=0,A.value=withTiming(1,{duration:E,reduceMotion:PRESENCE_REDUCE_MOTION})):T.value=withSpring(0,j))}}},[R,x,l,_,T,A,P,r,j,S,E,w]),Y=usePanGesture(B),G=useAnimatedStyle(()=>_?{opacity:A.value,transform:[{translateX:T.value}]}:{opacity:A.value,transform:[{translateY:T.value}]},[_,T,A]),X=useAnimatedStyle(()=>({opacity:interpolate(T.value,[R,0],[0,u],Extrapolation.CLAMP)*A.value,pointerEvents:Math.abs(T.value-R)<.5?"none":"auto"}),[T,R,u,A]),J=useMemo(()=>buildStyles(g),[g]),z=useCallback(()=>{if(!n)return;const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),U()},[n,U,c]),W=useMemo(()=>sideLayoutOf(r,C,y),[r,C,y]),q=useRef(i);return L&&(q.current=!0),q.current?_jsxs(View,{style:StyleSheet.absoluteFill,pointerEvents:"box-none",testID:m,accessibilityViewIsModal:L,children:[_jsx(Animated.View,{style:[J.backdrop,{backgroundColor:g.colors.scrim},X],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:z,accessibilityRole:"button",accessibilityLabel:b.close,disabled:!n||!L})}),_jsx(GestureDetector,{gesture:Y,children:_jsx(Animated.View,{accessibilityRole:"alert",accessibilityLabel:f??b.drawer,style:[W,{backgroundColor:g.colors.surface,...g.shadow.modal},d,G],children:_jsx(View,{style:J.content,children:p})})})]}):null});Drawer.displayName="Drawer";const closedOffsetOf=(e,t)=>{switch(e){case"left":case"top":return-t;case"right":case"bottom":return t}},sideLayoutOf=(e,t,a)=>{switch(e){case"left":return{position:"absolute",top:0,bottom:0,left:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingLeft:a.left};case"right":return{position:"absolute",top:0,bottom:0,right:0,width:t,paddingTop:a.top,paddingBottom:a.bottom,paddingRight:a.right};case"top":return{position:"absolute",top:0,left:0,right:0,height:t,paddingTop:a.top,paddingLeft:a.left,paddingRight:a.right};case"bottom":return{position:"absolute",bottom:0,left:0,right:0,height:t,paddingBottom:a.bottom,paddingLeft:a.left,paddingRight:a.right}}},resolveSize=(e,t,a)=>{if("number"==typeof e)return e;if("string"==typeof e){const i=parseFloat(e);if(Number.isNaN(i))return t?280:Math.round(.4*a.height);return i/100*(t?a.width:a.height)}return t?280:Math.round(.4*a.height)},buildStyles=e=>StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},content:{flex:1}});export{Drawer};export default Drawer;
@@ -1 +1 @@
1
- "use strict";import{useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,StyleSheet}from"react-native";import{createAnimatedValue,fontFor,useTheme}from"../../theme/index.js";import{TextInkContext}from"../Text/textInk.js";import{hasFieldText,RequiredMark}from"./FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const FLOATED_LABEL_SCALE=.85;const FLOATED_LABEL_LIFT=1;export const useFloatingLabel=({label:e,enabled:t,floated:n,required:i=!1,variant:o,sizeTokens:r,leadingOffset:a,trailingOffset:s=0,textAlign:l="left",paddingLeft:u,lineHeight:d,restNudge:m=0,floatTrim:f=0,color:c,style:h})=>{const g=useTheme(),x=useRef(createAnimatedValue(n?1:0)).current,p=useRef(createAnimatedValue(n?1:0)).current,A="outline"===o,[R,S]=useState(null);return useEffect(()=>{const e=n?1:0,timing=(t,n)=>Animated.timing(t,{toValue:e,duration:g.motion.duration.fast,easing:Easing.bezier(...g.motion.ease["in-out"]),useNativeDriver:n});A||p.setValue(e);const t=A?Animated.parallel([timing(x,!0),timing(p,!1)]):timing(x,!0);return t.start(),()=>t.stop()},[n,A,x,p,g.motion.duration.fast,g.motion.ease["in-out"]]),useMemo(()=>{if(!t||!hasFieldText(e))return{node:null,topNotch:void 0};const n=d??R?.height??r.text,o=null!=d?r["padding-y"]+m:Math.max(0,(r["min-height"]-n)/2),T=-(o+n/2+1-f),j=x.interpolate({inputRange:[0,1],outputRange:[0,T]}),v=x.interpolate({inputRange:[0,1],outputRange:[1,.85]}),E=-a,L=x.interpolate({inputRange:[0,1],outputRange:[0,E]}),y="right"===l?{right:r["padding-x"]+s,transformOrigin:"right center"}:"center"===l?{alignSelf:"center",transformOrigin:"center"}:{left:u+a,transformOrigin:"left center"},F=g.space.xs,_=R?.85*R.width:0,b=R?"right"===l?R.width-_:"center"===l?(R.width-_)/2:0:0,w=A&&R?{left:R.x+E+b-F,width:p.interpolate({inputRange:[0,1],outputRange:[0,_+2*F]})}:void 0,O=StyleSheet.flatten(h),k={fontSize:O?.fontSize??r.text,color:O?.color??c};return{node:_jsxs(Animated.Text,{pointerEvents:"none",onLayout:e=>{const{x:t,width:n,height:i}=e.nativeEvent.layout;S(e=>e&&e.x===t&&e.width===n&&e.height===i?e:{x:t,width:n,height:i})},style:[styles.label,y,{top:o,color:c,fontSize:r.text,lineHeight:d,...fontFor(g,"medium"),transform:[{translateX:L},{translateY:j},{scale:v}]},h],children:[_jsx(TextInkContext.Provider,{value:k,children:e}),i?_jsx(RequiredMark,{}):null]}),topNotch:w}},[t,e,i,A,r,a,s,l,u,d,m,f,c,h,x,p,R,g])};const styles=StyleSheet.create({label:{position:"absolute",zIndex:1}});
1
+ "use strict";import{useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,StyleSheet}from"react-native";import{createAnimatedValue,fontFor,useTheme}from"../../theme/index.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{TextInkContext}from"../Text/textInk.js";import{hasFieldText,RequiredMark}from"./FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const FLOATED_LABEL_SCALE=.85;const FLOATED_LABEL_LIFT=1;export const useFloatingLabel=({label:e,enabled:t,floated:n,required:i=!1,variant:r,sizeTokens:o,leadingOffset:a,trailingOffset:s=0,textAlign:l="left",paddingLeft:u,lineHeight:d,restNudge:m=0,floatTrim:f=0,color:c,style:h})=>{const g=useTheme(),p=useRef(createAnimatedValue(n?1:0)).current,x=useRef(createAnimatedValue(n?1:0)).current,v="outline"===r,[A,R]=useState(null);return useEffect(()=>{const e=n?1:0,timing=(t,n)=>Animated.timing(t,{toValue:e,duration:g.motion.duration.fast,easing:Easing.bezier(...g.motion.ease["in-out"]),useNativeDriver:n});v||x.setValue(e);const t=v?Animated.parallel([timing(p,nativeDriver),timing(x,!1)]):timing(p,nativeDriver);return t.start(),()=>t.stop()},[n,v,p,x,g.motion.duration.fast,g.motion.ease["in-out"]]),useMemo(()=>{if(!t||!hasFieldText(e))return{node:null,topNotch:void 0};const n=d??A?.height??o.text,r=null!=d?o["padding-y"]+m:Math.max(0,(o["min-height"]-n)/2),S=-(r+n/2+1-f),T=p.interpolate({inputRange:[0,1],outputRange:[0,S]}),j=p.interpolate({inputRange:[0,1],outputRange:[1,.85]}),E=-a,L=p.interpolate({inputRange:[0,1],outputRange:[0,E]}),y="right"===l?{right:o["padding-x"]+s,transformOrigin:"right center"}:"center"===l?{alignSelf:"center",transformOrigin:"center"}:{left:u+a,transformOrigin:"left center"},F=g.space.xs,_=A?.85*A.width:0,b=A?"right"===l?A.width-_:"center"===l?(A.width-_)/2:0:0,w=v&&A?{left:A.x+E+b-F,width:x.interpolate({inputRange:[0,1],outputRange:[0,_+2*F]})}:void 0,D=StyleSheet.flatten(h),O={fontSize:D?.fontSize??o.text,color:D?.color??c};return{node:_jsxs(Animated.Text,{pointerEvents:"none",onLayout:e=>{const{x:t,width:n,height:i}=e.nativeEvent.layout;R(e=>e&&e.x===t&&e.width===n&&e.height===i?e:{x:t,width:n,height:i})},style:[styles.label,y,{top:r,color:c,fontSize:o.text,lineHeight:d,...fontFor(g,"medium"),transform:[{translateX:L},{translateY:T},{scale:j}]},h],children:[_jsx(TextInkContext.Provider,{value:O,children:e}),i?_jsx(RequiredMark,{}):null]}),topNotch:w}},[t,e,i,v,o,a,s,l,u,d,m,f,c,h,p,x,A,g])};const styles=StyleSheet.create({label:{position:"absolute",zIndex:1}});
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useState}from"react";import{Gesture}from"react-native-gesture-handler";import{runOnJS,scrollTo,useAnimatedRef,useAnimatedStyle,useScrollViewOffset,useSharedValue,withTiming}from"react-native-reanimated";const DOUBLE_TAP_ZOOM=2.5;export const ZOOM_REST=1.01;const clamp=(e,a,l)=>{"worklet";return Math.min(Math.max(e,a),l)},panLimit=(e,a)=>{"worklet";return e*(a-1)/2};export const useFileViewerZoom=({zoomEnabled:e,maxZoom:a,viewportWidth:l,viewportHeight:u,maxScroll:t})=>{const[i,n]=useState(1),v=useAnimatedRef(),r=useScrollViewOffset(v),o=useSharedValue(0),s=useSharedValue(0),m=useSharedValue(0),c=useSharedValue(0),h=useSharedValue(1),d=useSharedValue(1),w=useSharedValue(0),S=useSharedValue(0),p=useSharedValue(0),f=useSharedValue(0);useEffect(()=>{m.value=l,c.value=u,s.value=t},[l,u,t,m,c,s]);const T=useCallback(()=>{h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,n(1)},[h,d,w,S,p,f]);useEffect(()=>{e||T()},[e,T]);const g=useCallback(e=>n(e),[]),V=useMemo(()=>Gesture.Native(),[]),k=useMemo(()=>{const l=Math.max(1,a),u=Math.min(2.5,l),t=Gesture.Pinch().enabled(e).onStart(()=>{"worklet";d.value=h.value,p.value=w.value,f.value=S.value}).onUpdate(e=>{"worklet";const a=clamp(d.value*e.scale,1,l),u=e.focalX-m.value/2,t=e.focalY-c.value/2,i=a/d.value,n=panLimit(m.value,a),v=panLimit(c.value,a);w.value=clamp(u-(u-p.value)*i,-n,n),S.value=clamp(t-(t-f.value)*i,-v,v),h.value=a}).onEnd(()=>{"worklet";if(h.value<=1.01)return h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,void runOnJS(g)(1);d.value=h.value,p.value=w.value,f.value=S.value,runOnJS(g)(h.value)}),i=Gesture.Pan().enabled(e).minPointers(1).maxPointers(1).manualActivation(!0).onTouchesMove((e,a)=>{"worklet";h.value>1.01?a.activate():a.fail()}).onStart(()=>{"worklet";p.value=w.value,f.value=S.value,o.value=r.value}).onUpdate(e=>{"worklet";const a=h.value,l=panLimit(m.value,a),u=panLimit(c.value,a);w.value=clamp(p.value+e.translationX,-l,l);const t=f.value+e.translationY,i=clamp(t,-u,u),n=t-i;if(0!==n){const e=clamp(o.value-n/a,0,s.value);e!==o.value&&(o.value=e,scrollTo(v,0,e,!1)),f.value-=n}S.value=i}).onEnd(()=>{"worklet";p.value=w.value,f.value=S.value}),n=Gesture.Tap().enabled(e).numberOfTaps(2).maxDistance(10).onEnd(e=>{"worklet";if(h.value>1.01)return h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,void runOnJS(g)(1);if(u<=1.01)return;const a=e.x-m.value/2,l=e.y-c.value/2,t=panLimit(m.value,u),i=panLimit(c.value,u),n=clamp(-a*(u-1),-t,t),v=clamp(-l*(u-1),-i,i);h.value=withTiming(u),w.value=withTiming(n),S.value=withTiming(v),d.value=u,p.value=n,f.value=v,runOnJS(g)(u)});return t.simultaneousWithExternalGesture(V),i.simultaneousWithExternalGesture(V),n.simultaneousWithExternalGesture(V),Gesture.Simultaneous(t,i,n)},[a,e,g,V,v,r,o,s,m,c,h,d,w,S,p,f]),O=useAnimatedStyle(()=>({transform:[{translateX:w.value},{translateY:S.value},{scale:h.value}]}),[w,S,h]);return{scrollRef:v,scrollGesture:V,zoomGesture:k,zoomStyle:O,zoomLevel:i,resetZoom:T}};
1
+ "use strict";import{useCallback,useEffect,useMemo,useState}from"react";import{GestureStateManager,useNativeGesture,usePanGesture,usePinchGesture,useSimultaneousGestures,useTapGesture}from"react-native-gesture-handler";import{runOnJS,scrollTo,useAnimatedRef,useAnimatedStyle,useScrollViewOffset,useSharedValue,withTiming}from"react-native-reanimated";const DOUBLE_TAP_ZOOM=2.5;export const ZOOM_REST=1.01;const clamp=(e,a,u)=>{"worklet";return Math.min(Math.max(e,a),u)},panLimit=(e,a)=>{"worklet";return e*(a-1)/2};export const useFileViewerZoom=({zoomEnabled:e,maxZoom:a,viewportWidth:u,viewportHeight:l,maxScroll:t})=>{const[i,v]=useState(1),s=useAnimatedRef(),n=useScrollViewOffset(s),r=useSharedValue(0),o=useSharedValue(0),m=useSharedValue(0),c=useSharedValue(0),h=useSharedValue(1),S=useSharedValue(1),d=useSharedValue(0),p=useSharedValue(0),w=useSharedValue(0),f=useSharedValue(0);useEffect(()=>{m.value=u,c.value=l,o.value=t},[u,l,t,m,c,o]);const T=useCallback(()=>{h.value=withTiming(1),d.value=withTiming(0),p.value=withTiming(0),S.value=1,w.value=0,f.value=0,v(1)},[h,S,d,p,w,f]);useEffect(()=>{e||T()},[e,T]);const g=useCallback(e=>v(e),[]),G=useNativeGesture(),M=Math.max(1,a),V=Math.min(2.5,M),k=useMemo(()=>({enabled:e,simultaneousWith:G,onActivate:()=>{"worklet";S.value=h.value,w.value=d.value,f.value=p.value},onUpdate:e=>{"worklet";const a=clamp(S.value*e.scale,1,M),u=e.focalX-m.value/2,l=e.focalY-c.value/2,t=a/S.value,i=panLimit(m.value,a),v=panLimit(c.value,a);d.value=clamp(u-(u-w.value)*t,-i,i),p.value=clamp(l-(l-f.value)*t,-v,v),h.value=a},onDeactivate:()=>{"worklet";if(h.value<=1.01)return h.value=withTiming(1),d.value=withTiming(0),p.value=withTiming(0),S.value=1,w.value=0,f.value=0,void runOnJS(g)(1);S.value=h.value,w.value=d.value,f.value=p.value,runOnJS(g)(h.value)}}),[e,M,g,G,h,S,d,p,w,f,m,c]),O=useMemo(()=>({enabled:e,simultaneousWith:G,minPointers:1,maxPointers:1,manualActivation:!0,onTouchesMove:e=>{"worklet";h.value>1.01?GestureStateManager.activate(e.handlerTag):GestureStateManager.fail(e.handlerTag)},onActivate:()=>{"worklet";w.value=d.value,f.value=p.value,r.value=n.value},onUpdate:e=>{"worklet";const a=h.value,u=panLimit(m.value,a),l=panLimit(c.value,a);d.value=clamp(w.value+e.translationX,-u,u);const t=f.value+e.translationY,i=clamp(t,-l,l),v=t-i;if(0!==v){const e=clamp(r.value-v/a,0,o.value);e!==r.value&&(r.value=e,scrollTo(s,0,e,!1)),f.value-=v}p.value=i},onDeactivate:()=>{"worklet";w.value=d.value,f.value=p.value}}),[e,G,n,r,o,m,c,h,d,p,w,f,s]),x=useMemo(()=>({enabled:e,simultaneousWith:G,numberOfTaps:2,maxDistance:10,onDeactivate:e=>{"worklet";if(h.value>1.01)return h.value=withTiming(1),d.value=withTiming(0),p.value=withTiming(0),S.value=1,w.value=0,f.value=0,void runOnJS(g)(1);if(V<=1.01)return;const a=e.x-m.value/2,u=e.y-c.value/2,l=panLimit(m.value,V),t=panLimit(c.value,V),i=clamp(-a*(V-1),-l,l),v=clamp(-u*(V-1),-t,t);h.value=withTiming(V),d.value=withTiming(i),p.value=withTiming(v),S.value=V,w.value=i,f.value=v,runOnJS(g)(V)}}),[e,G,V,g,h,S,d,p,w,f,m,c]),L=usePinchGesture(k),b=usePanGesture(O),A=useTapGesture(x),P=useSimultaneousGestures(L,b,A),E=useAnimatedStyle(()=>({transform:[{translateX:d.value},{translateY:p.value},{scale:h.value}]}),[d,p,h]);return{scrollRef:s,scrollGesture:G,zoomGesture:P,zoomStyle:E,zoomLevel:i,resetZoom:T}};
@@ -1 +1 @@
1
- "use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Dimensions,Image,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Carousel}from"../Carousel/index.js";import{Modal}from"../Modal/Modal.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"};const MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:l=!0,enableLightbox:i=!0,enablePinchZoom:s=!0,onIndexChange:o,haptic:n,loading:r=!1,accessibilityLabel:c,containerStyle:u,testID:m,labels:d})=>{const h=useTheme(),g=useMemo(()=>buildStyles(h),[h]),p=useMemo(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...d}),[d]),[b,S]=useState(clamp(t,0,Math.max(0,e.length-1))),[x,y]=useState(!1),v=useCallback(e=>{S(e),o?.(e)},[o]),I=useCallback(()=>{if(!i)return;const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),y(!0)},[i,n]),w=useCallback(()=>{const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),y(!1)},[n]),C=useCallback((t,a)=>{const l=t.alt??p.imageOf(a+1,e.length);return _jsx(Pressable,{onPress:I,accessibilityRole:"image",accessibilityLabel:l,accessibilityHint:i?p.openFullscreen:void 0,style:g.imageWrap,children:_jsx(Image,{source:t.source,style:g.image,resizeMode:"cover"})})},[i,e.length,I,g,p]),_=useCallback(e=>_jsx(Image,{source:e.source,style:g.thumbnailImage,resizeMode:"cover"}),[g]),f=_jsxs(View,{style:[g.container,u],testID:m,accessibilityLabel:c??p.gallery,children:[_jsxs(View,{style:g.carouselWrap,accessibilityElementsHidden:x,importantForAccessibility:x?"no-hide-descendants":"auto",children:[_jsx(Carousel,{data:e,defaultIndex:t,onIndexChange:v,renderItem:C,showPagination:!1,showThumbnails:a,renderThumbnail:_,haptic:n}),l&&e.length>0?_jsx(View,{style:g.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:h.colors["on-scrim"]},accessibilityLabel:p.imageOf(b+1,e.length),children:`${b+1} / ${e.length}`})}):null]}),i?_jsx(Lightbox,{open:x,images:e,initialIndex:b,enablePinchZoom:s,showCounter:l,onClose:w,onIndexChange:v,haptic:n,labels:p}):null]});return r?_jsx(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:l,containerStyle:u,testID:m}):f};ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:l,testID:i})=>{const s=useTheme(),o=Math.min(e?.length||4,6);return _jsxs(View,{style:[{width:"100%"},l],testID:i,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[_jsxs(View,{style:{position:"relative"},children:[_jsx(Skeleton,{width:"100%",height:280,radius:"lg"}),a?_jsx(View,{style:{position:"absolute",top:12,right:12},children:_jsx(Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.md},children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},`sk-thumb-${t}`))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:l,showCounter:i,onClose:s,onIndexChange:o,haptic:n,labels:r})=>{const c=useTheme(),u=useMemo(()=>buildLightboxStyles(c),[c]),m=useRef(null),[d,h]=useState(a),g=useCallback(e=>{if(e!==d){const t=resolveHaptic(n,"selection");t&&triggerHaptic(t),h(e),o(e)}},[d,o,n]),p=useCallback((e,a)=>_jsx(ZoomableImage,{image:e,index:a,total:t.length,active:a===d,enabled:l,maxScale:4,minScale:1,doubleTapScale:2,haptic:n,imageLabel:r.imageOf}),[d,l,t.length,n,r]),b=t[d]?.caption;return _jsx(Modal,{open:e,onClose:s,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:_jsxs(View,{style:u.backdrop,children:[_jsx(Carousel,{ref:m,data:t,defaultIndex:a,onIndexChange:g,renderItem:p,showPagination:!1,haptic:n}),i&&t.length>0?_jsx(View,{style:u.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:c.colors["on-scrim"]},accessibilityLabel:r.imageOf(d+1,t.length),children:`${d+1} / ${t.length}`})}):null,_jsx(Pressable,{onPress:s,accessibilityRole:"button",accessibilityLabel:r.closeGallery,style:u.closeButton,hitSlop:12,...hitSlopMarker(12),children:(c.settings.icons.close??defaultIcons.close)({size:24,color:c.colors["on-scrim"]})}),b?_jsx(Animated.View,{style:u.captionWrap,entering:void 0,accessibilityElementsHidden:!1,children:_jsx(Text,{variant:"body",align:"center",numberOfLines:3,style:u.captionText,children:b})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:l,enabled:i,maxScale:s,minScale:o,doubleTapScale:n,haptic:r,imageLabel:c})=>{const u=Dimensions.get("window"),m=useSharedValue(1),d=useSharedValue(1),h=useSharedValue(0),g=useSharedValue(0),p=useSharedValue(0),b=useSharedValue(0),S=useCallback(()=>{m.value=withSpring(1,SPRING_CONFIG),d.value=1,h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),p.value=0,b.value=0},[m,d,h,g,p,b]);React.useEffect(()=>{l||(m.value=withTiming(1,{duration:150}),h.value=withTiming(0,{duration:150}),g.value=withTiming(0,{duration:150}),d.value=1,p.value=0,b.value=0)},[l,m,h,g,d,p,b]);const x=useCallback(()=>{!1!==r&&triggerHaptic("impactLight")},[r]),y=useMemo(()=>Gesture.Pinch().enabled(i).onStart(()=>{"worklet";d.value=m.value}).onUpdate(e=>{"worklet";const t=d.value*e.scale;m.value=t<o?o+.3*(t-o):t>s?s+.2*(t-s):t}).onEnd(()=>{"worklet";return m.value<o?(m.value=withSpring(o,SPRING_CONFIG),h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),d.value=o,p.value=0,void(b.value=0)):m.value>s?(m.value=withSpring(s,SPRING_CONFIG),void(d.value=s)):void(d.value=m.value)}),[i,m,d,h,g,p,b,o,s]),v=useMemo(()=>Gesture.Pan().minPointers(1).maxPointers(1).onStart(()=>{"worklet";p.value=h.value,b.value=g.value}).onUpdate(e=>{"worklet";m.value<=1||(h.value=p.value+e.translationX,g.value=b.value+e.translationY)}).onEnd(()=>{"worklet";p.value=h.value,b.value=g.value}),[m,h,g,p,b]),I=useMemo(()=>Gesture.Tap().numberOfTaps(2).onEnd(()=>{"worklet";runOnJS(x)(),m.value>1?(m.value=withSpring(1,SPRING_CONFIG),h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),d.value=1,p.value=0,b.value=0):(m.value=withSpring(n,SPRING_CONFIG),d.value=n)}),[m,d,h,g,p,b,x,n]),w=useMemo(()=>Gesture.Race(y,v,I),[y,v,I]),C=useAnimatedStyle(()=>({transform:[{translateX:h.value},{translateY:g.value},{scale:m.value}]}),[h,g,m]);React.useEffect(()=>{l||S()},[l,S]);const _=e.alt??c(t+1,a);return _jsx(GestureDetector,{gesture:w,children:_jsx(Animated.View,{style:[lightboxImageStyles.container,{width:u.width}],children:_jsx(Animated.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,C],accessibilityLabel:_,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,...smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"],lineHeight:21}}),lightboxImageStyles=StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});export{ImageGallery};export default ImageGallery;
1
+ "use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Dimensions,Image,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,usePinchGesture,useTapGesture}from"react-native-gesture-handler";import Animated,{runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Carousel}from"../Carousel/index.js";import{Modal}from"../Modal/Modal.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"};const MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:l=!0,enableLightbox:i=!0,enablePinchZoom:s=!0,onIndexChange:o,haptic:n,loading:r=!1,accessibilityLabel:u,containerStyle:c,testID:m,labels:h})=>{const d=useTheme(),g=useMemo(()=>buildStyles(d),[d]),p=useMemo(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...h}),[h]),[b,S]=useState(clamp(t,0,Math.max(0,e.length-1))),[v,x]=useState(!1),y=useCallback(e=>{S(e),o?.(e)},[o]),I=useCallback(()=>{if(!i)return;const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!0)},[i,n]),w=useCallback(()=>{const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!1)},[n]),C=useCallback((t,a)=>{const l=t.alt??p.imageOf(a+1,e.length);return _jsx(Pressable,{onPress:I,accessibilityRole:"image",accessibilityLabel:l,accessibilityHint:i?p.openFullscreen:void 0,style:g.imageWrap,children:_jsx(Image,{source:t.source,style:g.image,resizeMode:"cover"})})},[i,e.length,I,g,p]),_=useCallback(e=>_jsx(Image,{source:e.source,style:g.thumbnailImage,resizeMode:"cover"}),[g]),f=_jsxs(View,{style:[g.container,c],testID:m,accessibilityLabel:u??p.gallery,children:[_jsxs(View,{style:g.carouselWrap,accessibilityElementsHidden:v,importantForAccessibility:v?"no-hide-descendants":"auto",children:[_jsx(Carousel,{data:e,defaultIndex:t,onIndexChange:y,renderItem:C,showPagination:!1,showThumbnails:a,renderThumbnail:_,haptic:n}),l&&e.length>0?_jsx(View,{style:g.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:d.colors["on-scrim"]},accessibilityLabel:p.imageOf(b+1,e.length),children:`${b+1} / ${e.length}`})}):null]}),i?_jsx(Lightbox,{open:v,images:e,initialIndex:b,enablePinchZoom:s,showCounter:l,onClose:w,onIndexChange:y,haptic:n,labels:p}):null]});return r?_jsx(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:l,containerStyle:c,testID:m}):f};ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:l,testID:i})=>{const s=useTheme(),o=Math.min(e?.length||4,6);return _jsxs(View,{style:[{width:"100%"},l],testID:i,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[_jsxs(View,{style:{position:"relative"},children:[_jsx(Skeleton,{width:"100%",height:280,radius:"lg"}),a?_jsx(View,{style:{position:"absolute",top:12,right:12},children:_jsx(Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.md},children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},`sk-thumb-${t}`))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:l,showCounter:i,onClose:s,onIndexChange:o,haptic:n,labels:r})=>{const u=useTheme(),c=useMemo(()=>buildLightboxStyles(u),[u]),m=useRef(null),[h,d]=useState(a),g=useCallback(e=>{if(e!==h){const t=resolveHaptic(n,"selection");t&&triggerHaptic(t),d(e),o(e)}},[h,o,n]),p=useCallback((e,a)=>_jsx(ZoomableImage,{image:e,index:a,total:t.length,active:a===h,enabled:l,maxScale:4,minScale:1,doubleTapScale:2,haptic:n,imageLabel:r.imageOf}),[h,l,t.length,n,r]),b=t[h]?.caption;return _jsx(Modal,{open:e,onClose:s,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:_jsxs(View,{style:c.backdrop,children:[_jsx(Carousel,{ref:m,data:t,defaultIndex:a,onIndexChange:g,renderItem:p,showPagination:!1,haptic:n}),i&&t.length>0?_jsx(View,{style:c.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:u.colors["on-scrim"]},accessibilityLabel:r.imageOf(h+1,t.length),children:`${h+1} / ${t.length}`})}):null,_jsx(Pressable,{onPress:s,accessibilityRole:"button",accessibilityLabel:r.closeGallery,style:c.closeButton,hitSlop:12,...hitSlopMarker(12),children:(u.settings.icons.close??defaultIcons.close)({size:24,color:u.colors["on-scrim"]})}),b?_jsx(Animated.View,{style:c.captionWrap,entering:void 0,accessibilityElementsHidden:!1,children:_jsx(Text,{variant:"body",align:"center",numberOfLines:3,style:c.captionText,children:b})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:l,enabled:i,maxScale:s,minScale:o,doubleTapScale:n,haptic:r,imageLabel:u})=>{const c=Dimensions.get("window"),m=useSharedValue(1),h=useSharedValue(1),d=useSharedValue(0),g=useSharedValue(0),p=useSharedValue(0),b=useSharedValue(0),S=useCallback(()=>{m.value=withSpring(1,SPRING_CONFIG),h.value=1,d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),p.value=0,b.value=0},[m,h,d,g,p,b]);React.useEffect(()=>{l||(m.value=withTiming(1,{duration:150}),d.value=withTiming(0,{duration:150}),g.value=withTiming(0,{duration:150}),h.value=1,p.value=0,b.value=0)},[l,m,d,g,h,p,b]);const v=useCallback(()=>{!1!==r&&triggerHaptic("impactLight")},[r]),x=useMemo(()=>({enabled:i,onActivate:()=>{"worklet";h.value=m.value},onUpdate:e=>{"worklet";const t=h.value*e.scale;m.value=t<o?o+.3*(t-o):t>s?s+.2*(t-s):t},onDeactivate:()=>{"worklet";return m.value<o?(m.value=withSpring(o,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=o,p.value=0,void(b.value=0)):m.value>s?(m.value=withSpring(s,SPRING_CONFIG),void(h.value=s)):void(h.value=m.value)}}),[i,m,h,d,g,p,b,o,s]),y=usePinchGesture(x),I=useMemo(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";p.value=d.value,b.value=g.value},onUpdate:e=>{"worklet";m.value<=1||(d.value=p.value+e.translationX,g.value=b.value+e.translationY)},onDeactivate:()=>{"worklet";p.value=d.value,b.value=g.value}}),[m,d,g,p,b]),w=usePanGesture(I),C=useMemo(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";runOnJS(v)(),m.value>1?(m.value=withSpring(1,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=1,p.value=0,b.value=0):(m.value=withSpring(n,SPRING_CONFIG),h.value=n)}}),[m,h,d,g,p,b,v,n]),_=useTapGesture(C),f=useCompetingGestures(y,w,_),G=useAnimatedStyle(()=>({transform:[{translateX:d.value},{translateY:g.value},{scale:m.value}]}),[d,g,m]);React.useEffect(()=>{l||S()},[l,S]);const j=e.alt??u(t+1,a);return _jsx(GestureDetector,{gesture:f,children:_jsx(Animated.View,{style:[lightboxImageStyles.container,{width:c.width}],children:_jsx(Animated.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,G],accessibilityLabel:j,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,...smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"],lineHeight:21}}),lightboxImageStyles=StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});export{ImageGallery};export default ImageGallery;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18;export const DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`});const selectOptionLabel=e=>e.label,selectOptionValue=e=>e.value,selectOptionDescription=e=>e.description,selectOptionDisabled=e=>!0===e.disabled,selectOptionIcon=e=>e.icon,hostStyle=StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,value:b,onChange:g,multi:x=!1,searchable:y=!1,searchSelectionColor:f,accessibilityLabel:S,optionStyle:T,selectedOptionStyle:j,optionTextStyle:w,selectedOptionTextStyle:C,testID:_}=e,k=c??selectOptionLabel,L=d??selectOptionValue,I=p??selectOptionDescription,O=u??selectOptionDisabled,R=h??selectOptionIcon,V=useTheme(),D=useSafeAreaInsets(),v=useMemo(()=>buildStyles(V),[V]),[P,H]=useState(""),M=Dimensions.get("window").height,B=Math.round(.7*M),A=useRef(createAnimatedValue(0)).current,{handleGesture:E,opacity:F}=useDragToDismiss({drag:A,travel:B,onDismiss:t}),z=useMemo(()=>Gesture.Native(),[]),W=useKeyboardState(e=>e.height),N=Math.max(0,Math.round(W)),G=Math.max(D.top,StatusBar.currentHeight??0)+V.space.sm,U=N>0,$=U?Math.max(0,Math.min(B,M-N-G)):B,J=useMemo(()=>{const e=y?P.trim().toLowerCase():"",matches=t=>0===e.length||k(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:o})}}),t},[y,P,s,i,k,I]),K=useCallback(()=>{t()},[t]),Y=useRef(null),Z=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of J.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of J.entries()){if(o<t||"option"!==s.kind)continue;const i=k(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,J,i,k]),Q=n&&Z.size>0&&0===P.trim().length,X=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Z.has("#")?["#"]:[]],[Z]),q=useCallback(e=>{const t=Z.get(e);void 0!==t&&Y.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Z]),ee=useRef(null),te=useCallback(()=>{null!==ee.current&&(clearTimeout(ee.current),ee.current=null)},[]),oe=useCallback(e=>{Y.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),te(),ee.current=setTimeout(()=>{ee.current=null,Y.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[te]);useEffect(()=>te,[te]);return _jsx(GestureHandlerRootView,{style:v.gestureRoot,children:_jsxs(Animated.View,{testID:_,accessibilityViewIsModal:!0,accessibilityLabel:S??o??a.fallbackName,style:[v.sheet,{maxHeight:$,marginBottom:N,paddingBottom:U?V.space.lg:D.bottom+V.space.lg,backgroundColor:V.colors.surface,borderTopLeftRadius:V.radius.xl,borderTopRightRadius:V.radius.xl,...smoothCorners,opacity:F,transform:[{translateY:A}],...V.shadow.modal}],children:[_jsx(GestureDetector,{gesture:E,children:_jsxs(View,{children:[_jsx(View,{style:v.sheetHandleRow,children:_jsx(View,{style:[v.sheetHandle,{backgroundColor:V.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[v.sheetTitle,{paddingHorizontal:V.space.lg,marginBottom:V.space.sm}],children:o}):null]})}),y?_jsx(View,{style:[v.searchWrap,{marginHorizontal:V.space.lg,marginBottom:V.space.sm}],children:_jsxs(View,{style:[v.searchBox,{backgroundColor:V.colors["bg-subtle"],borderColor:V.colors.border,borderRadius:V.radius.md,...smoothCorners,paddingHorizontal:V.space.md,gap:V.space.sm}],children:[(V.settings.icons.search??defaultIcons.search)({size:18,color:V.colors["text-subtle"]}),_jsx(TextInput,{value:P,onChangeText:H,placeholder:a.searchPlaceholder,placeholderTextColor:V.colors["text-subtle"],selectionColor:f??V.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[v.searchInput,{color:V.colors["text-body"],fontSize:V.text.base.size,paddingVertical:V.space.sm}]}),P.length>0?_jsx(Pressable,{onPress:()=>H(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(V.settings.icons.close??defaultIcons.close)({size:18,color:V.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[v.listWrap,Q?v.listRow:null],children:[_jsx(GestureDetector,{gesture:z,children:_jsx(FlatList,{ref:Y,data:J,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(L(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[v.sectionHeader,{paddingHorizontal:V.space.lg,paddingTop:V.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:v.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=k(o),i=L(o),n=I(o),a=R(o),c=(d=i,Array.isArray(b)?b.some(e=>String(e)===String(d)):null!=b&&String(b)===String(d));var d;const p=O(o),u=m?.(o)??!1;return _jsxs(Pressable,{onPress:()=>g(i,o),disabled:p,android_ripple:{color:V.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[v.optionRow,{backgroundColor:c?V.colors["surface-selected"]:e?V.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:V.space.lg,paddingVertical:V.space.md},T,c?j:null],children:[l?_jsx(View,{style:v.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[a?_jsx(View,{style:v.optionIcon,children:a}):null,_jsxs(View,{style:v.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[v.optionLabel,w,c?C:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:v.optionDescription,children:n}):null]})]}),x?_jsx(View,{style:[v.checkbox,{borderColor:c?V.colors.primary:V.colors.border,backgroundColor:c?V.colors.primary:"transparent"}],children:c?_jsx(View,{style:v.checkboxTick}):null}):c?"icon"===V.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:v.singleSelectedIcon,children:(V.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:V.colors.primary})}):_jsx(View,{style:[v.singleSelectedDot,{backgroundColor:V.colors.primary}]}):null]})},onScrollToIndexFailed:oe,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!Q,style:Q?v.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:V.space.xl},children:a.empty})})}),Q?_jsx(View,{style:[v.rail,{paddingRight:V.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:X.map(e=>{const t=Z.has(e);return _jsx(Pressable,{onPress:()=>q(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:a.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:v.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[v.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),x?_jsx(View,{style:[v.sheetFooter,{borderTopColor:V.colors["border-subtle"],paddingHorizontal:V.space.lg,paddingVertical:V.space.md}],children:_jsx(Pressable,{onPress:K,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[v.doneButton,{backgroundColor:e?V.colors["primary-pressed"]:V.colors.primary,borderRadius:V.radius.md,...smoothCorners,paddingVertical:V.space.sm,paddingHorizontal:V.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:V.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMemo(()=>({...DEFAULT_OPTION_SHEET_LABELS,...i}),[i]),c=useRef(o);c.current=o;const d=useRef(!1);return useEffect(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:a.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??a.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:a})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:14},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18;export const DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`});const selectOptionLabel=e=>e.label,selectOptionValue=e=>e.value,selectOptionDescription=e=>e.description,selectOptionDisabled=e=>!0===e.disabled,selectOptionIcon=e=>e.icon,hostStyle=StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,value:b,onChange:g,multi:x=!1,searchable:y=!1,searchSelectionColor:f,accessibilityLabel:S,optionStyle:T,selectedOptionStyle:j,optionTextStyle:w,selectedOptionTextStyle:C,testID:_}=e,k=c??selectOptionLabel,L=d??selectOptionValue,I=p??selectOptionDescription,O=u??selectOptionDisabled,R=h??selectOptionIcon,V=useTheme(),D=useSafeAreaInsets(),v=useMemo(()=>buildStyles(V),[V]),[P,H]=useState(""),M=Dimensions.get("window").height,B=Math.round(.7*M),A=useRef(createAnimatedValue(0)).current,{handleGesture:E,opacity:F}=useDragToDismiss({drag:A,travel:B,onDismiss:t}),z=useNativeGesture(),W=useKeyboardState(e=>e.height),N=Math.max(0,Math.round(W)),G=Math.max(D.top,StatusBar.currentHeight??0)+V.space.sm,U=N>0,$=U?Math.max(0,Math.min(B,M-N-G)):B,J=useMemo(()=>{const e=y?P.trim().toLowerCase():"",matches=t=>0===e.length||k(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:o})}}),t},[y,P,s,i,k,I]),K=useCallback(()=>{t()},[t]),Y=useRef(null),Z=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of J.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of J.entries()){if(o<t||"option"!==s.kind)continue;const i=k(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,J,i,k]),Q=n&&Z.size>0&&0===P.trim().length,X=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Z.has("#")?["#"]:[]],[Z]),q=useCallback(e=>{const t=Z.get(e);void 0!==t&&Y.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Z]),ee=useRef(null),te=useCallback(()=>{null!==ee.current&&(clearTimeout(ee.current),ee.current=null)},[]),oe=useCallback(e=>{Y.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),te(),ee.current=setTimeout(()=>{ee.current=null,Y.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[te]);useEffect(()=>te,[te]);return _jsx(GestureHandlerRootView,{style:v.gestureRoot,children:_jsxs(Animated.View,{testID:_,accessibilityViewIsModal:!0,accessibilityLabel:S??o??a.fallbackName,style:[v.sheet,{maxHeight:$,marginBottom:N,paddingBottom:U?V.space.lg:D.bottom+V.space.lg,backgroundColor:V.colors.surface,borderTopLeftRadius:V.radius.xl,borderTopRightRadius:V.radius.xl,...smoothCorners,opacity:F,transform:[{translateY:A}],...V.shadow.modal}],children:[_jsx(GestureDetector,{gesture:E,children:_jsxs(View,{children:[_jsx(View,{style:v.sheetHandleRow,children:_jsx(View,{style:[v.sheetHandle,{backgroundColor:V.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[v.sheetTitle,{paddingHorizontal:V.space.lg,marginBottom:V.space.sm}],children:o}):null]})}),y?_jsx(View,{style:[v.searchWrap,{marginHorizontal:V.space.lg,marginBottom:V.space.sm}],children:_jsxs(View,{style:[v.searchBox,{backgroundColor:V.colors["bg-subtle"],borderColor:V.colors.border,borderRadius:V.radius.md,...smoothCorners,paddingHorizontal:V.space.md,gap:V.space.sm}],children:[(V.settings.icons.search??defaultIcons.search)({size:18,color:V.colors["text-subtle"]}),_jsx(TextInput,{value:P,onChangeText:H,placeholder:a.searchPlaceholder,placeholderTextColor:V.colors["text-subtle"],selectionColor:f??V.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[v.searchInput,{color:V.colors["text-body"],fontSize:V.text.base.size,paddingVertical:V.space.sm}]}),P.length>0?_jsx(Pressable,{onPress:()=>H(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(V.settings.icons.close??defaultIcons.close)({size:18,color:V.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[v.listWrap,Q?v.listRow:null],children:[_jsx(GestureDetector,{gesture:z,children:_jsx(FlatList,{ref:Y,data:J,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(L(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[v.sectionHeader,{paddingHorizontal:V.space.lg,paddingTop:V.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:v.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=k(o),i=L(o),n=I(o),a=R(o),c=(d=i,Array.isArray(b)?b.some(e=>String(e)===String(d)):null!=b&&String(b)===String(d));var d;const p=O(o),u=m?.(o)??!1;return _jsxs(Pressable,{onPress:()=>g(i,o),disabled:p,android_ripple:{color:V.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[v.optionRow,{backgroundColor:c?V.colors["surface-selected"]:e?V.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:V.space.lg,paddingVertical:V.space.md},T,c?j:null],children:[l?_jsx(View,{style:v.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[a?_jsx(View,{style:v.optionIcon,children:a}):null,_jsxs(View,{style:v.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[v.optionLabel,w,c?C:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:v.optionDescription,children:n}):null]})]}),x?_jsx(View,{style:[v.checkbox,{borderColor:c?V.colors.primary:V.colors.border,backgroundColor:c?V.colors.primary:"transparent"}],children:c?_jsx(View,{style:v.checkboxTick}):null}):c?"icon"===V.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:v.singleSelectedIcon,children:(V.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:V.colors.primary})}):_jsx(View,{style:[v.singleSelectedDot,{backgroundColor:V.colors.primary}]}):null]})},onScrollToIndexFailed:oe,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!Q,style:Q?v.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:V.space.xl},children:a.empty})})}),Q?_jsx(View,{style:[v.rail,{paddingRight:V.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:X.map(e=>{const t=Z.has(e);return _jsx(Pressable,{onPress:()=>q(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:a.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:v.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[v.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),x?_jsx(View,{style:[v.sheetFooter,{borderTopColor:V.colors["border-subtle"],paddingHorizontal:V.space.lg,paddingVertical:V.space.md}],children:_jsx(Pressable,{onPress:K,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[v.doneButton,{backgroundColor:e?V.colors["primary-pressed"]:V.colors.primary,borderRadius:V.radius.md,...smoothCorners,paddingVertical:V.space.sm,paddingHorizontal:V.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:V.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMemo(()=>({...DEFAULT_OPTION_SHEET_LABELS,...i}),[i]),c=useRef(o);c.current=o;const d=useRef(!1);return useEffect(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:a.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??a.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:a})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:14},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
@@ -1 +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: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=>{writePng(n).then(e,t)},{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
+ "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{GestureDetector,GestureHandlerRootView,useCompetingGestures,usePanGesture}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:s})=>"draw"===e?_jsx(_Fragment,{children:t.map(e=>_jsx(StrokePath,{points:e.points,color:a},e.id))}):n?_jsx(SvgText,{x:o/2,y:s*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:s,defaultMode:i="draw",onModeChange:l,onEmptyChange:d,allowTyped:u=!0,signedBy:c,signedAt:p,height:m=DEFAULT_HEIGHT,maxNameLength:h=DEFAULT_NAME_LENGTH,inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x="selection",disabled:w=!1,style:T,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(u?i:"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:s,onModeChange:l,onEmptyChange:d});useEffect(()=>{te.current={onChange:r,onTypedNameChange:s,onModeChange:l,onEmptyChange:d}});const ne="draw"===Y&&!w,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)},[]),se=useCallback(()=>{K(Date.now()),te.current.onChange?.(B.current.map(e=>e.points))},[]),ie=useMemo(()=>{const pan=e=>({enabled:ne,runOnJS:!0,onBegin:e=>{H.current=pointOf(e.x,e.y)},onActivate: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,se())}});return{sidewaysConfig:{...pan("sideways"),activeOffsetX:[-6,6],failOffsetY:[-8,8]},restedConfig:{...pan("rested"),activateAfterLongPress:200}}},[ne,oe,se]),le=usePanGesture(ie.sidewaysConfig),de=usePanGesture(ie.restedConfig),ue=useCompetingGestures(le,de),ce=useCallback(e=>{$(e),te.current.onModeChange?.(e),announce("type"===e?P.typingAnnouncement:P.drawingAnnouncement)},[P.typingAnnouncement,P.drawingAnnouncement]);useEffect(()=>{D&&u&&!X.current&&"draw"===Y&&0===B.current.length&&ce("type")},[D,u,Y,ce]);const pe=useCallback(()=>{X.current=!0,ce("draw"===Y?"type":"draw")},[Y,ce]),me=useCallback(e=>{U(e),K(Date.now()),te.current.onTypedNameChange?.(e)},[]),he=useCallback(()=>{"type"===Y?me(""):(oe([]),se()),announce(P.clearedAnnouncement)},[Y,me,oe,se,P.clearedAnnouncement]),ge=useCallback(()=>{"draw"===Y&&0!==B.current.length&&(oe(B.current.slice(0,-1)),se(),announce(P.undoneAnnouncement))},[Y,oe,se,P.undoneAnnouncement]),ye=useCallback(()=>{ee(B.current.map(e=>e.points)),Q(!0)},[]),fe=useCallback(()=>{Q(!1)},[]),Se=useCallback(()=>{oe(Z.map(e=>(O.current+=1,{id:O.current,points:[...e]}))),se(),Q(!1)},[Z,oe,se]),xe=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=>{writePng(n).then(e,t)},{width:xe*a,height:m*a})}),toSvg:()=>buildSignatureSvg({width:xe,height:m,mode:Y,strokes:G.map(e=>e.points),typedName:z,ink:v,paper:R,strokeWidth:2.5,fontFamily:cssFontStack(j)}),clear:he,undo:ge,isEmpty:()=>ae}),[ae,P.emptyError,xe,m,Y,G,z,I,v,R,j,he,ge]);const we=useMemo(()=>[{name:"undo",label:P.undo},{name:"clear",label:P.clear},...u?[{name:"toggleMode",label:"draw"===Y?P.typeInstead:P.drawInstead}]:[]],[P.undo,P.clear,P.typeInstead,P.drawInstead,u,Y]),Te=useCallback(e=>{if(w)return;const{actionName:t}=e.nativeEvent;"undo"===t?ge():"clear"===t?he():"toggleMode"===t&&u&&pe()},[w,ge,he,pe,u]),be=useCallback(e=>{M(e.nativeEvent.layout.width)},[]),Ee=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:w?.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,w]),Ae=z.trim(),Ce=p??W,ve=c&&!ae?`Signed by ${c}${Ce?`, ${formatDateTime(Ce)}`:""}`:null,Re="type"===Y&&Ae?`${P.pad}. ${Ae}`:P.pad;return _jsxs(View,{style:[Ee.root,T],testID:b,children:[_jsx(GestureDetector,{gesture:ue,children:_jsxs(View,{style:Ee.pad,onLayout:be,accessible:!0,accessibilityRole:"image",accessibilityLabel:Re,accessibilityHint:"draw"===Y?P.padHint:void 0,accessibilityValue:{text:ae?P.empty:P.signed},accessibilityState:{disabled:w},"aria-disabled":w,accessibilityActions:we,onAccessibilityAction:Te,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:Ae,color:v,fontFamily:j,width:xe,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:Ae,color:A,fontFamily:j,width:xe,height:m})]}),_jsx(View,{pointerEvents:"none",style:Ee.baseline})]})}),"type"===Y?_jsx(Input,{label:P.typedLabel,placeholder:P.typedPlaceholder,value:z,onChangeText:me,maxLength:h,disabled:w,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:Ee.actions,children:[u?_jsx(Button,{label:"draw"===Y?P.typeInstead:P.drawInstead,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:w,onPress:pe,testID:b?`${b}-mode`:void 0}):_jsx(View,{}),"draw"===Y?_jsxs(View,{style:Ee.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:w,onPress:ge,testID:b?`${b}-undo`:void 0}),_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:w,onPress:he,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:w,onPress:ye,testID:b?`${b}-expand`:void 0}):null]}):null,"type"===Y&&Ae?_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:w,onPress:he,testID:b?`${b}-clear`:void 0}):null]}),ve?_jsx(Text,{variant:"caption",color:"secondary",children:ve}):null,n?_jsx(Modal,{visible:J,animationType:"slide",presentationStyle:"fullScreen",onRequestClose:fe,children:_jsxs(ExpandedRoot,{style:Ee.expandedRoot,children:[_jsxs(View,{style:Ee.expandedBar,children:[_jsx(Button,{label:P.close,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:fe,testID:b?`${b}-close`:void 0}),_jsx(Button,{label:P.done,variant:"solid",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:Se,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;