@bloxwap/hig 0.6.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 (286) 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 +45 -2
  31. package/contracts/dist/index.js +145 -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 +62 -2
  35. package/contracts/dist/messages.js +22 -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 +62 -7
  47. package/native/dist/account-block.js +54 -11
  48. package/native/dist/animated-number-model.d.ts +47 -1
  49. package/native/dist/animated-number-model.js +248 -21
  50. package/native/dist/animated-number.d.ts +41 -1
  51. package/native/dist/animated-number.js +165 -17
  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 +19 -1
  55. package/native/dist/asset-balance-row.js +24 -8
  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 +16 -2
  65. package/native/dist/bar-mark.js +23 -7
  66. package/native/dist/bar-pnl.js +7 -5
  67. package/native/dist/blocks.d.ts +13 -14
  68. package/native/dist/blocks.js +10 -6
  69. package/native/dist/brand.js +2 -1
  70. package/native/dist/button.d.ts +7 -2
  71. package/native/dist/button.js +16 -4
  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.d.ts +1 -1
  78. package/native/dist/data.js +8 -4
  79. package/native/dist/explainer-block.d.ts +91 -0
  80. package/native/dist/explainer-block.js +34 -0
  81. package/native/dist/field.d.ts +19 -5
  82. package/native/dist/field.js +56 -9
  83. package/native/dist/figure.d.ts +23 -0
  84. package/native/dist/figure.js +10 -0
  85. package/native/dist/gesture-sheet-model.d.ts +50 -0
  86. package/native/dist/gesture-sheet-model.js +105 -0
  87. package/native/dist/gesture-sheet-next.d.ts +82 -0
  88. package/native/dist/gesture-sheet-next.js +315 -0
  89. package/native/dist/gesture-sheet.d.ts +5 -1
  90. package/native/dist/gesture-sheet.js +13 -6
  91. package/native/dist/icons.d.ts +9 -6
  92. package/native/dist/icons.js +25 -24
  93. package/native/dist/language-block.d.ts +14 -1
  94. package/native/dist/language-block.js +11 -4
  95. package/native/dist/list-group.d.ts +44 -8
  96. package/native/dist/list-group.js +84 -13
  97. package/native/dist/manage-position-block.d.ts +35 -2
  98. package/native/dist/manage-position-block.js +41 -11
  99. package/native/dist/market-row.d.ts +46 -0
  100. package/native/dist/market-row.js +41 -0
  101. package/native/dist/navigation.js +5 -3
  102. package/native/dist/notifications-block.d.ts +30 -2
  103. package/native/dist/notifications-block.js +16 -8
  104. package/native/dist/number-format.d.ts +6 -0
  105. package/native/dist/number-format.js +9 -0
  106. package/native/dist/pickers.d.ts +32 -2
  107. package/native/dist/pickers.js +17 -9
  108. package/native/dist/position-block.d.ts +66 -10
  109. package/native/dist/position-block.js +45 -11
  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 +38 -5
  115. package/native/dist/profile-block.js +31 -6
  116. package/native/dist/provider.d.ts +14 -5
  117. package/native/dist/provider.js +32 -6
  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 +23 -5
  121. package/native/dist/radio-group.js +40 -12
  122. package/native/dist/recipes.d.ts +6 -0
  123. package/native/dist/recipes.js +6 -0
  124. package/native/dist/reward-block.d.ts +55 -13
  125. package/native/dist/reward-block.js +37 -14
  126. package/native/dist/screen-header.d.ts +59 -0
  127. package/native/dist/screen-header.js +37 -0
  128. package/native/dist/select.js +4 -2
  129. package/native/dist/selection.d.ts +3 -2
  130. package/native/dist/selection.js +1 -0
  131. package/native/dist/setting-header.d.ts +2 -8
  132. package/native/dist/setting-header.js +2 -11
  133. package/native/dist/setting-switch.d.ts +15 -2
  134. package/native/dist/setting-switch.js +11 -4
  135. package/native/dist/signals-block.d.ts +26 -2
  136. package/native/dist/signals-block.js +14 -4
  137. package/native/dist/slider.js +5 -1
  138. package/native/dist/sound-haptics-block.d.ts +29 -2
  139. package/native/dist/sound-haptics-block.js +19 -8
  140. package/native/dist/status.d.ts +47 -14
  141. package/native/dist/status.js +39 -22
  142. package/native/dist/sticky-header.d.ts +28 -0
  143. package/native/dist/sticky-header.js +29 -0
  144. package/native/dist/surface.d.ts +3 -1
  145. package/native/dist/surface.js +2 -1
  146. package/native/dist/swap-amount-card.d.ts +57 -0
  147. package/native/dist/swap-amount-card.js +31 -0
  148. package/native/dist/swap-panel-block.d.ts +11 -4
  149. package/native/dist/swap-panel-block.js +67 -38
  150. package/native/dist/swap-parts.d.ts +5 -10
  151. package/native/dist/swap-parts.js +22 -24
  152. package/native/dist/swap-shared.d.ts +8 -2
  153. package/native/dist/swap-shared.js +10 -6
  154. package/native/dist/swap-views.js +6 -4
  155. package/native/dist/switch-row.d.ts +3 -2
  156. package/native/dist/switch-row.js +5 -3
  157. package/native/dist/switch.d.ts +4 -2
  158. package/native/dist/switch.js +3 -3
  159. package/native/dist/target-block.d.ts +40 -7
  160. package/native/dist/target-block.js +31 -11
  161. package/native/dist/toast.d.ts +47 -0
  162. package/native/dist/toast.js +386 -0
  163. package/native/dist/token-action-block.d.ts +26 -9
  164. package/native/dist/token-action-block.js +21 -8
  165. package/native/dist/trade-history-detail-block.d.ts +26 -1
  166. package/native/dist/trade-history-detail-block.js +17 -9
  167. package/native/dist/trade-history-list-block.d.ts +71 -5
  168. package/native/dist/trade-history-list-block.js +55 -17
  169. package/native/dist/wallet-address-core.d.ts +25 -0
  170. package/native/dist/wallet-address-core.js +34 -0
  171. package/native/dist/wallet-address.d.ts +6 -10
  172. package/native/dist/wallet-address.js +16 -20
  173. package/native-fonts/README.md +1 -1
  174. package/og-fonts/README.md +1 -1
  175. package/package.json +131 -2
  176. package/react/README.md +3 -1
  177. package/react/dist/animated-number-flow.d.ts +72 -0
  178. package/react/dist/animated-number-flow.js +316 -0
  179. package/react/dist/animated-number-model.d.ts +24 -0
  180. package/react/dist/animated-number-model.js +106 -3
  181. package/react/dist/animated-number.d.ts +49 -1
  182. package/react/dist/animated-number.js +146 -11
  183. package/react/dist/asset-balance-row.d.ts +19 -1
  184. package/react/dist/asset-balance-row.js +17 -3
  185. package/react/dist/async-result.d.ts +2 -0
  186. package/react/dist/async-result.js +11 -0
  187. package/react/dist/avatar.d.ts +25 -0
  188. package/react/dist/avatar.js +50 -0
  189. package/react/dist/bar-mark.d.ts +5 -2
  190. package/react/dist/bar-mark.js +5 -3
  191. package/react/dist/blocks/account-block.d.ts +57 -7
  192. package/react/dist/blocks/account-block.js +51 -11
  193. package/react/dist/blocks/assets-block.d.ts +106 -0
  194. package/react/dist/blocks/assets-block.js +135 -0
  195. package/react/dist/blocks/confirm-block.d.ts +91 -0
  196. package/react/dist/blocks/confirm-block.js +31 -0
  197. package/react/dist/blocks/explainer-block.d.ts +80 -0
  198. package/react/dist/blocks/explainer-block.js +20 -0
  199. package/react/dist/blocks/install-command.js +3 -1
  200. package/react/dist/blocks/language-block.d.ts +9 -1
  201. package/react/dist/blocks/language-block.js +8 -6
  202. package/react/dist/blocks/manage-position-block.d.ts +30 -2
  203. package/react/dist/blocks/manage-position-block.js +23 -4
  204. package/react/dist/blocks/market-row.d.ts +20 -9
  205. package/react/dist/blocks/market-row.js +17 -4
  206. package/react/dist/blocks/notifications-block.d.ts +27 -2
  207. package/react/dist/blocks/notifications-block.js +11 -2
  208. package/react/dist/blocks/pickers.d.ts +30 -1
  209. package/react/dist/blocks/pickers.js +32 -10
  210. package/react/dist/blocks/position-block.d.ts +34 -11
  211. package/react/dist/blocks/position-block.js +16 -5
  212. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  213. package/react/dist/blocks/preset-picker-block.js +19 -0
  214. package/react/dist/blocks/profile-block.d.ts +33 -6
  215. package/react/dist/blocks/profile-block.js +31 -6
  216. package/react/dist/blocks/reward-block.d.ts +65 -21
  217. package/react/dist/blocks/reward-block.js +24 -11
  218. package/react/dist/blocks/screen-header.d.ts +34 -2
  219. package/react/dist/blocks/screen-header.js +17 -6
  220. package/react/dist/blocks/setting-switch.d.ts +14 -1
  221. package/react/dist/blocks/setting-switch.js +11 -4
  222. package/react/dist/blocks/signals-block.d.ts +23 -2
  223. package/react/dist/blocks/signals-block.js +6 -5
  224. package/react/dist/blocks/sound-haptics-block.d.ts +27 -3
  225. package/react/dist/blocks/sound-haptics-block.js +11 -7
  226. package/react/dist/blocks/sticky-header.d.ts +19 -0
  227. package/react/dist/blocks/sticky-header.js +103 -0
  228. package/react/dist/blocks/swap/amount-card.js +2 -1
  229. package/react/dist/blocks/swap/settings.js +4 -3
  230. package/react/dist/blocks/swap/shared.d.ts +29 -23
  231. package/react/dist/blocks/swap/shared.js +36 -32
  232. package/react/dist/blocks/swap-panel-block.d.ts +12 -3
  233. package/react/dist/blocks/swap-panel-block.js +72 -37
  234. package/react/dist/blocks/target-block.d.ts +35 -7
  235. package/react/dist/blocks/target-block.js +26 -12
  236. package/react/dist/blocks/token-action-block.d.ts +21 -8
  237. package/react/dist/blocks/token-action-block.js +9 -6
  238. package/react/dist/blocks/trade-history-detail-block.d.ts +23 -1
  239. package/react/dist/blocks/trade-history-detail-block.js +5 -4
  240. package/react/dist/blocks/trade-history-list-block.d.ts +31 -5
  241. package/react/dist/blocks/trade-history-list-block.js +20 -10
  242. package/react/dist/blocks.d.ts +12 -8
  243. package/react/dist/blocks.js +6 -2
  244. package/react/dist/brand.js +2 -1
  245. package/react/dist/button.d.ts +9 -3
  246. package/react/dist/button.js +12 -5
  247. package/react/dist/confetti.d.ts +27 -0
  248. package/react/dist/confetti.js +240 -0
  249. package/react/dist/data.js +11 -4
  250. package/react/dist/field.d.ts +20 -5
  251. package/react/dist/field.js +30 -8
  252. package/react/dist/figure.d.ts +23 -0
  253. package/react/dist/figure.js +12 -0
  254. package/react/dist/gesture-sheet.d.ts +15 -1
  255. package/react/dist/gesture-sheet.js +53 -8
  256. package/react/dist/list-group.d.ts +41 -8
  257. package/react/dist/list-group.js +49 -13
  258. package/react/dist/navigation.js +11 -3
  259. package/react/dist/overlay.d.ts +28 -3
  260. package/react/dist/overlay.js +29 -3
  261. package/react/dist/preset-group.d.ts +30 -0
  262. package/react/dist/preset-group.js +13 -0
  263. package/react/dist/provider.d.ts +42 -5
  264. package/react/dist/provider.js +84 -10
  265. package/react/dist/qr-code.d.ts +32 -0
  266. package/react/dist/qr-code.js +28 -0
  267. package/react/dist/select.js +10 -3
  268. package/react/dist/selection.d.ts +18 -4
  269. package/react/dist/selection.js +20 -10
  270. package/react/dist/slider.js +5 -1
  271. package/react/dist/status.d.ts +14 -10
  272. package/react/dist/status.js +17 -9
  273. package/react/dist/styles.css +380 -150
  274. package/react/dist/surface.d.ts +5 -1
  275. package/react/dist/surface.js +1 -1
  276. package/react/dist/toast.d.ts +19 -12
  277. package/react/dist/toast.js +29 -7
  278. package/react/dist/wallet-address-core.d.ts +27 -0
  279. package/react/dist/wallet-address-core.js +29 -0
  280. package/react/dist/wallet-address.d.ts +6 -12
  281. package/react/dist/wallet-address.js +5 -16
  282. package/tokens/README.md +2 -2
  283. package/tokens/dist/index.d.ts +16 -0
  284. package/tokens/dist/index.js +16 -0
  285. package/tokens/dist/manifest.json +8 -0
  286. package/tokens/dist/tokens.css +6 -0
