@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
@@ -0,0 +1,88 @@
1
+ import { tokens } from '@bloxwap/hig/tokens';
2
+ import { ALTIMETER_TICK_PX, easeInOut } from './altimeter-model.js';
3
+ import { capsuleCenters } from './outcome-model.js';
4
+ /** Keep the first valid target for each ID. Invalid prices must never enter chart geometry. */
5
+ export function validTargets(targets) {
6
+ const ids = new Set();
7
+ return targets.filter(target => {
8
+ if (!target.id || ids.has(target.id) || !Number.isFinite(target.price) || target.price <= 0)
9
+ return false;
10
+ ids.add(target.id);
11
+ return true;
12
+ });
13
+ }
14
+ const LABEL_HEIGHT = 18, LABEL_GAP = 6, EDGE_INSET = 8;
15
+ const sideOffset = (price, display) => price > display ? LABEL_GAP + 2 : -LABEL_HEIGHT - LABEL_GAP + 2;
16
+ /** Labels stay inside the chart and share the chart capsule layout's collision avoidance. */
17
+ export function placeTargets(targets, display, spacing, height, sideOffsets) {
18
+ const positions = new Map();
19
+ if (!Number.isFinite(display) || display <= 0 || !Number.isFinite(spacing) || spacing <= 0 || !Number.isFinite(height) || height <= 0)
20
+ return positions;
21
+ for (const target of targets) {
22
+ const y = height / 2 - ((target.price - display) / spacing) * ALTIMETER_TICK_PX;
23
+ positions.set(target.id, { y, anchor: Math.max(0, Math.min(height, y)), pinned: y < 0 ? 'top' : y > height ? 'bottom' : null });
24
+ }
25
+ // Price order also breaks ties for targets pinned at the same edge, independently of array order.
26
+ const labelled = targets.filter(target => target.label).sort((a, b) => b.price - a.price);
27
+ const wanted = labelled.map(target => {
28
+ const { y } = positions.get(target.id);
29
+ const top = y + (sideOffsets?.get(target.id) ?? sideOffset(target.price, display));
30
+ return top + LABEL_HEIGHT / 2 - EDGE_INSET;
31
+ });
32
+ const centers = capsuleCenters(wanted, Math.max(LABEL_HEIGHT, height - EDGE_INSET * 2), LABEL_HEIGHT, LABEL_GAP, true);
33
+ for (const [index, target] of labelled.entries())
34
+ positions.get(target.id).labelTop = centers[index] - LABEL_HEIGHT / 2 + EDGE_INSET;
35
+ return positions;
36
+ }
37
+ /** Follow the line exactly; animate only its above/below offset, then resolve collisions and edge pinning. */
38
+ export function targetLayout() {
39
+ const sides = new Map();
40
+ return {
41
+ reset() { sides.clear(); },
42
+ update(targets, display, spacing, height, now, snap = false) {
43
+ const offsets = new Map();
44
+ for (const target of targets) {
45
+ if (!target.label)
46
+ continue;
47
+ const to = sideOffset(target.price, display);
48
+ let side = sides.get(target.id);
49
+ if (!side || snap) {
50
+ side = { from: to, to, start: now };
51
+ sides.set(target.id, side);
52
+ }
53
+ const value = side.from + (side.to - side.from) * easeInOut((now - side.start) / tokens.motion.base);
54
+ if (side.to !== to) {
55
+ side.from = value;
56
+ side.to = to;
57
+ side.start = now;
58
+ }
59
+ offsets.set(target.id, value);
60
+ }
61
+ for (const id of sides.keys())
62
+ if (!offsets.has(id))
63
+ sides.delete(id);
64
+ const positions = placeTargets(targets, display, spacing, height, offsets);
65
+ if (!positions.size)
66
+ sides.clear();
67
+ return positions;
68
+ },
69
+ };
70
+ }
71
+ /** Tracks displayed prices, so the effect coincides with the line reaching the live pill. */
72
+ export function targetCrossings() {
73
+ let previous = NaN;
74
+ const levels = new Map();
75
+ return {
76
+ reset() { previous = NaN; levels.clear(); },
77
+ update(price, targets) {
78
+ const crossed = targets.filter(target => levels.get(target.id) === target.price && ((previous < target.price && price >= target.price) || (previous > target.price && price <= target.price)));
79
+ // Coalesced effects use the last level encountered along the direction of travel.
80
+ crossed.sort((a, b) => price > previous ? a.price - b.price : b.price - a.price);
81
+ previous = price;
82
+ levels.clear();
83
+ for (const target of targets)
84
+ levels.set(target.id, target.price);
85
+ return crossed;
86
+ },
87
+ };
88
+ }
@@ -0,0 +1,8 @@
1
+ /** A live price source: call `onPrice` with each new price, and return a function that stops it. */
2
+ export type AltimeterFeed = (onPrice: (price: number) => void, onStale?: () => void) => () => void;
3
+ /**
4
+ * AltimeterChart's default feed: the Bitcoin mid price from Hyperliquid's public best-bid/offer stream, a market
5
+ * that is always moving. It needs no key and sends nothing but the subscription. Products pass their own `price`
6
+ * or `feed`.
7
+ */
8
+ export declare const bitcoinPrice: AltimeterFeed;
@@ -0,0 +1,41 @@
1
+ const HYPERLIQUID_WS = 'wss://api.hyperliquid.xyz/ws';
2
+ /**
3
+ * AltimeterChart's default feed: the Bitcoin mid price from Hyperliquid's public best-bid/offer stream, a market
4
+ * that is always moving. It needs no key and sends nothing but the subscription. Products pass their own `price`
5
+ * or `feed`.
6
+ */
7
+ export const bitcoinPrice = (onPrice, onStale) => {
8
+ if (typeof WebSocket === 'undefined')
9
+ return () => { };
10
+ let socket, retry, stopped = false, attempts = 0;
11
+ let deadline;
12
+ const open = () => {
13
+ if (stopped)
14
+ return;
15
+ const current = socket = new WebSocket(HYPERLIQUID_WS);
16
+ const arm = () => { clearTimeout(deadline); deadline = setTimeout(() => { if (!stopped && socket === current)
17
+ current.close(); }, 30_000); };
18
+ arm();
19
+ current.onopen = () => current.send(JSON.stringify({ method: 'subscribe', subscription: { type: 'bbo', coin: 'BTC' } }));
20
+ current.onmessage = event => {
21
+ if (stopped || socket !== current)
22
+ return;
23
+ try {
24
+ const message = JSON.parse(String(event.data));
25
+ if (message?.channel !== 'bbo')
26
+ return;
27
+ const sides = (message.data?.bbo ?? []).map((level) => Number(level?.px)).filter((px) => Number.isFinite(px) && px > 0);
28
+ if (sides.length === 0)
29
+ return;
30
+ attempts = 0;
31
+ arm();
32
+ onPrice(sides.reduce((sum, px) => sum + px, 0) / sides.length);
33
+ }
34
+ catch { /* A malformed frame is skipped; the next one carries the price. */ }
35
+ };
36
+ current.onclose = () => { if (stopped || socket !== current)
37
+ return; clearTimeout(deadline); onStale?.(); retry = setTimeout(open, Math.min(30_000, 1000 * 2 ** attempts++)); };
38
+ };
39
+ open();
40
+ return () => { stopped = true; clearTimeout(retry); clearTimeout(deadline); socket?.close(); };
41
+ };
@@ -0,0 +1,19 @@
1
+ import type { OutcomeFeed } from './outcome-model.js';
2
+ interface Question {
3
+ question: number;
4
+ name: string;
5
+ description: string;
6
+ namedOutcomes: number[];
7
+ }
8
+ /** The open UEFA Champions League winner market with the earliest resolution date. */
9
+ export declare function nextChampionsLeagueQuestion(questions: readonly Question[]): Question | undefined;
10
+ /** What is left for every unlisted club once each listed club has a price: one minus their sum, never below zero. */
11
+ export declare function remainder(prices: readonly (number | null)[]): number | null;
12
+ /**
13
+ * OutcomeChart's default feed: the winner of the UEFA Champions League on Hyperliquid's outcome markets, the
14
+ * venue's most traded market. Each listed club is priced at the live midpoint of its order book; `Other` is what
15
+ * remains. It finds the market by name, so once a season settles it moves to the next one by itself. It needs no
16
+ * key. Products pass their own `outcomes` or `feed`.
17
+ */
18
+ export declare const championsLeagueWinner: OutcomeFeed;
19
+ export {};
@@ -0,0 +1,104 @@
1
+ const INFO = 'https://api.hyperliquid.xyz/info', STREAM = 'wss://api.hyperliquid.xyz/ws';
2
+ /** How often the feed checks for the next season's market. */
3
+ const REFRESH_MS = 15 * 60_000;
4
+ /** The feed reports live prices at most this often. */
5
+ const REPORT_MS = 500;
6
+ // Club names on the venue, mapped to the reference codes; `other` is every club the venue does not list.
7
+ const names = { Barcelona: 'BAR', 'Paris Saint-Germain': 'PSG', 'Real Madrid': 'RMA', 'Bayern Munich': 'BAY', Arsenal: 'ARS', 'Manchester City': 'MCI', other: 'Other' };
8
+ const OTHER = 'other';
9
+ const field = (description, key) => description.split('|').find(part => part.startsWith(`${key}:`))?.slice(key.length + 1) ?? '';
10
+ /** The open UEFA Champions League winner market with the earliest resolution date. */
11
+ export function nextChampionsLeagueQuestion(questions) {
12
+ return questions.filter(q => q.name === 'template:sportsTournamentWinner' && field(q.description, 'competition') === 'UEFA Champions League' && q.namedOutcomes?.length)
13
+ .sort((a, b) => field(a.description, 'resolutionDeadline').localeCompare(field(b.description, 'resolutionDeadline')))[0];
14
+ }
15
+ /** What is left for every unlisted club once each listed club has a price: one minus their sum, never below zero. */
16
+ export function remainder(prices) {
17
+ return prices.every(price => price != null) ? Math.max(0, 1 - prices.reduce((sum, price) => sum + (price ?? 0), 0)) : null;
18
+ }
19
+ /**
20
+ * OutcomeChart's default feed: the winner of the UEFA Champions League on Hyperliquid's outcome markets, the
21
+ * venue's most traded market. Each listed club is priced at the live midpoint of its order book; `Other` is what
22
+ * remains. It finds the market by name, so once a season settles it moves to the next one by itself. It needs no
23
+ * key. Products pass their own `outcomes` or `feed`.
24
+ */
25
+ export const championsLeagueWinner = (onOutcomes, onStale) => {
26
+ if (typeof fetch === 'undefined' || typeof WebSocket === 'undefined')
27
+ return () => { };
28
+ let stopped = false, socket, timer, reported = 0, pending, current = -1, outcomes = [], failures = 0;
29
+ const abort = new AbortController();
30
+ const info = (body) => fetch(INFO, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body), signal: abort.signal }).then(response => { if (!response.ok)
31
+ throw new Error(String(response.status)); return response.json(); });
32
+ const snapshot = () => { const listed = outcomes.filter(outcome => outcome.id !== OTHER); return outcomes.map(outcome => outcome.id === OTHER ? { ...outcome, price: remainder(listed.map(o => o.price)) } : { ...outcome }); };
33
+ const report = () => {
34
+ if (stopped || pending)
35
+ return;
36
+ pending = setTimeout(() => { pending = undefined; reported = Date.now(); if (!stopped)
37
+ onOutcomes(snapshot()); }, Math.max(0, reported + REPORT_MS - Date.now()));
38
+ };
39
+ let deadline, reconnect;
40
+ const listen = () => {
41
+ if (stopped)
42
+ return;
43
+ socket?.close();
44
+ const live = socket = new WebSocket(STREAM);
45
+ const arm = () => { clearTimeout(deadline); deadline = setTimeout(() => { if (!stopped && socket === live)
46
+ live.close(); }, 30_000); };
47
+ arm();
48
+ live.onopen = () => { for (const outcome of outcomes)
49
+ if (outcome.id !== OTHER)
50
+ live.send(JSON.stringify({ method: 'subscribe', subscription: { type: 'l2Book', coin: outcome.id } })); };
51
+ live.onmessage = event => {
52
+ if (stopped || socket !== live)
53
+ return;
54
+ try {
55
+ const message = JSON.parse(String(event.data));
56
+ // The order book sends a snapshot on subscribing and again as it changes; best-quote streams stay silent on a quiet market.
57
+ if (message?.channel !== 'l2Book')
58
+ return;
59
+ const [bid, ask] = (message.data?.levels ?? []).map((side) => Number(side?.[0]?.px)), outcome = outcomes.find(o => o.id === message.data?.coin);
60
+ // A one-sided book says little about the price; keep the last one.
61
+ if (!outcome || !(bid > 0) || !(ask > 0))
62
+ return;
63
+ outcome.price = (bid + ask) / 2;
64
+ arm();
65
+ report();
66
+ }
67
+ catch { /* A malformed frame is skipped. */ }
68
+ };
69
+ live.onclose = () => { if (stopped || socket !== live)
70
+ return; clearTimeout(deadline); onStale?.(); reconnect = setTimeout(() => { if (!stopped && socket === live)
71
+ listen(); }, 5000); };
72
+ };
73
+ const refresh = async () => {
74
+ try {
75
+ const meta = await info({ type: 'outcomeMeta' }), question = nextChampionsLeagueQuestion(meta.questions ?? []);
76
+ if (stopped)
77
+ return;
78
+ if (question && question.question !== current) {
79
+ // Starting prices put the favorite first; the order then stays fixed so capsules keep their colors.
80
+ const mids = await info({ type: 'allMids' });
81
+ if (stopped)
82
+ return;
83
+ const listed = question.namedOutcomes.map(id => {
84
+ const coin = `#${id * 10}`, club = field((meta.outcomes ?? []).find(o => o.outcome === id)?.description ?? '', 'participant') || coin, price = Number(mids[coin]);
85
+ return { id: coin, label: names[club] ?? club, price: price > 0 ? price : null };
86
+ }).sort((a, b) => (b.price ?? 0) - (a.price ?? 0));
87
+ current = question.question;
88
+ outcomes = [...listed, { id: OTHER, label: names.other, price: null }];
89
+ report();
90
+ listen();
91
+ }
92
+ failures = 0;
93
+ }
94
+ catch {
95
+ if (!stopped)
96
+ onStale?.();
97
+ failures++; /* Offline or rate limited: try again below. */
98
+ }
99
+ if (!stopped)
100
+ timer = setTimeout(refresh, failures ? Math.min(REFRESH_MS, 2000 * 2 ** failures) : REFRESH_MS);
101
+ };
102
+ refresh();
103
+ return () => { stopped = true; abort.abort(); clearTimeout(timer); clearTimeout(pending); clearTimeout(deadline); clearTimeout(reconnect); socket?.close(); };
104
+ };
@@ -6,3 +6,9 @@ export declare const chartTheme: DeepPartial<ChartConfig>;
6
6
  export declare function PriceChart({ summary, ...props }: ChartProps & {
7
7
  summary: string;
8
8
  }): React.JSX.Element;
