@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.
- package/README.md +2 -2
- package/chart/README.md +13 -2
- package/chart/dist/altimeter-burst.d.ts +4 -0
- package/chart/dist/altimeter-burst.js +43 -0
- package/chart/dist/altimeter-chart.d.ts +52 -0
- package/chart/dist/altimeter-chart.js +275 -0
- package/chart/dist/altimeter-model.d.ts +43 -0
- package/chart/dist/altimeter-model.js +148 -0
- package/chart/dist/altimeter-targets.d.ts +33 -0
- package/chart/dist/altimeter-targets.js +88 -0
- package/chart/dist/bitcoin-price.d.ts +8 -0
- package/chart/dist/bitcoin-price.js +41 -0
- package/chart/dist/champions-league.d.ts +19 -0
- package/chart/dist/champions-league.js +104 -0
- package/chart/dist/index.d.ts +6 -0
- package/chart/dist/index.js +5 -0
- package/chart/dist/outcome-chart.d.ts +37 -0
- package/chart/dist/outcome-chart.js +212 -0
- package/chart/dist/outcome-model.d.ts +43 -0
- package/chart/dist/outcome-model.js +71 -0
- package/chart/dist/plus-grid.d.ts +6 -0
- package/chart/dist/plus-grid.js +29 -0
- package/contracts/README.md +1 -1
- package/contracts/dist/avatar.d.ts +68 -0
- package/contracts/dist/avatar.js +93 -0
- package/contracts/dist/confetti.d.ts +174 -0
- package/contracts/dist/confetti.js +138 -0
- package/contracts/dist/decimal.d.ts +7 -0
- package/contracts/dist/decimal.js +35 -0
- package/contracts/dist/index.d.ts +29 -2
- package/contracts/dist/index.js +123 -4
- package/contracts/dist/invariants.d.ts +17 -0
- package/contracts/dist/invariants.js +24 -0
- package/contracts/dist/login.d.ts +34 -0
- package/contracts/dist/login.js +43 -0
- package/contracts/dist/messages.d.ts +57 -3
- package/contracts/dist/messages.js +20 -2
- package/contracts/dist/number-flow.d.ts +90 -0
- package/contracts/dist/number-flow.js +150 -0
- package/contracts/dist/qr.d.ts +151 -0
- package/contracts/dist/qr.js +581 -0
- package/contracts/dist/toast.d.ts +168 -0
- package/contracts/dist/toast.js +171 -0
- package/feedback/README.md +1 -1
- package/feedback/dist/contract.js +1 -1
- package/feedback/dist/react.js +2 -4
- package/native/README.md +6 -1
- package/native/dist/account-block.d.ts +10 -1
- package/native/dist/account-block.js +17 -7
- package/native/dist/animated-number-model.d.ts +41 -1
- package/native/dist/animated-number-model.js +201 -23
- package/native/dist/animated-number.d.ts +39 -1
- package/native/dist/animated-number.js +164 -17
- package/native/dist/announce.d.ts +2 -0
- package/native/dist/announce.js +10 -0
- package/native/dist/asset-balance-row.d.ts +3 -1
- package/native/dist/asset-balance-row.js +15 -4
- package/native/dist/assets-block.d.ts +115 -0
- package/native/dist/assets-block.js +87 -0
- package/native/dist/async-result.d.ts +2 -0
- package/native/dist/async-result.js +11 -0
- package/native/dist/avatar-frame.d.ts +29 -0
- package/native/dist/avatar-frame.js +56 -0
- package/native/dist/avatar.d.ts +21 -0
- package/native/dist/avatar.js +31 -0
- package/native/dist/bar-mark.d.ts +2 -0
- package/native/dist/bar-mark.js +4 -2
- package/native/dist/bar-pnl.js +2 -1
- package/native/dist/blocks.d.ts +9 -2
- package/native/dist/blocks.js +8 -1
- package/native/dist/brand.js +2 -1
- package/native/dist/button.d.ts +7 -2
- package/native/dist/button.js +13 -3
- package/native/dist/checkbox.js +2 -1
- package/native/dist/confetti.d.ts +33 -0
- package/native/dist/confetti.js +143 -0
- package/native/dist/confirm-block.d.ts +98 -0
- package/native/dist/confirm-block.js +48 -0
- package/native/dist/data.d.ts +1 -1
- package/native/dist/data.js +5 -1
- package/native/dist/deposit-block.d.ts +19 -0
- package/native/dist/deposit-block.js +17 -0
- package/native/dist/explainer-block.d.ts +91 -0
- package/native/dist/explainer-block.js +34 -0
- package/native/dist/field.d.ts +5 -1
- package/native/dist/field.js +27 -6
- package/native/dist/gesture-sheet-model.d.ts +50 -0
- package/native/dist/gesture-sheet-model.js +105 -0
- package/native/dist/gesture-sheet-next.d.ts +82 -0
- package/native/dist/gesture-sheet-next.js +315 -0
- package/native/dist/gesture-sheet.d.ts +5 -1
- package/native/dist/gesture-sheet.js +13 -6
- package/native/dist/icons.d.ts +9 -6
- package/native/dist/icons.js +25 -24
- package/native/dist/language-block.d.ts +10 -1
- package/native/dist/language-block.js +11 -4
- package/native/dist/list-group.d.ts +3 -1
- package/native/dist/list-group.js +26 -13
- package/native/dist/login-block.d.ts +4 -0
- package/native/dist/login-block.js +22 -0
- package/native/dist/manage-position-block.d.ts +8 -1
- package/native/dist/manage-position-block.js +7 -2
- package/native/dist/market-row.js +19 -8
- package/native/dist/navigation.js +5 -3
- package/native/dist/number-format.d.ts +6 -0
- package/native/dist/number-format.js +9 -0
- package/native/dist/pickers.d.ts +8 -0
- package/native/dist/pickers.js +3 -3
- package/native/dist/position-block.d.ts +5 -5
- package/native/dist/preset-group.d.ts +31 -0
- package/native/dist/preset-group.js +39 -0
- package/native/dist/preset-picker-block.d.ts +107 -0
- package/native/dist/preset-picker-block.js +43 -0
- package/native/dist/profile-block.d.ts +10 -1
- package/native/dist/profile-block.js +8 -3
- package/native/dist/provider.d.ts +5 -2
- package/native/dist/provider.js +27 -5
- package/native/dist/qr-code.d.ts +33 -0
- package/native/dist/qr-code.js +29 -0
- package/native/dist/radio-group.d.ts +19 -7
- package/native/dist/radio-group.js +39 -10
- package/native/dist/reward-block.d.ts +10 -7
- package/native/dist/reward-block.js +9 -4
- package/native/dist/screen-header.d.ts +13 -3
- package/native/dist/screen-header.js +12 -4
- package/native/dist/select.js +4 -2
- package/native/dist/selection.d.ts +2 -1
- package/native/dist/selection.js +1 -0
- package/native/dist/setting-switch.d.ts +1 -1
- package/native/dist/setting-switch.js +7 -3
- package/native/dist/slider.js +5 -1
- package/native/dist/sound-haptics-block.js +1 -1
- package/native/dist/status.d.ts +41 -9
- package/native/dist/status.js +34 -17
- package/native/dist/sticky-header.js +9 -1
- package/native/dist/swap-amount-card.d.ts +57 -0
- package/native/dist/swap-amount-card.js +31 -0
- package/native/dist/{swap-panel-block.d.ts → swap-block.d.ts} +18 -8
- package/native/dist/{swap-panel-block.js → swap-block.js} +63 -35
- package/native/dist/swap-parts.d.ts +3 -10
- package/native/dist/swap-parts.js +22 -24
- package/native/dist/swap-shared.d.ts +2 -2
- package/native/dist/swap-shared.js +10 -6
- package/native/dist/swap-sheet.d.ts +3 -3
- package/native/dist/swap-sheet.js +3 -3
- package/native/dist/swap-views.js +1 -1
- package/native/dist/target-block.d.ts +7 -1
- package/native/dist/target-block.js +13 -6
- package/native/dist/toast.d.ts +47 -0
- package/native/dist/toast.js +386 -0
- package/native/dist/token-action-block.d.ts +11 -2
- package/native/dist/token-action-block.js +10 -4
- package/native/dist/trade-history-list-block.js +7 -4
- package/native/dist/wallet-address-core.js +6 -3
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +155 -11
- package/react/README.md +3 -1
- package/react/dist/animated-number-flow.d.ts +72 -0
- package/react/dist/animated-number-flow.js +316 -0
- package/react/dist/animated-number-model.d.ts +18 -0
- package/react/dist/animated-number-model.js +75 -5
- package/react/dist/animated-number.d.ts +45 -1
- package/react/dist/animated-number.js +137 -6
- package/react/dist/asset-balance-row.d.ts +3 -1
- package/react/dist/asset-balance-row.js +10 -4
- package/react/dist/async-result.d.ts +2 -0
- package/react/dist/async-result.js +11 -0
- package/react/dist/avatar.d.ts +25 -0
- package/react/dist/avatar.js +50 -0
- package/react/dist/blocks/account-block.d.ts +5 -1
- package/react/dist/blocks/account-block.js +11 -6
- package/react/dist/blocks/assets-block.d.ts +106 -0
- package/react/dist/blocks/assets-block.js +135 -0
- package/react/dist/blocks/confirm-block.d.ts +91 -0
- package/react/dist/blocks/confirm-block.js +31 -0
- package/react/dist/blocks/deposit-block.d.ts +19 -0
- package/react/dist/blocks/deposit-block.js +15 -0
- package/react/dist/blocks/explainer-block.d.ts +80 -0
- package/react/dist/blocks/explainer-block.js +20 -0
- package/react/dist/blocks/install-command.js +3 -1
- package/react/dist/blocks/language-block.d.ts +5 -1
- package/react/dist/blocks/language-block.js +4 -3
- package/react/dist/blocks/login-block.d.ts +4 -0
- package/react/dist/blocks/login-block.js +14 -0
- package/react/dist/blocks/manage-position-block.d.ts +3 -1
- package/react/dist/blocks/manage-position-block.js +2 -2
- package/react/dist/blocks/market-row.js +8 -3
- package/react/dist/blocks/notifications-block.d.ts +3 -1
- package/react/dist/blocks/notifications-block.js +2 -2
- package/react/dist/blocks/pickers.d.ts +9 -0
- package/react/dist/blocks/pickers.js +4 -2
- package/react/dist/blocks/position-block.d.ts +3 -3
- package/react/dist/blocks/preset-picker-block.d.ts +85 -0
- package/react/dist/blocks/preset-picker-block.js +19 -0
- package/react/dist/blocks/profile-block.d.ts +5 -1
- package/react/dist/blocks/profile-block.js +12 -13
- package/react/dist/blocks/reward-block.d.ts +13 -8
- package/react/dist/blocks/reward-block.js +7 -4
- package/react/dist/blocks/screen-header.d.ts +10 -2
- package/react/dist/blocks/screen-header.js +7 -4
- package/react/dist/blocks/setting-switch.js +6 -3
- package/react/dist/blocks/signals-block.d.ts +3 -1
- package/react/dist/blocks/signals-block.js +4 -3
- package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
- package/react/dist/blocks/sound-haptics-block.js +2 -2
- package/react/dist/blocks/sticky-header.d.ts +14 -4
- package/react/dist/blocks/sticky-header.js +68 -8
- package/react/dist/blocks/swap/settings.js +2 -1
- package/react/dist/blocks/swap/shared.d.ts +22 -22
- package/react/dist/blocks/swap/shared.js +30 -28
- package/react/dist/blocks/{swap-panel-block.d.ts → swap-block.d.ts} +19 -8
- package/react/dist/blocks/swap-block.js +215 -0
- package/react/dist/blocks/swap-sheet.d.ts +3 -3
- package/react/dist/blocks/swap-sheet.js +3 -3
- package/react/dist/blocks/target-block.d.ts +7 -1
- package/react/dist/blocks/target-block.js +10 -4
- package/react/dist/blocks/token-action-block.d.ts +6 -2
- package/react/dist/blocks/token-action-block.js +3 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
- package/react/dist/blocks/trade-history-detail-block.js +2 -2
- package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
- package/react/dist/blocks/trade-history-list-block.js +7 -4
- package/react/dist/blocks.d.ts +8 -2
- package/react/dist/blocks.js +7 -1
- package/react/dist/brand.js +2 -1
- package/react/dist/button.d.ts +9 -3
- package/react/dist/button.js +8 -3
- package/react/dist/confetti.d.ts +27 -0
- package/react/dist/confetti.js +240 -0
- package/react/dist/data.js +8 -1
- package/react/dist/field.d.ts +6 -1
- package/react/dist/field.js +18 -9
- package/react/dist/gesture-sheet.d.ts +15 -1
- package/react/dist/gesture-sheet.js +53 -8
- package/react/dist/list-group.js +11 -7
- package/react/dist/navigation.js +11 -3
- package/react/dist/overlay.d.ts +1 -4
- package/react/dist/overlay.js +1 -3
- package/react/dist/popover.d.ts +30 -0
- package/react/dist/popover.js +34 -0
- package/react/dist/preset-group.d.ts +30 -0
- package/react/dist/preset-group.js +13 -0
- package/react/dist/provider.d.ts +2 -2
- package/react/dist/provider.js +23 -6
- package/react/dist/qr-code.d.ts +32 -0
- package/react/dist/qr-code.js +28 -0
- package/react/dist/select.js +10 -3
- package/react/dist/selection.d.ts +13 -5
- package/react/dist/selection.js +13 -8
- package/react/dist/slider.js +5 -1
- package/react/dist/status.d.ts +14 -10
- package/react/dist/status.js +17 -9
- package/react/dist/styles.css +260 -165
- package/react/dist/toast.d.ts +19 -12
- package/react/dist/toast.js +29 -7
- package/react/dist/wallet-address-core.d.ts +8 -4
- package/react/dist/wallet-address-core.js +10 -5
- package/tokens/README.md +2 -2
- package/tokens/assets/onramps/apple-pay.svg +33 -0
- package/tokens/assets/onramps/bank.svg +98 -0
- package/tokens/assets/onramps/blink.svg +37 -0
- package/tokens/assets/onramps/cashapp.svg +33 -0
- package/tokens/assets/onramps/crypto.svg +121 -0
- package/tokens/assets/onramps/exchange.svg +105 -0
- package/tokens/dist/deposit-icons.d.ts +1 -0
- package/tokens/dist/deposit-icons.js +28 -0
- package/tokens/dist/index.d.ts +16 -0
- package/tokens/dist/index.js +16 -0
- package/tokens/dist/manifest.json +8 -0
- package/tokens/dist/tokens.css +6 -0
- package/react/dist/blocks/swap-panel-block.js +0 -178
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { formatNumber } from '
|
|
1
|
+
import { formatNumber } from './number-format.js';
|
|
2
2
|
const supportedParts = new Set(['integer', 'fraction', 'decimal', 'group', 'plusSign', 'minusSign', 'percentSign', 'currency', 'unit', 'compact', 'literal', 'exponentSeparator', 'exponentInteger', 'exponentMinusSign', 'exponentPlusSign', 'approximatelySign']);
|
|
3
3
|
const bidiControls = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/u;
|
|
4
4
|
export function formatNumberReadout(value, locale, options, formattedValue, prefix, suffix) {
|
|
5
5
|
const known = typeof value === 'number' && Number.isFinite(value);
|
|
6
6
|
if (!known)
|
|
7
7
|
return { known: false, core: '—', text: '—' };
|
|
8
|
+
// Without a sign to compose, the reading is the unsigned formatter's own, and that one is kept; `formatNumber` builds its own each time.
|
|
8
9
|
let core;
|
|
9
10
|
if (formattedValue)
|
|
10
11
|
core = formattedValue;
|
|
11
12
|
else {
|
|
12
13
|
try {
|
|
13
|
-
|
|
14
|
+
const sign = options?.signDisplay;
|
|
15
|
+
core = sign === undefined || sign === 'auto' ? formatFor(locale, options).unsigned.format(value) : formatNumber(value, locale, options);
|
|
14
16
|
}
|
|
15
17
|
catch {
|
|
16
18
|
core = String(value);
|
|
@@ -45,13 +47,43 @@ export function safeNumberLayout(text, direction) {
|
|
|
45
47
|
return true;
|
|
46
48
|
}
|
|
47
49
|
const asciiDigits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
50
|
+
const keptFormats = new Map(), keptLocaleDigits = new Map();
|
|
51
|
+
let keptFor;
|
|
52
|
+
function current() { if (keptFor !== Intl.NumberFormat) {
|
|
53
|
+
keptFormats.clear();
|
|
54
|
+
keptLocaleDigits.clear();
|
|
55
|
+
keptFor = Intl.NumberFormat;
|
|
56
|
+
} }
|
|
57
|
+
function formatFor(locale, options) {
|
|
58
|
+
current();
|
|
59
|
+
const key = `${locale}\u0000${options ? JSON.stringify(options) : ''}`;
|
|
60
|
+
let kept = keptFormats.get(key);
|
|
61
|
+
if (!kept) {
|
|
62
|
+
// The numbering system is the unsigned format's: Hermes on iOS ignores `signDisplay`, and HIG composes the sign itself.
|
|
63
|
+
const { signDisplay: _sign, ...rest } = options ?? {}, unsigned = new Intl.NumberFormat(locale, rest);
|
|
64
|
+
kept = { unsigned, numberingSystem: unsigned.resolvedOptions().numberingSystem };
|
|
65
|
+
if (keptFormats.size >= 64)
|
|
66
|
+
keptFormats.clear();
|
|
67
|
+
keptFormats.set(key, kept);
|
|
68
|
+
}
|
|
69
|
+
return kept;
|
|
70
|
+
}
|
|
48
71
|
/** The ten digit glyphs of a locale's numbering system, or `null` when Intl cannot name them one character each. */
|
|
49
72
|
function localeDigits(locale) {
|
|
73
|
+
current();
|
|
74
|
+
const kept = keptLocaleDigits.get(locale);
|
|
75
|
+
if (kept)
|
|
76
|
+
return kept;
|
|
50
77
|
try {
|
|
51
78
|
const numberingSystem = new Intl.NumberFormat(locale).resolvedOptions().numberingSystem;
|
|
52
79
|
const digitFormatter = new Intl.NumberFormat(locale, { numberingSystem, useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
|
53
80
|
const digits = Array.from({ length: 10 }, (_, digit) => { const formatted = digitFormatter.format(digit); return Array.from(formatted).length === 1 ? formatted : ''; });
|
|
54
|
-
|
|
81
|
+
if (!digits.every(Boolean) || new Set(digits).size !== 10)
|
|
82
|
+
return null;
|
|
83
|
+
if (keptLocaleDigits.size >= 64)
|
|
84
|
+
keptLocaleDigits.clear();
|
|
85
|
+
keptLocaleDigits.set(locale, digits);
|
|
86
|
+
return digits;
|
|
55
87
|
}
|
|
56
88
|
catch {
|
|
57
89
|
return null;
|
|
@@ -91,32 +123,121 @@ export function createFormattedReelModel(text, locale, direction) {
|
|
|
91
123
|
flush();
|
|
92
124
|
return { canonical: text, digits, tokens };
|
|
93
125
|
}
|
|
94
|
-
|
|
126
|
+
const minusSign = /[-−‐-―﹣-]/u;
|
|
127
|
+
/** The ten digit glyphs a reel rolls through: the numbering system's when Intl names it (each checked one glyph, and one integer part where `formatToParts` exists), else ASCII when the text uses it, else the locale's. */
|
|
128
|
+
function reelDigits(locale, kept, text) {
|
|
129
|
+
const numberingSystem = kept.numberingSystem;
|
|
130
|
+
if (!numberingSystem)
|
|
131
|
+
return Array.from(text).some(character => asciiDigits.includes(character)) ? asciiDigits : localeDigits(locale);
|
|
132
|
+
return kept.digits === undefined ? kept.digits = systemDigits(locale, numberingSystem) : kept.digits;
|
|
133
|
+
}
|
|
134
|
+
function systemDigits(locale, numberingSystem) {
|
|
135
|
+
const formatter = new Intl.NumberFormat(locale, { numberingSystem, useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
|
136
|
+
const digits = Array.from({ length: 10 }, (_, digit) => {
|
|
137
|
+
const formatted = formatter.format(digit);
|
|
138
|
+
if (Array.from(formatted).length !== 1)
|
|
139
|
+
return '';
|
|
140
|
+
if (typeof formatter.formatToParts !== 'function')
|
|
141
|
+
return formatted;
|
|
142
|
+
const parts = formatter.formatToParts(digit);
|
|
143
|
+
return parts.length === 1 && parts[0].type === 'integer' && parts[0].value === formatted ? formatted : '';
|
|
144
|
+
});
|
|
145
|
+
return digits.every(Boolean) && new Set(digits).size === 10 ? digits : null;
|
|
146
|
+
}
|
|
147
|
+
/** Intl's own parts for the value, when the runtime has `formatToParts` and they spell `text` with at least one integer digit. */
|
|
148
|
+
function intlParts(value, locale, options, text, kept) {
|
|
149
|
+
try {
|
|
150
|
+
if (kept.parts === undefined) {
|
|
151
|
+
const built = new Intl.NumberFormat(locale, options);
|
|
152
|
+
kept.parts = typeof built.formatToParts === 'function' ? built : null;
|
|
153
|
+
}
|
|
154
|
+
const formatter = kept.parts;
|
|
155
|
+
if (!formatter)
|
|
156
|
+
return null;
|
|
157
|
+
const parts = formatter.formatToParts(value);
|
|
158
|
+
return parts.length && parts.some(part => part.type === 'integer') && parts.map(part => part.value).join('') === text ? parts : null;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** The locale's decimal separator for these options, read from formatted text: whatever sits between the digits of `1.5`. */
|
|
165
|
+
function decimalSeparator(locale, options, digits) {
|
|
166
|
+
const { style, currency, currencyDisplay, numberingSystem } = options ?? {};
|
|
167
|
+
const probe = new Intl.NumberFormat(locale, { ...(style === 'currency' && currency ? { style, currency, currencyDisplay } : null), ...(numberingSystem ? { numberingSystem } : null), useGrouping: false, minimumFractionDigits: 1, maximumFractionDigits: 1 });
|
|
168
|
+
const characters = Array.from(probe.format(1.5)), first = characters.findIndex(character => digits.includes(character));
|
|
169
|
+
let last = characters.length - 1;
|
|
170
|
+
while (last > first && !digits.includes(characters[last]))
|
|
171
|
+
last--;
|
|
172
|
+
return first >= 0 && last > first + 1 ? characters.slice(first + 1, last).join('') : null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Parts read from formatted text, for runtimes without `formatToParts` (Hermes on iOS): digits before the locale's decimal
|
|
176
|
+
* separator are the integer, digits after it the fraction, anything else between the first and last digit a group separator,
|
|
177
|
+
* and what lies outside them the sign (`-`, `−`, `+`) or literal text (currency, percent, compact and unit signs, spaces).
|
|
178
|
+
* Scientific and engineering notation are left to Intl's parts.
|
|
179
|
+
*/
|
|
180
|
+
function textParts(text, locale, options, digits, kept) {
|
|
181
|
+
if (options?.notation === 'scientific' || options?.notation === 'engineering')
|
|
182
|
+
return null;
|
|
183
|
+
const characters = Array.from(text), isDigit = (character) => digits.includes(character);
|
|
184
|
+
const first = characters.findIndex(isDigit);
|
|
185
|
+
if (first < 0)
|
|
186
|
+
return null;
|
|
187
|
+
let last = characters.length - 1;
|
|
188
|
+
while (!isDigit(characters[last]))
|
|
189
|
+
last--;
|
|
190
|
+
const separators = kept.separators ??= new Map();
|
|
191
|
+
let found = separators.get(digits);
|
|
192
|
+
if (found === undefined) {
|
|
193
|
+
found = decimalSeparator(locale, options, digits);
|
|
194
|
+
separators.set(digits, found);
|
|
195
|
+
}
|
|
196
|
+
const separator = Array.from(found ?? '');
|
|
197
|
+
let point = -1;
|
|
198
|
+
if (separator.length)
|
|
199
|
+
for (let index = first + 1; index + separator.length <= last; index++)
|
|
200
|
+
if (separator.every((character, offset) => characters[index + offset] === character)) {
|
|
201
|
+
point = index;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
const parts = [];
|
|
205
|
+
const push = (type, value) => { const previous = parts[parts.length - 1]; if (previous && previous.type === type && type !== 'decimal')
|
|
206
|
+
previous.value += value;
|
|
207
|
+
else
|
|
208
|
+
parts.push({ type, value }); };
|
|
209
|
+
for (let index = 0; index < characters.length; index++) {
|
|
210
|
+
const character = characters[index];
|
|
211
|
+
if (index === point) {
|
|
212
|
+
push('decimal', separator.join(''));
|
|
213
|
+
index += separator.length - 1;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (isDigit(character))
|
|
217
|
+
push(point >= 0 && index > point ? 'fraction' : 'integer', character);
|
|
218
|
+
else if (index > first && index < last)
|
|
219
|
+
push('group', character);
|
|
220
|
+
else
|
|
221
|
+
push(minusSign.test(character) ? 'minusSign' : character === '+' ? 'plusSign' : 'literal', character);
|
|
222
|
+
}
|
|
223
|
+
return parts;
|
|
224
|
+
}
|
|
225
|
+
/** The reels of a reading, or `null` where it is drawn static. `reading` is the readout's own text for the value (`formatNumberReadout(...).core`) when the caller already has it, so it is not formatted twice. */
|
|
226
|
+
export function createNumberReelModel(value, locale, options, formattedValue, direction, animateFormatted = false, reading) {
|
|
95
227
|
if (typeof value === 'number' && Number.isFinite(value) && formattedValue && animateFormatted && typeof Intl !== 'undefined')
|
|
96
228
|
return createFormattedReelModel(formattedValue, locale, direction);
|
|
97
229
|
if (typeof value !== 'number' || !Number.isFinite(value) || formattedValue || direction !== 'ltr' || typeof Intl === 'undefined' || typeof Intl.NumberFormat !== 'function')
|
|
98
230
|
return null;
|
|
99
231
|
try {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const canonical =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const parts = formatter.formatToParts(value);
|
|
107
|
-
if (!parts.length || parts.map(part => part.value).join('') !== canonical)
|
|
108
|
-
return null;
|
|
109
|
-
const numberingSystem = formatter.resolvedOptions().numberingSystem;
|
|
110
|
-
if (!numberingSystem)
|
|
111
|
-
return null;
|
|
112
|
-
const digitFormatter = new Intl.NumberFormat(locale, { numberingSystem, useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
|
113
|
-
if (typeof digitFormatter.formatToParts !== 'function')
|
|
232
|
+
// The reels draw the readout's own text, whose sign HIG composes (Hermes on iOS ignores `signDisplay`). Intl's parts are used
|
|
233
|
+
// when they spell exactly that text; otherwise (no `formatToParts`, or parts without the composed sign) the parts are read
|
|
234
|
+
// from the text itself, so iOS and Android roll the same reels.
|
|
235
|
+
const canonical = reading ?? formatNumberReadout(value, locale, options).core, kept = formatFor(locale, options);
|
|
236
|
+
const digits = reelDigits(locale, kept, canonical);
|
|
237
|
+
if (!digits || !safeNumberLayout(canonical, direction))
|
|
114
238
|
return null;
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
return parts.length === 1 && parts[0].type === 'integer' && parts[0].value === formatted && Array.from(formatted).length === 1 ? formatted : '';
|
|
118
|
-
});
|
|
119
|
-
if (digits.some(digit => !digit) || new Set(digits).size !== 10 || !safeNumberLayout(canonical, direction))
|
|
239
|
+
const parts = intlParts(value, locale, options, canonical, kept) ?? textParts(canonical, locale, options, digits, kept);
|
|
240
|
+
if (!parts)
|
|
120
241
|
return null;
|
|
121
242
|
const digitIndexes = new Map(digits.map((digit, index) => [digit, index]));
|
|
122
243
|
const count = (type) => parts.filter(part => part.type === type).reduce((total, part) => total + Array.from(part.value).length, 0);
|
|
@@ -157,3 +278,60 @@ export function createNumberReelModel(value, locale, options, formattedValue, di
|
|
|
157
278
|
return null;
|
|
158
279
|
}
|
|
159
280
|
}
|
|
281
|
+
/** The NumberFlow place of a reel: an integer reel's own place (0 is the ones), a negative one for a fraction reel (-1 is the tenths), `null` for an exponent's. */
|
|
282
|
+
export function numberReelPlace(token) { return token.type === 'integer' ? token.place ?? 0 : token.type === 'fraction' ? -1 - (token.place ?? 0) : null; }
|
|
283
|
+
/** The reels of a model as NumberFlow places, in display order. */
|
|
284
|
+
export function numberReelPlaces(model) {
|
|
285
|
+
return model.tokens.filter(token => token.kind === 'digit').map(token => ({ key: token.key, digit: token.digit ?? 0, place: numberReelPlace(token) }));
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Where a reel's strip sits for a position that has turned any number of times either way. The strip is `length + 1` glyphs,
|
|
289
|
+
* the last repeating the first, so every position between two digits (9 to 0 included) is two neighbouring rows. UI thread.
|
|
290
|
+
*/
|
|
291
|
+
export function numberFlowReelOffset(position, length, height) {
|
|
292
|
+
'worklet';
|
|
293
|
+
return -(((position % length) + length) % length) * height;
|
|
294
|
+
}
|
|
295
|
+
/** Progress along a sampled curve (first sample 0, last 1) at time `progress`. The UI-thread twin of `sampleNumberFlowEasing`. */
|
|
296
|
+
export function sampleReelEasing(samples, progress) {
|
|
297
|
+
'worklet';
|
|
298
|
+
const scaled = Math.max(0, Math.min(1, progress)) * (samples.length - 1), index = Math.floor(scaled), start = samples[index], end = index + 1 < samples.length ? samples[index + 1] : start;
|
|
299
|
+
return start + (end - start) * (scaled - index);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* One turn of a reel by `delta` glyphs, for `defineAnimation`. A new turn does not restart the reel: it is added to the turns
|
|
303
|
+
* still in flight, each keeping its own clock and curve, which is what NumberFlow's additive animations do on web. So a reel
|
|
304
|
+
* asked to move again while it moves keeps its speed instead of easing in from rest every time, and it always ends on the
|
|
305
|
+
* digit the last turn asked for. With nothing in flight `onFrame` reports finished and the frame callback stops. HIG's
|
|
306
|
+
* provider decides reduced motion, so the system setting is not consulted here. UI thread.
|
|
307
|
+
*/
|
|
308
|
+
export function createNumberFlowRoll(delta, duration, samples) {
|
|
309
|
+
'worklet';
|
|
310
|
+
// Reanimated drops an animation whose `current` already equals the value it is assigned to, before `onStart` runs (a timing
|
|
311
|
+
// holds its target there). This roll only knows its target once it starts, so it starts as no number at all.
|
|
312
|
+
return { type: 'hig-number-flow', current: Number.NaN, toValue: 0, turns: [], reduceMotion: false,
|
|
313
|
+
onStart(animation, value, now, previous) {
|
|
314
|
+
'worklet';
|
|
315
|
+
const continuing = !!previous && previous.type === 'hig-number-flow' && typeof previous.toValue === 'number';
|
|
316
|
+
animation.turns = continuing && previous?.turns ? previous.turns.filter(turn => now < turn.start + turn.duration) : [];
|
|
317
|
+
animation.toValue = (continuing ? previous?.toValue : Math.round(value)) + delta;
|
|
318
|
+
if (duration > 0 && delta !== 0)
|
|
319
|
+
animation.turns.push({ delta, start: now, duration });
|
|
320
|
+
animation.current = animation.turns.length ? value : animation.toValue;
|
|
321
|
+
},
|
|
322
|
+
onFrame(animation, now) {
|
|
323
|
+
'worklet';
|
|
324
|
+
let remaining = 0;
|
|
325
|
+
const active = [];
|
|
326
|
+
for (const turn of animation.turns) {
|
|
327
|
+
const progress = (now - turn.start) / turn.duration;
|
|
328
|
+
if (progress < 1) {
|
|
329
|
+
remaining += turn.delta * (1 - sampleReelEasing(samples, progress));
|
|
330
|
+
active.push(turn);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
animation.turns = active;
|
|
334
|
+
animation.current = animation.toValue - remaining;
|
|
335
|
+
return active.length === 0;
|
|
336
|
+
} };
|
|
337
|
+
}
|
|
@@ -1,11 +1,49 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type NumberFlowDigits, type NumberFlowTiming } from '@bloxwap/hig/contracts/number-flow';
|
|
2
3
|
import { type NumberProps } from './data.js';
|
|
3
4
|
import { type NumberTrend } from './animated-number-model.js';
|
|
4
5
|
export type AnimatedNumberTrend = NumberTrend;
|
|
6
|
+
export type { NumberFlowDigits, NumberFlowEasing, NumberFlowTiming } from '@bloxwap/hig/contracts/number-flow';
|
|
5
7
|
export interface AnimatedNumberProps extends NumberProps {
|
|
8
|
+
/** How long a change takes, in milliseconds. Sliding: 180 by default, at most 600. Flowing: sets the roll (900 by default) and fades take half of it; the timings below override it. Zero or less draws the new value at once. */
|
|
6
9
|
duration?: number;
|
|
10
|
+
/** Which way digits move: `1` up, `-1` down, `0` each digit its own way, or a function of the old and new value. Defaults to the direction the value moved. */
|
|
7
11
|
trend?: AnimatedNumberTrend;
|
|
12
|
+
/**
|
|
13
|
+
* How a change is drawn. `'flow'` is NumberFlow's motion: every changed digit rolls through the digits between its old and new
|
|
14
|
+
* value on NumberFlow's curve, a place the figure gains rolls up from zero as it fades in, and a new value joins the roll in
|
|
15
|
+
* flight. `'slide'` is the short settle: the reel eases straight to the new digit and a newer value retargets it.
|
|
16
|
+
* `NumberFlow` flows and `AnimatedNumberReadout` slides unless told otherwise. A reading native cannot lay out place by
|
|
17
|
+
* place (right-to-left, unmeasured glyphs) is drawn static either way.
|
|
18
|
+
*/
|
|
19
|
+
motion?: 'flow' | 'slide';
|
|
20
|
+
/** `false` draws every new value at once, with no motion, as reduced motion does. Use it for typed echoes and until first data arrives. Default `true`. */
|
|
21
|
+
animated?: boolean;
|
|
22
|
+
/** Flowing only: the roll of a changed digit. Defaults to `transformTiming`. */
|
|
23
|
+
spinTiming?: NumberFlowTiming;
|
|
24
|
+
/** Flowing only: the roll unless `spinTiming` is set. On web it also times the sideways slide when the figure changes width; native changes width at once. Default 900 ms on NumberFlow's curve. */
|
|
25
|
+
transformTiming?: NumberFlowTiming;
|
|
26
|
+
/** Flowing only: the fade of a place that arrives. Default 450 ms ease-out. */
|
|
27
|
+
opacityTiming?: NumberFlowTiming;
|
|
28
|
+
/** Flowing only: a limit for an integer place, keyed by place (0 is the ones). `{1:{max:5}}` makes the tens of a seconds counter wrap from 5 to 0. */
|
|
29
|
+
digits?: NumberFlowDigits;
|
|
30
|
+
/** Flowing only, with a trend: every place below the highest one that changed turns once all the way round even when its digit is the same, so the figure reads as counting through the values between. */
|
|
31
|
+
continuous?: boolean;
|
|
32
|
+
/** Accepted so one call site serves both platforms. Web keeps the moving parts on their own layers; native reels already are. */
|
|
33
|
+
willChange?: boolean;
|
|
8
34
|
/** With `formattedValue`, moves the host's text place by place: each digit it contains rolls in place, counted from the end, and the rest stays as written. Without it `formattedValue` is drawn static, as before. */
|
|
9
35
|
animateFormatted?: boolean;
|
|
10
36
|
}
|
|
11
|
-
|
|
37
|
+
/** `AnimatedNumberReadout` with NumberFlow's motion by default: the same component and the same props, under the name the product uses for it. */
|
|
38
|
+
export declare function NumberFlow({ motion, ...props }: AnimatedNumberProps): React.JSX.Element;
|
|
39
|
+
export type NumberFlowProps = AnimatedNumberProps;
|
|
40
|
+
/** On web, moves the flowing figures inside it together when one changes width. Native figures change width at once, so this draws its children and nothing else; it exists so one tree serves both platforms. */
|
|
41
|
+
export declare function NumberFlowGroup({ children }: {
|
|
42
|
+
children?: React.ReactNode;
|
|
43
|
+
}): React.JSX.Element;
|
|
44
|
+
/**
|
|
45
|
+
* A number that moves place by place when its value changes. It slides by default; `motion='flow'` (or `NumberFlow`, which is
|
|
46
|
+
* this component flowing by default) gives it NumberFlow's motion. Either way assistive technology gets one static reading,
|
|
47
|
+
* and reduced motion draws each new value at once.
|
|
48
|
+
*/
|
|
49
|
+
export declare function AnimatedNumberReadout({ value, options: requested, formattedValue, animateFormatted, stale, label, tone, style, testID, maxFontSizeMultiplier, trend, prefix, suffix, duration: requestedDuration, motion, animated, spinTiming, transformTiming, opacityTiming, digits, continuous }: AnimatedNumberProps): React.JSX.Element;
|
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { PixelRatio, StyleSheet, View } from 'react-native';
|
|
5
|
-
import Reanimated, { cancelAnimation, Easing, ReduceMotion, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
5
|
+
import Reanimated, { cancelAnimation, defineAnimation, Easing, ReduceMotion, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import { numberFlowDeltas, numberFlowDigitLength, numberFlowEasingSamples, resolveNumberFlowTimings } from '@bloxwap/hig/contracts/number-flow';
|
|
6
7
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
7
8
|
import { presentNumberFormat } from '@bloxwap/hig/contracts';
|
|
8
9
|
import { tokens } from '@bloxwap/hig/tokens';
|
|
9
|
-
import { createNumberReelModel, formatNumberReadout, numberTrendDirection, safeNumberLayout } from './animated-number-model.js';
|
|
10
|
+
import { createNumberFlowRoll, createNumberReelModel, formatNumberReadout, numberFlowReelOffset, numberReelPlace, numberReelPlaces, numberTrendDirection, safeNumberLayout, sampleReelEasing } from './animated-number-model.js';
|
|
10
11
|
import { useColors, useHIG, useNumberLocale } from './provider.js';
|
|
11
12
|
import { detectScript, Text } from './surface.js';
|
|
12
|
-
const numberTypographyKeys = new Set(['fontFamily', 'fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'textAlign']);
|
|
13
|
+
const numberTypographyKeys = new Set(['fontFamily', 'fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'textAlign', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle']);
|
|
13
14
|
// Android Fabric reads colour 0 as "unset", so 'transparent' (0x00000000) drew the hidden reading in the default
|
|
14
15
|
// black under the reels. Clear white is non-zero there and still invisible.
|
|
15
|
-
const
|
|
16
|
+
const hiddenColor = '#ffffff00';
|
|
17
|
+
// While the reels draw, the reading stays for assistive technology and tests but leaves the flow, so the readout is sized by
|
|
18
|
+
// what it draws. It sits on the side the figure is aligned to; in a row it is measured at its own width and never wraps.
|
|
19
|
+
const hiddenReading = { left: { color: hiddenColor, position: 'absolute', top: 0, left: 0 }, right: { color: hiddenColor, position: 'absolute', top: 0, right: 0 }, center: { color: hiddenColor, position: 'absolute', top: 0, left: 0, right: 0 } };
|
|
20
|
+
// The reel row is the readout's in-flow content: it keeps its content width (no shrink) and the readout takes that width.
|
|
21
|
+
const reelRowStyle = { flexDirection: 'row', alignItems: 'center', flexShrink: 0, direction: 'ltr' };
|
|
16
22
|
const clampedDuration = (duration) => Number.isFinite(duration) && duration > 0 ? Math.min(duration, 600) : 0;
|
|
17
|
-
|
|
23
|
+
const sameGlyphs = (first, second) => first === second || (first.length === second.length && first.every((glyph, index) => glyph === second[index]));
|
|
24
|
+
/**
|
|
25
|
+
* One place of a sliding figure: twenty glyphs in a column behind a window one glyph high. A readout draws again for every
|
|
26
|
+
* value (and whenever its parent does), and most of its places have the digit they had, so a reel is drawn again only when its
|
|
27
|
+
* digit, its motion or its face changes. The trend alone does not count: it only matters to a digit that changed.
|
|
28
|
+
*/
|
|
29
|
+
const DigitReel = memo(function DigitReel({ digits, digit, trend, duration, reducedMotion, width, height, style, styleKey, script, maxFontSizeMultiplier }) {
|
|
18
30
|
const position = useSharedValue(digit), previousDigit = useRef(digit);
|
|
19
|
-
const animatedStyle = useAnimatedStyle(() =>
|
|
31
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
32
|
+
'worklet';
|
|
33
|
+
return { transform: [{ translateY: -position.value * height }] };
|
|
34
|
+
}, [height]);
|
|
20
35
|
useEffect(() => {
|
|
21
36
|
const motionDuration = clampedDuration(duration);
|
|
22
37
|
if (previousDigit.current === digit) {
|
|
@@ -54,9 +69,86 @@ function DigitReel({ digits, digit, trend, duration, reducedMotion, width, heigh
|
|
|
54
69
|
position.value = withTiming(destination, { duration: motionDuration, easing: Easing.bezier(...tokens.easing.standard), reduceMotion: ReduceMotion.Never });
|
|
55
70
|
}, [digit, trend, duration, reducedMotion, position]);
|
|
56
71
|
useEffect(() => () => cancelAnimation(position), [position]);
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
// The rows only change with the face, so they are the same elements while the reel turns: a new digit moves the column and draws no text again.
|
|
73
|
+
const rows = useMemo(() => Array.from({ length: 20 }, (_, index) => { const glyph = digits[index % 10]; return _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [style, { width, height, textAlign: 'center' }], children: glyph }, `${index}:${glyph}`); }), [digits, width, height, styleKey, script, maxFontSizeMultiplier]);
|
|
74
|
+
return _jsx(View, { collapsable: false, style: { width, height, overflow: 'hidden' }, children: _jsx(Reanimated.View, { style: animatedStyle, children: rows }) });
|
|
75
|
+
}, (previous, next) => previous.digit === next.digit && previous.duration === next.duration && previous.reducedMotion === next.reducedMotion && sameGlyphs(previous.digits, next.digits) && previous.width === next.width && previous.height === next.height && previous.styleKey === next.styleKey && previous.script === next.script && previous.maxFontSizeMultiplier === next.maxFontSizeMultiplier);
|
|
76
|
+
/**
|
|
77
|
+
* The moving part of a flowing place: `length + 1` glyphs in a column, translated on the UI thread. It mounts on the place's
|
|
78
|
+
* first turn, already showing the digit it replaces, and stays for the turns after it. Its position counts glyphs on a reel of
|
|
79
|
+
* `length`, so a turn on a reel of another length (a limited place given a digit past its limit, or back) starts from the
|
|
80
|
+
* digit it replaces rather than from a position counted on the old reel.
|
|
81
|
+
*/
|
|
82
|
+
function FlowStrip({ glyphs, length, from, digit, delta, step, enter, duration, samples, fade, fadeSamples, width, height, style, styleKey, script, maxFontSizeMultiplier }) {
|
|
83
|
+
const position = useSharedValue(from), opacity = useSharedValue(enter && fade > 0 ? 0 : 1), applied = useRef(null);
|
|
84
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
85
|
+
'worklet';
|
|
86
|
+
return { opacity: opacity.value, transform: [{ translateY: numberFlowReelOffset(position.value, length, height) }] };
|
|
87
|
+
}, [length, height]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const last = applied.current;
|
|
90
|
+
applied.current = { step, digit, length };
|
|
91
|
+
if (!last || last.step !== step) {
|
|
92
|
+
if (duration > 0 && delta) {
|
|
93
|
+
// A reel of another length: what is in flight was counted on the old one, so this turn starts from the digit it replaces.
|
|
94
|
+
if (last && last.length !== length) {
|
|
95
|
+
cancelAnimation(position);
|
|
96
|
+
position.value = digit - delta;
|
|
97
|
+
}
|
|
98
|
+
// A new turn joins whatever is still in flight; the roll works out where it ends from where the reel was going.
|
|
99
|
+
position.value = defineAnimation(digit, () => {
|
|
100
|
+
'worklet';
|
|
101
|
+
return createNumberFlowRoll(delta, duration, samples);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
cancelAnimation(position);
|
|
106
|
+
position.value = digit;
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// Motion was turned off, the digit changed without a turn or the reel changed length: land on the digit, cutting short whatever was in flight.
|
|
111
|
+
if (last.digit !== digit || last.length !== length || duration <= 0) {
|
|
112
|
+
cancelAnimation(position);
|
|
113
|
+
position.value = digit;
|
|
114
|
+
}
|
|
115
|
+
}, [step, digit, delta, length, duration, samples, position]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!enter)
|
|
118
|
+
return;
|
|
119
|
+
if (fade > 0)
|
|
120
|
+
opacity.value = withTiming(1, { duration: fade, easing: (progress) => {
|
|
121
|
+
'worklet';
|
|
122
|
+
return sampleReelEasing(fadeSamples, progress);
|
|
123
|
+
}, reduceMotion: ReduceMotion.Never });
|
|
124
|
+
// Motion was turned off while the place was still arriving: it is simply there.
|
|
125
|
+
else {
|
|
126
|
+
cancelAnimation(opacity);
|
|
127
|
+
opacity.value = 1;
|
|
128
|
+
}
|
|
129
|
+
}, [enter, fade, fadeSamples, opacity]);
|
|
130
|
+
// Forgetting the applied turn lets an effect that runs again after this cleanup (React's development double mount) start it again rather than leave the reel where the cancel stopped it.
|
|
131
|
+
useEffect(() => () => { cancelAnimation(position); cancelAnimation(opacity); applied.current = null; }, [position, opacity]);
|
|
132
|
+
// The rows only change with the reel and the face, so they are the same elements from one turn to the next: a turn moves the strip and draws no text again.
|
|
133
|
+
const rows = useMemo(() => Array.from({ length: length + 1 }, (_, index) => _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [style, { width, height, textAlign: 'center' }], children: glyphs[index % length] }, index)), [glyphs, length, width, height, styleKey, script, maxFontSizeMultiplier]);
|
|
134
|
+
return _jsx(Reanimated.View, { style: animatedStyle, children: rows });
|
|
59
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* One place of a flowing figure. At rest it is a single glyph in a box the size of the widest digit; the strip that rolls
|
|
138
|
+
* mounts the first time the place turns, so a screen of figures that never change mounts one text per digit. A place that
|
|
139
|
+
* joins a figure already on screen arrives turning, from zero.
|
|
140
|
+
*/
|
|
141
|
+
const FlowDigit = memo(function FlowDigit(props) {
|
|
142
|
+
const { glyphs, digit, delta, step, width, height, style, script, maxFontSizeMultiplier } = props;
|
|
143
|
+
// Where the strip starts from. Set during render, so the strip mounts in the commit that first turns the place.
|
|
144
|
+
const [strip, setStrip] = useState(step > 0 && delta !== 0 ? { from: digit - delta, enter: true } : null);
|
|
145
|
+
if (!strip && step > 0 && delta !== 0)
|
|
146
|
+
setStrip({ from: digit - delta, enter: false });
|
|
147
|
+
return _jsx(View, { collapsable: false, style: { width, height, overflow: 'hidden' }, children: strip ? _jsx(FlowStrip, { ...props, from: strip.from, enter: strip.enter }) : _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [style, { width, height, textAlign: 'center' }], children: glyphs[digit] }) });
|
|
148
|
+
}, (previous, next) => previous.digit === next.digit && previous.step === next.step && previous.delta === next.delta && previous.length === next.length && sameGlyphs(previous.glyphs, next.glyphs) && previous.width === next.width && previous.height === next.height && previous.duration === next.duration && previous.samples === next.samples && previous.fade === next.fade && previous.fadeSamples === next.fadeSamples && previous.styleKey === next.styleKey && previous.script === next.script && previous.maxFontSizeMultiplier === next.maxFontSizeMultiplier);
|
|
149
|
+
/** A part of the figure that does not turn: a sign, a separator, an affix. Drawn again only when its text or its face changes. */
|
|
150
|
+
const StillPart = memo(function StillPart({ text, style, script, maxFontSizeMultiplier }) { return _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: style, children: text }); }, (previous, next) => previous.text === next.text && previous.styleKey === next.styleKey && previous.script === next.script && previous.maxFontSizeMultiplier === next.maxFontSizeMultiplier);
|
|
151
|
+
const noTurns = new Map();
|
|
60
152
|
function recordGlyph(measurements, key, index, event, setMetrics) {
|
|
61
153
|
const { width, height } = event.nativeEvent.layout;
|
|
62
154
|
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0)
|
|
@@ -69,18 +161,32 @@ function recordGlyph(measurements, key, index, event, setMetrics) {
|
|
|
69
161
|
return;
|
|
70
162
|
setMetrics(current => current?.key === key && current.width === measuredWidth && current.height === measuredHeight ? current : { key, width: measuredWidth, height: measuredHeight });
|
|
71
163
|
}
|
|
72
|
-
|
|
164
|
+
/** `AnimatedNumberReadout` with NumberFlow's motion by default: the same component and the same props, under the name the product uses for it. */
|
|
165
|
+
export function NumberFlow({ motion = 'flow', ...props }) { return _jsx(AnimatedNumberReadout, { motion: motion, ...props }); }
|
|
166
|
+
/** On web, moves the flowing figures inside it together when one changes width. Native figures change width at once, so this draws its children and nothing else; it exists so one tree serves both platforms. */
|
|
167
|
+
export function NumberFlowGroup({ children }) { return _jsx(_Fragment, { children: children }); }
|
|
168
|
+
/**
|
|
169
|
+
* A number that moves place by place when its value changes. It slides by default; `motion='flow'` (or `NumberFlow`, which is
|
|
170
|
+
* this component flowing by default) gives it NumberFlow's motion. Either way assistive technology gets one static reading,
|
|
171
|
+
* and reduced motion draws each new value at once.
|
|
172
|
+
*/
|
|
173
|
+
export function AnimatedNumberReadout({ value, options: requested, formattedValue, animateFormatted, stale, label, tone = 'text', style, testID, maxFontSizeMultiplier, trend, prefix, suffix, duration: requestedDuration, motion = 'slide', animated = true, spinTiming, transformTiming, opacityTiming, digits, continuous = false }) {
|
|
174
|
+
const duration = requestedDuration ?? 180, flow = motion === 'flow';
|
|
73
175
|
const locale = useNumberLocale();
|
|
74
|
-
const { messages, direction, reducedMotion, fontFamily, fontFamilies, fontFamiliesByScript, letterSpacingByScript, maxFontSizeMultiplier: providerMaxFontSizeMultiplier, numberFormat } = useHIG(), colors = useColors();
|
|
75
|
-
const options = presentNumberFormat(requested, numberFormat);
|
|
76
|
-
|
|
176
|
+
const { messages, direction, reducedMotion: reduced, fontFamily, fontFamilies, fontFamiliesByScript, letterSpacingByScript, maxFontSizeMultiplier: providerMaxFontSizeMultiplier, numberFormat } = useHIG(), colors = useColors(), reducedMotion = reduced || !animated;
|
|
177
|
+
const options = presentNumberFormat(requested, numberFormat), optionsKey = options ? JSON.stringify(options) : '';
|
|
178
|
+
// The reading and its reels depend on the value and the format alone. A readout draws more often than its value changes (its
|
|
179
|
+
// parent draws, the digits are measured, a turn is worked out), and none of those renders formats anything again.
|
|
180
|
+
const reading = useMemo(() => formatNumberReadout(value, locale, options, formattedValue, prefix, suffix), [value, locale, optionsKey, formattedValue, prefix, suffix]), staleSuffix = stale ? ` ${messages.stale ?? en.stale}` : '';
|
|
77
181
|
const previousValue = useRef(value), directionTrend = numberTrendDirection(trend, previousValue.current, value);
|
|
78
182
|
useEffect(() => { previousValue.current = value; }, [value]);
|
|
79
183
|
const typography = Object.fromEntries(Object.entries(StyleSheet.flatten(style) ?? {}).filter(([key]) => numberTypographyKeys.has(key)));
|
|
184
|
+
if (typography.fontSize !== undefined && typography.lineHeight === undefined)
|
|
185
|
+
typography.lineHeight = undefined;
|
|
80
186
|
const color = colors[tone === 'positive' || tone === 'negative' || tone === 'warning' || tone === 'muted' || tone === 'faint' || tone === 'up' || tone === 'down' ? tone : 'text'];
|
|
81
187
|
const textStyle = [typography, { color, fontVariant: ['tabular-nums'] }];
|
|
82
188
|
const script = detectScript(`${reading.text}${staleSuffix}`, locale);
|
|
83
|
-
const model = createNumberReelModel(value, locale, options, formattedValue, direction, animateFormatted);
|
|
189
|
+
const model = useMemo(() => createNumberReelModel(value, locale, options, formattedValue, direction, animateFormatted, reading.core), [value, locale, optionsKey, formattedValue, direction, animateFormatted]);
|
|
84
190
|
const safeModel = model && safeNumberLayout(`${prefix ?? ''}${suffix ?? ''}${staleSuffix}`, direction) ? model : null;
|
|
85
191
|
let fontScale = 0;
|
|
86
192
|
try {
|
|
@@ -94,7 +200,48 @@ export function AnimatedNumberReadout({ value, options: requested, formattedValu
|
|
|
94
200
|
const [metrics, setMetrics] = useState(null);
|
|
95
201
|
const activeModel = safeModel && fontScale > 0 && Number.isFinite(fontScale) && metrics?.key === measurementKey ? safeModel : null;
|
|
96
202
|
const activeMetrics = activeModel ? metrics : null;
|
|
97
|
-
const
|
|
203
|
+
const align = typography.textAlign === 'right' ? 'right' : typography.textAlign === 'center' ? 'center' : 'left';
|
|
204
|
+
const justifyContent = align === 'right' ? 'flex-end' : align === 'center' ? 'center' : 'flex-start';
|
|
98
205
|
const visualProps = { accessible: false, script, maxFontSizeMultiplier };
|
|
99
|
-
|
|
206
|
+
// Flowing: the turn of every place for this change, worked out in the render that first draws the new reading so the places
|
|
207
|
+
// that turn get their strip in the same commit. Kept in state (not a ref) so a render React throws away leaves no trace.
|
|
208
|
+
const timings = resolveNumberFlowTimings({ duration: requestedDuration, spinTiming, transformTiming, opacityTiming }), spinSamples = numberFlowEasingSamples(timings.spin.easing), fadeSamples = numberFlowEasingSamples(timings.opacity.easing);
|
|
209
|
+
const [flowStep, setFlowStep] = useState(null);
|
|
210
|
+
let turns = noTurns;
|
|
211
|
+
if (flow && activeModel) {
|
|
212
|
+
// A new locale or format is a different reading rather than a new value, as on web: it is drawn at once and the next value rolls from it.
|
|
213
|
+
const signature = `${locale}\u0000${optionsKey}\u0000${formattedValue ? 1 : 0}`;
|
|
214
|
+
if (!flowStep || flowStep.key !== measurementKey || flowStep.signature !== signature)
|
|
215
|
+
setFlowStep({ key: measurementKey, signature, canonical: activeModel.canonical, value, places: numberReelPlaces(activeModel), turns: noTurns });
|
|
216
|
+
else if (flowStep.canonical !== activeModel.canonical) {
|
|
217
|
+
const places = numberReelPlaces(activeModel), moving = !reducedMotion && timings.spin.duration > 0, deltas = moving ? numberFlowDeltas(flowStep.places, places, { trend: numberTrendDirection(trend, flowStep.value, value), digits, continuous }) : null, before = new Map(flowStep.places.map(place => [place.key, place.digit])), next = new Map();
|
|
218
|
+
for (const place of places) {
|
|
219
|
+
const delta = deltas?.get(place.key) ?? 0, old = flowStep.turns.get(place.key);
|
|
220
|
+
// The same reel the shared model counted the turn on: long enough for both ends of it.
|
|
221
|
+
if (delta)
|
|
222
|
+
next.set(place.key, { step: (old?.step ?? 0) + 1, delta, length: numberFlowDigitLength(digits, place.place, Math.max(place.digit, before.get(place.key) ?? 0)) });
|
|
223
|
+
// No turn: the place keeps its reel while its digit still fits it.
|
|
224
|
+
else if (old)
|
|
225
|
+
next.set(place.key, place.digit < old.length ? old : { ...old, length: numberFlowDigitLength(digits, place.place, place.digit) });
|
|
226
|
+
}
|
|
227
|
+
setFlowStep({ key: measurementKey, signature, canonical: activeModel.canonical, value, places, turns: next });
|
|
228
|
+
turns = next;
|
|
229
|
+
}
|
|
230
|
+
else
|
|
231
|
+
turns = flowStep.turns;
|
|
232
|
+
}
|
|
233
|
+
else if (flowStep)
|
|
234
|
+
setFlowStep(null);
|
|
235
|
+
const styleKey = JSON.stringify([typography, color]), partProps = { style: textStyle, styleKey, script, maxFontSizeMultiplier };
|
|
236
|
+
// The ten digits, measured for a face and size: drawn again when what is measured changes, not with every value.
|
|
237
|
+
const probes = useMemo(() => safeModel ? _jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', pointerEvents: 'none', style: { position: 'absolute', opacity: 0, flexDirection: 'row' }, children: safeModel.digits.map((glyph, index) => _createElement(Text, { ...visualProps, key: `${measurementKey}:${index}`, onLayout: event => recordGlyph(measurements, measurementKey, index, event, setMetrics), style: textStyle }, glyph)) }) : null, [measurementKey, color]);
|
|
238
|
+
// The reels are drawn in the readout's flow, so the readout is exactly as wide as the row it draws: the composed sign, every
|
|
239
|
+
// static part read from the text, each reel at the widest digit's advance and the affixes, each its own text, measured by
|
|
240
|
+
// the layout pass that draws it. The reading they replace leaves the flow (it stays, invisible, for assistive technology).
|
|
241
|
+
// Before, the reels were an overlay on the reading, and the readout only grew to the reels after their row reported its
|
|
242
|
+
// width; on the Seeker (Android) the readout kept the reading's width, so `+100.00%` drew past its box into the following
|
|
243
|
+
// ` on margin`. Wherever the parts are wider than the reading (separate texts lose the reading's kerning, a face without
|
|
244
|
+
// tabular digits), the readout is now wider by that much; where they match (iOS), nothing moves. Each reel clips its own
|
|
245
|
+
// column, so nothing bleeds vertically, and no frame clips a glyph.
|
|
246
|
+
return _jsxs(View, { collapsable: false, style: activeModel ? { position: 'relative', flexDirection: 'row', alignItems: 'center', justifyContent } : { position: 'relative' }, children: [_jsxs(Text, { accessibilityLabel: label ? `${label}: ${reading.text}${staleSuffix}` : undefined, testID: testID, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [textStyle, activeModel ? hiddenReading[align] : undefined], children: [reading.text, staleSuffix] }), probes, activeModel && activeMetrics && _jsxs(View, { collapsable: false, accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', pointerEvents: 'none', style: reelRowStyle, children: [prefix && _jsx(StillPart, { ...partProps, text: prefix }), activeModel.tokens.map(token => token.kind === 'static' ? _createElement(StillPart, { ...partProps, key: token.key, text: token.value }) : flow ? _jsx(FlowDigit, { glyphs: activeModel.digits, length: turns.get(token.key)?.length ?? numberFlowDigitLength(digits, numberReelPlace(token), token.digit ?? 0), digit: token.digit ?? 0, delta: turns.get(token.key)?.delta ?? 0, step: turns.get(token.key)?.step ?? 0, duration: reducedMotion ? 0 : timings.spin.duration, samples: spinSamples, fade: reducedMotion ? 0 : timings.opacity.duration, fadeSamples: fadeSamples, width: activeMetrics.width, height: activeMetrics.height, style: textStyle, styleKey: styleKey, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier }, token.key) : _jsx(DigitReel, { digits: activeModel.digits, digit: token.digit ?? 0, trend: directionTrend, duration: duration, reducedMotion: reducedMotion, width: activeMetrics.width, height: activeMetrics.height, style: textStyle, styleKey: styleKey, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier }, token.key)), (suffix || staleSuffix) && _jsx(StillPart, { ...partProps, text: `${suffix ?? ''}${staleSuffix}` })] })] });
|
|
100
247
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Speaks a message to VoiceOver or TalkBack. On iOS an error interrupts what is being read and anything else queues behind it; Android's announcement has no interrupting mode. A failure is swallowed: the visible text remains. */
|
|
2
|
+
export declare function speak(message: string, severity: string): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AccessibilityInfo, Platform } from 'react-native';
|
|
2
|
+
/** Speaks a message to VoiceOver or TalkBack. On iOS an error interrupts what is being read and anything else queues behind it; Android's announcement has no interrupting mode. A failure is swallowed: the visible text remains. */
|
|
3
|
+
export function speak(message, severity) { if (Platform.OS === 'web' || !message)
|
|
4
|
+
return; try {
|
|
5
|
+
if (Platform.OS === 'ios' && typeof AccessibilityInfo.announceForAccessibilityWithOptions === 'function')
|
|
6
|
+
AccessibilityInfo.announceForAccessibilityWithOptions(message, { queue: severity !== 'error' });
|
|
7
|
+
else
|
|
8
|
+
AccessibilityInfo.announceForAccessibility(message);
|
|
9
|
+
}
|
|
10
|
+
catch { /* The visible message and navigable text remain available. */ } }
|
|
@@ -24,6 +24,8 @@ export interface AssetBalanceRowProps {
|
|
|
24
24
|
trailing?: React.ReactNode;
|
|
25
25
|
/** What the row reads for `trailing`, in place of its text, for an icon or a figure whose text is not what should be heard. */
|
|
26
26
|
trailingLabel?: string;
|
|
27
|
+
/** `trailing` holds a control, such as a Copy or Remove button: it stays its own accessibility element and touch target beside the row, out of the row's reading and outside the row's press (`<testID>-trailing`). The rest of the row is then one element (with `onSelect`, the button `<testID>-main`) read as before without the trailing text. */
|
|
28
|
+
trailingInteractive?: boolean;
|
|
27
29
|
/** Marks the row in use: a check on the trailing edge and `accessibilityState.selected`. */
|
|
28
30
|
selected?: boolean;
|
|
29
31
|
/** Dims the row, ignores presses and reads as unavailable. */
|
|
@@ -33,4 +35,4 @@ export interface AssetBalanceRowProps {
|
|
|
33
35
|
testID?: string;
|
|
34
36
|
}
|
|
35
37
|
/** One holding as a capsule row: a round avatar, the asset's name over its symbol, and its dollar value over its units. The avatar is padded equally on every side, so the capsule end is concentric with it, and both numbers update place by place. */
|
|
36
|
-
export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, unitsSuffix, headline, amounts, tag, trailing, trailingLabel, selected, disabled, onSelect, testID }: AssetBalanceRowProps): React.JSX.Element;
|
|
38
|
+
export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, unitsSuffix, headline, amounts, tag, trailing, trailingLabel, trailingInteractive, selected, disabled, onSelect, testID }: AssetBalanceRowProps): React.JSX.Element;
|