@@ -1,28 +1,42 @@
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 } from './animated-number-model.js';
5
- import { useHIG } from './provider.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';
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
- export function AnimatedNumberReadout({ duration = 180, trend, ...props }) {
9
- const { locale, direction, reducedMotion, messages } = useHIG();
10
+ import { presentNumberFormat } from '@bloxwap/hig/contracts';
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 }) {
20
+ const locale = useNumberLocale();
21
+ const { direction, reducedMotion: reduced, messages, numberFormat } = useHIG(), reducedMotion = reduced || !animated;
22
+ const props = { ...rest, options: presentNumberFormat(requested, numberFormat) };
10
23
  const element = useRef(null);
11
24
  const previous = useRef(null);
12
25
  const generation = useRef(0);
13
26
  const active = useRef([]);
14
- const signature = JSON.stringify([locale, direction, props.options ?? {}]);
27
+ const known = props.value != null && Number.isFinite(props.value), own = known && !!formattedValue;
28
+ const signature = JSON.stringify([locale, direction, props.options ?? {}, own, own && animateFormatted]);
15
29
  const frame = useMemo(() => {
16
- const model = createAnimatedNumberModel(props.value, locale, props.options), prior = previous.current, changed = !!prior && prior.signature === signature && !Object.is(prior.value, props.value);
30
+ const model = own ? createFormattedAnimatedNumberModel(formattedValue, locale, animateFormatted) : createAnimatedNumberModel(props.value, locale, props.options), prior = previous.current, changed = !!prior && prior.signature === signature && !Object.is(prior.value, props.value);
17
31
  let movement = 0;
18
32
  if (changed && prior && model.animatable && prior.model.animatable && Number.isFinite(prior.value) && Number.isFinite(props.value)) {
19
33
  const requested = typeof trend === 'function' ? trend(prior.value, props.value) : trend ?? Math.sign(props.value - prior.value);
20
34
  movement = requested === -1 || requested === 1 ? requested : 0;
21
35
  }
22
36
  return { model, changed, movement, tokens: createAnimatedNumberTransitions(changed ? prior?.model ?? null : null, model) };
23
- }, [props.value, signature]);
37
+ }, [props.value, signature, formattedValue]);
24
38
  const [settled, setSettled] = useState(null);
