@rocapine/react-native-onboarding 1.44.1 → 1.44.2
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/dist/infra/fonts/FontRegistryContext.d.ts +8 -7
- package/dist/infra/fonts/FontRegistryContext.d.ts.map +1 -1
- package/dist/infra/fonts/FontRegistryContext.js +10 -9
- package/dist/infra/fonts/FontRegistryContext.js.map +1 -1
- package/dist/infra/fonts/index.d.ts +1 -1
- package/dist/infra/fonts/index.d.ts.map +1 -1
- package/dist/infra/fonts/index.js +3 -1
- package/dist/infra/fonts/index.js.map +1 -1
- package/dist/infra/fonts/registry.d.ts +6 -2
- package/dist/infra/fonts/registry.d.ts.map +1 -1
- package/dist/infra/fonts/registry.js +63 -17
- package/dist/infra/fonts/registry.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/resolveFontFamily.test.ts +89 -0
- package/src/infra/fonts/FontRegistryContext.tsx +16 -10
- package/src/infra/fonts/index.ts +4 -0
- package/src/infra/fonts/registry.ts +74 -17
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { FontRegistry } from "./registry";
|
|
1
|
+
import type { FontRegistry, FontStyleKey } from "./registry";
|
|
2
2
|
export declare const FontRegistryProvider: import("react").Provider<FontRegistry>;
|
|
3
3
|
export declare const useFontRegistry: () => FontRegistry;
|
|
4
|
-
export declare const useResolvedFontFamily: (family: string | null | undefined, weight: string | number | null | undefined) => string | undefined;
|
|
4
|
+
export declare const useResolvedFontFamily: (family: string | null | undefined, weight: string | number | null | undefined, fontStyle?: FontStyleKey | string | null) => string | undefined;
|
|
5
5
|
/**
|
|
6
|
-
* Resolves a `family + weight` request to a registered font name.
|
|
7
|
-
* `resolvedToVariant: true` when the registry matched a concrete
|
|
8
|
-
* variant — callers should then suppress `fontWeight` on the rendered
|
|
9
|
-
* avoid synthetic emboldening on top of an already-weighted font file.
|
|
6
|
+
* Resolves a `family + weight + style` request to a registered font name.
|
|
7
|
+
* Returns `resolvedToVariant: true` when the registry matched a concrete
|
|
8
|
+
* weighted variant — callers should then suppress `fontWeight` on the rendered
|
|
9
|
+
* Text to avoid synthetic emboldening on top of an already-weighted font file.
|
|
10
|
+
* Pass `fontStyle: "italic"` to select the italic face when one is registered.
|
|
10
11
|
*/
|
|
11
|
-
export declare const useResolvedFontStyle: (family: string | null | undefined, weight: string | number | null | undefined) => {
|
|
12
|
+
export declare const useResolvedFontStyle: (family: string | null | undefined, weight: string | number | null | undefined, fontStyle?: FontStyleKey | string | null) => {
|
|
12
13
|
fontFamily: string | undefined;
|
|
13
14
|
fontWeight: string | number | undefined;
|
|
14
15
|
resolvedToVariant: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontRegistryContext.d.ts","sourceRoot":"","sources":["../../../src/infra/fonts/FontRegistryContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"FontRegistryContext.d.ts","sourceRoot":"","sources":["../../../src/infra/fonts/FontRegistryContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK7D,eAAO,MAAM,oBAAoB,wCAA+B,CAAC;AAEjE,eAAO,MAAM,eAAe,QAAO,YAA+C,CAAC;AAEnF,eAAO,MAAM,qBAAqB,GAChC,QAAQ,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAC1C,YAAY,YAAY,GAAG,MAAM,GAAG,IAAI,KACvC,MAAM,GAAG,SAMX,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAC1C,YAAY,YAAY,GAAG,MAAM,GAAG,IAAI,KACvC;IACD,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACxC,iBAAiB,EAAE,OAAO,CAAC;CAc5B,CAAC"}
|
|
@@ -7,21 +7,22 @@ const FontRegistryContext = (0, react_1.createContext)({});
|
|
|
7
7
|
exports.FontRegistryProvider = FontRegistryContext.Provider;
|
|
8
8
|
const useFontRegistry = () => (0, react_1.useContext)(FontRegistryContext);
|
|
9
9
|
exports.useFontRegistry = useFontRegistry;
|
|
10
|
-
const useResolvedFontFamily = (family, weight) => {
|
|
10
|
+
const useResolvedFontFamily = (family, weight, fontStyle) => {
|
|
11
11
|
const registry = (0, exports.useFontRegistry)();
|
|
12
|
-
return (0, react_1.useMemo)(() => (0, registry_1.resolveFontFamily)(registry, family, weight), [registry, family, weight]);
|
|
12
|
+
return (0, react_1.useMemo)(() => (0, registry_1.resolveFontFamily)(registry, family, weight, fontStyle), [registry, family, weight, fontStyle]);
|
|
13
13
|
};
|
|
14
14
|
exports.useResolvedFontFamily = useResolvedFontFamily;
|
|
15
15
|
/**
|
|
16
|
-
* Resolves a `family + weight` request to a registered font name.
|
|
17
|
-
* `resolvedToVariant: true` when the registry matched a concrete
|
|
18
|
-
* variant — callers should then suppress `fontWeight` on the rendered
|
|
19
|
-
* avoid synthetic emboldening on top of an already-weighted font file.
|
|
16
|
+
* Resolves a `family + weight + style` request to a registered font name.
|
|
17
|
+
* Returns `resolvedToVariant: true` when the registry matched a concrete
|
|
18
|
+
* weighted variant — callers should then suppress `fontWeight` on the rendered
|
|
19
|
+
* Text to avoid synthetic emboldening on top of an already-weighted font file.
|
|
20
|
+
* Pass `fontStyle: "italic"` to select the italic face when one is registered.
|
|
20
21
|
*/
|
|
21
|
-
const useResolvedFontStyle = (family, weight) => {
|
|
22
|
+
const useResolvedFontStyle = (family, weight, fontStyle) => {
|
|
22
23
|
const registry = (0, exports.useFontRegistry)();
|
|
23
24
|
return (0, react_1.useMemo)(() => {
|
|
24
|
-
const fontFamily = (0, registry_1.resolveFontFamily)(registry, family, weight);
|
|
25
|
+
const fontFamily = (0, registry_1.resolveFontFamily)(registry, family, weight, fontStyle);
|
|
25
26
|
const variants = family ? registry === null || registry === void 0 ? void 0 : registry[family] : undefined;
|
|
26
27
|
const resolvedToVariant = !!variants && fontFamily !== undefined && fontFamily !== family;
|
|
27
28
|
return {
|
|
@@ -29,7 +30,7 @@ const useResolvedFontStyle = (family, weight) => {
|
|
|
29
30
|
fontWeight: resolvedToVariant ? undefined : (weight !== null && weight !== void 0 ? weight : undefined),
|
|
30
31
|
resolvedToVariant,
|
|
31
32
|
};
|
|
32
|
-
}, [registry, family, weight]);
|
|
33
|
+
}, [registry, family, weight, fontStyle]);
|
|
33
34
|
};
|
|
34
35
|
exports.useResolvedFontStyle = useResolvedFontStyle;
|
|
35
36
|
//# sourceMappingURL=FontRegistryContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontRegistryContext.js","sourceRoot":"","sources":["../../../src/infra/fonts/FontRegistryContext.tsx"],"names":[],"mappings":";;;AAAA,iCAA2D;AAE3D,yCAA+C;AAE/C,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAAe,EAAE,CAAC,CAAC;AAE/C,QAAA,oBAAoB,GAAG,mBAAmB,CAAC,QAAQ,CAAC;AAE1D,MAAM,eAAe,GAAG,GAAiB,EAAE,CAAC,IAAA,kBAAU,EAAC,mBAAmB,CAAC,CAAC;AAAtE,QAAA,eAAe,mBAAuD;AAE5E,MAAM,qBAAqB,GAAG,CACnC,MAAiC,EACjC,MAA0C,
|
|
1
|
+
{"version":3,"file":"FontRegistryContext.js","sourceRoot":"","sources":["../../../src/infra/fonts/FontRegistryContext.tsx"],"names":[],"mappings":";;;AAAA,iCAA2D;AAE3D,yCAA+C;AAE/C,MAAM,mBAAmB,GAAG,IAAA,qBAAa,EAAe,EAAE,CAAC,CAAC;AAE/C,QAAA,oBAAoB,GAAG,mB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EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAC5C,CAAC,CAAC;AArBW,QAAA,oBAAoB,wBAqB/B"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { registerFonts, resolveFontFamily, normalizeWeight, type FontRegistry, } from "./registry";
|
|
1
|
+
export { registerFonts, resolveFontFamily, normalizeWeight, normalizeStyle, isSystemFontFamily, type FontRegistry, type RegisteredFace, type FontStyleKey, } from "./registry";
|
|
2
2
|
export { FontRegistryProvider, useFontRegistry, useResolvedFontFamily, useResolvedFontStyle, } from "./FontRegistryContext";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infra/fonts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infra/fonts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useResolvedFontStyle = exports.useResolvedFontFamily = exports.useFontRegistry = exports.FontRegistryProvider = exports.normalizeWeight = exports.resolveFontFamily = exports.registerFonts = void 0;
|
|
3
|
+
exports.useResolvedFontStyle = exports.useResolvedFontFamily = exports.useFontRegistry = exports.FontRegistryProvider = exports.isSystemFontFamily = exports.normalizeStyle = exports.normalizeWeight = exports.resolveFontFamily = exports.registerFonts = void 0;
|
|
4
4
|
var registry_1 = require("./registry");
|
|
5
5
|
Object.defineProperty(exports, "registerFonts", { enumerable: true, get: function () { return registry_1.registerFonts; } });
|
|
6
6
|
Object.defineProperty(exports, "resolveFontFamily", { enumerable: true, get: function () { return registry_1.resolveFontFamily; } });
|
|
7
7
|
Object.defineProperty(exports, "normalizeWeight", { enumerable: true, get: function () { return registry_1.normalizeWeight; } });
|
|
8
|
+
Object.defineProperty(exports, "normalizeStyle", { enumerable: true, get: function () { return registry_1.normalizeStyle; } });
|
|
9
|
+
Object.defineProperty(exports, "isSystemFontFamily", { enumerable: true, get: function () { return registry_1.isSystemFontFamily; } });
|
|
8
10
|
var FontRegistryContext_1 = require("./FontRegistryContext");
|
|
9
11
|
Object.defineProperty(exports, "FontRegistryProvider", { enumerable: true, get: function () { return FontRegistryContext_1.FontRegistryProvider; } });
|
|
10
12
|
Object.defineProperty(exports, "useFontRegistry", { enumerable: true, get: function () { return FontRegistryContext_1.useFontRegistry; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/infra/fonts/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/infra/fonts/index.ts"],"names":[],"mappings":";;;AAAA,uCASoB;AARlB,yGAAA,aAAa,OAAA;AACb,6GAAA,iBAAiB,OAAA;AACjB,2GAAA,eAAe,OAAA;AACf,0GAAA,cAAc,OAAA;AACd,8GAAA,kBAAkB,OAAA;AAKpB,6DAK+B;AAJ7B,2HAAA,oBAAoB,OAAA;AACpB,sHAAA,eAAe,OAAA;AACf,4HAAA,qBAAqB,OAAA;AACrB,2HAAA,oBAAoB,OAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { FontsManifest, FontWeightKey } from "../../types";
|
|
2
|
-
export type
|
|
2
|
+
export type FontStyleKey = "normal" | "italic";
|
|
3
|
+
export type RegisteredFace = Partial<Record<FontStyleKey, string>>;
|
|
4
|
+
export type FontRegistry = Record<string, Record<number, RegisteredFace>>;
|
|
3
5
|
export declare const normalizeWeight: (key: FontWeightKey | string | number | undefined) => number;
|
|
6
|
+
export declare const normalizeStyle: (style: string | undefined | null) => FontStyleKey;
|
|
7
|
+
export declare const isSystemFontFamily: (family: string | null | undefined) => boolean;
|
|
4
8
|
export declare const registerFonts: (manifest: FontsManifest | undefined) => Promise<FontRegistry>;
|
|
5
|
-
export declare const resolveFontFamily: (registry: FontRegistry | null | undefined, family: string | null | undefined, weight: string | number | null | undefined) => string | undefined;
|
|
9
|
+
export declare const resolveFontFamily: (registry: FontRegistry | null | undefined, family: string | null | undefined, weight: string | number | null | undefined, fontStyle?: FontStyleKey | string | null) => string | undefined;
|
|
6
10
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/infra/fonts/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/infra/fonts/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,aAAa,EAEb,aAAa,EACd,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAG/C,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAGnE,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;AAU1E,eAAO,MAAM,eAAe,GAAI,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,KAAG,MAOlF,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,YACxB,CAAC;AAwB3C,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OAGtE,CAAC;AAoDF,eAAO,MAAM,aAAa,GAAU,UAAU,aAAa,GAAG,SAAS,KAAG,OAAO,CAAC,YAAY,CAyC7F,CAAC;AASF,eAAO,MAAM,iBAAiB,GAC5B,UAAU,YAAY,GAAG,IAAI,GAAG,SAAS,EACzC,QAAQ,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAC1C,YAAY,YAAY,GAAG,MAAM,GAAG,IAAI,KACvC,MAAM,GAAG,SA8BX,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveFontFamily = exports.registerFonts = exports.normalizeWeight = void 0;
|
|
3
|
+
exports.resolveFontFamily = exports.registerFonts = exports.isSystemFontFamily = exports.normalizeStyle = exports.normalizeWeight = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
4
5
|
const WEIGHT_NAME_TO_NUM = {
|
|
5
6
|
regular: 400,
|
|
6
7
|
medium: 500,
|
|
@@ -20,6 +21,33 @@ const normalizeWeight = (key) => {
|
|
|
20
21
|
return Number.isFinite(parsed) ? parsed : 400;
|
|
21
22
|
};
|
|
22
23
|
exports.normalizeWeight = normalizeWeight;
|
|
24
|
+
const normalizeStyle = (style) => style === "italic" ? "italic" : "normal";
|
|
25
|
+
exports.normalizeStyle = normalizeStyle;
|
|
26
|
+
// Font families whose internal name collides with the iOS system font (SF Pro).
|
|
27
|
+
// Registering custom faces under one of these names makes iOS give the system
|
|
28
|
+
// font precedence, so only Regular resolves — every other weight renders tofu.
|
|
29
|
+
// On iOS we skip registering them and resolve to `fontFamily: undefined` so RN
|
|
30
|
+
// uses the real system font (which *is* SF Pro) honoring `fontWeight`. On
|
|
31
|
+
// Android (no SF Pro system font) the bundled faces register normally.
|
|
32
|
+
const SYSTEM_FONT_FAMILIES = new Set([
|
|
33
|
+
"system",
|
|
34
|
+
"sfpro",
|
|
35
|
+
"sfprodisplay",
|
|
36
|
+
"sfprotext",
|
|
37
|
+
"sfprorounded",
|
|
38
|
+
"sfuidisplay",
|
|
39
|
+
"sfuitext",
|
|
40
|
+
]);
|
|
41
|
+
const normalizeFamilyKey = (family) => family.toLowerCase().replace(/[\s_.-]+/g, "");
|
|
42
|
+
// True when `family` names a platform system font that must NOT be registered as
|
|
43
|
+
// a bundled face on iOS (see SYSTEM_FONT_FAMILIES). Always false on other
|
|
44
|
+
// platforms — only iOS has the SF Pro collision.
|
|
45
|
+
const isSystemFontFamily = (family) => {
|
|
46
|
+
if (!family || react_native_1.Platform.OS !== "ios")
|
|
47
|
+
return false;
|
|
48
|
+
return SYSTEM_FONT_FAMILIES.has(normalizeFamilyKey(family));
|
|
49
|
+
};
|
|
50
|
+
exports.isSystemFontFamily = isSystemFontFamily;
|
|
23
51
|
// The registered (PostScript) name is the font file's base name, without
|
|
24
52
|
// directory, query string, or extension — e.g. ".../Inter-SemiBold.ttf?v=2"
|
|
25
53
|
// registers as "Inter-SemiBold".
|
|
@@ -46,29 +74,28 @@ const normalizeFamilyVariants = (input) => {
|
|
|
46
74
|
if (!input)
|
|
47
75
|
return [];
|
|
48
76
|
if (Array.isArray(input)) {
|
|
49
|
-
|
|
77
|
+
// Key by weight+style so an italic face is never overwritten by the upright
|
|
78
|
+
// face at the same weight (and vice-versa). Last entry wins on exact dup.
|
|
79
|
+
const byKey = new Map();
|
|
50
80
|
for (const entry of input) {
|
|
51
81
|
if (!entry || typeof entry.url !== "string" || !entry.url)
|
|
52
82
|
continue;
|
|
53
83
|
const weight = (0, exports.normalizeWeight)(entry.weight);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
if (!existing || isNormalStyle) {
|
|
57
|
-
byWeight.set(weight, { weight, url: entry.url });
|
|
58
|
-
}
|
|
84
|
+
const style = (0, exports.normalizeStyle)(entry.style);
|
|
85
|
+
byKey.set(`${weight}-${style}`, { weight, style, url: entry.url });
|
|
59
86
|
}
|
|
60
|
-
return Array.from(
|
|
87
|
+
return Array.from(byKey.values());
|
|
61
88
|
}
|
|
62
89
|
const out = [];
|
|
63
90
|
for (const [weightKey, url] of Object.entries(input)) {
|
|
64
91
|
if (typeof url !== "string" || !url)
|
|
65
92
|
continue;
|
|
66
|
-
out.push({ weight: (0, exports.normalizeWeight)(weightKey), url });
|
|
93
|
+
out.push({ weight: (0, exports.normalizeWeight)(weightKey), style: "normal", url });
|
|
67
94
|
}
|
|
68
95
|
return out;
|
|
69
96
|
};
|
|
70
97
|
const registerFonts = async (manifest) => {
|
|
71
|
-
var _a;
|
|
98
|
+
var _a, _b;
|
|
72
99
|
const registry = {};
|
|
73
100
|
if (!manifest || Object.keys(manifest).length === 0)
|
|
74
101
|
return registry;
|
|
@@ -77,16 +104,27 @@ const registerFonts = async (manifest) => {
|
|
|
77
104
|
return registry;
|
|
78
105
|
const loads = [];
|
|
79
106
|
for (const [family, variantsInput] of Object.entries(manifest)) {
|
|
107
|
+
// Don't register a system-font family's bundled faces on iOS — resolution
|
|
108
|
+
// returns `fontFamily: undefined` for it so the real system font is used.
|
|
109
|
+
if ((0, exports.isSystemFontFamily)(family))
|
|
110
|
+
continue;
|
|
80
111
|
const variants = normalizeFamilyVariants(variantsInput);
|
|
81
112
|
if (variants.length === 0)
|
|
82
113
|
continue;
|
|
83
114
|
registry[family] = (_a = registry[family]) !== null && _a !== void 0 ? _a : {};
|
|
84
|
-
for (const { weight, url } of variants) {
|
|
115
|
+
for (const { weight, style, url } of variants) {
|
|
85
116
|
const registeredName = buildRegisteredName(url);
|
|
86
|
-
registry[family][weight] =
|
|
117
|
+
const bucket = (registry[family][weight] = (_b = registry[family][weight]) !== null && _b !== void 0 ? _b : {});
|
|
118
|
+
bucket[style] = registeredName;
|
|
87
119
|
loads.push(Font.loadAsync({ [registeredName]: { uri: url } }).catch((error) => {
|
|
88
|
-
|
|
89
|
-
|
|
120
|
+
var _a;
|
|
121
|
+
console.warn(`[onboarding] Failed to load font "${family}" weight ${weight} (${style}) from ${url}:`, error);
|
|
122
|
+
const b = (_a = registry[family]) === null || _a === void 0 ? void 0 : _a[weight];
|
|
123
|
+
if (b) {
|
|
124
|
+
delete b[style];
|
|
125
|
+
if (Object.keys(b).length === 0)
|
|
126
|
+
delete registry[family][weight];
|
|
127
|
+
}
|
|
90
128
|
}));
|
|
91
129
|
}
|
|
92
130
|
}
|
|
@@ -94,16 +132,24 @@ const registerFonts = async (manifest) => {
|
|
|
94
132
|
return registry;
|
|
95
133
|
};
|
|
96
134
|
exports.registerFonts = registerFonts;
|
|
97
|
-
|
|
135
|
+
// Picks the requested style from a weight bucket, falling back to the other
|
|
136
|
+
// style when the requested one isn't available at that weight.
|
|
137
|
+
const pickFace = (face, style) => { var _a, _b; return (face ? ((_b = (_a = face[style]) !== null && _a !== void 0 ? _a : face.normal) !== null && _b !== void 0 ? _b : face.italic) : undefined); };
|
|
138
|
+
const resolveFontFamily = (registry, family, weight, fontStyle) => {
|
|
139
|
+
var _a;
|
|
98
140
|
if (!family)
|
|
99
141
|
return undefined;
|
|
142
|
+
// System font on iOS: let RN resolve the real system font from fontWeight.
|
|
143
|
+
if ((0, exports.isSystemFontFamily)(family))
|
|
144
|
+
return undefined;
|
|
100
145
|
if (!registry)
|
|
101
146
|
return family;
|
|
102
147
|
const variants = registry[family];
|
|
103
148
|
if (!variants)
|
|
104
149
|
return family;
|
|
150
|
+
const style = (0, exports.normalizeStyle)(fontStyle);
|
|
105
151
|
const requested = (0, exports.normalizeWeight)(weight);
|
|
106
|
-
const exact = variants[requested];
|
|
152
|
+
const exact = pickFace(variants[requested], style);
|
|
107
153
|
if (exact)
|
|
108
154
|
return exact;
|
|
109
155
|
const available = Object.keys(variants)
|
|
@@ -121,7 +167,7 @@ const resolveFontFamily = (registry, family, weight) => {
|
|
|
121
167
|
bestDelta = delta;
|
|
122
168
|
}
|
|
123
169
|
}
|
|
124
|
-
return variants[best];
|
|
170
|
+
return (_a = pickFace(variants[best], style)) !== null && _a !== void 0 ? _a : family;
|
|
125
171
|
};
|
|
126
172
|
exports.resolveFontFamily = resolveFontFamily;
|
|
127
173
|
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/infra/fonts/registry.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/infra/fonts/registry.ts"],"names":[],"mappings":";;;AAAA,+CAAwC;AAiBxC,MAAM,kBAAkB,GAA2B;IACjD,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,GAAG;IACX,QAAQ,EAAE,GAAG;IACb,IAAI,EAAE,GAAG;IACT,SAAS,EAAE,GAAG;CACf,CAAC;AAEK,MAAM,eAAe,GAAG,CAAC,GAAgD,EAAU,EAAE;IAC1F,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;IAClD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,MAAM,KAAK,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACxB,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;AAChD,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B;AAEK,MAAM,cAAc,GAAG,CAAC,KAAgC,EAAgB,EAAE,CAC/E,KA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IACH,CAAC;IACD,OAAO,MAAA,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,mCAAI,MAAM,CAAC;AACnD,CAAC,CAAC;AAnCW,QAAA,iBAAiB,qBAmC5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocapine/react-native-onboarding",
|
|
3
|
-
"version": "1.44.
|
|
3
|
+
"version": "1.44.2",
|
|
4
4
|
"description": "Headless React Native SDK for Rocapine Onboarding Studio - Data fetching, state management, and hooks",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
// Mutable Platform mock — isSystemFontFamily reads Platform.OS at call time.
|
|
4
|
+
const { Platform } = vi.hoisted(() => ({
|
|
5
|
+
Platform: { OS: "android" as "ios" | "android" },
|
|
6
|
+
}));
|
|
7
|
+
vi.mock("react-native", () => ({ Platform }));
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
resolveFontFamily,
|
|
11
|
+
isSystemFontFamily,
|
|
12
|
+
type FontRegistry,
|
|
13
|
+
} from "../infra/fonts/registry";
|
|
14
|
+
|
|
15
|
+
describe("resolveFontFamily", () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
Platform.OS = "android";
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Playfair Display: bold has both upright + italic faces at weight 700.
|
|
21
|
+
const registry: FontRegistry = {
|
|
22
|
+
"playfair-display": {
|
|
23
|
+
400: { normal: "PlayfairDisplay-Regular", italic: "PlayfairDisplay-Italic" },
|
|
24
|
+
700: { normal: "PlayfairDisplay-Bold", italic: "PlayfairDisplay-BoldItalic" },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
it("selects the italic face when fontStyle: italic is requested", () => {
|
|
29
|
+
expect(resolveFontFamily(registry, "playfair-display", 700, "italic")).toBe(
|
|
30
|
+
"PlayfairDisplay-BoldItalic"
|
|
31
|
+
);
|
|
32
|
+
expect(resolveFontFamily(registry, "playfair-display", 700, "normal")).toBe(
|
|
33
|
+
"PlayfairDisplay-Bold"
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("defaults to the upright face when no style is given", () => {
|
|
38
|
+
expect(resolveFontFamily(registry, "playfair-display", 700)).toBe(
|
|
39
|
+
"PlayfairDisplay-Bold"
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("falls back to the other style when the requested one is absent at that weight", () => {
|
|
44
|
+
const onlyNormal: FontRegistry = {
|
|
45
|
+
fam: { 700: { normal: "Fam-Bold" } },
|
|
46
|
+
};
|
|
47
|
+
expect(resolveFontFamily(onlyNormal, "fam", 700, "italic")).toBe("Fam-Bold");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("matches the nearest weight when exact weight is missing", () => {
|
|
51
|
+
expect(resolveFontFamily(registry, "playfair-display", 600, "italic")).toBe(
|
|
52
|
+
"PlayfairDisplay-BoldItalic"
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("returns the raw family name for an unregistered family", () => {
|
|
57
|
+
expect(resolveFontFamily(registry, "unknown", 400)).toBe("unknown");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("system font collision (iOS)", () => {
|
|
62
|
+
beforeEach(() => {
|
|
63
|
+
Platform.OS = "android";
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("treats SF Pro family names as system fonts only on iOS", () => {
|
|
67
|
+
Platform.OS = "ios";
|
|
68
|
+
expect(isSystemFontFamily("sf-pro-display")).toBe(true);
|
|
69
|
+
expect(isSystemFontFamily("SF Pro Display")).toBe(true);
|
|
70
|
+
expect(isSystemFontFamily("system")).toBe(true);
|
|
71
|
+
expect(isSystemFontFamily("playfair-display")).toBe(false);
|
|
72
|
+
|
|
73
|
+
Platform.OS = "android";
|
|
74
|
+
expect(isSystemFontFamily("sf-pro-display")).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("resolves a system family to undefined on iOS (use the real system font)", () => {
|
|
78
|
+
const registry: FontRegistry = {
|
|
79
|
+
"sf-pro-display": { 500: { normal: "SFProDisplay-Medium" } },
|
|
80
|
+
};
|
|
81
|
+
Platform.OS = "ios";
|
|
82
|
+
expect(resolveFontFamily(registry, "sf-pro-display", 500)).toBeUndefined();
|
|
83
|
+
|
|
84
|
+
Platform.OS = "android";
|
|
85
|
+
expect(resolveFontFamily(registry, "sf-pro-display", 500)).toBe(
|
|
86
|
+
"SFProDisplay-Medium"
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useContext, useMemo } from "react";
|
|
2
|
-
import type { FontRegistry } from "./registry";
|
|
2
|
+
import type { FontRegistry, FontStyleKey } from "./registry";
|
|
3
3
|
import { resolveFontFamily } from "./registry";
|
|
4
4
|
|
|
5
5
|
const FontRegistryContext = createContext<FontRegistry>({});
|
|
@@ -10,21 +10,27 @@ export const useFontRegistry = (): FontRegistry => useContext(FontRegistryContex
|
|
|
10
10
|
|
|
11
11
|
export const useResolvedFontFamily = (
|
|
12
12
|
family: string | null | undefined,
|
|
13
|
-
weight: string | number | null | undefined
|
|
13
|
+
weight: string | number | null | undefined,
|
|
14
|
+
fontStyle?: FontStyleKey | string | null
|
|
14
15
|
): string | undefined => {
|
|
15
16
|
const registry = useFontRegistry();
|
|
16
|
-
return useMemo(
|
|
17
|
+
return useMemo(
|
|
18
|
+
() => resolveFontFamily(registry, family, weight, fontStyle),
|
|
19
|
+
[registry, family, weight, fontStyle]
|
|
20
|
+
);
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
|
-
* Resolves a `family + weight` request to a registered font name.
|
|
21
|
-
* `resolvedToVariant: true` when the registry matched a concrete
|
|
22
|
-
* variant — callers should then suppress `fontWeight` on the rendered
|
|
23
|
-
* avoid synthetic emboldening on top of an already-weighted font file.
|
|
24
|
+
* Resolves a `family + weight + style` request to a registered font name.
|
|
25
|
+
* Returns `resolvedToVariant: true` when the registry matched a concrete
|
|
26
|
+
* weighted variant — callers should then suppress `fontWeight` on the rendered
|
|
27
|
+
* Text to avoid synthetic emboldening on top of an already-weighted font file.
|
|
28
|
+
* Pass `fontStyle: "italic"` to select the italic face when one is registered.
|
|
24
29
|
*/
|
|
25
30
|
export const useResolvedFontStyle = (
|
|
26
31
|
family: string | null | undefined,
|
|
27
|
-
weight: string | number | null | undefined
|
|
32
|
+
weight: string | number | null | undefined,
|
|
33
|
+
fontStyle?: FontStyleKey | string | null
|
|
28
34
|
): {
|
|
29
35
|
fontFamily: string | undefined;
|
|
30
36
|
fontWeight: string | number | undefined;
|
|
@@ -32,7 +38,7 @@ export const useResolvedFontStyle = (
|
|
|
32
38
|
} => {
|
|
33
39
|
const registry = useFontRegistry();
|
|
34
40
|
return useMemo(() => {
|
|
35
|
-
const fontFamily = resolveFontFamily(registry, family, weight);
|
|
41
|
+
const fontFamily = resolveFontFamily(registry, family, weight, fontStyle);
|
|
36
42
|
const variants = family ? registry?.[family] : undefined;
|
|
37
43
|
const resolvedToVariant =
|
|
38
44
|
!!variants && fontFamily !== undefined && fontFamily !== family;
|
|
@@ -41,5 +47,5 @@ export const useResolvedFontStyle = (
|
|
|
41
47
|
fontWeight: resolvedToVariant ? undefined : (weight ?? undefined),
|
|
42
48
|
resolvedToVariant,
|
|
43
49
|
};
|
|
44
|
-
}, [registry, family, weight]);
|
|
50
|
+
}, [registry, family, weight, fontStyle]);
|
|
45
51
|
};
|
package/src/infra/fonts/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
1
2
|
import type {
|
|
2
3
|
FontFamilyManifest,
|
|
3
4
|
FontFamilyManifestInput,
|
|
@@ -6,7 +7,13 @@ import type {
|
|
|
6
7
|
FontWeightKey,
|
|
7
8
|
} from "../../types";
|
|
8
9
|
|
|
9
|
-
export type
|
|
10
|
+
export type FontStyleKey = "normal" | "italic";
|
|
11
|
+
|
|
12
|
+
// One weight bucket can hold both an upright and an italic face.
|
|
13
|
+
export type RegisteredFace = Partial<Record<FontStyleKey, string>>;
|
|
14
|
+
|
|
15
|
+
// family -> weight -> { normal?, italic? } registered (PostScript) names.
|
|
16
|
+
export type FontRegistry = Record<string, Record<number, RegisteredFace>>;
|
|
10
17
|
|
|
11
18
|
const WEIGHT_NAME_TO_NUM: Record<string, number> = {
|
|
12
19
|
regular: 400,
|
|
@@ -25,6 +32,36 @@ export const normalizeWeight = (key: FontWeightKey | string | number | undefined
|
|
|
25
32
|
return Number.isFinite(parsed) ? parsed : 400;
|
|
26
33
|
};
|
|
27
34
|
|
|
35
|
+
export const normalizeStyle = (style: string | undefined | null): FontStyleKey =>
|
|
36
|
+
style === "italic" ? "italic" : "normal";
|
|
37
|
+
|
|
38
|
+
// Font families whose internal name collides with the iOS system font (SF Pro).
|
|
39
|
+
// Registering custom faces under one of these names makes iOS give the system
|
|
40
|
+
// font precedence, so only Regular resolves — every other weight renders tofu.
|
|
41
|
+
// On iOS we skip registering them and resolve to `fontFamily: undefined` so RN
|
|
42
|
+
// uses the real system font (which *is* SF Pro) honoring `fontWeight`. On
|
|
43
|
+
// Android (no SF Pro system font) the bundled faces register normally.
|
|
44
|
+
const SYSTEM_FONT_FAMILIES = new Set<string>([
|
|
45
|
+
"system",
|
|
46
|
+
"sfpro",
|
|
47
|
+
"sfprodisplay",
|
|
48
|
+
"sfprotext",
|
|
49
|
+
"sfprorounded",
|
|
50
|
+
"sfuidisplay",
|
|
51
|
+
"sfuitext",
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
const normalizeFamilyKey = (family: string): string =>
|
|
55
|
+
family.toLowerCase().replace(/[\s_.-]+/g, "");
|
|
56
|
+
|
|
57
|
+
// True when `family` names a platform system font that must NOT be registered as
|
|
58
|
+
// a bundled face on iOS (see SYSTEM_FONT_FAMILIES). Always false on other
|
|
59
|
+
// platforms — only iOS has the SF Pro collision.
|
|
60
|
+
export const isSystemFontFamily = (family: string | null | undefined): boolean => {
|
|
61
|
+
if (!family || Platform.OS !== "ios") return false;
|
|
62
|
+
return SYSTEM_FONT_FAMILIES.has(normalizeFamilyKey(family));
|
|
63
|
+
};
|
|
64
|
+
|
|
28
65
|
// The registered (PostScript) name is the font file's base name, without
|
|
29
66
|
// directory, query string, or extension — e.g. ".../Inter-SemiBold.ttf?v=2"
|
|
30
67
|
// registers as "Inter-SemiBold".
|
|
@@ -49,29 +86,28 @@ const loadExpoFont = (): typeof import("expo-font") | null => {
|
|
|
49
86
|
}
|
|
50
87
|
};
|
|
51
88
|
|
|
52
|
-
type NormalizedVariant = { weight: number; url: string };
|
|
89
|
+
type NormalizedVariant = { weight: number; style: FontStyleKey; url: string };
|
|
53
90
|
|
|
54
91
|
const normalizeFamilyVariants = (input: FontFamilyManifestInput | undefined): NormalizedVariant[] => {
|
|
55
92
|
if (!input) return [];
|
|
56
93
|
|
|
57
94
|
if (Array.isArray(input)) {
|
|
58
|
-
|
|
95
|
+
// Key by weight+style so an italic face is never overwritten by the upright
|
|
96
|
+
// face at the same weight (and vice-versa). Last entry wins on exact dup.
|
|
97
|
+
const byKey = new Map<string, NormalizedVariant>();
|
|
59
98
|
for (const entry of input as FontVariantEntry[]) {
|
|
60
99
|
if (!entry || typeof entry.url !== "string" || !entry.url) continue;
|
|
61
100
|
const weight = normalizeWeight(entry.weight as FontWeightKey | number);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
if (!existing || isNormalStyle) {
|
|
65
|
-
byWeight.set(weight, { weight, url: entry.url });
|
|
66
|
-
}
|
|
101
|
+
const style = normalizeStyle(entry.style);
|
|
102
|
+
byKey.set(`${weight}-${style}`, { weight, style, url: entry.url });
|
|
67
103
|
}
|
|
68
|
-
return Array.from(
|
|
104
|
+
return Array.from(byKey.values());
|
|
69
105
|
}
|
|
70
106
|
|
|
71
107
|
const out: NormalizedVariant[] = [];
|
|
72
108
|
for (const [weightKey, url] of Object.entries(input as FontFamilyManifest)) {
|
|
73
109
|
if (typeof url !== "string" || !url) continue;
|
|
74
|
-
out.push({ weight: normalizeWeight(weightKey as FontWeightKey), url });
|
|
110
|
+
out.push({ weight: normalizeWeight(weightKey as FontWeightKey), style: "normal", url });
|
|
75
111
|
}
|
|
76
112
|
return out;
|
|
77
113
|
};
|
|
@@ -86,21 +122,30 @@ export const registerFonts = async (manifest: FontsManifest | undefined): Promis
|
|
|
86
122
|
const loads: Array<Promise<void>> = [];
|
|
87
123
|
|
|
88
124
|
for (const [family, variantsInput] of Object.entries(manifest)) {
|
|
125
|
+
// Don't register a system-font family's bundled faces on iOS — resolution
|
|
126
|
+
// returns `fontFamily: undefined` for it so the real system font is used.
|
|
127
|
+
if (isSystemFontFamily(family)) continue;
|
|
128
|
+
|
|
89
129
|
const variants = normalizeFamilyVariants(variantsInput);
|
|
90
130
|
if (variants.length === 0) continue;
|
|
91
131
|
registry[family] = registry[family] ?? {};
|
|
92
132
|
|
|
93
|
-
for (const { weight, url } of variants) {
|
|
133
|
+
for (const { weight, style, url } of variants) {
|
|
94
134
|
const registeredName = buildRegisteredName(url);
|
|
95
|
-
registry[family][weight] =
|
|
135
|
+
const bucket = (registry[family][weight] = registry[family][weight] ?? {});
|
|
136
|
+
bucket[style] = registeredName;
|
|
96
137
|
|
|
97
138
|
loads.push(
|
|
98
139
|
Font.loadAsync({ [registeredName]: { uri: url } as any }).catch((error: unknown) => {
|
|
99
140
|
console.warn(
|
|
100
|
-
`[onboarding] Failed to load font "${family}" weight ${weight} from ${url}:`,
|
|
141
|
+
`[onboarding] Failed to load font "${family}" weight ${weight} (${style}) from ${url}:`,
|
|
101
142
|
error
|
|
102
143
|
);
|
|
103
|
-
|
|
144
|
+
const b = registry[family]?.[weight];
|
|
145
|
+
if (b) {
|
|
146
|
+
delete b[style];
|
|
147
|
+
if (Object.keys(b).length === 0) delete registry[family][weight];
|
|
148
|
+
}
|
|
104
149
|
})
|
|
105
150
|
);
|
|
106
151
|
}
|
|
@@ -110,18 +155,30 @@ export const registerFonts = async (manifest: FontsManifest | undefined): Promis
|
|
|
110
155
|
return registry;
|
|
111
156
|
};
|
|
112
157
|
|
|
158
|
+
// Picks the requested style from a weight bucket, falling back to the other
|
|
159
|
+
// style when the requested one isn't available at that weight.
|
|
160
|
+
const pickFace = (
|
|
161
|
+
face: RegisteredFace | undefined,
|
|
162
|
+
style: FontStyleKey
|
|
163
|
+
): string | undefined => (face ? (face[style] ?? face.normal ?? face.italic) : undefined);
|
|
164
|
+
|
|
113
165
|
export const resolveFontFamily = (
|
|
114
166
|
registry: FontRegistry | null | undefined,
|
|
115
167
|
family: string | null | undefined,
|
|
116
|
-
weight: string | number | null | undefined
|
|
168
|
+
weight: string | number | null | undefined,
|
|
169
|
+
fontStyle?: FontStyleKey | string | null
|
|
117
170
|
): string | undefined => {
|
|
118
171
|
if (!family) return undefined;
|
|
172
|
+
// System font on iOS: let RN resolve the real system font from fontWeight.
|
|
173
|
+
if (isSystemFontFamily(family)) return undefined;
|
|
119
174
|
if (!registry) return family;
|
|
120
175
|
const variants = registry[family];
|
|
121
176
|
if (!variants) return family;
|
|
122
177
|
|
|
178
|
+
const style = normalizeStyle(fontStyle);
|
|
123
179
|
const requested = normalizeWeight(weight as FontWeightKey | undefined);
|
|
124
|
-
|
|
180
|
+
|
|
181
|
+
const exact = pickFace(variants[requested], style);
|
|
125
182
|
if (exact) return exact;
|
|
126
183
|
|
|
127
184
|
const available = Object.keys(variants)
|
|
@@ -139,5 +196,5 @@ export const resolveFontFamily = (
|
|
|
139
196
|
bestDelta = delta;
|
|
140
197
|
}
|
|
141
198
|
}
|
|
142
|
-
return variants[best];
|
|
199
|
+
return pickFace(variants[best], style) ?? family;
|
|
143
200
|
};
|