@bloxwap/hig 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/README.md +2 -2
  2. package/chart/README.md +13 -2
  3. package/chart/dist/altimeter-burst.d.ts +4 -0
  4. package/chart/dist/altimeter-burst.js +43 -0
  5. package/chart/dist/altimeter-chart.d.ts +52 -0
  6. package/chart/dist/altimeter-chart.js +275 -0
  7. package/chart/dist/altimeter-model.d.ts +43 -0
  8. package/chart/dist/altimeter-model.js +148 -0
  9. package/chart/dist/altimeter-targets.d.ts +33 -0
  10. package/chart/dist/altimeter-targets.js +88 -0
  11. package/chart/dist/bitcoin-price.d.ts +8 -0
  12. package/chart/dist/bitcoin-price.js +41 -0
  13. package/chart/dist/champions-league.d.ts +19 -0
  14. package/chart/dist/champions-league.js +104 -0
  15. package/chart/dist/index.d.ts +6 -0
  16. package/chart/dist/index.js +5 -0
  17. package/chart/dist/outcome-chart.d.ts +37 -0
  18. package/chart/dist/outcome-chart.js +212 -0
  19. package/chart/dist/outcome-model.d.ts +43 -0
  20. package/chart/dist/outcome-model.js +71 -0
  21. package/chart/dist/plus-grid.d.ts +6 -0
  22. package/chart/dist/plus-grid.js +29 -0
  23. package/contracts/README.md +1 -1
  24. package/contracts/dist/avatar.d.ts +68 -0
  25. package/contracts/dist/avatar.js +93 -0
  26. package/contracts/dist/confetti.d.ts +174 -0
  27. package/contracts/dist/confetti.js +138 -0
  28. package/contracts/dist/decimal.d.ts +7 -0
  29. package/contracts/dist/decimal.js +35 -0
  30. package/contracts/dist/index.d.ts +29 -2
  31. package/contracts/dist/index.js +123 -4
  32. package/contracts/dist/invariants.d.ts +17 -0
  33. package/contracts/dist/invariants.js +24 -0
  34. package/contracts/dist/login.d.ts +34 -0
  35. package/contracts/dist/login.js +43 -0
  36. package/contracts/dist/messages.d.ts +57 -3
  37. package/contracts/dist/messages.js +20 -2
  38. package/contracts/dist/number-flow.d.ts +90 -0
  39. package/contracts/dist/number-flow.js +150 -0
  40. package/contracts/dist/qr.d.ts +151 -0
  41. package/contracts/dist/qr.js +581 -0
  42. package/contracts/dist/toast.d.ts +168 -0
  43. package/contracts/dist/toast.js +171 -0
  44. package/feedback/README.md +1 -1
  45. package/feedback/dist/contract.js +1 -1
  46. package/feedback/dist/react.js +2 -4
  47. package/native/README.md +6 -1
  48. package/native/dist/account-block.d.ts +10 -1
  49. package/native/dist/account-block.js +17 -7
  50. package/native/dist/animated-number-model.d.ts +41 -1
  51. package/native/dist/animated-number-model.js +201 -23
  52. package/native/dist/animated-number.d.ts +39 -1
  53. package/native/dist/animated-number.js +164 -17
  54. package/native/dist/announce.d.ts +2 -0
  55. package/native/dist/announce.js +10 -0
  56. package/native/dist/asset-balance-row.d.ts +3 -1
  57. package/native/dist/asset-balance-row.js +15 -4
  58. package/native/dist/assets-block.d.ts +115 -0
  59. package/native/dist/assets-block.js +87 -0
  60. package/native/dist/async-result.d.ts +2 -0
  61. package/native/dist/async-result.js +11 -0
  62. package/native/dist/avatar-frame.d.ts +29 -0
  63. package/native/dist/avatar-frame.js +56 -0
  64. package/native/dist/avatar.d.ts +21 -0
  65. package/native/dist/avatar.js +31 -0
  66. package/native/dist/bar-mark.d.ts +2 -0
  67. package/native/dist/bar-mark.js +4 -2
  68. package/native/dist/bar-pnl.js +2 -1
  69. package/native/dist/blocks.d.ts +9 -2
  70. package/native/dist/blocks.js +8 -1
  71. package/native/dist/brand.js +2 -1
  72. package/native/dist/button.d.ts +7 -2
  73. package/native/dist/button.js +13 -3
  74. package/native/dist/checkbox.js +2 -1
  75. package/native/dist/confetti.d.ts +33 -0
  76. package/native/dist/confetti.js +143 -0
  77. package/native/dist/confirm-block.d.ts +98 -0
  78. package/native/dist/confirm-block.js +48 -0
  79. package/native/dist/data.d.ts +1 -1
  80. package/native/dist/data.js +5 -1
  81. package/native/dist/deposit-block.d.ts +19 -0
  82. package/native/dist/deposit-block.js +17 -0
  83. package/native/dist/explainer-block.d.ts +91 -0
  84. package/native/dist/explainer-block.js +34 -0
  85. package/native/dist/field.d.ts +5 -1
  86. package/native/dist/field.js +27 -6
  87. package/native/dist/gesture-sheet-model.d.ts +50 -0
  88. package/native/dist/gesture-sheet-model.js +105 -0
  89. package/native/dist/gesture-sheet-next.d.ts +82 -0
  90. package/native/dist/gesture-sheet-next.js +315 -0
  91. package/native/dist/gesture-sheet.d.ts +5 -1
  92. package/native/dist/gesture-sheet.js +13 -6
  93. package/native/dist/icons.d.ts +9 -6
  94. package/native/dist/icons.js +25 -24
  95. package/native/dist/language-block.d.ts +10 -1
  96. package/native/dist/language-block.js +11 -4
  97. package/native/dist/list-group.d.ts +3 -1
  98. package/native/dist/list-group.js +26 -13
  99. package/native/dist/login-block.d.ts +4 -0
  100. package/native/dist/login-block.js +22 -0
  101. package/native/dist/manage-position-block.d.ts +8 -1
  102. package/native/dist/manage-position-block.js +7 -2
  103. package/native/dist/market-row.js +19 -8
  104. package/native/dist/navigation.js +5 -3
  105. package/native/dist/number-format.d.ts +6 -0
  106. package/native/dist/number-format.js +9 -0
  107. package/native/dist/pickers.d.ts +8 -0
  108. package/native/dist/pickers.js +3 -3
  109. package/native/dist/position-block.d.ts +5 -5
  110. package/native/dist/preset-group.d.ts +31 -0
  111. package/native/dist/preset-group.js +39 -0
  112. package/native/dist/preset-picker-block.d.ts +107 -0
  113. package/native/dist/preset-picker-block.js +43 -0
  114. package/native/dist/profile-block.d.ts +10 -1
  115. package/native/dist/profile-block.js +8 -3
  116. package/native/dist/provider.d.ts +5 -2
  117. package/native/dist/provider.js +27 -5
  118. package/native/dist/qr-code.d.ts +33 -0
  119. package/native/dist/qr-code.js +29 -0
  120. package/native/dist/radio-group.d.ts +19 -7
  121. package/native/dist/radio-group.js +39 -10
  122. package/native/dist/reward-block.d.ts +10 -7
  123. package/native/dist/reward-block.js +9 -4
  124. package/native/dist/screen-header.d.ts +13 -3
  125. package/native/dist/screen-header.js +12 -4
  126. package/native/dist/select.js +4 -2
  127. package/native/dist/selection.d.ts +2 -1
  128. package/native/dist/selection.js +1 -0
  129. package/native/dist/setting-switch.d.ts +1 -1
  130. package/native/dist/setting-switch.js +7 -3
  131. package/native/dist/slider.js +5 -1
  132. package/native/dist/sound-haptics-block.js +1 -1
  133. package/native/dist/status.d.ts +41 -9
  134. package/native/dist/status.js +34 -17
  135. package/native/dist/sticky-header.js +9 -1
  136. package/native/dist/swap-amount-card.d.ts +57 -0
  137. package/native/dist/swap-amount-card.js +31 -0
  138. package/native/dist/{swap-panel-block.d.ts → swap-block.d.ts} +18 -8
  139. package/native/dist/{swap-panel-block.js → swap-block.js} +63 -35
  140. package/native/dist/swap-parts.d.ts +3 -10
  141. package/native/dist/swap-parts.js +22 -24
  142. package/native/dist/swap-shared.d.ts +2 -2
  143. package/native/dist/swap-shared.js +10 -6
  144. package/native/dist/swap-sheet.d.ts +3 -3
  145. package/native/dist/swap-sheet.js +3 -3
  146. package/native/dist/swap-views.js +1 -1
  147. package/native/dist/target-block.d.ts +7 -1
  148. package/native/dist/target-block.js +13 -6
  149. package/native/dist/toast.d.ts +47 -0
  150. package/native/dist/toast.js +386 -0
  151. package/native/dist/token-action-block.d.ts +11 -2
  152. package/native/dist/token-action-block.js +10 -4
  153. package/native/dist/trade-history-list-block.js +7 -4
  154. package/native/dist/wallet-address-core.js +6 -3
  155. package/native-fonts/README.md +1 -1
  156. package/og-fonts/README.md +1 -1
  157. package/package.json +155 -11
  158. package/react/README.md +3 -1
  159. package/react/dist/animated-number-flow.d.ts +72 -0
  160. package/react/dist/animated-number-flow.js +316 -0
  161. package/react/dist/animated-number-model.d.ts +18 -0
  162. package/react/dist/animated-number-model.js +75 -5
  163. package/react/dist/animated-number.d.ts +45 -1
  164. package/react/dist/animated-number.js +137 -6
  165. package/react/dist/asset-balance-row.d.ts +3 -1
  166. package/react/dist/asset-balance-row.js +10 -4
  167. package/react/dist/async-result.d.ts +2 -0
  168. package/react/dist/async-result.js +11 -0
  169. package/react/dist/avatar.d.ts +25 -0
  170. package/react/dist/avatar.js +50 -0
  171. package/react/dist/blocks/account-block.d.ts +5 -1
  172. package/react/dist/blocks/account-block.js +11 -6
  173. package/react/dist/blocks/assets-block.d.ts +106 -0
  174. package/react/dist/blocks/assets-block.js +135 -0
  175. package/react/dist/blocks/confirm-block.d.ts +91 -0
  176. package/react/dist/blocks/confirm-block.js +31 -0
  177. package/react/dist/blocks/deposit-block.d.ts +19 -0
  178. package/react/dist/blocks/deposit-block.js +15 -0
  179. package/react/dist/blocks/explainer-block.d.ts +80 -0
  180. package/react/dist/blocks/explainer-block.js +20 -0
  181. package/react/dist/blocks/install-command.js +3 -1
  182. package/react/dist/blocks/language-block.d.ts +5 -1
  183. package/react/dist/blocks/language-block.js +4 -3
  184. package/react/dist/blocks/login-block.d.ts +4 -0
  185. package/react/dist/blocks/login-block.js +14 -0
  186. package/react/dist/blocks/manage-position-block.d.ts +3 -1
  187. package/react/dist/blocks/manage-position-block.js +2 -2
  188. package/react/dist/blocks/market-row.js +8 -3
  189. package/react/dist/blocks/notifications-block.d.ts +3 -1
  190. package/react/dist/blocks/notifications-block.js +2 -2
  191. package/react/dist/blocks/pickers.d.ts +9 -0
  192. package/react/dist/blocks/pickers.js +4 -2
  193. package/react/dist/blocks/position-block.d.ts +3 -3
  194. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  195. package/react/dist/blocks/preset-picker-block.js +19 -0
  196. package/react/dist/blocks/profile-block.d.ts +5 -1
  197. package/react/dist/blocks/profile-block.js +12 -13
  198. package/react/dist/blocks/reward-block.d.ts +13 -8
  199. package/react/dist/blocks/reward-block.js +7 -4
  200. package/react/dist/blocks/screen-header.d.ts +10 -2
  201. package/react/dist/blocks/screen-header.js +7 -4
  202. package/react/dist/blocks/setting-switch.js +6 -3
  203. package/react/dist/blocks/signals-block.d.ts +3 -1
  204. package/react/dist/blocks/signals-block.js +4 -3
  205. package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
  206. package/react/dist/blocks/sound-haptics-block.js +2 -2
  207. package/react/dist/blocks/sticky-header.d.ts +14 -4
  208. package/react/dist/blocks/sticky-header.js +68 -8
  209. package/react/dist/blocks/swap/settings.js +2 -1
  210. package/react/dist/blocks/swap/shared.d.ts +22 -22
  211. package/react/dist/blocks/swap/shared.js +30 -28
  212. package/react/dist/blocks/{swap-panel-block.d.ts → swap-block.d.ts} +19 -8
  213. package/react/dist/blocks/swap-block.js +215 -0
  214. package/react/dist/blocks/swap-sheet.d.ts +3 -3
  215. package/react/dist/blocks/swap-sheet.js +3 -3
  216. package/react/dist/blocks/target-block.d.ts +7 -1
  217. package/react/dist/blocks/target-block.js +10 -4
  218. package/react/dist/blocks/token-action-block.d.ts +6 -2
  219. package/react/dist/blocks/token-action-block.js +3 -2
  220. package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
  221. package/react/dist/blocks/trade-history-detail-block.js +2 -2
  222. package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
  223. package/react/dist/blocks/trade-history-list-block.js +7 -4
  224. package/react/dist/blocks.d.ts +8 -2
  225. package/react/dist/blocks.js +7 -1
  226. package/react/dist/brand.js +2 -1
  227. package/react/dist/button.d.ts +9 -3
  228. package/react/dist/button.js +8 -3
  229. package/react/dist/confetti.d.ts +27 -0
  230. package/react/dist/confetti.js +240 -0
  231. package/react/dist/data.js +8 -1
  232. package/react/dist/field.d.ts +6 -1
  233. package/react/dist/field.js +18 -9
  234. package/react/dist/gesture-sheet.d.ts +15 -1
  235. package/react/dist/gesture-sheet.js +53 -8
  236. package/react/dist/list-group.js +11 -7
  237. package/react/dist/navigation.js +11 -3
  238. package/react/dist/overlay.d.ts +1 -4
  239. package/react/dist/overlay.js +1 -3
  240. package/react/dist/popover.d.ts +30 -0
  241. package/react/dist/popover.js +34 -0
  242. package/react/dist/preset-group.d.ts +30 -0
  243. package/react/dist/preset-group.js +13 -0
  244. package/react/dist/provider.d.ts +2 -2
  245. package/react/dist/provider.js +23 -6
  246. package/react/dist/qr-code.d.ts +32 -0
  247. package/react/dist/qr-code.js +28 -0
  248. package/react/dist/select.js +10 -3
  249. package/react/dist/selection.d.ts +13 -5
  250. package/react/dist/selection.js +13 -8
  251. package/react/dist/slider.js +5 -1
  252. package/react/dist/status.d.ts +14 -10
  253. package/react/dist/status.js +17 -9
  254. package/react/dist/styles.css +260 -165
  255. package/react/dist/toast.d.ts +19 -12
  256. package/react/dist/toast.js +29 -7
  257. package/react/dist/wallet-address-core.d.ts +8 -4
  258. package/react/dist/wallet-address-core.js +10 -5
  259. package/tokens/README.md +2 -2
  260. package/tokens/assets/onramps/apple-pay.svg +33 -0
  261. package/tokens/assets/onramps/bank.svg +98 -0
  262. package/tokens/assets/onramps/blink.svg +37 -0
  263. package/tokens/assets/onramps/cashapp.svg +33 -0
  264. package/tokens/assets/onramps/crypto.svg +121 -0
  265. package/tokens/assets/onramps/exchange.svg +105 -0
  266. package/tokens/dist/deposit-icons.d.ts +1 -0
  267. package/tokens/dist/deposit-icons.js +28 -0
  268. package/tokens/dist/index.d.ts +16 -0
  269. package/tokens/dist/index.js +16 -0
  270. package/tokens/dist/manifest.json +8 -0
  271. package/tokens/dist/tokens.css +6 -0
  272. package/react/dist/blocks/swap-panel-block.js +0 -178