25
- const known = props.value != null && Number.isFinite(props.value), reading = known ? `${props.prefix ?? ''}${frame.model.reading}${props.suffix ?? ''}` : frame.model.reading, staleText = messages.stale ?? en.stale, accessible = `${props.label ? `${props.label}: ` : ''}${reading}${props.stale ? ` ${staleText}` : ''}`;
39
+ const reading = known ? `${props.prefix ?? ''}${frame.model.reading}${props.suffix ?? ''}` : frame.model.reading, staleText = messages.stale ?? en.stale, accessible = `${props.label ? `${props.label}: ` : ''}${reading}${props.stale ? ` ${staleText}` : ''}`;
26
40
  useEffect(() => {
27
41
  const id = ++generation.current;
28
42
  const cancel = () => { const running = active.current; active.current = []; for (const animation of running) {
@@ -67,6 +81,127 @@ export function AnimatedNumberReadout({ duration = 180, trend, ...props }) {
67
81
  return () => { if (generation.current === id)
68
82
  cancel(); };
69
83
  }, [frame, reducedMotion, duration]);
70
- const tokens = settled === frame || reducedMotion ? createAnimatedNumberTransitions(null, frame.model) : frame.tokens;
71
- 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 });
72
207
  }
@@ -12,8 +12,26 @@ export interface AssetBalanceRowProps extends Omit<React.HTMLAttributes<HTMLElem
12
12
  balance?: number | null;
