@bloxwap/hig 0.6.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/README.md +2 -2
  2. package/chart/README.md +13 -2
  3. package/chart/dist/altimeter-burst.d.ts +4 -0
  4. package/chart/dist/altimeter-burst.js +43 -0
  5. package/chart/dist/altimeter-chart.d.ts +52 -0
  6. package/chart/dist/altimeter-chart.js +275 -0
  7. package/chart/dist/altimeter-model.d.ts +43 -0
  8. package/chart/dist/altimeter-model.js +148 -0
  9. package/chart/dist/altimeter-targets.d.ts +33 -0
  10. package/chart/dist/altimeter-targets.js +88 -0
  11. package/chart/dist/bitcoin-price.d.ts +8 -0
  12. package/chart/dist/bitcoin-price.js +41 -0
  13. package/chart/dist/champions-league.d.ts +19 -0
  14. package/chart/dist/champions-league.js +104 -0
  15. package/chart/dist/index.d.ts +6 -0
  16. package/chart/dist/index.js +5 -0
  17. package/chart/dist/outcome-chart.d.ts +37 -0
  18. package/chart/dist/outcome-chart.js +212 -0
  19. package/chart/dist/outcome-model.d.ts +43 -0
  20. package/chart/dist/outcome-model.js +71 -0
  21. package/chart/dist/plus-grid.d.ts +6 -0
  22. package/chart/dist/plus-grid.js +29 -0
  23. package/contracts/README.md +1 -1
  24. package/contracts/dist/avatar.d.ts +68 -0
  25. package/contracts/dist/avatar.js +93 -0
  26. package/contracts/dist/confetti.d.ts +174 -0
  27. package/contracts/dist/confetti.js +138 -0
  28. package/contracts/dist/decimal.d.ts +7 -0
  29. package/contracts/dist/decimal.js +35 -0
  30. package/contracts/dist/index.d.ts +45 -2
  31. package/contracts/dist/index.js +145 -4
  32. package/contracts/dist/invariants.d.ts +17 -0
  33. package/contracts/dist/invariants.js +24 -0
  34. package/contracts/dist/messages.d.ts +62 -2
  35. package/contracts/dist/messages.js +22 -2
  36. package/contracts/dist/number-flow.d.ts +90 -0
  37. package/contracts/dist/number-flow.js +150 -0
  38. package/contracts/dist/qr.d.ts +151 -0
  39. package/contracts/dist/qr.js +581 -0
  40. package/contracts/dist/toast.d.ts +168 -0
  41. package/contracts/dist/toast.js +171 -0
  42. package/feedback/README.md +1 -1
  43. package/feedback/dist/contract.js +1 -1
  44. package/feedback/dist/react.js +2 -4
  45. package/native/README.md +6 -1
  46. package/native/dist/account-block.d.ts +62 -7
  47. package/native/dist/account-block.js +54 -11
  48. package/native/dist/animated-number-model.d.ts +47 -1
  49. package/native/dist/animated-number-model.js +248 -21
  50. package/native/dist/animated-number.d.ts +41 -1
  51. package/native/dist/animated-number.js +165 -17
  52. package/native/dist/announce.d.ts +2 -0
  53. package/native/dist/announce.js +10 -0
  54. package/native/dist/asset-balance-row.d.ts +19 -1
  55. package/native/dist/asset-balance-row.js +24 -8
  56. package/native/dist/assets-block.d.ts +115 -0
  57. package/native/dist/assets-block.js +87 -0
  58. package/native/dist/async-result.d.ts +2 -0
  59. package/native/dist/async-result.js +11 -0
  60. package/native/dist/avatar-frame.d.ts +29 -0
  61. package/native/dist/avatar-frame.js +56 -0
  62. package/native/dist/avatar.d.ts +21 -0
  63. package/native/dist/avatar.js +31 -0
  64. package/native/dist/bar-mark.d.ts +16 -2
  65. package/native/dist/bar-mark.js +23 -7
  66. package/native/dist/bar-pnl.js +7 -5
  67. package/native/dist/blocks.d.ts +13 -14
  68. package/native/dist/blocks.js +10 -6
  69. package/native/dist/brand.js +2 -1
  70. package/native/dist/button.d.ts +7 -2
  71. package/native/dist/button.js +16 -4
  72. package/native/dist/checkbox.js +2 -1
  73. package/native/dist/confetti.d.ts +33 -0
  74. package/native/dist/confetti.js +143 -0
  75. package/native/dist/confirm-block.d.ts +98 -0
  76. package/native/dist/confirm-block.js +48 -0
  77. package/native/dist/data.d.ts +1 -1
  78. package/native/dist/data.js +8 -4
  79. package/native/dist/explainer-block.d.ts +91 -0
  80. package/native/dist/explainer-block.js +34 -0
  81. package/native/dist/field.d.ts +19 -5
  82. package/native/dist/field.js +56 -9
  83. package/native/dist/figure.d.ts +23 -0
  84. package/native/dist/figure.js +10 -0
  85. package/native/dist/gesture-sheet-model.d.ts +50 -0
  86. package/native/dist/gesture-sheet-model.js +105 -0
  87. package/native/dist/gesture-sheet-next.d.ts +82 -0
  88. package/native/dist/gesture-sheet-next.js +315 -0
  89. package/native/dist/gesture-sheet.d.ts +5 -1
  90. package/native/dist/gesture-sheet.js +13 -6
  91. package/native/dist/icons.d.ts +9 -6
  92. package/native/dist/icons.js +25 -24
  93. package/native/dist/language-block.d.ts +14 -1
  94. package/native/dist/language-block.js +11 -4
  95. package/native/dist/list-group.d.ts +44 -8
  96. package/native/dist/list-group.js +84 -13
  97. package/native/dist/manage-position-block.d.ts +35 -2
  98. package/native/dist/manage-position-block.js +41 -11
  99. package/native/dist/market-row.d.ts +46 -0
  100. package/native/dist/market-row.js +41 -0
  101. package/native/dist/navigation.js +5 -3
  102. package/native/dist/notifications-block.d.ts +30 -2
  103. package/native/dist/notifications-block.js +16 -8
  104. package/native/dist/number-format.d.ts +6 -0
  105. package/native/dist/number-format.js +9 -0
  106. package/native/dist/pickers.d.ts +32 -2
  107. package/native/dist/pickers.js +17 -9
  108. package/native/dist/position-block.d.ts +66 -10
  109. package/native/dist/position-block.js +45 -11
  110. package/native/dist/preset-group.d.ts +31 -0
  111. package/native/dist/preset-group.js +39 -0
  112. package/native/dist/preset-picker-block.d.ts +107 -0
  113. package/native/dist/preset-picker-block.js +43 -0
  114. package/native/dist/profile-block.d.ts +38 -5
  115. package/native/dist/profile-block.js +31 -6
  116. package/native/dist/provider.d.ts +14 -5
  117. package/native/dist/provider.js +32 -6
  118. package/native/dist/qr-code.d.ts +33 -0
  119. package/native/dist/qr-code.js +29 -0
  120. package/native/dist/radio-group.d.ts +23 -5
  121. package/native/dist/radio-group.js +40 -12
  122. package/native/dist/recipes.d.ts +6 -0
  123. package/native/dist/recipes.js +6 -0
  124. package/native/dist/reward-block.d.ts +55 -13
  125. package/native/dist/reward-block.js +37 -14
  126. package/native/dist/screen-header.d.ts +59 -0
  127. package/native/dist/screen-header.js +37 -0
  128. package/native/dist/select.js +4 -2
  129. package/native/dist/selection.d.ts +3 -2
  130. package/native/dist/selection.js +1 -0
  131. package/native/dist/setting-header.d.ts +2 -8
  132. package/native/dist/setting-header.js +2 -11
  133. package/native/dist/setting-switch.d.ts +15 -2
  134. package/native/dist/setting-switch.js +11 -4
  135. package/native/dist/signals-block.d.ts +26 -2
  136. package/native/dist/signals-block.js +14 -4
  137. package/native/dist/slider.js +5 -1
  138. package/native/dist/sound-haptics-block.d.ts +29 -2
  139. package/native/dist/sound-haptics-block.js +19 -8
  140. package/native/dist/status.d.ts +47 -14
  141. package/native/dist/status.js +39 -22
  142. package/native/dist/sticky-header.d.ts +28 -0
  143. package/native/dist/sticky-header.js +29 -0
  144. package/native/dist/surface.d.ts +3 -1
  145. package/native/dist/surface.js +2 -1
  146. package/native/dist/swap-amount-card.d.ts +57 -0
  147. package/native/dist/swap-amount-card.js +31 -0
  148. package/native/dist/swap-panel-block.d.ts +11 -4
  149. package/native/dist/swap-panel-block.js +67 -38
  150. package/native/dist/swap-parts.d.ts +5 -10
  151. package/native/dist/swap-parts.js +22 -24
  152. package/native/dist/swap-shared.d.ts +8 -2
  153. package/native/dist/swap-shared.js +10 -6
  154. package/native/dist/swap-views.js +6 -4
  155. package/native/dist/switch-row.d.ts +3 -2
  156. package/native/dist/switch-row.js +5 -3
  157. package/native/dist/switch.d.ts +4 -2
  158. package/native/dist/switch.js +3 -3
  159. package/native/dist/target-block.d.ts +40 -7
  160. package/native/dist/target-block.js +31 -11
  161. package/native/dist/toast.d.ts +47 -0
  162. package/native/dist/toast.js +386 -0
  163. package/native/dist/token-action-block.d.ts +26 -9
  164. package/native/dist/token-action-block.js +21 -8
  165. package/native/dist/trade-history-detail-block.d.ts +26 -1
  166. package/native/dist/trade-history-detail-block.js +17 -9
  167. package/native/dist/trade-history-list-block.d.ts +71 -5
  168. package/native/dist/trade-history-list-block.js +55 -17
  169. package/native/dist/wallet-address-core.d.ts +25 -0
  170. package/native/dist/wallet-address-core.js +34 -0
  171. package/native/dist/wallet-address.d.ts +6 -10
  172. package/native/dist/wallet-address.js +16 -20
  173. package/native-fonts/README.md +1 -1
  174. package/og-fonts/README.md +1 -1
  175. package/package.json +131 -2
  176. package/react/README.md +3 -1
  177. package/react/dist/animated-number-flow.d.ts +72 -0
  178. package/react/dist/animated-number-flow.js +316 -0
  179. package/react/dist/animated-number-model.d.ts +24 -0
  180. package/react/dist/animated-number-model.js +106 -3
  181. package/react/dist/animated-number.d.ts +49 -1
  182. package/react/dist/animated-number.js +146 -11
  183. package/react/dist/asset-balance-row.d.ts +19 -1
  184. package/react/dist/asset-balance-row.js +17 -3
  185. package/react/dist/async-result.d.ts +2 -0
  186. package/react/dist/async-result.js +11 -0
  187. package/react/dist/avatar.d.ts +25 -0
  188. package/react/dist/avatar.js +50 -0
  189. package/react/dist/bar-mark.d.ts +5 -2
  190. package/react/dist/bar-mark.js +5 -3
  191. package/react/dist/blocks/account-block.d.ts +57 -7
  192. package/react/dist/blocks/account-block.js +51 -11
  193. package/react/dist/blocks/assets-block.d.ts +106 -0
  194. package/react/dist/blocks/assets-block.js +135 -0
  195. package/react/dist/blocks/confirm-block.d.ts +91 -0
  196. package/react/dist/blocks/confirm-block.js +31 -0
  197. package/react/dist/blocks/explainer-block.d.ts +80 -0
  198. package/react/dist/blocks/explainer-block.js +20 -0
  199. package/react/dist/blocks/install-command.js +3 -1
  200. package/react/dist/blocks/language-block.d.ts +9 -1
  201. package/react/dist/blocks/language-block.js +8 -6
  202. package/react/dist/blocks/manage-position-block.d.ts +30 -2
  203. package/react/dist/blocks/manage-position-block.js +23 -4
  204. package/react/dist/blocks/market-row.d.ts +20 -9
  205. package/react/dist/blocks/market-row.js +17 -4
  206. package/react/dist/blocks/notifications-block.d.ts +27 -2
  207. package/react/dist/blocks/notifications-block.js +11 -2
  208. package/react/dist/blocks/pickers.d.ts +30 -1
  209. package/react/dist/blocks/pickers.js +32 -10
  210. package/react/dist/blocks/position-block.d.ts +34 -11
  211. package/react/dist/blocks/position-block.js +16 -5
  212. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  213. package/react/dist/blocks/preset-picker-block.js +19 -0
  214. package/react/dist/blocks/profile-block.d.ts +33 -6
  215. package/react/dist/blocks/profile-block.js +31 -6
  216. package/react/dist/blocks/reward-block.d.ts +65 -21
  217. package/react/dist/blocks/reward-block.js +24 -11
  218. package/react/dist/blocks/screen-header.d.ts +34 -2
  219. package/react/dist/blocks/screen-header.js +17 -6
  220. package/react/dist/blocks/setting-switch.d.ts +14 -1
  221. package/react/dist/blocks/setting-switch.js +11 -4
  222. package/react/dist/blocks/signals-block.d.ts +23 -2
  223. package/react/dist/blocks/signals-block.js +6 -5
  224. package/react/dist/blocks/sound-haptics-block.d.ts +27 -3
  225. package/react/dist/blocks/sound-haptics-block.js +11 -7
  226. package/react/dist/blocks/sticky-header.d.ts +19 -0
  227. package/react/dist/blocks/sticky-header.js +103 -0
  228. package/react/dist/blocks/swap/amount-card.js +2 -1
  229. package/react/dist/blocks/swap/settings.js +4 -3
  230. package/react/dist/blocks/swap/shared.d.ts +29 -23
  231. package/react/dist/blocks/swap/shared.js +36 -32
  232. package/react/dist/blocks/swap-panel-block.d.ts +12 -3
  233. package/react/dist/blocks/swap-panel-block.js +72 -37
  234. package/react/dist/blocks/target-block.d.ts +35 -7
  235. package/react/dist/blocks/target-block.js +26 -12
  236. package/react/dist/blocks/token-action-block.d.ts +21 -8
  237. package/react/dist/blocks/token-action-block.js +9 -6
  238. package/react/dist/blocks/trade-history-detail-block.d.ts +23 -1
  239. package/react/dist/blocks/trade-history-detail-block.js +5 -4
  240. package/react/dist/blocks/trade-history-list-block.d.ts +31 -5
  241. package/react/dist/blocks/trade-history-list-block.js +20 -10
  242. package/react/dist/blocks.d.ts +12 -8
  243. package/react/dist/blocks.js +6 -2
  244. package/react/dist/brand.js +2 -1
  245. package/react/dist/button.d.ts +9 -3
  246. package/react/dist/button.js +12 -5
  247. package/react/dist/confetti.d.ts +27 -0
  248. package/react/dist/confetti.js +240 -0
  249. package/react/dist/data.js +11 -4
  250. package/react/dist/field.d.ts +20 -5
  251. package/react/dist/field.js +30 -8
  252. package/react/dist/figure.d.ts +23 -0
  253. package/react/dist/figure.js +12 -0
  254. package/react/dist/gesture-sheet.d.ts +15 -1
  255. package/react/dist/gesture-sheet.js +53 -8
  256. package/react/dist/list-group.d.ts +41 -8
  257. package/react/dist/list-group.js +49 -13
  258. package/react/dist/navigation.js +11 -3
  259. package/react/dist/overlay.d.ts +28 -3
  260. package/react/dist/overlay.js +29 -3
  261. package/react/dist/preset-group.d.ts +30 -0
  262. package/react/dist/preset-group.js +13 -0
  263. package/react/dist/provider.d.ts +42 -5
  264. package/react/dist/provider.js +84 -10
  265. package/react/dist/qr-code.d.ts +32 -0
  266. package/react/dist/qr-code.js +28 -0
  267. package/react/dist/select.js +10 -3
  268. package/react/dist/selection.d.ts +18 -4
  269. package/react/dist/selection.js +20 -10
  270. package/react/dist/slider.js +5 -1
  271. package/react/dist/status.d.ts +14 -10
  272. package/react/dist/status.js +17 -9
  273. package/react/dist/styles.css +380 -150
  274. package/react/dist/surface.d.ts +5 -1
  275. package/react/dist/surface.js +1 -1
  276. package/react/dist/toast.d.ts +19 -12
  277. package/react/dist/toast.js +29 -7
  278. package/react/dist/wallet-address-core.d.ts +27 -0
  279. package/react/dist/wallet-address-core.js +29 -0
  280. package/react/dist/wallet-address.d.ts +6 -12
  281. package/react/dist/wallet-address.js +5 -16
  282. package/tokens/README.md +2 -2
  283. package/tokens/dist/index.d.ts +16 -0
  284. package/tokens/dist/index.js +16 -0
  285. package/tokens/dist/manifest.json +8 -0
  286. package/tokens/dist/tokens.css +6 -0
