@bloxwap/hig 0.7.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 +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/messages.d.ts +56 -2
- 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 +161 -16
- 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 +6 -1
- package/native/dist/blocks.js +5 -0
- 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.js +2 -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/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 +9 -3
- package/native/dist/swap-panel-block.js +59 -33
- 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-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 +10 -1
- package/native/dist/token-action-block.js +9 -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 +111 -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 +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/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/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 +10 -3
- package/react/dist/blocks/swap-panel-block.js +71 -36
- 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 +5 -1
- package/react/dist/blocks/token-action-block.js +2 -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 +5 -1
- package/react/dist/blocks.js +4 -0
- 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 +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 +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 +238 -163
- 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/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
|
@@ -35,15 +35,40 @@ export declare function numberLocale(locale: string, presentation?: NumberFormat
|
|
|
35
35
|
* field the options set themselves wins. Without a presentation, or for any other style, the same options object is returned.
|
|
36
36
|
*/
|
|
37
37
|
export declare function presentNumberFormat<T extends Intl.NumberFormatOptions | undefined>(options: T, presentation?: NumberFormatPresentation): T;
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Display only. Keep raw decimal strings in transaction logic. A `signDisplay` the runtime's Intl ignores (Hermes on iOS draws
|
|
40
|
+
* `12.34%` for `exceptZero`) is composed by {@link formatSignedNumber}, so every engine draws the same string; engines whose Intl
|
|
41
|
+
* honours it format exactly as before.
|
|
42
|
+
*/
|
|
39
43
|
export declare function formatNumber(value: number | null | undefined, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
44
|
+
/** `Intl.NumberFormatOptions['signDisplay']`, with ES2023's `negative`, which the TypeScript lib in use may not list. */
|
|
45
|
+
export type SignDisplay = NonNullable<Intl.NumberFormatOptions['signDisplay']> | 'negative';
|
|
46
|
+
/** Whether this runtime's `Intl.NumberFormat` draws `signDisplay` (each mode is checked once, in decimal, currency and percent). */
|
|
47
|
+
export declare function intlSignDisplaySupported(mode: SignDisplay): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* `Intl.NumberFormat` with `signDisplay`, composed without asking Intl to draw the sign: the magnitude and the locale's own negative
|
|
50
|
+
* form are formatted with `signDisplay` left out, and a plus takes the minus sign's place, so the sign keeps its side of the currency
|
|
51
|
+
* sign, percent sign and digits and any bidi marks around it (`+$12.50`, `12,50 $` → `+12,50 $`, `$+12.50` in de-CH, `+١٢` in
|
|
52
|
+
* Arabic). Zero follows the rounded figure: `exceptZero` draws `0.00` for 0.001 at two places, as Intl does. Where the negative form
|
|
53
|
+
* has no minus (accounting parentheses), the locale's plus leads the positive form. Matches ICU's output for decimal, currency,
|
|
54
|
+
* percent, unit and compact formats; display only.
|
|
55
|
+
*/
|
|
56
|
+
export declare function formatSignedNumber(value: number | null | undefined, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
40
57
|
/** Leverage multiplier display (`10×`). Never percent-styled; the `×` suffix is untranslated. Unknown → `—`. */
|
|
41
58
|
export declare function formatLeverage(value: number | null | undefined, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
42
59
|
/** Amount followed by an untranslated ticker such as `USDC` (not an ISO 4217 currency), joined by a no-break space. Unknown → `—`. */
|
|
43
60
|
export declare function formatTicker(value: number | null | undefined, ticker: string, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
44
61
|
/** Clock display for funding and other protocol instants. The host must name the zone; the zone name is always shown. Unknown → `—`. */
|
|
45
62
|
export declare function formatZonedTime(value: Date | number | null | undefined, locale: string, timeZone: string, options?: Intl.DateTimeFormatOptions): string;
|
|
46
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Time left until a market opens, rounded up to the second. `visible` is a clock: `2:14:33`, or `1d 04:12:09` past a day.
|
|
65
|
+
* `spoken` names the largest units in words without seconds (`2 hours, 14 minutes`), so it changes once a minute and is
|
|
66
|
+
* calm in an accessible name; under a minute it reads the seconds. Negative time reads as zero.
|
|
67
|
+
*/
|
|
68
|
+
export declare function formatCountdown(remainingMs: number, locale?: string): {
|
|
69
|
+
visible: string;
|
|
70
|
+
spoken: string;
|
|
71
|
+
};
|
|
47
72
|
export interface FontManifest {
|
|
48
73
|
version: string;
|
|
49
74
|
faces: ReadonlyArray<{
|
|
@@ -55,3 +80,5 @@ export interface FontManifest {
|
|
|
55
80
|
}>;
|
|
56
81
|
}
|
|
57
82
|
export declare function nativeFont(manifest: FontManifest, family: string, weight: number, script?: string): string;
|
|
83
|
+
export { assertUniqueKeys, numericRange, progressValue, paginationValue } from './invariants.js';
|
|
84
|
+
export { decimal, decimalMultiply, decimalDivide, decimalCompare, localizeDecimal } from './decimal.js';
|
package/contracts/dist/index.js
CHANGED
|
@@ -45,9 +45,89 @@ export function presentNumberFormat(options, presentation) {
|
|
|
45
45
|
merged[key] = value;
|
|
46
46
|
return merged;
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Display only. Keep raw decimal strings in transaction logic. A `signDisplay` the runtime's Intl ignores (Hermes on iOS draws
|
|
50
|
+
* `12.34%` for `exceptZero`) is composed by {@link formatSignedNumber}, so every engine draws the same string; engines whose Intl
|
|
51
|
+
* honours it format exactly as before.
|
|
52
|
+
*/
|
|
49
53
|
export function formatNumber(value, locale = 'en-US', options = {}) {
|
|
50
|
-
|
|
54
|
+
if (value == null || !Number.isFinite(value))
|
|
55
|
+
return '—';
|
|
56
|
+
const sign = options.signDisplay;
|
|
57
|
+
try {
|
|
58
|
+
return sign !== undefined && sign !== 'auto' && !intlSignDisplaySupported(sign) ? formatSignedNumber(value, locale, options) : new Intl.NumberFormat(locale, options).format(value);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return '—';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const signSupport = new Map();
|
|
65
|
+
/** Whether this runtime's `Intl.NumberFormat` draws `signDisplay` (each mode is checked once, in decimal, currency and percent). */
|
|
66
|
+
export function intlSignDisplaySupported(mode) {
|
|
67
|
+
const known = signSupport.get(mode);
|
|
68
|
+
if (known !== undefined)
|
|
69
|
+
return known;
|
|
70
|
+
const expected = {
|
|
71
|
+
always: [[1, '+1', '+$1.00', '+100%'], [0, '+0', '+$0.00', '+0%'], [-1, '-1', '-$1.00', '-100%']],
|
|
72
|
+
exceptZero: [[1, '+1', '+$1.00', '+100%'], [0, '0', '$0.00', '0%'], [-0, '0', '$0.00', '0%'], [-1, '-1', '-$1.00', '-100%']],
|
|
73
|
+
negative: [[1, '1', '$1.00', '100%'], [-0, '0', '$0.00', '0%'], [-1, '-1', '-$1.00', '-100%']],
|
|
74
|
+
never: [[1, '1', '$1.00', '100%'], [-1, '1', '$1.00', '100%']],
|
|
75
|
+
};
|
|
76
|
+
let supported = false;
|
|
77
|
+
try {
|
|
78
|
+
const cases = expected[mode];
|
|
79
|
+
if (cases) {
|
|
80
|
+
const signed = (options) => new Intl.NumberFormat('en-US', { ...options, signDisplay: mode });
|
|
81
|
+
const decimal = signed({}), money = signed({ style: 'currency', currency: 'USD' }), share = signed({ style: 'percent' });
|
|
82
|
+
supported = cases.every(([value, plain, usd, percent]) => decimal.format(value) === plain && money.format(value) === usd && share.format(value) === percent);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
supported = false;
|
|
87
|
+
}
|
|
88
|
+
signSupport.set(mode, supported);
|
|
89
|
+
return supported;
|
|
90
|
+
}
|
|
91
|
+
const minusSign = /[-−‐-―﹣-]/u;
|
|
92
|
+
/**
|
|
93
|
+
* `Intl.NumberFormat` with `signDisplay`, composed without asking Intl to draw the sign: the magnitude and the locale's own negative
|
|
94
|
+
* form are formatted with `signDisplay` left out, and a plus takes the minus sign's place, so the sign keeps its side of the currency
|
|
95
|
+
* sign, percent sign and digits and any bidi marks around it (`+$12.50`, `12,50 $` → `+12,50 $`, `$+12.50` in de-CH, `+١٢` in
|
|
96
|
+
* Arabic). Zero follows the rounded figure: `exceptZero` draws `0.00` for 0.001 at two places, as Intl does. Where the negative form
|
|
97
|
+
* has no minus (accounting parentheses), the locale's plus leads the positive form. Matches ICU's output for decimal, currency,
|
|
98
|
+
* percent, unit and compact formats; display only.
|
|
99
|
+
*/
|
|
100
|
+
export function formatSignedNumber(value, locale = 'en-US', options = {}) {
|
|
101
|
+
if (value == null || !Number.isFinite(value))
|
|
102
|
+
return '—';
|
|
103
|
+
const { signDisplay: requested, ...rest } = options, signDisplay = requested;
|
|
104
|
+
let formatter;
|
|
105
|
+
try {
|
|
106
|
+
formatter = new Intl.NumberFormat(locale, rest);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return '—';
|
|
110
|
+
}
|
|
111
|
+
if (signDisplay === undefined || signDisplay === 'auto')
|
|
112
|
+
return formatter.format(value);
|
|
113
|
+
const magnitude = Math.abs(value), negative = value < 0 || Object.is(value, -0), absolute = formatter.format(magnitude), zero = absolute === formatter.format(0);
|
|
114
|
+
const plus = () => {
|
|
115
|
+
const minus = formatter.format(-magnitude), at = minus.search(minusSign);
|
|
116
|
+
if (at >= 0)
|
|
117
|
+
return `${minus.slice(0, at)}+${minus.slice(at + 1)}`;
|
|
118
|
+
const digits = new Intl.NumberFormat(locale, { maximumFractionDigits: 0, useGrouping: false }), sign = digits.format(-1).replace(digits.format(1), '');
|
|
119
|
+
return `${minusSign.test(sign) ? sign.replace(minusSign, '+') : '+'}${absolute}`;
|
|
120
|
+
};
|
|
121
|
+
switch (signDisplay) {
|
|
122
|
+
case 'never': {
|
|
123
|
+
const { currencySign, ...plain } = rest;
|
|
124
|
+
return currencySign === undefined ? absolute : new Intl.NumberFormat(locale, plain).format(magnitude);
|
|
125
|
+
}
|
|
126
|
+
case 'negative': return negative && !zero ? formatter.format(-magnitude) : absolute;
|
|
127
|
+
case 'exceptZero': return zero ? absolute : negative ? formatter.format(-magnitude) : plus();
|
|
128
|
+
case 'always': return negative ? formatter.format(-magnitude) : plus();
|
|
129
|
+
default: return formatter.format(value);
|
|
130
|
+
}
|
|
51
131
|
}
|
|
52
132
|
/** Leverage multiplier display (`10×`). Never percent-styled; the `×` suffix is untranslated. Unknown → `—`. */
|
|
53
133
|
export function formatLeverage(value, locale = 'en-US', options = { maximumFractionDigits: 2 }) {
|
|
@@ -62,9 +142,46 @@ export function formatTicker(value, ticker, locale = 'en-US', options = {}) {
|
|
|
62
142
|
/** Clock display for funding and other protocol instants. The host must name the zone; the zone name is always shown. Unknown → `—`. */
|
|
63
143
|
export function formatZonedTime(value, locale, timeZone, options = { hour: 'numeric', minute: '2-digit' }) {
|
|
64
144
|
const time = value instanceof Date ? value.getTime() : value;
|
|
65
|
-
if (time == null || !Number.isFinite(time))
|
|
145
|
+
if (time == null || !Number.isFinite(time) || Math.abs(time) > 8640000000000000)
|
|
66
146
|
return '—';
|
|
67
|
-
|
|
147
|
+
try {
|
|
148
|
+
return new Intl.DateTimeFormat(locale, { timeZoneName: 'short', ...options, timeZone }).format(time);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return '—';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Font 0.1.2 publishes CSS/Next loaders, native faces are derived by the optional pinned HIG font generator. */
|
|
155
|
+
/** Formats one unit with Intl (`2 hours`, `1d`), falling back to plain digits and the unit name where the runtime lacks unit formatting. */
|
|
156
|
+
function formatUnit(value, unit, locale, unitDisplay) {
|
|
157
|
+
try {
|
|
158
|
+
return new Intl.NumberFormat(locale, { style: 'unit', unit, unitDisplay }).format(value);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return unitDisplay === 'narrow' ? `${value}${unit[0]}` : `${value} ${unit}${value === 1 ? '' : 's'}`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Time left until a market opens, rounded up to the second. `visible` is a clock: `2:14:33`, or `1d 04:12:09` past a day.
|
|
166
|
+
* `spoken` names the largest units in words without seconds (`2 hours, 14 minutes`), so it changes once a minute and is
|
|
167
|
+
* calm in an accessible name; under a minute it reads the seconds. Negative time reads as zero.
|
|
168
|
+
*/
|
|
169
|
+
export function formatCountdown(remainingMs, locale = 'en-US') {
|
|
170
|
+
if (!Number.isFinite(remainingMs))
|
|
171
|
+
return { visible: '—', spoken: '—' };
|
|
172
|
+
const total = Math.max(0, Math.ceil(remainingMs / 1000));
|
|
173
|
+
const days = Math.floor(total / 86400), hours = Math.floor(total % 86400 / 3600), minutes = Math.floor(total % 3600 / 60), seconds = total % 60;
|
|
174
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
175
|
+
const visible = days > 0 ? `${formatUnit(days, 'day', locale, 'narrow')} ${pad(hours)}:${pad(minutes)}:${pad(seconds)}` : `${hours}:${pad(minutes)}:${pad(seconds)}`;
|
|
176
|
+
const words = total < 60 ? [formatUnit(seconds, 'second', locale, 'long')] : [days ? formatUnit(days, 'day', locale, 'long') : '', hours ? formatUnit(hours, 'hour', locale, 'long') : '', minutes ? formatUnit(minutes, 'minute', locale, 'long') : ''].filter(Boolean);
|
|
177
|
+
let spoken;
|
|
178
|
+
try {
|
|
179
|
+
spoken = new Intl.ListFormat(locale, { style: 'narrow', type: 'unit' }).format(words);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
spoken = words.join(', ');
|
|
183
|
+
}
|
|
184
|
+
return { visible, spoken };
|
|
68
185
|
}
|
|
69
186
|
export function nativeFont(manifest, family, weight, script = 'latin') {
|
|
70
187
|
const face = manifest.faces.find(f => f.family === family && f.weight === weight && f.script === script);
|
|
@@ -72,3 +189,5 @@ export function nativeFont(manifest, family, weight, script = 'latin') {
|
|
|
72
189
|
throw new Error(`Register a pinned ${family} ${weight} ${script} native face`);
|
|
73
190
|
return face.registration ?? face.family;
|
|
74
191
|
}
|
|
192
|
+
export { assertUniqueKeys, numericRange, progressValue, paginationValue } from './invariants.js';
|
|
193
|
+
export { decimal, decimalMultiply, decimalDivide, decimalCompare, localizeDecimal } from './decimal.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Identity must not collapse two rows into one stateful element. */
|
|
2
|
+
export declare function assertUniqueKeys<T>(items: readonly T[], key: (item: T) => string | number, label?: string): void;
|
|
3
|
+
/** Shared finite range for visuals, accessibility and emitted values. */
|
|
4
|
+
export declare function numericRange(min?: number, max?: number, step?: number): {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
step: number;
|
|
8
|
+
clamp: (value: number) => number;
|
|
9
|
+
};
|
|
10
|
+
export declare function progressValue(value: number | undefined, max: number): {
|
|
11
|
+
max: number;
|
|
12
|
+
value: number | undefined;
|
|
13
|
+
};
|
|
14
|
+
export declare function paginationValue(page: number, total: number): {
|
|
15
|
+
total: number;
|
|
16
|
+
page: number;
|
|
17
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Identity must not collapse two rows into one stateful element. */
|
|
2
|
+
export function assertUniqueKeys(items, key, label = 'Collection') {
|
|
3
|
+
const seen = new Set();
|
|
4
|
+
for (const item of items) {
|
|
5
|
+
const id = String(key(item));
|
|
6
|
+
if (seen.has(id))
|
|
7
|
+
throw new Error(`${label} requires unique keys: ${id}`);
|
|
8
|
+
seen.add(id);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Shared finite range for visuals, accessibility and emitted values. */
|
|
12
|
+
export function numericRange(min = 0, max = 100, step = 1) {
|
|
13
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || max < min || !Number.isFinite(step) || step <= 0)
|
|
14
|
+
throw new RangeError('Range requires finite min <= max and step > 0');
|
|
15
|
+
return { min, max, step, clamp: (value) => Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : min };
|
|
16
|
+
}
|
|
17
|
+
export function progressValue(value, max) {
|
|
18
|
+
const ceiling = Number.isFinite(max) && max > 0 ? max : 100;
|
|
19
|
+
return { max: ceiling, value: value === undefined || !Number.isFinite(value) ? undefined : Math.min(ceiling, Math.max(0, value)) };
|
|
20
|
+
}
|
|
21
|
+
export function paginationValue(page, total) {
|
|
22
|
+
const count = Number.isFinite(total) ? Math.max(1, Math.floor(total)) : 1;
|
|
23
|
+
return { total: count, page: Number.isFinite(page) ? Math.max(1, Math.min(count, Math.floor(page))) : 1 };
|
|
24
|
+
}
|
|
@@ -26,7 +26,7 @@ export interface HIGMessages {
|
|
|
26
26
|
loadingContent: string;
|
|
27
27
|
/** List loading row. */
|
|
28
28
|
loadingItems: string;
|
|
29
|
-
/** Web
|
|
29
|
+
/** Web chart fallback: AltimeterChart and OutcomeChart while they wait for data, PriceChart while the chart engine loads. */
|
|
30
30
|
loadingChart: string;
|
|
31
31
|
/** List default empty text. */
|
|
32
32
|
noItems: string;
|
|
@@ -184,7 +184,7 @@ export interface HIGMessages {
|
|
|
184
184
|
addressCopied: string;
|
|
185
185
|
/** Visible hint under a wallet address that copies on press. */
|
|
186
186
|
tapToCopy: string;
|
|
187
|
-
/** Accessible name of a
|
|
187
|
+
/** Accessible name of a QR code (WalletAddress, QRCode). */
|
|
188
188
|
qrCode: string;
|
|
189
189
|
/** Control key legend in the swap panel's shortcut hint on non-Apple keyboards (`Ctrl K`). Apple keyboards show ⌘. */
|
|
190
190
|
swapControlKey: string;
|
|
@@ -216,6 +216,42 @@ export interface HIGMessages {
|
|
|
216
216
|
unstake: string;
|
|
217
217
|
/** SearchInput: accessible name of the clear button when the host gives no `clearLabel`. */
|
|
218
218
|
clearSearch: string;
|
|
219
|
+
/** AssetsBlock: the default heading. */
|
|
220
|
+
assets: string;
|
|
221
|
+
/** AssetsBlock: search placeholder (with a trailing ellipsis) and accessible name. */
|
|
222
|
+
searchMarkets: string;
|
|
223
|
+
/** AssetsBlock: accessible name of the category filter. */
|
|
224
|
+
marketCategories: string;
|
|
225
|
+
/** AssetsBlock: accessible name of the All / Positions / Trend control. */
|
|
226
|
+
assetsView: string;
|
|
227
|
+
/** AssetsBlock: the unfiltered category capsule and view. */
|
|
228
|
+
assetsAll: string;
|
|
229
|
+
/** AssetsBlock: the view of markets with an open position. */
|
|
230
|
+
assetsPositions: string;
|
|
231
|
+
/** AssetsBlock: the view of markets with a signal. */
|
|
232
|
+
assetsTrend: string;
|
|
233
|
+
/** AssetsBlock: a row's watch signal, read after the market. */
|
|
234
|
+
signalWatch: string;
|
|
235
|
+
/** AssetsBlock: a row's upward signal, read after the market. */
|
|
236
|
+
signalUp: string;
|
|
237
|
+
/** AssetsBlock: a row's downward signal, read after the market. */
|
|
238
|
+
signalDown: string;
|
|
239
|
+
/** AssetsBlock: empty Positions view. */
|
|
240
|
+
noPositions: string;
|
|
241
|
+
/** AssetsBlock: empty Trend view. */
|
|
242
|
+
noTrend: string;
|
|
243
|
+
/** AssetsBlock: before the countdown to when a closed legacy market opens, as in “Opens in 2:14:33”. */
|
|
244
|
+
opensIn: string;
|
|
245
|
+
/** ConfirmBlock: the default heading and confirming action. */
|
|
246
|
+
confirmSend: string;
|
|
247
|
+
/** ConfirmBlock: label of the destination address row. */
|
|
248
|
+
sendTo: string;
|
|
249
|
+
/** ConfirmBlock: label of the network row. */
|
|
250
|
+
sendNetwork: string;
|
|
251
|
+
/** ConfirmBlock: heading of the warning above the actions. */
|
|
252
|
+
sendWarningTitle: string;
|
|
253
|
+
/** ConfirmBlock: body of the warning, naming the token and the network. */
|
|
254
|
+
sendWarning: (symbol: string, network: string) => string;
|
|
219
255
|
}
|
|
220
256
|
export declare const close = "Close";
|
|
221
257
|
export declare const cancel = "Cancel";
|
|
@@ -321,6 +357,24 @@ export declare const receive = "Receive";
|
|
|
321
357
|
export declare const stake = "Stake";
|
|
322
358
|
export declare const unstake = "Unstake";
|
|
323
359
|
export declare const clearSearch = "Clear search";
|
|
360
|
+
export declare const assets = "Assets";
|
|
361
|
+
export declare const searchMarkets = "Search markets";
|
|
362
|
+
export declare const marketCategories = "Market categories";
|
|
363
|
+
export declare const assetsView = "View";
|
|
364
|
+
export declare const assetsAll = "All";
|
|
365
|
+
export declare const assetsPositions = "Positions";
|
|
366
|
+
export declare const assetsTrend = "Trend";
|
|
367
|
+
export declare const signalWatch = "Watch";
|
|
368
|
+
export declare const signalUp = "Rising";
|
|
369
|
+
export declare const signalDown = "Falling";
|
|
370
|
+
export declare const noPositions = "No open positions";
|
|
371
|
+
export declare const noTrend = "No trending markets";
|
|
372
|
+
export declare const opensIn = "Opens in";
|
|
373
|
+
export declare const confirmSend = "Confirm Send";
|
|
374
|
+
export declare const sendTo = "To";
|
|
375
|
+
export declare const sendNetwork = "Network";
|
|
376
|
+
export declare const sendWarningTitle = "Double-check the address.";
|
|
377
|
+
export declare const sendWarning: (symbol: string, network: string) => string;
|
|
324
378
|
/** The complete English catalog. */
|
|
325
379
|
export declare const defaultMessages: Readonly<HIGMessages>;
|
|
326
380
|
/** Every message key, in documentation order. */
|
|
@@ -103,8 +103,26 @@ export const receive = 'Receive';
|
|
|
103
103
|
export const stake = 'Stake';
|
|
104
104
|
export const unstake = 'Unstake';
|
|
105
105
|
export const clearSearch = 'Clear search';
|
|
106
|
+
export const assets = 'Assets';
|
|
107
|
+
export const searchMarkets = 'Search markets';
|
|
108
|
+
export const marketCategories = 'Market categories';
|
|
109
|
+
export const assetsView = 'View';
|
|
110
|
+
export const assetsAll = 'All';
|
|
111
|
+
export const assetsPositions = 'Positions';
|
|
112
|
+
export const assetsTrend = 'Trend';
|
|
113
|
+
export const signalWatch = 'Watch';
|
|
114
|
+
export const signalUp = 'Rising';
|
|
115
|
+
export const signalDown = 'Falling';
|
|
116
|
+
export const noPositions = 'No open positions';
|
|
117
|
+
export const noTrend = 'No trending markets';
|
|
118
|
+
export const opensIn = 'Opens in';
|
|
119
|
+
export const confirmSend = 'Confirm Send';
|
|
120
|
+
export const sendTo = 'To';
|
|
121
|
+
export const sendNetwork = 'Network';
|
|
122
|
+
export const sendWarningTitle = 'Double-check the address.';
|
|
123
|
+
export const sendWarning = (symbol, network) => `${symbol} moves to this address on ${network} instantly — there's no clawback if the address is wrong.`;
|
|
106
124
|
/** The complete English catalog. */
|
|
107
|
-
export const defaultMessages = { close, cancel, dismiss, dismissNotice, busy, notifications, loading, loadingContent, loadingItems, loadingChart, noItems, noRows, retry, loadMore, stale, required, breadcrumb, pagination, previous, next, pageOf, search, searching, noResults, resultCount, back, menuDescription, choose, chooseOne, inProgress, progressValue, copied, copyFailed, copyInstallCommand, reviewAssetOrder, amountInAsset, availableAmount, reviewOrder, confirmOrder, confirmOrderDescription, orderUnavailable, statusOnline, statusOffline, statusStale, increase, decrease, swapFrom, swapTo, swapSelectToken, swapAmount, swapSwitchDenomination, swapFlip, swapActionSend, swapActionSwap, swapActionBridge, swapChooseToken, swapChooseDestination, swapEnterAmount, swapInsufficient, swapSendFromWallet, swapReset, swapSettings, swapMax, swapTest, swapSlippage, swapSlippageTitle, swapSlippageCustom, swapFee, swapFees, swapFeeTotal, swapDenomination, swapDollars, swapUnits, swapSearchTokens, swapChains, swapAllChains, swapHot, swapAllTokens, swapNoTokens, swapSelected, swapConnectWallet, swapDisconnect, swapGenerateAddress, swapRecipient, swapScan, copyAddress, addressCopied, tapToCopy, qrCode, swapControlKey, swapKeypad, swapDelete, account, deposit, accountBalance, showAddress, editName, changeProfilePicture, language, searchLanguages, receive, stake, unstake, clearSearch };
|
|
125
|
+
export const defaultMessages = { close, cancel, dismiss, dismissNotice, busy, notifications, loading, loadingContent, loadingItems, loadingChart, noItems, noRows, retry, loadMore, stale, required, breadcrumb, pagination, previous, next, pageOf, search, searching, noResults, resultCount, back, menuDescription, choose, chooseOne, inProgress, progressValue, copied, copyFailed, copyInstallCommand, reviewAssetOrder, amountInAsset, availableAmount, reviewOrder, confirmOrder, confirmOrderDescription, orderUnavailable, statusOnline, statusOffline, statusStale, increase, decrease, swapFrom, swapTo, swapSelectToken, swapAmount, swapSwitchDenomination, swapFlip, swapActionSend, swapActionSwap, swapActionBridge, swapChooseToken, swapChooseDestination, swapEnterAmount, swapInsufficient, swapSendFromWallet, swapReset, swapSettings, swapMax, swapTest, swapSlippage, swapSlippageTitle, swapSlippageCustom, swapFee, swapFees, swapFeeTotal, swapDenomination, swapDollars, swapUnits, swapSearchTokens, swapChains, swapAllChains, swapHot, swapAllTokens, swapNoTokens, swapSelected, swapConnectWallet, swapDisconnect, swapGenerateAddress, swapRecipient, swapScan, copyAddress, addressCopied, tapToCopy, qrCode, swapControlKey, swapKeypad, swapDelete, account, deposit, accountBalance, showAddress, editName, changeProfilePicture, language, searchLanguages, receive, stake, unstake, clearSearch, assets, searchMarkets, marketCategories, assetsView, assetsAll, assetsPositions, assetsTrend, signalWatch, signalUp, signalDown, noPositions, noTrend, opensIn, confirmSend, sendTo, sendNetwork, sendWarningTitle, sendWarning };
|
|
108
126
|
/** Every message key, in documentation order. */
|
|
109
127
|
export const messageKeys = /* @__PURE__ */ Object.keys(defaultMessages);
|
|
110
128
|
/**
|
|
@@ -115,7 +133,7 @@ export const messageKeys = /* @__PURE__ */ Object.keys(defaultMessages);
|
|
|
115
133
|
export function resolveMessages(base, overrides) {
|
|
116
134
|
if (!overrides)
|
|
117
135
|
return base;
|
|
118
|
-
const formatters = ['dismissNotice', 'pageOf', 'resultCount', 'progressValue', 'reviewAssetOrder', 'amountInAsset', 'availableAmount', 'confirmOrderDescription', 'swapSelectToken', 'swapAmount', 'swapInsufficient', 'swapSlippage', 'swapFee'];
|
|
136
|
+
const formatters = ['dismissNotice', 'pageOf', 'resultCount', 'progressValue', 'reviewAssetOrder', 'amountInAsset', 'availableAmount', 'confirmOrderDescription', 'swapSelectToken', 'swapAmount', 'swapInsufficient', 'swapSlippage', 'swapFee', 'sendWarning'];
|
|
119
137
|
const resolved = { ...base };
|
|
120
138
|
for (const [key, value] of Object.entries(overrides)) {
|
|
121
139
|
if (value !== undefined && typeof value === (formatters.includes(key) ? 'function' : 'string'))
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NumberFlow's arithmetic, shared by the web and native renderers so both roll the same digits the same way: how far a place
|
|
3
|
+
* turns, which way, through how many glyphs, for how long and along which curve. Nothing here touches a DOM or a view.
|
|
4
|
+
*/
|
|
5
|
+
/** A named curve, or cubic-bezier control points `[x1, y1, x2, y2]`. `'number-flow'` is NumberFlow's own settle; `'standard'` is HIG's. */
|
|
6
|
+
export type NumberFlowEasing = 'number-flow' | 'standard' | 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | readonly [number, number, number, number];
|
|
7
|
+
/** One part of the motion: how long it takes, in milliseconds, and its curve. Either may be left to the default. */
|
|
8
|
+
export interface NumberFlowTiming {
|
|
9
|
+
duration?: number;
|
|
10
|
+
easing?: NumberFlowEasing;
|
|
11
|
+
}
|
|
12
|
+
export interface NumberFlowResolvedTiming {
|
|
13
|
+
duration: number;
|
|
14
|
+
easing: NumberFlowEasing;
|
|
15
|
+
}
|
|
16
|
+
export interface NumberFlowTimings {
|
|
17
|
+
/** Digits rolling to their new value. */
|
|
18
|
+
spin: NumberFlowResolvedTiming;
|
|
19
|
+
/** Places sliding sideways when the figure gains or loses a place. */
|
|
20
|
+
transform: NumberFlowResolvedTiming;
|
|
21
|
+
/** Places fading in and out. */
|
|
22
|
+
opacity: NumberFlowResolvedTiming;
|
|
23
|
+
}
|
|
24
|
+
/** Per-place limits, keyed by integer place (0 is the ones). `{1:{max:5}}` makes the tens of a seconds counter wrap 5 to 0. */
|
|
25
|
+
export type NumberFlowDigits = Readonly<Record<number, {
|
|
26
|
+
readonly max?: number;
|
|
27
|
+
}>>;
|
|
28
|
+
/** One digit of a figure: its stable key, its value, and its place (0 ones, 1 tens, -1 tenths; `null` outside the number, as in an exponent). */
|
|
29
|
+
export interface NumberFlowPlace {
|
|
30
|
+
key: string;
|
|
31
|
+
digit: number;
|
|
32
|
+
place: number | null;
|
|
33
|
+
}
|
|
34
|
+
/** NumberFlow's default settle, sampled at equal steps of time (number-flow, MIT). */
|
|
35
|
+
export declare const numberFlowCurve: readonly number[];
|
|
36
|
+
/** No part of the motion runs longer than this, whatever the host asks for. */
|
|
37
|
+
export declare const numberFlowMaxDuration = 3000;
|
|
38
|
+
/** NumberFlow's defaults: 900 ms on its settle for movement, 450 ms ease-out for fades. */
|
|
39
|
+
export declare const numberFlowDefaults: {
|
|
40
|
+
readonly transform: NumberFlowResolvedTiming;
|
|
41
|
+
readonly opacity: NumberFlowResolvedTiming;
|
|
42
|
+
};
|
|
43
|
+
/** The control points of a curve, or `null` for `'number-flow'`, which is sampled rather than a bezier. */
|
|
44
|
+
export declare function numberFlowBezier(easing: NumberFlowEasing): readonly [number, number, number, number] | null;
|
|
45
|
+
/** The curve as a CSS easing function, for the Web Animations API. `linear()` needs a browser from 2023; pass `sampled=false` for the nearest bezier instead. */
|
|
46
|
+
export declare function numberFlowEasingCSS(easing: NumberFlowEasing, sampled?: boolean): string;
|
|
47
|
+
/** A cubic bezier's progress at time `x` (both 0 to 1): Newton's method, then bisection where the slope is too flat. */
|
|
48
|
+
export declare function numberFlowBezierAt(points: readonly [number, number, number, number], x: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* The curve as progress values at equal steps of time, first 0 and last 1. A renderer that cannot hand the curve to its
|
|
51
|
+
* animation engine (a UI-thread worklet) reads its progress from this table with `sampleNumberFlowEasing`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function numberFlowEasingSamples(easing: NumberFlowEasing): readonly number[];
|
|
54
|
+
/** Progress along a sampled curve at time `progress` (0 to 1), interpolated between the two nearest samples. */
|
|
55
|
+
export declare function sampleNumberFlowEasing(samples: readonly number[], progress: number): number;
|
|
56
|
+
/** A host timing over a fallback: a finite duration is kept within 0 and `numberFlowMaxDuration`, a known curve is kept, anything else falls back. */
|
|
57
|
+
export declare function resolveNumberFlowTiming(timing: NumberFlowTiming | undefined, fallback: NumberFlowResolvedTiming): NumberFlowResolvedTiming;
|
|
58
|
+
/**
|
|
59
|
+
* The three timings of one figure. `duration` is the shorthand: it sets how long digits roll and places slide, and fades take
|
|
60
|
+
* half of it. `transformTiming` is also the roll's timing until `spinTiming` says otherwise, as in NumberFlow.
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveNumberFlowTimings({ duration, spinTiming, transformTiming, opacityTiming }: {
|
|
63
|
+
duration?: number;
|
|
64
|
+
spinTiming?: NumberFlowTiming;
|
|
65
|
+
transformTiming?: NumberFlowTiming;
|
|
66
|
+
opacityTiming?: NumberFlowTiming;
|
|
67
|
+
}): NumberFlowTimings;
|
|
68
|
+
/** How many glyphs a place rolls through before it wraps: ten, or `max + 1` where `digits` limits an integer place, and never fewer than the digit it must show. */
|
|
69
|
+
export declare function numberFlowDigitLength(digits: NumberFlowDigits | undefined, place: number | null, digit?: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* How far a place turns, in glyphs: positive rolls up to higher digits, negative down. With a trend the place keeps turning
|
|
72
|
+
* that way and wraps past its last glyph (9 to 0 going up is +1, not -9); without one it takes the short way its own digits
|
|
73
|
+
* point. `loop` turns an unchanged place once all the way round, for a figure that counts continuously.
|
|
74
|
+
*/
|
|
75
|
+
export declare function numberFlowDelta(previous: number, value: number, trend: number, length?: number, loop?: boolean): number;
|
|
76
|
+
/** The highest place that changed between two readings, in display order, or `undefined` when none did. Places at or below it loop when the figure is continuous. */
|
|
77
|
+
export declare function numberFlowLoopStart(previous: readonly NumberFlowPlace[], next: readonly NumberFlowPlace[]): number | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* The turn of every place in the new reading, by key. A place the old reading did not have starts from zero, as it does in
|
|
80
|
+
* NumberFlow. `trend` is the resolved direction of the whole change (-1, 0 or 1); places the new reading dropped are not listed.
|
|
81
|
+
*/
|
|
82
|
+
export declare function numberFlowDeltas(previous: readonly NumberFlowPlace[], next: readonly NumberFlowPlace[], { trend, digits, continuous }: {
|
|
83
|
+
trend: number;
|
|
84
|
+
digits?: NumberFlowDigits;
|
|
85
|
+
continuous?: boolean;
|
|
86
|
+
}): Map<string, number>;
|
|
87
|
+
/** The glyph index a reel shows at a position that has turned any number of times either way. */
|
|
88
|
+
export declare function numberFlowGlyph(position: number, length?: number): number;
|
|
89
|
+
/** Whether text can be drawn place by place from left to right without reordering it: no bidi controls and no right-to-left letters (Arabic-script digits are fine). */
|
|
90
|
+
export declare function numberFlowNeutral(text: string): boolean;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NumberFlow's arithmetic, shared by the web and native renderers so both roll the same digits the same way: how far a place
|
|
3
|
+
* turns, which way, through how many glyphs, for how long and along which curve. Nothing here touches a DOM or a view.
|
|
4
|
+
*/
|
|
5
|
+
/** NumberFlow's default settle, sampled at equal steps of time (number-flow, MIT). */
|
|
6
|
+
export const numberFlowCurve = [0, .005, .019, .039, .066, .096, .129, .165, .202, .24, .278, .316, .354, .39, .426, .461, .494, .526, .557, .586, .614, .64, .665, .689, .711, .731, .751, .769, .786, .802, .817, .831, .844, .856, .867, .877, .887, .896, .904, .912, .919, .925, .931, .937, .942, .947, .951, .955, .959, .962, .965, .968, .971, .973, .976, .978, .98, .981, .983, .984, .986, .987, .988, .989, .99, .991, .992, .992, .993, .994, .994, .995, .995, .996, .996, .9963, .9967, .9969, .9972, .9975, .9977, .9979, .9981, .9982, .9984, .9985, .9987, .9988, .9989, 1];
|
|
7
|
+
/** No part of the motion runs longer than this, whatever the host asks for. */
|
|
8
|
+
export const numberFlowMaxDuration = 3000;
|
|
9
|
+
/** NumberFlow's defaults: 900 ms on its settle for movement, 450 ms ease-out for fades. */
|
|
10
|
+
export const numberFlowDefaults = { transform: { duration: 900, easing: 'number-flow' }, opacity: { duration: 450, easing: 'ease-out' } };
|
|
11
|
+
const beziers = { standard: [0.22, 1, 0.36, 1], linear: [0, 0, 1, 1], ease: [0.25, 0.1, 0.25, 1], 'ease-in': [0.42, 0, 1, 1], 'ease-out': [0, 0, 0.58, 1], 'ease-in-out': [0.42, 0, 0.58, 1] };
|
|
12
|
+
const finite = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
13
|
+
const validEasing = (easing) => easing === 'number-flow' || (typeof easing === 'string' && easing in beziers) || (Array.isArray(easing) && easing.length === 4 && easing.every(finite) && easing[0] >= 0 && easing[0] <= 1 && easing[2] >= 0 && easing[2] <= 1);
|
|
14
|
+
/** The control points of a curve, or `null` for `'number-flow'`, which is sampled rather than a bezier. */
|
|
15
|
+
export function numberFlowBezier(easing) {
|
|
16
|
+
if (easing === 'number-flow')
|
|
17
|
+
return null;
|
|
18
|
+
return typeof easing === 'string' ? beziers[easing] ?? beziers.standard : easing;
|
|
19
|
+
}
|
|
20
|
+
/** The curve as a CSS easing function, for the Web Animations API. `linear()` needs a browser from 2023; pass `sampled=false` for the nearest bezier instead. */
|
|
21
|
+
export function numberFlowEasingCSS(easing, sampled = true) {
|
|
22
|
+
const bezier = numberFlowBezier(easing);
|
|
23
|
+
if (!bezier)
|
|
24
|
+
return sampled ? `linear(${numberFlowCurve.join(',')})` : `cubic-bezier(${beziers.standard.join(',')})`;
|
|
25
|
+
return `cubic-bezier(${bezier.join(',')})`;
|
|
26
|
+
}
|
|
27
|
+
/** A cubic bezier's progress at time `x` (both 0 to 1): Newton's method, then bisection where the slope is too flat. */
|
|
28
|
+
export function numberFlowBezierAt(points, x) {
|
|
29
|
+
const [x1, y1, x2, y2] = points;
|
|
30
|
+
if (x <= 0)
|
|
31
|
+
return 0;
|
|
32
|
+
if (x >= 1)
|
|
33
|
+
return 1;
|
|
34
|
+
const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx, cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;
|
|
35
|
+
const at = (t) => ((ax * t + bx) * t + cx) * t;
|
|
36
|
+
let t = x;
|
|
37
|
+
for (let index = 0; index < 8; index++) {
|
|
38
|
+
const error = at(t) - x;
|
|
39
|
+
if (Math.abs(error) < 1e-6)
|
|
40
|
+
return ((ay * t + by) * t + cy) * t;
|
|
41
|
+
const slope = (3 * ax * t + 2 * bx) * t + cx;
|
|
42
|
+
if (Math.abs(slope) < 1e-6)
|
|
43
|
+
break;
|
|
44
|
+
t -= error / slope;
|
|
45
|
+
}
|
|
46
|
+
let low = 0, high = 1;
|
|
47
|
+
t = x;
|
|
48
|
+
for (let index = 0; index < 32; index++) {
|
|
49
|
+
const error = at(t) - x;
|
|
50
|
+
if (Math.abs(error) < 1e-6)
|
|
51
|
+
break;
|
|
52
|
+
if (error > 0)
|
|
53
|
+
high = t;
|
|
54
|
+
else
|
|
55
|
+
low = t;
|
|
56
|
+
t = (low + high) / 2;
|
|
57
|
+
}
|
|
58
|
+
return ((ay * t + by) * t + cy) * t;
|
|
59
|
+
}
|
|
60
|
+
const sampleCache = new Map();
|
|
61
|
+
/**
|
|
62
|
+
* The curve as progress values at equal steps of time, first 0 and last 1. A renderer that cannot hand the curve to its
|
|
63
|
+
* animation engine (a UI-thread worklet) reads its progress from this table with `sampleNumberFlowEasing`.
|
|
64
|
+
*/
|
|
65
|
+
export function numberFlowEasingSamples(easing) {
|
|
66
|
+
const bezier = numberFlowBezier(easing);
|
|
67
|
+
if (!bezier)
|
|
68
|
+
return numberFlowCurve;
|
|
69
|
+
const key = bezier.join(','), cached = sampleCache.get(key);
|
|
70
|
+
if (cached)
|
|
71
|
+
return cached;
|
|
72
|
+
const steps = 60, samples = Array.from({ length: steps + 1 }, (_, index) => index === 0 ? 0 : index === steps ? 1 : numberFlowBezierAt(bezier, index / steps));
|
|
73
|
+
sampleCache.set(key, samples);
|
|
74
|
+
return samples;
|
|
75
|
+
}
|
|
76
|
+
/** Progress along a sampled curve at time `progress` (0 to 1), interpolated between the two nearest samples. */
|
|
77
|
+
export function sampleNumberFlowEasing(samples, progress) {
|
|
78
|
+
const scaled = Math.max(0, Math.min(1, progress)) * (samples.length - 1), index = Math.floor(scaled), start = samples[index], end = samples[index + 1] ?? start;
|
|
79
|
+
return start + (end - start) * (scaled - index);
|
|
80
|
+
}
|
|
81
|
+
/** A host timing over a fallback: a finite duration is kept within 0 and `numberFlowMaxDuration`, a known curve is kept, anything else falls back. */
|
|
82
|
+
export function resolveNumberFlowTiming(timing, fallback) {
|
|
83
|
+
const duration = finite(timing?.duration) ? Math.max(0, Math.min(numberFlowMaxDuration, timing.duration)) : fallback.duration;
|
|
84
|
+
return { duration, easing: validEasing(timing?.easing) ? timing.easing : fallback.easing };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The three timings of one figure. `duration` is the shorthand: it sets how long digits roll and places slide, and fades take
|
|
88
|
+
* half of it. `transformTiming` is also the roll's timing until `spinTiming` says otherwise, as in NumberFlow.
|
|
89
|
+
*/
|
|
90
|
+
export function resolveNumberFlowTimings({ duration, spinTiming, transformTiming, opacityTiming }) {
|
|
91
|
+
const shorthand = finite(duration) ? duration : undefined, transform = resolveNumberFlowTiming(transformTiming, resolveNumberFlowTiming({ duration: shorthand }, numberFlowDefaults.transform));
|
|
92
|
+
return { transform, spin: resolveNumberFlowTiming(spinTiming, transform), opacity: resolveNumberFlowTiming(opacityTiming, resolveNumberFlowTiming({ duration: shorthand === undefined ? undefined : shorthand / 2 }, numberFlowDefaults.opacity)) };
|
|
93
|
+
}
|
|
94
|
+
/** How many glyphs a place rolls through before it wraps: ten, or `max + 1` where `digits` limits an integer place, and never fewer than the digit it must show. */
|
|
95
|
+
export function numberFlowDigitLength(digits, place, digit = 0) {
|
|
96
|
+
const max = place === null ? undefined : digits?.[place]?.max, length = finite(max) && Number.isInteger(max) && max >= 1 && max <= 9 ? max + 1 : 10;
|
|
97
|
+
return digit >= length ? 10 : length;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* How far a place turns, in glyphs: positive rolls up to higher digits, negative down. With a trend the place keeps turning
|
|
101
|
+
* that way and wraps past its last glyph (9 to 0 going up is +1, not -9); without one it takes the short way its own digits
|
|
102
|
+
* point. `loop` turns an unchanged place once all the way round, for a figure that counts continuously.
|
|
103
|
+
*/
|
|
104
|
+
export function numberFlowDelta(previous, value, trend, length = 10, loop = false) {
|
|
105
|
+
const difference = value - previous;
|
|
106
|
+
if (!difference)
|
|
107
|
+
return loop && trend ? length * Math.sign(trend) : 0;
|
|
108
|
+
const direction = trend || Math.sign(difference);
|
|
109
|
+
if (direction < 0 && value > previous)
|
|
110
|
+
return value - length - previous;
|
|
111
|
+
if (direction > 0 && value < previous)
|
|
112
|
+
return length - previous + value;
|
|
113
|
+
return difference;
|
|
114
|
+
}
|
|
115
|
+
/** The highest place that changed between two readings, in display order, or `undefined` when none did. Places at or below it loop when the figure is continuous. */
|
|
116
|
+
export function numberFlowLoopStart(previous, next) {
|
|
117
|
+
const same = (places, place) => places.some(other => other.place === place.place && other.digit === place.digit);
|
|
118
|
+
const changed = [previous.find(place => place.place !== null && !same(next, place))?.place, next.find(place => place.place !== null && !same(previous, place))?.place].filter((place) => typeof place === 'number');
|
|
119
|
+
return changed.length ? Math.max(...changed) : undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The turn of every place in the new reading, by key. A place the old reading did not have starts from zero, as it does in
|
|
123
|
+
* NumberFlow. `trend` is the resolved direction of the whole change (-1, 0 or 1); places the new reading dropped are not listed.
|
|
124
|
+
*/
|
|
125
|
+
export function numberFlowDeltas(previous, next, { trend, digits, continuous = false }) {
|
|
126
|
+
const before = new Map(previous.map(place => [place.key, place])), start = continuous && trend ? numberFlowLoopStart(previous, next) : undefined, deltas = new Map();
|
|
127
|
+
for (const place of next) {
|
|
128
|
+
const old = before.get(place.key)?.digit ?? 0, length = numberFlowDigitLength(digits, place.place, Math.max(place.digit, old));
|
|
129
|
+
deltas.set(place.key, numberFlowDelta(old, place.digit, trend, length, start !== undefined && place.place !== null && start >= place.place));
|
|
130
|
+
}
|
|
131
|
+
return deltas;
|
|
132
|
+
}
|
|
133
|
+
/** The glyph index a reel shows at a position that has turned any number of times either way. */
|
|
134
|
+
export function numberFlowGlyph(position, length = 10) { return ((Math.round(position) % length) + length) % length; }
|
|
135
|
+
const bidiControls = /[--]/u;
|
|
136
|
+
function strongRTL(character) {
|
|
137
|
+
const point = character.codePointAt(0);
|
|
138
|
+
if (point === undefined)
|
|
139
|
+
return false;
|
|
140
|
+
if ((point >= 0x0660 && point <= 0x0669) || (point >= 0x06f0 && point <= 0x06f9) || (point >= 0x066a && point <= 0x066c))
|
|
141
|
+
return false;
|
|
142
|
+
return (point >= 0x0590 && point <= 0x08ff) || (point >= 0xfb1d && point <= 0xfdff) || (point >= 0xfe70 && point <= 0xfefc) || (point >= 0x10800 && point <= 0x10fff) || (point >= 0x1e800 && point <= 0x1edff) || (point >= 0x1ee00 && point <= 0x1eeff);
|
|
143
|
+
}
|
|
144
|
+
/** Whether text can be drawn place by place from left to right without reordering it: no bidi controls and no right-to-left letters (Arabic-script digits are fine). */
|
|
145
|
+
export function numberFlowNeutral(text) {
|
|
146
|
+
for (const character of Array.from(text))
|
|
147
|
+
if (bidiControls.test(character) || strongRTL(character))
|
|
148
|
+
return false;
|
|
149
|
+
return true;
|
|
150
|
+
}
|