13
13
  /** Format of the units line. Defaults to at most six fraction digits. */
14
14
  balanceOptions?: Intl.NumberFormatOptions;
15
+ /** Host text after the units figure, such as ` HYPE`. Drawn only when the units are known. */
16
+ unitsSuffix?: string;
17
+ /** `units` puts the units on the headline line in place of the value and draws no second line, for a holding with no dollar value. Defaults to `value`. */
18
+ headline?: 'value' | 'units';
19
+ /** `false` draws no figures at all, for a row that is just an item to pick, such as a method or a chain. Defaults to `true`. */
20
+ amounts?: boolean;
21
+ /** Short muted host text under the figures, such as the ledger a holding sits in. Read after them. */
22
+ tag?: string;
23
+ /** Host content on the trailing edge, after the figures. Inside a pressable row it must not be interactive. It is read in place, last. */
24
+ trailing?: React.ReactNode;
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
+ 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;
29
+ /** Marks the row in use: a check on the trailing edge, and `aria-current` for assistive technology. */
30
+ selected?: boolean;
31
+ /** Dims the row and ignores presses. */
32
+ disabled?: boolean;
15
33
  /** Makes the whole row a button. */
16
34
  onSelect?: () => void;
17
35
  }
18
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. */
19
- export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, 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,10 +1,24 @@
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';
5
+ import { PressDecoration } from './provider.js';
4
6
  const usd = { style: 'currency', currency: 'USD' }, units = { maximumFractionDigits: 6 };
7
+ const check = _jsx(Check, { size: 20, className: 'hig-asset-row-check' });
5
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. */
6
- export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, onSelect, className, ...rest }) {
7
- 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 })] }), _jsxs("span", { className: 'hig-asset-row-amounts', children: [_jsx("strong", { children: _jsx(AnimatedNumberReadout, { value: value, options: usd }) }), balance !== undefined && _jsx("span", { children: _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions }) })] })] });
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;
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 }) })] });
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] });
8
15
  const classes = `hig-asset-row${className ? ` ${className}` : ''}`;
