@bloxwap/hig 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +2 -2
  2. package/chart/README.md +13 -2
  3. package/chart/dist/altimeter-burst.d.ts +4 -0
  4. package/chart/dist/altimeter-burst.js +43 -0
  5. package/chart/dist/altimeter-chart.d.ts +52 -0
  6. package/chart/dist/altimeter-chart.js +275 -0
  7. package/chart/dist/altimeter-model.d.ts +43 -0
  8. package/chart/dist/altimeter-model.js +148 -0
  9. package/chart/dist/altimeter-targets.d.ts +33 -0
  10. package/chart/dist/altimeter-targets.js +88 -0
  11. package/chart/dist/bitcoin-price.d.ts +8 -0
  12. package/chart/dist/bitcoin-price.js +41 -0
  13. package/chart/dist/champions-league.d.ts +19 -0
  14. package/chart/dist/champions-league.js +104 -0
  15. package/chart/dist/index.d.ts +6 -0
  16. package/chart/dist/index.js +5 -0
  17. package/chart/dist/outcome-chart.d.ts +37 -0
  18. package/chart/dist/outcome-chart.js +212 -0
  19. package/chart/dist/outcome-model.d.ts +43 -0
  20. package/chart/dist/outcome-model.js +71 -0
  21. package/chart/dist/plus-grid.d.ts +6 -0
  22. package/chart/dist/plus-grid.js +29 -0
  23. package/contracts/README.md +1 -1
  24. package/contracts/dist/avatar.d.ts +68 -0
  25. package/contracts/dist/avatar.js +93 -0
  26. package/contracts/dist/confetti.d.ts +174 -0
  27. package/contracts/dist/confetti.js +138 -0
  28. package/contracts/dist/decimal.d.ts +7 -0
  29. package/contracts/dist/decimal.js +35 -0
  30. package/contracts/dist/index.d.ts +29 -2
  31. package/contracts/dist/index.js +123 -4
  32. package/contracts/dist/invariants.d.ts +17 -0
  33. package/contracts/dist/invariants.js +24 -0
  34. package/contracts/dist/messages.d.ts +56 -2
  35. package/contracts/dist/messages.js +20 -2
  36. package/contracts/dist/number-flow.d.ts +90 -0
  37. package/contracts/dist/number-flow.js +150 -0
  38. package/contracts/dist/qr.d.ts +151 -0
  39. package/contracts/dist/qr.js +581 -0
  40. package/contracts/dist/toast.d.ts +168 -0
  41. package/contracts/dist/toast.js +171 -0
  42. package/feedback/README.md +1 -1
  43. package/feedback/dist/contract.js +1 -1
  44. package/feedback/dist/react.js +2 -4
  45. package/native/README.md +6 -1
  46. package/native/dist/account-block.d.ts +10 -1
  47. package/native/dist/account-block.js +17 -7
  48. package/native/dist/animated-number-model.d.ts +41 -1
  49. package/native/dist/animated-number-model.js +201 -23
  50. package/native/dist/animated-number.d.ts +39 -1
  51. package/native/dist/animated-number.js +161 -16
  52. package/native/dist/announce.d.ts +2 -0
  53. package/native/dist/announce.js +10 -0
  54. package/native/dist/asset-balance-row.d.ts +3 -1
  55. package/native/dist/asset-balance-row.js +15 -4
  56. package/native/dist/assets-block.d.ts +115 -0
  57. package/native/dist/assets-block.js +87 -0
  58. package/native/dist/async-result.d.ts +2 -0
  59. package/native/dist/async-result.js +11 -0
  60. package/native/dist/avatar-frame.d.ts +29 -0
  61. package/native/dist/avatar-frame.js +56 -0
  62. package/native/dist/avatar.d.ts +21 -0
  63. package/native/dist/avatar.js +31 -0
  64. package/native/dist/bar-mark.d.ts +2 -0
  65. package/native/dist/bar-mark.js +4 -2
  66. package/native/dist/bar-pnl.js +2 -1
  67. package/native/dist/blocks.d.ts +6 -1
  68. package/native/dist/blocks.js +5 -0
  69. package/native/dist/brand.js +2 -1
  70. package/native/dist/button.d.ts +7 -2
  71. package/native/dist/button.js +13 -3
  72. package/native/dist/checkbox.js +2 -1
  73. package/native/dist/confetti.d.ts +33 -0
  74. package/native/dist/confetti.js +143 -0
  75. package/native/dist/confirm-block.d.ts +98 -0
  76. package/native/dist/confirm-block.js +48 -0
  77. package/native/dist/data.js +2 -0
  78. package/native/dist/explainer-block.d.ts +91 -0
  79. package/native/dist/explainer-block.js +34 -0
  80. package/native/dist/field.d.ts +5 -1
  81. package/native/dist/field.js +27 -6
  82. package/native/dist/gesture-sheet-model.d.ts +50 -0
  83. package/native/dist/gesture-sheet-model.js +105 -0
  84. package/native/dist/gesture-sheet-next.d.ts +82 -0
  85. package/native/dist/gesture-sheet-next.js +315 -0
  86. package/native/dist/gesture-sheet.d.ts +5 -1
  87. package/native/dist/gesture-sheet.js +13 -6
  88. package/native/dist/icons.d.ts +9 -6
  89. package/native/dist/icons.js +25 -24
  90. package/native/dist/language-block.d.ts +10 -1
  91. package/native/dist/language-block.js +11 -4
  92. package/native/dist/list-group.d.ts +3 -1
  93. package/native/dist/list-group.js +26 -13
  94. package/native/dist/manage-position-block.d.ts +8 -1
  95. package/native/dist/manage-position-block.js +7 -2
  96. package/native/dist/market-row.js +19 -8
  97. package/native/dist/navigation.js +5 -3
  98. package/native/dist/number-format.d.ts +6 -0
  99. package/native/dist/number-format.js +9 -0
  100. package/native/dist/pickers.d.ts +8 -0
  101. package/native/dist/pickers.js +3 -3
  102. package/native/dist/position-block.d.ts +5 -5
  103. package/native/dist/preset-group.d.ts +31 -0
  104. package/native/dist/preset-group.js +39 -0
  105. package/native/dist/preset-picker-block.d.ts +107 -0
  106. package/native/dist/preset-picker-block.js +43 -0
  107. package/native/dist/profile-block.d.ts +10 -1
  108. package/native/dist/profile-block.js +8 -3
  109. package/native/dist/provider.d.ts +5 -2
  110. package/native/dist/provider.js +27 -5
  111. package/native/dist/qr-code.d.ts +33 -0
  112. package/native/dist/qr-code.js +29 -0
  113. package/native/dist/radio-group.d.ts +19 -7
  114. package/native/dist/radio-group.js +39 -10
  115. package/native/dist/reward-block.d.ts +10 -7
  116. package/native/dist/reward-block.js +9 -4
  117. package/native/dist/screen-header.d.ts +13 -3
  118. package/native/dist/screen-header.js +12 -4
  119. package/native/dist/select.js +4 -2
  120. package/native/dist/selection.d.ts +2 -1
  121. package/native/dist/selection.js +1 -0
  122. package/native/dist/setting-switch.d.ts +1 -1
  123. package/native/dist/setting-switch.js +7 -3
  124. package/native/dist/slider.js +5 -1
  125. package/native/dist/sound-haptics-block.js +1 -1
  126. package/native/dist/status.d.ts +41 -9
  127. package/native/dist/status.js +34 -17
  128. package/native/dist/sticky-header.js +9 -1
  129. package/native/dist/swap-amount-card.d.ts +57 -0
  130. package/native/dist/swap-amount-card.js +31 -0
  131. package/native/dist/swap-panel-block.d.ts +9 -3
  132. package/native/dist/swap-panel-block.js +59 -33
  133. package/native/dist/swap-parts.d.ts +3 -10
  134. package/native/dist/swap-parts.js +22 -24
  135. package/native/dist/swap-shared.d.ts +2 -2
  136. package/native/dist/swap-shared.js +10 -6
  137. package/native/dist/swap-views.js +1 -1
  138. package/native/dist/target-block.d.ts +7 -1
  139. package/native/dist/target-block.js +13 -6
  140. package/native/dist/toast.d.ts +47 -0
  141. package/native/dist/toast.js +386 -0
  142. package/native/dist/token-action-block.d.ts +10 -1
  143. package/native/dist/token-action-block.js +9 -4
  144. package/native/dist/trade-history-list-block.js +7 -4
  145. package/native/dist/wallet-address-core.js +6 -3
  146. package/native-fonts/README.md +1 -1
  147. package/og-fonts/README.md +1 -1
  148. package/package.json +111 -2
  149. package/react/README.md +3 -1
  150. package/react/dist/animated-number-flow.d.ts +72 -0
  151. package/react/dist/animated-number-flow.js +316 -0
  152. package/react/dist/animated-number-model.d.ts +18 -0
  153. package/react/dist/animated-number-model.js +75 -5
  154. package/react/dist/animated-number.d.ts +45 -1
  155. package/react/dist/animated-number.js +137 -6
  156. package/react/dist/asset-balance-row.d.ts +3 -1
  157. package/react/dist/asset-balance-row.js +10 -4
  158. package/react/dist/async-result.d.ts +2 -0
  159. package/react/dist/async-result.js +11 -0
  160. package/react/dist/avatar.d.ts +25 -0
  161. package/react/dist/avatar.js +50 -0
  162. package/react/dist/blocks/account-block.d.ts +5 -1
  163. package/react/dist/blocks/account-block.js +11 -6
  164. package/react/dist/blocks/assets-block.d.ts +106 -0
  165. package/react/dist/blocks/assets-block.js +135 -0
  166. package/react/dist/blocks/confirm-block.d.ts +91 -0
  167. package/react/dist/blocks/confirm-block.js +31 -0
  168. package/react/dist/blocks/explainer-block.d.ts +80 -0
  169. package/react/dist/blocks/explainer-block.js +20 -0
  170. package/react/dist/blocks/install-command.js +3 -1
  171. package/react/dist/blocks/language-block.d.ts +5 -1
  172. package/react/dist/blocks/language-block.js +4 -3
  173. package/react/dist/blocks/manage-position-block.d.ts +3 -1
  174. package/react/dist/blocks/manage-position-block.js +2 -2
  175. package/react/dist/blocks/market-row.js +8 -3
  176. package/react/dist/blocks/notifications-block.d.ts +3 -1
  177. package/react/dist/blocks/notifications-block.js +2 -2
  178. package/react/dist/blocks/pickers.d.ts +9 -0
  179. package/react/dist/blocks/pickers.js +4 -2
  180. package/react/dist/blocks/position-block.d.ts +3 -3
  181. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  182. package/react/dist/blocks/preset-picker-block.js +19 -0
  183. package/react/dist/blocks/profile-block.d.ts +5 -1
  184. package/react/dist/blocks/profile-block.js +12 -13
  185. package/react/dist/blocks/reward-block.d.ts +13 -8
  186. package/react/dist/blocks/reward-block.js +7 -4
  187. package/react/dist/blocks/screen-header.d.ts +10 -2
  188. package/react/dist/blocks/screen-header.js +7 -4
  189. package/react/dist/blocks/setting-switch.js +6 -3
  190. package/react/dist/blocks/signals-block.d.ts +3 -1
  191. package/react/dist/blocks/signals-block.js +4 -3
  192. package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
  193. package/react/dist/blocks/sound-haptics-block.js +2 -2
  194. package/react/dist/blocks/sticky-header.d.ts +14 -4
  195. package/react/dist/blocks/sticky-header.js +68 -8
  196. package/react/dist/blocks/swap/settings.js +2 -1
  197. package/react/dist/blocks/swap/shared.d.ts +22 -22
  198. package/react/dist/blocks/swap/shared.js +30 -28
  199. package/react/dist/blocks/swap-panel-block.d.ts +10 -3
  200. package/react/dist/blocks/swap-panel-block.js +71 -36
  201. package/react/dist/blocks/target-block.d.ts +7 -1
  202. package/react/dist/blocks/target-block.js +10 -4
  203. package/react/dist/blocks/token-action-block.d.ts +5 -1
  204. package/react/dist/blocks/token-action-block.js +2 -2
  205. package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
  206. package/react/dist/blocks/trade-history-detail-block.js +2 -2
  207. package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
  208. package/react/dist/blocks/trade-history-list-block.js +7 -4
  209. package/react/dist/blocks.d.ts +5 -1
  210. package/react/dist/blocks.js +4 -0
  211. package/react/dist/brand.js +2 -1
  212. package/react/dist/button.d.ts +9 -3
  213. package/react/dist/button.js +8 -3
  214. package/react/dist/confetti.d.ts +27 -0
  215. package/react/dist/confetti.js +240 -0
  216. package/react/dist/data.js +8 -1
  217. package/react/dist/field.d.ts +6 -1
  218. package/react/dist/field.js +18 -9
  219. package/react/dist/gesture-sheet.d.ts +15 -1
  220. package/react/dist/gesture-sheet.js +53 -8
  221. package/react/dist/list-group.js +11 -7
  222. package/react/dist/navigation.js +11 -3
  223. package/react/dist/overlay.d.ts +28 -3
  224. package/react/dist/overlay.js +29 -3
  225. package/react/dist/preset-group.d.ts +30 -0
  226. package/react/dist/preset-group.js +13 -0
  227. package/react/dist/provider.d.ts +2 -2
  228. package/react/dist/provider.js +23 -6
  229. package/react/dist/qr-code.d.ts +32 -0
  230. package/react/dist/qr-code.js +28 -0
  231. package/react/dist/select.js +10 -3
  232. package/react/dist/selection.d.ts +13 -5
  233. package/react/dist/selection.js +13 -8
  234. package/react/dist/slider.js +5 -1
  235. package/react/dist/status.d.ts +14 -10
  236. package/react/dist/status.js +17 -9
  237. package/react/dist/styles.css +238 -163
  238. package/react/dist/toast.d.ts +19 -12
  239. package/react/dist/toast.js +29 -7
  240. package/react/dist/wallet-address-core.d.ts +8 -4
  241. package/react/dist/wallet-address-core.js +10 -5
  242. package/tokens/README.md +2 -2
  243. package/tokens/dist/index.d.ts +16 -0
  244. package/tokens/dist/index.js +16 -0
  245. package/tokens/dist/manifest.json +8 -0
  246. package/tokens/dist/tokens.css +6 -0
