@webority/mobile-ui 0.98.0 → 0.99.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.
@@ -9737,7 +9737,7 @@ var _f = {
9737
9737
  })
9738
9738
  }, vf = null, yf = (e) => {
9739
9739
  if (typeof document > "u") return null;
9740
- if (!vf || !vf.polite.isConnected) {
9740
+ if (!vf?.polite.isConnected) {
9741
9741
  let e = (e) => {
9742
9742
  let t = document.createElement("div");
9743
9743
  return t.setAttribute("aria-live", e), t.setAttribute("aria-atomic", "true"), t.setAttribute("role", e === "assertive" ? "alert" : "status"), Object.assign(t.style, {
@@ -14706,7 +14706,7 @@ var og = R.create({
14706
14706
  } : {
14707
14707
  style: [
14708
14708
  k.iconCircle,
14709
- { backgroundColor: A.bar + "22" },
14709
+ { backgroundColor: `${A.bar}22` },
14710
14710
  S
14711
14711
  ],
14712
14712
  children: J(z, {
@@ -15984,7 +15984,7 @@ var Tg = (e) => R.create({
15984
15984
  height: v,
15985
15985
  borderRadius: a.radius.pill,
15986
15986
  ...$,
15987
- backgroundColor: p + "22"
15987
+ backgroundColor: `${p}22`
15988
15988
  },
15989
15989
  e.iconCircleStyle
15990
15990
  ],
@@ -16054,7 +16054,7 @@ var Tg = (e) => R.create({
16054
16054
  importantForAccessibility: "no-hide-descendants",
16055
16055
  onLayout: (e) => ce(e.nativeEvent.layout.width),
16056
16056
  testID: "toast-countdown",
16057
- style: [f.countdownTrack, { backgroundColor: p + "22" }],
16057
+ style: [f.countdownTrack, { backgroundColor: `${p}22` }],
16058
16058
  children: [o.reduced ? J(H, { style: [f.countdownFill, { backgroundColor: p }] }) : null, !o.reduced && se > 0 ? J(b.View, { style: [f.countdownFill, {
16059
16059
  backgroundColor: p,
16060
16060
  transform: [{ translateX: le }]
@@ -20413,7 +20413,9 @@ var ly = (e) => R.create({
20413
20413
  }, [t]);
20414
20414
  let Ce = m(() => {
20415
20415
  let e = /* @__PURE__ */ new Set();
20416
- return o?.forEach((t) => e.add(py(dy(t)))), e;
20416
+ return o?.forEach((t) => {
20417
+ e.add(py(dy(t)));
20418
+ }), e;
20417
20419
  }, [o]), we = m(() => i ? dy(i) : null, [i]), Te = m(() => a ? dy(a) : null, [a]), Ee = l((e) => !!(we && e.getTime() < we.getTime()) || !!(Te && e.getTime() > Te.getTime()) || !!Ce.has(py(e)), [
20418
20420
  we,
20419
20421
  Te,
@@ -21738,7 +21740,9 @@ var zy = (e, t) => e.key ?? (typeof e.label == "string" ? `${e.label}-${t}` : `r
21738
21740
  e && (V.setValue(F), K(!1));
21739
21741
  }), e.push(o);
21740
21742
  }
21741
- return () => e.forEach((e) => e.stop());
21743
+ return () => e.forEach((e) => {
21744
+ e.stop();
21745
+ });
21742
21746
  }, [
21743
21747
  n,
21744
21748
  G,
@@ -21759,7 +21763,7 @@ var zy = (e, t) => e.key ?? (typeof e.label == "string" ? `${e.label}-${t}` : `r
21759
21763
  let e, t;
21760
21764
  return n ? (e = setTimeout(() => {
21761
21765
  U.current && v.sendAccessibilityEvent(U.current, "focus");
21762
- }, 150), W.current = !0) : W.current && (W.current = !1, x && x.current && (t = setTimeout(() => {
21766
+ }, 150), W.current = !0) : W.current && (W.current = !1, x?.current && (t = setTimeout(() => {
21763
21767
  let e = x.current;
21764
21768
  e && v.sendAccessibilityEvent(e, "focus");
21765
21769
  }, M))), () => {
@@ -22371,7 +22375,9 @@ var $y = 0, eb = () => "wfp-" + ++$y, tb = {
22371
22375
  let W = l((e) => {
22372
22376
  U.current = e, ee(e);
22373
22377
  }, [ee]), [G, K] = g(null), [q, te] = g(!1), ne = x ?? G ?? void 0, X = typeof o == "number" && V.length >= o, Z = l((e, t) => {
22374
- e.length !== 0 && (K(e[0]), e.forEach((e) => D?.(e, t)), !1 !== C && hr("notificationError"));
22378
+ e.length !== 0 && (K(e[0]), e.forEach((e) => {
22379
+ D?.(e, t);
22380
+ }), !1 !== C && hr("notificationError"));
22375
22381
  }, [D, C]), re = l(async (e) => {
22376
22382
  let t;
22377
22383
  try {
@@ -24805,13 +24811,17 @@ var rx = ({ label: e, accessibilityLabel: t, onPress: n, theme: r }) => J(P, {
24805
24811
  v
24806
24812
  ]), z = Ve(() => ({ transform: [{ translateX: A.value }] })), B = Ve(() => ({ opacity: O > 0 ? Math.min(1, Math.max(0, A.value / O)) : 0 })), V = Ve(() => ({ opacity: k > 0 ? Math.min(1, Math.max(0, -A.value / k)) : 0 })), ee = m(() => {
24807
24813
  let e = [];
24808
- return n?.forEach((t) => e.push({
24809
- name: t.key,
24810
- label: t.label
24811
- })), r?.forEach((t) => e.push({
24812
- name: t.key,
24813
- label: t.label
24814
- })), e;
24814
+ return n?.forEach((t) => {
24815
+ e.push({
24816
+ name: t.key,
24817
+ label: t.label
24818
+ });
24819
+ }), r?.forEach((t) => {
24820
+ e.push({
24821
+ name: t.key,
24822
+ label: t.label
24823
+ });
24824
+ }), e;
24815
24825
  }, [n, r]), U = l((e) => {
24816
24826
  let t = e.nativeEvent.actionName, i = [...n ?? [], ...r ?? []].find((e) => e.key === t);
24817
24827
  i && (!1 !== u && hr("selection"), i.onPress());
@@ -26039,7 +26049,7 @@ function $x({ messages: e, keyExtractor: t, renderMessage: n, getAuthorKey: r, g
26039
26049
  inverted: !0,
26040
26050
  onScroll: G,
26041
26051
  onEndReached: o ? K : void 0,
26042
- ListHeaderComponent: u ? J(ne, { children: u }) : null,
26052
+ ListHeaderComponent: u ? J(H, { children: u }) : null,
26043
26053
  ListFooterComponent: s ? J(Dp, {
26044
26054
  size: "sm",
26045
26055
  accessibilityLabel: M.loadingOlder,
@@ -26681,7 +26691,9 @@ var lS = ({ keys: e, index: t, label: n, valueText: r, reduceMotion: i, theme: a
26681
26691
  useNativeDriver: !0
26682
26692
  });
26683
26693
  a.start(), t.push(a);
26684
- }), () => t.forEach((e) => e.stop());
26694
+ }), () => t.forEach((e) => {
26695
+ e.stop();
26696
+ });
26685
26697
  }, [
26686
26698
  I,
26687
26699
  U,
@@ -35488,7 +35500,7 @@ var LE = kt({
35488
35500
  kind: "WeborityPhone",
35489
35501
  library: {
35490
35502
  name: "@webority/mobile-ui",
35491
- version: "0.98.0"
35503
+ version: "0.99.0"
35492
35504
  },
35493
35505
  rendererProtocolVersion: 8,
35494
35506
  platform: "Phone",
@@ -52021,7 +52033,7 @@ var LE = kt({
52021
52033
  "primary-hover": "Primary fill while a control is hovered or pressed.",
52022
52034
  "primary-pressed": "Primary fill while a control is pressed.",
52023
52035
  "primary-soft": "Soft primary tint behind selected and highlighted rows.",
52024
- "primary-text": "Primary as text and small glyphs on a page, passing AA contrast.",
52036
+ "primary-text": "Primary as text and small glyphs on a page.",
52025
52037
  "primary-wash": "Faint translucent primary wash over a surface.",
52026
52038
  "primary-wash-strong": "Stronger translucent primary wash over a surface.",
52027
52039
  scrim: "Dim behind page-level backdrops such as drawers, modals and the shell.",
@@ -2,7 +2,7 @@
2
2
  "kind": "WeborityPhone",
3
3
  "library": {
4
4
  "name": "@webority/mobile-ui",
5
- "version": "0.98.0"
5
+ "version": "0.99.0"
6
6
  },
7
7
  "rendererProtocolVersion": 8,
8
8
  "platform": "Phone",
@@ -19509,7 +19509,7 @@
19509
19509
  "primary-hover": "Primary fill while a control is hovered or pressed.",
19510
19510
  "primary-pressed": "Primary fill while a control is pressed.",
19511
19511
  "primary-soft": "Soft primary tint behind selected and highlighted rows.",
19512
- "primary-text": "Primary as text and small glyphs on a page, passing AA contrast.",
19512
+ "primary-text": "Primary as text and small glyphs on a page.",
19513
19513
  "primary-wash": "Faint translucent primary wash over a surface.",
19514
19514
  "primary-wash-strong": "Stronger translucent primary wash over a surface.",
19515
19515
  "scrim": "Dim behind page-level backdrops such as drawers, modals and the shell.",
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "webority-phone",
3
- "version": "0.98.0",
3
+ "version": "0.99.0",
4
4
  "platform": "Phone",
5
5
  "kitModuleVersion": 2,
6
6
  "rendererProtocolVersion": 8,
7
7
  "library": {
8
8
  "name": "@webority/mobile-ui",
9
- "version": "0.98.0"
9
+ "version": "0.99.0"
10
10
  },
11
11
  "files": {
12
12
  "manifest.json": {
13
- "sha256": "682b7e1489858684f87e374719f35a84c1c269cae40de64ab32f155c9f15b13f",
14
- "bytes": 613066
13
+ "sha256": "16aa3d358f20a0378f904bcebbba3091435b1dc6a731e40e322891527e2e12de",
14
+ "bytes": 613045
15
15
  },
16
16
  "kit.js": {
17
- "sha256": "9cc96e8c487ed95ccae82be7bcfdfe7f1b1e12790659e2c8cde6631d849f56ca",
18
- "bytes": 5916270
17
+ "sha256": "94880a369ac08e87375eb27b52748e02b02b753e2d43338a1931c8e437c6c06b",
18
+ "bytes": 5916304
19
19
  },
20
20
  "kit.css": {
21
21
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Banner=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_hitSlop=require("../../utils/hitSlop.js"),_index2=require("../Skeleton/index.js"),_jsxRuntime=require("react/jsx-runtime");const Banner=exports.Banner=(0,_react.forwardRef)((e,t)=>{const{title:r,message:i,variant:n="info",icon:s,actions:o,dismissible:a=!1,onDismiss:l,haptic:c,visible:d=!0,animateMount:u=!0,loading:x=!1,accessibilityRole:m="alert",accessibilityLabel:p,style:g,containerStyle:h,iconCircleStyle:_,tintBarStyle:y,closeButtonStyle:b,actionButtonStyle:j,testID:f}=e,v=(0,_index.useTheme)(),R=(0,_usePresenceMotion.usePresenceMotion)(),w=(0,_react.useMemo)(()=>buildStyles(v),[v]),S=(0,_react.useMemo)(()=>tintFor(v,n),[v,n]),[N,k]=R.range(-20,0),B=(0,_react.useRef)((0,_index.createAnimatedValue)(u&&d?N:0)).current,C=(0,_react.useRef)((0,_index.createAnimatedValue)(u&&d?0:d?1:0)).current,[V,z]=(0,_react.useState)(d),D=(0,_react.useRef)(!0);if((0,_react.useEffect)(()=>{if(D.current&&(D.current=!1,!u))return;let e;return d?(z(!0),e=_reactNative.Animated.parallel([_reactNative.Animated.timing(B,{toValue:k,duration:v.motion.duration.default,useNativeDriver:!0}),_reactNative.Animated.timing(C,{toValue:1,duration:R.duration("default"),useNativeDriver:!0})]),e.start()):V&&(e=_reactNative.Animated.parallel([_reactNative.Animated.timing(B,{toValue:N,duration:v.motion.duration.fast,useNativeDriver:!0}),_reactNative.Animated.timing(C,{toValue:0,duration:R.duration("fast"),useNativeDriver:!0})]),e.start(()=>{z(!1)})),()=>e?.stop()},[d]),!V)return null;const T=r??" ",H="string"==typeof i?i??" ":"",M="alert"===m?"danger"===n?"assertive":"polite":"none",A=(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{ref:t,accessibilityRole:m,accessibilityLiveRegion:M,accessibilityLabel:p,testID:f,style:[w.container,{backgroundColor:v.colors["bg-subtle"],borderRadius:v.radius.md,..._corners.smoothCorners,padding:v.space.md,opacity:C,transform:[{translateY:B}]},g,h],children:[v.components.banner["tint-bar-width"]>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tintBar,{backgroundColor:S.bar},y]}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.row,children:[!1===s?null:s?(0,_jsxRuntime.jsx)(_reactNative.View,{style:w.iconWrap,children:s}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.iconCircle,{backgroundColor:S.bar+"22"},_],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.iconGlyph,{color:S.ink}],accessible:!1,children:S.glyph})}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.textBlock,children:[r||x?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:v.colors["text-body"],fontSize:v.text.base.size,...(0,_index.fontFor)(v,"semibold"),lineHeight:20},numberOfLines:2,children:T}):null,"string"==typeof i||x?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:v.colors["text-muted"],fontSize:v.text.sm.size,...(0,_index.fontFor)(v,"normal"),lineHeight:18,marginTop:r?v.space.xxs:0},children:H||" "}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{marginTop:r?v.space.xxs:0},children:i})]}),a?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{accessibilityRole:"button",accessibilityLabel:"Dismiss banner",onPress:()=>{const e=(0,_hapticUtils.resolveHaptic)(c,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),l?.()},hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),style:({pressed:e})=>[w.closeBtn,{backgroundColor:e?v.colors["surface-pressed"]:"transparent"},b],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:v.colors["text-muted"],fontSize:v.text.lg.size,fontWeight:v.weight.bold,lineHeight:17},accessible:!1,children:"×"})}):null]}),o&&o.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:w.actionsRow,children:o.map((e,t)=>{const r=e.tone??"primary",i=e.variant??"ghost",n="danger"===r?v.colors.danger:"neutral"===r?v.colors["text-muted"]:S.glyphColor,s="danger"===r?v.colors["danger-text"]:"neutral"===r?v.colors["text-muted"]:S.ink,o="danger"===r?v.colors["on-danger"]:"neutral"===r?v.colors["on-neutral-strong"]:S.on,a="solid"===i;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{accessibilityRole:"button",accessibilityLabel:e.label,onPress:()=>{const t=(0,_hapticUtils.resolveHaptic)(c,"selection");t&&(0,_hapticUtils.triggerHaptic)(t),e.onPress()},style:({pressed:t})=>[w.actionBtn,"md"===e.size&&w.actionBtnMd,"outline"===i&&{borderWidth:1,borderColor:s},{backgroundColor:a?n:t?v.colors["surface-pressed"]:"transparent",opacity:a&&t?.85:1},j],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:a?o:s,fontSize:v.text.sm.size,textAlign:"center",...(0,_index.fontFor)(v,"semibold")},children:e.label})},`${e.label}-${t}`)})}):null]});return x?(0,_jsxRuntime.jsx)(BannerSkeleton,{...e}):A});Banner.displayName="Banner";const BannerSkeleton=({title:e,actions:t,icon:r,containerStyle:i,style:n})=>{const s=(0,_index.useTheme)(),o=!1!==r;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:s.colors.surface,borderRadius:s.radius.md,..._corners.smoothCorners,padding:s.space.md,borderWidth:1,borderColor:s.colors.border},i,n],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[o?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{marginRight:s.space.sm},children:(0,_jsxRuntime.jsx)(_index2.Skeleton,{shape:"circle",width:32,height:32})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flex:1},children:[void 0!==e?(0,_jsxRuntime.jsx)(_index2.Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:s.space.xs}}):null,(0,_jsxRuntime.jsx)(_index2.SkeletonText,{lines:2,fontSize:s.text.sm.size,lastLineWidth:"70%"}),t&&t.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",marginTop:s.space.sm},children:t.map((e,t)=>(0,_jsxRuntime.jsx)(_index2.Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:s.space.sm}},`sk-banner-action-${t}`))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton",Banner.Skeleton=BannerSkeleton;const tintFor=(e,t)=>{switch(t){case"success":return{bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors["success-text"],on:e.colors["on-success"],glyph:"✓"};case"warning":return{bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors["warning-text"],on:e.colors["on-warning"],glyph:"⚠"};case"danger":return{bar:e.colors.danger,glyphColor:e.colors.danger,ink:e.colors["danger-text"],on:e.colors["on-danger"],glyph:"✗"};case"neutral":return{bar:e.colors["text-subtle"],glyphColor:e.colors["text-muted"],ink:e.colors["text-muted"],on:e.colors["on-neutral-strong"],glyph:"i"};default:return{bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors["primary-text"],on:e.colors["on-primary"],glyph:"i"}}},buildStyles=e=>{const t=e.components.banner,r=e.space.sm;return _reactNative.StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.space.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:t["tint-bar-width"]},row:{flexDirection:"row",alignItems:"flex-start"},iconWrap:{marginRight:r},iconCircle:{width:28,height:28,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",marginRight:r},iconGlyph:{fontSize:e.text.base.size,fontWeight:"700",lineHeight:17},textBlock:{flex:1,paddingRight:e.space.xs},closeBtn:{width:28,height:28,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.space.xxs},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.space.xs,columnGap:e.space.xs,rowGap:e.space.xs},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,borderRadius:e.radius.sm,..._corners.smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.space.md}})};var _default=exports.default=Banner;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Banner=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_hitSlop=require("../../utils/hitSlop.js"),_index2=require("../Skeleton/index.js"),_jsxRuntime=require("react/jsx-runtime");const Banner=exports.Banner=(0,_react.forwardRef)((e,t)=>{const{title:r,message:i,variant:n="info",icon:s,actions:o,dismissible:a=!1,onDismiss:l,haptic:c,visible:d=!0,animateMount:u=!0,loading:x=!1,accessibilityRole:m="alert",accessibilityLabel:p,style:g,containerStyle:h,iconCircleStyle:_,tintBarStyle:y,closeButtonStyle:b,actionButtonStyle:j,testID:f}=e,v=(0,_index.useTheme)(),R=(0,_usePresenceMotion.usePresenceMotion)(),w=(0,_react.useMemo)(()=>buildStyles(v),[v]),S=(0,_react.useMemo)(()=>tintFor(v,n),[v,n]),[N,k]=R.range(-20,0),B=(0,_react.useRef)((0,_index.createAnimatedValue)(u&&d?N:0)).current,C=(0,_react.useRef)((0,_index.createAnimatedValue)(u&&d?0:d?1:0)).current,[V,z]=(0,_react.useState)(d),D=(0,_react.useRef)(!0);if((0,_react.useEffect)(()=>{if(D.current&&(D.current=!1,!u))return;let e;return d?(z(!0),e=_reactNative.Animated.parallel([_reactNative.Animated.timing(B,{toValue:k,duration:v.motion.duration.default,useNativeDriver:!0}),_reactNative.Animated.timing(C,{toValue:1,duration:R.duration("default"),useNativeDriver:!0})]),e.start()):V&&(e=_reactNative.Animated.parallel([_reactNative.Animated.timing(B,{toValue:N,duration:v.motion.duration.fast,useNativeDriver:!0}),_reactNative.Animated.timing(C,{toValue:0,duration:R.duration("fast"),useNativeDriver:!0})]),e.start(()=>{z(!1)})),()=>e?.stop()},[d]),!V)return null;const T=r??" ",H="string"==typeof i?i??" ":"",M="alert"===m?"danger"===n?"assertive":"polite":"none",A=(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{ref:t,accessibilityRole:m,accessibilityLiveRegion:M,accessibilityLabel:p,testID:f,style:[w.container,{backgroundColor:v.colors["bg-subtle"],borderRadius:v.radius.md,..._corners.smoothCorners,padding:v.space.md,opacity:C,transform:[{translateY:B}]},g,h],children:[v.components.banner["tint-bar-width"]>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tintBar,{backgroundColor:S.bar},y]}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.row,children:[!1===s?null:s?(0,_jsxRuntime.jsx)(_reactNative.View,{style:w.iconWrap,children:s}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.iconCircle,{backgroundColor:`${S.bar}22`},_],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.iconGlyph,{color:S.ink}],accessible:!1,children:S.glyph})}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.textBlock,children:[r||x?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:v.colors["text-body"],fontSize:v.text.base.size,...(0,_index.fontFor)(v,"semibold"),lineHeight:20},numberOfLines:2,children:T}):null,"string"==typeof i||x?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:v.colors["text-muted"],fontSize:v.text.sm.size,...(0,_index.fontFor)(v,"normal"),lineHeight:18,marginTop:r?v.space.xxs:0},children:H||" "}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{marginTop:r?v.space.xxs:0},children:i})]}),a?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{accessibilityRole:"button",accessibilityLabel:"Dismiss banner",onPress:()=>{const e=(0,_hapticUtils.resolveHaptic)(c,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),l?.()},hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),style:({pressed:e})=>[w.closeBtn,{backgroundColor:e?v.colors["surface-pressed"]:"transparent"},b],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:v.colors["text-muted"],fontSize:v.text.lg.size,fontWeight:v.weight.bold,lineHeight:17},accessible:!1,children:"×"})}):null]}),o&&o.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:w.actionsRow,children:o.map((e,t)=>{const r=e.tone??"primary",i=e.variant??"ghost",n="danger"===r?v.colors.danger:"neutral"===r?v.colors["text-muted"]:S.glyphColor,s="danger"===r?v.colors["danger-text"]:"neutral"===r?v.colors["text-muted"]:S.ink,o="danger"===r?v.colors["on-danger"]:"neutral"===r?v.colors["on-neutral-strong"]:S.on,a="solid"===i;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{accessibilityRole:"button",accessibilityLabel:e.label,onPress:()=>{const t=(0,_hapticUtils.resolveHaptic)(c,"selection");t&&(0,_hapticUtils.triggerHaptic)(t),e.onPress()},style:({pressed:t})=>[w.actionBtn,"md"===e.size&&w.actionBtnMd,"outline"===i&&{borderWidth:1,borderColor:s},{backgroundColor:a?n:t?v.colors["surface-pressed"]:"transparent",opacity:a&&t?.85:1},j],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:a?o:s,fontSize:v.text.sm.size,textAlign:"center",...(0,_index.fontFor)(v,"semibold")},children:e.label})},`${e.label}-${t}`)})}):null]});return x?(0,_jsxRuntime.jsx)(BannerSkeleton,{...e}):A});Banner.displayName="Banner";const BannerSkeleton=({title:e,actions:t,icon:r,containerStyle:i,style:n})=>{const s=(0,_index.useTheme)(),o=!1!==r;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:s.colors.surface,borderRadius:s.radius.md,..._corners.smoothCorners,padding:s.space.md,borderWidth:1,borderColor:s.colors.border},i,n],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[o?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{marginRight:s.space.sm},children:(0,_jsxRuntime.jsx)(_index2.Skeleton,{shape:"circle",width:32,height:32})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flex:1},children:[void 0!==e?(0,_jsxRuntime.jsx)(_index2.Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:s.space.xs}}):null,(0,_jsxRuntime.jsx)(_index2.SkeletonText,{lines:2,fontSize:s.text.sm.size,lastLineWidth:"70%"}),t&&t.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",marginTop:s.space.sm},children:t.map((e,t)=>(0,_jsxRuntime.jsx)(_index2.Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:s.space.sm}},`sk-banner-action-${t}`))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton",Banner.Skeleton=BannerSkeleton;const tintFor=(e,t)=>{switch(t){case"success":return{bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors["success-text"],on:e.colors["on-success"],glyph:"✓"};case"warning":return{bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors["warning-text"],on:e.colors["on-warning"],glyph:"⚠"};case"danger":return{bar:e.colors.danger,glyphColor:e.colors.danger,ink:e.colors["danger-text"],on:e.colors["on-danger"],glyph:"✗"};case"neutral":return{bar:e.colors["text-subtle"],glyphColor:e.colors["text-muted"],ink:e.colors["text-muted"],on:e.colors["on-neutral-strong"],glyph:"i"};default:return{bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors["primary-text"],on:e.colors["on-primary"],glyph:"i"}}},buildStyles=e=>{const t=e.components.banner,r=e.space.sm;return _reactNative.StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.space.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:t["tint-bar-width"]},row:{flexDirection:"row",alignItems:"flex-start"},iconWrap:{marginRight:r},iconCircle:{width:28,height:28,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",marginRight:r},iconGlyph:{fontSize:e.text.base.size,fontWeight:"700",lineHeight:17},textBlock:{flex:1,paddingRight:e.space.xs},closeBtn:{width:28,height:28,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.space.xxs},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.space.xs,columnGap:e.space.xs,rowGap:e.space.xs},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,borderRadius:e.radius.sm,..._corners.smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.space.md}})};var _default=exports.default=Banner;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DatePicker=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index3=require("../PickerTrigger/index.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const NAV_BUTTON_SIZE=36,AnimatedGestureRoot=_reactNative.Animated.createAnimatedComponent(_reactNativeGestureHandler.GestureHandlerRootView),GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),isSameDay=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),toIso=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,addMonths=(e,t)=>new Date(e.getFullYear(),e.getMonth()+t,1),buildMonthMatrix=(e,t)=>{const a=e.getFullYear(),r=e.getMonth(),i=(new Date(a,r,1).getDay()-t+7)%7,s=[];for(let e=0;e<42;e+=1){const t=new Date(a,r,1-i+e);s.push({date:t,inMonth:t.getMonth()===r,iso:toIso(t)})}return s},weekdayLabels=(e,t)=>{const a=new Intl.DateTimeFormat(e,{weekday:"short"}),r=[];for(let e=0;e<7;e+=1){const i=new Date(1970,0,4+(t+e)%7);r.push(a.format(i))}return r},formatMonthYear=(e,t)=>new Intl.DateTimeFormat(t,{month:"long",year:"numeric"}).format(e),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:i,maxDate:s,disabledDates:n,mode:o="modal",locale:l="en-IN",weekStartsOn:c=0,title:d="Select Date",confirmLabel:u="Confirm",cancelLabel:m="Cancel",style:_,containerStyle:g,headerLabelStyle:x,navButtonStyle:y,footerButtonStyle:h,haptic:b,testID:p,label:v,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,formatValue:M,triggerStyle:T}=e,V=void 0!==e.visible,[k,P]=(0,_react.useState)(!1),I=V?e.visible:k,F=V?p:p?`${p}-calendar`:void 0,Y=(0,_index.useTheme)(),L=(0,_usePresenceMotion.usePresenceMotion)(),[z,B]=(0,_ModalSafeArea.useModalInsets)(),$=(0,_react.useMemo)(()=>buildStyles(Y),[Y]),[q,H]=(0,_react.useState)(()=>startOfDay(new Date));(0,_react.useEffect)(()=>{I&&H(startOfDay(new Date))},[I]);const E=t?startOfDay(t):q,[O,W]=(0,_react.useState)(E),[G,X]=(0,_react.useState)(t?startOfDay(t):null),[Z,U]=(0,_react.useState)("days"),J=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,K=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,Q=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ee=(0,_react.useRef)(0),te=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ae=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,re=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ie=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,se=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ne=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current;(0,_react.useEffect)(()=>{if(t){const e=startOfDay(t);X(e),W(e)}else X(null)},[t]);const oe=(0,_react.useMemo)(()=>{const e=new Set;return n?.forEach(t=>e.add(toIso(startOfDay(t)))),e},[n]),le=(0,_react.useMemo)(()=>i?startOfDay(i):null,[i]),ce=(0,_react.useMemo)(()=>s?startOfDay(s):null,[s]),de=(0,_react.useCallback)(e=>!!(le&&e.getTime()<le.getTime())||(!!(ce&&e.getTime()>ce.getTime())||!!oe.has(toIso(e))),[le,ce,oe]),ue=(0,_react.useMemo)(()=>buildMonthMatrix(O,c),[O,c]),me=(0,_react.useMemo)(()=>buildYearCells(O.getFullYear()),[O]),ge=(0,_react.useMemo)(()=>buildDecadeCells(O.getFullYear()),[O]),xe=(0,_react.useMemo)(()=>weekdayLabels(l,c),[l,c]),ye=(0,_react.useMemo)(()=>new Intl.DateTimeFormat(l,{weekday:"long",year:"numeric",month:"long",day:"numeric"}),[l]),he=(0,_react.useMemo)(()=>{if("days"===Z)return formatMonthYear(O,l);if("years"===Z){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[O,ge,l,Z,me]),be=(0,_react.useCallback)(e=>!!(le&&e<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),pe=(0,_react.useCallback)(e=>!!(le&&e+10-1<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),ve=(0,_react.useCallback)(e=>{!1!==b&&(0,_index2.triggerHaptic)("impactLight");const t=e>0?1:-1,a=Y.motion.duration.fast,r=Y.motion.duration.fast,[i]=L.range(32*-t,0),[s]=L.range(32*t,0),n=L.reduced?L.duration("fast"):a,o=L.reduced?L.duration("fast"):r;_reactNative.Animated.sequence([_reactNative.Animated.parallel([_reactNative.Animated.timing(te,{toValue:i,duration:a,easing:_reactNative.Easing.out(_reactNative.Easing.quad),useNativeDriver:!0}),_reactNative.Animated.timing(ae,{toValue:0,duration:n,useNativeDriver:!0})]),_reactNative.Animated.timing(te,{toValue:s,duration:0,useNativeDriver:!0}),_reactNative.Animated.parallel([_reactNative.Animated.timing(te,{toValue:0,duration:r,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(ae,{toValue:1,duration:o,useNativeDriver:!0})])]).start();const c=addMonths(O,e);W(c),_reactNative.AccessibilityInfo.announceForAccessibility(formatMonthYear(c,l))},[O,b,l,ae,te,L,Y.motion.duration.fast]),fe=(0,_react.useCallback)(()=>{"days"!==Z?(!1!==b&&(0,_index2.triggerHaptic)("impactLight"),W("years"===Z?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))):ve(-1)},[ve,Z,b]),je=(0,_react.useCallback)(()=>{"days"!==Z?(!1!==b&&(0,_index2.triggerHaptic)("impactLight"),W("years"===Z?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))):ve(1)},[ve,Z,b]),Ne=(0,_react.useCallback)(()=>{const[e]=L.range(.9,1),t=L.reduced?L.duration("default"):Y.motion.duration.default;(0,_index.setNativeValue)(ie,0),(0,_index.setNativeValue)(se,e),_reactNative.Animated.parallel([_reactNative.Animated.timing(ie,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(se,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0})]).start()},[ie,se,L,Y.motion.duration.default]),Re=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(b,"selection");if(e&&(0,_index2.triggerHaptic)(e),!L.reduced){const e=80,t=100;_reactNative.Animated.sequence([_reactNative.Animated.timing(ne,{toValue:.96,duration:e,useNativeDriver:!0}),_reactNative.Animated.timing(ne,{toValue:1,duration:t,useNativeDriver:!0})]).start()}U(e=>"days"===e?"years":"years"===e?"decades":"years"),Ne()},[Ne,ne,b,L.reduced]),we=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),W(t=>new Date(e,t.getMonth(),1)),U("days"),Ne()},[Ne,b]),De=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),W(t=>new Date(e+4,t.getMonth(),1)),U("years"),Ne()},[Ne,b]),Ce=(0,_react.useCallback)(e=>{if(de(e.date))return;const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),X(e.date),e.inMonth||W(new Date(e.date.getFullYear(),e.date.getMonth(),1)),L.reduced||((0,_index.setNativeValue)(re,.7),_reactNative.Animated.spring(re,{toValue:1,damping:Y.motion.spring.bouncy.damping,stiffness:Y.motion.spring.bouncy.stiffness,mass:Y.motion.spring.bouncy.mass,useNativeDriver:!0}).start())},[de,L.reduced,re,Y.motion.spring.bouncy,b]),Se=(0,_react.useCallback)(()=>{V||P(!1),r?.()},[V,r]),Ae=(0,_react.useCallback)(()=>{"modal"===o?_reactNative.Animated.parallel([_reactNative.Animated.timing(J,{toValue:0,duration:L.duration("default"),easing:_reactNative.Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!1}),_reactNative.Animated.timing(K,{toValue:0,duration:L.duration("fast"),easing:_reactNative.Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!0})]).start(()=>{Se()}):Se()},[J,o,Se,L,K,Y.motion.ease.accelerate]),{handleGesture:Me,opacity:Te}=(0,_useDragToDismiss.useDragToDismiss)({drag:Q,travel:()=>ee.current||320,onDismiss:Ae}),Ve=(0,_react.useMemo)(()=>_reactNative.Animated.multiply(K,Te),[K,Te]),ke=(0,_react.useMemo)(()=>J.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(Y.colors.scrim),Y.colors.scrim]}),[J,Y.colors.scrim]);(0,_react.useEffect)(()=>{if("modal"===o&&I){J.setValue(0),(0,_index.setNativeValue)(K,0),(0,_index.setNativeValue)(Q,0),(0,_index.setNativeValue)(Te,1);const e=L.reduced?_reactNative.Animated.timing(K,{toValue:1,duration:L.duration("default"),useNativeDriver:!0}):_reactNative.Animated.spring(K,{toValue:1,damping:Y.motion.spring.gentle.damping,stiffness:Y.motion.spring.gentle.stiffness,mass:Y.motion.spring.gentle.mass,useNativeDriver:!0}),t=_reactNative.Animated.parallel([_reactNative.Animated.timing(J,{toValue:1,duration:L.duration("default"),easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!1}),e]);return t.start(),()=>t.stop()}},[I,o,J,L,K,Q,Te,Y.motion]);const Pe=(0,_react.useCallback)(()=>{!1!==b&&(0,_index2.triggerHaptic)("selection"),Ae()},[Ae,b]),Ie=(0,_react.useCallback)(()=>{G&&(!1!==b&&(0,_index2.triggerHaptic)("notificationSuccess"),a?.(G),Ae())},[Ae,a,G,b]),Fe=K.interpolate({inputRange:[0,1],outputRange:L.range(320,0)}),Ye=(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.titleRow,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.title,accessibilityRole:"header",children:d})}),Le=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.card,_,g],accessibilityRole:"modal"===o?void 0:"none",accessible:!1,testID:F,children:["modal"===o?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Me,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.handle}),Ye]})}):Ye,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.headerRow,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:fe,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Previous month":"years"===Z?"Previous years":"Previous decades",hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.navText,children:"‹"})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Re,style:[$.headerLabelWrap,x],accessibilityRole:"button",accessibilityLabel:"days"===Z?`${he}, switch to year selection`:"years"===Z?`${he}, switch to decade selection`:`${he}, switch to year selection`,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[$.headerLabelInner,{transform:[{scale:ne}],opacity:"days"===Z?ae:1}],children:[(0,_jsxRuntime.jsx)(_reactNative.Animated.Text,{style:[$.headerLabel,{transform:[{translateX:"days"===Z?te:0}]}],accessibilityLiveRegion:"polite",children:he}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.headerCaret,children:(Y.settings.icons.chevronDown??_defaultIcons.defaultIcons.chevronDown)({size:Y.text.sm.size,color:Y.colors["text-muted"]})})]})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:je,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Next month":"years"===Z?"Next years":"Next decades",hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.navText,children:"›"})})]}),"days"===Z?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.weekdayRow,children:xe.map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.weekdayCell,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.weekdayText,children:e})},`${e}-${t}`))}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.grid,{opacity:ae,transform:[{translateX:te}]}],children:Array.from({length:6}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:ue.slice(7*t,7*t+7).map(e=>{const t=de(e.date),a=!!G&&isSameDay(e.date,G),r=isSameDay(e.date,q),i=a?Y.colors.primary:"transparent",s=r&&!a?Y.colors.primary:"transparent",n=a?Y.colors["on-primary"]:e.inMonth?t?Y.colors["text-disabled"]:Y.colors["text-body"]:Y.colors["text-subtle"],o=t?.3:e.inMonth?1:.4;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:ye.format(e.date),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.dayCell,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.dayInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:o},a?{transform:[{scale:re}]}:null],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.dayText,{color:n}],children:e.date.getDate()})})},e.iso)})},`r-${t}`))})]}):"years"===Z?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.yearGrid,{opacity:ie,transform:[{scale:se}]}],children:Array.from({length:3}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:me.slice(4*t,4*t+4).map(e=>{const t=be(e),a=!!G&&G.getFullYear()===e,r=q.getFullYear()===e,i=a?Y.colors.primary:"transparent",s=r&&!a?Y.colors.primary:"transparent",n=a?Y.colors["on-primary"]:t?Y.colors["text-disabled"]:Y.colors["text-body"],o=t?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>we(e),accessibilityRole:"button",accessibilityLabel:`Year ${e}`,accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.yearCell,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[$.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:o}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.yearText,{color:n}],children:e})})},`year-${e}`)})},`yr-${t}`))}):(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.yearGrid,{opacity:ie,transform:[{scale:se}]}],children:Array.from({length:3}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:ge.slice(4*t,4*t+4).map(e=>{const t=e+10-1,a=pe(e),r=!!G&&decadeStartFor(G.getFullYear())===e,i=decadeStartFor(q.getFullYear())===e,s=r?Y.colors.primary:"transparent",n=i&&!r?Y.colors.primary:"transparent",o=r?Y.colors["on-primary"]:a?Y.colors["text-disabled"]:Y.colors["text-body"],l=a?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:a,onPress:()=>De(e),accessibilityRole:"button",accessibilityLabel:`Decade ${e} to ${t}`,accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:$.yearCell,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.yearInner,{backgroundColor:s,borderColor:n,borderWidth:i&&!r?1.5:0,opacity:l}],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.yearText,{color:o}],children:`${e}s`}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.decadeRangeText,{color:r?Y.colors["on-primary"]:Y.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${t}`))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Pe,style:({pressed:e})=>[$.footerBtn,$.footerCancel,e&&$.footerBtnPressed,h],accessibilityRole:"button",accessibilityLabel:m,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.footerBtnText,{color:Y.colors["text-muted"]}],children:m})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Ie,disabled:!G,style:({pressed:e})=>[$.footerBtn,$.footerConfirm,{backgroundColor:Y.colors.primary,opacity:G?1:.5},e&&{backgroundColor:Y.colors["primary-hover"]},h],accessibilityRole:"button",accessibilityLabel:u,accessibilityState:{disabled:!G},"aria-disabled":!G,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.footerBtnText,{color:Y.colors["on-primary"]}],children:u})})]})]}),ze=t?(M??(e=>e.toLocaleDateString()))(t):void 0,Be=!V;if("inline"===o)return I||Be?Be?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index3.PickerTrigger,{label:v,value:ze,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,onPress:()=>P(!0),triggerStyle:T,testID:p}),I?Le:null]}):Le:null;const $e=(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:I,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Ae,children:(0,_jsxRuntime.jsx)(_ModalSafeArea.ModalSafeArea,{onInsets:B,children:(0,_jsxRuntime.jsxs)(AnimatedGestureRoot,{collapsable:!1,style:[$.backdrop,{backgroundColor:ke}],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:Ae,accessibilityLabel:"Dismiss"}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.sheetWrap,{paddingBottom:Math.max(z.bottom,Y.space.lg),opacity:Ve,transform:[{translateY:_reactNative.Animated.add(Fe,Q)}]}],onLayout:e=>{ee.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Le}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})});return Be?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index3.PickerTrigger,{label:v,value:ze,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,onPress:()=>P(!0),triggerStyle:T,testID:p}),$e]}):$e};exports.DatePicker=DatePicker;const buildStyles=e=>{const t=e.shadow.popover;return _reactNative.StyleSheet.create({backdrop:{..._reactNative.StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,..._corners.smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},weekdayRow:{flexDirection:"row",marginBottom:e.space.xs},weekdayCell:{flex:1,alignItems:"center",paddingVertical:e.space.xs},weekdayText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,color:e.colors["text-subtle"],letterSpacing:e["letter-spacing"].wide},grid:{},gridRow:{flexDirection:"row"},dayCell:{flex:1,aspectRatio:1,alignItems:"center",justifyContent:"center",padding:e.space.xxs},dayInner:{width:"100%",height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},dayText:{fontSize:e.text.sm.size,fontWeight:e.weight.medium},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,..._corners.smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold}})};var _default=exports.default=DatePicker;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DatePicker=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index3=require("../PickerTrigger/index.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const NAV_BUTTON_SIZE=36,AnimatedGestureRoot=_reactNative.Animated.createAnimatedComponent(_reactNativeGestureHandler.GestureHandlerRootView),GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),isSameDay=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),toIso=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,addMonths=(e,t)=>new Date(e.getFullYear(),e.getMonth()+t,1),buildMonthMatrix=(e,t)=>{const a=e.getFullYear(),r=e.getMonth(),i=(new Date(a,r,1).getDay()-t+7)%7,s=[];for(let e=0;e<42;e+=1){const t=new Date(a,r,1-i+e);s.push({date:t,inMonth:t.getMonth()===r,iso:toIso(t)})}return s},weekdayLabels=(e,t)=>{const a=new Intl.DateTimeFormat(e,{weekday:"short"}),r=[];for(let e=0;e<7;e+=1){const i=new Date(1970,0,4+(t+e)%7);r.push(a.format(i))}return r},formatMonthYear=(e,t)=>new Intl.DateTimeFormat(t,{month:"long",year:"numeric"}).format(e),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:i,maxDate:s,disabledDates:n,mode:o="modal",locale:l="en-IN",weekStartsOn:c=0,title:d="Select Date",confirmLabel:u="Confirm",cancelLabel:m="Cancel",style:_,containerStyle:g,headerLabelStyle:x,navButtonStyle:y,footerButtonStyle:h,haptic:b,testID:p,label:v,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,formatValue:M,triggerStyle:T}=e,V=void 0!==e.visible,[k,P]=(0,_react.useState)(!1),I=V?e.visible:k,F=V?p:p?`${p}-calendar`:void 0,Y=(0,_index.useTheme)(),L=(0,_usePresenceMotion.usePresenceMotion)(),[z,B]=(0,_ModalSafeArea.useModalInsets)(),$=(0,_react.useMemo)(()=>buildStyles(Y),[Y]),[q,H]=(0,_react.useState)(()=>startOfDay(new Date));(0,_react.useEffect)(()=>{I&&H(startOfDay(new Date))},[I]);const E=t?startOfDay(t):q,[O,W]=(0,_react.useState)(E),[G,X]=(0,_react.useState)(t?startOfDay(t):null),[Z,U]=(0,_react.useState)("days"),J=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,K=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,Q=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ee=(0,_react.useRef)(0),te=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ae=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,re=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ie=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,se=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ne=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current;(0,_react.useEffect)(()=>{if(t){const e=startOfDay(t);X(e),W(e)}else X(null)},[t]);const oe=(0,_react.useMemo)(()=>{const e=new Set;return n?.forEach(t=>{e.add(toIso(startOfDay(t)))}),e},[n]),le=(0,_react.useMemo)(()=>i?startOfDay(i):null,[i]),ce=(0,_react.useMemo)(()=>s?startOfDay(s):null,[s]),de=(0,_react.useCallback)(e=>!!(le&&e.getTime()<le.getTime())||(!!(ce&&e.getTime()>ce.getTime())||!!oe.has(toIso(e))),[le,ce,oe]),ue=(0,_react.useMemo)(()=>buildMonthMatrix(O,c),[O,c]),me=(0,_react.useMemo)(()=>buildYearCells(O.getFullYear()),[O]),ge=(0,_react.useMemo)(()=>buildDecadeCells(O.getFullYear()),[O]),xe=(0,_react.useMemo)(()=>weekdayLabels(l,c),[l,c]),ye=(0,_react.useMemo)(()=>new Intl.DateTimeFormat(l,{weekday:"long",year:"numeric",month:"long",day:"numeric"}),[l]),he=(0,_react.useMemo)(()=>{if("days"===Z)return formatMonthYear(O,l);if("years"===Z){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[O,ge,l,Z,me]),be=(0,_react.useCallback)(e=>!!(le&&e<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),pe=(0,_react.useCallback)(e=>!!(le&&e+10-1<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),ve=(0,_react.useCallback)(e=>{!1!==b&&(0,_index2.triggerHaptic)("impactLight");const t=e>0?1:-1,a=Y.motion.duration.fast,r=Y.motion.duration.fast,[i]=L.range(32*-t,0),[s]=L.range(32*t,0),n=L.reduced?L.duration("fast"):a,o=L.reduced?L.duration("fast"):r;_reactNative.Animated.sequence([_reactNative.Animated.parallel([_reactNative.Animated.timing(te,{toValue:i,duration:a,easing:_reactNative.Easing.out(_reactNative.Easing.quad),useNativeDriver:!0}),_reactNative.Animated.timing(ae,{toValue:0,duration:n,useNativeDriver:!0})]),_reactNative.Animated.timing(te,{toValue:s,duration:0,useNativeDriver:!0}),_reactNative.Animated.parallel([_reactNative.Animated.timing(te,{toValue:0,duration:r,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(ae,{toValue:1,duration:o,useNativeDriver:!0})])]).start();const c=addMonths(O,e);W(c),_reactNative.AccessibilityInfo.announceForAccessibility(formatMonthYear(c,l))},[O,b,l,ae,te,L,Y.motion.duration.fast]),fe=(0,_react.useCallback)(()=>{"days"!==Z?(!1!==b&&(0,_index2.triggerHaptic)("impactLight"),W("years"===Z?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))):ve(-1)},[ve,Z,b]),je=(0,_react.useCallback)(()=>{"days"!==Z?(!1!==b&&(0,_index2.triggerHaptic)("impactLight"),W("years"===Z?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))):ve(1)},[ve,Z,b]),Ne=(0,_react.useCallback)(()=>{const[e]=L.range(.9,1),t=L.reduced?L.duration("default"):Y.motion.duration.default;(0,_index.setNativeValue)(ie,0),(0,_index.setNativeValue)(se,e),_reactNative.Animated.parallel([_reactNative.Animated.timing(ie,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(se,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0})]).start()},[ie,se,L,Y.motion.duration.default]),Re=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(b,"selection");if(e&&(0,_index2.triggerHaptic)(e),!L.reduced){const e=80,t=100;_reactNative.Animated.sequence([_reactNative.Animated.timing(ne,{toValue:.96,duration:e,useNativeDriver:!0}),_reactNative.Animated.timing(ne,{toValue:1,duration:t,useNativeDriver:!0})]).start()}U(e=>"days"===e?"years":"years"===e?"decades":"years"),Ne()},[Ne,ne,b,L.reduced]),we=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),W(t=>new Date(e,t.getMonth(),1)),U("days"),Ne()},[Ne,b]),De=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),W(t=>new Date(e+4,t.getMonth(),1)),U("years"),Ne()},[Ne,b]),Ce=(0,_react.useCallback)(e=>{if(de(e.date))return;const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),X(e.date),e.inMonth||W(new Date(e.date.getFullYear(),e.date.getMonth(),1)),L.reduced||((0,_index.setNativeValue)(re,.7),_reactNative.Animated.spring(re,{toValue:1,damping:Y.motion.spring.bouncy.damping,stiffness:Y.motion.spring.bouncy.stiffness,mass:Y.motion.spring.bouncy.mass,useNativeDriver:!0}).start())},[de,L.reduced,re,Y.motion.spring.bouncy,b]),Se=(0,_react.useCallback)(()=>{V||P(!1),r?.()},[V,r]),Ae=(0,_react.useCallback)(()=>{"modal"===o?_reactNative.Animated.parallel([_reactNative.Animated.timing(J,{toValue:0,duration:L.duration("default"),easing:_reactNative.Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!1}),_reactNative.Animated.timing(K,{toValue:0,duration:L.duration("fast"),easing:_reactNative.Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!0})]).start(()=>{Se()}):Se()},[J,o,Se,L,K,Y.motion.ease.accelerate]),{handleGesture:Me,opacity:Te}=(0,_useDragToDismiss.useDragToDismiss)({drag:Q,travel:()=>ee.current||320,onDismiss:Ae}),Ve=(0,_react.useMemo)(()=>_reactNative.Animated.multiply(K,Te),[K,Te]),ke=(0,_react.useMemo)(()=>J.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(Y.colors.scrim),Y.colors.scrim]}),[J,Y.colors.scrim]);(0,_react.useEffect)(()=>{if("modal"===o&&I){J.setValue(0),(0,_index.setNativeValue)(K,0),(0,_index.setNativeValue)(Q,0),(0,_index.setNativeValue)(Te,1);const e=L.reduced?_reactNative.Animated.timing(K,{toValue:1,duration:L.duration("default"),useNativeDriver:!0}):_reactNative.Animated.spring(K,{toValue:1,damping:Y.motion.spring.gentle.damping,stiffness:Y.motion.spring.gentle.stiffness,mass:Y.motion.spring.gentle.mass,useNativeDriver:!0}),t=_reactNative.Animated.parallel([_reactNative.Animated.timing(J,{toValue:1,duration:L.duration("default"),easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!1}),e]);return t.start(),()=>t.stop()}},[I,o,J,L,K,Q,Te,Y.motion]);const Pe=(0,_react.useCallback)(()=>{!1!==b&&(0,_index2.triggerHaptic)("selection"),Ae()},[Ae,b]),Ie=(0,_react.useCallback)(()=>{G&&(!1!==b&&(0,_index2.triggerHaptic)("notificationSuccess"),a?.(G),Ae())},[Ae,a,G,b]),Fe=K.interpolate({inputRange:[0,1],outputRange:L.range(320,0)}),Ye=(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.titleRow,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.title,accessibilityRole:"header",children:d})}),Le=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.card,_,g],accessibilityRole:"modal"===o?void 0:"none",accessible:!1,testID:F,children:["modal"===o?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Me,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.handle}),Ye]})}):Ye,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.headerRow,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:fe,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Previous month":"years"===Z?"Previous years":"Previous decades",hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.navText,children:"‹"})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Re,style:[$.headerLabelWrap,x],accessibilityRole:"button",accessibilityLabel:"days"===Z?`${he}, switch to year selection`:"years"===Z?`${he}, switch to decade selection`:`${he}, switch to year selection`,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[$.headerLabelInner,{transform:[{scale:ne}],opacity:"days"===Z?ae:1}],children:[(0,_jsxRuntime.jsx)(_reactNative.Animated.Text,{style:[$.headerLabel,{transform:[{translateX:"days"===Z?te:0}]}],accessibilityLiveRegion:"polite",children:he}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.headerCaret,children:(Y.settings.icons.chevronDown??_defaultIcons.defaultIcons.chevronDown)({size:Y.text.sm.size,color:Y.colors["text-muted"]})})]})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:je,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Next month":"years"===Z?"Next years":"Next decades",hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.navText,children:"›"})})]}),"days"===Z?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.weekdayRow,children:xe.map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.weekdayCell,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.weekdayText,children:e})},`${e}-${t}`))}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.grid,{opacity:ae,transform:[{translateX:te}]}],children:Array.from({length:6}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:ue.slice(7*t,7*t+7).map(e=>{const t=de(e.date),a=!!G&&isSameDay(e.date,G),r=isSameDay(e.date,q),i=a?Y.colors.primary:"transparent",s=r&&!a?Y.colors.primary:"transparent",n=a?Y.colors["on-primary"]:e.inMonth?t?Y.colors["text-disabled"]:Y.colors["text-body"]:Y.colors["text-subtle"],o=t?.3:e.inMonth?1:.4;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:ye.format(e.date),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.dayCell,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.dayInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:o},a?{transform:[{scale:re}]}:null],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.dayText,{color:n}],children:e.date.getDate()})})},e.iso)})},`r-${t}`))})]}):"years"===Z?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.yearGrid,{opacity:ie,transform:[{scale:se}]}],children:Array.from({length:3}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:me.slice(4*t,4*t+4).map(e=>{const t=be(e),a=!!G&&G.getFullYear()===e,r=q.getFullYear()===e,i=a?Y.colors.primary:"transparent",s=r&&!a?Y.colors.primary:"transparent",n=a?Y.colors["on-primary"]:t?Y.colors["text-disabled"]:Y.colors["text-body"],o=t?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>we(e),accessibilityRole:"button",accessibilityLabel:`Year ${e}`,accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.yearCell,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[$.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:o}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.yearText,{color:n}],children:e})})},`year-${e}`)})},`yr-${t}`))}):(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.yearGrid,{opacity:ie,transform:[{scale:se}]}],children:Array.from({length:3}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:ge.slice(4*t,4*t+4).map(e=>{const t=e+10-1,a=pe(e),r=!!G&&decadeStartFor(G.getFullYear())===e,i=decadeStartFor(q.getFullYear())===e,s=r?Y.colors.primary:"transparent",n=i&&!r?Y.colors.primary:"transparent",o=r?Y.colors["on-primary"]:a?Y.colors["text-disabled"]:Y.colors["text-body"],l=a?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:a,onPress:()=>De(e),accessibilityRole:"button",accessibilityLabel:`Decade ${e} to ${t}`,accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:$.yearCell,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.yearInner,{backgroundColor:s,borderColor:n,borderWidth:i&&!r?1.5:0,opacity:l}],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.yearText,{color:o}],children:`${e}s`}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.decadeRangeText,{color:r?Y.colors["on-primary"]:Y.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${t}`))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Pe,style:({pressed:e})=>[$.footerBtn,$.footerCancel,e&&$.footerBtnPressed,h],accessibilityRole:"button",accessibilityLabel:m,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.footerBtnText,{color:Y.colors["text-muted"]}],children:m})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Ie,disabled:!G,style:({pressed:e})=>[$.footerBtn,$.footerConfirm,{backgroundColor:Y.colors.primary,opacity:G?1:.5},e&&{backgroundColor:Y.colors["primary-hover"]},h],accessibilityRole:"button",accessibilityLabel:u,accessibilityState:{disabled:!G},"aria-disabled":!G,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.footerBtnText,{color:Y.colors["on-primary"]}],children:u})})]})]}),ze=t?(M??(e=>e.toLocaleDateString()))(t):void 0,Be=!V;if("inline"===o)return I||Be?Be?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index3.PickerTrigger,{label:v,value:ze,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,onPress:()=>P(!0),triggerStyle:T,testID:p}),I?Le:null]}):Le:null;const $e=(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:I,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Ae,children:(0,_jsxRuntime.jsx)(_ModalSafeArea.ModalSafeArea,{onInsets:B,children:(0,_jsxRuntime.jsxs)(AnimatedGestureRoot,{collapsable:!1,style:[$.backdrop,{backgroundColor:ke}],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:Ae,accessibilityLabel:"Dismiss"}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.sheetWrap,{paddingBottom:Math.max(z.bottom,Y.space.lg),opacity:Ve,transform:[{translateY:_reactNative.Animated.add(Fe,Q)}]}],onLayout:e=>{ee.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Le}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})});return Be?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index3.PickerTrigger,{label:v,value:ze,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,onPress:()=>P(!0),triggerStyle:T,testID:p}),$e]}):$e};exports.DatePicker=DatePicker;const buildStyles=e=>{const t=e.shadow.popover;return _reactNative.StyleSheet.create({backdrop:{..._reactNative.StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,..._corners.smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},weekdayRow:{flexDirection:"row",marginBottom:e.space.xs},weekdayCell:{flex:1,alignItems:"center",paddingVertical:e.space.xs},weekdayText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,color:e.colors["text-subtle"],letterSpacing:e["letter-spacing"].wide},grid:{},gridRow:{flexDirection:"row"},dayCell:{flex:1,aspectRatio:1,alignItems:"center",justifyContent:"center",padding:e.space.xxs},dayInner:{width:"100%",height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},dayText:{fontSize:e.text.sm.size,fontWeight:e.weight.medium},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,..._corners.smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold}})};var _default=exports.default=DatePicker;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.matchesAccept=exports.formatFileSize=exports.default=exports.FilePicker=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index4=require("../FieldBase/index.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index5=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");let fileIdSeq=0;const nextFileId=()=>"wfp-"+ ++fileIdSeq,DEFAULT_LABELS={trigger:"Attach file",addMore:"Add more",sheetTitle:"Add from",removeFile:e=>`Remove ${e}`,retry:"Retry upload",errorTooMany:e=>`You can attach up to ${e} files.`,errorTooLarge:(e,t)=>`${e} is larger than ${t} MB.`,errorWrongType:e=>`${e} is not an accepted file type.`},formatFileSize=e=>{if(void 0===e||e<=0)return"";const t=["B","KB","MB","GB"];let r=e,i=0;for(;r>=1024&&i<t.length-1;)r/=1024,i+=1;return`${r>=10||0===i?Math.round(r):Math.round(10*r)/10} ${t[i]}`};exports.formatFileSize=formatFileSize;const matchesAccept=(e,t)=>!t||0===t.length||!!e&&t.some(t=>"*/*"===t||"*"===t||(t.endsWith("/*")?e.startsWith(t.slice(0,t.length-1)):e===t));exports.matchesAccept=matchesAccept;const isImage=e=>!0===e.type?.startsWith("image/")||!e.type&&/\.(png|jpe?g|gif|webp|heic)$/i.test(e.name),imageSourceOf=e=>e.thumbnailUrl??(isImage(e)?e.uri??e.url:void 0),extensionOf=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"FILE":e.slice(t+1).toUpperCase().slice(0,4)},FilePicker=exports.FilePicker=(0,_react.forwardRef)((e,t)=>{const{files:r,defaultFiles:i,onChange:s,sources:o,maxFiles:n,maxSizeMB:l,accept:a,validate:c,process:d,variant:u="card",renderFile:x,renderTrigger:m,disabled:h=!1,helperText:g,error:p,labels:_,haptic:b,onPick:y,onRemove:f,onError:j,onFilePress:v,onRetry:R,style:S,accessibilityLabel:T,testID:C}=e,F=(0,_index2.useTheme)(),w=(0,_react.useMemo)(()=>buildStyles(F),[F]),z=(0,_react.useMemo)(()=>({...DEFAULT_LABELS,..._}),[_]),N=F.radius.md,P=F.colors.primary,[k,I]=(0,_index.useControllableState)({value:r,defaultValue:i??[],onChange:s}),O=(0,_react.useRef)(k);O.current=k;const V=(0,_react.useCallback)(e=>{O.current=e,I(e)},[I]),[M,B]=(0,_react.useState)(null),[L,A]=(0,_react.useState)(!1),$=p??M??void 0,q="number"==typeof n&&k.length>=n,H=(0,_react.useCallback)((e,t)=>{0!==e.length&&(B(e[0]),e.forEach(e=>j?.(e,t)),!1!==b&&(0,_index3.triggerHaptic)("notificationError"))},[j,b]),E=(0,_react.useCallback)(async e=>{let t;try{t=await e.pick()}catch(e){return void H([e instanceof Error?e.message:String(e)])}if(!t||0===t.length)return;const r=[];let i=t.map(e=>({id:nextFileId(),name:e.name??e.uri.split("/").pop()??"file",uri:e.uri,type:e.type,size:e.size,meta:e.meta,status:"idle"}));if("number"==typeof n){const e=Math.max(0,n-O.current.length);i.length>e&&(r.push(z.errorTooMany(n)),i=i.slice(0,e))}const s=[];for(const e of i){if("number"==typeof l&&"number"==typeof e.size&&e.size>1024*l*1024){r.push(z.errorTooLarge(e.name,l));continue}if(!matchesAccept(e.type,a)){r.push(z.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):s.push(e)}if(H(r),0===s.length)return;if(!d){V([...O.current,...s]),B(r.length>0?r[0]:null);const e=(0,_index3.resolveHaptic)(b,"selection");return e&&(0,_index3.triggerHaptic)(e),void y?.(s)}const o=s.map(e=>({...e,status:"processing"}));V([...O.current,...o]);const u=[];for(const e of o)try{const t=await d({...e,status:"idle"}),r={...t,id:e.id,status:t.status??"idle"};V(O.current.map(t=>t.id===e.id?r:t)),u.push(r)}catch(t){V(O.current.filter(t=>t.id!==e.id)),H([t instanceof Error?t.message:String(t)],e)}if(u.length>0){0===r.length&&B(null);const e=(0,_index3.resolveHaptic)(b,"selection");e&&(0,_index3.triggerHaptic)(e),y?.(u)}},[n,l,a,c,d,z,H,V,y,b]),W=(0,_react.useCallback)(e=>{if(h||q)return;const t=e?o.find(t=>t.key===e):1===o.length?o[0]:void 0;t?E(t):o.length>1&&A(!0)},[h,q,o,E]),D=(0,_react.useCallback)(e=>{if(h)return;V(O.current.filter(t=>t.id!==e.id)),B(null);const t=(0,_index3.resolveHaptic)(b,"selection");t&&(0,_index3.triggerHaptic)(t),f?.(e)},[h,V,f,b]),U=(0,_react.useCallback)(()=>{V([]),B(null)},[V]);(0,_react.useImperativeHandle)(t,()=>({open:W,clear:U}),[W,U]);const G=0===k.length?z.trigger:`${k.length} file${1===k.length?"":"s"} attached`,K=T??`Attachments. ${G}`,statusText=e=>{switch(e.status){case"processing":return"Processing…";case"uploading":return`Uploading ${Math.round(100*(e.progress??0))}%`;case"done":return"Uploaded";case"error":return e.error??"Failed";default:return""}},fileA11yLabel=e=>[e.name,formatFileSize(e.size),statusText(e)].filter(Boolean).join(", "),Y=F.settings.icons.attachment??_defaultIcons.defaultIcons.attachment,renderStatusOverlay=e=>{if("processing"===e.status)return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm"})});if("uploading"===e.status){const t=Math.round(100*(e.progress??0));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.tileOverlayText,{color:F.colors["on-scrim"]}],children:`${t}%`}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileProgressTrack,{backgroundColor:F.colors.border}],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileProgressFill,{width:`${t}%`,backgroundColor:F.colors.primary}]})})]})}return"done"===e.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.doneBadge,{backgroundColor:F.colors.success}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.doneBadgeText,{color:F.colors["on-success"]}],children:"✓"})}):null},renderThumbnail=e=>{const t=imageSourceOf(e);return t?(0,_jsxRuntime.jsx)(_reactNative.Image,{source:{uri:t},style:w.thumbnailImage}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.extensionTile,{backgroundColor:F.colors["bg-subtle"]}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.extensionText,{color:F.colors["text-muted"],...(0,_index2.fontFor)(F,"semibold")}],children:extensionOf(e.name)})})},removeButton=e=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>D(e),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.removeFile(e.name),style:[w.removeButton,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.removeButtonText,{color:F.colors["on-scrim"]}],children:"×"})}),retryButton=e=>R&&"error"===e.status?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>R(e),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.retry,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.retryText,{color:F.colors.primary}],children:"↻"})}):null,renderOneFile=(e,t)=>{const r={file:e,index:t,disabled:h,remove:()=>D(e),retry:R?()=>R(e):void 0},i=x?x(r):"card"===u?(e=>{const{file:t}=e;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.tile,{width:84,height:84,borderRadius:N,..._corners.smoothCorners,borderColor:"error"===t.status?F.colors.danger:F.colors.border}],children:[renderThumbnail(t),renderStatusOverlay(t),"error"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:retryButton(t)}):null,removeButton(t)]})})(r):(e=>{const{file:t}=e,r=statusText(t);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.listRow,{borderRadius:N,..._corners.smoothCorners,borderColor:"error"===t.status?F.colors.danger:F.colors.border,backgroundColor:F.colors.bg}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.listThumb,{borderRadius:F.radius.sm,..._corners.smoothCorners}],children:[renderThumbnail(t),"processing"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm"})}):null]}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.listTextWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,ellipsizeMode:"middle",style:[w.listName,{color:F.colors["text-body"],fontSize:F.text.sm.size,...(0,_index2.fontFor)(F,"medium")}],children:t.name}),(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,style:[w.listSubtitle,{color:"error"===t.status?F.colors["danger-text"]:F.colors["text-subtle"],fontSize:F.text.xs.size}],children:[formatFileSize(t.size),r].filter(Boolean).join(" · ")}),"uploading"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.listProgressTrack,{backgroundColor:F.colors.border}],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.listProgressFill,{width:`${Math.round(100*(t.progress??0))}%`,backgroundColor:F.colors.primary}]})}):null]}),retryButton(t),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>D(t),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.removeFile(t.name),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.listRemoveText,{color:F.colors["text-subtle"]}],children:"×"})})]})})(r);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:v?()=>v(e):void 0,disabled:h||!v,accessibilityLabel:fileA11yLabel(e),children:i},e.id)},J={open:W,disabled:h||q,fileCount:k.length,atCapacity:q},dashedTrigger=e=>(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>W(),disabled:h||q,accessibilityRole:"button",accessibilityLabel:K,accessibilityState:{disabled:h||q},"aria-disabled":h||q,style:({pressed:t})=>[w.trigger,e?w.triggerCompact:null,{borderRadius:N,..._corners.smoothCorners,borderColor:P,backgroundColor:t?F.colors["surface-pressed"]:F.colors.bg,opacity:h||q?.55:1}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.triggerRow,children:[Y?Y({size:16,color:F.colors.primary}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.triggerText,{color:F.colors.primary,fontSize:F.text.sm.size,...(0,_index2.fontFor)(F,"medium")}],children:0===k.length?z.trigger:z.addMore})]}),!e&&g?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.helperText,{color:F.colors["text-subtle"],fontSize:F.text.xs.size}],children:g}):null]}),Q=(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>W(),disabled:h||q,accessibilityRole:"button",accessibilityLabel:z.addMore,style:({pressed:e})=>[w.tile,w.addTile,{width:84,height:84,borderRadius:N,..._corners.smoothCorners,borderColor:P,backgroundColor:e?F.colors["surface-pressed"]:"transparent",opacity:h||q?.55:1}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.addTileText,{color:F.colors.primary}],children:"+"})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.container,S],testID:C,accessibilityLabel:K,children:["card"===u?0===k.length?m?m(J):dashedTrigger(!1):(0,_jsxRuntime.jsxs)(_reactNative.ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[w.strip,{columnGap:F.space.sm}],children:[k.map(renderOneFile),m?m(J):q||h?null:Q]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{rowGap:F.space.sm},children:[m?m(J):q?null:dashedTrigger(k.length>0),k.map(renderOneFile)]}),(0,_index4.hasFieldText)($)?(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityLiveRegion:"polite",style:[w.errorText,{color:F.colors["danger-text"],fontSize:F.text.xs.size,marginTop:F.space.xxs}],children:$}):null,(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:L,onClose:()=>A(!1),title:z.sheetTitle,options:o,labelOf:e=>e.label,getValue:e=>e.key,disabledOf:()=>!1,descriptionOf:e=>e.description,iconOf:e=>e.icon,isSelected:()=>!1,onSelect:e=>{A(!1),E(e)}})]})});FilePicker.displayName="FilePicker";const buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},trigger:{borderWidth:1,borderStyle:"dashed",alignItems:"center",minHeight:48,paddingVertical:e.space.md,paddingHorizontal:e.space.lg},triggerCompact:{minHeight:40,paddingVertical:e.space.sm},triggerRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},triggerText:{includeFontPadding:!1},helperText:{includeFontPadding:!1,marginTop:e.space.xs,textAlign:"center"},strip:{paddingVertical:e.space.xxs},tile:{borderWidth:1,overflow:"hidden"},addTile:{borderStyle:"dashed",alignItems:"center",justifyContent:"center"},addTileText:{fontSize:e.text["3xl"].size,includeFontPadding:!1},thumbnailImage:{width:"100%",height:"100%",resizeMode:"cover"},extensionTile:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"},extensionText:{fontSize:e.text.sm.size,letterSpacing:1,includeFontPadding:!1},tileOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},tileOverlayText:{fontSize:e.text.sm.size,includeFontPadding:!1,marginBottom:e.space.xs},tileProgressTrack:{position:"absolute",left:8,right:8,bottom:8,height:3,borderRadius:e.radius.pill,..._corners.smoothCorners,overflow:"hidden"},tileProgressFill:{height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners},doneBadge:{position:"absolute",right:4,bottom:4,width:18,height:18,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},doneBadgeText:{fontSize:e.text.xs.size,includeFontPadding:!1},removeButton:{position:"absolute",top:4,right:4,width:20,height:20,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},removeButtonText:{fontSize:e.text.sm.size,lineHeight:15,includeFontPadding:!1},retryText:{fontSize:e.text.xl.size,includeFontPadding:!1},listRow:{flexDirection:"row",alignItems:"center",borderWidth:1,padding:e.space.sm,columnGap:e.space.sm},listThumb:{width:40,height:40,overflow:"hidden"},listTextWrap:{flex:1},listName:{includeFontPadding:!1},listSubtitle:{includeFontPadding:!1,marginTop:e.space.xxs},listProgressTrack:{height:3,borderRadius:e.radius.pill,..._corners.smoothCorners,overflow:"hidden",marginTop:e.space.xs},listProgressFill:{height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners},listRemoveText:{fontSize:e.text["2xl"].size,includeFontPadding:!1,paddingHorizontal:e.space.xs},errorText:{includeFontPadding:!1}});var _default=exports.default=FilePicker;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.matchesAccept=exports.formatFileSize=exports.default=exports.FilePicker=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index4=require("../FieldBase/index.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index5=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");let fileIdSeq=0;const nextFileId=()=>"wfp-"+ ++fileIdSeq,DEFAULT_LABELS={trigger:"Attach file",addMore:"Add more",sheetTitle:"Add from",removeFile:e=>`Remove ${e}`,retry:"Retry upload",errorTooMany:e=>`You can attach up to ${e} files.`,errorTooLarge:(e,t)=>`${e} is larger than ${t} MB.`,errorWrongType:e=>`${e} is not an accepted file type.`},formatFileSize=e=>{if(void 0===e||e<=0)return"";const t=["B","KB","MB","GB"];let r=e,i=0;for(;r>=1024&&i<t.length-1;)r/=1024,i+=1;return`${r>=10||0===i?Math.round(r):Math.round(10*r)/10} ${t[i]}`};exports.formatFileSize=formatFileSize;const matchesAccept=(e,t)=>!t||0===t.length||!!e&&t.some(t=>"*/*"===t||"*"===t||(t.endsWith("/*")?e.startsWith(t.slice(0,t.length-1)):e===t));exports.matchesAccept=matchesAccept;const isImage=e=>!0===e.type?.startsWith("image/")||!e.type&&/\.(png|jpe?g|gif|webp|heic)$/i.test(e.name),imageSourceOf=e=>e.thumbnailUrl??(isImage(e)?e.uri??e.url:void 0),extensionOf=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"FILE":e.slice(t+1).toUpperCase().slice(0,4)},FilePicker=exports.FilePicker=(0,_react.forwardRef)((e,t)=>{const{files:r,defaultFiles:i,onChange:s,sources:o,maxFiles:n,maxSizeMB:l,accept:a,validate:c,process:d,variant:u="card",renderFile:x,renderTrigger:m,disabled:h=!1,helperText:g,error:p,labels:_,haptic:b,onPick:y,onRemove:f,onError:j,onFilePress:v,onRetry:R,style:S,accessibilityLabel:T,testID:C}=e,F=(0,_index2.useTheme)(),w=(0,_react.useMemo)(()=>buildStyles(F),[F]),z=(0,_react.useMemo)(()=>({...DEFAULT_LABELS,..._}),[_]),N=F.radius.md,P=F.colors.primary,[k,I]=(0,_index.useControllableState)({value:r,defaultValue:i??[],onChange:s}),O=(0,_react.useRef)(k);O.current=k;const V=(0,_react.useCallback)(e=>{O.current=e,I(e)},[I]),[M,B]=(0,_react.useState)(null),[L,A]=(0,_react.useState)(!1),$=p??M??void 0,q="number"==typeof n&&k.length>=n,H=(0,_react.useCallback)((e,t)=>{0!==e.length&&(B(e[0]),e.forEach(e=>{j?.(e,t)}),!1!==b&&(0,_index3.triggerHaptic)("notificationError"))},[j,b]),E=(0,_react.useCallback)(async e=>{let t;try{t=await e.pick()}catch(e){return void H([e instanceof Error?e.message:String(e)])}if(!t||0===t.length)return;const r=[];let i=t.map(e=>({id:nextFileId(),name:e.name??e.uri.split("/").pop()??"file",uri:e.uri,type:e.type,size:e.size,meta:e.meta,status:"idle"}));if("number"==typeof n){const e=Math.max(0,n-O.current.length);i.length>e&&(r.push(z.errorTooMany(n)),i=i.slice(0,e))}const s=[];for(const e of i){if("number"==typeof l&&"number"==typeof e.size&&e.size>1024*l*1024){r.push(z.errorTooLarge(e.name,l));continue}if(!matchesAccept(e.type,a)){r.push(z.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):s.push(e)}if(H(r),0===s.length)return;if(!d){V([...O.current,...s]),B(r.length>0?r[0]:null);const e=(0,_index3.resolveHaptic)(b,"selection");return e&&(0,_index3.triggerHaptic)(e),void y?.(s)}const o=s.map(e=>({...e,status:"processing"}));V([...O.current,...o]);const u=[];for(const e of o)try{const t=await d({...e,status:"idle"}),r={...t,id:e.id,status:t.status??"idle"};V(O.current.map(t=>t.id===e.id?r:t)),u.push(r)}catch(t){V(O.current.filter(t=>t.id!==e.id)),H([t instanceof Error?t.message:String(t)],e)}if(u.length>0){0===r.length&&B(null);const e=(0,_index3.resolveHaptic)(b,"selection");e&&(0,_index3.triggerHaptic)(e),y?.(u)}},[n,l,a,c,d,z,H,V,y,b]),W=(0,_react.useCallback)(e=>{if(h||q)return;const t=e?o.find(t=>t.key===e):1===o.length?o[0]:void 0;t?E(t):o.length>1&&A(!0)},[h,q,o,E]),D=(0,_react.useCallback)(e=>{if(h)return;V(O.current.filter(t=>t.id!==e.id)),B(null);const t=(0,_index3.resolveHaptic)(b,"selection");t&&(0,_index3.triggerHaptic)(t),f?.(e)},[h,V,f,b]),U=(0,_react.useCallback)(()=>{V([]),B(null)},[V]);(0,_react.useImperativeHandle)(t,()=>({open:W,clear:U}),[W,U]);const G=0===k.length?z.trigger:`${k.length} file${1===k.length?"":"s"} attached`,K=T??`Attachments. ${G}`,statusText=e=>{switch(e.status){case"processing":return"Processing…";case"uploading":return`Uploading ${Math.round(100*(e.progress??0))}%`;case"done":return"Uploaded";case"error":return e.error??"Failed";default:return""}},fileA11yLabel=e=>[e.name,formatFileSize(e.size),statusText(e)].filter(Boolean).join(", "),Y=F.settings.icons.attachment??_defaultIcons.defaultIcons.attachment,renderStatusOverlay=e=>{if("processing"===e.status)return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm"})});if("uploading"===e.status){const t=Math.round(100*(e.progress??0));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.tileOverlayText,{color:F.colors["on-scrim"]}],children:`${t}%`}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileProgressTrack,{backgroundColor:F.colors.border}],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileProgressFill,{width:`${t}%`,backgroundColor:F.colors.primary}]})})]})}return"done"===e.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.doneBadge,{backgroundColor:F.colors.success}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.doneBadgeText,{color:F.colors["on-success"]}],children:"✓"})}):null},renderThumbnail=e=>{const t=imageSourceOf(e);return t?(0,_jsxRuntime.jsx)(_reactNative.Image,{source:{uri:t},style:w.thumbnailImage}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.extensionTile,{backgroundColor:F.colors["bg-subtle"]}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.extensionText,{color:F.colors["text-muted"],...(0,_index2.fontFor)(F,"semibold")}],children:extensionOf(e.name)})})},removeButton=e=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>D(e),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.removeFile(e.name),style:[w.removeButton,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.removeButtonText,{color:F.colors["on-scrim"]}],children:"×"})}),retryButton=e=>R&&"error"===e.status?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>R(e),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.retry,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.retryText,{color:F.colors.primary}],children:"↻"})}):null,renderOneFile=(e,t)=>{const r={file:e,index:t,disabled:h,remove:()=>D(e),retry:R?()=>R(e):void 0},i=x?x(r):"card"===u?(e=>{const{file:t}=e;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.tile,{width:84,height:84,borderRadius:N,..._corners.smoothCorners,borderColor:"error"===t.status?F.colors.danger:F.colors.border}],children:[renderThumbnail(t),renderStatusOverlay(t),"error"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:retryButton(t)}):null,removeButton(t)]})})(r):(e=>{const{file:t}=e,r=statusText(t);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.listRow,{borderRadius:N,..._corners.smoothCorners,borderColor:"error"===t.status?F.colors.danger:F.colors.border,backgroundColor:F.colors.bg}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.listThumb,{borderRadius:F.radius.sm,..._corners.smoothCorners}],children:[renderThumbnail(t),"processing"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm"})}):null]}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.listTextWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,ellipsizeMode:"middle",style:[w.listName,{color:F.colors["text-body"],fontSize:F.text.sm.size,...(0,_index2.fontFor)(F,"medium")}],children:t.name}),(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,style:[w.listSubtitle,{color:"error"===t.status?F.colors["danger-text"]:F.colors["text-subtle"],fontSize:F.text.xs.size}],children:[formatFileSize(t.size),r].filter(Boolean).join(" · ")}),"uploading"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.listProgressTrack,{backgroundColor:F.colors.border}],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.listProgressFill,{width:`${Math.round(100*(t.progress??0))}%`,backgroundColor:F.colors.primary}]})}):null]}),retryButton(t),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>D(t),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.removeFile(t.name),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.listRemoveText,{color:F.colors["text-subtle"]}],children:"×"})})]})})(r);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:v?()=>v(e):void 0,disabled:h||!v,accessibilityLabel:fileA11yLabel(e),children:i},e.id)},J={open:W,disabled:h||q,fileCount:k.length,atCapacity:q},dashedTrigger=e=>(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>W(),disabled:h||q,accessibilityRole:"button",accessibilityLabel:K,accessibilityState:{disabled:h||q},"aria-disabled":h||q,style:({pressed:t})=>[w.trigger,e?w.triggerCompact:null,{borderRadius:N,..._corners.smoothCorners,borderColor:P,backgroundColor:t?F.colors["surface-pressed"]:F.colors.bg,opacity:h||q?.55:1}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.triggerRow,children:[Y?Y({size:16,color:F.colors.primary}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.triggerText,{color:F.colors.primary,fontSize:F.text.sm.size,...(0,_index2.fontFor)(F,"medium")}],children:0===k.length?z.trigger:z.addMore})]}),!e&&g?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.helperText,{color:F.colors["text-subtle"],fontSize:F.text.xs.size}],children:g}):null]}),Q=(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>W(),disabled:h||q,accessibilityRole:"button",accessibilityLabel:z.addMore,style:({pressed:e})=>[w.tile,w.addTile,{width:84,height:84,borderRadius:N,..._corners.smoothCorners,borderColor:P,backgroundColor:e?F.colors["surface-pressed"]:"transparent",opacity:h||q?.55:1}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.addTileText,{color:F.colors.primary}],children:"+"})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.container,S],testID:C,accessibilityLabel:K,children:["card"===u?0===k.length?m?m(J):dashedTrigger(!1):(0,_jsxRuntime.jsxs)(_reactNative.ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[w.strip,{columnGap:F.space.sm}],children:[k.map(renderOneFile),m?m(J):q||h?null:Q]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{rowGap:F.space.sm},children:[m?m(J):q?null:dashedTrigger(k.length>0),k.map(renderOneFile)]}),(0,_index4.hasFieldText)($)?(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityLiveRegion:"polite",style:[w.errorText,{color:F.colors["danger-text"],fontSize:F.text.xs.size,marginTop:F.space.xxs}],children:$}):null,(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:L,onClose:()=>A(!1),title:z.sheetTitle,options:o,labelOf:e=>e.label,getValue:e=>e.key,disabledOf:()=>!1,descriptionOf:e=>e.description,iconOf:e=>e.icon,isSelected:()=>!1,onSelect:e=>{A(!1),E(e)}})]})});FilePicker.displayName="FilePicker";const buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},trigger:{borderWidth:1,borderStyle:"dashed",alignItems:"center",minHeight:48,paddingVertical:e.space.md,paddingHorizontal:e.space.lg},triggerCompact:{minHeight:40,paddingVertical:e.space.sm},triggerRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},triggerText:{includeFontPadding:!1},helperText:{includeFontPadding:!1,marginTop:e.space.xs,textAlign:"center"},strip:{paddingVertical:e.space.xxs},tile:{borderWidth:1,overflow:"hidden"},addTile:{borderStyle:"dashed",alignItems:"center",justifyContent:"center"},addTileText:{fontSize:e.text["3xl"].size,includeFontPadding:!1},thumbnailImage:{width:"100%",height:"100%",resizeMode:"cover"},extensionTile:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"},extensionText:{fontSize:e.text.sm.size,letterSpacing:1,includeFontPadding:!1},tileOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},tileOverlayText:{fontSize:e.text.sm.size,includeFontPadding:!1,marginBottom:e.space.xs},tileProgressTrack:{position:"absolute",left:8,right:8,bottom:8,height:3,borderRadius:e.radius.pill,..._corners.smoothCorners,overflow:"hidden"},tileProgressFill:{height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners},doneBadge:{position:"absolute",right:4,bottom:4,width:18,height:18,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},doneBadgeText:{fontSize:e.text.xs.size,includeFontPadding:!1},removeButton:{position:"absolute",top:4,right:4,width:20,height:20,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},removeButtonText:{fontSize:e.text.sm.size,lineHeight:15,includeFontPadding:!1},retryText:{fontSize:e.text.xl.size,includeFontPadding:!1},listRow:{flexDirection:"row",alignItems:"center",borderWidth:1,padding:e.space.sm,columnGap:e.space.sm},listThumb:{width:40,height:40,overflow:"hidden"},listTextWrap:{flex:1},listName:{includeFontPadding:!1},listSubtitle:{includeFontPadding:!1,marginTop:e.space.xxs},listProgressTrack:{height:3,borderRadius:e.radius.pill,..._corners.smoothCorners,overflow:"hidden",marginTop:e.space.xs},listProgressFill:{height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners},listRemoveText:{fontSize:e.text["2xl"].size,includeFontPadding:!1,paddingHorizontal:e.space.xs},errorText:{includeFontPadding:!1}});var _default=exports.default=FilePicker;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_MESSAGE_LIST_LABELS=void 0,exports.MessageList=MessageList,exports.default=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useReducedMotion=require("../../hooks/useReducedMotion.js"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_corners=require("../../utils/corners.js"),_index2=require("../Badge/index.js"),_index3=require("../DateSeparator/index.js"),_index4=require("../IconButton/index.js"),_index5=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_MESSAGE_LIST_LABELS=exports.DEFAULT_MESSAGE_LIST_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday",jumpToLatest:"Jump to the latest message",newMessages:e=>1===e?"1 new message":`${e} new messages`,unread:"New messages",loadingOlder:"Loading earlier messages"}),JUMP_AT=160,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:JUMP_AT},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";function MessageList({messages:e,keyExtractor:t,renderMessage:n,getAuthorKey:s,getDate:r,firstUnreadKey:a,onLoadOlder:o,loadingOlder:i=!1,hasOlder:l=!0,typing:u,empty:c,getAnnouncement:d,followNew:_,keyboardAware:m=!0,keyboardOffset:x,labels:p,now:j,onScroll:f,contentContainerStyle:g,style:y,testID:b,...S}){const v=(0,_index.useTheme)(),L=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),h=(0,_useReducedMotion.useReducedMotion)(),E=(0,_react.useMemo)(()=>buildStyles(v),[v]),R=(0,_react.useMemo)(()=>({...DEFAULT_MESSAGE_LIST_LABELS,...p}),[p]),w=x??L.bottom,T=(0,_react.useRef)(null),A=(0,_react.useRef)(!1),[C,M]=(0,_react.useState)(!1),[I,N]=(0,_react.useState)(0),O=(0,_react.useMemo)(()=>{const n=r?e.map(e=>(0,_mobileCore.formatDate)(r(e))):null,o=s?e.map(s):null,i=void 0===a?-1:e.findIndex(e=>t(e)===a);return e.map((t,s)=>{const a=s===e.length-1,l=null!==n&&(a||n[s]!==n[s+1]),u=null!==o&&!a&&o[s+1]===o[s]&&!l&&s!==i,c=null!==o&&s>0&&o[s-1]===o[s]&&(null===n||n[s-1]===n[s])&&s-1!==i;return{groupPosition:positionOf(u,c),day:l&&r?(0,_index3.dayLabel)(r(t),{now:j,labels:R}):null,unread:s===i}})},[e,r,s,a,t,j,R]),k=(0,_react.useCallback)(()=>{T.current?.scrollToOffset({offset:0,animated:!h}),N(0)},[h]),q=e.length>0?t(e[0]):null,D=(0,_react.useRef)(q);(0,_react.useEffect)(()=>{const n=D.current;if(D.current=q,null===n||null===q||n===q)return;const s=e.findIndex(e=>t(e)===n);if(-1===s)return void N(0);const r=e.slice(0,s).reverse();for(const e of r){const t=d?.(e);t&&(0,_announce.announce)(t)}_&&r.some(_)?k():A.current&&N(e=>e+r.length)},[q]);const P=(0,_react.useCallback)(e=>{const t=e.nativeEvent.contentOffset.y>JUMP_AT;t!==A.current&&(A.current=t,M(t),t||N(0)),f?.(e)},[f]),F=(0,_react.useCallback)(()=>{l&&!i&&o?.()},[l,i,o]),V=(0,_react.useCallback)(({item:e,index:t})=>{const s=O[t];return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[s?.day?(0,_jsxRuntime.jsx)(_index3.DateSeparator,{label:s.day}):null,s?.unread?(0,_jsxRuntime.jsx)(_index3.DateSeparator,{label:R.unread,emphasis:!0}):null,n({item:e,index:t,groupPosition:s?.groupPosition??"single"})]})},[O,R.unread,n]),B=(0,_react.useCallback)(e=>t(e),[t]),U=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNativeKeyboardController.KeyboardChatScrollView,{...e,inverted:!0,offset:w}),[w]),K=I>0?`${R.newMessages(I)}. ${R.jumpToLatest}`:R.jumpToLatest;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[E.root,y],children:[(0,_jsxRuntime.jsx)(_reactNative.FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...S,ref:T,data:e,renderItem:V,keyExtractor:B,inverted:!0,onScroll:P,onEndReached:o?F:void 0,ListHeaderComponent:u?(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:u}):null,ListFooterComponent:i?(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm",accessibilityLabel:R.loadingOlder,style:E.older}):null,ListEmptyComponent:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.fill,children:c}):null,renderScrollComponent:m?U:void 0,contentContainerStyle:[E.content,0===e.length?E.grow:null,g],testID:b}),C?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:E.jump,pointerEvents:"box-none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.jumpDisc,children:(0,_jsxRuntime.jsx)(_index4.IconButton,{icon:"arrow-down",accessibilityLabel:K,variant:"ghost",tone:"neutral",onPress:k,testID:b?`${b}-jump`:void 0})}),I>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.count,pointerEvents:"none",importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,children:(0,_jsxRuntime.jsx)(_index2.Badge,{value:I,max:99,tone:"primary",size:"sm"})}):null]}):null]})}const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},content:{paddingHorizontal:e.space.md,paddingVertical:e.space.sm},grow:{flexGrow:1},fill:{flex:1},older:{paddingVertical:e.space.md},jump:{position:"absolute",right:e.space.md,bottom:e.space.md},jumpDisc:{borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:e.colors.surface,...e.shadow.elevated},count:{position:"absolute",top:-e.space.xs,right:-e.space.xs}});var _default=exports.default=MessageList;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_MESSAGE_LIST_LABELS=void 0,exports.MessageList=MessageList,exports.default=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useReducedMotion=require("../../hooks/useReducedMotion.js"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_corners=require("../../utils/corners.js"),_index2=require("../Badge/index.js"),_index3=require("../DateSeparator/index.js"),_index4=require("../IconButton/index.js"),_index5=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_MESSAGE_LIST_LABELS=exports.DEFAULT_MESSAGE_LIST_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday",jumpToLatest:"Jump to the latest message",newMessages:e=>1===e?"1 new message":`${e} new messages`,unread:"New messages",loadingOlder:"Loading earlier messages"}),JUMP_AT=160,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:JUMP_AT},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";function MessageList({messages:e,keyExtractor:t,renderMessage:n,getAuthorKey:r,getDate:s,firstUnreadKey:a,onLoadOlder:o,loadingOlder:i=!1,hasOlder:l=!0,typing:u,empty:c,getAnnouncement:d,followNew:_,keyboardAware:m=!0,keyboardOffset:x,labels:p,now:j,onScroll:f,contentContainerStyle:y,style:g,testID:b,...S}){const v=(0,_index.useTheme)(),L=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),h=(0,_useReducedMotion.useReducedMotion)(),E=(0,_react.useMemo)(()=>buildStyles(v),[v]),R=(0,_react.useMemo)(()=>({...DEFAULT_MESSAGE_LIST_LABELS,...p}),[p]),w=x??L.bottom,T=(0,_react.useRef)(null),A=(0,_react.useRef)(!1),[C,M]=(0,_react.useState)(!1),[I,N]=(0,_react.useState)(0),O=(0,_react.useMemo)(()=>{const n=s?e.map(e=>(0,_mobileCore.formatDate)(s(e))):null,o=r?e.map(r):null,i=void 0===a?-1:e.findIndex(e=>t(e)===a);return e.map((t,r)=>{const a=r===e.length-1,l=null!==n&&(a||n[r]!==n[r+1]),u=null!==o&&!a&&o[r+1]===o[r]&&!l&&r!==i,c=null!==o&&r>0&&o[r-1]===o[r]&&(null===n||n[r-1]===n[r])&&r-1!==i;return{groupPosition:positionOf(u,c),day:l&&s?(0,_index3.dayLabel)(s(t),{now:j,labels:R}):null,unread:r===i}})},[e,s,r,a,t,j,R]),k=(0,_react.useCallback)(()=>{T.current?.scrollToOffset({offset:0,animated:!h}),N(0)},[h]),q=e.length>0?t(e[0]):null,D=(0,_react.useRef)(q);(0,_react.useEffect)(()=>{const n=D.current;if(D.current=q,null===n||null===q||n===q)return;const r=e.findIndex(e=>t(e)===n);if(-1===r)return void N(0);const s=e.slice(0,r).reverse();for(const e of s){const t=d?.(e);t&&(0,_announce.announce)(t)}_&&s.some(_)?k():A.current&&N(e=>e+s.length)},[q]);const P=(0,_react.useCallback)(e=>{const t=e.nativeEvent.contentOffset.y>JUMP_AT;t!==A.current&&(A.current=t,M(t),t||N(0)),f?.(e)},[f]),V=(0,_react.useCallback)(()=>{l&&!i&&o?.()},[l,i,o]),F=(0,_react.useCallback)(({item:e,index:t})=>{const r=O[t];return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[r?.day?(0,_jsxRuntime.jsx)(_index3.DateSeparator,{label:r.day}):null,r?.unread?(0,_jsxRuntime.jsx)(_index3.DateSeparator,{label:R.unread,emphasis:!0}):null,n({item:e,index:t,groupPosition:r?.groupPosition??"single"})]})},[O,R.unread,n]),B=(0,_react.useCallback)(e=>t(e),[t]),U=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNativeKeyboardController.KeyboardChatScrollView,{...e,inverted:!0,offset:w}),[w]),K=I>0?`${R.newMessages(I)}. ${R.jumpToLatest}`:R.jumpToLatest;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[E.root,g],children:[(0,_jsxRuntime.jsx)(_reactNative.FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...S,ref:T,data:e,renderItem:F,keyExtractor:B,inverted:!0,onScroll:P,onEndReached:o?V:void 0,ListHeaderComponent:u?(0,_jsxRuntime.jsx)(_reactNative.View,{children:u}):null,ListFooterComponent:i?(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm",accessibilityLabel:R.loadingOlder,style:E.older}):null,ListEmptyComponent:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.fill,children:c}):null,renderScrollComponent:m?U:void 0,contentContainerStyle:[E.content,0===e.length?E.grow:null,y],testID:b}),C?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:E.jump,pointerEvents:"box-none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.jumpDisc,children:(0,_jsxRuntime.jsx)(_index4.IconButton,{icon:"arrow-down",accessibilityLabel:K,variant:"ghost",tone:"neutral",onPress:k,testID:b?`${b}-jump`:void 0})}),I>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.count,pointerEvents:"none",importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,children:(0,_jsxRuntime.jsx)(_index2.Badge,{value:I,max:99,tone:"primary",size:"sm"})}):null]}):null]})}const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},content:{paddingHorizontal:e.space.md,paddingVertical:e.space.sm},grow:{flexGrow:1},fill:{flex:1},older:{paddingVertical:e.space.md},jump:{position:"absolute",right:e.space.md,bottom:e.space.md},jumpDisc:{borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:e.colors.surface,...e.shadow.elevated},count:{position:"absolute",top:-e.space.xs,right:-e.space.xs}});var _default=exports.default=MessageList;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Modal=exports.MODAL_DISMISS_GRACE_MS=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_squircle=require("../../utils/squircle.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const MODAL_DISMISS_GRACE_MS=exports.MODAL_DISMISS_GRACE_MS=300,SCALE_START_VALUE=.9,Modal=exports.Modal=(0,_react.forwardRef)((e,t)=>{const{visible:r,onRequestClose:a,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:o,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:_,restoreFocusRef:f,onDismissed:p,haptic:v,testID:g}=e,b=(0,_index.useTheme)(),S=(0,_usePresenceMotion.usePresenceMotion)(),[h,x]=(0,_ModalSafeArea.useModalInsets)(),A=o??S.duration("default"),M=_reactNative.Dimensions.get("window").height,N=(0,_react.useRef)(!l&&r),R=N.current,y=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:.9)).current,j=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:0)).current,q=(0,_react.useRef)((0,_index.createAnimatedValue)(R?0:M)).current,C=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:0)).current,V=(0,_react.useRef)(null),D=(0,_react.useRef)(!1),[T,w]=(0,_react.useState)(r),I=(0,_react.useMemo)(()=>buildStyles(b),[b]),E=(0,_react.useMemo)(()=>{const e=b.colors.scrim;return"number"!=typeof s?e:(0,_color.withAlpha)(e,s)??e},[b.colors.scrim,s]),P=(0,_react.useMemo)(()=>C.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(E),E]}),[C,E]);(0,_react.useEffect)(()=>{r&&w(!0)},[r]),(0,_react.useEffect)(()=>{const e=[];if(r&&T&&N.current)N.current=!1;else if(r&&T){const t=_reactNative.Animated.timing(C,{toValue:1,duration:S.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),S.reduced){j.setValue(0),q.setValue(0),y.setValue(1);const t=_reactNative.Animated.timing(j,{toValue:1,duration:A,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===i){j.setValue(1);const t=_reactNative.Animated.spring(q,{toValue:0,damping:b.motion.spring.gentle.damping,stiffness:b.motion.spring.gentle.stiffness,mass:b.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=_reactNative.Animated.parallel([_reactNative.Animated.spring(y,{toValue:1,damping:b.motion.spring.gentle.damping,stiffness:b.motion.spring.gentle.stiffness,mass:b.motion.spring.gentle.mass,useNativeDriver:!0}),_reactNative.Animated.timing(j,{toValue:1,duration:A,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(T){const t=S.duration("fast"),r=_reactNative.Easing.bezier(...b.motion.ease.accelerate),a=_reactNative.Animated.timing(j,{toValue:0,duration:t,easing:r,useNativeDriver:!0}),s=S.reduced?a:"bottom"===i?_reactNative.Animated.timing(q,{toValue:M,duration:t,easing:r,useNativeDriver:!0}):_reactNative.Animated.parallel([_reactNative.Animated.timing(y,{toValue:.9,duration:t,easing:r,useNativeDriver:!0}),a]),n=_reactNative.Animated.parallel([s,_reactNative.Animated.timing(C,{toValue:0,duration:S.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(q.setValue(M),w(!1))}),e.push(n)}return()=>e.forEach(e=>e.stop())},[r,T,i,A,y,j,C,q,M,b.motion.spring.gentle.damping,b.motion.spring.gentle.stiffness,b.motion.spring.gentle.mass,S,b.motion.ease.accelerate]),(0,_react.useEffect)(()=>{if("web"===_reactNative.Platform.OS)return;let e,t;return r?(e=setTimeout(()=>{V.current&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(V.current,"focus")},150),D.current=!0):D.current&&(D.current=!1,f&&f.current&&(t=setTimeout(()=>{const e=f.current;e&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(e,"focus")},A))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[r,A,f]);const L=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{if(r)return void(L.current=!0);if(!L.current)return;if(L.current=!1,!p)return;const e=setTimeout(p,MODAL_DISMISS_GRACE_MS);return()=>clearTimeout(e)},[r,p]);const k=(0,_react.useCallback)(()=>{if(!n)return;const e=(0,_hapticUtils.resolveHaptic)(v,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),a()},[n,a,v]),z=(0,_react.useCallback)(()=>{u&&a()},[u,a]),F=(0,_SquircleFill.useSquircle)("bottom"!==i&&"fullScreen"!==i,b.radius.xl),O=(0,_react.useMemo)(()=>"fullScreen"===i?[I.fullScreenContent,{backgroundColor:b.colors.surface}]:"bottom"===i?[I.bottomContent,{backgroundColor:b.colors.surface,borderTopLeftRadius:b.radius.xl,borderTopRightRadius:b.radius.xl,..._corners.smoothCorners,paddingTop:b.space.lg,paddingHorizontal:b.space.lg,paddingBottom:b.space.lg+h.bottom},b.shadow.modal]:[I.centeredContent,{backgroundColor:b.colors.surface,borderRadius:F.active&&F.size?(0,_squircle.squircleHostRadius)(F.size.width,F.size.height,b.radius.xl):b.radius.xl,..._corners.smoothCorners,padding:b.space.xl},b.shadow.modal],[i,b,I,h.bottom,F.active,F.size]),W=(0,_react.useMemo)(()=>"bottom"===i?I.bottomWrapper:"fullScreen"===i?I.fullScreenWrapper:I.centeredWrapper,[i,I]),H=(0,_react.useMemo)(()=>"bottom"===i?{opacity:j,transform:[{translateY:q}]}:"fullScreen"===i?{opacity:j}:{opacity:j,transform:[{scale:y}]},[i,y,j,q]);return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:T,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:z,testID:g,children:(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{V.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:I.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:(0,_jsxRuntime.jsxs)(_ModalSafeArea.ModalSafeArea,{onInsets:x,children:[(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{collapsable:!1,style:[_reactNative.StyleSheet.absoluteFill,W,{backgroundColor:P},_],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:k,accessibilityRole:"button",accessibilityLabel:"Close modal",disabled:!n}),(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[O,H,m],onLayout:F.onLayout,pointerEvents:"auto",children:[F.active&&F.size?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:F.size.width,height:F.size.height,radius:b.radius.xl,fill:b.colors.surface}):null,d]})]}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1}});var _default=exports.default=Modal;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Modal=exports.MODAL_DISMISS_GRACE_MS=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_squircle=require("../../utils/squircle.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const MODAL_DISMISS_GRACE_MS=exports.MODAL_DISMISS_GRACE_MS=300,SCALE_START_VALUE=.9,Modal=exports.Modal=(0,_react.forwardRef)((e,t)=>{const{visible:r,onRequestClose:a,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:o,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:_,restoreFocusRef:f,onDismissed:p,haptic:v,testID:g}=e,b=(0,_index.useTheme)(),S=(0,_usePresenceMotion.usePresenceMotion)(),[h,x]=(0,_ModalSafeArea.useModalInsets)(),A=o??S.duration("default"),M=_reactNative.Dimensions.get("window").height,N=(0,_react.useRef)(!l&&r),R=N.current,y=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:.9)).current,j=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:0)).current,q=(0,_react.useRef)((0,_index.createAnimatedValue)(R?0:M)).current,C=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:0)).current,V=(0,_react.useRef)(null),D=(0,_react.useRef)(!1),[T,w]=(0,_react.useState)(r),I=(0,_react.useMemo)(()=>buildStyles(b),[b]),E=(0,_react.useMemo)(()=>{const e=b.colors.scrim;return"number"!=typeof s?e:(0,_color.withAlpha)(e,s)??e},[b.colors.scrim,s]),P=(0,_react.useMemo)(()=>C.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(E),E]}),[C,E]);(0,_react.useEffect)(()=>{r&&w(!0)},[r]),(0,_react.useEffect)(()=>{const e=[];if(r&&T&&N.current)N.current=!1;else if(r&&T){const t=_reactNative.Animated.timing(C,{toValue:1,duration:S.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),S.reduced){j.setValue(0),q.setValue(0),y.setValue(1);const t=_reactNative.Animated.timing(j,{toValue:1,duration:A,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===i){j.setValue(1);const t=_reactNative.Animated.spring(q,{toValue:0,damping:b.motion.spring.gentle.damping,stiffness:b.motion.spring.gentle.stiffness,mass:b.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=_reactNative.Animated.parallel([_reactNative.Animated.spring(y,{toValue:1,damping:b.motion.spring.gentle.damping,stiffness:b.motion.spring.gentle.stiffness,mass:b.motion.spring.gentle.mass,useNativeDriver:!0}),_reactNative.Animated.timing(j,{toValue:1,duration:A,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(T){const t=S.duration("fast"),r=_reactNative.Easing.bezier(...b.motion.ease.accelerate),a=_reactNative.Animated.timing(j,{toValue:0,duration:t,easing:r,useNativeDriver:!0}),s=S.reduced?a:"bottom"===i?_reactNative.Animated.timing(q,{toValue:M,duration:t,easing:r,useNativeDriver:!0}):_reactNative.Animated.parallel([_reactNative.Animated.timing(y,{toValue:.9,duration:t,easing:r,useNativeDriver:!0}),a]),n=_reactNative.Animated.parallel([s,_reactNative.Animated.timing(C,{toValue:0,duration:S.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(q.setValue(M),w(!1))}),e.push(n)}return()=>e.forEach(e=>{e.stop()})},[r,T,i,A,y,j,C,q,M,b.motion.spring.gentle.damping,b.motion.spring.gentle.stiffness,b.motion.spring.gentle.mass,S,b.motion.ease.accelerate]),(0,_react.useEffect)(()=>{if("web"===_reactNative.Platform.OS)return;let e,t;return r?(e=setTimeout(()=>{V.current&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(V.current,"focus")},150),D.current=!0):D.current&&(D.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(e,"focus")},A))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[r,A,f]);const L=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{if(r)return void(L.current=!0);if(!L.current)return;if(L.current=!1,!p)return;const e=setTimeout(p,MODAL_DISMISS_GRACE_MS);return()=>clearTimeout(e)},[r,p]);const k=(0,_react.useCallback)(()=>{if(!n)return;const e=(0,_hapticUtils.resolveHaptic)(v,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),a()},[n,a,v]),z=(0,_react.useCallback)(()=>{u&&a()},[u,a]),F=(0,_SquircleFill.useSquircle)("bottom"!==i&&"fullScreen"!==i,b.radius.xl),O=(0,_react.useMemo)(()=>"fullScreen"===i?[I.fullScreenContent,{backgroundColor:b.colors.surface}]:"bottom"===i?[I.bottomContent,{backgroundColor:b.colors.surface,borderTopLeftRadius:b.radius.xl,borderTopRightRadius:b.radius.xl,..._corners.smoothCorners,paddingTop:b.space.lg,paddingHorizontal:b.space.lg,paddingBottom:b.space.lg+h.bottom},b.shadow.modal]:[I.centeredContent,{backgroundColor:b.colors.surface,borderRadius:F.active&&F.size?(0,_squircle.squircleHostRadius)(F.size.width,F.size.height,b.radius.xl):b.radius.xl,..._corners.smoothCorners,padding:b.space.xl},b.shadow.modal],[i,b,I,h.bottom,F.active,F.size]),W=(0,_react.useMemo)(()=>"bottom"===i?I.bottomWrapper:"fullScreen"===i?I.fullScreenWrapper:I.centeredWrapper,[i,I]),H=(0,_react.useMemo)(()=>"bottom"===i?{opacity:j,transform:[{translateY:q}]}:"fullScreen"===i?{opacity:j}:{opacity:j,transform:[{scale:y}]},[i,y,j,q]);return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:T,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:z,testID:g,children:(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{V.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:I.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:(0,_jsxRuntime.jsxs)(_ModalSafeArea.ModalSafeArea,{onInsets:x,children:[(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{collapsable:!1,style:[_reactNative.StyleSheet.absoluteFill,W,{backgroundColor:P},_],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:k,accessibilityRole:"button",accessibilityLabel:"Close modal",disabled:!n}),(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[O,H,m],onLayout:F.onLayout,pointerEvents:"auto",children:[F.active&&F.size?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:F.size.width,height:F.size.height,radius:b.radius.xl,fill:b.colors.surface}):null,d]})]}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1}});var _default=exports.default=Modal;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.OTPInput=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_jsxRuntime=require("react/jsx-runtime");const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=exports.OTPInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:n,onComplete:a,length:s=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:c=0,disabled:u=!1,error:d,size:_="md",secure:m=!1,haptic:p,onFocus:g,accessibilityLabel:x,style:f,cellStyle:h,textStyle:v,testID:b}=e,[y,j]=(0,_index.useControllableState)({value:i,defaultValue:r??"",onChange:n}),N=(0,_index2.useTheme)(),R=(0,_react.useMemo)(()=>buildStyles(N),[N]),C=(0,_index2.resolveOtpInputSize)(N,_),T=(0,_react.useRef)([]),[F,k]=(0,_react.useState)(-1),V=(0,_react.useRef)(null),w=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,E=(0,_react.useRef)(new Map),A=(0,_react.useMemo)(()=>{const e=E.current,t=[];for(let i=0;i<s;i+=1){let r=e.get(i);r||(r=new _reactNative.Animated.Value(0),e.set(i,r)),t.push(r)}for(const t of Array.from(e.keys()))t>=s&&e.delete(t);return t},[s]),I=(0,_react.useRef)(-1),S=N.settings.components["otp-input"]?.shakeOnError??!1,O=(0,_index.useReducedMotion)(),z=!0===d||(0,_FieldBase.hasFieldText)(d);(0,_react.useEffect)(()=>{let e;return null===V.current||!z||V.current||(p&&(0,_index3.triggerHaptic)("notificationError"),S&&!O&&((0,_index2.setNativeValue)(w,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(w,{toValue:1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:-1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:0,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0})]),e.start())),V.current=z,()=>e?.stop()},[z,w,S,p,O,N.motion.duration.instant]),(0,_react.useEffect)(()=>{const e=I.current;if(I.current=F,e===F)return;if(-1===e&&-1===F)return;const t=[];return A.forEach((i,r)=>{const n=r===F?1:0;if(r!==F&&r!==e)return;const a=_reactNative.Animated.timing(i,{toValue:n,duration:N.motion.duration.fast,easing:_reactNative.Easing.bezier(...N.motion.ease["in-out"]),useNativeDriver:!0});a.start(),t.push(a)}),()=>t.forEach(e=>e.stop())},[F,A,N]);const B=(0,_react.useCallback)(e=>{const t=T.current[e];t&&t.focus()},[]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>B(0),blur:()=>{const e=T.current[F>=0?F:0];e?.blur()},clear:()=>{j(""),B(0)}}),[B,F,j]),(0,_react.useEffect)(()=>{if(l&&!u){const e=setTimeout(()=>B(0),c);return()=>clearTimeout(e)}},[l,c,u,B]);const D=(0,_react.useMemo)(()=>{const e=new Array(s).fill("");for(let t=0;t<Math.min(y.length,s);t+=1)e[t]=y[t]??"";return e},[y,s]),P=(0,_react.useCallback)(e=>{const t=e.slice(0,s);t!==y&&(j(t),t.length===s&&a&&a(t))},[s,j,a,y]),q=(0,_react.useCallback)((e,t)=>{const i=t.replace(/\u200B/g,""),r=sanitizeChar(i,o);if(!r){const t=D.slice(),i=(t[e]??"").length>0;if(t[e]="",P(t.join("").slice(0,s)),!i&&e>0){const t=D.slice();t[e-1]="",P(t.join("")),B(e-1)}return}const n=D[e]??"",a=n&&r.length>s&&r.startsWith(n)?r.slice(n.length):r;if(a.length>=s){const t=a.slice(0,s),i=y.length;return P(t),t.length!==i&&p&&(0,_index3.triggerHaptic)(p),void T.current[e]?.blur()}const l=D.slice();let c=e;for(let e=0;e<r.length&&c<s;e+=1)l[c]=r[e]??"",c+=1;const u=l.join("").slice(0,s),d=y.length;P(u),u.length!==d&&p&&(0,_index3.triggerHaptic)(p);const _=Math.min(c,s-1);c>=s?T.current[e]?.blur():B(_)},[D,B,o,s,p,P,y]),M=(0,_react.useCallback)((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(D[e]??"").length){if(e>0){const t=D.slice();t[e-1]="",P(t.join("")),B(e-1)}}else{const t=D.slice();t[e]="",P(t.join(""))}},[D,B,P]),H=(0,_react.useCallback)((e,t)=>{k(e),g?.(t)},[g]),W=(0,_react.useCallback)(()=>{k(-1)},[]),L=(0,_react.useCallback)(()=>{if(u)return;const e=D.indexOf("");B(-1===e?s-1:e)},[D,u,B,s]),$=x??`Enter ${s}-digit code`,G=w.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:f,accessible:!0,accessibilityRole:"none",accessibilityLabel:$,accessibilityValue:{text:i},accessibilityState:{disabled:u},"aria-disabled":u,testID:b,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:L,disabled:u,accessible:!1,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[R.row,{columnGap:C.gap,transform:[{translateX:G}]}],children:D.map((e,t)=>{const i=F===t,r=e.length>0,n=z?N.colors["danger-border"]:N.colors["focus-ring"],a=A[t];if(!a)return null;const l=m&&r?"●":e;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:R.cellWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{size:_,width:C.cell,height:C.cell,borderRadius:C.radius,borderWidth:1.5,focused:i,error:z,filled:r,disabled:u,paddingHorizontal:N.space.none,paddingVertical:N.space.none,gap:N.space.none,style:h,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:e=>{T.current[t]=e},value:(m&&r?"":e)||"​",onChangeText:e=>q(t,e),onKeyPress:e=>M(t,e),onFocus:e=>H(t,e),onBlur:W,keyboardType:o,editable:!u,selectTextOnFocus:!0,caretHidden:r,maxLength:s+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[R.input,{fontSize:C.text,color:N.colors["text-body"],...(0,_index2.fontFor)(N,"semibold")},v]}),m&&r?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:R.maskOverlay,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[{fontSize:C.text,color:N.colors["text-body"],...(0,_index2.fontFor)(N,"semibold")},v],children:l})}):null]}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[R.underline,{backgroundColor:n,opacity:a}]})]},`otp-cell-${t}`)})})}),(0,_jsxRuntime.jsx)(_FieldBase.FieldMessage,{size:_,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,..._corners.smoothCorners}});var _default=exports.default=OTPInput;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.OTPInput=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_jsxRuntime=require("react/jsx-runtime");const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=exports.OTPInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:n,onComplete:a,length:s=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:c=0,disabled:u=!1,error:d,size:_="md",secure:m=!1,haptic:p,onFocus:g,accessibilityLabel:x,style:f,cellStyle:h,textStyle:v,testID:b}=e,[y,j]=(0,_index.useControllableState)({value:i,defaultValue:r??"",onChange:n}),N=(0,_index2.useTheme)(),R=(0,_react.useMemo)(()=>buildStyles(N),[N]),C=(0,_index2.resolveOtpInputSize)(N,_),T=(0,_react.useRef)([]),[F,k]=(0,_react.useState)(-1),V=(0,_react.useRef)(null),w=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,E=(0,_react.useRef)(new Map),A=(0,_react.useMemo)(()=>{const e=E.current,t=[];for(let i=0;i<s;i+=1){let r=e.get(i);r||(r=new _reactNative.Animated.Value(0),e.set(i,r)),t.push(r)}for(const t of Array.from(e.keys()))t>=s&&e.delete(t);return t},[s]),I=(0,_react.useRef)(-1),S=N.settings.components["otp-input"]?.shakeOnError??!1,O=(0,_index.useReducedMotion)(),z=!0===d||(0,_FieldBase.hasFieldText)(d);(0,_react.useEffect)(()=>{let e;return null===V.current||!z||V.current||(p&&(0,_index3.triggerHaptic)("notificationError"),S&&!O&&((0,_index2.setNativeValue)(w,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(w,{toValue:1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:-1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:0,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0})]),e.start())),V.current=z,()=>e?.stop()},[z,w,S,p,O,N.motion.duration.instant]),(0,_react.useEffect)(()=>{const e=I.current;if(I.current=F,e===F)return;if(-1===e&&-1===F)return;const t=[];return A.forEach((i,r)=>{const n=r===F?1:0;if(r!==F&&r!==e)return;const a=_reactNative.Animated.timing(i,{toValue:n,duration:N.motion.duration.fast,easing:_reactNative.Easing.bezier(...N.motion.ease["in-out"]),useNativeDriver:!0});a.start(),t.push(a)}),()=>t.forEach(e=>{e.stop()})},[F,A,N]);const B=(0,_react.useCallback)(e=>{const t=T.current[e];t&&t.focus()},[]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>B(0),blur:()=>{const e=T.current[F>=0?F:0];e?.blur()},clear:()=>{j(""),B(0)}}),[B,F,j]),(0,_react.useEffect)(()=>{if(l&&!u){const e=setTimeout(()=>B(0),c);return()=>clearTimeout(e)}},[l,c,u,B]);const D=(0,_react.useMemo)(()=>{const e=new Array(s).fill("");for(let t=0;t<Math.min(y.length,s);t+=1)e[t]=y[t]??"";return e},[y,s]),P=(0,_react.useCallback)(e=>{const t=e.slice(0,s);t!==y&&(j(t),t.length===s&&a&&a(t))},[s,j,a,y]),q=(0,_react.useCallback)((e,t)=>{const i=t.replace(/\u200B/g,""),r=sanitizeChar(i,o);if(!r){const t=D.slice(),i=(t[e]??"").length>0;if(t[e]="",P(t.join("").slice(0,s)),!i&&e>0){const t=D.slice();t[e-1]="",P(t.join("")),B(e-1)}return}const n=D[e]??"",a=n&&r.length>s&&r.startsWith(n)?r.slice(n.length):r;if(a.length>=s){const t=a.slice(0,s),i=y.length;return P(t),t.length!==i&&p&&(0,_index3.triggerHaptic)(p),void T.current[e]?.blur()}const l=D.slice();let c=e;for(let e=0;e<r.length&&c<s;e+=1)l[c]=r[e]??"",c+=1;const u=l.join("").slice(0,s),d=y.length;P(u),u.length!==d&&p&&(0,_index3.triggerHaptic)(p);const _=Math.min(c,s-1);c>=s?T.current[e]?.blur():B(_)},[D,B,o,s,p,P,y]),M=(0,_react.useCallback)((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(D[e]??"").length){if(e>0){const t=D.slice();t[e-1]="",P(t.join("")),B(e-1)}}else{const t=D.slice();t[e]="",P(t.join(""))}},[D,B,P]),H=(0,_react.useCallback)((e,t)=>{k(e),g?.(t)},[g]),W=(0,_react.useCallback)(()=>{k(-1)},[]),L=(0,_react.useCallback)(()=>{if(u)return;const e=D.indexOf("");B(-1===e?s-1:e)},[D,u,B,s]),$=x??`Enter ${s}-digit code`,G=w.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:f,accessible:!0,accessibilityRole:"none",accessibilityLabel:$,accessibilityValue:{text:i},accessibilityState:{disabled:u},"aria-disabled":u,testID:b,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:L,disabled:u,accessible:!1,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[R.row,{columnGap:C.gap,transform:[{translateX:G}]}],children:D.map((e,t)=>{const i=F===t,r=e.length>0,n=z?N.colors["danger-border"]:N.colors["focus-ring"],a=A[t];if(!a)return null;const l=m&&r?"●":e;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:R.cellWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{size:_,width:C.cell,height:C.cell,borderRadius:C.radius,borderWidth:1.5,focused:i,error:z,filled:r,disabled:u,paddingHorizontal:N.space.none,paddingVertical:N.space.none,gap:N.space.none,style:h,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:e=>{T.current[t]=e},value:(m&&r?"":e)||"​",onChangeText:e=>q(t,e),onKeyPress:e=>M(t,e),onFocus:e=>H(t,e),onBlur:W,keyboardType:o,editable:!u,selectTextOnFocus:!0,caretHidden:r,maxLength:s+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[R.input,{fontSize:C.text,color:N.colors["text-body"],...(0,_index2.fontFor)(N,"semibold")},v]}),m&&r?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:R.maskOverlay,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[{fontSize:C.text,color:N.colors["text-body"],...(0,_index2.fontFor)(N,"semibold")},v],children:l})}):null]}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[R.underline,{backgroundColor:n,opacity:a}]})]},`otp-cell-${t}`)})})}),(0,_jsxRuntime.jsx)(_FieldBase.FieldMessage,{size:_,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,..._corners.smoothCorners}});var _default=exports.default=OTPInput;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Swipeable=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,n=Object.defineProperty,r={__proto__:null,default:e};if(Object(e)!==e)return r;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,r)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=n&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?n(r,i,a):r[i]=e[i]);return r}const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:a,rightActions:i,threshold:n,fullSwipeThreshold:r,onSwipeOpen:c,onSwipeClose:s,disabled:o=!1,haptic:l,containerStyle:u,contentStyle:d,actionStyle:_,accessibilityLabel:m,testID:h}=e,v=(0,_index.useTheme)(),p=n??80,R=r??200,N=(0,_react.useMemo)(()=>buildStyles(v),[v]),S=(0,_react.useMemo)(()=>buildActionStyles(v),[v]),b=!!a&&a.length>0,f=!!i&&i.length>0,w=_reactNative.Dimensions.get("window").width,x=b?p*(a?.length??0):0,g=f?p*(i?.length??0):0,y=(0,_reactNativeReanimated.useSharedValue)(0),j=(0,_reactNativeReanimated.useSharedValue)(0),O=(0,_react.useRef)(null);(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(y),(0,_reactNativeReanimated.cancelAnimation)(j)},[y,j]);const I=(0,_react.useCallback)(e=>{O.current!==e&&(O.current=e,c?.(e))},[c]),C=(0,_react.useCallback)(()=>{null!==O.current&&(O.current=null,s?.())},[s]),G=(0,_react.useCallback)(e=>{const t="left"===e?a:i,n=t?.[0];n&&(!1!==l&&(0,_index2.triggerHaptic)("notificationSuccess"),n.onPress(),y.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),O.current=null,s?.())},[a,i,y,s,l]),A=(0,_react.useCallback)(()=>{y.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),C()},[y,C]),P=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(l,"selection");t&&(0,_index2.triggerHaptic)(t),e.onPress(),A()},[A,l]),k=(0,_react.useMemo)(()=>{const e=x,t=g,a=R,i=-R,n=w,r=-w,c=p,s=b,l=f;return _reactNativeGestureHandler.Gesture.Pan().enabled(!o).withTestId(h?`${h}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";j.value=y.value}).onUpdate(a=>{"worklet";const i=j.value+a.translationX;y.value=i>0&&!s||i<0&&!l?0:i>e&&s?e+.35*(i-e):i<-t&&l?.35*(i+t)-t:i}).onEnd(()=>{"worklet";const o=y.value;return s&&o>=a?(y.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(G)("left")):l&&o<=i?(y.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(G)("right")):s&&o>=c?(y.value=(0,_reactNativeReanimated.withSpring)(e,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(I)("left")):l&&o<=-c?(y.value=(0,_reactNativeReanimated.withSpring)(-t,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(I)("right")):(y.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(C)())})},[o,j,G,R,b,f,x,C,I,g,w,p,y,h]),F=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:y.value}]})),T=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:x>0?Math.min(1,Math.max(0,y.value/x)):0})),M=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:g>0?Math.min(1,Math.max(0,-y.value/g)):0})),E=(0,_react.useMemo)(()=>{const e=[];return a?.forEach(t=>e.push({name:t.key,label:t.label})),i?.forEach(t=>e.push({name:t.key,label:t.label})),e},[a,i]),q=(0,_react.useCallback)(e=>{const t=e.nativeEvent.actionName,n=[...a??[],...i??[]].find(e=>e.key===t);n&&(!1!==l&&(0,_index2.triggerHaptic)("selection"),n.onPress())},[a,i,l]);return b||f?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[N.root,u],testID:h,accessibilityLabel:m,accessibilityActions:E,onAccessibilityAction:q,children:[b?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[N.actionsRow,N.actionsLeft,{width:x},_,T],pointerEvents:"box-none",children:a?.map(e=>(0,_jsxRuntime.jsx)(ActionButton,{action:e,theme:v,actionStyles:S,width:p,onPress:P},e.key))}):null,f?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[N.actionsRow,N.actionsRight,{width:g},_,M],pointerEvents:"box-none",children:i?.map(e=>(0,_jsxRuntime.jsx)(ActionButton,{action:e,theme:v,actionStyles:S,width:p,onPress:P},e.key))}):null,(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:k,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[N.content,d,F],children:t})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:u,testID:h,children:t})};exports.Swipeable=Swipeable,Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:a,width:i,onPress:n})=>{const r=e.tone??"neutral",c=toneToBg(t,r);return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>n(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[a.button,{width:i,backgroundColor:c,paddingHorizontal:t.space.sm}],children:[e.icon?(0,_jsxRuntime.jsx)(_reactNative.View,{style:a.icon,children:e.icon}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[a.label,{color:toneToOnColor(t,r),fontSize:t.text.sm.size,fontWeight:t.weight.semibold}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>_reactNative.StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>_reactNative.StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});var _default=exports.default=Swipeable;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Swipeable=void 0;var cache,_react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,n=Object.defineProperty,r={__proto__:null,default:e};if(Object(e)!==e)return r;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,r)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=n&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?n(r,i,a):r[i]=e[i]);return r}const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:a,rightActions:i,threshold:n,fullSwipeThreshold:r,onSwipeOpen:c,onSwipeClose:s,disabled:o=!1,haptic:l,containerStyle:u,contentStyle:d,actionStyle:_,accessibilityLabel:m,testID:h}=e,v=(0,_index.useTheme)(),p=n??80,R=r??200,N=(0,_react.useMemo)(()=>buildStyles(v),[v]),S=(0,_react.useMemo)(()=>buildActionStyles(v),[v]),b=!!a&&a.length>0,f=!!i&&i.length>0,w=_reactNative.Dimensions.get("window").width,x=b?p*(a?.length??0):0,g=f?p*(i?.length??0):0,y=(0,_reactNativeReanimated.useSharedValue)(0),j=(0,_reactNativeReanimated.useSharedValue)(0),O=(0,_react.useRef)(null);(0,_react.useEffect)(()=>()=>{(0,_reactNativeReanimated.cancelAnimation)(y),(0,_reactNativeReanimated.cancelAnimation)(j)},[y,j]);const I=(0,_react.useCallback)(e=>{O.current!==e&&(O.current=e,c?.(e))},[c]),C=(0,_react.useCallback)(()=>{null!==O.current&&(O.current=null,s?.())},[s]),G=(0,_react.useCallback)(e=>{const t="left"===e?a:i,n=t?.[0];n&&(!1!==l&&(0,_index2.triggerHaptic)("notificationSuccess"),n.onPress(),y.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),O.current=null,s?.())},[a,i,y,s,l]),A=(0,_react.useCallback)(()=>{y.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),C()},[y,C]),P=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(l,"selection");t&&(0,_index2.triggerHaptic)(t),e.onPress(),A()},[A,l]),k=(0,_react.useMemo)(()=>{const e=x,t=g,a=R,i=-R,n=w,r=-w,c=p,s=b,l=f;return _reactNativeGestureHandler.Gesture.Pan().enabled(!o).withTestId(h?`${h}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";j.value=y.value}).onUpdate(a=>{"worklet";const i=j.value+a.translationX;y.value=i>0&&!s||i<0&&!l?0:i>e&&s?e+.35*(i-e):i<-t&&l?.35*(i+t)-t:i}).onEnd(()=>{"worklet";const o=y.value;return s&&o>=a?(y.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(G)("left")):l&&o<=i?(y.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(G)("right")):s&&o>=c?(y.value=(0,_reactNativeReanimated.withSpring)(e,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(I)("left")):l&&o<=-c?(y.value=(0,_reactNativeReanimated.withSpring)(-t,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(I)("right")):(y.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),void(0,_reactNativeReanimated.runOnJS)(C)())})},[o,j,G,R,b,f,x,C,I,g,w,p,y,h]),F=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:y.value}]})),T=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:x>0?Math.min(1,Math.max(0,y.value/x)):0})),M=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({opacity:g>0?Math.min(1,Math.max(0,-y.value/g)):0})),E=(0,_react.useMemo)(()=>{const e=[];return a?.forEach(t=>{e.push({name:t.key,label:t.label})}),i?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[a,i]),q=(0,_react.useCallback)(e=>{const t=e.nativeEvent.actionName,n=[...a??[],...i??[]].find(e=>e.key===t);n&&(!1!==l&&(0,_index2.triggerHaptic)("selection"),n.onPress())},[a,i,l]);return b||f?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[N.root,u],testID:h,accessibilityLabel:m,accessibilityActions:E,onAccessibilityAction:q,children:[b?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[N.actionsRow,N.actionsLeft,{width:x},_,T],pointerEvents:"box-none",children:a?.map(e=>(0,_jsxRuntime.jsx)(ActionButton,{action:e,theme:v,actionStyles:S,width:p,onPress:P},e.key))}):null,f?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[N.actionsRow,N.actionsRight,{width:g},_,M],pointerEvents:"box-none",children:i?.map(e=>(0,_jsxRuntime.jsx)(ActionButton,{action:e,theme:v,actionStyles:S,width:p,onPress:P},e.key))}):null,(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:k,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[N.content,d,F],children:t})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:u,testID:h,children:t})};exports.Swipeable=Swipeable,Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:a,width:i,onPress:n})=>{const r=e.tone??"neutral",c=toneToBg(t,r);return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>n(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[a.button,{width:i,backgroundColor:c,paddingHorizontal:t.space.sm}],children:[e.icon?(0,_jsxRuntime.jsx)(_reactNative.View,{style:a.icon,children:e.icon}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[a.label,{color:toneToOnColor(t,r),fontSize:t.text.sm.size,fontWeight:t.weight.semibold}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>_reactNative.StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>_reactNative.StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});var _default=exports.default=Swipeable;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Toast=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_jsxRuntime=require("react/jsx-runtime");const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},DISMISS_ACTIONS=[{name:"dismiss",label:"Dismiss"}],Toast=({toast:e,index:t,onDismiss:i,shownAt:a,runtime:n})=>{const r=(0,_index.useTheme)(),s=(0,_usePresenceMotion.usePresenceMotion)(),o=s.duration("fast"),c=e.variant??"default",l=e.position??"bottom",u=(0,_react.useMemo)(()=>buildStyles(r),[r]),d=(0,_react.useMemo)(()=>tintFor(r,c),[r,c]),m=(0,_react.useMemo)(()=>inkFor(r,c),[r,c]),_=r.components.toast["icon-circle-size"],p=r.text[r.components.toast["icon-glyph-text"]].size,v=r.components.toast["tint-bar-width"],g=r.settings.components.toast?.defaultDurationMs??3e3,h=r.settings.components.toast?.enableSwipeDismiss??!0,x="top"===l?-120:120,f=(0,_react.useRef)((0,_index.createAnimatedValue)(s.reduced?0:x)).current,N=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,b=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,A=(0,_react.useRef)(!1),S="top"===l?8*t:8*-t,y=Math.max(1-.04*t,.9),w=(0,_react.useRef)((0,_index.createAnimatedValue)(S)).current;(0,_react.useEffect)(()=>{(0,_index.setNativeValue)(w,S)},[S,w]);const R=(0,_react.useMemo)(()=>_reactNative.Animated.add(f,w),[f,w]),M=void 0!==e.action,T=e.duration??g,V=T>0&&M&&"web"===_reactNative.Platform.OS?Math.max(T,8e3):T,D=V<=0||M&&!0===n?.screenReaderOn,j=!0===e.countdown&&!D,C=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,I=(0,_react.useRef)({initialised:!1,timer:null,remaining:0,startedAt:0}),E=(0,_react.useRef)({touch:!1,pan:!1,hover:!1}),O=(0,_react.useRef)(()=>{}),P=(0,_react.useRef)({id:e.id,totalMs:V,shownAt:a,runtime:n,persistent:D,animateBar:!1});P.current={id:e.id,totalMs:V,shownAt:a,runtime:n,persistent:D,animateBar:j&&!s.reduced};const k=(0,_react.useCallback)(()=>{const e=I.current,t=P.current,i=E.current;if(!e.initialised){e.initialised=!0;const i=t.runtime?.readRemaining(t.id),a=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=i??(t.totalMs>0?Math.max(t.totalMs-a,0):0),t.totalMs>0&&e.remaining<t.totalMs&&(0,_index.setNativeValue)(C,e.remaining/t.totalMs)}const a=!(t.persistent||A.current||i.touch||i.pan||i.hover);a&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,O.current()},e.remaining),t.animateBar&&_reactNative.Animated.timing(C,{toValue:0,duration:e.remaining,easing:_reactNative.Easing.linear,useNativeDriver:!0}).start()):a||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),C.stopAnimation())},[C]),dismiss=()=>{if(A.current)return;A.current=!0,k();const t=[_reactNative.Animated.timing(b,{toValue:0,duration:o,easing:_reactNative.Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:!0})];s.reduced||t.push(_reactNative.Animated.timing(f,{toValue:x,duration:r.motion.duration.fast,easing:_reactNative.Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:!0})),_reactNative.Animated.parallel(t).start(()=>i(e.id))};O.current=dismiss,(0,_react.useEffect)(()=>{const e=s.reduced?_reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0}):_reactNative.Animated.parallel([_reactNative.Animated.spring(f,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),_reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),(0,_react.useEffect)(()=>{k()},[D,k]),(0,_react.useEffect)(()=>()=>{const e=I.current,t=P.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),C.stopAnimation(),e.initialised&&t.totalMs>0&&!A.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[C]);const L=(0,_react.useCallback)((e,t)=>{E.current[e]=t,k()},[k]),H=(0,_react.useCallback)(()=>L("touch",!0),[L]),F=(0,_react.useCallback)(e=>L("touch",(e.nativeEvent.touches?.length??0)>0),[L]),z=(0,_react.useCallback)(()=>L("hover",!0),[L]),B=(0,_react.useCallback)(()=>L("hover",!1),[L]),q=(0,_react.useMemo)(()=>_reactNative.PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>L("pan",!0),onPanResponderMove:(e,t)=>{(0,_index.setNativeValue)(N,t.dx);const i=1-.7*Math.min(Math.abs(t.dx)/200,1);(0,_index.setNativeValue)(b,i)},onPanResponderTerminate:()=>{if(L("pan",!1),s.reduced)return(0,_index.setNativeValue)(N,0),void _reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0}).start();_reactNative.Animated.parallel([_reactNative.Animated.spring(N,{toValue:0,damping:r.motion.spring.snappy.damping,stiffness:r.motion.spring.snappy.stiffness,mass:r.motion.spring.snappy.mass,useNativeDriver:!0}),_reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,a)=>{if(Math.abs(a.dx)>80||Math.abs(a.vx)>.5){const t=a.dx>=0?1:-1;A.current=!0,L("pan",!1);const n=[_reactNative.Animated.timing(b,{toValue:0,duration:o,useNativeDriver:!0})];s.reduced||n.push(_reactNative.Animated.timing(N,{toValue:500*t,duration:r.motion.duration.fast,useNativeDriver:!0})),_reactNative.Animated.parallel(n).start(()=>i(e.id))}else L("pan",!1),s.reduced?((0,_index.setNativeValue)(N,0),_reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0}).start()):_reactNative.Animated.parallel([_reactNative.Animated.spring(N,{toValue:0,useNativeDriver:!0}),_reactNative.Animated.spring(b,{toValue:1,useNativeDriver:!0})]).start()}}),[N,b,L,o,s.reduced,r.motion.duration.fast,r.motion.spring.snappy.damping,r.motion.spring.snappy.stiffness,r.motion.spring.snappy.mass,i,e.id]),G={accessibilityActions:DISMISS_ACTIONS,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[W,U]=(0,_react.useState)(0),$=(0,_react.useMemo)(()=>C.interpolate({inputRange:[0,1],outputRange:[-W,0]}),[C,W]),K=e.description?`${e.message}. ${e.description}`:e.message,X=e.action&&j?`${e.action.label}, ${Math.ceil(V/1e3)} seconds`:e.action?.label;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{...h?q.panHandlers:{},...M?{}:{accessible:!0,...G},..."web"===_reactNative.Platform.OS?{onPointerEnter:z,onPointerLeave:B}:{},onTouchStart:H,onTouchEnd:F,onTouchCancel:F,accessibilityLabel:K,testID:e.testID,style:[u.container,{backgroundColor:r.colors.surface,borderRadius:r.radius.lg,..._corners.smoothCorners,padding:r.space.md,...r.shadow.elevated,opacity:b,transform:[{translateY:R},{translateX:N},{scale:y}]},e.style,e.containerStyle],children:[v>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[u.tintBar,{width:v,backgroundColor:d}]}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:u.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(c);return t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[u.iconCircle,{width:_,height:_,borderRadius:r.radius.pill,..._corners.smoothCorners,backgroundColor:d+"22"},e.iconCircleStyle],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[u.iconGlyph,{color:m,fontSize:p}],accessible:!1,children:t})}):null})(),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:u.textBlock,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[u.message,{color:r.colors["text-body"],fontSize:r.text.base.size,...(0,_index.fontFor)(r,"semibold")},e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[u.description,{color:r.colors["text-muted"],fontSize:r.text.sm.size}],numberOfLines:3,children:e.description}):null]}),e.action?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{accessibilityRole:"button",accessibilityLabel:X,hitSlop:ACTION_HIT_SLOP,...(0,_hitSlop.hitSlopMarker)(ACTION_HIT_SLOP),...G,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[u.actionBtn,{backgroundColor:t?r.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:d,fontSize:r.text.sm.size,...(0,_index.fontFor)(r,"semibold")},numberOfLines:1,children:e.action.label})}):null]}),j?(0,_jsxRuntime.jsxs)(_reactNative.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>U(e.nativeEvent.layout.width),testID:"toast-countdown",style:[u.countdownTrack,{backgroundColor:d+"22"}],children:[s.reduced?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[u.countdownFill,{backgroundColor:d}]}):null,!s.reduced&&W>0?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[u.countdownFill,{backgroundColor:d,transform:[{translateX:$}]}]}):null]}):null]})};exports.Toast=Toast;const tintFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>_reactNative.StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,..._corners.smoothCorners,marginLeft:e.space.sm}});var _default=exports.default=Toast;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Toast=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_jsxRuntime=require("react/jsx-runtime");const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},DISMISS_ACTIONS=[{name:"dismiss",label:"Dismiss"}],Toast=({toast:e,index:t,onDismiss:i,shownAt:a,runtime:n})=>{const r=(0,_index.useTheme)(),s=(0,_usePresenceMotion.usePresenceMotion)(),o=s.duration("fast"),c=e.variant??"default",l=e.position??"bottom",u=(0,_react.useMemo)(()=>buildStyles(r),[r]),d=(0,_react.useMemo)(()=>tintFor(r,c),[r,c]),m=(0,_react.useMemo)(()=>inkFor(r,c),[r,c]),_=r.components.toast["icon-circle-size"],p=r.text[r.components.toast["icon-glyph-text"]].size,v=r.components.toast["tint-bar-width"],g=r.settings.components.toast?.defaultDurationMs??3e3,h=r.settings.components.toast?.enableSwipeDismiss??!0,x="top"===l?-120:120,f=(0,_react.useRef)((0,_index.createAnimatedValue)(s.reduced?0:x)).current,N=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,b=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,A=(0,_react.useRef)(!1),S="top"===l?8*t:8*-t,y=Math.max(1-.04*t,.9),w=(0,_react.useRef)((0,_index.createAnimatedValue)(S)).current;(0,_react.useEffect)(()=>{(0,_index.setNativeValue)(w,S)},[S,w]);const R=(0,_react.useMemo)(()=>_reactNative.Animated.add(f,w),[f,w]),M=void 0!==e.action,T=e.duration??g,V=T>0&&M&&"web"===_reactNative.Platform.OS?Math.max(T,8e3):T,D=V<=0||M&&!0===n?.screenReaderOn,j=!0===e.countdown&&!D,C=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,I=(0,_react.useRef)({initialised:!1,timer:null,remaining:0,startedAt:0}),E=(0,_react.useRef)({touch:!1,pan:!1,hover:!1}),O=(0,_react.useRef)(()=>{}),P=(0,_react.useRef)({id:e.id,totalMs:V,shownAt:a,runtime:n,persistent:D,animateBar:!1});P.current={id:e.id,totalMs:V,shownAt:a,runtime:n,persistent:D,animateBar:j&&!s.reduced};const k=(0,_react.useCallback)(()=>{const e=I.current,t=P.current,i=E.current;if(!e.initialised){e.initialised=!0;const i=t.runtime?.readRemaining(t.id),a=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=i??(t.totalMs>0?Math.max(t.totalMs-a,0):0),t.totalMs>0&&e.remaining<t.totalMs&&(0,_index.setNativeValue)(C,e.remaining/t.totalMs)}const a=!(t.persistent||A.current||i.touch||i.pan||i.hover);a&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,O.current()},e.remaining),t.animateBar&&_reactNative.Animated.timing(C,{toValue:0,duration:e.remaining,easing:_reactNative.Easing.linear,useNativeDriver:!0}).start()):a||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),C.stopAnimation())},[C]),dismiss=()=>{if(A.current)return;A.current=!0,k();const t=[_reactNative.Animated.timing(b,{toValue:0,duration:o,easing:_reactNative.Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:!0})];s.reduced||t.push(_reactNative.Animated.timing(f,{toValue:x,duration:r.motion.duration.fast,easing:_reactNative.Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:!0})),_reactNative.Animated.parallel(t).start(()=>i(e.id))};O.current=dismiss,(0,_react.useEffect)(()=>{const e=s.reduced?_reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0}):_reactNative.Animated.parallel([_reactNative.Animated.spring(f,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),_reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),(0,_react.useEffect)(()=>{k()},[D,k]),(0,_react.useEffect)(()=>()=>{const e=I.current,t=P.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),C.stopAnimation(),e.initialised&&t.totalMs>0&&!A.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[C]);const L=(0,_react.useCallback)((e,t)=>{E.current[e]=t,k()},[k]),H=(0,_react.useCallback)(()=>L("touch",!0),[L]),F=(0,_react.useCallback)(e=>L("touch",(e.nativeEvent.touches?.length??0)>0),[L]),z=(0,_react.useCallback)(()=>L("hover",!0),[L]),B=(0,_react.useCallback)(()=>L("hover",!1),[L]),q=(0,_react.useMemo)(()=>_reactNative.PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>L("pan",!0),onPanResponderMove:(e,t)=>{(0,_index.setNativeValue)(N,t.dx);const i=1-.7*Math.min(Math.abs(t.dx)/200,1);(0,_index.setNativeValue)(b,i)},onPanResponderTerminate:()=>{if(L("pan",!1),s.reduced)return(0,_index.setNativeValue)(N,0),void _reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0}).start();_reactNative.Animated.parallel([_reactNative.Animated.spring(N,{toValue:0,damping:r.motion.spring.snappy.damping,stiffness:r.motion.spring.snappy.stiffness,mass:r.motion.spring.snappy.mass,useNativeDriver:!0}),_reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,a)=>{if(Math.abs(a.dx)>80||Math.abs(a.vx)>.5){const t=a.dx>=0?1:-1;A.current=!0,L("pan",!1);const n=[_reactNative.Animated.timing(b,{toValue:0,duration:o,useNativeDriver:!0})];s.reduced||n.push(_reactNative.Animated.timing(N,{toValue:500*t,duration:r.motion.duration.fast,useNativeDriver:!0})),_reactNative.Animated.parallel(n).start(()=>i(e.id))}else L("pan",!1),s.reduced?((0,_index.setNativeValue)(N,0),_reactNative.Animated.timing(b,{toValue:1,duration:o,useNativeDriver:!0}).start()):_reactNative.Animated.parallel([_reactNative.Animated.spring(N,{toValue:0,useNativeDriver:!0}),_reactNative.Animated.spring(b,{toValue:1,useNativeDriver:!0})]).start()}}),[N,b,L,o,s.reduced,r.motion.duration.fast,r.motion.spring.snappy.damping,r.motion.spring.snappy.stiffness,r.motion.spring.snappy.mass,i,e.id]),G={accessibilityActions:DISMISS_ACTIONS,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[$,W]=(0,_react.useState)(0),U=(0,_react.useMemo)(()=>C.interpolate({inputRange:[0,1],outputRange:[-$,0]}),[C,$]),K=e.description?`${e.message}. ${e.description}`:e.message,X=e.action&&j?`${e.action.label}, ${Math.ceil(V/1e3)} seconds`:e.action?.label;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{...h?q.panHandlers:{},...M?{}:{accessible:!0,...G},..."web"===_reactNative.Platform.OS?{onPointerEnter:z,onPointerLeave:B}:{},onTouchStart:H,onTouchEnd:F,onTouchCancel:F,accessibilityLabel:K,testID:e.testID,style:[u.container,{backgroundColor:r.colors.surface,borderRadius:r.radius.lg,..._corners.smoothCorners,padding:r.space.md,...r.shadow.elevated,opacity:b,transform:[{translateY:R},{translateX:N},{scale:y}]},e.style,e.containerStyle],children:[v>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[u.tintBar,{width:v,backgroundColor:d}]}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:u.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(c);return t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[u.iconCircle,{width:_,height:_,borderRadius:r.radius.pill,..._corners.smoothCorners,backgroundColor:`${d}22`},e.iconCircleStyle],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[u.iconGlyph,{color:m,fontSize:p}],accessible:!1,children:t})}):null})(),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:u.textBlock,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[u.message,{color:r.colors["text-body"],fontSize:r.text.base.size,...(0,_index.fontFor)(r,"semibold")},e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[u.description,{color:r.colors["text-muted"],fontSize:r.text.sm.size}],numberOfLines:3,children:e.description}):null]}),e.action?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{accessibilityRole:"button",accessibilityLabel:X,hitSlop:ACTION_HIT_SLOP,...(0,_hitSlop.hitSlopMarker)(ACTION_HIT_SLOP),...G,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[u.actionBtn,{backgroundColor:t?r.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:d,fontSize:r.text.sm.size,...(0,_index.fontFor)(r,"semibold")},numberOfLines:1,children:e.action.label})}):null]}),j?(0,_jsxRuntime.jsxs)(_reactNative.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>W(e.nativeEvent.layout.width),testID:"toast-countdown",style:[u.countdownTrack,{backgroundColor:`${d}22`}],children:[s.reduced?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[u.countdownFill,{backgroundColor:d}]}):null,!s.reduced&&$>0?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[u.countdownFill,{backgroundColor:d,transform:[{translateX:U}]}]}):null]}):null]})};exports.Toast=Toast;const tintFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>_reactNative.StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,..._corners.smoothCorners,marginLeft:e.space.sm}});var _default=exports.default=Toast;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setPath=exports.getPath=exports.deletePath=void 0;const tokenize=t=>{const e=[],r=/[^.[\]]+/g;let o;for(;null!==(o=r.exec(t));){const t=o[0];e.push(/^\d+$/.test(t)?Number(t):t)}return e},getPath=(t,e)=>{const r=tokenize(e);let o=t;for(const t of r){if(null==o||"object"!=typeof o)return;o=o[t]}return o};exports.getPath=getPath;const setPath=(t,e,r)=>{const o=tokenize(e);if(0===o.length)return t;const n=Array.isArray(t)?[...t]:{...t};let s=n;for(let t=0;t<o.length-1;t++){const e=o[t],r=o[t+1],n=s[e],l=null!=n&&"object"==typeof n?Array.isArray(n)?[...n]:{...n}:"number"==typeof r?[]:{};s[e]=l,s=l}return s[o[o.length-1]]=r,n};exports.setPath=setPath;const deletePath=(t,e)=>{const r=tokenize(e);if(0===r.length)return t;const o=Array.isArray(t)?[...t]:{...t};let n=o;for(let t=0;t<r.length-1;t++){const e=r[t],s=n[e];if(null==s||"object"!=typeof s)return o;const l=Array.isArray(s)?[...s]:{...s};n[e]=l,n=l}const s=r[r.length-1];return Array.isArray(n)&&"number"==typeof s?n.splice(s,1):delete n[s],o};exports.deletePath=deletePath;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setPath=exports.getPath=exports.deletePath=void 0;const tokenize=t=>{const e=[],r=/[^.[\]]+/g;for(const o of t.matchAll(r)){const t=o[0];e.push(/^\d+$/.test(t)?Number(t):t)}return e},getPath=(t,e)=>{const r=tokenize(e);let o=t;for(const t of r){if(null==o||"object"!=typeof o)return;o=o[t]}return o};exports.getPath=getPath;const setPath=(t,e,r)=>{const o=tokenize(e);if(0===o.length)return t;const n=Array.isArray(t)?[...t]:{...t};let s=n;for(let t=0;t<o.length-1;t++){const e=o[t],r=o[t+1],n=s[e],l=null!=n&&"object"==typeof n?Array.isArray(n)?[...n]:{...n}:"number"==typeof r?[]:{};s[e]=l,s=l}return s[o[o.length-1]]=r,n};exports.setPath=setPath;const deletePath=(t,e)=>{const r=tokenize(e);if(0===r.length)return t;const o=Array.isArray(t)?[...t]:{...t};let n=o;for(let t=0;t<r.length-1;t++){const e=r[t],s=n[e];if(null==s||"object"!=typeof s)return o;const l=Array.isArray(s)?[...s]:{...s};n[e]=l,n=l}const s=r[r.length-1];return Array.isArray(n)&&"number"==typeof s?n.splice(s,1):delete n[s],o};exports.deletePath=deletePath;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.announce=void 0;var _reactNative=require("react-native");let webRegions=null;const webRegion=e=>{if("undefined"==typeof document)return null;if(!webRegions||!webRegions.polite.isConnected){const make=e=>{const t=document.createElement("div");return t.setAttribute("aria-live",e),t.setAttribute("aria-atomic","true"),t.setAttribute("role","assertive"===e?"alert":"status"),Object.assign(t.style,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"}),document.body.appendChild(t),t};webRegions={polite:make("polite"),assertive:make("assertive")}}return e?webRegions.polite:webRegions.assertive},announce=(e,t)=>{if(!e)return;const i=!1!==t?.polite;if("web"===_reactNative.Platform.OS){const t=webRegion(i);return void(t&&(t.textContent="",setTimeout(()=>{t.textContent=e},50)))}"ios"!==_reactNative.Platform.OS?_reactNative.AccessibilityInfo.announceForAccessibility(e):_reactNative.AccessibilityInfo.announceForAccessibilityWithOptions(e,i?{queue:!0}:{queue:!1,priority:"high"})};exports.announce=announce;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.announce=void 0;var _reactNative=require("react-native");let webRegions=null;const webRegion=e=>{if("undefined"==typeof document)return null;if(!webRegions?.polite.isConnected){const make=e=>{const t=document.createElement("div");return t.setAttribute("aria-live",e),t.setAttribute("aria-atomic","true"),t.setAttribute("role","assertive"===e?"alert":"status"),Object.assign(t.style,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"}),document.body.appendChild(t),t};webRegions={polite:make("polite"),assertive:make("assertive")}}return e?webRegions.polite:webRegions.assertive},announce=(e,t)=>{if(!e)return;const i=!1!==t?.polite;if("web"===_reactNative.Platform.OS){const t=webRegion(i);return void(t&&(t.textContent="",setTimeout(()=>{t.textContent=e},50)))}"ios"!==_reactNative.Platform.OS?_reactNative.AccessibilityInfo.announceForAccessibility(e):_reactNative.AccessibilityInfo.announceForAccessibilityWithOptions(e,i?{queue:!0}:{queue:!1,priority:"high"})};exports.announce=announce;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,fontFor,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Banner=forwardRef((e,t)=>{const{title:r,message:o,variant:s="info",icon:n,actions:i,dismissible:l=!1,onDismiss:a,haptic:c,visible:d=!0,animateMount:u=!0,loading:m=!1,accessibilityRole:p="alert",accessibilityLabel:g,style:h,containerStyle:x,iconCircleStyle:y,tintBarStyle:b,closeButtonStyle:f,actionButtonStyle:w,testID:j}=e,S=useTheme(),k=usePresenceMotion(),C=useMemo(()=>buildStyles(S),[S]),B=useMemo(()=>tintFor(S,s),[S,s]),[_,R]=k.range(-20,0),V=useRef(createAnimatedValue(u&&d?_:0)).current,v=useRef(createAnimatedValue(u&&d?0:d?1:0)).current,[z,T]=useState(d),H=useRef(!0);if(useEffect(()=>{if(H.current&&(H.current=!1,!u))return;let e;return d?(T(!0),e=Animated.parallel([Animated.timing(V,{toValue:R,duration:S.motion.duration.default,useNativeDriver:!0}),Animated.timing(v,{toValue:1,duration:k.duration("default"),useNativeDriver:!0})]),e.start()):z&&(e=Animated.parallel([Animated.timing(V,{toValue:_,duration:S.motion.duration.fast,useNativeDriver:!0}),Animated.timing(v,{toValue:0,duration:k.duration("fast"),useNativeDriver:!0})]),e.start(()=>{T(!1)})),()=>e?.stop()},[d]),!z)return null;const A=r??" ",D="string"==typeof o?o??" ":"",M="alert"===p?"danger"===s?"assertive":"polite":"none",L=_jsxs(Animated.View,{ref:t,accessibilityRole:p,accessibilityLiveRegion:M,accessibilityLabel:g,testID:j,style:[C.container,{backgroundColor:S.colors["bg-subtle"],borderRadius:S.radius.md,...smoothCorners,padding:S.space.md,opacity:v,transform:[{translateY:V}]},h,x],children:[S.components.banner["tint-bar-width"]>0?_jsx(View,{style:[C.tintBar,{backgroundColor:B.bar},b]}):null,_jsxs(View,{style:C.row,children:[!1===n?null:_jsx(View,n?{style:C.iconWrap,children:n}:{style:[C.iconCircle,{backgroundColor:B.bar+"22"},y],children:_jsx(Text,{style:[C.iconGlyph,{color:B.ink}],accessible:!1,children:B.glyph})}),_jsxs(View,{style:C.textBlock,children:[r||m?_jsx(Text,{style:{color:S.colors["text-body"],fontSize:S.text.base.size,...fontFor(S,"semibold"),lineHeight:20},numberOfLines:2,children:A}):null,"string"==typeof o||m?_jsx(Text,{style:{color:S.colors["text-muted"],fontSize:S.text.sm.size,...fontFor(S,"normal"),lineHeight:18,marginTop:r?S.space.xxs:0},children:D||" "}):_jsx(View,{style:{marginTop:r?S.space.xxs:0},children:o})]}),l?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:"Dismiss banner",onPress:()=>{const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),a?.()},hitSlop:8,...hitSlopMarker(8),style:({pressed:e})=>[C.closeBtn,{backgroundColor:e?S.colors["surface-pressed"]:"transparent"},f],children:_jsx(Text,{style:{color:S.colors["text-muted"],fontSize:S.text.lg.size,fontWeight:S.weight.bold,lineHeight:17},accessible:!1,children:"×"})}):null]}),i&&i.length>0?_jsx(View,{style:C.actionsRow,children:i.map((e,t)=>{const r=e.tone??"primary",o=e.variant??"ghost",s="danger"===r?S.colors.danger:"neutral"===r?S.colors["text-muted"]:B.glyphColor,n="danger"===r?S.colors["danger-text"]:"neutral"===r?S.colors["text-muted"]:B.ink,i="danger"===r?S.colors["on-danger"]:"neutral"===r?S.colors["on-neutral-strong"]:B.on,l="solid"===o;return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.label,onPress:()=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress()},style:({pressed:t})=>[C.actionBtn,"md"===e.size&&C.actionBtnMd,"outline"===o&&{borderWidth:1,borderColor:n},{backgroundColor:l?s:t?S.colors["surface-pressed"]:"transparent",opacity:l&&t?.85:1},w],children:_jsx(Text,{style:{color:l?i:n,fontSize:S.text.sm.size,textAlign:"center",...fontFor(S,"semibold")},children:e.label})},`${e.label}-${t}`)})}):null]});return m?_jsx(BannerSkeleton,{...e}):L});Banner.displayName="Banner";const BannerSkeleton=({title:e,actions:t,icon:r,containerStyle:o,style:s})=>{const n=useTheme(),i=!1!==r;return _jsxs(View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:n.colors.surface,borderRadius:n.radius.md,...smoothCorners,padding:n.space.md,borderWidth:1,borderColor:n.colors.border},o,s],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[i?_jsx(View,{style:{marginRight:n.space.sm},children:_jsx(Skeleton,{shape:"circle",width:32,height:32})}):null,_jsxs(View,{style:{flex:1},children:[void 0!==e?_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:n.space.xs}}):null,_jsx(SkeletonText,{lines:2,fontSize:n.text.sm.size,lastLineWidth:"70%"}),t&&t.length>0?_jsx(View,{style:{flexDirection:"row",marginTop:n.space.sm},children:t.map((e,t)=>_jsx(Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:n.space.sm}},`sk-banner-action-${t}`))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton",Banner.Skeleton=BannerSkeleton;const tintFor=(e,t)=>{switch(t){case"success":return{bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors["success-text"],on:e.colors["on-success"],glyph:"✓"};case"warning":return{bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors["warning-text"],on:e.colors["on-warning"],glyph:"⚠"};case"danger":return{bar:e.colors.danger,glyphColor:e.colors.danger,ink:e.colors["danger-text"],on:e.colors["on-danger"],glyph:"✗"};case"neutral":return{bar:e.colors["text-subtle"],glyphColor:e.colors["text-muted"],ink:e.colors["text-muted"],on:e.colors["on-neutral-strong"],glyph:"i"};default:return{bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors["primary-text"],on:e.colors["on-primary"],glyph:"i"}}},buildStyles=e=>{const t=e.components.banner,r=e.space.sm;return StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.space.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:t["tint-bar-width"]},row:{flexDirection:"row",alignItems:"flex-start"},iconWrap:{marginRight:r},iconCircle:{width:28,height:28,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",marginRight:r},iconGlyph:{fontSize:e.text.base.size,fontWeight:"700",lineHeight:17},textBlock:{flex:1,paddingRight:e.space.xs},closeBtn:{width:28,height:28,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.space.xxs},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.space.xs,columnGap:e.space.xs,rowGap:e.space.xs},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.space.md}})};export{Banner};export default Banner;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,fontFor,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Skeleton,SkeletonText}from"../Skeleton/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Banner=forwardRef((e,t)=>{const{title:r,message:o,variant:s="info",icon:n,actions:i,dismissible:l=!1,onDismiss:a,haptic:c,visible:d=!0,animateMount:u=!0,loading:m=!1,accessibilityRole:p="alert",accessibilityLabel:g,style:h,containerStyle:x,iconCircleStyle:y,tintBarStyle:b,closeButtonStyle:f,actionButtonStyle:w,testID:j}=e,S=useTheme(),k=usePresenceMotion(),C=useMemo(()=>buildStyles(S),[S]),B=useMemo(()=>tintFor(S,s),[S,s]),[_,R]=k.range(-20,0),V=useRef(createAnimatedValue(u&&d?_:0)).current,v=useRef(createAnimatedValue(u&&d?0:d?1:0)).current,[z,T]=useState(d),H=useRef(!0);if(useEffect(()=>{if(H.current&&(H.current=!1,!u))return;let e;return d?(T(!0),e=Animated.parallel([Animated.timing(V,{toValue:R,duration:S.motion.duration.default,useNativeDriver:!0}),Animated.timing(v,{toValue:1,duration:k.duration("default"),useNativeDriver:!0})]),e.start()):z&&(e=Animated.parallel([Animated.timing(V,{toValue:_,duration:S.motion.duration.fast,useNativeDriver:!0}),Animated.timing(v,{toValue:0,duration:k.duration("fast"),useNativeDriver:!0})]),e.start(()=>{T(!1)})),()=>e?.stop()},[d]),!z)return null;const A=r??" ",D="string"==typeof o?o??" ":"",M="alert"===p?"danger"===s?"assertive":"polite":"none",L=_jsxs(Animated.View,{ref:t,accessibilityRole:p,accessibilityLiveRegion:M,accessibilityLabel:g,testID:j,style:[C.container,{backgroundColor:S.colors["bg-subtle"],borderRadius:S.radius.md,...smoothCorners,padding:S.space.md,opacity:v,transform:[{translateY:V}]},h,x],children:[S.components.banner["tint-bar-width"]>0?_jsx(View,{style:[C.tintBar,{backgroundColor:B.bar},b]}):null,_jsxs(View,{style:C.row,children:[!1===n?null:_jsx(View,n?{style:C.iconWrap,children:n}:{style:[C.iconCircle,{backgroundColor:`${B.bar}22`},y],children:_jsx(Text,{style:[C.iconGlyph,{color:B.ink}],accessible:!1,children:B.glyph})}),_jsxs(View,{style:C.textBlock,children:[r||m?_jsx(Text,{style:{color:S.colors["text-body"],fontSize:S.text.base.size,...fontFor(S,"semibold"),lineHeight:20},numberOfLines:2,children:A}):null,"string"==typeof o||m?_jsx(Text,{style:{color:S.colors["text-muted"],fontSize:S.text.sm.size,...fontFor(S,"normal"),lineHeight:18,marginTop:r?S.space.xxs:0},children:D||" "}):_jsx(View,{style:{marginTop:r?S.space.xxs:0},children:o})]}),l?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:"Dismiss banner",onPress:()=>{const e=resolveHaptic(c,"selection");e&&triggerHaptic(e),a?.()},hitSlop:8,...hitSlopMarker(8),style:({pressed:e})=>[C.closeBtn,{backgroundColor:e?S.colors["surface-pressed"]:"transparent"},f],children:_jsx(Text,{style:{color:S.colors["text-muted"],fontSize:S.text.lg.size,fontWeight:S.weight.bold,lineHeight:17},accessible:!1,children:"×"})}):null]}),i&&i.length>0?_jsx(View,{style:C.actionsRow,children:i.map((e,t)=>{const r=e.tone??"primary",o=e.variant??"ghost",s="danger"===r?S.colors.danger:"neutral"===r?S.colors["text-muted"]:B.glyphColor,n="danger"===r?S.colors["danger-text"]:"neutral"===r?S.colors["text-muted"]:B.ink,i="danger"===r?S.colors["on-danger"]:"neutral"===r?S.colors["on-neutral-strong"]:B.on,l="solid"===o;return _jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:e.label,onPress:()=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress()},style:({pressed:t})=>[C.actionBtn,"md"===e.size&&C.actionBtnMd,"outline"===o&&{borderWidth:1,borderColor:n},{backgroundColor:l?s:t?S.colors["surface-pressed"]:"transparent",opacity:l&&t?.85:1},w],children:_jsx(Text,{style:{color:l?i:n,fontSize:S.text.sm.size,textAlign:"center",...fontFor(S,"semibold")},children:e.label})},`${e.label}-${t}`)})}):null]});return m?_jsx(BannerSkeleton,{...e}):L});Banner.displayName="Banner";const BannerSkeleton=({title:e,actions:t,icon:r,containerStyle:o,style:s})=>{const n=useTheme(),i=!1!==r;return _jsxs(View,{style:[{flexDirection:"row",alignItems:"flex-start",backgroundColor:n.colors.surface,borderRadius:n.radius.md,...smoothCorners,padding:n.space.md,borderWidth:1,borderColor:n.colors.border},o,s],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[i?_jsx(View,{style:{marginRight:n.space.sm},children:_jsx(Skeleton,{shape:"circle",width:32,height:32})}):null,_jsxs(View,{style:{flex:1},children:[void 0!==e?_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:n.space.xs}}):null,_jsx(SkeletonText,{lines:2,fontSize:n.text.sm.size,lastLineWidth:"70%"}),t&&t.length>0?_jsx(View,{style:{flexDirection:"row",marginTop:n.space.sm},children:t.map((e,t)=>_jsx(Skeleton,{width:72,height:28,shape:"rounded",style:{marginRight:n.space.sm}},`sk-banner-action-${t}`))}):null]})]})};BannerSkeleton.displayName="BannerSkeleton",Banner.Skeleton=BannerSkeleton;const tintFor=(e,t)=>{switch(t){case"success":return{bar:e.colors.success,glyphColor:e.colors.success,ink:e.colors["success-text"],on:e.colors["on-success"],glyph:"✓"};case"warning":return{bar:e.colors.warning,glyphColor:e.colors.warning,ink:e.colors["warning-text"],on:e.colors["on-warning"],glyph:"⚠"};case"danger":return{bar:e.colors.danger,glyphColor:e.colors.danger,ink:e.colors["danger-text"],on:e.colors["on-danger"],glyph:"✗"};case"neutral":return{bar:e.colors["text-subtle"],glyphColor:e.colors["text-muted"],ink:e.colors["text-muted"],on:e.colors["on-neutral-strong"],glyph:"i"};default:return{bar:e.colors.primary,glyphColor:e.colors.primary,ink:e.colors["primary-text"],on:e.colors["on-primary"],glyph:"i"}}},buildStyles=e=>{const t=e.components.banner,r=e.space.sm;return StyleSheet.create({container:{overflow:"hidden",paddingLeft:e.space.md},tintBar:{position:"absolute",left:0,top:0,bottom:0,width:t["tint-bar-width"]},row:{flexDirection:"row",alignItems:"flex-start"},iconWrap:{marginRight:r},iconCircle:{width:28,height:28,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",marginRight:r},iconGlyph:{fontSize:e.text.base.size,fontWeight:"700",lineHeight:17},textBlock:{flex:1,paddingRight:e.space.xs},closeBtn:{width:28,height:28,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",marginLeft:e.space.xxs},actionsRow:{flexDirection:"row",flexWrap:"wrap",justifyContent:"flex-end",marginTop:e.space.xs,columnGap:e.space.xs,rowGap:e.space.xs},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,borderRadius:e.radius.sm,...smoothCorners,maxWidth:"100%",alignItems:"center",justifyContent:"center"},actionBtnMd:{minHeight:44,paddingHorizontal:e.space.md}})};export{Banner};export default Banner;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Easing,Modal,Pressable,StyleSheet,Text,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const NAV_BUTTON_SIZE=36,AnimatedGestureRoot=Animated.createAnimatedComponent(GestureHandlerRootView),GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),isSameDay=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),toIso=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,addMonths=(e,t)=>new Date(e.getFullYear(),e.getMonth()+t,1),buildMonthMatrix=(e,t)=>{const a=e.getFullYear(),r=e.getMonth(),s=(new Date(a,r,1).getDay()-t+7)%7,i=[];for(let e=0;e<42;e+=1){const t=new Date(a,r,1-s+e);i.push({date:t,inMonth:t.getMonth()===r,iso:toIso(t)})}return i},weekdayLabels=(e,t)=>{const a=new Intl.DateTimeFormat(e,{weekday:"short"}),r=[];for(let e=0;e<7;e+=1){const s=new Date(1970,0,4+(t+e)%7);r.push(a.format(s))}return r},formatMonthYear=(e,t)=>new Intl.DateTimeFormat(t,{month:"long",year:"numeric"}).format(e),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:s,maxDate:i,disabledDates:o,mode:n="modal",locale:l="en-IN",weekStartsOn:c=0,title:d="Select Date",confirmLabel:u="Confirm",cancelLabel:m="Cancel",style:g,containerStyle:y,headerLabelStyle:h,navButtonStyle:p,footerButtonStyle:b,haptic:f,testID:x,label:w,placeholder:D,helperText:v,error:C,required:j,disabled:S,size:A,variant:V,clearable:T,onClear:_,formatValue:M,triggerStyle:R}=e,k=void 0!==e.visible,[I,P]=useState(!1),F=k?e.visible:I,N=k?x:x?`${x}-calendar`:void 0,Y=useTheme(),L=usePresenceMotion(),[z,B]=useModalInsets(),$=useMemo(()=>buildStyles(Y),[Y]),[E,H]=useState(()=>startOfDay(new Date));useEffect(()=>{F&&H(startOfDay(new Date))},[F]);const O=t?startOfDay(t):E,[W,G]=useState(O),[q,X]=useState(t?startOfDay(t):null),[Z,U]=useState("days"),J=useRef(createAnimatedValue(0)).current,K=useRef(createAnimatedValue(0)).current,Q=useRef(createAnimatedValue(0)).current,ee=useRef(0),te=useRef(createAnimatedValue(0)).current,ae=useRef(createAnimatedValue(1)).current,re=useRef(createAnimatedValue(1)).current,se=useRef(createAnimatedValue(1)).current,ie=useRef(createAnimatedValue(1)).current,oe=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(t){const e=startOfDay(t);X(e),G(e)}else X(null)},[t]);const ne=useMemo(()=>{const e=new Set;return o?.forEach(t=>e.add(toIso(startOfDay(t)))),e},[o]),le=useMemo(()=>s?startOfDay(s):null,[s]),ce=useMemo(()=>i?startOfDay(i):null,[i]),de=useCallback(e=>!!(le&&e.getTime()<le.getTime())||(!!(ce&&e.getTime()>ce.getTime())||!!ne.has(toIso(e))),[le,ce,ne]),ue=useMemo(()=>buildMonthMatrix(W,c),[W,c]),me=useMemo(()=>buildYearCells(W.getFullYear()),[W]),ge=useMemo(()=>buildDecadeCells(W.getFullYear()),[W]),ye=useMemo(()=>weekdayLabels(l,c),[l,c]),he=useMemo(()=>new Intl.DateTimeFormat(l,{weekday:"long",year:"numeric",month:"long",day:"numeric"}),[l]),pe=useMemo(()=>{if("days"===Z)return formatMonthYear(W,l);if("years"===Z){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[W,ge,l,Z,me]),be=useCallback(e=>!!(le&&e<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),fe=useCallback(e=>!!(le&&e+10-1<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),xe=useCallback(e=>{!1!==f&&triggerHaptic("impactLight");const t=e>0?1:-1,a=Y.motion.duration.fast,r=Y.motion.duration.fast,[s]=L.range(32*-t,0),[i]=L.range(32*t,0),o=L.reduced?L.duration("fast"):a,n=L.reduced?L.duration("fast"):r;Animated.sequence([Animated.parallel([Animated.timing(te,{toValue:s,duration:a,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(ae,{toValue:0,duration:o,useNativeDriver:!0})]),Animated.timing(te,{toValue:i,duration:0,useNativeDriver:!0}),Animated.parallel([Animated.timing(te,{toValue:0,duration:r,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ae,{toValue:1,duration:n,useNativeDriver:!0})])]).start();const c=addMonths(W,e);G(c),AccessibilityInfo.announceForAccessibility(formatMonthYear(c,l))},[W,f,l,ae,te,L,Y.motion.duration.fast]),we=useCallback(()=>{"days"!==Z?(!1!==f&&triggerHaptic("impactLight"),G("years"===Z?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))):xe(-1)},[xe,Z,f]),De=useCallback(()=>{"days"!==Z?(!1!==f&&triggerHaptic("impactLight"),G("years"===Z?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))):xe(1)},[xe,Z,f]),ve=useCallback(()=>{const[e]=L.range(.9,1),t=L.reduced?L.duration("default"):Y.motion.duration.default;setNativeValue(se,0),setNativeValue(ie,e),Animated.parallel([Animated.timing(se,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ie,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0})]).start()},[se,ie,L,Y.motion.duration.default]),Ce=useCallback(()=>{const e=resolveHaptic(f,"selection");if(e&&triggerHaptic(e),!L.reduced){const e=80,t=100;Animated.sequence([Animated.timing(oe,{toValue:.96,duration:e,useNativeDriver:!0}),Animated.timing(oe,{toValue:1,duration:t,useNativeDriver:!0})]).start()}U(e=>"days"===e?"years":"years"===e?"decades":"years"),ve()},[ve,oe,f,L.reduced]),je=useCallback(e=>{const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),G(t=>new Date(e,t.getMonth(),1)),U("days"),ve()},[ve,f]),Se=useCallback(e=>{const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),G(t=>new Date(e+4,t.getMonth(),1)),U("years"),ve()},[ve,f]),Ae=useCallback(e=>{if(de(e.date))return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),X(e.date),e.inMonth||G(new Date(e.date.getFullYear(),e.date.getMonth(),1)),L.reduced||(setNativeValue(re,.7),Animated.spring(re,{toValue:1,damping:Y.motion.spring.bouncy.damping,stiffness:Y.motion.spring.bouncy.stiffness,mass:Y.motion.spring.bouncy.mass,useNativeDriver:!0}).start())},[de,L.reduced,re,Y.motion.spring.bouncy,f]),Ve=useCallback(()=>{k||P(!1),r?.()},[k,r]),Te=useCallback(()=>{"modal"===n?Animated.parallel([Animated.timing(J,{toValue:0,duration:L.duration("default"),easing:Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!1}),Animated.timing(K,{toValue:0,duration:L.duration("fast"),easing:Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!0})]).start(()=>{Ve()}):Ve()},[J,n,Ve,L,K,Y.motion.ease.accelerate]),{handleGesture:Me,opacity:Re}=useDragToDismiss({drag:Q,travel:()=>ee.current||320,onDismiss:Te}),ke=useMemo(()=>Animated.multiply(K,Re),[K,Re]),Ie=useMemo(()=>J.interpolate({inputRange:[0,1],outputRange:[transparentOf(Y.colors.scrim),Y.colors.scrim]}),[J,Y.colors.scrim]);useEffect(()=>{if("modal"===n&&F){J.setValue(0),setNativeValue(K,0),setNativeValue(Q,0),setNativeValue(Re,1);const e=L.reduced?Animated.timing(K,{toValue:1,duration:L.duration("default"),useNativeDriver:!0}):Animated.spring(K,{toValue:1,damping:Y.motion.spring.gentle.damping,stiffness:Y.motion.spring.gentle.stiffness,mass:Y.motion.spring.gentle.mass,useNativeDriver:!0}),t=Animated.parallel([Animated.timing(J,{toValue:1,duration:L.duration("default"),easing:Easing.out(Easing.cubic),useNativeDriver:!1}),e]);return t.start(),()=>t.stop()}},[F,n,J,L,K,Q,Re,Y.motion]);const Pe=useCallback(()=>{!1!==f&&triggerHaptic("selection"),Te()},[Te,f]),Fe=useCallback(()=>{q&&(!1!==f&&triggerHaptic("notificationSuccess"),a?.(q),Te())},[Te,a,q,f]),Ne=K.interpolate({inputRange:[0,1],outputRange:L.range(320,0)}),Ye=_jsx(View,{style:$.titleRow,children:_jsx(Text,{style:$.title,accessibilityRole:"header",children:d})}),Le=_jsxs(View,{style:[$.card,g,y],accessibilityRole:"modal"===n?void 0:"none",accessible:!1,testID:N,children:["modal"===n?_jsx(GestureDetector,{gesture:Me,children:_jsxs(View,{style:$.grabArea,children:[_jsx(View,{style:$.handle}),Ye]})}):Ye,_jsxs(View,{style:$.headerRow,children:[_jsx(Pressable,{onPress:we,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,p],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Previous month":"years"===Z?"Previous years":"Previous decades",hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:$.navText,children:"‹"})}),_jsx(Pressable,{onPress:Ce,style:[$.headerLabelWrap,h],accessibilityRole:"button",accessibilityLabel:"days"===Z?`${pe}, switch to year selection`:"years"===Z?`${pe}, switch to decade selection`:`${pe}, switch to year selection`,hitSlop:8,...hitSlopMarker(8),children:_jsxs(Animated.View,{style:[$.headerLabelInner,{transform:[{scale:oe}],opacity:"days"===Z?ae:1}],children:[_jsx(Animated.Text,{style:[$.headerLabel,{transform:[{translateX:"days"===Z?te:0}]}],accessibilityLiveRegion:"polite",children:pe}),_jsx(View,{style:$.headerCaret,children:(Y.settings.icons.chevronDown??defaultIcons.chevronDown)({size:Y.text.sm.size,color:Y.colors["text-muted"]})})]})}),_jsx(Pressable,{onPress:De,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,p],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Next month":"years"===Z?"Next years":"Next decades",hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:$.navText,children:"›"})})]}),"days"===Z?_jsxs(_Fragment,{children:[_jsx(View,{style:$.weekdayRow,children:ye.map((e,t)=>_jsx(View,{style:$.weekdayCell,children:_jsx(Text,{style:$.weekdayText,children:e})},`${e}-${t}`))}),_jsx(Animated.View,{style:[$.grid,{opacity:ae,transform:[{translateX:te}]}],children:Array.from({length:6}).map((e,t)=>_jsx(View,{style:$.gridRow,children:ue.slice(7*t,7*t+7).map(e=>{const t=de(e.date),a=!!q&&isSameDay(e.date,q),r=isSameDay(e.date,E),s=a?Y.colors.primary:"transparent",i=r&&!a?Y.colors.primary:"transparent",o=a?Y.colors["on-primary"]:e.inMonth?t?Y.colors["text-disabled"]:Y.colors["text-body"]:Y.colors["text-subtle"],n=t?.3:e.inMonth?1:.4;return _jsx(Pressable,{disabled:t,onPress:()=>Ae(e),accessibilityRole:"button",accessibilityLabel:he.format(e.date),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.dayCell,children:_jsx(Animated.View,{style:[$.dayInner,{backgroundColor:s,borderColor:i,borderWidth:r&&!a?1.5:0,opacity:n},a?{transform:[{scale:re}]}:null],children:_jsx(Text,{style:[$.dayText,{color:o}],children:e.date.getDate()})})},e.iso)})},`r-${t}`))})]}):_jsx(Animated.View,"years"===Z?{style:[$.yearGrid,{opacity:se,transform:[{scale:ie}]}],children:Array.from({length:3}).map((e,t)=>_jsx(View,{style:$.gridRow,children:me.slice(4*t,4*t+4).map(e=>{const t=be(e),a=!!q&&q.getFullYear()===e,r=E.getFullYear()===e,s=a?Y.colors.primary:"transparent",i=r&&!a?Y.colors.primary:"transparent",o=a?Y.colors["on-primary"]:t?Y.colors["text-disabled"]:Y.colors["text-body"],n=t?.3:1;return _jsx(Pressable,{disabled:t,onPress:()=>je(e),accessibilityRole:"button",accessibilityLabel:`Year ${e}`,accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.yearCell,children:_jsx(View,{style:[$.yearInner,{backgroundColor:s,borderColor:i,borderWidth:r&&!a?1.5:0,opacity:n}],children:_jsx(Text,{style:[$.yearText,{color:o}],children:e})})},`year-${e}`)})},`yr-${t}`))}:{style:[$.yearGrid,{opacity:se,transform:[{scale:ie}]}],children:Array.from({length:3}).map((e,t)=>_jsx(View,{style:$.gridRow,children:ge.slice(4*t,4*t+4).map(e=>{const t=e+10-1,a=fe(e),r=!!q&&decadeStartFor(q.getFullYear())===e,s=decadeStartFor(E.getFullYear())===e,i=r?Y.colors.primary:"transparent",o=s&&!r?Y.colors.primary:"transparent",n=r?Y.colors["on-primary"]:a?Y.colors["text-disabled"]:Y.colors["text-body"],l=a?.3:1;return _jsx(Pressable,{disabled:a,onPress:()=>Se(e),accessibilityRole:"button",accessibilityLabel:`Decade ${e} to ${t}`,accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:$.yearCell,children:_jsxs(View,{style:[$.yearInner,{backgroundColor:i,borderColor:o,borderWidth:s&&!r?1.5:0,opacity:l}],children:[_jsx(Text,{style:[$.yearText,{color:n}],children:`${e}s`}),_jsx(Text,{style:[$.decadeRangeText,{color:r?Y.colors["on-primary"]:Y.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${t}`))}),_jsxs(View,{style:$.footer,children:[_jsx(Pressable,{onPress:Pe,style:({pressed:e})=>[$.footerBtn,$.footerCancel,e&&$.footerBtnPressed,b],accessibilityRole:"button",accessibilityLabel:m,children:_jsx(Text,{style:[$.footerBtnText,{color:Y.colors["text-muted"]}],children:m})}),_jsx(Pressable,{onPress:Fe,disabled:!q,style:({pressed:e})=>[$.footerBtn,$.footerConfirm,{backgroundColor:Y.colors.primary,opacity:q?1:.5},e&&{backgroundColor:Y.colors["primary-hover"]},b],accessibilityRole:"button",accessibilityLabel:u,accessibilityState:{disabled:!q},"aria-disabled":!q,children:_jsx(Text,{style:[$.footerBtnText,{color:Y.colors["on-primary"]}],children:u})})]})]}),ze=t?(M??(e=>e.toLocaleDateString()))(t):void 0,Be=!k;if("inline"===n)return F||Be?Be?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{label:w,value:ze,placeholder:D,helperText:v,error:C,required:j,disabled:S,size:A,variant:V,clearable:T,onClear:_,onPress:()=>P(!0),triggerStyle:R,testID:x}),F?Le:null]}):Le:null;const $e=_jsx(Modal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Te,children:_jsx(ModalSafeArea,{onInsets:B,children:_jsxs(AnimatedGestureRoot,{collapsable:!1,style:[$.backdrop,{backgroundColor:Ie}],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:Te,accessibilityLabel:"Dismiss"}),_jsx(Animated.View,{style:[$.sheetWrap,{paddingBottom:Math.max(z.bottom,Y.space.lg),opacity:ke,transform:[{translateY:Animated.add(Ne,Q)}]}],onLayout:e=>{ee.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Le}),_jsx(ToastHost,{})]})})});return Be?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{label:w,value:ze,placeholder:D,helperText:v,error:C,required:j,disabled:S,size:A,variant:V,clearable:T,onClear:_,onPress:()=>P(!0),triggerStyle:R,testID:x}),$e]}):$e},buildStyles=e=>{const t=e.shadow.popover;return StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,...smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},weekdayRow:{flexDirection:"row",marginBottom:e.space.xs},weekdayCell:{flex:1,alignItems:"center",paddingVertical:e.space.xs},weekdayText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,color:e.colors["text-subtle"],letterSpacing:e["letter-spacing"].wide},grid:{},gridRow:{flexDirection:"row"},dayCell:{flex:1,aspectRatio:1,alignItems:"center",justifyContent:"center",padding:e.space.xxs},dayInner:{width:"100%",height:"100%",borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},dayText:{fontSize:e.text.sm.size,fontWeight:e.weight.medium},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,...smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold}})};export{DatePicker};export default DatePicker;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Easing,Modal,Pressable,StyleSheet,Text,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{transparentOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{PickerTrigger}from"../PickerTrigger/index.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const NAV_BUTTON_SIZE=36,AnimatedGestureRoot=Animated.createAnimatedComponent(GestureHandlerRootView),GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),isSameDay=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),toIso=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,addMonths=(e,t)=>new Date(e.getFullYear(),e.getMonth()+t,1),buildMonthMatrix=(e,t)=>{const a=e.getFullYear(),r=e.getMonth(),s=(new Date(a,r,1).getDay()-t+7)%7,i=[];for(let e=0;e<42;e+=1){const t=new Date(a,r,1-s+e);i.push({date:t,inMonth:t.getMonth()===r,iso:toIso(t)})}return i},weekdayLabels=(e,t)=>{const a=new Intl.DateTimeFormat(e,{weekday:"short"}),r=[];for(let e=0;e<7;e+=1){const s=new Date(1970,0,4+(t+e)%7);r.push(a.format(s))}return r},formatMonthYear=(e,t)=>new Intl.DateTimeFormat(t,{month:"long",year:"numeric"}).format(e),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:s,maxDate:i,disabledDates:o,mode:n="modal",locale:l="en-IN",weekStartsOn:c=0,title:d="Select Date",confirmLabel:u="Confirm",cancelLabel:m="Cancel",style:g,containerStyle:y,headerLabelStyle:h,navButtonStyle:p,footerButtonStyle:b,haptic:f,testID:x,label:w,placeholder:D,helperText:v,error:C,required:j,disabled:S,size:A,variant:V,clearable:T,onClear:_,formatValue:M,triggerStyle:R}=e,k=void 0!==e.visible,[I,P]=useState(!1),F=k?e.visible:I,N=k?x:x?`${x}-calendar`:void 0,Y=useTheme(),L=usePresenceMotion(),[z,B]=useModalInsets(),$=useMemo(()=>buildStyles(Y),[Y]),[E,H]=useState(()=>startOfDay(new Date));useEffect(()=>{F&&H(startOfDay(new Date))},[F]);const O=t?startOfDay(t):E,[W,G]=useState(O),[q,X]=useState(t?startOfDay(t):null),[Z,U]=useState("days"),J=useRef(createAnimatedValue(0)).current,K=useRef(createAnimatedValue(0)).current,Q=useRef(createAnimatedValue(0)).current,ee=useRef(0),te=useRef(createAnimatedValue(0)).current,ae=useRef(createAnimatedValue(1)).current,re=useRef(createAnimatedValue(1)).current,se=useRef(createAnimatedValue(1)).current,ie=useRef(createAnimatedValue(1)).current,oe=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(t){const e=startOfDay(t);X(e),G(e)}else X(null)},[t]);const ne=useMemo(()=>{const e=new Set;return o?.forEach(t=>{e.add(toIso(startOfDay(t)))}),e},[o]),le=useMemo(()=>s?startOfDay(s):null,[s]),ce=useMemo(()=>i?startOfDay(i):null,[i]),de=useCallback(e=>!!(le&&e.getTime()<le.getTime())||(!!(ce&&e.getTime()>ce.getTime())||!!ne.has(toIso(e))),[le,ce,ne]),ue=useMemo(()=>buildMonthMatrix(W,c),[W,c]),me=useMemo(()=>buildYearCells(W.getFullYear()),[W]),ge=useMemo(()=>buildDecadeCells(W.getFullYear()),[W]),ye=useMemo(()=>weekdayLabels(l,c),[l,c]),he=useMemo(()=>new Intl.DateTimeFormat(l,{weekday:"long",year:"numeric",month:"long",day:"numeric"}),[l]),pe=useMemo(()=>{if("days"===Z)return formatMonthYear(W,l);if("years"===Z){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[W,ge,l,Z,me]),be=useCallback(e=>!!(le&&e<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),fe=useCallback(e=>!!(le&&e+10-1<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),xe=useCallback(e=>{!1!==f&&triggerHaptic("impactLight");const t=e>0?1:-1,a=Y.motion.duration.fast,r=Y.motion.duration.fast,[s]=L.range(32*-t,0),[i]=L.range(32*t,0),o=L.reduced?L.duration("fast"):a,n=L.reduced?L.duration("fast"):r;Animated.sequence([Animated.parallel([Animated.timing(te,{toValue:s,duration:a,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(ae,{toValue:0,duration:o,useNativeDriver:!0})]),Animated.timing(te,{toValue:i,duration:0,useNativeDriver:!0}),Animated.parallel([Animated.timing(te,{toValue:0,duration:r,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ae,{toValue:1,duration:n,useNativeDriver:!0})])]).start();const c=addMonths(W,e);G(c),AccessibilityInfo.announceForAccessibility(formatMonthYear(c,l))},[W,f,l,ae,te,L,Y.motion.duration.fast]),we=useCallback(()=>{"days"!==Z?(!1!==f&&triggerHaptic("impactLight"),G("years"===Z?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))):xe(-1)},[xe,Z,f]),De=useCallback(()=>{"days"!==Z?(!1!==f&&triggerHaptic("impactLight"),G("years"===Z?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))):xe(1)},[xe,Z,f]),ve=useCallback(()=>{const[e]=L.range(.9,1),t=L.reduced?L.duration("default"):Y.motion.duration.default;setNativeValue(se,0),setNativeValue(ie,e),Animated.parallel([Animated.timing(se,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0}),Animated.timing(ie,{toValue:1,duration:t,easing:Easing.out(Easing.cubic),useNativeDriver:!0})]).start()},[se,ie,L,Y.motion.duration.default]),Ce=useCallback(()=>{const e=resolveHaptic(f,"selection");if(e&&triggerHaptic(e),!L.reduced){const e=80,t=100;Animated.sequence([Animated.timing(oe,{toValue:.96,duration:e,useNativeDriver:!0}),Animated.timing(oe,{toValue:1,duration:t,useNativeDriver:!0})]).start()}U(e=>"days"===e?"years":"years"===e?"decades":"years"),ve()},[ve,oe,f,L.reduced]),je=useCallback(e=>{const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),G(t=>new Date(e,t.getMonth(),1)),U("days"),ve()},[ve,f]),Se=useCallback(e=>{const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),G(t=>new Date(e+4,t.getMonth(),1)),U("years"),ve()},[ve,f]),Ae=useCallback(e=>{if(de(e.date))return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),X(e.date),e.inMonth||G(new Date(e.date.getFullYear(),e.date.getMonth(),1)),L.reduced||(setNativeValue(re,.7),Animated.spring(re,{toValue:1,damping:Y.motion.spring.bouncy.damping,stiffness:Y.motion.spring.bouncy.stiffness,mass:Y.motion.spring.bouncy.mass,useNativeDriver:!0}).start())},[de,L.reduced,re,Y.motion.spring.bouncy,f]),Ve=useCallback(()=>{k||P(!1),r?.()},[k,r]),Te=useCallback(()=>{"modal"===n?Animated.parallel([Animated.timing(J,{toValue:0,duration:L.duration("default"),easing:Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!1}),Animated.timing(K,{toValue:0,duration:L.duration("fast"),easing:Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!0})]).start(()=>{Ve()}):Ve()},[J,n,Ve,L,K,Y.motion.ease.accelerate]),{handleGesture:Me,opacity:Re}=useDragToDismiss({drag:Q,travel:()=>ee.current||320,onDismiss:Te}),ke=useMemo(()=>Animated.multiply(K,Re),[K,Re]),Ie=useMemo(()=>J.interpolate({inputRange:[0,1],outputRange:[transparentOf(Y.colors.scrim),Y.colors.scrim]}),[J,Y.colors.scrim]);useEffect(()=>{if("modal"===n&&F){J.setValue(0),setNativeValue(K,0),setNativeValue(Q,0),setNativeValue(Re,1);const e=L.reduced?Animated.timing(K,{toValue:1,duration:L.duration("default"),useNativeDriver:!0}):Animated.spring(K,{toValue:1,damping:Y.motion.spring.gentle.damping,stiffness:Y.motion.spring.gentle.stiffness,mass:Y.motion.spring.gentle.mass,useNativeDriver:!0}),t=Animated.parallel([Animated.timing(J,{toValue:1,duration:L.duration("default"),easing:Easing.out(Easing.cubic),useNativeDriver:!1}),e]);return t.start(),()=>t.stop()}},[F,n,J,L,K,Q,Re,Y.motion]);const Pe=useCallback(()=>{!1!==f&&triggerHaptic("selection"),Te()},[Te,f]),Fe=useCallback(()=>{q&&(!1!==f&&triggerHaptic("notificationSuccess"),a?.(q),Te())},[Te,a,q,f]),Ne=K.interpolate({inputRange:[0,1],outputRange:L.range(320,0)}),Ye=_jsx(View,{style:$.titleRow,children:_jsx(Text,{style:$.title,accessibilityRole:"header",children:d})}),Le=_jsxs(View,{style:[$.card,g,y],accessibilityRole:"modal"===n?void 0:"none",accessible:!1,testID:N,children:["modal"===n?_jsx(GestureDetector,{gesture:Me,children:_jsxs(View,{style:$.grabArea,children:[_jsx(View,{style:$.handle}),Ye]})}):Ye,_jsxs(View,{style:$.headerRow,children:[_jsx(Pressable,{onPress:we,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,p],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Previous month":"years"===Z?"Previous years":"Previous decades",hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:$.navText,children:"‹"})}),_jsx(Pressable,{onPress:Ce,style:[$.headerLabelWrap,h],accessibilityRole:"button",accessibilityLabel:"days"===Z?`${pe}, switch to year selection`:"years"===Z?`${pe}, switch to decade selection`:`${pe}, switch to year selection`,hitSlop:8,...hitSlopMarker(8),children:_jsxs(Animated.View,{style:[$.headerLabelInner,{transform:[{scale:oe}],opacity:"days"===Z?ae:1}],children:[_jsx(Animated.Text,{style:[$.headerLabel,{transform:[{translateX:"days"===Z?te:0}]}],accessibilityLiveRegion:"polite",children:pe}),_jsx(View,{style:$.headerCaret,children:(Y.settings.icons.chevronDown??defaultIcons.chevronDown)({size:Y.text.sm.size,color:Y.colors["text-muted"]})})]})}),_jsx(Pressable,{onPress:De,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,p],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Next month":"years"===Z?"Next years":"Next decades",hitSlop:8,...hitSlopMarker(8),children:_jsx(Text,{style:$.navText,children:"›"})})]}),"days"===Z?_jsxs(_Fragment,{children:[_jsx(View,{style:$.weekdayRow,children:ye.map((e,t)=>_jsx(View,{style:$.weekdayCell,children:_jsx(Text,{style:$.weekdayText,children:e})},`${e}-${t}`))}),_jsx(Animated.View,{style:[$.grid,{opacity:ae,transform:[{translateX:te}]}],children:Array.from({length:6}).map((e,t)=>_jsx(View,{style:$.gridRow,children:ue.slice(7*t,7*t+7).map(e=>{const t=de(e.date),a=!!q&&isSameDay(e.date,q),r=isSameDay(e.date,E),s=a?Y.colors.primary:"transparent",i=r&&!a?Y.colors.primary:"transparent",o=a?Y.colors["on-primary"]:e.inMonth?t?Y.colors["text-disabled"]:Y.colors["text-body"]:Y.colors["text-subtle"],n=t?.3:e.inMonth?1:.4;return _jsx(Pressable,{disabled:t,onPress:()=>Ae(e),accessibilityRole:"button",accessibilityLabel:he.format(e.date),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.dayCell,children:_jsx(Animated.View,{style:[$.dayInner,{backgroundColor:s,borderColor:i,borderWidth:r&&!a?1.5:0,opacity:n},a?{transform:[{scale:re}]}:null],children:_jsx(Text,{style:[$.dayText,{color:o}],children:e.date.getDate()})})},e.iso)})},`r-${t}`))})]}):_jsx(Animated.View,"years"===Z?{style:[$.yearGrid,{opacity:se,transform:[{scale:ie}]}],children:Array.from({length:3}).map((e,t)=>_jsx(View,{style:$.gridRow,children:me.slice(4*t,4*t+4).map(e=>{const t=be(e),a=!!q&&q.getFullYear()===e,r=E.getFullYear()===e,s=a?Y.colors.primary:"transparent",i=r&&!a?Y.colors.primary:"transparent",o=a?Y.colors["on-primary"]:t?Y.colors["text-disabled"]:Y.colors["text-body"],n=t?.3:1;return _jsx(Pressable,{disabled:t,onPress:()=>je(e),accessibilityRole:"button",accessibilityLabel:`Year ${e}`,accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.yearCell,children:_jsx(View,{style:[$.yearInner,{backgroundColor:s,borderColor:i,borderWidth:r&&!a?1.5:0,opacity:n}],children:_jsx(Text,{style:[$.yearText,{color:o}],children:e})})},`year-${e}`)})},`yr-${t}`))}:{style:[$.yearGrid,{opacity:se,transform:[{scale:ie}]}],children:Array.from({length:3}).map((e,t)=>_jsx(View,{style:$.gridRow,children:ge.slice(4*t,4*t+4).map(e=>{const t=e+10-1,a=fe(e),r=!!q&&decadeStartFor(q.getFullYear())===e,s=decadeStartFor(E.getFullYear())===e,i=r?Y.colors.primary:"transparent",o=s&&!r?Y.colors.primary:"transparent",n=r?Y.colors["on-primary"]:a?Y.colors["text-disabled"]:Y.colors["text-body"],l=a?.3:1;return _jsx(Pressable,{disabled:a,onPress:()=>Se(e),accessibilityRole:"button",accessibilityLabel:`Decade ${e} to ${t}`,accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:$.yearCell,children:_jsxs(View,{style:[$.yearInner,{backgroundColor:i,borderColor:o,borderWidth:s&&!r?1.5:0,opacity:l}],children:[_jsx(Text,{style:[$.yearText,{color:n}],children:`${e}s`}),_jsx(Text,{style:[$.decadeRangeText,{color:r?Y.colors["on-primary"]:Y.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${t}`))}),_jsxs(View,{style:$.footer,children:[_jsx(Pressable,{onPress:Pe,style:({pressed:e})=>[$.footerBtn,$.footerCancel,e&&$.footerBtnPressed,b],accessibilityRole:"button",accessibilityLabel:m,children:_jsx(Text,{style:[$.footerBtnText,{color:Y.colors["text-muted"]}],children:m})}),_jsx(Pressable,{onPress:Fe,disabled:!q,style:({pressed:e})=>[$.footerBtn,$.footerConfirm,{backgroundColor:Y.colors.primary,opacity:q?1:.5},e&&{backgroundColor:Y.colors["primary-hover"]},b],accessibilityRole:"button",accessibilityLabel:u,accessibilityState:{disabled:!q},"aria-disabled":!q,children:_jsx(Text,{style:[$.footerBtnText,{color:Y.colors["on-primary"]}],children:u})})]})]}),ze=t?(M??(e=>e.toLocaleDateString()))(t):void 0,Be=!k;if("inline"===n)return F||Be?Be?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{label:w,value:ze,placeholder:D,helperText:v,error:C,required:j,disabled:S,size:A,variant:V,clearable:T,onClear:_,onPress:()=>P(!0),triggerStyle:R,testID:x}),F?Le:null]}):Le:null;const $e=_jsx(Modal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Te,children:_jsx(ModalSafeArea,{onInsets:B,children:_jsxs(AnimatedGestureRoot,{collapsable:!1,style:[$.backdrop,{backgroundColor:Ie}],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:Te,accessibilityLabel:"Dismiss"}),_jsx(Animated.View,{style:[$.sheetWrap,{paddingBottom:Math.max(z.bottom,Y.space.lg),opacity:ke,transform:[{translateY:Animated.add(Ne,Q)}]}],onLayout:e=>{ee.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Le}),_jsx(ToastHost,{})]})})});return Be?_jsxs(_Fragment,{children:[_jsx(PickerTrigger,{label:w,value:ze,placeholder:D,helperText:v,error:C,required:j,disabled:S,size:A,variant:V,clearable:T,onClear:_,onPress:()=>P(!0),triggerStyle:R,testID:x}),$e]}):$e},buildStyles=e=>{const t=e.shadow.popover;return StyleSheet.create({backdrop:{...StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,...smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},weekdayRow:{flexDirection:"row",marginBottom:e.space.xs},weekdayCell:{flex:1,alignItems:"center",paddingVertical:e.space.xs},weekdayText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,color:e.colors["text-subtle"],letterSpacing:e["letter-spacing"].wide},grid:{},gridRow:{flexDirection:"row"},dayCell:{flex:1,aspectRatio:1,alignItems:"center",justifyContent:"center",padding:e.space.xxs},dayInner:{width:"100%",height:"100%",borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},dayText:{fontSize:e.text.sm.size,fontWeight:e.weight.medium},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,...smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,...smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold}})};export{DatePicker};export default DatePicker;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useImperativeHandle,useMemo,useRef,useState}from"react";import{Image,Pressable,ScrollView,StyleSheet,Text,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{hasFieldText}from"../FieldBase/index.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";let fileIdSeq=0;const nextFileId=()=>"wfp-"+ ++fileIdSeq,DEFAULT_LABELS={trigger:"Attach file",addMore:"Add more",sheetTitle:"Add from",removeFile:e=>`Remove ${e}`,retry:"Retry upload",errorTooMany:e=>`You can attach up to ${e} files.`,errorTooLarge:(e,t)=>`${e} is larger than ${t} MB.`,errorWrongType:e=>`${e} is not an accepted file type.`};export const formatFileSize=e=>{if(void 0===e||e<=0)return"";const t=["B","KB","MB","GB"];let r=e,s=0;for(;r>=1024&&s<t.length-1;)r/=1024,s+=1;return`${r>=10||0===s?Math.round(r):Math.round(10*r)/10} ${t[s]}`};export const matchesAccept=(e,t)=>!t||0===t.length||!!e&&t.some(t=>"*/*"===t||"*"===t||(t.endsWith("/*")?e.startsWith(t.slice(0,t.length-1)):e===t));const isImage=e=>!0===e.type?.startsWith("image/")||!e.type&&/\.(png|jpe?g|gif|webp|heic)$/i.test(e.name),imageSourceOf=e=>e.thumbnailUrl??(isImage(e)?e.uri??e.url:void 0),extensionOf=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"FILE":e.slice(t+1).toUpperCase().slice(0,4)},FilePicker=forwardRef((e,t)=>{const{files:r,defaultFiles:s,onChange:i,sources:o,maxFiles:l,maxSizeMB:n,accept:a,validate:c,process:d,variant:u="card",renderFile:h,renderTrigger:g,disabled:m=!1,helperText:p,error:x,labels:b,haptic:f,onPick:y,onRemove:T,onError:S,onFilePress:j,onRetry:C,style:w,accessibilityLabel:F,testID:_}=e,v=useTheme(),z=useMemo(()=>buildStyles(v),[v]),P=useMemo(()=>({...DEFAULT_LABELS,...b}),[b]),k=v.radius.md,R=v.colors.primary,[I,V]=useControllableState({value:r,defaultValue:s??[],onChange:i}),M=useRef(I);M.current=I;const O=useCallback(e=>{M.current=e,V(e)},[V]),[B,L]=useState(null),[H,$]=useState(!1),A=x??B??void 0,E="number"==typeof l&&I.length>=l,W=useCallback((e,t)=>{0!==e.length&&(L(e[0]),e.forEach(e=>S?.(e,t)),!1!==f&&triggerHaptic("notificationError"))},[S,f]),D=useCallback(async e=>{let t;try{t=await e.pick()}catch(e){return void W([e instanceof Error?e.message:String(e)])}if(!t||0===t.length)return;const r=[];let s=t.map(e=>({id:nextFileId(),name:e.name??e.uri.split("/").pop()??"file",uri:e.uri,type:e.type,size:e.size,meta:e.meta,status:"idle"}));if("number"==typeof l){const e=Math.max(0,l-M.current.length);s.length>e&&(r.push(P.errorTooMany(l)),s=s.slice(0,e))}const i=[];for(const e of s){if("number"==typeof n&&"number"==typeof e.size&&e.size>1024*n*1024){r.push(P.errorTooLarge(e.name,n));continue}if(!matchesAccept(e.type,a)){r.push(P.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):i.push(e)}if(W(r),0===i.length)return;if(!d){O([...M.current,...i]),L(r.length>0?r[0]:null);const e=resolveHaptic(f,"selection");return e&&triggerHaptic(e),void y?.(i)}const o=i.map(e=>({...e,status:"processing"}));O([...M.current,...o]);const u=[];for(const e of o)try{const t=await d({...e,status:"idle"}),r={...t,id:e.id,status:t.status??"idle"};O(M.current.map(t=>t.id===e.id?r:t)),u.push(r)}catch(t){O(M.current.filter(t=>t.id!==e.id)),W([t instanceof Error?t.message:String(t)],e)}if(u.length>0){0===r.length&&L(null);const e=resolveHaptic(f,"selection");e&&triggerHaptic(e),y?.(u)}},[l,n,a,c,d,P,W,O,y,f]),U=useCallback(e=>{if(m||E)return;const t=e?o.find(t=>t.key===e):1===o.length?o[0]:void 0;t?D(t):o.length>1&&$(!0)},[m,E,o,D]),G=useCallback(e=>{if(m)return;O(M.current.filter(t=>t.id!==e.id)),L(null);const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),T?.(e)},[m,O,T,f]),N=useCallback(()=>{O([]),L(null)},[O]);useImperativeHandle(t,()=>({open:U,clear:N}),[U,N]);const q=0===I.length?P.trigger:`${I.length} file${1===I.length?"":"s"} attached`,K=F??`Attachments. ${q}`,statusText=e=>{switch(e.status){case"processing":return"Processing…";case"uploading":return`Uploading ${Math.round(100*(e.progress??0))}%`;case"done":return"Uploaded";case"error":return e.error??"Failed";default:return""}},fileA11yLabel=e=>[e.name,formatFileSize(e.size),statusText(e)].filter(Boolean).join(", "),Y=v.settings.icons.attachment??defaultIcons.attachment,renderStatusOverlay=e=>{if("processing"===e.status)return _jsx(View,{style:[z.tileOverlay,{backgroundColor:v.colors.scrim}],children:_jsx(Spinner,{size:"sm"})});if("uploading"===e.status){const t=Math.round(100*(e.progress??0));return _jsxs(View,{style:[z.tileOverlay,{backgroundColor:v.colors.scrim}],children:[_jsx(Text,{style:[z.tileOverlayText,{color:v.colors["on-scrim"]}],children:`${t}%`}),_jsx(View,{style:[z.tileProgressTrack,{backgroundColor:v.colors.border}],children:_jsx(View,{style:[z.tileProgressFill,{width:`${t}%`,backgroundColor:v.colors.primary}]})})]})}return"done"===e.status?_jsx(View,{style:[z.doneBadge,{backgroundColor:v.colors.success}],children:_jsx(Text,{style:[z.doneBadgeText,{color:v.colors["on-success"]}],children:"✓"})}):null},renderThumbnail=e=>{const t=imageSourceOf(e);return t?_jsx(Image,{source:{uri:t},style:z.thumbnailImage}):_jsx(View,{style:[z.extensionTile,{backgroundColor:v.colors["bg-subtle"]}],children:_jsx(Text,{style:[z.extensionText,{color:v.colors["text-muted"],...fontFor(v,"semibold")}],children:extensionOf(e.name)})})},removeButton=e=>_jsx(Pressable,{onPress:()=>G(e),disabled:m,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:P.removeFile(e.name),style:[z.removeButton,{backgroundColor:v.colors.scrim}],children:_jsx(Text,{style:[z.removeButtonText,{color:v.colors["on-scrim"]}],children:"×"})}),retryButton=e=>C&&"error"===e.status?_jsx(Pressable,{onPress:()=>C(e),disabled:m,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:P.retry,children:_jsx(Text,{style:[z.retryText,{color:v.colors.primary}],children:"↻"})}):null,renderOneFile=(e,t)=>{const r={file:e,index:t,disabled:m,remove:()=>G(e),retry:C?()=>C(e):void 0},s=h?h(r):"card"===u?(e=>{const{file:t}=e;return _jsxs(View,{style:[z.tile,{width:84,height:84,borderRadius:k,...smoothCorners,borderColor:"error"===t.status?v.colors.danger:v.colors.border}],children:[renderThumbnail(t),renderStatusOverlay(t),"error"===t.status?_jsx(View,{style:[z.tileOverlay,{backgroundColor:v.colors.scrim}],children:retryButton(t)}):null,removeButton(t)]})})(r):(e=>{const{file:t}=e,r=statusText(t);return _jsxs(View,{style:[z.listRow,{borderRadius:k,...smoothCorners,borderColor:"error"===t.status?v.colors.danger:v.colors.border,backgroundColor:v.colors.bg}],children:[_jsxs(View,{style:[z.listThumb,{borderRadius:v.radius.sm,...smoothCorners}],children:[renderThumbnail(t),"processing"===t.status?_jsx(View,{style:[z.tileOverlay,{backgroundColor:v.colors.scrim}],children:_jsx(Spinner,{size:"sm"})}):null]}),_jsxs(View,{style:z.listTextWrap,children:[_jsx(Text,{numberOfLines:1,ellipsizeMode:"middle",style:[z.listName,{color:v.colors["text-body"],fontSize:v.text.sm.size,...fontFor(v,"medium")}],children:t.name}),_jsx(Text,{numberOfLines:1,style:[z.listSubtitle,{color:"error"===t.status?v.colors["danger-text"]:v.colors["text-subtle"],fontSize:v.text.xs.size}],children:[formatFileSize(t.size),r].filter(Boolean).join(" · ")}),"uploading"===t.status?_jsx(View,{style:[z.listProgressTrack,{backgroundColor:v.colors.border}],children:_jsx(View,{style:[z.listProgressFill,{width:`${Math.round(100*(t.progress??0))}%`,backgroundColor:v.colors.primary}]})}):null]}),retryButton(t),_jsx(Pressable,{onPress:()=>G(t),disabled:m,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:P.removeFile(t.name),children:_jsx(Text,{style:[z.listRemoveText,{color:v.colors["text-subtle"]}],children:"×"})})]})})(r);return _jsx(Pressable,{onPress:j?()=>j(e):void 0,disabled:m||!j,accessibilityLabel:fileA11yLabel(e),children:s},e.id)},J={open:U,disabled:m||E,fileCount:I.length,atCapacity:E},dashedTrigger=e=>_jsxs(Pressable,{onPress:()=>U(),disabled:m||E,accessibilityRole:"button",accessibilityLabel:K,accessibilityState:{disabled:m||E},"aria-disabled":m||E,style:({pressed:t})=>[z.trigger,e?z.triggerCompact:null,{borderRadius:k,...smoothCorners,borderColor:R,backgroundColor:t?v.colors["surface-pressed"]:v.colors.bg,opacity:m||E?.55:1}],children:[_jsxs(View,{style:z.triggerRow,children:[Y?Y({size:16,color:v.colors.primary}):null,_jsx(Text,{style:[z.triggerText,{color:v.colors.primary,fontSize:v.text.sm.size,...fontFor(v,"medium")}],children:0===I.length?P.trigger:P.addMore})]}),!e&&p?_jsx(Text,{style:[z.helperText,{color:v.colors["text-subtle"],fontSize:v.text.xs.size}],children:p}):null]}),Q=_jsx(Pressable,{onPress:()=>U(),disabled:m||E,accessibilityRole:"button",accessibilityLabel:P.addMore,style:({pressed:e})=>[z.tile,z.addTile,{width:84,height:84,borderRadius:k,...smoothCorners,borderColor:R,backgroundColor:e?v.colors["surface-pressed"]:"transparent",opacity:m||E?.55:1}],children:_jsx(Text,{style:[z.addTileText,{color:v.colors.primary}],children:"+"})});return _jsxs(View,{style:[z.container,w],testID:_,accessibilityLabel:K,children:["card"===u?0===I.length?g?g(J):dashedTrigger(!1):_jsxs(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[z.strip,{columnGap:v.space.sm}],children:[I.map(renderOneFile),g?g(J):E||m?null:Q]}):_jsxs(View,{style:{rowGap:v.space.sm},children:[g?g(J):E?null:dashedTrigger(I.length>0),I.map(renderOneFile)]}),hasFieldText(A)?_jsx(Text,{accessibilityLiveRegion:"polite",style:[z.errorText,{color:v.colors["danger-text"],fontSize:v.text.xs.size,marginTop:v.space.xxs}],children:A}):null,_jsx(OptionSheet,{open:H,onClose:()=>$(!1),title:P.sheetTitle,options:o,labelOf:e=>e.label,getValue:e=>e.key,disabledOf:()=>!1,descriptionOf:e=>e.description,iconOf:e=>e.icon,isSelected:()=>!1,onSelect:e=>{$(!1),D(e)}})]})});FilePicker.displayName="FilePicker";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},trigger:{borderWidth:1,borderStyle:"dashed",alignItems:"center",minHeight:48,paddingVertical:e.space.md,paddingHorizontal:e.space.lg},triggerCompact:{minHeight:40,paddingVertical:e.space.sm},triggerRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},triggerText:{includeFontPadding:!1},helperText:{includeFontPadding:!1,marginTop:e.space.xs,textAlign:"center"},strip:{paddingVertical:e.space.xxs},tile:{borderWidth:1,overflow:"hidden"},addTile:{borderStyle:"dashed",alignItems:"center",justifyContent:"center"},addTileText:{fontSize:e.text["3xl"].size,includeFontPadding:!1},thumbnailImage:{width:"100%",height:"100%",resizeMode:"cover"},extensionTile:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"},extensionText:{fontSize:e.text.sm.size,letterSpacing:1,includeFontPadding:!1},tileOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},tileOverlayText:{fontSize:e.text.sm.size,includeFontPadding:!1,marginBottom:e.space.xs},tileProgressTrack:{position:"absolute",left:8,right:8,bottom:8,height:3,borderRadius:e.radius.pill,...smoothCorners,overflow:"hidden"},tileProgressFill:{height:"100%",borderRadius:e.radius.pill,...smoothCorners},doneBadge:{position:"absolute",right:4,bottom:4,width:18,height:18,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},doneBadgeText:{fontSize:e.text.xs.size,includeFontPadding:!1},removeButton:{position:"absolute",top:4,right:4,width:20,height:20,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},removeButtonText:{fontSize:e.text.sm.size,lineHeight:15,includeFontPadding:!1},retryText:{fontSize:e.text.xl.size,includeFontPadding:!1},listRow:{flexDirection:"row",alignItems:"center",borderWidth:1,padding:e.space.sm,columnGap:e.space.sm},listThumb:{width:40,height:40,overflow:"hidden"},listTextWrap:{flex:1},listName:{includeFontPadding:!1},listSubtitle:{includeFontPadding:!1,marginTop:e.space.xxs},listProgressTrack:{height:3,borderRadius:e.radius.pill,...smoothCorners,overflow:"hidden",marginTop:e.space.xs},listProgressFill:{height:"100%",borderRadius:e.radius.pill,...smoothCorners},listRemoveText:{fontSize:e.text["2xl"].size,includeFontPadding:!1,paddingHorizontal:e.space.xs},errorText:{includeFontPadding:!1}});export{FilePicker};export default FilePicker;
1
+ "use strict";import{forwardRef,useCallback,useImperativeHandle,useMemo,useRef,useState}from"react";import{Image,Pressable,ScrollView,StyleSheet,Text,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{hasFieldText}from"../FieldBase/index.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";let fileIdSeq=0;const nextFileId=()=>"wfp-"+ ++fileIdSeq,DEFAULT_LABELS={trigger:"Attach file",addMore:"Add more",sheetTitle:"Add from",removeFile:e=>`Remove ${e}`,retry:"Retry upload",errorTooMany:e=>`You can attach up to ${e} files.`,errorTooLarge:(e,t)=>`${e} is larger than ${t} MB.`,errorWrongType:e=>`${e} is not an accepted file type.`};export const formatFileSize=e=>{if(void 0===e||e<=0)return"";const t=["B","KB","MB","GB"];let r=e,s=0;for(;r>=1024&&s<t.length-1;)r/=1024,s+=1;return`${r>=10||0===s?Math.round(r):Math.round(10*r)/10} ${t[s]}`};export const matchesAccept=(e,t)=>!t||0===t.length||!!e&&t.some(t=>"*/*"===t||"*"===t||(t.endsWith("/*")?e.startsWith(t.slice(0,t.length-1)):e===t));const isImage=e=>!0===e.type?.startsWith("image/")||!e.type&&/\.(png|jpe?g|gif|webp|heic)$/i.test(e.name),imageSourceOf=e=>e.thumbnailUrl??(isImage(e)?e.uri??e.url:void 0),extensionOf=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"FILE":e.slice(t+1).toUpperCase().slice(0,4)},FilePicker=forwardRef((e,t)=>{const{files:r,defaultFiles:s,onChange:i,sources:o,maxFiles:l,maxSizeMB:n,accept:a,validate:c,process:d,variant:u="card",renderFile:h,renderTrigger:g,disabled:m=!1,helperText:p,error:x,labels:b,haptic:f,onPick:y,onRemove:T,onError:S,onFilePress:j,onRetry:C,style:w,accessibilityLabel:F,testID:_}=e,v=useTheme(),z=useMemo(()=>buildStyles(v),[v]),P=useMemo(()=>({...DEFAULT_LABELS,...b}),[b]),k=v.radius.md,R=v.colors.primary,[I,V]=useControllableState({value:r,defaultValue:s??[],onChange:i}),M=useRef(I);M.current=I;const O=useCallback(e=>{M.current=e,V(e)},[V]),[B,L]=useState(null),[H,$]=useState(!1),A=x??B??void 0,E="number"==typeof l&&I.length>=l,W=useCallback((e,t)=>{0!==e.length&&(L(e[0]),e.forEach(e=>{S?.(e,t)}),!1!==f&&triggerHaptic("notificationError"))},[S,f]),D=useCallback(async e=>{let t;try{t=await e.pick()}catch(e){return void W([e instanceof Error?e.message:String(e)])}if(!t||0===t.length)return;const r=[];let s=t.map(e=>({id:nextFileId(),name:e.name??e.uri.split("/").pop()??"file",uri:e.uri,type:e.type,size:e.size,meta:e.meta,status:"idle"}));if("number"==typeof l){const e=Math.max(0,l-M.current.length);s.length>e&&(r.push(P.errorTooMany(l)),s=s.slice(0,e))}const i=[];for(const e of s){if("number"==typeof n&&"number"==typeof e.size&&e.size>1024*n*1024){r.push(P.errorTooLarge(e.name,n));continue}if(!matchesAccept(e.type,a)){r.push(P.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):i.push(e)}if(W(r),0===i.length)return;if(!d){O([...M.current,...i]),L(r.length>0?r[0]:null);const e=resolveHaptic(f,"selection");return e&&triggerHaptic(e),void y?.(i)}const o=i.map(e=>({...e,status:"processing"}));O([...M.current,...o]);const u=[];for(const e of o)try{const t=await d({...e,status:"idle"}),r={...t,id:e.id,status:t.status??"idle"};O(M.current.map(t=>t.id===e.id?r:t)),u.push(r)}catch(t){O(M.current.filter(t=>t.id!==e.id)),W([t instanceof Error?t.message:String(t)],e)}if(u.length>0){0===r.length&&L(null);const e=resolveHaptic(f,"selection");e&&triggerHaptic(e),y?.(u)}},[l,n,a,c,d,P,W,O,y,f]),U=useCallback(e=>{if(m||E)return;const t=e?o.find(t=>t.key===e):1===o.length?o[0]:void 0;t?D(t):o.length>1&&$(!0)},[m,E,o,D]),G=useCallback(e=>{if(m)return;O(M.current.filter(t=>t.id!==e.id)),L(null);const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),T?.(e)},[m,O,T,f]),N=useCallback(()=>{O([]),L(null)},[O]);useImperativeHandle(t,()=>({open:U,clear:N}),[U,N]);const q=0===I.length?P.trigger:`${I.length} file${1===I.length?"":"s"} attached`,K=F??`Attachments. ${q}`,statusText=e=>{switch(e.status){case"processing":return"Processing…";case"uploading":return`Uploading ${Math.round(100*(e.progress??0))}%`;case"done":return"Uploaded";case"error":return e.error??"Failed";default:return""}},fileA11yLabel=e=>[e.name,formatFileSize(e.size),statusText(e)].filter(Boolean).join(", "),Y=v.settings.icons.attachment??defaultIcons.attachment,renderStatusOverlay=e=>{if("processing"===e.status)return _jsx(View,{style:[z.tileOverlay,{backgroundColor:v.colors.scrim}],children:_jsx(Spinner,{size:"sm"})});if("uploading"===e.status){const t=Math.round(100*(e.progress??0));return _jsxs(View,{style:[z.tileOverlay,{backgroundColor:v.colors.scrim}],children:[_jsx(Text,{style:[z.tileOverlayText,{color:v.colors["on-scrim"]}],children:`${t}%`}),_jsx(View,{style:[z.tileProgressTrack,{backgroundColor:v.colors.border}],children:_jsx(View,{style:[z.tileProgressFill,{width:`${t}%`,backgroundColor:v.colors.primary}]})})]})}return"done"===e.status?_jsx(View,{style:[z.doneBadge,{backgroundColor:v.colors.success}],children:_jsx(Text,{style:[z.doneBadgeText,{color:v.colors["on-success"]}],children:"✓"})}):null},renderThumbnail=e=>{const t=imageSourceOf(e);return t?_jsx(Image,{source:{uri:t},style:z.thumbnailImage}):_jsx(View,{style:[z.extensionTile,{backgroundColor:v.colors["bg-subtle"]}],children:_jsx(Text,{style:[z.extensionText,{color:v.colors["text-muted"],...fontFor(v,"semibold")}],children:extensionOf(e.name)})})},removeButton=e=>_jsx(Pressable,{onPress:()=>G(e),disabled:m,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:P.removeFile(e.name),style:[z.removeButton,{backgroundColor:v.colors.scrim}],children:_jsx(Text,{style:[z.removeButtonText,{color:v.colors["on-scrim"]}],children:"×"})}),retryButton=e=>C&&"error"===e.status?_jsx(Pressable,{onPress:()=>C(e),disabled:m,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:P.retry,children:_jsx(Text,{style:[z.retryText,{color:v.colors.primary}],children:"↻"})}):null,renderOneFile=(e,t)=>{const r={file:e,index:t,disabled:m,remove:()=>G(e),retry:C?()=>C(e):void 0},s=h?h(r):"card"===u?(e=>{const{file:t}=e;return _jsxs(View,{style:[z.tile,{width:84,height:84,borderRadius:k,...smoothCorners,borderColor:"error"===t.status?v.colors.danger:v.colors.border}],children:[renderThumbnail(t),renderStatusOverlay(t),"error"===t.status?_jsx(View,{style:[z.tileOverlay,{backgroundColor:v.colors.scrim}],children:retryButton(t)}):null,removeButton(t)]})})(r):(e=>{const{file:t}=e,r=statusText(t);return _jsxs(View,{style:[z.listRow,{borderRadius:k,...smoothCorners,borderColor:"error"===t.status?v.colors.danger:v.colors.border,backgroundColor:v.colors.bg}],children:[_jsxs(View,{style:[z.listThumb,{borderRadius:v.radius.sm,...smoothCorners}],children:[renderThumbnail(t),"processing"===t.status?_jsx(View,{style:[z.tileOverlay,{backgroundColor:v.colors.scrim}],children:_jsx(Spinner,{size:"sm"})}):null]}),_jsxs(View,{style:z.listTextWrap,children:[_jsx(Text,{numberOfLines:1,ellipsizeMode:"middle",style:[z.listName,{color:v.colors["text-body"],fontSize:v.text.sm.size,...fontFor(v,"medium")}],children:t.name}),_jsx(Text,{numberOfLines:1,style:[z.listSubtitle,{color:"error"===t.status?v.colors["danger-text"]:v.colors["text-subtle"],fontSize:v.text.xs.size}],children:[formatFileSize(t.size),r].filter(Boolean).join(" · ")}),"uploading"===t.status?_jsx(View,{style:[z.listProgressTrack,{backgroundColor:v.colors.border}],children:_jsx(View,{style:[z.listProgressFill,{width:`${Math.round(100*(t.progress??0))}%`,backgroundColor:v.colors.primary}]})}):null]}),retryButton(t),_jsx(Pressable,{onPress:()=>G(t),disabled:m,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:P.removeFile(t.name),children:_jsx(Text,{style:[z.listRemoveText,{color:v.colors["text-subtle"]}],children:"×"})})]})})(r);return _jsx(Pressable,{onPress:j?()=>j(e):void 0,disabled:m||!j,accessibilityLabel:fileA11yLabel(e),children:s},e.id)},J={open:U,disabled:m||E,fileCount:I.length,atCapacity:E},dashedTrigger=e=>_jsxs(Pressable,{onPress:()=>U(),disabled:m||E,accessibilityRole:"button",accessibilityLabel:K,accessibilityState:{disabled:m||E},"aria-disabled":m||E,style:({pressed:t})=>[z.trigger,e?z.triggerCompact:null,{borderRadius:k,...smoothCorners,borderColor:R,backgroundColor:t?v.colors["surface-pressed"]:v.colors.bg,opacity:m||E?.55:1}],children:[_jsxs(View,{style:z.triggerRow,children:[Y?Y({size:16,color:v.colors.primary}):null,_jsx(Text,{style:[z.triggerText,{color:v.colors.primary,fontSize:v.text.sm.size,...fontFor(v,"medium")}],children:0===I.length?P.trigger:P.addMore})]}),!e&&p?_jsx(Text,{style:[z.helperText,{color:v.colors["text-subtle"],fontSize:v.text.xs.size}],children:p}):null]}),Q=_jsx(Pressable,{onPress:()=>U(),disabled:m||E,accessibilityRole:"button",accessibilityLabel:P.addMore,style:({pressed:e})=>[z.tile,z.addTile,{width:84,height:84,borderRadius:k,...smoothCorners,borderColor:R,backgroundColor:e?v.colors["surface-pressed"]:"transparent",opacity:m||E?.55:1}],children:_jsx(Text,{style:[z.addTileText,{color:v.colors.primary}],children:"+"})});return _jsxs(View,{style:[z.container,w],testID:_,accessibilityLabel:K,children:["card"===u?0===I.length?g?g(J):dashedTrigger(!1):_jsxs(ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[z.strip,{columnGap:v.space.sm}],children:[I.map(renderOneFile),g?g(J):E||m?null:Q]}):_jsxs(View,{style:{rowGap:v.space.sm},children:[g?g(J):E?null:dashedTrigger(I.length>0),I.map(renderOneFile)]}),hasFieldText(A)?_jsx(Text,{accessibilityLiveRegion:"polite",style:[z.errorText,{color:v.colors["danger-text"],fontSize:v.text.xs.size,marginTop:v.space.xxs}],children:A}):null,_jsx(OptionSheet,{open:H,onClose:()=>$(!1),title:P.sheetTitle,options:o,labelOf:e=>e.label,getValue:e=>e.key,disabledOf:()=>!1,descriptionOf:e=>e.description,iconOf:e=>e.icon,isSelected:()=>!1,onSelect:e=>{$(!1),D(e)}})]})});FilePicker.displayName="FilePicker";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},trigger:{borderWidth:1,borderStyle:"dashed",alignItems:"center",minHeight:48,paddingVertical:e.space.md,paddingHorizontal:e.space.lg},triggerCompact:{minHeight:40,paddingVertical:e.space.sm},triggerRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},triggerText:{includeFontPadding:!1},helperText:{includeFontPadding:!1,marginTop:e.space.xs,textAlign:"center"},strip:{paddingVertical:e.space.xxs},tile:{borderWidth:1,overflow:"hidden"},addTile:{borderStyle:"dashed",alignItems:"center",justifyContent:"center"},addTileText:{fontSize:e.text["3xl"].size,includeFontPadding:!1},thumbnailImage:{width:"100%",height:"100%",resizeMode:"cover"},extensionTile:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"},extensionText:{fontSize:e.text.sm.size,letterSpacing:1,includeFontPadding:!1},tileOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},tileOverlayText:{fontSize:e.text.sm.size,includeFontPadding:!1,marginBottom:e.space.xs},tileProgressTrack:{position:"absolute",left:8,right:8,bottom:8,height:3,borderRadius:e.radius.pill,...smoothCorners,overflow:"hidden"},tileProgressFill:{height:"100%",borderRadius:e.radius.pill,...smoothCorners},doneBadge:{position:"absolute",right:4,bottom:4,width:18,height:18,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},doneBadgeText:{fontSize:e.text.xs.size,includeFontPadding:!1},removeButton:{position:"absolute",top:4,right:4,width:20,height:20,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center"},removeButtonText:{fontSize:e.text.sm.size,lineHeight:15,includeFontPadding:!1},retryText:{fontSize:e.text.xl.size,includeFontPadding:!1},listRow:{flexDirection:"row",alignItems:"center",borderWidth:1,padding:e.space.sm,columnGap:e.space.sm},listThumb:{width:40,height:40,overflow:"hidden"},listTextWrap:{flex:1},listName:{includeFontPadding:!1},listSubtitle:{includeFontPadding:!1,marginTop:e.space.xxs},listProgressTrack:{height:3,borderRadius:e.radius.pill,...smoothCorners,overflow:"hidden",marginTop:e.space.xs},listProgressFill:{height:"100%",borderRadius:e.radius.pill,...smoothCorners},listRemoveText:{fontSize:e.text["2xl"].size,includeFontPadding:!1,paddingHorizontal:e.space.xs},errorText:{includeFontPadding:!1}});export{FilePicker};export default FilePicker;
@@ -1 +1 @@
1
- "use strict";import{formatDate}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{FlatList,StyleSheet,View}from"react-native";import{KeyboardChatScrollView}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{Badge}from"../Badge/index.js";import{DateSeparator,dayLabel}from"../DateSeparator/index.js";import{IconButton}from"../IconButton/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MESSAGE_LIST_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday",jumpToLatest:"Jump to the latest message",newMessages:e=>1===e?"1 new message":`${e} new messages`,unread:"New messages",loadingOlder:"Loading earlier messages"});const JUMP_AT=160,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:160},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";export function MessageList({messages:e,keyExtractor:t,renderMessage:o,getAuthorKey:s,getDate:n,firstUnreadKey:r,onLoadOlder:a,loadingOlder:l=!1,hasOlder:i=!0,typing:d,empty:u,getAnnouncement:c,followNew:m,keyboardAware:p=!0,keyboardOffset:f,labels:g,now:y,onScroll:x,contentContainerStyle:b,style:j,testID:S,...h}){const _=useTheme(),w=useSafeAreaInsets(),L=useReducedMotion(),E=useMemo(()=>buildStyles(_),[_]),C=useMemo(()=>({...DEFAULT_MESSAGE_LIST_LABELS,...g}),[g]),v=f??w.bottom,I=useRef(null),T=useRef(!1),[k,M]=useState(!1),[O,D]=useState(0),A=useMemo(()=>{const o=n?e.map(e=>formatDate(n(e))):null,a=s?e.map(s):null,l=void 0===r?-1:e.findIndex(e=>t(e)===r);return e.map((t,s)=>{const r=s===e.length-1,i=null!==o&&(r||o[s]!==o[s+1]),d=null!==a&&!r&&a[s+1]===a[s]&&!i&&s!==l,u=null!==a&&s>0&&a[s-1]===a[s]&&(null===o||o[s-1]===o[s])&&s-1!==l;return{groupPosition:positionOf(d,u),day:i&&n?dayLabel(n(t),{now:y,labels:C}):null,unread:s===l}})},[e,n,s,r,t,y,C]),V=useCallback(()=>{I.current?.scrollToOffset({offset:0,animated:!L}),D(0)},[L]),F=e.length>0?t(e[0]):null,P=useRef(F);useEffect(()=>{const o=P.current;if(P.current=F,null===o||null===F||o===F)return;const s=e.findIndex(e=>t(e)===o);if(-1===s)return void D(0);const n=e.slice(0,s).reverse();for(const e of n){const t=c?.(e);t&&announce(t)}m&&n.some(m)?V():T.current&&D(e=>e+n.length)},[F]);const R=useCallback(e=>{const t=e.nativeEvent.contentOffset.y>160;t!==T.current&&(T.current=t,M(t),t||D(0)),x?.(e)},[x]),B=useCallback(()=>{i&&!l&&a?.()},[i,l,a]),K=useCallback(({item:e,index:t})=>{const s=A[t];return _jsxs(_Fragment,{children:[s?.day?_jsx(DateSeparator,{label:s.day}):null,s?.unread?_jsx(DateSeparator,{label:C.unread,emphasis:!0}):null,o({item:e,index:t,groupPosition:s?.groupPosition??"single"})]})},[A,C.unread,o]),z=useCallback(e=>t(e),[t]),N=useCallback(e=>_jsx(KeyboardChatScrollView,{...e,inverted:!0,offset:v}),[v]),U=O>0?`${C.newMessages(O)}. ${C.jumpToLatest}`:C.jumpToLatest;return _jsxs(View,{style:[E.root,j],children:[_jsx(FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...h,ref:I,data:e,renderItem:K,keyExtractor:z,inverted:!0,onScroll:R,onEndReached:a?B:void 0,ListHeaderComponent:d?_jsx(_Fragment,{children:d}):null,ListFooterComponent:l?_jsx(Spinner,{size:"sm",accessibilityLabel:C.loadingOlder,style:E.older}):null,ListEmptyComponent:u?_jsx(View,{style:E.fill,children:u}):null,renderScrollComponent:p?N:void 0,contentContainerStyle:[E.content,0===e.length?E.grow:null,b],testID:S}),k?_jsxs(View,{style:E.jump,pointerEvents:"box-none",children:[_jsx(View,{style:E.jumpDisc,children:_jsx(IconButton,{icon:"arrow-down",accessibilityLabel:U,variant:"ghost",tone:"neutral",onPress:V,testID:S?`${S}-jump`:void 0})}),O>0?_jsx(View,{style:E.count,pointerEvents:"none",importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,children:_jsx(Badge,{value:O,max:99,tone:"primary",size:"sm"})}):null]}):null]})}const buildStyles=e=>StyleSheet.create({root:{flex:1},content:{paddingHorizontal:e.space.md,paddingVertical:e.space.sm},grow:{flexGrow:1},fill:{flex:1},older:{paddingVertical:e.space.md},jump:{position:"absolute",right:e.space.md,bottom:e.space.md},jumpDisc:{borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors.surface,...e.shadow.elevated},count:{position:"absolute",top:-e.space.xs,right:-e.space.xs}});export default MessageList;
1
+ "use strict";import{formatDate}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{FlatList,StyleSheet,View}from"react-native";import{KeyboardChatScrollView}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{Badge}from"../Badge/index.js";import{DateSeparator,dayLabel}from"../DateSeparator/index.js";import{IconButton}from"../IconButton/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MESSAGE_LIST_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday",jumpToLatest:"Jump to the latest message",newMessages:e=>1===e?"1 new message":`${e} new messages`,unread:"New messages",loadingOlder:"Loading earlier messages"});const JUMP_AT=160,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:160},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";export function MessageList({messages:e,keyExtractor:t,renderMessage:o,getAuthorKey:s,getDate:n,firstUnreadKey:r,onLoadOlder:a,loadingOlder:l=!1,hasOlder:i=!0,typing:d,empty:u,getAnnouncement:c,followNew:m,keyboardAware:p=!0,keyboardOffset:f,labels:g,now:y,onScroll:x,contentContainerStyle:b,style:j,testID:S,...h}){const _=useTheme(),w=useSafeAreaInsets(),L=useReducedMotion(),E=useMemo(()=>buildStyles(_),[_]),C=useMemo(()=>({...DEFAULT_MESSAGE_LIST_LABELS,...g}),[g]),v=f??w.bottom,I=useRef(null),T=useRef(!1),[k,M]=useState(!1),[O,D]=useState(0),A=useMemo(()=>{const o=n?e.map(e=>formatDate(n(e))):null,a=s?e.map(s):null,l=void 0===r?-1:e.findIndex(e=>t(e)===r);return e.map((t,s)=>{const r=s===e.length-1,i=null!==o&&(r||o[s]!==o[s+1]),d=null!==a&&!r&&a[s+1]===a[s]&&!i&&s!==l,u=null!==a&&s>0&&a[s-1]===a[s]&&(null===o||o[s-1]===o[s])&&s-1!==l;return{groupPosition:positionOf(d,u),day:i&&n?dayLabel(n(t),{now:y,labels:C}):null,unread:s===l}})},[e,n,s,r,t,y,C]),V=useCallback(()=>{I.current?.scrollToOffset({offset:0,animated:!L}),D(0)},[L]),P=e.length>0?t(e[0]):null,F=useRef(P);useEffect(()=>{const o=F.current;if(F.current=P,null===o||null===P||o===P)return;const s=e.findIndex(e=>t(e)===o);if(-1===s)return void D(0);const n=e.slice(0,s).reverse();for(const e of n){const t=c?.(e);t&&announce(t)}m&&n.some(m)?V():T.current&&D(e=>e+n.length)},[P]);const R=useCallback(e=>{const t=e.nativeEvent.contentOffset.y>160;t!==T.current&&(T.current=t,M(t),t||D(0)),x?.(e)},[x]),B=useCallback(()=>{i&&!l&&a?.()},[i,l,a]),K=useCallback(({item:e,index:t})=>{const s=A[t];return _jsxs(_Fragment,{children:[s?.day?_jsx(DateSeparator,{label:s.day}):null,s?.unread?_jsx(DateSeparator,{label:C.unread,emphasis:!0}):null,o({item:e,index:t,groupPosition:s?.groupPosition??"single"})]})},[A,C.unread,o]),z=useCallback(e=>t(e),[t]),N=useCallback(e=>_jsx(KeyboardChatScrollView,{...e,inverted:!0,offset:v}),[v]),U=O>0?`${C.newMessages(O)}. ${C.jumpToLatest}`:C.jumpToLatest;return _jsxs(View,{style:[E.root,j],children:[_jsx(FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...h,ref:I,data:e,renderItem:K,keyExtractor:z,inverted:!0,onScroll:R,onEndReached:a?B:void 0,ListHeaderComponent:d?_jsx(View,{children:d}):null,ListFooterComponent:l?_jsx(Spinner,{size:"sm",accessibilityLabel:C.loadingOlder,style:E.older}):null,ListEmptyComponent:u?_jsx(View,{style:E.fill,children:u}):null,renderScrollComponent:p?N:void 0,contentContainerStyle:[E.content,0===e.length?E.grow:null,b],testID:S}),k?_jsxs(View,{style:E.jump,pointerEvents:"box-none",children:[_jsx(View,{style:E.jumpDisc,children:_jsx(IconButton,{icon:"arrow-down",accessibilityLabel:U,variant:"ghost",tone:"neutral",onPress:V,testID:S?`${S}-jump`:void 0})}),O>0?_jsx(View,{style:E.count,pointerEvents:"none",importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,children:_jsx(Badge,{value:O,max:99,tone:"primary",size:"sm"})}):null]}):null]})}const buildStyles=e=>StyleSheet.create({root:{flex:1},content:{paddingHorizontal:e.space.md,paddingVertical:e.space.sm},grow:{flexGrow:1},fill:{flex:1},older:{paddingVertical:e.space.md},jump:{position:"absolute",right:e.space.md,bottom:e.space.md},jumpDisc:{borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors.surface,...e.shadow.elevated},count:{position:"absolute",top:-e.space.xs,right:-e.space.xs}});export default MessageList;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Dimensions,Easing,Platform,Pressable,Modal as RNModal,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9,Modal=forwardRef((e,t)=>{const{visible:s,onRequestClose:r,presentation:i="centered",backdropOpacity:o,backdropPressClose:a=!0,animationDuration:n,animateMount:l=!0,accessibilityLabel:u,hardwareBackPress:c=!0,children:d,contentStyle:m,backdropStyle:f,restoreFocusRef:p,onDismissed:g,haptic:b,testID:h}=e,S=useTheme(),A=usePresenceMotion(),[y,v]=useModalInsets(),x=n??A.duration("default"),M=Dimensions.get("window").height,R=useRef(!l&&s),V=R.current,j=useRef(createAnimatedValue(V?1:.9)).current,C=useRef(createAnimatedValue(V?1:0)).current,w=useRef(createAnimatedValue(V?0:M)).current,T=useRef(createAnimatedValue(V?1:0)).current,D=useRef(null),_=useRef(!1),[E,k]=useState(s),I=useMemo(()=>buildStyles(S),[S]),N=useMemo(()=>{const e=S.colors.scrim;return"number"!=typeof o?e:withAlpha(e,o)??e},[S.colors.scrim,o]),q=useMemo(()=>T.interpolate({inputRange:[0,1],outputRange:[transparentOf(N),N]}),[T,N]);useEffect(()=>{s&&k(!0)},[s]),useEffect(()=>{const e=[];if(s&&E&&R.current)R.current=!1;else if(s&&E){const t=Animated.timing(T,{toValue:1,duration:A.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),A.reduced){C.setValue(0),w.setValue(0),j.setValue(1);const t=Animated.timing(C,{toValue:1,duration:x,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===i){C.setValue(1);const t=Animated.spring(w,{toValue:0,damping:S.motion.spring.gentle.damping,stiffness:S.motion.spring.gentle.stiffness,mass:S.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(j,{toValue:1,damping:S.motion.spring.gentle.damping,stiffness:S.motion.spring.gentle.stiffness,mass:S.motion.spring.gentle.mass,useNativeDriver:!0}),Animated.timing(C,{toValue:1,duration:x,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(E){const t=A.duration("fast"),s=Easing.bezier(...S.motion.ease.accelerate),r=Animated.timing(C,{toValue:0,duration:t,easing:s,useNativeDriver:!0}),o=A.reduced?r:"bottom"===i?Animated.timing(w,{toValue:M,duration:t,easing:s,useNativeDriver:!0}):Animated.parallel([Animated.timing(j,{toValue:.9,duration:t,easing:s,useNativeDriver:!0}),r]),a=Animated.parallel([o,Animated.timing(T,{toValue:0,duration:A.duration("default"),useNativeDriver:!1})]);a.start(({finished:e})=>{e&&(w.setValue(M),k(!1))}),e.push(a)}return()=>e.forEach(e=>e.stop())},[s,E,i,x,j,C,T,w,M,S.motion.spring.gentle.damping,S.motion.spring.gentle.stiffness,S.motion.spring.gentle.mass,A,S.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return s?(e=setTimeout(()=>{D.current&&AccessibilityInfo.sendAccessibilityEvent(D.current,"focus")},150),_.current=!0):_.current&&(_.current=!1,p&&p.current&&(t=setTimeout(()=>{const e=p.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},x))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[s,x,p]);const P=useRef(!1);useEffect(()=>{if(s)return void(P.current=!0);if(!P.current)return;if(P.current=!1,!g)return;const e=setTimeout(g,300);return()=>clearTimeout(e)},[s,g]);const z=useCallback(()=>{if(!a)return;const e=resolveHaptic(b,"selection");e&&triggerHaptic(e),r()},[a,r,b]),H=useCallback(()=>{c&&r()},[c,r]),L=useSquircle("bottom"!==i&&"fullScreen"!==i,S.radius.xl),F=useMemo(()=>"fullScreen"===i?[I.fullScreenContent,{backgroundColor:S.colors.surface}]:"bottom"===i?[I.bottomContent,{backgroundColor:S.colors.surface,borderTopLeftRadius:S.radius.xl,borderTopRightRadius:S.radius.xl,...smoothCorners,paddingTop:S.space.lg,paddingHorizontal:S.space.lg,paddingBottom:S.space.lg+y.bottom},S.shadow.modal]:[I.centeredContent,{backgroundColor:S.colors.surface,borderRadius:L.active&&L.size?squircleHostRadius(L.size.width,L.size.height,S.radius.xl):S.radius.xl,...smoothCorners,padding:S.space.xl},S.shadow.modal],[i,S,I,y.bottom,L.active,L.size]),W=useMemo(()=>"bottom"===i?I.bottomWrapper:"fullScreen"===i?I.fullScreenWrapper:I.centeredWrapper,[i,I]),O=useMemo(()=>"bottom"===i?{opacity:C,transform:[{translateY:w}]}:"fullScreen"===i?{opacity:C}:{opacity:C,transform:[{scale:j}]},[i,j,C,w]);return _jsx(RNModal,{visible:E,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:H,testID:h,children:_jsx(View,{ref:e=>{D.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:I.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:u,children:_jsxs(ModalSafeArea,{onInsets:v,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,W,{backgroundColor:q},f],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:z,accessibilityRole:"button",accessibilityLabel:"Close modal",disabled:!a}),_jsxs(Animated.View,{style:[F,O,m],onLayout:L.onLayout,pointerEvents:"auto",children:[L.active&&L.size?_jsx(SquircleFill,{width:L.size.width,height:L.size.height,radius:S.radius.xl,fill:S.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1}});export{Modal};export default Modal;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Dimensions,Easing,Platform,Pressable,Modal as RNModal,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9,Modal=forwardRef((e,t)=>{const{visible:s,onRequestClose:r,presentation:i="centered",backdropOpacity:o,backdropPressClose:a=!0,animationDuration:n,animateMount:l=!0,accessibilityLabel:u,hardwareBackPress:c=!0,children:d,contentStyle:m,backdropStyle:f,restoreFocusRef:p,onDismissed:g,haptic:b,testID:h}=e,S=useTheme(),A=usePresenceMotion(),[y,v]=useModalInsets(),x=n??A.duration("default"),M=Dimensions.get("window").height,R=useRef(!l&&s),V=R.current,j=useRef(createAnimatedValue(V?1:.9)).current,C=useRef(createAnimatedValue(V?1:0)).current,w=useRef(createAnimatedValue(V?0:M)).current,T=useRef(createAnimatedValue(V?1:0)).current,D=useRef(null),_=useRef(!1),[E,k]=useState(s),I=useMemo(()=>buildStyles(S),[S]),N=useMemo(()=>{const e=S.colors.scrim;return"number"!=typeof o?e:withAlpha(e,o)??e},[S.colors.scrim,o]),q=useMemo(()=>T.interpolate({inputRange:[0,1],outputRange:[transparentOf(N),N]}),[T,N]);useEffect(()=>{s&&k(!0)},[s]),useEffect(()=>{const e=[];if(s&&E&&R.current)R.current=!1;else if(s&&E){const t=Animated.timing(T,{toValue:1,duration:A.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),A.reduced){C.setValue(0),w.setValue(0),j.setValue(1);const t=Animated.timing(C,{toValue:1,duration:x,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===i){C.setValue(1);const t=Animated.spring(w,{toValue:0,damping:S.motion.spring.gentle.damping,stiffness:S.motion.spring.gentle.stiffness,mass:S.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(j,{toValue:1,damping:S.motion.spring.gentle.damping,stiffness:S.motion.spring.gentle.stiffness,mass:S.motion.spring.gentle.mass,useNativeDriver:!0}),Animated.timing(C,{toValue:1,duration:x,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(E){const t=A.duration("fast"),s=Easing.bezier(...S.motion.ease.accelerate),r=Animated.timing(C,{toValue:0,duration:t,easing:s,useNativeDriver:!0}),o=A.reduced?r:"bottom"===i?Animated.timing(w,{toValue:M,duration:t,easing:s,useNativeDriver:!0}):Animated.parallel([Animated.timing(j,{toValue:.9,duration:t,easing:s,useNativeDriver:!0}),r]),a=Animated.parallel([o,Animated.timing(T,{toValue:0,duration:A.duration("default"),useNativeDriver:!1})]);a.start(({finished:e})=>{e&&(w.setValue(M),k(!1))}),e.push(a)}return()=>e.forEach(e=>{e.stop()})},[s,E,i,x,j,C,T,w,M,S.motion.spring.gentle.damping,S.motion.spring.gentle.stiffness,S.motion.spring.gentle.mass,A,S.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return s?(e=setTimeout(()=>{D.current&&AccessibilityInfo.sendAccessibilityEvent(D.current,"focus")},150),_.current=!0):_.current&&(_.current=!1,p?.current&&(t=setTimeout(()=>{const e=p.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},x))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[s,x,p]);const P=useRef(!1);useEffect(()=>{if(s)return void(P.current=!0);if(!P.current)return;if(P.current=!1,!g)return;const e=setTimeout(g,300);return()=>clearTimeout(e)},[s,g]);const z=useCallback(()=>{if(!a)return;const e=resolveHaptic(b,"selection");e&&triggerHaptic(e),r()},[a,r,b]),H=useCallback(()=>{c&&r()},[c,r]),L=useSquircle("bottom"!==i&&"fullScreen"!==i,S.radius.xl),F=useMemo(()=>"fullScreen"===i?[I.fullScreenContent,{backgroundColor:S.colors.surface}]:"bottom"===i?[I.bottomContent,{backgroundColor:S.colors.surface,borderTopLeftRadius:S.radius.xl,borderTopRightRadius:S.radius.xl,...smoothCorners,paddingTop:S.space.lg,paddingHorizontal:S.space.lg,paddingBottom:S.space.lg+y.bottom},S.shadow.modal]:[I.centeredContent,{backgroundColor:S.colors.surface,borderRadius:L.active&&L.size?squircleHostRadius(L.size.width,L.size.height,S.radius.xl):S.radius.xl,...smoothCorners,padding:S.space.xl},S.shadow.modal],[i,S,I,y.bottom,L.active,L.size]),W=useMemo(()=>"bottom"===i?I.bottomWrapper:"fullScreen"===i?I.fullScreenWrapper:I.centeredWrapper,[i,I]),O=useMemo(()=>"bottom"===i?{opacity:C,transform:[{translateY:w}]}:"fullScreen"===i?{opacity:C}:{opacity:C,transform:[{scale:j}]},[i,j,C,w]);return _jsx(RNModal,{visible:E,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:H,testID:h,children:_jsx(View,{ref:e=>{D.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:I.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:u,children:_jsxs(ModalSafeArea,{onInsets:v,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,W,{backgroundColor:q},f],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:z,accessibilityRole:"button",accessibilityLabel:"Close modal",disabled:!a}),_jsxs(Animated.View,{style:[F,O,m],onLayout:L.onLayout,pointerEvents:"auto",children:[L.active&&L.size?_jsx(SquircleFill,{width:L.size.width,height:L.size.height,radius:S.radius.xl,fill:S.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1}});export{Modal};export default Modal;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:s,onChange:i,onComplete:r,length:o=6,keyboardType:a="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,onFocus:g,accessibilityLabel:h,style:b,cellStyle:x,textStyle:y,testID:j}=e,[v,C]=useControllableState({value:n,defaultValue:s??"",onChange:i}),T=useTheme(),V=useMemo(()=>buildStyles(T),[T]),S=resolveOtpInputSize(T,m),k=useRef([]),[F,w]=useState(-1),E=useRef(null),A=useRef(createAnimatedValue(0)).current,I=useRef(new Map),R=useMemo(()=>{const e=I.current,t=[];for(let n=0;n<o;n+=1){let s=e.get(n);s||(s=new Animated.Value(0),e.set(n,s)),t.push(s)}for(const t of Array.from(e.keys()))t>=o&&e.delete(t);return t},[o]),O=useRef(-1),_=T.settings.components["otp-input"]?.shakeOnError??!1,z=useReducedMotion(),M=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===E.current||!M||E.current||(f&&triggerHaptic("notificationError"),_&&!z&&(setNativeValue(A,0),e=Animated.sequence([Animated.timing(A,{toValue:1,duration:T.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(A,{toValue:-1,duration:T.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(A,{toValue:1,duration:T.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(A,{toValue:0,duration:T.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0})]),e.start())),E.current=M,()=>e?.stop()},[M,A,_,f,z,T.motion.duration.instant]),useEffect(()=>{const e=O.current;if(O.current=F,e===F)return;if(-1===e&&-1===F)return;const t=[];return R.forEach((n,s)=>{const i=s===F?1:0;if(s!==F&&s!==e)return;const r=Animated.timing(n,{toValue:i,duration:T.motion.duration.fast,easing:Easing.bezier(...T.motion.ease["in-out"]),useNativeDriver:!0});r.start(),t.push(r)}),()=>t.forEach(e=>e.stop())},[F,R,T]);const D=useCallback(e=>{const t=k.current[e];t&&t.focus()},[]);useImperativeHandle(t,()=>({focus:()=>D(0),blur:()=>{const e=k.current[F>=0?F:0];e?.blur()},clear:()=>{C(""),D(0)}}),[D,F,C]),useEffect(()=>{if(l&&!c){const e=setTimeout(()=>D(0),u);return()=>clearTimeout(e)}},[l,u,c,D]);const P=useMemo(()=>{const e=new Array(o).fill("");for(let t=0;t<Math.min(v.length,o);t+=1)e[t]=v[t]??"";return e},[v,o]),H=useCallback(e=>{const t=e.slice(0,o);t!==v&&(C(t),t.length===o&&r&&r(t))},[o,C,r,v]),N=useCallback((e,t)=>{const n=t.replace(/\u200B/g,""),s=sanitizeChar(n,a);if(!s){const t=P.slice(),n=(t[e]??"").length>0;if(t[e]="",H(t.join("").slice(0,o)),!n&&e>0){const t=P.slice();t[e-1]="",H(t.join("")),D(e-1)}return}const i=P[e]??"",r=i&&s.length>o&&s.startsWith(i)?s.slice(i.length):s;if(r.length>=o){const t=r.slice(0,o),n=v.length;return H(t),t.length!==n&&f&&triggerHaptic(f),void k.current[e]?.blur()}const l=P.slice();let u=e;for(let e=0;e<s.length&&u<o;e+=1)l[u]=s[e]??"",u+=1;const c=l.join("").slice(0,o),d=v.length;H(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,o-1);u>=o?k.current[e]?.blur():D(m)},[P,D,a,o,f,H,v]),B=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(P[e]??"").length){if(e>0){const t=P.slice();t[e-1]="",H(t.join("")),D(e-1)}}else{const t=P.slice();t[e]="",H(t.join(""))}},[P,D,H]),W=useCallback((e,t)=>{w(e),g?.(t)},[g]),L=useCallback(()=>{w(-1)},[]),$=useCallback(()=>{if(c)return;const e=P.indexOf("");D(-1===e?o-1:e)},[P,c,D,o]),q=h??`Enter ${o}-digit code`,G=A.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return _jsxs(View,{style:b,accessible:!0,accessibilityRole:"none",accessibilityLabel:q,accessibilityValue:{text:n},accessibilityState:{disabled:c},"aria-disabled":c,testID:j,children:[_jsx(Pressable,{onPress:$,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[V.row,{columnGap:S.gap,transform:[{translateX:G}]}],children:P.map((e,t)=>{const n=F===t,s=e.length>0,i=M?T.colors["danger-border"]:T.colors["focus-ring"],r=R[t];if(!r)return null;const l=p&&s?"●":e;return _jsxs(View,{style:V.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:S.cell,height:S.cell,borderRadius:S.radius,borderWidth:1.5,focused:n,error:M,filled:s,disabled:c,paddingHorizontal:T.space.none,paddingVertical:T.space.none,gap:T.space.none,style:x,children:[_jsx(TextInput,{ref:e=>{k.current[t]=e},value:(p&&s?"":e)||"​",onChangeText:e=>N(t,e),onKeyPress:e=>B(t,e),onFocus:e=>W(t,e),onBlur:L,keyboardType:a,editable:!c,selectTextOnFocus:!0,caretHidden:s,maxLength:o+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[V.input,{fontSize:S.text,color:T.colors["text-body"],...fontFor(T,"semibold")},y]}),p&&s?_jsx(View,{pointerEvents:"none",style:V.maskOverlay,children:_jsx(Text,{style:[{fontSize:S.text,color:T.colors["text-body"],...fontFor(T,"semibold")},y],children:l})}):null]}),_jsx(Animated.View,{style:[V.underline,{backgroundColor:i,opacity:r}]})]},`otp-cell-${t}`)})})}),_jsx(FieldMessage,{size:m,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,...smoothCorners}});export{OTPInput};export default OTPInput;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:s,onChange:i,onComplete:r,length:o=6,keyboardType:a="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,onFocus:g,accessibilityLabel:h,style:b,cellStyle:x,textStyle:y,testID:j}=e,[v,C]=useControllableState({value:n,defaultValue:s??"",onChange:i}),T=useTheme(),V=useMemo(()=>buildStyles(T),[T]),S=resolveOtpInputSize(T,m),k=useRef([]),[F,w]=useState(-1),E=useRef(null),A=useRef(createAnimatedValue(0)).current,I=useRef(new Map),R=useMemo(()=>{const e=I.current,t=[];for(let n=0;n<o;n+=1){let s=e.get(n);s||(s=new Animated.Value(0),e.set(n,s)),t.push(s)}for(const t of Array.from(e.keys()))t>=o&&e.delete(t);return t},[o]),O=useRef(-1),_=T.settings.components["otp-input"]?.shakeOnError??!1,z=useReducedMotion(),M=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===E.current||!M||E.current||(f&&triggerHaptic("notificationError"),_&&!z&&(setNativeValue(A,0),e=Animated.sequence([Animated.timing(A,{toValue:1,duration:T.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(A,{toValue:-1,duration:T.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(A,{toValue:1,duration:T.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(A,{toValue:0,duration:T.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0})]),e.start())),E.current=M,()=>e?.stop()},[M,A,_,f,z,T.motion.duration.instant]),useEffect(()=>{const e=O.current;if(O.current=F,e===F)return;if(-1===e&&-1===F)return;const t=[];return R.forEach((n,s)=>{const i=s===F?1:0;if(s!==F&&s!==e)return;const r=Animated.timing(n,{toValue:i,duration:T.motion.duration.fast,easing:Easing.bezier(...T.motion.ease["in-out"]),useNativeDriver:!0});r.start(),t.push(r)}),()=>t.forEach(e=>{e.stop()})},[F,R,T]);const D=useCallback(e=>{const t=k.current[e];t&&t.focus()},[]);useImperativeHandle(t,()=>({focus:()=>D(0),blur:()=>{const e=k.current[F>=0?F:0];e?.blur()},clear:()=>{C(""),D(0)}}),[D,F,C]),useEffect(()=>{if(l&&!c){const e=setTimeout(()=>D(0),u);return()=>clearTimeout(e)}},[l,u,c,D]);const P=useMemo(()=>{const e=new Array(o).fill("");for(let t=0;t<Math.min(v.length,o);t+=1)e[t]=v[t]??"";return e},[v,o]),H=useCallback(e=>{const t=e.slice(0,o);t!==v&&(C(t),t.length===o&&r&&r(t))},[o,C,r,v]),N=useCallback((e,t)=>{const n=t.replace(/\u200B/g,""),s=sanitizeChar(n,a);if(!s){const t=P.slice(),n=(t[e]??"").length>0;if(t[e]="",H(t.join("").slice(0,o)),!n&&e>0){const t=P.slice();t[e-1]="",H(t.join("")),D(e-1)}return}const i=P[e]??"",r=i&&s.length>o&&s.startsWith(i)?s.slice(i.length):s;if(r.length>=o){const t=r.slice(0,o),n=v.length;return H(t),t.length!==n&&f&&triggerHaptic(f),void k.current[e]?.blur()}const l=P.slice();let u=e;for(let e=0;e<s.length&&u<o;e+=1)l[u]=s[e]??"",u+=1;const c=l.join("").slice(0,o),d=v.length;H(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,o-1);u>=o?k.current[e]?.blur():D(m)},[P,D,a,o,f,H,v]),B=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(P[e]??"").length){if(e>0){const t=P.slice();t[e-1]="",H(t.join("")),D(e-1)}}else{const t=P.slice();t[e]="",H(t.join(""))}},[P,D,H]),W=useCallback((e,t)=>{w(e),g?.(t)},[g]),L=useCallback(()=>{w(-1)},[]),$=useCallback(()=>{if(c)return;const e=P.indexOf("");D(-1===e?o-1:e)},[P,c,D,o]),q=h??`Enter ${o}-digit code`,G=A.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return _jsxs(View,{style:b,accessible:!0,accessibilityRole:"none",accessibilityLabel:q,accessibilityValue:{text:n},accessibilityState:{disabled:c},"aria-disabled":c,testID:j,children:[_jsx(Pressable,{onPress:$,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[V.row,{columnGap:S.gap,transform:[{translateX:G}]}],children:P.map((e,t)=>{const n=F===t,s=e.length>0,i=M?T.colors["danger-border"]:T.colors["focus-ring"],r=R[t];if(!r)return null;const l=p&&s?"●":e;return _jsxs(View,{style:V.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:S.cell,height:S.cell,borderRadius:S.radius,borderWidth:1.5,focused:n,error:M,filled:s,disabled:c,paddingHorizontal:T.space.none,paddingVertical:T.space.none,gap:T.space.none,style:x,children:[_jsx(TextInput,{ref:e=>{k.current[t]=e},value:(p&&s?"":e)||"​",onChangeText:e=>N(t,e),onKeyPress:e=>B(t,e),onFocus:e=>W(t,e),onBlur:L,keyboardType:a,editable:!c,selectTextOnFocus:!0,caretHidden:s,maxLength:o+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[V.input,{fontSize:S.text,color:T.colors["text-body"],...fontFor(T,"semibold")},y]}),p&&s?_jsx(View,{pointerEvents:"none",style:V.maskOverlay,children:_jsx(Text,{style:[{fontSize:S.text,color:T.colors["text-body"],...fontFor(T,"semibold")},y],children:l})}):null]}),_jsx(Animated.View,{style:[V.underline,{backgroundColor:i,opacity:r}]})]},`otp-cell-${t}`)})})}),_jsx(FieldMessage,{size:m,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,...smoothCorners}});export{OTPInput};export default OTPInput;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef}from"react";import{Dimensions,Pressable,StyleSheet,Text,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,runOnJS,useAnimatedStyle,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:n,rightActions:i,threshold:s,fullSwipeThreshold:o,onSwipeOpen:r,onSwipeClose:l,disabled:a=!1,haptic:c,containerStyle:u,contentStyle:d,actionStyle:h,accessibilityLabel:m,testID:S}=e,p=useTheme(),g=s??80,w=o??200,b=useMemo(()=>buildStyles(p),[p]),f=useMemo(()=>buildActionStyles(p),[p]),y=!!n&&n.length>0,x=!!i&&i.length>0,v=Dimensions.get("window").width,A=y?g*(n?.length??0):0,_=x?g*(i?.length??0):0,C=useSharedValue(0),I=useSharedValue(0),O=useRef(null);useEffect(()=>()=>{cancelAnimation(C),cancelAnimation(I)},[C,I]);const G=useCallback(e=>{O.current!==e&&(O.current=e,r?.(e))},[r]),j=useCallback(()=>{null!==O.current&&(O.current=null,l?.())},[l]),N=useCallback(e=>{const t="left"===e?n:i,s=t?.[0];s&&(!1!==c&&triggerHaptic("notificationSuccess"),s.onPress(),C.value=withSpring(0,SPRING_CONFIG),O.current=null,l?.())},[n,i,C,l,c]),R=useCallback(()=>{C.value=withSpring(0,SPRING_CONFIG),j()},[C,j]),k=useCallback(e=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress(),R()},[R,c]),P=useMemo(()=>{const e=A,t=_,n=w,i=-w,s=v,o=-v,r=g,l=y,c=x;return Gesture.Pan().enabled(!a).withTestId(S?`${S}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";I.value=C.value}).onUpdate(n=>{"worklet";const i=I.value+n.translationX;C.value=i>0&&!l||i<0&&!c?0:i>e&&l?e+.35*(i-e):i<-t&&c?.35*(i+t)-t:i}).onEnd(()=>{"worklet";const a=C.value;return l&&a>=n?(C.value=withSpring(s,SPRING_CONFIG),void runOnJS(N)("left")):c&&a<=i?(C.value=withSpring(o,SPRING_CONFIG),void runOnJS(N)("right")):l&&a>=r?(C.value=withSpring(e,SPRING_CONFIG),void runOnJS(G)("left")):c&&a<=-r?(C.value=withSpring(-t,SPRING_CONFIG),void runOnJS(G)("right")):(C.value=withSpring(0,SPRING_CONFIG),void runOnJS(j)())})},[a,I,N,w,y,x,A,j,G,_,v,g,C,S]),T=useAnimatedStyle(()=>({transform:[{translateX:C.value}]})),F=useAnimatedStyle(()=>({opacity:A>0?Math.min(1,Math.max(0,C.value/A)):0})),E=useAnimatedStyle(()=>({opacity:_>0?Math.min(1,Math.max(0,-C.value/_)):0})),V=useMemo(()=>{const e=[];return n?.forEach(t=>e.push({name:t.key,label:t.label})),i?.forEach(t=>e.push({name:t.key,label:t.label})),e},[n,i]),D=useCallback(e=>{const t=e.nativeEvent.actionName,s=[...n??[],...i??[]].find(e=>e.key===t);s&&(!1!==c&&triggerHaptic("selection"),s.onPress())},[n,i,c]);return y||x?_jsxs(View,{style:[b.root,u],testID:S,accessibilityLabel:m,accessibilityActions:V,onAccessibilityAction:D,children:[y?_jsx(Animated.View,{style:[b.actionsRow,b.actionsLeft,{width:A},h,F],pointerEvents:"box-none",children:n?.map(e=>_jsx(ActionButton,{action:e,theme:p,actionStyles:f,width:g,onPress:k},e.key))}):null,x?_jsx(Animated.View,{style:[b.actionsRow,b.actionsRight,{width:_},h,E],pointerEvents:"box-none",children:i?.map(e=>_jsx(ActionButton,{action:e,theme:p,actionStyles:f,width:g,onPress:k},e.key))}):null,_jsx(GestureDetector,{gesture:P,children:_jsx(Animated.View,{style:[b.content,d,T],children:t})})]}):_jsx(View,{style:u,testID:S,children:t})};Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:n,width:i,onPress:s})=>{const o=e.tone??"neutral",r=toneToBg(t,o);return _jsxs(Pressable,{onPress:()=>s(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[n.button,{width:i,backgroundColor:r,paddingHorizontal:t.space.sm}],children:[e.icon?_jsx(View,{style:n.icon,children:e.icon}):null,_jsx(Text,{style:[n.label,{color:toneToOnColor(t,o),fontSize:t.text.sm.size,fontWeight:t.weight.semibold}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});export{Swipeable};export default Swipeable;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef}from"react";import{Dimensions,Pressable,StyleSheet,Text,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,runOnJS,useAnimatedStyle,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:n,rightActions:i,threshold:s,fullSwipeThreshold:o,onSwipeOpen:r,onSwipeClose:l,disabled:a=!1,haptic:c,containerStyle:u,contentStyle:d,actionStyle:h,accessibilityLabel:m,testID:S}=e,p=useTheme(),g=s??80,w=o??200,b=useMemo(()=>buildStyles(p),[p]),f=useMemo(()=>buildActionStyles(p),[p]),y=!!n&&n.length>0,x=!!i&&i.length>0,v=Dimensions.get("window").width,A=y?g*(n?.length??0):0,_=x?g*(i?.length??0):0,C=useSharedValue(0),I=useSharedValue(0),O=useRef(null);useEffect(()=>()=>{cancelAnimation(C),cancelAnimation(I)},[C,I]);const G=useCallback(e=>{O.current!==e&&(O.current=e,r?.(e))},[r]),j=useCallback(()=>{null!==O.current&&(O.current=null,l?.())},[l]),N=useCallback(e=>{const t="left"===e?n:i,s=t?.[0];s&&(!1!==c&&triggerHaptic("notificationSuccess"),s.onPress(),C.value=withSpring(0,SPRING_CONFIG),O.current=null,l?.())},[n,i,C,l,c]),R=useCallback(()=>{C.value=withSpring(0,SPRING_CONFIG),j()},[C,j]),k=useCallback(e=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress(),R()},[R,c]),P=useMemo(()=>{const e=A,t=_,n=w,i=-w,s=v,o=-v,r=g,l=y,c=x;return Gesture.Pan().enabled(!a).withTestId(S?`${S}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";I.value=C.value}).onUpdate(n=>{"worklet";const i=I.value+n.translationX;C.value=i>0&&!l||i<0&&!c?0:i>e&&l?e+.35*(i-e):i<-t&&c?.35*(i+t)-t:i}).onEnd(()=>{"worklet";const a=C.value;return l&&a>=n?(C.value=withSpring(s,SPRING_CONFIG),void runOnJS(N)("left")):c&&a<=i?(C.value=withSpring(o,SPRING_CONFIG),void runOnJS(N)("right")):l&&a>=r?(C.value=withSpring(e,SPRING_CONFIG),void runOnJS(G)("left")):c&&a<=-r?(C.value=withSpring(-t,SPRING_CONFIG),void runOnJS(G)("right")):(C.value=withSpring(0,SPRING_CONFIG),void runOnJS(j)())})},[a,I,N,w,y,x,A,j,G,_,v,g,C,S]),T=useAnimatedStyle(()=>({transform:[{translateX:C.value}]})),F=useAnimatedStyle(()=>({opacity:A>0?Math.min(1,Math.max(0,C.value/A)):0})),E=useAnimatedStyle(()=>({opacity:_>0?Math.min(1,Math.max(0,-C.value/_)):0})),V=useMemo(()=>{const e=[];return n?.forEach(t=>{e.push({name:t.key,label:t.label})}),i?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[n,i]),D=useCallback(e=>{const t=e.nativeEvent.actionName,s=[...n??[],...i??[]].find(e=>e.key===t);s&&(!1!==c&&triggerHaptic("selection"),s.onPress())},[n,i,c]);return y||x?_jsxs(View,{style:[b.root,u],testID:S,accessibilityLabel:m,accessibilityActions:V,onAccessibilityAction:D,children:[y?_jsx(Animated.View,{style:[b.actionsRow,b.actionsLeft,{width:A},h,F],pointerEvents:"box-none",children:n?.map(e=>_jsx(ActionButton,{action:e,theme:p,actionStyles:f,width:g,onPress:k},e.key))}):null,x?_jsx(Animated.View,{style:[b.actionsRow,b.actionsRight,{width:_},h,E],pointerEvents:"box-none",children:i?.map(e=>_jsx(ActionButton,{action:e,theme:p,actionStyles:f,width:g,onPress:k},e.key))}):null,_jsx(GestureDetector,{gesture:P,children:_jsx(Animated.View,{style:[b.content,d,T],children:t})})]}):_jsx(View,{style:u,testID:S,children:t})};Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:n,width:i,onPress:s})=>{const o=e.tone??"neutral",r=toneToBg(t,o);return _jsxs(Pressable,{onPress:()=>s(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[n.button,{width:i,backgroundColor:r,paddingHorizontal:t.space.sm}],children:[e.icon?_jsx(View,{style:n.icon,children:e.icon}):null,_jsx(Text,{style:[n.label,{color:toneToOnColor(t,o),fontSize:t.text.sm.size,fontWeight:t.weight.semibold}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});export{Swipeable};export default Swipeable;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,fontFor,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},DISMISS_ACTIONS=[{name:"dismiss",label:"Dismiss"}],Toast=({toast:e,index:t,onDismiss:n,shownAt:i,runtime:s})=>{const a=useTheme(),r=usePresenceMotion(),o=r.duration("fast"),l=e.variant??"default",c=e.position??"bottom",u=useMemo(()=>buildStyles(a),[a]),d=useMemo(()=>tintFor(a,l),[a,l]),m=useMemo(()=>inkFor(a,l),[a,l]),p=a.components.toast["icon-circle-size"],g=a.text[a.components.toast["icon-glyph-text"]].size,h=a.components.toast["tint-bar-width"],f=a.settings.components.toast?.defaultDurationMs??3e3,b=a.settings.components.toast?.enableSwipeDismiss??!0,x="top"===c?-120:120,v=useRef(createAnimatedValue(r.reduced?0:x)).current,A=useRef(createAnimatedValue(0)).current,S=useRef(createAnimatedValue(0)).current,y=useRef(!1),w="top"===c?8*t:8*-t,M=Math.max(1-.04*t,.9),T=useRef(createAnimatedValue(w)).current;useEffect(()=>{setNativeValue(T,w)},[w,T]);const V=useMemo(()=>Animated.add(v,T),[v,T]),_=void 0!==e.action,D=e.duration??f,C=D>0&&_&&"web"===Platform.OS?Math.max(D,8e3):D,R=C<=0||_&&!0===s?.screenReaderOn,N=!0===e.countdown&&!R,I=useRef(createAnimatedValue(1)).current,E=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),P=useRef({touch:!1,pan:!1,hover:!1}),j=useRef(()=>{}),k=useRef({id:e.id,totalMs:C,shownAt:i,runtime:s,persistent:R,animateBar:!1});k.current={id:e.id,totalMs:C,shownAt:i,runtime:s,persistent:R,animateBar:N&&!r.reduced};const O=useCallback(()=>{const e=E.current,t=k.current,n=P.current;if(!e.initialised){e.initialised=!0;const n=t.runtime?.readRemaining(t.id),i=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=n??(t.totalMs>0?Math.max(t.totalMs-i,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(I,e.remaining/t.totalMs)}const i=!(t.persistent||y.current||n.touch||n.pan||n.hover);i&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,j.current()},e.remaining),t.animateBar&&Animated.timing(I,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:!0}).start()):i||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),I.stopAnimation())},[I]),dismiss=()=>{if(y.current)return;y.current=!0,O();const t=[Animated.timing(S,{toValue:0,duration:o,easing:Easing.bezier(...a.motion.ease.accelerate),useNativeDriver:!0})];r.reduced||t.push(Animated.timing(v,{toValue:x,duration:a.motion.duration.fast,easing:Easing.bezier(...a.motion.ease.accelerate),useNativeDriver:!0})),Animated.parallel(t).start(()=>n(e.id))};j.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}):Animated.parallel([Animated.spring(v,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{O()},[R,O]),useEffect(()=>()=>{const e=E.current,t=k.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),I.stopAnimation(),e.initialised&&t.totalMs>0&&!y.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[I]);const L=useCallback((e,t)=>{P.current[e]=t,O()},[O]),H=useCallback(()=>L("touch",!0),[L]),F=useCallback(e=>L("touch",(e.nativeEvent.touches?.length??0)>0),[L]),z=useCallback(()=>L("hover",!0),[L]),B=useCallback(()=>L("hover",!1),[L]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>L("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(A,t.dx);const n=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(S,n)},onPanResponderTerminate:()=>{if(L("pan",!1),r.reduced)return setNativeValue(A,0),void Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start();Animated.parallel([Animated.spring(A,{toValue:0,damping:a.motion.spring.snappy.damping,stiffness:a.motion.spring.snappy.stiffness,mass:a.motion.spring.snappy.mass,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,i)=>{if(Math.abs(i.dx)>80||Math.abs(i.vx)>.5){const t=i.dx>=0?1:-1;y.current=!0,L("pan",!1);const s=[Animated.timing(S,{toValue:0,duration:o,useNativeDriver:!0})];r.reduced||s.push(Animated.timing(A,{toValue:500*t,duration:a.motion.duration.fast,useNativeDriver:!0})),Animated.parallel(s).start(()=>n(e.id))}else L("pan",!1),r.reduced?(setNativeValue(A,0),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start()):Animated.parallel([Animated.spring(A,{toValue:0,useNativeDriver:!0}),Animated.spring(S,{toValue:1,useNativeDriver:!0})]).start()}}),[A,S,L,o,r.reduced,a.motion.duration.fast,a.motion.spring.snappy.damping,a.motion.spring.snappy.stiffness,a.motion.spring.snappy.mass,n,e.id]),W={accessibilityActions:DISMISS_ACTIONS,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[U,$]=useState(0),K=useMemo(()=>I.interpolate({inputRange:[0,1],outputRange:[-U,0]}),[I,U]),X=e.description?`${e.message}. ${e.description}`:e.message,Y=e.action&&N?`${e.action.label}, ${Math.ceil(C/1e3)} seconds`:e.action?.label;return _jsxs(Animated.View,{...b?G.panHandlers:{},..._?{}:{accessible:!0,...W},..."web"===Platform.OS?{onPointerEnter:z,onPointerLeave:B}:{},onTouchStart:H,onTouchEnd:F,onTouchCancel:F,accessibilityLabel:X,testID:e.testID,style:[u.container,{backgroundColor:a.colors.surface,borderRadius:a.radius.lg,...smoothCorners,padding:a.space.md,...a.shadow.elevated,opacity:S,transform:[{translateY:V},{translateX:A},{scale:M}]},e.style,e.containerStyle],children:[h>0?_jsx(View,{style:[u.tintBar,{width:h,backgroundColor:d}]}):null,_jsxs(View,{style:u.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[u.iconCircle,{width:p,height:p,borderRadius:a.radius.pill,...smoothCorners,backgroundColor:d+"22"},e.iconCircleStyle],children:_jsx(Text,{style:[u.iconGlyph,{color:m,fontSize:g}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:u.textBlock,children:[_jsx(Text,{style:[u.message,{color:a.colors["text-body"],fontSize:a.text.base.size,...fontFor(a,"semibold")},e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{style:[u.description,{color:a.colors["text-muted"],fontSize:a.text.sm.size}],numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:Y,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...W,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[u.actionBtn,{backgroundColor:t?a.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{style:{color:d,fontSize:a.text.sm.size,...fontFor(a,"semibold")},numberOfLines:1,children:e.action.label})}):null]}),N?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>$(e.nativeEvent.layout.width),testID:"toast-countdown",style:[u.countdownTrack,{backgroundColor:d+"22"}],children:[r.reduced?_jsx(View,{style:[u.countdownFill,{backgroundColor:d}]}):null,!r.reduced&&U>0?_jsx(Animated.View,{style:[u.countdownFill,{backgroundColor:d,transform:[{translateX:K}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,fontFor,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},DISMISS_ACTIONS=[{name:"dismiss",label:"Dismiss"}],Toast=({toast:e,index:t,onDismiss:n,shownAt:i,runtime:s})=>{const a=useTheme(),r=usePresenceMotion(),o=r.duration("fast"),l=e.variant??"default",c=e.position??"bottom",u=useMemo(()=>buildStyles(a),[a]),d=useMemo(()=>tintFor(a,l),[a,l]),m=useMemo(()=>inkFor(a,l),[a,l]),p=a.components.toast["icon-circle-size"],g=a.text[a.components.toast["icon-glyph-text"]].size,h=a.components.toast["tint-bar-width"],f=a.settings.components.toast?.defaultDurationMs??3e3,b=a.settings.components.toast?.enableSwipeDismiss??!0,x="top"===c?-120:120,v=useRef(createAnimatedValue(r.reduced?0:x)).current,A=useRef(createAnimatedValue(0)).current,S=useRef(createAnimatedValue(0)).current,y=useRef(!1),w="top"===c?8*t:8*-t,M=Math.max(1-.04*t,.9),T=useRef(createAnimatedValue(w)).current;useEffect(()=>{setNativeValue(T,w)},[w,T]);const V=useMemo(()=>Animated.add(v,T),[v,T]),_=void 0!==e.action,D=e.duration??f,C=D>0&&_&&"web"===Platform.OS?Math.max(D,8e3):D,R=C<=0||_&&!0===s?.screenReaderOn,N=!0===e.countdown&&!R,I=useRef(createAnimatedValue(1)).current,E=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),P=useRef({touch:!1,pan:!1,hover:!1}),j=useRef(()=>{}),k=useRef({id:e.id,totalMs:C,shownAt:i,runtime:s,persistent:R,animateBar:!1});k.current={id:e.id,totalMs:C,shownAt:i,runtime:s,persistent:R,animateBar:N&&!r.reduced};const O=useCallback(()=>{const e=E.current,t=k.current,n=P.current;if(!e.initialised){e.initialised=!0;const n=t.runtime?.readRemaining(t.id),i=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=n??(t.totalMs>0?Math.max(t.totalMs-i,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(I,e.remaining/t.totalMs)}const i=!(t.persistent||y.current||n.touch||n.pan||n.hover);i&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,j.current()},e.remaining),t.animateBar&&Animated.timing(I,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:!0}).start()):i||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),I.stopAnimation())},[I]),dismiss=()=>{if(y.current)return;y.current=!0,O();const t=[Animated.timing(S,{toValue:0,duration:o,easing:Easing.bezier(...a.motion.ease.accelerate),useNativeDriver:!0})];r.reduced||t.push(Animated.timing(v,{toValue:x,duration:a.motion.duration.fast,easing:Easing.bezier(...a.motion.ease.accelerate),useNativeDriver:!0})),Animated.parallel(t).start(()=>n(e.id))};j.current=dismiss,useEffect(()=>{const e=r.reduced?Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}):Animated.parallel([Animated.spring(v,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]);return e.start(),()=>e.stop()},[]),useEffect(()=>{O()},[R,O]),useEffect(()=>()=>{const e=E.current,t=k.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),I.stopAnimation(),e.initialised&&t.totalMs>0&&!y.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[I]);const L=useCallback((e,t)=>{P.current[e]=t,O()},[O]),H=useCallback(()=>L("touch",!0),[L]),F=useCallback(e=>L("touch",(e.nativeEvent.touches?.length??0)>0),[L]),z=useCallback(()=>L("hover",!0),[L]),B=useCallback(()=>L("hover",!1),[L]),G=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>L("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(A,t.dx);const n=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(S,n)},onPanResponderTerminate:()=>{if(L("pan",!1),r.reduced)return setNativeValue(A,0),void Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start();Animated.parallel([Animated.spring(A,{toValue:0,damping:a.motion.spring.snappy.damping,stiffness:a.motion.spring.snappy.stiffness,mass:a.motion.spring.snappy.mass,useNativeDriver:!0}),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0})]).start()},onPanResponderRelease:(t,i)=>{if(Math.abs(i.dx)>80||Math.abs(i.vx)>.5){const t=i.dx>=0?1:-1;y.current=!0,L("pan",!1);const s=[Animated.timing(S,{toValue:0,duration:o,useNativeDriver:!0})];r.reduced||s.push(Animated.timing(A,{toValue:500*t,duration:a.motion.duration.fast,useNativeDriver:!0})),Animated.parallel(s).start(()=>n(e.id))}else L("pan",!1),r.reduced?(setNativeValue(A,0),Animated.timing(S,{toValue:1,duration:o,useNativeDriver:!0}).start()):Animated.parallel([Animated.spring(A,{toValue:0,useNativeDriver:!0}),Animated.spring(S,{toValue:1,useNativeDriver:!0})]).start()}}),[A,S,L,o,r.reduced,a.motion.duration.fast,a.motion.spring.snappy.damping,a.motion.spring.snappy.stiffness,a.motion.spring.snappy.mass,n,e.id]),$={accessibilityActions:DISMISS_ACTIONS,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[W,U]=useState(0),K=useMemo(()=>I.interpolate({inputRange:[0,1],outputRange:[-W,0]}),[I,W]),X=e.description?`${e.message}. ${e.description}`:e.message,Y=e.action&&N?`${e.action.label}, ${Math.ceil(C/1e3)} seconds`:e.action?.label;return _jsxs(Animated.View,{...b?G.panHandlers:{},..._?{}:{accessible:!0,...$},..."web"===Platform.OS?{onPointerEnter:z,onPointerLeave:B}:{},onTouchStart:H,onTouchEnd:F,onTouchCancel:F,accessibilityLabel:X,testID:e.testID,style:[u.container,{backgroundColor:a.colors.surface,borderRadius:a.radius.lg,...smoothCorners,padding:a.space.md,...a.shadow.elevated,opacity:S,transform:[{translateY:V},{translateX:A},{scale:M}]},e.style,e.containerStyle],children:[h>0?_jsx(View,{style:[u.tintBar,{width:h,backgroundColor:d}]}):null,_jsxs(View,{style:u.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[u.iconCircle,{width:p,height:p,borderRadius:a.radius.pill,...smoothCorners,backgroundColor:`${d}22`},e.iconCircleStyle],children:_jsx(Text,{style:[u.iconGlyph,{color:m,fontSize:g}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:u.textBlock,children:[_jsx(Text,{style:[u.message,{color:a.colors["text-body"],fontSize:a.text.base.size,...fontFor(a,"semibold")},e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{style:[u.description,{color:a.colors["text-muted"],fontSize:a.text.sm.size}],numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:Y,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...$,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[u.actionBtn,{backgroundColor:t?a.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{style:{color:d,fontSize:a.text.sm.size,...fontFor(a,"semibold")},numberOfLines:1,children:e.action.label})}):null]}),N?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>U(e.nativeEvent.layout.width),testID:"toast-countdown",style:[u.countdownTrack,{backgroundColor:`${d}22`}],children:[r.reduced?_jsx(View,{style:[u.countdownFill,{backgroundColor:d}]}):null,!r.reduced&&W>0?_jsx(Animated.View,{style:[u.countdownFill,{backgroundColor:d,transform:[{translateX:K}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;default:return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];default:return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";default:return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:19},textBlock:{flex:1,paddingRight:e.space.sm},message:{lineHeight:20},description:{marginTop:e.space.xxs,lineHeight:18},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
@@ -1 +1 @@
1
- "use strict";const tokenize=t=>{const e=[],r=/[^.[\]]+/g;let n;for(;null!==(n=r.exec(t));){const t=n[0];e.push(/^\d+$/.test(t)?Number(t):t)}return e};export const getPath=(t,e)=>{const r=tokenize(e);let n=t;for(const t of r){if(null==n||"object"!=typeof n)return;n=n[t]}return n};export const setPath=(t,e,r)=>{const n=tokenize(e);if(0===n.length)return t;const o=Array.isArray(t)?[...t]:{...t};let s=o;for(let t=0;t<n.length-1;t++){const e=n[t],r=n[t+1],o=s[e],l=null!=o&&"object"==typeof o?Array.isArray(o)?[...o]:{...o}:"number"==typeof r?[]:{};s[e]=l,s=l}return s[n[n.length-1]]=r,o};export const deletePath=(t,e)=>{const r=tokenize(e);if(0===r.length)return t;const n=Array.isArray(t)?[...t]:{...t};let o=n;for(let t=0;t<r.length-1;t++){const e=r[t],s=o[e];if(null==s||"object"!=typeof s)return n;const l=Array.isArray(s)?[...s]:{...s};o[e]=l,o=l}const s=r[r.length-1];return Array.isArray(o)&&"number"==typeof s?o.splice(s,1):delete o[s],n};
1
+ "use strict";const tokenize=t=>{const e=[],r=/[^.[\]]+/g;for(const n of t.matchAll(r)){const t=n[0];e.push(/^\d+$/.test(t)?Number(t):t)}return e};export const getPath=(t,e)=>{const r=tokenize(e);let n=t;for(const t of r){if(null==n||"object"!=typeof n)return;n=n[t]}return n};export const setPath=(t,e,r)=>{const n=tokenize(e);if(0===n.length)return t;const o=Array.isArray(t)?[...t]:{...t};let s=o;for(let t=0;t<n.length-1;t++){const e=n[t],r=n[t+1],o=s[e],c=null!=o&&"object"==typeof o?Array.isArray(o)?[...o]:{...o}:"number"==typeof r?[]:{};s[e]=c,s=c}return s[n[n.length-1]]=r,o};export const deletePath=(t,e)=>{const r=tokenize(e);if(0===r.length)return t;const n=Array.isArray(t)?[...t]:{...t};let o=n;for(let t=0;t<r.length-1;t++){const e=r[t],s=o[e];if(null==s||"object"!=typeof s)return n;const c=Array.isArray(s)?[...s]:{...s};o[e]=c,o=c}const s=r[r.length-1];return Array.isArray(o)&&"number"==typeof s?o.splice(s,1):delete o[s],n};
@@ -1 +1 @@
1
- "use strict";import{AccessibilityInfo,Platform}from"react-native";let webRegions=null;const webRegion=e=>{if("undefined"==typeof document)return null;if(!webRegions||!webRegions.polite.isConnected){const make=e=>{const t=document.createElement("div");return t.setAttribute("aria-live",e),t.setAttribute("aria-atomic","true"),t.setAttribute("role","assertive"===e?"alert":"status"),Object.assign(t.style,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"}),document.body.appendChild(t),t};webRegions={polite:make("polite"),assertive:make("assertive")}}return e?webRegions.polite:webRegions.assertive};export const announce=(e,t)=>{if(!e)return;const i=!1!==t?.polite;if("web"===Platform.OS){const t=webRegion(i);return void(t&&(t.textContent="",setTimeout(()=>{t.textContent=e},50)))}"ios"!==Platform.OS?AccessibilityInfo.announceForAccessibility(e):AccessibilityInfo.announceForAccessibilityWithOptions(e,i?{queue:!0}:{queue:!1,priority:"high"})};
1
+ "use strict";import{AccessibilityInfo,Platform}from"react-native";let webRegions=null;const webRegion=e=>{if("undefined"==typeof document)return null;if(!webRegions?.polite.isConnected){const make=e=>{const t=document.createElement("div");return t.setAttribute("aria-live",e),t.setAttribute("aria-atomic","true"),t.setAttribute("role","assertive"===e?"alert":"status"),Object.assign(t.style,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"}),document.body.appendChild(t),t};webRegions={polite:make("polite"),assertive:make("assertive")}}return e?webRegions.polite:webRegions.assertive};export const announce=(e,t)=>{if(!e)return;const i=!1!==t?.polite;if("web"===Platform.OS){const t=webRegion(i);return void(t&&(t.textContent="",setTimeout(()=>{t.textContent=e},50)))}"ios"!==Platform.OS?AccessibilityInfo.announceForAccessibility(e):AccessibilityInfo.announceForAccessibilityWithOptions(e,i?{queue:!0}:{queue:!1,priority:"high"})};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-ui",
3
- "version": "0.98.0",
3
+ "version": "0.99.0",
4
4
  "description": "Beautiful, animated, accessible React Native components, theme and form engine for Webority projects.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -86,8 +86,8 @@
86
86
  "react-native-safe-area-context": ">=5.4.0",
87
87
  "react-native-svg": ">=15.0.0",
88
88
  "react-native-worklets": ">=0.10.0",
89
- "@webority/canvas-kit": "0.98.0",
90
- "@webority/mobile-core": "0.98.0"
89
+ "@webority/canvas-kit": "0.99.0",
90
+ "@webority/mobile-core": "0.99.0"
91
91
  },
92
92
  "peerDependenciesMeta": {
93
93
  "@webority/canvas-kit": {
@@ -148,10 +148,10 @@
148
148
  "react-test-renderer": "19.2.8",
149
149
  "rimraf": "6.1.3",
150
150
  "typescript": "5.9.3",
151
- "@webority/canvas-kit": "0.98.0",
152
- "@webority/mobile-core": "0.98.0",
153
- "@webority/tokens": "0.98.0",
154
- "@webority/mobile-dev": "0.0.0"
151
+ "@webority/canvas-kit": "0.99.0",
152
+ "@webority/mobile-core": "0.99.0",
153
+ "@webority/mobile-dev": "0.0.0",
154
+ "@webority/tokens": "0.99.0"
155
155
  },
156
156
  "scripts": {
157
157
  "build": "bob build && node ../mobile-dev/scripts/minify-lib.mjs && node -e \"require('node:fs').rmSync('dist/canvas-kit',{recursive:true,force:true})\" && node ../canvas-kit/dist/cli.js build --config canvas-kit.json --out dist/canvas-kit",