@bloxwap/hig 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) 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/login.d.ts +34 -0
  35. package/contracts/dist/login.js +43 -0
  36. package/contracts/dist/messages.d.ts +57 -3
  37. package/contracts/dist/messages.js +20 -2
  38. package/contracts/dist/number-flow.d.ts +90 -0
  39. package/contracts/dist/number-flow.js +150 -0
  40. package/contracts/dist/qr.d.ts +151 -0
  41. package/contracts/dist/qr.js +581 -0
  42. package/contracts/dist/toast.d.ts +168 -0
  43. package/contracts/dist/toast.js +171 -0
  44. package/feedback/README.md +1 -1
  45. package/feedback/dist/contract.js +1 -1
  46. package/feedback/dist/react.js +2 -4
  47. package/native/README.md +6 -1
  48. package/native/dist/account-block.d.ts +10 -1
  49. package/native/dist/account-block.js +17 -7
  50. package/native/dist/animated-number-model.d.ts +41 -1
  51. package/native/dist/animated-number-model.js +201 -23
  52. package/native/dist/animated-number.d.ts +39 -1
  53. package/native/dist/animated-number.js +164 -17
  54. package/native/dist/announce.d.ts +2 -0
  55. package/native/dist/announce.js +10 -0
  56. package/native/dist/asset-balance-row.d.ts +3 -1
  57. package/native/dist/asset-balance-row.js +15 -4
  58. package/native/dist/assets-block.d.ts +115 -0
  59. package/native/dist/assets-block.js +87 -0
  60. package/native/dist/async-result.d.ts +2 -0
  61. package/native/dist/async-result.js +11 -0
  62. package/native/dist/avatar-frame.d.ts +29 -0
  63. package/native/dist/avatar-frame.js +56 -0
  64. package/native/dist/avatar.d.ts +21 -0
  65. package/native/dist/avatar.js +31 -0
  66. package/native/dist/bar-mark.d.ts +2 -0
  67. package/native/dist/bar-mark.js +4 -2
  68. package/native/dist/bar-pnl.js +2 -1
  69. package/native/dist/blocks.d.ts +9 -2
  70. package/native/dist/blocks.js +8 -1
  71. package/native/dist/brand.js +2 -1
  72. package/native/dist/button.d.ts +7 -2
  73. package/native/dist/button.js +13 -3
  74. package/native/dist/checkbox.js +2 -1
  75. package/native/dist/confetti.d.ts +33 -0
  76. package/native/dist/confetti.js +143 -0
  77. package/native/dist/confirm-block.d.ts +98 -0
  78. package/native/dist/confirm-block.js +48 -0
  79. package/native/dist/data.d.ts +1 -1
  80. package/native/dist/data.js +5 -1
  81. package/native/dist/deposit-block.d.ts +19 -0
  82. package/native/dist/deposit-block.js +17 -0
  83. package/native/dist/explainer-block.d.ts +91 -0
  84. package/native/dist/explainer-block.js +34 -0
  85. package/native/dist/field.d.ts +5 -1
  86. package/native/dist/field.js +27 -6
  87. package/native/dist/gesture-sheet-model.d.ts +50 -0
  88. package/native/dist/gesture-sheet-model.js +105 -0
  89. package/native/dist/gesture-sheet-next.d.ts +82 -0
  90. package/native/dist/gesture-sheet-next.js +315 -0
  91. package/native/dist/gesture-sheet.d.ts +5 -1
  92. package/native/dist/gesture-sheet.js +13 -6
  93. package/native/dist/icons.d.ts +9 -6
  94. package/native/dist/icons.js +25 -24
  95. package/native/dist/language-block.d.ts +10 -1
  96. package/native/dist/language-block.js +11 -4
  97. package/native/dist/list-group.d.ts +3 -1
  98. package/native/dist/list-group.js +26 -13
  99. package/native/dist/login-block.d.ts +4 -0
  100. package/native/dist/login-block.js +22 -0
  101. package/native/dist/manage-position-block.d.ts +8 -1
  102. package/native/dist/manage-position-block.js +7 -2
  103. package/native/dist/market-row.js +19 -8
  104. package/native/dist/navigation.js +5 -3
  105. package/native/dist/number-format.d.ts +6 -0
  106. package/native/dist/number-format.js +9 -0
  107. package/native/dist/pickers.d.ts +8 -0
  108. package/native/dist/pickers.js +3 -3
  109. package/native/dist/position-block.d.ts +5 -5
  110. package/native/dist/preset-group.d.ts +31 -0
  111. package/native/dist/preset-group.js +39 -0
  112. package/native/dist/preset-picker-block.d.ts +107 -0
  113. package/native/dist/preset-picker-block.js +43 -0
  114. package/native/dist/profile-block.d.ts +10 -1
  115. package/native/dist/profile-block.js +8 -3
  116. package/native/dist/provider.d.ts +5 -2
  117. package/native/dist/provider.js +27 -5
  118. package/native/dist/qr-code.d.ts +33 -0
  119. package/native/dist/qr-code.js +29 -0
  120. package/native/dist/radio-group.d.ts +19 -7
  121. package/native/dist/radio-group.js +39 -10
  122. package/native/dist/reward-block.d.ts +10 -7
  123. package/native/dist/reward-block.js +9 -4
  124. package/native/dist/screen-header.d.ts +13 -3
  125. package/native/dist/screen-header.js +12 -4
  126. package/native/dist/select.js +4 -2
  127. package/native/dist/selection.d.ts +2 -1
  128. package/native/dist/selection.js +1 -0
  129. package/native/dist/setting-switch.d.ts +1 -1
  130. package/native/dist/setting-switch.js +7 -3
  131. package/native/dist/slider.js +5 -1
  132. package/native/dist/sound-haptics-block.js +1 -1
  133. package/native/dist/status.d.ts +41 -9
  134. package/native/dist/status.js +34 -17
  135. package/native/dist/sticky-header.js +9 -1
  136. package/native/dist/swap-amount-card.d.ts +57 -0
  137. package/native/dist/swap-amount-card.js +31 -0
  138. package/native/dist/{swap-panel-block.d.ts → swap-block.d.ts} +18 -8
  139. package/native/dist/{swap-panel-block.js → swap-block.js} +63 -35
  140. package/native/dist/swap-parts.d.ts +3 -10
  141. package/native/dist/swap-parts.js +22 -24
  142. package/native/dist/swap-shared.d.ts +2 -2
  143. package/native/dist/swap-shared.js +10 -6
  144. package/native/dist/swap-sheet.d.ts +3 -3
  145. package/native/dist/swap-sheet.js +3 -3
  146. package/native/dist/swap-views.js +1 -1
  147. package/native/dist/target-block.d.ts +7 -1
  148. package/native/dist/target-block.js +13 -6
  149. package/native/dist/toast.d.ts +47 -0
  150. package/native/dist/toast.js +386 -0
  151. package/native/dist/token-action-block.d.ts +11 -2
  152. package/native/dist/token-action-block.js +10 -4
  153. package/native/dist/trade-history-list-block.js +7 -4
  154. package/native/dist/wallet-address-core.js +6 -3
  155. package/native-fonts/README.md +1 -1
  156. package/og-fonts/README.md +1 -1
  157. package/package.json +155 -11
  158. package/react/README.md +3 -1
  159. package/react/dist/animated-number-flow.d.ts +72 -0
  160. package/react/dist/animated-number-flow.js +316 -0
  161. package/react/dist/animated-number-model.d.ts +18 -0
  162. package/react/dist/animated-number-model.js +75 -5
  163. package/react/dist/animated-number.d.ts +45 -1
  164. package/react/dist/animated-number.js +137 -6
  165. package/react/dist/asset-balance-row.d.ts +3 -1
  166. package/react/dist/asset-balance-row.js +10 -4
  167. package/react/dist/async-result.d.ts +2 -0
  168. package/react/dist/async-result.js +11 -0
  169. package/react/dist/avatar.d.ts +25 -0
  170. package/react/dist/avatar.js +50 -0
  171. package/react/dist/blocks/account-block.d.ts +5 -1
  172. package/react/dist/blocks/account-block.js +11 -6
  173. package/react/dist/blocks/assets-block.d.ts +106 -0
  174. package/react/dist/blocks/assets-block.js +135 -0
  175. package/react/dist/blocks/confirm-block.d.ts +91 -0
  176. package/react/dist/blocks/confirm-block.js +31 -0
  177. package/react/dist/blocks/deposit-block.d.ts +19 -0
  178. package/react/dist/blocks/deposit-block.js +15 -0
  179. package/react/dist/blocks/explainer-block.d.ts +80 -0
  180. package/react/dist/blocks/explainer-block.js +20 -0
  181. package/react/dist/blocks/install-command.js +3 -1
  182. package/react/dist/blocks/language-block.d.ts +5 -1
  183. package/react/dist/blocks/language-block.js +4 -3
  184. package/react/dist/blocks/login-block.d.ts +4 -0
  185. package/react/dist/blocks/login-block.js +14 -0
  186. package/react/dist/blocks/manage-position-block.d.ts +3 -1
  187. package/react/dist/blocks/manage-position-block.js +2 -2
  188. package/react/dist/blocks/market-row.js +8 -3
  189. package/react/dist/blocks/notifications-block.d.ts +3 -1
  190. package/react/dist/blocks/notifications-block.js +2 -2
  191. package/react/dist/blocks/pickers.d.ts +9 -0
  192. package/react/dist/blocks/pickers.js +4 -2
  193. package/react/dist/blocks/position-block.d.ts +3 -3
  194. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  195. package/react/dist/blocks/preset-picker-block.js +19 -0
  196. package/react/dist/blocks/profile-block.d.ts +5 -1
  197. package/react/dist/blocks/profile-block.js +12 -13
  198. package/react/dist/blocks/reward-block.d.ts +13 -8
  199. package/react/dist/blocks/reward-block.js +7 -4
  200. package/react/dist/blocks/screen-header.d.ts +10 -2
  201. package/react/dist/blocks/screen-header.js +7 -4
  202. package/react/dist/blocks/setting-switch.js +6 -3
  203. package/react/dist/blocks/signals-block.d.ts +3 -1
  204. package/react/dist/blocks/signals-block.js +4 -3
  205. package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
  206. package/react/dist/blocks/sound-haptics-block.js +2 -2
  207. package/react/dist/blocks/sticky-header.d.ts +14 -4
  208. package/react/dist/blocks/sticky-header.js +68 -8
  209. package/react/dist/blocks/swap/settings.js +2 -1
  210. package/react/dist/blocks/swap/shared.d.ts +22 -22
  211. package/react/dist/blocks/swap/shared.js +30 -28
  212. package/react/dist/blocks/{swap-panel-block.d.ts → swap-block.d.ts} +19 -8
  213. package/react/dist/blocks/swap-block.js +215 -0
  214. package/react/dist/blocks/swap-sheet.d.ts +3 -3
  215. package/react/dist/blocks/swap-sheet.js +3 -3
  216. package/react/dist/blocks/target-block.d.ts +7 -1
  217. package/react/dist/blocks/target-block.js +10 -4
  218. package/react/dist/blocks/token-action-block.d.ts +6 -2
  219. package/react/dist/blocks/token-action-block.js +3 -2
  220. package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
  221. package/react/dist/blocks/trade-history-detail-block.js +2 -2
  222. package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
  223. package/react/dist/blocks/trade-history-list-block.js +7 -4
  224. package/react/dist/blocks.d.ts +8 -2
  225. package/react/dist/blocks.js +7 -1
  226. package/react/dist/brand.js +2 -1
  227. package/react/dist/button.d.ts +9 -3
  228. package/react/dist/button.js +8 -3
  229. package/react/dist/confetti.d.ts +27 -0
  230. package/react/dist/confetti.js +240 -0
  231. package/react/dist/data.js +8 -1
  232. package/react/dist/field.d.ts +6 -1
  233. package/react/dist/field.js +18 -9
  234. package/react/dist/gesture-sheet.d.ts +15 -1
  235. package/react/dist/gesture-sheet.js +53 -8
  236. package/react/dist/list-group.js +11 -7
  237. package/react/dist/navigation.js +11 -3
  238. package/react/dist/overlay.d.ts +1 -4
  239. package/react/dist/overlay.js +1 -3
  240. package/react/dist/popover.d.ts +30 -0
  241. package/react/dist/popover.js +34 -0
  242. package/react/dist/preset-group.d.ts +30 -0
  243. package/react/dist/preset-group.js +13 -0
  244. package/react/dist/provider.d.ts +2 -2
  245. package/react/dist/provider.js +23 -6
  246. package/react/dist/qr-code.d.ts +32 -0
  247. package/react/dist/qr-code.js +28 -0
  248. package/react/dist/select.js +10 -3
  249. package/react/dist/selection.d.ts +13 -5
  250. package/react/dist/selection.js +13 -8
  251. package/react/dist/slider.js +5 -1
  252. package/react/dist/status.d.ts +14 -10
  253. package/react/dist/status.js +17 -9
  254. package/react/dist/styles.css +260 -165
  255. package/react/dist/toast.d.ts +19 -12
  256. package/react/dist/toast.js +29 -7
  257. package/react/dist/wallet-address-core.d.ts +8 -4
  258. package/react/dist/wallet-address-core.js +10 -5
  259. package/tokens/README.md +2 -2
  260. package/tokens/assets/onramps/apple-pay.svg +33 -0
  261. package/tokens/assets/onramps/bank.svg +98 -0
  262. package/tokens/assets/onramps/blink.svg +37 -0
  263. package/tokens/assets/onramps/cashapp.svg +33 -0
  264. package/tokens/assets/onramps/crypto.svg +121 -0
  265. package/tokens/assets/onramps/exchange.svg +105 -0
  266. package/tokens/dist/deposit-icons.d.ts +1 -0
  267. package/tokens/dist/deposit-icons.js +28 -0
  268. package/tokens/dist/index.d.ts +16 -0
  269. package/tokens/dist/index.js +16 -0
  270. package/tokens/dist/manifest.json +8 -0
  271. package/tokens/dist/tokens.css +6 -0
  272. package/react/dist/blocks/swap-panel-block.js +0 -178
