@webority/mobile-ui 0.148.0 → 0.149.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas-kit/kit.js +4580 -4419
- package/dist/canvas-kit/manifest.json +1 -1
- package/dist/canvas-kit/release.json +5 -5
- package/lib/commonjs/components/BarChart/BarChart.js +1 -1
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/Drawer/Drawer.js +1 -1
- package/lib/commonjs/components/FieldBase/useFloatingLabel.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/OptionSheet/OptionSheet.js +1 -1
- package/lib/commonjs/components/SignaturePad/SignaturePad.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/WheelPicker/Wheel.js +1 -1
- package/lib/commonjs/components/ZoomableImage/ZoomableImage.js +1 -1
- package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
- package/lib/commonjs/navigation/NavigationScreen.js +1 -1
- package/lib/module/components/BarChart/BarChart.js +1 -1
- package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/module/components/Drawer/Drawer.js +1 -1
- package/lib/module/components/FieldBase/useFloatingLabel.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/OptionSheet/OptionSheet.js +1 -1
- package/lib/module/components/SignaturePad/SignaturePad.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/WheelPicker/Wheel.js +1 -1
- package/lib/module/components/ZoomableImage/ZoomableImage.js +1 -1
- package/lib/module/hooks/useDragToDismiss.js +1 -1
- package/lib/module/navigation/NavigationScreen.js +1 -1
- package/lib/typescript/commonjs/components/BottomSheet/BottomSheet.d.ts +1 -1
- package/lib/typescript/commonjs/components/Drawer/Drawer.d.ts +1 -1
- package/lib/typescript/commonjs/components/FileViewer/useFileViewerZoom.d.ts +3 -3
- package/lib/typescript/commonjs/components/Swipeable/Swipeable.d.ts +1 -1
- package/lib/typescript/commonjs/hooks/useDragToDismiss.d.ts +5 -5
- package/lib/typescript/module/components/BottomSheet/BottomSheet.d.ts +1 -1
- package/lib/typescript/module/components/Drawer/Drawer.d.ts +1 -1
- package/lib/typescript/module/components/FileViewer/useFileViewerZoom.d.ts +3 -3
- package/lib/typescript/module/components/Swipeable/Swipeable.d.ts +1 -1
- package/lib/typescript/module/hooks/useDragToDismiss.d.ts +5 -5
- package/package.json +9 -9
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webority-phone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.149.0",
|
|
4
4
|
"platform": "Phone",
|
|
5
5
|
"kitModuleVersion": 2,
|
|
6
6
|
"rendererProtocolVersion": 13,
|
|
7
7
|
"library": {
|
|
8
8
|
"name": "@webority/mobile-ui",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.149.0"
|
|
10
10
|
},
|
|
11
11
|
"files": {
|
|
12
12
|
"manifest.json": {
|
|
13
|
-
"sha256": "
|
|
13
|
+
"sha256": "6bf27a44120c1bddebbd5827560102c578abf7d52fd0005d223d556906d46dde",
|
|
14
14
|
"bytes": 664381
|
|
15
15
|
},
|
|
16
16
|
"kit.js": {
|
|
17
|
-
"sha256": "
|
|
18
|
-
"bytes":
|
|
17
|
+
"sha256": "8f5be6049c165557ee814ba4b4b456b7b8ea2cf52c079f77b94b9426193e55be",
|
|
18
|
+
"bytes": 6144222
|
|
19
19
|
},
|
|
20
20
|
"kit.css": {
|
|
21
21
|
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DEFAULT_BAR_CHART_LABELS=exports.BarChart=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_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"),_scale=require("./scale.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_BAR_CHART_LABELS=exports.DEFAULT_BAR_CHART_LABELS=Object.freeze({chart:"Bar chart",noData:"no data",highest:(e,t)=>`Highest: ${e}, ${t}`}),AUTO_VALUES_MAX_BARS=7,MAX_BAR_WIDTH=40,BAR_SHARE=.6,MIN_BAR_HEIGHT=2,VALUE_LABEL_ROOM=20,PLOT_PAD=6,HEADER_MIN_HEIGHT=48,AXIS_LABEL_MIN_WIDTH=44,CHAR_WIDTH=8,SWATCH_SIZE=10,STACK_TONES=["primary","info","success","warning","danger","neutral"],FONT_SCALE_CAP=1.2,toneColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],safe=e=>"number"==typeof e&&Number.isFinite(e)?e:0,entryAt=(e,t)=>{const r=e[t];if(void 0===r)throw new Error(`BarChart has no entry at index ${t}.`);return r},defaultFormatValue=e=>(0,_mobileCore.formatNumber)(e),defaultFormatTick=e=>(0,_mobileCore.formatCompactNumber)(e),BarChart=exports.BarChart=(0,_react.forwardRef)((e,t)=>{const{data:r,tone:a="primary",color:i,series:s,height:n=160,label:l,summary:o,formatValue:c=defaultFormatValue,formatTick:u=defaultFormatTick,showValues:d,selection:m,defaultSelection:_=null,onSelect:x,haptic:h,labels:y,style:p,testID:b}=e;(0,_assertValidValue.assertValidValue)("BarChart","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const f=(0,_react.useMemo)(()=>({...DEFAULT_BAR_CHART_LABELS,...y}),[y]),j=(0,_index2.useTheme)(),R=r.length,[v,A]=(0,_react.useState)(0),[g,w]=(0,_index.useControllableState)({value:m,defaultValue:_,onChange:x}),C=null!==g&&g>=0&&g<R?g:null,S=(0,_react.useRef)(C);S.current=C;const T=(0,_react.useRef)(-1),M=(0,_index3.resolveHaptic)(h,"tick"),N=(0,_react.useCallback)(()=>{M&&(0,_index3.triggerHaptic)(M)},[M]),L=d??(R>0&&R<=7),V=void 0!==s&&s.length>0,B=(0,_react.useMemo)(()=>V?s.map((e,t)=>e.tone??entryAt(STACK_TONES,t%STACK_TONES.length)):[],[V,s]),E=(0,_react.useMemo)(()=>V?s.map(e=>e.key):[],[V,s]),D=(0,_react.useMemo)(()=>V?r.map(e=>s.map(t=>safe(e.values?.[t.key]))):null,[r,s,V]),$=(0,_react.useMemo)(()=>D?D.map(e=>e.reduce((e,t)=>e+t,0)):r.map(e=>safe(e.value)),[r,D]),H=(0,_react.useMemo)(()=>D?D.flatMap(e=>[e.reduce((e,t)=>t>0?e+t:e,0),e.reduce((e,t)=>t<0?e+t:e,0)]):$,[D,$]),I=(0,_react.useMemo)(()=>(0,_scale.barScale)(H),[H]),k=L?20:6,O=L&&I.min<0?20:6,F=Math.max(1,n-k-O),G=(0,_react.useCallback)(e=>k+(I.max-e)/(I.max-I.min)*F,[k,I.max,I.min,F]),q=G(0),W=(0,_react.useMemo)(()=>I.ticks.map(e=>u(e)),[I.ticks,u]),U=Math.ceil(8*Math.max(...W.map(e=>e.length),1)*1.2)+j.space.xs,z=R>0?v/R:0,P=Math.max(1,Math.ceil(44/Math.max(1,z||44))),X=(0,_react.useCallback)(e=>{const t=entryAt(r,e);if(t.accessibilityLabel)return t.accessibilityLabel;if(D&&s){const r=entryAt(D,e);return`${t.label}, ${s.map((e,t)=>`${e.label} ${c(entryAt(r,t))}`).join(", ")}`}return`${t.label}, ${c(entryAt($,e))}`},[r,c,$,D,s]),K=(0,_react.useMemo)(()=>{let e=-1,t=0;for(const[r,a]of $.entries())(-1===e||a>t)&&(e=r,t=a);return e},[$]),J=o??(K>=0?f.highest(entryAt(r,K).label,c(entryAt($,K))):""),Y=(0,_react.useRef)({fire:N,setSelected:w,count:R,plotWidth:v});Y.current={fire:N,setSelected:w,count:R,plotWidth:v};const Z=(0,_react.useMemo)(()=>{const indexAt=e=>{const{count:t,plotWidth:r}=Y.current;return 0===t||r<=0||!Number.isFinite(e)?-1:Math.min(t-1,Math.max(0,Math.floor(e/r*t)))},scrubTo=e=>{const t=indexAt(e);t<0||t===T.current||(T.current=t,Y.current.fire(),Y.current.setSelected(t))},e=_reactNativeGestureHandler.Gesture.Pan().runOnJS(!0).activeOffsetX([-8,8]).failOffsetY([-12,12]).onStart(e=>{T.current=S.current??-1,scrubTo(e.x)}).onUpdate(e=>scrubTo(e.x)).withTestId(b?`${b}-pan`:"bar-chart-pan"),t=_reactNativeGestureHandler.Gesture.Tap().runOnJS(!0).onEnd((e,t)=>{if(!t)return;const r=indexAt(e.x);r<0||(Y.current.fire(),T.current=r,Y.current.setSelected(r===S.current?null:r))}).withTestId(b?`${b}-tap`:"bar-chart-tap");return _reactNativeGestureHandler.Gesture.Race(e,t)},[b]),Q=(0,_react.useCallback)(e=>{if(0===R)return;const t=S.current,r="increment"===e.nativeEvent.actionName?null===t?0:Math.min(R-1,t+1):null===t?R-1:Math.max(0,t-1);r!==t&&(N(),w(r))},[R,N,w]),ee=(0,_react.useCallback)(e=>{const t=Math.round(e.nativeEvent.layout.width);A(e=>e===t?e:t)},[]),te=i??toneColor(j,a),re=j.radius.sm,ae=l??f.chart,ie=0===R?`${ae}, ${f.noData}`:J?`${ae}, ${J}`:ae,se=null===C?J:X(C),ne=Math.min(40,Math.max(4,.6*z)),renderStack=(e,t,r)=>{const a=e.reduce((e,t)=>t>0?e+t:e,0),i=e.reduce((e,t)=>t<0?e+t:e,0);if(0===a&&0===i)return null;const s=G(a),n=[];let l=0,o=0;return e.forEach((e,r)=>{if(0===e)return;const a=e>0?l:o,i=a+e;e>0?l=i:o=i;const c=G(a),u=G(i);n.push((0,_jsxRuntime.jsx)(_reactNative.View,{testID:b?`${b}-bar-${t}-series-${r}`:void 0,style:{position:"absolute",left:0,right:0,top:Math.min(c,u)-s,height:Math.abs(c-u),backgroundColor:toneColor(j,entryAt(B,r))}},entryAt(E,r)))}),(0,_jsxRuntime.jsx)(_reactNative.View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(z-ne)/2,top:s,width:ne,height:Math.max(2,G(i)-s),overflow:"hidden",opacity:r?.4:1,..._corners.smoothCorners,...a>0?{borderTopLeftRadius:re,borderTopRightRadius:re}:null,...i<0?{borderBottomLeftRadius:re,borderBottomRightRadius:re}:null},children:n})},le=$.map((e,t)=>{const r=G(e),a=e>=0?r:q,i=0===e?0:Math.max(2,Math.abs(r-q)),s=null!==C&&C!==t;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.slot,{height:n}],children:[v>0&&D?renderStack(entryAt(D,t),t,s):null,v>0&&!D&&i>0?(0,_jsxRuntime.jsx)(_reactNative.View,{testID:b?`${b}-bar-${t}`:void 0,style:{position:"absolute",left:(z-ne)/2,top:a,width:ne,height:i,backgroundColor:te,opacity:s?.4:1,..._corners.smoothCorners,...e>=0?{borderTopLeftRadius:re,borderTopRightRadius:re}:{borderBottomLeftRadius:re,borderBottomRightRadius:re}}}):null,L&&v>0?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"secondary",align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",left:0,right:0,top:e>=0?(D?G(entryAt(H,2*t)):r)-20+2:(D?G(entryAt(H,2*t+1)):r)+2},children:u(e)}):null]},t)});return 0===R?(0,_jsxRuntime.jsx)(_reactNative.View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:ie,testID:b,style:[styles.root,p],children:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",color:"secondary",children:"No data"})}):(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:t,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:ie,accessibilityValue:{min:0,max:R-1,now:C??0,text:se},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Q,testID:b,style:[styles.root,p],children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[styles.header,{minHeight:48,marginBottom:j.space.sm}],children:null===C?J?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",color:"secondary",children:J}):null:(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"secondary",numberOfLines:1,children:entryAt(r,C).label}),(0,_jsxRuntime.jsx)(_index4.Text,{variant:"h3",numberOfLines:1,testID:b?`${b}-callout`:void 0,children:c(entryAt($,C))})]})}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.body,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:U,height:n},children:I.ticks.map((e,t)=>(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"tertiary",align:"right",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",right:j.space.xs,left:0,top:G(e)-8},children:entryAt(W,t)},e))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.plotColumn,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Z,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{height:n},onLayout:ee,testID:b?`${b}-plot`:void 0,children:[I.ticks.map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:{position:"absolute",left:0,right:0,top:G(e)-(0===e?.75:_reactNative.StyleSheet.hairlineWidth),height:0===e?1.5:2*_reactNative.StyleSheet.hairlineWidth,backgroundColor:0===e?j.colors["text-subtle"]:j.colors["border-subtle"]}},e)),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[styles.slots,{height:n}],children:le})]})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.axis,children:r.map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.axisSlot,children:t%P===0?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:C===t?"primary":"tertiary",weight:C===t?"semibold":void 0,align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:z>0?{width:z*P}:void 0,children:e.axisLabel??e.label}):null},t))})]})]}),s&&V?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[styles.legend,{marginTop:j.space.sm,columnGap:j.space.md,rowGap:j.space.xs}],children:s.map((e,t)=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.legendItem,{columnGap:j.space.xs}],children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:10,height:10,borderRadius:j.radius.sm,..._corners.smoothCorners,backgroundColor:toneColor(j,entryAt(B,t))}}),(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,children:e.label})]},e.key))}):null]})});BarChart.displayName="BarChart";const styles=_reactNative.StyleSheet.create({root:{alignSelf:"stretch"},header:{justifyContent:"center"},body:{flexDirection:"row"},plotColumn:{flex:1},slots:{flexDirection:"row"},slot:{flex:1},axis:{flexDirection:"row"},legend:{flexDirection:"row",flexWrap:"wrap"},legendItem:{flexDirection:"row",alignItems:"center"},axisSlot:{flex:1,alignItems:"center",overflow:"visible"}});var _default=exports.default=BarChart;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DEFAULT_BAR_CHART_LABELS=exports.BarChart=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_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"),_scale=require("./scale.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_BAR_CHART_LABELS=exports.DEFAULT_BAR_CHART_LABELS=Object.freeze({chart:"Bar chart",noData:"no data",highest:(e,t)=>`Highest: ${e}, ${t}`}),AUTO_VALUES_MAX_BARS=7,MAX_BAR_WIDTH=40,BAR_SHARE=.6,MIN_BAR_HEIGHT=2,VALUE_LABEL_ROOM=20,PLOT_PAD=6,HEADER_MIN_HEIGHT=48,AXIS_LABEL_MIN_WIDTH=44,CHAR_WIDTH=8,SWATCH_SIZE=10,STACK_TONES=["primary","info","success","warning","danger","neutral"],FONT_SCALE_CAP=1.2,toneColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],safe=e=>"number"==typeof e&&Number.isFinite(e)?e:0,entryAt=(e,t)=>{const r=e[t];if(void 0===r)throw new Error(`BarChart has no entry at index ${t}.`);return r},defaultFormatValue=e=>(0,_mobileCore.formatNumber)(e),defaultFormatTick=e=>(0,_mobileCore.formatCompactNumber)(e),BarChart=exports.BarChart=(0,_react.forwardRef)((e,t)=>{const{data:r,tone:a="primary",color:i,series:s,height:n=160,label:l,summary:o,formatValue:c=defaultFormatValue,formatTick:u=defaultFormatTick,showValues:d,selection:m,defaultSelection:_=null,onSelect:x,haptic:h,labels:y,style:b,testID:p}=e;(0,_assertValidValue.assertValidValue)("BarChart","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const f=(0,_react.useMemo)(()=>({...DEFAULT_BAR_CHART_LABELS,...y}),[y]),j=(0,_index2.useTheme)(),v=r.length,[R,A]=(0,_react.useState)(0),[g,C]=(0,_index.useControllableState)({value:m,defaultValue:_,onChange:x}),S=null!==g&&g>=0&&g<v?g:null,w=(0,_react.useRef)(S);w.current=S;const M=(0,_react.useRef)(-1),T=(0,_index3.resolveHaptic)(h,"tick"),N=(0,_react.useCallback)(()=>{T&&(0,_index3.triggerHaptic)(T)},[T]),L=d??(v>0&&v<=7),V=void 0!==s&&s.length>0,B=(0,_react.useMemo)(()=>V?s.map((e,t)=>e.tone??entryAt(STACK_TONES,t%STACK_TONES.length)):[],[V,s]),D=(0,_react.useMemo)(()=>V?s.map(e=>e.key):[],[V,s]),E=(0,_react.useMemo)(()=>V?r.map(e=>s.map(t=>safe(e.values?.[t.key]))):null,[r,s,V]),$=(0,_react.useMemo)(()=>E?E.map(e=>e.reduce((e,t)=>e+t,0)):r.map(e=>safe(e.value)),[r,E]),H=(0,_react.useMemo)(()=>E?E.flatMap(e=>[e.reduce((e,t)=>t>0?e+t:e,0),e.reduce((e,t)=>t<0?e+t:e,0)]):$,[E,$]),I=(0,_react.useMemo)(()=>(0,_scale.barScale)(H),[H]),k=L?20:6,O=L&&I.min<0?20:6,F=Math.max(1,n-k-O),G=(0,_react.useCallback)(e=>k+(I.max-e)/(I.max-I.min)*F,[k,I.max,I.min,F]),q=G(0),W=(0,_react.useMemo)(()=>I.ticks.map(e=>u(e)),[I.ticks,u]),U=Math.ceil(8*Math.max(...W.map(e=>e.length),1)*1.2)+j.space.xs,z=v>0?R/v:0,P=Math.max(1,Math.ceil(44/Math.max(1,z||44))),X=(0,_react.useCallback)(e=>{const t=entryAt(r,e);if(t.accessibilityLabel)return t.accessibilityLabel;if(E&&s){const r=entryAt(E,e);return`${t.label}, ${s.map((e,t)=>`${e.label} ${c(entryAt(r,t))}`).join(", ")}`}return`${t.label}, ${c(entryAt($,e))}`},[r,c,$,E,s]),K=(0,_react.useMemo)(()=>{let e=-1,t=0;for(const[r,a]of $.entries())(-1===e||a>t)&&(e=r,t=a);return e},[$]),J=o??(K>=0?f.highest(entryAt(r,K).label,c(entryAt($,K))):""),Y=(0,_react.useRef)({fire:N,setSelected:C,count:v,plotWidth:R});Y.current={fire:N,setSelected:C,count:v,plotWidth:R};const Z=(0,_react.useCallback)(e=>{const{count:t,plotWidth:r}=Y.current;return 0===t||r<=0||!Number.isFinite(e)?-1:Math.min(t-1,Math.max(0,Math.floor(e/r*t)))},[]),Q=(0,_react.useCallback)(e=>{const t=Z(e);t<0||t===M.current||(M.current=t,Y.current.fire(),Y.current.setSelected(t))},[Z]),ee=(0,_react.useMemo)(()=>({runOnJS:!0,activeOffsetX:[-8,8],failOffsetY:[-12,12],onActivate:e=>{M.current=w.current??-1,Q(e.x)},onUpdate:e=>Q(e.x),testID:p?`${p}-pan`:"bar-chart-pan"}),[Q,p]),te=(0,_reactNativeGestureHandler.usePanGesture)(ee),re=(0,_react.useMemo)(()=>({runOnJS:!0,onDeactivate:e=>{if(e.canceled)return;const t=Z(e.x);t<0||(Y.current.fire(),M.current=t,Y.current.setSelected(t===w.current?null:t))},testID:p?`${p}-tap`:"bar-chart-tap"}),[Z,p]),ae=(0,_reactNativeGestureHandler.useTapGesture)(re),ie=(0,_reactNativeGestureHandler.useCompetingGestures)(te,ae),se=(0,_react.useCallback)(e=>{if(0===v)return;const t=w.current,r="increment"===e.nativeEvent.actionName?null===t?0:Math.min(v-1,t+1):null===t?v-1:Math.max(0,t-1);r!==t&&(N(),C(r))},[v,N,C]),ne=(0,_react.useCallback)(e=>{const t=Math.round(e.nativeEvent.layout.width);A(e=>e===t?e:t)},[]),le=i??toneColor(j,a),oe=j.radius.sm,ce=l??f.chart,ue=0===v?`${ce}, ${f.noData}`:J?`${ce}, ${J}`:ce,de=null===S?J:X(S),me=Math.min(40,Math.max(4,.6*z)),renderStack=(e,t,r)=>{const a=e.reduce((e,t)=>t>0?e+t:e,0),i=e.reduce((e,t)=>t<0?e+t:e,0);if(0===a&&0===i)return null;const s=G(a),n=[];let l=0,o=0;return e.forEach((e,r)=>{if(0===e)return;const a=e>0?l:o,i=a+e;e>0?l=i:o=i;const c=G(a),u=G(i);n.push((0,_jsxRuntime.jsx)(_reactNative.View,{testID:p?`${p}-bar-${t}-series-${r}`:void 0,style:{position:"absolute",left:0,right:0,top:Math.min(c,u)-s,height:Math.abs(c-u),backgroundColor:toneColor(j,entryAt(B,r))}},entryAt(D,r)))}),(0,_jsxRuntime.jsx)(_reactNative.View,{testID:p?`${p}-bar-${t}`:void 0,style:{position:"absolute",left:(z-me)/2,top:s,width:me,height:Math.max(2,G(i)-s),overflow:"hidden",opacity:r?.4:1,..._corners.smoothCorners,...a>0?{borderTopLeftRadius:oe,borderTopRightRadius:oe}:null,...i<0?{borderBottomLeftRadius:oe,borderBottomRightRadius:oe}:null},children:n})},xe=$.map((e,t)=>{const r=G(e),a=e>=0?r:q,i=0===e?0:Math.max(2,Math.abs(r-q)),s=null!==S&&S!==t;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.slot,{height:n}],children:[R>0&&E?renderStack(entryAt(E,t),t,s):null,R>0&&!E&&i>0?(0,_jsxRuntime.jsx)(_reactNative.View,{testID:p?`${p}-bar-${t}`:void 0,style:{position:"absolute",left:(z-me)/2,top:a,width:me,height:i,backgroundColor:le,opacity:s?.4:1,..._corners.smoothCorners,...e>=0?{borderTopLeftRadius:oe,borderTopRightRadius:oe}:{borderBottomLeftRadius:oe,borderBottomRightRadius:oe}}}):null,L&&R>0?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"secondary",align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",left:0,right:0,top:e>=0?(E?G(entryAt(H,2*t)):r)-20+2:(E?G(entryAt(H,2*t+1)):r)+2},children:u(e)}):null]},t)});return 0===v?(0,_jsxRuntime.jsx)(_reactNative.View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:ue,testID:p,style:[styles.root,b],children:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",color:"secondary",children:"No data"})}):(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:t,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:ue,accessibilityValue:{min:0,max:v-1,now:S??0,text:de},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:se,testID:p,style:[styles.root,b],children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[styles.header,{minHeight:48,marginBottom:j.space.sm}],children:null===S?J?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",color:"secondary",children:J}):null:(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"secondary",numberOfLines:1,children:entryAt(r,S).label}),(0,_jsxRuntime.jsx)(_index4.Text,{variant:"h3",numberOfLines:1,testID:p?`${p}-callout`:void 0,children:c(entryAt($,S))})]})}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.body,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:U,height:n},children:I.ticks.map((e,t)=>(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"tertiary",align:"right",numberOfLines:1,maxFontSizeMultiplier:1.2,style:{position:"absolute",right:j.space.xs,left:0,top:G(e)-8},children:entryAt(W,t)},e))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.plotColumn,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ie,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{height:n},onLayout:ne,testID:p?`${p}-plot`:void 0,children:[I.ticks.map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:{position:"absolute",left:0,right:0,top:G(e)-(0===e?.75:_reactNative.StyleSheet.hairlineWidth),height:0===e?1.5:2*_reactNative.StyleSheet.hairlineWidth,backgroundColor:0===e?j.colors["text-subtle"]:j.colors["border-subtle"]}},e)),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[styles.slots,{height:n}],children:xe})]})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.axis,children:r.map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.axisSlot,children:t%P===0?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:S===t?"primary":"tertiary",weight:S===t?"semibold":void 0,align:"center",numberOfLines:1,maxFontSizeMultiplier:1.2,style:z>0?{width:z*P}:void 0,children:e.axisLabel??e.label}):null},t))})]})]}),s&&V?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[styles.legend,{marginTop:j.space.sm,columnGap:j.space.md,rowGap:j.space.xs}],children:s.map((e,t)=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.legendItem,{columnGap:j.space.xs}],children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:10,height:10,borderRadius:j.radius.sm,..._corners.smoothCorners,backgroundColor:toneColor(j,entryAt(B,t))}}),(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"secondary",numberOfLines:1,maxFontSizeMultiplier:1.2,children:e.label})]},e.key))}):null]})});BarChart.displayName="BarChart";const styles=_reactNative.StyleSheet.create({root:{alignSelf:"stretch"},header:{justifyContent:"center"},body:{flexDirection:"row"},plotColumn:{flex:1},slots:{flexDirection:"row"},slot:{flex:1},axis:{flexDirection:"row"},legend:{flexDirection:"row",flexWrap:"wrap"},legendItem:{flexDirection:"row",alignItems:"center"},axisSlot:{flex:1,alignItems:"center",overflow:"visible"}});var _default=exports.default=BarChart;
|
|
@@ -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:y=!1,presentation:x="sheet",animateMount:R=!0,handleIndicatorStyle:N,containerStyle:g,header:w,actions:j,actionsLayout:C="auto",footer:M,headerStyle:O,footerStyle:E,children:T,accessibilityLabel:k,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!=w||null!=d,L=null!=j&&j.length>0,P=null!=M||L,D=y?"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"===x||"auto"===x&&Math.min(Y.width,Y.height)>=600,$=Math.min(560,J-2*H.space.xl),[X,Q]=(0,_ModalSafeArea.useModalInsets)(),Z="modal"===D?X.top:q.top,ee="modal"===D?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+(P?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),ye=(0,_reactNativeReanimated.useSharedValue)(1),xe=(0,_reactNativeReanimated.useSharedValue)(-1),[Re,Ne]=(0,_react.useState)(-1),ge=(0,_react.useRef)(!1),[we,je]=(0,_react.useState)(!1),[Ce,Me]=(0,_react.useState)(!1),Oe=(0,_react.useRef)(!1),Ee=(0,_react.useRef)(i);Ee.current=i;const[Te,ke]=(0,_react.useState)(!1),Ae=(0,_react.useRef)(!R&&a),Be=(0,_react.useRef)(-1),Ve=(0,_react.useRef)(!1);Ve.current="modal"===D?Ce:Te;const Ie=(0,_react.useRef)(u);Ie.current=u;const Le=(0,_react.useRef)(r);Le.current=r;const Pe=(0,_react.useRef)(!1),De=(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)(()=>(De.current=!0,()=>{De.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;Re!==e&&(Ne(e),xe.value=e,e>=0&&o?.(e))},[Re,xe,o]),Ue=(0,_react.useCallback)(()=>{ge.current=!1,xe.value<0&&(Oe.current=!0,"modal"===D?(je(!1),"ios"!==_reactNative.Platform.OS&&Me(!1)):ke(!1))},[D,xe]),Je=(0,_react.useCallback)(()=>{Oe.current&&Me(!1)},[]);(0,_react.useEffect)(()=>{("modal"===D?!Ce:!Te)&&Oe.current&&(Oe.current=!1,Ee.current?.(),Ge(!0))},[D,Ce,Te,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):Re>=0?Re:0,a=xe.value,r=qe(t);return Oe.current=!1,Ge(!1),"modal"===D?(Me(!0),je(!0)):ke(!0),a<0&&Ae.current?(be.value=r,ye.value=1,Fe(t),void s?.(a,t)):a<0&&G.reduced?(be.value=r,ye.value=0,ye.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,ye.value=1),Fe(t),void ze(r,a,t))},[ze,fe,Re,xe,D,s,G,ye,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=xe.value;Fe(-1),ge.current=!0,s?.(t,-1);const a=G.reduced?ye: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,xe,Ue,s,G,ye,Fe,be,H.motion.ease.accelerate]),Ke=(0,_react.useCallback)((e,t,a)=>{const r=Ie.current;if(!r)return void e();if(Pe.current)return void t?.();const n=r();"boolean"!=typeof n?(Pe.current=!0,a?.(),n.then(a=>{Pe.current=!1,a&&De.current&&Be.current>=0?e():t?.()},e=>{throw Pe.current=!1,e})):(n?e:t)?.()},[]),$e=(0,_react.useCallback)(()=>new Promise(e=>{Be.current<0?e(!0):Ke(()=>{Le.current(),Ye(),e(!0)},()=>e(!1))}),[Ye,Ke]),Xe=(0,_react.useCallback)(()=>{Le.current()},[]),Qe=(0,_react.useCallback)(()=>{l&&$e()},[l,$e]),Ze=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{const e=Ze.current!==a;Ze.current=a,e?a?We(n??0):Ye():a&&"number"==typeof n&&n!==xe.value&&We(n)},[a,n]);const et=(0,_react.useRef)({hostHeight:F,contentSnap:he});(0,_react.useEffect)(()=>{const e=et.current;if(e.hostHeight===F&&e.contentSnap===he)return;if(et.current={hostHeight:F,contentSnap:he},e.hostHeight===F&&xe.value<0)return;const t=qe(xe.value);be.value=Ae.current?t:(0,_reactNativeReanimated.withSpring)(t,SPRING_CONFIG)},[F,he]);const tt=F-Se,at=(0,_react.useMemo)(()=>ve.map(e=>F-e),[ve,F]),rt=(0,_react.useCallback)(()=>{const e=Be.current;e<0||ze(qe(e),e,e)},[ze,qe]),nt=(0,_react.useCallback)((e,t)=>{const a=xe.value;-1!==e?(Fe(e),ze(t,a,e)):Ke(()=>{_reactNative.Keyboard.dismiss(),(0,_index2.triggerHaptic)("selection"),Le.current(),Ye()},rt,rt)},[ze,Ye,xe,Ke,Fe,rt]),ot=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Native().withTestId(B?`${B}-content-gesture`:"bottom-sheet-content-gesture"),[B]),st=(0,_react.useMemo)(()=>{const e=at,t=fe,a=tt,r=c;return _reactNativeGestureHandler.Gesture.Pan().withTestId(B?`${B}-pan-gesture`:"bottom-sheet-pan-gesture").activeOffsetY([-10,10]).failOffsetX([-15,15]).onStart(()=>{"worklet";pe.value=be.value}).onUpdate(e=>{"worklet";const t=pe.value+e.translationY;be.value=t<a?a+.25*(t-a):t}).onEnd(a=>{"worklet";const n=be.value,o=a.velocityY,[s]=e;if(void 0===s)return void(0,_reactNativeReanimated.runOnJS)(nt)(-1,t);if(o>1e3)return r?void(0,_reactNativeReanimated.runOnJS)(nt)(-1,t):void(0,_reactNativeReanimated.runOnJS)(nt)(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)(nt)(-1,t):(0,_reactNativeReanimated.runOnJS)(nt)(i,c)})},[fe,pe,c,nt,tt,at,B,be]),{height:it}=(0,_reactNativeKeyboardController.useReanimatedKeyboardAnimation)(),ct="shift"===p,lt=(0,_reactNativeReanimated.useDerivedValue)(()=>ct?it.value:0,[ct,it]),ut=ve[Re>=0?Re:0]??Se,dt=H.space.md,_t=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{if(K){const e=lt.value,t=F+e-ut-dt,a=e<0&&be.value>t?t:be.value;return{top:a<Z?Z:a,opacity:ye.value}}const e=be.value+lt.value,t=lt.value<0?Z:tt;return{top:e<t?t:e,opacity:ye.value}},[K,lt,F,ut,dt,be,Z,ye,tt]),ht=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=lt.value;if(K){const t=F+e-ut-dt,a=e<0&&be.value>t?t:be.value,r=F+e-dt-(a<Z?Z:a);return{height:r<0?0:r>ut?ut:r}}const t=e<0?Z:tt,a=be.value+e,r=F+e-(a<t?t:a);return{height:r<0?0:r>Se?Se:r}},[lt,K,F,ut,dt,be,Z,tt,Se]),mt=Re>=0,vt=(0,_react.useMemo)(()=>buildStyles(H),[H]),ft=(0,_react.useCallback)(()=>{l&&Ke(()=>{(0,_index2.triggerHaptic)("selection"),Le.current(),Ye()})},[l,Ye,Ke]),St=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Tap().withTestId(B?`${B}-backdrop-gesture`:"bottom-sheet-backdrop-gesture").maxDuration(250).onEnd((_e,e)=>{"worklet";e&&(0,_reactNativeReanimated.runOnJS)(ft)()}),[ft,B]),bt=(0,_react.useMemo)(()=>({snapIndex:Re,snapPoints:ve,close:Xe,requestClose:$e}),[Re,ve,Xe,$e]);if("inline"===D&&!Te)return null;if("modal"===D&&!Ce)return null;const pt=(0,_jsxRuntime.jsxs)(_reactNative.View,{collapsable:!1,style:["modal"===D?vt.backdropModal:vt.backdropInline,{backgroundColor:"modal"===D?(0,_color.transparentOf)(H.colors.scrim):H.colors.scrim}],onLayout:W,testID:B,accessibilityViewIsModal:A??mt,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:St,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:k,accessibilityViewIsModal:A??mt,accessibilityActions:[{name:"escape",label:V.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[vt.sheet,{height:Se,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,..._corners.smoothCorners,...H.shadow.modal},K?{height:ut,left:(J-$)/2,right:void 0,width:$,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,g,_t],children:(0,_jsxRuntime.jsxs)(SheetBody,{style:[vt.body,ht],keyboardOffset:lt,children:[K?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:H.space.md}}):(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:st,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:vt.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:[vt.handle,{backgroundColor:H.colors.border},N]})})}),I&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[vt.header,O],onLayout:te?oe:void 0,children:[null!=d?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",accessibilityRole:"header",children:d}):null,w]}),h?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ot,children:(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{ref:m,style:vt.scrollContent,onScroll:v,onContentSizeChange:me,onLayout:S,scrollEventThrottle:b,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:T})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:te?[vt.content,{overflow:"visible"}]:vt.content,children:te?(0,_jsxRuntime.jsx)(_reactNative.View,{onLayout:ie,children:T}):T}),P&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[vt.footer,E],onLayout:te?ue:void 0,children:[L?(0,_jsxRuntime.jsx)(_reactNative.View,{style:vt.actions,children:(0,_jsxRuntime.jsx)(_OverlayActions.OverlayActions,{actions:j??[],layout:C})}):null,M]})]})})]}),yt=(0,_jsxRuntime.jsx)(BottomSheetContext.Provider,{value:bt,children:pt});return"modal"===D?(0,_jsxRuntime.jsx)(_Modal.Modal,{open:we,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:vt.modalRoot,children:yt}):yt}):yt};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:e>0?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"),_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:y=!1,presentation:x="sheet",animateMount:R=!0,handleIndicatorStyle:N,containerStyle:g,header:j,actions:C,actionsLayout:w="auto",footer:M,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!=j||null!=d,D=null!=C&&C.length>0,L=null!=M||D,P=y?"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"===x||"auto"===x&&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),ye=(0,_reactNativeReanimated.useSharedValue)(1),xe=(0,_reactNativeReanimated.useSharedValue)(-1),[Re,Ne]=(0,_react.useState)(-1),ge=(0,_react.useRef)(!1),[je,Ce]=(0,_react.useState)(!1),[we,Me]=(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)(!R&&a),Be=(0,_react.useRef)(-1),Ve=(0,_react.useRef)(!1);Ve.current="modal"===P?we: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;Re!==e&&(Ne(e),xe.value=e,e>=0&&o?.(e))},[Re,xe,o]),Ue=(0,_react.useCallback)(()=>{ge.current=!1,xe.value<0&&(Oe.current=!0,"modal"===P?(Ce(!1),"ios"!==_reactNative.Platform.OS&&Me(!1)):Te(!1))},[P,xe]),Je=(0,_react.useCallback)(()=>{Oe.current&&Me(!1)},[]);(0,_react.useEffect)(()=>{("modal"===P?!we:!ke)&&Oe.current&&(Oe.current=!1,Ee.current?.(),Ge(!0))},[P,we,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):Re>=0?Re:0,a=xe.value,r=qe(t);return Oe.current=!1,Ge(!1),"modal"===P?(Me(!0),Ce(!0)):Te(!0),a<0&&Ae.current?(be.value=r,ye.value=1,Fe(t),void s?.(a,t)):a<0&&G.reduced?(be.value=r,ye.value=0,ye.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,ye.value=1),Fe(t),void ze(r,a,t))},[ze,fe,Re,xe,P,s,G,ye,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=xe.value;Fe(-1),ge.current=!0,s?.(t,-1);const a=G.reduced?ye: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,xe,Ue,s,G,ye,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);(0,_react.useEffect)(()=>{const e=Ze.current!==a;Ze.current=a,e?a?We(n??0):Ye():a&&"number"==typeof n&&n!==xe.value&&We(n)},[a,n]);const et=(0,_react.useRef)({hostHeight:F,contentSnap:he});(0,_react.useEffect)(()=>{const e=et.current;if(e.hostHeight===F&&e.contentSnap===he)return;if(et.current={hostHeight:F,contentSnap:he},e.hostHeight===F&&xe.value<0)return;const t=qe(xe.value);be.value=Ae.current?t:(0,_reactNativeReanimated.withSpring)(t,SPRING_CONFIG)},[F,he]);const tt=F-Se,at=(0,_react.useMemo)(()=>ve.map(e=>F-e),[ve,F]),rt=(0,_react.useCallback)(()=>{const e=Be.current;e<0||ze(qe(e),e,e)},[ze,qe]),nt=(0,_react.useCallback)((e,t)=>{const a=xe.value;-1!==e?(Fe(e),ze(t,a,e)):Ke(()=>{_reactNative.Keyboard.dismiss(),(0,_index2.triggerHaptic)("selection"),De.current(),Ye()},rt,rt)},[ze,Ye,xe,Ke,Fe,rt]),ot=(0,_react.useMemo)(()=>({testID:B?`${B}-content-gesture`:"bottom-sheet-content-gesture"}),[B]),st=(0,_reactNativeGestureHandler.useNativeGesture)(ot),it=(0,_react.useMemo)(()=>{const e=at,t=fe,a=tt,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)(nt)(-1,t);if(o>1e3)return r?void(0,_reactNativeReanimated.runOnJS)(nt)(-1,t):void(0,_reactNativeReanimated.runOnJS)(nt)(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)(nt)(-1,t):(0,_reactNativeReanimated.runOnJS)(nt)(i,c)}}},[fe,pe,c,nt,tt,at,B,be]),ct=(0,_reactNativeGestureHandler.usePanGesture)(it),{height:lt}=(0,_reactNativeKeyboardController.useReanimatedKeyboardAnimation)(),ut="shift"===p,dt=(0,_reactNativeReanimated.useDerivedValue)(()=>ut?lt.value:0,[ut,lt]),_t=ve[Re>=0?Re:0]??Se,ht=H.space.md,mt=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{if(K){const e=dt.value,t=F+e-_t-ht,a=e<0&&be.value>t?t:be.value;return{top:a<Z?Z:a,opacity:ye.value}}const e=be.value+dt.value,t=dt.value<0?Z:tt;return{top:e<t?t:e,opacity:ye.value}},[K,dt,F,_t,ht,be,Z,ye,tt]),vt=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=dt.value;if(K){const t=F+e-_t-ht,a=e<0&&be.value>t?t:be.value,r=F+e-ht-(a<Z?Z:a);return{height:r<0?0:r>_t?_t:r}}const t=e<0?Z:tt,a=be.value+e,r=F+e-(a<t?t:a);return{height:r<0?0:r>Se?Se:r}},[dt,K,F,_t,ht,be,Z,tt,Se]),ft=Re>=0,St=(0,_react.useMemo)(()=>buildStyles(H),[H]),bt=(0,_react.useCallback)(()=>{l&&Ke(()=>{(0,_index2.triggerHaptic)("selection"),De.current(),Ye()})},[l,Ye,Ke]),pt=(0,_react.useMemo)(()=>({testID:B?`${B}-backdrop-gesture`:"bottom-sheet-backdrop-gesture",maxDuration:250,onDeactivate:e=>{"worklet";e.canceled||(0,_reactNativeReanimated.runOnJS)(bt)()}}),[bt,B]),yt=(0,_reactNativeGestureHandler.useTapGesture)(pt),xt=(0,_react.useMemo)(()=>({snapIndex:Re,snapPoints:ve,close:Xe,requestClose:$e}),[Re,ve,Xe,$e]);if("inline"===P&&!ke)return null;if("modal"===P&&!we)return null;const Rt=(0,_jsxRuntime.jsxs)(_reactNative.View,{collapsable:!1,style:["modal"===P?St.backdropModal:St.backdropInline,{backgroundColor:"modal"===P?(0,_color.transparentOf)(H.colors.scrim):H.colors.scrim}],onLayout:W,testID:B,accessibilityViewIsModal:A??ft,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:yt,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??ft,accessibilityActions:[{name:"escape",label:V.close}],onAccessibilityAction:e=>{"escape"===e.nativeEvent.actionName&&Qe()},onAccessibilityEscape:Qe,style:[St.sheet,{height:Se,backgroundColor:H.colors.surface,borderTopLeftRadius:H.radius.xl,borderTopRightRadius:H.radius.xl,..._corners.smoothCorners,...H.shadow.modal},K?{height:_t,left:(J-$)/2,right:void 0,width:$,borderBottomLeftRadius:H.radius.xl,borderBottomRightRadius:H.radius.xl}:null,g,mt],children:(0,_jsxRuntime.jsxs)(SheetBody,{style:[St.body,vt],keyboardOffset:dt,children:[K?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:H.space.md}}):(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ct,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:St.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:[St.handle,{backgroundColor:H.colors.border},N]})})}),I&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[St.header,O],onLayout:te?oe:void 0,children:[null!=d?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",accessibilityRole:"header",children:d}):null,j]}),h?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:st,children:(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{ref:m,style:St.scrollContent,onScroll:v,onContentSizeChange:me,onLayout:S,scrollEventThrottle:b,keyboardShouldPersistTaps:"always",keyboardDismissMode:"none",children:k})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:te?[St.content,{overflow:"visible"}]:St.content,children:te?(0,_jsxRuntime.jsx)(_reactNative.View,{onLayout:ie,children:k}):k}),L&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[St.footer,E],onLayout:te?ue:void 0,children:[D?(0,_jsxRuntime.jsx)(_reactNative.View,{style:St.actions,children:(0,_jsxRuntime.jsx)(_OverlayActions.OverlayActions,{actions:C??[],layout:w})}):null,M]})]})})]}),Nt=(0,_jsxRuntime.jsx)(BottomSheetContext.Provider,{value:xt,children:Rt});return"modal"===P?(0,_jsxRuntime.jsx)(_Modal.Modal,{open:je,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:St.modalRoot,children:Nt}):Nt}):Nt};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:e>0?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 +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:
|
|
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 x="left"===n||"right"===n,M=(0,_react.useMemo)(()=>resolveSize(s,x,S),[s,x,S]),O=(0,_react.useMemo)(()=>closedOffsetOf(n,M),[n,M]),D=(0,_reactNativeReanimated.useSharedValue)(r?0:O),L=(0,_reactNativeReanimated.useSharedValue)(r?0:O),C=(0,_reactNativeReanimated.useSharedValue)(r?1:0),[A,T]=(0,_react.useState)(r),j=(0,_reactNativeReanimated.useSharedValue)(r);(0,_react.useEffect)(()=>{A||R||(D.value=O,L.value=O)},[O,A,D,L,R]);const k=h.motion.spring.snappy,P=(0,_react.useCallback)(()=>{if(R)return D.value=0,void(C.value=(0,_reactNativeReanimated.withTiming)(1,{duration:g,reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION}));C.value=1,D.value=(0,_reactNativeReanimated.withSpring)(0,k)},[D,C,k,R,g]),V=(0,_react.useCallback)(()=>{R?C.value=(0,_reactNativeReanimated.withTiming)(0,{duration:N,reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&(D.value=O)}):D.value=(0,_reactNativeReanimated.withSpring)(O,k)},[D,C,O,k,R,N]),q=(0,_react.useCallback)(e=>{T(t=>t===e?t:(i?.(e),e)),j.value=e},[i,j]),F=(0,_react.useCallback)(()=>{q(!0),P()},[q,P]),I=(0,_react.useCallback)(()=>{q(!1),V()},[q,V]),U=(0,_react.useCallback)(()=>{A?I():F()},[A,F,I]);(0,_react.useImperativeHandle)(t,()=>({open:F,close:I,toggle:U}),[F,I,U]),(0,_react.useEffect)(()=>{E&&a!==A&&(a?F():I())},[a]);const B=(0,_react.useMemo)(()=>{const e=O,t=n,a=o;return{...x?{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=x?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=x?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,_reactNativeReanimated.runOnJS)(q)(!1),R?C.value=(0,_reactNativeReanimated.withTiming)(0,{duration:N,reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION},t=>{"worklet";t&&(D.value=e)}):D.value=(0,_reactNativeReanimated.withSpring)(e,k)):((0,_reactNativeReanimated.runOnJS)(q)(!0),R?(D.value=0,C.value=(0,_reactNativeReanimated.withTiming)(1,{duration:g,reduceMotion:_usePresenceMotion.PRESENCE_REDUCE_MOTION})):D.value=(0,_reactNativeReanimated.withSpring)(0,k))}}},[O,L,o,x,D,C,q,n,k,R,g,N]),H=(0,_reactNativeGestureHandler.usePanGesture)(B),W=(0,_reactNativeReanimated.useAnimatedStyle)(()=>x?{opacity:C.value,transform:[{translateX:D.value}]}:{opacity:C.value,transform:[{translateY:D.value}]},[x,D,C]),G=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:(0,_reactNativeReanimated.interpolate)(D.value,[O,0],[0,l],_reactNativeReanimated.Extrapolation.CLAMP)*C.value,pointerEvents:Math.abs(D.value-O)<.5?"none":"auto"}),[D,O,l,C]),Y=(0,_react.useMemo)(()=>buildStyles(h),[h]),X=(0,_react.useCallback)(()=>{if(!c)return;const e=(0,_index2.resolveHaptic)(u,"selection");e&&(0,_index2.triggerHaptic)(e),I()},[c,I,u]),z=(0,_react.useMemo)(()=>sideLayoutOf(n,M,w),[n,M,w]),J=(0,_react.useRef)(r);return A&&(J.current=!0),J.current?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_reactNative.StyleSheet.absoluteFill,pointerEvents:"box-none",testID:f,accessibilityViewIsModal:A,children:[(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[Y.backdrop,{backgroundColor:h.colors.scrim},G],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:X,accessibilityRole:"button",accessibilityLabel:m.close,disabled:!c||!A})}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:H,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{accessibilityRole:"alert",accessibilityLabel:v??m.drawer,style:[z,{backgroundColor:h.colors.surface,...h.shadow.modal},d,W],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:Y.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.useFloatingLabel=exports.FLOATED_LABEL_SCALE=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_textInk=require("../Text/textInk.js"),_FieldBase=require("./FieldBase.js"),_jsxRuntime=require("react/jsx-runtime");const FLOATED_LABEL_SCALE=exports.FLOATED_LABEL_SCALE=.85,FLOATED_LABEL_LIFT=1,useFloatingLabel=({label:e,enabled:t,floated:i,required:n=!1,variant:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useFloatingLabel=exports.FLOATED_LABEL_SCALE=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_textInk=require("../Text/textInk.js"),_FieldBase=require("./FieldBase.js"),_jsxRuntime=require("react/jsx-runtime");const FLOATED_LABEL_SCALE=exports.FLOATED_LABEL_SCALE=.85,FLOATED_LABEL_LIFT=1,useFloatingLabel=({label:e,enabled:t,floated:i,required:n=!1,variant:r,sizeTokens:a,leadingOffset:o,trailingOffset:s=0,textAlign:l="left",paddingLeft:u,lineHeight:d,restNudge:c=0,floatTrim:_=0,color:x,style:g})=>{const h=(0,_index.useTheme)(),v=(0,_react.useRef)((0,_index.createAnimatedValue)(i?1:0)).current,L=(0,_react.useRef)((0,_index.createAnimatedValue)(i?1:0)).current,f="outline"===r,[p,m]=(0,_react.useState)(null);return(0,_react.useEffect)(()=>{const e=i?1:0,timing=(t,i)=>_reactNative.Animated.timing(t,{toValue:e,duration:h.motion.duration.fast,easing:_reactNative.Easing.bezier(...h.motion.ease["in-out"]),useNativeDriver:i});f||L.setValue(e);const t=f?_reactNative.Animated.parallel([timing(v,_nativeDriver.nativeDriver),timing(L,!1)]):timing(v,_nativeDriver.nativeDriver);return t.start(),()=>t.stop()},[i,f,v,L,h.motion.duration.fast,h.motion.ease["in-out"]]),(0,_react.useMemo)(()=>{if(!t||!(0,_FieldBase.hasFieldText)(e))return{node:null,topNotch:void 0};const i=d??p?.height??a.text,r=null!=d?a["padding-y"]+c:Math.max(0,(a["min-height"]-i)/2),A=-(r+i/2+1-_),E=v.interpolate({inputRange:[0,1],outputRange:[0,A]}),F=v.interpolate({inputRange:[0,1],outputRange:[1,FLOATED_LABEL_SCALE]}),R=-o,S=v.interpolate({inputRange:[0,1],outputRange:[0,R]}),T="right"===l?{right:a["padding-x"]+s,transformOrigin:"right center"}:"center"===l?{alignSelf:"center",transformOrigin:"center"}:{left:u+o,transformOrigin:"left center"},j=h.space.xs,D=p?p.width*FLOATED_LABEL_SCALE:0,O=p?"right"===l?p.width-D:"center"===l?(p.width-D)/2:0:0,b=f&&p?{left:p.x+R+O-j,width:L.interpolate({inputRange:[0,1],outputRange:[0,D+2*j]})}:void 0,N=_reactNative.StyleSheet.flatten(g),y={fontSize:N?.fontSize??a.text,color:N?.color??x};return{node:(0,_jsxRuntime.jsxs)(_reactNative.Animated.Text,{pointerEvents:"none",onLayout:e=>{const{x:t,width:i,height:n}=e.nativeEvent.layout;m(e=>e&&e.x===t&&e.width===i&&e.height===n?e:{x:t,width:i,height:n})},style:[styles.label,T,{top:r,color:x,fontSize:a.text,lineHeight:d,...(0,_index.fontFor)(h,"medium"),transform:[{translateX:S},{translateY:E},{scale:F}]},g],children:[(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:y,children:e}),n?(0,_jsxRuntime.jsx)(_FieldBase.RequiredMark,{}):null]}),topNotch:b}},[t,e,n,f,a,o,s,l,u,d,c,_,x,g,v,L,p,h])};exports.useFloatingLabel=useFloatingLabel;const styles=_reactNative.StyleSheet.create({label:{position:"absolute",zIndex:1}});
|
|
@@ -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");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:u})=>{const[l,r]=(0,_react.useState)(1),v=(0,_reactNativeReanimated.useAnimatedRef)(),n=(0,_reactNativeReanimated.useScrollViewOffset)(v),c=(0,_reactNativeReanimated.useSharedValue)(0),m=(0,_reactNativeReanimated.useSharedValue)(0),s=(0,_reactNativeReanimated.useSharedValue)(0),o=(0,_reactNativeReanimated.useSharedValue)(0),d=(0,_reactNativeReanimated.useSharedValue)(1),_=(0,_reactNativeReanimated.useSharedValue)(1),N=(0,_reactNativeReanimated.useSharedValue)(0),R=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),w=(0,_reactNativeReanimated.useSharedValue)(0);(0,_react.useEffect)(()=>{s.value=t,o.value=i,m.value=u},[t,i,u,s,o,m]);const S=(0,_react.useCallback)(()=>{d.value=(0,_reactNativeReanimated.withTiming)(1),N.value=(0,_reactNativeReanimated.withTiming)(0),R.value=(0,_reactNativeReanimated.withTiming)(0),_.value=1,h.value=0,w.value=0,r(1)},[d,_,N,R,h,w]);(0,_react.useEffect)(()=>{e||S()},[e,S]);const p=(0,_react.useCallback)(e=>r(e),[]),T=(0,_reactNativeGestureHandler.useNativeGesture)(),O=Math.max(1,a),M=Math.min(2.5,O),f=(0,_react.useMemo)(()=>({enabled:e,simultaneousWith:T,onActivate:()=>{"worklet";_.value=d.value,h.value=N.value,w.value=R.value},onUpdate:e=>{"worklet";const a=clamp(_.value*e.scale,1,O),t=e.focalX-s.value/2,i=e.focalY-o.value/2,u=a/_.value,l=panLimit(s.value,a),r=panLimit(o.value,a);N.value=clamp(t-(t-h.value)*u,-l,l),R.value=clamp(i-(i-w.value)*u,-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),R.value=(0,_reactNativeReanimated.withTiming)(0),_.value=1,h.value=0,w.value=0,void(0,_reactNativeReanimated.runOnJS)(p)(1);_.value=d.value,h.value=N.value,w.value=R.value,(0,_reactNativeReanimated.runOnJS)(p)(d.value)}}),[e,O,p,T,d,_,N,R,h,w,s,o]),g=(0,_react.useMemo)(()=>({enabled:e,simultaneousWith:T,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";h.value=N.value,w.value=R.value,c.value=n.value},onUpdate:e=>{"worklet";const a=d.value,t=panLimit(s.value,a),i=panLimit(o.value,a);N.value=clamp(h.value+e.translationX,-t,t);const u=w.value+e.translationY,l=clamp(u,-i,i),r=u-l;if(0!==r){const e=clamp(c.value-r/a,0,m.value);e!==c.value&&(c.value=e,(0,_reactNativeReanimated.scrollTo)(v,0,e,!1)),w.value-=r}R.value=l},onDeactivate:()=>{"worklet";h.value=N.value,w.value=R.value}}),[e,T,n,c,m,s,o,d,N,R,h,w,v]),G=(0,_react.useMemo)(()=>({enabled:e,simultaneousWith:T,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),R.value=(0,_reactNativeReanimated.withTiming)(0),_.value=1,h.value=0,w.value=0,void(0,_reactNativeReanimated.runOnJS)(p)(1);if(M<=ZOOM_REST)return;const a=e.x-s.value/2,t=e.y-o.value/2,i=panLimit(s.value,M),u=panLimit(o.value,M),l=clamp(-a*(M-1),-i,i),r=clamp(-t*(M-1),-u,u);d.value=(0,_reactNativeReanimated.withTiming)(M),N.value=(0,_reactNativeReanimated.withTiming)(l),R.value=(0,_reactNativeReanimated.withTiming)(r),_.value=M,h.value=l,w.value=r,(0,_reactNativeReanimated.runOnJS)(p)(M)}}),[e,T,M,p,d,_,N,R,h,w,s,o]),V=(0,_reactNativeGestureHandler.usePinchGesture)(f),Z=(0,_reactNativeGestureHandler.usePanGesture)(g),k=(0,_reactNativeGestureHandler.useTapGesture)(G),x=(0,_reactNativeGestureHandler.useSimultaneousGestures)(V,Z,k),E=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:N.value},{translateY:R.value},{scale:d.value}]}),[N,R,d]);return{scrollRef:v,scrollGesture:T,zoomGesture:x,zoomStyle:E,zoomLevel:l,resetZoom:S}};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]),[x,v]=(0,_react.useState)(clamp(a,0,Math.max(0,e.length-1))),[p,b]=(0,_react.useState)(!1),R=(0,_react.useCallback)(e=>{v(e),n?.(e)},[n]),S=(0,_react.useCallback)(()=>{if(!l)return;const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!0)},[l,s]),y=(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:S,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,S,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:R,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(x+1,e.length),children:`${x+1} / ${e.length}`})}):null]}),l?(0,_jsxRuntime.jsx)(Lightbox,{open:p,images:e,initialIndex:x,enablePinchZoom:r,showCounter:i,onClose:y,onIndexChange:R,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);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:Array.from({length:n}).map((e,a)=>(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:64,height:64,radius:"md",style:{marginRight:r.space.sm}},`sk-thumb-${a}`))}):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]),x=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"]})}),x?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:u.captionWrap,entering:void 0,accessibilityElementsHidden:!1,children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",align:"center",numberOfLines:3,style:u.captionText,children:x})}):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),x=(0,_reactNativeReanimated.useSharedValue)(0),v=(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,x.value=0},[d,m,_,h,g,x]);_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,x.value=0)},[i,d,_,h,m,g,x]);const p=(0,_react.useCallback)(()=>{!1!==o&&(0,_index2.triggerHaptic)("impactLight")},[o]),b=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Pinch().enabled(l).onStart(()=>{"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}).onEnd(()=>{"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(x.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,x,n,r]),R=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Pan().minPointers(1).maxPointers(1).onStart(()=>{"worklet";g.value=_.value,x.value=h.value}).onUpdate(e=>{"worklet";d.value<=1||(_.value=g.value+e.translationX,h.value=x.value+e.translationY)}).onEnd(()=>{"worklet";g.value=_.value,x.value=h.value}),[d,_,h,g,x]),S=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Tap().numberOfTaps(2).onEnd(()=>{"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,x.value=0):(d.value=(0,_reactNativeReanimated.withSpring)(s,SPRING_CONFIG),m.value=s)}),[d,m,_,h,g,x,p,s]),y=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Race(b,R,S),[b,R,S]),I=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:_.value},{translateY:h.value},{scale:d.value}]}),[_,h,d]);_react.default.useEffect(()=>{i||v()},[i,v]);const N=e.alt??c(a+1,t);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:y,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,I],accessibilityLabel:N,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"],lineHeight:21}}),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")),_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),R=(0,_react.useCallback)(e=>{x(e),n?.(e)},[n]),y=(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)((t,a)=>{const i=t.alt??g.imageOf(a+1,e.length);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:y,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,y,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:t,onIndexChange:R,renderItem:I,showPagination:!1,showThumbnails:a,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:R,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);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:Array.from({length:n}).map((e,t)=>(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:64,height:64,radius:"md",style:{marginRight:r.space.sm}},`sk-thumb-${t}`))}):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,entering:void 0,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]),R=(0,_reactNativeGestureHandler.usePinchGesture)(b),y=(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)(y),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)(R,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(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"],lineHeight:21}}),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_OPTION_SHEET_LABELS=void 0,exports.OptionSheet=OptionSheet,exports.default=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index2=require("../Modal/index.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const SEARCH_ICON_SIZE=18,DEFAULT_OPTION_SHEET_LABELS=exports.DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`}),selectOptionLabel=e=>e.label,selectOptionValue=e=>e.value,selectOptionDescription=e=>e.description,selectOptionDisabled=e=>!0===e.disabled,selectOptionIcon=e=>e.icon,hostStyle=_reactNative.StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:i,options:r,sections:s,renderSectionHeader:o,renderOption:a,alphabetIndex:n=!1,labels:l,getOptionLabel:c,getOptionValue:d,getOptionDescription:u,isOptionDisabled:p,getOptionIcon:h,destructiveOf:m,value:x,onChange:_,multi:b=!1,searchable:g=!1,searchSelectionColor:y,accessibilityLabel:j,optionStyle:f,selectedOptionStyle:S,optionTextStyle:R,selectedOptionTextStyle:v,testID:T}=e,w=c??selectOptionLabel,C=d??selectOptionValue,N=u??selectOptionDescription,L=p??selectOptionDisabled,O=h??selectOptionIcon,I=(0,_index.useTheme)(),k=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),D=(0,_react.useMemo)(()=>buildStyles(I),[I]),[H,V]=(0,_react.useState)(""),P=_reactNative.Dimensions.get("window").height,E=Math.round(.7*P),M=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,{handleGesture:A,opacity:B}=(0,_useDragToDismiss.useDragToDismiss)({drag:M,travel:E,onDismiss:t}),z=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Native(),[]),F=(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.height),W=Math.max(0,Math.round(F)),q=Math.max(k.top,_reactNative.StatusBar.currentHeight??0)+I.space.sm,G=W>0,U=G?Math.max(0,Math.min(E,P-W-q)):E,$=(0,_react.useMemo)(()=>{const e=g?H.trim().toLowerCase():"",matches=t=>0===e.length||w(t).toLowerCase().includes(e)||(N(t)??"").toLowerCase().includes(e);if(!s)return r.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return s.forEach((e,i)=>{const r=e.options.filter(matches);if(0!==r.length){t.push({kind:"header",title:e.title});for(const e of r)t.push({kind:"option",option:e,section:i})}}),t},[g,H,r,s,w,N]),K=(0,_react.useCallback)(()=>{t()},[t]),J=(0,_react.useRef)(null),Y=(0,_react.useMemo)(()=>{const e=new Map;if(!n)return e;let t=0;if(s)for(const[e,i]of $.entries())"header"===i.kind&&(t=e+1);for(const[i,r]of $.entries()){if(i<t||"option"!==r.kind)continue;const s=w(r.option).trim().charAt(0).toUpperCase(),o=/^[A-Z]$/.test(s)?s:"#";e.has(o)||e.set(o,i)}return e},[n,$,s,w]),Z=n&&Y.size>0&&0===H.trim().length,Q=(0,_react.useMemo)(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Y.has("#")?["#"]:[]],[Y]),X=(0,_react.useCallback)(e=>{const t=Y.get(e);void 0!==t&&J.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Y]),ee=(0,_react.useRef)(null),te=(0,_react.useCallback)(()=>{null!==ee.current&&(clearTimeout(ee.current),ee.current=null)},[]),ie=(0,_react.useCallback)(e=>{J.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),te(),ee.current=setTimeout(()=>{ee.current=null,J.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[te]);(0,_react.useEffect)(()=>te,[te]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:D.gestureRoot,children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{testID:T,accessibilityViewIsModal:!0,accessibilityLabel:j??i??l.fallbackName,style:[D.sheet,{maxHeight:U,marginBottom:W,paddingBottom:G?I.space.lg:k.bottom+I.space.lg,backgroundColor:I.colors.surface,borderTopLeftRadius:I.radius.xl,borderTopRightRadius:I.radius.xl,..._corners.smoothCorners,opacity:B,transform:[{translateY:M}],...I.shadow.modal}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:A,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.sheetHandleRow,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.sheetHandle,{backgroundColor:I.colors.border}]})}),i?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",style:[D.sheetTitle,{paddingHorizontal:I.space.lg,marginBottom:I.space.sm}],children:i}):null]})}),g?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.searchWrap,{marginHorizontal:I.space.lg,marginBottom:I.space.sm}],children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[D.searchBox,{backgroundColor:I.colors["bg-subtle"],borderColor:I.colors.border,borderRadius:I.radius.md,..._corners.smoothCorners,paddingHorizontal:I.space.md,gap:I.space.sm}],children:[(I.settings.icons.search??_defaultIcons.defaultIcons.search)({size:18,color:I.colors["text-subtle"]}),(0,_jsxRuntime.jsx)(_reactNative.TextInput,{value:H,onChangeText:V,placeholder:l.searchPlaceholder,placeholderTextColor:I.colors["text-subtle"],selectionColor:y??I.colors["focus-ring"],accessibilityLabel:l.searchOptions,style:[D.searchInput,{color:I.colors["text-body"],fontSize:I.text.base.size,paddingVertical:I.space.sm}]}),H.length>0?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>V(""),hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:l.clearSearch,children:(I.settings.icons.close??_defaultIcons.defaultIcons.close)({size:18,color:I.colors["text-muted"]})}):null]})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[D.listWrap,Z?D.listRow:null],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:z,children:(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:J,data:$,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(C(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return(0,_jsxRuntime.jsx)(_reactNative.View,{accessible:!0,accessibilityRole:"header",style:[D.sectionHeader,{paddingHorizontal:I.space.lg,paddingTop:I.space.md}],children:o?o(e.title):(0,_jsxRuntime.jsx)(_index3.Text,{variant:"caption",weight:"semibold",color:"tertiary",style:D.sectionTitle,children:e.title.toUpperCase()})});const i=e.option,r=w(i),s=C(i),n=N(i),l=O(i),c=(d=s,Array.isArray(x)?x.some(e=>String(e)===String(d)):null!=x&&String(x)===String(d));var d;const u=L(i),p=m?.(i)??!1;return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>_(s,i),disabled:u,android_ripple:{color:I.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:r,accessibilityState:{selected:c,disabled:u},"aria-selected":c,"aria-disabled":u,style:({pressed:e})=>[D.optionRow,{backgroundColor:c?I.colors["surface-selected"]:e?I.colors["surface-pressed"]:"transparent",opacity:u?.5:1,paddingHorizontal:I.space.lg,paddingVertical:I.space.md},f,c?S:null],children:[a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.optionTextWrap,children:a({option:i,selected:c,disabled:u,index:t})}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[l?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.optionIcon,children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.optionTextWrap,children:[(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:c?"semibold":"medium",color:p?"danger":c?"brand":void 0,style:[D.optionLabel,R,c?v:null],children:r}),n?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:D.optionDescription,children:n}):null]})]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.checkbox,{borderColor:c?I.colors.primary:I.colors.border,backgroundColor:c?I.colors.primary:"transparent"}],children:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.checkboxTick}):null}):c?"icon"===I.settings.components["option-sheet"]?.selectedMarker?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.singleSelectedIcon,children:(I.settings.icons.selectedTick??_defaultIcons.defaultIcons.selectedTick)({size:20,color:I.colors.primary})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.singleSelectedDot,{backgroundColor:I.colors.primary}]}):null]})},onScrollToIndexFailed:ie,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!Z,style:Z?D.listBesideRail:null,ListEmptyComponent:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:I.space.xl},children:l.empty})})}),Z?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.rail,{paddingRight:I.space.xs}],accessibilityRole:"list",accessibilityLabel:l.jumpToLetter,testID:"option-sheet-alphabet",children:Q.map(e=>{const t=Y.has(e);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>X(e),disabled:!t,hitSlop:{left:8,right:8},...(0,_hitSlop.hitSlopMarker)({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:l.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:D.railLetter,children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[D.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.sheetFooter,{borderTopColor:I.colors["border-subtle"],paddingHorizontal:I.space.lg,paddingVertical:I.space.md}],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:K,accessibilityRole:"button",accessibilityLabel:l.done,style:({pressed:e})=>[D.doneButton,{backgroundColor:e?I.colors["primary-pressed"]:I.colors.primary,borderRadius:I.radius.md,..._corners.smoothCorners,paddingVertical:I.space.sm,paddingHorizontal:I.space.lg}],children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:"semibold",style:{color:I.colors["on-primary"]},children:l.done})})}):null]})})}function OptionSheet(e){const{open:t,onOpenChange:i,onAfterClose:r,labels:s,onClose:o,haptic:a,...n}=e,l=(0,_react.useMemo)(()=>({...DEFAULT_OPTION_SHEET_LABELS,...s}),[s]),c=(0,_react.useRef)(i);c.current=i;const d=(0,_react.useRef)(!1);return(0,_react.useEffect)(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),(0,_jsxRuntime.jsx)(_index2.Modal,{open:t,onClose:o,presentation:"bottom",onDismissed:r,haptic:a,contentStyle:hostStyle,labels:{close:l.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??l.fallbackName,children:(0,_jsxRuntime.jsx)(OptionSheetPanel,{...n,onClose:o,labels:l})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>_reactNative.StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:14},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,..._corners.smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,..._corners.smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:_reactNative.StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});var _default=exports.default=OptionSheet;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_OPTION_SHEET_LABELS=void 0,exports.OptionSheet=OptionSheet,exports.default=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index2=require("../Modal/index.js"),_index3=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const SEARCH_ICON_SIZE=18,DEFAULT_OPTION_SHEET_LABELS=exports.DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`}),selectOptionLabel=e=>e.label,selectOptionValue=e=>e.value,selectOptionDescription=e=>e.description,selectOptionDisabled=e=>!0===e.disabled,selectOptionIcon=e=>e.icon,hostStyle=_reactNative.StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:i,options:r,sections:s,renderSectionHeader:o,renderOption:a,alphabetIndex:n=!1,labels:l,getOptionLabel:c,getOptionValue:d,getOptionDescription:u,isOptionDisabled:p,getOptionIcon:h,destructiveOf:m,value:x,onChange:_,multi:b=!1,searchable:g=!1,searchSelectionColor:y,accessibilityLabel:j,optionStyle:f,selectedOptionStyle:S,optionTextStyle:R,selectedOptionTextStyle:v,testID:T}=e,w=c??selectOptionLabel,C=d??selectOptionValue,N=u??selectOptionDescription,L=p??selectOptionDisabled,O=h??selectOptionIcon,I=(0,_index.useTheme)(),k=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),D=(0,_react.useMemo)(()=>buildStyles(I),[I]),[H,V]=(0,_react.useState)(""),P=_reactNative.Dimensions.get("window").height,E=Math.round(.7*P),A=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,{handleGesture:B,opacity:M}=(0,_useDragToDismiss.useDragToDismiss)({drag:A,travel:E,onDismiss:t}),z=(0,_reactNativeGestureHandler.useNativeGesture)(),F=(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.height),W=Math.max(0,Math.round(F)),q=Math.max(k.top,_reactNative.StatusBar.currentHeight??0)+I.space.sm,G=W>0,U=G?Math.max(0,Math.min(E,P-W-q)):E,$=(0,_react.useMemo)(()=>{const e=g?H.trim().toLowerCase():"",matches=t=>0===e.length||w(t).toLowerCase().includes(e)||(N(t)??"").toLowerCase().includes(e);if(!s)return r.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return s.forEach((e,i)=>{const r=e.options.filter(matches);if(0!==r.length){t.push({kind:"header",title:e.title});for(const e of r)t.push({kind:"option",option:e,section:i})}}),t},[g,H,r,s,w,N]),K=(0,_react.useCallback)(()=>{t()},[t]),J=(0,_react.useRef)(null),Y=(0,_react.useMemo)(()=>{const e=new Map;if(!n)return e;let t=0;if(s)for(const[e,i]of $.entries())"header"===i.kind&&(t=e+1);for(const[i,r]of $.entries()){if(i<t||"option"!==r.kind)continue;const s=w(r.option).trim().charAt(0).toUpperCase(),o=/^[A-Z]$/.test(s)?s:"#";e.has(o)||e.set(o,i)}return e},[n,$,s,w]),Z=n&&Y.size>0&&0===H.trim().length,Q=(0,_react.useMemo)(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Y.has("#")?["#"]:[]],[Y]),X=(0,_react.useCallback)(e=>{const t=Y.get(e);void 0!==t&&J.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Y]),ee=(0,_react.useRef)(null),te=(0,_react.useCallback)(()=>{null!==ee.current&&(clearTimeout(ee.current),ee.current=null)},[]),ie=(0,_react.useCallback)(e=>{J.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),te(),ee.current=setTimeout(()=>{ee.current=null,J.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[te]);(0,_react.useEffect)(()=>te,[te]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:D.gestureRoot,children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{testID:T,accessibilityViewIsModal:!0,accessibilityLabel:j??i??l.fallbackName,style:[D.sheet,{maxHeight:U,marginBottom:W,paddingBottom:G?I.space.lg:k.bottom+I.space.lg,backgroundColor:I.colors.surface,borderTopLeftRadius:I.radius.xl,borderTopRightRadius:I.radius.xl,..._corners.smoothCorners,opacity:M,transform:[{translateY:A}],...I.shadow.modal}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:B,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.sheetHandleRow,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.sheetHandle,{backgroundColor:I.colors.border}]})}),i?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",style:[D.sheetTitle,{paddingHorizontal:I.space.lg,marginBottom:I.space.sm}],children:i}):null]})}),g?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.searchWrap,{marginHorizontal:I.space.lg,marginBottom:I.space.sm}],children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[D.searchBox,{backgroundColor:I.colors["bg-subtle"],borderColor:I.colors.border,borderRadius:I.radius.md,..._corners.smoothCorners,paddingHorizontal:I.space.md,gap:I.space.sm}],children:[(I.settings.icons.search??_defaultIcons.defaultIcons.search)({size:18,color:I.colors["text-subtle"]}),(0,_jsxRuntime.jsx)(_reactNative.TextInput,{value:H,onChangeText:V,placeholder:l.searchPlaceholder,placeholderTextColor:I.colors["text-subtle"],selectionColor:y??I.colors["focus-ring"],accessibilityLabel:l.searchOptions,style:[D.searchInput,{color:I.colors["text-body"],fontSize:I.text.base.size,paddingVertical:I.space.sm}]}),H.length>0?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>V(""),hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:l.clearSearch,children:(I.settings.icons.close??_defaultIcons.defaultIcons.close)({size:18,color:I.colors["text-muted"]})}):null]})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[D.listWrap,Z?D.listRow:null],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:z,children:(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:J,data:$,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(C(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return(0,_jsxRuntime.jsx)(_reactNative.View,{accessible:!0,accessibilityRole:"header",style:[D.sectionHeader,{paddingHorizontal:I.space.lg,paddingTop:I.space.md}],children:o?o(e.title):(0,_jsxRuntime.jsx)(_index3.Text,{variant:"caption",weight:"semibold",color:"tertiary",style:D.sectionTitle,children:e.title.toUpperCase()})});const i=e.option,r=w(i),s=C(i),n=N(i),l=O(i),c=(d=s,Array.isArray(x)?x.some(e=>String(e)===String(d)):null!=x&&String(x)===String(d));var d;const u=L(i),p=m?.(i)??!1;return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>_(s,i),disabled:u,android_ripple:{color:I.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:r,accessibilityState:{selected:c,disabled:u},"aria-selected":c,"aria-disabled":u,style:({pressed:e})=>[D.optionRow,{backgroundColor:c?I.colors["surface-selected"]:e?I.colors["surface-pressed"]:"transparent",opacity:u?.5:1,paddingHorizontal:I.space.lg,paddingVertical:I.space.md},f,c?S:null],children:[a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.optionTextWrap,children:a({option:i,selected:c,disabled:u,index:t})}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[l?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.optionIcon,children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.optionTextWrap,children:[(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:c?"semibold":"medium",color:p?"danger":c?"brand":void 0,style:[D.optionLabel,R,c?v:null],children:r}),n?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:D.optionDescription,children:n}):null]})]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.checkbox,{borderColor:c?I.colors.primary:I.colors.border,backgroundColor:c?I.colors.primary:"transparent"}],children:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.checkboxTick}):null}):c?"icon"===I.settings.components["option-sheet"]?.selectedMarker?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.singleSelectedIcon,children:(I.settings.icons.selectedTick??_defaultIcons.defaultIcons.selectedTick)({size:20,color:I.colors.primary})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.singleSelectedDot,{backgroundColor:I.colors.primary}]}):null]})},onScrollToIndexFailed:ie,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!Z,style:Z?D.listBesideRail:null,ListEmptyComponent:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:I.space.xl},children:l.empty})})}),Z?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.rail,{paddingRight:I.space.xs}],accessibilityRole:"list",accessibilityLabel:l.jumpToLetter,testID:"option-sheet-alphabet",children:Q.map(e=>{const t=Y.has(e);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>X(e),disabled:!t,hitSlop:{left:8,right:8},...(0,_hitSlop.hitSlopMarker)({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:l.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:D.railLetter,children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[D.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.sheetFooter,{borderTopColor:I.colors["border-subtle"],paddingHorizontal:I.space.lg,paddingVertical:I.space.md}],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:K,accessibilityRole:"button",accessibilityLabel:l.done,style:({pressed:e})=>[D.doneButton,{backgroundColor:e?I.colors["primary-pressed"]:I.colors.primary,borderRadius:I.radius.md,..._corners.smoothCorners,paddingVertical:I.space.sm,paddingHorizontal:I.space.lg}],children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:"semibold",style:{color:I.colors["on-primary"]},children:l.done})})}):null]})})}function OptionSheet(e){const{open:t,onOpenChange:i,onAfterClose:r,labels:s,onClose:o,haptic:a,...n}=e,l=(0,_react.useMemo)(()=>({...DEFAULT_OPTION_SHEET_LABELS,...s}),[s]),c=(0,_react.useRef)(i);c.current=i;const d=(0,_react.useRef)(!1);return(0,_react.useEffect)(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),(0,_jsxRuntime.jsx)(_index2.Modal,{open:t,onClose:o,presentation:"bottom",onDismissed:r,haptic:a,contentStyle:hostStyle,labels:{close:l.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??l.fallbackName,children:(0,_jsxRuntime.jsx)(OptionSheetPanel,{...n,onClose:o,labels:l})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>_reactNative.StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:14},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,..._corners.smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,..._corners.smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:_reactNative.StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});var _default=exports.default=OptionSheet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.SignaturePad=exports.DEFAULT_SIGNATURE_PAD_LABELS=void 0;var cache,_mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeSvg=_interopRequireWildcard(require("react-native-svg")),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_index2=require("../Button/index.js"),_index3=require("../Input/index.js"),_index4=require("../Text/index.js"),_signatureGeometry=require("./signatureGeometry.js"),_writePng=require("./writePng"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var n,a,r=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(a in e)"default"!==a&&{}.hasOwnProperty.call(e,a)&&((n=r&&Object.getOwnPropertyDescriptor(e,a))&&(n.get||n.set)?r(i,a,n):i[a]=e[a]);return i}const DEFAULT_SIGNATURE_PAD_LABELS=exports.DEFAULT_SIGNATURE_PAD_LABELS=Object.freeze({pad:"Signature pad",padHint:"Draw with one finger. To sign without drawing, use the type your name action.",caption:"Sign above the line. To start with an up or down stroke, rest your finger a moment first.",typedCaption:"Your typed name is used as your signature.",undo:"Undo",clear:"Clear",typeInstead:"Type your name instead",drawInstead:"Draw instead",typedLabel:"Type your name",typedPlaceholder:"Your full name",empty:"Not signed",signed:"Signed",typingAnnouncement:"Signing by typing your name. Your typed name is used as your signature. Choose Draw instead to sign with your finger.",drawingAnnouncement:"Signing by drawing. Use one finger on the pad.",clearedAnnouncement:"Signature cleared",undoneAnnouncement:"Last stroke removed",emptyError:"Add a signature first.",expand:"Expand",done:"Done",close:"Close"}),STROKE_WIDTH=2.5,SIDEWAYS_TO_DRAW=6,UPRIGHT_TO_SCROLL=8,REST_TO_DRAW_MS=200,MIN_POINT_GAP=.8,DEFAULT_HEIGHT=180,EXPANDED_CHROME=200,DEFAULT_NAME_LENGTH=100,MAX_EXPORT_SCALE=3,MIN_TARGET=44,BASELINE_OPACITY=.3,DISABLED_OPACITY=.5,TARGET_STYLE={minHeight:44},defaultScriptFont=()=>_reactNative.Platform.select({ios:"Snell Roundhand",default:"cursive"}),cssFontStack=e=>"cursive"===e?"cursive":`'${e}', cursive`,useScreenReader=()=>{const[e,t]=(0,_react.useState)(!1);return(0,_react.useEffect)(()=>{let e=!0;_reactNative.AccessibilityInfo.isScreenReaderEnabled().then(n=>{e&&t(n)});const n=_reactNative.AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,n.remove()}},[]),e},StrokePath=(0,_react.memo)(({points:e,color:t})=>(0,_jsxRuntime.jsx)(_reactNativeSvg.Path,{d:(0,_signatureGeometry.strokePath)(e),stroke:t,strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}));StrokePath.displayName="SignaturePadStroke";const Marks=({mode:e,strokes:t,name:n,color:a,fontFamily:r,width:i,height:s})=>"draw"===e?(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:t.map(e=>(0,_jsxRuntime.jsx)(StrokePath,{points:e.points,color:a},e.id))}):n?(0,_jsxRuntime.jsx)(_reactNativeSvg.Text,{x:i/2,y:s*_signatureGeometry.BASELINE_RATIO,fontSize:(0,_signatureGeometry.typedFontSize)(i,n),fontFamily:r,textAnchor:"middle",fill:a,children:n}):null,SignaturePadSurface=(0,_react.forwardRef)((e,t)=>{const{expandable:n,initialStrokes:a,onChange:r,initialTypedName:i="",onTypedNameChange:s,defaultMode:o="draw",onModeChange:c,onEmptyChange:d,allowTyped:l=!0,signedBy:u,signedAt:_,height:m=DEFAULT_HEIGHT,maxNameLength:p=DEFAULT_NAME_LENGTH,inkColor:g,paperColor:h,scriptFontFamily:y,labels:x,haptic:f="selection",disabled:S=!1,style:v,testID:R}=e;(0,_assertValidValue.assertValidValue)("SignaturePad","defaultMode",e.defaultMode,["draw","type"]);const b=(0,_index.useTheme)(),j=void 0===g&&void 0===h,w=j?b.colors["text-body"]:g??_index.lightTheme.colors["text-body"],T=j?b.colors.surface:h??_index.lightTheme.colors.surface,E=j?_index.lightTheme.colors["text-body"]:w,A=j?_index.lightTheme.colors.surface:T,C=E!==w||A!==T,N=y??defaultScriptFont(),P=(0,_react.useMemo)(()=>({...DEFAULT_SIGNATURE_PAD_LABELS,...x}),[x]),I=useScreenReader(),L=(0,_react.useRef)(null),D=(0,_react.useRef)(null),[k,G]=(0,_react.useState)(0),[M,F]=(0,_react.useState)(()=>(a??[]).map((e,t)=>({id:t+1,points:[...e]}))),O=(0,_react.useRef)(M),H=(0,_react.useRef)(M.length),B=(0,_react.useRef)(null),q=(0,_react.useRef)(null),[U,V]=(0,_react.useState)(l?o:"draw"),[W,Y]=(0,_react.useState)(i),[$,z]=(0,_react.useState)(null),X=(0,_react.useRef)(!1),{height:K}=(0,_reactNative.useWindowDimensions)(),[J,Q]=(0,_react.useState)(!1),[Z,ee]=(0,_react.useState)([]),te=(0,_react.useRef)({onChange:r,onTypedNameChange:s,onModeChange:c,onEmptyChange:d});(0,_react.useEffect)(()=>{te.current={onChange:r,onTypedNameChange:s,onModeChange:c,onEmptyChange:d}});const ne="draw"===U&&!S,ae="draw"===U?0===M.length:0===W.trim().length,re=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{re.current!==ae&&(re.current=ae,te.current.onEmptyChange?.(ae))},[ae]);const ie=(0,_react.useCallback)(e=>{O.current=e,F(e)},[]),se=(0,_react.useCallback)(()=>{z(Date.now()),te.current.onChange?.(O.current.map(e=>e.points))},[]),oe=(0,_react.useMemo)(()=>{const pan=e=>_reactNativeGestureHandler.Gesture.Pan().enabled(ne).runOnJS(!0).onBegin(e=>{B.current=(0,_signatureGeometry.pointOf)(e.x,e.y)}).onStart(t=>{q.current=e,H.current+=1;const n=(0,_signatureGeometry.pointOf)(t.x,t.y);ie([...O.current,{id:H.current,points:[B.current??n,n]}])}).onUpdate(t=>{if(q.current!==e)return;const n=O.current[O.current.length-1];if(void 0===n)throw new Error("The stroke being drawn is missing.");const a=(0,_signatureGeometry.pointOf)(t.x,t.y),r=n.points[n.points.length-1];if(void 0===r)throw new Error("A drawn stroke has no points.");(0,_signatureGeometry.distanceBetween)(r,a)<.8||ie([...O.current.slice(0,-1),{...n,points:[...n.points,a]}])}).onFinalize(()=>{q.current===e&&(q.current=null,se())}),e=pan("sideways").activeOffsetX([-6,6]).failOffsetY([-8,8]),t=pan("rested").activateAfterLongPress(200);return _reactNativeGestureHandler.Gesture.Race(e,t)},[ne,ie,se]),ce=(0,_react.useCallback)(e=>{V(e),te.current.onModeChange?.(e),(0,_announce.announce)("type"===e?P.typingAnnouncement:P.drawingAnnouncement)},[P.typingAnnouncement,P.drawingAnnouncement]);(0,_react.useEffect)(()=>{I&&l&&!X.current&&"draw"===U&&0===O.current.length&&ce("type")},[I,l,U,ce]);const de=(0,_react.useCallback)(()=>{X.current=!0,ce("draw"===U?"type":"draw")},[U,ce]),le=(0,_react.useCallback)(e=>{Y(e),z(Date.now()),te.current.onTypedNameChange?.(e)},[]),ue=(0,_react.useCallback)(()=>{"type"===U?le(""):(ie([]),se()),(0,_announce.announce)(P.clearedAnnouncement)},[U,le,ie,se,P.clearedAnnouncement]),me=(0,_react.useCallback)(()=>{"draw"===U&&0!==O.current.length&&(ie(O.current.slice(0,-1)),se(),(0,_announce.announce)(P.undoneAnnouncement))},[U,ie,se,P.undoneAnnouncement]),pe=(0,_react.useCallback)(()=>{ee(O.current.map(e=>e.points)),Q(!0)},[]),ge=(0,_react.useCallback)(()=>{Q(!1)},[]),he=(0,_react.useCallback)(()=>{ie(Z.map(e=>(H.current+=1,{id:H.current,points:[...e]}))),se(),Q(!1)},[Z,ie,se]),ye=k||_signatureGeometry.FALLBACK_WIDTH;(0,_react.useImperativeHandle)(t,()=>({toFile:()=>new Promise((e,t)=>{if(ae)return void t(new Error(P.emptyError));const n=C?D.current:L.current;if(!n)return void t(new Error("The signature pad is not on screen."));const a=Math.min(3,Math.max(1,_reactNative.PixelRatio.get()));n.toDataURL(n=>{(0,_writePng.writePng)(n).then(e,t)},{width:ye*a,height:m*a})}),toSvg:()=>(0,_signatureGeometry.buildSignatureSvg)({width:ye,height:m,mode:U,strokes:M.map(e=>e.points),typedName:W,ink:E,paper:A,strokeWidth:2.5,fontFamily:cssFontStack(N)}),clear:ue,undo:me,isEmpty:()=>ae}),[ae,P.emptyError,ye,m,U,M,W,C,E,A,N,ue,me]);const xe=(0,_react.useMemo)(()=>[{name:"undo",label:P.undo},{name:"clear",label:P.clear},...l?[{name:"toggleMode",label:"draw"===U?P.typeInstead:P.drawInstead}]:[]],[P.undo,P.clear,P.typeInstead,P.drawInstead,l,U]),fe=(0,_react.useCallback)(e=>{if(S)return;const{actionName:t}=e.nativeEvent;"undo"===t?me():"clear"===t?ue():"toggleMode"===t&&l&&de()},[S,me,ue,de,l]),Se=(0,_react.useCallback)(e=>{G(e.nativeEvent.layout.width)},[]),ve=(0,_react.useMemo)(()=>_reactNative.StyleSheet.create({root:{gap:b.space.sm},pad:{height:m,borderWidth:b.size.border,borderColor:b.colors.border,borderRadius:b.radius.md,..._corners.smoothCorners,overflow:"hidden",backgroundColor:T,opacity:S?.5:1},baseline:{position:"absolute",left:b.space.md,right:b.space.md,top:m*_signatureGeometry.BASELINE_RATIO,height:_reactNative.StyleSheet.hairlineWidth,backgroundColor:w,opacity:.3},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:b.space.xs},trailing:{flexDirection:"row",alignItems:"center",gap:b.space.xs},expandedRoot:{flex:1,padding:b.space.md,gap:b.space.sm,backgroundColor:b.colors.bg},expandedBar:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"}}),[b,m,T,w,S]),Re=W.trim(),be=_??$,je=u&&!ae?`Signed by ${u}${be?`, ${(0,_mobileCore.formatDateTime)(be)}`:""}`:null,we="type"===U&&Re?`${P.pad}. ${Re}`:P.pad;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[ve.root,v],testID:R,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:oe,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:ve.pad,onLayout:Se,accessible:!0,accessibilityRole:"image",accessibilityLabel:we,accessibilityHint:"draw"===U?P.padHint:void 0,accessibilityValue:{text:ae?P.empty:P.signed},accessibilityState:{disabled:S},"aria-disabled":S,accessibilityActions:xe,onAccessibilityAction:fe,children:[C?(0,_jsxRuntime.jsxs)(_reactNativeSvg.default,{ref:D,style:_reactNative.StyleSheet.absoluteFill,width:"100%",height:m,children:[(0,_jsxRuntime.jsx)(_reactNativeSvg.Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:A}),(0,_jsxRuntime.jsx)(Marks,{mode:U,strokes:M,name:Re,color:E,fontFamily:N,width:ye,height:m})]}):null,(0,_jsxRuntime.jsxs)(_reactNativeSvg.default,{ref:L,width:"100%",height:m,children:[(0,_jsxRuntime.jsx)(_reactNativeSvg.Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:T}),(0,_jsxRuntime.jsx)(Marks,{mode:U,strokes:M,name:Re,color:w,fontFamily:N,width:ye,height:m})]}),(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:ve.baseline})]})}),"type"===U?(0,_jsxRuntime.jsx)(_index3.Input,{label:P.typedLabel,placeholder:P.typedPlaceholder,value:W,onChangeText:le,maxLength:p,disabled:S,autoComplete:"name",textContentType:"name",autoCapitalize:"words",autoCorrect:!1,returnKeyType:"done",testID:R?`${R}-name`:void 0}):null,(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"tertiary",children:"draw"===U?P.caption:P.typedCaption}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:ve.actions,children:[l?(0,_jsxRuntime.jsx)(_index2.Button,{label:"draw"===U?P.typeInstead:P.drawInstead,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:de,testID:R?`${R}-mode`:void 0}):(0,_jsxRuntime.jsx)(_reactNative.View,{}),"draw"===U?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:ve.trailing,children:[M.length>0?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index2.Button,{label:P.undo,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:me,testID:R?`${R}-undo`:void 0}),(0,_jsxRuntime.jsx)(_index2.Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:ue,testID:R?`${R}-clear`:void 0})]}):null,n?(0,_jsxRuntime.jsx)(_index2.Button,{label:P.expand,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:pe,testID:R?`${R}-expand`:void 0}):null]}):null,"type"===U&&Re?(0,_jsxRuntime.jsx)(_index2.Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:ue,testID:R?`${R}-clear`:void 0}):null]}),je?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"secondary",children:je}):null,n?(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:J,animationType:"slide",presentationStyle:"fullScreen",onRequestClose:ge,children:(0,_jsxRuntime.jsxs)(ExpandedRoot,{style:ve.expandedRoot,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:ve.expandedBar,children:[(0,_jsxRuntime.jsx)(_index2.Button,{label:P.close,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,onPress:ge,testID:R?`${R}-close`:void 0}),(0,_jsxRuntime.jsx)(_index2.Button,{label:P.done,variant:"solid",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,onPress:he,testID:R?`${R}-done`:void 0})]}),J?(0,_jsxRuntime.jsx)(SignaturePadSurface,{expandable:!1,defaultMode:"draw",allowTyped:!1,initialStrokes:Z,onChange:ee,height:Math.max(DEFAULT_HEIGHT,K-200),inkColor:g,paperColor:h,scriptFontFamily:y,labels:x,haptic:f,testID:R?`${R}-expanded`:void 0}):null]})}):null]})});SignaturePadSurface.displayName="SignaturePadSurface";const ExpandedRoot="android"===_reactNative.Platform.OS?_reactNativeGestureHandler.GestureHandlerRootView:_reactNative.View,SignaturePad=exports.SignaturePad=(0,_react.forwardRef)((e,t)=>(0,_jsxRuntime.jsx)(SignaturePadSurface,{...e,expandable:!0,ref:t}));SignaturePad.displayName="SignaturePad";var _default=exports.default=SignaturePad;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.SignaturePad=exports.DEFAULT_SIGNATURE_PAD_LABELS=void 0;var cache,_mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeSvg=_interopRequireWildcard(require("react-native-svg")),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_index2=require("../Button/index.js"),_index3=require("../Input/index.js"),_index4=require("../Text/index.js"),_signatureGeometry=require("./signatureGeometry.js"),_writePng=require("./writePng"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var n,a,r=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(a in e)"default"!==a&&{}.hasOwnProperty.call(e,a)&&((n=r&&Object.getOwnPropertyDescriptor(e,a))&&(n.get||n.set)?r(i,a,n):i[a]=e[a]);return i}const DEFAULT_SIGNATURE_PAD_LABELS=exports.DEFAULT_SIGNATURE_PAD_LABELS=Object.freeze({pad:"Signature pad",padHint:"Draw with one finger. To sign without drawing, use the type your name action.",caption:"Sign above the line. To start with an up or down stroke, rest your finger a moment first.",typedCaption:"Your typed name is used as your signature.",undo:"Undo",clear:"Clear",typeInstead:"Type your name instead",drawInstead:"Draw instead",typedLabel:"Type your name",typedPlaceholder:"Your full name",empty:"Not signed",signed:"Signed",typingAnnouncement:"Signing by typing your name. Your typed name is used as your signature. Choose Draw instead to sign with your finger.",drawingAnnouncement:"Signing by drawing. Use one finger on the pad.",clearedAnnouncement:"Signature cleared",undoneAnnouncement:"Last stroke removed",emptyError:"Add a signature first.",expand:"Expand",done:"Done",close:"Close"}),STROKE_WIDTH=2.5,SIDEWAYS_TO_DRAW=6,UPRIGHT_TO_SCROLL=8,REST_TO_DRAW_MS=200,MIN_POINT_GAP=.8,DEFAULT_HEIGHT=180,EXPANDED_CHROME=200,DEFAULT_NAME_LENGTH=100,MAX_EXPORT_SCALE=3,MIN_TARGET=44,BASELINE_OPACITY=.3,DISABLED_OPACITY=.5,TARGET_STYLE={minHeight:44},defaultScriptFont=()=>_reactNative.Platform.select({ios:"Snell Roundhand",default:"cursive"}),cssFontStack=e=>"cursive"===e?"cursive":`'${e}', cursive`,useScreenReader=()=>{const[e,t]=(0,_react.useState)(!1);return(0,_react.useEffect)(()=>{let e=!0;_reactNative.AccessibilityInfo.isScreenReaderEnabled().then(n=>{e&&t(n)});const n=_reactNative.AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,n.remove()}},[]),e},StrokePath=(0,_react.memo)(({points:e,color:t})=>(0,_jsxRuntime.jsx)(_reactNativeSvg.Path,{d:(0,_signatureGeometry.strokePath)(e),stroke:t,strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}));StrokePath.displayName="SignaturePadStroke";const Marks=({mode:e,strokes:t,name:n,color:a,fontFamily:r,width:i,height:s})=>"draw"===e?(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:t.map(e=>(0,_jsxRuntime.jsx)(StrokePath,{points:e.points,color:a},e.id))}):n?(0,_jsxRuntime.jsx)(_reactNativeSvg.Text,{x:i/2,y:s*_signatureGeometry.BASELINE_RATIO,fontSize:(0,_signatureGeometry.typedFontSize)(i,n),fontFamily:r,textAnchor:"middle",fill:a,children:n}):null,SignaturePadSurface=(0,_react.forwardRef)((e,t)=>{const{expandable:n,initialStrokes:a,onChange:r,initialTypedName:i="",onTypedNameChange:s,defaultMode:o="draw",onModeChange:c,onEmptyChange:d,allowTyped:l=!0,signedBy:u,signedAt:_,height:m=DEFAULT_HEIGHT,maxNameLength:p=DEFAULT_NAME_LENGTH,inkColor:g,paperColor:h,scriptFontFamily:y,labels:x,haptic:f="selection",disabled:S=!1,style:v,testID:R}=e;(0,_assertValidValue.assertValidValue)("SignaturePad","defaultMode",e.defaultMode,["draw","type"]);const w=(0,_index.useTheme)(),b=void 0===g&&void 0===h,j=b?w.colors["text-body"]:g??_index.lightTheme.colors["text-body"],T=b?w.colors.surface:h??_index.lightTheme.colors.surface,E=b?_index.lightTheme.colors["text-body"]:j,A=b?_index.lightTheme.colors.surface:T,C=E!==j||A!==T,N=y??defaultScriptFont(),P=(0,_react.useMemo)(()=>({...DEFAULT_SIGNATURE_PAD_LABELS,...x}),[x]),I=useScreenReader(),L=(0,_react.useRef)(null),D=(0,_react.useRef)(null),[k,G]=(0,_react.useState)(0),[M,F]=(0,_react.useState)(()=>(a??[]).map((e,t)=>({id:t+1,points:[...e]}))),O=(0,_react.useRef)(M),H=(0,_react.useRef)(M.length),B=(0,_react.useRef)(null),q=(0,_react.useRef)(null),[U,V]=(0,_react.useState)(l?o:"draw"),[W,Y]=(0,_react.useState)(i),[$,z]=(0,_react.useState)(null),X=(0,_react.useRef)(!1),{height:K}=(0,_reactNative.useWindowDimensions)(),[J,Q]=(0,_react.useState)(!1),[Z,ee]=(0,_react.useState)([]),te=(0,_react.useRef)({onChange:r,onTypedNameChange:s,onModeChange:c,onEmptyChange:d});(0,_react.useEffect)(()=>{te.current={onChange:r,onTypedNameChange:s,onModeChange:c,onEmptyChange:d}});const ne="draw"===U&&!S,ae="draw"===U?0===M.length:0===W.trim().length,re=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{re.current!==ae&&(re.current=ae,te.current.onEmptyChange?.(ae))},[ae]);const ie=(0,_react.useCallback)(e=>{O.current=e,F(e)},[]),se=(0,_react.useCallback)(()=>{z(Date.now()),te.current.onChange?.(O.current.map(e=>e.points))},[]),oe=(0,_react.useMemo)(()=>{const pan=e=>({enabled:ne,runOnJS:!0,onBegin:e=>{B.current=(0,_signatureGeometry.pointOf)(e.x,e.y)},onActivate:t=>{q.current=e,H.current+=1;const n=(0,_signatureGeometry.pointOf)(t.x,t.y);ie([...O.current,{id:H.current,points:[B.current??n,n]}])},onUpdate:t=>{if(q.current!==e)return;const n=O.current[O.current.length-1];if(void 0===n)throw new Error("The stroke being drawn is missing.");const a=(0,_signatureGeometry.pointOf)(t.x,t.y),r=n.points[n.points.length-1];if(void 0===r)throw new Error("A drawn stroke has no points.");(0,_signatureGeometry.distanceBetween)(r,a)<.8||ie([...O.current.slice(0,-1),{...n,points:[...n.points,a]}])},onFinalize:()=>{q.current===e&&(q.current=null,se())}});return{sidewaysConfig:{...pan("sideways"),activeOffsetX:[-6,6],failOffsetY:[-8,8]},restedConfig:{...pan("rested"),activateAfterLongPress:200}}},[ne,ie,se]),ce=(0,_reactNativeGestureHandler.usePanGesture)(oe.sidewaysConfig),de=(0,_reactNativeGestureHandler.usePanGesture)(oe.restedConfig),le=(0,_reactNativeGestureHandler.useCompetingGestures)(ce,de),ue=(0,_react.useCallback)(e=>{V(e),te.current.onModeChange?.(e),(0,_announce.announce)("type"===e?P.typingAnnouncement:P.drawingAnnouncement)},[P.typingAnnouncement,P.drawingAnnouncement]);(0,_react.useEffect)(()=>{I&&l&&!X.current&&"draw"===U&&0===O.current.length&&ue("type")},[I,l,U,ue]);const me=(0,_react.useCallback)(()=>{X.current=!0,ue("draw"===U?"type":"draw")},[U,ue]),pe=(0,_react.useCallback)(e=>{Y(e),z(Date.now()),te.current.onTypedNameChange?.(e)},[]),ge=(0,_react.useCallback)(()=>{"type"===U?pe(""):(ie([]),se()),(0,_announce.announce)(P.clearedAnnouncement)},[U,pe,ie,se,P.clearedAnnouncement]),he=(0,_react.useCallback)(()=>{"draw"===U&&0!==O.current.length&&(ie(O.current.slice(0,-1)),se(),(0,_announce.announce)(P.undoneAnnouncement))},[U,ie,se,P.undoneAnnouncement]),ye=(0,_react.useCallback)(()=>{ee(O.current.map(e=>e.points)),Q(!0)},[]),xe=(0,_react.useCallback)(()=>{Q(!1)},[]),fe=(0,_react.useCallback)(()=>{ie(Z.map(e=>(H.current+=1,{id:H.current,points:[...e]}))),se(),Q(!1)},[Z,ie,se]),Se=k||_signatureGeometry.FALLBACK_WIDTH;(0,_react.useImperativeHandle)(t,()=>({toFile:()=>new Promise((e,t)=>{if(ae)return void t(new Error(P.emptyError));const n=C?D.current:L.current;if(!n)return void t(new Error("The signature pad is not on screen."));const a=Math.min(3,Math.max(1,_reactNative.PixelRatio.get()));n.toDataURL(n=>{(0,_writePng.writePng)(n).then(e,t)},{width:Se*a,height:m*a})}),toSvg:()=>(0,_signatureGeometry.buildSignatureSvg)({width:Se,height:m,mode:U,strokes:M.map(e=>e.points),typedName:W,ink:E,paper:A,strokeWidth:2.5,fontFamily:cssFontStack(N)}),clear:ge,undo:he,isEmpty:()=>ae}),[ae,P.emptyError,Se,m,U,M,W,C,E,A,N,ge,he]);const ve=(0,_react.useMemo)(()=>[{name:"undo",label:P.undo},{name:"clear",label:P.clear},...l?[{name:"toggleMode",label:"draw"===U?P.typeInstead:P.drawInstead}]:[]],[P.undo,P.clear,P.typeInstead,P.drawInstead,l,U]),Re=(0,_react.useCallback)(e=>{if(S)return;const{actionName:t}=e.nativeEvent;"undo"===t?he():"clear"===t?ge():"toggleMode"===t&&l&&me()},[S,he,ge,me,l]),we=(0,_react.useCallback)(e=>{G(e.nativeEvent.layout.width)},[]),be=(0,_react.useMemo)(()=>_reactNative.StyleSheet.create({root:{gap:w.space.sm},pad:{height:m,borderWidth:w.size.border,borderColor:w.colors.border,borderRadius:w.radius.md,..._corners.smoothCorners,overflow:"hidden",backgroundColor:T,opacity:S?.5:1},baseline:{position:"absolute",left:w.space.md,right:w.space.md,top:m*_signatureGeometry.BASELINE_RATIO,height:_reactNative.StyleSheet.hairlineWidth,backgroundColor:j,opacity:.3},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:w.space.xs},trailing:{flexDirection:"row",alignItems:"center",gap:w.space.xs},expandedRoot:{flex:1,padding:w.space.md,gap:w.space.sm,backgroundColor:w.colors.bg},expandedBar:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"}}),[w,m,T,j,S]),je=W.trim(),Te=_??$,Ee=u&&!ae?`Signed by ${u}${Te?`, ${(0,_mobileCore.formatDateTime)(Te)}`:""}`:null,Ae="type"===U&&je?`${P.pad}. ${je}`:P.pad;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[be.root,v],testID:R,children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:le,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:be.pad,onLayout:we,accessible:!0,accessibilityRole:"image",accessibilityLabel:Ae,accessibilityHint:"draw"===U?P.padHint:void 0,accessibilityValue:{text:ae?P.empty:P.signed},accessibilityState:{disabled:S},"aria-disabled":S,accessibilityActions:ve,onAccessibilityAction:Re,children:[C?(0,_jsxRuntime.jsxs)(_reactNativeSvg.default,{ref:D,style:_reactNative.StyleSheet.absoluteFill,width:"100%",height:m,children:[(0,_jsxRuntime.jsx)(_reactNativeSvg.Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:A}),(0,_jsxRuntime.jsx)(Marks,{mode:U,strokes:M,name:je,color:E,fontFamily:N,width:Se,height:m})]}):null,(0,_jsxRuntime.jsxs)(_reactNativeSvg.default,{ref:L,width:"100%",height:m,children:[(0,_jsxRuntime.jsx)(_reactNativeSvg.Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:T}),(0,_jsxRuntime.jsx)(Marks,{mode:U,strokes:M,name:je,color:j,fontFamily:N,width:Se,height:m})]}),(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:be.baseline})]})}),"type"===U?(0,_jsxRuntime.jsx)(_index3.Input,{label:P.typedLabel,placeholder:P.typedPlaceholder,value:W,onChangeText:pe,maxLength:p,disabled:S,autoComplete:"name",textContentType:"name",autoCapitalize:"words",autoCorrect:!1,returnKeyType:"done",testID:R?`${R}-name`:void 0}):null,(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"tertiary",children:"draw"===U?P.caption:P.typedCaption}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:be.actions,children:[l?(0,_jsxRuntime.jsx)(_index2.Button,{label:"draw"===U?P.typeInstead:P.drawInstead,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:me,testID:R?`${R}-mode`:void 0}):(0,_jsxRuntime.jsx)(_reactNative.View,{}),"draw"===U?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:be.trailing,children:[M.length>0?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index2.Button,{label:P.undo,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:he,testID:R?`${R}-undo`:void 0}),(0,_jsxRuntime.jsx)(_index2.Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:ge,testID:R?`${R}-clear`:void 0})]}):null,n?(0,_jsxRuntime.jsx)(_index2.Button,{label:P.expand,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:ye,testID:R?`${R}-expand`:void 0}):null]}):null,"type"===U&&je?(0,_jsxRuntime.jsx)(_index2.Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,disabled:S,onPress:ge,testID:R?`${R}-clear`:void 0}):null]}),Ee?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",color:"secondary",children:Ee}):null,n?(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:J,animationType:"slide",presentationStyle:"fullScreen",onRequestClose:xe,children:(0,_jsxRuntime.jsxs)(ExpandedRoot,{style:be.expandedRoot,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:be.expandedBar,children:[(0,_jsxRuntime.jsx)(_index2.Button,{label:P.close,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,onPress:xe,testID:R?`${R}-close`:void 0}),(0,_jsxRuntime.jsx)(_index2.Button,{label:P.done,variant:"solid",tone:"primary",size:"md",style:TARGET_STYLE,haptic:f,onPress:fe,testID:R?`${R}-done`:void 0})]}),J?(0,_jsxRuntime.jsx)(SignaturePadSurface,{expandable:!1,defaultMode:"draw",allowTyped:!1,initialStrokes:Z,onChange:ee,height:Math.max(DEFAULT_HEIGHT,K-200),inkColor:g,paperColor:h,scriptFontFamily:y,labels:x,haptic:f,testID:R?`${R}-expanded`:void 0}):null]})}):null]})});SignaturePadSurface.displayName="SignaturePadSurface";const ExpandedRoot="android"===_reactNative.Platform.OS?_reactNativeGestureHandler.GestureHandlerRootView:_reactNative.View,SignaturePad=exports.SignaturePad=(0,_react.forwardRef)((e,t)=>(0,_jsxRuntime.jsx)(SignaturePadSurface,{...e,expandable:!0,ref:t}));SignaturePad.displayName="SignaturePad";var _default=exports.default=SignaturePad;
|
|
@@ -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,r
|
|
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,r=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(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=r&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?r(n,i,a):n[i]=e[i]);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:i,tone:r="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],S=g.height-2*R,y=(0,_react.useMemo)(()=>buildStyles(x,g),[x,g]),C=x.colors[r],[j,N]=(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)(()=>{N(!1),T.value=(0,_reactNativeReanimated.withSpring)(0,{damping:18,stiffness:160,mass:1})},[T]),M=(0,_react.useCallback)(()=>{N(!0),E(),a(),!1!==l&&(L.current&&clearTimeout(L.current),L.current=setTimeout(V,l))},[E,a,l,V]),O=(0,_react.useCallback)(e=>{if(s||j)return;const{actionName:t}=e.nativeEvent;"activate"!==t&&"increment"!==t||M()},[s,j,M]);_react.default.useEffect(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(T),L.current&&clearTimeout(L.current)},[T]);const k=(0,_react.useCallback)(e=>{A.value=Math.max(0,e.nativeEvent.layout.width-S-2*R)},[A,S,R]),D=(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&&!j,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,_reactNativeReanimated.runOnJS)(M)()):T.value=(0,_reactNativeReanimated.withSpring)(0,t)}}},[s,j,o,T,A,w,M,x.motion.duration.fast]),q=(0,_reactNativeGestureHandler.usePanGesture)(D),I=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:T.value}]}),[T]),W=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({width:T.value+S+R}),[T,S,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:[y.track,{backgroundColor:x.colors["bg-subtle"]},_,m],onLayout:k,testID:v,accessibilityRole:"adjustable",accessibilityLabel:j?p.confirmed:i??p.slide,accessibilityState:{disabled:s},"aria-disabled":s,accessibilityActions:b,onAccessibilityAction:O,children:[(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[y.fill,{backgroundColor:C,opacity:s?.5:1},W],pointerEvents:"none"}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[y.labelWrap,F],pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",style:[y.label,{color:x.colors["text-muted"]},f],numberOfLines:1,children:j?p.confirmed:i??p.slide})}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:q,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[y.handle,{width:S,height:S,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*S})})})]})});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,t){if(!t&&e&&e.__esModule)return e;var a,i,r=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(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=r&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?r(n,i,a):n[i]=e[i]);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,i)=>{if(i<=0)return clamp(e,t,a);const r=Math.round((e-t)/i)*i+t,n=String(i).split(".")[1]?.length??0,s=n>0?Number(r.toFixed(n)):r;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),Slider=exports.Slider=(0,_react.forwardRef)((e,t)=>{const{min:a=0,max:i=100,step:r=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:b,containerStyle:v,trackStyle:p,fillStyle:f,thumbStyle:g,labelStyle:R,thumbPressScale:x,labelShowDuration:y,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,M=x??1.1,H=y??S.motion.duration.fast,O=w??1,D=(0,_react.useMemo)(()=>buildStyles(S,j),[S,j]),A=(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),W=S.colors[s],I=(0,_valueText.sliderToneInk)(S,s),q=!0===e.range,[P,L]=(0,_index.useControllableState)({value:e.value,defaultValue:e.defaultValue??(q?[a,i]:a),onChange:e.onChange}),X=(0,_reactNativeReanimated.useSharedValue)(0),B=(0,_reactNativeReanimated.useSharedValue)(0),G=(0,_reactNativeReanimated.useSharedValue)(q?P[0]:P),F=(0,_reactNativeReanimated.useSharedValue)(q?P[1]:P),z=(0,_reactNativeReanimated.useSharedValue)(0),J=(0,_reactNativeReanimated.useSharedValue)(0),U=(0,_reactNativeReanimated.useSharedValue)(1),Z=(0,_reactNativeReanimated.useSharedValue)(1),$="always"===o,K=(0,_reactNativeReanimated.useSharedValue)($?1:0),Q=(0,_reactNativeReanimated.useSharedValue)($?1:0),Y=(0,_react.useMemo)(()=>10**(String(r).split(".")[1]?.length??0),[r]);(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(X),(0,_reactNativeReanimated.cancelAnimation)(B),(0,_reactNativeReanimated.cancelAnimation)(U),(0,_reactNativeReanimated.cancelAnimation)(Z),(0,_reactNativeReanimated.cancelAnimation)(K),(0,_reactNativeReanimated.cancelAnimation)(Q)},[X,B,U,Z,K,Q]);const ee=(0,_react.useCallback)((e,t)=>{const r=t-2*C;return i===a||r<=0?C:C+(e-a)/(i-a)*r},[a,i,C]),te=(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*(i-a),a,i,r)},[a,i,r,C]),ae=(0,_react.useRef)(!1),ie=S.motion.duration.fast,re=(0,_react.useRef)(P);re.current=P;const ne=(0,_react.useRef)(E);ne.current=E;const se=(0,_react.useCallback)((e=!1)=>{const t=ne.current;if(t<=0)return;const place=t=>e?(0,_reactNativeReanimated.withTiming)(t,{duration:ie,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}):t,a=re.current;if(q){const[e,i]=a,r=Math.min(e,i),n=Math.max(e,i);G.value=r,F.value=n,X.value=place(ee(r,t)),B.value=place(ee(n,t))}else{const e=a;G.value=e,F.value=e,X.value=place(ee(e,t))}},[q,ee,G,F,X,B,ie]),[le,ce]=(0,_react.useState)(0),oe=(0,_react.useRef)(!1),ue=(0,_react.useCallback)(e=>{ae.current=e,e||(oe.current=!0,ce(e=>e+1))},[]);(0,_react.useEffect)(()=>{if(ae.current)return;const e=oe.current;oe.current=!1,se(e)},[JSON.stringify(P),E,le,se]);const de=(0,_react.useCallback)(e=>{const t=e.nativeEvent.layout.width;J.value=t,T(t)},[J]),me=(0,_react.useCallback)((e,t)=>{L(q?[e,t]:e)},[q,L]),he=(0,_react.useCallback)(()=>{const e=(0,_index3.resolveHaptic)(_,"selection");e&&(0,_index3.triggerHaptic)(e)},[_]),be=(0,_react.useRef)(me);be.current=me;const ve=(0,_react.useRef)(he);ve.current=he;const pe=(0,_react.useCallback)((e,t)=>be.current(e,t),[]),fe=(0,_react.useCallback)(()=>ve.current(),[]),ge=Math.max(0,(44-j.thumbDiameter)/2),Re=ge>0?ge:void 0,xe=(0,_react.useCallback)(e=>{const t="low"===e?X:B,s="low"===e?G:F,l="low"===e?F:G,c="low"===e?U:Z,d="low"===e?K:Q,m="low"===e,h=a,_=i,b=r,v=Y,p=q,f=M,g=V,R=!0===o,x=u,y=O,w=H,N=A,S=C,follow=e=>{"worklet";const a=J.value-2*S;if(a<=0||!Number.isFinite(e))return;const i=Math.min(Math.max(z.value+e,S),J.value-S);let r=h+(i-S)/a*(_-h);b>0&&(r=Math.round((r-h)/b)*b+h,r=Math.round(r*v)/v),r=Math.min(Math.max(r,h),_),p&&(m&&r>l.value&&(r=l.value),!m&&r<l.value&&(r=l.value)),t.value=x||_===h?_===h?S:S+(r-h)/(_-h)*a:p?m?Math.min(i,B.value):Math.max(i,X.value):i,r!==s.value&&(s.value=r,r!==h&&r!==_||(0,_reactNativeReanimated.runOnJS)(fe)(),(0,_reactNativeReanimated.runOnJS)(pe)(G.value,F.value))},k=_reactNativeGestureHandler.Gesture.Pan().enabled(!n).minDistance(0);return(void 0===Re?k:k.hitSlop(Re)).onStart(()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(ue)(!0),z.value=t.value,g&&(c.value=(0,_reactNativeReanimated.withSpring)(f,N)),R&&(d.value=(0,_reactNativeReanimated.withTiming)(y,{duration:w,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)})),(0,_reactNativeReanimated.runOnJS)(fe)()}).onUpdate(e=>{"worklet";follow(e.translationX)}).onEnd(e=>{"worklet";follow(e.translationX),g&&(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)(ue)(!1)})},[n,a,i,r,Y,q,M,V,o,u,O,H,A,C,Re,pe,fe,ue,X,B,G,F,U,Z,K,Q,z,J]),ye=(0,_react.useMemo)(()=>xe("low"),[xe]),we=(0,_react.useMemo)(()=>xe("high"),[xe]),Ne=(0,_react.useCallback)(e=>{if(n||q||E<=0)return;const t=clamp(e.nativeEvent.locationX,0,E),a=te(t,E);a!==G.value&&(he(),G.value=a,X.value=(0,_reactNativeReanimated.withTiming)(ee(a,E),{duration:S.motion.duration.fast,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}),me(a,a))},[n,q,E,te,ee,me,he,X,G,S.motion.duration.fast]),Se=(0,_react.useCallback)(e=>{if(n)return;const t="increment"===e.nativeEvent.actionName?r:-r,s=r>0?Math.round(t*Y)/Y:t;if(q){const e=Math.round((G.value+s)*Y)/Y,t=clamp(e,a,F.value);t!==G.value&&(G.value=t,X.value=ee(t,E),he(),me(t,F.value))}else{const e=Math.round((G.value+s)*Y)/Y,t=clamp(e,a,i);t!==G.value&&(G.value=t,X.value=ee(t,E),he(),me(t,t))}},[n,r,Y,q,a,i,ee,E,X,G,F,me,he]),ke=j.thumbDiameter/2,je=n?S.colors["surface-disabled"]:W,Ce="inset"===c?{backgroundColor:je,borderColor:S.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===c?{backgroundColor:je,borderWidth:0}:"bar"===c?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:S.colors.surface,borderColor:je},Ve=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=J.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}]}},[J,n,q,B,X,C]),Me=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:X.value-ke},{scale:U.value}]}),[X,ke,U]),He=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:B.value-ke},{scale:Z.value}]}),[B,ke,Z]),Oe=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:K.value}),[K]),De=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:Q.value}),[Q]),clampDisplay=e=>clamp(e,a,i),Ae=clampDisplay(q?Math.min(...P):P),Ee=clampDisplay(q?Math.max(...P):P);return(0,_jsxRuntime.jsx)(_reactNative.View,{ref:t,style:[D.container,v,b],testID:N,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityValue:q?{min:a,max:i,now:Ae,text:`${Ae} to ${Ee}`}:{min:a,max:i,now:Ae},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:Se,children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Ne,disabled:n||q,style:D.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.trackWrap,onLayout:de,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},p]}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.fill,{backgroundColor:n?S.colors["surface-disabled"]:W},f,Ve]})]}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ye,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:ke,..._corners.smoothCorners,opacity:n?.55:1},Ce,g,Me],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o?(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[D.bubbleWrap,Oe],pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubble,{backgroundColor:W}],children:m?m(Ae):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",style:[{color:I},R],numberOfLines:1,children:d(Ae)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubbleCaret,{backgroundColor:W}]})]}):null})}),q?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:we,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[D.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:ke,..._corners.smoothCorners,opacity:n?.55:1},Ce,g,He],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o?(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[D.bubbleWrap,De],pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubble,{backgroundColor:W}],children:m?m(Ee):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",style:[{color:I},R],numberOfLines:1,children:d(Ee)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.bubbleCaret,{backgroundColor:W}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,i=Math.max(t.thumbDiameter,t.trackHeight),r=i/2+e.space.xs;return _reactNative.StyleSheet.create({container:{width:"100%",paddingVertical:r,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:i,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(i-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:(i-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;
|
|
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,t){if(!t&&e&&e.__esModule)return e;var a,i,r=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(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=r&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?r(n,i,a):n[i]=e[i]);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,i)=>{if(i<=0)return clamp(e,t,a);const r=Math.round((e-t)/i)*i+t,n=String(i).split(".")[1]?.length??0,s=n>0?Number(r.toFixed(n)):r;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),Slider=exports.Slider=(0,_react.forwardRef)((e,t)=>{const{min:a=0,max:i=100,step:r=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:p,fillStyle:f,thumbStyle:g,labelStyle:R,thumbPressScale:x,labelShowDuration:y,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,M=x??1.1,H=y??S.motion.duration.fast,D=w??1,O=(0,_react.useMemo)(()=>buildStyles(S,j),[S,j]),A=(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),W=S.colors[s],I=(0,_valueText.sliderToneInk)(S,s),P=!0===e.range,[q,L]=(0,_index.useControllableState)({value:e.value,defaultValue:e.defaultValue??(P?[a,i]:a),onChange:e.onChange}),G=(0,_reactNativeReanimated.useSharedValue)(0),X=(0,_reactNativeReanimated.useSharedValue)(0),B=(0,_reactNativeReanimated.useSharedValue)(P?q[0]:q),F=(0,_reactNativeReanimated.useSharedValue)(P?q[1]:q),z=(0,_reactNativeReanimated.useSharedValue)(0),J=(0,_reactNativeReanimated.useSharedValue)(0),U=(0,_reactNativeReanimated.useSharedValue)(1),Z=(0,_reactNativeReanimated.useSharedValue)(1),$="always"===o,K=(0,_reactNativeReanimated.useSharedValue)($?1:0),Q=(0,_reactNativeReanimated.useSharedValue)($?1:0),Y=(0,_react.useMemo)(()=>10**(String(r).split(".")[1]?.length??0),[r]);(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(G),(0,_reactNativeReanimated.cancelAnimation)(X),(0,_reactNativeReanimated.cancelAnimation)(U),(0,_reactNativeReanimated.cancelAnimation)(Z),(0,_reactNativeReanimated.cancelAnimation)(K),(0,_reactNativeReanimated.cancelAnimation)(Q)},[G,X,U,Z,K,Q]);const ee=(0,_react.useCallback)((e,t)=>{const r=t-2*C;return i===a||r<=0?C:C+(e-a)/(i-a)*r},[a,i,C]),te=(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*(i-a),a,i,r)},[a,i,r,C]),ae=(0,_react.useRef)(!1),ie=S.motion.duration.fast,re=(0,_react.useRef)(q);re.current=q;const ne=(0,_react.useRef)(E);ne.current=E;const se=(0,_react.useCallback)((e=!1)=>{const t=ne.current;if(t<=0)return;const place=t=>e?(0,_reactNativeReanimated.withTiming)(t,{duration:ie,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}):t,a=re.current;if(P){const[e,i]=a,r=Math.min(e,i),n=Math.max(e,i);B.value=r,F.value=n,G.value=place(ee(r,t)),X.value=place(ee(n,t))}else{const e=a;B.value=e,F.value=e,G.value=place(ee(e,t))}},[P,ee,B,F,G,X,ie]),[le,ce]=(0,_react.useState)(0),oe=(0,_react.useRef)(!1),ue=(0,_react.useCallback)(e=>{ae.current=e,e||(oe.current=!0,ce(e=>e+1))},[]);(0,_react.useEffect)(()=>{if(ae.current)return;const e=oe.current;oe.current=!1,se(e)},[JSON.stringify(q),E,le,se]);const de=(0,_react.useCallback)(e=>{const t=e.nativeEvent.layout.width;J.value=t,T(t)},[J]),me=(0,_react.useCallback)((e,t)=>{L(P?[e,t]:e)},[P,L]),he=(0,_react.useCallback)(()=>{const e=(0,_index3.resolveHaptic)(_,"selection");e&&(0,_index3.triggerHaptic)(e)},[_]),ve=(0,_react.useRef)(me);ve.current=me;const be=(0,_react.useRef)(he);be.current=he;const pe=(0,_react.useCallback)((e,t)=>ve.current(e,t),[]),fe=(0,_react.useCallback)(()=>be.current(),[]),ge=Math.max(0,(44-j.thumbDiameter)/2),Re=ge>0?ge:void 0,xe=(0,_react.useCallback)(e=>{const t="low"===e?G:X,s="low"===e?B:F,l="low"===e?F:B,c="low"===e?U:Z,d="low"===e?K:Q,m="low"===e,h=a,_=i,v=r,b=Y,p=P,f=M,g=V,R=!0===o,x=u,y=D,w=H,N=A,S=C,follow=e=>{"worklet";const a=J.value-2*S;if(a<=0||!Number.isFinite(e))return;const i=Math.min(Math.max(z.value+e,S),J.value-S);let r=h+(i-S)/a*(_-h);v>0&&(r=Math.round((r-h)/v)*v+h,r=Math.round(r*b)/b),r=Math.min(Math.max(r,h),_),p&&(m&&r>l.value&&(r=l.value),!m&&r<l.value&&(r=l.value)),t.value=x||_===h?_===h?S:S+(r-h)/(_-h)*a:p?m?Math.min(i,X.value):Math.max(i,G.value):i,r!==s.value&&(s.value=r,r!==h&&r!==_||(0,_reactNativeReanimated.runOnJS)(fe)(),(0,_reactNativeReanimated.runOnJS)(pe)(B.value,F.value))};return{enabled:!n,minDistance:0,...void 0===Re?{}:{hitSlop:Re},onActivate:()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(ue)(!0),z.value=t.value,g&&(c.value=(0,_reactNativeReanimated.withSpring)(f,N)),R&&(d.value=(0,_reactNativeReanimated.withTiming)(y,{duration:w,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)})),(0,_reactNativeReanimated.runOnJS)(fe)()},onUpdate:e=>{"worklet";follow(e.translationX)},onDeactivate:e=>{"worklet";follow(e.translationX),g&&(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)(ue)(!1)}}},[n,a,i,r,Y,P,M,V,o,u,D,H,A,C,Re,pe,fe,ue,G,X,B,F,U,Z,K,Q,z,J]),ye=(0,_react.useMemo)(()=>xe("low"),[xe]),we=(0,_react.useMemo)(()=>xe("high"),[xe]),Ne=(0,_reactNativeGestureHandler.usePanGesture)(ye),Se=(0,_reactNativeGestureHandler.usePanGesture)(we),ke=(0,_react.useCallback)(e=>{if(n||P||E<=0)return;const t=clamp(e.nativeEvent.locationX,0,E),a=te(t,E);a!==B.value&&(he(),B.value=a,G.value=(0,_reactNativeReanimated.withTiming)(ee(a,E),{duration:S.motion.duration.fast,easing:_reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)}),me(a,a))},[n,P,E,te,ee,me,he,G,B,S.motion.duration.fast]),je=(0,_react.useCallback)(e=>{if(n)return;const t="increment"===e.nativeEvent.actionName?r:-r,s=r>0?Math.round(t*Y)/Y:t;if(P){const e=Math.round((B.value+s)*Y)/Y,t=clamp(e,a,F.value);t!==B.value&&(B.value=t,G.value=ee(t,E),he(),me(t,F.value))}else{const e=Math.round((B.value+s)*Y)/Y,t=clamp(e,a,i);t!==B.value&&(B.value=t,G.value=ee(t,E),he(),me(t,t))}},[n,r,Y,P,a,i,ee,E,G,B,F,me,he]),Ce=j.thumbDiameter/2,Ve=n?S.colors["surface-disabled"]:W,Me="inset"===c?{backgroundColor:Ve,borderColor:S.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===c?{backgroundColor:Ve,borderWidth:0}:"bar"===c?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:S.colors.surface,borderColor:Ve},He=(0,_reactNativeReanimated.useAnimatedStyle)(()=>{const e=J.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const t=n?.55:1;if(P){const a=Math.max(0,X.value-G.value+2*C);return{opacity:t,transform:[{translateX:G.value-C},{scaleX:a/e}]}}return{opacity:t,transform:[{translateX:G.value+C-e},{scaleX:1}]}},[J,n,P,X,G,C]),De=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:G.value-Ce},{scale:U.value}]}),[G,Ce,U]),Oe=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:X.value-Ce},{scale:Z.value}]}),[X,Ce,Z]),Ae=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:K.value}),[K]),Ee=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:Q.value}),[Q]),clampDisplay=e=>clamp(e,a,i),Te=clampDisplay(P?Math.min(...q):q),We=clampDisplay(P?Math.max(...q):q);return(0,_jsxRuntime.jsx)(_reactNative.View,{ref:t,style:[O.container,b,v],testID:N,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityValue:P?{min:a,max:i,now:Te,text:`${Te} to ${We}`}:{min:a,max:i,now:Te},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:je,children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ke,disabled:n||P,style:O.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:O.trackWrap,onLayout:de,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:O.trackClip,pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[O.track,{backgroundColor:n?S.colors["surface-disabled"]:S.colors.border},p]}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[O.fill,{backgroundColor:n?S.colors["surface-disabled"]:W},f,He]})]}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Ne,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ce,..._corners.smoothCorners,opacity:n?.55:1},Me,g,De],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o?(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[O.bubbleWrap,Ae],pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Te):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",style:[{color:I},R],numberOfLines:1,children:d(Te)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}),P?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Se,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ce,..._corners.smoothCorners,opacity:n?.55:1},Me,g,Oe],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:o?(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[O.bubbleWrap,Ee],pointerEvents:"none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[O.bubble,{backgroundColor:W}],children:m?m(We):(0,_jsxRuntime.jsx)(_index4.Text,{variant:"caption",weight:"semibold",style:[{color:I},R],numberOfLines:1,children:d(We)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,i=Math.max(t.thumbDiameter,t.trackHeight),r=i/2+e.space.xs;return _reactNative.StyleSheet.create({container:{width:"100%",paddingVertical:r,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:i,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(i-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:(i-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;
|