@@ -3,19 +3,24 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useId, useRef } from 'react';
4
4
  import * as en from '@bloxwap/hig/contracts/messages';
5
5
  import { useHIG } from './provider.js';
6
- function useButton({ intent = 'primary', busy = false, busyLabel, disabled, fullWidth, suppressFeedback, onClick, children, type = 'button', ...props }, ref, kind) {
6
+ function useButton({ intent = 'primary', busy = false, busyLabel, disabled, fullWidth, suppressFeedback, onClick, children, type = 'button', href, glow, ...props }, ref, kind) {
7
7
  // The provider puts its press layer on the context (see PressDecoration); calling it here keeps the layer out of a lone Button bundle.
8
8
  const context = useHIG();
9
9
  const id = useId();
10
10
  const sequence = useRef(0);
11
11
  const busyText = busyLabel ?? context.messages.busy ?? en.busy;
12
- return _jsxs("button", { ...props, ref: ref, type: type, className: `hig-button ${props.className ?? ''}`, "data-intent": intent, "data-full": fullWidth || undefined, "data-density": context.density, disabled: disabled || busy, "aria-busy": busy || undefined, onClick: e => { e.stopPropagation(); onClick?.(e); if (!e.defaultPrevented && !disabled && !busy && !suppressFeedback) {
12
+ const inert = !!disabled || busy;
13
+ const link = href !== undefined;
14
+ // One element either way. An inert link has no href, so it leaves the tab order like a disabled button, and keeps its link role for assistive technology.
15
+ const Root = (link ? 'a' : 'button');
16
+ return _jsxs(Root, { ...props, ...(link ? inert ? { role: 'link', 'aria-disabled': true } : { href } : { type, disabled: inert }), ref: ref, className: `hig-button ${props.className ?? ''}`, "data-intent": intent, "data-full": fullWidth || undefined, "data-density": context.density, "data-glow": glow || undefined, "aria-busy": busy || undefined, onClick: e => { if (inert)
17
+ return e.preventDefault(); e.stopPropagation(); onClick?.(e); if (!e.defaultPrevented && !suppressFeedback) {
13
18
  try {
14
19
  context.onAccepted?.(id);
15
20
  context.feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent: 'activate', origin: e.detail === 0 ? 'keyboard' : 'pointer' });
16
21
  }
17
22
  catch { /* Optional feedback cannot alter the action. */ }
18
- } }, children: [busy && _jsx("span", { className: 'hig-button-spinner', "aria-hidden": 'true' }), children, busy && busyText ? _jsxs("span", { role: 'status', className: 'hig-busy hig-sr-only', children: [" \u00B7 ", busyText] }) : null, context.drawPress?.(kind, !!disabled || busy)] });
23
+ } }, children: [busy && _jsx("span", { className: 'hig-button-spinner', "aria-hidden": 'true' }), children, busy && busyText ? _jsxs("span", { role: 'status', className: 'hig-busy hig-sr-only', children: [" \u00B7 ", busyText] }) : null, context.drawPress?.(kind, inert)] });
19
24
  }