@@ -1,10 +1,13 @@
1
+ import { decimal, decimalMultiply, decimalDivide } from '@bloxwap/hig/contracts';
1
2
  /** Where Back leads: slippage and fees return to settings, everything else to the main form. */
2
3
  export const swapParentView = (view) => view === 'slippage' || view === 'fees' ? 'settings' : 'main';
3
4
  export const slippagePresets = [0.001, 0.005, 0.01];
4
5
  export function swapAction(from, to) {
5
- if (!from || !to || from.symbol === to.symbol)
6
+ if (!from || !to)
6
7
  return 'send';
7
- return from.chainId === to.chainId ? 'swap' : 'bridge';
8
+ if (String(from.chainId) !== String(to.chainId))
9
+ return 'bridge';
10
+ return from.id === to.id ? 'send' : 'swap';
8
11
  }
9
12
  /** A clean numeric string: no trailing zeros, at most `digits` decimals. */
10
13
  export const trimNumber = (value, digits = 8) => String(Number((Number.isFinite(value) ? value : 0).toFixed(digits)));
@@ -20,8 +23,8 @@ export function sanitizeAmount(raw) {
20
23
  /** Token units shown in the active denomination. Dollars floor to the cent so Max never resolves to more than the balance. */
21
24
  export function unitsToEntry(units, mode, price) {
22
25
  if (mode === 'token')
23
- return trimNumber(units);
24
- return price > 0 ? String(Math.floor(units * price * 100) / 100) : '0';
26
+ return decimal(units);
27
+ return price > 0 ? decimalMultiply(units, price, 2) : '0';
25
28
  }
26
29
  /** Applies one keypad key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
27
30
  export function applyAmountKey(current, key, mode, decimals) {
@@ -52,9 +55,10 @@ export const formatPercent = (fraction) => `${Number((fraction * 100).toFixed(4)
52
55
  /** A small trial amount: 1% of holdings, capped at about one dollar's worth. */
53
56
  export function testAmount(token) {
54
57
  const balance = token.balance ?? 0, price = token.price ?? 0;
55
- if (!(balance > 0))
58
+ if (!(balance > 0) || !Number.isFinite(balance))
56
59
  return 0;
57
- return Number(Math.min(balance * 0.01, price > 0 ? 1 / price : balance * 0.01).toFixed(8));
60
+ const fraction = decimalDivide(balance, 100, token.decimals ?? 18);
61
+ return Number(decimal(price > 0 ? Math.min(Number(fraction), Number(decimalDivide(1, price, token.decimals ?? 18))) : fraction, token.decimals ?? 18));
58
62
  }
59
63
  export const shortAddress = (address) => address.length <= 12 ? address : `${address.slice(0, 6)}…${address.slice(-4)}`;
60
64
  /** A stable flat colour for a wallet address, so the same wallet always looks the same. */
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { Pressable, View } from 'react-native';
4
- import { formatNumber } from '@bloxwap/hig/contracts';
4
+ import { formatNumber } from './number-format.js';
5
5
  import { useColors, useFills, useHIG, useMessages, useNumberLocale, usePresentNumber } from './provider.js';
6
6
  import { Text } from './surface.js';
7
7
  import { Field, Input } from './field.js';
@@ -24,6 +24,8 @@ export interface TargetBlockLabels {
24
24
  custom: string;
25
25
  /** Accessible name of the info button that shows `note`: How this order fills. Without it the note is always shown. */
26
26
  info?: string;
27
+ /** Accessible name of the quick choices, not drawn: Quick targets. Defaults to `title`. */
28
+ presets?: string;
27
29
  }
28
30
  export interface TargetBlockProps {
29
31
  kind: TargetKind;
@@ -90,7 +92,11 @@ export interface TargetUnitOption {
90
92
  export declare function targetPresets(presets: readonly (number | TargetPreset)[]): TargetPreset[];
91
93
  /** The units as `{unit, disabled}`, whichever form the host gave. */
92
94
  export declare function targetUnits(units: readonly (TargetUnit | TargetUnitOption)[]): TargetUnitOption[];
93
- /** Number format of a target in a unit. Dollars and percents carry their sign; `short` drops the cents of a whole dollar amount, for a preset. */
95
+ /**
96
+ * Number format of a target in a unit. Dollars and percents carry their sign. `short` is a preset's value: a whole dollar amount
97
+ * or a whole price drops its fraction digits (`+$10`, `$63,000`), whatever fraction digits `priceOptions` fix, so a preset reads
98
+ * the same on web and native; a price formatted by significant digits keeps `priceOptions`.
99
+ */
94
100
  export declare function targetFormat(unit: TargetUnit, priceOptions?: Intl.NumberFormatOptions, short?: number): Intl.NumberFormatOptions;
95
101
  /**
96
102
  * Where each known price sits on the bar, as a fraction of its width from the low-price edge, the prices in price order, and
@@ -1,12 +1,14 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { Pressable, View } from 'react-native';
4
- import { formatNumber } from '@bloxwap/hig/contracts';
4
+ import { formatNumber } from './number-format.js';
5
5
  import { useColors, useFills, useHIG, useMessages, useNumberLocale, usePresentNumber } from './provider.js';
6
6
  import { StickyHeaderLayout } from './sticky-header.js';
7
7
  import { Surface, Text } from './surface.js';
8
+ import { barFillOpacity } from './bar-mark.js';
8
9
  import { Button, IconButton } from './button.js';
9
10
  import { SegmentedControl } from './radio-group.js';
11
+ import { PresetGroup } from './preset-group.js';
10
12
  import { ChevronIcon, SeverityIcon } from './icons.js';
11
13
  import { AnimatedNumberReadout } from './animated-number.js';
12
14
  import { formatNumberReadout } from './animated-number-model.js';
@@ -18,13 +20,18 @@ const usd = { style: 'currency', currency: 'USD' };
18
20
  const allUnits = ['dollar', 'price', 'percent'];
19
21
  const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
20
22
  const known = (value) => value != null && Number.isFinite(value);
21
- /** Number format of a target in a unit. Dollars and percents carry their sign; `short` drops the cents of a whole dollar amount, for a preset. */
23
+ /**
24
+ * Number format of a target in a unit. Dollars and percents carry their sign. `short` is a preset's value: a whole dollar amount
25
+ * or a whole price drops its fraction digits (`+$10`, `$63,000`), whatever fraction digits `priceOptions` fix, so a preset reads
26
+ * the same on web and native; a price formatted by significant digits keeps `priceOptions`.
27
+ */
22
28
  export function targetFormat(unit, priceOptions = usd, short) {
29
+ const whole = short !== undefined && Number.isInteger(short);
23
30
  if (unit === 'price')
24
- return priceOptions;
31
+ return whole && priceOptions.minimumSignificantDigits === undefined && priceOptions.maximumSignificantDigits === undefined ? { ...priceOptions, minimumFractionDigits: 0, maximumFractionDigits: 0 } : priceOptions;
25
32
  if (unit === 'percent')
26
33
  return { style: 'percent', maximumFractionDigits: 2, signDisplay: 'exceptZero' };
27
- return { ...usd, signDisplay: 'exceptZero', ...(short !== undefined && Number.isInteger(short) ? { maximumFractionDigits: 0 } : null) };
34
+ return { ...usd, signDisplay: 'exceptZero', ...(whole ? { maximumFractionDigits: 0 } : null) };
28
35
  }
29
36
  /**
30
37
  * Where each known price sits on the bar, as a fraction of its width from the low-price edge, the prices in price order, and
@@ -61,13 +68,13 @@ export function TargetBlock({ kind, labels, position, orderType, note, entry, tr
61
68
  const target = trigger !== undefined ? trigger : unit === 'price' ? value : null;
62
69
  const { positions, order, from, to } = targetLayout({ entry, trigger: target });
63
70
  const prices = { entry, trigger: target };
64
- const stop = kind === 'stop-loss', tone = stop ? colors.negative : colors.positive, intent = stop ? 'destructive' : 'primary';
71
+ const stop = kind === 'stop-loss', tone = stop ? colors.negative : colors.positive, intent = stop ? 'destructive' : 'primary', onFill = stop ? colors.background : colors.onAction;
65
72
  const triggerLeads = (positions.trigger ?? 0) < (positions.entry ?? 0);
66
73
  const align = (index) => order.length > 1 && index === order.length - 1 ? 'flex-end' : order.length === 3 && index === 1 ? 'center' : 'flex-start';
67
74
  const part = (grow) => ({ flexGrow: grow, flexShrink: 1, flexBasis: 0, backgroundColor: fills.raised });
68
75
  const sticky = !!stickyHeader;
69
76
  const header = _jsxs(View, { testID: 'target-header', style: { flexDirection: 'row', alignItems: 'center', minHeight: 44 }, children: [_jsx(View, { style: { minWidth: side, alignItems: 'flex-start' }, children: onBack ? _jsx(IconButton, { intent: 'ghost', label: t.back, suppressFeedback: true, testID: 'target-back', onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: 'target-title', nativeID: headingId, accessibilityRole: 'header', numberOfLines: 1, style: { flex: 1, textAlign: 'center', fontSize: 17, lineHeight: 24, fontWeight: '600', color: colors.text }, children: labels.title }), _jsx(View, { style: { minWidth: side, alignItems: 'flex-end' }, children: info ? (() => { const button = _jsx(IconButton, { intent: 'ghost', label: info, suppressFeedback: true, testID: 'target-info', accessibilityState: { expanded: open }, onPress: () => setOpen(!open), children: _jsx(SeverityIcon, { kind: 'info', color: colors.text }) }); return pair ? _jsxs(View, { testID: 'target-header-actions', style: { direction, flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [button, headerAction] }) : button; })() : headerAction })] });
70
- const body = _jsxs(_Fragment, { children: [_jsx(View, { style: { alignItems: 'center', marginTop: 16 }, children: _jsx(AnimatedNumberReadout, { testID: 'target-amount', value: value, options: targetFormat(unit, priceOptions), style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9, textAlign: 'center' } }) }), note && !info ? _jsx(Text, { testID: 'target-note', style: { color: colors.muted, fontSize: 14, lineHeight: 21, textAlign: 'center', marginTop: 16 }, children: note }) : null, _jsxs(PriceCard, { testID: 'target-prices', style: { gap: 12, marginTop: 16, minWidth: 0 }, children: [position || orderType ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [position ? _jsx(Text, { testID: 'target-position', accessibilityRole: 'header', style: { fontSize: 16, lineHeight: 24, fontWeight: '600', flexShrink: 1 }, children: position }) : _jsx(View, {}), orderType ? _jsx(Text, { testID: 'target-order-type', style: { color: colors.muted, fontSize: 14, lineHeight: 21, flexShrink: 1 }, children: orderType }) : null] }) : null, _jsxs(View, { ...hidden, testID: 'target-bar', style: { flexDirection: 'row', height: 24, borderRadius: 8, overflow: 'hidden' }, children: [_jsx(View, { style: part(from) }), to > from ? _jsx(View, { testID: 'target-move', style: { flexGrow: to - from, flexShrink: 1, flexBasis: 0, minWidth: 6, backgroundColor: tone, borderStartWidth: 3, borderEndWidth: 3, borderStartColor: triggerLeads ? tone : colors.text, borderEndColor: triggerLeads ? colors.text : tone } }) : null, _jsx(View, { style: part(1 - to) })] }), _jsx(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: order.map((price, index) => _jsxs(View, { accessible: true, accessibilityLabel: `${labels[price]}, ${formatNumberReadout(prices[price], locale, present(priceOptions)).text}`, testID: `target-${price}`, style: { alignItems: align(index), flexShrink: 1, minWidth: 0 }, children: [_jsx(View, { ...hidden, children: _jsx(AnimatedNumberReadout, { value: prices[price], options: priceOptions, tone: price === 'trigger' ? (stop ? 'negative' : 'positive') : 'text', style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }) }), _jsx(Text, { ...hidden, numberOfLines: 1, style: { color: colors.muted, fontSize: 12, lineHeight: 16 }, children: labels[price] })] }, price)) })] }), units.length > 1 ? _jsx(View, { testID: 'target-units', style: { marginTop: 16 }, children: _jsx(SegmentedControl, { label: labels.unit, options: targetUnits(units).map(option => ({ value: option.unit, label: labels.units[option.unit], disabled: option.disabled })), value: unit, onValueChange: next => onUnitChange?.(next) }) }) : null, onCustom && customText === null ? _jsxs(Pressable, { testID: 'target-custom', accessibilityRole: 'button', accessibilityState: customValue !== undefined ? { selected: false } : undefined, onPress: onCustom, style: ({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 48, paddingHorizontal: 16, borderRadius: 9999, backgroundColor: pressed ? fills.raised : fills.well, marginTop: 16 }), children: [_jsx(Text, { numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: labels.custom }), _jsx(View, { ...hidden, style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: colors.muted }) })] }) : null, onCustom && customText !== null ? _jsxs(Pressable, { testID: 'target-custom', accessibilityRole: 'button', accessibilityLabel: `${labels.custom}, ${customText}`, accessibilityState: { selected: true }, onPress: onCustom, style: ({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 48, paddingHorizontal: 14, borderRadius: 9999, borderWidth: 2, borderColor: tone, backgroundColor: pressed ? fills.raised : fills.well, marginTop: 16 }), children: [_jsx(Text, { ...hidden, numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: labels.custom }), _jsxs(View, { ...hidden, style: { direction, flexDirection: 'row', alignItems: 'center', gap: 6, flexShrink: 1 }, children: [_jsx(Text, { testID: 'target-custom-value', numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '500', color: tone }, children: customText }), _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: colors.muted }) })] })] }) : null, presets.length > 0 ? _jsx(View, { testID: 'target-presets', style: { direction, flexDirection: 'row', gap: 8, marginTop: 16 }, children: targetPresets(presets).map(({ value: preset, disabled }) => { const selected = custom === null && preset === value; return _jsx(Button, { testID: `target-preset-${preset}`, intent: selected ? intent : 'secondary', disabled: disabled, accessibilityState: { selected }, onPress: () => onValueChange?.(preset), style: { flex: 1, alignSelf: 'auto', paddingHorizontal: 8 }, children: formatNumber(preset, locale, present(targetFormat(unit, priceOptions, preset))) }, preset); }) }) : null, info && open ? _jsx(Pressable, { testID: 'target-popover-dismiss', ...hidden, onPress: () => setOpen(false), style: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, zIndex: 1 } }) : null, info && open ? _jsx(View, { testID: 'target-popover', accessibilityLiveRegion: 'polite', style: { position: 'absolute', top: sticky ? 4 : 64, ...(direction === 'rtl' ? { left: 16 } : { right: 16 }), maxWidth: 280, zIndex: 2, padding: 12, borderRadius: 14, backgroundColor: colors.nested }, children: _jsx(Text, { testID: 'target-note', style: { color: colors.text, fontSize: 14, lineHeight: 21 }, children: note }) }) : null, _jsxs(View, { testID: 'target-actions', style: { direction, flexDirection: 'row', gap: 8, marginTop: 16 }, children: [onCancel ? _jsx(Button, { testID: 'target-cancel', intent: 'secondary', onPress: onCancel, style: { flex: 1, alignSelf: 'auto' }, children: labels.cancel ?? t.cancel }) : null, _jsx(Button, { testID: 'target-submit', intent: intent, disabled: submitDisabled ?? value === null, busy: busy, onPress: onSubmit, style: { flex: 1, alignSelf: 'auto' }, children: labels.submit })] })] });
77
+ const body = _jsxs(_Fragment, { children: [_jsx(View, { style: { alignItems: 'center', marginTop: 16 }, children: _jsx(AnimatedNumberReadout, { testID: 'target-amount', value: value, options: targetFormat(unit, priceOptions), style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9, textAlign: 'center' } }) }), note && !info ? _jsx(Text, { testID: 'target-note', style: { color: colors.muted, fontSize: 14, lineHeight: 21, textAlign: 'center', marginTop: 16 }, children: note }) : null, _jsxs(PriceCard, { testID: 'target-prices', style: { gap: 12, marginTop: 16, minWidth: 0 }, children: [position || orderType ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [position ? _jsx(Text, { testID: 'target-position', accessibilityRole: 'header', style: { fontSize: 16, lineHeight: 24, fontWeight: '600', flexShrink: 1 }, children: position }) : _jsx(View, {}), orderType ? _jsx(Text, { testID: 'target-order-type', style: { color: colors.muted, fontSize: 14, lineHeight: 21, flexShrink: 1 }, children: orderType }) : null] }) : null, _jsxs(View, { ...hidden, testID: 'target-bar', style: { flexDirection: 'row', height: 24, borderRadius: 8, overflow: 'hidden' }, children: [_jsx(View, { style: part(from) }), to > from ? _jsx(View, { testID: 'target-move', style: { flexGrow: to - from, flexShrink: 1, flexBasis: 0, minWidth: 6, borderStartWidth: 3, borderEndWidth: 3, borderStartColor: triggerLeads ? tone : colors.text, borderEndColor: triggerLeads ? colors.text : tone }, children: _jsx(View, { testID: 'target-fill', style: { flex: 1, backgroundColor: tone, opacity: barFillOpacity } }) }) : null, _jsx(View, { style: part(1 - to) })] }), _jsx(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: order.map((price, index) => _jsxs(View, { accessible: true, accessibilityLabel: `${labels[price]}, ${formatNumberReadout(prices[price], locale, present(priceOptions)).text}`, testID: `target-${price}`, style: { alignItems: align(index), flexShrink: 1, minWidth: 0 }, children: [_jsx(View, { ...hidden, children: _jsx(AnimatedNumberReadout, { value: prices[price], options: priceOptions, tone: price === 'trigger' ? (stop ? 'negative' : 'positive') : 'text', style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }) }), _jsx(Text, { ...hidden, numberOfLines: 1, style: { color: colors.muted, fontSize: 12, lineHeight: 16 }, children: labels[price] })] }, price)) })] }), units.length > 1 ? _jsx(View, { testID: 'target-units', style: { marginTop: 16 }, children: _jsx(SegmentedControl, { label: labels.unit, options: targetUnits(units).map(option => ({ value: option.unit, label: labels.units[option.unit], disabled: option.disabled })), value: unit, onValueChange: next => onUnitChange?.(next) }) }) : null, onCustom && customText === null ? _jsxs(Pressable, { testID: 'target-custom', accessibilityRole: 'button', accessibilityState: customValue !== undefined ? { selected: false } : undefined, onPress: onCustom, style: ({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 48, paddingHorizontal: 16, borderRadius: 9999, backgroundColor: pressed ? fills.raised : fills.well, marginTop: 16 }), children: [_jsx(Text, { numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: labels.custom }), _jsx(View, { ...hidden, style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: colors.muted }) })] }) : null, onCustom && customText !== null ? _jsxs(Pressable, { testID: 'target-custom', accessibilityRole: 'button', accessibilityLabel: `${labels.custom}, ${customText}`, accessibilityState: { selected: true }, onPress: onCustom, style: ({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 48, paddingHorizontal: 16, borderRadius: 9999, backgroundColor: stop ? colors.negative : colors.action, opacity: pressed ? 0.9 : 1, marginTop: 16 }), children: [_jsx(Text, { ...hidden, numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '600', color: onFill }, children: labels.custom }), _jsxs(View, { ...hidden, style: { direction, flexDirection: 'row', alignItems: 'center', gap: 6, flexShrink: 1 }, children: [_jsx(Text, { testID: 'target-custom-value', numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '500', color: onFill }, children: customText }), _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: onFill }) })] })] }) : null, presets.length > 0 ? _jsx(PresetGroup, { testID: 'target-presets', label: labels.presets ?? labels.title, selectedIntent: intent, options: targetPresets(presets).map(({ value: preset, disabled }) => ({ value: preset, disabled, testID: `target-preset-${preset}`, label: formatNumber(preset, locale, present(targetFormat(unit, priceOptions, preset))) })), value: custom === null ? value : null, onValueChange: next => onValueChange?.(next), style: { marginTop: 16 } }) : null, info && open ? _jsx(Pressable, { testID: 'target-popover-dismiss', ...hidden, onPress: () => setOpen(false), style: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, zIndex: 1 } }) : null, info && open ? _jsx(View, { testID: 'target-popover', accessibilityLiveRegion: 'polite', style: { position: 'absolute', top: sticky ? 4 : 64, ...(direction === 'rtl' ? { left: 16 } : { right: 16 }), maxWidth: 280, zIndex: 2, padding: 12, borderRadius: 14, backgroundColor: colors.nested }, children: _jsx(Text, { testID: 'target-note', style: { color: colors.text, fontSize: 14, lineHeight: 21 }, children: note }) }) : null, _jsxs(View, { testID: 'target-actions', style: { direction, flexDirection: 'row', gap: 8, marginTop: 16 }, children: [onCancel ? _jsx(Button, { testID: 'target-cancel', intent: 'secondary', onPress: onCancel, style: { flex: 1, alignSelf: 'auto' }, children: labels.cancel ?? t.cancel }) : null, _jsx(Button, { testID: 'target-submit', intent: intent, disabled: !!submitDisabled || !known(value) || (unit === 'price' && value <= 0), busy: busy, onPress: onSubmit, style: { flex: 1, alignSelf: 'auto' }, children: labels.submit })] })] });
71
78
  if (sticky)
72
79
  return _jsx(StickyHeaderLayout, { testID: testID, headerTestID: 'target-sticky-header', header: header, background: stickyHeaderBackground, scrollComponent: scrollComponent, children: body });
73
80
  return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [header, body] });
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { type ToastBaseOptions, type ToastCall, type ToastId, type ToastPosition, type ToastSwipeDirection } from '@bloxwap/hig/contracts/toast';
3
+ export type { ToastBaseOptions, ToastCall, ToastId, ToastPosition, ToastSeverity, ToastSwipeDirection } from '@bloxwap/hig/contracts/toast';
4
+ export interface ToastOptions extends ToastBaseOptions {
5
+ action?: React.ReactNode;
6
+ }
7
+ export interface ToasterProps {
8
+ /** The corner or edge the stack hangs from. Default `bottom-center`, as on web. `left` and `right` are the physical sides in either direction, as in Sonner; only the capsule's content mirrors under right-to-left. */
9
+ position?: ToastPosition;
10
+ /** Draws the visible notices one after another instead of as a collapsed stack. Default `false`. A finger resting on a notice for 200ms expands the stack until it lifts, and a running screen reader keeps it expanded so every notice can be reached. */
11
+ expand?: boolean;
12
+ /** Notices drawn at once; older ones wait behind them and their time does not run. Default 3; anything below 1 or not a number shows one. */
13
+ visibleToasts?: number;
14
+ /** Points between notices when expanded, and how far each notice behind the front peeks out when collapsed. Default 14. */
15
+ gap?: number;
16
+ /** Points between the stack and the screen edges, added to the safe-area insets: one number for every edge, or an object naming edges, the others keeping the default. Default 16 on a window narrower than 600 points and 24 otherwise. `left` and `right` are the physical sides, like `position`. */
17
+ offset?: number | {
18
+ top?: number;
19
+ right?: number;
20
+ bottom?: number;
21
+ left?: number;
22
+ };
23
+ /** Milliseconds a notice stays when `toast()` names no `duration`. Default 4000, which also stands in for a value that is not a positive number. */
24
+ duration?: number;
25
+ /** Directions a swipe dismisses in. Default: towards the edges the stack sits against (`bottom-center` → down; `top-right` → up and right). */
26
+ swipeDirections?: readonly ToastSwipeDirection[];
27
+ /** Prefix of the test IDs: `<testID>` on the layer and `<testID>-toast` on each notice. */
28
+ testID?: string;
29
+ }
30
+ /** Dismisses one notice by id, or every notice when the id is omitted. */
31
+ export declare function dismissToast(id?: ToastId): void;
32
+ /**
33
+ * Raises a transient HIG capsule on the mounted `Toaster` and returns its id. Callable from anywhere. `toast.success`,
34
+ * `toast.error`, `toast.warning` and `toast.info` set the severity; `toast.dismiss` is `dismissToast`. The same call,
35
+ * options and names work in `@bloxwap/hig/react/toast`.
36
+ */
37
+ export declare const toast: ToastCall<ToastOptions>;
38
+ /**
39
+ * The host for transient HIG notices on native. Mount it once, last inside the root view, within HIGProvider,
40
+ * GestureHandlerRootView and SafeAreaProvider; `toast()` then works from anywhere. It draws the same capsule as `Toast`,
41
+ * stacked the way Sonner stacks on web: the newest in front, up to three visible, each leaving after its time, by its
42
+ * close control or by a swipe. A touch holds every notice's time and so does the app going to the background.
43
+ *
44
+ * Reanimated moves the notices and Gesture Handler reads the finger, both on the UI thread; only transforms and opacity
45
+ * change while anything moves. With no notice showing it renders nothing.
46
+ */
47
+ export declare function Toaster({ position, expand, visibleToasts, gap, offset, duration, swipeDirections, testID }: ToasterProps): React.JSX.Element | null;
@@ -0,0 +1,386 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
3
+ import { AccessibilityInfo, AppState, StyleSheet, View, useWindowDimensions } from 'react-native';
4
+ import Reanimated, { cancelAnimation, Easing, ReduceMotion, runOnJS, useAnimatedReaction, useAnimatedStyle, useSharedValue, withSpring, withTiming } from 'react-native-reanimated';
5
+ import { Gesture, GestureDetector } from 'react-native-gesture-handler';
6
+ import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
7
+ import * as en from '@bloxwap/hig/contracts/messages';
8
+ import { notificationDelta } from '@bloxwap/hig/contracts/announcements';
9
+ import { TOAST_DURATION, TOAST_EXIT, TOAST_GAP, TOAST_HOLD, TOAST_MOTION, TOAST_NARROW, TOAST_NARROW_OFFSET, TOAST_OFFSET, TOAST_REDUCED_FADE, TOAST_SPRING, TOAST_VISIBLE, TOAST_WIDTH, toastClockPause, toastClockRun, toastDrag, toastDuration, toastEdge, toastEnterFrom, toastExitTo, toastGrab, toastLeave, toastOrder, toastRemove, toastSlot, toastSwipeAxis, toastSwipeDirections, toastSwipeDismisses, toastSwipeOut, toastUpsert } from '@bloxwap/hig/contracts/toast';
10
+ import { useColors, useHIG } from './provider.js';
11
+ import { ToastNotice } from './status.js';
12
+ import { speak } from './announce.js';
13
+ // One store for the app, so `toast()` works from anywhere, not only from components. Mounted hosts subscribe; the last one mounted draws.
14
+ let entries = [], sequence = 0;
15
+ const listeners = new Set(), hosts = [];
16
+ const emit = () => { for (const listener of [...listeners])
17
+ listener(); };
18
+ const subscribe = (listener) => { listeners.add(listener); return () => { listeners.delete(listener); }; };
19
+ const snapshot = () => entries;
20
+ function attach(host) {
21
+ hosts.push(host);
22
+ emit();
23
+ return () => {
24
+ hosts.splice(hosts.indexOf(host), 1);
25
+ // Notices on their way out have nobody left to finish them.
26
+ if (hosts.length === 0)
27
+ entries = entries.filter(entry => !entry.leaving);
28
+ emit();
29
+ };
30
+ }
31
+ /** Starts one notice's exit and tells its owner why: its time ran out (`expired`), or it was dismissed. The host removes it when the exit has played. */
32
+ function leave(key, expired) {
33
+ const entry = entries.find(candidate => candidate.key === key);
34
+ if (!entry || entry.leaving)
35
+ return;
36
+ entries = toastLeave(entries, entry.id);
37
+ emit();
38
+ if (expired)
39
+ entry.value.onAutoClose?.();
40
+ else
41
+ entry.value.onDismiss?.();
42
+ }
43
+ function forget(key) { const next = toastRemove(entries, key); if (next !== entries) {
44
+ entries = next;
45
+ emit();
46
+ } }
47
+ function raise(message, options = {}) {
48
+ const { severity = 'info', description, action, dismissName, duration, id, onDismiss, onAutoClose } = options;
49
+ // As in Sonner, an empty string is not an id: the notice gets the next one.
50
+ const key = ++sequence, resolved = typeof id === 'number' || (typeof id === 'string' && id.length > 0) ? id : key;
51
+ entries = toastUpsert(entries, { key, id: resolved, duration: toastDuration(duration), value: { message, description, severity, action, dismissName, onDismiss, onAutoClose } });
52
+ emit();
53
+ return resolved;
54
+ }
55
+ /** Dismisses one notice by id, or every notice when the id is omitted. */
56
+ export function dismissToast(id) {
57
+ const next = toastLeave(entries, id);
58
+ if (next === entries)
59
+ return;
60
+ const dismissed = next.filter((entry, index) => entry.leaving && !entries[index].leaving);
61
+ // Without a mounted Toaster nothing can play the exit, so they go at once.
62
+ entries = hosts.length > 0 ? next : next.filter(entry => !entry.leaving);
63
+ emit();
64
+ for (const entry of dismissed)
65
+ entry.value.onDismiss?.();
66
+ }
67
+ const as = (severity) => (message, options) => raise(message, { ...options, severity });
68
+ /**
69
+ * Raises a transient HIG capsule on the mounted `Toaster` and returns its id. Callable from anywhere. `toast.success`,
70
+ * `toast.error`, `toast.warning` and `toast.info` set the severity; `toast.dismiss` is `dismissToast`. The same call,
71
+ * options and names work in `@bloxwap/hig/react/toast`.
72
+ */
73
+ export const toast = Object.assign(raise, { success: as('success'), error: as('error'), warning: as('warning'), info: as('info'), dismiss: dismissToast });
74
+ // The provider decides reduced motion (it already follows the OS setting), so these timings never defer to the system on their own.
75
+ const MOVE = { duration: TOAST_MOTION.duration, easing: Easing.bezier(...TOAST_MOTION.curve), reduceMotion: ReduceMotion.Never };
76
+ const EXIT = { duration: TOAST_EXIT.duration, easing: Easing.bezier(...TOAST_EXIT.curve), reduceMotion: ReduceMotion.Never };
77
+ const FADE = { duration: TOAST_REDUCED_FADE, easing: Easing.bezier(...TOAST_EXIT.curve), reduceMotion: ReduceMotion.Never };
78
+ const NO_INSETS = { top: 0, right: 0, bottom: 0, left: 0 };
79
+ // A card renders again when its place in the stack changes how it takes touches; what it shows has not changed then, so the capsule is skipped.
80
+ const Capsule = memo(ToastNotice);
81
+ /**
82
+ * One notice in the stack. React renders it when the store changes; everything that moves it runs on the UI thread. Its
83
+ * slot comes from the shared stack, so a notice arriving, leaving or changing height restacks every card in one frame
84
+ * without a render, and only transforms and opacity change while it moves.
85
+ */
86
+ const Card = memo(function Card({ entry, front, hidden, interactive, lift, gap, visible, reduce, left, right, up, down, narrow, testID, stack, expanded, held, report, hold }) {
87
+ const id = entry.key, { leaving, value } = entry, colors = useColors();
88
+ const y = useSharedValue(0), scaleX = useSharedValue(1), scaleY = useSharedValue(1), opacity = useSharedValue(0), content = useSharedValue(1), dragX = useSharedValue(0), dragY = useSharedValue(0);
89
+ // 0: laid out but not placed yet. 1: in the stack. 2: leaving, so nothing may pull it back.
90
+ const phase = useSharedValue(0), gone = useSharedValue(false);
91
+ const rest = useSharedValue({ y: 0, height: 0, index: -1 }), size = useSharedValue({ width: 0, height: 0 });
92
+ // The axis a drag is locked to (0 none, 1 horizontal, 2 vertical) and the translation that counts as rest, so the notice does not jump by the recognition distance.
93
+ const axis = useSharedValue(0), origin = useSharedValue(0);
94
+ useAnimatedReaction(() => {
95
+ 'worklet';
96
+ const { keys, heights } = stack.value, index = keys.indexOf(id);
97
+ const slot = toastSlot(index, heights, expanded.value || held.value, gap, visible, lift);
98
+ return { index, height: index < 0 ? 0 : heights[index], y: slot.y, scaleX: slot.scaleX, scaleY: slot.scaleY, opacity: slot.opacity, content: slot.content };
99
+ }, (next, previous) => {
100
+ 'worklet';
101
+ if (next.index < 0 || phase.value === 2)
102
+ return;
103
+ rest.value = { y: next.y, height: next.height, index: next.index };
104
+ // What it was drawn at, when it was already in the stack: only what differs from that moves, so a restack that leaves a notice where it is costs it nothing.
105
+ const was = phase.value === 1 && previous !== null && previous.index >= 0 ? previous : null;
106
+ if (phase.value === 0) {
107
+ phase.value = 1;
108
+ // The front slides in from its own height away; a notice that appears further back fades in where it rests.
109
+ y.value = next.index === 0 && !reduce ? toastEnterFrom(next.y, next.height, lift) : next.y;
110
+ scaleX.value = next.scaleX;
111
+ scaleY.value = next.scaleY;
112
+ content.value = next.content;
113
+ opacity.value = 0;
114
+ }
115
+ if (was === null || next.y !== was.y)
116
+ y.value = reduce ? next.y : withTiming(next.y, MOVE);
117
+ if (was === null || next.scaleX !== was.scaleX)
118
+ scaleX.value = reduce ? next.scaleX : withTiming(next.scaleX, MOVE);
119
+ if (was === null || next.scaleY !== was.scaleY)
120
+ scaleY.value = reduce ? next.scaleY : withTiming(next.scaleY, MOVE);
121
+ const fade = reduce ? FADE : MOVE;
122
+ if (was === null || next.opacity !== was.opacity)
123
+ opacity.value = withTiming(next.opacity, fade);
124
+ if (was === null || next.content !== was.content)
125
+ content.value = withTiming(next.content, fade);
126
+ }, [id, gap, visible, lift, reduce]);
127
+ // The exit, unless a swipe has already sent the notice on its way.
128
+ useAnimatedReaction(() => {
129
+ 'worklet';
130
+ return gone.value;
131
+ }, (now, before) => {
132
+ 'worklet';
133
+ if (!now || now === before || phase.value === 2)
134
+ return;
135
+ const placed = phase.value === 1;
136
+ phase.value = 2;
137
+ if (!placed)
138
+ return;
139
+ opacity.value = withTiming(0, reduce ? FADE : EXIT);
140
+ if (!reduce)
141
+ y.value = withTiming(toastExitTo(rest.value.y, rest.value.height, lift, rest.value.index === 0 || expanded.value || held.value), EXIT);
142
+ }, [lift, reduce]);
143
+ // The store drops the notice once the exit has had time to play. The exit itself never waits for this thread.
144
+ useEffect(() => { if (!leaving)
145
+ return; gone.value = true; const timer = setTimeout(() => forget(id), TOAST_EXIT.duration + 50); return () => clearTimeout(timer); }, [leaving, id, gone]);
146
+ const dismiss = useCallback(() => leave(id, false), [id]);
147
+ const pan = useMemo(() => Gesture.Pan().enabled(interactive).activeOffsetX([-8, 8]).activeOffsetY([-8, 8])
148
+ // A finger on the notice holds every notice's time, whether or not it goes on to swipe.
149
+ .onBegin(() => {
150
+ 'worklet';
151
+ runOnJS(hold)(id, true);
152
+ })
153
+ .onStart(event => {
154
+ 'worklet';
155
+ const horizontal = toastSwipeAxis(event.translationX, event.translationY) === 'x';
156
+ axis.value = horizontal ? 1 : 2;
157
+ // A notice caught while it springs back carries on from where it is.
158
+ if (horizontal) {
159
+ cancelAnimation(dragX);
160
+ origin.value = event.translationX - toastGrab(dragX.value, left, right);
161
+ }
162
+ else {
163
+ cancelAnimation(dragY);
164
+ origin.value = event.translationY - toastGrab(dragY.value, up, down);
165
+ }
166
+ })
167
+ .onChange(event => {
168
+ 'worklet';
169
+ if (phase.value === 2)
170
+ return;
171
+ if (axis.value === 1)
172
+ dragX.value = toastDrag(event.translationX - origin.value, left, right);
173
+ else if (axis.value === 2)
174
+ dragY.value = toastDrag(event.translationY - origin.value, up, down);
175
+ })
176
+ .onEnd((event, success) => {
177
+ 'worklet';
178
+ const horizontal = axis.value === 1;
179
+ axis.value = 0;
180
+ if (phase.value === 2)
181
+ return;
182
+ const amount = horizontal ? dragX.value : dragY.value, velocity = horizontal ? event.velocityX : event.velocityY;
183
+ // A gesture the system took away (a call, the notice pushed behind a new one) is not a decision to dismiss: it goes back to rest.
184
+ if (success !== false && toastSwipeDismisses(amount, velocity, horizontal ? left : up, horizontal ? right : down)) {
185
+ phase.value = 2;
186
+ const out = toastSwipeOut(amount, velocity, horizontal ? size.value.width : size.value.height), timing = { duration: out.duration, easing: EXIT.easing, reduceMotion: ReduceMotion.Never };
187
+ if (!reduce) {
188
+ if (horizontal)
189
+ dragX.value = withTiming(out.to, timing);
190
+ else
191
+ dragY.value = withTiming(out.to, timing);
192
+ }
193
+ opacity.value = withTiming(0, reduce ? FADE : timing);
194
+ runOnJS(dismiss)();
195
+ return;
196
+ }
197
+ // Not far or fast enough: back to rest on a spring that carries the release velocity.
198
+ const spring = { ...TOAST_SPRING, velocity, reduceMotion: reduce ? ReduceMotion.Always : ReduceMotion.Never };
199
+ if (horizontal)
200
+ dragX.value = withSpring(0, spring);
201
+ else
202
+ dragY.value = withSpring(0, spring);
203
+ })
204
+ .onFinalize(() => {
205
+ 'worklet';
206
+ axis.value = 0;
207
+ runOnJS(hold)(id, false);
208
+ }), [id, interactive, left, right, up, down, reduce, hold, dismiss]);
209
+ const cardStyle = useAnimatedStyle(() => {
210
+ 'worklet';
211
+ return { opacity: opacity.value, transform: [{ translateX: dragX.value }, { translateY: y.value + dragY.value }, { scaleX: scaleX.value }, { scaleY: scaleY.value }] };
212
+ });
213
+ const contentStyle = useAnimatedStyle(() => {
214
+ 'worklet';
215
+ return { opacity: content.value };
216
+ });
217
+ const onLayout = useCallback((event) => { const { width, height } = event.nativeEvent.layout; size.value = { width, height }; report(id, height); }, [id, report, size]);
218
+ const name = testID === undefined ? undefined : `${testID}-toast`;
219
+ // A notice behind a collapsed stack, or past the visible ones, shows no content: it takes no touches and assistive technology skips it.
220
+ return _jsx(GestureDetector, { gesture: pan, children: _jsx(Reanimated.View, { testID: name, onLayout: onLayout, pointerEvents: interactive ? 'auto' : 'none', accessibilityElementsHidden: hidden || (!front && !interactive), importantForAccessibility: hidden || (!front && !interactive) ? 'no-hide-descendants' : 'auto', style: [styles.card, lift === 1 ? styles.top : styles.bottom, narrow ? styles.narrow : styles.wide, { backgroundColor: colors.nested }, cardStyle], children: _jsx(Reanimated.View, { style: contentStyle, children: _jsx(Capsule, { message: value.message, description: value.description, severity: value.severity, action: value.action, dismissName: value.dismissName, onDismiss: dismiss, hug: true, style: styles.bare }) }) }) });
221
+ });
222
+ /**
223
+ * The host for transient HIG notices on native. Mount it once, last inside the root view, within HIGProvider,
224
+ * GestureHandlerRootView and SafeAreaProvider; `toast()` then works from anywhere. It draws the same capsule as `Toast`,
225
+ * stacked the way Sonner stacks on web: the newest in front, up to three visible, each leaving after its time, by its
226
+ * close control or by a swipe. A touch holds every notice's time and so does the app going to the background.
227
+ *
228
+ * Reanimated moves the notices and Gesture Handler reads the finger, both on the UI thread; only transforms and opacity
229
+ * change while anything moves. With no notice showing it renders nothing.
230
+ */
231
+ export function Toaster({ position = 'bottom-center', expand = false, visibleToasts = TOAST_VISIBLE, gap = TOAST_GAP, offset, duration = TOAST_DURATION, swipeDirections, testID }) {
232
+ const env = useHIG(), insets = useContext(SafeAreaInsetsContext) ?? NO_INSETS, { width } = useWindowDimensions();
233
+ const token = useRef({}).current;
234
+ const list = useSyncExternalStore(subscribe, snapshot, snapshot), active = useSyncExternalStore(subscribe, () => hosts[hosts.length - 1] === token, () => false);
235
+ useEffect(() => attach(token), [token]);
236
+ // A screen reader cannot reach content the collapsed stack hides, so the stack stays expanded while one runs.
237
+ const [reader, setReader] = useState(false);
238
+ useEffect(() => { let alive = true; void AccessibilityInfo.isScreenReaderEnabled().then(value => { if (alive && value)
239
+ setReader(true); }).catch(() => { }); const subscription = AccessibilityInfo.addEventListener('screenReaderChanged', setReader); return () => { alive = false; subscription.remove(); }; }, []);
240
+ const open = expand || reader, visible = visibleToasts >= 1 ? Math.floor(visibleToasts) : 1;
241
+ const order = useMemo(() => active ? toastOrder(list) : [], [active, list]);
242
+ const stack = useSharedValue({ keys: [], heights: [] }), expanded = useSharedValue(open), held = useSharedValue(false);
243
+ useEffect(() => { expanded.value = open; }, [open, expanded]);
244
+ const heights = useRef(new Map()).current, published = useRef({ keys: [], heights: [] });
245
+ const clocks = useRef(new Map()).current;
246
+ const holds = useRef(new Set()).current, awake = useRef(AppState.currentState !== 'background' && AppState.currentState !== 'inactive');
247
+ // The notices the last commit drew. One that leaves stays for its exit only if it is among them: a notice waiting behind the stack has nothing on screen to take away, so no card is mounted to play its exit.
248
+ const drawn = useRef(new Set());
249
+ const rank = new Map(order.map((entry, index) => [entry.key, index]));
250
+ // One notice past the visible ones stays mounted and transparent, so the notice the stack pushes out fades where it is and the one it uncovers is ready.
251
+ const mounted = active ? list.filter(entry => entry.leaving ? drawn.current.has(entry.key) && heights.has(entry.key) : rank.get(entry.key) <= visible) : [];
252
+ const latest = useRef({ order, visible, duration, mounted });
253
+ latest.current = { order, visible, duration, mounted };
254
+ // The stack the UI thread lays out: live notices that have been measured, front first. A new notice joins when its height is known, so nothing moves for it before it can be placed.
255
+ const publish = useCallback(() => {
256
+ const keys = [], sizes = [];
257
+ for (const entry of latest.current.order) {
258
+ const height = heights.get(entry.key);
259
+ if (height === undefined)
260
+ continue;
261
+ keys.push(entry.key);
262
+ sizes.push(height);
263
+ }
264
+ const last = published.current;
265
+ if (last.keys.length === keys.length && keys.every((key, index) => key === last.keys[index] && sizes[index] === last.heights[index]))
266
+ return;
267
+ published.current = { keys, heights: sizes };
268
+ stack.value = { keys, heights: sizes };
269
+ }, [heights, stack]);
270
+ // A notice's time runs only while it is one of the visible notices, nothing is held and the app is in front. Raising it again under the same id starts its time over.
271
+ const sync = useCallback(() => {
272
+ const now = Date.now(), paused = holds.size > 0 || !awake.current, live = new Set();
273
+ latest.current.order.forEach((entry, index) => {
274
+ const total = entry.duration ?? toastDuration(latest.current.duration) ?? TOAST_DURATION;
275
+ if (total === Infinity)
276
+ return;
277
+ let record = clocks.get(entry.key);
278
+ if (!record || record.revision !== entry.revision) {
279
+ if (record?.timer != null)
280
+ clearTimeout(record.timer);
281
+ record = { clock: { remaining: total, startedAt: null }, revision: entry.revision, timer: null };
282
+ clocks.set(entry.key, record);
283
+ }
284
+ live.add(entry.key);
285
+ const runs = !paused && index < latest.current.visible && heights.has(entry.key);
286
+ if (runs && record.clock.startedAt === null) {
287
+ record.clock = toastClockRun(record.clock, now);
288
+ record.timer = setTimeout(() => leave(entry.key, true), record.clock.remaining);
289
+ }
290
+ else if (!runs && record.clock.startedAt !== null) {
291
+ record.clock = toastClockPause(record.clock, now);
292
+ if (record.timer != null)
293
+ clearTimeout(record.timer);
294
+ record.timer = null;
295
+ }
296
+ });
297
+ for (const [key, record] of clocks)
298
+ if (!live.has(key)) {
299
+ if (record.timer != null)
300
+ clearTimeout(record.timer);
301
+ clocks.delete(key);
302
+ }
303
+ }, [clocks, heights, holds]);
304
+ const report = useCallback((key, height) => { if (heights.get(key) === height)
305
+ return; heights.set(key, height); publish(); sync(); }, [heights, publish, sync]);
306
+ // Time stops the moment a finger lands. The stack expands only if it stays, so a tap or a quick swipe does not stir it.
307
+ const peek = useRef(null);
308
+ const settle = useCallback(() => {
309
+ if (holds.size === 0) {
310
+ if (peek.current !== null) {
311
+ clearTimeout(peek.current);
312
+ peek.current = null;
313
+ }
314
+ held.value = false;
315
+ }
316
+ else if (peek.current === null)
317
+ peek.current = setTimeout(() => { held.value = holds.size > 0; }, TOAST_HOLD);
318
+ sync();
319
+ }, [holds, held, sync]);
320
+ // The notices that take touches. A finger reported on any other arrived late, from a notice that has since been pushed out of reach, and is ignored.
321
+ const reach = useRef(new Set());
322
+ const hold = useCallback((key, down) => { if (!down)
323
+ holds.delete(key);
324
+ else if (reach.current.has(key))
325
+ holds.add(key); settle(); }, [holds, settle]);
326
+ useEffect(() => {
327
+ const known = new Set(list.map(entry => entry.key));
328
+ for (const key of [...heights.keys()])
329
+ if (!known.has(key))
330
+ heights.delete(key);
331
+ // Only a notice that takes touches can be holding the time. One that is gone, leaving, or pushed out of reach may never report the finger lifting, and would hold every notice for good.
332
+ const touchable = new Set();
333
+ latest.current.order.forEach((entry, index) => { if (index < visible && (index === 0 || open))
334
+ touchable.add(entry.key); });
335
+ reach.current = touchable;
336
+ for (const key of [...holds])
337
+ if (!touchable.has(key))
338
+ holds.delete(key);
339
+ drawn.current = new Set(latest.current.mounted.map(entry => entry.key));
340
+ // A notice dismissed while it is not drawn, or before it was laid out, has no exit to play.
341
+ if (active)
342
+ for (const entry of list)
343
+ if (entry.leaving && !drawn.current.has(entry.key))
344
+ forget(entry.key);
345
+ publish();
346
+ settle();
347
+ }, [active, list, visible, duration, open, heights, holds, publish, settle]);
348
+ useEffect(() => { const subscription = AppState.addEventListener('change', state => { awake.current = state === 'active'; sync(); }); return () => subscription.remove(); }, [sync]);
349
+ useEffect(() => () => { for (const record of clocks.values())
350
+ if (record.timer != null)
351
+ clearTimeout(record.timer); clocks.clear(); if (peek.current !== null)
352
+ clearTimeout(peek.current); }, [clocks]);
353
+ // One announcement per burst: an error if there is one, otherwise the newest, which is the one drawn in front. A notice that is redrawn unchanged is not read again.
354
+ const spoken = useRef(new Map());
355
+ useEffect(() => {
356
+ if (!active)
357
+ return;
358
+ const delta = notificationDelta(spoken.current, [...order].reverse().map(entry => ({ id: String(entry.key), message: [entry.value.message, entry.value.description].filter(Boolean).join('. '), severity: entry.value.severity })));
359
+ spoken.current = delta.next;
360
+ if (delta.message)
361
+ speak(delta.message, delta.severity);
362
+ }, [active, order]);
363
+ const edge = toastEdge(position);
364
+ const directions = useMemo(() => swipeDirections ?? toastSwipeDirections(position), [swipeDirections, position]);
365
+ if (mounted.length === 0)
366
+ return null;
367
+ const narrow = width < TOAST_NARROW, fallback = narrow ? TOAST_NARROW_OFFSET : TOAST_OFFSET;
368
+ const distance = (side) => (typeof offset === 'object' ? offset[side] : offset) ?? fallback;
369
+ const label = env.messages.notifications ?? en.notifications;
370
+ // `left` and `right` are physical, as in Sonner. The layer always lays out left to right, so start and end on the rail are the physical left and right whatever the provider or the OS says (React Native swaps `left` and `right` themselves under an RTL OS). The capsule sets the provider's direction on its own row.
371
+ return _jsx(View, { testID: testID, pointerEvents: 'box-none', style: [StyleSheet.absoluteFill, styles.layer], children: _jsx(View, { pointerEvents: 'box-none', accessibilityLabel: label, style: [styles.rail, { top: insets.top + distance('top'), bottom: insets.bottom + distance('bottom'), start: insets.left + distance('left'), end: insets.right + distance('right'), alignItems: edge.x === 'center' ? 'center' : edge.x === 'left' ? 'flex-start' : 'flex-end' }], children: mounted.map(entry => {
372
+ const index = rank.get(entry.key) ?? -1, hidden = index < 0 || index >= visible;
373
+ return _jsx(Card, { entry: entry, front: index === 0, hidden: hidden, interactive: !hidden && !entry.leaving && (index === 0 || open), lift: edge.lift, gap: gap, visible: visible, reduce: env.reducedMotion, left: directions.includes('left'), right: directions.includes('right'), up: directions.includes('top'), down: directions.includes('bottom'), narrow: narrow, testID: testID, stack: stack, expanded: expanded, held: held, report: report, hold: hold }, entry.key);
374
+ }) }) });
375
+ }
376
+ const styles = StyleSheet.create({
377
+ layer: { direction: 'ltr' },
378
+ rail: { position: 'absolute' },
379
+ // The capsule's own fill, radius and shadow sit on the moving view, so the content inside can fade without the capsule going with it.
380
+ card: { position: 'absolute', borderRadius: 22, boxShadow: '0 4px 16px #0006' },
381
+ top: { top: 0 },
382
+ bottom: { bottom: 0 },
383
+ narrow: { maxWidth: '100%' },
384
+ wide: { maxWidth: TOAST_WIDTH },
385
+ bare: { backgroundColor: 'transparent', boxShadow: undefined },
386
+ });
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { type ScrollViewProps } from 'react-native';
2
3
  import type { HIGMessages } from '@bloxwap/hig/contracts/messages';
3
4
  import { type BarMarkElement } from './bar-mark.js';
4
5
  export type { BarMarkElement, BarMarkFigure } from './bar-mark.js';
@@ -40,8 +41,16 @@ export interface TokenActionBlockProps {
40
41
  /** A line under the actions, for example why some are missing. `noteTone` tints it as in SwapPanelBlock. */
41
42
  note?: React.ReactNode;
42
43
  noteTone?: 'muted' | 'warning' | 'negative';
44
+ /** Keeps the header pinned while the rest scrolls: the block becomes its own scroll view with the header as its sticky first child, transparent at rest and filled once content scrolls under it. Place it in a bounded container, such as a sheet body. */
45
+ stickyHeader?: boolean;
46
+ /** With `stickyHeader`: the header's fill once content is under it. Defaults to the background role; in a sheet pass the sheet's fill. */
47
+ stickyHeaderBackground?: string;
48
+ /** The scroll view used with `stickyHeader`, such as a sheet library's own. Defaults to React Native's ScrollView. */
49
+ scrollComponent?: React.ComponentType<ScrollViewProps>;
50
+ /** `nativeID` of the title, so a sheet around the block can name itself with `accessibilityLabelledBy` (Android). */
51
+ headingId?: string;
43
52
  testID?: string;
44
53
  }
45
54
  /** An action's text: its own `label`, else the built-in name of its id, else the id. */
46
55
  export declare const tokenActionLabel: (action: TokenAction, messages: Partial<HIGMessages>) => string;
47
- export declare function TokenActionBlock({ symbol, name, value, units, unitsSuffix, unitsOptions, assets, chains, chainsTitle, actions, onBack, headerAction, note, noteTone, testID }: TokenActionBlockProps): React.JSX.Element;
56
+ export declare function TokenActionBlock({ symbol, name, value, units, unitsSuffix, unitsOptions, assets, chains, chainsTitle, actions, onBack, headerAction, note, noteTone, stickyHeader, stickyHeaderBackground, scrollComponent, headingId, testID }: TokenActionBlockProps): React.JSX.Element;