@webority/mobile-ui 0.161.0 → 0.164.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.
- package/android/src/newarch/java/com/webority/mobileui/pdfrasterizer/PdfRasterizerModule.kt +4 -4
- package/dist/canvas-kit/kit.js +7 -7
- package/dist/canvas-kit/manifest.json +6 -1
- package/dist/canvas-kit/release.json +6 -6
- package/ios/PdfRasterizer.mm +3 -3
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/Confetti/Confetti.js +1 -1
- package/lib/commonjs/components/Drawer/Drawer.js +1 -1
- package/lib/commonjs/components/FileViewer/useFileViewerZoom.js +1 -1
- package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
- package/lib/commonjs/components/NonModalBottomSheet/NonModalBottomSheet.js +1 -1
- package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/commonjs/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/commonjs/components/Slider/Slider.js +1 -1
- package/lib/commonjs/components/SortableList/SortableList.js +1 -1
- package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
- package/lib/commonjs/components/TagInput/TagInput.js +1 -1
- package/lib/commonjs/components/ZoomableImage/ZoomableImage.js +1 -1
- package/lib/commonjs/utils/warnUnknownProps.js +1 -1
- package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/module/components/Confetti/Confetti.js +1 -1
- package/lib/module/components/Drawer/Drawer.js +1 -1
- package/lib/module/components/FileViewer/useFileViewerZoom.js +1 -1
- package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
- package/lib/module/components/NonModalBottomSheet/NonModalBottomSheet.js +1 -1
- package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/module/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/module/components/Slider/Slider.js +1 -1
- package/lib/module/components/SortableList/SortableList.js +1 -1
- package/lib/module/components/Swipeable/Swipeable.js +1 -1
- package/lib/module/components/TagInput/TagInput.js +1 -1
- package/lib/module/components/ZoomableImage/ZoomableImage.js +1 -1
- package/lib/module/utils/warnUnknownProps.js +1 -1
- package/lib/typescript/commonjs/components/Autocomplete/Autocomplete.d.ts +1 -1
- package/lib/typescript/commonjs/components/Avatar/Avatar.d.ts +1 -1
- package/lib/typescript/commonjs/components/BottomSheet/BottomSheet.d.ts +4 -4
- package/lib/typescript/commonjs/components/Carousel/Carousel.d.ts +1 -1
- package/lib/typescript/commonjs/components/ChoiceGroup/ChoiceGroup.d.ts +4 -4
- package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +1 -1
- package/lib/typescript/commonjs/components/Descriptions/Descriptions.d.ts +2 -2
- package/lib/typescript/commonjs/components/Drawer/Drawer.d.ts +1 -1
- package/lib/typescript/commonjs/components/FieldBase/Chevron.d.ts +1 -1
- package/lib/typescript/commonjs/components/FieldBase/FieldBase.d.ts +13 -13
- package/lib/typescript/commonjs/components/FilePicker/FilePicker.d.ts +10 -10
- package/lib/typescript/commonjs/components/ForceUpdateDialog/ForceUpdateDialog.d.ts +2 -2
- package/lib/typescript/commonjs/components/FormField/FormField.d.ts +1 -1
- package/lib/typescript/commonjs/components/IconButton/IconButton.d.ts +2 -2
- package/lib/typescript/commonjs/components/ImageGallery/ImageGallery.d.ts +1 -1
- package/lib/typescript/commonjs/components/InlineSelect/InlineSelect.d.ts +7 -7
- package/lib/typescript/commonjs/components/Input/Input.d.ts +2 -2
- package/lib/typescript/commonjs/components/Modal/Modal.d.ts +1 -1
- package/lib/typescript/commonjs/components/OptionSheet/OptionSheet.d.ts +4 -4
- package/lib/typescript/commonjs/components/PhoneNumberInput/PhoneNumberInput.d.ts +1 -1
- package/lib/typescript/commonjs/components/PickerTrigger/PickerTrigger.d.ts +4 -4
- package/lib/typescript/commonjs/components/ProfilePicker/ProfilePicker.d.ts +1 -1
- package/lib/typescript/commonjs/components/ProgressBar/ProgressBar.d.ts +1 -1
- package/lib/typescript/commonjs/components/Radio/RadioDot.d.ts +2 -2
- package/lib/typescript/commonjs/components/Repeater/Repeater.d.ts +2 -2
- package/lib/typescript/commonjs/components/RichTextEditor/markdownActions.d.ts +3 -3
- package/lib/typescript/commonjs/components/SearchBar/SearchBar.d.ts +1 -1
- package/lib/typescript/commonjs/components/SegmentedControl/SegmentedControl.d.ts +1 -1
- package/lib/typescript/commonjs/components/Select/Select.d.ts +6 -6
- package/lib/typescript/commonjs/components/Skeleton/Skeleton.d.ts +3 -3
- package/lib/typescript/commonjs/components/Skeleton/SkeletonClock.d.ts +3 -3
- package/lib/typescript/commonjs/components/Skeleton/SkeletonContent.d.ts +6 -6
- package/lib/typescript/commonjs/components/Skeleton/SkeletonList.d.ts +2 -2
- package/lib/typescript/commonjs/components/Skeleton/SkeletonProvider.d.ts +5 -5
- package/lib/typescript/commonjs/components/Skeleton/SkeletonSkip.d.ts +2 -2
- package/lib/typescript/commonjs/components/SlideToConfirm/SlideToConfirm.d.ts +1 -1
- package/lib/typescript/commonjs/components/Tabs/Tabs.d.ts +2 -2
- package/lib/typescript/commonjs/components/TagInput/TagInput.d.ts +1 -1
- package/lib/typescript/commonjs/components/Timeline/Timeline.d.ts +8 -8
- package/lib/typescript/commonjs/components/ZoomableImage/ZoomableImage.d.ts +4 -4
- package/lib/typescript/commonjs/specs/NativePdfRasterizer.d.ts +4 -4
- package/lib/typescript/commonjs/theme/animatedValue.d.ts +4 -4
- package/lib/typescript/commonjs/utils/feedback.d.ts +3 -3
- package/lib/typescript/commonjs/utils/warnUnknownProps.d.ts +2 -2
- package/lib/typescript/module/components/Autocomplete/Autocomplete.d.ts +1 -1
- package/lib/typescript/module/components/Avatar/Avatar.d.ts +1 -1
- package/lib/typescript/module/components/BottomSheet/BottomSheet.d.ts +4 -4
- package/lib/typescript/module/components/Carousel/Carousel.d.ts +1 -1
- package/lib/typescript/module/components/ChoiceGroup/ChoiceGroup.d.ts +4 -4
- package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +1 -1
- package/lib/typescript/module/components/Descriptions/Descriptions.d.ts +2 -2
- package/lib/typescript/module/components/Drawer/Drawer.d.ts +1 -1
- package/lib/typescript/module/components/FieldBase/Chevron.d.ts +1 -1
- package/lib/typescript/module/components/FieldBase/FieldBase.d.ts +13 -13
- package/lib/typescript/module/components/FilePicker/FilePicker.d.ts +10 -10
- package/lib/typescript/module/components/ForceUpdateDialog/ForceUpdateDialog.d.ts +2 -2
- package/lib/typescript/module/components/FormField/FormField.d.ts +1 -1
- package/lib/typescript/module/components/IconButton/IconButton.d.ts +2 -2
- package/lib/typescript/module/components/ImageGallery/ImageGallery.d.ts +1 -1
- package/lib/typescript/module/components/InlineSelect/InlineSelect.d.ts +7 -7
- package/lib/typescript/module/components/Input/Input.d.ts +2 -2
- package/lib/typescript/module/components/Modal/Modal.d.ts +1 -1
- package/lib/typescript/module/components/OptionSheet/OptionSheet.d.ts +4 -4
- package/lib/typescript/module/components/PhoneNumberInput/PhoneNumberInput.d.ts +1 -1
- package/lib/typescript/module/components/PickerTrigger/PickerTrigger.d.ts +4 -4
- package/lib/typescript/module/components/ProfilePicker/ProfilePicker.d.ts +1 -1
- package/lib/typescript/module/components/ProgressBar/ProgressBar.d.ts +1 -1
- package/lib/typescript/module/components/Radio/RadioDot.d.ts +2 -2
- package/lib/typescript/module/components/Repeater/Repeater.d.ts +2 -2
- package/lib/typescript/module/components/RichTextEditor/markdownActions.d.ts +3 -3
- package/lib/typescript/module/components/SearchBar/SearchBar.d.ts +1 -1
- package/lib/typescript/module/components/SegmentedControl/SegmentedControl.d.ts +1 -1
- package/lib/typescript/module/components/Select/Select.d.ts +6 -6
- package/lib/typescript/module/components/Skeleton/Skeleton.d.ts +3 -3
- package/lib/typescript/module/components/Skeleton/SkeletonClock.d.ts +3 -3
- package/lib/typescript/module/components/Skeleton/SkeletonContent.d.ts +6 -6
- package/lib/typescript/module/components/Skeleton/SkeletonList.d.ts +2 -2
- package/lib/typescript/module/components/Skeleton/SkeletonProvider.d.ts +5 -5
- package/lib/typescript/module/components/Skeleton/SkeletonSkip.d.ts +2 -2
- package/lib/typescript/module/components/SlideToConfirm/SlideToConfirm.d.ts +1 -1
- package/lib/typescript/module/components/Tabs/Tabs.d.ts +2 -2
- package/lib/typescript/module/components/TagInput/TagInput.d.ts +1 -1
- package/lib/typescript/module/components/Timeline/Timeline.d.ts +8 -8
- package/lib/typescript/module/components/ZoomableImage/ZoomableImage.d.ts +4 -4
- package/lib/typescript/module/specs/NativePdfRasterizer.d.ts +4 -4
- package/lib/typescript/module/theme/animatedValue.d.ts +4 -4
- package/lib/typescript/module/utils/feedback.d.ts +3 -3
- package/lib/typescript/module/utils/warnUnknownProps.d.ts +2 -2
- package/package.json +7 -7
- package/src/specs/NativePdfRasterizer.ts +4 -4
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"kind": "WeborityPhone",
|
|
3
3
|
"library": {
|
|
4
4
|
"name": "@webority/mobile-ui",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.164.0"
|
|
6
6
|
},
|
|
7
7
|
"rendererProtocolVersion": 14,
|
|
8
8
|
"platform": "Phone",
|
|
@@ -23006,6 +23006,11 @@
|
|
|
23006
23006
|
"version": "0.160.0",
|
|
23007
23007
|
"components": [],
|
|
23008
23008
|
"values": {}
|
|
23009
|
+
},
|
|
23010
|
+
{
|
|
23011
|
+
"version": "0.164.0",
|
|
23012
|
+
"components": [],
|
|
23013
|
+
"values": {}
|
|
23009
23014
|
}
|
|
23010
23015
|
]
|
|
23011
23016
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webority-phone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.164.0",
|
|
4
4
|
"platform": "Phone",
|
|
5
5
|
"kitModuleVersion": 2,
|
|
6
6
|
"rendererProtocolVersion": 14,
|
|
7
7
|
"library": {
|
|
8
8
|
"name": "@webority/mobile-ui",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.164.0"
|
|
10
10
|
},
|
|
11
11
|
"files": {
|
|
12
12
|
"manifest.json": {
|
|
13
|
-
"sha256": "
|
|
14
|
-
"bytes":
|
|
13
|
+
"sha256": "a39d25029c533f90179a3c5d1f5bc74d6177011aa51eef88df9d564fc6dc8ab2",
|
|
14
|
+
"bytes": 668584
|
|
15
15
|
},
|
|
16
16
|
"kit.js": {
|
|
17
|
-
"sha256": "
|
|
18
|
-
"bytes":
|
|
17
|
+
"sha256": "289e5366486a32390ee180e3ba4e57c02374d2c04431d4babbf82bd52713abca",
|
|
18
|
+
"bytes": 5663399
|
|
19
19
|
},
|
|
20
20
|
"kit.css": {
|
|
21
21
|
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
package/ios/PdfRasterizer.mm
CHANGED
|
@@ -8,7 +8,7 @@ static NSString *const kCacheDirName = @"pdf-rasterizer-cache";
|
|
|
8
8
|
// Both render sides stay within this, scaled together so the aspect ratio holds.
|
|
9
9
|
static const CGFloat kMaxRenderDimensionPx = 4096;
|
|
10
10
|
|
|
11
|
-
// Wraps a CGPDFDocumentRef so ARC can own its lifetime inside an NSMutableDictionary
|
|
11
|
+
// Wraps a CGPDFDocumentRef so ARC can own its lifetime inside an NSMutableDictionary.
|
|
12
12
|
// CGPDFDocumentRef is a plain CF type with no toll-free-bridged Foundation counterpart.
|
|
13
13
|
@interface PdfRasterizerDocumentBox : NSObject
|
|
14
14
|
@property (nonatomic, assign, readonly) CGPDFDocumentRef document;
|
|
@@ -126,7 +126,7 @@ static CGAffineTransform PdfRasterizerFillTransform(CGPDFPageRef page, CGSize ta
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
if (CGPDFDocumentIsEncrypted(document)) {
|
|
129
|
-
// Only ever try the empty password
|
|
129
|
+
// Only ever try the empty password. A real password prompt is a UI
|
|
130
130
|
// concern the caller owns, not this module's job to solve.
|
|
131
131
|
CGPDFDocumentUnlockWithPassword(document, "");
|
|
132
132
|
if (!CGPDFDocumentIsUnlocked(document)) {
|
|
@@ -302,7 +302,7 @@ static CGAffineTransform PdfRasterizerFillTransform(CGPDFPageRef page, CGSize ta
|
|
|
302
302
|
[self.documents removeObjectForKey:handle];
|
|
303
303
|
|
|
304
304
|
NSString *cacheDir = [self cacheDirectoryForHandle:handle];
|
|
305
|
-
// Best-effort cleanup
|
|
305
|
+
// Best-effort cleanup: a stale cache dir on delete failure is not worth
|
|
306
306
|
// failing an otherwise-successful close over.
|
|
307
307
|
[[NSFileManager defaultManager] removeItemAtPath:cacheDir error:nil];
|
|
308
308
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useBottomSheet=exports.default=exports.DEFAULT_BOTTOM_SHEET_LABELS=exports.BottomSheet=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_OverlayActions=require("../Dialog/OverlayActions.js"),_Modal=require("../Modal/Modal.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,n=Object.defineProperty,o={__proto__:null,default:e};if(Object(e)!==e)return o;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,o)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=n&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?n(o,r,a):o[r]=e[r]);return o}const DEFAULT_BOTTOM_SHEET_LABELS=exports.DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"}),DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=(0,_react.createContext)(null),useBottomSheet=()=>{const e=(0,_react.useContext)(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};exports.useBottomSheet=useBottomSheet;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:a,onClose:r,snapIndex:n,onSnapChange:o,onAnimate:s,onAfterClose:i,enablePanDownToClose:c=!0,enableBackdropPress:l=!0,onBeforeClose:u,title:d,labels:_,scrollable:h=!1,scrollRef:m,onScroll:v,onContentSizeChange:f,onScrollLayout:S,scrollEventThrottle:b,keyboardBehavior:p="shift",inline:x=!1,presentation:R="sheet",animateMount:y=!0,handleIndicatorStyle:N,containerStyle:g,header:M,actions:j,actionsLayout:C="auto",footer:w,headerStyle:O,footerStyle:E,children:k,accessibilityLabel:T,accessibilityViewIsModal:A,testID:B}=e;(0,_assertValidValue.assertValidValue)("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),(0,_assertValidValue.assertValidValue)("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),(0,_assertValidValue.assertValidValue)("BottomSheet","actionsLayout",e.actionsLayout,_OverlayActions.ACTIONS_LAYOUTS);const V=(0,_react.useMemo)(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,..._}),[_]),I=null!=M||null!=d,D=null!=j&&j.length>0,L=null!=w||D,P=x?"inline":"modal",H=(0,_index.useTheme)(),G=(0,_usePresenceMotion.usePresenceMotion)(),q=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),[F,U]=(0,_react.useState)(()=>_reactNative.Dimensions.get("window").height),[J,z]=(0,_react.useState)(()=>_reactNative.Dimensions.get("window").width),W=(0,_react.useCallback)(e=>{const{height:t,width:a}=e.nativeEvent.layout;t>0&&U(e=>e===t?e:t),a>0&&z(e=>e===a?e:a)},[]),Y=(0,_reactNative.useWindowDimensions)(),K="dialog"===R||"auto"===R&&Math.min(Y.width,Y.height)>=600,$=Math.min(560,J-2*H.space.xl),[X,Q]=(0,_ModalSafeArea.useModalInsets)(),Z="modal"===P?X.top:q.top,ee="modal"===P?X.bottom:q.bottom,te=t.includes("content"),[ae,re]=useMeasuredHeight(),[ne,oe]=useMeasuredHeight(),[se,ie,ce]=useMeasuredHeight(),[le,ue]=useMeasuredHeight(),de=K?H.space.md:ae,he=te?Math.min(de+(I?ne:0)+se+(L?le:0)+ee,F-Z):0,me=(0,_react.useCallback)((e,t)=>{te&&ce(t),f?.(e,t)},[te,f,ce]),ve=(0,_react.useMemo)(()=>resolveSnapPoints(t,F,he),[t,F,he]),fe=F,Se=ve[ve.length-1]??0,be=(0,_reactNativeReanimated.useSharedValue)(fe),pe=(0,_reactNativeReanimated.useSharedValue)(fe),xe=(0,_reactNativeReanimated.useSharedValue)(1),Re=(0,_reactNativeReanimated.useSharedValue)(-1),[ye,Ne]=(0,_react.useState)(-1),ge=(0,_react.useRef)(!1),[Me,je]=(0,_react.useState)(!1),[Ce,we]=(0,_react.useState)(!1),Oe=(0,_react.useRef)(!1),Ee=(0,_react.useRef)(i);Ee.current=i;const[ke,Te]=(0,_react.useState)(!1),Ae=(0,_react.useRef)(!y&&a),Be=(0,_react.useRef)(-1),Ve=(0,_react.useRef)(!1);Ve.current="modal"===P?Ce:ke;const Ie=(0,_react.useRef)(u);Ie.current=u;const De=(0,_react.useRef)(r);De.current=r;const Le=(0,_react.useRef)(!1),Pe=(0,_react.useRef)(!0),He=(0,_react.useRef)([]),Ge=(0,_react.useCallback)(e=>{const t=He.current;He.current=[];for(const a of t)a(e)},[]);(0,_react.useEffect)(()=>(Pe.current=!0,()=>{Pe.current=!1,Ge(!1)}),[Ge]);const qe=(0,_react.useCallback)(e=>{if(e<0||e>=ve.length)return fe;const t=ve[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return K?(F-t)/2:F-t},[ve,F,fe,K]),Fe=(0,_react.useCallback)(e=>{Be.current=e;ye!==e&&(Ne(e),Re.value=e,e>=0&&o?.(e))},[ye,Re,o]),Ue=(0,_react.useCallback)(()=>{ge.current=!1,Re.value<0&&(Oe.current=!0,"modal"===P?(je(!1),"ios"!==_reactNative.Platform.OS&&we(!1)):Te(!1))},[P,Re]),Je=(0,_react.useCallback)(()=>{Oe.current&&we(!1)},[]);(0,_react.useEffect)(()=>{("modal"===P?!Ce:!ke)&&Oe.current&&(Oe.current=!1,Ee.current?.(),Ge(!0))},[P,Ce,ke,Ge]);const ze=(0,_react.useCallback)((e,t,a)=>{ge.current=!0,s?.(t,a),be.value=(0,_reactNativeReanimated.withSpring)(e,SPRING_CONFIG,e=>{"worklet";e&&(0,_reactNativeReanimated.runOnJS)(Ue)()})},[s,be,Ue]),We=(0,_react.useCallback)(e=>{const t="number"==typeof e?clamp(e,0,ve.length-1):Math.max(ye,0),a=Re.value,r=qe(t);return Oe.current=!1,Ge(!1),"modal"===P?(we(!0),je(!0)):Te(!0),a<0&&Ae.current?(be.value=r,xe.value=1,Fe(t),void s?.(a,t)):a<0&&G.reduced?(be.value=r,xe.value=0,xe.value=(0,_reactNativeReanimated.withTiming)(1,{duration:G.duration("fast"),easing:_reactNativeReanimated.Easing.bezier(...H.motion.ease.decelerate),reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION}),Fe(t),void s?.(a,t)):(a<0&&(be.value=fe,xe.value=1),Fe(t),void ze(r,a,t))},[ze,fe,ye,Re,P,s,G,xe,ve.length,Fe,Ge,H.motion.ease.decelerate,be,qe]),Ye=(0,_react.useCallback)(()=>new Promise(e=>{if(Be.current<0)return void(Ve.current?He.current.push(e):e(!0));He.current.push(e),Ae.current=!1;const t=Re.value;Fe(-1),ge.current=!0,s?.(t,-1);const a=G.reduced?xe:be,r=G.reduced?0:fe;a.value=(0,_reactNativeReanimated.withTiming)(r,{duration:G.duration("fast"),easing:_reactNativeReanimated.Easing.bezier(...H.motion.ease.accelerate),reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(0,_reactNativeReanimated.runOnJS)(Ue)()})}),[fe,Re,Ue,s,G,xe,Fe,be,H.motion.ease.accelerate]),Ke=(0,_react.useCallback)((e,t,a)=>{const r=Ie.current;if(!r)return void e();if(Le.current)return void t?.();const n=r();"boolean"!=typeof n?(Le.current=!0,a?.(),n.then(a=>{Le.current=!1,a&&Pe.current&&Be.current>=0?e():t?.()},e=>{throw Le.current=!1,e})):(n?e:t)?.()},[]),$e=(0,_react.useCallback)(()=>new Promise(e=>{Be.current<0?e(!0):Ke(()=>{De.current(),Ye(),e(!0)},()=>e(!1))}),[Ye,Ke]),Xe=(0,_react.useCallback)(()=>{De.current()},[]),Qe=(0,_react.useCallback)(()=>{l&&$e()},[l,$e]),Ze=(0,_react.useRef)(null),et=(0,_react.useRef)(We);et.current=We;const tt=(0,_react.useRef)(Ye);tt.current=Ye,(0,_react.useEffect)(()=>{const e=Ze.current!==a;Ze.current=a,e?a?et.current(n??0):tt.current():a&&"number"==typeof n&&n!==Re.value&&et.current(n)},[a,n,Re]);const at=(0,_react.useRef)({hostHeight:F,contentSnap:he}),rt=(0,_react.useRef)(qe);rt.current=qe,(0,_react.useEffect)(()=>{const e=at.current;if(e.hostHeight===F&&e.contentSnap===he)return;if(at.current={hostHeight:F,contentSnap:he},e.hostHeight===F&&Re.value<0)return;const t=rt.current(Re.value);be.value=Ae.current?t:(0,_reactNativeReanimated.withSpring)(t,SPRING_CONFIG)},[F,he,Re,be]);const nt=F-Se,ot=(0,_react.useMemo)(()=>ve.map(e=>F-e),[ve,F]),st=(0,_react.useCallback)(()=>{const e=Be.current;e<0||ze(qe(e),e,e)},[ze,qe]),it=(0,_react.useCallback)((e,t)=>{const a=Re.value;-1!==e?(Fe(e),ze(t,a,e)):Ke(()=>{_reactNative.Keyboard.dismiss(),(0,_index2.triggerHaptic)("selection"),De.current(),Ye()},st,st)},[ze,Ye,Re,Ke,Fe,st]),ct=(0,_react.useMemo)(()=>({testID:B?`${B}-content-gesture`:"bottom-sheet-content-gesture"}),[B]),lt=(0,_reactNativeGestureHandler.useNativeGesture)(ct),ut=(0,_react.useMemo)(()=>{const e=ot,t=fe,a=nt,r=c;return{testID:B?`${B}-pan-gesture`:"bottom-sheet-pan-gesture",activeOffsetY:[-10,10],failOffsetX:[-15,15],onActivate:()=>{"worklet";pe.value=be.value},onUpdate:e=>{"worklet";const t=pe.value+e.translationY;be.value=t<a?a+.25*(t-a):t},onDeactivate:a=>{"worklet";const n=be.value,o=a.velocityY,[s]=e;if(void 0===s)return void(0,_reactNativeReanimated.runOnJS)(it)(-1,t);if(o>1e3)return r?void(0,_reactNativeReanimated.runOnJS)(it)(-1,t):void(0,_reactNativeReanimated.runOnJS)(it)(0,s);let i=0,c=s,l=1/0,u=0;for(const t of e){const e=Math.abs(n-t);e<l&&(l=e,c=t,i=u),u++}r&&n-s>80?(0,_reactNativeReanimated.runOnJS)(it)(-1,t):(0,_reactNativeReanimated.runOnJS)(it)(i,c)}}},[fe,pe,c,it,nt,ot,B,be]),dt=(0,_reactNativeGestureHandler.usePanGesture)(ut),{height:_t}=(0,_reactNativeKeyboardController.useReanimatedKeyboardAnimation)(),ht="shift"===p,mt=(0,_reactNativeReanimated.useDerivedValue)(()=>ht?_t.value:0,[ht,_t]),vt=ve[Math.max(ye,0)]??Se,ft=H.space.md,St=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{if(K){const e=mt.value,t=F+e-vt-ft,a=e<0&&be.value>t?t:be.value;return{top:Math.max(a,Z),opacity:xe.value}}const e=be.value+mt.value,t=mt.value<0?Z:nt;return{top:Math.max(e,t),opacity:xe.value}},[K,mt,F,vt,ft,be,Z,xe,nt]),bt=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=mt.value;if(K){const t=F+e-vt-ft,a=e<0&&be.value>t?t:be.value,r=Math.max(a,Z),n=F+e-ft-r;return{height:n<0?0:Math.min(n,vt)}}const t=e<0?Z:nt,a=be.value+e,r=Math.max(a,t),n=F+e-r;return{height:n<0?0:Math.min(n,Se)}},[mt,K,F,vt,ft,be,Z,nt,Se]),pt=ye>=0,xt=(0,_react.useMemo)(()=>buildStyles(H),[H]),Rt=(0,_react.useCallback)(()=>{l&&Ke(()=>{(0,_index2.triggerHaptic)("selection"),De.current(),Ye()})},[l,Ye,Ke]),yt=(0,_react.useMemo)(()=>({testID:B?`${B}-backdrop-gesture`:"bottom-sheet-backdrop-gesture",maxDuration:250,onDeactivate:e=>{"worklet";e.canceled||(0,_reactNativeReanimated.runOnJS)(Rt)()}}),[Rt,B]),Nt=(0,_reactNativeGestureHandler.useTapGesture)(yt),gt=(0,_react.useMemo)(()=>({snapIndex:ye,snapPoints:ve,close:Xe,requestClose:$e}),[ye,ve,Xe,$e]);if("inline"===P&&!ke)return null;if("modal"===P&&!Ce)return null;const Mt=(0,_jsxRuntime.jsxs)(_reactNative.View,{collapsable:!1,style:["modal"===P?xt.backdropModal:xt.backdropInline,{backgroundColor:"modal"===P?(0,_color.transparentOf)(H.colors.scrim):H.colors.scrim}],onLayout:W,testID:B,accessibilityViewIsModal:A??pt,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Nt,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:_reactNative.StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:V.close})}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{accessibilityRole:"alert",accessibilityLabel:T,accessibilityViewIsModal:A??pt,accessibilityActions:[{name:"escape",label:V.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[xt.sheet,{height:Se,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,..._corners.smoothCorners,...H.shadow.modal},K?{height:vt,left:(J-$)/2,right:void 0,width:$,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,g,St],children:(0,_jsxRuntime.jsxs)(SheetBody,{style:[xt.body,bt],keyboardOffset:mt,children:[K?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:H.space.md}}):(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:dt,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:xt.handleRow,onLayout:te?re:void 0,accessible:!0,accessibilityLabel:V.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:B?`${B}-handle`:"bottom-sheet-handle",children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[xt.handle,{backgroundColor:H.colors.border},N]})})}),I&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[xt.header,O],onLayout:te?oe:void 0,children:[null!=d?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",accessibilityRole:"header",children:d}):null,M]}),h?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:lt,children:(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{ref:m,style:xt.scrollContent,onScroll:v,onContentSizeChange:me,onLayout:S,scrollEventThrottle:b,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:k})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:te?[xt.content,{overflow:"visible"}]:xt.content,children:te?(0,_jsxRuntime.jsx)(_reactNative.View,{onLayout:ie,children:k}):k}),L&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[xt.footer,E],onLayout:te?ue:void 0,children:[D?(0,_jsxRuntime.jsx)(_reactNative.View,{style:xt.actions,children:(0,_jsxRuntime.jsx)(_OverlayActions.OverlayActions,{actions:j??[],layout:C})}):null,w]})]})})]}),jt=(0,_jsxRuntime.jsx)(BottomSheetContext.Provider,{value:gt,children:Mt});return"modal"===P?(0,_jsxRuntime.jsx)(_Modal.Modal,{open:Me,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===_reactNative.Platform.OS?Je:void 0,children:"android"===_reactNative.Platform.OS?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:xt.modalRoot,children:jt}):jt}):jt};exports.BottomSheet=BottomSheet;const SheetBody=({style:e,keyboardOffset:t,children:a})=>{const r=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)().bottom,n=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=r+t.value;return{paddingBottom:Math.max(e,0)}},[r,t]);return(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[e,n],children:a})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=(0,_react.useState)(0),a=(0,_react.useCallback)(e=>{t(t=>t===e?t:e)},[]);return[e,(0,_react.useCallback)(e=>a(e.nativeEvent.layout.height),[a]),a]},resolveSnapPoints=(e,t,a)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return a;const r=parseFloat(e);return Number.isNaN(r)?0:r/100*t})].sort((e,t)=>e-t),clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>_reactNative.StyleSheet.create({backdropModal:{flex:1},backdropInline:{..._reactNative.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,..._corners.smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});var _default=exports.default=BottomSheet;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useBottomSheet=exports.default=exports.DEFAULT_BOTTOM_SHEET_LABELS=exports.BottomSheet=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_reactNativeWorklets=require("react-native-worklets"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_OverlayActions=require("../Dialog/OverlayActions.js"),_Modal=require("../Modal/Modal.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,o=Object.defineProperty,s={__proto__:null,default:e};if(Object(e)!==e)return s;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,s)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=o&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?o(s,r,a):s[r]=e[r]);return s}const DEFAULT_BOTTOM_SHEET_LABELS=exports.DEFAULT_BOTTOM_SHEET_LABELS=Object.freeze({close:"Close bottom sheet",dragHandle:"Drag handle"}),DEFAULT_SNAP_POINTS=["content"],TABLET_MIN_SHORT_SIDE=600,DIALOG_MAX_WIDTH=560,BottomSheetContext=(0,_react.createContext)(null),useBottomSheet=()=>{const e=(0,_react.useContext)(BottomSheetContext);if(!e)throw new Error("[@webority/mobile-ui] BottomSheet: useBottomSheet must be used inside a <BottomSheet>.");return e};exports.useBottomSheet=useBottomSheet;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:a,onClose:r,snapIndex:o,onSnapChange:s,onAnimate:n,onAfterClose:i,enablePanDownToClose:c=!0,enableBackdropPress:l=!0,onBeforeClose:u,title:d,labels:_,scrollable:h=!1,scrollRef:m,onScroll:v,onContentSizeChange:f,onScrollLayout:b,scrollEventThrottle:S,keyboardBehavior:p="shift",inline:x=!1,presentation:R="sheet",animateMount:y=!0,handleIndicatorStyle:N,containerStyle:g,header:M,actions:j,actionsLayout:w="auto",footer:C,headerStyle:k,footerStyle:O,children:E,accessibilityLabel:T,accessibilityViewIsModal:A,testID:B}=e;(0,_assertValidValue.assertValidValue)("BottomSheet","presentation",e.presentation,["sheet","dialog","auto"]),(0,_assertValidValue.assertValidValue)("BottomSheet","keyboardBehavior",e.keyboardBehavior,["none","shift"]),(0,_assertValidValue.assertValidValue)("BottomSheet","actionsLayout",e.actionsLayout,_OverlayActions.ACTIONS_LAYOUTS);const V=(0,_react.useMemo)(()=>({...DEFAULT_BOTTOM_SHEET_LABELS,..._}),[_]),I=null!=M||null!=d,D=null!=j&&j.length>0,L=null!=C||D,P=x?"inline":"modal",H=(0,_index.useTheme)(),G=(0,_usePresenceMotion.usePresenceMotion)(),q=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),[W,F]=(0,_react.useState)(()=>_reactNative.Dimensions.get("window").height),[U,z]=(0,_react.useState)(()=>_reactNative.Dimensions.get("window").width),Y=(0,_react.useCallback)(e=>{const{height:t,width:a}=e.nativeEvent.layout;t>0&&F(e=>e===t?e:t),a>0&&z(e=>e===a?e:a)},[]),K=(0,_reactNative.useWindowDimensions)(),$="dialog"===R||"auto"===R&&Math.min(K.width,K.height)>=600,X=Math.min(560,U-2*H.space.xl),[J,Q]=(0,_ModalSafeArea.useModalInsets)(),Z="modal"===P?J.top:q.top,ee="modal"===P?J.bottom:q.bottom,te=t.includes("content"),[ae,re]=useMeasuredHeight(),[oe,se]=useMeasuredHeight(),[ne,ie,ce]=useMeasuredHeight(),[le,ue]=useMeasuredHeight(),de=$?H.space.md:ae,he=te?Math.min(de+(I?oe:0)+ne+(L?le:0)+ee,W-Z):0,me=(0,_react.useCallback)((e,t)=>{te&&ce(t),f?.(e,t)},[te,f,ce]),ve=(0,_react.useMemo)(()=>resolveSnapPoints(t,W,he),[t,W,he]),fe=W,be=ve[ve.length-1]??0,Se=(0,_reactNativeReanimated.useSharedValue)(fe),pe=(0,_reactNativeReanimated.useSharedValue)(fe),xe=(0,_reactNativeReanimated.useSharedValue)(1),Re=(0,_reactNativeReanimated.useSharedValue)(-1),[ye,Ne]=(0,_react.useState)(-1),ge=(0,_react.useRef)(!1),[Me,je]=(0,_react.useState)(!1),[we,Ce]=(0,_react.useState)(!1),ke=(0,_react.useRef)(!1),Oe=(0,_react.useRef)(i);Oe.current=i;const[Ee,Te]=(0,_react.useState)(!1),Ae=(0,_react.useRef)(!y&&a),Be=(0,_react.useRef)(-1),Ve=(0,_react.useRef)(!1);Ve.current="modal"===P?we:Ee;const Ie=(0,_react.useRef)(u);Ie.current=u;const De=(0,_react.useRef)(r);De.current=r;const Le=(0,_react.useRef)(!1),Pe=(0,_react.useRef)(!0),He=(0,_react.useRef)([]),Ge=(0,_react.useCallback)(e=>{const t=He.current;He.current=[];for(const a of t)a(e)},[]);(0,_react.useEffect)(()=>(Pe.current=!0,()=>{Pe.current=!1,Ge(!1)}),[Ge]);const qe=(0,_react.useCallback)(e=>{if(e<0||e>=ve.length)return fe;const t=ve[e];if(void 0===t)throw new Error("BottomSheet: an in-range snap index always has a resolved snap point");return $?(W-t)/2:W-t},[ve,W,fe,$]),We=(0,_react.useCallback)(e=>{Be.current=e;ye!==e&&(Ne(e),Re.value=e,e>=0&&s?.(e))},[ye,Re,s]),Fe=(0,_react.useCallback)(()=>{ge.current=!1,Re.value<0&&(ke.current=!0,"modal"===P?(je(!1),"ios"!==_reactNative.Platform.OS&&Ce(!1)):Te(!1))},[P,Re]),Ue=(0,_react.useCallback)(()=>{ke.current&&Ce(!1)},[]);(0,_react.useEffect)(()=>{("modal"===P?!we:!Ee)&&ke.current&&(ke.current=!1,Oe.current?.(),Ge(!0))},[P,we,Ee,Ge]);const ze=(0,_react.useCallback)((e,t,a)=>{ge.current=!0,n?.(t,a),Se.value=(0,_reactNativeReanimated.withSpring)(e,SPRING_CONFIG,e=>{"worklet";e&&(0,_reactNativeWorklets.scheduleOnRN)(Fe)})},[n,Se,Fe]),Ye=(0,_react.useCallback)(e=>{const t="number"==typeof e?clamp(e,0,ve.length-1):Math.max(ye,0),a=Re.value,r=qe(t);return ke.current=!1,Ge(!1),"modal"===P?(Ce(!0),je(!0)):Te(!0),a<0&&Ae.current?(Se.value=r,xe.value=1,We(t),void n?.(a,t)):a<0&&G.reduced?(Se.value=r,xe.value=0,xe.value=(0,_reactNativeReanimated.withTiming)(1,{duration:G.duration("fast"),easing:_reactNativeReanimated.Easing.bezier(...H.motion.ease.decelerate),reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION}),We(t),void n?.(a,t)):(a<0&&(Se.value=fe,xe.value=1),We(t),void ze(r,a,t))},[ze,fe,ye,Re,P,n,G,xe,ve.length,We,Ge,H.motion.ease.decelerate,Se,qe]),Ke=(0,_react.useCallback)(()=>new Promise(e=>{if(Be.current<0)return void(Ve.current?He.current.push(e):e(!0));He.current.push(e),Ae.current=!1;const t=Re.value;We(-1),ge.current=!0,n?.(t,-1);const a=G.reduced?xe:Se,r=G.reduced?0:fe;a.value=(0,_reactNativeReanimated.withTiming)(r,{duration:G.duration("fast"),easing:_reactNativeReanimated.Easing.bezier(...H.motion.ease.accelerate),reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(0,_reactNativeWorklets.scheduleOnRN)(Fe)})}),[fe,Re,Fe,n,G,xe,We,Se,H.motion.ease.accelerate]),$e=(0,_react.useCallback)((e,t,a)=>{const r=Ie.current;if(!r)return void e();if(Le.current)return void t?.();const o=r();"boolean"!=typeof o?(Le.current=!0,a?.(),o.then(a=>{Le.current=!1,a&&Pe.current&&Be.current>=0?e():t?.()},e=>{throw Le.current=!1,e})):(o?e:t)?.()},[]),Xe=(0,_react.useCallback)(()=>new Promise(e=>{Be.current<0?e(!0):$e(()=>{De.current(),Ke(),e(!0)},()=>e(!1))}),[Ke,$e]),Je=(0,_react.useCallback)(()=>{De.current()},[]),Qe=(0,_react.useCallback)(()=>{l&&Xe()},[l,Xe]),Ze=(0,_react.useRef)(null),et=(0,_react.useRef)(Ye);et.current=Ye;const tt=(0,_react.useRef)(Ke);tt.current=Ke,(0,_react.useEffect)(()=>{const e=Ze.current!==a;Ze.current=a,e?a?et.current(o??0):tt.current():a&&"number"==typeof o&&o!==Re.value&&et.current(o)},[a,o,Re]);const at=(0,_react.useRef)({hostHeight:W,contentSnap:he}),rt=(0,_react.useRef)(qe);rt.current=qe,(0,_react.useEffect)(()=>{const e=at.current;if(e.hostHeight===W&&e.contentSnap===he)return;if(at.current={hostHeight:W,contentSnap:he},e.hostHeight===W&&Re.value<0)return;const t=rt.current(Re.value);Se.value=Ae.current?t:(0,_reactNativeReanimated.withSpring)(t,SPRING_CONFIG)},[W,he,Re,Se]);const ot=W-be,st=(0,_react.useMemo)(()=>ve.map(e=>W-e),[ve,W]),nt=(0,_react.useCallback)(()=>{const e=Be.current;e<0||ze(qe(e),e,e)},[ze,qe]),it=(0,_react.useCallback)((e,t)=>{const a=Re.value;-1!==e?(We(e),ze(t,a,e)):$e(()=>{_reactNative.Keyboard.dismiss(),(0,_index2.triggerHaptic)("selection"),De.current(),Ke()},nt,nt)},[ze,Ke,Re,$e,We,nt]),ct=(0,_react.useMemo)(()=>({testID:B?`${B}-content-gesture`:"bottom-sheet-content-gesture"}),[B]),lt=(0,_reactNativeGestureHandler.useNativeGesture)(ct),ut=(0,_react.useMemo)(()=>{const e=st,t=fe,a=ot,r=c;return{testID:B?`${B}-pan-gesture`:"bottom-sheet-pan-gesture",activeOffsetY:[-10,10],failOffsetX:[-15,15],onActivate:()=>{"worklet";pe.value=Se.value},onUpdate:e=>{"worklet";const t=pe.value+e.translationY;Se.value=t<a?a+.25*(t-a):t},onDeactivate:a=>{"worklet";const o=Se.value,s=a.velocityY,[n]=e;if(void 0===n)return void(0,_reactNativeWorklets.scheduleOnRN)(it,-1,t);if(s>1e3)return r?void(0,_reactNativeWorklets.scheduleOnRN)(it,-1,t):void(0,_reactNativeWorklets.scheduleOnRN)(it,0,n);let i=0,c=n,l=1/0,u=0;for(const t of e){const e=Math.abs(o-t);e<l&&(l=e,c=t,i=u),u++}r&&o-n>80?(0,_reactNativeWorklets.scheduleOnRN)(it,-1,t):(0,_reactNativeWorklets.scheduleOnRN)(it,i,c)}}},[fe,pe,c,it,ot,st,B,Se]),dt=(0,_reactNativeGestureHandler.usePanGesture)(ut),{height:_t}=(0,_reactNativeKeyboardController.useReanimatedKeyboardAnimation)(),ht="shift"===p,mt=(0,_reactNativeReanimated.useDerivedValue)(()=>ht?_t.value:0,[ht,_t]),vt=ve[Math.max(ye,0)]??be,ft=H.space.md,bt=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{if($){const e=mt.value,t=W+e-vt-ft,a=e<0&&Se.value>t?t:Se.value;return{top:Math.max(a,Z),opacity:xe.value}}const e=Se.value+mt.value,t=mt.value<0?Z:ot;return{top:Math.max(e,t),opacity:xe.value}},[$,mt,W,vt,ft,Se,Z,xe,ot]),St=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=mt.value;if($){const t=W+e-vt-ft,a=e<0&&Se.value>t?t:Se.value,r=Math.max(a,Z),o=W+e-ft-r;return{height:o<0?0:Math.min(o,vt)}}const t=e<0?Z:ot,a=Se.value+e,r=Math.max(a,t),o=W+e-r;return{height:o<0?0:Math.min(o,be)}},[mt,$,W,vt,ft,Se,Z,ot,be]),pt=ye>=0,xt=(0,_react.useMemo)(()=>buildStyles(H),[H]),Rt=(0,_react.useCallback)(()=>{l&&$e(()=>{(0,_index2.triggerHaptic)("selection"),De.current(),Ke()})},[l,Ke,$e]),yt=(0,_react.useMemo)(()=>({testID:B?`${B}-backdrop-gesture`:"bottom-sheet-backdrop-gesture",maxDuration:250,onDeactivate:e=>{"worklet";e.canceled||(0,_reactNativeWorklets.scheduleOnRN)(Rt)}}),[Rt,B]),Nt=(0,_reactNativeGestureHandler.useTapGesture)(yt),gt=(0,_react.useMemo)(()=>({snapIndex:ye,snapPoints:ve,close:Je,requestClose:Xe}),[ye,ve,Je,Xe]);if("inline"===P&&!Ee)return null;if("modal"===P&&!we)return null;const Mt=(0,_jsxRuntime.jsxs)(_reactNative.View,{collapsable:!1,style:["modal"===P?xt.backdropModal:xt.backdropInline,{backgroundColor:"modal"===P?(0,_color.transparentOf)(H.colors.scrim):H.colors.scrim}],onLayout:Y,testID:B,accessibilityViewIsModal:A??pt,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Nt,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:_reactNative.StyleSheet.absoluteFill,accessibilityRole:"button",accessibilityLabel:V.close})}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{accessibilityRole:"alert",accessibilityLabel:T,accessibilityViewIsModal:A??pt,accessibilityActions:[{name:"escape",label:V.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[xt.sheet,{height:be,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,..._corners.smoothCorners,...H.shadow.modal},$?{height:vt,left:(U-X)/2,right:void 0,width:X,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,g,bt],children:(0,_jsxRuntime.jsxs)(SheetBody,{style:[xt.body,St],keyboardOffset:mt,children:[$?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:H.space.md}}):(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:dt,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:xt.handleRow,onLayout:te?re:void 0,accessible:!0,accessibilityLabel:V.dragHandle,accessibilityHint:"Drag up or down to resize the sheet, or swipe down to close it",testID:B?`${B}-handle`:"bottom-sheet-handle",children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[xt.handle,{backgroundColor:H.colors.border},N]})})}),I&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[xt.header,k],onLayout:te?se:void 0,children:[null!=d?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",accessibilityRole:"header",children:d}):null,M]}),h?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:lt,children:(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{ref:m,style:xt.scrollContent,onScroll:v,onContentSizeChange:me,onLayout:b,scrollEventThrottle:S,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:E})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:te?[xt.content,{overflow:"visible"}]:xt.content,children:te?(0,_jsxRuntime.jsx)(_reactNative.View,{onLayout:ie,children:E}):E}),L&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[xt.footer,O],onLayout:te?ue:void 0,children:[D?(0,_jsxRuntime.jsx)(_reactNative.View,{style:xt.actions,children:(0,_jsxRuntime.jsx)(_OverlayActions.OverlayActions,{actions:j??[],layout:w})}):null,C]})]})})]}),jt=(0,_jsxRuntime.jsx)(BottomSheetContext.Provider,{value:gt,children:Mt});return"modal"===P?(0,_jsxRuntime.jsx)(_Modal.Modal,{open:Me,onClose:Qe,presentation:"fullScreen",bare:!0,backdropPressClose:!1,haptic:!1,animateMount:!1,onInsetsChange:Q,onDismissed:"ios"===_reactNative.Platform.OS?Ue:void 0,children:"android"===_reactNative.Platform.OS?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:xt.modalRoot,children:jt}):jt}):jt};exports.BottomSheet=BottomSheet;const SheetBody=({style:e,keyboardOffset:t,children:a})=>{const r=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)().bottom,o=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=r+t.value;return{paddingBottom:Math.max(e,0)}},[r,t]);return(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[e,o],children:a})};BottomSheet.displayName="BottomSheet";const useMeasuredHeight=()=>{const[e,t]=(0,_react.useState)(0),a=(0,_react.useCallback)(e=>{t(t=>t===e?t:e)},[]);return[e,(0,_react.useCallback)(e=>a(e.nativeEvent.layout.height),[a]),a]},resolveSnapPoints=(e,t,a)=>[...e.map(e=>{if("number"==typeof e)return e;if("content"===e)return a;const r=parseFloat(e);return Number.isNaN(r)?0:r/100*t})].sort((e,t)=>e-t),clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>_reactNative.StyleSheet.create({backdropModal:{flex:1},backdropInline:{..._reactNative.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,..._corners.smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1},modalRoot:{flex:1}});var _default=exports.default=BottomSheet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.buildPieces=exports.DEFAULT_PHYSICS=exports.Confetti=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeSvg=_interopRequireWildcard(require("react-native-svg")),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,a){if(!a&&e&&e.__esModule)return e;var t,r,i=Object.defineProperty,s={__proto__:null,default:e};if(Object(e)!==e)return s;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,s)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((t=i&&Object.getOwnPropertyDescriptor(e,r))&&(t.get||t.set)?i(s,r,t):s[r]=e[r]);return s}const TAU=2*Math.PI,DEG=Math.PI/180,SPEED_FACTOR={slow:1.6,normal:1,fast:.6},DEFAULT_PHYSICS=exports.DEFAULT_PHYSICS={velocity:1,drag:1,fallSpeed:1,spread:0},PRESET_SHAPES={pop:["strip","strip","strip","square","circle","triangle","star","streamer"],rain:["strip","strip","strip","circle","square"],fireworks:["circle","circle","star","star","triangle","strip"]},rand=(e,a)=>e+Math.random()*(a-e),itemAt=(e,a,t)=>{const r=e[a];if(void 0===r)throw new Error(`Confetti needs at least one ${t}`);return r},pick=e=>itemAt(e,Math.floor(Math.random()*e.length),"shape"),randomSign=()=>Math.random()<.5?1:-1,commonPiece=(e,a)=>({color:itemAt(e.colors,a%e.colors.length,"colour"),size:e.baseSize*rand(.6,1.4),shape:pick(e.shapes),rotations:rand(1,5),rotateDir:randomSign(),flutterFreq:rand(2,5)}),popPiece=(e,a)=>{const t=e.physics.spread>0?e.physics.spread/2:100,r=(-90+rand(-t,t))*DEG,i=rand(1.8,4.2)*e.physics.velocity;return{...commonPiece(e,a),x0Frac:e.originXFrac,y0Frac:e.originYFrac,vxFrac:Math.cos(r)*i*.7,vyFrac:Math.sin(r)*i,drag:rand(5.5,7.5)*e.physics.drag,terminalFrac:rand(.22,.44)*e.physics.fallSpeed,delay:rand(0,.05),swayAmp:rand(4,16),swayFreq:rand(1,3)}},rainPiece=(e,a)=>({...commonPiece(e,a),x0Frac:Math.random(),y0Frac:-.05,vxFrac:rand(-.12,.12)*e.physics.velocity,vyFrac:rand(.05,.25)*e.physics.velocity,drag:rand(2.5,4)*e.physics.drag,terminalFrac:rand(.95,1.35)*e.physics.fallSpeed,delay:rand(0,.35),swayAmp:rand(10,30),swayFreq:rand(1,3)}),FIREWORK_BURSTS=4,buildFireworks=(e,a)=>{const t=Math.max(1,Math.round(e/4)),r=a.physics.spread>0?a.physics.spread/2:180,i=[];for(let s=0;s<4&&i.length<e;s+=1){const n=rand(.18,.82),c=rand(.18,.52),o=s/4*.5+rand(0,.06);for(let s=0;s<t&&i.length<e;s+=1){const e=rand(-r,r)*DEG,t=rand(1.4,3.4)*a.physics.velocity;i.push({...commonPiece(a,i.length),x0Frac:n,y0Frac:c,vxFrac:Math.cos(e)*t*.7,vyFrac:Math.sin(e)*t,drag:rand(6.5,8.5)*a.physics.drag,terminalFrac:rand(.18,.38)*a.physics.fallSpeed,delay:o,swayAmp:rand(3,12),swayFreq:rand(1,3)})}}return i},buildPieces=(e,a,t)=>{if("fireworks"===a)return buildFireworks(e,t);const r="rain"===a?rainPiece:popPiece;return Array.from({length:e},(e,a)=>r(t,a))};exports.buildPieces=buildPieces;const SHAPE_BOX={strip:{w:1,h:.45},square:{w:1,h:1},circle:{w:1,h:1},triangle:{w:1,h:1},star:{w:1.2,h:1.2},streamer:{w:3,h:1.2}},TRIANGLE_POINTS="50,4 96,96 4,96",STAR_POINTS="50,2 61,36 97,36 68,58 79,94 50,72 21,94 32,58 3,36 39,36",STREAMER_PATH="M2,50 C20,6 44,94 62,50 S92,6 98,50",ShapeBody=({shape:e,color:a})=>"triangle"===e||"star"===e?(0,_jsxRuntime.jsx)(_reactNativeSvg.default,{width:"100%",height:"100%",viewBox:"0 0 100 100",children:(0,_jsxRuntime.jsx)(_reactNativeSvg.Polygon,{points:"star"===e?STAR_POINTS:TRIANGLE_POINTS,fill:a})}):"streamer"===e?(0,_jsxRuntime.jsx)(_reactNativeSvg.default,{width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",children:(0,_jsxRuntime.jsx)(_reactNativeSvg.Path,{d:STREAMER_PATH,stroke:a,strokeWidth:22,strokeLinecap:"round",fill:"none"})}):null,ConfettiPiece=({piece:e,progress:a,width:t,height:r,fadeOut:i})=>{const s=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const s=1-e.delay,n=s<=0?0:Math.min(1,Math.max(0,(a.value-e.delay)/s)),c=(1-Math.exp(-e.drag*n))/e.drag,o=e.x0Frac*t+e.vxFrac*t*c,l=e.y0Frac*r+e.terminalFrac*r*n+(e.vyFrac-e.terminalFrac)*r*c,d=Math.sin(n*e.swayFreq*TAU)*e.swayAmp,h=e.rotateDir*e.rotations*360*n,p=.35+.65*Math.abs(Math.cos(n*e.flutterFreq*TAU));return{opacity:i?Math.max(0,1-Math.max(0,n-.75)/.25):1,transform:[{translateX:o+d},{translateY:l},{rotate:`${h}deg`},{scaleY:p}]}},[e,a,t,r,i]),n=SHAPE_BOX[e.shape],c="triangle"===e.shape||"star"===e.shape||"streamer"===e.shape;return(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[{position:"absolute",width:e.size*n.w,height:e.size*n.h,borderRadius:"circle"===e.shape?e.size*n.h/2:1,backgroundColor:c?"transparent":e.color},s],children:(0,_jsxRuntime.jsx)(ShapeBody,{shape:e.shape,color:e.color})})},Confetti=exports.Confetti=(0,_react.forwardRef)(({count:e=80,colors:a,preset:t="pop",shapes:r,speed:i="normal",physics:s,origin:n,duration:c=2800,fadeOut:o=!0,autoStart:l=!1,recycle:d=!1,size:h=10,onComplete:p,style:u,testID:_},m)=>{(0,_assertValidValue.assertValidValue)("Confetti","preset",t,["pop","rain","fireworks"]),(0,_assertValidValue.assertValidValue)("Confetti","speed",i,["slow","normal","fast"]);for(const e of r??[])(0,_assertValidValue.assertValidValue)("Confetti","shapes",e,["strip","square","circle","triangle","star","streamer"]);const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.buildPieces=exports.DEFAULT_PHYSICS=exports.Confetti=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeSvg=_interopRequireWildcard(require("react-native-svg")),_reactNativeWorklets=require("react-native-worklets"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,a){if(!a&&e&&e.__esModule)return e;var t,r,i=Object.defineProperty,s={__proto__:null,default:e};if(Object(e)!==e)return s;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,s)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((t=i&&Object.getOwnPropertyDescriptor(e,r))&&(t.get||t.set)?i(s,r,t):s[r]=e[r]);return s}const TAU=2*Math.PI,DEG=Math.PI/180,SPEED_FACTOR={slow:1.6,normal:1,fast:.6},DEFAULT_PHYSICS=exports.DEFAULT_PHYSICS={velocity:1,drag:1,fallSpeed:1,spread:0},PRESET_SHAPES={pop:["strip","strip","strip","square","circle","triangle","star","streamer"],rain:["strip","strip","strip","circle","square"],fireworks:["circle","circle","star","star","triangle","strip"]},rand=(e,a)=>e+Math.random()*(a-e),itemAt=(e,a,t)=>{const r=e[a];if(void 0===r)throw new Error(`Confetti needs at least one ${t}`);return r},pick=e=>itemAt(e,Math.floor(Math.random()*e.length),"shape"),randomSign=()=>Math.random()<.5?1:-1,commonPiece=(e,a)=>({color:itemAt(e.colors,a%e.colors.length,"colour"),size:e.baseSize*rand(.6,1.4),shape:pick(e.shapes),rotations:rand(1,5),rotateDir:randomSign(),flutterFreq:rand(2,5)}),popPiece=(e,a)=>{const t=e.physics.spread>0?e.physics.spread/2:100,r=(-90+rand(-t,t))*DEG,i=rand(1.8,4.2)*e.physics.velocity;return{...commonPiece(e,a),x0Frac:e.originXFrac,y0Frac:e.originYFrac,vxFrac:Math.cos(r)*i*.7,vyFrac:Math.sin(r)*i,drag:rand(5.5,7.5)*e.physics.drag,terminalFrac:rand(.22,.44)*e.physics.fallSpeed,delay:rand(0,.05),swayAmp:rand(4,16),swayFreq:rand(1,3)}},rainPiece=(e,a)=>({...commonPiece(e,a),x0Frac:Math.random(),y0Frac:-.05,vxFrac:rand(-.12,.12)*e.physics.velocity,vyFrac:rand(.05,.25)*e.physics.velocity,drag:rand(2.5,4)*e.physics.drag,terminalFrac:rand(.95,1.35)*e.physics.fallSpeed,delay:rand(0,.35),swayAmp:rand(10,30),swayFreq:rand(1,3)}),FIREWORK_BURSTS=4,buildFireworks=(e,a)=>{const t=Math.max(1,Math.round(e/4)),r=a.physics.spread>0?a.physics.spread/2:180,i=[];for(let s=0;s<4&&i.length<e;s+=1){const n=rand(.18,.82),c=rand(.18,.52),o=s/4*.5+rand(0,.06);for(let s=0;s<t&&i.length<e;s+=1){const e=rand(-r,r)*DEG,t=rand(1.4,3.4)*a.physics.velocity;i.push({...commonPiece(a,i.length),x0Frac:n,y0Frac:c,vxFrac:Math.cos(e)*t*.7,vyFrac:Math.sin(e)*t,drag:rand(6.5,8.5)*a.physics.drag,terminalFrac:rand(.18,.38)*a.physics.fallSpeed,delay:o,swayAmp:rand(3,12),swayFreq:rand(1,3)})}}return i},buildPieces=(e,a,t)=>{if("fireworks"===a)return buildFireworks(e,t);const r="rain"===a?rainPiece:popPiece;return Array.from({length:e},(e,a)=>r(t,a))};exports.buildPieces=buildPieces;const SHAPE_BOX={strip:{w:1,h:.45},square:{w:1,h:1},circle:{w:1,h:1},triangle:{w:1,h:1},star:{w:1.2,h:1.2},streamer:{w:3,h:1.2}},TRIANGLE_POINTS="50,4 96,96 4,96",STAR_POINTS="50,2 61,36 97,36 68,58 79,94 50,72 21,94 32,58 3,36 39,36",STREAMER_PATH="M2,50 C20,6 44,94 62,50 S92,6 98,50",ShapeBody=({shape:e,color:a})=>"triangle"===e||"star"===e?(0,_jsxRuntime.jsx)(_reactNativeSvg.default,{width:"100%",height:"100%",viewBox:"0 0 100 100",children:(0,_jsxRuntime.jsx)(_reactNativeSvg.Polygon,{points:"star"===e?STAR_POINTS:TRIANGLE_POINTS,fill:a})}):"streamer"===e?(0,_jsxRuntime.jsx)(_reactNativeSvg.default,{width:"100%",height:"100%",viewBox:"0 0 100 100",preserveAspectRatio:"none",children:(0,_jsxRuntime.jsx)(_reactNativeSvg.Path,{d:STREAMER_PATH,stroke:a,strokeWidth:22,strokeLinecap:"round",fill:"none"})}):null,ConfettiPiece=({piece:e,progress:a,width:t,height:r,fadeOut:i})=>{const s=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const s=1-e.delay,n=s<=0?0:Math.min(1,Math.max(0,(a.value-e.delay)/s)),c=(1-Math.exp(-e.drag*n))/e.drag,o=e.x0Frac*t+e.vxFrac*t*c,l=e.y0Frac*r+e.terminalFrac*r*n+(e.vyFrac-e.terminalFrac)*r*c,d=Math.sin(n*e.swayFreq*TAU)*e.swayAmp,h=e.rotateDir*e.rotations*360*n,p=.35+.65*Math.abs(Math.cos(n*e.flutterFreq*TAU));return{opacity:i?Math.max(0,1-Math.max(0,n-.75)/.25):1,transform:[{translateX:o+d},{translateY:l},{rotate:`${h}deg`},{scaleY:p}]}},[e,a,t,r,i]),n=SHAPE_BOX[e.shape],c="triangle"===e.shape||"star"===e.shape||"streamer"===e.shape;return(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[{position:"absolute",width:e.size*n.w,height:e.size*n.h,borderRadius:"circle"===e.shape?e.size*n.h/2:1,backgroundColor:c?"transparent":e.color},s],children:(0,_jsxRuntime.jsx)(ShapeBody,{shape:e.shape,color:e.color})})},Confetti=exports.Confetti=(0,_react.forwardRef)(({count:e=80,colors:a,preset:t="pop",shapes:r,speed:i="normal",physics:s,origin:n,duration:c=2800,fadeOut:o=!0,autoStart:l=!1,recycle:d=!1,size:h=10,onComplete:p,style:u,testID:_},m)=>{(0,_assertValidValue.assertValidValue)("Confetti","preset",t,["pop","rain","fireworks"]),(0,_assertValidValue.assertValidValue)("Confetti","speed",i,["slow","normal","fast"]);for(const e of r??[])(0,_assertValidValue.assertValidValue)("Confetti","shapes",e,["strip","square","circle","triangle","star","streamer"]);const v=(0,_index2.useTheme)(),y=(0,_index.useReducedMotion)(),f=(0,_reactNative.useWindowDimensions)(),[g,S]=(0,_react.useState)({width:f.width,height:f.height}),[x,w]=(0,_react.useState)(!1),[R,F]=(0,_react.useState)([]),P=(0,_react.useMemo)(()=>a??[v.colors.primary,v.colors.neutral,v.colors.success,v.colors.warning,v.colors.danger,v.colors.info],[a,v.colors]),A=(0,_reactNativeReanimated.useSharedValue)(0),E=c*SPEED_FACTOR[i],M=(0,_react.useCallback)(()=>{w(!1),p?.()},[p]),N=(0,_react.useCallback)(()=>{if(y)return void p?.();(0,_reactNativeReanimated.cancelAnimation)(A),A.value=0,F(buildPieces(e,t,{colors:P,baseSize:h,originXFrac:n?n.x/Math.max(1,g.width):.5,originYFrac:n?n.y/Math.max(1,g.height):.5,physics:{velocity:void 0===s?.velocity?DEFAULT_PHYSICS.velocity:s.velocity,drag:void 0===s?.drag?DEFAULT_PHYSICS.drag:s.drag,fallSpeed:void 0===s?.fallSpeed?DEFAULT_PHYSICS.fallSpeed:s.fallSpeed,spread:void 0===s?.spread?DEFAULT_PHYSICS.spread:s.spread},shapes:r??PRESET_SHAPES[t]})),w(!0);const a=(0,_reactNativeReanimated.withTiming)(1,{duration:E,easing:_reactNativeReanimated.Easing.linear},e=>{"worklet";e&&!d&&(0,_reactNativeWorklets.scheduleOnRN)(M)});A.value=d?(0,_reactNativeReanimated.withRepeat)(a,-1,!1):a},[y,A,E,d,M,p,e,P,t,r,s,h,n,g.width,g.height]),T=(0,_react.useCallback)(()=>{(0,_reactNativeReanimated.cancelAnimation)(A),w(!1)},[A]);(0,_react.useImperativeHandle)(m,()=>({start:N,stop:T}),[N,T]);const C=(0,_react.useRef)(l).current,j=(0,_react.useRef)(N).current;(0,_react.useEffect)(()=>(C&&j(),()=>(0,_reactNativeReanimated.cancelAnimation)(A)),[A,C,j]);const k=(0,_react.useCallback)(e=>{const{width:a,height:t}=e.nativeEvent.layout;a>0&&t>0&&S({width:a,height:t})},[]),b=(0,_react.useMemo)(()=>R.map((e,a)=>({key:`confetti-${a}`,piece:e})),[R]);return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[_reactNative.StyleSheet.absoluteFill,u],pointerEvents:"none",onLayout:k,testID:_,children:x?b.map(({key:e,piece:a})=>(0,_jsxRuntime.jsx)(ConfettiPiece,{piece:a,progress:A,width:g.width,height:g.height,fadeOut:o},e)):null})});Confetti.displayName="Confetti";var _default=exports.default=Confetti;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Drawer=exports.DEFAULT_DRAWER_LABELS=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,i=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=i&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?i(n,r,a):n[r]=e[r]);return n}const DEFAULT_DRAWER_LABELS=exports.DEFAULT_DRAWER_LABELS={close:"Close drawer",drawer:"Drawer"},DEFAULT_CLOSE_VELOCITY_THRESHOLD=1e3,DEFAULT_DRAG_ACTIVATION_OFFSET=10,Drawer=exports.Drawer=(0,_react.forwardRef)((e,t)=>{const{open:a,defaultOpen:r=!1,onOpenChange:i,side:n="left",width:s,enableSwipe:o=!0,enableBackdropPress:c=!0,backdropOpacity:l=.5,haptic:u,containerStyle:d,children:_,accessibilityLabel:v,labels:p,testID:f}=e,h=(0,_index.useTheme)();(0,_assertValidValue.assertValidValue)("Drawer","side",e.side,["left","right","top","bottom"]);const m=(0,_react.useMemo)(()=>({...DEFAULT_DRAWER_LABELS,...p}),[p]),b=(0,_usePresenceMotion.usePresenceMotion)(),R=b.reduced,g=b.duration("default"),N=b.duration("fast"),w=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),E="boolean"==typeof a,[S,y]=(0,_react.useState)(()=>_reactNative.Dimensions.get("window"));(0,_react.useEffect)(()=>{const e=_reactNative.Dimensions.addEventListener("change",({window:e})=>y(e));return()=>e.remove()},[]);const O="left"===n||"right"===n,x=(0,_react.useMemo)(()=>resolveSize(s,O,S),[s,O,S]),M=(0,_react.useMemo)(()=>closedOffsetOf(n,x),[n,x]),D=(0,_reactNativeReanimated.useSharedValue)(r?0:M),L=(0,_reactNativeReanimated.useSharedValue)(r?0:M),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Drawer=exports.DEFAULT_DRAWER_LABELS=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_reactNativeWorklets=require("react-native-worklets"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,i=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=i&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?i(n,r,a):n[r]=e[r]);return n}const DEFAULT_DRAWER_LABELS=exports.DEFAULT_DRAWER_LABELS={close:"Close drawer",drawer:"Drawer"},DEFAULT_CLOSE_VELOCITY_THRESHOLD=1e3,DEFAULT_DRAG_ACTIVATION_OFFSET=10,Drawer=exports.Drawer=(0,_react.forwardRef)((e,t)=>{const{open:a,defaultOpen:r=!1,onOpenChange:i,side:n="left",width:s,enableSwipe:o=!0,enableBackdropPress:c=!0,backdropOpacity:l=.5,haptic:u,containerStyle:d,children:_,accessibilityLabel:v,labels:p,testID:f}=e,h=(0,_index.useTheme)();(0,_assertValidValue.assertValidValue)("Drawer","side",e.side,["left","right","top","bottom"]);const m=(0,_react.useMemo)(()=>({...DEFAULT_DRAWER_LABELS,...p}),[p]),b=(0,_usePresenceMotion.usePresenceMotion)(),R=b.reduced,g=b.duration("default"),N=b.duration("fast"),w=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),E="boolean"==typeof a,[S,y]=(0,_react.useState)(()=>_reactNative.Dimensions.get("window"));(0,_react.useEffect)(()=>{const e=_reactNative.Dimensions.addEventListener("change",({window:e})=>y(e));return()=>e.remove()},[]);const O="left"===n||"right"===n,x=(0,_react.useMemo)(()=>resolveSize(s,O,S),[s,O,S]),M=(0,_react.useMemo)(()=>closedOffsetOf(n,x),[n,x]),D=(0,_reactNativeReanimated.useSharedValue)(r?0:M),L=(0,_reactNativeReanimated.useSharedValue)(r?0:M),k=(0,_reactNativeReanimated.useSharedValue)(r?1:0),[C,A]=(0,_react.useState)(r),T=(0,_reactNativeReanimated.useSharedValue)(r);(0,_react.useEffect)(()=>{C||R||(D.value=M,L.value=M)},[M,C,D,L,R]);const j=h.motion.spring.snappy,P=(0,_react.useCallback)(()=>{if(R)return D.value=0,void(k.value=(0,_reactNativeReanimated.withTiming)(1,{duration:g,reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION}));k.value=1,D.value=(0,_reactNativeReanimated.withSpring)(0,j)},[D,k,j,R,g]),V=(0,_react.useCallback)(()=>{R?k.value=(0,_reactNativeReanimated.withTiming)(0,{duration:N,reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(D.value=M)}):D.value=(0,_reactNativeReanimated.withSpring)(M,j)},[D,k,M,j,R,N]),q=(0,_react.useCallback)(e=>{A(t=>t===e?t:(i?.(e),e)),T.value=e},[i,T]),F=(0,_react.useCallback)(()=>{q(!0),P()},[q,P]),I=(0,_react.useCallback)(()=>{q(!1),V()},[q,V]),U=(0,_react.useCallback)(()=>{C?I():F()},[C,F,I]);(0,_react.useImperativeHandle)(t,()=>({open:F,close:I,toggle:U}),[F,I,U]);const W=(0,_react.useRef)({isOpen:C,open:F,close:I});W.current={isOpen:C,open:F,close:I},(0,_react.useEffect)(()=>{if(!E)return;const e=W.current;a!==e.isOpen&&(a?e.open():e.close())},[a,E]);const B=(0,_react.useMemo)(()=>{const e=M,t=n,a=o;return{...O?{activeOffsetX:[-10,10],failOffsetY:[-15,15]}:{activeOffsetY:[-10,10],failOffsetX:[-15,15]},onActivate:()=>{"worklet";a&&(L.value=D.value)},onUpdate:t=>{"worklet";if(!a)return;const r=O?t.translationX:t.translationY,i=L.value+r,n=Math.min(0,e),s=Math.max(0,e);D.value=i<n?n+.25*(i-n):i>s?s+.25*(i-s):i},onDeactivate:r=>{"worklet";if(!a)return;const i=O?r.velocityX:r.velocityY,n=D.value;let s=!1;s="left"===t||"top"===t?i<-1e3:i>1e3;const o=Math.abs(e),c=Math.abs(n)/o;s||c>.5?((0,_reactNativeWorklets.scheduleOnRN)(q,!1),R?k.value=(0,_reactNativeReanimated.withTiming)(0,{duration:N,reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION},t=>{"worklet";t&&(D.value=e)}):D.value=(0,_reactNativeReanimated.withSpring)(e,j)):((0,_reactNativeWorklets.scheduleOnRN)(q,!0),R?(D.value=0,k.value=(0,_reactNativeReanimated.withTiming)(1,{duration:g,reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION})):D.value=(0,_reactNativeReanimated.withSpring)(0,j))}}},[M,L,o,O,D,k,q,n,j,R,g,N]),H=(0,_reactNativeGestureHandler.usePanGesture)(B),G=(0,_reactNativeReanimated.useAnimatedStyle)(()=>O?{opacity:k.value,transform:[{translateX:D.value}]}:{opacity:k.value,transform:[{translateY:D.value}]},[O,D,k]),Y=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:(0,_reactNativeReanimated.interpolate)(D.value,[M,0],[0,l],_reactNativeReanimated.Extrapolation.CLAMP)*k.value,pointerEvents:Math.abs(D.value-M)<.5?"none":"auto"}),[D,M,l,k]),X=(0,_react.useMemo)(()=>buildStyles(h),[h]),z=(0,_react.useCallback)(()=>{if(!c)return;const e=(0,_index2.resolveHaptic)(u,"selection");e&&(0,_index2.triggerHaptic)(e),I()},[c,I,u]),J=(0,_react.useMemo)(()=>sideLayoutOf(n,x,w),[n,x,w]),K=(0,_react.useRef)(r);return C&&(K.current=!0),K.current?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_reactNative.StyleSheet.absoluteFill,pointerEvents:"box-none",testID:f,accessibilityViewIsModal:C,children:[(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[X.backdrop,{backgroundColor:h.colors.scrim},Y],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:z,accessibilityRole:"button",accessibilityLabel:m.close,disabled:!c||!C})}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:H,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{accessibilityRole:"alert",accessibilityLabel:v??m.drawer,style:[J,{backgroundColor:h.colors.surface,...h.shadow.modal},d,G],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:X.content,children:_})})})]}):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 r=parseFloat(e);if(Number.isNaN(r))return t?280:Math.round(.4*a.height);return r/100*(t?a.width:a.height)}return t?280:Math.round(.4*a.height)},buildStyles=e=>_reactNative.StyleSheet.create({backdrop:{..._reactNative.StyleSheet.absoluteFill},content:{flex:1}});var _default=exports.default=Drawer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useFileViewerZoom=exports.ZOOM_REST=void 0;var _react=require("react"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=require("react-native-reanimated");const DOUBLE_TAP_ZOOM=2.5,ZOOM_REST=exports.ZOOM_REST=1.01,clamp=(e,a,t)=>{"worklet";return Math.min(Math.max(e,a),t)},panLimit=(e,a)=>{"worklet";return e*(a-1)/2},useFileViewerZoom=({zoomEnabled:e,maxZoom:a,viewportWidth:t,viewportHeight:i,maxScroll:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useFileViewerZoom=exports.ZOOM_REST=void 0;var _react=require("react"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=require("react-native-reanimated"),_reactNativeWorklets=require("react-native-worklets");const DOUBLE_TAP_ZOOM=2.5,ZOOM_REST=exports.ZOOM_REST=1.01,clamp=(e,a,t)=>{"worklet";return Math.min(Math.max(e,a),t)},panLimit=(e,a)=>{"worklet";return e*(a-1)/2},useFileViewerZoom=({zoomEnabled:e,maxZoom:a,viewportWidth:t,viewportHeight:i,maxScroll:l})=>{const[u,r]=(0,_react.useState)(1),v=(0,_reactNativeReanimated.useAnimatedRef)(),n=(0,_reactNativeReanimated.useScrollViewOffset)(v),c=(0,_reactNativeReanimated.useSharedValue)(0),s=(0,_reactNativeReanimated.useSharedValue)(0),o=(0,_reactNativeReanimated.useSharedValue)(0),m=(0,_reactNativeReanimated.useSharedValue)(0),d=(0,_reactNativeReanimated.useSharedValue)(1),_=(0,_reactNativeReanimated.useSharedValue)(1),N=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),R=(0,_reactNativeReanimated.useSharedValue)(0),w=(0,_reactNativeReanimated.useSharedValue)(0);(0,_react.useEffect)(()=>{o.value=t,m.value=i,s.value=l},[t,i,l,o,m,s]);const p=(0,_react.useCallback)(()=>{d.value=(0,_reactNativeReanimated.withTiming)(1),N.value=(0,_reactNativeReanimated.withTiming)(0),h.value=(0,_reactNativeReanimated.withTiming)(0),_.value=1,R.value=0,w.value=0,r(1)},[d,_,N,h,R,w]);(0,_react.useEffect)(()=>{e||p()},[e,p]);const T=(0,_react.useCallback)(e=>r(e),[]),S=(0,_reactNativeGestureHandler.useNativeGesture)(),O=Math.max(1,a),M=Math.min(2.5,O),f=(0,_react.useMemo)(()=>({enabled:e,simultaneousWith:S,onActivate:()=>{"worklet";_.value=d.value,R.value=N.value,w.value=h.value},onUpdate:e=>{"worklet";const a=clamp(_.value*e.scale,1,O),t=e.focalX-o.value/2,i=e.focalY-m.value/2,l=a/_.value,u=panLimit(o.value,a),r=panLimit(m.value,a);N.value=clamp(t-(t-R.value)*l,-u,u),h.value=clamp(i-(i-w.value)*l,-r,r),d.value=a},onDeactivate:()=>{"worklet";if(d.value<=ZOOM_REST)return d.value=(0,_reactNativeReanimated.withTiming)(1),N.value=(0,_reactNativeReanimated.withTiming)(0),h.value=(0,_reactNativeReanimated.withTiming)(0),_.value=1,R.value=0,w.value=0,void(0,_reactNativeWorklets.scheduleOnRN)(T,1);_.value=d.value,R.value=N.value,w.value=h.value,(0,_reactNativeWorklets.scheduleOnRN)(T,d.value)}}),[e,O,T,S,d,_,N,h,R,w,o,m]),g=(0,_react.useMemo)(()=>({enabled:e,simultaneousWith:S,minPointers:1,maxPointers:1,manualActivation:!0,onTouchesMove:e=>{"worklet";d.value>ZOOM_REST?_reactNativeGestureHandler.GestureStateManager.activate(e.handlerTag):_reactNativeGestureHandler.GestureStateManager.fail(e.handlerTag)},onActivate:()=>{"worklet";R.value=N.value,w.value=h.value,c.value=n.value},onUpdate:e=>{"worklet";const a=d.value,t=panLimit(o.value,a),i=panLimit(m.value,a);N.value=clamp(R.value+e.translationX,-t,t);const l=w.value+e.translationY,u=clamp(l,-i,i),r=l-u;if(0!==r){const e=clamp(c.value-r/a,0,s.value);e!==c.value&&(c.value=e,(0,_reactNativeReanimated.scrollTo)(v,0,e,!1)),w.value-=r}h.value=u},onDeactivate:()=>{"worklet";R.value=N.value,w.value=h.value}}),[e,S,n,c,s,o,m,d,N,h,R,w,v]),k=(0,_react.useMemo)(()=>({enabled:e,simultaneousWith:S,numberOfTaps:2,maxDistance:10,onDeactivate:e=>{"worklet";if(d.value>ZOOM_REST)return d.value=(0,_reactNativeReanimated.withTiming)(1),N.value=(0,_reactNativeReanimated.withTiming)(0),h.value=(0,_reactNativeReanimated.withTiming)(0),_.value=1,R.value=0,w.value=0,void(0,_reactNativeWorklets.scheduleOnRN)(T,1);if(M<=ZOOM_REST)return;const a=e.x-o.value/2,t=e.y-m.value/2,i=panLimit(o.value,M),l=panLimit(m.value,M),u=clamp(-a*(M-1),-i,i),r=clamp(-t*(M-1),-l,l);d.value=(0,_reactNativeReanimated.withTiming)(M),N.value=(0,_reactNativeReanimated.withTiming)(u),h.value=(0,_reactNativeReanimated.withTiming)(r),_.value=M,R.value=u,w.value=r,(0,_reactNativeWorklets.scheduleOnRN)(T,M)}}),[e,S,M,T,d,_,N,h,R,w,o,m]),G=(0,_reactNativeGestureHandler.usePinchGesture)(f),V=(0,_reactNativeGestureHandler.usePanGesture)(g),Z=(0,_reactNativeGestureHandler.useTapGesture)(k),x=(0,_reactNativeGestureHandler.useSimultaneousGestures)(G,V,Z),E=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:N.value},{translateY:h.value},{scale:d.value}]}),[N,h,d]);return{scrollRef:v,scrollGesture:S,zoomGesture:x,zoomStyle:E,zoomLevel:u,resetZoom:p}};exports.useFileViewerZoom=useFileViewerZoom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ImageGallery=exports.DEFAULT_IMAGE_GALLERY_LABELS=void 0;var cache,_react=_interopRequireWildcard(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"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Carousel/index.js"),_Modal=require("../Modal/Modal.js"),_index4=require("../Skeleton/index.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,a){if(!a&&e&&e.__esModule)return e;var t,i,l=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)&&((t=l&&Object.getOwnPropertyDescriptor(e,i))&&(t.get||t.set)?l(r,i,t):r[i]=e[i]);return r}const DEFAULT_IMAGE_GALLERY_LABELS=exports.DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,a)=>`Image ${e} of ${a}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"},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:a=0,showThumbnails:t=!0,showCounter:i=!0,enableLightbox:l=!0,enablePinchZoom:r=!0,onIndexChange:n,haptic:s,loading:o=!1,accessibilityLabel:c,containerStyle:u,testID:d,labels:m})=>{const _=(0,_index.useTheme)(),h=(0,_react.useMemo)(()=>buildStyles(_),[_]),g=(0,_react.useMemo)(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...m}),[m]),[v,x]=(0,_react.useState)(clamp(a,0,Math.max(0,e.length-1))),[p,b]=(0,_react.useState)(!1),y=(0,_react.useCallback)(e=>{x(e),n?.(e)},[n]),R=(0,_react.useCallback)(()=>{if(!l)return;const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!0)},[l,s]),S=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!1)},[s]),I=(0,_react.useCallback)((a,t)=>{const i=a.alt??g.imageOf(t+1,e.length);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:R,accessibilityRole:"image",accessibilityLabel:i,accessibilityHint:l?g.openFullscreen:void 0,style:h.imageWrap,children:(0,_jsxRuntime.jsx)(_reactNative.Image,{source:a.source,style:h.image,resizeMode:"cover"})})},[l,e.length,R,h,g]),N=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNative.Image,{source:e.source,style:h.thumbnailImage,resizeMode:"cover"}),[h]),j=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[h.container,u],testID:d,accessibilityLabel:c??g.gallery,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:h.carouselWrap,accessibilityElementsHidden:p,importantForAccessibility:p?"no-hide-descendants":"auto",children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{data:e,defaultIndex:a,onIndexChange:y,renderItem:I,showPagination:!1,showThumbnails:t,renderThumbnail:N,haptic:s}),i&&e.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:h.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"label",weight:"semibold",style:{color:_.colors["on-scrim"]},accessibilityLabel:g.imageOf(v+1,e.length),children:`${v+1} / ${e.length}`})}):null]}),l?(0,_jsxRuntime.jsx)(Lightbox,{open:p,images:e,initialIndex:v,enablePinchZoom:r,showCounter:i,onClose:S,onIndexChange:y,haptic:s,labels:g}):null]});return o?(0,_jsxRuntime.jsx)(ImageGallerySkeleton,{images:e,showThumbnails:t,showCounter:i,containerStyle:u,testID:d}):j};exports.ImageGallery=ImageGallery,ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:a=!0,showCounter:t=!0,containerStyle:i,testID:l})=>{const r=(0,_index.useTheme)(),n=Math.min(e?.length||4,6),s=(0,_react.useMemo)(()=>Array.from({length:n},(e,a)=>({key:`sk-thumb-${a}`})),[n]);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{width:"100%"},i],testID:l,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{position:"relative"},children:[(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:"100%",height:280,radius:"lg"}),t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:"absolute",top:12,right:12},children:(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:44,height:22,radius:"pill"})}):null]}),a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",marginTop:r.space.md},children:s.map(e=>(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:64,height:64,radius:"md",style:{marginRight:r.space.sm}},e.key))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:a,initialIndex:t,enablePinchZoom:i,showCounter:l,onClose:r,onIndexChange:n,haptic:s,labels:o})=>{const c=(0,_index.useTheme)(),u=(0,_react.useMemo)(()=>buildLightboxStyles(c),[c]),d=(0,_react.useRef)(null),[m,_]=(0,_react.useState)(t),h=(0,_react.useCallback)(e=>{if(e!==m){const a=(0,_index2.resolveHaptic)(s,"selection");a&&(0,_index2.triggerHaptic)(a),_(e),n(e)}},[m,n,s]),g=(0,_react.useCallback)((e,t)=>(0,_jsxRuntime.jsx)(ZoomableImage,{image:e,index:t,total:a.length,active:t===m,enabled:i,maxScale:4,minScale:1,doubleTapScale:2,haptic:s,imageLabel:o.imageOf}),[m,i,a.length,s,o]),v=a[m]?.caption;return(0,_jsxRuntime.jsx)(_Modal.Modal,{open:e,onClose:r,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:u.backdrop,children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{ref:d,data:a,defaultIndex:t,onIndexChange:h,renderItem:g,showPagination:!1,haptic:s}),l&&a.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:u.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"label",weight:"semibold",style:{color:c.colors["on-scrim"]},accessibilityLabel:o.imageOf(m+1,a.length),children:`${m+1} / ${a.length}`})}):null,(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:r,accessibilityRole:"button",accessibilityLabel:o.closeGallery,style:u.closeButton,hitSlop:12,...(0,_hitSlop.hitSlopMarker)(12),children:(c.settings.icons.close??_defaultIcons.defaultIcons.close)({size:24,color:c.colors["on-scrim"]})}),v?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:u.captionWrap,accessibilityElementsHidden:!1,children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",align:"center",numberOfLines:3,style:u.captionText,children:v})}):null]})})},ZoomableImage=({image:e,index:a,total:t,active:i,enabled:l,maxScale:r,minScale:n,doubleTapScale:s,haptic:o,imageLabel:c})=>{const u=_reactNative.Dimensions.get("window"),d=(0,_reactNativeReanimated.useSharedValue)(1),m=(0,_reactNativeReanimated.useSharedValue)(1),_=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),g=(0,_reactNativeReanimated.useSharedValue)(0),v=(0,_reactNativeReanimated.useSharedValue)(0),x=(0,_react.useCallback)(()=>{d.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),m.value=1,_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),g.value=0,v.value=0},[d,m,_,h,g,v]);_react.default.useEffect(()=>{i||(d.value=(0,_reactNativeReanimated.withTiming)(1,{duration:150}),_.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),h.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),m.value=1,g.value=0,v.value=0)},[i,d,_,h,m,g,v]);const p=(0,_react.useCallback)(()=>{!1!==o&&(0,_index2.triggerHaptic)("impactLight")},[o]),b=(0,_react.useMemo)(()=>({enabled:l,onActivate:()=>{"worklet";m.value=d.value},onUpdate:e=>{"worklet";const a=m.value*e.scale;d.value=a<n?n+.3*(a-n):a>r?r+.2*(a-r):a},onDeactivate:()=>{"worklet";return d.value<n?(d.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),m.value=n,g.value=0,void(v.value=0)):d.value>r?(d.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),void(m.value=r)):void(m.value=d.value)}}),[l,d,m,_,h,g,v,n,r]),y=(0,_reactNativeGestureHandler.usePinchGesture)(b),R=(0,_react.useMemo)(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";g.value=_.value,v.value=h.value},onUpdate:e=>{"worklet";d.value<=1||(_.value=g.value+e.translationX,h.value=v.value+e.translationY)},onDeactivate:()=>{"worklet";g.value=_.value,v.value=h.value}}),[d,_,h,g,v]),S=(0,_reactNativeGestureHandler.usePanGesture)(R),I=(0,_react.useMemo)(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(p)(),d.value>1?(d.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),m.value=1,g.value=0,v.value=0):(d.value=(0,_reactNativeReanimated.withSpring)(s,SPRING_CONFIG),m.value=s)}}),[d,m,_,h,g,v,p,s]),N=(0,_reactNativeGestureHandler.useTapGesture)(I),j=(0,_reactNativeGestureHandler.useCompetingGestures)(y,S,N),w=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:_.value},{translateY:h.value},{scale:d.value}]}),[_,h,d]);_react.default.useEffect(()=>{i||x()},[i,x]);const C=e.alt??c(a+1,t);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:j,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[lightboxImageStyles.container,{width:u.width}],children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,w],accessibilityLabel:C,accessible:!0})})})},clamp=(e,a,t)=>Math.min(Math.max(e,a),t),buildStyles=e=>_reactNative.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,..._corners.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,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>_reactNative.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,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"]}}),lightboxImageStyles=_reactNative.StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});var _default=exports.default=ImageGallery;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ImageGallery=exports.DEFAULT_IMAGE_GALLERY_LABELS=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeWorklets=require("react-native-worklets"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Carousel/index.js"),_Modal=require("../Modal/Modal.js"),_index4=require("../Skeleton/index.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,l=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=l&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?l(r,i,a):r[i]=e[i]);return r}const DEFAULT_IMAGE_GALLERY_LABELS=exports.DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"},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:i=!0,enableLightbox:l=!0,enablePinchZoom:r=!0,onIndexChange:n,haptic:s,loading:o=!1,accessibilityLabel:c,containerStyle:u,testID:d,labels:m})=>{const _=(0,_index.useTheme)(),h=(0,_react.useMemo)(()=>buildStyles(_),[_]),g=(0,_react.useMemo)(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...m}),[m]),[v,x]=(0,_react.useState)(clamp(t,0,Math.max(0,e.length-1))),[p,b]=(0,_react.useState)(!1),y=(0,_react.useCallback)(e=>{x(e),n?.(e)},[n]),R=(0,_react.useCallback)(()=>{if(!l)return;const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!0)},[l,s]),S=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!1)},[s]),N=(0,_react.useCallback)((t,a)=>{const i=t.alt??g.imageOf(a+1,e.length);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:R,accessibilityRole:"image",accessibilityLabel:i,accessibilityHint:l?g.openFullscreen:void 0,style:h.imageWrap,children:(0,_jsxRuntime.jsx)(_reactNative.Image,{source:t.source,style:h.image,resizeMode:"cover"})})},[l,e.length,R,h,g]),I=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNative.Image,{source:e.source,style:h.thumbnailImage,resizeMode:"cover"}),[h]),j=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[h.container,u],testID:d,accessibilityLabel:c??g.gallery,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:h.carouselWrap,accessibilityElementsHidden:p,importantForAccessibility:p?"no-hide-descendants":"auto",children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{data:e,defaultIndex:t,onIndexChange:y,renderItem:N,showPagination:!1,showThumbnails:a,renderThumbnail:I,haptic:s}),i&&e.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:h.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"label",weight:"semibold",style:{color:_.colors["on-scrim"]},accessibilityLabel:g.imageOf(v+1,e.length),children:`${v+1} / ${e.length}`})}):null]}),l?(0,_jsxRuntime.jsx)(Lightbox,{open:p,images:e,initialIndex:v,enablePinchZoom:r,showCounter:i,onClose:S,onIndexChange:y,haptic:s,labels:g}):null]});return o?(0,_jsxRuntime.jsx)(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:i,containerStyle:u,testID:d}):j};exports.ImageGallery=ImageGallery,ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:i,testID:l})=>{const r=(0,_index.useTheme)(),n=Math.min(e?.length||4,6),s=(0,_react.useMemo)(()=>Array.from({length:n},(e,t)=>({key:`sk-thumb-${t}`})),[n]);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{width:"100%"},i],testID:l,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{position:"relative"},children:[(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:"100%",height:280,radius:"lg"}),a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:"absolute",top:12,right:12},children:(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",marginTop:r.space.md},children:s.map(e=>(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:64,height:64,radius:"md",style:{marginRight:r.space.sm}},e.key))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:i,showCounter:l,onClose:r,onIndexChange:n,haptic:s,labels:o})=>{const c=(0,_index.useTheme)(),u=(0,_react.useMemo)(()=>buildLightboxStyles(c),[c]),d=(0,_react.useRef)(null),[m,_]=(0,_react.useState)(a),h=(0,_react.useCallback)(e=>{if(e!==m){const t=(0,_index2.resolveHaptic)(s,"selection");t&&(0,_index2.triggerHaptic)(t),_(e),n(e)}},[m,n,s]),g=(0,_react.useCallback)((e,a)=>(0,_jsxRuntime.jsx)(ZoomableImage,{image:e,index:a,total:t.length,active:a===m,enabled:i,maxScale:4,minScale:1,doubleTapScale:2,haptic:s,imageLabel:o.imageOf}),[m,i,t.length,s,o]),v=t[m]?.caption;return(0,_jsxRuntime.jsx)(_Modal.Modal,{open:e,onClose:r,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:u.backdrop,children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{ref:d,data:t,defaultIndex:a,onIndexChange:h,renderItem:g,showPagination:!1,haptic:s}),l&&t.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:u.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"label",weight:"semibold",style:{color:c.colors["on-scrim"]},accessibilityLabel:o.imageOf(m+1,t.length),children:`${m+1} / ${t.length}`})}):null,(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:r,accessibilityRole:"button",accessibilityLabel:o.closeGallery,style:u.closeButton,hitSlop:12,...(0,_hitSlop.hitSlopMarker)(12),children:(c.settings.icons.close??_defaultIcons.defaultIcons.close)({size:24,color:c.colors["on-scrim"]})}),v?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:u.captionWrap,accessibilityElementsHidden:!1,children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",align:"center",numberOfLines:3,style:u.captionText,children:v})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:i,enabled:l,maxScale:r,minScale:n,doubleTapScale:s,haptic:o,imageLabel:c})=>{const u=_reactNative.Dimensions.get("window"),d=(0,_reactNativeReanimated.useSharedValue)(1),m=(0,_reactNativeReanimated.useSharedValue)(1),_=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),g=(0,_reactNativeReanimated.useSharedValue)(0),v=(0,_reactNativeReanimated.useSharedValue)(0),x=(0,_react.useCallback)(()=>{d.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),m.value=1,_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),g.value=0,v.value=0},[d,m,_,h,g,v]);_react.default.useEffect(()=>{i||(d.value=(0,_reactNativeReanimated.withTiming)(1,{duration:150}),_.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),h.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),m.value=1,g.value=0,v.value=0)},[i,d,_,h,m,g,v]);const p=(0,_react.useCallback)(()=>{!1!==o&&(0,_index2.triggerHaptic)("impactLight")},[o]),b=(0,_react.useMemo)(()=>({enabled:l,onActivate:()=>{"worklet";m.value=d.value},onUpdate:e=>{"worklet";const t=m.value*e.scale;d.value=t<n?n+.3*(t-n):t>r?r+.2*(t-r):t},onDeactivate:()=>{"worklet";return d.value<n?(d.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),m.value=n,g.value=0,void(v.value=0)):d.value>r?(d.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),void(m.value=r)):void(m.value=d.value)}}),[l,d,m,_,h,g,v,n,r]),y=(0,_reactNativeGestureHandler.usePinchGesture)(b),R=(0,_react.useMemo)(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";g.value=_.value,v.value=h.value},onUpdate:e=>{"worklet";d.value<=1||(_.value=g.value+e.translationX,h.value=v.value+e.translationY)},onDeactivate:()=>{"worklet";g.value=_.value,v.value=h.value}}),[d,_,h,g,v]),S=(0,_reactNativeGestureHandler.usePanGesture)(R),N=(0,_react.useMemo)(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";(0,_reactNativeWorklets.scheduleOnRN)(p),d.value>1?(d.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),m.value=1,g.value=0,v.value=0):(d.value=(0,_reactNativeReanimated.withSpring)(s,SPRING_CONFIG),m.value=s)}}),[d,m,_,h,g,v,p,s]),I=(0,_reactNativeGestureHandler.useTapGesture)(N),j=(0,_reactNativeGestureHandler.useCompetingGestures)(y,S,I),w=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:_.value},{translateY:h.value},{scale:d.value}]}),[_,h,d]);_react.default.useEffect(()=>{i||x()},[i,x]);const C=e.alt??c(t+1,a);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:j,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[lightboxImageStyles.container,{width:u.width}],children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,w],accessibilityLabel:C,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>_reactNative.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,..._corners.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,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>_reactNative.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,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"]}}),lightboxImageStyles=_reactNative.StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});var _default=exports.default=ImageGallery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.NonModalBottomSheet=exports.DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,n=Object.defineProperty,i={__proto__:null,default:e};if(Object(e)!==e)return i;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,i)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=n&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?n(i,r,a):i[r]=e[r]);return i}const DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=exports.DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=Object.freeze({dragHandle:"Drag handle"}),ERROR_PREFIX="[@webority/mobile-ui] NonModalBottomSheet: ",SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,OVERSHOOT_TO_CLOSE=80,PERCENT_PATTERN=/^(\d+(?:\.\d+)?|\.\d+)%$/,parsePercent=e=>{if("string"!=typeof e)return;const t=PERCENT_PATTERN.exec(e);if(!t)return;const a=Number(t[1]);return a>0&&a<=100?a:void 0},isValidSnapPoint=e=>"number"==typeof e?Number.isFinite(e)&&e>0:void 0!==parsePercent(e),validateProps=(e,t)=>{if(0===e.length)throw new Error(`${ERROR_PREFIX}snapPoints needs at least one snap point.`);for(const t of e)if(!isValidSnapPoint(t))throw new Error(`${ERROR_PREFIX}snap point ${String(t)} is not a positive number or a percentage up to 100%.`);if(null!=t&&(!Number.isInteger(t)||t<0||t>=e.length))throw new Error(`${ERROR_PREFIX}snapIndex ${t} is outside the snap points.`)},resolveNonModalSnapPoints=(e,t)=>e.map(e=>"number"==typeof e?e:parseFloat(e)/100*t).sort((e,t)=>e-t),topAt=(e,t,a)=>{const r=e[a];if(void 0===r)throw new Error(`${ERROR_PREFIX}snap index ${a} has no snap point.`);return Math.max(0,t-r)},NonModalBottomSheet=e=>{const{open:t,onClose:a,snapPoints:r,snapIndex:n,onSnapChange:i,enablePanDownToClose:o=!0,scrollable:s=!1,title:c,header:l,footer:u,labels:d,handleIndicatorStyle:_,containerStyle:h,children:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.NonModalBottomSheet=exports.DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeWorklets=require("react-native-worklets"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,n=Object.defineProperty,i={__proto__:null,default:e};if(Object(e)!==e)return i;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,i)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=n&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?n(i,r,a):i[r]=e[r]);return i}const DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=exports.DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=Object.freeze({dragHandle:"Drag handle"}),ERROR_PREFIX="[@webority/mobile-ui] NonModalBottomSheet: ",SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,OVERSHOOT_TO_CLOSE=80,PERCENT_PATTERN=/^(\d+(?:\.\d+)?|\.\d+)%$/,parsePercent=e=>{if("string"!=typeof e)return;const t=PERCENT_PATTERN.exec(e);if(!t)return;const a=Number(t[1]);return a>0&&a<=100?a:void 0},isValidSnapPoint=e=>"number"==typeof e?Number.isFinite(e)&&e>0:void 0!==parsePercent(e),validateProps=(e,t)=>{if(0===e.length)throw new Error(`${ERROR_PREFIX}snapPoints needs at least one snap point.`);for(const t of e)if(!isValidSnapPoint(t))throw new Error(`${ERROR_PREFIX}snap point ${String(t)} is not a positive number or a percentage up to 100%.`);if(null!=t&&(!Number.isInteger(t)||t<0||t>=e.length))throw new Error(`${ERROR_PREFIX}snapIndex ${t} is outside the snap points.`)},resolveNonModalSnapPoints=(e,t)=>e.map(e=>"number"==typeof e?e:parseFloat(e)/100*t).sort((e,t)=>e-t),topAt=(e,t,a)=>{const r=e[a];if(void 0===r)throw new Error(`${ERROR_PREFIX}snap index ${a} has no snap point.`);return Math.max(0,t-r)},NonModalBottomSheet=e=>{const{open:t,onClose:a,snapPoints:r,snapIndex:n,onSnapChange:i,enablePanDownToClose:o=!0,scrollable:s=!1,title:c,header:l,footer:u,labels:d,handleIndicatorStyle:_,containerStyle:h,children:v,accessibilityLabel:m,testID:p}=e;validateProps(r,n);const f=(0,_react.useMemo)(()=>({...DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS,...d}),[d]),R=(0,_index.useTheme)(),N=(0,_usePresenceMotion.usePresenceMotion)(),E=N.reduced,b=(0,_react.useMemo)(()=>buildStyles(R),[R]),[x,S]=(0,_react.useState)(()=>_reactNative.Dimensions.get("window").height),O=(0,_react.useCallback)(e=>{const t=e.nativeEvent.layout.height;t>0&&S(t)},[]),g=(0,_react.useMemo)(()=>resolveNonModalSnapPoints(r,x),[r,x]),M=g[g.length-1]??0,y=x,w=Math.max(0,x-M),T=(0,_react.useCallback)(e=>topAt(g,x,e),[g,x]),[P,j]=(0,_react.useState)(!1),[C,A]=(0,_react.useState)(-1),I=(0,_react.useRef)(-1),L=(0,_react.useRef)(a);L.current=a;const k=(0,_react.useRef)(i);k.current=i;const D=(0,_reactNativeReanimated.useSharedValue)(y),B=(0,_reactNativeReanimated.useSharedValue)(y),F=(0,_react.useCallback)(()=>{I.current<0&&j(!1)},[]),V=(0,_react.useCallback)(()=>{if(I.current=-1,A(-1),E)return D.value=y,void F();D.value=(0,_reactNativeReanimated.withTiming)(y,{duration:N.duration("fast"),easing:_reactNativeReanimated.Easing.bezier(...R.motion.ease.accelerate),reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(0,_reactNativeWorklets.scheduleOnRN)(F)})},[y,N,E,R.motion.ease.accelerate,D,F]),H=(0,_react.useCallback)(e=>{const t=T(e);D.value=E?t:(0,_reactNativeReanimated.withSpring)(t,SPRING_CONFIG)},[E,T,D]),q=(0,_react.useCallback)((e,t)=>{e!==I.current&&(I.current=e,A(e),H(e),t&&k.current?.(e))},[H]),$=(0,_react.useEffectEvent)(e=>{if(!e)return void(I.current>=0&&V());const t=n??0;j(!0);const a=T(t);E?D.value=a:(D.value=y,D.value=(0,_reactNativeReanimated.withSpring)(a,SPRING_CONFIG)),I.current=t,A(t)});(0,_react.useEffect)(()=>{$(t)},[t]);const G=(0,_react.useEffectEvent)(e=>{t&&P&&e!==I.current&&q(e,!1)});(0,_react.useEffect)(()=>{null!=n&&G(n)},[n]);const W=(0,_react.useEffectEvent)(e=>{const t=I.current;t>=0&&(D.value=topAt(g,e,t))});(0,_react.useEffect)(()=>{W(x)},[x]);const U=(0,_react.useCallback)(e=>{if(e<0)return(0,_index2.triggerHaptic)("selection"),V(),void L.current();e!==I.current?q(e,!0):H(e)},[q,H,V]),X=(0,_react.useCallback)(e=>{const t=I.current;t<0||q(Math.min(Math.max(t+e,0),g.length-1),!0)},[q,g.length]),Y=(0,_react.useMemo)(()=>g.map(e=>x-e),[g,x]),z=(0,_react.useMemo)(()=>{const e=Y,t=w,a=o;return{testID:p?`${p}-pan-gesture`:"non-modal-bottom-sheet-pan-gesture",activeOffsetY:[-10,10],onActivate:()=>{"worklet";B.value=D.value},onUpdate:e=>{"worklet";const a=B.value+e.translationY;D.value=a<t?t+.25*(a-t):a},onDeactivate:t=>{"worklet";const r=D.value,n=e[0];if(void 0===n)return;if(t.velocityY>1e3)return void(0,_reactNativeWorklets.scheduleOnRN)(U,a?-1:0);if(a&&r-n>80)return void(0,_reactNativeWorklets.scheduleOnRN)(U,-1);let i=0,o=1/0,s=0;for(const t of e){const e=Math.abs(r-t);e<o&&(o=e,i=s),s++}(0,_reactNativeWorklets.scheduleOnRN)(U,i)}}},[B,o,U,w,Y,p,D]),J=(0,_reactNativeGestureHandler.usePanGesture)(z),K=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({top:Math.max(D.value,w)}),[w]),Q=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=Math.max(D.value,w),t=x-e;return{height:Math.max(0,Math.min(t,M))}},[x,M,w]);return P?(0,_jsxRuntime.jsx)(_reactNative.View,{collapsable:!1,style:_reactNative.StyleSheet.absoluteFill,pointerEvents:"box-none",onLayout:O,testID:p,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{accessibilityLabel:m,testID:p?`${p}-sheet`:void 0,style:[b.sheet,{height:M,backgroundColor:R.colors.surface,borderTopLeftRadius:R.radius.xl,borderTopRightRadius:R.radius.xl,..._corners.smoothCorners,...R.shadow.modal},h,K],children:(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[b.body,Q],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:J,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:b.handleRow,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:f.dragHandle,accessibilityHint:"Swipe up or down to change the height of the sheet",accessibilityValue:{text:`Snap point ${C+1} of ${g.length}`},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName?X(1):"decrement"===e.nativeEvent.actionName&&X(-1)},testID:p?`${p}-handle`:void 0,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[b.handle,{backgroundColor:R.colors.border},_]})})}),null!=c?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",accessibilityRole:"header",children:c}):null,l,s?(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{style:b.scrollContent,children:v}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:b.content,children:v}),u]})})}):null};exports.NonModalBottomSheet=NonModalBottomSheet,NonModalBottomSheet.displayName="NonModalBottomSheet";const buildStyles=e=>_reactNative.StyleSheet.create({sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},handle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1}});var _default=exports.default=NonModalBottomSheet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseE164=exports.formatE164=exports.default=exports.PhoneNumberInput=exports.DEFAULT_PHONE_NUMBER_INPUT_LABELS=exports.DEFAULT_CALLING_CODES=exports.ALL_CALLING_CODES=void 0;var _mobileCore=require("@webority/mobile-core"),_countries=require("@webority/mobile-core/phone/countries"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_index4=require("../FieldBase/index.js"),_Chevron=require("../FieldBase/Chevron.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_PHONE_NUMBER_INPUT_LABELS=exports.DEFAULT_PHONE_NUMBER_INPUT_LABELS=Object.freeze({placeholder:"Phone number",popular:"Popular",allCountries:"All countries",countrySheetTitle:"Country code",countrySearchPlaceholder:"Search…",invalid:"Enter a valid number",invalidMobile:"Enter a valid mobile number",countryButton:e=>`Country code, currently +${e}`}),DEFAULT_CALLING_CODES=exports.DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}],ALL_CALLING_CODES=exports.ALL_CALLING_CODES=(0,_mobileCore.getPhoneCountries)().map(e=>({iso:e.iso,code:e.callingCode,label:_countries.PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label)),digitsOnly=e=>e.replace(/[^0-9]/g,""),formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;exports.formatE164=formatE164;const parseE164=(e,t,i)=>{const o=e.replace(/[^0-9]/g,"");if(!o)return null;const n=(0,_mobileCore.splitPhoneNumber)(`+${o}`);let r=n?.callingCode,l=n?.nationalNumber??"";if(!r){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(r=e.find(e=>o.startsWith(e)),!r)return null;l=o.slice(r.length)}const a=t.filter(e=>e.code===r),s=a.find(e=>e.iso===i)?.iso??a.find(e=>e.iso===n?.country)?.iso??n?.country??a[0]?.iso??"";return{callingCode:r,nationalNumber:l,iso:s}};exports.parseE164=parseE164;const planOf=e=>(0,_mobileCore.isSupportedCountry)(e)?e:null,assertDefaultCountryVisible=(e,t)=>{if(void 0!==e&&!t.some(t=>t.iso===e))throw new RangeError(`PhoneNumberInput: defaultCountry "${e}" is not among the visible countries. Add it to countries, or remove it from hiddenCountries.`)},PhoneNumberInput=exports.PhoneNumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:o,onChange:n,e164:r,onChangeE164:l,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,blurOnSubmit:c,onComplete:d,onValidityChange:b,countries:p=ALL_CALLING_CODES,popularCountries:_,hiddenCountries:m,showFlag:h=!0,renderFlag:f,renderCountry:g,showAlphabetIndex:x,defaultCountry:C,validation:N="any",maxLength:y,formatAsYouType:v=!0,countryLocked:S=!1,label:E,labelMode:L="top",labelStyle:I,placeholder:T,helperText:j,error:P,invalidMessage:A,required:F,disabled:O=!1,size:V="md",variant:R,radius:D,labels:M,haptic:U,accessibilityLabel:B,countryAccessibilityLabel:q,onFocus:w,onBlur:z,style:k,testID:$}=e;(0,_assertValidValue.assertValidValue)("PhoneNumberInput","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const G=(0,_index2.useTheme)(),H=(0,_react.useMemo)(()=>buildStyles(G),[G]),W=(0,_react.useRef)(null),Y=(0,_react.useMemo)(()=>M?{...DEFAULT_PHONE_NUMBER_INPUT_LABELS,...M}:DEFAULT_PHONE_NUMBER_INPUT_LABELS,[M]),K=T??Y.placeholder,Z=(0,_react.useMemo)(()=>/-([A-Za-z]{2})(?:-|$)/.exec((0,_mobileCore.getFormatterConfig)().locale)?.[1]?.toUpperCase(),[]),J=(0,_react.useMemo)(()=>m?.length?p.filter(e=>!m.includes(e.iso)):p,[p,m]),Q=(0,_react.useMemo)(()=>{if(!_?.length)return;const e=_.map(e=>J.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:Y.popular,options:e},{title:Y.allCountries,options:J}]:void 0},[_,Y.popular,Y.allCountries,J]),X=(0,_react.useCallback)((e,t,i)=>{if(!e)return null;if(f)return f(e);if(!h)return null;const o=(0,_mobileCore.countryFlagEmoji)(e.iso);return o?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",style:[H.flag,{fontSize:t}],testID:i,children:o}):null},[f,h,H.flag]),ee=(0,_react.useCallback)(e=>{const t=planOf(e),i=t?(0,_mobileCore.maxNationalNumberLength)(t,!1===N?"any":N):Number.POSITIVE_INFINITY;return y?Math.min(i,y):i},[y,N]),te=(0,_react.useCallback)((e,t)=>e.slice(0,ee(t)),[ee]),ie=(0,_react.useCallback)((e,t)=>{const i=planOf(t)??void 0,o=(0,_mobileCore.splitPhoneNumber)(e,i);if(!o)return null;const n=o.country??t,r=p.find(e=>e.iso===n);return{callingCode:r?.code??o.callingCode,nationalNumber:te(o.nationalNumber,n),iso:r?.iso??n}},[p,te]);(0,_react.useState)(()=>assertDefaultCountryVisible(C,J));const oe=(0,_react.useMemo)(()=>{const e=J.find(e=>e.iso===(C??Z))??J[0]??p[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof o?ie(o,t.iso)??t:o??t},[p,J,C,Z,o,ie]),ne=(0,_react.useCallback)(e=>{if(!1===N)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?(0,_mobileCore.isValidNationalNumber)(e.nationalNumber,t,N):e.nationalNumber.length>0},[N]),[re,le]=(0,_react.useState)(oe.iso),ae=(0,_react.useMemo)(()=>{if(void 0===r)return;const e=r?parseE164(r,p,re):null;if(e)return{...e,nationalNumber:te(e.nationalNumber,e.iso)};const t=p.find(e=>e.iso===re);return{callingCode:t?.code??oe.callingCode,nationalNumber:"",iso:re}},[r,p,re,oe.callingCode,te]),se=(0,_react.useCallback)(e=>{le(e.iso),n?.(e),l?.(e.nationalNumber?formatE164(e):"",{country:p.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:ne(e)})},[n,l,p,ne]),[ue,ce]=(0,_index.useControllableState)({value:i??ae,defaultValue:oe,onChange:se}),[de,be]=(0,_react.useState)(!1),pe=(0,_react.useCallback)(()=>{O||W.current?.focus()},[O]),[me,he]=(0,_react.useState)(!1),[fe,ge]=(0,_react.useState)(!1),[xe,Ce]=(0,_react.useState)(!1),Ne=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{xe||(Ne.current=!1)},[xe]);const ye=(0,_index2.resolveFieldSize)(G,V),ve=(0,_index4.resolveFieldTextStyle)(G,{disabled:O}),Se=R??G.settings.components.field?.defaultVariant??"outline",Ee="underline"===Se,Le=G.space.md,[Ie,Te]=(0,_react.useState)(0),je=Ie+Le+1+Le,Pe=ue.nationalNumber.length>0,Ae=F&&!E&&!Pe&&K.length>0,Fe=de||Pe,Oe=Boolean(E)&&"float"===L&&Ie>0,Ve=(0,_useFloatingLabel.useFloatingLabel)({label:E,enabled:Oe,floated:Fe,required:F,variant:Se,sizeTokens:ye,leadingOffset:je,paddingLeft:Ee?G.space.none:ye["padding-x"],color:G.colors["field-label"],style:I}),Re=(0,_react.useMemo)(()=>p.find(e=>e.iso===ue.iso),[p,ue.iso]),De=planOf(ue.iso),Me=v&&De?(0,_mobileCore.formatPhoneAsTyped)(ue.nationalNumber,De):ue.nationalNumber,Ue=ee(ue.iso),Be=0===ue.nationalNumber.length||me||!Number.isFinite(Ue)?void 0:Me.length+Math.max(0,Ue-ue.nationalNumber.length),qe=ne(ue);(0,_react.useEffect)(()=>{Pe||ge(!1)},[Pe]);const we=De?(0,_mobileCore.maxNationalNumberLength)(De,!1===N?"any":N):Number.POSITIVE_INFINITY,ze=ue.nationalNumber.length>=we,ke=!1!==N&&!1!==A&&Pe&&!qe&&(fe||ze),$e="mobile"===N?Y.invalidMobile:Y.invalid,Ge=(0,_index4.hasFieldText)(P)?P:ke?A||$e:void 0,He=!0===P||(0,_index4.hasFieldText)(Ge),We=(0,_react.useRef)(qe),Ye=(0,_react.useRef)(ue);Ye.current=ue,(0,_react.useEffect)(()=>{We.current!==qe&&(We.current=qe,b?.(qe),qe&&d?.(formatE164(Ye.current)))},[qe,d,b]);const Ke=(0,_react.useCallback)(e=>{if(e.includes("+")){const t=ie(e,ue.iso);if(t&&!S&&J.some(e=>e.iso===t.iso))return void ce(t);if(t&&t.iso===ue.iso)return void ce(t)}ce({...ue,nationalNumber:te(digitsOnly(e),ue.iso)})},[J,S,ue,ie,te,ce]),Ze=(0,_react.useCallback)(e=>{ce({callingCode:e.code,iso:e.iso,nationalNumber:te(ue.nationalNumber,e.iso)}),Ce(!1);const t=(0,_index3.resolveHaptic)(U,"selection");t&&(0,_index3.triggerHaptic)(t)},[ue,U,te,ce]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>W.current?.focus(),blur:()=>W.current?.blur(),clear:()=>ce({...Ye.current,nationalNumber:""}),isFocused:()=>W.current?.isFocused()??!1,getValue:()=>Ye.current,getE164:()=>formatE164(Ye.current),getFormatted:()=>{const e=Ye.current,t=planOf(e.iso);return t?(0,_mobileCore.formatPhoneAsTyped)(e.nationalNumber,t):e.nationalNumber},isValid:()=>ne(Ye.current),getCountry:()=>p.find(e=>e.iso===Ye.current.iso)}),[p,ne,ce]);const Je=O||S,Qe=(0,_jsxRuntime.jsx)(_index4.FieldBase,{size:V,variant:Se,radius:D,topNotch:Ve.topNotch,focused:de,disabled:O,error:He,filled:Pe,onPress:pe,pressFeedback:!1,leadingDivider:!0,paddingLeft:Ee?G.space.none:void 0,leading:(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{Je||(Ne.current=!0,Ce(!0))},disabled:Je,accessibilityRole:"button",accessibilityLabel:q??Y.countryButton(ue.callingCode),accessibilityState:{disabled:Je},"aria-disabled":Je,hitSlop:6,...(0,_hitSlop.hitSlopMarker)(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Te(e=>e===t?e:t)},style:H.codeTrigger,testID:$?`${$}-code`:void 0,children:[X(Re,ye.text,$?`${$}-flag`:void 0),(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",style:[H.codeText,{color:ve.color,fontSize:ye.text}],children:`+${ue.callingCode}`}),S?null:(0,_jsxRuntime.jsx)(_Chevron.Chevron,{color:O?G.colors["field-icon-disabled"]:G.colors["field-icon"],size:ye.icon,open:xe})]}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:H.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:W,value:Me,maxLength:Be,onChangeText:Ke,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,blurOnSubmit:c,onSelectionChange:e=>{const{start:t,end:i}=e.nativeEvent.selection;he(t!==i)},onFocus:()=>{be(!0),w?.()},onBlur:()=>{be(!1),Pe&&!Ne.current&&ge(!0),z?.()},editable:!O,placeholder:Oe&&!Fe||Ae?void 0:K,placeholderTextColor:ve.placeholderColor,accessibilityLabel:B??E??K,selectionColor:G.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[H.input,{color:ve.color,fontSize:ye.text,...ve.weightStyle,paddingLeft:Ee?G.space.none:void 0}],testID:$?`${$}-input`:void 0}),Ae?(0,_jsxRuntime.jsx)(_index4.RequiredPlaceholder,{text:K,color:ve.placeholderColor,fontSize:ye.text,weightStyle:ve.weightStyle}):null]})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:k,testID:$,children:[E&&"top"===L?(0,_jsxRuntime.jsx)(_index4.FieldLabel,{size:V,required:F,children:E}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:H.fieldWrapper,children:[Qe,Ve.node]}),(0,_jsxRuntime.jsx)(_index4.FieldMessage,{size:V,error:He,text:He?Ge:j}),(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:xe,haptic:U,onClose:()=>Ce(!1),title:Y.countrySheetTitle,options:J,sections:Q,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>X(e,G.text.lg.size),renderOption:g?({option:e,selected:t})=>g(e,{selected:t}):void 0,value:Re?.iso,onChange:(e,t)=>Ze(t),searchable:J.length>8,labels:{searchPlaceholder:Y.countrySearchPlaceholder},alphabetIndex:x??J.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...(0,_index2.fontFor)(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});var _default=exports.default=PhoneNumberInput;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseE164=exports.formatE164=exports.default=exports.PhoneNumberInput=exports.DEFAULT_PHONE_NUMBER_INPUT_LABELS=exports.DEFAULT_CALLING_CODES=exports.ALL_CALLING_CODES=void 0;var _mobileCore=require("@webority/mobile-core"),_countries=require("@webority/mobile-core/phone/countries"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_index4=require("../FieldBase/index.js"),_Chevron=require("../FieldBase/Chevron.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_PHONE_NUMBER_INPUT_LABELS=exports.DEFAULT_PHONE_NUMBER_INPUT_LABELS=Object.freeze({placeholder:"Phone number",popular:"Popular",allCountries:"All countries",countrySheetTitle:"Country code",countrySearchPlaceholder:"Search…",invalid:"Enter a valid number",invalidMobile:"Enter a valid mobile number",countryButton:e=>`Country code, currently +${e}`}),DEFAULT_CALLING_CODES=exports.DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}],ALL_CALLING_CODES=exports.ALL_CALLING_CODES=(0,_mobileCore.getPhoneCountries)().map(e=>({iso:e.iso,code:e.callingCode,label:_countries.PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label)),digitsOnly=e=>e.replace(/[^0-9]/g,""),formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;exports.formatE164=formatE164;const parseE164=(e,t,i)=>{const o=e.replace(/[^0-9]/g,"");if(!o)return null;const n=(0,_mobileCore.splitPhoneNumber)(`+${o}`);let r=n?.callingCode,a=n?.nationalNumber??"";if(!r){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(r=e.find(e=>o.startsWith(e)),!r)return null;a=o.slice(r.length)}const l=t.filter(e=>e.code===r),s=l.find(e=>e.iso===i)?.iso??l.find(e=>e.iso===n?.country)?.iso??n?.country??l[0]?.iso??"";return{callingCode:r,nationalNumber:a,iso:s}};exports.parseE164=parseE164;const planOf=e=>(0,_mobileCore.isSupportedCountry)(e)?e:null,assertDefaultCountryVisible=(e,t)=>{if(void 0!==e&&!t.some(t=>t.iso===e))throw new RangeError(`PhoneNumberInput: defaultCountry "${e}" is not among the visible countries. Add it to countries, or remove it from hiddenCountries.`)},PhoneNumberInput=exports.PhoneNumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:o,onChange:n,e164:r,onChangeE164:a,returnKeyType:l,submitBehavior:s,onSubmitEditing:u,onComplete:c,onValidityChange:d,countries:b=ALL_CALLING_CODES,popularCountries:p,hiddenCountries:_,showFlag:m=!0,renderFlag:h,renderCountry:f,showAlphabetIndex:g,defaultCountry:x,validation:C="any",maxLength:N,formatAsYouType:y=!0,countryLocked:v=!1,label:S,labelMode:E="top",labelStyle:L,placeholder:I,helperText:T,error:j,invalidMessage:P,required:A,disabled:F=!1,size:O="md",variant:V,radius:R,labels:D,haptic:M,accessibilityLabel:U,countryAccessibilityLabel:B,onFocus:q,onBlur:w,style:z,testID:k}=e;(0,_assertValidValue.assertValidValue)("PhoneNumberInput","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const $=(0,_index2.useTheme)(),G=(0,_react.useMemo)(()=>buildStyles($),[$]),H=(0,_react.useRef)(null),W=(0,_react.useMemo)(()=>D?{...DEFAULT_PHONE_NUMBER_INPUT_LABELS,...D}:DEFAULT_PHONE_NUMBER_INPUT_LABELS,[D]),Y=I??W.placeholder,K=(0,_react.useMemo)(()=>/-([A-Za-z]{2})(?:-|$)/.exec((0,_mobileCore.getFormatterConfig)().locale)?.[1]?.toUpperCase(),[]),Z=(0,_react.useMemo)(()=>_?.length?b.filter(e=>!_.includes(e.iso)):b,[b,_]),J=(0,_react.useMemo)(()=>{if(!p?.length)return;const e=p.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:W.popular,options:e},{title:W.allCountries,options:Z}]:void 0},[p,W.popular,W.allCountries,Z]),Q=(0,_react.useCallback)((e,t,i)=>{if(!e)return null;if(h)return h(e);if(!m)return null;const o=(0,_mobileCore.countryFlagEmoji)(e.iso);return o?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",style:[G.flag,{fontSize:t}],testID:i,children:o}):null},[h,m,G.flag]),X=(0,_react.useCallback)(e=>{const t=planOf(e),i=t?(0,_mobileCore.maxNationalNumberLength)(t,!1===C?"any":C):Number.POSITIVE_INFINITY;return N?Math.min(i,N):i},[N,C]),ee=(0,_react.useCallback)((e,t)=>e.slice(0,X(t)),[X]),te=(0,_react.useCallback)((e,t)=>{const i=planOf(t)??void 0,o=(0,_mobileCore.splitPhoneNumber)(e,i);if(!o)return null;const n=o.country??t,r=b.find(e=>e.iso===n);return{callingCode:r?.code??o.callingCode,nationalNumber:ee(o.nationalNumber,n),iso:r?.iso??n}},[b,ee]);(0,_react.useState)(()=>assertDefaultCountryVisible(x,Z));const ie=(0,_react.useMemo)(()=>{const e=Z.find(e=>e.iso===(x??K))??Z[0]??b[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof o?te(o,t.iso)??t:o??t},[b,Z,x,K,o,te]),oe=(0,_react.useCallback)(e=>{if(!1===C)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?(0,_mobileCore.isValidNationalNumber)(e.nationalNumber,t,C):e.nationalNumber.length>0},[C]),[ne,re]=(0,_react.useState)(ie.iso),ae=(0,_react.useMemo)(()=>{if(void 0===r)return;const e=r?parseE164(r,b,ne):null;if(e)return{...e,nationalNumber:ee(e.nationalNumber,e.iso)};const t=b.find(e=>e.iso===ne);return{callingCode:t?.code??ie.callingCode,nationalNumber:"",iso:ne}},[r,b,ne,ie.callingCode,ee]),le=(0,_react.useCallback)(e=>{re(e.iso),n?.(e),a?.(e.nationalNumber?formatE164(e):"",{country:b.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:oe(e)})},[n,a,b,oe]),[se,ue]=(0,_index.useControllableState)({value:i??ae,defaultValue:ie,onChange:le}),[ce,de]=(0,_react.useState)(!1),be=(0,_react.useCallback)(()=>{F||H.current?.focus()},[F]),[pe,me]=(0,_react.useState)(!1),[he,fe]=(0,_react.useState)(!1),[ge,xe]=(0,_react.useState)(!1),Ce=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{ge||(Ce.current=!1)},[ge]);const Ne=(0,_index2.resolveFieldSize)($,O),ye=(0,_index4.resolveFieldTextStyle)($,{disabled:F}),ve=V??$.settings.components.field?.defaultVariant??"outline",Se="underline"===ve,Ee=$.space.md,[Le,Ie]=(0,_react.useState)(0),Te=Le+Ee+1+Ee,je=se.nationalNumber.length>0,Pe=A&&!S&&!je&&Y.length>0,Ae=ce||je,Fe=Boolean(S)&&"float"===E&&Le>0,Oe=(0,_useFloatingLabel.useFloatingLabel)({label:S,enabled:Fe,floated:Ae,required:A,variant:ve,sizeTokens:Ne,leadingOffset:Te,paddingLeft:Se?$.space.none:Ne["padding-x"],color:$.colors["field-label"],style:L}),Ve=(0,_react.useMemo)(()=>b.find(e=>e.iso===se.iso),[b,se.iso]),Re=planOf(se.iso),De=y&&Re?(0,_mobileCore.formatPhoneAsTyped)(se.nationalNumber,Re):se.nationalNumber,Me=X(se.iso),Ue=0===se.nationalNumber.length||pe||!Number.isFinite(Me)?void 0:De.length+Math.max(0,Me-se.nationalNumber.length),Be=oe(se);(0,_react.useEffect)(()=>{je||fe(!1)},[je]);const qe=Re?(0,_mobileCore.maxNationalNumberLength)(Re,!1===C?"any":C):Number.POSITIVE_INFINITY,we=se.nationalNumber.length>=qe,ze=!1!==C&&!1!==P&&je&&!Be&&(he||we),ke="mobile"===C?W.invalidMobile:W.invalid,$e=(0,_index4.hasFieldText)(j)?j:ze?P||ke:void 0,Ge=!0===j||(0,_index4.hasFieldText)($e),He=(0,_react.useRef)(Be),We=(0,_react.useRef)(se);We.current=se,(0,_react.useEffect)(()=>{He.current!==Be&&(He.current=Be,d?.(Be),Be&&c?.(formatE164(We.current)))},[Be,c,d]);const Ye=(0,_react.useCallback)(e=>{if(e.includes("+")){const t=te(e,se.iso);if(t&&!v&&Z.some(e=>e.iso===t.iso))return void ue(t);if(t&&t.iso===se.iso)return void ue(t)}ue({...se,nationalNumber:ee(digitsOnly(e),se.iso)})},[Z,v,se,te,ee,ue]),Ke=(0,_react.useCallback)(e=>{ue({callingCode:e.code,iso:e.iso,nationalNumber:ee(se.nationalNumber,e.iso)}),xe(!1);const t=(0,_index3.resolveHaptic)(M,"selection");t&&(0,_index3.triggerHaptic)(t)},[se,M,ee,ue]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>H.current?.focus(),blur:()=>H.current?.blur(),clear:()=>ue({...We.current,nationalNumber:""}),isFocused:()=>H.current?.isFocused()??!1,getValue:()=>We.current,getE164:()=>formatE164(We.current),getFormatted:()=>{const e=We.current,t=planOf(e.iso);return t?(0,_mobileCore.formatPhoneAsTyped)(e.nationalNumber,t):e.nationalNumber},isValid:()=>oe(We.current),getCountry:()=>b.find(e=>e.iso===We.current.iso)}),[b,oe,ue]);const Ze=F||v,Je=(0,_jsxRuntime.jsx)(_index4.FieldBase,{size:O,variant:ve,radius:R,topNotch:Oe.topNotch,focused:ce,disabled:F,error:Ge,filled:je,onPress:be,pressFeedback:!1,leadingDivider:!0,paddingLeft:Se?$.space.none:void 0,leading:(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{Ze||(Ce.current=!0,xe(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:B??W.countryButton(se.callingCode),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...(0,_hitSlop.hitSlopMarker)(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Ie(e=>e===t?e:t)},style:G.codeTrigger,testID:k?`${k}-code`:void 0,children:[Q(Ve,Ne.text,k?`${k}-flag`:void 0),(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",style:[G.codeText,{color:ye.color,fontSize:Ne.text}],children:`+${se.callingCode}`}),v?null:(0,_jsxRuntime.jsx)(_Chevron.Chevron,{color:F?$.colors["field-icon-disabled"]:$.colors["field-icon"],size:Ne.icon,open:ge})]}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:H,value:De,maxLength:Ue,onChangeText:Ye,returnKeyType:l,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:i}=e.nativeEvent.selection;me(t!==i)},onFocus:()=>{de(!0),q?.()},onBlur:()=>{de(!1),je&&!Ce.current&&fe(!0),w?.()},editable:!F,placeholder:Fe&&!Ae||Pe?void 0:Y,placeholderTextColor:ye.placeholderColor,accessibilityLabel:U??S??Y,selectionColor:$.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[G.input,{color:ye.color,fontSize:Ne.text,...ye.weightStyle,paddingLeft:Se?$.space.none:void 0}],testID:k?`${k}-input`:void 0}),Pe?(0,_jsxRuntime.jsx)(_index4.RequiredPlaceholder,{text:Y,color:ye.placeholderColor,fontSize:Ne.text,weightStyle:ye.weightStyle}):null]})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:z,testID:k,children:[S&&"top"===E?(0,_jsxRuntime.jsx)(_index4.FieldLabel,{size:O,required:A,children:S}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.fieldWrapper,children:[Je,Oe.node]}),(0,_jsxRuntime.jsx)(_index4.FieldMessage,{size:O,error:Ge,text:Ge?$e:T}),(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:ge,haptic:M,onClose:()=>xe(!1),title:W.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,$.text.lg.size),renderOption:f?({option:e,selected:t})=>f(e,{selected:t}):void 0,value:Ve?.iso,onChange:(e,t)=>Ke(t),searchable:Z.length>8,labels:{searchPlaceholder:W.countrySearchPlaceholder},alphabetIndex:g??Z.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...(0,_index2.fontFor)(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});var _default=exports.default=PhoneNumberInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.SlideToConfirm=exports.DEFAULT_SLIDE_TO_CONFIRM_LABELS=void 0;var cache,_react=_interopRequireWildcard(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"),_corners=require("../../utils/corners.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
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.SlideToConfirm=exports.DEFAULT_SLIDE_TO_CONFIRM_LABELS=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeWorklets=require("react-native-worklets"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,i=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=i&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?i(n,r,a):n[r]=e[r]);return n}const DEFAULT_SLIDE_TO_CONFIRM_LABELS=exports.DEFAULT_SLIDE_TO_CONFIRM_LABELS=Object.freeze({slide:"Slide to confirm",confirmed:"Confirmed",confirmAction:"Confirm"}),SIZE_MAP={sm:{height:44,pad:"xxs"},md:{height:56,pad:"xs"},lg:{height:64,pad:"sm"}},Chevron=({color:e,size:t})=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:0,height:0,borderTopWidth:.4*t,borderBottomWidth:.4*t,borderLeftWidth:.55*t,borderTopColor:"transparent",borderBottomColor:"transparent",borderLeftColor:e,marginLeft:.2*t}}),SlideToConfirm=exports.SlideToConfirm=(0,_react.forwardRef)((e,t)=>{const{onConfirm:a,label:r,tone:i="primary",size:n="md",disabled:s=!1,threshold:o=.9,resetAfter:l=!1,haptic:c,icon:d,labels:u,style:m,trackStyle:_,handleStyle:h,labelStyle:f,testID:v}=e;(0,_assertValidValue.assertValidValue)("SlideToConfirm","tone",e.tone,["primary","success","warning","danger","info","neutral"]),(0,_assertValidValue.assertValidValue)("SlideToConfirm","size",e.size,["sm","md","lg"]);const p=(0,_react.useMemo)(()=>({...DEFAULT_SLIDE_TO_CONFIRM_LABELS,...u}),[u]),b=(0,_react.useMemo)(()=>[{name:"activate",label:p.confirmAction},{name:"increment",label:p.confirmAction}],[p.confirmAction]),x=(0,_index.useTheme)(),g=SIZE_MAP[n],R=x.space[g.pad],y=g.height-2*R,S=(0,_react.useMemo)(()=>buildStyles(x,g),[x,g]),C=x.colors[i],[N,j]=(0,_react.useState)(!1),T=(0,_reactNativeReanimated.useSharedValue)(0),A=(0,_reactNativeReanimated.useSharedValue)(0),w=(0,_reactNativeReanimated.useSharedValue)(0),L=(0,_react.useRef)(null),E=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(c,"notificationSuccess");e&&(0,_index2.triggerHaptic)(e)},[c]),V=(0,_react.useCallback)(()=>{j(!1),T.value=(0,_reactNativeReanimated.withSpring)(0,{damping:18,stiffness:160,mass:1})},[T]),k=(0,_react.useCallback)(()=>{j(!0),E(),a(),!1!==l&&(L.current&&clearTimeout(L.current),L.current=setTimeout(V,l))},[E,a,l,V]),M=(0,_react.useCallback)(e=>{if(s||N)return;const{actionName:t}=e.nativeEvent;"activate"!==t&&"increment"!==t||k()},[s,N,k]);_react.default.useEffect(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(T),L.current&&clearTimeout(L.current)},[T]);const O=(0,_react.useCallback)(e=>{A.value=Math.max(0,e.nativeEvent.layout.width-y-2*R)},[A,y,R]),q=(0,_react.useMemo)(()=>{const e=o,t={damping:18,stiffness:160,mass:1},a={duration:x.motion.duration.fast,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)};return{enabled:!s&&!N,minDistance:0,onActivate:()=>{"worklet";w.value=T.value},onUpdate:e=>{"worklet";T.value=Math.min(Math.max(w.value+e.translationX,0),A.value)},onDeactivate:()=>{"worklet";A.value>0&&T.value>=A.value*e?(T.value=(0,_reactNativeReanimated.withTiming)(A.value,a),(0,_reactNativeWorklets.scheduleOnRN)(k)):T.value=(0,_reactNativeReanimated.withSpring)(0,t)}}},[s,N,o,T,A,w,k,x.motion.duration.fast]),D=(0,_reactNativeGestureHandler.usePanGesture)(q),I=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:T.value}]}),[T]),W=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({width:T.value+y+R}),[T,y,R]),F=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=A.value>0?A.value:1;return{opacity:Math.max(0,1-T.value/(.6*e))}},[A,T]);return(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:t,style:[S.track,{backgroundColor:x.colors["bg-subtle"]},_,m],onLayout:O,testID:v,accessibilityRole:"adjustable",accessibilityLabel:N?p.confirmed:r??p.slide,accessibilityState:{disabled:s},"aria-disabled":s,accessibilityActions:b,onAccessibilityAction:M,children:[(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.fill,{backgroundColor:C,opacity:s?.5:1},W],pointerEvents:"none"}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.labelWrap,F],pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",style:[S.label,{color:x.colors["text-muted"]},f],numberOfLines:1,children:N?p.confirmed:r??p.slide})}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:D,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[S.handle,{width:y,height:y,borderRadius:x.radius.pill,..._corners.smoothCorners,backgroundColor:x.colors.surface,opacity:s?.5:1,...x.shadow.card},h,I],children:d??(0,_jsxRuntime.jsx)(Chevron,{color:C,size:.5*y})})})]})});SlideToConfirm.displayName="SlideToConfirm";const buildStyles=(e,t)=>_reactNative.StyleSheet.create({track:{height:t.height,borderRadius:e.radius.pill,..._corners.smoothCorners,justifyContent:"center",overflow:"hidden",padding:e.space[t.pad]},fill:{position:"absolute",left:0,top:0,bottom:0,borderRadius:e.radius.pill,..._corners.smoothCorners},labelWrap:{position:"absolute",left:t.height,right:t.height},label:{textAlign:"center",includeFontPadding:!1},handle:{alignItems:"center",justifyContent:"center"}});var _default=exports.default=SlideToConfirm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Slider=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("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_index4=require("../Text/index.js"),_valueText=require("./valueText.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,a){if(!a&&e&&e.__esModule)return e;var t,r,i=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)&&((t=i&&Object.getOwnPropertyDescriptor(e,r))&&(t.get||t.set)?i(n,r,t):n[r]=e[r]);return n}const VARIANT_SIZE_MAP={inset:{sm:{trackHeight:14,thumbDiameter:10},md:{trackHeight:20,thumbDiameter:14},lg:{trackHeight:26,thumbDiameter:18}},minimal:{sm:{trackHeight:2,thumbDiameter:14},md:{trackHeight:3,thumbDiameter:18},lg:{trackHeight:4,thumbDiameter:22}},bar:{sm:{trackHeight:20,thumbDiameter:20},md:{trackHeight:28,thumbDiameter:28},lg:{trackHeight:36,thumbDiameter:36}}},INSET_RING_RATIO=.3,MIN_THUMB_TOUCH=44,clamp=(e,a,t)=>Math.min(Math.max(e,a),t),snapToStep=(e,a,t,r)=>{if(r<=0)return clamp(e,a,t);const i=Math.round((e-a)/r)*r+a,n=String(r).split(".")[1]?.length??0,s=n>0?Number(i.toFixed(n)):i;return clamp(s,a,t)},BUBBLE_GAP=2,BUBBLE_CARET=8,BUBBLE_WRAP_WIDTH=160,NO_SHADOW={shadowOpacity:0,elevation:0},defaultFormatLabel=e=>String(e),isPair=e=>Array.isArray(e),Slider=exports.Slider=(0,_react.forwardRef)((e,a)=>{const{min:t=0,max:r=100,step:i=1,disabled:n=!1,tone:s="primary",size:l="md",variant:c="default",showLabel:o=!1,snapThumb:u=!1,formatLabel:d=defaultFormatLabel,renderLabel:m,accessibilityLabel:h,haptic:_,style:v,containerStyle:b,trackStyle:g,fillStyle:f,thumbStyle:p,labelStyle:R,thumbPressScale:y,labelShowDuration:x,labelOpacity:w,testID:N}=e;(0,_assertValidValue.assertValidValue)("Slider","tone",e.tone,["primary","success","warning","danger","info","neutral"]),(0,_assertValidValue.assertValidValue)("Slider","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("Slider","variant",e.variant,["default","inset","minimal","bar"]);const S=(0,_index2.useTheme)(),k=(0,_react.useMemo)(()=>{const e=(0,_index2.resolveSliderSize)(S,l);return{trackHeight:e["track-height"],thumbDiameter:e["thumb-diameter"]}},[S,l]),j=(0,_react.useMemo)(()=>"default"===c?k:VARIANT_SIZE_MAP[c][l],[k,l,c]),C="inset"===c?j.trackHeight/2:0,V=S.settings.components.slider?.thumbPressAnimation??!1,A=y??1.1,M=x??S.motion.duration.fast,H=w??1,D=(0,_react.useMemo)(()=>buildStyles(S,j),[S,j]),O=(0,_react.useMemo)(()=>({damping:S.motion.spring.snappy.damping,stiffness:S.motion.spring.snappy.stiffness,mass:S.motion.spring.snappy.mass}),[S.motion.spring.snappy]),[E,T]=(0,_react.useState)(0),P=S.colors[s],W=(0,_valueText.sliderToneInk)(S,s),I=!0===e.range,q=(0,_react.useCallback)(a=>{if(!0!==e.range){if(Array.isArray(a))throw new Error("Slider received a range value in single mode.");e.onChange?.(a)}else{if(!Array.isArray(a))throw new Error("Slider received a single value in range mode.");e.onChange?.(a)}},[e.onChange,e.range]),[L,G]=(0,_index.useControllableState)({value:e.value,defaultValue:e.defaultValue??(I?[t,r]:t),onChange:q}),X=(0,_reactNativeReanimated.useSharedValue)(0),B=(0,_reactNativeReanimated.useSharedValue)(0),F=(0,_reactNativeReanimated.useSharedValue)(isPair(L)?L[0]:L),z=(0,_reactNativeReanimated.useSharedValue)(isPair(L)?L[1]:L),J=(0,_reactNativeReanimated.useSharedValue)(0),U=(0,_reactNativeReanimated.useSharedValue)(0),Z=(0,_reactNativeReanimated.useSharedValue)(1),$=(0,_reactNativeReanimated.useSharedValue)(1),K="always"===o,Q=(0,_reactNativeReanimated.useSharedValue)(K?1:0),Y=(0,_reactNativeReanimated.useSharedValue)(K?1:0),ee=(0,_react.useMemo)(()=>10**(String(i).split(".")[1]?.length??0),[i]);(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(X),(0,_reactNativeReanimated.cancelAnimation)(B),(0,_reactNativeReanimated.cancelAnimation)(Z),(0,_reactNativeReanimated.cancelAnimation)($),(0,_reactNativeReanimated.cancelAnimation)(Q),(0,_reactNativeReanimated.cancelAnimation)(Y)},[X,B,Z,$,Q,Y]);const ae=(0,_react.useCallback)((e,a)=>{const i=a-2*C;return r===t||i<=0?C:C+(e-t)/(r-t)*i},[t,r,C]),te=(0,_react.useCallback)((e,a)=>{const n=a-2*C;if(n<=0)return t;const s=clamp((e-C)/n,0,1);return snapToStep(t+s*(r-t),t,r,i)},[t,r,i,C]),re=(0,_react.useRef)(!1),ie=S.motion.duration.fast,ne=(0,_react.useRef)(L);ne.current=L;const se=(0,_react.useRef)(E);se.current=E;const le=(0,_react.useCallback)((e=!1)=>{const a=se.current;if(a<=0)return;const place=a=>e?(0,_reactNativeReanimated.withTiming)(a,{duration:ie,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}):a,t=ne.current;if(isPair(t)){const[e,r]=t,i=Math.min(e,r),n=Math.max(e,r);F.value=i,z.value=n,X.value=place(ae(i,a)),B.value=place(ae(n,a))}else{const e=t;F.value=e,z.value=e,X.value=place(ae(e,a))}},[ae,F,z,X,B,ie]),[ce,oe]=(0,_react.useState)(0),ue=(0,_react.useRef)(!1),de=(0,_react.useCallback)(e=>{re.current=e,e||(ue.current=!0,oe(e=>e+1))},[]);(0,_react.useEffect)(()=>{if(re.current)return;const e=ue.current;ue.current=!1,le(e)},[JSON.stringify(L),E,ce,le]);const me=(0,_react.useCallback)(e=>{const a=e.nativeEvent.layout.width;U.value=a,T(a)},[U]),he=(0,_react.useCallback)((e,a)=>{G(I?[e,a]:e)},[I,G]),ve=(0,_react.useCallback)(()=>{const e=(0,_index3.resolveHaptic)(_,"selection");e&&(0,_index3.triggerHaptic)(e)},[_]),be=(0,_react.useRef)(he);be.current=he;const ge=(0,_react.useRef)(ve);ge.current=ve;const fe=(0,_react.useCallback)((e,a)=>be.current(e,a),[]),pe=(0,_react.useCallback)(()=>ge.current(),[]),Re=Math.max(0,(44-j.thumbDiameter)/2),ye=Re>0?Re:void 0,xe=(0,_react.useCallback)(e=>{const a="low"===e?X:B,s="low"===e?F:z,l="low"===e?z:F,c="low"===e?Z:$,d="low"===e?Q:Y,m="low"===e,h=t,_=r,v=i,b=ee,g=I,f=A,p=V,R=!0===o,y=u,x=H,w=M,N=O,S=C,follow=e=>{"worklet";const t=U.value-2*S;if(t<=0||!Number.isFinite(e))return;const r=Math.min(Math.max(J.value+e,S),U.value-S);let i=h+(r-S)/t*(_-h);v>0&&(i=Math.round((i-h)/v)*v+h,i=Math.round(i*b)/b),i=Math.min(Math.max(i,h),_),g&&(m&&i>l.value&&(i=l.value),!m&&i<l.value&&(i=l.value)),a.value=y||_===h?_===h?S:S+(i-h)/(_-h)*t:g?m?Math.min(r,B.value):Math.max(r,X.value):r,i!==s.value&&(s.value=i,i!==h&&i!==_||(0,_reactNativeReanimated.runOnJS)(pe)(),(0,_reactNativeReanimated.runOnJS)(fe)(F.value,z.value))};return{enabled:!n,minDistance:0,...void 0===ye?{}:{hitSlop:ye},onActivate:()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(de)(!0),J.value=a.value,p&&(c.value=(0,_reactNativeReanimated.withSpring)(f,N)),R&&(d.value=(0,_reactNativeReanimated.withTiming)(x,{duration:w,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)})),(0,_reactNativeReanimated.runOnJS)(pe)()},onUpdate:e=>{"worklet";follow(e.translationX)},onDeactivate:e=>{"worklet";follow(e.translationX),p&&(c.value=(0,_reactNativeReanimated.withSpring)(1,N)),R&&(d.value=(0,_reactNativeReanimated.withTiming)(0,{duration:w,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}))},onFinalize:()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(de)(!1)}}},[n,t,r,i,ee,I,A,V,o,u,H,M,O,C,ye,fe,pe,de,X,B,F,z,Z,$,Q,Y,J,U]),we=(0,_react.useMemo)(()=>xe("low"),[xe]),Ne=(0,_react.useMemo)(()=>xe("high"),[xe]),Se=(0,_reactNativeGestureHandler.usePanGesture)(we),ke=(0,_reactNativeGestureHandler.usePanGesture)(Ne),je=(0,_react.useCallback)(e=>{if(n||I||E<=0)return;const a=clamp(e.nativeEvent.locationX,0,E),t=te(a,E);t!==F.value&&(ve(),F.value=t,X.value=(0,_reactNativeReanimated.withTiming)(ae(t,E),{duration:S.motion.duration.fast,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}),he(t,t))},[n,I,E,te,ae,he,ve,X,F,S.motion.duration.fast]),Ce=(0,_react.useCallback)(e=>{if(n)return;const a="increment"===e.nativeEvent.actionName?i:-i,s=i>0?Math.round(a*ee)/ee:a;if(I){const e=Math.round((F.value+s)*ee)/ee,a=clamp(e,t,z.value);a!==F.value&&(F.value=a,X.value=ae(a,E),ve(),he(a,z.value))}else{const e=Math.round((F.value+s)*ee)/ee,a=clamp(e,t,r);a!==F.value&&(F.value=a,X.value=ae(a,E),ve(),he(a,a))}},[n,i,ee,I,t,r,ae,E,X,F,z,he,ve]),Ve=j.thumbDiameter/2,Ae=n?S.colors["surface-disabled"]:P,Me="inset"===c?{backgroundColor:Ae,borderColor:S.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===c?{backgroundColor:Ae,borderWidth:0}:"bar"===c?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:S.colors.surface,borderColor:Ae},He=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=U.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const a=n?.55:1;if(I){const t=Math.max(0,B.value-X.value+2*C);return{opacity:a,transform:[{translateX:X.value-C},{scaleX:t/e}]}}return{opacity:a,transform:[{translateX:X.value+C-e},{scaleX:1}]}},[U,n,I,B,X,C]),De=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:X.value-Ve},{scale:Z.value}]}),[X,Ve,Z]),Oe=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:B.value-Ve},{scale:$.value}]}),[B,Ve,$]),Ee=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:Q.value}),[Q]),Te=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:Y.value}),[Y]),clampDisplay=e=>clamp(e,t,r),Pe=clampDisplay(isPair(L)?Math.min(...L):L),We=clampDisplay(isPair(L)?Math.max(...L):L);return(0,_jsxRuntime.jsx)(_reactNative.View,{ref:a,style:[D.container,b,v],testID:N,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityValue:I?{min:t,max:r,now:Pe,text:`${Pe} to ${We}`}:{min:t,max:r,now:Pe},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Ce,children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:je,disabled:n||I,style:D.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.trackWrap,onLayout:me,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.trackClip,pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.track,{backgroundColor:n?S.colors["surface-disabled"]:S.colors.border},g]}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.fill,{backgroundColor:n?S.colors["surface-disabled"]:P},f,He]})]}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Se,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ve,..._corners.smoothCorners,opacity:n?.55:1},Me,p,De],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o?(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[D.bubbleWrap,Ee],pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubble,{backgroundColor:P}],children:m?m(Pe):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",style:[{color:W},R],numberOfLines:1,children:d(Pe)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubbleCaret,{backgroundColor:P}]})]}):null})}),I?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ke,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ve,..._corners.smoothCorners,opacity:n?.55:1},Me,p,Oe],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o?(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[D.bubbleWrap,Te],pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubble,{backgroundColor:P}],children:m?m(We):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",style:[{color:W},R],numberOfLines:1,children:d(We)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubbleCaret,{backgroundColor:P}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,a)=>{const t=e.shadow.elevated,r=Math.max(a.thumbDiameter,a.trackHeight),i=r/2+e.space.xs;return _reactNative.StyleSheet.create({container:{width:"100%",paddingVertical:i,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:r,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:a.trackHeight,top:(r-a.trackHeight)/2,borderRadius:a.trackHeight/2,..._corners.smoothCorners,overflow:"hidden"},track:{position:"absolute",top:0,right:0,bottom:0,left:0,borderRadius:a.trackHeight/2,..._corners.smoothCorners},fill:{position:"absolute",top:0,left:0,width:"100%",height:a.trackHeight,borderRadius:a.trackHeight/2,..._corners.smoothCorners,transformOrigin:"left"},thumb:{position:"absolute",top:(r-a.thumbDiameter)/2,left:0,borderWidth:2,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation,alignItems:"center",justifyContent:"center"},bubbleWrap:{position:"absolute",bottom:a.thumbDiameter+2,left:a.thumbDiameter/2-80,width:160,alignItems:"center"},bubbleCaret:{width:8,height:8,marginTop:-5,borderRadius:e.radius.none,..._corners.smoothCorners,transform:[{rotate:"45deg"}]},bubble:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xxs,borderRadius:e.radius.md,..._corners.smoothCorners,minWidth:36,alignItems:"center",justifyContent:"center",..._reactNative.Platform.select({ios:{shadowColor:e.shadow.card.shadowColor,shadowOffset:e.shadow.card.shadowOffset,shadowOpacity:e.shadow.card.shadowOpacity,shadowRadius:e.shadow.card.shadowRadius},android:{elevation:e.shadow.card.elevation},default:{}})}})};var _default=exports.default=Slider;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Slider=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeWorklets=require("react-native-worklets"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_index4=require("../Text/index.js"),_valueText=require("./valueText.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,i=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=i&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?i(n,r,a):n[r]=e[r]);return n}const VARIANT_SIZE_MAP={inset:{sm:{trackHeight:14,thumbDiameter:10},md:{trackHeight:20,thumbDiameter:14},lg:{trackHeight:26,thumbDiameter:18}},minimal:{sm:{trackHeight:2,thumbDiameter:14},md:{trackHeight:3,thumbDiameter:18},lg:{trackHeight:4,thumbDiameter:22}},bar:{sm:{trackHeight:20,thumbDiameter:20},md:{trackHeight:28,thumbDiameter:28},lg:{trackHeight:36,thumbDiameter:36}}},INSET_RING_RATIO=.3,MIN_THUMB_TOUCH=44,clamp=(e,t,a)=>Math.min(Math.max(e,t),a),snapToStep=(e,t,a,r)=>{if(r<=0)return clamp(e,t,a);const i=Math.round((e-t)/r)*r+t,n=String(r).split(".")[1]?.length??0,s=n>0?Number(i.toFixed(n)):i;return clamp(s,t,a)},BUBBLE_GAP=2,BUBBLE_CARET=8,BUBBLE_WRAP_WIDTH=160,NO_SHADOW={shadowOpacity:0,elevation:0},defaultFormatLabel=e=>String(e),isPair=e=>Array.isArray(e),Slider=exports.Slider=(0,_react.forwardRef)((e,t)=>{const{min:a=0,max:r=100,step:i=1,disabled:n=!1,tone:s="primary",size:l="md",variant:c="default",showLabel:o=!1,snapThumb:u=!1,formatLabel:d=defaultFormatLabel,renderLabel:m,accessibilityLabel:h,haptic:_,style:v,containerStyle:b,trackStyle:g,fillStyle:f,thumbStyle:p,labelStyle:R,thumbPressScale:y,labelShowDuration:x,labelOpacity:N,testID:w}=e;(0,_assertValidValue.assertValidValue)("Slider","tone",e.tone,["primary","success","warning","danger","info","neutral"]),(0,_assertValidValue.assertValidValue)("Slider","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("Slider","variant",e.variant,["default","inset","minimal","bar"]);const k=(0,_index2.useTheme)(),S=(0,_react.useMemo)(()=>{const e=(0,_index2.resolveSliderSize)(k,l);return{trackHeight:e["track-height"],thumbDiameter:e["thumb-diameter"]}},[k,l]),j=(0,_react.useMemo)(()=>"default"===c?S:VARIANT_SIZE_MAP[c][l],[S,l,c]),C="inset"===c?j.trackHeight/2:0,V=k.settings.components.slider?.thumbPressAnimation??!1,A=y??1.1,M=x??k.motion.duration.fast,H=N??1,D=(0,_react.useMemo)(()=>buildStyles(k,j),[k,j]),O=(0,_react.useMemo)(()=>({damping:k.motion.spring.snappy.damping,stiffness:k.motion.spring.snappy.stiffness,mass:k.motion.spring.snappy.mass}),[k.motion.spring.snappy]),[E,T]=(0,_react.useState)(0),W=k.colors[s],P=(0,_valueText.sliderToneInk)(k,s),q=!0===e.range,I=(0,_react.useCallback)(t=>{if(!0!==e.range){if(Array.isArray(t))throw new Error("Slider received a range value in single mode.");e.onChange?.(t)}else{if(!Array.isArray(t))throw new Error("Slider received a single value in range mode.");e.onChange?.(t)}},[e.onChange,e.range]),[L,G]=(0,_index.useControllableState)({value:e.value,defaultValue:e.defaultValue??(q?[a,r]:a),onChange:I}),X=(0,_reactNativeReanimated.useSharedValue)(0),B=(0,_reactNativeReanimated.useSharedValue)(0),F=(0,_reactNativeReanimated.useSharedValue)(isPair(L)?L[0]:L),z=(0,_reactNativeReanimated.useSharedValue)(isPair(L)?L[1]:L),U=(0,_reactNativeReanimated.useSharedValue)(0),Z=(0,_reactNativeReanimated.useSharedValue)(0),$=(0,_reactNativeReanimated.useSharedValue)(1),J=(0,_reactNativeReanimated.useSharedValue)(1),K="always"===o,Q=(0,_reactNativeReanimated.useSharedValue)(K?1:0),Y=(0,_reactNativeReanimated.useSharedValue)(K?1:0),ee=(0,_react.useMemo)(()=>10**(String(i).split(".")[1]?.length??0),[i]);(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(X),(0,_reactNativeReanimated.cancelAnimation)(B),(0,_reactNativeReanimated.cancelAnimation)($),(0,_reactNativeReanimated.cancelAnimation)(J),(0,_reactNativeReanimated.cancelAnimation)(Q),(0,_reactNativeReanimated.cancelAnimation)(Y)},[X,B,$,J,Q,Y]);const te=(0,_react.useCallback)((e,t)=>{const i=t-2*C;return r===a||i<=0?C:C+(e-a)/(r-a)*i},[a,r,C]),ae=(0,_react.useCallback)((e,t)=>{const n=t-2*C;if(n<=0)return a;const s=clamp((e-C)/n,0,1);return snapToStep(a+s*(r-a),a,r,i)},[a,r,i,C]),re=(0,_react.useRef)(!1),ie=k.motion.duration.fast,ne=(0,_react.useRef)(L);ne.current=L;const se=(0,_react.useRef)(E);se.current=E;const le=(0,_react.useCallback)((e=!1)=>{const t=se.current;if(t<=0)return;const place=t=>e?(0,_reactNativeReanimated.withTiming)(t,{duration:ie,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}):t,a=ne.current;if(isPair(a)){const[e,r]=a,i=Math.min(e,r),n=Math.max(e,r);F.value=i,z.value=n,X.value=place(te(i,t)),B.value=place(te(n,t))}else{const e=a;F.value=e,z.value=e,X.value=place(te(e,t))}},[te,F,z,X,B,ie]),[ce,oe]=(0,_react.useState)(0),ue=(0,_react.useRef)(!1),de=(0,_react.useCallback)(e=>{re.current=e,e||(ue.current=!0,oe(e=>e+1))},[]);(0,_react.useEffect)(()=>{if(re.current)return;const e=ue.current;ue.current=!1,le(e)},[JSON.stringify(L),E,ce,le]);const me=(0,_react.useCallback)(e=>{const t=e.nativeEvent.layout.width;Z.value=t,T(t)},[Z]),he=(0,_react.useCallback)((e,t)=>{G(q?[e,t]:e)},[q,G]),ve=(0,_react.useCallback)(()=>{const e=(0,_index3.resolveHaptic)(_,"selection");e&&(0,_index3.triggerHaptic)(e)},[_]),be=(0,_react.useRef)(he);be.current=he;const ge=(0,_react.useRef)(ve);ge.current=ve;const fe=(0,_react.useCallback)((e,t)=>be.current(e,t),[]),pe=(0,_react.useCallback)(()=>ge.current(),[]),Re=Math.max(0,(44-j.thumbDiameter)/2),ye=Re>0?Re:void 0,xe=(0,_react.useCallback)(e=>{const t="low"===e?X:B,s="low"===e?F:z,l="low"===e?z:F,c="low"===e?$:J,d="low"===e?Q:Y,m="low"===e,h=a,_=r,v=i,b=ee,g=q,f=A,p=V,R=!0===o,y=u,x=H,N=M,w=O,k=C,follow=e=>{"worklet";const a=Z.value-2*k;if(a<=0||!Number.isFinite(e))return;const r=Math.min(Math.max(U.value+e,k),Z.value-k);let i=h+(r-k)/a*(_-h);v>0&&(i=Math.round((i-h)/v)*v+h,i=Math.round(i*b)/b),i=Math.min(Math.max(i,h),_),g&&(m&&i>l.value&&(i=l.value),!m&&i<l.value&&(i=l.value)),t.value=y||_===h?_===h?k:k+(i-h)/(_-h)*a:g?m?Math.min(r,B.value):Math.max(r,X.value):r,i!==s.value&&(s.value=i,i!==h&&i!==_||(0,_reactNativeWorklets.scheduleOnRN)(pe),(0,_reactNativeWorklets.scheduleOnRN)(fe,F.value,z.value))};return{enabled:!n,minDistance:0,...void 0===ye?{}:{hitSlop:ye},onActivate:()=>{"worklet";(0,_reactNativeWorklets.scheduleOnRN)(de,!0),U.value=t.value,p&&(c.value=(0,_reactNativeReanimated.withSpring)(f,w)),R&&(d.value=(0,_reactNativeReanimated.withTiming)(x,{duration:N,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)})),(0,_reactNativeWorklets.scheduleOnRN)(pe)},onUpdate:e=>{"worklet";follow(e.translationX)},onDeactivate:e=>{"worklet";follow(e.translationX),p&&(c.value=(0,_reactNativeReanimated.withSpring)(1,w)),R&&(d.value=(0,_reactNativeReanimated.withTiming)(0,{duration:N,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}))},onFinalize:()=>{"worklet";(0,_reactNativeWorklets.scheduleOnRN)(de,!1)}}},[n,a,r,i,ee,q,A,V,o,u,H,M,O,C,ye,fe,pe,de,X,B,F,z,$,J,Q,Y,U,Z]),Ne=(0,_react.useMemo)(()=>xe("low"),[xe]),we=(0,_react.useMemo)(()=>xe("high"),[xe]),ke=(0,_reactNativeGestureHandler.usePanGesture)(Ne),Se=(0,_reactNativeGestureHandler.usePanGesture)(we),je=(0,_react.useCallback)(e=>{if(n||q||E<=0)return;const t=clamp(e.nativeEvent.locationX,0,E),a=ae(t,E);a!==F.value&&(ve(),F.value=a,X.value=(0,_reactNativeReanimated.withTiming)(te(a,E),{duration:k.motion.duration.fast,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}),he(a,a))},[n,q,E,ae,te,he,ve,X,F,k.motion.duration.fast]),Ce=(0,_react.useCallback)(e=>{if(n)return;const t="increment"===e.nativeEvent.actionName?i:-i,s=i>0?Math.round(t*ee)/ee:t;if(q){const e=Math.round((F.value+s)*ee)/ee,t=clamp(e,a,z.value);t!==F.value&&(F.value=t,X.value=te(t,E),ve(),he(t,z.value))}else{const e=Math.round((F.value+s)*ee)/ee,t=clamp(e,a,r);t!==F.value&&(F.value=t,X.value=te(t,E),ve(),he(t,t))}},[n,i,ee,q,a,r,te,E,X,F,z,he,ve]),Ve=j.thumbDiameter/2,Ae=n?k.colors["surface-disabled"]:W,Me="inset"===c?{backgroundColor:Ae,borderColor:k.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===c?{backgroundColor:Ae,borderWidth:0}:"bar"===c?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:k.colors.surface,borderColor:Ae},He=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=Z.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const t=n?.55:1;if(q){const a=Math.max(0,B.value-X.value+2*C);return{opacity:t,transform:[{translateX:X.value-C},{scaleX:a/e}]}}return{opacity:t,transform:[{translateX:X.value+C-e},{scaleX:1}]}},[Z,n,q,B,X,C]),De=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:X.value-Ve},{scale:$.value}]}),[X,Ve,$]),Oe=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:B.value-Ve},{scale:J.value}]}),[B,Ve,J]),Ee=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:Q.value}),[Q]),Te=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:Y.value}),[Y]),clampDisplay=e=>clamp(e,a,r),We=clampDisplay(isPair(L)?Math.min(...L):L),Pe=clampDisplay(isPair(L)?Math.max(...L):L);return(0,_jsxRuntime.jsx)(_reactNative.View,{ref:t,style:[D.container,b,v],testID:w,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityValue:q?{min:a,max:r,now:We,text:`${We} to ${Pe}`}:{min:a,max:r,now:We},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Ce,children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:je,disabled:n||q,style:D.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.trackWrap,onLayout:me,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.trackClip,pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.track,{backgroundColor:n?k.colors["surface-disabled"]:k.colors.border},g]}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.fill,{backgroundColor:n?k.colors["surface-disabled"]:W},f,He]})]}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ke,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ve,..._corners.smoothCorners,opacity:n?.55:1},Me,p,De],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o?(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[D.bubbleWrap,Ee],pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubble,{backgroundColor:W}],children:m?m(We):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",style:[{color:P},R],numberOfLines:1,children:d(We)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubbleCaret,{backgroundColor:W}]})]}):null})}),q?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Se,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ve,..._corners.smoothCorners,opacity:n?.55:1},Me,p,Oe],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o?(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[D.bubbleWrap,Te],pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubble,{backgroundColor:W}],children:m?m(Pe):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",style:[{color:P},R],numberOfLines:1,children:d(Pe)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubbleCaret,{backgroundColor:W}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,r=Math.max(t.thumbDiameter,t.trackHeight),i=r/2+e.space.xs;return _reactNative.StyleSheet.create({container:{width:"100%",paddingVertical:i,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:r,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(r-t.trackHeight)/2,borderRadius:t.trackHeight/2,..._corners.smoothCorners,overflow:"hidden"},track:{position:"absolute",top:0,right:0,bottom:0,left:0,borderRadius:t.trackHeight/2,..._corners.smoothCorners},fill:{position:"absolute",top:0,left:0,width:"100%",height:t.trackHeight,borderRadius:t.trackHeight/2,..._corners.smoothCorners,transformOrigin:"left"},thumb:{position:"absolute",top:(r-t.thumbDiameter)/2,left:0,borderWidth:2,shadowColor:a.shadowColor,shadowOffset:a.shadowOffset,shadowOpacity:a.shadowOpacity,shadowRadius:a.shadowRadius,elevation:a.elevation,alignItems:"center",justifyContent:"center"},bubbleWrap:{position:"absolute",bottom:t.thumbDiameter+2,left:t.thumbDiameter/2-80,width:160,alignItems:"center"},bubbleCaret:{width:8,height:8,marginTop:-5,borderRadius:e.radius.none,..._corners.smoothCorners,transform:[{rotate:"45deg"}]},bubble:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xxs,borderRadius:e.radius.md,..._corners.smoothCorners,minWidth:36,alignItems:"center",justifyContent:"center",..._reactNative.Platform.select({ios:{shadowColor:e.shadow.card.shadowColor,shadowOffset:e.shadow.card.shadowOffset,shadowOpacity:e.shadow.card.shadowOpacity,shadowRadius:e.shadow.card.shadowRadius},android:{elevation:e.shadow.card.elevation},default:{}})}})};var _default=exports.default=Slider;
|