9
- return onSelect ? _jsx("button", { type: 'button', ...rest, className: classes, onClick: onSelect, children: content }) : _jsx("div", { ...rest, className: classes, children: content });
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] });
20
+ return onSelect
21
+ ? _jsxs("button", { type: 'button', ...rest, ...state, className: classes, disabled: disabled, onClick: onSelect, children: [content, _jsx(PressDecoration, { kind: 'row', disabled: disabled })] })
22
+ // A static row is a generic div, where aria-disabled is not read; disabled, it becomes a group, which carries the state.
23
+ : _jsx("div", { role: disabled ? 'group' : undefined, ...rest, ...state, "aria-disabled": disabled || undefined, className: classes, children: content });
10
24
  }
@@ -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 }); }
@@ -1,16 +1,19 @@
1
1
  import React from 'react';
2
+ import { type Figure } from './figure.js';
2
3
  /** Colour roles a segment can take. They follow the token palette (and a host's market colours) like any other role. */
3
4
  export type BarMarkTone = 'positive' | 'info' | 'warning' | 'negative' | 'muted' | 'faint';
4
5
  /** The order segments take tones in when they name neither a `tone` nor a `color`. */
5
6
  export declare const barMarkTones: readonly BarMarkTone[];
6
- /** One part of the bar. `value` is in the host's own unit; only its share of the whole is drawn. `detail` is host-formatted text shown after the label, such as `12.4 GB`. `color` is a host hex for a category outside the tone roles. */
7
+ /** A legend amount that can change while the bar is shown: formatted with `options` between `prefix` and `suffix`, and updated place by place. `null` reads as unknown. */
8
+ export type BarMarkFigure = Figure;
9
+ /** One part of the bar. `value` is in the host's own unit; only its share of the whole is drawn. `detail` is shown after the label: host-formatted text, such as `12.4 GB`, or a live figure. `color` is a host hex for a category outside the tone roles. */
7
10
  export interface BarMarkElement {
8
11
  id?: string;
9
12
  label: string;
10
13
  value: number;
11
14
  tone?: BarMarkTone;
12
15
  color?: string;
13
- detail?: string;
16
+ detail?: string | BarMarkFigure;
14
17
  }
15
18
  export interface BarMarkProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
16
19
  title: string;
@@ -2,7 +2,9 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useId } from 'react';
4
4
  import { formatNumber } from '@bloxwap/hig/contracts';
5
- import { useHIG } from './provider.js';
5
+ import { useNumberLocale } from './provider.js';
6
+ import { AnimatedNumberReadout } from './animated-number.js';
7
+ import { figureProps } from './figure.js';
6
8
  /** The order segments take tones in when they name neither a `tone` nor a `color`. */
7
9
  export const barMarkTones = ['positive', 'info', 'warning', 'negative', 'muted', 'faint'];
8
10
  const amount = (value) => Number.isFinite(value) && value > 0 ? value : 0;
@@ -13,9 +15,9 @@ export function barMarkShares(elements, total) {
13
15
  }
14
16
  /** A one-dimensional stacked bar: a titled card whose single bar is divided among its elements, with a legend naming each part. */