9
+ export { AltimeterChart, type AltimeterChartProps } from './altimeter-chart.js';
10
+ export type { AltimeterTarget } from './altimeter-targets.js';
11
+ export { bitcoinPrice, type AltimeterFeed } from './bitcoin-price.js';
12
+ export { OutcomeChart, type OutcomeChartProps } from './outcome-chart.js';
13
+ export { outcomeColors, type Outcome, type OutcomeFeed } from './outcome-model.js';
14
+ export { championsLeagueWinner } from './champions-league.js';
@@ -10,3 +10,8 @@ const Chart = lazy(() => import('@bloxwap/chart/react').then(m => ({ default: m.
10
10
  export const chartTheme = { theme: { background: tokens.colors.surface.srgb, textColor: tokens.colors.text.srgb, borderColor: tokens.colors.border.srgb, fontFamily: 'Bloxwap Sans, system-ui, sans-serif', monoFamily: 'Bloxwap Mono, monospace' }, grid: { color: tokens.colors.border.srgb }, crosshair: { color: tokens.colors.muted.srgb, labelBackground: tokens.colors.action.srgb, labelColor: tokens.colors.onAction.srgb }, series: { upColor: tokens.colors.buy.srgb, downColor: tokens.colors.sell.srgb } };
11
11
  /** Web canvas only. Native uses labeled price rows; no embedded engine or WebView claim. */
12
12
  export function PriceChart({ summary, ...props }) { const { messages } = useHIG(); const colors = useColors(); const theme = useMemo(() => ({ ...chartTheme, crosshair: { ...chartTheme.crosshair, labelBackground: colors.action, labelColor: colors.onAction } }), [colors]); return _jsxs("figure", { children: [_jsx("figcaption", { children: summary }), _jsx(Suspense, { fallback: _jsx("p", { role: 'status', children: messages.loadingChart ?? en.loadingChart }), children: _jsx(Chart, { ...props, preset: theme }) })] }); }
13
+ export { AltimeterChart } from './altimeter-chart.js';
14
+ export { bitcoinPrice } from './bitcoin-price.js';
15
+ export { OutcomeChart } from './outcome-chart.js';
16
+ export { outcomeColors } from './outcome-model.js';
17
+ export { championsLeagueWinner } from './champions-league.js';
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { type AltimeterTick } from './altimeter-model.js';
3
+ import { type Outcome, type OutcomeFeed, type OutcomeScale } from './outcome-model.js';
4
+ export interface OutcomeChartProps extends Omit<React.HTMLAttributes<HTMLElement>, 'children'> {
5
+ /** Text alternative shown as the figure's caption, for example the question and where its prices come from. */
6
+ summary: string;
7
+ /** Two to ten outcomes, owned by the host. `null` or empty reads as waiting. Omit it to use `feed`. */
8
+ outcomes?: readonly Outcome[] | null;
9
+ /** Live source of outcomes, used only while `outcomes` is omitted. Defaults to `championsLeagueWinner`. Keep its identity stable. */
10
+ feed?: OutcomeFeed;
11
+ /** Chart height in pixels. Default 360. */
12
+ height?: number;
13
+ }
14
+ export interface OutcomeTrail {
15
+ color: string;
16
+ ticks: readonly AltimeterTick[];
17
+ /** Eased chance at the trail's tip, 0 to 1. */
18
+ value: number;
19
+ /** Vertical center of the capsule the trail ends in. */
20
+ capsule: number;
21
+ }
22
+ /** Paints one frame: the grid, then each trail from the leading edge to its capsule. */
23
+ export declare function drawOutcomes(ctx: CanvasRenderingContext2D, frame: {
24
+ width: number;
25
+ height: number;
26
+ now: number;
27
+ phase: number;
28
+ grid: string;
29
+ scale?: OutcomeScale;
30
+ trails: readonly OutcomeTrail[];
31
+ }): void;
32
+ /**
33
+ * The chances of the outcomes of one question, live: AltimeterChart's grid and trails, flowing left at 50px per
34
+ * second, on a ladder zoomed to the range the chances occupy. Each outcome's trail ends in a stroked capsule
35
+ * with its label and its chance. It draws no positions or controls. Web canvas only.
36
+ */
37
+ export declare function OutcomeChart({ summary, outcomes, feed, height, style, ...props }: OutcomeChartProps): React.JSX.Element;
@@ -0,0 +1,212 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
4
+ import { tokens } from '@bloxwap/hig/tokens';
5
+ import * as en from '@bloxwap/hig/contracts/messages';
6
+ import { useHIG, useColors } from '@bloxwap/hig/react/provider';
7
+ import { AnimatedNumberReadout } from '@bloxwap/hig/react/animated-number';
8
+ import { ALTIMETER_EASE_MS, ALTIMETER_FLOW_PX, ALTIMETER_SAMPLE_MS, easeInOut, gridPhase, smoothTrail, trailPoints } from './altimeter-model.js';
9
+ import { OUTCOME_LIMIT, capsuleCenters, outcomeChance, outcomeColors, outcomeScale, outcomeTicks, outcomeY } from './outcome-model.js';
10
+ import { championsLeagueWinner } from './champions-league.js';
11
+ import { drawPlusGrid, monoFont } from './plus-grid.js';
12
+ /** How long a capsule takes to glide from the waiting stack to its place once its first price arrives. */
13
+ const ARRIVE_MS = 600;
14
+ /** Width of the curve that carries a trail into its capsule. */
15
+ const CONNECTOR = 40;
16
+ /** Room above 100% and below 0%, so the end ticks and a capsule at either end fit. */
17
+ const INSET = 24;
18
+ /** Capsule height. Shorter than AltimeterChart's 36px pill: mixed-case labels sit lower than a row of digits, so the same height reads as too tall. */
19
+ const CAPSULE = 30;
20
+ /** Width of the ladder on the trailing edge: its labels, then an 8px tick mark 10px from the edge, as AltimeterChart. */
21
+ const LADDER = 76;
22
+ /** Gap between the capsules and the trailing edge. They sit over the ladder's labels, as AltimeterChart's pill does. */
23
+ const EDGE = 8;
24
+ /** Inset of the leading tick marks, where the trails start, as AltimeterChart. */
25
+ const PAD = 18;
26
+ /** Capsule column width for a chart `width` wide; the CSS below states the same rule. */
27
+ const capsuleWidth = (width) => Math.min(width * .55, 200);
28
+ /** Capsules read to three decimals, the precision outcome prices move in; the ladder stays in whole percents. */
29
+ const CHANCE = { style: 'percent', minimumFractionDigits: 3, maximumFractionDigits: 3 };
30
+ const transparent = (color) => /^#[0-9a-f]{6}$/i.test(color) ? `${color}00` : 'transparent';
31
+ /** Paints one frame: the grid, then each trail from the leading edge to its capsule. */
32
+ export function drawOutcomes(ctx, frame) {
33
+ const { width, height } = frame, trailEnd = Math.max(PAD + 40, width - EDGE - capsuleWidth(width) - CONNECTOR), yFor = (chance) => outcomeY(chance, height, INSET, frame.scale);
34
+ ctx.clearRect(0, 0, width, height);
35
+ ctx.lineJoin = 'round';
36
+ // One row of marks per ladder tick, so each row is a ten percent line.
37
+ drawPlusGrid(ctx, width, height, frame.phase, frame.grid, outcomeTicks(frame.scale).map(yFor));
38
+ ctx.lineWidth = 2.5;
39
+ for (const trail of frame.trails) {
40
+ const points = trailPoints(trail.ticks, frame.now, PAD, trailEnd, yFor), last = points.at(-1), tip = yFor(trail.value);
41
+ if (!last)
42
+ continue;
43
+ const fade = ctx.createLinearGradient(PAD, 0, trailEnd, 0);
44
+ fade.addColorStop(0, transparent(trail.color));
45
+ fade.addColorStop(1, trail.color);
46
+ ctx.strokeStyle = fade;
47
+ ctx.beginPath();
48
+ smoothTrail(points, ctx);
49
+ const dx = trailEnd - last[0];
50
+ if (dx > 0)
51
+ ctx.bezierCurveTo(last[0] + dx / 3, last[1], trailEnd - dx / 3, tip, trailEnd, tip);
52
+ else
53
+ ctx.lineTo(trailEnd, tip);
54
+ // From the live chance to the capsule, which may sit off the line to clear its neighbors.
55
+ ctx.bezierCurveTo(trailEnd + CONNECTOR / 2, tip, trailEnd + CONNECTOR / 2, trail.capsule, trailEnd + CONNECTOR, trail.capsule);
56
+ ctx.stroke();
57
+ }
58
+ }
59
+ /**
60
+ * The chances of the outcomes of one question, live: AltimeterChart's grid and trails, flowing left at 50px per
61
+ * second, on a ladder zoomed to the range the chances occupy. Each outcome's trail ends in a stroked capsule
62
+ * with its label and its chance. It draws no positions or controls. Web canvas only.
63
+ */
64
+ export function OutcomeChart({ summary, outcomes, feed = championsLeagueWinner, height = 360, style, ...props }) {
65
+ const { locale, messages, reducedMotion } = useHIG();
66
+ const colors = useColors();
67
+ const box = useRef(null), canvas = useRef(null), list = useRef(null);
68
+ const [stale, setStale] = useState(false);
69
+ const controlled = outcomes !== undefined;
70
+ const [fed, setFed] = useState(null);
71
+ useEffect(() => {
72
+ if (controlled) {
73
+ setStale(false);
74
+ return;
75
+ }
76
+ let alive = true;
77
+ let deadline;
78
+ setFed(null);
79
+ setStale(false);
80
+ const expire = () => { if (alive) {
81
+ setFed(null);
82
+ setStale(true);
83
+ } };
84
+ deadline = setTimeout(expire, 30_000);
85
+ const stop = feed(next => { if (!alive)
86
+ return; setFed(next); setStale(false); clearTimeout(deadline); deadline = setTimeout(expire, 30_000); }, expire);
87
+ return () => { alive = false; clearTimeout(deadline); stop(); };
88
+ }, [controlled, feed]);
89
+ const shown = useMemo(() => ((controlled ? outcomes : fed) ?? []).filter((item, index, all) => item.id !== '' && all.findIndex(candidate => candidate.id === item.id) === index).slice(0, OUTCOME_LIMIT), [controlled, outcomes, fed]);
90
+ const paint = (outcome, index) => outcome.color ?? outcomeColors[index % outcomeColors.length];
91
+ const percent = useMemo(() => new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 0 }), [locale]);
92
+ // Where each capsule rests: at its outcome's chance, moved apart from close neighbors.
93
+ // The ladder zooms to the range the chances occupy, and holds still until one leaves it.
94
+ const held = useRef(null), chances = shown.map(outcome => outcomeChance(outcome.price));
95
+ const scale = outcomeScale(chances, held.current ?? undefined);
96
+ // Only a ladder fitted to real chances is worth holding; the whole ladder shown while waiting is not.
97
+ held.current = chances.some(chance => chance != null) ? scale : null;
98
+ const ticks = outcomeTicks(scale);
99
+ const rest = capsuleCenters(shown.map(outcome => outcomeY(outcomeChance(outcome.price) ?? scale.low, height, INSET, scale)), height, CAPSULE);
100
+ // The frame loop reads the newest props without restarting, so a re-render never clears the trails.
101
+ const settings = useRef({ shown, rest, scale, colors, reducedMotion });
102
+ const eased = useRef(new Map());
103
+ // Capsules render at rest; while a chance eases, an offset carries each one along its trail's tip.
104
+ // Outcomes wait for their first price stacked at the bottom; when it arrives, the capsule glides from the stack to its place.
105
+ const arrival = useRef({ clock: NaN, priced: new Map(), at: new Map(), moving: new Map() });
106
+ const place = useRef((_now) => []);
107
+ place.current = frameTime => {
108
+ const { shown, rest, scale, reducedMotion } = settings.current, state = arrival.current;
109
+ if (frameTime !== undefined)
110
+ state.clock = frameTime;
111
+ const now = state.clock, tips = shown.map(outcome => { const value = eased.current.get(outcome.id)?.value; return outcomeY(value != null && Number.isFinite(value) ? value : outcomeChance(outcome.price) ?? scale.low, height, INSET, scale); });
112
+ const centers = capsuleCenters(tips, height, CAPSULE), items = list.current?.children;
113
+ for (const id of state.priced.keys())
114
+ if (!shown.some(outcome => outcome.id === id)) {
115
+ state.priced.delete(id);
116
+ state.at.delete(id);
117
+ state.moving.delete(id);
118
+ }
119
+ for (const [index, outcome] of shown.entries()) {
120
+ const priced = outcomeChance(outcome.price) != null, from = state.at.get(outcome.id);
121
+ if (priced && state.priced.get(outcome.id) === false && from !== undefined && !reducedMotion && Number.isFinite(now))
122
+ state.moving.set(outcome.id, { from, start: now });
123
+ state.priced.set(outcome.id, priced);
124
+ const move = state.moving.get(outcome.id);
125
+ if (move) {
126
+ const progress = (now - move.start) / ARRIVE_MS;
127
+ if (progress >= 1 || reducedMotion)
128
+ state.moving.delete(outcome.id);
129
+ else
130
+ centers[index] = move.from + (centers[index] - move.from) * easeInOut(progress);
131
+ }
132
+ state.at.set(outcome.id, centers[index]);
133
+ const item = items?.[index];
134
+ if (item)
135
+ item.style.transform = `translateY(${+(centers[index] - rest[index]).toFixed(2)}px)`;
136
+ }
137
+ return centers;
138
+ };
139
+ useLayoutEffect(() => { settings.current = { shown, rest, scale, colors, reducedMotion }; place.current(); });
140
+ useEffect(() => {
141
+ const surface = canvas.current, container = box.current;
142
+ if (!surface || !container)
143
+ return;
144
+ let context = null;
145
+ try {
146
+ context = surface.getContext('2d');
147
+ }
148
+ catch { /* No canvas: the caption, ladder and capsules remain. */ }
149
+ let width = container.clientWidth, raf = 0, sampled = -Infinity;
150
+ const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(entries => { width = entries[0].contentRect.width; });
151
+ observer?.observe(container);
152
+ const tracks = eased.current;
153
+ const step = (now) => {
154
+ raf = requestAnimationFrame(step);
155
+ const { shown, scale, colors, reducedMotion } = settings.current, sample = now - sampled >= ALTIMETER_SAMPLE_MS, keep = (Math.max(width, 0) / ALTIMETER_FLOW_PX) * 1000 + 2000;
156
+ // After a pause (a hidden tab stops the frames) the trails start flat again, so no line bridges the gap.
157
+ if (sample && now - sampled > 2000)
158
+ for (const track of tracks.values())
159
+ track.ticks = [];
160
+ for (const id of tracks.keys())
161
+ if (!shown.some(outcome => outcome.id === id))
162
+ tracks.delete(id);
163
+ for (const outcome of shown) {
164
+ const target = outcomeChance(outcome.price);
165
+ if (target == null) {
166
+ tracks.delete(outcome.id);
167
+ continue;
168
+ }
169
+ let track = tracks.get(outcome.id);
170
+ if (!track || reducedMotion) {
171
+ track = { from: target, to: target, start: now, value: target, ticks: track?.ticks ?? [] };
172
+ tracks.set(outcome.id, track);
173
+ }
174
+ else if (target !== track.to) {
175
+ if (now - track.start >= ALTIMETER_EASE_MS) {
176
+ track.from = track.value;
177
+ track.start = now;
178
+ }
179
+ track.to = target;
180
+ }
181
+ track.value = track.from + (track.to - track.from) * easeInOut((now - track.start) / ALTIMETER_EASE_MS);
182
+ if (sample) {
183
+ if (track.ticks.length === 0)
184
+ track.ticks.push({ t: now - keep, p: track.value });
185
+ track.ticks.push({ t: now, p: track.value });
186
+ while (track.ticks.length > 2 && track.ticks[1].t < now - keep)
187
+ track.ticks.shift();
188
+ }
189
+ }
190
+ if (sample)
191
+ sampled = now;
192
+ const centers = place.current(now);
193
+ if (!context || width <= 0)
194
+ return;
195
+ const ratio = window.devicePixelRatio || 1, w = Math.max(1, Math.round(width * ratio)), h = Math.max(1, Math.round(height * ratio));
196
+ if (surface.width !== w)
197
+ surface.width = w;
198
+ if (surface.height !== h)
199
+ surface.height = h;
200
+ context.setTransform(ratio, 0, 0, ratio, 0, 0);
201
+ drawOutcomes(context, { width, height, now, phase: reducedMotion ? 0 : gridPhase(now), grid: colors.nested, scale, trails: shown.flatMap((outcome, index) => { const track = tracks.get(outcome.id); return track ? [{ color: outcome.color ?? outcomeColors[index % outcomeColors.length], ticks: track.ticks, value: track.value, capsule: centers[index] }] : []; }) });
202
+ };
203
+ raf = requestAnimationFrame(step);
204
+ return () => { cancelAnimationFrame(raf); observer?.disconnect(); };
205
+ }, [height]);
206
+ return _jsxs("figure", { ...props, style: { margin: 0, inlineSize: '100%', minInlineSize: 0, ...style }, children: [_jsx("figcaption", { style: { marginBlockEnd: tokens.space.sm }, children: summary }), _jsxs("div", { ref: box, dir: 'ltr', style: { position: 'relative', height, overflow: 'hidden', borderRadius: tokens.radius.xl, background: colors.background, fontFamily: monoFont }, children: [_jsx("canvas", { ref: canvas, "aria-hidden": true, style: { position: 'absolute', inset: 0, width: '100%', height: '100%' } }), shown.length === 0
207
+ ? _jsx("p", { role: 'status', style: { position: 'absolute', inset: 0, margin: 0, display: 'grid', placeItems: 'center', color: colors.muted, fontFamily: 'var(--hig-font-sans, inherit)' }, children: stale ? (messages.stale ?? en.stale) : (messages.loadingChart ?? en.loadingChart) })
208
+ : _jsxs(_Fragment, { children: [_jsx("svg", { "aria-hidden": true, width: PAD, height: height, viewBox: `0 0 ${PAD} ${height}`, style: { position: 'absolute', left: 0, top: 0 }, children: ticks.map(tick => { const y = outcomeY(tick, height, INSET, scale); return _jsx("line", { x1: PAD - 8, x2: PAD, y1: y, y2: y, stroke: colors.muted, strokeWidth: 1, strokeLinecap: 'round', opacity: .75 }, tick); }) }), _jsx("svg", { "aria-hidden": true, "data-hig-outcome-ladder": true, width: LADDER, height: height, viewBox: `0 0 ${LADDER} ${height}`, style: { position: 'absolute', right: 0, top: 0 }, children: ticks.map(tick => {
209
+ const y = outcomeY(tick, height, INSET, scale);
210
+ return _jsxs("g", { opacity: .75, children: [_jsx("text", { x: LADDER - PAD - 14, y: y, textAnchor: 'end', dominantBaseline: 'central', fill: colors.muted, fontSize: 13, children: percent.format(tick) }), _jsx("line", { x1: LADDER - PAD, x2: LADDER - PAD + 8, y1: y, y2: y, stroke: colors.muted, strokeWidth: 1, strokeLinecap: 'round' })] }, tick);
211
+ }) }), _jsx("ul", { ref: list, style: { position: 'absolute', top: 0, right: EDGE, width: 'min(55%, 200px)', height: '100%', margin: 0, padding: 0, listStyle: 'none' }, children: shown.map((outcome, index) => _jsxs("li", { "data-hig-outcome": outcome.id, style: { position: 'absolute', insetInline: 0, top: rest[index] - CAPSULE / 2, height: CAPSULE, boxSizing: 'border-box', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, paddingInline: 14, border: `1px solid ${paint(outcome, index)}`, borderRadius: tokens.radius.pill, background: colors.background, color: paint(outcome, index), fontSize: 16, fontWeight: 600, lineHeight: 1.5, fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap' }, children: [_jsx("span", { style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' }, children: outcome.label }), _jsx(AnimatedNumberReadout, { value: outcomeChance(outcome.price), options: CHANCE })] }, outcome.id)) })] })] })] });
212
+ }
@@ -0,0 +1,43 @@
1
+ export interface Outcome {
2
+ /** Stable key. */
3
+ id: string;
4
+ /** Host text for the capsule, such as a team code or `Cut`. */
5
+ label: string;
6
+ /** Current price of one share in dollars, 0 to 1, read as its chance from 0 to 100%. `null` while unknown. */
7
+ price: number | null;
8
+ /** Host hex color. Defaults to `outcomeColors` in order. */
9
+ color?: string;
10
+ }
11
+ /** A live source of outcomes: call `onOutcomes` with each new snapshot, and return a function that stops it. */
12
+ export type OutcomeFeed = (onOutcomes: (outcomes: readonly Outcome[]) => void, onStale?: () => void) => () => void;
13
+ /** The most outcomes drawn; later ones are dropped. */
14
+ export declare const OUTCOME_LIMIT = 10;
15
+ /** Default line and capsule colors, in order. Each reads on the dark chart background (4.5:1 or better on #0a0a0a). */
16
+ export declare const outcomeColors: readonly string[];
17
+ /** An outcome's price as a chance from 0 to 1, or `null` while unknown. */
18
+ export declare function outcomeChance(price: number | null | undefined): number | null;
19
+ /** The part of 0..1 the ladder shows, and the chance between two ticks. */
20
+ export interface OutcomeScale {
21
+ low: number;
22
+ high: number;
23
+ step: number;
24
+ }
25
+ /** The whole ladder: 0 to 100% with a tick every ten percent. */
26
+ export declare const fullScale: OutcomeScale;
27
+ /**
28
+ * The ladder for these chances: the range they occupy plus a tenth of it on each side, on the finest of 1, 2, 5 or
29
+ * 10 percent steps that needs no more than twelve, and never fewer than four. Unknown chances are ignored; with none
30
+ * known it is the whole ladder. The `previous` scale is kept while every chance stays inside it, unless the chances
31
+ * have closed in to a third of it or less, so the ladder holds still while chances move.
32
+ */
33
+ export declare function outcomeScale(chances: readonly (number | null)[], previous?: OutcomeScale): OutcomeScale;
34
+ /** The ladder's ticks, from the top of the scale down. */
35
+ export declare function outcomeTicks(scale?: OutcomeScale): number[];
36
+ /** Vertical position of a chance: the top of the scale sits `inset` below the top and its bottom `inset` above the bottom. Chances outside the scale stay on its edge. */
37
+ export declare function outcomeY(chance: number, height: number, inset: number, scale?: OutcomeScale): number;
38
+ /**
39
+ * Centers for capsules of `size` that want to sit at `wanted` but may not overlap: neighbors keep `gap` between
40
+ * them and all stay inside `height`; when they cannot all fit with the gap, the gap shrinks. Returned in the order given.
41
+ * `preserveOrder` keeps the input sequence instead of sorting by desired position, for stable target-label stacks.
42
+ */
43
+ export declare function capsuleCenters(wanted: readonly number[], height: number, size?: number, gap?: number, preserveOrder?: boolean): number[];