@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.
- 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 +45 -2
- package/contracts/dist/index.js +145 -4
- package/contracts/dist/invariants.d.ts +17 -0
- package/contracts/dist/invariants.js +24 -0
- package/contracts/dist/messages.d.ts +62 -2
- package/contracts/dist/messages.js +22 -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 +62 -7
- package/native/dist/account-block.js +54 -11
- package/native/dist/animated-number-model.d.ts +47 -1
- package/native/dist/animated-number-model.js +248 -21
- package/native/dist/animated-number.d.ts +41 -1
- package/native/dist/animated-number.js +165 -17
- package/native/dist/announce.d.ts +2 -0
- package/native/dist/announce.js +10 -0
- package/native/dist/asset-balance-row.d.ts +19 -1
- package/native/dist/asset-balance-row.js +24 -8
- 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 +16 -2
- package/native/dist/bar-mark.js +23 -7
- package/native/dist/bar-pnl.js +7 -5
- package/native/dist/blocks.d.ts +13 -14
- package/native/dist/blocks.js +10 -6
- package/native/dist/brand.js +2 -1
- package/native/dist/button.d.ts +7 -2
- package/native/dist/button.js +16 -4
- 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 +8 -4
- package/native/dist/explainer-block.d.ts +91 -0
- package/native/dist/explainer-block.js +34 -0
- package/native/dist/field.d.ts +19 -5
- package/native/dist/field.js +56 -9
- package/native/dist/figure.d.ts +23 -0
- package/native/dist/figure.js +10 -0
- 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 +14 -1
- package/native/dist/language-block.js +11 -4
- package/native/dist/list-group.d.ts +44 -8
- package/native/dist/list-group.js +84 -13
- package/native/dist/manage-position-block.d.ts +35 -2
- package/native/dist/manage-position-block.js +41 -11
- package/native/dist/market-row.d.ts +46 -0
- package/native/dist/market-row.js +41 -0
- package/native/dist/navigation.js +5 -3
- package/native/dist/notifications-block.d.ts +30 -2
- package/native/dist/notifications-block.js +16 -8
- package/native/dist/number-format.d.ts +6 -0
- package/native/dist/number-format.js +9 -0
- package/native/dist/pickers.d.ts +32 -2
- package/native/dist/pickers.js +17 -9
- package/native/dist/position-block.d.ts +66 -10
- package/native/dist/position-block.js +45 -11
- 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 +38 -5
- package/native/dist/profile-block.js +31 -6
- package/native/dist/provider.d.ts +14 -5
- package/native/dist/provider.js +32 -6
- package/native/dist/qr-code.d.ts +33 -0
- package/native/dist/qr-code.js +29 -0
- package/native/dist/radio-group.d.ts +23 -5
- package/native/dist/radio-group.js +40 -12
- package/native/dist/recipes.d.ts +6 -0
- package/native/dist/recipes.js +6 -0
- package/native/dist/reward-block.d.ts +55 -13
- package/native/dist/reward-block.js +37 -14
- package/native/dist/screen-header.d.ts +59 -0
- package/native/dist/screen-header.js +37 -0
- package/native/dist/select.js +4 -2
- package/native/dist/selection.d.ts +3 -2
- package/native/dist/selection.js +1 -0
- package/native/dist/setting-header.d.ts +2 -8
- package/native/dist/setting-header.js +2 -11
- package/native/dist/setting-switch.d.ts +15 -2
- package/native/dist/setting-switch.js +11 -4
- package/native/dist/signals-block.d.ts +26 -2
- package/native/dist/signals-block.js +14 -4
- package/native/dist/slider.js +5 -1
- package/native/dist/sound-haptics-block.d.ts +29 -2
- package/native/dist/sound-haptics-block.js +19 -8
- package/native/dist/status.d.ts +47 -14
- package/native/dist/status.js +39 -22
- package/native/dist/sticky-header.d.ts +28 -0
- package/native/dist/sticky-header.js +29 -0
- package/native/dist/surface.d.ts +3 -1
- package/native/dist/surface.js +2 -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 +11 -4
- package/native/dist/swap-panel-block.js +67 -38
- package/native/dist/swap-parts.d.ts +5 -10
- package/native/dist/swap-parts.js +22 -24
- package/native/dist/swap-shared.d.ts +8 -2
- package/native/dist/swap-shared.js +10 -6
- package/native/dist/swap-views.js +6 -4
- package/native/dist/switch-row.d.ts +3 -2
- package/native/dist/switch-row.js +5 -3
- package/native/dist/switch.d.ts +4 -2
- package/native/dist/switch.js +3 -3
- package/native/dist/target-block.d.ts +40 -7
- package/native/dist/target-block.js +31 -11
- package/native/dist/toast.d.ts +47 -0
- package/native/dist/toast.js +386 -0
- package/native/dist/token-action-block.d.ts +26 -9
- package/native/dist/token-action-block.js +21 -8
- package/native/dist/trade-history-detail-block.d.ts +26 -1
- package/native/dist/trade-history-detail-block.js +17 -9
- package/native/dist/trade-history-list-block.d.ts +71 -5
- package/native/dist/trade-history-list-block.js +55 -17
- package/native/dist/wallet-address-core.d.ts +25 -0
- package/native/dist/wallet-address-core.js +34 -0
- package/native/dist/wallet-address.d.ts +6 -10
- package/native/dist/wallet-address.js +16 -20
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +131 -2
- 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 +24 -0
- package/react/dist/animated-number-model.js +106 -3
- package/react/dist/animated-number.d.ts +49 -1
- package/react/dist/animated-number.js +146 -11
- package/react/dist/asset-balance-row.d.ts +19 -1
- package/react/dist/asset-balance-row.js +17 -3
- 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/bar-mark.d.ts +5 -2
- package/react/dist/bar-mark.js +5 -3
- package/react/dist/blocks/account-block.d.ts +57 -7
- package/react/dist/blocks/account-block.js +51 -11
- 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/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 +9 -1
- package/react/dist/blocks/language-block.js +8 -6
- package/react/dist/blocks/manage-position-block.d.ts +30 -2
- package/react/dist/blocks/manage-position-block.js +23 -4
- package/react/dist/blocks/market-row.d.ts +20 -9
- package/react/dist/blocks/market-row.js +17 -4
- package/react/dist/blocks/notifications-block.d.ts +27 -2
- package/react/dist/blocks/notifications-block.js +11 -2
- package/react/dist/blocks/pickers.d.ts +30 -1
- package/react/dist/blocks/pickers.js +32 -10
- package/react/dist/blocks/position-block.d.ts +34 -11
- package/react/dist/blocks/position-block.js +16 -5
- 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 +33 -6
- package/react/dist/blocks/profile-block.js +31 -6
- package/react/dist/blocks/reward-block.d.ts +65 -21
- package/react/dist/blocks/reward-block.js +24 -11
- package/react/dist/blocks/screen-header.d.ts +34 -2
- package/react/dist/blocks/screen-header.js +17 -6
- package/react/dist/blocks/setting-switch.d.ts +14 -1
- package/react/dist/blocks/setting-switch.js +11 -4
- package/react/dist/blocks/signals-block.d.ts +23 -2
- package/react/dist/blocks/signals-block.js +6 -5
- package/react/dist/blocks/sound-haptics-block.d.ts +27 -3
- package/react/dist/blocks/sound-haptics-block.js +11 -7
- package/react/dist/blocks/sticky-header.d.ts +19 -0
- package/react/dist/blocks/sticky-header.js +103 -0
- package/react/dist/blocks/swap/amount-card.js +2 -1
- package/react/dist/blocks/swap/settings.js +4 -3
- package/react/dist/blocks/swap/shared.d.ts +29 -23
- package/react/dist/blocks/swap/shared.js +36 -32
- package/react/dist/blocks/swap-panel-block.d.ts +12 -3
- package/react/dist/blocks/swap-panel-block.js +72 -37
- package/react/dist/blocks/target-block.d.ts +35 -7
- package/react/dist/blocks/target-block.js +26 -12
- package/react/dist/blocks/token-action-block.d.ts +21 -8
- package/react/dist/blocks/token-action-block.js +9 -6
- package/react/dist/blocks/trade-history-detail-block.d.ts +23 -1
- package/react/dist/blocks/trade-history-detail-block.js +5 -4
- package/react/dist/blocks/trade-history-list-block.d.ts +31 -5
- package/react/dist/blocks/trade-history-list-block.js +20 -10
- package/react/dist/blocks.d.ts +12 -8
- package/react/dist/blocks.js +6 -2
- package/react/dist/brand.js +2 -1
- package/react/dist/button.d.ts +9 -3
- package/react/dist/button.js +12 -5
- package/react/dist/confetti.d.ts +27 -0
- package/react/dist/confetti.js +240 -0
- package/react/dist/data.js +11 -4
- package/react/dist/field.d.ts +20 -5
- package/react/dist/field.js +30 -8
- package/react/dist/figure.d.ts +23 -0
- package/react/dist/figure.js +12 -0
- package/react/dist/gesture-sheet.d.ts +15 -1
- package/react/dist/gesture-sheet.js +53 -8
- package/react/dist/list-group.d.ts +41 -8
- package/react/dist/list-group.js +49 -13
- package/react/dist/navigation.js +11 -3
- package/react/dist/overlay.d.ts +28 -3
- package/react/dist/overlay.js +29 -3
- package/react/dist/preset-group.d.ts +30 -0
- package/react/dist/preset-group.js +13 -0
- package/react/dist/provider.d.ts +42 -5
- package/react/dist/provider.js +84 -10
- 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 +18 -4
- package/react/dist/selection.js +20 -10
- 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 +380 -150
- package/react/dist/surface.d.ts +5 -1
- package/react/dist/surface.js +1 -1
- package/react/dist/toast.d.ts +19 -12
- package/react/dist/toast.js +29 -7
- package/react/dist/wallet-address-core.d.ts +27 -0
- package/react/dist/wallet-address-core.js +29 -0
- package/react/dist/wallet-address.d.ts +6 -12
- package/react/dist/wallet-address.js +5 -16
- package/tokens/README.md +2 -2
- 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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NumberFlowPlace } from '@bloxwap/hig/contracts/number-flow';
|
|
1
2
|
export type NumberTrend = -1 | 0 | 1 | ((previousValue: number, value: number) => -1 | 0 | 1);
|
|
2
3
|
export interface NumberReading {
|
|
3
4
|
known: boolean;
|
|
@@ -21,4 +22,49 @@ export interface NumberReelModel {
|
|
|
21
22
|
export declare function formatNumberReadout(value: number | null | undefined, locale: string, options?: Intl.NumberFormatOptions, formattedValue?: string, prefix?: string, suffix?: string): NumberReading;
|
|
22
23
|
export declare function numberTrendDirection(trend: NumberTrend | undefined, previousValue: number | null | undefined, value: number | null | undefined): -1 | 0 | 1;
|
|
23
24
|
export declare function safeNumberLayout(text: string, direction: string): boolean;
|
|
24
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Reels for host-formatted text: every digit of `text` (ASCII, or the locale's own digits) becomes a reel keyed by its place
|
|
27
|
+
* counted from the end, and everything else stays as written. Used for a figure's `formattedValue` when the host formats
|
|
28
|
+
* numbers itself, for example because the runtime's Intl does not match its number table.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createFormattedReelModel(text: string, locale: string, direction: string): NumberReelModel | null;
|
|
31
|
+
/** 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. */
|
|
32
|
+
export declare function createNumberReelModel(value: number | null | undefined, locale: string, options: Intl.NumberFormatOptions | undefined, formattedValue: string | undefined, direction: string, animateFormatted?: boolean, reading?: string): NumberReelModel | null;
|
|
33
|
+
/** 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. */
|
|
34
|
+
export declare function numberReelPlace(token: Pick<NumberReelToken, 'type' | 'place'>): number | null;
|
|
35
|
+
/** The reels of a model as NumberFlow places, in display order. */
|
|
36
|
+
export declare function numberReelPlaces(model: NumberReelModel): NumberFlowPlace[];
|
|
37
|
+
/**
|
|
38
|
+
* Where a reel's strip sits for a position that has turned any number of times either way. The strip is `length + 1` glyphs,
|
|
39
|
+
* the last repeating the first, so every position between two digits (9 to 0 included) is two neighbouring rows. UI thread.
|
|
40
|
+
*/
|
|
41
|
+
export declare function numberFlowReelOffset(position: number, length: number, height: number): number;
|
|
42
|
+
/** Progress along a sampled curve (first sample 0, last 1) at time `progress`. The UI-thread twin of `sampleNumberFlowEasing`. */
|
|
43
|
+
export declare function sampleReelEasing(samples: readonly number[], progress: number): number;
|
|
44
|
+
export type NumberFlowTurn = {
|
|
45
|
+
delta: number;
|
|
46
|
+
start: number;
|
|
47
|
+
duration: number;
|
|
48
|
+
};
|
|
49
|
+
/** A Reanimated animation object: one reel position, which is its target less what every turn still in flight has left to go. */
|
|
50
|
+
export type NumberFlowRoll = {
|
|
51
|
+
type: 'hig-number-flow';
|
|
52
|
+
current: number;
|
|
53
|
+
toValue: number;
|
|
54
|
+
turns: NumberFlowTurn[];
|
|
55
|
+
reduceMotion: false;
|
|
56
|
+
onStart: (animation: NumberFlowRoll, value: number, now: number, previous?: {
|
|
57
|
+
type?: string;
|
|
58
|
+
toValue?: unknown;
|
|
59
|
+
turns?: NumberFlowTurn[];
|
|
60
|
+
} | null) => void;
|
|
61
|
+
onFrame: (animation: NumberFlowRoll, now: number) => boolean;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* One turn of a reel by `delta` glyphs, for `defineAnimation`. A new turn does not restart the reel: it is added to the turns
|
|
65
|
+
* still in flight, each keeping its own clock and curve, which is what NumberFlow's additive animations do on web. So a reel
|
|
66
|
+
* asked to move again while it moves keeps its speed instead of easing in from rest every time, and it always ends on the
|
|
67
|
+
* digit the last turn asked for. With nothing in flight `onFrame` reports finished and the frame callback stops. HIG's
|
|
68
|
+
* provider decides reduced motion, so the system setting is not consulted here. UI thread.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createNumberFlowRoll(delta: number, duration: number, samples: readonly number[]): NumberFlowRoll;
|
|
@@ -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);
|
|
@@ -44,30 +46,198 @@ export function safeNumberLayout(text, direction) {
|
|
|
44
46
|
return false;
|
|
45
47
|
return true;
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
}
|
|
71
|
+
/** The ten digit glyphs of a locale's numbering system, or `null` when Intl cannot name them one character each. */
|
|
72
|
+
function localeDigits(locale) {
|
|
73
|
+
current();
|
|
74
|
+
const kept = keptLocaleDigits.get(locale);
|
|
75
|
+
if (kept)
|
|
76
|
+
return kept;
|
|
50
77
|
try {
|
|
51
|
-
const
|
|
52
|
-
|
|
78
|
+
const numberingSystem = new Intl.NumberFormat(locale).resolvedOptions().numberingSystem;
|
|
79
|
+
const digitFormatter = new Intl.NumberFormat(locale, { numberingSystem, useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
|
80
|
+
const digits = Array.from({ length: 10 }, (_, digit) => { const formatted = digitFormatter.format(digit); return Array.from(formatted).length === 1 ? formatted : ''; });
|
|
81
|
+
if (!digits.every(Boolean) || new Set(digits).size !== 10)
|
|
53
82
|
return null;
|
|
54
|
-
|
|
55
|
-
|
|
83
|
+
if (keptLocaleDigits.size >= 64)
|
|
84
|
+
keptLocaleDigits.clear();
|
|
85
|
+
keptLocaleDigits.set(locale, digits);
|
|
86
|
+
return digits;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Reels for host-formatted text: every digit of `text` (ASCII, or the locale's own digits) becomes a reel keyed by its place
|
|
94
|
+
* counted from the end, and everything else stays as written. Used for a figure's `formattedValue` when the host formats
|
|
95
|
+
* numbers itself, for example because the runtime's Intl does not match its number table.
|
|
96
|
+
*/
|
|
97
|
+
export function createFormattedReelModel(text, locale, direction) {
|
|
98
|
+
if (!text || !safeNumberLayout(text, direction))
|
|
99
|
+
return null;
|
|
100
|
+
const characters = Array.from(text), ascii = characters.some(character => asciiDigits.includes(character));
|
|
101
|
+
const digits = ascii ? asciiDigits : localeDigits(locale);
|
|
102
|
+
if (!digits)
|
|
103
|
+
return null;
|
|
104
|
+
const count = characters.filter(character => digits.includes(character)).length;
|
|
105
|
+
if (!count)
|
|
106
|
+
return null;
|
|
107
|
+
const tokens = [];
|
|
108
|
+
let run = '', seen = 0;
|
|
109
|
+
const flush = () => { if (run) {
|
|
110
|
+
tokens.push({ key: `static:${tokens.length}`, kind: 'static', type: 'literal', value: run, partIndex: tokens.length });
|
|
111
|
+
run = '';
|
|
112
|
+
} };
|
|
113
|
+
for (const character of characters) {
|
|
114
|
+
const digit = digits.indexOf(character);
|
|
115
|
+
if (digit < 0) {
|
|
116
|
+
run += character;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
flush();
|
|
120
|
+
const place = count - ++seen;
|
|
121
|
+
tokens.push({ key: `digit:${place}`, kind: 'digit', type: 'integer', value: character, partIndex: tokens.length, digit, place });
|
|
122
|
+
}
|
|
123
|
+
flush();
|
|
124
|
+
return { canonical: text, digits, tokens };
|
|
125
|
+
}
|
|
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)
|
|
56
156
|
return null;
|
|
57
157
|
const parts = formatter.formatToParts(value);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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) {
|
|
227
|
+
if (typeof value === 'number' && Number.isFinite(value) && formattedValue && animateFormatted && typeof Intl !== 'undefined')
|
|
228
|
+
return createFormattedReelModel(formattedValue, locale, direction);
|
|
229
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || formattedValue || direction !== 'ltr' || typeof Intl === 'undefined' || typeof Intl.NumberFormat !== 'function')
|
|
230
|
+
return null;
|
|
231
|
+
try {
|
|
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))
|
|
65
238
|
return null;
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
return parts.length === 1 && parts[0].type === 'integer' && parts[0].value === formatted && Array.from(formatted).length === 1 ? formatted : '';
|
|
69
|
-
});
|
|
70
|
-
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)
|
|
71
241
|
return null;
|
|
72
242
|
const digitIndexes = new Map(digits.map((digit, index) => [digit, index]));
|
|
73
243
|
const count = (type) => parts.filter(part => part.type === type).reduce((total, part) => total + Array.from(part.value).length, 0);
|
|
@@ -108,3 +278,60 @@ export function createNumberReelModel(value, locale, options, formattedValue, di
|
|
|
108
278
|
return null;
|
|
109
279
|
}
|
|
110
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,9 +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;
|
|
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. */
|
|
35
|
+
animateFormatted?: boolean;
|
|
8
36
|
}
|
|
9
|
-
|
|
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;
|