@velion-la/onboarding-sdk-react-native 1.4.0-beta.1 → 1.4.0-beta.3
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/CHANGELOG.md +18 -0
- package/README.md +33 -1
- package/lib/commonjs/camera/AddressSearchBar.js +9 -7
- package/lib/commonjs/camera/AddressSearchBar.js.map +1 -1
- package/lib/commonjs/camera/DocumentCapture.js +7 -6
- package/lib/commonjs/camera/DocumentCapture.js.map +1 -1
- package/lib/commonjs/camera/LivenessCamera.js +6 -5
- package/lib/commonjs/camera/LivenessCamera.js.map +1 -1
- package/lib/commonjs/camera/MapAddressPicker.js +2 -1
- package/lib/commonjs/camera/MapAddressPicker.js.map +1 -1
- package/lib/commonjs/core/VelionOnboarding.js +123 -6
- package/lib/commonjs/core/VelionOnboarding.js.map +1 -1
- package/lib/commonjs/core/sessionCancelledCopy.js +25 -0
- package/lib/commonjs/core/sessionCancelledCopy.js.map +1 -0
- package/lib/commonjs/core/sessionStateMapper.js +17 -4
- package/lib/commonjs/core/sessionStateMapper.js.map +1 -1
- package/lib/commonjs/core/sseReasonMessages.js +19 -1
- package/lib/commonjs/core/sseReasonMessages.js.map +1 -1
- package/lib/commonjs/i18n/strings/en.js +5 -1
- package/lib/commonjs/i18n/strings/en.js.map +1 -1
- package/lib/commonjs/i18n/strings/es.js +5 -1
- package/lib/commonjs/i18n/strings/es.js.map +1 -1
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/steps/AddressInfoStep.js +4 -3
- package/lib/commonjs/steps/AddressInfoStep.js.map +1 -1
- package/lib/commonjs/steps/DocumentsOcrStep.js +4 -3
- package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/commonjs/steps/EconomicActivityStep.js +3 -2
- package/lib/commonjs/steps/EconomicActivityStep.js.map +1 -1
- package/lib/commonjs/steps/EmailOtpStep.js +2 -1
- package/lib/commonjs/steps/EmailOtpStep.js.map +1 -1
- package/lib/commonjs/steps/FaceMatchStep.js +3 -2
- package/lib/commonjs/steps/FaceMatchStep.js.map +1 -1
- package/lib/commonjs/steps/LivenessMatchStep.js +3 -2
- package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
- package/lib/commonjs/steps/PhoneOtpStep.js +2 -1
- package/lib/commonjs/steps/PhoneOtpStep.js.map +1 -1
- package/lib/commonjs/steps/TermsAndConditionsStep.js +3 -2
- package/lib/commonjs/steps/TermsAndConditionsStep.js.map +1 -1
- package/lib/commonjs/transport/api.js +18 -1
- package/lib/commonjs/transport/api.js.map +1 -1
- package/lib/commonjs/transport/sse.js +2 -2
- package/lib/commonjs/transport/sse.js.map +1 -1
- package/lib/commonjs/types/index.js +18 -6
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/ui/StepShell.js +3 -2
- package/lib/commonjs/ui/StepShell.js.map +1 -1
- package/lib/commonjs/ui/VelionOnboardingScreen.js +5 -4
- package/lib/commonjs/ui/VelionOnboardingScreen.js.map +1 -1
- package/lib/commonjs/ui/icons/StepIcon.js +2 -2
- package/lib/commonjs/ui/icons/StepIcon.js.map +1 -1
- package/lib/commonjs/ui/overlays/AnalyzingOverlay.js +3 -2
- package/lib/commonjs/ui/overlays/AnalyzingOverlay.js.map +1 -1
- package/lib/commonjs/ui/overlays/LoadingOverlay.js +2 -1
- package/lib/commonjs/ui/overlays/LoadingOverlay.js.map +1 -1
- package/lib/commonjs/ui/overlays/RetryDialog.js +4 -3
- package/lib/commonjs/ui/overlays/RetryDialog.js.map +1 -1
- package/lib/commonjs/ui/primitives/BackButton.js +2 -1
- package/lib/commonjs/ui/primitives/BackButton.js.map +1 -1
- package/lib/commonjs/ui/primitives/Banner.js +3 -2
- package/lib/commonjs/ui/primitives/Banner.js.map +1 -1
- package/lib/commonjs/ui/primitives/Button.js +8 -5
- package/lib/commonjs/ui/primitives/Button.js.map +1 -1
- package/lib/commonjs/ui/primitives/Checkbox.js +5 -4
- package/lib/commonjs/ui/primitives/Checkbox.js.map +1 -1
- package/lib/commonjs/ui/primitives/CountrySelect.js +16 -13
- package/lib/commonjs/ui/primitives/CountrySelect.js.map +1 -1
- package/lib/commonjs/ui/primitives/DatePicker.js +4 -3
- package/lib/commonjs/ui/primitives/DatePicker.js.map +1 -1
- package/lib/commonjs/ui/primitives/Input.js +9 -7
- package/lib/commonjs/ui/primitives/Input.js.map +1 -1
- package/lib/commonjs/ui/primitives/SearchableSingleSelectList.js +8 -6
- package/lib/commonjs/ui/primitives/SearchableSingleSelectList.js.map +1 -1
- package/lib/commonjs/ui/primitives/Select.js +11 -9
- package/lib/commonjs/ui/primitives/Select.js.map +1 -1
- package/lib/commonjs/ui/primitives/Text.js +67 -0
- package/lib/commonjs/ui/primitives/Text.js.map +1 -0
- package/lib/commonjs/ui/primitives/index.js +13 -0
- package/lib/commonjs/ui/primitives/index.js.map +1 -1
- package/lib/commonjs/ui/theme/ThemeProvider.js +14 -1
- package/lib/commonjs/ui/theme/ThemeProvider.js.map +1 -1
- package/lib/commonjs/ui/theme/fontLoader.js +77 -0
- package/lib/commonjs/ui/theme/fontLoader.js.map +1 -0
- package/lib/commonjs/ui/theme/fonts.js +200 -0
- package/lib/commonjs/ui/theme/fonts.js.map +1 -0
- package/lib/commonjs/ui/theme/index.js +31 -0
- package/lib/commonjs/ui/theme/index.js.map +1 -1
- package/lib/commonjs/ui/theme/tokens.js +32 -9
- package/lib/commonjs/ui/theme/tokens.js.map +1 -1
- package/lib/module/camera/AddressSearchBar.js +5 -3
- package/lib/module/camera/AddressSearchBar.js.map +1 -1
- package/lib/module/camera/DocumentCapture.js +2 -1
- package/lib/module/camera/DocumentCapture.js.map +1 -1
- package/lib/module/camera/LivenessCamera.js +2 -1
- package/lib/module/camera/LivenessCamera.js.map +1 -1
- package/lib/module/camera/MapAddressPicker.js +2 -1
- package/lib/module/camera/MapAddressPicker.js.map +1 -1
- package/lib/module/core/VelionOnboarding.js +124 -7
- package/lib/module/core/VelionOnboarding.js.map +1 -1
- package/lib/module/core/sessionCancelledCopy.js +21 -0
- package/lib/module/core/sessionCancelledCopy.js.map +1 -0
- package/lib/module/core/sessionStateMapper.js +16 -4
- package/lib/module/core/sessionStateMapper.js.map +1 -1
- package/lib/module/core/sseReasonMessages.js +18 -0
- package/lib/module/core/sseReasonMessages.js.map +1 -1
- package/lib/module/i18n/strings/en.js +5 -1
- package/lib/module/i18n/strings/en.js.map +1 -1
- package/lib/module/i18n/strings/es.js +5 -1
- package/lib/module/i18n/strings/es.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/steps/AddressInfoStep.js +2 -1
- package/lib/module/steps/AddressInfoStep.js.map +1 -1
- package/lib/module/steps/DocumentsOcrStep.js +2 -1
- package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/module/steps/EconomicActivityStep.js +2 -1
- package/lib/module/steps/EconomicActivityStep.js.map +1 -1
- package/lib/module/steps/EmailOtpStep.js +2 -1
- package/lib/module/steps/EmailOtpStep.js.map +1 -1
- package/lib/module/steps/FaceMatchStep.js +2 -1
- package/lib/module/steps/FaceMatchStep.js.map +1 -1
- package/lib/module/steps/LivenessMatchStep.js +2 -1
- package/lib/module/steps/LivenessMatchStep.js.map +1 -1
- package/lib/module/steps/PhoneOtpStep.js +2 -1
- package/lib/module/steps/PhoneOtpStep.js.map +1 -1
- package/lib/module/steps/TermsAndConditionsStep.js +2 -1
- package/lib/module/steps/TermsAndConditionsStep.js.map +1 -1
- package/lib/module/transport/api.js +18 -1
- package/lib/module/transport/api.js.map +1 -1
- package/lib/module/transport/sse.js +2 -2
- package/lib/module/transport/sse.js.map +1 -1
- package/lib/module/types/index.js +18 -6
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/ui/StepShell.js +2 -1
- package/lib/module/ui/StepShell.js.map +1 -1
- package/lib/module/ui/VelionOnboardingScreen.js +2 -1
- package/lib/module/ui/VelionOnboardingScreen.js.map +1 -1
- package/lib/module/ui/icons/StepIcon.js +1 -1
- package/lib/module/ui/icons/StepIcon.js.map +1 -1
- package/lib/module/ui/overlays/AnalyzingOverlay.js +2 -1
- package/lib/module/ui/overlays/AnalyzingOverlay.js.map +1 -1
- package/lib/module/ui/overlays/LoadingOverlay.js +2 -1
- package/lib/module/ui/overlays/LoadingOverlay.js.map +1 -1
- package/lib/module/ui/overlays/RetryDialog.js +2 -1
- package/lib/module/ui/overlays/RetryDialog.js.map +1 -1
- package/lib/module/ui/primitives/BackButton.js +2 -1
- package/lib/module/ui/primitives/BackButton.js.map +1 -1
- package/lib/module/ui/primitives/Banner.js +2 -1
- package/lib/module/ui/primitives/Banner.js.map +1 -1
- package/lib/module/ui/primitives/Button.js +7 -4
- package/lib/module/ui/primitives/Button.js.map +1 -1
- package/lib/module/ui/primitives/Checkbox.js +2 -1
- package/lib/module/ui/primitives/Checkbox.js.map +1 -1
- package/lib/module/ui/primitives/CountrySelect.js +8 -5
- package/lib/module/ui/primitives/CountrySelect.js.map +1 -1
- package/lib/module/ui/primitives/DatePicker.js +2 -1
- package/lib/module/ui/primitives/DatePicker.js.map +1 -1
- package/lib/module/ui/primitives/Input.js +6 -4
- package/lib/module/ui/primitives/Input.js.map +1 -1
- package/lib/module/ui/primitives/SearchableSingleSelectList.js +5 -3
- package/lib/module/ui/primitives/SearchableSingleSelectList.js.map +1 -1
- package/lib/module/ui/primitives/Select.js +5 -3
- package/lib/module/ui/primitives/Select.js.map +1 -1
- package/lib/module/ui/primitives/Text.js +65 -0
- package/lib/module/ui/primitives/Text.js.map +1 -0
- package/lib/module/ui/primitives/index.js +1 -0
- package/lib/module/ui/primitives/index.js.map +1 -1
- package/lib/module/ui/theme/ThemeProvider.js +13 -1
- package/lib/module/ui/theme/ThemeProvider.js.map +1 -1
- package/lib/module/ui/theme/fontLoader.js +70 -0
- package/lib/module/ui/theme/fontLoader.js.map +1 -0
- package/lib/module/ui/theme/fonts.js +191 -0
- package/lib/module/ui/theme/fonts.js.map +1 -0
- package/lib/module/ui/theme/index.js +3 -2
- package/lib/module/ui/theme/index.js.map +1 -1
- package/lib/module/ui/theme/tokens.js +31 -9
- package/lib/module/ui/theme/tokens.js.map +1 -1
- package/lib/typescript/camera/AddressSearchBar.d.ts.map +1 -1
- package/lib/typescript/core/VelionOnboarding.d.ts +24 -0
- package/lib/typescript/core/VelionOnboarding.d.ts.map +1 -1
- package/lib/typescript/core/sessionCancelledCopy.d.ts +14 -0
- package/lib/typescript/core/sessionCancelledCopy.d.ts.map +1 -0
- package/lib/typescript/core/sessionStateMapper.d.ts +11 -3
- package/lib/typescript/core/sessionStateMapper.d.ts.map +1 -1
- package/lib/typescript/core/sseReasonMessages.d.ts +6 -0
- package/lib/typescript/core/sseReasonMessages.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/es.d.ts +2 -0
- package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/steps/AddressInfoStep.d.ts.map +1 -1
- package/lib/typescript/steps/EconomicActivityStep.d.ts.map +1 -1
- package/lib/typescript/steps/EmailOtpStep.d.ts.map +1 -1
- package/lib/typescript/steps/FaceMatchStep.d.ts.map +1 -1
- package/lib/typescript/steps/LivenessMatchStep.d.ts.map +1 -1
- package/lib/typescript/steps/PhoneOtpStep.d.ts.map +1 -1
- package/lib/typescript/steps/TermsAndConditionsStep.d.ts.map +1 -1
- package/lib/typescript/transport/api.d.ts +1 -0
- package/lib/typescript/transport/api.d.ts.map +1 -1
- package/lib/typescript/transport/sse.d.ts.map +1 -1
- package/lib/typescript/types/index.d.ts +58 -12
- package/lib/typescript/types/index.d.ts.map +1 -1
- package/lib/typescript/ui/StepShell.d.ts.map +1 -1
- package/lib/typescript/ui/VelionOnboardingScreen.d.ts.map +1 -1
- package/lib/typescript/ui/overlays/LoadingOverlay.d.ts.map +1 -1
- package/lib/typescript/ui/overlays/RetryDialog.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/BackButton.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/Banner.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/Button.d.ts +2 -1
- package/lib/typescript/ui/primitives/Button.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/Checkbox.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/CountrySelect.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/DatePicker.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/Input.d.ts +3 -3
- package/lib/typescript/ui/primitives/Input.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/SearchableSingleSelectList.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/Select.d.ts.map +1 -1
- package/lib/typescript/ui/primitives/Text.d.ts +19 -0
- package/lib/typescript/ui/primitives/Text.d.ts.map +1 -0
- package/lib/typescript/ui/primitives/index.d.ts +1 -0
- package/lib/typescript/ui/primitives/index.d.ts.map +1 -1
- package/lib/typescript/ui/theme/ThemeProvider.d.ts +7 -0
- package/lib/typescript/ui/theme/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/ui/theme/fontLoader.d.ts +28 -0
- package/lib/typescript/ui/theme/fontLoader.d.ts.map +1 -0
- package/lib/typescript/ui/theme/fonts.d.ts +157 -0
- package/lib/typescript/ui/theme/fonts.d.ts.map +1 -0
- package/lib/typescript/ui/theme/index.d.ts +3 -2
- package/lib/typescript/ui/theme/index.d.ts.map +1 -1
- package/lib/typescript/ui/theme/tokens.d.ts +25 -2
- package/lib/typescript/ui/theme/tokens.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/camera/AddressSearchBar.tsx +3 -4
- package/src/camera/DocumentCapture.tsx +1 -1
- package/src/camera/LivenessCamera.tsx +1 -1
- package/src/camera/MapAddressPicker.tsx +1 -1
- package/src/core/VelionOnboarding.ts +118 -5
- package/src/core/sessionCancelledCopy.ts +29 -0
- package/src/core/sessionStateMapper.ts +18 -5
- package/src/core/sseReasonMessages.ts +20 -0
- package/src/i18n/strings/en.ts +5 -0
- package/src/i18n/strings/es.ts +5 -0
- package/src/index.ts +2 -0
- package/src/steps/AddressInfoStep.tsx +6 -1
- package/src/steps/DocumentsOcrStep.tsx +1 -1
- package/src/steps/EconomicActivityStep.tsx +6 -1
- package/src/steps/EmailOtpStep.tsx +6 -1
- package/src/steps/FaceMatchStep.tsx +6 -1
- package/src/steps/LivenessMatchStep.tsx +7 -1
- package/src/steps/PhoneOtpStep.tsx +6 -1
- package/src/steps/TermsAndConditionsStep.tsx +7 -1
- package/src/transport/api.ts +17 -1
- package/src/transport/sse.ts +2 -0
- package/src/types/index.ts +58 -12
- package/src/ui/StepShell.tsx +6 -1
- package/src/ui/VelionOnboardingScreen.tsx +5 -1
- package/src/ui/icons/StepIcon.tsx +1 -1
- package/src/ui/overlays/AnalyzingOverlay.tsx +1 -1
- package/src/ui/overlays/LoadingOverlay.tsx +7 -1
- package/src/ui/overlays/RetryDialog.tsx +5 -1
- package/src/ui/primitives/BackButton.tsx +5 -1
- package/src/ui/primitives/Banner.tsx +5 -1
- package/src/ui/primitives/Button.tsx +5 -4
- package/src/ui/primitives/Checkbox.tsx +5 -1
- package/src/ui/primitives/CountrySelect.tsx +5 -6
- package/src/ui/primitives/DatePicker.tsx +7 -1
- package/src/ui/primitives/Input.tsx +6 -6
- package/src/ui/primitives/SearchableSingleSelectList.tsx +3 -4
- package/src/ui/primitives/Select.tsx +3 -3
- package/src/ui/primitives/Text.tsx +66 -0
- package/src/ui/primitives/index.ts +1 -0
- package/src/ui/theme/ThemeProvider.tsx +15 -2
- package/src/ui/theme/fontLoader.ts +92 -0
- package/src/ui/theme/fonts.ts +220 -0
- package/src/ui/theme/index.ts +9 -0
- package/src/ui/theme/tokens.ts +44 -6
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Loads the theme's catalog font with `expo-font` (OSDKR-45).
|
|
3
|
+
*
|
|
4
|
+
* `useCatalogFont` returns the catalog id only once every face is registered,
|
|
5
|
+
* so `ThemeProvider` never hands texts a family the platform does not have.
|
|
6
|
+
* Until then — and for good if the download fails — texts use the system font.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useEffect, useState } from 'react';
|
|
10
|
+
import * as ExpoFont from 'expo-font';
|
|
11
|
+
import { log } from '../../utils/log';
|
|
12
|
+
import {
|
|
13
|
+
fontSources,
|
|
14
|
+
resolveFontId,
|
|
15
|
+
type VelionCatalogFontId,
|
|
16
|
+
} from './fonts';
|
|
17
|
+
|
|
18
|
+
/** The slice of `expo-font` the loader uses; injectable for tests. */
|
|
19
|
+
export interface FontApi {
|
|
20
|
+
isLoaded(fontFamily: string): boolean;
|
|
21
|
+
loadAsync(fontMap: Record<string, string>): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const expoFontApi: FontApi = {
|
|
25
|
+
isLoaded: (fontFamily) => ExpoFont.isLoaded(fontFamily),
|
|
26
|
+
loadAsync: (fontMap) => ExpoFont.loadAsync(fontMap),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** True when every face of the font is already registered. */
|
|
30
|
+
export function isCatalogFontLoaded(
|
|
31
|
+
fontId: VelionCatalogFontId,
|
|
32
|
+
api: FontApi = expoFontApi,
|
|
33
|
+
): boolean {
|
|
34
|
+
return Object.keys(fontSources(fontId)).every((face) => api.isLoaded(face));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Registers every face of the font. Resolves `true` when they are all usable
|
|
39
|
+
* and `false` when the download failed; it never rejects, because a missing
|
|
40
|
+
* font must not break the flow.
|
|
41
|
+
*/
|
|
42
|
+
export async function loadCatalogFont(
|
|
43
|
+
fontId: VelionCatalogFontId,
|
|
44
|
+
api: FontApi = expoFontApi,
|
|
45
|
+
): Promise<boolean> {
|
|
46
|
+
if (isCatalogFontLoaded(fontId, api)) return true;
|
|
47
|
+
try {
|
|
48
|
+
await api.loadAsync(fontSources(fontId));
|
|
49
|
+
return true;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
log.warn(
|
|
52
|
+
`Could not load font "${fontId}"; using the system font.`,
|
|
53
|
+
error,
|
|
54
|
+
);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Resolves `fontFamily` against the catalog and loads it. Returns the id once
|
|
61
|
+
* the font is usable, `null` while it loads, when it failed, or when the value
|
|
62
|
+
* is not a catalog font.
|
|
63
|
+
*/
|
|
64
|
+
export function useCatalogFont(
|
|
65
|
+
fontFamily: string | undefined,
|
|
66
|
+
): VelionCatalogFontId | null {
|
|
67
|
+
const fontId = resolveFontId(fontFamily);
|
|
68
|
+
const [loadedFontId, setLoadedFontId] = useState<VelionCatalogFontId | null>(
|
|
69
|
+
() => (fontId && isCatalogFontLoaded(fontId) ? fontId : null),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!fontId) {
|
|
74
|
+
if (fontFamily && fontFamily.trim().toLowerCase() !== 'system') {
|
|
75
|
+
log.warn(
|
|
76
|
+
`Font "${fontFamily}" is not in the SDK font catalog; using the system font.`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
setLoadedFontId(null);
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
let active = true;
|
|
83
|
+
loadCatalogFont(fontId).then((loaded) => {
|
|
84
|
+
if (active) setLoadedFontId(loaded ? fontId : null);
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
active = false;
|
|
88
|
+
};
|
|
89
|
+
}, [fontId, fontFamily]);
|
|
90
|
+
|
|
91
|
+
return loadedFontId === fontId ? loadedFontId : null;
|
|
92
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Closed font catalog for `VelionTheme.fontFamily` (OSDKR-45).
|
|
3
|
+
*
|
|
4
|
+
* The theme names a font by id; the SDK maps that id to the font files it
|
|
5
|
+
* downloads with `expo-font`. A URL never comes from configuration (R-B12 of
|
|
6
|
+
* the web-onboarding design): an id outside the catalog renders with the
|
|
7
|
+
* system font. The ids and the catalog must stay in sync with the web SDK
|
|
8
|
+
* (OSDKW-39), so a workflow looks the same on web and mobile.
|
|
9
|
+
*
|
|
10
|
+
* Each family ships four static faces (400 / 500 / 600 / 700) — the weights
|
|
11
|
+
* the SDK's text styles use. Lighter weights resolve to 400 and heavier ones
|
|
12
|
+
* to 700. The files are the Google Fonts TTF instances (iOS and Android do not
|
|
13
|
+
* load WOFF2); the URLs are immutable and versioned by Google.
|
|
14
|
+
*
|
|
15
|
+
* This module has no React Native imports so it can be unit-tested in Node.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Weight slots the catalog ships a face for. */
|
|
19
|
+
export type FontWeightSlot = 400 | 500 | 600 | 700;
|
|
20
|
+
|
|
21
|
+
interface FontFamilyEntry {
|
|
22
|
+
/** Family name as Google Fonts publishes it. */
|
|
23
|
+
displayName: string;
|
|
24
|
+
/** One TTF per weight slot. */
|
|
25
|
+
faces: Record<FontWeightSlot, string>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const CATALOG = {
|
|
29
|
+
'inter': {
|
|
30
|
+
displayName: 'Inter',
|
|
31
|
+
faces: {
|
|
32
|
+
400: 'https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfMZg.ttf',
|
|
33
|
+
500: 'https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuI6fMZg.ttf',
|
|
34
|
+
600: 'https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuGKYMZg.ttf',
|
|
35
|
+
700: 'https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuFuYMZg.ttf',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
'roboto': {
|
|
39
|
+
displayName: 'Roboto',
|
|
40
|
+
faces: {
|
|
41
|
+
400: 'https://fonts.gstatic.com/s/roboto/v51/KFOMCnqEu92Fr1ME7kSn66aGLdTylUAMQXC89YmC2DPNWubEbWmT.ttf',
|
|
42
|
+
500: 'https://fonts.gstatic.com/s/roboto/v51/KFOMCnqEu92Fr1ME7kSn66aGLdTylUAMQXC89YmC2DPNWub2bWmT.ttf',
|
|
43
|
+
600: 'https://fonts.gstatic.com/s/roboto/v51/KFOMCnqEu92Fr1ME7kSn66aGLdTylUAMQXC89YmC2DPNWuYaammT.ttf',
|
|
44
|
+
700: 'https://fonts.gstatic.com/s/roboto/v51/KFOMCnqEu92Fr1ME7kSn66aGLdTylUAMQXC89YmC2DPNWuYjammT.ttf',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
'open-sans': {
|
|
48
|
+
displayName: 'Open Sans',
|
|
49
|
+
faces: {
|
|
50
|
+
400: 'https://fonts.gstatic.com/s/opensans/v44/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsjZ0C4n.ttf',
|
|
51
|
+
500: 'https://fonts.gstatic.com/s/opensans/v44/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsjr0C4n.ttf',
|
|
52
|
+
600: 'https://fonts.gstatic.com/s/opensans/v44/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsgH1y4n.ttf',
|
|
53
|
+
700: 'https://fonts.gstatic.com/s/opensans/v44/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsg-1y4n.ttf',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
'montserrat': {
|
|
57
|
+
displayName: 'Montserrat',
|
|
58
|
+
faces: {
|
|
59
|
+
400: 'https://fonts.gstatic.com/s/montserrat/v31/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCtr6Ew-.ttf',
|
|
60
|
+
500: 'https://fonts.gstatic.com/s/montserrat/v31/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCtZ6Ew-.ttf',
|
|
61
|
+
600: 'https://fonts.gstatic.com/s/montserrat/v31/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCu170w-.ttf',
|
|
62
|
+
700: 'https://fonts.gstatic.com/s/montserrat/v31/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCuM70w-.ttf',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
'poppins': {
|
|
66
|
+
displayName: 'Poppins',
|
|
67
|
+
faces: {
|
|
68
|
+
400: 'https://fonts.gstatic.com/s/poppins/v24/pxiEyp8kv8JHgFVrFJA.ttf',
|
|
69
|
+
500: 'https://fonts.gstatic.com/s/poppins/v24/pxiByp8kv8JHgFVrLGT9V1s.ttf',
|
|
70
|
+
600: 'https://fonts.gstatic.com/s/poppins/v24/pxiByp8kv8JHgFVrLEj6V1s.ttf',
|
|
71
|
+
700: 'https://fonts.gstatic.com/s/poppins/v24/pxiByp8kv8JHgFVrLCz7V1s.ttf',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
'nunito': {
|
|
75
|
+
displayName: 'Nunito',
|
|
76
|
+
faces: {
|
|
77
|
+
400: 'https://fonts.gstatic.com/s/nunito/v32/XRXI3I6Li01BKofiOc5wtlZ2di8HDLshRTM.ttf',
|
|
78
|
+
500: 'https://fonts.gstatic.com/s/nunito/v32/XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhRTM.ttf',
|
|
79
|
+
600: 'https://fonts.gstatic.com/s/nunito/v32/XRXI3I6Li01BKofiOc5wtlZ2di8HDGUmRTM.ttf',
|
|
80
|
+
700: 'https://fonts.gstatic.com/s/nunito/v32/XRXI3I6Li01BKofiOc5wtlZ2di8HDFwmRTM.ttf',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
'source-sans-3': {
|
|
84
|
+
displayName: 'Source Sans 3',
|
|
85
|
+
faces: {
|
|
86
|
+
400: 'https://fonts.gstatic.com/s/sourcesans3/v20/nwpBtKy2OAdR1K-IwhWudF-R9QMylBJAV3Bo8Ky461EN.ttf',
|
|
87
|
+
500: 'https://fonts.gstatic.com/s/sourcesans3/v20/nwpBtKy2OAdR1K-IwhWudF-R9QMylBJAV3Bo8KyK61EN.ttf',
|
|
88
|
+
600: 'https://fonts.gstatic.com/s/sourcesans3/v20/nwpBtKy2OAdR1K-IwhWudF-R9QMylBJAV3Bo8Kxm7FEN.ttf',
|
|
89
|
+
700: 'https://fonts.gstatic.com/s/sourcesans3/v20/nwpBtKy2OAdR1K-IwhWudF-R9QMylBJAV3Bo8Kxf7FEN.ttf',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
'work-sans': {
|
|
93
|
+
displayName: 'Work Sans',
|
|
94
|
+
faces: {
|
|
95
|
+
400: 'https://fonts.gstatic.com/s/worksans/v24/QGY_z_wNahGAdqQ43RhVcIgYT2Xz5u32K0nXNig.ttf',
|
|
96
|
+
500: 'https://fonts.gstatic.com/s/worksans/v24/QGY_z_wNahGAdqQ43RhVcIgYT2Xz5u32K3vXNig.ttf',
|
|
97
|
+
600: 'https://fonts.gstatic.com/s/worksans/v24/QGY_z_wNahGAdqQ43RhVcIgYT2Xz5u32K5fQNig.ttf',
|
|
98
|
+
700: 'https://fonts.gstatic.com/s/worksans/v24/QGY_z_wNahGAdqQ43RhVcIgYT2Xz5u32K67QNig.ttf',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
'ibm-plex-sans': {
|
|
102
|
+
displayName: 'IBM Plex Sans',
|
|
103
|
+
faces: {
|
|
104
|
+
400: 'https://fonts.gstatic.com/s/ibmplexsans/v23/zYXGKVElMYYaJe8bpLHnCwDKr932-G7dytD-Dmu1swZSAXcomDVmadSD6llzAA.ttf',
|
|
105
|
+
500: 'https://fonts.gstatic.com/s/ibmplexsans/v23/zYXGKVElMYYaJe8bpLHnCwDKr932-G7dytD-Dmu1swZSAXcomDVmadSD2FlzAA.ttf',
|
|
106
|
+
600: 'https://fonts.gstatic.com/s/ibmplexsans/v23/zYXGKVElMYYaJe8bpLHnCwDKr932-G7dytD-Dmu1swZSAXcomDVmadSDNF5zAA.ttf',
|
|
107
|
+
700: 'https://fonts.gstatic.com/s/ibmplexsans/v23/zYXGKVElMYYaJe8bpLHnCwDKr932-G7dytD-Dmu1swZSAXcomDVmadSDDV5zAA.ttf',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
'dm-sans': {
|
|
111
|
+
displayName: 'DM Sans',
|
|
112
|
+
faces: {
|
|
113
|
+
400: 'https://fonts.gstatic.com/s/dmsans/v17/rP2tp2ywxg089UriI5-g4vlH9VoD8CmcqZG40F9JadbnoEwAopxhTg.ttf',
|
|
114
|
+
500: 'https://fonts.gstatic.com/s/dmsans/v17/rP2tp2ywxg089UriI5-g4vlH9VoD8CmcqZG40F9JadbnoEwAkJxhTg.ttf',
|
|
115
|
+
600: 'https://fonts.gstatic.com/s/dmsans/v17/rP2tp2ywxg089UriI5-g4vlH9VoD8CmcqZG40F9JadbnoEwAfJthTg.ttf',
|
|
116
|
+
700: 'https://fonts.gstatic.com/s/dmsans/v17/rP2tp2ywxg089UriI5-g4vlH9VoD8CmcqZG40F9JadbnoEwARZthTg.ttf',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
} as const satisfies Record<string, FontFamilyEntry>;
|
|
120
|
+
|
|
121
|
+
/** Id of a font in the catalog. */
|
|
122
|
+
export type VelionCatalogFontId = keyof typeof CATALOG;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Accepted values of `VelionTheme.fontFamily`: a catalog id, or `'system'`
|
|
126
|
+
* (the platform font, the default).
|
|
127
|
+
*/
|
|
128
|
+
export type VelionFontId = 'system' | VelionCatalogFontId;
|
|
129
|
+
|
|
130
|
+
/** Every accepted font id, `'system'` first. */
|
|
131
|
+
export const VELION_FONT_IDS: readonly VelionFontId[] = [
|
|
132
|
+
'system',
|
|
133
|
+
...(Object.keys(CATALOG) as VelionCatalogFontId[]),
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
const WEIGHT_SLOTS: readonly FontWeightSlot[] = [400, 500, 600, 700];
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Resolves the `fontFamily` theme value to a catalog id, or `null` for the
|
|
140
|
+
* system font.
|
|
141
|
+
*
|
|
142
|
+
* Tolerates the CSS-style values the web theme used to take: only the first
|
|
143
|
+
* family of a comma-separated stack counts, quotes and case are ignored, and
|
|
144
|
+
* the Google Fonts name works as well as the id (`'Open Sans'` and
|
|
145
|
+
* `'"Open Sans", sans-serif'` both give `open-sans`). Anything else gives
|
|
146
|
+
* `null`.
|
|
147
|
+
*/
|
|
148
|
+
export function resolveFontId(
|
|
149
|
+
value: string | null | undefined,
|
|
150
|
+
): VelionCatalogFontId | null {
|
|
151
|
+
if (!value) return null;
|
|
152
|
+
const first = value.split(',')[0] ?? '';
|
|
153
|
+
const normalized = first
|
|
154
|
+
.trim()
|
|
155
|
+
.replace(/^['"]|['"]$/g, '')
|
|
156
|
+
.trim()
|
|
157
|
+
.toLowerCase()
|
|
158
|
+
.replace(/[\s_]+/g, '-');
|
|
159
|
+
return Object.prototype.hasOwnProperty.call(CATALOG, normalized)
|
|
160
|
+
? (normalized as VelionCatalogFontId)
|
|
161
|
+
: null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Maps a React Native `fontWeight` to the face that renders it. Numeric
|
|
166
|
+
* weights round to the nearest slot (ties go up); `'bold'` is 700 and anything
|
|
167
|
+
* unrecognised, `'normal'` included, is 400.
|
|
168
|
+
*/
|
|
169
|
+
export function weightSlot(fontWeight: unknown): FontWeightSlot {
|
|
170
|
+
if (fontWeight === 'bold') return 700;
|
|
171
|
+
const numeric =
|
|
172
|
+
typeof fontWeight === 'number' ? fontWeight : Number(fontWeight);
|
|
173
|
+
if (!Number.isFinite(numeric)) return 400;
|
|
174
|
+
if (numeric <= 400) return 400;
|
|
175
|
+
if (numeric >= 700) return 700;
|
|
176
|
+
return numeric < 550 ? 500 : 600;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Name the face is registered under with `expo-font`. Prefixed so it cannot
|
|
181
|
+
* collide with a font the host app loads itself.
|
|
182
|
+
*/
|
|
183
|
+
export function fontFaceName(
|
|
184
|
+
fontId: VelionCatalogFontId,
|
|
185
|
+
weight: FontWeightSlot,
|
|
186
|
+
): string {
|
|
187
|
+
return `VelionFont-${fontId}-${weight}`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The `{ faceName: url }` map to hand to `expo-font`'s `loadAsync`. */
|
|
191
|
+
export function fontSources(
|
|
192
|
+
fontId: VelionCatalogFontId,
|
|
193
|
+
): Record<string, string> {
|
|
194
|
+
const entry: FontFamilyEntry = CATALOG[fontId];
|
|
195
|
+
const sources: Record<string, string> = {};
|
|
196
|
+
for (const weight of WEIGHT_SLOTS) {
|
|
197
|
+
sources[fontFaceName(fontId, weight)] = entry.faces[weight];
|
|
198
|
+
}
|
|
199
|
+
return sources;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Style that makes a text render with the loaded catalog font.
|
|
204
|
+
*
|
|
205
|
+
* Returns `undefined` when there is no font to apply, so the text keeps the
|
|
206
|
+
* system font. `fontWeight` is set to the slot of the face picked: on iOS the
|
|
207
|
+
* face is looked up by family and weight, so a mismatched weight would pick
|
|
208
|
+
* another face; on Android it stops a synthetic bold on top of a bold face.
|
|
209
|
+
*/
|
|
210
|
+
export function fontStyleFor(
|
|
211
|
+
fontId: VelionCatalogFontId | null,
|
|
212
|
+
fontWeight: unknown,
|
|
213
|
+
): { fontFamily: string; fontWeight: `${FontWeightSlot}` } | undefined {
|
|
214
|
+
if (!fontId) return undefined;
|
|
215
|
+
const weight = weightSlot(fontWeight);
|
|
216
|
+
return {
|
|
217
|
+
fontFamily: fontFaceName(fontId, weight),
|
|
218
|
+
fontWeight: String(weight) as `${FontWeightSlot}`,
|
|
219
|
+
};
|
|
220
|
+
}
|
package/src/ui/theme/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export {
|
|
2
2
|
ThemeProvider,
|
|
3
3
|
useTheme,
|
|
4
|
+
useOptionalTheme,
|
|
4
5
|
useReducedMotion,
|
|
5
6
|
type ThemeProviderProps,
|
|
6
7
|
} from './ThemeProvider';
|
|
@@ -12,6 +13,14 @@ export {
|
|
|
12
13
|
mixHex,
|
|
13
14
|
withAlpha,
|
|
14
15
|
isHexDark,
|
|
16
|
+
DEFAULT_CONTROL_HEIGHT_PX,
|
|
15
17
|
type ResolvedTheme,
|
|
16
18
|
type ThemeTokenSet,
|
|
17
19
|
} from './tokens';
|
|
20
|
+
export {
|
|
21
|
+
VELION_FONT_IDS,
|
|
22
|
+
resolveFontId,
|
|
23
|
+
fontStyleFor,
|
|
24
|
+
type VelionFontId,
|
|
25
|
+
type VelionCatalogFontId,
|
|
26
|
+
} from './fonts';
|
package/src/ui/theme/tokens.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { VelionTheme } from '../../types';
|
|
12
|
+
import type { VelionCatalogFontId } from './fonts';
|
|
12
13
|
|
|
13
14
|
/** Tonal token set. Shape matches `VelionTheme` (all required, no undefineds). */
|
|
14
15
|
export type ThemeTokenSet = Required<VelionTheme>;
|
|
@@ -23,8 +24,21 @@ export interface ResolvedTheme extends ThemeTokenSet {
|
|
|
23
24
|
effectiveMode: 'light' | 'dark';
|
|
24
25
|
/** The numeric pixel value parsed from `borderRadius` (the SDK-wide default). */
|
|
25
26
|
borderRadiusPx: number;
|
|
27
|
+
/** Minimum height of inputs and selects, parsed from `inputHeight`. */
|
|
28
|
+
inputHeightPx: number;
|
|
29
|
+
/** Minimum height of buttons, parsed from `buttonHeight`. */
|
|
30
|
+
buttonHeightPx: number;
|
|
31
|
+
/**
|
|
32
|
+
* Catalog font every text renders with, or `null` for the system font.
|
|
33
|
+
* Set only once the font files are loaded, so a text never names a face the
|
|
34
|
+
* platform does not have yet.
|
|
35
|
+
*/
|
|
36
|
+
fontId: VelionCatalogFontId | null;
|
|
26
37
|
}
|
|
27
38
|
|
|
39
|
+
/** Default for `inputHeight` and `buttonHeight`: the 44 px tap target. */
|
|
40
|
+
export const DEFAULT_CONTROL_HEIGHT_PX = 44;
|
|
41
|
+
|
|
28
42
|
export const LIGHT_TOKENS: ThemeTokenSet = {
|
|
29
43
|
primaryColor: '#2563EB',
|
|
30
44
|
secondaryColor: '#1D4ED8',
|
|
@@ -32,7 +46,7 @@ export const LIGHT_TOKENS: ThemeTokenSet = {
|
|
|
32
46
|
textColor: '#111827',
|
|
33
47
|
textSecondaryColor: '#6B7280',
|
|
34
48
|
borderRadius: '8px',
|
|
35
|
-
fontFamily: '
|
|
49
|
+
fontFamily: 'system',
|
|
36
50
|
errorColor: '#DC2626',
|
|
37
51
|
successColor: '#16A34A',
|
|
38
52
|
warningColor: '#D97706',
|
|
@@ -40,6 +54,8 @@ export const LIGHT_TOKENS: ThemeTokenSet = {
|
|
|
40
54
|
cardShadow: '0 4px 6px -1px rgba(0,0,0,0.10), 0 2px 4px -2px rgba(0,0,0,0.10)',
|
|
41
55
|
hideStepIcons: false,
|
|
42
56
|
hideProgressBar: false,
|
|
57
|
+
inputHeight: '44px',
|
|
58
|
+
buttonHeight: '44px',
|
|
43
59
|
};
|
|
44
60
|
|
|
45
61
|
export const DARK_TOKENS: ThemeTokenSet = {
|
|
@@ -49,7 +65,7 @@ export const DARK_TOKENS: ThemeTokenSet = {
|
|
|
49
65
|
textColor: '#F1F5F9',
|
|
50
66
|
textSecondaryColor: '#94A3B8',
|
|
51
67
|
borderRadius: '8px',
|
|
52
|
-
fontFamily: '
|
|
68
|
+
fontFamily: 'system',
|
|
53
69
|
errorColor: '#F87171',
|
|
54
70
|
successColor: '#34D399',
|
|
55
71
|
warningColor: '#FBBF24',
|
|
@@ -57,6 +73,8 @@ export const DARK_TOKENS: ThemeTokenSet = {
|
|
|
57
73
|
cardShadow: '0 8px 18px -4px rgba(0,0,0,0.55), 0 4px 8px -4px rgba(0,0,0,0.40)',
|
|
58
74
|
hideStepIcons: false,
|
|
59
75
|
hideProgressBar: false,
|
|
76
|
+
inputHeight: '44px',
|
|
77
|
+
buttonHeight: '44px',
|
|
60
78
|
};
|
|
61
79
|
|
|
62
80
|
export function getDefaultThemeTokens(
|
|
@@ -65,10 +83,16 @@ export function getDefaultThemeTokens(
|
|
|
65
83
|
return colorMode === 'dark' ? { ...DARK_TOKENS } : { ...LIGHT_TOKENS };
|
|
66
84
|
}
|
|
67
85
|
|
|
68
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Layers consumer overrides on top of the base tokens for the requested mode.
|
|
88
|
+
*
|
|
89
|
+
* `loadedFontId` is the catalog font whose files are already loaded (see
|
|
90
|
+
* `ThemeProvider`); until then texts keep the system font.
|
|
91
|
+
*/
|
|
69
92
|
export function resolveTheme(
|
|
70
93
|
theme: VelionTheme | undefined,
|
|
71
94
|
colorMode: 'light' | 'dark',
|
|
95
|
+
loadedFontId: VelionCatalogFontId | null = null,
|
|
72
96
|
): ResolvedTheme {
|
|
73
97
|
const base = colorMode === 'dark' ? DARK_TOKENS : LIGHT_TOKENS;
|
|
74
98
|
const merged: ThemeTokenSet = { ...base, ...theme };
|
|
@@ -79,7 +103,16 @@ export function resolveTheme(
|
|
|
79
103
|
? 'dark'
|
|
80
104
|
: 'light';
|
|
81
105
|
const borderRadiusPx = parsePx(merged.borderRadius, 8);
|
|
82
|
-
|
|
106
|
+
const inputHeightPx = parsePx(merged.inputHeight, DEFAULT_CONTROL_HEIGHT_PX);
|
|
107
|
+
const buttonHeightPx = parsePx(merged.buttonHeight, DEFAULT_CONTROL_HEIGHT_PX);
|
|
108
|
+
return {
|
|
109
|
+
...merged,
|
|
110
|
+
effectiveMode,
|
|
111
|
+
borderRadiusPx,
|
|
112
|
+
inputHeightPx,
|
|
113
|
+
buttonHeightPx,
|
|
114
|
+
fontId: loadedFontId,
|
|
115
|
+
};
|
|
83
116
|
}
|
|
84
117
|
|
|
85
118
|
/** WCAG relative-luminance check. Returns false on unparsable input. */
|
|
@@ -149,8 +182,13 @@ function clamp(n: number, min: number, max: number): number {
|
|
|
149
182
|
return n;
|
|
150
183
|
}
|
|
151
184
|
|
|
152
|
-
|
|
153
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Parses a `'12px'` theme length. A bare number (`'12'`) is read as pixels;
|
|
187
|
+
* anything else — other units, garbage, a missing value — gives `fallback`.
|
|
188
|
+
*/
|
|
189
|
+
export function parsePx(value: string | undefined, fallback: number): number {
|
|
190
|
+
if (typeof value !== 'string') return fallback;
|
|
191
|
+
const m = value.trim().match(/^(\d+(?:\.\d+)?)\s*(?:px)?$/i);
|
|
154
192
|
if (m && m[1]) {
|
|
155
193
|
const parsed = Number(m[1]);
|
|
156
194
|
if (Number.isFinite(parsed)) return parsed;
|