15
17
  export function BarMark({ title, description, elements, total, legend = true, size = 'default', surface = true, className, ...rest }) {
16
- const { locale } = useHIG();
18
+ const locale = useNumberLocale();
17
19
  const id = useId();
18
20
  const { shares, rest: remainder } = barMarkShares(elements, total);
19
21
  const paint = (element, index) => element.color ? { style: { '--hig-bar-mark-color': element.color } } : { 'data-tone': element.tone ?? barMarkTones[index % barMarkTones.length] };
20
- return _jsxs("section", { ...rest, className: `${surface ? 'hig-surface ' : ''}hig-bar-mark${className ? ` ${className}` : ''}`, "data-surface": surface ? undefined : 'false', "data-size": size === 'small' ? size : undefined, "aria-labelledby": id, children: [_jsxs("div", { className: 'hig-bar-mark-header', children: [_jsx("strong", { id: id, className: 'hig-bar-mark-title', children: title }), description != null && _jsx("span", { className: 'hig-bar-mark-description', children: description })] }), _jsxs("div", { className: 'hig-bar-mark-bar', "aria-hidden": 'true', children: [elements.map((element, index) => shares[index] > 0 && _jsx("span", { className: 'hig-bar-mark-segment', ...paint(element, index), style: { ...paint(element, index).style, flexGrow: shares[index] } }, element.id ?? index)), remainder > 0 && _jsx("span", { className: 'hig-bar-mark-rest', style: { flexGrow: remainder } })] }), _jsx("ul", { className: legend ? 'hig-bar-mark-legend' : 'hig-sr-only', children: elements.map((element, index) => _jsxs("li", { children: [_jsx("span", { className: 'hig-bar-mark-dot', "aria-hidden": 'true', ...paint(element, index) }), _jsx("span", { children: element.label }), element.detail && _jsx("span", { className: 'hig-bar-mark-detail', children: element.detail }), _jsx("span", { className: 'hig-sr-only', children: formatNumber(shares[index], locale, { style: 'percent', maximumFractionDigits: 1 }) })] }, element.id ?? index)) })] });
22
+ return _jsxs("section", { ...rest, className: `${surface ? 'hig-surface ' : ''}hig-bar-mark${className ? ` ${className}` : ''}`, "data-surface": surface ? undefined : 'false', "data-size": size === 'small' ? size : undefined, "aria-labelledby": id, children: [_jsxs("div", { className: 'hig-bar-mark-header', children: [_jsx("strong", { id: id, className: 'hig-bar-mark-title', children: title }), description != null && _jsx("span", { className: 'hig-bar-mark-description', children: description })] }), _jsxs("div", { className: 'hig-bar-mark-bar', "aria-hidden": 'true', children: [elements.map((element, index) => shares[index] > 0 && _jsx("span", { className: 'hig-bar-mark-segment', ...paint(element, index), style: { ...paint(element, index).style, flexGrow: shares[index] } }, element.id ?? index)), remainder > 0 && _jsx("span", { className: 'hig-bar-mark-rest', style: { flexGrow: remainder } })] }), _jsx("ul", { className: legend ? 'hig-bar-mark-legend' : 'hig-sr-only', children: elements.map((element, index) => _jsxs("li", { children: [_jsx("span", { className: 'hig-bar-mark-dot', "aria-hidden": 'true', ...paint(element, index) }), _jsx("span", { children: element.label }), element.detail && _jsx("span", { className: 'hig-bar-mark-detail', children: typeof element.detail === 'string' ? element.detail : _jsx(AnimatedNumberReadout, { ...figureProps(element.detail) }) }), _jsx("span", { className: 'hig-sr-only', children: formatNumber(shares[index], locale, { style: 'percent', maximumFractionDigits: 1 }) })] }, element.id ?? index)) })] });
21
23
  }
@@ -13,6 +13,38 @@ export interface AccountAsset {
13
13
  price?: number | null;
14
14
  /** Dollar value of the holding. Defaults to `balance × price`. */
15
15
  value?: number | null;
16
+ /** Set false to draw no units line, for a holding whose units are the same figure as its value. */
17
+ units?: boolean;
18
+ /** Set false to draw this row plain even when the block has `onAssetSelect`. */
19
+ selectable?: boolean;
20
+ /** Format of the units figure. Defaults to at most six fraction digits. */
21
+ unitsOptions?: Intl.NumberFormatOptions;
22
+ /** Host text after the units figure, such as ` PAPER`. */
23
+ unitsSuffix?: string;
24
+ /** Short muted host text under the figures, such as the ledger the holding sits in (Perp, Spot, Staked). */
25
+ tag?: string;
26
+ /** When the value is unknown but the balance is known: `units` (the default) headlines the units; `dash` shows the unknown dash over the units, for a value that is still loading. */
27
+ unknownValue?: 'units' | 'dash';
28
+ }
29
+ /** Row order after the pinned asset: `value` (largest first, the default) or `given` (the order the host passed). */
30
+ export type AccountOrder = 'value' | 'given';
31
+ /** How `accountRows` picks and orders: `order` after the pinned asset, and `pinnedId`, an asset id pinned in place of the symbol match. */
32
+ export interface AccountRowsOptions {
33
+ order?: AccountOrder;
34
+ pinnedId?: string;
35
+ }
36
+ /** A titled group of holdings with its own total, such as one ledger of the account. */
37
+ export interface AccountSection {
38
+ id: string;
39
+ /** Heading over the group. */
40
+ title: string;
41
+ /** The group's total in dollars, on the trailing edge of its heading. Defaults to the sum of its asset values; `null` reads as unknown. */
42
+ total?: number | null;
43
+ assets: readonly AccountAsset[];
44
+ /** Row order in this group; defaults to the block's `order`. */
45
+ order?: AccountOrder;
46
+ /** Id of the asset that leads this group; defaults to the block's `pinnedId`, then the `pinnedSymbol` match. */
47
+ pinnedId?: string;
16
48
  }
17
49
  export interface AccountBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
18
50
  /** Heading. Defaults to the built-in “Account”. */
@@ -23,24 +55,42 @@ export interface AccountBlockProps extends Omit<React.HTMLAttributes<HTMLElement
23
55
  onShowAddress?: () => void;