@@ -1,14 +1,24 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useMemo, useRef, useState } from 'react';
4
- import { createAnimatedNumberModel, createAnimatedNumberTransitions, createFormattedAnimatedNumberModel } from './animated-number-model.js';
3
+ import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
4
+ import { createAnimatedNumberModel, createAnimatedNumberTransitions, createFormattedAnimatedNumberModel, numberFlowPlaces, numberFlowTokenKeys } from './animated-number-model.js';
5
+ import { NumberFlowEngine, numberFlowCommit, numberFlowWebMotion } from './animated-number-flow.js';
6
+ import { numberFlowDeltas, numberFlowDigitLength, numberFlowNeutral, resolveNumberFlowTimings } from '@bloxwap/hig/contracts/number-flow';
5
7
  import { useHIG, useNumberLocale } from './provider.js';
6
8
  import { tokens as higTokens } from '@bloxwap/hig/tokens';
7
9
  import * as en from '@bloxwap/hig/contracts/messages';
8
10
  import { presentNumberFormat } from '@bloxwap/hig/contracts';
9
- export function AnimatedNumberReadout({ duration = 180, trend, options: requested, formattedValue, animateFormatted = false, ...rest }) {
11
+ /**
12
+ * A number that moves place by place when its value changes. It slides by default; `motion='flow'` (or `NumberFlow`, which is
13
+ * this component flowing by default) gives it NumberFlow's motion. Either way the reading assistive technology gets is one
14
+ * static text, and reduced motion draws each new value at once.
15
+ */
16
+ export function AnimatedNumberReadout({ motion = 'slide', ...props }) { return motion === 'flow' ? _jsx(FlowReadout, { ...props }) : _jsx(SlideReadout, { ...props }); }
17
+ /** `AnimatedNumberReadout` with NumberFlow's motion by default: the same component and the same props, under the name the product uses for it. */
18
+ export function NumberFlow({ motion = 'flow', ...props }) { return _jsx(AnimatedNumberReadout, { motion: motion, ...props }); }
19
+ function SlideReadout({ duration = 180, trend, options: requested, formattedValue, animateFormatted = false, animated = true, className, ...rest }) {
10
20
  const locale = useNumberLocale();
11
- const { direction, reducedMotion, messages, numberFormat } = useHIG();
21
+ const { direction, reducedMotion: reduced, messages, numberFormat } = useHIG(), reducedMotion = reduced || !animated;
12
22
  const props = { ...rest, options: presentNumberFormat(requested, numberFormat) };
13
23
  const element = useRef(null);
14
24
  const previous = useRef(null);
@@ -71,6 +81,127 @@ export function AnimatedNumberReadout({ duration = 180, trend, options: requeste
71
81
  return () => { if (generation.current === id)
72
82
  cancel(); };
73
83
  }, [frame, reducedMotion, duration]);
74
- const tokens = settled === frame || reducedMotion ? createAnimatedNumberTransitions(null, frame.model) : frame.tokens;
75
- return _jsxs("span", { className: 'hig-number', children: [_jsx("span", { className: 'hig-sr-only', "aria-label": props.label ? accessible : undefined, children: accessible }), _jsxs("span", { ref: element, className: 'hig-animated-number-visual', "aria-hidden": 'true', dir: direction, children: [known && props.prefix, tokens.map(token => token.changed ? _jsxs("span", { className: 'hig-animated-number-place', "data-hig-animated-number-change": true, children: [token.oldText !== undefined && _jsx("span", { className: 'hig-animated-number-old', children: token.oldText }), token.text && _jsx("span", { className: 'hig-animated-number-new', children: token.text })] }, token.key) : _jsx("span", { children: token.text }, token.key)), known && props.suffix, props.stale && _jsxs("span", { children: [" ", staleText] })] })] });
84
+ // The same elements for the same reading: a parent that draws again without a new value costs this figure no reconciliation.
85
+ const still = settled === frame || reducedMotion;
86
+ return useMemo(() => {
87
+ const tokens = still ? createAnimatedNumberTransitions(null, frame.model) : frame.tokens;
88
+ return _jsxs("span", { className: className ? `hig-number ${className}` : 'hig-number', children: [_jsx("span", { className: 'hig-sr-only', "aria-label": props.label ? accessible : undefined, children: accessible }), _jsxs("span", { ref: element, className: 'hig-animated-number-visual', "aria-hidden": 'true', dir: direction, children: [known && props.prefix, tokens.map(token => token.changed ? _jsxs("span", { className: 'hig-animated-number-place', "data-hig-animated-number-change": true, children: [token.oldText !== undefined && _jsx("span", { className: 'hig-animated-number-old', children: token.oldText }), token.text && _jsx("span", { className: 'hig-animated-number-new', children: token.text })] }, token.key) : _jsx("span", { children: token.text }, token.key)), known && props.suffix, props.stale && _jsxs("span", { children: [" ", staleText] })] })] });
89
+ }, [frame, still, className, props.label, accessible, direction, known, props.prefix, props.suffix, props.stale, staleText]);
90
+ }
91
+ const FlowGroupContext = React.createContext(null);
92
+ /**
93
+ * Moves the flowing figures inside it together: when one changes width, its neighbours in the group slide to their new
94
+ * positions instead of jumping, as the parts of a single figure do. For a row of figures that read as one, such as the units
95
+ * of a countdown. Text between the figures is not moved. On native it draws its children and nothing else.
96
+ */
97
+ export function NumberFlowGroup({ children }) {
98
+ const group = useMemo(() => {
99
+ const members = new Set();
100
+ let pending = false;
101
+ return { join(member) { members.add(member); return () => { members.delete(member); }; }, willUpdate() { if (pending)
102
+ return; pending = true; for (const member of members)
103
+ member.measure(); }, didUpdate() { if (!pending)
104
+ return; pending = false; for (const member of members)
105
+ member.flip(); } };
106
+ }, []);
107
+ return _jsx(FlowGroupContext.Provider, { value: group, children: children });
108
+ }
109
+ /** Runs `before` after a render and before its changes reach the DOM, the one moment the old positions can still be read. Function components have no such hook. */
110
+ class BeforeCommit extends React.Component {
111
+ getSnapshotBeforeUpdate() { this.props.before(); return null; }
112
+ componentDidUpdate() { }
113
+ render() { return this.props.children; }
114
+ }
115
+ const useCommitEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
116
+ const asciiDigits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
117
+ function FlowReadout(all) {
118
+ const { duration, trend, options: requested, formattedValue, animateFormatted = false, animated = true, spinTiming, transformTiming, opacityTiming, digits, continuous = false, willChange = false, className, ...rest } = all;
119
+ const locale = useNumberLocale();
120
+ const { direction, reducedMotion, messages, numberFormat } = useHIG(), group = useContext(FlowGroupContext);
121
+ const props = { ...rest, options: presentNumberFormat(requested, numberFormat) };
122
+ const known = props.value != null && Number.isFinite(props.value), own = known && !!formattedValue;
123
+ const signature = JSON.stringify([locale, direction, props.options ?? {}, own, own && animateFormatted]);
124
+ const model = useMemo(() => own ? createFormattedAnimatedNumberModel(formattedValue, locale, animateFormatted) : createAnimatedNumberModel(props.value, locale, props.options), [props.value, signature, formattedValue]);
125
+ const keys = useMemo(() => numberFlowTokenKeys(model.tokens), [model]);
126
+ const timings = resolveNumberFlowTimings({ duration, spinTiming, transformTiming, opacityTiming }), timingKey = JSON.stringify(timings), flowMotion = useMemo(() => numberFlowWebMotion(timings), [timingKey]);
127
+ const staleText = messages.stale ?? en.stale, prefix = known ? props.prefix ?? '' : '', suffix = known ? props.suffix ?? '' : '', reading = `${prefix}${model.reading}${suffix}`, accessible = `${props.label ? `${props.label}: ` : ''}${reading}${props.stale ? ` ${staleText}` : ''}`;
128
+ // Everything the visual draws, so an affix or the stale mark changing is a change to slide for as much as a digit is.
129
+ const drawn = JSON.stringify([prefix, model.reading, suffix, props.stale ? staleText : '']), placeable = !model.animatable || numberFlowNeutral(model.reading), moving = animated && !reducedMotion && placeable && model.animatable;
130
+ const visual = useRef(null), engine = useRef(null), committed = useRef(null), live = useRef({ moving, motion: flowMotion });
131
+ useEffect(() => group?.join({ measure: () => { if (live.current.moving)
132
+ engine.current?.measure(); }, flip: () => engine.current?.flip(live.current.motion) }), [group]);
133
+ useEffect(() => () => engine.current?.cancel(), []);
134
+ // A figure that is about to change holds its writes until every figure changing in the same commit has read its positions.
135
+ const expected = useRef(false), before = () => { const prior = committed.current; if (!prior || !moving || (prior.model === model && prior.drawn === drawn))
136
+ return; if (!expected.current) {
137
+ expected.current = true;
138
+ numberFlowCommit.expect();
139
+ } if (group)
140
+ group.willUpdate();
141
+ else
142
+ engine.current?.measure(); };
143
+ const change = () => {
144
+ // A reading that slides instead is drawn by another tree; whatever comes back after it is a first paint, not a change.
145
+ if (!placeable) {
146
+ committed.current = null;
147
+ engine.current?.cancel();
148
+ return;
149
+ }
150
+ const flow = engine.current ??= new NumberFlowEngine();
151
+ flow.attach(visual.current);
152
+ live.current = { moving, motion: flowMotion };
153
+ const prior = committed.current;
154
+ committed.current = { value: props.value, signature, model, drawn };
155
+ if (!moving && flow.busy)
156
+ flow.cancel();
157
+ if (!prior || (prior.model === model && prior.drawn === drawn))
158
+ return;
159
+ // A new locale, format or direction is a different reading rather than a new value, and a hidden page has nobody to move for.
160
+ if (!moving || prior.signature !== signature || !prior.model.animatable || document.visibilityState === 'hidden') {
161
+ flow.cancel();
162
+ group?.didUpdate();
163
+ return;
164
+ }
165
+ if (group)
166
+ group.didUpdate();
167
+ else
168
+ flow.flip(flowMotion);
169
+ if (prior.model === model || flowMotion.spin.duration <= 0)
170
+ return;
171
+ let movement = 0;
172
+ if (Number.isFinite(prior.value) && Number.isFinite(props.value)) {
173
+ const wanted = typeof trend === 'function' ? trend(prior.value, props.value) : trend ?? Math.sign(props.value - prior.value);
174
+ movement = wanted === -1 || wanted === 1 ? wanted : 0;
175
+ }
176
+ const old = new Map(numberFlowPlaces(prior.model).map(place => [place.key, place.digit])), places = numberFlowPlaces(model), deltas = numberFlowDeltas(numberFlowPlaces(prior.model), places, { trend: movement, digits, continuous }), spins = new Map();
177
+ for (const place of places) {
178
+ const delta = deltas.get(place.key) ?? 0, from = old.get(place.key) ?? 0;
179
+ if (delta)
180
+ spins.set(place.key, { delta, from, length: numberFlowDigitLength(digits, place.place, Math.max(place.digit, from)) });
181
+ }
182
+ flow.spin(spins, model.digits ?? asciiDigits, flowMotion.spin);
183
+ };
184
+ useCommitEffect(() => { try {
185
+ change();
186
+ }
187
+ finally {
188
+ if (expected.current) {
189
+ expected.current = false;
190
+ numberFlowCommit.done();
191
+ }
192
+ } });
193
+ // The same elements for the same reading: a parent that draws again without a new value costs this figure no reconciliation.
194
+ const figure = useMemo(() => {
195
+ // The digits, first to last with the separators between them, sit in one box the engine clips while it changes width; signs and currency stay outside it.
196
+ const parts = model.tokens.map((token, index) => token.digit ? _jsx("span", { className: 'hig-number-flow-place', "data-hig-flow-key": keys[index], "data-hig-flow-digit": '', children: _jsx("span", { className: 'hig-number-flow-digit', children: token.text }) }, keys[index]) : _jsx("span", { className: 'hig-number-flow-part', "data-hig-flow-key": keys[index], children: token.text }, keys[index]));
197
+ const found = model.tokens.findIndex(token => token.digit), first = found < 0 ? parts.length : found;
198
+ let last = parts.length - 1;
199
+ while (last >= first && !model.tokens[last].digit)
200
+ last--;
201
+ return _jsxs("span", { className: className ? `hig-number hig-number-flow ${className}` : 'hig-number hig-number-flow', children: [_jsx("span", { className: 'hig-sr-only', "aria-label": props.label ? accessible : undefined, children: accessible }), _jsxs("span", { ref: visual, className: 'hig-animated-number-visual', "aria-hidden": 'true', dir: direction, "data-will-change": willChange ? '' : undefined, children: [prefix && _jsx("span", { className: 'hig-number-flow-part', "data-hig-flow-key": 'affix:prefix', children: prefix }), _jsxs("span", { className: 'hig-number-flow-core', dir: 'ltr', children: [parts.slice(0, first), _jsxs("span", { className: 'hig-number-flow-digits', children: [parts.slice(first, last + 1), _jsx("span", { className: 'hig-number-flow-ghosts' }, 'ghosts')] }, 'digits'), parts.slice(last + 1)] }), suffix && _jsx("span", { className: 'hig-number-flow-part', "data-hig-flow-key": 'affix:suffix', children: suffix }), props.stale && _jsxs("span", { className: 'hig-number-flow-part', "data-hig-flow-key": 'affix:stale', children: [" ", staleText] }), _jsx("span", { className: 'hig-number-flow-ghosts' })] })] });
202
+ }, [model, keys, className, props.label, accessible, direction, willChange, prefix, suffix, props.stale, staleText]);
203
+ // The number itself is always drawn left to right, as digits are in every script; a reading that needs reordering slides instead.
204
+ if (!placeable)
205
+ return _jsx(SlideReadout, { ...all });
206
+ return _jsx(BeforeCommit, { before: before, children: figure });
76
207
  }
@@ -24,6 +24,8 @@ export interface AssetBalanceRowProps extends Omit<React.HTMLAttributes<HTMLElem
24
24
  trailing?: React.ReactNode;
25
25
  /** What assistive technology reads for `trailing`, in place of its content, for an icon or a figure whose text is not what should be heard. */
26
26
  trailingLabel?: string;
27
+ /** `trailing` holds a control, such as a Copy or Remove button. With `onSelect`, the row becomes a `div.hig-asset-row` holding the row's button (`button.hig-asset-row-main`: the artwork, name and figures) and the control beside it, so the control is never inside the button; it is never hidden from assistive technology. A static row already keeps it reachable. */
28
+ trailingInteractive?: boolean;
27
29
  /** Marks the row in use: a check on the trailing edge, and `aria-current` for assistive technology. */
28
30
  selected?: boolean;
29
31
  /** Dims the row and ignores presses. */
@@ -32,4 +34,4 @@ export interface AssetBalanceRowProps extends Omit<React.HTMLAttributes<HTMLElem
32
34
  onSelect?: () => void;
33
35
  }