20
25
  export const Button = forwardRef(function Button(props, ref) { return useButton(props, ref, 'button'); });
21
26
  export const IconButton = forwardRef(function IconButton({ label, children, className, ...props }, ref) { return useButton({ ...props, className: `hig-icon-button ${className ?? ''}`, 'aria-label': label, children: _jsx("span", { "aria-hidden": 'true', children: children }) }, ref, 'icon-button'); });
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { type ConfettiOptions } from '@bloxwap/hig/contracts/confetti';
3
+ export { mirrorConfetti, type ConfettiOptions, type ConfettiShape } from '@bloxwap/hig/contracts/confetti';
4
+ export interface ConfettiFire {
5
+ /** Fires one burst and resolves when it has finished, or at once when nothing is drawn: under reduced motion (unless `disableForReducedMotion` is false), with no pieces, or on a server. Colours and reduced motion come from the most recently mounted `Confetti`, else from the document. */
6
+ (options?: ConfettiOptions): Promise<void>;
7
+ /** Stops every burst now, also one still waiting for its host, removes the canvas and resolves their promises. */
8
+ reset(): void;
9
+ }
10
+ /** Fires a burst of confetti over the viewport. Call it from an event handler or an effect; it needs no `Confetti` to be mounted on web. */
11
+ export declare const confetti: ConfettiFire;
12
+ export interface ConfettiProps {
13
+ /** Fires `options` whenever it is truthy: on mount, and each time it changes to another truthy value. A win count or an order id works. Leave it out to fire only through `confetti()`. */
14
+ trigger?: unknown;
15
+ /** The burst `trigger` fires, or several fired together. Read when `trigger` changes, so it need not be a stable object. */
16
+ options?: ConfettiOptions | readonly ConfettiOptions[];
17
+ }
18
+ /**
19
+ * The confetti host. Mount it once inside HIGProvider: bursts then follow the provider's `reducedMotion`, `primaryColor`
20
+ * and `marketColors`. It draws nothing itself and never renders again for a burst; on web the canvas is added to the
21
+ * document body while pieces fly. With `trigger` it also fires declaratively.
22
+ *
23
+ * HIGProvider reads the system's reduced motion setting in an effect, after the effects of what it holds. So where the
24
+ * system asks for reduced motion, a burst asked for while this host mounts (a truthy `trigger`, or `confetti()` in a mount
25
+ * effect) waits for the one render that follows, and is then drawn only if the provider itself says motion is wanted.
26
+ */
27
+ export declare function Confetti({ trigger, options }: ConfettiProps): React.JSX.Element;
@@ -0,0 +1,240 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { nativeDisplayP3, nativeSrgb } from '@bloxwap/hig/tokens';
5
+ import { CONFETTI_FIRST_TICK, CONFETTI_TICKS_PER_SECOND, confettiBursts, confettiDefaults, confettiFlight, confettiOpacity, confettiSkipped, confettiStarPoints, confettiTravel, createConfettiBurst } from '@bloxwap/hig/contracts/confetti';
6
+ import { useHIG } from './provider.js';
7
+ export { mirrorConfetti } from '@bloxwap/hig/contracts/confetti';
8
+ const hosts = [];
9
+ let layer = null;
10
+ /** The token roles a burst is painted in when the call names no colours: CSS variable, the variable it defaults to, and the token role behind both. */
11
+ const roles = [['--hig-action', '', 'action'], ['--hig-info', '', 'info'], ['--hig-down', '--hig-sell', 'sell'], ['--hig-warning', '', 'warning'], ['--hig-up', '--hig-buy', 'buy']];
12
+ const systemReducedMotion = () => typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
13
+ const wideGamut = () => typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('color', 'color(display-p3 1 1 1)');
14
+ const displayP3 = (hex) => `color(display-p3 ${[1, 3, 5].map(at => Number((parseInt(hex.slice(at, at + 2), 16) / 255).toFixed(4))).join(' ')})`;
15
+ /**
16
+ * The default colours as the canvas can paint them. The `--hig-*` variables already hold `color(display-p3 …)` where the
17
+ * browser supports it, and a provider's `primaryColor` or `marketColors` where one is set. Without the tokens stylesheet
18
+ * the token tables stand in: Display P3 where the browser can parse it, sRGB elsewhere.
19
+ */
20
+ function themeColors(anchor) {
21
+ const style = getComputedStyle(anchor), wide = wideGamut();
22
+ return roles.map(([name, fallback, role]) => style.getPropertyValue(name).trim() || (fallback && style.getPropertyValue(fallback).trim()) || (wide ? displayP3(nativeDisplayP3[role]) : nativeSrgb[role]));
23
+ }
24
+ /** A Display P3 canvas on a screen that can show it, so the token colours keep their full strength; an sRGB canvas elsewhere. */
25
+ function paintContext(canvas) {
26
+ let context = null;
27
+ try {
28
+ if (typeof window.matchMedia === 'function' && window.matchMedia('(color-gamut: p3)').matches)
29
+ context = canvas.getContext('2d', { colorSpace: 'display-p3' });
30
+ }
31
+ catch { /* An engine that rejects the setting paints sRGB. */ }
32
+ try {
33
+ return context ?? canvas.getContext('2d');
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ }
39
+ function measure(current) {
40
+ const root = document.documentElement, width = root.clientWidth || window.innerWidth, height = root.clientHeight || window.innerHeight, ratio = window.devicePixelRatio || 1;
41
+ current.width = width;
42
+ current.height = height;
43
+ current.canvas.width = Math.round(width * ratio);
44
+ current.canvas.height = Math.round(height * ratio);
45
+ // Resizing the canvas resets its state, so the scale is set again: pieces are placed in CSS pixels and painted in device pixels.
46
+ current.context.setTransform(ratio, 0, 0, ratio, 0, 0);
47
+ current.stale = false;
48
+ }
49
+ const resized = () => { if (layer)
50
+ layer.stale = true; };
51
+ function open(zIndex) {
52
+ const canvas = document.createElement('canvas'), context = paintContext(canvas);
53
+ if (!context)
54
+ return null;
55
+ // Decoration: nothing for assistive technology to read.
56
+ canvas.ariaHidden = 'true';
57
+ canvas.dataset.higConfetti = '';
58
+ Object.assign(canvas.style, { position: 'fixed', top: '0', left: '0', width: '100%', height: '100%', pointerEvents: 'none', zIndex: String(zIndex) });
59
+ const current = { canvas, context, runs: [], frame: 0, width: 0, height: 0, stale: true };
60
+ (document.body ?? document.documentElement).appendChild(canvas);
61
+ window.addEventListener('resize', resized);
62
+ return current;
63
+ }
64
+ function close(current) {
65
+ if (layer === current)
66
+ layer = null;
67
+ if (current.frame)
68
+ cancelAnimationFrame(current.frame);
69
+ current.frame = 0;
70
+ window.removeEventListener('resize', resized);
71
+ current.canvas.remove();
72
+ }
73
+ const turn = Math.PI * 2, starPoints = confettiStarPoints;
74
+ const flight = { x: 0, y: 0, ux: 0, uy: 0, vx: 0, vy: 0, wobble: 0 };
75
+ /**
76
+ * One burst at tick `t`. Each piece is its own small convex path, filled on its own as canvas-confetti fills it, which is
77
+ * the cheap case for a canvas. What canvas-confetti repeats for every piece is done once here: the opacity is set once a
78
+ * burst and the fill colour once for each of its colours, with no colour string built or parsed per piece.
79
+ */
80
+ function draw(context, run, t, width, height) {
81
+ const { burst, groups } = run, { physics, origin, colors } = burst, travel = confettiTravel(physics, t), left = origin.x * width, top = origin.y * height, size = physics.size;
82
+ context.globalAlpha = confettiOpacity(physics, t);
83
+ for (let color = 0; color < groups.length; color++) {
84
+ const group = groups[color];
85
+ if (!group.length)
86
+ continue;
87
+ context.fillStyle = colors[color];
88
+ for (let index = 0; index < group.length; index++) {
89
+ const particle = group[index];
90
+ confettiFlight(particle, physics, t, travel, flight);
91
+ const x = left + flight.x, y = top + flight.y;
92
+ context.beginPath();
93
+ if (particle.shape === 'circle')
94
+ context.ellipse(x, y, Math.abs(flight.ux) * 0.6, Math.abs(flight.vy) * 0.6, Math.PI / 10 * flight.wobble, 0, turn);
95
+ else if (particle.shape === 'star') {
96
+ context.moveTo(x + starPoints[0][0] * size, y + starPoints[0][1] * size);
97
+ for (let point = 1; point < 10; point++)
98
+ context.lineTo(x + starPoints[point][0] * size, y + starPoints[point][1] * size);
99
+ }
100
+ else {
101
+ const { ux, uy, vx, vy } = flight;
102
+ context.moveTo(x, y);
103
+ context.lineTo(x + ux, y + uy);
104
+ context.lineTo(x + ux + vx, y + uy + vy);
105
+ context.lineTo(x + vx, y + vy);
106
+ }
107
+ context.closePath();
108
+ context.fill();
109
+ }
110
+ }
111
+ }
112
+ function frame(now) {
113
+ const current = layer;
114
+ if (!current)
115
+ return;
116
+ current.frame = 0;
117
+ if (current.stale)
118
+ measure(current);
119
+ const { context, width, height } = current;
120
+ context.clearRect(0, 0, width, height);
121
+ const runs = current.runs;
122
+ let kept = 0;
123
+ for (let index = 0; index < runs.length; index++) {
124
+ const run = runs[index];
125
+ // Time, not frames, moves a burst: it takes the same time at 60 Hz and 120 Hz, and a dropped frame costs nothing later.
126
+ if (run.start < 0)
127
+ run.start = now;
128
+ const t = CONFETTI_FIRST_TICK + (now - run.start) * CONFETTI_TICKS_PER_SECOND / 1000;
129
+ if (t >= run.burst.physics.ticks)
130
+ run.resolve();
131
+ else {
132
+ draw(context, run, t, width, height);
133
+ runs[kept++] = run;
134
+ }
135
+ }
136
+ runs.length = kept;
137
+ if (kept === 0) {
138
+ close(current);
139
+ return;
140
+ }
141
+ current.frame = requestAnimationFrame(frame);
142
+ }
143
+ function fire(options, host) {
144
+ if (typeof window === 'undefined' || typeof document === 'undefined')
145
+ return Promise.resolve();
146
+ // The host cannot answer for reduced motion yet: the burst waits for it, a moment at most.
147
+ if (host && !host.ready)
148
+ return new Promise(resolve => { if (host.waiting.length >= 8) {
149
+ resolve();
150
+ return;
151
+ } host.waiting.push({ options, resolve }); });
152
+ if (layer && layer.runs.length >= 8)
153
+ return Promise.resolve();
154
+ const reduced = host ? host.reducedMotion() : systemReducedMotion();
155
+ if (confettiSkipped(options, reduced))
156
+ return Promise.resolve();
157
+ const burst = createConfettiBurst(options, () => themeColors(host?.anchor() ?? document.documentElement));
158
+ if (burst.particles.length === 0)
159
+ return Promise.resolve();
160
+ const zIndex = options?.zIndex;
161
+ const current = layer ??= open(typeof zIndex === 'number' && Number.isFinite(zIndex) ? zIndex : confettiDefaults.zIndex);
162
+ // No 2D canvas here: there is nothing to draw on, so the burst is over.
163
+ if (!current)
164
+ return Promise.resolve();
165
+ const groups = burst.colors.map(() => []);
166
+ for (const particle of burst.particles)
167
+ groups[particle.color].push(particle);
168
+ return new Promise(resolve => {
169
+ current.runs.push({ burst, groups, start: -1, resolve });
170
+ if (!current.frame)
171
+ current.frame = requestAnimationFrame(frame);
172
+ });
173
+ }
174
+ function reset() {
175
+ for (const host of hosts)
176
+ for (const wait of host.waiting.splice(0))
177
+ wait.resolve();
178
+ const current = layer;
179
+ if (!current)
180
+ return;
181
+ close(current);
182
+ for (const run of current.runs.splice(0))
183
+ run.resolve();
184
+ }
185
+ /** Fires a burst of confetti over the viewport. Call it from an event handler or an effect; it needs no `Confetti` to be mounted on web. */
186
+ export const confetti = Object.assign((options) => fire(options, hosts[hosts.length - 1]), { reset });
187
+ /**
188
+ * The confetti host. Mount it once inside HIGProvider: bursts then follow the provider's `reducedMotion`, `primaryColor`
189
+ * and `marketColors`. It draws nothing itself and never renders again for a burst; on web the canvas is added to the
190
+ * document body while pieces fly. With `trigger` it also fires declaratively.
191
+ *
192
+ * HIGProvider reads the system's reduced motion setting in an effect, after the effects of what it holds. So where the
193
+ * system asks for reduced motion, a burst asked for while this host mounts (a truthy `trigger`, or `confetti()` in a mount
194
+ * effect) waits for the one render that follows, and is then drawn only if the provider itself says motion is wanted.
195
+ */
196
+ export function Confetti({ trigger, options }) {
197
+ const { reducedMotion } = useHIG();
198
+ const [settled, setSettled] = useState(false);
199
+ const anchor = useRef(null), motion = useRef(reducedMotion), latest = useRef(options), fired = useRef(undefined), self = useRef(null);
200
+ motion.current = reducedMotion;
201
+ latest.current = options;
202
+ // One host for the life of the component, so a burst it holds survives React running the effects twice in development.
203
+ const host = self.current ??= { anchor: () => anchor.current, reducedMotion: () => motion.current === true, ready: false, waiting: [] };
204
+ useEffect(() => {
205
+ hosts.push(host);
206
+ // Without a system request for reduced motion the provider has nothing left to learn. With one, this update is rendered
207
+ // together with the provider's own, and the effect below runs once both are in.
208
+ if (systemReducedMotion())
209
+ setSettled(true);
210
+ else
211
+ host.ready = true;
212
+ return () => {
213
+ const index = hosts.indexOf(host);
214
+ if (index >= 0)
215
+ hosts.splice(index, 1);
216
+ // Only a host that stays out is gone; what it still held is over.
217
+ void Promise.resolve().then(() => { if (!hosts.includes(host))
218
+ for (const wait of host.waiting.splice(0))
219
+ wait.resolve(); });
220
+ };
221
+ }, [host]);
222
+ useEffect(() => {
223
+ if (!settled)
224
+ return;
225
+ host.ready = true;
226
+ for (const wait of host.waiting.splice(0))
227
+ void fire(wait.options, host).then(wait.resolve);
228
+ }, [settled, host]);
229
+ useEffect(() => {
230
+ // Each truthy value fires once, also when React runs the effect twice in development.
231
+ if (Object.is(fired.current, trigger))
232
+ return;
233
+ fired.current = trigger;
234
+ if (!trigger)
235
+ return;
236
+ for (const burst of confettiBursts(latest.current))
237
+ void fire(burst, host);
238
+ }, [trigger, host]);
239
+ return _jsx("span", { ref: anchor, hidden: true, "data-hig-confetti-host": '' });
240
+ }
@@ -1,6 +1,10 @@
1
1
  "use client";
2
2
  import { createElement as _createElement } from "react";
3
3
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { ChevronUp } from '@bloxwap/icons/react/chevron-up';
5
+ import { ChevronDown } from '@bloxwap/icons/react/chevron-down';
6
+ import { ChevronsUpDown } from '@bloxwap/icons/react/chevrons-up-down';
7
+ import { assertUniqueKeys } from '@bloxwap/hig/contracts';
4
8
  import { formatNumber, presentNumberFormat } from '@bloxwap/hig/contracts';
5
9
  import * as en from '@bloxwap/hig/contracts/messages';
6
10
  import { useHIG, useNumberLocale } from './provider.js';
@@ -24,13 +28,16 @@ export function VerticalAddress({ address, kind, rowHeight, className }) {
24
28
  export function Metric({ label, value }) { return _jsxs("dl", { className: 'hig-surface', children: [_jsx("dt", { children: label }), _jsx("dd", { children: value })] }); }
25
29
  export const Stat = Metric;
26
30
  export function List({ items, keyFor, render, empty, label, loading = false, error, onRetry, onLoadMore }) {
31
+ assertUniqueKeys(items, keyFor, 'List');
27
32
  const { messages } = useHIG();
28
33
  return _jsxs("div", { className: 'hig-data-list', "aria-busy": loading, children: [items.length ? _jsx("ul", { className: 'hig-list', "aria-label": label, children: items.map(item => _jsx("li", { children: render(item) }, keyFor(item))) }) : !loading && !error ? _jsx("p", { className: 'hig-list-message', children: empty ?? messages.noItems ?? en.noItems }) : null, loading && _jsx("p", { className: 'hig-list-message', role: 'status', children: messages.loadingItems ?? en.loadingItems }), error && _jsxs("div", { className: 'hig-list-error', role: 'alert', children: [_jsx("p", { className: 'hig-list-message', children: error }), onRetry && _jsx("button", { className: 'hig-button', "data-intent": 'secondary', type: 'button', disabled: loading, onClick: onRetry, children: messages.retry ?? en.retry })] }), onLoadMore && _jsx("button", { className: 'hig-button', "data-intent": 'secondary', type: 'button', disabled: loading, onClick: onLoadMore, children: messages.loadMore ?? en.loadMore })] });
29
34
  }
30
35
  export function Row({ className, ...props }) { return _jsx("div", { ...props, className: `hig-row${className ? ` ${className}` : ''}` }); }
31
36
  function tableRowAttributes(props) { const attributes = { ...props }; delete attributes.children; delete attributes.dangerouslySetInnerHTML; delete attributes.role; return attributes; }
32
37
  export function Table({ caption, rows, columns, keyFor, rowProps, className, style, tableClassName, captionHidden = false, stickyHeader = false, loading = false, state }) {
38
+ assertUniqueKeys(rows, keyFor, 'Table');
39
+ assertUniqueKeys(columns, column => column.key, 'Table columns');
33
40
  const { messages } = useHIG();
34
41
  const status = state !== undefined ? state : loading ? _jsx("span", { role: 'status', children: messages.loading ?? en.loading }) : !rows.length ? messages.noRows ?? en.noRows : null;
35
- return _jsx("div", { className: `hig-table-scroll${className ? ` ${className}` : ''}`, style: style, tabIndex: 0, role: 'region', "aria-label": caption, "aria-busy": loading || undefined, children: _jsxs("table", { className: `hig-table${tableClassName ? ` ${tableClassName}` : ''}`, "data-sticky-header": stickyHeader || undefined, children: [_jsx("caption", { className: captionHidden ? 'hig-sr-only' : undefined, children: caption }), _jsx("thead", { children: _jsx("tr", { children: columns.map(c => _jsx("th", { scope: 'col', "aria-sort": c.sort, style: c.align ? { textAlign: c.align } : undefined, children: c.onSort ? _jsxs("button", { type: 'button', className: 'hig-table-sort', onClick: c.onSort, children: [c.label, _jsxs("svg", { className: 'hig-table-sort-icon', "aria-hidden": 'true', focusable: 'false', width: '14', height: '14', viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round', children: [_jsx("path", { className: 'hig-table-sort-up', d: 'm4.5 6 3.5-3.5L11.5 6' }), _jsx("path", { className: 'hig-table-sort-down', d: 'm4.5 10 3.5 3.5 3.5-3.5' })] })] }) : c.label }, c.key)) }) }), _jsxs("tbody", { children: [rows.map((row, index) => _createElement("tr", { ...tableRowAttributes(rowProps?.(row, index)), key: keyFor(row) }, columns.map(c => _jsx("td", { style: c.align ? { textAlign: c.align } : undefined, children: c.render(row) }, c.key)))), status !== null && status !== false && _jsx("tr", { className: 'hig-table-state', children: _jsx("td", { colSpan: Math.max(1, columns.length), children: status }) })] })] }) });
42
+ return _jsx("div", { className: `hig-table-scroll${className ? ` ${className}` : ''}`, style: style, tabIndex: 0, role: 'region', "aria-label": caption, "aria-busy": loading || undefined, children: _jsxs("table", { className: `hig-table${tableClassName ? ` ${tableClassName}` : ''}`, "data-sticky-header": stickyHeader || undefined, children: [_jsx("caption", { className: captionHidden ? 'hig-sr-only' : undefined, children: caption }), _jsx("thead", { children: _jsx("tr", { children: columns.map(c => _jsx("th", { scope: 'col', "aria-sort": c.sort, style: c.align ? { textAlign: c.align } : undefined, children: c.onSort ? _jsxs("button", { type: 'button', className: 'hig-table-sort', onClick: c.onSort, children: [c.label, (c.sort === 'ascending' ? _jsx(ChevronUp, { size: 14, className: 'hig-table-sort-icon' }) : c.sort === 'descending' ? _jsx(ChevronDown, { size: 14, className: 'hig-table-sort-icon' }) : _jsx(ChevronsUpDown, { size: 14, className: 'hig-table-sort-icon' }))] }) : c.label }, c.key)) }) }), _jsxs("tbody", { children: [rows.map((row, index) => _createElement("tr", { ...tableRowAttributes(rowProps?.(row, index)), key: keyFor(row) }, columns.map(c => _jsx("td", { style: c.align ? { textAlign: c.align } : undefined, children: c.render(row) }, c.key)))), status !== null && status !== false && _jsx("tr", { className: 'hig-table-state', children: _jsx("td", { colSpan: Math.max(1, columns.length), children: status }) })] })] }) });
36
43
  }
@@ -10,7 +10,12 @@ export interface FieldProps {
10
10
  }
11
11
  export declare function Field({ id: provided, label, description, descriptionTone, error, required, disabled, children }: React.PropsWithChildren<FieldProps>): React.JSX.Element;
12
12
  export declare const Label: (props: React.LabelHTMLAttributes<HTMLLabelElement>) => React.JSX.Element;
13
- export declare const Input: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
13
+ export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'prefix'> {
14
+ /** Host text on the leading edge inside the field, before what is typed, such as `@` for a handle or `$` for an amount. Drawn muted and not part of the value; the input names it in its description (`aria-describedby`, before the field's help and error), so it is read after the label. The text starts after it. */
15
+ prefix?: string;
16
+ }
17
+ export declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
18
+ /** Marked pure, as `SearchInput` is, so a bundle that imports only `Input` drops it. */
14
19
  export declare const TextArea: React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> & React.RefAttributes<HTMLTextAreaElement>>;
15
20
  /** The magnifying glass sits inset on the leading edge; the input keeps the ref, class and every prop. Marked pure so a bundle that imports another field drops the icon. */
16
21
  export interface SearchInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { createContext, useContext, useId, useRef, forwardRef } from 'react';
3
+ import { Search } from '@bloxwap/icons/react/search';
4
+ import { X } from '@bloxwap/icons/react/x';
5
+ import { createContext, useContext, useId, useRef, useCallback, useEffect, forwardRef } from 'react';
4
6
  import * as en from '@bloxwap/hig/contracts/messages';
5
7
  import { PressDecoration, useHIG } from './provider.js';
6
8
  const Context = createContext({ id: '' });
@@ -9,23 +11,30 @@ export function Field({ id: provided, label, description, descriptionTone, error
9
11
  const generated = useId();
10
12
  const id = provided ?? generated;
11
13
  const ids = [description && `${id}-help`, error && `${id}-error`].filter(Boolean).join(' ') || undefined;
14
+ const controls = useRef(0);
15
+ const register = useCallback(() => { if (++controls.current > 1)
16
+ throw new Error('Field requires exactly one control.'); return () => { controls.current--; }; }, []);
12
17
  const positive = descriptionTone === 'positive';
13
- return _jsx(Context.Provider, { value: { id, description: ids, invalid: !!error, disabled, required }, children: _jsxs("div", { className: 'hig-field', children: [_jsxs("label", { htmlFor: id, children: [label, required ? ` ${messages.required ?? en.required}` : ''] }), children, description && _jsx("p", { id: `${id}-help`, "data-tone": positive ? 'positive' : undefined, "aria-live": positive ? 'polite' : undefined, children: description }), error && _jsx("p", { id: `${id}-error`, role: 'alert', children: error })] }) });
18
+ return _jsx(Context.Provider, { value: { id, description: ids, invalid: !!error, disabled, required, register }, children: _jsxs("div", { className: 'hig-field', children: [_jsxs("label", { htmlFor: id, children: [label, required ? ` ${messages.required ?? en.required}` : ''] }), children, description && _jsx("p", { id: `${id}-help`, "data-tone": positive ? 'positive' : undefined, "aria-live": positive ? 'polite' : undefined, children: description }), error && _jsx("p", { id: `${id}-error`, role: 'alert', children: error })] }) });
14
19
  }
15
20
  export const Label = (props) => _jsx("label", { ...props });
16
- export const Input = forwardRef(function Input(props, ref) { const field = useContext(Context); return _jsx("input", { id: field.id || undefined, "aria-describedby": field.description, "aria-invalid": field.invalid || undefined, required: field.required, ...props, disabled: !!field.disabled || props.disabled, ref: ref, className: `hig-input ${props.className ?? ''}` }); });
17
- export const TextArea = forwardRef(function TextArea(props, ref) { const field = useContext(Context); return _jsx("textarea", { id: field.id || undefined, "aria-describedby": field.description, "aria-invalid": field.invalid || undefined, required: field.required, ...props, disabled: !!field.disabled || props.disabled, ref: ref, className: `hig-input ${props.className ?? ''}` }); });
21
+ export const Input = forwardRef(function Input({ prefix, ...props }, ref) { const field = useContext(Context); useEffect(() => field.register?.(), [field.register]); const own = useId(); const input = _jsx("input", { ...props, id: field.id || props.id, "aria-describedby": [prefix && own, field.description, props['aria-describedby']].filter(Boolean).join(' ') || undefined, "aria-invalid": field.invalid || props['aria-invalid'], required: field.required || props.required, disabled: !!field.disabled || props.disabled, ref: ref, className: `hig-input ${props.className ?? ''}` }); return prefix ? _jsxs("span", { className: 'hig-input-affix', children: [_jsx("span", { id: own, className: 'hig-input-prefix', children: prefix }), input] }) : input; });
22
+ /** Marked pure, as `SearchInput` is, so a bundle that imports only `Input` drops it. */
23
+ export const TextArea = /* @__PURE__ */ forwardRef(function TextArea(props, ref) { const field = useContext(Context); useEffect(() => field.register?.(), [field.register]); return _jsx("textarea", { ...props, id: field.id || props.id, "aria-describedby": [field.description, props['aria-describedby']].filter(Boolean).join(' ') || undefined, "aria-invalid": field.invalid || props['aria-invalid'], required: field.required || props.required, disabled: !!field.disabled || props.disabled, ref: ref, className: `hig-input ${props.className ?? ''}` }); });
18
24
  export const SearchInput = /* @__PURE__ */ forwardRef(function SearchInput({ trailing, onClear, clearLabel, ...props }, ref) {
19
25
  const { messages } = useHIG();
20
26
  const inner = useRef(null);
21
27
  const off = !!useContext(Context).disabled || !!props.disabled;
22
- const attach = (node) => { inner.current = node; if (typeof ref === 'function')
23
- ref(node);
28
+ const attach = useCallback((node) => { inner.current = node; const cleanup = typeof ref === 'function' ? ref(node) : undefined; if (ref && typeof ref !== 'function')
29
+ ref.current = node; return () => { inner.current = null; if (typeof cleanup === 'function')
30
+ cleanup();
31
+ else if (typeof ref === 'function')
32
+ ref(null);
24
33
  else if (ref)
25
- ref.current = node; };
26
- const clear = onClear && props.value != null && String(props.value) !== '' ? _jsxs("button", { type: 'button', className: 'hig-search-clear', "aria-label": clearLabel ?? messages.clearSearch ?? en.clearSearch, disabled: off, onClick: () => { onClear(); inner.current?.focus(); }, children: [_jsx("svg", { "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 16 16', children: _jsx("path", { d: 'm4 4 8 8m0-8-8 8' }) }), _jsx(PressDecoration, { kind: 'icon-button', disabled: off })] }) : null;
34
+ ref.current = null; }; }, [ref]);
35
+ const clear = onClear && props.value != null && String(props.value) !== '' ? _jsxs("button", { type: 'button', className: 'hig-search-clear', "aria-label": clearLabel ?? messages.clearSearch ?? en.clearSearch, disabled: off, onClick: () => { onClear(); inner.current?.focus(); }, children: [_jsx(X, { size: 16 }), _jsx(PressDecoration, { kind: 'icon-button', disabled: off })] }) : null;
27
36
  const extra = trailing != null && trailing !== false;
28
37
  const end = extra || clear ? _jsxs("span", { className: 'hig-search-trailing', children: [trailing, clear] }) : null;
29
38
  // The end padding stays while the clear button comes and goes, so typed text never reflows.
30
- return _jsxs("span", { className: 'hig-search-input', "data-trailing": extra || onClear ? '' : undefined, children: [_jsxs("svg", { className: 'hig-search-icon', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', children: [_jsx("circle", { cx: '9', cy: '9', r: '5.25' }), _jsx("path", { d: 'm13 13 3.5 3.5' })] }), _jsx(Input, { type: 'search', ...props, ref: onClear ? attach : ref }), end] });
39
+ return _jsxs("span", { className: 'hig-search-input', "data-trailing": extra || onClear ? '' : undefined, children: [_jsx(Search, { size: 20, className: 'hig-search-icon' }), _jsx(Input, { type: 'search', ...props, ref: onClear ? attach : ref }), end] });
31
40
  });
@@ -22,6 +22,8 @@ interface GestureSheetCommonProps extends Omit<DialogProps, 'contentProps'> {
22
22
  handleProps?: GestureSheetHandleProps;
23
23
  handleRef?: React.Ref<HTMLDivElement>;
24
24
  overlayProps?: GestureSheetOverlayProps;
25
+ /** `id` of a heading inside the sheet that names it, such as a block's `headingId`: the sheet is then named by that heading (`aria-labelledby`) and its own `title` is kept for the backend but hidden from assistive technology, so the name is read once. */
26
+ labelledBy?: string;
25
27
  }
26
28
  export type GestureSheetProps = GestureSheetCommonProps & (
27
29
  /** Backend defaults are retained, including autoFocus=false and repositionInputs=true. */
@@ -37,5 +39,17 @@ export type GestureSheetProps = GestureSheetCommonProps & (
37
39
  maxDynamicContentSize?: number;
38
40
  });
39
41
  /** Optional web gesture backend. Install vaul separately; the core overlay entry never imports it. */
40
- export declare function GestureSheet({ open, onOpenChange, title, description, trigger, children, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, closeLabel, backendProps, contentMode, handle, handleProps, handleRef, overlayProps, enableDynamicSizing, maxDynamicContentSize }: GestureSheetProps): React.JSX.Element;
42
+ export declare function GestureSheet({ open, onOpenChange, title, description, trigger, children, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, closeLabel, backendProps, contentMode, handle, handleProps, handleRef, overlayProps, enableDynamicSizing, maxDynamicContentSize, labelledBy }: GestureSheetProps): React.JSX.Element;
43
+ export interface GestureSheetViewProps extends React.HTMLAttributes<HTMLDivElement> {
44
+ /** Names the view. A change swaps the content with the transition. */
45
+ viewKey: string | number;
46
+ }
47
+ /**
48
+ * One view of a sheet that shows several, such as the steps of a flow or the levels of a menu. When `viewKey` changes, the
49
+ * old view fades and shrinks out of the way without holding its space, the new one fades in at its own size, and a
50
+ * content-sized sheet (`enableDynamicSizing`) moves to the new height at the same time. Going deeper and going back look
51
+ * the same, as in Vaul. The first view appears with the sheet, and nothing moves under reduced motion. The outgoing view is
52
+ * inert and hidden from assistive technology while it leaves.
53
+ */
54
+ export declare function GestureSheetView({ viewKey, children, className, ...rest }: GestureSheetViewProps): React.JSX.Element;
41
55
  export {};
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
4
4
  import { Drawer } from 'vaul';
5
5
  import * as en from '@bloxwap/hig/contracts/messages';
6
6
  import { useHIG, useThemeStyle } from './provider.js';
@@ -22,8 +22,11 @@ function useDynamicHeight(open, enabled, reducedMotion, panel, content) {
22
22
  return;
23
23
  let previous = null;
24
24
  const cancel = () => { const current = animation.current; animation.current = null; current?.cancel(); };
25
- const measure = () => {
26
- const next = content.getBoundingClientRect().height, from = animation.current ? card.getBoundingClientRect().height : previous;
25
+ const measure = (entries) => {
26
+ const next = entries?.[0]?.borderBoxSize?.[0]?.blockSize ?? content.getBoundingClientRect().height;
27
+ if (previous !== null && Math.abs(previous - next) < .5)
28
+ return;
29
+ const from = animation.current ? card.getBoundingClientRect().height : previous;
27
30
  previous = next;
28
31
  if (from === null || Math.abs(from - next) < .5)
29
32
  return;
@@ -32,13 +35,13 @@ function useDynamicHeight(open, enabled, reducedMotion, panel, content) {
32
35
  return;
33
36
  }
34
37
  cancel();
35
- const current = card.animate([{ height: `${from}px` }, { height: `${next}px` }], { duration: 200, easing: 'cubic-bezier(.32,.72,0,1)' });
38
+ const current = card.animate([{ height: `${from}px` }, { height: `${next}px` }], { duration: 270, easing: 'cubic-bezier(.26,.08,.25,1)' });
36
39
  animation.current = current;
37
40
  current.onfinish = current.oncancel = () => { if (animation.current === current)
38
41
  animation.current = null; };
39
42
  };
40
43
  const resize = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(measure);
41
- resize?.observe(content);
44
+ resize?.observe(content, { box: 'border-box' });
42
45
  measure();
43
46
  const inline = typeof MutationObserver === 'undefined' ? null : new MutationObserver(() => { if (card.style.height)
44
47
  cancel(); });
@@ -62,7 +65,7 @@ const MOTION_PROPERTIES = ['transform', 'transition', 'transition-property', 'tr
62
65
  const BACKGROUND_PROPERTIES = [...MOTION_PROPERTIES, 'border-radius', 'overflow', 'transform-origin'];
63
66
  const BODY_POSITION = ['position', 'top', 'left', 'right', 'height'];
64
67
  /** Optional web gesture backend. Install vaul separately; the core overlay entry never imports it. */
65
- export function GestureSheet({ open, onOpenChange, title, description, trigger, children, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, closeLabel, backendProps, contentMode = 'default', handle = true, handleProps, handleRef, overlayProps, enableDynamicSizing = false, maxDynamicContentSize }) {
68
+ export function GestureSheet({ open, onOpenChange, title, description, trigger, children, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, closeLabel, backendProps, contentMode = 'default', handle = true, handleProps, handleRef, overlayProps, enableDynamicSizing = false, maxDynamicContentSize, labelledBy }) {
66
69
  if (enableDynamicSizing && Object.entries(backendProps ?? {}).some(([key, value]) => value !== undefined && DYNAMIC_BACKEND.has(key)))
67
70
  throw new Error('Dynamic GestureSheet does not accept Vaul snap-point props.');
68
71
  if (maxDynamicContentSize !== undefined && (!Number.isFinite(maxDynamicContentSize) || maxDynamicContentSize <= 0))
@@ -121,8 +124,50 @@ export function GestureSheet({ open, onOpenChange, title, description, trigger,
121
124
  }
122
125
  onOpenChange(next);
123
126
  };
124
- const body = _jsxs(_Fragment, { children: [handle && _jsx(Drawer.Handle, { ...grip, ref: handleRef, className: ['hig-gesture-handle', handleClass].filter(Boolean).join(' ') }), _jsx(Drawer.Title, { className: titleHidden ? 'hig-sr-only' : undefined, children: title }), description && _jsx(Drawer.Description, { className: descriptionHidden ? 'hig-sr-only' : undefined, children: description }), children, closeButton !== null && _jsx(Drawer.Close, { asChild: true, children: closeButton ?? _jsx(Button, { intent: 'secondary', suppressFeedback: true, children: closeLabel ?? messages.close ?? en.close }) })] });
127
+ const body = _jsxs(_Fragment, { children: [handle && _jsx(Drawer.Handle, { ...grip, ref: handleRef, className: ['hig-gesture-handle', handleClass].filter(Boolean).join(' ') }), _jsx(Drawer.Title, { className: titleHidden || labelledBy ? 'hig-sr-only' : undefined, "aria-hidden": labelledBy ? true : undefined, children: title }), description && _jsx(Drawer.Description, { className: descriptionHidden ? 'hig-sr-only' : undefined, children: description }), children, closeButton !== null && _jsx(Drawer.Close, { asChild: true, children: closeButton ?? _jsx(Button, { intent: 'secondary', suppressFeedback: true, children: closeLabel ?? messages.close ?? en.close }) })] });
125
128
  return _jsxs(Drawer.Root, { ...backend, open: open, onOpenChange: requestOpen, modal: true, onAnimationEnd: next => { if (next === currentOpen.current)
126
- onAnimationEnd?.(next); }, children: [trigger && _jsx(Drawer.Trigger, { asChild: true, children: trigger }), _jsxs(Drawer.Portal, { children: [_jsx(Drawer.Overlay, { ...overlay, ref: backdrop, className: ['hig-backdrop', 'hig-gesture-backdrop', overlayClass].filter(Boolean).join(' '), "data-hig-motion": reducedMotion ? 'reduced' : 'full' }), _jsx(Drawer.Content, { ...content, ...(!description ? { 'aria-describedby': undefined } : {}), ref: setPanel, className: ['hig-gesture-sheet', className].filter(Boolean).join(' '), role: 'dialog', dir: direction, lang: locale, style: { ...themeStyle, ...style, ...(dynamic && maxDynamicContentSize !== undefined && { maxHeight: maxDynamicContentSize }) }, onPointerDownCapture: event => { const restorePanel = snapshotStyles(panel.current, MOTION_PROPERTIES), restoreOverlay = snapshotStyles(backdrop.current, ['opacity', 'transition']), restoreBackground = backend.shouldScaleBackground ? snapshotStyles(document.querySelector('[data-vaul-drawer-wrapper]'), BACKGROUND_PROPERTIES) : () => { }; motion.current = () => { restorePanel(); restoreOverlay(); restoreBackground(); }; onPointerDownCapture?.(event); }, onInteractOutside: event => { if (event.detail.originalEvent.type === 'focusin')
129
+ onAnimationEnd?.(next); }, children: [trigger && _jsx(Drawer.Trigger, { asChild: true, children: trigger }), _jsxs(Drawer.Portal, { children: [_jsx(Drawer.Overlay, { ...overlay, ref: backdrop, className: ['hig-backdrop', 'hig-gesture-backdrop', overlayClass].filter(Boolean).join(' '), "data-hig-motion": reducedMotion ? 'reduced' : 'full' }), _jsx(Drawer.Content, { ...content, ...(!description ? { 'aria-describedby': undefined } : {}), ...(labelledBy ? { 'aria-labelledby': labelledBy } : {}), ref: setPanel, className: ['hig-gesture-sheet', className].filter(Boolean).join(' '), role: 'dialog', dir: direction, lang: locale, style: { ...themeStyle, ...style, ...(dynamic && maxDynamicContentSize !== undefined && { maxHeight: maxDynamicContentSize }) }, onPointerDownCapture: event => { const restorePanel = snapshotStyles(panel.current, MOTION_PROPERTIES), restoreOverlay = snapshotStyles(backdrop.current, ['opacity', 'transition']), restoreBackground = backend.shouldScaleBackground ? snapshotStyles(document.querySelector('[data-vaul-drawer-wrapper]'), BACKGROUND_PROPERTIES) : () => { }; motion.current = () => { restorePanel(); restoreOverlay(); restoreBackground(); }; onPointerDownCapture?.(event); }, onInteractOutside: event => { if (event.detail.originalEvent.type === 'focusin')
127
130
  onFocusOutside?.(event); onInteractOutside?.(event); }, "data-hig-content-mode": contentMode, "data-hig-motion": reducedMotion ? 'reduced' : 'full', "data-hig-dynamic": dynamic ? 'true' : undefined, children: dynamic ? _jsx("div", { ref: setAnatomy, className: 'hig-gesture-dynamic', "data-hig-content-mode": contentMode, children: body }) : body })] })] });
128
131
  }
132
+ // One curve for the height and both views, measured from Vaul's Dynamic Drawer: no spring and no overshoot, a short ease in and a long ease out. The old view leaves in 270ms and the new one arrives in 220ms.
133
+ const VIEW_SWAP = { duration: 270, easing: 'cubic-bezier(.26,.08,.25,1)' };
134
+ const useCommitEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
135
+ /**
136
+ * One view of a sheet that shows several, such as the steps of a flow or the levels of a menu. When `viewKey` changes, the
137
+ * old view fades and shrinks out of the way without holding its space, the new one fades in at its own size, and a
138
+ * content-sized sheet (`enableDynamicSizing`) moves to the new height at the same time. Going deeper and going back look
139
+ * the same, as in Vaul. The first view appears with the sheet, and nothing moves under reduced motion. The outgoing view is
140
+ * inert and hidden from assistive technology while it leaves.
141
+ */
142
+ export function GestureSheetView({ viewKey, children, className, ...rest }) {
143
+ const { reducedMotion } = useHIG();
144
+ const committed = useRef({ key: viewKey, node: children }), enter = useRef(null), exit = useRef(null), mounted = useRef(false);
145
+ const [shown, setShown] = useState(viewKey), [leaving, setLeaving] = useState(null);
146
+ // The children of the view that was last on screen are kept so it can be drawn once more while it leaves.
147
+ if (shown !== viewKey) {
148
+ setShown(viewKey);
149
+ setLeaving(reducedMotion || committed.current.key === viewKey ? null : committed.current);
150
+ }
151
+ useEffect(() => { committed.current = { key: viewKey, node: children }; });
152
+ useCommitEffect(() => {
153
+ if (!mounted.current) {
154
+ mounted.current = true;
155
+ return;
156
+ }
157
+ if (reducedMotion) {
158
+ setLeaving(null);
159
+ return;
160
+ }
161
+ const incoming = enter.current?.animate?.([{ opacity: 0, transform: 'scale(.96)' }, { opacity: 1, transform: 'scale(1)' }], { ...VIEW_SWAP, duration: 220 });
162
+ const out = exit.current?.animate?.([{ opacity: 1, transform: 'scale(1)' }, { opacity: 0, transform: 'scale(.96)' }], { ...VIEW_SWAP, fill: 'forwards' });
163
+ if (!out) {
164
+ setLeaving(null);
165
+ return () => incoming?.cancel();
166
+ }
167
+ const done = () => setLeaving(current => current && current.key !== viewKey ? null : current);
168
+ out.onfinish = done;
169
+ out.oncancel = done;
170
+ return () => { out.onfinish = null; out.oncancel = null; incoming?.cancel(); out.cancel(); };
171
+ }, [viewKey, reducedMotion]);
172
+ return _jsxs("div", { ...rest, className: ['hig-gesture-views', className].filter(Boolean).join(' '), children: [leaving && _jsx("div", { ref: exit, className: 'hig-gesture-view', "data-leaving": '', "aria-hidden": 'true', inert: true, children: leaving.node }, leaving.key), _jsx("div", { ref: enter, className: 'hig-gesture-view', children: children }, viewKey)] });
173
+ }
@@ -1,5 +1,8 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { ArrowUpRight } from '@bloxwap/icons/react/arrow-up-right';
4
+ import { Check } from '@bloxwap/icons/react/check';
5
+ import { ChevronRight } from '@bloxwap/icons/react/chevron-right';
3
6
  import React, { Children, forwardRef, useId, useRef } from 'react';
4
7
  import * as en from '@bloxwap/hig/contracts/messages';
5
8
  import { PressDecoration, useControllable, useHIG } from './provider.js';
@@ -14,10 +17,9 @@ export function ListGroup({ title, titleAccessory, action, intro, children, clas
14
17
  const rows = Children.toArray(children);
15
18
  return _jsxs("section", { ...rest, className: `hig-list-group${className ? ` ${className}` : ''}`, "aria-labelledby": titled ? id : undefined, children: [action ? _jsxs("div", { className: 'hig-list-group-header', children: [heading, _jsxs("button", { type: 'button', className: 'hig-list-group-action', disabled: action.disabled, onClick: action.onSelect, children: [action.label, _jsx(PressDecoration, { kind: 'button', disabled: !!action.disabled })] })] }) : heading, shown(intro) && _jsx("div", { className: 'hig-list-group-intro', children: intro }), (!shown(intro) || rows.length > 0) && _jsx("ul", { className: 'hig-list-group-rows', children: rows.map((child, index) => _jsx("li", { children: child }, React.isValidElement(child) && child.key != null ? child.key : index)) })] });
16
19
  }
17
- const svg = { 'aria-hidden': true, focusable: false, viewBox: '0 0 20 20', width: 20, height: 20, fill: 'none', stroke: 'currentColor', strokeLinecap: 'round', strokeLinejoin: 'round' };
18
- const chevron = _jsx("svg", { className: 'hig-list-row-chevron', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '20', height: '20', fill: 'none', stroke: 'currentColor', strokeWidth: '1.8', strokeLinecap: 'round', strokeLinejoin: 'round', children: _jsx("path", { d: 'm7.5 4.5 5.5 5.5-5.5 5.5' }) });
19
- const external = _jsx("svg", { ...svg, className: 'hig-list-row-chevron', "data-glyph": 'external', strokeWidth: '1.8', children: _jsx("path", { d: 'M6.5 13.5 14 6M8 5.5h6.5V12' }) });
20
- const check = _jsx("svg", { ...svg, className: 'hig-list-row-check', strokeWidth: '2', children: _jsx("path", { d: 'm4.5 10.5 3.5 3.5 7.5-8' }) });
20
+ const chevron = _jsx(ChevronRight, { size: 20, className: 'hig-list-row-chevron' });
21
+ const external = _jsx(ArrowUpRight, { size: 20, className: 'hig-list-row-chevron', "data-glyph": 'external' });
22
+ const check = _jsx(Check, { size: 20, className: 'hig-list-row-check' });
21
23
  /** One row of a `ListGroup`: the label leads; a value, icons, a badge or a control trail. With `onSelect` or `href` the whole row is one target and shows a disclosure chevron; with `checked` or `onCheckedChange` the whole row is a switch; otherwise the row is static, so a control in `trailing` is its only target. The ref reaches the row's element. */
22
24
  export const ListRow = /* @__PURE__ */ forwardRef(function ListRow({ label, description, tone, leading, value, valueLabel, valueTone, trailing, onSelect, href, disabled, selected, busy, busyLabel, disclosure, checked, defaultChecked, onCheckedChange, className, ...rest }, ref) {
23
25
  const { messages } = useHIG();
@@ -28,11 +30,13 @@ export const ListRow = /* @__PURE__ */ forwardRef(function ListRow({ label, desc
28
30
  const toggles = !pressable && (checked !== undefined || defaultChecked !== undefined || onCheckedChange != null);
29
31
  const text = typeof value === 'string' || typeof value === 'number';
30
32
  const busyText = busyLabel ?? messages.busy ?? en.busy;
31
- const name = _jsx("span", { className: 'hig-list-row-label', "data-tone": tone, children: label });
33
+ const labelId = useId();
34
+ // A switch row's input is named by this visible label (aria-labelledby), so the name is drawn and read once.
35
+ const name = _jsx("span", { id: toggles ? labelId : undefined, className: 'hig-list-row-label', "data-tone": tone, children: label });
32
36
  const glyphKind = disclosure ?? (selected !== undefined ? 'none' : 'chevron');
33
37
  const glyph = busy && !toggles ? _jsx("span", { className: 'hig-button-spinner hig-list-row-spinner', "aria-hidden": 'true' }) : selected ? check : pressable ? (glyphKind === 'chevron' ? chevron : glyphKind === 'external' ? external : null) : null;
34
- const swatch = toggles ? _jsxs("label", { className: 'hig-choice hig-switch', children: [_jsx("input", { ref: input, role: 'switch', type: 'checkbox', checked: on, disabled: disabled, "aria-busy": busy || undefined, "aria-describedby": shown(description) ? descriptionId : undefined, onChange: event => { if (!busy)
35
- setOn(event.target.checked); } }), _jsx("span", { children: label })] }) : null;
38
+ const swatch = toggles ? _jsx("label", { className: 'hig-choice hig-switch', children: _jsx("input", { ref: input, role: 'switch', type: 'checkbox', checked: on, disabled: disabled, "aria-busy": busy || undefined, "aria-labelledby": labelId, "aria-describedby": shown(description) ? descriptionId : undefined, onChange: event => { if (!busy)
39
+ setOn(event.target.checked); } }) }) : null;
36
40
  const content = _jsxs(_Fragment, { children: [leading != null && _jsx("span", { className: 'hig-list-row-leading', "aria-hidden": 'true', children: leading }), shown(description) ? _jsxs("span", { className: 'hig-list-row-text', children: [name, _jsx("span", { id: descriptionId, className: 'hig-list-row-description', children: description })] }) : name, value != null && _jsx("span", { className: 'hig-list-row-value', "data-tone": text && valueTone && valueTone !== 'muted' ? valueTone : undefined, children: !text && valueLabel ? _jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": 'true', children: value }), _jsx("span", { className: 'hig-sr-only', children: valueLabel })] }) : value }), (trailing != null || swatch) && _jsxs("span", { className: 'hig-list-row-trailing', children: [trailing, swatch] }), glyph, busy && !toggles && busyText ? _jsxs("span", { role: 'status', className: 'hig-busy hig-sr-only', children: [" \u00B7 ", busyText] }) : null] });
37
41
  const classes = `hig-list-row${className ? ` ${className}` : ''}`;
38
42
  const current = selected ? { 'aria-current': true } : {};