@@ -0,0 +1,71 @@
1
+ // Geometry for OutcomeChart: each outcome's chance on a 0 to 100% ladder, and the capsules the trails end in.
2
+ /** The most outcomes drawn; later ones are dropped. */
3
+ export const OUTCOME_LIMIT = 10;
4
+ /** Default line and capsule colors, in order. Each reads on the dark chart background (4.5:1 or better on #0a0a0a). */
5
+ export const outcomeColors = ['#e5a445', '#6b9a3c', '#4f8fe0', '#c8643c', '#d0554f', '#8279d9', '#8a8880', '#3fa7a0', '#d873b0', '#d9c24a'];
6
+ /** An outcome's price as a chance from 0 to 1, or `null` while unknown. */
7
+ export function outcomeChance(price) { return price == null || !Number.isFinite(price) ? null : Math.min(1, Math.max(0, price)); }
8
+ /** The whole ladder: 0 to 100% with a tick every ten percent. */
9
+ export const fullScale = { low: 0, high: 1, step: .1 };
10
+ const STEPS = [.01, .02, .05, .1];
11
+ /**
12
+ * The ladder for these chances: the range they occupy plus a tenth of it on each side, on the finest of 1, 2, 5 or
13
+ * 10 percent steps that needs no more than twelve, and never fewer than four. Unknown chances are ignored; with none
14
+ * known it is the whole ladder. The `previous` scale is kept while every chance stays inside it, unless the chances
15
+ * have closed in to a third of it or less, so the ladder holds still while chances move.
16
+ */
17
+ export function outcomeScale(chances, previous) {
18
+ const known = chances.filter((chance) => chance != null);
19
+ if (known.length === 0)
20
+ return previous ?? fullScale;
21
+ const least = Math.min(...known), most = Math.max(...known), margin = Math.max(.002, (most - least) * .1), from = Math.max(0, least - margin), to = Math.min(1, most + margin);
22
+ let step = .1, first = 0, last = 10;
23
+ for (const candidate of STEPS) {
24
+ const units = Math.round(1 / candidate);
25
+ let low = Math.floor(from / candidate + 1e-9), high = Math.ceil(to / candidate - 1e-9);
26
+ while (high - low < 4) {
27
+ if (low > 0)
28
+ low--;
29
+ if (high - low < 4 && high < units)
30
+ high++;
31
+ }
32
+ if (high - low <= 12) {
33
+ step = candidate;
34
+ first = low;
35
+ last = high;
36
+ break;
37
+ }
38
+ }
39
+ const round = (value) => +value.toFixed(6), fresh = { low: round(first * step), high: round(last * step), step };
40
+ return previous && least >= previous.low && most <= previous.high && (fresh.high - fresh.low) * 3 > previous.high - previous.low ? previous : fresh;
41
+ }
42
+ /** The ladder's ticks, from the top of the scale down. */
43
+ export function outcomeTicks(scale = fullScale) {
44
+ const count = Math.round((scale.high - scale.low) / scale.step);
45
+ return Array.from({ length: count + 1 }, (_, index) => +(scale.high - index * scale.step).toFixed(6));
46
+ }
47
+ /** Vertical position of a chance: the top of the scale sits `inset` below the top and its bottom `inset` above the bottom. Chances outside the scale stay on its edge. */
48
+ export function outcomeY(chance, height, inset, scale = fullScale) {
49
+ const share = Math.min(1, Math.max(0, (scale.high - chance) / (scale.high - scale.low)));
50
+ return inset + share * (height - 2 * inset);
51
+ }
52
+ /**
53
+ * Centers for capsules of `size` that want to sit at `wanted` but may not overlap: neighbors keep `gap` between
54
+ * them and all stay inside `height`; when they cannot all fit with the gap, the gap shrinks. Returned in the order given.
55
+ * `preserveOrder` keeps the input sequence instead of sorting by desired position, for stable target-label stacks.
56
+ */
57
+ export function capsuleCenters(wanted, height, size = 36, gap = 6, preserveOrder = false) {
58
+ const order = wanted.map((_, index) => index), placed = [];
59
+ if (!preserveOrder)
60
+ order.sort((a, b) => wanted[a] - wanted[b]);
61
+ // A crowded chart gives up the gap before any capsule leaves it.
62
+ const step = order.length > 1 ? Math.min(size + gap, (height - size) / (order.length - 1)) : size + gap;
63
+ for (const [rank, index] of order.entries())
64
+ placed[rank] = Math.max(wanted[index], rank ? placed[rank - 1] + step : size / 2);
65
+ for (let rank = order.length - 1; rank >= 0; rank--)
66
+ placed[rank] = Math.min(placed[rank], rank === order.length - 1 ? height - size / 2 : placed[rank + 1] - step);
67
+ const centers = [];
68
+ for (const [rank, index] of order.entries())
69
+ centers[index] = placed[rank];
70
+ return centers;
71
+ }
@@ -0,0 +1,6 @@
1
+ /** The mono face as the page loads it (a font loader's variable, else the family name), for DOM text. */
2
+ export declare const monoFont: string;
3
+ /** The mono face by name, for a canvas before the page's own font stack is read. */
4
+ export declare const monoFallback: string;
5
+ /** Strokes plus marks on 50px columns. `phase` in (-50, 0] shifts them left. Rows are 50px apart unless `rows` names their vertical centers. */
6
+ export declare function drawPlusGrid(ctx: CanvasRenderingContext2D, width: number, height: number, phase: number, color: string, rows?: readonly number[]): void;
@@ -0,0 +1,29 @@
1
+ import { tokens } from '@bloxwap/hig/tokens';
2
+ import { ALTIMETER_FLOW_PX, ALTIMETER_MARK_ARM } from './altimeter-model.js';
3
+ /** The mono face as the page loads it (a font loader's variable, else the family name), for DOM text. */
4
+ export const monoFont = `var(--hig-font-mono, "${tokens.font.mono.family}", ${tokens.font.mono.fallback.join(', ')})`;
5
+ /** The mono face by name, for a canvas before the page's own font stack is read. */
6
+ export const monoFallback = `"${tokens.font.mono.family}", ${tokens.font.mono.fallback.join(', ')}`;
7
+ /** Strokes plus marks on 50px columns. `phase` in (-50, 0] shifts them left. Rows are 50px apart unless `rows` names their vertical centers. */
8
+ export function drawPlusGrid(ctx, width, height, phase, color, rows) {
9
+ const half = ALTIMETER_FLOW_PX / 2, arm = ALTIMETER_MARK_ARM;
10
+ let centers = rows;
11
+ if (!centers) {
12
+ const tiled = [];
13
+ for (let y = half; y < height + arm; y += ALTIMETER_FLOW_PX)
14
+ tiled.push(y);
15
+ centers = tiled;
16
+ }
17
+ ctx.lineCap = 'round';
18
+ ctx.beginPath();
19
+ for (let x = phase + half; x < width + arm; x += ALTIMETER_FLOW_PX)
20
+ for (const y of centers) {
21
+ ctx.moveTo(x - arm, y);
22
+ ctx.lineTo(x + arm, y);
23
+ ctx.moveTo(x, y - arm);
24
+ ctx.lineTo(x, y + arm);
25
+ }
26
+ ctx.strokeStyle = color;
27
+ ctx.lineWidth = 1;
28
+ ctx.stroke();
29
+ }
@@ -1,3 +1,3 @@
1
1
  # @bloxwap/hig/contracts