34
36
  /** One holding in a list: round artwork, the asset's name over its symbol, and its dollar value over its units. Both numbers update place by place. */
35
- export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, unitsSuffix, headline, amounts, tag, trailing, trailingLabel, selected, disabled, onSelect, className, ...rest }: AssetBalanceRowProps): React.JSX.Element;
37
+ export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, unitsSuffix, headline, amounts, tag, trailing, trailingLabel, trailingInteractive, selected, disabled, onSelect, className, ...rest }: AssetBalanceRowProps): React.JSX.Element;
@@ -1,16 +1,22 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Check } from '@bloxwap/icons/react/check';
3
4
  import { AnimatedNumberReadout } from './animated-number.js';
4
5
  import { PressDecoration } from './provider.js';
5
6
  const usd = { style: 'currency', currency: 'USD' }, units = { maximumFractionDigits: 6 };
6
- const check = _jsx("svg", { className: 'hig-asset-row-check', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '20', height: '20', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', children: _jsx("path", { d: 'm4.5 10.5 3.5 3.5 7.5-8' }) });
7
+ const check = _jsx(Check, { size: 20, className: 'hig-asset-row-check' });
7
8
  /** One holding in a list: round artwork, the asset's name over its symbol, and its dollar value over its units. Both numbers update place by place. */
8
- export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, unitsSuffix, headline = 'value', amounts = true, tag, trailing, trailingLabel, selected, disabled, onSelect, className, ...rest }) {
9
- const unitsFirst = headline === 'units';
9
+ export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, unitsSuffix, headline = 'value', amounts = true, tag, trailing, trailingLabel, trailingInteractive, selected, disabled, onSelect, className, ...rest }) {
10
+ const unitsFirst = headline === 'units', hasTrailing = trailing != null && trailing !== false, split = !!trailingInteractive && hasTrailing;
10
11
  const figures = amounts && _jsxs(_Fragment, { children: [_jsx("strong", { children: unitsFirst ? _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions, suffix: unitsSuffix }) : _jsx(AnimatedNumberReadout, { value: value, options: usd }) }), !unitsFirst && balance !== undefined && _jsx("span", { children: _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions, suffix: unitsSuffix }) })] });
