@bloxwap/hig 0.0.0-stage → 0.5.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 (220) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +44 -2
  3. package/chart/README.md +23 -0
  4. package/chart/dist/index.d.ts +8 -0
  5. package/chart/dist/index.js +12 -0
  6. package/contracts/README.md +3 -0
  7. package/contracts/dist/announcements.d.ts +12 -0
  8. package/contracts/dist/announcements.js +8 -0
  9. package/contracts/dist/feedback.d.ts +40 -0
  10. package/contracts/dist/feedback.js +1 -0
  11. package/contracts/dist/index.d.ts +41 -0
  12. package/contracts/dist/index.js +52 -0
  13. package/contracts/dist/messages.d.ts +300 -0
  14. package/contracts/dist/messages.js +114 -0
  15. package/css.d.ts +2 -0
  16. package/feedback/README.md +7 -0
  17. package/feedback/assets/error.wav +0 -0
  18. package/feedback/assets/manifest.json +78 -0
  19. package/feedback/assets/success.wav +0 -0
  20. package/feedback/assets/tick.wav +0 -0
  21. package/feedback/assets/toggle.wav +0 -0
  22. package/feedback/dist/browser-haptic.d.ts +23 -0
  23. package/feedback/dist/browser-haptic.js +41 -0
  24. package/feedback/dist/contract.d.ts +40 -0
  25. package/feedback/dist/contract.js +59 -0
  26. package/feedback/dist/native.d.ts +28 -0
  27. package/feedback/dist/native.js +63 -0
  28. package/feedback/dist/preferences.d.ts +8 -0
  29. package/feedback/dist/preferences.js +24 -0
  30. package/feedback/dist/presets.d.ts +57 -0
  31. package/feedback/dist/presets.js +1 -0
  32. package/feedback/dist/react.d.ts +19 -0
  33. package/feedback/dist/react.js +23 -0
  34. package/feedback/dist/web-haptic.d.ts +6 -0
  35. package/feedback/dist/web-haptic.js +6 -0
  36. package/feedback/dist/web-sound.d.ts +5 -0
  37. package/feedback/dist/web-sound.js +32 -0
  38. package/feedback/dist/web.d.ts +3 -0
  39. package/feedback/dist/web.js +4 -0
  40. package/native/README.md +16 -0
  41. package/native/android/build.gradle +28 -0
  42. package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableView.java +173 -0
  43. package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableViewManager.java +23 -0
  44. package/native/android/src/main/java/com/bloxwap/hig/HIGPackage.java +24 -0
  45. package/native/dist/animated-number-model.d.ts +24 -0
  46. package/native/dist/animated-number-model.js +110 -0
  47. package/native/dist/animated-number.d.ts +9 -0
  48. package/native/dist/animated-number.js +97 -0
  49. package/native/dist/brand.d.ts +7 -0
  50. package/native/dist/brand.js +7 -0
  51. package/native/dist/button.d.ts +30 -0
  52. package/native/dist/button.js +36 -0
  53. package/native/dist/checkbox.d.ts +3 -0
  54. package/native/dist/checkbox.js +11 -0
  55. package/native/dist/data.d.ts +57 -0
  56. package/native/dist/data.js +47 -0
  57. package/native/dist/field.d.ts +16 -0
  58. package/native/dist/field.js +26 -0
  59. package/native/dist/gesture-sheet.d.ts +73 -0
  60. package/native/dist/gesture-sheet.js +153 -0
  61. package/native/dist/icons.d.ts +21 -0
  62. package/native/dist/icons.js +20 -0
  63. package/native/dist/navigation.d.ts +48 -0
  64. package/native/dist/navigation.js +58 -0
  65. package/native/dist/overlay.d.ts +36 -0
  66. package/native/dist/overlay.js +65 -0
  67. package/native/dist/pickers.d.ts +54 -0
  68. package/native/dist/pickers.js +60 -0
  69. package/native/dist/provider.d.ts +62 -0
  70. package/native/dist/provider.js +67 -0
  71. package/native/dist/radio-group.d.ts +21 -0
  72. package/native/dist/radio-group.js +91 -0
  73. package/native/dist/recipes.d.ts +45 -0
  74. package/native/dist/recipes.js +32 -0
  75. package/native/dist/roles.d.ts +6 -0
  76. package/native/dist/roles.js +4 -0
  77. package/native/dist/select.d.ts +3 -0
  78. package/native/dist/select.js +9 -0
  79. package/native/dist/selection-types.d.ts +22 -0
  80. package/native/dist/selection-types.js +1 -0
  81. package/native/dist/selection.d.ts +8 -0
  82. package/native/dist/selection.js +7 -0
  83. package/native/dist/slider.d.ts +11 -0
  84. package/native/dist/slider.js +42 -0
  85. package/native/dist/status.d.ts +86 -0
  86. package/native/dist/status.js +112 -0
  87. package/native/dist/surface.d.ts +19 -0
  88. package/native/dist/surface.js +42 -0
  89. package/native/dist/swap-panel.d.ts +125 -0
  90. package/native/dist/swap-panel.js +177 -0
  91. package/native/dist/swap-parts.d.ts +86 -0
  92. package/native/dist/swap-parts.js +66 -0
  93. package/native/dist/swap-shared.d.ts +65 -0
  94. package/native/dist/swap-shared.js +76 -0
  95. package/native/dist/swap-sheet.d.ts +14 -0
  96. package/native/dist/swap-sheet.js +26 -0
  97. package/native/dist/swap-views.d.ts +41 -0
  98. package/native/dist/swap-views.js +37 -0
  99. package/native/dist/switch-row.d.ts +8 -0
  100. package/native/dist/switch-row.js +18 -0
  101. package/native/dist/switch.d.ts +10 -0
  102. package/native/dist/switch.js +30 -0
  103. package/native/dist/text-content.d.ts +5 -0
  104. package/native/dist/text-content.js +6 -0
  105. package/native/dist/wallet-address.d.ts +37 -0
  106. package/native/dist/wallet-address.js +50 -0
  107. package/native-fonts/README.md +17 -0
  108. package/native-fonts/dist/index.d.ts +164 -0
  109. package/native-fonts/dist/index.js +164 -0
  110. package/native-fonts/fonts/BloxwapMono-Bold.ttf +0 -0
  111. package/native-fonts/fonts/BloxwapMono-ExtraBold.ttf +0 -0
  112. package/native-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
  113. package/native-fonts/fonts/BloxwapMono-SemiBold.ttf +0 -0
  114. package/native-fonts/fonts/BloxwapMono.ttf +0 -0
  115. package/native-fonts/fonts/BloxwapSans-Black.ttf +0 -0
  116. package/native-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
  117. package/native-fonts/fonts/BloxwapSans-ExtraBold.ttf +0 -0
  118. package/native-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
  119. package/native-fonts/fonts/BloxwapSans-SemiBold.ttf +0 -0
  120. package/native-fonts/fonts/BloxwapSans.ttf +0 -0
  121. package/native-fonts/fonts/BloxwapSansKR-SemiBold.ttf +0 -0
  122. package/native-fonts/fonts/BloxwapSansKR.ttf +0 -0
  123. package/native-fonts/fonts/BloxwapSansSC-SemiBold.ttf +0 -0
  124. package/native-fonts/fonts/BloxwapSansSC.ttf +0 -0
  125. package/native-fonts/fonts/OFL.txt +93 -0
  126. package/native-fonts/fonts/manifest.json +164 -0
  127. package/og-fonts/README.md +34 -0
  128. package/og-fonts/dist/index.d.ts +116 -0
  129. package/og-fonts/dist/index.js +102 -0
  130. package/og-fonts/dist/node.d.ts +11 -0
  131. package/og-fonts/dist/node.js +39 -0
  132. package/og-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
  133. package/og-fonts/fonts/BloxwapSans-Black.ttf +0 -0
  134. package/og-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
  135. package/og-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
  136. package/og-fonts/fonts/BloxwapSans.ttf +0 -0
  137. package/og-fonts/fonts/OFL.txt +93 -0
  138. package/og-fonts/fonts/manifest.json +65 -0
  139. package/package.json +476 -4
  140. package/react/README.md +30 -0
  141. package/react/dist/animated-number-model.d.ts +20 -0
  142. package/react/dist/animated-number-model.js +92 -0
  143. package/react/dist/animated-number.d.ts +8 -0
  144. package/react/dist/animated-number.js +72 -0
  145. package/react/dist/base.css +9 -0
  146. package/react/dist/brand.d.ts +7 -0
  147. package/react/dist/brand.js +5 -0
  148. package/react/dist/button.d.ts +14 -0
  149. package/react/dist/button.js +20 -0
  150. package/react/dist/data.d.ts +78 -0
  151. package/react/dist/data.js +36 -0
  152. package/react/dist/dialog.d.ts +29 -0
  153. package/react/dist/dialog.js +21 -0
  154. package/react/dist/field.d.ts +16 -0
  155. package/react/dist/field.js +20 -0
  156. package/react/dist/gesture-sheet.d.ts +41 -0
  157. package/react/dist/gesture-sheet.js +128 -0
  158. package/react/dist/navigation.d.ts +48 -0
  159. package/react/dist/navigation.js +69 -0
  160. package/react/dist/notify.d.ts +14 -0
  161. package/react/dist/notify.js +6 -0
  162. package/react/dist/overlay.d.ts +17 -0
  163. package/react/dist/overlay.js +18 -0
  164. package/react/dist/provider.d.ts +25 -0
  165. package/react/dist/provider.js +50 -0
  166. package/react/dist/recipes/activity-list.d.ts +8 -0
  167. package/react/dist/recipes/activity-list.js +6 -0
  168. package/react/dist/recipes/balance-card.d.ts +6 -0
  169. package/react/dist/recipes/balance-card.js +5 -0
  170. package/react/dist/recipes/code-window.d.ts +4 -0
  171. package/react/dist/recipes/code-window.js +4 -0
  172. package/react/dist/recipes/install-command.d.ts +6 -0
  173. package/react/dist/recipes/install-command.js +15 -0
  174. package/react/dist/recipes/market-row.d.ts +25 -0
  175. package/react/dist/recipes/market-row.js +8 -0
  176. package/react/dist/recipes/marketing-hero.d.ts +7 -0
  177. package/react/dist/recipes/marketing-hero.js +5 -0
  178. package/react/dist/recipes/pickers.d.ts +57 -0
  179. package/react/dist/recipes/pickers.js +78 -0
  180. package/react/dist/recipes/swap/amount-card.d.ts +40 -0
  181. package/react/dist/recipes/swap/amount-card.js +7 -0
  182. package/react/dist/recipes/swap/picker.d.ts +26 -0
  183. package/react/dist/recipes/swap/picker.js +20 -0
  184. package/react/dist/recipes/swap/settings.d.ts +24 -0
  185. package/react/dist/recipes/swap/settings.js +25 -0
  186. package/react/dist/recipes/swap/shared.d.ts +98 -0
  187. package/react/dist/recipes/swap/shared.js +106 -0
  188. package/react/dist/recipes/swap-panel.d.ts +127 -0
  189. package/react/dist/recipes/swap-panel.js +170 -0
  190. package/react/dist/recipes/swap-sheet.d.ts +16 -0
  191. package/react/dist/recipes/swap-sheet.js +22 -0
  192. package/react/dist/recipes/trade-entry.d.ts +11 -0
  193. package/react/dist/recipes/trade-entry.js +12 -0
  194. package/react/dist/recipes.d.ts +10 -0
  195. package/react/dist/recipes.js +11 -0
  196. package/react/dist/select.d.ts +4 -0
  197. package/react/dist/select.js +174 -0
  198. package/react/dist/selection.d.ts +40 -0
  199. package/react/dist/selection.js +23 -0
  200. package/react/dist/slider.d.ts +11 -0
  201. package/react/dist/slider.js +10 -0
  202. package/react/dist/status.d.ts +63 -0
  203. package/react/dist/status.js +47 -0
  204. package/react/dist/styles.css +542 -0
  205. package/react/dist/surface.d.ts +291 -0
  206. package/react/dist/surface.js +9 -0
  207. package/react/dist/toast.d.ts +17 -0
  208. package/react/dist/toast.js +21 -0
  209. package/react/dist/wallet-address.d.ts +23 -0
  210. package/react/dist/wallet-address.js +24 -0
  211. package/tokens/README.md +17 -0
  212. package/tokens/assets/bloxwap-icon.svg +1 -0
  213. package/tokens/dist/brand.d.ts +19 -0
  214. package/tokens/dist/brand.js +24 -0
  215. package/tokens/dist/index.d.ts +437 -0
  216. package/tokens/dist/index.js +514 -0
  217. package/tokens/dist/manifest.json +200 -0
  218. package/tokens/dist/theme.d.ts +11 -0
  219. package/tokens/dist/theme.js +22 -0
  220. package/tokens/dist/tokens.css +120 -0