2
2
 
3
- Version 0.6.0, an entry of `@bloxwap/hig`. See the HIG architecture and platform limitations before adoption.
3
+ Version 0.8.1, an entry of `@bloxwap/hig`. See the HIG architecture and platform limitations before adoption.
@@ -0,0 +1,68 @@
1
+ /** Side of the square the face is drawn in. Every length in a `BeamAvatar` is in these units; renderers scale it with a `0 0 36 36` view box. */
2
+ export declare const beamSize = 36;
3
+ /** The eyes: two rounded bars at `leftEyeX` and `rightEyeX`. */
4
+ export declare const beamEye: {
5
+ readonly y: 14;
6
+ readonly width: 1.5;
7
+ readonly height: 2;
8
+ readonly radius: 1;
9
+ };
10
+ /** Which ink reads on a colour: `dark` on a bright colour, `light` on a deep one. */
11
+ export type BeamInk = 'dark' | 'light';
12
+ /** The two inks a face may be drawn in. */
13
+ export interface BeamInks {
14
+ dark: string;
15
+ light: string;
16
+ }
17
+ /** boring-avatars' own inks. Renderers pass the provider's background and text roles instead. */
18
+ export declare const beamInks: BeamInks;
19
+ /** Token roles of the default face palette, in this order. The order and the number of colours decide which colours a seed lands on. */
20
+ export declare const avatarColorRoles: readonly ['action', 'info', 'negative', 'warning'];
21
+ /** A `size` an avatar can be drawn at: a finite number of zero or more. Anything else (NaN, a negative, Infinity, or a value that is not a number from untyped code) is undefined, and the avatar keeps its default size. */
22
+ export declare function avatarSide(size: unknown): number | undefined;
23
+ /** The initials of `name`: its first two UTF-16 units, as Avatar has always drawn them, and the second half of a character that this cut would split (an emoji after one letter), so no half character is drawn. */
24
+ export declare function avatarInitials(name: string): string;
25
+ /** A generated face: what to paint and where, with no platform types. */
26
+ export interface BeamAvatar {
27
+ /** Position in the palette of the backdrop colour. */
28
+ backgroundIndex: number;
29
+ /** Position in the palette of the wrapper colour. */
30
+ wrapperIndex: number;
31
+ /** The backdrop: the whole square. */
32
+ backgroundColor: string;
33
+ /** The wrapper: the tilted shape the face sits on. */
34
+ wrapperColor: string;
35
+ /** Which ink reads on the wrapper colour. */
36
+ ink: BeamInk;
37
+ /** The eyes and mouth: `inks[ink]`. */
38
+ faceColor: string;
39
+ /** SVG transform of the wrapper, a `beamSize` square at the origin. */
40
+ wrapperTransform: string;
41
+ /** Corner radius of the wrapper: `beamSize` makes it a disc, `beamSize / 6` a rounded square. */
42
+ wrapperRadius: number;
43
+ /** SVG transform of the group that holds the eyes and mouth. */
44
+ faceTransform: string;
45
+ /** SVG path of the mouth. */
46
+ mouthPath: string;
47
+ /** True: the mouth is a line, stroked one unit wide with round caps and no fill. False: it is a filled shape with no stroke. */
48
+ mouthStroked: boolean;
49
+ /** Left edge of the left eye. */
50
+ leftEyeX: number;
51
+ /** Left edge of the right eye. */
52
+ rightEyeX: number;
53
+ }
54
+ /** boring-avatars' string hash: a 32-bit rolling hash of the UTF-16 code units, made positive. It is case-sensitive, so pass an address in one casing. */
55
+ export declare function beamHash(seed: string): number;
56
+ /**
57
+ * The ink that reads on `color`, by boring-avatars' rule: `dark` when the colour's YIQ brightness is 128 or more, otherwise `light`.
58
+ * A six-digit hex colour gets the answer boring-avatars gives. A colour this cannot read (a CSS variable, a colour name) gets `dark`,
59
+ * because avatar palettes are bright; boring-avatars itself draws white there.
60
+ */
61
+ export declare function beamInk(color: string): BeamInk;
62
+ /**
63
+ * The face for `seed` in `colors`: the same seed and palette always give the same description, on every platform.
64
+ * `colors` is the palette, in order; its length decides which positions a seed lands on, so a host keeps its faces by keeping its palette.
65
+ * `inks` are the two colours the eyes and mouth may take; the wrapper colour chooses between them (`beamInk`).
66
+ * An empty palette gives empty colours at position 0; renderers substitute their default palette before calling.
67
+ */
68
+ export declare function beamAvatar(seed: string, colors: readonly string[], inks?: BeamInks): BeamAvatar;
@@ -0,0 +1,93 @@
1
+ // The generated avatar face, as plain arithmetic shared by the web and native renderers so both draw the same face for a seed.
2
+ // The geometry is the "beam" variant of boring-avatars 2.0.4 (MIT, https://boringavatars.com): the same seed and palette give the
3
+ // same shapes and the same palette positions, so a host that moves from that package keeps its faces.
4
+ /** Side of the square the face is drawn in. Every length in a `BeamAvatar` is in these units; renderers scale it with a `0 0 36 36` view box. */
5
+ export const beamSize = 36;
6
+ /** The eyes: two rounded bars at `leftEyeX` and `rightEyeX`. */
7
+ export const beamEye = { y: 14, width: 1.5, height: 2, radius: 1 };
8
+ /** boring-avatars' own inks. Renderers pass the provider's background and text roles instead. */
9
+ export const beamInks = { dark: '#000000', light: '#FFFFFF' };
10
+ /** Token roles of the default face palette, in this order. The order and the number of colours decide which colours a seed lands on. */
11
+ export const avatarColorRoles = ['action', 'info', 'negative', 'warning'];
12
+ /** A `size` an avatar can be drawn at: a finite number of zero or more. Anything else (NaN, a negative, Infinity, or a value that is not a number from untyped code) is undefined, and the avatar keeps its default size. */
13
+ export function avatarSide(size) { return typeof size === 'number' && Number.isFinite(size) && size >= 0 ? size : undefined; }
14
+ /** The initials of `name`: its first two UTF-16 units, as Avatar has always drawn them, and the second half of a character that this cut would split (an emoji after one letter), so no half character is drawn. */
15
+ export function avatarInitials(name) {
16
+ const high = name.charCodeAt(1), low = name.charCodeAt(2);
17
+ return name.slice(0, high >= 0xd800 && high <= 0xdbff && low >= 0xdc00 && low <= 0xdfff ? 3 : 2);
18
+ }
19
+ /** boring-avatars' string hash: a 32-bit rolling hash of the UTF-16 code units, made positive. It is case-sensitive, so pass an address in one casing. */
20
+ export function beamHash(seed) {
21
+ let hash = 0;
22
+ for (let index = 0; index < seed.length; index++) {
23
+ hash = (hash << 5) - hash + seed.charCodeAt(index);
24
+ hash = hash & hash;
25
+ }
26
+ return Math.abs(hash);
27
+ }
28
+ const digit = (value, place) => Math.floor(value / Math.pow(10, place) % 10);
29
+ const even = (value, place) => digit(value, place) % 2 === 0;
30
+ /** `value % range`, negated when the decimal digit at `place` is even. A zero stays a plain zero, so descriptions compare equal. */
31
+ function unit(value, range, place) { const rest = value % range; return place && rest !== 0 && even(value, place) ? -rest : rest; }
32
+ const channel = (text, scale) => text.endsWith('%') ? parseFloat(text) * 2.55 : parseFloat(text) * scale;
33
+ /** Red, green and blue (0–255) of `#rgb`, `#rrggbb` (an alpha digit pair is ignored), `rgb()` and `color(srgb | display-p3 …)`; undefined for anything else, such as a CSS variable or a colour name. Display P3 channels are read as they are written, which is close enough to choose an ink. */
34
+ function channels(color) {
35
+ const text = color.trim().toLowerCase();
36
+ const hex = /^#([0-9a-f]{3,8})$/.exec(text)?.[1];
37
+ if (hex !== undefined) {
38
+ if (hex.length === 3 || hex.length === 4)
39
+ return [parseInt(hex[0] + hex[0], 16), parseInt(hex[1] + hex[1], 16), parseInt(hex[2] + hex[2], 16)];
40
+ if (hex.length === 6 || hex.length === 8)
41
+ return [parseInt(hex.slice(0, 2), 16), parseInt(hex.slice(2, 4), 16), parseInt(hex.slice(4, 6), 16)];
42
+ return undefined;
43
+ }
44
+ const call = /^(rgba?|color)\(\s*(?:(srgb|display-p3)\s+)?([^)]*)\)$/.exec(text);
45
+ if (!call)
46
+ return undefined;
47
+ const [, name, space, body = ''] = call;
48
+ if ((name === 'color') !== (space !== undefined))
49
+ return undefined;
50
+ const parts = body.split('/')[0].split(/[\s,]+/).filter(Boolean);
51
+ if (parts.length < 3)
52
+ return undefined;
53
+ const [red, green, blue] = parts.slice(0, 3).map(part => channel(part, name === 'color' ? 255 : 1));
54
+ return Number.isFinite(red) && Number.isFinite(green) && Number.isFinite(blue) ? [red, green, blue] : undefined;
55
+ }
56
+ /**
57
+ * The ink that reads on `color`, by boring-avatars' rule: `dark` when the colour's YIQ brightness is 128 or more, otherwise `light`.
58
+ * A six-digit hex colour gets the answer boring-avatars gives. A colour this cannot read (a CSS variable, a colour name) gets `dark`,
59
+ * because avatar palettes are bright; boring-avatars itself draws white there.
60
+ */
61
+ export function beamInk(color) {
62
+ const rgb = channels(color);
63
+ if (!rgb)
64
+ return 'dark';
65
+ return (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000 >= 128 ? 'dark' : 'light';
66
+ }
67
+ /**
68
+ * The face for `seed` in `colors`: the same seed and palette always give the same description, on every platform.
69
+ * `colors` is the palette, in order; its length decides which positions a seed lands on, so a host keeps its faces by keeping its palette.
70
+ * `inks` are the two colours the eyes and mouth may take; the wrapper colour chooses between them (`beamInk`).
71
+ * An empty palette gives empty colours at position 0; renderers substitute their default palette before calling.
72
+ */
73
+ export function beamAvatar(seed, colors, inks = beamInks) {
74
+ const hash = beamHash(seed), range = Math.max(1, colors.length);
75
+ const wrapperIndex = hash % range, backgroundIndex = (hash + 13) % range;
76
+ const wrapperColor = colors[wrapperIndex] ?? '', backgroundColor = colors[backgroundIndex] ?? '';
77
+ const preX = unit(hash, 10, 1), wrapperX = preX < 5 ? preX + beamSize / 9 : preX;
78
+ const preY = unit(hash, 10, 2), wrapperY = preY < 5 ? preY + beamSize / 9 : preY;
79
+ const faceX = wrapperX > beamSize / 6 ? wrapperX / 2 : unit(hash, 8, 1);
80
+ const faceY = wrapperY > beamSize / 6 ? wrapperY / 2 : unit(hash, 7, 2);
81
+ const centre = beamSize / 2, mouthY = 19 + unit(hash, 3), eyeSpread = unit(hash, 5), mouthStroked = even(hash, 2);
82
+ const ink = beamInk(wrapperColor);
83
+ return {
84
+ backgroundIndex, wrapperIndex, backgroundColor, wrapperColor, ink, faceColor: inks[ink],
85
+ wrapperTransform: `translate(${wrapperX} ${wrapperY}) rotate(${unit(hash, 360)} ${centre} ${centre}) scale(${1 + unit(hash, beamSize / 12) / 10})`,
86
+ wrapperRadius: even(hash, 1) ? beamSize : beamSize / 6,
87
+ faceTransform: `translate(${faceX} ${faceY}) rotate(${unit(hash, 10, 3)} ${centre} ${centre})`,
88
+ mouthPath: mouthStroked ? `M15 ${mouthY}c2 1 4 1 6 0` : `M13,${mouthY} a1,0.75 0 0,0 10,0`,
89
+ mouthStroked,
90
+ leftEyeX: 14 - eyeSpread,
91
+ rightEyeX: 20 + eyeSpread,
92
+ };
93
+ }
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Confetti physics shared by the web canvas and the native views, so a burst flies the same on both. It follows
3
+ * canvas-confetti's arithmetic, restated as a function of time: a piece's place at tick `t` is computed directly instead of
4
+ * being stepped frame by frame, so a renderer may ask for any `t` (a 120 Hz display asks for half ticks) and a dropped frame
5
+ * never slows the burst down. A tick is 1/60 s. Distances are CSS pixels on web and points on native; `y` grows downwards.
6
+ * The flight functions carry a `'worklet'` directive, so native runs them on the UI thread.
7
+ */
8
+ export type ConfettiShape = 'square' | 'circle' | 'star';
9
+ /** The options of one burst, modelled on canvas-confetti's so a call maps over. */
10
+ export interface ConfettiOptions {
11
+ /** How many pieces the burst launches. Default 50. */
12
+ particleCount?: number;
13
+ /** Launch direction in degrees: 90 is straight up, 0 is towards the right edge, 180 towards the left. Default 90. */
14
+ angle?: number;
15
+ /** How far, in degrees, pieces may stray from `angle` in total. Default 45. */
16
+ spread?: number;
17
+ /** Launch speed in pixels per tick. Each piece starts between half and one and a half times this. Default 45. `startVelocity`, `gravity`, `drift`, `scalar` and `ticks` are kept within a million either way, so no input can place a piece at infinity. */
18
+ startVelocity?: number;
19
+ /** The share of its launch speed a piece keeps each tick, from 0 to 1; above 1 a piece gains speed. Default 0.9. */
20
+ decay?: number;
21
+ /** Pull downwards: 1 falls at full speed, 0 floats and a negative value rises. Default 1. */
22
+ gravity?: number;
23
+ /** Sideways push in pixels per tick; positive is towards the right edge. Default 0. */
24
+ drift?: number;
25
+ /** How long the burst lasts, in ticks of 1/60 s. Pieces fade out over it. Default 200. */
26
+ ticks?: number;
27
+ /** Where the burst starts, as a share of the layer: `x` 0 is the left edge and 1 the right in both text directions, `y` 0 is the top and 1 the bottom. Default the centre, `{x:0.5,y:0.5}`. */
28
+ origin?: {
29
+ x?: number;
30
+ y?: number;
31
+ };
32
+ /** Colours, dealt to the pieces in turn (repeat one to weight it). Web takes any CSS colour, native any React Native colour. Default: the provider's `action`, `info`, `down`, `warning` and `up` roles. */
33
+ colors?: readonly string[];
34
+ /** Shapes, picked at random for each piece. Default `['square','circle']`. */
35
+ shapes?: readonly ConfettiShape[];
36
+ /** Scales every piece; below 0 reads as 0. Default 1. */
37
+ scalar?: number;
38
+ /** Pieces neither tumble nor wobble. Default false. */
39
+ flat?: boolean;
40
+ /** Draws nothing when reduced motion is on. Default true; canvas-confetti defaults to false. */
41
+ disableForReducedMotion?: boolean;
42
+ /** Web only: the stacking order of the canvas, read from the burst that creates it. Default 100. Native stacks by where `Confetti` is mounted. */
43
+ zIndex?: number;
44
+ }
45
+ /** One piece as launched. Everything it does later follows from these numbers and the tick. */
46
+ export interface ConfettiParticle {
47
+ /** Launch velocity in pixels per tick, split by axis. */
48
+ readonly dx: number;
49
+ readonly dy: number;
50
+ /** Where its wobble starts, in radians, and how far it turns each tick. */
51
+ readonly wobble: number;
52
+ readonly wobbleSpeed: number;
53
+ /** Where its tumble starts, in radians. It turns 0.1 each tick. */
54
+ readonly tilt: number;
55
+ /** Seeds the flutter each piece redraws with every tick. */
56
+ readonly seed: number;
57
+ /** Index into the burst's `colors`. */
58
+ readonly color: number;
59
+ readonly shape: ConfettiShape;
60
+ }
61
+ /** What every piece of a burst shares. Small on purpose: native copies it to the UI thread once. */
62
+ export interface ConfettiPhysics {
63
+ readonly ticks: number;
64
+ readonly decay: number;
65
+ /** Fall in pixels per tick (three times the `gravity` option, as in canvas-confetti). */
66
+ readonly gravity: number;
67
+ readonly drift: number;
68
+ /** Edge of a square piece in pixels: 10 times `scalar`. */
69
+ readonly size: number;
70
+ readonly flat: boolean;
71
+ }
72
+ /** A launched burst: its pieces, the colours they index and where it starts as a share of the layer. */
73
+ export interface ConfettiBurst {
74
+ readonly particles: readonly ConfettiParticle[];
75
+ readonly colors: readonly string[];
76
+ readonly origin: {
77
+ readonly x: number;
78
+ readonly y: number;
79
+ };
80
+ readonly physics: ConfettiPhysics;
81
+ }
82
+ /** A piece at one tick: `x`,`y` from the burst's origin, and the two edges (`ux`,`uy`) and (`vx`,`vy`) of the parallelogram canvas-confetti draws from that point. `wobble` is the wobble angle. */
83
+ export interface ConfettiFlight {
84
+ x: number;
85
+ y: number;
86
+ ux: number;
87
+ uy: number;
88
+ vx: number;
89
+ vy: number;
90
+ wobble: number;
91
+ }
92
+ /** A piece as one box a view can draw: its centre from the burst's origin, a rotation in radians and its width and height as a share of `confettiBox`. */
93
+ export interface ConfettiPose {
94
+ x: number;
95
+ y: number;
96
+ rotate: number;
97
+ scaleX: number;
98
+ scaleY: number;
99
+ }
100
+ /** Ticks per second, and so the length of a tick. */
101
+ export declare const CONFETTI_TICKS_PER_SECOND = 60;
102
+ /** The tick a burst is first drawn at, as canvas-confetti's first frame is: its pieces have already left the origin. A renderer runs `t` from here to `physics.ticks`. */
103
+ export declare const CONFETTI_FIRST_TICK = 1;
104
+ /** canvas-confetti's defaults, apart from `colors` (the renderer's token roles) and `disableForReducedMotion` (true here). */
105
+ export declare const confettiDefaults: {
106
+ readonly particleCount: 50;
107
+ readonly angle: 90;
108
+ readonly spread: 45;
109
+ readonly startVelocity: 45;
110
+ readonly decay: 0.9;
111
+ readonly gravity: 1;
112
+ readonly drift: 0;
113
+ readonly ticks: 200;
114
+ readonly origin: {
115
+ readonly x: 0.5;
116
+ readonly y: 0.5;
117
+ };
118
+ readonly shapes: readonly ConfettiShape[];
119
+ readonly scalar: 1;
120
+ readonly flat: false;
121
+ readonly disableForReducedMotion: true;
122
+ readonly zIndex: 100;
123
+ };
124
+ /** canvas-confetti's star for a piece of size 1: five outer points this far from its centre and five inner points between them, the first outer point straight up. */
125
+ export declare const CONFETTI_STAR_OUTER = 0.8, CONFETTI_STAR_INNER = 0.4;
126
+ /** The star's outline for a piece of size 1, around its centre: ten points, alternately outer and inner. A renderer with paths joins them. */
127
+ export declare const confettiStarPoints: readonly (readonly [number, number])[];
128
+ /**
129
+ * The same star for a renderer without paths: five equal triangles, each with its apex on an outer point, its sides along
130
+ * the star's two edges there and its base through the centre. Turned a fifth of a turn apart they cover the star exactly,
131
+ * with nothing outside it. `width` is the base and `height` the apex above it, for a piece of size 1.
132
+ */
133
+ export declare const confettiStarWedge: {
134
+ readonly width: number;
135
+ readonly height: 0.8;
136
+ };
137
+ /**
138
+ * Launches a burst: `particleCount` pieces, each with its own direction, speed, wobble and tumble drawn from `random`
139
+ * (seven draws a piece, in the order shape, wobble, wobble speed, speed, direction, tumble, flutter seed). Invalid numbers
140
+ * read as the default, and `colors` or `shapes` that are not a list as none given. `fallbackColors` (a list, or a function asked only when needed) are used when `options.colors` holds
141
+ * no colour. Pass a seeded `random` for a repeatable burst.
142
+ */
143
+ export declare function createConfettiBurst(options: ConfettiOptions | undefined, fallbackColors: readonly string[] | (() => readonly string[]), random?: () => number): ConfettiBurst;
144
+ /** True when the burst should not be drawn: reduced motion is on and the call did not opt out with `disableForReducedMotion: false`. */
145
+ export declare function confettiSkipped(options: ConfettiOptions | undefined, reducedMotion: boolean | undefined): boolean;
146
+ /** The same burst seen in a mirror: for a cannon that should fire from the leading edge in right-to-left text. Confetti itself is physical and never mirrors on its own. */
147
+ export declare function mirrorConfetti(options?: ConfettiOptions): ConfettiOptions;
148
+ /** One burst, several or none as a list: what `Confetti` fires for its `options`. Nothing given is one default burst. */
149
+ export declare function confettiBursts(options: ConfettiOptions | readonly ConfettiOptions[] | undefined): readonly (ConfettiOptions | undefined)[];
150
+ /** How long a burst is drawn for, in milliseconds: from `CONFETTI_FIRST_TICK` to its last tick. */
151
+ export declare function confettiDuration(physics: ConfettiPhysics): number;
152
+ /** How visible a burst is at tick `t`: every piece fades in a straight line over the burst, from 1 on its first tick, as in canvas-confetti, towards 0 one tick after its last. */
153
+ export declare function confettiOpacity(physics: ConfettiPhysics, t: number): number;
154
+ /**
155
+ * How far its launch speed has carried a piece by tick `t`, in ticks' worth of that speed: the sum of `decay` to the power
156
+ * of each tick so far. Every piece of a burst shares it, so a renderer may compute it once a frame. With a `decay` above 1
157
+ * it grows without end, so it stops at a distance far off any screen and stays a finite number.
158
+ */
159
+ export declare function confettiTravel(physics: ConfettiPhysics, t: number): number;
160
+ /**
161
+ * Where a piece is at tick `t` and the parallelogram it is drawn as, written into `out`. `travel` is `confettiTravel` for the
162
+ * same tick. The flutter (canvas-confetti redraws each piece with a new random width every tick) is a hash of the piece's
163
+ * seed and the whole tick, so it stays at 60 changes a second on any display and is the same on both platforms.
164
+ */
165
+ export declare function confettiFlight(particle: ConfettiParticle, physics: ConfettiPhysics, t: number, travel: number, out: ConfettiFlight): ConfettiFlight;
166
+ /** The untransformed box a piece is drawn in, in pixels: a square's edge, a circle's diameter, or the square around a star. */
167
+ export declare function confettiBox(shape: ConfettiShape, physics: ConfettiPhysics): number;
168
+ /**
169
+ * A piece at tick `t` for a renderer that moves boxes and cannot draw a slanted one (React Native drops skew on Android).
170
+ * A circle is exact: canvas-confetti draws it as a turning ellipse. A square's parallelogram becomes the rectangle with the
171
+ * same centre, the same area and the same long and short axes (its singular values), turned to the long axis; a flat square
172
+ * is exact. A star keeps its size and does not turn: the renderer fills its box with `confettiStarWedge` triangles.
173
+ */
174
+ export declare function confettiPose(particle: ConfettiParticle, physics: ConfettiPhysics, t: number): ConfettiPose;
@@ -0,0 +1,138 @@
1
+ /** Ticks per second, and so the length of a tick. */
2
+ export const CONFETTI_TICKS_PER_SECOND = 60;
3
+ /** The tick a burst is first drawn at, as canvas-confetti's first frame is: its pieces have already left the origin. A renderer runs `t` from here to `physics.ticks`. */
4
+ export const CONFETTI_FIRST_TICK = 1;
5
+ /** canvas-confetti's defaults, apart from `colors` (the renderer's token roles) and `disableForReducedMotion` (true here). */
6
+ export const confettiDefaults = { particleCount: 50, angle: 90, spread: 45, startVelocity: 45, decay: 0.9, gravity: 1, drift: 0, ticks: 200, origin: { x: 0.5, y: 0.5 }, shapes: ['square', 'circle'], scalar: 1, flat: false, disableForReducedMotion: true, zIndex: 100 };
7
+ /** The furthest an option may reach either way, and the furthest a launch speed may carry a piece, in ticks' worth of it. Far beyond any screen, and small enough that every place computed from them is a finite number. */
8
+ const REACH = 1e6, TRAVEL = 1e9;
9
+ /** A finite number within `low` and `high`; anything else is the default. */
10
+ const finite = (value, fallback, low = -REACH, high = REACH) => typeof value === 'number' && Number.isFinite(value) ? Math.min(high, Math.max(low, value)) : fallback;
11
+ const list = (value) => Array.isArray(value) ? value : [];
12
+ const shapes = ['square', 'circle', 'star'];
13
+ /** canvas-confetti's star for a piece of size 1: five outer points this far from its centre and five inner points between them, the first outer point straight up. */
14
+ export const CONFETTI_STAR_OUTER = 0.8, CONFETTI_STAR_INNER = 0.4;
15
+ /** The star's outline for a piece of size 1, around its centre: ten points, alternately outer and inner. A renderer with paths joins them. */
16
+ export const confettiStarPoints = Array.from({ length: 10 }, (_, index) => { const angle = Math.PI * 1.5 + index * Math.PI / 5, radius = index % 2 ? CONFETTI_STAR_INNER : CONFETTI_STAR_OUTER; return [Math.cos(angle) * radius, Math.sin(angle) * radius]; });
17
+ /**
18
+ * The same star for a renderer without paths: five equal triangles, each with its apex on an outer point, its sides along
19
+ * the star's two edges there and its base through the centre. Turned a fifth of a turn apart they cover the star exactly,
20
+ * with nothing outside it. `width` is the base and `height` the apex above it, for a piece of size 1.
21
+ */
22
+ export const confettiStarWedge = { width: 2 * CONFETTI_STAR_OUTER * CONFETTI_STAR_INNER * Math.sin(Math.PI / 5) / (CONFETTI_STAR_OUTER - CONFETTI_STAR_INNER * Math.cos(Math.PI / 5)), height: CONFETTI_STAR_OUTER };
23
+ /**
24
+ * Launches a burst: `particleCount` pieces, each with its own direction, speed, wobble and tumble drawn from `random`
25
+ * (seven draws a piece, in the order shape, wobble, wobble speed, speed, direction, tumble, flutter seed). Invalid numbers
26
+ * read as the default, and `colors` or `shapes` that are not a list as none given. `fallbackColors` (a list, or a function asked only when needed) are used when `options.colors` holds
27
+ * no colour. Pass a seeded `random` for a repeatable burst.
28
+ */
29
+ export function createConfettiBurst(options, fallbackColors, random = Math.random) {
30
+ const o = options ?? {}, d = confettiDefaults;
31
+ const count = Math.floor(finite(o.particleCount, d.particleCount, 0, 500));
32
+ const angle = finite(o.angle, d.angle) * Math.PI / 180, spread = finite(o.spread, d.spread) * Math.PI / 180, velocity = finite(o.startVelocity, d.startVelocity);
33
+ const own = list(o.colors).filter(color => typeof color === 'string' && color !== '');
34
+ const colors = own.length ? own : typeof fallbackColors === 'function' ? fallbackColors() : fallbackColors;
35
+ const picked = list(o.shapes).filter(shape => shapes.includes(shape));
36
+ const pool = picked.length ? picked : d.shapes;
37
+ const particles = [];
38
+ for (let index = count - 1; index >= 0 && colors.length > 0; index--) {
39
+ const shape = pool[Math.min(pool.length - 1, Math.floor(random() * pool.length))];
40
+ const wobble = random() * 10, wobbleSpeed = Math.min(0.11, random() * 0.1 + 0.05), speed = velocity * 0.5 + random() * velocity;
41
+ const direction = -angle + (0.5 * spread - random() * spread), tilt = (random() * 0.5 + 0.25) * Math.PI, seed = random() * 1000;
42
+ particles.push({ dx: Math.cos(direction) * speed, dy: Math.sin(direction) * speed, wobble, wobbleSpeed, tilt, seed, color: index % colors.length, shape });
43
+ }
44
+ return { particles, colors, origin: { x: finite(o.origin?.x, d.origin.x), y: finite(o.origin?.y, d.origin.y) },
45
+ physics: { ticks: finite(o.ticks, d.ticks, 1), decay: finite(o.decay, d.decay, 0), gravity: finite(o.gravity, d.gravity) * 3, drift: finite(o.drift, d.drift), size: 10 * finite(o.scalar, d.scalar, 0), flat: o.flat === true } };
46
+ }
47
+ /** True when the burst should not be drawn: reduced motion is on and the call did not opt out with `disableForReducedMotion: false`. */
48
+ export function confettiSkipped(options, reducedMotion) { return reducedMotion === true && options?.disableForReducedMotion !== false; }
49
+ /** The same burst seen in a mirror: for a cannon that should fire from the leading edge in right-to-left text. Confetti itself is physical and never mirrors on its own. */
50
+ export function mirrorConfetti(options) {
51
+ const o = options ?? {}, d = confettiDefaults;
52
+ return { ...o, angle: 180 - finite(o.angle, d.angle), drift: 0 - finite(o.drift, d.drift), origin: { ...o.origin, x: 1 - finite(o.origin?.x, d.origin.x) } };
53
+ }
54
+ /** One burst, several or none as a list: what `Confetti` fires for its `options`. Nothing given is one default burst. */
55
+ export function confettiBursts(options) { return Array.isArray(options) ? options : [options]; }
56
+ /** How long a burst is drawn for, in milliseconds: from `CONFETTI_FIRST_TICK` to its last tick. */
57
+ export function confettiDuration(physics) {
58
+ 'worklet';
59
+ return Math.max(0, physics.ticks - CONFETTI_FIRST_TICK) * 1000 / CONFETTI_TICKS_PER_SECOND;
60
+ }
61
+ /** How visible a burst is at tick `t`: every piece fades in a straight line over the burst, from 1 on its first tick, as in canvas-confetti, towards 0 one tick after its last. */
62
+ export function confettiOpacity(physics, t) {
63
+ 'worklet';
64
+ return Math.max(0, Math.min(1, 1 - (t - CONFETTI_FIRST_TICK) / physics.ticks));
65
+ }
66
+ /**
67
+ * How far its launch speed has carried a piece by tick `t`, in ticks' worth of that speed: the sum of `decay` to the power
68
+ * of each tick so far. Every piece of a burst shares it, so a renderer may compute it once a frame. With a `decay` above 1
69
+ * it grows without end, so it stops at a distance far off any screen and stays a finite number.
70
+ */
71
+ export function confettiTravel(physics, t) {
72
+ 'worklet';
73
+ const decay = physics.decay;
74
+ return Math.min(TRAVEL, decay === 1 ? t : (1 - Math.pow(decay, t)) / (1 - decay));
75
+ }
76
+ /**
77
+ * Where a piece is at tick `t` and the parallelogram it is drawn as, written into `out`. `travel` is `confettiTravel` for the
78
+ * same tick. The flutter (canvas-confetti redraws each piece with a new random width every tick) is a hash of the piece's
79
+ * seed and the whole tick, so it stays at 60 changes a second on any display and is the same on both platforms.
80
+ */
81
+ export function confettiFlight(particle, physics, t, travel, out) {
82
+ 'worklet';
83
+ const size = physics.size;
84
+ out.x = particle.dx * travel + physics.drift * t;
85
+ out.y = particle.dy * travel + physics.gravity * t;
86
+ if (physics.flat) {
87
+ out.ux = size;
88
+ out.uy = 0;
89
+ out.vx = 0;
90
+ out.vy = size;
91
+ out.wobble = 0;
92
+ return out;
93
+ }
94
+ const wobble = particle.wobble + particle.wobbleSpeed * t, tilt = particle.tilt + 0.1 * t;
95
+ const noise = Math.sin((particle.seed + Math.floor(t)) * 12.9898) * 43758.5453, flutter = 2 + noise - Math.floor(noise);
96
+ out.ux = size * Math.cos(wobble);
97
+ out.uy = flutter * Math.sin(tilt);
98
+ out.vx = flutter * Math.cos(tilt);
99
+ out.vy = size * Math.sin(wobble);
100
+ out.wobble = wobble;
101
+ return out;
102
+ }
103
+ /** The untransformed box a piece is drawn in, in pixels: a square's edge, a circle's diameter, or the square around a star. */
104
+ export function confettiBox(shape, physics) {
105
+ 'worklet';
106
+ return shape === 'circle' ? physics.size * 1.2 : shape === 'star' ? physics.size * 1.6 : physics.size;
107
+ }
108
+ /**
109
+ * A piece at tick `t` for a renderer that moves boxes and cannot draw a slanted one (React Native drops skew on Android).
110
+ * A circle is exact: canvas-confetti draws it as a turning ellipse. A square's parallelogram becomes the rectangle with the
111
+ * same centre, the same area and the same long and short axes (its singular values), turned to the long axis; a flat square
112
+ * is exact. A star keeps its size and does not turn: the renderer fills its box with `confettiStarWedge` triangles.
113
+ */
114
+ export function confettiPose(particle, physics, t) {
115
+ 'worklet';
116
+ // confettiFlight's sums, kept in local variables and taken only as far as the shape needs them. Native runs this for every
117
+ // piece every frame, and its engine allocates a flight object and a boxed number for each field written to it: a star needs
118
+ // no angle at all and a circle no tumble or flutter. The results are the same numbers, bit for bit.
119
+ const size = physics.size, travel = confettiTravel(physics, t), x = particle.dx * travel + physics.drift * t, y = particle.dy * travel + physics.gravity * t;
120
+ if (size <= 0)
121
+ return { x, y, rotate: 0, scaleX: 0, scaleY: 0 };
122
+ if (particle.shape === 'star')
123
+ return { x, y, rotate: 0, scaleX: 1, scaleY: 1 };
124
+ const flat = physics.flat, wobble = flat ? 0 : particle.wobble + particle.wobbleSpeed * t, ux = flat ? size : size * Math.cos(wobble), vy = flat ? size : size * Math.sin(wobble);
125
+ if (particle.shape === 'circle')
126
+ return { x, y, rotate: Math.PI / 10 * wobble, scaleX: Math.abs(ux) / size, scaleY: Math.abs(vy) / size };
127
+ let uy = 0, vx = 0;
128
+ if (!flat) {
129
+ const tilt = particle.tilt + 0.1 * t, noise = Math.sin((particle.seed + Math.floor(t)) * 12.9898) * 43758.5453, flutter = 2 + noise - Math.floor(noise);
130
+ uy = flutter * Math.sin(tilt);
131
+ vx = flutter * Math.cos(tilt);
132
+ }
133
+ // Singular values of [[ux,vx],[uy,vy]] and the rotation that follows the stretch; the rotation before it only turns a square onto itself.
134
+ const e = (ux + vy) / 2, f = (ux - vy) / 2, g = (uy + vx) / 2, h = (uy - vx) / 2;
135
+ const q = Math.sqrt(e * e + h * h), r = Math.sqrt(f * f + g * g);
136
+ // The flutter does not shrink with the piece, so a piece far below a pixel would be stretched without end: the stretch stops at REACH.
137
+ return { x: x + (ux + vx) / 2, y: y + (uy + vy) / 2, rotate: (Math.atan2(h, e) + Math.atan2(g, f)) / 2, scaleX: Math.min(REACH, (q + r) / size), scaleY: Math.min(REACH, Math.abs(q - r) / size) };
138
+ }
@@ -0,0 +1,7 @@
1
+ /** Bounded, nonnegative decimal arithmetic for transaction input. Numbers are display adapters only. */
2
+ export declare function decimal(value: string | number, places?: number): string;
3
+ export declare function decimalMultiply(a: string | number, b: string | number, places?: number): string;
4
+ export declare function decimalDivide(a: string | number, b: string | number, places?: number): string;
5
+ export declare function decimalCompare(a: string | number, b: string | number): -1 | 0 | 1;
6
+ /** Localizes an editor's decimal digits without converting the amount to a floating-point number. */
7
+ export declare function localizeDecimal(value: string, locale: string): string;
@@ -0,0 +1,35 @@
1
+ /** Bounded, nonnegative decimal arithmetic for transaction input. Numbers are display adapters only. */
2
+ export function decimal(value, places = 100) {
3
+ const input = String(value), raw = input.startsWith('.') ? '0' + input : input;
4
+ if (raw.length > 1000 || !Number.isInteger(places) || places < 0 || places > 100)
5
+ throw new RangeError('Invalid decimal precision or length');
6
+ const match = /^(\d+)(?:\.(\d*))?(?:e([+-]?\d+))?$/i.exec(raw);
7
+ if (!match)
8
+ return '0';
9
+ const exponent = Number(match[3] ?? 0);
10
+ if (!Number.isInteger(exponent) || Math.abs(exponent) > 100)
11
+ return '0';
12
+ const digits = match[1] + (match[2] ?? ''), point = match[1].length + exponent;
13
+ const whole = point <= 0 ? '0' : digits.slice(0, point).padEnd(point, '0');
14
+ const fraction = (point < 0 ? '0'.repeat(-point) + digits : digits.slice(point)).slice(0, places).replace(/0+$/, '');
15
+ return whole.replace(/^0+(?=\d)/, '') + (fraction ? '.' + fraction : '');
16
+ }
17
+ function parts(value) { const [whole, fraction = ''] = decimal(value).split('.'); return { n: BigInt(whole + fraction), scale: fraction.length }; }
18
+ function format(n, scale) { const raw = n.toString().padStart(scale + 1, '0'); return decimal(scale ? raw.slice(0, -scale) + '.' + raw.slice(-scale) : raw); }
19
+ export function decimalMultiply(a, b, places = 100) { const x = parts(a), y = parts(b); return decimal(format(x.n * y.n, x.scale + y.scale), places); }
20
+ export function decimalDivide(a, b, places = 18) { const x = parts(a), y = parts(b); if (!y.n)
21
+ return '0'; if (!Number.isInteger(places) || places < 0 || places > 100)
22
+ throw new RangeError('Invalid decimal precision'); return format(x.n * 10n ** BigInt(y.scale + places) / (y.n * 10n ** BigInt(x.scale)), places); }
23
+ export function decimalCompare(a, b) { const x = parts(a), y = parts(b), left = x.n * 10n ** BigInt(y.scale), right = y.n * 10n ** BigInt(x.scale); return left < right ? -1 : left > right ? 1 : 0; }
24
+ /** Localizes an editor's decimal digits without converting the amount to a floating-point number. */
25
+ export function localizeDecimal(value, locale) {
26
+ try {
27
+ const formatter = new Intl.NumberFormat(locale, { useGrouping: false, maximumFractionDigits: 1 });
28
+ const separator = formatter.formatToParts(1.1).find(part => part.type === 'decimal')?.value ?? '.';
29
+ const digits = Array.from({ length: 10 }, (_, digit) => formatter.format(digit));
30
+ return value.replace(/[0-9.]/g, char => char === '.' ? separator : digits[Number(char)]);
31
+ }
32
+ catch {
33
+ return value;
34
+ }
35
+ }