11
- const content = _jsxs(_Fragment, { children: [_jsx("span", { className: 'hig-asset-row-icon', "aria-hidden": 'true', children: typeof icon === 'string' ? _jsx("img", { src: icon, alt: '' }) : icon ?? symbol.slice(0, 3) }), _jsxs("span", { className: 'hig-asset-row-identity', children: [_jsx("strong", { children: name }), _jsx("span", { children: symbol })] }), (amounts || tag) && _jsxs("span", { className: 'hig-asset-row-amounts', children: [figures, tag && _jsx("small", { className: 'hig-asset-row-tag', children: tag })] }), trailing != null && trailing !== false && _jsx("span", { className: 'hig-asset-row-trailing', "aria-hidden": trailingLabel !== undefined || undefined, children: trailing }), trailingLabel !== undefined && trailing != null && trailing !== false && _jsx("span", { className: 'hig-sr-only hig-asset-row-trailing-label', children: trailingLabel }), selected && check] });
12
+ const main = _jsxs(_Fragment, { children: [_jsx("span", { className: 'hig-asset-row-icon', "aria-hidden": 'true', children: typeof icon === 'string' ? _jsx("img", { src: icon, alt: '' }) : icon ?? symbol.slice(0, 3) }), _jsxs("span", { className: 'hig-asset-row-identity', children: [_jsx("strong", { children: name }), _jsx("span", { children: symbol })] }), (amounts || tag) && _jsxs("span", { className: 'hig-asset-row-amounts', children: [figures, tag && _jsx("small", { className: 'hig-asset-row-tag', children: tag })] })] });
13
+ const end = _jsxs(_Fragment, { children: [hasTrailing && _jsx("span", { className: 'hig-asset-row-trailing', "aria-hidden": !trailingInteractive && trailingLabel !== undefined || undefined, children: trailing }), !trailingInteractive && trailingLabel !== undefined && hasTrailing && _jsx("span", { className: 'hig-sr-only hig-asset-row-trailing-label', children: trailingLabel }), selected && check] });
14
+ const content = _jsxs(_Fragment, { children: [main, end] });
12
15
  const classes = `hig-asset-row${className ? ` ${className}` : ''}`;