@@ -0,0 +1,170 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useMemo, useRef, useState } from 'react';
4
+ import { formatNumber } from '@bloxwap/hig/contracts';
5
+ import * as en from '@bloxwap/hig/contracts/messages';
6
+ import { useControllable, useHIG } from '../provider.js';
7
+ import { Button, IconButton } from '../button.js';
8
+ import { AnimatedNumberReadout } from '../animated-number.js';
9
+ import { notify } from '../notify.js';
10
+ import { VerticalAddress } from '../data.js';
11
+ import { SwapPicker } from './swap/picker.js';
12
+ import { SwapSettings } from './swap/settings.js';
13
+ import { SwapIcon, SwapKeypad, SwapPill, addressGradient, applyAmountKey, chainsOf, formatPercent, parentView, sanitizeAmount, shortAddress, swapAction, testAmount, trimNumber, unitsToEntry } from './swap/shared.js';
14
+ export { swapAction } from './swap/shared.js';
15
+ export { SwapAmountCard } from './swap/amount-card.js';
16
+ export { SwapPill, SwapKeypad } from './swap/shared.js';
17
+ const textTarget = (target) => { const element = target; return !!element && (/^(INPUT|TEXTAREA|SELECT)$/.test(element.tagName) || element.isContentEditable); };
18
+ const amountKey = (event) => event.metaKey || event.ctrlKey || event.altKey ? null : /^[0-9.]$/.test(event.key) ? event.key : event.key === 'Backspace' ? 'back' : null;
19
+ /**
20
+ * Send, swap and bridge in one panel: a From card and a To card joined by a flip control, an amount entered in dollars
21
+ * or token units, token pickers, settings, and one action that names itself from the chosen pair.
22
+ * Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
23
+ */
24
+ export function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTokenIds, from: fromProp, to: toProp, defaultFrom = null, defaultTo = null, onFromChange, onToChange, amount, onAmountChange, received, fee, fees, quoteLoading, slippage = 0.005, onSlippageChange, denomination, onDenominationChange, wallet, onConnect, onDisconnect, recipient, onRecipientChange, onScanRecipient, receive, receiving, onReceivingChange, onSubmit, submitting = false, onReset, destination, details, note, noteTone = 'muted', title, onBack, controls = true, actionIcon, lockFrom = false, lockTo = false, actionLabel, oneWay: oneWayProp = false, denominationSwitch = true, keypad = 'auto', shortcuts = true, captureKeyboard = false, view: viewProp, onViewChange, settings, className, style }) {
25
+ const { messages, locale } = useHIG();
26
+ const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
27
+ const [to, setTo] = useControllable(toProp, defaultTo, onToChange);
28
+ const [defaultMode, setDefaultMode] = useControllable(denomination, 'usd', onDenominationChange);
29
+ const [isReceiving, setReceiving] = useControllable(receiving, false, onReceivingChange);
30
+ // A mounted `amount` seeds the entry, in the default denomination at the initial From token's price.
31
+ const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(Number(amount) || 0, defaultMode, from?.price ?? 0));
32
+ const [fromMode, applyFromMode] = useState(defaultMode);
33
+ const [toMode, applyToMode] = useState(defaultMode);
34
+ const [view, show] = useControllable(viewProp, 'main', onViewChange);
35
+ const root = useRef(null);
36
+ const previous = useRef('main');
37
+ const openPicker = (side) => show(side);
38
+ const back = () => show(parentView(view));
39
+ // A push slides in from the trailing edge and a pop from the leading edge. Popping to the cards returns focus to the control that pushed.
40
+ const direction = view === 'main' || (view === 'settings' && previous.current !== 'main') ? 'pop' : 'push';
41
+ useEffect(() => { const from = previous.current; previous.current = view; if (view !== 'main' || from === 'main')
42
+ return; root.current?.querySelector(from === 'from' || from === 'to' ? `[data-side='${from}'] .hig-swap-hit` : '.hig-swap-settings-button')?.focus(); }, [view]);
43
+ const [touch, setTouch] = useState(false);
44
+ const [hint, showHint] = useState(null);
45
+ const [copied, setCopied] = useState('');
46
+ useEffect(() => {
47
+ const coarse = window.matchMedia?.('(pointer: coarse)');
48
+ const update = () => setTouch(!!coarse?.matches);
49
+ update();
50
+ coarse?.addEventListener('change', update);
51
+ if (window.matchMedia?.('(hover: hover) and (pointer: fine)').matches)
52
+ showHint(/Mac|iPhone|iPad/.test(navigator.platform) ? 'mac' : 'pc');
53
+ return () => coarse?.removeEventListener('change', update);
54
+ }, []);
55
+ const fromPrice = from?.price ?? 0, toPrice = to?.price ?? 0, input = Number(entry) || 0;
56
+ const units = fromMode === 'token' ? input : fromPrice > 0 ? input / fromPrice : 0, usd = units * fromPrice, unitsText = trimNumber(units);
57
+ const showReceive = isReceiving && !!receive;
58
+ // Report the amount in token units; resync the entry when the host sets a different amount.
59
+ const reported = useRef(amount ?? '0');
60
+ useEffect(() => { if (reported.current !== unitsText) {
61
+ reported.current = unitsText;
62
+ onAmountChange?.(unitsText);
63
+ } }, [unitsText]);
64
+ useEffect(() => { if (amount === undefined || Number(amount) === Number(reported.current))
65
+ return; reported.current = trimNumber(Number(amount) || 0); setEntry(unitsToEntry(Number(amount) || 0, fromMode, fromPrice)); }, [amount]);
66
+ const sameAsset = !!from && !!to && from.id === to.id;
67
+ const receivedUnits = sameAsset ? units : received ?? (toPrice > 0 ? usd / toPrice : 0);
68
+ const receivedUsd = toPrice > 0 ? receivedUnits * toPrice : sameAsset ? usd : 0;
69
+ const action = swapAction(from, to);
70
+ const insufficient = !!from && (from.balance ?? 0) > 0 && units > (from.balance ?? 0);
71
+ // A destination or a details card stands in for the To token: one way, and ready from the From side alone.
72
+ const fixed = !!destination || (!!details && !to);
73
+ const oneWay = oneWayProp || fixed;
74
+ const ready = !!from && (!!to || fixed) && !destination?.pending && units > 0 && !insufficient;
75
+ const actionText = showReceive ? (messages.swapSendFromWallet ?? en.swapSendFromWallet) : !from || (!to && !fixed) ? (messages.swapChooseToken ?? en.swapChooseToken) : destination?.pending ? (messages.swapChooseDestination ?? en.swapChooseDestination) : units <= 0 ? (messages.swapEnterAmount ?? en.swapEnterAmount) : insufficient ? (messages.swapInsufficient ?? en.swapInsufficient)(from.symbol) : actionLabel ?? (action === 'swap' && !fixed ? messages.swapActionSwap ?? en.swapActionSwap : action === 'bridge' && !fixed ? messages.swapActionBridge ?? en.swapActionBridge : messages.swapActionSend ?? en.swapActionSend);
76
+ const pristine = (lockFrom || !from) && (lockTo || !to) && input === 0;
77
+ // Updater form: several keys can land before the next render, and each must build on the last.
78
+ const latest = useRef(fromMode);
79
+ latest.current = fromMode;
80
+ const latestView = useRef(view);
81
+ latestView.current = view;
82
+ const press = (key) => setEntry(current => applyAmountKey(current, key, latest.current));
83
+ const paste = (text) => { const clean = text.trim().replace(/,/g, ''); if (clean === '' || !/^[0-9]*\.?[0-9]*$/.test(clean))
84
+ return false; const next = sanitizeAmount(clean); setEntry(latest.current === 'usd' ? trimNumber(Number(next) || 0, 2) : next); return true; };
85
+ const switchFromMode = (mode) => { if (mode === fromMode)
86
+ return; setEntry(mode === 'usd' ? trimNumber(usd, 2) : trimNumber(units)); applyFromMode(mode); };
87
+ const changeDenomination = (mode) => { setDefaultMode(mode); switchFromMode(mode); applyToMode(mode); };
88
+ // A new default applies to an untouched entry at once; a typed amount keeps its denomination until reset.
89
+ useEffect(() => { if (input === 0) {
90
+ applyFromMode(defaultMode);
91
+ applyToMode(defaultMode);
92
+ } }, [defaultMode]);
93
+ const reset = () => { setEntry('0'); applyFromMode(defaultMode); applyToMode(defaultMode); if (isReceiving)
94
+ setReceiving(false); if (!lockFrom)
95
+ setFrom(null); if (!lockTo)
96
+ setTo(null); onReset?.(); };
97
+ const flip = () => { if (!from || !to)
98
+ return; setFrom(to); setTo(from); };
99
+ const submit = () => { if (submitting)
100
+ return; if (showReceive) {
101
+ onConnect?.();
102
+ return;
103
+ } if (ready)
104
+ onSubmit(fixed ? 'send' : action); };
105
+ const copyAddress = () => { if (!receive?.onCopy)
106
+ return; Promise.resolve().then(receive.onCopy).then(() => { const text = (messages.addressCopied ?? en.addressCopied); setCopied(notify(text, { severity: 'success', id: 'hig-swap-address', dismissName: (messages.dismissNotice ?? en.dismissNotice)(text, (messages.dismiss ?? en.dismiss)) }) ? text : ''); }).catch(() => setCopied('')); };
107
+ useEffect(() => {
108
+ if (!shortcuts && !captureKeyboard)
109
+ return;
110
+ const onKeyDown = (event) => {
111
+ const key = event.key.toLowerCase();
112
+ if (shortcuts && (event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey && (key === 'f' || key === 'k')) {
113
+ const side = key === 'f' ? 'from' : 'to';
114
+ if (side === 'from' ? lockFrom : lockTo || fixed)
115
+ return;
116
+ event.preventDefault();
117
+ show(side);
118
+ return;
119
+ }
120
+ if (!captureKeyboard || event.defaultPrevented || textTarget(event.target) || latestView.current !== 'main')
121
+ return;
122
+ const pressed = amountKey(event);
123
+ if (pressed) {
124
+ event.preventDefault();
125
+ press(pressed);
126
+ }
127
+ };
128
+ const onPaste = (event) => { if (captureKeyboard && !event.defaultPrevented && !textTarget(event.target) && paste(event.clipboardData?.getData('text') ?? ''))
129
+ event.preventDefault(); };
130
+ window.addEventListener('keydown', onKeyDown);
131
+ document.addEventListener('paste', onPaste);
132
+ return () => { window.removeEventListener('keydown', onKeyDown); document.removeEventListener('paste', onPaste); };
133
+ }, [shortcuts, captureKeyboard, lockFrom, lockTo, fixed]);
134
+ // Keys typed while focus is inside the cards drive the amount; in a pushed view Escape pops it.
135
+ const inPanel = (event) => view === 'main' && !textTarget(event.target);
136
+ const onKeyDown = (event) => { if (view !== 'main' && event.key === 'Escape') {
137
+ event.preventDefault();
138
+ event.stopPropagation();
139
+ back();
140
+ return;
141
+ } if (captureKeyboard || !inPanel(event))
142
+ return; const pressed = amountKey(event); if (pressed) {
143
+ event.preventDefault();
144
+ press(pressed);
145
+ } };
146
+ const onPaste = (event) => { if (!captureKeyboard && inPanel(event) && paste(event.clipboardData.getData('text')))
147
+ event.preventDefault(); };
148
+ const chainList = useMemo(() => chains ?? chainsOf(tokens), [chains, tokens]);
149
+ const usdText = (value) => formatNumber(value, locale, { style: 'currency', currency: 'USD' });
150
+ const fraction = entry.includes('.') ? Math.min(entry.length - entry.indexOf('.') - 1, fromMode === 'usd' ? 2 : 8) : 0;
151
+ // An account (a token with a `caption`) reads name over caption beside one disc, and offers Max only.
152
+ const account = (side, token, locked) => _jsxs("div", { className: 'hig-swap-selected', "data-account": 'true', children: [_jsx("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: token.icon ? _jsx("img", { src: token.icon, alt: '' }) : _jsx("span", { className: 'hig-swap-initials', children: token.symbol.slice(0, 3) }) }), _jsxs("span", { className: 'hig-swap-identity', children: [_jsxs("strong", { children: [token.name, !locked && _jsx(SwapIcon, { name: 'expand', size: 16 })] }), _jsx("span", { children: token.caption })] }), side === 'from' && (token.balance ?? 0) > 0 && _jsx("span", { className: 'hig-swap-meta', children: _jsx(SwapPill, { onClick: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: (messages.swapMax ?? en.swapMax) }) })] });
153
+ const header = (side, token) => _jsxs("div", { className: 'hig-swap-selected', children: [_jsxs("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: [wallet?.address && _jsx("span", { className: 'hig-swap-avatar', style: { background: addressGradient(wallet.address) } }), token.chainIcon && _jsx("img", { src: token.chainIcon, alt: '' }), token.icon ? _jsx("img", { src: token.icon, alt: '' }) : _jsx("span", { className: 'hig-swap-initials', children: token.symbol.slice(0, 3) })] }), _jsxs("span", { className: 'hig-swap-identity', children: [wallet?.address && _jsx("span", { children: shortAddress(wallet.address) }), _jsx("span", { children: token.chain }), _jsx("strong", { children: token.name })] }), side === 'from' ? (token.balance ?? 0) > 0 && _jsxs("span", { className: 'hig-swap-meta', children: [_jsxs("span", { className: 'hig-swap-pills', children: [_jsxs(SwapPill, { onClick: () => setEntry(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: [_jsx(SwapIcon, { name: 'flask', size: 14 }), (messages.swapTest ?? en.swapTest)] }), _jsx(SwapPill, { onClick: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: (messages.swapMax ?? en.swapMax) })] }), _jsxs("span", { className: 'hig-number', children: [formatNumber(token.balance, locale, { maximumFractionDigits: 6 }), " ", token.symbol] })] })
154
+ : _jsxs("span", { className: 'hig-swap-meta', children: [_jsxs(SwapPill, { onClick: () => show(onSlippageChange ? 'slippage' : 'settings'), children: [_jsx(SwapIcon, { name: 'sliders', size: 14 }), (messages.swapSlippage ?? en.swapSlippage)(formatPercent(slippage))] }), _jsx("span", { children: (messages.swapFee ?? en.swapFee)(quoteLoading ? '…' : fee != null ? usdText(fee) : '—') })] })] });
155
+ const receiveView = (view) => { const content = _jsxs(_Fragment, { children: [view.qr && _jsx("span", { className: 'hig-swap-qr', children: view.qr }), _jsx(VerticalAddress, { address: view.address })] }); return view.onCopy ? _jsx("button", { type: 'button', className: 'hig-swap-receive', "aria-label": (messages.copyAddress ?? en.copyAddress) + ': ' + view.address, onClick: copyAddress, children: content }) : _jsx("div", { className: 'hig-swap-receive', children: content }); };
156
+ const card = (side) => {
157
+ const token = side === 'from' ? from : to, label = side === 'from' ? (messages.swapFrom ?? en.swapFrom) : (messages.swapTo ?? en.swapTo), mode = side === 'from' ? fromMode : toMode, locked = side === 'from' ? lockFrom : lockTo;
158
+ const cardUnits = side === 'from' ? units : receivedUnits, cardUsd = side === 'from' ? usd : receivedUsd;
159
+ const shown = side === 'from' ? input : mode === 'token' ? receivedUnits : receivedUsd;
160
+ return _jsxs("div", { className: 'hig-swap-card', "data-side": side, "data-locked": locked || undefined, children: [_jsxs("div", { className: 'hig-swap-slot', children: [!locked && _jsx("button", { type: 'button', className: 'hig-swap-hit', "aria-label": (messages.swapSelectToken ?? en.swapSelectToken)(label), onClick: () => openPicker(side) }), _jsx("div", { className: 'hig-swap-slot-content', children: token ? token.caption !== undefined ? account(side, token, locked) : header(side, token) : _jsxs(_Fragment, { children: [_jsxs("span", { className: 'hig-swap-placeholder', children: [label, "\u2026"] }), shortcuts && hint && !locked && _jsxs("kbd", { className: 'hig-swap-kbd', children: [hint === 'mac' ? '⌘' : messages.swapControlKey ?? en.swapControlKey, " ", side === 'from' ? 'F' : 'K'] })] }) })] }), side === 'from' && showReceive && receive ? receiveView(receive) :
161
+ !(side === 'to' && showReceive) && _jsxs("div", { className: 'hig-swap-amount-area', children: [!locked && _jsx("button", { type: 'button', className: 'hig-swap-hit', tabIndex: -1, "aria-hidden": 'true', onClick: () => openPicker(side) }), _jsxs("div", { className: 'hig-swap-amount-content', children: [_jsx("div", { className: 'hig-swap-amount', "data-muted": side === 'to' || undefined, ...(side === 'from' ? { role: 'textbox', tabIndex: 0, 'aria-label': (messages.swapAmount ?? en.swapAmount)(label) } : {}), children: _jsx(AnimatedNumberReadout, { value: shown, label: side === 'to' ? (messages.swapAmount ?? en.swapAmount)(label) : undefined, prefix: mode === 'usd' ? '$' : '', suffix: side === 'from' && entry.endsWith('.') ? '.' : '', options: { minimumFractionDigits: side === 'from' ? fraction : 0, maximumFractionDigits: mode === 'usd' ? 2 : 8, useGrouping: false } }) }), denominationSwitch && _jsxs(SwapPill, { "aria-label": (messages.swapSwitchDenomination ?? en.swapSwitchDenomination), onClick: () => side === 'from' ? switchFromMode(fromMode === 'usd' ? 'token' : 'usd') : applyToMode(toMode === 'usd' ? 'token' : 'usd'), children: [_jsx("span", { "aria-hidden": 'true', className: 'hig-swap-equals', children: "=" }), mode === 'token' ? _jsx(AnimatedNumberReadout, { value: cardUsd, options: { style: 'currency', currency: 'USD' } }) : _jsx(AnimatedNumberReadout, { value: cardUnits, suffix: token ? ` ${token.symbol}` : '', options: { maximumFractionDigits: 8, useGrouping: false } }), _jsx(SwapIcon, { name: 'flip', size: 14 })] })] })] })] });
162
+ };
163
+ // The fixed bottom card is one compact row for the destination (artwork, where it goes, a trailing detail and fee), label and value rows, or both.
164
+ const fixedCard = fixed && _jsxs("div", { className: 'hig-swap-card', "data-side": 'to', "data-compact": 'true', "data-pending": destination?.pending || undefined, children: [destination && _jsxs("div", { className: 'hig-swap-slot', children: [destination.onPress && _jsx("button", { type: 'button', className: 'hig-swap-hit', "aria-label": destination.title, onClick: destination.onPress }), _jsx("div", { className: 'hig-swap-slot-content', children: _jsxs("div", { className: 'hig-swap-selected', children: [_jsx("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: destination.icon ? _jsx("img", { src: destination.icon, alt: '' }) : destination.address ? _jsx("span", { className: 'hig-swap-avatar', style: { background: addressGradient(destination.address) } }) : _jsx("span", { className: 'hig-swap-initials', children: destination.title.slice(0, 2) }) }), _jsxs("span", { className: 'hig-swap-identity', children: [_jsx("strong", { children: destination.title }), destination.subtitle && _jsx("span", { children: destination.subtitle }), destination.address && _jsx("span", { children: shortAddress(destination.address) })] }), (destination.detail || fee !== undefined || destination.onPress) && _jsxs("span", { className: 'hig-swap-meta', "data-row": destination.onPress ? 'true' : undefined, children: [_jsxs("span", { children: [destination.detail && _jsx("span", { children: destination.detail }), fee !== undefined && _jsx("span", { children: (messages.swapFee ?? en.swapFee)(quoteLoading ? '…' : fee != null ? usdText(fee) : '—') })] }), destination.onPress && _jsx(SwapIcon, { name: 'chevron', size: 16 })] })] }) })] }), details && details.length > 0 && _jsx("dl", { className: 'hig-swap-details', children: details.map(row => _jsxs("div", { children: [_jsx("dt", { children: row.label }), _jsx("dd", { children: row.value })] }, row.label)) })] });
165
+ const fromCard = card('from'), toCard = fixedCard || card('to');
166
+ const body = view === 'main' ? _jsxs(_Fragment, { children: [title && _jsxs("div", { className: 'hig-swap-view-header', "data-plain": onBack ? undefined : 'true', children: [onBack && _jsx("button", { type: 'button', className: 'hig-swap-back', "aria-label": messages.back ?? en.back, onClick: onBack, children: _jsx(SwapIcon, { name: 'back' }) }), _jsx("h2", { className: 'hig-swap-view-title', children: title })] }), fromCard, _jsx("div", { className: 'hig-swap-flip', children: oneWay ? _jsx("span", { "aria-hidden": 'true', children: _jsx(SwapIcon, { name: 'down', size: 16 }) }) : _jsx("button", { type: 'button', "aria-label": (messages.swapFlip ?? en.swapFlip), disabled: !from || !to, onClick: flip, children: _jsx(SwapIcon, { name: 'flip', size: 16 }) }) }), toCard, !showReceive && (keypad === 'always' || (keypad === 'auto' && touch)) && _jsx(SwapKeypad, { onKey: press, label: (messages.swapKeypad ?? en.swapKeypad), deleteLabel: (messages.swapDelete ?? en.swapDelete) }), note && _jsx("p", { className: 'hig-swap-note', "data-tone": noteTone, role: 'note', children: note }), _jsxs("div", { className: 'hig-swap-actions', children: [controls && _jsx(IconButton, { className: 'hig-swap-settings-button', intent: 'secondary', label: (messages.swapSettings ?? en.swapSettings), suppressFeedback: true, onClick: () => show('settings'), children: _jsx(SwapIcon, { name: 'menu' }) }), _jsxs(Button, { fullWidth: true, busy: submitting, disabled: !showReceive && !ready, onClick: submit, children: [actionIcon, actionText] }), controls && _jsx(IconButton, { intent: 'secondary', label: (messages.swapReset ?? en.swapReset), disabled: pristine || submitting, onClick: reset, children: _jsx(SwapIcon, { name: 'reset' }) })] })] }) : view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect: setFrom, wallet: wallet, onConnect: onConnect, onDisconnect: onDisconnect, receiving: isReceiving, onReceivingChange: receive ? setReceiving : undefined })
167
+ : view === 'to' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: tokens, chains: chainList, hotTokenIds: hotTokenIds, selected: to, onSelect: setTo, wallet: wallet, recipient: recipient, onRecipientChange: onRecipientChange, onScanRecipient: onScanRecipient })
168
+ : _jsx(SwapSettings, { view: view, onViewChange: show, onBack: back, denomination: defaultMode, onDenominationChange: denominationSwitch ? changeDenomination : undefined, slippage: slippage, onSlippageChange: onSlippageChange, fee: fee, fees: fees, quoteLoading: quoteLoading, children: settings });
169
+ return _jsxs("section", { ref: root, className: `hig-swap-panel${className ? ` ${className}` : ''}`, style: style, "data-view": view, "data-receiving": showReceive || undefined, onKeyDown: onKeyDown, onPaste: onPaste, children: [_jsx("div", { className: 'hig-swap-view', "data-direction": direction, children: body }, view), _jsx("p", { className: 'hig-sr-only', role: 'status', children: copied })] });
170
+ }
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { type SwapPanelProps } from './swap-panel.js';
3
+ export interface SwapSheetProps extends SwapPanelProps {
4
+ open: boolean;
5
+ onOpenChange: (open: boolean) => void;
6
+ /** Accessible name of the sheet; not drawn. */
7
+ title: string;
8
+ /** One element that opens the sheet and accepts a ref. */
9
+ trigger?: React.ReactNode;
10
+ }
11
+ /**
12
+ * SwapPanel presented in a gesture sheet (Vaul). Token pickers and settings push inside the same sheet, which resizes to
13
+ * each view. Escape and Back pop a pushed view first; from the cards, Escape, the scrim and a downward drag close the sheet.
14
+ * Lives in its own entry so the recipes aggregate stays free of the optional Vaul peer.
15
+ */
16
+ export declare function SwapSheet({ open, onOpenChange, title, trigger, view: viewProp, onViewChange, ...panel }: SwapSheetProps): React.JSX.Element;
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect } from 'react';
4
+ import { useControllable } from '../provider.js';
5
+ import { GestureSheet } from '../gesture-sheet.js';
6
+ import { SwapPanel } from './swap-panel.js';
7
+ import { parentView } from './swap/shared.js';
8
+ /**
9
+ * SwapPanel presented in a gesture sheet (Vaul). Token pickers and settings push inside the same sheet, which resizes to
10
+ * each view. Escape and Back pop a pushed view first; from the cards, Escape, the scrim and a downward drag close the sheet.
11
+ * Lives in its own entry so the recipes aggregate stays free of the optional Vaul peer.
12
+ */
13
+ export function SwapSheet({ open, onOpenChange, title, trigger, view: viewProp, onViewChange, ...panel }) {
14
+ const [view, show] = useControllable(viewProp, 'main', onViewChange);
15
+ // A reopened sheet starts on the cards, not on the view it was closed from.
16
+ useEffect(() => { if (!open && view !== 'main')
17
+ show('main'); }, [open]);
18
+ return _jsx(GestureSheet, { open: open, onOpenChange: onOpenChange, title: title, titleHidden: true, trigger: trigger, closeButton: null, contentMode: 'custom', enableDynamicSizing: true, contentProps: { className: 'hig-swap-sheet', onEscapeKeyDown: event => { if (view !== 'main') {
19
+ event.preventDefault();
20
+ show(parentView(view));
21
+ } } }, children: _jsx(SwapPanel, { ...panel, view: view, onViewChange: show }) });
22
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ /** Host validates and submits. Opening review never submits a transaction. */
3
+ export declare function TradeEntry({ asset, amount, onAmountChange, onConfirm, busy, error, available }: {
4
+ asset: string;
5
+ amount: string;
6
+ onAmountChange: (v: string) => void;
7
+ onConfirm: () => void;
8
+ busy?: boolean;
9
+ error?: string;
10
+ available: string;
11
+ }): React.JSX.Element;
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from 'react';
4
+ import * as en from '@bloxwap/hig/contracts/messages';
5
+ import { useHIG } from '../provider.js';
6
+ import { Button } from '../button.js';
7
+ import { Surface, Stack, Heading } from '../surface.js';
8
+ import { Field, AmountInput } from '../field.js';
9
+ import { Dialog } from '../dialog.js';
10
+ import { Alert } from '../status.js';
11
+ /** Host validates and submits. Opening review never submits a transaction. */
12
+ export function TradeEntry({ asset, amount, onAmountChange, onConfirm, busy, error, available }) { const { messages } = useHIG(); const [review, setReview] = useState(false); return _jsx(Surface, { children: _jsxs(Stack, { children: [_jsx(Heading, { children: (messages.reviewAssetOrder ?? en.reviewAssetOrder)(asset) }), _jsx(Field, { label: (messages.amountInAsset ?? en.amountInAsset)(asset), description: (messages.availableAmount ?? en.availableAmount)(available), error: error, children: _jsx(AmountInput, { value: amount, onChange: e => onAmountChange(e.target.value), readOnly: busy }) }), _jsx(Button, { fullWidth: true, className: 'hig-form-action', disabled: !amount || !!error, busy: busy, onClick: () => setReview(true), children: messages.reviewOrder ?? en.reviewOrder }), _jsxs(Dialog, { open: review, onOpenChange: setReview, title: messages.confirmOrder ?? en.confirmOrder, description: (messages.confirmOrderDescription ?? en.confirmOrderDescription)(amount, asset), children: [_jsx(Button, { busy: busy, disabled: !!error, onClick: onConfirm, children: messages.confirmOrder ?? en.confirmOrder }), error && _jsx(Alert, { title: messages.orderUnavailable ?? en.orderUnavailable, severity: 'error', children: _jsx("p", { children: error }) })] })] }) }); }
@@ -0,0 +1,10 @@
1
+ /** Aggregate entry. TradeEntry needs @radix-ui/react-dialog; import single recipes from `@bloxwap/hig/react/recipes/<name>` to avoid overlay peers. SwapSheet (Vaul) is only at `recipes/swap-sheet`. */
2
+ export { MarketRow } from './recipes/market-row.js';
3
+ export { BalanceCard } from './recipes/balance-card.js';
4
+ export { TradeEntry } from './recipes/trade-entry.js';
5
+ export { InstallCommand } from './recipes/install-command.js';
6
+ export { CodeWindow } from './recipes/code-window.js';
7
+ export { MarketingHero } from './recipes/marketing-hero.js';
8
+ export { ActivityList } from './recipes/activity-list.js';
9
+ export { FromPicker, ToPicker, type FromPickerProps, type ToPickerProps, type PickerListProps } from './recipes/pickers.js';
10
+ export { SwapPanel, swapAction, type SwapPanelProps, type SwapToken, type SwapChain, type SwapAction, type SwapDenomination, type SwapWallet, type SwapFee, type SwapReceive, type SwapDestination, type SwapDetail } from './recipes/swap-panel.js';
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ /** Aggregate entry. TradeEntry needs @radix-ui/react-dialog; import single recipes from `@bloxwap/hig/react/recipes/<name>` to avoid overlay peers. SwapSheet (Vaul) is only at `recipes/swap-sheet`. */
3
+ export { MarketRow } from './recipes/market-row.js';
4
+ export { BalanceCard } from './recipes/balance-card.js';
5
+ export { TradeEntry } from './recipes/trade-entry.js';
6
+ export { InstallCommand } from './recipes/install-command.js';
7
+ export { CodeWindow } from './recipes/code-window.js';
8
+ export { MarketingHero } from './recipes/marketing-hero.js';
9
+ export { ActivityList } from './recipes/activity-list.js';
10
+ export { FromPicker, ToPicker } from './recipes/pickers.js';
11
+ export { SwapPanel, swapAction } from './recipes/swap-panel.js';
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { ChoicesProps } from './selection.js';
3
+ /** A select-only combobox. DOM focus stays on the trigger while its active option is announced. */
4
+ export declare function Select({ label, options, value, defaultValue, disabled, onValueChange }: ChoicesProps): React.JSX.Element;
@@ -0,0 +1,174 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
4
+ import { useControllable, useHIG } from './provider.js';
5
+ /** A select-only combobox. DOM focus stays on the trigger while its active option is announced. */
6
+ export function Select({ label, options, value, defaultValue, disabled, onValueChange }) {
7
+ const id = useId();
8
+ const { direction, locale } = useHIG();
9
+ const [current, setCurrent] = useControllable(value, defaultValue ?? options.find(option => !option.disabled)?.value ?? '', onValueChange);
10
+ const [open, setOpen] = useState(false);
11
+ const [active, setActive] = useState(-1);
12
+ const trigger = useRef(null);
13
+ const list = useRef(null);
14
+ const search = useRef({ text: '', time: 0 });
15
+ const match = options.findIndex(option => option.value === current);
16
+ const selected = match >= 0 ? match : options.findIndex(option => !option.disabled);
17
+ const expanded = open && !disabled && options.length > 0;
18
+ const activeOption = active >= 0 && !options[active]?.disabled ? options[active] : undefined;
19
+ const optionId = (index) => `${id}-option-${index}`;
20
+ function show(edge) {
21
+ if (disabled || !options.length)
22
+ return;
23
+ // Safari does not focus buttons on pointer activation; the combobox owns keyboard navigation.
24
+ trigger.current?.focus();
25
+ const enabled = options.flatMap((option, index) => option.disabled ? [] : [index]);
26
+ setActive(edge === 'last' ? (enabled.at(-1) ?? -1) : edge === 'first' ? (enabled[0] ?? -1) : selected >= 0 && !options[selected].disabled ? selected : enabled[0] ?? -1);
27
+ setOpen(true);
28
+ search.current = { text: '', time: 0 };
29
+ }
30
+ function choose(index) {
31
+ const option = options[index];
32
+ if (disabled || !option || option.disabled)
33
+ return;
34
+ setCurrent(option.value);
35
+ setOpen(false);
36
+ trigger.current?.focus();
37
+ }
38
+ function move(delta) {
39
+ const enabled = options.flatMap((option, index) => option.disabled ? [] : [index]);
40
+ if (!enabled.length)
41
+ return;
42
+ const position = enabled.indexOf(active);
43
+ setActive(enabled[Math.min(enabled.length - 1, Math.max(0, position + delta))]);
44
+ }
45
+ function onKeyDown(event) {
46
+ if (disabled)
47
+ return;
48
+ if (event.key === 'Escape' && expanded) {
49
+ event.preventDefault();
50
+ event.stopPropagation();
51
+ setOpen(false);
52
+ return;
53
+ }
54
+ if (event.key === 'Tab') {
55
+ setOpen(false);
56
+ return;
57
+ }
58
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
59
+ event.preventDefault();
60
+ if (!expanded)
61
+ show();
62
+ else
63
+ move(event.key === 'ArrowDown' ? 1 : -1);
64
+ return;
65
+ }
66
+ if (event.key === 'Home' || event.key === 'End') {
67
+ event.preventDefault();
68
+ show(event.key === 'Home' ? 'first' : 'last');
69
+ return;
70
+ }
71
+ if (event.key === 'Enter' || (event.key === ' ' && (!search.current.text || Date.now() - search.current.time >= 700))) {
72
+ event.preventDefault();
73
+ if (expanded)
74
+ choose(active);
75
+ else
76
+ show();
77
+ return;
78
+ }
79
+ if (event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey)
80
+ return;
81
+ event.preventDefault();
82
+ const now = Date.now();
83
+ const previous = now - search.current.time < 700 ? search.current.text : '';
84
+ const text = (previous + event.key).toLocaleLowerCase(locale);
85
+ search.current = { text, time: now };
86
+ const query = [...text].every(character => character === text[0]) ? text[0] : text;
87
+ const start = expanded ? active : selected;
88
+ // Multi-character typeahead also considers the active option; repeated letters cycle matches.
89
+ const offset = query.length > 1 ? 0 : 1;
90
+ for (let step = 0; step < options.length; step++) {
91
+ const index = (Math.max(start, 0) + step + offset) % options.length;
92
+ const option = options[index];
93
+ if (!option.disabled && option.label.toLocaleLowerCase(locale).startsWith(query)) {
94
+ if (expanded)
95
+ setActive(index);
96
+ else
97
+ setCurrent(option.value);
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ useLayoutEffect(() => {
103
+ if (!expanded || !trigger.current || !list.current)
104
+ return;
105
+ const popup = list.current;
106
+ const button = trigger.current;
107
+ // The top layer escapes overflow clipping without a portal, preserving host theme and modal ownership.
108
+ popup.showPopover?.();
109
+ const position = () => {
110
+ const rect = button.getBoundingClientRect();
111
+ const gap = 6;
112
+ const inset = 8;
113
+ const viewport = window.visualViewport;
114
+ const width = viewport?.width ?? window.innerWidth;
115
+ const height = viewport?.height ?? window.innerHeight;
116
+ const left = viewport?.offsetLeft ?? 0;
117
+ const top = viewport?.offsetTop ?? 0;
118
+ const below = top + height - rect.bottom - gap - inset;
119
+ const above = rect.top - top - gap - inset;
120
+ const desired = Math.min(320, popup.scrollHeight || 320);
121
+ const upwards = below < desired && above > below;
122
+ const maxHeight = Math.max(0, Math.min(320, upwards ? above : below));
123
+ // The presenting animation settles from the edge nearest the trigger.
124
+ popup.dataset.placement = upwards ? 'top' : 'bottom';
125
+ const popupWidth = Math.min(rect.width, Math.max(0, width - inset * 2));
126
+ popup.style.width = `${popupWidth}px`;
127
+ popup.style.maxHeight = `${maxHeight}px`;
128
+ popup.style.left = `${Math.max(left + inset, Math.min(direction === 'rtl' ? rect.right - popupWidth : rect.left, left + width - popupWidth - inset))}px`;
129
+ popup.style.top = `${upwards ? Math.max(top + inset, rect.top - gap - Math.min(popup.scrollHeight, maxHeight)) : rect.bottom + gap}px`;
130
+ };
131
+ position();
132
+ const resize = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(position);
133
+ resize?.observe(button);
134
+ window.addEventListener('resize', position);
135
+ window.addEventListener('scroll', position, true);
136
+ window.visualViewport?.addEventListener('resize', position);
137
+ window.visualViewport?.addEventListener('scroll', position);
138
+ return () => { resize?.disconnect(); window.removeEventListener('resize', position); window.removeEventListener('scroll', position, true); window.visualViewport?.removeEventListener('resize', position); window.visualViewport?.removeEventListener('scroll', position); };
139
+ }, [expanded, direction, options.length]);
140
+ useEffect(() => {
141
+ if (disabled || !options.length)
142
+ setOpen(false);
143
+ }, [disabled, options.length]);
144
+ useEffect(() => {
145
+ if (!expanded)
146
+ return;
147
+ const outside = (event) => { const target = event.target; if (!trigger.current?.contains(target) && !list.current?.contains(target))
148
+ setOpen(false); };
149
+ // Consume Escape before an enclosing modal's document capture listener can dismiss it too.
150
+ const escape = (event) => { if (event.key === 'Escape') {
151
+ event.preventDefault();
152
+ event.stopPropagation();
153
+ setOpen(false);
154
+ } };
155
+ document.addEventListener('pointerdown', outside);
156
+ window.addEventListener('keydown', escape, true);
157
+ return () => { document.removeEventListener('pointerdown', outside); window.removeEventListener('keydown', escape, true); };
158
+ }, [expanded]);
159
+ useEffect(() => {
160
+ if (!expanded || !activeOption)
161
+ return;
162
+ const option = document.getElementById(optionId(active));
163
+ const popup = list.current;
164
+ if (!option || !popup)
165
+ return;
166
+ // Scroll only the option list: scrollIntoView can unexpectedly move the surrounding page.
167
+ if (option.offsetTop < popup.scrollTop)
168
+ popup.scrollTop = option.offsetTop;
169
+ else if (option.offsetTop + option.offsetHeight > popup.scrollTop + popup.clientHeight)
170
+ popup.scrollTop = option.offsetTop + option.offsetHeight - popup.clientHeight;
171
+ }, [expanded, active, activeOption, id]);
172
+ return _jsxs("div", { className: 'hig-field', children: [_jsx("label", { id: `${id}-label`, htmlFor: id, children: label }), _jsxs("div", { className: 'hig-select', children: [_jsxs("button", { ref: trigger, id: id, type: 'button', role: 'combobox', className: 'hig-input hig-select-trigger', disabled: disabled, "aria-labelledby": `${id}-label`, "aria-haspopup": 'listbox', "aria-expanded": expanded, "aria-controls": expanded ? `${id}-list` : undefined, "aria-activedescendant": expanded && activeOption ? optionId(active) : undefined, onClick: () => expanded ? setOpen(false) : show(), onKeyDown: onKeyDown, onBlur: () => setOpen(false), children: [_jsx("span", { className: 'hig-select-value', children: options[selected]?.label ?? '' }), _jsx("svg", { className: 'hig-select-chevron', "aria-hidden": 'true', viewBox: '0 0 20 20', children: _jsx("path", { d: 'm5 7.5 5 5 5-5' }) })] }), expanded && _jsx("div", { ref: list, id: `${id}-list`, className: 'hig-select-list', role: 'listbox', "aria-labelledby": `${id}-label`, popover: 'manual', onPointerDown: event => event.preventDefault(), children: options.map((option, index) => _jsxs("div", { id: optionId(index), role: 'option', className: 'hig-select-option', "aria-selected": index === selected, "aria-disabled": option.disabled || undefined, "data-active": index === active || undefined, onPointerMove: () => { if (!option.disabled)
173
+ setActive(index); }, onClick: () => choose(index), children: [_jsx("span", { children: option.label }), _jsx("svg", { className: 'hig-select-check', "aria-hidden": 'true', viewBox: '0 0 20 20', children: _jsx("path", { d: 'm4 10 4 4 8-8' }) })] }, option.value)) })] })] });
174
+ }
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ export interface Choice {
3
+ value: string;
4
+ label: string;
5
+ disabled?: boolean;
6
+ }
7
+ interface CheckedProps {
8
+ label: string;
9
+ checked?: boolean;
10
+ defaultChecked?: boolean;
11
+ disabled?: boolean;
12
+ onCheckedChange?: (value: boolean) => void;
13
+ }
14
+ export declare function Checkbox({ label, checked, defaultChecked, disabled, onCheckedChange }: CheckedProps): React.JSX.Element;
15
+ export declare function Switch({ label, checked, defaultChecked, disabled, onCheckedChange }: CheckedProps): React.JSX.Element;
16
+ export interface ChoicesProps {
17
+ label: string;
18
+ options: readonly Choice[];
19
+ value?: string;
20
+ defaultValue?: string;
21
+ disabled?: boolean;
22
+ onValueChange?: (value: string) => void;
23
+ }
24
+ export declare function RadioGroup({ label, options, value, defaultValue, disabled, onValueChange }: ChoicesProps): React.JSX.Element;
25
+ export declare function SegmentedControl({ label, options, value, defaultValue, disabled, onValueChange }: ChoicesProps): React.JSX.Element;
26
+ export interface FilterOption extends Choice {
27
+ icon?: string;
28
+ }
29
+ export interface FilterProps {
30
+ label: string;
31
+ options: readonly FilterOption[];
32
+ value?: string;
33
+ defaultValue?: string;
34
+ disabled?: boolean;
35
+ onValueChange?: (value: string) => void;
36
+ }
37
+ /** One row of filter capsules that scrolls sideways. Single choice with radio semantics; the chosen capsule inverts and a check draws into its circle. */
38
+ export declare function Filter({ label, options, value, defaultValue, disabled, onValueChange }: FilterProps): React.JSX.Element;
39
+ export { Select } from './select.js';
40
+ export { Slider } from './slider.js';
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import { useControllable } from './provider.js';
5
+ export function Checkbox({ label, checked, defaultChecked = false, disabled, onCheckedChange }) { const [value, set] = useControllable(checked, defaultChecked, onCheckedChange); return _jsxs("label", { className: 'hig-choice', children: [_jsx("input", { type: 'checkbox', checked: value, disabled: disabled, onChange: e => set(e.target.checked) }), _jsx("span", { children: label })] }); }
6
+ export function Switch({ label, checked, defaultChecked = false, disabled, onCheckedChange }) { const [value, set] = useControllable(checked, defaultChecked, onCheckedChange); return _jsxs("label", { className: 'hig-choice hig-switch', children: [_jsx("input", { role: 'switch', type: 'checkbox', checked: value, disabled: disabled, onChange: e => set(e.target.checked) }), _jsx("span", { children: label })] }); }
7
+ export function RadioGroup({ label, options, value, defaultValue = '', disabled, onValueChange }) { const name = useId(); const [current, set] = useControllable(value, defaultValue, onValueChange); return _jsxs("fieldset", { className: 'hig-group', disabled: disabled, children: [_jsx("legend", { children: label }), options.map(o => _jsxs("label", { className: 'hig-choice', children: [_jsx("input", { type: 'radio', name: name, value: o.value, checked: current === o.value, disabled: o.disabled, onChange: () => set(o.value) }), _jsx("span", { children: o.label })] }, o.value))] }); }
8
+ export function SegmentedControl({ label, options, value, defaultValue = '', disabled, onValueChange }) {
9
+ const name = useId();
10
+ const [current, set] = useControllable(value, defaultValue, onValueChange);
11
+ const selected = options.findIndex(option => option.value === current);
12
+ return _jsxs("fieldset", { className: 'hig-group hig-segmented-control', disabled: disabled, children: [_jsx("legend", { children: label }), _jsxs("div", { className: 'hig-segments', style: { '--hig-segment-count': Math.max(1, options.length), '--hig-segment-index': selected }, children: [selected >= 0 && _jsx("span", { className: 'hig-segment-indicator', "aria-hidden": 'true', "data-disabled": disabled || options[selected].disabled || undefined }), options.map(o => _jsxs("label", { className: 'hig-segment', children: [_jsx("input", { type: 'radio', name: name, value: o.value, checked: current === o.value, disabled: o.disabled, onChange: () => { if (!disabled && !o.disabled)
13
+ set(o.value); } }), _jsx("span", { children: o.label })] }, o.value))] })] });
14
+ }
15
+ /** One row of filter capsules that scrolls sideways. Single choice with radio semantics; the chosen capsule inverts and a check draws into its circle. */
16
+ export function Filter({ label, options, value, defaultValue = '', disabled, onValueChange }) {
17
+ const name = useId();
18
+ const [current, set] = useControllable(value, defaultValue, onValueChange);
19
+ return _jsx("div", { className: 'hig-filter', role: 'radiogroup', "aria-label": label, "aria-disabled": disabled || undefined, children: options.map(o => _jsxs("label", { className: 'hig-filter-chip', children: [_jsx("input", { type: 'radio', name: name, value: o.value, checked: current === o.value, disabled: disabled || o.disabled, onChange: () => { if (!disabled && !o.disabled)
20
+ set(o.value); } }), _jsxs("span", { className: 'hig-filter-mark', "aria-hidden": 'true', children: [o.icon && _jsx("img", { src: o.icon, alt: '', loading: 'lazy' }), _jsx("svg", { viewBox: '0 0 16 16', focusable: 'false', children: _jsx("path", { pathLength: '1', d: 'm3.75 8.5 2.75 2.75 5.75-6.25' }) })] }), _jsx("span", { children: o.label })] }, o.value)) });
21
+ }
22
+ export { Select } from './select.js';
23
+ export { Slider } from './slider.js';
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ export declare function Slider({ label, value, defaultValue, min, max, step, disabled, onValueChange }: {
3
+ label: string;
4
+ value?: number;
5
+ defaultValue?: number;
6
+ min?: number;
7
+ max?: number;
8
+ step?: number;
9
+ disabled?: boolean;
10
+ onValueChange?: (value: number) => void;
11
+ }): React.JSX.Element;
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import { useControllable } from './provider.js';
5
+ export function Slider({ label, value, defaultValue = 0, min = 0, max = 100, step = 1, disabled, onValueChange }) {
6
+ const id = useId();
7
+ const [current, set] = useControllable(value, defaultValue, onValueChange);
8
+ const fill = max > min ? Math.min(100, Math.max(0, (current - min) / (max - min) * 100)) : 0;
9
+ return _jsxs("div", { className: 'hig-field hig-slider', children: [_jsxs("label", { htmlFor: id, children: [label, ": ", current] }), _jsx("input", { id: id, className: 'hig-range', style: { '--hig-range-fill': `${fill}%` }, type: 'range', min: min, max: max, step: step, disabled: disabled, value: current, onChange: e => set(e.target.valueAsNumber) })] });
10
+ }
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ export type BadgeTone = 'neutral' | 'positive' | 'negative' | 'warning' | 'info';
3
+ export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
4
+ tone?: BadgeTone;
5
+ }
6
+ /** A quiet status label. The host owns announcements and may supply typography or an accessible name. */
7
+ export declare const Badge: React.ForwardRefExoticComponent<BadgeProps & React.RefAttributes<HTMLSpanElement>>;
8
+ /** `note` and `tip` are documentation callout severities: note uses the `info` token role and tip the `positive` role, like info and success. `default` is the neutral variant: a faint `text` tint with the title in `text`. */
9
+ export type AlertSeverity = 'default' | 'info' | 'success' | 'warning' | 'error' | 'note' | 'tip';
10
+ /** Severity tints the fill 10% and colours the title from a token role (info/note → info, success/tip → positive, warning → warning, error → negative; default → 6% of text), with no stroke or glow. The title may be any inline node, such as text with a code span. */
11
+ export declare function Alert({ title, children, severity, action, announce }: React.PropsWithChildren<{
12
+ title: React.ReactNode;
13
+ severity?: AlertSeverity;
14
+ action?: React.ReactNode;
15
+ announce?: boolean;
16
+ }>): React.JSX.Element;
17
+ export declare const Callout: typeof Alert;
18
+ export interface Notice {
19
+ id: string;
20
+ message: string;
21
+ severity: 'info' | 'success' | 'warning' | 'error';
22
+ action?: React.ReactNode;
23
+ }
24
+ /** One notice as a single capsule row: severity symbol on the leading edge, message, optional action, close on the trailing edge. Shared by `Toast` and the Sonner-backed `toast()`; it announces nothing itself. */
25
+ export declare function ToastNotice({ message, severity, action, dismissName, onDismiss }: {
26
+ message: React.ReactNode;
27
+ severity?: Notice['severity'];
28
+ action?: React.ReactNode; /** Accessible name of the close button. */
29
+ dismissName: string;
30
+ onDismiss: () => void;
31
+ }): React.JSX.Element;
32
+ /** Persistent until dismissed; host deduplicates ids, critical messages remain inline. */
33
+ export declare function Toast({ notices, onDismiss, dismissLabel }: {
34
+ notices: readonly Notice[];
35
+ onDismiss: (id: string) => void; /** Dismiss wording inside the close button's accessible name (`messages.dismissNotice`); the button itself draws a close symbol. Defaults to HIGProvider `messages.dismiss`. */
36
+ dismissLabel?: string;
37
+ }): React.JSX.Element;
38
+ export declare function Progress({ label, value, max }: {
39
+ label: string;
40
+ value?: number;
41
+ max?: number;
42
+ }): React.JSX.Element;
43
+ export declare function Spinner({ label }: {
44
+ label?: string;
45
+ }): React.JSX.Element;
46
+ export declare function Skeleton({ label }: {
47
+ label?: string;
48
+ }): React.JSX.Element;
49
+ /** Centred stack: symbol, title, optional description, optional action. Decorative `illustration` replaces the default symbol (same prop as native); `null` omits it. */
50
+ export declare function EmptyState({ title, description, action, illustration }: {
51
+ title: string;
52
+ description?: string;
53
+ action?: React.ReactNode;
54
+ illustration?: React.ReactNode;
55
+ }): React.JSX.Element;
56
+ export declare function Avatar({ name, src }: {
57
+ name: string;
58
+ src?: string;
59
+ }): React.JSX.Element;
60
+ export declare function StatusIndicator({ label, state }: {
61
+ label: string;
62
+ state: 'online' | 'offline' | 'stale';
63
+ }): React.JSX.Element;