24
56
  /** A control on the trailing edge of the header, usually an `IconButton`. Replaces the QR button. */
25
57
  headerAction?: React.ReactNode;
26
- /** Total in dollars. Defaults to the sum of the asset values; `null` reads as unknown. */
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;
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. */
27
63
  balance?: number | null;
28
- assets: readonly AccountAsset[];
64
+ /** Every holding as one list: the pinned asset, then the rest by value. Ignored when `sections` is set. */
65
+ assets?: readonly AccountAsset[];
66
+ /** Titled groups, each with its own total, drawn in the order given in place of the flat `assets` list. */
67
+ sections?: readonly AccountSection[];
29
68
  /** Symbol of the asset that is always first. Defaults to `USDC`. */
30
69
  pinnedSymbol?: string;
70
+ /** Id of the asset that is always first, in place of the `pinnedSymbol` match, for a holding whose symbol is not unique. */
71
+ pinnedId?: string;
72
+ /** Order of the rows after the pinned one: `value` (largest first, the default) or `given` (the order passed). */
73
+ order?: AccountOrder;
31
74
  /** Shows the deposit action beside the total. */
32
75
  onDeposit?: () => void;
33
76
  /** Text of the deposit action. Defaults to the built-in “Deposit”. */
34
77
  depositLabel?: string;
35
- /** Makes each row a button that reports its asset. */
36
- onAssetSelect?: (asset: AccountAsset) => void;
78
+ /** Makes each row a button that reports its asset, and with `sections` the section it is in. */
79
+ onAssetSelect?: (asset: AccountAsset, section?: AccountSection) => void;
37
80
  }