13
16
  const state = { 'aria-current': selected ? 'true' : undefined, 'data-selected': selected || undefined };
17
+ // A control in the trailing slot sits beside the row's button, never inside it.
18
+ if (onSelect && split)
19
+ return _jsxs("div", { ...rest, "data-selected": state['data-selected'], "aria-disabled": disabled || undefined, className: classes, children: [_jsxs("button", { type: 'button', ...(state['aria-current'] ? { 'aria-current': state['aria-current'] } : {}), className: 'hig-asset-row-main', disabled: disabled, onClick: onSelect, children: [main, _jsx(PressDecoration, { kind: 'row', disabled: disabled })] }), end] });
14
20
  return onSelect
15
21
  ? _jsxs("button", { type: 'button', ...rest, ...state, className: classes, disabled: disabled, onClick: onSelect, children: [content, _jsx(PressDecoration, { kind: 'row', disabled: disabled })] })
16
22
  // A static row is a generic div, where aria-disabled is not read; disabled, it becomes a group, which carries the state.
@@ -0,0 +1,2 @@
1
+ /** Start an operation and test whether its result still belongs to this owner. */
2
+ export declare function useAsyncResult(owner: unknown): () => () => boolean;
@@ -0,0 +1,11 @@
1
+ import { useEffect, useRef } from 'react';
2
+ /** Start an operation and test whether its result still belongs to this owner. */
3
+ export function useAsyncResult(owner) {
4
+ const state = useRef({ owner, generation: 0, alive: true });
5
+ if (!Object.is(state.current.owner, owner)) {
6
+ state.current.owner = owner;
7
+ state.current.generation++;
8
+ }
9
+ useEffect(() => { state.current.alive = true; return () => { state.current.alive = false; state.current.generation++; }; }, []);
10
+ return () => { const generation = ++state.current.generation; return () => state.current.alive && state.current.generation === generation; };
11
+ }
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ /** Token roles of the default face palette, in this order: the `avatarColorRoles` of `@bloxwap/hig/contracts/avatar`, which web and native share. The order and the number of colours decide which colours a seed lands on. */
3
+ export declare const avatarColorRoles: readonly ["action", "info", "negative", "warning"];
4
+ export interface AvatarProps {
5
+ /** The person or account. It is the accessible name, the first two letters are the initials, and it is the seed of the generated face unless `seed` is given. */
6
+ name: string;
7
+ /** An image to show instead, cropped to fill the box. If it fails to load, the initials or the generated face show in its place. */
8
+ src?: string;
9
+ /** What the generated face is drawn from, such as a wallet address. The same seed and colours draw the same face on web and native. It is case-sensitive. Passing it selects the generated face. Defaults to `name`. */
10
+ seed?: string;
11
+ /** What shows without an image: `initials`, the first two letters of `name` on the well fill, or `beam`, a generated face. Defaults to `initials`, or to `beam` when `seed` is given. */
12
+ variant?: 'initials' | 'beam';
13
+ /** Width and height in CSS pixels. Defaults to 40. With it, the initials are drawn at 40% of the size. A size that is not a finite number of zero or more is ignored. */
14
+ size?: number;
15
+ /** Palette of the generated face, as CSS colours. Defaults to the `action`, `info`, `negative` and `warning` token roles (`avatarColorRoles`), which are Display P3 where the screen supports it. A seed picks by position, so the same list in the same order keeps the same faces. */
16
+ colors?: readonly string[];
17
+ /** One colour for the eyes and mouth of every generated face. Left out, each face takes the `background` role on a bright colour and the `text` role on a deep one. */
18
+ faceColor?: string;
19
+ /** A square with no rounded corners instead of a disc, for a host that clips it to its own shape. */
20
+ square?: boolean;
21
+ /** Hides the avatar from assistive technology, for an avatar beside the name it stands for. */
22
+ decorative?: boolean;
23
+ }
24
+ /** A person or account as a 40px disc: an image, else the first two letters of the name, else (with `variant='beam'` or a `seed`) a face generated from the seed. The face is an identity picture, so it is the same in right-to-left layouts and it never moves. It renders again only when one of its props changes. */
25
+ export declare function Avatar({ name, src, seed, variant, size, colors, faceColor, square, decorative }: AvatarProps): React.JSX.Element;
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
4
+ import { avatarColorRoles as paletteRoles, avatarInitials, avatarSide, beamAvatar, beamEye, beamSize } from '@bloxwap/hig/contracts/avatar';
5
+ import { useColors } from './provider.js';
6
+ /** Token roles of the default face palette, in this order: the `avatarColorRoles` of `@bloxwap/hig/contracts/avatar`, which web and native share. The order and the number of colours decide which colours a seed lands on. */
7
+ export const avatarColorRoles = paletteRoles;
8
+ const beamPaints = avatarColorRoles.map(role => `var(--hig-${role})`), beamInks = { dark: 'var(--hig-background)', light: 'var(--hig-text)' }, beamBox = `0 0 ${beamSize} ${beamSize}`;
9
+ /** The generated face as inline SVG. The drawing is kept until its seed, colours or ink change, so a parent or a provider that renders again with the same face computes nothing and writes nothing to the page. */
10
+ function BeamFace({ seed, colors, faceColor }) {
11
+ // The default palette paints the CSS variables (Display P3 where supported) and chooses each ink from the provider's resolved roles, so a host `primaryColor` is read too.
12
+ // A host often writes its palette inline, so the palette is compared by its colours, not by the array.
13
+ const roles = useColors(), own = colors && colors.length > 0 ? colors : undefined, palette = own?.join('\n');
14
+ return useMemo(() => {
15
+ const face = beamAvatar(seed, own ?? avatarColorRoles.map(role => roles[role]), beamInks), paint = own ?? beamPaints, ink = faceColor ?? face.faceColor;
16
+ return _jsxs("svg", { viewBox: beamBox, "aria-hidden": 'true', focusable: 'false', children: [_jsx("rect", { width: beamSize, height: beamSize, style: { fill: paint[face.backgroundIndex] } }), _jsx("rect", { width: beamSize, height: beamSize, rx: face.wrapperRadius, transform: face.wrapperTransform, style: { fill: paint[face.wrapperIndex] } }), _jsxs("g", { transform: face.faceTransform, children: [_jsx("path", { d: face.mouthPath, style: face.mouthStroked ? { fill: 'none', stroke: ink, strokeLinecap: 'round' } : { fill: ink } }), _jsx("rect", { x: face.leftEyeX, y: beamEye.y, width: beamEye.width, height: beamEye.height, rx: beamEye.radius, style: { fill: ink } }), _jsx("rect", { x: face.rightEyeX, y: beamEye.y, width: beamEye.width, height: beamEye.height, rx: beamEye.radius, style: { fill: ink } })] })] });
17
+ // `own` is read through `palette`: the same colours in a new array are the same drawing.
18
+ }, [seed, palette, faceColor, roles]);
19
+ }
20
+ const samePalette = (a, b) => a === b || (a != null && b != null && a.length === b.length && a.every((color, index) => color === b[index]));
21
+ /**
22
+ * The same props: each one identical, and `colors` the same colours in whichever array, because a host often writes its palette inline.
23
+ * Each prop is read by name, because walking a list of names costs as much as the render it saves. `tests/avatar.dom.test.tsx` changes every prop of AvatarProps in turn, so a prop this does not read fails there.
24
+ */
25
+ const sameProps = (a, b) => a.name === b.name && a.seed === b.seed && a.src === b.src && a.size === b.size && a.variant === b.variant && a.faceColor === b.faceColor && a.square === b.square && a.decorative === b.decorative && samePalette(a.colors, b.colors);
26
+ /** What Avatar draws, kept while its props are the same: a list that renders again runs none of this for the rows that did not change. */
27
+ const Drawing = React.memo(function AvatarDrawing({ name, src, seed, variant, size, colors, faceColor, square, decorative }) {
28
+ const [failed, setFailed] = useState();
29
+ const image = useRef(null);
30
+ // An image that failed before this component could listen (a server-rendered page that has not hydrated yet) has fired its error event already.
31
+ // It reads as complete with no width; `decode()` tells it from a sound image with no size of its own, such as some SVG files.
32
+ useEffect(() => {
33
+ const node = image.current;
34
+ if (!src || !node || !node.complete || node.naturalWidth > 0 || typeof node.decode !== 'function')
35
+ return;
36
+ let current = true;
37
+ node.decode().catch(() => { if (current)
38
+ setFailed(src); });
39
+ return () => { current = false; };
40
+ }, [src]);
41
+ const side = avatarSide(size), box = side === undefined ? undefined : { width: side, height: side }, flat = square || undefined;
42
+ if (src && failed !== src)
43
+ return _jsx("img", { ref: image, className: 'hig-avatar', alt: decorative ? '' : name, src: src, style: box, "data-square": flat, onError: () => setFailed(src) });
44
+ const named = decorative ? { 'aria-hidden': true } : { role: 'img', 'aria-label': name };
45
+ if ((variant ?? (seed == null ? 'initials' : 'beam')) === 'beam')
46
+ return _jsx("span", { ...named, className: 'hig-avatar', "data-variant": 'beam', "data-square": flat, style: box, children: _jsx(BeamFace, { seed: seed ?? name, colors: colors, faceColor: faceColor }) });
47
+ return _jsx("span", { ...named, className: 'hig-avatar', "data-square": flat, style: side === undefined ? undefined : { width: side, height: side, fontSize: side * 0.4, lineHeight: 1 }, children: avatarInitials(name) });
48
+ }, sameProps);
49
+ /** A person or account as a 40px disc: an image, else the first two letters of the name, else (with `variant='beam'` or a `seed`) a face generated from the seed. The face is an identity picture, so it is the same in right-to-left layouts and it never moves. It renders again only when one of its props changes. */
50
+ export function Avatar({ name, src, seed, variant, size, colors, faceColor, square, decorative }) { return _jsx(Drawing, { name: name, src: src, seed: seed, variant: variant, size: size, colors: colors, faceColor: faceColor, square: square, decorative: decorative }); }
@@ -55,6 +55,10 @@ export interface AccountBlockProps extends Omit<React.HTMLAttributes<HTMLElement
55
55
  onShowAddress?: () => void;
