@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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HIG's QR code: the encoder and the drawing geometry, shared by the web and native `QRCode` so both platforms draw the same
|
|
3
|
+
* modules from the same arithmetic. Pure TypeScript with no DOM, React, React Native or package dependency.
|
|
4
|
+
*
|
|
5
|
+
* The encoder follows ISO/IEC 18004 (QR Code Model 2): numeric, alphanumeric and byte (UTF-8) modes, versions 1 to 40, error
|
|
6
|
+
* correction L/M/Q/H, Reed–Solomon blocks, all eight masks scored with the four penalty rules, format and version information.
|
|
7
|
+
*/
|
|
8
|
+
/** Error correction level: roughly 7%, 15%, 25% and 30% of the code can be lost and still read. */
|
|
9
|
+
export type QRErrorCorrection = 'low' | 'medium' | 'quartile' | 'high';
|
|
10
|
+
/** How the payload is packed: digits only, the 45-character upper-case alphabet, or UTF-8 bytes. */
|
|
11
|
+
export type QRMode = 'numeric' | 'alphanumeric' | 'byte';
|
|
12
|
+
export interface QREncodeOptions {
|
|
13
|
+
/** Error correction level; default `medium`. */
|
|
14
|
+
errorCorrection?: QRErrorCorrection;
|
|
15
|
+
/** Symbol version 1 to 40 (21 to 177 modules a side). Omitted, the smallest version that holds the value is used. */
|
|
16
|
+
version?: number;
|
|
17
|
+
/** Mask pattern 0 to 7. Omitted, the mask with the lowest penalty score is used. */
|
|
18
|
+
mask?: number;
|
|
19
|
+
/** Packing mode. Omitted, the densest mode the whole value fits: `numeric`, then `alphanumeric`, then `byte`. */
|
|
20
|
+
mode?: QRMode;
|
|
21
|
+
}
|
|
22
|
+
/** An encoded symbol, without a quiet zone. */
|
|
23
|
+
export interface QRMatrix {
|
|
24
|
+
/** Modules per side: `17 + 4 × version`. */
|
|
25
|
+
size: number;
|
|
26
|
+
version: number;
|
|
27
|
+
errorCorrection: QRErrorCorrection;
|
|
28
|
+
/** The mask pattern applied, 0 to 7. */
|
|
29
|
+
mask: number;
|
|
30
|
+
mode: QRMode;
|
|
31
|
+
/** `size × size` modules in row order; 1 is dark. */
|
|
32
|
+
modules: Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
/** Table 5: the alphanumeric alphabet in value order. */
|
|
35
|
+
export declare const QR_ALPHANUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
|
36
|
+
/** Centres of the alignment patterns along one axis (Annex E); empty for version 1. */
|
|
37
|
+
export declare function qrAlignmentCentres(version: number): number[];
|
|
38
|
+
/** The 15 format bits for a level and mask: five data bits, ten BCH(15,5) bits, masked with 101010000010010. */
|
|
39
|
+
export declare function qrFormatBits(level: QRErrorCorrection, mask: number): number;
|
|
40
|
+
/** The 18 version bits for versions 7 and up: six data bits and twelve Golay(18,6) bits. */
|
|
41
|
+
export declare function qrVersionBits(version: number): number;
|
|
42
|
+
/** The Reed–Solomon error correction codewords of one block: `count` codewords for the data codewords given. */
|
|
43
|
+
export declare function qrErrorCorrectionCodewords(data: Uint8Array, count: number): Uint8Array;
|
|
44
|
+
/** UTF-8 bytes of a string; an unpaired surrogate becomes U+FFFD, as `TextEncoder` writes it. */
|
|
45
|
+
export declare function qrUtf8(text: string): Uint8Array;
|
|
46
|
+
/** The densest mode that holds every character of a value: digits are `numeric`, the Table 5 alphabet `alphanumeric`, anything else `byte`. */
|
|
47
|
+
export declare function qrMode(value: string): QRMode;
|
|
48
|
+
/** Whether mask pattern `mask` inverts the module at a column and row (Table 10). */
|
|
49
|
+
export declare function qrMaskAt(mask: number, column: number, row: number): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The mask penalty of a symbol (ISO/IEC 18004 §7.8.3): runs of five or more, 2×2 blocks, finder-like sequences and the share of
|
|
52
|
+
* dark modules. `encodeQR` scores each candidate with its format and version cells still light, as the `qr` encoder behind Cuer
|
|
53
|
+
* and python-qrcode do, so HIG picks the same mask they pick.
|
|
54
|
+
*/
|
|
55
|
+
export declare function qrPenalty(modules: Uint8Array, size: number): number;
|
|
56
|
+
/** Why a value cannot be encoded: it is longer than a version 40 symbol (or the requested version) holds at the level. */
|
|
57
|
+
export declare class QRCapacityError extends RangeError {
|
|
58
|
+
constructor(message: string);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Encodes a string as a QR code symbol. Throws `QRCapacityError` when the value does not fit, and `RangeError` or `TypeError`
|
|
62
|
+
* for an option outside its range. The same value and options always give the same modules.
|
|
63
|
+
*/
|
|
64
|
+
export declare function encodeQR(value: string, options?: QREncodeOptions): QRMatrix;
|
|
65
|
+
/** The modules of a symbol as rows of booleans (`true` is dark), the shape other encoders return. */
|
|
66
|
+
export declare function qrRows(matrix: Pick<QRMatrix, 'size' | 'modules'>): boolean[][];
|
|
67
|
+
/** Modules a finder pattern spans on each side. */
|
|
68
|
+
export declare const QR_FINDER = 7;
|
|
69
|
+
/** Quiet zone ISO/IEC 18004 asks for around a symbol, in modules. */
|
|
70
|
+
export declare const QR_QUIET_ZONE = 4;
|
|
71
|
+
/** Radius of a data module's dot, in modules: Cuer's cell with its 10% inset, fully rounded. */
|
|
72
|
+
export declare const QR_DOT_RADIUS = 0.4;
|
|
73
|
+
export interface QRGeometryOptions {
|
|
74
|
+
/** Clears the centre square for an arena: an image or mark drawn over the code. */
|
|
75
|
+
arena?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** A QR code's drawing in module units, measured from the symbol's top-left corner (the quiet zone is outside it). */
|
|
78
|
+
export interface QRGeometry {
|
|
79
|
+
/** Modules per side. */
|
|
80
|
+
size: number;
|
|
81
|
+
/** One SVG path for the whole code: a round dot for every dark data module, then the three finder patterns, each a rounded ring around a rounded core. Fill it with the non-zero rule (the default). */
|
|
82
|
+
path: string;
|
|
83
|
+
/** Dots in `path`: the dark modules outside the finder patterns and the arena. */
|
|
84
|
+
dots: number;
|
|
85
|
+
/** Top-left module of each finder pattern: top left, top right, bottom left. */
|
|
86
|
+
finders: readonly {
|
|
87
|
+
x: number;
|
|
88
|
+
y: number;
|
|
89
|
+
}[];
|
|
90
|
+
/** The centre square cleared of modules, or `null` without an arena. `origin` is its first column and row and `size` its edge, in whole modules. */
|
|
91
|
+
arena: {
|
|
92
|
+
origin: number;
|
|
93
|
+
size: number;
|
|
94
|
+
} | null;
|
|
95
|
+
}
|
|
96
|
+
/** Edge of the cleared centre square for a symbol: a quarter of the side, made odd so it is centred on the centre module. */
|
|
97
|
+
export declare function qrArenaSize(size: number): number;
|
|
98
|
+
/**
|
|
99
|
+
* The Cuer look as one path: round dots for the data modules and rounded finder patterns, with the centre left clear when an
|
|
100
|
+
* arena is drawn. The ring is Cuer's one-module stroke around a 6×6 square of radius 1.25, written as a filled outline (7×7,
|
|
101
|
+
* radius 1.75) with a hole (5×5, radius 0.75); the core is 3×3 with radius 0.5.
|
|
102
|
+
*/
|
|
103
|
+
export declare function qrGeometry(matrix: Pick<QRMatrix, 'size' | 'modules'>, options?: QRGeometryOptions): QRGeometry;
|
|
104
|
+
export interface QRCodeOptions {
|
|
105
|
+
/** Error correction level. Omitted, `high` with an arena and `medium` without; under an arena `low` and `medium` are raised to `quartile`. */
|
|
106
|
+
errorCorrection?: QRErrorCorrection;
|
|
107
|
+
/** Clears the centre for an arena. */
|
|
108
|
+
arena?: boolean;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The error correction a code is drawn with. Without an arena it is the host's level, or `medium`. An arena covers the centre
|
|
112
|
+
* of the code, so there the default is `high` and a host's `low` or `medium` is raised to `quartile`: with the centre covered,
|
|
113
|
+
* `quartile` and `high` codes decoded in every case tested (tests/qr-model.test.ts), while some `medium` and most `low` ones did not.
|
|
114
|
+
*/
|
|
115
|
+
export declare function qrErrorCorrection(errorCorrection: QRErrorCorrection | undefined, arena: boolean): QRErrorCorrection;
|
|
116
|
+
/**
|
|
117
|
+
* Encodes a value and lays it out, for a renderer: `null` when the value does not fit a QR code, so a component can draw
|
|
118
|
+
* nothing instead of throwing while it renders.
|
|
119
|
+
*/
|
|
120
|
+
export declare function qrCodeGeometry(value: string, options?: QRCodeOptions): QRGeometry | null;
|
|
121
|
+
/** Where a renderer draws a code inside a square of `edge` pixels with `quietZone` clear modules on every side. */
|
|
122
|
+
export interface QRFrame {
|
|
123
|
+
/** Clear modules on every side, as drawn: never below zero. */
|
|
124
|
+
quietZone: number;
|
|
125
|
+
/** Modules across the square: the symbol and both quiet zones. */
|
|
126
|
+
span: number;
|
|
127
|
+
/** The SVG `viewBox`: module units with the symbol's top-left corner at the origin, so the path needs no transform. */
|
|
128
|
+
viewBox: string;
|
|
129
|
+
/** Pixels per module. */
|
|
130
|
+
unit: number;
|
|
131
|
+
/** Corner radius of the background tile, in modules: half the quiet zone, so a code without one has square corners. */
|
|
132
|
+
tileRadius: number;
|
|
133
|
+
/**
|
|
134
|
+
* The arena's box, half a module inside the cleared square with a one-module corner radius; `null` without an arena.
|
|
135
|
+
* `x`, `size` and `radius` are in modules from the symbol's corner (for a drawing inside the SVG); `left`, `edge` and
|
|
136
|
+
* `corner` are the same box in pixels from the square's corner (for an overlay of fixed size); `inset` and `extent` are
|
|
137
|
+
* its offset and edge as fractions of the square's edge (for an overlay that scales with the square).
|
|
138
|
+
*/
|
|
139
|
+
arena: {
|
|
140
|
+
x: number;
|
|
141
|
+
size: number;
|
|
142
|
+
radius: number;
|
|
143
|
+
left: number;
|
|
144
|
+
edge: number;
|
|
145
|
+
corner: number;
|
|
146
|
+
inset: number;
|
|
147
|
+
extent: number;
|
|
148
|
+
} | null;
|
|
149
|
+
}
|
|
150
|
+
/** Lays a geometry out in a square: the view box, the module size and the arena's box. A `quietZone` below zero or not finite counts as zero. */
|
|
151
|
+
export declare function qrFrame(geometry: Pick<QRGeometry, 'size' | 'arena'>, edge: number, quietZone?: number): QRFrame;
|