38
81
  /** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
39
82
  export declare const assetValue: (asset: AccountAsset) => number | null;
40
- /** The account's rows in display order: the pinned asset (a zero placeholder when the account does not hold it), then every other asset by dollar value, largest first, unknown values last and ties by name. */
41
- export declare function accountRows(assets: readonly AccountAsset[], pinnedSymbol?: string): {
83
+ /** 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. */
84
+ export declare function accountRows(assets: readonly AccountAsset[], pinnedSymbol?: string, options?: AccountRowsOptions): {
42
85
  pinned: AccountAsset;
43
86
  rest: AccountAsset[];
44
87
  };
88
+ /** A section's total: its own `total`, or the sum of its asset values. */
89
+ export declare const accountSectionTotal: (section: AccountSection) => number | null;
90
+ /** 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`. */
91
+ export declare function accountSectionRows(assets: readonly AccountAsset[], pinnedSymbol?: string, options?: AccountRowsOptions): {
92
+ pinned: AccountAsset | null;
93
+ rest: AccountAsset[];
94
+ };
45
95
  /** An account at a glance: a header, the total with a deposit action, the pinned dollar balance, then every other holding by value. */
46
- export declare function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets, pinnedSymbol, 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;
@@ -1,7 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
3
4
  import * as en from '@bloxwap/hig/contracts/messages';
4
- import { useHIG } from '../provider.js';
5
+ import { PressDecoration, useHIG } from '../provider.js';
5
6
  import { Button } from '../button.js';
6
7
  import { AnimatedNumberReadout } from '../animated-number.js';
7
8
  import { AssetBalanceRow } from '../asset-balance-row.js';
@@ -9,19 +10,58 @@ import { ScreenHeader, qrIcon } from './screen-header.js';
9
10
  export { AssetBalanceRow } from '../asset-balance-row.js';
10
11
  const usdCoin = 'USD Coin', usd = { style: 'currency', currency: 'USD' };
11
12
  /** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
12
- export const assetValue = (asset) => asset.value !== undefined ? asset.value : asset.balance != null && asset.price != null ? asset.balance * asset.price : null;
13
- /** The account's rows in display order: the pinned asset (a zero placeholder when the account does not hold it), then every other asset by dollar value, largest first, unknown values last and ties by name. */
14
- export function accountRows(assets, pinnedSymbol = 'USDC') {
15
- const index = assets.findIndex(asset => asset.symbol.toUpperCase() === pinnedSymbol.toUpperCase());
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
+ /** 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
+ export function accountRows(assets, pinnedSymbol = 'USDC', options = {}) {
16
+ const byId = options.pinnedId === undefined ? -1 : assets.findIndex(asset => asset.id === options.pinnedId);
17
+ const index = byId >= 0 ? byId : assets.findIndex(asset => asset.symbol.toUpperCase() === pinnedSymbol.toUpperCase());
16
18
  const pinned = index >= 0 ? assets[index] : { id: pinnedSymbol, name: pinnedSymbol === 'USDC' ? usdCoin : pinnedSymbol, symbol: pinnedSymbol, balance: 0, value: 0 };
17
- const rest = assets.filter((_, position) => position !== index).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); });
19
+ const others = assets.filter((_, position) => position !== index);
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); });
18
21
  return { pinned, rest };
19
22
  }
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; };
29
+ /** A section's total: its own `total`, or the sum of its asset values. */
30
+ export const accountSectionTotal = (section) => section.total !== undefined ? (section.total != null && Number.isFinite(section.total) ? section.total : null) : sum(section.assets);
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. */
32
+ const accountSectionsTotal = (sections) => { let all = 0; for (const section of sections) {
33
+ const total = accountSectionTotal(section);
34
+ if (total === null)
35
+ return null;
36
+ all += total;
37
+ } return Number.isFinite(all) ? all : null; };
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`. */
39
+ export function accountSectionRows(assets, pinnedSymbol = 'USDC', options = {}) {
40
+ const { pinned, rest } = accountRows(assets, pinnedSymbol, options);
41
+ return { pinned: assets.includes(pinned) ? pinned : null, rest };
42
+ }
20
43
  /** An account at a glance: a header, the total with a deposit action, the pinned dollar balance, then every other holding by value. */
21
- export function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets, pinnedSymbol = 'USDC', 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 }) {
22
45
  const { messages } = useHIG();
23
- const { pinned, rest: others } = accountRows(assets, pinnedSymbol);
24
- const total = balance !== undefined ? balance : assets.reduce((sum, asset) => sum + (assetValue(asset) ?? 0), 0);
25
- const row = (asset, pin) => _jsx("li", { "data-pinned": pin || undefined, children: _jsx(AssetBalanceRow, { name: asset.name, symbol: asset.symbol, icon: asset.icon, value: assetValue(asset), balance: pin ? undefined : asset.balance ?? null, onSelect: onAssetSelect && (() => onAssetSelect(asset)) }) }, asset.id);
26
- return _jsxs("section", { ...rest, className: `hig-account-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title ?? messages.account ?? en.account, onBack: onBack, action: headerAction ?? (onShowAddress && _jsx("button", { type: 'button', className: 'hig-swap-back hig-account-address', "aria-label": messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: qrIcon })) }), _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 })] }), _jsxs("ul", { className: 'hig-account-assets', children: [row(pinned, true), others.map(asset => row(asset, false))] })] });
46
+ const id = useId();
47
+ const shown = sections?.filter(section => section.assets.length > 0);
48
+ const total = balance !== undefined ? balance : shown ? accountSectionsTotal(shown) : sum(assets);
49
+ const row = (asset, pin, pinId, section) => {
50
+ // A row pinned by symbol is the dollar balance, so its units would repeat its value; a row pinned by id keeps its own units setting.
51
+ const value = assetValue(asset), units = (!pin || asset.id === pinId) && asset.units !== false;
52
+ const select = onAssetSelect && asset.selectable !== false ? (section ? () => onAssetSelect(asset, section) : () => onAssetSelect(asset)) : undefined;
53
+ return _jsx("li", { "data-pinned": pin || undefined, children: _jsx(AssetBalanceRow, { name: asset.name, symbol: asset.symbol, icon: asset.icon, value: value, balance: units ? asset.balance ?? null : undefined, balanceOptions: asset.unitsOptions, unitsSuffix: asset.unitsSuffix, tag: asset.tag, headline: units && value === null && asset.balance != null && asset.unknownValue !== 'dash' ? 'units' : undefined, onSelect: select }) }, asset.id);
54
+ };
55
+ let list;
56
+ if (shown)
57
+ list = _jsx("div", { className: 'hig-account-sections', children: shown.map((section, index) => {
58
+ const pinId = section.pinnedId ?? pinnedId;
59
+ const { pinned, rest: others } = accountSectionRows(section.assets, pinnedSymbol, { order: section.order ?? order, pinnedId: pinId }), heading = `${id}-section-${index}`;
60
+ return _jsxs("section", { className: 'hig-account-section', "aria-labelledby": heading, children: [_jsxs("div", { className: 'hig-account-section-header', children: [_jsx("h3", { id: heading, children: section.title }), _jsx("span", { className: 'hig-account-section-total', children: _jsx(AnimatedNumberReadout, { value: accountSectionTotal(section), options: usd }) })] }), _jsxs("ul", { className: 'hig-account-assets', children: [pinned && row(pinned, true, pinId, section), others.map(asset => row(asset, false, pinId, section))] })] }, section.id);
61
+ }) });
62
+ else {
63
+ const { pinned, rest: others } = accountRows(assets, pinnedSymbol, { order, pinnedId });
64
+ list = _jsxs("ul", { className: 'hig-account-assets', children: [row(pinned, true, pinnedId), others.map(asset => row(asset, false, pinnedId))] });
65
+ }
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] });
27
67
  }