56
56
  /** A control on the trailing edge of the header, usually an `IconButton`. Replaces the QR button. */
57
57
  headerAction?: React.ReactNode;
58
+ /** Pins the header to the top of the nearest scroller: transparent at rest, filled once content scrolls under it, and still when it starts to stick. See Pinned headers. */
59
+ stickyHeader?: boolean;
60
+ /** `id` of the header's heading, so a host dialog or sheet can name itself with `aria-labelledby`. */
61
+ headingId?: string;
58
62
  /** Total in dollars. Defaults to the sum of the asset values (with `sections`, the sum of the totals of the sections that are drawn, which is unknown when any of those totals is); `null` reads as unknown. */
59
63
  balance?: number | null;
60
64
  /** Every holding as one list: the pinned asset, then the rest by value. Ignored when `sections` is set. */
@@ -89,4 +93,4 @@ export declare function accountSectionRows(assets: readonly AccountAsset[], pinn
89
93
  rest: AccountAsset[];
90
94
  };
91
95
  /** An account at a glance: a header, the total with a deposit action, the pinned dollar balance, then every other holding by value. */
92
- export declare function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets, sections, pinnedSymbol, pinnedId, order, onDeposit, depositLabel, onAssetSelect, className, ...rest }: AccountBlockProps): React.JSX.Element;
96
+ export declare function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets, sections, pinnedSymbol, pinnedId, order, onDeposit, depositLabel, onAssetSelect, stickyHeader, headingId, className, ...rest }: AccountBlockProps): React.JSX.Element;
@@ -10,7 +10,7 @@ import { ScreenHeader, qrIcon } from './screen-header.js';
10
10
  export { AssetBalanceRow } from '../asset-balance-row.js';
11
11
  const usdCoin = 'USD Coin', usd = { style: 'currency', currency: 'USD' };
12
12
  /** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
13
- export const assetValue = (asset) => asset.value !== undefined ? asset.value : asset.balance != null && asset.price != null ? asset.balance * asset.price : null;
13
+ export const assetValue = (asset) => { const value = asset.value !== undefined ? asset.value : asset.balance != null && asset.price != null ? asset.balance * asset.price : null; return value != null && Number.isFinite(value) ? value : null; };
14
14
  /** The account's rows in display order: the pinned asset (the one with `options.pinnedId`, else the first with `pinnedSymbol`, else a zero placeholder), then every other asset by dollar value, largest first, unknown values last and ties by name, or with `options.order` `given` in the order passed. */
15
15
  export function accountRows(assets, pinnedSymbol = 'USDC', options = {}) {
16
16
  const byId = options.pinnedId === undefined ? -1 : assets.findIndex(asset => asset.id === options.pinnedId);
@@ -20,23 +20,28 @@ export function accountRows(assets, pinnedSymbol = 'USDC', options = {}) {
20
20
  const rest = options.order === 'given' ? others : others.sort((a, b) => { const left = assetValue(a), right = assetValue(b); return left === right ? a.name.localeCompare(b.name) : left === null ? 1 : right === null ? -1 : right - left || a.name.localeCompare(b.name); });
21
21
  return { pinned, rest };
22
22
  }
23
- const sum = (assets) => assets.reduce((total, asset) => total + (assetValue(asset) ?? 0), 0);
23
+ const sum = (assets) => { let total = 0; for (const asset of assets) {
24
+ const value = assetValue(asset);
25
+ if (value == null || !Number.isFinite(value))
26
+ return null;
27
+ total += value;
28
+ } return Number.isFinite(total) ? total : null; };
24
29
  /** A section's total: its own `total`, or the sum of its asset values. */
25
- export const accountSectionTotal = (section) => section.total !== undefined ? section.total : sum(section.assets);
30
+ export const accountSectionTotal = (section) => section.total !== undefined ? (section.total != null && Number.isFinite(section.total) ? section.total : null) : sum(section.assets);
26
31
  /** The block total for `sections`: the sum of the section totals, or unknown (`null`) when any of them is unknown. Pass only the sections that are drawn. */
27
32
  const accountSectionsTotal = (sections) => { let all = 0; for (const section of sections) {
28
33
  const total = accountSectionTotal(section);
29
34
  if (total === null)
30
35
  return null;
31
36
  all += total;
32
- } return all; };
37
+ } return Number.isFinite(all) ? all : null; };
33
38
  /** A section's rows in display order: the pinned asset first when the section holds it (no placeholder), then the rest by dollar value as in `accountRows`. */
34
39
  export function accountSectionRows(assets, pinnedSymbol = 'USDC', options = {}) {
35
40
  const { pinned, rest } = accountRows(assets, pinnedSymbol, options);
36
41
  return { pinned: assets.includes(pinned) ? pinned : null, rest };
37
42
  }
38
43
  /** An account at a glance: a header, the total with a deposit action, the pinned dollar balance, then every other holding by value. */
39
- export function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets = [], sections, pinnedSymbol = 'USDC', pinnedId, order, onDeposit, depositLabel, onAssetSelect, className, ...rest }) {
44
+ export function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets = [], sections, pinnedSymbol = 'USDC', pinnedId, order, onDeposit, depositLabel, onAssetSelect, stickyHeader, headingId, className, ...rest }) {
40
45
  const { messages } = useHIG();
41
46
  const id = useId();
42
47
  const shown = sections?.filter(section => section.assets.length > 0);
@@ -58,5 +63,5 @@ export function AccountBlock({ title, onBack, onShowAddress, headerAction, balan
58
63
  const { pinned, rest: others } = accountRows(assets, pinnedSymbol, { order, pinnedId });
59
64
  list = _jsxs("ul", { className: 'hig-account-assets', children: [row(pinned, true, pinnedId), others.map(asset => row(asset, false, pinnedId))] });
60
65
  }
61
- return _jsxs("section", { ...rest, className: `hig-account-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title ?? messages.account ?? en.account, onBack: onBack, action: headerAction ?? (onShowAddress && _jsxs("button", { type: 'button', className: 'hig-swap-back hig-account-address', "aria-label": messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: [qrIcon, _jsx(PressDecoration, { kind: 'back' })] })) }), _jsxs("div", { className: 'hig-account-summary', children: [_jsx("div", { className: 'hig-account-balance', children: _jsx(AnimatedNumberReadout, { value: total, label: messages.accountBalance ?? en.accountBalance, options: usd }) }), onDeposit && _jsx(Button, { onClick: onDeposit, children: depositLabel ?? messages.deposit ?? en.deposit })] }), list] });
66
+ return _jsxs("section", { ...rest, className: `hig-account-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title ?? messages.account ?? en.account, onBack: onBack, headingId: headingId, stickyHeader: stickyHeader, action: headerAction ?? (onShowAddress && _jsxs("button", { type: 'button', className: 'hig-swap-back hig-account-address', "aria-label": messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: [qrIcon, _jsx(PressDecoration, { kind: 'back' })] })) }), _jsxs("div", { className: 'hig-account-summary', children: [_jsx("div", { className: 'hig-account-balance', children: _jsx(AnimatedNumberReadout, { value: total, label: messages.accountBalance ?? en.accountBalance, options: usd }) }), onDeposit && _jsx(Button, { onClick: onDeposit, children: depositLabel ?? messages.deposit ?? en.deposit })] }), list] });
62
67
  }
@@ -0,0 +1,106 @@
1
+ import React from 'react';
2
+ /** A market's live heat signal: `watch` while it is being watched, `up` or `down` once it trends. */
3
+ export type AssetSignal = 'watch' | 'up' | 'down';
4
+ /** The three views of the list: every market, the markets with an open position, and the markets with a signal. */
5
+ export type AssetsView = 'all' | 'positions' | 'trend';
6
+ /** One market the host offers. Every word is host text. */
7
+ export interface AssetItem {
8
+ /** Stable id the host switches on. */
9
+ id: string;
10
+ /** Bitcoin. */
11
+ name: string;
12
+ /** BTC. */
13
+ symbol: string;
14
+ /** `id` of the `AssetCategory` whose section the market sits in. */
15
+ category: string;
16
+ /** Short host text after the symbol on the second line, such as the maximum leverage: `40×`. */
17
+ detail?: string;
18
+ /** Round artwork: an image URL or a host element. Without it the row shows the first letters of the symbol. */
19
+ icon?: string | React.ReactElement;
20
+ /** The trailing signal disc. `null` draws an empty disc, for a market with no signal yet; leave it out to draw no disc. */
21
+ signal?: AssetSignal | null;
22
+ /** The viewer holds an open position in this market, so it shows under Positions. */
23
+ position?: boolean;
24
+ /** Host content on the trailing edge, before the signal disc, such as the live result of the viewer's open position. It is drawn only (it sits inside the row button, hidden from assistive technology); the row reads `trailingLabel` for it. */
25
+ trailing?: React.ReactNode;
26
+ /** Words the row reads after its symbol line, such as `open position`, for what `trailing` shows. */
27
+ trailingLabel?: string;
28
+ /** More text the search matches, such as an alias or a ticker on another venue. */
29
+ keywords?: string;
30
+ disabled?: boolean;
31
+ }
32
+ /** A market type: a section of the list and a capsule in the category filter. */
33
+ export interface AssetCategory {
34
+ id: string;
35
+ /** Crypto. */
36
+ label: string;
37
+ /** A badge on the section heading's trailing edge, such as OPEN. Bloxwap trades around the clock, so there is no closed badge: use `opensAt` for a legacy market that is shut. */
38
+ status?: {
39
+ label: string;
40
+ tone?: 'positive' | 'negative' | 'warning' | 'info';
41
+ };
42
+ /** When the legacy market behind this category next opens, as epoch milliseconds or a `Date`. While it is ahead, the badge counts down to it (“Opens in 2:14:33”) in place of `status`, and the heading reads it in words. Once it passes, `status` shows again. */
43
+ opensAt?: number | Date;
44
+ }
45
+ export interface AssetsBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title' | 'onSelect'> {
46
+ /** Shows a clear button in the search field while it holds text: it empties the query and returns focus to the field. Named by `messages.clearSearch`. */
47
+ clearable?: boolean;
48
+ /** Heading. Defaults to the built-in “Assets”. */
49
+ title?: string;
50
+ /** Shows Close on the trailing edge of the header. */
51
+ onClose?: () => void;
52
+ assets: readonly AssetItem[];
53
+ /** Sections and filter capsules, in order. A market whose category is not listed is not shown. */
54
+ categories: readonly AssetCategory[];
55
+ onSelect: (asset: AssetItem) => void;
56
+ /** `id` of the market in use: its row is marked current. */
57
+ selectedId?: string | null;
58
+ view?: AssetsView;
59
+ defaultView?: AssetsView;
60
+ onViewChange?: (view: AssetsView) => void;
61
+ /** `id` of the chosen category; `''` is All. */
62
+ category?: string;
63
+ defaultCategory?: string;
64
+ onCategoryChange?: (category: string) => void;
65
+ query?: string;
66
+ defaultQuery?: string;
67
+ onQueryChange?: (query: string) => void;
68
+ /** `false` leaves out the category filter. Defaults to `true` when there is more than one category. */
69
+ categoryFilter?: boolean;
70
+ /** Shows the loading text in place of the empty text while the list is empty. */
71
+ loading?: boolean;
72
+ /** Pins the header (title and Close) to the top of the nearest scroller while the rest scrolls, as `ScreenHeader stickyHeader` does: transparent at rest, filled once content scrolls under it. */
73
+ stickyHeader?: boolean;
74
+ /** `id` of the heading, so a dialog or sheet around the block can name itself by it (`aria-labelledby`, `GestureSheet labelledBy`). */
75
+ headingId?: string;
76
+ /** Freezes the opening countdown at the text it last showed, stops its timer and its digits rolling, for example while the block is off screen. */
77
+ paused?: boolean;
78
+ /** The host's clock in epoch milliseconds, read for the opening countdown. Defaults to `Date.now`. */
79
+ now?: () => number;
80
+ /** A button under the empty text, drawn only while the list is empty and not `loading`, such as Browse all markets on an empty Positions view. `testID` becomes its `data-testid`. */
81
+ emptyAction?: AssetsEmptyAction;
82
+ /** With a hardware pointer, focus the search field on mount so typing filters at once. */
83
+ autoFocusSearch?: boolean;
84
+ /** While the search field holds a query and the arrows have not moved, Enter chooses the first enabled match, as a search box's top hit. By default Enter then chooses only a lone match. */
85
+ enterChoosesFirst?: boolean;
86
+ }
87
+ /** The empty list's action. */
88
+ export interface AssetsEmptyAction {
89
+ label: string;
90
+ onPress: () => void;
91
+ testID?: string;
92
+ }
93
+ /** The markets a view, category and query leave, grouped by category in the host's order. Empty sections are dropped. */
94
+ export declare function filterAssets(assets: readonly AssetItem[], categories: readonly AssetCategory[], { view, category, query }?: {
95
+ view?: AssetsView;
96
+ category?: string;
97
+ query?: string;
98
+ }): {
99
+ category: AssetCategory;
100
+ assets: AssetItem[];
101
+ }[];
102
+ /**
103
+ * Choose a market as one screen: a header, a search field, category capsules, the All / Positions / Trend views, then the
104
+ * markets in sections by category, each with its icon, name, symbol and detail, and its signal disc. The host owns the data.
105
+ */
106
+ export declare function AssetsBlock({ title, onClose, assets, categories, onSelect, selectedId, view, defaultView, onViewChange, category, defaultCategory, onCategoryChange, query, defaultQuery, onQueryChange, categoryFilter, loading, stickyHeader, headingId, clearable, paused, now: clock, emptyAction, autoFocusSearch, enterChoosesFirst, className, ...rest }: AssetsBlockProps): React.JSX.Element;